Towers of Hanoi: Difference between revisions
Content added Content deleted
(Updated the iterative D version) |
(→{{header|FALSE}}: Add F#) |
||
Line 430: | Line 430: | ||
Move disk 1 from the left pole to the right pole |
Move disk 1 from the left pole to the right pole |
||
</pre> |
</pre> |
||
=={{header|F#}}== |
|||
<lang fsharp>let rec hanoi num start finish = |
|||
match num with |
|||
| 0 -> [ ] |
|||
| _ -> let temp = (6 - start - finish) |
|||
(hanoi (num-1) start temp) @ [ start, finish ] @ (hanoi (num-1) temp finish) |
|||
[<EntryPoint>] |
|||
let main args = |
|||
(hanoi 4 1 2) |> List.iter (fun pair -> match pair with |
|||
| (a, b) -> printf "Move disc from %A to %A\n" a b) |
|||
0</lang> |
|||
=={{header|FALSE}}== |
=={{header|FALSE}}== |