// 1D cellular automaton class CA1D { static final int tablesize = 10; static final int table_java[] = {12, 13, 8, 7, 2, 1, 0, 11, 18, 20}; static int [1d] local table; inline public static int f(int s) { return table[s % tablesize]; } public static void CA(int [1d] local x, int [1d] local y, int [1d] local z, RectDomain<1> r, int a, int b, int c, int d, int e) { CA(x, y, z, r, a, b, c, d, e, table_java); } public static void CA(int [1d] local x, int [1d] local y, int [1d] local z, RectDomain<1> r, int a, int b, int c, int d, int e, /*int [1d] local t*/ int table_java[]) { int rlo = r.min()[1], rhi = r.max()[1]; y.junk(); foreach (p in r) { int v = (a * x[p - [2]] + b * x[p - [1]] + c * x[p] + d * x[p + [1]] + e * x[p + [2]]) % tablesize; y[p] = table_java[v]; } z.junk(); foreach (p in [rlo + 2 : rhi - 2]) { int v = (a * y[p - [2]] + b * y[p - [1]] + c * y[p] + d * y[p + [1]] + e * y[p + [2]]) % tablesize; z[p] = table_java[v]; } y.junk(); foreach (p in [rlo + 4 : rhi - 4]) { int v = (a * z[p - [2]] + b * z[p - [1]] + c * z[p] + d * z[p + [1]] + e * z[p + [2]]) % tablesize; x[p] = table_java[v]; } z.junk(); } public static void setup(int [1d] local x) { table = new int [0 : tablesize - 1]; for (int i = 0; i < tablesize; i++) table[i] = table_java[i]; foreach (p in x.domain()) { x[p] = p[1] * p[1] * (p[1] - 13) - 97531; if (x[p] < 0 || x[p] > 99999) x[p] = f(x[p] & 1234567); } } }