Towers of Hanoi

Let's review another programming problem called Towers of Hanoi and solve it using F#. The puzzle was invented by a French mathematician, Édouard Lucas, in 1883 and has been heavily cited in programming literature including Ralf Hinze's Functional Pearl: La Tour D'Hanoi (http://www.comlab.ox.ac.uk/ralf.hinze/publications/ICFP09.pdf). The objective of the puzzle is to move the tower from the starting pole to the target pole in the minimum number of steps following two simple rules:

  1. Only one top disk is allowed to move to a different pole during an action.
  2. A large disk cannot be placed on top of a smaller disk.
    Towers of Hanoi

A simple Pascal implementation ...

Get Learning F# Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.