Advent of Code 2020, now in the most terse and awful python possible
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
722 B

#!/usr/bin/env python3
from sys import argv
m = {}
m2 = {}
m_and = (2**36)-1
m_orr = 0
for l in open(argv[1]):
l = l.strip().split(" = ")
if l[0] == "mask":
m_and = int(l[1].replace("X", "1"), 2)
m_orr = int(l[1].replace("X", "0"), 2)
elif l[0].startswith("mem[") and l[0].endswith("]"):
o = int(l[0][4:-1])
v = int(l[1])
m[o] = (v & m_and) | m_orr
o |= m_and
f = m_and ^ m_orr
a = [o]
for x in range(36):
if ((f >> x) & 1) == 0:
continue
for e in range(len(a)):
a.append(a[e] ^ (1 << x))
for e in a:
m2[e] = v
print(sum(m.values()))
print(sum(m2.values()))