Skip to content

Instantly share code, notes, and snippets.

@praveeng1618
Created October 17, 2019 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveeng1618/ab685a660e0e46d6907f2f43b5e3543c to your computer and use it in GitHub Desktop.
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.
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)
@praveeng1618
Copy link
Author

1 #
11 # one 1's
21 # two 1's
1211 # one 2, and one 1.
111221 # #one 1, one 2, and two 1's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment