From 31730ffc5e9012219263f390ed56c4f99bd509d8 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Tue, 2 Jun 2026 14:32:47 +0200 Subject: [PATCH] 2015 day 10 --- adventofcode/2015/day10/day10.py | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 adventofcode/2015/day10/day10.py diff --git a/adventofcode/2015/day10/day10.py b/adventofcode/2015/day10/day10.py new file mode 100644 index 0000000..f5c19f5 --- /dev/null +++ b/adventofcode/2015/day10/day10.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import fileinput + + +def look_and_say(seq): + """ + Describe each element by counting the number of consecutive digits + of the same value and appending that count followed by the digit itself. + """ + ret = [] + current_char = seq[0] + current_count = 1 + for c in seq[1:]: + if c == current_char: + current_count += 1 + else: + ret.append(str(current_count)) + ret.append(current_char) + current_char = c + current_count = 1 + + # last char + ret.append(str(current_count)) + ret.append(current_char) + return "".join(ret) + + +def main(inp): + inp = list(inp) + for _ in range(40): + inp = look_and_say(inp) + print("Part 1:", len(inp)) + + for _ in range(10): # 40 + 10 = 50 + inp = look_and_say(inp) + print("Part 2:", len(inp)) + + +if __name__ == "__main__": + lines = next(x.rstrip() for x in fileinput.input()) + main(lines)