Skip to content
8 changes: 8 additions & 0 deletions .idea/A-December-Of-Algorithms-2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions December 01/python3_lakshminarayanans_cricmetric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Module documentation: count_runs

This module defines a function count_runs to calculate the total runs scored by a given number of batsmen.
It also tracks the highest run scored and the corresponding batsman index.

Usage:
total_n = int(input("Enter the total number of batsmen: "))
count_runs(total_n)
"""


def count_runs(total_n):
"""
Calculate the total runs scored by a given number of batsmen and track the highest run scored.

Parameters:
total_n (int): The total number of batsmen.

Returns:
None
"""

runs = 0
highest = 0
highest_index = 0

for i in range(total_n):
run = int(input(f"Enter the runs scored by batsman {i + 1}: "))
runs += run

if highest < run:
highest = run
highest_index = i

print("Total Runs:", runs)
print("Batsman with the highest run:", highest_index)


if __name__ == "__main__":
total_n = int(input("Enter the total number of batsmen: "))
count_runs(total_n)
44 changes: 44 additions & 0 deletions December 02/python3_lakshminarayanans_shopperschoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Module documentation: shoppers_frequency

This module defines a function shoppers_frequency to calculate the frequency of each unique product ID in a given list.

Usage:
product_ids = [2, 2, 3, 4, 5, 6, 2, 4, 6, 7]
shoppers_frequency(product_ids)
"""

def shoppers_frequency(product_ids):
"""
Calculate the frequency of each unique product ID in the given list.

Parameters:
product_ids (list): A list of product IDs.

Returns:
None
"""

unique_ids = []
final_frequency = []

for i in range(len(product_ids)):
counter = 0
current_val = product_ids[i]

if current_val not in unique_ids:
unique_ids.append(current_val)

for j in range(i, len(product_ids)):
if product_ids[j] == product_ids[i]:
counter += 1

final_frequency.append(counter)

print("Output")
print(final_frequency)


if __name__ == "__main__":
product_ids = [2, 2, 3, 4, 5, 6, 2, 4, 6, 7]
shoppers_frequency(product_ids)
36 changes: 36 additions & 0 deletions December 03/python3_lakshminarayanans_sunburnt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Module documentation: count_buildings_with_sunrise

This module defines a function count_buildings_with_sunrise to determine the number of buildings with a sunrise view.

Usage:
buildings_height = [7, 4, 8, 2, 9]
count_buildings_with_sunrise(buildings_height)
"""

def count_buildings_with_sunrise(buildings_height):
"""
Count the number of buildings with a sunrise view based on their heights.

Parameters:
buildings_height (list): A list representing the heights of buildings.

Returns:
None
"""

count = 1
highest = buildings_height[0]

for height in buildings_height[1:]:
if height > highest:
count += 1
highest = height

print("Output")
print(count)


if __name__ == "__main__":
buildings_height = [7, 4, 8, 2, 9]
count_buildings_with_sunrise(buildings_height)
54 changes: 54 additions & 0 deletions December 04/python3_lakshminarayanans_mirrormagic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Module documentation: Mirror Magic

This module defines a function find_palindromic_substring to find the smallest palindromic substring in a given string.

Usage:
input_name_1 = "Hollow"
output_1 = find_palindromic_substring(input_name_1)
print("Input:", input_name_1)
print("Output:", output_1)

input_name_2 = "Master"
output_2 = find_palindromic_substring(input_name_2)
print("\nInput:", input_name_2)
print("Output:", output_2)
"""


def find_palindromic_substring(name):
"""
Find the smallest palindromic substring in a given string.

Parameters:
name (str): The input string.

Returns:
str: The smallest palindromic substring, or "Error" if none is found.
"""
length = len(name)
possibilities = []

for i in range(length):
for j in range(i + 1, length + 1):
substring = name[i:j]
if substring == substring[::-1] and len(substring) > 1:
possibilities.append(substring)

if len(possibilities) < 1:
return "Error"
else:
return min(possibilities)


if __name__ == "__main__":
# Example Usage
input_name_1 = "Hollow"
output_1 = find_palindromic_substring(input_name_1)
print("Input:", input_name_1)
print("Output:", output_1)

input_name_2 = "Master"
output_2 = find_palindromic_substring(input_name_2)
print("\nInput:", input_name_2)
print("Output:", output_2)
Loading