5 lines
457 B
Python
5 lines
457 B
Python
import re;l=(x.strip()for x in open("input.txt"));m={}
|
|
def c(r, s=0):yield from (i for it in((0,1)if r[0]=='X'else(int(r[0]),))for i in c(r[1:],s*2+it))if len(r)else[s]
|
|
for k in l:s,match=(re.match(r"mask = (.+)",k)or(0,s))[1],re.match(r"mem\[(.+)] = (.+)",k);addr,dec=match and list(map(int,match and match.groups()))or(-1,0);m={**m,**{x:dec for x in(c([(a if b=='0'else b)for a,b in zip(format(addr,'036b'),s)])if addr!=-1else[])}}
|
|
print(sum(m.values()))
|