Advertisement
musifter

AoC 2023, day 4, part 2 (dc)

Dec 4th, 2023 (edited)
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.91 KB | Source Code | 0 0
  1. [q] sQ
  2. 0                       # sum
  3. ?
  4. [
  5.     # ASSUME: numbers on a card are unique (as are winning numbers)
  6.     # This means checking either way works correctly.
  7.     0 Sh                # clear have table with push
  8.     [
  9.         1r:h            # have(top) = 1
  10.         d 0<L           # loop while next > 0 (0 is divider)
  11.     ] dsLx
  12.  
  13.     # use divider (0) for count of wins
  14.     [
  15.         r;h+            # wins++ if have(top)
  16.         z3<L
  17.     ] dsLx
  18.  
  19.     # Stack: sum i=cardNum j=wins
  20.     rd;c 1+             # sum j i cards(i) (+1 for inital)
  21.     d5R+_4R sc          # c = cards(i); a += cards(i)
  22.  
  23.     r                   # i j
  24.     [
  25.         d0=Q            # quit if j=0
  26.         d3R d3R+ d;c    # j i i+j numCards(i+j)
  27.         lc+ r:c         # cards(i+j) = numCards(i+j) + c
  28.         r1- lLx         # i j--
  29.     ] dsLx
  30.     +s.                 # clear i and j
  31.  
  32.     ? z1<M
  33. ] dsMx
  34.  
  35. [Part 2: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement