### Calculate factorial

Code
Diff
• ``from math import factorial``
• from math import factorial as code
• def factorial(wars):
• return code(wars)
• from math import factorial

### Power of a number

Code
Diff
• ``from operator import pow as power``
• power = lambda n, p: pow(n, p)
• from operator import pow as power

### yas

Code
Diff
• ``from operator import add as add_numbers``
• add_numbers = lambda a, b: a + b

### Prime Checker [Optimized]

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

### Prime Checker [Optimized]

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