Ad
Code
Diff
  • add_arr=sum
    • add_arr = lambda foo: sum(foo)
    • add_arr=sum
Code
Diff
  • from calendar import isleap as isleap_year
    • from calendar import isleap as quadrennial
    • def isleap_year(year):
    • return quadrennial(year)
    • from calendar import isleap as isleap_year

Made so it works with large numbers too, and gave a little refactore

Code
Diff
  • def get_combination(k, n):
        def m(r):l=len(r);return r[0]if l==1else 1if l==0else m(r[:l//2])*m(r[(l//2):])
        def f(x):return 1 if x in(0,1)else m(list(range(1, x+1)))
        if(k,n)<=(0,0):return"n and k must be positive."
        if n<k:return"n must be greater than or equal to k."
        return f(n)/(f(n-k)*f(k))
    • def get_combination(k, n):
    • def get_factorial(x):
    • if x <= 0:return None
    • if x <= 1:return 1
    • return x * get_factorial(x-1)
    • 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."
    • else:
    • combination = get_factorial(n) / (get_factorial(n-k)*get_factorial(k))
    • return combination
    • def m(r):l=len(r);return r[0]if l==1else 1if l==0else m(r[:l//2])*m(r[(l//2):])
    • def f(x):return 1 if x in(0,1)else m(list(range(1, x+1)))
    • if(k,n)<=(0,0):return"n and k must be positive."
    • if n<k:return"n must be greater than or equal to k."
    • return f(n)/(f(n-k)*f(k))