Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

-a few bytes
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) (削除) 526 (削除ここまで) 471461 bytes

C=eval(input())
N=next
E=enumerate
def F(x,y,f):
 try:1/-~x/-~y;global a,v,n;c=C[y][x];~y;c=C[y][x];(x,y)in v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v+=[v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v[:0]=[(x,y)];a+=(c==15)+1;[c>>a&1and];[c>>i&1and F(x+a%2*x+i%2*(2-ai),y+(ai-1&~a1&~i),1<<(a^2i^2))for ai in(0,1,2,3)]
 except:1
while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip;a=len(*v)v);+n[15];(len(v)!=n[15]or(N(M:=map(max,zip(*v)))-N(m:=map(min,zip(*v)))+1)*(N(M)-N(m)+1)!=a/2)and(a!=4*n[6]*n[12]or n[6]!=n[9]or n[3]!=n[12]or n[0]>0)and z

Try it online! (all testcases) Try it online! (all testcases)

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) (削除) 526 (削除ここまで) 471 bytes

C=eval(input())
N=next
E=enumerate
def F(x,y,f):
 try:1/-~x/-~y;global a,v,n;c=C[y][x];(x,y)in v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v+=[(x,y)];a+=(c==15)+1;[c>>a&1and F(x+a%2*(2-a),y+(a-1&~a),1<<(a^2))for a in(0,1,2,3)]
 except:1
while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));(len(v)!=n[15]or(N(M)-N(m)+1)*(N(M)-N(m)+1)!=a/2)and(a!=4*n[6]*n[12]or n[6]!=n[9]or n[3]!=n[12]or n[0]>0)and z

Try it online! (all testcases)

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) (削除) 526 (削除ここまで) 461 bytes

C=eval(input())
N=next
E=enumerate
def F(x,y,f):
 try:1/-~x/-~y;c=C[y][x];(x,y)in v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v[:0]=[(x,y)];[c>>i&1and F(x+i%2*(2-i),y+(i-1&~i),1<<(i^2))for i in(0,1,2,3)]
 except:1
while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);a=len(v)+n[15];(len(v)!=n[15]or(N(M:=map(max,zip(*v)))-N(m:=map(min,zip(*v)))+1)*(N(M)-N(m)+1)!=a/2)and(a!=4*n[6]*n[12]or n[6]!=n[9]or n[3]!=n[12]or n[0]>0)and z

Try it online! (all testcases)

-55 bytes
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) 526(削除) 526 (削除ここまで) 471 bytes

-49 bytes thanks to @ovs and @pppery

C=eval(input())
N=next
E=enumerate
def s(C):
 def F(x,y,f):
 nonlocaltry:1/-~x/-~y;global a,v,n
 try:c=C[y][x]
 except:return
 ifn;c=C[y][x];(x,y)in v:return
 n[c]+=1
 if c&f<1:return
  C[y][x]=0;v+=[v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v+=[(x,y)];a+=(c==15)+1;c&1and y and+1;[c>>a&1and F(x,yx+a%2*(2-1,4a);c&2and F(x+1,y,8);c&4and Fy+(x,y+1a-1&~a),11<<(a^2);c&8and x)for anda Fin(x-10,y1,2,3)]
 except:1
while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));
 if 1-(len(v)==n[15]and!=n[15]or(N(M)-N(m)+1)*(N(M)-N(m)+1)==a!=a/2or a==4*n[6]*n[12]and2)and(a!=4*n[6]*n[12]or n[6]==n[9]andn[6]!=n[9]or n[3]==n[12]andn[3]!=n[12]or n[0]<1n[0]>0):returnand 0z

Try it online! (all testcases) Try it online! (all testcases)

Returns NoneThrows NameError for truefalse and 0doesn't throw for falsetrue.

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) 526 bytes

N=next
E=enumerate
def s(C):
 def F(x,y,f):
 nonlocal a,v,n
 try:c=C[y][x]
 except:return
 if(x,y)in v:return
 n[c]+=1
 if c&f<1:return
  C[y][x]=0;v+=[(x,y)];a+=(c==15)+1;c&1and y and F(x,y-1,4);c&2and F(x+1,y,8);c&4and F(x,y+1,1);c&8and x and F(x-1,y,2)
 while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));
 if 1-(len(v)==n[15]and(N(M)-N(m)+1)*(N(M)-N(m)+1)==a/2or a==4*n[6]*n[12]and n[6]==n[9]and n[3]==n[12]and n[0]<1):return 0

Try it online! (all testcases)

Returns None for true and 0 for false.

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) (削除) 526 (削除ここまで) 471 bytes

-49 bytes thanks to @ovs and @pppery

