Advertisement
musifter

AoC 2024, day 14, part 1 (dc)

Jan 1st, 2025 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | Source Code | 0 0
  1. # Command: tr -- '-p=v,' '_ ' <input | dc -fdc-p1.dc
  2.  
  3. # Calculate quadrant and increment
  4. [
  5.     ly dd*v/                    # y /= abs(y)
  6.     lx dd*v/                    # x /= abs(x); stack: sign(x) sign(y)
  7.     2*3r- +                     # index = 3 - sign(x) * 2 + sign(y) => {0, 2, 4, 6}
  8.     d;q 1+ r:q
  9. ] sQ
  10.  
  11. ?                               # stack: vy vx y x
  12. [
  13.     # ASSUME: velocities on (-dim,dim) and position always non-negative
  14.     # This means we can just add dim to velocities to have mod residues be non-negative.
  15.     A3+ A0* 3R+ A3% 51-         # y+=100*vy (mod 103), residue -51..51
  16.     r A1+ A0* 3R+ A1% 50-       # x+=100*vx (mod 101), residue -50..50
  17.  
  18.     # stack: x y (moved)
  19.     dsx r dsy* 0!=Q             # if (x*y) != 0, add to quad (pass by reg for clean stack)
  20.  
  21.     ? z0<M
  22. ] dsMx
  23.  
  24. [Part 1: ]n 6;q4;q*2;q*0;q*p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement