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] ]
- Collection extend [ sum [ ^self inject: 0 into: [:a :b | a + b] ] ]
- "
- | Mainline
- "
- list1 := Bag new.
- list2 := Bag new.
- stdin linesDo: [ :line |
- items := line subStrings collect: #asNumber.
- list1 add: items first.
- list2 add: items second.
- ].
- part1 := (list1 sorted with: list2 sorted collect: [:a :b | (a - b) abs]) sum.
- part2 := (list1 collect: [:a | a * (list2 occurrencesOf: a)]) sum.
- ('Part 1: %1' % {part1}) displayNl.
- ('Part 2: %1' % {part2}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement