Skip to content

Commit

Permalink
Solution for day 18, part 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Dec 22, 2024
1 parent 80616c4 commit b2287d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/aoc2024/days/ram_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def part1(steps: 1024, finish: [70, 70])
Common::AStar.solve(@start, finish, neighbours, cost, heuristic)
end

def part2(steps: 1024, finish: [70, 70])
pos = (steps...@positions.length).bsearch do |step|
part1(steps: step, finish: finish).nil?
end

@positions[pos - 1].join(',') # Array indexes start at 0!
end

def parse_input(input)
input.lines(chomp: true).map do |line|
line.split(',').map(&:to_i)
Expand Down
6 changes: 6 additions & 0 deletions test/days/ram_run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ def test_part1

assert_equal(22, @rr.part1(steps: 12, finish: [6, 6]))
end

def test_part2
@rr.setup(INPUT)

assert_equal('6,1', @rr.part2(steps: 12, finish: [6, 6]))
end
end

0 comments on commit b2287d0

Please sign in to comment.