Re: counting how many positive integers <n have digits that add up to m
- From: "robin" <robin51@xxxxxxxxxxx>
- Date: Sat, 22 May 2010 11:15:22 +1000
"Willem" <willem@xxxxxxxxxxxxxxx> wrote in message news:slrnhvd87i.h39.willem@xxxxxxxxxxxxxxxxxx
| robin wrote:
| ) "superpollo" <utente@xxxxxxxxxxx> wrote in message news:4bf44372$0$31380$4fafbaef@xxxxxxxxxxxxxxxxxxxxxx
| )| 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?
| ) Looks like your code finds the number of integers <= n, not < n.
| ) There are three loops in your code, one of which is implied.
| Where ? I don't see it.
I did say that it was "implied".
| Or do you mean the number-to-string conversion ?
The number-to-string conversion is the implied loop.
- Prev by Date: Re: on goto
- Next by Date: www.ebaychinaonline.com Good looks branded sunglasses for men and women,summer fashion accessories for sale,lowest price
- 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