Skip to content

Commit

Permalink
hw moved
Browse files Browse the repository at this point in the history
  • Loading branch information
canbula committed Nov 23, 2023
1 parent 70d61bd commit 3b6690b
Show file tree
Hide file tree
Showing 47 changed files with 234 additions and 234 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 22 additions & 22 deletions Week04/arrays_eren_aydogdu.py → Week04/hw/arrays_eren_aydogdu.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
## Abdullah Eren Aydoğdu, 200315040

import numpy as np


def replace_center_with_minus_one(d: int, n: int, m: int) -> np.ndarray:

if d <= 0:
raise ValueError("d must be greater than or equal to zero")
if m > n:
raise ValueError("m must be less than or equal to n")
if n < 0:
raise ValueError("n must be greater than zero")
if m < 0:
raise ValueError("m must be greater than zero")

arr = np.random.randint(0, (10 ** d), size=(n,n))

center = (n - m) // 2

arr[center:center + m, center:center + m] = -1

## Abdullah Eren Aydoğdu, 200315040

import numpy as np


def replace_center_with_minus_one(d: int, n: int, m: int) -> np.ndarray:

if d <= 0:
raise ValueError("d must be greater than or equal to zero")
if m > n:
raise ValueError("m must be less than or equal to n")
if n < 0:
raise ValueError("n must be greater than zero")
if m < 0:
raise ValueError("m must be greater than zero")

arr = np.random.randint(0, (10 ** d), size=(n,n))

center = (n - m) // 2

arr[center:center + m, center:center + m] = -1

return arr
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import numpy as np

def replace_center_with_minus_one(d, n, m):
if m > n:
raise ValueError("m should be less than or equal to n")
if d <= 0:
raise ValueError("d should be greater than 0")
if n < 0:
raise ValueError("n should be a positive integer")
if m < 0:
raise ValueError("m should be a positive integer")

rand_array = np.random.randint(10**d, size=(n, n))
center_start = (n - m) // 2
center_end = center_start + m

rand_array[center_start:center_end, center_start:center_end] = -1

return rand_array







import numpy as np

def replace_center_with_minus_one(d, n, m):
if m > n:
raise ValueError("m should be less than or equal to n")
if d <= 0:
raise ValueError("d should be greater than 0")
if n < 0:
raise ValueError("n should be a positive integer")
if m < 0:
raise ValueError("m should be a positive integer")

rand_array = np.random.randint(10**d, size=(n, n))
center_start = (n - m) // 2
center_end = center_start + m

rand_array[center_start:center_end, center_start:center_end] = -1

return rand_array








File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import numpy as np


def replace_center_with_minus_one(d, n, m):
if m > n:
raise ValueError("m can't be greater than n")
elif d <= 0:
raise ValueError("d must be greater than 0")
elif m < 0 or n < 0:
raise ValueError("m or n can't be lesser than 0")

numpy_array = np.random.randint(0, 10 ** d, size=(n, n))

start_corner = (n-m) // 2
end_row_or_col = start_corner + m-1

for r in range(start_corner,end_row_or_col+1):
for c in range(start_corner, end_row_or_col+1):
numpy_array[r,c] = -1

return numpy_array
import numpy as np


def replace_center_with_minus_one(d, n, m):
if m > n:
raise ValueError("m can't be greater than n")
elif d <= 0:
raise ValueError("d must be greater than 0")
elif m < 0 or n < 0:
raise ValueError("m or n can't be lesser than 0")

numpy_array = np.random.randint(0, 10 ** d, size=(n, n))

start_corner = (n-m) // 2
end_row_or_col = start_corner + m-1

for r in range(start_corner,end_row_or_col+1):
for c in range(start_corner, end_row_or_col+1):
numpy_array[r,c] = -1

return numpy_array
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np
def replace_center_with_minus_one(d, n, m):
if m > n or d <= 0 or n < 0 or m < 0:
raise ValueError("Invalid input parameters")
random_array = np.random.randint(10**d, size=(n, n))
start_row = (n - m) // 2
end_row = start_row + m
start_col = (n - m) // 2
end_col = start_col + m
modified_array = np.copy(random_array)
modified_array[start_row:end_row, start_col:end_col] = -1
return modified_array
import numpy as np
def replace_center_with_minus_one(d, n, m):
if m > n or d <= 0 or n < 0 or m < 0:
raise ValueError("Invalid input parameters")
random_array = np.random.randint(10**d, size=(n, n))
start_row = (n - m) // 2
end_row = start_row + m
start_col = (n - m) // 2
end_col = start_col + m
modified_array = np.copy(random_array)
modified_array[start_row:end_row, start_col:end_col] = -1
return modified_array
32 changes: 16 additions & 16 deletions Week04/arrays_sedef_elmas.py → Week04/hw/arrays_sedef_elmas.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import numpy as np
import random

def replace_center_with_minus_one(d, n, m):
if n < 0 or m < 0 or d <= 0 or m > n:
raise ValueError("Error: Invalid values!!")

array = np.random.randint(10**(d - 1), 10**d, size=(n, n))
x = (n - m) // 2
y = x + m

