def openOrSenior(data)
data.map { |m| senior?(m) ? 'Senior' : 'Open' }
end
def senior?(arr)
arr[0] > 54 && arr[1] > 7
end
VALID_ARR = [1,2,3,4,5,6,7,8,9]
FAILED = 'Try again!'
def valid_arr?(arr)
arr.sort == VALID_ARR
end
def done_or_not(board)
# check each row
board.each {|r| return FAILED unless valid_arr?(r) }
# check each column
board.transpose.each { |r| return FAILED unless valid_arr?(r) }
# check each 3x3 grid
board.each_slice(3) do |g|
# g.map{|f| f[0..2]}.reduce(:+) here can prob be extracted to another method,
# but I don't know how to pass in [0..2] as an argument. Maybe use a proc?
return FAILED unless valid_arr?(g.map{|f| f[0..2]}.reduce(:+))
return FAILED unless valid_arr?(g.map{|f| f[3..5]}.reduce(:+))
return FAILED unless valid_arr?(g.map{|f| f[6..8]}.reduce(:+))
end
'Finished!'
end