Last active
October 19, 2015 11:19
-
-
Save oxcar103/0661461b1fd0fd1910be to your computer and use it in GitHub Desktop.
Programa que realiza un triángulo de Sierpinski con el número de triángulos centrales determinados por el parámetro que se le pase. Para una correcta ejecución, se debe pasar un parámetro menor que 4 para verlo en la terminal o redireccionar la salida a un fichero de texto, reducir el tamaño de letra y buscar "1" ó "0".
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
#include <iostream> | |
#include <stdlib.h> | |
#include <vector> | |
#include <math.h> | |
using namespace std; | |
int main(int argc, char *argv[]){ | |
if(argc != 2){ | |
cout << "Uso correcto: ./Sierpinski <número de triángulos centrales>\n"; | |
return -1; | |
} | |
else{ | |
int triangulos = atoi(argv[1])+2; | |
int size = pow(2,triangulos); | |
vector<int> fila (size, 0), nueva (size, 0); | |
fila[size/2] = fila[size/2-1] = 1; | |
for(int i = 0; i < size; i++){ | |
cout << fila[i]; | |
} | |
cout << endl; | |
while(fila[0] != 1){ | |
for(int i = 0; i < size; i++){ | |
nueva[i] = (fila[i]==fila[i-1] && fila[i]==fila[i+1])? 0 : 1; | |
} | |
for(int i = 0; i < size; i++){ | |
fila[i] = nueva[i]; | |
cout << fila[i]; | |
} | |
cout << endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment