@Override public String next() { if (count == 0) { count++; return automaton.toString(); } else { automaton.step(); count++; return automaton.toString(); } }
public static void main(String[] args) { // Create a new cellular automaton of size 31 CA example = new CA(31); // Create a new rule int[] rule = {0, 1, 0, 0, 1, 0, 0, 0}; // Initialize the CA with the rule example.initialize(rule); // Get an iterator Iterator<String> iterator = example.iterator(); // Run the cellular automaton for 17 steps for (int i = 0; i < 17; i++) { if (iterator.hasNext()) { String s = iterator.next(); System.out.println(s); } } }