diff options
Diffstat (limited to 'challenge-244/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-244/roger-bell-west/python/ch-2.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-244/roger-bell-west/python/ch-2.py b/challenge-244/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..7878ee513c --- /dev/null +++ b/challenge-244/roger-bell-west/python/ch-2.py @@ -0,0 +1,21 @@ +#! /usr/bin/python3 + +from itertools import combinations + +def grouphero(nums0): + nums = nums0.copy() + nums.sort() + sum = 0 + for l in range(1, len(nums) + 1): + for c in combinations(nums, l): + sum += c[-1] * c[-1] * c[0] + return sum + +import unittest + +class TestGrouphero(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(grouphero([2, 1, 4]), 141, 'example 1') + +unittest.main() |
