def find_candidates(): candidates_without_zero = permutations([1, 2, 3, 4, 5, 6, 7, 8, 9]) candidates_without_five = permutations([0, 1, 2, 3, 4, 6, 7, 8, 9]) for candidate in candidates_without_zero: if candidate[3] % 2 == 0: yield candidate[0:5] + (0,) + candidate[5:] for candidate in candidates_without_five: if candidate[0] != 0 and candidate[3] % 2 == 0: yield candidate[0:5] + (5,) + candidate[5:]
def _find_all_cyclical(values): res = [] tail_idx_perms = permutations(range(1, len(values))) for idx_perm in tail_idx_perms: tail = [values[i] for i in idx_perm] head = values[0] for value in head: res += _find_cyclical(str(value)[-2:], tail + [[value]]) return res
def lexicographic_permutations(symbols): _permutations = permutations(symbols) joined_permutations = [reduce(lambda x, y: x + str(y), permutation, '') for permutation in _permutations] return sorted(joined_permutations)
def generate_keys(key_length): res = [] for symbols in pick_from(ALPHABET, key_length): res += map(lambda perm: reduce(add, perm), permutations(symbols)) return res