Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,22 @@
def lookandsay(number):
result = ""
repeat = number[0]
number = number[1:]+" "
times = 1
for actual in number:
if actual != repeat:
result += str(times)+repeat
times = 1
repeat = actual
else:
times += 1
return result
num = "1"
for i in range(10):
print num
num = lookandsay(num)

View file

@ -0,0 +1,9 @@
>>> from itertools import groupby
>>> def lookandsay(number):
return ''.join( str(len(list(g))) + k
for k,g in groupby(number) )
>>> numberstring='1'
>>> for i in range(10):
print numberstring
numberstring = lookandsay(numberstring)

View file

@ -0,0 +1,20 @@
>>> from itertools import groupby, islice
>>>
>>> def lookandsay(number='1'):
while True:
yield number
number = ''.join( str(len(list(g))) + k
for k,g in groupby(number) )
>>> print('\n'.join(islice(lookandsay(), 10)))
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211

View file

@ -0,0 +1,9 @@
import re
def lookandsay(str):
return re.sub(r'(.)\1*', lambda m: str(len(m.group(0))) + m.group(1), str)
num = "1"
for i in range(10):
print num
num = lookandsay(num)