Skip to content

Commit

Permalink
2024 day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
becojo committed Dec 1, 2024
1 parent 5f5f5b4 commit b67b2cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 2024/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/[0-9]
/[0-9][0-9]
6 changes: 6 additions & 0 deletions 2024/1-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
3 4
4 3
2 5
1 3
3 9
3 3
25 changes: 25 additions & 0 deletions 2024/1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
input = ARGF.read.lines
ax = []
bx = []

input.each do |line|
a, b = line.split.map(&:to_i)
ax << a
bx << b
end

ax.sort!
bx.sort!

part1 = ax.zip(bx).map do |(a, b)|
(b - a).abs
end.sum

puts part1

bf = bx.group_by(&:itself).transform_values(&:size)
part2 = ax.map do |a|
a * bf.fetch(a, 0)
end.sum

puts part2

0 comments on commit b67b2cc

Please sign in to comment.