[2022][ruby][3.x]

pull/1/head
Alpha Chen 1 year ago
parent e1016ab913
commit ccdfedbbb6
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,13 @@
priorities = ((?a..?z).to_a + (?A..?Z).to_a).map.with_index { [_1, _2+1] }.to_h
# part 1
# p ARGF.read.lines(chomp: true).map {|line|
# len = line.length
# a = line[0...len/2]
# b = line[len/2..]
# priorities.fetch((a.chars & b.chars)[0])
# }.sum
p ARGF.read.lines(chomp: true).each_slice(3).map {|chunk|
priorities.fetch(chunk.map(&:chars).inject(&:&)[0])
}.sum
Loading…
Cancel
Save