diff options
| author | Roger Bell_West <roger@firedrake.org> | 2022-10-17 11:05:10 +0100 |
|---|---|---|
| committer | Roger Bell_West <roger@firedrake.org> | 2022-10-17 11:05:10 +0100 |
| commit | 1d23f91d86e7ebb5291c17fc99ec0fc2ca48b64a (patch) | |
| tree | 7314948a34d730b3a58716b39d87f9a93011e8fc /challenge-187/roger-bell-west/python/ch-2.py | |
| parent | 70539816fb240ac725e4689763b9851c6fce6788 (diff) | |
| download | perlweeklychallenge-club-1d23f91d86e7ebb5291c17fc99ec0fc2ca48b64a.tar.gz perlweeklychallenge-club-1d23f91d86e7ebb5291c17fc99ec0fc2ca48b64a.tar.bz2 perlweeklychallenge-club-1d23f91d86e7ebb5291c17fc99ec0fc2ca48b64a.zip | |
Solutions for challenge #187
Diffstat (limited to 'challenge-187/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-187/roger-bell-west/python/ch-2.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-187/roger-bell-west/python/ch-2.py b/challenge-187/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..0686ce96cd --- /dev/null +++ b/challenge-187/roger-bell-west/python/ch-2.py @@ -0,0 +1,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() |
