Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Collection extend [
- " To make up for GNU smalltalk not taking symbols with collect: "
- apply: method [ ^self collect: [:x | x perform: method] ]
- ]
- Interval extend [
- " Get intersection of self and another Interval "
- & other [ ^(self first max: other first) to: (self last min: other last) ]
- ]
- String extend [
- " Interpret (\d+)-(\d+) string as an Interval "
- asInterval [
- | range |
- range := (self subStrings: '-') apply: #asInteger.
- ^Interval from: range first to: range second.
- ]
- ]
- "
- | Mainline
- "
- part1 := 0.
- part2 := 0.
- stdin linesDo: [ :line |
- ranges := (line substrings: $,) apply: #asInterval.
- intersection := ranges first & ranges second.
- (intersection notEmpty) ifTrue: [
- part2 := part2 + 1.
- " intersection matches a given range making it a subset "
- (ranges includes: intersection) ifTrue: [
- part1 := part1 + 1.
- ].
- ].
- ].
- ('Part 1: %1' % {part1}) displayNl.
- ('Part 2: %1' % {part2}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement