From 123adf9d800d9f33e043240292946b8baf908a2d Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 7 Sep 2018 21:22:29 -0500 Subject: max dot product done aka maximize online ad revenue.--- .../sources/max_dot_product.py | 20 ++++++++++++++ .../tests/max_dot_prodTest.py | 31 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 AlgoDesignAndTechniqueEdxPython/sources/max_dot_product.py create mode 100644 AlgoDesignAndTechniqueEdxPython/tests/max_dot_prodTest.py diff --git a/AlgoDesignAndTechniqueEdxPython/sources/max_dot_product.py b/AlgoDesignAndTechniqueEdxPython/sources/max_dot_product.py new file mode 100644 index 0000000..268a765 --- /dev/null +++ b/AlgoDesignAndTechniqueEdxPython/sources/max_dot_product.py @@ -0,0 +1,20 @@ +#Uses python3 + +import sys + +def getMaxDotProduct(a, b): + a.sort() + b.sort() + result = 0 + for i, j in zip(a,b): + result = result + i*j + return result + +if __name__ == '__main__': + input = sys.stdin.read() + data = list(map(int, input.split())) + n = data[0] + a = data[1:(n + 1)] + b = data[(n + 1):] + print(getMaxDotProduct(a, b)) + \ No newline at end of file diff --git a/AlgoDesignAndTechniqueEdxPython/tests/max_dot_prodTest.py b/AlgoDesignAndTechniqueEdxPython/tests/max_dot_prodTest.py new file mode 100644 index 0000000..2f8f7a2 --- /dev/null +++ b/AlgoDesignAndTechniqueEdxPython/tests/max_dot_prodTest.py @@ -0,0 +1,31 @@ +''' +Created on Sep 7, 2018 + +@author: haidong +''' +import unittest + +from sources.max_dot_product import getMaxDotProduct + +class Test(unittest.TestCase): + + + def testName(self): + a = [60, 100, 120] + b = [20, 50, 30] + self.assertEqual(getMaxDotProduct(a, b), 10200) + + def testName1(self): + a = [23] + b = [39] + self.assertEqual(getMaxDotProduct(a, b), 897) + + def testName2(self): + a = [1, 3, -5] + b = [-2,4,1] + self.assertEqual(getMaxDotProduct(a, b), 23) + + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file -- cgit v1.2.3