-
;What is the first term in the
-
;Fibonacci sequence to contain 1000 digits?
-
(define (square x) (* x x))
-
-
(define (pow man exp)
-
(cond
-
((= exp 0) 1)
-
((< exp 0) (/ 1 (pow exp (- man))))
-
((even? exp) (square (pow man (/ exp 2))))
-
((odd? exp) (* man (square (pow man (/ (- exp 1) 2)))))
-
(else #f)))
-
-
(define (prob25 digits)
-
(let ((big-const (pow 10 (- digits 1))))
-
(let fib ((first 1) (second 1) (count 1))
-
(if (>= first big-const)
-
count
-
(begin
-
;(display first) (display " ") (display count) (newline)
-
(fib second (+ first second) (+ count 1))
-
)))
-
)
-
)
-
-
(prob25 1000)
Posts Tagged ‘euler’
Euler problem 25
Friday, November 21st, 2008Euler Problem 1
Monday, November 3rd, 2008I’ve decided to do a series of posts with my solutions to the Euler problems. They’ll be tagged with “euler”, and once I figure out how I’ll stop them from showing up on the main page.
This is the first Euler Problem
-
(define sum
-
(lambda (x) (apply + x)))
-
(define product
-
(lambda x (apply * x)))
-
(define sum-1-to-n
-
(lambda (x) (* (/ 1 2) x (+ x 1))))
-
(define (1+ x) (+ x 1))
-
(define (-1+ x) (- x 1))
-
-
(let
-
((smalllist '(3 5 6 9 10 12 15))
-
(num15s (quotient 1000 15)))
-
"(* num15s 15) -> 990, so we add the last few by hand"
-
(+ (* 15
-
(length smalllist)
-
(sum-1-to-n (-1+ num15s)))
-
(* num15s (sum smalllist))
-
993 995 996 999))