home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Programming Contest / Problems Folder / Problem 02 - Hower of Tanoi / Solution.p < prev   
Encoding:
Text File  |  1998-05-25  |  1.6 KB  |  64 lines  |  [TEXT/CWIE]

  1. (*
  2. Problem 02 - Hower of Tanoi
  3.  
  4. This problem is to solve a variant
  5. of the Tower of Hanoi puzzle.  You remember the Tower of Hanoi, a board
  6. with three pegs, one of which has N disks of size 1, 2, 3, ... N, with the
  7. smallest disk at the top.  In the standard puzzle, the goal is to move all
  8. of the disks from one peg to another peg, by repeatedly moving a disk from
  9. the top of one peg to another peg without ever placing a larger disk on top
  10. of a smaller disk.
  11.  
  12. In our Hower of Tanoi problem, the objective and the constraints are the
  13. same, except that the disks on the first peg are initially in random order.
  14. You can still only move a smaller disk onto a larger disk.
  15.  
  16. Your objective is output the moves required to place all the disks on
  17. peg 3 in order with the smallest disk at the top.  
  18.  
  19. Input specification
  20.  
  21. The
  22. first line of the input file contains an integer M, M<1000, the number of
  23. disks in the problem.  The next M lines contain the numbers 1 .. M, one
  24. number per line, randomly ordered, where the first number is the size of
  25. the top disk on peg 1, the second number is the size of the 2nd
  26. disk from the top, etc.
  27.  
  28. Output specification
  29.  
  30. The output is a sequence of lines, each representing a single move, 
  31. consisting of the source peg number followed by a comma (',') followed
  32. by the destination peg number, followed by a return character.
  33.  
  34. Sample input
  35.  
  36. 2
  37. 2
  38. 1
  39.  
  40. Sample output
  41.  
  42. 1,3
  43. 1,3
  44. *)
  45.  
  46. unit Solution;
  47.  
  48. interface
  49.  
  50. // Do not modify the interface
  51.  
  52.     uses
  53.         Types, Files;
  54.         
  55.     function HowerOfTanoi( const infile, outfile: FSSpec ): OSErr;
  56.  
  57. implementation
  58.  
  59. // Fill in your solution and then submit this folder
  60.  
  61. // Team Name: FILL IN YOUR TEAM NAME!
  62.  
  63. end.
  64.