hanoi20.str 2.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
module hanoi20

imports libstrategolib

signature

sorts
   Disk Tower Move List

constructors
   d0 : Disk 
   d1 : Disk 
   d2 : Disk 
   d3 : Disk 
   d4 : Disk 
   d5 : Disk 
   d6 : Disk 
   d7 : Disk 
   d8 : Disk 
   d9 : Disk 
   d10 : Disk 
   d11 : Disk 
   d12 : Disk 
   d13 : Disk 
   d14 : Disk 
   d15 : Disk 
   d16 : Disk 
   d17 : Disk 
   d18 : Disk 
   d19 : Disk 
   d20 : Disk 
   a : Tower 
   b : Tower 
   c : Tower 
   movedisk : Disk * Tower * Tower -> Move 
   nil : List 
   cons : Move * List -> List 
   dec : Disk -> Disk 
   other : Tower * Tower -> Tower 
   conc : List * List -> List 
   solve : Tower * Tower * Disk -> List 

rules
   REC_E: dec (d20()) -> d19()
   REC_E: dec (d19()) -> d18()
   REC_E: dec (d18()) -> d17()
   REC_E: dec (d17()) -> d16()
   REC_E: dec (d16()) -> d15()
   REC_E: dec (d15()) -> d14()
   REC_E: dec (d14()) -> d13()
   REC_E: dec (d13()) -> d12()
   REC_E: dec (d12()) -> d11()
   REC_E: dec (d11()) -> d10()
   REC_E: dec (d10()) -> d9()
   REC_E: dec (d9()) -> d8()
   REC_E: dec (d8()) -> d7()
   REC_E: dec (d7()) -> d6()
   REC_E: dec (d6()) -> d5()
   REC_E: dec (d5()) -> d4()
   REC_E: dec (d4()) -> d3()
   REC_E: dec (d3()) -> d2()
   REC_E: dec (d2()) -> d1()
   REC_E: dec (d1()) -> d0()
   REC_E: other (a(), b()) -> c()
   REC_E: other (b(), a()) -> c()
   REC_E: other (a(), c()) -> b()
   REC_E: other (c(), a()) -> b()
   REC_E: other (b(), c()) -> a()
   REC_E: other (c(), b()) -> a()
   REC_E: conc (nil(), L) -> L
   REC_E: conc (L, nil()) -> L
   REC_E: conc (cons (H, T), L) -> cons (H, conc (T, L))
   REC_E: solve (ORG, DEST, d0()) -> nil()
   REC_E: solve (ORG, DEST, D) -> conc (solve (ORG, other (ORG, DEST), dec (D)), cons (movedisk (D, ORG, DEST), solve (other (ORG, DEST), DEST, dec (D)))) where not (equal-after-eval (|D, d0()))

strategies
   eval = memo (innermost (REC_E))
   equal-after-eval (|m1, m2) = equal (|<eval> m1, <eval> m2)
   eval-and-print = eval ; debug (!"result = ")
   main = 
      (<eval-and-print> solve (a(), b(), d20())) ;
      <exit> 0