From 0e582956d6a679af703724b309b768ef9ba833dd Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Mon, 19 Oct 2020 11:33:06 +0100 Subject: Solutions for challenge #83. --- challenge-083/roger-bell-west/python/ch-2.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 challenge-083/roger-bell-west/python/ch-2.py (limited to 'challenge-083/roger-bell-west/python/ch-2.py') diff --git a/challenge-083/roger-bell-west/python/ch-2.py b/challenge-083/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..c518da107a --- /dev/null +++ b/challenge-083/roger-bell-west/python/ch-2.py @@ -0,0 +1,30 @@ +#! /usr/bin/python3 + +from itertools import combinations +import unittest + +def fa(*a): + ss=sum(a) + ls=ss + li=0 + for inv in range(1,len(a)): + for l in combinations(a,inv): + s=ss-2*sum(l) + if (s >= 0): + if (ls == ss or s < ls or (s == ls and inv < li)): + ls=s + li=inv + return li + +class TestFa(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(fa(3,10,8),1,'example 1') + + def test_ex2(self): + self.assertEqual(fa(12,2,10),1,'example 2') + + def test_ex3(self): + self.assertEqual(fa(2,2,10),2,'example 3') + +unittest.main() -- cgit