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

No credit card required

## Implementing Recursive Division

The algorithm really is as simple as described. First, we’ll “blank out” the grid by linking every cell to its neighbors (effectively removing all interior walls), and then recursively split the grid in half by adding walls back in.

Unlike the other algorithms we’ve implemented, we’re going to break this one into a few different methods to help with the recursion. It’ll all start with our typical on(grid) method, though. Put the following in recursive_division.rb.

 recursive_division.rb ​Line 1 ​class​ RecursiveDivision ​- ​- ​def​ self.on(grid) ​- @grid = grid ​5 ​- @grid.each_cell ​do​ |cell| ​- cell.neighbors.each { |n| cell.link(n, false) } ​- ​end​ ​- ​10 divide(0, 0, @grid.rows, grid.columns) ​- ​end​

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

No credit card required