Euler Problem 74

Just iterate, create a list for each, test for replication and increment if 60.

#Euler74
class Algorithms:
    def sumBang(self, strStart):
        sum = 0
        for digit in range(0, len(strStart)):
            bang = 1
            for n in range (2,int(strStart[digit])+1):
                bang *= n
            sum += bang
        return sum
class Problem74:
    def __init__(self, limit):
        self.limit = limit
        self.Euler = Algorithms()
    def Solution(self):
        count = 0
        for n in range (78, self.limit+1):
            result = 0
            L = [n]
            while result != n:
                if len(L) == 1:
                    result = self.Euler.sumBang(str(n))
                else:
                    result = self.Euler.sumBang(str(result))
                if result in L:
                    L.append(result)
                    break
                else:
                    L.append(result)
            if len(L)-1 == 60:
                count += 1
            if n % 10000 == 0:
                print n, count
        return "Answer:"+str(count)
if __name__ == '__main__':
    P = Problem74(1000000)
    print P.Solution()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s