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 xml.sax.saxutils import escape | |
def generate_circle(radius: int, center: tuple[int, int], color: str) -> str: | |
""" | |
Generates a valid SVG string for a circle. | |
Args: | |
radius (int): The radius of the circle (must be positive). | |
center (tuple[int, int]): The (x, y) center position of the circle. |
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 collections import Counter | |
from dataclasses import dataclass | |
from datetime import datetime, timedelta | |
from typing import List | |
@dataclass | |
class Ingredient: | |
""" | |
Class to represent an ingredient and its expiration date. |
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, Optional | |
class StringSplitter: | |
@staticmethod | |
def split(string: str, delimiter: Optional[str] = None) -> List[str]: | |
""" | |
Splits the input string by the specified delimiter. | |
Args: |
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 collections import defaultdict | |
from typing import List, Tuple | |
# Define the type alias for better readability (colour and fabric tuple) | |
ClothingItem = Tuple[str, str] | |
def min_laundry_loads(items: List[ClothingItem]) -> int: | |
""" | |
This function takes a list of clothing items, each represented by a tuple |
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
def ways_to_score(total_points: int) -> int: | |
""" | |
Calculate the number of unique ways in American Football 🏈 to score exactly total_points | |
using combinations of touchdowns (6 points), field goals (3 points), and safeties (2 points). | |
:param total_points: An integer representing the total points to score. | |
:return: The number of unique ways to score exactly total_points. | |
""" | |
# ways[i] will hold the number of ways to score exactly i points. |
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 min_rows(groups: List[int], row_size: int) -> int: | |
""" | |
Calculate the minimum number of rows required to seat all groups | |
without splitting them across rows. | |
:param groups: List of integers where each integer represents a group size. | |
:param row_size: Integer representing the maximum number of people that can sit in a row. |
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 collections import defaultdict | |
from typing import List | |
def max_pairs(shoes: List[str]) -> int: | |
""" | |
Calculate the maximum number of matching pairs of shoes that can be formed. | |
:param shoes: A list of strings where each string represents a shoe with | |
its type ('L' for left or 'R' for right) and its size. |
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 Set | |
def equal_letters_digits(s: str) -> str: | |
""" | |
Finds the longest substring in the input string `s` where the number of distinct letters equals the number of distinct digits. | |
If there are multiple substrings with the same length, return the one that appears first. | |
:param s: The input string containing letters and digits. | |
:return: The longest valid substring according to the conditions, or an empty string if no such substring exists. |
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 collections import defaultdict | |
from typing import Dict, List | |
class LogEntry: | |
""" | |
Represents a log entry for a function call. | |
Attributes: | |
name (str): The name of the function. |
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 collections import defaultdict | |
from typing import List, Set | |
def find_unused(lines: List[str]) -> List[str]: | |
""" | |
Identify variables that are assigned but never used. | |
Examples: | |
```find_unused(["a = 1", "b = a", "c = 2", "log(b)"]) # ["c"]``` |