first commit

This commit is contained in:
Peter Hudec
2015-12-17 01:55:50 +01:00
commit 6a4482d038
35 changed files with 3965 additions and 0 deletions

26
10/part1.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python
import re
RE_MATCH_LONGEST = re.compile(r'(.)(\1*)')
def lookAndSay(sequence):
pos = 0
result = ""
while pos < len(sequence):
match = re.match(RE_MATCH_LONGEST, sequence[pos:])
pos += len(match.group(2)) + 1
result = "%s%d%s" % (result, len(match.group(2))+1, match.group(1))
return result
def main():
input = "1113222113"
for x in range(0, 40):
input = lookAndSay(input)
print len(input)
if __name__ == "__main__":
main()

26
10/part2.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python
import re
RE_MATCH_LONGEST = re.compile(r'(.)(\1*)')
def lookAndSay(sequence):
pos = 0
result = ""
while pos < len(sequence):
match = re.match(RE_MATCH_LONGEST, sequence[pos:])
pos += len(match.group(2)) + 1
result = "%s%d%s" % (result, len(match.group(2))+1, match.group(1))
return result
def main():
input = "1113222113"
for x in range(0, 50):
input = lookAndSay(input)
print len(input)
if __name__ == "__main__":
main()