Re: counting how many positive integers <n have digits that add up to m

superpollo <utente@xxxxxxxxxxx> wrote:

in python:

def prttn(m, n):
tot = 0
for i in range(n):
s = str(i)
sum = 0
for j in range(len(s)):
sum += int(s[j])
if sum == m:
tot += 1
return tot

any suggestion for improvement?

My first thought is that there might be a formula that will return the
result with no loops.