Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Last active August 29, 2015 14:07
Show Gist options
  • Save danielbonnell/6769fb41e2f5f4603fd9 to your computer and use it in GitHub Desktop.
Save danielbonnell/6769fb41e2f5f4603fd9 to your computer and use it in GitHub Desktop.
tic-tac-to challenge
def winner?(board)
@match = false
def check(type)
@match = true if type.uniq.length == 1 && !type.include?(" ")
end
board.each do |row|
check(row)
end
board.transpose.each do |col|
check(col)
end
diag1, diag2 = board.map.with_index { |row, i| [row[i], row[- i - 1]] }.transpose
check(diag1)
check(diag2)
@match
end
@danielbonnell
Copy link
Author

I wasn't able to get your line 8 suggestion implemented. It just won't work no matter how I play with it in the editor. Thanks for the other tips though. I simplified the code just a bit more, although launchcop is still giving is 8/7 for complexity (down from 11/7).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment