Qwen3.8-27B-honey / evals /code_recheck.json
robertkeus's picture
Code-bucket recheck: regression confirmed and quantified (+35% greedy, +39/+66% sampled; prose appendices, code itself 12% tighter)
ef72fc9 verified
Raw History Blame Contribute Delete
73.9 kB
{
"summary": {
"all": {
"base": {
"mean_tokens": 132.9,
"total_tokens": 6378,
"pass": 48,
"n": 48,
"truncated": 0
},
"honey": {
"mean_tokens": 195.3,
"total_tokens": 9375,
"pass": 47,
"n": 48,
"truncated": 0
},
"token_delta_pct": 47.0
},
"greedy": {
"base": {
"mean_tokens": 126.8,
"total_tokens": 2029,
"pass": 16,
"n": 16,
"truncated": 0
},
"honey": {
"mean_tokens": 171.1,
"total_tokens": 2737,
"pass": 16,
"n": 16,
"truncated": 0
},
"token_delta_pct": 34.9
},
"t1_s1": {
"base": {
"mean_tokens": 136.8,
"total_tokens": 2188,
"pass": 16,
"n": 16,
"truncated": 0
},
"honey": {
"mean_tokens": 227.4,
"total_tokens": 3638,
"pass": 15,
"n": 16,
"truncated": 0
},
"token_delta_pct": 66.3
},
"t1_s2": {
"base": {
"mean_tokens": 135.1,
"total_tokens": 2161,
"pass": 16,
"n": 16,
"truncated": 0
},
"honey": {
"mean_tokens": 187.5,
"total_tokens": 3000,
"pass": 16,
"n": 16,
"truncated": 0
},
"token_delta_pct": 38.8
}
},
"results": [
{
"key": "code1:greedy",
"id": "code1",
"cfg": "greedy",
"base": {
"tokens": 97,
"secs": 11.4,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s: str) -> bool:\n \"\"\"\n Returns True if the string s reads the same forwards and backwards,\n ignoring case and non-alphanumeric characters.\n \"\"\"\n # Filter to only alphanumeric characters and convert to lowercase\n cleaned = [char.lower() for char in s if char.isalnum()]\n # Check if the cleaned list is a palindrome\n return cleaned == cleaned[::-1]\n```"
},
"honey": {
"tokens": 173,
"secs": 33.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s):\n cleaned = ''.join(c.lower() for c in s if c.isalnum())\n return cleaned == cleaned[::-1]\n```\n\n**How it works:**\n\n1. **Filter and normalize** \u2014 `c.isalnum()` keeps only letters and digits; `c.lower()` makes the comparison case-insensitive.\n2. **Compare** \u2014 `cleaned[::-1]` reverses the string; equality means it's a palindrome.\n\n**Examples:**\n\n```python\nprint(is_palindrome(\"A man, a plan, a canal: Panama\")) # True\nprint(is_palindrome(\"race a car\")) # False\nprint(is_palindrome(\"Was it a car or a cat I saw?\")) # True\nprint(is_palindrome(\"\")) # True\n```"
}
},
{
"key": "code1:t1_s1",
"id": "code1",
"cfg": "t1_s1",
"base": {
"tokens": 99,
"secs": 11.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s: str) -> bool:\n \"\"\"\n Returns True if the string s reads the same forwards and backwards,\n ignoring case and non-alphanumeric characters.\n \"\"\"\n # Filter to keep only alphanumeric characters and convert to lowercase\n filtered = ''.join(char.lower() for char in s if char.isalnum())\n # Check if the filtered string is a palindrome\n return filtered == filtered[::-1]\n```"
},
"honey": {
"tokens": 124,
"secs": 23.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s):\n cleaned = ''.join(ch.lower() for ch in s if ch.isalnum())\n return cleaned == cleaned[::-1]\n```\n\n**How it works:**\n- Filters to alphanumeric characters only using `ch.isalnum()`\n- Converts to lowercase with `ch.lower()`\n- Compares the string to its reverse (`[::-1]`)\n\n**Example:**\n```python\nprint(is_palindrome(\"A man, a plan, a canal: Panama\")) # True\nprint(is_palindrome(\"race a car\")) # False\n```"
}
},
{
"key": "code1:t1_s2",
"id": "code1",
"cfg": "t1_s2",
"base": {
"tokens": 56,
"secs": 6.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s: str) -> bool:\n # Filter to only alphanumeric characters and convert to lowercase\n cleaned = ''.join(char.lower() for char in s if char.isalnum())\n return cleaned == cleaned[::-1]\n```"
},
"honey": {
"tokens": 74,
"secs": 14.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_palindrome(s):\n cleaned = ''.join(c.lower() for c in s if c.isalnum())\n return cleaned == cleaned[::-1]\n```\n\n`c.isalnum()` filters out non-alphanumeric characters, `.lower()` normalizes case, and `cleaned[::-1]` reverses the string for comparison."
}
},
{
"key": "code2:greedy",
"id": "code2",
"cfg": "greedy",
"base": {
"tokens": 101,
"secs": 11.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n):\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```"
},
"honey": {
"tokens": 139,
"secs": 26.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n):\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```\n\nCheck order matters: test `% 15` first so multiples of both 3 and 5 get `'FizzBuzz'`, not just `'Fizz'` or `'Buzz'`."
}
},
{
"key": "code2:t1_s1",
"id": "code2",
"cfg": "t1_s1",
"base": {
"tokens": 107,
"secs": 12.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n: int) -> list[str]:\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```"
},
"honey": {
"tokens": 150,
"secs": 28.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n):\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```\n\nCheck: `fizzbuzz(15)` returns `['1','2','Fizz','4','Buzz','Fizz','7','8','Fizz','Buzz','11','Fizz','13','14','FizzBuzz']`."
}
},
{
"key": "code2:t1_s2",
"id": "code2",
"cfg": "t1_s2",
"base": {
"tokens": 170,
"secs": 20.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n):\n \"\"\"\n Returns a list of strings for numbers 1 to n following FizzBuzz rules:\n - 'FizzBuzz' for multiples of 15\n - 'Fizz' for multiples of 3\n - 'Buzz' for multiples of 5\n - The number as a string otherwise\n \"\"\"\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```"
},
"honey": {
"tokens": 191,
"secs": 35.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef fizzbuzz(n):\n result = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n result.append('FizzBuzz')\n elif i % 3 == 0:\n result.append('Fizz')\n elif i % 5 == 0:\n result.append('Buzz')\n else:\n result.append(str(i))\n return result\n```\n\nChecking the order matters: `15` is tested first so numbers like `15`, `30` get `'FizzBuzz'` rather than falling into the `'Fizz'` branch. For example, `fizzbuzz(15)` returns `['1','2','Fizz','4','Buzz','Fizz','7','8','Fizz','Buzz','11','Fizz','13','14','FizzBuzz']`."
}
},
{
"key": "code3:greedy",
"id": "code3",
"cfg": "greedy",
"base": {
"tokens": 68,
"secs": 9.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef flatten(lst):\n \"\"\"Flatten an arbitrarily nested list of lists into a flat list.\"\"\"\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 160,
"secs": 29.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```\n\n**How it works:**\n- Iterates over each `item` in the input list.\n- If `item` is itself a list, recursively calls `flatten` on it and extends the result.\n- Otherwise, appends the item directly.\n\n**Example:**\n```python\n>>> flatten([1, [2, [3, [4, 5]], 6], 7])\n[1, 2, 3, 4, 5, 6, 7]\n```"
}
},
{
"key": "code3:t1_s1",
"id": "code3",
"cfg": "t1_s1",
"base": {
"tokens": 68,
"secs": 8.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef flatten(lst):\n \"\"\"Flatten an arbitrarily nested list of lists into a flat list.\"\"\"\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 432,
"secs": 79.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "## Flattening a Nested List\n\nHere's a recursive solution that handles arbitrarily deep nesting:\n\n```python\ndef flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```\n\n### How it works\n\n- **Base case**: when a sub-list is reached that contains no further lists, its elements are appended directly.\n- **Recursive step**: when an element is itself a list, `flatten` is called on it and the returned flat list is `extend`ed into `result`.\n- `isinstance(item, list)` checks for lists specifically. If you want to treat any iterable (tuples, sets, etc.) as nested, replace it with a broader check like `hasattr(item, '__iter__') and not isinstance(item, str)`.\n\n### Examples\n\n```python\nprint(flatten([1, [2, [3, [4, [5]]]]]))\n# [1, 2, 3, 4, 5]\n\nprint(flatten([[1, 2], [3, 4], [5, 6]]))\n# [1, 2, 3, 4, 5, 6]\n\nprint(flatten([]))\n# []\n\nprint(flatten([[[]]]))\n# []\n\nprint(flatten([1, [2, [3, [4, [5, [6, [7]]]]]]]))\n# [1, 2, 3, 4, 5, 6, 7]\n```\n\n### Generator version (lazy, memory-friendly)\n\nFor large datasets, a generator avoids building intermediate lists:\n\n```python\ndef flatten(lst):\n for item in lst:\n if isinstance(item, list):\n yield from flatten(item)\n else:\n yield item\n```\n\nCall it with `list(flatten(data))` when you need a concrete list."
}
},
{
"key": "code3:t1_s2",
"id": "code3",
"cfg": "t1_s2",
"base": {
"tokens": 68,
"secs": 8.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef flatten(lst):\n \"\"\"Flatten an arbitrarily nested list of lists into a flat list.\"\"\"\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 287,
"secs": 53.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef flatten(lst):\n \"\"\"Flatten an arbitrarily nested list of lists into a flat list.\"\"\"\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result\n```\n\n**How it works:**\n\n- Iterate over each `item` in the input `lst`.\n- If `item` is a `list`, recursively call `flatten` on it and extend `result` with the flattened sub-list.\n- Otherwise, append the item directly.\n- Base case: a list with no nested lists returns itself as a flat list.\n\n**Example:**\n\n```python\nnested = [1, [2, [3, [4, 5]], 6], 7]\nprint(flatten(nested)) # [1, 2, 3, 4, 5, 6, 7]\n```\n\n**Generator alternative** (memory-efficient for large inputs):\n\n```python\ndef flatten(lst):\n \"\"\"Yield elements from an arbitrarily nested list.\"\"\"\n for item in lst:\n if isinstance(item, list):\n yield from flatten(item)\n else:\n yield item\n```\n\nCall with `list(flatten(nested))` to get a list."
}
},
{
"key": "code4:greedy",
"id": "code4",
"cfg": "greedy",
"base": {
"tokens": 201,
"secs": 22.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\nimport re\n\ndef to_snake_case(s: str) -> str:\n \"\"\"\n Convert a CamelCase identifier to snake_case.\n \n Args:\n s: A string in CamelCase format.\n \n Returns:\n A string in snake_case format.\n \"\"\"\n if not s:\n return s\n \n # Insert an underscore before any uppercase letter that is followed by a lowercase letter\n # and is not at the beginning of the string\n s = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)\n # Insert an underscore before any uppercase letter that is preceded by a lowercase letter or digit\n s = re.sub(r'([a-z0-9])([A-Z])', r'\\1_\\2', s)\n # Convert to lowercase\n s = s.lower()\n \n return s\n```"
},
"honey": {
"tokens": 290,
"secs": 53.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\nimport re\n\ndef to_snake_case(s):\n # Insert underscore before a capital letter that follows a lowercase letter or digit\n s = re.sub(r'([a-z0-9])([A-Z])', r'\\1_\\2', s)\n # Insert underscore before a capital letter that is followed by a lowercase letter (handles acronyms like HTTPResponse)\n s = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)\n return s.lower()\n```\n\n**How it works:**\n\n1. **First regex** `([a-z0-9])([A-Z])` \u2014 catches the boundary between a lowercase/digit and an uppercase letter (e.g., `camelCase` \u2192 `camel_Case`).\n2. **Second regex** `([A-Z]+)([A-Z][a-z])` \u2014 catches acronym boundaries (e.g., `HTTPResponse` \u2192 `HTTP_Response`).\n3. `.lower()` converts everything to lowercase.\n\n**Examples:**\n\n```python\nprint(to_snake_case(\"camelCase\")) # camel_case\nprint(to_snake_case(\"HTTPResponse\")) # http_response\nprint(to_snake_case(\"getHTTPResponse\")) # get_http_response\nprint(to_snake_case(\"already_snake\")) # already_snake\n```"
}
},
{
"key": "code4:t1_s1",
"id": "code4",
"cfg": "t1_s1",
"base": {
"tokens": 356,
"secs": 40.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef to_snake_case(s: str) -> str:\n \"\"\"\n Convert a CamelCase identifier to snake_case.\n \n Examples:\n 'CamelCase' -> 'camel_case'\n 'HTMLParser' -> 'html_parser'\n 'getHTTPResponse' -> 'get_http_response'\n 'simple' -> 'simple'\n \"\"\"\n if not s:\n return s\n \n # Insert underscore before each uppercase letter that is preceded by a lowercase letter or digit\n # Also handle sequences of uppercase letters (e.g., 'HTMLParser' -> 'HTML_Parser')\n import re\n \n # Step 1: Handle boundaries between sequences of uppercase letters and the following uppercase+lowercase\n # e.g., 'HTMLParser' -> 'HTML_Parser'\n s = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)\n \n # Step 2: Insert underscore before uppercase letters that follow lowercase letters or digits\n # e.g., 'camelCase' -> 'camel_Case', 'getHTTPResponse' -> 'get_HTTP_Response' (after step 1)\n s = re.sub(r'([a-z\\d])([A-Z])', r'\\1_\\2', s)\n \n # Step 3: Convert to lowercase and replace any remaining spaces or hyphens with underscores\n s = s.lower()\n s = re.sub(r'[\\s-]+', '_', s)\n \n # Step 4: Remove any leading/trailing underscores\n s = s.strip('_')\n \n return s\n```"
},
"honey": {
"tokens": 247,
"secs": 45.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "## `to_snake_case`\n\n```python\nimport re\n\ndef to_snake_case(s: str) -> str:\n \"\"\"Convert a CamelCase identifier to snake_case.\"\"\"\n s = re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower()\n return s\n```\n\n**How it works:**\n- `re.sub(r'(?<!^)(?=[A-Z])', '_', s)` inserts an `_` before each uppercase letter \u2014 except when it's at the start of the string (handled by `(?<!^)`) and before it (handled by the lookaround `(?=[A-Z])`).\n- `.lower()` lowercases the whole result.\n\n**Examples:**\n```python\n>>> to_snake_case(\"HelloWorld\")\n\"hello_world\"\n\n>>> to_snake_case(\"HTTPResponseCode\")\n\"http_response_code\"\n\n>>> to_snake_case(\"simpleExample\")\n\"simple_example\"\n```\n\nNote: `HTTPResponseCode` becomes `http_response_code` \u2014 acronyms followed by a capitalized word are split correctly. A fully acronym-prefixed case like `HTMLParser` yields `html_parser`."
}
},
{
"key": "code4:t1_s2",
"id": "code4",
"cfg": "t1_s2",
"base": {
"tokens": 389,
"secs": 43.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\nimport re\n\ndef to_snake_case(s: str) -> str:\n \"\"\"Convert a CamelCase identifier to snake_case.\n \n Handles cases like:\n - SimpleCamelCase -> simple_camel_case\n - ACMECorp -> acme_corp (initialisms followed by word)\n - HTTPResponse -> http_response\n - Already_snake -> already_snake (pass through or normalize)\n - NoChange -> no_change\n \"\"\"\n if not s:\n return s\n \n # If string is already all lowercase with underscores, return as is\n if s == s.lower():\n return s\n \n # Step 1: Insert an underscore before a capital letter that is followed by lowercase letters\n # This handles transitions like \"Camel\" -> \"Camel\", but we want to catch boundaries\n # Better approach: use regex to handle common CamelCase patterns\n \n # First, handle cases where an uppercase letter is followed by lowercase, and preceded by lowercase or digit\n # E.g., \"simpleCamel\" -> \"simple_Camel\"\n s = re.sub(r'([a-z0-9])([A-Z])', r'\\1_\\2', s)\n \n # Then, handle cases where a sequence of uppercase letters is followed by a lowercase letter\n # E.g., \"HTTPResponse\" -> \"HTTP_Response\"\n s = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)\n \n # Convert to lowercase\n s = s.lower()\n \n # Remove any leading or trailing underscores\n s = s.strip('_')\n \n # Replace any multiple underscores with single underscore\n s = re.sub(r'_+', '_', s)\n \n return s\n```"
},
"honey": {
"tokens": 325,
"secs": 58.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\nimport re\n\ndef to_snake_case(s):\n # Insert an underscore before any uppercase letter that follows a lowercase letter or digit\n # and handle acronym boundaries (e.g., HTTPResponse -> http_response)\n s = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)\n s = re.sub(r'([a-z0-9])([A-Z])', r'\\1_\\2', s)\n return s.lower()\n```\n\n**How it works:**\n- `re.sub(r'([A-Z]+)([A-Z][a-z])', r'\\1_\\2', s)` \u2014 inserts an underscore between a run of uppercase letters and an acronym followed by a lowercase word (e.g., `HTTPResponse` \u2192 `HTTP_Response`).\n- `re.sub(r'([a-z0-9])([A-Z])', r'\\1_\\2', s)` \u2014 inserts an underscore at a lowercase/digit-to-uppercase boundary (e.g., `myVar` \u2192 `my_Var`).\n- `.lower()` converts everything to lowercase.\n\n**Examples:**\n```python\nprint(to_snake_case(\"myVariableName\")) # my_variable_name\nprint(to_snake_case(\"HTTPResponse\")) # http_response\nprint(to_snake_case(\"getHTTPResponse\")) # get_http_response\nprint(to_snake_case(\"already_snake_case\")) # already_snake_case\nprint(to_snake_case(\"simple\")) # simple\n```"
}
},
{
"key": "code5:greedy",
"id": "code5",
"cfg": "greedy",
"base": {
"tokens": 130,
"secs": 14.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef balanced(s: str) -> bool:\n \"\"\"\n Returns True if the brackets ()[]{} in s are balanced and properly nested.\n \"\"\"\n stack = []\n matching = {')': '(', ']': '[', '}': '{'}\n opening = set('([{')\n \n for char in s:\n if char in opening:\n stack.append(char)\n elif char in matching:\n if not stack or stack[-1] != matching[char]:\n return False\n stack.pop()\n \n return len(stack) == 0\n```"
},
"honey": {
"tokens": 189,
"secs": 34.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef balanced(s):\n stack = []\n pairs = {')': '(', ']': '[', '}': '{'}\n for ch in s:\n if ch in '([{':\n stack.append(ch)\n elif ch in ')]}':\n if not stack or stack[-1] != pairs[ch]:\n return False\n stack.pop()\n return not stack\n```\n\n**How it works:**\n- Push opening brackets onto the stack.\n- For each closing bracket, check that the stack top is the matching opener; if not, return `False`.\n- At the end, the stack must be empty (no unmatched openers).\n\n**Examples:**\n```python\nbalanced(\"{[()]}\") # True\nbalanced(\"{[(])}\") # False\nbalanced(\"((())\") # False\nbalanced(\"\") # True\n```"
}
},
{
"key": "code5:t1_s1",
"id": "code5",
"cfg": "t1_s1",
"base": {
"tokens": 109,
"secs": 16.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef balanced(s):\n stack = []\n matching = {')': '(', ']': '[', '}': '{'}\n opening = set('([{')\n closing = set(')]}')\n \n for char in s:\n if char in opening:\n stack.append(char)\n elif char in closing:\n if not stack or stack[-1] != matching[char]:\n return False\n stack.pop()\n \n return len(stack) == 0\n```"
},
"honey": {
"tokens": 248,
"secs": 57.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "## Balanced Brackets Checker\n\n```python\ndef balanced(s):\n stack = []\n pairs = {')': '(', ']': '[', '}': '{'}\n \n for ch in s:\n if ch in pairs.values():\n stack.append(ch)\n elif ch in pairs:\n if not stack or stack.pop() != pairs[ch]:\n return False\n \n return not stack\n```\n\n### How it works\n\n- **Opening brackets** `(`, `[`, `{` are pushed onto the stack.\n- **Closing brackets** `)`, `]`, `}` trigger a pop \u2014 if the stack is empty or the popped opening bracket doesn't match, the string is unbalanced \u2192 `False`.\n- At the end, an empty stack means every opener was closed \u2192 `True`; leftover openers \u2192 `False`.\n\n### Test\n\n```python\nprint(balanced(\"{[()]}\")) # True\nprint(balanced(\"{[(])}\")) # False\nprint(balanced(\"()[]{}\")) # True\nprint(balanced(\"((())\") # False\nprint(balanced(\"\"))) # True\n```"
}
},
{
"key": "code5:t1_s2",
"id": "code5",
"cfg": "t1_s2",
"base": {
"tokens": 111,
"secs": 12.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef balanced(s: str) -> bool:\n stack = []\n matching = {')': '(', ']': '[', '}': '{'}\n opening = set('([{')\n \n for char in s:\n if char in opening:\n stack.append(char)\n elif char in matching:\n if not stack or stack[-1] != matching[char]:\n return False\n stack.pop()\n # Ignore other characters\n \n return len(stack) == 0\n```"
},
"honey": {
"tokens": 137,
"secs": 25.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef balanced(s):\n stack = []\n pairs = {')': '(', ']': '[', '}': '{'}\n for ch in s:\n if ch in '([{':\n stack.append(ch)\n elif ch in ')]}':\n if not stack or stack[-1] != pairs[ch]:\n return False\n stack.pop()\n return not stack\n```\n\nThe function uses a stack to track opening brackets. For each closing bracket, it checks that the most recent unmatched opening bracket is the matching type. If the stack is empty at the end, all brackets were properly paired and nested."
}
},
{
"key": "code6:greedy",
"id": "code6",
"cfg": "greedy",
"base": {
"tokens": 155,
"secs": 17.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s: str) -> str:\n \"\"\"Run-length encode a string.\n \n Example: 'aaabcc' -> 'a3b1c2'\n \"\"\"\n if not s:\n return \"\"\n \n result = []\n current_char = s[0]\n count = 1\n \n for char in s[1:]:\n if char == current_char:\n count += 1\n else:\n result.append(f\"{current_char}{count}\")\n current_char = char\n count = 1\n \n # Append the last group\n result.append(f\"{current_char}{count}\")\n \n return \"\".join(result)\n```"
},
"honey": {
"tokens": 210,
"secs": 38.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s):\n if not s:\n return ''\n result = []\n count = 1\n for i in range(1, len(s) + 1):\n if i < len(s) and s[i] == s[i - 1]:\n count += 1\n else:\n result.append(s[i - 1] + str(count))\n count = 1\n return ''.join(result)\n```\n\n**How it works:**\n\n- Iterate through the string, tracking the current character and its consecutive count.\n- When the character changes (or we reach the end), append the character and its count to the result.\n- Join all parts into a single string.\n\n**Example:**\n\n```python\n>>> rle('aaabcc')\n'a3b1c2'\n>>> rle('')\n''\n>>> rle('aabbbcccc')\n'a2b3c4'\n```"
}
},
{
"key": "code6:t1_s1",
"id": "code6",
"cfg": "t1_s1",
"base": {
"tokens": 176,
"secs": 22.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s: str) -> str:\n \"\"\"Run-length encode a string.\n \n Args:\n s: Input string to encode.\n \n Returns:\n Run-length encoded string, e.g., 'aaabcc' -> 'a3b1c2'.\n \"\"\"\n if not s:\n return \"\"\n \n result = []\n count = 1\n \n for i in range(1, len(s)):\n if s[i] == s[i - 1]:\n count += 1\n else:\n result.append(s[i - 1] + str(count))\n count = 1\n \n # Append the last character group\n result.append(s[-1] + str(count))\n \n return \"\".join(result)\n```"
},
"honey": {
"tokens": 269,
"secs": 49.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s: str) -> str:\n if not s:\n return ''\n result = []\n count = 1\n for i in range(1, len(s)):\n if s[i] == s[i - 1]:\n count += 1\n else:\n result.append(f'{s[i - 1]}{count}')\n count = 1\n result.append(f'{s[-1]}{count}')\n return ''.join(result)\n```\n\n**How it works:**\n- Iterates through the string, tracking the current character and its consecutive count.\n- When the character changes, appends the previous character + count to the result.\n- After the loop, appends the final character + count (the last group isn't flushed inside the loop).\n- Joins all fragments into a single string.\n\n**Examples:**\n```python\nprint(rle('aaabcc')) # a3b1c2\nprint(rle('')) #\nprint(rle('a')) # a1\nprint(rle('aaaaaaa')) # a7\nprint(rle('ababab')) # a1b1a1b1a1b1\n```"
}
},
{
"key": "code6:t1_s2",
"id": "code6",
"cfg": "t1_s2",
"base": {
"tokens": 130,
"secs": 14.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s: str) -> str:\n if not s:\n return \"\"\n \n result = []\n current_char = s[0]\n count = 1\n \n for i in range(1, len(s)):\n if s[i] == current_char:\n count += 1\n else:\n result.append(f\"{current_char}{count}\")\n current_char = s[i]\n count = 1\n \n # Append the last group\n result.append(f\"{current_char}{count}\")\n \n return \"\".join(result)\n```"
},
"honey": {
"tokens": 160,
"secs": 29.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef rle(s):\n if not s:\n return ''\n result = []\n prev = s[0]\n count = 1\n for ch in s[1:]:\n if ch == prev:\n count += 1\n else:\n result.append(f'{prev}{count}')\n prev = ch\n count = 1\n result.append(f'{prev}{count}')\n return ''.join(result)\n```\n\nTrace through `'aaabcc'`: `a`\u00d73 \u2192 `a3`, `b`\u00d71 \u2192 `b1`, `c`\u00d72 \u2192 `c2` \u2192 `'a3b1c2'`. Empty input returns `''`."
}
},
{
"key": "code7:greedy",
"id": "code7",
"cfg": "greedy",
"base": {
"tokens": 274,
"secs": 30.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef merge_intervals(iv):\n \"\"\"\n Merges overlapping intervals given as a list of [start, end] pairs\n and returns them sorted.\n \n Args:\n iv: A list of intervals, where each interval is a list [start, end].\n \n Returns:\n A list of merged, non-overlapping intervals sorted by start time.\n \"\"\"\n if not iv:\n return []\n \n # Sort intervals by start time\n sorted_iv = sorted(iv, key=lambda x: x[0])\n \n # Initialize with the first interval\n merged = [sorted_iv[0][:]] # Make a copy\n \n for i in range(1, len(sorted_iv)):\n current_start, current_end = sorted_iv[i]\n last_start, last_end = merged[-1]\n \n # Check if the current interval overlaps with the last merged interval\n if current_start <= last_end:\n # Merge: update the end of the last interval if needed\n merged[-1][1] = max(last_end, current_end)\n else:\n # No overlap, add the current interval as a new merged interval\n merged.append([current_start, current_end])\n \n return merged\n```"
},
"honey": {
"tokens": 125,
"secs": 23.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef merge_intervals(iv):\n if not iv:\n return []\n iv.sort(key=lambda x: x[0])\n merged = [iv[0]]\n for start, end in iv[1:]:\n if start <= merged[-1][1]:\n merged[-1][1] = max(merged[-1][1], end)\n else:\n merged.append([start, end])\n return merged\n```\n\nSorts by start time, then walks through merging any interval whose start falls within the previous merged interval's end."
}
},
{
"key": "code7:t1_s1",
"id": "code7",
"cfg": "t1_s1",
"base": {
"tokens": 236,
"secs": 26.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef merge_intervals(iv: list[list[int]]) -> list[list[int]]:\n \"\"\"\n Merges overlapping intervals and returns them sorted.\n \n Args:\n iv: A list of [start, end] pairs representing intervals.\n \n Returns:\n A list of merged, non-overlapping intervals, sorted by start time.\n \"\"\"\n if not iv:\n return []\n \n # Sort intervals by start time\n sorted_iv = sorted(iv, key=lambda x: x[0])\n \n merged = [sorted_iv[0]]\n \n for current in sorted_iv[1:]:\n last = merged[-1]\n # Check if current interval overlaps with the last merged interval\n if current[0] <= last[1]:\n # Merge: update the end of the last interval to the max of both ends\n last[1] = max(last[1], current[1])\n else:\n # No overlap: add the current interval as a new interval\n merged.append(current)\n \n return merged\n```"
},
"honey": {
"tokens": 623,
"secs": 113.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "## Merge Overlapping Intervals\n\n```python\ndef merge_intervals(iv):\n \"\"\"\n Merge overlapping intervals and return them sorted.\n\n Args:\n iv: list of [start, end] pairs, e.g. [[1,3], [2,6], [8,10]]\n\n Returns:\n list of merged intervals sorted by start value.\n\n Examples:\n >>> merge_intervals([[1,3],[2,6],[8,10],[15,18]])\n [[1,6],[8,10],[15,18]]\n\n >>> merge_intervals([[1,4],[4,5]])\n [[1,5]]\n\n >>> merge_intervals([])\n []\n \"\"\"\n if not iv:\n return []\n\n # 1. Sort intervals by start value\n iv_sorted = sorted(iv, key=lambda x: x[0])\n\n # 2. Initialize result with the first interval\n merged = [iv_sorted[0][:]] # copy to avoid mutating input\n\n # 3. Iterate through the rest, merging when overlapping\n for start, end in iv_sorted[1:]:\n last_start, last_end = merged[-1]\n if start <= last_end:\n # Overlapping \u2192 extend the end of the last merged interval\n merged[-1][1] = max(last_end, end)\n else:\n # No overlap \u2192 append as a new interval\n merged.append([start, end])\n\n return merged\n```\n\n### How It Works\n\n1. **Sort** the intervals by their start value so overlapping intervals are adjacent.\n2. **Iterate** through each interval, comparing it with the last one added to `merged`.\n3. If the current interval's start is \u2264 the last merged interval's end, they overlap \u2014 extend the end via `max(last_end, end)`. The `max` handles containment (e.g. `[1,10]` and `[2,3]`).\n4. Otherwise, append as a new interval.\n\n### Edge Cases Handled\n\n| Input | Output | Why |\n|---|---|---|\n| `[]` | `[]` | Early return |\n| `[[1,10],[2,3]]` | `[[1,10]]` | `max` preserves larger end |\n| `[[1,4],[4,5]]` | `[[1,5]]` | Touching boundaries merged |\n| `[[8,10],[1,3],[2,6]]` | `[[1,6],[8,10]]` | Unsorted input handled by `sorted` |\n\n### Complexity\n\n- **Time:** `O(n log n)` \u2014 dominated by the sort.\n- **Space:** `O(n)` \u2014 for the `merged` list (and the sorted copy)."
}
},
{
"key": "code7:t1_s2",
"id": "code7",
"cfg": "t1_s2",
"base": {
"tokens": 220,
"secs": 25.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef merge_intervals(iv):\n \"\"\"\n Merges overlapping intervals and returns them sorted.\n \n Args:\n iv: A list of [start, end] pairs representing intervals.\n \n Returns:\n A list of merged non-overlapping intervals, sorted by start time.\n \"\"\"\n if not iv:\n return []\n \n # Sort intervals by start time\n intervals = sorted(iv, key=lambda x: x[0])\n \n merged = [intervals[0]]\n \n for current in intervals[1:]:\n last = merged[-1]\n # If current interval overlaps with the last merged interval\n if current[0] <= last[1]:\n # Merge: update the end of the last interval to the max of both ends\n last[1] = max(last[1], current[1])\n else:\n # No overlap, add current interval to merged list\n merged.append(current)\n \n return merged\n```"
},
"honey": {
"tokens": 107,
"secs": 20.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef merge_intervals(iv):\n if not iv:\n return []\n iv.sort(key=lambda x: x[0])\n merged = [iv[0]]\n for current in iv[1:]:\n last = merged[-1]\n if current[0] <= last[1]:\n merged[-1] = [last[0], max(last[1], current[1])]\n else:\n merged.append(current)\n return merged\n```"
}
},
{
"key": "code8:greedy",
"id": "code8",
"cfg": "greedy",
"base": {
"tokens": 97,
"secs": 11.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n if n == 0:\n return 0\n if n == 1:\n return 1\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, a + b\n return b\n```"
},
"honey": {
"tokens": 102,
"secs": 19.4,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n a, b = 0, 1\n for _ in range(n):\n a, b = b, a + b\n return a\n```\n\nIterative, O(n) time, O(1) space. `nth_fib(0)` returns `0`, `nth_fib(1)` returns `1`."
}
},
{
"key": "code8:t1_s1",
"id": "code8",
"cfg": "t1_s1",
"base": {
"tokens": 99,
"secs": 11.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be a non-negative integer\")\n if n == 0:\n return 0\n if n == 1:\n return 1\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, a + b\n return b\n```"
},
"honey": {
"tokens": 130,
"secs": 26.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n a, b = 0, 1\n for _ in range(n):\n a, b = b, a + b\n return a\n```\n\nThis iteratively advances the pair `(a, b)` through the Fibonacci sequence `n` times. After `n` iterations, `a` holds `F(n)`. Handles the base cases `nth_fib(0) == 0` and `nth_fib(1) == 1` naturally."
}
},
{
"key": "code8:t1_s2",
"id": "code8",
"cfg": "t1_s2",
"base": {
"tokens": 97,
"secs": 11.4,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n if n == 0:\n return 0\n if n == 1:\n return 1\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, a + b\n return b\n```"
},
"honey": {
"tokens": 125,
"secs": 23.4,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef nth_fib(n):\n if n < 0:\n raise ValueError(\"n must be non-negative\")\n a, b = 0, 1\n for _ in range(n):\n a, b = b, a + b\n return a\n```\n\nTrace: `nth_fib(0)` \u2192 loop doesn't run \u2192 returns `a=0`. `nth_fib(1)` \u2192 one iteration: `a=1, b=1` \u2192 returns `1`. `nth_fib(6)` \u2192 returns `8`. \u2713"
}
},
{
"key": "code9:greedy",
"id": "code9",
"cfg": "greedy",
"base": {
"tokens": 95,
"secs": 11.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef reverse_words(s: str) -> str:\n \"\"\"\n Reverses the order of words in a string.\n \n Args:\n s: Input string with words separated by spaces.\n \n Returns:\n A string with the words in reversed order.\n \"\"\"\n if not s:\n return s\n words = s.split()\n return ' '.join(reversed(words))\n```"
},
"honey": {
"tokens": 112,
"secs": 21.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef reverse_words(s):\n return ' '.join(s.split()[::-1])\n```\n\n**How it works:**\n- `s.split()` splits the string into a list of words (handles multiple spaces).\n- `[::-1]` reverses the list.\n- `' '.join(...)` joins them back with single spaces.\n\n**Example:**\n```python\n>>> reverse_words(\"Hello world\")\n'world Hello'\n>>> reverse_words(\" multiple spaces \")\n'spaces multiple'\n```"
}
},
{
"key": "code9:t1_s1",
"id": "code9",
"cfg": "t1_s1",
"base": {
"tokens": 136,
"secs": 16.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef reverse_words(s: str) -> str:\n \"\"\"\n Reverses the order of words in a string.\n \n Words are defined as sequences of non-space characters separated by single or multiple spaces.\n Leading and trailing spaces are removed, and the result has single spaces between words.\n \n Args:\n s: Input string containing words separated by spaces.\n \n Returns:\n A string with the order of words reversed.\n \"\"\"\n if not s or not s.strip():\n return \"\"\n words = s.split()\n return \" \".join(reversed(words))\n```"
},
"honey": {
"tokens": 322,
"secs": 61.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": false,
"text": "```python\ndef reverse_words(s: str) -> str:\n \"\"\"Reverse the order of words in a string.\n\n Words are split on any whitespace, and the result is joined with\n single spaces. Empty strings return empty strings.\n\n >>> reverse_words(\"Hello world\")\n 'world Hello'\n >>> reverse_words(\"The quick brown fox\")\n 'fox brown quick The'\n >>> reverse_words(\"\")\n ''\n >>> reverse_words(\" multiple spaces \")\n 'spaces multiple'\n \"\"\"\n return \" \".join(s.split())[::-1]\n```\n\nWait \u2014 that's not right. Let me fix: the `[::-1]` reverses characters, not words.\n\n```python\ndef reverse_words(s: str) -> str:\n \"\"\"Reverse the order of words in a string.\n\n Words are split on any whitespace, and the result is joined with\n single spaces. Empty strings return empty strings.\n\n >>> reverse_words(\"Hello world\")\n 'world Hello'\n >>> reverse_words(\"The quick brown fox\")\n 'fox brown quick The'\n >>> reverse_words(\"\")\n ''\n >>> reverse_words(\" multiple spaces \")\n 'spaces multiple'\n \"\"\"\n return \" \".join(s.split()[::-1])\n```\n\n`s.split()` splits on any whitespace and drops empty strings. `[::-1]` reverses the list of words. `\" \".join(...)` joins them back with single spaces."
}
},
{
"key": "code9:t1_s2",
"id": "code9",
"cfg": "t1_s2",
"base": {
"tokens": 132,
"secs": 15.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef reverse_words(s: str) -> str:\n \"\"\"\n Reverses the order of words in a string.\n \n Args:\n s: Input string\n \n Returns:\n A string with the order of words reversed\n \n Example:\n >>> reverse_words(\"hello world\")\n 'world hello'\n >>> reverse_words(\"The quick brown fox\")\n 'fox brown quick The'\n \"\"\"\n if not s or not s.strip():\n return s\n \n words = s.split()\n words.reverse()\n return ' '.join(words)\n```"
},
"honey": {
"tokens": 161,
"secs": 30.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef reverse_words(s):\n return ' '.join(reversed(s.split()))\n```\n\n**How it works:**\n\n1. `s.split()` \u2014 splits the string into a list of words (default splits on any whitespace, handling multiple spaces between words).\n2. `reversed(...)` \u2014 returns an iterator over the list in reverse order.\n3. `' '.join(...)` \u2014 joins the reversed words back into a string separated by a single space.\n\n**Examples:**\n\n```python\n>>> reverse_words(\"Hello world\")\n'world Hello'\n>>> reverse_words(\"The quick brown fox\")\n'fox brown quick The'\n>>> reverse_words(\"\")\n''\n>>> reverse_words(\" multiple spaces \")\n'spaces multiple'\n```"
}
},
{
"key": "code10:greedy",
"id": "code10",
"cfg": "greedy",
"base": {
"tokens": 67,
"secs": 9.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n \"\"\"Count the number of vowels (a, e, i, o, u) in a string, case-insensitive.\"\"\"\n vowels = set('aeiouAEIOU')\n return sum(1 for char in s if char in vowels)\n```"
},
"honey": {
"tokens": 140,
"secs": 27.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n return sum(1 for c in s.lower() if c in 'aeiou')\n```\n\n**How it works:**\n- `s.lower()` \u2014 normalizes the string to lowercase so the check is case-insensitive.\n- `c in 'aeiou'` \u2014 tests each character against the set of vowels.\n- `sum(1 for ...)` \u2014 counts how many characters pass the test.\n\n**Example:**\n```python\n>>> count_vowels(\"Hello World\")\n3\n>>> count_vowels(\"AEIOU\")\n5\n>>> count_vowels(\"\")\n0\n```"
}
},
{
"key": "code10:t1_s1",
"id": "code10",
"cfg": "t1_s1",
"base": {
"tokens": 67,
"secs": 8.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n \"\"\"Count the number of vowels (a, e, i, o, u, case-insensitive) in a string.\"\"\"\n vowels = set('aeiouAEIOU')\n return sum(1 for char in s if char in vowels)\n```"
},
"honey": {
"tokens": 32,
"secs": 6.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n return sum(1 for c in s.lower() if c in 'aeiou')\n```"
}
},
{
"key": "code10:t1_s2",
"id": "code10",
"cfg": "t1_s2",
"base": {
"tokens": 67,
"secs": 7.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n \"\"\"Count the number of vowels (a, e, i, o, u) in a string, case-insensitive.\"\"\"\n vowels = set('aeiouAEIOU')\n return sum(1 for char in s if char in vowels)\n```"
},
"honey": {
"tokens": 122,
"secs": 23.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef count_vowels(s):\n \"\"\"Count the number of vowels (a, e, i, o, u) in a string, case-insensitive.\"\"\"\n return sum(1 for c in s if c.lower() in 'aeiou')\n```\n\nExample:\n```python\nprint(count_vowels(\"Hello, World!\")) # 3\nprint(count_vowels(\"AEIOU\")) # 5\nprint(count_vowels(\"xyz\")) # 0\nprint(count_vowels(\"\")) # 0\n```"
}
},
{
"key": "code11:greedy",
"id": "code11",
"cfg": "greedy",
"base": {
"tokens": 156,
"secs": 18.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n \"\"\"\n Perform binary search on a sorted list.\n \n Args:\n arr: A sorted list of elements.\n target: The element to search for.\n \n Returns:\n The index of target in arr if found, otherwise -1.\n \"\"\"\n left = 0\n right = len(arr) - 1\n \n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n \n return -1\n```"
},
"honey": {
"tokens": 172,
"secs": 33.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1\n```\n\n**How it works:**\n- Maintains a search window `[left, right]`.\n- Each iteration computes `mid`, compares `arr[mid]` to `target`, and discards half the window.\n- Returns `mid` on a match; returns `-1` when the window is exhausted.\n- Time: O(log n). Space: O(1)."
}
},
{
"key": "code11:t1_s1",
"id": "code11",
"cfg": "t1_s1",
"base": {
"tokens": 160,
"secs": 20.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n \"\"\"\n Perform binary search on a sorted list to find the target.\n \n Args:\n arr: A sorted list of elements.\n target: The element to search for.\n \n Returns:\n The index of target in arr, or -1 if not found.\n \"\"\"\n left, right = 0, len(arr) - 1\n \n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n \n return -1\n```"
},
"honey": {
"tokens": 240,
"secs": 48.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1\n```\n\n**How it works:** The list is kept as two pointers \u2014 `left` starts at index 0, `right` at the last index. Each iteration computes `mid`, compares `arr[mid]` to `target`, and discards the half that can't contain `target`. If `target` is never found, the loop exits and returns `-1`.\n\n**Example:**\n```python\narr = [1, 3, 5, 7, 9]\nprint(binary_search(arr, 7)) # \u2192 3\nprint(binary_search(arr, 4)) # \u2192 -1\n```\n\nTime complexity: **O(log n)**. Space: **O(1)**."
}
},
{
"key": "code11:t1_s2",
"id": "code11",
"cfg": "t1_s2",
"base": {
"tokens": 95,
"secs": 14.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n left = 0\n right = len(arr) - 1\n \n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n \n return -1\n```"
},
"honey": {
"tokens": 165,
"secs": 37.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1\n```\n\nStandard iterative binary search. `left` and `right` track the shrinking search window; `mid` is the pivot checked each iteration. If the value is too small, advance `left`; too large, retreat `right`. Return `-1` when the window collapses without a match. O(log n) time, O(1) space."
}
},
{
"key": "code12:greedy",
"id": "code12",
"cfg": "greedy",
"base": {
"tokens": 53,
"secs": 6.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 186,
"secs": 36.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```\n\n**How it works:**\n- `seen` tracks elements already encountered.\n- For each item, if it's not in `seen`, add it to both `seen` and `result`.\n- Returns a new list with duplicates removed, original order preserved.\n\n**Example:**\n```python\n>>> dedupe([3, 1, 2, 1, 3, 4])\n[3, 1, 2, 4]\n```\n\n**Note:** Elements must be hashable. For unhashable items (e.g., lists), use a different approach like checking membership in the result list directly."
}
},
{
"key": "code12:t1_s1",
"id": "code12",
"cfg": "t1_s1",
"base": {
"tokens": 67,
"secs": 8.4,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n \"\"\"Remove duplicates from a list while preserving the original order.\"\"\"\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 93,
"secs": 18.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```\n\nThis iterates through the list once, tracking seen items in a set for O(1) lookup and appending each unique item to the result in its original order. Time complexity: O(n)."
}
},
{
"key": "code12:t1_s2",
"id": "code12",
"cfg": "t1_s2",
"base": {
"tokens": 105,
"secs": 12.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n \"\"\"\n Remove duplicates from a list while preserving the original order.\n \n Args:\n lst: A list of elements.\n \n Returns:\n A new list with duplicates removed, preserving the original order.\n \"\"\"\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```"
},
"honey": {
"tokens": 167,
"secs": 32.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef dedupe(lst):\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```\n\n**How it works:**\n- Iterates through the list, tracking seen items in a `set` (O(1) lookups).\n- Appends each item to `result` only on first occurrence.\n- Returns the deduplicated list with original order preserved.\n\n**Example:**\n```python\n>>> dedupe([3, 1, 2, 3, 4, 1])\n[3, 1, 2, 4]\n```\n\nTime complexity: O(n). Space complexity: O(n)."
}
},
{
"key": "code13:greedy",
"id": "code13",
"cfg": "greedy",
"base": {
"tokens": 171,
"secs": 20.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s, k):\n \"\"\"\n Shift each letter in s by k positions (wrapping around), preserving case\n and leaving other characters unchanged.\n \n Args:\n s: The input string.\n k: The number of positions to shift each letter.\n \n Returns:\n The encrypted string.\n \"\"\"\n result = []\n for char in s:\n if char.isalpha():\n if char.isupper():\n base = ord('A')\n else:\n base = ord('a')\n shifted = (ord(char) - base + k) % 26 + base\n result.append(chr(shifted))\n else:\n result.append(char)\n return ''.join(result)\n```"
},
"honey": {
"tokens": 221,
"secs": 43.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s, k):\n result = []\n for c in s:\n if c.isalpha():\n base = ord('A') if c.isupper() else ord('a')\n result.append(chr((ord(c) - base + k) % 26 + base))\n else:\n result.append(c)\n return ''.join(result)\n```\n\n**How it works:**\n\n- For each character, check if it's a letter.\n- Determine the base (`'A'` for uppercase, `'a'` for lowercase).\n- Shift the letter by `k` positions using modular arithmetic (`% 26`) to wrap around.\n- Non-letter characters are appended unchanged.\n\n**Example:**\n\n```python\nprint(caesar(\"Hello, World!\", 3)) # \"Khoor, Zruog!\"\nprint(caesar(\"xyz\", 3)) # \"abc\"\nprint(caesar(\"ABC\", -3)) # \"ZYZ\"\n```"
}
},
{
"key": "code13:t1_s1",
"id": "code13",
"cfg": "t1_s1",
"base": {
"tokens": 130,
"secs": 17.1,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s: str, k: int) -> str:\n \"\"\"Shift each letter in s by k positions, preserving case and leaving other characters unchanged.\"\"\"\n result = []\n for char in s:\n if char.isalpha():\n if char.isupper():\n base = ord('A')\n else:\n base = ord('a')\n shifted = (ord(char) - base + k) % 26 + base\n result.append(chr(shifted))\n else:\n result.append(char)\n return ''.join(result)\n```"
},
"honey": {
"tokens": 236,
"secs": 46.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s, k):\n result = []\n for c in s:\n if c.isalpha():\n base = ord('A') if c.isupper() else ord('a')\n result.append(chr((ord(c) - base + k) % 26 + base))\n else:\n result.append(c)\n return ''.join(result)\n```\n\nThis works by iterating over each character. For letters, it finds the offset from the base (`'A'` or `'a'`), adds `k`, applies modulo 26 to wrap around, then converts back to a character. Non-alpha characters are appended unchanged. Negative `k` values work correctly in Python since `%` returns a non-negative result when the divisor is positive.\n\n**Examples:**\n```python\n>>> caesar(\"Hello, World!\", 3)\n'Khoor, Zruog!'\n>>> caesar(\"abc\", -2)\n'xyz'\n>>> caesar(\"Python3.11\", 5)\n'Udynts3.11'\n```"
}
},
{
"key": "code13:t1_s2",
"id": "code13",
"cfg": "t1_s2",
"base": {
"tokens": 109,
"secs": 13.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s: str, k: int) -> str:\n result = []\n for char in s:\n if char.isalpha():\n if char.isupper():\n base = ord('A')\n else:\n base = ord('a')\n shifted = (ord(char) - base + k) % 26\n result.append(chr(base + shifted))\n else:\n result.append(char)\n return ''.join(result)\n```"
},
"honey": {
"tokens": 268,
"secs": 51.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef caesar(s, k):\n result = []\n for c in s:\n if c.isalpha():\n base = ord('A') if c.isupper() else ord('a')\n result.append(chr((ord(c) - base + k) % 26 + base))\n else:\n result.append(c)\n return ''.join(result)\n```\n\n**How it works:**\n\n- For each alphabetic character, determine the base (`'A'` for uppercase, `'a'` for lowercase).\n- Shift the character by `k` positions using modular arithmetic: `(ord(c) - base + k) % 26 + base`.\n- The `% 26` handles wrapping around (and works correctly for negative `k` in Python, since Python's modulo returns a non-negative result for a positive modulus).\n- Non-alpha characters are appended unchanged.\n\n**Examples:**\n\n```python\n>>> caesar(\"Hello, World!\", 3)\n'Khoor, Zruog!'\n>>> caesar(\"abc\", 3)\n'def'\n>>> caesar(\"xyz\", 3)\n'abc'\n>>> caesar(\"abc\", -3)\n'xyz'\n```"
}
},
{
"key": "code14:greedy",
"id": "code14",
"cfg": "greedy",
"base": {
"tokens": 132,
"secs": 15.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef two_sum(nums, target):\n \"\"\"\n Returns the indices of the two numbers in nums that add up to target.\n \n Args:\n nums: List of integers\n target: Integer target sum\n \n Returns:\n List of two indices [i, j] such that nums[i] + nums[j] == target\n \"\"\"\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []\n```"
},
"honey": {
"tokens": 211,
"secs": 40.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef two_sum(nums, target):\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []\n```\n\n**How it works:**\n\n- Iterate through `nums` once, tracking each number and its index in the `seen` dictionary.\n- For each number, compute its `complement` (`target - num`).\n- If the complement was already seen, return the pair of indices.\n- Otherwise, store the current number and index.\n- If no pair is found, return an empty list.\n\n**Time complexity:** O(n) \u2014 single pass. \n**Space complexity:** O(n) \u2014 for the hash map.\n\n**Example:**\n```python\n>>> two_sum([2, 7, 11, 15], 9)\n[0, 1]\n```"
}
},
{
"key": "code14:t1_s1",
"id": "code14",
"cfg": "t1_s1",
"base": {
"tokens": 139,
"secs": 16.8,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef two_sum(nums: list[int], target: int) -> list[int]:\n \"\"\"\n Returns the indices of the two numbers in nums that add up to target.\n \n Args:\n nums: A list of integers.\n target: The target sum.\n \n Returns:\n A list containing two indices of the numbers that add up to target.\n \"\"\"\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []\n```"
},
"honey": {
"tokens": 216,
"secs": 42.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "## `two_sum` function\n\n```python\ndef two_sum(nums, target):\n \"\"\"Return the indices of the two numbers in nums that add up to target.\n\n Uses a hash map for O(n) time complexity.\n \"\"\"\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return None # no solution found\n```\n\n**How it works:** For each number, compute its complement (`target - num`). If the complement is already in the map, return both indices. Otherwise, store the current number and its index.\n\n**Example:**\n```python\n>>> two_sum([2, 7, 11, 15], 9)\n[0, 1]\n```\n\n**Time complexity:** O(n) \u2014 single pass. **Space complexity:** O(n) \u2014 hash map stores at most n entries."
}
},
{
"key": "code14:t1_s2",
"id": "code14",
"cfg": "t1_s2",
"base": {
"tokens": 131,
"secs": 15.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef two_sum(nums, target):\n \"\"\"\n Returns the indices of the two numbers in nums that add up to target.\n \n Args:\n nums: List of integers\n target: Target sum\n \n Returns:\n List of two indices [i, j] such that nums[i] + nums[j] == target\n \"\"\"\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []\n```"
},
"honey": {
"tokens": 164,
"secs": 31.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef two_sum(nums, target):\n num_map = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in num_map:\n return [num_map[complement], i]\n num_map[num] = i\n return []\n```\n\n**How it works:**\n\n- Iterate through `nums` once, storing each number and its index in a hash map.\n- For each number, compute its *complement* (`target - num`) and check if it's already in the map.\n- If found, return the two indices. Otherwise, store the current number and index.\n- Runs in **O(n)** time and **O(n)** space \u2014 one pass, constant-time lookups."
}
},
{
"key": "code15:greedy",
"id": "code15",
"cfg": "greedy",
"base": {
"tokens": 106,
"secs": 12.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n):\n \"\"\"Return True if n is a prime number, False otherwise.\"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n**0.5) + 1, 2):\n if n % i == 0:\n return False\n return True\n```"
},
"honey": {
"tokens": 232,
"secs": 45.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n):\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n**0.5) + 1, 2):\n if n % i == 0:\n return False\n return True\n```\n\n**How it works:**\n\n- **n < 2** \u2192 not prime (0, 1, and negatives excluded).\n- **n == 2** \u2192 the only even prime, return `True`.\n- **n % 2 == 0** \u2192 any other even number is not prime.\n- **Loop from 3 to \u221an, step 2** \u2192 only check odd divisors. If any divides `n` evenly, it's not prime.\n- If no divisor found, `n` is prime.\n\nChecking up to \u221an is sufficient because if `n = a \u00d7 b`, one factor must be \u2264 \u221an."
}
},
{
"key": "code15:t1_s1",
"id": "code15",
"cfg": "t1_s1",
"base": {
"tokens": 109,
"secs": 13.3,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n: int) -> bool:\n \"\"\"Return True if n is a prime number, False otherwise.\"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n i = 3\n while i * i <= n:\n if n % i == 0:\n return False\n i += 2\n return True\n```"
},
"honey": {
"tokens": 149,
"secs": 29.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n if n % i == 0 or n % (i + 2) == 0:\n return False\n i += 6\n return True\n```\n\nThis checks divisibility up to \u221an using the 6k\u00b11 optimization \u2014 all primes > 3 are of that form, so we skip multiples of 2 and 3."
}
},
{
"key": "code15:t1_s2",
"id": "code15",
"cfg": "t1_s2",
"base": {
"tokens": 138,
"secs": 16.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \n A prime number is a natural number greater than 1 that has no positive \n divisors other than 1 and itself.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n i = 3\n while i * i <= n:\n if n % i == 0:\n return False\n i += 2\n return True\n```"
},
"honey": {
"tokens": 285,
"secs": 55.7,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n if n % i == 0 or n % (i + 2) == 0:\n return False\n i += 6\n return True\n```\n\n**How it works:**\n\n- **Handles edge cases first** \u2014 numbers \u2264 1 are not prime; 2 and 3 are.\n- **Eliminates even and divisible-by-3 numbers** early, so the loop only needs to check candidates of the form `6k \u00b1 1`.\n- **Loop checks up to \u221an** \u2014 if no divisor is found by then, `n` is prime. Starting at 5 and stepping by 6, we test `i` and `i + 2` (which covers `6k - 1` and `6k + 1`).\n\n```python\nprint(is_prime(7)) # True\nprint(is_prime(10)) # False\nprint(is_prime(2)) # True\nprint(is_prime(1)) # False\n```"
}
},
{
"key": "code16:greedy",
"id": "code16",
"cfg": "greedy",
"base": {
"tokens": 126,
"secs": 15.2,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n \"\"\"Split a list into consecutive chunks of size n.\n \n Args:\n lst: The list to split.\n n: The size of each chunk.\n \n Returns:\n A list of lists, where each inner list is a chunk of size n\n (the last chunk may be shorter).\n \"\"\"\n if n <= 0:\n raise ValueError(\"Chunk size n must be positive\")\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```"
},
"honey": {
"tokens": 75,
"secs": 14.6,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```\n\nSlices `lst[i:i+n]` for each step of `n` across the list. If `n` is 0, `range` yields nothing, so it returns `[]`."
}
},
{
"key": "code16:t1_s1",
"id": "code16",
"cfg": "t1_s1",
"base": {
"tokens": 130,
"secs": 15.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n \"\"\"Split a list into consecutive chunks of size n.\n \n Args:\n lst: The input list.\n n: The size of each chunk.\n \n Returns:\n A list of chunks, where each chunk is a list of at most n elements.\n The last chunk may be shorter than n.\n \"\"\"\n if n <= 0:\n raise ValueError(\"Chunk size n must be a positive integer\")\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```"
},
"honey": {
"tokens": 127,
"secs": 24.5,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```\n\nSlicing handles the last partial chunk automatically. `range(0, len(lst), n)` steps through start indices; each slice `lst[i:i+n]` grabs up to `n` elements, stopping short at the end if fewer remain.\n\n```python\n>>> chunk([1, 2, 3, 4, 5], 2)\n[[1, 2], [3, 4], [5]]\n```"
}
},
{
"key": "code16:t1_s2",
"id": "code16",
"cfg": "t1_s2",
"base": {
"tokens": 143,
"secs": 17.0,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n \"\"\"\n Split a list into consecutive chunks of size n.\n The last chunk may be shorter if the list length is not a multiple of n.\n \n Args:\n lst: The list to split.\n n: The size of each chunk.\n \n Returns:\n A list of lists, where each inner list is a chunk of size n (except possibly the last).\n \"\"\"\n if n <= 0:\n raise ValueError(\"Chunk size n must be positive\")\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```"
},
"honey": {
"tokens": 262,
"secs": 49.9,
"stop": "<|im_end|>",
"truncated": false,
"pass": true,
"text": "```python\ndef chunk(lst, n):\n return [lst[i:i + n] for i in range(0, len(lst), n)]\n```\n\nThis uses a list comprehension to slice `lst` in steps of `n`. `range(0, len(lst), n)` generates start indices `0, n, 2n, ...`, and each slice `lst[i:i+n]` grabs up to `n` elements \u2014 the last chunk will be shorter if `len(lst)` isn't divisible by `n`.\n\nExample:\n```python\n>>> chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)\n[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n\n>>> chunk([1, 2, 3, 4, 5], 3)\n[[1, 2, 3], [4, 5]]\n```\n\nEdge cases: empty list \u2192 `[]`, `n > len(lst)` \u2192 `[lst]`, `n <= 0` \u2192 raises `ValueError` (slice step can't be zero or negative in range)."
}
}
]
}