Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created March 15, 2014 21:28
Show Gist options
  • Save bjhaid/9574144 to your computer and use it in GitHub Desktop.
Save bjhaid/9574144 to your computer and use it in GitHub Desktop.
def valid?(tic)
tac = *tic
3.times { |i| tac.push((0..2).map { |x| tic[x][i] }) }
tac.push((0..2).map { |x| tic[x][x] }).push((0..2).map { |x| tic[tic.size - 1 - x][x] })
(tac.select { |x| x.uniq.size == 1 && x.first != :e }).first
end
@koriroys
Copy link

def valid?(tic)
  [
    [0,1,2],[3,4,5],[6,7,8],
    [0,3,6],[1,4,7],[2,5,8],
    [0,4,8],[2,4,6]
  ].map{ |p| p.map { |n| tic.flatten[n] } }.select { |a| a.uniq.size == 1 && a[0] != :e }.first
end

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