musifter

AoC 2025, day 1 (smalltalk)

Dec 1st, 2025 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smalltalk 0.96 KB | Source Code | 0 0
  1. #!/usr/local/bin/gst -q
  2.  
  3. Collection extend [ sum [ ^self inject: 0 into: [:a :b | a + b] ] ]
  4.  
  5. SequenceableCollection extend [
  6.     " Returns collection of results from calling binBlock for each link pair "
  7.     chain: binBlock [
  8.         | res |
  9.         res := self copyEmptyForCollect.
  10.         self fold: [:curr :next | res add: (binBlock value: curr value: next). next].
  11.         ^res
  12.     ]
  13. ]
  14.  
  15. "
  16. | Mainline
  17. "
  18. pos := 50.
  19. stops := (stdin lines contents collect: [:line |
  20.            | mag |
  21.             mag := line allButFirst asNumber.
  22.             pos := pos + (line first == $L ifTrue: [mag negated] ifFalse: [mag]).
  23.          ]) asOrderedCollection addFirst: 50; yourself.
  24.  
  25. zeros := stops chain: [:a :b | (b > a) ifTrue:  [((a // 100) - (b // 100)) abs]
  26.                                        ifFalse: [((a negated // 100) - (b negated // 100)) abs]].
  27.  
  28. ('Part 1: %1' % {stops count: [:s | (s \\ 100) == 0]}) displayNl.
  29. ('Part 2: %1' % {zeros sum}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment