Facebook

Course Name Start Date Time Duration Registration Link
Selenium with Java and API Test Automation 16th September 2020 7.30 AM IST to 9:00 AM IST 45 days ClickHere
Please mail To sudhakar@qtpsudhakar.com to Register for training

Tuesday, June 16, 2020

Find combination of numbers whose sum equal to specific value


def getCombinations(arr, exp, somepart=[]):
    total = sum(somepart)
    if total == exp:
        print(somepart)
    if total >= exp:
        return
    for i in range(0, len(arr)):
        getCombinations(arr[i + 1:], exp, somepart + [arr[i]])


getCombinations([2, 4, 5, 8, 12, 17, 21, 3], 20)

No comments :

Post a Comment