summaryrefslogtreecommitdiff
path: root/2024/01b/run.rb
diff options
context:
space:
mode:
Diffstat (limited to '2024/01b/run.rb')
-rwxr-xr-x2024/01b/run.rb24
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
+
+