Skip to content

Instantly share code, notes, and snippets.

@jaeming
Created November 6, 2015 11:12
Show Gist options
  • Save jaeming/a3f7614815d06d5d282e to your computer and use it in GitHub Desktop.
Save jaeming/a3f7614815d06d5d282e to your computer and use it in GitHub Desktop.
sudoku
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