Python implementation
import sys def move(src, dst, tmp, num): if num == 1: print 'Move from', src, 'to', dst else: move(src, tmp, dst, num-1) move(src, dst, tmp, 1) move(tmp, dst, src, num-1) move('left', 'right', 'middle', int(sys.argv[1]))
Gives the correct solution for the tower of Hanoi. But my port circuit,
(define move (lambda (src dst tmp num) (if (= num 1) (printf "Move from ~s to ~s \n" src dst) ((move src tmp dst (- num 1)) (move src dst tmp 1) (move tmp dst src (- num 1))))))
Gives the correct solution, but at the end causes the following error.
procedure application: expected procedure, given: #<void>; arguments were: #<void> #<void>
I know his expression about printing, which throws an error, but I canโt understand why this is happening?
source share