[Tutor] no loops

Marc Poulin marc_a_poulin at yahoo.com
Wed Jul 12 03:42:16 CEST 2006


--- John Fouhy <john at fouhy.net> wrote:

> On 12/07/06, Christopher Spears
> <cspears2002 at yahoo.com> wrote:
> > Now the exercise is:
> > As an exercise, rewrite this function so that it
> > doesn't contain any loops.
> >
> > I have been staring at this function and drawing a
> > blank.  Something tells me that I need to use
> > iteration, but I am not sure how I could implement
> it.
> 
> Hi Chris,
> 
> You are using iteration.  That's what loops are :-)
> 
> Perhaps you meant to say "recursion", which is where
> a function calls
> itself.  You could solve this recursively, but I
> think Gregor's
> comment is closer to what they want you to do.
> 
> -- 
> John.

I agree with Gregor and John. What makes the problem
difficult is the fact that time is represented using 3
different units of measure: hours, minutes, and
seconds. The math becomes much simpler if you convert
the time value to a single unit (such as seconds).

But it doesn't have to be seconds. I recall seeing one
 database that stores time as fractional hours where a
minute is worth 1/60 of an hour and a second is worth
1/3600 of an hour. 

In other words, 1:15 is stored as 1.25 hours, 4:30 is
stored as 4.5 hours, and so forth. Converting from
(hours, minutes, seconds) to fractional hours is
pretty easy, but going the other way is not so simple.




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list