Guest User

Untitled

a guest
Aug 5th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.82 KB | None | 0 0
  1. %-------------------------------------------------------------------
  2. % 1. describe the following situation of the towers of Hanoi game
  3. %    in logic
  4. %
  5. %          I                     I                    I
  6. %          I                     I                    I
  7. %        +---+                   I                +-------+
  8. %        | d |                   I                |   c   |
  9. %  +----------------+            I              +-----------+
  10. %  |       a        |            I              |     b     |
  11. % ==================================================================
  12. %         rod1                  rod2                 rod3
  13. %
  14. % use relative positions like
  15. %       a is on rod1
  16. %       d is on a
  17. %       top of d is clear
  18. % etc.
  19. % since the size of the disks matters it must be represented, too.
  20. %
  21. % hints:
  22. % - use the identifiers from the diagram (a, b, c, d, rod1, rod2, ...)
  23. % - use predicate names:
  24. %     is_on(A,B)       meaning A is on B
  25. %     clear_top(A)     meaning top of A is clear
  26. %     and size_of(A,S) meaning size of A is S
  27. % - avoid blanks between predicate name and open parenthesis
  28. % - terminate statements by a dot  
  29. % - assume implicit universal quantification for variables
  30. % - use upper case symbols for variables (Prolog style variables)
  31. %
  32.  
  33. % 2. specify a predicate is_above(A,B) which is true
  34. %    if A is on B or if A is on C and C is above B
  35. %
  36.  
  37. % 3. specify a predicate move(A,B,C) which is true
  38. %    if the top of A is clear
  39. %       the top of C is clear
  40. %       A is on B
  41. %       and the size of C is bigger than size of A
  42. %
  43. %-------------------------------------------------------------------
  44.  
  45.  
  46. % use this 'predicate' to print all legal moves
  47. % do not change this!
  48.  
  49. print_all_moves :-
  50.   forall(move(A,B,C), writeln(move(A,B,C))),
  51.   forall(is_above(A,B), writeln(is_above(A,B))).
Add Comment
Please, Sign In to add comment