Wolfram Cellular Automaton: Coding Train Challenge #179

2024-01-18
Wolfram Cellular Automaton: Coding Train Challenge #179 - Teaser

This is my entry to the Coding Train challenge #179 "wolfram alpha - CA".

Play it

The challenge was to build a simple cellular automaton that operates in only one dimension.

See the original video from the Coding Train
Read more about Elementary Cellular Automata

Deep dive

So the idea behind my entry was to play around with the ruleset of the cellular automaton.
What I ended up doing was basically adding the state of an entire row as part of the input for the next generation.

The 'global' state is defined by checking if the majority of cells in the current row are active or not.
Let's call that state 'sparse' for few active cells and 'crowded' for many active cells.

Determine the global state: crowded vs sparse
Determine the global state: crowded vs sparse

const alive_count = this.current_state.cells.reduce((a, b): number => a + b.value, 0); 
const global_state = alive_count > (this.current_state.cells.length / 2) ? 'crowded' : 'sparse';

Now if the new state of a cell should be determined based on the current neighbourhood we first apply two (distinct) regular rules for elementary cellular automata. Based on the 'global' state and the results we then decide the state of the new cell.
For a 'crowded' state both rules need to result in an active cell for the final result to return active.
For a 'sparse' state either rule needs to result in an active cell for the final result to return active.

global state influence
global state influence

switch (global_state) {
  case 'crowded': return rule1 && rule2;
  case 'sparse': return rule1 || rule2;
}

This leads to more 'stable' environments, where it is less likely that all cells assume the same state.
Rules in this automaton are defined by the first and the second sub-rule they apply.
As an example an update step in Rule "30 - 54" would look like this.

example 30-54
example 30-54

Some labels in the preset list do not match the rules they set: that is how the 2024 version shipped.

Comments

captcha