Jump to content

Elementary cellular automaton: Difference between revisions

Updated D entry
(→‎{{header|Racket}}: actual implementation added)
(Updated D entry)
Line 356:
=={{header|D}}==
{{trans|Python}}
<lang d>import std.stdio, std.string, std.conv, std.range, std.algorithm, std.typecons;
 
enum mod = (in int n, in int m) pure nothrow @nogc => ((n % m) + m) % m;
Line 363:
public string front;
public enum bool empty = false;
private immutable const(char)[string] next;
 
this(in string cells_, in uint rule) {
this.front = cells_;
immutable ruleBits = "%08b".format(rule).retro.text;
next = 8.iota.map!(n => tuple("%03b".format(n), char(ruleBits[n]))).assocArray;
}
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.