aboutsummaryrefslogtreecommitdiff
path: root/challenge-078/lubos-kolouch/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-19 12:50:14 +0100
committerGitHub <noreply@github.com>2020-09-19 12:50:14 +0100
commit2e47a82a7bf92e8f7e1034af1d50016f4c1cda87 (patch)
tree74e1492b868dfadad74128431fd90c1f72f46769 /challenge-078/lubos-kolouch/python/ch-2.py
parent3b5da31652f26d7752e9a0a5a8c098090b38450a (diff)
parentf8351e3ab761d7dbe2d9691a85678b86469182de (diff)
downloadperlweeklychallenge-club-2e47a82a7bf92e8f7e1034af1d50016f4c1cda87.tar.gz
perlweeklychallenge-club-2e47a82a7bf92e8f7e1034af1d50016f4c1cda87.tar.bz2
perlweeklychallenge-club-2e47a82a7bf92e8f7e1034af1d50016f4c1cda87.zip
Merge pull request #2322 from LubosKolouch/chal_078_LK
Remove extra space
Diffstat (limited to 'challenge-078/lubos-kolouch/python/ch-2.py')
-rw-r--r--challenge-078/lubos-kolouch/python/ch-2.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-078/lubos-kolouch/python/ch-2.py b/challenge-078/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..c1be12853b
--- /dev/null
+++ b/challenge-078/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,35 @@
+#!/bin/env python
+""" https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/
+ Task 2
+ Left Rotation
+ 19.9.2020 Lubos Kolouch """
+
+
+class ListRotator:
+ """ Rotate the array based on list of elems """
+
+ def __init__(self, arr: list(), elems: list()):
+ self.arr = arr
+ self.elems = elems
+
+ def rotate_arr(self, first: int):
+ """ Rotate the array so that passed elem is first """
+
+ return self.arr[first:] + self.arr[0:first]
+
+ def process_offset(self):
+ """ Process the list of elems for rotation """
+
+ output = list()
+
+ for elem in self.elems:
+ output.append(self.rotate_arr(elem))
+
+ return output
+
+
+test_list = ListRotator(arr=[10, 20, 30, 40, 50], elems=[3, 4])
+assert test_list.process_offset() == [[40, 50, 10, 20, 30], [50, 10, 20, 30, 40]]
+
+test_list = ListRotator(arr=[7, 4, 2, 6, 3], elems=[1, 3, 4])
+assert test_list.process_offset() == [[4, 2, 6, 3, 7], [6, 3, 7, 4, 2], [3, 7, 4, 2, 6]]