Function to print a diamond shape

Jay Norwood jayn at prismnet.com
Tue Mar 25 22:28:15 PDT 2014


This corrects the parallel example range in the second foreach.  
Still slow.

void printDiamonde2cpa(in uint N)
{
     size_t N2 = N/2;
     char p[] = uninitializedArray!(char[])(N2+N);
     p[0..N2] = ' ';
     p[N2..$] = '*';
     char nl[] = uninitializedArray!(char[])(1);
     nl[] = '\n';

     char[][] wc = minimallyInitializedArray!(char[][])(N);

     auto w = appender!(char[])();

     foreach(n, ref elem; taskPool.parallel(wc[0..N2+1],100)){
         elem = p[n .. N2+2*n+1];
     }

     foreach (rn, ref elem ; taskPool.parallel(wc[N2+1..N],100)){
         int n = N2 - rn - 1;
         elem = p[n .. N2+2*n+1];
     }
     auto wj = join(wc,nl);
     w.put(wj);

     writeln(w.data);
}


More information about the Digitalmars-d-learn mailing list