How to resolve the algorithm Averages/Mean time of day step by step in the Euphoria programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Mean time of day step by step in the Euphoria programming language
Table of Contents
Problem Statement
A particular activity of bats occurs at these times of the day: Using the idea that there are twenty-four hours in a day, which is analogous to there being 360 degrees in a circle, map times of day to and from angles; and using the ideas of Averages/Mean angle compute and show the average time of the nocturnal activity to an accuracy of one second of time.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Mean time of day step by step in the Euphoria programming language
Source code in the euphoria programming language
include std/console.e
include std/math.e
include std/mathcons.e
include std/sequence.e
include std/get.e
function T2D(sequence TimeSeq)
return (360 * TimeSeq[1] / 24 + 360 * TimeSeq[2] / (24 * 60) +
360 * TimeSeq[3] / (24 * 3600))
end function
function D2T(atom angle)
sequence TimeSeq = {0,0,0}
atom seconds = 24 * 60 * 60 * angle / 360
TimeSeq[3] = mod(seconds,60)
TimeSeq[2] = (mod(seconds,3600) - TimeSeq[3]) / 60
TimeSeq[1] = seconds / 3600
return TimeSeq
end function
function MeanAngle(sequence angles)
atom x = 0, y = 0
integer l = length(angles)
for i = 1 to length(angles) do
x += cos(angles[i] * PI / 180)
y += sin(angles[i] * PI / 180)
end for
return atan2(y / l, x / l) * 180 / PI
end function
sequence TimeEntry, TimeList = {}, TimeSeq
puts(1,"Enter times. Enter with no input to end\n")
while 1 do
TimeEntry = prompt_string("")
if equal(TimeEntry,"") then -- no more entries
for i = 1 to length(TimeList) do
TimeList[i] = split(TimeList[i],":") -- split the times into sequences
for j = 1 to 3 do
TimeList[i][j] = defaulted_value(TimeList[i][j],0) -- convert to numerical values
end for
end for
exit
end if
TimeList = append(TimeList,TimeEntry)
end while
sequence AngleList = repeat({},length(TimeList))
for i = 1 to length(AngleList) do
AngleList[i] = T2D(TimeList[i])
end for
sequence MeanTime = D2T(360+MeanAngle(AngleList))
printf(1,"\nMean Time: %d:%d:%d\n",MeanTime)
if getc(0) then end if
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Objeck programming language
You may also check:How to resolve the algorithm First-class functions step by step in the Mercury programming language
You may also check:How to resolve the algorithm Partition function P step by step in the 11l programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the RPL programming language