[ create a new paste ] login | about

Link: http://codepad.org/W3QrjxmS    [ raw code | output | fork ]

Scheme, pasted on Mar 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(define (seq357)
  (define (merge x y)
    (let ((xv (car x)) (yv (car y)))
      (if (<= xv yv) (cons xv (delay (merge (force (cdr x)) y)))
                     (cons yv (delay (merge x (force (cdr y))))))))
  (define (smult m s) (cons (* m (car s)) (delay (smult m (force (cdr s)))))) ;; equiv to map (* m)
  (define (s7 n) (cons n (delay (s7 (* n 7)))))
  (define s57 (cons 1 (delay (merge (s7 7) (smult 5 s57)))))
  (define s357 (cons 1 (delay (merge (force (cdr s57)) (smult 3 s357)))))
  s357)

;;; test...
(define limit 1000000)
(define (countemto lmt)(do ((nxt (seq357) (force (cdr nxt))) (cnt 1 (+ cnt 1))) ((>= cnt lmt) (car nxt))))
(display (time (countemto limit))) (newline)


Output:
1
2
cpu time: 2129 real time: 2255 gc time: 524
13426592765267303385420752863449559332046383396897766778332312798684008264824725020769591310454416088759899139404296875


Create a new paste based on this one


Comments: