diff --git a/Week03/pyramid_tarik_bozgan.py b/Week03/pyramid_tarik_bozgan.py new file mode 100644 index 0000000..9bd324b --- /dev/null +++ b/Week03/pyramid_tarik_bozgan.py @@ -0,0 +1,6 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + while number_of_blocks >= 0: + height += 1 + number_of_blocks -= height + return height - 1 diff --git a/Week03/sequences_tarik_bozgan.py b/Week03/sequences_tarik_bozgan.py new file mode 100644 index 0000000..1ba0206 --- /dev/null +++ b/Week03/sequences_tarik_bozgan.py @@ -0,0 +1,23 @@ +def remove_duplicates(seq): + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq): + counts = {} + for item in seq: + if item in counts: + counts[item] += 1 + else: + counts[item] = 1 + return counts + + +def reverse_dict(d): + reversed_dict = {} + for key, value in d.items(): + reversed_dict[value] = key + return reversed_dict \ No newline at end of file diff --git a/Week04/arrays_tarik_bozgan.py b/Week04/arrays_tarik_bozgan.py new file mode 100644 index 0000000..2d51c11 --- /dev/null +++ b/Week04/arrays_tarik_bozgan.py @@ -0,0 +1,20 @@ +import numpy as np + +def replace_center_with_minus_one(d, n, m): + if m > n: + raise ValueError("m cannot be greater than n") + if d <= 0: + raise ValueError("d must be greater than 0") + if n < 0: + raise ValueError("n must be greater than or equal to 0") + if m < 0: + raise ValueError("m must be greater than or equal to 0") + + arr = np.random.randint(10**(d-1), 10**d, size=(n, n)) + + start_index = (n - m) // 2 + end_index = start_index + m + + arr[start_index:end_index, start_index:end_index] = -1 + + return arr \ No newline at end of file