Module: SudokuSolver::Cell

Defined in:
lib/sudoku_solver/grid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gridObject

Returns the value of attribute grid.



5
6
7
# File 'lib/sudoku_solver/grid.rb', line 5

def grid
  @grid
end

Instance Method Details

#neighboursObject



7
8
9
10
11
12
13
14
15
# File 'lib/sudoku_solver/grid.rb', line 7

def neighbours
  sx = x - x % grid.dimension
  sy = y - y % grid.dimension
  neighbours_values = [
    grid[grid.size, y],
    grid[x, grid.size],
    grid[sx..(sx + grid.dimension - 1), sy..(sy + grid.dimension - 1)] ].
      inject([]) { |r, z| r + z.to_a }.flatten.uniq.reject { |d| d == self }
end