Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- init := ((stdin nextLine) subStrings: ',') collect: [:n | n asInteger].
- table := LookupTable new.
- (1 to: (init size - 1)) do: [ :t | table at: (init at: t) put: t ].
- next := init last.
- curr := 0.
- (init size to: 2020) do: [ :t |
- curr := next.
- next := t - (table at: curr ifAbsent: [t]).
- table at: curr put: t.
- ].
- stdout nextPutAll: ('Part 1: ', curr asString); nl.
- (2021 to: 30000000) do: [ :t |
- (t \\ 10000 == 0) ifTrue: [ stdout nextPutAll: ('Time: ', t asString); cr; flush ].
- curr := next.
- next := t - (table at: curr ifAbsent: [t]).
- table at: curr put: t.
- ].
- stdout nl; nextPutAll: ('Part 2: ', curr asString); nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement