task_id
stringlengths
4
6
prompt
stringlengths
152
1.04k
canonical_solution
stringlengths
18
953
test
stringlengths
135
1.8k
entry_point
stringlengths
2
37
en/0
def calculate_tsubo(x: float, y: float) -> int: """ Calculates the size of the land with the specified length x meters and width y meters, and returns the number of tsubos. The land size is returned as an integer. 1 tsubo = 3.30579 square meters Args: x (float): Vertical length of land (meters) y (float): horizontal length of land (meters) Returns: int: Returns the land area in tsubo units. Example: >>> calculate_tsubo(10, 10) 30 >>> calculate_tsubo(5, 7) 10 """
area_square_meters = x * y tsubo = area_square_meters / 3.30579 return int(tsubo)
def check(candidate): assert candidate(10.0, 10.0) == 30 assert candidate(5.5, 7.2) == 11 assert candidate(0.3, 10.0) == 0 assert candidate(10.0, 0.3) == 0 assert candidate(0.0, 0.0) == 0 assert candidate(100.0, 100.0) == 3024 assert candidate(5.5, 5.5) == 9 assert candidate(3.14, 3.14) == 2
calculate_tsubo
en/1
def calculate_tax_included_price(amount: int) -> int: """ Calculate the tax-included amount by adding consumption tax to the total amount at the time of takeout. The consumption tax rate is calculated at 8%, rounded off, and returned as an integer. argument: amount (int): Total amount for takeout (excluding tax) Return value: int: Tax-included amount including consumption tax (rounded off) Usage example: >>> calculate_tax_included_price(1000) 1080 >>> calculate_tax_included_price(500) 540 >>> calculate_tax_included_price(1234) 1333 """
tax_rate = 0.08 tax_included_price = amount * (1 + tax_rate) return round(tax_included_price)
def check(candidate): assert candidate(1000) == 1080 assert candidate(500) == 540 assert candidate(1234) == 1333 assert candidate(0) == 0 assert candidate(1) == 1 assert candidate(2500) == 2700 assert candidate(999) == 1079
calculate_tax_included_price
en/2
def tatami_to_square_meters(n: int) -> float: """ Convert the number of tatami mats to square meters and calculate to two decimal places. Convert as 1 tatami = 1.62 square meters. argument: n (int): number of tatami mats Return value: float: square meter (2 decimal places) Usage example: >>> tatami_to_square_meters(1) 1.62 >>> tatami_to_square_meters(6) 9.72 >>> tatami_to_square_meters(10) 16.20 """
square_meters = n * 1.62 return round(square_meters, 2)
def check(candidate): assert candidate(1) == 1.62 assert candidate(2) == 3.24 assert candidate(3) == 4.86 assert candidate(6) == 9.72 assert candidate(6) == 9.72 assert candidate(9) == 14.58 assert candidate(10) == 16.20 assert candidate(15) == 24.30 assert candidate(20) == 32.40
tatami_to_square_meters
en/3
def tokyo_dome_units(n: int) -> float: """ Calculates how many Tokyo Dome areas are covered by the given area `n` and returns it in two decimal places. `n` is an integer value representing the area you want to calculate in square meters. The area equivalent to one Tokyo Dome is approximately 46,755 square meters. argument: n (int): Area to be calculated (square meters) Return value: float: How many Tokyo Domes the area is equivalent to (up to 2 decimal places) example: >>> tokyo_dome_units(100000) 2.14 >>> tokyo_dome_units(50000) 1.07 >>> tokyo_dome_units(46755) 1.00 """
# ๆฑไบฌใƒ‰ใƒผใƒ ใฎๅบŠ้ข็ฉ๏ผˆๅนณๆ–นใƒกใƒผใƒˆใƒซ๏ผ‰ tokyo_dome_area = 46755 # ๆฑไบฌใƒ‰ใƒผใƒ ไฝ•ๅ€‹ๅˆ†ใ‹ใ‚’่จˆ็ฎ—ใ—ใฆใ€ๅฐๆ•ฐ็‚นไปฅไธ‹2ๆกใพใงใฎๆตฎๅ‹•ๅฐๆ•ฐ็‚นๆ•ฐใง่ฟ”ใ™ units = n / tokyo_dome_area return round(units, 2)
def check(candidate): assert candidate(100000) == 2.14 assert candidate(50000) == 1.07 assert candidate(46755) == 1.00 assert candidate(46755 * 2) == 2.00 assert candidate(46755 * 10) == 10.00 assert candidate(1000000) == 21.39 assert candidate(467550) == 10.00
tokyo_dome_units
en/4
def judge_janken(a: str, b: str) -> str: """ Determines the result of rock, paper, scissors and returns the winner as "A" or "B", and in case of a tie, returns "ๅผ•ใๅˆ†ใ‘". It is based on the rule that "ใ‚ฐใƒผ" beats "ใƒใƒงใ‚ญ", "ใƒใƒงใ‚ญ" beats "ใƒ‘ใƒผ", and "ใƒ‘ใƒผ" beats "ใ‚ฐใƒผ". argument: a (str): Player A's hand ("ใ‚ฐใƒผ", "ใƒใƒงใ‚ญ", "ใƒ‘ใƒผ") b (str): Player B's hand ("ใ‚ฐใƒผ", "ใƒใƒงใ‚ญ", "ใƒ‘ใƒผ") Return value: str: Returns the winner as "A" or "B", or "ๅผ•ใๅˆ†ใ‘" in case of a tie. Usage example: >>> judge_janken("ใ‚ฐใƒผ", "ใƒใƒงใ‚ญ") 'A' >>> judge_janken("ใƒ‘ใƒผ", "ใƒใƒงใ‚ญ") 'B' >>> judge_janken("ใ‚ฐใƒผ", "ใ‚ฐใƒผ") 'ๅผ•ใๅˆ†ใ‘' """
if a == b: return "ๅผ•ใๅˆ†ใ‘" win_map = { ("ใ‚ฐใƒผ", "ใƒใƒงใ‚ญ"): "A", ("ใƒใƒงใ‚ญ", "ใƒ‘ใƒผ"): "A", ("ใƒ‘ใƒผ", "ใ‚ฐใƒผ"): "A", ("ใƒใƒงใ‚ญ", "ใ‚ฐใƒผ"): "B", ("ใƒ‘ใƒผ", "ใƒใƒงใ‚ญ"): "B", ("ใ‚ฐใƒผ", "ใƒ‘ใƒผ"): "B" } return win_map.get((a, b))
def check(candidate): assert candidate("ใ‚ฐใƒผ", "ใƒใƒงใ‚ญ") == "A" assert candidate("ใƒ‘ใƒผ", "ใƒใƒงใ‚ญ") == "B" assert candidate("ใƒใƒงใ‚ญ", "ใ‚ฐใƒผ") == "B" assert candidate("ใ‚ฐใƒผ", "ใƒ‘ใƒผ") == "B" assert candidate("ใƒใƒงใ‚ญ", "ใƒ‘ใƒผ") == "A" assert candidate("ใƒ‘ใƒผ", "ใ‚ฐใƒผ") == "A" assert candidate("ใ‚ฐใƒผ", "ใ‚ฐใƒผ") == "ๅผ•ใๅˆ†ใ‘" assert candidate("ใƒใƒงใ‚ญ", "ใƒใƒงใ‚ญ") == "ๅผ•ใๅˆ†ใ‘" assert candidate("ใƒ‘ใƒผ", "ใƒ‘ใƒผ") == "ๅผ•ใๅˆ†ใ‘"
judge_janken
en/5
def count_pencils(n: int) -> str: """ When counting pencils in Japanese, ``hon'' is added after the number as a particle. This particle is read differently depending on the ones place of the number. If the ones place is "0, 1, 6, or 8", it is read as "ใฝใ‚“", and if it is "3", it is read as "ใผใ‚“". Other numbers such as "2, 4, 5, 7, and 9" are read as "ใปใ‚“". argument: n (int): Number of pencils (positive integer less than or equal to 999) Return value: str: How to read the particle ``hon'' ('ใปใ‚“', 'ใฝใ‚“', or 'ใผใ‚“') Usage example: >>> count_pencils(1) 'ใฝใ‚“' >>> count_pencils(3) 'ใผใ‚“' >>> count_pencils(7) 'ใปใ‚“' """
last_digit = n % 10 if last_digit in [2, 4, 5, 7, 9]: return "ใปใ‚“" elif last_digit in [0, 1, 6, 8]: return "ใฝใ‚“" elif last_digit == 3: return "ใผใ‚“"
def check(candidate): assert candidate(6) == "ใฝใ‚“" assert candidate(8) == "ใฝใ‚“" assert candidate(10) == "ใฝใ‚“" assert candidate(21) == "ใฝใ‚“" assert candidate(3) == "ใผใ‚“" assert candidate(13) == "ใผใ‚“" assert candidate(4) == "ใปใ‚“" assert candidate(5) == "ใปใ‚“" assert candidate(7) == "ใปใ‚“" assert candidate(12) == "ใปใ‚“" assert candidate(99) == "ใปใ‚“"
count_pencils
en/6
def eto_from_year(year: int) -> str: """ Given a year in the Western calendar, find the zodiac sign for that year. The zodiac signs repeat in order: the zodiac (ๅญ, ไธ‘, ๅฏ…, ๅฏ, ่พฐ, ๅทณ, ๅˆ, ๆœช, ็”ณ, ้…‰, ๆˆŒ, ไบฅ). >>> eto_from_year(2024) '่พฐ' >>> eto_from_year(2023) 'ๅฏ' >>> eto_from_year(2000) '่พฐ' """
eto_cycle = ["ๅญ", "ไธ‘", "ๅฏ…", "ๅฏ", "่พฐ", "ๅทณ", "ๅˆ", "ๆœช", "็”ณ", "้…‰", "ๆˆŒ", "ไบฅ"] index = (year - 4) % 12 return eto_cycle[index]
def check(candidate): assert candidate(2020) == "ๅญ" assert candidate(2021) == "ไธ‘" assert candidate(2022) == "ๅฏ…" assert candidate(2023) == "ๅฏ" assert candidate(2024) == "่พฐ" assert candidate(2025) == "ๅทณ" assert candidate(2026) == "ๅˆ" assert candidate(2027) == "ๆœช" assert candidate(2028) == "็”ณ" assert candidate(2029) == "้…‰" assert candidate(2030) == "ๆˆŒ" assert candidate(2031) == "ไบฅ" assert candidate(2008) == "ๅญ" assert candidate(1996) == "ๅญ" assert candidate(1984) == "ๅญ"
eto_from_year
en/7
def is_valid_postal_code(postal_code: str) -> bool: """ A function that determines whether a postal code is formatted correctly. The correct format for a postal code is 123-4567, which meets the following conditions: - It is a 7 digit number. - A hyphen ('-') is between the third and fourth digits. - There is a 3-digit number before the hyphen and a 4-digit number after it. argument: postal_code (str): Postal code string Return value: bool: True if the format is correct, False if it is not. """
# ๆ–‡ๅญ—ๅˆ—ใฎ้•ทใ•ใŒ8ใงใ‚ใ‚Šใ€4ๆ–‡ๅญ—็›ฎใซ '-' ใŒใ‚ใ‚Šใ€ๅ‰3ๆกใจๅพŒ4ๆกใŒๆ•ฐๅญ—ใ‹็ขบ่ช if len(postal_code) == 8 and postal_code[3] == '-': # ใƒใ‚คใƒ•ใƒณๅ‰ใฎ้ƒจๅˆ†ใจใƒใ‚คใƒ•ใƒณๅพŒใฎ้ƒจๅˆ†ใŒๆ•ฐๅญ—ใ‹ใฉใ†ใ‹็ขบ่ช if postal_code[:3].isdigit() and postal_code[4:].isdigit(): return True return False
def check(candidate): assert candidate("123-4567") == True assert candidate("000-0000") == True assert candidate("12-34567") == False assert candidate("1234-567") == False assert candidate("123-456") == False assert candidate("1234567") == False assert candidate("abc-defg") == False
is_valid_postal_code
en/8
def convert_wareki_to_seireki(wareki: str) -> int: """ Converts the given Japanese calendar to the Western calendar. The Japanese calendar is limited to era names from ``ๆ˜Žๆฒป'' to ``ไปคๅ’Œ.'' The Japanese calendar is expressed as "ไปคๅ’Œ3ๅนด" or "ๅนณๆˆ30ๅนด". Argument: wareki (str): Japanese calendar string Return: int: An integer representing the year in the Western calendar Execution example: >>> convert_wareki_to_seireki('ไปคๅ’Œ3ๅนด') 2021 >>> convert_wareki_to_seireki('ๅนณๆˆ30ๅนด') 2018 >>> convert_wareki_to_seireki('ๆ˜ญๅ’Œ64ๅนด') 1989 >>> convert_wareki_to_seireki('ๅนณๆˆๅ…ƒๅนด') 1989 """
eras = { "ไปคๅ’Œ": 2019, "ๅนณๆˆ": 1989, "ๆ˜ญๅ’Œ": 1926, "ๅคงๆญฃ": 1912, "ๆ˜Žๆฒป": 1868 } era_name = wareki[:2] year_str = wareki[2:-1] year = 1 if year_str == "ๅ…ƒ" else int(year_str) return eras[era_name] + year - 1
def check(candidate): assert candidate('ไปคๅ’Œ3ๅนด') == 2021 assert candidate('ๅนณๆˆ30ๅนด') == 2018 assert candidate('ๆ˜ญๅ’Œ64ๅนด') == 1989 assert candidate('ๅนณๆˆๅ…ƒๅนด') == 1989 assert candidate('ๅคงๆญฃๅ…ƒๅนด') == 1912 assert candidate('ๆ˜Žๆฒป45ๅนด') == 1912 assert candidate('ไปคๅ’Œๅ…ƒๅนด') == 2019 assert candidate('ๆ˜ญๅ’Œ1ๅนด') == 1926 assert candidate('ๆ˜Žๆฒป1ๅนด') == 1868
convert_wareki_to_seireki
en/9
def is_shichi_go_san_age(birth_year: int, current_year: int) -> bool: """ Given the year of birth and the current year, determine whether that age is eligible for Shichi-Go-San. Since Shichi-Go-San is celebrated in the years when people are 3, 5, or 7 years old, it returns True if it is applicable, and False otherwise. argument: birth_year (int): Year of birth (Western calendar) current_year (int): Current year (Western calendar) Return value: bool: True if the target age of Shichi-Go-San, otherwise False Execution example: >>> is_shichi_go_san_age(2020, 2023) True # 3 years old >>> is_shichi_go_san_age(2018, 2023) True # 5 years old >>> is_shichi_go_san_age(2016, 2023) True # 7 years old >>> is_shichi_go_san_age(2017, 2023) False >>> is_shichi_go_san_age(2020, 2024) False """
age = current_year - birth_year return age in {3, 5, 7}
def check(candidate): assert candidate(2020, 2023) == True assert candidate(2018, 2023) == True assert candidate(2016, 2023) == True assert candidate(2017, 2023) == False assert candidate(2020, 2024) == False assert candidate(2015, 2023) == False assert candidate(2021, 2023) == False
is_shichi_go_san_age
en/10
def solve_tsurukame(total_animals: int, total_legs: int) -> tuple: """ A function that solves Tsurukame arithmetic. Calculate the number of each from the total of the crane and turtle and the total of the legs. Use the fact that cranes have two legs and turtles have four legs to solve this problem. For example, if the number of cranes is x and the number of turtles is y, the following formula holds. 1. x + y = total_animals (total number of cranes and turtles is given) 2. 2x + 4y = total_legs (given the sum of the legs of the crane and turtle) Transform this simultaneous equation to first find the number of turtles, y, and then find the number of cranes, x, by subtracting the number of turtles from the total number. argument: total_animals (int): Total number of cranes and turtles total_legs (int): total number of legs Return value: tuple: (number of cranes, number of turtles) Usage example: >>> solve_tsurukame(10, 28) (6, 4) """
y = (total_legs - 2 * total_animals) // 2 x = total_animals - y return x, y
def check(candidate): # ๅŸบๆœฌ็š„ใชใƒ†ใ‚นใƒˆใ‚ฑใƒผใ‚น assert candidate(10, 28) == (6, 4) assert candidate(8, 24) == (4, 4) assert candidate(5, 14) == (3, 2) # ้ถดใจไบ€ใŒๅ…จใฆ้ถดใพใŸใฏๅ…จใฆไบ€ใฎๅ ดๅˆ assert candidate(10, 20) == (10, 0) assert candidate(5, 20) == (0, 5) # ใ‚จใƒƒใ‚ธใ‚ฑใƒผใ‚น: ้ถดใจไบ€ใŒ1ๅŒนใšใค assert candidate(2, 6) == (1, 1)
solve_tsurukame
en/11
def get_emergency_service(text: str) -> int: """ If the input string matches the service name of an emergency number, returns that number. Corresponding service name: - ๆถˆ้˜ฒใƒปๆ•‘ๆ€ฅ: 119 - ่ญฆๅฏŸ: 110 - ๅคฉๆฐ—ไบˆๅ ฑ: 177 - ็ฝๅฎณ็”จไผ่จ€ใƒ€ใ‚คใƒคใƒซ: 171 - ๆตทไธŠไฟๅฎ‰ๅบ: 118 - ๆถˆ่ฒป่€…ใƒ›ใƒƒใƒˆใƒฉใ‚คใƒณ: 188 argument: text (str): Service name corresponding to the emergency number. Return value: int: Corresponding emergency phone number (integer). Execution example: >>> extract_emergency_number_from_key("ๆถˆ้˜ฒใƒปๆ•‘ๆ€ฅ") 119 >>> extract_emergency_number_from_key("่ญฆๅฏŸ") 110 >>> extract_emergency_number_from_key("ๅคฉๆฐ—ไบˆๅ ฑ") 177 """
emergency_services = { "ๆถˆ้˜ฒใƒปๆ•‘ๆ€ฅ": 119, "่ญฆๅฏŸ": 110, "ๅคฉๆฐ—ไบˆๅ ฑ": 177, "็ฝๅฎณ็”จไผ่จ€ใƒ€ใ‚คใƒคใƒซ": 171, "ๆตทไธŠไฟๅฎ‰ๅบ": 118, "ๆถˆ่ฒป่€…ใƒ›ใƒƒใƒˆใƒฉใ‚คใƒณ": 188 } return emergency_services.get(text)
def check(candidate): assert candidate("ๆถˆ้˜ฒใƒปๆ•‘ๆ€ฅ") == 119 assert candidate("่ญฆๅฏŸ") == 110 assert candidate("ๅคฉๆฐ—ไบˆๅ ฑ") == 177 assert candidate("็ฝๅฎณ็”จไผ่จ€ใƒ€ใ‚คใƒคใƒซ") == 171 assert candidate("ๆตทไธŠไฟๅฎ‰ๅบ") == 118 assert candidate("ๆถˆ่ฒป่€…ใƒ›ใƒƒใƒˆใƒฉใ‚คใƒณ") == 188
get_emergency_service
en/12
def missing_positions(player_positions): """ Check the baseball positions and identify the missing positions. argument: player_positions (list): List of positions the player is in (in Kanji). Return value: list: List of missing positions. Execution example: >>> positions = ["ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹"] >>> missing_positions(positions) ['ไธญๅ …ๆ‰‹', 'ๅทฆ็ฟผๆ‰‹', 'ๅณ็ฟผๆ‰‹'] >>> positions = ["ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธญๅ …ๆ‰‹", "ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹"] >>> missing_positions(positions) ['ไธ€ๅกๆ‰‹', 'ไบŒๅกๆ‰‹', 'ไธ‰ๅกๆ‰‹', '้Šๆ’ƒๆ‰‹'] """
required_positions = { "ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹", "ไธญๅ …ๆ‰‹", "ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹" } current_positions = set(player_positions) missing = required_positions - current_positions return list(missing)
def check(candidate): assert set(candidate(["ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹"])) == {"ไธญๅ …ๆ‰‹", "ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹"} assert set(candidate(["ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹", "ไธญๅ …ๆ‰‹"])) == {"ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹"} assert set(candidate([])) == {"ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹", "ไธญๅ …ๆ‰‹", "ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹"} assert set(candidate(["ๆŠ•ๆ‰‹", "ๆ•ๆ‰‹", "ไธญๅ …ๆ‰‹"])) == {"ไธ€ๅกๆ‰‹", "ไบŒๅกๆ‰‹", "ไธ‰ๅกๆ‰‹", "้Šๆ’ƒๆ‰‹", "ๅทฆ็ฟผๆ‰‹", "ๅณ็ฟผๆ‰‹"}
missing_positions
en/13
def calculate_salt_solution_concentration(salt: float, water: float) -> float: """ Calculate the concentration of saline solution. Concentration = (weight of salt / (weight of salt + weight of water)) * 100 argument: salt (float): weight of salt (g) water (float): weight of water (g) Return value: float: Concentration of saline solution (%) Usage example: >>> calculate_salt_solution_concentration(10, 90) 10.0 >>> calculate_salt_solution_concentration(15, 85) 15.0 """
if salt + water == 0: return 0.0 concentration = (salt / (salt + water)) * 100 return concentration
def check(candidate): assert candidate(10, 90) == 10.0 assert candidate(15, 85) == 15.0 assert candidate(50, 50) == 50.0 assert candidate(30, 70) == 30.0
calculate_salt_solution_concentration
en/14
def corrections_needed(lyrics: str) -> int: """ Compare the given lyrics with the lyrics of Japan's national anthem "Kimigayo". Calculate the number of edits required to correct mistakes. Lyrics comparison is performed using character strings that do not include spaces. argument: lyrics (str): Lyrics entered by the user Return value: int: Number of times required for insertion/replacement/deletion and correction Execution example: >>> corrections_needed("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใง") 0 >>> corrections_needed("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใ ") 1 """
correct_lyrics = "ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใง" lyrics = lyrics.replace(" ", "") len_lyrics, len_correct = len(lyrics), len(correct_lyrics) dp = [[0] * (len_correct + 1) for _ in range(len_lyrics + 1)] for i in range(len_lyrics + 1): dp[i][0] = i for j in range(len_correct + 1): dp[0][j] = j for i in range(1, len_lyrics + 1): for j in range(1, len_correct + 1): if lyrics[i - 1] == correct_lyrics[j - 1]: cost = 0 else: cost = 1 dp[i][j] = min( dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost ) return dp[len_lyrics][len_correct]
def check(candidate): assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใง") == 0 assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใ ") == 1 assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซ็™พๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใง") == 1 assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Š่‹”ใฎใ‚€ใ™ใพใง") == 1 assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพ") == 1 assert candidate("ๅ›ใŒไปฃๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Šใฆ่‹”ใฎใ‚€ใ™ใพใงใ ใ‚ˆ") == 3 assert candidate("ๅ›ใŒไปฃใฏๅƒไปฃใซๅ…ซๅƒไปฃใซ็ดฐ็ŸณใฎๅทŒใจใชใ‚Š่‹”ใฎใ‚€ใ™ใพ") == 2
corrections_needed
en/15
def get_condiment_by_hiragana(hiragana: str) -> str: """ Returns the seasoning that corresponds to the hiragana in the input line. argument: hiragana (str): Hiragana for the line (``ใ•'', ``ใ—', ``ใ™'', ``ใ›'', ``ใ'') Return value: str: Compatible seasonings ("็ ‚็ณ–", "ๅกฉ", "้…ข", "้†คๆฒน", "miso") Usage example: >>> get_condiment_by_hiragana("ใ•") '็ ‚็ณ–' >>> get_condiment_by_hiragana("ใ—") 'ๅกฉ' >>> get_condiment_by_hiragana("ใ™") '้…ข' >>> get_condiment_by_hiragana("ใ›") '้†คๆฒน' >>> get_condiment_by_hiragana("ใ") 'ๅ‘ณๅ™Œ' """
condiments = { "ใ•": "็ ‚็ณ–", "ใ—": "ๅกฉ", "ใ™": "้…ข", "ใ›": "้†คๆฒน", "ใ": "ๅ‘ณๅ™Œ" } return condiments.get(hiragana)
def check(candidate): assert candidate("ใ•") == "็ ‚็ณ–" assert candidate("ใ—") == "ๅกฉ" assert candidate("ใ™") == "้…ข" assert candidate("ใ›") == "้†คๆฒน" assert candidate("ใ") == "ๅ‘ณๅ™Œ"
get_condiment_by_hiragana
en/16
def classify_bow(angle: int) -> str: """ Based on the angle of the bow, the type of bow ('ไผš้‡ˆ', 'ๆ™ฎ้€š็คผ', 'ๆœ€ๆ•ฌ็คผ') is determined. argument: angle (int): angle of bow (integer) Return value: str: type of bow ('ไผš้‡ˆ', 'ๆ™ฎ้€š็คผ', 'ๆœ€ๆ•ฌ็คผ', or '็„กๅŠนใช่ง’ๅบฆ') Execution example: >>> classify_bow(15) 'ไผš้‡ˆ' >>> classify_bow(30) 'ๆ™ฎ้€š็คผ' >>> classify_bow(45) 'ๆœ€ๆ•ฌ็คผ' >>> classify_bow(20) '็„กๅŠนใช่ง’ๅบฆ' """
if angle == 15: return "ไผš้‡ˆ" elif angle == 30: return "ๆ™ฎ้€š็คผ" elif angle == 45: return "ๆœ€ๆ•ฌ็คผ" else: return "็„กๅŠนใช่ง’ๅบฆ"
def check(candidate): assert candidate(15) == "ไผš้‡ˆ" assert candidate(30) == "ๆ™ฎ้€š็คผ" assert candidate(45) == "ๆœ€ๆ•ฌ็คผ" assert candidate(20) == "็„กๅŠนใช่ง’ๅบฆ" assert candidate(0) == "็„กๅŠนใช่ง’ๅบฆ" assert candidate(60) == "็„กๅŠนใช่ง’ๅบฆ"
classify_bow
en/17
def tatami_area(num_tatami: int, tatami_type: str) -> float: """ Calculate the area of โ€‹โ€‹the room from the number of tatami mats and the type of tatami mats. The type of tatami is designated as ``ๆฑŸๆˆธ้–“'' or ``ไบฌ้–“''. - ๆฑŸๆˆธ้–“: 1.76 square meters (approximately 1.76 square meters) - ไบฌ้–“: 1.82 square meters (approximately 1.82 square meters) argument: num_tatami (int): Number of tatami tatami_type (str): Tatami type. Either 'ๆฑŸๆˆธ้–“' or 'ไบฌ้–“'. Return value: float: area of โ€‹โ€‹the room (square meters) Execution example: >>> tatami_area(6, "ๆฑŸๆˆธ้–“") 10.56 >>> tatami_area(6, "ไบฌ้–“") 10.92 """
tatami_sizes = { "ๆฑŸๆˆธ้–“": 1.76, "ไบฌ้–“": 1.82 } return round(num_tatami * tatami_sizes[tatami_type], 2)
def check(candidate): assert candidate(6, "ๆฑŸๆˆธ้–“") == 10.56 assert candidate(6, "ไบฌ้–“") == 10.92 assert candidate(1, "ๆฑŸๆˆธ้–“") == 1.76 assert candidate(1, "ไบฌ้–“") == 1.82 assert candidate(10, "ๆฑŸๆˆธ้–“") == 17.6 assert candidate(10, "ไบฌ้–“") == 18.2
tatami_area
en/18
def compare_fortunes(last_year: str, this_year: str) -> str: """ Compare last year's fortune with this year's fortune and decide whether this year's fortune is better, worse, or unchanged than last year. Omikuji ranks are evaluated in the following order (left is best): ๅคงๅ‰ > ไธญๅ‰ > ๅฐๅ‰ > ๅ‰ > ๆœซๅ‰ > ๅ‡ถ > ๅคงๅ‡ถ Argument: last_year (str): Last year's omikuji result this_year (str): This year's fortune results Return value: str: Message indicating whether this year is ่‰ฏใ„, ๆ‚ชใ„, or ๅค‰ๅŒ–ใชใ— than last year Example: >>> compare_fortunes("ๅ‰", "ๅคงๅ‰") '่‰ฏใ„' >>> compare_fortunes("ๅคงๅ‰", "ๅฐๅ‰") 'ๆ‚ชใ„' >>> compare_fortunes("ไธญๅ‰", "ไธญๅ‰") 'ๅค‰ๅŒ–ใชใ—' """
fortune_ranks = { "ๅคงๅ‰": 1, "ไธญๅ‰": 2, "ๅฐๅ‰": 3, "ๅ‰": 4, "ๆœซๅ‰": 5, "ๅ‡ถ": 6, "ๅคงๅ‡ถ": 7 } last_rank = fortune_ranks.get(last_year, float('inf')) this_rank = fortune_ranks.get(this_year, float('inf')) if this_rank < last_rank: return '่‰ฏใ„' elif this_rank > last_rank: return 'ๆ‚ชใ„' else: return 'ๅค‰ๅŒ–ใชใ—'
def check(candidate): assert candidate("ๅ‰", "ๅคงๅ‰") == '่‰ฏใ„' assert candidate("ๅคงๅ‰", "ๅฐๅ‰") == 'ๆ‚ชใ„' assert candidate("ไธญๅ‰", "ไธญๅ‰") == 'ๅค‰ๅŒ–ใชใ—' assert candidate("ๅ‡ถ", "ๅ‰") == '่‰ฏใ„' assert candidate("ๅคงๅ‡ถ", "ๅคงๅ‰") == '่‰ฏใ„' assert candidate("ๅคงๅ‰", "ๅคงๅ‡ถ") == 'ๆ‚ชใ„' assert candidate("ๆœซๅ‰", "ๆœซๅ‰") == 'ๅค‰ๅŒ–ใชใ—' assert candidate("ๅฐๅ‰", "ไธญๅ‰") == '่‰ฏใ„' assert candidate("ๅฐๅ‰", "ๅ‡ถ") == 'ๆ‚ชใ„' assert candidate("ไธญๅ‰", "ๅฐๅ‰") == 'ๆ‚ชใ„' assert candidate("ๅคงๅ‰", "ๅคงๅ‰") == 'ๅค‰ๅŒ–ใชใ—'
compare_fortunes
en/19
def judo_match_winner(A: dict, B: dict) -> str: """ Determine the winner or loser of a judo match. argument: A (dict): Player A's score and foul information - "ไธ€ๆœฌ" (int): Number of one - "ๆŠ€ใ‚ใ‚Š" (int): number of wazaari - "ๆŒ‡ๅฐŽ" (int): number of teachings B (dict): Player B's score and foul information - "ไธ€ๆœฌ" (int): Number of one - "ๆŠ€ใ‚ใ‚Š" (int): number of wazaari - "ๆŒ‡ๅฐŽ" (int): number of teachings Return value: str: string representing the winner ("A", "B", "extension") Execution example: >>> judo_match_winner({"ไธ€ๆœฌ": 1, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 0}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 0}) 'A' >>> judo_match_winner({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 2, "ๆŒ‡ๅฐŽ": 1}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 0}) 'A' >>> judo_match_winner({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}) 'ๅปถ้•ท' """
# 1. ไธ€ๆœฌๅ‹ใกใฎๅˆคๅฎš if A["ไธ€ๆœฌ"] > B["ไธ€ๆœฌ"]: return "A" elif A["ไธ€ๆœฌ"] < B["ไธ€ๆœฌ"]: return "B" # 2. ๆŠ€ใ‚ใ‚Šใฎๅˆคๅฎš๏ผˆ2ใคใงไธ€ๆœฌใจๅŒ็ญ‰๏ผ‰ if A["ๆŠ€ใ‚ใ‚Š"] >= 2: return "A" if B["ๆŠ€ใ‚ใ‚Š"] >= 2: return "B" if A["ๆŠ€ใ‚ใ‚Š"] > B["ๆŠ€ใ‚ใ‚Š"]: return "A" if A["ๆŠ€ใ‚ใ‚Š"] < B["ๆŠ€ใ‚ใ‚Š"]: return "B" # 3. ๆŒ‡ๅฐŽใซใ‚ˆใ‚‹ๆ•—ๅŒ—๏ผˆๆŒ‡ๅฐŽ3ใคใงๆ•—ๅŒ—๏ผ‰ if A["ๆŒ‡ๅฐŽ"] >= 3 and B["ๆŒ‡ๅฐŽ"] < 3: return "B" if B["ๆŒ‡ๅฐŽ"] >= 3 and A["ๆŒ‡ๅฐŽ"] < 3: return "A" # 4. ๅผ•ใๅˆ†ใ‘๏ผˆๅปถ้•ท๏ผ‰ return "ๅปถ้•ท"
def check(candidate): # ไธ€ๆœฌๅ‹ใกใฎไพ‹ assert candidate({"ไธ€ๆœฌ": 1, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 0}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 0}) == "A" assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 0}, {"ไธ€ๆœฌ": 1, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 0}) == "B" # ๆŠ€ใ‚ใ‚Šใฎๅˆคๅฎš assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 2, "ๆŒ‡ๅฐŽ": 1}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 0}) == "A" assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 0}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 2, "ๆŒ‡ๅฐŽ": 0}) == "B" # ๆŒ‡ๅฐŽใซใ‚ˆใ‚‹ๅ‹ๆ•— assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 2}) == "B" assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 2}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}) == "A" # ๅผ•ใๅˆ†ใ‘๏ผˆๅปถ้•ท๏ผ‰ assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 0, "ๆŒ‡ๅฐŽ": 3}) == "ๅปถ้•ท" assert candidate({"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 1}, {"ไธ€ๆœฌ": 0, "ๆŠ€ใ‚ใ‚Š": 1, "ๆŒ‡ๅฐŽ": 1}) == "ๅปถ้•ท"
judo_match_winner
en/20
def compare_to_tokyo_tower(height: int) -> str: """ Compare the height of Tokyo Tower (333m) and the input height, Determine if they are higher, lower, or the same height. argument: height (int): Height to compare (unit: meters) Return: str: Is the input height "้ซ˜ใ„", "ไฝŽใ„", or "ๅŒใ˜" Usage example: >>> compare_to_tokyo_tower(400) '้ซ˜ใ„' >>> compare_to_tokyo_tower(333) 'ๅŒใ˜' >>> compare_to_tokyo_tower(100) 'ไฝŽใ„' """
TOKYO_TOWER_HEIGHT = 333 # ๆฑไบฌใ‚ฟใƒฏใƒผใฎ้ซ˜ใ•๏ผˆๅ˜ไฝ: ใƒกใƒผใƒˆใƒซ๏ผ‰ if height > TOKYO_TOWER_HEIGHT: return "้ซ˜ใ„" elif height < TOKYO_TOWER_HEIGHT: return "ไฝŽใ„" else: return "ๅŒใ˜"
def check(candidate): assert candidate(400) == "้ซ˜ใ„" assert candidate(333) == "ๅŒใ˜" assert candidate(100) == "ไฝŽใ„" assert candidate(500) == "้ซ˜ใ„" assert candidate(0) == "ไฝŽใ„"
compare_to_tokyo_tower
en/21
def is_valid_mynumber_format(mynumber: str) -> bool: """ Determine whether the My Number format is correct. My Number is a 12-digit number that is unique to each person. argument: mynumber (str): My number (string format) Return value: bool: True if the format is correct, False otherwise example: >>> is_valid_mynumber_format("123456789012") True >>> is_valid_mynumber_format("12345678ABCD") False >>> is_valid_mynumber_format("12345678901") False """
return mynumber.isdigit() and len(mynumber) == 12
def check(candidate): assert candidate("123456789012") == True assert candidate("135790246810") == True assert candidate("12345678901") == False assert candidate("1234567890123") == False assert candidate("ABCDEFGGIJKL") == False
is_valid_mynumber_format
en/22
def can_vote(birthday: str, today: str) -> bool: """ A program to determine voting age (18 years or older). argument: birthday (str): Date of birth ("YYYYๅนดMMๆœˆDDๆ—ฅ"). today (str): Current date ("YYYYๅนดMMๆœˆDDๆ—ฅ"). Return value: bool: True if you have the right to vote, False otherwise. Execution example: >>> can_vote("2000ๅนด01ๆœˆ01ๆ—ฅ", "2008ๅนด01ๆœˆ01ๆ—ฅ") False >>> can_vote("2000ๅนด01ๆœˆ01ๆ—ฅ", "2020ๅนด01ๆœˆ01ๆ—ฅ") True """
# ็”Ÿๅนดๆœˆๆ—ฅใจ็พๅœจใฎๆ—ฅไป˜ใ‚’ๅˆ†ๅ‰ฒใ—ใ€ๆ•ดๆ•ฐใซๅค‰ๆ› birth_year, birth_month, birth_day = map(int, birthday.replace("ๅนด", "-").replace("ๆœˆ", "-").replace("ๆ—ฅ", "").split("-")) today_year, today_month, today_day = map(int, today.replace("ๅนด", "-").replace("ๆœˆ", "-").replace("ๆ—ฅ", "").split("-")) # ๅนด้ฝขใ‚’่จˆ็ฎ— age = today_year - birth_year if (today_month, today_day) < (birth_month, birth_day): age -= 1 # ่ช•็”Ÿๆ—ฅใŒๆฅใฆใ„ใชใ„ๅ ดๅˆใฏๅนด้ฝขใ‚’1ๅผ•ใ # 18ๆญณไปฅไธŠใ‹ใฉใ†ใ‹ใ‚’ๅˆคๅฎš return age >= 18
def check(candidate): assert candidate("2000ๅนด01ๆœˆ01ๆ—ฅ", "2008ๅนด01ๆœˆ01ๆ—ฅ") == False assert candidate("2000ๅนด01ๆœˆ01ๆ—ฅ", "2020ๅนด01ๆœˆ01ๆ—ฅ") == True assert candidate("2002ๅนด12ๆœˆ31ๆ—ฅ", "2021ๅนด12ๆœˆ31ๆ—ฅ") == True assert candidate("2005ๅนด07ๆœˆ01ๆ—ฅ", "2023ๅนด06ๆœˆ30ๆ—ฅ") == False assert candidate("2005ๅนด07ๆœˆ01ๆ—ฅ", "2023ๅนด07ๆœˆ01ๆ—ฅ") == True
can_vote
en/23
def get_rokuyou(days: int) -> str: """ Assuming that today's Rokuyo is "ๅ…ˆๅ‹", returns the Rokuyo from the specified number of days later. argument: days (int): Number of days since today Return value: str: Rokuyo (any of "ๅ…ˆๅ‹", "ๅ‹ๅผ•", "ๅ…ˆ่ฒ ", "ไปๆป…", "ๅคงๅฎ‰", "่ตคๅฃ") """
rokuyou_names = ["ๅ…ˆๅ‹", "ๅ‹ๅผ•", "ๅ…ˆ่ฒ ", "ไปๆป…", "ๅคงๅฎ‰", "่ตคๅฃ"] index = days % 6 return rokuyou_names[index]
def check(candidate): assert candidate(0) == "ๅ…ˆๅ‹" assert candidate(1) == "ๅ‹ๅผ•" assert candidate(2) == "ๅ…ˆ่ฒ " assert candidate(3) == "ไปๆป…" assert candidate(4) == "ๅคงๅฎ‰" assert candidate(5) == "่ตคๅฃ" assert candidate(6) == "ๅ…ˆๅ‹" assert candidate(7) == "ๅ‹ๅผ•" assert candidate(30) == "ๅ…ˆๅ‹" assert candidate(365) == "่ตคๅฃ"
get_rokuyou
en/24
import re def normalize_postal_code(postal_code: str) -> str: """ A function that unifies the notation of postal codes. ใƒปDelete extra white space ใƒปConvert full-width numbers and full-width symbols (such as "-") to half-width - Place the hyphen in the postal code in the correct position (e.g. '1234567' โ†’ '123-4567') argument: postal_code (str): Postal code string Return value: str: Normalized postal code example: >>> normalize_postal_code("ใ€’1234567") '123-4567' >>> normalize_postal_code("1234567") '123-4567' """
postal_code = re.sub(r'\s+|ใ€’', '', postal_code) full_width_to_half_width = str.maketrans( '๏ผ๏ผ‘๏ผ’๏ผ“๏ผ”๏ผ•๏ผ–๏ผ—๏ผ˜๏ผ™๏ผ', '0123456789-' ) postal_code = postal_code.translate(full_width_to_half_width) postal_code = re.sub(r'(\d{3})(\d{4})', r'\1-\2', postal_code) return postal_code
def check(candidate): assert candidate("๏ผ‘๏ผ’๏ผ“-๏ผ”๏ผ•๏ผ–๏ผ—") == '123-4567' assert candidate("1234567") == '123-4567' assert candidate(" 123 4567 ") == '123-4567' assert candidate("ใ€’๏ผ‘๏ผ’๏ผ“๏ผ”๏ผ•๏ผ–๏ผ—") == '123-4567' assert candidate("๏ผ‘๏ผ’๏ผ“ใ€€๏ผ”๏ผ•๏ผ–๏ผ—") == '123-4567' assert candidate("123-4567") == '123-4567' assert candidate("๏ผ‘๏ผ’๏ผ“๏ผ๏ผ”๏ผ•๏ผ–๏ผ—") == '123-4567'
normalize_postal_code
en/25
def identify_nanakusa(name: str) -> bool: """ Returns True if the given name `name` applies to the seven spring herbs, otherwise returns False. The seven herbs of spring are "ใ›ใ‚Š", "ใชใšใช", "ใ”ใŽใ‚‡ใ†", "ใฏใ“ในใ‚‰", "ใปใจใ‘ใฎใ–", "ใ™ใšใช" or "ใ™ใšใ—ใ‚". argument: - name (str): Hiragana name Return value: - bool: True/False Example: >>> identify_nanakusa("ใ›ใ‚Š") True >>> identify_nanakusa("ใชใšใช") True >>> identify_nanakusa("ใ•ใใ‚‰") False >>> identify_nanakusa("ใใ") False """
# ๆ˜ฅใฎไธƒ่‰ใฎใƒชใ‚นใƒˆ nanakusa = {"ใ›ใ‚Š", "ใชใšใช", "ใ”ใŽใ‚‡ใ†", "ใฏใ“ในใ‚‰", "ใปใจใ‘ใฎใ–", "ใ™ใšใช", "ใ™ใšใ—ใ‚"} # ๅๅ‰ใŒไธƒ่‰ใซๅซใพใ‚Œใ‚‹ใ‹ใฉใ†ใ‹ใ‚’ๅˆคๅฎš return name in nanakusa
def check(candidate): assert candidate("ใ›ใ‚Š") == True assert candidate("ใชใšใช") == True assert candidate("ใ”ใŽใ‚‡ใ†") == True assert candidate("ใฏใ“ในใ‚‰") == True assert candidate("ใปใจใ‘ใฎใ–") == True assert candidate("ใ™ใšใช") == True assert candidate("ใ™ใšใ—ใ‚") == True assert candidate("ใ•ใใ‚‰") == False assert candidate("ใใ") == False assert candidate("ใŸใ‚“ใฝใฝ") == False assert candidate("ใปใ†ใ‚Œใ‚“ใใ†") == False
identify_nanakusa
en/26
import math def calculate_fan(radius: int, angle: int, threshold: float) -> bool: """ If the area of โ€‹โ€‹the fan is greater than or equal to `threshold`, it is determined that the pattern looks beautiful. Calculates the area of โ€‹โ€‹the fan and returns True if it looks good, False if it doesn't. The area of โ€‹โ€‹the fan is calculated using the following formula: Area = 0.5 * radius^2 * (radian value of angle) argument: radius (int): Radius of the fan (unit: cm, positive integer). angle (int): The angle of the fan (unit: degrees, 0-360). threshold (float): The area threshold (unit: square cm) for the pattern to look good. Return value: bool: True if the area is greater than or equal to the threshold, otherwise False. example: >>> calculate_fan(10, 180, 100) True >>> calculate_fan(10, 90, 100) False """
# ่ง’ๅบฆใ‚’ใƒฉใ‚ธใ‚ขใƒณใซๅค‰ๆ› angle_rad = math.radians(angle) # ๆ‰‡ๅญใฎ้ข็ฉใ‚’่จˆ็ฎ— area = 0.5 * (radius ** 2) * angle_rad # ้ข็ฉใŒ้–พๅ€คไปฅไธŠใ‹ๅˆคๅฎš return area >= threshold
def check(candidate): assert candidate(10, 180, 100) == True assert candidate(10, 90, 100) == False assert candidate(15, 120, 150) == True assert candidate(5, 360, 150) == False assert candidate(20, 360, 500) == True assert candidate(1, 1, 0.01) == False
calculate_fan
en/27
def calculate_mission_success(skill: int, difficulty: int) -> int: """ Calculate the ninja's mission success rate. The mission success rate can be calculated from the difference between the ninja's technical ability and the difficulty of the mission. argument: skill (int): Ninja's technical ability (1-100) difficulty (int): Difficulty of the mission (1-100) Return value: int: Mission success rate (0-100) """
return max(0, skill - difficulty)
def check(candidate): assert candidate(80, 50) == 30 assert candidate(40, 60) == 0 assert candidate(100, 100) == 0 assert candidate(70, 50) == 20 assert candidate(50, 50) == 0 assert candidate(90, 30) == 60 assert candidate(30, 70) == 0 assert candidate(1, 100) == 0 assert candidate(100, 1) == 99
calculate_mission_success
en/28
def weight_needed_for_sumo(height: int, current_weight: int) -> tuple: """ Calculate the amount of weight gain needed to reach the average BMI of a sumo wrestler from your height and current weight. If the sumo wrestler's average BMI is 33, returns the target weight and required weight gain. argument: height (int): Height (cm) current_weight (int): Current weight (kg) Return value: tuple: target weight and required weight gain (both integers) example: >>> weight_needed_for_sumo(180, 100) (106, 6) >>> weight_needed_for_sumo(175, 80) (101, 21) """
target_bmi = 33 height_m = height / 100 target_weight = target_bmi * (height_m ** 2) weight_increase = target_weight - current_weight target_weight = int(round(target_weight)) weight_increase = int(round(weight_increase)) return (target_weight, weight_increase)
def check(candidate): assert candidate(180, 100) == (107, 7) assert candidate(175, 80) == (101, 21) assert candidate(160, 60) == (84, 24) assert candidate(200, 120) == (132, 12) assert candidate(165, 75) == (90, 15) assert candidate(150, 50) == (74, 24) assert candidate(190, 90) == (119, 29) assert candidate(185, 85) == (113, 28) assert candidate(155, 65) == (79, 14) assert candidate(178, 70) == (105, 35)
weight_needed_for_sumo
en/29
def month_to_emoji(month: int) -> str: """ A function that accepts the month and returns the corresponding emoji. """ number_to_emoji = { 1: '๐ŸŽ', 2: '๐Ÿ‘น', 3: '๐ŸŽŽ', 4: '๐ŸŒธ', 5: '๐ŸŽ', 6: 'โ˜”', 7: '๐ŸŽ‹', 8: '๐Ÿ‰', 9: '๐ŸŽ‘', 10: '๐Ÿƒ', 11: '๐Ÿ', 12: '๐ŸŽ„' } emoji = number_to_emoji.get(month, '') return emoji def create_monthly_message(month: int) -> str: """ A function that accepts the month and creates a corresponding message. month_to_emoji gets the emoji for the month and returns it on both sides of the message. >>> create_monthly_message(1) '๐ŸŽไปŠๆœˆใฏ1ๆœˆใงใ™๐ŸŽ' >>> create_monthly_message(12) '๐ŸŽ„ไปŠๆœˆใฏ12ๆœˆใงใ™๐ŸŽ„' """
emoji = month_to_emoji(month) return f'{emoji}ไปŠๆœˆใฏ{month}ๆœˆใงใ™{emoji}'
def check(candidate): assert candidate(1) == '๐ŸŽไปŠๆœˆใฏ1ๆœˆใงใ™๐ŸŽ' assert candidate(2) == '๐Ÿ‘นไปŠๆœˆใฏ2ๆœˆใงใ™๐Ÿ‘น' assert candidate(3) == '๐ŸŽŽไปŠๆœˆใฏ3ๆœˆใงใ™๐ŸŽŽ' assert candidate(4) == '๐ŸŒธไปŠๆœˆใฏ4ๆœˆใงใ™๐ŸŒธ' assert candidate(5) == '๐ŸŽไปŠๆœˆใฏ5ๆœˆใงใ™๐ŸŽ' assert candidate(6) == 'โ˜”ไปŠๆœˆใฏ6ๆœˆใงใ™โ˜”' assert candidate(7) == '๐ŸŽ‹ไปŠๆœˆใฏ7ๆœˆใงใ™๐ŸŽ‹' assert candidate(8) == '๐Ÿ‰ไปŠๆœˆใฏ8ๆœˆใงใ™๐Ÿ‰' assert candidate(9) == '๐ŸŽ‘ไปŠๆœˆใฏ9ๆœˆใงใ™๐ŸŽ‘' assert candidate(10) == '๐ŸƒไปŠๆœˆใฏ10ๆœˆใงใ™๐Ÿƒ' assert candidate(11) == '๐ŸไปŠๆœˆใฏ11ๆœˆใงใ™๐Ÿ' assert candidate(12) == '๐ŸŽ„ไปŠๆœˆใฏ12ๆœˆใงใ™๐ŸŽ„'
create_monthly_message
en/30
def calculate_postcard_fee(fee: int, x: int) -> int: """ This is a function that calculates the price of postcards. argument: fee (int): Fee for one postcard (yen) x (int): Number of postcards Return value: int: Total postcard fee (yen) example: >>> calculate_postcard_fee(63, 1) 63 >>> calculate_postcard_fee(63, 5) 315 """
return fee * x
def check(candidate): assert candidate(63, 1) == 63 assert candidate(63, 5) == 315 assert candidate(63, 10) == 630 assert candidate(70, 10) == 700 assert candidate(84, 2) == 168 assert candidate(84, 3) == 252
calculate_postcard_fee
en/31
from typing import List def sort_koinobori(sizes: List[int]) -> List[int]: """ Sort the carp streamer size list from largest to largest. - sizes (List[int]): List of sizes (cm) of each carp streamer. - Returns: A list of carp streamers sorted by size. example: >>> sort_koinobori([30, 50, 70, 20]) [70, 50, 30, 20] >>> sort_koinobori([100, 200, 150]) [200, 150, 100] """
return sorted(sizes, reverse=True)
def check(candidate): assert candidate([30, 50, 70, 20]) == [70, 50, 30, 20] assert candidate([100, 200, 150]) == [200, 150, 100] assert candidate([10, 10, 10]) == [10, 10, 10] assert candidate([5, 3, 8, 1]) == [8, 5, 3, 1] assert candidate([500, 100, 300, 200]) == [500, 300, 200, 100] assert candidate([1]) == [1] assert candidate([999, 1000, 888, 1000]) == [1000, 1000, 999, 888]
sort_koinobori
en/32
from typing import List def determine_winner(red_scores: List[int], white_scores: List[int]) -> str: """ The winner of the ็ด…็™ฝๆญŒๅˆๆˆฆ will be determined. Each group is given a score, and the team with the highest total score is the winning team. Returns either "็ด…็ต„", "็™ฝ็ต„", or "ๅผ•ใๅˆ†ใ‘". Example: >>> determine_winner([10, 20, 30], [15, 25, 20]) 'ๅผ•ใๅˆ†ใ‘' >>> determine_winner([50, 40, 60], [30, 20, 10]) '็ด…็ต„' >>> determine_winner([10, 20, 30], [40, 50, 60]) '็™ฝ็ต„' """
red_total = sum(red_scores) white_total = sum(white_scores) if red_total > white_total: return "็ด…็ต„" elif white_total > red_total: return "็™ฝ็ต„" else: return "ๅผ•ใๅˆ†ใ‘"
def check(candidate): assert candidate([10, 20, 30], [15, 25, 20]) == 'ๅผ•ใๅˆ†ใ‘' assert candidate([50, 40, 60], [30, 20, 10]) == '็ด…็ต„' assert candidate([10, 20, 30], [40, 50, 60]) == '็™ฝ็ต„' assert candidate([100, 200, 300], [100, 150, 200]) == '็ด…็ต„' assert candidate([0, 0, 0], [0, 0, 0]) == 'ๅผ•ใๅˆ†ใ‘' assert candidate([999], [1000]) == '็™ฝ็ต„'
determine_winner
en/33
from typing import List def calculate_yamanote_distance(start: str, end: str, stations: List[str]) -> int: """ Given a list of stations on the Yamanote Line, a departure station, and an arrival station, calculate the number of stations from the departure station to the arrival station. Since the Yamanote Line is a circular line, we consider two routes, one clockwise and one counterclockwise, and return the one with fewer stations. - start (str): Name of departure station - end (str): name of arrival station - stations (List[str]): List of station names on the Yamanote Line (in order along the loop line) - Return value: Shortest number of stations """
start_index = stations.index(start) end_index = stations.index(end) clockwise_distance = (end_index - start_index) % len(stations) counterclockwise_distance = (start_index - end_index) % len(stations) return min(clockwise_distance, counterclockwise_distance)
def check(candidate): stations = ["ๆฑไบฌ", "ๆœ‰ๆฅฝ็”บ", "ๆ–ฐๆฉ‹", "ๆตœๆพ็”บ", "็”ฐ็”บ", "ๅ“ๅท", "ๅคงๅดŽ", "ไบ”ๅ็”ฐ", "็›ฎ้ป’", "ๆตๆฏ”ๅฏฟ", "ๆธ‹่ฐท", "ๅŽŸๅฎฟ", "ไปฃใ€…ๆœจ", "ๆ–ฐๅฎฟ", "ๆ–ฐๅคงไน…ไฟ", "้ซ˜็”ฐ้ฆฌๅ ด", "็›ฎ็™ฝ", "ๆฑ ่ข‹", "ๅคงๅกš", "ๅทฃ้ดจ", "้ง’่พผ", "็”ฐ็ซฏ", "่ฅฟๆ—ฅๆšฎ้‡Œ", "ๆ—ฅๆšฎ้‡Œ", "้ถฏ่ฐท", "ไธŠ้‡Ž", "ๅพกๅพ’็”บ", "็ง‹่‘‰ๅŽŸ", "็ฅž็”ฐ"] assert candidate("ๆฑไบฌ", "ๅ“ๅท", stations) == 5 assert candidate("ๆฑไบฌ", "ๆธ‹่ฐท", stations) == 10 assert candidate("ๆธ‹่ฐท", "ๆฑไบฌ", stations) == 10 assert candidate("ๆตๆฏ”ๅฏฟ", "็›ฎ้ป’", stations) == 1 assert candidate("ๅคงๅกš", "ไธŠ้‡Ž", stations) == 7 assert candidate("็ง‹่‘‰ๅŽŸ", "ๆฑไบฌ", stations) == 2
calculate_yamanote_distance
en/34
def daruma_block(blocks: list, count: int) -> list: """ Daruma blocks are arranged in the order of blocks. Drops the bottom block count times and returns the list of currently remaining Daruma blocks. argument: blocks (list): list of Daruma blocks count (int): Number of drops Return value: list: Daruma's block list after dropping it Example: >>> daruma_block(['่ตค', '้’', '็ท‘', '้ป„'], 2) ['่ตค', '้’'] >>> daruma_block(['่ตค', '้’'], 1) ['่ตค'] """
return blocks[:-count] if count < len(blocks) else []
def check(candidate): assert candidate(['่ตค', '้’', '็ท‘', '้ป„'], 1) == ['่ตค', '้’', '็ท‘'] assert candidate(['่ตค', '้’', '็ท‘', '้ป„'], 2) == ['่ตค', '้’'] assert candidate(['่ตค', '้’', '็ท‘', '้ป„'], 3) == ['่ตค'] assert candidate(['่ตค', '้’', '็ท‘', '้ป„'], 4) == [] assert candidate(['่ตค', '้’'], 1) == ['่ตค']
daruma_block
en/35
def ryugu_time_passed(days: int) -> int: """ Returns the number of days elapsed on earth based on the number of days spent in Ryugu Castle. If you spend one day in Ryugu Castle, 365 days have passed on earth. argument: days (int): Number of days spent in Ryugujo Return value: int: Number of days on earth Usage example: >>> ryugu_time_passed(1) 365 >>> ryugu_time_passed(10) 3650 """
return int(days) * 365
def check(candidate): assert candidate(1) == 365 assert candidate(0) == 0 assert candidate(10) == 3650 assert candidate(100) == 36500 assert candidate(365) == 133225 assert candidate(2) == 730 assert candidate(50) == 18250 assert candidate(123) == 44895
ryugu_time_passed
en/36
def check_kendo_gear(gear: list) -> str: """ A function that determines whether all Kendo armor is available. argument: gear (list): List of equipped armor Return value: str: 'ๆบ–ๅ‚™ๅฎŒไบ†' or 'ๆบ–ๅ‚™ไธ่ถณ' Usage example: >>> check_kendo_gear(['้ข', 'ๅฐๆ‰‹', '่ƒด', 'ๅž‚']) 'ๆบ–ๅ‚™ๅฎŒไบ†' >>> check_kendo_gear(['้ข', 'ๅฐๆ‰‹', 'ๅž‚']) 'ๆบ–ๅ‚™ไธ่ถณ' """
required_gear = {'้ข', 'ๅฐๆ‰‹', '่ƒด', 'ๅž‚'} if required_gear.issubset(set(gear)): return 'ๆบ–ๅ‚™ๅฎŒไบ†' else: return 'ๆบ–ๅ‚™ไธ่ถณ'
def check(candidate): assert candidate(['้ข', 'ๅฐๆ‰‹', '่ƒด', 'ๅž‚']) == 'ๆบ–ๅ‚™ๅฎŒไบ†' assert candidate(['้ข', 'ๅฐๆ‰‹', 'ๅž‚']) == 'ๆบ–ๅ‚™ไธ่ถณ' assert candidate(['้ข', 'ๅฐๆ‰‹']) == 'ๆบ–ๅ‚™ไธ่ถณ' assert candidate(['้ข', '้ข', '้ข', '้ข']) == 'ๆบ–ๅ‚™ไธ่ถณ' assert candidate(['้ข', 'ๅฐๆ‰‹', '่ƒด']) == 'ๆบ–ๅ‚™ไธ่ถณ' assert candidate([]) == 'ๆบ–ๅ‚™ไธ่ถณ' assert candidate(['ๅฐๆ‰‹', '่ƒด', 'ๅž‚', '้ข']) == 'ๆบ–ๅ‚™ๅฎŒไบ†' assert candidate(['้ข', 'ๅฐๆ‰‹', '่ƒด', 'ๅž‚', 'ใ‚ตใƒใƒผใ‚ฟใƒผ']) == 'ๆบ–ๅ‚™ๅฎŒไบ†' assert candidate(['้ข', 'ๅž‚', 'ๅฐๆ‰‹', '่ƒด', '่ถณ่ข‹']) == 'ๆบ–ๅ‚™ๅฎŒไบ†'
check_kendo_gear
en/37
def get_ehou_direction(year: int) -> str: """ A function that receives the year in the Western calendar and returns the lucky direction (ๆฑๅŒ—ๆฑ, ๅ—ๅ—ๆฑ, ่ฅฟๅ—่ฅฟ, or ๅŒ—ๅŒ—่ฅฟ) of that year. argument: year (int): year of the Western calendar Return value: str: Direction of lucky direction for the year Usage example: >>> get_ehou_direction(2024) 'ๆฑๅŒ—ๆฑ' >>> get_ehou_direction(2025) 'ๅŒ—ๅŒ—่ฅฟ' >>> get_ehou_direction(2026) '่ฅฟๅ—่ฅฟ' >>> get_ehou_direction(2027) 'ๅ—ๅ—ๆฑ' """
directions = ['ๆฑๅŒ—ๆฑ', 'ๅŒ—ๅŒ—่ฅฟ', '่ฅฟๅ—่ฅฟ', 'ๅ—ๅ—ๆฑ'] return directions[year % 4]
def check(candidate): assert candidate(2020) == 'ๆฑๅŒ—ๆฑ' assert candidate(2021) == 'ๅŒ—ๅŒ—่ฅฟ' assert candidate(2022) == '่ฅฟๅ—่ฅฟ' assert candidate(2023) == 'ๅ—ๅ—ๆฑ' assert candidate(2024) == 'ๆฑๅŒ—ๆฑ' assert candidate(2025) == 'ๅŒ—ๅŒ—่ฅฟ' assert candidate(2026) == '่ฅฟๅ—่ฅฟ' assert candidate(2027) == 'ๅ—ๅ—ๆฑ' assert candidate(2028) == 'ๆฑๅŒ—ๆฑ'
get_ehou_direction
en/38
from collections import Counter def rank_sushi_ingredients(orders: list) -> list: """ A function that returns popular sushi items from a sushi order list in order of ranking. argument: orders (list): List of ordered sushi items Return value: list: List of sushi toppings arranged in order of popularity Usage example: >>> rank_sushi_ingredients(["ใพใใ‚", "ใ‚ตใƒผใƒขใƒณ", "ใพใใ‚", "ใ„ใใ‚‰", "ใ‚ตใƒผใƒขใƒณ", "ใพใใ‚"]) ['ใพใใ‚', 'ใ‚ตใƒผใƒขใƒณ', 'ใ„ใใ‚‰'] >>> rank_sushi_ingredients(["ใˆใณ", "ใˆใณ", "ใŸใพใ”", "ใ„ใ‹", "ใ„ใ‹", "ใ„ใ‹"]) ['ใ„ใ‹', 'ใˆใณ', 'ใŸใพใ”'] >>> rank_sushi_ingredients(["ใพใใ‚", "ใพใใ‚", "ใพใใ‚"]) ['ใพใใ‚'] """
count = Counter(orders) sorted_items = sorted(count.items(), key=lambda x: (-x[1], x[0])) return [item[0] for item in sorted_items]
def check(candidate): # ๅŸบๆœฌ็š„ใชใƒ†ใ‚นใƒˆใ‚ฑใƒผใ‚น assert candidate(["ใพใใ‚", "ใ‚ตใƒผใƒขใƒณ", "ใพใใ‚", "ใ„ใใ‚‰", "ใ‚ตใƒผใƒขใƒณ", "ใพใใ‚"]) == ['ใพใใ‚', 'ใ‚ตใƒผใƒขใƒณ', 'ใ„ใใ‚‰'] assert candidate(["ใˆใณ", "ใˆใณ", "ใŸใพใ”", "ใ„ใ‹", "ใ„ใ‹", "ใ„ใ‹"]) == ['ใ„ใ‹', 'ใˆใณ', 'ใŸใพใ”'] assert candidate(["ใพใใ‚", "ใพใใ‚", "ใพใใ‚"]) == ['ใพใใ‚'] assert candidate(["ใ†ใซ", "ใ„ใใ‚‰", "ใ„ใใ‚‰", "ใŸใ“", "ใŸใ“", "ใŸใ“", "ใ‚ตใƒผใƒขใƒณ", "ใ‚ตใƒผใƒขใƒณ", "ใ‚ตใƒผใƒขใƒณ"]) == ['ใŸใ“', 'ใ‚ตใƒผใƒขใƒณ', 'ใ„ใใ‚‰', 'ใ†ใซ'] # ๅขƒ็•Œๅ€คใƒ†ใ‚นใƒˆ assert candidate([]) == [] assert candidate(["ใพใใ‚"]) == ["ใพใใ‚"] assert candidate(["ใพใใ‚", "ใพใใ‚", "ใพใใ‚", "ใพใใ‚", "ใพใใ‚"]) == ["ใพใใ‚"]
rank_sushi_ingredients
en/39
def calculate_remaining_bill(total_bill: int, boss_bills: list, other_members_count: int) -> int: """ A function that distributes the amount of your bill. argument: total_bill (int): Total amount boss_bills (list): List of amounts paid by the boss other_members_count (int): Number of people other than the boss Return value: int: amount paid by each member Usage example: >>> calculate_remaining_bill(10000, [3000, 2000], 3) 1666 >>> calculate_remaining_bill(15000, [5000], 4) 2500 >>> calculate_remaining_bill(20000, [8000, 8000], 1) 4000 """
total_boss_payment = sum(boss_bills) remaining_amount = total_bill - total_boss_payment if remaining_amount <= 0: return 0 remaining_per_member = remaining_amount // other_members_count return remaining_per_member
def check(candidate): assert candidate(10000, [3000, 2000], 3) == 1666 assert candidate(15000, [5000], 4) == 2500 assert candidate(20000, [8000, 8000], 1) == 4000 assert candidate(10000, [10000], 3) == 0 assert candidate(10000, [11000], 3) == 0 assert candidate(1000000, [400000, 300000], 10) == 30000 assert candidate(1000000, [999999], 1) == 1
calculate_remaining_bill
en/40
def recommend_least_crowded_train(train_crowdings: dict) -> str: """ A function that recommends the least crowded train based on the congestion level of each train. argument: train_crowdings (dict): Dictionary of {train name: crowding rate (0-100%)} Return value: str: name of the least crowded train Usage example: >>> recommend_least_crowded_train({"A train": 80, "B train": 60, "C train": 90}) 'B train' >>> recommend_least_crowded_train({"Yamanote Line": 95, "Keihin Tohoku Line": 85, "Chuo Line": 99}) 'Keihin Tohoku Line' """
return min(train_crowdings, key=lambda train: train_crowdings[train])
def check(candidate): assert candidate({"Aๅˆ—่ปŠ": 80, "Bๅˆ—่ปŠ": 60, "Cๅˆ—่ปŠ": 90}) == 'Bๅˆ—่ปŠ' assert candidate({"ๅฑฑๆ‰‹็ทš": 95, "ไบฌๆตœๆฑๅŒ—็ทš": 85, "ไธญๅคฎ็ทš": 99}) == 'ไบฌๆตœๆฑๅŒ—็ทš' assert candidate({"Aๅˆ—่ปŠ": 50, "Bๅˆ—่ปŠ": 50, "Cๅˆ—่ปŠ": 50}) == 'Aๅˆ—่ปŠ' assert candidate({"ๅˆ—่ปŠ1": 0, "ๅˆ—่ปŠ2": 100}) == 'ๅˆ—่ปŠ1' assert candidate({"ๅˆ—่ปŠ1": 0}) == 'ๅˆ—่ปŠ1' assert candidate({"ๆ–ฐๅนน็ทš": 10, "็‰นๆ€ฅ": 20, "ๅฟซ้€Ÿ": 15}) == 'ๆ–ฐๅนน็ทš' assert candidate({"ๅคœ่กŒๅˆ—่ปŠ": 100, "้€šๅ‹คๅฟซ้€Ÿ": 99, "ๆ™ฎ้€šๅˆ—่ปŠ": 98}) == 'ๆ™ฎ้€šๅˆ—่ปŠ' assert candidate({"A": 100, "B": 100, "C": 100}) == 'A' assert candidate({"ๆ€ฅ่กŒ": 70, "ๆ™ฎ้€š": 40, "็‰นๆ€ฅ": 90}) == 'ๆ™ฎ้€š'
recommend_least_crowded_train
en/41
def get_izumo_traditional_month_name(n: int) -> str: """ Returns the traditional month name of the Izumo region that corresponds to the current month. In the Izumo region, October is called "็ฅžๆœ‰ๆœˆ". argument: n (int): current month (1-12) Return value: str: Ancient month name in Izumo region example: >>> get_izumo_traditional_month_name(1) '็ฆๆœˆ' >>> get_izumo_traditional_month_name(6) 'ๆฐด็„กๆœˆ' >>> get_izumo_traditional_month_name(10) '็ฅžๆœ‰ๆœˆ' """
month_names = [ "็ฆๆœˆ", "ๅฆ‚ๆœˆ", "ๅผฅ็”Ÿ", "ๅฏๆœˆ", "็šๆœˆ", "ๆฐด็„กๆœˆ", "ๆ–‡ๆœˆ", "่‘‰ๆœˆ", "้•ทๆœˆ", "็ฅžๆœ‰ๆœˆ", "้œœๆœˆ", "ๅธซ่ตฐ" ] return month_names[n - 1]
def check(candidate): assert candidate(1) == "็ฆๆœˆ" assert candidate(2) == "ๅฆ‚ๆœˆ" assert candidate(3) == "ๅผฅ็”Ÿ" assert candidate(4) == "ๅฏๆœˆ" assert candidate(5) == "็šๆœˆ" assert candidate(6) == "ๆฐด็„กๆœˆ" assert candidate(7) == "ๆ–‡ๆœˆ" assert candidate(8) == "่‘‰ๆœˆ" assert candidate(9) == "้•ทๆœˆ" assert candidate(10) == "็ฅžๆœ‰ๆœˆ" assert candidate(11) == "้œœๆœˆ" assert candidate(10) == "็ฅžๆœ‰ๆœˆ" assert candidate(12) == "ๅธซ่ตฐ"
get_izumo_traditional_month_name
en/42
def append_administrative_unit(prefecture: str) -> str: """ Returns the given prefecture name with the correct administrative unit ("้ƒฝ", "้“", "ๅบœ", "็œŒ"). argument: prefecture (str): prefecture name without administrative unit Return value: str: Prefecture name with administrative unit example: >>> append_administrative_unit("ๆฑไบฌ") 'ๆฑไบฌ้ƒฝ' >>> append_administrative_unit("ๅŒ—ๆตท้“") 'ๅŒ—ๆตท้“' >>> append_administrative_unit("ไบฌ้ƒฝ") 'ไบฌ้ƒฝๅบœ' >>> append_administrative_unit("ๆ„›็Ÿฅ") 'ๆ„›็Ÿฅ็œŒ' """
prefectures_with_special_units = { "ๆฑไบฌ": "ๆฑไบฌ้ƒฝ", "ๅคง้˜ช": "ๅคง้˜ชๅบœ", "ไบฌ้ƒฝ": "ไบฌ้ƒฝๅบœ", "ๅŒ—ๆตท้“": "ๅŒ—ๆตท้“" } if prefecture in prefectures_with_special_units: return prefectures_with_special_units[prefecture] else: return prefecture + "็œŒ"
def check(candidate): assert candidate("ๆฑไบฌ") == "ๆฑไบฌ้ƒฝ" assert candidate("ๅŒ—ๆตท้“") == "ๅŒ—ๆตท้“" assert candidate("ๅคง้˜ช") == "ๅคง้˜ชๅบœ" assert candidate("ไบฌ้ƒฝ") == "ไบฌ้ƒฝๅบœ" assert candidate("ๅŸผ็Ž‰") == "ๅŸผ็Ž‰็œŒ" assert candidate("็ฅžๅฅˆๅท") == "็ฅžๅฅˆๅท็œŒ" assert candidate("ๆ„›็Ÿฅ") == "ๆ„›็Ÿฅ็œŒ" assert candidate("ๆ–ฐๆฝŸ") == "ๆ–ฐๆฝŸ็œŒ" assert candidate("ๅ…ตๅบซ") == "ๅ…ตๅบซ็œŒ" assert candidate("็ฆๅฒก") == "็ฆๅฒก็œŒ" assert candidate("ๆฒ–็ธ„") == "ๆฒ–็ธ„็œŒ"
append_administrative_unit
en/43
import math def days_to_complete(m: int, n: int) -> int: """ Calculate how many days it will take Takashi and Kiyoshi to finish their work together. Round the result up to the nearest integer. argument: m (int): How many days would it take for Takashi to do it alone? n (int): How many days would it take if Kiyoshi did it alone? Return value: int: Number of days it takes for two people to finish the job (rounded up to the nearest integer) Usage example: >>> days_to_complete(6, 3) 2 >>> days_to_complete(5, 5) 3 >>> days_to_complete(7, 4) 3 """
combined_rate = 1/m + 1/n total_days = 1 / combined_rate return math.ceil(total_days)
def check(candidate): assert candidate(6, 3) == 2 assert candidate(5, 5) == 3 assert candidate(7, 4) == 3 assert candidate(10, 2) == 2 assert candidate(8, 8) == 4 assert candidate(12, 6) == 4 assert candidate(9, 3) == 3 assert candidate(15, 5) == 4
days_to_complete
en/44
import math def days_to_meet(x: int, y: int) -> int: """ There is an older brother and a younger brother who fly back and forth across the 120 ri between Edo and Kyoto. The older brother goes x miles a day, and the younger brother goes y miles a day. Now, the older brother is heading towards Kyoto and the younger brother is heading towards Edo and Kyoto respectively. We left at the same time. Calculate on what day the brothers will meet. argument: x (int): Distance traveled by my brother in a day (village) y (int): Distance traveled by the younger brother in a day (village) Return value: int: number of days the siblings meet Execution example: >>> days_to_meet(14, 11) 5 >>> days_to_meet(10, 12) 6 """
total_distance = 120 combined_speed = x + y return math.ceil(total_distance / combined_speed)
def check(candidate): assert candidate(14, 11) == 5 assert candidate(10, 12) == 6 assert candidate(20, 20) == 3 assert candidate(15, 15) == 4 assert candidate(25, 30) == 3 assert candidate(1, 1) == 60 assert candidate(10, 110) == 1
days_to_meet
en/45
def find_number_of_thieves(m: int, r: int, c: int) -> int: """ If the thief takes m pieces each, there will be r pieces left over, and if he takes m-1 pieces each, there will be c pieces left over. Calculate the number of thieves. argument: m (int): Number of silk items taken per person r (int): Remaining reciprocal c (int): missing counternumber Return value: int: number of thieves Usage example: >>> find_number_of_thieves(5, 3, 2) -5 >>> find_number_of_thieves(4, 1, 3) -4 >>> find_number_of_thieves(6, 0, 1) -1 """
n = -(r + c) return n
def check(candidate): assert candidate(5, 3, 2) == -5 assert candidate(4, 1, 3) == -4 assert candidate(6, 0, 1) == -1 assert candidate(10, 5, 7) == -12 assert candidate(3, 2, 2) == -4
find_number_of_thieves
en/46
def total_bales_of_rice(n: int) -> int: """ Rice bales are stacked sideways in a cedar shape. Find the total number of rice bales. argument: n (int): Number of rice bags in the bottom row Return value: int: How many bales are there in total? Execution example: >>> total_bales_of_rice(3) 6 >>> total_bales_of_rice(5) 15 >>> total_bales_of_rice(1) 1 """
return n * (n + 1) // 2
def check(candidate): assert candidate(3) == 6 assert candidate(5) == 15 assert candidate(1) == 1 assert candidate(10) == 55 assert candidate(0) == 0 assert candidate(20) == 210
total_bales_of_rice
en/47
def total_cries(n: int) -> int: """ If there are n crows, each crow crows n times, and they are in n pools, calculate how many crows they crow in total. argument: n (int): An integer representing the number of crows, number of uras, and number of crows per crow Return value: int: Total number of cries Execution example: >>> total_cries(1) 1 >>> total_cries(2) 8 >>> total_cries(3) 27 >>> total_cries(4) 64 """
return n ** 3
def check(candidate): assert candidate(1000) == 1000 ** 3 assert candidate(500) == 500 ** 3 assert candidate(1234) == 1234 ** 3 assert candidate(0) == 0 ** 3 assert candidate(1) == 1 ** 3 assert candidate(2500) == 2500 ** 3 assert candidate(999) == 999 ** 3
total_cries
en/48
def min_coins(x: int) -> int: """ Calculate the minimum number of coins required to pay x yen. The coins that can be used are 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen. argument: x (int): amount to pay Return value: int: minimum number of coins Execution example: >>> min_coins(1) 1 >>> min_coins(567) 6 """
coins = [500, 100, 50, 10, 5, 1] count = 0 for coin in coins: count += x // coin x %= coin return count
def check(candidate): assert candidate(1) == 1 assert candidate(5) == 1 assert candidate(11) == 2 assert candidate(250) == 3 assert candidate(567) == 6 assert candidate(1000) == 2 assert candidate(1234) == 11
min_coins
en/49
def count_ways(n: int) -> int: """ When you go up the n-step stairs at Yamadera, you go up one or two steps, Calculate the number of ways to climb if you do not climb two steps in succession. argument: n (int): Number of stairs (positive integer) Return value: int: number of ways up the stairs Execution example: >>> count_ways(1) 1 >>> count_ways(2) 2 >>> count_ways(3) 3 """
if n == 1: return 1 if n == 2: return 2 dp = [0] * (n + 1) dp[1] = 1 dp[2] = 2 for i in range(3, n + 1): dp[i] = dp[i - 1] + dp[i - 2] return dp[n]
def check(candidate): assert candidate(1) == 1 assert candidate(2) == 2 assert candidate(3) == 3 assert candidate(4) == 5 assert candidate(5) == 8 assert candidate(6) == 13 assert candidate(7) == 21 assert candidate(8) == 34 assert candidate(9) == 55 assert candidate(10) == 89 assert candidate(15) == 987
count_ways
en/50
def is_japan_prefecture(prefecture): """ A function that determines whether a given prefecture name is a Japanese prefecture. This function is based on a list of Japan's 47 prefectures (1 capital, 1 prefecture, 2 prefectures, 43 prefectures). Checks whether the entered prefecture name is included in that list and returns the result. Parameters: prefecture (str): Prefecture name to be determined Returns: bool: True if the prefecture name is included in Japan, otherwise False example: >>> is_japan_prefecture('ๆฑไบฌ้ƒฝ') True >>> is_japan_prefecture('ใƒ‹ใƒฅใƒผใƒจใƒผใ‚ฏ') False """
japan_prefectures = [ 'ๅŒ—ๆตท้“', '้’ๆฃฎ็œŒ', 'ๅฒฉๆ‰‹็œŒ', 'ๅฎฎๅŸŽ็œŒ', '็ง‹็”ฐ็œŒ', 'ๅฑฑๅฝข็œŒ', '็ฆๅณถ็œŒ', '่ŒจๅŸŽ็œŒ', 'ๆ ƒๆœจ็œŒ', '็พค้ฆฌ็œŒ', 'ๅŸผ็Ž‰็œŒ', 'ๅƒ่‘‰็œŒ', 'ๆฑไบฌ้ƒฝ', '็ฅžๅฅˆๅท็œŒ', 'ๆ–ฐๆฝŸ็œŒ', 'ๅฏŒๅฑฑ็œŒ', '็Ÿณๅท็œŒ', '็ฆไบ•็œŒ', 'ๅฑฑๆขจ็œŒ', '้•ท้‡Ž็œŒ', 'ๅฒ้˜œ็œŒ', '้™ๅฒก็œŒ', 'ๆ„›็Ÿฅ็œŒ', 'ไธ‰้‡็œŒ', 'ๆป‹่ณ€็œŒ', 'ไบฌ้ƒฝๅบœ', 'ๅคง้˜ชๅบœ', 'ๅ…ตๅบซ็œŒ', 'ๅฅˆ่‰ฏ็œŒ', 'ๅ’ŒๆญŒๅฑฑ็œŒ', '้ณฅๅ–็œŒ', 'ๅณถๆ น็œŒ', 'ๅฒกๅฑฑ็œŒ', 'ๅบƒๅณถ็œŒ', 'ๅฑฑๅฃ็œŒ', 'ๅพณๅณถ็œŒ', '้ฆ™ๅท็œŒ', 'ๆ„›ๅช›็œŒ', '้ซ˜็Ÿฅ็œŒ', '็ฆๅฒก็œŒ', 'ไฝ่ณ€็œŒ', '้•ทๅดŽ็œŒ', '็†Šๆœฌ็œŒ', 'ๅคงๅˆ†็œŒ', 'ๅฎฎๅดŽ็œŒ', '้นฟๅ…ๅณถ็œŒ', 'ๆฒ–็ธ„็œŒ' ] return prefecture in japan_prefectures
def check(candidate): true_prefectures = [ 'ๆฑไบฌ้ƒฝ', 'ๅคง้˜ชๅบœ', 'ๅŒ—ๆตท้“', '็ฆๅฒก็œŒ', 'ๆฒ–็ธ„็œŒ', '้’ๆฃฎ็œŒ', 'ๅฒฉๆ‰‹็œŒ', 'ๅฎฎๅŸŽ็œŒ', '็ง‹็”ฐ็œŒ', 'ๅฑฑๅฝข็œŒ', '็ฆๅณถ็œŒ', '่ŒจๅŸŽ็œŒ', 'ๆ ƒๆœจ็œŒ', '็พค้ฆฌ็œŒ', 'ๅŸผ็Ž‰็œŒ', 'ๅƒ่‘‰็œŒ', '็ฅžๅฅˆๅท็œŒ', 'ๆ–ฐๆฝŸ็œŒ', 'ๅฏŒๅฑฑ็œŒ', '็Ÿณๅท็œŒ', '็ฆไบ•็œŒ', 'ๅฑฑๆขจ็œŒ', '้•ท้‡Ž็œŒ', 'ๅฒ้˜œ็œŒ', '้™ๅฒก็œŒ', 'ๆ„›็Ÿฅ็œŒ', 'ไธ‰้‡็œŒ', 'ๆป‹่ณ€็œŒ', 'ไบฌ้ƒฝๅบœ', 'ๅ…ตๅบซ็œŒ', 'ๅฅˆ่‰ฏ็œŒ', 'ๅ’ŒๆญŒๅฑฑ็œŒ', '้ณฅๅ–็œŒ', 'ๅณถๆ น็œŒ', 'ๅฒกๅฑฑ็œŒ', 'ๅบƒๅณถ็œŒ', 'ๅฑฑๅฃ็œŒ', 'ๅพณๅณถ็œŒ', '้ฆ™ๅท็œŒ', 'ๆ„›ๅช›็œŒ', '้ซ˜็Ÿฅ็œŒ', 'ไฝ่ณ€็œŒ', '้•ทๅดŽ็œŒ', '็†Šๆœฌ็œŒ', 'ๅคงๅˆ†็œŒ', 'ๅฎฎๅดŽ็œŒ', '้นฟๅ…ๅณถ็œŒ' ] for prefecture in true_prefectures: assert candidate(prefecture) == True false_prefectures = ['ใƒ‹ใƒฅใƒผใƒจใƒผใ‚ฏๅทž', 'ใ‚ซใƒชใƒ•ใ‚ฉใƒซใƒ‹ใ‚ขๅทž', 'ไธŠๆตทๅธ‚', 'ใƒ‘ใƒช', 'ใƒญใƒณใƒ‰ใƒณ', 'ใ‚ทใƒณใ‚ฌใƒใƒผใƒซ', 'ใƒใƒณใ‚ณใ‚ฏ', 'ใ‚ทใƒ‰ใƒ‹ใƒผ'] for location in false_prefectures: assert candidate(location) == False
is_japan_prefecture
en/51
import math def calculate_coin_change(N: int, bill: int) -> int: """ Calculates the amount of change that is generated when paying for an item worth N yen using the specified banknote. argument: N (int): Product price. bill (int): The amount of banknotes to be used (e.g. 1000 yen, 5000 yen, 10000 yen, etc.). Return value: int: Amount of change (less than 1000 yen). Usage example: >>> calculate_coin_change(1200, 1000) 800 >>> calculate_coin_change(2500, 1000) 500 """
num_of_bills = math.ceil(N / bill) total_paid = num_of_bills * bill change = total_paid - N coin_change = change % 1000 return coin_change
def check(candidate): assert candidate(1200, 1000) == 800 assert candidate(2500, 1000) == 500 assert candidate(3000, 1000) == 0 assert candidate(4500, 2000) == 500 assert candidate(9999, 5000) == 1 assert candidate(1000, 1000) == 0 assert candidate(1, 10000) == 999 assert candidate(1500, 2000) == 500
calculate_coin_change
en/52
import math def lcm(a, b): """Function to find the least common multiple of two integers""" return a * b // math.gcd(a, b) def find_next_fireworks_time(N: int, periods: list) -> int: """ A function that calculates the next time all fireworks will go off at the same time. Parameters: N (int): Number of fireworks periods (list): List of firing periods for each fireworks Return value: int: Time when all fireworks will be launched at the same time """
result = periods[0] for i in range(1, N): result = lcm(result, periods[i]) return result
def check(candidate): assert candidate(3, [3, 5, 7]) == 105 assert candidate(2, [4, 6]) == 12 assert candidate(4, [2, 3, 4, 5]) == 60 assert candidate(5, [1, 1, 1, 1, 1]) == 1 assert candidate(3, [10, 20, 30]) == 60 assert candidate(2, [6, 8]) == 24 assert candidate(3, [11, 13, 17]) == 2431 assert candidate(1, [9]) == 9 assert candidate(3, [15, 25, 35]) == 525
find_next_fireworks_time
en/53
import math def can_measure_water(X: int, Y: int, Z: int) -> bool: """ A function that determines whether bucket A has a capacity of X liters, bucket B has a capacity of Y liters, and can measure Z liters of water. argument: X (int): Capacity of bucket A Y (int): Capacity of bucket B Z (int): amount of water you want to measure Return value: bool: True if Z liters can be measured, False if not. Usage example: >>> can_measure_water(3, 5, 4) True >>> can_measure_water(2, 6, 5) False >>> can_measure_water(1, 2, 3) True """
# ZใŒXใจYใ‚’ๅˆใ‚ใ›ใŸๅฎน้‡ใ‚’่ถ…ใˆใ‚‹ๅ ดๅˆใฏๆธฌๅฎšไธ่ƒฝ if Z > X + Y: return False # ZใƒชใƒƒใƒˆใƒซใŒXใƒชใƒƒใƒˆใƒซใจYใƒชใƒƒใƒˆใƒซใฎๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐใงๅ‰ฒใ‚Šๅˆ‡ใ‚Œใ‚‹ใ‹็ขบ่ช return Z % math.gcd(X, Y) == 0
def check(candidate): assert candidate(3, 5, 4) == True assert candidate(2, 6, 5) == False assert candidate(1, 2, 3) == True assert candidate(8, 12, 20) == True assert candidate(8, 12, 25) == False assert candidate(7, 5, 3) == True assert candidate(7, 5, 0) == True assert candidate(7, 5, 12) == True assert candidate(7, 5, 13) == False
can_measure_water
en/54
def check_olympic_year(year: int) -> bool: """ A function that checks whether the year is the year in which the Olympics were held in Japan. argument: year (int): year to check Return value: bool: True if the year the Olympics were held in Japan, False otherwise. Usage example: >>> check_olympic_year(1964) True >>> check_olympic_year(2000) False >>> check_olympic_year(2021) True """
olympic_years = {1964, 1972, 1998, 2021} return year in olympic_years
def check(candidate): assert candidate(1964) == True assert candidate(1972) == True assert candidate(1998) == True assert candidate(2021) == True assert candidate(2000) == False assert candidate(2016) == False assert candidate(2024) == False
check_olympic_year
en/55
def is_seven_gods(god_name: str) -> bool: """ Returns True if it is the name of the Seven Lucky Gods. >>> is_seven_gods("ๆตๆฏ”ๅฏฟ") True >>> is_seven_gods("ๅคง้ป’ๅคฉ") True >>> is_seven_gods("้˜ฟๅผฅ้™€ๅฆ‚ๆฅ") False """
seven_gods = ["ๆตๆฏ”ๅฏฟ", "ๅคง้ป’ๅคฉ", "ๆฏ˜ๆฒ™้–€ๅคฉ", "ๅผ่ฒกๅคฉ", "็ฆ็ฆ„ๅฏฟ", "ๅฏฟ่€ไบบ", "ๅธƒ่ข‹"] return god_name in seven_gods
def check(candidate): assert candidate("ๆตๆฏ”ๅฏฟ") == True assert candidate("ๅคง้ป’ๅคฉ") == True assert candidate("ๆฏ˜ๆฒ™้–€ๅคฉ") == True assert candidate("ๅผ่ฒกๅคฉ") == True assert candidate("็ฆ็ฆ„ๅฏฟ") == True assert candidate("ๅฏฟ่€ไบบ") == True assert candidate("ๅธƒ่ข‹") == True assert candidate("้˜ฟๅผฅ้™€ๅฆ‚ๆฅ") == False assert candidate("้‡ˆ่ฟฆ") == False assert candidate("่ฆณ้Ÿณ") == False assert candidate("ไธๅ‹•ๆ˜Ž็Ž‹") == False
is_seven_gods
en/56
def next_pigeon_clock_time(current_hour: int, interval: int) -> int: """ Calculate the next time the cuckoo clock will ring. argument: current_hour (int): current time (0 <= current_hour < 24) interval (int): Ringing interval (0 <= interval < 24) Return value: int: next time to ring (0 <= int < 24) Execution example: >>> next_pigeon_clock_time(14, 3) 17 >>> next_pigeon_clock_time(23, 1) 0 >>> next_pigeon_clock_time(22, 5) 3 >>> next_pigeon_clock_time(0, 24) 0 >>> next_pigeon_clock_time(12, 12) 0 """
next_hour = (current_hour + interval) % 24 return next_hour
def check(candidate): assert candidate(14, 3) == 17 assert candidate(23, 1) == 0 assert candidate(22, 5) == 3 assert candidate(0, 24) == 0 assert candidate(12, 12) == 0 assert candidate(6, 18) == 0 assert candidate(15, 10) == 1 assert candidate(23, 25) == 0 assert candidate(0, 1) == 1
next_pigeon_clock_time
en/57
def can_hanako_see_fireworks(A: int, B: int, C: int, D: int) -> bool: """ Determine whether Hanako can watch the fireworks display. - A (int): Start date of the fireworks display (number of days from today, afternoon). - B (int): End date of the fireworks display (number of days from today, afternoon). - C (int): Hanako's arrival date (number of days from today, morning). - D (int): The day Hanako leaves (number of days from today, morning). >>> can_hanako_see_fireworks(2, 4, 1, 3) True >>> can_hanako_see_fireworks(2, 4, 0, 2) False >>> can_hanako_see_fireworks(1, 5, 3, 6) True """
return C <= B and D > A
def check(candidate): assert candidate(2, 4, 1, 3) == True assert candidate(1, 5, 3, 6) == True assert candidate(2, 4, 0, 5) == True assert candidate(2, 4, 0, 2) == False assert candidate(3, 5, 0, 3) == False assert candidate(1, 2, 3, 4) == False assert candidate(2, 3, 4, 5) == False
can_hanako_see_fireworks
en/58
import datetime def get_tokyo_seijinshiki_date(year: int) -> str: """ Finds the coming-of-age ceremony date in Tokyo for the specified year. argument: year (int): year Return value: str: Date of coming-of-age ceremony (YYYY-MM-DD format) Usage example: >>> get_tokyo_seijinshiki_date(2024) '2024-01-08' """
# ๆŒ‡ๅฎšใ•ใ‚ŒใŸๅนดใฎ1ๆœˆ1ๆ—ฅใ‚’ๅ–ๅพ— first_january = datetime.date(year, 1, 1) # ็ฌฌ1ๆœˆๆ›œๆ—ฅใ‚’่จˆ็ฎ— first_monday = first_january + datetime.timedelta(days=(7 - first_january.weekday()) % 7) # ็ฌฌ2ๆœˆๆ›œๆ—ฅใ‚’่จˆ็ฎ— seijin_shiki_date = first_monday + datetime.timedelta(days=7) return seijin_shiki_date.strftime('%Y-%m-%d')
def check(candidate): assert candidate(2024) == "2024-01-08" assert candidate(2023) == "2023-01-09" assert candidate(2025) == "2025-01-13" assert candidate(2022) == "2022-01-10" assert candidate(2020) == "2020-01-13"
get_tokyo_seijinshiki_date
en/59
def find_number_of_apples(n: int, price: int) -> int: """ Find the number of apples purchased if a total of n apples and oranges are purchased and the total price is price yen. Apples cost 250 yen each, and oranges cost 120 yen each. argument: n (int): Total number of apples and oranges purchased price (int): total price Return value: int: Number of apples purchased. example: >>> find_number_of_apples(2, 370) 1 >>> find_number_of_apples(1, 250) 1 """
for x in range(n + 1): if 250 * x + 120 * (n - x) == price: return x return -1
def check(candidate): assert candidate(1, 250) == 1 assert candidate(1, 120) == 0 assert candidate(2, 370) == 1 assert candidate(5, 860) == 2 assert candidate(9, 1470) == 3 assert candidate(20, 3700) == 10
find_number_of_apples
en/60
def mouse_population(n: int) -> int: """ In January, the parent mouse gave birth to 12 children, and the total number of children was 14. From February onwards, every rat gives birth to 12 pups, so the number of rats each month is 13 times that of the previous month. argument: n (int): Month number (nth month) Return value: int: total number of rats in month n Execution example: >>> mouse_population(1) 14 >>> mouse_population(2) 98 >>> mouse_population(3) 686 >>> mouse_population(4) 4802 """
return 2*7**n
def check(candidate): assert candidate(1) == 14 assert candidate(2) == 98 assert candidate(3) == 686 assert candidate(4) == 4802 assert candidate(5) == 33614 assert candidate(6) == 235298 assert candidate(12) == 27682574402
mouse_population
en/61
import datetime def get_weekday(date: str) -> str: """ A function that returns the day of the week that corresponds to a given date. argument: date (str): date (yyyy-mm-dd format) Return value: str: Day of the week Usage example: >>> get_weekday("2024-01-01") 'ๆœˆๆ›œๆ—ฅ' >>> get_weekday("2024-02-14") 'ๆฐดๆ›œๆ—ฅ' """
dt = datetime.datetime.strptime(date, "%Y-%m-%d") weekdays = ["ๆœˆๆ›œๆ—ฅ", "็ซๆ›œๆ—ฅ", "ๆฐดๆ›œๆ—ฅ", "ๆœจๆ›œๆ—ฅ", "้‡‘ๆ›œๆ—ฅ", "ๅœŸๆ›œๆ—ฅ", "ๆ—ฅๆ›œๆ—ฅ"] return weekdays[dt.weekday()]
def check(candidate): assert candidate("2024-01-01") == "ๆœˆๆ›œๆ—ฅ" assert candidate("2024-01-02") == "็ซๆ›œๆ—ฅ" assert candidate("2024-01-03") == "ๆฐดๆ›œๆ—ฅ" assert candidate("2024-01-04") == "ๆœจๆ›œๆ—ฅ" assert candidate("2024-01-05") == "้‡‘ๆ›œๆ—ฅ" assert candidate("2024-01-06") == "ๅœŸๆ›œๆ—ฅ" assert candidate("2024-01-07") == "ๆ—ฅๆ›œๆ—ฅ" assert candidate("2024-02-14") == "ๆฐดๆ›œๆ—ฅ" assert candidate("2024-12-31") == "็ซๆ›œๆ—ฅ"
get_weekday
en/62
def find_b_paper_size(width: int, height: int) -> str: """ Determines the size of paper with the given dimensions using JIS standard B version and returns it. argument: width (int): Paper width (mm) height (int): Height of paper (mm) Return value: str: B version paper size (e.g. "B2") """
b_width, b_height = 1030, 1456 for i in range(11): if (width == b_width and height == b_height) or (width == b_height and height == b_width): return f"B{i}" b_width, b_height = b_height // 2, b_width
def check(candidate): assert candidate(1030, 1456) == "B0" assert candidate(728, 1030) == "B1" assert candidate(515, 728) == "B2" assert candidate(364, 515) == "B3" assert candidate(257, 364) == "B4" assert candidate(182, 257) == "B5" assert candidate(128, 182) == "B6" assert candidate(91, 128) == "B7" assert candidate(64, 91) == "B8" assert candidate(45, 64) == "B9" assert candidate(32, 45) == "B10" assert candidate(1456, 1030) == "B0" assert candidate(1030, 728) == "B1" assert candidate(728, 515) == "B2"
find_b_paper_size
en/63
def sanmoku_winner(board: list) -> str: """ Determine the winner or loser of tic-tac-toe. Tic-tac-toe is won when three Go pieces of the same color line up vertically, horizontally, or diagonally. It is assumed that a given board always has a winner or loser. argument: board (list): A 5ร—5 board represented by a double list. Each element is either "้ป’", "็™ฝ", or an empty string (""). Return value: str: "้ป’" or "็™ฝ" to represent the winner. """
directions = [(0, 1), (1, 0), (1, 1), (1, -1)] # ๆจช, ็ธฆ, ๅณไธ‹ใŒใ‚Š, ๅทฆไธ‹ใŒใ‚Š n = len(board) for row in range(n): for col in range(n): if board[row][col] in ("้ป’", "็™ฝ"): player = board[row][col] for dr, dc in directions: if all( 0 <= row + dr * i < n and 0 <= col + dc * i < n and board[row + dr * i][col + dc * i] == player for i in range(3) ): return player
def check(candidate): # ๆจชๆ–นๅ‘ใฎๅ‹ๅˆฉ board1 = [ ["้ป’", "้ป’", "้ป’", "", ""], ["", "็™ฝ", "", "", ""], ["", "", "", "็™ฝ", ""], ["", "", "", "", ""], ["", "", "", "", ""] ] assert candidate(board1) == "้ป’" # ็ธฆๆ–นๅ‘ใฎๅ‹ๅˆฉ board2 = [ ["", "", "", "", ""], ["็™ฝ", "้ป’", "", "", ""], ["็™ฝ", "้ป’", "", "", ""], ["็™ฝ", "้ป’", "", "", ""], ["", "", "", "", ""] ] assert candidate(board2) == "็™ฝ" # ๅทฆไธ‹ใŒใ‚Šๆ–œใ‚ใฎๅ‹ๅˆฉ board3 = [ ["", "", "", "", "็™ฝ"], ["", "", "", "็™ฝ", ""], ["", "", "็™ฝ", "", ""], ["", "้ป’", "", "", ""], ["้ป’", "", "", "", ""] ] assert candidate(board3) == "็™ฝ" # ็ต‚ไบ†ๆ™‚ใฎ็›ค้ขใŒ่ค‡้›‘ใชใ‚ฑใƒผใ‚น๏ผˆๆจชๆ–นๅ‘๏ผ‰ board4 = [ ["้ป’", "้ป’", "้ป’", "็™ฝ", "็™ฝ"], ["็™ฝ", "็™ฝ", "้ป’", "้ป’", "็™ฝ"], ["็™ฝ", "้ป’", "็™ฝ", "้ป’", "้ป’"], ["้ป’", "็™ฝ", "้ป’", "็™ฝ", "็™ฝ"], ["็™ฝ", "้ป’", "็™ฝ", "็™ฝ", "้ป’"] ] assert candidate(board4) == "้ป’" # ็ต‚ไบ†ๆ™‚ใฎ็›ค้ขใŒ่ค‡้›‘ใชใ‚ฑใƒผใ‚น๏ผˆ็ธฆๆ–นๅ‘๏ผ‰ board6 = [ ["็™ฝ", "้ป’", "็™ฝ", "้ป’", "็™ฝ"], ["็™ฝ", "้ป’", "็™ฝ", "้ป’", "็™ฝ"], ["็™ฝ", "้ป’", "็™ฝ", "้ป’", "็™ฝ"], ["้ป’", "็™ฝ", "้ป’", "็™ฝ", "้ป’"], ["็™ฝ", "้ป’", "็™ฝ", "้ป’", "็™ฝ"] ] assert candidate(board6) == "็™ฝ"
sanmoku_winner
en/64
def goldfish_scooping_score(fish_weights: list, poi_strength: int) -> int: """ Calculate the goldfish scooping score. Returns 0 if the sum of the weights exceeds the strength of the poi. argument: fish_weights (list of int): List of weights for each goldfish (e.g. [3, 2, 5]) poi_strength (int): Poi strength (e.g. 10) Return value: int: total score Usage example: >>> goldfish_scooping_score([3, 2, 5], 10) 10 >>> goldfish_scooping_score([3, 4, 6], 10) 0 >>> goldfish_scooping_score([2, 2, 2], 7) 6 """
total_weight = sum(fish_weights) if total_weight > poi_strength: return 0 return total_weight
def check(candidate): assert candidate([3, 2, 5], 10) == 10 assert candidate([2, 2, 2], 7) == 6 assert candidate([3, 4, 6], 10) == 0 assert candidate([4, 3, 3], 10) == 10 assert candidate([1, 1, 1], 3) == 3 assert candidate([], 10) == 0
goldfish_scooping_score
en/65
def hanako_otoshidama(before_price: int, growth_percentage: int, saving_price: int, item_price: int): """ The New Year has arrived. Hanako receives her New Year's gift. New Year's gift is the amount increased by `growth_percentage`% from the previous year's `before_price`. Hanako should determine whether she can reach the amount of money she wants for the game `item_price` by combining her savings `saving_price` with this year's New Year's gift. argument: before_price (int): Amount of New Year's gift from the previous year growth_percentage (int): Growth percentage value saving_price (int): Saving amount item_price (int): Price of the game you want Return value: str: If it can be achieved, it returns "่ณผๅ…ฅๅฏ่ƒฝ", otherwise it returns "ๅทฎ้กใฏ{ๅทฎ้ก}ๅ††". """
current_otoshidama = before_price * (100 + growth_percentage) // 100 total_money = current_otoshidama + saving_price if total_money >= item_price: return "่ณผๅ…ฅๅฏ่ƒฝ" else: return f"ๅทฎ้กใฏ{item_price - total_money}ๅ††"
def check(candidate): assert candidate(10000, 10, 5000, 16000) == "่ณผๅ…ฅๅฏ่ƒฝ" assert candidate(10000, 5, 3000, 15000) == "ๅทฎ้กใฏ1500ๅ††" assert candidate(5000, 20, 2000, 10000) == "ๅทฎ้กใฏ2000ๅ††"
hanako_otoshidama
en/66
import math def calculate_folds(x: float) -> int: """ Calculate the number of folds of origami from the length of one side of a small square. argument: x (float): The length of one side of a small square. Return value: int: Number of times the origami was folded n. """
n = math.log2(1 / x) return int(n)
def check(candidate): assert candidate(0.5) == 1 assert candidate(0.25) == 2 assert candidate(0.125) == 3 assert candidate(0.0625) == 4 assert candidate(1) == 0 assert candidate(0.03125) == 5 assert candidate(0.015625) == 6
calculate_folds
en/67
def calculate_and_check_caffeine(logs): """ A record of the drinks and caffeine consumed today will be provided. Check whether your daily caffeine intake exceeds 400mg. argument: logs: A list of dictionaries that record the daily caffeine intake of drinks. Each dictionary contains 'drink' (drink name) and 'caffeine_mg' (caffeine amount). Return value: 'High' if your caffeine intake exceeds 400mg 'Low' if your caffeine intake is less than 400mg """
recommended_limit = 400 total_caffeine = 0 for log in logs: total_caffeine += log['caffeine_mg'] if total_caffeine > recommended_limit: return "High" else: return "Low"
def check(candidate): logs1 = [ {'drink': 'ใ‚ณใƒผใƒ’ใƒผ', 'caffeine_mg': 95}, {'drink': '็ด…่Œถ', 'caffeine_mg': 40}, {'drink': 'ใ‚ธใƒฅใƒผใ‚น', 'caffeine_mg': 10} ] result1 = candidate(logs1) assert result1 == "Low", f"Test 1 failed: {result1}" logs2 = [ {'drink': 'ใ‚ณใƒผใƒ’ใƒผ', 'caffeine_mg': 100}, {'drink': '็ด…่Œถ', 'caffeine_mg': 100}, {'drink': 'ใ‚จใƒŠใ‚ธใƒผใƒ‰ใƒชใƒณใ‚ฏ', 'caffeine_mg': 100} ] result2 = candidate(logs2) assert result2 == "Low", f"Test 2 failed: {result2}" logs3 = [ {'drink': 'ใ‚ณใƒผใƒ’ใƒผ', 'caffeine_mg': 200}, {'drink': '็ด…่Œถ', 'caffeine_mg': 150}, {'drink': 'ใ‚จใƒŠใ‚ธใƒผใƒ‰ใƒชใƒณใ‚ฏ', 'caffeine_mg': 100} ] result3 = candidate(logs3) assert result3 == "High", f"Test 3 failed: {result3}"
calculate_and_check_caffeine
en/68
from typing import List def find_best_seat_with_location(seats: List[int], current: int) -> int: """ Given a seating list and current location, Haruko searches for a seat without anyone sitting next to her. argument: seats (List[int]): Seat list (0: empty seats, 1: seated seats). current (int): Haruko's current location (seat index). Return value: int: Index of the seat to which Haruko should move (starting at 0). Returns current location if there is no need to move. """
n = len(seats) best_seat = current # ๅˆๆœŸๅ€คใฏ็พๅœจๅœฐ min_distance = float('inf') # ๆœ€ๅฐ็งปๅ‹•่ท้›ขใฎๅˆๆœŸๅŒ– for i in range(n): if seats[i] == 0: # ็ฉบๅธญใ‚’ๆŽขใ™ # ้šฃใŒ็ฉบใ„ใฆใ„ใ‚‹ใ‹็ขบ่ช left_empty = (i == 0 or seats[i - 1] == 0) right_empty = (i == n - 1 or seats[i + 1] == 0) if left_empty and right_empty: distance = abs(current - i) # ็พๅœจๅœฐใ‹ใ‚‰ใฎ่ท้›ข if distance < min_distance: # ใ‚ˆใ‚Š่ฟ‘ใ„ๅธญใ‚’ๆŽขใ™ min_distance = distance best_seat = i return best_seat
def check(candidate): assert candidate([1, 0, 0, 1, 0, 0, 1], 2) == 2 assert candidate([1, 0, 1, 1, 0, 1, 0], 5) == 5 assert candidate([1, 1, 1, 1], 0) == 0 assert candidate([0, 0, 1, 0, 0], 2) == 0 assert candidate([1, 0, 0, 0, 1], 3) == 2 assert candidate([0, 0, 0, 0, 0], 2) == 2 assert candidate([1, 1, 0, 0, 1], 2) == 2
find_best_seat_with_location
en/69
import math def calculate_number_of_trees(r: float) -> int: """ If you want to plant trees around the perimeter of a circular lake with a radius of r meters, calculate the number of trees that can be planted every 3 meters. argument: r (float): radius of the lake (meters) Return value: int: Number of trees to be planted Execution example: >>> calculate_number_of_trees(10) 20 >>> calculate_number_of_trees(5) 10 """
circumference = 2 * math.pi * r return int(circumference // 3)
def check(candidate): assert candidate(10) == 20 assert candidate(5) == 10 assert candidate(15) == 31 assert candidate(3) == 6 assert candidate(1) == 2
calculate_number_of_trees
en/70
def min_cooking_time(ingredients): """ A function that calculates the minimum time to fry tempura using two pots. argument: ingredients (list): list of ingredients for frying time Return value: int: minimum frying time Usage example: >>> min_cooking_time([2, 3, 2, 1, 4]) 7 """
# ้ฃŸๆใฎๆšใ’ๆ™‚้–“ใ‚’ใ‚ฝใƒผใƒˆ๏ผˆ็Ÿญใ„้ †๏ผ‰ ingredients.sort() # 2ใคใฎ้‹ใ‚’ไฝฟใฃใŸๆœ€ๅฐๆ™‚้–“ใ‚’่จˆ็ฎ— time1 = 0 # ้‹1ใฎๆ™‚้–“ time2 = 0 # ้‹2ใฎๆ™‚้–“ for i in range(len(ingredients)): if time1 <= time2: time1 += ingredients[i] # ้‹1ใซ้ฃŸๆใ‚’่ฟฝๅŠ  else: time2 += ingredients[i] # ้‹2ใซ้ฃŸๆใ‚’่ฟฝๅŠ  return max(time1, time2) # ใฉใกใ‚‰ใ‹้•ทใ„ๆ–นใฎๆ™‚้–“ใŒๅ…จไฝ“ใฎๆ™‚้–“
def check(candidate): assert candidate([2, 3, 2, 1, 4]) == 7 assert candidate([3, 3, 3, 3]) == 6 assert candidate([5]) == 5 assert candidate([1, 2, 3, 4, 5, 6]) == 12
min_cooking_time
en/71
def get_essay_by_author(author: str) -> str: """ A function that returns the three major essays related to a given author. argument: author (str): name of the author Return value: str: Titles of three major essays related to the author """
essays = { "ๆธ…ๅฐ‘็ด่จ€": "ๆž•่‰ๅญ", "้ดจ้•ทๆ˜Ž": "ๆ–นไธˆ่จ˜", "ๅ‰็”ฐๅ…ผๅฅฝ": "ๅพ’็„ถ่‰" } return essays.get(author)
def check(candidate): assert candidate("ๆธ…ๅฐ‘็ด่จ€") == "ๆž•่‰ๅญ" assert candidate("้ดจ้•ทๆ˜Ž") == "ๆ–นไธˆ่จ˜" assert candidate("ๅ‰็”ฐๅ…ผๅฅฝ") == "ๅพ’็„ถ่‰"
get_essay_by_author
en/72
def calculate_restitution_coefficient(initial_velocity: float, final_velocity: float) -> float: """ Calculate the bounce coefficient of the Ohajiki. argument: initial_velocity (float): Velocity before collision. final_velocity (float): Velocity after collision. Return value: float: bounce coefficient e (value in the range 0 to 1) Usage example: >>> calculate_restitution_coefficient(5.0, 3.0) 0.6 >>> calculate_restitution_coefficient(5.0, 0.0) 0.0 """
if initial_velocity == 0: return 0.0 return final_velocity / initial_velocity
def check(candidate): assert candidate(5.0, 3.0) == 0.6 assert candidate(5.0, 0.0) == 0.0 assert candidate(10.0, 5.0) == 0.5 assert candidate(7.0, 7.0) == 1.0
calculate_restitution_coefficient
en/73
def get_rainbow_color(wavelength: int) -> str: """ Determine the rainbow color that corresponds to the given wavelength. argument: wavelength (int): Wavelength of light in nanometers. Return value: str: Rainbow color corresponding to wavelength (string) Usage example: >>> get_rainbow_color(650) '่ตค' >>> get_rainbow_color(510) '็ท‘' >>> get_rainbow_color(400) '็ดซ' >>> get_rainbow_color(800) None """
if 620 <= wavelength <= 750: return "่ตค" elif 590 <= wavelength < 620: return "ๆฉ™" elif 570 <= wavelength < 590: return "้ป„" elif 495 <= wavelength < 570: return "็ท‘" elif 450 <= wavelength < 495: return "้’" elif 430 <= wavelength < 450: return "่—" elif 380 <= wavelength < 430: return "็ดซ" else: return None
def check(candidate): assert candidate(650) == "่ตค" assert candidate(610) == "ๆฉ™" assert candidate(575) == "้ป„" assert candidate(510) == "็ท‘" assert candidate(480) == "้’" assert candidate(445) == "่—" assert candidate(400) == "็ดซ" assert candidate(800) == None
get_rainbow_color
en/74
from typing import List, Tuple import math def calculate_arrow_distance(speed: float, angle: float) -> float: """ Calculate the flight distance from the speed and angle at which the arrow was shot. argument: speed (float): initial speed of the arrow (m/s) angle (float): Angle at which the arrow is shot (in degrees) Return value: float: Arrow flight distance (m) (2 decimal places) Execution example: >>> calculate_arrow_distance(50, 45) 255.10 >>>calculate_arrow_distance(30, 30) 79.85 """
g = 9.8 # ๅฎšๆ•ฐ: ้‡ๅŠ›ๅŠ ้€Ÿๅบฆ๏ผˆm/s^2๏ผ‰ angle_rad = math.radians(angle) distance = (speed ** 2 * math.sin(2 * angle_rad)) / g return round(distance, 2)
def check(candidate): assert candidate(50, 45) == 255.10 assert candidate(30, 30) == 79.53 assert candidate(40, 60) == 141.39 assert candidate(20, 15) == 20.41 assert candidate(100, 45) == 1020.41
calculate_arrow_distance
en/75
def calculate_congestion_rate(max_capacity: int, current_passengers: int) -> float: """ Calculate the congestion rate of the train. argument: max_capacity (int): Train capacity (maximum capacity) current_passengers (int): Number of passengers currently on board Return value: float: Crowding rate (%) example: >>> calculate_congestion_rate(100, 120) 120.0 >>> calculate_congestion_rate(100, 50) 50.0 """
return (current_passengers / max_capacity) * 100
def check(candidate): assert candidate(100, 120) == 120.0 assert candidate(100, 50) == 50.0 assert candidate(150, 150) == 100.0 assert candidate(200, 180) == 90.0 assert candidate(300, 450) == 150.0
calculate_congestion_rate
en/76
def count_votes(votes: list) -> dict: """ Tally the voting results and calculate the number of votes for each candidate. argument: votes (list): List of voting results (list of candidate names) Return value: dict: a dictionary containing the number of votes each candidate received and the name of the winner Usage example: >>> votes = ["A", "B", "A", "C", "B", "A", "C", "B", "C", "C"] >>> count_votes(votes) {'A': 3, 'B': 3, 'C': 4, 'ๅ‹่€…': 'C'} """
# ๆŠ•็ฅจ็ตๆžœใ‚’้›†่จˆใ™ใ‚‹่พžๆ›ธใ‚’ไฝœๆˆ vote_count = {} # ๆŠ•็ฅจใ‚’้›†่จˆ for vote in votes: if vote in vote_count: vote_count[vote] += 1 else: vote_count[vote] = 1 # ๅ‹่€…ใ‚’ๆฑบๅฎš๏ผˆๅพ—็ฅจๆ•ฐใŒๅŒใ˜ๅ ดๅˆใฏๆœ€ๅˆใฎๅ€™่ฃœ่€…ใ‚’ๅ‹่€…ใจใ™ใ‚‹๏ผ‰ winner = max(vote_count, key=vote_count.get) # ็ตๆžœใซๅ‹่€…ใ‚’่ฟฝๅŠ  vote_count['ๅ‹่€…'] = winner return vote_count
def check(candidate): assert candidate(["A", "B", "A", "C", "B", "A", "C", "B", "C", "C"]) == {'A': 3, 'B': 3, 'C': 4, 'ๅ‹่€…': 'C'} assert candidate(["A", "A", "A", "B", "B", "C"]) == {'A': 3, 'B': 2, 'C': 1, 'ๅ‹่€…': 'A'} assert candidate(["A", "B", "B", "C", "C", "C", "C"]) == {'A': 1, 'B': 2, 'C': 4, 'ๅ‹่€…': 'C'} assert candidate(["X", "Y", "Y", "X", "Z", "Z", "Z"]) == {'X': 2, 'Y': 2, 'Z': 3, 'ๅ‹่€…': 'Z'}
count_votes
en/77
def day_or_night(hour: int, solstice: str) -> str: """ Determines whether the specified time is daytime or nighttime. Consider sunrise and sunset depending on the season. - hour (int): Time (integer from 0 to 23). - solstice (str): One of "summer solstice", "winter solstice", "spring equinox", "autumn equinox". - Return value: "day" or "night". Sunrise/Sunset (hypothetical): ๅค่‡ณ: sunrise at 4 o'clock, sunset at 20 o'clock ๅ†ฌ่‡ณ: Sunrise 7:00, Sunset 17:00 ๆ˜ฅๅˆ†/็ง‹ๅˆ†: Sunrise 6:00, Sunset 18:00 >>> day_or_night(5, "ๅค่‡ณ") 'ๆ˜ผ' >>> day_or_night(21, "ๅค่‡ณ") 'ๅคœ' >>> day_or_night(6, "ๅ†ฌ่‡ณ") 'ๅคœ' >>> day_or_night(12, "ๆ˜ฅๅˆ†") 'ๆ˜ผ' >>> day_or_night(19, "็ง‹ๅˆ†") 'ๅคœ' """
if solstice not in ("ๅค่‡ณ", "ๅ†ฌ่‡ณ", "ๆ˜ฅๅˆ†", "็ง‹ๅˆ†"): raise ValueError("solsticeใฏ'ๅค่‡ณ', 'ๅ†ฌ่‡ณ', 'ๆ˜ฅๅˆ†', '็ง‹ๅˆ†'ใฎใ„ใšใ‚Œใ‹ใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„ใ€‚") # ๅญฃ็ฏ€ใ”ใจใฎๆ—ฅใฎๅ‡บใƒปๆ—ฅใฎๅ…ฅใ‚Šๆ™‚ๅˆป if solstice == "ๅค่‡ณ": sunrise, sunset = 4, 20 elif solstice == "ๅ†ฌ่‡ณ": sunrise, sunset = 7, 17 elif solstice in ("ๆ˜ฅๅˆ†", "็ง‹ๅˆ†"): sunrise, sunset = 6, 18 # ๆ˜ผ้–“ใ‹ๅคœ้–“ใ‚’ๅˆคๅฎš return "ๆ˜ผ" if sunrise <= hour < sunset else "ๅคœ"
def check(candidate): assert candidate(4, "ๅค่‡ณ") == "ๆ˜ผ" assert candidate(3, "ๅค่‡ณ") == "ๅคœ" assert candidate(12, "ๅค่‡ณ") == "ๆ˜ผ" assert candidate(20, "ๅค่‡ณ") == "ๅคœ" assert candidate(21, "ๅค่‡ณ") == "ๅคœ" assert candidate(7, "ๅ†ฌ่‡ณ") == "ๆ˜ผ" assert candidate(6, "ๅ†ฌ่‡ณ") == "ๅคœ" assert candidate(12, "ๅ†ฌ่‡ณ") == "ๆ˜ผ" assert candidate(17, "ๅ†ฌ่‡ณ") == "ๅคœ" assert candidate(18, "ๅ†ฌ่‡ณ") == "ๅคœ" assert candidate(6, "ๆ˜ฅๅˆ†") == "ๆ˜ผ" assert candidate(5, "ๆ˜ฅๅˆ†") == "ๅคœ" assert candidate(12, "ๆ˜ฅๅˆ†") == "ๆ˜ผ" assert candidate(18, "ๆ˜ฅๅˆ†") == "ๅคœ" assert candidate(19, "ๆ˜ฅๅˆ†") == "ๅคœ" assert candidate(6, "็ง‹ๅˆ†") == "ๆ˜ผ" assert candidate(5, "็ง‹ๅˆ†") == "ๅคœ" assert candidate(12, "็ง‹ๅˆ†") == "ๆ˜ผ" assert candidate(18, "็ง‹ๅˆ†") == "ๅคœ" assert candidate(19, "็ง‹ๅˆ†") == "ๅคœ"
day_or_night
en/78
def get_japanese_holiday(month: int) -> list: """ If you enter a month, it will return a list of Japanese holidays in that month. argument: month (int): month (1-12) Return value: list: list of applicable holidays Usage example: >>> get_japanese_holiday(1) ['New Year's Day', 'Coming-of-Age Day'] >>> get_japanese_holiday(11) ['Culture Day', 'Labor Thanksgiving Day'] """
holiday_dict = { 1: ['ๅ…ƒๆ—ฅ', 'ๆˆไบบใฎๆ—ฅ'], # ๆˆไบบใฎๆ—ฅใฏ1ๆœˆใฎ็ฌฌ2ๆœˆๆ›œๆ—ฅ 2: ['ๅปบๅ›ฝ่จ˜ๅฟตใฎๆ—ฅ'], # 2ๆœˆ11ๆ—ฅ 3: ['ๆ˜ฅๅˆ†ใฎๆ—ฅ'], # ๆ˜ฅๅˆ†ใฎๆ—ฅใฏๅนดใซใ‚ˆใฃใฆๅค‰ๅ‹•ใ™ใ‚‹ใŒใ€3ๆœˆ20ๆ—ฅ้ ƒ 4: ['ๆ˜ญๅ’Œใฎๆ—ฅ'], # 4ๆœˆ29ๆ—ฅ 5: ['ๆ†ฒๆณ•่จ˜ๅฟตๆ—ฅ', 'ใฟใฉใ‚Šใฎๆ—ฅ', 'ใ“ใฉใ‚‚ใฎๆ—ฅ'], # 5ๆœˆ3ๆ—ฅ, 5ๆœˆ4ๆ—ฅ, 5ๆœˆ5ๆ—ฅ 6: [], # 6ๆœˆใฏ็ฅๆ—ฅใชใ— 7: ['ๆตทใฎๆ—ฅ'], # ๆตทใฎๆ—ฅใฏ7ๆœˆใฎ็ฌฌ3ๆœˆๆ›œๆ—ฅ 8: ['ๅฑฑใฎๆ—ฅ'], # ๅฑฑใฎๆ—ฅใฏ8ๆœˆ11ๆ—ฅ 9: ['ๆ•ฌ่€ใฎๆ—ฅ', '็ง‹ๅˆ†ใฎๆ—ฅ'], # ๆ•ฌ่€ใฎๆ—ฅใฏ9ๆœˆใฎ็ฌฌ3ๆœˆๆ›œๆ—ฅใ€็ง‹ๅˆ†ใฎๆ—ฅใฏ9ๆœˆ23ๆ—ฅ้ ƒ 10: ['ใ‚นใƒใƒผใƒ„ใฎๆ—ฅ'], # 10ๆœˆใฎ็ฌฌ2ๆœˆๆ›œๆ—ฅ 11: ['ๆ–‡ๅŒ–ใฎๆ—ฅ', 'ๅ‹คๅŠดๆ„Ÿ่ฌใฎๆ—ฅ'], # 11ๆœˆ3ๆ—ฅ, 11ๆœˆ23ๆ—ฅ 12: [], # 12ๆœˆใฏ็ฅๆ—ฅใชใ— } return holiday_dict.get(month, [])
def check(candidate): assert candidate(1) == ['ๅ…ƒๆ—ฅ', 'ๆˆไบบใฎๆ—ฅ'] # 1ๆœˆ assert candidate(2) == ['ๅปบๅ›ฝ่จ˜ๅฟตใฎๆ—ฅ'] # 2ๆœˆ assert candidate(3) == ['ๆ˜ฅๅˆ†ใฎๆ—ฅ'] # 3ๆœˆ assert candidate(4) == ['ๆ˜ญๅ’Œใฎๆ—ฅ'] # 4ๆœˆ assert candidate(5) == ['ๆ†ฒๆณ•่จ˜ๅฟตๆ—ฅ', 'ใฟใฉใ‚Šใฎๆ—ฅ', 'ใ“ใฉใ‚‚ใฎๆ—ฅ'] # 5ๆœˆ assert candidate(7) == ['ๆตทใฎๆ—ฅ'] # 7ๆœˆ assert candidate(8) == ['ๅฑฑใฎๆ—ฅ'] # 8ๆœˆ assert candidate(9) == ['ๆ•ฌ่€ใฎๆ—ฅ', '็ง‹ๅˆ†ใฎๆ—ฅ'] # 9ๆœˆ assert candidate(10) == ['ใ‚นใƒใƒผใƒ„ใฎๆ—ฅ'] # 10ๆœˆ assert candidate(11) == ['ๆ–‡ๅŒ–ใฎๆ—ฅ', 'ๅ‹คๅŠดๆ„Ÿ่ฌใฎๆ—ฅ'] # 11ๆœˆ assert candidate(6) == [] # 6ๆœˆ assert candidate(12) == [] # 12ๆœˆ
get_japanese_holiday
en/79
def check_yakudoshi(age: int, gender: str) -> str: """ Based on age and gender, it determines whether the age is in bad year, mae-yaku, or after-yaku. argument: age (int): Age to judge gender (str): gender ('male' or 'female') Return value: str: One of the โ€ๅŽ„ๅนดโ€, โ€ๅ‰ๅŽ„โ€, โ€ๅพŒๅŽ„โ€, or "ๅŽ„ๅนดใงใฏใชใ„" Usage example: >>> check_yakudoshi(25, 'ๅฅณๆ€ง') 'ๅ‰ๅŽ„' >>> check_yakudoshi(33, 'ๅฅณๆ€ง') 'ๅŽ„ๅนด' >>> check_yakudoshi(37, '็”ทๆ€ง') 'ๅพŒๅŽ„' >>> check_yakudoshi(40, '็”ทๆ€ง') 'ๅŽ„ๅนดใงใฏใชใ„' """
male_yakudoshi = { 'ๅ‰ๅŽ„': [24, 40, 60], 'ๅŽ„ๅนด': [25, 41, 61], 'ๅพŒๅŽ„': [26, 42, 62] } female_yakudoshi = { 'ๅ‰ๅŽ„': [18, 32, 36], 'ๅŽ„ๅนด': [19, 33, 37], 'ๅพŒๅŽ„': [20, 34, 38] } if gender == '็”ทๆ€ง': yakudoshi_dict = male_yakudoshi elif gender == 'ๅฅณๆ€ง': yakudoshi_dict = female_yakudoshi for yakutype, ages in yakudoshi_dict.items(): if age in ages: return yakutype return 'ๅŽ„ๅนดใงใฏใชใ„'
def check(candidate): # 1. ็”ทๆ€งใฎใƒ†ใ‚นใƒˆ assert candidate(24, '็”ทๆ€ง') == 'ๅ‰ๅŽ„' # ๅ‰ๅŽ„ assert candidate(25, '็”ทๆ€ง') == 'ๅŽ„ๅนด' # ๅŽ„ๅนด assert candidate(26, '็”ทๆ€ง') == 'ๅพŒๅŽ„' # ๅพŒๅŽ„ assert candidate(40, '็”ทๆ€ง') == 'ๅ‰ๅŽ„' # ๅ‰ๅŽ„ assert candidate(41, '็”ทๆ€ง') == 'ๅŽ„ๅนด' # ๅŽ„ๅนด assert candidate(42, '็”ทๆ€ง') == 'ๅพŒๅŽ„' # ๅพŒๅŽ„ assert candidate(30, '็”ทๆ€ง') == 'ๅŽ„ๅนดใงใฏใชใ„' # ใฉใฎๅŽ„ๅนดใซใ‚‚่ฉฒๅฝ“ใ—ใชใ„ # 2. ๅฅณๆ€งใฎใƒ†ใ‚นใƒˆ assert candidate(18, 'ๅฅณๆ€ง') == 'ๅ‰ๅŽ„' # ๅ‰ๅŽ„ assert candidate(19, 'ๅฅณๆ€ง') == 'ๅŽ„ๅนด' # ๅŽ„ๅนด assert candidate(20, 'ๅฅณๆ€ง') == 'ๅพŒๅŽ„' # ๅพŒๅŽ„ assert candidate(32, 'ๅฅณๆ€ง') == 'ๅ‰ๅŽ„' # ๅ‰ๅŽ„ assert candidate(33, 'ๅฅณๆ€ง') == 'ๅŽ„ๅนด' # ๅŽ„ๅนด assert candidate(34, 'ๅฅณๆ€ง') == 'ๅพŒๅŽ„' # ๅพŒๅŽ„ assert candidate(25, 'ๅฅณๆ€ง') == 'ๅŽ„ๅนดใงใฏใชใ„' # ใฉใฎๅŽ„ๅนดใซใ‚‚่ฉฒๅฝ“ใ—ใชใ„
check_yakudoshi
en/80
def binary_search_count(numbers, x): """ Hanako and Taro are enjoying a number guessing game. Hanako creates a sequence of numbers arranged in ascending order and determines the secret number. Taro guesses the secret number while performing a binary search. Please calculate how many times Taro can guess the secret number. argument: numbers (list): a sequence of numbers arranged in ascending order x (int): secret number Return value: count (int): Number of times it takes Taro to guess the secret number example: >>> binary_search_count([1, 3, 5, 7, 9], 5) 1 >>> binary_search_count([1, 3, 5, 7, 9], 7) 2 >>> binary_search_count([1, 3, 5, 7, 9], 2) 3 """
left, right = 0, len(numbers) - 1 count = 0 while left <= right: count += 1 mid = (left + right) // 2 if numbers[mid] == x: return count elif numbers[mid] < x: left = mid + 1 else: right = mid - 1 return count
def check(candidate): assert candidate([1, 3, 5, 7, 9], 5) == 1 assert candidate([1, 3, 5, 7, 9], 7) == 2 assert candidate([1, 3, 5, 7, 9], 2) == 3 assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1) == 3 assert candidate([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10) == 4
binary_search_count
en/81
def calculate_rice_time(rice_type: str) -> int: """ A function that returns the soaking time (minutes) required to cook rice. Minimum requirements: - rice_type is one of "็™ฝ็ฑณ", "็Ž„็ฑณ", or "็„กๆด—็ฑณ" . - If any other rice_type is specified, -1 is returned. rule: - "็™ฝ็ฑณ" requires 30 minutes of soaking time. - "็Ž„็ฑณ" requires soaking time of 360 minutes (6 hours). - For "็„กๆด—็ฑณ", soaking time is 0 minutes (not required). argument: rice_type (str): Type of rice Return value: int: Immersion time (minutes) Usage example: >>> calculate_rice_time("็™ฝ็ฑณ") 30 >>> calculate_rice_time("็Ž„็ฑณ") 360 >>> calculate_rice_time("็„กๆด—็ฑณ") 0 >>> calculate_rice_time("ใ‚‚ใก็ฑณ") -1 """
if rice_type == "็™ฝ็ฑณ": return 30 elif rice_type == "็Ž„็ฑณ": return 360 # 6ๆ™‚้–“ = 360ๅˆ† elif rice_type == "็„กๆด—็ฑณ": return 0 else: return -1 # ไธๆ˜Žใชใ”้ฃฏใฎ็จฎ้กž
def check(candidate): assert candidate("็™ฝ็ฑณ") == 30 assert candidate("็Ž„็ฑณ") == 360 assert candidate("็„กๆด—็ฑณ") == 0 assert candidate("ใ‚‚ใก็ฑณ") == -1 assert candidate("้ป’็ฑณ") == -1 assert candidate("") == -1 assert candidate("WHITE") == -1 assert candidate("็™ฝ") == -1 assert candidate("็„กๆด—") == -1 assert candidate("็Ž„") == -1
calculate_rice_time
en/82
def is_mobile_phone(number: str) -> bool: """ Determine whether the given phone number is a Japanese mobile phone number. Japanese mobile phone numbers start like this: -090 - 080 -070 argument: number (str): 11-digit phone number (must start with 0) Return value: bool: Returns True if it is a mobile phone number, otherwise returns False. Usage example: >>> is_mobile_phone("09012345678") True >>> is_mobile_phone("08098765432") True >>> is_mobile_phone("07011112222") True >>> is_mobile_phone("0312345678") False >>> is_mobile_phone("0123456789") False """
if number.startswith("090") or number.startswith("080") or number.startswith("070"): return True return False
def check(candidate): # ไฝฟ็”จไพ‹ assert candidate("09012345678") == True assert candidate("08098765432") == True assert candidate("07011112222") == True assert candidate("0312345678") == False assert candidate("0123456789") == False # ๆ—ฅๆœฌใฎๆบๅธฏ้›ป่ฉฑ็•ชๅทๅฝขๅผ assert candidate("09012345678") == True assert candidate("08098765432") == True assert candidate("07055556666") == True # ๆ—ฅๆœฌใฎๆบๅธฏ้›ป่ฉฑ็•ชๅทๅฝขๅผใงใฏใชใ„ assert candidate("0312345678") == False assert candidate("01201234567") == False assert candidate("05012345678") == False
is_mobile_phone
en/83
def hiragana_to_katakana(name: str) -> str: """ Converts the name entered in hiragana to katakana. argument: name (str): Full name entered in hiragana Return value: str: Full name converted to katakana Usage example: >>> hiragana_to_katakana('ใŸใชใ‹ ใŸใ‚ใ†') 'ใ‚ฟใƒŠใ‚ซ ใ‚ฟใƒญใ‚ฆ' >>> hiragana_to_katakana('ใ•ใจใ† ใ˜ใ‚ใ†') 'ใ‚ตใƒˆใ‚ฆ ใ‚ธใƒญใ‚ฆ' >>> hiragana_to_katakana('ใ‚„ใพใ  ใฏใชใ“') 'ใƒคใƒžใƒ€ ใƒใƒŠใ‚ณ' """
hiragana = ( "ใใ‚ใƒใ„ใ…ใ†ใ‡ใˆใ‰ใŠใ‹ใŒใใŽใใใ‘ใ’ใ“ใ”ใ•ใ–ใ—ใ˜ใ™ใšใ›ใœใใž" "ใŸใ ใกใขใคใฅใฆใงใจใฉใชใซใฌใญใฎใฏใฐใฑใฒใณใดใตใถใทใธในใบใปใผใฝ" "ใพใฟใ‚€ใ‚ใ‚‚ใ‚ƒใ‚„ใ‚…ใ‚†ใ‚‡ใ‚ˆใ‚‰ใ‚Šใ‚‹ใ‚Œใ‚ใ‚Žใ‚ใ‚ใ‚‘ใ‚’ใ‚“ใ‚”" ) katakana = ( "ใ‚กใ‚ขใ‚ฃใ‚คใ‚ฅใ‚ฆใ‚งใ‚จใ‚ฉใ‚ชใ‚ซใ‚ฌใ‚ญใ‚ฎใ‚ฏใ‚ฐใ‚ฑใ‚ฒใ‚ณใ‚ดใ‚ตใ‚ถใ‚ทใ‚ธใ‚นใ‚บใ‚ปใ‚ผใ‚ฝใ‚พ" "ใ‚ฟใƒ€ใƒใƒ‚ใƒ„ใƒ…ใƒ†ใƒ‡ใƒˆใƒ‰ใƒŠใƒ‹ใƒŒใƒใƒŽใƒใƒใƒ‘ใƒ’ใƒ“ใƒ”ใƒ•ใƒ–ใƒ—ใƒ˜ใƒ™ใƒšใƒ›ใƒœใƒ" "ใƒžใƒŸใƒ ใƒกใƒขใƒฃใƒคใƒฅใƒฆใƒงใƒจใƒฉใƒชใƒซใƒฌใƒญใƒฎใƒฏใƒฐใƒฑใƒฒใƒณใƒด" ) # ใฒใ‚‰ใŒใชใ‚’ใ‚ซใ‚ฟใ‚ซใƒŠใซๅค‰ๆ› return name.translate(str.maketrans(hiragana, katakana))
def check(candidate): # ๅŸบๆœฌ็š„ใชไฝฟ็”จไพ‹ assert candidate('ใŸใชใ‹ ใŸใ‚ใ†') == 'ใ‚ฟใƒŠใ‚ซ ใ‚ฟใƒญใ‚ฆ' assert candidate('ใ•ใจใ† ใ˜ใ‚ใ†') == 'ใ‚ตใƒˆใ‚ฆ ใ‚ธใƒญใ‚ฆ' assert candidate('ใ‚„ใพใ  ใฏใชใ“') == 'ใƒคใƒžใƒ€ ใƒใƒŠใ‚ณ' # ๆง˜ใ€…ใชใฒใ‚‰ใŒใชๆ–‡ๅญ—ๅˆ— assert candidate('ใใ‚€ใ‚‰ ใฟใ•ใ') == 'ใ‚ญใƒ ใƒฉ ใƒŸใ‚ตใ‚ญ' assert candidate('ใ“ใฐใ‚„ใ— ใพใ•ใฒใ‚') == 'ใ‚ณใƒใƒคใ‚ท ใƒžใ‚ตใƒ’ใƒญ' assert candidate('ใฏใ—ใ‚‚ใจ ใ‹ใ„ใจ') == 'ใƒใ‚ทใƒขใƒˆ ใ‚ซใ‚คใƒˆ' assert candidate('ใพใคใ‚‚ใจ ใ•ใใ‚‰') == 'ใƒžใƒ„ใƒขใƒˆ ใ‚ตใ‚ฏใƒฉ'
hiragana_to_katakana
en/84
def contains_fullwidth_katakana(text: str) -> bool: """ Checks whether the given string contains full-width katakana characters. Returns True if full-width katakana is included. argument: text (str): string to check Return value: bool: True if full-width katakana is included, False if not Usage example: >>> contains_fullwidth_katakana("ใ‚ซใ‚ฟใ‚ซใƒŠ") True >>> contains_fullwidth_katakana("ใ“ใ‚“ใซใกใฏ") False >>> contains_fullwidth_katakana("Hello") False """
for char in text: if '\u30A0' <= char <= '\u30FF': return True return False
def check(candidate): assert candidate("ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == True assert candidate("ใ‚ซใ‚ญใ‚ฏใ‚ฑใ‚ณ") == True assert candidate("ใƒใƒญใƒผใƒฏใƒผใƒซใƒ‰") == True assert candidate("ใ‹ใŸใ‹ใช") == False assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠ") == True assert candidate("็‰‡ไปฎๅ") == False assert candidate("KATAKANA") == False assert candidate("katakana") == False
contains_fullwidth_katakana
en/85
def number_to_kanji(number: int) -> str: """ This function converts the given number into Chinese numerals and returns it. argument: number (int): number (0 <= number <= 9999) Return value: str: Numeric value expressed in Chinese numerals example: >>> number_to_kanji(0) 'ใ€‡' >>> number_to_kanji(21) 'ไบŒๅไธ€' >>> number_to_kanji(105) '็™พไบ”' >>> number_to_kanji(9999) 'ไนๅƒไน็™พไนๅไน' """
if number == 0: return "ใ€‡" kanji_digits = "ใ€‡ไธ€ไบŒไธ‰ๅ››ไบ”ๅ…ญไธƒๅ…ซไน" units = ["", "ๅ", "็™พ", "ๅƒ"] kanji = "" digits = str(number) length = len(digits) for i, digit in enumerate(digits): d = int(digit) if d == 0: continue unit = units[length - i - 1] if d == 1 and unit in ["ๅ", "็™พ", "ๅƒ"] and i == 0: kanji += unit else: kanji += kanji_digits[d] + unit return kanji
def check(candidate): assert candidate(0) == "ใ€‡" assert candidate(1) == "ไธ€" assert candidate(10) == "ๅ" assert candidate(21) == "ไบŒๅไธ€" assert candidate(105) == "็™พไบ”" assert candidate(1234) == "ๅƒไบŒ็™พไธ‰ๅๅ››" assert candidate(9999) == "ไนๅƒไน็™พไนๅไน"
number_to_kanji
en/86
def sum_of_kanji_numbers(S: str) -> int: """ A function that calculates the sum of the Chinese digits '1' to '9' in the string S. argument: S (str): A string containing the Chinese numerals 'ไธ€ไบŒไธ‰ๅ››ไบ”ๅ…ญไธƒๅ…ซไน'. Return value: int: Total number obtained by converting kanji numerals. example >>> sum_of_kanji_numbers(โ€ไธ€ไบŒไธ‰ๅ››ไบ”ๅ…ญไธƒๅ…ซไนโ€) 45 """
kanji_to_number = {'ไธ€': 1, 'ไบŒ': 2, 'ไธ‰': 3, 'ๅ››': 4, 'ไบ”': 5, 'ๅ…ญ': 6, 'ไธƒ': 7, 'ๅ…ซ': 8, 'ไน': 9} return sum(kanji_to_number[char] for char in S if char in kanji_to_number)
def check(candidate): assert candidate("ไธ€ไบŒไธ‰ๅ››ไบ”ๅ…ญไธƒๅ…ซไน") == 45 assert candidate("ไธ‰ไบ”ไธƒ") == 15 assert candidate("ไธ€ๅ››ไธƒ") == 12 assert candidate("ไบŒไบŒไบŒ") == 6 assert candidate("ไนไน") == 18
sum_of_kanji_numbers
en/87
import re def parse_date(date_str: str) -> tuple: """ Converts a date string in 'YYYYๅนดMMๆœˆDDๆ—ฅ' format to a tuple (year, month, day). argument: date_str (str): Date string in the format 'YYYYYYYYMMMMDDD' Return value: tuple: tuple of (year, month, day) Usage example: >>> parse_japanese_date('2024ๅนด11ๆœˆ20ๆ—ฅ') (2024, 11, 20) """
pattern = r'(\d{4})ๅนด(\d{2})ๆœˆ(\d{2})ๆ—ฅ' match = re.match(pattern, date_str) if match: return tuple(map(int, match.groups()))
def check(candidate): assert candidate('2024ๅนด11ๆœˆ20ๆ—ฅ') == (2024, 11, 20) assert candidate('2000ๅนด01ๆœˆ01ๆ—ฅ') == (2000, 1, 1) assert candidate('1999ๅนด12ๆœˆ31ๆ—ฅ') == (1999, 12, 31)
parse_date
en/88
from typing import List def max_shiritori_chain(words: List[str]) -> int: """ Returns the chain number of how many times Shiritori lasts. Rules: - Match the last letter of the previous word with the first letter of the next word - Ends if the same word appears or if the last letter of the word ends with "n" argument: words (List[str]): list of words Return value: int: longest shiritori chain number Usage example: >>> max_shiritori_chain(["ใญใ“", "ใ“ใŸใค", "ใคใฟใ", "ใใคใญ", "ใญใšใฟ"]) 5 >>> max_shiritori_chain(["ใ‚Šใ‚“ใ”", "ใ”ใพ", "ใพใ‚Š", "ใ„ใฌ", "ใฌใ‚Šใˆ", "ใˆใ‚“ใดใค"]) 3 >>> max_shiritori_chain(["ใ•ใใ‚‰", "ใ‚‰ใ„ใŠใ‚“", "ใ‚“ใพ", "ใพใคใ‚Š"]) 1 """
if not words: return 0 chain_count = 0 seen_words = set() for i in range(len(words)): word = words[i] if word in seen_words or word[-1] == "ใ‚“": break seen_words.add(word) if i > 0 and words[i - 1][-1] != word[0]: break chain_count += 1 return chain_count
def check(candidate): assert candidate(["ใญใ“", "ใ“ใŸใค", "ใคใฟใ", "ใใคใญ", "ใญใšใฟ"]) == 5 assert candidate(["ใ‚Šใ‚“ใ”", "ใ”ใพ", "ใพใ‚Š", "ใ„ใฌ", "ใฌใ‚Šใˆ", "ใˆใ‚“ใดใค"]) == 3 assert candidate(["ใ‚Šใ‚“ใ”", "ใ”ใพ", "ใพใ‚Š", "ใ‚Šใ‚“ใ”"]) == 3 assert candidate(["ใ•ใใ‚‰", "ใ‚‰ใฃใฑ", "ใฑใ‚“", "ใ‚“ใพ", "ใพใคใ‚Š"]) == 2 assert candidate(["ใ•ใใ‚‰", "ใ‚‰ใ„ใŠใ‚“", "ใ‚“ใพ", "ใพใคใ‚Š"]) == 1 assert candidate(["ใŸใฌใ", "ใใคใญ", "ใญใšใฟ", "ใฟใฟใš", "ใšใ‚‹ใ„"]) == 5
max_shiritori_chain
en/89
def calculate(expression: str) -> int: """ Performs a calculation based on a kanji calculation formula and returns the result. argument: expression (str): Kanji calculation expression (e.g. "ๅ’Œ 3 5") Return value: int: calculation result Usage example: >>> calculate("ๅ’Œ 3 5") 8 >>> calculate("ๅทฎ 9 4") 5 >>> calculate("็ฉ 2 6") 12 >>> calculate("ๅ•† 8 2") 4 """
# ๆ–‡ๅญ—ๅˆ—ใ‚’ๅˆ†ๅ‰ฒใ—ใฆใ€ๆผ”็ฎ—ใฎ็จฎ้กžใจๆ•ฐๅ€คใ‚’ๅ–ๅพ— parts = expression.split() operator, a, b = parts[0], int(parts[1]), int(parts[2]) # ๆผขๅญ—ใซๅฏพๅฟœใ™ใ‚‹่จˆ็ฎ—ใ‚’่กŒใ† if operator == "ๅ’Œ": return a + b elif operator == "ๅทฎ": return a - b elif operator == "็ฉ": return a * b elif operator == "ๅ•†": return a // b # 0้™ค็ฎ—ใฏๅ…ฅๅŠ›ๅดใฎ่ฒฌไปปใง้˜ฒใๅ‰ๆ
def check(candidate): assert candidate("ๅ’Œ 3 5") == 8 assert candidate("ๅทฎ 9 4") == 5 assert candidate("็ฉ 2 6") == 12 assert candidate("ๅ•† 8 2") == 4 assert candidate("ๅ•† 7 3") == 2 assert candidate("ๅทฎ 0 5") == -5 assert candidate("ๅ’Œ 0 0") == 0 assert candidate("็ฉ 5 0") == 0
calculate
en/90
import re from typing import List def extract_numbers_from_text(text: str) -> List[int]: """ Extracts numbers from a given Japanese sentence and returns them as a list of integers. argument: text (str): Japanese text containing numbers. Return value: List[int]: List of extracted numbers. Execution example: >>> extract_numbers_from_text("ไปŠๅนดใฎไบˆ็ฎ—ใฏ500ไธ‡ๅ††ใงใ€ๅ…ˆๆœˆใฎๅฃฒไธŠใฏ200ไธ‡ๅ††ใงใ—ใŸใ€‚") [500, 200] >>> extract_numbers_from_text("ใŠๅบ—ใซใฏ3ใคใฎใƒชใƒณใ‚ดใŒใ‚ใ‚Šใ€4ไบบใฎใŠๅฎขใ•ใ‚“ใŒๆฅใพใ—ใŸใ€‚") [3, 4] >>> extract_numbers_from_text("2023ๅนดใฏ็‰นๅˆฅใชๅนดใงใ™ใ€‚") [2023] >>> extract_numbers_from_text("ๆ–‡็ซ ใซๆ•ฐๅ€คใŒใ‚ใ‚Šใพใ›ใ‚“ใ€‚") [] """
numbers = re.findall(r'\d+', text) return [int(num) for num in numbers]
def check(candidate): assert candidate("ไปŠๅนดใฎไบˆ็ฎ—ใฏ500ไธ‡ๅ††ใงใ€ๅ…ˆๆœˆใฎๅฃฒไธŠใฏ200ไธ‡ๅ††ใงใ—ใŸใ€‚") == [500, 200] assert candidate("ใŠๅบ—ใซใฏ3ใคใฎใƒชใƒณใ‚ดใŒใ‚ใ‚Šใ€4ไบบใฎใŠๅฎขใ•ใ‚“ใŒๆฅใพใ—ใŸใ€‚") == [3, 4] assert candidate("ไปŠๆ—ฅใฏ5ๆœˆ10ๆ—ฅใงใ€ๅˆๅพŒ2ๆ™‚30ๅˆ†ใซๅง‹ใพใ‚Šใพใ™ใ€‚") == [5, 10, 2, 30] assert candidate("2023ๅนดใฏ็‰นๅˆฅใชๅนดใงใ™ใ€‚") == [2023] assert candidate("10ไบบใฎๅ‚ๅŠ ่€…ใจ1000ๆžšใฎใƒใ‚ฑใƒƒใƒˆใŒใ‚ใ‚Šใพใ™ใ€‚") == [10, 1000] assert candidate("็ตๆžœใฏ3-2ใงๅ‹ๅˆฉใ—ใพใ—ใŸ๏ผ") == [3, 2] assert candidate("ๆ–‡็ซ ใซๆ•ฐๅ€คใŒใ‚ใ‚Šใพใ›ใ‚“ใ€‚") == []
extract_numbers_from_text
en/91
def sort_in_japanese_order(words: list) -> list: """ Sorts the input word list in alphabetical order. argument: words (list): word list to be sorted Return value: list: list of words sorted alphabetically Execution example: >>> sort_in_japanese_order(["ใ•ใใ‚‰", "ใ‚ใŠใ„", "ใใ"]) ['ใ‚ใŠใ„', 'ใใ', 'ใ•ใใ‚‰'] """
return sorted(words, key=lambda word: ''.join(chr(ord(c)) for c in word))
def check(candidate): assert candidate(["ใ•ใใ‚‰", "ใ‚ใŠใ„", "ใใ"]) == ["ใ‚ใŠใ„", "ใใ", "ใ•ใใ‚‰"] assert candidate(["ใ†ใฟ", "ใˆใ", "ใ‚ใ‚"]) == ["ใ‚ใ‚", "ใ†ใฟ", "ใˆใ"] assert candidate(["ใ‚ใ•ใฒ", "ใ‚ใ‹ใ‚Š", "ใ‚ใ„"]) == ["ใ‚ใ„", "ใ‚ใ‹ใ‚Š", "ใ‚ใ•ใฒ"] assert candidate(["ใ‚ซใ‚ฟใ‚ซใƒŠ", "ใฒใ‚‰ใŒใช", "ใ‹ใ‚“ใ˜"]) == ["ใ‹ใ‚“ใ˜", "ใฒใ‚‰ใŒใช", "ใ‚ซใ‚ฟใ‚ซใƒŠ"] assert candidate(["ใ‚ใ„", "ใ†ใŸ", "ใˆใฎใ"]) == ["ใ‚ใ„", "ใ†ใŸ", "ใˆใฎใ"] assert candidate(["ใ‚ใ‹ใ‚Š"]) == ["ใ‚ใ‹ใ‚Š"]
sort_in_japanese_order
en/92
def is_matching_iroha_song(text: str) -> bool: """ A function that determines whether the given string completely matches the Iroha song. Ignore spaces and line breaks in the input string. Full text of the Iroha song (check for matches, ignoring spaces and line breaks): ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆ ใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™ example: >>> is_matching_iroha_song("ใ„ใ‚ใฏใซใปใธใจ ใกใ‚Šใฌใ‚‹ใ‚’ ใ‚ใ‹ใ‚ˆใŸใ‚Œใ ใคใญใชใ‚‰ใ‚€ ใ†ใ‚ใฎใŠใใ‚„ใพ ใ‘ใตใ“ใˆใฆ ใ‚ใ•ใใ‚†ใ‚ใฟใ— ใˆใฒใ‚‚ใ›ใ™") True >>> is_matching_iroha_song("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™") True """
iroha_song = "ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™" cleaned_text = ''.join(char for char in text if char not in ' \n') return cleaned_text == iroha_song
def check(candidate): # ใ„ใ‚ใฏๆญŒใจๅฎŒๅ…จใซไธ€่‡ดใ™ใ‚‹ใ‚ฑใƒผใ‚น assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™") == True # ๆ”น่กŒใ‚„ใ‚นใƒšใƒผใ‚นใŒๅซใพใ‚Œใ‚‹ใŒใ€ใ„ใ‚ใฏๆญŒใฎ้ †็•ชใŒๆญฃใ—ใ„ใ‚ฑใƒผใ‚น assert candidate("ใ„ใ‚ใฏใซใปใธใจ ใกใ‚Šใฌใ‚‹ใ‚’ ใ‚ใ‹ใ‚ˆใŸใ‚Œใ ใคใญใชใ‚‰ใ‚€ ใ†ใ‚ใฎใŠใใ‚„ใพ ใ‘ใตใ“ใˆใฆ ใ‚ใ•ใใ‚†ใ‚ใฟใ— ใˆใฒใ‚‚ใ›ใ™") == True assert candidate("ใ„ใ‚ใฏใซใปใธใจ\nใกใ‚Šใฌใ‚‹ใ‚’\nใ‚ใ‹ใ‚ˆใŸใ‚Œใ\nใคใญใชใ‚‰ใ‚€\nใ†ใ‚ใฎใŠใใ‚„ใพ\nใ‘ใตใ“ใˆใฆ\nใ‚ใ•ใใ‚†ใ‚ใฟใ—\nใˆใฒใ‚‚ใ›ใ™") == True assert candidate(" ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™ ") == True # 1ๆ–‡ๅญ—ใ ใ‘็•ฐใชใ‚‹ใ‚ฑใƒผใ‚น assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ„ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™") == False assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›") == False assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™ใ™") == False # ้€”ไธญใงๅคงใใชๅค‰ๆ›ดใŒใ‚ใ‚‹ใ‚ฑใƒผใ‚น assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใ‚ใ‚ใ‚ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™") == False assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’ใ‚ใ‹ใ‚ˆใŸใ‚Œใใคใญใชใ‚‰ใ‚€ใ†ใ‚ใฎใŠใใ‚„ใพใ‘ใตใ“ใˆใฆใ‚ใ•ใใ‚†ใ‚ใฟใ—ใˆใฒใ‚‚ใ›ใ™123") == False # ๅฎŒๅ…จใซ็•ฐใชใ‚‹ใ‚ฑใƒผใ‚น assert candidate("") == False assert candidate("ใ‚ใ„ใ†ใˆใŠใ‹ใใใ‘ใ“") == False assert candidate("ใ„ใ‚ใฏใซใปใธใจใกใ‚Šใฌใ‚‹ใ‚’") == False
is_matching_iroha_song
en/93
def validate_aiueo_poem(prefix: str, poem: list) -> bool: """ A function that determines whether each line of an essay begins with the specified prefix character string. Args: prefix (str): The first character string of the AIUEO composition (any character string). poem (list): A list of Aiueo essays. Returns: bool: True if all lines are correct, False otherwise. example: >>> validate_aiueo_poem("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‹ใ—"]) True >>> validate_aiueo_poem("ใ•ใ—ใ™ใ›ใ", ["ใ•: ใ•ใใ‚‰", "ใ—: ใ—ใ‚", "ใ™: ใ™ใ„ใ‹", "ใ›: ใ›ใฟ", "ใ: ใใ‚‰"]) True >>> validate_aiueo_poem("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ•ใใ‚‰", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‹ใ—"]) False """
if len(prefix) != len(poem): return False for i, line in enumerate(poem): if not line.startswith(f"{prefix[i]}: {prefix[i]}"): return False return True
def check(candidate): # ๆญฃใ—ใ„ใ‚ใ„ใ†ใˆใŠไฝœๆ–‡ใฎใƒใ‚งใƒƒใ‚ฏ assert candidate("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‹ใ—"]) == True assert candidate("ใ•ใ—ใ™ใ›ใ", ["ใ•: ใ•ใใ‚‰", "ใ—: ใ—ใ‚", "ใ™: ใ™ใ„ใ‹", "ใ›: ใ›ใฟ", "ใ: ใใ‚‰"]) == True assert candidate("ใŸใกใคใฆใจ", ["ใŸ: ใŸใฌใ", "ใก: ใกใ‹", "ใค: ใคใ", "ใฆ: ใฆใŒใฟ", "ใจ: ใจใ‘ใ„"]) == True # ่ชคใฃใŸใ‚ใ„ใ†ใˆใŠไฝœๆ–‡ใฎใƒใ‚งใƒƒใ‚ฏ assert candidate("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ•ใใ‚‰", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‹ใ—"]) == False assert candidate("ใ‹ใใใ‘ใ“", ["ใ‹: ใ‹ใ‚", "ใ: ใใฎใ“", "ใ: ใใ‚‚", "ใ‘: ใ‘ใ„ใ“", "ใ“: ใ“ใญใ“"]) == True assert candidate("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‚‚ใก"]) == True assert candidate("ใชใซใฌใญใฎ", ["ใช: ใชใ™", "ใซ: ใซใ‚“ใ˜ใ‚“", "ใฌ: ใฌใฎ", "ใญ: ใญใ“", "ใฎ: ใฎใง"]) == True # ๅขƒ็•Œใ‚ฑใƒผใ‚นใฎใƒใ‚งใƒƒใ‚ฏ assert candidate("ใ‚", ["ใ‚: ใ‚ใ•"]) == True assert candidate("ใ‚", ["ใ‚: ใ•ใใ‚‰"]) == False assert candidate("ใ‚ใ„", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ"]) == True assert candidate("ใ‚ใ„", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใ‚“ใ“"]) == True assert candidate("ใ‚ใ„", ["ใ‚: ใ„ใ‚“ใ“", "ใ„: ใ„ใฌ"]) == False # ็•ฐใชใ‚‹้•ทใ•ใฎใƒใ‚งใƒƒใ‚ฏ assert candidate("ใ‚ใ„ใ†ใˆใŠ", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ"]) == False assert candidate("ใ‚ใ„ใ†", ["ใ‚: ใ‚ใ•", "ใ„: ใ„ใฌ", "ใ†: ใ†ใฟ", "ใˆ: ใˆใณ", "ใŠ: ใŠใ‹ใ—"]) == False
validate_aiueo_poem
en/94
def contains_major_river(text: str) -> bool: """ Determines whether text contains the name of one of Japan's three major rivers. Japan's three major rivers are "ไฟกๆฟƒๅท", "ๅˆฉๆ นๅท", and "็Ÿณ็‹ฉๅท". argument: text (str): Character string to be evaluated. Return value: bool: True if any of the three major rivers is included, False if not. """
major_rivers = ["ไฟกๆฟƒๅท", "ๅˆฉๆ นๅท", "็Ÿณ็‹ฉๅท"] return any(river in text for river in major_rivers)
def check(candidate): assert candidate("ๆ˜จๆ—ฅใฏไฟกๆฟƒใซ่กŒใใพใ—ใŸใ€‚") == False assert candidate("ๅˆฉๆ นใฎๆตๅŸŸใฏๅบƒใ„ใงใ™ใญใ€‚") == False assert candidate("็Ÿณ็‹ฉๅœฐๆ–นใฏ้›ชใŒๅคšใ„ใงใ™ใ€‚") == False assert candidate("ไฟกๆฟƒๅทใฏๆ—ฅๆœฌๆœ€้•ทใฎๅทใงใ™ใ€‚") == True assert candidate("ใ“ใฎๅœฐๅŸŸใงใฏๅˆฉๆ นๅทใŒๆœ‰ๅใงใ™ใ€‚") == True assert candidate("็Ÿณ็‹ฉๅทใŒๆตใ‚Œใ‚‹้ขจๆ™ฏใฏ็พŽใ—ใ„ใ€‚") == True assert candidate("ๆ—ฅๆœฌใซใฏ็พŽใ—ใ„ๅทใŒๅคšใ„ใ€‚") == False assert candidate("ๅŒ—ๆตท้“ใซใฏๅคšใใฎๅทใŒๆตใ‚Œใฆใ„ใพใ™ใ€‚") == False
contains_major_river
en/95
def extract_repeated_words(words: list) -> list: """ A function that extracts only words in which the same string is repeated twice from a list of strings. Args: words (list): list of strings Returns: list: list containing only words that are repeated twice example: >>> extract_repeated_words(['ใ„ใ‚ใ„ใ‚', 'ใŸใณใŸใณ', 'ใ‚ใ‹ใ‚ใŠ', 'abcabc', 'abcd', 'ใฉใใฉใ']) ['ใ„ใ‚ใ„ใ‚', 'ใŸใณใŸใณ', 'abcabc', 'ใฉใใฉใ'] """
result = [word for word in words if len(word) % 2 == 0 and word[:len(word)//2] == word[len(word)//2:]] return result
def check(candidate): assert candidate(['ใ„ใ‚ใ„ใ‚', 'ใŸใณใŸใณ', 'ใ‚ใ‹ใ‚ใŠ', 'ใ‹ใใ‹ใ', 'ใฉใใฉใ', 'ใฒใ‚‹ใฒใ‚‹', 'ใญใ‚‹ใญใ‚‹']) == ['ใ„ใ‚ใ„ใ‚', 'ใŸใณใŸใณ', 'ใ‹ใใ‹ใ', 'ใฉใใฉใ', 'ใฒใ‚‹ใฒใ‚‹', 'ใญใ‚‹ใญใ‚‹'] assert candidate(['ใ‚ใ‹ใ‚ใŠ', 'ใ—ใ‚ใใ‚', 'ใใ‚ใ—ใ‚', 'ใ‚ใŠใ‚ใŠ']) == ['ใ‚ใŠใ‚ใŠ'] assert candidate(['ใ‚ใ„ใ‚ใ„', 'ใ„ใ„ใ†ใ†', 'ใ†ใˆใ†ใˆ', 'ใˆใŠใˆใŠ', 'ใ‹ใใ‹ใ']) == ['ใ‚ใ„ใ‚ใ„', 'ใ†ใˆใ†ใˆ', 'ใˆใŠใˆใŠ', 'ใ‹ใใ‹ใ'] assert candidate(['ใ‚ใ•ใ‚ใ•', 'ใฒใ‚‹ใฒใ‚‹', 'ใ‚ˆใ‚‹ใ‚ˆใ‚‹', 'ใฐใ‚“ใฐใ‚“']) == ['ใ‚ใ•ใ‚ใ•', 'ใฒใ‚‹ใฒใ‚‹', 'ใ‚ˆใ‚‹ใ‚ˆใ‚‹', 'ใฐใ‚“ใฐใ‚“'] assert candidate(['ใดใ‹ใดใ‹', 'ใ“ใ‚ใ“ใ‚', 'ใ™ในใ™ใน', 'ใคใ‚„ใคใ‚„']) == ['ใดใ‹ใดใ‹', 'ใ“ใ‚ใ“ใ‚', 'ใ™ในใ™ใน', 'ใคใ‚„ใคใ‚„'] assert candidate(['ใตใ‚ใตใ‚', 'ใ‚‚ใ“ใ‚‚ใ“', 'ใ•ใ‚‰ใ•ใ‚‰', 'ใคใ‚‹ใคใ‚‹', 'ใ”ใ‚ใ”ใ‚']) == ['ใตใ‚ใตใ‚', 'ใ‚‚ใ“ใ‚‚ใ“', 'ใ•ใ‚‰ใ•ใ‚‰', 'ใคใ‚‹ใคใ‚‹', 'ใ”ใ‚ใ”ใ‚'] assert candidate(['ใใ‚‹ใใ‚‹', 'ใพใ‚‹ใพใ‚‹', 'ใใ‚‹ใใ‚‹', 'ใฆใใฆใ']) == ['ใใ‚‹ใใ‚‹', 'ใพใ‚‹ใพใ‚‹', 'ใใ‚‹ใใ‚‹', 'ใฆใใฆใ'] assert candidate(['ใฏใ‚‰ใฏใ‚‰', 'ใฉใใฉใ', 'ใ‚ใใ‚ใ', 'ใใ‚ใใ‚', 'ใฒใ‚„ใฒใ‚„']) == ['ใฏใ‚‰ใฏใ‚‰', 'ใฉใใฉใ', 'ใ‚ใใ‚ใ', 'ใใ‚ใใ‚', 'ใฒใ‚„ใฒใ‚„']
extract_repeated_words
en/96
def get_hiragana(key: int, presses: int) -> str: """ Returns hiragana depending on the phone's key and number of presses. argument: key (int): Pressed key number (0-9). presses (int): Number of key presses (1 or more). Return value: str: Corresponding Hiragana character. """
key_map = { 1: ["ใ‚", "ใ„", "ใ†", "ใˆ", "ใŠ"], 2: ["ใ‹", "ใ", "ใ", "ใ‘", "ใ“"], 3: ["ใ•", "ใ—", "ใ™", "ใ›", "ใ"], 4: ["ใŸ", "ใก", "ใค", "ใฆ", "ใจ"], 5: ["ใช", "ใซ", "ใฌ", "ใญ", "ใฎ"], 6: ["ใฏ", "ใฒ", "ใต", "ใธ", "ใป"], 7: ["ใพ", "ใฟ", "ใ‚€", "ใ‚", "ใ‚‚"], 8: ["ใ‚„", "ใ‚†", "ใ‚ˆ"], 9: ["ใ‚‰", "ใ‚Š", "ใ‚‹", "ใ‚Œ", "ใ‚"], 0: ["ใ‚", "ใ‚’", "ใ‚“"], } characters = key_map[key] index = (presses - 1) % len(characters) return characters[index]
def check(candidate): key_map = { 1: ["ใ‚", "ใ„", "ใ†", "ใˆ", "ใŠ"], 2: ["ใ‹", "ใ", "ใ", "ใ‘", "ใ“"], 3: ["ใ•", "ใ—", "ใ™", "ใ›", "ใ"], 4: ["ใŸ", "ใก", "ใค", "ใฆ", "ใจ"], 5: ["ใช", "ใซ", "ใฌ", "ใญ", "ใฎ"], 6: ["ใฏ", "ใฒ", "ใต", "ใธ", "ใป"], 7: ["ใพ", "ใฟ", "ใ‚€", "ใ‚", "ใ‚‚"], 8: ["ใ‚„", "ใ‚†", "ใ‚ˆ"], 9: ["ใ‚‰", "ใ‚Š", "ใ‚‹", "ใ‚Œ", "ใ‚"], 0: ["ใ‚", "ใ‚’", "ใ‚“"], } for key, characters in key_map.items(): for presses in range(1, len(characters) * 2 + 1): # ๅ„ใ‚ญใƒผใฎใƒชใ‚นใƒˆ้•ทใฎ2ๅ€ใพใงใƒ†ใ‚นใƒˆ expected = characters[(presses - 1) % len(characters)] result = get_hiragana(key, presses) assert result == expected
get_hiragana
en/97
def romaji_to_hiragana(romaji: str) -> str: """ Convert Hepburn-style romaji to hiragana. argument: romaji (str): Romaji to be converted (50 sounds only) Return value: str: String converted to hiragana Execution example: >>> romaji_to_hiragana("konnichiha") 'ใ“ใ‚“ใซใกใฏ' >>> romaji_to_hiragana("sushi") 'ใ™ใ—' """
romaji_map = { "a": "ใ‚", "i": "ใ„", "u": "ใ†", "e": "ใˆ", "o": "ใŠ", "ka": "ใ‹", "ki": "ใ", "ku": "ใ", "ke": "ใ‘", "ko": "ใ“", "sa": "ใ•", "shi": "ใ—", "su": "ใ™", "se": "ใ›", "so": "ใ", "ta": "ใŸ", "chi": "ใก", "tsu": "ใค", "te": "ใฆ", "to": "ใจ", "na": "ใช", "ni": "ใซ", "nu": "ใฌ", "ne": "ใญ", "no": "ใฎ", "ha": "ใฏ", "hi": "ใฒ", "fu": "ใต", "he": "ใธ", "ho": "ใป", "ma": "ใพ", "mi": "ใฟ", "mu": "ใ‚€", "me": "ใ‚", "mo": "ใ‚‚", "ya": "ใ‚„", "yu": "ใ‚†", "yo": "ใ‚ˆ", "ra": "ใ‚‰", "ri": "ใ‚Š", "ru": "ใ‚‹", "re": "ใ‚Œ", "ro": "ใ‚", "wa": "ใ‚", "wo": "ใ‚’", "n": "ใ‚“", } i = 0 result = [] while i < len(romaji): for length in (3, 2, 1): if romaji[i:i+length] in romaji_map: result.append(romaji_map[romaji[i:i+length]]) i += length break else: result.append(romaji[i]) i += 1 return ''.join(result)
def check(candidate): assert candidate("aiueo") == "ใ‚ใ„ใ†ใˆใŠ" assert candidate("akasatana") == "ใ‚ใ‹ใ•ใŸใช" assert candidate("hamayarawa") == "ใฏใพใ‚„ใ‚‰ใ‚" assert candidate("konnichiha") == "ใ“ใ‚“ใซใกใฏ" assert candidate("sushi") == "ใ™ใ—" assert candidate("satsumaimo") == "ใ•ใคใพใ„ใ‚‚"
romaji_to_hiragana
en/98
def classify_japanese_characters(text: str) -> dict: """ Classifies the input string into kanji, hiragana, katakana, and other characters and returns the number of each character. argument: text (str): string to process Return value: dict: Classification results for each character type (e.g. {'ๆผขๅญ—': 3, 'ใฒใ‚‰ใŒใช': 5, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 2, 'ใใฎไป–': 4}) Execution example: >>> classify_japanese_characters("ไปŠๆ—ฅใฏๆ™ดใ‚Œใงใ™ใ€‚") {'ๆผขๅญ—': 3, 'ใฒใ‚‰ใŒใช': 4, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 0, 'ใใฎไป–': 1} """
result = {'ๆผขๅญ—': 0, 'ใฒใ‚‰ใŒใช': 0, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 0, 'ใใฎไป–': 0} for char in text: if '\u4e00' <= char <= '\u9fff': result['ๆผขๅญ—'] += 1 elif '\u3040' <= char <= '\u309f': result['ใฒใ‚‰ใŒใช'] += 1 elif '\u30a0' <= char <= '\u30ff': result['ใ‚ซใ‚ฟใ‚ซใƒŠ'] += 1 else: result['ใใฎไป–'] += 1 return result
def check(candidate): assert candidate("ไปŠๆ—ฅใฏๆ™ดใ‚Œใงใ™ใ€‚") == {'ๆผขๅญ—': 3, 'ใฒใ‚‰ใŒใช': 4, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 0, 'ใใฎไป–': 1} assert candidate("ใ‚ใ„ใ†ใˆใŠใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == {'ๆผขๅญ—': 0, 'ใฒใ‚‰ใŒใช': 5, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 5, 'ใใฎไป–': 0} assert candidate("ไฝ“่‚ฒใฎๆŽˆๆฅญใงใฏใ‚ตใƒƒใ‚ซใƒผใ‚’ใ‚„ใ‚Šใพใ™ใ€‚ไปŠๆ—ฅใ‚‚ๅ…ƒๆฐ—ไธ€ๆฏใซ้ ‘ๅผตใ‚Šใพใ—ใ‚‡ใ†ใ€‚") == {'ๆผขๅญ—': 12, 'ใฒใ‚‰ใŒใช': 15, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 4, 'ใใฎไป–': 2} assert candidate("ABC123!@#ๆผขๅญ—ใฒใ‚‰ใŒใชใ‚ซใ‚ฟใ‚ซใƒŠ") == {'ๆผขๅญ—': 2, 'ใฒใ‚‰ใŒใช': 4, 'ใ‚ซใ‚ฟใ‚ซใƒŠ': 4, 'ใใฎไป–': 9}
classify_japanese_characters
en/99
def can_create_henohenomoheji(text: str) -> bool: """ By rearranging the given string `text`, determine whether it is possible to create ``Henohenomoheji''. Returns True if it can be created, False otherwise. >>> can_create_heno_heno_moheji("ใธใฎใธใฎใ‚‚ใธใ˜") True >>> can_create_heno_heno_moheji("ใธใธใธใฎใฎใ‚‚ใ˜") True >>> can_create_heno_heno_moheji("ใธใฎใธใฎใธใฎใธ") False """
required_characters = {"ใธ": 3, "ใฎ": 2, "ใ‚‚": 1, "ใ˜": 1} for char, count in required_characters.items(): if text.count(char) < count: return False return True
def check(candidate): assert candidate("ใธใฎใธใฎใ‚‚ใธใ˜") == True assert candidate("ใธใธใธใฎใฎใ‚‚ใ˜") == True assert candidate("ใธใฎใธใฎใธใฎใธ") == False assert candidate("ใธใฎใธใธใ‚‚ใ˜ใฎ") == True assert candidate("ใธใธใธใ‚‚ใ‚‚ใ‚‚ใ˜") == False assert candidate("ใฏใฒใตใธใปใฎใป") == False
can_create_henohenomoheji
README.md exists but content is empty.
Downloads last month
62