Project Euler #164: Numbers for which no three consecutive digits have a sum greater than a given value.

  • + 0 comments

    Can anyone help me. My answers are coming when m < 7 but not for greater than 7. It gives timeout error. Here is my code in python2

    m = int(input())
    for i in range(0,m):
        if i==0:
            ll = str(1)
            ul = str(9)
        else:
            ll = ll + str(0)
            ul = ul + str(9)
    ll = int(ll)
    ul = int(ul)
    
    count = 0
    i = ll
    while i <= ul:
        numlist = [int(j) for j in str(i)]
        k = 3
        l = 0
        flag = 0
        while k <= len(numlist):
            if sum(numlist[l:k]) > 9:
                flag = 1
                break
            l = l + 1
            k = k + 1    
        if flag == 0:
            count = count + 1
        i = i + 1
    print count