Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions Week03/pyramid_hilmi_aydin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def calculate_pyramid_height(number_of_blocks):
# Initialize the height of the pyramid
height = 0
# Blocks required for the current layer
layer_blocks = 1

# Continue building layers as long as there are enough blocks
while number_of_blocks >= layer_blocks:
# Subtract used blocks from the total
number_of_blocks -= layer_blocks
# Increase pyramid height by 1
height += 1
# Next layer needs one more block
layer_blocks += 1

return height
23 changes: 23 additions & 0 deletions Week03/sequences_hilmi_aydin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def remove_duplicates(seq: list) -> list:
"""
This function removes duplicates from a list.
"""
# Convert list to dictionary to remove duplicates, then back to list while preserving order
return list(dict.fromkeys(seq))

def list_counts(seq: list) -> dict:
"""
This function counts the number of occurrences of each item in a list.
"""
counts = {}
for item in seq:
# If item exists, increment its count. Otherwise, default to 0 and add 1
counts[item] = counts.get(item, 0) + 1
return counts

def reverse_dict(d: dict) -> dict:
"""
This function reverses the keys and values of a dictionary.
"""
# Swap keys and values using dictionary comprehension
return {value: key for key, value in d.items()}
Loading