Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- FileStream fileIn: './Automata.st'!
- " Definition of a hexgrid space for the Automaton class "
- Space subclass: PaperGrid [
- | dirs |
- coordDirs := { (-1 @ -1). (0 @ -1). (1 @ -1).
- (-1 @ 0). (1 @ 0).
- (-1 @ 1). (0 @ 1). (1 @ 1) }.
- PaperGrid class >> load: input [
- ^(super new) init: input
- ]
- init: inputData [
- | width |
- width := inputData first size + 1.
- dirs := coordDirs collect: [:c | c y * width + c x].
- inputData keysAndValuesDo: [:y :line |
- line keysAndValuesDo: [:x :char |
- (char = $@) ifTrue: [ self setAlive: (y * width + x) ]
- ]
- ].
- super initState.
- ^self
- ]
- neighbours: cell [
- ^dirs collect: [ :d | cell + d ]
- ]
- ]
- "
- | Mainline
- "
- auto := Automaton space: (PaperGrid load: stdin lines contents)
- dieRule: [:neigh | neigh < 4]
- liveRule: [:neigh | false ].
- startingRolls := auto space liveCells size.
- ('Part 1: %1' % {startingRolls - (auto runTurns: 1)}) displayNl.
- ('Part 2: %1' % {startingRolls - (auto runUntilStable)}) displayNl.
Advertisement
Add Comment
Please, Sign In to add comment