diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-07-28 06:26:12 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-07-28 06:26:12 +0100 |
| commit | d20c0a014b2fb7524c0bb3254ee9cabeea1069be (patch) | |
| tree | e505a9b07fabd755e9285b6a77ccbce2baf209d6 | |
| parent | 4f61c5490b237866b9ae95d4437d3a4957f8e495 (diff) | |
| download | perlweeklychallenge-club-d20c0a014b2fb7524c0bb3254ee9cabeea1069be.tar.gz perlweeklychallenge-club-d20c0a014b2fb7524c0bb3254ee9cabeea1069be.tar.bz2 perlweeklychallenge-club-d20c0a014b2fb7524c0bb3254ee9cabeea1069be.zip | |
- Added solutions by guest Orestis Zekai.
| -rw-r--r-- | challenge-018/orestis-zekai/README | 1 | ||||
| -rw-r--r-- | challenge-018/orestis-zekai/python/ch-1.py | 18 | ||||
| -rw-r--r-- | challenge-018/orestis-zekai/python/ch-2.py | 55 | ||||
| -rw-r--r-- | guests.json | 3 |
4 files changed, 77 insertions, 0 deletions
diff --git a/challenge-018/orestis-zekai/README b/challenge-018/orestis-zekai/README new file mode 100644 index 0000000000..7e89e9dd0f --- /dev/null +++ b/challenge-018/orestis-zekai/README @@ -0,0 +1 @@ +Solutions by Orestis Zekai. diff --git a/challenge-018/orestis-zekai/python/ch-1.py b/challenge-018/orestis-zekai/python/ch-1.py new file mode 100644 index 0000000000..e997db9e74 --- /dev/null +++ b/challenge-018/orestis-zekai/python/ch-1.py @@ -0,0 +1,18 @@ +# Longest common substring
+
+string1 = "ABABC"
+string2 = "BABCA"
+
+max_substring = ""
+max_length = -1
+
+
+for i in range(0, len(string1)+1):
+ for j in range(0, len(string1)+1):
+ if (string1[i:j] in string2) and len(string1[i:j]) > max_length:
+ max_length = len(string1[i:j])
+ max_substring = string1[i:j]
+
+
+print('The longest substring is: ' + max_substring)
+print('The length of the longest substring is: ' + str(max_length))
\ No newline at end of file diff --git a/challenge-018/orestis-zekai/python/ch-2.py b/challenge-018/orestis-zekai/python/ch-2.py new file mode 100644 index 0000000000..ff36bfd529 --- /dev/null +++ b/challenge-018/orestis-zekai/python/ch-2.py @@ -0,0 +1,55 @@ +import time
+import math
+
+def is_empty(queue):
+ if not queue:
+ print("Queue is empty")
+ else:
+ print("Queue is not empty")
+
+def insert_with_priority(queue):
+ print('Enter the priority of the element you want to insert')
+ priority = int(input())
+ timestamp = time.time()
+
+ queue.append([priority, timestamp])
+ return queue
+
+def pull_highest_prority_element(queue):
+ queue.remove(max(queue))
+ return queue
+
+available_choices = [1, 2, 3, 4]
+queue = []
+
+while 1:
+ print('\n\n')
+ print('================================')
+ print('Current status of queue')
+ if not queue:
+ print(queue)
+ else:
+ for i in range(0, len(queue)):
+ print(queue[i][0])
+
+
+ print('1. Check if queue is empty')
+ print('2. Insert with priority')
+ print('3. Pull highest priority element')
+ print('4. Exit')
+ print('Enter the number of your choice')
+
+ choice = int(input())
+ while (choice not in available_choices):
+ print('Please enter a valid choice')
+ choice = int(input())
+
+ if (choice == 1):
+ is_empty(queue)
+ if (choice == 2):
+ queue = insert_with_priority(queue)
+ if (choice == 3):
+ queue = pull_highest_prority_element(queue)
+ if (choice == 4):
+ break
+
diff --git a/guests.json b/guests.json new file mode 100644 index 0000000000..f51bf26225 --- /dev/null +++ b/guests.json @@ -0,0 +1,3 @@ +{ + "orestis-zekai" : "Orestis Zekai" +} |
