aboutsummaryrefslogtreecommitdiff
path: root/challenge-244/roger-bell-west/python/ch-2.py
blob: 7878ee513cf7f7184e6c7be6dcf4fd92d396db53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()