Skip to content

[ImgBot] Optimize images #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Binary file modified arithmetic_analysis/image_data/2D_problems.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified arithmetic_analysis/image_data/2D_problems_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def newton_raphson(func: str, a: int, precision: int = 10 ** -10) -> float:
""" Finds root from the point 'a' onwards by Newton-Raphson method
"""Finds root from the point 'a' onwards by Newton-Raphson method
>>> newton_raphson("sin(x)", 2)
3.1415926536808043
>>> newton_raphson("x**2 - 5*x +2", 0.4)
Expand Down
8 changes: 4 additions & 4 deletions backtracking/all_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def generate_all_permutations(sequence):

def create_state_space_tree(sequence, current_sequence, index, index_used):
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly len(sequence) - index children.
It terminates when it reaches the end of the given sequence.
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly len(sequence) - index children.
It terminates when it reaches the end of the given sequence.
"""

if index == len(sequence):
print(current_sequence)
Expand Down
8 changes: 4 additions & 4 deletions backtracking/all_subsequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def generate_all_subsequences(sequence):

def create_state_space_tree(sequence, current_subsequence, index):
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""
Creates a state space tree to iterate through each branch using DFS.
We know that each state has exactly two children.
It terminates when it reaches the end of the given sequence.
"""

if index == len(sequence):
print(current_subsequence)
Expand Down
12 changes: 6 additions & 6 deletions backtracking/n_queens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def isSafe(board, row, column):
"""
This function returns a boolean value True if it is safe to place a queen there considering
This function returns a boolean value True if it is safe to place a queen there considering
the current state of the board.

Parameters :
Expand Down Expand Up @@ -40,13 +40,13 @@ def isSafe(board, row, column):

def solve(board, row):
"""
It creates a state space tree and calls the safe function until it receives a
False Boolean and terminates that branch and backtracks to the next
It creates a state space tree and calls the safe function until it receives a
False Boolean and terminates that branch and backtracks to the next
poosible solution branch.
"""
if row >= len(board):
"""
If the row number exceeds N we have board with a successful combination
If the row number exceeds N we have board with a successful combination
and that combination is appended to the solution list and the board is printed.

"""
Expand All @@ -56,9 +56,9 @@ def solve(board, row):
return
for i in range(len(board)):
"""
For every row it iterates through each column to check if it is feesible to place a
For every row it iterates through each column to check if it is feesible to place a
queen there.
If all the combinations for that particular branch are successful the board is
If all the combinations for that particular branch are successful the board is
reinitialized for the next possible combination.
"""
if isSafe(board, row, i):
Expand Down
2 changes: 1 addition & 1 deletion backtracking/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def sudoku(grid):
[7, 4, 5, 2, 8, 6, 3, 1, 9]]
>>> sudoku(no_solution)
False
"""
"""

if is_completed(grid):
return grid
Expand Down
10 changes: 5 additions & 5 deletions backtracking/sum_of_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def generate_sum_of_subsets_soln(nums, max_sum):

def create_state_space_tree(nums, max_sum, num_index, path, result, remaining_nums_sum):
"""
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
Creates a state space tree to iterate through each branch using DFS.
It terminates the branching of a node when any of the two conditions
given below satisfy.
This algorithm follows depth-fist-search and backtracks when the node is not branchable.

"""
"""
if sum(path) > max_sum or (remaining_nums_sum + sum(path)) < max_sum:
return
if sum(path) == max_sum:
Expand Down
10 changes: 5 additions & 5 deletions blockchain/modular_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def modular_division2(a, b, n):

def extended_gcd(a, b):
"""
>>> extended_gcd(10, 6)
(2, -1, 2)
>>> extended_gcd(10, 6)
(2, -1, 2)

>>> extended_gcd(7, 5)
(1, -2, 3)
>>> extended_gcd(7, 5)
(1, -2, 3)

** extended_gcd function is used when d = gcd(a,b) is required in output
** extended_gcd function is used when d = gcd(a,b) is required in output

"""
assert a >= 0 and b >= 0
Expand Down
70 changes: 35 additions & 35 deletions ciphers/xor_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
class XORCipher:
def __init__(self, key=0):
"""
simple constructor that receives a key or uses
default key = 0
"""
simple constructor that receives a key or uses
default key = 0
"""

# private field
self.__key = key

def encrypt(self, content, key):
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(key, int) and isinstance(content, str)
Expand All @@ -55,11 +55,11 @@ def encrypt(self, content, key):

def decrypt(self, content, key):
"""
input: 'content' of type list and 'key' of type int
output: decrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type list and 'key' of type int
output: decrypted string 'content' as a list of chars
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(key, int) and isinstance(content, list)
Expand All @@ -80,11 +80,11 @@ def decrypt(self, content, key):

def encrypt_string(self, content, key=0):
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: encrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(key, int) and isinstance(content, str)
Expand All @@ -105,11 +105,11 @@ def encrypt_string(self, content, key=0):

