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_1397_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.
The function should be able to handle negative numbers, zero, and large integers. It should be optimized to perform well with large datasets.
The provided array is: [... | def is_prime(n):
"""
Check if the 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 False
return True
def filter_primes(num... | 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(17) == True
assert is_prime(-3) == False
assert is_prime(0) == False
assert is_prime(1) == False
def test_filter_primes():
... | [
{
"docstring": "Check if the number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out the prime numbers from a list of integers.",
"function_declaration": "def filter_primes(numbers):",
... | [
0,
1,
1,
1,
1,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"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 == 2:\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001397",
"row_id": 1397,
"seed_ids": "[24359]"
} | 0.660261 | Evol_1397 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f8c7140b4ba5b845ed73b3217b9c9b90db573017 | 79daf252461bc707aabaa4aa3e323cbbfa6eacdd | |||
v1.0 | instruct | Evol | Evol_1478_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, but the order of the prime numbers should be in descending order. For assistance, you can refer to this link: https://www.geeksforgeeks.org/python-program-to-check-whether-a-nu... | def is_prime(num):
"""
Checks 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 get_primes_in_desce... | from solution import is_prime, get_primes_in_descending_order
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(19) == True
assert is_prime(1) == False
assert is... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Takes a list of integers and returns a new list containing only the prime numbers\nfrom the original list, in descending orde... | [
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 Checks 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_9 | {
"original_instruction": "",
"prompt_id": "00001478",
"row_id": 1478,
"seed_ids": "[4401]"
} | 0.684845 | Evol_1478 | I | [
"is_prime",
"get_primes_in_descending_order"
] | 2 | [
[
"get_primes_in_descending_order",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6c2c2eeb890e4448d87fb3af7a0199a1eba3597c | 3d278a3bc50a2fc5fb54a998119bf8a893c766ec | |||
v1.0 | instruct | Evol | Evol_1503_I | Develop a program that takes a Roman numeral as input and converts it to its equivalent integer value. Ensure that the program handles invalid Roman numeral inputs by returning an appropriate error message. | def roman_to_int(roman):
"""
Converts a Roman numeral to an integer.
Returns an integer if the Roman numeral is valid, otherwise returns an error message.
"""
roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
# Validate the Roman numeral
for ch in roman:
... | from solution import roman_to_int
def test_valid_roman_numerals():
assert roman_to_int("III") == 3
assert roman_to_int("IV") == 4
assert roman_to_int("IX") == 9
assert roman_to_int("LVIII") == 58
assert roman_to_int("MCMXCIV") == 1994
def test_invalid_roman_numerals():
assert roman_to_int("III... | [
{
"docstring": "Converts a Roman numeral to an integer.\nReturns an integer if the Roman numeral is valid, otherwise returns an error message.",
"function_declaration": "def roman_to_int(roman):",
"function_name": "roman_to_int",
"parameter_list": "(roman)"
},
{
"docstring": "Converts an int... | [
0,
0,
0,
0,
0,
0,
0,
1,
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 roman_to_int(s):\n \"\"\"\n Converts a roman numeral to an integer.\n If the input is invalid, returns an error message.\n \"\"\"\n roman_to_int... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001503",
"row_id": 1503,
"seed_ids": "[42136]"
} | 0.548599 | Evol_1503 | I | [
"roman_to_int",
"int_to_roman"
] | 2 | [
[
"roman_to_int",
"int_to_roman"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2ab57902c19ff04d33c88a2d8675e12f73b9564b | 7c511785c64ac77c62a12a47c82316f958e650e9 | |||
v1.0 | instruct | Evol | Evol_1523_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 to check for prime numbers, ensuring optimal performance by using the square root method for divisibility checks. | import math
def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns 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:
... | 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(17) == True
assert is_prime(18) == False
assert is_prime(-1) == False
assert is_prime(0) == Fals... | [
{
"docstring": "Returns True if n is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the input list 'numbers'.",
"function_declaration": "de... | [
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 Check if a number is a prime number.\n :param n: Integer to check\n :return: True if n is prime, else False\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001523",
"row_id": 1523,
"seed_ids": "[28199]"
} | 0.705683 | Evol_1523 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0244c82dedceb9b04053aab851fe5815dd52b6f3 | eb7fcb85fc26d724e6af1c09dd61053cebd2235c | |||
v1.0 | instruct | Evol | Evol_1534_I | Implement a function in Python that takes a list of integers as input and returns a new list with only the prime numbers from the original list. Utilize a helper function to determine if a number is prime. It's important that the main function has a time complexity no worse than O(n * sqrt(m)), where 'n' is the length ... | from math import isqrt
def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num < 2:
return False
for i in range(2, isqrt(num) + 1):
if num % i == 0:
return False
return True
def filter_primes(numbers):
"""
Returns a list of prime... | 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 determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the given list of integers.",
"function_declaration": "def fil... | [
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_9 | {
"original_instruction": "",
"prompt_id": "00001534",
"row_id": 1534,
"seed_ids": "[36475]"
} | 0.734917 | Evol_1534 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 59979d7d267777d7051c6ed010aa38cef6941524 | 7401b7833f2f16740aa8f36d85eb2a2d246fa7f0 | |||
v1.0 | instruct | Evol | Evol_1570_I | Given a large directory of files, design a program that searches for a specific keyword in each file and lists the filenames that contain the keyword. The program should be able to handle different file formats (text, JSON, CSV, etc.) and should be optimized for performance to effectively handle the processing of thous... | import os
import json
import csv
def search_keyword_in_file(filepath, keyword):
count = 0
try:
if filepath.endswith('.txt'):
with open(filepath, 'r', errors='ignore') as f:
content = f.read()
count = content.count(keyword)
elif filepath.endswith('.jso... | import tempfile
import os
from solution import search_keyword_in_directory
def create_temp_file(directory, filename, content):
filepath = os.path.join(directory, filename)
with open(filepath, 'w') as f:
f.write(content)
return filepath
def test_search_keyword_in_directory():
with tempfile.Temp... | [
{
"docstring": null,
"function_declaration": "def search_keyword_in_file(filepath, keyword):",
"function_name": "search_keyword_in_file",
"parameter_list": "(filepath, keyword)"
},
{
"docstring": null,
"function_declaration": "def search_keyword_in_directory(directory, keyword):",
"f... | [
0,
1,
1,
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 os\nimport json\nimport csv\n\ndef search_keyword_in_file(file_path, keyword):\n try:\n if file_path.endswith('.txt'):\n with open(file... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00001570",
"row_id": 1570,
"seed_ids": "[43519]"
} | 0.637625 | Evol_1570 | I | [
"search_keyword_in_file",
"search_keyword_in_directory"
] | 2 | [
[
"search_keyword_in_directory",
"search_keyword_in_file"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d326135df6253756c733880decbbd7f10d6f6a7 | c200098e7c58090f38d5e0b9ff1bbc302e7780a3 | |||
v1.0 | instruct | Evol | Evol_1577_I | Create a function to sort an array of integers using the merge sort algorithm. Your implementation should divide the array into two halves, recursively sort each half, and then merge the sorted halves back together. The function should also handle edge cases such as an empty array or an array with a single element.
Ad... | def merge_sort(arr):
if len(arr) < 2:
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, right):
result = []
i = j = 0
while i < len(left) and j < len(right):
if left[i] ... | from solution import merge_sort, count_inversions
def test_merge_sort_empty_array():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_unsorted_arra... | [
{
"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)"
},
{
"docst... | [
1,
1,
1,
0,
1,
1,
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 merge_sort(arr):\n \"\"\"\n Returns a sorted array using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n mid = le... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001577",
"row_id": 1577,
"seed_ids": "[45156]"
} | 0.676395 | Evol_1577 | I | [
"merge_sort",
"merge",
"count_inversions",
"merge_sort_and_count",
"merge_and_count"
] | 5 | [
[
"count_inversions",
"merge_sort_and_count"
],
[
"merge_sort",
"merge"
],
[
"merge_sort_and_count",
"merge_and_count"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ae126e04362c6db1c1f71b8bcd1c3e8c17bde210 | a1b555c00f10a97fb686cb615c0b49f8ad82ca5f | |||
v1.0 | instruct | Evol | Evol_1599_I | Implement the K-means clustering algorithm from scratch to partition a dataset into K clusters. The dataset consists of points in a 2D space. Your implementation should include steps for initializing centroids, assigning points to the nearest centroid, and updating centroids based on the assigned points. After a specif... | import numpy as np
def initialize_centroids(X, K):
"""
Initializes K centroids randomly selected from the data points.
"""
indices = np.random.choice(np.arange(len(X)), size=K, replace=False)
return X[indices]
def closest_centroids(X, centroids):
"""
Assigns each data point to the closest ... | import numpy as np
from solution import initialize_centroids, closest_centroids, update_centroids, kmeans
def test_initialize_centroids():
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
centroids = initialize_centroids(X, 2)
assert centroids.shape == (2, 2)
assert len(set(tuple(point) for point in cent... | [
{
"docstring": "Initializes K centroids randomly selected from the data points.",
"function_declaration": "def initialize_centroids(X, K):",
"function_name": "initialize_centroids",
"parameter_list": "(X, K)"
},
{
"docstring": "Assigns each data point to the closest centroid.",
"function... | [
0,
1,
1,
0,
0,
1,
0,
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 numpy as np\n\ndef initialize_centroids(points, k):\n \"\"\"\n Randomly initialize `k` centroids from the `points`.\n \"\"\"\n return points[np.... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00001599",
"row_id": 1599,
"seed_ids": "[36846]"
} | 0.638768 | Evol_1599 | I | [
"initialize_centroids",
"closest_centroids",
"update_centroids",
"kmeans"
] | 4 | [
[
"kmeans",
"closest_centroids"
],
[
"kmeans",
"initialize_centroids"
],
[
"kmeans",
"update_centroids"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 280fce37d68cdca296b15018db160c877ce88df3 | a1bb3cd811f38188effd71bef053b3181ae3df32 | |||
v1.0 | instruct | Evol | Evol_1615_I | Write a program that takes a list of integers and returns the sum of all prime numbers in the list. If no prime numbers are found, return 0.
Example:
Input: [4, 6, 9, 11, 20, 23]
Output: 34
Explanation:
Prime numbers in the list are 11 and 23, their sum is 34. | def is_prime(num):
"""
Helper function to 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... | from solution import sum_of_primes
def test_sum_of_primes_with_primes():
assert sum_of_primes([4, 6, 9, 11, 20, 23]) == 34
def test_sum_of_primes_without_primes():
assert sum_of_primes([4, 6, 8, 10, 20]) == 0
def test_sum_of_primes_all_primes():
assert sum_of_primes([2, 3, 5, 7, 11]) == 28
def test_sum_... | [
{
"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 the sum of all prime numbers in the list.\nIf no prime numbers are found, returns 0.",
"functio... | [
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_2 | {
"original_instruction": "",
"prompt_id": "00001615",
"row_id": 1615,
"seed_ids": "[5581]"
} | 0.637671 | Evol_1615 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6465c8a9db62cd627c9637d700f0adab800f5dd | 6c039a1fac5d6c033a0507bb6a72f9ea3bfd83d9 | |||
v1.0 | instruct | Evol | Evol_1623_I | Design a Python program that reads a CSV file containing rows of numerical data representing different stocks' prices over time. Your task is to implement the Exponential Moving Average (EMA) for each stock. The program should allow the user to specify the span for the EMA calculation. Present the results as a new CSV ... | import pandas as pd
import matplotlib.pyplot as plt
def calculate_ema(data, span):
"""
Computes the Exponential Moving Average (EMA) for a given data series.
Parameters:
- data (pandas.Series): The data series to compute the EMA on.
- span (int): The span for the EMA calculation.
Returns:... | import pandas as pd
import tempfile
import pytest
from solution import calculate_ema, process_csv, plot_stock_with_ema
def test_calculate_ema():
data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
span = 2
expected_ema = pd.Series([1.0, 1.6666667, 2.5555556, 3.5185185, 4.5061728, 5.5020577, 6.5006862, 7.5002... | [
{
"docstring": "Computes the Exponential Moving Average (EMA) for a given data series.\n\nParameters:\n- data (pandas.Series): The data series to compute the EMA on.\n- span (int): The span for the EMA calculation.\n\nReturns:\n- pandas.Series: The EMA of the input data series.",
"function_declaration": "de... | [
0,
0,
0,
0,
0,
1,
1,
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": "import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef calculate_ema(df, span):\n \"\"\"\n Calculate the Exponential Moving Average ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001623",
"row_id": 1623,
"seed_ids": "[19369]"
} | 0.523031 | Evol_1623 | I | [
"calculate_ema",
"process_csv",
"plot_stock_with_ema"
] | 3 | [
[
"plot_stock_with_ema",
"calculate_ema"
],
[
"process_csv",
"calculate_ema"
]
] | 2 | [] | false | [] | false | pytest | true | [
"matplotlib",
"pandas"
] | false | 7125b9450479d7f70ece7d7c357b66b59a1a9ecc | ec35c8840f7fea9a98144cf943f5b71bd1214c6a | |||
v1.0 | instruct | Evol | Evol_1656_I | Create a Python function that takes a list of integers, and returns a new list where each element is the factorial of the corresponding element in the input list. The function should not use any external libraries like `math`. Demonstrate your function with the list [3, 4, 5]. | def factorial(n):
"""
Helper function to calculate the factorial of a number.
"""
if n == 0:
return 1
result = 1
for i in range(1, n + 1):
result *= i
return result
def list_factorial(lst):
"""
Returns a list where each element is the factorial of the corresponding e... | from solution import list_factorial, factorial
def test_factorial_zero():
assert factorial(0) == 1
def test_factorial_positive_numbers():
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
def test_list_factorial():
... | [
{
"docstring": "Helper function to calculate the factorial of a number.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list where each element is the factorial of the corresponding element in the input list.",... | [
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 factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n for i in range(1, ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001656",
"row_id": 1656,
"seed_ids": "[32997]"
} | 0.707161 | Evol_1656 | I | [
"factorial",
"list_factorial"
] | 2 | [
[
"list_factorial",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ececcf8ffd1ffae22a18f5e50b5feced6e805c49 | f224a146f17ad1973fdf6469e07380e55c58a547 | |||
v1.0 | instruct | Evol | Evol_1690_I | Write a Python function that takes a list of integers and returns the list of prime numbers in the same order they appear in the input list. If the list is empty or does not contain any prime numbers, return an empty list.
**Example:**
```python
def filter_primes(numbers):
pass
# Sample Input:
numbers = [10, 15... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise 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... | from solution import filter_primes
def test_primes_in_mixed_list():
assert filter_primes([10, 15, 3, 7, 19, 6]) == [3, 7, 19]
def test_no_primes():
assert filter_primes([4, 6, 8]) == []
def test_empty_list():
assert filter_primes([]) == []
def test_all_primes():
assert filter_primes([2, 3, 5, 7, 11]... | [
{
"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": "Filters the prime numbers from the list of integers and returns a new list with only 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 is_prime(n):\n \"\"\"\n Checks if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is a p... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00001690",
"row_id": 1690,
"seed_ids": "[43472]"
} | 0.709802 | Evol_1690 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b07afa3b5b59de3e38b4b5e3bf72a6395539c547 | dab8bd5879c84b75249cd44ddf8471228b8ee1cd | |||
v1.0 | instruct | Evol | Evol_1696_I | Create a function in Python that takes a list of integers and returns a new list containing only the prime numbers from the original list. Ensure that the function handles an empty list input as well and returns an empty list in that case. An example of the function call and its expected output is provided below:
```p... | 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 filter_primes(numbers):
"""
Returns a list containing only the prime numbers from the original list.
"""
return [num for num in numbers if is_... | from solution import filter_primes
def test_filter_primes_with_primes():
assert filter_primes([2, 4, 6, 7, 9, 11, 13]) == [2, 7, 11, 13]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_filter_primes_with_empty_list():
assert filter_primes([]) == []
def test... | [
{
"docstring": null,
"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 list.",
"function_declaration": "def filter_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 Helper function to determine if a number is prime.\n Returns True if n is prime, False otherwise.\n \"\"\"\n if n <= 1:\... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001696",
"row_id": 1696,
"seed_ids": "[35128]"
} | 0.626693 | Evol_1696 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0028ce24295d72aef768263cfcce4b60936ed9f0 | 18e4184a2ca51a827a97244703c49030876d42ee | |||
v1.0 | instruct | Evol | Evol_1733_I | You are given an unsorted array of integers. Design and implement an algorithm to sort the array using the Merge Sort technique. Additionally, analyze the algorithm's time and space complexity. Discuss the scenarios where Merge Sort would be preferred over other sorting algorithms like Quick Sort. | def merge_sort(arr):
"""
Sorts an array of integers using the Merge Sort algorithm.
"""
if len(arr) <= 1:
return arr
# Splitting the array into two halves
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])
# Merging the sorted h... | from solution import merge_sort
def test_merge_sort_already_sorted():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted():
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_merge_sort_random_order():
assert merge_sort([3, 1, 4, 5, 2]) == [1, 2, 3, 4, 5]... | [
{
"docstring": "Sorts an array of integers using the Merge Sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted arrays into one sorted array.",
"function_declaration": "def merge(le... | [
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 Sorts an array using Merge Sort technique.\n \n Parameters:\n arr (list): The unsorted array of integers.\n \n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001733",
"row_id": 1733,
"seed_ids": "[18200]"
} | 0.710495 | Evol_1733 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02c475c58c8818661583e644ceea06b5b62a6417 | 947a8ab89cd8fd2becce648fff683ab8b18119e6 | |||
v1.0 | instruct | Evol | Evol_1737_I | Implement a function `merge_sorted_lists` that takes in two sorted lists and merges them into a single sorted list. You are required to maintain the order of elements, ensuring that the final list is sorted in ascending order.
Additionally, the function should handle nested lists where each element within the nested ... | def flatten(lst):
"""
Helper function to flatten a nested list.
"""
flattened_list = []
for item in lst:
if isinstance(item, list):
flattened_list.extend(flatten(item))
else:
flattened_list.append(item)
return flattened_list
def merge_sorted_lists(list1, ... | from solution import flatten, merge_sorted_lists
def test_flatten():
assert flatten([1, [2, 3], 4, [5, [6, 7]]]) == [1, 2, 3, 4, 5, 6, 7]
assert flatten([1, 2, [3]]) == [1, 2, 3]
assert flatten([[1, 2], 3]) == [1, 2, 3]
assert flatten([1, [2], 3, [4, [5]]]) == [1, 2, 3, 4, 5]
def test_merge_sorted_lis... | [
{
"docstring": "Helper function to flatten a nested list.",
"function_declaration": "def flatten(lst):",
"function_name": "flatten",
"parameter_list": "(lst)"
},
{
"docstring": "Merges two sorted lists into one sorted list, handling nested lists.",
"function_declaration": "def merge_sort... | [
1,
1,
0,
0,
1,
1,
0,
1,
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 flatten_and_merge(list1, list2):\n \"\"\"\n This function takes in two sorted lists, possibly containing nested lists,\n flattens them and merges them... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001737",
"row_id": 1737,
"seed_ids": "[36209]"
} | 0.560326 | Evol_1737 | I | [
"flatten",
"merge_sorted_lists"
] | 2 | [
[
"merge_sorted_lists",
"flatten"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36e3db967f1775548c9654b5ddd17ef2e88e259b | 936d6591796cba307d4747b8b34a80e6df30147a | |||
v1.0 | instruct | Evol | Evol_1744_I | Create a function in Python that accepts a list of integers and returns a list of tuples, where each tuple contains a pair of numbers from the input list whose product is a prime number. If no such pairs exist, return an empty list. Ensure your solution properly handles edge cases such as input lists with fewer than tw... | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False # other even numbers are not prime
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
... | from solution import is_prime, pairs_with_prime_product
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
def test_pairs_with_prime_product():
# Test wi... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of tuples, where each tuple contains a pair of numbers\nfrom the input list whose product is a prime numbe... | [
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": "import math\n\ndef 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... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001744",
"row_id": 1744,
"seed_ids": "[41706]"
} | 0.644993 | Evol_1744 | I | [
"is_prime",
"pairs_with_prime_product"
] | 2 | [
[
"pairs_with_prime_product",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1bc27e128eb93e4db536f9c529920c92189949f2 | 95423313d85771695290c0ba2ac444eb86d7b2ef | |||
v1.0 | instruct | Evol | Evol_1746_I | Create 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. Additionally, if a non-integer or a negative number is encountered within the list, raise an appropriate exception with a meaningful error message. Ensure the function is optim... | def is_prime(n):
"""
Helper function to determine if a number is prime.
Returns True if prime, 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... | import pytest
from solution import get_prime_numbers
def test_get_prime_numbers_basic():
assert get_prime_numbers([2, 3, 5, 10, 15, 17, 23]) == [2, 3, 5, 17, 23]
def test_get_prime_numbers_empty():
assert get_prime_numbers([]) == []
def test_get_prime_numbers_no_primes():
assert get_prime_numbers([4, 6, ... | [
{
"docstring": "Helper function to determine if a number is prime.\nReturns True if prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Accepts a list of integers and returns a new list containing only ... | [
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 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": "00001746",
"row_id": 1746,
"seed_ids": "[47029]"
} | 0.643297 | Evol_1746 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 674ba0685f5a9358c9181b6ae185e275621c36c0 | 9e295ab9171fbb209f8766a17ac5818e7b87af74 | |||
v1.0 | instruct | Evol | Evol_1808_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. Ensure that your function handles edge cases such as negative numbers, zero, and one correctly. Include a brief explanation of how your prime-checking logic works. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
A prime number is a natural number greater than 1,
that has no positive divisors other than 1 and itself.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for ... | from solution import filter_primes, is_prime
def test_is_prime():
assert not is_prime(-10)
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(29)
def test_filter_primes_basic():
assert filter_primes([1, 2, 3, 4, 5,... | [
{
"docstring": "Returns True if n is a prime number, else False.\nA prime number is a natural number greater than 1, \nthat has no positive divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "... | [
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 Helper function to check if a number is prime.\n A number n is prime if it's greater than 1 and has ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001808",
"row_id": 1808,
"seed_ids": "[34494]"
} | 0.659142 | Evol_1808 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 631f510ac48910bd129eea3c7fc8524c4ff61187 | 670d4494e1f81bae25c523f1f9da09b0a311c108 | |||
v1.0 | instruct | Evol | Evol_1819_I | <p><code> words = ["algorithm", "binary", "code", "data", "debug", "function", "loop", "program", "syntax", "variable"] </code><p> Given the list of words above, write a function that finds the longest word that can be constructed by deleting some characters of the string "programming" without reorder... | def is_subsequence(word, string):
"""
Check if word is a subsequence of string
"""
it = iter(string)
return all(char in it for char in word)
def longest_word(words, string):
"""
Finds the longest word from the list that can be constructed by deleting some
characters of the string "stri... | from solution import longest_word
def test_longest_word():
words = ["algorithm", "binary", "code", "data", "debug", "function", "loop", "program", "syntax", "variable"]
string = "programming"
assert longest_word(words, string) == "program"
def test_longest_word_no_subsequence():
words = ["hello", "wor... | [
{
"docstring": "Check if word is a subsequence of string",
"function_declaration": "def is_subsequence(word, string):",
"function_name": "is_subsequence",
"parameter_list": "(word, string)"
},
{
"docstring": "Finds the longest word from the list that can be constructed by deleting some \ncha... | [
1,
0,
1,
0,
0,
0,
1,
1,
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 longest_word_by_deleting_chars(words, string):\n \"\"\"\n Finds the longest word from the list 'words' that can be constructed by deleting some character... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001819",
"row_id": 1819,
"seed_ids": "[20585]"
} | 0.68741 | Evol_1819 | I | [
"is_subsequence",
"longest_word"
] | 2 | [
[
"longest_word",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4c73c4f0e4a34b54a511c35a44375126dabd51de | 29a67b4765eaa1a11fd358e66f72996c39bb179c | |||
v1.0 | instruct | Evol | Evol_1823_I | Write a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. Implement a helper function to check if a number is prime. | def is_prime(n):
"""
Returns True if the number n is prime, otherwise 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 filt... | 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(17) == True
assert is_prime(18) == False
assert is_prime(29) == True
def test_filter_primes_with_no_primes():
assert filter_pr... | [
{
"docstring": "Returns True if the number n is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the list of integers provided.",
"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 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_7 | {
"original_instruction": "",
"prompt_id": "00001823",
"row_id": 1823,
"seed_ids": "[47075]"
} | 0.65951 | Evol_1823 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76092cc202a86ce85455a0a2966943556132436b | 2655fcfba226d7400de64fa0d3e039cdcf341c1b | |||
v1.0 | instruct | Evol | Evol_1865_I | Write a function that accepts a list of integers and returns a list containing only the prime numbers from the original list, but reversed in order. If the input list is empty or contains no prime numbers, return an empty list.
Function signature:
```python
def filter_and_reverse_primes(nums: List[int]) -> List[int]:
... | from typing import List
def is_prime(n: int) -> bool:
"""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 filter_and_reverse_primes(nums: List[int]) -> List[int]:
""... | from solution import filter_and_reverse_primes
def test_filter_and_reverse_primes_with_primes():
assert filter_and_reverse_primes([3, 6, 10, 29, 18, 19]) == [19, 29, 3]
def test_filter_and_reverse_primes_with_no_primes():
assert filter_and_reverse_primes([4, 6, 8, 10, 12]) == []
def test_filter_and_reverse_p... | [
{
"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, in reverse order.",
"function_declaration": "def filte... | [
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 Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00001865",
"row_id": 1865,
"seed_ids": "[26813]"
} | 0.655407 | Evol_1865 | I | [
"is_prime",
"filter_and_reverse_primes"
] | 2 | [
[
"filter_and_reverse_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a03b00957a81a7759045785bb598d0b7e606b362 | eb0f5d263ebdc7c403a45a5cd71daa3f8a80d582 | |||
v1.0 | instruct | Evol | Evol_1877_I | Create a Python function that accepts a list of integers and returns the list sorted in such a way that all prime numbers appear before non-prime numbers, while maintaining the relative order of prime numbers and non-prime numbers as they appear in the original list. Optimize for readability and efficiency.
Example:
I... | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def sort_primes_first(lst):
"""
Sort the list such that prime numbers appear before non-prime ... | from solution import is_prime, sort_primes_first
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_sort_primes_firs... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Sort the list such that prime numbers appear before non-prime numbers,\nmaintaining the relative order from the origin... | [
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 == 2:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001877",
"row_id": 1877,
"seed_ids": "[28777]"
} | 0.652486 | Evol_1877 | I | [
"is_prime",
"sort_primes_first"
] | 2 | [
[
"sort_primes_first",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f110aaab985aece8c82c4dd0067139abac75d84b | 7bfd427729874522f7629121c8d57001ad1d8a6d | |||
v1.0 | instruct | Evol | Evol_1885_I | Design an efficient algorithm to process and analyze log files generated by a distributed system. The log files record events with timestamps and other metadata, and they are stored across multiple servers. Your solution should aggregate and sort events from these distributed logs by timestamp, detect anomalies based o... | import heapq
from collections import defaultdict
import re
from datetime import datetime
def parse_log_entry(log_entry):
"""
Parses a log entry to extract the timestamp and other metadata.
The log entry format is assumed to be "timestamp metadata".
"""
log_parts = log_entry.split(' ', 1)
timest... | from datetime import datetime
from solution import parse_log_entry, merge_and_sort_logs, detect_anomalies, summarize_anomalies
def test_parse_log_entry():
log_entry = "2023-10-01T12:00:00 EventA occurred"
timestamp, metadata = parse_log_entry(log_entry)
assert timestamp == datetime(2023, 10, 1, 12, 0, 0)
... | [
{
"docstring": "Parses a log entry to extract the timestamp and other metadata.\nThe log entry format is assumed to be \"timestamp metadata\".",
"function_declaration": "def parse_log_entry(log_entry):",
"function_name": "parse_log_entry",
"parameter_list": "(log_entry)"
},
{
"docstring": "M... | [
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": "from datetime import datetime\n\nclass LogProcessor:\n def __init__(self):\n self.logs = []\n self.anomalies = []\n\n def add_log(self, server_... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001885",
"row_id": 1885,
"seed_ids": "[29589]"
} | 0.516432 | Evol_1885 | I | [
"parse_log_entry",
"merge_and_sort_logs",
"detect_anomalies",
"summarize_anomalies"
] | 4 | [
[
"merge_and_sort_logs",
"parse_log_entry"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a42302a4ebba7ce0d71c8cbfbf09ae47079c790 | 510fa9140f58785eda531adb08f4967da4715349 | |||
v1.0 | instruct | Evol | Evol_1913_I | Given a list of integers, write a function that returns a list of booleans indicating whether each integer in the list is prime or not. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Function Signature:
```python
def is_prime_list(numbers: List[int]) -> List[bo... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to determine 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) ... | from solution import is_prime_list
def test_is_prime_list():
assert is_prime_list([2, 3, 4, 5, 6, 7]) == [True, True, False, True, False, True]
assert is_prime_list([11, 13, 14, 15, 16, 17]) == [True, True, False, False, False, True]
assert is_prime_list([1, -5, 0, 7, 23, 24]) == [False, False, False, True... | [
{
"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 list of booleans indicating whether each integer in the list is prime or not.",
"function_dec... | [
1,
1,
1,
1,
0,
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": "from typing import List\n\ndef is_prime(number: int) -> bool:\n \"\"\"\n Returns True if the number is a prime, False otherwise.\n \"\"\"\n if number <... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00001913",
"row_id": 1913,
"seed_ids": "[41161]"
} | 0.808136 | Evol_1913 | I | [
"is_prime",
"is_prime_list"
] | 2 | [
[
"is_prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0181bd5035451f207246427bffa5a58d308734ca | 2d915cedf4ef10d3bacd1a38d0dd9acba81143e5 | |||
v1.0 | instruct | Evol | Evol_1925_I | Write a function in Python that takes a nested list of integers as input and returns a new list where each integer is replaced with its frequency within the nested list. Be sure to handle any depth of nesting. For example, given the input `[[1, 2], [1, [2, [3, 4], 3]], 4]`, the function should return `[[2, 2], [2, [2, ... | def flatten_and_count(nested_list):
"""
Flattens a nested list of integers and returns a dictionary with the frequency count of each integer.
"""
def flatten(lst):
for item in lst:
if isinstance(item, int):
yield item
elif isinstance(item, list):
... | from solution import nested_frequency
def test_nested_frequency_simple():
input_list = [[1, 2], [1, [2, [3, 4], 3]], 4]
expected_output = [[2, 2], [2, [2, [2, 2], 2]], 2]
assert nested_frequency(input_list) == expected_output
def test_nested_frequency_single_element():
input_list = [[5]]
expected_... | [
{
"docstring": "Flattens a nested list of integers and returns a dictionary with the frequency count of each integer.",
"function_declaration": "def flatten_and_count(nested_list):",
"function_name": "flatten_and_count",
"parameter_list": "(nested_list)"
},
{
"docstring": "Replaces each inte... | [
1,
1,
1,
1,
0,
1,
1,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "from collections import Counter\nfrom typing import Union, List\n\ndef flatten_and_count(nested_list: List[Union[int, List]]) -> Counter:\n \"\"\"\n Flattens... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001925",
"row_id": 1925,
"seed_ids": "[31396]"
} | 0.639638 | Evol_1925 | I | [
"flatten_and_count",
"replace_with_frequency",
"nested_frequency"
] | 3 | [
[
"nested_frequency",
"flatten_and_count"
],
[
"nested_frequency",
"replace_with_frequency"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0833a64494cdbc91361435e9873e03904b83a5f7 | 51527eb6d69f6ee56e1e1066c163d5fedba9921e | |||
v1.0 | instruct | Evol | Evol_1948_I | Formulate a Python function that analyzes a given text file and identifies the top 5 most frequently occurring words. The function should preprocess the text by converting it to lowercase, removing punctuation, and disregarding common stop words. It must return a list of tuples, each containing a word and its frequency... | import string
from collections import Counter
STOP_WORDS = {
'i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", "you've", "you'll", "you'd", 'your',
'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it',
"it's", 'its', ... | from solution import get_top_five_words
def test_get_top_five_words_empty_file(tmp_path):
file = tmp_path / "empty.txt"
file.write_text("")
assert get_top_five_words(file) == []
def test_get_top_five_words_single_word(tmp_path):
file = tmp_path / "single.txt"
file.write_text("hello")
assert ge... | [
{
"docstring": null,
"function_declaration": "def preprocess_text(text):",
"function_name": "preprocess_text",
"parameter_list": "(text)"
},
{
"docstring": null,
"function_declaration": "def get_top_five_words(file_path):",
"function_name": "get_top_five_words",
"parameter_list":... | [
0,
0,
0,
0,
0,
1,
1,
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\nimport collections\nfrom typing import List, Tuple\n\n# Define common English stop words\nSTOP_WORDS = set([\n \"i\", \"me\", \"my\", \"myself\", \"w... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00001948",
"row_id": 1948,
"seed_ids": "[42109]"
} | 0.721957 | Evol_1948 | I | [
"preprocess_text",
"get_top_five_words"
] | 2 | [
[
"get_top_five_words",
"preprocess_text"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c7616257c55fde5b48f9702f04dcaf5ef5d673ca | 11733f15be0a04be4625d8bf9bce04d61b1de961 | |||
v1.0 | instruct | Evol | Evol_1959_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 for finding prime numbers.
The List = [10, 15, 20, 23, 29, 31, 45, 50] | def sieve_of_eratosthenes(n):
sieve = [True] * (n + 1)
p = 2
while (p * p <= n):
if (sieve[p] == True):
for i in range(p * p, n + 1, p):
sieve[i] = False
p += 1
return [p for p in range(2, n + 1) if sieve[p]]
def extract_prime_numbers(lst):
if not lst:
... | from solution import sieve_of_eratosthenes, extract_prime_numbers
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
assert sieve_of_eratosthenes(1) == []
def test_extract_prime_numbers():
assert e... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def extract_prime_numbers(lst):",
"function_name": "extract_prime_numbers",
"parameter_... | [
1,
1,
1,
1,
1,
0,
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 sieve_of_eratosthenes(n):\n \"\"\"Returns a list of prime numbers up to n using the sieve of Eratosthenes.\"\"\"\n is_prime = [True] * (n + 1)\n p = 2... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00001959",
"row_id": 1959,
"seed_ids": "[1496]"
} | 0.681423 | Evol_1959 | I | [
"sieve_of_eratosthenes",
"extract_prime_numbers"
] | 2 | [
[
"extract_prime_numbers",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d98a990094a0ffbbc8822c751a6dcbedb1eb2cd | 9243fb8d45a337c11250c8864e28bd34957f48e4 | |||
v1.0 | instruct | Evol | Evol_2002_I | Write a Python program that calculates the nth Fibonacci number. The program should prompt the user to enter a positive integer n and should include error handling for invalid inputs such as non-integer or negative values. Implement the function using both iterative and recursive approaches and display the results for ... | def fibonacci_iterative(n):
"""
Returns the nth Fibonacci number using an iterative approach.
n: An integer representing the position in the Fibonacci sequence.
"""
if n <= 0:
raise ValueError("n must be a positive integer")
if n == 1 or n == 2:
return 1
a, b = 1... | from solution import fibonacci_iterative, fibonacci_recursive, get_fibonacci_n
def test_fibonacci_iterative():
assert fibonacci_iterative(1) == 1
assert fibonacci_iterative(2) == 1
assert fibonacci_iterative(3) == 2
assert fibonacci_iterative(4) == 3
assert fibonacci_iterative(5) == 5
assert fi... | [
{
"docstring": "Returns the nth Fibonacci number using an iterative approach.\nn: An integer representing the position in the Fibonacci sequence.",
"function_declaration": "def fibonacci_iterative(n):",
"function_name": "fibonacci_iterative",
"parameter_list": "(n)"
},
{
"docstring": "Return... | [
0,
1,
0,
0,
0,
0,
0,
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": "def iterative_fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number using an iterative approach.\n \"\"\"\n if n < 0:\n raise ValueError(\"n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002002",
"row_id": 2002,
"seed_ids": "[4414]"
} | 0.787226 | Evol_2002 | I | [
"fibonacci_iterative",
"fibonacci_recursive",
"get_fibonacci_n"
] | 3 | [
[
"get_fibonacci_n",
"fibonacci_iterative"
],
[
"get_fibonacci_n",
"fibonacci_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d7323366867c80ba1b2d9c91259dc3d2593feb8c | ced859779732fcd72bcb121a09de23ac98f968d9 | |||
v1.0 | instruct | Evol | Evol_2025_I | Given a list of strings, write a function to group them by their starting letter in case-insensitive manner. Specifically, return a dictionary where the keys are the lowercase starting letters and the values are lists of words that start with that particular letter.
Additionally, you are provided a pre-written functio... | def add_to_group(word, group_dict):
first_letter = word[0].lower()
if first_letter in group_dict:
group_dict[first_letter].append(word)
else:
group_dict[first_letter] = [word]
def group_by_starting_letter(words):
group_dict = {}
for word in words:
add_to_group(word, grou... | from solution import add_to_group, group_by_starting_letter
def test_add_to_group_new_group():
group_dict = {}
add_to_group('Apple', group_dict)
assert group_dict == {'a': ['Apple']}
def test_add_to_group_existing_group():
group_dict = {'a': ['Apple']}
add_to_group('apricot', group_dict)
asser... | [
{
"docstring": null,
"function_declaration": "def add_to_group(word, group_dict):",
"function_name": "add_to_group",
"parameter_list": "(word, group_dict)"
},
{
"docstring": null,
"function_declaration": "def group_by_starting_letter(words):",
"function_name": "group_by_starting_lett... | [
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 add_to_group(word, group_dict):\n first_letter = word[0].lower()\n if first_letter in group_dict:\n group_dict[first_letter].append(word)\n els... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002025",
"row_id": 2025,
"seed_ids": "[10926]"
} | 0.627977 | Evol_2025 | I | [
"add_to_group",
"group_by_starting_letter"
] | 2 | [
[
"group_by_starting_letter",
"add_to_group"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db27872fefdcb33d7a7222949dd9e864658a0ac5 | aabf20f0d2b36c3c2f417acd047d314e5ff0265d | |||
v1.0 | instruct | Evol | Evol_2028_I | Create a function that takes a list of integers and returns a list of the prime numbers from the input list in ascending order. If no prime numbers are found, return an empty list. Optimize the function for efficient computation.
Example:
Input: [15, 3, 7, 10, 24]
Output: [3, 7]
Input: [8, 10, 20]
Output: [] | 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 find_primes(numbers)... | from solution import find_primes, is_prime
def test_find_primes_with_mixed():
assert find_primes([15, 3, 7, 10, 24]) == [3, 7]
def test_find_primes_with_no_primes():
assert find_primes([8, 10, 20]) == []
def test_find_primes_with_all_primes():
assert find_primes([11, 2, 5, 3, 7]) == [2, 3, 5, 7, 11]
def... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the input list in ascending order.",
"function_declaration": "def find_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 is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002028",
"row_id": 2028,
"seed_ids": "[3310]"
} | 0.677526 | Evol_2028 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a673f3d9d65059f00c64d88520f9d24377145389 | 9b37f70ad693e023e3ebf571597c8b63eccf9d5f | |||
v1.0 | instruct | Evol | Evol_2105_I | Design a Python function to analyze and transform a given list of strings where each element represents a mathematical expression in infix notation. The function needs to convert each expression into its respective postfix notation (Reverse Polish Notation) and then evaluate it. The function should return a list of eva... | def infix_to_postfix(expression):
"""
Converts an infix expression to postfix notation.
"""
precedence = {'+': 1, '-': 1, '*': 2, '/': 2}
stack = []
postfix = []
tokens = expression.split()
for token in tokens:
if token.isnumeric():
postfix.append(token)
... | from solution import infix_to_postfix, evaluate_postfix, analyze_expressions
def test_infix_to_postfix():
assert infix_to_postfix("3 + 4 * 2 / ( 1 - 5 )") == '3 4 2 * 1 5 - / +'
assert infix_to_postfix("10 + 2 * 6") == '10 2 6 * +'
assert infix_to_postfix("100 * 2 + 12") == '100 2 * 12 +'
assert infix_... | [
{
"docstring": "Converts an infix expression to postfix notation.",
"function_declaration": "def infix_to_postfix(expression):",
"function_name": "infix_to_postfix",
"parameter_list": "(expression)"
},
{
"docstring": "Evaluates a postfix expression.",
"function_declaration": "def evaluat... | [
1,
0,
0,
1,
0,
1,
0,
0,
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": "def infix_to_postfix(expression):\n precedence = {'+': 1, '-': 1, '*': 2, '/': 2}\n output = []\n operators = []\n \n def greater_precedence(op1, op... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002105",
"row_id": 2105,
"seed_ids": "[44966]"
} | 0.530904 | Evol_2105 | I | [
"infix_to_postfix",
"evaluate_postfix",
"analyze_expressions"
] | 3 | [
[
"analyze_expressions",
"evaluate_postfix"
],
[
"analyze_expressions",
"infix_to_postfix"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bbfa4d1cf89439487cee254ac3c90f52f9daf172 | 32e1dc734260abd8c8dc9937a873b9979d68aaf2 | |||
v1.0 | instruct | Evol | Evol_2110_I | Write a function that takes a list of strings and a target string as input. The function should return all strings from the list that can be formed by deleting some characters of the target string without reordering the remaining characters. Ensure your solution is efficient for large inputs.
def find_subsequences(str... | def is_subsequence(s, target):
"""
Helper function to determine if `s` is a subsequence of `target`.
"""
it = iter(target)
return all(char in it for char in s)
def find_subsequences(strings_list, target_string):
"""
Returns all strings from `strings_list` that can be formed by
deleting... | from solution import find_subsequences
def test_find_subsequences_all_valid():
assert find_subsequences(["abc", "ac", "b"], "abc") == ["abc", "ac", "b"]
def test_find_subsequences_some_valid():
assert find_subsequences(["a", "d", "e"], "abc") == ["a"]
def test_find_subsequences_none_valid():
assert f... | [
{
"docstring": "Helper function to determine if `s` is a subsequence of `target`.",
"function_declaration": "def is_subsequence(s, target):",
"function_name": "is_subsequence",
"parameter_list": "(s, target)"
},
{
"docstring": "Returns all strings from `strings_list` that can be formed by \n... | [
1,
0,
1,
0,
1,
0,
1,
0,
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 find_subsequences(strings_list, target_string):\n \"\"\"\n Returns all strings from strings_list that can be formed by \n deleting some characters of ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002110",
"row_id": 2110,
"seed_ids": "[11544]"
} | 0.608005 | Evol_2110 | I | [
"is_subsequence",
"find_subsequences"
] | 2 | [
[
"find_subsequences",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bfc8bd2be7503edfd6bd4dfc7fe02561ac6ddf22 | ca79a46bcd138e466ce4dfa424694197ea382fff | |||
v1.0 | instruct | Evol | Evol_2126_I | Write a Python function that calculates and returns the first 'n' terms of the sequence where each term is described as the product of its position (1-based) and the sum of its digits. For instance, if 'n' is 5, the sequence would be [1, 4, 9, 16, 25]. | def sum_of_digits(num):
"""
Returns the sum of the digits of the given number.
"""
return sum(int(digit) for digit in str(num))
def sequence_term(n):
"""
Returns the n-th term of the sequence where each term is described as
the product of its position (1-based) and the sum of its digits.
... | from solution import sum_of_digits, sequence_term, sequence
def test_sum_of_digits():
assert sum_of_digits(1) == 1
assert sum_of_digits(10) == 1
assert sum_of_digits(123) == 6
assert sum_of_digits(999) == 27
def test_sequence_term():
assert sequence_term(1) == 1
assert sequence_term(2) == 4
... | [
{
"docstring": "Returns the sum of the digits of the given number.",
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": "Returns the n-th term of the sequence where each term is described as\nthe product of its pos... | [
1,
0,
0,
0,
0,
0,
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 digit_sum(num):\n \"\"\"\n Returns the sum of the digits of a given number.\n \"\"\"\n return sum(int(digit) for digit in str(num))\n\ndef sequence... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002126",
"row_id": 2126,
"seed_ids": "[41485]"
} | 0.627994 | Evol_2126 | I | [
"sum_of_digits",
"sequence_term",
"sequence"
] | 3 | [
[
"sequence",
"sequence_term"
],
[
"sequence_term",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b76ca9d5e3395aedc1e4f293186886ea6d7d4b0d | bc6f9720625b44696315013843df776a523cf872 | |||
v1.0 | instruct | Evol | Evol_2147_I | Implement a function `find_kth_largest(nums, k)` that accepts a list of integers `nums` and an integer `k`, and returns the k-th largest element in the list. The solution must have an average-case time complexity of O(n) or better. You may assume that `1 <= k <= len(nums)`. Additionally, provide a brief explanation of ... | import random
def partition(nums, left, right, pivot_index):
pivot_value = nums[pivot_index]
nums[pivot_index], nums[right] = nums[right], nums[pivot_index] # Move pivot to end
store_index = left
for i in range(left, right):
if nums[i] > pivot_value:
nums[store_index], nums[i] = nu... | from solution import find_kth_largest
def test_single_element():
assert find_kth_largest([1], 1) == 1
def test_two_elements():
assert find_kth_largest([1, 2], 1) == 2
assert find_kth_largest([1, 2], 2) == 1
def test_multiple_elements():
assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5
assert f... | [
{
"docstring": null,
"function_declaration": "def partition(nums, left, right, pivot_index):",
"function_name": "partition",
"parameter_list": "(nums, left, right, pivot_index)"
},
{
"docstring": null,
"function_declaration": "def quickselect(nums, left, right, k):",
"function_name":... | [
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 partition(nums, low, high):\n pivot = nums[high]\n i = low - 1\n for j in range(low, high):\n if nums[j] >= pivot:\n i += 1\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002147",
"row_id": 2147,
"seed_ids": "[32982]"
} | 0.713999 | Evol_2147 | I | [
"partition",
"quickselect",
"find_kth_largest"
] | 3 | [
[
"find_kth_largest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c414e6f4e6211005c30ba14b80cb8eea7217fe43 | 1236854b8160520d089d8d28f0c3ab91d178c659 | |||
v1.0 | instruct | Evol | Evol_2151_I | Implement a command-line tool in Python that manages a simple to-do list. The tool should support the following operations: adding a new task with a specified deadline, listing all tasks (sorted by deadline), marking a task as completed, and deleting a task. Each task should include a title, description, deadline, and ... | import json
import os
from datetime import datetime, timedelta
from filelock import FileLock
TODO_FILE = 'todo_list.json'
LOCK_FILE = 'todo_list.lock'
DATE_FORMAT = '%Y-%m-%d'
def load_tasks():
if os.path.exists(TODO_FILE):
with open(TODO_FILE, 'r') as file:
return json.load(file)
return [... | import os
import pytest
import json
from datetime import datetime, timedelta
from solution import add_task, list_tasks, mark_task_completed, delete_task, archive_old_tasks, TODO_FILE, DATE_FORMAT
def setup_module(module):
if os.path.exists(TODO_FILE):
os.rename(TODO_FILE, TODO_FILE + '.bak')
def teardown... | [
{
"docstring": null,
"function_declaration": "def load_tasks():",
"function_name": "load_tasks",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def save_tasks(tasks):",
"function_name": "save_tasks",
"parameter_list": "(tasks)"
},
{
"docstring": n... | [
0,
0,
1,
0,
0,
0,
0,
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 os\nimport json\nimport datetime\nfrom threading import Lock\nfrom contextlib import contextmanager\n\n# Global lock for managing concurrent access\ntask_lo... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002151",
"row_id": 2151,
"seed_ids": "[8074]"
} | 0.429957 | Evol_2151 | I | [
"load_tasks",
"save_tasks",
"add_task",
"list_tasks",
"mark_task_completed",
"delete_task",
"archive_old_tasks",
"manage_to_do_list"
] | 8 | [
[
"add_task",
"load_tasks"
],
[
"add_task",
"save_tasks"
],
[
"archive_old_tasks",
"load_tasks"
],
[
"archive_old_tasks",
"save_tasks"
],
[
"delete_task",
"load_tasks"
],
[
"delete_task",
"save_tasks"
],
[
"list_tasks",
"load_tasks"
]... | 14 | [] | false | [] | false | pytest | true | [
"filelock"
] | false | 97c521d2e0d80e91031ca2b3151fcc84b5b7e5f9 | 73798ae661551bc9dcb8113f5295f35c94357aba | |||
v1.0 | instruct | Evol | Evol_2187_I | Implement a Python function named "word_histogram" that takes a string as input and returns a dictionary. The dictionary should have individual words from the input string as keys and the number of times each word appears in the string as values. Assume that the input string is a sentence where words are separated by s... | import string
def word_histogram(sentence):
"""
Returns a dictionary with words as keys and their frequency as values.
Words are considered case-insensitive and punctuation is ignored.
"""
# Remove punctuation and convert to lower case
translator = str.maketrans('', '', string.punctuation)
... | from solution import word_histogram, most_frequent_word
def test_word_histogram_basic():
sentence = "Hello world"
expected = {"hello": 1, "world": 1}
assert word_histogram(sentence) == expected
def test_word_histogram_with_punctuation():
sentence = "Hello, world! Hello."
expected = {"hello": 2, "w... | [
{
"docstring": "Returns a dictionary with words as keys and their frequency as values.\nWords are considered case-insensitive and punctuation is ignored.",
"function_declaration": "def word_histogram(sentence):",
"function_name": "word_histogram",
"parameter_list": "(sentence)"
},
{
"docstri... | [
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": "import string\n\ndef word_histogram(sentence):\n \"\"\"\n Returns a dictionary with words as keys and their frequency as values.\n \"\"\"\n # Remove pu... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002187",
"row_id": 2187,
"seed_ids": "[3828]"
} | 0.745988 | Evol_2187 | I | [
"word_histogram",
"most_frequent_word"
] | 2 | [
[
"most_frequent_word",
"word_histogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eef2e060278bd6bcd238e48af26e71a1d63d53a2 | 247d6316342b276a501f4871bfd925a3c3d0e5c3 | |||
v1.0 | instruct | Evol | Evol_2199_I | Given a list of integers, return a new list containing only the prime numbers from the original list.
example_list = [10, 15, 3, 7, 9, 11] | def is_prime(n):
"""
Check 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 False
return True
def filter_primes(i... | from solution import filter_primes
def test_filter_primes_mixed_list():
assert filter_primes([10, 15, 3, 7, 9, 11]) == [3, 7, 11]
def test_filter_primes_all_non_primes():
assert filter_primes([4, 6, 8, 10, 15]) == []
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5,... | [
{
"docstring": "Check 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 of integers.",
"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 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": "00002199",
"row_id": 2199,
"seed_ids": "[39218]"
} | 0.560931 | Evol_2199 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cbbc195e7212adc3d3d9510ca684515bb225d483 | e2e7e0b28b2a3d20a2f16fb03f7a7529fefca824 | |||
v1.0 | instruct | Evol | Evol_2211_I | Create a command-line application in Python that acts as a simple task manager. This application should allow the user to add new tasks with due dates, list all tasks, mark tasks as completed, and delete tasks. Ensure the application stores tasks persistently between runs using a file-based storage method. Implement er... | import json
import os
from datetime import datetime
TASKS_FILE = 'tasks.json'
def load_tasks():
if os.path.exists(TASKS_FILE):
with open(TASKS_FILE, 'r') as file:
return json.load(file)
return []
def save_tasks(tasks):
with open(TASKS_FILE, 'w') as file:
json.dump(tasks, file)... | import os
import json
import pytest
from solution import add_task, list_tasks, mark_task_completed, delete_task, TASKS_FILE
def setup_function():
if os.path.exists(TASKS_FILE):
os.remove(TASKS_FILE)
def teardown_function():
if os.path.exists(TASKS_FILE):
os.remove(TASKS_FILE)
def test_add_tas... | [
{
"docstring": null,
"function_declaration": "def load_tasks():",
"function_name": "load_tasks",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def save_tasks(tasks):",
"function_name": "save_tasks",
"parameter_list": "(tasks)"
},
{
"docstring": n... | [
0,
1,
1,
0,
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": "import json\nimport os\nfrom datetime import datetime\n\nTASK_FILE = 'tasks.json'\n\ndef load_tasks():\n if os.path.exists(TASK_FILE):\n with open(TASK_F... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002211",
"row_id": 2211,
"seed_ids": "[43985]"
} | 0.478758 | Evol_2211 | I | [
"load_tasks",
"save_tasks",
"add_task",
"list_tasks",
"mark_task_completed",
"delete_task"
] | 6 | [
[
"add_task",
"load_tasks"
],
[
"add_task",
"save_tasks"
],
[
"delete_task",
"load_tasks"
],
[
"delete_task",
"save_tasks"
],
[
"list_tasks",
"load_tasks"
],
[
"mark_task_completed",
"load_tasks"
],
[
"mark_task_completed",
"save_tasks"... | 7 | [] | false | [] | false | pytest | true | [] | true | e122c1ea6f6bf888c2b67bd800cd5682c3748a7a | 185efbc4082749b9ebff0edb1275514690f44344 | |||
v1.0 | instruct | Evol | Evol_2218_I | Create a function `longest_disjoint_subsequence` that finds the longest subsequence from an array of integers where the difference between consecutive elements is always greater than 2. The function should also include a helper function, `valid_subsequence`, that verifies if a given subsequence meets the criteria.
Ens... | def valid_subsequence(subseq: list) -> bool:
""" Verify if the given subsequence has all consecutive elements with a difference greater than 2."""
for i in range(len(subseq) - 1):
if abs(subseq[i + 1] - subseq[i]) <= 2:
return False
return True
def longest_disjoint_subsequence(array: li... | from solution import valid_subsequence, longest_disjoint_subsequence
def test_valid_subsequence():
assert valid_subsequence([1, 4, 7, 10]) == True
assert valid_subsequence([1, 3, 5, 7, 9]) == False
assert valid_subsequence([1, 5, 10]) == True
assert valid_subsequence([1, 2, 6, 10]) == False
def test_l... | [
{
"docstring": "Verify if the given subsequence has all consecutive elements with a difference greater than 2.",
"function_declaration": "def valid_subsequence(subseq):",
"function_name": "valid_subsequence",
"parameter_list": "(subseq)"
},
{
"docstring": "Find the longest subsequence from t... | [
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": "def valid_subsequence(subseq):\n \"\"\" Verify if the given subsequence has all consecutive elements with a difference greater than 2.\"\"\"\n for i in range... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002218",
"row_id": 2218,
"seed_ids": "[8644]"
} | 0.826153 | Evol_2218 | I | [
"valid_subsequence",
"longest_disjoint_subsequence"
] | 2 | [
[
"longest_disjoint_subsequence",
"valid_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52f5b0c2287726d25589253efd11363033505627 | 87d623abc673894294eeee7d50d5685874ff4ca8 | |||
v1.0 | instruct | Evol | Evol_2232_I | <div class="center"><img src="project/images/p345_matrix1.gif" class="dark_img" alt="p345_matrix1.gif" /></div>
<p>The image above shows a 5x5 matrix with each cell containing an integer. This is just one example of a matrix used in the problem described below.</p>
<p>The text file available for download (<a href="pr... | import numpy as np
from scipy.optimize import linear_sum_assignment
import os
def read_matrices(filename):
with open(filename, 'r') as file:
data = file.read()
matrices = []
individual_matrix = []
for line in data.splitlines():
if line.strip():
individual_matrix.append(... | from solution import read_matrices, maximum_sum_assignment, solve_problem
import numpy as np
def test_read_matrices():
filename = 'test_matrices.txt'
data = """7 53 183 439 863
497 383 563 79 973
287 63 343 169 583
627 343 773 959 943
767 473 103 699 303
7 53 183 439 863
497 383 563 79 973
287 63 343 169 583
... | [
{
"docstring": null,
"function_declaration": "def read_matrices(filename):",
"function_name": "read_matrices",
"parameter_list": "(filename)"
},
{
"docstring": null,
"function_declaration": "def maximum_sum_assignment(matrix):",
"function_name": "maximum_sum_assignment",
"paramet... | [
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": "def read_matrices_from_file(filepath):\n \"\"\"\n Reads matrices from the given file and returns a list of matrices.\n Each matrix is represented as a lis... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002232",
"row_id": 2232,
"seed_ids": "[9433]"
} | 0.561785 | Evol_2232 | I | [
"read_matrices",
"maximum_sum_assignment",
"solve_problem"
] | 3 | [
[
"solve_problem",
"maximum_sum_assignment"
],
[
"solve_problem",
"read_matrices"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | dcd91cbda52271dd0154dc2fc10f66b81b751780 | 14642e53902bba2954e0e433186f11c6d80d05d9 | |||
v1.0 | instruct | Evol | Evol_2245_I | Write a function that computes the Euclidean distance between two points in a multi-dimensional space. The function should accept two lists of equal length, where each list contains the coordinates of a point. Use this function to find the nearest point from a list of points to a given reference point. The input to you... | import math
def euclidean_distance(point1, point2):
"""
Computes and returns the Euclidean distance between two points in a multi-dimensional space.
"""
if len(point1) != len(point2):
raise ValueError("Both points must have the same number of dimensions.")
distance = math.sqrt(sum((x -... | from solution import euclidean_distance, find_nearest_point
def test_euclidean_distance():
assert euclidean_distance([0, 0], [3, 4]) == 5
assert euclidean_distance([1, 2, 3], [4, 5, 6]) == math.sqrt(27)
assert euclidean_distance([-1, -2], [-4, -6]) == 5
def test_find_nearest_point():
points = [[1, 2],... | [
{
"docstring": "Computes and returns the Euclidean distance between two points in a multi-dimensional space.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Finds the nearest p... | [
0,
0,
1,
1,
1,
0,
0,
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 math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Computes the Euclidean distance between two points in a multi-dimensional space.\n \"\"\... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002245",
"row_id": 2245,
"seed_ids": "[12590]"
} | 0.60603 | Evol_2245 | I | [
"euclidean_distance",
"find_nearest_point"
] | 2 | [
[
"find_nearest_point",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c972ff95deca8e646986fce383cebad6a8cd4e0f | 92b9369124891461a3c41d0d7577b897b633390c | |||
v1.0 | instruct | Evol | Evol_2254_I | Design a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Your function should include an inner helper function to determine the primality of a number and handle cases where the input list is empty or contains non-integer elements by returning an ap... | def is_prime(n):
"""
Helper function to determine if a number is a 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 get_prime_numbers
def test_prime_numbers_in_mixed_list():
assert get_prime_numbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_empty_list():
assert get_prime_numbers([]) == []
def test_list_with_non_integer_elements():
assert get_prime_numbers([2, 3, 'a', 5, 7]) == "Err... | [
{
"docstring": "Helper function to determine if a number is a 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 'lst'.\nIf 'lst' is empty or contains non-integer ele... | [
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 filter_primes(numbers):\n \"\"\"\n Filters the list and returns only the prime numbers.\n If the list is empty or contains non-integer elements, retur... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002254",
"row_id": 2254,
"seed_ids": "[25689]"
} | 0.628391 | Evol_2254 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d15b3ec8ad9a624c0d05c53ffdd71b385fc2805a | 0af14cbd9d7b247b8198fb58c85d41cf1eab6a72 | |||
v1.0 | instruct | Evol | Evol_2261_I | Develop a function in Python that accepts a list of integers and returns a new list containing only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should be named `extract_primes`. Include appropriate docstr... | def is_prime(n):
"""Check if a number is prime."""
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_primes(numbers):
"""
R... | from solution import extract_primes
def test_extract_primes_with_only_primes():
assert extract_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_extract_primes_with_no_primes():
assert extract_primes([4, 6, 8, 9, 12]) == []
def test_extract_primes_with_mixed_numbers():
assert extract_primes([2, 4, 5,... | [
{
"docstring": "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 given list of integers.\n\n:param numbers: A list of integers\n:return: A list of prime 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 :param n: Integer number to check\n :return: True if n is prime, False otherwise\n \"\"\"... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002261",
"row_id": 2261,
"seed_ids": "[22511]"
} | 0.673126 | Evol_2261 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de07ead71dc12d956a687b6b719d773f7a525176 | ababcd09c89272b2528a665185f8292551ddab6f | |||
v1.0 | instruct | Evol | Evol_2272_I | Design a Python program that calculates the shortest path in a weighted, directed graph using Dijkstra's algorithm. The program should first read graph data from a text file, where each line represents an edge with a source node, destination node, and weight (formatted as "source destination weight"). The program shoul... | import heapq
def dijkstra(graph, start):
"""
Calculate the shortest paths from the start node to all other nodes using Dijkstra's algorithm.
Params:
graph: dict, the graph where keys are nodes and values are lists of tuples (neighbor, weight)
start: the starting node
Returns:
(dis... | import pytest
from solution import dijkstra, read_graph_from_file, shortest_path
def test_dijkstra_example_graph():
graph = {
'a': [('b', 4), ('c', 2)],
'b': [('e', 3)],
'c': [('b', 1), ('d', 4), ('e', 5)],
'd': [('e', 1)],
'e': []
}
start = 'a'
distances, previo... | [
{
"docstring": "Calculate the shortest paths from the start node to all other nodes using Dijkstra's algorithm.\n\nParams:\ngraph: dict, the graph where keys are nodes and values are lists of tuples (neighbor, weight)\nstart: the starting node\n\nReturns:\n(distances, previous): a tuple where distances is a dic... | [
1,
0,
0,
0,
1,
1,
0,
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 heapq\n\ndef dijkstra(graph, start):\n \"\"\"\n Dijkstra's algorithm to find the shortest path in a weighted, directed graph.\n \n :param graph:... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002272",
"row_id": 2272,
"seed_ids": "[9296]"
} | 0.616217 | Evol_2272 | I | [
"dijkstra",
"read_graph_from_file",
"shortest_path"
] | 3 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3276001ef3aaf5c2aeb3fc6159b5d061f2a731d | ef68c863836b0b1e2923aa29cf20004abb02e908 | |||
v1.0 | instruct | Evol | Evol_2285_I | In a game, you are given a number and you need to determine if it can be expressed as the sum of two prime numbers. Write a function `canBeSumOfTwoPrimes(n)` that takes an integer `n` and returns `True` if `n` can be expressed as the sum of two prime numbers and `False` otherwise. Keep in mind that 1 is not a prime num... | def is_prime(num):
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 False
i += 6
return True
def canBeSumOfTwoPrimes(n):
... | from solution import canBeSumOfTwoPrimes
def test_canBeSumOfTwoPrimes_positive_case():
assert canBeSumOfTwoPrimes(10) == True # 10 = 3 + 7
def test_canBeSumOfTwoPrimes_no_pair():
assert canBeSumOfTwoPrimes(11) == False # There are no two primes that sum up to 11
def test_canBeSumOfTwoPrimes_smallest_sum():... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def canBeSumOfTwoPrimes(n):",
"function_name": "canBeSumOfTwoPrimes",
"parameter_list": "(n)"
}
] | [
0,
0,
0,
0,
0,
1,
0,
1,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def canBeSumOfTwoPrimes(n: int) -> bool:\n \"\"\"\n Returns True if n can be expressed as the sum of two prime numbers, False otherwise.\n \"\"\"\n if ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002285",
"row_id": 2285,
"seed_ids": "[15423]"
} | 0.723006 | Evol_2285 | I | [
"is_prime",
"canBeSumOfTwoPrimes"
] | 2 | [
[
"canBeSumOfTwoPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d543c6be58e45038221b93d2f99eb5dee2a8d93 | fc24b84f4839858c4559c886c725d5c385dfb0ac | |||
v1.0 | instruct | Evol | Evol_2298_I | Create a Python function `generate_primes` that takes an integer `n` and returns a list of the first `n` prime numbers. You are not allowed to use any libraries that directly provide prime numbers, but you may use standard mathematical libraries. Implement the function as efficiently as possible. Additionally, include ... | import math
def is_prime(num):
"""
Helper function to determine 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:
... | from solution import generate_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(1)
assert not is_prime(0)
assert not is_prime(-1)
def test_generate_pri... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of the first 'n' prime numbers.",
"function_declaration": "def generate_primes(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 generate_primes(n):\n \"\"\"\n Returns a list of the first n prime numbers.\n \"\"\"\n if n <= 0:\n return []\n \n primes = []\n nu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00002298",
"row_id": 2298,
"seed_ids": "[3779]"
} | 0.661263 | Evol_2298 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6493d0ec9d5f0f5c0bf94963c677cd3581c523b | 194d237dddb63c1139516d98349d38034d9bef1a | |||
v1.0 | instruct | Evol | Evol_2303_I | You are given a list of points in a 2D plane, where each point is represented as a tuple (x, y). Write a Python function `find_closest_pair(points)` that finds the closest pair of points in the list and returns the pair with the smallest distance between them. If there are multiple pairs with the same smallest distance... | import math
from typing import List, Tuple
def euclidean_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float:
return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)
def find_closest_pair(points: List[Tuple[int, int]]) -> Tuple[Tuple[int, int], Tuple[int, int]]:
min_dista... | from solution import find_closest_pair
def test_find_closest_pair_general_case():
points = [(1, 2), (4, 6), (7, 8), (2, 1), (3, 4)]
assert find_closest_pair(points) in [((1, 2), (2, 1)), ((2, 1), (1, 2))]
def test_find_closest_pair_two_points():
points = [(1, 1), (2, 2)]
assert find_closest_pair(p... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": null,
"function_declaration": "def find_closest_pair(points):",
"function_name": "find_closest_pair",
... | [
1,
1,
0,
0,
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": "from typing import List, Tuple\nfrom math import sqrt\n\ndef euclidean_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:\n return sqrt((p1[0] - p2[0]... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002303",
"row_id": 2303,
"seed_ids": "[1330]"
} | 0.730367 | Evol_2303 | I | [
"euclidean_distance",
"find_closest_pair"
] | 2 | [
[
"find_closest_pair",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 82efeaff1f0928347c15c1179ba3f48c115f8da3 | 785a67392b07d4bc4a24d5efbe259c39413f0845 | |||
v1.0 | instruct | Evol | Evol_2320_I | Design a sophisticated algorithm capable of parsing and analyzing a large XML document, extracting hierarchical data, and transforming it into a structured JSON format. Emphasize the importance of preserving the intrinsic relationships and nested structures present within the original XML while ensuring the output adhe... | import xml.etree.ElementTree as ET
import json
def xml_to_dict(element):
"""
Converts an XML element and its children into a dictionary.
"""
def element_to_dict(elem):
node = {}
children = list(elem)
if children:
d = {}
for child in children:
... | from solution import convert_xml_to_json
import xml.etree.ElementTree as ET
import json
def test_convert_xml_to_json_simple():
xml_string = "<root><child>value</child></root>"
expected_json = json.dumps({"root": {"child": "value"}}, indent=4)
assert convert_xml_to_json(xml_string) == expected_json
def tes... | [
{
"docstring": "Converts an XML element and its children into a dictionary.",
"function_declaration": "def xml_to_dict(element):",
"function_name": "xml_to_dict",
"parameter_list": "(element)"
},
{
"docstring": "Converts an XML string to a JSON string.",
"function_declaration": "def conv... | [
1,
1,
0,
1,
1,
1,
0,
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": "import xml.etree.ElementTree as ET\nimport json\n\ndef xml_to_json(xml_string):\n \"\"\"\n Parses an XML string, extracting hierarchical data and transformin... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002320",
"row_id": 2320,
"seed_ids": "[7779]"
} | 0.587584 | Evol_2320 | I | [
"xml_to_dict",
"convert_xml_to_json"
] | 2 | [
[
"convert_xml_to_json",
"xml_to_dict"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af49b7a8e16cbceaed851a7c606aff5704c4c506 | 6bcc07c1dfc28785a73bdc46bfdb23f2ee7aa5bf | |||
v1.0 | instruct | Evol | Evol_2333_I | Write a Python function that receives a list of integers and returns a new list containing only the prime numbers from the original list in the same order. Your function should implement a helper function to check for primality, and cannot use any libraries such as `sympy` or similar. Ensure the function is efficient f... | 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 Fals... | 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
assert is_prime(1) == False
assert is_prime(0) == False... | [
{
"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 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_6 | {
"original_instruction": "",
"prompt_id": "00002333",
"row_id": 2333,
"seed_ids": "[21394]"
} | 0.624722 | Evol_2333 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 428271f4533ad6dcc0d58a58192a73bbc1c3ca86 | 7acf100d9be9e214f2fbd14b06154c84359c738c | |||
v1.0 | instruct | Evol | Evol_2385_I | Explain how you would design a microservices architecture for an e-commerce platform, highlighting key services, the communication between these services, and considerations for ensuring scalability and fault tolerance. | # Simplified communication between services using dummy functions and a message queue
# Simulate a message queue
message_queue = []
def user_service_add_user(user_id, user_info):
"""
Adds a user to the system and notifies other services.
"""
print(f"User {user_id} added")
# Publish user created ev... | # Tests to verify the communication between services and message queue handling
from solution import user_service_add_user, product_service_add_product, order_service_create_order, handle_event
def test_user_service_add_user():
message_queue.clear() # Ensure the message_queue is empty before the test
user_se... | [
{
"docstring": "Adds a user to the system and notifies other services.",
"function_declaration": "def user_service_add_user(user_id, user_info):",
"function_name": "user_service_add_user",
"parameter_list": "(user_id, user_info)"
},
{
"docstring": "Adds a product to the system.",
"functi... | [
0,
0,
1,
1,
1,
1,
0,
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": "from flask import Flask, request, jsonify\nimport requests\n\napp = Flask(__name__)\n\n# Microservice URLs\nUSER_SERVICE_URL = 'http://user-service'\nPRODUCT_SERVI... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002385",
"row_id": 2385,
"seed_ids": "[35107]"
} | 0.212425 | Evol_2385 | I | [
"user_service_add_user",
"product_service_add_product",
"order_service_create_order",
"payment_service_process_payment",
"notification_service_send_email",
"handle_event"
] | 6 | [
[
"handle_event",
"notification_service_send_email"
],
[
"handle_event",
"payment_service_process_payment"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 29221b7a61f36c96cfd885516a30eece9db1e32f | bc919d52d3fd50207826acfbd46cbc19c1c3723e | |||
v1.0 | instruct | Evol | Evol_2418_I | Build a recommendation system using collaborative filtering in Python. The goal of the system is to recommend movies to users based on their movie ratings. You are given a dictionary of users and the movies they have rated, along with the ratings they have given. The structure of the dictionary is as follows:
ratings ... | import numpy as np
def pearson_correlation(user_ratings, user1, user2):
"""
Calculate the Pearson correlation coefficient between two users' ratings.
"""
common_movies = [movie for movie in user_ratings[user1] if movie in user_ratings[user2]]
n = len(common_movies)
if n == 0:
retur... | from solution import recommend_movies
def test_recommend_movies_user_not_found():
ratings = {
'User1': {'MovieA': 4.5, 'MovieB': 3.0, 'MovieC': 5.0},
'User2': {'MovieA': 2.0, 'MovieB': 3.5, 'MovieD': 4.0},
'User3': {'MovieC': 4.0, 'MovieD': 2.5, 'MovieE': 4.5},
'User4': {'MovieB': 2... | [
{
"docstring": "Calculate the Pearson correlation coefficient between two users' ratings.",
"function_declaration": "def pearson_correlation(user_ratings, user1, user2):",
"function_name": "pearson_correlation",
"parameter_list": "(user_ratings, user1, user2)"
},
{
"docstring": "Recommend mo... | [
1,
0,
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 numpy as np\n\ndef pearson_correlation(user_ratings, user1, user2):\n \"\"\"\n Calculate the Pearson correlation coefficient between two users' rating... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00002418",
"row_id": 2418,
"seed_ids": "[26111]"
} | 0.547739 | Evol_2418 | I | [
"pearson_correlation",
"recommend_movies"
] | 2 | [
[
"recommend_movies",
"pearson_correlation"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 5211720f02ee73aa38193ade3fc417f90fa92b27 | b156a75c7bffb3d0faf3ec9e22af9e671748f6ab | |||
v1.0 | instruct | Evol | Evol_2444_I | Develop a function to process log entries from a system monitoring tool. Each log entry contains a timestamp and various event details. Your program should be able to:
- Parse log entries to extract timestamps and event details.
- Filter log entries based on a given time range.
- Sort log entries in ascending or desce... | from datetime import datetime
from collections import defaultdict
def parse_log_entry(log_entry, time_format):
"""
Parse a single log entry to extract timestamp and event details.
Assumes that each log entry is a string where the first part is the timestamp followed by the event details.
"""
try:
... | from solution import parse_log_entry, filter_log_entries, sort_log_entries, categorize_log_entries, generate_summary_report
def test_parse_log_entry_valid():
log_entry = "2023-05-15 10:15:53 ERROR Disk space low"
time_format = "%Y-%m-%d %H:%M:%S"
timestamp, event_details = parse_log_entry(log_entry, time_f... | [
{
"docstring": "Parse a single log entry to extract timestamp and event details.\nAssumes that each log entry is a string where the first part is the timestamp followed by the event details.",
"function_declaration": "def parse_log_entry(log_entry, time_format):",
"function_name": "parse_log_entry",
... | [
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": "from datetime import datetime\n\ndef parse_log_entry(log_entry, time_format):\n \"\"\"\n Parse a single log entry and extract timestamp and event details.\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002444",
"row_id": 2444,
"seed_ids": "[23633]"
} | 0.645118 | Evol_2444 | I | [
"parse_log_entry",
"filter_log_entries",
"sort_log_entries",
"categorize_log_entries",
"generate_summary_report"
] | 5 | [
[
"categorize_log_entries",
"parse_log_entry"
],
[
"filter_log_entries",
"parse_log_entry"
],
[
"generate_summary_report",
"categorize_log_entries"
],
[
"generate_summary_report",
"filter_log_entries"
],
[
"sort_log_entries",
"parse_log_entry"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 1f23ea450910312e58c08e0e117f364775aec359 | 9fef673f16a913de7de220215fe6917198ed9126 | |||
v1.0 | instruct | Evol | Evol_2445_I | Implement a Python program that reads in a CSV file containing information about employees, such as employee ID, name, department, and salary. The program should provide functionality to:
1. List all employees in a specific department.
2. Calculate the average salary for a specific department.
3. Identify the employee(... | import csv
from collections import defaultdict
def read_employees(csv_file_path):
employees = []
with open(csv_file_path, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
row['salary'] = float(row['salary'])
employees.append(row)
return emp... | import pytest
from solution import read_employees, list_employees_by_department, calculate_average_salary, find_highest_and_lowest_salary
def test_read_employees(tmp_path):
csv_file = tmp_path / "employees.csv"
csv_file.write_text("employee_id,name,department,salary\n1,John Doe,Engineering,70000\n2,Jane Smith,... | [
{
"docstring": null,
"function_declaration": "def read_employees(csv_file_path):",
"function_name": "read_employees",
"parameter_list": "(csv_file_path)"
},
{
"docstring": null,
"function_declaration": "def list_employees_by_department(employees, department):",
"function_name": "list... | [
1,
0,
1,
1,
1,
0,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import csv\nfrom collections import defaultdict\n\ndef read_csv(file_path):\n employees = []\n try:\n with open(file_path, mode='r') as file:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002445",
"row_id": 2445,
"seed_ids": "[3925]"
} | 0.561823 | Evol_2445 | I | [
"read_employees",
"list_employees_by_department",
"calculate_average_salary",
"find_highest_and_lowest_salary"
] | 4 | [
[
"calculate_average_salary",
"list_employees_by_department"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9b1b5ef871bc4ed5296caa0b3662ad934058aa77 | 19064d82f9386e2e9a50db562517ec616b5a7dae | |||
v1.0 | instruct | Evol | Evol_2469_I | Implement a function `find_happy_numbers(n)` that takes a positive integer `n` and returns a list of the first `n` happy numbers. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number eq... | def is_happy_number(num):
"""
Helper function to determine if a number is a happy number.
"""
visited = set()
while num != 1 and num not in visited:
visited.add(num)
num = sum(int(digit) ** 2 for digit in str(num))
return num == 1
def find_happy_numbers(n):
"""
Returns t... | from solution import find_happy_numbers
def test_find_happy_numbers_basic():
assert find_happy_numbers(1) == [1]
assert find_happy_numbers(3) == [1, 7, 10]
assert find_happy_numbers(5) == [1, 7, 10, 13, 19]
def test_find_happy_numbers_larger():
assert find_happy_numbers(8) == [1, 7, 10, 13, 19, 23, 28... | [
{
"docstring": "Helper function to determine if a number is a happy number.",
"function_declaration": "def is_happy_number(num):",
"function_name": "is_happy_number",
"parameter_list": "(num)"
},
{
"docstring": "Returns the first n happy numbers.",
"function_declaration": "def find_happy... | [
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_happy_number(x):\n \"\"\"Helper function to determine if a number x is happy.\"\"\"\n seen = set()\n while x != 1 and x not in seen:\n seen.... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002469",
"row_id": 2469,
"seed_ids": "[38928]"
} | 0.545329 | Evol_2469 | I | [
"is_happy_number",
"find_happy_numbers"
] | 2 | [
[
"find_happy_numbers",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b88cb1e845d8577c908ad3ac414d00bb2be0d69c | 0baf6453a6df82b58ab568bfaa4ced83e302d684 | |||
v1.0 | instruct | Evol | Evol_2527_I | Write a program to read a list of email addresses and filter out invalid ones based on the following rules:
1. An email address must have exactly one '@' symbol.
2. The local part (before the '@') should not be empty and should only contain alphanumeric characters and the following special characters: '.', '_', and '-'... | import re
from collections import defaultdict
def is_valid_email(email):
"""
Validates if the given email address is valid based on described rules.
"""
email_regex = re.compile(r'^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$')
return bool(email_regex.match(email))
def categorize_emails(email_l... | from solution import is_valid_email, categorize_emails
def test_is_valid_email():
# Test valid emails
assert is_valid_email("user.name@example.com")
assert is_valid_email("user_name@example.com")
assert is_valid_email("user-name@example.com")
assert is_valid_email("username@example.com")
#... | [
{
"docstring": "Validates if the given email address is valid based on described rules.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Categorizes valid emails by their domain and counts the number of ... | [
1,
0,
0,
0,
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": "import re\nfrom collections import defaultdict\n\ndef is_valid_email(email):\n \"\"\"\n This function checks if an email address is valid based on the provid... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002527",
"row_id": 2527,
"seed_ids": "[17915]"
} | 0.485716 | Evol_2527 | I | [
"is_valid_email",
"categorize_emails",
"user_interface"
] | 3 | [
[
"categorize_emails",
"is_valid_email"
],
[
"user_interface",
"categorize_emails"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6b09c254a22a7ac275f6604284dda3cc9457afd2 | 8ef0d7b7b289ce6839eb9b1c80fc58892bc12075 | |||
v1.0 | instruct | Evol | Evol_2564_I | Write a function in Python that takes an integer `n` and a list of `n` random numbers as input. The function should return a dictionary with three keys: "odd", "even", and "prime". The values corresponding to these keys should be lists containing the odd numbers, even numbers, and prime numbers from the input list, res... | def is_prime(num):
"""
Checks 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 categorize_numbers(... | from solution import categorize_numbers
def test_all_odd_numbers():
assert categorize_numbers(5, [1, 3, 5, 7, 9]) == {
"odd": [1, 3, 5, 7, 9],
"even": [],
"prime": [3, 5, 7]
}
def test_all_even_numbers():
assert categorize_numbers(4, [2, 4, 6, 8]) == {
"odd": [],
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Categorizes the provided list of numbers into odd, even, and prime.\n\nParameters:\nn (int): The number of elements in the li... | [
1,
1,
0,
0,
0,
1,
1,
1,
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 is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002564",
"row_id": 2564,
"seed_ids": "[27909]"
} | 0.628902 | Evol_2564 | I | [
"is_prime",
"categorize_numbers"
] | 2 | [
[
"categorize_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02c9da8eb73d16996a0faaf40bc5894d26c4b409 | 50cb42517e74ea9b41de680884396eb53a177d6d | |||
v1.0 | instruct | Evol | Evol_2602_I | Create a function in Python that takes a dictionary as an input, where the keys are strings and the values are lists of integers. The function should return a new dictionary with the same keys, but the values should now be the median of the respective lists. If a list is empty, the function should return None for that ... | from typing import List, Dict, Union
def median_of_list(numbers: List[int]) -> Union[int, None]:
"""
Returns the median of the list numbers. If the list is empty, returns None.
"""
if not numbers:
return None
sorted_numbers = sorted(numbers)
n = len(sorted_numbers)
mid_index = ... | from solution import dictionary_medians
def test_dictionary_medians():
assert dictionary_medians({"a": [1, 3, 5], "b": [2, 4, 6, 8], "c": []}) == {"a": 3, "b": 5, "c": None}
assert dictionary_medians({"x": [7, 4, 1], "y": [10, 20, 30, 40], "z": [42]}) == {"x": 4, "y": 25, "z": 42}
assert dictionary_medians... | [
{
"docstring": "Returns the median of the list numbers. If the list is empty, returns None.",
"function_declaration": "def median_of_list(numbers):",
"function_name": "median_of_list",
"parameter_list": "(numbers)"
},
{
"docstring": "Given a dictionary with lists of integers as values, retur... | [
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, Dict, Optional\n\ndef median_of_lists(data: Dict[str, List[int]]) -> Dict[str, Optional[float]]:\n def median(lst: List[int]) -> Option... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002602",
"row_id": 2602,
"seed_ids": "[13790]"
} | 0.722195 | Evol_2602 | I | [
"median_of_list",
"dictionary_medians"
] | 2 | [
[
"dictionary_medians",
"median_of_list"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4f30f0a71e555299b30728bd00fabfde8018d48 | d234dd77895a38ba0a6a5a9764cf98ca49811661 | |||
v1.0 | instruct | Evol | Evol_2615_I | Explain the difference between synchronous and asynchronous programming. Provide a Python example that demonstrates the benefits of using asynchronous programming over synchronous programming in handling multiple tasks. | import time
import asyncio
def synchronous_task(task_name, wait_time):
"""
Simulate a synchronous task by sleeping for wait_time seconds.
"""
print(f"Task {task_name} starting")
time.sleep(wait_time)
print(f"Task {task_name} completed")
def run_synchronous_tasks():
"""
Run multiple syn... | import time
import asyncio
from solution import synchronous_task, run_synchronous_tasks, asynchronous_task, run_asynchronous_tasks
def test_synchronous_task():
start_time = time.time()
run_synchronous_tasks()
elapsed_time = time.time() - start_time
assert elapsed_time >= 10, "Synchronous tasks should t... | [
{
"docstring": "Simulate a synchronous task by sleeping for wait_time seconds.",
"function_declaration": "def synchronous_task(task_name, wait_time):",
"function_name": "synchronous_task",
"parameter_list": "(task_name, wait_time)"
},
{
"docstring": "Run multiple synchronous tasks.",
"fu... | [
0,
1,
1,
1,
1,
1,
1,
0,
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 synchronous_task(n):\n \"\"\"\n Performs a synchronous task by sleeping for n seconds\n and then returning a completion message.\n \"\"\"\n from... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002615",
"row_id": 2615,
"seed_ids": "[32364]"
} | 0.386564 | Evol_2615 | I | [
"synchronous_task",
"run_synchronous_tasks",
"asynchronous_task",
"run_asynchronous_tasks"
] | 4 | [
[
"run_asynchronous_tasks",
"asynchronous_task"
],
[
"run_synchronous_tasks",
"synchronous_task"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 807fb47b635cccd1c493d88eb5c4b1ca20fc67a8 | abe388ece63a3c26711aec701c7f9d78f0497a6e | |||
v1.0 | instruct | Evol | Evol_2624_I | Design and provide three related functions `is_arithmetic_sequence`, `missing_number_in_sequence`, and `restore_arithmetic_sequence`. Here are the key requirements for each function:
- `is_arithmetic_sequence`: Create a function to check if a given list of integers forms an arithmetic sequence or not. An arithmetic se... | def is_arithmetic_sequence(sequence):
"""
Returns True if the given sequence forms an arithmetic sequence, False otherwise.
"""
if len(sequence) < 2:
return True
diff = sequence[1] - sequence[0]
for i in range(2, len(sequence)):
if sequence[i] - sequence[i-1] != diff:
... | from solution import is_arithmetic_sequence, missing_number_in_sequence, restore_arithmetic_sequence
def test_is_arithmetic_sequence():
assert is_arithmetic_sequence([1, 2, 3, 4, 5]) == True
assert is_arithmetic_sequence([2, 4, 6, 8]) == True
assert is_arithmetic_sequence([1, 3, 6]) == False
assert is_... | [
{
"docstring": "Returns True if the given sequence forms an arithmetic sequence, False otherwise.",
"function_declaration": "def is_arithmetic_sequence(sequence):",
"function_name": "is_arithmetic_sequence",
"parameter_list": "(sequence)"
},
{
"docstring": "Identifies and returns the single ... | [
0,
0,
0,
1,
1,
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": "def is_arithmetic_sequence(sequence):\n \"\"\"\n Check if the given list of integers forms an arithmetic sequence.\n \"\"\"\n if len(sequence) < 2:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00002624",
"row_id": 2624,
"seed_ids": "[40425]"
} | 0.67902 | Evol_2624 | I | [
"is_arithmetic_sequence",
"missing_number_in_sequence",
"restore_arithmetic_sequence"
] | 3 | [
[
"restore_arithmetic_sequence",
"is_arithmetic_sequence"
],
[
"restore_arithmetic_sequence",
"missing_number_in_sequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | abdebd927a76ad43be58b4e9a6a2ed7d907caee0 | c6ed77cb660076957e0b381325b5e0198b727bf1 | |||
v1.0 | instruct | Evol | Evol_2645_I | You are to implement a simple library system in Python that manages the borrowing and returning of books. Your task is to write a function that can add books to the library, lend books to users, and return books back to the library. The library system should keep a record of which books are available and which are curr... | library_books = {}
borrowed_books = {}
def add_book(book_title):
library_books[book_title] = library_books.get(book_title, 0) + 1
def borrow_book(book_title, user_name):
if book_title in library_books and library_books[book_title] > 0:
library_books[book_title] -= 1
borrowed_books[book_title] ... | from solution import add_book, borrow_book, return_book, library_books, borrowed_books
def test_add_book():
library_books.clear()
add_book("The Great Gatsby")
assert library_books == {"The Great Gatsby": 1}
def test_borrow_book_success():
library_books.clear()
borrowed_books.clear()
add_book("... | [
{
"docstring": null,
"function_declaration": "def add_book(book_title):",
"function_name": "add_book",
"parameter_list": "(book_title)"
},
{
"docstring": null,
"function_declaration": "def borrow_book(book_title, user_name):",
"function_name": "borrow_book",
"parameter_list": "(b... | [
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": "class Library:\n def __init__(self):\n self.library_books = []\n self.borrowed_books = {}\n\n def add_book(self, book_title):\n if book_... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002645",
"row_id": 2645,
"seed_ids": "[42269]"
} | 0.453013 | Evol_2645 | I | [
"add_book",
"borrow_book",
"return_book"
] | 3 | [
[
"return_book",
"add_book"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87cb26609a970ae7decea5e8d015ed195e7c9807 | 9d9a45d4c857a131a9f702bb30641b03dd17a314 | |||
v1.0 | instruct | Evol | Evol_2653_I | Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, in the same order. Ensure that your function is optimized for efficiency. For example, given the list [4, 7, 10, 11, 13, 18, 19], the function should return [7, 11, 13, 19]. | def is_prime(n):
"""
Helper function to 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 +... | 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(9) == False
assert is_prime(11) == True
def test_filter_primes():
assert filter_primes([4, 7, 10, 1... | [
{
"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 Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00002653",
"row_id": 2653,
"seed_ids": "[16587]"
} | 0.627422 | Evol_2653 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f9c501b5961f9a05af124a87dd7d6e71579ff12 | b15424098a5c5d8f74995c723b5b5fb5b5c12b4d | |||
v1.0 | instruct | Evol | Evol_2694_I | Write a Python function `matrix_manipulation` that generates an N x M matrix filled with elements. The elements of the matrix follow a specific pattern: the value at position (i, j) is calculated as \(3 * i - 2 * j\).
Your function should have the following features:
1. Accept two integers N and M as parameters to de... | import copy
def generate_matrix(N, M):
"""Generates a N x M matrix filled with elements based on the rule 3 * i - 2 * j."""
if N <= 0 or M <= 0:
raise ValueError("N and M must be positive integers")
return [[3 * i - 2 * j for j in range(M)] for i in range(N)]
def transpose_matrix(matrix):
"""T... | from solution import generate_matrix, transpose_matrix, rotate_matrix_90_clockwise, matrix_manipulation
def test_generate_matrix():
matrix = generate_matrix(3, 3)
expected = [
[0, -2, -4],
[3, 1, -1],
[6, 4, 2]
]
assert matrix == expected
def test_transpose_matrix():
matrix... | [
{
"docstring": "Generates a N x M matrix filled with elements based on the rule 3 * i - 2 * j.",
"function_declaration": "def generate_matrix(N, M):",
"function_name": "generate_matrix",
"parameter_list": "(N, M)"
},
{
"docstring": "Transposes the given matrix.",
"function_declaration": ... | [
1,
1,
0,
1,
1,
0,
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 generate_matrix(N, M):\n if not (isinstance(N, int) and isinstance(M, int) and N > 0 and M > 0):\n raise ValueError(\"N and M must be positive intege... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002694",
"row_id": 2694,
"seed_ids": "[22768]"
} | 0.540312 | Evol_2694 | I | [
"generate_matrix",
"transpose_matrix",
"rotate_matrix_90_clockwise",
"matrix_manipulation"
] | 4 | [
[
"matrix_manipulation",
"generate_matrix"
],
[
"matrix_manipulation",
"rotate_matrix_90_clockwise"
],
[
"matrix_manipulation",
"transpose_matrix"
],
[
"rotate_matrix_90_clockwise",
"transpose_matrix"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 146f381a22fc50ba582a4a2456efa14621df5647 | ab8844fa8c137bed469810a3812d1b9763a037b6 | |||
v1.0 | instruct | Evol | Evol_2730_I | Create a Python function to determine if a matrix contains any zeros along its diagonals. Provide two matrices and write code to identify if they contain any zero values along both the primary and secondary diagonals. Optimize your algorithm for efficient processing. In addition, ensure that the function can handle rec... | def hasZeroPrimaryDiagonal(matrix):
"""
Check if there are any zeros along the primary diagonal of the matrix.
"""
for i in range(min(len(matrix), len(matrix[0]))):
if matrix[i][i] == 0:
return True
return False
def hasZeroSecondaryDiagonal(matrix):
"""
Check if there ar... | from solution import hasZeroPrimaryDiagonal, hasZeroSecondaryDiagonal, checkDiagonals
def test_hasZeroPrimaryDiagonal():
matrix1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix2 = [[1, 0], [0, 2]]
matrix3 = [[1, 2, 3], [4, 0, 6], [7, 8, 9]]
assert hasZeroPrimaryDiagonal(matrix1) == False
assert hasZeroP... | [
{
"docstring": "Check if there are any zeros along the primary diagonal of the matrix.",
"function_declaration": "def hasZeroPrimaryDiagonal(matrix):",
"function_name": "hasZeroPrimaryDiagonal",
"parameter_list": "(matrix)"
},
{
"docstring": "Check if there are any zeros along the secondary ... | [
0,
0,
1,
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": "def hasZeroPrimaryDiagonal(matrix):\n \"\"\"\n Check if the matrix has any zeroes along the primary diagonal.\n \"\"\"\n rows = len(matrix)\n for i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00002730",
"row_id": 2730,
"seed_ids": "[22134]"
} | 0.448894 | Evol_2730 | I | [
"hasZeroPrimaryDiagonal",
"hasZeroSecondaryDiagonal",
"checkDiagonals"
] | 3 | [
[
"checkDiagonals",
"hasZeroPrimaryDiagonal"
],
[
"checkDiagonals",
"hasZeroSecondaryDiagonal"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0527aaa7a3fbd996885e76d063805f021ffcc82b | d2e4cdd6ac2ee2cae9bc04f3a862d17a86f692c6 | |||
v1.0 | instruct | Evol | Evol_2742_I | Formulate a Python algorithm that takes in a list of integers and returns a new list containing only the prime numbers from the original list. | def is_prime(n):
"""
Check if a number 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
re... | 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(17) == True
assert is_prime(19) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-5) == Fals... | [
{
"docstring": "Check if a number is a prime number.",
"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 filter_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 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": "00002742",
"row_id": 2742,
"seed_ids": "[32243]"
} | 0.614946 | Evol_2742 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c7909d07f7942aa798070965a16f5b44e8f4c66 | 385b7e60ede0303bac636e71e7067b5a6abdb346 | |||
v1.0 | instruct | Evol | Evol_2761_I | Create a Python function that takes a list of positive integers and returns a new list where each integer is replaced by the sum of its prime factors. The function should then calculate and return the sum of all elements in the new list. Note that if a number itself is prime, its prime factor sum is the number itself.
... | def prime_factors(n):
"""
Returns a list of prime factors of the given number n.
"""
i = 2
factors = []
while i * i <= n:
while (n % i) == 0:
factors.append(i)
n //= i
i += 1
if n > 1:
factors.append(n)
return factors
def prime_factor_sum(... | from solution import prime_factor_sum
def test_prime_factor_sum_example():
nums = [6, 28, 15]
assert prime_factor_sum(nums) == 24
def test_prime_factor_sum_single_number():
nums = [6]
assert prime_factor_sum(nums) == 5
def test_prime_factor_sum_prime_numbers():
nums = [2, 3, 5, 7, 11]
assert ... | [
{
"docstring": "Returns a list of prime factors of the given number n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the sum of prime factors for each number in the input list.",
"functio... | [
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_prime_factors(n):\n \"\"\"\n Returns the sum of prime factors of the given number n.\n If n is prime, it returns n.\n \"\"\"\n def is_pri... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00002761",
"row_id": 2761,
"seed_ids": "[46366]"
} | 0.688266 | Evol_2761 | I | [
"prime_factors",
"prime_factor_sum"
] | 2 | [
[
"prime_factor_sum",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4213431c2c6b44ace4d72b9395cda714e703ed8a | 1855da743909f6411b351b3e0943284aeaa40316 | |||
v1.0 | instruct | Evol | Evol_2765_I | Given a list of integers, determine the count of unique prime numbers present in the list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
```
list = [2, 3, 5, 7, 8, 10, 11, 13, 13, 3]
# Output: 5 (unique prime numbers are 2, 3, 5, 7, 11, 13)
``` | def is_prime(n):
"""
Checks if a 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
return T... | from solution import count_unique_primes, is_prime
def test_is_prime():
# Test lower primes
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
# Test non-primes and larger primes
assert is_prime(1) == False
assert is_prime(4)... | [
{
"docstring": "Checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of unique prime numbers in the list numbers.",
"function_declaration": "def count_unique_primes(numbers):... | [
1,
1,
1,
1,
1,
0,
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 count_unique_prime_numbers(nums):\n \"\"\"\n Given a list of integers, this function returns the count of unique prime numbers present in the list.\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002765",
"row_id": 2765,
"seed_ids": "[8830]"
} | 0.644488 | Evol_2765 | I | [
"is_prime",
"count_unique_primes"
] | 2 | [
[
"count_unique_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bbe42dcadcf271d62e3956ef722ce2e0dd670040 | 2d739b385ba7953a309a6017a807e8f579e53544 | |||
v1.0 | instruct | Evol | Evol_2781_I | Implement a function that takes an array of integers and returns a new array containing only the prime numbers from the original array. The function should be optimized to handle an array with up to 10,000 integers efficiently. As part of your solution, include a helper function that determines if a given integer is pr... | def is_prime(n):
"""
Determines 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... | from solution import is_prime, primes_from_array
def test_is_prime():
assert not is_prime(0)
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)
assert is_prime(11)
assert not is_prime(15)
assert is_prime(... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing only the prime numbers from the original array.",
"function_declaration": "def primes_from... | [
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": "00002781",
"row_id": 2781,
"seed_ids": "[25872]"
} | 0.602369 | Evol_2781 | I | [
"is_prime",
"primes_from_array"
] | 2 | [
[
"primes_from_array",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7642c1967aea17f1b1690ab0b46a4c48985c4e8b | 41166f5abb452ce27da715b5eb8c5afbdc86c296 | |||
v1.0 | instruct | Evol | Evol_2803_I | Write a Python function to find the longest substring without repeating characters from a given string. The function should return the substring and its length. Document any assumptions you make, and analyze the time complexity of your solution. Additionally, extend the function to handle a list of strings and output t... | def longest_unique_substring(s):
"""
Returns the longest substring without repeating characters from a given string s,
and its length.
"""
char_index_map = {}
longest_substring = ""
start = 0
for i, char in enumerate(s):
if char in char_index_map and char_index_map[char] >= star... | from solution import longest_unique_substring, longest_unique_substrings
def test_longest_unique_substring_single_string():
assert longest_unique_substring("abcabcbb") == ("abc", 3)
assert longest_unique_substring("bbbbb") == ("b", 1)
assert longest_unique_substring("pwwkew") == ("wke", 3)
assert longe... | [
{
"docstring": "Returns the longest substring without repeating characters from a given string s,\nand its length.",
"function_declaration": "def longest_unique_substring(s):",
"function_name": "longest_unique_substring",
"parameter_list": "(s)"
},
{
"docstring": "Returns the longest substri... | [
1,
0,
1,
1,
0,
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": "def longest_substring_no_repeats(s):\n \"\"\"\n Finds the longest substring without repeating characters from a given string.\n \n Args:\n s (str): ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00002803",
"row_id": 2803,
"seed_ids": "[40594]"
} | 0.72168 | Evol_2803 | I | [
"longest_unique_substring",
"longest_unique_substrings"
] | 2 | [
[
"longest_unique_substrings",
"longest_unique_substring"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d04b2ff024bfff7d93ba1b656fe848127daed693 | 57d1257a57e205eafb86ae4bac6df42f5eac03ec | |||
v1.0 | instruct | Evol | Evol_2821_I | Write a function in Python that takes an integer `n` and returns a list containing the first `n` prime numbers. Your solution should be efficient and consider the time complexity of the algorithm used to find prime numbers. | def is_prime(num):
"""
Helper function to determine 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
d... | from solution import first_n_primes
def test_first_n_primes_zero():
assert first_n_primes(0) == []
def test_first_n_primes_one():
assert first_n_primes(1) == [2]
def test_first_n_primes_five():
assert first_n_primes(5) == [2, 3, 5, 7, 11]
def test_first_n_primes_ten():
assert first_n_primes(10) == [... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
... | [
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 is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00002821",
"row_id": 2821,
"seed_ids": "[37567]"
} | 0.715079 | Evol_2821 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 32e69f216238618499231b68c1e1c402bf272994 | f569602d9bddd96d69991d766a0606e4b5693454 | |||
v1.0 | instruct | Evol | Evol_2823_I | Given an integer, determine whether it is a T-prime or not. A T-prime is a number that is the square of a prime number. For example, 4 is a T-prime because it is equal to $2^2$, where 2 is a prime number.
### Input
- A single integer $n$, where $1 \leq n \leq 10^{12}$.
### Output
- Output "YES" if the number is a T-p... | import math
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
... | from solution import is_t_prime
def test_t_prime():
assert is_t_prime(49) == "YES"
assert is_t_prime(10) == "NO"
assert is_t_prime(4) == "YES"
assert is_t_prime(9) == "YES"
assert is_t_prime(25) == "YES"
assert is_t_prime(1) == "NO"
assert is_t_prime(1000000000000) == "NO" # This is 10^12 a... | [
{
"docstring": "Check if a number n is a prime number ",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number n is a T-prime ",
"function_declaration": "def is_t_prime(n):",
"function_name": "is_t_prime"... | [
1,
1,
0,
0,
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": "import math\n\ndef is_prime(n):\n \"\"\" Check if a number n is a prime number \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00002823",
"row_id": 2823,
"seed_ids": "[8601]"
} | 0.60808 | Evol_2823 | I | [
"is_prime",
"is_t_prime"
] | 2 | [
[
"is_t_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bbe9a44a7d36024b09d45466b761338ecfcee70f | 6180c00c0a6a1775ea82e3d0ef83c37522fb11fb | |||
v1.0 | instruct | Evol | Evol_2830_I | Create a Python program that reads a file containing a list of integers, one per line. Implement a function to identify all prime numbers from the list and write them into a new file. Then, create another function to read this new file, sum all the prime numbers, and return the sum along with the count of total prime n... | import os
def read_integers_from_file(file_path):
"""
Reads a list of integers from the specified file.
Each line in the file should contain one integer.
Returns a list of integers.
Raises ValueError if the file contains non-integer values.
"""
integers = []
try:
with open(file... | import os
import pytest
from solution import read_integers_from_file, write_primes_to_file, sum_and_count_primes, is_prime
# Helper function for creating test files
def create_test_file(file_path, lines):
with open(file_path, 'w') as file:
file.write('\n'.join(lines))
def test_read_integers_from_file():
... | [
{
"docstring": "Reads a list of integers from the specified file.\nEach line in the file should contain one integer.\n\nReturns a list of integers.\nRaises ValueError if the file contains non-integer values.",
"function_declaration": "def read_integers_from_file(file_path):",
"function_name": "read_inte... | [
1,
1,
1,
1,
0,
1,
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 is_prime(n):\n \"\"\"\n Checks if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00002830",
"row_id": 2830,
"seed_ids": "[27978]"
} | 0.60227 | Evol_2830 | I | [
"read_integers_from_file",
"is_prime",
"write_primes_to_file",
"sum_and_count_primes"
] | 4 | [
[
"write_primes_to_file",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 79576008cbd0bb24ac707a07420cd737d922c4cf | a5012ab2e3b0ad11c793acc28664bba99d7bc886 | |||
v1.0 | instruct | Evol | Evol_2845_I | Create a Python script that reads the file 'transactions.csv', which contains transaction records with the fields: `transaction_id`, `timestamp`, `customer_id`, `amount`, and `category`. Write a function to load the data into a pandas DataFrame. Then perform the following tasks:
1. Write a function to determine the to... | import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def load_transactions(file_path):
"""
Load the transaction data into a pandas DataFrame.
"""
return pd.read_csv(file_path)
def unique_customers(df):
"""
Determine the total number of unique customers.
"""
return df[... | import pandas as pd
import numpy as np
from solution import load_transactions, unique_customers, total_transaction_amount_by_category, top_5_customers_by_spending, peak_hour_per_day, remove_outliers
def test_unique_customers():
data = {
'transaction_id': [1, 2, 3, 4, 5],
'timestamp': ['2023-01-01 1... | [
{
"docstring": "Load the transaction data into a pandas DataFrame.",
"function_declaration": "def load_transactions(file_path):",
"function_name": "load_transactions",
"parameter_list": "(file_path)"
},
{
"docstring": "Determine the total number of unique customers.",
"function_declarati... | [
0,
0,
1,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import pandas as pd\nimport matplotlib.pyplot as plt\n\ndef load_data(file_path):\n return pd.read_csv(file_path)\n\ndef get_unique_customers(data):\n return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00002845",
"row_id": 2845,
"seed_ids": "[32832]"
} | 0.45434 | Evol_2845 | I | [
"load_transactions",
"unique_customers",
"total_transaction_amount_by_category",
"top_5_customers_by_spending",
"peak_hour_per_day",
"visualize_data",
"remove_outliers"
] | 7 | [
[
"visualize_data",
"top_5_customers_by_spending"
],
[
"visualize_data",
"total_transaction_amount_by_category"
]
] | 2 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"pandas"
] | false | d0946d36b8c60d46ac5ea1600872ffb98bfe2cb9 | a11a8602f738e754e691a60fee2bdfcddfb687c8 | |||
v1.0 | instruct | Evol | Evol_2893_I | Emily is applying the "Multiply by 4 and Subtract 3" rule to create her numerical sequence starting with 1. Which of the following statements about the sequence is most accurate?
A) The fifth element in the sequence will be an even number.
B) There will always be a mix of even and odd numbers in the sequence.
C) The p... | def next_element(n):
"""
Returns the next element in the sequence following
the "Multiply by 4 and Subtract 3" rule.
"""
return (n * 4) - 3
def generate_sequence(start, length):
"""
Generates a sequence of given length starting from the given value.
"""
sequence = [start]
for _... | from solution import next_element, generate_sequence
def test_next_element():
assert next_element(1) == 1
assert next_element(2) == 5
assert next_element(-1) == -7
def test_generate_sequence():
assert generate_sequence(1, 5) == [1, 1, 1, 1, 1]
assert generate_sequence(2, 3) == [2, 5, 17]
asser... | [
{
"docstring": "Returns the next element in the sequence following \nthe \"Multiply by 4 and Subtract 3\" rule.",
"function_declaration": "def next_element(n):",
"function_name": "next_element",
"parameter_list": "(n)"
},
{
"docstring": "Generates a sequence of given length starting from the... | [
0,
0,
1,
0,
1,
0,
0,
1,
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 sequence_element(n):\n \"\"\"\n Returns the nth element in the sequence starting with 1,\n and using the \"Multiply by 4 and Subtract 3\" rule.\n \... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002893",
"row_id": 2893,
"seed_ids": "[10049]"
} | 0.490581 | Evol_2893 | I | [
"next_element",
"generate_sequence"
] | 2 | [
[
"generate_sequence",
"next_element"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f075809db85e299713a6a18c3a76391e1858b082 | 7f2a6f2a6b341c4718bffccb5551cecae29fe031 | |||
v1.0 | instruct | Evol | Evol_2900_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 an input element is not an integer, the function should skip it and continue processing the next element. Optimize the function to handle large lists efficiently.
For example:
inpu... | def is_prime(n):
"""
Helper function to 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 +... | from solution import extract_primes
def test_extract_primes_with_mixed_inputs():
assert extract_primes([11, 22, "foo", 3, 4.5, 5]) == [11, 3, 5]
def test_extract_primes_with_non_primes():
assert extract_primes([6, 8, 10, 15]) == []
def test_extract_primes_with_primes():
assert extract_primes([2, 3, 5, 7,... | [
{
"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 input list of integers.\nSkips non-integer elements."... | [
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 the given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002900",
"row_id": 2900,
"seed_ids": "[16872]"
} | 0.64426 | Evol_2900 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d6a38c0d3c8be3d8add790d69e59b65252b0a2b | c7c24b6a30a4ff86cb7639972a9d382800b73842 | |||
v1.0 | instruct | Evol | Evol_2913_I | Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, in the same order.
Function Signature:
```python
def filter_primes(numbers: List[int]) -> List[int]:
pass
```
Input:
- A list of integers (0 <= len(numbers) <= 1000, -10^6 <= numbers[... | from typing import List
def is_prime(n: int) -> bool:
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(numbers: List[int]) -> List[... | from solution import filter_primes
def test_filter_primes_with_primes_and_non_primes():
assert filter_primes([10, 29, 15, 37, -3, 17, 23]) == [29, 37, 17, 23]
def test_filter_primes_with_mixed_numbers():
assert filter_primes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [2, 3, 5, 7]
def test_filter_primes_with_empty_li... | [
{
"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,
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\nimport math\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n if num ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00002913",
"row_id": 2913,
"seed_ids": "[45816]"
} | 0.648493 | Evol_2913 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 345c9392fccf03d0ef903a6d3fdcc91574bada50 | 9d0643aba2edd0f2c8310cba9f9692e98163e3d6 | |||
v1.0 | instruct | Evol | Evol_2919_I | Implement a k-means clustering algorithm from scratch and use it to cluster the data from the Iris dataset. After obtaining the clusters, use a silhouette score to evaluate the quality of the clustering. Compare the silhouette score of your implementation with the score obtained using Scikit-learn’s k-means implementat... | import numpy as np
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import silhouette_score
def initialize_centroids(X, k):
np.random.seed(42)
random_indices = np.random.permutation(np.arange(len(X)))
centroids = X[random_indices[:k]]
return c... | from solution import preprocess_iris_data, kmeans, compute_silhouette_score
from sklearn.cluster import KMeans
import numpy as np
def test_initialize_centroids():
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
centroids = initialize_centroids(X, 2)
assert centroids.shape == (2, 2)
assert len(np.unique(... | [
{
"docstring": null,
"function_declaration": "def initialize_centroids(X, k):",
"function_name": "initialize_centroids",
"parameter_list": "(X, k)"
},
{
"docstring": null,
"function_declaration": "def assign_clusters(X, centroids):",
"function_name": "assign_clusters",
"parameter... | [
0,
1,
1,
1,
1,
1,
1,
0,
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 numpy as np\nimport pandas as pd\nfrom sklearn.datasets import load_iris\nfrom sklearn.metrics import silhouette_score\nfrom sklearn.preprocessing import St... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002919",
"row_id": 2919,
"seed_ids": "[31991]"
} | 0.470661 | Evol_2919 | I | [
"initialize_centroids",
"assign_clusters",
"update_centroids",
"kmeans",
"preprocess_iris_data",
"compute_silhouette_score"
] | 6 | [
[
"kmeans",
"assign_clusters"
],
[
"kmeans",
"initialize_centroids"
],
[
"kmeans",
"update_centroids"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy",
"sklearn"
] | false | ec0a3e4b919a85ee881c0a64c08e68f60a159428 | 8dca08126c8898ab4826d4da802381ddf0a38f93 | |||
v1.0 | instruct | Evol | Evol_2925_I | Create a Python function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. The function should remove any duplicates and maintain the original order of the first occurrence of each prime number.
numbers = [17, 23, 23, 4, 2, 5, 4, 29, 5, 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
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_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filter_primes_with_duplicates():
assert filter_primes([17, 23, 23, 4, 2, 5, 4, 29, 5, 17]) == [17, 23, 2, 5, 29]
def test_filter_primes_no_primes():
assert filter_pr... | [
{
"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 unique prime numbers maintaining the original order.",
"function_declaration": "def filte... | [
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 n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002925",
"row_id": 2925,
"seed_ids": "[23267]"
} | 0.675347 | Evol_2925 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8409992f4bb6b63ff3ded0511c909f223ee4883a | 39f3e37bf3cdd0c1b1ee7e7fae3b84c803112ff9 | |||
v1.0 | instruct | Evol | Evol_2933_I | Write a function in Python to calculate the nth Fibonacci number, but with the added constraint that every number in the sequence is generated using memoization to optimize performance. Your function should handle large inputs efficiently (e.g., n = 1000). Additionally, write a function to calculate the time complexity... | def fibonacci(n, memo={}):
"""
Calculate the nth Fibonacci number using memoization.
Args:
n (int): The position in the Fibonacci sequence.
memo (dict): Dictionary to store previously calculated Fibonacci numbers.
Returns:
int: The nth Fibonacci number.
"""
if n in memo:
... | import time
from solution import fibonacci, non_memoized_fibonacci, time_complexity, test_memoization
def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(10) == 55
assert fibonacci(20) == 6765
assert fibonacci(30) == 832040
assert fibonacci(50) == 1258626902... | [
{
"docstring": "Calculate the nth Fibonacci number using memoization.\n\nArgs:\nn (int): The position in the Fibonacci sequence.\nmemo (dict): Dictionary to store previously calculated Fibonacci numbers.\n\nReturns:\nint: The nth Fibonacci number.",
"function_declaration": "def fibonacci(n, memo={}):",
... | [
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Calculate the nth Fibonacci number using memoization.\n \n Args:\n n (int): The position in the Fibonacci sequ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00002933",
"row_id": 2933,
"seed_ids": "[862]"
} | 0.702932 | Evol_2933 | I | [
"fibonacci",
"non_memoized_fibonacci",
"time_complexity",
"test_memoization"
] | 4 | [
[
"test_memoization",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71a16fd1d62849c6721efab06ebfbafbfe3d8ecd | 0bc439bc78135e7394938905b57e0d3e65d5588f | |||
v1.0 | instruct | Evol | Evol_2949_I | Create a program that implements a basic chat server using WebSockets in Python. The server should be capable of handling multiple simultaneous client connections. Implement the following features:
1. A way for new users to connect to the chat by providing a unique username.
2. Broadcast a new user's arrival to all co... | import asyncio
import websockets
import json
clients = {}
usernames = set()
async def register_client(websocket):
while True:
msg = await websocket.recv()
msg_data = json.loads(msg)
if msg_data["action"] == "register":
username = msg_data["username"]
if use... | import asyncio
import websockets
import json
import pytest
from solution import start_server
@pytest.fixture
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close()
@pytest.fixture
async def server(event_loop):
server = await start_server
yield server
server.close()
awai... | [] | [
0,
1,
1,
0,
0,
0,
1,
0,
1,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import asyncio\nimport websockets\nimport json\n\nclients = {} # Dictionary to store clients and their usernames\n\nasync def broadcast(message):\n \"\"\"Send ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00002949",
"row_id": 2949,
"seed_ids": "[13978]"
} | 0.546328 | Evol_2949 | I | [
"register_client",
"unregister_client",
"broadcast",
"handler"
] | 4 | [
[
"handler",
"broadcast"
],
[
"handler",
"register_client"
],
[
"handler",
"unregister_client"
],
[
"register_client",
"broadcast"
],
[
"unregister_client",
"broadcast"
]
] | 5 | [] | false | [] | false | pytest | true | [
"websockets"
] | false | 9818046409518e6c2222b322b49f160233431f36 | 2ca4eabadf87bea0424d229dfe93b72fd5acf233 | |||
v1.0 | instruct | Evol | Evol_2950_I | Create a function in a programming language that takes a list of integers and sorts it using the Merge Sort algorithm. The function should recursively divide the list into halves until each sublist has one element, then merge the sorted sublists to produce the sorted list. The function must be implemented without using... | def merge_sort(arr):
"""
Sorts a list of integers using the Merge Sort algorithm.
Parameters:
arr (list): List of integers to sort.
Returns:
list: Sorted list of integers.
"""
# Base case: a list of zero or one elements is already sorted
if len(arr) <= 1:
return arr
... | from solution import merge_sort
def test_merge_sort_with_positive_numbers():
assert merge_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62]
def test_merge_sort_with_negative_numbers():
assert merge_sort([-12, -3, -7, -1, 0, -2]) == [-12, -7, -3, -2, -1, 0]
def test_merge_sort_with_mixed_sign_numbers():
... | [
{
"docstring": "Sorts a list of integers using the Merge Sort algorithm.\n\nParameters:\narr (list): List of integers to sort.\n\nReturns:\nlist: Sorted list of integers.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstrin... | [
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(lst):\n \"\"\"\n Sorts a list of integers using the Merge Sort algorithm.\n \"\"\"\n if len(lst) <= 1:\n return lst\n\n # Divi... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002950",
"row_id": 2950,
"seed_ids": "[15488]"
} | 0.64269 | Evol_2950 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 67a16a867e453de164a7ea3ca83c337b631ee96e | dd4e8bb209a2c9811cde942b8f8fe1146717e8e3 | |||
v1.0 | instruct | Evol | Evol_2962_I | Devise a code that takes an array of integers as input and determines if there exists a pair of indices (i, j) such that i < j and the sum of elements at these indices is a prime number. | def is_prime(n):
"""Returns True if n is a prime number, False otherwise."""
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 pair_with_prime_... | from solution import is_prime, pair_with_prime_sum
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(0) == False
assert is_prime(-1) == False
assert is_prime(29) =... | [
{
"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": "Takes an array of integers and returns True if there's a pair of indices (i, j) such that i < j\nand the... | [
1,
0,
0,
0,
0,
0,
0,
1,
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": "def is_prime(n):\n \"\"\"Returns True if n is a prime number, False otherwise.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00002962",
"row_id": 2962,
"seed_ids": "[20046]"
} | 0.668129 | Evol_2962 | I | [
"is_prime",
"pair_with_prime_sum"
] | 2 | [
[
"pair_with_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f3bdded485bd18dd6089e7a0a8485a1b6fd70c3 | 1f5ab953cf9b54553671594db9c381c840e274b3 | |||
v1.0 | instruct | Evol | Evol_2963_I | Write a function in Python that reads a large text file and counts the frequency of each word using multiple processes. The function should divide the file into chunks and spawn a separate process to count words in each chunk. Ensure that the file reading and word counting operations are thread-safe. Also, the function... | import os
import multiprocessing
from collections import Counter
import re
class FileNotFoundError(Exception):
pass
def read_chunk(file_name, start, size):
with open(file_name, "rb") as f:
f.seek(start)
chunk = f.read(size)
return chunk
def count_words_in_chunk(chunk):
chunk = chunk.d... | import os
import pytest
from solution import word_count_in_file, FileNotFoundError
def create_test_file():
content = "Hello, world! Hello! This is a test file. Hello world! "
content *= 10000 # create a large file by repeating the content
with open("test_file.txt", "w") as f:
f.write(content)
@pyt... | [] | [
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 os\nfrom collections import Counter\nfrom multiprocessing import Process, Pipe\nimport mmap\n\nclass CustomFileNotFoundError(Exception):\n pass\n\ndef co... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002963",
"row_id": 2963,
"seed_ids": "[24858]"
} | 0.68558 | Evol_2963 | I | [
"read_chunk",
"count_words_in_chunk",
"word_count_in_file",
"process_chunk"
] | 4 | [
[
"process_chunk",
"count_words_in_chunk"
],
[
"process_chunk",
"read_chunk"
],
[
"word_count_in_file",
"process_chunk"
]
] | 3 | [] | false | [
"FileNotFoundError"
] | true | pytest | true | [] | true | 1d9350fa2e2efa4eb699ea659c8c905e265a78f4 | d892ce5eaa696becad8ec0d8b16f9ed173f76949 | |||
v1.0 | instruct | Evol | Evol_2971_I | Write a function that accepts an array of strings and returns a new array containing only the strings that are palindromes. A palindrome is a word that reads the same forwards and backwards, case-insensitively. The function should not use any built-in string reversal methods.
Example:
Input: ["Racecar", "hello", "Leve... | def is_palindrome(word):
"""
Helper function to check if a given word is a palindrome.
The function is case-insensitive.
"""
word = word.lower()
left, right = 0, len(word) - 1
while left < right:
if word[left] != word[right]:
return False
left += 1
right -... | from solution import filter_palindromes
def test_filter_palindromes_basic():
assert filter_palindromes(["Racecar", "hello", "Level", "world", "noon", "Python"]) == ["Racecar", "Level", "noon"]
def test_filter_palindromes_no_palindromes():
assert filter_palindromes(["hello", "world", "Python"]) == []
def test... | [
{
"docstring": "Helper function to check if a given word is a palindrome.\nThe function is case-insensitive.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Returns a new array containing only the palindrom... | [
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_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n s = s.lower() # Case-insensitive check\n le... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002971",
"row_id": 2971,
"seed_ids": "[5661]"
} | 0.734882 | Evol_2971 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ecdc0501a7cc32db15cae734f229de75ffff59da | 7d56ec012b0ee544d0f41efd2ac2c7aded3b1386 | |||
v1.0 | instruct | Evol | Evol_2972_I | Write a function that takes in a list of integers and returns a new list containing only the prime numbers from the original list, preserving their order. Implement an efficient algorithm to check for primality to ensure the function can handle large input sizes. | def is_prime(num):
"""
Checks 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 False
i += ... | 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(35) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == Fal... | [
{
"docstring": "Checks 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 filter_primes(number... | [
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": "from math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00002972",
"row_id": 2972,
"seed_ids": "[31541]"
} | 0.611633 | Evol_2972 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d11c62901648b8e6a5e20266c1a94903043404fc | 344c94274d241fb8fa448593cc0d2a8d670692a8 | |||
v1.0 | instruct | Evol | Evol_2974_I | Write a function `is_prime(n)` that checks whether a given integer `n` is a prime number. Return `True` if `n` is prime, and `False` otherwise. Then, using this helper function, create a function `prime_in_range(start, end)` that returns a list of all prime numbers within the given range `start` to `end`, including bot... | def is_prime(n):
"""
Check if the integer n is a prime number.
Parameters:
- n (int): The integer to check for primality.
Returns:
- bool: True if n is prime, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
... | from solution import is_prime, prime_in_range
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(19) == True
assert is_prime(1) == False # 1 is not a prime number
... | [
{
"docstring": "Check if the integer n is a prime number.\n\nParameters:\n- n (int): The integer to check for primality.\n\nReturns:\n- bool: True if n is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstrin... | [
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 the integer n is a prime number.\n \n Parameters:\n - n (int): The integer to check for primality.\n \n R... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00002974",
"row_id": 2974,
"seed_ids": "[24026]"
} | 0.760805 | Evol_2974 | I | [
"is_prime",
"prime_in_range"
] | 2 | [
[
"prime_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60a158f7f561bd525fed2c103cd6421b6e9ce4c7 | 28ccef8bffad7df5f917137f71ccc9e2ad05ee9a | |||
v1.0 | instruct | Evol | Evol_3030_I | Explain how the Knuth-Morris-Pratt (KMP) algorithm improves pattern searching within a text. Illustrate the concept with an example, detailing the preprocessing step and the search step. Highlight the advantages of using KMP over the naive string matching algorithm. | def compute_lps(pattern):
length = 0
lps = [0] * len(pattern)
i = 1
while i < len(pattern):
if pattern[i] == pattern[length]:
length += 1
lps[i] = length
i += 1
else:
if length != 0:
length = lps[length - 1]
els... | from solution import kmp_search, compute_lps
def test_compute_lps():
assert compute_lps("AABAACAABAA") == [0, 1, 0, 1, 2, 0, 1, 2, 3, 4, 5]
assert compute_lps("ABCDE") == [0, 0, 0, 0, 0]
assert compute_lps("AAACAAAA") == [0, 1, 2, 0, 1, 2, 3, 3]
assert compute_lps("ABABCABAB") == [0, 0, 1, 2, 0, 1, 2, ... | [
{
"docstring": null,
"function_declaration": "def compute_lps(pattern):",
"function_name": "compute_lps",
"parameter_list": "(pattern)"
},
{
"docstring": null,
"function_declaration": "def kmp_search(text, pattern):",
"function_name": "kmp_search",
"parameter_list": "(text, patte... | [
1,
0,
0,
0,
1,
1,
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 compute_lps(pattern):\n \"\"\"\n Compute the longest prefix which is also suffix (LPS) array for the pattern.\n \"\"\"\n lps = [0] * len(pattern)\n... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00003030",
"row_id": 3030,
"seed_ids": "[27999]"
} | 0.414929 | Evol_3030 | I | [
"compute_lps",
"kmp_search"
] | 2 | [
[
"kmp_search",
"compute_lps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 193c7b005f7122b57f1ec239f1b02b4ace0a65b8 | 37f0921bf9332940f1c2844b38c52fec6ed8219d | |||
v1.0 | instruct | Evol | Evol_3040_I | Create a function in a language of your choice that takes a list of integers and returns a dictionary where the keys are the unique integers and the values are Booleans indicating whether the integer is prime.
The function should handle error scenarios such as when the input list contains non-integer elements.
Examp... | def is_prime(n):
"""
Determines if a given number n is prime.
Args:
- n (int): The number to check for primality.
Returns:
- bool: True if n is prime, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2... | from solution import prime_dict, is_prime
def test_prime_dict_with_mixed_elements():
numbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 'a', 15]
expected_output = {
2: True,
3: True,
4: False,
5: True,
6: False,
7: True,
8: False,
9: False,
10... | [
{
"docstring": "Determines if a given number n is prime.\n\nArgs:\n- n (int): The number to check for primality.\n\nReturns:\n- bool: True if n is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Ret... | [
1,
1,
1,
1,
1,
0,
1,
0,
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 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_9 | {
"original_instruction": "",
"prompt_id": "00003040",
"row_id": 3040,
"seed_ids": "[9315]"
} | 0.708353 | Evol_3040 | I | [
"is_prime",
"prime_dict"
] | 2 | [
[
"prime_dict",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2103b06d4ab8a78d4ea90131ddbd352062f4af0 | e9b507521dfab71229b346fa97d0c486b6ea22ae | |||
v1.0 | instruct | Evol | Evol_3072_I | Design an algorithm that receives a list of integers and returns a new list containing only the prime numbers from the original list. Optimize your solution to handle lists containing up to 10,000 integers efficiently. Provide a Python function implementing the algorithm and include necessary helper functions to check ... | def is_prime(n):
"""
Helper function to 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 +... | 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(29) == True
assert is_prime(25) == False
assert is_prime(1) == False
assert is_prime(0) == False... | [
{
"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 list.",
"function_declaration": "def fil... | [
1,
1,
0,
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 is_prime(n):\n \"\"\"\n Checks if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00003072",
"row_id": 3072,
"seed_ids": "[28850]"
} | 0.611055 | Evol_3072 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0383eb07111f2d2cb3a53c37e6844f4ed1c14e1c | 3c22bb6a4485ccd5d17d7979c1357ebf22d8a3ed | |||
v1.0 | instruct | Evol | Evol_3083_I | Implement a Python function that takes a list of integers and returns a new list with the squares of the original integers, but only for those integers that are even. Each intermediate step, from filtering the even numbers to computing their squares, should be handled within separate helper functions to demonstrate mod... | def filter_even_numbers(numbers):
"""
Returns a list of even numbers from the input list.
"""
return [num for num in numbers if num % 2 == 0]
def square_numbers(numbers):
"""
Returns a list of squared numbers from the input list.
"""
return [num ** 2 for num in numbers]
def process_num... | from solution import filter_even_numbers, square_numbers, process_numbers
def test_filter_even_numbers():
assert filter_even_numbers([1, 2, 3, 4, 5]) == [2, 4]
assert filter_even_numbers([1, 3, 5]) == []
assert filter_even_numbers([2, 4, 6]) == [2, 4, 6]
def test_square_numbers():
assert square_number... | [
{
"docstring": "Returns a list of even numbers from the input list.",
"function_declaration": "def filter_even_numbers(numbers):",
"function_name": "filter_even_numbers",
"parameter_list": "(numbers)"
},
{
"docstring": "Returns a list of squared numbers from the input list.",
"function_d... | [
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 filter_even_numbers(numbers):\n \"\"\"\n Filters out the even numbers from a list.\n \"\"\"\n return [num for num in numbers if num % 2 == 0]\n\nde... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003083",
"row_id": 3083,
"seed_ids": "[27873]"
} | 0.675604 | Evol_3083 | I | [
"filter_even_numbers",
"square_numbers",
"process_numbers"
] | 3 | [
[
"process_numbers",
"filter_even_numbers"
],
[
"process_numbers",
"square_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fb816a472b163916232a109d6fe2e40fd268d7bb | 0b0fb18c91f48a57ee3ed83b5356bffcae47b4ad | |||
v1.0 | instruct | Evol | Evol_3100_I | Devise an efficient algorithm to sort a list of integers which consists of both positive and negative numbers. Optimize the algorithm to handle lists with large numbers of elements where a traditional quicksort or mergesort may prove inefficient. Additionally, implement a function to measure and compare the performance... | def optimized_sort(nums):
"""
An efficient sorting algorithm to sort a list of both positive and negative integers.
Uses Timsort algorithm which is efficient for large datasets.
"""
return sorted(nums)
def performance_test(size):
import random
from time import time
nums = [random.randi... | from solution import optimized_sort, performance_test
def test_small_list():
assert optimized_sort([4, -1, 7, -3, 2, -6, 5]) == [-6, -3, -1, 2, 4, 5, 7]
assert optimized_sort([]) == []
assert optimized_sort([1]) == [1]
def test_all_positive():
assert optimized_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
... | [
{
"docstring": "An efficient sorting algorithm to sort a list of both positive and negative integers.\nUses Timsort algorithm which is efficient for large datasets.",
"function_declaration": "def optimized_sort(nums):",
"function_name": "optimized_sort",
"parameter_list": "(nums)"
},
{
"docs... | [
0,
1,
1,
0,
0,
1,
1,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "def radix_sort(nums):\n \"\"\"\n An optimized sorting algorithm using Radix Sort\n that works efficiently for positive and negative numbers.\n \"\"\"\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003100",
"row_id": 3100,
"seed_ids": "[25046]"
} | 0.621648 | Evol_3100 | I | [
"optimized_sort",
"performance_test"
] | 2 | [
[
"performance_test",
"optimized_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 453561b101ece45c229e37f0106b2ed25a725f82 | 8dcb670a79fe5f3c1276e46a20387670aea7bd4b | |||
v1.0 | instruct | Evol | Evol_3123_I | Implement a function in Python that accepts a list of integers and returns a new list containing only the prime numbers from the original list. Ensure that the function handles both positive and negative integers, excluding any negative numbers from the result.
def filter_primes(numbers):
# Your code here
# Examp... | 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
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def filter_pr... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([3, 4, -1, 7, 10, 13]) == [3, 7, 13]
def test_filter_primes_with_only_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_pr... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the prime numbers from a list of integers.\n\n:param numbers: List of integers\n:return: List of 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 == 2:\n ret... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003123",
"row_id": 3123,
"seed_ids": "[11111]"
} | 0.580423 | Evol_3123 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6a764610c397598469aef9b79efb4390078bc58e | 4fb77947c9268adff7782c10d6c5c69763ef9c7e | |||
v1.0 | instruct | Evol | Evol_3133_I | Write a function that takes a list of integers as an input and returns a new list that contains only the prime numbers from the original list. To solve this problem, do not use any library functions related to prime number generation or checking. Additionally, optimize the function to minimize the number of calculation... | 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():
assert filter_primes([10, 15, 3, 7, 19, 22, 23, 25, 29]) == [3, 7, 19, 23, 29]
assert filter_primes([4, 6, 8, 10, 12]) == []
assert filter_primes([2, 5, 7, 11, 13]) == [2, 5, 7, 11, 13]
assert filter_primes([1, 2, 3, 4, 5]) == [2, 3, 5]
a... | [
{
"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(input_lis... | [
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 <= 3:\n return True\n if n % 2 == 0 or n % ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003133",
"row_id": 3133,
"seed_ids": "[34227]"
} | 0.623557 | Evol_3133 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b27e0466979f6ff78651e64075eff647a4427ab3 | 54470191e4510c4d78fe55487ce2517885ac9e3d | |||
v1.0 | instruct | Evol | Evol_3165_I | Implement a matrix manipulation program that performs the following operations based on user input:
1. Transpose the Matrix
2. Rotate the Matrix 90 degrees clockwise
3. Rotate the Matrix 90 degrees counterclockwise
The program should initially accept a matrix of integers and display a menu for selecting an operation.... | def transpose(matrix):
"""Transposes the given matrix."""
rows, cols = len(matrix), len(matrix[0])
return [[matrix[j][i] for j in range(rows)] for i in range(cols)]
def rotate_90_clockwise(matrix):
"""Rotates the given matrix 90 degrees clockwise."""
return [list(reversed(col)) for col in zip(*matr... | from solution import transpose, rotate_90_clockwise, rotate_90_counterclockwise, apply_operation
def test_transpose():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
result = transpose(matrix)
expected = [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
assert re... | [
{
"docstring": "Transposes the given matrix.",
"function_declaration": "def transpose(matrix):",
"function_name": "transpose",
"parameter_list": "(matrix)"
},
{
"docstring": "Rotates the given matrix 90 degrees clockwise.",
"function_declaration": "def rotate_90_clockwise(matrix):",
... | [
0,
0,
1,
1,
0,
1,
0,
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": "def transpose_matrix(matrix):\n \"\"\"\n Transpose the given matrix.\n \n :param matrix: List[List[int]] - a 2D list representing the matrix\n :retu... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00003165",
"row_id": 3165,
"seed_ids": "[48414]"
} | 0.461522 | Evol_3165 | I | [
"transpose",
"rotate_90_clockwise",
"rotate_90_counterclockwise",
"apply_operation"
] | 4 | [
[
"apply_operation",
"rotate_90_clockwise"
],
[
"apply_operation",
"rotate_90_counterclockwise"
],
[
"apply_operation",
"transpose"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | df83853b4a31a96fdfc4c78a1e8128304f70edc8 | 6410f64da3a4a37e0e30ee88315e49da12fb2a17 | |||
v1.0 | instruct | Evol | Evol_3207_I | In a 2D grid of integers, each cell in the grid represents a building with a certain height. A peak is defined as a cell that is strictly greater than its four neighboring cells (north, east, south, and west). Write a function that takes a 2D list representing the heights of buildings in a grid and returns the coordina... | def findPeaks(grid):
rows = len(grid)
cols = len(grid[0])
peaks = []
for r in range(rows):
for c in range(cols):
if (r == 0 or grid[r][c] > grid[r-1][c]) and \
(r == rows-1 or grid[r][c] > grid[r+1][c]) and \
(c == 0 or grid[r][c] > grid[r][c-1]) and \
... | # Since the code above is self-contained, I will test directly with inlining the function definitions.
def test_findPeaks_single_peak():
grid = [
[1, 4, 3, 2],
[3, 5, 6, 4],
[2, 2, 1, 3]
]
assert findPeaks(grid) == ([(1, 2)], 6, 6)
def test_findPeaks_multiple_peaks():
grid = [
... | [
{
"docstring": null,
"function_declaration": "def findPeaks(grid):",
"function_name": "findPeaks",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def prod(lst):",
"function_name": "prod",
"parameter_list": "(lst)"
}
] | [
0,
0,
0,
0,
1,
1,
0,
0,
1,
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 findPeaks(grid):\n rows = len(grid)\n cols = len(grid[0])\n peaks = []\n \n for r in range(rows):\n for c in range(cols):\n is... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00003207",
"row_id": 3207,
"seed_ids": "[12393]"
} | 0.568305 | Evol_3207 | I | [
"findPeaks",
"prod"
] | 2 | [
[
"findPeaks",
"prod"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 77213909f863de90c72a03d9df888e19264c7804 | ad3ce8179456bef9c2d6fe0303ebaa8b29b6b93c | |||
v1.0 | instruct | Evol | Evol_3218_I | Write a Python function that accepts a list of integers and returns a dictionary. The keys of the dictionary should be the original integers, and the values should be True if the integer is a prime number and False otherwise.
def prime_status(numbers):
pass | def is_prime(n):
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 prime_status(numbers):
"""
Takes a list of integers and returns a dict... | from solution import prime_status
def test_prime_numbers():
assert prime_status([2, 3, 5, 7, 11]) == {2: True, 3: True, 5: True, 7: True, 11: True}
def test_non_prime_numbers():
assert prime_status([4, 6, 8, 9, 10]) == {4: False, 6: False, 8: False, 9: False, 10: False}
def test_mixed_numbers():
assert p... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a dictionary.\nKeys: original integers from the list.\nValues: True if the integer is prime, False otherwise.",
"f... | [
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_5 | {
"original_instruction": "",
"prompt_id": "00003218",
"row_id": 3218,
"seed_ids": "[27197]"
} | 0.722547 | Evol_3218 | I | [
"is_prime",
"prime_status"
] | 2 | [
[
"prime_status",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3f033aeb6c7cab3b6dfaf91466e275a0e4a6ece8 | b0532fc1b476f401f9ce4c212195299531456e09 | |||
v1.0 | instruct | Evol | Evol_3234_I | Given the following Python code, identify and correct any logical errors that exist. Once you have a logically correct version of the code, refactor it to improve its efficiency in terms of time complexity. Additionally, write a function to measure and compare the execution time of the original versus the refactored fu... | def find_max(arr):
if not arr:
return None
max_num = arr[0]
for num in arr:
if num > max_num:
max_num = num
return max_num
def find_max_refactored(arr):
if not arr:
return None
return max(arr)
import time
def compare_execution_time(arr):
start_time_orig... | from solution import find_max, find_max_refactored, compare_execution_time
def test_find_max():
assert find_max([1, 2, 3, 4, 5]) == 5
assert find_max([5, 4, 3, 2, 1]) == 5
assert find_max([-1, -2, -3, -4, -5]) == -1
assert find_max([]) == None
assert find_max([0]) == 0
def test_find_max_refactored... | [
{
"docstring": null,
"function_declaration": "def find_max(arr):",
"function_name": "find_max",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def find_max_refactored(arr):",
"function_name": "find_max_refactored",
"parameter_list": "(arr)"
},
{
... | [
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 find_max(arr):\n \"\"\"\n Returns the maximum value in the array arr.\n \"\"\"\n if not arr:\n raise ValueError(\"The input array cannot be ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003234",
"row_id": 3234,
"seed_ids": "[8031]"
} | 0.649055 | Evol_3234 | I | [
"find_max",
"find_max_refactored",
"compare_execution_time"
] | 3 | [
[
"compare_execution_time",
"find_max"
],
[
"compare_execution_time",
"find_max_refactored"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d550573ebb88f67d826528f5cf67da1c17a309ee | 97c04c1ab7fbd97c6b6e7fe58c6e90259c219abe | |||
v1.0 | instruct | Evol | Evol_3282_I | Write a program that reads a text file, counts the frequency of each word, and writes the results to a new file in descending order of frequency. Ignore case and punctuation, considering only words that contain alphabetic characters. | import re
from collections import Counter
def read_file(file_path):
"""
Reads the content of a file and returns it as a string.
"""
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
def write_file(file_path, content):
"""
Writes content to a file.
"""
with... | import os
from solution import generate_frequency_report, read_file, write_file, count_word_frequencies
# Helper functions to create and remove test files
def create_test_file(file_path, content):
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
def remove_test_file(file_path):
... | [
{
"docstring": "Reads the content of a file and returns it as a string.",
"function_declaration": "def read_file(file_path):",
"function_name": "read_file",
"parameter_list": "(file_path)"
},
{
"docstring": "Writes content to a file.",
"function_declaration": "def write_file(file_path, c... | [
1,
0,
0,
0,
0,
0,
0,
0,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import Counter\n\ndef count_word_frequency(input_file, output_file):\n \"\"\"\n Reads a text file, counts the frequency of each w... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00003282",
"row_id": 3282,
"seed_ids": "[29015]"
} | 0.660471 | Evol_3282 | I | [
"read_file",
"write_file",
"count_word_frequencies",
"generate_frequency_report"
] | 4 | [
[
"generate_frequency_report",
"count_word_frequencies"
],
[
"generate_frequency_report",
"read_file"
],
[
"generate_frequency_report",
"write_file"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a30e002749b2b2137f4cdb9c80c21eac1b843101 | 6bb1e3ce3c77818a3c58bfa0b2d9eb11f89ef6da | |||
v1.0 | instruct | Evol | Evol_3309_I | Write a function that takes an integer array as input and returns a new array containing only the prime numbers from the original array, in the same order they appeared. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. | def is_prime(n):
"""
Checks if the given 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_primes(arr):
... | 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(17) == True
assert is_prime(-3) == False
assert is_prime(1) == Fals... | [
{
"docstring": "Checks if the given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing only the prime numbers from the original array.",
"function_declaration": "def filte... | [
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(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n r... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00003309",
"row_id": 3309,
"seed_ids": "[35048]"
} | 0.644361 | Evol_3309 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a91074f6a29873fe88feef928fc8a709a89d90d9 | 3e2c4adc4b97877008ec0b5a9d7827d5891732ce | |||
v1.0 | instruct | Evol | Evol_3344_I | Write a function that takes a list of integers as input and returns another list consisting of the prime factors of each number in the input list. The result should present prime factors in ascending order, and each number should only appear once in the output list, even if it is a factor of multiple input numbers. | def prime_factors(n):
"""Returns the list of prime factors of the given number n."""
factors = set()
i = 2
while i * i <= n:
while (n % i) == 0:
factors.add(i)
n //= i
i += 1
if n > 1:
factors.add(n)
return list(factors)
def get_prime_factors_list... | from solution import get_prime_factors_list
def test_single_number():
assert get_prime_factors_list([28]) == [2, 7]
def test_multiple_numbers():
assert get_prime_factors_list([12, 15, 21]) == [2, 3, 5, 7]
def test_prime_numbers():
assert get_prime_factors_list([7, 13, 19]) == [7, 13, 19]
def test_with_1... | [
{
"docstring": "Returns the list of prime factors of the given number n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of unique prime factors from the input list of integers.",
"function_dec... | [
0,
1,
0,
1,
1,
0,
1,
1,
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 prime_factors(numbers):\n \"\"\"\n Returns a list of prime factors of given list of numbers.\n The result list will contain each prime factor only onc... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003344",
"row_id": 3344,
"seed_ids": "[19610]"
} | 0.75954 | Evol_3344 | I | [
"prime_factors",
"get_prime_factors_list"
] | 2 | [
[
"get_prime_factors_list",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be2b99f414943bf2f7fb202347c4e82cfd673d68 | 4c33a18ea72b48751b32fa7c42fc65acedfcabbc | |||
v1.0 | instruct | Evol | Evol_3350_I | Write a program that accepts a list of integers and returns the product of all prime numbers in the list. Your code should include a function to check for prime numbers and handle edge cases, such as an empty list or a list with no prime numbers. If no prime numbers are found, the program should return a message indica... | 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
for i in range(3, int(n**0.5) + 1, 2): # Check only odd numbers
if n % i == 0:
retur... | from solution import is_prime, product_of_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(9) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == Fa... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the product of all prime numbers in the list.\nIf there are no prime numbers or the list is empty,\nreturns a message indi... | [
1,
1,
1,
1,
1,
0,
0,
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 Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00003350",
"row_id": 3350,
"seed_ids": "[5966]"
} | 0.692833 | Evol_3350 | I | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2d0ad1202666275f7a4b6d32fbb95bfcbf52fb41 | 07398d307ee4f5865a0bab7814baccbc674f7109 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.