Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7d40fd9
Solution for #01
darshaandaghicha Dec 22, 2021
8beae6b
Solution for #02
darshaandaghicha Dec 22, 2021
55d2457
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 22, 2021
474d189
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 26, 2021
f641044
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 27, 2021
063950b
Solution for #3
darshaandaghicha Dec 27, 2021
809ce3b
Merge branch 'main' of https://github.com/DSAghicha/A-December-of-Alg…
darshaandaghicha Dec 27, 2021
35c4f95
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 27, 2021
cd33ff6
Solution for #05
darshaandaghicha Dec 27, 2021
e928516
Merge branch 'main' of https://github.com/DSAghicha/A-December-of-Alg…
darshaandaghicha Dec 27, 2021
0ec707f
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 29, 2021
c0be6f0
Solution for #06
darshaandaghicha Dec 29, 2021
7bba63a
Merge branch 'main' of https://github.com/DSAghicha/A-December-of-Alg…
darshaandaghicha Dec 29, 2021
4eb84cc
Solution for #10
darshaandaghicha Dec 29, 2021
f441269
Solution for #10
darshaandaghicha Dec 29, 2021
270ad0f
Solution for #12
darshaandaghicha Dec 29, 2021
28f0d6e
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 30, 2021
0d5e66a
Merge branch 'SVCE-ACM:main' into main
darshaandaghicha Dec 31, 2021
c525708
Solution for #08
darshaandaghicha Jan 1, 2022
1085c50
Merge branch 'main' of https://github.com/DSAghicha/A-December-of-Alg…
darshaandaghicha Jan 1, 2022
8b14ab5
Solution for #07
darshaandaghicha Jan 1, 2022
48df464
Rectified return type of function
darshaandaghicha Jan 1, 2022
ba42b48
Solution for #13
darshaandaghicha Jan 2, 2022
3179624
Revert "Solution for #13"
darshaandaghicha Jan 2, 2022
c7ff516
Solution for #13
darshaandaghicha Jan 2, 2022
fc8b5fa
Solution for #14
darshaandaghicha Jan 3, 2022
ba1a3ad
Revert "Solution for #14"
darshaandaghicha Jan 3, 2022
335f97a
Solution for #14
darshaandaghicha Jan 3, 2022
43a186f
Revert "Not supportable @ 3.10"
darshaandaghicha Jan 3, 2022
8a07e7c
Solution for #14
darshaandaghicha Jan 3, 2022
c87e812
Solution for #09
darshaandaghicha Jan 3, 2022
b908411
Solution for #15
darshaandaghicha Jan 7, 2022
d2effd2
refractor: Added EOF
darshaandaghicha Jan 7, 2022
905763c
Solution for #16
darshaandaghicha Jan 9, 2022
c1e2408
Solution for #17
darshaandaghicha Jan 9, 2022
ad770d2
Solution for #18
darshaandaghicha Jan 9, 2022
208d45e
Solution for #19
darshaandaghicha Jan 9, 2022
ce76a47
bug: Removed Safe Check
darshaandaghicha Jan 9, 2022
4a9cdc3
Solution for #21
darshaandaghicha Jan 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions December-01/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# #1 Elegant Facelift
# @Author: DSAghicha (Darshaan Aghicha)

def common_char(all_str: list[str]) -> int:
"""
Identifies common characters in words of a list.

Keyword Arguments:
all_str: List of words

Returns number of letters repeated.
"""
rep_letters: int = 0
limit: int = len(all_str)
char_dict: dict[str: list[int]] = {}

for word in all_str:
unique: set[str] = set(word)
for letter in unique:
occurrence: int = word.count(letter)
try:
char_dict[letter].append(occurrence)
except KeyError:
char_dict[letter] = [occurrence]

for key in char_dict:
if len(char_dict[key]) == limit:
rep_letters += 1
return rep_letters


def main():
words: list = [word for word in input("Enter space separated list of stones: ").split()]
print(common_char(words))


if __name__ == '__main__':
main()
37 changes: 37 additions & 0 deletions December-02/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# #02 Bingo!
# @DSAghicha (Darshaan Aghicha)

