Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- "
- | Mainline
- "
- part1 := 0.
- count := 0.
- hash := Array new: 160000 withAll: 0.
- tmp := Dictionary new.
- stdin lines contents do: [:line |
- | num last idx |
- num := line asNumber.
- last := num \\ 10.
- idx := 0.
- tmp empty.
- ((count := count + 1) \\ 50 == 0) ifTrue: [
- stderr nextPutAll: ('[%1] %2 ') % {count. num}; cr; flush.
- ].
- (1 to: 2000) do: [:i |
- num := ((num bitShift: 6) bitXor: num) bitAnd: 16rFFFFFF.
- num := (num bitShift: -5) bitXor: num.
- num := ((num bitShift: 11) bitXor: num) bitAnd: 16rFFFFFF.
- idx := ((idx * 20) + (num \\ 10) - last + 10) \\ 160000.
- last := num \\ 10.
- (i >= 4) ifTrue: [
- tmp at: idx ifAbsentPut: [last].
- ]
- ].
- part1 := part1 + num.
- tmp keysAndValuesDo: [:idx :bananas |
- hash at: idx put: (hash at: idx ifAbsent: [0]) + bananas.
- ]
- ].
- stdout nl.
- ('Part 1: %1' % {part1}) displayNl.
- ('Part 2: %1' % {hash fold: [:a :b | a max: b]}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement