T-Shirt #6

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

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

A sixth entry in our  "Numeric  T-Shirt" line:  

Back of T-Shirt:  "The only integer equal to the sum of the 6th powers of its digits!"

Front:  __ __ __ __ __ __?

Background & Techniques

Another 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 Program 

bulletBrowse source code
bulletDownload source 
bulletDownload  executable

Suggestions for Further Explorations

Add a Stop button to allow user to interrupt execution for sl0ow computer or large values of N.  (Set Tag=1 on Stop button click.  In Search button click routine, set tag = 0 before loop and execute Application.processmessages and check for Tag=1 once in a while inside the loop.)
Time and display run times.
Try  using the IntPower function from Delphi's Math unit to calculate the powers.   Is it faster or slower than calculating the powers in a loop?
Use Int64 type, 64 bit integers, and find a way to check faster for numbers larger than 8 digits. 

 

Originally posted: May 5,  2003 Modified:February 18, 2016
 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.