]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/towers-of-hanoi/towers-of-hanoi.factor
factor: trim using lists
[factor.git] / extra / rosetta-code / towers-of-hanoi / towers-of-hanoi.factor
1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: formatting kernel math ;
4 IN: rosetta-code.towers-of-hanoi
5
6 ! http://rosettacode.org/wiki/Towers_of_Hanoi
7
8 ! In this task, the goal is to solve the Towers of Hanoi problem
9 ! with recursion.
10
11 : move ( from to -- )
12     "%d->%d\n" printf ;
13
14 :: hanoi ( n from to other -- )
15     n 0 > [
16         n 1 - from other to hanoi
17         from to move
18         n 1 - other to from hanoi
19     ] when ;
20
21 ! USAGE: 3 1 3 2 hanoi