From 0eea370f9de0009ade23d399c832053930f6d126 Mon Sep 17 00:00:00 2001 From: Tyler Hoffman Date: Sat, 7 Dec 2024 08:36:21 -0500 Subject: [PATCH 1/2] Solve 07.a --- aoc_2024/day_07/__init__.py | 0 aoc_2024/day_07/a.py | 51 +++++++++++++++++++++++++++++++++ aoc_2024/day_07/from_prompt.py | Bin 0 -> 276 bytes aoc_2024/day_07/input.txt | Bin 0 -> 24857 bytes aoc_2024/day_07/parser.py | 10 +++++++ tests/test_day_07/__init__.py | 0 tests/test_day_07/test_a.py | 10 +++++++ 7 files changed, 71 insertions(+) create mode 100644 aoc_2024/day_07/__init__.py create mode 100644 aoc_2024/day_07/a.py create mode 100644 aoc_2024/day_07/from_prompt.py create mode 100644 aoc_2024/day_07/input.txt create mode 100644 aoc_2024/day_07/parser.py create mode 100644 tests/test_day_07/__init__.py create mode 100644 tests/test_day_07/test_a.py diff --git a/aoc_2024/day_07/__init__.py b/aoc_2024/day_07/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2024/day_07/a.py b/aoc_2024/day_07/a.py new file mode 100644 index 0000000..b9878fa --- /dev/null +++ b/aoc_2024/day_07/a.py @@ -0,0 +1,51 @@ +from dataclasses import dataclass +from typing import Generator +from aoc_2024.day_07.parser import Parser + + +@dataclass +class Day07PartASolver: + equations: list[tuple[int, list[int]]] + + @property + def solution(self) -> int: + output = 0 + for answer, nums in self.equations: + if self.can_be_true(answer, nums): + output += answer + return output + + def can_be_true(self, answer: int, nums: list[int]) -> bool: + return True in self.has_solution(answer, nums, nums[0], 1) + + def has_solution( + self, + answer: int, + nums: list[int], + so_far: int, + index: int, + ) -> Generator[bool, None, None]: + if so_far > answer: + yield False + elif index == len(nums): + yield so_far == answer + else: + yield from self.has_solution(answer, nums, so_far + nums[index], index + 1) + yield from self.has_solution(answer, nums, so_far * nums[index], index + 1) + + +def solve(input: str) -> int: + data = Parser.parse(input) + solver = Day07PartASolver(data) + + return solver.solution + + +def get_solution() -> int: + with open("aoc_2024/day_07/input.txt", "r") as f: + input = f.read() + return solve(input) + + +if __name__ == "__main__": + print(get_solution()) diff --git a/aoc_2024/day_07/from_prompt.py b/aoc_2024/day_07/from_prompt.py new file mode 100644 index 0000000000000000000000000000000000000000..18573e90bf025ed95e650f0882b667c36144eb2e GIT binary patch literal 276 zcmV+v0qgz%M@dveQdv+`04t4hdlZF*K}zu1jj@&+xzhXN`km$GupMrJgEPwC3vX`XO@QZjo#q ach{K2NqC%meqRWq^)scJ;xY5T)}=euSceAy literal 0 HcmV?d00001 diff --git a/aoc_2024/day_07/input.txt b/aoc_2024/day_07/input.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb201688862cb142905c0275b2f9781776c1513b GIT binary patch literal 24857 zcmV(wK(L`Yx!XkY4o-fis$hfv&K+eU+5pmb2+k2`QWB!vss)G@F&x{hOcY%f31vXQ%}krM z(ibhfWuj%+sQ!tPIn?Tb3UG*jL@y40F>6jadEcXbpW&%$GL(FH`!(chd)9J?C>1Mr zr(5x5s;7W^WobESBF1w#Xi~Ea_jQfxYo66hw&cJbW{(`?7=;f=-A;XBhzGFS^{Xj} zOy}On6fG{FpvHIWm{gYdw!3at=E~|DnVGPlOlb)mLCb;ju1&Udfm3^6;w`F$*7^X$ zL?sJ_1Ud4`s-(GA;Wnp=r=3v1qUo^Yt}ej5iab~{o5vreB!Qs%Cp_~fQ&x85zw-Jl zJK~$M^YI3a!vbN^HOW>TadMbi=H=25zTE|!M|j$!_n$eP9@Cv~(3$ zi*l`l-@b+w4D*^);Fu*|DlBjcI76+4PET^LPiJ0WIiylAc~Z17bRLm6Z$IGw==#!%l0Hzo;+l1Jkm+`@}`vkHb9W?ePbsWqXlC(ae2-~*29*)Q?uu)Zb!tLSlT z>rO`$IaEd(AUo#`U4_Q<4ufd2p}XMl=&FlF4iFMF;IqNVlcNszE!6(t9VERP7R9T3 z(FGl_J#XV=*IHehn)OGqA=EEG_>*o@do%-X6#^v+1tgaS^%5b}DUF?;N-Y_I^L^N} z=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?YprDZoVDoULQ%^ISs5>-RU{tG$GW@g~+>ctN;67g12`0D|r1IT)36AVR}HJ54* z-Y1T{hH=aPPt?E)3KH|VFL#rHmq=dXnAt$8Dr4Nqcsd>MSW6)`sd^rhCuWsYmQUXg zyq9e}tO!u9zh#C&AW=THSz^aIK5nO&8mb!b*2wL`jO{vj63jxPmCTf5l4=O@8f{MZd^f#=lAs?aJr9J=AudBhX@$0bg;x#@a|R zO$BB4p(x_jX$5)BCE#Pp7fl<@8jmQVJ6&LQj$Qe#wyo(5j`gmoBuGQrzq zzRavy`@%UmJxMO1W43ShH*W%)F?d!7lQl@Ej}7Q)pZo<*kxZk&w7R+O6~hxdDsG@9 zc-@2Iqbjx6XxfulnQh5s_qInwNI+XxW-2Fz&USGvZR))v)<^REJyN2hz2K0Y#3v1c z5Nt}C$BL2U(i>I4_(r4le~Yil8t=L#dEf`J*5A(7aCpMR*hdi@@IRcu$+O{y?Jhb;7+ofLozd$|!$zgPRFi+aWg(LO4i%-lRF*C`P1{HnC2$a$Av??! QEaA25NQ-UC&8#in`|3VLbpQYW literal 0 HcmV?d00001 diff --git a/aoc_2024/day_07/parser.py b/aoc_2024/day_07/parser.py new file mode 100644 index 0000000..39fd658 --- /dev/null +++ b/aoc_2024/day_07/parser.py @@ -0,0 +1,10 @@ +class Parser: + @staticmethod + def parse(input: str) -> list[tuple[int, list[int]]]: + lines = input.strip().splitlines() + return [Parser.parse_line(line) for line in lines] + + @staticmethod + def parse_line(line: str) -> tuple[int, list[int]]: + left, right = line.split(": ") + return int(left), [int(num) for num in right.split(" ")] diff --git a/tests/test_day_07/__init__.py b/tests/test_day_07/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_day_07/test_a.py b/tests/test_day_07/test_a.py new file mode 100644 index 0000000..eeec72b --- /dev/null +++ b/tests/test_day_07/test_a.py @@ -0,0 +1,10 @@ +from aoc_2024.day_07.a import get_solution, solve +from aoc_2024.day_07.from_prompt import SAMPLE_DATA, SAMPLE_SOLUTION_A, SOLUTION_A + + +def test_solve(): + assert solve(SAMPLE_DATA) == SAMPLE_SOLUTION_A + + +def test_my_solution(): + assert get_solution() == SOLUTION_A From 775ad4ab124b174af71d0d1e9d597b617a69bcc3 Mon Sep 17 00:00:00 2001 From: Tyler Hoffman Date: Sat, 7 Dec 2024 08:39:59 -0500 Subject: [PATCH 2/2] Solve 07.b --- aoc_2024/day_07/b.py | 54 +++++++++++++++++++++++++++++++++ aoc_2024/day_07/from_prompt.py | Bin 276 -> 275 bytes tests/test_day_07/test_b.py | 10 ++++++ 3 files changed, 64 insertions(+) create mode 100644 aoc_2024/day_07/b.py create mode 100644 tests/test_day_07/test_b.py diff --git a/aoc_2024/day_07/b.py b/aoc_2024/day_07/b.py new file mode 100644 index 0000000..1ff5791 --- /dev/null +++ b/aoc_2024/day_07/b.py @@ -0,0 +1,54 @@ +from dataclasses import dataclass +from typing import Generator +from aoc_2024.day_07.parser import Parser + + +@dataclass +class Day07PartBSolver: + equations: list[tuple[int, list[int]]] + + @property + def solution(self) -> int: + output = 0 + for answer, nums in self.equations: + if self.can_be_true(answer, nums): + output += answer + return output + + def can_be_true(self, answer: int, nums: list[int]) -> bool: + return True in self.has_solution(answer, nums, nums[0], 1) + + def has_solution( + self, + answer: int, + nums: list[int], + so_far: int, + index: int, + ) -> Generator[bool, None, None]: + if so_far > answer: + yield False + elif index == len(nums): + yield so_far == answer + else: + yield from self.has_solution(answer, nums, so_far + nums[index], index + 1) + yield from self.has_solution(answer, nums, so_far * nums[index], index + 1) + yield from self.has_solution( + answer, nums, int(f"{so_far}{nums[index]}"), index + 1 + ) + + +def solve(input: str) -> int: + data = Parser.parse(input) + solver = Day07PartBSolver(data) + + return solver.solution + + +def get_solution() -> int: + with open("aoc_2024/day_07/input.txt", "r") as f: + input = f.read() + return solve(input) + + +if __name__ == "__main__": + print(get_solution()) diff --git a/aoc_2024/day_07/from_prompt.py b/aoc_2024/day_07/from_prompt.py index 18573e90bf025ed95e650f0882b667c36144eb2e..be75432f8a505e636a6c98d1b45290ba580bafa4 100644 GIT binary patch literal 275 zcmV+u0qp(&M@dveQdv+`0E%kJz^kCJ?&=!n2@77yX+1+BF%JNYgXAU+AL^M?n%%=1 z_Sz@-%I!Jg`CfLEHlA?HZn(PPRUs6{8#qCh&q=w{bMo=Z6 z@OXO7r8s)lFuR;QFGO#+Ei+cW{&G0r2|JLWAK(A&5ZcA&HtV?fjQK&jl|3x(9Z?uu zHY4{3cA-XN`km$GupMrJgEPwC3vX`XO@QZjo#q ach{K2NqC%meqRWq^)scJ;xY5T)}=euSceAy diff --git a/tests/test_day_07/test_b.py b/tests/test_day_07/test_b.py new file mode 100644 index 0000000..b140cbf --- /dev/null +++ b/tests/test_day_07/test_b.py @@ -0,0 +1,10 @@ +from aoc_2024.day_07.b import get_solution, solve +from aoc_2024.day_07.from_prompt import SAMPLE_DATA, SAMPLE_SOLUTION_B, SOLUTION_B + + +def test_solve(): + assert solve(SAMPLE_DATA) == SAMPLE_SOLUTION_B + + +def test_my_solution(): + assert get_solution() == SOLUTION_B