O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Eller’s Algorithm

Eller’s algorithm works strictly one row at a time, so our implementation will take advantage of that by leaning on a row-centric state object. Once we have that state object, the rest of the algorithm comes together quickly.

We’ll start with the RowState class, which we’ll place under the namespace of the Ellers class. It will all go in ellers.rb.

ellers.rb
 
class​ Ellers
 
 
class​ RowState
 
def​ initialize(starting_set=0)
 
@cells_in_set = {}
 
@set_for_cell = []
 
@next_set = starting_set
 
end
 
end
 
 
end

It’s certainly not much yet, but it does get us started. The initialize method has a starting_set parameter (defaulting to 0), which will be used to determine what value is used for new sets. It ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required