diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-24 22:25:42 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-24 22:25:42 +0000 |
commit | a7a6b86002b595bc167af72606b14c67ed1bdf8f (patch) | |
tree | bff94329cf969bd9df68d3b9782fee2107db56c2 /10 | |
download | aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.gz aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.xz aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.zip |
init commit
Diffstat (limited to '10')
-rw-r--r-- | 10/input | 1 | ||||
-rw-r--r-- | 10/solution.py | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/10/input b/10/input new file mode 100644 index 0000000..ec6ebd7 --- /dev/null +++ b/10/input @@ -0,0 +1 @@ +1113222113 diff --git a/10/solution.py b/10/solution.py new file mode 100644 index 0000000..51a569f --- /dev/null +++ b/10/solution.py @@ -0,0 +1,33 @@ +from collections import Counter + +def look_and_say(n: str) -> str: + """ + for every consecutive chunk of characters, count the number of characters, concatenate the chunk length and the character + """ + res = [] + char = n[0] + count = 1 + for c in n[1:]: + if c == char: + count += 1 + else: + res.append(str(count) + char) + char = c + count = 1 + res.append(str(count) + char) + return ''.join(res) + +def part1(n: str) -> str: + for i in range(40): + n = look_and_say(n) + return len(n) + +def part2(n: str) -> str: + for i in range(50): + n = look_and_say(n) + return len(n) + +if __name__ == '__main__': + inp = '1113222113' + print(part1(inp)) + print(part2(inp)) |