for i in range(x, y):
for j in range(x, y):
array[i, j] = -1

return array
import numpy as np
import random

def replace_center_with_minus_one(d, n, m):
if n < 0 or m < 0 or d <= 0 or m > n:
raise ValueError("Error: Invalid values!!")

array = np.random.randint(10**(d - 1), 10**d, size=(n, n))
x = (n - m) // 2
y = x + m

for i in range(x, y):
for j in range(x, y):
array[i, j] = -1

return array
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 18 additions & 18 deletions Week04/arrays_yaser_beker.py → Week04/hw/arrays_yaser_beker.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import numpy as np

def replace_center_with_minus_one(d, n, m):
if m > n or d <= 0 or n < 0 or m < 0:
raise ValueError("Invalid input parameters")

# Create an n-by-n array with random integers up to d digits
random_array = np.random.randint(10**d, size=(n, n))

# Find the starting and ending indices for the center region
start_index = (n - m) // 2
end_index = start_index + m

# Create a copy of the random array and replace the center with -1
modified_array = random_array.copy()
modified_array[start_index:end_index, start_index:end_index] = -1

return modified_array
import numpy as np

def replace_center_with_minus_one(d, n, m):
if m > n or d <= 0 or n < 0 or m < 0:
raise ValueError("Invalid input parameters")

# Create an n-by-n array with random integers up to d digits
random_array = np.random.randint(10**d, size=(n, n))

# Find the starting and ending indices for the center region
start_index = (n - m) // 2
end_index = start_index + m

# Create a copy of the random array and replace the center with -1
modified_array = random_array.copy()
modified_array[start_index:end_index, start_index:end_index] = -1

return modified_array
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
122 changes: 61 additions & 61 deletions Week05/bra_yaser_beker.py → Week05/hw/bra_yaser_beker.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
from flask import Flask, request, jsonify

class BinaryRepresentation:
def __init__(self, number):
if isinstance(number, bool):
raise TypeError("Unexpected data format, anticipated input of type int or float")
if not isinstance(number, (int, float)):
raise TypeError("Unexpected data format, anticipated input of type int, float or bool")
self.number = number

def integer2binary(self):
integer_part = int(self.number)
binary_string = ""
while integer_part > 0:
remainder = integer_part % 2
integer_part //= 2
binary_string += str(remainder)

return binary_string[::-1]

def decimal2binary(self):
decimal_part = abs(self.number - int(self.number))
binary_string = ""

while decimal_part != 0 and len(binary_string) < 10:
decimal_part *= 2
binary_integer_part = int(decimal_part)
binary_string += str(binary_integer_part)
decimal_part -= binary_integer_part

return binary_string

def __str__(self):
integer_binary = self.integer2binary()
decimal_binary = self.decimal2binary()

# Ensure integer part is always displayed
if integer_binary == "":
integer_binary = "0"

return f"{integer_binary}.{decimal_binary}"


app = Flask(__name__)

@app.route('/', methods=['GET'])
def convert_to_binary():
number = request.args.get('number')

if number is None:
return jsonify({"error": "Please send a GET request to /?number=<number>"}), 400

try:
number = float(request.args['number'])
binary_representation = BinaryRepresentation(number)
return jsonify({'binary_representation': str(binary_representation)})
except (TypeError, ValueError):
return jsonify({"error": "Please send a GET request to /?number=<number> with a valid number"}), 400

if __name__ == '__main__':
app.run(debug=True)
from flask import Flask, request, jsonify

class BinaryRepresentation:
def __init__(self, number):
if isinstance(number, bool):
raise TypeError("Unexpected data format, anticipated input of type int or float")
if not isinstance(number, (int, float)):
raise TypeError("Unexpected data format, anticipated input of type int, float or bool")
self.number = number

def integer2binary(self):
integer_part = int(self.number)
binary_string = ""
while integer_part > 0:
remainder = integer_part % 2
integer_part //= 2
binary_string += str(remainder)

return binary_string[::-1]

def decimal2binary(self):
decimal_part = abs(self.number - int(self.number))
binary_string = ""

while decimal_part != 0 and len(binary_string) < 10:
decimal_part *= 2
binary_integer_part = int(decimal_part)
binary_string += str(binary_integer_part)
decimal_part -= binary_integer_part

return binary_string

def __str__(self):
integer_binary = self.integer2binary()
decimal_binary = self.decimal2binary()

# Ensure integer part is always displayed
if integer_binary == "":
integer_binary = "0"

return f"{integer_binary}.{decimal_binary}"


app = Flask(__name__)

@app.route('/', methods=['GET'])
def convert_to_binary():
number = request.args.get('number')

if number is None:
return jsonify({"error": "Please send a GET request to /?number=<number>"}), 400

try:
number = float(request.args['number'])
binary_representation = BinaryRepresentation(number)
return jsonify({'binary_representation': str(binary_representation)})
except (TypeError, ValueError):
return jsonify({"error": "Please send a GET request to /?number=<number> with a valid number"}), 400

if __name__ == '__main__':
app.run(debug=True)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3b6690b

Please sign in to comment.