Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Last active September 22, 2020 08:13
Show Gist options
  • Save vlad-bezden/f5be3862b51935334f83 to your computer and use it in GitHub Desktop.
Save vlad-bezden/f5be3862b51935334f83 to your computer and use it in GitHub Desktop.
Solution of Tower of Hanoi problem using F#
let rec TowerOfHanoi fromPole destPole tempPole disks =
if disks > 0 then
TowerOfHanoi fromPole tempPole destPole (disks - 1)
printfn "Moving from %c to %c" fromPole destPole
TowerOfHanoi tempPole destPole fromPole (disks - 1)
TowerOfHanoi '1' '2' '3' '4'
@isocolon
Copy link

Great write-up! Solution is a lot more readable than some of the other F# solutions out there.

A small correction: printf in line 4 should be printfn.

@vlad-bezden
Copy link
Author

Thank you @isocolon I updated code as you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment