Add valid? method

This commit is contained in:
Alberto Venturini 2019-10-29 21:42:13 +02:00
parent 61bbd00f6d
commit 5b01700650
2 changed files with 19 additions and 2 deletions

View file

@ -24,8 +24,14 @@ module Sudoku
@grid[y][x]
end
def check_valid(value : Value, x, y)
def valid?(value : Value, x, y)
if value == nil
true
else
extract_row(y).all? { |i| i != value } &&
extract_column(x).all? { |i| i != value } &&
extract_block(x, y).all? { |i| i.all? { |j| j != value } }
end
end
def extract_row(y)