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
""" | |
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 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 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!. |
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, Optional | |
import random | |
class WhiteElephantGame: | |
""" | |
A simulation of the White Elephant Gift Exchange game. https://www.whiteelephantrules.com/ | |
Overview: | |
The game involves players taking turns to either open a new gift from a pool of unopened gifts |
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 Sequence | |
from array import array | |
from itertools import accumulate | |
def wrap_gifts(gift_lengths: Sequence[int], paper_width: int) -> int: | |
""" | |
Find the maximum number of gifts that can be wrapped using a single strip of wrapping paper. | |
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 typing import List | |
def roll_call(names: List[str]) -> List[str]: | |
""" | |
Reverses each name in the input list, then sorts the names alphabetically. | |
Args: | |
names (List[str]): A list of names to reverse and sort. |
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 max_the_stock(prices: List[int]) -> int: | |
""" | |
Determine the maximum profit achievable by buying and selling a stock once. | |
Args: | |
prices (List[int]): A list of integers representing stock prices in chronological order. |
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 see_buildings_left(buildings: List[int]) -> int: | |
""" | |
Calculate the number of buildings visible from the left. | |
A building is visible if it is taller than all the buildings to its left. | |
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 | |
def group_anagrams(words: List[str]) -> List[List[str]]: | |
"""Groups an array of strings into lists of anagrams. | |
Args: | |
words (List[str]): List of words to group by anagrams. |
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 random | |
from collections import Counter | |
from typing import List, Dict | |
def roll_dice(num_dice: int = 5) -> List[int]: | |
""" | |
Rolls a specified number of dice and returns their values as a list. | |
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
import xml.etree.ElementTree as ET | |
from urllib.request import urlopen, Request | |
from urllib.error import URLError | |
from typing import Optional | |
# Attempt to import feedparser; set flag based on availability | |
try: | |
import feedparser | |
USE_FEEDPARSER = True |