task_id stringlengths 11 13 | prompt stringlengths 115 1.11k | canonical_solution stringlengths 16 864 | test stringlengths 117 1.8k | entry_point stringlengths 1 30 |
|---|---|---|---|---|
HumanEval/0 | from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
"""ตรวจสอบว่าในรายการตัวเลขที่กำหนดไว้ มีตัวเลขสองตัวใดที่อยู่ใกล้กันมากกว่าเกณฑ์ที่กำหนดไว้หรือไม่
>>> 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], ... | for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
distance = abs(elem - elem2)
if distance < threshold:
return True
return False
|
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 |
HumanEval/1 | 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
current_string.append(c)
if current_depth == 0:
... |
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == [
'(()())', '((()))', '()', '((())()())'
]
assert candidate('() (()) ((())) (((())))') == [
'()', '(())', '((()))', '(((())))'
]
assert candidate('(()... | separate_paren_groups |
HumanEval/2 |
def truncate_number(number: float) -> float:
"""เมื่อกำหนดจำนวนจุดลอยตัวเป็นบวก ตัวเลขดังกล่าวสามารถแยกออกเป็นส่วนจำนวนเต็ม (จำนวนเต็มที่มากที่สุดที่เล็กกว่าจำนวนที่กำหนด) และทศนิยม (ส่วนที่เหลือจะเล็กกว่า 1 เสมอ) ส่งคืนส่วนทศนิยมของตัวเลข
>>> truncate_number(3.5)
0.5
"""
| 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
| truncate_number |
HumanEval/3 | from typing import List
def below_zero(operations: List[int]) -> bool:
"""คุณจะได้รับรายการการฝากและถอนเงินในบัญชีธนาคารที่เริ่มต้นด้วยยอดเงินคงเหลือเป็นศูนย์ งานของคุณคือตรวจจับว่าเมื่อใดยอดเงินคงเหลือในบัญชีจะลดลงต่ำกว่าศูนย์ และเมื่อถึงจุดนั้น ฟังก์ชันควรส่งคืนค่า True มิฉะนั้น ฟังก์ชันควรส่งคืนค่า False
>... | 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 |
HumanEval/4 | from typing import List
def mean_absolute_deviation(numbers: List[float]) -> float:
"""สำหรับรายการตัวเลขอินพุตที่กำหนด ให้คำนวณค่าเบี่ยงเบนสัมบูรณ์เฉลี่ยรอบค่าเฉลี่ยของชุดข้อมูลนี้ ค่าเบี่ยงเบนสัมบูรณ์เฉลี่ยคือความแตกต่างสัมบูรณ์เฉลี่ยระหว่างแต่ละองค์ประกอบและจุดศูนย์กลาง (ค่าเฉลี่ยในกรณีนี้): MAD = ค่าเฉลี่ย | ... | 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
| mean_absolute_deviation |
HumanEval/5 | from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
"""แทรก 'ตัวแบ่ง' ตัวเลขระหว่างองค์ประกอบ 'ตัวเลข' สององค์ประกอบติดต่อกันของรายการอินพุต
>>> intersperse([], 4)
[]
>>> intersperse([1, 2, 3], 4)
[1, 4, 2, 4, 3]
"""
| 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]
| intersperse |
HumanEval/6 | from typing import List
def parse_nested_parens(paren_string: str) -> List[int]:
"""อินพุตของฟังก์ชันนี้คือสตริงที่แสดงกลุ่มต่างๆ หลายกลุ่มสำหรับวงเล็บซ้อนที่คั่นด้วยช่องว่าง สำหรับแต่ละกลุ่ม ให้แสดงระดับการซ้อนวงเล็บที่ลึกที่สุด ตัวอย่างเช่น (()()) มีระดับการซ้อนสูงสุดสองระดับในขณะที่ ((())) มีสามระดับ
>>> p... | 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
return max_depth
return [parse_paren_group(x) for x in paren_string.s... |
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3]
assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4]
assert candidate('(()(())((())))') == [4]
| parse_nested_parens |
HumanEval/7 | from typing import List
def filter_by_substring(strings: List[str], substring: str) -> List[str]:
"""กรองรายการอินพุตของสตริงเฉพาะที่มีสตริงย่อยที่กำหนดเท่านั้น
>>> filter_by_substring([], 'a')
[]
>>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')
['abc', 'bacd', 'array']
"""
| 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 |
HumanEval/8 | from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
"""สำหรับรายการจำนวนเต็มที่กำหนด ให้ส่งคืนทูเพิลที่ประกอบด้วยผลรวมและผลคูณของจำนวนเต็มทั้งหมดในรายการ ผลรวมว่างควรเท่ากับ 0 และผลคูณว่างควรเท่ากับ 1
>>> sum_product([])
(0, 1)
>>> sum_product([1, 2, 3, 4])
(10, ... | 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)
| sum_product |
HumanEval/9 | from typing import List, Tuple
def rolling_max(numbers: List[int]) -> List[int]:
"""จากรายการจำนวนเต็มที่กำหนดให้ สร้างรายการขององค์ประกอบสูงสุดที่หมุนเวียนที่พบจนถึงช่วงเวลาที่กำหนดในลำดับ
>>> rolling_max([1, 2, 3, 2, 3, 4, 2])
[1, 2, 3, 3, 3, 4, 4]
"""
| 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]
| rolling_max |
HumanEval/10 |
def is_palindrome(string: str) -> bool:
"""ทดสอบว่าสตริงที่กำหนดเป็นพาลินโดรม """
return string == string[::-1]
def make_palindrome(string: str) -> str:
""" Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string th... | if not string:
return ''
beginning_of_suffix = 0
while not is_palindrome(string[beginning_of_suffix:]):
beginning_of_suffix += 1
return string + string[:beginning_of_suffix][::-1]
|
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'
| make_palindrome |
HumanEval/11 | from typing import List
def string_xor(a: str, b: str) -> str:
"""อินพุตเป็นสตริงสองตัวคือ a และ b ที่ประกอบด้วย 1 และ 0 เท่านั้น ดำเนินการ XOR แบบไบนารีกับอินพุตเหล่านี้และส่งคืนผลลัพธ์เป็นสตริงด้วยเช่นกัน
>>> string_xor('010', '110')
'100'
"""
| 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'
| string_xor |
HumanEval/12 | from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
"""จากรายการสตริง ให้ส่งคืนสตริงที่ยาวที่สุด ส่งคืนสตริงแรกในกรณีที่มีสตริงหลายตัวที่มีความยาวเท่ากัน ส่งคืน None ในกรณีที่รายการอินพุตว่างเปล่า
>>> longest([])
>>> longest(['a', 'b', 'c'])
'a'
>>> longest(['a', '... | 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'
| longest |
HumanEval/13 |
def greatest_common_divisor(a: int, b: int) -> int:
"""คืนค่าตัวหารร่วมมากของจำนวนเต็มสองจำนวนคือ a และ b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
| 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
| greatest_common_divisor |
HumanEval/14 | from typing import List
def all_prefixes(string: str) -> List[str]:
"""แสดงรายการคำนำหน้าทั้งหมดตั้งแต่สั้นที่สุดไปจนถึงยาวที่สุดของสตริงอินพุต
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
| 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']
| all_prefixes |
HumanEval/15 |
def string_sequence(n: int) -> str:
"""ส่งคืนสตริงที่มีตัวเลขที่คั่นด้วยช่องว่างตั้งแต่ 0 ถึง n
>>> string_sequence(0)
'0'
>>> string_sequence(5)
'0 1 2 3 4 5'
"""
| 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'
| string_sequence |
HumanEval/16 |
def count_distinct_characters(string: str) -> int:
"""กำหนดสตริง ให้หาว่ามีอักขระที่แตกต่างกันกี่ตัว (โดยไม่คำนึงถึงตัวพิมพ์ใหญ่เล็ก) ที่ประกอบด้วย
>>> count_distinct_characters('xyzXYZ')
3
>>> count_distinct_characters('Jerry')
4
"""
| 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
| count_distinct_characters |
HumanEval/17 | from typing import List
def parse_music(music_string: str) -> List[int]:
"""อินพุตสำหรับฟังก์ชันนี้คือสตริงที่แสดงโน้ตดนตรีในรูปแบบ ASCII พิเศษ งานของคุณคือวิเคราะห์สตริงนี้และส่งคืนรายการจำนวนเต็มที่สอดคล้องกับจำนวนจังหวะที่แต่ละจังหวะไม่คงอยู่ ต่อไปนี้คือคำอธิบาย: 'o' - โน้ตตัวเต็ม ยาวนานสี่จังหวะ 'o|' - โน้ตตั... | 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 |
HumanEval/18 |
def how_many_times(string: str, substring: str) -> int:
"""ค้นหาว่าสามารถพบซับสตริงที่กำหนดได้กี่ครั้งในสตริงต้นฉบับ นับกรณีที่ทับซ้อนกัน
>>> how_many_times('', 'a')
0
>>> how_many_times('aaa', 'a')
3
>>> how_many_times('aaaa', 'aa')
3
"""
| 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
| how_many_times |
HumanEval/19 | from typing import List
def sort_numbers(numbers: str) -> str:
"""อินพุตเป็นสตริงตัวเลขที่คั่นด้วยช่องว่างตั้งแต่ 'ศูนย์' ถึง 'เก้า' ตัวเลือกที่ถูกต้องคือ 'ศูนย์' 'หนึ่ง' 'สอง' 'สาม' 'สี่' 'ห้า' 'หก' 'เจ็ด' 'แปด' และ 'เก้า' ส่งคืนสตริงที่มีตัวเลขเรียงจากน้อยไปมาก
>>> sort_numbers('three one five')
'one th... | 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 numbers.split(' ') if x], key=lambda x: value_map[x]))
|
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 |
HumanEval/20 | from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
"""จากรายการตัวเลขที่จัดทำไว้ (ความยาวอย่างน้อย 2) ให้เลือกตัวเลข 2 ตัวที่อยู่ใกล้กันมากที่สุด แล้วส่งคืนตามลำดับ (ตัวเลขที่น้อยกว่า ตัวเลขที่มากกว่า)
>>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]... | closest_pair = None
distance = None
for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
if distance is None:
distance = abs(elem - elem2)
closest_pair = tuple(sorted([elem, elem2]))
... |
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 |
HumanEval/21 | from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
"""กำหนดรายการตัวเลข (อย่างน้อย 2 องค์ประกอบ) ใช้การแปลงเชิงเส้นกับรายการนั้น โดยที่ตัวเลขที่เล็กที่สุดจะกลายเป็น 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... | 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 |
HumanEval/22 | from typing import List, Any
def filter_integers(values: List[Any]) -> List[int]:
"""กรองรายการค่า Python ที่กำหนดไว้เฉพาะสำหรับจำนวนเต็มเท่านั้น
>>> filter_integers(['a', 3.14, 5])
[5]
>>> filter_integers([1, 2, 3, 'abc', {}, []])
[1, 2, 3]
"""
| 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]
| filter_integers |
HumanEval/23 |
def strlen(string: str) -> int:
"""ส่งคืนความยาวของสตริงที่กำหนด
>>> strlen('')
0
>>> strlen('abc')
3
"""
| return len(string)
|
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('') == 0
assert candidate('x') == 1
assert candidate('asdasnakj') == 9
| strlen |
HumanEval/24 |
def largest_divisor(n: int) -> int:
"""สำหรับจำนวน n ที่กำหนด หาจำนวนที่มากที่สุดที่หาร n ได้ลงตัว ซึ่งมีค่าน้อยกว่า n
>>> largest_divisor(15)
5
"""
| 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
| largest_divisor |
HumanEval/25 | from typing import List
def factorize(n: int) -> List[int]:
"""ส่งคืนรายการปัจจัยเฉพาะของจำนวนเต็มที่กำหนดให้ตามลำดับจากน้อยไปหามาก ปัจจัยแต่ละตัวควรแสดงรายการตามจำนวนครั้งที่ปรากฏในการแยกตัวประกอบ จำนวนอินพุตควรเท่ากับผลคูณของปัจจัยทั้งหมด
>>> factorize(8)
[2, 2, 2]
>>> factorize(25)
[5, 5]
>... | 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 |
HumanEval/26 | from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
"""จากรายการจำนวนเต็ม ให้ลบองค์ประกอบทั้งหมดที่เกิดขึ้นมากกว่าหนึ่งครั้งออก รักษาลำดับขององค์ประกอบให้เหมือนเดิมกับในอินพุต
>>> remove_duplicates([1, 2, 3, 2, 4])
[1, 3, 4]
"""
| 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]
| remove_duplicates |
HumanEval/27 |
def flip_case(string: str) -> str:
"""สำหรับสตริงที่กำหนด ให้เปลี่ยนตัวอักษรตัวพิมพ์เล็กเป็นตัวพิมพ์ใหญ่ และเปลี่ยนตัวอักษรตัวพิมพ์ใหญ่เป็นตัวพิมพ์เล็ก
>>> flip_case('Hello')
'hELLO'
"""
| 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'
| flip_case |
HumanEval/28 | from typing import List
def concatenate(strings: List[str]) -> str:
"""เชื่อมโยงรายการสตริงเข้าเป็นสตริงเดียว
>>> concatenate([])
''
>>> concatenate(['a', 'b', 'c'])
'abc'
"""
| 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'
| concatenate |
HumanEval/29 | from typing import List
def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:
"""กรองรายการอินพุตของสตริงเฉพาะรายการที่เริ่มต้นด้วยคำนำหน้าที่กำหนดเท่านั้น
>>> filter_by_prefix([], 'a')
[]
>>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')
['abc', 'array']
"""
| 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']
| filter_by_prefix |
HumanEval/30 |
def get_positive(l: list):
"""กลับเฉพาะตัวเลขบวกในรายการ
>>> 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]
"""
| 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([]) == []
| get_positive |
HumanEval/31 |
def is_prime(n):
"""คืนค่าเป็นจริงถ้าตัวเลขที่กำหนดเป็นจำนวนเฉพาะ และคืนค่าเท็จถ้าไม่เป็นเช่นนั้น
>>> 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
... | 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 |
HumanEval/32 | import math
def poly(xs: list, x: float):
"""ประเมินพหุนามที่มีค่าสัมประสิทธิ์ xs ที่จุด x ส่งคืน xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n
"""
return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])
def find_zero(xs: list):
""" xs are coefficients of a polynomial.
find_zero ... | 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) / 2.0
if poly(xs, center) * poly(xs, begin) > 0:
begin = center
else:
end = center
return begin
|
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 |
HumanEval/33 |
def sort_third(l: list):
"""ฟังก์ชันนี้ใช้รายการ l และส่งคืนรายการ l' โดยที่ l' จะเหมือนกับ l ในดัชนีที่หารด้วยสามไม่ลงตัว ในขณะที่ค่าของ l ในดัชนีที่หารด้วยสามลงตัวจะเท่ากับค่าของดัชนีที่สอดคล้องกันของ l แต่ได้รับการเรียงลำดับ
>>> sort_third([1, 2, 3])
[1, 2, 3]
>>> sort_third([5, 6, 3, 4, 8, 9, 2])
... | 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 |
HumanEval/34 |
def unique(l: list):
"""ส่งคืนองค์ประกอบที่ไม่ซ้ำกันที่เรียงลำดับในรายการ
>>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])
[0, 2, 3, 5, 9, 123]
"""
| 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]
| unique |
HumanEval/35 |
def max_element(l: list):
"""ส่งคืนองค์ประกอบสูงสุดในรายการ
>>> max_element([1, 2, 3])
3
>>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
123
"""
| 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
| max_element |
HumanEval/36 |
def fizz_buzz(n: int):
"""คืนจำนวนครั้งที่หลัก 7 ปรากฏในจำนวนเต็มที่น้อยกว่า n ซึ่งหารด้วย 11 หรือ 13 ลงตัว
>>> fizz_buzz(50)
0
>>> fizz_buzz(78)
2
>>> fizz_buzz(79)
3
"""
| 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
| fizz_buzz |
HumanEval/37 |
def sort_even(l: list):
"""ฟังก์ชันนี้ใช้รายการ l และส่งคืนรายการ l' โดยที่ l' จะเหมือนกับ l ในดัชนีคี่ ในขณะที่ค่าในดัชนีคู่จะเท่ากับค่าของดัชนีคู่ของ l แต่ได้รับการเรียงลำดับ
>>> sort_even([1, 2, 3])
[1, 2, 3]
>>> sort_even([5, 6, 3, 4])
[3, 6, 5, 4]
"""
| 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 |
HumanEval/38 |
def encode_cyclic(s: str):
"""ส่งคืนสตริงที่เข้ารหัสโดยการหมุนเวียนกลุ่มอักขระสามตัว
"""
# split string to groups. Each of length 3.
groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]
# cycle elements in each group. Unless group has fewer elements than 3.
groups =... | return encode_cyclic(encode_cyclic(s))
|
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
| decode_cyclic |
HumanEval/39 |
def prime_fib(n: int):
"""prime_fib คืนค่าตัวเลขที่ n ซึ่งเป็นตัวเลข Fibonacci และเป็นจำนวนเฉพาะด้วย
>>> prime_fib(1)
2
>>> prime_fib(2)
3
>>> prime_fib(3)
5
>>> prime_fib(4)
13
>>> prime_fib(5)
89
"""
| 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_prime(f[-1]):
... |
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 |
HumanEval/40 |
def triples_sum_to_zero(l: list):
"""triples_sum_to_zero จะรับรายการจำนวนเต็มเป็นอินพุต โดยจะคืนค่า True หากมีองค์ประกอบที่แตกต่างกันสามองค์ประกอบในรายการที่ผลรวมเป็นศูนย์ และคืนค่า False หากไม่เป็นเช่นนั้น
>>> triples_sum_to_zero([1, 3, 5, 0])
False
>>> triples_sum_to_zero([1, 3, -2, 1])
True
... | 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 |
HumanEval/41 |
def car_race_collision(n: int):
"""ลองนึกภาพถนนที่ตรงและยาวไม่มีที่สิ้นสุด มีรถยนต์ n คันขับจากซ้ายไปขวา ในขณะเดียวกัน รถยนต์อีก n คันขับจากขวาไปซ้าย รถทั้งสองคันเริ่มอยู่ห่างกันมาก รถทุกคันเคลื่อนที่ด้วยความเร็วเท่ากัน กล่าวกันว่ารถสองคันจะชนกันเมื่อรถที่เคลื่อนที่จากซ้ายไปขวาชนกับรถที่เคลื่อนที่จากขวาไปซ้าย อย่... | 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
| car_race_collision |
HumanEval/42 |
def incr_list(l: list):
"""กลับรายการที่มีองค์ประกอบเพิ่มขึ้นทีละ 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]
"""
| 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]
| incr_list |
HumanEval/43 |
def pairs_sum_to_zero(l):
"""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_s... | 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 |
HumanEval/44 |
def change_base(x: int, base: int):
"""เปลี่ยนฐานตัวเลขของเลขอินพุต x ให้เป็นฐาน ส่งคืนการแสดงสตริงหลังจากการแปลง เลขฐานน้อยกว่า 10
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
'111'
"""
| 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 |
HumanEval/45 |
def triangle_area(a, h):
"""กำหนดความยาวด้านและพื้นที่ส่งคืนสูงสำหรับสามเหลี่ยม
>>> triangle_area(5, 3)
7.5
"""
| 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
| triangle_area |
HumanEval/46 |
def fib4(n: int):
"""ลำดับตัวเลข Fib4 เป็นลำดับที่คล้ายกับลำดับ Fibbonacci ซึ่งกำหนดดังนี้: 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) โปรดเขียนฟังก์ชันเพื่อคำนวณองค์ประกอบที่ n ของลำดับตัวเลข fib4 อย่างมีประสิทธิภาพ อย่าใช้การเรียกซ้ำ
>>> fib4... | 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
| fib4 |
HumanEval/47 |
def median(l: list):
"""คืนค่ามัธยฐานขององค์ประกอบในรายการ l
>>> median([3, 1, 2, 4, 5])
3
>>> median([-10, 4, 6, 1000, 10, 20])
15.0
"""
| 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
| median |
HumanEval/48 |
def is_palindrome(text: str):
"""ตรวจสอบว่าสตริงที่กำหนดเป็นพาลินโดรมหรือไม่
>>> is_palindrome('')
True
>>> is_palindrome('aba')
True
>>> is_palindrome('aaaaa')
True
>>> is_palindrome('zbcd')
False
"""
| 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
| is_palindrome |
HumanEval/49 |
def modp(n: int, p: int):
"""ส่งกลับ 2^n โมดูโล p (ระวังตัวเลข)
>>> 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 |
HumanEval/50 |
def encode_shift(s: str):
"""ส่งคืนสตริงที่เข้ารหัสโดยการเลื่อนอักขระแต่ละตัวทีละ 5 ตัวในตัวอักษร
"""
return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s])
def decode_shift(s: str):
"""
takes as input string encoded with encode_shift function. Returns decoded string.
... | 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 |
HumanEval/51 |
def remove_vowels(text):
"""remove_vowels เป็นฟังก์ชันที่รับสตริงและส่งคืนสตริงโดยไม่มีสระ
>>> remove_vowels('')
''
>>> remove_vowels("abcdef\nghijklm")
'bcdf\nghjklm'
>>> remove_vowels('abcdef')
'bcdf'
>>> remove_vowels('aaaaa')
''
>>> remove_vowels('aaBAA')
'B'
>>> re... | 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 |
HumanEval/52 |
def below_threshold(l: list, t: int):
"""คืนค่า True ถ้าตัวเลขทั้งหมดในรายการ l ต่ำกว่าเกณฑ์ 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 |
HumanEval/53 |
def add(x: int, y: int):
"""บวกเลขสองตัวคือ x และ y
>>> add(2, 3)
5
>>> add(5, 7)
12
"""
| 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 |
HumanEval/54 |
def same_chars(s0: str, s1: str):
"""ตรวจสอบว่าคำสองคำมีอักขระเดียวกันหรือไม่
>>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')
True
>>> same_chars('abcd', 'dddddddabc')
True
>>> same_chars('dddddddabc', 'abcd')
True
>>> same_chars('eabcd', 'dddddddabc')
False
>>> same_chars('a... | 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 |
HumanEval/55 |
def fib(n: int):
"""ส่งคืนเลข Fibonacci อันดับที่ n
>>> fib(10)
55
>>> fib(1)
1
>>> fib(8)
21
"""
| 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
| fib |
HumanEval/56 |
def correct_bracketing(brackets: str):
"""วงเล็บเป็นสตริงของ "<" และ ">" คืนค่า True หากวงเล็บเปิดทุกอันมีวงเล็บปิดที่สอดคล้องกัน
>>> correct_bracketing("<")
False
>>> correct_bracketing("<>")
True
>>> correct_bracketing("<<><>>")
True
>>> correct_bracketing("><<>")
False
"""
| 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 |
HumanEval/57 |
def monotonic(l: list):
"""ค่า Return True คือองค์ประกอบของรายการที่มีการเพิ่มขึ้นหรือลดลงแบบเอกภาพ
>>> monotonic([1, 2, 4, 20])
True
>>> monotonic([1, 20, 4, 10])
False
>>> monotonic([4, 1, 0, -10])
True
"""
| 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 |
HumanEval/58 |
def common(l1: list, l2: list):
"""ส่งคืนองค์ประกอบทั่วไปที่ไม่ซ้ำกันที่เรียงลำดับสำหรับสองรายการ
>>> 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]
"""
| 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], []) == []
| common |
HumanEval/59 |
def largest_prime_factor(n: int):
"""ส่งคืนตัวประกอบเฉพาะที่ใหญ่ที่สุดของ n ถือว่า n > 1 และไม่ใช่ตัวประกอบเฉพาะ
>>> largest_prime_factor(13195)
29
>>> largest_prime_factor(2048)
2
"""
| 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(largest, j)
return largest
|
METADATA = {}
def check(candidate):
assert candidate(15) == 5
assert candidate(27) == 3
assert candidate(63) == 7
assert candidate(330) == 11
assert candidate(13195) == 29
| largest_prime_factor |
HumanEval/60 |
def sum_to_n(n: int):
"""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
"""
| 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
| sum_to_n |
HumanEval/61 |
def correct_bracketing(brackets: str):
"""วงเล็บเป็นสตริงของ "(" และ ")" คืนค่า True หากวงเล็บเปิดทุกอันมีวงเล็บปิดที่สอดคล้องกัน
>>> correct_bracketing("(")
False
>>> correct_bracketing("()")
True
>>> correct_bracketing("(()())")
True
>>> correct_bracketing(")(()")
False
"""
| 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 |
HumanEval/62 |
def derivative(xs: list):
"""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]
"""
| 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]) == []
| derivative |
HumanEval/63 |
def fibfib(n: int):
"""ลำดับตัวเลข FibFib เป็นลำดับที่คล้ายกับลำดับ Fibbonacci ซึ่งกำหนดดังนี้: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3) โปรดเขียนฟังก์ชันเพื่อคำนวณองค์ประกอบที่ n ของลำดับตัวเลข FibFib อย่างมีประสิทธิภาพ
>>> fibfib(1)
0
>>> fibf... | 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
| fibfib |
HumanEval/64 |
FIX = """
Add more test cases.
"""
def vowels_count(s):
"""เขียนฟังก์ชัน vowels_count ซึ่งรับสตริงที่แสดงคำเป็นอินพุตและส่งคืนจำนวนสระในสตริง สระในกรณีนี้คือ 'a', 'e', 'i', 'o', 'u' ในที่นี้ 'y' ก็เป็นสระเช่นกัน แต่จะต้องอยู่ท้ายคำที่กำหนดเท่านั้น ตัวอย่าง:
>>> vowels_count("abcde")
2
>>> vowels_count... | 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 |
HumanEval/65 |
def circular_shift(x, shift):
"""การเลื่อนตัวเลขของจำนวนเต็ม x แบบวงกลม เลื่อนตัวเลขไปทางขวาโดยการเลื่อน แล้วส่งคืนผลลัพธ์เป็นสตริง หากการเลื่อน > จำนวนตัวเลข ให้ส่งคืนตัวเลขที่ย้อนกลับ
>>> circular_shift(12, 1)
"21"
>>> circular_shift(12, 2)
"12"
"""
| 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 |
HumanEval/66 |
def digitSum(s):
"""งาน เขียนฟังก์ชันที่รับสตริงเป็นอินพุตและส่งคืนผลรวมของรหัส ASCII ของอักขระตัวบนเท่านั้น ตัวอย่าง: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abcCd") => 67 digitSum("helloE") => 69 digitSum("woArBld") => 131 digitSum("aAaaaXa") => 153
"""
| 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 |
HumanEval/67 |
def fruit_distribution(s,n):
"""ในงานนี้ คุณจะได้รับสตริงที่แสดงถึงจำนวนแอปเปิ้ลและส้มที่กระจายอยู่ในตะกร้าผลไม้ ตะกร้านี้ประกอบด้วยแอปเปิ้ล ส้ม และมะม่วง เมื่อกำหนดสตริงที่แสดงถึงจำนวนส้มและแอปเปิ้ลทั้งหมด และจำนวนเต็มที่แสดงถึงจำนวนผลไม้ทั้งหมดในตะกร้า ให้ส่งคืนจำนวนผลมะม่วงในตะกร้า ตัวอย่างเช่น fruit_distributi... | 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 |
HumanEval/68 |
def pluck(arr):
""""เมื่อกำหนดอาร์เรย์ที่แสดงถึงสาขาของต้นไม้ที่มีโหนดจำนวนเต็มที่ไม่เป็นลบ งานของคุณคือเลือกโหนดหนึ่งและส่งคืน โหนดที่คัดมาควรเป็นโหนดที่มีค่าคู่ที่เล็กที่สุด หากพบโหนดหลายโหนดที่มีค่าคู่ที่เล็กที่สุดเท่ากัน ให้ส่งคืนโหนดที่มีดัชนีที่เล็กที่สุด โหนดที่คัดมาควรส่งคืนในรายการ [ smalest_value, ดัชนีข... | 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 |
HumanEval/69 |
def search(lst):
'''คุณจะได้รับรายการจำนวนเต็มบวกที่ไม่ว่าง ส่งคืนจำนวนเต็มที่มากที่สุดที่มากกว่าศูนย์และมีความถี่มากกว่าหรือเท่ากับค่าของจำนวนเต็มนั้นเอง ความถี่ของจำนวนเต็มคือจำนวนครั้งที่จำนวนเต็มนั้นปรากฏในรายการ หากไม่มีค่าดังกล่าว ให้ส่งคืน -1 ตัวอย่าง: search([4, 1, 2, 2, 3, 1]) == 2 search([1, 2, 2, 3, 3, ... | 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 |
HumanEval/70 |
def strange_sort_list(lst):
'''กำหนดให้รายการจำนวนเต็มแสดงรายการในลำดับที่แปลกประหลาด การเรียงลำดับที่แปลกประหลาดคือเมื่อคุณเริ่มต้นด้วยค่าต่ำสุด จากนั้นจึงเป็นค่าสูงสุดของจำนวนเต็มที่เหลือ จากนั้นจึงเป็นค่าต่ำสุด และเป็นเช่นนี้ไปเรื่อยๆ ตัวอย่าง: strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3] strange_sort_list([... | 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 |
HumanEval/71 |
def triangle_area(a, b, c):
'''กำหนดความยาวของด้านทั้งสามของสามเหลี่ยม ส่งคืนพื้นที่ของสามเหลี่ยมที่ปัดเศษเป็นทศนิยม 2 ตำแหน่งหากด้านทั้งสามประกอบเป็นสามเหลี่ยมที่ถูกต้อง มิฉะนั้น ส่งคืน -1 ด้านทั้งสามประกอบเป็นสามเหลี่ยมที่ถูกต้องเมื่อผลรวมของด้านสองด้านใดๆ มากกว่าด้านที่สาม ตัวอย่าง: triangle_area(3, 4, 5) == 6.... | 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 |
HumanEval/72 |
def will_it_fly(q,w):
'''เขียนฟังก์ชันที่คืนค่า True หากวัตถุ q จะบิน และคืนค่า False หากไม่เป็นเช่นนั้น วัตถุ q จะบินได้หากมีความสมดุล (เป็นรายการพาลินโดรม) และผลรวมขององค์ประกอบน้อยกว่าหรือเท่ากับน้ำหนักสูงสุดที่เป็นไปได้ w ตัวอย่าง: will_it_fly([1, 2], 5) ➞ False # 1+2 น้อยกว่าน้ำหนักสูงสุดที่เป็นไปได้ แต่ไม่สม... | 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 |
HumanEval/73 |
def smallest_change(arr):
"""กำหนดอาร์เรย์ arr ของจำนวนเต็ม หาจำนวนองค์ประกอบน้อยที่สุดที่ต้องเปลี่ยนแปลงเพื่อให้เป็นอาร์เรย์พาลินโดรม อาร์เรย์พาลินโดรมคืออาร์เรย์ที่อ่านค่าแบบเดียวกันทั้งไปข้างหน้าและข้างหลัง ในการเปลี่ยนแปลงหนึ่งครั้ง คุณสามารถเปลี่ยนองค์ประกอบหนึ่งเป็นองค์ประกอบอื่นใดก็ได้ ตัวอย่างเช่น: smalles... | 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 |
HumanEval/74 |
def total_match(lst1, lst2):
'''เขียนฟังก์ชันที่ยอมรับรายการสตริงสองรายการและส่งคืนรายการที่มีจำนวนอักขระทั้งหมดในสตริงทั้งหมดของรายการน้อยกว่ารายการอื่น ถ้ารายการทั้งสองมีจำนวนอักขระเท่ากัน ให้ส่งคืนรายการแรก ตัวอย่าง total_match([], []) ➞ [] total_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi'] total_match([... | 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 |
HumanEval/75 |
def is_multiply_prime(a):
"""เขียนฟังก์ชันที่คืนค่าเป็นจริงหากตัวเลขที่กำหนดคือการคูณจำนวนเฉพาะ 3 จำนวน และคืนค่าเท็จหากไม่ใช่ โดยทราบว่า (a) น้อยกว่า 100 ตัวอย่าง: is_multiply_prime(30) == True 30 = 2 * 3 * 5
"""
| 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):
if not i... | 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 |
HumanEval/76 |
def is_simple_power(x, n):
"""งานของคุณคือเขียนฟังก์ชันที่คืนค่าเป็นจริงหากตัวเลข x เป็นเลขยกกำลังธรรมดาของ n และคืนค่าเท็จในกรณีอื่น ๆ x เป็นเลขยกกำลังธรรมดาของ n ถ้า n**int=x ตัวอย่างเช่น: 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_... | 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 |
HumanEval/77 |
def iscube(a):
'''เขียนฟังก์ชันที่รับจำนวนเต็ม a และส่งคืนค่า True หากจำนวนเต็มนี้เป็นกำลังสามของจำนวนเต็มบางตัว หมายเหตุ: คุณอาจถือว่าอินพุตนั้นถูกต้องเสมอ ตัวอย่าง: iscube(1) ==> True iscube(2) ==> False iscube(-1) ==> True iscube(64) ==> True iscube(0) ==> True iscube(180) ==> False
'''
| 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 |
HumanEval/78 |
def hex_key(num):
"""คุณได้รับมอบหมายให้เขียนฟังก์ชันที่รับเลขฐานสิบหกเป็นสตริงและนับจำนวนหลักฐานสิบหกที่เป็นจำนวนเฉพาะ (จำนวนเฉพาะหรือจำนวนเฉพาะคือจำนวนธรรมชาติที่มากกว่า 1 ซึ่งไม่ใช่ผลคูณของจำนวนธรรมชาติที่เล็กกว่าสองตัว) หลักฐานสิบหกคือ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F จำนวนเฉพาะคือ 2, 3, 5, 7, 11... | 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 |
HumanEval/79 |
def decimal_to_binary(decimal):
"""คุณจะได้รับตัวเลขในรูปแบบทศนิยม และงานของคุณคือการแปลงตัวเลขดังกล่าวเป็นรูปแบบไบนารี ฟังก์ชันควรส่งคืนสตริง โดยแต่ละอักขระจะแสดงเป็นเลขฐานสอง อักขระแต่ละตัวในสตริงจะเป็น "0" หรือ "1" โดยจะมีอักขระพิเศษอีกสองตัวคือ "db" ที่จุดเริ่มต้นและจุดสิ้นสุดของสตริง อักขระพิเศษเหล่านี้จะช่วย... | 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 |
HumanEval/80 |
def is_happy(s):
"""คุณจะได้รับสตริง 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) => Fa... | 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 |
HumanEval/81 |
def numerical_letter_grade(grades):
"""ตอนนี้เป็นสัปดาห์สุดท้ายของภาคการศึกษาและครูต้องให้เกรดกับนักเรียน ครูได้สร้างอัลกอริทึมสำหรับการให้เกรดของเธอเอง ปัญหาเดียวคือ ครูทำรหัสที่ใช้ในการให้เกรดหายไป ครูได้ให้รายการ GPA ของนักเรียนบางคนแก่คุณ และคุณต้องเขียนฟังก์ชันที่สามารถแสดงรายการเกรดเป็นตัวอักษรโดยใช้ตารางต่อ... |
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.append("B+")
elif gpa > 2.7:
... | 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 |
HumanEval/82 |
def prime_length(string):
"""เขียนฟังก์ชันที่รับสตริงและส่งคืน True หากความยาวสตริงเป็นจำนวนเฉพาะหรือส่งคืน False หากไม่เช่นนั้น ตัวอย่าง prime_length('Hello') == True prime_length('abcdcba') == True prime_length('kittens') == True prime_length('orange') == False
"""
| 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 |
HumanEval/83 |
def starts_one_ends(n):
"""กำหนดจำนวนเต็มบวก n ให้ส่งคืนจำนวนเต็มบวก n หลักที่เริ่มต้นหรือลงท้ายด้วย 1
"""
| 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 |
HumanEval/84 |
def solve(N):
"""กำหนดจำนวนเต็มบวก N ให้ส่งคืนผลรวมทั้งหมดของตัวเลขในรูปแบบไบนารี ตัวอย่าง สำหรับ N = 1000 ผลรวมของตัวเลขจะเท่ากับ 1 ผลลัพธ์ควรเป็น "1" สำหรับ N = 150 ผลรวมของตัวเลขจะเท่ากับ 6 ผลลัพธ์ควรเป็น "110" สำหรับ N = 147 ผลรวมของตัวเลขจะเท่ากับ 12 ผลลัพธ์ควรเป็น "1100" ตัวแปร: @N จำนวนเต็ม ข้อจำกัด: 0 ≤ 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 |
HumanEval/85 |
def add(lst):
"""กำหนดรายการจำนวนเต็มที่ไม่ว่าง lst. เพิ่มองค์ประกอบคู่ที่มีดัชนีคี่ ตัวอย่าง: add([4, 2, 6, 7]) ==> 2
"""
| 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.
| add |
HumanEval/86 |
def anti_shuffle(s):
"""เขียนฟังก์ชันที่รับสตริงและส่งคืนเวอร์ชันที่เรียงลำดับของสตริงนั้น เวอร์ชันที่เรียงลำดับของสตริงคือสตริงที่คำทั้งหมด (คั่นด้วยช่องว่าง) จะถูกแทนที่ด้วยคำใหม่ โดยที่อักขระทั้งหมดจะเรียงตามลำดับจากน้อยไปมากตามค่า ASCII หมายเหตุ: คุณควรคงลำดับของคำและช่องว่างในประโยคไว้ ตัวอย่างเช่น: anti_shuf... | 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 |
HumanEval/87 |
def get_row(lst, x):
"""คุณจะได้รับข้อมูล 2 มิติในรูปแบบรายการซ้อน ซึ่งคล้ายกับเมทริกซ์ อย่างไรก็ตาม ต่างจากเมทริกซ์ ตรงที่แต่ละแถวอาจมีจำนวนคอลัมน์ต่างกัน เมื่อกำหนด lst และจำนวนเต็ม x ให้ค้นหาจำนวนเต็ม x ในรายการ และส่งคืนรายการของทูเพิล [(x1, y1), (x2, y2) ...] โดยที่แต่ละทูเพิลเป็นพิกัด - (แถว คอลัมน์) เริ่มต้... | 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 |
HumanEval/88 |
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 |
HumanEval/89 |
def encrypt(s):
"""สร้างฟังก์ชัน encrypt ที่รับสตริงเป็นอาร์กิวเมนต์และส่งคืนสตริงที่เข้ารหัสด้วยตัวอักษรที่หมุน ตัวอักษรควรหมุนในลักษณะที่ตัวอักษรเลื่อนลงสองคูณสองตำแหน่ง ตัวอย่างเช่น: encrypt('hi') ส่งคืน 'lm' encrypt('asdfghjkl') ส่งคืน 'ewhjklnop' encrypt('gf') ส่งคืน 'kj' encrypt('et') ส่งคืน 'ix'
"""
| 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 |
HumanEval/90 |
def next_smallest(lst):
"""คุณจะได้รับรายการจำนวนเต็ม เขียนฟังก์ชัน next_smallest() ที่ส่งคืนองค์ประกอบที่เล็กเป็นอันดับ 2 ของรายการ ส่งคืน 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
"""
| 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 |
HumanEval/91 |
def is_bored(S):
"""คุณจะได้รับคำจำนวนหนึ่ง และงานของคุณคือนับจำนวนความเบื่อหน่าย ความเบื่อหน่ายคือประโยคที่เริ่มต้นด้วยคำว่า "I" ประโยคจะถูกคั่นด้วย '.', '?' หรือ '!' ตัวอย่างเช่น:
>>> is_bored("Hello world")
0
>>> is_bored("The sky is blue. The sun is shining. I love this weather")
1
"""
| 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 |
HumanEval/92 |
def any_int(x, y, z):
'''สร้างฟังก์ชันที่ใช้ตัวเลข 3 ตัว คืนค่าเป็นจริงหากตัวเลขตัวหนึ่งมีค่าเท่ากับผลรวมของอีกสองตัว และตัวเลขทั้งหมดเป็นจำนวนเต็ม คืนค่าเท็จในกรณีอื่น ๆ ตัวอย่าง 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
'''
|
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 |
HumanEval/93 |
def encode(message):
"""จงเขียนฟังก์ชันที่รับข้อความและเข้ารหัสโดยเปลี่ยนตัวพิมพ์ใหญ่-เล็กของตัวอักษรทั้งหมด และแทนที่สระทั้งหมดในข้อความด้วยตัวอักษรที่ปรากฏอยู่ข้างหน้าสระนั้น 2 ตำแหน่งในตัวอักษรภาษาอังกฤษ โดยถือว่ามีเฉพาะตัวอักษรเท่านั้น ตัวอย่าง:
>>> encode('test')
'TGST'
>>> encode('This is a messa... | 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 |
HumanEval/94 |
def skjkasdkd(lst):
"""คุณจะได้รับรายการจำนวนเต็ม คุณต้องค้นหาค่าเฉพาะที่ใหญ่ที่สุดและส่งคืนผลรวมของตัวเลขเหล่านั้น ตัวอย่าง: สำหรับ 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,... | 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 digit in str(maxx))
... | 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 |
HumanEval/95 |
def check_dict_case(dict):
"""ให้พจนานุกรมส่งกลับค่า True หากคีย์ทั้งหมดเป็นสตริงตัวพิมพ์เล็กหรือคีย์ทั้งหมดเป็นสตริงตัวพิมพ์ใหญ่ มิฉะนั้นให้ส่งกลับค่า False ฟังก์ชันควรส่งกลับค่า False หากพจนานุกรมที่กำหนดว่างเปล่า ตัวอย่าง: check_dict_case({"a":"apple", "b":"banana"}) ควรส่งกลับค่า True check_dict_case({"a":"app... | 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():
state = "upper"... | 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 |
HumanEval/96 |
def count_up_to(n):
"""ใช้ฟังก์ชันที่รับจำนวนเต็มที่ไม่เป็นลบและส่งคืนอาร์เรย์ของจำนวนเต็ม 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]
... | 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 |
HumanEval/97 |
def multiply(a, b):
"""ดำเนินการฟังก์ชันที่รับจำนวนเต็มสองจำนวนและส่งคืนผลคูณของหลักหน่วยของจำนวนเต็มเหล่านั้นให้สมบูรณ์ สมมติว่าอินพุตนั้นถูกต้องเสมอ ตัวอย่าง: multiply(148, 412) ควรส่งคืน 16, multiply(19, 28) ควรส่งคืน 72, multiply(2020, 1851) ควรส่งคืน 0, multiply(14,-15) ควรส่งคืน 20
"""
| 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 |
HumanEval/98 |
def count_upper(s):
"""กำหนดสตริง s ให้นับจำนวนสระตัวพิมพ์ใหญ่ในดัชนีคู่ ตัวอย่างเช่น count_upper('aBCdEf') คืนค่า 1 count_upper('abcdefg') คืนค่า 0 count_upper('dBBE') คืนค่า 0
"""
| 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 |
HumanEval/99 |
def closest_integer(value):
'''สร้างฟังก์ชันที่รับค่า (สตริง) ที่แสดงถึงตัวเลขและส่งคืนจำนวนเต็มที่ใกล้เคียงที่สุดกับตัวเลขนั้น หากตัวเลขมีระยะห่างเท่ากันจากจำนวนเต็มสองจำนวน ให้ปัดเศษออกจากศูนย์ ตัวอย่าง >>> closest_integer("10") 10 >>> closest_integer("15.3") 15 หมายเหตุ: การปัดเศษออกจากศูนย์หมายความว่าหากตัวเลข... | 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 = floor(num)
elif len(valu... | 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 |
Subsets and Splits
Select Specific Task Data
Retrieves all records from the test dataset where the task_id is 'HumanEval\/0', providing basic filtering but limited analytical value.