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
6 changes: 6 additions & 0 deletions Week03/pyramid_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions Week03/sequences_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions Week04/arrays_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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