Averages/Mean time of day: Difference between revisions

Content added Content deleted
m (→‎{{header|C#}}: Changing the section header so that task shows up under the language properly)
Line 11: Line 11:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}(AutoHotkey1.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"])
<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) {
c := ATan(1) / 45
static c := ATan(1) / 45
for k, v in t
for k, v in t {
n := StrSplit(v, ":")
n := StrSplit(v, ":")
, r := c * (n[1] * 3600 + n[2] * 60 + n[3]) / 240
r := c * (n[1] * 3600 + n[2] * 60 + n[3]) / 240
, x += Cos(r)
x += Cos(r)
, y += Sin(r)
y += Sin(r)
}
r := atan2(x, y) / c
r := atan2(x, y) / c
r := (r < 0 ? r + 360 : r) / 15
r := (r < 0 ? r + 360 : r) / 15
Line 31: Line 32:
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>
}</lang>atan2() is available [http://www.autohotkey.com/board/topic/24114-popup-calculator-expression-evaluator/ here].
{{out}}
{{out}}
<pre>The mean time is: 23:47:43</pre>
<pre>The mean time is: 23:47:43</pre>