Skip to content

Instantly share code, notes, and snippets.

@Tremeschin
Last active May 31, 2021 12:39
Show Gist options
  • Save Tremeschin/f65a6ee252b7569b60ab72e6a88b9dfd to your computer and use it in GitHub Desktop.
Save Tremeschin/f65a6ee252b7569b60ab72e6a88b9dfd to your computer and use it in GitHub Desktop.
8 lines tic tac toe
import numpy as n
g,p,w=n.array([[0]*3]*3),1,"-OX"
while True:
for r in g: print(' '.join(w[x]for x in r))
c,p=int(input(w[-p])),-p
g[divmod(c-1,3)]=p
s=n.concatenate((n.sum(g,axis=0),n.sum(g.T,axis=0),[sum(g.diagonal())],[sum(n.fliplr(g).diagonal())]))
if e:=w[1]if 3 in s else w[2]if-3 in s else 0: exit(e+"wins")
@Tremeschin
Copy link
Author

Need Python 3.8 because walrus operator := on line 8 ( or until I find a shorter way to exit and determine if anyone wins)

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