Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Symbol extend [ value: arg [^arg perform: self] ]
- SequenceableCollection extend [
- chain: binBlock [
- | res |
- res := self copyEmptyForCollect.
- self fold: [:curr :next | res add: (binBlock value: curr value: next). next].
- ^res
- ]
- checkReport [
- | diffs |
- diffs := self chain: [:a :b | b - a].
- ^diffs allSatisfy: [:d | (d abs between: 1 and: 3) and: [diffs first * d > 0]]
- ]
- ]
- "
- | Mainline
- "
- part1 := 0.
- part2 := 0.
- stdin linesDo: [ :line |
- report := line subStrings collect: #asNumber.
- (report checkReport)
- ifTrue: [ part1 := part1 + 1 ]
- ifFalse: [
- subLists := (1 to: report size) collect: [:i |
- (report copyReplaceFrom: i to: i withObject: nil) select: #notNil
- ].
- (subLists anySatisfy: [:list | list checkReport]) ifTrue: [part2 := part2 + 1]
- ].
- ].
- ('Part 1: %1' % {part1}) displayNl.
- ('Part 2: %1' % {part1 + part2}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement