Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Averages-Mean-angle/D/averages-mean-angle.d
Normal file
16
Task/Averages-Mean-angle/D/averages-mean-angle.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.stdio, std.algorithm, std.complex;
|
||||
import std.math: PI;
|
||||
|
||||
auto radians(T)(in T d) pure nothrow @nogc { return d * PI / 180; }
|
||||
auto degrees(T)(in T r) pure nothrow @nogc { return r * 180 / PI; }
|
||||
|
||||
real meanAngle(T)(in T[] D) pure nothrow @nogc {
|
||||
immutable t = reduce!((a, d) => a + d.radians.expi)(0.complex, D);
|
||||
return (t / D.length).arg.degrees;
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (angles; [[350, 10], [90, 180, 270, 360], [10, 20, 30]])
|
||||
writefln("The mean angle of %s is: %.2f degrees",
|
||||
angles, angles.meanAngle);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue