mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Reimplement day 10 using itertools combine.
Now it DOES run using pypy, and is faster again.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user