aboutsummaryrefslogtreecommitdiff
path: root/challenge-187/roger-bell-west/python/ch-2.py
blob: 0686ce96cd16a04f3987e0605cfbb1fb02f87596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/python3

import unittest

from itertools import combinations

def magicaltriplets(a):
  out = []
  mv = 0
  for b in combinations(a, 3):
    if b[0] + b[1] > b[2] and b[1] + b[2] > b[0] and b[0] + b[2] > b[1]:
       v = sum(b)
       if v > mv:
         mv = v
         out = b
  return list(reversed(sorted(out)))

class TestMagicaltriplets(unittest.TestCase):

        def test_ex1(self):
          self.assertEqual(magicaltriplets([1, 2, 3, 2]),
                           [3, 2, 2],
                           'example 1')

        def test_ex2(self):
          self.assertEqual(magicaltriplets([1, 3, 2]),
                           [],
                           'example 2')

        def test_ex3(self):
          self.assertEqual(magicaltriplets([1, 1, 2, 3]),
                           [],
                           'example 3')

        def test_ex4(self):
          self.assertEqual(magicaltriplets([2, 4, 3]),
                           [4, 3, 2],
                           'example 4')

unittest.main()