Project Euler #178: Step Numbers

  • + 0 comments

    What wrong in this Code?

    n = int(input())
    d = n
    x = []
    a = n
    
    def check(a,d):
        if(d==0):
            pass
        elif(d==10):
            x.append(1)
        elif(a<10):
            x.append(a)
            d = ((d-a)/10)
            check(d,d)
        elif(a%10==0 and a==10):
            x.append(0)
            d = (d/10)
            check(d,d)
        elif(a%10==0):
            a=a/10;
            check(a,d)
        else:
            a=a%10;
            check(a,d)
    check(a,d)
    x.reverse()     
    
    l = len(str(n))            
    
    count = 0
    for i in range(0,l-2):
            if((x[i]-x[i+1])==-1 or (x[i]-x[i+1])==1):
                    count = count + 1
    print(count)