View Source Hanoi.Algo (Towers of Hanoi v1.0.0)
An algorithm solving the Towers of Hanoi problem by recursion.
Summary
Functions
An algorithm to get the list of moves to transfer stones by recursion
A move is valid if the stone exists, the stack moved to is empty, or has a larger stone on it
Returns a new board with stone moved, or an error if an invalid move
An algorithm to move stones between stacks by recursion
Functions
@spec get_moves(board :: Hanoi.Board.t()) :: {:ok, list()}
An algorithm to get the list of moves to transfer stones by recursion
@spec is_valid_move(board :: Hanoi.Board.t(), from :: atom(), to :: atom()) :: boolean()
A move is valid if the stone exists, the stack moved to is empty, or has a larger stone on it
@spec move_stone( board :: Hanoi.Board.t(), from :: atom(), to :: atom(), debug :: boolean() ) :: {:ok | :error, Hanoi.Board.t()}
Returns a new board with stone moved, or an error if an invalid move
@spec run_algo(board :: Hanoi.Board.t()) :: Hanoi.Board.t()
An algorithm to move stones between stacks by recursion