Task
Produce an ASCII representation of a Sierpinski triangle of order   N.



Example
The Sierpinski triangle of order   4   should look like this:

                       *
                      * *
                     *   *
                    * * * *
                   *       *
                  * *     * *
                 *   *   *   *
                * * * * * * * *
               *               *
              * *             * *
             *   *           *   *
            * * * *         * * * *
           *       *       *       *
          * *     * *     * *     * *
         *   *   *   *   *   *   *   *
        * * * * * * * * * * * * * * * *



Related tasks
 Sierpinski triangle/Graphical for graphics images of this pattern. 
 Sierpinski carpet


include "cowgol.coh";
include "argv.coh";
 
var order: uint8 := 4; # default order
 
# Read order from command line if there is an argument
ArgvInit();
var argmt := ArgvNext();
if argmt != 0 as [uint8] then 
    var a: int32;
    (a, argmt) := AToI(argmt);
    if a<3 or 7<a then
        print("Order must be between 3 and 7.");
        print_nl();
        ExitWithError();
    end if;
    order := a as uint8;
end if;
 
var one: uint8 := 1; # shift argument can't be constant...
var size: uint8 := one << order;
 
var y: uint8 := size;
while y > 0 loop
    var x: uint8 := 0;
    while x < y-1 loop
        print_char(' ');
        x := x + 1;
    end loop;
    x := 0;
    while x + y <= size loop
        if x & (y-1) != 0 then
            print("  ");
        else
            print("* ");
        end if;
        x := x + 1;
    end loop;
    print_nl();
    y := y - 1;
end loop;