From bf4d2700e0e2532c117547c2eedf287d06651c6d Mon Sep 17 00:00:00 2001 From: StarlitGhost <679547+StarlitGhost@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:21:59 +0000 Subject: [PATCH] [2024/19] p1 solved --- .aoc_tiles/tiles/2024/19.png | Bin 0 -> 5199 bytes 2024/19/example | 10 +++++++ 2024/19/script.py | 51 +++++++++++++++++++++++++++++++++++ README.md | 7 +++-- 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .aoc_tiles/tiles/2024/19.png create mode 100644 2024/19/example create mode 100644 2024/19/script.py diff --git a/.aoc_tiles/tiles/2024/19.png b/.aoc_tiles/tiles/2024/19.png new file mode 100644 index 0000000000000000000000000000000000000000..50d74c1e60620cc996d5c45721318761eda99e4f GIT binary patch literal 5199 zcmV-V6tL@wP) zX;>6jy2npfH@&g%&D~|K#g%3mEcNeM-J@g{$85YUxUsigf~sZ=_`9l~6M73y%S<>AH^=kFCTPaSTxJgm67>@<{1$5?|d z+7T`TTwQh=o;$!;+gH3aHA05pqSoq~JC)T99cKz3WZiwF>C+9aXh*mVa8XMUxMr?c zLIEOkbC9_?OpElZs&8L^;9?csfQLXW7k{-PYSq`+$0hNhpS}Ge;VUYQwnM3|u5T}@ zZ8=>~^SDJ}xZ6N4r}azav7tTyfP2!LPwofGBBM1-O z671{p-MR(Kww|bKHBwpR8Un6@l*mrt=bVaNzunUI=>PyP1bYYh zI44BN;=^P-o|U<%7>gHgDWhDI#`?XoVeS4b1mVSn`u_Lp@hyr9haGS36?U&HPaO8bo%RMbzdC2@#*tx zzC6SyGQgvxwiy86<|ui0{=`|)f$omt`}OU+GYSC!yWg9OmTc+lnX&PphpW@&t;?_- zF8e&=L1QNX;N+&ozOMG@#!cxt=WabTq;tQP2`Z^=wigS1-5i91{&AccQKRNW2VA&a zYdbDrBwj;Hk#No56)Kg=jQpz2Z%)VB#Q1Q(lG^4#Z|85{Px5qrw%^DAkAJTE!_QYr zVW=?Tcr6>%ySp!{wS6x3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=AS5P;`Z&^NvJRyO0_%;x&6jMc)XN^5V26OWJ(ZbEIf7Jn)yFo zDlV;UnK;&K#k`4U3v2Sq>hR;7ckbM|d-v|=pMNfqNY0!&!@+1rxQuc8n?jvl|I^j- zrp}(@xm8A~9~`(CHQICAUuVvX8ME*7t@VFiWH@^M{rBI;#KdG~X7b?E!5C=h)$%ap z4rmJZoVv5;)E!gQ`c}o-z2^bxe5u;nS^z+1W+sheHN}M&XKQ&Faw+6_=ka)EAMkD5 zxUs0H=-$11FvkbUg%p=-c^GmjpA%a<>oKYxB@W##JCtBZ?^;SZFA3oq{1@-XD`CVz0y6m=x; z`3RRb*La@yk-X<4Tno9xJntiU&qugc;r8cwAIW<@!nGpz{{i6*(On}GdLsY;002ov JPDHLkV1hTXhBN>G literal 0 HcmV?d00001 diff --git a/2024/19/example b/2024/19/example new file mode 100644 index 0000000..29648be --- /dev/null +++ b/2024/19/example @@ -0,0 +1,10 @@ +r, wr, b, g, bwu, rb, gb, br + +brwrr +bggr +gbbr +rrbgbr +ubwu +bwurrg +brgr +bbrgwb diff --git a/2024/19/script.py b/2024/19/script.py new file mode 100644 index 0000000..803e7db --- /dev/null +++ b/2024/19/script.py @@ -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() diff --git a/README.md b/README.md index c4983f7..643ab02 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

- Advent of Code - 195/486 ⭐ + Advent of Code - 196/488 ⭐

- 2024 - 34 ⭐ - Python + 2024 - 35 ⭐ - Python

@@ -62,6 +62,9 @@ My solutions to the yearly Advents of Code + + +

2023 - 47 ⭐ - Python