Advertisement
musifter

AoC 2025, day 25 (smalltalk)

Dec 25th, 2024 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.72 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. Symbol extend [ value: arg [^arg perform: self] ]
  4.  
  5. " Changes to booleans to give basic integer coercion: "
  6. Boolean extend  [ generality [^1] ]
  7. True  extend    [ truncated  [^1] ]
  8. False extend    [ truncated  [^0] ]
  9.  
  10. "
  11. |  Mainline
  12. "
  13. locks := Set new.
  14. keys  := Set new.
  15.  
  16. ((stdin contents tokenize: '\n\n') collect: #lines) do: [:item |
  17.     " Convert images to bitArrays, AND them and any overlap will be a 1: "
  18.     bitArray := item join inject: 0 into: [:a :b | a * 2 + (b = $#)].
  19.  
  20.     ((item first first = $#) ifTrue: [locks] ifFalse: [keys]) add: bitArray.
  21. ].
  22.  
  23. part1 := locks inject: 0 into: [:sum :l | sum + (keys count: [:k | (k bitAnd: l) = 0])].
  24. ('Part 1: %1' % {part1}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement