// Display the unique magic 'hexagrams' 
//            /\
//        ___/k_\____
//       \a /\c /\e /
//        \/b_\/d_\/
//        /\ j/\ f/\ 
//       /i_\/g_\/l_\
//           \ h/
//            \/
//
//
// 'Magic' means all the rows, etc add to the same number.
//
// 27March04

char used[13]; 
int a,b,c,d,e,f,g,h,i,j,k,l;
int rowsum;

void printit() // write to console
{
   printf(  "\n"
    "        %3i\n"
	"  %3i   %3i   %3i\n"
	"     %3i   %3i    \n"
	"     %3i   %3i    \n"
	"  %3i   %3i   %3i\n"
	"        %3i\n",

               k,
           a,  c,  e,
             b,  d,
             j,  f,
           i,  g,  l, 
               h);
}


int main()
{

for (a=1; a<=7; a++) {	// always the lowest value corner; 5 more similar corners
 used[a]++;				// show this number as used
 for (b=1; b<=12; b++)
  if (!used[b]) {		// 'for' loop consists of this single 'if' statement; no {} needed
   used[b]++;
   for (c=1; c<=12; c++)
    if (!used[c]) {
     used[c]++;
     for (d=1; d<=12; d++)
      if (!used[d]) {
       used[d]++;
       for (e=a+1; e<=12; e++)	// a is the lowest corner
        if (!used[e]) {
         used[e]++;
         rowsum = a+b+c+d+e;
         for (k=a+1; k<=12; k++)
          if (!used[k]) {
           used[k]++;
           for (f=1; f<=12; f++)
            if (!used[f]) {
             used[f]++;
             l = rowsum-k-f-d-c;
             if (l>a && l<=12 && !used[l]) {
              used[l]++;
              g = b+c+k -f-l;  // 2 rows with i+j in common
              if (g>0 && g<=12 && !used[g]) {
               used[g]++;
               h = rowsum-g-f-d-e;
               if (h>a && h<=12 && !used[h]) {
                used[h]++;
                j = rowsum-a-b-g-h;
                if (j>0 && j<=12 && !used[j]) {
                 used[j]++;
                 i = rowsum-j-g-f-l;
                 if (i>k && i<=12 && !used[i]) // i>k>a - avoid reflections and rotations
                   printit();
                 used[j]--;
                } 
                used[h]--;
               } 
             used[g]--;
            } 
            used[l]--;
           } 
          used[f]--;
         } 	
         used[k]--;
        }
        used[e]--;
       } 
       used[d]--;
      } 
     used[c]--;
    } 
   used[b]--;
  } 
 used[a]--;
} 		//for a

printf("\n");

}

