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


Problem Description
A sixth entry in our "Numeric TShirt" line: Back of TShirt: "The only integer equal to the sum of the 6th powers of its digits!" Front: __ __ __ __ __ __? Background & TechniquesAnother simple program for beginners. The primary problem is how to pick the digits out of an integer and then compute the 6th power of each and add them up. The trick to isolating the low order digit of a number is to compute the number mod 10. The "mod" function returns remainders, and the remainder of dividing a number by 10 is the low order digit!. Multiplying it by itself 5 times is good enough to compute the 6th power. And finally, dividing the number by 10 truncates the low order digit moving the next digit to the low order position so we can repeat the loop. If we sum these 6th powers inside the loop until all digits have been processed, we can check the sum against the original number and report those that match. This implementation with 30 lines or so of code, takes the power as an input value so we can check values from 1 to 8 (above 8 the run times will get very long and numbers are approaching the limit of 32 bit integers). Running/Exploring the ProgramSuggestions for Further Explorations

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