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/e0047/euler0047.rkt

22 lines
643 B
Racket

#lang racket
(require math/number-theory)
(define (primefactors x)
(if (prime? x)
(list x)
(for/or ((i (cons 2 (range 3 (+ 1 (ceiling (sqrt x))) 2)))
#:when (prime? i)
#:when (zero? (remainder x i)))
(cons i (primefactors (quotient x i))))))
(define (recur x)
(if (and
(equal? (length (remove-duplicates (primefactors x))) 4)
(equal? (length (remove-duplicates (primefactors (+ x 1)))) 4)
(equal? (length (remove-duplicates (primefactors (+ x 2)))) 4)
(equal? (length (remove-duplicates (primefactors (+ x 3)))) 4))
x
(recur (+ x 1))))
(recur 2)