solved 47 in racket, ugly code
This commit is contained in:
parent
65b6786569
commit
8564d3de28
1 changed files with 22 additions and 0 deletions
22
47/euler47.rkt
Normal file
22
47/euler47.rkt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#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)
|
Reference in a new issue