Author Message

Hi,
Please can someone tell me where is the problem?
I used a "clock-1" procedure to convert a time given in milliseconds into the format " h:m:s:ms " where h represents the number of hours, m the number of minutes, s for seconds and ms for milliseconds.
here is the procedure

(define (clock-1 x)
(define (find-hours)
(quotient x 3600000))
(define (rest-from-hours)
(remainder x 3600000))
(define (find-minutes)
(quotient (rest-from-hours) 60000))
(define (rest-from-minutes)
(remainder x 60000))
(define (find-seconds)
(quotient (rest-from-minutes) 1000))
(define (rest-from-seconds)
(remainder (rest-from-minutes) 1000))
(define (find-ms)
(rest-from-seconds) )

(display (find-hours))
(display ":")
(display (find-minutes))
(display ":")
(display (find-seconds))
(display ":")
(display (find-ms))
(newline))

Now I want to use "clock-1" to compute the time taken by the execution of  "(rec-expt 1 3000)" where

(define (rec-expt x y)
(define (expt y)
(if (= y 0)
1
(* x (expt (- y 1)))))
(if (>= y 0)
(expt y)
(/ 1 (expt (abs y)))))

So I put the following

(clock-1 (time (rec-expt 1 3000)))
(time (rec-expt 1 3000))

It should return the same results, at least "0:0:1:563 "here the problem, the results are

Quote:
>(clock-1 (time (rec-expt 1 3000)))

(time (rec-expt 1 3000))
5 collections
1563 ms elapsed cpu time (user+system time), including 1533 ms collecting
0:0:0:1        ???
Quote:
>(time (rec-expt 1 3000))

(time (rec-expt 1 3000))
5 collections
1552 ms elapsed cpu time (user+system time), including 1502 ms collecting
1

The two returned times are different and(time (rec-expt 1 3000)) should return  "0:0:1:563 "  where is the problem?

Sun, 05 May 2002 03:00:00 GMT

 Page 1 of 1 [ 1 post ]

Relevant Pages