From abd946c749238552deaf211130b03b49fa52057e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 9 May 2025 16:44:39 +0100 Subject: [PATCH] 2017: d05: ex1: add solution --- 2017/d05/ex1/ex1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 2017/d05/ex1/ex1.py diff --git a/2017/d05/ex1/ex1.py b/2017/d05/ex1/ex1.py new file mode 100755 index 0000000..7a09715 --- /dev/null +++ b/2017/d05/ex1/ex1.py @@ -0,0 +1,27 @@ +#!/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 + instructions[offset] += 1 + offset += instructions[offset] - 1 # Account for previous increment + assert False # Sanity check + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()