Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new python codes for max_product_subarray, min_window, and min_meeting_rooms in HumanEval. #621

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Evaluation/HumanEval/data/humaneval-python.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@
{"task_id": "Python/161", "prompt": "\ndef solve(s):\n \"\"\"You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n \"\"\"\n", "canonical_solution": " 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", "test": "def check(solve):\n\n # Check some simple cases\n assert solve(\"AsDf\") == \"aSdF\"\n assert solve(\"1234\") == \"4321\"\n assert solve(\"ab\") == \"AB\"\n assert solve(\"#a@C\") == \"#A@c\"\n assert solve(\"#AsdfW^45\") == \"#aSDFw^45\"\n assert solve(\"#6@2\") == \"2@6#\"\n\n # Check some edge cases that are easy to work out by hand.\n assert solve(\"#$a^D\") == \"#$A^d\"\n assert solve(\"#ccc\") == \"#CCC\"\n\n # Don't remove this line:\n\ncheck(solve)", "text": " You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"", "declaration": "def solve(s):\n", "example_test": "def check(solve):\n # Check some simple cases\n assert solve(\"1234\") == \"4321\"\n assert solve(\"ab\") == \"AB\"\n assert solve(\"#a@C\") == \"#A@c\"\n # Don't remove this line:\ncheck(solve)\n"}
{"task_id": "Python/162", "prompt": "\ndef string_to_md5(text):\n \"\"\"\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n \"\"\"\n", "canonical_solution": " import hashlib\n return hashlib.md5(text.encode('ascii')).hexdigest() if text else None\n", "test": "def check(string_to_md5):\n\n # Check some simple cases\n assert string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n assert string_to_md5('') == None\n assert string_to_md5('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'\n assert string_to_md5('password') == '5f4dcc3b5aa765d61d8327deb882cf99'\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(string_to_md5)", "text": " Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'", "declaration": "def string_to_md5(text):\n", "example_test": "def check(string_to_md5):\n # Check some simple cases\n assert string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n # Check some edge cases that are easy to work out by hand.\n assert True\ncheck(string_to_md5)\n"}
{"task_id": "Python/163", "prompt": "\ndef generate_integers(a, b):\n \"\"\"\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generate_integers(2, 8) => [2, 4, 6, 8]\n generate_integers(8, 2) => [2, 4, 6, 8]\n generate_integers(10, 14) => []\n \"\"\"\n", "canonical_solution": " 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", "test": "def check(generate_integers):\n\n # Check some simple cases\n assert generate_integers(2, 10) == [2, 4, 6, 8], \"Test 1\"\n assert generate_integers(10, 2) == [2, 4, 6, 8], \"Test 2\"\n assert generate_integers(132, 2) == [2, 4, 6, 8], \"Test 3\"\n assert generate_integers(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\ncheck(generate_integers)", "text": " Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generate_integers(2, 8) => [2, 4, 6, 8]\n generate_integers(8, 2) => [2, 4, 6, 8]\n generate_integers(10, 14) => []", "declaration": "def generate_integers(a, b):\n", "example_test": "def check(generate_integers):\n # Check some simple cases\n assert generate_integers(2, 10) == [2, 4, 6, 8], \"Test 1\"\n assert generate_integers(10, 2) == [2, 4, 6, 8], \"Test 2\"\n assert generate_integers(132, 2) == [2, 4, 6, 8], \"Test 3\"\n assert generate_integers(17,89) == [], \"Test 4\"\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!)\"\ncheck(generate_integers)\n"}
{"task_id": "Python/164", "prompt": "from typing import List\n\ndef max_product_subarray(nums: List[int]) -> int:\n \"\"\" Given a list of integers, find the maximum product of any contiguous subarray.\n >>> max_product_subarray([2, 3, -2, 4])\n 6\n \"\"\"\n", "canonical_solution": " def max_product_subarray(nums):\n max_product = float('-inf')\n min_product = 1\n max_product_end = 1\n \n for num in nums:\n if num == 0:\n min_product = 1\n max_product_end = 1\n max_product = max(max_product, 0)\n continue\n \n temp = max_product_end\n max_product_end = max(num, num * max_product_end, num * min_product)\n min_product = min(num, num * temp, num * min_product)\n max_product = max(max_product, max_product_end)\n \n return max_product\n", "test": "\nMETADATA = {\n 'author': 'ocman-nazir-briet',\n 'dataset': 'test'\n}\n\ndef check(max_product_subarray):\n assert max_product_subarray([2, 3, -2, 4]) == 6\n assert max_product_subarray([-2, 0, -1]) == 0\n assert max_product_subarray([-2, 3, -4]) == 24\n\ncheck(max_product_subarray)", "text": " Given a list of integers, find the maximum product of any contiguous subarray.\n >>> max_product_subarray([2, 3, -2, 4])\n 6", "declaration": "from typing import List\n\ndef max_product_subarray(nums: List[int]) -> int:\n", "example_test": "def check(max_product_subarray):\n assert max_product_subarray([2, 3, -2, 4]) == 6\ncheck(max_product_subarray)\n"}
{"task_id": "Python/165", "prompt": "from collections import Counter\n\ndef min_window(s: str, chars: str) -> str:\n \"\"\" Given a string and a set of characters, find the smallest substring that contains all characters.\n >>> min_window(\"ADOBECODEBANC\", \"ABC\")\n \"BANC\"\n \"\"\"\n", "canonical_solution": " def min_window(s, chars):\n from collections import Counter\n char_count = Counter(chars)\n left = 0\n min_len = float('inf')\n min_window = \"\"\n required = len(chars)\n \n for right, char in enumerate(s):\n if char in char_count:\n char_count[char] -= 1\n if char_count[char] >= 0:\n required -= 1\n \n while required == 0:\n if right - left + 1 < min_len:\n min_len = right - left + 1\n min_window = s[left:right+1]\n if s[left] in char_count:\n char_count[s[left]] += 1\n if char_count[s[left]] > 0:\n required += 1\n left += 1\n \n return min_window\n", "test": "\nMETADATA = {\n 'author': 'ocman-nazir-briet',\n 'dataset': 'test'\n}\n\ndef check(min_window):\n assert min_window(\"ADOBECODEBANC\", \"ABC\") == \"BANC\"\n assert min_window(\"a\", \"a\") == \"a\"\n assert min_window(\"a\", \"aa\") == \"\"\n\ncheck(min_window)", "text": " Given a string and a set of characters, find the smallest substring that contains all characters.\n >>> min_window(\"ADOBECODEBANC\", \"ABC\")\n \"BANC\"", "declaration": "from collections import Counter\n\ndef min_window(s: str, chars: str) -> str:\n", "example_test": "def check(min_window):\n assert min_window(\"ADOBECODEBANC\", \"ABC\") == \"BANC\"\ncheck(min_window)\n"}
{"task_id": "Python/166", "prompt": "from typing import List, Tuple\n\ndef min_meeting_rooms(intervals: List[Tuple[int, int]]) -> int:\n \"\"\" Given a list of meeting intervals, determine the minimum number of rooms required.\n >>> min_meeting_rooms([(0, 30), (5, 10), (15, 20)])\n 2\n \"\"\"\n", "canonical_solution": " def min_meeting_rooms(intervals):\n start_times = sorted([i[0] for i in intervals])\n end_times = sorted([i[1] for i in intervals])\n \n rooms = 0\n end_ptr = 0\n \n for start in start_times:\n if start < end_times[end_ptr]:\n rooms += 1\n else:\n end_ptr += 1\n \n return rooms\n", "test": "\nMETADATA = {\n 'author': 'ocman-nazir-briet',\n 'dataset': 'test'\n}\n\ndef check(min_meeting_rooms):\n assert min_meeting_rooms([(0, 30), (5, 10), (15, 20)]) == 2\n assert min_meeting_rooms([(7, 10), (2, 4)]) == 1\n\ncheck(min_meeting_rooms)", "text": " Given a list of meeting intervals, determine the minimum number of rooms required.\n >>> min_meeting_rooms([(0, 30), (5, 10), (15, 20)])\n 2", "declaration": "from typing import List, Tuple\n\ndef min_meeting_rooms(intervals: List[Tuple[int, int]]) -> int:\n", "example_test": "def check(min_meeting_rooms):\n assert min_meeting_rooms([(0, 30), (5, 10), (15, 20)]) == 2\ncheck(min_meeting_rooms)\n"}