Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- Integer extend [
- %% modulus [ ^self - 1 \\ modulus + 1 ]
- ]
- Collection extend [
- at: idx modInc: val [ ^self at: idx put: ((self at: idx) + val %% 10) ]
- at: idx inc: val [ ^self at: idx put: ((self at: idx) + val) ]
- sum [ ^self inject: 0 into: [:a : b | a + b] ]
- ]
- Object subclass: Die100 [
- | rolls |
- Die100 class >> new [ ^super new init ]
- init [ rolls := 0. ^self ]
- stream [ ^Generator on: [:gen | [gen yield: (rolls := rolls + 1) %% 100] repeat] ]
- rolls [ ^rolls ]
- ]
- "
- | Mainline
- "
- pawns := stdin lines contents collect: [:line | (line tokenize: ': ') second asNumber].
- score := Array new: 2 withAll: 0.
- player := 2.
- die := (Die100 new).
- roll := die stream.
- [
- " switch player "
- player := 3 - player.
- " move token around track the sum of three dice rolls "
- pawns at: player modInc: (roll next: 3) sum.
- " score where token lands, check for win "
- (score at: player inc: (pawns at: player)) >= 1000
- ] whileFalse.
- ('Part 1: %1' % {(score at: 3 - player) * die rolls}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement