advent of code day 3: i might be r-slurred edition

idk how to do multi line spoilers lol



letters = ['','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

total_score = 0

team = []

for line in open("input.txt"):
    team.append(line.strip())

for i in range(2, len(team), 3):
    for letter in team[i]:
        if letter in team[i-2] and letter in team[i-1]:
            total_score += letters.index(letter)
            break

print(total_score)

some real caveman shit but it works

80
Jump in the discussion.

No email address required.

Part 1:

print(sum([set([a - 0x60 if a > 0x60 else a - 0x26 for a in bytes(l[0:int(len(l)/2)],'ascii') if a in bytes(l[int(len(l)/2):],'ascii')]).pop() for l in open('resources/day3.txt').readlines()]))
Jump in the discussion.

No email address required.

Part 2:

print(sum((ord(set([c for c in g[0] if c in g[1] and c in g[2]][:-1]).pop()) + 20) % 58 for g in [ open('eval/day3part2.txt').readlines()[blk:blk+3] for blk in range(0,len(open('eval/day3part2.txt').readlines()),3)]))

There's probably a one-liner for chunking file.readlines() while only reading the file once (probably somewhere in itertools), but I'm done for today.

Part 1 using modulus and removing a few unnecessary iterator-to-list conversions:

print(sum(set((a + 20) % 58 for a in bytes(l[0:int(len(l)/2)],'ascii') if a in bytes(l[int(len(l)/2):],'ascii')).pop() for l in open('eval/day3part1.txt').readlines()))
Jump in the discussion.

No email address required.

I'm glad I wasn't the only one who had to open the file twice. Felt like it was dumb just to get the file length :marseydunce: but I guess you gotta

Jump in the discussion.

No email address required.

did a :marseyfortuneteller: steal your enter key?

Jump in the discussion.

No email address required.

Darn btfo my 1 liner

Jump in the discussion.

No email address required.

:marseynotes:

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.