Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
start = "_###_##_#_#_#_#__#__"
|
||||
offLeft = '_'
|
||||
offRight = '_'
|
||||
dead = '_'
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(start)
|
||||
g := newGenerator(start, offLeft, offRight, dead)
|
||||
for i := 0; i < 10; i++ {
|
||||
fmt.Println(g())
|
||||
}
|
||||
}
|
||||
|
||||
func newGenerator(start string, offLeft, offRight, dead byte) func() string {
|
||||
g0 := string(offLeft) + start + string(offRight)
|
||||
g1 := []byte(g0)
|
||||
last := len(g0) - 1
|
||||
return func() string {
|
||||
for i := 1; i < last; i++ {
|
||||
switch l := g0[i-1]; {
|
||||
case l != g0[i+1]:
|
||||
g1[i] = g0[i]
|
||||
case g0[i] == dead:
|
||||
g1[i] = l
|
||||
default:
|
||||
g1[i] = dead
|
||||
}
|
||||
}
|
||||
g0 = string(g1)
|
||||
return g0[1:last]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
start = "_###_##_#_#_#_#__#__"
|
||||
offLeft = '_'
|
||||
offRight = '_'
|
||||
dead = '_'
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(start)
|
||||
a := make([]byte, len(start)+2)
|
||||
a[0] = offLeft
|
||||
copy(a[1:], start)
|
||||
a[len(a)-1] = offRight
|
||||
var read, write sync.WaitGroup
|
||||
read.Add(len(start) + 1)
|
||||
for i := 1; i <= len(start); i++ {
|
||||
go cell(a[i-1:i+2], &read, &write)
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
write.Add(len(start) + 1)
|
||||
read.Done()
|
||||
read.Wait()
|
||||
read.Add(len(start) + 1)
|
||||
write.Done()
|
||||
write.Wait()
|
||||
fmt.Println(string(a[1 : len(a)-1]))
|
||||
}
|
||||
}
|
||||
|
||||
func cell(kernel []byte, read, write *sync.WaitGroup) {
|
||||
var next byte
|
||||
for {
|
||||
l, v, r := kernel[0], kernel[1], kernel[2]
|
||||
read.Done()
|
||||
switch {
|
||||
case l != r:
|
||||
next = v
|
||||
case v == dead:
|
||||
next = l
|
||||
default:
|
||||
next = dead
|
||||
}
|
||||
read.Wait()
|
||||
kernel[1] = next
|
||||
write.Done()
|
||||
write.Wait()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue