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

*From*: "Daniel T." <daniel_t@xxxxxxxxxxxxx>*Date*: Sat, 22 May 2010 08:47:35 -0400

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.

.

**Follow-Ups**:

**References**:**counting how many positive integers <n have digits that add up to m***From:*superpollo

- Prev by Date:
**Re: on goto** - Next by Date:
**complexity again. (was: on goto)** - Previous by thread:
**Re: counting how many positive integers <n have digits that add up to m** - Next by thread:
**Re: counting how many positive integers <n have digits that add up to m** - Index(es):