aboutsummaryrefslogtreecommitdiff
path: root/challenge-196/lubos-kolouch/python
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-08-08 11:50:37 +0200
committerLubos Kolouch <lubos@kolouch.net>2023-08-08 11:50:37 +0200
commitec6da3d64ef535445c423ac7fd687d7074df0d79 (patch)
tree1b62d497dbf11090b9732a0897eb502e92b713a0 /challenge-196/lubos-kolouch/python
parent267f197dc9dd52a0a7dac2d59bccc642abe542a0 (diff)
downloadperlweeklychallenge-club-ec6da3d64ef535445c423ac7fd687d7074df0d79.tar.gz
perlweeklychallenge-club-ec6da3d64ef535445c423ac7fd687d7074df0d79.tar.bz2
perlweeklychallenge-club-ec6da3d64ef535445c423ac7fd687d7074df0d79.zip
feat(challenge-196/lubos-kolouch/perl,python/): Challenge 196 LK Perl Python
Diffstat (limited to 'challenge-196/lubos-kolouch/python')
-rw-r--r--challenge-196/lubos-kolouch/python/ch-1.py29
-rw-r--r--challenge-196/lubos-kolouch/python/ch-2.py30
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-196/lubos-kolouch/python/ch-1.py b/challenge-196/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..2a53fbee40
--- /dev/null
+++ b/challenge-196/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from typing import List
+
+
+def find_pattern_132(nums: List[int]) -> List[int]:
+
+ for i in range(len(nums)):
+
+ for j in range(i+1, len(nums)):
+
+ for k in range(j+1, len(nums)):
+
+ if nums[i] < nums[k] < nums[j]:
+
+ return [nums[i], nums[j], nums[k]]
+
+ return []
+
+
+# Test cases
+print(find_pattern_132([3, 1, 4, 2])) # Expected: [1, 4, 2]
+
+print(find_pattern_132([1, 2, 3, 4])) # Expected: []
+
+print(find_pattern_132([1, 3, 2, 4, 6, 5])) # Expected: [1, 3, 2]
+
+print(find_pattern_132([1, 3, 4, 2])) # Expected: [1, 3, 2]
diff --git a/challenge-196/lubos-kolouch/python/ch-2.py b/challenge-196/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..fe83254399
--- /dev/null
+++ b/challenge-196/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+def find_ranges(array):
+ ranges = []
+ start, end = None, None
+
+ for num in array:
+ if start is None:
+ start = end = num
+ elif num == end + 1:
+ end = num
+ else:
+ if end > start:
+ ranges.append([start, end])
+ start = end = num
+
+ if start is not None and end > start:
+ ranges.append([start, end])
+
+ return ranges
+
+
+# Test cases
+assert find_ranges([1, 3, 4, 5, 7]) == [[3, 5]], "Example 1"
+assert find_ranges([1, 2, 3, 6, 7, 9]) == [[1, 3], [6, 7]], "Example 2"
+assert find_ranges([0, 1, 2, 4, 5, 6, 8, 9]) == [
+ [0, 2], [4, 6], [8, 9]], "Example 3"
+
+print("All tests passed!")