Assignment 2: Solving the Lazy Hobo Riddle

Due Thursday, April 17, 6pm

This assignment is to write a Java application.

The following riddle dates back to the late 19th century (its revival is credited to Will Shortz, crossword puzzle editor of the New York Times). A solution to the riddle consists of 4 numbers a, b, c, and d such that a squared + b squared + c squared + d squared = 200.  So, what you need to do is to systematically generate combinations of 4 numbers, and check whether the current combination has the property that the squares of its numbers sum to 200.

Since the squares of numbers that are 15 or greater exceed 200, the only values that you need to consider for  a, b, c, and d occur in the interval [1, 14].  As there is no advantage to evaluate the same combination more than once, you should generate the combinations in a manner that eliminates duplicate combinations (e.g., {1,2,3,3} is the combination as {2,1,3,3}).  An easy way to ensure no duplication is to generate the combinations in ascending order.  As a result, each generated combination will have the property that  a <= b <=  c <= d .

To solve the riddle, consider the various possibilities for a in the interval [1, 14].  For a given value of a, consider all possibilities of  b, c, and d subject to the constraints discussed above.  In particular, the possibilities for b are [a, 14].  In a similar manner, given that a and b are fixed, consider all possibilities for c and d.  The possible values for c are [b, 14].  Once a, b, and c have been fixed, the possible values for d are [c, 14]. 

Your application's output should look like what appears between the horizontal rules:

        Lazy hobo possible solutions:
    1. 2 4 6 12
    2. 6 6 8 8

Turn In Procedure 

Email your file to Emailing to the wrong address is not an acceptable reason for a late turn-in. Be sure to email your file while logged into your own account 

Submit a hard copy of your file to the CS10 homework box.