Adding aoc2025
This commit is contained in:
parent
aebf78646d
commit
fd3a0a1b09
41
2024/day1/main.py
Normal file
41
2024/day1/main.py
Normal 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
19
2024/template/main.py
Normal 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()
|
||||
|
8
python_tools/aoc_utils.py
Normal file
8
python_tools/aoc_utils.py
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
def file2list(filepath):
|
||||
f = open(filepath, 'r')
|
||||
return [x.strip() for x in f.readlines()]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user