Skip to content

Commit

Permalink
[2024/19] p1 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 19, 2024
1 parent c82521a commit bf4d270
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
Binary file added .aoc_tiles/tiles/2024/19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions 2024/19/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
r, wr, b, g, bwu, rb, gb, br

brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb
51 changes: 51 additions & 0 deletions 2024/19/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from GhostyUtils import aoc
from functools import cache
import re


"""
@cache
def validate(design: str, patterns: frozenset[str]) -> bool:
if design in patterns:
if aoc.args.verbose or aoc.args.progress:
print(f"{design} - found")
return True
else:
# try all splits
valid = False
for i in range(1, len(design)-1):
valid = validate(design[:i], patterns) and validate(design[i:], patterns)
if valid:
break
return valid
return False
"""


def validate(design: str, patterns: frozenset[str]) -> bool:
pattern = re.compile(r"^(" + r'|'.join(patterns) + r")+$")
return re.match(pattern, design)


def main():
patterns, designs = aoc.read_sections()
patterns = frozenset(patterns.split(', '))
designs = designs.splitlines()

valid = 0
for design in designs:
if validate(design, patterns):
if aoc.args.verbose or aoc.args.progress:
print(f"1 - {design}")
valid += 1
else:
if aoc.args.verbose or aoc.args.progress:
print(f"0 - {design}")

print(f"p1: {valid}")


if __name__ == "__main__":
main()
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

<!-- AOC TILES BEGIN -->
<h1 align="center">
Advent of Code - 195/486
Advent of Code - 196/488
</h1>
<h1 align="center">
2024 - 34 ⭐ - Python
2024 - 35 ⭐ - Python
</h1>
<a href="2024/1/script.py">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
Expand Down Expand Up @@ -62,6 +62,9 @@ My solutions to the yearly Advents of Code
<a href="2024/18/script.py">
<img src=".aoc_tiles/tiles/2024/18.png" width="161px">
</a>
<a href="2024/19/script.py">
<img src=".aoc_tiles/tiles/2024/19.png" width="161px">
</a>
<h1 align="center">
2023 - 47 ⭐ - Python
</h1>
Expand Down

0 comments on commit bf4d270

Please sign in to comment.