Advertisement
musifter

AoC 2023 day 18, part 1 (Smalltalk)

Dec 18th, 2023 (edited)
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.60 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. "
  4. | Mainline
  5. "
  6. area   := 0.
  7. pos    := (0 @ 0).
  8. trench := 0.
  9.  
  10. stdin linesDo: [ :line |
  11.     parts := line subStrings.
  12.  
  13.     delta := parts second asNumber.
  14.     vert := (parts first = 'U') | (parts first = 'D').
  15.     (parts first = 'U') | (parts first = 'L') ifTrue: [ delta := delta * -1 ].
  16.  
  17.     vert ifTrue:  [ pos y: (pos y + delta) ]
  18.          ifFalse: [ pos x: (pos x + delta) ].
  19.  
  20.     area := area + (delta * (vert ifTrue: [pos x] ifFalse: [-1 * pos y])).
  21.     trench := trench + delta abs.
  22. ].
  23.  
  24. part1 := (area abs + trench) / 2 + 1.
  25. ('Part 1: %1' % {part1}) displayNl.
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement