2015 day-5 completion part 1 & 2

This commit is contained in:
Xevion
2019-11-23 16:48:15 -06:00
parent cd84a0ac04
commit dece4338c0
3 changed files with 1054 additions and 0 deletions

1000
2015/day-5/input Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
import os
import sys
import re
PATH = os.path.join(sys.path[0], '..', 'input')
DATA = open(PATH, 'r').read().split('\n')
PATTERN = r'(\w)\1'
def req1(string):
count = 0
for vowel in list('aeiou'):
count += string.count(vowel)
if count >= 3:
return True
return False
def req2(string):
return bool(re.search(PATTERN, string))
def req3(string):
for sub in ['ab', 'cd', 'pq', 'xy']:
if sub in string:
return False
return True
def reqAll(string):
return req3(string) and req1(string) and req2(string)
i = 0
for line in DATA:
i += 1 if reqAll(line) else 0
print(i)

View File

@@ -0,0 +1,22 @@
import os
import sys
import re
PATH = os.path.join(sys.path[0], '..', 'input')
DATA = open(PATH, 'r').read().split('\n')
PATTERN_1 = r'.*(\w\w).*\1.*'
PATTERN_2 = r'(\w)\w\1'
def req1(string):
return bool(re.match(PATTERN_1, string))
def req2(string):
return bool(re.search(PATTERN_2, string))
def reqAll(string):
return req1(string) and req2(string)
i = 0
for line in DATA:
i += 1 if reqAll(line) else 0
print(i)