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.

didn't see the thread, here's my matlab code :marseytunaktunak:

A = readlines("input.txt","EmptyLineRule","skip")';

item = @(x) intersect(x(1:end/2),x(end/2+1:end));
iterfunc1 = @(x) item(char(x));
iterfunc2 = @(x,y,z) intersect(intersect(char(x),char(y)),char(z));

str1 = cell2mat(arrayfun(iterfunc1,A,'UniformOutput',false));
str2 = cell2mat(arrayfun(iterfunc2,A(1:3:end),A(2:3:end),A(3:3:end),'UniformOutput',false));

res1 = sum(str1,2)-sum(38-(38-96)*(str1>=97),2);
res2 = sum(str2,2)-sum(38-(38-96)*(str2>=97),2);

fprintf("Part 1 : %d\n",res1)
fprintf("Part 1 : %d\n",res2)
Jump in the discussion.

No email address required.

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