2

I was wondering how to use the Rule 110, with 55 lines and 14 cells. I have to then display that in an LED matrix display.

Anyway my question is, how can I implement such automaton ??

I dont really know where to start, can someone please shed some light on how can I approach this problem ?

Is there a specific METHOD I must follow ?

Thanks

--PROGRAM USED IS -> C

EDIT

char array[54][14];
for(v=0;v<55;v++){ 
  for(b=0;b<15;b++){ 
    if(org[v][b-1]==0 && org[v][b]==0 && org[v][b+1] == 0)                                                         
      {
        array[v][b]=0;
      }
      array[v][b]=org[v][b];
 }

}

Does that make sense ?? org stands for original

NLed
  • 1,845
  • 14
  • 39
  • 68
  • I added the "hpomewrk" tag; if I'm wrong, let us know. – Charlie Martin Mar 04 '11 at 02:24
  • Ok I deleted my other topic :) – NLed Mar 06 '11 at 14:23
  • Now you're getting into the right neighborhood. Two things: (1) you've got the rule step where all three cells are 0 -- but there are seven more rules, for 001 through 111. So you'll need a total of eight if's. (2) think about the effect of that last assignment, array[v][b]=org[v][b]; -- it doesn't do what you think it does. – Charlie Martin Mar 06 '11 at 21:26

1 Answers1

6

Okay, every cellular automaton is built around a "recurrance relation", so that the state at time t depends on the state at time t-1. So every cellular automaton has a basic structure where you have some data structure, like an array, that represents the state. So, abstractly, your program will look like

State t
/* initialize t */
while(/* end condition isn't satisfied */){
    t = rule(t);
    /* display state somehow */
}

where rule(t) is a function that computes that next state.

The next step is to come up with a data structure to represent the state. That's actually easy -- the state of an elementary 1 d cellular automaton is just a vector of 1s and 0s.

So you need an array of 14 small numbers. Space is not going to be an issue, so use int:

 int t[14] ; /* state vector*/

The end condition is easy -- you're supposed to do 55 rows, so you need

 int count = 0;
 while(count++ < 55)

Notice that gives you rows 0-54, which is 55. A good basic pattern in C is that you start at 0, post-increment, and test less-than. Probably 9 out of 10 loops you write in C will have that pattern.

Now, finally, the question is how to implement your rule. Unfortunately, since this is C, you can't do it quite as simply as in my description; the rule has to update the vector in place. That's going to look a lot like

void rule(int t[]){
     /* compute the update here */
}

Now, I'm not going to tell you exactly how to compute the update, because then you don't get any of the fun. But you might find the Wikipedia article on Rule 110 interesting.

When you read it, ponder this: This simple rule is "Turing complete" -- which means its capable, perhaps with lots of fussing about, of representing any computation. That simple rule, in itself, is a "computer" in the theoretical sense.

Update

Okay, a little more on the rules. Have a look at the rule table in the Wiki article. What it shows is that you take three cells of your array and determine the next value for the middle one of the three.

So in your rule, you need the array you pass in, t, and an array for the next instant, call it t1.

  void rule(int t[]){ // there's the original
       int t1[14];    // there's the new array
       int ix ;       // an index for the loop that's coming up

You want to go through each cell of the array

       for(ix=0; ix < 14; ix++){

and check the cell, along with the cells to left and right

            if(t[ix-1] == 0 && t[ix] == 0 && t[ix+1] == 0)
               t1[ix] = 0;
            else if(t[ix-1] == 0 && t[ix] == 0 && t[ix+1] == 1)
               t1[ix] = 1;

and so on. You'll need to think about what happens at the edges, ie, when ix == 0 or ix == 13.

Fincally, you'll need another for loop to copy t1 back into t.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • Hmm, can I replace these conditions with if statements ? For example, if I put : If array [0][0]=1, [0][1]=1, [0][2]=1, then [1][1]=0 ... or does this make no sense ? – NLed Mar 04 '11 at 02:29
  • You're on the right track, but this is a one-dimensional array, so the left hand side will always be t[something] = something ; – Charlie Martin Mar 04 '11 at 02:36
  • Thank you, very informative !! If I get stuck later on ill post back here :) – NLed Mar 04 '11 at 02:40
  • Thank you for the update, so since I got columns as well, I must add another value, for example : t1[14][col] ... right ? – NLed Mar 06 '11 at 15:20
  • Yes. If you're going to display them all at once, you need a second dimension, as you've shown it. – Charlie Martin Mar 06 '11 at 21:27