racket solution for the third problem
This commit is contained in:
parent
faf8f4962a
commit
88e45dc7a3
1 changed files with 14 additions and 0 deletions
14
3/euler3.rkt
Normal file
14
3/euler3.rkt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require math/number-theory)
|
||||||
|
|
||||||
|
(define (primes x) (filter prime? (range 2 (sqrt x))))
|
||||||
|
|
||||||
|
(define (primefactors x primes)
|
||||||
|
(if (prime? x)
|
||||||
|
(list x)
|
||||||
|
(if (zero? (remainder x (car primes)))
|
||||||
|
(cons (car primes) (primefactors (quotient x (car primes)) primes))
|
||||||
|
(primefactors x (cdr primes)))))
|
||||||
|
|
||||||
|
(apply max (primefactors 600851475143 (primes 600851475143)))
|
Reference in a new issue