| cellular_automata.py | ||
| main_cellular_automata.py | ||
| README.md | ||
DECODE DEMCODE CHALLENGE #2
Description
A solution for the Decode Demcon Challenge #2 - Linear Cellular Automata.
The generations are implemented as the binary representations of integers.
The right and left neighbours are obtained by left and right shifts respectively.
The rule table is represented by a single integer, where the n-th bit is set to 1 if the binary representation of n interpreted as the row in the rule table is True, e.g. the 5th bit is set if 5 = (101)2, so True False True, which means the cell is unset and both its neighbours are occupied.
Given that the values of all rules will be ANDed there is a need to flip the bits if an entry in the rule table is False. For this we XOR with a mask consisting of 1s with the length of the automata.
The main advantage of this representation is that a batch of cells equal to the word length of the processor can be iterated at once.
A slight improvement could be achieved by calculating the next generations unset bits if the population count of the rule table integer is more than half.
Running the project
To execute run
python main_cellular_automata.py
Then input a setup, for example
A 11 10 init_start 6 init_end
B 61 20 init_start 20 40 init_end
U 60 40 init_start 40 60 init_end 0 1 1 0 0 1 1 0