From ae9a02410ba769a44fba5a496350a46e25b5c005 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Tue, 3 Dec 2024 07:12:29 +0000 Subject: [PATCH] Add some checks to day1 --- day1/run.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/day1/run.py b/day1/run.py index a115614..292d41d 100644 --- a/day1/run.py +++ b/day1/run.py @@ -15,13 +15,21 @@ class SplitLists: self.list1, self.list2 = zip(*[val.split() for val in input.split("\n") if val]) def __str__(self) -> str: - part1 = 0 + return f"Part 1 = {self._part1}, Part 2 = {self._part2}" + + @property + def _part1(self) -> int: + outp = 0 for val in self.distances(): - part1 += val - part2 = 0 + outp += val + return outp + + @property + def _part2(self) -> int: + outp = 0 for val, occ in zip(self.list1, self.occurances()): - part2 += int(val) * occ - return f"Part1: {part1}\nPart2: {part2}" + outp += int(val) * occ + return outp def distances(self) -> List[int]: return [ @@ -33,12 +41,10 @@ class SplitLists: return [self.list2.count(key) for key in self.list1] -def main(*args, **kwargs) -> None: - example = SplitLists(input=EXAMPLE) - print(example) - with open("input.txt", "r") as f: - print(SplitLists(input=f.read())) - - if __name__ == "__main__": - main() + example = SplitLists(input=EXAMPLE) + print("EXAMPLE:\n", example) + assert example._part1 == 11 + assert example._part2 == 31 + with open("input.txt", "r") as f: + print("Puzzle:\n", SplitLists(input=f.read()))