Add: 10->12, 17
This commit is contained in:
46
2015/10.py
Normal file
46
2015/10.py
Normal file
@@ -0,0 +1,46 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user