-2
0
Introduction
An elementary cellular automaton is a cellular automaton that is 1-dimensional and has 2 states, 1 and 0. These cellular automata are categorized based on a simple code: the Wolfram code, invented by Stephen Wolfram (yes, the Wolfram | Alpha guy). It works like this:
- First, you the set of all possible states for a cell and its 2 neighbors; this gives you 8 (2^3) states. You then arrange them in order (in this case) from left to right, so you have 000, 001, 010, 011, 100, 101, 110, and 111.
- Then, for each state, you take the resulting state of the center cell, either a 0 or 1. Then, you are left with 8 bits.
- You can guess what you do next: you combine the 8 bits into a single 1-byte number. This gives you 255 possible cellular automatons.
Challenge
Given the Wolfram code number of a cellular automaton and a 3-bit state, you must write a program that will output the state of the center cell for that state.
- The two integers may be taken from any input method that is convenient (ie. variable, stdin, command line arguments, function arguments) Input can be taken as any type, as long as that type is capable of representing integers. For example, you could take input as an array of digits, a string, or an integer. Input can be in any base you want.
- The output may also be in any convenient method (ie. variable, stdout, exit code, return value) The only restriction is that the use must be able to see the output (no outputting to /dev/null). Output can be given as any type as well.
Example I/O
Number:
255
, State:101
States:1, 1, 1, 1, 1, 1, 1, 1
Output:1
Number:
129
, State:110
States:1, 0, 0, 0, 0, 0, 0, 1
Output:0
Number:
170
, State:001
States:1, 0, 1, 0, 1, 0, 1, 0
Output:0
Rules
This is code-golf, so shortest answer in bytes wins!
1Now our task is to search for a duplicate of indexing. – None – 2019-12-10T13:36:12.680
2
You've had a number of questions that have been unclear, duplicates or turned out to be extremely trivial like this one. Have you considered posting your questions in the Sandbox for a couple of days in order to iron out some of the kinks beforehand?
– Jo King – 2019-12-12T23:54:12.997