This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"golang.org/x/exp/constraints" | |
) | |
type SkipList[K constraints.Ordered] struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digits = [0b111111000, 0b011000100, 0b110100001, 0b100000111, 0b011001010, 0b101101010, 0b001110110, 0b100010100, 0b111111010, 0b110001011] | |
print(sum(1 for m in range(512) if m.bit_count() == 4 and len({x & m for x in digits}) == 10)) # 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f ← ( | |
⊙(⊡1)⊡0. | |
⊓(⊃(≠@.)(≠@#)$"._."°□)(⊜⋕≠@,.°□) | |
:×↻1,⊐/⊂⊜(□\+-1).+1 | |
⊙:⊢.⍉\(×⊙+/+,)×⊠=.⇡⧻. | |
⊙(;;)⊢⇌°□∧(□/+×⊙,⬚0↻¯1×⬚0↻⊙:¯⊙≥.⊙(,°□)):⊙(:⊙:)□ | |
) | |
/+⊜(f⊜□≠@ .)≠@\n. &fras "12.in" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import count | |
N,M=137,139 | |
print((m:={(i//(M+1),i%(M+1)):c for i,c in enumerate(open(0).read())}) and next(i for i in count() if ((r:=[r for i,j in m if m[i,j]=='>' and m[i,(j+1)%M]=='.' for r in (((i,j),'.'),((i,(j+1)%M),'>'))]), m.update(r)) and ((p:=[p for i,j in m if m[i,j]=='v' and m[(i+1)%N,j]=='.' for p in (((i,j),'.'),(((i+1)%N,j),'v'))]), m.update(p)) and not(p or r))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from heapq import heappush, heappop | |
from itertools import takewhile,product,count | |
(D:=4,x:=((*[0]*11,),(1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4)),s:=((*[0]*11,),(4,4,4,3),(4,3,2,1),(2,2,1,2),(1,1,3,3)),d:={s:0},q:=[(0,s)],print(next(filter(None,(len(q)==0 or (t:=heappop(q)) and (v:=t[1]) and d[v]==t[0] and (v==x and d[x] or (f:={(i,j) for i in range(11) for j in takewhile(lambda x: not v[0][x],range(i,11))}) and (p:=[*product(range(1,5),(0,1,3,5,7,9,10))]) and (g:=[0]+[len(v[i])==0 or max(v[i])==min(v[i])==i for i in range(1,5)]) and any((n not in d or d[n]>nd) and (d.update({n:nd}) or heappush(q,(nd,n))) for nd,n in [(d[v]+(D-len(v[i])+abs(j-2*i))*10**(i-1),((*v[0][:j],0,*v[0][j+1:]),*v[1:i],(i,*v[i]),*v[i+1:])) for i,j in p if g[i] and v[0][j]==i and (j<2*i and (j+1,2*i) or (2*i,j-1)) in f]+[(d[v]+(D-len(v[i])+1+abs(j-2*i))*10**(v[i][0]-1),((*v[0][:j],v[i][0],*v[0][j+1:]),*v[1:i],(*v[i][1:],),*v[i+1:])) for i,j in p if not g[i] and (min(2*i,j),max(2*i,j)) in f]) and 0) for _ in count()))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import prod | |
from itertools import islice | |
print(next((lambda g:g(g,s,r(s,6)%8))(lambda g,s,t:(lambda f:f(f,0,r(s,5)))(lambda f,a,x:f(f,a*16+x%16,r(s,5)) if x>15 else a*16+x) if t==4 else [sum,prod,min,max,0,lambda x:x[0]>x[1],lambda x:x[0]<x[1],lambda x:x[0]==x[1]][t]([g(g,z,r(z,5)%8) for i in [r(s,1)] for v in [r(s,15-4*i)] for z in [islice(s,v+i*10000)] for _ in zip(range((1-i)*1000+v),z)])) for s in [iter(''.join(bin(int(h,16))[2:].zfill(4) for h in open(0).read().strip()))] for r in [lambda s,k:int(''.join(next(zip(*[s]*k))),2)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re,math | |
print(sum((2*c[0]-1)*math.prod(map(sum,c[1])) for c in [m.extend([i for d in m for i in [(1-d[0],[[*map(min,zip(a,b))] for a,b in zip(c[1],d[1])])] if min(map(sum,i[1]))>0]) or c[0] and m.append(c) or m for m in [[]] for s in open(0) for c in [(s[1]=='n',[[-int(x[0]),int(x[1])+1] for x in re.findall(r'(-?\d+)..(-?\d+)',s)])]][0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print([(lambda f:f(f,0,3,4,0,0))(lambda f,i,p,q,s,t: (i,p,q,s,t) not in m and m.update({(i,p,q,s,t): sum(f(f,1-i,q,(p+d+2)%10+1,t,s+(p+d+2)%10+1)*[1,3,6,7,6,3,1][d] for d in range(7)) if t<21 else i}) or m[i,p,q,s,t]) for m in [{}]][0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(max(next(filter(None,(g(b[v]%5) or g(b.pop(v)//5+5) or max(c)==5 and (i,sum(map(int,b.keys()))*int(v)) for i,v in enumerate(d) if v in b))) for f in [open(0)] for d in [next(f).strip().split(',')] for b in [{k:i for i,k in enumerate(b)} for b in zip(*[iter(f.read().split())]*25)] for c in [[0]*10] for g in [lambda i:c.__setitem__(i,c[i]+1)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
print([*[reduce(lambda m,_: ({v:a[0][int(''.join("01"[m[0].get(v+d,m[1])=='#'] for d in D),2)] for v in {v-d for v in m[0] for d in D}},a[0][511*(m[1]=='#')]),range(50),(a[2],'.')) for D in [[k//3+k%3*1j for k in range(9)]] for f in [open(0)] for a in [(next(f),next(f),{x+y*1j:c for x,s in enumerate(f) for y,c in enumerate(s)})]][0][0].values()].count('#')) |
NewerOlder