Skip to content

Latest commit

 

History

History
50 lines (41 loc) · 1.59 KB

1.md

File metadata and controls

50 lines (41 loc) · 1.59 KB

Day 1

Was it just me or was that a trickier Day 1 than usual? A challenger Jonah Eng vies to steal my championship spot, and succeeds... for today.

Part 1 Part 2 Total
Time 5:04 13:27 18:31

Part 1

Took me a bit to figure out that my data getter was parsing adjacent digits as one. Solved dirtily by converting to strings, then grabbing the correct value.

from helpers.datagetter import aocd_data_in

din, aocd_submit = aocd_data_in(split=True, numbers=True)

sum = 0
for line in din:
    sum += int(str("%s%s" % (str(line[0])[0], str(line[-1])[-1])))

aocd_submit(sum)

Part 2

Do I want to tell you how long I stared at the code waiting for rindex to pop into my head? Well you can check the table above.

from helpers.datagetter import aocd_data_in

din, aocd_submit = aocd_data_in(split=True, numbers=False)

digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "|", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
sum = 0
for line in din:
    first = len(line)
    first_dig = -1
    last = 0
    last_dig = 0
    for dig in digits:
        if str(dig) not in line:
            continue
        if line.index(str(dig)) <= first:
            first = line.index(str(dig))
            first_dig = dig
        if line.rindex(str(dig)) >= last:
            last = line.rindex(str(dig))
            last_dig = dig
    first_dig = digits.index(first_dig) % 10
    last_dig = digits.index(last_dig) % 10
    sum += int(str("%s%s" % (first_dig, last_dig)))

aocd_submit(sum)