Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
18c802a4c5
2 changed files with 6 additions and 9 deletions
1
1/euler1.py
Normal file
1
1/euler1.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
sum([x for x in range(1,1000) if x % 5 == 0 or x % 3 == 0])
|
14
3/euler3.rkt
14
3/euler3.rkt
|
@ -2,13 +2,9 @@
|
||||||
|
|
||||||
(require math/number-theory)
|
(require math/number-theory)
|
||||||
|
|
||||||
(define (primes x) (filter prime? (range 2 (sqrt x))))
|
(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))))
|
||||||
|
|
||||||
(define (primefactors x primes)
|
(max-prime-factor 600851475143)
|
||||||
(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