This file contains 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
import random | |
def get_random_hex(length): | |
return hex(random.getrandbits(length*4))[2:].zfill(length) | |
# >>> print(get_random_hex(8)) | |
# 062e08db |
This file contains 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
def cipher(string: str, offset: int) -> str: | |
result = '' | |
for char in string: | |
if 'a' <= char <= 'z': | |
start, end = 'a', 'z' | |
elif 'A' <= char <= 'Z': | |
start, end = 'A', 'Z' | |
else: | |
start, end = char, char | |
This file contains 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
def assumption_sort(array): | |
"""An O(1) sorting algorithm | |
Sorts in O(1) time. Sorts and returns the input array assuming it is already | |
sorted - if it is not then output of this function is an implementation | |
detail and is left undefined. | |
""" | |
return array |
This file contains 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
def despamify(text: str, threshold=5) -> tuple[bool, str]: | |
last_char = "" | |
repeat_count = 0 | |
despammed = False | |
output = "" | |
for char in text: | |
if char == last_char: | |
repeat_count += 1 | |
else: |