Anonymous user
Elementary cellular automaton/Random number generator: Difference between revisions
Elementary cellular automaton/Random number generator (view source)
Revision as of 15:37, 29 November 2020
, 3 years ago→{{header|Kotlin}}
Thundergnat (talk | contribs) 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}}==
|