Averages/Mean time of day: Difference between revisions

Added Julia language
(Added Julia language)
Line 871:
23:00:00
23:47:43</lang>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{trans|Matlab}}
<lang julia>function meantime(times::Array, dlm::String=":")
c = π / (12 * 60 * 60)
a = map(x -> parse.(Int, x), split.(times, dlm))
ϕ = collect(3600t[1] + 60t[2] + t[3] for t in a)
d = angle(mean(exp.(c * im * ϕ))) / 2π # days
if d < 0 d += 1 end
# Convert to h:m:s
h = trunc(Int, d * 24)
m = trunc(Int, d * 24 * 60) - h * 60
s = trunc(Int, d * 24 * 60 * 60) - h * 60 * 60 - m * 60
return "$h:$m:$s"
end
 
times = String["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
mtime = meantime(times)
println("Times:")
println.(times)
println("Mean: $mtime")</lang>
 
{{out}}
<pre>Times:
23:00:17
23:40:20
00:12:45
00:17:19
Mean: 23:47:43</pre>
 
=={{header|Kotlin}}==
Anonymous user