Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- input := stdin nextLine.
- #(4 14) keysAndValuesDo: [ :part :width |
- window := 1 to: width.
- mark := width.
- seen := Set new.
- "
- | Basic idea is that we're going to examine on an operating window
- | from the far end, shrinking it as we go until either:
- | - it shrinks to nothing, meaning no matches and we're done
- | - we find a pair, in which case we jump the window forward to split them
- "
- [window notEmpty] whileTrue: [
- (seen includes: (input at: window last)) ifTrue: [
- window := window last + 1 to: (mark := window last + width).
- seen empty.
- ] ifFalse: [
- seen add: (input at: window last).
- window := window allButLast.
- ]
- ].
- ('Part %1: %2' % {part. mark}) displayNl.
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement