Alpha DevCon 2018
Results 1 to 4 of 4

Thread: Programming Puzzle 15 - Sum the Cubes

  1. #1
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,300

    Default 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. #2
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    490

    Default 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]
    Stephen Pilon
    Associate Librarian
    Christendom College

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,300

    Default 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. #4
    Member
    Real Name
    Jeb Richardson
    Join Date
    Aug 2011
    Location
    Bowling Green, KY
    Posts
    26

    Default Re: Programming Puzzle 15 - Sum the Cubes

    puz 15 attempt.

    puz 15.txt

Similar Threads

  1. Programming Puzzle 2 - Another Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 16
    Last Post: 12-20-2014, 10:38 AM
  2. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 05:40 AM
  3. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 04:50 PM
  4. Programming Puzzle 14 - Sum the Squares
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 08-15-2011, 04:28 PM
  5. Programming Puzzle 6 - Another nested loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 6
    Last Post: 08-08-2011, 04:30 PM

Bookmarks

Posting Permissions

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