#Project Euler Question 74
#How many chains, with a starting number below one million, contain exactly sixty non-repeating terms?

import math

def digit_factorial(x, y):
    fact_list = {0: 1, 1: 1, 2: 2, 3: 6, 4: 24, 5: 120, 6: 720, 7: 5040, 8: 40320, 9: 362880}
    term_list = set()
    num_numlength_dic = dict()
    length_check = y
    for n in range(1, x + 1):
        chain_list = {n}
        fact_n = sum(fact_list[int(i)] for i in str(n))
        while fact_n not in chain_list:
            chain_list.add(fact_n)
            if len(chain_list) > y:
                break
            if fact_n in num_numlength_dic:
                chain_list.update(num_numlength_dic[fact_n])
            fact_n = sum(fact_list[int(i)] for i in str(fact_n))
        else:
            if len(chain_list) == length_check:
                term_list.add(n)
            num_numlength_dic.update({n: chain_list})
    return len(term_list)

print (digit_factorial(1000000, 60))
bb6b545d1418604eecb7c2fc8aeb64d1e162db6a
<mask token>

<mask token>


def digit_factorial(x, y):
    fact_list = {(0): 1, (1): 1, (2): 2, (3): 6, (4): 24, (5): 120, (6): 
        720, (7): 5040, (8): 40320, (9): 362880}
    term_list = set()
    num_numlength_dic = dict()
    length_check = y
    for n in range(1, x + 1):
        chain_list = {n}
        fact_n = sum(fact_list[int(i)] for i in str(n))
        while fact_n not in chain_list:
            chain_list.add(fact_n)
            if len(chain_list) > y:
                break
            if fact_n in num_numlength_dic:
                chain_list.update(num_numlength_dic[fact_n])
            fact_n = sum(fact_list[int(i)] for i in str(fact_n))
        else:
            if len(chain_list) == length_check:
                term_list.add(n)
            num_numlength_dic.update({n: chain_list})
    return len(term_list)


<mask token>

<mask token>


def digit_factorial(x, y):
    fact_list = {(0): 1, (1): 1, (2): 2, (3): 6, (4): 24, (5): 120, (6): 
        720, (7): 5040, (8): 40320, (9): 362880}
    term_list = set()
    num_numlength_dic = dict()
    length_check = y
    for n in range(1, x + 1):
        chain_list = {n}
        fact_n = sum(fact_list[int(i)] for i in str(n))
        while fact_n not in chain_list:
            chain_list.add(fact_n)
            if len(chain_list) > y:
                break
            if fact_n in num_numlength_dic:
                chain_list.update(num_numlength_dic[fact_n])
            fact_n = sum(fact_list[int(i)] for i in str(fact_n))
        else:
            if len(chain_list) == length_check:
                term_list.add(n)
            num_numlength_dic.update({n: chain_list})
    return len(term_list)


print(digit_factorial(1000000, 60))

import math


def digit_factorial(x, y):
    fact_list = {(0): 1, (1): 1, (2): 2, (3): 6, (4): 24, (5): 120, (6): 
        720, (7): 5040, (8): 40320, (9): 362880}
    term_list = set()
    num_numlength_dic = dict()
    length_check = y
    for n in range(1, x + 1):
        chain_list = {n}
        fact_n = sum(fact_list[int(i)] for i in str(n))
        while fact_n not in chain_list:
            chain_list.add(fact_n)
            if len(chain_list) > y:
                break
            if fact_n in num_numlength_dic:
                chain_list.update(num_numlength_dic[fact_n])
            fact_n = sum(fact_list[int(i)] for i in str(fact_n))
        else:
            if len(chain_list) == length_check:
                term_list.add(n)
            num_numlength_dic.update({n: chain_list})
    return len(term_list)


print(digit_factorial(1000000, 60))

#Project Euler Question 74
#How many chains, with a starting number below one million, contain exactly sixty non-repeating terms?

import math

def digit_factorial(x, y):
    fact_list = {0: 1, 1: 1, 2: 2, 3: 6, 4: 24, 5: 120, 6: 720, 7: 5040, 8: 40320, 9: 362880}
    term_list = set()
    num_numlength_dic = dict()
    length_check = y
    for n in range(1, x + 1):
        chain_list = {n}
        fact_n = sum(fact_list[int(i)] for i in str(n))
        while fact_n not in chain_list:
            chain_list.add(fact_n)
            if len(chain_list) > y:
                break
            if fact_n in num_numlength_dic:
                chain_list.update(num_numlength_dic[fact_n])
            fact_n = sum(fact_list[int(i)] for i in str(fact_n))
        else:
            if len(chain_list) == length_check:
                term_list.add(n)
            num_numlength_dic.update({n: chain_list})
    return len(term_list)

print (digit_factorial(1000000, 60))