A small F# console sample that solves the Tower of Hanoi puzzle using the State monad from FSharpPlus. Each recursive move is pushed onto a state-tracked list via monad { ... } computation expressions, and the final move sequence is printed to the console.
This is a legacy learning sample (last updated in 2020) targeting .NET Framework 4.5.1 with the classic .fsproj / packages.config project format.
hanoi src bare dst heightrecursively builds the move sequence insideState<Step list, unit>- Each move is recorded as a
Steprecord (Src,Dst,Height) usingmodify State.execruns the computation against an empty list and yields the ordered move listmainsolves a 3-disk puzzle from"Left"to"Right"and prints the result withprintfn "%A"
- .NET Framework 4.5.1 (or Mono) with F# tooling — Visual Studio / Visual Studio for Mac era
- NuGet packages (via
packages.config):FSharp.Core 4.7.2,FSharpPlus 1.1.1,System.ValueTuple 4.4.0
Open FsharpHanoi.sln in Visual Studio, restore NuGet packages, then build and run. The program prints the move list for a 3-disk Tower of Hanoi. Change the argument of result in Program.fs to solve for a different disk count.
FsharpHanoi.sln # Solution file
FsharpHanoi/
Program.fs # Hanoi solver using FSharpPlus State monad
FsharpHanoi.fsproj # Legacy-format F# project (net451)
packages.config # NuGet package pins
