From f925e1c86cb651c894c7734ae5fd469b51e238ba Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 9 Aug 2017 12:40:11 +0200 Subject: [PATCH 1/4] Fasten the solution to 10 in bash by halving the tested integers --- e0010/euler0010.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/e0010/euler0010.bash b/e0010/euler0010.bash index fd0f5f8..09594d5 100755 --- a/e0010/euler0010.bash +++ b/e0010/euler0010.bash @@ -1,10 +1,12 @@ -#!/usr/bin/bash +#!/bin/bash # 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 )) done echo "$primeSum" From f4284934baf21eea568fabda669f8f28457cd76b Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 9 Aug 2017 12:41:08 +0200 Subject: [PATCH 2/4] Add julia solution to 10 --- e0010/euler0010.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 e0010/euler0010.jl diff --git a/e0010/euler0010.jl b/e0010/euler0010.jl new file mode 100644 index 0000000..1c5d491 --- /dev/null +++ b/e0010/euler0010.jl @@ -0,0 +1,14 @@ +#!/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 +end +sumprimes(11) +print(2) +@time prime = sumprimes(7) +print(prime) From 047060dfbbf8ff4ce83f68ca94518784b5ad26bf Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 9 Aug 2017 12:52:06 +0200 Subject: [PATCH 3/4] Change to the actual test number --- e0010/euler0010.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/e0010/euler0010.jl b/e0010/euler0010.jl index 1c5d491..d2f0e7d 100644 --- a/e0010/euler0010.jl +++ b/e0010/euler0010.jl @@ -3,12 +3,11 @@ import Primes function sumprimes(n::Int) #primnumbers = SharedArray{Int}(n) primesum=2 - parasum += @parallel (+) for i in 3:2:n + parasum = @parallel (+) for i in 3:2:n Primes.isprime(i)*i end - primesum + primesum+=parasum end -sumprimes(11) -print(2) -@time prime = sumprimes(7) +sumprimes(10) +@time prime = sumprimes(2000000) print(prime) From f1434adda31155096cdfafa17bd55fce125a0599 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 9 Aug 2017 18:37:45 +0200 Subject: [PATCH 4/4] Add problem 15 in julia --- e0015/euler0015.jl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 e0015/euler0015.jl diff --git a/e0015/euler0015.jl b/e0015/euler0015.jl new file mode 100644 index 0000000..93b3095 --- /dev/null +++ b/e0015/euler0015.jl @@ -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)