This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My own timer code using recursion (2 codes wit same structure but different output) | |
import time | |
def clock_1(i, j): | |
if i == 0 and j == 60: | |
return | |
else: | |
if i != 0 and j != 60: | |
clock_1(i - 1, j + 1) | |
time.sleep(1) | |
print(i, ":", j) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Brides select their groom based on their priorities | |
''' | |
list1 = [1, 6, 18, 9, 2, 5, 6, 23, 565] | |
list2 = [16, 33, 4, 8, 13, 39, 54, 3, 1] | |
final = list(filter(lambda a: a % 1 == 0, list1)) | |
final2 = list(filter(lambda a: a % 3 != 0, list2)) | |
final3 = list(filter(lambda a: a % 3 == 0, list2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Harlod and his homework | |
''' | |
money = [20, 54, 41] | |
deadline = [3, 4, 5] | |
money1 = [60, 40, 80] | |
deadline1 = [1, 2, 2] | |
lst = min(deadline) | |
res = list(filter(lambda i: i >= lst, deadline)) | |
if res != 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Minimise the sum | |
''' | |
import time | |
t1 = time.process_time() | |
a = [] | |
for i in range(len(a)-1): | |
b = max(a) | |
c = b // 2 | |
a.append(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
The code below is to minimize the sum of all elements in an array. I have provided the time that the code is taking to execute too. | |
Miniize the sum was the question that was asked in a coding contest that I have recently participated in, and got to know that | |
it if a frequently asked question. | |
''' | |
import time | |
# The start time is not that useful in this program. But mentioned just incase | |
t1 = time.process_time() | |
a = [20, 7, 5, 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
In the below code, I just took the modulo criteria for the filtering process. | |
if res = 0: The so and so person secured more than 80% or can be taken in any other aspect i.e. the work experience in so and so field.. etc etc.. aspects | |
if res = 1: >70% | |
if res = 2: >60% | |
Or the criterias can be taken the other way i.e. 0: 60% - 70%, 1: >=70% - 80%, 2: >80% | |
The criteria can be choosen based on changing the number than we're performin modulo operation with. | |
''' | |
Recursive Operation | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Stack Data Structure | |
""" | |
class Stack: | |
def __init__(self): | |
self.number=[] |