Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Character extend [
- asDigit [
- ^self value - $0 value
- ]
- ]
- input := OrderedCollection new.
- stdin nextLine do: [ :c | input add: c asDigit ].
- " Build ring out of input "
- cup_ring := Array new: input size.
- input fold: [ :a :b | cup_ring at: a put: b ].
- cup_ring at: input last put: input first.
- " Play 100 turns "
- curr := input first.
- (1 to: 100) do: [ :turn |
- ptr := curr.
- " Move over next three, marking them as grabbed "
- " Zero counts as grabbed so we skip it while calculating dest "
- grab := Set with: 0.
- (1 to: 3) do: [ :i | ptr := cup_ring at: ptr. grab add: ptr ].
- " Calculate destination for block "
- dest := curr - 1.
- [ grab includes: dest ] whileTrue: [ dest := (dest - 1) \\ 10 ].
- " Relink ring with block after dest "
- old_curr_ptr := cup_ring at: curr.
- cup_ring at: curr put: (cup_ring at: ptr). " curr points to after block "
- cup_ring at: ptr put: (cup_ring at: dest). " end block to old after dest "
- cup_ring at: dest put: old_curr_ptr. " dest to start of block "
- curr := cup_ring at: curr.
- ].
- 'Part 1: ' display.
- curr := 1. [ (curr := cup_ring at: curr) ~= 1 ] whileTrue: [ curr display ]. stdout nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement