You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
input = DATA.read
|
|
.scan(/\d+/).map(&:to_i)
|
|
.each_slice(2).to_a.transpose
|
|
.map(&:sort)
|
|
|
|
left, right = input
|
|
|
|
# part one
|
|
pp left.zip(right).sum { (_1 - _2).abs }
|
|
|
|
# part two
|
|
pp left.sum { _1 * right.count(_1) }
|
|
|
|
__END__
|
|
3 4
|
|
4 3
|
|
2 5
|
|
1 3
|
|
3 9
|
|
3 3
|