Gistrec

Ханойска башня

Sep 4th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.57 KB | None | 0 0
  1. class hanoi
  2.    predicates
  3.        hanoi : (unsigned N).
  4. end class hanoi
  5.  
  6. implement hanoi
  7.    domains
  8.        pole = string.
  9.  
  10.    clauses
  11.        hanoi(N) :- move(N, "left", "centre", "right").
  12.  
  13.    class predicates
  14.        move : (unsigned N, pole A, pole B, pole C).
  15.    clauses
  16.        move(0, _, _, _) :- !.
  17.        move(N, A, B, C) :-
  18.            move(N-1, A, C, B),
  19.            stdio::writef("move a disc from % pole to the % pole\n", A, C),
  20.            move(N-1, B, A, C).
  21. end implement hanoi
  22.  
  23. goal
  24.    console::init(),
  25.    hanoi::hanoi(4).
Advertisement
Add Comment
Please, Sign In to add comment