Logo

Programming-Idioms

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.
Implementation
Python

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Python implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
a = e*(a+b*c+cos(d))
#include <math.h>
  for (i=0; i<n; i++)
    a[i] = e*(a[i]+b[i]*c[i]+cos(d[i]);
$a[$_] = $e * ($a[$_] + $b[$_] * $c[$_] + cos $d[$_]) for 0 .. $#a;
for i := 0 to High(a) do
    a[i] = e*(a[i]+b[i]*c[i]+cos(d[i]);
a = a.zip(b,c,d).map{|i,j,k,l| e*(i+j*k+Math::cos(l)) }
for i in 0..a.len() {
    a[i] = e * (a[i] + b[i] * c[i] + d[i].cos());
}
import "math"
func applyFormula(a, b, c, d []float64, e float64) {
	for i, v := range a {
		a[i] = e * (v + b[i] + c[i] + math.Cos(d[i]))
	}
}
import math
a = [e*(a[i] + b[i] + c[i] + math.cos(d[i])) for i in range(len(a))]
a.forEach((aa, i) => a[i] = e * (aa + b[i] * c[i] + Math.cos(d[i])))