Skip to content

Instantly share code, notes, and snippets.

@skalahonza
Created May 23, 2018 11:29
Show Gist options
  • Save skalahonza/1a3a7b78a5a8df0cf77449a486be1b73 to your computer and use it in GitHub Desktop.
Save skalahonza/1a3a7b78a5a8df0cf77449a486be1b73 to your computer and use it in GitHub Desktop.
Hanoi tower solver for three towers, return list of tupples (actsions) --> (from, to)
; list of actions
; - n počet disků
; move tower to c
; last stage to 2
(define (hanoi n a b c)
(cond
((eq? n 1) (list(cons a b))) ; jedno patro dám rovnou na b
(#t (append (hanoi (- n 1) a c b) (list(cons a b))
(hanoi (- n 1) c b a)
))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment