Mathematics
Algorithms
Numbers
Code
Diff
  • """
    Simple and fast, around 2-3ms
    """
    # One line removed, one is edited with wit but actually works, you really should git gud < idk >
    def prime_checker(n):
        for i in range(3, int(n**.5)+1 if n > 0 else 10, 2):
            if n%i == 0: return False
        return (n > 2 and n%2 != 0) or n == 2
    
  • 11
    """
    
    22
    Simple and fast, around 2-3ms
    
    33
    """
    
    4
    # One line removed, one is added with wit, you really should git gud < Haiku >
    
    4+
    # One line removed, one is edited with wit but actually works, you really should git gud < idk >
    
    55
    def prime_checker(n):
    
    6
        if n == 2 and n%2 != 0 and n > 2: return True
    
    7
        for i in range(3, int(n**.5)+1, 2):
    
    6+
        for i in range(3, int(n**.5)+1 if n > 0 else 10, 2):
    
    88
            if n%i == 0: return False
    
    9
        return True
    
    8+
        return (n > 2 and n%2 != 0) or n == 2
    
Mathematics
Algorithms
Numbers
Code
Diff
  • """
    Simple and fast, around 2-3ms
    """
    def prime_checker(n):
        if n == 2: return True
        if n%2 == 0 or n < 2: return False
        for i in range(3, int(n**.5)+1, 2):
            if n%i == 0: return False
        return True
    
  • 11
    """
    
    2
    https://en.wikipedia.org/wiki/Primality_test
    
    3
    An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3
    
    4
    -- Using generator instead of list (works faster)
    
    5
    -- range(0, 30 * sqrt_n + 1, 30) instead of (30 * k for k in range(sqrt_n + 1))
    
    2+
    Simple and fast, around 2-3ms
    
    66
    """
    
    77
    def prime_checker(n):
    
    8
        if n in [2, 3, 5]:
    
    9
            return True
    
    10
        elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n <= 1:
    
    11
            return False
    
    12
        
    
    5+
        if n == 2: return True
    
    6+
        if n%2 == 0 or n < 2: return False
    
    7+
        for i in range(3, int(n**.5)+1, 2):
    
    8+
            if n%i == 0: return False
    
    1919
        return True
    
Code
Diff
  • digit_sum = lambda n: sum(map(int, str(abs(n))))
  • 1
    def digit_sum(n: int) -> int:
    
    2
        return sum(map(int, str(abs(n))))
    
    1+
    digit_sum = lambda n: sum(map(int, str(abs(n))))