Skip to content

Instantly share code, notes, and snippets.

@mwormleonhard

mwormleonhard/looksay.py Secret

Created Aug 11, 2014
Embed
What would you like to do?
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
You can’t perform that action at this time.