[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]


Problem DescriptionFor a given power value, find all numbers greater than 1 which are equal to the sum of their digits raised to that power. For example: 370=3^{3}+7^{3}+0^{3}. Background & TechniquesThis problem is from an article "Are Toy Problems Useful" written by Donald Knuth, published in the February , 1977 issue of Popular Computing magazine, I found it reprinted in "Selected Papers on Computer Science:, Donald E. Knuth, Cambridge University Press, 1996. The articled challenged claims by G. H. Hardy that trivial problems were useless and a waste of time. Knuth believes, and I agree, that such problems are useful if a encourage and reinforce problem solving skills in the same sense that story problems in your Algebra or Calculus textbook are useful. This one in particular proved challenging because my standard "Brute Force" approach works OK for single digit powers but finding the single number equal to the sum of the 10 powers of its digits takes 25 minutes on my medium speed laptop. The program allows users to enter a Power value between 2 and 15 and has buttons for each of 3 methods implemented. Button 1 tests all permutations with repeats for N digit integers. We'll call
this "Brute Force 1"and it works Programmer's Notes:The program uses several components from our DFFLIB library and any recent version will be required before recompiling the program. UComboV2 is used to generate permutations and combinations. UIntList, used in Button 3, lets us create an integer list of number "signatures" and the array of digits represented. Because it is easy here to start processes which may run for hours, provisions are made for the user to interrupt execution. The technique used in many programs here on DFF is as follows:
The Stop button in this case is made large enough to to cover all three buttons and is initially moved to the top left corner of the top button. It is initially and normally has its Visibility property set to False. Entering the Button click exit, sets the Stop button Visible to True and sets it back to False before exiting the procedure. Running/Exploring the Program
Suggestions for Further Explorations

[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 20002018, Gary Darby All rights reserved. 