Jump to content

Elementary cellular automaton/Random number generator: Difference between revisions

m (Promote to task, lots of examples, little controversy)
Line 346:
220 197 147 174 117 97 149 171 100 151
</pre>
 
=={{header|Nim}}==
{{trans|Kotlin}}
<lang Nim>const N = 64
 
template pow2(x: uint): uint = 1u shl x
 
proc evolve(state: uint; rule: Positive) =
var state = state
for _ in 1..10:
var b = 0u
for q in countdown(7, 0):
let st = state
b = b or (st and 1) shl q
state = 0
for i in 0u..<N:
let t = (st shr (i - 1) or st shl (N + 1 - i)) and 7
if (rule.uint and pow2(t)) != 0: state = state or pow2(i)
stdout.write ' ', b
echo ""
 
evolve(1, 30)</lang>
 
{{out}}
<pre> 220 197 147 174 117 97 149 171 100 151</pre>
 
=={{header|Pascal}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.