Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Axioma:
- string trianguloSierpinski = "A";
- // Reglas de producción:
- Func<string, string> transformarA = x => x.Replace("A", "B-A-B");
- Func<string, string> marcarBs = x => x.Replace("B", "[B]");
- Func<string, string> transformarB = x => x.Replace("[B]", "A+B+A");
- // Nivel de recursión:
- int nivelRecursion = 6;
- Enumerable.Range(1, nivelRecursion)
- .ToList()
- .ForEach(
- numRecursion =>
- {
- trianguloSierpinski = transformarB(transformarA(marcarBs(trianguloSierpinski)));
- }
- );
- trianguloSierpinski
- .Replace("A", "forward 5" + Environment.NewLine)
- .Replace("B", "forward 5" + Environment.NewLine)
- .Replace("+", "left 60" + Environment.NewLine)
- .Replace("-", "right 60" + Environment.NewLine)
- .Dump("Comandos Logo para Triángulo de Sierpinski");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement