This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
project-euler/3/euler3.rkt
2017-05-09 19:48:35 +02:00

14 lines
No EOL
392 B
Racket

#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)))