def trunc_number(n, i, j): l = [] while j >= i: s = mtools.separate_digits(n) m = int(mtools.combine_digits(s[:i])) r = int(mtools.combine_digits(s[i:])) if r > m: l.append((m, r)) i += 1 return l
def count(): l = range(1,10) cnt = 0 sets = [] for np in mtools.dict_perm(l): if np[-1] in [2,4,5,6,8]: continue n = mtools.combine_digits(np) c, s = count_partition(n) cnt += c if c > 0: for e in s: sets.append(e) #output all valid sets and #make sure no duplicates d = {} for s in sets: h = hashable(s) try: if d[h]: print h return 'Duplicated.' except KeyError: print h d[h] = True return cnt
def M(n, d): i = 1 while i < n: pns = possible_nums(n, d, i) for ns in pns: ns.sort() for num in mtools.dict_perm(ns): if num[0] == 0: continue inum = mtools.combine_digits(num) if mtools.is_prime(inum): return n - i i += 1
def S(n, d): i = 1 prime_found = False primes_sum = 0 checked = {} while i < n and not prime_found: pns = possible_nums(n, d, i) for ns in pns: ns.sort() for num in mtools.dict_perm(ns): if num[0] == 0: continue inum = mtools.combine_digits(num) try: if checked[inum]: continue except KeyError: checked[inum] = True if mtools.is_prime(inum): prime_found = True primes_sum += inum i += 1 return primes_sum