https://codegolf.stackexchange.com/questions/273387/cellular-automata-rule-30 Skip to main content Stack Exchange Network Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange [ ] Loading... 1. + Tour Start here for a quick overview of the site + Help Center Detailed answers to any questions you might have + Meta Discuss the workings and policies of this site + About Us Learn more about Stack Overflow the company, and our products 2. 3. current community + Code Golf help chat + Code Golf Meta your communities Sign up or log in to customize your list. more stack exchange communities company blog 4. 5. Log in 6. Sign up Share Your Experience: Take the 2024 Developer Survey Code Golf 1. 1. Home 2. Questions 3. Tags 4. 5. Users 6. Jobs New 7. Companies 8. Unanswered 2. Teams [teams-promo] Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams Create a free Team 3. Teams 4. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams Teams Q&A for work Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams Cellular Automata Rule 30 Ask Question Asked today Modified today Viewed 807 times 6 \$\begingroup\$ What is 'Rule 30'? Rule 30 is a particularly special automation because it demonstrates complexity arising from simple rules, chaos and randomness, and is computationally irreducible (i.e. the fastest way to find out what any cell or line will look like after many generations is simply to run the automaton). It's also Stephen Wolfram's favourite discovery: Today my all-time favorite science discovery is 40 yrs old! My June 1, 1984 diary told me to "take pict." of "R30" on a 9 pm flight to London ... which is when I finally realized (2 yrs after first generating it) what a big deal rule 30 is... Further explanation of rule 30. Challenge The goal is to generate the first 32 lines of cellular automata rule 30 as represented in ASCII (well, O's and .'s) as per this slightly modified example found on its wikipedia page: ...............................O............................... ..............................OOO.............................. .............................OO..O............................. ............................OO.OOOO............................ ...........................OO..O...O........................... ..........................OO.OOOO.OOO.......................... .........................OO..O....O..O......................... ........................OO.OOOO..OOOOOO........................ .......................OO..O...OOO.....O....................... ......................OO.OOOO.OO..O...OOO...................... .....................OO..O....O.OOOO.OO..O..................... ....................OO.OOOO..OO.O....O.OOOO.................... ...................OO..O...OOO..OO..OO.O...O................... ..................OO.OOOO.OO..OOO.OOO..OO.OOO.................. .................OO..O....O.OOO...O..OOO..O..O................. ................OO.OOOO..OO.O..O.OOOOO..OOOOOOO................ ...............OO..O...OOO..OOOO.O....OOO......O............... ..............OO.OOOO.OO..OOO....OO..OO..O....OOO.............. .............OO..O....O.OOO..O..OO.OOO.OOOO..OO..O............. ............OO.OOOO..OO.O..OOOOOO..O...O...OOO.OOOO............ ...........OO..O...OOO..OOOO.....OOOO.OOO.OO...O...O........... ..........OO.OOOO.OO..OOO...O...OO....O...O.O.OOO.OOO.......... .........OO..O....O.OOO..O.OOO.OO.O..OOO.OO.O.O...O..O......... ........OO.OOOO..OO.O..OOO.O...O..OOOO...O..O.OO.OOOOOO........ .......OO..O...OOO..OOOO...OO.OOOOO...O.OOOOO.O..O.....O....... ......OO.OOOO.OO..OOO...O.OO..O....O.OO.O.....OOOOO...OOO...... .....OO..O....O.OOO..O.OO.O.OOOO..OO.O..OO...OO....O.OO..O..... ....OO.OOOO..OO.O..OOO.O..O.O...OOO..OOOO.O.OO.O..OO.O.OOOO.... ...OO..O...OOO..OOOO...OOOO.OO.OO..OOO....O.O..OOOO..O.O...O... ..OO.OOOO.OO..OOO...O.OO....O..O.OOO..O..OO.OOOO...OOO.OO.OOO.. .OO..O....O.OOO..O.OO.O.O..OOOOO.O..OOOOOO..O...O.OO...O..O..O. OO.OOOO..OO.O..OOO.O..O.OOOO.....OOOO.....OOOO.OO.O.O.OOOOOOOOO Note: this may be a duplicate (or subset of) this previous challenge. * code-golf * ascii-art * cellular-automata Share Improve this question Follow edited 5 hours ago stevec asked 6 hours ago stevec's user avatar stevecstevec 16133 bronze badges New contributor stevec is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. \$\endgroup\$ 2 * 1 \$\begingroup\$ @Arnauld great catch (I hadn't noticed it). I think it's conventional not to include any empty column(s) (I suspect Wikipedia added it for visual clarity). I will remove it in the question. I think that's best \$\endgroup\$ - stevec 6 hours ago * 2 \$\begingroup\$ +1 but I would suggest explaining the rule rather than linking externally. \$\endgroup\$ - Jonathan Allan 4 hours ago Add a comment | 5 Answers 5 Sorted by: Reset to default [Highest score (default) ] 2 \$\begingroup\$ Google Sheets, 171 bytes =LET(o,"O",r,REPT(".",31),a,r&o&r,{a;SCAN(a,Z1:Z31,LAMBDA(a,_,JOIN(,MAP(SEQUENCE(63),LAMBDA(i,IF(XOR(IFERROR(MID(a,i-1,1))=o,OR(MID(a,i,1)=o,MID(a,i+1,1)=o)),o,"."))))))}) enter image description here Share Improve this answer Follow answered 5 hours ago z..'s user avatar z..z.. 59111 silver badge55 bronze badges \$\endgroup\$ Add a comment | 1 \$\begingroup\$ APL+WIN, 120 bytes m-32 63[?]0 m[0;62]-1 :for i :in 1+[?]31 n-m[i-1;] :for j :in [?]63 m[i;j]-(|v)[?](|1|v)[?]-1|v-3|n n-1|n :end :end '.o'[([?][?]32)[?]m] Try it online! Thanks to Dyalog Classic Share Improve this answer Follow answered 4 hours ago Graham's user avatar GrahamGraham 6,24611 gold badge1414 silver badges1111 bronze badges \$\endgroup\$ Add a comment | 1 \$\begingroup\$ JavaScript (ES11), 91 bytes f=(r=1n<<33n)=>r%2n?"":(g=s=>s[r/=2n,63]?s+f(r):g("._O"[r&2n]+s,r|=(7n*r%8n&4n)<<63n))(` `) Try it online! Share Improve this answer Follow edited 16 mins ago answered 5 hours ago Arnauld's user avatar ArnauldArnauld 193k2020 gold badges176176 silver badges638638 bronze badges \$\endgroup\$ Add a comment | 0 \$\begingroup\$ Jelly, [S: 22 :S] 21 bytes 32TOEBO0jH-MD3PDThi)O. A niladic Link that yields a list of lines. Try it online! How? 32TOEBO0jH-MD3PDThi)O. - Link: no arguments 32 - set the left argument to 32 T - untruth -> [0,0,...,0,1] (31 zeros and a one) OEB - bounce -> [0,0,...,0,1,0,...,0,0] (the top line) T - collect while distinct, applying: D - last three links as a monad - f(Line): O0 - literal [0,0] j - join with {Line} (wrap the Line with zeros) 3P - for overlapping infixes of length three: D - last three links as a monad - f([a,b,c]): H - head and yield {[a,b,c]} -> a M - max {[b,c]} -> M - - {a} not equal? {M} h - head to index {32} -> first 32 lines i)O. - index into "O." Possible triples and their new state: a b c max(b,c) -> M a != M -> New State 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 0 Share Improve this answer Follow edited 3 hours ago answered 3 hours ago Jonathan Allan's user avatar Jonathan AllanJonathan Allan 107k77 gold badges6464 silver badges276276 bronze badges \$\endgroup\$ Add a comment | 0 \$\begingroup\$ Charcoal, 32 bytes UB.x31ps0F31<<[?]F63--SSKM0[?]KM1|3 Try it online! Link is to verbose version of code. Explanation: UB. Set the "background", which is anywhere where the null character or no character all is printed, to .. x31ps0 Write a 0 in the 32nd column in the canvas. F31<< Repeat for each of the remaining 31 rows. [?] Start at the beginning of the next line. F63 Repeat for each of the 63 columns. --SSKM0[?]KM1|3 Peek the cells adjacent to the current cell. Using @JonathanAllan's formula, take the absolute difference of the ordinal of the cell above and to the left (a in his formula) with the ordinal of the maximum of the cells above (b) and above and to the right (c), and output the character with that ordinal. When the two values are equal, i.e. either all three cells are empty or a has a 0 and at least one of b and c have a 0, then the result is zero, and a null character is written, which is then considered to be part of the background, while if the two values are different then one will be a 0 and the other will not, and the absolute difference of the ordinals will be the ordinal of 0 and that will be output. 33 bytes using the actual definition of the rule: UB.x31ps0F31<<[?]F63SS+ps0/30X2[?]...KM3+ps0 Attempt This Online! Link is to verbose version of code. Needs to use ATO instead of TIO because AtIndex is broken on TIO. Explanation: As above but decodes the presence of the cells in the row above using a custom base, right-shifts 30 by that amount, then outputs the presence according to the LSB. Share Improve this answer Follow answered 1 hour ago Neil's user avatar NeilNeil 171k1212 gold badges7272 silver badges276276 bronze badges \$\endgroup\$ Add a comment | Your Answer [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] If this is an answer to a challenge... * ...Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead. * ...Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one. Explanations of your answer make it more interesting to read and are very much encouraged. * ...Include a short header which indicates the language(s) of your code and its score, as defined by the challenge. More generally... * ...Please make sure to answer the question and provide sufficient detail. * ...Avoid asking for help, clarification or responding to other answers (use comments instead). Draft saved Draft discarded [ ] Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Submit Post as a guest Name [ ] Email Required, but never shown [ ] Post as a guest Name [ ] Email Required, but never shown [ ] Post Your Answer Discard By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy. Not the answer you're looking for? Browse other questions tagged * code-golf * ascii-art * cellular-automata or ask your own question. Welcome to Code Golf and Coding Challenges Stack Exchange! This is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox. * The Overflow Blog * An open-source development paradigm * Developers get by with a little help from AI: Stack Overflow Knows code... * Featured on Meta * Testing a new version of Stack Overflow Jobs * What deliverables would you like to see out of a working group? Linked 9 Produce an image based on an elementary cellular automata ruleset Related 16 Simulate any 1D cellular automaton 25 Simulate the Wireworld cellular automaton 33 Simulate Rule 110 10 Identifying Sequences for Cellular Automata 14 Pseudorandom Cellular Automaton 16 Digital Cellular Automata 30 Plurality Voting with Cellular Automata 9 Produce an image based on an elementary cellular automata ruleset 8 Find the rule of a cellular automaton Hot Network Questions * Meaning of the last stanza of "Haunted Houses" by Longfellow? * How can I as a player handle the NPCs in a campaign stealing the spotlight? * unusual use of future tense instead of present tense: **wird .... haben** * How many plot twists are too many plot twists? * what is the title of the story that includes a character named Glauken and a woman named Magda? * Who is Gall in Italo Svevo's "Senilita"? * Catching a Cat on an infinite Line * Are dual citizenship passports linked? * How to draw complex speciation diagram? * Is the Rocket Lab launch scheduled for May 31 only launching a tiny cubesat? * Break a word into vowels and consonants * C++ static vector implementation * Universe apps not showing in app center Ubuntu 24.04 * How do I manage the Deck of Many Things? * When did the Catholic Church first make an official statement on the Millenarianism? * How can I help a PhD student who's dead-set on keeping methodologically wrong results? * Is it correct to say "a picture of teen uncle James"? * The last five Moves #2 * Solve recurrence relation * Is it possible to set the local value of showbreak to "nothing"? * Waking up in the middle of a dream * Makefile to build and test a C program * How many individual extrasolar "shiny" objects has humanity identified? * What rises to the level of being a "a different spirit," per 2 Corinthians 11:4? more hot questions Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. [https://codegolf.sta] * Code Golf * Tour * Help * Chat * Contact * Feedback Company * Stack Overflow * Teams * Advertising * Collectives * Talent * About * Press * Legal * Privacy Policy * Terms of Service * Cookie Settings * Cookie Policy Stack Exchange Network * Technology * Culture & recreation * Life & arts * Science * Professional * Business * API * Data * Blog * Facebook * Twitter * LinkedIn * Instagram Site design / logo (c) 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2024.5.30.9975