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.

ruby is a wonderful language and so much more pleasant to script in than python

def part_one()
  sacks = File.read("input.txt").split

  compartments = sacks.map do |sack|
    sack.chars.partition.with_index { |_, i| i < sack.length / 2 }
  end

  shared_letters = compartments.map { |c| c.reduce(&:&) }.flatten
  summed_priorities(shared_letters)
end

def part_two()
  groups = File.read('input.txt').split.each_slice(3).to_a

  badges = groups.map do |sacks|
    sacks.map(&:chars).reduce(&:&)
  end.flatten

  summed_priorities(badges)
end

def summed_priorities(list)
  letters = ('a'..'z').to_a + ('A'..'Z').to_a
  priorities = Hash[(1..letters.size).zip(letters)].invert

  list.map { |l| priorities[l] }.reduce(&:+)
end

![](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fflamingtext.com%2Fnet-fu%2Fproxy_form.cgi%3Fimageoutput%3Dtrue%26script%3Dalien-glow-anim-logo%26text%3Di%2520love%2520!YOU!%26doScale%3Dtrue%26scaleWidth%3D480%26scaleHeight%3D240)

Jump in the discussion.

No email address required.

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