From ca1ceaa487d5ad6d40b88200745914289444dc57 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 9 May 2025 16:44:54 +0100 Subject: [PATCH] 2017: d05: ex2: add solution --- 2017/d05/ex2/ex2.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 2017/d05/ex2/ex2.py diff --git a/2017/d05/ex2/ex2.py b/2017/d05/ex2/ex2.py new file mode 100755 index 0000000..10f1f4d --- /dev/null +++ b/2017/d05/ex2/ex2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import itertools +import sys + + +def solve(input: str) -> int: + def parse(input: str) -> list[int]: + return [int(n) for n in input.splitlines()] + + instructions = parse(input) + offset = 0 + for i in itertools.count(): + if offset < 0 or offset >= len(instructions): + return i + delta = -1 if instructions[offset] >= 3 else 1 + instructions[offset] += delta + offset += instructions[offset] - delta # Account for previous increment + assert False # Sanity check + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()