Skip to content

Instantly share code, notes, and snippets.

@mwormleonhard
Created August 11, 2014 17:31
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 mwormleonhard/b0c0bcfb320989befc50 to your computer and use it in GitHub Desktop.
Save mwormleonhard/b0c0bcfb320989befc50 to your computer and use it in GitHub Desktop.
Look-and-say-sequence generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# looksay.py
#
#----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <mwormleonhard@gmail.com> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
# Martin Worm-leonhard
# ----------------------------------------------------------------------------
def main():
seed = raw_input('Indtast seed (Enter = 1) > ')
if seed == "":
seed=1
else:
seed = int(seed)
numIter = raw_input("Antal iterationer (Enter = 25) ? > ")
if numIter == "":
numIter=25
else:
numIter=int(numIter)
for i in range(numIter):
print(seed)
seed=str(seed)
j=0
counter=0
newstring = ""
while j<len(seed):
digit=seed[j]
for k in range(j,len(seed)):
if seed[k] == digit:
counter+=1
else:
break
newstring += str(counter) + digit
j+=counter
counter = 0
seed = newstring
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment