nv78 commited on
Commit
172b602
·
verified ·
1 Parent(s): 9a38522

Add IntentSpec benchmark data

Browse files
Files changed (3) hide show
  1. README.md +98 -0
  2. canonicals.jsonl +49 -0
  3. spec_pairs.jsonl +49 -0
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ task_categories:
4
+ - text-generation
5
+ - text-classification
6
+ language:
7
+ - en
8
+ pretty_name: IntentSpec Benchmark
9
+ size_categories:
10
+ - n<1K
11
+ ---
12
+
13
+ # IntentSpec Benchmark — Data Supplement
14
+
15
+ This archive contains the benchmark data used to compute Intent Violation
16
+ Rate (IVR) in the paper: 49 tasks, each derived from a HumanEval problem and
17
+ extended with an ambiguous/gold prompt pair and a decomposed set of
18
+ executable constraints.
19
+
20
+ ## Files
21
+
22
+ ### `spec_pairs.jsonl`
23
+
24
+ The benchmark itself — one JSON object per line, one line per task. This is
25
+ the file consumed directly by the evaluation pipeline (`run_experiment1.py`,
26
+ `validate_benchmark.py` in the software supplement).
27
+
28
+ Fields:
29
+
30
+ | Field | Type | Description |
31
+ |---------------------|-----------------|-------------|
32
+ | `task_id` | string | HumanEval task identifier, e.g. `"HumanEval/26"`. Matches the `task_id` in `canonicals.jsonl`. |
33
+ | `spec_type` | string | Category of the task. Currently always `"algorithm"`. |
34
+ | `ambiguous_prompt` | string | The under-specified prompt a developer might plausibly write — states only some of the task's real constraints. |
35
+ | `gold_prompt` | string | The fully clarified version of the prompt, stating every constraint explicitly. |
36
+ | `constraints` | list of objects | All atomic, executable constraints implied by the gold prompt (see below). |
37
+ | `stated_test_ids` | list of strings | IDs (from `constraints`) that are mentioned, even implicitly, in `ambiguous_prompt`. |
38
+ | `hidden_test_ids` | list of strings | IDs (from `constraints`) that appear only in `gold_prompt`, not in `ambiguous_prompt`. A solution that passes all `stated_test_ids` but fails one or more `hidden_test_ids` counts as an intent violation — this is what IVR measures. |
39
+
40
+ Each entry in `constraints` is an object:
41
+
42
+ | Field | Type | Description |
43
+ |---------------|--------|-------------|
44
+ | `id` | string | Local constraint identifier (e.g. `"C1"`), referenced by `stated_test_ids`/`hidden_test_ids`. |
45
+ | `description` | string | Human-readable statement of the constraint. |
46
+ | `test_code` | string | Executable Python snippet that calls `solution(...)` and asserts the constraint holds. Run by concatenating a candidate solution with this snippet and executing it; a zero exit code means the constraint passed. |
47
+
48
+ Example (abbreviated):
49
+
50
+ ```json
51
+ {
52
+ "task_id": "HumanEval/26",
53
+ "spec_type": "algorithm",
54
+ "ambiguous_prompt": "Write a function named `solution` that takes a list of integers and removes any elements that appear more than once.",
55
+ "gold_prompt": "Write a function named `solution` that takes a list of integers, removes all elements that occur more than once, preserves the original order of remaining elements, and returns a new list without mutating the input.",
56
+ "constraints": [
57
+ {"id": "C1", "description": "Elements appearing more than once are removed", "test_code": "result = solution([1, 2, 3, 2, 4])\nassert 2 not in result"},
58
+ {"id": "C2", "description": "Original order of remaining elements is preserved", "test_code": "..."},
59
+ {"id": "C3", "description": "Input list is not mutated", "test_code": "..."},
60
+ {"id": "C4", "description": "Empty list returns empty list", "test_code": "..."}
61
+ ],
62
+ "stated_test_ids": ["C1"],
63
+ "hidden_test_ids": ["C2", "C3", "C4"]
64
+ }
65
+ ```
66
+
67
+ ### `canonicals.jsonl`
68
+
69
+ The original HumanEval reference (gold) solutions that `spec_pairs.jsonl`
70
+ was built from. Used for benchmark validation — confirming that a correct,
71
+ known-good solution passes every constraint (stated and hidden) for its
72
+ task, i.e. that IVR == 0 for canonical solutions.
73
+
74
+ Fields:
75
+
76
+ | Field | Type | Description |
77
+ |----------------------|--------|-------------|
78
+ | `task_id` | string | HumanEval task identifier, matches `spec_pairs.jsonl`. |
79
+ | `entry_point` | string | Name of the function under test in the original HumanEval problem. |
80
+ | `prompt` | string | Original HumanEval function signature + docstring. |
81
+ | `canonical_solution` | string | Original HumanEval reference implementation body. |
82
+ | `full_source` | string | `prompt` + `canonical_solution` concatenated into a runnable module. |
83
+
84
+ ## Provenance and licensing
85
+
86
+ Both files are derived from **HumanEval**
87
+ (https://github.com/openai/human-eval), released by OpenAI under the
88
+ **MIT License**. `canonicals.jsonl` reproduces HumanEval's original prompts
89
+ and reference solutions verbatim (field-renamed for our pipeline).
90
+ `spec_pairs.jsonl` is new work built on top of HumanEval: for each of the 49
91
+ selected HumanEval tasks, we authored an ambiguous/gold prompt pair and a
92
+ decomposed set of constraint tests by hand, using the HumanEval problem
93
+ statement and reference solution as the source of ground truth. `task_id`
94
+ values (e.g. `"HumanEval/26"`) directly reference the corresponding upstream
95
+ HumanEval problem.
96
+
97
+ This derived data is released under the same MIT License as HumanEval, in
98
+ accordance with its terms.
canonicals.jsonl ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"task_id": "HumanEval/26", "entry_point": "remove_duplicates", "prompt": "from typing import List\n\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n \"\"\" From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> remove_duplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n \"\"\"\n", "canonical_solution": "\n num_cnt = dict()\n for number in numbers:\n if number not in num_cnt:\n num_cnt[number] = 0\n num_cnt[number] += 1\n return [number for number in numbers if num_cnt[number] == 1]\n\n", "full_source": "from typing import List\n\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n \"\"\" From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> remove_duplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n \"\"\"\n\n num_cnt = dict()\n for number in numbers:\n if number not in num_cnt:\n num_cnt[number] = 0\n num_cnt[number] += 1\n return [number for number in numbers if num_cnt[number] == 1]\n\n"}
2
+ {"task_id": "HumanEval/18", "entry_point": "how_many_times", "prompt": "\n\ndef how_many_times(string: str, substring: str) -> int:\n \"\"\" Find how many times a given substring can be found in the original string. Count overlaping cases.\n >>> how_many_times('', 'a')\n 0\n >>> how_many_times('aaa', 'a')\n 3\n >>> how_many_times('aaaa', 'aa')\n 3\n \"\"\"\n", "canonical_solution": "\n\n occurences = 0\n for i in range(len(string)):\n if string[i:].startswith(substring):\n occurences += 1\n return occurences\n\n", "full_source": "\n\ndef how_many_times(string: str, substring: str) -> int:\n \"\"\" Find how many times a given substring can be found in the original string. Count overlaping cases.\n >>> how_many_times('', 'a')\n 0\n >>> how_many_times('aaa', 'a')\n 3\n >>> how_many_times('aaaa', 'aa')\n 3\n \"\"\"\n\n\n occurences = 0\n for i in range(len(string)):\n if string[i:].startswith(substring):\n occurences += 1\n return occurences\n\n"}
3
+ {"task_id": "HumanEval/25", "entry_point": "factorize", "prompt": "from typing import List\n\n\ndef factorize(n: int) -> List[int]:\n \"\"\" Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n \"\"\"\n", "canonical_solution": "\n 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", "full_source": "from typing import List\n\n\ndef factorize(n: int) -> List[int]:\n \"\"\" Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n \"\"\"\n\n 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"}
4
+ {"task_id": "HumanEval/12", "entry_point": "longest", "prompt": "from typing import List, Optional\n\n\ndef longest(strings: List[str]) -> Optional[str]:\n \"\"\" Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n \"\"\"\n", "canonical_solution": "\n 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", "full_source": "from typing import List, Optional\n\n\ndef longest(strings: List[str]) -> Optional[str]:\n \"\"\" Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n \"\"\"\n\n 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"}
5
+ {"task_id": "HumanEval/20", "entry_point": "find_closest_elements", "prompt": "from typing import List, Tuple\n\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n \"\"\" From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n (2.0, 2.2)\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n (2.0, 2.0)\n \"\"\"\n", "canonical_solution": "\n\n numbers.sort()\n min_diff = float(\"inf\")\n min_pair = None\n for l, r in zip(numbers[:-1], numbers[1:]):\n diff = r - l\n if diff < min_diff:\n min_diff = diff\n min_pair = (l, r)\n return min_pair\n\n", "full_source": "from typing import List, Tuple\n\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n \"\"\" From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n (2.0, 2.2)\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n (2.0, 2.0)\n \"\"\"\n\n\n numbers.sort()\n min_diff = float(\"inf\")\n min_pair = None\n for l, r in zip(numbers[:-1], numbers[1:]):\n diff = r - l\n if diff < min_diff:\n min_diff = diff\n min_pair = (l, r)\n return min_pair\n\n"}
6
+ {"task_id": "HumanEval/21", "entry_point": "rescale_to_unit", "prompt": "from typing import List\n\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n \"\"\" Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n \"\"\"\n", "canonical_solution": "\n\n ma, mi = max(numbers), min(numbers)\n k = 1 / (ma - mi)\n return list(map(lambda x: (x - mi) * k, numbers))\n\n", "full_source": "from typing import List\n\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n \"\"\" Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n \"\"\"\n\n\n ma, mi = max(numbers), min(numbers)\n k = 1 / (ma - mi)\n return list(map(lambda x: (x - mi) * k, numbers))\n\n"}
7
+ {"task_id": "HumanEval/7", "entry_point": "filter_by_substring", "prompt": "from typing import List\n\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that contain given substring\n >>> filter_by_substring([], 'a')\n []\n >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n \"\"\"\n", "canonical_solution": "\n return list(filter(lambda s: substring in s, strings))\n\n", "full_source": "from typing import List\n\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that contain given substring\n >>> filter_by_substring([], 'a')\n []\n >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n \"\"\"\n\n return list(filter(lambda s: substring in s, strings))\n\n"}
8
+ {"task_id": "HumanEval/47", "entry_point": "median", "prompt": "\n\ndef median(l: list):\n \"\"\"Return median of elements in the list l.\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 15.0\n \"\"\"\n", "canonical_solution": "\n\n sorted_l = sorted(l)\n if len(l) % 2 == 1:\n return sorted_l[len(l) // 2]\n else:\n return (sorted_l[len(l) // 2 - 1] + sorted_l[len(l) // 2]) / 2\n\n", "full_source": "\n\ndef median(l: list):\n \"\"\"Return median of elements in the list l.\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 15.0\n \"\"\"\n\n\n sorted_l = sorted(l)\n if len(l) % 2 == 1:\n return sorted_l[len(l) // 2]\n else:\n return (sorted_l[len(l) // 2 - 1] + sorted_l[len(l) // 2]) / 2\n\n"}
9
+ {"task_id": "HumanEval/30", "entry_point": "get_positive", "prompt": "\n\ndef get_positive(l: list):\n \"\"\"Return only positive numbers in the list.\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 \"\"\"\n", "canonical_solution": "\n return list(filter(lambda x: x > 0, l))\n\n", "full_source": "\n\ndef get_positive(l: list):\n \"\"\"Return only positive numbers in the list.\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 \"\"\"\n\n return list(filter(lambda x: x > 0, l))\n\n"}
10
+ {"task_id": "HumanEval/34", "entry_point": "unique", "prompt": "\n\ndef unique(l: list):\n \"\"\"Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n \"\"\"\n", "canonical_solution": "\n return sorted(set(l))\n\n", "full_source": "\n\ndef unique(l: list):\n \"\"\"Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n \"\"\"\n\n return sorted(set(l))\n\n"}
11
+ {"task_id": "HumanEval/51", "entry_point": "remove_vowels", "prompt": "\n\ndef remove_vowels(text):\n \"\"\"\n remove_vowels is a function that takes string and returns string without 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 'B'\n >>> remove_vowels('zbcd')\n 'zbcd'\n \"\"\"\n", "canonical_solution": "\n return \"\".join(list(filter(lambda ch: ch not in \"aeiouAEIOU\", text)))\n\n", "full_source": "\n\ndef remove_vowels(text):\n \"\"\"\n remove_vowels is a function that takes string and returns string without 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 'B'\n >>> remove_vowels('zbcd')\n 'zbcd'\n \"\"\"\n\n return \"\".join(list(filter(lambda ch: ch not in \"aeiouAEIOU\", text)))\n\n"}
12
+ {"task_id": "HumanEval/57", "entry_point": "monotonic", "prompt": "\n\ndef monotonic(l: list):\n \"\"\"Return True is list elements are monotonically increasing or decreasing.\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 \"\"\"\n", "canonical_solution": "\n inc, dec = True, True\n for i in range(len(l) - 1):\n if l[i] > l[i + 1]: inc = False\n if l[i] < l[i + 1]: dec = False\n return inc or dec\n\n", "full_source": "\n\ndef monotonic(l: list):\n \"\"\"Return True is list elements are monotonically increasing or decreasing.\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 \"\"\"\n\n inc, dec = True, True\n for i in range(len(l) - 1):\n if l[i] > l[i + 1]: inc = False\n if l[i] < l[i + 1]: dec = False\n return inc or dec\n\n"}
13
+ {"task_id": "HumanEval/58", "entry_point": "common", "prompt": "\n\ndef common(l1: list, l2: list):\n \"\"\"Return sorted unique common elements for two lists.\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 \"\"\"\n", "canonical_solution": "\n return sorted(list(set(l1).intersection(set(l2))))\n\n", "full_source": "\n\ndef common(l1: list, l2: list):\n \"\"\"Return sorted unique common elements for two lists.\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 \"\"\"\n\n return sorted(list(set(l1).intersection(set(l2))))\n\n"}
14
+ {"task_id": "HumanEval/42", "entry_point": "incr_list", "prompt": "\n\ndef incr_list(l: list):\n \"\"\"Return list with elements incremented by 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 \"\"\"\n", "canonical_solution": "\n return [x + 1 for x in l]\n\n", "full_source": "\n\ndef incr_list(l: list):\n \"\"\"Return list with elements incremented by 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 \"\"\"\n\n return [x + 1 for x in l]\n\n"}
15
+ {"task_id": "HumanEval/65", "entry_point": "circular_shift", "prompt": "\ndef circular_shift(x, shift):\n \"\"\"Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circular_shift(12, 1)\n \"21\"\n >>> circular_shift(12, 2)\n \"12\"\n \"\"\"\n", "canonical_solution": "\n\n s = str(x)\n if shift > len(s): return s[::-1]\n shift %= len(s)\n if shift == 0:\n return s\n else:\n return s[len(s) - shift:] + s[:len(s) - shift]\n\n", "full_source": "\ndef circular_shift(x, shift):\n \"\"\"Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circular_shift(12, 1)\n \"21\"\n >>> circular_shift(12, 2)\n \"12\"\n \"\"\"\n\n\n s = str(x)\n if shift > len(s): return s[::-1]\n shift %= len(s)\n if shift == 0:\n return s\n else:\n return s[len(s) - shift:] + s[:len(s) - shift]\n\n"}
16
+ {"task_id": "HumanEval/68", "entry_point": "pluck", "prompt": "\ndef pluck(arr):\n \"\"\"\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index. \n\n Example 3:\n Input: []\n Output: []\n \n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n \"\"\"\n", "canonical_solution": "\n\n if all(val % 2 == 1 for val in arr): return []\n min_even = min(filter(lambda x: x % 2 == 0, arr))\n for i in range(len(arr)):\n if arr[i] == min_even:\n return [min_even, i]\n\n", "full_source": "\ndef pluck(arr):\n \"\"\"\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index. \n\n Example 3:\n Input: []\n Output: []\n \n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n \"\"\"\n\n\n if all(val % 2 == 1 for val in arr): return []\n min_even = min(filter(lambda x: x % 2 == 0, arr))\n for i in range(len(arr)):\n if arr[i] == min_even:\n return [min_even, i]\n\n"}
17
+ {"task_id": "HumanEval/70", "entry_point": "strange_sort_list", "prompt": "\ndef strange_sort_list(lst):\n '''\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]\n strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]\n strange_sort_list([]) == []\n '''\n", "canonical_solution": "\n sorted_list = sorted(lst)\n ans, i, j = [], 0, len(sorted_list) - 1\n while i < j:\n ans.append(sorted_list[i])\n ans.append(sorted_list[j])\n i += 1\n j -= 1\n if i == j: ans.append(sorted_list[i])\n return ans\n\n", "full_source": "\ndef strange_sort_list(lst):\n '''\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]\n strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]\n strange_sort_list([]) == []\n '''\n\n sorted_list = sorted(lst)\n ans, i, j = [], 0, len(sorted_list) - 1\n while i < j:\n ans.append(sorted_list[i])\n ans.append(sorted_list[j])\n i += 1\n j -= 1\n if i == j: ans.append(sorted_list[i])\n return ans\n\n"}
18
+ {"task_id": "HumanEval/72", "entry_point": "will_it_fly", "prompt": "\ndef will_it_fly(q,w):\n '''\n Write a function that returns True if the object q will fly, and False otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n\n Example:\n will_it_fly([1, 2], 5) \u279e False \n # 1+2 is less than the maximum possible weight, but it's unbalanced.\n\n will_it_fly([3, 2, 3], 1) \u279e False\n # it's balanced, but 3+2+3 is more than the maximum possible weight.\n\n will_it_fly([3, 2, 3], 9) \u279e True\n # 3+2+3 is less than the maximum possible weight, and it's balanced.\n\n will_it_fly([3], 5) \u279e True\n # 3 is less than the maximum possible weight, and it's balanced.\n '''\n", "canonical_solution": "\n return q == q[::-1] and sum(q) <= w\n\n", "full_source": "\ndef will_it_fly(q,w):\n '''\n Write a function that returns True if the object q will fly, and False otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n\n Example:\n will_it_fly([1, 2], 5) \u279e False \n # 1+2 is less than the maximum possible weight, but it's unbalanced.\n\n will_it_fly([3, 2, 3], 1) \u279e False\n # it's balanced, but 3+2+3 is more than the maximum possible weight.\n\n will_it_fly([3, 2, 3], 9) \u279e True\n # 3+2+3 is less than the maximum possible weight, and it's balanced.\n\n will_it_fly([3], 5) \u279e True\n # 3 is less than the maximum possible weight, and it's balanced.\n '''\n\n return q == q[::-1] and sum(q) <= w\n\n"}
19
+ {"task_id": "HumanEval/74", "entry_point": "total_match", "prompt": "\ndef total_match(lst1, lst2):\n '''\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n\n Examples\n total_match([], []) \u279e []\n total_match(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\n total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\n total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\n total_match(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']\n '''\n", "canonical_solution": "\n c1, c2 = sum(map(lambda s: len(s), lst1)), sum(map(lambda s: len(s), lst2))\n return lst1 if c1 <= c2 else lst2\n\n", "full_source": "\ndef total_match(lst1, lst2):\n '''\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n\n Examples\n total_match([], []) \u279e []\n total_match(['hi', 'admin'], ['hI', 'Hi']) \u279e ['hI', 'Hi']\n total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) \u279e ['hi', 'admin']\n total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) \u279e ['hI', 'hi', 'hi']\n total_match(['4'], ['1', '2', '3', '4', '5']) \u279e ['4']\n '''\n\n c1, c2 = sum(map(lambda s: len(s), lst1)), sum(map(lambda s: len(s), lst2))\n return lst1 if c1 <= c2 else lst2\n\n"}
20
+ {"task_id": "HumanEval/64", "entry_point": "vowels_count", "prompt": "\nFIX = \"\"\"\nAdd more test cases.\n\"\"\"\n\ndef vowels_count(s):\n \"\"\"Write a function vowels_count which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowels_count(\"abcde\")\n 2\n >>> vowels_count(\"ACEDY\")\n 3\n \"\"\"\n", "canonical_solution": "\n if s == \"\": return 0\n cnt = len(list(filter(lambda ch: ch in \"aeiouAEIOU\", s)))\n if s[-1] in \"yY\": cnt += 1\n return cnt\n\n", "full_source": "\nFIX = \"\"\"\nAdd more test cases.\n\"\"\"\n\ndef vowels_count(s):\n \"\"\"Write a function vowels_count which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowels_count(\"abcde\")\n 2\n >>> vowels_count(\"ACEDY\")\n 3\n \"\"\"\n\n if s == \"\": return 0\n cnt = len(list(filter(lambda ch: ch in \"aeiouAEIOU\", s)))\n if s[-1] in \"yY\": cnt += 1\n return cnt\n\n"}
21
+ {"task_id": "HumanEval/66", "entry_point": "digitSum", "prompt": "\ndef digitSum(s):\n \"\"\"Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n \"\"\"\n", "canonical_solution": "\n return sum([ord(ch) for ch in s if ch.isupper()])\n\n", "full_source": "\ndef digitSum(s):\n \"\"\"Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n \"\"\"\n\n return sum([ord(ch) for ch in s if ch.isupper()])\n\n"}
22
+ {"task_id": "HumanEval/71", "entry_point": "triangle_area", "prompt": "\ndef triangle_area(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle. \n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater \n than the third side.\n Example:\n triangle_area(3, 4, 5) == 6.00\n triangle_area(1, 2, 10) == -1\n '''\n", "canonical_solution": "\n\n if a + b <= c or a + c <= b or b + c <= a: return -1\n p = (a + b + c) / 2\n return round((p * (p - a) * (p - b) * (p - c)) ** 0.5, 2)\n\n", "full_source": "\ndef triangle_area(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle. \n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater \n than the third side.\n Example:\n triangle_area(3, 4, 5) == 6.00\n triangle_area(1, 2, 10) == -1\n '''\n\n\n if a + b <= c or a + c <= b or b + c <= a: return -1\n p = (a + b + c) / 2\n return round((p * (p - a) * (p - b) * (p - c)) ** 0.5, 2)\n\n"}
23
+ {"task_id": "HumanEval/86", "entry_point": "anti_shuffle", "prompt": "\ndef anti_shuffle(s):\n \"\"\"\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n\n For example:\n anti_shuffle('Hi') returns 'Hi'\n anti_shuffle('hello') returns 'ehllo'\n anti_shuffle('Hello World!!!') returns 'Hello !!!Wdlor'\n \"\"\"\n", "canonical_solution": "\n words = s.split(\" \")\n return \" \".join(map(lambda x: \"\".join(sorted(x, key=lambda ch: ord(ch))), words))\n\n", "full_source": "\ndef anti_shuffle(s):\n \"\"\"\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n\n For example:\n anti_shuffle('Hi') returns 'Hi'\n anti_shuffle('hello') returns 'ehllo'\n anti_shuffle('Hello World!!!') returns 'Hello !!!Wdlor'\n \"\"\"\n\n words = s.split(\" \")\n return \" \".join(map(lambda x: \"\".join(sorted(x, key=lambda ch: ord(ch))), words))\n\n"}
24
+ {"task_id": "HumanEval/90", "entry_point": "next_smallest", "prompt": "\ndef next_smallest(lst):\n \"\"\"\n You are given a list of integers.\n Write a function next_smallest() that returns the 2nd smallest element of the list.\n Return None if there is no such element.\n \n next_smallest([1, 2, 3, 4, 5]) == 2\n next_smallest([5, 1, 4, 3, 2]) == 2\n next_smallest([]) == None\n next_smallest([1, 1]) == None\n \"\"\"\n", "canonical_solution": "\n if len(lst) <= 1: return None\n sorted_list = sorted(lst)\n for x in sorted_list:\n if x != sorted_list[0]:\n return x \n\n", "full_source": "\ndef next_smallest(lst):\n \"\"\"\n You are given a list of integers.\n Write a function next_smallest() that returns the 2nd smallest element of the list.\n Return None if there is no such element.\n \n next_smallest([1, 2, 3, 4, 5]) == 2\n next_smallest([5, 1, 4, 3, 2]) == 2\n next_smallest([]) == None\n next_smallest([1, 1]) == None\n \"\"\"\n\n if len(lst) <= 1: return None\n sorted_list = sorted(lst)\n for x in sorted_list:\n if x != sorted_list[0]:\n return x \n\n"}
25
+ {"task_id": "HumanEval/95", "entry_point": "check_dict_case", "prompt": "\ndef check_dict_case(dict):\n \"\"\"\n Given a dictionary, return True if all keys are strings in lower \n case or all keys are strings in upper case, else return False.\n The function should return False is the given dictionary is empty.\n Examples:\n check_dict_case({\"a\":\"apple\", \"b\":\"banana\"}) should return True.\n check_dict_case({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return False.\n check_dict_case({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return False.\n check_dict_case({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return False.\n check_dict_case({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return True.\n \"\"\"\n", "canonical_solution": "\n keys = list(dict.keys())\n if keys == []: return False\n lower, upper = True, True\n for k in keys:\n if type(k) != str:\n lower = upper = False\n break\n if not k.islower(): lower = False\n if not k.isupper(): upper = False\n return lower or upper\n\n", "full_source": "\ndef check_dict_case(dict):\n \"\"\"\n Given a dictionary, return True if all keys are strings in lower \n case or all keys are strings in upper case, else return False.\n The function should return False is the given dictionary is empty.\n Examples:\n check_dict_case({\"a\":\"apple\", \"b\":\"banana\"}) should return True.\n check_dict_case({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return False.\n check_dict_case({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return False.\n check_dict_case({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return False.\n check_dict_case({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return True.\n \"\"\"\n\n keys = list(dict.keys())\n if keys == []: return False\n lower, upper = True, True\n for k in keys:\n if type(k) != str:\n lower = upper = False\n break\n if not k.islower(): lower = False\n if not k.isupper(): upper = False\n return lower or upper\n\n"}
26
+ {"task_id": "HumanEval/98", "entry_point": "count_upper", "prompt": "\ndef count_upper(s):\n \"\"\"\n Given a string s, count the number of uppercase vowels in even indices.\n \n For example:\n count_upper('aBCdEf') returns 1\n count_upper('abcdefg') returns 0\n count_upper('dBBE') returns 0\n \"\"\"\n", "canonical_solution": "\n cnt = 0\n for i in range(0, len(s), 2):\n if s[i] in \"AEIOU\":\n cnt += 1\n return cnt\n\n", "full_source": "\ndef count_upper(s):\n \"\"\"\n Given a string s, count the number of uppercase vowels in even indices.\n \n For example:\n count_upper('aBCdEf') returns 1\n count_upper('abcdefg') returns 0\n count_upper('dBBE') returns 0\n \"\"\"\n\n cnt = 0\n for i in range(0, len(s), 2):\n if s[i] in \"AEIOU\":\n cnt += 1\n return cnt\n\n"}
27
+ {"task_id": "HumanEval/99", "entry_point": "closest_integer", "prompt": "\ndef closest_integer(value):\n '''\n Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n\n Examples\n >>> closest_integer(\"10\")\n 10\n >>> closest_integer(\"15.3\")\n 15\n\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closest_integer(\"14.5\") should\n return 15 and closest_integer(\"-14.5\") should return -15.\n '''\n", "canonical_solution": "\n\n def rounding(val):\n if abs(val - int(val)) != 0.5:\n return round(val)\n if val > 0:\n return int(val) + 1\n else:\n return int(val) - 1\n return rounding(float(value))\n\n", "full_source": "\ndef closest_integer(value):\n '''\n Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n\n Examples\n >>> closest_integer(\"10\")\n 10\n >>> closest_integer(\"15.3\")\n 15\n\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closest_integer(\"14.5\") should\n return 15 and closest_integer(\"-14.5\") should return -15.\n '''\n\n\n def rounding(val):\n if abs(val - int(val)) != 0.5:\n return round(val)\n if val > 0:\n return int(val) + 1\n else:\n return int(val) - 1\n return rounding(float(value))\n\n"}
28
+ {"task_id": "HumanEval/102", "entry_point": "choose_num", "prompt": "\ndef choose_num(x, y):\n \"\"\"This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n choose_num(12, 15) = 14\n choose_num(13, 12) = -1\n \"\"\"\n", "canonical_solution": "\n\n if x > y: return -1\n if x == y: return y if y % 2 == 0 else -1\n return y if y % 2 == 0 else y - 1\n\n", "full_source": "\ndef choose_num(x, y):\n \"\"\"This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n choose_num(12, 15) = 14\n choose_num(13, 12) = -1\n \"\"\"\n\n\n if x > y: return -1\n if x == y: return y if y % 2 == 0 else -1\n return y if y % 2 == 0 else y - 1\n\n"}
29
+ {"task_id": "HumanEval/104", "entry_point": "unique_digits", "prompt": "\ndef unique_digits(x):\n \"\"\"Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> unique_digits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> unique_digits([152, 323, 1422, 10])\n []\n \"\"\"\n", "canonical_solution": "\n\n def judge(x):\n for ch in str(x):\n if int(ch) % 2 == 0:\n return False\n return True\n return sorted(list(filter(judge, x)))\n\n", "full_source": "\ndef unique_digits(x):\n \"\"\"Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> unique_digits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> unique_digits([152, 323, 1422, 10])\n []\n \"\"\"\n\n\n def judge(x):\n for ch in str(x):\n if int(ch) % 2 == 0:\n return False\n return True\n return sorted(list(filter(judge, x)))\n\n"}
30
+ {"task_id": "HumanEval/108", "entry_point": "count_nums", "prompt": "\ndef count_nums(arr):\n \"\"\"\n Write a function count_nums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> count_nums([]) == 0\n >>> count_nums([-1, 11, -11]) == 1\n >>> count_nums([1, 1, 2]) == 3\n \"\"\"\n", "canonical_solution": "\n def judge(x: int) -> int:\n l = list(str(x))\n if l[0] == \"-\":\n l = l[1:]\n l = list(map(int, l))\n l[0] = -l[0]\n else:\n l = list(map(int, l))\n return 1 if sum(l) > 0 else 0\n return sum(map(judge, arr))\n\n", "full_source": "\ndef count_nums(arr):\n \"\"\"\n Write a function count_nums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> count_nums([]) == 0\n >>> count_nums([-1, 11, -11]) == 1\n >>> count_nums([1, 1, 2]) == 3\n \"\"\"\n\n def judge(x: int) -> int:\n l = list(str(x))\n if l[0] == \"-\":\n l = l[1:]\n l = list(map(int, l))\n l[0] = -l[0]\n else:\n l = list(map(int, l))\n return 1 if sum(l) > 0 else 0\n return sum(map(judge, arr))\n\n"}
31
+ {"task_id": "HumanEval/120", "entry_point": "maximum", "prompt": "\ndef maximum(arr, k):\n \"\"\"\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n \"\"\"\n", "canonical_solution": "\n\n return sorted(sorted(arr)[::-1][:k])\n\n", "full_source": "\ndef maximum(arr, k):\n \"\"\"\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n \"\"\"\n\n\n return sorted(sorted(arr)[::-1][:k])\n\n"}
32
+ {"task_id": "HumanEval/126", "entry_point": "is_sorted", "prompt": "\ndef is_sorted(lst):\n '''\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return False. Assume no negative numbers and only integers.\n\n Examples\n is_sorted([5]) \u279e True\n is_sorted([1, 2, 3, 4, 5]) \u279e True\n is_sorted([1, 3, 2, 4, 5]) \u279e False\n is_sorted([1, 2, 3, 4, 5, 6]) \u279e True\n is_sorted([1, 2, 3, 4, 5, 6, 7]) \u279e True\n is_sorted([1, 3, 2, 4, 5, 6, 7]) \u279e False\n is_sorted([1, 2, 2, 3, 3, 4]) \u279e True\n is_sorted([1, 2, 2, 2, 3, 4]) \u279e False\n '''\n", "canonical_solution": "\n\n count = dict()\n for x in lst:\n if x not in count: count[x] = 0\n count[x] += 1\n if count[x] > 2: return False\n return lst == sorted(lst)\n\n", "full_source": "\ndef is_sorted(lst):\n '''\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return False. Assume no negative numbers and only integers.\n\n Examples\n is_sorted([5]) \u279e True\n is_sorted([1, 2, 3, 4, 5]) \u279e True\n is_sorted([1, 3, 2, 4, 5]) \u279e False\n is_sorted([1, 2, 3, 4, 5, 6]) \u279e True\n is_sorted([1, 2, 3, 4, 5, 6, 7]) \u279e True\n is_sorted([1, 3, 2, 4, 5, 6, 7]) \u279e False\n is_sorted([1, 2, 2, 3, 3, 4]) \u279e True\n is_sorted([1, 2, 2, 2, 3, 4]) \u279e False\n '''\n\n\n count = dict()\n for x in lst:\n if x not in count: count[x] = 0\n count[x] += 1\n if count[x] > 2: return False\n return lst == sorted(lst)\n\n"}
33
+ {"task_id": "HumanEval/91", "entry_point": "is_bored", "prompt": "\ndef is_bored(S):\n \"\"\"\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> is_bored(\"Hello world\")\n 0\n >>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n \"\"\"\n", "canonical_solution": "\n sentences = map(lambda x: x.strip(), ((S.replace(\"?\", \".\")).replace(\"!\", \".\")).split(\".\"))\n return len([s for s in sentences if s.startswith(\"I \")])\n\n", "full_source": "\ndef is_bored(S):\n \"\"\"\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> is_bored(\"Hello world\")\n 0\n >>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n \"\"\"\n\n sentences = map(lambda x: x.strip(), ((S.replace(\"?\", \".\")).replace(\"!\", \".\")).split(\".\"))\n return len([s for s in sentences if s.startswith(\"I \")])\n\n"}
34
+ {"task_id": "HumanEval/131", "entry_point": "digits", "prompt": "\ndef digits(n):\n \"\"\"Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n \"\"\"\n", "canonical_solution": "\n\n has_odd, prod = False, 1\n for ch in str(n):\n if int(ch) % 2 == 1:\n has_odd = True\n prod *= int(ch)\n return 0 if not has_odd else prod\n\n", "full_source": "\ndef digits(n):\n \"\"\"Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n \"\"\"\n\n\n has_odd, prod = False, 1\n for ch in str(n):\n if int(ch) % 2 == 1:\n has_odd = True\n prod *= int(ch)\n return 0 if not has_odd else prod\n\n"}
35
+ {"task_id": "HumanEval/135", "entry_point": "can_arrange", "prompt": "\ndef can_arrange(arr):\n \"\"\"Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n can_arrange([1,2,4,3,5]) = 3\n can_arrange([1,2,3]) = -1\n \"\"\"\n", "canonical_solution": "\n\n for i in range(len(arr) - 1, 0, -1):\n if not (arr[i] >= arr[i - 1]):\n return i\n return -1\n\n", "full_source": "\ndef can_arrange(arr):\n \"\"\"Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n can_arrange([1,2,4,3,5]) = 3\n can_arrange([1,2,3]) = -1\n \"\"\"\n\n\n for i in range(len(arr) - 1, 0, -1):\n if not (arr[i] >= arr[i - 1]):\n return i\n return -1\n\n"}
36
+ {"task_id": "HumanEval/136", "entry_point": "largest_smallest_integers", "prompt": "\ndef largest_smallest_integers(lst):\n '''\n Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as None.\n\n Examples:\n largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)\n largest_smallest_integers([]) == (None, None)\n largest_smallest_integers([0]) == (None, None)\n '''\n", "canonical_solution": "\n neg = list(filter(lambda x: x < 0, lst))\n pos = list(filter(lambda x: x > 0, lst))\n return None if neg == [] else max(neg), None if pos == [] else min(pos)\n\n", "full_source": "\ndef largest_smallest_integers(lst):\n '''\n Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as None.\n\n Examples:\n largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)\n largest_smallest_integers([]) == (None, None)\n largest_smallest_integers([0]) == (None, None)\n '''\n\n neg = list(filter(lambda x: x < 0, lst))\n pos = list(filter(lambda x: x > 0, lst))\n return None if neg == [] else max(neg), None if pos == [] else min(pos)\n\n"}
37
+ {"task_id": "HumanEval/140", "entry_point": "fix_spaces", "prompt": "\ndef fix_spaces(text):\n \"\"\"\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fix_spaces(\"Example\") == \"Example\"\n fix_spaces(\"Example 1\") == \"Example_1\"\n fix_spaces(\" Example 2\") == \"_Example_2\"\n fix_spaces(\" Example 3\") == \"_Example-3\"\n \"\"\"\n", "canonical_solution": "\n ans = text\n for i in range(len(text), 2, -1):\n ans = ans.replace(\" \" * i, \"-\")\n return ans.replace(\" \", \"_\")\n\n", "full_source": "\ndef fix_spaces(text):\n \"\"\"\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fix_spaces(\"Example\") == \"Example\"\n fix_spaces(\"Example 1\") == \"Example_1\"\n fix_spaces(\" Example 2\") == \"_Example_2\"\n fix_spaces(\" Example 3\") == \"_Example-3\"\n \"\"\"\n\n ans = text\n for i in range(len(text), 2, -1):\n ans = ans.replace(\" \" * i, \"-\")\n return ans.replace(\" \", \"_\")\n\n"}
38
+ {"task_id": "HumanEval/149", "entry_point": "sorted_list_sum", "prompt": "\ndef sorted_list_sum(lst):\n \"\"\"Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n \"\"\"\n", "canonical_solution": "\n from functools import cmp_to_key\n def cmp(s: str, t: str):\n if len(s) != len(t):\n return len(s) - len(t)\n return -1 if s < t else 1\n return sorted(list(filter(lambda s: len(s) % 2 == 0, lst)), key=cmp_to_key(cmp))\n\n", "full_source": "\ndef sorted_list_sum(lst):\n \"\"\"Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n \"\"\"\n\n from functools import cmp_to_key\n def cmp(s: str, t: str):\n if len(s) != len(t):\n return len(s) - len(t)\n return -1 if s < t else 1\n return sorted(list(filter(lambda s: len(s) % 2 == 0, lst)), key=cmp_to_key(cmp))\n\n"}
39
+ {"task_id": "HumanEval/151", "entry_point": "double_the_difference", "prompt": "\ndef double_the_difference(lst):\n '''\n Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n \n double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n double_the_difference([-1, -2, 0]) == 0\n double_the_difference([9, -2]) == 81\n double_the_difference([0]) == 0 \n \n If the input list is empty, return 0.\n '''\n", "canonical_solution": "\n ans = 0\n for num in lst:\n if num % 2 == 1 and num > 0 and \".\" not in str(num):\n ans += num ** 2\n return ans\n\n", "full_source": "\ndef double_the_difference(lst):\n '''\n Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n \n double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n double_the_difference([-1, -2, 0]) == 0\n double_the_difference([9, -2]) == 81\n double_the_difference([0]) == 0 \n \n If the input list is empty, return 0.\n '''\n\n ans = 0\n for num in lst:\n if num % 2 == 1 and num > 0 and \".\" not in str(num):\n ans += num ** 2\n return ans\n\n"}
40
+ {"task_id": "HumanEval/158", "entry_point": "find_max", "prompt": "\ndef find_max(words):\n \"\"\"Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n find_max([\"name\", \"of\", \"string\"]) == \"string\"\n find_max([\"name\", \"enam\", \"game\"]) == \"enam\"\n find_max([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"\n \"\"\"\n", "canonical_solution": "\n\n mx_ch_cnt, ans = 0, \"\"\n for word in words:\n ch_cnt = len(set(word)) \n if ch_cnt > mx_ch_cnt or (ch_cnt == mx_ch_cnt and word < ans):\n mx_ch_cnt, ans = ch_cnt, word\n return ans\n\n", "full_source": "\ndef find_max(words):\n \"\"\"Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n find_max([\"name\", \"of\", \"string\"]) == \"string\"\n find_max([\"name\", \"enam\", \"game\"]) == \"enam\"\n find_max([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"\n \"\"\"\n\n\n mx_ch_cnt, ans = 0, \"\"\n for word in words:\n ch_cnt = len(set(word)) \n if ch_cnt > mx_ch_cnt or (ch_cnt == mx_ch_cnt and word < ans):\n mx_ch_cnt, ans = ch_cnt, word\n return ans\n\n"}
41
+ {"task_id": "HumanEval/163", "entry_point": "generate_integers", "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": "\n\n if a > b: a, b = b, a\n return [i for i in range(a, min(b + 1, 10)) if i % 2 == 0]\n\n", "full_source": "\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\n\n if a > b: a, b = b, a\n return [i for i in range(a, min(b + 1, 10)) if i % 2 == 0]\n\n"}
42
+ {"task_id": "HumanEval/88", "entry_point": "sort_array", "prompt": "\ndef sort_array(array):\n \"\"\"\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sort_array([]) => []\n * sort_array([5]) => [5]\n * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n \"\"\"\n", "canonical_solution": "\n\n if array == []: return []\n return sorted(array, reverse=(array[0]+array[-1]) % 2 == 0)\n\n", "full_source": "\ndef sort_array(array):\n \"\"\"\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sort_array([]) => []\n * sort_array([5]) => [5]\n * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n \"\"\"\n\n\n if array == []: return []\n return sorted(array, reverse=(array[0]+array[-1]) % 2 == 0)\n\n"}
43
+ {"task_id": "HumanEval/93", "entry_point": "encode", "prompt": "\ndef encode(message):\n \"\"\"\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n \"\"\"\n", "canonical_solution": "\n\n def switch_case(ch):\n if ord(\"A\") <= ord(ch) <= ord(\"Z\"):\n return chr(ord(ch) + 32)\n elif ord(\"a\") <= ord(ch) <= ord(\"z\"):\n return chr(ord(ch) - 32)\n else:\n return ch\n \n def vowel_change(ch):\n return ch if ch not in \"aeiouAEIOU\" else chr(ord(ch) + 2)\n \n m = \"\".join(map(switch_case, message))\n return \"\".join(map(vowel_change, m))\n\n", "full_source": "\ndef encode(message):\n \"\"\"\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n \"\"\"\n\n\n def switch_case(ch):\n if ord(\"A\") <= ord(ch) <= ord(\"Z\"):\n return chr(ord(ch) + 32)\n elif ord(\"a\") <= ord(ch) <= ord(\"z\"):\n return chr(ord(ch) - 32)\n else:\n return ch\n \n def vowel_change(ch):\n return ch if ch not in \"aeiouAEIOU\" else chr(ord(ch) + 2)\n \n m = \"\".join(map(switch_case, message))\n return \"\".join(map(vowel_change, m))\n\n"}
44
+ {"task_id": "HumanEval/101", "entry_point": "words_string", "prompt": "\ndef words_string(s):\n \"\"\"\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n words_string(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n words_string(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n \"\"\"\n", "canonical_solution": "\n words = (s.replace(\",\", \" \")).split()\n return [word for word in words if word != \"\"]\n\n", "full_source": "\ndef words_string(s):\n \"\"\"\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n words_string(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n words_string(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n \"\"\"\n\n words = (s.replace(\",\", \" \")).split()\n return [word for word in words if word != \"\"]\n\n"}
45
+ {"task_id": "HumanEval/105", "entry_point": "by_length", "prompt": "\ndef by_length(arr):\n \"\"\"\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\n For example:\n arr = [2, 1, 1, 4, 5, 8, 2, 3] \n -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] \n -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\n return [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\n \n If the array is empty, return an empty array:\n arr = []\n return []\n \n If the array has any strange number ignore it:\n arr = [1, -1 , 55] \n -> sort arr -> [-1, 1, 55]\n -> reverse arr -> [55, 1, -1]\n return = ['One']\n \"\"\"\n", "canonical_solution": "\n def to_word(x: int) -> str:\n if x == 1:\n return \"One\"\n elif x == 2:\n return \"Two\"\n elif x == 3:\n return \"Three\"\n elif x == 4:\n return \"Four\"\n elif x == 5:\n return \"Five\"\n elif x == 6:\n return \"Six\"\n elif x == 7:\n return \"Seven\"\n elif x == 8:\n return \"Eight\"\n else:\n return \"Nine\"\n sorted_list, ans = sorted(arr)[::-1], []\n for x in sorted_list:\n if 1 <= x <= 9:\n ans.append(to_word(x))\n return ans\n\n", "full_source": "\ndef by_length(arr):\n \"\"\"\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\n For example:\n arr = [2, 1, 1, 4, 5, 8, 2, 3] \n -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] \n -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\n return [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\n \n If the array is empty, return an empty array:\n arr = []\n return []\n \n If the array has any strange number ignore it:\n arr = [1, -1 , 55] \n -> sort arr -> [-1, 1, 55]\n -> reverse arr -> [55, 1, -1]\n return = ['One']\n \"\"\"\n\n def to_word(x: int) -> str:\n if x == 1:\n return \"One\"\n elif x == 2:\n return \"Two\"\n elif x == 3:\n return \"Three\"\n elif x == 4:\n return \"Four\"\n elif x == 5:\n return \"Five\"\n elif x == 6:\n return \"Six\"\n elif x == 7:\n return \"Seven\"\n elif x == 8:\n return \"Eight\"\n else:\n return \"Nine\"\n sorted_list, ans = sorted(arr)[::-1], []\n for x in sorted_list:\n if 1 <= x <= 9:\n ans.append(to_word(x))\n return ans\n\n"}
46
+ {"task_id": "HumanEval/111", "entry_point": "histogram", "prompt": "\ndef histogram(test):\n \"\"\"Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n \"\"\"\n", "canonical_solution": "\n\n if test == \"\": return {} \n count, ans = dict(), dict()\n for word in test.split(\" \"):\n if word != \"\":\n if word not in count: count[word] = 0\n count[word] += 1\n mx = max(list(count.values()))\n for ch, c in count.items():\n if c == mx:\n ans[ch] = c\n return ans\n\n", "full_source": "\ndef histogram(test):\n \"\"\"Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n \"\"\"\n\n\n if test == \"\": return {} \n count, ans = dict(), dict()\n for word in test.split(\" \"):\n if word != \"\":\n if word not in count: count[word] = 0\n count[word] += 1\n mx = max(list(count.values()))\n for ch, c in count.items():\n if c == mx:\n ans[ch] = c\n return ans\n\n"}
47
+ {"task_id": "HumanEval/112", "entry_point": "reverse_delete", "prompt": "\ndef reverse_delete(s,c):\n \"\"\"Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and True/False for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',False)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',False)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',True)\n \"\"\"\n", "canonical_solution": "\n ss = \"\".join(filter(lambda ch: ch not in c, s))\n return ss, ss == ss[::-1]\n\n", "full_source": "\ndef reverse_delete(s,c):\n \"\"\"Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and True/False for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',False)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',False)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',True)\n \"\"\"\n\n ss = \"\".join(filter(lambda ch: ch not in c, s))\n return ss, ss == ss[::-1]\n\n"}
48
+ {"task_id": "HumanEval/145", "entry_point": "order_by_points", "prompt": "\ndef order_by_points(nums):\n \"\"\"\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> order_by_points([]) == []\n \"\"\"\n", "canonical_solution": "\n def weight(x):\n x_list = list(str(x))\n if x_list[0] == \"-\":\n x_list = x_list[1:]\n x_list = list(map(int, x_list))\n x_list[0] = -x_list[0]\n else:\n x_list = list(map(int, x_list))\n return sum(x_list)\n return sorted(nums, key=weight)\n\n", "full_source": "\ndef order_by_points(nums):\n \"\"\"\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> order_by_points([]) == []\n \"\"\"\n\n def weight(x):\n x_list = list(str(x))\n if x_list[0] == \"-\":\n x_list = x_list[1:]\n x_list = list(map(int, x_list))\n x_list[0] = -x_list[0]\n else:\n x_list = list(map(int, x_list))\n return sum(x_list)\n return sorted(nums, key=weight)\n\n"}
49
+ {"task_id": "HumanEval/161", "entry_point": "solve", "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": "\n ans, has_letter = \"\", False\n for ch in s:\n if ch.isalpha():\n has_letter = True\n ans += ch.swapcase()\n else:\n ans += ch\n return ans if has_letter else s[::-1]\n\n", "full_source": "\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\n ans, has_letter = \"\", False\n for ch in s:\n if ch.isalpha():\n has_letter = True\n ans += ch.swapcase()\n else:\n ans += ch\n return ans if has_letter else s[::-1]\n\n"}
spec_pairs.jsonl ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"task_id": "HumanEval/26", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of integers and removes any elements that appear more than once.", "gold_prompt": "Write a function named `solution` that takes a list of integers, removes all elements that occur more than once, preserves the original order of remaining elements, and returns a new list without mutating the input.", "constraints": [{"id": "C1", "description": "Elements appearing more than once are removed", "test_code": "result = solution([1, 2, 3, 2, 4])\nassert 2 not in result, f'Duplicate element 2 should be removed, got {result}'"}, {"id": "C2", "description": "Original order of remaining elements is preserved", "test_code": "result = solution([4, 1, 3, 1, 2])\nassert result == [4, 3, 2], f'Expected [4, 3, 2] (order preserved), got {result}'"}, {"id": "C3", "description": "Input list is not mutated", "test_code": "inp = [1, 2, 3, 2, 4]\n_ = solution(inp)\nassert inp == [1, 2, 3, 2, 4], f'Input was mutated: {inp}'"}, {"id": "C4", "description": "Empty list returns empty list", "test_code": "result = solution([])\nassert result == [], f'Expected [], got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
2
+ {"task_id": "HumanEval/18", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that counts how many times a given substring appears in a string.", "gold_prompt": "Write a function named `solution` that counts how many times a given substring appears in a string, including overlapping occurrences.", "constraints": [{"id": "C1", "description": "Basic substring count works", "test_code": "result = solution('abc', 'a')\nassert result == 1, f'Expected 1, got {result}'"}, {"id": "C2", "description": "Overlapping occurrences are counted", "test_code": "result = solution('aaaa', 'aa')\nassert result == 3, f'Expected 3 (overlapping), got {result}'"}, {"id": "C3", "description": "Empty string returns 0", "test_code": "result = solution('', 'a')\nassert result == 0, f'Expected 0 for empty string, got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
3
+ {"task_id": "HumanEval/25", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns the prime factors of a given integer.", "gold_prompt": "Write a function named `solution` that returns a list of prime factors of the given integer in ascending order. Each factor should appear as many times as it appears in the factorization. The product of all returned factors should equal the input.", "constraints": [{"id": "C1", "description": "Basic factorization works", "test_code": "result = solution(13)\nassert result == [13], f'Expected [13], got {result}'"}, {"id": "C2", "description": "Output is in ascending order", "test_code": "result = solution(15)\nassert result == [3, 5], f'Expected [3, 5], got {result}'"}, {"id": "C3", "description": "Repeated factors appear multiple times", "test_code": "result = solution(8)\nassert result == [2, 2, 2], f'Expected [2, 2, 2], got {result}'"}, {"id": "C4", "description": "Product of all factors equals input", "test_code": "result = solution(70)\nimport math\nassert math.prod(result) == 70, f'Product of {result} should equal 70'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
4
+ {"task_id": "HumanEval/12", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of strings and returns the longest one.", "gold_prompt": "Write a function named `solution` that takes a list of strings and returns the longest one. If multiple strings share the same maximum length, return the first one. Return None if the input list is empty.", "constraints": [{"id": "C1", "description": "Returns the longest string", "test_code": "result = solution(['a', 'ab', 'abc'])\nassert result == 'abc', f'Expected abc, got {result}'"}, {"id": "C2", "description": "Returns first string when tie exists", "test_code": "result = solution(['bc', 'ab', 'cd'])\nassert result == 'bc', f'Expected bc (first of equal length), got {result}'"}, {"id": "C3", "description": "Returns None for empty list", "test_code": "result = solution([])\nassert result is None, f'Expected None, got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
5
+ {"task_id": "HumanEval/20", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of numbers and returns the two that are closest to each other.", "gold_prompt": "Write a function named `solution` that takes a list of numbers of length at least two, finds the two closest to each other, and returns them as a tuple in ascending order (smaller number first).", "constraints": [{"id": "C1", "description": "Identifies closest pair correctly", "test_code": "result = solution([1.0, 1.5, 2.0, 3.0, 4.0])\nassert tuple(result) == (1.0, 1.5), f'Expected (1.0, 1.5), got {result}'"}, {"id": "C2", "description": "Returns pair in ascending order (smaller first), input given unsorted", "test_code": "result = solution([5.0, 1.0, 2.1, 1.9, 8.0])\nassert tuple(result) == (1.9, 2.1), f'Expected (1.9, 2.1) in ascending order, got {result}'"}, {"id": "C3", "description": "Handles duplicate values correctly", "test_code": "result = solution([1.0, 2.0, 3.0, 2.0])\nassert tuple(result) == (2.0, 2.0), f'Expected (2.0, 2.0) for duplicates, got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
6
+ {"task_id": "HumanEval/21", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of numbers and applies a linear transformation to it.", "gold_prompt": "Write a function named `solution` that takes a list of numbers (at least two elements), and applies a linear transformation so that the smallest number becomes 0 and the largest becomes 1. Preserve the original order of elements.", "constraints": [{"id": "C1", "description": "Basic linear transformation works", "test_code": "result = solution([1.0, 2.0, 3.0, 4.0, 5.0])\nassert result == [0.0, 0.25, 0.5, 0.75, 1.0], f'Expected [0.0, 0.25, 0.5, 0.75, 1.0], got {result}'"}, {"id": "C2", "description": "Minimum becomes exactly 0 and maximum becomes exactly 1", "test_code": "result = solution([2.0, 1.0, 5.0, 3.0, 4.0])\nassert result[1] == 0.0 and result[2] == 1.0, f'Min should be 0.0 and max should be 1.0, got {result}'"}, {"id": "C3", "description": "Original order of elements is preserved", "test_code": "result = solution([2.0, 1.0, 5.0, 3.0, 4.0])\nassert result == [0.25, 0.0, 1.0, 0.5, 0.75], f'Expected [0.25, 0.0, 1.0, 0.5, 0.75] (order preserved), got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
7
+ {"task_id": "HumanEval/7", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of strings and a substring, and returns only the strings that contain the substring.", "gold_prompt": "Write a function named `solution` that takes a list of strings and a substring, and returns only the strings that contain the substring. Matching is case sensitive. Preserve the original order of matching strings. Return an empty list if no strings match or if the input list is empty.", "constraints": [{"id": "C1", "description": "Basic filtering works", "test_code": "result = solution(['apple', 'banana', 'apricot'], 'ap')\nassert result == ['apple', 'apricot'], f'Expected [apple, apricot], got {result}'"}, {"id": "C2", "description": "Matching is case sensitive", "test_code": "result = solution(['Apple', 'apple', 'APPLE'], 'apple')\nassert result == ['apple'], f'Expected [apple] (case sensitive), got {result}'"}, {"id": "C3", "description": "Original order of matching strings is preserved", "test_code": "result = solution(['cat', 'car', 'bar', 'card'], 'car')\nassert result == ['car', 'card'], f'Expected [car, card] (order preserved), got {result}'"}, {"id": "C4", "description": "Empty input list returns empty list", "test_code": "result = solution([], 'ap')\nassert result == [], f'Expected [], got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
8
+ {"task_id": "HumanEval/47", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns the median", "gold_prompt": "Write a function named `solution` that takes a list l and returns the median of its elements. For odd-length lists return the middle element. For even-length lists return the average of the two middle elements. Do not mutate the input list.", "constraints": [{"id": "C1", "description": "Basic median calculation", "test_code": "result = solution([2, 4, 6])\nassert result == 4, f'Expected 4, got {result}'"}, {"id": "C2", "description": "Handles negative numbers correctly", "test_code": "result = solution([-100, 0, 5, 15, 20])\nassert result == 5, f'Expected 5, got {result}'"}, {"id": "C3", "description": "Returns average of two middle elements for even-length list that is unsorted", "test_code": "result = solution([-10, 4, 6, 1000, 10, 20])\nassert result == 8.0, f'Expected 8.0, got {result}'"}, {"id": "C4", "description": "Input list is not mutated", "test_code": "inp = [3, 1, 2, 4, 5]\nresult = solution(inp)\nassert inp == [3, 1, 2, 4, 5], f'Input was mutated: {inp}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
9
+ {"task_id": "HumanEval/30", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of numbers and returns only the positive ones.", "gold_prompt": "Write a function named `solution` that takes a list of numbers and returns only the strictly positive values (greater than zero). Preserve the original order of elements. Do not mutate the input list. Return an empty list if no positive values exist.", "constraints": [{"id": "C1", "description": "Basic positive filtering works", "test_code": "result = solution([-2, 4, 6])\nassert result == [4, 6], f'Expected [4, 6], got {result}'"}, {"id": "C2", "description": "Zero is excluded (strictly greater than zero)", "test_code": "result = solution([-2, 0, 5, 3])\nassert result == [5, 3], f'Expected [5, 3] (zero excluded), got {result}'"}, {"id": "C3", "description": "Original order of positive elements is preserved", "test_code": "result = solution([-2, 5, 3, 2, -10, 1])\nassert result == [5, 3, 2, 1], f'Expected [5, 3, 2, 1] (order preserved), got {result}'"}, {"id": "C4", "description": "Returns empty list when no positive values exist", "test_code": "result = solution([-10, -4, -5, -3, -100])\nassert result == [], f'Expected [], got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
10
+ {"task_id": "HumanEval/34", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named solution that returns the unique elements in a list.", "gold_prompt": "Write a function named `solution` that takes a list and returns only the unique values, sorted in ascending order. There should be no duplicate values.", "constraints": [{"id": "C1", "description": "Only unique values", "test_code": "result = solution([-2, 4, 4, 6, 6])\nassert result == [-2, 4, 6], f'Expected [-2, 4, 6], got {result}'"}, {"id": "C2", "description": "Sorted in ascending order", "test_code": "result = solution([-2, 0, 5, 3, 5, 0, 3])\nassert result == [-2, 0, 3, 5], f'Expected [-2, 0, 3, 5] (sorted), got {result}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}
11
+ {"task_id": "HumanEval/51", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns a string without vowels.", "gold_prompt": "Write a function named `solution` that takes a string and returns the same string with all vowels (both uppercase and lowercase) removed. Preserve the original order and case of remaining characters. Return the string unchanged if it has no vowels. Return an empty string if given an empty string.", "constraints": [{"id": "C1", "description": "Removes lowercase vowels", "test_code": "result = solution('testing')\nassert result == 'tstng', f\"Expected tstng, got {result}\""}, {"id": "C2", "description": "Removes uppercase vowels too", "test_code": "result = solution('TEstIng')\nassert result == 'Tstng', f\"Expected Tstng, got {result}\""}, {"id": "C3", "description": "Handles string with no vowels", "test_code": "result = solution('bcdfg')\nassert result == 'bcdfg', f\"Expected bcdfg, got {result}\""}, {"id": "C4", "description": "Handles empty string", "test_code": "result = solution('')\nassert result == '', f\"Expected empty string, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
12
+ {"task_id": "HumanEval/57", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns True if a list is monotonically increasing.", "gold_prompt": "Write a function named `solution` that returns True if the elements are monotonically increasing or monotonically decreasing (the element following is always equal to or less/greater than). Otherwise, it will return False. The list does not mutate.", "constraints": [{"id": "C1", "description": "Monotonically increasing", "test_code": "result = solution([1, 2, 3, 4])\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C2", "description": "Monotonically decreasing", "test_code": "result = solution([4, 3, 2, 1])\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C3", "description": "Handles duplicates properly", "test_code": "result = solution([1, 1, 1])\nassert result == True, f\"Expected True, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
13
+ {"task_id": "HumanEval/58", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns common elements between 2 lists.", "gold_prompt": "Write a function named `solution` that a list of unique and common elements between 2 lists, sorted in ascending order.", "constraints": [{"id": "C1", "description": "Captures common elements", "test_code": "result = solution([1, 2, 3, 4], [2, 3])\nassert result == [2, 3], f\"Expected [2, 3], got {result}\""}, {"id": "C2", "description": "Only returns unique elements, no duplicates even if input has repeats", "test_code": "result = solution([1, 2, 2, 3, 3], [2, 2, 3])\nassert result == [2, 3], f\"Expected [2, 3] (deduplicated), got {result}\""}, {"id": "C3", "description": "Returns in sorted, ascending order", "test_code": "result = solution([5, 0, 8, 1, 3], [3, 2, 6, 8])\nassert result == [3, 8], f\"Expected [3, 8], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
14
+ {"task_id": "HumanEval/42", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns a list incremented by 1.", "gold_prompt": "Write a function named `solution` that takes a list of numbers and returns a new list with each element incremented by 1. Preserve the original order. Do not mutate the input list.", "constraints": [{"id": "C1", "description": "Increments elements", "test_code": "result = solution([1, 2, 3])\nassert result == [2, 3, 4], f'Expected [2, 3, 4], got {result}'"}, {"id": "C2", "description": "Ordering is maintained", "test_code": "result = solution([-1, -2, 1, 5, 10])\nassert result == [0, -1, 2, 6, 11], f'Expected [0, -1, 2, 6, 11] (order preserved), got {result}'"}, {"id": "C3", "description": "Input list is not mutated", "test_code": "inp = [1, 2, 3]\nresult = solution(inp)\nassert inp == [1, 2, 3], f'Input was mutated: {inp}'"}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
15
+ {"task_id": "HumanEval/65", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes an integer x and a shift amount, and circularly shifts the digits of x to the right by shift positions, returning the result as a string.", "gold_prompt": "Write a function named `solution` that takes an integer x and a shift amount. Circularly shift the digits of x to the right by shift positions and return the result as a string. If shift is greater than the number of digits in x, return the digits reversed instead.", "constraints": [{"id": "C1", "description": "Basic circular shift works", "test_code": "result = solution(12, 1)\nassert result == '21', f\"Expected '21', got {result}\""}, {"id": "C2", "description": "Shift equal to digit length wraps back to original", "test_code": "result = solution(12, 2)\nassert result == '12', f\"Expected '12', got {result}\""}, {"id": "C3", "description": "Shift greater than digit length reverses instead", "test_code": "result = solution(97, 8)\nassert result == '79', f\"Expected '79' (reversed), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
16
+ {"task_id": "HumanEval/68", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of non-negative integers and returns the smallest even value along with its index, as a list `[value, index]`.", "gold_prompt": "Write a function named `solution` that takes a list of non-negative integers and returns the smallest even value along with its index, as a list `[value, index]`. If multiple positions share the smallest even value, return the one with the smallest index. If no even values exist or the input list is empty, return an empty list.", "constraints": [{"id": "C1", "description": "Basic smallest even value with index works", "test_code": "result = solution([4, 2, 3])\nassert result == [2, 1], f\"Expected [2, 1], got {result}\""}, {"id": "C2", "description": "Tie-breaking returns smallest index among equal smallest even values", "test_code": "result = solution([5, 0, 3, 0, 4, 2])\nassert result == [0, 1], f\"Expected [0, 1] (first occurrence), got {result}\""}, {"id": "C3", "description": "Returns empty list when no even values exist", "test_code": "result = solution([1, 3, 5, 7])\nassert result == [], f\"Expected [], got {result}\""}, {"id": "C4", "description": "Returns empty list for empty input", "test_code": "result = solution([])\nassert result == [], f\"Expected [], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
17
+ {"task_id": "HumanEval/70", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of integers, and returns the list in a strange order: minimum first, then maximum of the remaining, then minimum of the remaining, and so on.", "gold_prompt": "Write a function named `solution` that takes a list of integers and returns them reordered by repeatedly taking the minimum then the maximum of the remaining elements until all elements are placed. Handle duplicate values, odd-length lists, and empty input correctly.", "constraints": [{"id": "C1", "description": "Basic strange sort works", "test_code": "result = solution([1, 2, 3, 4])\nassert result == [1, 4, 2, 3], f\"Expected [1, 4, 2, 3], got {result}\""}, {"id": "C2", "description": "Handles duplicate values correctly", "test_code": "result = solution([5, 5, 5, 5])\nassert result == [5, 5, 5, 5], f\"Expected [5, 5, 5, 5], got {result}\""}, {"id": "C3", "description": "Handles empty list", "test_code": "result = solution([])\nassert result == [], f\"Expected [], got {result}\""}, {"id": "C4", "description": "Handles odd-length list (middle element placement)", "test_code": "result = solution([1, 2, 3, 4, 5])\nassert result == [1, 5, 2, 4, 3], f\"Expected [1, 5, 2, 4, 3], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
18
+ {"task_id": "HumanEval/72", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list q and a weight limit w, and returns True if the sum of q's elements is less than or equal to w.", "gold_prompt": "Write a function named `solution` that takes a list q and a weight limit w. Return True only if q is a palindrome (reads the same forwards and backwards) AND the sum of its elements is less than or equal to w. Return False if either condition fails.", "constraints": [{"id": "C1", "description": "Basic weight check works", "test_code": "result = solution([3], 5)\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C2", "description": "Returns False when weight is fine but list is not a palindrome", "test_code": "result = solution([1, 2], 5)\nassert result == False, f\"Expected False (not balanced), got {result}\""}, {"id": "C3", "description": "Returns False when palindrome but weight exceeds limit", "test_code": "result = solution([3, 2, 3], 1)\nassert result == False, f\"Expected False (weight exceeded), got {result}\""}, {"id": "C4", "description": "Returns True only when both conditions are satisfied", "test_code": "result = solution([3, 2, 3], 9)\nassert result == True, f\"Expected True, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
19
+ {"task_id": "HumanEval/74", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes two lists of strings and returns whichever list has fewer total characters across all its strings.", "gold_prompt": "Write a function named `solution` that takes two lists of strings, lst1 and lst2. Return whichever list has fewer total characters across all its strings. If both lists have the same total character count, return lst1 (the first list).", "constraints": [{"id": "C1", "description": "Returns list with fewer total characters", "test_code": "result = solution(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])\nassert result == ['hi', 'admin'], f\"Expected ['hi', 'admin'], got {result}\""}, {"id": "C2", "description": "Returns first list when total character counts are equal", "test_code": "result = solution(['hi', 'admin'], ['ab', 'admin'])\nassert result == ['hi', 'admin'], f\"Expected ['hi', 'admin'] (tie goes to first, both have 7 chars), got {result}\""}, {"id": "C3", "description": "Handles empty lists correctly", "test_code": "result = solution([], [])\nassert result == [], f\"Expected [], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
20
+ {"task_id": "HumanEval/64", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string and returns the number of vowels in it. Vowels are 'a', 'e', 'i', 'o', 'u'.", "gold_prompt": "Write a function named `solution` that takes a string and returns the number of vowels in it, counting both uppercase and lowercase 'a', 'e', 'i', 'o', 'u'. The letter 'y' also counts as a vowel, but only when it is the last character of the string.", "constraints": [{"id": "C1", "description": "Basic vowel count works", "test_code": "result = solution('abcde')\nassert result == 2, f\"Expected 2, got {result}\""}, {"id": "C2", "description": "Counts uppercase vowels and trailing Y together", "test_code": "result = solution('ACEDY')\nassert result == 3, f\"Expected 3 (A, E, and trailing Y), got {result}\""}, {"id": "C3", "description": "Counts trailing 'y' as a vowel when no other vowels present", "test_code": "result = solution('sky')\nassert result == 1, f\"Expected 1 (y at end counts, no other vowels), got {result}\""}, {"id": "C4", "description": "Does not count 'y' when it is not the last character", "test_code": "result = solution('gym')\nassert result == 0, f\"Expected 0 (y not at end, no other vowels), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
21
+ {"task_id": "HumanEval/66", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string and returns the sum of ASCII codes of its characters.", "gold_prompt": "Write a function named `solution` that takes a string and returns the sum of ASCII codes of only the uppercase characters in the string. Lowercase letters and other characters are not included in the sum.", "constraints": [{"id": "C1", "description": "Basic sum-of-all-characters case works (matches ambiguous prompt literally)", "test_code": "result = solution('AB')\nassert result == 131, f\"Expected 131, got {result}\""}, {"id": "C2", "description": "Only uppercase letters are counted, lowercase excluded", "test_code": "result = solution('abcCd')\nassert result == 67, f\"Expected 67 (only C), got {result}\""}, {"id": "C3", "description": "Empty string returns 0", "test_code": "result = solution('')\nassert result == 0, f\"Expected 0, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
22
+ {"task_id": "HumanEval/71", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes the lengths of three sides and returns the area of the triangle.", "gold_prompt": "Write a function named `solution` that takes the lengths of three sides of a triangle and returns the area rounded to 2 decimal points. Three sides form a valid triangle when the sum of any two sides is greater than the third. If the sides do not form a valid triangle, return -1.", "constraints": [{"id": "C1", "description": "Basic area calculation works for valid triangle", "test_code": "result = solution(3, 4, 5)\nassert result == 6.00, f\"Expected 6.00, got {result}\""}, {"id": "C2", "description": "Returns -1 for invalid triangle (fails triangle inequality)", "test_code": "result = solution(1, 2, 10)\nassert result == -1, f\"Expected -1, got {result}\""}, {"id": "C3", "description": "Result is rounded to 2 decimal places", "test_code": "result = solution(5, 5, 5)\nimport math\nexpected = round((5**2 * math.sqrt(3)) / 4, 2)\nassert result == expected, f\"Expected {expected}, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
23
+ {"task_id": "HumanEval/86", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string and returns a version where the characters are arranged in ascending order based on ASCII value.", "gold_prompt": "Write a function named `solution` that takes a string and returns an ordered version of it. Words (separated by single spaces) should each have their characters individually rearranged in ascending ASCII order. The order of the words and the spaces between them should be preserved.", "constraints": [{"id": "C1", "description": "Basic character ordering within a single word works", "test_code": "result = solution('cba')\nassert result == 'abc', f\"Expected 'abc', got {result}\""}, {"id": "C2", "description": "Word boundaries are preserved, not sorted across whole string", "test_code": "result = solution('zyx wvu')\nassert result == 'xyz uvw', f\"Expected 'xyz uvw' (each word sorted separately), got {result}\""}, {"id": "C3", "description": "Original word order and spacing preserved", "test_code": "result = solution('cba fed')\nassert result == 'abc def', f\"Expected 'abc def', got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
24
+ {"task_id": "HumanEval/90", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns the 2nd smallest element of the list.", "gold_prompt": "Write a function named `solution` that takes a list of integers and returns the 2nd smallest element of the list. Return None if there is no such element.", "constraints": [{"id": "C1", "description": "Returns 2nd smallest element", "test_code": "result = solution([1, 2, 3, 4, 5])\nassert result == 2, f\"Expected 2, got {result}\""}, {"id": "C2", "description": "Can handle unsorted lists", "test_code": "result = solution([5, 10, 2, 1, 13, 60])\nassert result == 2, f\"Expected 2, got {result}\""}, {"id": "C3", "description": "Can handle empty lists", "test_code": "result = solution([])\nassert result == None, f\"Expected None, got {result}\""}, {"id": "C4", "description": "Can handle lists with duplicate values (therefore, no 2nd smallest element)", "test_code": "result = solution([2, 2, 2, 2])\nassert result == None, f\"Expected None, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
25
+ {"task_id": "HumanEval/95", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns True if all keys are in lower or upper case.", "gold_prompt": "Write a function named `solution` that takes a dictionary and returns True if all keys are strings in lower case, or all keys are strings in upper case. Return False if the keys are mixed case or if the dictionary is empty.", "constraints": [{"id": "C1", "description": "Returns True when all keys are lowercase", "test_code": "result = solution({'a': 1, 'b': 2})\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C2", "description": "Returns True when all keys are uppercase", "test_code": "result = solution({'A': 1, 'B': 2})\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C3", "description": "Returns False when keys are mixed case", "test_code": "result = solution({'a': 1, 'B': 2})\nassert result == False, f\"Expected False, got {result}\""}, {"id": "C4", "description": "Returns False for empty dictionary", "test_code": "result = solution({})\nassert result == False, f\"Expected False, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
26
+ {"task_id": "HumanEval/98", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns the number of uppercase vowels on even indices.", "gold_prompt": "Write a function named `solution` that takes a string and counts the number of uppercase vowels that have an even-numbered index (0-indexed). If the string is empty, it should return 0 instead of None or raising an error.", "constraints": [{"id": "C1", "description": "Returns correct count of uppercase vowels on even indices", "test_code": "result = solution('aEIoU')\nassert result == 2, f\"Expected 2, got {result}\""}, {"id": "C2", "description": "Returns 0 for empty string rather than None or error", "test_code": "result = solution('')\nassert result == 0, f\"Expected 0, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}
27
+ {"task_id": "HumanEval/99", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a value (string) representing a number and returns the closest integer to it.", "gold_prompt": "Write a function named `solution` that takes a value (string) representing a number and returns the closest integer to it. If the number is exactly equidistant between two integers, round away from zero (not banker's rounding). For example, 14.5 rounds to 15, and -14.5 rounds to -15.", "constraints": [{"id": "C1", "description": "Basic rounding works for non-tie cases", "test_code": "result = solution('15.3')\nassert result == 15, f\"Expected 15, got {result}\""}, {"id": "C2", "description": "Ties round away from zero for positive numbers", "test_code": "result = solution('14.5')\nassert result == 15, f\"Expected 15 (away from zero), got {result}\""}, {"id": "C3", "description": "Ties round away from zero for negative numbers", "test_code": "result = solution('-14.5')\nassert result == -15, f\"Expected -15 (away from zero), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
28
+ {"task_id": "HumanEval/102", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes two positive numbers and returns the biggest even number within their range.", "gold_prompt": "Write a function named `solution` that takes two positive numbers x and y, and returns the biggest even number in the inclusive range [x, y]. If no even number exists in that range, return -1.", "constraints": [{"id": "C1", "description": "Returns biggest even number within range", "test_code": "result = solution(1, 5)\nassert result == 4, f\"Expected 4, got {result}\""}, {"id": "C2", "description": "Range is inclusive of the endpoints", "test_code": "result = solution(1, 4)\nassert result == 4, f\"Expected 4 (endpoint included), got {result}\""}, {"id": "C3", "description": "Returns -1 when no even number exists in range", "test_code": "result = solution(1, 1)\nassert result == -1, f\"Expected -1, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
29
+ {"task_id": "HumanEval/104", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of positive integers and returns only the ones where every digit is odd.", "gold_prompt": "Write a function named `solution` that takes a list of positive integers and returns a sorted list (ascending order) of only the elements where every digit is odd (no even digits present).", "constraints": [{"id": "C1", "description": "Filters correctly for numbers with all-odd digits (order not checked)", "test_code": "result = solution([15, 33, 1422, 1])\nassert set(result) == {1, 15, 33}, f\"Expected elements {{1, 15, 33}}, got {result}\""}, {"id": "C2", "description": "Output is sorted in ascending order", "test_code": "result = solution([33, 1, 15])\nassert result == [1, 15, 33], f\"Expected [1, 15, 33] (sorted), got {result}\""}, {"id": "C3", "description": "Returns empty list when no elements qualify", "test_code": "result = solution([152, 323, 1422, 10])\nassert result == [], f\"Expected [], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
30
+ {"task_id": "HumanEval/108", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes an array of integers and returns the count of elements whose digit sum is greater than 0.", "gold_prompt": "Write a function named `solution` that takes an array of integers and returns the count of elements whose digit sum is greater than 0. For negative numbers, treat the first digit as negative when summing (e.g., -123 has signed digits -1, 2, 3, summing to 4).", "constraints": [{"id": "C1", "description": "Basic digit sum count works for positive numbers", "test_code": "result = solution([1, 11, -1, -11, 4])\nassert result == 3, f\"Expected 3, got {result}\""}, {"id": "C2", "description": "Negative single-digit numbers are treated as negative, not counted", "test_code": "result = solution([-1])\nassert result == 0, f\"Expected 0 (digit sum is -1), got {result}\""}, {"id": "C3", "description": "Handles empty array", "test_code": "result = solution([])\nassert result == 0, f\"Expected 0, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
31
+ {"task_id": "HumanEval/120", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes an array of integers and a positive integer k, and returns a sorted list of the k largest numbers in the array.", "gold_prompt": "Write a function named `solution` that takes an array of integers and a positive integer k, and returns a sorted list (ascending order) containing the k largest numbers in the array.", "constraints": [{"id": "C1", "description": "Basic k largest numbers works", "test_code": "result = solution([-3, -4, 5], 3)\nassert result == [-4, -3, 5], f\"Expected [-4, -3, 5], got {result}\""}, {"id": "C2", "description": "Output is sorted ascending, not descending", "test_code": "result = solution([4, -4, 4], 2)\nassert result == [4, 4], f\"Expected [4, 4] (ascending order), got {result}\""}, {"id": "C3", "description": "Handles duplicate values correctly", "test_code": "result = solution([1, 5, 5, 3], 2)\nassert result == [5, 5], f\"Expected [5, 5], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
32
+ {"task_id": "HumanEval/126", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of numbers and returns True if sorted in ascending order. Assume no negative numbers, and only integers.", "gold_prompt": "Write a function named `solution` that takes a list of numbers and returns True if sorted in ascending order. If any number appears more than twice in the list, return False regardless of sort order. An empty list is considered sorted and returns True. Assume no negative numbers, and only integers.", "constraints": [{"id": "C1", "description": "Works on basic ascending case", "test_code": "result = solution([1, 2, 3, 4])\nassert result == True, f\"Expected True, got {result}\""}, {"id": "C2", "description": "Allows one duplicate per number, still sorted", "test_code": "result = solution([1, 2, 2, 3, 3, 4])\nassert result == True, f\"Expected True (single duplicates allowed), got {result}\""}, {"id": "C3", "description": "Returns False when a number appears more than twice, even if sorted", "test_code": "result = solution([1, 2, 2, 2, 3, 4])\nassert result == False, f\"Expected False (2 appears 3 times), got {result}\""}, {"id": "C4", "description": "Empty list is considered sorted (returns True)", "test_code": "result = solution([])\nassert result == True, f\"Expected True, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3", "C4"]}
33
+ {"task_id": "HumanEval/91", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string of sentences and counts how many sentences start with 'I'. Sentences are delimited by periods, question marks, or exclamation marks.", "gold_prompt": "Write a function named `solution` that takes a string of sentences and counts how many sentences start with the standalone word 'I' (not words merely beginning with 'I' like 'Is' or 'It'). Sentences are delimited by periods, question marks, or exclamation marks.", "constraints": [{"id": "C1", "description": "Basic case works for sentence starting with 'I'", "test_code": "result = solution('The sky is blue. The sun is shining. I love this weather')\nassert result == 1, f\"Expected 1, got {result}\""}, {"id": "C2", "description": "Words merely starting with 'I' (like 'Is', 'It') do not count", "test_code": "result = solution('Is the sky blue? It is nice.')\nassert result == 0, f\"Expected 0 (Is/It are not standalone I), got {result}\""}, {"id": "C3", "description": "Handles multiple sentence delimiters (., ?, !)", "test_code": "result = solution('I love It! I will be productive. Is that ok?')\nassert result == 2, f\"Expected 2, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
34
+ {"task_id": "HumanEval/131", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a positive integer n and returns the product of the odd digits.", "gold_prompt": "Write a function named `solution` that takes a positive integer n and returns the product of the odd digits. Return 0 if all digits are even.", "constraints": [{"id": "C1", "description": "Basic case of product of odd digits works.", "test_code": "result = solution(15)\nassert result == 5, f\"Expected 5, got {result}\""}, {"id": "C2", "description": "Handles all even case properly.", "test_code": "result = solution(22)\nassert result == 0, f\"Expected 0, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}
35
+ {"task_id": "HumanEval/135", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that returns the largest index of an element which is not greater than or equal to the element immediately preceding it. The given array will not contain duplicate values.", "gold_prompt": "Write a function named `solution` that returns the largest index of an element which is not greater than or equal to the element immediately preceding it. If no such element exists, return -1. The given array will not contain duplicate values.", "constraints": [{"id": "C1", "description": "Basic case of largest index violating non-decreasing order works", "test_code": "result = solution([5, 4, 6, 7, 8])\nassert result == 1, f\"Expected 1, got {result}\""}, {"id": "C2", "description": "Handles non-existing case, returns -1", "test_code": "result = solution([1, 2, 3])\nassert result == -1, f\"Expected -1, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}
36
+ {"task_id": "HumanEval/136", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of integers and returns a tuple (a, b), where a is the largest negative integer and b is the smallest positive integer in the list.", "gold_prompt": "Write a function named `solution` that takes a list of integers and returns a tuple (a, b), where a is the largest negative integer and b is the smallest positive integer in the list. Zero counts as neither positive nor negative. If no negative integers exist, a is None. If no positive integers exist, b is None.", "constraints": [{"id": "C1", "description": "Basic case works when both negative and positive exist", "test_code": "result = solution([1, 3, 2, 4, 5, 6, -2])\nassert tuple(result) == (-2, 1), f\"Expected (-2, 1), got {result}\""}, {"id": "C2", "description": "Zero is not counted as positive or negative", "test_code": "result = solution([0])\nassert tuple(result) == (None, None), f\"Expected (None, None), got {result}\""}, {"id": "C3", "description": "Returns None for the missing half when only one sign exists", "test_code": "result = solution([2, 4, 1, 3, 5, 7])\nassert tuple(result) == (None, 1), f\"Expected (None, 1), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
37
+ {"task_id": "HumanEval/140", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string and replaces spaces with underscores. If there are multiple consecutive spaces, replace them with a dash instead.", "gold_prompt": "Write a function named `solution` that takes a string and replaces single spaces with underscores. If there are more than 2 consecutive spaces (3 or more), replace the entire run of spaces with a single dash instead of an underscore per space.", "constraints": [{"id": "C1", "description": "Single space becomes underscore", "test_code": "result = solution('Example 1')\nassert result == 'Example_1', f\"Expected 'Example_1', got {result}\""}, {"id": "C2", "description": "Exactly 2 consecutive spaces become 2 underscores, not a dash (threshold is 3+)", "test_code": "result = solution('Example 1')\nassert result == 'Example__1', f\"Expected 'Example__1' (2 spaces = 2 underscores), got {result}\""}, {"id": "C3", "description": "3 or more consecutive spaces become a single dash", "test_code": "result = solution('Example 1')\nassert result == 'Example-1', f\"Expected 'Example-1' (3+ spaces = dash), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
38
+ {"task_id": "HumanEval/149", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of strings, removes strings with odd length, and returns the result sorted by length in ascending order.", "gold_prompt": "Write a function named `solution` that takes a list of strings, removes strings with odd length (keeping only even-length strings), and returns the result sorted by length in ascending order. If two strings have the same length, sort them alphabetically.", "constraints": [{"id": "C1", "description": "Basic filtering and sorting by length works", "test_code": "result = solution(['aa', 'a', 'aaa'])\nassert result == ['aa'], f\"Expected ['aa'], got {result}\""}, {"id": "C2", "description": "Ties in length are sorted alphabetically", "test_code": "result = solution(['dcba', 'abcd'])\nassert result == ['abcd', 'dcba'], f\"Expected ['abcd', 'dcba'] (alphabetical for tie), got {result}\""}, {"id": "C3", "description": "Handles multiple length groups sorted correctly with ties resolved", "test_code": "result = solution(['school', 'asdf', 'b', 'AI'])\nassert result == ['AI', 'asdf', 'school'], f\"Expected ['AI', 'asdf', 'school'], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
39
+ {"task_id": "HumanEval/151", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of numbers and returns the sum of squares of numbers in the list that are odd.", "gold_prompt": "Write a function named `solution` that takes a list of numbers and returns the sum of squares of numbers in the list that are odd. Ignore numbers that are negative or not whole integers (e.g., floats with decimal parts). Return 0 for an empty list.", "constraints": [{"id": "C1", "description": "Basic case works", "test_code": "result = solution([1, 2, 3])\nassert result == 10, f\"Expected 10, got {result}\""}, {"id": "C2", "description": "Ignores negative numbers and non-integer (decimal) values", "test_code": "result = solution([1, 3, -5, 0.5, 2.7])\nassert result == 10, f\"Expected 10 (only 1 and 3 count), got {result}\""}, {"id": "C3", "description": "Returns 0 for empty list", "test_code": "result = solution([])\nassert result == 0, f\"Expected 0, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
40
+ {"task_id": "HumanEval/158", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of strings and returns the word with the maximum number of unique characters.", "gold_prompt": "Write a function named `solution` that takes a list of strings and returns the word with the maximum number of unique characters. If multiple words share the same maximum count of unique characters, return the one that comes first in lexicographical order.", "constraints": [{"id": "C1", "description": "Uses unique character count, not total string length", "test_code": "result = solution(['aabb', 'abcd'])\nassert result == 'abcd', f\"Expected 'abcd' (4 unique chars vs 2), got {result}\""}, {"id": "C2", "description": "Ties in unique character count resolve lexicographically", "test_code": "result = solution(['name', 'enam', 'game'])\nassert result == 'enam', f\"Expected 'enam', got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}
41
+ {"task_id": "HumanEval/163", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes two positive integers a and b, and returns the even digits between a and b.", "gold_prompt": "Write a function named `solution` that takes two positive integers a and b, and returns the even single digits (0-9) between a and b, in ascending order, inclusive of endpoints. Works regardless of whether a or b is larger.", "constraints": [{"id": "C1", "description": "Basic case works", "test_code": "result = solution(2, 8)\nassert result == [2, 4, 6, 8], f\"Expected [2, 4, 6, 8], got {result}\""}, {"id": "C2", "description": "Result is capped at single digits (0-9), even if b is larger", "test_code": "result = solution(1, 14)\nassert result == [2, 4, 6, 8], f\"Expected [2, 4, 6, 8] (capped at single digits), got {result}\""}, {"id": "C3", "description": "Works when a > b (order is swapped internally)", "test_code": "result = solution(8, 2)\nassert result == [2, 4, 6, 8], f\"Expected [2, 4, 6, 8], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
42
+ {"task_id": "HumanEval/88", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes an array of non-negative integers and returns a sorted copy of the array, without modifying the original.", "gold_prompt": "Write a function named `solution` that takes an array of non-negative integers and returns a sorted copy. Sort in ascending order if the sum of the first and last elements is odd, or descending order if that sum is even. Do not mutate the input array.", "constraints": [{"id": "C1", "description": "Basic sorting works when sum is odd (ascending)", "test_code": "result = solution([2, 4, 3, 0, 1, 5])\nassert result == [0, 1, 2, 3, 4, 5], f\"Expected [0, 1, 2, 3, 4, 5], got {result}\""}, {"id": "C2", "description": "Sorts descending when sum of first and last elements is even", "test_code": "result = solution([2, 4, 3, 0, 1, 5, 6])\nassert result == [6, 5, 4, 3, 2, 1, 0], f\"Expected [6, 5, 4, 3, 2, 1, 0] (descending), got {result}\""}, {"id": "C3", "description": "Input array is not mutated", "test_code": "inp = [2, 4, 3, 0, 1, 5]\nresult = solution(inp)\nassert inp == [2, 4, 3, 0, 1, 5], f\"Input was mutated: {inp}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
43
+ {"task_id": "HumanEval/93", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a message and swaps the case of all letters.", "gold_prompt": "Write a function named `solution` that takes a message, swaps the case of all letters, and then replaces all vowels (a, e, i, o, u, both cases) with the letter that appears 2 places ahead of it in the alphabet. Case swapping happens first, then the vowel shift is applied to the result.", "constraints": [{"id": "C1", "description": "Basic case swap works (vowel-free input, isolates case-swap only)", "test_code": "result = solution('Xyz')\nassert result == 'xYZ', f\"Expected 'xYZ', got {result}\""}, {"id": "C2", "description": "Vowels are shifted 2 places ahead after case swap", "test_code": "result = solution('test')\nassert result == 'TGST', f\"Expected 'TGST', got {result}\""}, {"id": "C3", "description": "Order matters: case swap happens before vowel shift", "test_code": "result = solution('a')\nassert result == 'C', f\"Expected 'C' (swap to A, then shift to C), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
44
+ {"task_id": "HumanEval/101", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string of words separated by commas and returns a list of the words.", "gold_prompt": "Write a function named `solution` that takes a string of words separated by commas, spaces, or both, and returns a list of the words with no empty strings in the result, even if there are consecutive delimiters.", "constraints": [{"id": "C1", "description": "Basic comma-separated case works", "test_code": "result = solution('One, two, three')\nassert result == ['One', 'two', 'three'], f\"Expected ['One', 'two', 'three'], got {result}\""}, {"id": "C2", "description": "Handles space-only separated words too", "test_code": "result = solution('Hi my name is John')\nassert result == ['Hi', 'my', 'name', 'is', 'John'], f\"Expected ['Hi', 'my', 'name', 'is', 'John'], got {result}\""}, {"id": "C3", "description": "Consecutive delimiters do not produce empty string entries", "test_code": "result = solution('One,, two, three,')\nassert result == ['One', 'two', 'three'], f\"Expected ['One', 'two', 'three'] (no empty entries), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
45
+ {"task_id": "HumanEval/105", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes an array of integers, sorts the values, reverses the order, and returns a list where each value is replaced by its corresponding number name (One, Two, Three, ... Nine).", "gold_prompt": "Write a function named `solution` that takes an array of integers, keeps only values between 1 and 9 inclusive, sorts them, reverses the order, and returns a list where each remaining value is replaced by its corresponding number name (One through Nine). Values outside 1-9 are silently ignored rather than causing an error.", "constraints": [{"id": "C1", "description": "Basic sort, reverse, and name conversion works", "test_code": "result = solution([2, 1, 1, 4, 5, 8, 2, 3])\nassert result == ['Eight', 'Five', 'Four', 'Three', 'Two', 'Two', 'One', 'One'], f\"Expected the reversed named list, got {result}\""}, {"id": "C2", "description": "Values outside 1-9 range are silently ignored, not erroring", "test_code": "result = solution([1, -1, 55])\nassert result == ['One'], f\"Expected ['One'] (out-of-range values ignored), got {result}\""}, {"id": "C3", "description": "Empty array returns empty list", "test_code": "result = solution([])\nassert result == [], f\"Expected [], got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
46
+ {"task_id": "HumanEval/111", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a space-separated string of lowercase letters and returns a dictionary of the letter with the most repetitions and its count.", "gold_prompt": "Write a function named `solution` that takes a space-separated string of lowercase letters and returns a dictionary mapping each letter to its count, but only including letters that have the maximum occurrence count. If multiple letters are tied for the maximum, include all of them. Return an empty dictionary for an empty string.", "constraints": [{"id": "C1", "description": "Basic case with a single most-frequent letter works", "test_code": "result = solution('b b b b a')\nassert result == {'b': 4}, f\"Expected {{'b': 4}}, got {result}\""}, {"id": "C2", "description": "Returns all letters tied for the maximum count, not just one", "test_code": "result = solution('a b b a')\nassert result == {'a': 2, 'b': 2}, f\"Expected {{'a': 2, 'b': 2}}, got {result}\""}, {"id": "C3", "description": "Empty string returns empty dictionary", "test_code": "result = solution('')\nassert result == {}, f\"Expected {{}}, got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
47
+ {"task_id": "HumanEval/112", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes two strings s and c, removes from s any character that appears in c, and checks if the resulting string is a palindrome.", "gold_prompt": "Write a function named `solution` that takes two strings s and c, removes from s any character that appears in c, and returns a tuple (result_string, is_palindrome) where is_palindrome is True if the resulting string reads the same forwards and backwards.", "constraints": [{"id": "C1", "description": "Basic filtering and palindrome check works", "test_code": "result = solution('abcde', 'ae')\nassert tuple(result) == ('bcd', False), f\"Expected ('bcd', False), got {result}\""}, {"id": "C2", "description": "Returns a tuple with result string as first element and boolean as second", "test_code": "result = solution('abcdedcba', 'ab')\nassert tuple(result) == ('cdedc', True), f\"Expected ('cdedc', True), got {result}\""}, {"id": "C3", "description": "Handles case where all characters are removed (empty string is a palindrome)", "test_code": "result = solution('a', 'a')\nassert tuple(result) == ('', True), f\"Expected ('', True), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
48
+ {"task_id": "HumanEval/145", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a list of integers and sorts them in ascending order according to the sum of their digits.", "gold_prompt": "Write a function named `solution` that takes a list of integers and sorts them in ascending order by the sum of their digits. For negative numbers, treat the first digit as negative when summing (e.g., -11 has digit sum -1-1=-2). If multiple items have the same digit sum, preserve their original relative order (stable sort).", "constraints": [{"id": "C1", "description": "Basic digit-sum sorting works for positive numbers, no ties", "test_code": "result = solution([100, 25, 3])\nassert result == [100, 3, 25], f\"Expected [100, 3, 25], got {result}\""}, {"id": "C2", "description": "Negative numbers treat first digit as negative in the sum", "test_code": "result = solution([1, 11, -1, -11, -12])\nassert result == [-1, -11, 1, -12, 11], f\"Expected [-1, -11, 1, -12, 11], got {result}\""}, {"id": "C3", "description": "Ties in digit sum preserve original relative order (stable sort)", "test_code": "result = solution([10, 1])\nassert result == [10, 1], f\"Expected [10, 1] (both sum to 1, original order preserved), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2", "C3"]}
49
+ {"task_id": "HumanEval/161", "spec_type": "algorithm", "ambiguous_prompt": "Write a function named `solution` that takes a string and swaps the case of each letter, leaving non-letter characters unchanged.", "gold_prompt": "Write a function named `solution` that takes a string and swaps the case of each letter (lower to upper, upper to lower), leaving non-letter characters unchanged. If the string contains no letters at all, return the string reversed instead.", "constraints": [{"id": "C1", "description": "Basic case swap works, non-letters unchanged", "test_code": "result = solution('#a@C')\nassert result == '#A@c', f\"Expected '#A@c', got {result}\""}, {"id": "C2", "description": "String with no letters is reversed instead of returned as-is", "test_code": "result = solution('1234')\nassert result == '4321', f\"Expected '4321' (reversed, no letters present), got {result}\""}], "stated_test_ids": ["C1"], "hidden_test_ids": ["C2"]}