task_id stringlengths 4 6 | category stringclasses 8
values | prompt stringlengths 152 1.03k | canonical_solution stringlengths 18 1.32k | test stringlengths 135 1.21k | entry_point stringlengths 2 37 |
|---|---|---|---|---|---|
EN/100 | 日本語処理 | def correct_quotation_bracketing(quotation: str):
""" The argument quotation is a string consisting of '「」'.
If all open square brackets have corresponding close square brackets, it returns True.
>>> correct_quotation_bracketing("「」")
True
>>> correct_quotation_bracketing("「「」「」")
False
"""
| depth = 0
for char in quotation:
if char == "「":
depth += 1
elif char == "」":
depth -= 1
if depth < 0:
return False
return depth == 0
| def check(candidate):
assert candidate("「」")
assert candidate("「「」」")
assert candidate("「」「」")
assert candidate("「」「「」」")
assert not candidate("「")
assert not candidate("」「")
assert not candidate("」」")
assert not candidate("「」「")
assert not candidate("「「」")
| correct_quotation_bracketing |
EN/101 | 日本語処理 | import re
def most_frequent_script(text: str) -> str:
"""
Determines which of hiragana, katakana, or kanji characters occur most frequently in the given string.
The return value is one of ‘hiragana’, ‘katakana’, or ‘kanji’.
Arguments:
text (str): String to be tested
Return value:
... | hiragana = re.findall(r'[ぁ-ん]', text) # 平仮名の正規表現
katakana = re.findall(r'[ァ-ン]', text) # 片仮名の正規表現
kanji = re.findall(r'[一-龯]', text) # 漢字の正規表現
hiragana_count = len(hiragana)
katakana_count = len(katakana)
kanji_count = len(kanji)
m = max(hiragana_count, katakana_count, kanji_count)
i... | def check(candidate):
assert candidate("こんにちは、今日はいい天気ですね。カナカナカナ") == '平仮名'
assert candidate("アイウエオカタカナ") == '片仮名'
assert candidate("漢字を含む文章です") == '漢字'
assert candidate("あいうえおカナ") == '平仮名'
assert candidate("一二三四五六") == '漢字'
assert candidate("あいうえお") == '平仮名'
assert candidate("アイウエオ") == '片仮名... | most_frequent_script |
EN/102 | 日本語処理 | 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 essa... | 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
# 誤ったあいうえお... | validate_aiueo_poem |
EN/103 | 日本語処理 | 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
... | 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/104 | 日本語処理 | def count_kanji(text: str) -> int:
"""
Count the number of kanji in a sentence.
argument:
text (str): the entered text
Return value:
int: number of occurrences of kanji
Usage example:
>>> count_kanji("今日は学校に行きます。")
4
>>> count_kanji("AIが進化する未来は楽しみです。")
4
"""
| return sum(1 for char in text if '一' <= char <= '龥')
| def check(candidate):
assert candidate("今日は学校に行きます。") == 5
assert candidate("AIが進化する未来は楽しみです。") == 5
assert candidate("ひらがなとカタカナだけの文章") == 2
assert candidate("1月2日、私は映画を見た。") == 6
| count_kanji |
EN/105 | 日本語処理 | def sort_numbers(numbers: str) -> str:
"""
The argument is a string of Japanese numbers from ``zero'' to ``nine'' separated by spaces.
Valid Japanese numbers are '', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'. be.
The function returns a string with the numbers sorted ... | japanese_to_number = {
'零': 0, '一': 1, '二': 2, '三': 3,
'四': 4, '五': 5, '六': 6, '七': 7,
'八': 8, '九': 9
}
words = numbers.split()
sorted_numbers = sorted(words, key=lambda x: japanese_to_number[x])
return ' '.join(sorted_numbers)
| def check(candidate):
assert candidate('') == ''
assert candidate('三') == '三'
assert candidate('三 五 九') == '三 五 九'
assert candidate('五 零 四 七 九 八') == '零 四 五 七 八 九'
assert candidate('六 五 四 三 二 一 零') == '零 一 二 三 四 五 六'
| sort_numbers |
EN/106 | 日本語処理 | from collections import Counter
def most_common_kanji(names: list) -> str:
"""
Create a function that identifies the most frequently used Kanji characters from the given name list 'names' and returns the most frequently used Kanji character.
Argument:
- names (list): Name list consisting only of K... | kanji_counts = Counter("".join(names))
most_common = sorted(kanji_counts.items(), key=lambda x: (-x[1], x[0]))[0]
return most_common[0]
| def check(candidate):
assert candidate(["太郎", "花子", "太郎", "一郎"]) == '郎'
assert candidate(["翔太", "翔子", "翔"]) == '翔'
assert candidate(["坂本", "坂田", "坂井", "高坂"]) == '坂'
assert candidate(["太田", "坂本", "高橋", "佐藤"]) == '佐'
assert candidate(["田中", "田村", "田端", "山中", "山村", "山端"]) == '山'
| most_common_kanji |
EN/107 | 日本語処理 | 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"... | # 文字列を分割して、演算の種類と数値を取得
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 ... | 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/108 | 日本語処理 | 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:
>>> pa... | 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/109 | 日本語処理 | def count_same_surnames(names: list) -> dict:
"""
A function that counts the number of identical surnames from a list containing only surnames.
argument:
names (list): List of surnames written in kanji
Return value:
dict: Dictionary of surnames and their occurrences
Usage example:
>>>... | surname_counts = {}
for surname in names:
surname_counts[surname] = surname_counts.get(surname, 0) + 1
return surname_counts
| def check(candidate):
assert candidate(["山田", "山田", "田中", "佐藤", "田中", "山田"]) == {'山田': 3, '田中': 2, '佐藤': 1}
assert candidate(["鈴木", "鈴木", "佐藤", "佐藤", "佐藤", "伊藤"]) == {'鈴木': 2, '佐藤': 3, '伊藤': 1}
assert candidate(["山田"]) == {'山田': 1}
assert candidate(["山田", "田中", "田中", "田中"]) == {'山田': 1, '田中': 3}
ass... | count_same_surnames |
EN/110 | 日本語処理 | def is_smart_sentence(text: str) -> bool:
"""
This function determines whether a statement is smart or unwise.
A smart sentence is one that contains kanji.
argument:
text (str): Japanese text
Return value:
bool: True if the sentence contains kanji, False if it does not
Usage example:
... | for char in text:
if '一' <= char <= '龯': # 漢字のUnicode範囲
return True
return False
| def check(candidate):
assert candidate("私は学校に行きます") == True
assert candidate("名前順に並んでください") == True
assert candidate("自己紹介してください") == True
assert candidate("出席番号を記述してください") == True
assert candidate("おはようございます") == False
assert candidate("コンニチハ") == False
assert candidate("わたしははなこです") == Fals... | is_smart_sentence |
EN/111 | 日本語処理 | import re
def is_yojijukugo(word: str) -> bool:
"""
A function that determines whether a given word is a four-character compound word.
"""
| return bool(re.fullmatch(r'[一-龯]{4}', word))
| def check(candidate):
assert candidate("臨機応変") == True # 4つの漢字から構成
assert candidate("言語道断") == True # 4つの漢字から構成
assert candidate("温故知新") == True # 4つの漢字から構成
assert candidate("一石二鳥") == True # 4つの漢字から構成
assert candidate("四面楚歌") == True # 4つの漢字から構成
assert candidate("サクラサク") == False # カタカナが含... | is_yojijukugo |
EN/112 | 日本語処理 | def time_to_colon_format(time_str: str) -> str:
"""
Converts a time string in the format `XX:XX:XX` to the format `HH:MM:SS`.
Example:
>>> time_to_colon_format(”12時30分45秒“)
‘12:30:45’
>>> time_to_colon_format(”9時5分3秒")
'09:05:03'
"""
| time_str = time_str.replace('時', ':').replace('分', ':').replace('秒', '')
time_parts = time_str.split(":")
time_parts = [part.zfill(2) for part in time_parts]
return ":".join(time_parts)
| def check(candidate):
assert candidate("12時30分45秒") == '12:30:45'
assert candidate("9時5分3秒") == '09:05:03'
assert candidate("0時0分0秒") == '00:00:00'
assert candidate("23時59分59秒") == '23:59:59'
assert candidate("1時1分1秒") == '01:01:01'
| time_to_colon_format |
EN/113 | 日本語処理 | def kanji_to_roman(kanji):
"""
Given a kanji number (from 1 to 9), return a string that is the romanized version of that number.
Ex:
>>> kanji_to_roman("一")
'i'
>>> kanji_to_roman("九")
'ix'
"""
| def int_to_mini_roman(number):
"""
正の整数が与えられたとき、ローマ数字に相当する文字列を小文字で返す。
1 <= num <= 9
"""
num = [1, 4, 5, 9]
sym = ["i", "iv", "v", "ix"]
i = 3
res = ''
while number:
div = number // num[i]
number %= num[i]
... | def check(candidate):
assert candidate("一") == 'i'
assert candidate("二") == 'ii'
assert candidate("三") == 'iii'
assert candidate("四") == 'iv'
assert candidate("五") == 'v'
assert candidate("六") == 'vi'
assert candidate("七") == 'vii'
assert candidate("八") == 'viii'
assert candidate("九"... | kanji_to_roman |
EN/114 | 単位変換 | 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 ... | 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) ... | calculate_tsubo |
EN/115 | 単位変換 | 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)
Usa... | 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/116 | 単位変換 | def tokyo_dome_units(n: int) -> float:
"""
Calculates how many Tokyo Dome areas are covered by the given area `n` and returns the result in two decimal places.
`n` is an integer value representing the area to be calculated in square meters.
The area equivalent to one Tokyo Dome is approximately 46,755 s... | # 東京ドームの床面積(平方メートル)
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/117 | 単位変換 | 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 (appr... | 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/118 | 単位変換 | 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... | 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(9... | find_b_paper_size |
EN/119 | 単位変換 | 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:
... | 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/120 | 単位変換 | 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 num... | 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) == "ほん"
ass... | count_pencils |
EN/121 | 単位変換 | def count_dogs(count: int) -> str:
"""
Express the number of dogs using the correct counting method (pets) in Japanese.
argument:
count (int): Number of dogs.
Return value:
str: Correct Japanese expression (e.g. "1ぴきの犬", "3びきの犬").
"""
| if count in {1, 6, 8, 10}:
suffix = "ぴき"
elif count == 3:
suffix = "びき"
else:
suffix = "ひき"
return f"{count}{suffix}の犬"
| def check(candidate):
assert candidate(1) == "1ぴきの犬"
assert candidate(6) == "6ぴきの犬"
assert candidate(8) == "8ぴきの犬"
assert candidate(10) == "10ぴきの犬"
assert candidate(3) == "3びきの犬"
assert candidate(2) == "2ひきの犬"
assert candidate(4) == "4ひきの犬"
assert candidate(5) == "5ひきの犬"
assert candi... | count_dogs |
EN/122 | 単位変換 | from datetime import datetime, timedelta
def convert_to_timezone(jst_time, timezone):
"""
Convert Japan Standard Time (JST, UTC+9) to the time in the specified time zone.
argument:
jst_time (str): String representing JST date and time (format: "YYYY-MM-DD HH:MM:SS")
timezone (str): Destina... | timezone_offsets = {
"UTC": -9, # 協定世界時 (UTC)
"PST": -17, # 太平洋標準時 (UTC-8)
"EST": -14, # 東部標準時 (UTC-5)
"CET": -8 # 中央ヨーロッパ時間 (UTC+1)
}
jst_datetime = datetime.strptime(jst_time, "%Y-%m-%d %H:%M:%S")
offset = timezone_offsets[timezone]
converted_time = jst_date... | def check(candidate):
assert candidate("2025-01-04 12:00:00", "UTC") == "2025-01-04 03:00:00"
assert candidate("2025-01-04 12:00:00", "PST") == "2025-01-03 19:00:00"
assert candidate("2025-01-04 12:00:00", "EST") == "2025-01-03 22:00:00"
assert candidate("2025-01-04 12:00:00", "CET") == "2025-01-04 04:0... | convert_to_timezone |
EN/123 | 単位変換 | def convert_to_buai(value: float) -> str:
"""
Converts the specified decimal value to a percentage.
Arguments:
value (float): Decimal value (must be between 0.0 and 1.0)
Return value:
str: A string in the format ‘○割○分○厘’
Ex:
>>> convert_to_waribunrin(0.375)
'3割7分5厘'
>>> conver... | total_rin = round(value * 1000) # 1000分率で計算
wari = total_rin // 100 # 割(100厘単位)
remaining_rin = total_rin % 100 # 割を引いた後の厘
bun = remaining_rin // 10 # 分(10厘単位)
rin = remaining_rin % 10 # 残った厘
return f"{wari}割{bun}分{rin}厘"
| def check(candidate):
assert candidate(0.375) == "3割7分5厘"
assert candidate(0.42) == "4割2分0厘"
assert candidate(1.0) == "10割0分0厘"
assert candidate(0.05) == "0割5分0厘"
assert candidate(0.999) == "9割9分9厘"
assert candidate(0.1) == "1割0分0厘"
assert candidate(0.95) == "9割5分0厘"
assert candidate(0.0... | convert_to_buai |
EN/124 | 単位変換 | def calculate_tower_units(height_meters: int) -> float:
"""
Calculates how many Tokyo Towers the specified height is equivalent to.
Arguments:
height_meters (int): Height in meters
Return value:
float: Equivalent number of Tokyo Towers (to one decimal place)
Example usage:
>>>... | tower_height = 333
return round(height_meters / tower_height, 1)
| def check(candidate):
assert candidate(1000) == 3.0
assert candidate(666) == 2.0
assert candidate(333) == 1.0
assert candidate(100) == 0.3
assert candidate(2000) == 6.0
| calculate_tower_units |
EN/125 | 数学・科学 | 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 u... | 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
... | count_ways |
EN/126 | 数学・科学 | def solve_tsurukame(total_animals: int, total_legs: int) -> tuple:
"""
A function that solves Tsurukame arithmetic. Find 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 exam... | 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... | solve_tsurukame |
EN/127 | 数学・科学 | 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 o... | # 角度をラジアンに変換
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/128 | 数学・科学 | 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 ... | 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/129 | 数学・科学 | 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 to Kyoto and the y... | 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/130 | 数学・科学 | 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
... | 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/131 | 数学・科学 | def total_bales_of_rice(n: int) -> int:
"""
Rice bales are stacked sideways in n bales, 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:
... | 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/132 | 数学・科学 | 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... | 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/133 | 数学・科学 | 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が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,... | can_measure_water |
EN/134 | 数学・科学 | 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 purchas... | 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/135 | 数学・科学 | 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 nu... | 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/136 | 数学・科学 | 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... | 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) == ... | next_pigeon_clock_time |
EN/137 | 数学・科学 | 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... | 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,... | calculate_coin_change |
EN/138 | 数学・科学 | 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 (in... | 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
... | find_next_fireworks_time |
EN/139 | 数学・科学 | def is_valid_sudoku(board: list) -> bool:
"""
A function that determines whether or not a 9×9 Sudoku puzzle is correct.
Arguments:
board (list): 9×9 two-dimensional list (integers 1 to 9)
Return value:
bool: True if the solution is correct, False if there are errors
"""
| def is_valid_group(group):
return sorted(group) == list(range(1, 10))
for row in board: # 行のチェック
if not is_valid_group(row):
return False
for col in zip(*board): # 列のチェック
if not is_valid_group(list(col)):
return False
for i in range(0, 9, 3): # 3... | def check(candidate):
assert candidate([
[5, 3, 4, 6, 7, 8, 9, 1, 2],
[6, 7, 2, 1, 9, 5, 3, 4, 8],
[1, 9, 8, 3, 4, 2, 5, 6, 7],
[8, 5, 9, 7, 6, 1, 4, 2, 3],
[4, 2, 6, 8, 5, 3, 7, 9, 1],
[7, 1, 3, 9, 2, 4, 8, 5, 6],
[9, 6, 1, 5, 3, 7, 2, 8, 4],
[2, 8, 7... | is_valid_sudoku |
EN/140 | 数学・科学 | def calculate_salt_solution_concentration(salt: float, water: float) -> float:
"""
Calculate the concentration of the 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... | 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/141 | 数学・科学 | 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:
... | 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/142 | 数学・科学 | 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:
... | 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 "藍"
... | 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/143 | 数学・科学 | 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 ... | 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/144 | 数学・科学 | def celsius_to_fahrenheit(celsius: float) -> float:
"""
Converts a temperature in degrees Celsius (°C) to degrees Fahrenheit (°F).
Arguments:
celsius (float): Temperature in degrees Celsius
Return value:
float: Temperature in degrees Fahrenheit (to one decimal place)
"""
| fahrenheit = celsius * 1.8 + 32
return round(fahrenheit, 1)
| def check(candidate):
assert candidate(0) == 32.0
assert candidate(100) == 212.0
assert candidate(-40) == -40.0
assert candidate(37) == 98.6
assert candidate(20) == 68.0
assert candidate(50) == 122.0
assert candidate(-10) == 14.0
assert candidate(30) == 86.0
assert candidate(-273.15)... | celsius_to_fahrenheit |
EN/145 | 数学・科学 | def bf(planet1: str, planet2: str) -> tuple:
"""
Considering the eight planets of the solar system, all planets located between two planets
Returns a tuple ordered by proximity to the sun.
If planet1 or planet2 is an invalid planet name, returns an empty tuple.
argument:
planet1 (str):... | planet_names = ("水星", "金星", "地球", "火星", "木星", "土星", "天王星", "海王星")
if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2:
return ()
planet1_index = planet_names.index(planet1)
planet2_index = planet_names.index(planet2)
if planet1_index < planet2_index:
r... | def check(candidate):
# 簡単なケースをチェック
assert candidate("木星", "海王星") == ("土星", "天王星"), "最初のテストエラー: " + str(len(candidate("木星", "海王星")))
assert candidate("地球", "水星") == ("金星",), "2番目のテストエラー: " + str(candidate("地球", "水星"))
assert candidate("水星", "天王星") == ("金星", "地球", "火星", "木星", "土星"), "3番目のテストエラー: " + str... | bf |
EN/146 | 公民・法律 | 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 takeo... | 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/147 | 公民・法律 | 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 for each person.
argument:
mynumber (str): My number (string format)
Return value:
bool: True if the format is correct, False ot... | 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/148 | 公民・法律 | 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 otherwi... | # 生年月日と現在の日付を分割し、整数に変換
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
... | 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/149 | 公民・法律 | from datetime import datetime
def years_until_voting_right(birth_year: int) -> int:
"""
Calculates the number of years from the year of birth to the age at which one has the right to vote (18 years old).
Arguments:
birth_year (int): Year of birth
Return:
int: Number of years until t... | current_year = datetime.now().year
voting_age = 18
age_at_voting = birth_year + voting_age
if age_at_voting <= current_year:
return 0
else:
return age_at_voting - current_year
| def check(candidate):
assert candidate(2000) == 0
assert candidate(2005) == 0
assert candidate(2006) == 0
assert candidate(2007) == 0
assert candidate(2008) == 1
assert candidate(2009) == 2
assert candidate(2010) == 3
assert candidate(2015) == 8
assert candidate(2020) == 13
| years_until_voting_right |
EN/150 | 公民・法律 | 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 dig... | # 文字列の長さが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/151 | 公民・法律 | 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
argum... | 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/152 | 公民・法律 | import re
def normalize_postal_code(postal_code: str) -> str:
"""
A function that unifies the notation of postal codes.
・Remove 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. '12345... | postal_code = re.sub(r'\s+|〒', '', postal_code)
full_width_to_half_width = str.maketrans(
'0123456789-',
'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") == '123-4567'
assert candidate("1234567") == '123-4567'
assert candidate(" 123 4567 ") == '123-4567'
assert candidate("〒1234567") == '123-4567'
assert candidate("123 4567") == '123-4567'
assert candidate("123-4567") == '123-4567'
assert cand... | normalize_postal_code |
EN/153 | 公民・法律 | 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 ... | # 投票結果を集計する辞書を作成
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
... | 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... | count_votes |
EN/154 | 公民・法律 | 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:
... | 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
a... | is_mobile_phone |
EN/155 | 公民・法律 | def convert_currency(exchange_rate, amount):
"""
A function that converts Japanese yen to foreign currency.
argument:
exchange_rate (float): Exchange rate from Japanese yen to foreign currency.
amount (int): Amount in Japanese yen.
Return value:
float: The converted amount (up ... | return round(amount * exchange_rate, 2)
| def check(candidate):
assert candidate(0.007, 1000) == 7.0
assert candidate(0.006, 500) == 3.0
assert candidate(0.005, 200) == 1.0
assert candidate(0.007, 1) == 0.01
| convert_currency |
EN/156 | 公民・法律 | def check_separation_of_powers(student_answers: dict) -> str:
"""
Your job is to judge whether the answers submitted by students to questions about the separation of powers ('student_answers') are correct or incorrect, and to return model answers if they are incorrect.
determine whether the answer is correc... | correct_answers = {"内閣": "行政権","国会": "立法権","裁判所": "司法権"}
if dict(sorted(student_answers.items())) == correct_answers:
return "全問正解"
else:
return str(correct_answers)
| def check(candidate):
# "全問正解"
assert candidate({"国会": "立法権", "内閣": "行政権", "裁判所": "司法権"}) == "全問正解"
assert candidate({"内閣": "行政権", "裁判所": "司法権", "国会": "立法権"}) == "全問正解"
assert candidate({"裁判所": "司法権", "内閣": "行政権", "国会": "立法権"}) == "全問正解"
# '{"内閣": "行政権","国会": "立法権","裁判所": "司法権"}'
answers = str({... | check_separation_of_powers |
EN/157 | その他 | def utf8_to_japanese_string(byte_data: bytes) -> str:
"""
A function that converts a UTF-8 byte string to a Japanese character string.
argument:
byte_data (bytes): UTF-8 byte string
Return value:
str: decoded Japanese string
Usage example:
>>> utf8_to_japanese_string(b'\xe3\x81\x93\xe... | return byte_data.decode('utf-8')
| def check(candidate):
assert candidate(b'\xe3\x81\x8a\xe3\x81\xaf\xe3\x82\x88\xe3\x81\x86') == 'おはよう'
assert candidate(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf') == 'こんにちは'
assert candidate(b'\xe3\x81\x82\xe3\x82\xa2\xe6\xbc\xa2') == 'あア漢'
assert candidate(b'\xe3\x81\x93\xe3\x82\x9... | utf8_to_japanese_string |
EN/158 | その他 | def convert_japanese_text(text: str, encoding: str = 'utf-8') -> bytes:
"""
A function that converts a Japanese string to the specified character code.
argument:
text (str): Japanese string
encoding (str): encoding to convert to (default is UTF-8)
Return value:
bytes: converted byte string... | return text.encode(encoding) | def check(candidate):
# 1. UTF-8エンコード
assert candidate('こんにちは', 'utf-8') == b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' # こんにちは
assert candidate('おはよう', 'utf-8') == b'\xe3\x81\x8a\xe3\x81\xaf\xe3\x82\x88\xe3\x81\x86' # おはよう
assert candidate('ひらがな', 'utf-8') == b'\xe3\x81\xb2\xe3\x8... | convert_japanese_text |
EN/159 | その他 | 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 o... | 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/160 | その他 | 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 g... | 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/161 | その他 | def remove_vowels(text):
"""
remove_vowels is a function that takes a string containing only hiragana as an argument and returns the string without vowels.
example:
>>> remove_vowels('')
''
>>> remove_vowels('あいうえお')
''
>>> remove_vowels('あいうえおかきくけこ')
'かきくけこ'
"""
| vowels = 'あいうえお'
return ''.join(char for char in text if char not in vowels)
| def check(candidate):
assert candidate('') == ''
assert candidate('あいうえお') == ''
assert candidate('かきくけこ') == 'かきくけこ'
assert candidate('さしすせそ') == 'さしすせそ'
assert candidate('たちつてと') == 'たちつてと'
assert candidate('あいうえおかきくけこ') == 'かきくけこ'
assert candidate('あかいさうたえなおは') == 'かさたなは'
| remove_vowels |
EN/162 | その他 | 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 numbe... | 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枚のチケットがあります。") == [1... | extract_numbers_from_text |
EN/163 | その他 | def fizz_buzz(n: int) -> str:
"""
A function that returns the number of times the number 7 appears among integers less than n that are divisible by 11 or 13.
example:
>>> fizz_buzz(50)
'0 times'
>>> fizz_buzz(78)
'twice'
>>> fizz_buzz(79)
'3 times'
"""
| count = 0
for i in range(n):
if i % 11 == 0 or i % 13 == 0:
count += str(i).count('7')
return f'{count}回'
| METADATA = {}
def check(candidate):
assert candidate(50) == '0回'
assert candidate(78) == '2回'
assert candidate(79) == '3回'
assert candidate(100) == '3回'
assert candidate(200) == '6回'
assert candidate(4000) == '192回'
assert candidate(10000) == '639回'
assert candidate(100000) == '8026回'
| fizz_buzz |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.