Please Criticize My Code
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Sat Aug 20 05:01:55 EDT 2005
Two versions of mine, one of the fastest (not using Psyco) and one of
the shortest:
. from itertools import groupby
.
. def audioactiveFast(n):
. 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
.
.
. def audioactiveShort(n):
. s = [1]
. for i in xrange(n-1):
. r = 0
. for e,l in groupby(str(s[-1])):
. r = r*100 + len(list(l))*10 + int(e)
. s.append( r )
. return s
Bye,
bearophile
More information about the Python-list
mailing list