diff options
Diffstat (limited to '2024/01a/run.rb')
-rwxr-xr-x | 2024/01a/run.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/2024/01a/run.rb b/2024/01a/run.rb new file mode 100755 index 0000000..420a596 --- /dev/null +++ b/2024/01a/run.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +data = File.read("data.txt") + +data = data.split("\n") +data = data.map(&:split) + +first_row = data.map { |data| data[0] }.sort +second_row = data.map { |data| data[1] }.sort + +merged = first_row.zip(second_row) + +distance = merged.map do |row| + (row[0].to_i - row[1].to_i).abs +end.sum + +p distance |