Logo

Programming-Idioms

  • Ruby
  • C++
  • Haskell
  • C#
  • Js

Idiom #208 Formula with arrays

Given the arrays a,b,c,d of equal length and the scalar e, calculate a = e*(a+b*c+cos(d)).
Store the results in a.

a.forEach((aa, i) => a[i] = e * (aa + b[i] * c[i] + Math.cos(d[i])))
a = a.zip(b,c,d).map{|i,j,k,l| e*(i+j*k+Math::cos(l)) }
for (int i = 0; i < a.Length; i++)
  a[i] = e * (a[i] + b[i] * c[i] + Math.Cos(d[i]));
#include <math.h>
  for (int i=0; i<n; i++)
    a[i] = e*(a[i]+b[i]*c[i]+cos(d[i]));

Assume n is the length.

New implementation...
< >
tkoenig