commit ba4105f018fefce8ad96540e6bdde27a4a9e7039 Author: Armin Friedl Date: Sun Dec 1 18:53:33 2024 +0100 Day 01 diff --git a/day01.py b/day01.py new file mode 100644 index 0000000..6f05d19 --- /dev/null +++ b/day01.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +from collections import Counter +from functools import reduce + +# 1 + +with open("day01") as f: + lines = f.readlines() + +els = [l.split() for l in lines] +l1 = [int(el[0]) for el in els] +l2 = [int(el[1]) for el in els] + +l1.sort() +l2.sort() + +d = [abs(e[0] - e[1]) for e in zip(l1, l2)] +res = sum(d) + + +# 2 +ctn = Counter(l2) +res = reduce(lambda accum, e: accum + e*ctn.get(e, 0), l1, 0)