aboutsummaryrefslogtreecommitdiff
path: root/challenge-191/mohammad-anwar/python/ch-1.py
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2022-11-20 14:22:01 -0500
committerDave Jacoby <jacoby.david@gmail.com>2022-11-20 14:22:01 -0500
commitdd682dfee966fe63cbfbbbf6a9cb903b1d831416 (patch)
treea71619e10c8dcd29fc13a08beb1325f4a7bc5a84 /challenge-191/mohammad-anwar/python/ch-1.py
parentd6d01468fd7a5647b9ba96ebf7a0157ff79f3352 (diff)
parentbde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff)
downloadperlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.gz
perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.bz2
perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-191/mohammad-anwar/python/ch-1.py')
-rw-r--r--challenge-191/mohammad-anwar/python/ch-1.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-191/mohammad-anwar/python/ch-1.py b/challenge-191/mohammad-anwar/python/ch-1.py
new file mode 100644
index 0000000000..d8b6032c40
--- /dev/null
+++ b/challenge-191/mohammad-anwar/python/ch-1.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python3
+
+'''
+
+Week 191:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-191
+
+Task #1: Twice Largest
+
+ You are given list of integers, @list.
+
+ Write a script to find out whether the largest item in the list
+ is at least twice as large as each of the other items.
+
+'''
+
+import unittest
+
+def twiceLargest(array) -> int:
+ m = sorted(array).pop()
+ for i in array:
+ if i == m:
+ continue
+ if i * 2 > m:
+ return -1
+
+ return 1
+
+#
+#
+# Unit test class
+
+class TestTwiceLargest(unittest.TestCase):
+ def test_twiceLargest(self):
+ self.assertEqual(twiceLargest([1, 2, 3, 4]), -1, 'Example 1')
+ self.assertEqual(twiceLargest([1, 2, 0, 5]), 1, 'Example 2')
+ self.assertEqual(twiceLargest([2, 6, 3, 1]), 1, 'Example 3')
+ self.assertEqual(twiceLargest([4, 5, 2, 3]), -1, 'Example 4')
+
+unittest.main()