C=eval(input())
N=next
E=enumerate
def F(x,y,f):
 try:1/-~x/-~y;global a,v,n;c=C[y][x];(x,y)in v<Q;n[c]+=1;c&f<1<Q;C[y][x]=0;v+=[(x,y)];a+=(c==15)+1;[c>>a&1and F(x+a%2*(2-a),y+(a-1&~a),1<<(a^2))for a in(0,1,2,3)]
 except:1
while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));(len(v)!=n[15]or(N(M)-N(m)+1)*(N(M)-N(m)+1)!=a/2)and(a!=4*n[6]*n[12]or n[6]!=n[9]or n[3]!=n[12]or n[0]>0)and z

Try it online! (all testcases)

Throws NameError for false and doesn't throw for true.

-28 bytes
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74

Python 3, (削除) 667 (削除ここまで) 554(削除) 554 (削除ここまで) 526 bytes

N=next
E=enumerate
def Fs(C,):
 def F(x,y,f):
 global t,nonlocal a,v,n
 try:c=C[y][x]
 except:return
 if(x,y)in v:return
 t|=c==0 n[c]+=1
 if notif c&fc&f<1:return
 C[y][x]=0;v+=[(x,y)]
 a+=];a+=(c==15)+1;n[c]+=1
+1;c&1and ify c&1andand y>0:F(C,x,y-1,4)
 if;c&2and c&2:F(C,x+1,y,8)
 if;c&4and c&4:F(C,x,y+1,1);c&8and ifx c&8andand x>0:F(C,x-1,y,2)
def s(C):
 globalwhile t,a,v,n;t=a=0;v=[];n={3:0,6:0,9:0,12l:0=[(x,15:0}
 y)for y,r in E(C):
 for x,e in E(r)if e]:
 a=0;v=[];n={k:0for ifk e:Fin range(C,x,y16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));return;
 if 1-(len(v)==n[15]and(N(M)-N(m)+1)*(N(M)-N(m)+1)==a/2and s(C)or2or a==4*n[6]*n[12]and n[6]==n[9]and n[3]==n[12]and t<1and s(Cn[0]<1):return 0

Try it online! (all testcases) Try it online! (all testcases)

Returns None for true and False0 for false.

Python 3, (削除) 667 (削除ここまで) 554 bytes

N=next
E=enumerate
def F(C,x,y,f):
 global t,a,v,n
 try:c=C[y][x]
 except:return
 if(x,y)in v:return
 t|=c==0
 if not c&f:return
 C[y][x]=0;v+=[(x,y)]
 a+=(c==15)+1;n[c]+=1
 if c&1and y>0:F(C,x,y-1,4)
 if c&2:F(C,x+1,y,8)
 if c&4:F(C,x,y+1,1) if c&8and x>0:F(C,x-1,y,2)
def s(C):
 global t,a,v,n;t=a=0;v=[];n={3:0,6:0,9:0,12:0,15:0}
 for y,r in E(C):
 for x,e in E(r):
 if e:F(C,x,y,15);m,M=map(min,zip(*v)),map(max,zip(*v));return len(v)==n[15]and(N(M)-N(m)+1)*(N(M)-N(m)+1)==a/2and s(C)or a==4*n[6]*n[12]and n[6]==n[9]and n[3]==n[12]and t<1and s(C)

Try it online! (all testcases)

Returns None for true and False for false.

Python 3, (削除) 667 (削除ここまで) (削除) 554 (削除ここまで) 526 bytes

N=next
E=enumerate
def s(C):
 def F(x,y,f):
 nonlocal a,v,n
 try:c=C[y][x]
 except:return
 if(x,y)in v:return
  n[c]+=1
 if c&f<1:return
 C[y][x]=0;v+=[(x,y)];a+=(c==15)+1;c&1and y and F(x,y-1,4);c&2and F(x+1,y,8);c&4and F(x,y+1,1);c&8and x and F(x-1,y,2)
 while l:=[(x,y)for y,r in E(C)for x,e in E(r)if e]:
 a=0;v=[];n={k:0for k in range(16)};F(*l[0],15);m,M=map(min,zip(*v)),map(max,zip(*v));
 if 1-(len(v)==n[15]and(N(M)-N(m)+1)*(N(M)-N(m)+1)==a/2or a==4*n[6]*n[12]and n[6]==n[9]and n[3]==n[12]and n[0]<1):return 0

Try it online! (all testcases)

Returns None for true and 0 for false.

-113 bytes
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74
Loading
Add commented, ungolfed
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74
Loading
Source Link
fireflame241
  • 16.4k
  • 2
  • 31
  • 74
Loading

AltStyle によって変換されたページ (->オリジナル) /