musifter

AoC 2025 day 12 (Smalltalk)

Dec 12th, 2025 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.89 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. Symbol extend [
  4.     value: arg               [ ^arg perform: self ]
  5.     value: arg1 value: arg2  [ ^arg1 perform: self with: arg2 ]
  6. ]
  7.  
  8. Collection extend [ sum  [^self inject: 0 into: [:a :b | a + b]] ]
  9.  
  10. "
  11. | Mainline
  12. "
  13. input := (stdin contents tokenize: '\n\n') collect: #lines.
  14.  
  15. sizes := input allButLast collect: [:p | (p collect: [:row | row count: [:chr | chr == $#]]) sum].
  16.  
  17. part1 := input last count: [:region |
  18.            | nums |
  19.             nums  := (region substrings: 'x: ') collect: #asNumber.
  20.  
  21.             area     := nums first * nums second.
  22.             needArea := ((nums allButFirst: 2) with: sizes collect: #*) sum.
  23.  
  24.             tileSpots := (nums first // 3) * (nums second // 3).
  25.             needSpots := (nums allButFirst: 2) sum.
  26.  
  27.             (area >= needArea) and: [tileSpots >= needSpots]
  28.          ].
  29.  
  30. ('Part 1: %1' % {part1}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment