Skip to content

Instantly share code, notes, and snippets.

@kmbenjel
Created May 19, 2021 07:08
Show Gist options
  • Save kmbenjel/f91a523524f42ec51fcee0e6054377bc to your computer and use it in GitHub Desktop.
Save kmbenjel/f91a523524f42ec51fcee0e6054377bc to your computer and use it in GitHub Desktop.
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