Euler Problem 79

Just a simple substitution routine.

#Euler79
class Problem79:
    def __init__(self, list):
        self.list = list
    def Solution(self):
        code = [0,1,2,3,4,5,6,7,8,9]
        used = [0,1,2,3,4,5,6,7,8,9]
        for n in self.list:
            d0 = int(str(n)[0])
            if d0 in used:
                used.pop(used.index(d0))
            i0 = code.index(d0)
            d1 = int(str(n)[1])
            if d1 in used:
                used.pop(used.index(d1))
            i1 = code.index(d1)
            d2 = int(str(n)[2])
            if d2 in used:
                used.pop(used.index(d2))
            i2 = code.index(d2)
            print d0, d1, d2, i0, i1, i2, used, code,
            if i1 < i0:
                code.insert(i0+1, d1)
                code.pop(i1)
            if i2 < i1:
                code.insert(i1+1, d2)
                code.pop(i2)
            print code
        for n in used:
            code.pop(code.index(n))
        answer = ""
        for n in code:
            answer += str(n)
        return "Answer = " + answer
if __name__ == '__main__':
    P = Problem79([319,680,180,690,129,620,762,689,762,318,368,710,720,710,629,168,160,689,
        716,731,736,729,316,729,729,710,769,290,719,680,318,389,162,289,162,718,
        729,319,790,680,890,362,319,760,316,729,380,319,728,716])
    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