musifter

AoC 2025, day 5 part 1 (dc)

Dec 5th, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | Source Code | 0 0
  1. # Command: tr '-' ' ' </tmp/input | dc -fdc-p1.dc
  2.  
  3. # read ranges section onto stack
  4. 0 ?             # end start i
  5. [
  6.     3R d3R r:r  # range(i)   = end;   i start
  7.     1+ d3R r:r  # range(++i) = start; i
  8.     1+ ? z1<L
  9. ] dsLx          # length of range array left on stack
  10.  
  11. [ lc1+sc q ] sC
  12.  
  13. # count food ids that fall in a range
  14. ?
  15. [
  16.     sf d                    # i=num | num (length of array)
  17.     [
  18.           1- d;r lf-        # end-food i
  19.         r 1- d;r lf-        # start-food i end-food
  20.         3R*                 # (start-food)*(end-food) i
  21.         0!<C                # if test <= 0 then count and quit
  22.         d0<I
  23.     ] dsIx s.
  24.  
  25.     ? z1<M
  26. ] dsMx
  27.  
  28. [Part 1: ]n lcp
Advertisement
Add Comment
Please, Sign In to add comment