-
-
Notifications
You must be signed in to change notification settings - Fork 47k
Numerous significant improvements Beta #12811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
156 commits
Select commit
Hold shift + click to select a range
6891142
Add doctests for butterfly_pattern.py
lighting9999 22083ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d9b07df
Update minimum_spanning_tree_kruskal2.py
lighting9999 97b33b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 158128c
Update lru_cache.py
lighting9999 cecabe3
Update lru_cache.py
lighting9999 9d16049
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2c17e86
Update lfu_cache.py
lighting9999 fcadabe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1e71b72
Update lfu_cache.py
lighting9999 34da76f
Update stack_with_doubly_linked_list.py
lighting9999 ae755a6
Update skew_heap.py
lighting9999 fb07e07
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] be9ff5b
Update skew_heap.py
lighting9999 8abfbf1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd9bdf9
Update skew_heap.py
lighting9999 60cb936
Update skew_heap.py
lighting9999 3627416
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d42704a
Update skew_heap.py
lighting9999 c78fbf7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6e7bd44
Update skew_heap.py
lighting9999 24baa2b
Update test_digital_image_processing.py
lighting9999 127378f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f3f0898
Update test_digital_image_processing.py
lighting9999 aa46117
Update test_digital_image_processing.py
lighting9999 fe0c1b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eed74bf
Update minimum_spanning_tree_prims2.py
lighting9999 8404a25
Update minimum_spanning_tree_prims2.py
lighting9999 a978c35
Update minimum_spanning_tree_prims2.py
lighting9999 a7e4603
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dd16651
Update minimum_spanning_tree_prims2.py
lighting9999 3793d09
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 98e9282
Update matrix_class.py
lighting9999 54f2730
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d5ab844
Update matrix_class.py
lighting9999 d1d1bcc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a961455
Update matrix_class.py
lighting9999 8eace88
Update matrix_class.py
lighting9999 ac0dfd3
Update matrix_class.py
lighting9999 b863139
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8166650
Update skew_heap.py
lighting9999 5508c20
Update skew_heap.py
lighting9999 f157d20
Update skew_heap.py
lighting9999 a24fd46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b4117d8
Update skew_heap.py
lighting9999 f0beacc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6b07de6
Update skew_heap.py
lighting9999 0febfb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 78fe5bb
Update skew_heap.py
lighting9999 283601d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e013166
Update skew_heap.py
lighting9999 cf707b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b33f0b0
Update skew_heap.py
lighting9999 f0a4b6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4f0910c
Update skew_heap.py
lighting9999 180d8d5
Update skew_heap.py
lighting9999 c5693db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 84ec049
Update skew_heap.py
lighting9999 1273319
Update skew_heap.py
lighting9999 a1a379c
Update minimum_spanning_tree_prims2.py
lighting9999 bf11752
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4226641
fix sum_of_digits.py
lighting9999 a2b2951
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3361c55
Update skew_heap.py
lighting9999 96ade05
Update skew_heap.py
lighting9999 bf93372
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 072a3d6
fix skew_heap.py
lighting9999 ed6be0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a35036f
fix l001 skew_heap.py
lighting9999 208adb1
Update skew_heap.py
lighting9999 06cb5d3
Update atbash.py
lighting9999 b1e0e3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 23772e7
Update pascal_triangle.py
lighting9999 adc0210
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 13d179b
Update pascal_triangle.py
lighting9999 21e2c45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4ad424a
Update shuffled_shift_cipher.py
lighting9999 c901985
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7bbfdca
Update diff_views_of_binary_tree.py
lighting9999 9ab3e07
Update binary_search_tree.py
lighting9999 fef70fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 33b0846
Delete data_structures/binary_tree/red_black_tree.py
lighting9999 bac8021
Add red_black_tree.py
lighting9999 e7f3e0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b6ed393
Update red_black_tree.py
lighting9999 00f7847
Update red_black_tree.py
lighting9999 52891a4
Update red_black_tree.py
lighting9999 99ea24e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] be02fd5
Update red_black_tree.py
lighting9999 11c74ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 76b34e8
Update red_black_tree.py
lighting9999 6c499c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fbd60e6
Update binary_search_tree.py
lighting9999 91cb294
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] de2c080
Update diff_views_of_binary_tree.py
lighting9999 1a25ad6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e6ad021
Update avl_tree.py
lighting9999 28a57e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c7d9326
Update binary_search_tree.py
lighting9999 c8747af
Update red_black_tree.py
lighting9999 8cccecf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 71cba73
Update red_black_tree.py
lighting9999 4bb794d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 17ea820
Update red_black_tree.py
lighting9999 2762dbc
Update red_black_tree.py
lighting9999 03d7920
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2adfd0b
Update avl_tree.py
lighting9999 7504e8d
Update binary_search_tree.py
lighting9999 0ea5a47
Update treap.py
lighting9999 44ce050
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3bea2fa
Update local_weighted_learning.py
lighting9999 42ee813
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b8116a1
Update sha256.py
lighting9999 26a0655
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d73d647
Update mfcc.py
lighting9999 ae67342
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9219789
Update hill_cipher.py
lighting9999 bea40aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3f70e94
Update requirements.txt
lighting9999 2aa8610
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4268f2e
Update hill_cipher.py
lighting9999 30d5ff2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fa453bc
Update hill_cipher.py
lighting9999 a24b482
Update hill_cipher.py
lighting9999 fa54f68
Update pyproject.toml
lighting9999 d971725
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6e83656
Update hill_cipher.py
lighting9999 5fa46b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8185cc0
Update hill_cipher.py
lighting9999 a5cc16e
Update hill_cipher.py
lighting9999 77e427e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b1d0d1f
Update hill_cipher.py
lighting9999 9ed3bbe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5b090a3
Update hill_cipher.py
lighting9999 3c4e968
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1755567
Update hill_cipher.py
lighting9999 c762326
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fc7451f
Update hill_cipher.py
lighting9999 a9f3230
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 90e39fb
Update hill_cipher.py
lighting9999 e9b4412
Update hill_cipher.py
lighting9999 d1730fc
Update pyproject.toml
lighting9999 d0ea216
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6c75ea1
Update send_file.py
lighting9999 91b2f25
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6ac7dd8
rallback pyproject.toml
lighting9999 b7a9585
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea77031
Update average_median.py
lighting9999 5d1b795
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3b0d81f
Update singly_linked_list.py
lighting9999 d857ae2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa63803
Update current_stock_price.py
lighting9999 3eed96c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 21381f3
Update current_stock_price.py
lighting9999 1c15757
Update current_stock_price.py
lighting9999 2040c60
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,52 +3,34 @@ | |
import string | ||
|
||
|
||
def atbash_slow(sequence: str) -> str: | ||
def atbash(text: str) -> str: | ||
""" | ||
>>> atbash_slow("ABCDEFG") | ||
'ZYXWVUT' | ||
Encodes or decodes text using the Atbash cipher. | ||
|
||
>>> atbash_slow("aW;;123BX") | ||
'zD;;123YC' | ||
""" | ||
output = "" | ||
for i in sequence: | ||
extract = ord(i) | ||
if 65 <= extract <= 90: | ||
output += chr(155 - extract) | ||
elif 97 <= extract <= 122: | ||
output += chr(219 - extract) | ||
else: | ||
output += i | ||
return output | ||
|
||
|
||
def atbash(sequence: str) -> str: | ||
""" | ||
>>> atbash("ABCDEFG") | ||
'ZYXWVUT' | ||
|
||
>>> atbash("aW;;123BX") | ||
'zD;;123YC' | ||
""" | ||
letters = string.ascii_letters | ||
letters_reversed = string.ascii_lowercase[::-1] + string.ascii_uppercase[::-1] | ||
return "".join( | ||
letters_reversed[letters.index(c)] if c in letters else c for c in sequence | ||
) | ||
The Atbash cipher substitutes each letter with its mirror in the alphabet: | ||
A -> Z, B -> Y, C -> X, ... Z -> A (case is preserved) | ||
Non-alphabetic characters are left unchanged. | ||
|
||
Args: | ||
text: The input string to encode/decode | ||
|
||
def benchmark() -> None: | ||
"""Let's benchmark our functions side-by-side...""" | ||
from timeit import timeit | ||
Returns: | ||
The transformed string | ||
""" | ||
# Create translation tables for uppercase and lowercase | ||
lowercase_map = str.maketrans(string.ascii_lowercase, string.ascii_lowercase[::-1]) | ||
uppercase_map = str.maketrans(string.ascii_uppercase, string.ascii_uppercase[::-1]) | ||
|
||
print("Running performance benchmarks...") | ||
setup = "from string import printable ; from __main__ import atbash, atbash_slow" | ||
print(f"> atbash_slow(): {timeit('atbash_slow(printable)', setup=setup)} seconds") | ||
print(f"> atbash(): {timeit('atbash(printable)', setup=setup)} seconds") | ||
# Apply both translation mappings | ||
return text.translate(lowercase_map).translate(uppercase_map) | ||
|
||
|
||
# Example usage | ||
if __name__ == "__main__": | ||
for example in ("ABCDEFGH", "123GGjj", "testStringtest", "with space"): | ||
print(f"{example} encrypted in atbash: {atbash(example)}") | ||
benchmark() | ||
test_string = "Hello, World! 123" | ||
encoded = atbash(test_string) | ||
decoded = atbash(encoded) | ||
|
||
print(f"Original: {test_string}") | ||
print(f"Encoded: {encoded}") | ||
print(f"Decoded: {decoded}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are worse than the code that they replace. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of benchmark is to measure the speed of the algorithms. Replacing the algorithm defeats the purpose of this function.