musifter

AoC 2025, day 10 part 1 (dc)

Dec 20th, 2025
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | Source Code | 0 0
  1. [rs.q]  sQ                   # clear depth and return numButtons
  2. [F++q] sX                    # return a big number (15 + depth + numButtons)
  3. [r] sr                       # reverse top of stack
  4.  
  5. # XOR button into current array: buttonArray ->
  6. [
  7.     Fr x                    # conx1 conx2 ... 15 (sentinel)
  8.     [
  9.         d;c 1r- r:c         # curr[conx1] = !curr[conx1]
  10.         dF>I
  11.     ] dsIx s.
  12. ] s^
  13.  
  14.  
  15. # Recurse binary: numButtons depth -> minimum button presses
  16. [
  17.     0d                       # i=0 sum=0 numButtons depth
  18.     [
  19.         d;c 3R A*+           # sum = sum*10 + curr[i]
  20.         r1+ dll>C
  21.     ] dsCx s.                # current numButtons depth
  22.  
  23.         lp=Q                # return (numButtons) if (pattern == curr)
  24.     rd  ln<X                # if (depth > numButtons) return (result F^F)
  25.  
  26.     # depth numButtons
  27.     d;b dl^x                # xor current with button[depth] to press
  28.     _3R 1+ d3R d3R          # depth++ numButtons numButtons depth [butt]
  29.     r1+ lRx                 # recurse( numButtons+1, depth+1 )
  30.  
  31.     # result numButons depth [butt]
  32.     4R l^x                  # xor current with button[depth] to unpress
  33.     _3R lRx                 # recurse( numButtons, depth+1 )
  34.  
  35.     d3R d3R                 # ret1 ret2 ret2 ret1
  36.     >r s.                   # put max on top and delete it
  37. ] sR
  38.  
  39. ?
  40. [
  41.     0                           # i [jolts] [butt1] [butt2] ... [buttn] [input]
  42.     [
  43.         1+                      # i++
  44.         d4R r:b                 # button[i] = [butt1]; i jolts butt2 ... input
  45.         z3<L
  46.     ] dsLx
  47.  
  48.     sn                          # n = number of buttons
  49.     rx sp                       # p = light pattern
  50.     xz sl                       # l = number of lights (from jolt elements)
  51.     c                           # clear jolt elements
  52.  
  53.     1 0 lRx                     # recurse( numButtons=0, depth=1 )
  54.     ls+ss                       # sum += result
  55.  
  56.     ? z0<M
  57. ] dsMx
  58.  
  59. [Part 1: ]nlsp
Advertisement
Add Comment
Please, Sign In to add comment