aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-04 12:12:29 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-04 12:12:29 +0000
commit6619f2571264d4c6c73fadbdc972e76dd5836bdb (patch)
tree8e73e6c6f95fba11598322fa7cb68888504f7adb /challenge-113/paulo-custodio/python/ch-1.py
parent9cfe9430aee48716f1e4f6da28f5a4763118a373 (diff)
downloadperlweeklychallenge-club-6619f2571264d4c6c73fadbdc972e76dd5836bdb.tar.gz
perlweeklychallenge-club-6619f2571264d4c6c73fadbdc972e76dd5836bdb.tar.bz2
perlweeklychallenge-club-6619f2571264d4c6c73fadbdc972e76dd5836bdb.zip
Fix task 1 of challenge 113: accept any combinations of numbers containing D
Diffstat (limited to 'challenge-113/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-113/paulo-custodio/python/ch-1.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/challenge-113/paulo-custodio/python/ch-1.py b/challenge-113/paulo-custodio/python/ch-1.py
index e544a5ccd8..5c1e781f0c 100644
--- a/challenge-113/paulo-custodio/python/ch-1.py
+++ b/challenge-113/paulo-custodio/python/ch-1.py
@@ -19,13 +19,19 @@
import sys
import re
+from itertools import combinations
+
+def nums_containing(n, d):
+ nums = list(filter(lambda x: re.search(str(d), str(x)), range(n+1)))
+ return nums
def represent(n, d):
- sum = 0
- for i in range(n+1):
- if re.search(str(d), str(i)):
- sum += i
- return sum==n
+ nums = nums_containing(n, d)
+ for k in range(1, len(nums)+1):
+ for combin in combinations(nums, k):
+ if sum(combin) == n:
+ return True
+ return False
if represent(int(sys.argv[1]), int(sys.argv[2])):
print(1)