mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-05 23:14:16 -06:00
2015 day-5 completion part 1 & 2
This commit is contained in:
1000
2015/day-5/input
Normal file
1000
2015/day-5/input
Normal file
File diff suppressed because it is too large
Load Diff
32
2015/day-5/python/part_1.py
Normal file
32
2015/day-5/python/part_1.py
Normal 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)
|
||||
22
2015/day-5/python/part_2.py
Normal file
22
2015/day-5/python/part_2.py
Normal 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)
|
||||
Reference in New Issue
Block a user