summaryrefslogtreecommitdiffstats
path: root/10/solution.py
diff options
context:
space:
mode:
Diffstat (limited to '10/solution.py')
-rw-r--r--10/solution.py33
1 files changed, 33 insertions, 0 deletions
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))