HOME
>
Programing
>
Pascal
>
ECAの計算
注意
-
このサイトの利用によって生じた損害については当方では責任を負いかねますのでご了承ください。
概要
-
離散的計算モデルであるElementary Cellular Automaton(ECA)の計算を行います。
コード
program ECA(input, output);
{Elementary Cellular Automaton}
const len = 25;
procedure main;
var seed, i, j, k : integer;
tr : array [0..1, 0..1, 0..1] of integer;
w, tmp : array [-len*2 .. len*2] of integer;
begin
{パターンの種を読み込む}
writeln('Input Seed number (0 - 256)');
write('Seed = ');
readln(seed);
{変換パターンの作成}
{seedを2進数展開する}
for i := 0 to 1 do
for j := 0 to 1 do
for k := 0 to 1 do
begin
tr[i,j,k] := seed mod 2;
seed := seed div 2
end;
{変換パターンの出力}
for i := 0 to 1 do
for j := 0 to 1 do
for k := 0 to 1 do
writeln('tr[', i, ',', j, ',', k, '] = ', tr[i,j,k]);
{列の初期化}
for i := -len*2 to len*2 do
w[i] := 0;
w[0] := 1;
{初期列の書き出し}
for k := -len to len do
if w[k] = 1 then
write('#')
else
write(' ');
writeln;
{パターンによる変換と書き出し}
for i:= 1 to len do
begin
{変換}
for j := -len*2+i to len*2-i do
tmp[j] := tr[w[j-1], w[j], w[j+1]];
w := tmp;
{出力}
for k := -len to len do
if w[k] = 1 then
write('#')
else
write(' ');
writeln
end
end;
begin
main
end.
実行結果1(ルール30)
$ CalcECA
Input Seed number (0 - 256)
Seed = 30
tr[0,0,0] = 0
tr[0,0,1] = 1
tr[0,1,0] = 1
tr[0,1,1] = 1
tr[1,0,0] = 1
tr[1,0,1] = 0
tr[1,1,0] = 0
tr[1,1,1] = 0
#
###
## #
## ####
## # #
## #### ###
## # # #
## #### ######
## # ### #
## #### ## # ###
## # # #### ## #
## #### ## # # ####
## # ### ## ## # #
## #### ## ### ### ## ###
## # # ### # ### # #
## #### ## # # ##### #######
## # ### #### # ### #
## #### ## ### ## ## # ###
## # # ### # ## ### #### ## #
## #### ## # ###### # # ### ####
## # ### #### #### ### ## # #
## #### ## ### # ## # # # ### ###
## # # ### # ### ## # ### ## # # # #
## #### ## # ### # # #### # # ## ######
## # ### #### ## ##### # ##### # # #
## #### ## ### # ## # # ## # ##### ###
実行結果2(ルール50)
$ CalcECA
Input Seed number (0 - 256)
Seed = 50
tr[0,0,0] = 0
tr[0,0,1] = 1
tr[0,1,0] = 0
tr[0,1,1] = 0
tr[1,0,0] = 1
tr[1,0,1] = 1
tr[1,1,0] = 0
tr[1,1,1] = 0
#
# #
# # #
# # # #
# # # # #
# # # # # #
# # # # # # #
# # # # # # # #
# # # # # # # # #
# # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # # # # # #
# # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # #
実行結果3(ルール90)
$ CalcECA
Input Seed number (0 - 256)
Seed = 90
tr[0,0,0] = 0
tr[0,0,1] = 1
tr[0,1,0] = 0
tr[0,1,1] = 1
tr[1,0,0] = 1
tr[1,0,1] = 0
tr[1,1,0] = 1
tr[1,1,1] = 0
#
# #
# #
# # # #
# #
# # # #
# # # #
# # # # # # # #
# #
# # # #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # #
# #
# # # #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # #
# # # #
# # # # # # # #
実行結果4(ルール110)
$ CalcECA
Input Seed number (0 - 256)
Seed = 110
tr[0,0,0] = 0
tr[0,0,1] = 1
tr[0,1,0] = 1
tr[0,1,1] = 1
tr[1,0,0] = 0
tr[1,0,1] = 1
tr[1,1,0] = 1
tr[1,1,1] = 0
#
##
###
## #
#####
## #
### ##
## # ###
####### #
## ###
### ## #
## # #####
##### ## #
## # ### ##
### #### # ###
## # ## ##### #
######## ## ###
## #### ## #
### ## # #####
## # ### #### #
##### ## ### # ##
## # ##### # ## ###
### ## ## ######## #
## # ###### ## ###
####### # ### ## #
## # #### # #####