musifter

AoC 2025 day 9 part 1 (dc)

Dec 10th, 2025 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | Source Code | 0 0
  1. # Command: tr ',' ' ' <input | dc -fdc-p1.dc
  2.  
  3. [sm0] sS                    # store top in S, replace with 0
  4.  
  5. 1 ?                         # y x i=0
  6. [
  7.     3R1+                    # i++ y x
  8.     d3R r:y                 # y(i) = y
  9.     d3R r:x                 # x(i) = x
  10.     ? z1<L
  11. ] dsLx
  12.  
  13. # stack: i=num
  14. d;x r d;y
  15. 1:y r 1:x                   # add last to slot 1 (forms cycle)
  16.  
  17. r                           # i
  18. [
  19.     d1-                     # j=i-1 i
  20.     [
  21.         d;x r d;y           # y(j) j x(j) i
  22.         4R
  23.         d;x r d;y           # y(i) i x(i) y(j) j x(j)
  24.         4R   -d*v1+         # abs(delta y)+1 i x(i) j x(j)
  25.         5R4R -d*v1+ *       # area i j
  26.         d lm<S s.
  27.  
  28.         r1- d0<J
  29.     ] dsJx +
  30.     1- d1<I
  31. ] dsIx
  32.  
  33. [Part 1: ]n lmp
Advertisement
Add Comment
Please, Sign In to add comment