 # Thread: Programming Puzzle 15 - Sum the Cubes

1. ## 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 = 13 + 53 + 33

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 2. ## 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] 3. ## 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)` 4. ## Re: Programming Puzzle 15 - Sum the Cubes

puz 15 attempt.

puz 15.txt #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•