Ad
Code
Diff
  • from math import factorial
    • from math import factorial as code
    • def factorial(wars):
    • return code(wars)
    • from math import factorial
Code
Diff
  • from operator import pow as power
    • power = lambda n, p: pow(n, p)
    • from operator import pow as power
Code
Diff
  • from operator import add as add_numbers
    • add_numbers = lambda a, b: a + b
    • from operator import add as add_numbers
Mathematics
Algorithms
Logic
Numbers
Code
Diff
  • from gmpy2 import is_prime as prime_checker
    • import re
    • def prime_checker(n):
    • return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None
    • from gmpy2 import is_prime as prime_checker
Mathematics
Algorithms
Logic
Numbers

Fun with regexp

Code
Diff
  • import re
    def prime_checker(n):
        return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None
    • from math import sqrt
    • primes = [2]
    • import re
    • def prime_checker(n):
    • global primes
    • for p in primes:
    • if n == p:
    • return True
    • if n % p == 0:
    • return False
    • for c in range((l := primes[-1]) + l % 2 + 1, int(sqrt(n)), 2):
    • if prime_checker(c):
    • primes.append(c)
    • if n % c == 0:
    • return False
    • return True
    • return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None