m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/06/b.rb
blob: aa29c00852cb9b0bd3c27e6943a096845190de01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
groups = File.read('input.txt').split("\n\n")

total = groups.reduce(0) do |total, group|
  answers = group.split("\n")
  
  all = answers.reduce(Hash.new true) do |all, answer|
    new_all = {}
    answer.each_char do |c|
      if all[c]
        new_all[c] = true
      end
    end
    new_all
  end
  subtotal = all.size
  total + subtotal
end

puts total