| Index: recipes/next_prime.py
|
| diff --git a/recipes/next_prime.py b/recipes/next_prime.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..af28cf1cbfa0cf320c6c6d768e10c07a84fd3906
|
| --- /dev/null
|
| +++ b/recipes/next_prime.py
|
| @@ -0,0 +1,36 @@
|
| +from recipe_engine.recipe_api import Property
|
| +from recipe_engine import config
|
| +import math
|
| +
|
| +DEPS = [
|
| + 'recipe_engine/properties',
|
| +]
|
| +
|
| +PROPERTIES = {
|
| + 'curr_prime': Property(kind=int),
|
| +}
|
| +
|
| +RETURN_SCHEMA = config.ReturnSchema(
|
| + result=config.Single(int),
|
| +)
|
| +
|
| +def is_prime(val):
|
| + if val % 2 == 0:
|
| + return False
|
| + for div in range(3, math.ceil(math.sqrt(val))):
|
| + if val % div == 0:
|
| + return False
|
| + return True
|
| +
|
| +def RunSteps(api, curr_prime):
|
| + curr_prime += 2
|
| + while not is_prime(curr_prime):
|
| + curr_prime += 2
|
| +
|
| + return RETURN_SCHEMA(result=curr_prime)
|
| +
|
| +def GenTests(api):
|
| + yield (
|
| + api.test('basic') +
|
| + api.properties(curr_prime=3)
|
| + )
|
|
|