diff options
| author | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-11 19:46:40 +0100 |
|---|---|---|
| committer | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-11 19:46:40 +0100 |
| commit | 9a2ad027cc1dfe67502cb4ddb9204095a94a2842 (patch) | |
| tree | 4914d3553f3a49f66ce2c143ec779421ecfafbb6 | |
| parent | 9d8ad5ed628bd86f5b7ff1149686916e9403c3d2 (diff) | |
Add 2018 day 2 part 2 solution
| -rwxr-xr-x | 2018/02/puzzle-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2018/02/puzzle-2.py b/2018/02/puzzle-2.py new file mode 100755 index 0000000..37ce920 --- /dev/null +++ b/2018/02/puzzle-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import itertools + + +def main() -> None: + with open('input', 'r') as f: + xs = f.readlines() + print(next( + x for x in + itertools.starmap(common, itertools.combinations(xs, 2)) + if x is not None + ), end='') + + +def common(x: str, y: str) -> str | None: + it = (i for i, (a, b) in enumerate(zip(x, y)) if a != b) + i = next(it) + try: + next(it) + except StopIteration: + return x[:i] + x[i+1:] + + +if __name__ == '__main__': + main() |