mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Re-blacken (#2246)
* Avoid double spaces * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
e2ee52d773
commit
4535283554
@ -8,14 +8,7 @@ This file contains the test-suite for the linear algebra library.
|
|||||||
"""
|
"""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from lib import (
|
from lib import Matrix, Vector, axpy, squareZeroMatrix, unitBasisVector, zeroVector
|
||||||
Matrix,
|
|
||||||
Vector,
|
|
||||||
axpy,
|
|
||||||
squareZeroMatrix,
|
|
||||||
unitBasisVector,
|
|
||||||
zeroVector,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -28,7 +28,7 @@ def num_digits_fast(n: int) -> int:
|
|||||||
>>> num_digits_fast(123)
|
>>> num_digits_fast(123)
|
||||||
3
|
3
|
||||||
"""
|
"""
|
||||||
return (math.floor(math.log(abs(n), 10) + 1))
|
return math.floor(math.log(abs(n), 10) + 1)
|
||||||
|
|
||||||
|
|
||||||
def num_digits_faster(n: int) -> int:
|
def num_digits_faster(n: int) -> int:
|
||||||
@ -41,7 +41,7 @@ def num_digits_faster(n: int) -> int:
|
|||||||
>>> num_digits_faster(123)
|
>>> num_digits_faster(123)
|
||||||
3
|
3
|
||||||
"""
|
"""
|
||||||
return (len(str(abs(n))))
|
return len(str(abs(n)))
|
||||||
|
|
||||||
|
|
||||||
def benchmark() -> None:
|
def benchmark() -> None:
|
||||||
@ -49,47 +49,83 @@ def benchmark() -> None:
|
|||||||
Benchmark code for comparing 3 functions,
|
Benchmark code for comparing 3 functions,
|
||||||
with 3 different length int values.
|
with 3 different length int values.
|
||||||
"""
|
"""
|
||||||
print('\nFor small_num = ', small_num, ':')
|
print("\nFor small_num = ", small_num, ":")
|
||||||
print("> num_digits()",
|
print(
|
||||||
'\t\tans =', num_digits(small_num),
|
"> num_digits()",
|
||||||
'\ttime =', timeit("z.num_digits(z.small_num)",
|
"\t\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits(small_num),
|
||||||
print("> num_digits_fast()",
|
"\ttime =",
|
||||||
'\tans =', num_digits_fast(small_num),
|
timeit("z.num_digits(z.small_num)", setup="import __main__ as z"),
|
||||||
'\ttime =', timeit("z.num_digits_fast(z.small_num)",
|
"seconds",
|
||||||
setup="import __main__ as z"), "seconds")
|
)
|
||||||
print("> num_digits_faster()",
|
print(
|
||||||
'\tans =', num_digits_faster(small_num),
|
"> num_digits_fast()",
|
||||||
'\ttime =', timeit("z.num_digits_faster(z.small_num)",
|
"\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits_fast(small_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_fast(z.small_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"> num_digits_faster()",
|
||||||
|
"\tans =",
|
||||||
|
num_digits_faster(small_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_faster(z.small_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
|
||||||
print('\nFor medium_num = ', medium_num, ':')
|
print("\nFor medium_num = ", medium_num, ":")
|
||||||
print("> num_digits()",
|
print(
|
||||||
'\t\tans =', num_digits(medium_num),
|
"> num_digits()",
|
||||||
'\ttime =', timeit("z.num_digits(z.medium_num)",
|
"\t\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits(medium_num),
|
||||||
print("> num_digits_fast()",
|
"\ttime =",
|
||||||
'\tans =', num_digits_fast(medium_num),
|
timeit("z.num_digits(z.medium_num)", setup="import __main__ as z"),
|
||||||
'\ttime =', timeit("z.num_digits_fast(z.medium_num)",
|
"seconds",
|
||||||
setup="import __main__ as z"), "seconds")
|
)
|
||||||
print("> num_digits_faster()",
|
print(
|
||||||
'\tans =', num_digits_faster(medium_num),
|
"> num_digits_fast()",
|
||||||
'\ttime =', timeit("z.num_digits_faster(z.medium_num)",
|
"\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits_fast(medium_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_fast(z.medium_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"> num_digits_faster()",
|
||||||
|
"\tans =",
|
||||||
|
num_digits_faster(medium_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_faster(z.medium_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
|
||||||
print('\nFor large_num = ', large_num, ':')
|
print("\nFor large_num = ", large_num, ":")
|
||||||
print("> num_digits()",
|
print(
|
||||||
'\t\tans =', num_digits(large_num),
|
"> num_digits()",
|
||||||
'\ttime =', timeit("z.num_digits(z.large_num)",
|
"\t\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits(large_num),
|
||||||
print("> num_digits_fast()",
|
"\ttime =",
|
||||||
'\tans =', num_digits_fast(large_num),
|
timeit("z.num_digits(z.large_num)", setup="import __main__ as z"),
|
||||||
'\ttime =', timeit("z.num_digits_fast(z.large_num)",
|
"seconds",
|
||||||
setup="import __main__ as z"), "seconds")
|
)
|
||||||
print("> num_digits_faster()",
|
print(
|
||||||
'\tans =', num_digits_faster(large_num),
|
"> num_digits_fast()",
|
||||||
'\ttime =', timeit("z.num_digits_faster(z.large_num)",
|
"\tans =",
|
||||||
setup="import __main__ as z"), "seconds")
|
num_digits_fast(large_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_fast(z.large_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"> num_digits_faster()",
|
||||||
|
"\tans =",
|
||||||
|
num_digits_faster(large_num),
|
||||||
|
"\ttime =",
|
||||||
|
timeit("z.num_digits_faster(z.large_num)", setup="import __main__ as z"),
|
||||||
|
"seconds",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
import requests
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
def horoscope(zodiac_sign: int, day: str) -> str:
|
def horoscope(zodiac_sign: int, day: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user