Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- " Read decks "
- section := stdin contents tokenize: '\n\n'.
- deck1 := ((section first) tokenize: '\n') asOrderedCollection removeFirst; yourself.
- deck1 := deck1 collect: [ :v | v asNumber ].
- deck2 := ((section second) tokenize: '\n') asOrderedCollection removeFirst; yourself.
- deck2 := deck2 collect: [ :v | v asNumber ].
- " Play game "
- [(deck1 size > 0) and: [deck2 size > 0]] whileTrue: [
- card1 := deck1 removeFirst.
- card2 := deck2 removeFirst.
- (card1 > card2) ifTrue: [
- deck1 addLast: card1; addLast: card2.
- ] ifFalse: [
- deck2 addLast: card2; addLast: card1.
- ].
- ].
- " Tally score "
- part1 := 0.
- win_deck := (deck1 size > 0) ifTrue: [ deck1 ] ifFalse: [ deck2 ].
- win_deck reverse keysAndValuesDo: [ :i :v | part1 := part1 + (i * v) ].
- stdout nextPutAll: 'Part 1: ', part1 asString; nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement