diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2023-08-10 18:39:25 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2023-08-10 18:39:25 +0200 |
| commit | 35dc9fc9edb601859684ea65c76db9d294214d96 (patch) | |
| tree | 6debfd56c561ebdadad419f738a377aed11acc2d /challenge-199/lubos-kolouch/python | |
| parent | 66803aade1dcd00f1a8ccc64498ee984fbb988eb (diff) | |
| download | perlweeklychallenge-club-35dc9fc9edb601859684ea65c76db9d294214d96.tar.gz perlweeklychallenge-club-35dc9fc9edb601859684ea65c76db9d294214d96.tar.bz2 perlweeklychallenge-club-35dc9fc9edb601859684ea65c76db9d294214d96.zip | |
feat(challenge-199/lubos-kolouch/): Challenge 199 LK Perl Python blog
Diffstat (limited to 'challenge-199/lubos-kolouch/python')
| -rw-r--r-- | challenge-199/lubos-kolouch/python/ch-1.py | 25 | ||||
| -rw-r--r-- | challenge-199/lubos-kolouch/python/ch-2.py | 29 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-199/lubos-kolouch/python/ch-1.py b/challenge-199/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..f245a04557 --- /dev/null +++ b/challenge-199/lubos-kolouch/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import unittest + + +def good_pairs(lst): + count = 0 + for i in range(len(lst)): + for j in range(i + 1, len(lst)): + if lst[i] == lst[j]: + count += 1 + return count + + +class TestGoodPairs(unittest.TestCase): + + def test_cases(self): + self.assertEqual(good_pairs([1, 2, 3, 1, 1, 3]), 4, 'Test Case 1') + self.assertEqual(good_pairs([1, 2, 3]), 0, 'Test Case 2') + self.assertEqual(good_pairs([1, 1, 1, 1]), 6, 'Test Case 3') + + +if __name__ == '__main__': + unittest.main() diff --git a/challenge-199/lubos-kolouch/python/ch-2.py b/challenge-199/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..a799fa9fd6 --- /dev/null +++ b/challenge-199/lubos-kolouch/python/ch-2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import unittest + + +def good_triplets(x, y, z, lst): + count = 0 + for i in range(len(lst) - 2): + for j in range(i + 1, len(lst) - 1): + for k in range(j + 1, len(lst)): + if abs(lst[i] - lst[j]) <= x and \ + abs(lst[j] - lst[k]) <= y and \ + abs(lst[i] - lst[k]) <= z: + count += 1 + return count + + +class TestGoodTriplets(unittest.TestCase): + + def test_cases(self): + self.assertEqual(good_triplets(7, 2, 3, [3, 0, 1, 1, 9, 7]), 4, + 'Test Case 1') + self.assertEqual(good_triplets(0, 0, 1, [1, 1, 2, 2, 3]), 0, + 'Test Case 2') + + +if __name__ == '__main__': + unittest.main() |
