Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Collection extend [
- apply: method [ ^self collect: [:x | x perform: method] ]
- ]
- "
- | Mainline
- "
- sections := stdin contents tokenize: '\n\n'.
- " Turn list of points into Set of Points "
- points := Set from: (sections first lines collect: [ :line |
- coord := (line substrings: $,) apply: #asNumber.
- (coord first @ coord second)
- ]).
- " Turn folding rules into an Array of axis->line-num associations "
- folds := sections second lines collect: [ :line |
- rule := (line substrings) third substrings: $=.
- (rule first -> rule second asNumber)
- ].
- part1 := nil.
- extent := (0 @ 0).
- folds do: [ :fold |
- " Make point methods to get and set the right coord for the fold "
- axis := fold key asSymbol.
- set := (fold key, ':') asSymbol.
- " Adjust extent of visible rectangle "
- extent perform: set with: fold value - 1.
- " Map points under transformation. Set merges points as needed. "
- points := points collect: [ :pt |
- ((pt perform: axis) > fold value) ifTrue: [
- pt perform: set with: (2 * fold value - (pt perform: axis)).
- ].
- pt
- ].
- (part1) ifNil: [ part1 := points size ]. " Get first size for part 1 "
- ].
- ('Part 1: %1' % {part1}) displayNl.
- 'Part 2:' displayNl.
- (0 to: extent y) do: [ :y |
- (0 to: extent x) do: [ :x |
- stdout nextPut: ((points includes: x@y) ifTrue: [$#] ifFalse: [$ ]).
- ].
- stdout nl.
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement