Solve day 24 2017.

This commit is contained in:
felixm 2024-06-09 04:58:42 -04:00
parent 869a22a310
commit f62f5fcff2
2 changed files with 37 additions and 0 deletions

35
2017/d24.py Normal file
View File

@ -0,0 +1,35 @@
from collections import defaultdict
def part_1(data):
ports = [list(map(int, line.split("/"))) for line in data.splitlines()]
in_to_out = defaultdict(list)
for index, (i, o) in enumerate(ports):
in_to_out[i].append((o, index))
in_to_out[o].append((i, index))
max_sum = 0
max_len = (0, 0)
bs = [(0, [], 0, 0)]
while bs:
current_port, used, current_sum, current_len = bs.pop()
max_sum = max(max_sum, current_sum)
max_len = max(max_len, (current_len, current_sum))
for out_port, index in in_to_out[current_port]:
if index in used:
continue
new_sum = current_sum + current_port + out_port
bs.append((out_port, used + [index], new_sum, current_len + 1))
print(max_sum)
print(max_len[1])
def main():
with open("i24.txt") as f:
data = f.read()
part_1(data)
if __name__ == "__main__":
main()

View File

@ -84,3 +84,5 @@ written in Python.
- Day 21: 90:00
- Day 22: 25:00
- Day 23:
- Day 24: 15:45 (48th)
- Day 25: