Last active
October 15, 2015 00:48
-
-
Save VadimBrodsky/30064b651568a69ecadc to your computer and use it in GitHub Desktop.
Sudoku solver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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