Question 940999: What are the 4 digit numbers with a total of 18. List them. (Zero can be a first digit.) Is there a formula to do it ? Thanx in advance :-) Answer by richard1234(7193) (Show Source):
You can put this solution on YOUR website! Assuming you mean digit sum of 18, there are 670 of them, which would take up a lot of space to list here, so here is my Python code:
def counter():
__count = 0
__for a in range(0,10):
____for b in range(0,10):
______for c in range(0,10):
________for d in range(0,10):
__________if a+b+c+d == 18:
____________count += 1
__print count
The generating function for F(x) # of 4-digit numbers with the sum-of-digits property (leading 0's included) is