musifter

AoC 2021 day 13, part 1 (dc)

Dec 13th, 2021 (edited)
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/usr/bin/dc
  2.  
  3. # Process fold section (storing first fold axis and line in a and l)
  4. [
  5. sl sa # store line, axis (clobber, only want first fold)
  6. d _1!=R # loop until top is -1
  7. ] sR
  8. lRx s.
  9.  
  10. [ ll2* lx- sx ] sX # macro to flip in x
  11. [ ll2* ly- sy ] sY # macro to flip in y
  12.  
  13. [ lY sF [ly] sA ] sS # macro to swap x-macros for y-macros
  14. [ lx ] sA # store axis value loader in A
  15. lX sF # start with X in F (flip transform macro)
  16. la 121=S # if doing Y, S will change the above macros
  17.  
  18. [ lc1- sc ] sM # point merged, reduce count
  19.  
  20. # Loop to transform each point and check for collisions
  21. [
  22. sy sx # store point into x,y
  23. lAx ll<F # execute transform if on far side of line
  24.  
  25. ly 10000* lx+ # calculate hash (10000y + x)
  26. d;h 1=M 1 r:h # (h(hash) = 1, merge) (h(hash) = 1)
  27.  
  28. z 0<L # loop while points on stack
  29. ] sL
  30.  
  31. z 2/ sc # init count with number of points (stack/2)
  32. lLx # start loop
  33.  
  34. [Part 1: ]n lcp
  35.  
Add Comment
Please, Sign In to add comment