Пример #1
0
def main(verbose=False):
    result = []
    # We have at most 7 digits, so we consider all ascending
    # lists of digits with a digit sum between 1 and 63.
    # Since ascending requires the first element of the digit lists
    # is *equal to* the minimum, we allow an 8th digit which is
    # simply a padded zero
    for digit_sum in range(1, 63 + 1):
        for choice in ascending(8, digit_sum, 0, 9):
            choice = choice[1:]
            non_zero = [digit for digit in choice if digit != 0]
            factorial_sum = sum(factorial(digit) for digit in non_zero)
            possible_zeros = 7 - len(non_zero)

            # Can fill out the number with zeros (up to 7 digits)
            for zeros_add in range(possible_zeros + 1):
                factorial_digits = [int(digit) for digit in str(factorial_sum)]
                if (sorted(factorial_digits) ==
                        sorted(non_zero + [0] * zeros_add)):
                    result.append(factorial_sum)

                factorial_sum += 1  # Add factorial(0)

    result = [val for val in result if val not in [1, 2]]

    if verbose:
        return "%s.\nThe full list of numbers is as follows: %s." % (
            sum(result), ", ".join(str(number) for number in result))
    else:
        return sum(result)
Пример #2
0
def dice_outcomes(num_dice, num_sides):
    result = {}
    for bottom in range(1, num_sides + 1):
        for dice_sum in range(1 * num_dice, num_sides * num_dice + 1):
            for outcome in ascending(num_dice, dice_sum, bottom, num_sides):
                curr_sum = sum(outcome)
                # if curr_sum is not in result, sets to total_perms(outcome)
                # (default 0 returned by get)
                result[curr_sum] = (result.get(curr_sum, 0) +
                                    total_perms(outcome))
    return result
Пример #3
0
def main(verbose=False):
    MATCHES = []
    for bottom in range(1, 12 + 1):
        MATCHES.extend(ascending(10, 70, bottom, 12))

    add_ons = {}
    for biggest in range(1, 8):
        add_ons[biggest] = generate_addons(10, 1, biggest)

    count = 0
    for match in MATCHES:
        bottom = match[0]
        for addon in add_ons[bottom]:
            curr = addon + match
            count += total_perms(curr)
    return count