imk0tter

FACTORIAL MATH

Jul 27th, 2023 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. from random import randint
  2.  
  3. def INFINITY_UNIQUE_NUMBER_SERIES(x, *args):
  4.     if (len(args) > 0): return INFINITY_UNIQUE_NUMBER_SERIES((x * 2 - 1) * (2 ** args[0]), *args[1:])
  5.     return x
  6.  
  7.  
  8. def FACTORIAL(x):
  9.     result = 1
  10.     for i in range(0, x):
  11.         result = result * (i + 1)
  12.     return result
  13.  
  14. def FACTORIAL_BASE(x):
  15.     results = []
  16.     radix = 1
  17.     while x > 0:
  18.         current = x % radix
  19.         results = [int(current)] + results
  20.         x = (x - current) / radix
  21.         radix += 1
  22.     return results
  23.  
  24. def DECIMAL_TO_PERMUTATION(decimal, factorial_list, factorial_list_count = 0):
  25.     if (factorial_list_count == 0):
  26.         factorial_list_count = len(factorial_list)
  27.     current_permutation = FACTORIAL_BASE(decimal)
  28.     new_factorial_list = factorial_list.copy()
  29.  
  30.     permutation = []
  31.     permutation2 = []
  32.     for i in range(0, len(new_factorial_list) - len(current_permutation) - 0):
  33.         permutation2 = permutation2 + [new_factorial_list.pop(0)]
  34.     for element in current_permutation:
  35.         current_factorial = new_factorial_list.pop(element)
  36.         permutation = permutation + [current_factorial]
  37.     while len(new_factorial_list) > 0:
  38.         permutation2 = permutation2 + [new_factorial_list.pop(0)]
  39.     return permutation2, permutation, current_permutation
  40.  
  41. def FACTORIAL_BASE_TO_DECIMAL(factorial_base, padding = 0):
  42.     current_radix = len(factorial_base) - 1
  43.     decimal = 0
  44.     for current_number in factorial_base:
  45.         decimal = current_number * FACTORIAL(current_radix) + decimal
  46.         current_radix = current_radix - 1
  47.     return decimal
  48.  
  49. def PERMUTATION_TO_FACTORIAL_BASE(current_business_slot_list, static_business_slot_list):
  50.     current_static_business_slot_list = static_business_slot_list.copy()
  51.     factorial_base = []
  52.  
  53.     while len(current_static_business_slot_list) > len(current_business_slot_list):
  54.         current_static_business_slot_list.pop(0)
  55.  
  56.     for current_business_slot in current_business_slot_list:
  57.         current_index = current_static_business_slot_list.index(current_business_slot)
  58.         current_static_business_slot_list.pop(current_index)
  59.         factorial_base = factorial_base + [current_index]
  60.     return factorial_base
  61.  
  62. def PERMUTATION_TO_DECIMAL(permutation, static_business_slots):
  63.     return FACTORIAL_BASE_TO_DECIMAL(PERMUTATION_TO_FACTORIAL_BASE(permutation, static_business_slots))
  64.  
  65.  
  66. def PERMUTATION_MAX(slots):
  67.     return FACTORIAL(slots)
  68.  
  69. # EXAMPLE:
  70. #business_slots = ["MATH", "SCIENCE", "WAR", "ART", "PSYCHOLOGY", "BIOLOGY", "ELECTRICITY", "BUSINESS", "RELIGION", "MARTIAL ART", "MARTIAL WAR", "PRODUCTION"]
  71.  
  72. business_slots = ["PRODUCTION", "MARTIAL WAR", "MARTIAL ART", "RELIGION", "BUSINESS", "ELECTRICITY", "BIOLOGY", "PSYCHOLOGY", "ART", "WAR", "SCIENCE", "MATH"]
  73.  
  74. for permutation_number in range(0, PERMUTATION_MAX(6)):
  75.     permutation = DECIMAL_TO_PERMUTATION(permutation_number, business_slots)
  76.     print("CURRENT_ITERATION: " + str(permutation_number) + ", " + str(permutation))
  77.     print("DECIMAL: " + str(PERMUTATION_TO_DECIMAL(permutation[1], business_slots)))
  78.     print("\n")
  79.  
  80. print(str(PERMUTATION_TO_DECIMAL(["MATH", "WAR", "SCIENCE", "PSYCHOLOGY", "ART"], business_slots)))
  81. print(str(DECIMAL_TO_PERMUTATION(112, business_slots)))
Add Comment
Please, Sign In to add comment