You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2022/ruby/day_03.rb

9 lines
284 B

priorities = (?a..?z).chain(?A..?Z).each.with_index.to_h { [_1, _2+1] }
input = ARGF.read.lines(chomp: true).map(&:chars)
# part 1
p input.sum { priorities.fetch(_1.each_slice(_1.length/2).inject(&:&)[0]) }
# part 2
p input.each_slice(3).sum { priorities.fetch(_1.inject(&:&)[0]) }