47 lines
654 B
Python
47 lines
654 B
Python
input = "1"
|
|
|
|
def look_and_say(input):
|
|
s = ""
|
|
last = 'x'
|
|
count = 1
|
|
|
|
for n in input:
|
|
if last == 'x':
|
|
last = n
|
|
count = 1
|
|
continue;
|
|
|
|
if last == n:
|
|
count += 1
|
|
continue;
|
|
|
|
s+=f"{count}{last}"
|
|
|
|
last=n
|
|
count=1
|
|
|
|
return s+f"{count}{n}"
|
|
|
|
|
|
""" Not worth it
|
|
def recursive_look_and_say(input):
|
|
j = len(input)//2
|
|
|
|
while True:
|
|
if j == len(input)-1:
|
|
return look_and_say(input)
|
|
|
|
# Assert 'j' does not divide repeating characters
|
|
if input[j] != input[j+1]:
|
|
return recursive_look_and_say(input[:j+1])+ recursive_look_and_say(input[j+1:])
|
|
|
|
j+=1
|
|
"""
|
|
|
|
|
|
# Result
|
|
|
|
for i in range(50):
|
|
input = look_and_say(input)
|
|
print(len(input))
|