Exemplo n.º 1
0
def unique_digits(n):
    """Returns the unique digits of n as a set, or None if any digits are repeated."""
    d = split_digits(n)
    s = set(d)

    if len(d) == len(s):
        return s
Exemplo n.º 2
0
def rotations(n):
    d = deque(split_digits(n))
    result = []

    for i in range(len(d)):
        result.append(join_digits(d))
        d.rotate()

    return result
Exemplo n.º 3
0
def solve(limit, digits):
    result = 0

    for n in range(limit + 1):
        root = decimal.Decimal(n).sqrt()

        if not float(root).is_integer():
            result += sum(split_digits(root)[:digits])

    return result
Exemplo n.º 4
0
def next_number(n):
    """Returns the next number in the number chain

    >>> next_number(44)
    32

    >>> next_number(89)
    145
    """
    return sum(map(lambda d: d**2, split_digits(n)))
Exemplo n.º 5
0
def solve(number, window_size):
    """
    >>> solve(NUMBER, 4)
    5832
    """
    digits = split_digits(number)
    greatest_product = 0

    for window in gen_window(digits, window_size):
        greatest_product = max(greatest_product, prod(window))

    return greatest_product
Exemplo n.º 6
0
def truncations(n):
    """
    Returns all possible truncations of n.

    >>> truncations(3797)
    {97, 3, 37, 7, 3797, 379, 797}
    """
    d = split_digits(n)
    result = set([n])

    for i in range(1, len(d)):
        result.add(join_digits(d[i:]))
        result.add(join_digits(d[:i]))

    return result
Exemplo n.º 7
0
def digit_factorial(n):
    return sum(map(factorial, split_digits(n)))
Exemplo n.º 8
0
from itertools import count
from common.digits import split_digits

for i in count(1):
    if set(split_digits(i)) == \
            set(split_digits(i * 2)) == \
            set(split_digits(i * 3)) == \
            set(split_digits(i * 4)) == \
            set(split_digits(i * 5)) == \
            set(split_digits(i * 6)):

        print(i)
        break
Exemplo n.º 9
0
def reverse_digits(n):
    """
    >>> reverse_digits(1292)
    2921
    """
    return join_digits(reversed(split_digits(n)))
Exemplo n.º 10
0
def gen_champernownes_decimals():
    for i in count(1):
        for d in split_digits(i):
            yield d
Exemplo n.º 11
0
def sum_of_digits_raised(n, power):
    return sum([x**power for x in split_digits(n)])
Exemplo n.º 12
0
def is_pandigital(n):
    return PANDIGITAL == Counter(split_digits(n))