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.

:marseyno: ord() + offset

:marseyyes: 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']

Jump in the discussion.

No email address required.

it looks r-slurred but it was the first thing i thought of and I already have macros set up for the quoting and changing the case so it only really took as long as typing out the lowercase alphabet

looking back i should have just made it a string and saved on the commas

Jump in the discussion.

No email address required.

i think ord is the wrong way around. caps are first in ASCII but in advent of code they are last.

theoretically you could do this

get_num = lambda letter : (ord(letter)-97 if letter.islower() else ord(letter)-65+26)+1
for i in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print(get_num(i))

result is numbers 1-52

Jump in the discussion.

No email address required.

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