Add julia solution and fasten bash solution for problem 10 #1
3 changed files with 44 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# I have yet to see this script coming to an end...
|
# I have yet to see this script coming to an end...
|
||||||
|
|
||||||
declare -i primeSum=0
|
declare -i primeSum=2
|
||||||
|
sequence=$(seq 3 2 2000000)
|
||||||
|
|
||||||
for num in {2..2000000}; do
|
for num in $sequence; do
|
||||||
|
echo $num
|
||||||
[[ "$(factor $num | cut -d " " -f2)" != $num ]] || primeSum=$(( $primeSum + $num ))
|
[[ "$(factor $num | cut -d " " -f2)" != $num ]] || primeSum=$(( $primeSum + $num ))
|
||||||
done
|
done
|
||||||
echo "$primeSum"
|
echo "$primeSum"
|
||||||
|
|
13
e0010/euler0010.jl
Normal file
13
e0010/euler0010.jl
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/julia
|
||||||
|
import Primes
|
||||||
|
function sumprimes(n::Int)
|
||||||
|
#primnumbers = SharedArray{Int}(n)
|
||||||
|
primesum=2
|
||||||
|
parasum = @parallel (+) for i in 3:2:n
|
||||||
|
Primes.isprime(i)*i
|
||||||
|
end
|
||||||
|
primesum+=parasum
|
||||||
|
end
|
||||||
|
sumprimes(10)
|
||||||
|
@time prime = sumprimes(2000000)
|
||||||
|
print(prime)
|
26
e0015/euler0015.jl
Normal file
26
e0015/euler0015.jl
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
function euler0015(n::Integer)
|
||||||
|
n=big(n)
|
||||||
|
Int(div(prod(n+1:2n,1),factorial(big(n))))
|
||||||
|
end
|
||||||
|
|
||||||
|
function euler0015_2(n::Integer)
|
||||||
|
factorial(2*big(n))/factorial(big(n))^2
|
||||||
|
end
|
||||||
|
|
||||||
|
function euler0015_3(n::Integer)
|
||||||
|
n=big(n)
|
||||||
|
prod(n+1:2n,1)//factorial(big(n))
|
||||||
|
end
|
||||||
|
|
||||||
|
euler0015(3)
|
||||||
|
@time result=euler0015(big(20))
|
||||||
|
println(result)
|
||||||
|
|
||||||
|
euler0015_2(3)
|
||||||
|
@time result=euler0015_2(big(20))
|
||||||
|
println(Int(result))
|
||||||
|
|
||||||
|
euler0015_3(3)
|
||||||
|
@time result=euler0015_3(big(20))
|
||||||
|
println(result)
|
Reference in a new issue