Skip to content

Commit

Permalink
fix part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
golubitsky committed Sep 16, 2024
1 parent 9c8f7af commit f14d71c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dsa/advent-of-code/2017/day_20.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def manhattan_distance(particle)

def index_of_min_distance(particles)
lowest = Float::INFINITY
lowest_index = -1
lowest_index = nil

particles.each_with_index do |particle, index|
m = manhattan_distance(particle)
Expand All @@ -41,7 +41,7 @@ def index_of_min_distance(particles)
lowest_index
end

def solution(data, part = 1)
def solution(data, part)
particles = parsed_particles(data)

last_index = -1
Expand Down Expand Up @@ -78,7 +78,7 @@ def solution(data, part = 1)

# heuristic: assume that if the same particle is closest n times in a row
# it will always be closest
arbitrary_threshold = 100
arbitrary_threshold = 500
if count == arbitrary_threshold
return last_index if part == 1
return particles.count if part == 2
Expand All @@ -88,5 +88,6 @@ def solution(data, part = 1)

if __FILE__ == $0
data = File.readlines('day_20_input.txt')
pp solution(data, part = 1)
pp solution(data, part = 2)
end

0 comments on commit f14d71c

Please sign in to comment.