Project Euler #178: Step Numbers

Sort by

recency

|

14 Discussions

|

  • + 0 comments

    For me this was the most difficult type of problem with counting specific numbers whose digits satisfy some condition. After some failed attempts I finally cracked it. It requuires simple DP. In my case I used 3 dimensional arrays. The problem is tricky, so it needs carefull analysis.

  • + 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)
    
  • + 0 comments

    My script gives correct output in IDLE but fails due to timeout for this problem. Any suggestion or help:

    i = input() x=10**10

    def prime(a3): n=a3+1 flag=0 count=2 for i in range(n): flag=0 while flag!=1: count=count+1 for i in range(2,count): if count%i==0: count=count+1 break else: continue flag=1 print count

    def fun(x,i): if i<10*x: print 0 elif i==10*x: print 1 elif i>10*x: a=i/10*x
    a1=str(int(a)) a2=list(a1) a3=len(a2)-1 prime(a3)

    fun(x, i)

  • + 0 comments

    I submitted my solution. it works fine on my machine. Runtime errors shown on your results. why is that?

  • + 0 comments

    when do we get solutions of the problem?