mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Create codespell.yml (#1698)
* fixup! Format Python code with psf/black push * Create codespell.yml * fixup! Format Python code with psf/black push
This commit is contained in:
@@ -12,7 +12,7 @@ https://www.hackerearth.com/practice/notes/matrix-exponentiation-1/
|
||||
|
||||
class Matrix:
|
||||
def __init__(self, arg):
|
||||
if isinstance(arg, list): # Initialzes a matrix identical to the one provided.
|
||||
if isinstance(arg, list): # Initializes a matrix identical to the one provided.
|
||||
self.t = arg
|
||||
self.n = len(arg)
|
||||
else: # Initializes a square matrix of the given size and set the values to zero.
|
||||
@@ -50,7 +50,7 @@ def fibonacci_with_matrix_exponentiation(n, f1, f2):
|
||||
|
||||
|
||||
def simple_fibonacci(n, f1, f2):
|
||||
# Trival Cases
|
||||
# Trivial Cases
|
||||
if n == 1:
|
||||
return f1
|
||||
elif n == 2:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Refrences: https://en.wikipedia.org/wiki/M%C3%B6bius_function
|
||||
References: https://en.wikipedia.org/wiki/M%C3%B6bius_function
|
||||
References: wikipedia:square free number
|
||||
python/black : True
|
||||
flake8 : True
|
||||
|
||||
@@ -4,18 +4,18 @@ Sieve of Eratosthenes
|
||||
Input : n =10
|
||||
Output : 2 3 5 7
|
||||
|
||||
Input : n = 20
|
||||
Input : n = 20
|
||||
Output: 2 3 5 7 11 13 17 19
|
||||
|
||||
you can read in detail about this at
|
||||
you can read in detail about this at
|
||||
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
"""
|
||||
|
||||
|
||||
def prime_sieve_eratosthenes(num):
|
||||
"""
|
||||
print the prime numbers upto n
|
||||
|
||||
print the prime numbers up to n
|
||||
|
||||
>>> prime_sieve_eratosthenes(10)
|
||||
2 3 5 7
|
||||
>>> prime_sieve_eratosthenes(20)
|
||||
@@ -26,7 +26,7 @@ def prime_sieve_eratosthenes(num):
|
||||
p = 2
|
||||
|
||||
while p * p <= num:
|
||||
if primes[p] == True:
|
||||
if primes[p]:
|
||||
for i in range(p * p, num + 1, p):
|
||||
primes[i] = False
|
||||
p += 1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Numerical integration or quadrature for a smooth function f with known values at x_i
|
||||
|
||||
This method is the classical approch of suming 'Equally Spaced Abscissas'
|
||||
This method is the classical approach of suming 'Equally Spaced Abscissas'
|
||||
|
||||
method 2:
|
||||
"Simpson Rule"
|
||||
|
||||
@@ -22,7 +22,7 @@ def square_root_iterative(
|
||||
a: float, max_iter: int = 9999, tolerance: float = 0.00000000000001
|
||||
) -> float:
|
||||
"""
|
||||
Sqaure root is aproximated using Newtons method.
|
||||
Square root is aproximated using Newtons method.
|
||||
https://en.wikipedia.org/wiki/Newton%27s_method
|
||||
|
||||
>>> all(abs(square_root_iterative(i)-math.sqrt(i)) <= .00000000000001 for i in range(0, 500))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Numerical integration or quadrature for a smooth function f with known values at x_i
|
||||
|
||||
This method is the classical approch of suming 'Equally Spaced Abscissas'
|
||||
This method is the classical approach of suming 'Equally Spaced Abscissas'
|
||||
|
||||
method 1:
|
||||
"extended trapezoidal rule"
|
||||
|
||||
@@ -31,17 +31,17 @@ def zeller(date_input: str) -> str:
|
||||
...
|
||||
ValueError: invalid literal for int() with base 10: '.4'
|
||||
|
||||
Validate second seperator:
|
||||
Validate second separator:
|
||||
>>> zeller('01-31*2010')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Date seperator must be '-' or '/'
|
||||
ValueError: Date separator must be '-' or '/'
|
||||
|
||||
Validate first seperator:
|
||||
Validate first separator:
|
||||
>>> zeller('01^31-2010')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Date seperator must be '-' or '/'
|
||||
ValueError: Date separator must be '-' or '/'
|
||||
|
||||
Validate out of range year:
|
||||
>>> zeller('01-31-8999')
|
||||
@@ -55,7 +55,7 @@ def zeller(date_input: str) -> str:
|
||||
...
|
||||
TypeError: zeller() missing 1 required positional argument: 'date_input'
|
||||
|
||||
Test length fo date_input:
|
||||
Test length of date_input:
|
||||
>>> zeller('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
@@ -92,7 +92,7 @@ def zeller(date_input: str) -> str:
|
||||
sep_1: str = date_input[2]
|
||||
# Validate
|
||||
if sep_1 not in ["-", "/"]:
|
||||
raise ValueError("Date seperator must be '-' or '/'")
|
||||
raise ValueError("Date separator must be '-' or '/'")
|
||||
|
||||
# Get day
|
||||
d: int = int(date_input[3] + date_input[4])
|
||||
@@ -100,11 +100,11 @@ def zeller(date_input: str) -> str:
|
||||
if not 0 < d < 32:
|
||||
raise ValueError("Date must be between 1 - 31")
|
||||
|
||||
# Get second seperator
|
||||
# Get second separator
|
||||
sep_2: str = date_input[5]
|
||||
# Validate
|
||||
if sep_2 not in ["-", "/"]:
|
||||
raise ValueError("Date seperator must be '-' or '/'")
|
||||
raise ValueError("Date separator must be '-' or '/'")
|
||||
|
||||
# Get year
|
||||
y: int = int(date_input[6] + date_input[7] + date_input[8] + date_input[9])
|
||||
|
||||
Reference in New Issue
Block a user