first commit
This commit is contained in:
5
05/input2
Normal file
5
05/input2
Normal file
@ -0,0 +1,5 @@
|
||||
ugknbfddgicrmopn
|
||||
aaa
|
||||
jchzalrnumimnmhp
|
||||
haegwjzuvuyypxyu
|
||||
dvszwmarrgswjxmb
|
||||
4
05/input3
Normal file
4
05/input3
Normal file
@ -0,0 +1,4 @@
|
||||
qjhvhtzxzqqjkmpb
|
||||
xxyxx
|
||||
uurcxstgmygtbstg
|
||||
ieodomkazucvgmuy
|
||||
49
05/part1.py
Normal file
49
05/part1.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def count_vovels(line):
|
||||
count = 0
|
||||
for vovel in ['a', 'e', 'i', 'o', 'u']:
|
||||
count = count + line.count(vovel)
|
||||
return count
|
||||
|
||||
|
||||
def count_bad(line):
|
||||
count = 0
|
||||
for vovel in ['ab', 'cd', 'pq', 'xy']:
|
||||
count = count + line.count(vovel)
|
||||
return count
|
||||
|
||||
def count_double(line):
|
||||
regexp = re.compile(r"(.)\1")
|
||||
match = re.search(regexp, line)
|
||||
if match:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def main():
|
||||
nice = 0
|
||||
for line in read_file('input'):
|
||||
if count_vovels(line) < 3:
|
||||
continue
|
||||
if count_double(line) < 1:
|
||||
continue
|
||||
if count_bad(line) > 0:
|
||||
continue
|
||||
nice = nice + 1
|
||||
|
||||
print nice
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
43
05/part2.py
Normal file
43
05/part2.py
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def count_twice(line):
|
||||
regexp = re.compile(r"(..).*\1")
|
||||
match = re.search(regexp, line)
|
||||
if match:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def count_repeat(line):
|
||||
regexp = re.compile(r"(.).\1")
|
||||
match = re.search(regexp, line)
|
||||
if match:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
nice = 0
|
||||
for line in read_file('input'):
|
||||
if not count_twice(line):
|
||||
continue
|
||||
if not count_repeat(line):
|
||||
continue
|
||||
nice = nice + 1
|
||||
|
||||
print nice
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user