-
-
Save mwormleonhard/b0c0bcfb320989befc50 to your computer and use it in GitHub Desktop.
Look-and-say-sequence generator
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
#!/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