5 kyu

2D Cellular Automata [Code Golf]

Description
Loading description...
Mathematics
Restricted
Algorithms
Cellular Automata
  • Please sign in or sign up to leave a comment.
  • FArekkusu Avatar

    Python 3.8 should be enabled.

  • Blind4Basics Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    Might be interesting to reduce the execution time: it's a bit weird to wait 9s to get feedback for this kind of task. You should begin with building your own version of deepcopy: this module/function is just fucking slow... x/ That should divide by 2 the time of execution of the tests, already.

    • Dr Gabo Avatar

      You would be surprised by how little deepcopy matters in these tests. I can reduce the number of big tests (half maybe?), which seem to be approx. 80-90% of the execution time. Do you think it's more convenient that way?

    • Blind4Basics Avatar

      ah right, I forgot what actually was the task... XD Yes I guess it would be better. There is no point to use so much ressources here. As long as you can check that the algo is correct...

    • Dr Gabo Avatar

      Seems reasonable. Now the execution time should be around 4 secs.

      Suggestion marked resolved by Dr Gabo 5 years ago
  • Blind4Basics Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    not hard enough... ;p I could go lower than this (and I'm bad ot golfing XD )

  • Blind4Basics Avatar

    can we mutate the input?

  • Blind4Basics Avatar

    Hi,

    The description is missing stuff (maybe for "non mathematically oriented ppl"...? x) ).

    Let's say the matrix is

    0 0 1 1 0
    1 1 0 0 1
    0 1 0 0 0
    

    and rules are: [[1,1,1]]. how do you apply it to the matric exactly?

    * 0 1 1 0  ->  0 * 1 1 0
    * 1 0 0 1  ->  1 * 0 0 1    ?
    * 1 0 0 0  ->  0 * 0 0 0
    
    
    * * * 1 0  ->  0 * * * 0
    1 1 0 0 1  ->  1 1 0 0 1    ??
    0 1 0 0 0  ->  0 1 0 0 0
    

    anything else???

    When several rules, if I understood correctly, we just apply all of them at "the same place" to determine if the central bit is 0 or 1, right?

    => you have to give an example matching the actual task. Examples only for 1D may have introductory purpose, but no more ;p

    • Dr Gabo Avatar

      The second way is the correct one if I understood you correctly.

      given a matrix

      0 0 0 0 0
      1 0 0 1 1
      1 1 1 0 0
      0 0 1 0 1
      

      and a rule

      0 0 0
      

      It will slide like this:

      * * * 0 0
      1 0 0 1 1
      1 1 1 0 0
      0 0 1 0 1
      
      
      0 * * * 0
      1 0 0 1 1
      1 1 1 0 0
      0 0 1 0 1
      
      ...
      
      0 0 0 0 0
      1 0 0 1 1
      1 * * * 0
      0 0 1 0 1
      
      ...
      

      In short, rules are not rotated. I will make that clear in the description :) (also some examples for the 2D case)

      Also, you are right about the application of multiple rules. If any of the rules give a 1 when centered at some position, then it will be a one.

    • Blind4Basics Avatar

      ok, good. About the wrapping, it happens only on a line? (seems evident, but just to be sure) I mean, not this way:

      0 0 0 0 0
      1 0 0 1 *
      * * 0 0 0
      0 0 1 0 1
      
    • Blind4Basics Avatar

      errr... what is steps... ? xo The number of "one step shift"? Or the number of passes over the complete matrix? Seems rather evident it's the first (...??), but make it clear

    • Dr Gabo Avatar

      The description says that we define a transformation as applying the rules to the whole matrix. step specifies how many times you have to transform the matrix, so it's the number of passes over the complete matrix.

      I'm sorry if that wasn't creal :S

    • Dr Gabo Avatar

      Also, I modified the description to add an example of the 2D case. Take a look if you may to see if it's clear enough :)

    • Blind4Basics Avatar

      Shouldn't the very first 2D example rather be this one??

      * * 0 *
      1 1 1 0  => They match, gives 1
      0 0 1 0
      

      Seems we don't care about the evoluitons of M in the current "step". That's not pretty clear either (but visible with the example... If I didn't mess up my brain in the meantime... x) )

    • Dr Gabo Avatar

      Intuitively, yes, but the order does not matter at all with this algorithm. I find it more easy to understand if the first example is not wrapping around.

      Also, on the second question. A step is done on the matrix without modifications (you can see the example, it does not change when sliding), so we do not care about the previous steps when doing a rule application.

    • Dr Gabo Avatar

      ok, good. About the wrapping, it happens only on a line? (seems evident, but just to be sure) I mean, not this way: [...]

      You're right, it only happens on the same row/column.

    • Blind4Basics Avatar
      Issue marked resolved by Blind4Basics 5 years ago