How to resolve the algorithm Averages/Mean time of day step by step in the ooRexx 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 ooRexx 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 ooRexx programming language
Source code in the oorexx programming language
/* REXX ---------------------------------------------------------------
* 25.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
times='23:00:17 23:40:20 00:12:45 00:17:19'
sum=0
day=86400
x=0
y=0
Do i=1 To words(times) /* loop over times */
time.i=word(times,i) /* pick a time */
alpha.i=t2a(time.i) /* convert to angle (degrees) */
/* Say time.i format(alpha.i,6,9) */
x=x+rxcalcsin(alpha.i) /* accumulate sines */
y=y+rxcalccos(alpha.i) /* accumulate cosines */
End
ww=rxcalcarctan(x/y) /* compute average angle */
ss=ww*86400/360 /* convert to seconds */
If ss<0 Then ss=ss+day /* avoid negative value */
m=ss%60 /* split into hh mm ss */
s=ss-m*60
h=m%60
m=m-h*60
Say f2(h)':'f2(m)':'f2(s) /* show the mean time */
Exit
t2a: Procedure Expose day /* convert time to angle */
Parse Arg hh ':' mm ':' ss
sec=(hh*60+mm)*60+ss
If sec>(day/2) Then
sec=sec-day
a=360*sec/day
Return a
f2: return right(format(arg(1),2,0),2,0)
::requires rxmath library
You may also check:How to resolve the algorithm Compare length of two strings step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the REBOL programming language
You may also check:How to resolve the algorithm Tree traversal step by step in the E programming language
You may also check:How to resolve the algorithm Binary digits step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Function definition step by step in the Falcon programming language