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\/100 | \ndef make_a_pile(n):\n """เมื่อกำหนดจำนวนเต็มบวก n คุณต้องสร้างกองหิน n ระดับ ระดับแรกมีหิน n ก้อน จำนวนหินในระดับถัดไปคือ - จำนวนคี่ถัดไปถ้า n เป็นคี่ - จำนวนคู่ถัดไปถ้า n เป็นคู่ ส่งคืนจำนวนหินในแต่ละระดับในรายการ โดยที่องค์ประกอบที่ดัชนี i แสดงถึงจำนวนหินในระดับ (i+1) ตัวอย่าง:\n >>> make_a_pile(3)\n [3, 5, 7]"""\n | return [n + 2*i for i in range(n)]\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(3) == [3, 5, 7], "Test 3"\n assert candidate(4) == [4,6,8,10], "Test 4"\n assert candidate(5) == [5, 7, 9, 11, 13]\n assert candidate(6) == [6, 8, 10, 12, 14, 16]\n assert candidate(8) == [8, 10, 12, 14, 16, 18, 20, 22]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | make_a_pile |
HumanEval\/101 | \ndef words_string(s):\n """คุณจะได้รับสตริงคำที่คั่นด้วยเครื่องหมายจุลภาคหรือช่องว่าง งานของคุณคือแยกสตริงออกเป็นคำและส่งคืนอาร์เรย์ของคำเหล่านั้น ตัวอย่างเช่น: words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]\n """\n | if not s:\n return []\n\n s_list = []\n\n for letter in s:\n if letter == ',':\n s_list.append(' ')\n else:\n s_list.append(letter)\n\n s_list = "".join(s_list)\n return s_list.split()\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("Hi, my name is John") == ["Hi", "my", "name", "is", "John"]\n assert candidate("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]\n assert candidate("Hi, my name") == ["Hi", "my", "name"]\n assert candidate("One,, two, three, four, five, six,") == ["One", "two", "three", "four", "five", "six"]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate("") == []\n assert candidate("ahmed , gamal") == ["ahmed", "gamal"]\n\n | words_string |
HumanEval\/102 | \ndef choose_num(x, y):\n """ฟังก์ชันนี้ใช้ค่า x และ y เป็นจำนวนบวกสองค่า และส่งคืนจำนวนเต็มคู่ที่มากที่สุดที่อยู่ในช่วง [x, y] รวม หากไม่มีค่าดังกล่าว ฟังก์ชันควรส่งคืน -1 ตัวอย่างเช่น: choose_num(12, 15) = 14 choose_num(13, 12) = -1\n """\n | if x > y:\n return -1\n if y % 2 == 0:\n return y\n if x == y:\n return -1\n return y - 1\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(12, 15) == 14\n assert candidate(13, 12) == -1\n assert candidate(33, 12354) == 12354\n assert candidate(5234, 5233) == -1\n assert candidate(6, 29) == 28\n assert candidate(27, 10) == -1\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(7, 7) == -1\n assert candidate(546, 546) == 546\n\n | choose_num |
HumanEval\/103 | \ndef rounded_avg(n, m):\n """คุณได้รับจำนวนเต็มบวกสองจำนวนคือ n และ m และงานของคุณคือคำนวณค่าเฉลี่ยของจำนวนเต็มตั้งแต่ n ถึง m (รวมทั้ง n และ m) ปัดเศษคำตอบเป็นจำนวนเต็มที่ใกล้เคียงที่สุดและแปลงเป็นเลขฐานสอง หาก n มากกว่า m ให้ส่งคืน -1 ตัวอย่าง: rounded_avg(1, 5) => "0b11" rounded_avg(7, 5) => -1 rounded_avg(10, 20) => "0b1111" rounded_avg(20, 33) => "0b11010"\n """\n | if m < n:\n return -1\n summation = 0\n for i in range(n, m+1):\n summation += i\n return bin(round(summation\/(m - n + 1)))\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(1, 5) == "0b11"\n assert candidate(7, 13) == "0b1010"\n assert candidate(964,977) == "0b1111001010"\n assert candidate(996,997) == "0b1111100100"\n assert candidate(560,851) == "0b1011000010"\n assert candidate(185,546) == "0b101101110"\n assert candidate(362,496) == "0b110101101"\n assert candidate(350,902) == "0b1001110010"\n assert candidate(197,233) == "0b11010111"\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(7, 5) == -1\n assert candidate(5, 1) == -1\n assert candidate(5, 5) == "0b101"\n\n | rounded_avg |
HumanEval\/104 | \ndef unique_digits(x):\n """กำหนดรายการของจำนวนเต็มบวก x ให้ส่งคืนรายการที่เรียงลำดับขององค์ประกอบทั้งหมดที่ไม่มีเลขคู่ หมายเหตุ: รายการที่ส่งคืนควรเรียงลำดับตามลำดับเพิ่มขึ้น ตัวอย่างเช่น:\n >>> unique_digits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> unique_digits([152, 323, 1422, 10])\n []"""\n | odd_digit_elements = []\n for i in x:\n if all (int(c) % 2 == 1 for c in str(i)):\n odd_digit_elements.append(i)\n return sorted(odd_digit_elements)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([15, 33, 1422, 1]) == [1, 15, 33]\n assert candidate([152, 323, 1422, 10]) == []\n assert candidate([12345, 2033, 111, 151]) == [111, 151]\n assert candidate([135, 103, 31]) == [31, 135]\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | unique_digits |
HumanEval\/105 | \ndef by_length(arr):\n """กำหนดอาร์เรย์ของจำนวนเต็ม ให้เรียงลำดับจำนวนเต็มที่อยู่ระหว่าง 1 ถึง 9 รวมทั้งหมด ย้อนกลับอาร์เรย์ผลลัพธ์ แล้วแทนที่แต่ละหลักด้วยชื่อที่สอดคล้องกันจาก "หนึ่ง" "สอง" "สาม" "สี่" "ห้า" "หก" "เจ็ด" "แปด" "เก้า" ตัวอย่าง: arr = [2, 1, 1, 4, 5, 8, 2, 3] -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1] return ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"] ถ้าอาร์เรย์ว่างเปล่า ให้ส่งคืนอาร์เรย์ว่าง: arr = [] return [] ถ้าอาร์เรย์มีตัวเลขแปลกๆ ให้ละเว้น: arr = [1, -1 , 55] -> sort arr -> [-1, 1, 55] -> reverse arr -> [55, 1, -1] return = [\'One\']\n """\n | dic = {\n 1: "One",\n 2: "Two",\n 3: "Three",\n 4: "Four",\n 5: "Five",\n 6: "Six",\n 7: "Seven",\n 8: "Eight",\n 9: "Nine",\n }\n sorted_arr = sorted(arr, reverse=True)\n new_arr = []\n for var in sorted_arr:\n try:\n new_arr.append(dic[var])\n except:\n pass\n return new_arr\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([2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"], "Error"\n assert candidate([]) == [], "Error"\n assert candidate([1, -1 , 55]) == ['One'], "Error"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([1, -1, 3, 2]) == ["Three", "Two", "One"]\n assert candidate([9, 4, 8]) == ["Nine", "Eight", "Four"]\n\n | by_length |
HumanEval\/106 | \ndef f(n):\n """นำฟังก์ชัน f ที่รับ n เป็นพารามิเตอร์มาใช้งาน และส่งคืนรายการขนาด n โดยที่ค่าขององค์ประกอบที่ดัชนี i จะเป็นแฟกทอเรียลของ i หาก i เป็นเลขคู่ หรือเป็นผลรวมของตัวเลขตั้งแต่ 1 ถึง i ในกรณีอื่น i เริ่มจาก 1 แฟกทอเรียลของ i คือการคูณตัวเลขตั้งแต่ 1 ถึง i (1 * 2 * ... * i) ตัวอย่าง: f(5) == [1, 2, 6, 24, 15]\n """\n | ret = []\n for i in range(1,n+1):\n if i%2 == 0:\n x = 1\n for j in range(1,i+1): x *= j\n ret += [x]\n else:\n x = 0\n for j in range(1,i+1): x += j\n ret += [x]\n return ret\n | def check(candidate):\n\n assert candidate(5) == [1, 2, 6, 24, 15]\n assert candidate(7) == [1, 2, 6, 24, 15, 720, 28]\n assert candidate(1) == [1]\n assert candidate(3) == [1, 2, 6]\n | f |
HumanEval\/107 | \ndef even_odd_palindrome(n):\n """กำหนดจำนวนเต็มบวก n ให้ส่งคืนทูเพิลที่มีจำนวนพาลินโดรมจำนวนเต็มคู่และคี่ที่อยู่ในช่วง (1, n) รวม ตัวอย่าง 1: อินพุต: 3 เอาต์พุต: (1, 2) คำอธิบาย: พาลินโดรมจำนวนเต็มคือ 1, 2, 3 โดยหนึ่งในนั้นเป็นจำนวนคู่ และอีกสองอันเป็นจำนวนคี่ ตัวอย่าง 2: อินพุต: 12 เอาต์พุต: (4, 6) คำอธิบาย: พาลินโดรมจำนวนเต็มคือ 1, 2, 3, 4, 5, 6, 7, 8, 9, 11 โดยสี่อันเป็นจำนวนคู่ และอีก 6 อันเป็นจำนวนคี่ หมายเหตุ: 1. 1 <= n <= 10^3 2. ทูเพิลที่ส่งคืนมีจำนวนพาลินโดรมจำนวนเต็มคู่และคี่ตามลำดับ\n """\n | def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\n even_palindrome_count = 0\n odd_palindrome_count = 0\n\n for i in range(1, n+1):\n if i%2 == 1 and is_palindrome(i):\n odd_palindrome_count += 1\n elif i%2 == 0 and is_palindrome(i):\n even_palindrome_count += 1\n return (even_palindrome_count, odd_palindrome_count)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(123) == (8, 13)\n assert candidate(12) == (4, 6)\n assert candidate(3) == (1, 2)\n assert candidate(63) == (6, 8)\n assert candidate(25) == (5, 6)\n assert candidate(19) == (4, 6)\n assert candidate(9) == (4, 5), "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), "This prints if this assert fails 2 (also good for debugging!)"\n\n | even_odd_palindrome |
HumanEval\/108 | \ndef count_nums(arr):\n """เขียนฟังก์ชัน count_nums ซึ่งรับอาร์เรย์ของจำนวนเต็ม และส่งคืนจำนวนองค์ประกอบที่ผลรวมของตัวเลข > 0 หากตัวเลขเป็นค่าลบ ตัวเลขที่มีเครื่องหมายตัวแรกจะเป็นค่าลบ เช่น -123 มีตัวเลขที่มีเครื่องหมายคือ -1, 2 และ 3\n >>> count_nums([]) == 0\n >>> count_nums([-1, 11, -11]) == 1\n >>> count_nums([1, 1, 2]) == 3"""\n | def digits_sum(n):\n neg = 1\n if n < 0: n, neg = -1 * n, -1 \n n = [int(i) for i in str(n)]\n n[0] = n[0] * neg\n return sum(n)\n return len(list(filter(lambda x: x > 0, [digits_sum(i) for i in arr])))\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([]) == 0\n assert candidate([-1, -2, 0]) == 0\n assert candidate([1, 1, 2, -2, 3, 4, 5]) == 6\n assert candidate([1, 6, 9, -6, 0, 1, 5]) == 5\n assert candidate([1, 100, 98, -7, 1, -1]) == 4\n assert candidate([12, 23, 34, -45, -56, 0]) == 5\n assert candidate([-0, 1**0]) == 1\n assert candidate([1]) == 1\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | count_nums |
HumanEval\/109 | \ndef move_one_ball(arr):\n """เรามีอาร์เรย์ \'arr\' ของจำนวนเต็ม N ตัว arr[1], arr[2], ..., arr[N] ตัวเลขในอาร์เรย์จะถูกเรียงลำดับแบบสุ่ม งานของคุณคือตรวจสอบว่าเป็นไปได้หรือไม่ที่จะเรียงลำดับอาร์เรย์ในลำดับที่ไม่ลดลงโดยดำเนินการต่อไปนี้กับอาร์เรย์ที่กำหนด: คุณสามารถเลื่อนไปทางขวาได้หลายครั้งเท่าที่ต้องการ การเลื่อนไปทางขวาหนึ่งครั้งหมายถึงการเลื่อนองค์ประกอบทั้งหมดในอาร์เรย์ไปหนึ่งตำแหน่งในทิศทางที่ถูกต้อง องค์ประกอบสุดท้ายของอาร์เรย์จะย้ายไปที่ตำแหน่งเริ่มต้นในอาร์เรย์ เช่น ดัชนีที่ 0 หากสามารถรับอาร์เรย์ที่เรียงลำดับได้โดยดำเนินการข้างต้น ให้ส่งคืนค่า True มิฉะนั้นให้ส่งคืนค่า False หากอาร์เรย์ที่กำหนดว่างเปล่า ให้ส่งคืนค่า True หมายเหตุ: รายการที่กำหนดให้มีองค์ประกอบที่ไม่ซ้ำกันอย่างแน่นอน ตัวอย่างเช่น: move_one_ball([3, 4, 5, 1, 2])==>True คำอธิบาย: โดยการเลื่อนไปทางขวา 2 ครั้ง จะทำให้ได้ลำดับที่ไม่ลดลงสำหรับอาร์เรย์ที่กำหนด move_one_ball([3, 5, 4, 1, 2])==>เท็จ คำอธิบาย: ไม่สามารถรับลำดับที่ไม่ลดลงสำหรับอาร์เรย์ที่กำหนดได้โดยดำเนินการเลื่อนไปทางขวาจำนวนใดๆ ก็ได้\n """\n | if len(arr)==0:\n return True\n sorted_array=sorted(arr)\n my_arr=[]\n \n min_value=min(arr)\n min_index=arr.index(min_value)\n my_arr=arr[min_index:]+arr[0:min_index]\n for i in range(len(arr)):\n if my_arr[i]!=sorted_array[i]:\n return False\n return True\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([3, 4, 5, 1, 2])==True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([3, 5, 10, 1, 2])==True\n assert candidate([4, 3, 1, 2])==False\n # Check some edge cases that are easy to work out by hand.\n assert candidate([3, 5, 4, 1, 2])==False, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([])==True\n | move_one_ball |
HumanEval\/110 | \ndef exchange(lst1, lst2):\n """ในปัญหานี้ คุณจะใช้ฟังก์ชันที่รับรายการตัวเลขสองรายการ และพิจารณาว่าเป็นไปได้หรือไม่ที่จะทำการแลกเปลี่ยนองค์ประกอบระหว่างรายการเหล่านั้นเพื่อทำให้ lst1 เป็นรายการของตัวเลขคู่เท่านั้น ไม่มีข้อจำกัดเกี่ยวกับจำนวนองค์ประกอบที่แลกเปลี่ยนระหว่าง lst1 และ lst2 หากสามารถแลกเปลี่ยนองค์ประกอบระหว่าง lst1 และ lst2 เพื่อทำให้องค์ประกอบทั้งหมดของ lst1 เป็นเลขคู่ ให้ส่งคืน "YES" มิฉะนั้น ให้ส่งคืน "NO" ตัวอย่างเช่น: exchange([1, 2, 3, 4], [1, 2, 3, 4]) => "YES" exchange([1, 2, 3, 4], [1, 5, 3, 4]) => "NO" ถือว่ารายการอินพุตจะไม่ว่างเปล่า\n """\n | odd = 0\n even = 0\n for i in lst1:\n if i%2 == 1:\n odd += 1\n for i in lst2:\n if i%2 == 0:\n even += 1\n if even >= odd:\n return "YES"\n return "NO"\n \n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1, 2, 3, 4], [1, 2, 3, 4]) == "YES"\n assert candidate([1, 2, 3, 4], [1, 5, 3, 4]) == "NO"\n assert candidate([1, 2, 3, 4], [2, 1, 4, 3]) == "YES" \n assert candidate([5, 7, 3], [2, 6, 4]) == "YES"\n assert candidate([5, 7, 3], [2, 6, 3]) == "NO" \n assert candidate([3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]) == "NO"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([100, 200], [200, 200]) == "YES"\n\n | exchange |
HumanEval\/111 | \ndef histogram(test):\n """กำหนดสตริงที่แสดงถึงตัวอักษรตัวเล็กที่คั่นด้วยช่องว่าง ให้ส่งคืนพจนานุกรมของตัวอักษรที่มีการทำซ้ำมากที่สุดและมีจำนวนที่สอดคล้องกัน หากมีตัวอักษรหลายตัวปรากฏเหมือนกัน ให้ส่งคืนทั้งหมด ตัวอย่าง: histogram(\'ab c\') == {\'a\': 1, \'b\': 1, \'c\': 1} histogram(\'abb a\') == {\'a\': 2, \'b\': 2} histogram(\'abca b\') == {\'a\': 2, \'b\': 2} histogram(\'bbbb a\') == {\'b\': 4} histogram(\'\') == {}\n """\n | dict1={}\n list1=test.split(" ")\n t=0\n\n for i in list1:\n if(list1.count(i)>t) and i!='':\n t=list1.count(i)\n if t>0:\n for i in list1:\n if(list1.count(i)==t):\n \n dict1[i]=t\n return dict1\n | def check(candidate):\n\n # Check some simple cases\n assert candidate('a b b a') == {'a':2,'b': 2}, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate('a b c a b') == {'a': 2, 'b': 2}, "This prints if this assert fails 2 (good for debugging!)"\n assert candidate('a b c d g') == {'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1}, "This prints if this assert fails 3 (good for debugging!)"\n assert candidate('r t g') == {'r': 1,'t': 1,'g': 1}, "This prints if this assert fails 4 (good for debugging!)"\n assert candidate('b b b b a') == {'b': 4}, "This prints if this assert fails 5 (good for debugging!)"\n assert candidate('r t g') == {'r': 1,'t': 1,'g': 1}, "This prints if this assert fails 6 (good for debugging!)"\n \n \n # Check some edge cases that are easy to work out by hand.\n assert candidate('') == {}, "This prints if this assert fails 7 (also good for debugging!)"\n assert candidate('a') == {'a': 1}, "This prints if this assert fails 8 (also good for debugging!)"\n\n | histogram |
HumanEval\/112 | \ndef reverse_delete(s,c):\n """งาน เราได้รับสตริง 2 ตัวคือ s และ c คุณต้องลบตัวอักษรทั้งหมดใน s ที่เท่ากับตัวอักษรใดๆ ใน c จากนั้นตรวจสอบว่าสตริงผลลัพธ์เป็นพาลินโดรมหรือไม่ สตริงจะถูกเรียกว่าพาลินโดรมหากอ่านแบบย้อนกลับและไปข้างหน้าเหมือนกัน คุณควรส่งคืนทูเพิลที่มีสตริงผลลัพธ์และค่า True\/False สำหรับการตรวจสอบ ตัวอย่าง สำหรับ s = "abcde", c = "ae" ผลลัพธ์ควรเป็น (\'bcd\',False) สำหรับ s = "abcdef", c = "b" ผลลัพธ์ควรเป็น (\'acdef\',False) สำหรับ s = "abcdedcba", c = "ab" ผลลัพธ์ควรเป็น (\'cdedc\',True)\n """\n | s = ''.join([char for char in s if char not in c])\n return (s,s[::-1] == s)\n | def check(candidate):\n\n assert candidate("abcde","ae") == ('bcd',False)\n assert candidate("abcdef", "b") == ('acdef',False)\n assert candidate("abcdedcba","ab") == ('cdedc',True)\n assert candidate("dwik","w") == ('dik',False)\n assert candidate("a","a") == ('',True)\n assert candidate("abcdedcba","") == ('abcdedcba',True)\n assert candidate("abcdedcba","v") == ('abcdedcba',True)\n assert candidate("vabba","v") == ('abba',True)\n assert candidate("mamma", "mia") == ("", True)\n | reverse_delete |
HumanEval\/113 | \ndef odd_count(lst):\n """ให้รายการสตริงที่มีเฉพาะตัวเลข ให้ส่งคืนรายการ องค์ประกอบ i แต่ละตัวของเอาต์พุตควรเป็น "จำนวนองค์ประกอบคี่ในสตริง i ของอินพุต" โดยที่ i ทั้งหมดควรถูกแทนที่ด้วยจำนวนหลักคี่ในสตริงที่ i ของอินพุต\n >>> odd_count(['1234567'])\n ["the number of odd elements 4n the str4ng 4 of the 4nput."]\n >>> odd_count(['3',"11111111"])\n ["the number of odd elements 1n the str1ng 1 of the 1nput.",\n "the number of odd elements 8n the str8ng 8 of the 8nput."]"""\n | res = []\n for arr in lst:\n n = sum(int(d)%2==1 for d in arr)\n res.append("the number of odd elements " + str(n) + "n the str"+ str(n) +"ng "+ str(n) +" of the "+ str(n) +"nput.")\n return res\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(['1234567']) == ["the number of odd elements 4n the str4ng 4 of the 4nput."], "Test 1"\n assert candidate(['3',"11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."], "Test 2"\n assert candidate(['271', '137', '314']) == [\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.'\n ]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | odd_count |
HumanEval\/114 | \ndef minSubArraySum(nums):\n """กำหนดอาร์เรย์ของจำนวนเต็ม nums หาผลรวมขั้นต่ำของอาร์เรย์ย่อยของ nums ที่ไม่ว่าง ตัวอย่าง minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 minSubArraySum([-1, -2, -3]) == -6\n """\n | max_sum = 0\n s = 0\n for num in nums:\n s += -num\n if (s < 0):\n s = 0\n max_sum = max(s, max_sum)\n if max_sum == 0:\n max_sum = max(-i for i in nums)\n min_sum = -max_sum\n return min_sum\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([2, 3, 4, 1, 2, 4]) == 1, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([-1, -2, -3]) == -6\n assert candidate([-1, -2, -3, 2, -10]) == -14\n assert candidate([-9999999999999999]) == -9999999999999999\n assert candidate([0, 10, 20, 1000000]) == 0\n assert candidate([-1, -2, -3, 10, -5]) == -6\n assert candidate([100, -1, -2, -3, 10, -5]) == -6\n assert candidate([10, 11, 13, 8, 3, 4]) == 3\n assert candidate([100, -33, 32, -1, 0, -2]) == -33\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([-10]) == -10, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([7]) == 7\n assert candidate([1, -1]) == -1\n | minSubArraySum |
HumanEval\/115 | \ndef max_fill(grid, capacity):\n import math\n """คุณจะได้รับตารางบ่อน้ำรูปสี่เหลี่ยมผืนผ้า แต่ละแถวแทนบ่อน้ำ 1 บ่อ และแต่ละบ่อน้ำในแถวแทนน้ำ 1 หน่วย แต่ละบ่อน้ำจะมีถังที่สอดคล้องกันซึ่งใช้สำหรับตักน้ำออกจากบ่อ และถังทั้งหมดจะมีความจุเท่ากัน หน้าที่ของคุณคือใช้ถังเพื่อเทน้ำออกจากบ่อ กำหนดจำนวนครั้งที่คุณต้องการลดถังลง ตัวอย่างที่ 1: อินพุต: grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]] bucket_capacity : 1 เอาต์พุต: 6 ตัวอย่างที่ 2: อินพุต: grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] bucket_capacity : 2 เอาต์พุต: 5 ตัวอย่างที่ 3: อินพุต: grid : [[0,0,0], [0,0,0]] bucket_capacity : 5 เอาต์พุต: 0 ข้อจำกัด: * บ่อน้ำทั้งหมดมีความยาวเท่ากัน * 1 <= grid.length <= 10^2 * 1 <= grid[:,1].length <= 10^2 * grid[i][j] -> 0 | 1 * 1 <= ความจุ <= 10\n """\n | return sum([math.ceil(sum(arr)\/capacity) for arr in grid])\n | def check(candidate):\n\n\n # Check some simple cases\n assert True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1) == 6, "Error"\n assert candidate([[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2) == 5, "Error"\n assert candidate([[0,0,0], [0,0,0]], 5) == 0, "Error"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([[1,1,1,1], [1,1,1,1]], 2) == 4, "Error"\n assert candidate([[1,1,1,1], [1,1,1,1]], 9) == 2, "Error"\n\n | max_fill |
HumanEval\/116 | \ndef sort_array(arr):\n """ใน Kata นี้ คุณต้องเรียงลำดับอาร์เรย์ของจำนวนเต็มที่ไม่เป็นลบตามจำนวนเลขฐานสองที่แสดงเป็นเลขฐานสองจากน้อยไปมาก สำหรับจำนวนเลขฐานสองที่ใกล้เคียงกัน ให้เรียงลำดับตามค่าทศนิยม ซึ่งจะต้องดำเนินการดังนี้:\n >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]"""\n | return sorted(sorted(arr), key=lambda x: bin(x)[2:].count('1'))\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,5,2,3,4]) == [1, 2, 4, 3, 5]\n assert candidate([-2,-3,-4,-5,-6]) == [-4, -2, -6, -5, -3]\n assert candidate([1,0,2,3,4]) == [0, 1, 2, 4, 3]\n assert candidate([]) == []\n assert candidate([2,5,77,4,5,3,5,7,2,3,4]) == [2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77]\n assert candidate([3,6,44,12,32,5]) == [32, 3, 5, 6, 12, 44]\n assert candidate([2,4,8,16,32]) == [2, 4, 8, 16, 32]\n assert candidate([2,4,8,16,32]) == [2, 4, 8, 16, 32]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | sort_array |
HumanEval\/117 | \ndef select_words(s, n):\n """เมื่อกำหนดสตริง s และจำนวนธรรมชาติ n คุณได้รับมอบหมายให้ใช้งานฟังก์ชันที่ส่งคืนรายการคำทั้งหมดจากสตริง s ที่มีพยัญชนะ n ตัวพอดี โดยคำเหล่านี้จะปรากฏตามลำดับในสตริง s หากสตริง s ว่างเปล่า ฟังก์ชันควรส่งคืนรายการว่างเปล่า หมายเหตุ: คุณอาจถือว่าสตริงอินพุตมีเฉพาะตัวอักษรและช่องว่างเท่านั้น ตัวอย่าง: select_words("Mary had a little lamb", 4) ==> ["little"] select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"] select_words("simple white space", 2) ==> [] select_words("Hello world", 4) ==> ["world"] select_words("Uncle sam", 3) ==> ["Uncle"]\n """\n | result = []\n for word in s.split():\n n_consonants = 0\n for i in range(0, len(word)):\n if word[i].lower() not in ["a","e","i","o","u"]:\n n_consonants += 1 \n if n_consonants == n:\n result.append(word)\n return result\n\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("Mary had a little lamb", 4) == ["little"], "First test error: " + str(candidate("Mary had a little lamb", 4)) \n assert candidate("Mary had a little lamb", 3) == ["Mary", "lamb"], "Second test error: " + str(candidate("Mary had a little lamb", 3)) \n assert candidate("simple white space", 2) == [], "Third test error: " + str(candidate("simple white space", 2)) \n assert candidate("Hello world", 4) == ["world"], "Fourth test error: " + str(candidate("Hello world", 4)) \n assert candidate("Uncle sam", 3) == ["Uncle"], "Fifth test error: " + str(candidate("Uncle sam", 3))\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate("", 4) == [], "1st edge test error: " + str(candidate("", 4))\n assert candidate("a b c d e f", 1) == ["b", "c", "d", "f"], "2nd edge test error: " + str(candidate("a b c d e f", 1))\n\n | select_words |
HumanEval\/118 | \ndef get_closest_vowel(word):\n """คุณจะได้รับคำศัพท์หนึ่งคำ งานของคุณคือค้นหาสระที่ใกล้เคียงที่สุดที่อยู่ระหว่างพยัญชนะสองตัวจากด้านขวาของคำ (ต้องตรงตามตัวพิมพ์ใหญ่-เล็ก) สระในตอนต้นและตอนท้ายไม่นับ ส่งคืนสตริงว่างหากคุณไม่พบสระที่ตรงตามเงื่อนไขข้างต้น คุณอาจถือว่าสตริงที่กำหนดมีเฉพาะตัวอักษรภาษาอังกฤษเท่านั้น ตัวอย่าง: get_closest_vowel("yogurt") ==> "u" get_closest_vowel("FULL") ==> "U" get_closest_vowel("quick") ==> "" get_closest_vowel("ab") ==> ""\n """\n | if len(word) < 3:\n return ""\n\n vowels = {"a", "e", "i", "o", "u", "A", "E", 'O', 'U', 'I'}\n for i in range(len(word)-2, 0, -1):\n if word[i] in vowels:\n if (word[i+1] not in vowels) and (word[i-1] not in vowels):\n return word[i]\n return ""\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("yogurt") == "u"\n assert candidate("full") == "u"\n assert candidate("easy") == ""\n assert candidate("eAsy") == ""\n assert candidate("ali") == ""\n assert candidate("bad") == "a"\n assert candidate("most") == "o"\n assert candidate("ab") == ""\n assert candidate("ba") == ""\n assert candidate("quick") == ""\n assert candidate("anime") == "i"\n assert candidate("Asia") == ""\n assert candidate("Above") == "o"\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | get_closest_vowel |
HumanEval\/119 | \ndef match_parens(lst):\n '''คุณจะได้รับรายการสตริงสองสตริง โดยสตริงทั้งสองประกอบด้วยวงเล็บเปิด \'(\' หรือวงเล็บปิด \')\' เท่านั้น งานของคุณคือตรวจสอบว่าสามารถต่อสตริงทั้งสองเข้าด้วยกันในลำดับใด ๆ ได้หรือไม่ สตริงที่ได้จะดีหรือไม่ สตริง S จะถือว่าดีก็ต่อเมื่อวงเล็บทั้งหมดใน S สมดุลกัน ตัวอย่างเช่น สตริง \'(())()\' ดีในขณะที่สตริง \'())\' ไม่ดี ให้ส่งคืน \'ใช่\' หากมีวิธีสร้างสตริงที่ดี และส่งคืน \'ไม่ใช่\' หากไม่เป็นเช่นนั้น ตัวอย่าง: match_parens([\'()(\', \')\']) == \'ใช่\' match_parens([\')\', \')\']) == \'ไม่\'\n '''\n | def check(s):\n val = 0\n for i in s:\n if i == '(':\n val = val + 1\n else:\n val = val - 1\n if val < 0:\n return False\n return True if val == 0 else False\n\n S1 = lst[0] + lst[1]\n S2 = lst[1] + lst[0]\n return 'Yes' if check(S1) or check(S2) else 'No'\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(['()(', ')']) == 'Yes'\n assert candidate([')', ')']) == 'No'\n assert candidate(['(()(())', '())())']) == 'No'\n assert candidate([')())', '(()()(']) == 'Yes'\n assert candidate(['(())))', '(()())((']) == 'Yes'\n assert candidate(['()', '())']) == 'No'\n assert candidate(['(()(', '()))()']) == 'Yes'\n assert candidate(['((((', '((())']) == 'No'\n assert candidate([')(()', '(()(']) == 'No'\n assert candidate([')(', ')(']) == 'No'\n \n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(['(', ')']) == 'Yes'\n assert candidate([')', '(']) == 'Yes' \n\n | match_parens |
HumanEval\/120 | \ndef maximum(arr, k):\n """กำหนดอาร์เรย์ arr ของจำนวนเต็มและจำนวนเต็มบวก k ให้ส่งคืนรายการที่เรียงลำดับความยาว k พร้อมตัวเลขสูงสุด k ตัวใน arr ตัวอย่างที่ 1: อินพุต: arr = [-3, -4, 5], k = 3 เอาต์พุต: [-4, -3, 5] ตัวอย่างที่ 2: อินพุต: arr = [4, -4, 4], k = 2 เอาต์พุต: [4, 4] ตัวอย่างที่ 3: อินพุต: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1 เอาต์พุต: [2] หมายเหตุ: 1. ความยาวของอาร์เรย์จะอยู่ในช่วง [1, 1000] 2. องค์ประกอบในอาร์เรย์จะอยู่ในช่วง [-1000, 1000] 3. 0 <= k <= len(arr)\n """\n | if k == 0:\n return []\n arr.sort()\n ans = arr[-k:]\n return ans\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([-3, -4, 5], 3) == [-4, -3, 5]\n assert candidate([4, -4, 4], 2) == [4, 4]\n assert candidate([-3, 2, 1, 2, -1, -2, 1], 1) == [2]\n assert candidate([123, -123, 20, 0 , 1, 2, -3], 3) == [2, 20, 123]\n assert candidate([-123, 20, 0 , 1, 2, -3], 4) == [0, 1, 2, 20]\n assert candidate([5, 15, 0, 3, -13, -8, 0], 7) == [-13, -8, 0, 0, 3, 5, 15]\n assert candidate([-1, 0, 2, 5, 3, -10], 2) == [3, 5]\n assert candidate([1, 0, 5, -7], 1) == [5]\n assert candidate([4, -4], 2) == [-4, 4]\n assert candidate([-10, 10], 2) == [-10, 10]\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1, 2, 3, -23, 243, -400, 0], 0) == []\n\n | maximum |
HumanEval\/121 | \ndef solution(lst):\n """กำหนดรายการจำนวนเต็มที่ไม่ว่าง ให้ส่งคืนผลรวมขององค์ประกอบคี่ทั้งหมดที่อยู่ในตำแหน่งคู่ ตัวอย่าง solution([5, 8, 7, 1]) ==> 12 solution([3, 3, 3, 3, 3]) ==> 9 solution([30, 13, 24, 321]) ==>0\n """\n | return sum([x for idx, x in enumerate(lst) if idx%2==0 and x%2==1])\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([5, 8, 7, 1]) == 12\n assert candidate([3, 3, 3, 3, 3]) == 9\n assert candidate([30, 13, 24, 321]) == 0\n assert candidate([5, 9]) == 5\n assert candidate([2, 4, 8]) == 0\n assert candidate([30, 13, 23, 32]) == 23\n assert candidate([3, 13, 2, 9]) == 3\n\n # Check some edge cases that are easy to work out by hand.\n\n | solution |
HumanEval\/122 | \ndef add_elements(arr, k):\n """กำหนดอาร์เรย์ของจำนวนเต็ม arr และจำนวนเต็ม k ที่ไม่ว่าง ให้ส่งคืนผลรวมขององค์ประกอบที่มีตัวเลขไม่เกินสองหลักจากองค์ประกอบ k แรกของ arr ตัวอย่าง: อินพุต: arr = [111,21,3,4000,5,6,7,8,9], k = 4 เอาต์พุต: 24 # ผลรวมของ 21 + 3 เงื่อนไข: 1. 1 <= len(arr) <= 100 2. 1 <= k <= len(arr)\n """\n | return sum(elem for elem in arr[:k] if len(str(elem)) <= 2)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1,-2,-3,41,57,76,87,88,99], 3) == -4\n assert candidate([111,121,3,4000,5,6], 2) == 0\n assert candidate([11,21,3,90,5,6,7,8,9], 4) == 125\n assert candidate([111,21,3,4000,5,6,7,8,9], 4) == 24, "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], 1) == 1, "This prints if this assert fails 2 (also good for debugging!)"\n\n | add_elements |
HumanEval\/123 | \ndef get_odd_collatz(n):\n """กำหนดจำนวนเต็มบวก n ให้ส่งคืนรายการที่เรียงลำดับแล้วที่มีจำนวนคี่ในลำดับคอลลาตซ์ สมมติฐานคอลลาตซ์เป็นสมมติฐานทางคณิตศาสตร์ที่เกี่ยวข้องกับลำดับที่กำหนดดังต่อไปนี้: เริ่มต้นด้วยจำนวนเต็มบวก n ใดๆ จากนั้นแต่ละเทอมจะได้มาจากเทอมก่อนหน้าดังนี้: ถ้าเทอมก่อนหน้าเป็นเลขคู่ เทอมถัดไปจะเป็นครึ่งหนึ่งของเทอมก่อนหน้า ถ้าเทอมก่อนหน้าเป็นเลขคี่ เทอมถัดไปจะเป็น 3 เท่าของเทอมก่อนหน้าบวก 1 สมมติฐานคือไม่ว่าค่า n จะเป็นเท่าใด ลำดับจะถึง 1 เสมอ หมายเหตุ: 1. Collatz(1) คือ [1] 2. ส่งคืนรายการที่เรียงลำดับจากน้อยไปมาก ตัวอย่างเช่น: get_odd_collatz(5) ส่งคืน [1, 5] # ลำดับคอลลาตซ์สำหรับ 5 คือ [5, 16, 8, 4, 2, 1] ดังนั้นเลขคี่จึงเป็น 1 และ 5 เท่านั้น\n """\n | if n%2==0:\n odd_collatz = [] \n else:\n odd_collatz = [n]\n while n > 1:\n if n % 2 == 0:\n n = n\/2\n else:\n n = n*3 + 1\n \n if n%2 == 1:\n odd_collatz.append(int(n))\n\n return sorted(odd_collatz)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(14) == [1, 5, 7, 11, 13, 17]\n assert candidate(5) == [1, 5]\n assert candidate(12) == [1, 3, 5], "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) == [1], "This prints if this assert fails 2 (also good for debugging!)"\n\n | get_odd_collatz |
HumanEval\/124 | \ndef valid_date(date):\n """คุณต้องเขียนฟังก์ชันที่ตรวจสอบสตริงวันที่ที่กำหนดและส่งคืนค่า True หากวันที่นั้นถูกต้อง มิฉะนั้นจะส่งคืนค่า False วันที่นั้นจะถูกต้องหากเป็นไปตามกฎทั้งหมดต่อไปนี้: 1. สตริงวันที่ไม่ว่างเปล่า 2. จำนวนวันไม่น้อยกว่า 1 วันหรือสูงกว่า 31 วันสำหรับเดือน 1,3,5,7,8,10,12 และจำนวนวันไม่น้อยกว่า 1 วันหรือสูงกว่า 30 วันสำหรับเดือน 4,6,9,11 และจำนวนวันต้องไม่น้อยกว่า 1 และไม่สูงกว่า 29 สำหรับเดือนที่ 2 3. เดือนไม่ควรน้อยกว่า 1 และไม่สูงกว่า 12 4. วันที่ควรอยู่ในรูปแบบ mm-dd-yyyy เช่น valid_date(\'03-11-2000\') => True valid_date(\'15-01-2012\') => False valid_date(\'04-0-2040\') => False valid_date(\'06-04-2020\') => True valid_date(\'06\/04\/2020\') => False\n """\n | try:\n date = date.strip()\n month, day, year = date.split('-')\n month, day, year = int(month), int(day), int(year)\n if month < 1 or month > 12:\n return False\n if month in [1,3,5,7,8,10,12] and day < 1 or day > 31:\n return False\n if month in [4,6,9,11] and day < 1 or day > 30:\n return False\n if month == 2 and day < 1 or day > 29:\n return False\n except:\n return False\n\n return True\n | def check(candidate):\n\n # Check some simple cases\n assert candidate('03-11-2000') == True\n\n assert candidate('15-01-2012') == False\n\n assert candidate('04-0-2040') == False\n\n assert candidate('06-04-2020') == True\n\n assert candidate('01-01-2007') == True\n\n assert candidate('03-32-2011') == False\n\n assert candidate('') == False\n\n assert candidate('04-31-3000') == False\n\n assert candidate('06-06-2005') == True\n\n assert candidate('21-31-2000') == False\n\n assert candidate('04-12-2003') == True\n\n assert candidate('04122003') == False\n\n assert candidate('20030412') == False\n\n assert candidate('2003-04') == False\n\n assert candidate('2003-04-12') == False\n\n assert candidate('04-2003') == False\n | valid_date |
HumanEval\/125 | \ndef split_words(txt):\n '''กำหนดสตริงของคำ ให้ส่งคืนรายการคำที่แบ่งตามช่องว่าง ถ้าไม่มีช่องว่างในข้อความ คุณควรแบ่งด้วยเครื่องหมายจุลภาค \' ถ้าไม่มีเครื่องหมายจุลภาค คุณควรส่งคืนจำนวนตัวอักษรพิมพ์เล็กที่มีลำดับคี่ในตัวอักษร ord(\'a\') = 0, ord(\'b\') = 1, ... ord(\'z\') = 25 ตัวอย่าง split_words("Hello world!") ➞ ["Hello", "world!"] split_words("Hello,world!") ➞ ["Hello", "world!"] split_words("abcdef") == 3\n '''\n | if " " in txt:\n return txt.split()\n elif "," in txt:\n return txt.replace(',',' ').split()\n else:\n return len([i for i in txt if i.islower() and ord(i)%2 == 0])\n | def check(candidate):\n\n assert candidate("Hello world!") == ["Hello","world!"]\n assert candidate("Hello,world!") == ["Hello","world!"]\n assert candidate("Hello world,!") == ["Hello","world,!"]\n assert candidate("Hello,Hello,world !") == ["Hello,Hello,world","!"]\n assert candidate("abcdef") == 3\n assert candidate("aaabb") == 2\n assert candidate("aaaBb") == 1\n assert candidate("") == 0\n | split_words |
HumanEval\/126 | \ndef is_sorted(lst):\n '''ให้แสดงรายการตัวเลข ให้ส่งคืนว่าตัวเลขเหล่านั้นเรียงลำดับจากน้อยไปมากหรือไม่ หากรายการมีตัวเลขเดียวกันซ้ำกันมากกว่า 1 ตัว ให้ส่งคืนค่า False สมมติว่าไม่มีตัวเลขติดลบและมีเพียงจำนวนเต็มเท่านั้น ตัวอย่าง is_sorted([5]) ➞ True is_sorted([1, 2, 3, 4, 5]) ➞ True is_sorted([1, 3, 2, 4, 5]) ➞ False is_sorted([1, 2, 3, 4, 5, 6]) ➞ True is_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True is_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False is_sorted([1, 2, 2, 3, 3, 4]) ➞ True is_sorted([1, 2, 2, 2, 3, 4]) ➞ False\n '''\n | count_digit = dict([(i, 0) for i in lst])\n for i in lst:\n count_digit[i]+=1 \n if any(count_digit[i] > 2 for i in lst):\n return False\n if all(lst[i-1] <= lst[i] for i in range(1, len(lst))):\n return True\n else:\n return False\n \n \n | def check(candidate):\n\n # Check some simple cases\n assert candidate([5]) == True\n assert candidate([1, 2, 3, 4, 5]) == True\n assert candidate([1, 3, 2, 4, 5]) == False\n assert candidate([1, 2, 3, 4, 5, 6]) == True\n assert candidate([1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate([1, 3, 2, 4, 5, 6, 7]) == False, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([]) == True, "This prints if this assert fails 2 (good for debugging!)"\n assert candidate([1]) == True, "This prints if this assert fails 3 (good for debugging!)"\n assert candidate([3, 2, 1]) == False, "This prints if this assert fails 4 (good for debugging!)"\n \n # Check some edge cases that are easy to work out by hand.\n assert candidate([1, 2, 2, 2, 3, 4]) == False, "This prints if this assert fails 5 (good for debugging!)"\n assert candidate([1, 2, 3, 3, 3, 4]) == False, "This prints if this assert fails 6 (good for debugging!)"\n assert candidate([1, 2, 2, 3, 3, 4]) == True, "This prints if this assert fails 7 (good for debugging!)"\n assert candidate([1, 2, 3, 4]) == True, "This prints if this assert fails 8 (good for debugging!)"\n\n | is_sorted |
HumanEval\/127 | \ndef intersection(interval1, interval2):\n """คุณจะได้รับช่วงสองช่วง โดยแต่ละช่วงเป็นคู่ของจำนวนเต็ม ตัวอย่างเช่น ช่วง = (start, end) = (1, 2) ช่วงที่กำหนดเป็นช่วงปิด ซึ่งหมายความว่าช่วง (start, end) ประกอบด้วยทั้ง start และ end สำหรับแต่ละช่วงที่กำหนด จะถือว่า start น้อยกว่าหรือเท่ากับ end งานของคุณคือการกำหนดว่าความยาวของจุดตัดของช่วงทั้งสองนี้เป็นจำนวนเฉพาะหรือไม่ ตัวอย่างเช่น จุดตัดของช่วง (1, 3), (2, 4) คือ (2, 3) ซึ่งมีความยาวเท่ากับ 1 ซึ่งไม่ใช่จำนวนเฉพาะ หากความยาวของจุดตัดเป็นจำนวนเฉพาะ ให้ส่งคืน "YES" มิฉะนั้น ให้ส่งคืน "NO" หากช่วงทั้งสองไม่ตัดกัน ให้ส่งคืน "NO" [อินพุต\/เอาต์พุต] ตัวอย่าง: จุดตัด ((1, 2), (2, 3)) ==> "ไม่ใช่" จุดตัด ((-1, 1), (0, 4)) ==> "ไม่ใช่" จุดตัด ((-3, -1), (-5, 5)) ==> "ใช่"\n """\n | def is_prime(num):\n if num == 1 or num == 0:\n return False\n if num == 2:\n return True\n for i in range(2, num):\n if num%i == 0:\n return False\n return True\n\n l = max(interval1[0], interval2[0])\n r = min(interval1[1], interval2[1])\n length = r - l\n if length > 0 and is_prime(length):\n return "YES"\n return "NO"\n | def check(candidate):\n\n # Check some simple cases\n assert candidate((1, 2), (2, 3)) == "NO"\n assert candidate((-1, 1), (0, 4)) == "NO"\n assert candidate((-3, -1), (-5, 5)) == "YES"\n assert candidate((-2, 2), (-4, 0)) == "YES"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate((-11, 2), (-1, -1)) == "NO"\n assert candidate((1, 2), (3, 5)) == "NO"\n assert candidate((1, 2), (1, 2)) == "NO"\n assert candidate((-2, -2), (-3, -2)) == "NO"\n\n | intersection |
HumanEval\/128 | \ndef prod_signs(arr):\n """คุณจะได้รับอาร์เรย์ arr ของจำนวนเต็ม และคุณต้องส่งคืนผลรวมของขนาดของจำนวนเต็มคูณด้วยผลคูณของเครื่องหมายทั้งหมดของแต่ละจำนวนในอาร์เรย์ ซึ่งแสดงด้วย 1, -1 หรือ 0 หมายเหตุ: ส่งคืน None สำหรับ arr ที่ว่างเปล่า ตัวอย่าง:\n >>> prod_signs([1, 2, 2, -4]) == -9\n >>> prod_signs([0, 1]) == 0\n >>> prod_signs([]) == None"""\n | if not arr: return None\n prod = 0 if 0 in arr else (-1) ** len(list(filter(lambda x: x < 0, arr)))\n return prod * sum([abs(i) for i in arr])\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, 2, 2, -4]) == -9\n assert candidate([0, 1]) == 0\n assert candidate([1, 1, 1, 2, 3, -1, 1]) == -10\n assert candidate([]) == None\n assert candidate([2, 4,1, 2, -1, -1, 9]) == 20\n assert candidate([-1, 1, -1, 1]) == 4\n assert candidate([-1, 1, 1, 1]) == -4\n assert candidate([-1, 1, 1, 0]) == 0\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | prod_signs |
HumanEval\/129 | \ndef minPath(grid, k):\n """กำหนดตารางที่มี N แถวและ N คอลัมน์ (N >= 2) และจำนวนเต็มบวก k เซลล์แต่ละเซลล์ของตารางจะมีค่า จำนวนเต็มทุกจำนวนในช่วง [1, N * N] รวมอยู่ด้วยจะปรากฏบนเซลล์ของตารางเพียงครั้งเดียว คุณต้องค้นหาเส้นทางที่สั้นที่สุดของความยาว k ในตาราง คุณสามารถเริ่มต้นจากเซลล์ใดก็ได้ และในแต่ละขั้นตอน คุณสามารถย้ายไปยังเซลล์ข้างเคียงเซลล์ใดก็ได้ กล่าวอีกนัยหนึ่งคือ คุณสามารถไปยังเซลล์ที่แบ่งปันขอบกับเซลล์ปัจจุบันของคุณได้ โปรดทราบว่าเส้นทางที่มีความยาว k หมายถึงการเยี่ยมชมเซลล์ k พอดี (ไม่จำเป็นต้องแยกจากกัน) คุณไม่สามารถออกจากตารางได้ เส้นทาง A (ความยาว k) ถือว่าน้อยกว่าเส้นทาง B (ความยาว k) หากหลังจากสร้างรายการค่าตามลำดับในเซลล์ที่ A และ B ผ่าน (เรียกว่า lst_A และ lst_B) แล้ว lst_A จะน้อยกว่า lst_B ตามพจนานุกรม กล่าวอีกนัยหนึ่งคือ มีดัชนีจำนวนเต็ม i (1 <= i <= k) ที่ทำให้ lst_A[i] < lst_B[i] และสำหรับ j ใดๆ (1 <= j < i) เราจะได้ lst_A[j] = lst_B[j] รับประกันว่าคำตอบจะไม่ซ้ำกัน ส่งคืนรายการค่าตามลำดับในเซลล์ที่เส้นทางขั้นต่ำผ่าน ตัวอย่าง: อินพุต: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3 เอาต์พุต: [1, 2, 1] อินพุต: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1 เอาต์พุต: [1]\n """\n | n = len(grid)\n val = n * n + 1\n for i in range(n):\n for j in range(n):\n if grid[i][j] == 1:\n temp = []\n if i != 0:\n temp.append(grid[i - 1][j])\n\n if j != 0:\n temp.append(grid[i][j - 1])\n\n if i != n - 1:\n temp.append(grid[i + 1][j])\n\n if j != n - 1:\n temp.append(grid[i][j + 1])\n\n val = min(temp)\n\n ans = []\n for i in range(k):\n if i % 2 == 0:\n ans.append(1)\n else:\n ans.append(val)\n return ans\n | def check(candidate):\n\n # Check some simple cases\n print\n assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1]\n assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1]\n assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2]\n assert candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7) == [1, 10, 1, 10, 1, 10, 1]\n assert candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5) == [1, 7, 1, 7, 1]\n assert candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1]\n assert candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]\n assert candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8) == [1, 3, 1, 3, 1, 3, 1, 3]\n assert candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8) == [1, 5, 1, 5, 1, 5, 1, 5]\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([[1, 2], [3, 4]], 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]\n assert candidate([[1, 3], [3, 2]], 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]\n\n | minPath |
HumanEval\/130 | \ndef tri(n):\n """ทุกคนรู้จักลำดับฟีโบนัชชี ซึ่งนักคณิตศาสตร์ได้ศึกษาอย่างลึกซึ้งในช่วงสองศตวรรษที่ผ่านมา อย่างไรก็ตาม สิ่งที่ผู้คนไม่รู้ก็คือลำดับทริโบนัชชี ลำดับทริโบนัชชีถูกกำหนดโดยการเกิดซ้ำ: tri(1) = 3 tri(n) = 1 + n \/ 2 ถ้า n เป็นเลขคู่ tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1) ถ้า n เป็นเลขคี่ ตัวอย่างเช่น: tri(2) = 1 + (2 \/ 2) = 2 tri(4) = 3 tri(3) = tri(2) + tri(1) + tri(4) = 2 + 3 + 3 = 8 คุณได้รับเลขจำนวนเต็มที่ไม่เป็นลบ n คุณต้องส่งคืนรายการของตัวเลข n + 1 แรกของลำดับทริโบนัชชี ตัวอย่าง: tri(3) = [1, 3, 2, 8]\n """\n | if n == 0:\n return [1]\n my_tri = [1, 3]\n for i in range(2, n + 1):\n if i % 2 == 0:\n my_tri.append(i \/ 2 + 1)\n else:\n my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) \/ 2)\n return my_tri\n | def check(candidate):\n\n # Check some simple cases\n \n assert candidate(3) == [1, 3, 2.0, 8.0]\n assert candidate(4) == [1, 3, 2.0, 8.0, 3.0]\n assert candidate(5) == [1, 3, 2.0, 8.0, 3.0, 15.0]\n assert candidate(6) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0]\n assert candidate(7) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0]\n assert candidate(8) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0]\n assert candidate(9) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0]\n assert candidate(20) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0, 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0]\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(0) == [1]\n assert candidate(1) == [1, 3]\n | tri |
HumanEval\/131 | \ndef digits(n):\n """กำหนดจำนวนเต็มบวก n ให้ส่งคืนผลคูณของหลักคี่ ส่งคืน 0 ถ้าหลักทั้งหมดเป็นเลขคู่ ตัวอย่างเช่น: digits(1) == 1 digits(4) == 0 digits(235) == 15\n """\n | product = 1\n odd_count = 0\n for digit in str(n):\n int_digit = int(digit)\n if int_digit%2 == 1:\n product= product*int_digit\n odd_count+=1\n if odd_count ==0:\n return 0\n else:\n return product\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(5) == 5\n assert candidate(54) == 5\n assert candidate(120) ==1\n assert candidate(5014) == 5\n assert candidate(98765) == 315\n assert candidate(5576543) == 2625\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(2468) == 0\n\n | digits |
HumanEval\/132 | \ndef is_nested(string):\n '''สร้างฟังก์ชันที่รับสตริงเป็นอินพุตซึ่งประกอบด้วยวงเล็บเหลี่ยมเท่านั้น ฟังก์ชันควรส่งคืนค่า True ก็ต่อเมื่อมีลำดับย่อยที่ถูกต้องของวงเล็บซึ่งวงเล็บอย่างน้อยหนึ่งอันในลำดับย่อยนั้นซ้อนกัน is_nested(\'[[]]\') ➞ True is_nested(\'[[]]]]]]][[[[[]\') ➞ False is_nested(\'[][]\') ➞ False is_nested(\'[[][]\') ➞ False is_nested(\'[[][]]\') ➞ True is_nested(\'[[]][[\') ➞ True\n '''\n | opening_bracket_index = []\n closing_bracket_index = []\n for i in range(len(string)):\n if string[i] == '[':\n opening_bracket_index.append(i)\n else:\n closing_bracket_index.append(i)\n closing_bracket_index.reverse()\n cnt = 0\n i = 0\n l = len(closing_bracket_index)\n for idx in opening_bracket_index:\n if i < l and idx < closing_bracket_index[i]:\n cnt += 1\n i += 1\n return cnt >= 2\n\n \n | def check(candidate):\n\n # Check some simple cases\n assert candidate('[[]]') == True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate('[]]]]]]][[[[[]') == False\n assert candidate('[][]') == False\n assert candidate(('[]')) == False\n assert candidate('[[[[]]]]') == True\n assert candidate('[]]]]]]]]]]') == False\n assert candidate('[][][[]]') == True\n assert candidate('[[]') == False\n assert candidate('[]]') == False\n assert candidate('[[]][[') == True\n assert candidate('[[][]]') == True\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('') == False, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate('[[[[[[[[') == False\n assert candidate(']]]]]]]]') == False\n\n | is_nested |
HumanEval\/133 | \n\ndef sum_squares(lst):\n """คุณจะได้รับรายการตัวเลข คุณต้องส่งคืนผลรวมของตัวเลขยกกำลังสองในรายการที่กำหนด ปัดเศษแต่ละองค์ประกอบในรายการเป็น int(Ceiling) บนสุดก่อน ตัวอย่าง: สำหรับ lst = [1,2,3] ผลลัพธ์ควรเป็น 14 สำหรับ lst = [1,4,9] ผลลัพธ์ควรเป็น 98 สำหรับ lst = [1,3,5,7] ผลลัพธ์ควรเป็น 84 สำหรับ lst = [1.4,4.2,0] ผลลัพธ์ควรเป็น 29 สำหรับ lst = [-2.4,1,1] ผลลัพธ์ควรเป็น 6\n """\n | import math\n squared = 0\n for i in lst:\n squared += math.ceil(i)**2\n return squared\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,3])==14, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([1.0,2,3])==14, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([1,3,5,7])==84, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([1.4,4.2,0])==29, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([-2.4,1,1])==6, "This prints if this assert fails 1 (good for debugging!)"\n\n assert candidate([100,1,15,2])==10230, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([10000,10000])==200000000, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([-1.4,4.6,6.3])==75, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([-1.4,17.9,18.9,19.9])==1086, "This prints if this assert fails 1 (good for debugging!)"\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([0])==0, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([-1])==1, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate([-1,1,0])==2, "This prints if this assert fails 2 (also good for debugging!)"\n\n | sum_squares |
HumanEval\/134 | \ndef check_if_last_char_is_a_letter(txt):\n '''สร้างฟังก์ชันที่ส่งคืนค่า True หากอักขระตัวสุดท้ายของสตริงที่กำหนดเป็นอักขระตัวอักษรและไม่ใช่ส่วนหนึ่งของคำ และส่งคืนค่า False หากไม่เป็นเช่นนั้น หมายเหตุ: "word" คือกลุ่มอักขระที่คั่นด้วยช่องว่าง ตัวอย่าง: check_if_last_char_is_a_letter("apple pie") ➞ False check_if_last_char_is_a_letter("apple pi e") ➞ True check_if_last_char_is_a_letter("apple pi e ") ➞ False check_if_last_char_is_a_letter("") ➞ False\n '''\n | \n check = txt.split(' ')[-1]\n return True if len(check) == 1 and (97 <= ord(check.lower()) <= 122) else False\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("apple") == False\n assert candidate("apple pi e") == True\n assert candidate("eeeee") == False\n assert candidate("A") == True\n assert candidate("Pumpkin pie ") == False\n assert candidate("Pumpkin pie 1") == False\n assert candidate("") == False\n assert candidate("eeeee e ") == False\n assert candidate("apple pie") == False\n assert candidate("apple pi e ") == False\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | check_if_last_char_is_a_letter |
HumanEval\/135 | \ndef can_arrange(arr):\n """สร้างฟังก์ชันที่ส่งคืนดัชนีที่ใหญ่ที่สุดขององค์ประกอบซึ่งไม่มากกว่าหรือเท่ากับองค์ประกอบก่อนหน้าทันที หากไม่มีองค์ประกอบดังกล่าว ให้ส่งคืน -1 อาร์เรย์ที่กำหนดจะไม่มีค่าซ้ำกัน ตัวอย่าง: can_arrange([1,2,4,3,5]) = 3 can_arrange([1,2,3]) = -1\n """\n | ind=-1\n i=1\n while i<len(arr):\n if arr[i]<arr[i-1]:\n ind=i\n i+=1\n return ind\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,4,3,5])==3\n assert candidate([1,2,4,5])==-1\n assert candidate([1,4,2,5,6,7,8,9,10])==2\n assert candidate([4,8,5,7,3])==4\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([])==-1\n\n | can_arrange |
HumanEval\/136 | \ndef largest_smallest_integers(lst):\n '''สร้างฟังก์ชันที่ส่งคืนทูเพิล (a, b) โดยที่ \'a\' คือจำนวนเต็มลบที่ใหญ่ที่สุด และ \'b\' คือจำนวนเต็มบวกที่น้อยที่สุดในรายการ ถ้าไม่มีจำนวนเต็มลบหรือบวก ให้ส่งคืนเป็น None ตัวอย่าง: largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1) largest_smallest_integers([]) == (None, None) largest_smallest_integers([0]) == (None, None)\n '''\n | smallest = list(filter(lambda x: x < 0, lst))\n largest = list(filter(lambda x: x > 0, lst))\n return (max(smallest) if smallest else None, min(largest) if largest else None)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([2, 4, 1, 3, 5, 7]) == (None, 1)\n assert candidate([2, 4, 1, 3, 5, 7, 0]) == (None, 1)\n assert candidate([1, 3, 2, 4, 5, 6, -2]) == (-2, 1)\n assert candidate([4, 5, 3, 6, 2, 7, -7]) == (-7, 2)\n assert candidate([7, 3, 8, 4, 9, 2, 5, -9]) == (-9, 2)\n assert candidate([]) == (None, None)\n assert candidate([0]) == (None, None)\n assert candidate([-1, -3, -5, -6]) == (-1, None)\n assert candidate([-1, -3, -5, -6, 0]) == (-1, None)\n assert candidate([-6, -4, -4, -3, 1]) == (-3, 1)\n assert candidate([-6, -4, -4, -3, -100, 1]) == (-3, 1)\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n | largest_smallest_integers |
HumanEval\/137 | \ndef compare_one(a, b):\n """สร้างฟังก์ชันที่ใช้จำนวนเต็ม จำนวนทศนิยม หรือสตริงที่แสดงถึงจำนวนจริง และส่งคืนตัวแปรที่มีค่ามากกว่าในประเภทตัวแปรที่กำหนด ส่งคืนค่า None หากค่าเท่ากัน หมายเหตุ: หากแสดงจำนวนจริงเป็นสตริง จุดทศนิยมอาจเป็น . หรือ , compare_one(1, 2.5) ➞ 2.5 compare_one(1, "2,3") ➞ "2,3" compare_one("5,1", "6") ➞ "6" compare_one("1", 1) ➞ None\n """\n | temp_a, temp_b = a, b\n if isinstance(temp_a, str): temp_a = temp_a.replace(',','.')\n if isinstance(temp_b, str): temp_b = temp_b.replace(',','.')\n if float(temp_a) == float(temp_b): return None\n return a if float(temp_a) > float(temp_b) else b \n | def check(candidate):\n\n # Check some simple cases\n assert candidate(1, 2) == 2\n assert candidate(1, 2.5) == 2.5\n assert candidate(2, 3) == 3\n assert candidate(5, 6) == 6\n assert candidate(1, "2,3") == "2,3"\n assert candidate("5,1", "6") == "6"\n assert candidate("1", "2") == "2"\n assert candidate("1", 1) == None\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | compare_one |
HumanEval\/138 | \ndef is_equal_to_sum_even(n):\n """ประเมินว่าตัวเลข n ที่กำหนดสามารถเขียนเป็นผลรวมของจำนวนคู่บวก 4 จำนวนพอดีหรือไม่ ตัวอย่าง is_equal_to_sum_even(4) == False is_equal_to_sum_even(6) == False is_equal_to_sum_even(8) == True\n """\n | return n%2 == 0 and n >= 8\n | def check(candidate):\n assert candidate(4) == False\n assert candidate(6) == False\n assert candidate(8) == True\n assert candidate(10) == True\n assert candidate(11) == False\n assert candidate(12) == True\n assert candidate(13) == False\n assert candidate(16) == True\n | is_equal_to_sum_even |
HumanEval\/139 | \ndef special_factorial(n):\n """แฟกทอเรียลของบราซิลถูกกำหนดเป็น: brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! โดยที่ n > 0 ตัวอย่างเช่น:\n >>> special_factorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer."""\n | fact_i = 1\n special_fact = 1\n for i in range(1, n+1):\n fact_i *= i\n special_fact *= fact_i\n return special_fact\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(4) == 288, "Test 4"\n assert candidate(5) == 34560, "Test 5"\n assert candidate(7) == 125411328000, "Test 7"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1) == 1, "Test 1"\n\n | special_factorial |
HumanEval\/140 | \ndef fix_spaces(text):\n """กำหนดข้อความสตริง ให้แทนที่ช่องว่างทั้งหมดด้วยเครื่องหมายขีดล่าง และถ้าสตริงมีช่องว่างติดต่อกันมากกว่า 2 ช่องว่าง ให้แทนที่ช่องว่างติดต่อกันทั้งหมดด้วย - fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Example_1" fix_spaces(" Example 2") == "_Example_2" fix_spaces(" Example 3") == "_Example-3"\n """\n | new_text = ""\n i = 0\n start, end = 0, 0\n while i < len(text):\n if text[i] == " ":\n end += 1\n else:\n if end - start > 2:\n new_text += "-"+text[i]\n elif end - start > 0:\n new_text += "_"*(end - start)+text[i]\n else:\n new_text += text[i]\n start, end = i+1, i+1\n i+=1\n if end - start > 2:\n new_text += "-"\n elif end - start > 0:\n new_text += "_"\n return new_text\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("Example") == "Example", "This prints if this assert fails 1 (good for debugging!)"\n assert candidate("Mudasir Hanif ") == "Mudasir_Hanif_", "This prints if this assert fails 2 (good for debugging!)"\n assert candidate("Yellow Yellow Dirty Fellow") == "Yellow_Yellow__Dirty__Fellow", "This prints if this assert fails 3 (good for debugging!)"\n \n # Check some edge cases that are easy to work out by hand.\n assert candidate("Exa mple") == "Exa-mple", "This prints if this assert fails 4 (good for debugging!)"\n assert candidate(" Exa 1 2 2 mple") == "-Exa_1_2_2_mple", "This prints if this assert fails 4 (good for debugging!)"\n\n | fix_spaces |
HumanEval\/141 | \ndef file_name_check(file_name):\n """สร้างฟังก์ชันที่รับสตริงที่แสดงชื่อไฟล์ และส่งคืน \'ใช่\' หากชื่อไฟล์ถูกต้อง และส่งกลับ \'ไม่ใช่\' หากไม่เป็นเช่นนั้น ชื่อไฟล์จะถือว่าถูกต้องก็ต่อเมื่อตรงตามเงื่อนไขต่อไปนี้ทั้งหมดเท่านั้น: - ชื่อไฟล์ไม่ควรมีตัวเลขเกินสามหลัก (\'0\'-\'9\') - ชื่อไฟล์มีจุด ".\' เพียงหนึ่งจุด - สตริงย่อยก่อนจุดไม่ควรว่างเปล่า และเริ่มต้นด้วยตัวอักษรจากภาษาละติน alphapet (\'a\'-\'z\' และ \'A\'-\'Z\') - สตริงย่อยหลังจุดควรเป็นอย่างใดอย่างหนึ่งจากนี้: [\'txt\', \'exe\', \'dll\'] ตัวอย่าง: file_name_check("example.txt") # => \'Yes\' file_name_check("1example.dll") # => \'No\' (ชื่อควรเริ่มต้นด้วยตัวอักษรละติน alphapet)\n """\n | suf = ['txt', 'exe', 'dll']\n lst = file_name.split(sep='.')\n if len(lst) != 2:\n return 'No'\n if not lst[1] in suf:\n return 'No'\n if len(lst[0]) == 0:\n return 'No'\n if not lst[0][0].isalpha():\n return 'No'\n t = len([x for x in lst[0] if x.isdigit()])\n if t > 3:\n return 'No'\n return 'Yes'\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("example.txt") == 'Yes'\n assert candidate("1example.dll") == 'No'\n assert candidate('s1sdf3.asd') == 'No'\n assert candidate('K.dll') == 'Yes'\n assert candidate('MY16FILE3.exe') == 'Yes'\n assert candidate('His12FILE94.exe') == 'No'\n assert candidate('_Y.txt') == 'No'\n assert candidate('?aREYA.exe') == 'No'\n assert candidate('\/this_is_valid.dll') == 'No'\n assert candidate('this_is_valid.wow') == 'No'\n assert candidate('this_is_valid.txt') == 'Yes'\n assert candidate('this_is_valid.txtexe') == 'No'\n assert candidate('#this2_i4s_5valid.ten') == 'No'\n assert candidate('@this1_is6_valid.exe') == 'No'\n assert candidate('this_is_12valid.6exe4.txt') == 'No'\n assert candidate('all.exe.txt') == 'No'\n assert candidate('I563_No.exe') == 'Yes'\n assert candidate('Is3youfault.txt') == 'Yes'\n assert candidate('no_one#knows.dll') == 'Yes'\n assert candidate('1I563_Yes3.exe') == 'No'\n assert candidate('I563_Yes3.txtt') == 'No'\n assert candidate('final..txt') == 'No'\n assert candidate('final132') == 'No'\n assert candidate('_f4indsartal132.') == 'No'\n \n \n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('.txt') == 'No'\n assert candidate('s.') == 'No'\n\n | file_name_check |
HumanEval\/142 | \n\n\ndef sum_squares(lst):\n """" ฟังก์ชันนี้จะใช้รายการจำนวนเต็ม สำหรับรายการทั้งหมดในรายการ ฟังก์ชันจะต้องยกกำลังรายการจำนวนเต็มหากดัชนีของฟังก์ชันเป็นผลคูณของ 3 และจะยกกำลังรายการจำนวนเต็มหากดัชนีของฟังก์ชันเป็นผลคูณของ 4 และไม่ใช่เป็นผลคูณของ 3 ฟังก์ชันจะไม่เปลี่ยนแปลงรายการในรายการที่มีดัชนีไม่ใช่ผลคูณของ 3 หรือ 4 ฟังก์ชันจะส่งคืนผลรวมของรายการทั้งหมด ตัวอย่าง: สำหรับ lst = [1,2,3] ผลลัพธ์ควรเป็น 6 สำหรับ lst = [] ผลลัพธ์ควรเป็น 0 สำหรับ lst = [-1,-5,2,-1,-5] ผลลัพธ์ควรเป็น -126\n """\n | result =[]\n for i in range(len(lst)):\n if i %3 == 0:\n result.append(lst[i]**2)\n elif i % 4 == 0 and i%3 != 0:\n result.append(lst[i]**3)\n else:\n result.append(lst[i])\n return sum(result)\n | def check(candidate):\n\n # Check some simple cases\n \n assert candidate([1,2,3]) == 6\n assert candidate([1,4,9]) == 14\n assert candidate([]) == 0\n assert candidate([1,1,1,1,1,1,1,1,1]) == 9\n assert candidate([-1,-1,-1,-1,-1,-1,-1,-1,-1]) == -3\n assert candidate([0]) == 0\n assert candidate([-1,-5,2,-1,-5]) == -126\n assert candidate([-56,-99,1,0,-2]) == 3030\n assert candidate([-1,0,0,0,0,0,0,0,-1]) == 0\n assert candidate([-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]) == -14196\n assert candidate([-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]) == -1448\n \n \n # Don't remove this line:\n | sum_squares |
HumanEval\/143 | \ndef words_in_sentence(sentence):\n """คุณจะได้รับสตริงที่แสดงถึงประโยค ประโยคประกอบด้วยคำบางคำที่คั่นด้วยช่องว่าง และคุณต้องส่งคืนสตริงที่มีคำจากประโยคเดิม ซึ่งความยาวเป็นจำนวนเฉพาะ ลำดับของคำในสตริงใหม่ควรเหมือนกับของเดิม ตัวอย่างที่ 1: อินพุต: ประโยค = "This is a test" เอาต์พุต: "is" ตัวอย่างที่ 2: อินพุต: ประโยค = "lets go for swimming" เอาต์พุต: "go for" ข้อจำกัด: * 1 <= len(sentence) <= 100 * ประโยคประกอบด้วยตัวอักษรเท่านั้น\n """\n | new_lst = []\n for word in sentence.split():\n flg = 0\n if len(word) == 1:\n flg = 1\n for i in range(2, len(word)):\n if len(word)%i == 0:\n flg = 1\n if flg == 0 or len(word) == 2:\n new_lst.append(word)\n return " ".join(new_lst)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("This is a test") == "is"\n assert candidate("lets go for swimming") == "go for"\n assert candidate("there is no place available here") == "there is no place"\n assert candidate("Hi I am Hussein") == "Hi am Hussein"\n assert candidate("go for it") == "go for it"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate("here") == ""\n assert candidate("here is") == "is"\n\n | words_in_sentence |
HumanEval\/144 | \ndef simplify(x, n):\n """งานของคุณคือการใช้ฟังก์ชันที่จะทำให้นิพจน์ x * n ง่ายขึ้น ฟังก์ชันนี้จะคืนค่า True หาก x * n ประเมินผลเป็นจำนวนเต็ม และคืนค่า False หากไม่เช่นนั้น ทั้ง x และ n ต่างก็เป็นสตริงที่แสดงเศษส่วน และมีรูปแบบดังต่อไปนี้<numerator> -<denominator> โดยที่ตัวเศษและตัวส่วนเป็นจำนวนเต็มบวกทั้งคู่ คุณสามารถถือว่า x และ n เป็นเศษส่วนที่ถูกต้อง และไม่มีศูนย์เป็นตัวส่วน simplify("1\/5", "5\/1") = True simplify("1\/6", "2\/1") = False simplify("7\/10", "10\/2") = False\n """\n | a, b = x.split("\/")\n c, d = n.split("\/")\n numerator = int(a) * int(c)\n denom = int(b) * int(d)\n if (numerator\/denom == int(numerator\/denom)):\n return True\n return False\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("1\/5", "5\/1") == True, 'test1'\n assert candidate("1\/6", "2\/1") == False, 'test2'\n assert candidate("5\/1", "3\/1") == True, 'test3'\n assert candidate("7\/10", "10\/2") == False, 'test4'\n assert candidate("2\/10", "50\/10") == True, 'test5'\n assert candidate("7\/2", "4\/2") == True, 'test6'\n assert candidate("11\/6", "6\/1") == True, 'test7'\n assert candidate("2\/3", "5\/2") == False, 'test8'\n assert candidate("5\/2", "3\/5") == False, 'test9'\n assert candidate("2\/4", "8\/4") == True, 'test10'\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate("2\/4", "4\/2") == True, 'test11'\n assert candidate("1\/5", "5\/1") == True, 'test12'\n assert candidate("1\/5", "1\/5") == False, 'test13'\n\n | simplify |
HumanEval\/145 | \ndef order_by_points(nums):\n """เขียนฟังก์ชันที่เรียงลำดับรายการจำนวนเต็มที่กำหนดตามลำดับจากน้อยไปมากตามผลรวมของตัวเลข หมายเหตุ: หากมีรายการหลายรายการที่ผลรวมของตัวเลขใกล้เคียงกัน ให้เรียงลำดับตามดัชนีในรายการเดิม ตัวอย่างเช่น:\n >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> order_by_points([]) == []"""\n | def digits_sum(n):\n neg = 1\n if n < 0: n, neg = -1 * n, -1 \n n = [int(i) for i in str(n)]\n n[0] = n[0] * neg\n return sum(n)\n return sorted(nums, key=digits_sum)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n assert candidate([1234,423,463,145,2,423,423,53,6,37,3457,3,56,0,46]) == [0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457]\n assert candidate([]) == []\n assert candidate([1, -11, -32, 43, 54, -98, 2, -3]) == [-3, -32, -98, -11, 1, 2, 43, 54]\n assert candidate([1,2,3,4,5,6,7,8,9,10,11]) == [1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9]\n assert candidate([0,6,6,-76,-21,23,4]) == [-76, -21, 0, 4, 23, 6, 6]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | order_by_points |
HumanEval\/146 | \ndef specialFilter(nums):\n """เขียนฟังก์ชันที่รับอาร์เรย์ของตัวเลขเป็นอินพุตและส่งคืนจำนวนองค์ประกอบในอาร์เรย์ที่มากกว่า 10 และหลักแรกและหลักสุดท้ายของตัวเลขเป็นเลขคี่ (1, 3, 5, 7, 9) ตัวอย่างเช่น: specialFilter([15, -73, 14, -15]) => 1 specialFilter([33, -2, -3, 45, 21, 109]) => 2\n """\n | \n count = 0\n for num in nums:\n if num > 10:\n odd_digits = (1, 3, 5, 7, 9)\n number_as_string = str(num)\n if int(number_as_string[0]) in odd_digits and int(number_as_string[-1]) in odd_digits:\n count += 1\n \n return count \n | def check(candidate):\n\n # Check some simple cases\n assert candidate([5, -2, 1, -5]) == 0 \n assert candidate([15, -73, 14, -15]) == 1\n assert candidate([33, -2, -3, 45, 21, 109]) == 2\n assert candidate([43, -12, 93, 125, 121, 109]) == 4\n assert candidate([71, -2, -33, 75, 21, 19]) == 3\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1]) == 0 \n assert candidate([]) == 0 \n\n | specialFilter |
HumanEval\/147 | \ndef get_max_triples(n):\n """คุณได้รับจำนวนเต็มบวก n คุณต้องสร้างอาร์เรย์จำนวนเต็ม a ที่มีความยาว n สำหรับแต่ละ i (1 ≤ i ≤ n) ค่าของ a[i] = i * i - i + 1 ส่งกลับจำนวนสาม (a[i], a[j], a[k]) ของ a โดยที่ i < j < k และ a[i] + a[j] + a[k] เป็นทวีคูณของ 3 ตัวอย่าง: อินพุต: n = 5 เอาต์พุต: 1 คำอธิบาย: a = [1, 3, 7, 13, 21] สามที่ถูกต้องคือ (1, 7, 13) เท่านั้น\n """\n | A = [i*i - i + 1 for i in range(1,n+1)]\n ans = []\n for i in range(n):\n for j in range(i+1,n):\n for k in range(j+1,n):\n if (A[i]+A[j]+A[k])%3 == 0:\n ans += [(A[i],A[j],A[k])]\n return len(ans)\n | def check(candidate):\n\n assert candidate(5) == 1\n assert candidate(6) == 4\n assert candidate(10) == 36\n assert candidate(100) == 53361\n | get_max_triples |
HumanEval\/148 | \ndef bf(planet1, planet2):\n '''ในระบบสุริยะของเรามีดาวเคราะห์ 8 ดวง ดวงที่อยู่ใกล้ดวงอาทิตย์ที่สุดคือดาวพุธ ดวงถัดมาคือดาวศุกร์ จากนั้นคือโลก ดาวอังคาร ดาวพฤหัสบดี ดาวเสาร์ ดาวยูเรนัส ดาวเนปจูน เขียนฟังก์ชันที่รับชื่อดาวเคราะห์ 2 ดวงเป็นสตริง ได้แก่ planet1 และ planet2 ฟังก์ชันควรส่งคืนทูเพิลที่มีดาวเคราะห์ทั้งหมดที่มีวงโคจรอยู่ระหว่างวงโคจรของ planet1 และวงโคจรของ planet2 โดยเรียงลำดับตามระยะห่างจากดวงอาทิตย์ ฟังก์ชันควรส่งคืนทูเพิลว่างหาก planet1 หรือ planet2 ไม่ใช่ชื่อดาวเคราะห์ที่ถูกต้อง ตัวอย่าง bf("Jupiter", "Neptune") ==> ("Saturn", "Uranus") bf("Earth", "Mercury") ==> ("Venus") bf("Mercury", "Uranus") ==> ("Venus", "Earth", "Mars", "Jupiter", "Saturn")\n '''\n | planet_names = ("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune")\n if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2:\n return ()\n planet1_index = planet_names.index(planet1)\n planet2_index = planet_names.index(planet2)\n if planet1_index < planet2_index:\n return (planet_names[planet1_index + 1: planet2_index])\n else:\n return (planet_names[planet2_index + 1 : planet1_index])\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("Jupiter", "Neptune") == ("Saturn", "Uranus"), "First test error: " + str(len(candidate("Jupiter", "Neptune"))) \n assert candidate("Earth", "Mercury") == ("Venus",), "Second test error: " + str(candidate("Earth", "Mercury")) \n assert candidate("Mercury", "Uranus") == ("Venus", "Earth", "Mars", "Jupiter", "Saturn"), "Third test error: " + str(candidate("Mercury", "Uranus")) \n assert candidate("Neptune", "Venus") == ("Earth", "Mars", "Jupiter", "Saturn", "Uranus"), "Fourth test error: " + str(candidate("Neptune", "Venus")) \n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate("Earth", "Earth") == ()\n assert candidate("Mars", "Earth") == ()\n assert candidate("Jupiter", "Makemake") == ()\n\n | bf |
HumanEval\/149 | \ndef sorted_list_sum(lst):\n """เขียนฟังก์ชันที่ยอมรับรายการสตริงเป็นพารามิเตอร์ ลบสตริงที่มีความยาวคี่ และส่งคืนรายการผลลัพธ์ที่มีลำดับการเรียงลำดับ รายการจะเป็นรายการสตริงเสมอ ไม่ใช่เป็นอาร์เรย์ของตัวเลข และอาจมีรายการที่ซ้ำกันได้ ลำดับของรายการควรเรียงจากน้อยไปมากตามความยาวของคำแต่ละคำ และคุณควรส่งคืนรายการที่เรียงลำดับตามกฎนั้น หากคำสองคำมีความยาวเท่ากัน ให้เรียงลำดับรายการตามตัวอักษร ฟังก์ชันควรส่งคืนรายการสตริงที่เรียงลำดับแล้ว คุณอาจถือว่าคำทั้งหมดจะมีความยาวเท่ากัน ตัวอย่างเช่น: assert list_sort(["aa", "a", "aaa"]) => ["aa"] assert list_sort(["ab", "a", "aaa", "cd"]) => ["ab", "cd"]\n """\n | lst.sort()\n new_lst = []\n for i in lst:\n if len(i)%2 == 0:\n new_lst.append(i)\n return sorted(new_lst, key=len)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(["aa", "a", "aaa"]) == ["aa"]\n assert candidate(["school", "AI", "asdf", "b"]) == ["AI", "asdf", "school"]\n assert candidate(["d", "b", "c", "a"]) == []\n assert candidate(["d", "dcba", "abcd", "a"]) == ["abcd", "dcba"]\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(["AI", "ai", "au"]) == ["AI", "ai", "au"]\n assert candidate(["a", "b", "b", "c", "c", "a"]) == []\n assert candidate(['aaaa', 'bbbb', 'dd', 'cc']) == ["cc", "dd", "aaaa", "bbbb"]\n\n | sorted_list_sum |
HumanEval\/150 | \ndef x_or_y(n, x, y):\n """โปรแกรมง่ายๆ ที่ควรส่งคืนค่าของ x หาก n เป็นจำนวนเฉพาะ และควรส่งคืนค่าของ y ในกรณีอื่น ตัวอย่าง: for x_or_y(7, 34, 12) == 34 for x_or_y(15, 8, 5) == 5\n """\n | if n == 1:\n return y\n for i in range(2, n):\n if n % i == 0:\n return y\n break\n else:\n return x\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(7, 34, 12) == 34\n assert candidate(15, 8, 5) == 5\n assert candidate(3, 33, 5212) == 33\n assert candidate(1259, 3, 52) == 3\n assert candidate(7919, -1, 12) == -1\n assert candidate(3609, 1245, 583) == 583\n assert candidate(91, 56, 129) == 129\n assert candidate(6, 34, 1234) == 1234\n \n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1, 2, 0) == 0\n assert candidate(2, 2, 0) == 2\n\n | x_or_y |
HumanEval\/151 | \ndef double_the_difference(lst):\n '''กำหนดรายการตัวเลข ให้ส่งคืนผลรวมของกำลังสองของตัวเลขในรายการที่เป็นเลขคี่ ไม่ต้องสนใจตัวเลขที่เป็นจำนวนเต็มลบหรือไม่ใช่จำนวนเต็ม double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10 double_the_difference([-1, -2, 0]) == 0 double_the_difference([9, -2]) == 81 double_the_difference([0]) == 0 ถ้ารายการอินพุตว่างเปล่า ให้ส่งคืน 0\n '''\n | return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([]) == 0 , "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([5, 4]) == 25 , "This prints if this assert fails 2 (good for debugging!)"\n assert candidate([0.1, 0.2, 0.3]) == 0 , "This prints if this assert fails 3 (good for debugging!)"\n assert candidate([-10, -20, -30]) == 0 , "This prints if this assert fails 4 (good for debugging!)"\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([-1, -2, 8]) == 0, "This prints if this assert fails 5 (also good for debugging!)"\n assert candidate([0.2, 3, 5]) == 34, "This prints if this assert fails 6 (also good for debugging!)"\n lst = list(range(-99, 100, 2))\n odd_sum = sum([i**2 for i in lst if i%2!=0 and i > 0])\n assert candidate(lst) == odd_sum , "This prints if this assert fails 7 (good for debugging!)"\n\n | double_the_difference |
HumanEval\/152 | \ndef compare(game,guess):\n """ฉันคิดว่าเราทุกคนคงจำความรู้สึกนั้นได้เมื่อผลลัพธ์ของเหตุการณ์ที่รอคอยมานานในที่สุดก็ถูกเปิดเผย ความรู้สึกและความคิดที่คุณมีในขณะนั้นคุ้มค่าแก่การจดบันทึกและเปรียบเทียบอย่างแน่นอน หน้าที่ของคุณคือตรวจสอบว่าบุคคลนั้นเดาผลลัพธ์ของการจับคู่จำนวนหนึ่งได้ถูกต้องหรือไม่ คุณจะได้รับอาร์เรย์คะแนนและการเดาสองชุดที่มีความยาวเท่ากัน โดยแต่ละดัชนีจะแสดงการจับคู่ที่ตรงกัน ส่งคืนอาร์เรย์ที่มีความยาวเท่ากันเพื่อระบุว่าการเดาแต่ละครั้งนั้นคลาดเคลื่อนแค่ไหน หากพวกเขาเดาถูก ค่าจะเป็น 0 และหากไม่ใช่ ค่าจะเป็นความแตกต่างสัมบูรณ์ระหว่างการเดาและคะแนน ตัวอย่าง: compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3] compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n """\n | return [abs(x-y) for x,y in zip(game,guess)]\n | def check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,3,4,5,1],[1,2,3,4,2,-2])==[0,0,0,0,3,3], "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([0,0,0,0,0,0],[0,0,0,0,0,0])==[0,0,0,0,0,0], "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([1,2,3],[-1,-2,-3])==[2,4,6], "This prints if this assert fails 1 (good for debugging!)"\n assert candidate([1,2,3,5],[-1,2,3,4])==[2,0,0,1], "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 True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | compare |
HumanEval\/153 | \ndef Strongest_Extension(class_name, extensions):\n """คุณจะได้รับชื่อของคลาส (สตริง) และรายการส่วนขยาย ส่วนขยายเหล่านี้จะถูกใช้เพื่อโหลดคลาสเพิ่มเติมให้กับคลาส ความแข็งแกร่งของส่วนขยายมีดังนี้ ให้ CAP เป็นจำนวนตัวอักษรพิมพ์ใหญ่ในชื่อส่วนขยาย และให้ SM เป็นจำนวนตัวอักษรพิมพ์เล็กในชื่อส่วนขยาย ความแข็งแกร่งจะกำหนดโดยเศษส่วน CAP - SM คุณควรค้นหาส่วนขยายที่แข็งแกร่งที่สุดและส่งคืนสตริงในรูปแบบนี้: ClassName.StrongestExtensionName หากมีส่วนขยายสองรายการขึ้นไปที่มีความแข็งแกร่งเท่ากัน คุณควรเลือกส่วนขยายที่อยู่อันดับแรกในรายการ ตัวอย่างเช่น หากคุณได้รับ "Slices" เป็นคลาสและรายการส่วนขยาย: [\'SErviNGSliCes\', \'Cheese\', \'StuFfed\'] คุณควรส่งคืน \'Slices.SErviNGSliCes\' เนื่องจาก \'SErviNGSliCes\' เป็นส่วนขยายที่แข็งแกร่งที่สุด (ความแข็งแกร่งคือ -1) ตัวอย่าง: สำหรับ Strongest_Extension(\'my_class\', [\'AA\', \'Be\', \'CC\']) == \'my_class.AA\'\n """\n | strong = extensions[0]\n my_val = len([x for x in extensions[0] if x.isalpha() and x.isupper()]) - len([x for x in extensions[0] if x.isalpha() and x.islower()])\n for s in extensions:\n val = len([x for x in s if x.isalpha() and x.isupper()]) - len([x for x in s if x.isalpha() and x.islower()])\n if val > my_val:\n strong = s\n my_val = val\n\n ans = class_name + "." + strong\n return ans\n\n | def check(candidate):\n\n # Check some simple cases\n assert candidate('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) == 'Watashi.eIGHt8OKe'\n assert candidate('Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']) == 'Boku123.YEs.WeCaNe'\n assert candidate('__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__', '123NoooneB321']) == '__YESIMHERE.NuLl__'\n assert candidate('K', ['Ta', 'TAR', 't234An', 'cosSo']) == 'K.TAR'\n assert candidate('__HAHA', ['Tab', '123', '781345', '-_-']) == '__HAHA.123'\n assert candidate('YameRore', ['HhAas', 'okIWILL123', 'WorkOut', 'Fails', '-_-']) == 'YameRore.okIWILL123'\n assert candidate('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) == 'finNNalLLly.WoW'\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('_', ['Bb', '91245']) == '_.Bb'\n assert candidate('Sp', ['671235', 'Bb']) == 'Sp.671235'\n \n | Strongest_Extension |
HumanEval\/154 | \ndef cycpattern_check(a , b):\n """คุณได้รับ 2 คำ คุณต้องคืนค่า True หากคำที่สองหรือการหมุนเวียนใดๆ ของคำนั้นเป็นสตริงย่อยในคำแรก cycpattern_check("abcd","abd") => False cycpattern_check("hello","ell") => True cycpattern_check("whassup","psus") => False cycpattern_check("abab","baa") => True cycpattern_check("efef","eeff") => False cycpattern_check("himenss","simen") => True\n """\n | l = len(b)\n pat = b + b\n for i in range(len(a) - l + 1):\n for j in range(l + 1):\n if a[i:i+l] == pat[j:j+l]:\n return True\n return False\n | def check(candidate):\n\n # Check some simple cases\n #assert True, "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 True, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate("xyzw","xyw") == False , "test #0"\n assert candidate("yello","ell") == True , "test #1"\n assert candidate("whattup","ptut") == False , "test #2"\n assert candidate("efef","fee") == True , "test #3"\n assert candidate("abab","aabb") == False , "test #4"\n assert candidate("winemtt","tinem") == True , "test #5"\n\n | cycpattern_check |
HumanEval\/155 | \ndef even_odd_count(num):\n """เมื่อกำหนดจำนวนเต็ม ให้ส่งคืนทูเพิลที่มีจำนวนหลักคู่และหลักคี่ตามลำดับ ตัวอย่าง: even_odd_count(-12) ==> (1, 1) even_odd_count(123) ==> (1, 2)\n """\n | even_count = 0\n odd_count = 0\n for i in str(abs(num)):\n if int(i)%2==0:\n even_count +=1\n else:\n odd_count +=1\n return (even_count, odd_count)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(7) == (0, 1)\n assert candidate(-78) == (1, 1)\n assert candidate(3452) == (2, 2)\n assert candidate(346211) == (3, 3)\n assert candidate(-345821) == (3, 3)\n assert candidate(-2) == (1, 0)\n assert candidate(-45347) == (2, 3)\n assert candidate(0) == (1, 0)\n\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | even_odd_count |
HumanEval\/156 | \ndef int_to_mini_roman(number):\n """เมื่อกำหนดจำนวนเต็มบวก ให้หาค่าเทียบเท่าตัวเลขโรมันเป็นสตริง แล้วส่งคืนเป็นตัวพิมพ์เล็ก ข้อจำกัด: 1 <= num <= 1000 ตัวอย่าง:\n >>> int_to_mini_roman(19) == 'xix'\n >>> int_to_mini_roman(152) == 'clii'\n >>> int_to_mini_roman(426) == 'cdxxvi'"""\n | num = [1, 4, 5, 9, 10, 40, 50, 90, \n 100, 400, 500, 900, 1000] \n sym = ["I", "IV", "V", "IX", "X", "XL", \n "L", "XC", "C", "CD", "D", "CM", "M"] \n i = 12\n res = ''\n while number: \n div = number \/\/ num[i] \n number %= num[i] \n while div: \n res += sym[i] \n div -= 1\n i -= 1\n return res.lower()\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(19) == 'xix'\n assert candidate(152) == 'clii'\n assert candidate(251) == 'ccli'\n assert candidate(426) == 'cdxxvi'\n assert candidate(500) == 'd'\n assert candidate(1) == 'i'\n assert candidate(4) == 'iv'\n assert candidate(43) == 'xliii'\n assert candidate(90) == 'xc'\n assert candidate(94) == 'xciv'\n assert candidate(532) == 'dxxxii'\n assert candidate(900) == 'cm'\n assert candidate(994) == 'cmxciv'\n assert candidate(1000) == 'm'\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | int_to_mini_roman |
HumanEval\/157 | \ndef right_angle_triangle(a, b, c):\n '''กำหนดความยาวของด้านทั้งสามของรูปสามเหลี่ยม คืนค่า True หากด้านทั้งสามประกอบกันเป็นรูปสามเหลี่ยมมุมฉาก คืนค่า False หากไม่เป็นเช่นนั้น รูปสามเหลี่ยมมุมฉากคือรูปสามเหลี่ยมที่มีมุมหนึ่งเป็นมุมฉากหรือ 90 องศา ตัวอย่าง: right_angle_triangle(3, 4, 5) == True right_angle_triangle(1, 2, 3) == False\n '''\n | return a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(3, 4, 5) == True, "This prints if this assert fails 1 (good for debugging!)"\n assert candidate(1, 2, 3) == False\n assert candidate(10, 6, 8) == True\n assert candidate(2, 2, 2) == False\n assert candidate(7, 24, 25) == True\n assert candidate(10, 5, 7) == False\n assert candidate(5, 12, 13) == True\n assert candidate(15, 8, 17) == True\n assert candidate(48, 55, 73) == True\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1, 1, 1) == False, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate(2, 2, 10) == False\n\n | right_angle_triangle |
HumanEval\/158 | \ndef find_max(words):\n """เขียนฟังก์ชันที่รับรายการสตริง รายการประกอบด้วยคำต่างๆ ส่งคืนคำที่มีจำนวนอักขระที่ไม่ซ้ำกันสูงสุด หากสตริงหลายรายการมีอักขระที่ไม่ซ้ำกันสูงสุด ให้ส่งคืนสตริงที่มาก่อนตามลำดับตัวอักษร find_max(["name", "of", "string"]) == "string" find_max(["name", "enam", "game"]) == "enam" find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa"\n """\n | return sorted(words, key = lambda x: (-len(set(x)), x))[0]\n | def check(candidate):\n\n # Check some simple cases\n assert (candidate(["name", "of", "string"]) == "string"), "t1"\n assert (candidate(["name", "enam", "game"]) == "enam"), 't2'\n assert (candidate(["aaaaaaa", "bb", "cc"]) == "aaaaaaa"), 't3'\n assert (candidate(["abc", "cba"]) == "abc"), 't4'\n assert (candidate(["play", "this", "game", "of","footbott"]) == "footbott"), 't5'\n assert (candidate(["we", "are", "gonna", "rock"]) == "gonna"), 't6'\n assert (candidate(["we", "are", "a", "mad", "nation"]) == "nation"), 't7'\n assert (candidate(["this", "is", "a", "prrk"]) == "this"), 't8'\n\n # Check some edge cases that are easy to work out by hand.\n assert (candidate(["b"]) == "b"), 't9'\n assert (candidate(["play", "play", "play"]) == "play"), 't10'\n\n | find_max |
HumanEval\/159 | \ndef eat(number, need, remaining):\n """คุณเป็นกระต่ายที่หิวโหย และคุณได้กินแครอทไปจำนวนหนึ่งแล้ว แต่ตอนนี้คุณต้องกินแครอทเพิ่มเพื่อให้ครบมื้อของวัน คุณควรส่งคืนอาร์เรย์ของ [ จำนวนแครอทที่กินทั้งหมดหลังมื้ออาหารของคุณ จำนวนแครอทที่เหลือหลังมื้ออาหารของคุณ ] ถ้าแครอทเหลือไม่เพียงพอ คุณจะกินแครอทที่เหลือทั้งหมด แต่จะยังคงหิวอยู่ ตัวอย่าง: * eat(5, 6, 10) -> [11, 4] * eat(4, 8, 9) -> [12, 1] * eat(1, 10, 10) -> [11, 0] * eat(2, 11, 5) -> [7, 0] ตัวแปร: @number : integer จำนวนแครอทที่คุณกิน @need : integer จำนวนแครอทที่คุณต้องกิน @remaining : integer คือ จำนวนแครอทที่เหลืออยู่ในสต็อก Constrain: * 0 <= จำนวน <= 1000 * 0 <= ความต้องการ <= 1000 * 0 <= ที่เหลือ <= 1000 สนุกนะ :)\n """\n | if(need <= remaining):\n return [ number + need , remaining-need ]\n else:\n return [ number + remaining , 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(5, 6, 10) == [11, 4], "Error"\n assert candidate(4, 8, 9) == [12, 1], "Error"\n assert candidate(1, 10, 10) == [11, 0], "Error"\n assert candidate(2, 11, 5) == [7, 0], "Error"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n assert candidate(4, 5, 7) == [9, 2], "Error"\n assert candidate(4, 5, 1) == [5, 0], "Error"\n\n | eat |
HumanEval\/160 | \ndef do_algebra(operator, operand):\n """กำหนดตัวดำเนินการรายการสองตัวและตัวดำเนินการ รายการแรกมีการดำเนินการพีชคณิตพื้นฐาน และรายการที่สองเป็นรายการของจำนวนเต็ม ใช้รายการทั้งสองที่กำหนดเพื่อสร้างนิพจน์พีชคณิตและส่งคืนการประเมินนิพจน์นี้ การดำเนินการพีชคณิตพื้นฐาน: การบวก ( + ) การลบ ( - ) การคูณ ( * ) การหารด้วยเลขฐานสอง ( \/\/ ) การยกกำลัง ( ** ) ตัวอย่าง: ตัวดำเนินการ[\'+\', \'*\', \'-\'] อาร์เรย์ = [2, 3, 4, 5] ผลลัพธ์ = 2 + 3 * 4 - 5 => ผลลัพธ์ = 9 หมายเหตุ: ความยาวของตัวดำเนินการรายการเท่ากับความยาวของตัวดำเนินการรายการลบหนึ่ง ตัวดำเนินการคือรายการของจำนวนเต็มที่ไม่เป็นลบ ตัวดำเนินการรายการมีตัวดำเนินการอย่างน้อยหนึ่งตัว และตัวดำเนินการรายการมีตัวดำเนินการอย่างน้อยสองตัว\n """\n | expression = str(operand[0])\n for oprt, oprn in zip(operator, operand[1:]):\n expression+= oprt + str(oprn)\n return eval(expression)\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(['**', '*', '+'], [2, 3, 4, 5]) == 37\n assert candidate(['+', '*', '-'], [2, 3, 4, 5]) == 9\n assert candidate(['\/\/', '*'], [7, 3, 4]) == 8, "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 True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | do_algebra |
HumanEval\/161 | \ndef solve(s):\n """คุณจะได้รับสตริง s หาก s[i] เป็นตัวอักษร ให้กลับตัวพิมพ์จากตัวพิมพ์เล็กเป็นตัวพิมพ์ใหญ่หรือในทางกลับกัน มิฉะนั้น ให้คงไว้ตามเดิม หากสตริงไม่มีตัวอักษร ให้กลับตัวพิมพ์ ฟังก์ชันควรส่งคืนสตริงที่ได้ ตัวอย่าง solve("1234") = "4321" solve("ab") = "AB" solve("#a@C") = "#A@c"\n """\n | flg = 0\n idx = 0\n new_str = list(s)\n for i in s:\n if i.isalpha():\n new_str[idx] = i.swapcase()\n flg = 1\n idx += 1\n s = ""\n for i in new_str:\n s += i\n if flg == 0:\n return s[len(s)::-1]\n return s\n | def check(candidate):\n\n # Check some simple cases\n assert candidate("AsDf") == "aSdF"\n assert candidate("1234") == "4321"\n assert candidate("ab") == "AB"\n assert candidate("#a@C") == "#A@c"\n assert candidate("#AsdfW^45") == "#aSDFw^45"\n assert candidate("#6@2") == "2@6#"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate("#$a^D") == "#$A^d"\n assert candidate("#ccc") == "#CCC"\n\n # Don't remove this line:\n | solve |
HumanEval\/162 | \ndef string_to_md5(text):\n """เมื่อได้รับสตริง \'text\' ให้ส่งคืนสตริงเทียบเท่าแฮช md5 หาก \'text\' เป็นสตริงว่าง ให้ส่งคืน None\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'"""\n | import hashlib\n return hashlib.md5(text.encode('ascii')).hexdigest() if text else None\n | def check(candidate):\n\n # Check some simple cases\n assert candidate('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n assert candidate('') == None\n assert candidate('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'\n assert candidate('password') == '5f4dcc3b5aa765d61d8327deb882cf99'\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n | string_to_md5 |
HumanEval\/163 | \ndef generate_integers(a, b):\n """กำหนดจำนวนเต็มบวกสองจำนวนคือ a และ b ให้ส่งคืนเลขคู่ระหว่าง a และ b ตามลำดับจากน้อยไปมาก ตัวอย่างเช่น generate_integers(2, 8) => [2, 4, 6, 8] generate_integers(8, 2) => [2, 4, 6, 8] generate_integers(10, 14) => []\n """\n | lower = max(2, min(a, b))\n upper = min(8, max(a, b))\n\n return [i for i in range(lower, upper+1) if i % 2 == 0]\n | def check(candidate):\n\n # Check some simple cases\n assert candidate(2, 10) == [2, 4, 6, 8], "Test 1"\n assert candidate(10, 2) == [2, 4, 6, 8], "Test 2"\n assert candidate(132, 2) == [2, 4, 6, 8], "Test 3"\n assert candidate(17,89) == [], "Test 4"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, "This prints if this assert fails 2 (also good for debugging!)"\n\n | generate_integers |