July 2015
Intermediate to advanced
286 pages
6h 31m
English
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 ...