Created
January 28, 2017 22:22
-
-
Save Fhernd/5a692fc7001b9168ca2e62f65f6030c4 to your computer and use it in GitHub Desktop.
Generación de comandos de Logo para dibujar un triángulo de Sierpinski.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment