One-dimensional two-state cellular automaton of size *n*consists of a (circular) array of size *n* and associatedrule that determines the change of states at each step. The samerule applies to all states simultaneously. Given index of any cell(array index) i in the range [0, n – 1], the rule applies to cellsa[i-1], a[i] and a[i+1] (i.e. to cell itself and its immediate leftand right neighbor), except for the bordering cells a[0] and a[n-1]whose states are computed in terms of a[n-1], a[0], a[1] anda[n-2], a[n-1], a[0] respectively. The same rule applies to allstates simultaneously. Rules are typically stated as *Wolframrules* as follows: Given an integer in the range 0 – 255, itsbinary representation represents the output of a 3-input booleanfunction. For example, if the rule is 30 = 00011110, itscorresponding table is:

a[i-1]a[i]a[i+1]a[i]’00000011010101111001101011001110

Graphically, this can be represented as:

In the figure below you can see the evolution of a cellularautomaton of size 31 and rule 30. The initial configurationconsists of all cells being set to 0 except for the middle one(a[15]=1).

For more information on elementary cellular automata visitWolfram.

Write a Java class CA which implements elementary cellularautomata. Declare fields:

- private boolean[] cell;
- private int size;
- private int rule;
- private boolean[] ttable;

Constructor takes two integers as arguments and assigns them tofields size and rule respectively, initializes array cells to falseexcept the value at index size/2 which is set to true andtranslates the integer value of variable ruleto binary stored inarray ttable.

Write a member method:

- public boolean[] getState()

which computes and returns the next state base on the currentstate and rule. Observe that current values of a[i-1], a[i] anda[i+1] determine the next state of a[i] in terms of indices. Forexample, if a[i-1] = true (1), a[i] = true (1), a[i + 1] = false(0), rule is 30 internally stored in ttable as {0, 1, 1, 1, 1, 0,0, 0}, then the next state of a[i] is simply ttable[index] whereindex = 4 * toInt(a[i-1]) + 2 * toInt(a[i]) + toInt(a[i+1]) = 4 * 1+ 2 * 1 + 1 * 0 = 6 and ttable[6] = false.

Write a driver class which takes two command line argumentsrepresenting size and rule, creates an object of type CA and startsan infinite loop. Within each loop iteration the call to methodgetState() is made and the returned boolean array is properlyformatted for output – false values are printed as space characters(‘ ‘) and true values are printed as ‘X’ characters. So, if you runyour driver class as java Lab32 40 90, the output after first 20steps should be:

o o o 1 1 1 1 o We were unable to transcribe this imageShow transcribed image text o o o 1 1 1 1 o

## Expert Answer

Answer to One-dimensional two-state cellular automaton of size n consists of a (circular) array of size n and associated rule that…