Averages/Mean time of day: Difference between revisions

Content added Content deleted
(Added Algol 68)
(Added Uiua solution)
Line 2,681: Line 2,681:
{{out}}
{{out}}
23:47:43
23:47:43

=={{header|Uiua}}==
Not much native support for trig in Uiua, so much of the code is just setting that up.
<syntaxhighlight lang="uiua">
# Find mean time of day using 'mean angle'

ParseTS ← setinv(/(+×60)⊜⋕≠@:.|/(◇⊂◇⊂)@:≡(□↙¯2⊂"00"°⋕)⌊[⍥(⊃÷◿60)2])
RpS ← ×π÷180÷240 1 # Radians per second
SpD ← ×× 24 60 60 # Seconds per day
Cos ← setinv(∿+η|-:η°∿)
# Polar to (complex) cartesian, and inverse.
PtoC ← setinv(
ℂ°⊟×⊟⊃∿Cos:°⊟
| √+∩(×.),⟜:°ℂ
⍤("undefined for r=0")≠0.
⊟⟜(⍥¯<0:°Cos÷)
)

Ts ← "23:00:17, 23:40:20, 00:12:45, 00:17:19"
⊜(PtoC ⊟1 ×RpS ParseTS)¬⦷", ".Ts # Get TSs as unit complex numbers.
⁅÷RpS⊡1°PtoC÷⊃(⧻|/+) # Average them and convert back to seconds.
°ParseTS+×SpD<0. # Ensure its >0, format as TS.

</syntaxhighlight >
{{out}}
<pre>
"23:47:43"
</pre>


=={{header|VBA}}==
=={{header|VBA}}==