Mathematics
Algorithms
Logic
Numbers
def prime_checker(n): if n < 4 or n==5: return n > 1 if n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False i = 7 sqrt_n = int(n ** 0.5) while i <= sqrt_n: if n % i == 0 or n % (i + 2) == 0: return False i += 7 return True
- def prime_checker(n):
if n < 4:- if n < 4 or n==5:
- return n > 1
if n % 2 == 0 or n % 3 == 0:- if n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
- return False
i = 5- i = 7
- sqrt_n = int(n ** 0.5)
- while i <= sqrt_n:
- if n % i == 0 or n % (i + 2) == 0:
- return False
i += 6- i += 7
- return True
import codewars_test as test from solution import prime_checker @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(prime_checker(653), True) test.assert_equals(prime_checker(654), False) test.assert_equals(prime_checker(5), True) test.assert_equals(prime_checker(777), False) test.assert_equals(prime_checker(977), True) test.assert_equals(prime_checker(125), False) test.assert_equals(prime_checker(997), True) test.assert_equals(prime_checker(709), True) test.assert_equals(prime_checker(15), False) test.assert_equals(prime_checker(11), True) test.assert_equals(prime_checker(13), True) test.assert_equals(prime_checker(17), True) test.assert_equals(prime_checker(19), True) test.assert_equals(prime_checker(23), True) test.assert_equals(prime_checker(29), True) test.assert_equals(prime_checker(1021), True)
- import codewars_test as test
- from solution import prime_checker
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(prime_checker(653), True)
- test.assert_equals(prime_checker(654), False)
- test.assert_equals(prime_checker(5), True)
- test.assert_equals(prime_checker(777), False)
- test.assert_equals(prime_checker(977), True)
- test.assert_equals(prime_checker(125), False)
- test.assert_equals(prime_checker(997), True)
- test.assert_equals(prime_checker(709), True)
- test.assert_equals(prime_checker(15), False)
- test.assert_equals(prime_checker(11), True)
- test.assert_equals(prime_checker(13), True)
- test.assert_equals(prime_checker(17), True)
- test.assert_equals(prime_checker(19), True)
- test.assert_equals(prime_checker(23), True)
- test.assert_equals(prime_checker(29), True)
- test.assert_equals(prime_checker(1021), True)