RosettaCodeData/Task/Sierpinski-triangle/C-sharp/sierpinski-triangle-5.cs
2023-07-01 13:44:08 -04:00

26 lines
528 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static List<string> Sierpinski(int n)
{
return Enumerable.Range(0, n).Aggregate(
new List<string>(){"*"},
(p, i) => {
string SPACE = " ".PadRight((int)Math.Pow(2, i));
var temp = new List<string>(from x in p select SPACE + x + SPACE);
temp.AddRange(from x in p select x + " " + x);
return temp;
}
);
}
static void Main ()
{
foreach(string s in Sierpinski(4)) { Console.WriteLine(s); }
}
}