diff options
| author | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-10 11:48:27 +0100 |
|---|---|---|
| committer | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-10 11:48:27 +0100 |
| commit | 20560f0bb5736a5b75fd4faac41b9d02e8af1636 (patch) | |
| tree | a6d493ed7a3c9b32086a3232ffbb1e4ed05c485a /2025/10 | |
| parent | e7c62d0e7f89df0bbb8ab8bff019671aa2933b86 (diff) | |
Add 2025 day 10 part 1 solution
Diffstat (limited to '2025/10')
| -rwxr-xr-x | 2025/10/puzzle-1.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/2025/10/puzzle-1.py b/2025/10/puzzle-1.py new file mode 100755 index 0000000..d27db0c --- /dev/null +++ b/2025/10/puzzle-1.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 + +import dataclasses +import functools +import itertools +import operator +from typing import Self + + +@dataclasses.dataclass +class Machine: + target: int + buttons: list[int] + + @classmethod + def from_record(cls, s: str) -> Self: + buttons: list[int] = [] + for token in s.split(' '): + match token[0]: + case '[': + token = token.translate({ + ord('.'): '0', + ord('#'): '1', + }) + target = int(token[len(token) - 2:0:-1], base=2) + case '(': + n = 0 + for x in map(int, token[1:-1].split(',')): + n |= 1 << x + buttons.append(n) + return cls(target, buttons) + + +def main() -> None: + with open('input', 'r') as f: + xs = [Machine.from_record(x) for x in f.readlines()] + print(sum(map(fewest_clicks, xs))) + + +def fewest_clicks(mach: Machine) -> int: + for i in itertools.count(start=1): + for comb in itertools.combinations_with_replacement(mach.buttons, i): + if functools.reduce(operator.xor, comb) == mach.target: + return i + # NOTREACHED + + +if __name__ == '__main__': + main() |