Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringlengths
12
14
prompt
stringlengths
118
1.11k
canonical_solution
stringlengths
17
895
test
stringlengths
125
1.84k
entry_point
stringlengths
1
30
HumanEval\/0
from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n """ตรวจสอบว่าในรายการตัวเลขที่กำหนดไว้ มีตัวเลขสองตัวใดที่อยู่ใกล้กันมากกว่าเกณฑ์ที่กำหนดไว้หรือไม่\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0,...
for idx, elem in enumerate(numbers):\n for idx2, elem2 in enumerate(numbers):\n if idx != idx2:\n distance = abs(elem - elem2)\n if distance < threshold:\n return True\n\n return False\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True\n assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False\n assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True\n assert candidate([1.0, 2....
has_close_elements
HumanEval\/1
from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n """อินพุตของฟังก์ชันนี้คือสตริงที่มีวงเล็บซ้อนกันหลายกลุ่ม เป้าหมายของคุณคือแยกกลุ่มเหล่านั้นออกเป็นสตริงแยกกันและส่งคืนรายการของกลุ่มเหล่านั้น กลุ่มที่แยกจากกันจะสมดุลกัน (วงเล็บเปิดแต่ละอันปิดอย่างถูกต้อง) และไม่ซ้อนกัน ไม่สน...
result = []\n current_string = []\n current_depth = 0\n\n for c in paren_string:\n if c == '(':\n current_depth += 1\n current_string.append(c)\n elif c == ')':\n current_depth -= 1\n current_string.append(c)\n\n if current_depth == 0:\n ...
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('(()()) ((())) () ((())()())') == [\n '(()())', '((()))', '()', '((())()())'\n ]\n assert candidate('() (()) ((())) (((())))') == [\n '()', '(())', '((()))', '(((())))'\n ]\n assert...
separate_paren_groups
HumanEval\/2
\n\ndef truncate_number(number: float) -> float:\n """เมื่อกำหนดจำนวนจุดลอยตัวเป็นบวก ตัวเลขดังกล่าวสามารถแยกออกเป็นส่วนจำนวนเต็ม (จำนวนเต็มที่มากที่สุดที่เล็กกว่าจำนวนที่กำหนด) และทศนิยม (ส่วนที่เหลือจะเล็กกว่า 1 เสมอ) ส่งคืนส่วนทศนิยมของตัวเลข\n >>> truncate_number(3.5)\n 0.5"""\n
return number % 1.0\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(3.5) == 0.5\n assert abs(candidate(1.33) - 0.33) < 1e-6\n assert abs(candidate(123.456) - 0.456) < 1e-6\n
truncate_number
HumanEval\/3
from typing import List\n\n\ndef below_zero(operations: List[int]) -> bool:\n """คุณจะได้รับรายการการฝากและถอนเงินในบัญชีธนาคารที่เริ่มต้นด้วยยอดเงินคงเหลือเป็นศูนย์ งานของคุณคือตรวจจับว่าเมื่อใดยอดเงินคงเหลือในบัญชีจะลดลงต่ำกว่าศูนย์ และเมื่อถึงจุดนั้น ฟังก์ชันควรส่งคืนค่า True มิฉะนั้น ฟังก์ชันควรส่งคืนค่า False\n...
balance = 0\n\n for op in operations:\n balance += op\n if balance < 0:\n return True\n\n return False\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == False\n assert candidate([1, 2, -3, 1, 2, -3]) == False\n assert candidate([1, 2, -4, 5, 6]) == True\n assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False\n assert candidate([1, -1, 2,...
below_zero
HumanEval\/4
from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n """สำหรับรายการตัวเลขอินพุตที่กำหนด ให้คำนวณค่าเบี่ยงเบนสัมบูรณ์เฉลี่ยรอบค่าเฉลี่ยของชุดข้อมูลนี้ ค่าเบี่ยงเบนสัมบูรณ์เฉลี่ยคือความแตกต่างสัมบูรณ์เฉลี่ยระหว่างแต่ละองค์ประกอบและจุดศูนย์กลาง (ค่าเฉลี่ยในกรณีนี้): MAD = ค่าเฉลี่...
mean = sum(numbers) \/ len(numbers)\n return sum(abs(x - mean) for x in numbers) \/ len(numbers)\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert abs(candidate([1.0, 2.0, 3.0]) - 2.0\/3.0) < 1e-6\n assert abs(candidate([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\n assert abs(candidate([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0\/5.0) < 1e-6\n\n
mean_absolute_deviation
HumanEval\/5
from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n """แทรก \'ตัวแบ่ง\' ตัวเลขระหว่างองค์ประกอบ \'ตัวเลข\' สององค์ประกอบติดต่อกันของรายการอินพุต\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]"""\n
if not numbers:\n return []\n\n result = []\n\n for n in numbers[:-1]:\n result.append(n)\n result.append(delimeter)\n\n result.append(numbers[-1])\n\n return result\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([], 7) == []\n assert candidate([5, 6, 3, 2], 8) == [5, 8, 6, 8, 3, 8, 2]\n assert candidate([2, 2, 2], 2) == [2, 2, 2, 2, 2]\n
intersperse
HumanEval\/6
from typing import List\n\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n """อินพุตของฟังก์ชันนี้คือสตริงที่แสดงกลุ่มต่างๆ หลายกลุ่มสำหรับวงเล็บซ้อนที่คั่นด้วยช่องว่าง สำหรับแต่ละกลุ่ม ให้แสดงระดับการซ้อนวงเล็บที่ลึกที่สุด ตัวอย่างเช่น (()()) มีระดับการซ้อนสูงสุดสองระดับในขณะที่ ((())) มีสามระดับ\n ...
def parse_paren_group(s):\n depth = 0\n max_depth = 0\n for c in s:\n if c == '(':\n depth += 1\n max_depth = max(depth, max_depth)\n else:\n depth -= 1\n\n return max_depth\n\n return [parse_paren_group(x) for x in pa...
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3]\n assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4]\n assert candidate('(()(())((())))') == [4]\n
parse_nested_parens
HumanEval\/7
from typing import List\n\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n """กรองรายการอินพุตของสตริงเฉพาะที่มีสตริงย่อยที่กำหนดเท่านั้น\n >>> filter_by_substring([], 'a')\n []\n >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']"""\n
return [x for x in strings if substring in x]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([], 'john') == []\n assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']\n assert candidate(['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'], 'xx...
filter_by_substring
HumanEval\/8
from typing import List, Tuple\n\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n """สำหรับรายการจำนวนเต็มที่กำหนด ให้ส่งคืนทูเพิลที่ประกอบด้วยผลรวมและผลคูณของจำนวนเต็มทั้งหมดในรายการ ผลรวมว่างควรเท่ากับ 0 และผลคูณว่างควรเท่ากับ 1\n >>> sum_product([])\n (0, 1)\n >>> sum_product([1, 2, 3, 4])\n ...
sum_value = 0\n prod_value = 1\n\n for n in numbers:\n sum_value += n\n prod_value *= n\n return sum_value, prod_value\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == (0, 1)\n assert candidate([1, 1, 1]) == (3, 1)\n assert candidate([100, 0]) == (100, 0)\n assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7)\n assert candidate([10]) == (10, 10)\n
sum_product
HumanEval\/9
from typing import List, Tuple\n\n\ndef rolling_max(numbers: List[int]) -> List[int]:\n """จากรายการจำนวนเต็มที่กำหนดให้ สร้างรายการขององค์ประกอบสูงสุดที่หมุนเวียนที่พบจนถึงช่วงเวลาที่กำหนดในลำดับ\n >>> rolling_max([1, 2, 3, 2, 3, 4, 2])\n [1, 2, 3, 3, 3, 4, 4]"""\n
running_max = None\n result = []\n\n for n in numbers:\n if running_max is None:\n running_max = n\n else:\n running_max = max(running_max, n)\n\n result.append(running_max)\n\n return result\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == []\n assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4]\n assert candidate([4, 3, 2, 1]) == [4, 4, 4, 4]\n assert candidate([3, 2, 3, 100, 3]) == [3, 3, 3, 100, 100]\n
rolling_max
HumanEval\/10
\n\ndef is_palindrome(string: str) -> bool:\n """ทดสอบว่าสตริงที่กำหนดเป็นพาลินโดรม """ return string == string[::-1] def make_palindrome(string: str) -> str:\n >>>""" Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string...
if not string:\n return ''\n\n beginning_of_suffix = 0\n\n while not is_palindrome(string[beginning_of_suffix:]):\n beginning_of_suffix += 1\n\n return string + string[:beginning_of_suffix][::-1]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == ''\n assert candidate('x') == 'x'\n assert candidate('xyz') == 'xyzyx'\n assert candidate('xyx') == 'xyx'\n assert candidate('jerry') == 'jerryrrej'\n
make_palindrome
HumanEval\/11
from typing import List\n\n\ndef string_xor(a: str, b: str) -> str:\n """อินพุตเป็นสตริงสองตัวคือ a และ b ที่ประกอบด้วย 1 และ 0 เท่านั้น ดำเนินการ XOR แบบไบนารีกับอินพุตเหล่านี้และส่งคืนผลลัพธ์เป็นสตริงด้วยเช่นกัน\n >>> string_xor('010', '110')\n '100'"""\n
def xor(i, j):\n if i == j:\n return '0'\n else:\n return '1'\n\n return ''.join(xor(x, y) for x, y in zip(a, b))\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('111000', '101010') == '010010'\n assert candidate('1', '1') == '0'\n assert candidate('0101', '0000') == '0101'\n
string_xor
HumanEval\/12
from typing import List, Optional\n\n\ndef longest(strings: List[str]) -> Optional[str]:\n """จากรายการสตริง ให้ส่งคืนสตริงที่ยาวที่สุด ส่งคืนสตริงแรกในกรณีที่มีสตริงหลายตัวที่มีความยาวเท่ากัน ส่งคืน None ในกรณีที่รายการอินพุตว่างเปล่า\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longes...
if not strings:\n return None\n\n maxlen = max(len(x) for x in strings)\n for s in strings:\n if len(s) == maxlen:\n return s\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == None\n assert candidate(['x', 'y', 'z']) == 'x'\n assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'\n
longest
HumanEval\/13
\n\ndef greatest_common_divisor(a: int, b: int) -> int:\n """คืนค่าตัวหารร่วมมากของจำนวนเต็มสองจำนวนคือ a และ b\n >>> greatest_common_divisor(3, 5)\n 1\n >>> greatest_common_divisor(25, 15)\n 5"""\n
while b:\n a, b = b, a % b\n return a\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(3, 7) == 1\n assert candidate(10, 15) == 5\n assert candidate(49, 14) == 7\n assert candidate(144, 60) == 12\n
greatest_common_divisor
HumanEval\/14
from typing import List\n\n\ndef all_prefixes(string: str) -> List[str]:\n """แสดงรายการคำนำหน้าทั้งหมดตั้งแต่สั้นที่สุดไปจนถึงยาวที่สุดของสตริงอินพุต\n >>> all_prefixes('abc')\n ['a', 'ab', 'abc']"""\n
result = []\n\n for i in range(len(string)):\n result.append(string[:i+1])\n return result\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == []\n assert candidate('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh']\n assert candidate('WWW') == ['W', 'WW', 'WWW']\n
all_prefixes
HumanEval\/15
\n\ndef string_sequence(n: int) -> str:\n """ส่งคืนสตริงที่มีตัวเลขที่คั่นด้วยช่องว่างตั้งแต่ 0 ถึง n\n >>> string_sequence(0)\n '0'\n >>> string_sequence(5)\n '0 1 2 3 4 5'"""\n
return ' '.join([str(x) for x in range(n + 1)])\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(0) == '0'\n assert candidate(3) == '0 1 2 3'\n assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10'\n
string_sequence
HumanEval\/16
\n\ndef count_distinct_characters(string: str) -> int:\n """กำหนดสตริง ให้หาว่ามีอักขระที่แตกต่างกันกี่ตัว (โดยไม่คำนึงถึงตัวพิมพ์ใหญ่เล็ก) ที่ประกอบด้วย\n >>> count_distinct_characters('xyzXYZ')\n 3\n >>> count_distinct_characters('Jerry')\n 4"""\n
return len(set(string.lower()))\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == 0\n assert candidate('abcde') == 5\n assert candidate('abcde' + 'cade' + 'CADE') == 5\n assert candidate('aaaaAAAAaaaa') == 1\n assert candidate('Jerry jERRY JeRRRY') == 5\n
count_distinct_characters
HumanEval\/17
from typing import List\n\n\ndef parse_music(music_string: str) -> List[int]:\n """อินพุตสำหรับฟังก์ชันนี้คือสตริงที่แสดงโน้ตดนตรีในรูปแบบ ASCII พิเศษ งานของคุณคือวิเคราะห์สตริงนี้และส่งคืนรายการจำนวนเต็มที่สอดคล้องกับจำนวนจังหวะที่แต่ละจังหวะไม่คงอยู่ ต่อไปนี้คือคำอธิบาย: \'o\' - โน้ตตัวเต็ม ยาวนานสี่จังหวะ \'o|\' ...
note_map = {'o': 4, 'o|': 2, '.|': 1}\n return [note_map[x] for x in music_string.split(' ') if x]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == []\n assert candidate('o o o o') == [4, 4, 4, 4]\n assert candidate('.| .| .| .|') == [1, 1, 1, 1]\n assert candidate('o| o| .| .| o o o o') == [2, 2, 1, 1, 4, 4, 4, 4]\n assert candidate(...
parse_music
HumanEval\/18
\n\ndef how_many_times(string: str, substring: str) -> int:\n """ค้นหาว่าสามารถพบซับสตริงที่กำหนดได้กี่ครั้งในสตริงต้นฉบับ นับกรณีที่ทับซ้อนกัน\n >>> how_many_times('', 'a')\n 0\n >>> how_many_times('aaa', 'a')\n 3\n >>> how_many_times('aaaa', 'aa')\n 3"""\n
times = 0\n\n for i in range(len(string) - len(substring) + 1):\n if string[i:i+len(substring)] == substring:\n times += 1\n\n return times\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('', 'x') == 0\n assert candidate('xyxyxyx', 'x') == 4\n assert candidate('cacacacac', 'cac') == 4\n assert candidate('john doe', 'john') == 1\n
how_many_times
HumanEval\/19
from typing import List\n\n\ndef sort_numbers(numbers: str) -> str:\n """อินพุตเป็นสตริงตัวเลขที่คั่นด้วยช่องว่างตั้งแต่ \'ศูนย์\' ถึง \'เก้า\' ตัวเลือกที่ถูกต้องคือ \'ศูนย์\' \'หนึ่ง\' \'สอง\' \'สาม\' \'สี่\' \'ห้า\' \'หก\' \'เจ็ด\' \'แปด\' และ \'เก้า\' ส่งคืนสตริงที่มีตัวเลขเรียงจากน้อยไปมาก\n >>> sort_numbers(...
value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n }\n return ' '.join(sorted([x for x in numbers.split(' ') if x], key=lambda x: value_map[x]))\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == ''\n assert candidate('three') == 'three'\n assert candidate('three five nine') == 'three five nine'\n assert candidate('five zero four seven nine eight') == 'zero four five seven eight nine'...
sort_numbers
HumanEval\/20
from typing import List, Tuple\n\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n """จากรายการตัวเลขที่จัดทำไว้ (ความยาวอย่างน้อย 2) ให้เลือกตัวเลข 2 ตัวที่อยู่ใกล้กันมากที่สุด แล้วส่งคืนตามลำดับ (ตัวเลขที่น้อยกว่า ตัวเลขที่มากกว่า)\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0,...
closest_pair = None\n distance = None\n\n for idx, elem in enumerate(numbers):\n for idx2, elem2 in enumerate(numbers):\n if idx != idx2:\n if distance is None:\n distance = abs(elem - elem2)\n closest_pair = tuple(sorted([elem, elem2]))\n...
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2]) == (3.9, 4.0)\n assert candidate([1.0, 2.0, 5.9, 4.0, 5.0]) == (5.0, 5.9)\n assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)\n assert candidate([1.0, 2....
find_closest_elements
HumanEval\/21
from typing import List\n\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n """กำหนดรายการตัวเลข (อย่างน้อย 2 องค์ประกอบ) ใช้การแปลงเชิงเส้นกับรายการนั้น โดยที่ตัวเลขที่เล็กที่สุดจะกลายเป็น 0 และตัวเลขที่ใหญ่ที่สุดจะกลายเป็น 1\n >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.7...
min_number = min(numbers)\n max_number = max(numbers)\n return [(x - min_number) \/ (max_number - min_number) for x in numbers]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([2.0, 49.9]) == [0.0, 1.0]\n assert candidate([100.0, 49.9]) == [1.0, 0.0]\n assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]\n assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) ...
rescale_to_unit
HumanEval\/22
from typing import List, Any\n\n\ndef filter_integers(values: List[Any]) -> List[int]:\n """กรองรายการค่า Python ที่กำหนดไว้เฉพาะสำหรับจำนวนเต็มเท่านั้น\n >>> filter_integers(['a', 3.14, 5])\n [5]\n >>> filter_integers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]"""\n
return [x for x in values if isinstance(x, int)]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == []\n assert candidate([4, {}, [], 23.2, 9, 'adasd']) == [4, 9]\n assert candidate([3, 'c', 3, 3, 'a', 'b']) == [3, 3, 3]\n
filter_integers
HumanEval\/23
\n\ndef strlen(string: str) -> int:\n """ส่งคืนความยาวของสตริงที่กำหนด\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3"""\n
return len(string)\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == 0\n assert candidate('x') == 1\n assert candidate('asdasnakj') == 9\n
strlen
HumanEval\/24
\n\ndef largest_divisor(n: int) -> int:\n """สำหรับจำนวน n ที่กำหนด หาจำนวนที่มากที่สุดที่หาร n ได้ลงตัว ซึ่งมีค่าน้อยกว่า n\n >>> largest_divisor(15)\n 5"""\n
for i in reversed(range(n)):\n if n % i == 0:\n return i\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(3) == 1\n assert candidate(7) == 1\n assert candidate(10) == 5\n assert candidate(100) == 50\n assert candidate(49) == 7\n
largest_divisor
HumanEval\/25
from typing import List\n\n\ndef factorize(n: int) -> List[int]:\n """ส่งคืนรายการปัจจัยเฉพาะของจำนวนเต็มที่กำหนดให้ตามลำดับจากน้อยไปหามาก ปัจจัยแต่ละตัวควรแสดงรายการตามจำนวนครั้งที่ปรากฏในการแยกตัวประกอบ จำนวนอินพุตควรเท่ากับผลคูณของปัจจัยทั้งหมด\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, ...
import math\n fact = []\n i = 2\n while i <= int(math.sqrt(n) + 1):\n if n % i == 0:\n fact.append(i)\n n \/\/= i\n else:\n i += 1\n\n if n > 1:\n fact.append(n)\n return fact\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(2) == [2]\n assert candidate(4) == [2, 2]\n assert candidate(8) == [2, 2, 2]\n assert candidate(3 * 19) == [3, 19]\n assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19]\n assert candidate(3 * ...
factorize
HumanEval\/26
from typing import List\n\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n """จากรายการจำนวนเต็ม ให้ลบองค์ประกอบทั้งหมดที่เกิดขึ้นมากกว่าหนึ่งครั้งออก รักษาลำดับขององค์ประกอบให้เหมือนเดิมกับในอินพุต\n >>> remove_duplicates([1, 2, 3, 2, 4])\n [1, 3, 4]"""\n
import collections\n c = collections.Counter(numbers)\n return [n for n in numbers if c[n] <= 1]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == []\n assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4]\n assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]\n
remove_duplicates
HumanEval\/27
\n\ndef flip_case(string: str) -> str:\n """สำหรับสตริงที่กำหนด ให้เปลี่ยนตัวอักษรตัวพิมพ์เล็กเป็นตัวพิมพ์ใหญ่ และเปลี่ยนตัวอักษรตัวพิมพ์ใหญ่เป็นตัวพิมพ์เล็ก\n >>> flip_case('Hello')\n 'hELLO'"""\n
return string.swapcase()\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == ''\n assert candidate('Hello!') == 'hELLO!'\n assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'\n
flip_case
HumanEval\/28
from typing import List\n\n\ndef concatenate(strings: List[str]) -> str:\n """เชื่อมโยงรายการสตริงเข้าเป็นสตริงเดียว\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'"""\n
return ''.join(strings)\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == ''\n assert candidate(['x', 'y', 'z']) == 'xyz'\n assert candidate(['x', 'y', 'z', 'w', 'k']) == 'xyzwk'\n
concatenate
HumanEval\/29
from typing import List\n\n\ndef filter_by_prefix(strings: List[str], prefix: str) -> List[str]:\n """กรองรายการอินพุตของสตริงเฉพาะรายการที่เริ่มต้นด้วยคำนำหน้าที่กำหนดเท่านั้น\n >>> filter_by_prefix([], 'a')\n []\n >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']"""\n
return [x for x in strings if x.startswith(prefix)]\n
\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([], 'john') == []\n assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']\n
filter_by_prefix
HumanEval\/30
\n\ndef get_positive(l: list):\n """กลับเฉพาะตัวเลขบวกในรายการ\n >>> get_positive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]"""\n
return [e for e in l if e > 0]\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6]\n assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]\n assert candidate([-1, -2]) == []\n assert candidate([]) == []\n\n
get_positive
HumanEval\/31
\n\ndef is_prime(n):\n """คืนค่าเป็นจริงถ้าตัวเลขที่กำหนดเป็นจำนวนเฉพาะ และคืนค่าเท็จถ้าไม่เป็นเช่นนั้น\n >>> is_prime(6)\n False\n >>> is_prime(101)\n True\n >>> is_prime(11)\n True\n >>> is_prime(13441)\n True\n >>> is_prime(61)\n True\n >>> is_prime(4)\n False\n >>> is_prime...
if n < 2:\n return False\n for k in range(2, n - 1):\n if n % k == 0:\n return False\n return True\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(6) == False\n assert candidate(101) == True\n assert candidate(11) == True\n assert candidate(13441) == True\n assert candidate(61) == True\n assert candidate(4) == False\n assert candidate(1) == False\n assert candidate(5) == True\...
is_prime
HumanEval\/32
import math\n\n\ndef poly(xs: list, x: float):\n """ประเมินพหุนามที่มีค่าสัมประสิทธิ์ xs ที่จุด x ส่งคืน xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n >>>"""\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\n\n\ndef find_zero(xs: list):""" xs are coefficients of a polynomial.\n fi...
begin, end = -1., 1.\n while poly(xs, begin) * poly(xs, end) > 0:\n begin *= 2.0\n end *= 2.0\n while end - begin > 1e-10:\n center = (begin + end) \/ 2.0\n if poly(xs, center) * poly(xs, begin) > 0:\n begin = center\n else:\n end = center\n return b...
\n\nMETADATA = {}\n\n\ndef check(candidate):\n import math\n import random\n rng = random.Random(42)\n import copy\n for _ in range(100):\n ncoeff = 2 * rng.randint(1, 4)\n coeffs = []\n for _ in range(ncoeff):\n coeff = rng.randint(-10, 10)\n if coeff == 0:\n ...
find_zero
HumanEval\/33
\n\ndef sort_third(l: list):\n """ฟังก์ชันนี้ใช้รายการ l และส่งคืนรายการ l\' โดยที่ l\' จะเหมือนกับ l ในดัชนีที่หารด้วยสามไม่ลงตัว ในขณะที่ค่าของ l ในดัชนีที่หารด้วยสามลงตัวจะเท่ากับค่าของดัชนีที่สอดคล้องกันของ l แต่ได้รับการเรียงลำดับ\n >>> sort_third([1, 2, 3])\n [1, 2, 3]\n >>> sort_third([5, 6, 3, 4, 8,...
l = list(l)\n l[::3] = sorted(l[::3])\n return l\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert tuple(candidate([1, 2, 3])) == tuple(sort_third([1, 2, 3]))\n 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]))\n assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == ...
sort_third
HumanEval\/34
\n\ndef unique(l: list):\n """ส่งคืนองค์ประกอบที่ไม่ซ้ำกันที่เรียงลำดับในรายการ\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]"""\n
return sorted(list(set(l)))\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]\n\n
unique
HumanEval\/35
\n\ndef max_element(l: list):\n """ส่งคืนองค์ประกอบสูงสุดในรายการ\n >>> max_element([1, 2, 3])\n 3\n >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123"""\n
m = l[0]\n for e in l:\n if e > m:\n m = e\n return m\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 2, 3]) == 3\n assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124\n
max_element
HumanEval\/36
\n\ndef fizz_buzz(n: int):\n """คืนจำนวนครั้งที่หลัก 7 ปรากฏในจำนวนเต็มที่น้อยกว่า n ซึ่งหารด้วย 11 หรือ 13 ลงตัว\n >>> fizz_buzz(50)\n 0\n >>> fizz_buzz(78)\n 2\n >>> fizz_buzz(79)\n 3"""\n
ns = []\n for i in range(n):\n if i % 11 == 0 or i % 13 == 0:\n ns.append(i)\n s = ''.join(list(map(str, ns)))\n ans = 0\n for c in s:\n ans += (c == '7')\n return ans\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(50) == 0\n assert candidate(78) == 2\n assert candidate(79) == 3\n assert candidate(100) == 3\n assert candidate(200) == 6\n assert candidate(4000) == 192\n assert candidate(10000) == 639\n assert candidate(100000) == 8026\n\n
fizz_buzz
HumanEval\/37
\n\ndef sort_even(l: list):\n """ฟังก์ชันนี้ใช้รายการ l และส่งคืนรายการ l\' โดยที่ l\' จะเหมือนกับ l ในดัชนีคี่ ในขณะที่ค่าในดัชนีคู่จะเท่ากับค่าของดัชนีคู่ของ l แต่ได้รับการเรียงลำดับ\n >>> sort_even([1, 2, 3])\n [1, 2, 3]\n >>> sort_even([5, 6, 3, 4])\n [3, 6, 5, 4]"""\n
evens = l[::2]\n odds = l[1::2]\n evens.sort()\n ans = []\n for e, o in zip(evens, odds):\n ans.extend([e, o])\n if len(evens) > len(odds):\n ans.append(evens[-1])\n return ans\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert tuple(candidate([1, 2, 3])) == tuple([1, 2, 3])\n 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])\n assert tuple(candidate([5, 8, -12, 4, 23, 2, 3, 11, 12, -10])) == tuple([-12, 8, 3, 4, 5, ...
sort_even
HumanEval\/38
\n\ndef encode_cyclic(s: str):\n """ส่งคืนสตริงที่เข้ารหัสโดยการหมุนเวียนกลุ่มอักขระสามตัว\n """\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) \/\/ 3)]\n # cycle elements in each group. Unless group has fewer elements than 3.\n ...
return encode_cyclic(encode_cyclic(s))\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n from random import randint, choice\n import string\n\n letters = string.ascii_lowercase\n for _ in range(100):\n str = ''.join(choice(letters) for i in range(randint(10, 20)))\n encoded_str = encode_cyclic(str)\n assert candidate(encoded_st...
decode_cyclic
HumanEval\/39
\n\ndef prime_fib(n: int):\n """prime_fib คืนค่าตัวเลขที่ n ซึ่งเป็นตัวเลข Fibonacci และเป็นจำนวนเฉพาะด้วย\n >>> prime_fib(1)\n 2\n >>> prime_fib(2)\n 3\n >>> prime_fib(3)\n 5\n >>> prime_fib(4)\n 13\n >>> prime_fib(5)\n 89"""\n
import math\n\n def is_prime(p):\n if p < 2:\n return False\n for k in range(2, min(int(math.sqrt(p)) + 1, p - 1)):\n if p % k == 0:\n return False\n return True\n f = [0, 1]\n while True:\n f.append(f[-1] + f[-2])\n if is_prime(f[-1])...
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(1) == 2\n assert candidate(2) == 3\n assert candidate(3) == 5\n assert candidate(4) == 13\n assert candidate(5) == 89\n assert candidate(6) == 233\n assert candidate(7) == 1597\n assert candidate(8) == 28657\n assert candidate(9)...
prime_fib
HumanEval\/40
\n\ndef triples_sum_to_zero(l: list):\n """triples_sum_to_zero จะรับรายการจำนวนเต็มเป็นอินพุต โดยจะคืนค่า True หากมีองค์ประกอบที่แตกต่างกันสามองค์ประกอบในรายการที่ผลรวมเป็นศูนย์ และคืนค่า False หากไม่เป็นเช่นนั้น\n >>> triples_sum_to_zero([1, 3, 5, 0])\n False\n >>> triples_sum_to_zero([1, 3, -2, 1])\n T...
for i in range(len(l)):\n for j in range(i + 1, len(l)):\n for k in range(j + 1, len(l)):\n if l[i] + l[j] + l[k] == 0:\n return True\n return False\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 3, 5, 0]) == False\n assert candidate([1, 3, 5, -1]) == False\n assert candidate([1, 3, -2, 1]) == True\n assert candidate([1, 2, 3, 7]) == False\n assert candidate([1, 2, 5, 7]) == False\n assert candidate([2, 4, -5, 3, 9, 7]) == Tru...
triples_sum_to_zero
HumanEval\/41
\n\ndef car_race_collision(n: int):\n """ลองนึกภาพถนนที่ตรงและยาวไม่มีที่สิ้นสุด มีรถยนต์ n คันขับจากซ้ายไปขวา ในขณะเดียวกัน รถยนต์อีก n คันขับจากขวาไปซ้าย รถทั้งสองคันเริ่มอยู่ห่างกันมาก รถทุกคันเคลื่อนที่ด้วยความเร็วเท่ากัน กล่าวกันว่ารถสองคันจะชนกันเมื่อรถที่เคลื่อนที่จากซ้ายไปขวาชนกับรถที่เคลื่อนที่จากขวาไปซ้าย ...
return n**2\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(2) == 4\n assert candidate(3) == 9\n assert candidate(4) == 16\n assert candidate(8) == 64\n assert candidate(10) == 100\n\n
car_race_collision
HumanEval\/42
\n\ndef incr_list(l: list):\n """กลับรายการที่มีองค์ประกอบเพิ่มขึ้นทีละ 1\n >>> incr_list([1, 2, 3])\n [2, 3, 4]\n >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [6, 4, 6, 3, 4, 4, 10, 1, 124]"""\n
return [(e + 1) for e in l]\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([]) == []\n assert candidate([3, 2, 1]) == [4, 3, 2]\n assert candidate([5, 2, 5, 2, 3, 3, 9, 0, 123]) == [6, 3, 6, 3, 4, 4, 10, 1, 124]\n\n
incr_list
HumanEval\/43
\n\ndef pairs_sum_to_zero(l):\n """pairs_sum_to_zero จะรับรายการจำนวนเต็มเป็นอินพุต โดยจะคืนค่า True หากมีองค์ประกอบที่แตกต่างกันสององค์ประกอบในรายการซึ่งผลรวมเป็นศูนย์ และคืนค่า False หากไม่เป็นเช่นนั้น\n >>> pairs_sum_to_zero([1, 3, 5, 0])\n False\n >>> pairs_sum_to_zero([1, 3, -2, 1])\n False\n >>>...
for i, l1 in enumerate(l):\n for j in range(i + 1, len(l)):\n if l1 + l[j] == 0:\n return True\n return False\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 3, 5, 0]) == False\n assert candidate([1, 3, -2, 1]) == False\n assert candidate([1, 2, 3, 7]) == False\n assert candidate([2, 4, -5, 3, 5, 7]) == True\n assert candidate([1]) == False\n\n assert candidate([-3, 9, -1, 3, 2, 30]) == Tr...
pairs_sum_to_zero
HumanEval\/44
\n\ndef change_base(x: int, base: int):\n """เปลี่ยนฐานตัวเลขของเลขอินพุต x ให้เป็นฐาน ส่งคืนการแสดงสตริงหลังจากการแปลง เลขฐานน้อยกว่า 10\n >>> change_base(8, 3)\n '22'\n >>> change_base(8, 2)\n '1000'\n >>> change_base(7, 2)\n '111'"""\n
ret = ""\n while x > 0:\n ret = str(x % base) + ret\n x \/\/= base\n return ret\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(8, 3) == "22"\n assert candidate(9, 3) == "100"\n assert candidate(234, 2) == "11101010"\n assert candidate(16, 2) == "10000"\n assert candidate(8, 2) == "1000"\n assert candidate(7, 2) == "111"\n for x in range(2, 8):\n assert ...
change_base
HumanEval\/45
\n\ndef triangle_area(a, h):\n """กำหนดความยาวด้านและพื้นที่ส่งคืนสูงสำหรับสามเหลี่ยม\n >>> triangle_area(5, 3)\n 7.5"""\n
return a * h \/ 2.0\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(5, 3) == 7.5\n assert candidate(2, 2) == 2.0\n assert candidate(10, 8) == 40.0\n\n
triangle_area
HumanEval\/46
\n\ndef fib4(n: int):\n """ลำดับตัวเลข 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 อย่างมีประสิทธิภาพ อย่าใช้การเรียกซ้ำ\n >>> ...
results = [0, 0, 2, 0]\n if n < 4:\n return results[n]\n\n for _ in range(4, n + 1):\n results.append(results[-1] + results[-2] + results[-3] + results[-4])\n results.pop(0)\n\n return results[-1]\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(5) == 4\n assert candidate(8) == 28\n assert candidate(10) == 104\n assert candidate(12) == 386\n\n
fib4
HumanEval\/47
\n\ndef median(l: list):\n """คืนค่ามัธยฐานขององค์ประกอบในรายการ l\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 15.0"""\n
l = sorted(l)\n if len(l) % 2 == 1:\n return l[len(l) \/\/ 2]\n else:\n return (l[len(l) \/\/ 2 - 1] + l[len(l) \/\/ 2]) \/ 2.0\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([3, 1, 2, 4, 5]) == 3\n assert candidate([-10, 4, 6, 1000, 10, 20]) == 8.0\n assert candidate([5]) == 5\n assert candidate([6, 5]) == 5.5\n assert candidate([8, 1, 3, 9, 9, 2, 7]) == 7 \n\n
median
HumanEval\/48
\n\ndef is_palindrome(text: str):\n """ตรวจสอบว่าสตริงที่กำหนดเป็นพาลินโดรมหรือไม่\n >>> is_palindrome('')\n True\n >>> is_palindrome('aba')\n True\n >>> is_palindrome('aaaaa')\n True\n >>> is_palindrome('zbcd')\n False"""\n
for i in range(len(text)):\n if text[i] != text[len(text) - 1 - i]:\n return False\n return True\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate('') == True\n assert candidate('aba') == True\n assert candidate('aaaaa') == True\n assert candidate('zbcd') == False\n assert candidate('xywyx') == True\n assert candidate('xywyz') == False\n assert candidate('xywzx') == False\n\n
is_palindrome
HumanEval\/49
\n\ndef modp(n: int, p: int):\n """ส่งกลับ 2^n โมดูโล p (ระวังตัวเลข)\n >>> modp(3, 5)\n 3\n >>> modp(1101, 101)\n 2\n >>> modp(0, 101)\n 1\n >>> modp(3, 11)\n 8\n >>> modp(100, 101)\n 1"""\n
ret = 1\n for i in range(n):\n ret = (2 * ret) % p\n return ret\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(3, 5) == 3\n assert candidate(1101, 101) == 2\n assert candidate(0, 101) == 1\n assert candidate(3, 11) == 8\n assert candidate(100, 101) == 1\n assert candidate(30, 5) == 4\n assert candidate(31, 5) == 3\n\n
modp
HumanEval\/50
\n\ndef encode_shift(s: str):\n """ส่งคืนสตริงที่เข้ารหัสโดยการเลื่อนอักขระแต่ละตัวทีละ 5 ตัวในตัวอักษร\n """\n return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s])\n\n\ndef decode_shift(s: str):"""\n 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])\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n from random import randint, choice\n import copy\n import string\n\n letters = string.ascii_lowercase\n for _ in range(100):\n str = ''.join(choice(letters) for i in range(randint(10, 20)))\n encoded_str = encode_shift(str)\n assert cand...
decode_shift
HumanEval\/51
\n\ndef remove_vowels(text):\n """remove_vowels เป็นฟังก์ชันที่รับสตริงและส่งคืนสตริงโดยไม่มีสระ\n >>> remove_vowels('')\n ''\n >>> remove_vowels("abcdef\nghijklm")\n 'bcdf\nghjklm'\n >>> remove_vowels('abcdef')\n 'bcdf'\n >>> remove_vowels('aaaaa')\n ''\n >>> remove_vowels('aaBAA')\n '...
return "".join([s for s in text if s.lower() not in ["a", "e", "i", "o", "u"]])\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate('') == ''\n assert candidate("abcdef\nghijklm") == 'bcdf\nghjklm'\n assert candidate('fedcba') == 'fdcb'\n assert candidate('eeeee') == ''\n assert candidate('acBAA') == 'cB'\n assert candidate('EcBOO') == 'cB'\n assert candidate('ybcd...
remove_vowels
HumanEval\/52
\n\ndef below_threshold(l: list, t: int):\n """คืนค่า True ถ้าตัวเลขทั้งหมดในรายการ l ต่ำกว่าเกณฑ์ t\n >>> below_threshold([1, 2, 4, 10], 100)\n True\n >>> below_threshold([1, 20, 4, 10], 5)\n False"""\n
for e in l:\n if e >= t:\n return False\n return True\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 2, 4, 10], 100)\n assert not candidate([1, 20, 4, 10], 5)\n assert candidate([1, 20, 4, 10], 21)\n assert candidate([1, 20, 4, 10], 22)\n assert candidate([1, 8, 4, 10], 11)\n assert not candidate([1, 8, 4, 10], 10)\n\n
below_threshold
HumanEval\/53
\n\ndef add(x: int, y: int):\n """บวกเลขสองตัวคือ x และ y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12"""\n
return x + y\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n import random\n\n assert candidate(0, 1) == 1\n assert candidate(1, 0) == 1\n assert candidate(2, 3) == 5\n assert candidate(5, 7) == 12\n assert candidate(7, 5) == 12\n\n for i in range(100):\n x, y = random.randint(0, 1000), random.randint(0, ...
add
HumanEval\/54
\n\ndef same_chars(s0: str, s1: str):\n """ตรวจสอบว่าคำสองคำมีอักขระเดียวกันหรือไม่\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n True\n >>> same_chars('abcd', 'dddddddabc')\n True\n >>> same_chars('dddddddabc', 'abcd')\n True\n >>> same_chars('eabcd', 'dddddddabc')\n False\n >>> s...
return set(s0) == set(s1)\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate('eabcdzzzz', 'dddzzzzzzzddeddabc') == True\n assert candidate('abcd', 'dddddddabc') == True\n assert candidate('dddddddabc', 'abcd') == True\n assert candidate('eabcd', 'dddddddabc') == False\n assert candidate('abcd', 'dddddddabcf') == Fals...
same_chars
HumanEval\/55
\n\ndef fib(n: int):\n """ส่งคืนเลข Fibonacci อันดับที่ n\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21"""\n
if n == 0:\n return 0\n if n == 1:\n return 1\n return fib(n - 1) + fib(n - 2)\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(10) == 55\n assert candidate(1) == 1\n assert candidate(8) == 21\n assert candidate(11) == 89\n assert candidate(12) == 144\n\n
fib
HumanEval\/56
\n\ndef correct_bracketing(brackets: str):\n """วงเล็บเป็นสตริงของ "<" และ ">" คืนค่า True หากวงเล็บเปิดทุกอันมีวงเล็บปิดที่สอดคล้องกัน\n >>> correct_bracketing("<")\n False\n >>> correct_bracketing("<>")\n True\n >>> correct_bracketing("<<><>>")\n True\n >>> correct_bracketing("><<>")\n Fals...
depth = 0\n for b in brackets:\n if b == "<":\n depth += 1\n else:\n depth -= 1\n if depth < 0:\n return False\n return depth == 0\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate("<>")\n assert candidate("<<><>>")\n assert candidate("<><><<><>><>")\n assert candidate("<><><<<><><>><>><<><><<>>>")\n assert not candidate("<<<><>>>>")\n assert not candidate("><<>")\n assert not candidate("<")\n assert not candi...
correct_bracketing
HumanEval\/57
\n\ndef monotonic(l: list):\n """ค่า Return True คือองค์ประกอบของรายการที่มีการเพิ่มขึ้นหรือลดลงแบบเอกภาพ\n >>> monotonic([1, 2, 4, 20])\n True\n >>> monotonic([1, 20, 4, 10])\n False\n >>> monotonic([4, 1, 0, -10])\n True"""\n
if l == sorted(l) or l == sorted(l, reverse=True):\n return True\n return False\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 2, 4, 10]) == True\n assert candidate([1, 2, 4, 20]) == True\n assert candidate([1, 20, 4, 10]) == False\n assert candidate([4, 1, 0, -10]) == True\n assert candidate([4, 1, 1, 0]) == True\n assert candidate([1, 2, 3, 2, 5, 60]) == Fa...
monotonic
HumanEval\/58
\n\ndef common(l1: list, l2: list):\n """ส่งคืนองค์ประกอบทั่วไปที่ไม่ซ้ำกันที่เรียงลำดับสำหรับสองรายการ\n >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n [1, 5, 653]\n >>> common([5, 3, 2, 8], [3, 2])\n [2, 3]\n"""\n
ret = set()\n for e1 in l1:\n for e2 in l2:\n if e1 == e2:\n ret.add(e1)\n return sorted(list(ret))\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]\n assert candidate([5, 3, 2, 8], [3, 2]) == [2, 3]\n assert candidate([4, 3, 2, 8], [3, 2, 4]) == [2, 3, 4]\n assert candidate([4, 3, 2, 8], []) == []\n\n
common
HumanEval\/59
\n\ndef largest_prime_factor(n: int):\n """ส่งคืนตัวประกอบเฉพาะที่ใหญ่ที่สุดของ n ถือว่า n > 1 และไม่ใช่ตัวประกอบเฉพาะ\n >>> largest_prime_factor(13195)\n 29\n >>> largest_prime_factor(2048)\n 2"""\n
def is_prime(k):\n if k < 2:\n return False\n for i in range(2, k - 1):\n if k % i == 0:\n return False\n return True\n largest = 1\n for j in range(2, n + 1):\n if n % j == 0 and is_prime(j):\n largest = max(largest, j)\n return l...
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(15) == 5\n assert candidate(27) == 3\n assert candidate(63) == 7\n assert candidate(330) == 11\n assert candidate(13195) == 29\n\n
largest_prime_factor
HumanEval\/60
\n\ndef sum_to_n(n: int):\n """sum_to_n คือฟังก์ชันที่หาผลรวมของตัวเลขตั้งแต่ 1 ถึง n\n >>> sum_to_n(30)\n 465\n >>> sum_to_n(100)\n 5050\n >>> sum_to_n(5)\n 15\n >>> sum_to_n(10)\n 55\n >>> sum_to_n(1)\n 1"""\n
return sum(range(n + 1))\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(1) == 1\n assert candidate(6) == 21\n assert candidate(11) == 66\n assert candidate(30) == 465\n assert candidate(100) == 5050\n\n
sum_to_n
HumanEval\/61
\n\ndef correct_bracketing(brackets: str):\n """วงเล็บเป็นสตริงของ "(" และ ")" คืนค่า True หากวงเล็บเปิดทุกอันมีวงเล็บปิดที่สอดคล้องกัน\n >>> correct_bracketing("(")\n False\n >>> correct_bracketing("()")\n True\n >>> correct_bracketing("(()())")\n True\n >>> correct_bracketing(")(()")\n Fals...
depth = 0\n for b in brackets:\n if b == "(":\n depth += 1\n else:\n depth -= 1\n if depth < 0:\n return False\n return depth == 0\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate("()")\n assert candidate("(()())")\n assert candidate("()()(()())()")\n assert candidate("()()((()()())())(()()(()))")\n assert not candidate("((()())))")\n assert not candidate(")(()")\n assert not candidate("(")\n assert not candi...
correct_bracketing
HumanEval\/62
\n\ndef derivative(xs: list):\n """xs แทนค่าสัมประสิทธิ์ของพหุนาม xs[0] + xs[1] * x + xs[2] * x^2 + .... ส่งกลับอนุพันธ์ของพหุนามนี้ในรูปแบบเดียวกัน\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]"""\n
return [(i * x) for i, x in enumerate(xs)][1:]\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([3, 1, 2, 4, 5]) == [1, 4, 12, 20]\n assert candidate([1, 2, 3]) == [2, 6]\n assert candidate([3, 2, 1]) == [2, 2]\n assert candidate([3, 2, 1, 0, 4]) == [2, 2, 0, 16]\n assert candidate([1]) == []\n\n
derivative
HumanEval\/63
\n\ndef fibfib(n: int):\n """ลำดับตัวเลข FibFib เป็นลำดับที่คล้ายกับลำดับ Fibbonacci ซึ่งกำหนดดังนี้: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3) โปรดเขียนฟังก์ชันเพื่อคำนวณองค์ประกอบที่ n ของลำดับตัวเลข FibFib อย่างมีประสิทธิภาพ\n >>> fibfib(1)\n 0\n >>...
if n == 0:\n return 0\n if n == 1:\n return 0\n if n == 2:\n return 1\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3)\n
\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(2) == 1\n assert candidate(1) == 0\n assert candidate(5) == 4\n assert candidate(8) == 24\n assert candidate(10) == 81\n assert candidate(12) == 274\n assert candidate(14) == 927\n\n
fibfib
HumanEval\/64
\nFIX = """\nAdd more test cases.\n"""\n\ndef vowels_count(s):\n """เขียนฟังก์ชัน vowels_count ซึ่งรับสตริงที่แสดงคำเป็นอินพุตและส่งคืนจำนวนสระในสตริง สระในกรณีนี้คือ \'a\', \'e\', \'i\', \'o\', \'u\' ในที่นี้ \'y\' ก็เป็นสระเช่นกัน แต่จะต้องอยู่ท้ายคำที่กำหนดเท่านั้น ตัวอย่าง:\n >>> vowels_count("abcde")\n 2\...
vowels = "aeiouAEIOU"\n n_vowels = sum(c in vowels for c in s)\n if s[-1] == 'y' or s[-1] == 'Y':\n n_vowels += 1\n return n_vowels\n
def check(candidate):\n\n # Check some simple cases\n assert candidate("abcde") == 2, "Test 1"\n assert candidate("Alone") == 3, "Test 2"\n assert candidate("key") == 2, "Test 3"\n assert candidate("bye") == 1, "Test 4"\n assert candidate("keY") == 2, "Test 5"\n assert candidate("bYe") == 1, "Test ...
vowels_count
HumanEval\/65
\ndef circular_shift(x, shift):\n """การเลื่อนตัวเลขของจำนวนเต็ม x แบบวงกลม เลื่อนตัวเลขไปทางขวาโดยการเลื่อน แล้วส่งคืนผลลัพธ์เป็นสตริง หากการเลื่อน > จำนวนตัวเลข ให้ส่งคืนตัวเลขที่ย้อนกลับ\n >>> circular_shift(12, 1)\n "21"\n >>> circular_shift(12, 2)\n "12""""\n
s = str(x)\n if shift > len(s):\n return s[::-1]\n else:\n return s[len(s) - shift:] + s[:len(s) - shift]\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(100, 2) == "001"\n assert candidate(12, 2) == "12"\n assert candidate(97, 8) == "79"\n assert candidate(12, 1) == "21", "This prints if this assert fails 1 (good for debugging!)"\n\n # Check some edge cases that are easy to work ou...
circular_shift
HumanEval\/66
\ndef digitSum(s):\n """งาน เขียนฟังก์ชันที่รับสตริงเป็นอินพุตและส่งคืนผลรวมของรหัส ASCII ของอักขระตัวบนเท่านั้น ตัวอย่าง: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abcCd") => 67 digitSum("helloE") => 69 digitSum("woArBld") => 131 digitSum("aAaaaXa") => 153\n """\n
if s == "": return 0\n return sum(ord(char) if char.isupper() else 0 for char in s)\n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate("") == 0, "Error"\n assert candidate("abAB") == 131, "Error"\n assert candidate("abcCd") == 67, "Error"\n assert candidate("helloE") == 69, "Error"\n asse...
digitSum
HumanEval\/67
\ndef fruit_distribution(s,n):\n """ในงานนี้ คุณจะได้รับสตริงที่แสดงถึงจำนวนแอปเปิ้ลและส้มที่กระจายอยู่ในตะกร้าผลไม้ ตะกร้านี้ประกอบด้วยแอปเปิ้ล ส้ม และมะม่วง เมื่อกำหนดสตริงที่แสดงถึงจำนวนส้มและแอปเปิ้ลทั้งหมด และจำนวนเต็มที่แสดงถึงจำนวนผลไม้ทั้งหมดในตะกร้า ให้ส่งคืนจำนวนผลมะม่วงในตะกร้า ตัวอย่างเช่น fruit_distribu...
lis = list()\n for i in s.split(' '):\n if i.isdigit():\n lis.append(int(i))\n return n - sum(lis)\n
def check(candidate):\n\n # Check some simple cases\n assert candidate("5 apples and 6 oranges",19) == 8\n assert candidate("5 apples and 6 oranges",21) == 10\n assert candidate("0 apples and 1 oranges",3) == 2\n assert candidate("1 apples and 0 oranges",3) == 2\n assert candidate("2 apples and 3 oran...
fruit_distribution
HumanEval\/68
\ndef pluck(arr):\n """"เมื่อกำหนดอาร์เรย์ที่แสดงถึงสาขาของต้นไม้ที่มีโหนดจำนวนเต็มที่ไม่เป็นลบ งานของคุณคือเลือกโหนดหนึ่งและส่งคืน โหนดที่คัดมาควรเป็นโหนดที่มีค่าคู่ที่เล็กที่สุด หากพบโหนดหลายโหนดที่มีค่าคู่ที่เล็กที่สุดเท่ากัน ให้ส่งคืนโหนดที่มีดัชนีที่เล็กที่สุด โหนดที่คัดมาควรส่งคืนในรายการ [ smalest_value, ดัชน...
if(len(arr) == 0): return []\n evens = list(filter(lambda x: x%2 == 0, arr))\n if(evens == []): return []\n return [min(evens), arr.index(min(evens))]\n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([4,2,3]) == [2, 1], "Error"\n assert candidate([1,2,3]) == [2, 1], "Error"\n assert candidate([]) == [], "Error"\n assert candidate([5, 0, 3, 0, 4, 2]) == [0...
pluck
HumanEval\/69
\ndef search(lst):\n '''คุณจะได้รับรายการจำนวนเต็มบวกที่ไม่ว่าง ส่งคืนจำนวนเต็มที่มากที่สุดที่มากกว่าศูนย์และมีความถี่มากกว่าหรือเท่ากับค่าของจำนวนเต็มนั้นเอง ความถี่ของจำนวนเต็มคือจำนวนครั้งที่จำนวนเต็มนั้นปรากฏในรายการ หากไม่มีค่าดังกล่าว ให้ส่งคืน -1 ตัวอย่าง: search([4, 1, 2, 2, 3, 1]) == 2 search([1, 2, 2, 3, 3...
frq = [0] * (max(lst) + 1)\n for i in lst:\n frq[i] += 1;\n\n ans = -1\n for i in range(1, len(frq)):\n if frq[i] >= i:\n ans = i\n \n return ans\n
def check(candidate):\n\n # manually generated tests\n assert candidate([5, 5, 5, 5, 1]) == 1\n assert candidate([4, 1, 4, 1, 4, 4]) == 4\n assert candidate([3, 3]) == -1\n assert candidate([8, 8, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate([2, 3, 3, 2, 2]) == 2\n\n # automatically generated tests\n...
search
HumanEval\/70
\ndef strange_sort_list(lst):\n '''กำหนดให้รายการจำนวนเต็มแสดงรายการในลำดับที่แปลกประหลาด การเรียงลำดับที่แปลกประหลาดคือเมื่อคุณเริ่มต้นด้วยค่าต่ำสุด จากนั้นจึงเป็นค่าสูงสุดของจำนวนเต็มที่เหลือ จากนั้นจึงเป็นค่าต่ำสุด และเป็นเช่นนี้ไปเรื่อยๆ ตัวอย่าง: strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3] strange_sort_list...
res, switch = [], True\n while lst:\n res.append(min(lst) if switch else max(lst))\n lst.remove(res[-1])\n switch = not switch\n return res\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3]\n assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]\n assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]\n assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]\n assert candidate([5, 5, 5, 5...
strange_sort_list
HumanEval\/71
\ndef triangle_area(a, b, c):\n '''กำหนดความยาวของด้านทั้งสามของสามเหลี่ยม ส่งคืนพื้นที่ของสามเหลี่ยมที่ปัดเศษเป็นทศนิยม 2 ตำแหน่งหากด้านทั้งสามประกอบเป็นสามเหลี่ยมที่ถูกต้อง มิฉะนั้น ส่งคืน -1 ด้านทั้งสามประกอบเป็นสามเหลี่ยมที่ถูกต้องเมื่อผลรวมของด้านสองด้านใดๆ มากกว่าด้านที่สาม ตัวอย่าง: triangle_area(3, 4, 5) == ...
if a + b <= c or a + c <= b or b + c <= a:\n return -1 \n s = (a + b + c)\/2 \n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5\n area = round(area, 2)\n return area\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(3, 4, 5) == 6.00, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(1, 2, 10) == -1\n assert candidate(4, 8, 5) == 8.18\n assert candidate(2, 2, 2) == 1.73\n assert candidate(1, 2, 3) == -1\n assert c...
triangle_area
HumanEval\/72
\ndef will_it_fly(q,w):\n '''เขียนฟังก์ชันที่คืนค่า True หากวัตถุ q จะบิน และคืนค่า False หากไม่เป็นเช่นนั้น วัตถุ q จะบินได้หากมีความสมดุล (เป็นรายการพาลินโดรม) และผลรวมขององค์ประกอบน้อยกว่าหรือเท่ากับน้ำหนักสูงสุดที่เป็นไปได้ w ตัวอย่าง: will_it_fly([1, 2], 5) ➞ False # 1+2 น้อยกว่าน้ำหนักสูงสุดที่เป็นไปได้ แต่ไม่...
if sum(q) > w:\n return False\n\n i, j = 0, len(q)-1\n while i<j:\n if q[i] != q[j]:\n return False\n i+=1\n j-=1\n return True\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([3, 2, 3], 9) is True\n assert candidate([1, 2], 5) is False\n assert candidate([3], 5) is True\n assert candidate([3, 2, 3], 1) is False\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1, 2,...
will_it_fly
HumanEval\/73
\ndef smallest_change(arr):\n """กำหนดอาร์เรย์ arr ของจำนวนเต็ม หาจำนวนองค์ประกอบน้อยที่สุดที่ต้องเปลี่ยนแปลงเพื่อให้เป็นอาร์เรย์พาลินโดรม อาร์เรย์พาลินโดรมคืออาร์เรย์ที่อ่านค่าแบบเดียวกันทั้งไปข้างหน้าและข้างหลัง ในการเปลี่ยนแปลงหนึ่งครั้ง คุณสามารถเปลี่ยนองค์ประกอบหนึ่งเป็นองค์ประกอบอื่นใดก็ได้ ตัวอย่างเช่น: small...
ans = 0\n for i in range(len(arr) \/\/ 2):\n if arr[i] != arr[len(arr) - i - 1]:\n ans += 1\n return ans\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,3,5,4,7,9,6]) == 4\n assert candidate([1, 2, 3, 4, 3, 2, 2]) == 1\n assert candidate([1, 4, 2]) == 1\n assert candidate([1, 4, 4, 2]) == 1\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1...
smallest_change
HumanEval\/74
\ndef total_match(lst1, lst2):\n '''เขียนฟังก์ชันที่ยอมรับรายการสตริงสองรายการและส่งคืนรายการที่มีจำนวนอักขระทั้งหมดในสตริงทั้งหมดของรายการน้อยกว่ารายการอื่น ถ้ารายการทั้งสองมีจำนวนอักขระเท่ากัน ให้ส่งคืนรายการแรก ตัวอย่าง total_match([], []) ➞ [] total_match([\'hi\', \'admin\'], [\'hI\', \'Hi\']) ➞ [\'hI\', \'Hi\']...
l1 = 0\n for st in lst1:\n l1 += len(st)\n \n l2 = 0\n for st in lst2:\n l2 += len(st)\n \n if l1 <= l2:\n return lst1\n else:\n return lst2\n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([], []) == []\n assert candidate(['hi', 'admin'], ['hi', 'hi']) == ['hi', 'hi']\n assert candidate(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) == ['hi', ...
total_match
HumanEval\/75
\ndef is_multiply_prime(a):\n """เขียนฟังก์ชันที่คืนค่าเป็นจริงหากตัวเลขที่กำหนดคือการคูณจำนวนเฉพาะ 3 จำนวน และคืนค่าเท็จหากไม่ใช่ โดยทราบว่า (a) น้อยกว่า 100 ตัวอย่าง: is_multiply_prime(30) == True 30 = 2 * 3 * 5\n """\n
def is_prime(n):\n for j in range(2,n):\n if n%j == 0:\n return False\n return True\n\n for i in range(2,101):\n if not is_prime(i): continue\n for j in range(2,101):\n if not is_prime(j): continue\n for k in range(2,101):\n ...
def check(candidate):\n\n assert candidate(5) == False\n assert candidate(30) == True\n assert candidate(8) == True\n assert candidate(10) == False\n assert candidate(125) == True\n assert candidate(3 * 5 * 7) == True\n assert candidate(3 * 6 * 7) == False\n assert candidate(9 * 9 * 9) == False\...
is_multiply_prime
HumanEval\/76
\ndef is_simple_power(x, n):\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 i...
if (n == 1): \n return (x == 1) \n power = 1\n while (power < x): \n power = power * n \n return (power == x) \n
def check(candidate):\n\n # Check some simple cases\n assert candidate(16, 2)== True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(143214, 16)== False, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(4, 2)==True, "This prints if this assert fail...
is_simple_power
HumanEval\/77
\ndef iscube(a):\n '''เขียนฟังก์ชันที่รับจำนวนเต็ม a และส่งคืนค่า True หากจำนวนเต็มนี้เป็นกำลังสามของจำนวนเต็มบางตัว หมายเหตุ: คุณอาจถือว่าอินพุตนั้นถูกต้องเสมอ ตัวอย่าง: iscube(1) ==> True iscube(2) ==> False iscube(-1) ==> True iscube(64) ==> True iscube(0) ==> True iscube(180) ==> False\n '''\n
a = abs(a)\n return int(round(a ** (1. \/ 3))) ** 3 == a\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(1) == True, "First test error: " + str(candidate(1))\n assert candidate(2) == False, "Second test error: " + str(candidate(2))\n assert candidate(-1) == True, "Third test error: " + str(candidate(-1))\n assert candidate(64) == True, "...
iscube
HumanEval\/78
\ndef hex_key(num):\n """คุณได้รับมอบหมายให้เขียนฟังก์ชันที่รับเลขฐานสิบหกเป็นสตริงและนับจำนวนหลักฐานสิบหกที่เป็นจำนวนเฉพาะ (จำนวนเฉพาะหรือจำนวนเฉพาะคือจำนวนธรรมชาติที่มากกว่า 1 ซึ่งไม่ใช่ผลคูณของจำนวนธรรมชาติที่เล็กกว่าสองตัว) หลักฐานสิบหกคือ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F จำนวนเฉพาะคือ 2, 3, 5, 7, ...
primes = ('2', '3', '5', '7', 'B', 'D')\n total = 0\n for i in range(0, len(num)):\n if num[i] in primes:\n total += 1\n return total\n
def check(candidate):\n\n # Check some simple cases\n assert candidate("AB") == 1, "First test error: " + str(candidate("AB")) \n assert candidate("1077E") == 2, "Second test error: " + str(candidate("1077E")) \n assert candidate("ABED1A33") == 4, "Third test error: " + str(candidate("ABED1A33")) ...
hex_key
HumanEval\/79
\ndef decimal_to_binary(decimal):\n """คุณจะได้รับตัวเลขในรูปแบบทศนิยม และงานของคุณคือการแปลงตัวเลขดังกล่าวเป็นรูปแบบไบนารี ฟังก์ชันควรส่งคืนสตริง โดยแต่ละอักขระจะแสดงเป็นเลขฐานสอง อักขระแต่ละตัวในสตริงจะเป็น "0" หรือ "1" โดยจะมีอักขระพิเศษอีกสองตัวคือ "db" ที่จุดเริ่มต้นและจุดสิ้นสุดของสตริง อักขระพิเศษเหล่านี้จะช่...
return "db" + bin(decimal)[2:] + "db"\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(0) == "db0db"\n assert candidate(32) == "db100000db"\n assert candidate(103) == "db1100111db"\n assert candidate(15) == "db1111db", "This prints if this assert fails 1 (good for debugging!)"\n\n # Check some edge cases that are eas...
decimal_to_binary
HumanEval\/80
\ndef is_happy(s):\n """คุณจะได้รับสตริง 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) => ...
if len(s) < 3:\n return False\n\n for i in range(len(s) - 2):\n \n if s[i] == s[i+1] or s[i+1] == s[i+2] or s[i] == s[i+2]:\n return False\n return True\n
def check(candidate):\n\n # Check some simple cases\n assert candidate("a") == False , "a"\n assert candidate("aa") == False , "aa"\n assert candidate("abcd") == True , "abcd"\n assert candidate("aabb") == False , "aabb"\n assert candidate("adb") == True , "adb"\n assert candidate("xyy") == False ,...
is_happy
HumanEval\/81
\ndef numerical_letter_grade(grades):\n """ตอนนี้เป็นสัปดาห์สุดท้ายของภาคการศึกษาและครูต้องให้เกรดกับนักเรียน ครูได้สร้างอัลกอริทึมสำหรับการให้เกรดของเธอเอง ปัญหาเดียวคือ ครูทำรหัสที่ใช้ในการให้เกรดหายไป ครูได้ให้รายการ GPA ของนักเรียนบางคนแก่คุณ และคุณต้องเขียนฟังก์ชันที่สามารถแสดงรายการเกรดเป็นตัวอักษรโดยใช้ตารางต...
\n \n letter_grade = []\n for gpa in grades:\n if gpa == 4.0:\n letter_grade.append("A+")\n elif gpa > 3.7:\n letter_grade.append("A")\n elif gpa > 3.3:\n letter_grade.append("A-")\n elif gpa > 3.0:\n letter_grade.append("B+")\n elif...
def check(candidate):\n\n # Check some simple cases\n assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']\n assert candidate([1.2]) == ['D+']\n assert candidate([0.5]) == ['D-']\n assert candidate([0.0]) == ['E']\n assert candidate([1, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B',...
numerical_letter_grade
HumanEval\/82
\ndef prime_length(string):\n """เขียนฟังก์ชันที่รับสตริงและส่งคืน True หากความยาวสตริงเป็นจำนวนเฉพาะหรือส่งคืน False หากไม่เช่นนั้น ตัวอย่าง prime_length(\'Hello\') == True prime_length(\'abcdcba\') == True prime_length(\'kittens\') == True prime_length(\'orange\') == False\n """\n
l = len(string)\n if l == 0 or l == 1:\n return False\n for i in range(2, l):\n if l % i == 0:\n return False\n return True\n
def check(candidate):\n\n # Check some simple cases\n assert candidate('Hello') == True\n assert candidate('abcdcba') == True\n assert candidate('kittens') == True\n assert candidate('orange') == False\n assert candidate('wow') == True\n assert candidate('world') == True\n assert candidate('Mada...
prime_length
HumanEval\/83
\ndef starts_one_ends(n):\n """กำหนดจำนวนเต็มบวก n ให้ส่งคืนจำนวนเต็มบวก n หลักที่เริ่มต้นหรือลงท้ายด้วย 1\n """\n
if n == 1: return 1\n return 18 * (10 ** (n - 2))\n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(1) == 1\n assert candidate(2) == 18\n assert candidate(3) == 180\n assert candidate(4) == 1800\n assert candidate(5) == 18000\n\n # Check some edge cas...
starts_one_ends
HumanEval\/84
\ndef solve(N):\n """กำหนดจำนวนเต็มบวก N ให้ส่งคืนผลรวมทั้งหมดของตัวเลขในรูปแบบไบนารี ตัวอย่าง สำหรับ N = 1000 ผลรวมของตัวเลขจะเท่ากับ 1 ผลลัพธ์ควรเป็น "1" สำหรับ N = 150 ผลรวมของตัวเลขจะเท่ากับ 6 ผลลัพธ์ควรเป็น "110" สำหรับ N = 147 ผลรวมของตัวเลขจะเท่ากับ 12 ผลลัพธ์ควรเป็น "1100" ตัวแปร: @N จำนวนเต็ม ข้อจำกัด: 0 ≤ ...
return bin(sum(int(i) for i in str(N)))[2:]\n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(1000) == "1", "Error"\n assert candidate(150) == "110", "Error"\n assert candidate(147) == "1100", "Error"\n\n # Check some edge cases that are easy to work ...
solve
HumanEval\/85
\ndef add(lst):\n """กำหนดรายการจำนวนเต็มที่ไม่ว่าง lst. เพิ่มองค์ประกอบคู่ที่มีดัชนีคี่ ตัวอย่าง: add([4, 2, 6, 7]) ==> 2\n """\n
return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0])\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([4, 88]) == 88\n assert candidate([4, 5, 6, 7, 2, 122]) == 122\n assert candidate([4, 0, 6, 7]) == 0\n assert candidate([4, 4, 6, 8]) == 12\n\n # Check some edge cases that are easy to work out by hand.\n \n
add
HumanEval\/86
\ndef anti_shuffle(s):\n """เขียนฟังก์ชันที่รับสตริงและส่งคืนเวอร์ชันที่เรียงลำดับของสตริงนั้น เวอร์ชันที่เรียงลำดับของสตริงคือสตริงที่คำทั้งหมด (คั่นด้วยช่องว่าง) จะถูกแทนที่ด้วยคำใหม่ โดยที่อักขระทั้งหมดจะเรียงตามลำดับจากน้อยไปมากตามค่า ASCII หมายเหตุ: คุณควรคงลำดับของคำและช่องว่างในประโยคไว้ ตัวอย่างเช่น: anti_sh...
return ' '.join([''.join(sorted(list(i))) for i in s.split(' ')])\n
def check(candidate):\n\n # Check some simple cases\n assert candidate('Hi') == 'Hi'\n assert candidate('hello') == 'ehllo'\n assert candidate('number') == 'bemnru'\n assert candidate('abcd') == 'abcd'\n assert candidate('Hello World!!!') == 'Hello !!!Wdlor'\n assert candidate('') == ''\n assert...
anti_shuffle
HumanEval\/87
\ndef get_row(lst, x):\n """คุณจะได้รับข้อมูล 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]\n return sorted(sorted(coords, key=lambda x: x[1], reverse=True), key=lambda x: x[0])\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n assert candidate([\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5...
get_row
HumanEval\/88
\ndef sort_array(array):\n """กำหนดอาร์เรย์ของจำนวนเต็มที่ไม่เป็นลบ ให้ส่งคืนสำเนาของอาร์เรย์ที่กำหนดหลังจากการเรียงลำดับ คุณจะเรียงลำดับอาร์เรย์ที่กำหนดในลำดับจากน้อยไปมาก หากผลรวม (ค่าดัชนีแรก ค่าดัชนีสุดท้าย) เป็นเลขคี่ หรือเรียงลำดับในลำดับจากมากไปน้อย หากผลรวม (ค่าดัชนีแรก ค่าดัชนีสุดท้าย) เป็นเลขคู่ หมายเหตุ: ...
return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0) \n
def check(candidate):\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([]) == [], "Error"\n assert candidate([5]) == [5], "Error"\n assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5], "Error"\n assert candidate([2, 4, 3,...
sort_array
HumanEval\/89
\ndef encrypt(s):\n """สร้างฟังก์ชัน encrypt ที่รับสตริงเป็นอาร์กิวเมนต์และส่งคืนสตริงที่เข้ารหัสด้วยตัวอักษรที่หมุน ตัวอักษรควรหมุนในลักษณะที่ตัวอักษรเลื่อนลงสองคูณสองตำแหน่ง ตัวอย่างเช่น: encrypt(\'hi\') ส่งคืน \'lm\' encrypt(\'asdfghjkl\') ส่งคืน \'ewhjklnop\' encrypt(\'gf\') ส่งคืน \'kj\' encrypt(\'et\') ส่งคืน ...
d = 'abcdefghijklmnopqrstuvwxyz'\n out = ''\n for c in s:\n if c in d:\n out += d[(d.index(c)+2*2) % 26]\n else:\n out += c\n return out\n
def check(candidate):\n\n # Check some simple cases\n assert candidate('hi') == 'lm', "This prints if this assert fails 1 (good for debugging!)"\n assert candidate('asdfghjkl') == 'ewhjklnop', "This prints if this assert fails 1 (good for debugging!)"\n assert candidate('gf') == 'kj', "This prints if this a...
encrypt
HumanEval\/90
\ndef next_smallest(lst):\n """คุณจะได้รับรายการจำนวนเต็ม เขียนฟังก์ชัน 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\n """\n
lst = sorted(set(lst))\n return None if len(lst) < 2 else lst[1]\n
def check(candidate):\n\n # Check some simple cases\n assert candidate([1, 2, 3, 4, 5]) == 2\n assert candidate([5, 1, 4, 3, 2]) == 2\n assert candidate([]) == None\n assert candidate([1, 1]) == None\n assert candidate([1,1,1,1,0]) == 1\n assert candidate([1, 0**0]) == None\n assert candidate([-...
next_smallest
HumanEval\/91
\ndef is_bored(S):\n """คุณจะได้รับคำจำนวนหนึ่ง และงานของคุณคือนับจำนวนความเบื่อหน่าย ความเบื่อหน่ายคือประโยคที่เริ่มต้นด้วยคำว่า "I" ประโยคจะถูกคั่นด้วย \'.\', \'?\' หรือ \'!\' ตัวอย่างเช่น:\n >>> is_bored("Hello world")\n 0\n >>> is_bored("The sky is blue. The sun is shining. I love this weather")\n 1"...
import re\n sentences = re.split(r'[.?!]\s*', S)\n return sum(sentence[0:2] == 'I ' for sentence in sentences)\n
def check(candidate):\n\n # Check some simple cases\n assert candidate("Hello world") == 0, "Test 1"\n assert candidate("Is the sky blue?") == 0, "Test 2"\n assert candidate("I love It !") == 1, "Test 3"\n assert candidate("bIt") == 0, "Test 4"\n assert candidate("I feel good today. I will be producti...
is_bored
HumanEval\/92
\ndef any_int(x, y, z):\n '''สร้างฟังก์ชันที่ใช้ตัวเลข 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\n '''\n
\n if isinstance(x,int) and isinstance(y,int) and isinstance(z,int):\n if (x+y==z) or (x+z==y) or (y+z==x):\n return True\n return False\n return False\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(2, 3, 1)==True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(2.5, 2, 3)==False, "This prints if this assert fails 2 (good for debugging!)"\n assert candidate(1.5, 5, 3.5)==False, "This prints if this asse...
any_int
HumanEval\/93
\ndef encode(message):\n """จงเขียนฟังก์ชันที่รับข้อความและเข้ารหัสโดยเปลี่ยนตัวพิมพ์ใหญ่-เล็กของตัวอักษรทั้งหมด และแทนที่สระทั้งหมดในข้อความด้วยตัวอักษรที่ปรากฏอยู่ข้างหน้าสระนั้น 2 ตำแหน่งในตัวอักษรภาษาอังกฤษ โดยถือว่ามีเฉพาะตัวอักษรเท่านั้น ตัวอย่าง:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a ...
vowels = "aeiouAEIOU"\n vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels])\n message = message.swapcase()\n return ''.join([vowels_replace[i] if i in vowels else i for i in message])\n
def check(candidate):\n\n # Check some simple cases\n assert candidate('TEST') == 'tgst', "This prints if this assert fails 1 (good for debugging!)"\n assert candidate('Mudasir') == 'mWDCSKR', "This prints if this assert fails 2 (good for debugging!)"\n assert candidate('YES') == 'ygs', "This prints if this...
encode
HumanEval\/94
\n\ndef skjkasdkd(lst):\n """คุณจะได้รับรายการจำนวนเต็ม คุณต้องค้นหาค่าเฉพาะที่ใหญ่ที่สุดและส่งคืนผลรวมของตัวเลขเหล่านั้น ตัวอย่าง: สำหรับ 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,...
def isPrime(n):\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n return False\n\n return True\n maxx = 0\n i = 0\n while i < len(lst):\n if(lst[i] > maxx and isPrime(lst[i])):\n maxx = lst[i]\n i+=1\n result = sum(int(digit) for digit in ...
def check(candidate):\n\n # Check some simple cases\n 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!)"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,...
skjkasdkd
HumanEval\/95
\ndef check_dict_case(dict):\n """ให้พจนานุกรมส่งกลับค่า True หากคีย์ทั้งหมดเป็นสตริงตัวพิมพ์เล็กหรือคีย์ทั้งหมดเป็นสตริงตัวพิมพ์ใหญ่ มิฉะนั้นให้ส่งกลับค่า False ฟังก์ชันควรส่งกลับค่า False หากพจนานุกรมที่กำหนดว่างเปล่า ตัวอย่าง: check_dict_case({"a":"apple", "b":"banana"}) ควรส่งกลับค่า True check_dict_case({"a":"a...
if len(dict.keys()) == 0:\n return False\n else:\n state = "start"\n for key in dict.keys():\n\n if isinstance(key, str) == False:\n state = "mixed"\n break\n if state == "start":\n if key.isupper():\n stat...
def check(candidate):\n\n # Check some simple cases\n assert candidate({"p":"pineapple", "b":"banana"}) == True, "First test error: " + str(candidate({"p":"pineapple", "b":"banana"}))\n assert candidate({"p":"pineapple", "A":"banana", "B":"banana"}) == False, "Second test error: " + str(candidate({"p":"pineapp...
check_dict_case
HumanEval\/96
\ndef count_up_to(n):\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 = []\n for i in range(2, n):\n is_prime = True\n for j in range(2, i):\n if i % j == 0:\n is_prime = False\n break\n if is_prime:\n primes.append(i)\n return primes\n\n
def check(candidate):\n\n assert candidate(5) == [2,3]\n assert candidate(6) == [2,3,5]\n assert candidate(7) == [2,3,5]\n assert candidate(10) == [2,3,5,7]\n assert candidate(0) == []\n assert candidate(22) == [2,3,5,7,11,13,17,19]\n assert candidate(1) == []\n assert candidate(18) == [2,3,5,7,...
count_up_to
HumanEval\/97
\ndef multiply(a, b):\n """ดำเนินการฟังก์ชันที่รับจำนวนเต็มสองจำนวนและส่งคืนผลคูณของหลักหน่วยของจำนวนเต็มเหล่านั้นให้สมบูรณ์ สมมติว่าอินพุตนั้นถูกต้องเสมอ ตัวอย่าง: multiply(148, 412) ควรส่งคืน 16, multiply(19, 28) ควรส่งคืน 72, multiply(2020, 1851) ควรส่งคืน 0, multiply(14,-15) ควรส่งคืน 20\n """\n
return abs(a % 10) * abs(b % 10)\n
def check(candidate):\n\n # Check some simple cases\n assert candidate(148, 412) == 16, "First test error: " + str(candidate(148, 412)) \n assert candidate(19, 28) == 72, "Second test error: " + str(candidate(19, 28)) \n assert candidate(2020, 1851) == 0, "Third test error: " + ...
multiply
HumanEval\/98
\ndef count_upper(s):\n """กำหนดสตริง s ให้นับจำนวนสระตัวพิมพ์ใหญ่ในดัชนีคู่ ตัวอย่างเช่น count_upper(\'aBCdEf\') คืนค่า 1 count_upper(\'abcdefg\') คืนค่า 0 count_upper(\'dBBE\') คืนค่า 0\n """\n
count = 0\n for i in range(0,len(s),2):\n if s[i] in "AEIOU":\n count += 1\n return count\n
def check(candidate):\n\n # Check some simple cases\n assert candidate('aBCdEf') == 1\n assert candidate('abcdefg') == 0\n assert candidate('dBBE') == 0\n assert candidate('B') == 0\n assert candidate('U') == 1\n assert candidate('') == 0\n assert candidate('EEEE') == 2\n\n # Check some ed...
count_upper
HumanEval\/99
\ndef closest_integer(value):\n '''สร้างฟังก์ชันที่รับค่า (สตริง) ที่แสดงถึงตัวเลขและส่งคืนจำนวนเต็มที่ใกล้เคียงที่สุดกับตัวเลขนั้น หากตัวเลขมีระยะห่างเท่ากันจากจำนวนเต็มสองจำนวน ให้ปัดเศษออกจากศูนย์ ตัวอย่าง >>> Closest_integer("10") 10 >>> Closest_integer("15.3") 15 หมายเหตุ: การปัดเศษออกจากศูนย์หมายความว่าหากตัวเ...
from math import floor, ceil\n\n if value.count('.') == 1:\n # remove trailing zeros\n while (value[-1] == '0'):\n value = value[:-1]\n\n num = float(value)\n if value[-2:] == '.5':\n if num > 0:\n res = ceil(num)\n else:\n res = floor(num)\n ...
def check(candidate):\n\n # Check some simple cases\n assert candidate("10") == 10, "Test 1"\n assert candidate("14.5") == 15, "Test 2"\n assert candidate("-15.5") == -16, "Test 3"\n assert candidate("15.3") == 15, "Test 3"\n\n # Check some edge cases that are easy to work out by hand.\n assert can...
closest_integer
End of preview. Expand in Data Studio

Thai HumanEval dataset

Original dataset: https://huggingface.co/datasets/openai/openai_humaneval

Translated to Thai by iApp Technology

Downloads last month
11