Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- day14_1():
- with open("input.txt", "r") as file:
- data = file.readlines()
- mem = {}
- on_mask = 0
- off_mask = 0
- for line in data:
- if line[1] == "a": # Mask
- mask = line[7:-1]
- on_mask = int(mask.replace("X", "0"), base=2) # OR to set 1s
- off_mask = int(mask.replace("X", "1"), base=2) # AND to set 0s
- else:
- addr = line[line.find("[")+1:line.find("]")]
- val = int(line[line.find("=")+2:-1])
- mem[addr] = (val | on_mask) & off_mask
- total = 0
- for k, v in mem.items():
- total += v
- return total
Advertisement
Add Comment
Please, Sign In to add comment