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

Link to this function

is_valid_move(board, from, to)

View Source
@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

Link to this function

move_stone(board, from, to, debug)

View Source
@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