From cbb34bf643c6307c3fe1be92d664f818a67e41ee Mon Sep 17 00:00:00 2001 From: fwcd Date: Thu, 25 Jan 2024 04:50:26 +0100 Subject: [PATCH] Output choices --- day23/src/day23.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/day23/src/day23.rb b/day23/src/day23.rb index 8a1af4e..3605492 100755 --- a/day23/src/day23.rb +++ b/day23/src/day23.rb @@ -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 @@ -33,6 +33,7 @@ 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 @@ -40,7 +41,7 @@ def longest_path(matrix, visited = Set[], pos = [0, 1], slopes: true) 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