version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Evol
Evol_3355_I
You are tasked with designing a system in a programming language of your choice to determine if a given string is a valid palindrome. Your software should be capable of handling multiple strings simultaneously and return a response for each string indicating whether it is a palindrome ("yes") or not ("no"). Additionall...
import re def is_palindrome(s): """ Determines if a given string is a palindrome. Spaces, punctuation, and casing are ignored. Parameters: s (str): The string to check. Returns: str: 'yes' if the string is a palindrome, 'no' otherwise. """ if not isinstance(s, str): raise ...
from solution import is_palindrome, check_palindromes import pytest def test_is_palindrome(): assert is_palindrome("A man, a plan, a canal, Panama") == 'yes' assert is_palindrome("racecar") == 'yes' assert is_palindrome("Hello, World!") == 'no' assert is_palindrome("") == 'yes' assert is_palindrome...
[ { "docstring": "Determines if a given string is a palindrome.\nSpaces, punctuation, and casing are ignored.\n\nParameters:\ns (str): The string to check.\n\nReturns:\nstr: 'yes' if the string is a palindrome, 'no' otherwise.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindr...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome.\n Handles spaces, punctuation, and mixed casing.\n \n Ar...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003355", "row_id": 3355, "seed_ids": "[34294]" }
0.76546
Evol_3355
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
530dbf7fbdadffe7cc25162e5f6e43291f82f51d
29299fe9fbcd61f09e9c7612509f8af80a32ac47
v1.0
instruct
Evol
Evol_3362_I
Formulate a Python script module that defines a function `is_prime(num)` to check if a number is prime and a function `generate_prime_numbers(n)` to generate a list of the first `n` prime numbers. Additionally, implement a function `is_palindrome(number)` to verify if a given number is a palindrome and a function `prim...
def is_prime(num): """ Check if a number is prime. """ if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def generate_prime_numbers(n): """ Generate a list of the first n prime numbers. """ prim...
from solution import ( is_prime, generate_prime_numbers, is_palindrome, prime_palindromes ) def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(25) == False def test_generate_prime_number...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate a list of the first n prime numbers.", "function_declaration": "def generate_prime_numbers(n):", "function_na...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n :param num: Integer, the number to check.\n :return: Boolean, True if the number is prime, ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003362", "row_id": 3362, "seed_ids": "[26645]" }
0.627988
Evol_3362
I
[ "is_prime", "generate_prime_numbers", "is_palindrome", "prime_palindromes" ]
4
[ [ "generate_prime_numbers", "is_prime" ], [ "prime_palindromes", "is_palindrome" ], [ "prime_palindromes", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
48a715496990795668cbe87777de7b94022e59ae
c4b1c81be9f54f88d242a6bfaff4af0956be1be0
v1.0
instruct
Evol
Evol_3372_I
Create a function that takes a list of mixed data types (integers and strings) and returns a dictionary with two keys: 'integers' and 'strings'. The value for each key should be a sorted list (in ascending order) containing only the integers or strings from the input list. Do not use built-in sorting functions. Examp...
def insertion_sort(arr): """ Sorts an array using the insertion sort algorithm. """ for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr def segregate_and_sor...
from solution import segregate_and_sort def test_segregate_and_sort_mixed_list(): input_list = [3, "apple", 1, "banana", 2, "cherry"] expected_output = { "integers": [1, 2, 3], "strings": ["apple", "banana", "cherry"] } assert segregate_and_sort(input_list) == expected_output def test_...
[ { "docstring": "Sorts an array using the insertion sort algorithm.", "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": "Segregates a mixed list into integers and strings,\nand returns a dictionary with two sorte...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def mixed_type_sort(my_list):\n \"\"\"\n Takes a list of mixed data types (integers and strings) and returns a dictionary \n with sorted lists of integers...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003372", "row_id": 3372, "seed_ids": "[5636]" }
0.719137
Evol_3372
I
[ "insertion_sort", "segregate_and_sort" ]
2
[ [ "segregate_and_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86464ac7e230be5d5c2e3e0580ba06873ffce5a4
9a6eeffba2e0efd6598d837bca19640de9286735
v1.0
instruct
Evol
Evol_3375_I
Write a Python function that identifies the longest increasing subsequence within a given list of integers. The function must efficiently handle lists that may include negative integers and have a size up to 10^5 elements without exceeding time and space complexity constraints. The returned subsequence should be a lis...
def longest_increasing_subsequence(arr): """ Finds the longest increasing subsequence in a list of integers. Returns the subsequence and its length as a tuple. """ from bisect import bisect_left if not arr: return [], 0 n = len(arr) # Will store the indices of the small...
from solution import longest_increasing_subsequence, process_multiple_requests def test_single_request(): arr = [10, 9, 2, 5, 3, 7, 101, 18] expected_subsequence = [2, 3, 7, 18] expected_length = 4 subsequence, length = longest_increasing_subsequence(arr) assert subsequence == expected_subsequence ...
[ { "docstring": "Finds the longest increasing subsequence in a list of integers.\nReturns the subsequence and its length as a tuple.", "function_declaration": "def longest_increasing_subsequence(arr):", "function_name": "longest_increasing_subsequence", "parameter_list": "(arr)" }, { "docstri...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from bisect import bisect_left\n\ndef longest_increasing_subsequence(nums):\n \"\"\"\n Finds the longest increasing subsequence (LIS) in the given list of in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003375", "row_id": 3375, "seed_ids": "[46775]" }
0.740513
Evol_3375
I
[ "longest_increasing_subsequence", "process_multiple_requests" ]
2
[ [ "process_multiple_requests", "longest_increasing_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ff0b89ff683a54ebfd2b4811113c89eedc7ef25
596b726e7aae110b24b51ebe8d6dc394429a444f
v1.0
instruct
Evol
Evol_3378_I
Write a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. If the input list is empty or has no prime numbers, return an empty list. Additionally, handle and fix the error in the given code snippet: ```python def is_prime(num): if num <= ...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def extract_primes(numbers): primes = [] for num in numbers: if is_prime(num): primes.append(num) return primes
from solution import is_prime, extract_primes def test_is_prime_with_prime_numbers(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(5) is True assert is_prime(7) is True def test_is_prime_with_non_prime_numbers(): assert is_prime(0) is False assert is_prime(1) is False ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def extract_primes(numbers):", "function_name": "extract_primes", "parameter_list": "(numbers)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determine if a number is prime.\n :param num: An integer.\n :return: True if the integer is a prime number, else False.\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003378", "row_id": 3378, "seed_ids": "[18985]" }
0.698358
Evol_3378
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2cbd62c1bc7223ceecc962bced9b2a41f569a509
a13bbb8f030bf63546d3ad4eede84e01a16515ff
v1.0
instruct
Evol
Evol_3394_I
**Develop a function to compute the Gini Impurity for a given dataset. The dataset is provided as a list of classes. Explain how the Gini Impurity helps in the process of splitting nodes in a decision tree classifier. Given the dataset below, calculate the Gini Impurity before and after splitting based on the threshold...
from collections import Counter def gini_impurity(dataset): """ Calculate the Gini Impurity for a given dataset. Args: dataset (list): List of classes. Returns: float: Gini Impurity """ total = len(dataset) if total == 0: return 0 class_counts = Counter(da...
from solution import gini_impurity, split_and_calculate_gini def test_gini_impurity(): assert gini_impurity([1, 1, 1]) == 0 assert gini_impurity([1, 1, 2, 2]) == 1 - 0.5*0.5 - 0.5*0.5 assert gini_impurity([1, 2, 2, 3]) == 1 - (1/4)**2 - (2/4)**2 - (1/4)**2 def test_split_and_calculate_gini(): dataset ...
[ { "docstring": "Calculate the Gini Impurity for a given dataset.\n\nArgs:\ndataset (list): List of classes.\n\nReturns:\nfloat: Gini Impurity", "function_declaration": "def gini_impurity(dataset):", "function_name": "gini_impurity", "parameter_list": "(dataset)" }, { "docstring": "Calculate ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def gini_impurity(classes):\n \"\"\"\n Computes the Gini Impurity for a given dataset.\n Gini Impurity = 1 - sum of (probability of each class)^2\n :pa...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003394", "row_id": 3394, "seed_ids": "[45447]" }
0.385147
Evol_3394
I
[ "gini_impurity", "split_and_calculate_gini" ]
2
[ [ "split_and_calculate_gini", "gini_impurity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f26ee5be3a249b076680a0b30eca22bfe05edd4
d0597500d411dc6c4735ed66cf342204faa113cf
v1.0
instruct
Evol
Evol_3402_I
Develop a program that takes a list of URLs and fetches their HTTP status codes. Your program should be able to handle cases where URLs are unreachable and should accurately report failures alongside successful responses. Additionally, ensure the program is optimized to handle a large list of URLs concurrently to minim...
import requests from concurrent.futures import ThreadPoolExecutor def fetch_status(url): """ Fetches the HTTP status code for a given URL. Handles exceptions for unreachable URLs. """ try: response = requests.get(url) return (url, response.status_code) except requests.RequestExc...
from solution import fetch_status_codes def test_fetch_status_codes_all_success(): urls = ["https://httpbin.org/status/200", "https://httpbin.org/status/204"] results = fetch_status_codes(urls) assert results == [ ("https://httpbin.org/status/200", 200), ("https://httpbin.org/status/204", 2...
[ { "docstring": "Fetches the HTTP status code for a given URL.\nHandles exceptions for unreachable URLs.", "function_declaration": "def fetch_status(url):", "function_name": "fetch_status", "parameter_list": "(url)" }, { "docstring": "Fetches HTTP status codes for a list of URLs concurrently....
[ 1, 1, 0, 1, 1, 1, 0, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import concurrent.futures\nimport requests\n\ndef fetch_status_code(url):\n \"\"\"\n Fetches the HTTP status code for a given URL.\n \n :param url: The...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003402", "row_id": 3402, "seed_ids": "[42695]" }
0.695326
Evol_3402
I
[ "fetch_status", "fetch_status_codes" ]
2
[ [ "fetch_status_codes", "fetch_status" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
e3f1723b67667cfd91d2951296eb372f3fd4949a
cef5934aba0315ebcf6241836227ed8a00be8737
v1.0
instruct
Evol
Evol_3403_I
Write a function that takes a list of integers and returns a new list with all the prime numbers removed. The order of the elements should be preserved. Provide an efficient solution considering the computational complexity of checking for prime numbers.
def is_prime(n): if n < 2: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for divisor in range(3, max_divisor, 2): if n % divisor == 0: return False return True def remo...
from solution import remove_primes def test_remove_primes_with_mixed_numbers(): assert remove_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [4, 6, 8, 9, 10] def test_remove_primes_with_all_primes(): assert remove_primes([2, 3, 5, 7, 11, 13]) == [] def test_remove_primes_with_no_primes(): assert remove_primes([...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list with all prime numbers removed.\n\nParameters:\nlst (list): List of integers.\n\nReturns:\nlist: New list with all prime numbers removed...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003403", "row_id": 3403, "seed_ids": "[14027]" }
0.585285
Evol_3403
I
[ "is_prime", "remove_primes" ]
2
[ [ "remove_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f55c9f6c5e7fba5733ff8b4b125d48014cd8adc
e43e0edf881e82bc2c898939857f2338fc857ef8
v1.0
instruct
Evol
Evol_3431_I
Given two strings, write a function called `find_common_subsequences` that finds all common subsequences between the two strings. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Your function should return a list of al...
from itertools import combinations def generate_subsequences(s): """ Generate all possible subsequences of a given string. """ subsequences = set() for i in range(1, len(s) + 1): for comb in combinations(s, i): subsequences.add(''.join(comb)) return subsequences def find_co...
from solution import find_common_subsequences def test_identical_strings(): assert find_common_subsequences("abc", "abc") == ["abc", "ab", "ac", "bc", "a", "b", "c"] def test_no_common_subsequences(): assert find_common_subsequences("abc", "def") == [] def test_empty_string(): assert find_common_subseque...
[ { "docstring": "Generate all possible subsequences of a given string.", "function_declaration": "def generate_subsequences(s):", "function_name": "generate_subsequences", "parameter_list": "(s)" }, { "docstring": "Finds all common subsequences between two strings and returns them sorted by l...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_common_subsequences(str1, str2):\n from itertools import combinations\n \n def all_subsequences(string):\n subs = set()\n for i in ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003431", "row_id": 3431, "seed_ids": "[11892]" }
0.650998
Evol_3431
I
[ "generate_subsequences", "find_common_subsequences" ]
2
[ [ "find_common_subsequences", "generate_subsequences" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e67bfcb7c9e7e97c88dc4dd39324bdfc4ceab8a
8352c1778dc6910bb261e50b1f9fa9c52b7e00c7
v1.0
instruct
Evol
Evol_3452_I
Write a function that takes a list of integers and returns the list sorted in non-decreasing order using the Merge Sort algorithm. Demonstrate how the function works with a test list. Include error handling for cases where the input is not a list or the list contains non-integer elements.
def merge_sort(arr): """ Sorts the list of integers in non-decreasing order using the Merge Sort algorithm. Includes error handling for cases where the input is not a list or the list contains non-integer elements. """ if not isinstance(arr, list): raise TypeError("Input should be of type li...
from solution import merge_sort def test_merge_sort_with_sorted_positive_numbers(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_with_unsorted_positive_numbers(): assert merge_sort([3, 1, 4, 5, 2]) == [1, 2, 3, 4, 5] def test_merge_sort_with_negative_numbers(): assert merge_s...
[ { "docstring": "Sorts the list of integers in non-decreasing order using the Merge Sort algorithm.\nIncludes error handling for cases where the input is not a list or the list contains non-integer elements.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_l...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_sort(nums):\n \"\"\"\n Sorts a list of integers in non-decreasing order using the Merge Sort algorithm.\n Raises TypeError if nums is not a list...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003452", "row_id": 3452, "seed_ids": "[8394]" }
0.670074
Evol_3452
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e09f84004bfcff0aa621d5e2da95e40e6230bb8e
3e2cfd923556a2d9467e21d6d707e2c4cde1b578
v1.0
instruct
Evol
Evol_3499_I
Write a function that takes in a list of integers and returns a new list with each element squared, but only if the original element is a prime number. If the element is not a prime number, it should be excluded from the new list. For example, given the input list [4, 7, 10, 11, 13, 16], the function should return [49,...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def square_primes(lst): """ Returns a new list with each element squared if the ...
from solution import square_primes, is_prime def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(11) assert not is_prime(0) assert not is_prime(1) assert not is_prime(15) assert is_prime(13) ...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list with each element squared if the element is a prime number.\nElements that are not pr...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003499", "row_id": 3499, "seed_ids": "[46780]" }
0.593126
Evol_3499
I
[ "is_prime", "square_primes" ]
2
[ [ "square_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa554c9b2748a9867e6021ac0137d638bc2f6a21
d03aaad51c1235bdf9b5573b7dca83d7d3130f55
v1.0
instruct
Evol
Evol_3510_I
Design a function in Python that takes a list of integers and returns a new list containing only the prime numbers from the original list. The function should implement a nested loop to check for the primality of each number. Define the structure of the function, and provide an example usage showcasing its capability t...
def is_prime(n): """ Helper function to check if a number is prime. Returns True if n is a prime number, otherwise False. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False...
[ { "docstring": "Helper function to check if a number is prime.\nReturns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a new list containi...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003510", "row_id": 3510, "seed_ids": "[2732]" }
0.689014
Evol_3510
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07aeca6274536a3c9f5846bc72027561a8150cf4
3c15a8f5bf4b581b7791db10620e4a4e95aebf86
v1.0
instruct
Evol
Evol_3543_I
Write a function in Python that receives an array of integers and returns an array containing only the prime numbers from the input, in the same order they appeared. If the input array contains no prime numbers, the function should return an empty array. Consider edge cases such as when the array is empty, or contains ...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def filter_primes(nums):...
from solution import filter_primes def test_empty_array(): assert filter_primes([]) == [] def test_no_primes(): assert filter_primes([0, 1, -2, -3, 4, 6, 8, 10]) == [] def test_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_mixed_elements(): assert filter_primes([1...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Filters the prime numbers from the given array.\n\nParameters:\nnums (list of int): The input array of integers.\n\nReturns:\n...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ret...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003543", "row_id": 3543, "seed_ids": "[26163]" }
0.692851
Evol_3543
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f2ec8c1c6dbc5e00870d62a83a8301c6ae103f1
9b13e56a92df6d661c87e2df0e779f0166429573
v1.0
instruct
Evol
Evol_3570_I
Write a function that takes in a list of integers and returns a new list containing all the elements of the original list but with each prime number replaced by the nearest prime number that is greater than or equal to it. If the input list is empty, return an empty list. The function should optimize for runtime effici...
def is_prime(n): """ Check if a number is a prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def next_prime(n): """ Fin...
from solution import is_prime, next_prime, replace_with_next_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False assert is_prime(0) == False def te...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the next prime greater than or equal to n.", "function_declaration": "def next_prime(n):", "function_name": "next_p...
[ 0, 0, 0, 1, 0, 1, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003570", "row_id": 3570, "seed_ids": "[36564]" }
0.569544
Evol_3570
I
[ "is_prime", "next_prime", "replace_with_next_primes" ]
3
[ [ "next_prime", "is_prime" ], [ "replace_with_next_primes", "next_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
876933750bc39cc05c7c3646a65e9b3e80bfebaf
639b6d83280e57af1c418ea2cfbf646fce9464b6
v1.0
instruct
Evol
Evol_3579_I
Write a function in Python that receives a list of integers and performs the following operations: 1. Find all the prime numbers in the list. 2. Compute the factorial of each prime number. 3. Return a dictionary where the keys are the prime numbers and the values are their respective factorials. Note: - A prime numbe...
from math import factorial def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def prime_factorials(numbers): primes = [num for num in numbers if is_prime(num)] return {prime: factorial(prime) for prime ...
from solution import prime_factorials def test_prime_factorials_example_case(): assert prime_factorials([2, 3, 4, 5, 6, 7, 8, 9, 10]) == {2: 2, 3: 6, 5: 120, 7: 5040} def test_prime_factorials_no_primes(): assert prime_factorials([4, 6, 8, 9, 10]) == {} def test_prime_factorials_all_primes(): assert prim...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def prime_factorials(numbers):", "function_name": "prime_factorials", "parameter_list": "(numbers)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n for i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003579", "row_id": 3579, "seed_ids": "[4683]" }
0.678307
Evol_3579
I
[ "is_prime", "prime_factorials" ]
2
[ [ "prime_factorials", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8cfa9a5fac4635ff038ddf846b28f8fbd733fa11
cdea65e99de54010d7765392d565c956ce02a273
v1.0
instruct
Evol
Evol_3589_I
Develop a program to simulate a basic package delivery system. In this system, packages are delivered to users through a series of delivery hubs. The path from the central hub (warehouse) to the end-user's address involves multiple intermediate hubs based on a defined route. Each package has a unique tracking ID, a sen...
class Hub: def __init__(self, identifier): self.identifier = identifier self.neighbors = [] def add_neighbor(self, neighbor): self.neighbors.append(neighbor) class Package: def __init__(self, tracking_id, sender_address, recipient_address, route): self.tracking_id = trackin...
def test_hub(): hub = Hub("A") assert hub.identifier == "A" assert hub.neighbors == [] def test_hub_add_neighbor(): hub_a = Hub("A") hub_b = Hub("B") hub_a.add_neighbor(hub_b) assert hub_b in hub_a.neighbors def test_package(): route = ["A", "B", "C"] package = Package("123", "Send...
[]
[ 1, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class Hub:\n def __init__(self, identifier):\n self.identifier = identifier\n self.neighbors = []\n \n def add_neighbor(self, neighbor_hub):...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003589", "row_id": 3589, "seed_ids": "[21029]" }
0.427187
Evol_3589
I
[ "initialize_hubs", "add_package", "move_packages", "simulate_delivery" ]
4
[ [ "simulate_delivery", "move_packages" ] ]
1
[]
false
[ "Hub", "Package" ]
true
pytest
false
[]
true
3e7af7f33c90ea0bde47c3044e39d9467c2242e9
8e3f108df3652b162374f9e8837937f5be7837d2
v1.0
instruct
Evol
Evol_3598_I
Write a Python function to find the sum of all prime numbers between two given numbers (inclusive). The function should take two integers as input and return the calculated sum. If there are no prime numbers in the given range, the function should return 0.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(20) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == Fal...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between a and b (inclusive).", "function_declaration": "def sum_of_primes(a, b):", "f...
[ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003598", "row_id": 3598, "seed_ids": "[22078]" }
0.656567
Evol_3598
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fdc912863bc5dc9298e476182af843054cff721c
79bd63948c7cac96ad29026c82d0d24e8f9a1abf
v1.0
instruct
Evol
Evol_3669_I
Create a function that takes a list of integers and returns a dictionary with the following properties for each number: whether it is a prime, whether it is a perfect square, and its factorial value. The function should handle edge cases where the number might be negative or zero. List: [2, 4, 5, -1, 0]
import math def is_prime(n): """ Return True if n is a prime number.""" if n <= 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def is_perfect_square(n): """Return True if n is a perfect square.""" if n < 0: ...
from solution import analyze_numbers def test_analyze_numbers(): test_list = [2, 4, 5, -1, 0] result = analyze_numbers(test_list) assert result[2]['is_prime'] == True assert result[2]['is_perfect_square'] == False assert result[2]['factorial'] == 2 assert result[4]['is_prime'] == False ...
[ { "docstring": "Return True if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return True if n is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003669", "row_id": 3669, "seed_ids": "[13396]" }
0.621659
Evol_3669
I
[ "is_prime", "is_perfect_square", "factorial", "analyze_numbers" ]
4
[ [ "analyze_numbers", "factorial" ], [ "analyze_numbers", "is_perfect_square" ], [ "analyze_numbers", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
768f36a35f1fdc06c92ab4209486df6bed34e58d
0599b1078c8e70875510d3737009c978615ecf2d
v1.0
instruct
Evol
Evol_3674_I
Implement a function that calculates the product of all the prime numbers in a given list of integers. Include error handling for non-integer inputs and return an appropriate error message when the input list is empty or contains no prime numbers. ```python def prime_product(numbers: list) -> int: """ This functio...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def prime_product(numbers: list) -> int: """ This function takes a list of integers and returns the...
from solution import prime_product def test_prime_product_with_primes(): assert prime_product([2, 3, 4, 5, 6]) == 30 assert prime_product([11, 13, 17]) == 2431 def test_prime_product_no_primes(): assert prime_product([4, 6, 8, 10]) == 'Error: No prime numbers in the list.' def test_prime_product_empty_li...
[ { "docstring": "Helper function to check if a number is prime. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "This function takes a list of integers and returns the product of all prime numbers in the list.\nIf there are...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Helper function to check if a number is prime. \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003674", "row_id": 3674, "seed_ids": "[17653]" }
0.706437
Evol_3674
I
[ "is_prime", "prime_product" ]
2
[ [ "prime_product", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7bcf1825f0962f496f8c16cb6386f1b4d0efcff
681cbf229c767483e1f40c0032c3da83a5a9ac0c
v1.0
instruct
Evol
Evol_3683_I
Design a function to balance a binary search tree (BST) which may contain duplicate values. Given an unbalanced BST with n nodes (1 <= n <= 10^5), your task is to write a function that transforms it into a balanced BST while retaining its properties. Your solution should perform the following operations: 1. Traverse t...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def inorder_traversal(root): """ Perform an inorder traversal of the BST and collect values in a list. """ if root is None: return [] return inord...
from solution import TreeNode, balance_bst, print_inorder, merge_two_bsts def test_inorder_traversal(): # Construct a sample BST root = TreeNode(3) root.left = TreeNode(1) root.right = TreeNode(4) root.left.right = TreeNode(2) # Expected inorder traversal: [1, 2, 3, 4] assert inorder_t...
[]
[ 0, 0, 0, 0, 1, 0, 1, 1, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef inorder...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003683", "row_id": 3683, "seed_ids": "[31688]" }
0.689013
Evol_3683
I
[ "inorder_traversal", "sorted_list_to_bst", "balance_bst", "print_inorder", "merge_two_bsts" ]
5
[ [ "balance_bst", "inorder_traversal" ], [ "balance_bst", "sorted_list_to_bst" ], [ "merge_two_bsts", "inorder_traversal" ], [ "merge_two_bsts", "sorted_list_to_bst" ], [ "print_inorder", "inorder_traversal" ] ]
5
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
9013a1957ddf2e20e5aadaaa270f1e6c14481906
cbfa1bd04f3bea4db008d4a2f04bdc3a52b541e9
v1.0
instruct
Evol
Evol_3707_I
Develop a sophisticated algorithm capable of dissecting multi-faceted social media data to automatically categorize and predict trending topics. Your solution should harness natural language processing techniques and advanced statistical modeling to analyze user engagement, hashtag proliferation, and temporal activity ...
import re from collections import Counter from datetime import datetime import pandas as pd from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer from sklearn.decomposition import LatentDirichletAllocation def preprocess_text(text): """ Preprocess the input text by removing special char...
from solution import preprocess_text, extract_hashtags, analyze_trends from datetime import datetime def test_preprocess_text(): assert preprocess_text("Check this out! http://example.com") == "check this out" assert preprocess_text("Amazing! #test @user") == "amazing test user" assert preprocess_text("123...
[ { "docstring": "Preprocess the input text by removing special characters, links, and converting to lowercase.", "function_declaration": "def preprocess_text(text):", "function_name": "preprocess_text", "parameter_list": "(text)" }, { "docstring": "Extract hashtags from the text.", "funct...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import re\nimport string\nfrom collections import Counter\nfrom datetime import datetime, timedelta\nimport pandas as pd\nfrom sklearn.feature_extraction.text impo...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003707", "row_id": 3707, "seed_ids": "[2331]" }
0.502706
Evol_3707
I
[ "preprocess_text", "extract_hashtags", "analyze_trends" ]
3
[ [ "analyze_trends", "extract_hashtags" ], [ "analyze_trends", "preprocess_text" ] ]
2
[]
false
[]
false
pytest
true
[ "pandas", "sklearn" ]
false
9e81c59e4c063e11240d60acba0e75c2d0243f5e
f7c659817b8bb925c70cb3c8258ad7055ec5c416
v1.0
instruct
Evol
Evol_3756_I
Original Problem: Write a function that takes a string as input and checks if it is a palindrome. A palindrome is a word, phrase, number, or other sequences of characters which reads the same backward as forward, ignoring spaces, punctuation, and capitalization. Modified Problem: Write a Python program that takes a li...
import string import logging # Setting up the logging configuration logging.basicConfig(filename='invalid_inputs.log', level=logging.ERROR) def is_palindrome(s): """ Returns True if the string s is a palindrome, ignoring spaces, punctuation, and capitalization. """ s = ''.join(char.lower() for char in...
from solution import is_palindrome, store_palindromes, sort_palindrome_dict, process_strings def test_is_palindrome(): assert is_palindrome("madam") == True assert is_palindrome("A man, a plan, a canal, Panama!") == True assert is_palindrome("hello") == False assert is_palindrome("No 'x' in Nixon") == ...
[ { "docstring": "Returns True if the string s is a palindrome, ignoring spaces, punctuation, and capitalization.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Accepts a list of strings and returns a dictionary o...
[ 1, 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if a string is a palindrome, ignoring spaces, punctuation, and capitalization.\n \"\"\"\n s = re.s...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00003756", "row_id": 3756, "seed_ids": "[26743]" }
0.774553
Evol_3756
I
[ "is_palindrome", "store_palindromes", "sort_palindrome_dict", "process_strings" ]
4
[ [ "process_strings", "sort_palindrome_dict" ], [ "process_strings", "store_palindromes" ], [ "store_palindromes", "is_palindrome" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f32d62579c5596c09ada8b4275a02dc4d8f088d9
b2cea0aaf1159de0f6fdc36dd608a4b776e240a6
v1.0
instruct
Evol
Evol_3785_I
Create a function that takes a list of integers as an argument and returns two separate lists: one containing all the prime numbers and the other containing all non-prime numbers from the given list. Ensure that the function handles edge cases such as an empty list or lists with no prime numbers correctly. Additionally...
def is_prime(n): """ Helper function to determine if a given number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False...
from solution import separate_primes def test_empty_list(): primes, non_primes = separate_primes([]) assert primes == [] assert non_primes == [] def test_only_prime_numbers(): primes, non_primes = separate_primes([2, 3, 5, 7, 11]) assert primes == [2, 3, 5, 7, 11] assert non_primes == [] def ...
[ { "docstring": "Helper function to determine if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns two separate lists:\none with prime numbers and one with non-p...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003785", "row_id": 3785, "seed_ids": "[778]" }
0.623133
Evol_3785
I
[ "is_prime", "separate_primes" ]
2
[ [ "separate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7eace3b646b174c957358d053b5828db607fcc4c
2953d09bd0190436a2b9c994a6e6832ba8db26f8
v1.0
instruct
Evol
Evol_3787_I
Create a function that takes a list of integers as input and returns a new list containing only the prime numbers from the input list. Ensure that your function is optimized for performance, especially for large input lists, and that it properly handles edge cases such as empty lists or lists with no prime numbers. Add...
from typing import List def is_prime(n: int) -> bool: """ Determine if n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: ...
from solution import filter_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True assert is_prime(1) == False assert is_prime(0) == False...
[ { "docstring": "Determine if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filter_primes(lst):...
[ 1, 1, 0, 1, 1, 1, 0, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003787", "row_id": 3787, "seed_ids": "[4500]" }
0.720857
Evol_3787
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
66508999e3bc3bef135f970e4a469baf0fe5098d
714f7d1b7f9734a3b03de770eaf847988dcc522d
v1.0
instruct
Evol
Evol_3803_I
Write a function to determine if a string has all unique characters. For example, "hello" has duplicate characters, while "world" does not. Your solution should first implement a function that checks uniqueness for a given string. Then, extend it to handle inputs of a list of strings and return a list of booleans indic...
def is_unique_string(s): """ Determines if a string has all unique characters. Args: s (str): The string to check. Returns: bool: True if all characters in the string are unique, False otherwise. """ char_set = set() for char in s: if char in char_set: r...
from solution import is_unique_string, are_strings_unique def test_is_unique_string(): assert is_unique_string("hello") == False assert is_unique_string("world") == True assert is_unique_string("") == True assert is_unique_string("abcdefg") == True assert is_unique_string("aabbcc") == False def te...
[ { "docstring": "Determines if a string has all unique characters.\n\nArgs:\ns (str): The string to check.\n\nReturns:\nbool: True if all characters in the string are unique, False otherwise.", "function_declaration": "def is_unique_string(s):", "function_name": "is_unique_string", "parameter_list": ...
[ 1, 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def has_all_unique_chars(s):\n \"\"\"\n Returns True if the string `s` has all unique characters, otherwise False.\n \"\"\"\n char_set = set()\n for...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003803", "row_id": 3803, "seed_ids": "[44488]" }
0.800037
Evol_3803
I
[ "is_unique_string", "are_strings_unique" ]
2
[ [ "are_strings_unique", "is_unique_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f3b35a71ed848361d63fdbe74c3309bf70cd755
123d30acfbd86558f53f443c1b6661ccf846b76a
v1.0
instruct
Evol
Evol_3808_I
Write a function in Python that takes a string representation of a mathematical expression and evaluates it. The string can contain positive integers and the operators +, -, *, and / (with no spaces in between). The function should respect the order of operations (PEMDAS/BODMAS rules). Additionally, handle cases wher...
import re def evaluate_expression(expression): """ Evaluates a mathematical expression given as a string, respecting the order of operations. """ # Step 0: Check validity of input and handle edge cases if not expression or not is_valid_expression(expression): raise ValueError("Invalid ...
import pytest from solution import evaluate_expression def test_valid_expressions(): assert evaluate_expression("3+2*2") == 7 assert evaluate_expression("3/2") == 1.5 assert evaluate_expression("(1+(4+5+2)-3)+(6+8)") == 23 assert evaluate_expression("(3+2)*2") == 10 def test_invalid_expressions(): ...
[ { "docstring": "Evaluates a mathematical expression given as a string, respecting the order of operations.", "function_declaration": "def evaluate_expression(expression):", "function_name": "evaluate_expression", "parameter_list": "(expression)" }, { "docstring": "Validates if the given expr...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def evaluate_expression(expression):\n \"\"\"\n Evaluates a mathematical expression string containing positive integers, +, -, *, /, \n and parentheses, f...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00003808", "row_id": 3808, "seed_ids": "[2651]" }
0.642091
Evol_3808
I
[ "evaluate_expression", "is_valid_expression" ]
2
[ [ "evaluate_expression", "is_valid_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed2e1cc37b24b45a7c28bbf9eb09611a7a932375
80eaac8dd2efaba3d106abc8de38b3f1bb0dda46
v1.0
instruct
Evol
Evol_3824_I
Write a program that takes a list of integers and returns a new list that contains only the prime numbers from the original list. Additionally, the program should include a function to find the highest prime number in the list and another function to calculate the sum of all prime numbers. Demonstrate the functionality...
import math def is_prime(n): """ Helper function to check if a given number n is prime. """ if n <= 1: return False if n == 2: return True for i in range(2, math.isqrt(n) + 1): if n % i == 0: return False return True def filter_primes(lst): """ R...
from solution import filter_primes, highest_prime, sum_of_primes def test_filter_primes(): assert filter_primes([10, 15, 3, 7, 11, 2, 20, 13, 5]) == [3, 7, 11, 2, 13, 5] assert filter_primes([1, 4, 6, 8, 9, 10]) == [] assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_highest_prime(): ...
[ { "docstring": "Helper function to check if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list lst.", "function_declaration": "def filter_prim...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003824", "row_id": 3824, "seed_ids": "[9868]" }
0.605102
Evol_3824
I
[ "is_prime", "filter_primes", "highest_prime", "sum_of_primes" ]
4
[ [ "filter_primes", "is_prime" ], [ "highest_prime", "filter_primes" ], [ "sum_of_primes", "filter_primes" ] ]
3
[]
false
[]
false
pytest
true
[]
true
fe18cc1e78e2bfd0ffdecb1ccec9e8300176d293
414e76100956509db906ec71fba25bb6c8ef75ed
v1.0
instruct
Evol
Evol_3827_I
Given a list of integers, perform the following tasks in Python: Original list: [7, 2, 9, 21, 4, 6, 1, 3] 1. Create a new list where each integer is replaced by the sum of its digits. 2. Use the new list to create a dictionary where each key is the original integer from the list and the value is the corresponding sum...
def sum_of_digits(n): """ Returns the sum of the digits of an integer n. """ return sum(int(digit) for digit in str(n)) def create_sum_list(int_list): """ Given a list of integers, returns a new list where each integer is replaced by the sum of its digits. """ return [sum_of_digits(x) f...
from solution import sum_of_digits, create_sum_list, create_digit_sum_dict, highest_digit_sum_in_list def test_sum_of_digits(): assert sum_of_digits(7) == 7 assert sum_of_digits(21) == 3 assert sum_of_digits(123) == 6 def test_create_sum_list(): assert create_sum_list([7, 21, 123]) == [7, 3, 6] as...
[ { "docstring": "Returns the sum of the digits of an integer n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, returns a new list where each integer is replaced by the sum of its digits....
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n\ndef create_digit_sums_list(integers):\n return [sum_of_digits(n) for n in integers]\n\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00003827", "row_id": 3827, "seed_ids": "[30008]" }
0.650256
Evol_3827
I
[ "sum_of_digits", "create_sum_list", "create_digit_sum_dict", "highest_digit_sum_in_list" ]
4
[ [ "create_digit_sum_dict", "sum_of_digits" ], [ "create_sum_list", "sum_of_digits" ], [ "highest_digit_sum_in_list", "create_digit_sum_dict" ] ]
3
[]
false
[]
false
pytest
true
[]
true
991c285c75a4a347f16e78bb70cb9b29227eacc4
c846e8752e447a86cf0911a3aa7779b0e01dea15
v1.0
instruct
Evol
Evol_3835_I
Create a function that takes a list of integers and returns the list with its elements rearranged to form the maximum possible integer. The output should be in the form of a string to avoid issues with large integers. Example: Input: [3, 30, 34, 5, 9] Output: "9534330"
from functools import cmp_to_key def comparator(a, b): t1 = a + b t2 = b + a return (t1 > t2) - (t1 < t2) # returns 1 if t1 > t2, -1 if t1 < t2, 0 otherwise def largest_number(nums): """ Takes a list of integers and returns the largest possible number formed by rearranging the list, as a string. ...
from solution import largest_number def test_largest_number_basic(): assert largest_number([3, 30, 34, 5, 9]) == "9534330" def test_largest_number_single_digit(): assert largest_number([1, 2, 3, 4, 5, 6, 7, 8, 9]) == "987654321" def test_largest_number_all_zeros(): assert largest_number([0, 0, 0, 0]) == ...
[ { "docstring": null, "function_declaration": "def comparator(a, b):", "function_name": "comparator", "parameter_list": "(a, b)" }, { "docstring": "Takes a list of integers and returns the largest possible number formed by rearranging the list, as a string.", "function_declaration": "def ...
[ 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Returns the largest possible number that can be formed from the list of integers.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003835", "row_id": 3835, "seed_ids": "[8108]" }
0.69669
Evol_3835
I
[ "comparator", "largest_number" ]
2
[ [ "largest_number", "comparator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab154dfdab19e331ad68caf584f6c4cdc4f4cd1e
86c4043fe427a812f3ad99acd473b31c5d45f0cc
v1.0
instruct
Evol
Evol_3859_I
Implement a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Optimize your function for performance with large input lists. Provide a brief explanation of your optimization approach.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import extract_primes def test_extract_primes_with_mixed_list(): assert extract_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_extract_primes_with_all_primes(): assert extract_primes([11, 13, 17, 19, 23]) == [11, 13, 17, 19, 23] def test_extract_primes_with_no_primes(): asser...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, returns a new list containing only the prime numbers.\nOptimizations include t...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003859", "row_id": 3859, "seed_ids": "[23404]" }
0.600905
Evol_3859
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4dbda4d8ad64ca9a5446db2e4247696acd0e04ab
f078aa7ee595fe60344a79a1a07f24dd38f90107
v1.0
instruct
Evol
Evol_3868_I
Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. If there are no prime numbers, the function should return an empty list. Ensure that your function handles edge cases such as negative numbers and zeros appropriately.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_primes...
from solution import filter_primes def test_filter_primes_all_prime_numbers(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_mixed_numbers(): assert filter_primes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_no_primes(): assert filter_prim...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the original list.", "function_declaration": "def...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003868", "row_id": 3868, "seed_ids": "[13112]" }
0.60558
Evol_3868
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
751fb6efa01491133c230d22cbb795b3115290d0
ccd1a7dcc02a1c49a2cf569221158df95176d99e
v1.0
instruct
Evol
Evol_3909_I
Construct a Python function capable of generating a Fibonacci sequence up to a given number of terms `n`. The function should allow for handling invalid input gracefully, such as negative integers, zero, or non-integer values. It should also be designed to process large values of `n` efficiently without running into me...
def generate_fibonacci(n): """ Generates the Fibonacci sequence up to n terms and returns the sequence with its sum. Args: n (int): The number of terms in the Fibonacci sequence. Returns: tuple: A tuple containing the Fibonacci sequence as a list and the sum of the sequence. """ ...
from solution import generate_fibonacci, generate_multiple_fibonacci def test_generate_fibonacci_valid_input(): assert generate_fibonacci(1) == ([0], 0) assert generate_fibonacci(2) == ([0, 1], 1) assert generate_fibonacci(5) == ([0, 1, 1, 2, 3], 7) assert generate_fibonacci(10) == ([0, 1, 1, 2, 3, 5, ...
[ { "docstring": "Generates the Fibonacci sequence up to n terms and returns the sequence with its sum.\n\nArgs:\nn (int): The number of terms in the Fibonacci sequence.\n\nReturns:\ntuple: A tuple containing the Fibonacci sequence as a list and the sum of the sequence.", "function_declaration": "def generate...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def generate_fibonacci(n):\n \"\"\"\n Generates a Fibonacci sequence up to n terms along with the sum of the sequence.\n \n Args:\n n (int): The num...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003909", "row_id": 3909, "seed_ids": "[37322]" }
0.773896
Evol_3909
I
[ "generate_fibonacci", "generate_multiple_fibonacci" ]
2
[ [ "generate_multiple_fibonacci", "generate_fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e287a9765dee079bbe8f8630c14b0b9cf97fc3c
8f29cef57647e6f6bcf31e0bbe6cf62be51285fc
v1.0
instruct
Evol
Evol_3962_I
Create a Python function that takes a list of dictionaries representing student records. Each dictionary contains `name`, `age`, and `grades` (a list of integers). The function should calculate the average grade for each student and classify them as "Pass" or "Fail". A student passes if their average grade is 60 or abo...
import sqlite3 def classify_students(students): """ Classify students as 'Pass' or 'Fail' based on their average grade. Args: students (list): A list of dictionaries, each containing 'name', 'age', and 'grades'. Returns: list: A list of dictionaries containing 'name' and 'classificati...
from solution import classify_students, save_to_database import sqlite3 import os DATABASE_PATH = 'students.db' def setup_function(): # Remove database file if exists before each test if os.path.exists(DATABASE_PATH): os.remove(DATABASE_PATH) def teardown_function(): # Remove database file after...
[ { "docstring": "Classify students as 'Pass' or 'Fail' based on their average grade.\n\nArgs:\nstudents (list): A list of dictionaries, each containing 'name', 'age', and 'grades'.\n\nReturns:\nlist: A list of dictionaries containing 'name' and 'classification'.", "function_declaration": "def classify_studen...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import sqlite3\n\ndef classify_students(student_records):\n \"\"\"\n Classifies students as \"Pass\" or \"Fail\" based on their average grade.\n Also stor...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003962", "row_id": 3962, "seed_ids": "[16128]" }
0.653144
Evol_3962
I
[ "classify_students", "save_to_database" ]
2
[ [ "classify_students", "save_to_database" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e78586ce98f782bee716496bea550d273d6e28a1
59a6c99e89aaa297ba0336edcad6e19aa9f36630
v1.0
instruct
Evol
Evol_4054_I
A robot is placed on an $8 \times 8$ grid. The robot's initial position is at the bottom-left corner (1, 1). The robot can move one step up, down, left, or right, but cannot move outside the grid. A teleporter is located at the top-right corner (8, 8). When the robot reaches the teleporter, it instantly teleports back ...
import random def simulate_robot(): grid_size = 8 start = (1, 1) teleporter = (8, 8) energy_area = {(i, j) for i in range(3, 7) for j in range(3, 7)} position = start energy_units = 0 steps = 0 while energy_units < 10 or position != teleporter: # Random move x,...
from solution import expected_steps, simulate_robot def test_simulate_robot(): """ Test simulate_robot to ensure it does not run infinitely and collects 10 energy units before ending. """ result = simulate_robot() assert result > 0 def test_expected_steps(): """ Test expected_steps produce...
[ { "docstring": null, "function_declaration": "def simulate_robot():", "function_name": "simulate_robot", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def expected_steps(num_simulations=10000):", "function_name": "expected_steps", "parameter_list": "(num...
[ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef simulate_robot_steps():\n # Initial position\n position = (1, 1)\n # Number of energy units collected\n energy_units = 0\n # St...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004054", "row_id": 4054, "seed_ids": "[46277]" }
0.591053
Evol_4054
I
[ "simulate_robot", "expected_steps" ]
2
[ [ "expected_steps", "simulate_robot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1520bcfbd2ae4f7d325345a05177793449508881
2c6ca850a90ab6edc11128f390cc3a1328a5a2ce
v1.0
instruct
Evol
Evol_4088_I
Write a Python function that takes a string and returns a new string with the characters in reverse order, without using Python's built-in reverse methods. Additionally, write a function to check if the reversed string is a palindrome, ignoring case and non-alphanumeric characters.
def reverse_string(s): """ Returns a new string with the characters in reverse order. """ reversed_str = "" for char in s: reversed_str = char + reversed_str return reversed_str def is_palindrome(s): """ Checks if the input string is a palindrome, ignoring case and non-alphanume...
from solution import reverse_string, is_palindrome def test_reverse_string(): assert reverse_string("hello") == "olleh" assert reverse_string("") == "" assert reverse_string("a") == "a" assert reverse_string("abc") == "cba" assert reverse_string("Madam") == "madaM" def test_is_palindrome(): as...
[ { "docstring": "Returns a new string with the characters in reverse order.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Checks if the input string is a palindrome, ignoring case and non-alphanumeric characte...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def reverse_string(s):\n \"\"\"\n Returns a new string with the characters in reverse order.\n \"\"\"\n reversed_s = ''\n for char in s:\n re...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004088", "row_id": 4088, "seed_ids": "[43897]" }
0.782765
Evol_4088
I
[ "reverse_string", "is_palindrome" ]
2
[ [ "is_palindrome", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5586b99f2c9f0d89ff665eaf5169cfae6391cfa1
2ae8bbce97079b1dab335175d00b86fe336b9528
v1.0
instruct
Evol
Evol_4118_I
Create a program that simulates a simplified ecosystem of predator and prey animals. The simulation should take place on a 2D grid where each cell can either be empty, contain a prey animal, or contain a predator animal. The program should allow the user to define the initial population and position of each animal. The...
import random # Define constants EMPTY = 0 PREY = 1 PREDATOR = 2 # Directions for movement DIRECTIONS = [(0, 1), (1, 0), (0, -1), (-1, 0)] class Animal: def __init__(self, breed_steps): self.steps_since_last_breed = 0 self.breed_steps = breed_steps class Prey(Animal): def __init__(self, bree...
from solution import EMPTY, PREY, PREDATOR, Prey, Predator, create_grid, place_animals, run_simulation def test_create_grid(): grid = create_grid(5, 5) assert grid == [[EMPTY for _ in range(5)] for _ in range(5)] def test_place_animals(): grid = create_grid(5, 5) initial_prey = [((1, 1), Prey(breed_st...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\nclass Animal:\n def __init__(self, reproduction_rate):\n self.reproduction_rate = reproduction_rate\n self.steps_since_reproducti...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004118", "row_id": 4118, "seed_ids": "[24529]" }
0.438318
Evol_4118
I
[ "create_grid", "place_animals", "print_grid", "run_simulation" ]
4
[ [ "run_simulation", "create_grid" ], [ "run_simulation", "place_animals" ], [ "run_simulation", "print_grid" ] ]
3
[]
false
[ "Animal", "Prey", "Predator" ]
true
pytest
true
[]
true
fe3a44c2f79d54f3b5b2968adf8457a1eb871962
f2f5fc875a4a9f3ae358621514935d77dc17ca48
v1.0
instruct
Evol
Evol_4123_I
Write a function in Python that takes a list of integers as input and returns a new list containing only the prime numbers from the original list. Additionally, the function should return the count of these prime numbers in the new list. Provide any necessary helper functions and ensure your solution has an efficient t...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import prime_numbers_and_count def test_prime_numbers_and_count(): assert prime_numbers_and_count([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == ([2, 3, 5, 7], 4) assert prime_numbers_and_count([11, 13, 17, 19, 23]) == ([11, 13, 17, 19, 23], 5) assert prime_numbers_and_count([0, 1, 4, 6, 8, 10, 12]) == ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the original input list,\nand the count of these prime nu...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004123", "row_id": 4123, "seed_ids": "[37512]" }
0.720684
Evol_4123
I
[ "is_prime", "prime_numbers_and_count" ]
2
[ [ "prime_numbers_and_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc2cd8a574ff7ef790918481dbb02e332c7f335a
eef4ae34d333581d476b6beadd5c47cfdcc1d05e
v1.0
instruct
Evol
Evol_4185_I
Write a Python function that generates a list of palindromic primes less than a given number `n`. A palindromic prime is a prime number that remains the same when its digits are reversed. The function should include input validation to ensure `n` is a positive integer greater than 2. If `n` does not meet this criterion...
def is_prime(num): if num < 2: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def is_palindrome(num): return str(num) == str(num)[::-1] def palind...
from solution import palindromic_primes def test_single_positive_integer(): assert palindromic_primes(10) == [2, 3, 5, 7] assert palindromic_primes(20) == [2, 3, 5, 7, 11] def test_single_positive_integer_count(): assert palindromic_primes(10, count=True) == 4 assert palindromic_primes(20, count=True)...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the number is prime, else False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004185", "row_id": 4185, "seed_ids": "[47146]" }
0.637017
Evol_4185
I
[ "is_prime", "is_palindrome", "palindromic_primes" ]
3
[ [ "palindromic_primes", "is_palindrome" ], [ "palindromic_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
22a921cdd5136badb818ae0f12b8e4f5c46b277e
486d1b1fe2ee9229d9c73ec8a3a6834fde9f4db3
v1.0
instruct
Evol
Evol_4188_I
In a sequence where each number is the product of its position (starting from 1) and the position immediately before and after it, determine the 6th number in the sequence. Interpret the position before 1 as 1 and after the end position (n) as n. What would be the 6th number if the options are A) 1080, B) 1440, C) 720,...
def sequence_value(n): if n == 1: return 1 return n * (n-1) * (n+1) def get_6th_number(): return sequence_value(6)
from solution import sequence_value, get_6th_number def test_sequence_value(): assert sequence_value(1) == 1 assert sequence_value(2) == 2 * 1 * 3 == 6 assert sequence_value(3) == 3 * 2 * 4 == 24 assert sequence_value(4) == 4 * 3 * 5 == 60 assert sequence_value(5) == 5 * 4 * 6 == 120 assert seq...
[ { "docstring": null, "function_declaration": "def sequence_value(n):", "function_name": "sequence_value", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def get_6th_number():", "function_name": "get_6th_number", "parameter_list": "()" } ]
[ 1, 0, 0, 1, 1, 1, 0, 1, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def sequence_product(n):\n \"\"\"\n Computes the product of the sequence number.\n \"\"\"\n if n == 1:\n return 1 * 1 * 2\n else:\n re...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004188", "row_id": 4188, "seed_ids": "[6011]" }
0.519398
Evol_4188
I
[ "sequence_value", "get_6th_number" ]
2
[ [ "get_6th_number", "sequence_value" ] ]
1
[]
false
[]
false
pytest
true
[]
true
44e9ef11acb4b4498b0e8886f314ee48cd2f8fce
c4347805eacda9942ff5bba3bee8a607dc2b3935
v1.0
instruct
Evol
Evol_4194_I
Define a sequence of integers where each term in the sequence is denoted by $a(n)$. The first term of this sequence is $a(1) = 1$. For any $n>1$, $a(n)$ is defined as the smallest positive integer greater than $a(n-1)$ such that $a(n) + a(n-1)$ is a perfect square. For example, the first few terms of the sequence are ...
import math def is_perfect_square(x): """ Check if x is a perfect square. """ s = int(math.sqrt(x)) return s * s == x def a(k): """ Returns the k-th term of the sequence a(n). """ if k == 1: return 1 sequence = [1] while len(sequence) < k: previous = se...
from solution import a def test_a_first_term(): assert a(1) == 1 def test_a_second_term(): assert a(2) == 3 def test_a_third_term(): assert a(3) == 6 def test_a_fourth_term(): assert a(4) == 10 def test_a_fifth_term(): assert a(5) == 15 def test_a_larger_terms(): assert a(6) == 21 # 15 + ...
[ { "docstring": "Check if x is a perfect square.", "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": "Returns the k-th term of the sequence a(n).", "function_declaration": "def a(k):", "function_name": ...
[ 0, 1, 0, 0, 0, 1, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"Check if x is a perfect square.\"\"\"\n s = int(math.sqrt(x))\n return s * s == x\n\ndef sequence_a(k):\n...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004194", "row_id": 4194, "seed_ids": "[9979]" }
0.583352
Evol_4194
I
[ "is_perfect_square", "a" ]
2
[ [ "a", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15c9f6b0c8e2db52d0118e464a20ccfd75104fee
d81c6266ab6aa3bb893d0d46613b67542b5b4122
v1.0
instruct
Evol
Evol_4199_I
Utilizing the Python programming language, devise a function to identify all prime numbers within a given range, inclusive of the start and end points. The function should take two parameters representing the start and end values and return a list of prime numbers within that range. Ensure the solution efficiently hand...
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def find_prim...
from solution import find_primes_in_range def test_small_range(): assert find_primes_in_range(10, 20) == [11, 13, 17, 19] def test_large_range(): assert find_primes_in_range(50, 100) == [53, 59, 61, 67, 71, 73, 79, 83, 89, 97] def test_single_prime_range(): assert find_primes_in_range(29, 29) == [29] de...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all prime numbers in the given range [start, end].", "function_declaration": "def find_primes_in_r...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004199", "row_id": 4199, "seed_ids": "[14734]" }
0.618656
Evol_4199
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c16a093efed8bbc113cb6d4c49927d9fa3baafff
61555668ae6bf6eeb5178043d8c9285d61d96731
v1.0
instruct
Evol
Evol_4205_I
Design a Python function, `calculate_average`, that computes the average value of an array of numbers. The function should also handle lists of lists (nested lists) by calculating the average of all the numbers contained within. For this purpose, you should implement two helper functions: `flatten_list` to convert nest...
def validate_numbers(lst): """Ensure each item in the list is either int or float. Raises: ValueError: If any item is not a number. """ for item in lst: if isinstance(item, list): validate_numbers(item) # Recursive check for nested lists elif not isinstance(item...
from solution import calculate_average, flatten_list, validate_numbers def test_validate_numbers_all_int(): validate_numbers([1, 2, 3]) # Should not raise any exception def test_validate_numbers_all_float(): validate_numbers([1.0, 2.0, 3.0]) # Should not raise any exception def test_validate_numbers_mixed_...
[ { "docstring": "Ensure each item in the list is either int or float.\n\nRaises:\n ValueError: If any item is not a number.", "function_declaration": "def validate_numbers(lst):", "function_name": "validate_numbers", "parameter_list": "(lst)" }, { "docstring": "Flatten a nested list into a...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def validate_numbers(lst):\n \"\"\"Ensure each item in the list is either int or float.\n \n Raises:\n ValueError: If any item is not a number.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004205", "row_id": 4205, "seed_ids": "[20957]" }
0.689744
Evol_4205
I
[ "validate_numbers", "flatten_list", "calculate_average" ]
3
[ [ "calculate_average", "flatten_list" ], [ "calculate_average", "validate_numbers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f88ccbb980f7ecd18db89e9791ea89fc0bfc6727
6b10ddfda4861ab349e5ba95937c54a94f6ca42d
v1.0
instruct
Evol
Evol_4211_I
Develop a program that synthesizes RGB color palettes based on specific inputs and constraints. The program should take a set of primary RGB colors (each defined by R, G, and B values between 0 and 255) and generate a range of new colors by blending these primary colors according to given ratios. The input will consis...
import numpy as np import matplotlib.pyplot as plt def normalize_ratios(ratios): """ Normalize a list of ratios so that they sum to 1. """ total = sum(ratios) if total == 0 or any(r < 0 for r in ratios): raise ValueError("Invalid blending ratio") return [r / total for r in ratios] def ...
from solution import blend_colors, visualize_colors def test_blend_colors_normal_input(): primary_colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] ratios = [[1/3, 1/3, 1/3], [1, 0, 0], [0, 1, 0], [0, 0, 1]] expected = [(85, 85, 85), (255, 0, 0), (0, 255, 0), (0, 0, 255)] assert blend_colors(primary_col...
[ { "docstring": "Normalize a list of ratios so that they sum to 1.", "function_declaration": "def normalize_ratios(ratios):", "function_name": "normalize_ratios", "parameter_list": "(ratios)" }, { "docstring": "Blend the primary colors based on the blending ratios.", "function_declaration...
[ 1, 1, 1, 0, 1, 1, 0, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\nimport numpy as np\n\ndef blend_colors(primary_colors: List[Tuple[int, int, int]], blending_ratios: List[List[float]], visualize: b...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004211", "row_id": 4211, "seed_ids": "[6033]" }
0.500071
Evol_4211
I
[ "normalize_ratios", "blend_colors", "visualize_colors" ]
3
[ [ "blend_colors", "normalize_ratios" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
c808c30527ac2fa16a4e98aa9bfbdebb70da875d
96d817033d5bac46f493ad48c0ea054f8b8f0f4e
v1.0
instruct
Evol
Evol_4212_I
Construct a function that identifies and returns all the distinct anagrams of a given word within a list of possible candidates. The function should handle case insensitivity and ignore spaces and punctuation in the input word and the candidate words. The function should also be able to manage and correctly identify a...
import re def sanitize_string(s): """ Removes all non-alphabetic characters from the string and converts it to lowercase """ return re.sub(r'[^a-z]', '', s.lower()) def is_anagram(word1, word2): """ Checks if word1 and word2 are anagrams, ignoring case and non-alphabetic characters. """ ...
from solution import find_anagrams def test_find_anagrams(): word = "listen" candidates = ["enlists", "google", "inlets", "banana", ["Silent", "LISTEN"], "tinsel", [None, "Listen"]] expected = ["inlets", ["silent", "listen"], "tinsel", ["listen"]] assert find_anagrams(word, candidates) == expected def...
[ { "docstring": "Removes all non-alphabetic characters from the string and converts it to lowercase", "function_declaration": "def sanitize_string(s):", "function_name": "sanitize_string", "parameter_list": "(s)" }, { "docstring": "Checks if word1 and word2 are anagrams, ignoring case and non...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import string\n\ndef normalize_string(s):\n return ''.join(sorted(s.lower().translate(str.maketrans('', '', string.punctuation + string.whitespace))))\n\ndef fi...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004212", "row_id": 4212, "seed_ids": "[26907]" }
0.614774
Evol_4212
I
[ "sanitize_string", "is_anagram", "find_anagrams" ]
3
[ [ "find_anagrams", "is_anagram" ], [ "find_anagrams", "sanitize_string" ], [ "is_anagram", "sanitize_string" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ad9eeb1938969cb7fc58242323d8acfa4c7d8014
ceee715922fc119708cac6ccb2fde7f2cf82c016
v1.0
instruct
Evol
Evol_4223_I
Create a function that takes a list of integers and returns a new list containing only the elements that are prime numbers. The function should efficiently check for prime numbers and maintain the original order of the elements in the returned list.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_prim...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13, 17]) == [2, 3, 5, 7, 11, 13, 17] def test_filter_primes_with_no_primes...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the input list.", "function_declaration": "def ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004223", "row_id": 4223, "seed_ids": "[11398]" }
0.639913
Evol_4223
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9920456c696f564b324a48aee2bce239a2fe58c
db2c3e70f50e118b41b5e593c69b59c1dafc4cef
v1.0
instruct
Evol
Evol_4239_I
Create a function that processes an input list of integers and returns a new list containing only the elements that are prime numbers. For instance, given the input list [4, 7, 12, 17, 23], the function should output [7, 17, 23]. Ensure the solution handles edge cases and has an efficient algorithm for checking prime n...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return F...
from solution import filter_primes def test_filter_primes_all_prime(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_mixed(): assert filter_primes([4, 7, 12, 17, 23]) == [7, 17, 23] def test_filter_primes_no_prime(): assert filter_primes([4, 6, 8, 10]) == [] def test_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def fi...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004239", "row_id": 4239, "seed_ids": "[43610]" }
0.663262
Evol_4239
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0305d8fc17f1220b92aa111148e7b133939c4875
001dd8521c2134beab2886c21d3477d3ea6f28db
v1.0
instruct
Evol
Evol_4316_I
Write a function that takes a list of integers as input and returns a new list containing only the prime numbers from the input list. The function should be efficient, using a technique such as the Sieve of Eratosthenes for prime number detection. Provide examples and edge cases to illustrate the functionality of your ...
def sieve_of_eratosthenes(max_num): """ Return a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm. """ sieve = [True] * (max_num + 1) sieve[0] = sieve[1] = False for start in range(2, int(max_num**0.5) + 1): if sieve[start]: for multiple in r...
from solution import filter_primes def test_filter_primes_empty_list(): assert filter_primes([]) == [] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 10, 12]) == [] def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_...
[ { "docstring": "Return a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Filter and return prime numbers ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Generate a list of boolean values, where index represents number\n and boolean value represents whether the...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004316", "row_id": 4316, "seed_ids": "[27209]" }
0.668201
Evol_4316
I
[ "sieve_of_eratosthenes", "filter_primes" ]
2
[ [ "filter_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2af84e06a37e5824484ec11ac7425f5227301e6f
d120cb51f1090a82a0d0c03c1ddf656a5db398c3
v1.0
instruct
Evol
Evol_4353_I
Complete the `merge_sort` function to implement the Merge Sort algorithm. Given an unsorted list of integers, the function should return the sorted list in ascending order using the Merge Sort algorithm. ## Function Signature ```python def merge_sort(arr: List[int]) -> List[int]: ``` ## Input - `arr` (List[int]): A ...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left: List[int], right: List[int]) -> List[int]...
from solution import merge_sort def test_merge_sort_with_positive_numbers(): assert merge_sort([38, 27, 43, 3, 9, 82, 10]) == [3, 9, 10, 27, 38, 43, 82] def test_merge_sort_with_negative_and_positive_numbers(): assert merge_sort([-1, 6, 3, -5, 9, 0, 2]) == [-5, -1, 0, 2, 3, 6, 9] def test_merge_sort_with_dup...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Perform a Merge Sort on a given list of integers.\n\n Parameters:\n arr (List[int]): A list of integers to sort.\n\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004353", "row_id": 4353, "seed_ids": "[1064]" }
0.651635
Evol_4353
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
380d62699ccdce88544ee65c462cb5be2fe61eca
b6c6e75661c99d945e66e437e85e59c25a205e86
v1.0
instruct
Evol
Evol_4378_I
Given a list of integers, write a function that returns a new list of the same integers sorted in ascending order, but with all prime numbers moved to the front of the list. Non-prime numbers should retain their relative order from the original list. For example, given the input [4, 3, 5, 7, 6, 2, 8], the output should...
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sort_primes_to_front(lst): ...
from solution import is_prime, sort_primes_to_front def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) def test_sort_primes_to_front_basic(): assert sort_primes_to_front([4, 3, 5, 7, 6, 2, 8]) =...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list with prime numbers moved to the front, retaining the relative\norder of non-prime numbers.", "function_dec...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004378", "row_id": 4378, "seed_ids": "[30168]" }
0.596242
Evol_4378
I
[ "is_prime", "sort_primes_to_front" ]
2
[ [ "sort_primes_to_front", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56e864a81af552ef7569e367005efb56835b9cad
1513149104bc85485014f41ed9c43cba3f212c1b
v1.0
instruct
Evol
Evol_4426_I
Design and implement a polynomial regression model using Python to forecast housing prices based on historical sales data. Your solution should encompass the following steps: 1. Data Preprocessing: Import the dataset, handle missing values, and perform any necessary data transformations such as normalization. 2. Mod...
import numpy as np import pandas as pd from sklearn.preprocessing import PolynomialFeatures, StandardScaler from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split, cross_val_score from sklearn.metrics import mean_squared_error, r2_score import matplotlib.pyplot as plt de...
import pytest from solution import preprocess_data, select_polynomial_degree, train_model, evaluate_model, predict, polynomial_regression_pipeline import pandas as pd # Dummy Data for Testing dummy_data = { 'Feature1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'Target': [1.2, 1.9, 3.2, 3.8, 5.1, 5.9, 7.1, 7.8, 9.2, 9.9...
[ { "docstring": "Preprocess the data by handling missing values and normalizing features.", "function_declaration": "def preprocess_data(df):", "function_name": "preprocess_data", "parameter_list": "(df)" }, { "docstring": "Select the degree of polynomial using cross-validation to balance bia...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import numpy as np\nimport pandas as pd\nfrom sklearn.preprocessing import PolynomialFeatures, StandardScaler\nfrom sklearn.model_selection import train_test_split...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004426", "row_id": 4426, "seed_ids": "[13212]" }
0.538356
Evol_4426
I
[ "preprocess_data", "select_polynomial_degree", "train_model", "evaluate_model", "predict", "create_plots", "polynomial_regression_pipeline" ]
7
[ [ "polynomial_regression_pipeline", "create_plots" ], [ "polynomial_regression_pipeline", "evaluate_model" ], [ "polynomial_regression_pipeline", "predict" ], [ "polynomial_regression_pipeline", "preprocess_data" ], [ "polynomial_regression_pipeline", "select_...
6
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy", "pandas", "sklearn" ]
false
a2c99ff46eae17c0bda48b8c80a6159e341d3848
c35710a34c48dbb101e1845f7dc3a353c2c4bb0a
v1.0
instruct
Evol
Evol_4451_I
Given a binary tree, where each node contains a value, write a function `is_subtree` that takes in two binary trees (A and B) and returns True if tree B is a subtree of tree A, and False otherwise. ### Input - `A`: The root node of Binary Tree A. - `B`: The root node of Binary Tree B. ### Output - A boolean value (Tr...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_same_tree(s, t): if not s and not t: return True if not s or not t: return False if s.val != t.val: return False return is_same...
from solution import TreeNode, is_subtree def test_is_subtree_positive(): # Example Binary Tree A rootA = TreeNode(3) rootA.left = TreeNode(4) rootA.right = TreeNode(5) rootA.left.left = TreeNode(1) rootA.left.right = TreeNode(2) # Example Binary Tree B rootB = TreeNode(4) rootB.le...
[]
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_subt...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004451", "row_id": 4451, "seed_ids": "[33761]" }
0.627376
Evol_4451
I
[ "is_same_tree", "is_subtree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0d7f0b7b9093760c640b67fd6ad3c8df04852ade
0f0347e149132228a5a0a680558e2506131aa87c
v1.0
instruct
Evol
Evol_4471_I
Develop a Python function that takes a list of integers and returns a new list containing only the elements that are Fibonacci numbers from the original list. Utilize an efficient algorithm to determine if a number is a Fibonacci number.
def is_fibonacci_number(n): """ Check if a number is a Fibonacci number by checking if one of (5*n*n + 4) or (5*n*n - 4) is a perfect square. """ if n < 0: return False def is_perfect_square(x): s = int(x ** 0.5) return s * s == x return is_perfect_square(5 * n * n...
from solution import filter_fibonacci_numbers, is_fibonacci_number def test_is_fibonacci_number(): assert is_fibonacci_number(0) == True assert is_fibonacci_number(1) == True assert is_fibonacci_number(2) == True assert is_fibonacci_number(3) == True assert is_fibonacci_number(4) == False asser...
[ { "docstring": "Check if a number is a Fibonacci number by checking if one of \n(5*n*n + 4) or (5*n*n - 4) is a perfect square.", "function_declaration": "def is_fibonacci_number(n):", "function_name": "is_fibonacci_number", "parameter_list": "(n)" }, { "docstring": "Returns a list of elemen...
[ 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_fibonacci(n):\n \"\"\"\n Returns True if n is a Fibonacci number, else False.\n \"\"\"\n if n < 0:\n return False\n # A...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004471", "row_id": 4471, "seed_ids": "[12305]" }
0.729927
Evol_4471
I
[ "is_fibonacci_number", "filter_fibonacci_numbers" ]
2
[ [ "filter_fibonacci_numbers", "is_fibonacci_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a24661c24160e5a301fd3be47923e6e71ccf63d4
dba9b3e99aa2e91afd8350a05fc3ac0c23d38703
v1.0
instruct
Evol
Evol_4487_I
Write a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Use the Sieve of Eratosthenes algorithm to identify the prime numbers. Provide the function signature as `def filter_primes(numbers: List[int]) -> List[int]:`. Example: ```python filt...
from typing import List def sieve_of_eratosthenes(max_num: int) -> List[bool]: """ Returns a list of boolean values where True indicates that the index is a prime number. Uses the Sieve of Eratosthenes algorithm. """ sieve = [True] * (max_num + 1) sieve[0] = sieve[1] = False # 0 and 1 are not ...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 9, 10]) == [] def test_filter_primes_mixed_numbers(): assert filter_primes([2, 3, 5, 7, 8, 10, 13, 15]) == ...
[ { "docstring": "Returns a list of boolean values where True indicates that the index is a prime number.\nUses the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "do...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef filter_primes(numbers: List[int]) -> List[int]:\n \"\"\"\n Returns a list containing only the prime numbers from the original ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004487", "row_id": 4487, "seed_ids": "[15117]" }
0.665638
Evol_4487
I
[ "sieve_of_eratosthenes", "filter_primes" ]
2
[ [ "filter_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e53a70fbeadc823f49016c638023606ac311672
e458e0af853d66a5dce4b7c65a0291451b0ad091
v1.0
instruct
Evol
Evol_4496_I
Design an algorithm to balance a binary search tree (BST). Given an unbalanced BST, the task is to convert it into a balanced BST that maintains the properties of a BST where the left subtree of a node contains only nodes with keys lesser than the node’s key, and the right subtree only nodes with keys greater than the ...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.key = key def store_inorder(node, inorder_list): """ Helper function to store the inorder traversal of a tree. """ if node is None: return # Store nodes in the left subtree stor...
from solution import TreeNode, balance_bst def bst_to_list(root): """ Helper function to convert BST to a sorted list which can be used in tests for comparison. """ result = [] def inorder(node): if not node: return inorder(node.left) result.append(node.key) ...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef inorder...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004496", "row_id": 4496, "seed_ids": "[44928]" }
0.667932
Evol_4496
I
[ "store_inorder", "sorted_array_to_bst", "balance_bst" ]
3
[ [ "balance_bst", "sorted_array_to_bst" ], [ "balance_bst", "store_inorder" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2a9f6ee942e23a6fbc477b622a78bf36237c0289
c471b32c36d99fe88e574199cafcdd87df3e6b77
v1.0
instruct
Evol
Evol_4501_I
Implement a function that takes a string as an input and returns the length of the longest substring without repeating characters. Additionally, write a function to display all distinct substrings of the input string that are of this maximum length. Ensure your solution efficiently handles edge cases and large inputs.
def length_of_longest_substring(s): """ Returns the length of the longest substring without repeating characters. """ n = len(s) max_length = 0 start = 0 char_index_map = {} for end in range(n): if s[end] in char_index_map: start = max(start, char_index_map[s[end]] +...
from solution import length_of_longest_substring, longest_substrings def test_length_of_longest_substring_single_char(): assert length_of_longest_substring('aaaaaaa') == 1 def test_length_of_longest_substring_no_repeats(): assert length_of_longest_substring('abcdef') == 6 def test_length_of_longest_substring...
[ { "docstring": "Returns the length of the longest substring without repeating characters.", "function_declaration": "def length_of_longest_substring(s):", "function_name": "length_of_longest_substring", "parameter_list": "(s)" }, { "docstring": "Returns all distinct substrings of maximum len...
[ 0, 0, 0, 1, 0, 1, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def length_of_longest_substring(s):\n \"\"\"\n Returns the length of the longest substring without repeating characters.\n \"\"\"\n n = len(s)\n cha...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004501", "row_id": 4501, "seed_ids": "[23886]" }
0.737369
Evol_4501
I
[ "length_of_longest_substring", "longest_substrings" ]
2
[ [ "longest_substrings", "length_of_longest_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
867d4355c976827bf978b0e8e2366048565f6c8e
e8e704e8d1b1bd8c80532ad5ad5002c8c86a836b
v1.0
instruct
Evol
Evol_4503_I
Write a function that accepts a list of integers and returns a new list that contains only the prime numbers from the original list. Use helper functions to check for prime numbers and to filter the list. If no prime numbers are found, return an empty list. Example input: [11, 14, 17, 19, 21] Example output: [11, 17, ...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for i in range(3, max_divisor, 2): if n % i == 0: return False ...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) assert not is_prime(4) assert is_prime(5) assert not is_prime(0) assert not is_prime(1) assert not is_prime(-3) assert is_prime(17) def test_filter_primes(): assert filter_primes([11, 14, 17, 19, 21]) ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the input list.", "function_declaration": "def filter_primes(numbers):...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004503", "row_id": 4503, "seed_ids": "[43898]" }
0.652204
Evol_4503
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cae22748de0c19e83d0f6645e2d321a02d2f828
baaf6a6634b3cbc1529224cd10537427df8edee6
v1.0
instruct
Evol
Evol_4520_I
Create a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. The function should efficiently check for primality to ensure optimal performance for large lists.
def is_prime(n): """Check if a number n is a prime number.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import filter_primes def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_filter_primes_with_no_primes(): assert filter_primes([1, 4, 6, 8, 9, 10]) == [] def test_filter_primes_with_mixed_numbers(): assert filter_primes([1, 2,...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the input list of integers.", "function_declaration": "def filter_primes(numbe...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004520", "row_id": 4520, "seed_ids": "[16811]" }
0.60644
Evol_4520
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d309ee45c279cb8651c6a9504a9a9f7514388322
5044c06d72d0373b285759b344673378f5d31450
v1.0
instruct
Evol
Evol_4531_I
Write a Python script that reads a CSV file containing details about different e-commerce products such as 'product_id', 'category', 'price', and 'rating'. Utilize the Pandas library to perform the following tasks: 1. Load the CSV file into a DataFrame. 2. Calculate the average price of products in each category. 3. Id...
import pandas as pd def read_csv(file_path): """ Reads a CSV file and returns a DataFrame. """ try: df = pd.read_csv(file_path) return df except FileNotFoundError: print("The file was not found.") return None except pd.errors.EmptyDataError: print("The fi...
import pandas as pd from io import StringIO from solution import read_csv, process_data, save_to_csv def test_read_csv_valid(): data = """product_id,category,price,rating 1,Electronics,199.99,4.5 2,Books,10.99,4.0 3,Clothing,29.99,3.7""" df = pd.read_csv(StringIO(data)) assert df is not None def test_read...
[ { "docstring": "Reads a CSV file and returns a DataFrame.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Processes the DataFrame to calculate the average price of products in each category\nand identify th...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import pandas as pd\n\ndef process_ecommerce_csv(file_path, output_path):\n try:\n # Load CSV file into a DataFrame\n data = pd.read_csv(file_path...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004531", "row_id": 4531, "seed_ids": "[9027]" }
0.676965
Evol_4531
I
[ "read_csv", "process_data", "save_to_csv", "process_ecommerce_data" ]
4
[ [ "process_ecommerce_data", "process_data" ], [ "process_ecommerce_data", "read_csv" ], [ "process_ecommerce_data", "save_to_csv" ] ]
3
[ "process_data" ]
false
[]
false
pytest
true
[ "pandas" ]
false
72e9771b47236f866c4afc07265ad28a12d0c86a
c71307acc21f11dfa04b3daff43ed1d5d654da26
v1.0
instruct
Evol
Evol_4552_I
Create a function that takes a list of integers and returns a new list consisting of only the prime numbers from the original list. Ensure that the function is optimally efficient and handles edge cases, such as empty lists or lists with no prime numbers, appropriately. Additionally, implement a helper function to dete...
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_pr...
from solution import is_prime, filter_primes def test_is_prime(): # Test prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(17) == True # Test non-prime numbers assert is_prime(1) == False assert is_prime(4) == False assert...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list consisting of only the prime numbers from the original list.", "function_declaration...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004552", "row_id": 4552, "seed_ids": "[47184]" }
0.642995
Evol_4552
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f6c7c80a84bfe61e35de5a02276390219718013
3457530943fbd36b884c64cb84a30105f033ce2b
v1.0
instruct
Evol
Evol_4569_I
Generate a matrix (2-dimensional array) where the number of rows (m) and columns (n) are given as input. Populate the matrix such that each element A[i][j] is populated using the formula: A[i][j] = (i+j)! / (i! * j!) where "!" denotes factorial. The result should be a matrix where each element is a binomial coefficie...
import math def factorial(n): """ Compute the factorial of n. """ if n < 0: raise ValueError("Factorial is not defined for negative numbers.") if n == 0: return 1 return math.factorial(n) def binomial_coefficient(i, j): """ Compute binomial coefficient C(i, j) which is ...
import pytest from solution import generate_matrix, binomial_coefficient, factorial def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(5) == 120 assert factorial(10) == 3628800 with pytest.raises(ValueError): factorial(-5) def test_binomial_coefficient...
[ { "docstring": "Compute the factorial of n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Compute binomial coefficient C(i, j) which is given by (i+j)! / (i! * j!)", "function_declaration": "def binomial_coefficien...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef factorial(n):\n \"\"\"\n Computes the factorial of a given number n.\n \"\"\"\n if n < 0:\n raise ValueError(\"Factorial is n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004569", "row_id": 4569, "seed_ids": "[35396]" }
0.555776
Evol_4569
I
[ "factorial", "binomial_coefficient", "generate_matrix" ]
3
[ [ "binomial_coefficient", "factorial" ], [ "generate_matrix", "binomial_coefficient" ] ]
2
[]
false
[]
false
pytest
true
[]
true
db877c0492b23f31622087986c7ca77d4ed23c6e
ee3cc31dfc8d7da383285585b0a97a4fc6faa1fb
v1.0
instruct
Evol
Evol_4588_I
Design a function that takes a list of integers and returns a list of tuples. Each tuple should contain a number from the list and its digital root. The digital root is obtained by iteratively summing the digits of a number until a single-digit number is obtained. For example, the digital root of 9875 is 2 (9+8+7+5=29,...
def digital_root(n): """ Helper function to calculate the digital root of a number `n`. """ while n >= 10 or n <= -10: n = sum(int(digit) for digit in str(abs(n))) return n if n >= 0 else -n def list_with_digital_roots(numbers): """ For a given list of integers `numbers`, returns a ...
from solution import digital_root, list_with_digital_roots def test_digital_root_single_digit(): assert digital_root(0) == 0 assert digital_root(5) == 5 assert digital_root(-5) == 5 def test_digital_root_multiple_digits(): assert digital_root(9875) == 2 assert digital_root(29) == 2 assert digi...
[ { "docstring": "Helper function to calculate the digital root of a number `n`.", "function_declaration": "def digital_root(n):", "function_name": "digital_root", "parameter_list": "(n)" }, { "docstring": "For a given list of integers `numbers`, returns a list of tuples \nwhere each tuple con...
[ 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def digital_root(n):\n \"\"\"\n Helper function to compute the digital root of a non-negative integer.\n \"\"\"\n while n > 9:\n n = sum(int(dig...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004588", "row_id": 4588, "seed_ids": "[9628]" }
0.634303
Evol_4588
I
[ "digital_root", "list_with_digital_roots" ]
2
[ [ "list_with_digital_roots", "digital_root" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec20a2a416eba8b4f944f0ff19c1d43cadf04f93
4d39b908d4ecf6bc530fa96a2355d9fba92b4257
v1.0
instruct
Evol
Evol_4619_I
Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Additionally, optimize the function to handle large inputs efficiently. Then, correct the errors in the provided code so the function works as intended. Sample Input: [29, 15, 23, 4, 7, 11, ...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def filter_primes(numbers): primes = [] ...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_filter_primes(): ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def filter_primes(numbers):", "function_name": "filter_primes", "parameter_list": "(numbers)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004619", "row_id": 4619, "seed_ids": "[10108]" }
0.625672
Evol_4619
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ae069f3bb7c47be37902d7ea7a86bb305c5c556
a748daffe05972f78984adefd256d8206800fa22
v1.0
instruct
Evol
Evol_4622_I
Compute the sum of all elements in the given list that are prime numbers. Array: [3, 5, 8, 13, 20, 23, 28]
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes(arr): """ Returns the sum of all elements in the given list tha...
from solution import sum_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(29) == True assert is_prime(30) == False def test_sum_of_primes(): ...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all elements in the given list that are prime numbers.", "function_declaration": ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004622", "row_id": 4622, "seed_ids": "[4235]" }
0.572898
Evol_4622
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
deca602231325e91b017e222cd8992e588e77542
e4099198d954fa67370d383338bfa5a52b6b4489
v1.0
instruct
Evol
Evol_4635_I
Design an efficient algorithm to solve the task of generating the nth term in the series of triangular numbers. The triangular number for a given n is defined by the formula T(n) = n*(n+1)/2. The solution should integrate both iterative and recursive approaches and should highlight the trade-offs between these methods....
import math from concurrent.futures import ThreadPoolExecutor def validate_and_round_input(n): # Validate and round the input to nearest integer if not isinstance(n, (int, float)): raise ValueError("Input must be an integer or a float") if n < 0: raise ValueError("Input must be a non-negati...
from solution import ( validate_and_round_input, triangular_number_iterative, triangular_number_recursive, generate_series_and_aggregate, process_input_array, parallel_processing, flawed_triangular_number ) import pytest def test_validate_and_round_input(): assert validate_and_round_in...
[ { "docstring": null, "function_declaration": "def validate_and_round_input(n):", "function_name": "validate_and_round_input", "parameter_list": "(n)" }, { "docstring": "Generate the nth triangular number iteratively.", "function_declaration": "def triangular_number_iterative(n):", "f...
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\nfrom concurrent.futures import ThreadPoolExecutor\n\ndef nth_triangular(n):\n \"\"\"\n Computes the nth triangular number using the formula T(n)...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004635", "row_id": 4635, "seed_ids": "[17363]" }
0.559268
Evol_4635
I
[ "validate_and_round_input", "triangular_number_iterative", "triangular_number_recursive", "generate_series_and_aggregate", "process_input_array", "parallel_processing", "flawed_triangular_number" ]
7
[ [ "generate_series_and_aggregate", "triangular_number_iterative" ], [ "generate_series_and_aggregate", "validate_and_round_input" ], [ "parallel_processing", "generate_series_and_aggregate" ], [ "process_input_array", "generate_series_and_aggregate" ], [ "triangul...
6
[]
false
[]
false
pytest
true
[]
true
bb28213ebbb193e73e5893c47c527a4496bdb17a
70238dd4d98689e07dfcf741070a32a91116638b
v1.0
instruct
Evol
Evol_4644_I
Write a function `least_common_multiple(a, b)` that takes two positive integers, `a` and `b`, and returns their least common multiple (LCM). The LCM of two integers is the smallest positive integer that is divisible by both `a` and `b`. Your function should have a time complexity of O(log(min(a, b))) using the greatest...
def gcd(x, y): """ Calculate the greatest common divisor of x and y using the Euclidean algorithm. """ while y: x, y = y, x % y return x def least_common_multiple(a, b): """ Calculate and return the least common multiple (LCM) of two positive integers a and b using the relat...
def test_gcd(): assert gcd(48, 18) == 6 assert gcd(7, 5) == 1 assert gcd(100, 10) == 10 assert gcd(27, 9) == 9 def test_least_common_multiple(): assert least_common_multiple(4, 5) == 20 assert least_common_multiple(10, 15) == 30 assert least_common_multiple(3, 7) == 21 assert least_...
[ { "docstring": "Calculate the greatest common divisor of x and y using the\nEuclidean algorithm.", "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": "Calculate and return the least common multiple (LCM) of two positive\nintegers a ...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Helper function to find the Greatest Common Divisor (GCD) of two numbers.\n Uses the Euclidean algorithm.\n \"\"\"\n while...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004644", "row_id": 4644, "seed_ids": "[23494]" }
0.691836
Evol_4644
I
[ "gcd", "least_common_multiple" ]
2
[ [ "least_common_multiple", "gcd" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b5d5ea6804f1547ba720e77ee6cf7ce0d6f2ec97
d87d088a3e4db04438f3bc6d9784b903e3692d33
v1.0
instruct
Evol
Evol_4647_I
Write a Python program that performs the following: 1. Reads an integer `N` from the user input. 2. Generates a list of `N` random integers between 1 and 100 inclusive. 3. Removes any duplicates from the list while keeping the order of the remaining elements. 4. Computes the sum of all the prime numbers in the resulti...
import random def is_prime(num): """ Returns True if num is a prime number, otherwise False. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def remove_duplicates(lst): """ Removes duplicates fr...
from solution import is_prime, remove_duplicates, sum_primes, process_numbers def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(19) == True assert is_prime(20) == False def test_remove_duplicates()...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Removes duplicates from lst while maintaining order.", "function_declaration": "def remove_dup...
[ 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004647", "row_id": 4647, "seed_ids": "[15530]" }
0.592173
Evol_4647
I
[ "is_prime", "remove_duplicates", "sum_primes", "process_numbers" ]
4
[ [ "process_numbers", "remove_duplicates" ], [ "process_numbers", "sum_primes" ], [ "sum_primes", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
891a4cbb0e7126123fa17af4158210ed44bb729a
7464592e8abc930e87f2e8f9c505187603df000d
v1.0
instruct
Evol
Evol_4665_I
Develop a Python function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. Ensure that the function is optimized for handling large lists efficiently.
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return Tru...
from solution import is_prime, filter_primes def test_is_prime(): # Test small primes assert is_prime(2) == True assert is_prime(3) == True # Test non-primes assert is_prime(4) == False assert is_prime(9) == False # Test larger primes assert is_prime(11) == True assert is_prime(17) ...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list.", "function_declaration": "def filter_primes(numbers):", "function_n...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004665", "row_id": 4665, "seed_ids": "[240]" }
0.628817
Evol_4665
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a5006bdbc8ffa317d5bb50812411b265a4ab9d2
e2f87ee889ff21eee7b2d05a045e1daa2e314f81
v1.0
instruct
Evol
Evol_4703_I
Implement a function in Python that takes a list of integers and returns a list of tuples. Each tuple should contain an integer from the input list and its corresponding factorial. The function should utilize a helper function to calculate the factorial of a given number. Provide type hints for the functions.
from typing import List, Tuple def factorial(n: int) -> int: """ Returns the factorial of the given integer n. """ if n == 0: return 1 result = 1 for i in range(1, n + 1): result *= i return result def list_factorials(numbers: List[int]) -> List[Tuple[int, int]]: """ ...
from solution import factorial, list_factorials def test_factorial_zero(): assert factorial(0) == 1 def test_factorial_one(): assert factorial(1) == 1 def test_factorial_positive_number(): assert factorial(5) == 120 def test_list_factorials_empty(): assert list_factorials([]) == [] def test_list_fa...
[ { "docstring": "Returns the factorial of the given integer n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a list of tuples.\nEach tuple contains an integer from the input list and...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef factorial(n: int) -> int:\n \"\"\"\n Returns the factorial of a given integer n.\n \"\"\"\n if n == 0:\n r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004703", "row_id": 4703, "seed_ids": "[15142]" }
0.726281
Evol_4703
I
[ "factorial", "list_factorials" ]
2
[ [ "list_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42ea7aad1d44c4cb0a415ecd7f4d939af7c92284
6df35e26b1729b29804262d3baca3f5feff5a6cb
v1.0
instruct
Evol
Evol_4769_I
Create a function that takes an unsorted list of integers and returns a new list containing only the prime numbers from the original list. Each prime number in the returned list should be in the same order as they appeared in the input list.
def is_prime(n): """ Checks if n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def extract_prime_numbers(lst...
from solution import extract_prime_numbers def test_extract_prime_numbers_mixed_list(): assert extract_prime_numbers([10, 2, 3, 4, 5, 6, 11, 13, 17, 19, 22, 23, 29]) == [2, 3, 5, 11, 13, 17, 19, 23, 29] def test_extract_prime_numbers_no_primes(): assert extract_prime_numbers([4, 6, 8, 10, 12, 14, 15, 16, 20])...
[ { "docstring": "Checks if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the input list.", "function_declaration": "def extract_prime_numbers(lst):", "func...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004769", "row_id": 4769, "seed_ids": "[29856]" }
0.649286
Evol_4769
I
[ "is_prime", "extract_prime_numbers" ]
2
[ [ "extract_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
465160935013c2353f06de04e7e59acb4f9382e0
5561f9bfad0b29ca1129c80d75dcc59103c44b82
v1.0
instruct
Evol
Evol_4806_I
Implement a function that takes a string containing a mathematical expression written in Roman numerals with '+' and '-' operators and returns the result as an integer. You can assume the input will always be a valid expression. Roman numerals are limited to 'I', 'V', 'X', 'L', 'C', 'D', 'M'. ### Input: - A single str...
def roman_to_int(s: str) -> int: """ Convert a Roman numeral string to an integer. """ roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} prev_value = 0 total = 0 for char in s[::-1]: # Traverse the string from the end value = roman_dict[char] if ...
from solution import roman_expression def test_roman_expression_single_number(): assert roman_expression("III") == 3 assert roman_expression("IX") == 9 def test_roman_expression_addition(): assert roman_expression("X+V") == 15 assert roman_expression("XII+II") == 14 def test_roman_expression_subtract...
[ { "docstring": "Convert a Roman numeral string to an integer.", "function_declaration": "def roman_to_int(s):", "function_name": "roman_to_int", "parameter_list": "(s)" }, { "docstring": "Evaluate the integer math expression with addition and subtraction.", "function_declaration": "def e...
[ 0, 0, 1, 1, 1, 1, 0, 0, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def roman_to_int(roman):\n \"\"\"\n Converts a Roman numeral to an integer.\n \"\"\"\n roman_numerals = {\n 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004806", "row_id": 4806, "seed_ids": "[20253]" }
0.694045
Evol_4806
I
[ "roman_to_int", "eval_roman_expression", "roman_expression" ]
3
[ [ "roman_expression", "eval_roman_expression" ], [ "roman_expression", "roman_to_int" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2c79ae394301a2a23ca9504eb197222c90b0d2db
6f27ca6a36bccdae93e45b87643adacc01a75fc3
v1.0
instruct
Evol
Evol_4829_I
Create a Python function that simulates a simplified version of a genetic algorithm to solve a basic optimization problem. The problem involves finding the maximum value of a given mathematical function, F(x), within a predefined range of x values. The function should include the following steps: - Initialize a populat...
import random def F(x): """ Example fitness function F(x) = -(x-3)**2 + 9 """ return -(x - 3)**2 + 9 def initialize_population(pop_size, x_min, x_max): """ Initialize a population of random x values within the specified range. """ return [random.uniform(x_min, x_max) for _ in range(pop...
import pytest from solution import F, initialize_population, compute_fitness, roulette_wheel_selection, crossover, mutate, genetic_algorithm def test_F(): assert F(3) == 9 assert F(0) == 0 assert F(6) == 0 def test_initialize_population(): population = initialize_population(10, 0, 10) assert l...
[ { "docstring": "Example fitness function F(x) = -(x-3)**2 + 9", "function_declaration": "def F(x):", "function_name": "F", "parameter_list": "(x)" }, { "docstring": "Initialize a population of random x values within the specified range.", "function_declaration": "def initialize_populatio...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef genetic_algorithm(F, x_range, pop_size=50, generations=100, crossover_prob=0.7, mutation_prob=0.01):\n \"\"\"\n Simulates a genetic algo...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00004829", "row_id": 4829, "seed_ids": "[7037]" }
0.433301
Evol_4829
I
[ "F", "initialize_population", "compute_fitness", "roulette_wheel_selection", "crossover", "mutate", "genetic_algorithm" ]
7
[ [ "compute_fitness", "F" ], [ "genetic_algorithm", "compute_fitness" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "initialize_population" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "roulette_wheel_selection" ]...
6
[]
false
[]
false
pytest
true
[]
true
521dd8bf24614e39c7df6ebed88c088d5baf9324
c4297f5a2817ff8f34106d917240d2c9bfd958f0
v1.0
instruct
Evol
Evol_4850_I
Implement a genetic algorithm from scratch in Python to solve a simple optimization problem. Your task is to maximize the function `f(x) = x * sin(10 * pi * x) + 1`, where `x` ranges from 0 to 1. The algorithm should include the following elements: population initialization, fitness evaluation, selection, crossover, mu...
import numpy as np import random def initialize_population(pop_size, chromosome_length): """ Initialize the population with random chromosomes. Each chromosome is binary encoded. """ return np.random.randint(2, size=(pop_size, chromosome_length)) def decode_chromosome(chromosome): """ Deco...
def test_initialize_population(): pop_size = 10 chromosome_length = 8 population = initialize_population(pop_size, chromosome_length) assert population.shape == (pop_size, chromosome_length) assert set(np.unique(population).tolist()).issubset({0, 1}) # Only binary values def test_decode_chromosome...
[ { "docstring": "Initialize the population with random chromosomes.\nEach chromosome is binary encoded.", "function_declaration": "def initialize_population(pop_size, chromosome_length):", "function_name": "initialize_population", "parameter_list": "(pop_size, chromosome_length)" }, { "docstr...
[ 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom math import sin, pi\n\ndef initialize_population(pop_size, gene_length):\n \"\"\"\n Initialize a population with random genes.\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004850", "row_id": 4850, "seed_ids": "[16632]" }
0.397256
Evol_4850
I
[ "initialize_population", "decode_chromosome", "fitness_function", "evaluate_population", "select_parents", "crossover", "mutate", "genetic_algorithm" ]
8
[ [ "evaluate_population", "decode_chromosome" ], [ "evaluate_population", "fitness_function" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "decode_chromosome" ], [ "genetic_algorithm", "evaluate_population" ], [ "genetic_algorithm", ...
8
[]
false
[]
false
pytest
false
[ "numpy" ]
false
de5a9484c618b42b3843c59a9826ad29cb9f5d00
05d4940f52873ec214225307a370b271ec87a897
v1.0
instruct
Evol
Evol_4883_I
Create a program that takes a list of integers and returns a new list that contains only the prime numbers from the original list. Ensure the program performs efficiently even for large lists and correctly identifies prime numbers.
def is_prime(n): """ Determines if a given number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6...
from solution import filter_primes def test_filter_primes_with_no_primes(): assert filter_primes([1, 4, 6, 8, 10]) == [] def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_primes_with_mixed_numbers(): assert filter_primes([10, 11, 12, 13, 14, 15])...
[ { "docstring": "Determines if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the list of numbers and returns a new list containing only the prime numbers.", "function_declaration": "...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004883", "row_id": 4883, "seed_ids": "[8863]" }
0.599718
Evol_4883
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
370b385eed291609427fd98d40f9271b6c933e8c
89af8f0c3478854adda320b16e81ba97a117d9b2
v1.0
instruct
Evol
Evol_4885_I
In a social network graph, users are represented as nodes and their friendships as undirected edges. Write a Python function to determine the largest connected component in such a graph. A connected component is a subset of nodes where there is a path between any pair of nodes within this subset. The function should re...
def bfs(graph, start_node): """ Breadth-First Search to explore all nodes in the connected component from the start_node. """ visited = set() queue = [start_node] while queue: node = queue.pop(0) if node not in visited: visited.add(node) queue.extend(...
from solution import largest_connected_component def test_single_node(): graph = { 1: [] } assert largest_connected_component(graph) == [1] def test_two_connected_nodes(): graph = { 1: [2], 2: [1] } assert sorted(largest_connected_component(graph)) == [1, 2] def test_d...
[ { "docstring": "Breadth-First Search to explore all nodes in the connected component from the start_node.", "function_declaration": "def bfs(graph, start_node):", "function_name": "bfs", "parameter_list": "(graph, start_node)" }, { "docstring": "Returns the largest connected component in the...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def dfs(node, graph, visited):\n \"\"\"\n Perform depth-first search to visit all nodes in the connected component.\n \"\"\"\n stack = [node]\n conn...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004885", "row_id": 4885, "seed_ids": "[34844]" }
0.483434
Evol_4885
I
[ "bfs", "largest_connected_component" ]
2
[ [ "largest_connected_component", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e8e5649c9da457f02935e95702e006a9a19aea9
11dff8e4d085c3168dd9ef5039f12396575daeba
v1.0
instruct
Evol
Evol_4892_I
Given a list of intervals representing lines on a 2D plane, merge all overlapping intervals and return the resulting list of non-overlapping intervals. Each interval is represented as a list of two integers [start, end], where start represents the starting point and end represents the ending point of the interval. Add...
def merge_intervals(intervals): """ Merges the overlapping intervals. """ if not intervals: return [] intervals.sort(key=lambda x: x[0]) merged = [intervals[0]] for current in intervals[1:]: last_merged = merged[-1] if current[0] <= last_merged[1]: ...
from solution import merge_intervals, add_interval, remove_interval def test_merge_intervals(): assert merge_intervals([[1, 3], [2, 4], [5, 7]]) == [[1, 4], [5, 7]] assert merge_intervals([[1, 5], [6, 9]]) == [[1, 5], [6, 9]] assert merge_intervals([[1, 4], [4, 5], [5, 8], [9, 12]]) == [[1, 8], [9, 12]] ...
[ { "docstring": "Merges the overlapping intervals.", "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": "Adds a new interval and merges if there are overlapping intervals.", "function_declaration...
[ 0, 1, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def merge_intervals(intervals):\n \"\"\"\n Merges overlapping intervals and returns a list of non-overlapping intervals.\n \"\"\"\n if not intervals:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004892", "row_id": 4892, "seed_ids": "[34188]" }
0.678019
Evol_4892
I
[ "merge_intervals", "add_interval", "remove_interval" ]
3
[ [ "add_interval", "merge_intervals" ], [ "remove_interval", "merge_intervals" ] ]
2
[]
false
[]
false
pytest
true
[]
true
46f21071b5a6a28e83b7680541eff71f639fc12e
080ba9e207a364d74d094a6f6ec2e437589052cd
v1.0
instruct
Evol
Evol_4913_I
Write a Python function that takes a list of integers as input and returns a new list containing only the prime numbers from the original list. Implement a helper function `is_prime(n)` to determine if a given number is prime. The function signature should be `filter_primes(numbers: List[int]) -> List[int]`.
from typing import List def is_prime(n: int) -> bool: """ Determine if a given number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return ...
from solution import filter_primes def test_filter_primes_with_primes_and_non_primes(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_all_non_primes(): assert filter...
[ { "docstring": "Determine if a given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filt...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004913", "row_id": 4913, "seed_ids": "[30010]" }
0.781363
Evol_4913
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4287e1cc6175f4d057faa5277f1c71687c57c935
79d998745afc5b869f295002613c6ebd77c3f130
v1.0
instruct
Evol
Evol_4993_I
Design a Python function that receives an unsorted list of integers and returns a new list, preserving the original order, but with all prime numbers removed. Ensure the function performs efficiently even with large input lists. For example, given the input list [6, 17, 4, 7, 12, 19, 24], the output should be [6, 4, ...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def remove_primes(lst): """ Returns a ...
from solution import remove_primes def test_remove_primes_with_primes(): assert remove_primes([6, 17, 4, 7, 12, 19, 24]) == [6, 4, 12, 24] def test_remove_primes_no_primes(): assert remove_primes([6, 4, 12, 24]) == [6, 4, 12, 24] def test_remove_primes_all_primes(): assert remove_primes([2, 3, 5, 7, 11])...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list with all primes removed from the input list, preserving the original order.", "function_declaration": "def remove_primes(lst):", "fu...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004993", "row_id": 4993, "seed_ids": "[42236]" }
0.568127
Evol_4993
I
[ "is_prime", "remove_primes" ]
2
[ [ "remove_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91bc16543aa2b788934554d57b0ba5ffaa9ff71f
cf3c76be5e156995a934c9bda9d7bd37f71bf020
v1.0
instruct
Evol
Evol_4998_I
Create a function that classifies a list of numbers into three different categories and returns a dictionary with these categories as keys. Here's the list of numbers: nums = [17, 23, 42, 56, 67, 89, 90, 100, 123] The requirements are: 1. The dictionary should have the following keys: "prime", "even" and "odd". ...
from math import isqrt def is_prime(n): """ Check if a number is prime """ if n <= 1: return False for i in range(2, isqrt(n) + 1): if n % i == 0: return False return True def classify_numbers(nums): """ Classifies a list of numbers into 'prime', 'even', and...
from solution import classify_numbers, is_prime def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-7) assert is_prime(17) def test_classify_numbers(): result = class...
[ { "docstring": "Check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Classifies a list of numbers into 'prime', 'even', and 'odd' categories.\n\nReturns:\n dict: A dictionary with keys 'prime', 'ev...
[ 0, 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def classify_numbers(nums):\n def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004998", "row_id": 4998, "seed_ids": "[44947]" }
0.535694
Evol_4998
I
[ "is_prime", "classify_numbers" ]
2
[ [ "classify_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98db9fbe56b64fac0ea8e13c7d94db0ac73beec1
36598953f73e54082ab12bc42f8166e3ee28b0a3
v1.0
instruct
Evol
Evol_5016_I
Develop a chatbot that uses natural language processing to parse user queries and provide appropriate responses based on a predefined set of rules. The chatbot should be able to handle different types of input, including greetings, questions about operating hours, and requests for product information. Make sure to impl...
import re def parse_query(user_input): """ Parses the user input and returns an appropriate response based on predefined rules. """ user_input = user_input.lower().strip() # Define predefined rules and responses greetings = ["hello", "hi", "hey", "good morning", "good afternoon", "good eve...
from solution import parse_query def test_greeting_responses(): assert parse_query("Hello") == "Hello! How can I assist you today?" assert parse_query("Hi there") == "Hello! How can I assist you today?" assert parse_query("good morning") == "Hello! How can I assist you today?" def test_operating_hours_que...
[ { "docstring": "Parses the user input and returns an appropriate response based on predefined rules.", "function_declaration": "def parse_query(user_input):", "function_name": "parse_query", "parameter_list": "(user_input)" }, { "docstring": "A simple interface function to interact with the ...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import re\n\ndef respond_to_greeting():\n return \"Hello! How can I assist you today?\"\n\ndef respond_to_hours():\n return \"Our operating hours are from 9 ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005016", "row_id": 5016, "seed_ids": "[48115]" }
0.336054
Evol_5016
I
[ "parse_query", "chatbot_interface" ]
2
[ [ "chatbot_interface", "parse_query" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6bbeb42466e0b84ea1438d982dfcf7ff62749c27
02fd6324f21539540b2e2ccb7c51a59d767b32b2
v1.0
instruct
Evol
Evol_5044_I
Write a Python function that takes a list of integers and returns the sum of all integers that are prime numbers. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. Avoid using built-in mathematical functions to check for prime numbers.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True for i in range(2, n): if n % i == 0: return False return True def sum_primes(numbers): """ Returns the sum of all prime numbers in the list. ""...
from solution import sum_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-3) == False ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the list.", "function_declaration": "def sum_primes(numbers):", "function_name": "...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \n A prime number is a natural number greater than 1 that has no po...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005044", "row_id": 5044, "seed_ids": "[42842]" }
0.753374
Evol_5044
I
[ "is_prime", "sum_primes" ]
2
[ [ "sum_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e6c549063e89c2285bdf1ca2ae5793ae7d75515
8ebf3ce68352deb185469e57a90e9801bd690700
v1.0
instruct
Evol
Evol_5045_I
Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array, in the same order. Prime numbers are integers greater than 1 that are only divisible by 1 and themselves. For instance, if the input array is `[4, 7, 10, 13, 17, 22]`, the function should ...
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_primes(arr): ...
from solution import is_prime, filter_primes def test_is_prime(): assert not is_prime(1) assert not is_prime(4) assert is_prime(7) assert not is_prime(10) assert is_prime(13) assert is_prime(17) assert not is_prime(22) assert is_prime(2) assert is_prime(3) assert not is_prime(9)...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns an array containing only the prime numbers from the original array.", "function_declaration": "def filter_pri...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even prim...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005045", "row_id": 5045, "seed_ids": "[52]" }
0.647048
Evol_5045
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
585c6870d2c1cf1b38f17f5f9682393e766ff9cb
810eb4e0487b08e66461306ab324fdc71067a3a3
v1.0
instruct
Evol
Evol_5078_I
Write a function that takes a list of integers and returns the sum of its elements excluding any integers that are prime numbers. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. In your solution, implement a helper function to determine if a number is prime. P...
def is_prime(n): """ Determines if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_excluding_primes(lst): """ Returns the sum of the elements in lst excluding any integers that...
from solution import is_prime, sum_excluding_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(75) == False def test_sum_excluding_primes_no_primes(): assert ...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of the elements in lst excluding any integers that are prime numbers.", "function_declaration": "def sum_...
[ 1, 1, 1, 0, 1, 0, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determines if an integer n is a prime number.\n A prime number is greater than 1 and has no divisors other than 1 and itself.\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005078", "row_id": 5078, "seed_ids": "[17800]" }
0.652076
Evol_5078
I
[ "is_prime", "sum_excluding_primes" ]
2
[ [ "sum_excluding_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2fc6a2acd33c1e4f8202b6d0d9c25fa7957aaf82
e6c459585da170fba8c1c78c9eb6104c90a45b20
v1.0
instruct
Evol
Evol_5106_I
Write a Python program to simulate an ant moving on a 2D grid. The ant starts at position (0, 0) and moves in random directions, one of `['UP', 'DOWN', 'LEFT', 'RIGHT']`, with each step covering a distance of 1 unit. Implement a function that takes an integer `n` as input and returns the final position of the ant after...
import random import math def simulate_ant_movement(n): """ Simulates the movement of an ant on a 2D grid for n steps. Returns the final position of the ant as a tuple (x, y). """ directions = ['UP', 'DOWN', 'LEFT', 'RIGHT'] x, y = 0, 0 for _ in range(n): move = random.choice(d...
from solution import simulate_ant_movement, average_distance_from_origin def test_simulate_ant_movement(): final_position = simulate_ant_movement(0) assert final_position == (0, 0), "Ant should be at the origin if no steps are taken." final_position = simulate_ant_movement(10) assert isinstance(fi...
[ { "docstring": "Simulates the movement of an ant on a 2D grid for n steps.\nReturns the final position of the ant as a tuple (x, y).", "function_declaration": "def simulate_ant_movement(n):", "function_name": "simulate_ant_movement", "parameter_list": "(n)" }, { "docstring": "Simulates the a...
[ 0, 1, 1, 0, 0, 0, 1, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\nimport math\n\ndef move_ant(n):\n \"\"\"\n Simulates the movement of an ant on a 2D grid starting from (0, 0).\n \n Args:\n n (int): ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005106", "row_id": 5106, "seed_ids": "[11547]" }
0.613592
Evol_5106
I
[ "simulate_ant_movement", "average_distance_from_origin" ]
2
[ [ "average_distance_from_origin", "simulate_ant_movement" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a19ad8388ed57f862ef4bfa94140e862a0376338
dc56b3153377b4f600ae1815700ba4e7632d32c1
v1.0
instruct
Evol
Evol_5126_I
Create a function that takes a rectangle (defined as a dictionary with the keys 'length' and 'width') and determines the minimum number of identical square tiles required to cover the entire area of the rectangle without any overlap. The function should return the side length of the square tiles used and the total numb...
import math def gcd(a, b): """ Calculate the Greatest Common Divisor of a and b. """ while b: a, b = b, a % b return a def min_square_tiles(rectangle): """ Determines the side length of the square tiles and the minimum number of square tiles required to cover the entire area o...
from solution import min_square_tiles def test_min_square_tiles_case_1(): rectangle = {'length': 20, 'width': 15} assert min_square_tiles(rectangle) == (5, 12) def test_min_square_tiles_case_2(): rectangle = {'length': 10, 'width': 10} assert min_square_tiles(rectangle) == (10, 1) def test_min_square...
[ { "docstring": "Calculate the Greatest Common Divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Determines the side length of the square tiles and \nthe minimum number of square tiles required to cover the en...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef min_square_tiles(rectangle):\n \"\"\"\n Returns the side length of the largest possible square tile and the number of such tiles required\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005126", "row_id": 5126, "seed_ids": "[7229]" }
0.656166
Evol_5126
I
[ "gcd", "min_square_tiles" ]
2
[ [ "min_square_tiles", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f8a1ef5bf8b3631898c6f232bb7a8d81c98c21a
53b925ccd0f0a706c61b498bf9418308a6b60846
v1.0
instruct
Evol
Evol_5155_I
Implement a function that analyzes the given matrix and categorizes its elements: def matrix_analysis(matrix): ''' Given an m x n matrix containing integers, perform the following tasks based on the matrix elements: 1. Find and return the sum of all prime numbers in the matrix. 2. If the sum of all pri...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_div = int(n ** 0.5) + 1 for i in range(3, max_div, 2): if n % i == 0: return False return True def matrix_analysis(matrix): prime_sum = 0 freq_dict...
from solution import matrix_analysis def test_prime_sum_and_frequency(): assert matrix_analysis([[2, 3, 4], [5, 6, 7], [8, 9, 10]]) == (17, {2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1}) def test_no_primes(): assert matrix_analysis([[1, 4, 6], [8, 9, 10], [12, 14, 15]]) == (-1, {1: 1, 4: 1, 6: 1, 8:...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def matrix_analysis(matrix):", "function_name": "matrix_analysis", "parameter_list": "(matrix)" } ]
[ 1, 0, 1, 1, 1, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n max_div = int(n ** 0.5) ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005155", "row_id": 5155, "seed_ids": "[16013]" }
0.564514
Evol_5155
I
[ "is_prime", "matrix_analysis" ]
2
[ [ "matrix_analysis", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
52b48667db3f8ae3c17316942f9c914e12e0ff69
8a3cf19ae1eedd94f1df688a16711d1cc6405b1c
v1.0
instruct
Evol
Evol_5183_I
Develop a Python function that identifies all the prime numbers up to a given integer `n` through the Sieve of Eratosthenes algorithm. Then, calculate the product of these prime numbers. Additionally, validate the function to handle different edge cases by writing comprehensive test cases. ```python def sieve_of_erat...
def sieve_of_eratosthenes(n): """ Returns a list of prime numbers up to the given integer n using the Sieve of Eratosthenes algorithm. """ if n <= 1: return [] primes = [True] * (n+1) p = 2 while p ** 2 <= n: if primes[p]: for i in range(p * p, n+1, p): ...
from solution import sieve_of_eratosthenes, product_of_primes def test_sieve_of_eratosthenes_basic_cases(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(2) == [2] assert sieve_of_eratosthenes(1) == [] assert sieve_of_eratosthenes(0) == [] def test_sieve_of_eratosthenes...
[ { "docstring": "Returns a list of prime numbers up to the given integer n using\nthe Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns the product of all pri...
[ 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n if n <= 1:\n return []\n primes = [True] * (n + 1)\n p = 2\n while p ** 2 <= n:\n if primes[p]:\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005183", "row_id": 5183, "seed_ids": "[2230]" }
0.654925
Evol_5183
I
[ "sieve_of_eratosthenes", "product_of_primes" ]
2
[ [ "product_of_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c4cb177cef3c5148f4ae0a97d9ae1f7bd6fcf2b
8b9519335d8a9acb8d14a0266f2deb38c8c82165
v1.0
instruct
Evol
Evol_5209_I
Write a Python program that takes a list of integers and returns a new list containing only the prime numbers from the original list. The algorithm should efficiently check for prime numbers.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False # All other even numbers are not primes max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor,...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True assert is_prime(-1) == False assert is_prime(0) == Fals...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filter the list to contain only prime numbers.", "function_declaration": "def filter_primes(numbers):", "function_name": "...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005209", "row_id": 5209, "seed_ids": "[41154]" }
0.701848
Evol_5209
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd8bebf73635c3e5973122430b096de6cb06a14a
0ad1f8cb65a261345246931afa4663534e459b66
v1.0
instruct
Evol
Evol_5265_I
Implement a function that receives a list of integers and returns a new list containing only the prime numbers from the original list. Make sure your solution is efficient and can handle large lists. def filter_primes(int_list): ??? # Example: # input: [10, 15, 3, 7, 9, 11, 13] # output: [3, 7, 11, 13]
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import filter_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True def test_filter_primes_with_primes_and_non_primes(): asser...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the original list.", "function_declaration...
[ 1, 1, 0, 1, 0, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005265", "row_id": 5265, "seed_ids": "[31794]" }
0.619771
Evol_5265
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
36b1591fca7b86ee4b4c39793541f197b416964e
6233f9bee473042b6694a29455cf62caffb70e17
v1.0
instruct
Evol
Evol_5282_I
Design a program that reads a series of temperatures (in Celsius) provided as input from the user, converts each temperature to Fahrenheit, and then determines and prints three things: the highest temperature in Fahrenheit, the lowest temperature in Fahrenheit, and the average temperature in Fahrenheit. Ensure the prog...
def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 def process_temperatures(temperatures): if not temperatures: raise ValueError("No temperatures provided") fahrenheit_temps = [celsius_to_fahrenheit(temp) for temp in temperatures] highest_temp = max(fahrenheit_temps) ...
from solution import celsius_to_fahrenheit, process_temperatures def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 assert celsius_to_fahrenheit(37) == 98.6 def test_process_temperatures_single_input...
[ { "docstring": null, "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": null, "function_declaration": "def process_temperatures(temperatures):", "function_name": "process_temperature...
[ 0, 0, 1, 1, 0, 1, 1, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef process_temperatures(celsi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005282", "row_id": 5282, "seed_ids": "[8863]" }
0.428988
Evol_5282
I
[ "celsius_to_fahrenheit", "process_temperatures" ]
2
[ [ "process_temperatures", "celsius_to_fahrenheit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31276e38142bd1b56164f245ca0030bf41b2c87a
6be671d240fa770cdd20a27ba192b00cecfee39c
v1.0
instruct
Evol
Evol_5284_I
Design a function that takes an array of integers as input and returns a new array containing only the prime numbers from the original array. Write a function `isPrime(n)` that checks if a number is prime, and use it within your main function. Ensure your function handles edge cases such as an empty array or an array w...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes an array of integers and returns a new array containing only the prime numbers from the original a...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def isPrime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005284", "row_id": 5284, "seed_ids": "[43360]" }
0.677425
Evol_5284
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7a9a1842473035d3de4f8725794481787fd9256
c4bece7c89eace95a00c731b258f3696bfb24160
v1.0
instruct
Evol
Evol_5308_I
Design an algorithm to simulate a simplified version of a basic blackjack game using Python. In this game, the player and the dealer each receive two cards initially. The player can choose to "hit" to receive another card or "stand" to keep their current hand. The goal is to have the highest hand value without exceedin...
import random # Function to shuffle and deal cards def shuffle_and_deal(): """ Shuffles the deck and deals the initial two cards for player and dealer. Returns: deck (list): Remaining cards in the deck. player_hand (list): Cards in player's hand. dealer_hand (list): Cards in dealer'...
from solution import shuffle_and_deal, calculate_hand_value # Unit test for shuffle_and_deal function def test_shuffle_and_deal(): deck, player_hand, dealer_hand = shuffle_and_deal() assert len(deck) == 48 assert len(player_hand) == 2 assert len(dealer_hand) == 2 # Unit test for calculate_hand_value f...
[ { "docstring": "Shuffles the deck and deals the initial two cards for player and dealer.\nReturns:\n deck (list): Remaining cards in the deck.\n player_hand (list): Cards in player's hand.\n dealer_hand (list): Cards in dealer's hand.", "function_declaration": "def shuffle_and_deal():", "functi...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\n# Define the card deck and values\ndeck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] * 4\n\n# Function to shuffle and deal cards\ndef shuffle_de...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005308", "row_id": 5308, "seed_ids": "[47429]" }
0.541218
Evol_5308
I
[ "shuffle_and_deal", "calculate_hand_value", "blackjack" ]
3
[ [ "blackjack", "calculate_hand_value" ], [ "blackjack", "shuffle_and_deal" ] ]
2
[]
false
[]
false
pytest
true
[]
true
83a7724b47145256c02d01b0046cd6cf3e769ce0
8f6f46f6d0d171095b8d3944ae2456a3e6438af0
v1.0
instruct
Evol
Evol_5394_I
Consider an $n \times n$ matrix filled with integers where each element falls in the range $[0, n-1]$. We define a special type of transformation on the matrix: - Rotate the matrix 90 degrees clockwise. - Reflect the matrix horizontally (flip along the vertical axis). - Reflect the matrix vertically (flip along the hor...
def factorial(n): """ Returns the factorial of n. """ if n == 0 or n == 1: return 1 else: result = 1 for i in range(2, n+1): result *= i return result def f(n): """ Finds the maximum number of n x n matrices such that no two matrices are equivalen...
from solution import factorial, f def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 def test_f(): assert f(2) == (factorial(4) % (10**9 + 7)) assert f(3) == (fac...
[ { "docstring": "Returns the factorial of n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Finds the maximum number of n x n matrices such that no two matrices are equivalent\nunder the given transformations.", "fun...
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def f(n):\n \"\"\"\n Returns the number of unique n x n matrices that are not equivalent under any series of transformations.\n This solution is specific ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005394", "row_id": 5394, "seed_ids": "[26981]" }
0.6096
Evol_5394
I
[ "factorial", "f" ]
2
[ [ "f", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c20398d2aee43f8ce2bebd422a430b91d1c4a749
dd2a18fb1fd92448a797eefc40b2ad37ced4d154
v1.0
instruct
Evol
Evol_5396_I
Implement a function in Python that accepts a list of integers and returns a new list that contains only the prime numbers from the original list. In your response, demonstrate the use of fundamental principles and describe the steps taken to determine the primality of each number.
def is_prime(n): """ Determines if an integer n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return Tru...
from solution import filter_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(0) == False assert is_prime(1) == False assert is_prime(-5) == False assert is_prime(17) == Tru...
[ { "docstring": "Determines if an integer n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the input list.", "function_declaration": "def filter_prime...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005396", "row_id": 5396, "seed_ids": "[41315]" }
0.684168
Evol_5396
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d77211a61272416a70c35bece0d5605f79ec86f
48700c911c723f39f8497f4b3640945bba2b53aa
v1.0
instruct
Evol
Evol_5407_I
Write a function to manage a library where each book is represented as an object with the following structure: ``` book = { 'title': 'The Great Gatsby', 'author': 'F. Scott Fitzgerald', 'publicationYear': 1925, 'genres': ['Classic', 'Fiction'], 'availableCopies': 3, 'reservations': [ {'m...
import datetime def is_valid_year(year): current_year = datetime.datetime.now().year return isinstance(year, int) and 1500 <= year <= current_year def is_valid_date(date_str): try: datetime.datetime.strptime(date_str, '%Y-%m-%d') return True except ValueError: return False def...
import pytest from solution import add_book, reserve_book, cancel_reservation, check_availability def test_add_book_success(): library = [] book = { 'title': 'The Great Gatsby', 'author': 'F. Scott Fitzgerald', 'publicationYear': 1925, 'genres': ['Classic', 'Fiction'], '...
[ { "docstring": null, "function_declaration": "def is_valid_year(year):", "function_name": "is_valid_year", "parameter_list": "(year)" }, { "docstring": null, "function_declaration": "def is_valid_date(date_str):", "function_name": "is_valid_date", "parameter_list": "(date_str)" ...
[ 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import datetime\n\ndef add_book(library, book):\n current_year = datetime.datetime.now().year\n \n # Validate the book fields\n if not isinstance(book[...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005407", "row_id": 5407, "seed_ids": "[22634]" }
0.496591
Evol_5407
I
[ "is_valid_year", "is_valid_date", "add_book", "reserve_book", "cancel_reservation", "check_availability" ]
6
[ [ "add_book", "is_valid_year" ], [ "reserve_book", "is_valid_date" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3b1cfec722bf4c5dd8d8811f0fa7a9dcb397bdfc
a7d56029fac5471f01469320e9524f22c5646128
v1.0
instruct
Evol
Evol_5454_I
Write a Python program that reads a list of email addresses from a text file and filters out the invalid email addresses. The valid email addresses should then be saved to a new text file. An email is considered valid if it follows this pattern: it must consist of a local part and a domain part separated by an '@' symb...
import re def is_valid_email(email): """ Validates if the given email follows the correct email format. """ # Define the regular expression for a valid email. local_part = r"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*" domain_part = r"([a-zA-Z0-9](?:[-a-zA-Z0-9]*[a-zA-Z0...
from solution import is_valid_email, filter_emails import os def test_is_valid_email(): # Valid emails assert is_valid_email("test@example.com") assert is_valid_email("first.last@iana.org") assert is_valid_email("test.email+alex@leetcode.com") # Invalid emails assert not is_valid_email("pl...
[ { "docstring": "Validates if the given email follows the correct email format.", "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": "Reads emails from the input file, filters out the invalid ones, and writes ...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import re\n\ndef is_valid_email(email):\n \"\"\"\n Check if the given email is valid based on the specified pattern.\n \"\"\"\n email_regex = re.compil...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005454", "row_id": 5454, "seed_ids": "[30725]" }
0.552542
Evol_5454
I
[ "is_valid_email", "filter_emails" ]
2
[ [ "filter_emails", "is_valid_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
200c0efd4dcf7e30eae1f4ce1c393bbf20cac4c8
7ffde37937c623980511f56df3b91ed6d9c3c3c5
v1.0
instruct
Evol
Evol_5538_I
Develop a Python function that takes a list of integers as input and returns a new list with all the prime numbers from the original list sorted in descending order. Ensure that your function handles edge cases, such as an empty list or a list with no prime numbers, appropriately.
def is_prime(n): """ Helper function that checks if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def filter...
from solution import filter_and_sort_primes def test_filter_and_sort_primes_regular_case(): assert filter_and_sort_primes([3, 5, 7, 8, 10, 11, 4]) == [11, 7, 5, 3] def test_filter_and_sort_primes_with_no_primes(): assert filter_and_sort_primes([4, 6, 8, 10, 12]) == [] def test_filter_and_sort_primes_with_all...
[ { "docstring": "Helper function that checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list with all the prime numbers from the original list sorted in descending order.", "fu...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005538", "row_id": 5538, "seed_ids": "[11397]" }
0.670086
Evol_5538
I
[ "is_prime", "filter_and_sort_primes" ]
2
[ [ "filter_and_sort_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f9bdc1a4f3056541ff3e67fb4074e8f2eb14e15
c0ba1f7bb214fc156b6147f23ea52ba2b72f9632
v1.0
instruct
Evol
Evol_5563_I
Write a Python function that takes a list of integers and rearranges the elements to form the largest possible integer. The function should return this largest integer as a string. Assume the input list will contain only non-negative integers. Example: ``` Input: [3, 30, 34, 5, 9] Output: '9534330' Input: [1, 20, 23,...
from functools import cmp_to_key def compare(a, b): if a + b > b + a: return -1 elif a + b < b + a: return 1 else: return 0 def largest_number(nums): if not nums: return "" # Convert the numbers to strings for comparison nums_str = list(map(str, nums)) ...
from solution import largest_number def test_largest_number_basic(): assert largest_number([3, 30, 34, 5, 9]) == '9534330' assert largest_number([1, 20, 23, 4, 8]) == '8423201' def test_largest_number_single_element(): assert largest_number([5]) == '5' assert largest_number([0]) == '0' def test_large...
[ { "docstring": null, "function_declaration": "def compare(a, b):", "function_name": "compare", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def largest_number(nums):", "function_name": "largest_number", "parameter_list": "(nums)" } ]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef compare(x, y):\n \"\"\"\n A comparison function that decides the order based on which\n concatenation results in a...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005563", "row_id": 5563, "seed_ids": "[36518]" }
0.688915
Evol_5563
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa6444821fadd1181d2ef63ee8e98a55b852c796
58a810cd287e6332a24be099df8bb97e0b8d0bbc
v1.0
instruct
Evol
Evol_5565_I
Implement a function that simulates a game of Tic-Tac-Toe for two players. The function should accept a series of moves as input and determine the result of the game. Ensure that the function handles invalid moves (e.g., out-of-bounds or already occupied cells). The function should print the final state of the board af...
def check_winner(board): """ Checks the board to determine if there is a winner. Returns "X" if player X wins, "O" if player O wins, and None otherwise. """ # Check rows, columns, and diagonals for a winner win_conditions = ( [(0, 0), (0, 1), (0, 2)], # first row [(1, 0), (1, 1...
from solution import tic_tac_toe def test_tic_tac_toe_x_wins(): moves = [ (0, 0, 'X'), (1, 0, 'O'), (0, 1, 'X'), (1, 1, 'O'), (0, 2, 'X') ] assert tic_tac_toe(moves) == "X wins" def test_tic_tac_toe_o_wins(): moves = [ (0, 0, 'O'), (1, 0, 'X'), ...
[ { "docstring": "Checks the board to determine if there is a winner.\nReturns \"X\" if player X wins, \"O\" if player O wins, and None otherwise.", "function_declaration": "def check_winner(board):", "function_name": "check_winner", "parameter_list": "(board)" }, { "docstring": "Checks if the...
[ 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def tic_tac_toe(moves):\n \"\"\"\n Simulates a game of Tic-Tac-Toe for two players based on a series of moves.\n Returns the final state of the board and ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005565", "row_id": 5565, "seed_ids": "[15743]" }
0.56019
Evol_5565
I
[ "check_winner", "is_full", "tic_tac_toe", "print_board" ]
4
[ [ "tic_tac_toe", "check_winner" ], [ "tic_tac_toe", "is_full" ], [ "tic_tac_toe", "print_board" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5189188534f2dafee1aaf63176ae64c7a6de267c
b1e78cfe5c9d224cb982d9dbe9618c3d45e17486
v1.0
instruct
Evol
Evol_5566_I
You are given a function that finds the longest palindrome in a given string. There are errors in the implementation. Your task is to correct the given Python function. ```python def longest_palindrom(s): start = 0 end = 0 for i in range(len(str)): l1 = expandFromCenter(s, i, i) l2 = expan...
def longest_palindrome(s): """ Returns the longest palindromic substring in the input string s. """ if not s: return "" start = 0 end = 0 for i in range(len(s)): l1 = expandFromCenter(s, i, i) l2 = expandFromCenter(s, i, i + 1) l = max(l1, l2) if l >...
def test_longest_palindrome(): assert longest_palindrome('babad') in ['bab', 'aba'] assert longest_palindrome('cbbd') == 'bb' assert longest_palindrome('a') == 'a' assert longest_palindrome('ac') in ['a', 'c'] assert longest_palindrome('racecar') == 'racecar' assert longest_palindrome('banana') ...
[ { "docstring": "Returns the longest palindromic substring in the input string s.", "function_declaration": "def longest_palindrome(s):", "function_name": "longest_palindrome", "parameter_list": "(s)" }, { "docstring": "Expands around the center and returns the length of the palindromic subst...
[ 1, 0, 1, 0, 1, 0, 1, 0, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def longest_palindrome(s):\n \"\"\"\n Returns the longest palindromic substring in the given input string s.\n \"\"\"\n start, end = 0, 0\n\n for i ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00005566", "row_id": 5566, "seed_ids": "[26256]" }
0.759747
Evol_5566
I
[ "longest_palindrome", "expandFromCenter" ]
2
[ [ "longest_palindrome", "expandFromCenter" ] ]
1
[]
false
[]
false
pytest
false
[]
true
92105c823ae2ef3aed8eb12b96371ff18648d3b6
fcbe33c45c49b33371e35d271ba66f9ee1ac63f3
v1.0
instruct
Evol
Evol_5608_I
Create and implement a sentiment analysis pipeline for a movie review dataset using a custom-built Naive Bayes classifier. The project should be able to classify reviews as positive or negative based on their content. Your implementation should include the following steps: 1. **Data Preprocessing**: Explain and imple...
import re import numpy as np from collections import Counter, defaultdict from sklearn.model_selection import train_test_split, StratifiedKFold from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score # Data Preprocessing def preprocess_text(text): # Tokenization, lowercasing, and removi...
import pytest from solution import preprocess_text, build_vocabulary, text_to_bow, NaiveBayesClassifier def test_preprocess_text(): text = "The quick brown fox jumps over the lazy dog. 123!" expected = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"] assert preprocess_text(text) == e...
[]
[ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import numpy as np\nimport pandas as pd\nfrom collections import defaultdict\nimport re\nfrom sklearn.model_selection import train_test_split, StratifiedKFold\nfro...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00005608", "row_id": 5608, "seed_ids": "[40694]" }
0.532971
Evol_5608
I
[ "preprocess_text", "build_vocabulary", "text_to_bow", "evaluate_model", "cross_validation" ]
5
[ [ "build_vocabulary", "preprocess_text" ], [ "cross_validation", "evaluate_model" ], [ "text_to_bow", "preprocess_text" ] ]
3
[]
false
[ "NaiveBayesClassifier" ]
true
pytest
true
[ "numpy", "sklearn" ]
false
9d653e6b9114d5396f89bb765e99837c842b01ff
3a928df5435072934995122376cdf1821fef71e4