Advertisement
musifter

AoC 2023 day 18, part 2 (dc)

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