diff options
author | mms <michal@sapka.me> | 2024-12-02 14:18:16 +0100 |
---|---|---|
committer | mms <michal@sapka.me> | 2024-12-02 14:18:16 +0100 |
commit | 558e9a668287b318a400725d1b6ad38e6753d54c (patch) | |
tree | 2416a52db75f55353013245f00bb5e72b0247507 /2024/01b/run.rb |
2024@1-2
Diffstat (limited to '2024/01b/run.rb')
-rwxr-xr-x | 2024/01b/run.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2024/01b/run.rb b/2024/01b/run.rb new file mode 100755 index 0000000..29d9539 --- /dev/null +++ b/2024/01b/run.rb @@ -0,0 +1,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 + + |