Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env/ python
- # -*-coding: utf-8-*-
- import sys
- def constant(function):
- def wrapper(x):
- if x == 1:
- return [0,1]
- return wrapper
- def factorial(x):
- if type(x) == int and x >= 0:
- result = lambda x: result(x-1) * x if x > 0 else 1
- return result(x)
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- @constant
- def antifactorial(x):
- if type(x) == int and x >= 0:
- for each in range(1, sys.getrecursionlimit()+1):
- x = float(x)/float(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a factorial"
- else:
- return each
- break
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- def superfactorial(x):
- if type(x) == int and x >= 0:
- result = lambda x: result(x-1) * factorial(x) if x > 0 else 1
- return result(x)
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- @constant
- def antisuperfactorial(x):
- if type(x) == int and x >= 0:
- for each in range(1, sys.getrecursionlimit()+1):
- x = float(x)/factorial(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a superfactorial"
- else:
- return each
- break
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- def hyperfactorial(x):
- if type(x) == int and x >= 0:
- result = lambda x: result(x-1) * superfactorial(x) if x > 0 else 1
- return result(x)
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- @constant
- def antihyperfactorial(x):
- if type(x) == int and x >= 0:
- for each in range(1, sys.getrecursionlimit()+1):
- x = float(x)/superfactorial(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a hyperfactorial"
- else:
- return each
- break
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- def doublefactorial(x):
- if type(x) == int and x >= 0:
- result = lambda x: result(x-2) * x if x > 0 else 1
- return result(x)
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- @constant
- def antiDoubleFactorial(x):
- if type(x) == int and x >= 0:
- if x % 2 == 0:
- for each in [z for z in range(2, sys.getrecursionlimit()) if z % 2 == 0]:
- x = float(x)/float(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a factorial"
- else:
- return each
- break
- else:
- for each in [z for z in range(1, sys.getrecursionlimit()) if z % 2 != 0]:
- x = float(x)/float(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a factorial"
- else:
- return each
- break
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative"
- def isPrime(x):
- if type(x) == int and x >= 0:
- if x == 0 or x == 1:
- return False
- for each in range(2,x+1):
- if x % each == 0 and x != each:
- return False
- break
- elif x % each == 0 and x == each:
- return True
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative")
- def primorial(x):
- if type(x) == int and x >= 0:
- primes = 1
- for each in range(2, x+1):
- if isPrime(each) == True:
- primes *= each
- return primes
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative"
- @constant
- def antiprimorial(x):
- if type(x) == int and x >= 0:
- for each in range(2,sys.getrecursionlimit()):
- if isPrime(each) == True:
- x = float(x)/float(each)
- if x != 1.0 and x > 1.0:
- continue
- elif x != 1.0 and x < 1.0:
- raise ValueError,"The given value is not a primorial"
- else:
- values = [each]
- for var in range(1,sys.getrecursionlimit()):
- if isPrime(each+var) == False:
- values.append(each+var)
- continue
- else:
- return values
- break
- break
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative"
- def isFactorion(x):
- if type(x) == int and x >= 0:
- factorion = 0
- number = tuple(str(x))
- for each in number:
- factorion +=factorial(int(each))
- if factorion == x:
- return True
- else:
- return False
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative"
- def isKFactorion(x,k):
- if type(x) == int and x >= 0:
- factorion = 0
- number = tuple(str(x))
- for each in number:
- factorion += factorial(int(each))
- if x == factorion * k:
- return True
- else:
- return False
- else:
- raise TypeError, "The given value must be positive integer, not %s"%(type(x) if type(x) != int else "negative"
- def sequense(function, valueFrom = 0, valueTo = 1):
- return [function(x) for x in range(valueFrom, valueTo+1)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement