summaryrefslogtreecommitdiff
path: root/2024/13
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
committermhsn <mail@mhsn.net>2026-03-18 21:48:13 +0000
commit86bac31392a76da84817eec020d2b84d099b3cc1 (patch)
treee2ee52db59b86b914d5b4bcceb19c9b5d899fff4 /2024/13
parent62fe361fc42dea75deaf7ac31c0ba6ba80e26a9c (diff)
downloadpuzzles-86bac31392a76da84817eec020d2b84d099b3cc1.tar.gz
puzzles-86bac31392a76da84817eec020d2b84d099b3cc1.zip
add other challenges supportHEADmaster
Diffstat (limited to '2024/13')
-rwxr-xr-x2024/13/python.py40
1 files changed, 0 insertions, 40 deletions
diff --git a/2024/13/python.py b/2024/13/python.py
deleted file mode 100755
index e78e35f..0000000
--- a/2024/13/python.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env python3
-
-import re
-from fileinput import input
-from itertools import batched
-
-lines = [line.strip() for line in input()]
-
-
-re_button = r"Button [A|B]: X\+(\d+), Y\+(\d+)"
-re_prize = r"Prize: X=(\d+), Y=(\d+)"
-
-
-def solve(machine, gold):
- m = re.fullmatch(
- r"Button A: X\+(\d+), Y\+(\d+)Button B: X\+(\d+), Y\+(\d+)Prize: X=(\d+), Y=(\d+)",
- "".join(machine),
- )
- # 2x2 matrix solve
- ax, ay, bx, by, px, py = map(int, m.groups())
- if gold:
- px += 10000000000000
- py += 10000000000000
- det = ax * by - ay * bx
-
- A = (by * px - bx * py) / det
- B = (-ay * px + ax * py) / det
-
- # Check solutions are ints
- if abs(int(A) - A) < 1e-7 and abs(int(B) - B) < 1e-7:
- return 3 * int(A) + int(B)
- else:
- return 0
-
-
-silver = sum(solve(b, False) for b in batched(lines, 4))
-gold = sum(solve(b, True) for b in batched(lines, 4))
-
-print("silver:", silver)
-print("gold:", gold)