-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHow Many Numbers.py
65 lines (39 loc) · 1.54 KB
/
How Many Numbers.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
Created on Nov 14, 2018
@author: kroberts
PROBLEM STATEMENT
We want to generate all the numbers of three digits that:
the value of adding their corresponding ones(digits) is equal to 10.
their digits are in increasing order (the numbers may have two or more equal contiguous digits)
The numbers that fulfill the two above constraints are: 118, 127, 136, 145, 226, 235, 244, 334
Make a function that receives two arguments:
the sum of digits value
the amount of desired digits for the numbers
The function should output an array with three values: [1,2,3]
1 - the total amount of all these possible numbers
2 - the minimum number
3 - the maximum numberwith
The example given above should be:
find_all(10, 3) == [8, 118, 334]
If we have only one possible number as a solution, it should output a result like the one below:
find_all(27, 3) == [1, 999, 999]
If there are no possible numbers, the function should output the empty array.
find_all(84, 4) == []
The number of solutions climbs up when the number of digits increases.
find_all(35, 6) == [123, 116999, 566666]
Features of the random tests:
'''
# CODE TIMES OUT!!!!!!!!!!
def find_all(sum_dig, digs):
final = []
for i in range(10**(digs-1), 10**digs, 1):
added = 0
lst = list(str(i))
for j in lst:
added+=int(j)
if added == sum_dig:
if lst == sorted(lst):
final+=[int(''.join(lst))]
if len(final) == 0:
return []
return [len(final), min(final), max(final)]