Advertisement
musifter

AoC 2024, day 5 (smalltalk)

Dec 5th, 2024 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.64 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. Symbol extend     [ value: arg [^arg perform: self] ]
  4. Collection extend [ at: idx inc: val [^self at: idx put: ((self at: idx) + val)] ]
  5.  
  6. "
  7. | Mainline
  8. "
  9. sections := (stdin contents tokenize: '\n\n') collect: #lines.
  10. order    := Set from: (sections first).
  11.  
  12. parts := Dictionary from: {true -> 0. false -> 0}.
  13. sections second do: [:list |
  14.     sorted := (list subStrings: ',') sort: [:a :b | order includes: (a,'|',b)].
  15.     parts at:  (list = (sorted join: ','))
  16.           inc: (sorted at: sorted size // 2 + 1) asNumber.
  17. ].
  18.  
  19. ('Part 1: %1' % {parts at: true})  displayNl.
  20. ('Part 2: %1' % {parts at: false}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement