On Thu, 25 Dec 2008 21:50:29 +0000, Jon Harrop <j...@ffconsultancy.com> wrote:
>Xah Lee wrote: >>> >On Dec 10, 2:47 pm, John W Kennedy <jwke...@attglobal.net> wrote: >>> >> C: >>> >>> >> #include <stdlib.h> >>> >> #include <math.h> >>> >>> >> void normal(int dim, float* x, float* a) { >>> >> float sum = 0.0f; >>> >> int i; >>> >> float divisor; >>> >> for (i = 0; i < dim; ++i) sum += x[i] * x[i]; >>> >> divisor = sqrt(sum); >>> >> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor; >>> >>> >> } >> >> Due to the low level of C, this C example should perhaps then accept a >> sequence of numbers separated by space... > >In other words, you want a REPL. > >Why don't we have another challenge that involves handling a non-trivial >input format, i.e. parsing? Maybe you could speed it up. sln ---------------------------------- void normal (int Dimension, double *X, double *A) { double *xp, *ap, divisor, sum; int i; for ( i=0, sum=0., xp=X; i<Dimension; i++, xp++) sum += (*xp) ** 2; divisor = sqrt ( sum ); for ( i=0, ap=A, xp=X; i<Dimension; i++, ap++, xp++) *ap = *xp / divisor; // if Dimension is greater than // sizeof double X[] or double A[] it will GPF. // this is a really, really bad design. } -- http://mail.python.org/mailman/listinfo/python-list