6 kyu
Is a number prime?
43,449 of 116,895arithmetric
Description:
Define a function that takes an integer argument and returns a logical value true
or false
depending on if the integer is a prime.
Per Wikipedia, a prime number ( or a prime ) is a natural number greater than 1
that has no positive divisors other than 1
and itself.
Requirements
- You can assume you will be given an integer input.
- You can not assume that the integer will be only positive. You may be given negative numbers as well ( or
0
). - NOTE on performance: There are no fancy optimizations required, but still the most trivial solutions might time out. Numbers go up to 2^31 ( or similar, depending on language ). Looping all the way up to
n
, orn/2
, will be too slow.
Example
is_prime(1) /* false */
is_prime(2) /* true */
is_prime(-1) /* false */
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Oct 19, 2013 |
Published | Oct 19, 2013 |
Warriors Trained | 249688 |
Total Skips | 33946 |
Total Code Submissions | 653265 |
Total Times Completed | 116895 |
JavaScript Completions | 43449 |
Python Completions | 34974 |
Ruby Completions | 4043 |
Haskell Completions | 1079 |
R Completions | 256 |
C# Completions | 5831 |
PHP Completions | 2925 |
C++ Completions | 8977 |
NASM Completions | 53 |
Java Completions | 10558 |
C Completions | 4541 |
Rust Completions | 1492 |
COBOL Completions | 22 |
Pascal Completions | 30 |
λ Calculus Completions | 4 |
Go Completions | 1383 |
Perl Completions | 31 |
D Completions | 10 |
Total Stars | 2573 |
% of votes with a positive feedback rating | 84% of 8949 |
Total "Very Satisfied" Votes | 6490 |
Total "Somewhat Satisfied" Votes | 2054 |
Total "Not Satisfied" Votes | 405 |