Skip to content

Commit

Permalink
improve day 20 performance
Browse files Browse the repository at this point in the history
  • Loading branch information
KatieLG committed Jan 4, 2025
1 parent 0551a16 commit 6474cc1
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions AOC/uiua/solutions/day20.ua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6474cc1

Please sign in to comment.