Skip to content

Commit

Permalink
2015 day 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacerulerwill committed Jan 7, 2025
1 parent f32fa53 commit f6baeb5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions puzzles/Y2015/D5/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Any


def puzzle(input: str) -> Any:
lines = [line.strip() for line in input.splitlines()]
nice_strings = 0
for line in lines:
vowel_count = 0
for char in line:
if char in "aeiou":
vowel_count += 1
if vowel_count < 3:
continue

for i in range(len(line) - 1):
if line[i] == line[i + 1]:
break
else:
continue

if any(substring in line for substring in ["ab", "cd", "pq", "xy"]):
continue
nice_strings += 1
return nice_strings
23 changes: 23 additions & 0 deletions puzzles/Y2015/D5/p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Any


def puzzle(input: str) -> Any:
lines = [line.strip() for line in input.splitlines()]
nice_strings = 0
for line in lines:
first = False
for i in range(len(line) - 3):
sub = line[i:i + 2]
if sub in line[i + 2:]:
first = True
break
if not first:
continue
second = False
for i in range(len(line) - 2):
if line[i] == line[i + 2]:
second = True
break
if second:
nice_strings += 1
return nice_strings

0 comments on commit f6baeb5

Please sign in to comment.