aboutsummaryrefslogtreecommitdiff
path: root/2015/15
diff options
context:
space:
mode:
Diffstat (limited to '2015/15')
-rw-r--r--2015/15/input4
-rwxr-xr-x2015/15/puzzle-1.py39
-rwxr-xr-x2015/15/puzzle-2.py41
3 files changed, 84 insertions, 0 deletions
diff --git a/2015/15/input b/2015/15/input
new file mode 100644
index 0000000..d1af06e
--- /dev/null
+++ b/2015/15/input
@@ -0,0 +1,4 @@
+Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2
+Sprinkles: capacity -3, durability 3, flavor 0, texture 0, calories 9
+Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1
+Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8
diff --git a/2015/15/puzzle-1.py b/2015/15/puzzle-1.py
new file mode 100755
index 0000000..806737c
--- /dev/null
+++ b/2015/15/puzzle-1.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+from math import prod
+import itertools
+import re
+
+
+def main() -> None:
+ data: list[list[int]] = []
+ with open("input", "r", encoding="utf-8") as f:
+ for line in f.readlines():
+ m = re.match(
+ r"[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)",
+ line,
+ )
+ data.append([int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))])
+
+ total: int = 0
+ for i in range(100):
+ for j in range(100 - i):
+ for k in range(100 - i - j):
+ if i + j + k > 100:
+ continue
+ h = 100 - i - j - k
+
+ parts: list[int] = []
+ parts.append(data[0][0] * i + data[1][0] * j + data[2][0] * k + data[3][0] * h)
+ parts.append(data[0][1] * i + data[1][1] * j + data[2][1] * k + data[3][1] * h)
+ parts.append(data[0][2] * i + data[1][2] * j + data[2][2] * k + data[3][2] * h)
+ parts.append(data[0][3] * i + data[1][3] * j + data[2][3] * k + data[3][3] * h)
+
+ if not any(map(lambda x: x < 0, parts)):
+ total = max(total, prod(parts))
+
+ print(total)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/2015/15/puzzle-2.py b/2015/15/puzzle-2.py
new file mode 100755
index 0000000..ec03a82
--- /dev/null
+++ b/2015/15/puzzle-2.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+from math import prod
+import itertools
+import re
+
+
+def main() -> None:
+ data: list[list[int]] = []
+ with open("input", "r", encoding="utf-8") as f:
+ for line in f.readlines():
+ m = re.match(
+ r"[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([0-9]+)",
+ line,
+ )
+ data.append(list(map(int, [m.group(i) for i in range(1, 6)])))
+
+ total: int = 0
+ for i in range(100):
+ for j in range(100 - i):
+ for k in range(100 - i - j):
+ if i + j + k > 100:
+ continue
+ h = 100 - i - j - k
+ if data[0][4] * i + data[1][4] * j + data[2][4] * k + data[3][4] * h != 500:
+ continue
+
+ parts: list[int] = []
+ parts.append(data[0][0] * i + data[1][0] * j + data[2][0] * k + data[3][0] * h)
+ parts.append(data[0][1] * i + data[1][1] * j + data[2][1] * k + data[3][1] * h)
+ parts.append(data[0][2] * i + data[1][2] * j + data[2][2] * k + data[3][2] * h)
+ parts.append(data[0][3] * i + data[1][3] * j + data[2][3] * k + data[3][3] * h)
+
+ if not any(map(lambda x: x < 0, parts)):
+ total = max(total, prod(parts))
+
+ print(total)
+
+
+if __name__ == "__main__":
+ main()