RosettaCodeData/Task/Sierpinski-carpet/PowerShell/sierpinski-carpet-1.psh
2016-12-05 22:15:40 +01:00

17 lines
491 B
Text

function Draw-SierpinskiCarpet ( [int]$N )
{
$Carpet = @( '#' ) * [math]::Pow( 3, $N )
ForEach ( $i in 1..$N )
{
$S = [math]::Pow( 3, $i - 1 )
ForEach ( $Row in 0..($S-1) )
{
$Carpet[$Row+$S+$S] = $Carpet[$Row] * 3
$Carpet[$Row+$S] = $Carpet[$Row] + ( " " * $Carpet[$Row].Length ) + $Carpet[$Row]
$Carpet[$Row] = $Carpet[$Row] * 3
}
}
$Carpet
}
Draw-SierpinskiCarpet 3