-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest10.py
More file actions
32 lines (26 loc) · 971 Bytes
/
Copy pathpythontest10.py
File metadata and controls
32 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from itertools import groupby
def audioactive1(n): # faster compiled
strl = {("1","1","1"): "31", ("1","1"): "21", ("1",): "11",
("2","2","2"): "32", ("2","2"): "22", ("2",): "12",
("3","3","3"): "33", ("3","3"): "23", ("3",): "13" }
s = [1]
prec = str(s[-1])
for i in xrange(n-1):
r = []
for e,l in groupby(prec):
r.append( strl[tuple(l)] )
prec = "".join(r)
s.append( int(prec) )
return s
def audioactive2(n): # faster uncompiled
strl = {("1","1","1"): "31", ("1","1"): "21", ("1",): "11",
("2","2","2"): "32", ("2","2"): "22", ("2",): "12",
("3","3","3"): "33", ("3","3"): "23", ("3",): "13" }
result = [1]
prec = "1"
for i in xrange(n-1):
prec = "".join( strl[tuple(l)] for e,l in groupby(prec) )
result.append( int(prec) )
return result
s = audioactive2(31)[30]
print len(str(s))