实施元胞自动机? “规则110”

发布于 2024-10-20 09:03:22 字数 533 浏览 1 评论 0原文

我想知道如何使用 55 条线和 14 个单元格的规则 110。然后我必须将其显示在 LED 矩阵显示屏上。

不管怎样,我的问题是,我怎样才能实现这样的自动机?

我真的不知道从哪里开始,有人可以告诉我如何解决这个问题吗?

我必须遵循特定的方法吗?

谢谢

--使用的程序是-> C

编辑

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];
 }

}

这有意义吗? org 代表原始

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-10-27 09:03:22

好的,每个元胞自动机都是围绕“递归关系”构建的,因此时间 t 的状态取决于时间 t-1 的状态。因此,每个元胞自动机都有一个基本结构,其中有一些代表状态的数据结构,例如数组。因此,抽象地讲,您的程序将类似于

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

其中 rule(t) 是计算下一个状态的函数。

下一步是提出一个数据结构来表示状态。这实际上很简单——基本一维元胞自动机的状态只是一个由 1 和 0 组成的向量。

所以你需要一个由 14 个小数字组成的数组。空间不会成为问题,因此使用 int:

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

结束条件很简单 - 您应该执行 55 行,因此您需要

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

注意,它为您提供第 0-54 行,即 55 行。 C 是从 0 开始,后递增,并测试小于。您用 C 编写的 10 个循环中可能有 9 个都会具有这种模式。

现在,最后的问题是如何实施您的规则。不幸的是,由于这是 C,所以你不能像我的描述那样简单地做到这一点;该规则必须更新向量。这看起来很像

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

现在,我不会确切地告诉您如何计算更新,因为那样您就不会获得任何乐趣。但您可能会发现关于规则 110 的维基百科文章很有趣

当您阅读它时,请思考一下:这个简单的规则是“图灵完备的”——这意味着它能够(也许需要很多麻烦)表示任何计算。这个简单的规则本身就是理论意义上的“计算机”。

更新

好的,更多关于规则的内容。查看 Wiki 文章中的规则表。它显示的是您获取数组的三个单元格并确定三个单元格中中间一个的下一个值。

因此,在您的规则中,您需要传入的数组 t 和下一时刻的数组,将其称为 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

您想要遍历数组的每个单元格

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

并检查该单元格以及左侧和右侧的单元格

            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;

等等。您需要考虑边缘处发生的情况,即当 ix == 0ix == 13 时。

最后,您需要另一个 for 循环将 t1 复制回 t

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文