aboutsummaryrefslogtreecommitdiff
path: root/2023/01/solve.py
blob: 9da84bf3f424791030ac4646155471e77c7d79b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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()