79 lines
1.3 KiB
Plaintext
79 lines
1.3 KiB
Plaintext
|
(*
|
||
|
adapted to Oberon-07 by 0CodErr, KolibriOS team
|
||
|
*)
|
||
|
(* Find sequence of digits 0, 1, 2 and of lengths 1 ... 90, such
|
||
|
that they contain no two adjacent subsequences that are equal *)
|
||
|
|
||
|
MODULE sequence012;
|
||
|
|
||
|
IMPORT In, Out, Console;
|
||
|
|
||
|
|
||
|
CONST
|
||
|
maxlength = 75;
|
||
|
|
||
|
|
||
|
VAR
|
||
|
n: INTEGER;
|
||
|
good: BOOLEAN;
|
||
|
s: ARRAY maxlength OF INTEGER;
|
||
|
|
||
|
|
||
|
PROCEDURE printsequence;
|
||
|
VAR
|
||
|
k: INTEGER;
|
||
|
BEGIN
|
||
|
Out.Char(" ");
|
||
|
FOR k := 1 TO n DO Out.Int(s[k], 1) END;
|
||
|
Out.Ln
|
||
|
END printsequence;
|
||
|
|
||
|
|
||
|
PROCEDURE changesequence;
|
||
|
BEGIN
|
||
|
IF s[n] = 3 THEN
|
||
|
DEC(n);
|
||
|
changesequence
|
||
|
ELSE
|
||
|
s[n] := s[n] + 1
|
||
|
END
|
||
|
END changesequence;
|
||
|
|
||
|
|
||
|
PROCEDURE try;
|
||
|
VAR
|
||
|
i, l, nhalf: INTEGER;
|
||
|
|
||
|
BEGIN
|
||
|
IF n <= 1 THEN
|
||
|
good := TRUE
|
||
|
ELSE
|
||
|
l := 0; nhalf := n DIV 2;
|
||
|
REPEAT
|
||
|
INC(l); i := 0;
|
||
|
REPEAT
|
||
|
good := s[n - i] # s[n - l - i];
|
||
|
INC(i)
|
||
|
UNTIL good OR (i = l)
|
||
|
UNTIL ~good OR (l >= nhalf)
|
||
|
END
|
||
|
END try;
|
||
|
|
||
|
|
||
|
BEGIN
|
||
|
Console.open;
|
||
|
|
||
|
n := 0;
|
||
|
REPEAT
|
||
|
INC(n);
|
||
|
s[n] := 1; try;
|
||
|
WHILE ~good DO
|
||
|
changesequence;
|
||
|
try
|
||
|
END;
|
||
|
printsequence
|
||
|
UNTIL n >= maxlength - 1;
|
||
|
In.Ln;
|
||
|
|
||
|
Console.exit(TRUE)
|
||
|
END sequence012.
|