blob: 420a596be22ed9ee9fc1448a9d1e97f707a5dcb3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
|