Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
24
Task/Averages-Mean-angle/Phix/averages-mean-angle.phix
Normal file
24
Task/Averages-Mean-angle/Phix/averages-mean-angle.phix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
function atan2(atom y, atom x)
|
||||
return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y)
|
||||
end function
|
||||
|
||||
function MeanAngle(sequence angles)
|
||||
atom x=0, y=0, ai_rad
|
||||
integer l=length(angles)
|
||||
|
||||
for i=1 to l do
|
||||
ai_rad = angles[i]*PI/180
|
||||
x += cos(ai_rad)
|
||||
y += sin(ai_rad)
|
||||
end for
|
||||
if abs(x)<1e-16 then return "not meaningful" end if
|
||||
return sprintf("%9.5f",atan2(y,x)*180/PI)
|
||||
end function
|
||||
|
||||
constant AngleLists = {{350,10},{90,180,270,360},{10,20,30},{180},{0,180}}
|
||||
sequence ai
|
||||
for i=1 to length(AngleLists) do
|
||||
ai = AngleLists[i]
|
||||
printf(1,"%+16s: Mean Angle is %s\n",{sprint(ai),MeanAngle(ai)})
|
||||
end for
|
||||
{} = wait_key()
|
||||
Loading…
Add table
Add a link
Reference in a new issue