Compare commits

...

2 Commits

Author SHA1 Message Date
29a556fd54 2019 day 1 to not derail 2024-07-28 19:13:13 -04:00
d2417a9377 Day 19 2018 wip 2024-07-28 19:04:25 -04:00
5 changed files with 80 additions and 0 deletions

41
2018/d19.py Normal file
View File

@ -0,0 +1,41 @@
from lib import get_data, str_to_ints
import d16
def part_1(data):
ip = None
regs = [0 for _ in range(6)]
regs[0] = 1 # part 2
insts = []
for line in data.splitlines():
if line.startswith("#"):
ip, = str_to_ints(line)
else:
fs = line.split()
vals = str_to_ints(line)
insts.append([fs[0]] + vals)
assert ip is not None
while regs[ip] < len(insts):
inst = insts[regs[ip]]
f = getattr(d16, inst[0])
# if inst[1:] == [3, 1, 3]:
# regs[3] = regs[1]
# regs[4] = regs[1]
f(regs, *inst[1:])
regs[ip] += 1
print(regs, regs[-1] + 1)
print(regs[0])
def main():
data = get_data(__file__)
part_1(data)
if __name__ == "__main__":
main()

32
2019/d1.py Normal file
View File

@ -0,0 +1,32 @@
from lib import get_data
def f(i):
i //= 3
i -= 2
return i
def part_1(data):
print(sum([f(int(line)) for line in data.splitlines()]))
def part_2(data):
r = 0
for line in data.splitlines():
i = f(int(line))
while i > 0:
r += i
i = f(i)
print(r)
def main():
data = get_data(__file__)
part_1(data)
part_2(data)
if __name__ == "__main__":
main()

1
2019/lib.py Symbolic link
View File

@ -0,0 +1 @@
../lib.py

1
2019/monitor.py Symbolic link
View File

@ -0,0 +1 @@
../monitor.py

View File

@ -109,6 +109,11 @@ written in Python.
- Day 18: 24:04
- Day 19:
# 2019
- Day 1: 4:25 (copy and paste error)
- Day 2:
# 2022
Done with this. Overall everything is solvable. It's more about consistency