-
Notifications
You must be signed in to change notification settings - Fork 3
/
fib.rkt
26 lines (21 loc) · 827 Bytes
/
fib.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#lang typed/racket
(: fibRec (Integer Integer Integer -> Integer))
(define (fibRec qianVal zuoVal rem)
(if (= 0 rem) zuoVal (fibRec zuoVal (+ qianVal zuoVal) (- rem 1))))
(: fib (Integer -> Integer))
(define (fib x)
(cond
((= x 0) 0)
((= x 1) 1)
(else (fibRec 0 1 (- x 1)))))
(: doWork (Integer Integer -> Integer))
(define (doWork acc rem)
(if (= 0 rem) acc (doWork
(+ acc (fib (remainder (+ 1 acc) 50)))
(- rem 1))))
(define arg (string->number (vector-ref (current-command-line-arguments) 0)))
(define n (if arg arg 0))
(define start (current-inexact-milliseconds))
(doWork 0 (if n (numerator (inexact->exact (real-part n))) 0))
(define duration (- (current-inexact-milliseconds) start))
(printf "LANGUAGE Racket ~a\n" (inexact->exact (floor duration)))