30 lines
467 B
Ruby
Executable File
30 lines
467 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'pry'
|
|
|
|
# Part 1
|
|
|
|
real_input = File.read("./input")
|
|
sample = '3 4
|
|
4 3
|
|
2 5
|
|
1 3
|
|
3 9
|
|
3 3'
|
|
|
|
input = real_input
|
|
|
|
col1 = input.split("\n").map(&:split).map{ | pair | pair[0].to_i}.sort
|
|
col2 = input.split("\n").map(&:split).map{ | pair | pair[1].to_i}.sort
|
|
|
|
#binding.pry
|
|
|
|
solution = col1.zip(col2).map{ | left, right | (right - left).abs }.sum
|
|
puts solution
|
|
|
|
# Part 2
|
|
|
|
p2 = col1.map{ | value | value * col2.count(value)}.sum
|
|
puts p2
|
|
|