summaryrefslogtreecommitdiff
path: root/problem-3.scm
blob: 81e899ef69ad68d10388c217e1d408c72d179a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(define (divisible? m n)
  (zero? (modulo m n)))

(define (largest-prime-factor n)
  (define (inner n d)
    (cond ((= d n)
           d)
          ((divisible? n d)
           (inner (/ n d) d))
          (else
           (inner n (1+ d)))))
  (inner n 2))

(largest-prime-factor 600851475143)