def find_arithmetic(list_): if len(list_) < 3: raise ValueError("List wrong size.") candidates = all_subsets(list_, 3) for cand in candidates: if cand[0] + cand[2] == 2 * cand[1]: return cand return []
def main(verbose=False): dice = all_subsets(range(10), 6) size = len(dice) for i in range(size): if 6 in dice[i] and 9 not in dice[i]: dice[i].append(9) if 9 in dice[i] and 6 not in dice[i]: dice[i].append(6) count = 0 candidates = [str(n ** 2).zfill(2) for n in range(1, 10)] for left_ind in range(size - 1): for right_ind in range(left_ind, size): if can_concat(dice[left_ind], dice[right_ind], candidates): count += 1 return count
def main(verbose=False): SIGNS = [operator.add, operator.sub, operator.mul, operator.div] SIGN_CANDS = [] for sign1 in SIGNS: for sign2 in SIGNS: for sign3 in SIGNS: SIGN_CANDS.append([sign1, sign2, sign3]) special_range = [n*1.0 for n in range(1, 10)] DIG_CANDS = all_subsets(special_range, 4) max_tuple = None max_val = 0 for dig_cand in DIG_CANDS: length = most_consecutive(dig_cand, SIGN_CANDS) if length > max_val: max_val = length max_tuple = dig_cand return ''.join(str(int(n)) for n in max_tuple)
def all_choices(n): result = [] number_digit_sums = (n + 1) / 2 candidates = [(">=10", 1), (">=10", 0), ("<10", 1), ("<10", 0)] for subset in all_subsets(candidates, number_digit_sums, unique=False): if n % 2 == 1: even_index = (n + 1) / 2 signature = subset[even_index - 1] # parity if signature[1] == 1: continue to_add = {} for k in range(1, n + 1): digit_sum_index = min(k, n + 1 - k) to_add[k] = subset[digit_sum_index - 1] result.append(to_add) return result