def decrypt_string(self, content, key=0):
"""
input: 'content' of type string and 'key' of type int
output: decrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: 'content' of type string and 'key' of type int
output: decrypted string 'content'
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(key, int) and isinstance(content, str)
Expand All @@ -130,12 +130,12 @@ def decrypt_string(self, content, key=0):

def encrypt_file(self, file, key=0):
"""
input: filename (str) and a key (int)
output: returns true if encrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: filename (str) and a key (int)
output: returns true if encrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(file, str) and isinstance(key, int)
Expand All @@ -155,12 +155,12 @@ def encrypt_file(self, file, key=0):

def decrypt_file(self, file, key):
"""
input: filename (str) and a key (int)
output: returns true if decrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""
input: filename (str) and a key (int)
output: returns true if decrypt process was
successful otherwise false
if key not passed the method uses the key by the constructor.
otherwise key = 1
"""

# precondition
assert isinstance(file, str) and isinstance(key, int)
Expand Down
Binary file modified compression/image_data/PSNR-example-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified compression/image_data/PSNR-example-comp-10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified compression/image_data/original_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 22 additions & 22 deletions conversions/decimal_to_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
def decimal_to_binary(num):

"""
Convert a Integer Decimal Number to a Binary Number as str.
>>> decimal_to_binary(0)
'0b0'
>>> decimal_to_binary(2)
'0b10'
>>> decimal_to_binary(7)
'0b111'
>>> decimal_to_binary(35)
'0b100011'
>>> # negatives work too
>>> decimal_to_binary(-2)
'-0b10'
>>> # other floats will error
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: 'float' object cannot be interpreted as an integer
>>> # strings will error as well
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: 'str' object cannot be interpreted as an integer
Convert a Integer Decimal Number to a Binary Number as str.
>>> decimal_to_binary(0)
'0b0'
>>> decimal_to_binary(2)
'0b10'
>>> decimal_to_binary(7)
'0b111'
>>> decimal_to_binary(35)
'0b100011'
>>> # negatives work too
>>> decimal_to_binary(-2)
'-0b10'
>>> # other floats will error
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: 'float' object cannot be interpreted as an integer
>>> # strings will error as well
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: 'str' object cannot be interpreted as an integer
"""

if type(num) == float:
Expand Down
64 changes: 32 additions & 32 deletions conversions/decimal_to_hexadecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@

def decimal_to_hexadecimal(decimal):
"""
take integer decimal value, return hexadecimal representation as str beginning with 0x
>>> decimal_to_hexadecimal(5)
'0x5'
>>> decimal_to_hexadecimal(15)
'0xf'
>>> decimal_to_hexadecimal(37)
'0x25'
>>> decimal_to_hexadecimal(255)
'0xff'
>>> decimal_to_hexadecimal(4096)
'0x1000'
>>> decimal_to_hexadecimal(999098)
'0xf3eba'
>>> # negatives work too
>>> decimal_to_hexadecimal(-256)
'-0x100'
>>> # floats are acceptable if equivalent to an int
>>> decimal_to_hexadecimal(17.0)
'0x11'
>>> # other floats will error
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError
>>> # strings will error as well
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError
>>> # results are the same when compared to Python's default hex function
>>> decimal_to_hexadecimal(-256) == hex(-256)
True
take integer decimal value, return hexadecimal representation as str beginning with 0x
>>> decimal_to_hexadecimal(5)
'0x5'
>>> decimal_to_hexadecimal(15)
'0xf'
>>> decimal_to_hexadecimal(37)
'0x25'
>>> decimal_to_hexadecimal(255)
'0xff'
>>> decimal_to_hexadecimal(4096)
'0x1000'
>>> decimal_to_hexadecimal(999098)
'0xf3eba'
>>> # negatives work too
>>> decimal_to_hexadecimal(-256)
'-0x100'
>>> # floats are acceptable if equivalent to an int
>>> decimal_to_hexadecimal(17.0)
'0x11'
>>> # other floats will error
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError
>>> # strings will error as well
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError
>>> # results are the same when compared to Python's default hex function
>>> decimal_to_hexadecimal(-256) == hex(-256)
True
"""
assert type(decimal) in (int, float) and decimal == int(decimal)
hexadecimal = ""
Expand Down
2 changes: 1 addition & 1 deletion conversions/decimal_to_octal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def decimal_to_octal(num: int) -> str:
"""Convert a Decimal Number to an Octal Number.

>>> all(decimal_to_octal(i) == oct(i) for i in (0, 2, 8, 64, 65, 216, 255, 256, 512))
True
"""
Expand Down
2 changes: 1 addition & 1 deletion data_structures/binary_tree/avl_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def leftrotation(node):

def rightrotation(node):
"""
a mirror symmetry rotation of the leftrotation
a mirror symmetry rotation of the leftrotation
"""
print("right rotation node:", node.getdata())
ret = node.getright()
Expand Down
10 changes: 5 additions & 5 deletions data_structures/binary_tree/red_black_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class RedBlackTree:

def __init__(self, label=None, color=0, parent=None, left=None, right=None):
"""Initialize a new Red-Black Tree node with the given values:
label: The value associated with this node
color: 0 if black, 1 if red
parent: The parent to this node
left: This node's left child
right: This node's right child
label: The value associated with this node
color: 0 if black, 1 if red
parent: The parent to this node
left: This node's left child
right: This node's right child
"""
self.label = label
self.parent = parent
Expand Down
Loading