Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
0
votes
How do I change my stove's temperature?
Python3, 168 bytes:
lambda *x:min(f(*x),key=len)
def f(a,b,c=''):
if a==b:yield c
if len(c)<10:
yield from f([a+1,[9,0][a==9]][a in[0,9]],b,c+'+')
yield from f([4,a-1][a!=0],b,c+'-')
Try it onl …
1
vote
Interpret the Shue Language
Python3, 264 bytes:
lambda x,y:next(M(x,p(y)))
def M(s,g):
if s in g[0]:yield s
for a,b in g[1]:
for i in range(len(s)):
if a==s[i:i+len(a)]:yield from M(s[:i]+b+s[i+len(a):],g)
def p(s):
d={} …
3
votes
Fill the rectangle
Python3, 460 bytes:
R=range
S=lambda x,y:[(X,Y)for X in R(x)for Y in R(y)]
def L(m,X,Y,w,h):
m=eval(str(m))
for x,y in S(X,Y):
if 0==m[y][x]and Y-y>=h and X-x>=w:
for j,k in S(h,w):
if m[y+ …
3
votes
Solve the Zany car game
Python3, 408 bytes:
lambda s:(q:=int(len(s)**0.5))and[j for k in next(f([[0]*q]*q,[(x//q,x%q)for x in R(q**2)],s),[])for j in k]
R=range
v=lambda x,L,A,B:all(all(0 in[i[j],i[j+1]]or 9==i[j][A]+i[j+1][ …
1
vote
Solve a jigsaw puzzle
Python3, 210 bytes:
def f(m,c=[]):
if(C:=len(c))==9:yield[c[i:i+3]for i in range(0,9,3)];return
for i in{*m}-{*c}:
t=[]
if C%3>0:t+=[m[c[-1]][1]==m[i][3]]
if C>3:t+=[m[c[C-3]][2]==m[i][0]]
i …
1
vote
CGAC2022 Day 18: Light all of the candles
Python3, 214 bytes:
def f(m):
q,s=[(m,[])],[m]
while q:
m,M=q.pop(0)
if all(m):return M
for i in range(len(m)):
U=[*m]
for j in[-1,0,1]:
if 0<=i+j<len(m):
U[i+j]=not U[i+j]
i …
2
votes
CGAC2022 Day 23: North Pole Railroads
Python3, 237 bytes:
lambda x:min(f(x))
def f(x):
q=[(x,[])]
while q:
a,b=q.pop(0)
if[]==a:yield len(b);continue
for I,i in enumerate(b):
if all(y<=a[0][0]or a[0][1]<=x for x,y in i):q+=[(a[ …
2
votes
Bringing Down the Building
Python3, 507 bytes:
E=enumerate
def S(b):
q=[*b]
while q:
Q=[q.pop(0)];R=[Q[0]]
while Q:
x,y=Q.pop(0)
F=1
for X,Y in[(1,0),(0,1),(0,-1),(-1,0),(-1,-1),(1,-1),(-1,1),(1,1)]:
C=(x+X,y …
5
votes
What dice do I need to display every integer up to X?
Python3, 475 bytes:
from itertools import*
R=range
N=lambda k:k+[6,9]*(6 in k or 9 in k)
P=permutations
def f(n):
q=[({*R(1,n+1)},[[]]if n<7 else[[0]])]
while q:
a,b=q.pop()
if not a:return[[0]* …
1
vote
Reorganize By Arrows
Python3, 584 bytes:
E=enumerate
U=lambda b,x,y:0<=x<len(b)and 0<=y<len(b[0])
def f(b):
q=[(x,y,'','',0,1)for x,r in E(b)for y,l in E(r)if'['==l]
while q:
x,y,w,l,X,Y=q.pop(0)
if(u:=b[x][y]).isal …
3
votes
Iterate over all non-equivalent strings
Python3, 323 bytes:
def B(a,b):
d={}
for a,b in zip(a,b):
if b not in(T:=d.get(a,[])):d[a]={*T,b}
return d
def F(n):
r,q=[],[['abcdefghijklmnopqrstuvwxyz'[:n]*2,'']]
for s,k in q:
if''==s:
…
1
vote
Simulate Round Robin Scheduling
Python3, 83 bytes:
def R(p,t,q):
Q,s=[*zip(p,t)],[]
for a,b in Q:s+=[a];Q+=[(a,b-q)]*(b>q)
return s
Try it online!
2
votes
Reverse engineer colors for a layout
Python3, 772 bytes:
E=enumerate
def f(l,I=[],r=[]):
if len(I)==len(l):yield r;return
for i,a in E(l):
if a==1 and i not in I:
j,k,Q,W=i,i,[],[]
while(j:=j-1)>=0 and j not in I and l[j]!=1 an …
2
votes
The too-short urinal problem
Python3, 219 bytes
E=enumerate
def f(u):
c,C=1,[0]*len(u)
while 0==all(C):I=max([i for i,a in E(C)if 0==a],key=lambda i:(u[i],min([abs(I-i)for I,A in E(C)if A]or[0]),(i-1<0 or 0==C[i-1])+(i+1>=len(u …
0
votes
Help me juice my avocados
Python3, 362 bytes
E=enumerate
M=[(0,1),(0,-1),(1,0),(-1,0)]
def f(a):
q=[({(x,y):u for x,r in E(a)for y,u in E(r)},[])]
while q:
m,j=q.pop(0)
if{3}=={*m.values()}:return j
for x,y in m:
fo …