Class: Point

Inherits:
Object
  • Object
show all
Defined in:
lib/sudoku_solver/point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y = 0, x = 0, value = 0) ⇒ Point

Returns a new instance of Point.



6
7
8
9
10
11
12
# 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

Instance Attribute Details

#boxObject

Returns the value of attribute box.



4
5
6
# File 'lib/sudoku_solver/point.rb', line 4

def box
  @box
end

#numsObject

Returns the value of attribute nums.



4
5
6
# File 'lib/sudoku_solver/point.rb', line 4

def nums
  @nums
end

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/sudoku_solver/point.rb', line 4

def position
  @position
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/sudoku_solver/point.rb', line 4

def value
  @value
end

Instance Method Details

#include?(num) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sudoku_solver/point.rb', line 46

def include?(num)
  nums.include?(num) || (num == value)
end

#share(point) ⇒ Object



18
19
20
21
22
23
24
# 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) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/sudoku_solver/point.rb', line 50

def subset?(point)
  nums.to_set.subset?(point.nums.to_set)
end

#xObject



55
56
57
# File 'lib/sudoku_solver/point.rb', line 55

def x
  @position.x
end

#yObject



59
60
61
# File 'lib/sudoku_solver/point.rb', line 59

def y
  @position.y
end