Day one
This commit is contained in:
commit
9b78a63fba
3 changed files with 1027 additions and 0 deletions
14
1-1.rb
Executable file
14
1-1.rb
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require "debug"
|
||||||
|
|
||||||
|
input = File.readlines("1.input").map(&:split)
|
||||||
|
|
||||||
|
first = input.map(&:first).compact.sort
|
||||||
|
last = input.map(&:last).compact.sort
|
||||||
|
|
||||||
|
result = first.map.with_index do |v, i|
|
||||||
|
(v.to_i - last[i].to_i).abs
|
||||||
|
end.sum
|
||||||
|
|
||||||
|
puts result
|
12
1-2.rb
Executable file
12
1-2.rb
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
input = File.readlines("1.input").map(&:split)
|
||||||
|
|
||||||
|
first = input.map(&:first).compact
|
||||||
|
last = input.map(&:last).compact
|
||||||
|
|
||||||
|
result = first.map do |v|
|
||||||
|
v.to_i * last.select { _1.match?(v) }.size
|
||||||
|
end.sum
|
||||||
|
|
||||||
|
puts result
|
Loading…
Reference in a new issue