Programming Puzzle 15 - Sum the Cubes

No, we're not talking ice cubes here, but cubed integers.

Consider this: The number 153 equals 1 cubed, plus 5 cubed, plus 3 cubed.

i.e. 153 = 1^{3} + 5^{3} + 3^{3}

Here's the challenge:

Find all other 3 digit numbers that have the same property. Display them in a message box, or write them to the trace window, at your option.

Have fun.

-- tom

Re: Programming Puzzle 15 - Sum the Cubes

Code:

`dim a as n`

dim b as n

dim c as n

dim sum_cubes as c = "The Sum Cubes are:" + crlf()

for x = 100 to 999

a = val(substr(str(x,3),1,1))

b = val(substr(str(x,3),2,1))

c = val(substr(str(x,3),3,1))

if a^3+b^3+c^3 = x then

sum_cubes = sum_cubes + x + " [" + a + "^3=" + a^3 + " | " + b + "^3=" + b^3 + " | " + c + "^3=" + c^3 + "]" + crlf()

end if

next x

? sum_cubes

= The Sum Cubes are:

153 [1^3=1 | 5^3=125 | 3^3=27]

370 [3^3=27 | 7^3=343 | 0^3=0]

371 [3^3=27 | 7^3=343 | 1^3=1]

407 [4^3=64 | 0^3=0 | 7^3=343]

Re: Programming Puzzle 15 - Sum the Cubes

Very nice!

To display the answer in a desktop app change the last line to:

Code:

`Msgbox("Answer", sum_cubes)`

1 Attachment(s)

Re: Programming Puzzle 15 - Sum the Cubes

puz 15 attempt.

Attachment 29071