day 1
This commit is contained in:
commit
dfd296d8f4
|
@ -0,0 +1 @@
|
||||||
|
.vs
|
|
@ -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')
|
|
@ -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')
|
Loading…
Reference in New Issue