Detecting 3-period oscillators

and properly (?) checking for zero-oscillator stasis.
This commit is contained in:
Dan Buch 2012-12-10 09:39:58 -05:00
parent 78625088e8
commit f22abc0430

View File

@ -20,11 +20,12 @@ var (
)
func pushChecksum(checksum string, checksums []string) {
first2 := make([]string, 2)
copy(first2, checksums[:2])
head := make([]string, 3)
copy(head, checksums[:3])
checksums[0] = checksum
checksums[1] = first2[0]
checksums[2] = first2[1]
checksums[1] = head[0]
checksums[2] = head[1]
checksums[3] = head[2]
}
func main() {
@ -37,8 +38,8 @@ func main() {
os.Exit(2)
}
checksums := make([]string, 3)
checksums[0], checksums[1], checksums[2] = "foo", "bar", "baz"
checksums := make([]string, 4)
checksums[0], checksums[1], checksums[2], checksums[3] = "foo", "bar", "baz", "qwx"
pushChecksum(game.Checksum(), checksums)
ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond)
@ -51,14 +52,20 @@ func main() {
curChecksum := game.Checksum()
if checksums[0] == curChecksum {
if checksums[0] == curChecksum || checksums[1] == curChecksum {
fmt.Println("Stasis!")
os.Exit(0)
}
if checksums[1] == curChecksum || checksums[2] == curChecksum {
fmt.Println("Checksum found in last 2")
fmt.Println("Stasis with blinkers or beacons or some such!")
if checksums[2] == curChecksum {
fmt.Println("Checksum found 2 periods ago")
fmt.Println("Stasis with 2-period oscillator(s)!")
os.Exit(0)
}
if checksums[3] == curChecksum {
fmt.Println("Checksum found 3 periods ago")
fmt.Println("Stasis with 3-period oscillator(s)!")
os.Exit(0)
}