Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Collection extend [ sum [ ^self inject: 0 into: [:a :b | a + b] ] ]
- SequenceableCollection extend [
- " Returns collection of results from calling binBlock for each link pair "
- chain: binBlock [
- | res |
- res := self copyEmptyForCollect.
- self fold: [:curr :next | res add: (binBlock value: curr value: next). next].
- ^res
- ]
- ]
- "
- | Mainline
- "
- pos := 50.
- stops := (stdin lines contents collect: [:line |
- | mag |
- mag := line allButFirst asNumber.
- pos := pos + (line first == $L ifTrue: [mag negated] ifFalse: [mag]).
- ]) asOrderedCollection addFirst: 50; yourself.
- zeros := stops chain: [:a :b | (b > a) ifTrue: [((a // 100) - (b // 100)) abs]
- ifFalse: [((a negated // 100) - (b negated // 100)) abs]].
- ('Part 1: %1' % {stops count: [:s | (s \\ 100) == 0]}) displayNl.
- ('Part 2: %1' % {zeros sum}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment