Created
October 17, 2019 18:51
-
-
Save praveeng1618/ab685a660e0e46d6907f2f43b5e3543c to your computer and use it in GitHub Desktop.
A look-and-say sequence is defined as the integer sequence beginning with a single digit in which the next term is obtained by describing the previous term.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stri,n = input().split() | |
n = int(n) | |
print(stri) | |
def fun(init): | |
stri = "" | |
i = 0 | |
while i < len(init): | |
j = i + 1 | |
count = 1 | |
while j <= len(init)-1 : | |
count = 1 | |
if init[i] == init[j] : | |
count = count + 1 | |
j = j + 1 | |
else : | |
break | |
stri = stri + str(count) | |
stri = stri + str(init[i]) | |
i = j | |
print(stri) | |
return stri | |
for i in range(1,n): | |
stri = fun(stri) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 #
11 # one 1's
21 # two 1's
1211 # one 2, and one 1.
111221 # #one 1, one 2, and two 1's.