Advertisement
musifter

AoC 2023, day 4, part 1 (dc)

Dec 4th, 2023 (edited)
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | Source Code | 0 0
  1. 0                       # sum
  2. ?
  3. [
  4.     # ASSUME: numbers on a card are unique in win and have sections
  5.     # This means checking either way works correctly.
  6.     0 Sh                # clear have table with push
  7.     [
  8.         1r:h            # have(top) = 1
  9.         d 0<L           # loop while next > 0 (0 is divider)
  10.     ] dsLx
  11.  
  12.     # use divider (0) for count of wins
  13.     [
  14.         r;h+            # wins++ if have(top)
  15.         z3<L
  16.     ] dsLx
  17.  
  18.     # stack: sum cardNum wins
  19.     rs.                 # junk cardNum
  20.     1-2r^ +             # sum += (2^(wins-1)); note: 2^(-1) floored to 0 for 0 wins
  21.  
  22.     ? z1<M
  23. ] dsMx
  24.  
  25. [Part 1: ]np
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement