Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/5a692fc7001b9168ca2e62f65f6030c4 to your computer and use it in GitHub Desktop.
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.
// 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