Skip to content

Instantly share code, notes, and snippets.

@lukakostic
Last active August 26, 2018 19:12
Show Gist options
  • Save lukakostic/937a863f8e1658bdd5af8432572ba603 to your computer and use it in GitHub Desktop.
Save lukakostic/937a863f8e1658bdd5af8432572ba603 to your computer and use it in GitHub Desktop.
/*
Try doing your own to replicate the below output, it took me more than id like to admit ;) (~1-2hrs)
lenght = 25
*************************
************ ************
*********** ***********
********** **********
********* *********
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
******** ********
********* *********
********** **********
*********** ***********
************ ************
*************************
*/
int dotsOnLine(int n){
if(n == 1) return 0;
if(n == 2) return 1;
return dotsOnLine(n-1)+2;
}
int main()
{
double lenght = 25;
for(double i = 1; i < lenght+1; i++){
double dots = 0;
if(i>(lenght/2.0)){
dots = dotsOnLine(lenght-i+1);
}else{
dots = dotsOnLine(i);
}
double spaces = lenght-dots;
for(double j = 1; j < lenght+1; j++){
if(j==(lenght/2.0)+0.5)
{
if(j<=((spaces/2.0)+0.5)){
printf("*");
}else{
printf(" ");
}
}
else if(j<=(lenght/2.0))
{
if(j<((spaces/2.0)+0.5)){
printf("*");
}else{
printf(" ");
}
}
else
{
if((lenght+1-j) <((spaces/2.0)+0.5)){
printf("*");
}else{
printf(" ");
}
}
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment