7 kyu
Sum of Primes
480 of 513Z-Fikar
Description:
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
You will be given the lower
and upper
limits: the program will look for any prime number that exists between the lower limit to the upper limit (included).
Your objective is to sum all the primes between the given limits.
- If the limits are primes, then they are included
- -100000 <=
lower
<upper
<= 100000 - If
lower
is greater thanupper
, it should return0
Example
You are given a lower limit of 4
and an upper limit of 20
.
So the prime numbers from 4 to 20 will be:
5, 7, 11, 13, 17, 19
and if you add them up, the result will be 72
.
sum_primes(4, 20) = 72 # 5 + 7 + 11 + 13 + 17 + 19 = 72
sum_primes(20, 4) = 0 # since lower is greater than upper
sum_primes(2, 7) = 17 # 2 + 3 + 5 + 7 = 17
sum_primes(11, 11) = 11 # it consists of one prime number
sum_primes(60, 60) = 0 # since 60 is not a prime number
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Apr 28, 2017 |
Published | Apr 28, 2017 |
Warriors Trained | 1119 |
Total Skips | 14 |
Total Code Submissions | 2601 |
Total Times Completed | 513 |
Python Completions | 480 |
Ruby Completions | 46 |
Total Stars | 21 |
% of votes with a positive feedback rating | 89% of 170 |
Total "Very Satisfied" Votes | 140 |
Total "Somewhat Satisfied" Votes | 23 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 15 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |