forked from ngiengkianyew/daily-coding-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_012.py
More file actions
20 lines (16 loc) · 692 Bytes
/
problem_012.py
File metadata and controls
20 lines (16 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def get_step_combos(num_steps, step_sizes):
combos = list()
if num_steps < min(step_sizes):
return combos
for step_size in step_sizes:
if num_steps == step_size:
combos.append([step_size])
elif num_steps > step_size:
child_combos = get_step_combos(num_steps - step_size, step_sizes)
for child_combo in child_combos:
combos.append([step_size] + child_combo)
return combos
assert get_step_combos(4, [1, 2]) == \
[[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2]]
assert get_step_combos(4, [1, 2, 3]) == \
[[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 3], [2, 1, 1], [2, 2], [3, 1]]