blob: 344143f90582945cc803c3b11b346bf45374dff8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/usr/bin/env python3
# Challenge 065
#
# TASK #1 > Digits Sum
# Submitted by: Mohammad S Anwar
# Reviewed by: Ryan Thompson
#
# You are given two positive numbers $N and $S.
#
# Write a script to list all positive numbers having exactly $N digits where sum
# of all digits equals to $S.
#
# Example
# Input:
# $N = 2
# $S = 4
#
# Output:
# 13, 22, 31, 40
import sys
from itertools import product
def digits_sum(N, S):
out = []
for n in range(10**(N-1), 10**N):
if sum(int(d) for d in str(n)) == S:
out.append(n)
return out
N, S = map(int, sys.argv[1:])
out = digits_sum(N, S)
print(", ".join(map(str, out)))
|