Advertisement
musifter

AoC day 2 (dc)

Dec 2nd, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/dc -f-
  2.  
  3. [q] SX
  4.  
  5. [
  6. rdd # 0 mag -> mag mag 0 (zero is rel-cmd, leave on top)
  7. lx+sx la*ly+sy r # -> (x += mag) mag 0 -> (y += a * mag) 0
  8. ] SF
  9.  
  10. [
  11. z 0 =X # stop when stack empty
  12.  
  13. r # mag cmd -> cmd mag
  14. 102r- # -> rel-cmd mag (cmd now relative to ASCII 'f')
  15.  
  16. d 0=F # (rel-cmd = 0) rel-cmd mag
  17.  
  18. 7*13% # sign mag (this works for -15, 0, and 2 which is all we need)
  19. * la+ sa # a += sign * mag
  20.  
  21. lLx # loop
  22. ] SL
  23.  
  24. 0dd sx sy sa # init x, y, a
  25. lLx # start loop
  26.  
  27. [Part 1: ]n lx la* p
  28. [Part 2: ]n lx ly* p
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement