Created
May 19, 2021 07:08
-
-
Save kmbenjel/f91a523524f42ec51fcee0e6054377bc to your computer and use it in GitHub Desktop.
This file contains 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 is_solved(board) | |
all_nine = board.join.chars.map{|i| i.to_i} | |
all_lines = [] | |
all_lines << [all_nine[0],all_nine[1],all_nine[2]] | |
all_lines << [all_nine[0],all_nine[3],all_nine[6]] | |
all_lines << [all_nine[0],all_nine[4],all_nine[8]] | |
all_lines << [all_nine[2],all_nine[5],all_nine[8]] | |
all_lines << [all_nine[2],all_nine[4],all_nine[6]] | |
all_lines << [all_nine[1],all_nine[4],all_nine[7]] | |
all_lines << [all_nine[3],all_nine[4],all_nine[5]] | |
all_lines << [all_nine[6],all_nine[7],all_nine[8]] | |
if all_lines.include?([1,1,1]) | |
1 | |
elsif all_lines.include?([2,2,2]) | |
2 | |
elsif all_nine.include?(0) | |
-1 | |
else | |
0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment