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
""" | |
Finds the largest interval in semitones between consecutive piano notes. | |
Supports both a standard library implementation and an optimized version | |
using the `mido` library (if installed). | |
USAGE: | |
- If `mido` is installed (`pip install mido` or `uv pip install mido`), it will use it automatically. | |
- If `mido` is not available, it falls back to a pure Python implementation. | |
""" |
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
""" | |
A store is going out of business and will reduce the price of all products by 10% every week leading up to the closing date. | |
Given the closing_date, visit_date, and the original_price of a product, this function returns the price of the product on the visit_date. | |
The function assumes that original_price is a positive number. | |
Examples: | |
>>> calculate_price('2025-04-01', '2025-03-03', 100) # 4 weeks of discounts | |
65.61 | |
>>> calculate_price('2025-04-01', '2025-03-15', 50) # 2 weeks of discounts | |
40.5 |
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
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 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
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 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
""" | |
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 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
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 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
""" | |
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 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
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 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
""" | |
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 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
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 |
NewerOlder