From e1d0c91525c94074e562f41102241b9eb0638bf7 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 1 Dec 2023 14:10:48 +0100 Subject: huh --- 2023/01/solve.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 2023/01/solve.py diff --git a/2023/01/solve.py b/2023/01/solve.py new file mode 100755 index 0000000..9da84bf --- /dev/null +++ b/2023/01/solve.py @@ -0,0 +1,17 @@ +#!/bin/env python + +# i don't like regex + +L = open("input").readlines() + +def part1(): + print(sum((n := list(filter(lambda x: x.isdigit(), l.strip())), int(n[0] + n[-1]))[1] for l in L)) + + +def part2(): + u = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] + print(sum((i := [int(p[0]) if p[0].isdigit() else u.index(p[: len(n)]) + 1 for p in r for n in u if p.startswith(n) or p[0].isdigit()], i[0] * 10 + i[-1])[1] for r in [[l[i : i + 7] for i in range(len(l))] for l in L])) + + +part1() +part2() -- cgit v1.2.3