Averages/Mean time of day: Difference between revisions

(Added Haskell version)
Line 925:
{{out}}
<pre>23:47:43 is the mean time of 23:00:17 23:40:20 00:12:45 00:17:19</pre>
 
=={{header|Phix}}==
<lang Phix>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 atan2(y,x)*180/PI
end function
function toSecAngle(integer hours, integer minutes, integer seconds)
return ((hours*60+minutes)*60+seconds)/(24*60*60)*360
end function
 
constant Times = {toSecAngle(23,00,17),
toSecAngle(23,40,20),
toSecAngle(00,12,45),
toSecAngle(00,17,19)}
 
function toHMS(object s)
if not string(s) then
if s<0 then s+=360 end if
s = 24*60*60*s/360
s = sprintf("%02d:%02d:%02d",{floor(s/3600),floor(remainder(s,3600)/60),remainder(s,60)})
end if
return s
end function
 
printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))})
{} = wait_key()</lang>
{{out}}
Mean Time is 23:47:43
 
=={{header|PicoLisp}}==
7,820

edits