#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Sierpinski_triangle
#

func sierpinski_triangle(n) {
    var triangle = ['*'];
    { |i|
        var sp = (' ' * 1<<i);
        triangle = (triangle.map {|x| sp + x + sp} +
                    triangle.map {|x| x + ' ' + x});
    } * n;
    triangle.join("\n");
}
 
say sierpinski_triangle(4);
