Created
November 6, 2015 11:12
-
-
Save jaeming/a3f7614815d06d5d282e to your computer and use it in GitHub Desktop.
sudoku
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
def valid?(pattern) | |
pattern.map(&:uniq!).map(&:nil?).include?(false) ? false : true | |
end | |
def validSolution(board) | |
rows, columns, grids = board, [], [] | |
9.times do |i| | |
column, grid = [], [] | |
board.map { |row| column << row[i] } | |
columns << column | |
board.drop(i*3).take(3).map{|row| grid << row.drop(i*3).take(3)} | |
grids << grid.flatten.drop(i*9).take(9) | |
end | |
valid?(rows) && valid?(columns) && valid?(grids) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment