Class: Kudo::Operator
- Inherits:
-
Object
- Object
- Kudo::Operator
- Defined in:
- lib/kudo/operator.rb
Class Method Summary collapse
- .get_column(sudoku, j) ⇒ Object
- .get_empty_cells(sudoku) ⇒ Object
- .get_row(sudoku, i) ⇒ Object
- .get_subgrid(sudoku, i, j) ⇒ Object
Class Method Details
.get_column(sudoku, j) ⇒ Object
20 21 22 |
# File 'lib/kudo/operator.rb', line 20 def get_column(sudoku, j) sudoku.map { |row| row[j] } end |
.get_empty_cells(sudoku) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/kudo/operator.rb', line 5 def get_empty_cells(sudoku) empty_cells = [] 9.times do |i| 9.times do |j| empty_cells.append([i, j]) if sudoku[i][j].zero? end end empty_cells end |
.get_row(sudoku, i) ⇒ Object
16 17 18 |
# File 'lib/kudo/operator.rb', line 16 def get_row(sudoku, i) sudoku[i] end |
.get_subgrid(sudoku, i, j) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kudo/operator.rb', line 24 def get_subgrid(sudoku, i, j) row = i / 3 * 3 col = j / 3 * 3 subgrid = [] (row..row + 2).each do |r| (col..col + 2).each do |c| subgrid << sudoku[r][c] end end subgrid end |