allowed_ints
の組み合わせのリストを生成する方法は、合計でgoal
になりますか?制限付き整数の組み合わせ
例:私がこれまでに作った何
allowed_ints=[1,2], goal=4
combinations = [[1,1,1,1],[1,1,2],[2,1,1],[2,2],[1,2,1]]
allowed_ints=[5, 6], goal=13
combinations = []
はない作品を行います。
def combinations(allowed_ints, goal):
if goal > 0:
for i in allowed_ints:
for p in combinations(allowed_ints, goal-i):
yield [i] + p
else:
yield []
print list(combinations([1, 2],3))
[[1, 1, 1], [1, 1, 2], [1, 2], [2, 1], [2, 2]] # not what I want
「ゴール」のしきい値を超えていないことを確認してください。 –
組み合わせ()の完全な実行後? –
あなたは、しかし、なぜタスクを延期することができます... –