From e9279325bd7009f7bf648989a09ce9c42afb7add Mon Sep 17 00:00:00 2001 From: Brad Hintze Date: Wed, 9 Oct 2019 16:16:39 -0700 Subject: [PATCH] prime sum up to number --- Solutions/Summation_of_primes.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Solutions/Summation_of_primes.rb diff --git a/Solutions/Summation_of_primes.rb b/Solutions/Summation_of_primes.rb new file mode 100644 index 0000000..a611aa6 --- /dev/null +++ b/Solutions/Summation_of_primes.rb @@ -0,0 +1,19 @@ +def get_primes(num) + start = 2 + primes = (start..num).to_a + + (start..num).each do |i| + (start..i).each do |ii| + if (i % ii == 0) && i != ii + primes.delete(i) + break + end + end + end + primes.sum +end + +print 'Please Enter a number? ' +num = gets.chomp +puts get_primes(num.to_i) +