From fd3a0a1b09c27addaf9a0f1671abba6d2131448e Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 1 Dec 2024 15:03:28 -0500 Subject: [PATCH] Adding aoc2025 --- 2024/day1/main.py | 41 +++++++++++++++++++++++++++++++++++++++ 2024/template/main.py | 19 ++++++++++++++++++ python_tools/aoc_utils.py | 8 ++++++++ 3 files changed, 68 insertions(+) create mode 100644 2024/day1/main.py create mode 100644 2024/template/main.py create mode 100644 python_tools/aoc_utils.py diff --git a/2024/day1/main.py b/2024/day1/main.py new file mode 100644 index 0000000..d77b5d2 --- /dev/null +++ b/2024/day1/main.py @@ -0,0 +1,41 @@ +import sys +import os +sys.path.insert(1, os.path.abspath('../../')) +from python_tools.aoc_utils import * +import collections as C + + +dict2 = C.defaultdict(lambda: 0) +list1 = [] +list2 = [] + +def part_one(input): + sum = 0 + for i in input: + x = i.split() + list1.append(x[0]) + list2.append(x[1]) + dict2[x[1]] += 1 + list1.sort() + list2.sort() + for i in range(len(list1)): + sum += abs(int(list1[i])-int(list2[i])) + print("Part_One:", sum) + + +def part_two(input): + p2_ans = 0 + for i in range(len(list1)): + p2_ans += abs(int(list1[i])*int(dict2[list1[i]])) + print("Part_Two:", p2_ans) + + + +def main(): + contents = file2list("input.txt") + part_one(contents) + part_two(contents) + +if __name__ == "__main__": + main() + diff --git a/2024/template/main.py b/2024/template/main.py new file mode 100644 index 0000000..9a83966 --- /dev/null +++ b/2024/template/main.py @@ -0,0 +1,19 @@ +import sys +import os +sys.path.insert(1, os.path.abspath('../../')) +from python_tools.aoc_utils import * + +def part_one(input): + pass + +def part_two(input): + pass + +def main(): + contents = file2list("test.txt") + part_one(contents) + part_two(contents) + +if __name__ == "__main__": + main() + diff --git a/python_tools/aoc_utils.py b/python_tools/aoc_utils.py new file mode 100644 index 0000000..d112e52 --- /dev/null +++ b/python_tools/aoc_utils.py @@ -0,0 +1,8 @@ + + +def file2list(filepath): + f = open(filepath, 'r') + return [x.strip() for x in f.readlines()] + + +