diff --git a/Week03/pyramid_hilmi_aydin.py b/Week03/pyramid_hilmi_aydin.py new file mode 100644 index 00000000..c1c3a2f1 --- /dev/null +++ b/Week03/pyramid_hilmi_aydin.py @@ -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 diff --git a/Week03/sequences_hilmi_aydin.py b/Week03/sequences_hilmi_aydin.py new file mode 100644 index 00000000..2cbd3265 --- /dev/null +++ b/Week03/sequences_hilmi_aydin.py @@ -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()} \ No newline at end of file