summaryrefslogtreecommitdiff
path: root/2024/01b/run.rb
blob: 29d9539dfa326c74fbc123a86e65e8a465a2f30a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby

data = File.read("data.txt")

data = data.split("\n")
data = data.map(&:split)

first_row = data.map { |data| data[0].to_i }
second_row = {}

data.map do |data| 
  value = data[1].to_i
  count = second_row[value] ? second_row[value] + 1 : 1
  second_row[value] =  count
end

similiarity = first_row.map do |value|
  multiplayer = second_row.fetch(value, 0)
  value * multiplayer
end.sum

p similiarity