diff --git a/Solutions/__pycache__/AlertManager.cpython-310.pyc b/Solutions/__pycache__/AlertManager.cpython-310.pyc new file mode 100644 index 0000000..00e988a Binary files /dev/null and b/Solutions/__pycache__/AlertManager.cpython-310.pyc differ diff --git a/Solutions/python3_the-ai-developer_Alternating-Square-Arrangement.py b/Solutions/python3_the-ai-developer_Alternating-Square-Arrangement.py new file mode 100644 index 0000000..3378cde --- /dev/null +++ b/Solutions/python3_the-ai-developer_Alternating-Square-Arrangement.py @@ -0,0 +1,13 @@ +Rc, Bc = map(int, input("Enter Red And Blue Blocks Count: ").split(" ")) +if abs(Rc - Bc) != 1: + print("Not Possible!") +else: + Greatest = 'R' if Rc > Bc else 'B' + Smallest = 'R' if Rc < Bc else 'B' + Min = min(Rc, Bc) + result = [] + for i in range(Min): + result.append(Greatest) + result.append(Smallest) + result.append(Greatest) + print("Anagram: ", ''.join(result)) diff --git a/Solutions/python3_the-ai-developer_Concurrent-Task-Execution.py b/Solutions/python3_the-ai-developer_Concurrent-Task-Execution.py new file mode 100644 index 0000000..9443bf4 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Concurrent-Task-Execution.py @@ -0,0 +1,52 @@ +from collections import defaultdict, deque + +def Exec_Ordr(tasks): + graph = defaultdict(list) + in_deg = defaultdict(int) + + for task, dependencies in tasks: + in_deg[task] + for dep in dependencies: + graph[dep].append(task) + in_deg[task] += 1 + + queue = deque([task for task in in_deg if in_deg[task] == 0]) + result = [] + + while queue: + current_batch = [] + for _ in range(len(queue)): + task = queue.popleft() + current_batch.append(task) + + for neighbor in graph[task]: + in_deg[neighbor] -= 1 + if in_deg[neighbor] == 0: + queue.append(neighbor) + + result.append(current_batch) + + if sum(len(batch) for batch in result) != len(tasks): + return "Error: Cyclic dependency detected" + + return result + +if __name__ == "__main__": + n = int(input("Enter the number of tasks: ")) + tasks = [] + + for _ in range(n): + task_id = input(f"Enter Task ID for Task {_+1}: ") + dependencies = input(f"Enter dependencies @Task {task_id}: ") + dependencies = dependencies.split(",") if dependencies else [] + tasks.append((task_id, dependencies)) + + output = Exec_Ordr(tasks) + + if isinstance(output, str): + print(output) + else: + print("Execution Order:") + for i, batch in enumerate(output, 1): + print(f"Step {i}: {batch}") + diff --git a/Solutions/python3_the-ai-developer_Customer-Return-Frequency.py b/Solutions/python3_the-ai-developer_Customer-Return-Frequency.py new file mode 100644 index 0000000..d28112d --- /dev/null +++ b/Solutions/python3_the-ai-developer_Customer-Return-Frequency.py @@ -0,0 +1 @@ +print(f"Customers Who Returned Only Once: {list(map(int,input('Enter Return List: ').split())).count(1)}") diff --git a/Solutions/python3_the-ai-developer_Cybersecurity-Alert-Management.py b/Solutions/python3_the-ai-developer_Cybersecurity-Alert-Management.py new file mode 100644 index 0000000..737e881 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Cybersecurity-Alert-Management.py @@ -0,0 +1,104 @@ +from datetime import datetime, timedelta + +class AlertManager: + def __init__(self): + self.alerts = {} + + def parse_timestamp(self, timestamp): + try: + return datetime.strptime(timestamp, "%H:%M:%S") + except ValueError: + raise ValueError(f"Invalid timestamp format: {timestamp}. Expected HH:MM:SS.") + + def process_alert(self, alert): + alert_id = alert["id"] + timestamp = self.parse_timestamp(alert["timestamp"]) + threat_level = alert["threat_level"] + + if alert_id in self.alerts: + stored_alert = self.alerts[alert_id] + stored_time = stored_alert["timestamp"] + + # Ignore alert if it's within 30 seconds + if timestamp - stored_time <= timedelta(seconds=30): + return + + # Update threat level if higher + if threat_level > stored_alert["threat_level"]: + self.alerts[alert_id]["threat_level"] = threat_level + self.alerts[alert_id]["timestamp"] = timestamp + else: + self.alerts[alert_id] = {"timestamp": timestamp, "threat_level": threat_level} + + def evict_old_alerts(self, current_time): + current_time = self.parse_timestamp(current_time) + ids_to_remove = [] + + print("\n[DEBUG] Current Time:", current_time) + print("[DEBUG] Stored Alerts Before Eviction:") + for alert_id, data in self.alerts.items(): + print(f" - ID: {alert_id}, Timestamp: {data['timestamp']}, Threat Level: {data['threat_level']}") + + for alert_id, data in self.alerts.items(): + if current_time - data["timestamp"] > timedelta(minutes=5): + print(f"[DEBUG] Evicting Alert ID: {alert_id} (Timestamp: {data['timestamp']})") + ids_to_remove.append(alert_id) + + for alert_id in ids_to_remove: + del self.alerts[alert_id] + + print("[DEBUG] Stored Alerts After Eviction:") + for alert_id, data in self.alerts.items(): + print(f" - ID: {alert_id}, Timestamp: {data['timestamp']}, Threat Level: {data['threat_level']}") + + def get_stored_alerts(self): + result = [] + for alert_id, data in self.alerts.items(): + result.append({ + "id": alert_id, + "timestamp": data["timestamp"].strftime("%H:%M:%S"), + "threat_level": data["threat_level"] + }) + return result + + +def main(): + alert_manager = AlertManager() + print("Enter alerts in the format: id,timestamp,threat_level (e.g., A123,00:00:10,3)") + print("Type 'stop' to finish...") + + while True: + user_input = input("Enter alert: ").strip() + if user_input.lower() == "stop": + break + + try: + alert_id, timestamp, threat_level = user_input.split(",") + alert = { + "id": alert_id.strip(), + "timestamp": timestamp.strip(), + "threat_level": int(threat_level.strip()) + } + alert_manager.process_alert(alert) + except ValueError as e: + print(f"Invalid format. Please try again. Error: {e}") + + current_time = input("Enter the current time (HH:MM:SS): ").strip() + try: + alert_manager.evict_old_alerts(current_time) + except ValueError as e: + print(f"Error with current time: {e}") + return + + print("\nStored alerts:") + stored_alerts = alert_manager.get_stored_alerts() + if not stored_alerts: + print("No alerts to display.") + else: + for alert in stored_alerts: + print(f"ID: {alert['id']}, Timestamp: {alert['timestamp']}, Threat Level: {alert['threat_level']}") + + +if __name__ == "__main__": + main() + diff --git a/Solutions/python3_the-ai-developer_Digit-Manipulation.py b/Solutions/python3_the-ai-developer_Digit-Manipulation.py new file mode 100644 index 0000000..4a0faf4 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Digit-Manipulation.py @@ -0,0 +1,15 @@ +def DigitSqrSum(n): + def DigitSum(x): + square_sum=0 + while x>0: + digit=x%10 + square_sum+=digit*digit + x//=10 + return square_sum + total_sum=0 + for i in range(1,n+1): + total_sum += DigitSum(i) + return total_sum + +print(f"Resultant Sum: {DigitSqrSum(int(input('Enter A Number: ')))}") + diff --git a/Solutions/python3_the-ai-developer_Endless-Towers.py b/Solutions/python3_the-ai-developer_Endless-Towers.py new file mode 100644 index 0000000..d5579a3 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Endless-Towers.py @@ -0,0 +1,12 @@ +def HanoiTower(n, source, target, auxiliary): + if n == 1: + print(f"Move disk 1 from {source} to {target}") + return + HanoiTower(n - 1, source, auxiliary, target) + print(f"Move disk {n} from {source} to {target}") + HanoiTower(n - 1, auxiliary, target, source) + +n = int(input("Enter number of disks: ")) +print(f"Minimum No.Of Moves: {(2**n)-1}!\nThe Move Sequence:") +HanoiTower(n, 'A', 'C', 'B') + diff --git a/Solutions/python3_the-ai-developer_Holiday-Gift-Arrangement.py b/Solutions/python3_the-ai-developer_Holiday-Gift-Arrangement.py new file mode 100644 index 0000000..6aeda14 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Holiday-Gift-Arrangement.py @@ -0,0 +1,17 @@ +def minTrips(houses, W): + trips = 0 + current_load = 0 + + for gifts in houses: + if current_load + gifts > W: + trips += 1 + current_load = 0 + current_load += gifts + + if current_load > 0: + trips += 1 + + return trips + +print(f"Required Minimum No.Of Trips: {minTrips(list(map(int, input('Enter Gifts For Houses: ').split())), int(input('Enter Max Capacity: ')))}") + diff --git a/Solutions/python3_the-ai-developer_Howards-Rare-Gems.py b/Solutions/python3_the-ai-developer_Howards-Rare-Gems.py new file mode 100644 index 0000000..829dfb6 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Howards-Rare-Gems.py @@ -0,0 +1,43 @@ +def manachers_algorithm(S): + S1 = '#'.join('^{}$'.format(S)) + LPS = [0] * len(S1) + center = right = 0 + + for i in range(1, len(S1) - 1): + mirror = 2 * center - i + if i < right: + LPS[i] = min(right - i, LPS[mirror]) + + while S1[i + LPS[i] + 1] == S1[i - (LPS[i] + 1)]: + LPS[i] += 1 + + if i + LPS[i] > right: + center = i + right = i + LPS[i] + + max_len, centerIndex = max((j, i) for i, j in enumerate(LPS)) + start = (centerIndex - max_len) // 2 + end = (centerIndex + max_len) // 2 + return S[start:end] + +def MaxPalindromicChainInc(chain): + gem_values = {'D': 500, 'R': 250, 'E': 100} + longest_palindrome = manachers_algorithm(chain) + + if not longest_palindrome: + return 0 + + print(f"Longest Plaindrome: {longest_palindrome}") + + gem_sum = 0 + for gem in longest_palindrome: + gem_sum += gem_values[gem] + + profit = gem_sum * len(longest_palindrome) + return profit + +if __name__ == "__main__": + chain = input("Enter Your Chain: ").strip() + profit = MaxPalindromicChainInc(chain) + print(f"Chain: {chain} -> Max Profit: ${profit}") + diff --git a/Solutions/python3_the-ai-developer_Josephus-Problem.py b/Solutions/python3_the-ai-developer_Josephus-Problem.py new file mode 100644 index 0000000..d6e9005 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Josephus-Problem.py @@ -0,0 +1,9 @@ +def Josephus(List,CrntIdx,k): + if len(List)==1: + return List[0] + CrntIdx=(CrntIdx+k)%len(List) + del List[CrntIdx] + return Josephus(List,CrntIdx,k) + +NPpl,k=list(map(int,input("Enter No.Of Peoples And The Kill Count: ").split())) +print(f"In Order To Be In A Safe Zone, You Need To Stand At: {Josephus([x for x in range(1,NPpl+1)],0,k-1)}") diff --git a/Solutions/python3_the-ai-developer_Min-Swap-Sort.py b/Solutions/python3_the-ai-developer_Min-Swap-Sort.py new file mode 100644 index 0000000..337aca1 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Min-Swap-Sort.py @@ -0,0 +1,27 @@ +def MinSwaps2Sort(arr): + n = len(arr) + paired = [(arr[i], i) for i in range(n)] + paired.sort(key=lambda x: x[0]) + + visited = [False] * n + swaps = 0 + + for i in range(n): + if visited[i] or paired[i][1] == i: + continue + + cycle_length = 0 + current = i + while not visited[current]: + visited[current] = True + next_index = paired[current][1] + current = next_index + cycle_length += 1 + + if cycle_length > 1: + swaps += (cycle_length - 1) + + return swaps + +print(f"Min No.Of Swaps: {MinSwaps2Sort(list(map(int,input('Enter Graph List: ').split(' '))))}") + diff --git a/Solutions/python3_the-ai-developer_Plant-Growth-Tracker.py b/Solutions/python3_the-ai-developer_Plant-Growth-Tracker.py new file mode 100644 index 0000000..f348422 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Plant-Growth-Tracker.py @@ -0,0 +1,3 @@ +import math +N = int(input("Enter No.Of Months: ")) +print(f"No.Of Plants(Predicted!): {int(((1+math.sqrt(5))**N-(1-math.sqrt(5))**N)/(2**N*math.sqrt(5)))}") diff --git a/Solutions/python3_the-ai-developer_Smart-Ticketing-System.py b/Solutions/python3_the-ai-developer_Smart-Ticketing-System.py new file mode 100644 index 0000000..589832b --- /dev/null +++ b/Solutions/python3_the-ai-developer_Smart-Ticketing-System.py @@ -0,0 +1,40 @@ +from collections import deque + +def TktCounter(N, requests): + vip_queue = deque() + regular_queue = deque() + result = [] + + for request in requests: + parts = request.split() + name = parts[0] + tickets_requested = int(parts[1]) + is_vip = "VIP" in parts + if is_vip: + vip_queue.append((name, tickets_requested)) + else: + regular_queue.append((name, tickets_requested)) + + while N > 0 and (vip_queue or regular_queue): + if vip_queue: + customer, tickets_requested = vip_queue.popleft() + else: + customer, tickets_requested = regular_queue.popleft() + + if tickets_requested <= N: + result.append(f"{customer} purchased {tickets_requested} tickets") + N -= tickets_requested + else: + result.append(f"{customer} purchased {N} tickets") + N = 0 + + for queue in [vip_queue, regular_queue]: + while queue: + customer, _ = queue.popleft() + result.append(f"{customer} was not served") + + return result + +N = int(input("Enter No.Of Tickets: ")) +Req_Booking = list(map(str,input("Enter Ticket Requests: ").split(","))) +print(f"Reservation Sheet!\n{TktCounter(N,Req_Booking)}") diff --git a/Solutions/python3_the-ai-developer_Split-The-Squad.py b/Solutions/python3_the-ai-developer_Split-The-Squad.py new file mode 100644 index 0000000..af389f3 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Split-The-Squad.py @@ -0,0 +1,39 @@ +from collections import Counter + +def SplitTheSquad(): + T = int(input("Enter No.Of Entities: ")) + results = [] + + for x in range(T): + N, K, D = map(int, input(f"Enter The Values Of N,K And D Of Entity {x+1}: ").split()) + A = list(map(int, input(f"Enter The List(A) Of Entitity {x+1}: ").split())) + freq = Counter(A) + U_total = len(freq) + + if U_total < 2 * K: + results.append("NO") + continue + + counts = sorted(freq.values(), reverse=True) + team1_count, team2_count = 0, 0 + team1_uniques, team2_uniques = 0, 0 + + for count in counts: + if team1_uniques < K: + team1_count += count + team1_uniques += 1 + elif team2_uniques < K: + team2_count += count + team2_uniques += 1 + else: + break + + if team1_uniques == K and team2_uniques == K and abs(team1_count - team2_count) <= D: + results.append("YES") + else: + results.append("NO") + + print("\n".join(results)) + +SplitTheSquad() + diff --git a/Solutions/python3_the-ai-developer_Target-Pair-Finder.py b/Solutions/python3_the-ai-developer_Target-Pair-Finder.py new file mode 100644 index 0000000..1c84aa2 --- /dev/null +++ b/Solutions/python3_the-ai-developer_Target-Pair-Finder.py @@ -0,0 +1,12 @@ +IntList=list(map(int,input("Enter List Of Integers: ").split(" "))) +Trgt=int(input("Enter Target Sum: ")) +def twoSum(nums, target): + Res=[] + n = len(nums) + for i in range(n - 1): + for j in range(i,n): + if nums[i] + nums[j] == target: + Res.append([nums[i],nums[j]]) + return Res + +print(f"Solution Arr: {twoSum(IntList,Trgt)}") diff --git a/Solutions/python3_the-ai-developer_The-Magical-Tower.py b/Solutions/python3_the-ai-developer_The-Magical-Tower.py new file mode 100644 index 0000000..d1116fa --- /dev/null +++ b/Solutions/python3_the-ai-developer_The-Magical-Tower.py @@ -0,0 +1,10 @@ +def GenMagicalTower(n): + tower = [] + for i in range(n): + row = [1] * (i + 1) + for j in range(1, i): + row[j] = tower[i-1][j-1] + tower[i-1][j] + tower.append(row) + return tower + +print(f"Resultant Tower: {GenMagicalTower(int(input('Enter No.Of Floors: ')))}") diff --git a/Solutions/python3_the-ai-developer_The-Robot-Returns.py b/Solutions/python3_the-ai-developer_The-Robot-Returns.py new file mode 100644 index 0000000..e0051fd --- /dev/null +++ b/Solutions/python3_the-ai-developer_The-Robot-Returns.py @@ -0,0 +1,2 @@ +moves = input("Enter Path: ") +print(f"{True if (moves.count('U') - moves.count('D') == 0 and moves.count('L') - moves.count('R') == 0) else False}") diff --git a/Solutions/python3_the-ai-developer_The-Vanishing-Number.py b/Solutions/python3_the-ai-developer_The-Vanishing-Number.py new file mode 100644 index 0000000..4ee999c --- /dev/null +++ b/Solutions/python3_the-ai-developer_The-Vanishing-Number.py @@ -0,0 +1 @@ +print(f"Missing Player: {int((lambda n: n*(n+1)/2 - sum(map(int, input('Enter Players: ').split())))(int(input('Enter No.Of Players: '))))}") diff --git a/Solutions/python3_the-ai-developer_The-Wave-Sort.py b/Solutions/python3_the-ai-developer_The-Wave-Sort.py new file mode 100644 index 0000000..2703f73 --- /dev/null +++ b/Solutions/python3_the-ai-developer_The-Wave-Sort.py @@ -0,0 +1,8 @@ +Arr = list(map(int,input("Enter A List: ").split(" "))) +for i in range(0,len(Arr)-1,2): + if i+1 < len(Arr) and Arr[i] < Arr[i+1]: + Arr[i],Arr[i+1] = Arr[i+1], Arr[i] + if i+2Arr[i+2]: + Arr[i+1], Arr[i+2] = Arr[i+2], Arr[i+1] + +print(Arr) diff --git a/Solutions/python3_the-ai-developer_Train-Platform-Calculation.py b/Solutions/python3_the-ai-developer_Train-Platform-Calculation.py new file mode 100644 index 0000000..e2e957f --- /dev/null +++ b/Solutions/python3_the-ai-developer_Train-Platform-Calculation.py @@ -0,0 +1,20 @@ +def CalcMinReqPlatforms(arr, dept): + + """ arr.sort() + dept.sort()""" + i = j = 0 + platforms = 0 + max_platforms = 0 + + while i < len(arr) and j < len(dept): + if arr[i] <= dept[j]: + platforms += 1 + i += 1 + max_platforms = max(max_platforms, platforms) + else: + platforms -= 1 + j += 1 + + return max_platforms + +print(f"Minimum Platforms Required: {CalcMinReqPlatforms(list(map(int,input('Enter Arrival Timings: ').split())),list(map(int,input('Enter Departure Timings: ').split())))}") diff --git a/python3_the-ai-developer_Smart-Ticketing-System.py b/python3_the-ai-developer_Smart-Ticketing-System.py new file mode 100644 index 0000000..e69de29