From 6a0c619d743d57a1ff1684144c148c9b8cc9a0be Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Fri, 11 Dec 2015 12:23:59 +0100 Subject: [PATCH] Reimplement day 10 using itertools combine. Now it DOES run using pypy, and is faster again. --- day-10/solution.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/day-10/solution.py b/day-10/solution.py index b19a4eb..4313de6 100644 --- a/day-10/solution.py +++ b/day-10/solution.py @@ -1,20 +1,7 @@ +import itertools + def lookandsay(line): - p = None - n = 0 - result = [] - for c in line: - if n > 0 and p is not c: - result.append(str(n)) - result.append(p) - n = 0 - - p = c - n += 1 - - result.append(str(n)) - result.append(p) - - return ''.join(result) + return ''.join([str(len(list(it))) + c for c, it in itertools.groupby(line)]) line = "1321131112"