Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using itertools and loops to find desired result
- Loading branch information
1 parent
cf16150
commit 8590718
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Name:Dipto Chakrabarty | ||
Topic:Combination Sum | ||
Date:1/02/2019 | ||
|
||
from itertools import combinations_with_replacement | ||
l=list(map(int,input().split())) #taking inputs and storing in list | ||
n=int(input()) #input of required sum | ||
k=len(l) #length of list | ||
d=[] | ||
for i in range(k): | ||
t=list(combinations_with_replacement(l,i+1)) #total combinations of the list | ||
d.append(t) #adding it to another list | ||
|
||
for i in range(len(d)): | ||
for j in range(len(d[i])): | ||
if(n==(sum(d[i][j]))): #checking if list element equals required number | ||
print(list(d[i][j])) | ||
|