Jump to content

One-dimensional cellular automata: Difference between revisions

Go solution
(Go solution)
Line 801:
Generation 8: __##________________
Generation 9: __##________________
=={{header|Go}}==
<lang go>package main
 
import "fmt"
 
const start = "_###_##_#_#_#_#__#__"
 
func main() {
g0 := []byte(start)
g1 := []byte(start)
fmt.Println(string(g0))
last := len(g0) - 1
for g := 0; g < 10; g++ {
for i := 1; i < last; i++ {
switch {
case g0[i-1] != g0[i+1]:
g1[i] = g0[i]
case g0[i] == '_':
g1[i] = g0[i-1]
default:
g1[i] = '_'
}
}
fmt.Println(string(g1))
copy(g0, g1)
}
}</lang>
Output:
<pre>
_###_##_#_#_#_#__#__
_#_#####_#_#_#______
__##___##_#_#_______
__##___###_#________
__##___#_##_________
__##____###_________
__##____#_#_________
__##_____#__________
__##________________
__##________________
__##________________
</pre>
 
=={{header|Haskell}}==
1,707

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.