Fasten the solution to 10 in bash by halving the tested integers

This commit is contained in:
Felix Cremer 2017-08-09 12:40:11 +02:00
parent ed772e7550
commit f925e1c86c

View file

@ -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"