Implementation of totalistic cellular automata

To handle totalistic rules that involve k colors and nearest neighbors, one can add the definition

CAStep[TotalisticCARule[rule_List, 1], a_List] := rule[[-1-(RotateLeft[a] + a + RotateRight[a])]]

to what was given on page 867. The following definition also handles the more general case of r neighbors:

CAStep[TotalisticCARule[rule_List, r_Integer], a_List] := rule[[-1-Sum[RotateLeft[a, i], {i, -r, r}]]]

One can generate the representation of totalistic rules used by these functions from code numbers using

ToTotalisticCARule[num_Integer, k_Integer, r_Integer] := TotalisticCARule[IntegerDigits[num, k, 1 + (k-1)(2r+1)], r]