Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Libraries:
Datasets
pandas
License:
Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringlengths
15
17
prompt
stringlengths
47
746
code
stringlengths
42
900
testcode
stringlengths
153
1.84k
entry_point
stringlengths
1
30
bt_JHumanEval/0
ใƒชใ‚นใƒˆnumbersใฎไธญใซใ€ไธŽใˆใ‚‰ใ‚ŒใŸthresholdใ‚ˆใ‚Š่ฟ‘ใ„๏ผ’ใคใฎๆ•ฐๅ€คใŒๅญ˜ๅœจใ™ใ‚‹ใ‹ๅˆคๅฎšใ™ใ‚‹ >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) True
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: for idx, elem in enumerate(numbers): for idx2, elem2 in enumerate(numbers): if idx != idx2: distance = abs(elem - elem2) if distance < threshold: ...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True assert candidate([1.0, 2.0, 5.9, 4.0,...
has_close_elements
bt_JHumanEval/1
ใ“ใฎ้–ขๆ•ฐใธใฎๅ…ฅๅŠ›ใฏใ€ๅ…ฅใ‚ŒๅญใซใชใฃใŸๆ‹ฌๅผงใŒ่ค‡ๆ•ฐๅซใพใ‚Œใ‚‹ๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚‹ใ€‚ ใ‚ใชใŸใฎ็›ฎ็š„ใฏใ€ใ“ใ‚Œใ‚‰ใฎๆ‹ฌๅผงใ‚’ๅˆฅใ€…ใฎๆ–‡ๅญ—ๅˆ—ใซๅˆ†ๅ‰ฒใ—ใ€ใใฎใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ใ“ใจใงใ‚ใ‚‹ใ€‚ ๅˆ†้›ขใ•ใ‚ŒใŸๆ‹ฌๅผงใฏใƒใƒฉใƒณใ‚นใŒใจใ‚Œใ€ใคใพใ‚Šใ€้–‹ใ„ใŸๆ‹ฌๅผงใฏใใ‚Œใžใ‚Œ้ฉๅˆ‡ใซ้–‰ใ˜ใ‚‰ใ‚Œใฆใ„ใฆใ€ ไบ’ใ„ใซๅ…ฅใ‚Œๅญใซใชใฃใฆใ„ใชใ„ใ€‚ๅผ•ๆ•ฐใฎๆ–‡ๅญ—ๅˆ—ๅ†…ใฎ็ฉบ็™ฝใฏ็„ก่ฆ–ใ›ใ‚ˆใ€‚ >>> separate_paren_groups('( ) (( )) (( )( ))') ['()', '(())', '(()())']
from typing import List def separate_paren_groups(paren_string: str) -> List[str]: result = [] current_string = [] current_depth = 0 for c in paren_string: if c == '(': current_depth += 1 current_string.append(c) elif c == ')': current_depth -= 1 ...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('(()()) ((())) () ((())()())') == [ '(()())', '((()))', '()', '((())()())' ] assert candidate('() (()) ((())) (((())))') == [ '()', '(())', '((()))', '(((())))' ] assert candidate('(()...
separate_paren_groups
bt_JHumanEval/2
ๆญฃใฎๆตฎๅ‹•ๅฐๆ•ฐ็‚นๆ•ฐใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใจใ€ใใ‚Œใ‚’ๆ•ดๆ•ฐ้ƒจ๏ผˆไธŽใˆใ‚‰ใ‚ŒใŸๆ•ฐใ‚ˆใ‚Šๅฐใ•ใ„ๆœ€ๅคงใฎๆ•ดๆ•ฐ๏ผ‰ ใจๅฐๆ•ฐ้ƒจ๏ผˆๅธธใซ1ใ‚ˆใ‚Šๅฐใ•ใ„ๆฎ‹ไฝ™้ƒจๅˆ†๏ผ‰ใซๅˆ†่งฃใ™ใ‚‹ใ“ใจใŒใงใใ‚‹ใ€‚ ้–ขๆ•ฐใฏใ€ๆ•ฐๅ€คใฎๅฐๆ•ฐ้ƒจใ‚’่ฟ”ใ™ใ€‚ >>> truncate_number(3.5) 0.5
def truncate_number(number: float) -> float: return number % 1.0
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3.5) == 0.5 assert abs(candidate(1.33) - 0.33) < 1e-6 assert abs(candidate(123.456) - 0.456) < 1e-6 candidate = truncate_number check(candidate)
truncate_number
bt_JHumanEval/3
้Š€่กŒๅฃๅบงใซๅฏพใ™ใ‚‹ๅ…ฅๅ‡บ้‡‘ๆ“ไฝœใฎใƒชใ‚นใƒˆใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ใ‚ใชใŸใฎใ‚ฟใ‚นใ‚ฏใฏใ€ๆฎ‹้ซ˜ใ‚ผใƒญใ‹ใ‚‰ ๅง‹ใพใฆใ€ๅฃๅบงใฎๆฎ‹้ซ˜ใŒใ‚ผใƒญไปฅไธ‹ใซใชใฃใŸใ‹ใฉใ†ใ‹ใ‚’ๆคœๅ‡บใ—ใ€ใใฎๆ™‚็‚นใง้–ขๆ•ฐใŒTrueใ‚’ ่ฟ”ใ™ใ‚ˆใ†ใซใ™ใ‚‹ใ“ใจใงใ™ใ€‚ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™ใ‚ˆใ†ใซใ—ใฆใใ ใ•ใ„ใ€‚ >>> below_zero([1, 2, 3]) False >>> below_zero([1, 2, -4, 5]) True
from typing import List def below_zero(operations: List[int]) -> bool: 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...
below_zero
bt_JHumanEval/4
็ฌฌไธ€ๅผ•ๆ•ฐใฎๆ•ฐๅ€คใƒชใ‚นใƒˆใซๅฏพใ—ใฆใ€ใ“ใฎใƒ‡ใƒผใ‚ฟใ‚ปใƒƒใƒˆใฎๅนณๅ‡ๅ€คใ‚’ไธญๅฟƒใจใ—ใŸๅนณๅ‡็ตถๅฏพๅๅทฎ(MAD)ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใ€‚ ๅนณๅ‡็ตถๅฏพๅๅทฎ(MAD)ใจใฏใ€ๅ„่ฆ็ด ใจไธญๅฟƒ็‚น๏ผˆใ“ใฎๅ ดๅˆใฏๅนณๅ‡ๅ€ค๏ผ‰ใจใฎๅทฎใฎ็ตถๅฏพๅ€คใฎๅนณๅ‡ใงใ‚ใ‚‹: MAD = ๅนณๅ‡๏ฝœx - x_mean๏ฝœ >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) 1.0
from typing import List def mean_absolute_deviation(numbers: List[float]) -> float: mean = sum(numbers) / len(numbers) return sum(abs(x - mean) for x in numbers) / len(numbers)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert abs(candidate([1.0, 2.0, 3.0]) - 2.0/3.0) < 1e-6 assert abs(candidate([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6 assert abs(candidate([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0/5.0) < 1e-6 candidate = mean_absolute_deviation check(ca...
mean_absolute_deviation
bt_JHumanEval/5
ๆ•ฐๅ€คใƒชใ‚นใƒˆ numbers ไธญใฎๅ…จใฆใฎ้€ฃ็ถšใ™ใ‚‹ไบŒ่ฆ็ด ใฎ้–“ใซใ€'delimeterใฎๅ€คใ‚’ๆŒฟๅ…ฅใ™ใ‚‹ >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3]
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: if not numbers: return [] result = [] for n in numbers[:-1]: result.append(n) result.append(delimeter) result.append(numbers[-1]) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 7) == [] assert candidate([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2] assert candidate([2, 2, 2], 2) == [2, 2, 2, 2, 2] candidate = intersperse check(candidate)
intersperse
bt_JHumanEval/6
ใ“ใฎ้–ขๆ•ฐใฎๅ…ฅๅŠ›ใฏใ€็ฉบ็™ฝใงๅŒบๅˆ‡ใ‚‰ใ‚ŒใŸ่ค‡ๆ•ฐใฎๅ…ฅใ‚ŒๅญใซใชใฃใŸๆ‹ฌๅผงใฎใ‚ฐใƒซใƒผใƒ—ใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—ใงใ™ใ€‚ ๅ„ใ‚ฐใƒซใƒผใƒ—ใซใคใ„ใฆใ€ๆ‹ฌๅผงใฎๆœ€ใ‚‚ๆทฑใ„ๅ…ฅใ‚Œๅญใฎใƒฌใƒ™ใƒซใ‚’ๅ‡บๅŠ›ใ—ใพใ™ใ€‚ ไพ‹ใˆใฐใ€'(()())'ใฏๆœ€ๅคงใง2ใƒฌใƒ™ใƒซใฎๅ…ฅใ‚Œๅญใซใชใฃใฆใ„ใพใ™ใŒใ€'((()))'ใฏ3ใƒฌใƒ™ใƒซใงใ™ใ€‚ >>> parse_nested_parens('(()()) ((())) () ((())()())') [2, 3, 1, 3]
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: def parse_paren_group(s): depth = 0 max_depth = 0 for c in s: if c == '(': depth += 1 max_depth = max(depth, max_depth) else: depth -= 1 ...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3] assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4] assert candidate('(()(())((())))') == [4] candidate = parse_nested_parens check(candidate)
parse_nested_parens
bt_JHumanEval/7
ๆ–‡ๅญ—ๅˆ—ใƒชใ‚นใƒˆstringsใ‚’ใ€ไธŽใˆใ‚ŒใŸ้ƒจๅˆ†ๆ–‡ๅญ—ๅˆ—substringใ‚’ๅซใ‚€ใ‚‚ใฎใ ใ‘ใซใƒ•ใ‚ฃใƒซใ‚ฟใ™ใ‚‹ >>> filter_by_substring([], 'a') [] >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a') ['abc', 'bacd', 'array']
from typing import List def filter_by_substring(strings: List[str], substring: str) -> List[str]: return [x for x in strings if substring in x]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 'john') == [] assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx'] assert candidate(['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'], 'xx') == ['xxx...
filter_by_substring
bt_JHumanEval/8
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ดๆ•ฐใƒชใ‚นใƒˆใซๅฏพใ—ใฆใ€ใƒชใ‚นใƒˆๅ†…ใฎใ™ในใฆใฎๆ•ดๆ•ฐใฎๅ’Œใจ็ฉใ‹ใ‚‰ใชใ‚‹ใ‚ฟใƒ—ใƒซใ‚’่ฟ”ใ™ใ€‚ ใŸใ ใ—ใ€็ฉบใฎๅ’Œใฏ0ใ€็ฉบใฎ็ฉใฏ1ใจใ™ใ‚‹ใ€‚ >>> sum_product([]) (0, 1) >>> sum_product([1, 2, 3, 4]) (10, 24)
from typing import List, Tuple def sum_product(numbers: List[int]) -> Tuple[int, int]: sum_value = 0 prod_value = 1 for n in numbers: sum_value += n prod_value *= n return sum_value, prod_value
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == (0, 1) assert candidate([1, 1, 1]) == (3, 1) assert candidate([100, 0]) == (100, 0) assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7) assert candidate([10]) == (10, 10) candidate = sum_pro...
sum_product
bt_JHumanEval/9
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ดๆ•ฐใƒชใ‚นใƒˆใ‹ใ‚‰ใ€ๅ„่ฆ็ด ใฎใใ“ใพใงใฎๆœ€ๅคงๅ€ค๏ผˆใƒญใƒผใƒชใƒณใ‚ฐๆœ€ๅคงๅ€ค๏ผ‰ใฎใƒชใ‚นใƒˆใ‚’็”Ÿๆˆใ™ใ‚‹ใ€‚ >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4]
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: running_max = None result = [] for n in numbers: if running_max is None: running_max = n else: running_max = max(running_max, n) result.append(running_max) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([4, 3, 2, 1]) == [4, 4, 4, 4] assert candidate([3, 2, 3, 100, 3]) == [3, 3, 3, 100, 100] candidate = rolling_max check(candidate)
rolling_max
bt_JHumanEval/10
ไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใงๅง‹ใพใ‚‹ๆœ€็Ÿญใฎๅ›žๆ–‡ใ‚’่ฆ‹ใคใ‘ใฆใใ ใ•ใ„ใ€‚ ใ‚ขใƒซใ‚ดใƒชใ‚บใƒ ใฎใ‚ขใ‚คใƒ‡ใ‚ขใฏไปฅไธ‹ใฎ้€šใ‚Šใงใ™๏ผš - ไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใฎไธญใงๆœ€ใ‚‚้•ทใ„ๅ›žๆ–‡ใจใชใ‚‹ๆŽฅๅฐพ่พžใ‚’่ฆ‹ใคใ‘ใพใ™ใ€‚ - ใใฎๅ›žๆ–‡ใฎๆŽฅๅฐพ่พžใฎๅ‰ใซๆฅใ‚‹ๆŽฅ้ ญ่พžใ‚’้€†้ †ใซใ—ใฆใ€ๆ–‡ๅญ—ๅˆ—ใฎๆœซๅฐพใซ่ฟฝๅŠ ใ—ใพใ™ใ€‚ >>> make_palindrome('') '' >>> make_palindrome('cat') 'catac' >>> make_palindrome('cata') 'catac'
def is_palindrome(string: str) -> bool: return string == string[::-1] def make_palindrome(string: str) -> str: if not string: return '' beginning_of_suffix = 0 while not is_palindrome(string[beginning_of_suffix:]): beginning_of_suffix += 1 return string + string[:beginning_...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('x') == 'x' assert candidate('xyz') == 'xyzyx' assert candidate('xyx') == 'xyx' assert candidate('jerry') == 'jerryrrej' candidate = make_palindrome check(candidate)
make_palindrome
bt_JHumanEval/11
ๅผ•ๆ•ฐใฏ1ใจ0ใฎใฟใ‹ใ‚‰ใชใ‚‹ๆ–‡ๅญ—ๅˆ—aใจbใงใ‚ใ‚‹ใ€‚ ใ“ใ‚Œใ‚‰ใฎๅผ•ๆ•ฐใซๅฏพใ—ใฆๆŽ’ไป–่ซ–็†ๅ’Œ(XOR)ใ‚’ๅฎŸ่กŒใ—ใ€็ตๆžœใ‚’ๆ–‡ๅญ—ๅˆ—ใจใ—ใฆ่ฟ”ใ™ใ€‚ >>> string_xor('010', '110') '100'
from typing import List def string_xor(a: str, b: str) -> str: def xor(i, j): if i == j: return '0' else: return '1' return ''.join(xor(x, y) for x, y in zip(a, b))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('111000', '101010') == '010010' assert candidate('1', '1') == '0' assert candidate('0101', '0000') == '0101' candidate = string_xor check(candidate)
string_xor
bt_JHumanEval/12
ๆ–‡ๅญ—ๅˆ—ใฎใƒชใ‚นใƒˆใฎใ†ใกใ€ๆœ€ใ‚‚้•ทใ„ใ‚‚ใฎใ‚’่ฟ”ใ™ใ€‚ๅŒใ˜้•ทใ•ใฎๆ–‡ๅญ—ๅˆ—ใŒ ่ค‡ๆ•ฐใ‚ใ‚‹ๅ ดๅˆใฏๆœ€ๅˆใฎใ‚‚ใฎใ‚’่ฟ”ใ™ใ€‚ๅ…ฅๅŠ›ใƒชใ‚นใƒˆใŒ็ฉบใฎๅ ดๅˆใฏ None ใ‚’่ฟ”ใ™ใ€‚ >>> longest([]) >>> longest(['a', 'b', 'c']) 'a' >>> longest(['a', 'bb', 'ccc']) 'ccc'
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: if not strings: return None maxlen = max(len(x) for x in strings) for s in strings: if len(s) == maxlen: return s
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == None assert candidate(['x', 'y', 'z']) == 'x' assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz' candidate = longest check(candidate)
longest
bt_JHumanEval/13
ๆ•ดๆ•ฐ a ใจ b ใฎๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐใ‚’่ฟ”ใ™ >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5
def greatest_common_divisor(a: int, b: int) -> int: while b: a, b = b, a % b return a
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3, 7) == 1 assert candidate(10, 15) == 5 assert candidate(49, 14) == 7 assert candidate(144, 60) == 12 candidate = greatest_common_divisor check(candidate)
greatest_common_divisor
bt_JHumanEval/14
ๅผ•ๆ•ฐใงไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใซๅฏพใ—ใฆใ€็Ÿญใ„ใ‚‚ใฎใ‹ใ‚‰้•ทใ„ใ‚‚ใฎใธใ€ๅ…จใฆใฎๆŽฅ้ ญ่พžใฎใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ >>> all_prefixes('abc') ['a', 'ab', 'abc']
from typing import List def all_prefixes(string: str) -> List[str]: result = [] for i in range(len(string)): result.append(string[:i+1]) return result
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == [] assert candidate('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh'] assert candidate('WWW') == ['W', 'WW', 'WWW'] candidate = all_prefixes check(candidate)
all_prefixes
bt_JHumanEval/15
0ใ‹ใ‚‰nใพใงใฎๆ•ฐๅญ—ใ‚’็ฉบ็™ฝๅŒบๅˆ‡ใ‚Šใง้€ฃ็ตใ—ใŸๆ–‡ๅญ—ๅˆ—ใง่ฟ”ใ™ใ€‚ >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5'
def string_sequence(n: int) -> str: return ' '.join([str(x) for x in range(n + 1)])
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(0) == '0' assert candidate(3) == '0 1 2 3' assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10' candidate = string_sequence check(candidate)
string_sequence
bt_JHumanEval/16
ๆ–‡ๅญ—ๅˆ—ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ใใฎๆ–‡ๅญ—ๅˆ—ใŒ๏ผˆๅคงๆ–‡ๅญ—ๅฐๆ–‡ๅญ—ใซ้–ขไฟ‚ใชใ๏ผ‰ใ„ใใคใฎ็•ฐใชใ‚‹ๆ–‡ๅญ—ใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‹ๆ•ฐใˆใ‚‹ >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4
def count_distinct_characters(string: str) -> int: return len(set(string.lower()))
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == 0 assert candidate('abcde') == 5 assert candidate('abcde' + 'cade' + 'CADE') == 5 assert candidate('aaaaAAAAaaaa') == 1 assert candidate('Jerry jERRY JeRRRY') == 5 candidate = count_distinct_c...
count_distinct_characters
bt_JHumanEval/17
ใ“ใฎ้–ขๆ•ฐใฎๅผ•ๆ•ฐใฏใ€็‰นๅˆฅใชASCIIๅฝขๅผใฎ้Ÿณ็ฌฆใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚‹ใ€‚ใ‚ใชใŸใฎไป•ไบ‹ใฏใ€ใ“ใฎๆ–‡ๅญ—ๅˆ—ใ‚’่งฃๆžใ—ใฆใ€ใใ‚Œใžใ‚Œใฎ้Ÿณ็ฌฆใŒไฝ•ๆ‹็ถšใใ‹ใซๅฏพๅฟœใ™ใ‚‹ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ใ“ใจใงใ‚ใ‚‹ใ€‚ ใ“ใ“ใซๅ‡กไพ‹ใŒใ‚ใ‚‹๏ผš o' - ๅ…จ้Ÿณ็ฌฆใ€4ๆ‹็ถšใ o|' - 2ๅˆ†้Ÿณ็ฌฆใ€2ๆ‹็ถšใ .|ใ€-4ๅˆ†้Ÿณ็ฌฆใ€1ๆ‹็ถšใ >>> parse_music('o o| .| o| o| .| .| .| .| o o') [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
from typing import List def parse_music(music_string: str) -> List[int]: note_map = {'o': 4, 'o|': 2, '.|': 1} return [note_map[x] for x in music_string.split(' ') if x]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == [] assert candidate('o o o o') == [4, 4, 4, 4] assert candidate('.| .| .| .|') == [1, 1, 1, 1] assert candidate('o| o| .| .| o o o o') == [2, 2, 1, 1, 4, 4, 4, 4] assert candidate('o| .| o| .| ...
parse_music
bt_JHumanEval/18
้ƒจๅˆ†ๆ–‡ๅญ—ๅˆ—substringใŒๆ–‡ๅญ—ๅˆ—stringใฎไธญใงไฝ•ๅ›ž่ฆ‹ใคใ‹ใ‚‹ใ‹ๆ•ฐใˆใ‚‹ใ€‚ ้‡ใชใ‚‹ใ‚ฑใƒผใ‚นใ‚‚ใ‚ซใ‚ฆใƒณใƒˆใซๅซใพใ‚Œใ‚‹ใ€‚ >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3
def how_many_times(string: str, substring: str) -> int: times = 0 for i in range(len(string) - len(substring) + 1): if string[i:i+len(substring)] == substring: times += 1 return times
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('', 'x') == 0 assert candidate('xyxyxyx', 'x') == 4 assert candidate('cacacacac', 'cac') == 4 assert candidate('john doe', 'john') == 1 candidate = how_many_times check(candidate)
how_many_times
bt_JHumanEval/19
ๅผ•ๆ•ฐใฏ'zero'ใ‹ใ‚‰'nine'ใพใงใฎ่‹ฑๅ˜่ชžใฎๆ•ฐใ‚’็ฉบ็™ฝใงๅŒบๅˆ‡ใฃใŸๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚‹ใ€‚ ๆœ‰ๅŠนใช่‹ฑๅ˜่ชžใฏ''ใ€'zero', 'one'ใ€'two'ใ€'three'ใ€'four'ใ€'five'ใ€'six'ใ€'seven'ใ€'eight'ใ€'nine'ใงใ‚ใ‚‹ใ€‚ ้–ขๆ•ฐใฏใ€่‹ฑๅ˜่ชžใฎๆ•ฐใ‚’ๅฐใ•ใ„ๆ–นใ‹ใ‚‰ๅคงใใ„ๆ–นใธใจใ‚ฝใƒผใƒˆใ—ใŸๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ™ใ€‚ >>> sort_numbers('three one five') 'one three five'
from typing import List def sort_numbers(numbers: str) -> str: value_map = { 'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9 } return ' '.join(sorted([x for x in num...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('three') == 'three' assert candidate('three five nine') == 'three five nine' assert candidate('five zero four seven nine eight') == 'zero four five seven eight nine' assert ...
sort_numbers
bt_JHumanEval/20
๏ผˆๅฐ‘ใชใใจใ‚‚้•ทใ•2ไปฅไธŠใฎ๏ผ‰ใƒชใ‚นใƒˆnumbersใ‹ใ‚‰ใ€ไบ’ใ„ใซๆœ€ใ‚‚่ฟ‘ใ„ใ‚‚ใฎใ‚’2ใค้ธใณใ€ ้ †็•ชใซ๏ผˆๅฐใ•ใ„ๆ•ฐใ€ๅคงใใ„ๆ•ฐ๏ผ‰่ฟ”ใ™ใ€‚ >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) (2.0, 2.2) >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) (2.0, 2.0)
from typing import List, Tuple def find_closest_elements(numbers: List[float]) -> Tuple[float, float]: closest_pair = None distance = None for idx, elem in enumerate(numbers): for idx2, elem2 in enumerate(numbers): if idx != idx2: if distance is None: ...
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]) == (3.9, 4.0) assert candidate([1.0, 2.0, 5.9, 4.0, 5.0]) == (5.0, 5.9) assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2) assert candidate([1.0, 2.0, 3.0, 4.0,...
find_closest_elements
bt_JHumanEval/21
(ๅฐ‘ใชใใจใ‚‚ 2 ใคไปฅไธŠใฎ่ฆ็ด ใ‹ใ‚‰ใชใ‚‹) ใƒชใ‚นใƒˆnumbersใซ็ทšๅฝขๅค‰ๆ›ใ‚’้ฉ็”จใ—ใ€ ๆœ€ๅฐใฎๆ•ฐๅ€คใŒ 0 ใซใชใ‚Šใ€ๆœ€ๅคงใฎๆ•ฐๅ€คใŒ 1 ใซใชใ‚‹ใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0]) [0.0, 0.25, 0.5, 0.75, 1.0]
from typing import List def rescale_to_unit(numbers: List[float]) -> List[float]: min_number = min(numbers) max_number = max(numbers) return [(x - min_number) / (max_number - min_number) for x in numbers]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([2.0, 49.9]) == [0.0, 1.0] assert candidate([100.0, 49.9]) == [1.0, 0.0] assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0] assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0....
rescale_to_unit
bt_JHumanEval/22
ไปปๆ„ใฎ็จฎ้กžใฎๅ€คใŒๅซใพใ‚Œใ‚‹ใƒชใ‚นใƒˆใ‹ใ‚‰ๆ•ดๆ•ฐๅ€คใฎใฟๆŠฝๅ‡บใ™ใ‚‹ >>> filter_integers(['a', 3.14, 5]) [5] >>> filter_integers([1, 2, 3, 'abc', {}, []]) [1, 2, 3]
from typing import List, Any def filter_integers(values: List[Any]) -> List[int]: return [x for x in values if isinstance(x, int)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([4, {}, [], 23.2, 9, 'adasd']) == [4, 9] assert candidate([3, 'c', 3, 3, 'a', 'b']) == [3, 3, 3] candidate = filter_integers check(candidate)
filter_integers
bt_JHumanEval/23
ๅผ•ๆ•ฐใงไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใฎ้•ทใ•ใ‚’่ฟ”ใ™ >>> strlen('') 0 >>> strlen('abc') 3
def strlen(string: str) -> int: return len(string)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == 0 assert candidate('x') == 1 assert candidate('asdasnakj') == 9 candidate = strlen check(candidate)
strlen
bt_JHumanEval/24
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ฐnใซใคใ„ใฆใ€nใฎ็ด„ๆ•ฐใฎใ†ใกใ€nใ‚ˆใ‚Šๅฐใ•ใ„ๆœ€ๅคงใฎๆ•ฐใ‚’ๆฑ‚ใ‚ใ‚‹ >>> largest_divisor(15) 5
def largest_divisor(n: int) -> int: for i in reversed(range(n)): if n % i == 0: return i
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(3) == 1 assert candidate(7) == 1 assert candidate(10) == 5 assert candidate(100) == 50 assert candidate(49) == 7 candidate = largest_divisor check(candidate)
largest_divisor
bt_JHumanEval/25
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ดๆ•ฐใฎ็ด ๅ› ๆ•ฐใฎใƒชใ‚นใƒˆใ‚’ๅฐใ•ใ„ใ‚‚ใฎใ‹ใ‚‰ๅคงใใ„ใ‚‚ใฎใฎ้ †ใซ่ฟ”ใ™ใ€‚ๅ„ๅ› ๆ•ฐใฏใ€ ๅ› ๆ•ฐๅˆ†่งฃใง็พใ‚Œใ‚‹ๅ›žๆ•ฐๅˆ†ใ€ใƒชใ‚นใƒˆใซ็™ปๅ ดใ™ใ‚‹ใ€‚ๅผ•ๆ•ฐใฎๆ•ดๆ•ฐใฏๅ…จใฆใฎๅ› ๆ•ฐใฎ็ฉใซ็ญ‰ใ—ใใช ใ‘ใ‚Œใฐใชใ‚‰ใชใ„ใ€‚ >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7]
from typing import List def factorize(n: int) -> List[int]: import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1 if n > 1: fact.append(n) return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * ...
factorize
bt_JHumanEval/26
ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใ‹ใ‚‰ใ€่ค‡ๆ•ฐๅ›žๅ‡บ็พใ™ใ‚‹่ฆ็ด ใ‚’ใ™ในใฆๅ–ใ‚Š้™คใใ€‚ ่ฆ็ด ใฎ้ †ๅบใฏๅ…ฅๅŠ›ใจๅŒใ˜ใ‚ˆใ†ใซใ™ใ‚‹ใ€‚ >>> remove_duplicates([1, 2, 3, 2, 4]) [1, 3, 4]
from typing import List def remove_duplicates(numbers: List[int]) -> List[int]: import collections c = collections.Counter(numbers) return [n for n in numbers if c[n] <= 1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5] candidate = remove_duplicates check(candidate)
remove_duplicates
bt_JHumanEval/27
ไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใซๅฏพใ—ใฆใ€่‹ฑๅฐๆ–‡ๅญ—ใ‚’่‹ฑๅคงๆ–‡ๅญ—ใซใ€่‹ฑๅคงๆ–‡ๅญ—ใ‚’่‹ฑๅฐๆ–‡ๅญ—ใซๅค‰ๆ›ใ™ใ‚‹ใ€‚ >>> flip_case('Hello') 'hELLO'
def flip_case(string: str) -> str: return string.swapcase()
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('Hello!') == 'hELLO!' assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS' candidate = flip_case check(candidate)
flip_case
bt_JHumanEval/28
ๆ–‡ๅญ—ๅˆ—ใฎใƒชใ‚นใƒˆใ‚’1ใคใฎๆ–‡ๅญ—ๅˆ—ใซ้€ฃ็ตใ™ใ‚‹ >>> concatenate([]) '' >>> concatenate(['a', 'b', 'c']) 'abc'
from typing import List def concatenate(strings: List[str]) -> str: return ''.join(strings)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == '' assert candidate(['x', 'y', 'z']) == 'xyz' assert candidate(['x', 'y', 'z', 'w', 'k']) == 'xyzwk' candidate = concatenate check(candidate)
concatenate
bt_JHumanEval/29
ๆ–‡ๅญ—ๅˆ—ใฎใƒชใ‚นใƒˆใ‹ใ‚‰ใ€ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆŽฅ้ ญ่พžprefixใงๅง‹ใพใ‚‹ใ‚‚ใฎใ ใ‘ใ‚’ๅ–ใ‚Šๅ‡บใ™ใ€‚ >>> filter_by_prefix([], 'a') [] >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a') ['abc', 'array']
from typing import List def filter_by_prefix(strings: List[str], prefix: str) -> List[str]: return [x for x in strings if x.startswith(prefix)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 'john') == [] assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx'] candidate = filter_by_prefix check(candidate)
filter_by_prefix
bt_JHumanEval/30
ใƒชใ‚นใƒˆๅ†…ใฎๆญฃใฎๆ•ฐใ ใ‘ใ‚’่ฟ”ใ™ใ€‚ >>> get_positive([-1, 2, -4, 5, 6]) [2, 5, 6] >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) [5, 3, 2, 3, 9, 123, 1]
def get_positive(l: list): return [e for e in l if e > 0]
METADATA = {} def check(candidate): assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6] assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1] assert candidate([-1, -2]) == [] assert candidate([]) == [] candidate = get_positive check(candidate)
get_positive
bt_JHumanEval/31
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ฐใŒ็ด ๆ•ฐใงใ‚ใ‚Œใฐ็œŸใ‚’ใ€ใใ†ใงใชใ‘ใ‚Œใฐๅฝใ‚’่ฟ”ใ™ใ€‚ >>> is_prime(6) False >>> is_prime(101) True >>> is_prime(11) True >>> is_prime(13441) True >>> is_prime(61) True >>> is_prime(4) False >>> is_prime(1) False
def is_prime(n): if n < 2: return False for k in range(2, n - 1): if n % k == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert ca...
is_prime
bt_JHumanEval/32
xsใฏๅคš้ …ๅผใฎไฟ‚ๆ•ฐใงใ‚ใ‚‹ใ€‚ find_zero้–ขๆ•ฐใฏใ€poly(x) = 0 ใจใชใ‚‹ x ใ‚’่ฆ‹ใคใ‘ใ‚‹ใ€‚ find_zero้–ขๆ•ฐใฏใ€ใŸใจใˆ่ค‡ๆ•ฐ่งฃใŒใ‚ใฃใŸใจใ—ใฆใ‚‚่งฃใ‚’ใฒใจใคใฎใฟใ‚’่ฟ”ใ™ใ€‚ ใ•ใ‚‰ใซใ€find_zero้–ขๆ•ฐใฏใ€่งฃใ‚’ๆŒใคใ“ใจใ‚’ไฟ่จผใ™ใ‚‹ใŸใ‚ใ€ๅถๆ•ฐๅ€‹ใฎไฟ‚ๆ•ฐxsใจ ๆœ€ๅคงไฟ‚ๆ•ฐใฏๅธธใซ0ใงใชใ„ใจๆƒณๅฎšใ™ใ‚‹ใ€‚ >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 ...
import math def poly(xs: list, x: float): return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end)...
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: co...
find_zero
bt_JHumanEval/33
ใ“ใฎ้–ขๆ•ฐใฏใƒชใ‚นใƒˆlใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€l'ใ‚’่ฟ”ใ™ใ€‚l'ใฏใ€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใŒ3ใงๅ‰ฒใ‚Š ๅˆ‡ใ‚Œใชใ„ๅ ดๅˆใฏlใจๅŒใ˜ใงใ‚ใ‚‹ใŒใ€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใŒ3ใงๅ‰ฒใ‚Šๅˆ‡ใ‚Œใ‚‹่ฆ็ด ใฏ ใ‚ฝใƒผใƒˆใ•ใ‚Œใฆใ„ใ‚‹ใ€‚ >>> sort_third([1, 2, 3]) [1, 2, 3] >>> sort_third([5, 6, 3, 4, 8, 9, 2]) [2, 6, 3, 4, 8, 9, 5]
def sort_third(l: list): l = list(l) l[::3] = sorted(l[::3]) return l
METADATA = {} def check(candidate): assert tuple(candidate([1, 2, 3])) == tuple(sort_third([1, 2, 3])) assert tuple(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) == tuple(sort_third([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == tuple(so...
sort_third
bt_JHumanEval/34
ใƒชใ‚นใƒˆๅ†…ใฎใƒฆใƒ‹ใƒผใ‚ฏใช่ฆ็ด ใ‚’ใ‚ฝใƒผใƒˆใ—ใฆ่ฟ”ใ™ >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123]) [0, 2, 3, 5, 9, 123]
def unique(l: list): return sorted(list(set(l)))
METADATA = {} def check(candidate): assert candidate([5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123] candidate = unique check(candidate)
unique
bt_JHumanEval/35
ใƒชใ‚นใƒˆๅ†…ใฎๆœ€ๅคง่ฆ็ด ใ‚’่ฟ”ใ™ใ€‚ >>> max_element([1, 2, 3]) 3 >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) 123
def max_element(l: list): m = l[0] for e in l: if e > m: m = e return m
METADATA = {} def check(candidate): assert candidate([1, 2, 3]) == 3 assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124 candidate = max_element check(candidate)
max_element
bt_JHumanEval/36
11ใพใŸใฏ13ใงๅ‰ฒใ‚Šๅˆ‡ใ‚Œใ‚‹nๆœชๆบ€ใฎๆ•ดๆ•ฐใฎไธญใซ7ใจใ„ใ†ๆ•ฐๅญ—ใŒ็พใ‚Œใ‚‹ๅ›žๆ•ฐใ‚’่ฟ”ใ™ใ€‚ >>> fizz_buzz(50) 0 >>> fizz_buzz(78) 2 >>> fizz_buzz(79) 3
def fizz_buzz(n: int): ns = [] for i in range(n): if i % 11 == 0 or i % 13 == 0: ns.append(i) s = ''.join(list(map(str, ns))) ans = 0 for c in s: ans += (c == '7') return ans
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 candidate = fizz_buz...
fizz_buzz
bt_JHumanEval/37
ใ“ใฎ้–ขๆ•ฐใฏใƒชใ‚นใƒˆ l ใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€l' ใ‚’่ฟ”ใ™ใ€‚l'ใฏใ€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใŒๅฅ‡ๆ•ฐใฎ ใจใใฏ l ใจๅŒใ˜ใงใ€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใŒๅถๆ•ฐใฎใจใใฏใ‚ฝใƒผใƒˆใ•ใ‚Œใฆใ„ใ‚‹ใ€‚ >>> sort_even([1, 2, 3]) [1, 2, 3] >>> sort_even([5, 6, 3, 4]) [3, 6, 5, 4]
def sort_even(l: list): evens = l[::2] odds = l[1::2] evens.sort() ans = [] for e, o in zip(evens, odds): ans.extend([e, o]) if len(evens) > len(odds): ans.append(evens[-1]) return ans
METADATA = {} def check(candidate): assert tuple(candidate([1, 2, 3])) == tuple([1, 2, 3]) assert tuple(candidate([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])) == tuple([-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]) assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == tuple([-12, 8, 3, 4, 5, 2, 12, 1...
sort_even
bt_JHumanEval/38
encode_cyclic้–ขๆ•ฐใงใ‚จใƒณใ‚ณใƒผใƒ‰ใ•ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใซๅ–ใ‚Šใ€ใƒ‡ใ‚ณใƒผใƒ‰ใ•ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ™ใ€‚
def encode_cyclic(s: str): # ๆ–‡ๅญ—ๅˆ—้•ทใŒ3ใซใชใ‚‹ใ‚ˆใ†ใซๆ–‡ๅญ—ๅˆ—ใ‚’ใ‚ฐใƒซใƒผใƒ—ๅŒ– groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)] # ใ‚ฐใƒซใƒผใƒ—ใฎ้•ทใ•ใŒ3ๆœชๆบ€ใงใชใ„้™ใ‚Šใ€ๅ„ใ‚ฐใƒซใƒผใƒ—ใ‚’ๅพช็’ฐใ•ใ›ใ‚‹ groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups] return "".join(groups) def decode_cyclic(s: st...
METADATA = {} def check(candidate): from random import randint, choice import string letters = string.ascii_lowercase for _ in range(100): str = ''.join(choice(letters) for i in range(randint(10, 20))) encoded_str = encode_cyclic(str) assert candidate(encoded_str) == str c...
decode_cyclic
bt_JHumanEval/39
prime_fib ใฏใƒ•ใ‚ฃใƒœใƒŠใƒƒใƒๆ•ฐใงใ€ใ‹ใค็ด ๆ•ฐใงใ‚ใ‚‹n็•ช็›ฎใฎๆ•ฐใ‚’่ฟ”ใ™ใ€‚ >>> prime_fib(1) 2 >>> prime_fib(2) 3 >>> prime_fib(3) 5 >>> prime_fib(4) 13 >>> prime_fib(5) 89
def prime_fib(n: int): import math def is_prime(p): if p < 2: return False for k in range(2, min(int(math.sqrt(p)) + 1, p - 1)): if p % k == 0: return False return True f = [0, 1] while True: f.append(f[-1] + f[-2]) if is_p...
METADATA = {} def check(candidate): assert candidate(1) == 2 assert candidate(2) == 3 assert candidate(3) == 5 assert candidate(4) == 13 assert candidate(5) == 89 assert candidate(6) == 233 assert candidate(7) == 1597 assert candidate(8) == 28657 assert candidate(9) == 514229 ...
prime_fib
bt_JHumanEval/40
triples_sum_to_zero ใฏๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใ‚’ๅผ•ๆ•ฐใซๅ–ใ‚Šใ€ ใƒชใ‚นใƒˆใฎไธญใซๅ’ŒใŒ0ใซใชใ‚‹๏ผ“ใคใฎ่ฆ็ด ใŒใ‚ใ‚ŒใฐTrueใ‚’ใ€ ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™ใ€‚ >>> 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...
def triples_sum_to_zero(l: list): 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 asser...
triples_sum_to_zero
bt_JHumanEval/41
ๅฎŒๅ…จใช็›ด็ทšใง็„ก้™ใซ้•ทใ„้“่ทฏใ‚’ๆƒณๅƒใ—ใฆใปใ—ใ„ใ€‚ nๅฐใฎ่ปŠใŒๅทฆใ‹ใ‚‰ๅณใซๅ‘ใ‹ใฃใฆ่ตฐใฃใฆใ„ใ‚‹ใ€‚ๅŒๆ™‚ใซใ€ๅˆฅใฎnๅฐใฎ่ปŠใŒ ๅณใ‹ใ‚‰ๅทฆใซๅ‘ใ‹ใฃใฆ่ตฐใฃใฆใ„ใ‚‹ใ€‚ใ“ใฎ2็ต„ใฎ่ปŠใฏใ€ๆœ€ๅˆใฏไบ’ใ„ใซ้ž ๅธธใซ้›ขใ‚Œใฆใ„ใ‚‹ใ€‚ใ™ในใฆใฎ่ปŠใฏๅŒใ˜้€Ÿๅบฆใงๅ‹•ใใ€‚2ๅฐใฎ่ปŠใฏๆฌกใฎใ‚ˆ ใ†ใซ่ก็ชใ™ใ‚‹ใ€‚ๅทฆใ‹ใ‚‰ๅณใซๅ‹•ใ„ใฆใ„ใ‚‹่ปŠใŒใ€ๅณใ‹ใ‚‰ๅทฆใซๅ‹•ใ„ใฆใ„ใ‚‹ ่ปŠใซใถใคใ‹ใ‚‹ใ“ใจใ€‚ ใ—ใ‹ใ—ใ€่ปŠใฏ้™ใ‚Šใชใ้ ‘ไธˆใงๅผทใ„ใ€‚ใ‚ใŸใ‹ใ‚‚่ก็ชใ—ใชใ‹ใฃใŸใ‹ใฎใ‚ˆ ใ†ใซใ€ใใฎ่ปŒ้“ใ‚’้€ฒใฟ็ถšใ‘ใ‚‹ใ€‚ ใ“ใฎ้–ขๆ•ฐใฏใ€ใ“ใฎใ‚ˆใ†ใช่ก็ชใฎๅ›žๆ•ฐใ‚’ๅ‡บๅŠ›ใ™ใ‚‹ใ€‚
def car_race_collision(n: int): return n**2
METADATA = {} def check(candidate): assert candidate(2) == 4 assert candidate(3) == 9 assert candidate(4) == 16 assert candidate(8) == 64 assert candidate(10) == 100 candidate = car_race_collision check(candidate)
car_race_collision
bt_JHumanEval/42
่ฆ็ด ใ‚’1ใšใคๅข—ใ‚„ใ—ใŸใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ใ€‚ >>> incr_list([1, 2, 3]) [2, 3, 4] >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123]) [6, 4, 6, 3, 4, 4, 10, 1, 124]
def incr_list(l: list): return [(e + 1) for e in l]
METADATA = {} def check(candidate): assert candidate([]) == [] assert candidate([3, 2, 1]) == [4, 3, 2] assert candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]) == [6, 3, 6, 3, 4, 4, 10, 1, 124] candidate = incr_list check(candidate)
incr_list
bt_JHumanEval/43
pairs_sum_to_zero ใฏๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใ‚’ๅผ•ๆ•ฐใซใจใ‚‹ใ€‚ ใƒชใ‚นใƒˆใฎไธญใซ๏ผ’ใคใฎ่ฆ็ด ใฎๅ’ŒใŒใ‚ผใƒญใซใชใ‚‹่ฆ็ด ใŒใ‚ใ‚ŒใฐTrueใ‚’ใ€ ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™ใ€‚ >>> pairs_sum_to_zero([1, 3, 5, 0]) False >>> pairs_sum_to_zero([1, 3, -2, 1]) False >>> pairs_sum_to_zero([1, 2, 3, 7]) False >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7]) True >>> pairs_sum_to_ze...
def pairs_sum_to_zero(l): for i, l1 in enumerate(l): for j in range(i + 1, len(l)): if l1 + l[j] == 0: return True return False
METADATA = {} def check(candidate): assert candidate([1, 3, 5, 0]) == False assert candidate([1, 3, -2, 1]) == False assert candidate([1, 2, 3, 7]) == False assert candidate([2, 4, -5, 3, 5, 7]) == True assert candidate([1]) == False assert candidate([-3, 9, -1, 3, 2, 30]) == True asser...
pairs_sum_to_zero
bt_JHumanEval/44
ๅผ•ๆ•ฐxใฎๅŸบๆ•ฐใ‚’baseใซๅค‰ๆ›ใ™ใ‚‹ใ€‚ ่ฟ”ใ‚Šๅ€คใฏๅค‰ๆ›ๅพŒใฎๆ–‡ๅญ—ๅˆ—่กจ็พใงใ‚ใ‚‹ใ€‚ ๅŸบๆ•ฐใฏ10ๆœชๆบ€ใงใ‚ใ‚‹ใ€‚ >>> change_base(8, 3) '22' >>> change_base(8, 2) '1000' >>> change_base(7, 2) '111'
def change_base(x: int, base: int): ret = "" while x > 0: ret = str(x % base) + ret x //= base return ret
METADATA = {} def check(candidate): assert candidate(8, 3) == "22" assert candidate(9, 3) == "100" assert candidate(234, 2) == "11101010" assert candidate(16, 2) == "10000" assert candidate(8, 2) == "1000" assert candidate(7, 2) == "111" for x in range(2, 8): assert candidate(x, ...
change_base
bt_JHumanEval/45
ไธ‰่ง’ๅฝขใฎไธ€่พบใฎ้•ทใ•ใจ้ซ˜ใ•ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€้ข็ฉใ‚’่ฟ”ใ™ใ€‚ >>> triangle_area(5, 3) 7.5
def triangle_area(a, h): return a * h / 2.0
METADATA = {} def check(candidate): assert candidate(5, 3) == 7.5 assert candidate(2, 2) == 2.0 assert candidate(10, 8) == 40.0 candidate = triangle_area check(candidate)
triangle_area
bt_JHumanEval/46
fib4ๆ•ฐๅˆ—ใฏใƒ•ใ‚ฃใƒœใƒŠใƒƒใƒๆ•ฐๅˆ—ใซไผผใŸๆ•ฐๅˆ—ใงใ€ๆฌกใฎใ‚ˆใ†ใซๅฎš็พฉใ•ใ‚Œใ‚‹๏ผš fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). fib4ๆ•ฐๅˆ—ใฎn็•ช็›ฎใฎ่ฆ็ด ใ‚’ๅŠน็އ็š„ใซ่จˆ็ฎ—ใ™ใ‚‹้–ขๆ•ฐใ‚’ๆ›ธใ‘ใ€‚ๅ†ๅธฐใฏไฝฟใ‚ใชใ„ใ“ใจใ€‚ >>> fib4(5) 4 >>> fib4(6) 8 >>> fib4(7) 14
def fib4(n: int): results = [0, 0, 2, 0] if n < 4: return results[n] for _ in range(4, n + 1): results.append(results[-1] + results[-2] + results[-3] + results[-4]) results.pop(0) return results[-1]
METADATA = {} def check(candidate): assert candidate(5) == 4 assert candidate(8) == 28 assert candidate(10) == 104 assert candidate(12) == 386 candidate = fib4 check(candidate)
fib4
bt_JHumanEval/47
ใƒชใ‚นใƒˆ l ใฎ่ฆ็ด ใฎไธญๅคฎๅ€คใ‚’่ฟ”ใ™ใ€‚ >>> median([3, 1, 2, 4, 5]) 3 >>> median([-10, 4, 6, 1000, 10, 20]) 15.0
def median(l: list): l = sorted(l) if len(l) % 2 == 1: return l[len(l) // 2] else: return (l[len(l) // 2 - 1] + l[len(l) // 2]) / 2.0
METADATA = {} def check(candidate): assert candidate([3, 1, 2, 4, 5]) == 3 assert candidate([-10, 4, 6, 1000, 10, 20]) == 8.0 assert candidate([5]) == 5 assert candidate([6, 5]) == 5.5 assert candidate([8, 1, 3, 9, 9, 2, 7]) == 7 candidate = median check(candidate)
median
bt_JHumanEval/48
ไธŽใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใŒๅ›žๆ–‡ใ‹ใฉใ†ใ‹ใ‚’ๅˆคๅฎšใ™ใ‚‹ >>> is_palindrome('') True >>> is_palindrome('aba') True >>> is_palindrome('aaaaa') True >>> is_palindrome('zbcd') False
def is_palindrome(text: str): for i in range(len(text)): if text[i] != text[len(text) - 1 - i]: return False return True
METADATA = {} def check(candidate): assert candidate('') == True assert candidate('aba') == True assert candidate('aaaaa') == True assert candidate('zbcd') == False assert candidate('xywyx') == True assert candidate('xywyz') == False assert candidate('xywzx') == False candidate = is_pa...
is_palindrome
bt_JHumanEval/49
2^n ใ‚’ p ใงๅ‰ฒใฃใŸใƒขใ‚ธใƒฅใƒญใ‚’่ฟ”ใ™ใ€‚่จˆ็ฎ—็ฒพๅบฆใซๆณจๆ„ใ€‚ >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1
def modp(n: int, p: int): 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 candidate = modp check(candidate)
modp
bt_JHumanEval/50
encode_shift้–ขๆ•ฐใงใ‚จใƒณใ‚ณใƒผใƒ‰ใ•ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใซๅ–ใ‚Šใ€ใƒ‡ใ‚ณใƒผใƒ‰ใ•ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ™ใ€‚
def encode_shift(s: str): return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s]) def decode_shift(s: str): return "".join([chr(((ord(ch) - 5 - ord("a")) % 26) + ord("a")) for ch in s])
METADATA = {} def check(candidate): from random import randint, choice import copy import string letters = string.ascii_lowercase for _ in range(100): str = ''.join(choice(letters) for i in range(randint(10, 20))) encoded_str = encode_shift(str) assert candidate(copy.dee...
decode_shift
bt_JHumanEval/51
remove_vowelsใฏๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใซๅ–ใ‚Šใ€ๆฏ้Ÿณใ‚’้™คใ„ใŸๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ™้–ขๆ•ฐใงใ‚ใ‚‹ใ€‚ >>> remove_vowels('') '' >>> remove_vowels("abcdef\nghijklm") 'bcdf\nghjklm' >>> remove_vowels('abcdef') 'bcdf' >>> remove_vowels('aaaaa') '' >>> remove_vowels('aaBAA') 'B' >>> remove_vowels('zbcd') 'zbcd'
def remove_vowels(text): return "".join([s for s in text if s.lower() not in ["a", "e", "i", "o", "u"]])
METADATA = {} def check(candidate): assert candidate('') == '' assert candidate("abcdef\nghijklm") == 'bcdf\nghjklm' assert candidate('fedcba') == 'fdcb' assert candidate('eeeee') == '' assert candidate('acBAA') == 'cB' assert candidate('EcBOO') == 'cB' assert candidate('ybcd') == 'ybcd'...
remove_vowels
bt_JHumanEval/52
ใƒชใ‚นใƒˆ l ๅ†…ใฎๅ…จใฆใฎๆ•ฐๅ€คใŒ้–พๅ€ค t ไปฅไธ‹ใฎๅ ดๅˆใ€Trueใ‚’่ฟ”ใ™ใ€‚ >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False
def below_threshold(l: list, t: int): 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) candidate = below_threshold...
below_threshold
bt_JHumanEval/53
2ใคใฎๆ•ฐxใจyใ‚’่ถณใ™ >>> add(2, 3) 5 >>> add(5, 7) 12
def add(x: int, y: int): return x + y
METADATA = {} def check(candidate): import random assert candidate(0, 1) == 1 assert candidate(1, 0) == 1 assert candidate(2, 3) == 5 assert candidate(5, 7) == 12 assert candidate(7, 5) == 12 for i in range(100): x, y = random.randint(0, 1000), random.randint(0, 1000) a...
add
bt_JHumanEval/54
2ใคใฎๅ˜่ชžใŒๅŒใ˜ๆ–‡ๅญ—ใ‚ปใƒƒใƒˆใ‹ใ‚‰ๆง‹ๆˆใ•ใ‚Œใ‚‹ใ‹ใฉใ†ใ‹ๅˆคๅฎšใ™ใ‚‹ใ€‚ >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc') True >>> same_chars('abcd', 'dddddddabc') True >>> same_chars('dddddddabc', 'abcd') True >>> same_chars('eabcd', 'dddddddabc') False >>> same_chars('abcd', 'dddddddabce') False >>> same_chars('eab...
def same_chars(s0: str, s1: str): return set(s0) == set(s1)
METADATA = {} def check(candidate): assert candidate('eabcdzzzz', 'dddzzzzzzzddeddabc') == True assert candidate('abcd', 'dddddddabc') == True assert candidate('dddddddabc', 'abcd') == True assert candidate('eabcd', 'dddddddabc') == False assert candidate('abcd', 'dddddddabcf') == False asse...
same_chars
bt_JHumanEval/55
n็•ช็›ฎใฎใƒ•ใ‚ฃใƒœใƒŠใƒƒใƒๆ•ฐใ‚’่ฟ”ใ™ใ€‚ >>> fib(10) 55 >>> fib(1) 1 >>> fib(8) 21
def fib(n: int): if n == 0: return 0 if n == 1: return 1 return fib(n - 1) + fib(n - 2)
METADATA = {} def check(candidate): assert candidate(10) == 55 assert candidate(1) == 1 assert candidate(8) == 21 assert candidate(11) == 89 assert candidate(12) == 144 candidate = fib check(candidate)
fib
bt_JHumanEval/56
ๅผ•ๆ•ฐbracketsใฏ"<"ใจ">"ใฎๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚‹ใ€‚ ใ™ในใฆใฎ้–‹ใๆ‹ฌๅผงใŒๅฏพๅฟœใ™ใ‚‹้–‰ใ˜ๆ‹ฌๅผงใ‚’ๆŒใคๅ ดๅˆใ€Trueใ‚’่ฟ”ใ™ใ€‚ >>> correct_bracketing("<") False >>> correct_bracketing("<>") True >>> correct_bracketing("<<><>>") True >>> correct_bracketing("><<>") False
def correct_bracketing(brackets: str): depth = 0 for b in brackets: if b == "<": depth += 1 else: depth -= 1 if depth < 0: return False return depth == 0
METADATA = {} def check(candidate): assert candidate("<>") assert candidate("<<><>>") assert candidate("<><><<><>><>") assert candidate("<><><<<><><>><>><<><><<>>>") assert not candidate("<<<><>>>>") assert not candidate("><<>") assert not candidate("<") assert not candidate("<<<<") ...
correct_bracketing
bt_JHumanEval/57
ใƒชใ‚นใƒˆใฎ่ฆ็ด ใŒๅ˜่ชฟๅข—ๅŠ ใพใŸใฏๅ˜่ชฟๆธ›ๅฐ‘ใ™ใ‚‹ๅ ดๅˆใซTrueใ‚’่ฟ”ใ™ใ€‚ >>> monotonic([1, 2, 4, 20]) True >>> monotonic([1, 20, 4, 10]) False >>> monotonic([4, 1, 0, -10]) True
def monotonic(l: list): if l == sorted(l) or l == sorted(l, reverse=True): return True return False
METADATA = {} def check(candidate): assert candidate([1, 2, 4, 10]) == True assert candidate([1, 2, 4, 20]) == True assert candidate([1, 20, 4, 10]) == False assert candidate([4, 1, 0, -10]) == True assert candidate([4, 1, 1, 0]) == True assert candidate([1, 2, 3, 2, 5, 60]) == False ass...
monotonic
bt_JHumanEval/58
2ใคใฎใƒชใ‚นใƒˆใซใคใ„ใฆใ€ใƒฆใƒ‹ใƒผใ‚ฏใชๅ…ฑ้€š่ฆ็ด ใ‚’ใ‚ฝใƒผใƒˆใ—ใฆ่ฟ”ใ™ใ€‚ >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) [1, 5, 653] >>> common([5, 3, 2, 8], [3, 2]) [2, 3]
def common(l1: list, l2: list): ret = set() for e1 in l1: for e2 in l2: if e1 == e2: ret.add(e1) return sorted(list(ret))
METADATA = {} def check(candidate): assert candidate([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653] assert candidate([5, 3, 2, 8], [3, 2]) == [2, 3] assert candidate([4, 3, 2, 8], [3, 2, 4]) == [2, 3, 4] assert candidate([4, 3, 2, 8], []) == [] candidate = common check(candida...
common
bt_JHumanEval/59
nใฎๆœ€ๅคงใจใชใ‚‹็ด ๅ› ๆ•ฐใ‚’่ฟ”ใ™ใ€‚ใŸใ ใ—ใ€ n > 1 ใ‚’ๅ‰ๆใจใ—ใ€็ด ๆ•ฐใงใฏใชใ„ใ‚‚ใฎใจใ™ใ‚‹ใ€‚ >>> largest_prime_factor(13195) 29 >>> largest_prime_factor(2048) 2
def largest_prime_factor(n: int): def is_prime(k): if k < 2: return False for i in range(2, k - 1): if k % i == 0: return False return True largest = 1 for j in range(2, n + 1): if n % j == 0 and is_prime(j): largest = max(l...
METADATA = {} def check(candidate): assert candidate(15) == 5 assert candidate(27) == 3 assert candidate(63) == 7 assert candidate(330) == 11 assert candidate(13195) == 29 candidate = largest_prime_factor check(candidate)
largest_prime_factor
bt_JHumanEval/60
sum_to_nใฏ1ใ‹ใ‚‰nใพใงใฎ็ทๅ’Œใ‚’ๆฑ‚ใ‚ใ‚‹้–ขๆ•ฐใงใ‚ใ‚‹ใ€‚ >>> sum_to_n(30) 465 >>> sum_to_n(100) 5050 >>> sum_to_n(5) 15 >>> sum_to_n(10) 55 >>> sum_to_n(1) 1
def sum_to_n(n: int): return sum(range(n + 1))
METADATA = {} def check(candidate): assert candidate(1) == 1 assert candidate(6) == 21 assert candidate(11) == 66 assert candidate(30) == 465 assert candidate(100) == 5050 candidate = sum_to_n check(candidate)
sum_to_n
bt_JHumanEval/61
ๅผ•ๆ•ฐbracketsใฏ"("ใจ") "ใ‹ใ‚‰ใชใ‚‹ๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚‹ใ€‚ ใ™ในใฆใฎ้–‹ใๆ‹ฌๅผงใŒๅฏพๅฟœใ™ใ‚‹้–‰ใ˜ๆ‹ฌๅผงใ‚’ๆŒใคๅ ดๅˆใ€Trueใ‚’่ฟ”ใ™ใ€‚ >>> correct_bracketing("(") False >>> correct_bracketing("()") True >>> correct_bracketing("(()())") True >>> correct_bracketing(")(()") False
def correct_bracketing(brackets: str): depth = 0 for b in brackets: if b == "(": depth += 1 else: depth -= 1 if depth < 0: return False return depth == 0
METADATA = {} def check(candidate): assert candidate("()") assert candidate("(()())") assert candidate("()()(()())()") assert candidate("()()((()()())())(()()(()))") assert not candidate("((()())))") assert not candidate(")(()") assert not candidate("(") assert not candidate("((((") ...
correct_bracketing
bt_JHumanEval/62
xsใฏๅคš้ …ๅผใฎไฟ‚ๆ•ฐๅˆ—ใ‚’่กจใ™ใ€‚ xs[0] + xs[1] * x + xs[2] * x^2 + .... ้–ขๆ•ฐใฏใ€ใ“ใฎๅคš้ …ๅผใฎๅฐŽ้–ขๆ•ฐใ‚’ๅŒใ˜ๅฝขๅผใง่ฟ”ใ™ใ€‚ >>> derivative([3, 1, 2, 4, 5]) [1, 4, 12, 20] >>> derivative([1, 2, 3]) [2, 6]
def derivative(xs: list): return [(i * x) for i, x in enumerate(xs)][1:]
METADATA = {} def check(candidate): assert candidate([3, 1, 2, 4, 5]) == [1, 4, 12, 20] assert candidate([1, 2, 3]) == [2, 6] assert candidate([3, 2, 1]) == [2, 2] assert candidate([3, 2, 1, 0, 4]) == [2, 2, 0, 16] assert candidate([1]) == [] candidate = derivative check(candidate)
derivative
bt_JHumanEval/63
FibFibๆ•ฐๅˆ—ใฏใƒ•ใ‚ฃใƒœใƒŠใƒƒใƒๆ•ฐๅˆ—ใซไผผใŸๆ•ฐๅˆ—ใงใ€ไปฅไธ‹ใฎใ‚ˆใ†ใซๅฎš็พฉใ•ใ‚Œใ‚‹๏ผš fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). fibfibๆ•ฐๅˆ—ใฎn็•ช็›ฎใฎ่ฆ็ด ใ‚’ๅŠน็އใ‚ˆใ่จˆ็ฎ—ใ™ใ‚‹้–ขๆ•ฐใ‚’ๆ›ธใ„ใฆใใ ใ•ใ„ใ€‚ >>> fibfib(1) 0 >>> fibfib(5) 4 >>> fibfib(8) 24
def fibfib(n: int): if n == 0: return 0 if n == 1: return 0 if n == 2: return 1 return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3)
METADATA = {} def check(candidate): assert candidate(2) == 1 assert candidate(1) == 0 assert candidate(5) == 4 assert candidate(8) == 24 assert candidate(10) == 81 assert candidate(12) == 274 assert candidate(14) == 927 candidate = fibfib check(candidate)
fibfib
bt_JHumanEval/64
ๅ˜่ชžใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใจใ—ใ€ใใฎๆ–‡ๅญ—ๅˆ—ใซๅซใพใ‚Œใ‚‹ๆฏ้Ÿณใฎๆ•ฐใ‚’่ฟ”ใ™ ้–ขๆ•ฐ vowels_count ใ‚’ๆ›ธใใชใ•ใ„ใ€‚ใ“ใฎๅ ดๅˆใฎๆฏ้Ÿณใฏ'a', 'e', 'i', 'o', 'u'ใงใ‚ใ‚‹ใ€‚ ใ“ใ“ใงใ€ไธŽใˆใ‚‰ใ‚ŒใŸๅ˜่ชžใฎๆœซๅฐพใซใ‚ใ‚‹ๅ ดๅˆใฎใฟใ€'y'ใ‚‚ๆฏ้Ÿณใจใ™ใ‚‹ใ€‚ ไพ‹: >>> vowels_count("abcde") 2 >>> vowels_count("ACEDY") 3
FIX = def vowels_count(s): vowels = "aeiouAEIOU" n_vowels = sum(c in vowels for c in s) if s[-1] == 'y' or s[-1] == 'Y': n_vowels += 1 return n_vowels
def check(candidate): # Check some simple cases assert candidate("abcde") == 2, "Test 1" assert candidate("Alone") == 3, "Test 2" assert candidate("key") == 2, "Test 3" assert candidate("bye") == 1, "Test 4" assert candidate("keY") == 2, "Test 5" assert candidate("bYe") == 1, "Test 6" a...
vowels_count
bt_JHumanEval/65
ๆ•ดๆ•ฐ x ใฎๆกใ‚’ๅพช็’ฐใ‚ทใƒ•ใƒˆใ™ใ‚‹ใ€‚shift ๅˆ†ใ ใ‘ๆกใ‚’ๅณใซใ‚ทใƒ•ใƒˆใ—ใ€็ตๆžœใ‚’ๆ–‡ๅญ—ๅˆ—ใจใ—ใฆ่ฟ”ใ™ใ€‚ ใ‚‚ใ—ใ€shift > ๆกๆ•ฐใชใ‚‰ใ€ๆกใ‚’ๅ่ปขใ—ใฆ่ฟ”ใ™ใ€‚ >>> circular_shift(12, 1) "21" >>> circular_shift(12, 2) "12"
def circular_shift(x, shift): s = str(x) if shift > len(s): return s[::-1] else: return s[len(s) - shift:] + s[:len(s) - shift]
def check(candidate): # Check some simple cases assert candidate(100, 2) == "001" assert candidate(12, 2) == "12" assert candidate(97, 8) == "79" assert candidate(12, 1) == "21", "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by han...
circular_shift
bt_JHumanEval/66
ใ‚ฟใ‚นใ‚ฏ ๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใซใจใ‚Šใ€่‹ฑๅคงๆ–‡ๅญ—ใฎใฟใฎASCIIใ‚ณใƒผใƒ‰ใฎๅ’Œใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใใ€‚ Examples: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abcCd") => 67 digitSum("helloE") => 69 digitSum("woArBld") => 131 digitSum("aAaaaXa") => 153
def digitSum(s): if s == "": return 0 return sum(ord(char) if char.isupper() else 0 for char in s)
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate("") == 0, "Error" assert candidate("abAB") == 131, "Error" assert candidate("abcCd") == 67, "Error" assert candidate("helloE") == 69, "Error" assert candi...
digitSum
bt_JHumanEval/67
ใ“ใฎ่ชฒ้กŒใงใฏใ€ๆžœ็‰ฉใฎๅ…ฅใฃใŸใ‚ซใ‚ดใซ้…ใ‚‰ใ‚ŒใŸใƒชใƒณใ‚ดใจใ‚ชใƒฌใƒณใ‚ธใฎๆ•ฐใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—ใŒ ไธŽใˆใ‚‰ใ‚Œใ€ใ“ใฎใ‚ซใ‚ดใซใฏใƒชใƒณใ‚ดใ€ใ‚ชใƒฌใƒณใ‚ธใ€ใƒžใƒณใ‚ดใƒผใฎๆžœๅฎŸใŒๅ…ฅใฃใฆใ„ใ‚‹ใ€‚ใ‚ชใƒฌใƒณใ‚ธ ใจใƒชใƒณใ‚ดใฎ็ทๆ•ฐใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—ใจใ€ใ‹ใ”ใฎไธญใฎๆžœ็‰ฉใฎ็ทๆ•ฐใ‚’่กจใ™ๆ•ดๆ•ฐใŒไธŽใˆใ‚‰ใ‚ŒใŸใ‚‰ใ€ ใ‹ใ”ใฎไธญใฎใƒžใƒณใ‚ดใƒผใฎๆžœ็‰ฉใฎๆ•ฐใ‚’่ฟ”ใ—ใชใ•ใ„ใ€‚ ใŸใจใˆใฐ: fruit_distribution("5 apples and 6 oranges", 19) ->19 - 5 - 6 = 8 fruit_distribution("0 apples and 1 oranges",3) -> 3 - 0 - 1 = 2 fruit_distribution...
def fruit_distribution(s,n): lis = list() for i in s.split(' '): if i.isdigit(): lis.append(int(i)) return n - sum(lis)
def check(candidate): # Check some simple cases assert candidate("5 apples and 6 oranges",19) == 8 assert candidate("5 apples and 6 oranges",21) == 10 assert candidate("0 apples and 1 oranges",3) == 2 assert candidate("1 apples and 0 oranges",3) == 2 assert candidate("2 apples and 3 oranges",10...
fruit_distribution
bt_JHumanEval/68
้ž่ฒ ๆ•ดๆ•ฐใฎใƒŽใƒผใƒ‰ใ‚’ๆŒใคๆœจใฎๆžใ‚’่กจใ™้…ๅˆ—ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใ™ใ‚‹ใ€‚ใ‚ใชใŸใฎไป•ไบ‹ใฏใ€ ใƒŽใƒผใƒ‰ใฎ1ใคใ‚’ๆŠœใๅ–ใ‚Šใ€ใใ‚Œใ‚’่ฟ”ใ™ใ“ใจใงใ‚ใ‚‹ใ€‚ ๆ‘˜ๅ‡บใ•ใ‚Œใ‚‹ใƒŽใƒผใƒ‰ใฏใ€ๆœ€ๅฐๅถๆ•ฐๅ€คใ‚’ๆŒใคใƒŽใƒผใƒ‰ใงใชใ‘ใ‚Œใฐใชใ‚‰ใชใ„ใ€‚ ๅŒใ˜ๆœ€ๅฐๅถๆ•ฐๅ€คใ‚’ๆŒใคใƒŽใƒผใƒ‰ใŒ่ค‡ๆ•ฐ่ฆ‹ใคใ‹ใฃใŸๅ ดๅˆใฏใ€ๆœ€ๅฐใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใ‚’ๆŒใค ใƒŽใƒผใƒ‰ใ‚’่ฟ”ใ™ใ€‚ ๆ‘˜ๅ‡บใ•ใ‚ŒใŸใƒŽใƒผใƒ‰ใฏ [ smalest_value, its index ] ใจใ„ใ†ใƒชใ‚นใƒˆใง่ฟ”ใ•ใ‚Œใชใ‘ใ‚Œใฐใชใ‚‰ใชใ„ใ€‚ ๅถๆ•ฐๅ€คใŒใชใ„ๅ ดๅˆใ‚„ไธŽใˆใ‚‰ใ‚ŒใŸ้…ๅˆ—ใŒ็ฉบใฎๅ ดๅˆใฏ [] ใ‚’่ฟ”ใ—ใพใ™ใ€‚ ไพ‹ 1: ๅ…ฅๅŠ›: [4,2,3] ๅ‡บๅŠ›: [2, 1] ่งฃ่ชฌ: 2ใฏๆœ€...
def pluck(arr): if(len(arr) == 0): return [] evens = list(filter(lambda x: x%2 == 0, arr)) if(evens == []): return [] return [min(evens), arr.index(min(evens))]
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([4,2,3]) == [2, 1], "Error" assert candidate([1,2,3]) == [2, 1], "Error" assert candidate([]) == [], "Error" assert candidate([5, 0, 3, 0, 4, 2]) == [0, 1], "...
pluck
bt_JHumanEval/69
ๆญฃใฎๆ•ดๆ•ฐใฎ็ฉบใงใชใ„ใƒชใ‚นใƒˆใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใ€‚0ใ‚ˆใ‚Šๅคงใใใ€ใใฎๆ•ดๆ•ฐ่‡ช่บซใฎๅ€คไปฅไธŠใฎ้ ปๅบฆใ‚’ ๆŒใคๆœ€ๅคงใฎๆ•ดๆ•ฐใ‚’่ฟ”ใ›ใ€‚ๆ•ดๆ•ฐใฎ้ ปๅบฆใจใฏใ€ใใ‚ŒใŒใƒชใ‚นใƒˆใซ็พใ‚Œใ‚‹ๅ›žๆ•ฐใงใ‚ใ‚‹ใ€‚ ใใฎใ‚ˆใ†ใชๅ€คใŒๅญ˜ๅœจใ—ใชใ„ๅ ดๅˆใฏ -1 ใ‚’่ฟ”ใ™ใ€‚ ไพ‹: 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
def search(lst): 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...
search
bt_JHumanEval/70
ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ใƒชใ‚นใƒˆใ‚’ๅฅ‡ๅฆ™ใช้ †ๅบใง่ฟ”ใ™ใ€‚ ๅฅ‡ๅฆ™ใชใ‚ฝใƒผใƒˆใจใฏใ€ๆœ€ๅฐๅ€คใ‹ใ‚‰ๅง‹ใพใ‚Šใ€ๆฎ‹ใ‚Šใฎๆ•ดๆ•ฐใฎๆœ€ๅคงๅ€คใ€ๆœ€ๅฐๅ€คใฎ้ †ใง ใ‚ฝใƒผใƒˆใ™ใ‚‹ใ“ใจใงใ‚ใ‚‹ใ€‚ ไพ‹: strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3] strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5] strange_sort_list([]) == []
def strange_sort_list(lst): res, switch = [], True while lst: res.append(min(lst) if switch else max(lst)) lst.remove(res[-1]) switch = not switch return res
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3] assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7] assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3] assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7] assert candidate([5, 5, 5, 5]) == [...
strange_sort_list
bt_JHumanEval/71
ไธ‰่ง’ๅฝขใฎ3่พบใฎ้•ทใ•ใŒไธŽใˆใ‚‰ใ‚ŒใŸใ€‚3่พบใŒๆœ‰ๅŠนใชไธ‰่ง’ๅฝขใ‚’ๅฝขๆˆใ—ใฆใ„ใ‚Œใฐใ€ ไธ‰่ง’ๅฝขใฎ้ข็ฉใ‚’ๅฐๆ•ฐ็‚นไปฅไธ‹2ๆกใงๅ››ๆจไบ”ๅ…ฅใ—ใฆ่ฟ”ใ™ใ€‚ใใ†ใงใชใ„ๅ ดๅˆใฏ-1ใ‚’ ่ฟ”ใ™ใ€‚ ไปปๆ„ใฎ2่พบใฎๅ’ŒใŒ3่พบใ‚ˆใ‚Šๅคงใใ„ใจใใ€3่พบใฏๆœ‰ๅŠนใชไธ‰่ง’ๅฝขใจใชใ‚‹ใ€‚ ไพ‹: triangle_area(3, 4, 5) == 6.00 triangle_area(1, 2, 10) == -1
def triangle_area(a, b, c): if a + b <= c or a + c <= b or b + c <= a: return -1 s = (a + b + c)/2 area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 area = round(area, 2) return area
def check(candidate): # Check some simple cases assert candidate(3, 4, 5) == 6.00, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1, 2, 10) == -1 assert candidate(4, 8, 5) == 8.18 assert candidate(2, 2, 2) == 1.73 assert candidate(1, 2, 3) == -1 assert candidate...
triangle_area
bt_JHumanEval/72
็‰ฉไฝ“qใŒ้ฃ›ในใฐTrueใ‚’ใ€ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใ‘ใ€‚ ็‰ฉไฝ“qใฏใƒใƒฉใƒณใ‚นใŒๅ–ใ‚Œใฆใ„ใฆ๏ผˆใคใพใ‚Šใ€ใƒชใ‚นใƒˆใŒๅ›žๆ–‡ใงใ‚ใฃใฆ๏ผ‰ใ€ใใฎ่ฆ็ด ใฎๅ’ŒใŒ ๆœ€ๅคง่ท้‡wไปฅไธ‹ใงใ‚ใ‚Œใฐ้ฃ›ใถใ€‚ ไพ‹: will_it_fly([1, 2], 5) โžž False # 1+2 ใฏๆœ€ๅคง่ท้‡ไปฅไธ‹ใงใ‚ใ‚‹ใŒใ€ใƒใƒฉใƒณใ‚นใŒๅ–ใ‚Œใฆใ„ใชใ„ will_it_fly([3, 2, 3], 1) โžž False # ใƒใƒฉใƒณใ‚นใŒๅ–ใ‚Œใฆใ„ใ‚‹ใŒใ€3+2+3 ใฏๆœ€ๅคง่ท้‡ใ‚’่ถ…ใˆใ‚‹ will_it_fly([3, 2, 3], 9) โžž True # 3+2+3 ใฏๆœ€ๅคง่ท้‡ไปฅไธ‹ใงใ‚ใ‚Šใ€ใƒใƒฉใƒณ...
def will_it_fly(q,w): if sum(q) > w: return False i, j = 0, len(q)-1 while i<j: if q[i] != q[j]: return False i+=1 j-=1 return True
def check(candidate): # Check some simple cases assert candidate([3, 2, 3], 9) is True assert candidate([1, 2], 5) is False assert candidate([3], 5) is True assert candidate([3, 2, 3], 1) is False # Check some edge cases that are easy to work out by hand. assert candidate([1, 2, 3], 6) is...
will_it_fly
bt_JHumanEval/73
ๆ•ดๆ•ฐใฎ้…ๅˆ—arrใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ใใฎ้…ๅˆ—ใ‚’ๅ›žๆ–‡้…ๅˆ—ใซใ™ใ‚‹ใŸใ‚ใซ ๅฟ…่ฆใช่ฆ็ด ใฎๆœ€ๅฐๆ•ฐใ‚’ๆฑ‚ใ‚ใ‚ˆใ€‚ๅ›žๆ–‡้…ๅˆ—ใจใฏใ€ๅ‰ใ‹ใ‚‰ใ‚‚ๅพŒใ‹ใ‚‰ใ‚‚ๅŒใ˜ ใ‚ˆใ†ใซใชใ‚‹้…ๅˆ—ใฎใ“ใจใงใ‚ใ‚‹ใ€‚1ๅ›žใฎๅค‰ๆ›ดใงใ€1ใคใฎ่ฆ็ด ใ‚’ไป–ใฎไปปๆ„ใฎ ่ฆ็ด ใซๅค‰ๆ›ดใงใใ‚‹ใ€‚ ไพ‹ใˆใฐ: 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
def smallest_change(arr): 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...
smallest_change
bt_JHumanEval/74
๏ผ’ใคใฎๆ–‡ๅญ—ๅˆ—ใƒชใ‚นใƒˆใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ใƒชใ‚นใƒˆใฎๅ…จๆ–‡ๅญ—ๆ•ฐใฎๅˆ่จˆใŒใ‚‚ใ†ไธ€ๆ–น ใฎใƒชใ‚นใƒˆใ‚ˆใ‚Šๅฐ‘ใชใ„ใƒชใ‚นใƒˆใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใใชใ•ใ„ใ€‚ ใ‚‚ใ—2ใคใฎใƒชใ‚นใƒˆใฎๆ–‡ๅญ—ๆ•ฐใŒๅŒใ˜ใชใ‚‰ใ€ๆœ€ๅˆใฎใƒชใ‚นใƒˆใ‚’่ฟ”ใ™ใ€‚ ไพ‹ total_match([], []) โžž [] total_match(['hi', 'admin'], ['hI', 'Hi']) โžž ['hI', 'Hi'] total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) โžž ['hi', 'admin'] total_match(['hi', 'admin'], ['hI', 'h...
def total_match(lst1, lst2): l1 = 0 for st in lst1: l1 += len(st) l2 = 0 for st in lst2: l2 += len(st) if l1 <= l2: return lst1 else: return lst2
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([], []) == [] assert candidate(['hi', 'admin'], ['hi', 'hi']) == ['hi', 'hi'] assert candidate(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) == ['hi', 'admin...
total_match
bt_JHumanEval/75
ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ฐใŒ3ใคใฎ็ด ๆ•ฐใฎๆŽ›ใ‘็ฎ—ใงใ‚ใ‚ŒใฐTrueใ‚’ใ€ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™ ้–ขๆ•ฐใ‚’ๆ›ธใใชใ•ใ„ใ€‚ ๅผ•ๆ•ฐ aใฏ100ไปฅไธ‹ใ‚’ๆ—ข็Ÿฅใจใ—ใฆใ„ใ‚ˆใ„ใ€‚ ไพ‹: is_multiply_prime(30) == True 30 = 2 * 3 * 5
def is_multiply_prime(a): def is_prime(n): for j in range(2,n): if n%j == 0: return False return True for i in range(2,101): if not is_prime(i): continue for j in range(2,101): if not is_prime(j): continue for k in range(2,101)...
def check(candidate): assert candidate(5) == False assert candidate(30) == True assert candidate(8) == True assert candidate(10) == False assert candidate(125) == True assert candidate(3 * 5 * 7) == True assert candidate(3 * 6 * 7) == False assert candidate(9 * 9 * 9) == False asser...
is_multiply_prime
bt_JHumanEval/76
ใ‚ใชใŸใฎใ‚ฟใ‚นใ‚ฏใฏใ€ใ‚ใ‚‹ๆ•ฐxใŒnใฎๅ˜็ด”ใชในใไน—ใงใ‚ใ‚‹ๅ ดๅˆใซtrueใ‚’ใ€ ใใ‚Œไปฅๅค–ใฎๅ ดๅˆใซfalseใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใใ“ใจใงใ‚ใ‚‹ใ€‚ xใฏใ€n**int=xใฎใจใใ€nใฎๅ˜็ด”ใชในใไน—ใงใ‚ใ‚‹ใ€‚ ไพ‹ใˆใฐ: is_simple_power(1, 4) => true is_simple_power(2, 2) => true is_simple_power(8, 2) => true is_simple_power(3, 2) => false is_simple_power(3, 1) => false is_simple_power(5, 3) => false
def is_simple_power(x, n): if (n == 1): return (x == 1) power = 1 while (power < x): power = power * n return (power == x)
def check(candidate): # Check some simple cases assert candidate(16, 2)== True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(143214, 16)== False, "This prints if this assert fails 1 (good for debugging!)" assert candidate(4, 2)==True, "This prints if this assert fails 1 (...
is_simple_power
bt_JHumanEval/77
ๆ•ดๆ•ฐaใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ใ“ใฎๆ•ดๆ•ฐใŒใ‚ใ‚‹ๆ•ดๆ•ฐใฎ3ไน—ใงใ‚ใ‚‹ๅ ดๅˆใซTrue ใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใใชใ•ใ„ใ€‚ ๆณจๆ„๏ผšๅ…ฅๅŠ›ใฏๅธธใซๅ‡ฆ็†ๅฏ่ƒฝใงใ‚ใ‚‹ใจไปฎๅฎšใ—ใฆใ‚ˆใ„ใ€‚ ไพ‹: iscube(1) ==> True iscube(2) ==> False iscube(-1) ==> True iscube(64) ==> True iscube(0) ==> True iscube(180) ==> False
def iscube(a): a = abs(a) return int(round(a ** (1. / 3))) ** 3 == a
def check(candidate): # Check some simple cases assert candidate(1) == True, "First test error: " + str(candidate(1)) assert candidate(2) == False, "Second test error: " + str(candidate(2)) assert candidate(-1) == True, "Third test error: " + str(candidate(-1)) assert candidate(64) == True, "Fourth...
iscube
bt_JHumanEval/78
16้€ฒๆ•ฐใฎๆ•ฐๅญ—ใ‚’ๆ–‡ๅญ—ๅˆ—ใจใ—ใฆๅ—ใ‘ๅ–ใ‚Šใ€ใใฎไธญใซๅซใพใ‚Œใ‚‹็ด ๆ•ฐใงใ‚ใ‚‹16้€ฒๆ•ฐใฎๆกๆ•ฐใ‚’ ใ‚ซใ‚ฆใƒณใƒˆใ™ใ‚‹้–ขๆ•ฐใ‚’ไฝœๆˆใ™ใ‚‹ใ‚ฟใ‚นใ‚ฏใŒไธŽใˆใ‚‰ใ‚Œใพใ—ใŸใ€‚็ด ๆ•ฐใจใฏใ€1ใ‚ˆใ‚Šๅคงใใใ€ 2ใคใฎใ‚ˆใ‚Šๅฐใ•ใ„่‡ช็„ถๆ•ฐใฎ็ฉใงใชใ„่‡ช็„ถๆ•ฐใงใ™ใ€‚ 16้€ฒๆ•ฐใฎๆกใซใฏ0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, FใŒใ‚ใ‚Šใพใ™ใ€‚ ็ด ๆ•ฐใจใ—ใฆใฏ2, 3, 5, 7, 11, 13, 17,...ใŒใ‚ใ‚Šใพใ™ใ€‚ ใ—ใŸใŒใฃใฆใ€ๆฌกใฎๆ•ฐๅญ—ใฎใ„ใšใ‚Œใ‹ใŒใ„ใใคใ‚ใ‚‹ใ‹ใ‚’ๅˆคๅฎšใ™ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™๏ผš 2, 3, 5, 7, B๏ผˆ=10้€ฒๆ•ฐใง11๏ผ‰, D๏ผˆ=10้€ฒๆ•ฐใง13๏ผ‰ ๆณจๆ„๏ผšๅ…ฅๅŠ›ใฏๅธธใซๆญฃ็ขบใ€ใพใŸใฏ็ฉบ...
def hex_key(num): primes = ('2', '3', '5', '7', 'B', 'D') total = 0 for i in range(0, len(num)): if num[i] in primes: total += 1 return total
def check(candidate): # Check some simple cases assert candidate("AB") == 1, "First test error: " + str(candidate("AB")) assert candidate("1077E") == 2, "Second test error: " + str(candidate("1077E")) assert candidate("ABED1A33") == 4, "Third test error: " + str(candidate("ABED1A33")) ...
hex_key
bt_JHumanEval/79
10้€ฒๆ•ฐๅฝขๅผใฎๆ•ฐๅ€คใŒไธŽใˆใ‚‰ใ‚Œใ€ใ‚ใชใŸใฎใ‚ฟใ‚นใ‚ฏใฏใใ‚Œใ‚’2้€ฒๆ•ฐๅฝขๅผใซๅค‰ๆ›ใ™ใ‚‹ใ“ใจใงใ‚ใ‚‹ใ€‚ ใ“ใฎ้–ขๆ•ฐใฏใ€ๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ—ใ€ใใฎๅ„ๆ–‡ๅญ—ใฏ2้€ฒๆ•ฐใ‚’่กจใ™ใ€‚ๆ–‡ๅญ—ๅˆ—ใฎๅ„ๆ–‡ๅญ—ใฏ'0'ใ‹'1'ใงใ‚ใ‚‹ใ€‚ ใชใŠใ€ๆ–‡ๅญ—ๅˆ—ใฎๆœ€ๅˆใจๆœ€ๅพŒใซใฏ'db'ใจใ„ใ†ไฝ™ๅˆ†ใชๆ–‡ๅญ—ใ‚’ใคใ‘ใ‚‹ใ€‚ ใ“ใฎๆ–‡ๅญ—ใฏๆ›ธๅผใ‚’ๅŠฉใ‘ใ‚‹ใŸใ‚ใซใ‚ใ‚‹ใ€‚ ไพ‹: decimal_to_binary(15) # "db1111db"ใ‚’่ฟ”ใ™ decimal_to_binary(32) # "db100000db"ใ‚’่ฟ”ใ™
def decimal_to_binary(decimal): return "db" + bin(decimal)[2:] + "db"
def check(candidate): # Check some simple cases assert candidate(0) == "db0db" assert candidate(32) == "db100000db" assert candidate(103) == "db1100111db" assert candidate(15) == "db1111db", "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to wor...
decimal_to_binary
bt_JHumanEval/80
ใ‚ใชใŸใฏๆ–‡ๅญ—ๅˆ—sใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใ€‚ ใ‚ใชใŸใฎใ‚ฟใ‚นใ‚ฏใฏใ€ใใฎๆ–‡ๅญ—ๅˆ—ใŒๅนธใ›ใ‹ใฉใ†ใ‹ใ‚’ใƒใ‚งใƒƒใ‚ฏใ™ใ‚‹ใ“ใจใงใ‚ใ‚‹ใ€‚ ๆ–‡ๅญ—ๅˆ—ใฏๅนธใ›ใจใฏใ€ๆ–‡ๅญ—ๅˆ—ใฎ้•ทใ•ใŒๅฐ‘ใชใใจใ‚‚3ไปฅไธŠใงใ€้€ฃ็ถšใ™ใ‚‹3ๆ–‡ๅญ—ใŒใ™ในใฆ็•ฐใชใ‚‹ๅ ดๅˆใงใ‚ใ‚‹ใ€‚ ไพ‹ใˆใฐ: is_happy(a) => False is_happy(aa) => False is_happy(abcd) => True is_happy(aabb) => False is_happy(adb) => True is_happy(xyy) => False
def is_happy(s): if len(s) < 3: return False for i in range(len(s) - 2): if s[i] == s[i+1] or s[i+1] == s[i+2] or s[i] == s[i+2]: return False return True
def check(candidate): # Check some simple cases assert candidate("a") == False , "a" assert candidate("aa") == False , "aa" assert candidate("abcd") == True , "abcd" assert candidate("aabb") == False , "aabb" assert candidate("adb") == True , "adb" assert candidate("xyy") == False , "xyy" ...
is_happy
bt_JHumanEval/81
ๅญฆๆœŸๆœ€็ต‚้€ฑใ€ๆ•™ๅธซใฏ็”Ÿๅพ’ใซๆˆ็ธพใ‚’ใคใ‘ใชใ‘ใ‚Œใฐใชใ‚‰ใชใ„ใ€‚ๆ•™ๅธซใฏ็‹ฌ่‡ชใฎใ‚ขใƒซใ‚ดใƒชใ‚บใƒ ใงๆŽก็‚นใ—ใฆใ„ใ‚‹ใ€‚ ๅ•้กŒใฏใ€ๅฝผๅฅณใŒๆˆ็ธพ่ฉ•ไพกใซไฝฟใฃใŸใ‚ณใƒผใƒ‰ใ‚’็ด›ๅคฑใ—ใฆใ—ใพใฃใŸใ“ใจใงใ™ใ€‚ ๅฝผๅฅณใฏไฝ•ไบบใ‹ใฎ็”Ÿๅพ’ใฎGPAใฎใƒชใ‚นใƒˆใ‚’ใ‚ใชใŸใซๆธกใ—ใŸใฎใงใ€ใ‚ใชใŸใฏๆฌกใฎ่กจใ‚’ไฝฟใฃใฆ่ฉ•็‚นใฎใƒชใ‚นใƒˆใ‚’ ๅ‡บๅŠ›ใงใใ‚‹้–ขๆ•ฐใ‚’ๆ›ธใใ“ใจใซใชใ‚Šใพใ—ใŸใ€‚ GPA | ่ฉ•็‚น 4.0 A+ > 3.7 A > 3.3 A- > 3.0 ...
def numerical_letter_grade(grades): letter_grade = [] for gpa in grades: if gpa == 4.0: letter_grade.append("A+") elif gpa > 3.7: letter_grade.append("A") elif gpa > 3.3: letter_grade.append("A-") elif gpa > 3.0: letter_grade.a...
def check(candidate): # Check some simple cases assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-'] assert candidate([1.2]) == ['D+'] assert candidate([0.5]) == ['D-'] assert candidate([0.0]) == ['E'] assert candidate([1, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+'] ...
numerical_letter_grade
bt_JHumanEval/82
ๆ–‡ๅญ—ๅˆ—ใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ๆ–‡ๅญ—ๅˆ—ใฎ้•ทใ•ใŒ็ด ๆ•ฐใงใ‚ใ‚ŒใฐTrueใ‚’ใ€ใใ†ใงใชใ‘ใ‚ŒใฐFalseใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๆ›ธใใ€‚ ไพ‹ prime_length('Hello') == True prime_length('abcdcba') == True prime_length('kittens') == True prime_length('orange') == False
def prime_length(string): l = len(string) if l == 0 or l == 1: return False for i in range(2, l): if l % i == 0: return False return True
def check(candidate): # Check some simple cases assert candidate('Hello') == True assert candidate('abcdcba') == True assert candidate('kittens') == True assert candidate('orange') == False assert candidate('wow') == True assert candidate('world') == True assert candidate('MadaM') == Tr...
prime_length
bt_JHumanEval/83
ๆญฃใฎๆ•ดๆ•ฐ n ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€n ๆกใฎๆญฃใฎๆ•ดๆ•ฐใง 1 ใงๅง‹ใพใ‚‹ใ‹ ใ‚‚ใ—ใใฏ็ต‚ใ‚ใ‚‹ๆ•ฐใฎใ‚ซใ‚ฆใƒณใƒˆใ‚’่ฟ”ใ™
def starts_one_ends(n): if n == 1: return 1 return 18 * (10 ** (n - 2))
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1) == 1 assert candidate(2) == 18 assert candidate(3) == 180 assert candidate(4) == 1800 assert candidate(5) == 18000 # Check some edge cases that ar...
starts_one_ends
bt_JHumanEval/84
ๆญฃใฎๆ•ดๆ•ฐ N ใŒไธŽใˆใ‚‰ใ‚ŒใŸๆ™‚ใ€ใใฎๆกใฎ็ทๅ’Œใ‚’2้€ฒๆ•ฐใง่ฟ”ใ™ใ€‚ ไพ‹ N = 1000ใฎใจใ, ๅ„ๆกใฎ็ทๅ’Œใฏ1ใ€ใ ใ‹ใ‚‰่ฟ”ใ‚Šๅ€คใฏ "1". N = 150ใฎใจใ,ๅ„ๆกใฎ็ทๅ’Œใฏ6ใ€ ใ ใ‹ใ‚‰่ฟ”ใ‚Šๅ€คใฏ "110". N = 147ใฎใจใ,ๅ„ๆกใฎ็ทๅ’Œใฏ12ใ€ ใ ใ‹ใ‚‰่ฟ”ใ‚Šๅ€คใฏ "1100". ๅค‰ๆ•ฐ: @N ๆ•ดๆ•ฐ ๅˆถ็ด„: 0 โ‰ค N โ‰ค 10000. ่ฟ”ใ‚Šๅ€ค: ๏ผ’้€ฒๆ•ฐ่กจ่จ˜ใฎๆ–‡ๅญ—ๅˆ—
def solve(N): return bin(sum(int(i) for i in str(N)))[2:]
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1000) == "1", "Error" assert candidate(150) == "110", "Error" assert candidate(147) == "1100", "Error" # Check some edge cases that are easy to work out by h...
solve
bt_JHumanEval/85
็ฉบใงใชใ„ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆlstใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ๅฅ‡ๆ•ฐใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใซใ‚ใ‚‹ๅถๆ•ฐใฎ่ฆ็ด ใ‚’ๅŠ ใˆใ‚‹ใ€‚ ไพ‹: add([4, 2, 6, 7]) ==> 2
def add(lst): return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0])
def check(candidate): # Check some simple cases assert candidate([4, 88]) == 88 assert candidate([4, 5, 6, 7, 2, 122]) == 122 assert candidate([4, 0, 6, 7]) == 0 assert candidate([4, 4, 6, 8]) == 12 # Check some edge cases that are easy to work out by hand. candidate = add check(candidat...
add
bt_JHumanEval/86
ๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใจใ—ใฆๅ—ใ‘ๅ–ใ‚Šใ€ใใฎใ€Œ้ †ๅบไป˜ใ‘ใ‚‰ใ‚ŒใŸใƒใƒผใ‚ธใƒงใƒณใ€ใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ไฝœๆˆใ—ใฆใใ ใ•ใ„ใ€‚ ้ †ๅบไป˜ใ‘ใ‚‰ใ‚ŒใŸใƒใƒผใ‚ธใƒงใƒณใจใฏใ€ๅ„ๅ˜่ชž๏ผˆ็ฉบ็™ฝใงๅŒบๅˆ‡ใ‚‰ใ‚ŒใŸ๏ผ‰ใฎๆ–‡ๅญ—ใŒASCIIๅ€คใซๅŸบใฅใ„ใฆๆ˜‡้ †ใซ ไธฆในๆ›ฟใˆใ‚‰ใ‚ŒใŸๆ–ฐใ—ใ„ๅ˜่ชžใซ็ฝฎใๆ›ใˆใ‚‰ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใงใ™ใ€‚ ๆณจๆ„๏ผšๆ–‡็ซ ๅ†…ใฎๅ˜่ชžใจ็ฉบ็™ฝใฎ้ †ๅบใฏใใฎใพใพไฟใฃใฆใใ ใ•ใ„ใ€‚ ไพ‹ใˆใฐ๏ผš anti_shuffle('Hi') ใฏ 'Hi'ใ‚’่ฟ”ใ™ anti_shuffle('hello') ใฏ 'ehllo'่ฟ”ใ™ anti_shuffle('Hello World!!!') ใฏ 'Hello !!!Wdlor'่ฟ”ใ™
def anti_shuffle(s): return ' '.join([''.join(sorted(list(i))) for i in s.split(' ')])
def check(candidate): # Check some simple cases assert candidate('Hi') == 'Hi' assert candidate('hello') == 'ehllo' assert candidate('number') == 'bemnru' assert candidate('abcd') == 'abcd' assert candidate('Hello World!!!') == 'Hello !!!Wdlor' assert candidate('') == '' assert candidat...
anti_shuffle
bt_JHumanEval/87
2ๆฌกๅ…ƒใฎใƒ‡ใƒผใ‚ฟใŒใƒใ‚นใƒˆใ•ใ‚ŒใŸใƒชใ‚นใƒˆใจใ—ใฆไธŽใˆใ‚‰ใ‚Œใ‚‹ใ€‚ใ“ใ‚Œใฏ่กŒๅˆ—ใซไผผใฆใ„ใ‚‹ใŒใ€ ่กŒๅˆ—ใจใฏ็•ฐใชใ‚Šใ€ๅ„่กŒใฏ็•ฐใชใ‚‹ๆ•ฐใฎๅˆ—ใ‚’ๅซใ‚€ใ“ใจใŒใงใใ‚‹ใ€‚ lstใจๆ•ดๆ•ฐxใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ใƒชใ‚นใƒˆๅ†…ใฎๆ•ดๆ•ฐxใ‚’่ฆ‹ใคใ‘ใ€ๅ„ใ‚ฟใƒ—ใƒซใŒ0ใ‹ใ‚‰ๅง‹ใพใ‚‹ ๅบงๆจ™๏ผˆ่กŒใ€ๅˆ—๏ผ‰ใงใ‚ใ‚‹ใ‚ˆใ†ใชใ‚ฟใƒ—ใƒซใฎใƒชใ‚นใƒˆ[(x1, y1), (x2, y2) ...]ใ‚’่ฟ”ใ™ใ€‚ ๅบงๆจ™ใ‚’ๆœ€ๅˆใฏ่กŒใฎๆ˜‡้ †ใงใ‚ฝใƒผใƒˆใ™ใ‚‹ใ€‚ ใพใŸใ€่กŒใฎๅบงๆจ™ใ‚’ๅˆ—ใฎ้™้ †ใงใ‚ฝใƒผใƒˆใ™ใ‚‹ใ€‚ ไพ‹: get_row([ [1,2,3,4,5,6], [1,2,3,4,1,6], [1,2,3,4,5,1] ], 1) == [(0, ...
def get_row(lst, x): coords = [(i, j) for i in range(len(lst)) for j in range(len(lst[i])) if lst[i][j] == x] return sorted(sorted(coords, key=lambda x: x[1], reverse=True), key=lambda x: x[0])
def check(candidate): # Check some simple cases assert candidate([ [1,2,3,4,5,6], [1,2,3,4,1,6], [1,2,3,4,5,1] ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)] assert candidate([ [1,2,3,4,5,6], [1,2,3,4,5,6], [1,2,3,4,5,6], [1,2,3,4,5,6], ...
get_row
bt_JHumanEval/88
้ž่ฒ ใฎๆ•ดๆ•ฐใ‹ใ‚‰ใชใ‚‹้…ๅˆ—ใŒไธŽใˆใ‚‰ใ‚ŒใŸๅ ดๅˆใ€้…ๅˆ—ใ‚’ใ‚ฝใƒผใƒˆใ—ใŸใ‚ณใƒ”ใƒผใ‚’่ฟ”ใ—ใฆใใ ใ•ใ„ใ€‚ ้…ๅˆ—ใฎๆœ€ๅˆใฎ่ฆ็ด ใจๆœ€ๅพŒใฎ่ฆ็ด ใฎๅ’ŒใŒๅฅ‡ๆ•ฐใงใ‚ใ‚Œใฐใ€้…ๅˆ—ใ‚’ๆ˜‡้ †๏ผˆๅฐใ•ใ„้ †๏ผ‰ใซใ‚ฝใƒผใƒˆใ—ใพใ™ใ€‚ ใใฎๅ’ŒใŒๅถๆ•ฐใงใ‚ใ‚Œใฐใ€้…ๅˆ—ใ‚’้™้ †๏ผˆๅคงใใ„้ †๏ผ‰ใซใ‚ฝใƒผใƒˆใ—ใพใ™ใ€‚ ๆณจๆ„็‚น๏ผš * ไธŽใˆใ‚‰ใ‚ŒใŸ้…ๅˆ—่‡ชไฝ“ใ‚’ๅค‰ๆ›ดใ—ใชใ„ใงใใ ใ•ใ„ใ€‚ ไพ‹: * sort_array([]) => [] * sort_array([5]) => [5] * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5] * sort_array([2, 4, 3, 0, 1, 5, ...
def sort_array(array): return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([]) == [], "Error" assert candidate([5]) == [5], "Error" assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5], "Error" assert candidate([2, 4, 3, 0, 1, ...
sort_array
bt_JHumanEval/89
ๆ–‡ๅญ—ๅˆ—ใ‚’ๅผ•ๆ•ฐใซใจใ‚Šใ€ใ‚ขใƒซใƒ•ใ‚กใƒ™ใƒƒใƒˆใ‚’ๅ›ž่ปขใ•ใ›ใฆๆš—ๅทๅŒ–ใ—ใŸ ๆ–‡ๅญ—ๅˆ—ใ‚’่ฟ”ใ™้–ขๆ•ฐencryptใ‚’ไฝœๆˆใ›ใ‚ˆใ€‚ ใ‚ขใƒซใƒ•ใ‚กใƒ™ใƒƒใƒˆใฏใ€ๆ–‡ๅญ—ไฝ็ฝฎใ‚’2ๅ€ใ—ใฆ2ใคไธ‹ใซใ‚ทใƒ•ใƒˆใ™ใ‚‹ใ‚ˆใ†ใซ ๅ›ž่ปขใ™ใ‚‹ใ€‚ ไพ‹: encrypt('hi') returns 'lm' encrypt('asdfghjkl') returns 'ewhjklnop' encrypt('gf') returns 'kj' encrypt('et') returns 'ix'
def encrypt(s): d = 'abcdefghijklmnopqrstuvwxyz' out = '' for c in s: if c in d: out += d[(d.index(c)+2*2) % 26] else: out += c return out
def check(candidate): # Check some simple cases assert candidate('hi') == 'lm', "This prints if this assert fails 1 (good for debugging!)" assert candidate('asdfghjkl') == 'ewhjklnop', "This prints if this assert fails 1 (good for debugging!)" assert candidate('gf') == 'kj', "This prints if this assert...
encrypt
bt_JHumanEval/90
ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใ€‚ ใƒชใ‚นใƒˆใฎ2็•ช็›ฎใซๅฐใ•ใ„่ฆ็ด ใ‚’่ฟ”ใ™้–ขๆ•ฐ next_smallest() ใ‚’ๆ›ธใใชใ•ใ„ใ€‚ ใใฎใ‚ˆใ†ใช่ฆ็ด ใŒใชใ„ๅ ดๅˆใฏ None ใ‚’่ฟ”ใ™ใ€‚ next_smallest([1, 2, 3, 4, 5]) == 2 next_smallest([5, 1, 4, 3, 2]) == 2 next_smallest([]) == None next_smallest([1, 1]) == None
def next_smallest(lst): lst = sorted(set(lst)) return None if len(lst) < 2 else lst[1]
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4, 5]) == 2 assert candidate([5, 1, 4, 3, 2]) == 2 assert candidate([]) == None assert candidate([1, 1]) == None assert candidate([1,1,1,1,0]) == 1 assert candidate([1, 0**0]) == None assert candidate([-35, 34, 1...
next_smallest
bt_JHumanEval/91
ๅ˜่ชžใฎๆ–‡ๅญ—ๅˆ—ใŒไธŽใˆใ‚‰ใ‚Œใ€ใ‚ใชใŸใฎใ‚ฟใ‚นใ‚ฏใฏ้€€ๅฑˆๆŒ‡ๆ•ฐใ‚’ๆ•ฐใˆใ‚‹ ใ“ใจใงใ‚ใ‚‹ใ€‚้€€ๅฑˆๆŒ‡ๆ•ฐใจใฏใ€"I "ใงๅง‹ใพใ‚‹ๆ–‡ใฎใ“ใจใงใ‚ใ‚‹ใ€‚ ๆ–‡ใฏ'.'ใ€โ€™?โ€™ใ€'!'ใฎใ„ใšใ‚Œใ‹ใงๅŒบๅˆ‡ใ‚‰ใ‚Œใ‚‹ใ€‚ ไพ‹ใˆใฐ: >>> is_bored("Hello world") 0 >>> is_bored("The sky is blue. The sun is shining. I love this weather") 1
def is_bored(S): import re sentences = re.split(r'[.?!]\s*', S) return sum(sentence[0:2] == 'I ' for sentence in sentences)
def check(candidate): # Check some simple cases assert candidate("Hello world") == 0, "Test 1" assert candidate("Is the sky blue?") == 0, "Test 2" assert candidate("I love It !") == 1, "Test 3" assert candidate("bIt") == 0, "Test 4" assert candidate("I feel good today. I will be productive. wil...
is_bored
bt_JHumanEval/92
3ใคใฎๆ•ฐๅ€คใ‚’ๅ—ใ‘ๅ–ใ‚‹้–ขๆ•ฐใ‚’ไฝœใ‚‹ใ€‚ 1ใคใฎๆ•ฐๅ€คใŒไป–ใฎ2ใคใฎๆ•ฐๅ€คใฎๅ’Œใจ็ญ‰ใ—ใใ€ใ™ในใฆใฎๆ•ฐๅ€คใŒๆ•ดๆ•ฐใงใ‚ใ‚‹ๅ ดๅˆใซTrueใ‚’่ฟ”ใ™ใ€‚ ใใ‚Œไปฅๅค–ใฎๅ ดๅˆใฏFalseใ‚’่ฟ”ใ™ใ€‚ ไพ‹ any_int(5, 2, 7) โžž True any_int(3, 2, 2) โžž False any_int(3, -2, 1) โžž True any_int(3.6, -2.2, 2) โžž False
def any_int(x, y, z): if isinstance(x,int) and isinstance(y,int) and isinstance(z,int): if (x+y==z) or (x+z==y) or (y+z==x): return True return False return False
def check(candidate): # Check some simple cases assert candidate(2, 3, 1)==True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(2.5, 2, 3)==False, "This prints if this assert fails 2 (good for debugging!)" assert candidate(1.5, 5, 3.5)==False, "This prints if this assert fa...
any_int
bt_JHumanEval/93
ใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ใ™ในใฆใฎๆ–‡ๅญ—ใฎๅคงๆ–‡ๅญ—ใจๅฐๆ–‡ๅญ—ใ‚’ๅ…ฅใ‚Œๆ›ฟใˆใ€ ใƒกใƒƒใ‚ปใƒผใ‚ธไธญใฎใ™ในใฆใฎๆฏ้Ÿณใ‚’่‹ฑ่ชžใฎๆฏ้Ÿณใฎ2ใคๅ‰ใซ็พใ‚Œใ‚‹ๆ–‡ๅญ—ใซ็ฝฎ ใๆ›ใˆใ‚‹ใ‚ˆใ†ใซใ‚จใƒณใ‚ณใƒผใƒ‰ใ™ใ‚‹้–ขๆ•ฐใ‚’ๆ›ธใใชใ•ใ„ใ€‚ ๆ–‡ๅญ—ใ ใ‘ใ‚’ๆƒณๅฎšใ™ใ‚‹ใ€‚ ไพ‹ >>> encode('test') 'TGST' >>> encode('This is a message') 'tHKS KS C MGSSCGG'
def encode(message): vowels = "aeiouAEIOU" vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels]) message = message.swapcase() return ''.join([vowels_replace[i] if i in vowels else i for i in message])
def check(candidate): # Check some simple cases assert candidate('TEST') == 'tgst', "This prints if this assert fails 1 (good for debugging!)" assert candidate('Mudasir') == 'mWDCSKR', "This prints if this assert fails 2 (good for debugging!)" assert candidate('YES') == 'ygs', "This prints if this asse...
encode
bt_JHumanEval/94
ๆ•ดๆ•ฐใฎใƒชใ‚นใƒˆใŒไธŽใˆใ‚‰ใ‚‹ใ€‚ ๆœ€ๅคงใฎ็ด ๆ•ฐใ‚’ๆฑ‚ใ‚ใ€ใใฎๆกๆ•ฐใฎๅ’Œใ‚’่ฟ”ใ™ๅฟ…่ฆใŒใ‚ใ‚‹ใ€‚ ไพ‹: lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] ใฎใจใใ€่ฟ”ใ‚Šๅ€คใฏ10 lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1]ใฎใจใใ€่ฟ”ใ‚Šๅ€คใฏ 25 lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3]ใฎใจใใ€่ฟ”ใ‚Šๅ€คใฏ13 lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6]ใฎใจใใ€่ฟ”ใ‚Šๅ€คใฏ11 ...
def skjkasdkd(lst): def isPrime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True maxx = 0 i = 0 while i < len(lst): if(lst[i] > maxx and isPrime(lst[i])): maxx = lst[i] i+=1 result = sum(int(digit) for d...
def check(candidate): # Check some simple cases assert candidate([0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3]) == 10, "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate([1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1]...
skjkasdkd
bt_JHumanEval/95
่พžๆ›ธใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ใ™ในใฆใฎใ‚ญใƒผใŒๅฐๆ–‡ๅญ—ใงใ‚ใ‚ŒใฐTrueใ‚’ใ€ ใ™ในใฆใฎใ‚ญใƒผใŒๅคงๆ–‡ๅญ—ใฎๆ–‡ๅญ—ๅˆ—ใงใ‚ใ‚ŒใฐFalseใ‚’่ฟ”ใ™ใ€‚ ไธŽใˆใ‚‰ใ‚ŒใŸ่พžๆ›ธใŒ็ฉบใฎๅ ดๅˆใ€ใ“ใฎ้–ขๆ•ฐใฏ False ใ‚’่ฟ”ใ™ใ€‚ ไพ‹: check_dict_case({"a":"apple", "b":"banana"}) ใฏใ€ Trueใ‚’่ฟ”ใ™ใ€‚ check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) ใฏใ€ Falseใ‚’่ฟ”ใ™ใ€‚ check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) ใฏใ€ Falseใ‚’่ฟ”ใ™ใ€‚ ...
def check_dict_case(dict): if len(dict.keys()) == 0: return False else: state = "start" for key in dict.keys(): if isinstance(key, str) == False: state = "mixed" break if state == "start": if key.isupper(): ...
def check(candidate): # Check some simple cases assert candidate({"p":"pineapple", "b":"banana"}) == True, "First test error: " + str(candidate({"p":"pineapple", "b":"banana"})) assert candidate({"p":"pineapple", "A":"banana", "B":"banana"}) == False, "Second test error: " + str(candidate({"p":"pineapple",...
check_dict_case
bt_JHumanEval/96
้ž่ฒ ๆ•ดๆ•ฐใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€็ด ๆ•ฐใงnใ‚ˆใ‚Šๅฐใ•ใ„ๆœ€ๅˆใฎnๅ€‹ใฎ ๆ•ดๆ•ฐใฎ้…ๅˆ—ใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๅฎŸ่ฃ…ใ›ใ‚ˆใ€‚ ไพ‹ใˆใฐ: count_up_to(5) => [2,3] count_up_to(11) => [2,3,5,7] count_up_to(0) => [] count_up_to(20) => [2,3,5,7,11,13,17,19] count_up_to(1) => [] count_up_to(18) => [2,3,5,7,11,13,17]
def count_up_to(n): primes = [] for i in range(2, n): is_prime = True for j in range(2, i): if i % j == 0: is_prime = False break if is_prime: primes.append(i) return primes
def check(candidate): assert candidate(5) == [2,3] assert candidate(6) == [2,3,5] assert candidate(7) == [2,3,5] assert candidate(10) == [2,3,5,7] assert candidate(0) == [] assert candidate(22) == [2,3,5,7,11,13,17,19] assert candidate(1) == [] assert candidate(18) == [2,3,5,7,11,13,17]...
count_up_to
bt_JHumanEval/97
2ใคใฎๆ•ดๆ•ฐใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ใใฎ๏ผ‘ใฎไฝใฎๆ•ฐใฎ็ฉใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ๅฎŒๆˆใ•ใ›ใ‚ˆใ€‚ ๅ…ฅๅŠ›ใฏๅธธใซๆœ‰ๅŠน็ฏ„ๅ›ฒใซใ‚ใ‚‹ใจใ™ใ‚‹ใ€‚ ไพ‹: multiply(148, 412) ใฏ16ใ‚’่ฟ”ใ™ใ€‚ multiply(19, 28) ใฏ72ใ‚’่ฟ”ใ™ใ€‚ multiply(2020, 1851) ใฏ0ใ‚’่ฟ”ใ™ใ€‚ multiply(14,-15) ใฏ20ใ‚’่ฟ”ใ™ใ€‚
def multiply(a, b): return abs(a % 10) * abs(b % 10)
def check(candidate): # Check some simple cases assert candidate(148, 412) == 16, "First test error: " + str(candidate(148, 412)) assert candidate(19, 28) == 72, "Second test error: " + str(candidate(19, 28)) assert candidate(2020, 1851) == 0, "Third test error: " + str(c...
multiply
bt_JHumanEval/98
ๆ–‡ๅญ—ๅˆ— s ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ๅถๆ•ฐใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚นใซๅซใพใ‚Œใ‚‹ๅคงๆ–‡ๅญ—ใฎๆฏ้Ÿณใฎๆ•ฐใ‚’ๆ•ฐใˆใ‚‹ใ€‚ ไพ‹ใˆใฐ: count_upper('aBCdEf') returns 1 count_upper('abcdefg') returns 0 count_upper('dBBE') returns 0
def count_upper(s): count = 0 for i in range(0,len(s),2): if s[i] in "AEIOU": count += 1 return count
def check(candidate): # Check some simple cases assert candidate('aBCdEf') == 1 assert candidate('abcdefg') == 0 assert candidate('dBBE') == 0 assert candidate('B') == 0 assert candidate('U') == 1 assert candidate('') == 0 assert candidate('EEEE') == 2 # Check some edge cases th...
count_upper
bt_JHumanEval/99
ๆ•ฐๅ€คใ‚’่กจใ™ๆ–‡ๅญ—ๅˆ—valueใ‚’ๅ—ใ‘ๅ–ใ‚Šใ€ใใ‚Œใซๆœ€ใ‚‚่ฟ‘ใ„ๆ•ดๆ•ฐใ‚’่ฟ”ใ™้–ขๆ•ฐใ‚’ไฝœใ‚‹ใ€‚ ใใฎๆ•ฐๅ€คใŒ2ใคใฎๆ•ดๆ•ฐใ‹ใ‚‰็ญ‰่ท้›ขใซใ‚ใ‚‹ๅ ดๅˆใฏใ€ใ‚ผใƒญใ‹ใ‚‰ๅ››ๆจไบ”ๅ…ฅใ™ใ‚‹ใ€‚ ไพ‹ >>> closest_integer("10") 10 >>> closest_integer("15.3") 15 Note: ใ‚ผใƒญใ‹ใ‚‰ใฎๅ››ๆจไบ”ๅ…ฅใจใฏใ€ไธŽใˆใ‚‰ใ‚ŒใŸๆ•ฐๅ€คใŒ2ใคใฎๆ•ดๆ•ฐใ‹ใ‚‰ ็ญ‰่ท้›ขใซใ‚ใ‚‹ๅ ดๅˆใ€ใ‚ผใƒญใ‹ใ‚‰้ ใ„ๆ–นใ‚’่ฟ”ใ™ใจใ„ใ†ๆ„ๅ‘ณใงใ‚ใ‚‹ใ€‚ ไพ‹ใˆใฐใ€ close_integer("14.5")ใฏ15ใ‚’่ฟ”ใ—ใ€closest_integer("-14.5")ใฏ-15ใ‚’่ฟ”ใ™ใ€‚
def closest_integer(value): from math import floor, ceil if value.count('.') == 1: # remove trailing zeros while (value[-1] == '0'): value = value[:-1] num = float(value) if value[-2:] == '.5': if num > 0: res = ceil(num) else: res = ...
def check(candidate): # Check some simple cases assert candidate("10") == 10, "Test 1" assert candidate("14.5") == 15, "Test 2" assert candidate("-15.5") == -16, "Test 3" assert candidate("15.3") == 15, "Test 3" # Check some edge cases that are easy to work out by hand. assert candidate("0...
closest_integer
End of preview. Expand in Data Studio

Dataset Card for bt_jhumaneval

How to use

from datasets import load_dataset
dataset = load_dataset("kogi-jwu/bt_jhumaneval")
Downloads last month
9