27
3
Rule 110 is a cellular automaton with some interesting properties. Your goal is to simulate a rule 110 in as few characters as possible.
For those who don't know, rule 110 is simulated line by line in a grid. Each square in a line of the grid looks at the squares above, above-left and above-right to determine what cell it should be.
current pattern 111 110 101 100 011 010 001 000
new cell 0 1 1 0 1 1 1 0
Input: numbers from 0 to 39 representing top row nth input square, in any reasonable format (comma-separated string, list, function arguments). To accommodate 1-indexed languages, numbers may also be 1-indexed and so range from 1 to 40.
Example input:
38,39
Output: A 40 x 40 grid representing the automata running including the first row. You should leave 0 as blank and 1 as any visible printing character. Trailing spaces are allowed, as long as the actual grid can reasonably be distinguished. The bottom of the grid may have a newline but there should not be blank lines between grid lines.
Example output:
XX
XXX
XX X
XXXXX
XX X
XXX XX
XX X XXX
XXXXXXX X
XX XXX
XXX XX X
XX X XXXXX
XXXXX XX X
XX X XXX XX
XXX XXXX X XXX
etc.
Note: A similar question about 1D cellular automata has already been asked, but I hope that, by using only one rule, shorter answers can be written.
You should probably specify that the space character can't be used for a 1. – KSFT – 2015-02-14T23:36:52.113
Rule #110: Mathematica has a built-in for all problems? – Stan Strum – 2018-03-02T19:33:50.017
Come on, someone do Husk! – Evan Carroll – 2018-04-19T23:31:52.990
Are 1-based indexing allowed, is a leading 0/space allowed? – ბიმო – 2018-12-04T22:03:01.200
@EvanCarroll: Here you go :D
– ბიმო – 2018-12-05T20:42:56.2471@BMO this is an old question, but since nowadays consensus is to allow flexible input formats, I'll modify the question to allow it – qwr – 2018-12-05T20:46:11.660
4Do the patterns wrap around (i.e. does the left-most cell check the right-most cell in the line above it)? – Ventero – 2014-07-14T07:15:00.710
4If it's singular, then it's a cellular automaton. – ClickRick – 2014-07-14T09:14:38.947
Do we have to take input as a comma-delimited string or (if we write a function) can we take a list of numbers as input? (At least one answer does the latter.) – Martin Ender – 2014-07-14T09:55:25.023
1
The answers may be fractionally shorter than Simulate any 1D cellular automaton because the rule is hard-coded rather than having to be parsed from the input, but other than that the answers are going to be the same. If it were a different rule then there would be potential for savings, but how on Earth would special-casing a Turing-powerful rule save anything over a general implementation?
– Peter Taylor – 2014-07-14T12:57:06.723@PeterTaylor I was thinking along the lines of some clever bithack. In addiction the input method and generation time is different. Lastly the current answers are much more than fractionally shorter (which doesn't really mean anything) – qwr – 2014-07-14T21:55:57.430
1@Ventero They do not in this version. – qwr – 2014-07-14T22:17:18.503
How do we handle edges? – xnor – 2014-07-14T22:29:52.937
@xnor Treat them as 0 – qwr – 2014-07-14T22:53:46.070
if you start at 1 and going to fill 40x40 whats the input for? – Sylwester – 2014-07-15T21:20:34.680
@Sylwester I'm sorry, I don't quite understand what you're asking. Can you clarify? – qwr – 2014-07-15T23:38:50.583
@qwr I cannot se the correlation between the input 38,39 and the 14 lines output starting with 3 (xx). – Sylwester – 2014-07-16T15:39:45.573