Skip to content

Instantly share code, notes, and snippets.

@VadimBrodsky
Last active October 15, 2015 00:48
Show Gist options
  • Save VadimBrodsky/30064b651568a69ecadc to your computer and use it in GitHub Desktop.
Save VadimBrodsky/30064b651568a69ecadc to your computer and use it in GitHub Desktop.
Sudoku solver
require 'pry'
#
# +---+---+---+
# | | | |
# | 3 | 5 | 4 |
# | | | |
# +---+---+---+
#
class Square
attr_accessor :value, :xPosition, :yPosition
def initialize(val, x, y)
self.value = val
self.xPosition = x
self.yPosition = y
end
def to_s
" #{value} "
end
end
class Group
attr_accessor :squares, :xPosition, :yPosition
def initialize(data, x, y)
@squares = []
self.xPosition = x
self.yPosition = y
3.times do |i|
3.times do |j|
@squares << Square.new(data.shift, j + 1, i + 1)
end
end
end
end
class Board
attr_accessor :groups
def initialize(array_of_groups)
@groups = []
3.times do |i|
3.times do |j|
@groups << Group.new(array_of_groups.shift, j + 1, i + 1)
end
end
end
end
sq1 = Square.new(8, 1, 1)
puts sq1
groups = [
[1, 9, 4, 0, 7, 6, 2, 0, 0],
[0, 6, 5, 2, 0, 0, 0, 8, 0],
[0, 2, 0, 4, 5, 8, 0, 0, 3],
[0, 0, 5, 0, 8, 0, 1, 0, 0],
[0, 0, 0, 0, 3, 0, 0, 0, 0],
[0, 0, 9, 0, 1, 0, 8, 0, 0],
[9, 0, 0, 7, 6, 8, 0, 4, 0],
[0, 4, 0, 0, 0, 3, 6, 9, 0],
[0, 0, 6, 5, 9, 0, 1, 8, 0]
]
# group = Group.new(group_1_values, 1, 1)
board = Board.new(groups)
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment