Skip to content

Instantly share code, notes, and snippets.

@amstocker
Created December 14, 2020 06:13
Show Gist options
  • Select an option

  • Save amstocker/6a939e589ab5f586cbaf00b5c4f012cc to your computer and use it in GitHub Desktop.

Select an option

Save amstocker/6a939e589ab5f586cbaf00b5c4f012cc to your computer and use it in GitHub Desktop.
with open("day14_input.txt") as f:
data = f.read().split('\n')
# Part 1
memory = [0] * 100000
for line in data:
if line[0:4] == "mask":
mask = line[7:]
mask0 = int(''.join(map(lambda c: '0' if c == 'X' else c, mask)), 2)
mask1 = int(''.join(map(lambda c: '1' if c == 'X' else c, mask)), 2)
if line[0:3] == "mem":
loc = int(line[4:line.find(']')])
num = int(line[line.find(']') + 4:])
memory[loc] = (num | mask0) & mask1
print(sum(memory))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment