Skip to content

Commit

Permalink
Combinationsum.py (#220)
Browse files Browse the repository at this point in the history
using itertools and loops to find desired result
  • Loading branch information
DiptoChakrabarty authored and MadhavBahl committed Feb 7, 2019
1 parent cf16150 commit 8590718
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions day23/python/Combinationsum.py
@@ -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]))

0 comments on commit 8590718

Please sign in to comment.