Averages/Mean angle: Difference between revisions
Add Factor example
Thundergnat (talk | contribs) m (→{{header|Ring}}: Remove vanity tags) |
(Add Factor example) |
||
Line 510:
>RosettaCode 90 180 270 360
Mean angle for [90; 180; 270; 360]: -90°
</pre>
=={{header|Factor}}==
<lang factor>USING: formatting kernel math math.functions math.libm math.trig
sequences ;
: mean-angle ( seq -- x )
[ deg>rad ] map [ [ sin ] map-sum ] [ [ cos ] map-sum ]
[ length ] tri recip [ * ] curry bi@ fatan2 rad>deg ;
: show ( seq -- )
dup mean-angle "The mean angle of %u is: %f°\n" printf ;
{ { 350 10 } { 90 180 270 360 } { 10 20 30 } } [ show ] each</lang>
{{out}}
<pre>
The mean angle of { 350 10 } is: -0.000000°
The mean angle of { 90 180 270 360 } is: -90.000000°
The mean angle of { 10 20 30 } is: 20.000000°
</pre>
|