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/100
def deduplicate_sentences(text: str) -> str: """ Divide a given Japanese sentence at the period mark "." and remove duplicate sentences. argument: text (str): Japanese text to remove duplicates. Return value: str: A sentence containing unique sentences with duplicates removed. """
sentences = text.split("。") unique_sentences = [] seen = set() for sentence in sentences: stripped_sentence = sentence.strip() if stripped_sentence and stripped_sentence not in seen: seen.add(stripped_sentence) unique_sentences.append(stripped_sentence) return "。".join(unique_sentences) + ("。" if unique_sentences else "")
def check(candidate): assert candidate("私は猫が好きです。猫は可愛いです。私は猫が好きです。") == "私は猫が好きです。猫は可愛いです。" assert candidate("明日は晴れるといいですね。晴れるといいですね。") == "明日は晴れるといいですね。晴れるといいですね。" assert candidate("東京は楽しいです。東京は楽しいです。") == "東京は楽しいです。" assert candidate("これはテストです。これはテストです。これは新しい文章です。") == "これはテストです。これは新しい文章です。" assert candidate("文が一つだけあります。") == "文が一つだけあります。"
deduplicate_sentences
en/101
def convert_to_manyo_gana(text: str) -> str: """ A function that converts a given string to Manyogana. Convert each Hiragana character to its Manyogana counterpart. Here, we will perform a temporary and simple conversion. For example, 「あ」is「安」、「い」is「以」、「う」is「宇」. argument: text (str): String containing hiragana. Return value: str: String converted to Manyogana. Usage example: 使用例: >>> convert_to_manyo_gana("あいう") '安以宇' """
hira_to_manyo = { 'あ': '安', 'い': '以', 'う': '宇', 'え': '衣', 'お': '於', 'か': '加', 'き': '幾', 'く': '久', 'け': '計', 'こ': '己', 'さ': '左', 'し': '之', 'す': '須', 'せ': '世', 'そ': '曽', 'た': '多', 'ち': '知', 'つ': '川', 'て': '天', 'と': '止', 'な': '奈', 'に': '仁', 'ぬ': '奴', 'ね': '祢', 'の': '乃', 'は': '波', 'ひ': '比', 'ふ': '布', 'へ': '部', 'ほ': '保', 'ま': '末', 'み': '美', 'む': '武', 'め': '女', 'も': '毛', 'や': '也', 'ゆ': '由', 'よ': '与', 'ら': '良', 'り': '利', 'る': '留', 'れ': '礼', 'ろ': '呂', 'わ': '和', 'ゐ': '為', 'ゑ': '恵', 'を': '遠', 'ん': '無' } result = [] for char in text: result.append(hira_to_manyo.get(char)) return ''.join(result)
def check(candidate): assert candidate("あいう") == '安以宇' assert candidate("かきくけこ") == '加幾久計己' assert candidate("さしすせそ") == '左之須世曽' assert candidate("たちつてと") == '多知川天止' assert candidate("なにぬねの") == '奈仁奴祢乃' assert candidate("はひふへほ") == '波比布部保' assert candidate("まみむめも") == '末美武女毛' assert candidate("やゆよ") == '也由与' assert candidate("らりるれろ") == '良利留礼呂' assert candidate("わゐゑをん") == '和為恵遠無'
convert_to_manyo_gana
en/102
def extract_hiragana(text: str) -> str: """ A function that extracts and returns only hiragana from a string `text`. argument: text (str): input string Return value: str: String with only hiragana extracted Example: >>> extract_hiragana("こんにちは。") 'こんにちは' >>> extract_hiragana("今日はいい天気ですね。") 'はいいですね' """
return ''.join(char for char in text if 'ぁ' <= char <= 'ん')
def check(candidate): assert candidate("") == '' assert candidate("こんにちは。") == 'こんにちは' assert candidate("今日はいい天気ですね。") == 'はいいですね' assert candidate("こんにちは。今日はいい天気ですね。") == 'こんにちははいいですね' assert candidate("ひらがなカタカナ漢字") == 'ひらがな' assert candidate("ひらがな、Hiragana、hiragana") == 'ひらがな'
extract_hiragana
en/103
def sort_japanese_characters(text: str) -> str: """ A function that receives a string, sorts and combines hiragana, katakana, kanji, and alphabets. argument: text (str): input string Return value: str: string of characters arranged in hiragana, katakana, kanji, alphabetical order Usage example: >>> sort_japanese_characters("ひらがな") 'がなひら' >>> sort_japanese_characters("ひらがなカタカナ漢字Alphabet") 'がなひらカカタナ字漢Aabehlpt' """
hiragana = sorted([char for char in text if 'ぁ' <= char <= 'ん']) katakana = sorted([char for char in text if 'ァ' <= char <= 'ヶ']) kanji = sorted([char for char in text if '一' <= char <= '龯']) alphabet = sorted([char for char in text if 'A' <= char <= 'Z' or 'a' <= char <= 'z']) return ''.join(hiragana + katakana + kanji + alphabet)
def check(candidate): assert candidate("ひらがな") == "がなひら" assert candidate("カタカナ") == "カカタナ" assert candidate("漢字") == "字漢" assert candidate("Alphabet") == "Aabehlpt" assert candidate("ひらがなカタカナ漢字Alphabet") == "がなひらカカタナ字漢Aabehlpt"
sort_japanese_characters
en/104
def count_onsen_symbols(text: str) -> int: """ Counts and returns the number of hot spring symbols "♨️" from the input string. Args: text (str): input string Returns: int: Number of hot spring symbols “♨️” """
return text.count('♨️')
def check(candidate): assert candidate("♨️") == 1 assert candidate("♨️♨️♨️♨️♨️") == 5 assert candidate("♨️あ♨️い♨️う♨️え♨️お♨️") == 6 assert candidate("♨️温泉に入りましょう♨️") == 2
count_onsen_symbols
en/105
def count_sentences(text: str) -> int: """ A function that counts how many Japanese sentences there are. Sentences are defined to be separated by one of "。", "!", or "?". argument: text (str): input Japanese text Return value: int: number of sentences Usage example: >>> count_sentences("") 0 >>> count_sentences("おはようございます。") 1 >>> count_sentences("今日はいい天気ですね。明日も晴れるといいですね!") 2 """
if not text: return 0 sentences = [sentence for sentence in text.split('。') if sentence] # 「。」で分割 temp_sentences = [] for sentence in sentences: temp_sentences.extend([s for s in sentence.split('!') if s]) # 「!」でさらに分割 final_sentences = [] for sentence in temp_sentences: final_sentences.extend([s for s in sentence.split('?') if s]) # 「?」でさらに分割 return len(final_sentences)
def check(candidate): assert candidate("") == 0 assert candidate("おはようございます。") == 1 assert candidate("今日はいい天気ですね。明日も晴れるといいですね!") == 2 assert candidate("おはよう!今日は何から始めようか?") == 2 assert candidate("おはようございます。今日はいい天気ですね!明日の天気はいかがでしょうか?") == 3
count_sentences
en/106
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\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf') 'こんにちは' """
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\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf\xe3\x80\x81\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf\xe5\xa4\xa9\xe6\xb0\x97\xe3\x81\x8c\xe3\x81\x84\xe3\x81\x84\xe3\x81\xa7\xe3\x81\x99\xe3\x81\xad\xe3\x80\x82') == 'こんにちは、今日は天気がいいですね。'
utf8_to_japanese_string
en/107
def convert_to_japanese_time(hour: int, minute: int) -> str: """ A function that converts the time (hour, minute) in 24-hour notation to Japanese notation for AM/PM. argument: hour (int): Time in 24-hour notation (0 <= hour < 24) minute (int): minute (0 <= minute < 60) Return value: str: Japanese notation for AM/PM hours (e.g. "10:30 AM", "2:15 PM") """
if 0 <= hour < 12: # 午前 meridian = "午前" display_hour = hour if hour != 0 else 0 # 0時はそのまま0時 else: # 午後 meridian = "午後" display_hour = hour - 12 if hour != 12 else 12 # 12時はそのまま12時 return f"{meridian}{display_hour}時{minute}分"
def check(candidate): assert candidate(0, 0) == '午前0時0分' assert candidate(0, 15) == '午前0時15分' assert candidate(11, 59) == '午前11時59分' assert candidate(12, 0) == '午後12時0分' assert candidate(12, 30) == '午後12時30分' assert candidate(23, 59) == '午後11時59分' assert candidate(14, 30) == '午後2時30分' assert candidate(1, 1) == '午前1時1分' assert candidate(13, 45) == '午後1時45分' assert candidate(11, 0) == '午前11時0分' assert candidate(18, 15) == '午後6時15分' assert candidate(21, 30) == '午後9時30分'
convert_to_japanese_time
en/108
def check_season(seasons: list, target: str) -> str: """ Determines whether the given season is included in the given list. argument: seasons (list): list of seasons (e.g. ['Spring', 'Summer', 'Autumn', 'Winter']) target (str): Season to judge (e.g. 'summer') Return value: str: Returns "含まれている" if the season is included, otherwise returns "含まれていない" Usage example: >>> check_season(['春', '夏', '秋', '冬'], '夏') '含まれている' >>> check_season(['春', '秋'], '夏') '含まれていない' >>> check_season([], '冬') '含まれていない' >>> check_season(['夏'], '夏') '含まれている' """
if target in seasons: return '含まれている' return '含まれていない'
def check(candidate): assert candidate(['春', '夏', '秋', '冬'], '夏') == '含まれている' assert candidate(['春', '秋'], '秋') == '含まれている' assert candidate(['夏'], '夏') == '含まれている' assert candidate(['春', '秋'], '夏') == '含まれていない' assert candidate(['冬'], '秋') == '含まれていない' assert candidate(['あ', 'い', 'う', 'え', 'お'], '秋') == '含まれていない' assert candidate(['夏'], '冬') == '含まれていない'
check_season
en/109
def count_particles(text: str) -> int: """ Create a function that counts the number of occurrences of particles (``ga'', ``no'', ``ha'', ``wo'', and ``ni'') in Japanese sentences. argument: text (str): Japanese text Return value: int: Number of particle occurrences Usage example: >>> count_particles("私は学校に行きます。") 2 """
particles = ['が', 'の', 'は', 'を', 'に'] count = 0 for particle in particles: count += text.count(particle) return count
def check(candidate): assert candidate("私は学校に行きます。") == 2 assert candidate("今日の天気は良いです。") == 2 assert candidate("AIは世界を変える。") == 2 assert candidate("がががののははをを") == 9 assert candidate("これは助詞が含まれていません。") == 2
count_particles
en/110
def is_keigo(text: str) -> bool: """ A function that determines whether the input sentence is honorific language (ending in "ます" or "です"). argument: text (str): Japanese text Return value: bool: Returns True if the sentence is honorific (ending with "ます" or "です"), otherwise returns false. Usage example: >>> is_keigo("私は学校に行きます。") True >>> is_keigo("今日はいい天気だね。") False >>> is_keigo("お手伝いさせていただきます。") True """
if text.endswith('ます。') or text.endswith('です。'): return True return False
def check(candidate): assert candidate("私は学校に行きます。") == True assert candidate("今日はいい天気だね。") == False assert candidate("お手伝いさせていただきます。") == True assert candidate("昨日の天気は悪かった。") == False assert candidate("今日は天気がいいです。") == True assert candidate("彼は走るのが早い。") == False assert candidate("AIは進化しています。") == True assert candidate("すごいね!") == False
is_keigo
en/111
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: >>> is_smart_sentence("私は学校に行きます。") True >>> is_smart_sentence("あいうえお") False """
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("わたしははなこです") == False assert candidate("わすれものした") == False
is_smart_sentence
en/112
def is_two_char_shiritori_valid(words: list) -> bool: """ A function that determines whether the two-character shiritori rule is satisfied. rule: - The "last two letters" of each word must exactly match the "first two letters" of the next word. argument: words (list): list of 2-letter shiritori words Return value: bool: True if two-character shiritori is established, otherwise False Usage example: >>> is_two_char_shiritori_valid(["しりとり", "とりくち", "くちばし", "ばしょ"]) True >>> is_two_char_shiritori_valid(["たぬき", "きつね", "ねこ", "こいぬ"]) False """
for i in range(len(words) - 1): if len(words[i]) < 2 or len(words[i + 1]) < 2: return False if words[i][-2:] != words[i + 1][:2]: return False return True
def check(candidate): assert candidate(["しりとり", "とりくち", "くちばし", "ばしょ"]) == True assert candidate(["たぬき", "きつね", "ねこ", "こいぬ"]) == False assert candidate(["ねこ", "こたつ", "つみき", "きのこ"]) == False assert candidate(["しりとり", "とりくち", "くちびる", "びるど"]) == True
is_two_char_shiritori_valid
en/113
def next_katakana(char: str) -> str: """ A function that returns the character following the specified character in a katakana table. If the specified character is the last character ('ン'), it will return to the first character ('a'). argument: char (str): 1 character katakana Return value: str: next katakana character Usage example: >>> next_katakana("ア") 'イ' >>> next_katakana("ン") 'ア' >>> next_katakana("カ") 'キ' >>> next_katakana("ヲ") 'ン' """
katakana_list = ['ア', 'イ', 'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ', 'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 'マ', 'ミ', 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヲ', 'ン'] index = katakana_list.index(char) next_index = (index + 1) % len(katakana_list) # 最後の文字の次は最初の文字 return katakana_list[next_index]
def check(candidate): assert candidate("ア") == 'イ' assert candidate("カ") == 'キ' assert candidate("ヲ") == 'ン' assert candidate("ン") == 'ア' assert candidate("ソ") == 'タ' assert candidate("ヨ") == 'ラ' assert candidate("ン") == 'ア' assert candidate("ホ") == 'マ' assert candidate("ワ") == 'ヲ'
next_katakana
en/114
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 last names Return value: dict: Dictionary of surnames and their occurrences Usage example: >>> count_same_surnames(["山田", "山田", "田中", "佐藤", "田中", "山田"]) {'山田': 3, '田中': 2, '佐藤': 1} >>> count_same_surnames(["鈴木", "鈴木", "佐藤", "佐藤", "佐藤", "伊藤"]) {'鈴木': 2, '佐藤': 3, '伊藤': 1} """
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} assert candidate(["伊藤", "伊藤", "伊藤", "伊藤", "伊藤"]) == {'伊藤': 5} assert candidate(["佐藤"]) == {'佐藤': 1} assert candidate(["佐藤", "佐藤", "佐藤"]) == {'佐藤': 3} assert candidate(["王", "王", "王"]) == {'王': 3} assert candidate(["中村", "中村", "中村", "田中"]) == {'中村': 3, '田中': 1}
count_same_surnames
en/115
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/116
import re def remove_english_and_numbers(text: str) -> str: """ A function that removes all letters, numbers, and spaces in a sentence. argument: text (str): string to process Return value: str: new string with letters, numbers, and spaces removed Usage example: >>> remove_english_and_numbers("今日は晴れです。") '今日は晴れです。' >>> remove_english_and_numbers("Today's weather is sunny.") '' """
return re.sub(r'[A-Za-z0-9\s]', '', text)
def check(candidate): assert candidate("今日は晴れです。") == '今日は晴れです。' assert candidate("The weather today is clear") == '' assert candidate("12345") == '' assert candidate("ABC123あいうえお") == 'あいうえお'
remove_english_and_numbers
en/117
def calculate_hiragana_percentage(text: str) -> int: """ A function that calculates the proportion of hiragana in text as a percentage (integer). argument: text (str): text consisting of romaji and hiragana Return value: int: Hiragana percentage (0 to 100) Usage example: >>> calculate_hiragana_percentage("今日は晴れです。") 50 >>> calculate_hiragana_percentage("ひらがな") 100 """
if len(text) == 0: return 0 total_chars = len(text) hiragana_count = sum(1 for char in text if '\u3040' <= char <= '\u309f') percentage = (hiragana_count / total_chars) * 100 return int(percentage) # 小数点以下を切り捨て
def check(candidate): assert candidate("今日は晴れです。") == 50 assert candidate("ひらがな") == 100 assert candidate("ひらがなカタカナ漢字") == 40 assert candidate("お花畑の近くでお絵描きをする") == 64 assert candidate("漢字") == 0
calculate_hiragana_percentage
en/118
def is_valid_reverse_shiritori(words: list) -> bool: """ A function that determines whether a list of hiragana satisfies the reverse shiritori rules. Gyaku-shiritori places the first letter of the previous word at the end of the next word. argument: words (list): list of hiragana words Return value: bool: True if the reverse rules are met, False if not Usage example: >>> is_valid_reverse_shiritori(["りんご", "ちり", "しゃち", "かし"]) True >>> is_valid_reverse_shiritori(["りんご", "ごりら", "らっぱ", "ぱせり"]) False """
for i in range(1, len(words)): if words[i-1][0] != words[i][-1]: return False return True
def check(candidate): assert candidate(["りんご", "ちり", "しゃち", "かし"]) == True assert candidate(["ごりら", "りんご", "くり", "きく", "かき"]) == True assert candidate(["らっぱ", "さら", "ささ", "せんさ"]) == True assert candidate(["りんご", "ごりら", "らっぱ", "ぱせり"]) == False assert candidate(["ごりら", "らっこ", "こども", "もも"]) == False
is_valid_reverse_shiritori
en/119
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 # カタカナが含まれている assert candidate("ひらがな") == False # 平仮名のみ assert candidate("ABC") == False # 英字のみ assert candidate("言語") == False # 2つの漢字だけ
is_yojijukugo
en/120
def reverse_japanese_text(text: str) -> str: """ A function that reverses a string. Usage example: >>> reverse_japanese_text("おはようございます") 'すまいざごうよはお' >>> reverse_japanese_text("漢字とひらがな") 'ながらひと字漢' """
return text[::-1]
def check(candidate): assert candidate("おはようございます") == 'すまいざごうよはお' assert candidate("漢字とひらがな") == 'ながらひと字漢' assert candidate("たけやぶやけた") == 'たけやぶやけた' assert candidate("こんにちは世界") == '界世はちにんこ' assert candidate("あいうえお") == 'おえういあ' assert candidate("カタカナひらがな漢字") == '字漢ながらひナカタカ' assert candidate("わをん") == 'んをわ'
reverse_japanese_text
en/121
from typing import List, Dict def count_emoji_occurrences(text: str, emoji_list: List[str]) -> Dict[str, int]: """ Counts the number of occurrences of an emoji in the given text, based on the specified list of emoji. argument: text (str): input text emoji_list (List[str]): List of emojis to count Return value: Dict[str, int]: Dictionary indicating the number of occurrences of each emoji Usage example: >>> count_emoji_occurrences("🍎🍏🍎🍇🍉🍉🍎", ["🍎", "🍉", "🍇"]) {'🍎': 3, '🍉': 2, '🍇': 1} >>> count_emoji_occurrences("🎉🎉🎉🎂🎂🎂🎂", ["🎉", "🎂", "🎈"]) {'🎉': 3, '🎂': 4, '🎈': 0} >>> count_emoji_occurrences("🌟✨💫🌟🌟✨", ["🌟", "✨", "💫"]) {'🌟': 3, '✨': 2, '💫': 1} """
emoji_counts = {emoji: 0 for emoji in emoji_list} # 指定された絵文字をすべて0で初期化 for char in text: if char in emoji_counts: emoji_counts[char] += 1 return emoji_counts
def check(candidate): assert candidate("🍎🍏🍎🍇🍉🍉🍎", ["🍎", "🍉", "🍇"]) == {'🍎': 3, '🍉': 2, '🍇': 1} assert candidate("🎉🎉🎉🎂🎂🎂🎂", ["🎉", "🎂", "🎈"]) == {'🎉': 3, '🎂': 4, '🎈': 0} assert candidate("🌟✨💫🌟🌟✨", ["🌟", "✨", "💫"]) == {'🌟': 3, '✨': 2, '💫': 1} assert candidate("", ["🎉", "🎂", "🎈"]) == {'🎉': 0, '🎂': 0, '🎈': 0} assert candidate("🍎🍏🍎🍇🍉🍉🍎", ["🍎", "🍏", "🍇", "🍉", "🍌"]) == {'🍎': 3, '🍏': 1, '🍇': 1, '🍉': 2, '🍌': 0} assert candidate("🎂🎂🎂🎂🎂", ["🎉", "🎂", "🎈"]) == {'🎉': 0, '🎂': 5, '🎈': 0} assert candidate("🍎🍎🍎", ["🍎"]) == {'🍎': 3} assert candidate("🍕🍕🍔🍔🍟🍟", ["🍕", "🍔", "🍟", "🌭"]) == {'🍕': 2, '🍔': 2, '🍟': 2, '🌭': 0} assert candidate("🍣🍣🍣🍣", ["🍣", "🍚", "🍛"]) == {'🍣': 4, '🍚': 0, '🍛': 0} assert candidate("💖💖💖💖💖", ["💖", "💗", "💕"]) == {'💖': 5, '💗': 0, '💕': 0}
count_emoji_occurrences
en/122
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 Usage example: >>> convert_japanese_text('こんにちは', 'utf-8') b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' >>> convert_japanese_text('漢字', 'shift_jis') b'\x8a\xbf\x8e\x9a' >>> convert_japanese_text('テスト', 'euc-jp') b'\xa5\xc6\xa5\xb9\xa5\xc8' """
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\x82\x89\xe3\x81\x8c\xe3\x81\xaa' # ひらがな # 2. Shift-JISエンコード assert candidate('こんにちは', 'shift_jis') == b'\x82\xb1\x82\xf1\x82\xc9\x82\xbf\x82\xcd' # こんにちは assert candidate('おはよう', 'shift_jis') == b'\x82\xa8\x82\xcd\x82\xe6\x82\xa4' # おはよう assert candidate('漢字', 'shift_jis') == b'\x8a\xbf\x8e\x9a' # 漢字 # 3. EUC-JPエンコード assert candidate('こんにちは', 'euc-jp') == b'\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4\xcf' # こんにちは assert candidate('テスト', 'euc-jp') == b'\xa5\xc6\xa5\xb9\xa5\xc8' # テスト assert candidate('日本語', 'euc-jp') == b'\xc6\xfc\xcb\xdc\xb8\xec' # 日本語
convert_japanese_text
en/123
import re def is_haiku(haiku: str) -> bool: """ Determines whether the given string is in 5-7-5 haiku form. Note: Inputs other than hiragana do not need to be considered. Also, one hiragana character is counted as one sound. argument: haiku (str): Hiragana string separated by spaces for each phrase Return value: bool: True if 5-7-5 format, False otherwise """
parts = haiku.split() if len(parts) != 3: return False syllable_count = [len(re.findall(r'[ぁ-ん]', part)) for part in parts] return syllable_count == [5, 7, 5]
def check(candidate): assert candidate("はるかぜや どこかへとんだ ふうせんが") == True assert candidate("ふるいけや かわずとびこむ みずのおと") == True assert candidate("しずけさや いわにしみいる せみのこえ") == True assert candidate("なつくさや つわものどもが ゆめのあと") == True assert candidate("ふるいけ かわず みず") == False assert candidate("はる かぜや どこ かへとん だふうせ んが") == False assert candidate("あいうえお あいうえおあい あいうえお") == True assert candidate("しずけさや いわにしみいる せみの声") == False assert candidate("こんにちは 世界 どうも") == False assert candidate("あきのよる") == False assert candidate("ふるいけや かわずとびこむ みずのおとほげ") == False
is_haiku
en/124
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
en/125
def solve(s): """ A string s is given. If s[i] is hiragana or katakana, convert that character (hiragana to katakana, katakana to hiragana). If it contains other characters, leave it as is. If the string does not contain any hiragana or katakana characters, reverse the entire string. The function returns a string of results. example: >>> solve("1234") '4321' >>> solve("あい") 'アイ' >>> solve("#あ@イ") '#ア@い' """
flg = 0 idx = 0 new_str = list(s) for i in s: if 'ぁ' <= i <= 'ん': # ひらがなをカタカナに変換 new_str[idx] = chr(ord(i) - ord('ぁ') + ord('ァ')) flg = 1 elif 'ァ' <= i <= 'ン': # カタカナをひらがなに変換 new_str[idx] = chr(ord(i) - ord('ァ') + ord('ぁ')) flg = 1 idx += 1 s = "".join(new_str) if flg == 0: return s[::-1] return s
def check(candidate): # 簡単なケースをチェック assert candidate("あい") == "アイ" assert candidate("1234") == "4321" assert candidate("アカ") == "あか" assert candidate("#あ@イ") == "#ア@い" assert candidate("#あいウエ^45") == "#アイうえ^45" assert candidate("#6@2") == "2@6#" # 境界ケースをチェック assert candidate("#$あ^カ") == "#$ア^か" assert candidate("#あああ") == "#アアア" assert candidate("かきくけこ") == "カキクケコ" assert candidate("アイウエオ") == "あいうえお" assert candidate("123456") == "654321"
solve
en/126
def fix_spaces(text): """ Given a string text, replace all spaces in it with underscores (_), If the string has two or more consecutive spaces, replace all consecutive spaces with hyphens (-). example: >>> fix_spaces("Example 1") 'Example 1' >>> fix_spaces("Example 1") 'Example_1' >>> fix_spaces("Example 1") 'Example-1' """
new_text = "" i = 0 start, end = 0, 0 while i < len(text): if text[i] == " ": end += 1 else: if end - start >= 2: new_text += "-" + text[i] elif end - start > 0: new_text += "_" * (end - start) + text[i] else: new_text += text[i] start, end = i + 1, i + 1 i += 1 if end - start > 2: new_text += "-" elif end - start > 0: new_text += "_" return new_text
def check(candidate): assert candidate("例") == "例" assert candidate("例1") == "例1" assert candidate("例 1") == "例_1" assert candidate("例 1") == "例-1" assert candidate("例 1 2") == "例-1-2" assert candidate(" 例 1 2") == "_例_1_2"
fix_spaces
en/127
def odd_count(lst): """ It takes a list of strings consisting only of numbers as an argument and returns a new list. Each element of the new output list is "入力のi番目の文字列に含まれる奇数の数はi個です。" is a string of the form , where every 'i' in this string is the i-th Replaced by the odd number in the string. example: >>> odd_count(['1234567']) ['入力の4番目の文字列に含まれる奇数の数は4個です。'] >>> odd_count(['3', '11111111']) ['入力の1番目の文字列に含まれる奇数の数は1個です。', '入力の8番目の文字列に含まれる奇数の数は8個です。'] """
result = [] for s in lst: odd_count = sum(1 for char in s if char in '13579') message = f"入力の{odd_count}番目の文字列に含まれる奇数の数は{odd_count}個です。" result.append(message) return result
def check(candidate): # 簡単なケースをチェック assert candidate(['1234567']) == ["入力の4番目の文字列に含まれる奇数の数は4個です。"], "テスト 1" assert candidate(['3', '11111111']) == [ "入力の1番目の文字列に含まれる奇数の数は1個です。", "入力の8番目の文字列に含まれる奇数の数は8個です。" ], "テスト 2" assert candidate(['271', '137', '314']) == [ '入力の2番目の文字列に含まれる奇数の数は2個です。', '入力の3番目の文字列に含まれる奇数の数は3個です。', '入力の2番目の文字列に含まれる奇数の数は2個です。' ], "テスト 3" # 手作業で簡単に検証できる境界ケースをチェック assert True, "このアサートが失敗した場合、このメッセージが表示されます(デバッグに便利です!)"
odd_count
en/128
def histogram(test): """ A string representing Kanji characters separated by spaces is given. The kanji that appears most often and Returns a dictionary of corresponding counts. If multiple kanji have the same number of occurrences, return all of them. example: histogram('一 二 三') == {'一': 1, '二': 1, '三': 1} histogram('一 二 二 一') == {'一': 2, '二': 2} histogram('一 二 三 一 二') == {'一': 2, '二': 2} histogram('二 二 二 二 一') == {'二': 4} histogram('') == {} """
dict1 = {} list1 = test.split(" ") t = 0 for i in list1: if list1.count(i) > t and i != '': t = list1.count(i) if t > 0: for i in list1: if list1.count(i) == t: dict1[i] = t return dict1
def check(candidate): # 簡単なケースをチェック assert candidate('一 二 二 一') == {'一': 2, '二': 2}, "テスト失敗 1" assert candidate('一 二 三 一 二') == {'一': 2, '二': 2}, "テスト失敗 2" assert candidate('一 二 三 四 五') == {'一': 1, '二': 1, '三': 1, '四': 1, '五': 1}, "テスト失敗 3" assert candidate('山 川 田') == {'山': 1, '川': 1, '田': 1}, "テスト失敗 4" assert candidate('二 二 二 二 一') == {'二': 4}, "テスト失敗 5" assert candidate('山 川 田') == {'山': 1, '川': 1, '田': 1}, "テスト失敗 6" # 手作業で簡単に検証できる境界ケースをチェック assert candidate('') == {}, "テスト失敗 7" assert candidate('一') == {'一': 1}, "テスト失敗 8"
histogram
en/129
def exchange(lst1, lst2): """ To receive a list of two numbers and make lst1 a list of only even numbers, A function that determines whether it is possible to exchange elements between lst1 and lst2. There is no limit to the number of elements exchanged between lst1 and lst2. Returns "可能" if it is possible to make all elements of lst1 even, If it is impossible, return "不可能". example: >>> exchange([1, 2, 3, 4], [1, 2, 3, 4]) '可能' >>> exchange([1, 2, 3, 4], [1, 5, 3, 4]) '不可能' """
odd = 0 even = 0 for i in lst1: if i%2 == 1: odd += 1 for i in lst2: if i%2 == 0: even += 1 if even >= odd: return "可能" return "不可能"
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4], [1, 2, 3, 4]) == "可能" assert candidate([1, 2, 3, 4], [1, 5, 3, 4]) == "不可能" assert candidate([1, 2, 3, 4], [2, 1, 4, 3]) == "可能" assert candidate([5, 7, 3], [2, 6, 4]) == "可能" assert candidate([5, 7, 3], [2, 6, 3]) == "不可能" assert candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) == "不可能" # Check some edge cases that are easy to work out by hand. assert candidate([100, 200], [200, 200]) == "可能"
exchange
en/130
def inverse_fib(target: int) -> int: """ A function that returns the Fibonacci number from a specified Fibonacci number. Returns -1 if the specified number is not a Fibonacci number. example: >>> inverse_fib(55) 10 >>> inverse_fib(1) 1 >>> inverse_fib(21) 8 >>> inverse_fib(100) -1 """
if target < 0: return -1 a, b = 0, 1 n = 0 while a <= target: if a == target: return n a, b = b, a + b n += 1 return -1
def check(candidate): assert candidate(55) == 10 assert candidate(1) == 1 assert candidate(21) == 8 assert candidate(89) == 11 assert candidate(144) == 12 assert candidate(100) == -1 assert candidate(233) == 13 assert candidate(377) == 14 assert candidate(610) == 15
inverse_fib
en/131
from typing import List def parse_taiko_rhythm(rhythm_string: str) -> List[int]: """ Parses the string representing the Japanese drum rhythm, converts each rhythm symbol to the corresponding number of beats, and returns it as a list. The Japanese drum rhythm consists of the following symbols: - 'ドン': 4 beats - 'ドコ': 2 beats - 'ツク': 1 beat input: rhythm_string (str): A string of characters delimited by spaces that represents the rhythm of Japanese drums output: List[int]: List of each rhythm symbol converted to the corresponding number of beats Usage example: >>> parse_taiko_rhythm('ドン ドコ ツク ドコ ドン') [4, 2, 1, 2, 4] >>> parse_taiko_rhythm('ドコ ドコ ドン ツク ツク ドン') [2, 2, 4, 1, 1, 4] """
# リズム記号と拍数の対応辞書 note_durations = { 'ドン': 4, 'ドコ': 2, 'ツク': 1 } # 入力文字列を空白で分割し、対応する拍数をリストにする beats = [note_durations[note] for note in rhythm_string.split()] return beats
def check(candidate): assert candidate('ドン ドコ ツク ドコ ドン') == [4, 2, 1, 2, 4] assert candidate('ドコ ドコ ドン ツク ツク ドン') == [2, 2, 4, 1, 1, 4] assert candidate('ドン ドン ドン') == [4, 4, 4] assert candidate('ツク ツク ツク ツク') == [1, 1, 1, 1] assert candidate('ドコ ドン') == [2, 4] assert candidate('ドン') == [4]
parse_taiko_rhythm
en/132
def count_dango(s: str) -> int: """ Count the dango "o" contained in the string s. argument: s (str): string to check Return value: int: number of dumplings Execution example: >>> count_dango("oo-oo-oo-o-") 7 >>> count_dango("oo-o-o-oo-") 6 >>> count_dango("o-o-o-o-o-") 5 """
return s.count('o')
def check(candidate): assert candidate("oo-oo-oo-o-") == 7 assert candidate("oo-o-o-oo-") == 6 assert candidate("o-o-o-o-o-") == 5 assert candidate("ooo-ooo-o-") == 7 assert candidate("o-oo-o-o-") == 5
count_dango
en/133
from typing import List def are_all_kites_high_enough(heights: List[float], threshold: float) -> bool: """ Determine whether the height of all kites is greater than or equal to a threshold. argument: heights (List[float]): Current height of each kite (m) threshold (float): Threshold for flying a kite (m) Return value: bool: True if the height of all kites is greater than or equal to the threshold, otherwise False Execution example: >>> are_all_kites_high_enough([10.0, 12.5, 9.0], 5.0) True >>> are_all_kites_high_enough([3.0, 6.0, 2.0], 5.0) False """
return all(height >= threshold for height in heights)
def check(candidate): assert candidate([10.0, 12.5, 9.0], 5.0) == True assert candidate([3.0, 6.0, 2.0], 5.0) == False assert candidate([7.0, 8.0, 9.0], 6.0) == True assert candidate([3.0, 5.0], 5.0) == False assert candidate([10.0, 10.5, 11.0], 10.0) == True
are_all_kites_high_enough
en/134
from typing import List def calculate_total_beans(ages: List[int]) -> int: """ Calculate the number of beans that the whole family will eat. Assume that each family member eats as many beans as their age. argument: ages (List[int]): List of ages of each family member. Return value: int: Number of beans eaten by the whole family (sum of ages). Usage example: >>> calculate_total_beans([10, 15, 20]) 45 >>> calculate_total_beans([5, 8, 13]) 26 """
return sum(ages)
def check(candidate): assert candidate([10, 15, 20]) == 45 assert candidate([5, 8, 13]) == 26 assert candidate([1, 2, 3, 4]) == 10 assert candidate([30, 25, 15]) == 70 assert candidate([7, 6, 5, 4]) == 22
calculate_total_beans
en/135
def count_hashi_pair(s: str) -> int: """ Count the number of bowls of chopsticks "|" included in the string s (two chopsticks make one bowl). argument: s (str): string to check Return value: int: number of chopsticks Execution example: >>> count_hashi_pair("||-|-|||-") 3 """
count = s.count("|") return count // 2
def check(candidate): assert candidate("||-|-|||-") == 3 assert candidate("|||-|-|") == 2 assert candidate("-|---|") == 1 assert candidate("|-||-|") == 2 assert candidate("|||||") == 2
count_hashi_pair
en/136
from typing import List def karaoke_score_with_grade(target: List[int], actual: List[int]) -> str: """ Calculates the pitch accuracy score in karaoke and assigns grades. Compare the ideal pitch list (target) and the pitch list for singing (actual), Returns a score according to the proportion of matching pitches. Judgment criteria: - S: 90% or more - A: 80% or more but less than 90% - B: 70% or more but less than 80% - C: 60% or more but less than 70% - D: Less than 60% argument: target (List[int]): ideal pitch list actual (List[int]): pitch list when singing Return value: str: Grade based on pitch matching rate (e.g. "Score: 85.0%, Grade: A") """
# 一致している音程の数をカウント match_count = sum(1 for t, a in zip(target, actual) if t == a) # スコアをパーセンテージで計算 score_percentage = (match_count / len(target)) * 100 # 成績を判定 if score_percentage >= 90: grade = "S" elif score_percentage >= 80: grade = "A" elif score_percentage >= 70: grade = "B" elif score_percentage >= 60: grade = "C" else: grade = "D" return grade
def check(candidate): assert candidate([60, 62, 64, 65, 67], [60, 62, 64, 65, 67]) == "S" assert candidate([60, 62, 64, 65, 67], [60, 62, 63, 65, 67]) == "A" assert candidate([60, 62, 64, 65, 67, 68, 69], [60, 61, 64, 64, 67, 68, 69]) == "B" assert candidate([60, 62, 64, 65, 67], [60, 61, 64, 65, 66]) == "C" assert candidate([60, 62, 64, 65, 67], [61, 61, 63, 64, 66]) == "D"
karaoke_score_with_grade
en/137
def evaluate_score(score: int) -> str: """ Grades will be evaluated based on the points given. Performance evaluation criteria: - 80 points or more: "良" - 60 points or more but less than 80 points: "可" - Less than 60 points: "不可" argument: score (int): Input score (0-100) Return value: str: Evaluated grade ("良", "可", "不可") Usage example: >>> evaluate_score(85) '良' >>> evaluate_score(75) '可' >>> evaluate_score(45) '不可' """
if score >= 80: return "良" elif score >= 60: return "可" else: return "不可"
def check(candidate): assert candidate(85) == "良" assert candidate(75) == "可" assert candidate(45) == "不可" assert candidate(60) == "可" assert candidate(80) == "良" assert candidate(59) == "不可" assert candidate(100) == "良" assert candidate(0) == "不可"
evaluate_score
en/138
def correct_bracketing(brackets: str) -> bool: """ Determines if the given string brackets has all the opening brackets "「" corresponding to the closing brackets "」". argument: brackets (str): String containing only "「", "」" Return value: bool: Returns True if every opening parenthesis has a corresponding closing parenthesis, otherwise returns False. Execution example: >>> correct_bracketing("「") False >>> correct_bracketing("「」") True >>> correct_bracketing("「「」「」」") True >>> correct_bracketing("」「「」") False """
balance = 0 for char in brackets: if char == '「': balance += 1 elif char == '」': balance -= 1 # 閉じカッコが開きカッコを上回ったら不正なカッコの並び if balance < 0: return False # 最後にすべての開きカッコが閉じられているか確認 return balance == 0
def check(candidate): assert candidate("「」") == True assert candidate("「「」「」」") == True assert candidate("「」「」") == True assert candidate("「「」」」") == False assert candidate("」「」") == False assert candidate("「「」」「」") == True assert candidate("」」「「」」") == False assert candidate("「」」") == False assert candidate("「」「」「」") == True assert candidate("「「」」") == True assert candidate("「」「「」」") == True assert candidate("」」」」") == False assert candidate("「「「「」」」」") == True
correct_bracketing
en/139
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): first planet name planet2 (str): second planet name Return value: tuple: A tuple of planets between two planets arranged in order of proximity to the sun example: >>> bf("木星", "海王星") ('土星', '天王星') >>> bf("地球", "水星") ('金星',) >>> bf("水星", "天王星") ('金星', '地球', '火星', '木星', '土星') """
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: return planet_names[planet1_index + 1 : planet2_index] else: return planet_names[planet2_index + 1 : planet1_index]
def check(candidate): # 簡単なケースをチェック assert candidate("木星", "海王星") == ("土星", "天王星"), "最初のテストエラー: " + str(len(candidate("木星", "海王星"))) assert candidate("地球", "水星") == ("金星",), "2番目のテストエラー: " + str(candidate("地球", "水星")) assert candidate("水星", "天王星") == ("金星", "地球", "火星", "木星", "土星"), "3番目のテストエラー: " + str(candidate("水星", "天王星")) assert candidate("海王星", "金星") == ("地球", "火星", "木星", "土星", "天王星"), "4番目のテストエラー: " + str(candidate("海王星", "金星")) # 手作業で簡単に検証できる境界ケースをチェック assert candidate("地球", "地球") == () assert candidate("火星", "地球") == () assert candidate("木星", "マケマケ") == ()
bf
en/140
from typing import List def below_zero(operations: List[int]) -> str: """ You will be given a list of deposit and withdrawal operations for your bank account. Your task starts from zero balance The function detects whether the account balance is less than or equal to zero, at which point the function flags "残高不足". It's about giving back. Otherwise, please return "残高あり". example: >>> below_zero([1, 2, 3]) '残高あり' >>> below_zero([1, 2, -4, 5]) '残高不足' """
balance = 0 for operation in operations: balance += operation if balance < 0: return '残高不足' return '残高あり'
def check(candidate): assert candidate([]) == '残高あり' assert candidate([1, 2, -3, 1, 2, -3]) == '残高あり' assert candidate([1, 2, -4, 5, 6]) == '残高不足' assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == '残高あり' assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == '残高不足' assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == '残高不足'
below_zero
en/141
from typing import List def all_prefixes(string: str) -> List[str]: """ Returns a list of all prefixes, from shortest to longest, for the string given as an argument. However, it is assumed that all character strings are in hiragana. example: >>> all_prefixes('Aiu') ['A', 'Ai', 'Aiu'] """
result = [] for i in range(len(string)): result.append(string[:i+1]) return result
def check(candidate): assert candidate('') == [] assert candidate('あいうえお') == ['あ', 'あい', 'あいう', 'あいうえ', 'あいうえお'] assert candidate('ひらがな') == ['ひ', 'ひら', 'ひらが', 'ひらがな']
all_prefixes
en/142
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 from smallest to largest. example: >>> sort_numbers('三 一 五') '一 三 五' """
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/143
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/144
def get_region(prefecture: str) -> str: """ Accepts a Japanese prefecture name as input and returns the corresponding region name. If a prefecture that does not exist is entered, "Unknown" is returned. >>> get_region('北海道') '北海道地方' >>> get_region('秋田県') '東北地方' """
regions = { "北海道地方": ["北海道"], "東北地方": ["青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県"], "関東地方": ["茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県"], "中部地方": ["新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県"], "近畿地方": ["三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県"], "中国地方": ["鳥取県", "島根県", "岡山県", "広島県", "山口県"], "四国地方": ["徳島県", "香川県", "愛媛県", "高知県"], "九州地方": ["福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県"], } for region, prefectures in regions.items(): if prefecture in prefectures: return region return "不明"
def check(candidate): assert candidate("北海道") == "北海道地方" assert candidate("秋田県") == "東北地方" assert candidate("福島県") == "東北地方" assert candidate("東京都") == "関東地方" assert candidate("茨城県") == "関東地方" assert candidate("愛知県") == "中部地方" assert candidate("石川県") == "中部地方" assert candidate("大阪府") == "近畿地方" assert candidate("和歌山県") == "近畿地方" assert candidate("広島県") == "中国地方" assert candidate("鳥取県") == "中国地方" assert candidate("香川県") == "四国地方" assert candidate("福岡県") == "九州地方" assert candidate("長崎県") == "九州地方" assert candidate("不存在県") == "不明"
get_region
en/145
def is_in_tokyo(ward: str) -> bool: """ A function that determines whether it is in Tokyo's 23 wards. argument: ward (str): Ward name to be judged. Return value: bool: True if the argument is the name of Tokyo's 23 wards, False otherwise. example: >>> is_in_tokyo("新宿区") True >>> is_in_tokyo("横浜市") False """
tokyo_23_wards = { "千代田区", "中央区", "港区", "新宿区", "文京区", "台東区", "墨田区", "江東区", "品川区", "目黒区", "大田区", "世田谷区", "渋谷区", "中野区", "杉並区", "豊島区", "北区", "荒川区", "板橋区", "練馬区", "足立区", "葛飾区", "江戸川区" } return ward in tokyo_23_wards
def check(candidate): assert candidate("新宿区") == True assert candidate("渋谷区") == True assert candidate("港区") == True assert candidate("千代田区") == True assert candidate("江戸川区") == True assert candidate("横浜市") == False assert candidate("大阪市") == False assert candidate("札幌市") == False assert candidate("さいたま市") == False assert candidate("富士市") == False
is_in_tokyo
en/146
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 candidate(7) == "7ひきの犬" assert candidate(9) == "9ひきの犬"
count_dogs
en/147
def translate_thank_you(language_code): """ Translate "ありがとう" by specifying the language code. Args: language_code (str): ISO 639-1 language code (Example: "ja", "en", "ru", "fr", "ko", "es", "de", "it", "zh", "ar") Returns: str: Translation of "ありがとう" into the specified language. """
translations = { "ja": "ありがとう", # 日本語 "en": "Thank you", # 英語 "ru": "Спасибо", # ロシア語 "fr": "Merci", # フランス語 "ko": "감사합니다", # 韓国語 "es": "Gracias", # スペイン語 "de": "Danke", # ドイツ語 "it": "Grazie", # イタリア語 "zh": "谢谢", # 中国語 "ar": "شكرا", # アラビア語 } return translations.get(language_code)
def check(candidate): assert candidate("ja") == "ありがとう" assert candidate("en") == "Thank you" assert candidate("es") == "Gracias" assert candidate("fr") == "Merci" assert candidate("de") == "Danke" assert candidate("it") == "Grazie" assert candidate("zh") == "谢谢" assert candidate("ko") == "감사합니다" assert candidate("ar") == "شكرا" assert candidate("ru") == "Спасибо"
translate_thank_you
en/148
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): Destination timezone (e.g. "UTC", "PST", "EST", "CET") Return value: str: Date and time in the specified time zone (format: "YYYY-MM-DD HH:MM:SS") """
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_datetime + timedelta(hours=offset) return converted_time.strftime("%Y-%m-%d %H:%M:%S")
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:00:00"
convert_to_timezone
en/149
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 to two decimal places). """
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/150
def get_ai_rank(ai_data): """ Obtain Japan's AI penetration rate ranking. argument: ai_data (dict): Dictionary with country name as key and AI penetration rate as value. Return value: int: Japanese ranking example: >>> ai_data = {"アメリカ": 75, "日本": 60, "中国": 80} >>> get_ai_rank(ai_data) 2 """
sorted_data = sorted(ai_data.items(), key=lambda x: x[1], reverse=True) ranking = {item[0]: rank + 1 for rank, item in enumerate(sorted_data)} return ranking["日本"]
def check(candidate): ai_data_1 = {"アメリカ": 75, "日本": 60, "中国": 80} assert candidate(ai_data_1) == 3, "Test 1 Failed" ai_data_2 = {"アメリカ": 50, "日本": 80, "中国": 75} assert candidate(ai_data_2) == 1, "Test 2 Failed" ai_data_3 = {"アメリカ": 75, "中国": 80, "日本": 50} assert candidate(ai_data_3) == 3, "Test 3 Failed" ai_data_4 = {"日本": 60} assert candidate(ai_data_4) == 1, "Test 4 Failed" ai_data_5 = {"アメリカ": 70, "日本": 60} assert candidate(ai_data_5) == 2, "Test 5 Failed" ai_data_6 = {"日本": 50, "中国": 80, "ドイツ": 65, "インド": 55} assert candidate(ai_data_6) == 4, "Test 6 Failed"
get_ai_rank
en/151
def replace_katakana(s, replacement): """ Replaces katakana characters in the given string s with the specified string replacement. argument: s (str): Target string. replacement (str): String used for replacement. Return value: str: String resulting from replacing katakana. Execution example: >>> replace_katakana("カタカナとひらがな", "*") '**とひらがな' """
return "".join(replacement if "ァ" <= char <= "ン" or char == "ヴ" else char for char in s)
def check(candidate): assert candidate("カタカナとひらがな", "*") == "****とひらがな" assert candidate("カタカナ", "!") == "!!!!" assert candidate("ひらがなと漢字", "?") == "ひらがなと漢字" assert candidate("漢字とカタカナ", "#") == "漢字と####" assert candidate("あアイいうウえエオお", "+") == "あ++いう+え++お"
replace_katakana
en/152
def get_hottest_location(temperature_data): """ Given city and temperature data, returns the city with the highest temperature. argument: temperature_data (dict): Dictionary of cities and their temperature data. Return value: str: Name of the city with the highest temperature. Execution example: >>> temperature_data = {"新宿区": 35.5, "大阪市": 34.0, "福岡市": 36.2} >>> get_hottest_location(temperature_data) '福岡市' """
return max(temperature_data, key=lambda location: temperature_data[location])
def check(candidate): assert candidate({"新宿区": 35.5, "大阪市": 34.0, "福岡市": 36.2}) == "福岡市" assert candidate({"横浜市": 29.8, "京都市": 33.1, "神戸市": 32.7}) == "京都市" assert candidate({"仙台市": 25.3, "長野市": 24.1, "高松市": 26.0}) == "高松市" assert candidate({"金沢市": 31.2}) == "金沢市" assert candidate({"富山市": -5.0, "秋田市": -3.2, "盛岡市": -7.1}) == "秋田市"
get_hottest_location
en/153
def check_ichiju_sansai(menu): """ Determine whether the menu satisfies the format of one soup and three dishes. argument: menu (dict): menu {"汁物": list of str, "主菜": list of str, "副菜": list of str} Return: bool: True if it satisfies the format of one soup and three dishes, otherwise False >>> check_ichiju_sansai({"汁物": ["味噌汁"], "主菜": ["焼き魚"], "副菜": ["おひたし", "漬物"]}) True >>> check_ichiju_sansai({"汁物": ["味噌汁"], "主菜": ["焼き魚"], "副菜": ["おひたし"]}) False """
if set(menu.keys()) != {"汁物", "主菜", "副菜"}: return False if len(menu["汁物"]) == 1 and len(menu["主菜"]) == 1 and len(menu["副菜"]) == 2: return True return False
def check(candidate): assert candidate({"汁物": ["味噌汁"], "主菜": ["焼き魚"], "副菜": ["おひたし", "漬物"]}) == True assert candidate({"汁物": ["豚汁"], "主菜": ["煮物"], "副菜": ["おひたし", "ポテトサラダ"]}) == True assert candidate({"汁物": ["味噌汁"], "主菜": ["焼き魚"], "副菜": ["おひたし"]}) == False assert candidate({"汁物": ["味噌汁"], "主菜": ["焼き魚"]}) == False assert candidate({"汁物": [], "主菜": ["焼き魚"], "副菜": ["おひたし", "漬物"]}) == False
check_ichiju_sansai
en/154
def search(lst): ''' You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency of an integer is the number of times it appears in the list. If no such a value exist, return -1. Examples: search([4, 1, 2, 2, 3, 1]) == 2 search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 search([5, 5, 4, 4, 4]) == -1 '''
frq = [0] * (max(lst) + 1) for i in lst: frq[i] += 1; ans = -1 for i in range(1, len(frq)): if frq[i] >= i: ans = i return ans
def check(candidate): # manually generated tests assert candidate([5, 5, 5, 5, 1]) == 1 assert candidate([4, 1, 4, 1, 4, 4]) == 4 assert candidate([3, 3]) == -1 assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8 assert candidate([2, 3, 3, 2, 2]) == 2 # automatically generated tests assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1 assert candidate([3, 2, 8, 2]) == 2 assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1 assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1 assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1 assert candidate([1, 9, 10, 1, 3]) == 1 assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5 assert candidate([1]) == 1 assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4 assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2 assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1 assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4 assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4 assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2 assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1 assert candidate([10]) == -1 assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2 assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1 assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1 assert candidate([3, 10, 10, 9, 2]) == -1
search
en/155
def find_max(words): """Write a function that accepts a list of strings. The list contains different words. Return the word with maximum number of unique characters. If multiple strings have maximum number of unique characters, return the one which comes first in lexicographical order. find_max(["name", "of", "string"]) == "string" find_max(["name", "enam", "game"]) == "enam" find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa" """
return sorted(words, key = lambda x: (-len(set(x)), x))[0]
def check(candidate): # Check some simple cases assert (candidate(["name", "of", "string"]) == "string"), "t1" assert (candidate(["name", "enam", "game"]) == "enam"), 't2' assert (candidate(["aaaaaaa", "bb", "cc"]) == "aaaaaaa"), 't3' assert (candidate(["abc", "cba"]) == "abc"), 't4' assert (candidate(["play", "this", "game", "of","footbott"]) == "footbott"), 't5' assert (candidate(["we", "are", "gonna", "rock"]) == "gonna"), 't6' assert (candidate(["we", "are", "a", "mad", "nation"]) == "nation"), 't7' assert (candidate(["this", "is", "a", "prrk"]) == "this"), 't8' # Check some edge cases that are easy to work out by hand. assert (candidate(["b"]) == "b"), 't9' assert (candidate(["play", "play", "play"]) == "play"), 't10'
find_max
en/156
def search(lst): ''' You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency of an integer is the number of times it appears in the list. If no such a value exist, return -1. Examples: search([4, 1, 2, 2, 3, 1]) == 2 search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 search([5, 5, 4, 4, 4]) == -1 '''
frq = [0] * (max(lst) + 1) for i in lst: frq[i] += 1; ans = -1 for i in range(1, len(frq)): if frq[i] >= i: ans = i return ans
def check(candidate): # manually generated tests assert candidate([5, 5, 5, 5, 1]) == 1 assert candidate([4, 1, 4, 1, 4, 4]) == 4 assert candidate([3, 3]) == -1 assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8 assert candidate([2, 3, 3, 2, 2]) == 2 # automatically generated tests assert candidate([2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]) == 1 assert candidate([3, 2, 8, 2]) == 2 assert candidate([6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]) == 1 assert candidate([8, 8, 3, 6, 5, 6, 4]) == -1 assert candidate([6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]) == 1 assert candidate([1, 9, 10, 1, 3]) == 1 assert candidate([6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]) == 5 assert candidate([1]) == 1 assert candidate([8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]) == 4 assert candidate([2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]) == 2 assert candidate([1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]) == 1 assert candidate([9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]) == 4 assert candidate([2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]) == 4 assert candidate([9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]) == 2 assert candidate([5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]) == -1 assert candidate([10]) == -1 assert candidate([9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]) == 2 assert candidate([5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]) == 1 assert candidate([7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]) == 1 assert candidate([3, 10, 10, 9, 2]) == -1
search
en/157
from typing import List def below_zero(operations: List[int]) -> bool: """ You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that point function should return True. Otherwise it should return False. >>> below_zero([1, 2, 3]) False >>> below_zero([1, 2, -4, 5]) True """
balance = 0 for op in operations: balance += op if balance < 0: return True return False
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == False assert candidate([1, 2, -3, 1, 2, -3]) == False assert candidate([1, 2, -4, 5, 6]) == True assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == True assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True
below_zero
en/158
def smallest_change(arr): """ Given an array arr of integers, find the minimum number of elements that need to be changed to make the array palindromic. A palindromic array is an array that is read the same backwards and forwards. In one change, you can change one element to any other element. For example: smallest_change([1,2,3,5,4,7,9,6]) == 4 smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1 smallest_change([1, 2, 3, 2, 1]) == 0 """
ans = 0 for i in range(len(arr) // 2): if arr[i] != arr[len(arr) - i - 1]: ans += 1 return ans
def check(candidate): # Check some simple cases assert candidate([1,2,3,5,4,7,9,6]) == 4 assert candidate([1, 2, 3, 4, 3, 2, 2]) == 1 assert candidate([1, 4, 2]) == 1 assert candidate([1, 4, 4, 2]) == 1 # Check some edge cases that are easy to work out by hand. assert candidate([1, 2, 3, 2, 1]) == 0 assert candidate([3, 1, 1, 3]) == 0 assert candidate([1]) == 0 assert candidate([0, 1]) == 1
smallest_change
en/159
def modp(n: int, p: int): """Return 2^n modulo p (be aware of numerics). >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1 """
ret = 1 for i in range(n): ret = (2 * ret) % p return ret
METADATA = {} def check(candidate): assert candidate(3, 5) == 3 assert candidate(1101, 101) == 2 assert candidate(0, 101) == 1 assert candidate(3, 11) == 8 assert candidate(100, 101) == 1 assert candidate(30, 5) == 4 assert candidate(31, 5) == 3
modp
en/160
def unique_digits(x): """Given a list of positive integers x. return a sorted list of all elements that hasn't any even digit. Note: Returned list should be sorted in increasing order. For example: >>> unique_digits([15, 33, 1422, 1]) [1, 15, 33] >>> unique_digits([152, 323, 1422, 10]) [] """
odd_digit_elements = [] for i in x: if all (int(c) % 2 == 1 for c in str(i)): odd_digit_elements.append(i) return sorted(odd_digit_elements)
def check(candidate): # Check some simple cases assert candidate([15, 33, 1422, 1]) == [1, 15, 33] assert candidate([152, 323, 1422, 10]) == [] assert candidate([12345, 2033, 111, 151]) == [111, 151] assert candidate([135, 103, 31]) == [31, 135] # Check some edge cases that are easy to work out by hand. assert True
unique_digits
en/161
def triples_sum_to_zero(l: list): """ triples_sum_to_zero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> triples_sum_to_zero([1, 3, 5, 0]) False >>> triples_sum_to_zero([1, 3, -2, 1]) True >>> triples_sum_to_zero([1, 2, 3, 7]) False >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7]) True >>> triples_sum_to_zero([1]) False """
for i in range(len(l)): for j in range(i + 1, len(l)): for k in range(j + 1, len(l)): if l[i] + l[j] + l[k] == 0: return True return False
METADATA = {} def check(candidate): assert candidate([1, 3, 5, 0]) == False assert candidate([1, 3, 5, -1]) == False assert candidate([1, 3, -2, 1]) == True assert candidate([1, 2, 3, 7]) == False assert candidate([1, 2, 5, 7]) == False assert candidate([2, 4, -5, 3, 9, 7]) == True assert candidate([1]) == False assert candidate([1, 3, 5, -100]) == False assert candidate([100, 3, 5, -100]) == False
triples_sum_to_zero
en/162
def reverse_delete(s,c): """Task We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c then check if the result string is palindrome. A string is called palindrome if it reads the same backward as forward. You should return a tuple containing the result string and True/False for the check. Example For s = "abcde", c = "ae", the result should be ('bcd',False) For s = "abcdef", c = "b" the result should be ('acdef',False) For s = "abcdedcba", c = "ab", the result should be ('cdedc',True) """
s = ''.join([char for char in s if char not in c]) return (s,s[::-1] == s)
def check(candidate): assert candidate("abcde","ae") == ('bcd',False) assert candidate("abcdef", "b") == ('acdef',False) assert candidate("abcdedcba","ab") == ('cdedc',True) assert candidate("dwik","w") == ('dik',False) assert candidate("a","a") == ('',True) assert candidate("abcdedcba","") == ('abcdedcba',True) assert candidate("abcdedcba","v") == ('abcdedcba',True) assert candidate("vabba","v") == ('abba',True) assert candidate("mamma", "mia") == ("", True)
reverse_delete
en/163
def below_threshold(l: list, t: int): """Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False """
for e in l: if e >= t: return False return True
METADATA = {} def check(candidate): assert candidate([1, 2, 4, 10], 100) assert not candidate([1, 20, 4, 10], 5) assert candidate([1, 20, 4, 10], 21) assert candidate([1, 20, 4, 10], 22) assert candidate([1, 8, 4, 10], 11) assert not candidate([1, 8, 4, 10], 10)
below_threshold