C511-001/002Organization of Programming LanguagesWinter 1999

Homework Assignment Number 4

Logic Puzzles

Due: March 4, 1999 (soft) March 15, 1999 (hard) (assigned: February 25, 1999)
Submit solution to hchen@ececs.uc.edu

Rationale:

We see how the use of amb can help express solutions to some logic puzzles.

Homework Problem:

In Scheme using amb and in C write programs to solve the following logic puzzles:

  1. Magic Square. Find a 4x4 integer matrix such that 1) every number is distinct and between 1 and 16, inclusive; 2) all rows, all columns, and both longest diagonals sum to 34; 3) the sum of all four corners is 34; and 4) the sum of the four numbers comprising the innermost square is 34. Solutions taking more than a day to complete on a 450MHz machine are not acceptable.
  2. Railway Engineering. A railway depot has an oval track and two branch lines, as shown in the figure below, which is used to train train drivers, also known as Engine-eers. The specific problem a student Engine-eer is asked to solve is how to move railway carriage A to position B and railway carriage B to position A without taking any of the railway carriages through the tunnel and returning the engine to its starting position. How can it be done?