repo_name stringclasses 1
value | pr_number int64 4.12k 11.2k | pr_title stringlengths 9 107 | pr_description stringlengths 107 5.48k | author stringlengths 4 18 | date_created timestamp[ns, tz=UTC] | date_merged timestamp[ns, tz=UTC] | previous_commit stringlengths 40 40 | pr_commit stringlengths 40 40 | query stringlengths 118 5.52k | before_content stringlengths 0 7.93M | after_content stringlengths 0 7.93M | label int64 -1 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """Created by Nathan Damon, @bizzfitch on github
>>> test_miller_rabin()
"""
def miller_rabin(n: int, allow_probable: bool = False) -> bool:
"""Deterministic Miller-Rabin algorithm for primes ~< 3.32e24.
Uses numerical analysis results to return whether or not the passed number
is prime. If the passed nu... | """Created by Nathan Damon, @bizzfitch on github
>>> test_miller_rabin()
"""
def miller_rabin(n: int, allow_probable: bool = False) -> bool:
"""Deterministic Miller-Rabin algorithm for primes ~< 3.32e24.
Uses numerical analysis results to return whether or not the passed number
is prime. If the passed nu... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Project Euler Problem 114: https://projecteuler.net/problem=114
A row measuring seven units in length has red blocks with a minimum length
of three units placed on it, such that any two red blocks
(which are allowed to be different lengths) are separated by at least one grey square.
There are exactly seventeen way... | """
Project Euler Problem 114: https://projecteuler.net/problem=114
A row measuring seven units in length has red blocks with a minimum length
of three units placed on it, such that any two red blocks
(which are allowed to be different lengths) are separated by at least one grey square.
There are exactly seventeen way... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Demonstrates implementation of SHA1 Hash function in a Python class and gives utilities
to find hash of string or hash of text from a file.
Usage: python sha1.py --string "Hello World!!"
python sha1.py --file "hello_world.txt"
When run without any arguments, it prints the hash of the string "Hello Wor... | """
Demonstrates implementation of SHA1 Hash function in a Python class and gives utilities
to find hash of string or hash of text from a file.
Usage: python sha1.py --string "Hello World!!"
python sha1.py --file "hello_world.txt"
When run without any arguments, it prints the hash of the string "Hello Wor... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Shortest job remaining first
Please note arrival time and burst
Please use spaces to separate times entered.
"""
from __future__ import annotations
import pandas as pd
def calculate_waitingtime(
arrival_time: list[int], burst_time: list[int], no_of_processes: int
) -> list[int]:
"""
Calculate the wai... | """
Shortest job remaining first
Please note arrival time and burst
Please use spaces to separate times entered.
"""
from __future__ import annotations
import pandas as pd
def calculate_waitingtime(
arrival_time: list[int], burst_time: list[int], no_of_processes: int
) -> list[int]:
"""
Calculate the wai... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Problem: https://projecteuler.net/problem=54
In the card game poker, a hand consists of five cards and are ranked,
from lowest to highest, in the following way:
High Card: Highest value card.
One Pair: Two cards of the same value.
Two Pairs: Two different pairs.
Three of a Kind: Three cards of the same value.
Str... | """
Problem: https://projecteuler.net/problem=54
In the card game poker, a hand consists of five cards and are ranked,
from lowest to highest, in the following way:
High Card: Highest value card.
One Pair: Two cards of the same value.
Two Pairs: Two different pairs.
Three of a Kind: Three cards of the same value.
Str... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | # https://en.wikipedia.org/wiki/Circular_convolution
"""
Circular convolution, also known as cyclic convolution,
is a special case of periodic convolution, which is the convolution of two
periodic functions that have the same period. Periodic convolution arises,
for example, in the context of the discrete-time Fourier... | # https://en.wikipedia.org/wiki/Circular_convolution
"""
Circular convolution, also known as cyclic convolution,
is a special case of periodic convolution, which is the convolution of two
periodic functions that have the same period. Periodic convolution arises,
for example, in the context of the discrete-time Fourier... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
The maximum subarray sum problem is the task of finding the maximum sum that can be
obtained from a contiguous subarray within a given array of numbers. For example, given
the array [-2, 1, -3, 4, -1, 2, 1, -5, 4], the contiguous subarray with the maximum sum
is [4, -1, 2, 1], so the maximum subarray sum is 6.
Kad... | """
The maximum subarray sum problem is the task of finding the maximum sum that can be
obtained from a contiguous subarray within a given array of numbers. For example, given
the array [-2, 1, -3, 4, -1, 2, 1, -5, 4], the contiguous subarray with the maximum sum
is [4, -1, 2, 1], so the maximum subarray sum is 6.
Kad... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | from __future__ import annotations
import random
import string
class ShuffledShiftCipher:
"""
This algorithm uses the Caesar Cipher algorithm but removes the option to
use brute force to decrypt the message.
The passcode is a random password from the selection buffer of
1. uppercase letters of t... | from __future__ import annotations
import random
import string
class ShuffledShiftCipher:
"""
This algorithm uses the Caesar Cipher algorithm but removes the option to
use brute force to decrypt the message.
The passcode is a random password from the selection buffer of
1. uppercase letters of t... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
This is a type of divide and conquer algorithm which divides the search space into
3 parts and finds the target value based on the property of the array or list
(usually monotonic property).
Time Complexity : O(log3 N)
Space Complexity : O(1)
"""
from __future__ import annotations
# This is the precision for thi... | """
This is a type of divide and conquer algorithm which divides the search space into
3 parts and finds the target value based on the property of the array or list
(usually monotonic property).
Time Complexity : O(log3 N)
Space Complexity : O(1)
"""
from __future__ import annotations
# This is the precision for thi... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
python/black : True
"""
from __future__ import annotations
def prime_factors(n: int) -> list[int]:
"""
Returns prime factors of n as a list.
>>> prime_factors(0)
[]
>>> prime_factors(100)
[2, 2, 5, 5]
>>> prime_factors(2560)
[2, 2, 2, 2, 2, 2, 2, 2, 2, 5]
>>> prime_factors(10*... | """
python/black : True
"""
from __future__ import annotations
def prime_factors(n: int) -> list[int]:
"""
Returns prime factors of n as a list.
>>> prime_factors(0)
[]
>>> prime_factors(100)
[2, 2, 5, 5]
>>> prime_factors(2560)
[2, 2, 2, 2, 2, 2, 2, 2, 2, 5]
>>> prime_factors(10*... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Problem 45: https://projecteuler.net/problem=45
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ...
Pentagonal P(n) = (n * (3 * n − 1)) / 2 1, 5, 12, 22, 35, ...
Hexagonal H(n) = n * (2 * n − 1) 1, 6, 15, 28, 45, ..... | """
Problem 45: https://projecteuler.net/problem=45
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ...
Pentagonal P(n) = (n * (3 * n − 1)) / 2 1, 5, 12, 22, 35, ...
Hexagonal H(n) = n * (2 * n − 1) 1, 6, 15, 28, 45, ..... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | from binascii import hexlify
from hashlib import sha256
from os import urandom
# RFC 3526 - More Modular Exponential (MODP) Diffie-Hellman groups for
# Internet Key Exchange (IKE) https://tools.ietf.org/html/rfc3526
primes = {
# 1536-bit
5: {
"prime": int(
"FFFFFFFFFFFFFFFFC90FDAA22168C234... | from binascii import hexlify
from hashlib import sha256
from os import urandom
# RFC 3526 - More Modular Exponential (MODP) Diffie-Hellman groups for
# Internet Key Exchange (IKE) https://tools.ietf.org/html/rfc3526
primes = {
# 1536-bit
5: {
"prime": int(
"FFFFFFFFFFFFFFFFC90FDAA22168C234... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | from collections.abc import Callable
import numpy as np
def euler_modified(
ode_func: Callable, y0: float, x0: float, step_size: float, x_end: float
) -> np.array:
"""
Calculate solution at each step to an ODE using Euler's Modified Method
The Euler Method is straightforward to implement, but can't g... | from collections.abc import Callable
import numpy as np
def euler_modified(
ode_func: Callable, y0: float, x0: float, step_size: float, x_end: float
) -> np.array:
"""
Calculate solution at each step to an ODE using Euler's Modified Method
The Euler Method is straightforward to implement, but can't g... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Find the area of various geometric shapes
Wikipedia reference: https://en.wikipedia.org/wiki/Area
"""
from math import pi, sqrt, tan
def surface_area_cube(side_length: float) -> float:
"""
Calculate the Surface Area of a Cube.
>>> surface_area_cube(1)
6
>>> surface_area_cube(1.6)
15.36000... | """
Find the area of various geometric shapes
Wikipedia reference: https://en.wikipedia.org/wiki/Area
"""
from math import pi, sqrt, tan
def surface_area_cube(side_length: float) -> float:
"""
Calculate the Surface Area of a Cube.
>>> surface_area_cube(1)
6
>>> surface_area_cube(1.6)
15.36000... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | import unittest
from timeit import timeit
def least_common_multiple_slow(first_num: int, second_num: int) -> int:
"""
Find the least common multiple of two numbers.
Learn more: https://en.wikipedia.org/wiki/Least_common_multiple
>>> least_common_multiple_slow(5, 2)
10
>>> least_common_multip... | import unittest
from timeit import timeit
def least_common_multiple_slow(first_num: int, second_num: int) -> int:
"""
Find the least common multiple of two numbers.
Learn more: https://en.wikipedia.org/wiki/Least_common_multiple
>>> least_common_multiple_slow(5, 2)
10
>>> least_common_multip... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | # Created by susmith98
from collections import Counter
from timeit import timeit
# Problem Description:
# Check if characters of the given string can be rearranged to form a palindrome.
# Counter is faster for long strings and non-Counter is faster for short strings.
def can_string_be_rearranged_as_palindrome_count... | # Created by susmith98
from collections import Counter
from timeit import timeit
# Problem Description:
# Check if characters of the given string can be rearranged to form a palindrome.
# Counter is faster for long strings and non-Counter is faster for short strings.
def can_string_be_rearranged_as_palindrome_count... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | from typing import Any
def viterbi(
observations_space: list,
states_space: list,
initial_probabilities: dict,
transition_probabilities: dict,
emission_probabilities: dict,
) -> list:
"""
Viterbi Algorithm, to find the most likely path of
states from the start and the expected ... | from typing import Any
def viterbi(
observations_space: list,
states_space: list,
initial_probabilities: dict,
transition_probabilities: dict,
emission_probabilities: dict,
) -> list:
"""
Viterbi Algorithm, to find the most likely path of
states from the start and the expected ... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | -1 | ||
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Project Euler Problem 135: https://projecteuler.net/problem=135
Given the positive integers, x, y, and z,
are consecutive terms of an arithmetic progression,
the least value of the positive integer, n,
for which the equation,
x2 − y2 − z2 = n, has exactly two solutions is n = 27:
342 − 272 − 202 = 122 − 92 − 62 =... | """
Project Euler Problem 135: https://projecteuler.net/problem=135
Given the positive integers, x, y, and z,
are consecutive terms of an arithmetic progression,
the least value of the positive integer, n,
for which the equation,
x2 − y2 − z2 = n, has exactly two solutions is n = 27:
342 − 272 − 202 = 122 − 92 − 62 =... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | -1 | ||
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
== Raise base to the power of exponent using recursion ==
Input -->
Enter the base: 3
Enter the exponent: 4
Output -->
3 to the power of 4 is 81
Input -->
Enter the base: 2
Enter the exponent: 0
Output -->
2 to the power of 0 is 1
"""
def power(base... | """
== Raise base to the power of exponent using recursion ==
Input -->
Enter the base: 3
Enter the exponent: 4
Output -->
3 to the power of 4 is 81
Input -->
Enter the base: 2
Enter the exponent: 0
Output -->
2 to the power of 0 is 1
"""
def power(base... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | -1 | ||
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | import sys
"""
Dynamic Programming
Implementation of Matrix Chain Multiplication
Time Complexity: O(n^3)
Space Complexity: O(n^2)
"""
def matrix_chain_order(array):
n = len(array)
matrix = [[0 for x in range(n)] for x in range(n)]
sol = [[0 for x in range(n)] for x in range(n)]
for chain_length in r... | import sys
"""
Dynamic Programming
Implementation of Matrix Chain Multiplication
Time Complexity: O(n^3)
Space Complexity: O(n^2)
"""
def matrix_chain_order(array):
n = len(array)
matrix = [[0 for x in range(n)] for x in range(n)]
sol = [[0 for x in range(n)] for x in range(n)]
for chain_length in r... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Author : Alexander Pantyukhin
Date : November 1, 2022
Task:
Given a list of days when you need to travel. Each day is integer from 1 to 365.
You are able to use tickets for 1 day, 7 days and 30 days.
Each ticket has a cost.
Find the minimum cost you need to travel every day in the given list of days.
Impleme... | """
Author : Alexander Pantyukhin
Date : November 1, 2022
Task:
Given a list of days when you need to travel. Each day is integer from 1 to 365.
You are able to use tickets for 1 day, 7 days and 30 days.
Each ticket has a cost.
Find the minimum cost you need to travel every day in the given list of days.
Impleme... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | """
Conversion of volume units.
Available Units:- Cubic metre,Litre,KiloLitre,Gallon,Cubic yard,Cubic foot,cup
USAGE :
-> Import this file into their respective project.
-> Use the function length_conversion() for conversion of volume units.
-> Parameters :
-> value : The number of from units you want to convert
... | """
Conversion of volume units.
Available Units:- Cubic metre,Litre,KiloLitre,Gallon,Cubic yard,Cubic foot,cup
USAGE :
-> Import this file into their respective project.
-> Use the function length_conversion() for conversion of volume units.
-> Parameters :
-> value : The number of from units you want to convert
... | -1 |
TheAlgorithms/Python | 8,960 | Consolidate find_min and find_min recursive and find_max and find_max_recursive | ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?
* [x] Merge two different implementations into one f... | CaedenPH | 2023-08-14T10:30:16Z | 2023-08-14T11:17:27Z | 2ab3bf2689d21e7375539c79ecee358e9d7c3359 | fb1b939a89fb08370297cbb455846f61f66847bc | Consolidate find_min and find_min recursive and find_max and find_max_recursive. ### Describe your change:
Merges `find_min` and `find_min_recursive` into just `find_min`.
Merges `find_min` and `find_max_recursive` into just `find_max`.
* [ ] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
... | # Created by sarathkaul on 12/11/19
import requests
def send_slack_message(message_body: str, slack_url: str) -> None:
headers = {"Content-Type": "application/json"}
response = requests.post(slack_url, json={"text": message_body}, headers=headers)
if response.status_code != 200:
msg = (
... | # Created by sarathkaul on 12/11/19
import requests
def send_slack_message(message_body: str, slack_url: str) -> None:
headers = {"Content-Type": "application/json"}
response = requests.post(slack_url, json={"text": message_body}, headers=headers)
if response.status_code != 200:
msg = (
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import numpy as np
from PIL import Image
def rgb2gray(rgb: np.array) -> np.array:
"""
Return gray image from rgb image
>>> rgb2gray(np.array([[[127, 255, 0]]]))
array([[187.6453]])
>>> rgb2gray(np.array([[[0, 0, 0]]]))
array([[0.]])
>>> rgb2gray(np.array([[[2, 4, 1]]]))
array([[3.0598]... | import numpy as np
from PIL import Image
def rgb2gray(rgb: np.array) -> np.array:
"""
Return gray image from rgb image
>>> rgb2gray(np.array([[[127, 255, 0]]]))
array([[187.6453]])
>>> rgb2gray(np.array([[[0, 0, 0]]]))
array([[0.]])
>>> rgb2gray(np.array([[[2, 4, 1]]]))
array([[3.0598]... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from pathlib import Path
import cv2
import numpy as np
from matplotlib import pyplot as plt
def get_rotation(
img: np.ndarray, pt1: np.ndarray, pt2: np.ndarray, rows: int, cols: int
) -> np.ndarray:
"""
Get image rotation
:param img: np.array
:param pt1: 3x2 list
:param pt2: 3x2 list
:par... | from pathlib import Path
import cv2
import numpy as np
from matplotlib import pyplot as plt
def get_rotation(
img: np.ndarray, pt1: np.ndarray, pt2: np.ndarray, rows: int, cols: int
) -> np.ndarray:
"""
Get image rotation
:param img: np.ndarray
:param pt1: 3x2 list
:param pt2: 3x2 list
:p... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from __future__ import annotations
def median(nums: list) -> int | float:
"""
Find median of a list of numbers.
Wiki: https://en.wikipedia.org/wiki/Median
>>> median([0])
0
>>> median([4, 1, 3, 2])
2.5
>>> median([2, 70, 6, 50, 20, 8, 4])
8
Args:
nums: List of nums
... | from __future__ import annotations
def median(nums: list) -> int | float:
"""
Find median of a list of numbers.
Wiki: https://en.wikipedia.org/wiki/Median
>>> median([0])
0
>>> median([4, 1, 3, 2])
2.5
>>> median([2, 70, 6, 50, 20, 8, 4])
8
Args:
nums: List of nums
... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from collections.abc import Callable
import numpy as np
def euler_modified(
ode_func: Callable, y0: float, x0: float, step_size: float, x_end: float
) -> np.array:
"""
Calculate solution at each step to an ODE using Euler's Modified Method
The Euler Method is straightforward to implement, but can't g... | from collections.abc import Callable
import numpy as np
def euler_modified(
ode_func: Callable, y0: float, x0: float, step_size: float, x_end: float
) -> np.ndarray:
"""
Calculate solution at each step to an ODE using Euler's Modified Method
The Euler Method is straightforward to implement, but can't... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
This script demonstrates an implementation of the Gaussian Error Linear Unit function.
* https://en.wikipedia.org/wiki/Activation_function#Comparison_of_activation_functions
The function takes a vector of K real numbers as input and returns x * sigmoid(1.702*x).
Gaussian Error Linear Unit (GELU) is a high-performi... | """
This script demonstrates an implementation of the Gaussian Error Linear Unit function.
* https://en.wikipedia.org/wiki/Activation_function#Comparison_of_activation_functions
The function takes a vector of K real numbers as input and returns x * sigmoid(1.702*x).
Gaussian Error Linear Unit (GELU) is a high-performi... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The Jaccard similarity coefficient is a commonly used indicator of the
similarity between two sets. Let U be a set and A and B be subsets of U,
then the Jaccard index/similarity is defined to be the ratio of the number
of elements of their intersection and the number of elements of their union.
Inspired from Wikip... | """
The Jaccard similarity coefficient is a commonly used indicator of the
similarity between two sets. Let U be a set and A and B be subsets of U,
then the Jaccard index/similarity is defined to be the ratio of the number
of elements of their intersection and the number of elements of their union.
Inspired from Wikip... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Author: P Shreyas Shetty
Implementation of Newton-Raphson method for solving equations of kind
f(x) = 0. It is an iterative method where solution is found by the expression
x[n+1] = x[n] + f(x[n])/f'(x[n])
If no solution exists, then either the solution will not be found when iteration
l... | """
Author: P Shreyas Shetty
Implementation of Newton-Raphson method for solving equations of kind
f(x) = 0. It is an iterative method where solution is found by the expression
x[n+1] = x[n] + f(x[n])/f'(x[n])
If no solution exists, then either the solution will not be found when iteration
limit is reached or the g... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import numpy as np
def qr_householder(a):
"""Return a QR-decomposition of the matrix A using Householder reflection.
The QR-decomposition decomposes the matrix A of shape (m, n) into an
orthogonal matrix Q of shape (m, m) and an upper triangular matrix R of
shape (m, n). Note that the matrix A does ... | import numpy as np
def qr_householder(a: np.ndarray):
"""Return a QR-decomposition of the matrix A using Householder reflection.
The QR-decomposition decomposes the matrix A of shape (m, n) into an
orthogonal matrix Q of shape (m, m) and an upper triangular matrix R of
shape (m, n). Note that the ma... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
This script demonstrates the implementation of the Sigmoid function.
The function takes a vector of K real numbers as input and then 1 / (1 + exp(-x)).
After through Sigmoid, the element of the vector mostly 0 between 1. or 1 between -1.
Script inspired from its corresponding Wikipedia article
https://en.wikipedi... | """
This script demonstrates the implementation of the Sigmoid function.
The function takes a vector of K real numbers as input and then 1 / (1 + exp(-x)).
After through Sigmoid, the element of the vector mostly 0 between 1. or 1 between -1.
Script inspired from its corresponding Wikipedia article
https://en.wikipedi... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
This script demonstrates the implementation of the tangent hyperbolic
or tanh function.
The function takes a vector of K real numbers as input and
then (e^x - e^(-x))/(e^x + e^(-x)). After through tanh, the
element of the vector mostly -1 between 1.
Script inspired from its corresponding Wikipedia article
https:/... | """
This script demonstrates the implementation of the tangent hyperbolic
or tanh function.
The function takes a vector of K real numbers as input and
then (e^x - e^(-x))/(e^x + e^(-x)). After through tanh, the
element of the vector mostly -1 between 1.
Script inspired from its corresponding Wikipedia article
https:/... | 1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Lower–upper (LU) decomposition factors a matrix as a product of a lower
triangular matrix and an upper triangular matrix. A square matrix has an LU
decomposition under the following conditions:
- If the matrix is invertible, then it has an LU decomposition if and only
if all of its leading principal minors ... | """
Lower–upper (LU) decomposition factors a matrix as a product of a lower
triangular matrix and an upper triangular matrix. A square matrix has an LU
decomposition under the following conditions:
- If the matrix is invertible, then it has an LU decomposition if and only
if all of its leading principal minors ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from __future__ import annotations
import typing
from collections.abc import Iterable
import numpy as np
Vector = typing.Union[Iterable[float], Iterable[int], np.ndarray] # noqa: UP007
VectorOut = typing.Union[np.float64, int, float] # noqa: UP007
def euclidean_distance(vector_1: Vector, vector_2: Vector) -> Vec... | from __future__ import annotations
import typing
from collections.abc import Iterable
import numpy as np
Vector = typing.Union[Iterable[float], Iterable[int], np.ndarray] # noqa: UP007
VectorOut = typing.Union[np.float64, int, float] # noqa: UP007
def euclidean_distance(vector_1: Vector, vector_2: Vector) -> Vec... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import math
class SegmentTree:
def __init__(self, a):
self.N = len(a)
self.st = [0] * (
4 * self.N
) # approximate the overall size of segment tree with array N
if self.N:
self.build(1, 0, self.N - 1)
def left(self, idx):
return idx * 2
de... | import math
class SegmentTree:
def __init__(self, a):
self.N = len(a)
self.st = [0] * (
4 * self.N
) # approximate the overall size of segment tree with array N
if self.N:
self.build(1, 0, self.N - 1)
def left(self, idx):
return idx * 2
de... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Locally weighted linear regression, also called local regression, is a type of
non-parametric linear regression that prioritizes data closest to a given
prediction point. The algorithm estimates the vector of model coefficients β
using weighted least squares regression:
β = (XᵀWX)⁻¹(XᵀWy),
where X is the design m... | """
Locally weighted linear regression, also called local regression, is a type of
non-parametric linear regression that prioritizes data closest to a given
prediction point. The algorithm estimates the vector of model coefficients β
using weighted least squares regression:
β = (XᵀWX)⁻¹(XᵀWy),
where X is the design m... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Created on Thu Oct 5 16:44:23 2017
@author: Christian Bender
This Python library contains some useful functions to deal with
prime numbers and whole numbers.
Overview:
is_prime(number)
sieve_er(N)
get_prime_numbers(N)
prime_factorization(number)
greatest_prime_factor(number)
smallest_prime_factor(number)
get_p... | """
Created on Thu Oct 5 16:44:23 2017
@author: Christian Bender
This Python library contains some useful functions to deal with
prime numbers and whole numbers.
Overview:
is_prime(number)
sieve_er(N)
get_prime_numbers(N)
prime_factorization(number)
greatest_prime_factor(number)
smallest_prime_factor(number)
get_p... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
A XOR Gate is a logic gate in boolean algebra which results to 1 (True) if only one of
the two inputs is 1, and 0 (False) if an even number of inputs are 1.
Following is the truth table of a XOR Gate:
------------------------------
| Input 1 | Input 2 | Output |
------------------------------
| 0... | """
A XOR Gate is a logic gate in boolean algebra which results to 1 (True) if only one of
the two inputs is 1, and 0 (False) if an even number of inputs are 1.
Following is the truth table of a XOR Gate:
------------------------------
| Input 1 | Input 2 | Output |
------------------------------
| 0... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Name scores
Problem 22
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file
containing over five-thousand first names, begin by sorting it into
alphabetical order. Then working out the alphabetical value for each name,
multiply this value by its alphabetical position in the list to obtain a ... | """
Name scores
Problem 22
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file
containing over five-thousand first names, begin by sorting it into
alphabetical order. Then working out the alphabetical value for each name,
multiply this value by its alphabetical position in the list to obtain a ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The maximum subarray sum problem is the task of finding the maximum sum that can be
obtained from a contiguous subarray within a given array of numbers. For example, given
the array [-2, 1, -3, 4, -1, 2, 1, -5, 4], the contiguous subarray with the maximum sum
is [4, -1, 2, 1], so the maximum subarray sum is 6.
Kad... | """
The maximum subarray sum problem is the task of finding the maximum sum that can be
obtained from a contiguous subarray within a given array of numbers. For example, given
the array [-2, 1, -3, 4, -1, 2, 1, -5, 4], the contiguous subarray with the maximum sum
is [4, -1, 2, 1], so the maximum subarray sum is 6.
Kad... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def alternative_string_arrange(first_str: str, second_str: str) -> str:
"""
Return the alternative arrangements of the two strings.
:param first_str:
:param second_str:
:return: String
>>> alternative_string_arrange("ABCD", "XY")
'AXBYCD'
>>> alternative_string_arrange("XY", "ABCD")
... | def alternative_string_arrange(first_str: str, second_str: str) -> str:
"""
Return the alternative arrangements of the two strings.
:param first_str:
:param second_str:
:return: String
>>> alternative_string_arrange("ABCD", "XY")
'AXBYCD'
>>> alternative_string_arrange("XY", "ABCD")
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def bin_to_decimal(bin_string: str) -> int:
"""
Convert a binary value to its decimal equivalent
>>> bin_to_decimal("101")
5
>>> bin_to_decimal(" 1010 ")
10
>>> bin_to_decimal("-11101")
-29
>>> bin_to_decimal("0")
0
>>> bin_to_decimal("a")
Traceback (most recent call l... | def bin_to_decimal(bin_string: str) -> int:
"""
Convert a binary value to its decimal equivalent
>>> bin_to_decimal("101")
5
>>> bin_to_decimal(" 1010 ")
10
>>> bin_to_decimal("-11101")
-29
>>> bin_to_decimal("0")
0
>>> bin_to_decimal("a")
Traceback (most recent call l... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Created on Fri Sep 28 15:22:29 2018
@author: Binish125
"""
import copy
import os
import cv2
import numpy as np
from matplotlib import pyplot as plt
class ConstantStretch:
def __init__(self):
self.img = ""
self.original_image = ""
self.last_list = []
self.rem = 0
self.... | """
Created on Fri Sep 28 15:22:29 2018
@author: Binish125
"""
import copy
import os
import cv2
import numpy as np
from matplotlib import pyplot as plt
class ConstantStretch:
def __init__(self):
self.img = ""
self.original_image = ""
self.last_list = []
self.rem = 0
self.... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from __future__ import annotations
from collections import Counter
from random import random
class MarkovChainGraphUndirectedUnweighted:
"""
Undirected Unweighted Graph for running Markov Chain Algorithm
"""
def __init__(self):
self.connections = {}
def add_node(self, node: str) -> None... | from __future__ import annotations
from collections import Counter
from random import random
class MarkovChainGraphUndirectedUnweighted:
"""
Undirected Unweighted Graph for running Markov Chain Algorithm
"""
def __init__(self):
self.connections = {}
def add_node(self, node: str) -> None... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The Mandelbrot set is the set of complex numbers "c" for which the series
"z_(n+1) = z_n * z_n + c" does not diverge, i.e. remains bounded. Thus, a
complex number "c" is a member of the Mandelbrot set if, when starting with
"z_0 = 0" and applying the iteration repeatedly, the absolute value of
"z_n" remains bounded... | """
The Mandelbrot set is the set of complex numbers "c" for which the series
"z_(n+1) = z_n * z_n + c" does not diverge, i.e. remains bounded. Thus, a
complex number "c" is a member of the Mandelbrot set if, when starting with
"z_0 = 0" and applying the iteration repeatedly, the absolute value of
"z_n" remains bounded... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Highly divisible triangular numbers
Problem 12
The sequence of triangle numbers is generated by adding the natural numbers. So
the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten
terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle... | """
Highly divisible triangular numbers
Problem 12
The sequence of triangle numbers is generated by adding the natural numbers. So
the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten
terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Given a string s, partition s such that every substring of the
partition is a palindrome.
Find the minimum cuts needed for a palindrome partitioning of s.
Time Complexity: O(n^2)
Space Complexity: O(n^2)
For other explanations refer to: https://www.youtube.com/watch?v=_H8V5hJUGd0
"""
def find_minimum_partitions(... | """
Given a string s, partition s such that every substring of the
partition is a palindrome.
Find the minimum cuts needed for a palindrome partitioning of s.
Time Complexity: O(n^2)
Space Complexity: O(n^2)
For other explanations refer to: https://www.youtube.com/watch?v=_H8V5hJUGd0
"""
def find_minimum_partitions(... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Modular Exponential.
Modular exponentiation is a type of exponentiation performed over a modulus.
For more explanation, please check
https://en.wikipedia.org/wiki/Modular_exponentiation
"""
"""Calculate Modular Exponential."""
def modular_exponential(base: int, power: int, mod: int):
"""
... | """
Modular Exponential.
Modular exponentiation is a type of exponentiation performed over a modulus.
For more explanation, please check
https://en.wikipedia.org/wiki/Modular_exponentiation
"""
"""Calculate Modular Exponential."""
def modular_exponential(base: int, power: int, mod: int):
"""
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Project Euler Problem 75: https://projecteuler.net/problem=75
It turns out that 12 cm is the smallest length of wire that can be bent to form an
integer sided right angle triangle in exactly one way, but there are many more examples.
12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17... | """
Project Euler Problem 75: https://projecteuler.net/problem=75
It turns out that 12 cm is the smallest length of wire that can be bent to form an
integer sided right angle triangle in exactly one way, but there are many more examples.
12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Given an array of integers and another integer target,
we are required to find a triplet from the array such that it's sum is equal to
the target.
"""
from __future__ import annotations
from itertools import permutations
from random import randint
from timeit import repeat
def make_dataset() -> tuple[list[int], ... | """
Given an array of integers and another integer target,
we are required to find a triplet from the array such that it's sum is equal to
the target.
"""
from __future__ import annotations
from itertools import permutations
from random import randint
from timeit import repeat
def make_dataset() -> tuple[list[int], ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Title : Calculating the speed of sound
Description :
The speed of sound (c) is the speed that a sound wave travels
per unit time (m/s). During propagation, the sound wave propagates
through an elastic medium. Its SI unit is meter per second (m/s).
Only longitudinal waves can propagate in liquids a... | """
Title : Calculating the speed of sound
Description :
The speed of sound (c) is the speed that a sound wave travels
per unit time (m/s). During propagation, the sound wave propagates
through an elastic medium. Its SI unit is meter per second (m/s).
Only longitudinal waves can propagate in liquids a... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Problem 33: https://projecteuler.net/problem=33
The fraction 49/98 is a curious fraction, as an inexperienced
mathematician in attempting to simplify it may incorrectly believe
that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial exampl... | """
Problem 33: https://projecteuler.net/problem=33
The fraction 49/98 is a curious fraction, as an inexperienced
mathematician in attempting to simplify it may incorrectly believe
that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial exampl... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | # Created by sarathkaul on 17/11/19
# Modified by Arkadip Bhattacharya(@darkmatter18) on 20/04/2020
from collections import defaultdict
def word_occurrence(sentence: str) -> dict:
"""
>>> from collections import Counter
>>> SENTENCE = "a b A b c b d b d e f e g e h e i e j e 0"
>>> occurence_dict = wo... | # Created by sarathkaul on 17/11/19
# Modified by Arkadip Bhattacharya(@darkmatter18) on 20/04/2020
from collections import defaultdict
def word_occurrence(sentence: str) -> dict:
"""
>>> from collections import Counter
>>> SENTENCE = "a b A b c b d b d e f e g e h e i e j e 0"
>>> occurence_dict = wo... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the ... | """
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Highly divisible triangular numbers
Problem 12
The sequence of triangle numbers is generated by adding the natural numbers. So
the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten
terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle... | """
Highly divisible triangular numbers
Problem 12
The sequence of triangle numbers is generated by adding the natural numbers. So
the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten
terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def double_factorial(n: int) -> int:
"""
Compute double factorial using recursive method.
Recursion can be costly for large numbers.
To learn about the theory behind this algorithm:
https://en.wikipedia.org/wiki/Double_factorial
>>> import math
>>> all(double_factorial(i) == math.prod(rang... | def double_factorial(n: int) -> int:
"""
Compute double factorial using recursive method.
Recursion can be costly for large numbers.
To learn about the theory behind this algorithm:
https://en.wikipedia.org/wiki/Double_factorial
>>> import math
>>> all(double_factorial(i) == math.prod(rang... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Implements an is valid email address algorithm
@ https://en.wikipedia.org/wiki/Email_address
"""
import string
email_tests: tuple[tuple[str, bool], ...] = (
("simple@example.com", True),
("very.common@example.com", True),
("disposable.style.email.with+symbol@example.com", True),
("other-email-wit... | """
Implements an is valid email address algorithm
@ https://en.wikipedia.org/wiki/Email_address
"""
import string
email_tests: tuple[tuple[str, bool], ...] = (
("simple@example.com", True),
("very.common@example.com", True),
("disposable.style.email.with+symbol@example.com", True),
("other-email-wit... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from __future__ import annotations
from typing import Any
class ContainsLoopError(Exception):
pass
class Node:
def __init__(self, data: Any) -> None:
self.data: Any = data
self.next_node: Node | None = None
def __iter__(self):
node = self
visited = []
while node... | from __future__ import annotations
from typing import Any
class ContainsLoopError(Exception):
pass
class Node:
def __init__(self, data: Any) -> None:
self.data: Any = data
self.next_node: Node | None = None
def __iter__(self):
node = self
visited = []
while node... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
A bag contains one red disc and one blue disc. In a game of chance a player takes a
disc at random and its colour is noted. After each turn the disc is returned to the
bag, an extra red disc is added, and another disc is taken at random.
The player pays £1 to play and wins if they have taken more blue discs than r... | """
A bag contains one red disc and one blue disc. In a game of chance a player takes a
disc at random and its colour is noted. After each turn the disc is returned to the
bag, an extra red disc is added, and another disc is taken at random.
The player pays £1 to play and wins if they have taken more blue discs than r... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Project Euler Problem 187: https://projecteuler.net/problem=187
A composite is a number containing at least two prime factors.
For example, 15 = 3 x 5; 9 = 3 x 3; 12 = 2 x 2 x 3.
There are ten composites below thirty containing precisely two,
not necessarily distinct, prime factors: 4, 6, 9, 10, 14, 15, 21, 22, 2... | """
Project Euler Problem 187: https://projecteuler.net/problem=187
A composite is a number containing at least two prime factors.
For example, 15 = 3 x 5; 9 = 3 x 3; 12 = 2 x 2 x 3.
There are ten composites below thirty containing precisely two,
not necessarily distinct, prime factors: 4, 6, 9, 10, 14, 15, 21, 22, 2... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | from __future__ import annotations
import sys
class Letter:
def __init__(self, letter: str, freq: int):
self.letter: str = letter
self.freq: int = freq
self.bitstring: dict[str, str] = {}
def __repr__(self) -> str:
return f"{self.letter}:{self.freq}"
class TreeNode:
def... | from __future__ import annotations
import sys
class Letter:
def __init__(self, letter: str, freq: int):
self.letter: str = letter
self.freq: int = freq
self.bitstring: dict[str, str] = {}
def __repr__(self) -> str:
return f"{self.letter}:{self.freq}"
class TreeNode:
def... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import sys
"""
Dynamic Programming
Implementation of Matrix Chain Multiplication
Time Complexity: O(n^3)
Space Complexity: O(n^2)
"""
def matrix_chain_order(array):
n = len(array)
matrix = [[0 for x in range(n)] for x in range(n)]
sol = [[0 for x in range(n)] for x in range(n)]
for chain_length in r... | import sys
"""
Dynamic Programming
Implementation of Matrix Chain Multiplication
Time Complexity: O(n^3)
Space Complexity: O(n^2)
"""
def matrix_chain_order(array):
n = len(array)
matrix = [[0 for x in range(n)] for x in range(n)]
sol = [[0 for x in range(n)] for x in range(n)]
for chain_length in r... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def alternative_list_arrange(first_input_list: list, second_input_list: list) -> list:
"""
The method arranges two lists as one list in alternative forms of the list elements.
:param first_input_list:
:param second_input_list:
:return: List
>>> alternative_list_arrange([1, 2, 3, 4, 5], ["A", "B"... | def alternative_list_arrange(first_input_list: list, second_input_list: list) -> list:
"""
The method arranges two lists as one list in alternative forms of the list elements.
:param first_input_list:
:param second_input_list:
:return: List
>>> alternative_list_arrange([1, 2, 3, 4, 5], ["A", "B"... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Project Euler Problem 6: https://projecteuler.net/problem=6
Sum square difference
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 3025
Hence the difference between the sum of... | """
Project Euler Problem 6: https://projecteuler.net/problem=6
Sum square difference
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 3025
Hence the difference between the sum of... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the ... | """
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def dencrypt(s: str, n: int = 13) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
>>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
>>> s = dencrypt(msg)
>>> s
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
>>> dencrypt(s) == msg
True
... | def dencrypt(s: str, n: int = 13) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
>>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
>>> s = dencrypt(msg)
>>> s
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
>>> dencrypt(s) == msg
True
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def is_contains_unique_chars(input_str: str) -> bool:
"""
Check if all characters in the string is unique or not.
>>> is_contains_unique_chars("I_love.py")
True
>>> is_contains_unique_chars("I don't love Python")
False
Time complexity: O(n)
Space complexity: O(1) 19320 bytes as we are h... | def is_contains_unique_chars(input_str: str) -> bool:
"""
Check if all characters in the string is unique or not.
>>> is_contains_unique_chars("I_love.py")
True
>>> is_contains_unique_chars("I don't love Python")
False
Time complexity: O(n)
Space complexity: O(1) 19320 bytes as we are h... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
This program print the matrix in spiral form.
This problem has been solved through recursive way.
Matrix must satisfy below conditions
i) matrix should be only one or two dimensional
ii) number of column of all rows should be equal
"""
def check_matrix(matrix: list[list[int]]) -> bool:
#... | """
This program print the matrix in spiral form.
This problem has been solved through recursive way.
Matrix must satisfy below conditions
i) matrix should be only one or two dimensional
ii) number of column of all rows should be equal
"""
def check_matrix(matrix: list[list[int]]) -> bool:
#... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | # Check whether Graph is Bipartite or Not using BFS
# A Bipartite Graph is a graph whose vertices can be divided into two independent sets,
# U and V such that every edge (u, v) either connects a vertex from U to V or a vertex
# from V to U. In other words, for every edge (u, v), either u belongs to U and v to V,
# o... | # Check whether Graph is Bipartite or Not using BFS
# A Bipartite Graph is a graph whose vertices can be divided into two independent sets,
# U and V such that every edge (u, v) either connects a vertex from U to V or a vertex
# from V to U. In other words, for every edge (u, v), either u belongs to U and v to V,
# o... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def binary_search(lst, item, start, end):
if start == end:
return start if lst[start] > item else start + 1
if start > end:
return start
mid = (start + end) // 2
if lst[mid] < item:
return binary_search(lst, item, mid + 1, end)
elif lst[mid] > item:
return binary_sea... | def binary_search(lst, item, start, end):
if start == end:
return start if lst[start] > item else start + 1
if start > end:
return start
mid = (start + end) // 2
if lst[mid] < item:
return binary_search(lst, item, mid + 1, end)
elif lst[mid] > item:
return binary_sea... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Similarity Search : https://en.wikipedia.org/wiki/Similarity_search
Similarity search is a search algorithm for finding the nearest vector from
vectors, used in natural language processing.
In this algorithm, it calculates distance with euclidean distance and
returns a list containing two data for each vector:
... | """
Similarity Search : https://en.wikipedia.org/wiki/Similarity_search
Similarity search is a search algorithm for finding the nearest vector from
vectors, used in natural language processing.
In this algorithm, it calculates distance with euclidean distance and
returns a list containing two data for each vector:
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | # Eulerian Path is a path in graph that visits every edge exactly once.
# Eulerian Circuit is an Eulerian Path which starts and ends on the same
# vertex.
# time complexity is O(V+E)
# space complexity is O(VE)
# using dfs for finding eulerian path traversal
def dfs(u, graph, visited_edge, path=None):
path = (pat... | # Eulerian Path is a path in graph that visits every edge exactly once.
# Eulerian Circuit is an Eulerian Path which starts and ends on the same
# vertex.
# time complexity is O(V+E)
# space complexity is O(VE)
# using dfs for finding eulerian path traversal
def dfs(u, graph, visited_edge, path=None):
path = (pat... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | # Implementation of Circular Queue (using Python lists)
class CircularQueue:
"""Circular FIFO queue with a fixed capacity"""
def __init__(self, n: int):
self.n = n
self.array = [None] * self.n
self.front = 0 # index of the first element
self.rear = 0
self.size = 0
... | # Implementation of Circular Queue (using Python lists)
class CircularQueue:
"""Circular FIFO queue with a fixed capacity"""
def __init__(self, n: int):
self.n = n
self.array = [None] * self.n
self.front = 0 # index of the first element
self.rear = 0
self.size = 0
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Horizontal Projectile Motion problem in physics.
This algorithm solves a specific problem in which
the motion starts from the ground as can be seen below:
(v = 0)
* *
* *
* *
* *
* *
* ... | """
Horizontal Projectile Motion problem in physics.
This algorithm solves a specific problem in which
the motion starts from the ground as can be seen below:
(v = 0)
* *
* *
* *
* *
* *
* ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | #!/usr/bin/env python
#
# Sort large text files in a minimum amount of memory
#
import argparse
import os
class FileSplitter:
BLOCK_FILENAME_FORMAT = "block_{0}.dat"
def __init__(self, filename):
self.filename = filename
self.block_filenames = []
def write_block(self, data, block_number... | #!/usr/bin/env python
#
# Sort large text files in a minimum amount of memory
#
import argparse
import os
class FileSplitter:
BLOCK_FILENAME_FORMAT = "block_{0}.dat"
def __init__(self, filename):
self.filename = filename
self.block_filenames = []
def write_block(self, data, block_number... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def elf_hash(data: str) -> int:
"""
Implementation of ElfHash Algorithm, a variant of PJW hash function.
>>> elf_hash('lorem ipsum')
253956621
"""
hash_ = x = 0
for letter in data:
hash_ = (hash_ << 4) + ord(letter)
x = hash_ & 0xF0000000
if x != 0:
hash_... | def elf_hash(data: str) -> int:
"""
Implementation of ElfHash Algorithm, a variant of PJW hash function.
>>> elf_hash('lorem ipsum')
253956621
"""
hash_ = x = 0
for letter in data:
hash_ = (hash_ << 4) + ord(letter)
x = hash_ & 0xF0000000
if x != 0:
hash_... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Jacobi Iteration Method - https://en.wikipedia.org/wiki/Jacobi_method
"""
from __future__ import annotations
import numpy as np
from numpy import float64
from numpy.typing import NDArray
# Method to find solution of system of linear equations
def jacobi_iteration_method(
coefficient_matrix: NDArray[float64],... | """
Jacobi Iteration Method - https://en.wikipedia.org/wiki/Jacobi_method
"""
from __future__ import annotations
import numpy as np
from numpy import float64
from numpy.typing import NDArray
# Method to find solution of system of linear equations
def jacobi_iteration_method(
coefficient_matrix: NDArray[float64],... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import math
from collections.abc import Callable
def intersection(function: Callable[[float], float], x0: float, x1: float) -> float:
"""
function is the f we want to find its root
x0 and x1 are two random starting points
>>> intersection(lambda x: x ** 3 - 1, -5, 5)
0.9999999999954654
>>> int... | import math
from collections.abc import Callable
def intersection(function: Callable[[float], float], x0: float, x1: float) -> float:
"""
function is the f we want to find its root
x0 and x1 are two random starting points
>>> intersection(lambda x: x ** 3 - 1, -5, 5)
0.9999999999954654
>>> int... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
https://en.wikipedia.org/wiki/Doubly_linked_list
"""
class Node:
def __init__(self, data):
self.data = data
self.previous = None
self.next = None
def __str__(self):
return f"{self.data}"
class DoublyLinkedList:
def __init__(self):
self.head = None
sel... | """
https://en.wikipedia.org/wiki/Doubly_linked_list
"""
class Node:
def __init__(self, data):
self.data = data
self.previous = None
self.next = None
def __str__(self):
return f"{self.data}"
class DoublyLinkedList:
def __init__(self):
self.head = None
sel... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
The algorithm finds the pattern in given text using following rule.
The bad-character rule considers the mismatched character in Text.
The next occurrence of that character to the left in Pattern is found,
If the mismatched character occurs to the left in Pattern,
a shift is proposed that aligns text block and pa... | """
The algorithm finds the pattern in given text using following rule.
The bad-character rule considers the mismatched character in Text.
The next occurrence of that character to the left in Pattern is found,
If the mismatched character occurs to the left in Pattern,
a shift is proposed that aligns text block and pa... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | import glob
import os
import random
from string import ascii_lowercase, digits
import cv2
"""
Flip image and bounding box for computer vision task
https://paperswithcode.com/method/randomhorizontalflip
"""
# Params
LABEL_DIR = ""
IMAGE_DIR = ""
OUTPUT_DIR = ""
FLIP_TYPE = 1 # (0 is vertical, 1 is horizontal)
def ... | import glob
import os
import random
from string import ascii_lowercase, digits
import cv2
"""
Flip image and bounding box for computer vision task
https://paperswithcode.com/method/randomhorizontalflip
"""
# Params
LABEL_DIR = ""
IMAGE_DIR = ""
OUTPUT_DIR = ""
FLIP_TYPE = 1 # (0 is vertical, 1 is horizontal)
def ... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | """
Output:
Enter an Infix Equation = a + b ^c
Symbol | Stack | Postfix
----------------------------
c | | c
^ | ^ | c
b | ^ | cb
+ | + | cb^
a | + | cb^a
| | cb^a+
a+b^c (Infix) -> +a^bc (Prefix)
"""
def infix_2_postf... | """
Output:
Enter an Infix Equation = a + b ^c
Symbol | Stack | Postfix
----------------------------
c | | c
^ | ^ | c
b | ^ | cb
+ | + | cb^
a | + | cb^a
| | cb^a+
a+b^c (Infix) -> +a^bc (Prefix)
"""
def infix_2_postf... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | -1 | ||
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | def print_dist(dist, v):
print("\nVertex Distance")
for i in range(v):
if dist[i] != float("inf"):
print(i, "\t", int(dist[i]), end="\t")
else:
print(i, "\t", "INF", end="\t")
print()
def min_dist(mdist, vset, v):
min_val = float("inf")
min_ind = -1
... | def print_dist(dist, v):
print("\nVertex Distance")
for i in range(v):
if dist[i] != float("inf"):
print(i, "\t", int(dist[i]), end="\t")
else:
print(i, "\t", "INF", end="\t")
print()
def min_dist(mdist, vset, v):
min_val = float("inf")
min_ind = -1
... | -1 |
TheAlgorithms/Python | 8,959 | Fix minor typing errors in maths/ | ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types from variables from different scope... | CaedenPH | 2023-08-14T10:19:55Z | 2023-08-15T21:27:42Z | 7618a92fee002475b3bed9227944972d346db440 | 490e645ed3b7ae50f0d7e23e047d088ba069ed56 | Fix minor typing errors in maths/. ### Describe your change:
Some changes include:
- Replacing all occurrences of `np.array` types with `np.ndarray`, the class returned from `np.array`
- Typing certain function bodies
- Refactoring `jaccard_similarity` to include types and fix `mypy` errors (bug) that stored types ... | # https://www.investopedia.com
from __future__ import annotations
def simple_interest(
principal: float, daily_interest_rate: float, days_between_payments: float
) -> float:
"""
>>> simple_interest(18000.0, 0.06, 3)
3240.0
>>> simple_interest(0.5, 0.06, 3)
0.09
>>> simple_interest(18000.0... | # https://www.investopedia.com
from __future__ import annotations
def simple_interest(
principal: float, daily_interest_rate: float, days_between_payments: float
) -> float:
"""
>>> simple_interest(18000.0, 0.06, 3)
3240.0
>>> simple_interest(0.5, 0.06, 3)
0.09
>>> simple_interest(18000.0... | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.