diff --git a/examples/ags/benchmark/humaneval.py b/examples/ags/benchmark/humaneval.py index 70c28cc5b..3cf4ff805 100644 --- a/examples/ags/benchmark/humaneval.py +++ b/examples/ags/benchmark/humaneval.py @@ -189,7 +189,7 @@ async def load_file_data(file_path: str) -> List[dict]: async def optimize_humaneval_evaluation(graph: Callable, file_path: str, path: str) -> Tuple[float, float]: data = await load_file_data(file_path) - results = await evaluate_all_problems(data, graph, max_concurrent_tasks=50) + results = await evaluate_all_problems(data, graph, max_concurrent_tasks=10) average_score, total_cost = save_results_to_jsonl(results, path=path) print(f"Average score on HumanEval dataset: {average_score:.5f}") print(f"Total Cost: {total_cost:.5f}") diff --git a/examples/ags/data/baselines/general/humaneval/humaneval_results_1727004938.jsonl b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727004938.jsonl new file mode 100644 index 000000000..6b4f555e5 --- /dev/null +++ b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727004938.jsonl @@ -0,0 +1 @@ +{"question": "\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", "prediction": "def can_arrange(arr):\n largest_index = -1\n for i in range(1, len(arr)):\n if arr[i] < arr[i - 1]:\n largest_index = i\n return largest_index", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.0009510199999999998} diff --git a/examples/ags/data/baselines/general/humaneval/humaneval_results_1727005529.jsonl b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727005529.jsonl new file mode 100644 index 000000000..e9a3baa73 --- /dev/null +++ b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727005529.jsonl @@ -0,0 +1 @@ +{"question": "\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", "prediction": "def can_arrange(arr):\n for i in range(len(arr) - 1, 0, -1):\n if arr[i] < arr[i-1]:\n return i\n return -1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0} diff --git a/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007492.jsonl b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007492.jsonl new file mode 100644 index 000000000..babbcc27f --- /dev/null +++ b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007492.jsonl @@ -0,0 +1 @@ +{"question": "\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", "prediction": "def can_arrange(arr):\n for i in range(len(arr) - 1, 0, -1):\n if arr[i] < arr[i-1]:\n return i\n return -1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.0037769999999999995} diff --git a/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007648.jsonl b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007648.jsonl new file mode 100644 index 000000000..21b2146fc --- /dev/null +++ b/examples/ags/data/baselines/general/humaneval/humaneval_results_1727007648.jsonl @@ -0,0 +1,131 @@ +{"question": "\ndef solve(N):\n \"\"\"Given a positive integer N, return the total sum of its digits in binary.\n \n Example\n For N = 1000, the sum of digits will be 1 the output should be \"1\".\n For N = 150, the sum of digits will be 6 the output should be \"110\".\n For N = 147, the sum of digits will be 12 the output should be \"1100\".\n \n Variables:\n @N integer\n Constraints: 0 \u2264 N \u2264 10000.\n Output:\n a string of binary number\n \"\"\"\n", "prediction": "def solve(N):\n # Calculate the sum of digits\n digit_sum = sum(int(digit) for digit in str(N))\n \n # Convert the sum to binary\n binary_sum = bin(digit_sum)[2:]\n \n return binary_sum", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.170664} +{"question": "\n\ndef truncate_number(number: float) -> float:\n \"\"\" Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncate_number(3.5)\n 0.5\n \"\"\"\n", "prediction": "def truncate_number(number: float) -> float:\n return number - int(number)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.0025380000000000003} +{"question": "\n\ndef skjkasdkd(lst):\n \"\"\"You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n \"\"\"\n", "prediction": "def skjkasdkd(lst):\n def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n def sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n\n primes = [num for num in lst if is_prime(num)]\n \n if not primes:\n return 0\n \n largest_prime = max(primes)\n return sum_of_digits(largest_prime)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.14256000000000002} +{"question": "\n\ndef triangle_area(a, h):\n \"\"\"Given length of a side and high return area for a triangle.\n >>> triangle_area(5, 3)\n 7.5\n \"\"\"\n", "prediction": "def triangle_area(a, h):\n \"\"\"Given length of a side and high return area for a triangle.\n >>> triangle_area(5, 3)\n 7.5\n \"\"\"\n return 0.5 * a * h", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.008271} +{"question": "\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", "prediction": "def 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 return [x + 1 for x in l]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.26796000000000003} +{"question": "\ndef search(lst):\n '''\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than \n zero, and has a frequency greater than or equal to the value of the integer itself. \n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1]) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3\n search([5, 5, 4, 4, 4]) == -1\n '''\n", "prediction": "def search(lst):\n # Create a dictionary to store the frequency of each number\n frequency = {}\n \n # Count the frequency of each number in the list\n for num in lst:\n frequency[num] = frequency.get(num, 0) + 1\n \n # Initialize the result to -1\n result = -1\n \n # Iterate through the frequency dictionary\n for num, freq in frequency.items():\n # Check if the number is positive and its frequency is greater than or equal to itself\n if num > 0 and freq >= num:\n # Update the result if this number is greater than the current result\n result = max(result, num)\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.28842600000000007} +{"question": "\ndef Strongest_Extension(class_name, extensions):\n \"\"\"You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters \n in the extension's name, the strength is given by the fraction CAP - SM. \n You should find the strongest extension and return a string in this \n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension \n (its strength is -1).\n Example:\n for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n \"\"\"\n", "prediction": "def Strongest_Extension(class_name, extensions):\n def extension_strength(ext):\n uppercase = sum(1 for char in ext if char.isupper())\n lowercase = sum(1 for char in ext if char.islower())\n return uppercase - lowercase\n\n strongest = max(extensions, key=extension_strength)\n return f\"{class_name}.{strongest}\"", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3496050000000001} +{"question": "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", "prediction": "from typing import List\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 # Count the occurrences of each number\n count_dict = {}\n for num in numbers:\n count_dict[num] = count_dict.get(num, 0) + 1\n \n # Create a new list with elements that occur only once\n result = [num for num in numbers if count_dict[num] == 1]\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3318840000000001} +{"question": "\ndef file_name_check(file_name):\n \"\"\"Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n Examples:\n file_name_check(\"example.txt\") # => 'Yes'\n file_name_check(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)\n \"\"\"\n", "prediction": "def file_name_check(file_name):\n # Check if the file name contains exactly one dot\n if file_name.count('.') != 1:\n return 'No'\n \n # Split the file name into name and extension\n name, ext = file_name.split('.')\n \n # Check if the name is not empty and starts with a letter\n if not name or not name[0].isalpha():\n return 'No'\n \n # Check if the extension is valid\n if ext not in ['txt', 'exe', 'dll']:\n return 'No'\n \n # Count the number of digits in the file name\n digit_count = sum(c.isdigit() for c in file_name)\n if digit_count > 3:\n return 'No'\n \n # If all checks pass, return 'Yes'\n return 'Yes'", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4635660000000001} +{"question": "\ndef select_words(s, n):\n \"\"\"Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n select_words(\"Mary had a little lamb\", 4) ==> [\"little\"]\n select_words(\"Mary had a little lamb\", 3) ==> [\"Mary\", \"lamb\"]\n select_words(\"simple white space\", 2) ==> []\n select_words(\"Hello world\", 4) ==> [\"world\"]\n select_words(\"Uncle sam\", 3) ==> [\"Uncle\"]\n \"\"\"\n", "prediction": "def select_words(s, n):\n def count_consonants(word):\n consonants = set('bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ')\n return sum(1 for char in word if char in consonants)\n\n words = s.split()\n return [word for word in words if count_consonants(word) == n]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4335300000000001} +{"question": "\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", "prediction": "def encode(message):\n vowels = 'aeiouAEIOU'\n result = []\n \n for char in message:\n if char.isalpha():\n if char in vowels:\n # Replace vowel with letter 2 places ahead\n new_char = chr((ord(char.lower()) - 97 + 2) % 26 + 97)\n result.append(new_char.swapcase())\n else:\n # Swap case for non-vowels\n result.append(char.swapcase())\n \n return ''.join(result)", "test_case_details": "\u9519\u8bef: This prints if this assert fails 1 (good for debugging!).\n \u89e3\u51b3\u65b9\u6848: def encode(message):\n vowels = 'aeiouAEIOU'\n result = []\n \n for char in message:\n if char.isalpha():\n if char in vowels:\n # Replace vowel with letter 2 places ahead\n new_char = chr((ord(char.lower()) - 97 + 2) % 26 + 97)\n result.append(new_char.swapcase())\n else:\n # Swap case for non-vowels\n result.append(char.swapcase())\n \n return ''.join(result).\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate('TEST') == 'tgst', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('Mudasir') == 'mWDCSKR', \"This prints if this assert fails 2 (good for debugging!)\"\n assert candidate('YES') == 'ygs', \"This prints if this assert fails 3 (good for debugging!)\"\n \n # Check some edge cases that are easy to work out by hand.\n assert candidate('This is a message') == 'tHKS KS C MGSSCGG', \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate(\"I DoNt KnOw WhAt tO WrItE\") == 'k dQnT kNqW wHcT Tq wRkTg', \"This prints if this assert fails 2 (also good for debugging!)\"\n\n", "score": 0, "cost": 0.4800690000000001} +{"question": "\n\ndef sum_squares(lst):\n \"\"\"You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n \n\n \"\"\"\n", "prediction": "import math\ndef sum_squares(lst):\n return sum(math.ceil(num) ** 2 for num in lst)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3657480000000001} +{"question": "\n\ndef fizz_buzz(n: int):\n \"\"\"Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizz_buzz(50)\n 0\n >>> fizz_buzz(78)\n 2\n >>> fizz_buzz(79)\n 3\n \"\"\"\n", "prediction": "def fizz_buzz(n: int):\n \"\"\"Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizz_buzz(50)\n 0\n >>> fizz_buzz(78)\n 2\n >>> fizz_buzz(79)\n 3\n \"\"\"\n count = 0\n for i in range(n):\n if i % 11 == 0 or i % 13 == 0:\n count += str(i).count('7')\n return count", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3959370000000001} +{"question": "\ndef prime_length(string):\n \"\"\"Write a function that takes a string and returns True if the string\n length is a prime number or False otherwise\n Examples\n prime_length('Hello') == True\n prime_length('abcdcba') == True\n prime_length('kittens') == True\n prime_length('orange') == False\n \"\"\"\n", "prediction": "def prime_length(string):\n \"\"\"Write a function that takes a string and returns True if the string\n length is a prime number or False otherwise\n Examples\n prime_length('Hello') == True\n prime_length('abcdcba') == True\n prime_length('kittens') == True\n prime_length('orange') == False\n \"\"\"\n length = len(string)\n \n if length < 2:\n return False\n \n for i in range(2, int(length**0.5) + 1):\n if length % i == 0:\n return False\n \n return True", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4741890000000001} +{"question": "from typing import List, Any\n\n\ndef filter_integers(values: List[Any]) -> List[int]:\n \"\"\" Filter given list of any python values only for integers\n >>> filter_integers(['a', 3.14, 5])\n [5]\n >>> filter_integers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n \"\"\"\n", "prediction": "from typing import List, Any\ndef filter_integers(values: List[Any]) -> List[int]:\n \"\"\" Filter given list of any python values only for integers\n >>> filter_integers(['a', 3.14, 5])\n [5]\n >>> filter_integers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n \"\"\"\n return [value for value in values if isinstance(value, int)]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4219650000000001} +{"question": "\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", "prediction": "def is_sorted(lst):\n if len(lst) <= 1:\n return True\n \n for i in range(1, len(lst)):\n if lst[i] < lst[i-1]:\n return False\n \n if i < len(lst) - 1 and lst[i] == lst[i-1] == lst[i+1]:\n return False\n \n return True", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.502851} +{"question": "\ndef fruit_distribution(s,n):\n \"\"\"\n In this task, you will be given a string that represents a number of apples and oranges \n that are distributed in a basket of fruit this basket contains \n apples, oranges, and mango fruits. Given the string that represents the total number of \n the oranges and apples and an integer that represent the total number of the fruits \n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruit_distribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruit_distribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruit_distribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruit_distribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n \"\"\"\n", "prediction": "def fruit_distribution(s, n):\n # Split the string and extract the numbers\n words = s.split()\n apples = int(words[0])\n oranges = int(words[3])\n \n # Calculate the number of mangoes\n mangoes = n - apples - oranges\n \n return mangoes", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5324430000000001} +{"question": "\ndef multiply(a, b):\n \"\"\"Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n Examples:\n multiply(148, 412) should return 16.\n multiply(19, 28) should return 72.\n multiply(2020, 1851) should return 0.\n multiply(14,-15) should return 20.\n \"\"\"\n", "prediction": "def multiply(a, b):\n \"\"\"Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n Examples:\n multiply(148, 412) should return 16.\n multiply(19, 28) should return 72.\n multiply(2020, 1851) should return 0.\n multiply(14,-15) should return 20.\n \"\"\"\n # Get the unit digit of a using modulo 10\n unit_a = abs(a) % 10\n \n # Get the unit digit of b using modulo 10\n unit_b = abs(b) % 10\n \n # Multiply the unit digits and return the result\n return unit_a * unit_b", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.32185500000000017} +{"question": "from typing import List\n\n\ndef string_xor(a: str, b: str) -> str:\n \"\"\" Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> string_xor('010', '110')\n '100'\n \"\"\"\n", "prediction": "def string_xor(a: str, b: str) -> str:\n result = ''\n for bit_a, bit_b in zip(a, b):\n if bit_a == bit_b:\n result += '0'\n else:\n result += '1'\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5808840000000002} +{"question": "\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", "prediction": "def 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 # Convert the integer to a string\n x_str = str(x)\n \n # Get the length of the number\n length = len(x_str)\n \n # If shift is greater than length, just reverse the string\n if shift >= length:\n return x_str[::-1]\n \n # Calculate the effective shift (in case shift > length)\n effective_shift = shift % length\n \n # Perform the circular shift\n shifted = x_str[-effective_shift:] + x_str[:-effective_shift]\n \n return shifted", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def 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 # Convert the integer to a string\n x_str = str(x)\n \n # Get the length of the number\n length = len(x_str)\n \n # If shift is greater than length, just reverse the string\n if shift >= length:\n return x_str[::-1]\n \n # Calculate the effective shift (in case shift > length)\n effective_shift = shift % length\n \n # Perform the circular shift\n shifted = x_str[-effective_shift:] + x_str[:-effective_shift]\n \n return shifted.\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate(100, 2) == \"001\"\n assert candidate(12, 2) == \"12\"\n assert candidate(97, 8) == \"79\"\n assert candidate(12, 1) == \"21\", \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(11, 101) == \"11\", \"This prints if this assert fails 2 (also good for debugging!)\"\n\n", "score": 0, "cost": 0.6371580000000002} +{"question": "\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", "prediction": "def anti_shuffle(s):\n # Split the string into words\n words = s.split()\n \n # Function to sort characters in a word\n def sort_word(word):\n # Separate alphanumeric characters from others\n alpha = ''.join(c for c in word if c.isalnum())\n non_alpha = ''.join(c for c in word if not c.isalnum())\n \n # Sort alphanumeric characters\n sorted_alpha = ''.join(sorted(alpha, key=lambda c: (c.lower(), c)))\n \n # Combine sorted alphanumeric characters with non-alphanumeric ones\n return sorted_alpha + non_alpha\n \n # Apply sort_word function to each word\n sorted_words = [sort_word(word) for word in words]\n \n # Join the sorted words back into a string\n return ' '.join(sorted_words)", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def anti_shuffle(s):\n # Split the string into words\n words = s.split()\n \n # Function to sort characters in a word\n def sort_word(word):\n # Separate alphanumeric characters from others\n alpha = ''.join(c for c in word if c.isalnum())\n non_alpha = ''.join(c for c in word if not c.isalnum())\n \n # Sort alphanumeric characters\n sorted_alpha = ''.join(sorted(alpha, key=lambda c: (c.lower(), c)))\n \n # Combine sorted alphanumeric characters with non-alphanumeric ones\n return sorted_alpha + non_alpha\n \n # Apply sort_word function to each word\n sorted_words = [sort_word(word) for word in words]\n \n # Join the sorted words back into a string\n return ' '.join(sorted_words).\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate('Hi') == 'Hi'\n assert candidate('hello') == 'ehllo'\n assert candidate('number') == 'bemnru'\n assert candidate('abcd') == 'abcd'\n assert candidate('Hello World!!!') == 'Hello !!!Wdlor'\n assert candidate('') == ''\n assert candidate('Hi. My name is Mister Robot. How are you?') == '.Hi My aemn is Meirst .Rboot How aer ?ouy'\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n", "score": 0, "cost": 0.20905200000000002} +{"question": "from typing import List\n\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n \"\"\" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parse_nested_parens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n \"\"\"\n", "prediction": "from typing import List\ndef parse_nested_parens(paren_string: str) -> List[int]:\n def depth(group: str) -> int:\n max_depth = 0\n current_depth = 0\n for char in group:\n if char == '(':\n current_depth += 1\n max_depth = max(max_depth, current_depth)\n elif char == ')':\n current_depth -= 1\n return max_depth\n\n groups = paren_string.split()\n return [depth(group) for group in groups]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.061005000000000004} +{"question": "\n\ndef flip_case(string: str) -> str:\n \"\"\" For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n >>> flip_case('Hello')\n 'hELLO'\n \"\"\"\n", "prediction": "def flip_case(string: str) -> str:\n return string.swapcase()", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.00483} +{"question": "\ndef is_simple_power(x, n):\n \"\"\"Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n For example:\n is_simple_power(1, 4) => true\n is_simple_power(2, 2) => true\n is_simple_power(8, 2) => true\n is_simple_power(3, 2) => false\n is_simple_power(3, 1) => false\n is_simple_power(5, 3) => false\n \"\"\"\n", "prediction": "def is_simple_power(x, n):\n \"\"\"Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n \"\"\"\n if x == 1:\n return True\n if n == 1:\n return x == 1\n \n power = 1\n result = n\n \n while result <= x:\n if result == x:\n return True\n power += 1\n result = n ** power\n \n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.092868} +{"question": "\n\n\ndef sum_squares(lst):\n \"\"\"\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n \"\"\"\n", "prediction": "def sum_squares(lst):\n \"\"\"\n This function takes a list of integers, modifies certain elements based on their indices,\n and returns the sum of all entries.\n \"\"\"\n result = 0\n for i, num in enumerate(lst):\n if i % 3 == 0:\n result += num ** 2 # Square if index is multiple of 3\n elif i % 4 == 0:\n result += num ** 3 # Cube if index is multiple of 4 (but not 3)\n else:\n result += num # Keep original value for other indices\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.16537200000000002} +{"question": "\n\ndef encode_cyclic(s: str):\n \"\"\"\n returns encoded string by cycling groups of three characters.\n \"\"\"\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n # cycle elements in each group. Unless group has fewer elements than 3.\n groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups]\n return \"\".join(groups)\n\n\ndef decode_cyclic(s: str):\n \"\"\"\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n \"\"\"\n", "prediction": "def decode_cyclic(s: str):\n \"\"\"\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n \"\"\"\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n # reverse cycle elements in each group. Unless group has fewer elements than 3.\n groups = [(group[-1] + group[:-1]) if len(group) == 3 else group for group in groups]\n return \"\".join(groups)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.071034} +{"question": "\n\ndef car_race_collision(n: int):\n \"\"\"\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n \"\"\"\n", "prediction": "def car_race_collision(n: int):\n return n * n", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.12515700000000002} +{"question": "from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\" For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n \"\"\"\n", "prediction": "from typing import List\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n if not numbers:\n return 0.0\n \n # Calculate the mean of the dataset\n mean = sum(numbers) / len(numbers)\n \n # Calculate the absolute deviations from the mean\n absolute_deviations = [abs(x - mean) for x in numbers]\n \n # Calculate the average of the absolute deviations\n mad = sum(absolute_deviations) / len(numbers)\n \n return mad", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.227367} +{"question": "\ndef is_equal_to_sum_even(n):\n \"\"\"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n is_equal_to_sum_even(4) == False\n is_equal_to_sum_even(6) == False\n is_equal_to_sum_even(8) == True\n \"\"\"\n", "prediction": "def is_equal_to_sum_even(n):\n \"\"\"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\"\"\"\n \n # Check if n is even and at least 8\n if n % 2 != 0 or n < 8:\n return False\n \n # If n is divisible by 4, it can always be written as sum of 4 equal even numbers\n if n % 4 == 0:\n return True\n \n # If n is of the form 4k+2, it can be written as 2 + 2 + (n-4)/2 + (n-4)/2\n if (n - 2) % 4 == 0:\n return True\n \n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.23378100000000002} +{"question": "import math\n\n\ndef poly(xs: list, x: float):\n \"\"\"\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n \"\"\"\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\n\n\ndef find_zero(xs: list):\n \"\"\" xs are coefficients of a polynomial.\n find_zero find x such that poly(x) = 0.\n find_zero returns only only zero point, even if there are many.\n Moreover, find_zero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n \"\"\"\n", "prediction": "import math\ndef poly(xs: list, x: float):\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\ndef poly_derivative(xs: list, x: float):\n return sum([i * coeff * math.pow(x, i-1) for i, coeff in enumerate(xs) if i > 0])\ndef find_zero(xs: list):\n if len(xs) % 2 != 0:\n raise ValueError(\"The number of coefficients must be even.\")\n \n if xs[-1] == 0:\n raise ValueError(\"The largest coefficient must be non-zero.\")\n\n # Initial guess: start at x = 1\n x = 1.0\n epsilon = 1e-10\n max_iterations = 1000\n\n for _ in range(max_iterations):\n y = poly(xs, x)\n if abs(y) < epsilon:\n return x\n \n dy = poly_derivative(xs, x)\n if dy == 0:\n # If derivative is zero, slightly adjust x and continue\n x += epsilon\n continue\n \n x = x - y / dy\n\n # If we reach here, the method didn't converge\n raise ValueError(\"Failed to converge to a solution.\")", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3025020000000001} +{"question": "\ndef simplify(x, n):\n \"\"\"Your task is to implement a function that will simplify the expression\n x * n. The function returns True if x * n evaluates to a whole number and False\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n / where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = True\n simplify(\"1/6\", \"2/1\") = False\n simplify(\"7/10\", \"10/2\") = False\n \"\"\"\n", "prediction": "from fractions import Fraction\ndef simplify(x, n):\n # Convert string fractions to Fraction objects\n x_frac = Fraction(x)\n n_frac = Fraction(n)\n \n # Multiply the fractions\n result = x_frac * n_frac\n \n # Check if the result is a whole number\n return result.denominator == 1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.153591} +{"question": "\ndef move_one_ball(arr):\n \"\"\"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return True else return False.\n If the given array is empty then return True.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n move_one_ball([3, 4, 5, 1, 2])==>True\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n move_one_ball([3, 5, 4, 1, 2])==>False\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n \"\"\"\n", "prediction": "def move_one_ball(arr):\n if not arr:\n return True\n \n n = len(arr)\n min_index = arr.index(min(arr))\n \n # Check if the array is already sorted\n if min_index == 0 and all(arr[i] <= arr[i+1] for i in range(n-1)):\n return True\n \n # Check if the array can be sorted with right shifts\n return all(arr[i] <= arr[(i+1) % n] for i in range(min_index, min_index + n - 1))", "test_case_details": "\u9519\u8bef: list index out of range.\n \u89e3\u51b3\u65b9\u6848: def move_one_ball(arr):\n if not arr:\n return True\n \n n = len(arr)\n min_index = arr.index(min(arr))\n \n # Check if the array is already sorted\n if min_index == 0 and all(arr[i] <= arr[i+1] for i in range(n-1)):\n return True\n \n # Check if the array can be sorted with right shifts\n return all(arr[i] <= arr[(i+1) % n] for i in range(min_index, min_index + n - 1)).\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate([3, 4, 5, 1, 2])==True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([3, 5, 10, 1, 2])==True\n assert candidate([4, 3, 1, 2])==False\n # Check some edge cases that are easy to work out by hand.\n assert candidate([3, 5, 4, 1, 2])==False, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([])==True\n", "score": 0, "cost": 0.22207800000000003} +{"question": "\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", "prediction": "def pluck(arr):\n if not arr:\n return []\n \n smallest_even = float('inf')\n smallest_index = -1\n \n for i, num in enumerate(arr):\n if num % 2 == 0 and num < smallest_even:\n smallest_even = num\n smallest_index = i\n \n if smallest_index != -1:\n return [smallest_even, smallest_index]\n else:\n return []", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.241545} +{"question": "\n\ndef is_palindrome(string: str) -> bool:\n \"\"\" Test if given string is a palindrome \"\"\"\n return string == string[::-1]\n\n\ndef make_palindrome(string: str) -> str:\n \"\"\" Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> make_palindrome('')\n ''\n >>> make_palindrome('cat')\n 'catac'\n >>> make_palindrome('cata')\n 'catac'\n \"\"\"\n", "prediction": "def make_palindrome(string: str) -> str:\n if not string:\n return \"\"\n \n for i in range(len(string), 0, -1):\n if is_palindrome(string[i-1:]):\n return string + string[:i-1][::-1]\n \n return string + string[:-1][::-1]", "test_case_details": "\u9519\u8bef: name 'is_palindrome' is not defined.\n \u89e3\u51b3\u65b9\u6848: def make_palindrome(string: str) -> str:\n if not string:\n return \"\"\n \n for i in range(len(string), 0, -1):\n if is_palindrome(string[i-1:]):\n return string + string[:i-1][::-1]\n \n return string + string[:-1][::-1].\n \u6d4b\u8bd5: \n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('') == ''\n assert candidate('x') == 'x'\n assert candidate('xyz') == 'xyzyx'\n assert candidate('xyx') == 'xyx'\n assert candidate('jerry') == 'jerryrrej'\n", "score": 0, "cost": 0.24821100000000001} +{"question": "\ndef count_up_to(n):\n \"\"\"Implement a function that takes an non-negative integer and returns an array of the first n\n integers that are prime numbers and less than n.\n for example:\n count_up_to(5) => [2,3]\n count_up_to(11) => [2,3,5,7]\n count_up_to(0) => []\n count_up_to(20) => [2,3,5,7,11,13,17,19]\n count_up_to(1) => []\n count_up_to(18) => [2,3,5,7,11,13,17]\n \"\"\"\n", "prediction": "def count_up_to(n):\n if n <= 2:\n return []\n \n primes = []\n is_prime = [True] * n\n is_prime[0] = is_prime[1] = False\n \n for i in range(2, int(n**0.5) + 1):\n if is_prime[i]:\n for j in range(i*i, n, i):\n is_prime[j] = False\n \n for i in range(2, n):\n if is_prime[i]:\n primes.append(i)\n \n return primes", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.148713} +{"question": "\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", "prediction": "def histogram(test):\n if not test:\n return {}\n\n # Split the string into a list of letters\n letters = test.split()\n\n # Count occurrences of each letter\n letter_counts = {}\n for letter in letters:\n letter_counts[letter] = letter_counts.get(letter, 0) + 1\n\n # Find the maximum count\n max_count = max(letter_counts.values())\n\n # Create a dictionary with letters that have the maximum count\n result = {letter: count for letter, count in letter_counts.items() if count == max_count}\n\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.08148} +{"question": "from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n \"\"\" Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True\n \"\"\"\n", "prediction": "from typing import List\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n numbers.sort() # Sort the list to compare adjacent elements\n \n for i in range(len(numbers) - 1):\n if abs(numbers[i] - numbers[i+1]) < threshold:\n return True\n \n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.27258000000000004} +{"question": "\ndef add_elements(arr, k):\n \"\"\"\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n \"\"\"\n", "prediction": "def add_elements(arr, k):\n sum = 0\n for i in range(min(k, len(arr))):\n if 0 <= arr[i] <= 99:\n sum += arr[i]\n return sum", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def add_elements(arr, k):\n sum = 0\n for i in range(min(k, len(arr))):\n if 0 <= arr[i] <= 99:\n sum += arr[i]\n return sum.\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate([1,-2,-3,41,57,76,87,88,99], 3) == -4\n assert candidate([111,121,3,4000,5,6], 2) == 0\n assert candidate([11,21,3,90,5,6,7,8,9], 4) == 125\n assert candidate([111,21,3,4000,5,6,7,8,9], 4) == 24, \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1], 1) == 1, \"This prints if this assert fails 2 (also good for debugging!)\"\n\n", "score": 0, "cost": 0.3438960000000001} +{"question": "\ndef get_odd_collatz(n):\n \"\"\"\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n\n For example:\n get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.\n \"\"\"\n", "prediction": "def get_odd_collatz(n):\n if n <= 0:\n return []\n \n odd_numbers = set()\n \n while n != 1:\n if n % 2 != 0:\n odd_numbers.add(n)\n \n if n % 2 == 0:\n n = n // 2\n else:\n n = 3 * n + 1\n \n odd_numbers.add(1) # Always include 1 as it's the last number in the sequence\n \n return sorted(list(odd_numbers))", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5275200000000001} +{"question": "\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", "prediction": "def 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 vowels = set('aeiouAEIOU')\n count = sum(1 for char in s if char in vowels)\n \n if s and s[-1].lower() == 'y':\n count += 1\n \n return count", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4072680000000001} +{"question": "\n\ndef change_base(x: int, base: int):\n \"\"\"Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n >>> change_base(8, 3)\n '22'\n >>> change_base(8, 2)\n '1000'\n >>> change_base(7, 2)\n '111'\n \"\"\"\n", "prediction": "def change_base(x: int, base: int):\n \"\"\"Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n \"\"\"\n if x == 0:\n return '0'\n \n digits = []\n while x:\n digits.append(str(x % base))\n x //= base\n \n return ''.join(digits[::-1])", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4124340000000001} +{"question": "\ndef specialFilter(nums):\n \"\"\"Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n \"\"\"\n", "prediction": "def specialFilter(nums):\n count = 0\n for num in nums:\n if num > 10:\n num_str = str(abs(num))\n if int(num_str[0]) % 2 == 1 and int(num_str[-1]) % 2 == 1:\n count += 1\n return count", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4173240000000001} +{"question": "from typing import List\n\n\ndef concatenate(strings: List[str]) -> str:\n \"\"\" Concatenate list of strings into a single string\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'\n \"\"\"\n", "prediction": "from typing import List\ndef concatenate(strings: List[str]) -> str:\n return ''.join(strings)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3534240000000001} +{"question": "\n\ndef triples_sum_to_zero(l: list):\n \"\"\"\n triples_sum_to_zero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triples_sum_to_zero([1, 3, 5, 0])\n False\n >>> triples_sum_to_zero([1, 3, -2, 1])\n True\n >>> triples_sum_to_zero([1, 2, 3, 7])\n False\n >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7])\n True\n >>> triples_sum_to_zero([1])\n False\n \"\"\"\n", "prediction": "def triples_sum_to_zero(l: list):\n n = len(l)\n if n < 3:\n return False\n \n for i in range(n - 2):\n for j in range(i + 1, n - 1):\n for k in range(j + 1, n):\n if l[i] + l[j] + l[k] == 0:\n return True\n \n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3854310000000001} +{"question": "\ndef minSubArraySum(nums):\n \"\"\"\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n \"\"\"\n", "prediction": "def minSubArraySum(nums):\n if not nums:\n return 0\n \n min_sum = float('inf')\n current_sum = 0\n \n for num in nums:\n current_sum = min(num, current_sum + num)\n min_sum = min(min_sum, current_sum)\n \n return min_sum", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4524180000000001} +{"question": "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", "prediction": "from typing import List\ndef factorize(n: int) -> List[int]:\n factors = []\n divisor = 2\n \n while n > 1:\n while n % divisor == 0:\n factors.append(divisor)\n n //= divisor\n divisor += 1\n \n if divisor * divisor > n:\n if n > 1:\n factors.append(n)\n break\n \n return factors", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.49790100000000004} +{"question": "\n\ndef strlen(string: str) -> int:\n \"\"\" Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n \"\"\"\n", "prediction": "def strlen(string: str) -> int:\n \"\"\" Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n \"\"\"\n return len(string)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3386790000000001} +{"question": "\ndef match_parens(lst):\n '''\n You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n\n Examples:\n match_parens(['()(', ')']) == 'Yes'\n match_parens([')', ')']) == 'No'\n '''\n", "prediction": "def match_parens(lst):\n # Combine both strings\n combined = lst[0] + lst[1]\n \n # Count open and close parentheses\n open_count = combined.count('(')\n close_count = combined.count(')')\n \n # If counts are not equal, it's impossible to balance\n if open_count != close_count:\n return 'No'\n \n # Check if it's possible to arrange them correctly\n balance = 0\n for char in combined:\n if char == '(':\n balance += 1\n else: # char == ')'\n balance -= 1\n \n # If at any point we have more closing than opening, it's not possible\n if balance < 0:\n return 'No'\n \n return 'Yes'", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def match_parens(lst):\n # Combine both strings\n combined = lst[0] + lst[1]\n \n # Count open and close parentheses\n open_count = combined.count('(')\n close_count = combined.count(')')\n \n # If counts are not equal, it's impossible to balance\n if open_count != close_count:\n return 'No'\n \n # Check if it's possible to arrange them correctly\n balance = 0\n for char in combined:\n if char == '(':\n balance += 1\n else: # char == ')'\n balance -= 1\n \n # If at any point we have more closing than opening, it's not possible\n if balance < 0:\n return 'No'\n \n return 'Yes'.\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate(['()(', ')']) == 'Yes'\n assert candidate([')', ')']) == 'No'\n assert candidate(['(()(())', '())())']) == 'No'\n assert candidate([')())', '(()()(']) == 'Yes'\n assert candidate(['(())))', '(()())((']) == 'Yes'\n assert candidate(['()', '())']) == 'No'\n assert candidate(['(()(', '()))()']) == 'Yes'\n assert candidate(['((((', '((())']) == 'No'\n assert candidate([')(()', '(()(']) == 'No'\n assert candidate([')(', ')(']) == 'No'\n \n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(['(', ')']) == 'Yes'\n assert candidate([')', '(']) == 'Yes' \n\n", "score": 0, "cost": 0.5483490000000001} +{"question": "\ndef numerical_letter_grade(grades):\n \"\"\"It is the last week of the semester and the teacher has to give the grades\n to students. The teacher has been making her own algorithm for grading.\n The only problem is, she has lost the code she used for grading.\n She has given you a list of GPAs for some students and you have to write \n a function that can output a list of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A \n > 3.3 A- \n > 3.0 B+\n > 2.7 B \n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+ \n > 0.7 D \n > 0.0 D-\n 0.0 E\n \n\n Example:\n grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']\n \"\"\"\n", "prediction": "def numerical_letter_grade(grades):\n grade_table = [\n (4.0, 'A+'),\n (3.7, 'A'),\n (3.3, 'A-'),\n (3.0, 'B+'),\n (2.7, 'B'),\n (2.3, 'B-'),\n (2.0, 'C+'),\n (1.7, 'C'),\n (1.3, 'C-'),\n (1.0, 'D+'),\n (0.7, 'D'),\n (0.0, 'D-'),\n ]\n \n letter_grades = []\n \n for gpa in grades:\n if gpa == 0.0:\n letter_grades.append('E')\n else:\n for threshold, grade in grade_table:\n if gpa >= threshold:\n letter_grades.append(grade)\n break\n \n return letter_grades", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def numerical_letter_grade(grades):\n grade_table = [\n (4.0, 'A+'),\n (3.7, 'A'),\n (3.3, 'A-'),\n (3.0, 'B+'),\n (2.7, 'B'),\n (2.3, 'B-'),\n (2.0, 'C+'),\n (1.7, 'C'),\n (1.3, 'C-'),\n (1.0, 'D+'),\n (0.7, 'D'),\n (0.0, 'D-'),\n ]\n \n letter_grades = []\n \n for gpa in grades:\n if gpa == 0.0:\n letter_grades.append('E')\n else:\n for threshold, grade in grade_table:\n if gpa >= threshold:\n letter_grades.append(grade)\n break\n \n return letter_grades.\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate([4.0, 3, 1.7, 2, 3.5]) == ['A+', 'B', 'C-', 'C', 'A-']\n assert candidate([1.2]) == ['D+']\n assert candidate([0.5]) == ['D-']\n assert candidate([0.0]) == ['E']\n assert candidate([1, 0.3, 1.5, 2.8, 3.3]) == ['D', 'D-', 'C-', 'B', 'B+']\n assert candidate([0, 0.7]) == ['E', 'D-']\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\n", "score": 0, "cost": 0.5603760000000001} +{"question": "\ndef decimal_to_binary(decimal):\n \"\"\"You will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n\n Examples:\n decimal_to_binary(15) # returns \"db1111db\"\n decimal_to_binary(32) # returns \"db100000db\"\n \"\"\"\n", "prediction": "def decimal_to_binary(decimal):\n if decimal == 0:\n return \"db0db\"\n \n binary = \"\"\n while decimal > 0:\n binary = str(decimal % 2) + binary\n decimal //= 2\n \n return \"db\" + binary + \"db\"", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5997060000000002} +{"question": "\n\ndef prime_fib(n: int):\n \"\"\"\n prime_fib returns n-th number that is a Fibonacci number and it's also prime.\n >>> prime_fib(1)\n 2\n >>> prime_fib(2)\n 3\n >>> prime_fib(3)\n 5\n >>> prime_fib(4)\n 13\n >>> prime_fib(5)\n 89\n \"\"\"\n", "prediction": "def prime_fib(n: int):\n \"\"\"\n prime_fib returns n-th number that is a Fibonacci number and it's also prime.\n \"\"\"\n def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n return True\n\n def fibonacci():\n a, b = 0, 1\n while True:\n yield b\n a, b = b, a + b\n\n count = 0\n for fib in fibonacci():\n if is_prime(fib):\n count += 1\n if count == n:\n return fib", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5533680000000001} +{"question": "\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", "prediction": "def next_smallest(lst):\n if len(lst) < 2:\n return None\n \n smallest = float('inf')\n next_smallest = float('inf')\n \n for num in lst:\n if num < smallest:\n next_smallest = smallest\n smallest = num\n elif num < next_smallest and num != smallest:\n next_smallest = num\n \n return next_smallest if next_smallest != float('inf') else None", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.19572} +{"question": "\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", "prediction": "def 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 \"\"\"\n count = 0\n for num in arr:\n digit_sum = sum(int(digit) for digit in str(abs(num)))\n if num < 0:\n digit_sum = -int(str(abs(num))[0]) + digit_sum - int(str(abs(num))[0])\n if digit_sum > 0:\n count += 1\n return count", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.076464} +{"question": "\ndef eat(number, need, remaining):\n \"\"\"\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n \"\"\"\n", "prediction": "def eat(number, need, remaining):\n # Calculate how many carrots the rabbit can actually eat\n can_eat = min(need, remaining)\n \n # Calculate the total number of carrots eaten\n total_eaten = number + can_eat\n \n # Calculate the number of carrots left\n left = max(0, remaining - can_eat)\n \n return [total_eaten, left]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.087144} +{"question": "\ndef compare_one(a, b):\n \"\"\"\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return None if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compare_one(1, 2.5) \u279e 2.5\n compare_one(1, \"2,3\") \u279e \"2,3\"\n compare_one(\"5,1\", \"6\") \u279e \"6\"\n compare_one(\"1\", 1) \u279e None\n \"\"\"\n", "prediction": "def compare_one(a, b):\n def convert_to_float(value):\n if isinstance(value, str):\n return float(value.replace(',', '.'))\n return float(value)\n\n try:\n a_float = convert_to_float(a)\n b_float = convert_to_float(b)\n\n if a_float == b_float:\n return None\n elif a_float > b_float:\n return a\n else:\n return b\n except ValueError:\n # Handle the case where conversion to float fails\n return None", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.055566000000000004} +{"question": "\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", "prediction": "def 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 sorted_list = sorted(l)\n length = len(sorted_list)\n \n if length % 2 == 0:\n # If the list has an even number of elements\n middle_right = length // 2\n middle_left = middle_right - 1\n return (sorted_list[middle_left] + sorted_list[middle_right]) / 2\n else:\n # If the list has an odd number of elements\n middle = length // 2\n return sorted_list[middle]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.10340400000000001} +{"question": "\ndef valid_date(date):\n \"\"\"You have to write a function which validates a given date string and\n returns True if the date is valid otherwise False.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example: \n valid_date('03-11-2000') => True\n\n valid_date('15-01-2012') => False\n\n valid_date('04-0-2040') => False\n\n valid_date('06-04-2020') => True\n\n valid_date('06/04/2020') => False\n \"\"\"\n", "prediction": "def valid_date(date):\n if not date:\n return False\n \n try:\n month, day, year = map(int, date.split('-'))\n except ValueError:\n return False\n \n if len(date.split('-')) != 3:\n return False\n \n if month < 1 or month > 12:\n return False\n \n if month in [1, 3, 5, 7, 8, 10, 12]:\n max_days = 31\n elif month in [4, 6, 9, 11]:\n max_days = 30\n else: # February\n max_days = 29\n \n if day < 1 or day > max_days:\n return False\n \n if year < 1:\n return False\n \n # Check if the date string matches the format mm-dd-yyyy\n if not (len(date) == 10 and date[2] == '-' and date[5] == '-'):\n return False\n \n return True", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.13685400000000003} +{"question": "\n\ndef correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"(\" and \")\".\n return True if every opening bracket has a corresponding closing bracket.\n\n >>> correct_bracketing(\"(\")\n False\n >>> correct_bracketing(\"()\")\n True\n >>> correct_bracketing(\"(()())\")\n True\n >>> correct_bracketing(\")(()\")\n False\n \"\"\"\n", "prediction": "def correct_bracketing(brackets: str):\n stack = []\n for bracket in brackets:\n if bracket == '(':\n stack.append(bracket)\n elif bracket == ')':\n if not stack:\n return False\n stack.pop()\n return len(stack) == 0", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.028748999999999997} +{"question": "\ndef smallest_change(arr):\n \"\"\"\n Given an array arr of integers, find the minimum number of elements that\n need to be changed to make the array palindromic. A palindromic array is an array that\n is read the same backwards and forwards. In one change, you can change one element to any other element.\n\n For example:\n smallest_change([1,2,3,5,4,7,9,6]) == 4\n smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1\n smallest_change([1, 2, 3, 2, 1]) == 0\n \"\"\"\n", "prediction": "def smallest_change(arr):\n left = 0\n right = len(arr) - 1\n changes = 0\n \n while left < right:\n if arr[left] != arr[right]:\n changes += 1\n left += 1\n right -= 1\n \n return changes", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.26362800000000003} +{"question": "\n\ndef sort_third(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sort_third([1, 2, 3])\n [1, 2, 3]\n >>> sort_third([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n \"\"\"\n", "prediction": "def sort_third(l: list):\n # Extract elements at indices divisible by 3\n third_elements = [l[i] for i in range(0, len(l), 3)]\n \n # Sort these elements\n sorted_third = sorted(third_elements)\n \n # Create a new list with the same length as the input\n result = l.copy()\n \n # Replace elements at indices divisible by 3 with sorted values\n for i, value in enumerate(sorted_third):\n if i * 3 < len(result):\n result[i * 3] = value\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.037806} +{"question": "\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", "prediction": "def reverse_delete(s, c):\n # Remove characters from s that are in c\n result = ''.join(char for char in s if char not in c)\n \n # Check if the result is a palindrome\n is_palindrome = result == result[::-1]\n \n # Return the tuple with the result string and palindrome check\n return (result, is_palindrome)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.045897} +{"question": "\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", "prediction": "def maximum(arr, k):\n # Sort the array in descending order\n sorted_arr = sorted(arr, reverse=True)\n \n # Return the first k elements\n return sorted(sorted_arr[:k])", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.033183} +{"question": "\ndef prod_signs(arr):\n \"\"\"\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prod_signs([1, 2, 2, -4]) == -9\n >>> prod_signs([0, 1]) == 0\n >>> prod_signs([]) == None\n \"\"\"\n", "prediction": "def prod_signs(arr):\n \"\"\"\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prod_signs([1, 2, 2, -4]) == -9\n >>> prod_signs([0, 1]) == 0\n >>> prod_signs([]) == None\n \"\"\"\n if not arr:\n return None\n \n sum_magnitudes = sum(abs(num) for num in arr)\n product_signs = 1\n \n for num in arr:\n if num > 0:\n product_signs *= 1\n elif num < 0:\n product_signs *= -1\n else: # num == 0\n product_signs *= 0\n break\n \n return sum_magnitudes * product_signs", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.20300400000000002} +{"question": "\n\ndef derivative(xs: list):\n \"\"\" xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n \"\"\"\n", "prediction": "def derivative(xs: list):\n \"\"\" xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n \"\"\"\n result = []\n for i in range(1, len(xs)):\n result.append(i * xs[i])\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.042033} +{"question": "\ndef string_to_md5(text):\n \"\"\"\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n \"\"\"\n", "prediction": "import hashlib\ndef string_to_md5(text):\n \"\"\"\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n \"\"\"\n if text == \"\":\n return None\n \n # Encode the string to bytes\n text_bytes = text.encode('utf-8')\n \n # Create an MD5 hash object\n md5_hash = hashlib.md5()\n \n # Update the hash object with the bytes\n md5_hash.update(text_bytes)\n \n # Get the hexadecimal representation of the hash\n return md5_hash.hexdigest()", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.21483300000000002} +{"question": "\ndef make_a_pile(n):\n \"\"\"\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n\n Examples:\n >>> make_a_pile(3)\n [3, 5, 7]\n \"\"\"\n", "prediction": "def make_a_pile(n):\n \"\"\"\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n\n Examples:\n >>> make_a_pile(3)\n [3, 5, 7]\n \"\"\"\n pile = [n]\n current = n\n \n for _ in range(1, n):\n if current % 2 == 0: # If current is even\n current += 2 # Next even number\n else: # If current is odd\n current += 2 # Next odd number\n pile.append(current)\n \n return pile", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.10950300000000002} +{"question": "\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", "prediction": "def unique_digits(x):\n def has_no_even_digit(num):\n return all(int(digit) % 2 != 0 for digit in str(num))\n \n result = [num for num in x if has_no_even_digit(num)]\n return sorted(result)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.28233300000000006} +{"question": "\n\ndef add(x: int, y: int):\n \"\"\"Add two numbers x and y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12\n \"\"\"\n", "prediction": "def add(x: int, y: int):\n \"\"\"Add two numbers x and y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12\n \"\"\"\n return x + y", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.243567} +{"question": "from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n \"\"\" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n \"\"\"\n", "prediction": "from typing import List\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n \"\"\" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n \"\"\"\n if not numbers:\n return []\n \n result = []\n for num in numbers[:-1]:\n result.extend([num, delimeter])\n result.append(numbers[-1])\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.31683300000000014} +{"question": "\ndef get_closest_vowel(word):\n \"\"\"You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n get_closest_vowel(\"yogurt\") ==> \"u\"\n get_closest_vowel(\"FULL\") ==> \"U\"\n get_closest_vowel(\"quick\") ==> \"\"\n get_closest_vowel(\"ab\") ==> \"\"\n \"\"\"\n", "prediction": "def get_closest_vowel(word):\n vowels = 'aeiouAEIOU'\n \n # Iterate through the word from right to left, skipping the last character\n for i in range(len(word) - 2, 0, -1):\n # Check if the current character is a vowel\n if word[i] in vowels:\n # Check if it's surrounded by consonants\n if word[i-1] not in vowels and word[i+1] not in vowels:\n return word[i]\n \n # If no vowel is found meeting the conditions, return an empty string\n return \"\"", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.48693900000000007} +{"question": "\ndef intersection(interval1, interval2):\n \"\"\"You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n \"\"\"\n", "prediction": "def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\ndef intersection(interval1, interval2):\n start1, end1 = interval1\n start2, end2 = interval2\n \n # Find the intersection\n intersection_start = max(start1, start2)\n intersection_end = min(end1, end2)\n \n # Check if there's an intersection\n if intersection_start <= intersection_end:\n # Calculate the length of the intersection\n intersection_length = intersection_end - intersection_start + 1\n \n # Check if the length is prime\n if is_prime(intersection_length):\n return \"YES\"\n \n return \"NO\"", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\ndef intersection(interval1, interval2):\n start1, end1 = interval1\n start2, end2 = interval2\n \n # Find the intersection\n intersection_start = max(start1, start2)\n intersection_end = min(end1, end2)\n \n # Check if there's an intersection\n if intersection_start <= intersection_end:\n # Calculate the length of the intersection\n intersection_length = intersection_end - intersection_start + 1\n \n # Check if the length is prime\n if is_prime(intersection_length):\n return \"YES\"\n \n return \"NO\".\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert candidate((1, 2), (2, 3)) == \"NO\"\n assert candidate((-1, 1), (0, 4)) == \"NO\"\n assert candidate((-3, -1), (-5, 5)) == \"YES\"\n assert candidate((-2, 2), (-4, 0)) == \"YES\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate((-11, 2), (-1, -1)) == \"NO\"\n assert candidate((1, 2), (3, 5)) == \"NO\"\n assert candidate((1, 2), (1, 2)) == \"NO\"\n assert candidate((-2, -2), (-3, -2)) == \"NO\"\n\n", "score": 0, "cost": 0.4406400000000001} +{"question": "\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", "prediction": "def double_the_difference(lst):\n return sum(num**2 for num in lst if isinstance(num, int) and num > 0 and num % 2 != 0)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.32649900000000015} +{"question": "\n\ndef modp(n: int, p: int):\n \"\"\"Return 2^n modulo p (be aware of numerics).\n >>> modp(3, 5)\n 3\n >>> modp(1101, 101)\n 2\n >>> modp(0, 101)\n 1\n >>> modp(3, 11)\n 8\n >>> modp(100, 101)\n 1\n \"\"\"\n", "prediction": "def modp(n: int, p: int):\n \"\"\"Return 2^n modulo p (be aware of numerics).\n \"\"\"\n result = 1\n base = 2 % p\n \n while n > 0:\n if n % 2 == 1:\n result = (result * base) % p\n base = (base * base) % p\n n //= 2\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4576260000000001} +{"question": "\n\ndef max_element(l: list):\n \"\"\"Return maximum element in the list.\n >>> max_element([1, 2, 3])\n 3\n >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n \"\"\"\n", "prediction": "def max_element(l: list):\n \"\"\"Return maximum element in the list.\n >>> max_element([1, 2, 3])\n 3\n >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n \"\"\"\n if not l:\n raise ValueError(\"Cannot find maximum of an empty list\")\n \n max_val = l[0]\n for num in l[1:]:\n if num > max_val:\n max_val = num\n \n return max_val", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3752580000000001} +{"question": "\ndef is_happy(s):\n \"\"\"You are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n For example:\n is_happy(a) => False\n is_happy(aa) => False\n is_happy(abcd) => True\n is_happy(aabb) => False\n is_happy(adb) => True\n is_happy(xyy) => False\n \"\"\"\n", "prediction": "def is_happy(s):\n # Check if the string length is at least 3\n if len(s) < 3:\n return False\n \n # Iterate through the string, checking every 3 consecutive letters\n for i in range(len(s) - 2):\n # Get the current 3 consecutive letters\n three_chars = s[i:i+3]\n \n # Check if all 3 characters are distinct\n if len(set(three_chars)) != 3:\n return False\n \n # If we've made it through the loop, the string is happy\n return True", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.44609100000000007} +{"question": "\ndef iscube(a):\n '''\n Write a function that takes an integer a and returns True \n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n Examples:\n iscube(1) ==> True\n iscube(2) ==> False\n iscube(-1) ==> True\n iscube(64) ==> True\n iscube(0) ==> True\n iscube(180) ==> False\n '''\n", "prediction": "def iscube(a):\n if a == 0:\n return True\n \n # Handle negative numbers by taking the absolute value\n a = abs(a)\n \n # Find the cube root of a\n cube_root = round(a ** (1/3))\n \n # Check if the cube of the rounded cube root equals the input\n return cube_root ** 3 == a", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3577920000000001} +{"question": "\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", "prediction": "def 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 return sorted(set(l))", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3614190000000001} +{"question": "\n\ndef fib4(n: int):\n \"\"\"The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fib4(0) -> 0\n fib4(1) -> 0\n fib4(2) -> 2\n fib4(3) -> 0\n fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\n Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n >>> fib4(5)\n 4\n >>> fib4(6)\n 8\n >>> fib4(7)\n 14\n \"\"\"\n", "prediction": "def fib4(n: int):\n if n < 4:\n return 2 if n == 2 else 0\n \n a, b, c, d = 0, 0, 2, 0\n for _ in range(4, n + 1):\n a, b, c, d = b, c, d, a + b + c + d\n \n return d", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.49233000000000005} +{"question": "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", "prediction": "from typing import List\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 return [s for s in strings if substring in s]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.507348} +{"question": "\n\ndef pairs_sum_to_zero(l):\n \"\"\"\n pairs_sum_to_zero takes a list of integers as an input.\n it returns True if there are two distinct elements in the list that\n sum to zero, and False otherwise.\n >>> pairs_sum_to_zero([1, 3, 5, 0])\n False\n >>> pairs_sum_to_zero([1, 3, -2, 1])\n False\n >>> pairs_sum_to_zero([1, 2, 3, 7])\n False\n >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7])\n True\n >>> pairs_sum_to_zero([1])\n False\n \"\"\"\n", "prediction": "def pairs_sum_to_zero(l):\n seen = set()\n for num in l:\n if -num in seen:\n return True\n seen.add(num)\n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5370420000000001} +{"question": "\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", "prediction": "def strange_sort_list(lst):\n if not lst:\n return []\n \n sorted_lst = sorted(lst)\n result = []\n left, right = 0, len(lst) - 1\n \n while left <= right:\n if len(result) % 2 == 0:\n result.append(sorted_lst[left])\n left += 1\n else:\n result.append(sorted_lst[right])\n right -= 1\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5714730000000001} +{"question": "\ndef split_words(txt):\n '''\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n split_words(\"Hello world!\") \u279e [\"Hello\", \"world!\"]\n split_words(\"Hello,world!\") \u279e [\"Hello\", \"world!\"]\n split_words(\"abcdef\") == 3 \n '''\n", "prediction": "def split_words(txt):\n # Check if there are any whitespaces in the text\n if ' ' in txt:\n return txt.split()\n \n # Check if there are any commas in the text\n if ',' in txt:\n return txt.split(',')\n \n # If no whitespaces or commas, count odd-ordered lowercase letters\n odd_count = sum(1 for char in txt.lower() if char.isalpha() and (ord(char) - ord('a')) % 2 == 1)\n return odd_count", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def split_words(txt):\n # Check if there are any whitespaces in the text\n if ' ' in txt:\n return txt.split()\n \n # Check if there are any commas in the text\n if ',' in txt:\n return txt.split(',')\n \n # If no whitespaces or commas, count odd-ordered lowercase letters\n odd_count = sum(1 for char in txt.lower() if char.isalpha() and (ord(char) - ord('a')) % 2 == 1)\n return odd_count.\n \u6d4b\u8bd5: def check(candidate):\n\n assert candidate(\"Hello world!\") == [\"Hello\",\"world!\"]\n assert candidate(\"Hello,world!\") == [\"Hello\",\"world!\"]\n assert candidate(\"Hello world,!\") == [\"Hello\",\"world,!\"]\n assert candidate(\"Hello,Hello,world !\") == [\"Hello,Hello,world\",\"!\"]\n assert candidate(\"abcdef\") == 3\n assert candidate(\"aaabb\") == 2\n assert candidate(\"aaaBb\") == 1\n assert candidate(\"\") == 0\n", "score": 0, "cost": 0.6311340000000002} +{"question": "\ndef exchange(lst1, lst2):\n \"\"\"In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n For example:\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n It is assumed that the input lists will be non-empty.\n \"\"\"\n", "prediction": "def exchange(lst1, lst2):\n \"\"\"\n Determines if it's possible to exchange elements between lst1 and lst2\n to make lst1 a list of only even numbers.\n \"\"\"\n # Count the number of odd numbers in lst1\n odd_count_lst1 = sum(1 for num in lst1 if num % 2 != 0)\n \n # Count the number of even numbers in lst2\n even_count_lst2 = sum(1 for num in lst2 if num % 2 == 0)\n \n # If there are enough even numbers in lst2 to replace all odd numbers in lst1,\n # then it's possible to make lst1 all even\n if even_count_lst2 >= odd_count_lst1:\n return \"YES\"\n else:\n return \"NO\"", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.12041100000000002} +{"question": "\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", "prediction": "def is_bored(S):\n # Split the string into sentences\n sentences = [s.strip() for s in S.replace('!', '.').replace('?', '.').split('.') if s.strip()]\n \n # Count sentences starting with \"I\"\n boredom_count = sum(1 for sentence in sentences if sentence.startswith('I '))\n \n return boredom_count", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.01179} +{"question": "\ndef starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n", "prediction": "def starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n return 10**(n-1) + 8 * 10**(n-2)", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n return 10**(n-1) + 8 * 10**(n-2).\n \u6d4b\u8bd5: def check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate(1) == 1\n assert candidate(2) == 18\n assert candidate(3) == 180\n assert candidate(4) == 1800\n assert candidate(5) == 18000\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\n", "score": 0, "cost": 0.13027200000000003} +{"question": "\ndef get_max_triples(n):\n \"\"\"\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n \"\"\"\n", "prediction": "def get_max_triples(n):\n # Initialize counters for remainders when divided by 3\n count_0 = 0\n count_1 = 0\n count_2 = 0\n\n # Calculate a[i] for each i and count the remainders\n for i in range(1, n + 1):\n value = i * i - i + 1\n remainder = value % 3\n if remainder == 0:\n count_0 += 1\n elif remainder == 1:\n count_1 += 1\n else:\n count_2 += 1\n\n # Calculate the number of valid triples\n result = (\n # All three numbers with remainder 0\n (count_0 * (count_0 - 1) * (count_0 - 2)) // 6 +\n # One number with each remainder\n count_0 * count_1 * count_2 +\n # Two numbers with remainder 1, one with remainder 2\n (count_1 * (count_1 - 1) * count_2) // 2 +\n # Two numbers with remainder 2, one with remainder 1\n (count_2 * (count_2 - 1) * count_1) // 2\n )\n\n return result", "test_case_details": "\u9519\u8bef: .\n \u89e3\u51b3\u65b9\u6848: def get_max_triples(n):\n # Initialize counters for remainders when divided by 3\n count_0 = 0\n count_1 = 0\n count_2 = 0\n\n # Calculate a[i] for each i and count the remainders\n for i in range(1, n + 1):\n value = i * i - i + 1\n remainder = value % 3\n if remainder == 0:\n count_0 += 1\n elif remainder == 1:\n count_1 += 1\n else:\n count_2 += 1\n\n # Calculate the number of valid triples\n result = (\n # All three numbers with remainder 0\n (count_0 * (count_0 - 1) * (count_0 - 2)) // 6 +\n # One number with each remainder\n count_0 * count_1 * count_2 +\n # Two numbers with remainder 1, one with remainder 2\n (count_1 * (count_1 - 1) * count_2) // 2 +\n # Two numbers with remainder 2, one with remainder 1\n (count_2 * (count_2 - 1) * count_1) // 2\n )\n\n return result.\n \u6d4b\u8bd5: def check(candidate):\n\n assert candidate(5) == 1\n assert candidate(6) == 4\n assert candidate(10) == 36\n assert candidate(100) == 53361\n", "score": 0, "cost": 0.256674} +{"question": "\ndef bf(planet1, planet2):\n '''\n There are eight planets in our solar system: the closerst to the Sun \n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2. \n The function should return a tuple containing all planets whose orbits are \n located between the orbit of planet1 and the orbit of planet2, sorted by \n the proximity to the sun. \n The function should return an empty tuple if planet1 or planet2\n are not correct planet names. \n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n '''\n", "prediction": "def bf(planet1, planet2):\n planets = [\"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\"]\n \n if planet1 not in planets or planet2 not in planets:\n return ()\n \n index1 = planets.index(planet1)\n index2 = planets.index(planet2)\n \n if index1 < index2:\n return tuple(planets[index1 + 1 : index2])\n elif index1 > index2:\n return tuple(planets[index2 + 1 : index1])\n else:\n return ()", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.188925} +{"question": "\ndef encrypt(s):\n \"\"\"Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n \"\"\"\n", "prediction": "def encrypt(s):\n result = \"\"\n for char in s:\n if char.isalpha():\n # Determine the base (lowercase or uppercase)\n base = ord('a') if char.islower() else ord('A')\n \n # Calculate the shift (2 * 2 = 4)\n shift = 4\n \n # Apply the rotation\n encrypted_char = chr((ord(char) - base + shift) % 26 + base)\n \n result += encrypted_char\n else:\n # If the character is not a letter, leave it unchanged\n result += char\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.181764} +{"question": "from typing import List, Tuple\n\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n \"\"\" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sum_product([])\n (0, 1)\n >>> sum_product([1, 2, 3, 4])\n (10, 24)\n \"\"\"\n", "prediction": "from typing import List, Tuple\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n \"\"\" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n \"\"\"\n if not numbers:\n return (0, 1)\n \n total_sum = sum(numbers)\n product = 1\n for num in numbers:\n product *= num\n \n return (total_sum, product)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.050820000000000004} +{"question": "\ndef int_to_mini_roman(number):\n \"\"\"\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> int_to_mini_roman(19) == 'xix'\n >>> int_to_mini_roman(152) == 'clii'\n >>> int_to_mini_roman(426) == 'cdxxvi'\n \"\"\"\n", "prediction": "def int_to_mini_roman(number):\n \"\"\"\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n \"\"\"\n roman_symbols = [\n ('m', 1000), ('cm', 900), ('d', 500), ('cd', 400),\n ('c', 100), ('xc', 90), ('l', 50), ('xl', 40),\n ('x', 10), ('ix', 9), ('v', 5), ('iv', 4), ('i', 1)\n ]\n \n result = ''\n for symbol, value in roman_symbols:\n while number >= value:\n result += symbol\n number -= value\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.160062} +{"question": "\ndef odd_count(lst):\n \"\"\"Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> odd_count(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> odd_count(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n \"\"\"\n", "prediction": "def odd_count(lst):\n result = []\n for i, num_string in enumerate(lst):\n odd_count = sum(1 for digit in num_string if int(digit) % 2 != 0)\n output = f\"the number of odd elements {odd_count}n the str{odd_count}ng {odd_count} of the {odd_count}nput.\"\n result.append(output)\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.065772} +{"question": "\n\ndef greatest_common_divisor(a: int, b: int) -> int:\n \"\"\" Return a greatest common divisor of two integers a and b\n >>> greatest_common_divisor(3, 5)\n 1\n >>> greatest_common_divisor(25, 15)\n 5\n \"\"\"\n", "prediction": "def greatest_common_divisor(a: int, b: int) -> int:\n \"\"\" Return a greatest common divisor of two integers a and b\n >>> greatest_common_divisor(3, 5)\n 1\n >>> greatest_common_divisor(25, 15)\n 5\n \"\"\"\n while b:\n a, b = b, a % b\n return abs(a)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.09747600000000001} +{"question": "\n\ndef largest_prime_factor(n: int):\n \"\"\"Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largest_prime_factor(13195)\n 29\n >>> largest_prime_factor(2048)\n 2\n \"\"\"\n", "prediction": "def largest_prime_factor(n: int):\n \"\"\"Return the largest prime factor of n. Assume n > 1 and is not a prime.\"\"\"\n largest_factor = 1\n \n # Handle all factors of 2\n while n % 2 == 0:\n largest_factor = 2\n n = n // 2\n \n # Check for odd factors\n for i in range(3, int(n**0.5) + 1, 2):\n while n % i == 0:\n largest_factor = i\n n = n // i\n \n # If n is still greater than 2, it is the largest prime factor\n if n > 2:\n largest_factor = n\n \n return largest_factor", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.176316} +{"question": "\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", "prediction": "import re\ndef fix_spaces(text):\n # Replace 3 or more consecutive spaces with a single hyphen\n text = re.sub(r' {3,}', '-', text)\n \n # Replace remaining single spaces with underscores\n text = text.replace(' ', '_')\n \n return text", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.019746} +{"question": "from typing import List\n\n\ndef below_zero(operations: List[int]) -> bool:\n \"\"\" You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True\n \"\"\"\n", "prediction": "def below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.015765} +{"question": "from typing import List\n\n\ndef parse_music(music_string: str) -> List[int]:\n \"\"\" Input to this function is a string representing musical notes in a special ASCII format.\n Your task is to parse this string and return list of integers corresponding to how many beats does each\n not last.\n\n Here is a legend:\n 'o' - whole note, lasts four beats\n 'o|' - half note, lasts two beats\n '.|' - quater note, lasts one beat\n\n >>> parse_music('o o| .| o| o| .| .| .| .| o o')\n [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]\n \"\"\"\n", "prediction": "def parse_music(music_string: str) -> List[int]:\n notes = music_string.split()\n result = []\n \n for note in notes:\n if note == 'o':\n result.append(4) # whole note\n elif note == 'o|':\n result.append(2) # half note\n elif note == '.|':\n result.append(1) # quarter note\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.11434200000000001} +{"question": "\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", "prediction": "def will_it_fly(q, w):\n # Check if the list is palindromic (balanced)\n if q != q[::-1]:\n return False\n \n # Check if the sum of elements is less than or equal to the maximum weight\n if sum(q) > w:\n return False\n \n # If both conditions are met, it will fly\n return True", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.024519} +{"question": "\ndef words_in_sentence(sentence):\n \"\"\"\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n \"\"\"\n", "prediction": "def words_in_sentence(sentence):\n def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n words = sentence.split()\n prime_length_words = [word for word in words if is_prime(len(word))]\n return \" \".join(prime_length_words)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.27804900000000005} +{"question": "\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", "prediction": "def largest_smallest_integers(lst):\n negatives = [num for num in lst if num < 0]\n positives = [num for num in lst if num > 0]\n \n largest_negative = max(negatives) if negatives else None\n smallest_positive = min(positives) if positives else None\n \n return (largest_negative, smallest_positive)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3077640000000001} +{"question": "\ndef x_or_y(n, x, y):\n \"\"\"A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for x_or_y(7, 34, 12) == 34\n for x_or_y(15, 8, 5) == 5\n \n \"\"\"\n", "prediction": "def x_or_y(n, x, y):\n \"\"\"A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for x_or_y(7, 34, 12) == 34\n for x_or_y(15, 8, 5) == 5\n \n \"\"\"\n if n < 2:\n return y\n \n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return y\n \n return x", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.2935170000000001} +{"question": "\n\ndef fibfib(n: int):\n \"\"\"The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n \"\"\"\n", "prediction": "def fibfib(n: int):\n if n < 2:\n return 0\n if n == 2:\n return 1\n \n # Initialize the first three values\n a, b, c = 0, 0, 1\n \n # Iterate from 3 to n\n for _ in range(3, n + 1):\n # Calculate the next value\n d = a + b + c\n # Shift the values\n a, b, c = b, c, d\n \n return c", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4017420000000001} +{"question": "\n\ndef same_chars(s0: str, s1: str):\n \"\"\"\n Check if two words have the same characters.\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n True\n >>> same_chars('abcd', 'dddddddabc')\n True\n >>> same_chars('dddddddabc', 'abcd')\n True\n >>> same_chars('eabcd', 'dddddddabc')\n False\n >>> same_chars('abcd', 'dddddddabce')\n False\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')\n False\n \"\"\"\n", "prediction": "def same_chars(s0: str, s1: str):\n # Convert strings to sets of unique characters\n set0 = set(s0)\n set1 = set(s1)\n \n # Compare the sets\n return set0 == set1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3360420000000001} +{"question": "\ndef even_odd_palindrome(n):\n \"\"\"\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Example 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\n Example 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n \"\"\"\n", "prediction": "def even_odd_palindrome(n):\n even_count = 0\n odd_count = 0\n \n for num in range(1, n + 1):\n if is_palindrome(num):\n if num % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n \n return (even_count, odd_count)\ndef is_palindrome(num):\n return str(num) == str(num)[::-1]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3910320000000001} +{"question": "\n\ndef encode_shift(s: str):\n \"\"\"\n returns encoded string by shifting every character by 5 in the alphabet.\n \"\"\"\n return \"\".join([chr(((ord(ch) + 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\n\ndef decode_shift(s: str):\n \"\"\"\n takes as input string encoded with encode_shift function. Returns decoded string.\n \"\"\"\n", "prediction": "def decode_shift(s: str):\n \"\"\"\n takes as input string encoded with encode_shift function. Returns decoded string.\n \"\"\"\n return \"\".join([chr(((ord(ch) - 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3799260000000001} +{"question": "\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", "prediction": "def solve(s):\n # Check if the string contains any letters\n if not any(c.isalpha() for c in s):\n # If no letters, reverse the entire string\n return s[::-1]\n \n # If there are letters, process each character\n result = []\n for char in s:\n if char.isalpha():\n # If it's a letter, reverse its case\n result.append(char.swapcase())\n else:\n # If it's not a letter, keep it as is\n result.append(char)\n \n # Join the characters and return the result\n return ''.join(result)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4276740000000001} +{"question": "\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", "prediction": "def common(l1: list, l2: list):\n \"\"\"Return sorted unique common elements for two lists.\"\"\"\n # Convert lists to sets to get unique elements and find intersection\n common_elements = set(l1) & set(l2)\n \n # Convert back to a sorted list\n return sorted(common_elements)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3116490000000001} +{"question": "\n\ndef is_palindrome(text: str):\n \"\"\"\n Checks if given string is a palindrome\n >>> is_palindrome('')\n True\n >>> is_palindrome('aba')\n True\n >>> is_palindrome('aaaaa')\n True\n >>> is_palindrome('zbcd')\n False\n \"\"\"\n", "prediction": "def is_palindrome(text: str):\n \"\"\"\n Checks if given string is a palindrome\n >>> is_palindrome('')\n True\n >>> is_palindrome('aba')\n True\n >>> is_palindrome('aaaaa')\n True\n >>> is_palindrome('zbcd')\n False\n \"\"\"\n # Convert the string to lowercase and remove non-alphanumeric characters\n cleaned_text = ''.join(char.lower() for char in text if char.isalnum())\n \n # Compare the cleaned string with its reverse\n return cleaned_text == cleaned_text[::-1]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.3699840000000001} +{"question": "\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", "prediction": "def 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 if len(array) <= 1:\n return array.copy()\n \n sorted_array = sorted(array)\n \n if (array[0] + array[-1]) % 2 == 1:\n return sorted_array\n else:\n return sorted_array[::-1]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5152950000000001} +{"question": "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", "prediction": "from typing import List\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n if len(numbers) < 2:\n raise ValueError(\"Input list must have at least two elements\")\n\n min_val = min(numbers)\n max_val = max(numbers)\n\n if min_val == max_val:\n return [0.0] * len(numbers)\n\n scale = max_val - min_val\n return [(x - min_val) / scale for x in numbers]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.4688280000000001} +{"question": "\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", "prediction": "def monotonic(l: list):\n if len(l) <= 1:\n return True\n \n # Check if the list is increasing\n increasing = all(l[i] <= l[i+1] for i in range(len(l) - 1))\n \n # Check if the list is decreasing\n decreasing = all(l[i] >= l[i+1] for i in range(len(l) - 1))\n \n # Return True if the list is either increasing or decreasing\n return increasing or decreasing", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5201790000000001} +{"question": "\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", "prediction": "def find_max(words):\n def count_unique_chars(word):\n return len(set(word))\n \n if not words:\n return \"\"\n \n return max(words, key=lambda x: (count_unique_chars(x), -ord(x[0])))", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5859270000000002} +{"question": "\ndef minPath(grid, k):\n \"\"\"\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n \"\"\"\n", "prediction": "def minPath(grid, k):\n n = len(grid)\n min_path = [float('inf')] * k\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # right, down, left, up\n \n def dfs(x, y, path, length):\n nonlocal min_path\n \n if length == k:\n if path < min_path:\n min_path = path[:]\n return\n \n for dx, dy in directions:\n nx, ny = x + dx, y + dy\n if 0 <= nx < n and 0 <= ny < n:\n new_path = path + [grid[nx][ny]]\n if new_path < min_path[:length+1]:\n dfs(nx, ny, new_path, length + 1)\n \n for i in range(n):\n for j in range(n):\n dfs(i, j, [grid[i][j]], 1)\n \n return min_path", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6920730000000002} +{"question": "\n\ndef sort_even(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sort_even([1, 2, 3])\n [1, 2, 3]\n >>> sort_even([5, 6, 3, 4])\n [3, 6, 5, 4]\n \"\"\"\n", "prediction": "def sort_even(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n \"\"\"\n # Extract elements at even indices\n even_elements = l[::2]\n \n # Sort the even elements\n even_elements.sort()\n \n # Create a new list with the same length as the input list\n result = [0] * len(l)\n \n # Fill in the odd indices with original values\n result[1::2] = l[1::2]\n \n # Fill in the even indices with sorted values\n result[::2] = even_elements\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5656080000000001} +{"question": "\ndef cycpattern_check(a , b):\n \"\"\"You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word\n cycpattern_check(\"abcd\",\"abd\") => False\n cycpattern_check(\"hello\",\"ell\") => True\n cycpattern_check(\"whassup\",\"psus\") => False\n cycpattern_check(\"abab\",\"baa\") => True\n cycpattern_check(\"efef\",\"eeff\") => False\n cycpattern_check(\"himenss\",\"simen\") => True\n\n \"\"\"\n", "prediction": "def cycpattern_check(a, b):\n if len(b) > len(a):\n return False\n \n # Double the second string to consider all rotations\n b_doubled = b + b\n \n # Check if any substring of b_doubled (of length b) is in a\n for i in range(len(b)):\n if b_doubled[i:i+len(b)] in a:\n return True\n \n return False", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5770230000000002} +{"question": "from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separate_paren_groups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n \"\"\"\n", "prediction": "from typing import List\ndef separate_paren_groups(paren_string: str) -> List[str]:\n result = []\n current_group = \"\"\n depth = 0\n \n for char in paren_string:\n if char == '(':\n depth += 1\n current_group += char\n elif char == ')':\n depth -= 1\n current_group += char\n \n if depth == 0:\n result.append(current_group)\n current_group = \"\"\n # Ignore spaces\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6193350000000002} +{"question": "\n\ndef below_threshold(l: list, t: int):\n \"\"\"Return True if all numbers in the list l are below threshold t.\n >>> below_threshold([1, 2, 4, 10], 100)\n True\n >>> below_threshold([1, 20, 4, 10], 5)\n False\n \"\"\"\n", "prediction": "def below_threshold(l: list, t: int):\n \"\"\"Return True if all numbers in the list l are below threshold t.\n >>> below_threshold([1, 2, 4, 10], 100)\n True\n >>> below_threshold([1, 20, 4, 10], 5)\n False\n \"\"\"\n return all(num < t for num in l)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5412720000000001} +{"question": "\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", "prediction": "def sorted_list_sum(lst):\n # Filter out strings with odd lengths\n even_length_strings = [s for s in lst if len(s) % 2 == 0]\n \n # Sort the remaining strings by length, then alphabetically\n sorted_strings = sorted(even_length_strings, key=lambda x: (len(x), x))\n \n return sorted_strings", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5909310000000002} +{"question": "\ndef tri(n):\n \"\"\"Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n \"\"\"\n", "prediction": "def tri(n):\n \"\"\"\n Calculate the Tribonacci sequence up to n+1 terms.\n \n Args:\n n (int): A non-negative integer representing the number of terms to calculate.\n \n Returns:\n list: A list containing the first n+1 numbers of the Tribonacci sequence.\n \"\"\"\n sequence = [1] # Initialize with tri(0) = 1 (assumed, as it's not specified in the problem)\n \n if n >= 1:\n sequence.append(3) # tri(1) = 3\n \n for i in range(2, n+1):\n if i % 2 == 0:\n # For even n\n sequence.append(1 + i // 2)\n else:\n # For odd n\n # We need to calculate tri(n+1) first\n next_term = 1 + (i+1) // 2 if (i+1) % 2 == 0 else 0 # placeholder for tri(n+1)\n current_term = sequence[-1] + sequence[-2] + next_term\n sequence.append(current_term)\n \n return sequence", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6839970000000002} +{"question": "\ndef rounded_avg(n, m):\n \"\"\"You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n Example:\n rounded_avg(1, 5) => \"0b11\"\n rounded_avg(7, 5) => -1\n rounded_avg(10, 20) => \"0b1111\"\n rounded_avg(20, 33) => \"0b11010\"\n \"\"\"\n", "prediction": "def rounded_avg(n, m):\n if n > m:\n return -1\n \n # Calculate the sum of integers from n to m\n total = sum(range(n, m + 1))\n \n # Calculate the count of numbers\n count = m - n + 1\n \n # Calculate the average and round it to the nearest integer\n avg = round(total / count)\n \n # Convert the rounded average to binary\n binary = bin(avg)\n \n return binary", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6094650000000003} +{"question": "\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", "prediction": "def closest_integer(value):\n # Convert the string to a float\n num = float(value)\n \n # Get the fractional part\n frac = abs(num) - int(abs(num))\n \n # If the fractional part is exactly 0.5, round away from zero\n if frac == 0.5:\n return int(num + (1 if num > 0 else -1))\n \n # Otherwise, use the built-in round function and convert to int\n return int(round(num))", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6044220000000002} +{"question": "\ndef sort_array(arr):\n \"\"\"\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n \"\"\"\n", "prediction": "def sort_array(arr):\n return sorted(arr, key=lambda x: (bin(abs(x)).count('1'), x))", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6476640000000002} +{"question": "\ndef get_row(lst, x):\n \"\"\"\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \n Examples:\n get_row([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n get_row([], 1) == []\n get_row([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n \"\"\"\n", "prediction": "def get_row(lst, x):\n result = []\n for row_index, row in enumerate(lst):\n for col_index, value in enumerate(row):\n if value == x:\n result.append((row_index, col_index))\n \n # Sort the result list\n result.sort(key=lambda coord: (coord[0], -coord[1]))\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6987030000000002} +{"question": "\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", "prediction": "def total_match(lst1, lst2):\n total_chars_lst1 = sum(len(s) for s in lst1)\n total_chars_lst2 = sum(len(s) for s in lst2)\n \n if total_chars_lst1 <= total_chars_lst2:\n return lst1\n else:\n return lst2", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6139470000000002} +{"question": "\ndef solution(lst):\n \"\"\"Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n \"\"\"\n", "prediction": "def solution(lst):\n \"\"\"Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n \"\"\"\n return sum(num for i, num in enumerate(lst) if i % 2 == 0 and num % 2 != 0)", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6529080000000003} +{"question": "\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", "prediction": "def generate_integers(a, b):\n # Ensure a is the smaller number and b is the larger\n start = min(a, b)\n end = max(a, b)\n \n # Generate a list of even digits between start and end\n result = [num for num in range(start, end + 1) if num % 2 == 0 and num < 10]\n \n # Sort the list in ascending order (though it should already be sorted)\n result.sort()\n \n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6705990000000003} +{"question": "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", "prediction": "from typing import List, Tuple\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n numbers.sort() # Sort the list in ascending order\n min_diff = float('inf')\n closest_pair = None\n\n for i in range(len(numbers) - 1):\n diff = numbers[i + 1] - numbers[i]\n if diff < min_diff:\n min_diff = diff\n closest_pair = (numbers[i], numbers[i + 1])\n\n return closest_pair", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6250710000000002} +{"question": "\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", "prediction": "import math\ndef triangle_area(a, b, c):\n # Check if the sides form a valid triangle\n if a + b > c and b + c > a and c + a > b:\n # Calculate semi-perimeter\n s = (a + b + c) / 2\n \n # Calculate area using Heron's formula\n area = math.sqrt(s * (s - a) * (s - b) * (s - c))\n \n # Round to 2 decimal points and return\n return round(area, 2)\n else:\n # If not a valid triangle, return -1\n return -1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6582540000000002} +{"question": "\ndef f(n):\n \"\"\" Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n Example:\n f(5) == [1, 2, 6, 24, 15]\n \"\"\"\n", "prediction": "def f(n):\n result = []\n for i in range(1, n + 1):\n if i % 2 == 0:\n # For even indices, calculate factorial\n factorial = 1\n for j in range(1, i + 1):\n factorial *= j\n result.append(factorial)\n else:\n # For odd indices, calculate sum\n sum_to_i = sum(range(1, i + 1))\n result.append(sum_to_i)\n return result", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6647490000000003} +{"question": "from typing import List\n\n\ndef all_prefixes(string: str) -> List[str]:\n \"\"\" Return list of all prefixes from shortest to longest of the input string\n >>> all_prefixes('abc')\n ['a', 'ab', 'abc']\n \"\"\"\n", "prediction": "from typing import List\ndef all_prefixes(string: str) -> List[str]:\n \"\"\" Return list of all prefixes from shortest to longest of the input string\n >>> all_prefixes('abc')\n ['a', 'ab', 'abc']\n \"\"\"\n return [string[:i+1] for i in range(len(string))]", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.5946210000000002} +{"question": "\ndef any_int(x, y, z):\n '''\n Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n \n Examples\n any_int(5, 2, 7) \u279e True\n \n any_int(3, 2, 2) \u279e False\n\n any_int(3, -2, 1) \u279e True\n \n any_int(3.6, -2.2, 2) \u279e False\n \n\n \n '''\n", "prediction": "def any_int(x, y, z):\n if not (isinstance(x, int) and isinstance(y, int) and isinstance(z, int)):\n return False\n \n return x == y + z or y == x + z or z == x + y", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6419910000000002} +{"question": "\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", "prediction": "def 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 # Ensure x is not greater than y\n if x > y:\n return -1\n \n # Start from y and move downwards\n for num in range(y, x - 1, -1):\n if num % 2 == 0:\n return num\n \n # If no even number is found\n return -1", "test_case_details": "\u89e3\u51b3\u65b9\u6848\u901a\u8fc7\u4e86\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002", "score": 1, "cost": 0.6764040000000002} diff --git a/io_humaneval.py b/io_humaneval.py new file mode 100644 index 000000000..7507c5910 --- /dev/null +++ b/io_humaneval.py @@ -0,0 +1,53 @@ +from examples.ags.scripts.operator import Operator +from examples.ags.scripts.graph import SolveGraph +from examples.ags.benchmark.humaneval import humaneval_evaluation +from examples.ags.scripts.operator_an import GenerateOp +from metagpt.actions.action_node import ActionNode +from metagpt.configs.models_config import ModelsConfig +from metagpt.llm import LLM +from pydantic import BaseModel, Field + +HUMANEVAL_PROMPT_IO = """ +{question}\nGenerate an answer to this question, without any additional test cases. +""" + +class GenerateOp(BaseModel): + solution: str = Field(default="", description="Python Solution For This Question.") + +class Generate(Operator): + def __init__(self, llm: LLM, name: str = "Generate"): + super().__init__(name, llm) + + async def __call__(self, problem, function_name, mode: str = None): + prompt = HUMANEVAL_PROMPT_IO.format(question=problem) + fill_kwargs = {"context": prompt, "llm": self.llm, "function_name": function_name} + if mode: + fill_kwargs["mode"] = mode + node = await ActionNode.from_pydantic(GenerateOp).fill(**fill_kwargs) + response = node.instruct_content.model_dump() + return response + +class IOSolveGraph(SolveGraph): + def __init__(self, name: str, llm_config, dataset: str): + super().__init__(name, llm_config, dataset) + self.cot_generate = Generate(self.llm) + + async def __call__(self, problem, function_name): + solution = await self.cot_generate(problem, function_name, mode="code_fill") + return solution["solution"], self.llm.cost_manager.total_cost + +if __name__ == "__main__": + async def main(): + # llm_config = ModelsConfig.default().get("gpt-4o-mini") + # llm_config = ModelsConfig.default().get("gpt-4o") + # llm_config = ModelsConfig.default().get("deepseek-chat") + llm_config = ModelsConfig.default().get("claude-3-5-sonnet-20240620") + graph = IOSolveGraph(name="Io", llm_config=llm_config, dataset="HumanEval") + file_path = "examples/ags/data/baseline_data/human-eval.jsonl" + samples = 33 # 33/131 + path = "examples/ags/data/baselines/general/humaneval" + score = await humaneval_evaluation(graph, file_path, samples, path,test=True) + return score + + import asyncio + asyncio.run(main()) diff --git a/metagpt/utils/token_counter.py b/metagpt/utils/token_counter.py index 6448f7faf..fe4da9a6a 100644 --- a/metagpt/utils/token_counter.py +++ b/metagpt/utils/token_counter.py @@ -360,6 +360,7 @@ def count_input_tokens(messages, model="gpt-3.5-turbo-0125"): "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-mini", + "claude-3-5-sonnet-20240620" }: tokens_per_message = 3 # # every reply is primed with <|start|>assistant<|message|> tokens_per_name = 1