Skip to content

Commit

Permalink
Output choices
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jan 25, 2024
1 parent 54e0c1f commit cbb34bf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions day23/src/day23.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def neighbors(matrix, pos, slopes: true)
.map { |a| a[1] }
end

def longest_path(matrix, visited = Set[], pos = [0, 1], slopes: true)
def longest_path(matrix, visited = Set[], pos = [0, 1], choices = [], slopes: true)
visited.add(pos)

# Follow path until we reach a choice point or the end
Expand All @@ -33,14 +33,15 @@ def longest_path(matrix, visited = Set[], pos = [0, 1], slopes: true)
visited.add(pos)
end

puts "#{choices}"
if n.size == 0
if pos == [matrix.size - 1, matrix[0].size - 2]
visited.size - 1
else
0
end
else
n.map { |p| longest_path(matrix, visited.clone, p, slopes: slopes) }.max
n.each_with_index.map { |p, i| longest_path(matrix, visited.clone, p, choices + [i], slopes: slopes) }.max
end
end

Expand Down

0 comments on commit cbb34bf

Please sign in to comment.