diff options
Diffstat (limited to 'challenge-244/packy-anderson/python/ch-2.py')
| -rw-r--r-- | challenge-244/packy-anderson/python/ch-2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-244/packy-anderson/python/ch-2.py b/challenge-244/packy-anderson/python/ch-2.py new file mode 100644 index 0000000000..3c13ba4d92 --- /dev/null +++ b/challenge-244/packy-anderson/python/ch-2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from itertools import combinations + +def power(arr): + return( (max(arr) ** 2) * min(arr) ) + +def groupHero(nums): + # generate a list of combinations + comb = [] + for i in range(1, len(nums)+1): + for c in combinations(nums, i): + comb.append(c) + return sum( + # generate the list of powers for each combination + [ power(x) for x in comb ] + ) + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(arr): + print(f'Input: @int = ({comma_join(arr)})') + output = groupHero(arr) + print(f'Output: {output}') + +print('Example 1:') +solution([2, 1, 4]) |
