Advertisement
musifter

AoC 2022, day 10 (dc both parts)

Dec 10th, 2022 (edited)
257
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | Source Code | 0 0
  1. [ d2*1+2%* ] S| # abs: (2*n + 1) % 2 * n (if dc mod preserves sign)
  2.  
  3. [
  4. []ps.
  5. ] sR # print newline
  6.  
  7. [ 0* ] sZ # zero top of stack
  8.  
  9. [Part 2: ]ps.
  10. [#]dn 0:t [ ] 1:t # print table (and print starting #)
  11.  
  12. # stack: time regX sum
  13. [
  14. d 3R d 3R * # (regX * time) time regX sum
  15. 4R+ r3R # s = (s + (regX * time)), stack: time regX sum
  16. ] sS
  17.  
  18. # main loop (stack: time regX sum data ...)
  19. [
  20. # Part 2
  21. d 40% # (time % 40) time regX sum ...
  22.  
  23. d 0=R # print newline every 40
  24.  
  25. 3R d 3R # (time % 40) regX regX time sum ...
  26. - l|x # abs( time%40 - regx ) regX time sum ...
  27. 1r 1!<Z # (idx := !(abs<=1)) regX time sum ...
  28. ;tn r # print t(idx), stack: time regX sum
  29.  
  30. # Part 1
  31. 1+ # time++ regX sum ...
  32. d 40% # time%40 time regX sum ...
  33. 20=S # score if time%40 = 20, stack: time regX sum ...
  34.  
  35. # Update regX
  36. r4R # pull up data: data regX time sum ...
  37. + # (regX += data) time sum ...
  38. r # time regX sum data ...
  39. z 3<L
  40. ] sL
  41.  
  42. 0 1 d lLx
  43.  
  44. [Part 1: ]n 3Rp
  45.  
  46. [<END>]ps.
  47. [<stack>]ps. f [<bottom>]ps.
  48.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement