Advertisement
musifter

AoC 2022, day 3, part 2 (dc)

Jan 16th, 2023 (edited)
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | Source Code | 0 0
  1. [q] sQ
  2.  
  3. # Score priority, reset and quit to main loop
  4. [
  5. r l2+ s2
  6. c 0Sc 3Q
  7. ] sP
  8.  
  9. # Increment c(pri)
  10. [
  11. d;c 1+ # c(pri)+1 pri rest
  12. d 3=P # score if sum == 3
  13. r:c # c(pri) = c(pri)+1
  14. 0 # push value to be discarded
  15. ] sI
  16.  
  17. # Loop (stack: items)
  18. [
  19. 32~ r 3- 26*- # convert item to priority
  20. d;c ls =I s. # inc c(pri) == state, discard pri
  21.  
  22. z 0<L # loop until stack empty
  23. ] sL
  24.  
  25. # Main loop
  26. [
  27. ?z 0=Q # get line, quit if empty
  28. lLx # parse line into count array
  29.  
  30. ls 1+ 3% ss # inc state (mod 3)
  31.  
  32. lMx
  33. ] sM
  34. lMx
  35.  
  36. [Part 2: ]n l2p
  37.  
  38. [<END>]ps.
  39. [<stack>]ps. f [<bottom>]ps.
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement