def to_num(code, word): result = 0 for c in word: d = code[c] result *= 10 result += d if len(word) != lib.num_digits(result): # leading digits cannot be 0 return 0 return result
def rotate(n): cnt = lib.num_digits(n) result = [n] for i in range(cnt-1): d = n % 10 n = int(n /10) n += d * 10**(cnt-1) result.append(n) return result
def get_candidates(n, filtr): i = 0 result = [] while lib.num_digits(i) < 4: i += n d = digits(i) if len(d) == 2: d.insert(0,0) if len(d) == 3 and nodups(d) and filtr(d): result.append(d) return result
#!/usr/bin/env python3 import lib n=1 d=1 i=0 N=1000 count = 0 while i < N+1: #print(i,str(n)+'/'+str(d),n/d) if (lib.num_digits(n) >lib.num_digits(d)): count += 1 #term' = 1 + 1/(1+term) n+= d #1 + term n,d=d,n #1/(1+term) n+= d #1+1/(1+term) i+=1 print(count)
cnt = {} for d in lib.to_digits(n): if d in cnt: cnt[d] += 1 else: cnt[d] = 1 return (0 in cnt and cnt[0] == 3) or \ (1 in cnt and cnt[1] == 3) or \ (2 in cnt and cnt[2] == 3) for p in range(S, N, 2): if not sieve[p]: continue if not has_dups(p): continue ln = lib.num_digits(p) for i in range(ln - 1): for j in range(i + 1, ln): for k in range(j + 1, ln): terms = [] d = 0 while d < 10: t = lib.set_digit(p, i, d) t = lib.set_digit(t, j, d) t = lib.set_digit(t, k, d) if sieve[t] and t >= p: terms.append(t) if 9 - d < F - len(terms): break d += 1 if len(terms) >= F:
def has_dups(n, digits=None): if n == 0: return True if digits is None: digits = {} while n: d = n % 10 n = int(n / 10) if d in digits: return True digits[d] = 1 return False products = {} for i in range(1, 100): # 1-2 digits if not has_dups(i): if i < 10: rng = range(1000, 100_000) # 3-5 digits else: rng = range(100, 1000) # 2-3 digits for j in rng: p = i * j if eligible(i, j, p): print(p, i, j) products[p] = 1 if lib.num_digits(p) + lib.num_digits(i) + lib.num_digits(j) > 9: break print(sum(products.keys()))
pairs = [] mx = 0 for k in d: val = d[k] if len(val) > 1: pairs.append(val) pairs = sorted(pairs, key=lambda a: len(a[0])) pairs.reverse() MX = 10**9 # longest word has 9 chars squares = defaultdict(list) i = 1 while i**2 < MX: sq = i**2 squares[lib.num_digits(sq)].append(sq) i += 1 def assign(num, word): code = {} for c, d in zip(word, lib.to_digits(num)): if c in code and code[c] != d: return None if d in code.values(): return None # d already mapped to a char code[c] = d return code def to_num(code, word):
#!/usr/bin/env python3 import lib count = 0 for pw in range(1, 100): i = 1 ln = 0 while ln < pw + 1: ln = lib.num_digits(i**pw) if ln == pw: print(i, '^', pw, i**pw) count += 1 i += 1 print(count)