forked from KolibriOS/kolibrios
75 lines
1.2 KiB
Plaintext
75 lines
1.2 KiB
Plaintext
|
(*
|
||
|
adapted to Oberon-07 by 0CodErr, KolibriOS team
|
||
|
*)
|
||
|
MODULE SierpinskiCarpet;
|
||
|
|
||
|
IMPORT In, Out, Console;
|
||
|
|
||
|
|
||
|
VAR
|
||
|
order: INTEGER;
|
||
|
|
||
|
|
||
|
PROCEDURE pow(b, n: INTEGER): INTEGER;
|
||
|
VAR
|
||
|
i, res: INTEGER;
|
||
|
|
||
|
BEGIN
|
||
|
res := 1;
|
||
|
FOR i := 1 TO n DO
|
||
|
res := res * b
|
||
|
END
|
||
|
|
||
|
RETURN res
|
||
|
END pow;
|
||
|
|
||
|
|
||
|
PROCEDURE in_carpet(x, y: INTEGER): BOOLEAN;
|
||
|
VAR
|
||
|
res, exit: BOOLEAN;
|
||
|
|
||
|
BEGIN
|
||
|
exit := FALSE;
|
||
|
res := TRUE;
|
||
|
WHILE (x > 0) & (y > 0) & (exit = FALSE) DO
|
||
|
IF (x MOD 3 = 1) & (y MOD 3 = 1) THEN
|
||
|
res := FALSE;
|
||
|
exit := TRUE
|
||
|
END;
|
||
|
y := y DIV 3;
|
||
|
x := x DIV 3
|
||
|
END
|
||
|
|
||
|
RETURN res
|
||
|
END in_carpet;
|
||
|
|
||
|
|
||
|
PROCEDURE PrintSierpinski(n: INTEGER);
|
||
|
VAR
|
||
|
i, j, l: INTEGER;
|
||
|
|
||
|
BEGIN
|
||
|
l := pow(3, n) - 1;
|
||
|
FOR i := 0 TO l DO
|
||
|
FOR j := 0 TO l DO
|
||
|
IF in_carpet(i, j) THEN
|
||
|
Out.Char("#")
|
||
|
ELSE
|
||
|
Out.Char(" ")
|
||
|
END
|
||
|
END;
|
||
|
Out.Ln
|
||
|
END
|
||
|
END PrintSierpinski;
|
||
|
|
||
|
|
||
|
BEGIN
|
||
|
Console.open;
|
||
|
|
||
|
Out.String("Input carpet order(0..3):");
|
||
|
In.Int(order);
|
||
|
PrintSierpinski(order);
|
||
|
In.Ln;
|
||
|
|
||
|
Console.exit(TRUE)
|
||
|
END SierpinskiCarpet.
|