Last active
April 23, 2021 20:12
-
-
Save chrysmur/03681d97a414af6d587e1f83820ccaed to your computer and use it in GitHub Desktop.
umbrella Challenge
This file contains hidden or 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
def umbrella_count(people, umbrellas, store={}): | |
if people in store: return store[people] | |
if people < 0: return None | |
if people == 0: return [] | |
shortest = None | |
for umb in umbrellas: | |
remainder = people - umb | |
result = umbrella_count(remainder, umbrellas, store) | |
if result is not None: | |
combination =[*result, umb] | |
store[people] = combination | |
if not shortest or (len(shortest) > len(combination)): | |
shortest = combination | |
return shortest | |
def solution(people, umbrellas): | |
count = umbrella_count(people, umbrellas) | |
print(count) | |
if count: return len(count); | |
else: return -1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wow