Averages/Mean time of day: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl}}: added v5.36 version)
m (syntax highlighting fixup automation)
Line 21: Line 21:
=={{header|11l}}==
=={{header|11l}}==
{{trans|Python}}
{{trans|Python}}
<lang 11l>F mean_angle(angles)
<syntaxhighlight lang=11l>F mean_angle(angles)
V x = sum(angles.map(a -> cos(radians(a)))) / angles.len
V x = sum(angles.map(a -> cos(radians(a)))) / angles.len
V y = sum(angles.map(a -> sin(radians(a)))) / angles.len
V y = sum(angles.map(a -> sin(radians(a)))) / angles.len
Line 41: Line 41:
R ‘#02:#02:#02’.format(h, m, s)
R ‘#02:#02:#02’.format(h, m, s)


print(mean_time([‘23:00:17’, ‘23:40:20’, ‘00:12:45’, ‘00:17:19’]))</lang>
print(mean_time([‘23:00:17’, ‘23:40:20’, ‘00:12:45’, ‘00:17:19’]))</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 49: Line 49:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
{{libheader|Action! Real Math}}
<lang Action!>INCLUDE "H6:REALMATH.ACT"
<syntaxhighlight lang=Action!>INCLUDE "H6:REALMATH.ACT"


DEFINE PTR="CARD"
DEFINE PTR="CARD"
Line 138: Line 138:
AverageTime(times,COUNT,t)
AverageTime(times,COUNT,t)
Print("Mean time is ") PrintTime(t)
Print("Mean time is ") PrintTime(t)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Mean_time_of_day.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Mean_time_of_day.png Screenshot from Atari 8-bit computer]
Line 146: Line 146:


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Calendar.Formatting;
<syntaxhighlight lang=Ada>with Ada.Calendar.Formatting;
with Ada.Command_Line;
with Ada.Command_Line;
with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Elementary_Functions;
Line 224: Line 224:
Ada.Text_IO.Put_Line ("Usage: mean_time_of_day <time-1> ...");
Ada.Text_IO.Put_Line ("Usage: mean_time_of_day <time-1> ...");
Ada.Text_IO.Put_Line (" <time-1> ... 'HH:MM:SS' format");
Ada.Text_IO.Put_Line (" <time-1> ... 'HH:MM:SS' format");
end Mean_Time_Of_Day;</lang>
end Mean_Time_Of_Day;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 233: Line 233:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
{{works with|AutoHotkey 1.1}}
<lang AutoHotkey>MsgBox, % "The mean time is: " MeanTime(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])
<syntaxhighlight lang=AutoHotkey>MsgBox, % "The mean time is: " MeanTime(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])


MeanTime(t, x=0, y=0) {
MeanTime(t, x=0, y=0) {
Line 253: Line 253:
atan2(x, y) {
atan2(x, y) {
return dllcall("msvcrt\atan2", "Double",y, "Double",x, "CDECL Double")
return dllcall("msvcrt\atan2", "Double",y, "Double",x, "CDECL Double")
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The mean time is: 23:47:43</pre>
<pre>The mean time is: 23:47:43</pre>


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>#!/usr/bin/awk -f
<syntaxhighlight lang=AWK>#!/usr/bin/awk -f
{
{
c = atan2(0,-1)/(12*60*60);
c = atan2(0,-1)/(12*60*60);
Line 271: Line 271:
if (p<0) p += 24*60*60;
if (p<0) p += 24*60*60;
print strftime("%T",p,1);
print strftime("%T",p,1);
}</lang>
}</syntaxhighlight>
<pre>$ echo 23:00:17, 23:40:20, 00:12:45, 00:17:19 | awk -f mean_time_of_day.awk
<pre>$ echo 23:00:17, 23:40:20, 00:12:45, 00:17:19 | awk -f mean_time_of_day.awk
23:47:43</pre>
23:47:43</pre>
Line 277: Line 277:
=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> nTimes% = 4
<syntaxhighlight lang=bbcbasic> nTimes% = 4
DATA 23:00:17, 23:40:20, 00:12:45, 00:17:19
DATA 23:00:17, 23:40:20, 00:12:45, 00:17:19
Line 315: Line 315:
DEF FNatan2(y,x) : ON ERROR LOCAL = SGN(y)*PI/2
DEF FNatan2(y,x) : ON ERROR LOCAL = SGN(y)*PI/2
IF x>0 THEN = ATN(y/x) ELSE IF y>0 THEN = ATN(y/x)+PI ELSE = ATN(y/x)-PI</lang>
IF x>0 THEN = ATN(y/x) ELSE IF y>0 THEN = ATN(y/x)+PI ELSE = ATN(y/x)-PI</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 322: Line 322:


=={{header|C}}==
=={{header|C}}==
<lang C>#include<stdlib.h>
<syntaxhighlight lang=C>#include<stdlib.h>
#include<math.h>
#include<math.h>
#include<stdio.h>
#include<stdio.h>
Line 390: Line 390:
meanTime.second);
meanTime.second);
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 403: Line 403:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang=csharp>using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
Line 458: Line 458:
}
}
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 471: Line 471:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iomanip>
<syntaxhighlight lang=cpp>#include <iomanip>
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
Line 536: Line 536:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 542: Line 542:
=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
{{trans|Echo Lisp}}
{{trans|Echo Lisp}}
<lang lisp>;; * Loading the split-sequence library
<syntaxhighlight lang=lisp>;; * Loading the split-sequence library
(eval-when (:compile-toplevel :load-toplevel :execute)
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload '("split-sequence")))
(ql:quickload '("split-sequence")))
Line 582: Line 582:
(reduce #'+ (mapcar (lambda (time)
(reduce #'+ (mapcar (lambda (time)
(make-polar 1 (time->radian time))) times)))))
(make-polar 1 (time->radian time))) times)))))
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 590: Line 590:
=={{header|D}}==
=={{header|D}}==
{{trans|Python}}
{{trans|Python}}
<lang d>import std.stdio, std.range, std.algorithm, std.complex, std.math,
<syntaxhighlight lang=d>import std.stdio, std.range, std.algorithm, std.complex, std.math,
std.format, std.conv;
std.format, std.conv;


