Instantly share code, notes, and snippets.

# dubistdu/soduku.md Created Mar 4, 2019

soduku kata
``````def validSolution(board)
return false if board.flatten.include?(0)
board.map {|a| a.uniq.count == 9}.include?(false) ? false : board
square_of_3 = board.map { |a| a.each_slice(3).to_a }
s1=square_of_3[0][0].zip(square_of_3[1][0],square_of_3[2][0])
s2=square_of_3[0][1].zip(square_of_3[1][1],square_of_3[2][1])
s3=square_of_3[0][2].zip(square_of_3[1][2],square_of_3[2][2])

s4=square_of_3[3][0].zip(square_of_3[4][0],square_of_3[5][0])
s5=square_of_3[3][1].zip(square_of_3[4][1],square_of_3[5][1])
s6=square_of_3[3][2].zip(square_of_3[4][2],square_of_3[5][2])

s7=square_of_3[6][0].zip(square_of_3[7][0],square_of_3[8][0])
s8=square_of_3[6][1].zip(square_of_3[7][1],square_of_3[8][1])
s9=square_of_3[6][2].zip(square_of_3[7][2],square_of_3[8][2])

squares = [s1, s2, s3, s4, s5, s6, s7, s8, s9]
columns=board[0].zip(board[1],board[2],board[3],board[4],board[5],board[6],board[7],board[8])
return false if columns.map {|a| a.uniq.count == 9}.include?(false)
squares.map { |square| square.flatten.uniq.count == 9 }.include?(false) ? false : true
end
``````