Sha256: 0de30c6b79474a9df3e5a78b04c4a92346c09dc3d2b90807b386ccbc0d94fe5a
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
require_relative 'container' require 'set' class Point attr_accessor :box, :position, :nums, :value 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 def nums @nums.sort end 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 def value=(val) if @value == 0 @value = val if @value != 0 @nums = [val] end end end def nums=(n) if @value == 0 @nums = n if @nums.count == 1 @value = @nums.first @nums = [@value] end end end def include?(num) nums.include?(num) || (num == value) end def subset?(point) nums.to_set.subset?(point.nums.to_set) end def x @position.x end def y @position.y end def blank_spaces [(position.y / 3) * 3 + (position.x / 3), position.y, position.x] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sudoku-jedi-1.0.0 | lib/sudoku_solver/point.rb |
sudoku-jedi-0.0.4 | lib/sudoku_solver/point.rb |