]> gitweb.factorcode.org Git - factor.git/blob - extra/logic/examples/hanoi/hanoi.factor
factor: trim more using lists.
[factor.git] / extra / logic / examples / hanoi / hanoi.factor
1 ! Copyright (C) 2019-2020 KUSUMOTO Norio.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs logic math ;
4 IN: logic.examples.hanoi
5
6 LOGIC-PREDS: hanoi moveo informo ;
7 LOGIC-VARS: A B C M N X Y ;
8 SYMBOLS: left center right ;
9
10 { hanoi N } { moveo N left center right } rule
11
12 { moveo 0 __ __ __ } !! rule
13
14 { moveo N A B C } {
15     [ [ N of 1 - ] M is ]
16     { moveo M A C B }
17     { informo A B }
18     { moveo M C B A }
19 } rule
20
21 { informo X Y } {
22     { writeo { "move disk from " X " to " Y } } { nlo }
23 } rule
24
25