aboutsummaryrefslogtreecommitdiff
path: root/challenge-073/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-073/lubos-kolouch/python')
-rwxr-xr-xchallenge-073/lubos-kolouch/python/ch-1.py27
-rwxr-xr-xchallenge-073/lubos-kolouch/python/ch-2.py29
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-073/lubos-kolouch/python/ch-1.py b/challenge-073/lubos-kolouch/python/ch-1.py
new file mode 100755
index 0000000000..2202e49cce
--- /dev/null
+++ b/challenge-073/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,27 @@
+#! /usr/bin/env python
+""" Perl weekly challenge 073
+ https://perlweeklychallenge.org/blog/perl-weekly-challenge-073/ Task 1 """
+
+
+def min_window(arr, s):
+ """ Return the min sliding window"""
+
+ return_array = list()
+
+ pos = 0
+
+ while 1:
+ last_index = min(len(arr)-1, pos + s)
+
+ app_min = min(arr[pos:last_index])
+ return_array.append(app_min)
+
+ if last_index == len(arr)-1:
+ break
+
+ pos += 1
+
+ return return_array
+
+
+assert min_window([1, 5, 0, 2, 9, 3, 7, 6, 4, 8], 3) == [0, 0, 0, 2, 3, 3, 4]
diff --git a/challenge-073/lubos-kolouch/python/ch-2.py b/challenge-073/lubos-kolouch/python/ch-2.py
new file mode 100755
index 0000000000..ebf988621b
--- /dev/null
+++ b/challenge-073/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,29 @@
+#! /usr/bin/env python
+""" Perl weekly challenge 073
+ https://perlweeklychallenge.org/blog/perl-weekly-challenge-073/ Task 2 """
+
+
+def get_smallest(arr):
+ """Write a script to create an array that represents the
+ smallest element to the left of each corresponding index.
+ If none found then use 0. """
+
+ return_array = list()
+ return_array.append(0)
+
+ my_min = arr[0]
+
+ for i in range(1, len(arr)):
+ if my_min < arr[i]:
+ return_array.append(my_min)
+ else:
+ return_array.append(0)
+
+ if arr[i] < my_min:
+ my_min = arr[i]
+
+ return return_array
+
+
+assert get_smallest([7, 8, 3, 12, 10]) == [0, 7, 0, 3, 3]
+assert get_smallest([4, 6, 5]) == [0, 4, 4]