Implementing Wilson's Algorithm

Learn to implement Wilson's algorithm in Ruby.

The Wilsons class

The following code uses an array to keep track of all unvisited cells in the grid. Besides letting us query whether a cell has been visited or not, this also lets us quickly choose an unvisited cell from which we can start our loop-erased random walk.

Get hands-on with 1400+ tech skills courses.