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