Ad
Code
Diff
  • code = 'lambda code: int(len(code))*3+7'
    return_hundred = lambda n: eval(code)(code)
    
    • def return_hundred(n):
    • return (n/2)*2
    • code = 'lambda code: int(len(code))*3+7'
    • return_hundred = lambda n: eval(code)(code)
Code
Diff
  • class NonPositiveArgumentError(ValueError):
        pass
    
    class WrongArgumentsOrderError(ValueError):
        pass
    
    class Compute:
        def get_factorial(self, n: int) -> int:
            if not isinstance(n, int):
                raise TypeError(f"n must be of type int, not {type(n)}.")
            if n < 0:
                raise NonPositiveArgumentError
            res = 1
            for i in range(1, n+1):
                res *= i
            return res
    
        def get_combination(self, k: int, n: int) -> int:
            if not isinstance(k, int):
                raise TypeError(f"k must be of type int, not {type(k)}.")
            if not isinstance(n, int):
                raise TypeError(f"n must be of type int, not {type(k)}.")
            if k <= 0:
                raise NonPositiveArgumentError("k must be positive.")
            if n <= 0:
                raise NonPositiveArgumentError("n must be positive.")
            if n < k:
                raise WrongArgumentsOrderError("n must be greater than or equal to k.")
            return self.get_factorial(n) / (self.get_factorial(n - k) * self.get_factorial(k))
        
    
    • class NonPositiveArgumentError(Exception):
    • class NonPositiveArgumentError(ValueError):
    • pass
    • class WrongArgumentsOrderError(Exception):
    • class WrongArgumentsOrderError(ValueError):
    • pass
    • class Compute:
    • def get_factorial(self, n: int) -> int:
    • if not isinstance(n, int):
    • raise TypeError(f"n must be of type int, not {type(n)}.")
    • if n < 0:
    • raise NonPositiveArgumentError
    • res = 1
    • for i in range(1, n+1):
    • res *= i
    • return res
    • def get_combination(self, k: int, n: int) -> int:
    • if not isinstance(k, int):
    • raise TypeError(f"k must be of type int, not {type(k)}.")
    • if not isinstance(n, int):
    • raise TypeError(f"n must be of type int, not {type(k)}.")
    • if k <= 0:
    • raise NonPositiveArgumentError("k must be positive.")
    • if n <= 0:
    • raise NonPositiveArgumentError("n must be positive.")
    • if n < k:
    • raise WrongArgumentsOrderError("n must be greater than or equal to k.")
    • return self.get_factorial(n) / (self.get_factorial(n - k) * self.get_factorial(k))
Code
Diff
  • class NonPositiveArgumentError(Exception):
        pass
    
    class WrongArgumentsOrderError(Exception):
        pass
    
    class Compute:
        def get_factorial(self, n: int) -> int:
            res = 1
            for i in range(1, n+1):
                res *= i
            return res
    
        def get_combination(self, k: int, n: int) -> int:
            if k <= 0:
                raise NonPositiveArgumentError("k must be positive.")
            if n <= 0:
                raise NonPositiveArgumentError("n must be positive.")
            if n < k:
                raise WrongArgumentsOrderError("n must be greater than or equal to k.")
            return self.get_factorial(n) / (self.get_factorial(n - k) * self.get_factorial(k))
        
    
    • from math import factorial
    • class NonPositiveArgumentError(Exception):
    • pass
    • class WrongArgumentsOrderError(Exception):
    • pass
    • def get_combination(k: int, n: int) -> int:
    • if k <= 0:
    • raise NonPositiveArgumentError("k must be positive.")
    • if n <= 0:
    • raise NonPositiveArgumentError("n must be positive.")
    • if n < k:
    • raise WrongArgumentsOrderError("n must be greater than or equal to k.")
    • return factorial(n) / (factorial(n-k)*factorial(k))
    • class Compute:
    • def get_factorial(self, n: int) -> int:
    • res = 1
    • for i in range(1, n+1):
    • res *= i
    • return res
    • def get_combination(self, k: int, n: int) -> int:
    • if k <= 0:
    • raise NonPositiveArgumentError("k must be positive.")
    • if n <= 0:
    • raise NonPositiveArgumentError("n must be positive.")
    • if n < k:
    • raise WrongArgumentsOrderError("n must be greater than or equal to k.")
    • return self.get_factorial(n) / (self.get_factorial(n - k) * self.get_factorial(k))
Code
Diff
  • from math import factorial
    
    class NonPositiveArgumentError(Exception):
        pass
    
    class WrongArgumentsOrderError(Exception):
        pass
    
    def get_combination(k: int, n: int) -> int:
        if k <= 0:
            raise NonPositiveArgumentError("k must be positive.")
        if n <= 0:
            raise NonPositiveArgumentError("n must be positive.")
        if n < k:
            raise WrongArgumentsOrderError("n must be greater than or equal to k.")
        return factorial(n) / (factorial(n-k)*factorial(k))
    • from math import factorial
    • class NonPositiveArgumentError(Exception):
    • pass
    • class WrongArgumentsOrderError(Exception):
    • pass
    • def get_combination(k: int, n: int) -> int:
    • if k <= 0 or n <= 0:
    • return "n and k must be positive."
    • if k <= 0:
    • raise NonPositiveArgumentError("k must be positive.")
    • if n <= 0:
    • raise NonPositiveArgumentError("n must be positive.")
    • if n < k:
    • return "n must be greater than or equal to k."
    • return factorial(n) / (factorial(n-k)*factorial(k))
    • raise WrongArgumentsOrderError("n must be greater than or equal to k.")
    • return factorial(n) / (factorial(n-k)*factorial(k))
Code
Diff
  • from math import factorial
    
    def get_combination(k: int, n: int) -> int:
        if k <= 0 or n <= 0:
            return "n and k must be positive."
        if n < k:
            return "n must be greater than or equal to k."
        return factorial(n) / (factorial(n-k)*factorial(k))  
    • def get_combination(k, n):
    • def fact(x):
    • res = 1
    • for i in range(1,x+1): res*=i
    • return res
    • from math import factorial
    • def get_combination(k: int, n: int) -> int:
    • if k <= 0 or n <= 0:
    • return "n and k must be positive."
    • if n < k:
    • return "n must be greater than or equal to k."
    • return fact(n) / (fact(n-k)*fact(k))
    • return factorial(n) / (factorial(n-k)*factorial(k))
Code
Diff
  • s=sorted
    is_anagram=lambda a,b:s(a)==s(b)
    
    • def is_anagram(str1, str2):
    • return sorted(str1) == sorted(str2)
    • s=sorted
    • is_anagram=lambda a,b:s(a)==s(b)
Code
Diff
  • s=sorted;is_anagram=lambda a,b:s(map(ord,a))==s(map(ord,b))
      
    • def is_anagram(s1, s2):
    • return sum(map(ord, s1)) == sum( map(ord, s2)) and sorted(map(ord, s1)) == sorted( map(ord, s2)) and len(s1) == len(s2)
    • s=sorted;is_anagram=lambda a,b:s(map(ord,a))==s(map(ord,b))
Code
Diff
  • def is_anagram(s1, s2):
        n1 = map(ord, s1)
        n2 = map(ord, s2)
        return sum(n1) == sum(n2) and sorted(n1) == sorted(n2) and len(s1) == len(s2)
      
    • def is_anagram(s1, s2):
    • n1 = [ord(i) for i in s1]
    • n2 = [ord(i) for i in s2]
    • n1 = map(ord, s1)
    • n2 = map(ord, s2)
    • return sum(n1) == sum(n2) and sorted(n1) == sorted(n2) and len(s1) == len(s2)