43 lines
1.1 KiB
Text
43 lines
1.1 KiB
Text
MODULE Cell EXPORTS Main;
|
|
|
|
IMPORT IO, Fmt, Word;
|
|
|
|
VAR culture := ARRAY [0..19] OF INTEGER {0, 1, 1, 1,
|
|
0, 1, 1, 0,
|
|
1, 0, 1, 0,
|
|
1, 0, 1, 0,
|
|
0, 1, 0, 0};
|
|
|
|
PROCEDURE Step(VAR culture: ARRAY OF INTEGER) =
|
|
VAR left: INTEGER := 0;
|
|
this, right: INTEGER;
|
|
BEGIN
|
|
FOR i := FIRST(culture) TO LAST(culture) - 1 DO
|
|
right := culture[i + 1];
|
|
this := culture[i];
|
|
culture[i] :=
|
|
Word.Or(Word.And(this, Word.Xor(left, right)), Word.And(Word.Not(this), Word.And(left, right)));
|
|
left := this;
|
|
END;
|
|
culture[LAST(culture)] := Word.And(culture[LAST(culture)], Word.Not(left));
|
|
END Step;
|
|
|
|
PROCEDURE Put(VAR culture: ARRAY OF INTEGER) =
|
|
BEGIN
|
|
FOR i := FIRST(culture) TO LAST(culture) DO
|
|
IF culture[i] = 1 THEN
|
|
IO.PutChar('#');
|
|
ELSE
|
|
IO.PutChar('_');
|
|
END;
|
|
END;
|
|
END Put;
|
|
|
|
BEGIN
|
|
FOR i := 0 TO 9 DO
|
|
IO.Put("Generation " & Fmt.Int(i) & " ");
|
|
Put(culture);
|
|
IO.Put("\n");
|
|
Step(culture);
|
|
END;
|
|
END Cell.
|