From 819fb264c01ef2dd62b1d21bf3dcc982bfe66f01 Mon Sep 17 00:00:00 2001 From: n1rna Date: Thu, 10 Oct 2019 00:08:29 +0330 Subject: [PATCH 1/2] Add solution for Summation of primes in bash --- Solutions/Summation_of_primes.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 Solutions/Summation_of_primes.sh diff --git a/Solutions/Summation_of_primes.sh b/Solutions/Summation_of_primes.sh new file mode 100755 index 0000000..ac15fbf --- /dev/null +++ b/Solutions/Summation_of_primes.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +factor $(seq 2 $1) | awk 'NF==2{print $2}' | awk '{s+=$1} END {print s}' + + From ad50d0eb2eebf098dfe212bfa88e8f91f29882b7 Mon Sep 17 00:00:00 2001 From: n1rna Date: Thu, 10 Oct 2019 11:56:39 +0330 Subject: [PATCH 2/2] Modify the solution to fit the question requiremens --- Solutions/Summation_of_primes.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Solutions/Summation_of_primes.sh b/Solutions/Summation_of_primes.sh index ac15fbf..588736c 100755 --- a/Solutions/Summation_of_primes.sh +++ b/Solutions/Summation_of_primes.sh @@ -1,5 +1,6 @@ #!/bin/bash -factor $(seq 2 $1) | awk 'NF==2{print $2}' | awk '{s+=$1} END {print s}' - - +arr=() +read num +for i in $(seq 1 $num); do read t && arr+=($t); done +for i in "${arr[@]}"; do factor $(seq 2 $i) | awk 'NF==2{print $2}' | awk '{s+=$1} END {print s}'; done