class Point

Attributes

box[RW]
nums[RW]
position[RW]
value[RW]

Public Class Methods

new(y=0, x=0, value = 0) click to toggle source
# File lib/sudoku_solver/point.rb, line 6
def initialize(y=0, x=0, value = 0)
  @value = value
  Struct.new("Coordinate", :x, :y) if !Struct::const_defined? "Coordinate"
  @position = Struct::Coordinate.new(x, y)
  @nums = []
  @box = (position.y / 3) * 3 + (position.x / 3) 
end

Public Instance Methods

include?(num) click to toggle source
# File lib/sudoku_solver/point.rb, line 46
def include?(num)
  nums.include?(num) || (num == value)
end
nums=(n) click to toggle source
# File lib/sudoku_solver/point.rb, line 35
def nums=(n)
  if @value == 0
    @nums = n
    if @nums.count == 1
      @value = @nums.first
      @nums = [@value]
    end
  end
end
share(point) click to toggle source
# File lib/sudoku_solver/point.rb, line 18
def share(point)
  a = []
  a << :box if @box == point.box
  a << :x if x == point.x
  a << :y if y == point.y
  return a
end
subset?(point) click to toggle source
# File lib/sudoku_solver/point.rb, line 50
def subset?(point)
  nums.to_set.subset?(point.nums.to_set)
end
value=(val) click to toggle source
# File lib/sudoku_solver/point.rb, line 26
def value=(val)
  if @value == 0
    @value = val
    if @value != 0 
      @nums = [val]
    end
  end
end
x() click to toggle source
# File lib/sudoku_solver/point.rb, line 55
def x
  @position.x
end
y() click to toggle source
# File lib/sudoku_solver/point.rb, line 59
def y
  @position.y
end