# [extropy-chat] Puzzle - Short Tale

Alan Eliasen eliasen at mindspring.com
Fri Feb 6 23:50:22 UTC 2004

```Spike wrote:
> I found an old notebook in which I used to do mathematical
> puzzles.  I had found in a commentary that 153 is the smallest
> number that is equal to the sum of the cubes of its digits.
> I do vaguely recall doing the calcs that resulted from my
> musing "What are the other numbers that are the sum of
> the cubes of their digits?"
>
> At the time I had a counterfeit Apple, but no printer,
> (and no sense of guilt for the theft of Apple's
> intellectual property) so if I calculated something, I
> had to write it down in a notebook.  Usually I also wrote
> down the algorithm but this time I wrote only the damn answers
> and Im going crazy trying to figure out how I figured
> this out 24 yrs ago with a 3.2 megahertz computer.  Yes
> young people, they really did go that slow back then.
>
> I wrote a couple pages of cryptic notes and figures,
> interspersed with the numbers 370, 371 and 407.  These
> are numbers that are the sum of their cubes.
>
> A few pages over I wrote "numbers equal to the 4th power
> of their digits:  1634, 8208, 9474."
>
> Later a table:
>
> 5th power:  4150, 4151, 54748, 92727, 93084, 194979.
>
> 6th:  548834
>
> 7th:  1741725, 4210818, 9800817, 9926315, 14459929.
>
> 8th:  24678050, 24678051, 88593477
>
> I neglected to write down the algorithm!  Question please,
> before I go crazy, HOW COULD I have found those solutions?
> I do vaguely recall deriving the code, but now Im at a
> complete loss for how.  OH NO I've grown stuuuupiiiiid!  {8-[

Here's a quick (3-minute) algorithm written in Frink (a programming language
of my own design):

-------
p = eval[input["Enter power: "]]

n = 0
while (true)
{
sum = 0
for c = array[char["\$n"]] //  Make array of unicode values for each char
{
v = c - char["0"]
sum = sum + v^p
}

if sum == n
println[n]

n=n+1
}
-------------------

Frink is available here:
http://futureboy.homeip.net/frinkdocs/

The algorithm for breaking the number into its digits could have also been
done by use of div and mod operations, but this was slightly quicker.

The algorithm, as listed above, doesn't terminate.  Finding the highest
possible bound for each power is left as an exercise for the reader, and
finding a good starting point as well.  (Zero and one are always solutions.)
But brute force works too.

--
Alan Eliasen                 | "You cannot reason a person out of a
eliasen at mindspring.com       |  position he did not reason himself
http://futureboy.homeip.net/ |  into in the first place."
|     --Jonathan Swift

```