Elementary cellular automaton/Random number generator: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Promote to task, lots of examples, little controversy) |
|||
Line 346: | Line 346: | ||
220 197 147 174 117 97 149 171 100 151 |
220 197 147 174 117 97 149 171 100 151 |
||
</pre> |
</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}}== |
=={{header|Pascal}}== |