Class: Point
- Inherits:
-
Object
- Object
- Point
- Defined in:
- lib/sudoku_solver/point.rb
Instance Attribute Summary collapse
-
#box ⇒ Object
Returns the value of attribute box.
-
#nums ⇒ Object
Returns the value of attribute nums.
-
#position ⇒ Object
Returns the value of attribute position.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #include?(num) ⇒ Boolean
-
#initialize(y = 0, x = 0, value = 0) ⇒ Point
constructor
A new instance of Point.
- #share(point) ⇒ Object
- #subset?(point) ⇒ Boolean
- #x ⇒ Object
- #y ⇒ Object
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
#box ⇒ Object
Returns the value of attribute box.
4 5 6 |
# File 'lib/sudoku_solver/point.rb', line 4 def box @box end |
#nums ⇒ Object
Returns the value of attribute nums.
4 5 6 |
# File 'lib/sudoku_solver/point.rb', line 4 def nums @nums end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/sudoku_solver/point.rb', line 4 def position @position end |
#value ⇒ Object
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
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
50 51 52 |
# File 'lib/sudoku_solver/point.rb', line 50 def subset?(point) nums.to_set.subset?(point.nums.to_set) end |
#x ⇒ Object
55 56 57 |
# File 'lib/sudoku_solver/point.rb', line 55 def x @position.x end |
#y ⇒ Object
59 60 61 |
# File 'lib/sudoku_solver/point.rb', line 59 def y @position.y end |