Skip to main content
Commonmark migration
Source Link

#Python 2, 536 509 448 441 bytes

Python 2, 536 509 448 441 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while w<1:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 print"P%d WINS"%-~(r(p).count('o')<2)

#Python 2, 536 509 448 441 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while w<1:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 print"P%d WINS"%-~(r(p).count('o')<2)

Python 2, 536 509 448 441 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while w<1:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 print"P%d WINS"%-~(r(p).count('o')<2)
added 9 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17

#Python 2, 536 509 448448 441 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while not ww<1:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 if w:print"P%d WINS"%-~(r(p).count('o')<2)

#Python 2, 536 509 448 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while not w:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 if w:print"P%d WINS"%-~(r(p).count('o')<2)

#Python 2, 536 509 448 441 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while w<1:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 print"P%d WINS"%-~(r(p).count('o')<2)
deleted 12 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17

#Python 2, 536 509 454448 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while not w:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=[_ for _ in m if w=min(map(r(p).count(_,m)<2];t+=1)<2;t+=1
    except:print"INVALID"
 if w:print"PLAYER %sprint"P%d WINS"%'21'[mWINS"%-~(r(p).findcount(w[0]'o')]<2)

#Python 2, 536 509 454 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while not w:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=[_ for _ in m if r(p).count(_)<2];t+=1
    except:print"INVALID"
 if w:print"PLAYER %s WINS"%'21'[m.find(w[0])]

#Python 2, 536 509 448 bytes

Call via a(); moves are to be entered in the form piece,destination (i.e., 1,4); quit with Ctrl-C. If anyone can see more golfing potential, I'm all ears.

b,r,x='_',lambda p:''.join([p[i]for i in x]),range(11)
def a(m='xo'):
 t=w=0;p=dict(zip(x,'xxxx___oooo'))
 while not w:
    print r(p);y=m[t%2]
    try:
     s,v=input();1/all([y==p[s],{v}<{r(p).rfind(b,0,s),r(p).find(b,s)},v-s]);p[s],p[v],h,c=b,y,0,{}  
     for _ in y,m[-~t%2]:
        for i in p:exec{_:"h=1;p.update(c)",b:"h,c=0,{}"}.get(p[i],h*"c[i]=b")
     w=min(map(r(p).count,m))<2;t+=1
    except:print"INVALID"
 if w:print"P%d WINS"%-~(r(p).count('o')<2)
deleted 7 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading
deleted 29 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading
deleted 8 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading
deleted 5 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading
deleted 12 characters in body
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading
Source Link
sirpercival
  • 1.8k
  • 11
  • 17
Loading