| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- (*
- 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.
|