def do_factor_stuff(n_old, recursion=0): i = 0 if n_old > 10**8: return print("n_old: {}".format(n_old)) if not n_old in n_map: n_map[n_old] = [] factors = list(primefac.primefac(n_old)) if len(factors) == 1: n_new = factors[0] print("finished here!") if not n_new in p_map: p_map[n_new] = 0 return else: permutation_table = get_permutation_table(len(factors)) # permutation_table = get_permutation_table(len(factors))[:3] factors_arr_str = np.array(list(map(str, factors))) lst = n_map[n_old] for row in permutation_table: n_new = int("".join(factors_arr_str[row])) if not n_new in lst: lst.append(n_new) if not n_new in n_map and recursion < 21: do_factor_stuff(n_new, recursion + 1)
def get_max_cycles_length_for_permutation(n): arr = get_permutation_table(n, same_pos=False) max_cycles = 0 cycles_lengths = [] row_orig = np.arange(0, n) for row in arr: row_i = row_orig.copy() is_full_one_cycle = True i = 1 row_i = row_i[row] while not np.all(row_i == row_orig): row_i = row_i[row] i += 1 if max_cycles < i: max_cycles = i cycles_lengths.append(i) return max_cycles
import sys import matplotlib.pyplot as plt import numpy as np from math import factorial as fac sys.path.append("../combinatorics/") from different_combinations import get_permutation_table PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) + "/" if __name__ == '__main__': n = 5 arr_pt = get_permutation_table(n) print("arr_pt.shape:\n{}".format(arr_pt.shape)) # print('Hello World!') d_stat = {} for row1 in arr_pt: a1 = row1.copy() for row2 in arr_pt: a2 = row2.copy() t = tuple(a1.tolist()) + tuple(a2.tolist()) l = [t] while True: a3 = a1[a2].copy() a1 = a2
# idx2 = np.array([4, 0, 1, 2, 3]) # idx3 = np.array([2, 0, 1, 3, 4]) # idxs_tbl = np.vstack((idx1, idx2, idx3)) # # idxs_tbl = np.vstack((idx1, idx2)) # amount_functions = idxs_tbl.shape[0] # print("amount_functions: {}".format(amount_functions)) # arr1 = arr[idx1] # arr2 = arr[idx2] # print("arr1: {}".format(arr1)) # print("arr2: {}".format(arr2)) # print("arr1.dtype: {}".format(arr1.dtype)) # print("arr2.dtype: {}".format(arr2.dtype)) perm_tbl = get_permutation_table(n) l_t_perm_tbl = list(map(tuple, perm_tbl.tolist())) s_t_perm_tbl = set(l_t_perm_tbl) d_from_to_mapping = dict( list( map(lambda x: (x[0], list(map(tuple, x[1]))), zip(l_t_perm_tbl, perm_tbl[:, idxs_tbl].tolist())))) # print("d_from_to_mapping: {}".format(d_from_to_mapping)) d_to_from_mapping = dict( list( map( lambda x: (x[0], list(map(tuple, x[1]))), zip(l_t_perm_tbl, perm_tbl[:, np.argsort(idxs_tbl, axis=1)].tolist()))))
m_amount = int(m_amount_str) # n = 4 arr_1d = np.arange(0, n) multiply_mask = n**np.arange(0, n) # print("multiply_mask: {}".format(multiply_mask)) # sys.exit(-1) print("arr_1d: {}".format(arr_1d)) # standard for rotating is 3 places/numbers! # m_amount = 2 idx = np.arange(0, m_amount) # rolls = [np.roll(idx, i) for i in range(1, m_amount)] rolls = different_combinations.get_permutation_table(m_amount, same_pos=False) print("rolls.shape: {}".format(rolls.shape)) rotation_idxs = [] # rotation_idxs = {} for j in range(0, n + 1 - m_amount): for i in range(0, len(rolls)): rotation_idxs.append((j + 1, i + 1)) print("len(rotation_idxs): {}".format(len(rotation_idxs))) # moves = list(rotation_idxs.keys()) # moves = list(rotation_idxs.keys()) moves = list(rotation_idxs) print("len(moves): {}".format(len(moves)))
for j in range(0, len_idxs_ident - 1): idxs_roll = np.argsort(sbox1_prev_part[j:j + len_idxs_ident]) if np.any(idxs_roll == idxs_ident_ident): continue sbox[idxs_ident] = sbox[idxs_ident[idxs_roll]] return sbox sbox[idxs_ident] = sbox[np.roll(idxs_ident, 1)] return sbox if __name__ == '__main__': n = 5 sbox_ident = np.arange(0, n) perm_tbl = get_permutation_table(n, is_same_pos=False) s_t_cycles = set() s_t_cycles_tpl = set() s_t_no_cylces = set() for perm in perm_tbl: for perm_prev in perm_tbl: sbox1 = perm_prev.copy() sbox2 = perm.copy() t = (tuple(sbox1.tolist()), tuple(sbox2.tolist())) if t in s_t_no_cylces or t in s_t_cycles: continue l_perms = [t] s_perms = set() is_finished_earlier = False
PATH_ROOT_DIR = os.path.abspath(os.path.dirname(sys.argv[0])) + "/" if __name__ == "__main__": m = 5 a, b = np.random.randint(0, m, (2, )) l = [] for x in range(0, m): l.append(a + b * x + x) sys.exit(0) n = 2 print("n: {}".format(n)) xs = np.arange(0, n) choosen_fs_base = get_permutation_table(n)[1:] perm_parts_tbl = different_combinations.get_all_permutations_parts( choosen_fs_base.shape[0], 1) # TODO: fix this whole process with a recursion search for the smallest amount # of needed functions to create a whole loop of distinct permutations with length n! # def mix_choosen_fs(): # choosen_fs[:] = choosen_fs[np.random.permutation(np.arange(0, factorial(n)-1))] def get_perm_parts_gen(): for row in perm_parts_tbl: yield row different_working_tpls = []
from utils_math_numbers import convert_n_to_other_base, convert_base_n_to_num sys.path.append("../combinatorics/") from different_combinations import get_permutation_table PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))+"/" if __name__=='__main__': found_cyclic_numbers_in_base = {} # for n in range(3, 4): for n in range(5, 6): print("n: {}".format(n)) arr = get_permutation_table(n) for b in range(n, 1000): for row in arr: num = convert_base_n_to_num(row, b) if num > 10000 or num < 2: continue if not num in found_cyclic_numbers_in_base: found_cyclic_numbers_in_base[num] = [] found_cyclic_numbers_in_base[num].append((b, n, row.tolist()[::-1])) print("len(found_cyclic_numbers_in_base): {}".format(len(found_cyclic_numbers_in_base))) arr = np.array(sorted(found_cyclic_numbers_in_base.keys())) idxs = np.where((arr[1:]-arr[:-1])>1)[0] print("idxs: {}".format(idxs))
print("i_iter: {}".format(i_iter)) lst_amount_stacks = [] lst_max_amount_per_stack = [] lst_max_amount_stacks_count = [] lst_max_amount_stacks = [] lst_i = [] for i in range(11, n_max + 1): lst_i.append(i) # print("i: {}".format(i)) # arr = get_stacked_runways(i, i) # print("- arr: {}".format(arr)) lst_arrs_amount_stack = [] permutation_tbl = get_permutation_table(i) + 1 # for j in range(0, i**3): # for j in range(0, factorial(i)//i): for i_s in permutation_tbl: arr_perm = get_stacked_runways(i, i_s) # arr_perm = get_stacked_runways(i, i, permutate=True) lst_arrs_amount_stack.append(np.sum(arr_perm > 0)) # print("- j: {}, arr_perm: {}".format(j, arr_perm)) # print("j: {}, lst_arrs_amount_stack: {}".format(j, lst_arrs_amount_stack)) arr_arrs_amount_stacks = np.array(lst_arrs_amount_stack) max_amount_stack = np.max(arr_arrs_amount_stacks) lst_max_amount_stacks.append(max_amount_stack) lst_max_amount_stacks_count.append( np.sum(arr_arrs_amount_stacks == max_amount_stack)) print("lst_i: {}".format(lst_i)) print("lst_max_amount_stacks: {}".format(lst_max_amount_stacks))