typed racket solution for euler 3
This commit is contained in:
parent
447f5ebd77
commit
7cf16ea48b
1 changed files with 5 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
#lang racket
|
||||
#lang typed/racket
|
||||
|
||||
(require math/number-theory)
|
||||
|
||||
(: max-prime-factor (-> Integer (U False Integer)))
|
||||
(define (max-prime-factor x)
|
||||
(if (prime? x) x
|
||||
(for/or ((i (filter prime? (range 2 (sqrt x)))))
|
||||
(if (zero? (remainder x i)) (max-prime-factor (quotient x i)) #f))))
|
||||
(for/or ((i (filter prime? (range 2 (ceiling (assert (sqrt x) real?)))))
|
||||
#:when (zero? (remainder x i)))
|
||||
(max-prime-factor (quotient x i)))))
|
||||
|
||||
(max-prime-factor 600851475143)
|
Reference in a new issue