#!/usr/bin/ruby

func sierpinski_diamond(n) {
    var triangle = ['*'];
    { |i|
        var sp = (' ' * 2**i);
        triangle = (triangle.map {|x| sp + x + sp } +
                    triangle.map {|x| x + ' ' + x } +
                    triangle.map {|x| sp + x + sp} );
    } * n;
    triangle.join("\n");
}

say sierpinski_diamond(2);
