Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- " Some conventient covering extensions: "
- String extend [
- asRadix: rad [ ^Number readFrom: (ReadStream on: self) radix: rad ]
- ]
- " Extending Set with a method to do the work for this script "
- Set extend [
- filter: wantMin [
- | i |
- i := 1.
- [self size > 1] whileTrue: [
- | sets sort |
- sets := Dictionary from: { $0 -> Set new. $1 -> Set new }.
- self do: [ :num | (sets at: (num at: i)) add: num ].
- sort := sets associations sorted: [:a :b |
- ((a value size > b value size) | (a key > b key)) xor: wantMin
- ].
- self removeAll: (sort first value).
- i := i + 1.
- ].
- ^self anyOne
- ]
- ]
- "
- | Mainline
- "
- input := stdin lines contents.
- oxyCo2 := #(true false) collect: [ :mode | (input asSet filter: mode) asRadix: 2 ].
- ('Part 2: %1' % {(oxyCo2 at: 1) * (oxyCo2 at: 2)}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement