Dataset Viewer
Auto-converted to Parquet
task_id
stringlengths
4
6
category
stringclasses
8 values
subcategory
stringclasses
13 values
prompt
stringlengths
152
1.03k
canonical_solution
stringlengths
18
1.32k
test
stringlengths
135
1.21k
entry_point
stringlengths
2
37
EN/0
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/1
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/2
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/3
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/4
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def check_season(seasons: list, target: str) -> str: """ Determines whether the given season is included in the given list. argument: seasons (list): list of seasons (e.g. ['Spring', 'Summer', 'Autumn', 'Winter']) target (str): Season to judge (e.g. 'summer') Return value: str: Returns "ๅซใพใ‚Œใฆใ„ใ‚‹" if the season is included, otherwise returns "ๅซใพใ‚Œใฆใ„ใชใ„" Usage example: >>> check_season(['ๆ˜ฅ', 'ๅค', '็ง‹', 'ๅ†ฌ'], 'ๅค') 'ๅซใพใ‚Œใฆใ„ใ‚‹' >>> check_season(['ๆ˜ฅ', '็ง‹'], 'ๅค') 'ๅซใพใ‚Œใฆใ„ใชใ„' >>> check_season([], 'ๅ†ฌ') 'ๅซใพใ‚Œใฆใ„ใชใ„' >>> check_season(['ๅค'], 'ๅค') 'ๅซใพใ‚Œใฆใ„ใ‚‹' """
if target in seasons: return 'ๅซใพใ‚Œใฆใ„ใ‚‹' return 'ๅซใพใ‚Œใฆใ„ใชใ„'
def check(candidate): assert candidate(['ๆ˜ฅ', 'ๅค', '็ง‹', 'ๅ†ฌ'], 'ๅค') == 'ๅซใพใ‚Œใฆใ„ใ‚‹' assert candidate(['ๆ˜ฅ', '็ง‹'], '็ง‹') == 'ๅซใพใ‚Œใฆใ„ใ‚‹' assert candidate(['ๅค'], 'ๅค') == 'ๅซใพใ‚Œใฆใ„ใ‚‹' assert candidate(['ๆ˜ฅ', '็ง‹'], 'ๅค') == 'ๅซใพใ‚Œใฆใ„ใชใ„' assert candidate(['ๅ†ฌ'], '็ง‹') == 'ๅซใพใ‚Œใฆใ„ใชใ„' assert candidate(['ใ‚', 'ใ„', 'ใ†', 'ใˆ', 'ใŠ'], '็ง‹') == 'ๅซใพใ‚Œใฆใ„ใชใ„' assert candidate(['ๅค'], 'ๅ†ฌ') == 'ๅซใพใ‚Œใฆใ„ใชใ„'
check_season
EN/5
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def count_particles(text: str) -> int: """ Create a function that counts the number of occurrences of particles (``ga'', ``no'', ``ha'', ``wo'', and ``ni'') in Japanese sentences. argument: text (str): Japanese text Return value: int: Number of particle occurrences Usage example: >>> count_particles("็งใฏๅญฆๆ กใซ่กŒใใพใ™ใ€‚") 2 """
particles = ['ใŒ', 'ใฎ', 'ใฏ', 'ใ‚’', 'ใซ'] count = 0 for particle in particles: count += text.count(particle) return count
def check(candidate): assert candidate("็งใฏๅญฆๆ กใซ่กŒใใพใ™ใ€‚") == 2 assert candidate("ไปŠๆ—ฅใฎๅคฉๆฐ—ใฏ่‰ฏใ„ใงใ™ใ€‚") == 2 assert candidate("AIใฏไธ–็•Œใ‚’ๅค‰ใˆใ‚‹ใ€‚") == 2 assert candidate("ใŒใŒใŒใฎใฎใฏใฏใ‚’ใ‚’") == 9 assert candidate("ใ“ใ‚ŒใฏๅŠฉ่ฉžใŒๅซใพใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚") == 2
count_particles
EN/6
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
from typing import List, Dict def count_emoji_occurrences(text: str, emoji_list: List[str]) -> Dict[str, int]: """ Counts the number of occurrences of an emoji in the given text, based on the specified list of emoji. argument: text (str): input text emoji_list (List[str]): List of emojis to count Return value: Dict[str, int]: Dictionary indicating the number of occurrences of each emoji Usage example: >>> count_emoji_occurrences("๐ŸŽ๐Ÿ๐ŸŽ๐Ÿ‡๐Ÿ‰๐Ÿ‰๐ŸŽ", ["๐ŸŽ", "๐Ÿ‰", "๐Ÿ‡"]) {'๐ŸŽ': 3, '๐Ÿ‰': 2, '๐Ÿ‡': 1} >>> count_emoji_occurrences("๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚", ["๐ŸŽ‰", "๐ŸŽ‚", "๐ŸŽˆ"]) {'๐ŸŽ‰': 3, '๐ŸŽ‚': 4, '๐ŸŽˆ': 0} >>> count_emoji_occurrences("๐ŸŒŸโœจ๐Ÿ’ซ๐ŸŒŸ๐ŸŒŸโœจ", ["๐ŸŒŸ", "โœจ", "๐Ÿ’ซ"]) {'๐ŸŒŸ': 3, 'โœจ': 2, '๐Ÿ’ซ': 1} """
emoji_counts = {emoji: 0 for emoji in emoji_list} # ๆŒ‡ๅฎšใ•ใ‚ŒใŸ็ตตๆ–‡ๅญ—ใ‚’ใ™ในใฆ0ใงๅˆๆœŸๅŒ– for char in text: if char in emoji_counts: emoji_counts[char] += 1 return emoji_counts
def check(candidate): assert candidate("๐ŸŽ๐Ÿ๐ŸŽ๐Ÿ‡๐Ÿ‰๐Ÿ‰๐ŸŽ", ["๐ŸŽ", "๐Ÿ‰", "๐Ÿ‡"]) == {'๐ŸŽ': 3, '๐Ÿ‰': 2, '๐Ÿ‡': 1} assert candidate("๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚", ["๐ŸŽ‰", "๐ŸŽ‚", "๐ŸŽˆ"]) == {'๐ŸŽ‰': 3, '๐ŸŽ‚': 4, '๐ŸŽˆ': 0} assert candidate("๐ŸŒŸโœจ๐Ÿ’ซ๐ŸŒŸ๐ŸŒŸโœจ", ["๐ŸŒŸ", "โœจ", "๐Ÿ’ซ"]) == {'๐ŸŒŸ': 3, 'โœจ': 2, '๐Ÿ’ซ': 1} assert candidate("", ["๐ŸŽ‰", "๐ŸŽ‚", "๐ŸŽˆ"]) == {'๐ŸŽ‰': 0, '๐ŸŽ‚': 0, '๐ŸŽˆ': 0} assert candidate("๐ŸŽ๐Ÿ๐ŸŽ๐Ÿ‡๐Ÿ‰๐Ÿ‰๐ŸŽ", ["๐ŸŽ", "๐Ÿ", "๐Ÿ‡", "๐Ÿ‰", "๐ŸŒ"]) == {'๐ŸŽ': 3, '๐Ÿ': 1, '๐Ÿ‡': 1, '๐Ÿ‰': 2, '๐ŸŒ': 0} assert candidate("๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚๐ŸŽ‚", ["๐ŸŽ‰", "๐ŸŽ‚", "๐ŸŽˆ"]) == {'๐ŸŽ‰': 0, '๐ŸŽ‚': 5, '๐ŸŽˆ': 0} assert candidate("๐ŸŽ๐ŸŽ๐ŸŽ", ["๐ŸŽ"]) == {'๐ŸŽ': 3} assert candidate("๐Ÿ•๐Ÿ•๐Ÿ”๐Ÿ”๐ŸŸ๐ŸŸ", ["๐Ÿ•", "๐Ÿ”", "๐ŸŸ", "๐ŸŒญ"]) == {'๐Ÿ•': 2, '๐Ÿ”': 2, '๐ŸŸ': 2, '๐ŸŒญ': 0} assert candidate("๐Ÿฃ๐Ÿฃ๐Ÿฃ๐Ÿฃ", ["๐Ÿฃ", "๐Ÿš", "๐Ÿ›"]) == {'๐Ÿฃ': 4, '๐Ÿš': 0, '๐Ÿ›': 0} assert candidate("๐Ÿ’–๐Ÿ’–๐Ÿ’–๐Ÿ’–๐Ÿ’–", ["๐Ÿ’–", "๐Ÿ’—", "๐Ÿ’•"]) == {'๐Ÿ’–': 5, '๐Ÿ’—': 0, '๐Ÿ’•': 0}
count_emoji_occurrences
EN/7
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
from typing import List def parse_taiko_rhythm(rhythm_string: str) -> List[int]: """ Parses the string representing the Japanese drum rhythm, converts each rhythm symbol to the corresponding number of beats, and returns it as a list. The Japanese drum rhythm consists of the following symbols: - 'ใƒ‰ใƒณ': 4 beats - 'ใƒ‰ใ‚ณ': 2 beats - 'ใƒ„ใ‚ฏ': 1 beat input: rhythm_string (str): A string of characters delimited by spaces that represents the rhythm of Japanese drums output: List[int]: List of each rhythm symbol converted to the corresponding number of beats Usage example: >>> parse_taiko_rhythm('ใƒ‰ใƒณ ใƒ‰ใ‚ณ ใƒ„ใ‚ฏ ใƒ‰ใ‚ณ ใƒ‰ใƒณ') [4, 2, 1, 2, 4] >>> parse_taiko_rhythm('ใƒ‰ใ‚ณ ใƒ‰ใ‚ณ ใƒ‰ใƒณ ใƒ„ใ‚ฏ ใƒ„ใ‚ฏ ใƒ‰ใƒณ') [2, 2, 4, 1, 1, 4] """
# ใƒชใ‚บใƒ ่จ˜ๅทใจๆ‹ๆ•ฐใฎๅฏพๅฟœ่พžๆ›ธ note_durations = { 'ใƒ‰ใƒณ': 4, 'ใƒ‰ใ‚ณ': 2, 'ใƒ„ใ‚ฏ': 1 } # ๅ…ฅๅŠ›ๆ–‡ๅญ—ๅˆ—ใ‚’็ฉบ็™ฝใงๅˆ†ๅ‰ฒใ—ใ€ๅฏพๅฟœใ™ใ‚‹ๆ‹ๆ•ฐใ‚’ใƒชใ‚นใƒˆใซใ™ใ‚‹ beats = [note_durations[note] for note in rhythm_string.split()] return beats
def check(candidate): assert candidate('ใƒ‰ใƒณ ใƒ‰ใ‚ณ ใƒ„ใ‚ฏ ใƒ‰ใ‚ณ ใƒ‰ใƒณ') == [4, 2, 1, 2, 4] assert candidate('ใƒ‰ใ‚ณ ใƒ‰ใ‚ณ ใƒ‰ใƒณ ใƒ„ใ‚ฏ ใƒ„ใ‚ฏ ใƒ‰ใƒณ') == [2, 2, 4, 1, 1, 4] assert candidate('ใƒ‰ใƒณ ใƒ‰ใƒณ ใƒ‰ใƒณ') == [4, 4, 4] assert candidate('ใƒ„ใ‚ฏ ใƒ„ใ‚ฏ ใƒ„ใ‚ฏ ใƒ„ใ‚ฏ') == [1, 1, 1, 1] assert candidate('ใƒ‰ใ‚ณ ใƒ‰ใƒณ') == [2, 4] assert candidate('ใƒ‰ใƒณ') == [4]
parse_taiko_rhythm
EN/8
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def count_dango(s: str) -> int: """ Count the dango "o" contained in the string s. argument: s (str): string to check Return value: int: number of dumplings Execution example: >>> count_dango("oo-oo-oo-o-") 7 >>> count_dango("oo-o-o-oo-") 6 >>> count_dango("o-o-o-o-o-") 5 """
return s.count('o')
def check(candidate): assert candidate("oo-oo-oo-o-") == 7 assert candidate("oo-o-o-oo-") == 6 assert candidate("o-o-o-o-o-") == 5 assert candidate("ooo-ooo-o-") == 7 assert candidate("o-oo-o-o-") == 5
count_dango
EN/9
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
import re def is_haiku(haiku: str) -> bool: """ Determines whether the given string is in 5-7-5 haiku form. Note: Inputs other than hiragana do not need to be considered. Also, one hiragana character is counted as one sound. argument: haiku (str): Hiragana string separated by spaces for each phrase Return value: bool: True if 5-7-5 format, False otherwise """
parts = haiku.split() if len(parts) != 3: return False syllable_count = [len(re.findall(r'[ใ-ใ‚“]', part)) for part in parts] return syllable_count == [5, 7, 5]
def check(candidate): assert candidate("ใฏใ‚‹ใ‹ใœใ‚„ ใฉใ“ใ‹ใธใจใ‚“ใ  ใตใ†ใ›ใ‚“ใŒ") == True assert candidate("ใตใ‚‹ใ„ใ‘ใ‚„ ใ‹ใ‚ใšใจใณใ“ใ‚€ ใฟใšใฎใŠใจ") == True assert candidate("ใ—ใšใ‘ใ•ใ‚„ ใ„ใ‚ใซใ—ใฟใ„ใ‚‹ ใ›ใฟใฎใ“ใˆ") == True assert candidate("ใชใคใใ•ใ‚„ ใคใ‚ใ‚‚ใฎใฉใ‚‚ใŒ ใ‚†ใ‚ใฎใ‚ใจ") == True assert candidate("ใตใ‚‹ใ„ใ‘ ใ‹ใ‚ใš ใฟใš") == False assert candidate("ใฏใ‚‹ ใ‹ใœใ‚„ ใฉใ“ ใ‹ใธใจใ‚“ ใ ใตใ†ใ› ใ‚“ใŒ") == False assert candidate("ใ‚ใ„ใ†ใˆใŠ ใ‚ใ„ใ†ใˆใŠใ‚ใ„ ใ‚ใ„ใ†ใˆใŠ") == True assert candidate("ใ—ใšใ‘ใ•ใ‚„ ใ„ใ‚ใซใ—ใฟใ„ใ‚‹ ใ›ใฟใฎๅฃฐ") == False assert candidate("ใ“ใ‚“ใซใกใฏ ไธ–็•Œ ใฉใ†ใ‚‚") == False assert candidate("ใ‚ใใฎใ‚ˆใ‚‹") == False assert candidate("ใตใ‚‹ใ„ใ‘ใ‚„ ใ‹ใ‚ใšใจใณใ“ใ‚€ ใฟใšใฎใŠใจใปใ’") == False
is_haiku
EN/10
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/11
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/12
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/13
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/14
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def weight_needed_for_sumo(height: int, current_weight: int) -> tuple: """ From your height and current weight, calculate the amount of weight gain needed to reach the average BMI of a sumo wrestler. 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/15
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/16
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/17
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/18
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/19
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/20
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/21
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/22
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/23
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/24
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/25
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
from typing import List def are_all_kites_high_enough(heights: List[float], threshold: float) -> bool: """ Determine whether the height of all kites is greater than or equal to a threshold. argument: heights (List[float]): Current height of each kite (m) threshold (float): Threshold for flying a kite (m) Return value: bool: True if the height of all kites is greater than or equal to the threshold, otherwise False Execution example: >>> are_all_kites_high_enough([10.0, 12.5, 9.0], 5.0) True >>> are_all_kites_high_enough([3.0, 6.0, 2.0], 5.0) False """
return all(height >= threshold for height in heights)
def check(candidate): assert candidate([10.0, 12.5, 9.0], 5.0) == True assert candidate([3.0, 6.0, 2.0], 5.0) == False assert candidate([7.0, 8.0, 9.0], 6.0) == True assert candidate([3.0, 5.0], 5.0) == False assert candidate([10.0, 10.5, 11.0], 10.0) == True
are_all_kites_high_enough
EN/26
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
from typing import List def karaoke_score_with_grade(target: List[int], actual: List[int]) -> str: """ Calculates the pitch accuracy score in karaoke and assigns grades. Compare the ideal pitch list (target) and the pitch list for singing (actual), Returns a score according to the proportion of matching pitches. Judgment criteria: - S: 90% or more - A: 80% or more but less than 90% - B: 70% or more but less than 80% - C: 60% or more but less than 70% - D: Less than 60% argument: target (List[int]): ideal pitch list actual (List[int]): pitch list when singing Return value: str: Grade based on pitch matching rate (e.g. "Score: 85.0%, Grade: A") """
# ไธ€่‡ดใ—ใฆใ„ใ‚‹้Ÿณ็จ‹ใฎๆ•ฐใ‚’ใ‚ซใ‚ฆใƒณใƒˆ match_count = sum(1 for t, a in zip(target, actual) if t == a) # ใ‚นใ‚ณใ‚ขใ‚’ใƒ‘ใƒผใ‚ปใƒณใƒ†ใƒผใ‚ธใง่จˆ็ฎ— score_percentage = (match_count / len(target)) * 100 # ๆˆ็ธพใ‚’ๅˆคๅฎš if score_percentage >= 90: grade = "S" elif score_percentage >= 80: grade = "A" elif score_percentage >= 70: grade = "B" elif score_percentage >= 60: grade = "C" else: grade = "D" return grade
def check(candidate): assert candidate([60, 62, 64, 65, 67], [60, 62, 64, 65, 67]) == "S" assert candidate([60, 62, 64, 65, 67], [60, 62, 63, 65, 67]) == "A" assert candidate([60, 62, 64, 65, 67, 68, 69], [60, 61, 64, 64, 67, 68, 69]) == "B" assert candidate([60, 62, 64, 65, 67], [60, 61, 64, 65, 66]) == "C" assert candidate([60, 62, 64, 65, 67], [61, 61, 63, 64, 66]) == "D"
karaoke_score_with_grade
EN/27
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def translate_thank_you(language_code): """ Translate "ใ‚ใ‚ŠใŒใจใ†" by specifying the language code. Args: language_code (str): ISO 639-1 language code (Example: "ja", "en", "ru", "fr", "ko", "es", "de", "it", "zh", "ar") Returns: str: Translation of "ใ‚ใ‚ŠใŒใจใ†" into the specified language. """
translations = { "ja": "ใ‚ใ‚ŠใŒใจใ†", # ๆ—ฅๆœฌ่ชž "en": "Thank you", # ่‹ฑ่ชž "ru": "ะกะฟะฐัะธะฑะพ", # ใƒญใ‚ทใ‚ข่ชž "fr": "Merci", # ใƒ•ใƒฉใƒณใ‚น่ชž "ko": "๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค", # ้Ÿ“ๅ›ฝ่ชž "es": "Gracias", # ใ‚นใƒšใ‚คใƒณ่ชž "de": "Danke", # ใƒ‰ใ‚คใƒ„่ชž "it": "Grazie", # ใ‚คใ‚ฟใƒชใ‚ข่ชž "zh": "่ฐข่ฐข", # ไธญๅ›ฝ่ชž "ar": "ุดูƒุฑุง", # ใ‚ขใƒฉใƒ“ใ‚ข่ชž } return translations.get(language_code)
def check(candidate): assert candidate("ja") == "ใ‚ใ‚ŠใŒใจใ†" assert candidate("en") == "Thank you" assert candidate("es") == "Gracias" assert candidate("fr") == "Merci" assert candidate("de") == "Danke" assert candidate("it") == "Grazie" assert candidate("zh") == "่ฐข่ฐข" assert candidate("ko") == "๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค" assert candidate("ar") == "ุดูƒุฑุง" assert candidate("ru") == "ะกะฟะฐัะธะฑะพ"
translate_thank_you
EN/28
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def check_ichiju_sansai(menu): """ Determine whether the menu satisfies the format of one soup and three dishes. argument: menu (dict): menu {"ๆฑ็‰ฉ": list of str, "ไธป่œ": list of str, "ๅ‰ฏ่œ": list of str} Return: bool: True if it satisfies the format of one soup and three dishes, otherwise False >>> check_ichiju_sansai({"ๆฑ็‰ฉ": ["ๅ‘ณๅ™Œๆฑ"], "ไธป่œ": ["็„ผใ้ญš"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—", "ๆผฌ็‰ฉ"]}) True >>> check_ichiju_sansai({"ๆฑ็‰ฉ": ["ๅ‘ณๅ™Œๆฑ"], "ไธป่œ": ["็„ผใ้ญš"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—"]}) False """
if set(menu.keys()) != {"ๆฑ็‰ฉ", "ไธป่œ", "ๅ‰ฏ่œ"}: return False if len(menu["ๆฑ็‰ฉ"]) == 1 and len(menu["ไธป่œ"]) == 1 and len(menu["ๅ‰ฏ่œ"]) == 2: return True return False
def check(candidate): assert candidate({"ๆฑ็‰ฉ": ["ๅ‘ณๅ™Œๆฑ"], "ไธป่œ": ["็„ผใ้ญš"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—", "ๆผฌ็‰ฉ"]}) == True assert candidate({"ๆฑ็‰ฉ": ["่ฑšๆฑ"], "ไธป่œ": ["็…ฎ็‰ฉ"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—", "ใƒใƒ†ใƒˆใ‚ตใƒฉใƒ€"]}) == True assert candidate({"ๆฑ็‰ฉ": ["ๅ‘ณๅ™Œๆฑ"], "ไธป่œ": ["็„ผใ้ญš"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—"]}) == False assert candidate({"ๆฑ็‰ฉ": ["ๅ‘ณๅ™Œๆฑ"], "ไธป่œ": ["็„ผใ้ญš"]}) == False assert candidate({"ๆฑ็‰ฉ": [], "ไธป่œ": ["็„ผใ้ญš"], "ๅ‰ฏ่œ": ["ใŠใฒใŸใ—", "ๆผฌ็‰ฉ"]}) == False
check_ichiju_sansai
EN/29
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/30
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def calculate_congestion_rate(max_capacity: int, current_passengers: int) -> float: """ Calculate the congestion rate of the train. Arguments: max_capacity (int): Train capacity (maximum capacity) current_passengers (int): Number of passengers currently on board Return: 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/31
้ขจ็ฟ’
้ขจ็ฟ’
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/32
้ขจ็ฟ’
้ขจ็ฟ’
def calculate_remaining_bill(total_bill: int, boss_bills: list, other_members_count: int) -> int: """ A function that splits the 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/33
้ขจ็ฟ’
้ขจ็ฟ’
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/34
้ขจ็ฟ’
้ขจ็ฟ’
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/35
้ขจ็ฟ’
้ขจ็ฟ’
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/36
้ขจ็ฟ’
้ขจ็ฟ’
def is_correct_hinamatsuri_order(dolls: list) -> bool: """ Given the correct order of the dolls for Hinamatsuri, create a function to determine whether the input order is correct. Argument: - dolls (list): the order of the dolls Return: - bool: True if correct, False if incorrect Example: >>> is_correct_hinamatsuri_order(["ใŠๅ†…่ฃๆง˜", "ใŠ้››ๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "้š่บซ", "ไป•ไธ"]) True >>> is_correct_hinamatsuri_order(["ใŠ้››ๆง˜", "ใŠๅ†…่ฃๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "ไป•ไธ", "้š่บซ"]) False """
correct_order = ["ใŠๅ†…่ฃๆง˜", "ใŠ้››ๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "้š่บซ", "ไป•ไธ"] return dolls == correct_order
def check(candidate): assert candidate(["ใŠๅ†…่ฃๆง˜", "ใŠ้››ๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "้š่บซ", "ไป•ไธ"]) == True assert candidate(["ใŠ้››ๆง˜", "ใŠๅ†…่ฃๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "ไป•ไธ", "้š่บซ"]) == False assert candidate(["ใŠ้››ๆง˜", "ใŠๅ†…่ฃๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "้š่บซ", "ไป•ไธ"]) == False assert candidate(["ใŠๅ†…่ฃๆง˜", "ใŠ้››ๆง˜", "้š่บซ", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "ไป•ไธ"]) == False assert candidate(["ไป•ไธ", "ใŠๅ†…่ฃๆง˜", "ไธ‰ไบบๅฎ˜ๅฅณ", "ไบ”ไบบๅ›ƒๅญ", "ใŠ้››ๆง˜", "้š่บซ"]) == False
is_correct_hinamatsuri_order
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
้ขจ็ฟ’
้ขจ็ฟ’
def is_keigo(text: str) -> bool: """ A function that determines whether the input sentence is honorific language (ending in "ใพใ™" or "ใงใ™"). argument: text (str): Japanese text Return value: bool: Returns True if the sentence is honorific (ending with "ใพใ™" or "ใงใ™"), otherwise returns false. Usage example: >>> is_keigo("็งใฏๅญฆๆ กใซ่กŒใใพใ™ใ€‚") True >>> is_keigo("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใ ใญใ€‚") False >>> is_keigo("ใŠๆ‰‹ไผใ„ใ•ใ›ใฆใ„ใŸใ ใใพใ™ใ€‚") True """
if text.endswith('ใพใ™ใ€‚') or text.endswith('ใงใ™ใ€‚'): return True return False
def check(candidate): assert candidate("็งใฏๅญฆๆ กใซ่กŒใใพใ™ใ€‚") == True assert candidate("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใ ใญใ€‚") == False assert candidate("ใŠๆ‰‹ไผใ„ใ•ใ›ใฆใ„ใŸใ ใใพใ™ใ€‚") == True assert candidate("ๆ˜จๆ—ฅใฎๅคฉๆฐ—ใฏๆ‚ชใ‹ใฃใŸใ€‚") == False assert candidate("ไปŠๆ—ฅใฏๅคฉๆฐ—ใŒใ„ใ„ใงใ™ใ€‚") == True assert candidate("ๅฝผใฏ่ตฐใ‚‹ใฎใŒๆ—ฉใ„ใ€‚") == False assert candidate("AIใฏ้€ฒๅŒ–ใ—ใฆใ„ใพใ™ใ€‚") == True assert candidate("ใ™ใ”ใ„ใญ๏ผ") == False
is_keigo
EN/39
้ขจ็ฟ’
้ขจ็ฟ’
def count_hashi_pair(s: str) -> int: """ Counts the number of chopsticks (two chopsticks make a set) in the string s. Args. s (str): string Return. int: Number of chopsticks Ex. >>> count_hashi_pair(""||-|-|||-"") 3 """
count = s.count("|") return count // 2
def check(candidate): assert candidate("||-|-|||-") == 3 assert candidate("|||-|-|") == 2 assert candidate("-|---|") == 1 assert candidate("|-||-|") == 2 assert candidate("|||||") == 2
count_hashi_pair
EN/40
้ขจ็ฟ’
้ขจ็ฟ’
from typing import List def calculate_total_beans(ages: List[int]) -> int: """ Calculate the number of beans that the whole family will eat. Assume that each family member eats as many beans as their age. argument: ages (List[int]): List of ages of each family member. Return value: int: Number of beans eaten by the whole family (sum of ages). Usage example: >>> calculate_total_beans([10, 15, 20]) 45 >>> calculate_total_beans([5, 8, 13]) 26 """
return sum(ages)
def check(candidate): assert candidate([10, 15, 20]) == 45 assert candidate([5, 8, 13]) == 26 assert candidate([1, 2, 3, 4]) == 10 assert candidate([30, 25, 15]) == 70 assert candidate([7, 6, 5, 4]) == 22
calculate_total_beans
EN/41
้ขจ็ฟ’
้ขจ็ฟ’
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/42
้ขจ็ฟ’
้ขจ็ฟ’
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/43
้ขจ็ฟ’
้ขจ็ฟ’
def convert_to_japanese_time(hour: int, minute: int) -> str: """ A function that converts the time (hour, minute) in 24-hour notation to Japanese notation for AM/PM. argument: hour (int): Time in 24-hour notation (0 <= hour < 24) minute (int): minute (0 <= minute < 60) Return value: str: Japanese notation for AM/PM hours (e.g. "10:30 AM", "2:15 PM") """
if 0 <= hour < 12: # ๅˆๅ‰ meridian = "ๅˆๅ‰" display_hour = hour if hour != 0 else 0 # 0ๆ™‚ใฏใใฎใพใพ0ๆ™‚ else: # ๅˆๅพŒ meridian = "ๅˆๅพŒ" display_hour = hour - 12 if hour != 12 else 12 # 12ๆ™‚ใฏใใฎใพใพ12ๆ™‚ return f"{meridian}{display_hour}ๆ™‚{minute}ๅˆ†"
def check(candidate): assert candidate(0, 0) == 'ๅˆๅ‰0ๆ™‚0ๅˆ†' assert candidate(0, 15) == 'ๅˆๅ‰0ๆ™‚15ๅˆ†' assert candidate(11, 59) == 'ๅˆๅ‰11ๆ™‚59ๅˆ†' assert candidate(12, 0) == 'ๅˆๅพŒ12ๆ™‚0ๅˆ†' assert candidate(12, 30) == 'ๅˆๅพŒ12ๆ™‚30ๅˆ†' assert candidate(23, 59) == 'ๅˆๅพŒ11ๆ™‚59ๅˆ†' assert candidate(14, 30) == 'ๅˆๅพŒ2ๆ™‚30ๅˆ†' assert candidate(1, 1) == 'ๅˆๅ‰1ๆ™‚1ๅˆ†' assert candidate(13, 45) == 'ๅˆๅพŒ1ๆ™‚45ๅˆ†' assert candidate(11, 0) == 'ๅˆๅ‰11ๆ™‚0ๅˆ†' assert candidate(18, 15) == 'ๅˆๅพŒ6ๆ™‚15ๅˆ†' assert candidate(21, 30) == 'ๅˆๅพŒ9ๆ™‚30ๅˆ†'
convert_to_japanese_time
EN/44
้ขจ็ฟ’
้ขจ็ฟ’
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/45
้ขจ็ฟ’
้ขจ็ฟ’
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/46
้ขจ็ฟ’
้ขจ็ฟ’
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/47
้ขจ็ฟ’
้ขจ็ฟ’
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/48
้ขจ็ฟ’
้ขจ็ฟ’
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/49
้ขจ็ฟ’
้ขจ็ฟ’
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/50
้ขจ็ฟ’
้ขจ็ฟ’
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/51
้ขจ็ฟ’
้ขจ็ฟ’
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/52
้ขจ็ฟ’
้ขจ็ฟ’
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/53
้ขจ็ฟ’
้ขจ็ฟ’
from datetime import datetime def generate_work_message(start_time: str, end_time: str) -> str: """ A function that generates a message after work based on the start and end times. Arguments: start_time (str): Start time of work (HH:MM format) end_time (str): End time of work (HH:MM format) Return value: str: message after work Example: >>> generate_work_message("09:00", "18:00") 'ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ใ‚†ใฃใใ‚Šไผ‘ใ‚“ใงใใ ใ•ใ„ใ€‚' >>> generate_work_message("09:00", "16:30") 'ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ๆ˜Žๆ—ฅใ‚‚ใŒใ‚“ใฐใ‚Šใพใ—ใ‚‡ใ†ใ€‚' """
start = datetime.strptime(start_time, "%H:%M") end = datetime.strptime(end_time, "%H:%M") work_duration = (end - start).seconds / 3600 # ๅ‹คๅ‹™ๆ™‚้–“๏ผˆๆ™‚้–“ๅ˜ไฝ๏ผ‰ if work_duration >= 8: return "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ใ‚†ใฃใใ‚Šไผ‘ใ‚“ใงใใ ใ•ใ„ใ€‚" else: return "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ๆ˜Žๆ—ฅใ‚‚ใŒใ‚“ใฐใ‚Šใพใ—ใ‚‡ใ†ใ€‚"
def check(candidate): assert candidate("09:00", "18:00") == "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ใ‚†ใฃใใ‚Šไผ‘ใ‚“ใงใใ ใ•ใ„ใ€‚" assert candidate("09:00", "16:30") == "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ๆ˜Žๆ—ฅใ‚‚ใŒใ‚“ใฐใ‚Šใพใ—ใ‚‡ใ†ใ€‚" assert candidate("08:00", "16:00") == "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ใ‚†ใฃใใ‚Šไผ‘ใ‚“ใงใใ ใ•ใ„ใ€‚" assert candidate("10:00", "15:00") == "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ๆ˜Žๆ—ฅใ‚‚ใŒใ‚“ใฐใ‚Šใพใ—ใ‚‡ใ†ใ€‚" assert candidate("11:00", "19:00") == "ใŠ็–ฒใ‚Œๆง˜ใงใ—ใŸใ€‚ใ‚†ใฃใใ‚Šไผ‘ใ‚“ใงใใ ใ•ใ„ใ€‚"
generate_work_message
EN/54
้ขจ็ฟ’
้ขจ็ฟ’
from datetime import datetime, timedelta def calculate_bedtime(wake_up_time: str, sleep_duration: str) -> str: """ Calculates the time you should go to bed to get the desired amount of sleep. Arguments: - wake_up_time (str): Time you want to wake up in the morning (e.g. โ€˜07:30โ€™) - sleep_duration (str): sleep duration (e.g. โ€œ8:00โ€, โ€œ7:30โ€) Return value: - time to go to bed (e.g. โ€œ23:30โ€, โ€œ10:30โ€) """
wake_up_time_obj = datetime.strptime(wake_up_time, "%H:%M") sleep_hours, sleep_minutes = map(int, sleep_duration.split(':')) sleep_duration_obj = timedelta(hours=sleep_hours, minutes=sleep_minutes) bed_time_obj = wake_up_time_obj - sleep_duration_obj return bed_time_obj.strftime("%H:%M")
def check(candidate): assert candidate("07:30", "8:00") == "23:30" assert candidate("07:30", "8:30") == "23:00" assert candidate("18:00", "7:30") == "10:30" assert candidate("18:15", "7:30") == "10:45" assert candidate("09:00", "7:00") == "02:00" assert candidate("10:00", "7:00") == "03:00" assert candidate("22:00", "6:30") == "15:30" assert candidate("06:00", "7:00") == "23:00"
calculate_bedtime
EN/55
้ขจ็ฟ’
้ขจ็ฟ’
def can_all_family_wait(times, num_people): """ A function to determine whether the Aoki family can all wait in line at a restaurant. The waiting time is (number of people until they enter the restaurant) * 30 minutes. Arguments: - times (list): List of acceptable waiting times (in minutes) for all members of the Aoki family. - num_people (int): Number of people until they enter the restaurant. Return value: - bool: True if all family members are waiting in line, False if even one person is not waiting in line. """
wait_time = num_people * 30 for time in times: if time < wait_time: return False return True
def check(candidate): assert candidate([60, 90, 120], 1) == True assert candidate([60, 90, 120], 2) == True assert candidate([60, 90, 120], 3) == False assert candidate([60, 90, 120], 4) == False assert candidate([120, 120, 120], 4) == True assert candidate([120, 150, 150], 4) == True assert candidate([60, 120, 150], 4) == False
can_all_family_wait
EN/56
้ขจ็ฟ’
def evaluate_score(score: int) -> str: """ Grades will be evaluated based on the points given. Performance evaluation criteria: - 80 points or more: "่‰ฏ" - 60 points or more but less than 80 points: "ๅฏ" - Less than 60 points: "ไธๅฏ" argument: score (int): Input score (0-100) Return value: str: Evaluated grade ("่‰ฏ", "ๅฏ", "ไธๅฏ") Usage example: >>> evaluate_score(85) '่‰ฏ' >>> evaluate_score(75) 'ๅฏ' >>> evaluate_score(45) 'ไธๅฏ' """
if score >= 80: return "่‰ฏ" elif score >= 60: return "ๅฏ" else: return "ไธๅฏ"
def check(candidate): assert candidate(85) == "่‰ฏ" assert candidate(75) == "ๅฏ" assert candidate(45) == "ไธๅฏ" assert candidate(60) == "ๅฏ" assert candidate(80) == "่‰ฏ" assert candidate(59) == "ไธๅฏ" assert candidate(100) == "่‰ฏ" assert candidate(0) == "ไธๅฏ"
evaluate_score
EN/57
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
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/58
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
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/59
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
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/60
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def get_region(prefecture: str) -> str: """ Accepts a Japanese prefecture name as input and returns the corresponding region name. If a prefecture that does not exist is entered, "Unknown" is returned. >>> get_region('ๅŒ—ๆตท้“') 'ๅŒ—ๆตท้“ๅœฐๆ–น' >>> get_region('็ง‹็”ฐ็œŒ') 'ๆฑๅŒ—ๅœฐๆ–น' """
regions = { "ๅŒ—ๆตท้“ๅœฐๆ–น": ["ๅŒ—ๆตท้“"], "ๆฑๅŒ—ๅœฐๆ–น": ["้’ๆฃฎ็œŒ", "ๅฒฉๆ‰‹็œŒ", "ๅฎฎๅŸŽ็œŒ", "็ง‹็”ฐ็œŒ", "ๅฑฑๅฝข็œŒ", "็ฆๅณถ็œŒ"], "้–ขๆฑๅœฐๆ–น": ["่ŒจๅŸŽ็œŒ", "ๆ ƒๆœจ็œŒ", "็พค้ฆฌ็œŒ", "ๅŸผ็Ž‰็œŒ", "ๅƒ่‘‰็œŒ", "ๆฑไบฌ้ƒฝ", "็ฅžๅฅˆๅท็œŒ"], "ไธญ้ƒจๅœฐๆ–น": ["ๆ–ฐๆฝŸ็œŒ", "ๅฏŒๅฑฑ็œŒ", "็Ÿณๅท็œŒ", "็ฆไบ•็œŒ", "ๅฑฑๆขจ็œŒ", "้•ท้‡Ž็œŒ", "ๅฒ้˜œ็œŒ", "้™ๅฒก็œŒ", "ๆ„›็Ÿฅ็œŒ"], "่ฟ‘็•ฟๅœฐๆ–น": ["ไธ‰้‡็œŒ", "ๆป‹่ณ€็œŒ", "ไบฌ้ƒฝๅบœ", "ๅคง้˜ชๅบœ", "ๅ…ตๅบซ็œŒ", "ๅฅˆ่‰ฏ็œŒ", "ๅ’ŒๆญŒๅฑฑ็œŒ"], "ไธญๅ›ฝๅœฐๆ–น": ["้ณฅๅ–็œŒ", "ๅณถๆ น็œŒ", "ๅฒกๅฑฑ็œŒ", "ๅบƒๅณถ็œŒ", "ๅฑฑๅฃ็œŒ"], "ๅ››ๅ›ฝๅœฐๆ–น": ["ๅพณๅณถ็œŒ", "้ฆ™ๅท็œŒ", "ๆ„›ๅช›็œŒ", "้ซ˜็Ÿฅ็œŒ"], "ไนๅทžๅœฐๆ–น": ["็ฆๅฒก็œŒ", "ไฝ่ณ€็œŒ", "้•ทๅดŽ็œŒ", "็†Šๆœฌ็œŒ", "ๅคงๅˆ†็œŒ", "ๅฎฎๅดŽ็œŒ", "้นฟๅ…ๅณถ็œŒ", "ๆฒ–็ธ„็œŒ"], } for region, prefectures in regions.items(): if prefecture in prefectures: return region 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("้ณฅๅ–็œŒ") == "ไธญๅ›ฝๅœฐๆ–น" assert candidate("้ฆ™ๅท็œŒ") == "ๅ››ๅ›ฝๅœฐๆ–น" assert candidate("็ฆๅฒก็œŒ") == "ไนๅทžๅœฐๆ–น" assert candidate("้•ทๅดŽ็œŒ") == "ไนๅทžๅœฐๆ–น" assert candidate("ไธๅญ˜ๅœจ็œŒ") == "ไธๆ˜Ž"
get_region
EN/61
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def is_in_tokyo(ward: str) -> bool: """ A function that determines whether it is in Tokyo's 23 wards. argument: ward (str): Ward name to be judged. Return value: bool: True if the argument is the name of Tokyo's 23 wards, False otherwise. example: >>> is_in_tokyo("ๆ–ฐๅฎฟๅŒบ") True >>> is_in_tokyo("ๆจชๆตœๅธ‚") False """
tokyo_23_wards = { "ๅƒไปฃ็”ฐๅŒบ", "ไธญๅคฎๅŒบ", "ๆธฏๅŒบ", "ๆ–ฐๅฎฟๅŒบ", "ๆ–‡ไบฌๅŒบ", "ๅฐๆฑๅŒบ", "ๅขจ็”ฐๅŒบ", "ๆฑŸๆฑๅŒบ", "ๅ“ๅทๅŒบ", "็›ฎ้ป’ๅŒบ", "ๅคง็”ฐๅŒบ", "ไธ–็”ฐ่ฐทๅŒบ", "ๆธ‹่ฐทๅŒบ", "ไธญ้‡ŽๅŒบ", "ๆ‰ไธฆๅŒบ", "่ฑŠๅณถๅŒบ", "ๅŒ—ๅŒบ", "่’ๅทๅŒบ", "ๆฟๆฉ‹ๅŒบ", "็ทด้ฆฌๅŒบ", "่ถณ็ซ‹ๅŒบ", "่‘›้ฃพๅŒบ", "ๆฑŸๆˆธๅทๅŒบ" } return ward in tokyo_23_wards
def check(candidate): 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 assert candidate("ๅฏŒๅฃซๅธ‚") == False
is_in_tokyo
EN/62
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def get_hottest_location(temperature_data): """ Given city and temperature data, returns the city with the highest temperature. argument: temperature_data (dict): Dictionary of cities and their temperature data. Return value: str: Name of the city with the highest temperature. Execution example: >>> temperature_data = {"ๆ–ฐๅฎฟๅŒบ": 35.5, "ๅคง้˜ชๅธ‚": 34.0, "็ฆๅฒกๅธ‚": 36.2} >>> get_hottest_location(temperature_data) '็ฆๅฒกๅธ‚' """
return max(temperature_data, key=lambda location: temperature_data[location])
def check(candidate): assert candidate({"ๆ–ฐๅฎฟๅŒบ": 35.5, "ๅคง้˜ชๅธ‚": 34.0, "็ฆๅฒกๅธ‚": 36.2}) == "็ฆๅฒกๅธ‚" assert candidate({"ๆจชๆตœๅธ‚": 29.8, "ไบฌ้ƒฝๅธ‚": 33.1, "็ฅžๆˆธๅธ‚": 32.7}) == "ไบฌ้ƒฝๅธ‚" assert candidate({"ไป™ๅฐๅธ‚": 25.3, "้•ท้‡Žๅธ‚": 24.1, "้ซ˜ๆพๅธ‚": 26.0}) == "้ซ˜ๆพๅธ‚" assert candidate({"้‡‘ๆฒขๅธ‚": 31.2}) == "้‡‘ๆฒขๅธ‚" assert candidate({"ๅฏŒๅฑฑๅธ‚": -5.0, "็ง‹็”ฐๅธ‚": -3.2, "็››ๅฒกๅธ‚": -7.1}) == "็ง‹็”ฐๅธ‚"
get_hottest_location
EN/63
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
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/64
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def is_tokaido_shinkansen_nobori(stations: list) -> str: """ Determines whether the specified station on the Tokaido Shinkansen is an 'ไธŠใ‚Š' (ๆฑไบฌ-bound) or 'ไธ‹ใ‚Š' (ๆ–ฐๅคง้˜ช-bound) station. This function takes a list of stations, which consists of different stations for the departure and arrival stations. It returns 'ไธŠใ‚Š' if the station is an up station on the Tokaido Shinkansen, 'ไธ‹ใ‚Š' if it is a down station, and 'ๅˆคๅฎšไธๅฏ' if it is not possible to determine. ไฝฟ็”จไพ‹: >>> is_tokaido_shinkansen_nobori(["ๆ–ฐๅคง้˜ช", "ๆฑไบฌ"]) 'ไธŠใ‚Š' >>> is_tokaido_shinkansen_nobori(["ๆฑไบฌ", "ๆ–ฐๅคง้˜ช"]) 'ไธ‹ใ‚Š' >>> is_tokaido_shinkansen_nobori(["ๅŒ—ๆตท้“", "ๆฒ–็ธ„"]) 'ๅˆคๅฎšไธๅฏ' """
tokaido_shinkansen_stations = [ "ๆฑไบฌ", "ๅ“ๅท", "ๆ–ฐๆจชๆตœ", "ๅฐ็”ฐๅŽŸ", "็†ฑๆตท", "ไธ‰ๅณถ", "ๆ–ฐๅฏŒๅฃซ", "้™ๅฒก", "ๆŽ›ๅท", "ๆตœๆพ", "่ฑŠๆฉ‹", "ไธ‰ๆฒณๅฎ‰ๅŸŽ", "ๅๅคๅฑ‹", "ๅฒ้˜œ็พฝๅณถ", "็ฑณๅŽŸ", "ไบฌ้ƒฝ", "ๆ–ฐๅคง้˜ช" ] start_station, end_station = stations[0], stations[1] if start_station not in tokaido_shinkansen_stations or end_station not in tokaido_shinkansen_stations: return "ๅˆคๅฎšไธๅฏ" else: start_index = tokaido_shinkansen_stations.index(start_station) end_index = tokaido_shinkansen_stations.index(end_station) return "ไธŠใ‚Š" if start_index > end_index else "ไธ‹ใ‚Š"
def check(candidate): assert candidate(["ๆ–ฐๅคง้˜ช", "ๆฑไบฌ"]) == "ไธŠใ‚Š" assert candidate(["ๆฑไบฌ", "ๆ–ฐๅคง้˜ช"]) == "ไธ‹ใ‚Š" assert candidate(["ๅๅคๅฑ‹", "ๆฑไบฌ"]) == "ไธŠใ‚Š" assert candidate(["้™ๅฒก", "ๅๅคๅฑ‹"]) == "ไธ‹ใ‚Š" assert candidate(["ไบฌ้ƒฝ", "ๆ–ฐๅคง้˜ช"]) == "ไธ‹ใ‚Š" assert candidate(["ๅ“ๅท", "ๆ–ฐๆจชๆตœ"]) == "ไธ‹ใ‚Š" assert candidate(["ๆŽ›ๅท", "่ฑŠๆฉ‹"]) == "ไธ‹ใ‚Š" assert candidate(["่ฑŠๆฉ‹", "้™ๅฒก"]) == "ไธŠใ‚Š" assert candidate(["ๅŒ—ๆตท้“", "ๆฒ–็ธ„"]) == "ๅˆคๅฎšไธๅฏ" assert candidate(["ๆฑไบฌ", "ๆฒ–็ธ„"]) == "ๅˆคๅฎšไธๅฏ"
is_tokaido_shinkansen_nobori
EN/65
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def is_japan_three_views(place: str) -> bool: """ Determine whether the specified place name is one of the three most scenic places in Japan. >>> is_japan_three_views(""ๆพๅณถ"") True >>> is_japan_three_views(""ๅคฉๆฉ‹็ซ‹"") True >>> is_japan_three_views(""ๅฎฎๅณถ"") True >>> is_japan_three_views(""ๅฏŒๅฃซๅฑฑ"") False """
japan_three_views = {"ๆพๅณถ", "ๅคฉๆฉ‹็ซ‹", "ๅฎฎๅณถ"} return place in japan_three_views
def check(candidate): assert candidate("ๆพๅณถ") == True assert candidate("ๅคฉๆฉ‹็ซ‹") == True assert candidate("ๅฎฎๅณถ") == True assert candidate("ๅฏŒๅฃซๅฑฑ") == False assert candidate("ๆฑไบฌใ‚ฟใƒฏใƒผ") == False assert candidate("็ต็ถๆน–") == False assert candidate("ๅฑ‹ไน…ๅณถ") == False assert candidate("ๆฒ–็ธ„") == False
is_japan_three_views
EN/66
ๆ—ฅๆœฌๅœฐ็†
ๆ—ฅๆœฌๅœฐ็†
def is_prefectural_capital(city: str) -> bool: """ Determines whether the specified city is the capital of the prefecture. Argument: city (str): City name Return: bool: True if the capital of the prefecture, False otherwise Ex: >>> is_prefectural_capital("ๆฑไบฌ") True >>> is_prefectural_capital("ๆธ‹่ฐท") False """
prefectural_capitals = { "ๆœญๅนŒ", "้’ๆฃฎ", "็››ๅฒก", "ไป™ๅฐ", "็ง‹็”ฐ", "ๅฑฑๅฝข", "็ฆๅณถ", "ๆฐดๆˆธ", "ๅฎ‡้ƒฝๅฎฎ", "ๅ‰ๆฉ‹", "ใ•ใ„ใŸใพ", "ๅƒ่‘‰", "ๆฑไบฌ", "ๆจชๆตœ", "ๆ–ฐๆฝŸ", "ๅฏŒๅฑฑ", "้‡‘ๆฒข", "็ฆไบ•", "็”ฒๅบœ", "้•ท้‡Ž", "ๅฒ้˜œ", "้™ๅฒก", "ๅๅคๅฑ‹", "ๆดฅ", "ๅคงๆดฅ", "ไบฌ้ƒฝ", "ๅคง้˜ช", "็ฅžๆˆธ", "ๅฅˆ่‰ฏ", "ๅ’ŒๆญŒๅฑฑ", "้ณฅๅ–", "ๆพๆฑŸ", "ๅฒกๅฑฑ", "ๅบƒๅณถ", "ๅฑฑๅฃ", "ๅพณๅณถ", "้ซ˜ๆพ", "ๆพๅฑฑ", "้ซ˜็Ÿฅ", "็ฆๅฒก", "ไฝ่ณ€", "้•ทๅดŽ", "็†Šๆœฌ", "ๅคงๅˆ†", "ๅฎฎๅดŽ", "้นฟๅ…ๅณถ", "้‚ฃ่ฆ‡" } return city in prefectural_capitals
def check(candidate): assert candidate("ๆฑไบฌ") == True assert candidate("ๆธ‹่ฐท") == False assert candidate("ๅŒ—ๆตท้“") == False assert candidate("ๆœญๅนŒ") == True assert candidate("ๆดฅ") == True assert candidate("ๅคงๆดฅ") == True assert candidate("้ซ˜ๆพ") == True assert candidate("ๅŸผ็Ž‰") == False assert candidate("็ฅžๅฅˆๅท") == False assert candidate("ๆฒ–็ธ„") == False
is_prefectural_capital
EN/67
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
def check_olympic_year(year: int) -> bool: """ A function that checks whether it 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/68
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/69
ๆ–‡ๅŒ–
ๆ–‡ๅŒ–
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/70
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def convert_to_manyo_gana(text: str) -> str: """ A function that converts a given string to Manyogana. Convert each Hiragana character to its Manyogana counterpart. Here, we will perform a temporary and simple conversion. For example, ใ€Œใ‚ใ€isใ€Œๅฎ‰ใ€ใ€ใ€Œใ„ใ€isใ€Œไปฅใ€ใ€ใ€Œใ†ใ€isใ€Œๅฎ‡ใ€. argument: text (str): String containing hiragana. Return value: str: String converted to Manyogana. Usage example: ไฝฟ็”จไพ‹๏ผš >>> convert_to_manyo_gana("ใ‚ใ„ใ†") 'ๅฎ‰ไปฅๅฎ‡' """
hira_to_manyo = { 'ใ‚': 'ๅฎ‰', 'ใ„': 'ไปฅ', 'ใ†': 'ๅฎ‡', 'ใˆ': '่กฃ', 'ใŠ': 'ๆ–ผ', 'ใ‹': 'ๅŠ ', 'ใ': 'ๅนพ', 'ใ': 'ไน…', 'ใ‘': '่จˆ', 'ใ“': 'ๅทฑ', 'ใ•': 'ๅทฆ', 'ใ—': 'ไน‹', 'ใ™': '้ ˆ', 'ใ›': 'ไธ–', 'ใ': 'ๆ›ฝ', 'ใŸ': 'ๅคš', 'ใก': '็Ÿฅ', 'ใค': 'ๅท', 'ใฆ': 'ๅคฉ', 'ใจ': 'ๆญข', 'ใช': 'ๅฅˆ', 'ใซ': 'ไป', 'ใฌ': 'ๅฅด', 'ใญ': '็ฅข', 'ใฎ': 'ไนƒ', 'ใฏ': 'ๆณข', 'ใฒ': 'ๆฏ”', 'ใต': 'ๅธƒ', 'ใธ': '้ƒจ', 'ใป': 'ไฟ', 'ใพ': 'ๆœซ', 'ใฟ': '็พŽ', 'ใ‚€': 'ๆญฆ', 'ใ‚': 'ๅฅณ', 'ใ‚‚': 'ๆฏ›', 'ใ‚„': 'ไนŸ', 'ใ‚†': '็”ฑ', 'ใ‚ˆ': 'ไธŽ', 'ใ‚‰': '่‰ฏ', 'ใ‚Š': 'ๅˆฉ', 'ใ‚‹': '็•™', 'ใ‚Œ': '็คผ', 'ใ‚': 'ๅ‘‚', 'ใ‚': 'ๅ’Œ', 'ใ‚': '็‚บ', 'ใ‚‘': 'ๆต', 'ใ‚’': '้ ', 'ใ‚“': '็„ก' } result = [] for char in text: result.append(hira_to_manyo.get(char)) return ''.join(result)
def check(candidate): assert candidate("ใ‚ใ„ใ†") == 'ๅฎ‰ไปฅๅฎ‡' assert candidate("ใ‹ใใใ‘ใ“") == 'ๅŠ ๅนพไน…่จˆๅทฑ' assert candidate("ใ•ใ—ใ™ใ›ใ") == 'ๅทฆไน‹้ ˆไธ–ๆ›ฝ' assert candidate("ใŸใกใคใฆใจ") == 'ๅคš็Ÿฅๅทๅคฉๆญข' assert candidate("ใชใซใฌใญใฎ") == 'ๅฅˆไปๅฅด็ฅขไนƒ' assert candidate("ใฏใฒใตใธใป") == 'ๆณขๆฏ”ๅธƒ้ƒจไฟ' assert candidate("ใพใฟใ‚€ใ‚ใ‚‚") == 'ๆœซ็พŽๆญฆๅฅณๆฏ›' assert candidate("ใ‚„ใ‚†ใ‚ˆ") == 'ไนŸ็”ฑไธŽ' assert candidate("ใ‚‰ใ‚Šใ‚‹ใ‚Œใ‚") == '่‰ฏๅˆฉ็•™็คผๅ‘‚' assert candidate("ใ‚ใ‚ใ‚‘ใ‚’ใ‚“") == 'ๅ’Œ็‚บๆต้ ็„ก'
convert_to_manyo_gana
EN/71
้ขจ็ฟ’
้ขจ็ฟ’
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/72
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
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/73
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def next_katakana(char: str) -> str: """ A function that returns the character following the specified character in a katakana table. If the specified character is the last character ('ใƒณ'), it will return to the first character ('a'). argument: char (str): 1 character katakana Return value: str: next katakana character Usage example: >>> next_katakana("ใ‚ข") 'ใ‚ค' >>> next_katakana("ใƒณ") 'ใ‚ข' >>> next_katakana("ใ‚ซ") 'ใ‚ญ' >>> next_katakana("ใƒฒ") 'ใƒณ' """
katakana_list = ['ใ‚ข', 'ใ‚ค', 'ใ‚ฆ', 'ใ‚จ', 'ใ‚ช', 'ใ‚ซ', 'ใ‚ญ', 'ใ‚ฏ', 'ใ‚ฑ', 'ใ‚ณ', 'ใ‚ต', 'ใ‚ท', 'ใ‚น', 'ใ‚ป', 'ใ‚ฝ', 'ใ‚ฟ', 'ใƒ', 'ใƒ„', 'ใƒ†', 'ใƒˆ', 'ใƒŠ', 'ใƒ‹', 'ใƒŒ', 'ใƒ', 'ใƒŽ', 'ใƒ', 'ใƒ’', 'ใƒ•', 'ใƒ˜', 'ใƒ›', 'ใƒž', 'ใƒŸ', 'ใƒ ', 'ใƒก', 'ใƒข', 'ใƒค', 'ใƒฆ', 'ใƒจ', 'ใƒฉ', 'ใƒช', 'ใƒซ', 'ใƒฌ', 'ใƒญ', 'ใƒฏ', 'ใƒฒ', 'ใƒณ'] index = katakana_list.index(char) next_index = (index + 1) % len(katakana_list) # ๆœ€ๅพŒใฎๆ–‡ๅญ—ใฎๆฌกใฏๆœ€ๅˆใฎๆ–‡ๅญ— return katakana_list[next_index]
def check(candidate): assert candidate("ใ‚ข") == 'ใ‚ค' assert candidate("ใ‚ซ") == 'ใ‚ญ' assert candidate("ใƒฒ") == 'ใƒณ' assert candidate("ใƒณ") == 'ใ‚ข' assert candidate("ใ‚ฝ") == 'ใ‚ฟ' assert candidate("ใƒจ") == 'ใƒฉ' assert candidate("ใƒณ") == 'ใ‚ข' assert candidate("ใƒ›") == 'ใƒž' assert candidate("ใƒฏ") == 'ใƒฒ'
next_katakana
EN/74
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def replace_katakana(s, replacement): """ Replaces katakana characters in the given string s with the specified string replacement. argument: s (str): Target string. replacement (str): String used for replacement. Return value: str: String resulting from replacing katakana. Execution example: >>> replace_katakana("ใ‚ซใ‚ฟใ‚ซใƒŠใจใฒใ‚‰ใŒใช", "*") '**ใจใฒใ‚‰ใŒใช' """
return "".join(replacement if "ใ‚ก" <= char <= "ใƒณ" or char == "ใƒด" else char for char in s)
def check(candidate): assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠใจใฒใ‚‰ใŒใช", "*") == "****ใจใฒใ‚‰ใŒใช" assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠ", "!") == "!!!!" assert candidate("ใฒใ‚‰ใŒใชใจๆผขๅญ—", "?") == "ใฒใ‚‰ใŒใชใจๆผขๅญ—" assert candidate("ๆผขๅญ—ใจใ‚ซใ‚ฟใ‚ซใƒŠ", "#") == "ๆผขๅญ—ใจ####" assert candidate("ใ‚ใ‚ขใ‚คใ„ใ†ใ‚ฆใˆใ‚จใ‚ชใŠ", "+") == "ใ‚++ใ„ใ†+ใˆ++ใŠ"
replace_katakana
EN/75
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def calculate_katakana_percentage(text: str) -> float: """ A function that calculates the percentage of katakana in a text. Arguments: text (str): Japanese text Return value: float: Percentage of katakana (to one decimal place) Example: >>> calculate_katakana_percentage("ใ‚ณใƒณใƒ”ใƒฅใƒผใ‚ฟ") 100.0 >>> calculate_katakana_percentage("ใ‚ซใ‚ฟใ‚ซใƒŠใจใฒใ‚‰ใŒใช") 44.4 """
if len(text) == 0: return 0.0 total_chars = len(text) katakana_count = sum(1 for char in text if '\u30a0' <= char <= '\u30ff') percentage = (katakana_count / total_chars) * 100 return round(percentage, 1)
def check(candidate): assert candidate("ใ‚ณใƒณใƒ”ใƒฅใƒผใ‚ฟ") == 100.0 assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠใจใฒใ‚‰ใŒใช") == 44.4 assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠใจๆผขๅญ—") == 57.1 assert candidate("ใ‚ใ‚ข้˜ฟใ‚“ใƒณ") == 40.0 assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠใƒˆใฒใ‚‰ใŒใชใƒˆๆผขๅญ—") == 50.0 assert candidate("ๆผขๅญ—ใฎใฟ") == 0.0
calculate_katakana_percentage
EN/76
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def convert_katakana_to_halfwidth(text: str) -> str: """ You are given a text (text) composed of hiragana and katakana syllabary characters. Create a function that converts all katakana characters in the text to half-width characters. Rules: - Keep hiragana and already half-width katakana characters unchanged Example: >>> convert_katakana_to_halfwidth("ใ‚ใ„ใ†ใˆใŠใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") 'ใ‚ใ„ใ†ใˆใŠ๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต' >>> convert_katakana_to_halfwidth("ใƒฏใƒฒใƒณใ‚ใ‚’ใ‚“") '๏พœ๏ฝฆ๏พใ‚ใ‚’ใ‚“' """
fullwidth = "ใ‚ขใ‚คใ‚ฆใ‚จใ‚ชใ‚ซใ‚ญใ‚ฏใ‚ฑใ‚ณใ‚ตใ‚ทใ‚นใ‚ปใ‚ฝใ‚ฟใƒใƒ„ใƒ†ใƒˆใƒŠใƒ‹ใƒŒใƒใƒŽใƒใƒ’ใƒ•ใƒ˜ใƒ›ใƒžใƒŸใƒ ใƒกใƒขใƒคใƒฆใƒจใƒฉใƒชใƒซใƒฌใƒญใƒฏใƒฒใƒณ" halfwidth = "๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต๏ฝถ๏ฝท๏ฝธ๏ฝน๏ฝบ๏ฝป๏ฝผ๏ฝฝ๏ฝพ๏ฝฟ๏พ€๏พ๏พ‚๏พƒ๏พ„๏พ…๏พ†๏พ‡๏พˆ๏พ‰๏พŠ๏พ‹๏พŒ๏พ๏พŽ๏พ๏พ๏พ‘๏พ’๏พ“๏พ”๏พ•๏พ–๏พ—๏พ˜๏พ™๏พš๏พ›๏พœ๏ฝฆ๏พ" return text.translate(str.maketrans(fullwidth, halfwidth))
def check(candidate): assert candidate("ใ‚ใ„ใ†ใˆใŠใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == "ใ‚ใ„ใ†ใˆใŠ๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต" assert candidate("ใƒฏใƒฒใƒณใ‚ใ‚’ใ‚“") == "๏พœ๏ฝฆ๏พใ‚ใ‚’ใ‚“" assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠ ใฒใ‚‰ใŒใช") == "๏ฝถ๏พ€๏ฝถ๏พ… ใฒใ‚‰ใŒใช" assert candidate("ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == "๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต ๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต" assert candidate("ใƒฏใƒฒใƒณ ใƒฏใƒฒใƒณ") == "๏พœ๏ฝฆ๏พ ๏พœ๏ฝฆ๏พ" assert candidate("๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต") == "๏ฝฑ๏ฝฒ๏ฝณ๏ฝด๏ฝต" assert candidate("๏พœ๏ฝฆ๏พ") == "๏พœ๏ฝฆ๏พ" assert candidate("ใฒใ‚‰ใŒใชใฎใฟ") == "ใฒใ‚‰ใŒใชใฎใฟ" assert candidate("ใ‚ขใ„ใ‚ฆใˆใ‚ช") == "๏ฝฑใ„๏ฝณใˆ๏ฝต" assert candidate("ใ‚ซใ‚ญใ‚ฏใ‚ฑใ‚ณใ‹ใใใ‘ใ“") == "๏ฝถ๏ฝท๏ฝธ๏ฝน๏ฝบใ‹ใใใ‘ใ“"
convert_katakana_to_halfwidth
EN/77
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def is_two_char_shiritori_valid_katakana(words: list) -> bool: """ A function that determines whether or not the rules for two-character shiritori using katakana are satisfied. Returns True if the two-character shiritori is valid, and False otherwise. Rules: - The โ€œlast two charactersโ€ of each word must be an exact match for the โ€œfirst two charactersโ€ of the next word. - It is assumed that the input consists entirely of katakana. Example: >>> is_two_char_shiritori_valid_katakana(["ใ‚ทใƒชใƒˆใƒช", "ใƒˆใƒชใ‚ฏใƒ", "ใ‚ฏใƒใƒใ‚ท", "ใƒใ‚ทใƒง"]) True >>> is_two_char_shiritori_valid_katakana(["ใ‚ฟใƒŒใ‚ญ", "ใ‚ญใƒ„ใƒ", "ใƒใ‚ณ", "ใ‚ณใ‚คใƒŒ"]) False """
for i in range(len(words) - 1): if len(words[i]) < 2 or len(words[i + 1]) < 2: return False if words[i][-2:] != words[i + 1][:2]: return False return True
def check(candidate): assert candidate(["ใ‚ทใƒชใƒˆใƒช", "ใƒˆใƒชใ‚ฏใƒ", "ใ‚ฏใƒใƒใ‚ท", "ใƒใ‚ทใƒง"]) == True assert candidate(["ใƒˆใƒžใƒˆ", "ใƒžใƒˆใƒชใƒงใƒผใ‚ทใ‚ซ", "ใ‚ทใ‚ซใ‚ค", "ใ‚ซใ‚คใ‚ฌใƒฉ"]) == True assert candidate(["ใ‚ญใƒ„ใƒ„ใ‚ญ", "ใƒ„ใ‚ญใ‚ขใ‚ซใƒช", "ใ‚ซใƒชใƒขใƒŽ", "ใƒขใƒŽใ‚ชใ‚ญ"]) == True assert candidate(["ใ‚ฟใƒŒใ‚ญ", "ใ‚ญใƒ„ใƒ", "ใƒใ‚ณ", "ใ‚ณใ‚คใƒŒ"]) == False assert candidate(["ใƒใ‚ณ", "ใ‚ณใ‚ฟใƒ„", "ใƒ„ใƒŸใ‚ญ", "ใ‚ญใƒŽใ‚ณ"]) == False assert candidate(["ใ‚ทใƒชใƒˆใƒช", "ใƒˆใƒชใ‚ฏใƒ", "ใ‚ฏใƒใƒ“ใƒซ", "ใƒ“ใƒซใƒ‰"]) == True assert candidate(["ใ‚ซใ‚ฟใ‚ซใƒŠ", "ใƒŠใƒžใ‚จ", "ใ‚จใ‚ขใ‚ณใƒณ"]) == False
is_two_char_shiritori_valid_katakana
EN/78
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def katakana_to_romaji(name: str) -> str: """ This function takes the furigana for the name โ€˜nameโ€™ and converts it to full-width capital letters. Ex: >>> katakana_to_romaji("ใ‚ฟใƒŠใ‚ซ") 'TANAKA' """
katakana_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', 'ใ‚ฌ': 'GA', 'ใ‚ฎ': 'GI', 'ใ‚ฐ': 'GU', 'ใ‚ฒ': 'GE', 'ใ‚ด': 'GO', 'ใ‚ถ': 'ZA', 'ใ‚ธ': 'JI', 'ใ‚บ': 'ZU', 'ใ‚ผ': 'ZE', 'ใ‚พ': 'ZO', 'ใƒ€': 'DA', 'ใƒ‚': 'JI', 'ใƒ…': 'ZU', 'ใƒ‡': 'DE', 'ใƒ‰': 'DO', 'ใƒ': 'BA', 'ใƒ“': 'BI', 'ใƒ–': 'BU', 'ใƒ™': 'BE', 'ใƒœ': 'BO', 'ใƒ‘': 'PA', 'ใƒ”': 'PI', 'ใƒ—': 'PU', 'ใƒš': 'PE', 'ใƒ': 'PO', 'ใ‚ก': 'a', 'ใ‚ฃ': 'i', 'ใ‚ฅ': 'u', 'ใ‚ง': 'e', 'ใ‚ฉ': 'o', 'ใƒฃ': 'ya', 'ใƒฅ': 'yu', 'ใƒง': 'yo', 'ใƒƒ': 'tsu', 'ใƒผ': '' } romaji = '' for char in name: romaji += katakana_map.get(char, '') return romaji
def check(candidate): assert candidate("ใ‚ขใ‚ชใ‚ญ") == "AOKI" assert candidate("ใ‚ซใƒใ‚ณ") == "KANEKO" assert candidate("ใ‚นใ‚บใ‚ญ") == "SUZUKI" assert candidate("ใ‚ฟใƒŠใ‚ซ") == "TANAKA" assert candidate("ใƒ‹ใ‚ทใƒ€") == "NISHIDA" assert candidate("ใƒ•ใ‚ธใƒขใƒˆ") == "FUJIMOTO" assert candidate("ใƒŸใ‚ฆใƒฉ") == "MIURA" assert candidate("ใƒคใƒŽ") == "YANO" assert candidate("ใƒฏใ‚ฟใƒŠใƒ™") == "WATANABE"
katakana_to_romaji
EN/79
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def encode_shift(s: str): return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s]) def decode_shift(s: str): """ This function takes a string encoded with the encode_shift function as an argument and returns the decoded string. """
return "".join([chr(((ord(ch) - ord("a") - 5) % 26) + ord("a")) for ch in s])
from random import randint, choice import string import copy def check(candidate): letters = string.ascii_lowercase for _ in range(50): str = ''.join(choice(letters) for i in range(randint(10, 20))) encoded_str = encode_shift(str) assert candidate(copy.deepcopy(encoded_str)) == str
decode_shift
EN/80
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
from collections import Counter def most_frequent_katakana(text: str) -> str: """ A function that returns the most frequent katakana character in a string. It ignores hiragana and kanji characters in the string and only counts katakana. Arguments: text (str): A string containing hiragana, katakana and kanji Return value: str: Most frequent katakana (if there is a tie, the first katakana that appears) """
katakana = [ch for ch in text if 'ใ‚ข' <= ch <= 'ใƒณ'] if not katakana: return "" counter = Counter(katakana) most_frequent = counter.most_common(1)[0][0] return most_frequent
def check(candidate): assert candidate("ใฒใ‚‰ใŒใช") == "" assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠ") == "ใ‚ซ" assert candidate("ๆผขๅญ—") == "" assert candidate("ใ‚ขใ‚ขใ‚คใ‚ขใ‚คใ‚ฆใ‚ขใ‚คใ‚ฆใ‚จใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == "ใ‚ข" assert candidate("ใ‚ขใ‚คใ‚คใ‚ฆใ‚ฆใ‚จใ‚จใ‚ช") == "ใ‚ค" assert candidate("ใฒใ‚‰ใŒใชใ‚„ใ‚ซใ‚ฟใ‚ซใƒŠใ‚„ๆผขๅญ—ใ‚’ๅซใ‚€") == "ใ‚ซ" assert candidate("ใƒ’ใƒฉใ‚ฌใƒŠใƒค็‰‡ไปฎๅใƒคใ‚ซใƒณใ‚ธใƒฒใƒ•ใ‚ฏใƒ ") == "ใƒค"
most_frequent_katakana
EN/81
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
็‰‡ไปฎๅ
def determine_winner(names: list) -> str: """ In a game involving ไฝ่—ค, ้ˆดๆœจ, and ้ซ˜ๆฉ‹, calculate the score for each player from the given list of names, and return the player with the highest score. Calculation method for score: - Total number of katakana + (total number of unique katakana * 10) - (total number of non-katakana * 2) Arguments: names (list): List of player names (strings containing katakana, hiragana and kanji) Return value: str: Name of the player with the highest score Example: >>> determine_winner(['ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช', 'ใ‚ขใ‚ขใ‚ขใ‚ขใ‚ขใ‚ข', 'ใ‚ใ‚ขใ„ใ‚คใ‚ฆใ‚จใ‚ช']) 'ไฝ่—ค' """
katakana = "ใ‚ขใ‚คใ‚ฆใ‚จใ‚ชใ‚ซใ‚ญใ‚ฏใ‚ฑใ‚ณใ‚ตใ‚ทใ‚นใ‚ปใ‚ฝใ‚ฟใƒใƒ„ใƒ†ใƒˆใƒŠใƒ‹ใƒŒใƒใƒŽใƒใƒ’ใƒ•ใƒ˜ใƒ›ใƒžใƒŸใƒ ใƒกใƒขใƒคใƒฆใƒจใƒฉใƒชใƒซใƒฌใƒญใƒฏใƒฒใƒณ" def calculate_score(name: str) -> int: """ ๅๅ‰ใ‹ใ‚‰ๅพ—็‚นใ‚’่จˆ็ฎ—ใ™ใ‚‹ """ count_katakana = sum(1 for char in name if char in katakana) # ็‰‡ไปฎๅใฎ็ทๆ•ฐ unique_katakana = len(set(char for char in name if char in katakana)) # ้‡่ค‡ใชใ—ใฎ็‰‡ไปฎๅใฎ็ทๆ•ฐ non_katakana_count = sum(1 for char in name if char not in katakana) # ็‰‡ไปฎๅไปฅๅค–ใฎ็ทๆ•ฐ score = count_katakana + unique_katakana * 10 - non_katakana_count * 2 return score # ใใ‚Œใžใ‚Œใฎใƒ—ใƒฌใ‚คใƒคใƒผใฎ็‚นๆ•ฐใ‚’่จˆ็ฎ— scores = [calculate_score(name) for name in names] # ๆœ€ใ‚‚้ซ˜ใ„็‚นๆ•ฐใ‚’ๅ–ใฃใŸใƒ—ใƒฌใ‚คใƒคใƒผใ‚’้ธๆŠž max_score = max(scores) winner_index = scores.index(max_score) return ["ไฝ่—ค", "้ˆดๆœจ", "้ซ˜ๆฉ‹"][winner_index]
def check(candidate): assert candidate(['ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช', 'ใ‚ขใ‚ขใ‚ขใ‚ขใ‚ขใ‚ข', 'ใ‚ใ‚ขใ„ใ‚คใ‚ฆใ‚จใ‚ช']) == 'ไฝ่—ค' assert candidate(['ใ‚ขใ‚ขใ‚ฆใ‚ฆใ‚ชใ‚ช', 'ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช', 'ใ‚ขใ‚ขใ‚ขใ‚ขใ‚ขใ‚ข']) == '้ˆดๆœจ' assert candidate(['ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช', 'ใ‚ขใ‚ขใ‚ขใ‚ขใ‚ขใ‚ข', 'ใ‚ขใ‚คใ‚ฆใ‚จใ‚ชใ‚ขใ‚คใ‚ฆใ‚จใ‚ช']) == '้ซ˜ๆฉ‹'
determine_winner
EN/82
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
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/83
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
def extract_hiragana(text: str) -> str: """ A function that extracts and returns only hiragana from a string `text`. argument: text (str): input string Return value: str: String with only hiragana extracted Example: >>> extract_hiragana("ใ“ใ‚“ใซใกใฏใ€‚") 'ใ“ใ‚“ใซใกใฏ' >>> extract_hiragana("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญใ€‚") 'ใฏใ„ใ„ใงใ™ใญ' """
return ''.join(char for char in text if 'ใ' <= char <= 'ใ‚“')
def check(candidate): assert candidate("") == '' assert candidate("ใ“ใ‚“ใซใกใฏใ€‚") == 'ใ“ใ‚“ใซใกใฏ' assert candidate("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญใ€‚") == 'ใฏใ„ใ„ใงใ™ใญ' assert candidate("ใ“ใ‚“ใซใกใฏใ€‚ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญใ€‚") == 'ใ“ใ‚“ใซใกใฏใฏใ„ใ„ใงใ™ใญ' assert candidate("ใฒใ‚‰ใŒใชใ‚ซใ‚ฟใ‚ซใƒŠๆผขๅญ—") == 'ใฒใ‚‰ใŒใช' assert candidate("ใฒใ‚‰ใŒใชใ€Hiraganaใ€hiragana") == 'ใฒใ‚‰ใŒใช'
extract_hiragana
EN/84
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
from typing import List def all_prefixes(string: str) -> List[str]: """ Returns a list of all prefixes, from shortest to longest, for the string given as an argument. However, it is assumed that all character strings are in hiragana. example: >>> all_prefixes('Aiu') ['A', 'Ai', 'Aiu'] """
result = [] for i in range(len(string)): result.append(string[:i+1]) return result
def check(candidate): assert candidate('') == [] assert candidate('ใ‚ใ„ใ†ใˆใŠ') == ['ใ‚', 'ใ‚ใ„', 'ใ‚ใ„ใ†', 'ใ‚ใ„ใ†ใˆ', 'ใ‚ใ„ใ†ใˆใŠ'] assert candidate('ใฒใ‚‰ใŒใช') == ['ใฒ', 'ใฒใ‚‰', 'ใฒใ‚‰ใŒ', 'ใฒใ‚‰ใŒใช']
all_prefixes
EN/85
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
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/86
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
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/87
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
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
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 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/90
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
def is_valid_reverse_shiritori(words: list) -> bool: """ A function that determines whether a list of hiragana satisfies the reverse shiritori rules. Gyaku-shiritori places the first letter of the previous word at the end of the next word. argument: words (list): list of hiragana words Return value: bool: True if the reverse rules are met, False if not Usage example: >>> is_valid_reverse_shiritori(["ใ‚Šใ‚“ใ”", "ใกใ‚Š", "ใ—ใ‚ƒใก", "ใ‹ใ—"]) True >>> is_valid_reverse_shiritori(["ใ‚Šใ‚“ใ”", "ใ”ใ‚Šใ‚‰", "ใ‚‰ใฃใฑ", "ใฑใ›ใ‚Š"]) False """
for i in range(1, len(words)): if words[i-1][0] != words[i][-1]: return False return True
def check(candidate): assert candidate(["ใ‚Šใ‚“ใ”", "ใกใ‚Š", "ใ—ใ‚ƒใก", "ใ‹ใ—"]) == True assert candidate(["ใ”ใ‚Šใ‚‰", "ใ‚Šใ‚“ใ”", "ใใ‚Š", "ใใ", "ใ‹ใ"]) == True assert candidate(["ใ‚‰ใฃใฑ", "ใ•ใ‚‰", "ใ•ใ•", "ใ›ใ‚“ใ•"]) == True assert candidate(["ใ‚Šใ‚“ใ”", "ใ”ใ‚Šใ‚‰", "ใ‚‰ใฃใฑ", "ใฑใ›ใ‚Š"]) == False assert candidate(["ใ”ใ‚Šใ‚‰", "ใ‚‰ใฃใ“", "ใ“ใฉใ‚‚", "ใ‚‚ใ‚‚"]) == False
is_valid_reverse_shiritori
EN/91
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
def hiragana_ascii_sum(s: str) -> int: """Takes a string of hiragana as an argument and returns the sum of the ASCII codes (Unicode code points) for hiragana characters only."""
total_sum = 0 for char in s: if 'ใ' <= char <= 'ใ‚“': total_sum += ord(char) return total_sum
def check(candidate): assert candidate("ใ‚ใ„") == 24710 assert candidate("ใ•ใ—ใ™ใ›ใ") == 61885 assert candidate("ใ‚ใ‹ใ•ใŸใช") == 61867 assert candidate("ใ‚abcใ„") == 24710 assert candidate("12345ใ‚ใ„") == 24710 assert candidate("ใ‚ใ‚’ใ‚“") == 37300
hiragana_ascii_sum
EN/92
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๅนณไปฎๅ
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/93
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
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/94
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
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/95
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def sort_japanese_characters(text: str) -> str: """ A function that receives a string, sorts and combines hiragana, katakana, kanji, and alphabets. argument: text (str): input string Return value: str: string of characters arranged in hiragana, katakana, kanji, alphabetical order Usage example: >>> sort_japanese_characters("ใฒใ‚‰ใŒใช") 'ใŒใชใฒใ‚‰' >>> sort_japanese_characters("ใฒใ‚‰ใŒใชใ‚ซใ‚ฟใ‚ซใƒŠๆผขๅญ—Alphabet") 'ใŒใชใฒใ‚‰ใ‚ซใ‚ซใ‚ฟใƒŠๅญ—ๆผขAabehlpt' """
hiragana = sorted([char for char in text if 'ใ' <= char <= 'ใ‚“']) katakana = sorted([char for char in text if 'ใ‚ก' <= char <= 'ใƒถ']) kanji = sorted([char for char in text if 'ไธ€' <= char <= '้พฏ']) alphabet = sorted([char for char in text if 'A' <= char <= 'Z' or 'a' <= char <= 'z']) return ''.join(hiragana + katakana + kanji + alphabet)
def check(candidate): assert candidate("ใฒใ‚‰ใŒใช") == "ใŒใชใฒใ‚‰" assert candidate("ใ‚ซใ‚ฟใ‚ซใƒŠ") == "ใ‚ซใ‚ซใ‚ฟใƒŠ" assert candidate("ๆผขๅญ—") == "ๅญ—ๆผข" assert candidate("Alphabet") == "Aabehlpt" assert candidate("ใฒใ‚‰ใŒใชใ‚ซใ‚ฟใ‚ซใƒŠๆผขๅญ—Alphabet") == "ใŒใชใฒใ‚‰ใ‚ซใ‚ซใ‚ฟใƒŠๅญ—ๆผขAabehlpt"
sort_japanese_characters
EN/96
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def solve(s): """ A string s is given. If s[i] is hiragana or katakana, convert that character (hiragana to katakana, katakana to hiragana). If it contains other characters, leave it as is. If the string does not contain any hiragana or katakana characters, reverse the entire string. The function returns a string of results. example: >>> solve("1234") '4321' >>> solve("ใ‚ใ„") 'ใ‚ขใ‚ค' >>> solve("#ใ‚@ใ‚ค") '#ใ‚ข@ใ„' """
flg = 0 idx = 0 new_str = list(s) for i in s: if 'ใ' <= i <= 'ใ‚“': # ใฒใ‚‰ใŒใชใ‚’ใ‚ซใ‚ฟใ‚ซใƒŠใซๅค‰ๆ› new_str[idx] = chr(ord(i) - ord('ใ') + ord('ใ‚ก')) flg = 1 elif 'ใ‚ก' <= i <= 'ใƒณ': # ใ‚ซใ‚ฟใ‚ซใƒŠใ‚’ใฒใ‚‰ใŒใชใซๅค‰ๆ› new_str[idx] = chr(ord(i) - ord('ใ‚ก') + ord('ใ')) flg = 1 idx += 1 s = "".join(new_str) if flg == 0: return s[::-1] return s
def check(candidate): # ็ฐกๅ˜ใชใ‚ฑใƒผใ‚นใ‚’ใƒใ‚งใƒƒใ‚ฏ assert candidate("ใ‚ใ„") == "ใ‚ขใ‚ค" assert candidate("1234") == "4321" assert candidate("ใ‚ขใ‚ซ") == "ใ‚ใ‹" assert candidate("#ใ‚@ใ‚ค") == "#ใ‚ข@ใ„" assert candidate("#ใ‚ใ„ใ‚ฆใ‚จ^45") == "#ใ‚ขใ‚คใ†ใˆ^45" assert candidate("#6@2") == "2@6#" # ๅขƒ็•Œใ‚ฑใƒผใ‚นใ‚’ใƒใ‚งใƒƒใ‚ฏ assert candidate("#$ใ‚^ใ‚ซ") == "#$ใ‚ข^ใ‹" assert candidate("#ใ‚ใ‚ใ‚") == "#ใ‚ขใ‚ขใ‚ข" assert candidate("ใ‹ใใใ‘ใ“") == "ใ‚ซใ‚ญใ‚ฏใ‚ฑใ‚ณ" assert candidate("ใ‚ขใ‚คใ‚ฆใ‚จใ‚ช") == "ใ‚ใ„ใ†ใˆใŠ" assert candidate("123456") == "654321"
solve
EN/97
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def count_sentences(text: str) -> int: """ A function that counts how many Japanese sentences there are. Sentences are defined to be separated by one of "ใ€‚", "๏ผ", or "๏ผŸ". argument: text (str): input Japanese text Return value: int: number of sentences Usage example: >>> count_sentences("") 0 >>> count_sentences("ใŠใฏใ‚ˆใ†ใ”ใ–ใ„ใพใ™ใ€‚") 1 >>> count_sentences("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญใ€‚ๆ˜Žๆ—ฅใ‚‚ๆ™ดใ‚Œใ‚‹ใจใ„ใ„ใงใ™ใญ๏ผ") 2 """
if not text: return 0 sentences = [sentence for sentence in text.split('ใ€‚') if sentence] # ใ€Œใ€‚ใ€ใงๅˆ†ๅ‰ฒ temp_sentences = [] for sentence in sentences: temp_sentences.extend([s for s in sentence.split('๏ผ') if s]) # ใ€Œ๏ผใ€ใงใ•ใ‚‰ใซๅˆ†ๅ‰ฒ final_sentences = [] for sentence in temp_sentences: final_sentences.extend([s for s in sentence.split('๏ผŸ') if s]) # ใ€Œ๏ผŸใ€ใงใ•ใ‚‰ใซๅˆ†ๅ‰ฒ return len(final_sentences)
def check(candidate): assert candidate("") == 0 assert candidate("ใŠใฏใ‚ˆใ†ใ”ใ–ใ„ใพใ™ใ€‚") == 1 assert candidate("ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญใ€‚ๆ˜Žๆ—ฅใ‚‚ๆ™ดใ‚Œใ‚‹ใจใ„ใ„ใงใ™ใญ๏ผ") == 2 assert candidate("ใŠใฏใ‚ˆใ†๏ผไปŠๆ—ฅใฏไฝ•ใ‹ใ‚‰ๅง‹ใ‚ใ‚ˆใ†ใ‹๏ผŸ") == 2 assert candidate("ใŠใฏใ‚ˆใ†ใ”ใ–ใ„ใพใ™ใ€‚ไปŠๆ—ฅใฏใ„ใ„ๅคฉๆฐ—ใงใ™ใญ๏ผๆ˜Žๆ—ฅใฎๅคฉๆฐ—ใฏใ„ใ‹ใŒใงใ—ใ‚‡ใ†ใ‹๏ผŸ") == 3
count_sentences
EN/98
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def count_onsen_symbols(text: str) -> int: """ Counts and returns the number of hot spring symbols "โ™จ๏ธ" from the input string. Args: text (str): input string Returns: int: Number of hot spring symbols โ€œโ™จ๏ธโ€ """
return text.count('โ™จ๏ธ')
def check(candidate): assert candidate("โ™จ๏ธ") == 1 assert candidate("โ™จ๏ธโ™จ๏ธโ™จ๏ธโ™จ๏ธโ™จ๏ธ") == 5 assert candidate("โ™จ๏ธใ‚โ™จ๏ธใ„โ™จ๏ธใ†โ™จ๏ธใˆโ™จ๏ธใŠโ™จ๏ธ") == 6 assert candidate("โ™จ๏ธๆธฉๆณ‰ใซๅ…ฅใ‚Šใพใ—ใ‚‡ใ†โ™จ๏ธ") == 2
count_onsen_symbols
EN/99
ๆ—ฅๆœฌ่ชžๅ‡ฆ็†
ๆททๅˆ
def check_katakana_hiragana_match(katakana: str, hiragana: str) -> bool: """ A function that checks whether katakana and hiragana match. Arguments: katakana (str): katakana string hiragana (str): hiragana string Return value: bool: True if katakana and hiragana match, False otherwise """
def katakana_to_hiragana(katakana: str) -> str: katakana_map = { 'ใ‚ข': 'ใ‚', 'ใ‚ค': 'ใ„', 'ใ‚ฆ': 'ใ†', 'ใ‚จ': 'ใˆ', 'ใ‚ช': 'ใŠ', 'ใ‚ซ': 'ใ‹', 'ใ‚ญ': 'ใ', 'ใ‚ฏ': 'ใ', 'ใ‚ฑ': 'ใ‘', 'ใ‚ณ': 'ใ“', 'ใ‚ต': 'ใ•', 'ใ‚ท': 'ใ—', 'ใ‚น': 'ใ™', 'ใ‚ป': 'ใ›', 'ใ‚ฝ': 'ใ', 'ใ‚ฟ': 'ใŸ', 'ใƒ': 'ใก', 'ใƒ„': 'ใค', 'ใƒ†': 'ใฆ', 'ใƒˆ': 'ใจ', 'ใƒŠ': 'ใช', 'ใƒ‹': 'ใซ', 'ใƒŒ': 'ใฌ', 'ใƒ': 'ใญ', 'ใƒŽ': 'ใฎ', 'ใƒ': 'ใฏ', 'ใƒ’': 'ใฒ', 'ใƒ•': 'ใต', 'ใƒ˜': 'ใธ', 'ใƒ›': 'ใป', 'ใƒž': 'ใพ', 'ใƒŸ': 'ใฟ', 'ใƒ ': 'ใ‚€', 'ใƒก': 'ใ‚', 'ใƒข': 'ใ‚‚', 'ใƒค': 'ใ‚„', 'ใƒฆ': 'ใ‚†', 'ใƒจ': 'ใ‚ˆ', 'ใƒฉ': 'ใ‚‰', 'ใƒช': 'ใ‚Š', 'ใƒซ': 'ใ‚‹', 'ใƒฌ': 'ใ‚Œ', 'ใƒญ': 'ใ‚', 'ใƒฏ': 'ใ‚', 'ใƒฒ': 'ใ‚’', 'ใƒณ': 'ใ‚“', 'ใ‚ฌ': 'ใŒ', 'ใ‚ฎ': 'ใŽ', 'ใ‚ฐ': 'ใ', 'ใ‚ฒ': 'ใ’', 'ใ‚ด': 'ใ”', 'ใ‚ถ': 'ใ–', 'ใ‚ธ': 'ใ˜', 'ใ‚บ': 'ใš', 'ใ‚ผ': 'ใœ', 'ใ‚พ': 'ใž', 'ใƒ€': 'ใ ', 'ใƒ‚': 'ใข', 'ใƒ…': 'ใฅ', 'ใƒ‡': 'ใง', 'ใƒ‰': 'ใฉ', 'ใƒ': 'ใฐ', 'ใƒ“': 'ใณ', 'ใƒ–': 'ใถ', 'ใƒ™': 'ใน', 'ใƒœ': 'ใผ', 'ใƒ‘': 'ใฑ', 'ใƒ”': 'ใด', 'ใƒ—': 'ใท', 'ใƒš': 'ใบ', 'ใƒ': 'ใฝ', 'ใ‚ก': 'ใ', 'ใ‚ฃ': 'ใƒ', 'ใ‚ฅ': 'ใ…', 'ใ‚ง': 'ใ‡', 'ใ‚ฉ': 'ใ‰', 'ใƒฃ': 'ใ‚ƒ', 'ใƒฅ': 'ใ‚…', 'ใƒง': 'ใ‚‡', 'ใƒƒ': 'ใฃ', 'ใƒผ': 'ใƒผ' } hiragana = ''.join([katakana_map.get(char, '') for char in katakana]) return hiragana converted_hiragana = katakana_to_hiragana(katakana) return converted_hiragana == hiragana
def check(candidate): assert candidate("ใ‚ฟใƒŠใ‚ซ", "ใŸใชใ‹") == True assert candidate("ใ‚นใ‚บใ‚ญ", "ใ™ใšใ") == True assert candidate("ใ‚ซใƒƒใƒ‘", "ใ‹ใฃใฑ") == True assert candidate("ใ‚ฟใ‚ซใƒใ‚ท", "ใŸใ‹ใฏใ—") == True assert candidate("ใ‚ฟใƒŠใ‚ซ", "ใชใ‹ใŸ") == False assert candidate("ใ‚ตใƒˆใ‚ฆ", "ใ™ใšใ") == False assert candidate("ใ‚ฌใƒƒใ‚ณใ‚ฆ", "ใ‹ใฃใฑ") == False assert candidate("ใ‚ฟใ‚ซใƒใ‚ท", "ใฏใ—ใ‚‚ใจ") == False
check_katakana_hiragana_match
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
57