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] ]
- SequenceableCollection extend [
- " Returns collection of results from calling binBlock for each link pair "
- chain: binBlock [
- | res |
- res := self copyEmptyForCollect.
- self fold: [:curr :next | res add: (binBlock value: curr value: next). next].
- ^res
- ]
- ]
- "
- | Mainline
- "
- input := stdin lines contents collect: [:line | line subStrings collect: #asNumber].
- part1 := 0.
- part2 := 0.
- input do: [:seq |
- row := seq.
- mult := 1.
- [row conform: [:n | n = 0]] whileFalse: [
- " Part 1 is sum of lasts, part 2 is alternating sum of firsts "
- part1 := part1 + row last.
- part2 := part2 + (mult * row first).
- mult := mult negated.
- row := row chain: [:a :b | b - a].
- ].
- ].
- ('Part 1: %1' % {part1}) displayNl.
- ('Part 2: %1' % {part2}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement