From dfd296d8f48973077d53f8b3919dc094995ed37b Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Wed, 4 Dec 2024 18:00:43 -0500 Subject: [PATCH] day 1 --- .gitignore | 1 + day_01/part_a.py | 11 +++++++++++ day_01/part_b.py | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 .gitignore create mode 100644 day_01/part_a.py create mode 100644 day_01/part_b.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a34381 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vs \ No newline at end of file diff --git a/day_01/part_a.py b/day_01/part_a.py new file mode 100644 index 0000000..aaa1185 --- /dev/null +++ b/day_01/part_a.py @@ -0,0 +1,11 @@ +import aocd + +def solve(data): + pairs = zip(*(map(sorted, zip(*(map(int, line.split()) for line in data.split('\n')))))) + return sum(abs(a-b) for a,b in pairs) + +if __name__ == '__main__': + solution = solve(aocd.get_data(year=2024, day=1)) + + print(solution) + aocd.submit(solution, year=2024, day=1, part='a') \ No newline at end of file diff --git a/day_01/part_b.py b/day_01/part_b.py new file mode 100644 index 0000000..1fa14e4 --- /dev/null +++ b/day_01/part_b.py @@ -0,0 +1,11 @@ +import aocd + +def solve(data): + list_a, list_b = zip(*(map(int, line.split()) for line in data.split('\n'))) + return sum(num*list_a.count(num)*list_b.count(num) for num in set(list_a)) + +if __name__ == '__main__': + solution = solve(aocd.get_data(year=2024, day=1)) + + print(solution) + aocd.submit(solution, year='2024', day=1, part='b') \ No newline at end of file