summary refs log tree commit diff stats
path: root/day13.py
diff options
context:
space:
mode:
Diffstat (limited to 'day13.py')
-rw-r--r--day13.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/day13.py b/day13.py
new file mode 100644
index 0000000..1f5bd23
--- /dev/null
+++ b/day13.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+from collections import defaultdict
+from itertools import permutations
+
+costs = defaultdict(lambda: defaultdict(int))
+
+with open('day13.txt') as data:
+    for line in data:
+        line = line.strip('.\n').split()
+        costs[line[0]][line[-1]] = int(line[3]) * (-1 if line[2] == 'lose' else 1)
+
+def calculate_cost(ordering):
+    return sum(costs[ordering[i-1]][ordering[i]] + costs[ordering[i]][ordering[i-1]]for i in range(len(ordering)))
+
+# part 1
+print(max(calculate_cost(order) for order in permutations(costs.keys())))
+
+# part 2
+for key in set(costs.keys()):
+    costs[key]['Myself'] = 0
+    costs['Myself'][key] = 0
+
+print(max(calculate_cost(order) for order in permutations(costs.keys())))