Line 628: Line 628:
void main() @safe {
void main() @safe {
["23:00:17", "23:40:20", "00:12:45", "00:17:19"].meanTime.writeln;
["23:00:17", "23:40:20", "00:12:45", "00:17:19"].meanTime.writeln;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 635: Line 635:
{{libheader| System.Math}}
{{libheader| System.Math}}
{{Trans|Go}}
{{Trans|Go}}
<lang Delphi>
<syntaxhighlight lang=Delphi>
program Averages_Mean_time_of_day;
program Averages_Mean_time_of_day;


Line 691: Line 691:
writeln(TimeToStr(MeanTime(ToTimes(Inputs))));
writeln(TimeToStr(MeanTime(ToTimes(Inputs))));
readln;
readln;
end.</lang>
end.</syntaxhighlight>
=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang=scheme>
;; string hh:mm:ss to radians
;; string hh:mm:ss to radians
(define (time->radian time)
(define (time->radian time)
Line 715: Line 715:
(mean-time '{"23:00:17" "23:40:20" "00:12:45" "00:17:19"})
(mean-time '{"23:00:17" "23:40:20" "00:12:45" "00:17:19"})
→ "23:47:43"
→ "23:47:43"
</syntaxhighlight>
</lang>




=={{header|Erlang}}==
=={{header|Erlang}}==
<lang Erlang>
<syntaxhighlight lang=Erlang>
-module( mean_time_of_day ).
-module( mean_time_of_day ).
-export( [from_times/1, task/0] ).
-export( [from_times/1, task/0] ).
Line 750: Line 750:
Secs = Seconds - (Hours * 3600) - (Minutes * 60),
Secs = Seconds - (Hours * 3600) - (Minutes * 60),
lists:flatten( io_lib:format("~2.10.0B:~2.10.0B:~2.10.0B", [Hours, Minutes, Secs]) ).
lists:flatten( io_lib:format("~2.10.0B:~2.10.0B:~2.10.0B", [Hours, Minutes, Secs]) ).
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 759: Line 759:
=={{header|Euphoria}}==
=={{header|Euphoria}}==
{{works with|OpenEuphoria}}
{{works with|OpenEuphoria}}
<lang Euphoria>
<syntaxhighlight lang=Euphoria>
include std/console.e
include std/console.e
include std/math.e
include std/math.e
Line 823: Line 823:
if getc(0) then end if
if getc(0) then end if
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 836: Line 836:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>open System
<syntaxhighlight lang=fsharp>open System
open System.Numerics
open System.Numerics


Line 856: Line 856:
|> deg2time |> fun t -> t.ToString(@"hh\:mm\:ss")
|> deg2time |> fun t -> t.ToString(@"hh\:mm\:ss")
|> printfn "%s: %s" msg
|> printfn "%s: %s" msg
0</lang>
0</syntaxhighlight>
{{out}}
{{out}}
<pre>>RosettaCode 23:00:17 23:40:20 00:12:45 00:17:19
<pre>>RosettaCode 23:00:17 23:40:20 00:12:45 00:17:19
Line 862: Line 862:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: arrays formatting kernel math math.combinators
<syntaxhighlight lang=factor>USING: arrays formatting kernel math math.combinators
math.functions math.libm math.parser math.trig qw sequences
math.functions math.libm math.parser math.trig qw sequences
splitting ;
splitting ;
Line 887: Line 887:
input dup mean-time "Mean time for %u is %s.\n" printf ;
input dup mean-time "Mean time for %u is %s.\n" printf ;


MAIN: mean-time-demo</lang>
MAIN: mean-time-demo</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 895: Line 895:
=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|gfortran 5.1.0}}
{{works with|gfortran 5.1.0}}
<lang fortran>
<syntaxhighlight lang=fortran>
program mean_time_of_day
program mean_time_of_day
implicit none
implicit none
Line 966: Line 966:
end function
end function
end program
end program
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 973: Line 973:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang=freebasic>' FB 1.05.0 Win64


Const pi As Double = 3.1415926535897932
Const pi As Double = 3.1415926535897932
Line 1,026: Line 1,026:
Print
Print
Print "Press any key to quit"
Print "Press any key to quit"
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 1,034: Line 1,034:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 1,083: Line 1,083:
_, dayFrac := math.Modf(1 + math.Atan2(ssum, csum)/(2*math.Pi))
_, dayFrac := math.Modf(1 + math.Atan2(ssum, csum)/(2*math.Pi))
return mean.Add(time.Duration(dayFrac * 24 * float64(time.Hour))), nil
return mean.Add(time.Duration(dayFrac * 24 * float64(time.Hour))), nil
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,091: Line 1,091:
=={{header|Groovy}}==
=={{header|Groovy}}==
Solution:
Solution:
<lang groovy>import static java.lang.Math.*
<syntaxhighlight lang=groovy>import static java.lang.Math.*


final format = 'HH:mm:ss', clock = PI / 12, millisPerHr = 3600*1000
final format = 'HH:mm:ss', clock = PI / 12, millisPerHr = 3600*1000
Line 1,101: Line 1,101:
def times = timeStrings.collect(parseTime)
def times = timeStrings.collect(parseTime)
formatTime(atan2( mean(times) { sin(it * clock) }, mean(times) { cos(it * clock) }) / clock)
formatTime(atan2( mean(times) { sin(it * clock) }, mean(times) { cos(it * clock) }) / clock)
}</lang>
}</syntaxhighlight>


Test:
Test:
<lang groovy>println (meanTime("23:00:17", "23:40:20", "00:12:45", "00:17:19"))</lang>
<syntaxhighlight lang=groovy>println (meanTime("23:00:17", "23:40:20", "00:12:45", "00:17:19"))</syntaxhighlight>


{{out}}
{{out}}
Line 1,110: Line 1,110:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Complex (cis, phase)
<syntaxhighlight lang=haskell>import Data.Complex (cis, phase)
import Data.List.Split (splitOn)
import Data.List.Split (splitOn)
import Text.Printf (printf)
import Text.Printf (printf)
Line 1,137: Line 1,137:
main :: IO ()
main :: IO ()
main = putStrLn $ radiansToTime $ meanAngle $ map timeToRadians ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
main = putStrLn $ radiansToTime $ meanAngle $ map timeToRadians ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 1,166: Line 1,166:
every (sumCosines := 0.0) +:= cos(dtor(!A))
every (sumCosines := 0.0) +:= cos(dtor(!A))
return rtod(atan(sumSines/*A,sumCosines/*A))
return rtod(atan(sumSines/*A,sumCosines/*A))
end</lang>
end</syntaxhighlight>


Sample run:
Sample run:
Line 1,178: Line 1,178:
=={{header|J}}==
=={{header|J}}==
use <code>avgAngleR</code> from [[Averages/Mean angle#J]]
use <code>avgAngleR</code> from [[Averages/Mean angle#J]]
<lang J>require 'types/datetime'
<syntaxhighlight lang=J>require 'types/datetime'
parseTimes=: ([: _&".;._2 ,&':');._2
parseTimes=: ([: _&".;._2 ,&':');._2
secsFromTime=: 24 60 60 #. ] NB. convert from time to seconds
secsFromTime=: 24 60 60 #. ] NB. convert from time to seconds
rft=: 2r86400p1 * secsFromTime NB. convert from time to radians
rft=: 2r86400p1 * secsFromTime NB. convert from time to radians
meanTime=: 'hh:mm:ss' fmtTime [: secsFromTime [: avgAngleR&.rft parseTimes</lang>
meanTime=: 'hh:mm:ss' fmtTime [: secsFromTime [: avgAngleR&.rft parseTimes</syntaxhighlight>
{{out|Example Use}}
{{out|Example Use}}
<lang J> meanTime '23:00:17 23:40:20 00:12:45 00:17:19 '
<syntaxhighlight lang=J> meanTime '23:00:17 23:40:20 00:12:45 00:17:19 '
23:47:43</lang>
23:47:43</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang java>public class MeanTimeOfDay {
<syntaxhighlight lang=java>public class MeanTimeOfDay {
static double meanAngle(double[] angles) {
static double meanAngle(double[] angles) {
Line 1,236: Line 1,236:
System.out.println("Average time is : " + degreesToTime(mean));
System.out.println("Average time is : " + degreesToTime(mean));
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,245: Line 1,245:
=={{header|Javascript}}==
=={{header|Javascript}}==
{{works with|Node.js}}
{{works with|Node.js}}
<lang Javascript>var args = process.argv.slice(2);
<syntaxhighlight lang=Javascript>var args = process.argv.slice(2);


function time_to_seconds( hms ) {
function time_to_seconds( hms ) {
Line 1,285: Line 1,285:
var seconds = Math.floor( sum / count )
var seconds = Math.floor( sum / count )
console.log( 'Mean time is ', seconds_to_time(seconds));
console.log( 'Mean time is ', seconds_to_time(seconds));
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,295: Line 1,295:


The "mean time" of two times that differ by 12 hours (e.g. ["00:00:00", "12:00:00"]) is not very well-defined, and is accordingly computed as null here.
The "mean time" of two times that differ by 12 hours (e.g. ["00:00:00", "12:00:00"]) is not very well-defined, and is accordingly computed as null here.
<lang jq># input: array of "h:m:s"
<syntaxhighlight lang=jq># input: array of "h:m:s"
def mean_time_of_day:
def mean_time_of_day:
def pi: 4 * (1|atan);
def pi: 4 * (1|atan);
Line 1,325: Line 1,325:
| round
| round
| secs2time
| secs2time
end ;</lang>
end ;</syntaxhighlight>
'''Examples'''
'''Examples'''
<lang jq>["0:0:0", "12:0:0" ],
<syntaxhighlight lang=jq>["0:0:0", "12:0:0" ],
["0:0:0", "24:0:0" ],
["0:0:0", "24:0:0" ],
["1:0:0", "1:0:0" ],
["1:0:0", "1:0:0" ],
Line 1,334: Line 1,334:
["23:0:0", "23:0:0" ],
["23:0:0", "23:0:0" ],
["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
| mean_time_of_day</lang>
| mean_time_of_day</syntaxhighlight>
{{out}}
{{out}}
<lang sh>$ jq -r -n -f Mean_time_of_day.jq
<syntaxhighlight lang=sh>$ jq -r -n -f Mean_time_of_day.jq
null
null
00:00:00
00:00:00
Line 1,343: Line 1,343:
00:00:01
00:00:01
23:00:00
23:00:00
23:47:43</lang>
23:47:43</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}
{{trans|MATLAB}}
{{trans|MATLAB}}
<lang julia>using Statistics
<syntaxhighlight lang=julia>using Statistics


function meantime(times::Array, dlm::String=":")
function meantime(times::Array, dlm::String=":")
Line 1,367: Line 1,367:
println("Times:")
println("Times:")
println.(times)
println.(times)
println("Mean: $mtime")</lang>
println("Mean: $mtime")</syntaxhighlight>


{{out}}
{{out}}
Line 1,379: Line 1,379:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<lang scala>// version 1.0.6
<syntaxhighlight lang=scala>// version 1.0.6


fun meanAngle(angles: DoubleArray): Double {
fun meanAngle(angles: DoubleArray): Double {
Line 1,414: Line 1,414:
val mean = meanAngle(angles)
val mean = meanAngle(angles)
println("Average time is : ${degreesToTime(mean)}")
println("Average time is : ${degreesToTime(mean)}")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,422: Line 1,422:


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<syntaxhighlight lang=lb>
<lang lb>
global pi
global pi
pi = acs(-1)
pi = acs(-1)
Line 1,468: Line 1,468:
atan2 = (y=0)*(x<0)*pi
atan2 = (y=0)*(x<0)*pi
End Function
End Function
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,481: Line 1,481:


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>
<syntaxhighlight lang=lua>
local times = {"23:00:17","23:40:20","00:12:45","00:17:19"}
local times = {"23:00:17","23:40:20","00:12:45","00:17:19"}


Line 1,516: Line 1,516:


print(angleToTime(meanAngle(times)))
print(angleToTime(meanAngle(times)))
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,524: Line 1,524:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang mathematica>meanTime[list_] :=
<syntaxhighlight lang=mathematica>meanTime[list_] :=
StringJoin@
StringJoin@
Riffle[ToString /@
Riffle[ToString /@
Line 1,531: Line 1,531:
Exp[FromDigits[ToExpression@StringSplit[#, ":"], 60] & /@
Exp[FromDigits[ToExpression@StringSplit[#, ":"], 60] & /@
list/(24*60*60) 2 Pi I]]]/(2 Pi)], ":"];
list/(24*60*60) 2 Pi I]]]/(2 Pi)], ":"];
meanTime[{"23:00:17", "23:40:20", "00:12:45", "00:17:19"}]</lang>
meanTime[{"23:00:17", "23:40:20", "00:12:45", "00:17:19"}]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
<lang MATLAB>function t = mean_time_of_day(t)
<syntaxhighlight lang=MATLAB>function t = mean_time_of_day(t)
c = pi/(12*60*60);
c = pi/(12*60*60);
for k=1:length(t)
for k=1:length(t)
Line 1,545: Line 1,545:
if (d<0) d += 1;
if (d<0) d += 1;
t = datestr(d,"HH:MM:SS");
t = datestr(d,"HH:MM:SS");
end; </lang>
end; </syntaxhighlight>
<pre>mean_time_of_day({'23:00:17', '23:40:20', '00:12:45', '00:17:19'})
<pre>mean_time_of_day({'23:00:17', '23:40:20', '00:12:45', '00:17:19'})
ans = 23:47:43
ans = 23:47:43
Line 1,552: Line 1,552:
=={{header|Nim}}==
=={{header|Nim}}==
{{works with|Nim|0.20.0+}}
{{works with|Nim|0.20.0+}}
<lang nim>import math, complex, strutils, sequtils
<syntaxhighlight lang=nim>import math, complex, strutils, sequtils
proc meanAngle(deg: openArray[float]): float =
proc meanAngle(deg: openArray[float]): float =
Line 1,571: Line 1,571:
align($h, 2, '0') & ":" & align($m, 2, '0') & ":" & align($s, 2, '0')
align($h, 2, '0') & ":" & align($m, 2, '0') & ":" & align($s, 2, '0')
echo meanTime(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])</lang>
echo meanTime(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 1,577: Line 1,577:
=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
{{works with|oo2c}}
{{works with|oo2c}}
<lang oberon2>
<syntaxhighlight lang=oberon2>
MODULE AvgTimeOfDay;
MODULE AvgTimeOfDay;
IMPORT
IMPORT
Line 1,648: Line 1,648:


END AvgTimeOfDay.
END AvgTimeOfDay.
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,655: Line 1,655:


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>let pi_twice = 2.0 *. 3.14159_26535_89793_23846_2643
<syntaxhighlight lang=ocaml>let pi_twice = 2.0 *. 3.14159_26535_89793_23846_2643
let day = float (24 * 60 * 60)
let day = float (24 * 60 * 60)


Line 1,691: Line 1,691:
Printf.printf "The mean time of [%s] is: %s\n"
Printf.printf "The mean time of [%s] is: %s\n"
(String.concat "; " times)
(String.concat "; " times)
(string_of_time (mean_time (List.map parse_time times)))</lang>
(string_of_time (mean_time (List.map parse_time times)))</syntaxhighlight>
{{out}}
{{out}}
The mean time of [23:00:17; 23:40:20; 00:12:45; 00:17:19] is: 23:47:43
The mean time of [23:00:17; 23:40:20; 00:12:45; 00:17:19] is: 23:47:43


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<lang oorexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang=oorexx>/* REXX ---------------------------------------------------------------
* 25.06.2014 Walter Pachl
* 25.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
*--------------------------------------------------------------------*/
Line 1,731: Line 1,731:
f2: return right(format(arg(1),2,0),2,0)
f2: return right(format(arg(1),2,0),2,0)


::requires rxmath library</lang>
::requires rxmath library</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>meanAngle(v)=atan(sum(i=1,#v,sin(v[i]))/sum(i=1,#v,cos(v[i])))%(2*Pi)
<syntaxhighlight lang=parigp>meanAngle(v)=atan(sum(i=1,#v,sin(v[i]))/sum(i=1,#v,cos(v[i])))%(2*Pi)
meanTime(v)=my(x=meanAngle(2*Pi*apply(u->u[1]/24+u[2]/1440+u[3]/86400, v))*12/Pi); [x\1, 60*(x-=x\1)\1, round(60*(60*x-60*x\1))]
meanTime(v)=my(x=meanAngle(2*Pi*apply(u->u[1]/24+u[2]/1440+u[3]/86400, v))*12/Pi); [x\1, 60*(x-=x\1)\1, round(60*(60*x-60*x\1))]
meanTime([[23,0,17], [23,40,20], [0,12,45], [0,17,19]])</lang>
meanTime([[23,0,17], [23,40,20], [0,12,45], [0,17,19]])</syntaxhighlight>
{{out}}
{{out}}
<pre>[23, 47, 43]</pre>
<pre>[23, 47, 43]</pre>
Line 1,746: Line 1,746:
Using the core module <code>Math::Complex</code> to enable use of complex numbers. The <code>POSIX</code> CPAN module provides the <code>fmod</code> routine for non-integer modulus calculations.
Using the core module <code>Math::Complex</code> to enable use of complex numbers. The <code>POSIX</code> CPAN module provides the <code>fmod</code> routine for non-integer modulus calculations.
{{trans|Raku}}
{{trans|Raku}}
<lang Perl>use strict;
<syntaxhighlight lang=Perl>use strict;
use warnings;
use warnings;
use POSIX 'fmod';
use POSIX 'fmod';
Line 1,779: Line 1,779:


@times = ("23:00:17", "23:40:20", "00:12:45", "00:17:19");
@times = ("23:00:17", "23:40:20", "00:12:45", "00:17:19");
print mean_time(@times) . " is the mean time of " . join(' ', @times) . "\n";</lang>
print mean_time(@times) . " is the mean time of " . join(' ', @times) . "\n";</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43 is the mean time of 23:00:17 23:40:20 00:12:45 00:17:19</pre>
<pre>23:47:43 is the mean time of 23:00:17 23:40:20 00:12:45 00:17:19</pre>
===v5.36===
===v5.36===
As previous, but using features from an up-to-date release of Perl, e.g. strict/warn/subroutine signatures without the <code>use</code> boilerplate.
As previous, but using features from an up-to-date release of Perl, e.g. strict/warn/subroutine signatures without the <code>use</code> boilerplate.
<lang perl>use v5.36;
<syntaxhighlight lang=perl>use v5.36;
use POSIX 'fmod';
use POSIX 'fmod';
use Math::Complex;
use Math::Complex;
Line 1,800: Line 1,800:


my @times = <23:00:17 23:40:20 00:12:45 00:17:19>;
my @times = <23:00:17 23:40:20 00:12:45 00:17:19>;
say my $result = mean_time(@times) . ' is the mean time of ' . join ' ', @times;</lang>
say my $result = mean_time(@times) . ' is the mean time of ' . join ' ', @times;</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43 is the mean time of 23:00:17 23:40:20 00:12:45 00:17:19</pre>
<pre>23:47:43 is the mean time of 23:00:17 23:40:20 00:12:45 00:17:19</pre>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">MeanAngle</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">angles</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">MeanAngle</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">angles</span><span style="color: #0000FF;">)</span>
Line 1,840: Line 1,840:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Mean Time is %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">toHMS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MeanAngle</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Times</span><span style="color: #0000FF;">))})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Mean Time is %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">toHMS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MeanAngle</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Times</span><span style="color: #0000FF;">))})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,847: Line 1,847:


=={{header|PHP}}==
=={{header|PHP}}==
<lang PHP>
<syntaxhighlight lang=PHP>
<?php
<?php
function time2ang($tim) {
function time2ang($tim) {
Line 1,885: Line 1,885:
print "The mean time of day is $result (angle $ma).\n";
print "The mean time of day is $result (angle $ma).\n";
?>
?>
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,893: Line 1,893:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(load "@lib/math.l")
<syntaxhighlight lang=PicoLisp>(load "@lib/math.l")


(de meanTime (Lst)
(de meanTime (Lst)
Line 1,902: Line 1,902:
(sum '((S) (cos (*/ ($tim S) pi 43200))) Lst) )
(sum '((S) (cos (*/ ($tim S) pi 43200))) Lst) )
43200 pi )
43200 pi )
(tim$ (% (+ Tim 86400) 86400) T) ) )</lang>
(tim$ (% (+ Tim 86400) 86400) T) ) )</syntaxhighlight>
{{out|Test}}
{{out|Test}}
<lang PicoLisp>: (meanTime '("23:00:17" "23:40:20" "00:12:45" "00:17:19"))
<syntaxhighlight lang=PicoLisp>: (meanTime '("23:00:17" "23:40:20" "00:12:45" "00:17:19"))
-> "23:47:43"</lang>
-> "23:47:43"</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>*process source attributes xref;
<syntaxhighlight lang=pli>*process source attributes xref;
avt: Proc options(main);
avt: Proc options(main);
/*--------------------------------------------------------------------
/*--------------------------------------------------------------------
Line 1,953: Line 1,953:
End;
End;


End;</lang>
End;</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang PowerShell>
<syntaxhighlight lang=PowerShell>
function Get-MeanTimeOfDay
function Get-MeanTimeOfDay
{
{
Line 2,025: Line 2,025:
}
}
}
}
</syntaxhighlight>
</lang>
<lang PowerShell>
<syntaxhighlight lang=PowerShell>
[timespan]$meanTimeOfDay = "23:00:17","23:40:20","00:12:45","00:17:19" | Get-MeanTimeOfDay
[timespan]$meanTimeOfDay = "23:00:17","23:40:20","00:12:45","00:17:19" | Get-MeanTimeOfDay
"Mean time is {0}" -f (Get-Date $meanTimeOfDay.ToString()).ToString("hh:mm:ss tt")
"Mean time is {0}" -f (Get-Date $meanTimeOfDay.ToString()).ToString("hh:mm:ss tt")
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,036: Line 2,036:


=={{header|Python}}==
=={{header|Python}}==
<lang python>from cmath import rect, phase
<syntaxhighlight lang=python>from cmath import rect, phase
from math import radians, degrees
from math import radians, degrees


Line 2,059: Line 2,059:


if __name__ == '__main__':
if __name__ == '__main__':
print( mean_time(["23:00:17", "23:40:20", "00:12:45", "00:17:19"]) )</lang>
print( mean_time(["23:00:17", "23:40:20", "00:12:45", "00:17:19"]) )</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang=racket>
#lang racket
#lang racket
(define (mean-angle/radians as)
(define (mean-angle/radians as)
Line 2,085: Line 2,085:
(loop q (cons (~r r #:min-width 2 #:pad-string "0") ts))))))
(loop q (cons (~r r #:min-width 2 #:pad-string "0") ts))))))
(mean-time '("23:00:17" "23:40:20" "00:12:45" "00:17:19"))
(mean-time '("23:00:17" "23:40:20" "00:12:45" "00:17:19"))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>"23:47:43"</pre>
<pre>"23:47:43"</pre>
Line 2,093: Line 2,093:
{{works with|Rakudo|2015.12}}
{{works with|Rakudo|2015.12}}


<lang perl6>sub tod2rad($_) { [+](.comb(/\d+/) Z* 3600,60,1) * tau / 86400 }
<syntaxhighlight lang=perl6>sub tod2rad($_) { [+](.comb(/\d+/) Z* 3600,60,1) * tau / 86400 }
sub rad2tod ($r) {
sub rad2tod ($r) {
Line 2,106: Line 2,106:
my @times = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"];
my @times = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"];
say "{ mean-time(@times) } is the mean time of @times[]";</lang>
say "{ mean-time(@times) } is the mean time of @times[]";</syntaxhighlight>


{{out}}
{{out}}
Line 2,114: Line 2,114:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang=rexx>/* REXX ---------------------------------------------------------------
* 25.06.2014 Walter Pachl
* 25.06.2014 Walter Pachl
* taken from ooRexx using my very aged sin/cos/artan functions
* taken from ooRexx using my very aged sin/cos/artan functions
Line 2,213: Line 2,213:
End
End
Numeric Digits (prec)
Numeric Digits (prec)
Return r+0</lang>
Return r+0</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 2,220: Line 2,220:
Using the methods at [[http://rosettacode.org/wiki/Averages/Mean_angle#Ruby|Averages/Mean angle]]
Using the methods at [[http://rosettacode.org/wiki/Averages/Mean_angle#Ruby|Averages/Mean angle]]


<lang ruby>def time2deg(t)
<syntaxhighlight lang=ruby>def time2deg(t)
raise "invalid time" unless m = t.match(/^(\d\d):(\d\d):(\d\d)$/)
raise "invalid time" unless m = t.match(/^(\d\d):(\d\d):(\d\d)$/)
hh,mm,ss = m[1..3].map {|e| e.to_i}
hh,mm,ss = m[1..3].map {|e| e.to_i}
Line 2,238: Line 2,238:
end
end


puts mean_time ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]</lang>
puts mean_time ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]</syntaxhighlight>
{{out}}
{{out}}
23:47:43
23:47:43


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>global pi
<syntaxhighlight lang=runbasic>global pi
pi = acs(-1)
pi = acs(-1)
Line 2,286: Line 2,286:
atan2 = (y=0)*(x<0)*pi
atan2 = (y=0)*(x<0)*pi
end if
end if
End Function</lang>
End Function</syntaxhighlight>
=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>
<syntaxhighlight lang=rust>
use std::f64::consts::PI;
use std::f64::consts::PI;


Line 2,351: Line 2,351:
}
}


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,358: Line 2,358:


=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|java.time.LocalTime}}<lang Scala>import java.time.LocalTime
{{libheader|java.time.LocalTime}}<syntaxhighlight lang=Scala>import java.time.LocalTime
import scala.compat.Platform
import scala.compat.Platform


Line 2,387: Line 2,387:
assert(LocalTime.MIN.plusSeconds(meanAngle(times, dayInSeconds).round).toString == "23:47:40")
assert(LocalTime.MIN.plusSeconds(meanAngle(times, dayInSeconds).round).toString == "23:47:40")
println(s"Successfully completed without errors. [total ${Platform.currentTime - executionStart} ms]")
println(s"Successfully completed without errors. [total ${Platform.currentTime - executionStart} ms]")
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
Line 2,394: Line 2,394:
To be self-contained, this starts with the functions from [[Averages/Mean angle]]
To be self-contained, this starts with the functions from [[Averages/Mean angle]]


<lang scheme>
<syntaxhighlight lang=scheme>
(import (scheme base)
(import (scheme base)
(scheme inexact)
(scheme inexact)
Line 2,447: Line 2,447:
(write (mean-time-of-day '("23:00:17" "23:40:20" "00:12:45" "00:17:19")))
(write (mean-time-of-day '("23:00:17" "23:40:20" "00:12:45" "00:17:19")))
(newline)
(newline)
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,457: Line 2,457:
{{trans|Ruby}}
{{trans|Ruby}}
Using the '''mean_angle()''' function from: [http://rosettacode.org/wiki/Averages/Mean_angle#Sidef "Averages/Mean angle"]
Using the '''mean_angle()''' function from: [http://rosettacode.org/wiki/Averages/Mean_angle#Sidef "Averages/Mean angle"]
<lang ruby>func time2deg(t) {
<syntaxhighlight lang=ruby>func time2deg(t) {
(var m = t.match(/^(\d\d):(\d\d):(\d\d)$/)) || die "invalid time"
(var m = t.match(/^(\d\d):(\d\d):(\d\d)$/)) || die "invalid time"
var (hh,mm,ss) = m.cap.map{.to_i}...
var (hh,mm,ss) = m.cap.map{.to_i}...
Line 2,473: Line 2,473:
}
}
 
 
say mean_time(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])</lang>
say mean_time(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])</syntaxhighlight>
{{out}}
{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>
Line 2,479: Line 2,479:
=={{header|SQL}}/{{header|PostgreSQL}}==
=={{header|SQL}}/{{header|PostgreSQL}}==
{{trans|Python}}
{{trans|Python}}
<lang SQL>
<syntaxhighlight lang=SQL>
--Setup table for testing
--Setup table for testing
CREATE TABLE time_table(times time);
CREATE TABLE time_table(times time);
Line 2,492: Line 2,492:
(SELECT EXTRACT(epoch from times) t
(SELECT EXTRACT(epoch from times) t
FROM time_table) T1
FROM time_table) T1
)T2</lang>
)T2</syntaxhighlight>


Output:
Output:
Line 2,501: Line 2,501:
=={{header|Swift}}==
=={{header|Swift}}==


<lang swift>import Foundation
<syntaxhighlight lang=swift>import Foundation


@inlinable public func d2r<T: FloatingPoint>(_ f: T) -> T { f * .pi / 180 }
@inlinable public func d2r<T: FloatingPoint>(_ f: T) -> T { f * .pi / 180 }
Line 2,557: Line 2,557:
let meanTime = DigitTime(fromDegrees: 360 + meanOfAngles(times.map({ $0.toDegrees() })))
let meanTime = DigitTime(fromDegrees: 360 + meanOfAngles(times.map({ $0.toDegrees() })))


print("Given times \(times), the mean time is \(meanTime)")</lang>
print("Given times \(times), the mean time is \(meanTime)")</syntaxhighlight>


{{out}}
{{out}}
Line 2,564: Line 2,564:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>proc meanTime {times} {
<syntaxhighlight lang=tcl>proc meanTime {times} {
set secsPerRad [expr {60 * 60 * 12 / atan2(0,-1)}]
set secsPerRad [expr {60 * 60 * 12 / atan2(0,-1)}]
set sumSin [set sumCos 0.0]
set sumSin [set sumCos 0.0]
Line 2,581: Line 2,581:
}
}


puts [meanTime {23:00:17 23:40:20 00:12:45 00:17:19}]</lang>
puts [meanTime {23:00:17 23:40:20 00:12:45 00:17:19}]</syntaxhighlight>
{{out}}
{{out}}
23:47:43
23:47:43
Line 2,587: Line 2,587:
=={{header|VBA}}==
=={{header|VBA}}==
Uses Excel and [[Averages/Mean_angle#VBA|mean angle]].
Uses Excel and [[Averages/Mean_angle#VBA|mean angle]].
<lang vb>Public Sub mean_time()
<syntaxhighlight lang=vb>Public Sub mean_time()
Dim angles() As Double
Dim angles() As Double
s = [{"23:00:17","23:40:20","00:12:45","00:17:19"}]
s = [{"23:00:17","23:40:20","00:12:45","00:17:19"}]
Line 2,594: Line 2,594:
Next i
Next i
Debug.Print Format(mean_angle(s) / 360 + 1, "hh:mm:ss")
Debug.Print Format(mean_angle(s) / 360 + 1, "hh:mm:ss")
End Sub</lang>{{out}}
End Sub</syntaxhighlight>{{out}}
<pre>23:47:43</pre>
<pre>23:47:43</pre>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Module Module1
<syntaxhighlight lang=vbnet>Module Module1


Function TimeToDegrees(time As TimeSpan) As Double
Function TimeToDegrees(time As TimeSpan) As Double
Line 2,644: Line 2,644:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>Enter times, end with no input:
<pre>Enter times, end with no input:
Line 2,656: Line 2,656:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|Wren}}
{{trans|Wren}}
<lang vlang>import math
<syntaxhighlight lang=vlang>import math


const inputs = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
const inputs = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
Line 2,694: Line 2,694:
s := t[2].f64()
s := t[2].f64()
return (h + m + s) / 240
return (h + m + s) / 240
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,703: Line 2,703:
=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang=ecmascript>import "/fmt" for Fmt


var timeToDegs = Fn.new { |time|
var timeToDegs = Fn.new { |time|
Line 2,736: Line 2,736:
var times = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
var times = ["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
var angles = times.map { |t| timeToDegs.call(t) }.toList
var angles = times.map { |t| timeToDegs.call(t) }.toList
System.print("Mean time of day is : %(degsToTime.call(meanAngle.call(angles)))")</lang>
System.print("Mean time of day is : %(degsToTime.call(meanAngle.call(angles)))")</syntaxhighlight>


{{out}}
{{out}}
Line 2,744: Line 2,744:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>include c:\cxpl\codes;
<syntaxhighlight lang=XPL0>include c:\cxpl\codes;


proc NumOut(N); \Display 2-digit N with leading zero
proc NumOut(N); \Display 2-digit N with leading zero
Line 2,780: Line 2,780:
];
];


TimeOut(MeanTime([4, [23,00,17], [23,40,20], [00,12,45], [00,17,19]]))</lang>
TimeOut(MeanTime([4, [23,00,17], [23,40,20], [00,12,45], [00,17,19]]))</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,788: Line 2,788:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|Phix}}
{{trans|Phix}}
<lang Yabasic>sub atan2(y, x)
<syntaxhighlight lang=Yabasic>sub atan2(y, x)
return 2 * atan((sqrt(x **2 + y ** 2) - x) / y)
return 2 * atan((sqrt(x **2 + y ** 2) - x) / y)
end sub
end sub
Line 2,833: Line 2,833:


// Output: Mean Time is 23:47:43
// Output: Mean Time is 23:47:43
</syntaxhighlight>
</lang>


=={{header|zkl}}==
=={{header|zkl}}==
Line 2,839: Line 2,839:
to task "Averages/Mean angle" and some on-the-fly
to task "Averages/Mean angle" and some on-the-fly
time-to-angle and back conversions.
time-to-angle and back conversions.
<lang zkl>var D=Time.Date;
<syntaxhighlight lang=zkl>var D=Time.Date;
fcn meanT(t1,t2,etc){
fcn meanT(t1,t2,etc){
ts:=vm.arglist.apply(fcn(hms){
ts:=vm.arglist.apply(fcn(hms){
Line 2,850: Line 2,850:
if(mt<0) mt+=24; //-0.204622-->23.7954
if(mt<0) mt+=24; //-0.204622-->23.7954
D.toHour(mt).concat(":")
D.toHour(mt).concat(":")
}</lang>
}</syntaxhighlight>
Time.Date.toFloat/toHour convert 24hr HMS to fractional time and back. Multiplying fractional time by 360/24=15 yields angle.
Time.Date.toFloat/toHour convert 24hr HMS to fractional time and back. Multiplying fractional time by 360/24=15 yields angle.
{{out}}
{{out}}