欧拉项目第65题.
#lang racket (define (k-con n f init) (let loop([i n] [r 0]) (cond [(= 1 i) (+ init r)] [else (loop (sub1 i) (/ 1 (+ r (f i))))]))) ;; ith convergent of sqrt(2) (define (sqrt2 i) (k-con i (λ (x) 2) 1)) ;; ith convergent of e (define (con-e i) (k-con i (λ (x) (let-values ([(q r) (quotient/remainder x 3)]) (if (zero? r) (* 2 q) 1))) 2)) (numerator (con-e 100))