From 6474cc1727dd44f2abaf7312e8db4eb92d0a2302 Mon Sep 17 00:00:00 2001 From: Katie <5213160+KatieLG@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:30:59 +0000 Subject: [PATCH] improve day 20 performance --- AOC/uiua/solutions/day20.ua | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/AOC/uiua/solutions/day20.ua b/AOC/uiua/solutions/day20.ua index 091a93c..52cf815 100644 --- a/AOC/uiua/solutions/day20.ua +++ b/AOC/uiua/solutions/day20.ua @@ -10,25 +10,23 @@ End ← ⊢⊚⌕@EInput # end position Ns ← ▽≠@#:⟜⊡+A₂¤ # valid neighbours Solve ← ⊢path(Ns|≍End)Start # solve maze Saving! ← ( - ⊃(/+⌵-∩↘₁|⌵-∩⊢) # det grid distance and score distance - -∩×⟜:⊸≤^0 # only keep the savings for cheat lengths under the threshold + ⊃(/+⌵-∩↘₁|⌵-∩⊢)°⊟ # det grid distance and score distance + -∩×⟜:⊸≤^0 # only keep the savings for cheat lengths under the threshold ) +SolutionPath ← Solve Input Cheats! ← ( - .≡⊂°⊏ # add distances to solution path - ⊞( - ◡(≤∩□) # filter to upper quadrant to avoid doubling cheats - ⨬(0|Saving!^0) # get the savings for each pair - ) - ♭ + ≡⊂°⊏ # add distances to solution path + ⧅<2 # for each pair of coordinates on the path + ♭≡(Saving!^0) # what is the saving ) # Part A -Solve Input # get solution -Cheats!2 # get cheats of length at most 2 -/+≥100 # count how many are >= 100 +SolutionPath +Cheats!2 # get cheats of length at most 2 +/+≥100 # count how many are >= 100 # Part B -Solve Input # get solution -Cheats!20 # get cheats of length at most 20 -/+≥100 # count how many are >= 100 +SolutionPath +Cheats!20 # get cheats of length at most 20 +/+≥100 # count how many are >= 100