Talk:One-dimensional cellular automata

From Rosetta Code
Revision as of 14:46, 17 January 2015 by Poulteki (talk | contribs) (Feeling that code compacity is important here, so I propose a different script to achieve this goal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I propose a different script to achieve this goal as :

  1. !/usr/local/bin/gawk -f
  2. FONCTIONS DEFINIES PAR UTILISATEUR

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 }

  1. POUR CHAQUE LIGNE DU FICHIER EN ENTREE FAIRE

{ str_=$0 gen=0 taille=length(str_) print "0: " str_ do { gen ? str_previous=str_ : str_previous="" gen=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)

}

  1. ACTIONS POST TRAITEMENT

END { }