2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,43 @@
Another new solution (twice size as previous solution) :
cat automata.awk :
#!/usr/local/bin/gawk -f
# User defined functions
function ASCII_to_Binary(str_) {
gsub("_","0",str_); gsub("@","1",str_)
return str_
}
function Binary_to_ASCII(bit_) {
gsub("0","_",bit_); gsub("1","@",bit_)
return bit_
}
function automate(b1,b2,b3) {
a = and(b1,b2,b3)
b = or(b1,b2,b3)
c = xor(b1,b2,b3)
d = a + b + c
return d == 1 ? 1 : 0
}
# For each line in input do
{
str_ = $0
gen = 0
taille = length(str_)
print "0: " str_
do {
gen ? str_previous = str_ : str_previous = ""
gen += 1
str_ = ASCII_to_Binary(str_)
split(str_,tab,"")
str_ = and(tab[1],tab[2])
for (i=1; i<=taille-2; i++) {
str_ = str_ automate(tab[i],tab[i+1],tab[i+2])
}
str_ = str_ and(tab[taille-1],tab[taille])
print gen ": " Binary_to_ASCII(str_)
} while (str_ != str_previous)
}

View file

@ -1,14 +1,17 @@
class Automata {
has ($.rule, @.cells);
method gist { <| |>.join: @!cells.map({$_ ?? '#' !! ' '}).join }
method code { $.rule.fmt("%08b").comb.reverse }
class Automaton {
has $.rule;
has @.cells;
has @.code = $!rule.fmt('%08b').flip.comb».Int;
method gist { "|{ @!cells.map({+$_ ?? '#' !! ' '}).join }|" }
method succ {
self.new: :$.rule, :cells()
self.code[
[Z+] 4 «*« @.cells.rotate(-1),
2 «*« @.cells,
@.cells.rotate(1)
]
)
self.new: :$!rule, :@!code, :cells()
@!code[
4 «*« @!cells.rotate(-1)
»+« 2 «*« @!cells
»+« @!cells.rotate(1)
]
)
}
}

View file

@ -1,5 +1,6 @@
my $size = 10;
my Automata $a .= new:
:rule(104),
:cells( 0 xx $size div 2, '111011010101'.comb, 0 xx $size div 2 );
my @padding = 0 xx 5;
my Automaton $a .= new:
rule => 104,
cells => flat @padding, '111011010101'.comb, @padding
;
say $a++ for ^10;

View file

@ -1,4 +1,4 @@
my $size = 50;
my Automata $a .= new: :rule(90), :cells( 0 xx $size div 2, 1, 0 xx $size div 2 );
my @padding = 0 xx 25;
my Automaton $a .= new: :rule(90), :cells(flat @padding, 1, @padding);
say $a++ for ^20;

View file

@ -25,7 +25,7 @@ Repeat
nG(n)=0
EndIf
Next
Swap cG() , nG()
CopyArray(nG(), cG())
Until Gen > 9
PrintN("Press any key to exit"): Repeat: Until Inkey() <> ""

View file

@ -1,15 +1,16 @@
/*REXX program displays N generations of one-dimensional cellular automata.*/
parse arg $ gens .; if $=='' | $==',' then $=001110110101010 /*use default?*/
if gens=='' then gens=40 /* " " */
L=length($)-1 /*adjusted len*/
do #=0 for gens /*process gens*/
say " generation" right(#,length(gens)) ' ' translate($,"",10)
@=0 /*+ generation*/
do j=2 for L; x=substr($,j-1,3) /*obtain cell.*/
if x==011 | x==101 | x==110 then @=overlay(1,@,j) /*cell lives. */
else @=overlay(0,@,j) /*cell death. */
end /*j*/
if $==@ then do; say right('repeats',40); leave; end /*it repeats? */
$=@ /*now use the next generation of cells.*/
end /*#*/
/*stick a fork in it, we're all done. */
/*REXX program generates & displays N generations of one─dimensional cellular automata. */
parse arg $ gens . /*obtain optional arguments from the CL*/
if $=='' | $=="," then $=001110110101010 /*Not specified? Then use the default.*/
if gens=='' | gens=="," then gens=40 /* " " " " " " */
do #=0 for gens /* process the one-dimensional cells.*/
say " generation" right(#,length(gens)) ' ' translate($, "", 10)
@=0 /* [↓] generation.*/
do j=2 for length($) - 1; x=substr($, j-1, 3) /*obtain the cell.*/
if x==011 | x==101 | x==110 then @=overlay(1, @, j) /*the cell lives. */
else @=overlay(0, @, j) /* " " dies. */
end /*j*/
if $==@ then do; say right('repeats', 40); leave; end /*does it repeat? */
$=@ /*now use the next generation of cells.*/
end /*#*/ /*stick a fork in it, we're all done. */