musifter

AoC 2025, day 1, part 2 (dc)

Dec 1st, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | None | 0 0
  1. # Command: tr 'LR' '_ ' <input | dc -fdc-p2.dc
  2.  
  3. 0                   # count
  4. [0*]sZ
  5.  
  6. 50
  7. ?                   # move pos count
  8. [
  9.     A0~             # move%100 move/100 pos count
  10.  
  11.     r d*v 4R+_3R    # count += abs(move/100)
  12.  
  13.     rd3R +          # pos+=move oldpos count
  14.  
  15.     d1r 0<Z r       # pos (pos<=0) oldpos count
  16.     d1r A0>Z 3R+    # (pos>=100)+(pos<=0) pos oldpos count
  17.     3R 0=Z          # 0 if oldpos was 0 (avoid double count)
  18.     3R+ r           # count += bool result
  19.  
  20.     A0 d3R +r%      # newpos = (pos + 100) % 100  (+100 needed for positive residue)
  21.     ? z2<M
  22. ] dsMx
  23.  
  24. [Part 2: ]nrp
Advertisement
Add Comment
Please, Sign In to add comment