Elementary cellular automaton: Difference between revisions

Content added Content deleted
(Added prolog implementation)
Line 1,540: Line 1,540:
#.#.............#.#
#.#.............#.#
</pre>
</pre>

=={{header|Prolog}}==
<lang prolog>initial([0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0]).

r(0,0,0,0).
r(0,0,1,1).
r(0,1,0,0).
r(0,1,1,1).
r(1,0,0,1).
r(1,0,1,0).
r(1,1,0,1).
r(1,1,1,0).

apply_rules([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S],
[A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1]) :-
r(S,A,B,A1), r(A,B,C,B1), r(B,C,D,C1), r(C,D,E,D1), r(D,E,F,E1),
r(E,F,G,F1), r(F,G,H,G1), r(G,H,I,H1), r(H,I,J,I1), r(I,J,K,J1),
r(J,K,L,K1), r(K,L,M,L1), r(L,M,N,M1), r(M,N,O,N1), r(N,O,P,O1),
r(O,P,Q,P1), r(P,Q,R,Q1), r(Q,R,S,R1), r(R,S,A,S1).
play :- initial(I), play(50, I).

writ(0) :- write('.').
writ(1) :- write(1).

play(0, _) :- !.
play(N, I) :-
maplist(writ, I), nl,
apply_rules(I, Next),
succ(N1, N),
play(N1, Next).</lang>



=={{header|Python}}==
=={{header|Python}}==