{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
" \n",
"
\n",
" Docs\n",
" |\n",
" GitHub\n",
" |\n",
" Community\n",
"
| \n", " | Unnamed: 0 | \n", "task_id | \n", "prompt | \n", "canonical_solution | \n", "test | \n", "entry_point | \n", "readable | \n", "solution | \n", "
|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "HumanEval/0 | \n", "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 | \n", "for idx, elem in enumerate(numbers):\\n for idx2, elem2 in enumerate(numbers):\\n if idx != idx2:\\n distance = abs(elem - elem2)\\n if distance < threshold:\\n return True\\n\\n return False\\n | \n", "\\n\\nMETADATA = {\\n 'author': 'jt',\\n 'dataset': 'test'\\n}\\n\\n\\ndef check(candidate):\\n assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True\\n assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False\\n assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True\\n assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) == False\\n assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) == True\\n assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) == True\\n assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) == False\\n\\n | \n", "has_close_elements | \n", "True | \n", "for idx, elem in enumerate(numbers):\\n for idx2, elem2 in enumerate(numbers):\\n if idx != idx2:\\n distance = abs(elem - elem2)\\n if distance < threshold:\\n return True\\n\\n return False\\n | \n", "
| 1 | \n", "1 | \n", "HumanEval/1 | \n", "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 | \n", "result = []\\n current_string = []\\n current_depth = 0\\n\\n for c in paren_string:\\n if c == '(':\\n current_depth += 1\\n current_string.append(c)\\n elif c == ')':\\n current_depth -= 1\\n current_string.append(c)\\n\\n if current_depth == 0:\\n result.append(''.join(current_string))\\n current_string.clear()\\n\\n return result\\n | \n", "\\n\\nMETADATA = {\\n 'author': 'jt',\\n 'dataset': 'test'\\n}\\n\\n\\ndef check(candidate):\\n assert candidate('(()()) ((())) () ((())()())') == [\\n '(()())', '((()))', '()', '((())()())'\\n ]\\n assert candidate('() (()) ((())) (((())))') == [\\n '()', '(())', '((()))', '(((())))'\\n ]\\n assert candidate('(()(())((())))') == [\\n '(()(())((())))'\\n ]\\n assert candidate('( ) (( )) (( )( ))') == ['()', '(())', '(()())']\\n | \n", "separate_paren_groups | \n", "True | \n", "result = []\\n current_string = []\\n current_depth = 0\\n\\n for c in paren_string:\\n if c == '(':\\n current_depth += 1\\n current_string.append(c)\\n elif c == ')':\\n current_depth -= 1\\n current_string.append(c)\\n\\n if current_depth == 0:\\n result.append(''.join(current_string))\\n current_string.clear()\\n\\n return result\\n | \n", "
| 2 | \n", "2 | \n", "HumanEval/2 | \n", "\\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 | \n", "return number % 1.0\\n | \n", "\\n\\nMETADATA = {\\n 'author': 'jt',\\n 'dataset': 'test'\\n}\\n\\n\\ndef check(candidate):\\n assert candidate(3.5) == 0.5\\n assert abs(candidate(1.33) - 0.33) < 1e-6\\n assert abs(candidate(123.456) - 0.456) < 1e-6\\n | \n", "truncate_number | \n", "False | \n", "return((lambda x: (lambda y: y(x))(lambda f: (lambda x: f(lambda v: x(x)(v)))(lambda y: f(lambda u: y(y)(u)))))(lambda f: (lambda x: f(lambda v: x(x)(v)))(lambda y: f(lambda u: y(y)(u))))(lambda f: lambda x: x if x == 0 else f(x - 1) + 1)(number % 1.0)) | \n", "
| 3 | \n", "3 | \n", "HumanEval/3 | \n", "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 | \n", "balance = 0\\n\\n for op in operations:\\n balance += op\\n if balance < 0:\\n return True\\n\\n return False\\n | \n", "\\n\\nMETADATA = {\\n 'author': 'jt',\\n 'dataset': 'test'\\n}\\n\\n\\ndef check(candidate):\\n assert candidate([]) == False\\n assert candidate([1, 2, -3, 1, 2, -3]) == False\\n assert candidate([1, 2, -4, 5, 6]) == True\\n assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False\\n assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == True\\n assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True\\n | \n", "below_zero | \n", "True | \n", "balance = 0\\n\\n for op in operations:\\n balance += op\\n if balance < 0:\\n return True\\n\\n return False\\n | \n", "
| 4 | \n", "4 | \n", "HumanEval/4 | \n", "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 | \n", "mean = sum(numbers) / len(numbers)\\n return sum(abs(x - mean) for x in numbers) / len(numbers)\\n | \n", "\\n\\nMETADATA = {\\n 'author': 'jt',\\n 'dataset': 'test'\\n}\\n\\n\\ndef check(candidate):\\n assert abs(candidate([1.0, 2.0, 3.0]) - 2.0/3.0) < 1e-6\\n assert abs(candidate([1.0, 2.0, 3.0, 4.0]) - 1.0) < 1e-6\\n assert abs(candidate([1.0, 2.0, 3.0, 4.0, 5.0]) - 6.0/5.0) < 1e-6\\n\\n | \n", "mean_absolute_deviation | \n", "True | \n", "mean = sum(numbers) / len(numbers)\\n return sum(abs(x - mean) for x in numbers) / len(numbers)\\n | \n", "
| \n", " | Unnamed: 0 | \n", "task_id | \n", "input | \n", "canonical_solution | \n", "test | \n", "entry_point | \n", "readable | \n", "output | \n", "readability | \n", "
|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "79 | \n", "HumanEval/79 | \n", "\\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 | \n", "return \"db\" + bin(decimal)[2:] + \"db\"\\n | \n", "def check(candidate):\\n\\n # Check some simple cases\\n assert candidate(0) == \"db0db\"\\n assert candidate(32) == \"db100000db\"\\n assert candidate(103) == \"db1100111db\"\\n assert candidate(15) == \"db1111db\", \"This prints if this assert fails 1 (good for debugging!)\"\\n\\n # Check some edge cases that are easy to work out by hand.\\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\\n\\n | \n", "decimal_to_binary | \n", "False | \n", "def obscure_code(decimal):\\n binary = bin(decimal)\\n binary = binary[2:]\\n prefix = \"db\"\\n suffix = \"db\"\\n result = prefix + binary + suffix\\n return result\\n\\nprint(obscure_code(10)) | \n", "readable | \n", "
| \n", " | input | \n", "output | \n", "label | \n", "explanation | \n", "
|---|---|---|---|---|
| 0 | \n", "\\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 | \n", "def obscure_code(decimal):\\n binary = bin(decimal)\\n binary = binary[2:]\\n prefix = \"db\"\\n suffix = \"db\"\\n result = prefix + binary + suffix\\n return result\\n\\nprint(obscure_code(10)) | \n", "readable | \n", "The code is quite straightforward and easy to understand. It starts by converting the decimal number to binary using the built-in bin() function. The result of this function is a string that starts with '0b', so the next line removes the first two characters. Then, it defines a prefix and a suffix, both 'db', and concatenates them with the binary string. The final result is returned. The function name 'obscure_code' is not very descriptive and does not match the task assignment 'decimal_to_binary', which could lead to confusion. However, the code inside the function is simple and readable. | \n", "
| 1 | \n", "\\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 | \n", "new_lst = []\\n for word in sentence.split():\\n flg = 0\\n if len(word) == 1:\\n flg = 1\\n for i in range(2, len(word)):\\n if len(word)%i == 0:\\n flg = 1\\n if flg == 0 or len(word) == 2:\\n new_lst.append(word)\\n return \" \".join(new_lst)\\n | \n", "unreadable | \n", "The code is relatively simple and straightforward, but there are a few areas where it could be improved for readability. The variable names 'new_lst' and 'flg' are not very descriptive, which can make it harder to understand what the code is doing. The logic for checking if a word's length is a prime number is also a bit convoluted and could be simplified or at least commented for clarity. The code lacks function definition and indentation, which are crucial for readability and understanding the flow of the code. The code also lacks error handling and doesn't check if the input is valid according to the constraints mentioned in the task assignment. Overall, while the code is not completely unreadable, it could definitely be improved for better readability. | \n", "
| 2 | \n", "\\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 | \n", "l = len(string)\\n if l == 0 or l == 1:\\n return False\\n for i in range(2, l):\\n if l % i == 0:\\n return False\\n return True\\n | \n", "readable | \n", "The code is quite straightforward and easy to understand. It first calculates the length of the string. Then it checks if the length is 0 or 1, in which case it returns False as neither 0 nor 1 are prime numbers. After that, it enters a loop where it checks if the length of the string is divisible by any number in the range from 2 to the length of the string (exclusive). If it finds a number that divides the length, it returns False as it means the length is not a prime number. If it doesn't find any such number, it returns True, indicating that the length is a prime number. The code is simple and does not contain any unnecessary complexity. The variable names could be more descriptive, but overall, the code is readable. | \n", "
| 3 | \n", "from typing import List, Tuple\\n\\n\\ndef rolling_max(numbers: List[int]) -> List[int]:\\n \"\"\" From a given list of integers, generate a list of rolling maximum element found until given moment\\n in the sequence.\\n >>> rolling_max([1, 2, 3, 2, 3, 4, 2])\\n [1, 2, 3, 3, 3, 4, 4]\\n \"\"\"\\n | \n", "running_max = None\\n result = []\\n\\n for n in numbers:\\n if running_max is None:\\n running_max = n\\n else:\\n running_max = max(running_max, n)\\n\\n result.append(running_max)\\n\\n return result\\n | \n", "readable | \n", "The code is well-structured and follows a logical flow. It starts by initializing a variable 'running_max' to None and an empty list 'result'. It then iterates over the list of numbers. For each number, it checks if 'running_max' is None (which it will be for the first number), and if so, sets 'running_max' to that number. Otherwise, it sets 'running_max' to the maximum of 'running_max' and the current number. It then appends 'running_max' to the 'result' list. Finally, it returns the 'result' list. The code is simple and straightforward, making it easy to understand what it's doing. The function name and docstring also clearly describe what the function does, which aids in readability. | \n", "
| 4 | \n", "\\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 | \n", "return list(map(lambda pair: pair[0] * pair[1], list(filter(lambda pair: pair[0] != 0, list(zip(list(range(len(xs))), xs)))))) | \n", "unreadable | \n", "The code is trying to calculate the derivative of a polynomial. It does this by creating a list of tuples where each tuple contains the index and the corresponding value from the input list. It then filters out the tuples where the index is 0, because the derivative of a constant term is 0. Finally, it uses map to multiply each index with its corresponding value, which gives the derivative of each term in the polynomial. While the logic is correct, the implementation is quite complex and hard to read. It uses a lot of nested functions and list comprehensions, which makes it difficult to understand what each part of the code is doing. A more readable implementation would break this down into multiple steps and use more descriptive variable names. | \n", "