Advertisement
musifter

AoC 2023 day 18 part 1 (dc)

Dec 18th, 2023 (edited)
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | Source Code | 0 0
  1. # Command: cut -d' ' -f-2 | tr 'RDLU' '0123' input | dc -fpart1.dc
  2.  
  3. # ASSUME: Every line is a 90 degree turn (just swap x and y on the stack each time)
  4. 0d ?                            # y x dir len
  5. [
  6.     r2~                         # y x len upleft=dir/2 vert=dir%2
  7.     2*1- r2*1-                  # y x len vert=(1|-1) upleft=(1|-1)
  8.     3Rd lb+sb *                 # border += len; y x vert delta=upleft*len
  9.  
  10.     d 4R+ _4R                   # x+=delta y vert delta
  11.     *r d3R *                    # x y vert*delta*y
  12.     la+sa                       # area += vert * delta * y; x y
  13.  
  14.     ? z2<M
  15. ] dsMx
  16.  
  17. [Part 1: ]n lad*v lb+ 2/ 1+p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement