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] ]
- " Extending Booleans to coerce to numbers: "
- Boolean extend [ generality [^1] ]
- True extend [ truncated [^1] ]
- False extend [ truncated [^0] ]
- "
- | Mainline
- "
- stones := Bag from: (stdin nextLine substrings collect: #asNumber).
- (1 to: 75) do: [ :time |
- next := Bag new.
- stones contents keysAndValuesDo: [ :value :num |
- len := (value floorLog: 10) + 1. "Note: floorLog returns 0 for value == 0 "
- (len \\ 2 == 0) ifTrue: [
- factor := 10 raisedToInteger: len // 2.
- next add: value // factor withOccurrences: num.
- next add: value \\ factor withOccurrences: num.
- ] ifFalse: [
- next add: value * 2024 + (value == 0) withOccurrences: num.
- ]
- ].
- stones := next.
- (time == 25) ifTrue: [('Part 1: %1' % {stones size}) displayNl].
- ].
- ('Part 2: %1' % {stones size}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement