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 math | |
from typing import List | |
def get_note_names(frequencies: List[float]) -> List[str]: | |
"""Convert frequencies to musical note names using A440 pitch standard. | |
Takes a list of frequencies in Hz and returns their corresponding musical notes, | |
indicating if they are sharp or flat relative to the standard pitch. |
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
from typing import List | |
from itertools import accumulate | |
def find_shield_break(shield_attacks: List[int], shield_capacity: int) -> int: | |
"""Finds the index where cumulative damage exceeds shield capacity. | |
Uses itertools.accumulate for efficient cumulative sum calculation. | |
Short-circuits when shield break is detected. |
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
""" | |
NFL Uniform Number Management | |
Defines valid NFL uniform number ranges by position according to official regulations. | |
Provides utilities to validate and find available numbers for players. | |
Position Groups and Number Ranges: | |
Offense: | |
- QB (Quarterback): 1-19 | |
- RB (Running Back): 20-49 |
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
from typing import Dict, Callable, Final | |
from operator import add, sub, mul, floordiv | |
OPERATORS: Final[Dict[str, Callable[[int, int], int]]] = { | |
"+": add, | |
"-": sub, | |
"*": mul, | |
"/": floordiv, | |
} |
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
""" | |
String Anagrams Finder | |
This module provides two different implementations for finding anagrams of a pattern | |
string within a larger text string. It includes both a sliding window approach (efficient) | |
and a permutation-based approach (for educational purposes). | |
Example: | |
>>> find_anagrams_sliding_window("cbaebabacd", "abc") | |
[0, 6] |
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
from typing import List | |
def longest_subsequence(numbers: List[int]) -> int: | |
""" | |
Find the length of the longest subsequence of consecutive integers in a list. | |
The difference between consecutive elements is either 1 or -1. | |
Args: | |
numbers (List[int]): A list of integers. |
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
""" | |
NATO phonetic alphabet converter. | |
This module converts text into NATO phonetic alphabet | |
representation, handling special cases like decimal points and quotation marks. | |
""" | |
from typing import Dict, List, Optional | |
# Core NATO phonetic alphabet mapping |
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
from typing import List | |
from itertools import permutations | |
def permute(text: str) -> List[str]: | |
""" | |
Generate all unique permutations of the input string. | |
Uses Python's built-in itertools.permutations for efficient generation | |
of all possible arrangements of characters. Duplicate permutations |
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
""" | |
Holiday date calculation module. | |
This module provides functionality to calculate dates and weekdays for various holidays | |
in the Gregorian calendar, including both fixed-date holidays (like Christmas and New | |
Years Day) and floating holidays (like Easter and Thanksgiving). | |
""" | |
from datetime import date, timedelta | |
from enum import Enum |
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 count_trailing_zeros_in_factorial(n: int) -> int: | |
""" | |
Calculate the number of trailing zeros in n! to determine how many perfectly round cookies are made. | |
Args: | |
n (int): The input number for which to calculate n! and count trailing zeros. | |
Returns: | |
int: The count of trailing zeros in n!. |
NewerOlder