#include <stdio.h>
#include <math.h>

main()
{
int counter[6];
float mass[6] = {139.57018, /*pm0.00035*/
                 493.677, /*pm 0.016*/
                 1869.3, /*pm 0,4*/
             	 1968.2, /*pm 0.5 */
 		 5279.0, /*pm 0.5 */
                 6286    /*pm 5 */
		 };
char id[6] = "pkdDbB";
double sum,sqrtsum,koide;
double cosine[4],angle[4];
int used;
int carry;
int i,j;

for (i=0; i<6; i++) {counter[i]=0;}
counter[0]=1;


do{

 sum=0;
 for (j=0; j<6; sum+=abs(counter[j++]-1)*mass[j]);
 sqrtsum=0;
 for (j=0; j<6; sqrtsum+=(counter[j]-1)*sqrt(mass[j]),j++);
 koide=(sqrtsum*sqrtsum)/sum;
 /*printf("%f, %f, %f\n", sum, sqrtsum, koide);*/
 used=0;
 for (j=0; j<6; used+=abs(counter[j]-1), j++);
 /*this is R.Foot suggestion, to measure the angle against (1,1,..1), but
   we could consider either 6 components or just N components, so there 
   are two different calculations*/
 cosine[1]= sqrtsum/(sqrt(6)*sqrt(sum)); 
 cosine[2]= sqrtsum/(sqrt(used)*sqrt(sum));
  /*a third option, only realistic for used =2 */
 cosine[3]= sqrtsum/(sqrt(3)*sqrt(sum));
 for (j=1;j<4;j++){
 if (cosine[j]>1) 
   angle[j]=0;
 else
   {angle[j]=(90/asin(1))*acos(cosine[j]);}
 }

 /*for (j=0; j<6; printf ("%d ", counter[j]), j++); */

 for (j=0; j<6; j++) 
    switch (counter[j]-1) 
       {case -1: printf("-"); break;
        case 0 : printf("_"); break;
        case 1: printf("+"); break;
       }  
 ;


   
 printf("  "); for (j=used; j<6; j++) printf(" ");
 for (j=0; j<6; j++) 
    if (abs(counter[j]-1)) 
      printf("%c",id[j]); 
    /*else{ print none, we pad before} */
 ;


 printf(" %d",used);

 printf("\t   %#8.4f",koide);
 for (j=1;j<4;j++)
  printf("\t  %#8.4f",angle[j]);

 printf("\n");

/*here we count to advance, up to cover the 6 digits*/
carry=1;
for (i=0; i<6; i++) 
 {
 counter[i]=counter[i]+carry;
 if (counter[i] > 2) {
    carry=1; counter[i]=counter[i]-3;
    } 
 else carry=0;
 }
} while (carry==0);
}