def sum_of_squares(number: int) -> None:
"""
Calculates sum of square of digits in the number, and calls itself until condition fails.
Conditions:
- number is not a positive integer. (prints "NO")
- sum = 1. (prints "YES")
Args:
number: int
Returns:
None
"""
if number > 0:
num: list[int] = [int(n) for n in str(number)]
sum_num: int = 0
for n in num:
sum_num += n ** 2
try:
if sum_num != 1:
sum_of_squares(sum_num)
else:
print("YES")
except RecursionError:
print("NO")
else:
print("NO")


def main() -> None:
num: int = int(input("Enter the Number: "))
sum_of_squares(num)


if __name__ == '__main__':
main()
56 changes: 56 additions & 0 deletions December-03/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# #03 Lotto!
# @DSAghicha (Darshaan Aghicha)
def search_grid(board: list[list[str]], name: str) -> bool:
ROW, COL = len(board), len(board[0])
path = set()

def search(row, col, i):
if i == len(name):
return True

if (row < 0 or col < 0 or row >= ROW or col >= COL or name[i] != board[row][col] or (row, col) in path):
False

path.add((row, col))

result = (search(row + 1, col, i + 1) or search(row - 1, col, i + 1) or search(row, col + 1, i + 1) or search(row, col - 1, i + 1))

return result

for row in range(ROW):
for col in range(COL):
if search(row, col, 0):
return True

return False


def main():
try:
R: int = int(input("Enter the number of rows: "))
C: int = int(input("Enter the number of columns: "))
matrix: list[list[str]] = []

for _i in range(C):
letters: list[str] = input(f"Enter {R} letters (space seperated): ").split(' ')

while len(letters) != R:
print("\nIt seems like you missed some letters!\n")
letters: list[str] = input(f"Re-enter {R} letters (space seperated): ").split(' ')
matrix.append([letter.upper() for letter in letters])

word: str = input("Enter word to be searched: ")
while len(word) < 2:
print("Please input a proper word!")
word: str = input("Re-enter word to be searched: ")

print(search_grid(matrix, word.upper()))
except ValueError:
print("It was not a number!\n\n")
main()


if __name__ == "__main__":
# grid: list[list[str]] = [["D","J","O","G"],["W","B","H","S"],["T","Z","N","E"]]
# print(search_grid(grid, name="JOHN"))
main()
33 changes: 33 additions & 0 deletions December-05/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# #05 Biscuit Bonanza!
# @DSAghicha (Darshaan Aghicha)
def check(customers: list[int], biscuits: list[int]) -> None:
if not customers or not biscuits or biscuits[0] not in customers:
print(f"Customers that are unable to eat = {len(customers)}")
return

if customers[0] == biscuits[0]:
customers.pop(0)
biscuits.pop(0)
# print(f"Front customer takes the top biscuit and leaves the line making customers = {customers} and biscuits = {biscuits}.")
else:
first_item = customers[0]
customers.pop(0)
customers.append(first_item)
# print(f"Front customer leaves the top biscuit and returns to the end of the line making customers = {customers}.")
check(customers, biscuits)


def main() -> None:
try:
customers: list[int] = [int(choice) for choice in input("Enter customers choice (space separated): ").split(' ')]
biscuits: list[int] = [int(choice) for choice in input("Enter biscuits choice (space separated): ").split(' ')]
check(customers, biscuits)
except ValueError:
print("One or more values were not integer!")


if __name__ == '__main__':
# customers = [1,1,0,0,1,0]
# biscuits = [0,1,0,1,1,1]
# check(customers, biscuits)
main()
36 changes: 36 additions & 0 deletions December-06/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# #06 Save The Templars!
# @DSAghicha (Darshaan Aghicha)
def swaps(data: list[str]) -> int:
total: int = data.count('T')
curTemplars: int = 0

for i in range(total):
if data[i] == 'T':
curTemplars += 1

ans = curTemplars

for i in range(total, len(data)):
if data[i] == 'T':
curTemplars += 1

if data[i - total] == 'T':
curTemplars -= 1

