# Python 2.7.7 Code
# Jonathan Frech 25th of February, 2016
# edited 26th of February, 2016
# edited 28th of February, 2016
# edited 4th of March , 2016
# set the program's mode
MODE = ["sequence", "length", "lambda"][2]
# advance the sequence
def advance(seq):
# special case
if seq == "":
return "1"
# result
res = ""
# init
c = seq[0]
a = 1
seq = seq[1:len(seq)]
# loop (look at the sequence and 'say' it)
for s in seq:
if s == c:
a += 1
else:
res += str(a) + c
c = s
a = 1
# return
return res + str(a) + c
# generate the sequence
if MODE == "sequence":
seq = ""
while True:
seq = advance(seq)
print seq
# generate the sequence and get each entry's length
elif MODE == "length":
seq = ""
while True:
seq = advance(seq)
print len(seq)
# approximate lambda
elif MODE == "lambda":
seq = ""
while True:
nseq = advance(seq)
if len(seq) > 0:
print "lambda approx. " + str(1. * len(nseq) / len(seq))
seq = nseq