Interesting. This is the timing on Mac. Comparing to Alex's result,
the numbers roughly match "< 7s" v.s. "> 13s" while fact-1 is close.
$ racket
Welcome to Racket v7.2.0.3.
> (enter! "factorial.rkt")
"factorial.rkt"> (equal? (fact 10) (fact-1 10))
#t
"factorial.rkt"> (time (void (fact-1
You can check if the big number multiplication is the problem, by using a
factorial version which does not need so many big number multiplications:
#lang racket/base
(require racket/math)
(define (fact n)
(if (zero? n) 1 (* n (fact (- n 1)
(define (fact-1 n)
(define nslots
2 matches
Mail list logo