開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Prolog (プログラミング言語)
- GProlog(GNU Prolog)(処理系)
7つの言語 7つの世界 (Bruce A. Tate (著)、まつもとゆきひろ (監訳)、田和 勝 (翻訳)、オーム社)の第4章(Prolog)、4.3(2日目: Wapner判事まで15分)、セルフスタディ2日目.(ハノイの塔)を取り組んでみる。
セルフスタディ2日目.(ハノイの塔)
コード(Emacs)
hanoi(0, A, B, C). hanoi(N, A, B, C) :- N > 0, M is N - 1, hanoi(M, A, C, B), write(N), write(': '), write(A), write('->'), write(C), write('\n'), hanoi(M, B, A, C).
入出力結果(Terminal)
GNU Prolog 1.4.4 (64 bits) Compiled Feb 5 2016, 06:20:25 with /opt/local/bin/gcc-apple-4.2 By Daniel Diaz Copyright (C) 1999-2013 Daniel Diaz | ?- ['tower_of_hanoi.pl']. compiling .../tower_of_hanoi.pl for byte code... .../tower_of_hanoi.pl:1: warning: singleton variables [A,B,C] for hanoi/4 .../tower_of_hanoi.pl compiled, 12 lines read - 1306 bytes written, 15 ms (2 ms) yes | ?- hanoi(0, a, b, c). true ? ; no | ?- hanoi(1, a, b, c). 1: a->c true ? a (1 ms) no | ?- hanoi(2, a, b, c). 1: a->b 2: a->c 1: b->c true ? a no | ?- hanoi(3, a, b, c). 1: a->c 2: a->b 1: c->b 3: a->c 1: b->a 2: b->c 1: a->c true ? a no | ?- hanoi(4, a, b, c). 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c true ? a no | ?- hanoi(10, a, b, c). 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 7: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 6: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 8: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 6: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 7: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 9: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 6: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 7: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 6: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 8: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 7: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 6: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 10: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 6: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 7: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 8: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 6: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 7: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 6: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 9: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 7: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 6: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 8: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 6: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 5: c->a 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 7: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 5: a->b 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 4: c->b 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 6: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c 4: b->a 1: c->a 2: c->b 1: a->b 3: c->a 1: b->c 2: b->a 1: c->a 5: b->c 1: a->b 2: a->c 1: b->c 3: a->b 1: c->a 2: c->b 1: a->b 4: a->c 1: b->c 2: b->a 1: c->a 3: b->c 1: a->b 2: a->c 1: b->c true ? a (8 ms) no | ?- Process prolog finished
0 コメント:
コメントを投稿