diff options
Diffstat (limited to 'challenge-139')
| -rw-r--r-- | challenge-139/lubos-kolouch/python/ch-1.py | 7 | ||||
| -rw-r--r-- | challenge-139/lubos-kolouch/python/ch-2.py | 54 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-139/lubos-kolouch/python/ch-1.py b/challenge-139/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..ba5233b9c6 --- /dev/null +++ b/challenge-139/lubos-kolouch/python/ch-1.py @@ -0,0 +1,7 @@ +def is_jort_sorted(what): + + return what == sorted(what) + + +assert is_jort_sorted([1, 2, 3, 4, 5]) == 1 +assert is_jort_sorted([1, 3, 2, 4, 5]) == 0 diff --git a/challenge-139/lubos-kolouch/python/ch-2.py b/challenge-139/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..1dc33593a8 --- /dev/null +++ b/challenge-139/lubos-kolouch/python/ch-2.py @@ -0,0 +1,54 @@ +import re +from sympy import nextprime +import decimal + + +def get_repeating_pattern(what): + + with decimal.localcontext() as ctx: + ctx.prec = 100 + big_reverse = str(decimal.Decimal(1) / decimal.Decimal(what)) + + repeating = re.findall(r'(.+?)\1', big_reverse) + + try: + return len(repeating[0]) + except IndexError: + return 0 + + +def is_long_prime(what): + + repeats = get_repeating_pattern(what) + + if repeats > 1 and repeats == what - 1: + return 1 + + return 0 + + +def generate_long_primes(): + """ Generate the primes for the challenge """ + + primes_count = 0 + at_prime = 0 + + result = [] + + while primes_count < 5: + at_prime = nextprime(at_prime) + + if is_long_prime(at_prime): + primes_count += 1 + result.append(at_prime) + + return result + + +assert get_repeating_pattern(7) == 6 +assert get_repeating_pattern(17) == 16 + +assert is_long_prime(7) == 1 +assert is_long_prime(17) == 1 +assert is_long_prime(2) == 0 +assert generate_long_primes() == [7, 17, 19, 23, 29] |
