Beispiel #1
0
def ok(n,ph):
  ndigits = lib.to_digits(n)
  phdigits = lib.to_digits(ph)
  if len(ndigits) != len(phdigits):
    return False
  ndigits.sort()
  phdigits.sort()
  return ndigits == phdigits
Beispiel #2
0
def key(n):
    l = lib.to_digits(n)
    l.sort()
    i = 0
    while l[0] == 0:
        l.pop(0)
        l.append(0)
    return lib.to_num(l)
Beispiel #3
0
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
Beispiel #4
0
def has_dups(n):
    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)
Beispiel #5
0
def check(i):
    if not sieve[i]:
        return
    if i in _memo:
        return
    perms = set(map(lib.to_num, lib.permutations(lib.to_digits(i))))

    pperms = []
    for perm in perms:
        if sieve[perm] and perm >= 1000:
            pperms.append(perm)
        _memo[perm] = True

    if len(pperms) < 3:
        return
    pperms.sort()

    for i in range(len(pperms)):
        for j in range(i + 1, len(pperms)):
            a, b = pperms[i], pperms[j]
            diff = b - a
            c = b + diff
            if c in pperms:
                print("".join(map(str, [a, b, c])))
Beispiel #6
0
#!/usr/bin/env python3
import lib
N = 10


def get_e_continued_fraction(n):
    """ Return the first n digits of the continued fraction of e."""
    if not n:
        return []
    result = [2]  # First digit
    n -= 1
    k = 1
    # Pattern is 1,2k,1...
    for i in range(n):
        if i % 3 == 1:
            result.append(k * 2)
            k += 1
        else:
            result.append(1)
    return result


count = 0
for i in range(1, N + 1):
    n, d = lib.eval_continued_fraction(get_e_continued_fraction(i))
    print(i, lib.fraction_tostr(n, d))

n, d = lib.eval_continued_fraction(get_e_continued_fraction(100))
print(sum(lib.to_digits(n)))
Beispiel #7
0
#!/usr/bin/env python3
import lib
N = 100

mx = 0
for i in range(1, 100):
    for j in range(1, 100):
        sm = sum(lib.to_digits(i**j))
        mx = max(sm, mx)

print(mx)
Beispiel #8
0
#!/usr/bin/env python3
import lib
N = 1000000

i = 1
for i in range(1, N):
    target = lib.to_digits(i)
    target.sort()
    ok = True
    for j in range(2, 6):
        m = lib.to_digits(i * j)
        m.sort()
        ok &= m == target
    if ok:
        print(i)
        break