musifter

AoC 2025 day 12 (dc)

Dec 12th, 2025 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | Source Code | 0 0
  1. # Command: tr '.#:x' '12  ' <input | dc -fdc-p1.dc
  2.  
  3. [q] sq
  4.  
  5. ?
  6. [
  7.     z1<q                        # more than 1 element means second section
  8.  
  9.     # stack: index
  10.     ??? 0                       # ASSSUME: pieces have three rows
  11.     [
  12.         r                       # row sum ... idx
  13.         [
  14.             A~                  # digit rest sum ...
  15.             2/ 3R+              # sum+=(digit==2) rest ...
  16.             r d0<D              # loop until (row == 0)
  17.         ] dsDx +
  18.  
  19.         # stack: sum piece* idx
  20.         z2<I
  21.     ] dsIx
  22.  
  23.     r1+:p
  24.  
  25.     ?? z0<L                     # skip blank line
  26. ] dsLx
  27.  
  28. 0                               # part1=0
  29. [
  30.     0 z4-                       # i=numPieces sum part1 targ_n targ_n-1 ... targ_1 length width
  31.     [
  32.         d;p
  33.         5R* 3R+                 # sum+=piece[i]*targ_n i targ_n-1 ...
  34.         r 1- d0<I
  35.     ] dsIx +
  36.  
  37.     # sum part1 length width
  38.     4R4R*                       # area sum part1
  39.     - d.1+/ +                   # part1 += ((sum - area) < 0)
  40.     ? zR z1<M                   # read line, rotate part1 to top
  41. ] dsMx
  42.  
  43. [Part 1: ]np
Advertisement
Add Comment
Please, Sign In to add comment