mirror of
https://github.com/ershisan99/advent-of-code.git
synced 2025-12-16 20:49:24 +00:00
2015 day 5
This commit is contained in:
1000
2015/day-5/input.txt
Normal file
1000
2015/day-5/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
21
2015/day-5/part-1.py
Normal file
21
2015/day-5/part-1.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||
# file_path = os.path.join(os.path.dirname(__file__), "./test-input.txt")
|
||||
input = open(file_path).read().strip()
|
||||
lines = input.split("\n")
|
||||
vowels = list("aeiou")
|
||||
forbidden_strings = ["ab", "cd", "pq", "xy"]
|
||||
|
||||
count = 0
|
||||
|
||||
for line in lines:
|
||||
if (
|
||||
any([forbidden_string in line for forbidden_string in forbidden_strings])
|
||||
or sum([line.count(vowel) for vowel in vowels]) < 3
|
||||
or not any([line[i + 1] == line[i] for i in range(len(line) - 1)])
|
||||
):
|
||||
continue
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
22
2015/day-5/part-2.py
Normal file
22
2015/day-5/part-2.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||
# file_path = os.path.join(os.path.dirname(__file__), "./test-input.txt")
|
||||
input = open(file_path).read().strip()
|
||||
lines = input.split("\n")
|
||||
|
||||
count = 0
|
||||
|
||||
for line in lines:
|
||||
if not any(
|
||||
[
|
||||
len(re.findall(pair, line)) >= 2
|
||||
for pair in {line[i] + line[i + 1] for i in range(len(line) - 1)}
|
||||
]
|
||||
) or not any([line[i + 2] == line[i] for i in range(len(line) - 2)]):
|
||||
continue
|
||||
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
5
2015/day-5/test-input.txt
Normal file
5
2015/day-5/test-input.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
qjhvhtzxzqqjkmpb
|
||||
xxyxx
|
||||
uurcxstgmygtbstg
|
||||
ieodomkazucvgmuy
|
||||
aaa
|
||||
Reference in New Issue
Block a user