ans = min(ans, curTemplars)

return ans

def main() -> None:
arrangement: list[str] = list(input("Enter arrangement sequence: "))
if arrangement:
arrangement = [i.upper() for i in arrangement]
print(swaps(arrangement))
else:
print("You didn't provide the sequence!!\n\nLet's try again")
main()



if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions December-07/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# #07 Amy helps Pawnee!
# @DSAghicha (Darshaan Aghicha)
def no_building(building_co: list[list[int]],axis: str, axis_no: int) -> int:
axis_rep: int = 0 if (axis == 'x') else 1
success: int = 0

for i in range(len(building_co)):
lt: bool = False
gt: bool = False
for j in range(axis_rep, 6, 2):
if building_co[i][j] < axis_no:
lt = True
elif building_co[i][j] > axis_no:
gt = True

if lt and gt: success += 1

return success

def main() -> None:
try:
successful_buildings: list[int] = []

# ? Getting Building Info
n: int = int(input("Enter number of buildings: "))
coordinates: list[list[int]] = []
print("Enter coordinates of the buildings:\n(Press Enter to enter coordinates of next building)")
for _ in range(n):
c: list[int] = [int(i) for i in input().split(' ')]
if len(c) == 6:
coordinates.append(c)
else:
print("You entered invalid number of coordinates!")
print("Each building must contain six coordinates\na1 b1 a2 b2 a3 b3\n\n")
main()

# ? Getting Plane Info
jet_planes = int(input("Enter number of jet-planes: "))
print("Enter axis and its coordinate (space separated):\n(Press Enter to enter coordinates of next plane)")
for _ in range(jet_planes):
c: list[str, int] = input().split()
if c[0] in ['x', 'y']:
units: int = no_building(coordinates, c[0], int(c[1]))
successful_buildings.append(units)
else:
print("Axis need to be X or Y!\n\n")
main()

# ? Printing Values
print("Buildings that received food:", *successful_buildings, sep= " ")
except ValueError:
print("I expected a number!!\n\n")
main()


if __name__ == "__main__":
main()
# no_building([[1, 0, 0, 2, 2, 2], [1, 3, 3, 5, 4, 0], [5, 4, 4, 5, 4, 4]], 'x', 2)
31 changes: 31 additions & 0 deletions December-08/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# #08 Anomalous Counter!
# @DSAghicha (Darshaan Aghicha)
def counter_value(timer: int) -> int:
if timer == 0:
return 0

counter_dial: int = 0
prev_dial: int = 0
cycle_dial: int = 0
counter = 0
while timer > counter_dial:
counter += 1
prev_dial = counter_dial
counter_dial = counter_dial + 3 * (2 ** cycle_dial)
cycle_dial += 1

return 3 * (2 ** (cycle_dial - 1)) - (timer - prev_dial) + 1



def main() -> None:
try:
time: int = int(input("Enter time: "))
value: int = counter_value(time)
print(f"Counter value = {value}")
except ValueError:
print("I expected a number!!\n\n")
main()

if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions December-09/python3_dsaghicha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# #09 Dream 11!
# @DSAghicha (Darshaan Aghicha)
def base_number(p:int, aptitude_ratings: list[int]) -> int:
revised_ratings: list[int] = [aptitude_ratings[i] for i in range(p)]
num1: int = revised_ratings[len(revised_ratings) - 1]
ans: int = 0
for i in range(len(revised_ratings) - 2, -1, -1):
ans += (num1 - revised_ratings[i])

return ans


def main() -> None:
try:
n: int = int(input("Enter number of understudies (n): "))
p: int = int(input("Enter number of understudies you wish to pick (p): "))
if n < 0 or p > n:
raise Exception
ar: list[int] = [int(N) for N in input(f"Enter the aptitude rating of {n} understudies (space separated): ").split(' ')]
sorted(ar)

print(f"Base number of periods required = {base_number(p, ar)}")

except ValueError:
print("I expected a number!!\n\n")
main()
except Exception:
print("Invalid Inputs!!\n\n")
main()


if __name__ == "__main__":
main()
Loading