Adding aoc2025

This commit is contained in:
Daniel Weber 2024-12-01 15:03:28 -05:00
parent aebf78646d
commit fd3a0a1b09
3 changed files with 68 additions and 0 deletions

41
2024/day1/main.py Normal file
View File

@ -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()

19
2024/template/main.py Normal file
View File

@ -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()

View File

@ -0,0 +1,8 @@
def file2list(filepath):
f = open(filepath, 'r')
return [x.strip() for x in f.readlines()]