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
Code_Contests
Code_Contests_49264_I
A string is defined as a “good string” if all its characters are distinct and the alphabetical order of characters in the string does not change. Given a string `str`, your task is to determine if it can become a good string by removing exactly one character. If it's possible, return the modified good string, otherwise...
def good_string(s): n = len(s) # Early return if the string is already a good string if is_good_string(s): return s for i in range(n): modified_string = s[:i] + s[i+1:] if is_good_string(modified_string): return modified_string return "IMPOSSIBLE" ...
from solution import good_string def test_good_string_already_good(): assert good_string("abcd") == "abcd" def test_good_string_remove_one(): assert good_string("abacd") == "abcd" def test_good_string_impossible(): assert good_string("ddca") == "IMPOSSIBLE" def test_good_string_all_same(): assert go...
[ { "docstring": null, "function_declaration": "def good_string(s):", "function_name": "good_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def is_good_string(s):", "function_name": "is_good_string", "parameter_list": "(s)" } ]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def good_string(s):\n n = len(s)\n \n # Early return if the string is already a good string\n if is_good_string(s):\n return s\n \n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049264", "row_id": 49264, "seed_ids": "[10935]" }
0.788848
Code_Contests_49264
I
[ "good_string", "is_good_string" ]
2
[ [ "good_string", "is_good_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0b069c790a192a3097bde048d4f782dcb7086a3
ae2912acc0f9ee390aa89c5c10c9e40b12c7d616
v1.0
instruct
Code_Contests
Code_Contests_49279_I
Alice loves prime numbers and palindromes. She is especially fascinated by numbers that are both prime and palindrome. She refers to such numbers as **prime palindromes**. Your task is to find the smallest prime palindrome greater than or equal to a given number `X`. A **prime number** is a natural number greater than...
def is_prime(n): """Check if n is a prime number.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is...
from solution import is_prime, is_palindrome, smallest_prime_palindrome 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(31) == True assert is_prime(32) == False def test_is_palindrome(): asse...
[ { "docstring": "Check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "pa...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n retur...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049279", "row_id": 49279, "seed_ids": "[10901]" }
0.788441
Code_Contests_49279
I
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7a962edc110596936498117656f4e0b278d1f77a
ec47482e136f90a9e2bf00eeac97fe60c6c9ef81
v1.0
instruct
Code_Contests
Code_Contests_49301_I
A line of people need to be arranged based on their heights. The heights of all people standing in the line can be represented by an array of integers where each integer denotes the height of a person. Your task is to write a program to sort the given array of heights in ascending order using Merge Sort algorithm and ...
def merge_sort(arr): if len(arr) > 1: mid = len(arr) // 2 L = arr[:mid] R = arr[mid:] merge_sort(L) merge_sort(R) i = j = k = 0 while i < len(L) and j < len(R): if L[i] <= R[j]: arr[k] = L[i] i += 1 el...
from solution import sort_heights def test_sort_heights_case1(): heights = [170, 155, 160, 175, 165] result = sort_heights(heights) assert result["merge_sort"] == [155, 160, 165, 170, 175] assert result["merge_sort_stability"] == "Stable" assert result["quick_sort"] == [155, 160, 165, 170, 175] ...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef merge_sort(arr):\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half = arr[mid:]\n\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049301", "row_id": 49301, "seed_ids": "[6976]" }
0.595916
Code_Contests_49301
I
[ "merge_sort", "partition", "quick_sort", "sort_heights" ]
4
[ [ "quick_sort", "partition" ], [ "sort_heights", "merge_sort" ], [ "sort_heights", "quick_sort" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f40913178f6d775f77763b226770c2ec5094c6a6
177fed5589789673210982bfeffd3d9fd3c69692
v1.0
instruct
Code_Contests
Code_Contests_49383_I
You are given two matrices `A` and `B` of size `m x n`. Write a function to check if matrix `B` can be obtained by rotating matrix `A` 0, 90, 180, or 270 degrees in a clockwise direction. Constraints: * $1 \leq m, n \leq 10$ Input: The input is given as two matrices in the following format: ``` m n a_00 a_01 ... a_...
def rotate_90(mat): return [list(row) for row in zip(*mat[::-1])] def is_rotation(a, b): if a == b: return True rotated_90 = rotate_90(a) if rotated_90 == b: return True rotated_180 = rotate_90(rotated_90) if rotated_180 == b: return True rotated_270 = rotate_90(rota...
from solution import check_matrix_rotation, rotate_90 def test_rotate_90(): assert rotate_90([[1,2,3], [4,5,6], [7,8,9]]) == [[7,4,1], [8,5,2], [9,6,3]] def test_is_rotation_0(): assert check_matrix_rotation(3, 3, [[1,2,3], [4,5,6], [7,8,9]], [[1,2,3], [4,5,6], [7,8,9]]) == "Yes" def test_is_rotation_90(): ...
[ { "docstring": null, "function_declaration": "def rotate_90(mat):", "function_name": "rotate_90", "parameter_list": "(mat)" }, { "docstring": null, "function_declaration": "def is_rotation(a, b):", "function_name": "is_rotation", "parameter_list": "(a, b)" }, { "docstring...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_90(mat):\n return [list(row) for row in zip(*mat[::-1])]\n\ndef is_rotation(a, b):\n if a == b:\n return True\n rotated_90 = rot...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049383", "row_id": 49383, "seed_ids": "[10621]" }
0.573374
Code_Contests_49383
I
[ "rotate_90", "is_rotation", "check_matrix_rotation" ]
3
[ [ "check_matrix_rotation", "is_rotation" ], [ "is_rotation", "rotate_90" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ca9e26a021eab27f1b56d00e1828d6bcc4f45213
31a78e5108ac6213ec4a76b5404b50e2f5c7ce4d
v1.0
instruct
Code_Contests
Code_Contests_49412_I
Three young friends, Alex, Charlie, and Jordan, are interested in a game involving binary trees. They define a binary tree as a data structure in which each node can have at most two children referred to as the left child and the right child. As part of their game, they want to calculate the depth of a binary tree. Th...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(nodes_info): nodes = {} for value, left, right in nodes_info: if value not in nodes: nodes[value] = TreeNode(value) node = nodes[value] ...
def test_calculate_tree_depths(): test_cases = [ ([ (1, 2, 3), (2, -1, -1), (3, -1, -1) ], 1), ([ (1, 2, 3), (2, -1, -1), (3, 4, 5), (4, -1, -1), (5, -1, -1) ], 2) ] for nodes...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes_in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049412", "row_id": 49412, "seed_ids": "[9502]" }
0.631734
Code_Contests_49412
I
[ "build_tree", "max_depth", "calculate_tree_depths", "main" ]
4
[ [ "calculate_tree_depths", "build_tree" ], [ "calculate_tree_depths", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
2866d594604719c87c39b5232e2b7fbe1b04b249
de24a58cf929d37f291b352c5499c4080c26a920
v1.0
instruct
Code_Contests
Code_Contests_49425_I
You are given a binary tree. For each node of the tree, find and note down the sum of values of all nodes forming the subtree rooted at that node. For example, consider the binary tree below: ``` 1 / \ 2 3 / \ 4 5 ``` The sums of the subtrees for each node are: - Node 1: 1 + 2 + 3 + 4 + 5 = 15 - Node 2...
def subtree_sums(n, edges): from collections import defaultdict tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) subtree_sum = [0] * (n + 1) visited = [False] * (n + 1) def dfs(node): visited[node] = True total_sum = node ...
def test_case_1(): assert process_input_and_solve(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == [15, 11, 3, 4, 5] def test_case_2(): assert process_input_and_solve(3, [(1, 2), (1, 3)]) == [6, 2, 3] def test_case_3(): assert process_input_and_solve(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == [28, 11,...
[ { "docstring": null, "function_declaration": "def subtree_sums(n, edges):", "function_name": "subtree_sums", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def process_input_and_solve(n, edges):", "function_name": "process_input_and_solve", "param...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def subtree_sum(n, edges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:\n graph[u].a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049425", "row_id": 49425, "seed_ids": "[9283]" }
0.679495
Code_Contests_49425
I
[ "subtree_sums", "process_input_and_solve" ]
2
[ [ "process_input_and_solve", "subtree_sums" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2fc4a359092ae932434c643f82423e0409cafbed
24672a87fbee0ce39374771ba072f5bc8f7c1428
v1.0
instruct
Code_Contests
Code_Contests_49437_I
You have a row of houses arranged in a straight line, each house having a certain amount of money stashed. However, you cannot rob two adjacent houses due to the security system in place that will automatically alert the police if two adjacent houses were broken into on the same night. Write a function to determine th...
def rob(houses): """ Returns the maximum amount of money you can rob without alerting the police. """ prev1 = prev2 = 0 for money in houses: temp = prev1 prev1 = max(prev2 + money, prev1) prev2 = temp return prev1 def max_robbery(test_cases): results = [] for cas...
from solution import rob, parse_input, max_robbery, solve def test_rob(): assert rob([1, 2, 3, 1]) == 4 assert rob([2, 7, 9, 3, 1]) == 12 assert rob([0]) == 0 assert rob([1,2]) == 2 assert rob([5,5,10,100,10,5]) == 110 def test_parse_input(): input_data = "2\n4\n1 2 3 1\n5\n2 7 9 3 1" test...
[ { "docstring": "Returns the maximum amount of money you can rob without alerting the police.", "function_declaration": "def rob(houses):", "function_name": "rob", "parameter_list": "(houses)" }, { "docstring": null, "function_declaration": "def max_robbery(test_cases):", "function_na...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rob(houses):\n \"\"\"\n Determines the maximum amount of money that can be robbed from a row of houses \n without alerting the police, i.e., w...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049437", "row_id": 49437, "seed_ids": "[12772]" }
0.707867
Code_Contests_49437
I
[ "rob", "max_robbery", "parse_input", "solve" ]
4
[ [ "max_robbery", "rob" ], [ "solve", "max_robbery" ], [ "solve", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
292c120bc53e2f8a9ce564e99ab895e5ac418abd
98d7a8f1087480211f7e5f33c22f21700dae8804
v1.0
instruct
Code_Contests
Code_Contests_49440_I
A company wants to implement a system to manage and process shifts for their employees. Each shift is represented by a string `shift` composed of alphabetic characters where each character can be 'O' (On-duty) or 'F' (Off-duty). The company needs to answer multiple queries about possible shifts. Each query contains th...
def can_generate_day_shift(current_shift, required_shift, day_shift): """ Checks if the day_shift can be generated from cyclic permutation of current_shift and a substitution of a subsequence with required_shift. """ n = len(current_shift) double_current_shift = current_shift * 2 for i ...
from solution import can_generate_day_shift, process_shift_queries def test_can_generate_day_shift(): assert can_generate_day_shift("OFOF", "OFOF", "OFOF") == "Yes" assert can_generate_day_shift("FOOOFF", "OOFOFO", "FOFOFO") == "No" assert can_generate_day_shift("OFFFOO", "FFOOOF", "OFFFOO") == "No" def t...
[ { "docstring": "Checks if the day_shift can be generated from cyclic permutation of\ncurrent_shift and a substitution of a subsequence with required_shift.", "function_declaration": "def can_generate_day_shift(current_shift, required_shift, day_shift):", "function_name": "can_generate_day_shift", "p...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def canGenerateShift(current_shift, required_shift, day_shift):\n \"\"\"\n Determines if `day_shift` can be generated by cyclic permutations of `curr...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00049440", "row_id": 49440, "seed_ids": "[5385]" }
0.668776
Code_Contests_49440
I
[ "can_generate_day_shift", "is_subsequence_replaceable", "process_shift_queries" ]
3
[ [ "can_generate_day_shift", "is_subsequence_replaceable" ], [ "process_shift_queries", "can_generate_day_shift" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fbccb7ef9ea496fe1f69de5a02d1d2bbb247fb21
78e5cf0c9705294fda2edb8d44a8abab4a4f8cc2
v1.0
instruct
Code_Contests
Code_Contests_49470_I
As an engineer, you are tasked with the design and analysis of a waste treatment plant for a small town. The plant consists of various treatment stations connected by pipes. Each station has a capacity limit, and the pipes indicate the possible flow of waste between these stations. The goal is to determine the maximum ...
from collections import deque, defaultdict def bfs_capacity(graph, start, end, parent): visited = [False] * len(graph) queue = deque([start]) visited[start] = True while queue: u = queue.popleft() for ind, val in enumerate(graph[u]): if not visited[ind] and val > 0: ...
import pytest from solution import max_waste_flow def test_example_case(): N = 4 E = 5 edges = [ (0, 1, 100), (0, 2, 100), (1, 2, 1), (1, 3, 100), (2, 3, 100) ] assert max_waste_flow(N, E, edges) == 200 def test_disjoint_paths(): N = 4 E = 4 edge...
[ { "docstring": null, "function_declaration": "def bfs_capacity(graph, start, end, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, start, end, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(graph, start, end):", "function_name": "edmo...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = [False] * len(graph)\n queue = deque([source])\n visit...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049470", "row_id": 49470, "seed_ids": "[13320]" }
0.636361
Code_Contests_49470
I
[ "bfs_capacity", "edmonds_karp", "max_waste_flow" ]
3
[ [ "edmonds_karp", "bfs_capacity" ], [ "max_waste_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
232a798c8d977e7cc04cd12e7c7ee05732776d67
94203e80f5b81b4041767100a2a601e65ed64f4c
v1.0
instruct
Code_Contests
Code_Contests_49472_I
A triplet in an array is defined as a sequence of three elements (a[i], a[j], a[k]) such that a[i] < a[j] < a[k] and i < j < k. Given an array of distinct integers, your task is to determine the number of such triplets in the array. INPUT The first line contains a single integer n, the number of elements in the array....
def count_triplets(arr): n = len(arr) if n < 3: return 0 count = 0 for i in range(n): for j in range(i+1, n): for k in range(j+1, n): if arr[i] < arr[j] < arr[k]: count += 1 return count def count_triplets_from_input(n, ...
from solution import count_triplets_from_input def test_sample_input(): assert count_triplets_from_input(7, "4 7 1 9 3 10 5") == 7 def test_no_triplets(): assert count_triplets_from_input(4, "4 3 2 1") == 0 def test_single_triplet(): assert count_triplets_from_input(3, "1 2 3") == 1 def test_multiple_tr...
[ { "docstring": null, "function_declaration": "def count_triplets(arr):", "function_name": "count_triplets", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def count_triplets_from_input(n, elements):", "function_name": "count_triplets_from_input", "para...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_triplets(n, arr):\n \"\"\"\n Count the number of triplets (a[i], a[j], a[k]) such that a[i] < a[j] < a[k] \n and i < j < k in the array ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00049472", "row_id": 49472, "seed_ids": "[5492]" }
0.756715
Code_Contests_49472
I
[ "count_triplets", "count_triplets_from_input" ]
2
[ [ "count_triplets_from_input", "count_triplets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8354deb2e59fec1acda98c7fcea7b1d04d3b93ba
466521b6a36c0d86c0d4d79cc8a70ff6757cfa03
v1.0
instruct
Code_Contests
Code_Contests_49474_I
You are given a list of n integers and a list of m queries. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n). For each query, calculate the sum of the integers from the l-th to the r-th position in the list (inclusive). Input The first line contains an integer n (1 ≤ n ≤ 10^5), the number of integers in th...
def prefix_sums(arr): """ Returns a list of prefix sums for the given array. """ prefix = [0] * (len(arr) + 1) for i in range(1, len(arr) + 1): prefix[i] = prefix[i - 1] + arr[i - 1] return prefix def range_sum(arr, queries): """ For each query (l, r) calculate the sum of the el...
def test_prefix_sums(): assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] assert prefix_sums([-1, -2, 3, 4, 5]) == [0, -1, -3, 0, 4, 9] assert prefix_sums([0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0] assert prefix_sums([1]) == [0, 1] def test_range_sum(): arr = [1, 2, 3, 4, 5] queries = [(1...
[ { "docstring": "Returns a list of prefix sums for the given array.", "function_declaration": "def prefix_sums(arr):", "function_name": "prefix_sums", "parameter_list": "(arr)" }, { "docstring": "For each query (l, r) calculate the sum of the elements \nfrom the l-th to the r-th position in t...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "def prefix_sums(arr):\n \"\"\"\n Compute prefix sums array for the given list of integers.\n \n Args:\n arr (list):...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049474", "row_id": 49474, "seed_ids": "[3365]" }
0.691379
Code_Contests_49474
I
[ "prefix_sums", "range_sum" ]
2
[ [ "range_sum", "prefix_sums" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8c43fa74a0b803d498c176f6f36b2313a1f9ba18
4b8e4b3853c7dc73982320da003b4ae82d4af60d
v1.0
instruct
Code_Contests
Code_Contests_49487_I
A robotics company is testing a new pathfinding algorithm for their autonomous robots. The robots move in a grid with M rows and N columns. Each cell in the grid can be empty or contain an obstacle. The robot can only move to an adjacent cell (vertically or horizontally) if that cell is empty. Given the starting positi...
from collections import deque def shortest_path(grid, M, N, sx, sy, ex, ey): if not (0 <= sx < M and 0 <= sy < N and 0 <= ex < M and 0 <= ey < N): return -1 if grid[sx][sy] == 1 or grid[ex][ey] == 1: return -1 visited = [[False for _ in range(N)] for __ in range(M)] directions = [(...
def test_shortest_path(): input_str = """ 1 5 5 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 4 4 """ expected_output = "8" assert robot_pathfinding(input_str).strip() == expected_output def test_shortest_path_no_path(): input_str = """ 1 3 3 ...
[ { "docstring": null, "function_declaration": "def shortest_path(grid, M, N, sx, sy, ex, ey):", "function_name": "shortest_path", "parameter_list": "(grid, M, N, sx, sy, ex, ey)" }, { "docstring": null, "function_declaration": "def solve_pathfinding_problem(T, test_cases):", "function...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_path(grid, M, N, sx, sy, ex, ey):\n if not (0 <= sx < M and 0 <= sy < N and 0 <= ex < M and 0 <= ey < N):\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049487", "row_id": 49487, "seed_ids": "[524]" }
0.694122
Code_Contests_49487
I
[ "shortest_path", "solve_pathfinding_problem", "robot_pathfinding" ]
3
[ [ "robot_pathfinding", "solve_pathfinding_problem" ], [ "solve_pathfinding_problem", "shortest_path" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ac0b227784423e35f281da77ff05cf61b38bdf69
1e45fc8fcd330e59dafa3fac5ed8b591db0dd84f
v1.0
instruct
Code_Contests
Code_Contests_49488_I
Tom and Jerry are playing a game on a 2D grid of size M x N. Initially, Tom starts at the top left corner of the grid (0, 0) and Jerry starts at the bottom right corner (M-1, N-1). The game progresses in turns, with each player moving alternately. In each turn, Tom can move one step either to the right (i.e., from (i, ...
from collections import deque def can_tom_win(grid, M, N): directions_tom = [(0, 1), (1, 0)] # right, down for Tom directions_jerry = [(0, -1), (-1, 0)] # left, up for Jerry start_tom = (0, 0) start_jerry = (M-1, N-1) # BFS to find shortest path distance for Tom and Jerry from their starts d...
def test_case_1(): grid = [ "...", ".#.", ".#." ] assert determine_winner(3, 3, grid) == "Tom wins" def test_case_2(): grid = [ "..#", ".#.", ".#." ] assert determine_winner(3, 3, grid) == "Jerry wins" def test_case_3(): grid = [ "......
[ { "docstring": null, "function_declaration": "def can_tom_win(grid, M, N):", "function_name": "can_tom_win", "parameter_list": "(grid, M, N)" }, { "docstring": null, "function_declaration": "def determine_winner(M, N, grid):", "function_name": "determine_winner", "parameter_list"...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef can_tom_win(grid, M, N):\n directions_tom = [(0, 1), (1, 0)] # right, down for Tom\n d...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049488", "row_id": 49488, "seed_ids": "[3323]" }
0.749583
Code_Contests_49488
I
[ "can_tom_win", "determine_winner" ]
2
[ [ "determine_winner", "can_tom_win" ] ]
1
[]
false
[]
false
pytest
false
[]
true
85613ea2cc3336581996dd74ece3fc1b40eb33c6
b5787e212bfbce60ed069c92d7e9c90d20f25a6a
v1.0
instruct
Code_Contests
Code_Contests_49580_I
You are given a binary tree with n nodes. Each node is assigned a value, which is initially set to 0 or 1. You are allowed to perform certain operations to convert the tree into a uniform binary tree where all nodes have the same value. In one operation, you can select any subtree of the binary tree and flip the value...
def find_min_operations(n, node_values, edges): from collections import defaultdict graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) def dfs(node, parent): count_0 = 0 if node_values[node - 1] else 1 count_1 = 1 if node_values[node - 1]...
def test_single_node(): assert min_operations(1, [0], []) == 0 assert min_operations(1, [1], []) == 0 def test_all_same(): assert min_operations(3, [0, 0, 0], [(1, 2), (1, 3)]) == 0 assert min_operations(3, [1, 1, 1], [(1, 2), (1, 3)]) == 0 def test_simple_case(): assert min_operations(3, [1, 0, 0...
[ { "docstring": null, "function_declaration": "def find_min_operations(n, node_values, edges):", "function_name": "find_min_operations", "parameter_list": "(n, node_values, edges)" }, { "docstring": null, "function_declaration": "def min_operations(n, node_values, edges):", "function_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_operations_to_uniform_tree(n, values, edges):\n from collections import defaultdict\n\n # Build adjacency list for the tree\n tree = defau...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049580", "row_id": 49580, "seed_ids": "[13172]" }
0.655992
Code_Contests_49580
I
[ "find_min_operations", "min_operations" ]
2
[ [ "min_operations", "find_min_operations" ] ]
1
[]
false
[]
false
pytest
false
[]
true
55243721c4ececb2393a0f55bed5c03bad87e727
367649ce99e67592c4d6946700afdfc16798f808
v1.0
instruct
Code_Contests
Code_Contests_49598_I
Given an undirected connected graph with `n` vertices and `m` edges, where each edge has a positive weight. Determine the sum of weights in the minimum spanning tree of the graph. Input The first line contains integers `n` and `m` (`1 ≤ n ≤ 1000`, `0 ≤ m ≤ 10000`). The following `m` lines contain three integers `u`, ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[roo...
from solution import minimum_spanning_tree def test_example_case(): n = 4 m = 5 edges = [ (1, 2, 5), (1, 3, 3), (4, 2, 7), (3, 4, 4), (2, 3, 6) ] assert minimum_spanning_tree(n, m, edges) == 12 def test_single_edge(): n = 2 m = 1 edges = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_spanning_tree(n, m, edges):\n \"\"\"\n Returns the sum of weights in the minimum spanning tree of the graph.\n Uses Kr...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00049598", "row_id": 49598, "seed_ids": "[4738]" }
0.788552
Code_Contests_49598
I
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
69da4190d973ee91bddbe07416cac5f3b075d36a
8ef16178d4d647dd38bf2aedddc1bb4d21dddaec
v1.0
instruct
Code_Contests
Code_Contests_49624_I
Tara loves playing with numbers, and she is particularly fond of prime numbers. She is generating a sequence of prime numbers and wants to know the k-th prime number in the generated sequence. Because prime numbers are a fundamental concept and useful in various fields, she decides to write a program for this task. Wr...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def kth_prime(k): count = 0 num = 1 ...
from solution import kth_prime def test_kth_prime_first_prime(): assert kth_prime(1) == 2 def test_kth_prime_small_primes(): assert kth_prime(2) == 3 assert kth_prime(3) == 5 assert kth_prime(4) == 7 assert kth_prime(5) == 11 def test_kth_prime_larger_prime(): assert kth_prime(10) == 29 def ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def kth_prime(k):", "function_name": "kth_prime", "parameter_list": "(k)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049624", "row_id": 49624, "seed_ids": "[4051]" }
0.653552
Code_Contests_49624
I
[ "is_prime", "kth_prime" ]
2
[ [ "kth_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a30c29046bf936fef31b206bd8f152522df2954f
10ddc8e9e3109b4fba1c67f1614637b3e08075a0
v1.0
instruct
Code_Contests
Code_Contests_49633_I
You are given a string of lowercase Latin letters. You are allowed to remove at most one character from this string. Your task is to determine if it is possible to obtain a palindrome by removing exactly one character or not removing any character at all. Input The first line of input contains an integer T denoting th...
def is_palindrome(s): return s == s[::-1] def can_form_palindrome(s): if is_palindrome(s): return True left, right = 0, len(s) - 1 while left < right: if s[left] != s[right]: # Try removing either left or right character without_left = s[left+1:right+1] ...
from solution import palindrome_check, is_palindrome, can_form_palindrome def test_is_palindrome(): assert is_palindrome("abba") == True assert is_palindrome("abcba") == True assert is_palindrome("abca") == False assert is_palindrome("a") == True assert is_palindrome("") == True def test_can_form_...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef can_form_palindrome_by_removal(s):\n if is_palindrome(s):\n return \"YES\"\n\n left, rig...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049633", "row_id": 49633, "seed_ids": "[9690]" }
0.884581
Code_Contests_49633
I
[ "is_palindrome", "can_form_palindrome", "palindrome_check" ]
3
[ [ "can_form_palindrome", "is_palindrome" ], [ "palindrome_check", "can_form_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
84eae7cc1962ce59217f867eb5faca1e635a6ed2
604b9392aa243bfbf48b107e660c92b1f3500ed6
v1.0
instruct
Code_Contests
Code_Contests_49635_I
Tommy is a passionate gardener. He has a rectangular garden of size \(n \times m\) (n rows and m columns). Each cell in the garden either contains soil that can be cultivated, represented by 1, or a pond that cannot be used for planting, represented by 0. Tommy wants to fence off the largest possible rectangular sub-g...
def maximalRectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) heights = [0] * m max_area = 0 for row in matrix: for i in range(m): if row[i] == 0: heights[i] = 0 else: heights[i] += ...
def test_maximalRectangle_small(): assert maximalRectangle([[1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 1, 0, 1, 1]]) == 6 def test_maximalRectangle_single(): assert maximalRectangle([[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == 1 def test_maximalRectangle_empty(): assert maximalRectangle([]) == 0 def...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n \n max_area = 0\n heights = [...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049635", "row_id": 49635, "seed_ids": "[4626]" }
0.628909
Code_Contests_49635
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a235b37e198d94cb5c0f55325aec8a30f14857eb
5ec16d72647cd672e9d58b9aa5ce8489c23e562b
v1.0
instruct
Code_Contests
Code_Contests_49721_I
You are given a matrix of size M x N where each cell represents the cost to build a wall on that cell. You need to find the minimum cost of building a continuous vertical wall from the top row to the bottom row. You are allowed to start from any cell in the top row and can move to the cell directly below or to the cell...
def min_cost_to_build_wall(cost): if not cost or not cost[0]: return 0 M, N = len(cost), len(cost[0]) dp = [[0]*N for _ in range(M)] # Initialize the first row of dp array to the cost of the top row for j in range(N): dp[0][j] = cost[0][j] # Build the dp array ...
from solution import min_cost_wall def test_example_1(): cost_matrix = [ [1, 3, 1, 5], [2, 2, 4, 1], [5, 1, 2, 3] ] assert min_cost_wall(3, 4, cost_matrix) == 4 def test_example_2(): cost_matrix = [ [10, 2, 1], [1, 2, 10] ] assert min_cost_wall(2, 3, cos...
[ { "docstring": null, "function_declaration": "def min_cost_to_build_wall(cost):", "function_name": "min_cost_to_build_wall", "parameter_list": "(cost)" }, { "docstring": null, "function_declaration": "def min_cost_wall(M, N, cost_matrix):", "function_name": "min_cost_wall", "para...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_cost_to_build_wall(cost):\n if not cost or not cost[0]:\n return 0\n \n M, N = len(cost), len(cost[0])\n dp = [[0]*N for _ in ra...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049721", "row_id": 49721, "seed_ids": "[1649]" }
0.625707
Code_Contests_49721
I
[ "min_cost_to_build_wall", "min_cost_wall" ]
2
[ [ "min_cost_wall", "min_cost_to_build_wall" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5285d465f2e167275b52343aaf4d8ef4d4c10f4f
751b4bd1523af843dc454916a257592d1b502a7d
v1.0
instruct
Code_Contests
Code_Contests_49724_I
Alex is a city planner responsible for designing a new park with a network of connected walking paths. The park can be represented as a undirected graph where vertices represent park landmarks, and edges represent walking paths between those landmarks. Due to certain construction constraints, some pairs of landmarks mu...
def find_connected_components(n, edges): """ Find the number of connected components in an undirected graph. """ from collections import defaultdict, deque def bfs(start): queue = deque([start]) visited[start] = True while queue: node = queue.popleft() ...
from solution import min_new_paths_to_add, park_paths def test_example_case_1(): assert park_paths(5, 3, ["1 2", "2 3", "4 5"]) == 1 def test_example_case_2(): assert park_paths(4, 1, ["1 2"]) == 2 def test_example_case_3(): assert park_paths(4, 4, ["1 2", "2 3", "3 4", "4 1"]) == 0 def test_single_land...
[ { "docstring": "Find the number of connected components in an undirected graph.", "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": "Returns the minimum number of new paths that n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_connected_components(n, edges):\n \"\"\"\n Find the number of connected components in an undirected graph.\n \"\"\"\n from collections...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049724", "row_id": 49724, "seed_ids": "[8366]" }
0.720765
Code_Contests_49724
I
[ "find_connected_components", "min_new_paths_to_add", "park_paths" ]
3
[ [ "min_new_paths_to_add", "find_connected_components" ], [ "park_paths", "min_new_paths_to_add" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f8697161cbc70fd6650a3a91cf21f61a5ed8db2d
b714df862a460cc8b785db58ac4cb48101142ae7
v1.0
instruct
Code_Contests
Code_Contests_49734_I
You're given an undirected and connected graph with n vertices and m edges. Each edge has a weight associated with it. Your task is to determine if there exists an edge in the graph that, when removed, will separate the graph into exactly two connected components. If such an edge exists, also find the edge whose remova...
def find_max_difference_brige(n, m, edges): from collections import defaultdict import sys sys.setrecursionlimit(10**6) def dfs(u, visited, disc, low, parent): nonlocal time, bridge, max_edge visited[u] = True disc[u] = low[u] = time time += 1 for v, w in gr...
from solution import find_max_difference_brige def test_example1(): n = 4 m = 3 edges = [(1, 2, 10), (2, 3, 5), (3, 4, 6)] assert find_max_difference_brige(n, m, edges) == 10 def test_example2(): n = 5 m = 4 edges = [(1, 2, 1), (2, 3, 2), (2, 4, 3), (4, 5, 4)] assert find_max_differenc...
[ { "docstring": null, "function_declaration": "def find_max_difference_brige(n, m, edges):", "function_name": "find_max_difference_brige", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def example():", "function_name": "example", "parameter_lis...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_critical_edge(n, m, edges):\n from collections import defaultdict\n import copy\n\n # Step 1: Build the adjacency list of the graph\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049734", "row_id": 49734, "seed_ids": "[1679]" }
0.700025
Code_Contests_49734
I
[ "find_max_difference_brige", "example" ]
2
[ [ "example", "find_max_difference_brige" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed477ac8ad57ed04e819dd260d289e81244e943f
f64b419da52031e33c81a7ace06a2b0dd877e0c3
v1.0
instruct
Code_Contests
Code_Contests_49743_I
You are given an array of n integers. Find the length of the longest subsequence that consists of prime numbers only. A subsequence is obtained by deleting zero or more elements from the array without changing the order of the remaining elements. A prime number is a number greater than 1 that has no positive divisors ...
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 sq = int(num**0.5) + 1 for i in range(3, sq, 2): if num % i == 0: return False return...
from solution import is_prime, longest_prime_subsequence_length def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(7) == True assert is_prime(9) == False assert is_prime(11) == True assert is_prime(1) == False assert is...
[ { "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 length of the longest subsequence that consists of prime numbers only.", "function_declarat...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determines if a number is prime.\n A prime number is a number greater than 1 that has no positive divisors \n oth...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00049743", "row_id": 49743, "seed_ids": "[13288]" }
0.746164
Code_Contests_49743
I
[ "is_prime", "longest_prime_subsequence_length" ]
2
[ [ "longest_prime_subsequence_length", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1738fca3907a2ae14e2d04d7d38fc947d4054eb
b6341feb1f2ade9d4c4d66145c3bad5b11935f19
v1.0
instruct
Code_Contests
Code_Contests_49752_I
You are given a positive integer `n`. Your task is to generate an n-th row of Pascal's triangle. Pascal's triangle is a triangular array of the binomial coefficients. The elements of the n-th row of Pascal's triangle are given by where `C(n, k) = n! / (k! * (n - k)!)`, `0 <= k <= n`, and `!` denotes factorial. For e...
def factorial(num): if num == 0 or num == 1: return 1 fact = 1 for i in range(2, num + 1): fact *= i return fact def pascal_row(n): row = [] for k in range(n + 1): row.append(factorial(n) // (factorial(k) * factorial(n - k))) return row
from solution import pascal_row def test_pascal_row_zero(): assert pascal_row(0) == [1] def test_pascal_row_one(): assert pascal_row(1) == [1, 1] def test_pascal_row_two(): assert pascal_row(2) == [1, 2, 1] def test_pascal_row_three(): assert pascal_row(3) == [1, 3, 3, 1] def test_pascal_row_four()...
[ { "docstring": null, "function_declaration": "def factorial(num):", "function_name": "factorial", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def pascal_row(n):", "function_name": "pascal_row", "parameter_list": "(n)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(num):\n if num == 0 or num == 1:\n return 1\n fact = 1\n for i in range(2, num + 1):\n fact *= i\n return fact\n\nd...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049752", "row_id": 49752, "seed_ids": "[11750]" }
0.524797
Code_Contests_49752
I
[ "factorial", "pascal_row" ]
2
[ [ "pascal_row", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f01df95612875feb4e04b3def99c3336643fc15
0c6d02d1040070ccb46c21dde25c0b09ab1c1411
v1.0
instruct
Code_Contests
Code_Contests_49785_I
In an enchanting forest, there are n mystical islands interconnected by exactly n-1 magical bridges. Each bridge links a pair of islands and it is possible to travel between any two islands using one or more bridges. The Great Wizard of the forest has a flying broomstick that can help him quickly travel between islands...
from collections import deque, defaultdict def bfs_distance(n, start, edges): # Using BFS to calculate distances from the start island queue = deque([start]) distances = [-1] * (n + 1) distances[start] = 0 while queue: current = queue.popleft() for neighbor in edges[cu...
from solution import count_valid_start_islands def test_example_1(): n = 7 d = 3 k = 2 known_islands = [3, 4, 5] bridges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)] assert count_valid_start_islands(n, d, k, known_islands, bridges) == 3 def test_example_2(): n = 5 d = 2 k = 1...
[ { "docstring": null, "function_declaration": "def bfs_distance(n, start, edges):", "function_name": "bfs_distance", "parameter_list": "(n, start, edges)" }, { "docstring": null, "function_declaration": "def count_valid_start_islands(n, d, k, known_islands, bridges):", "function_name"...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_islands(n, d, k, q, bridges):\n from collections import defaultdict, deque\n \n def bfs(start, adjacency_list):\n # BFS to get dis...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00049785", "row_id": 49785, "seed_ids": "[3269]" }
0.664169
Code_Contests_49785
I
[ "bfs_distance", "count_valid_start_islands" ]
2
[ [ "count_valid_start_islands", "bfs_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c49710131893ca2ff81e4cbea0551f043b9a8eab
66afc62489878d76f9d11e15245d21bc0b7de983
v1.0
instruct
Code_Contests
Code_Contests_49792_I
You are given `N` points on a 2D coordinate plane. Each point can be represented as (x, y). Your task is to determine how many unique squares can be formed using these points as the vertices. Note: A square is defined as a quadrilateral with all four sides of equal length and all internal angles of 90 degrees. INPUT:...
from collections import defaultdict def count_unique_squares(points): points_set = set((x, y) for x, y in points) n = len(points) lookup = defaultdict(int) for i in range(n): for j in range(i + 1, n): (x1, y1) = points[i] (x2, y2) = points[j] if (x1 != x...
from solution import unique_squares, parse_input def test_case_1(): input_data = "1\n4\n0 0\n0 1\n1 0\n1 1\n" test_cases = parse_input(input_data) assert unique_squares(test_cases) == [1] def test_case_2(): input_data = "1\n5\n0 0\n0 1\n1 0\n1 1\n2 2\n" test_cases = parse_input(input_data) ass...
[ { "docstring": null, "function_declaration": "def count_unique_squares(points):", "function_name": "count_unique_squares", "parameter_list": "(points)" }, { "docstring": null, "function_declaration": "def unique_squares(test_cases):", "function_name": "unique_squares", "parameter...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_squares(points):\n \"\"\"\n Function to count unique squares that can be formed with the given points.\n points: List of tuples (...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00049792", "row_id": 49792, "seed_ids": "[13291]" }
0.665984
Code_Contests_49792
I
[ "count_unique_squares", "unique_squares", "parse_input" ]
3
[ [ "unique_squares", "count_unique_squares" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
40ebacd22e2b48a35c92f0067fcdfacafe484689
f641b90fc515b8b69d9c71aee04f5af837f6d8b7
v1.0
instruct
Code_Contests
Code_Contests_49799_I
You are tasked with evaluating the sum of the series of prime numbers up to a provided integer n. Input An integer t, 1 ≤ t ≤ 100, denoting the number of test cases, followed by t lines, each containing a single integer n, 1 ≤ n ≤ 10^3. Output For each integer n given in the input, display a line with the sum of al...
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_divisor = int(num ** 0.5) + 1 for divisor in range(3, max_divisor, 2): if num % divisor == 0: return False return True def sum_of_primes_up_to_n(n)...
from solution import is_prime, sum_of_primes_up_to_n, process_input def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False def test_sum_of_primes_up_to_n(): assert sum_of_primes_up_to_n(10)...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_primes_up_to_n(n):", "function_name": "sum_of_primes_up_to_n", "parameter_list": "(n)" }, { ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_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 max_divi...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00049799", "row_id": 49799, "seed_ids": "[13226]" }
0.623529
Code_Contests_49799
I
[ "is_prime", "sum_of_primes_up_to_n", "process_input" ]
3
[ [ "process_input", "sum_of_primes_up_to_n" ], [ "sum_of_primes_up_to_n", "is_prime" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
1679b1882fcac1ef361cd278e19da175414e171b
d3ac8b0ccbb0f592b6064d195218ea92f65bac55
v1.0
instruct
Code_Contests
Code_Contests_49952_I
Super Vizorix the Wizard is known for his complex and difficult mazes. He has a collection of T mazes, each of which is represented as a grid with R rows and C columns. Each cell in the grid can either be empty (.) or blocked (X). Super Vizorix wants to know the number of distinct paths from the top-left corner to the ...
def count_paths(mazes): """ Returns a list with the number of distinct paths from the top-left to the bottom-right corner for each maze. """ results = [] for maze in mazes: R, C, grid = maze if grid[0][0] == 'X' or grid[R-1][C-1] == 'X': results.append(0) co...
def test_count_paths(): assert count_paths([(3, 3, [['.', '.', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) == [2] assert count_paths([(3, 3, [['X', 'X', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) == [0] assert count_paths([(1, 1, [['.']])]) == [1] assert count_paths([(2, 2, [['.', 'X'], ['X', '.']])]) ==...
[ { "docstring": "Returns a list with the number of distinct paths from the top-left to the bottom-right corner for each maze. ", "function_declaration": "def count_paths(mazes):", "function_name": "count_paths", "parameter_list": "(mazes)" }, { "docstring": "Parses the input data and returns ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_paths_in_maze(maze, R, C):\n # Create a 2D dp array initialized with 0\n dp = [[0] * C for _ in range(R)]\n \n # Initialize the start...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00049952", "row_id": 49952, "seed_ids": "[2365]" }
0.710437
Code_Contests_49952
I
[ "count_paths", "parse_input", "solve" ]
3
[ [ "solve", "count_paths" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
03916589cfc2f41ec9d81e9a2415f6fab16722ec
09e7aa8a071d709886633e24a03bc4261ca51908
v1.0
instruct
Evol
Evol_10_I
You are given a list of integers and you need to find and return the sum of all the prime numbers contained in the list. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. Write a function that accomplishes this task. input_array = [10, 15, 3, 7, 19, 21, 29] ###...
from typing import List def is_prime(n: int) -> bool: """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_primes(input_array: List[int]) -> int...
from solution import sum_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_sum_of_primes(): ...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the input_array.", "function_declaration": "def sum_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": "from typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000010", "row_id": 10, "seed_ids": "[32446]" }
0.694876
Evol_10
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38519f5f20f57718fc1d3b1a3d04dd8950ae7dc0
dc37f01d5608cae4b295f028a71f9dacf19bafd5
v1.0
instruct
Evol
Evol_14_I
Develop a Python function that takes a list of integers and returns a dictionary. The dictionary keys should be the integers from the list that are prime numbers, and the value for each key should be the sum of the digits of that prime number. Ensure your function is optimized for efficiency with larger lists.
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 sum_of_digits(n): return sum(int(digit) for digit in str(n)) def prime_digi...
from solution import prime_digit_sum def test_prime_digit_sum_with_primes(): assert prime_digit_sum([2, 3, 5, 7, 11, 13, 17]) == {2: 2, 3: 3, 5: 5, 7: 7, 11: 2, 13: 4, 17: 8} def test_prime_digit_sum_with_mixed_numbers(): assert prime_digit_sum([4, 6, 8, 9, 10, 11, 13]) == {11: 2, 13: 4} def test_prime_digit...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Retu...
[ 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_1
{ "original_instruction": "", "prompt_id": "00000014", "row_id": 14, "seed_ids": "[33103]" }
0.643776
Evol_14
I
[ "is_prime", "sum_of_digits", "prime_digit_sum" ]
3
[ [ "prime_digit_sum", "is_prime" ], [ "prime_digit_sum", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a8e0052ec9123e909f82dbca2323097e6a34a63d
bb05cd4a6a790db0f85b200651934d5722691cd9
v1.0
instruct
Evol
Evol_25_I
Write a Python function that takes as input a list of integers and returns a list of the largest prime factor of each integer. If an integer is prime or less than 2, return the integer itself. For the implementation, ensure that you consider efficiency by leveraging any mathematical optimizations you know. Additionally...
def largest_prime_factor(n): if n <= 1: return n i = 2 while i * i <= n: if n % i: i += 1 else: n //= i return n def largest_prime_factors(lst): return [largest_prime_factor(n) for n in lst]
from solution import largest_prime_factors def test_empty_list(): assert largest_prime_factors([]) == [] def test_prime_numbers(): assert largest_prime_factors([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_composite_numbers(): assert largest_prime_factors([10, 15, 21, 28]) == [5, 5, 7, 7] def t...
[ { "docstring": null, "function_declaration": "def largest_prime_factor(n):", "function_name": "largest_prime_factor", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def largest_prime_factors(lst):", "function_name": "largest_prime_factors", "parameter_li...
[ 1, 1, 0, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000025", "row_id": 25, "seed_ids": "[5262]" }
0.839219
Evol_25
I
[ "largest_prime_factor", "largest_prime_factors" ]
2
[ [ "largest_prime_factors", "largest_prime_factor" ] ]
1
[]
false
[]
false
pytest
true
[]
true
546faa794c16f50c793925a5bc87b6ee8f3349dc
3f8ee4acb483e00eeafc22762513e54f034ce950
v1.0
instruct
Evol
Evol_39_I
Design a program that reads a text file containing a list of integers, one per line, and calculates the moving average of those integers with a specified window size. The program should then write the moving average results to a new file. Each result should be on a new line. To ensure memory efficiency, implement the r...
def read_integers(file_path): """ Reads a file containing a list of integers, one per line. Yields each integer. """ with open(file_path, 'r') as file: for line in file: yield int(line.strip()) def write_moving_averages(file_path, moving_averages): """ Writes the moving ...
import os from solution import read_integers, write_moving_averages, calculate_moving_averages, process_file def test_read_integers(tmp_path): # Setup input_file = tmp_path / "input.txt" input_file.write_text("1\n2\n3\n4\n5\n") # Function call and assertion expected_result = [1, 2, 3, 4, 5] ...
[ { "docstring": "Reads a file containing a list of integers, one per line.\nYields each integer.", "function_declaration": "def read_integers(file_path):", "function_name": "read_integers", "parameter_list": "(file_path)" }, { "docstring": "Writes the moving averages to a file, one per line."...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def read_integers_from_file(file_path):\n \"\"\"\n Generator to read integers from a file, one per line.\n \"\"\"\n with open(file_path, 'r') as file:\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000039", "row_id": 39, "seed_ids": "[34550]" }
0.527993
Evol_39
I
[ "read_integers", "write_moving_averages", "calculate_moving_averages", "process_file" ]
4
[ [ "process_file", "calculate_moving_averages" ], [ "process_file", "read_integers" ], [ "process_file", "write_moving_averages" ] ]
3
[]
false
[]
false
pytest
true
[]
true
95fe0cab710b7e2779e7145f9a08a6c0470a0882
2043b86f43e7205a290d9ca8897cd1a023207593
v1.0
instruct
Evol
Evol_53_I
Develop a Python function that sorts a list of nested dictionaries by a specified key at any depth, and returns the sorted list. The function should accept two arguments: the list of dictionaries and the key. If the key is not present in any of the dictionaries, the original list should be returned. Additionally, analy...
def find_key(d, key): """ Helper function that recursively searches for the key in nested dictionaries. Returns the value if the key is found, otherwise returns None. """ if key in d: return d[key] for k, v in d.items(): if isinstance(v, dict): result = find_key(v, ke...
from solution import sort_nested_dicts def test_sort_nested_dicts_with_present_key(): data = [ {"level1": {"level2": {"id": 3, "value": "C"}}}, {"level1": {"level2": {"id": 1, "value": "A"}}}, {"level1": {"level2": {"id": 2, "value": "B"}}}, {"level1": {"info": {"name": "D"}}} ]...
[ { "docstring": "Helper function that recursively searches for the key in nested dictionaries.\nReturns the value if the key is found, otherwise returns None.", "function_declaration": "def find_key(d, key):", "function_name": "find_key", "parameter_list": "(d, key)" }, { "docstring": "Sorts ...
[ 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 sort_nested_dicts(data, key):\n \"\"\"\n Sorts a list of nested dictionaries by a specified key at any depth.\n \n Args:\n data (list): A list o...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000053", "row_id": 53, "seed_ids": "[3636]" }
0.5952
Evol_53
I
[ "find_key", "sort_nested_dicts" ]
2
[ [ "sort_nested_dicts", "find_key" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1f10e27394d60636f018d650e48a7e8ed717a636
38e5c68ae02133dfc891a9dcec4b01f548ea6210
v1.0
instruct
Evol
Evol_70_I
Design a function that takes a string consisting of lowercase and uppercase letters and returns a new string where each character is shifted by 3 positions in the alphabet, maintaining the original case. For example, 'a' becomes 'd', 'Z' becomes 'C'. Include error handling for non-alphabetic characters, which should re...
def shift_char(c, shift): if c.islower(): return chr((ord(c) - ord('a') + shift) % 26 + ord('a')) elif c.isupper(): return chr((ord(c) - ord('A') + shift) % 26 + ord('A')) else: return c def shift_string(s, shift=3): """ Returns a new string where each character is shifted b...
from solution import shift_string def test_shift_lowercase_letters(): assert shift_string("abc") == "def" assert shift_string("xyz") == "abc" def test_shift_uppercase_letters(): assert shift_string("ABC") == "DEF" assert shift_string("XYZ") == "ABC" def test_shift_mixed_case_letters(): assert shi...
[ { "docstring": null, "function_declaration": "def shift_char(c, shift):", "function_name": "shift_char", "parameter_list": "(c, shift)" }, { "docstring": "Returns a new string where each character is shifted by 'shift' positions in the alphabet.\nNon-alphabetic characters remain unchanged.\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 shift_string(input_str):\n \"\"\"\n Shifts each letter in the input string by 3 positions in the alphabet, maintaining the case.\n Non-alphabetic char...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000070", "row_id": 70, "seed_ids": "[15739]" }
0.68281
Evol_70
I
[ "shift_char", "shift_string" ]
2
[ [ "shift_string", "shift_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23dd4b390713f80240ed824c1894e8d4ef76e822
6f54789697ce832fa137979a68f37e8bdd47144c
v1.0
instruct
Evol
Evol_77_I
Write a Python function named `find_prime_numbers` that takes two integers, `start` and `end`, as parameters and returns a list of all prime numbers between `start` and `end` (inclusive). A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example: ```python fin...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False elif n <= 3: return True elif 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 find_prime_numbers def test_primes_in_middle_range(): assert find_prime_numbers(10, 30) == [11, 13, 17, 19, 23, 29] def test_no_primes(): assert find_prime_numbers(0, 1) == [] def test_single_prime_range(): assert find_prime_numbers(2, 2) == [2] def test_large_prime_range(): ass...
[ { "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 all prime numbers between start and end (inclusive).", "function_declaration": "def find_...
[ 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_prime_numbers(start, end):\n \"\"\"\n Returns a list of prime numbers between `start` and `end` (inclusive).\n \"\"\"\n def is_prime(n):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000077", "row_id": 77, "seed_ids": "[31050]" }
0.68536
Evol_77
I
[ "is_prime", "find_prime_numbers" ]
2
[ [ "find_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
208848aa43d2d903c7a23e86a2376376b4b69972
dba5be32574f16f4de3ed08e5ef0d996af0d2944
v1.0
instruct
Evol
Evol_78_I
Create a program that takes a list of strings as input, where each string represents an arithmetic expression consisting of non-negative integers and the operators '+', '-', '*', and '/'. The program should evaluate each expression and return a list of results corresponding to the input expressions. The input strings w...
def evaluate_expression(expression): """ Evaluates a single arithmetic expression string and returns the result """ def apply_operator(operators, operands): operator = operators.pop() right_operand = operands.pop() left_operand = operands.pop() if operator == '+': ...
from solution import evaluate_expressions def test_single_expression(): assert evaluate_expressions(["3+5*2"]) == [13] def test_multiple_expressions(): expressions = ["3+5*2", "(2+3)*(5-2)", "10/2-1"] results = [13, 15, 4] assert evaluate_expressions(expressions) == results def test_division_and_subt...
[ { "docstring": "Evaluates a single arithmetic expression string and returns the result", "function_declaration": "def evaluate_expression(expression):", "function_name": "evaluate_expression", "parameter_list": "(expression)" }, { "docstring": "Takes a list of arithmetic expression strings a...
[ 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": "import operator\n\n# Helper function to perform arithmetic operations\ndef operate(a, b, op):\n if op == '+':\n return a + b\n elif op == '-':\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000078", "row_id": 78, "seed_ids": "[12915]" }
0.689794
Evol_78
I
[ "evaluate_expression", "evaluate_expressions" ]
2
[ [ "evaluate_expressions", "evaluate_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
666002ee235dc3a770c480f5b78f9b6e44125a84
79707519c8eb218249ff3314d7a5a16fb5fc0943
v1.0
instruct
Evol
Evol_91_I
Implement a simple chat application using WebSockets in Python. Your application should allow multiple clients to connect to the server and exchange messages in real-time. The server should broadcast each message it receives to all connected clients. Do not use any third-party libraries except for `websockets` and `asy...
# Chat Server import asyncio import websockets connected_clients = {} async def broadcast(message): if connected_clients: await asyncio.wait([client.send(message) for client in connected_clients.values()]) async def handle_client(websocket, path): client_id = websocket.remote_address connected_cl...
import asyncio from websockets import connect, serve import pytest @pytest.mark.asyncio async def test_chat_server(): async def mock_client(send_message): uri = "ws://localhost:6789" async with connect(uri) as websocket: if send_message: await websocket.send(send_message...
[]
[ 1, 0, 0, 1, 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": "import asyncio\nimport websockets\n\nconnected_clients = {}\n\nasync def broadcast_message(message, sender_ws):\n for client_ws in connected_clients:\n i...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000091", "row_id": 91, "seed_ids": "[29333]" }
0.547115
Evol_91
I
[ "broadcast", "handle_client", "main", "send_message", "receive_message", "main" ]
6
[ [ "handle_client", "broadcast" ] ]
1
[]
false
[]
false
pytest
false
[ "websockets" ]
false
132756d430f3114425a2273895ba0dfd238bbb4a
35d5dd21a82b3a8233c640cc63d012f09960b16a
v1.0
instruct
Evol
Evol_96_I
Implement 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 your solution is efficient for large lists of integers. Make use of list comprehensions and a helper function to check primality. Avoid using built-in functions l...
def is_prime(n): """ Checks 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 i += 6 return T...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 10]) == [] def test_filter_primes_mixed(): assert filter_primes([4, 6, 7, 10, 13]) == [7, 13] def test_filter_prim...
[ { "docstring": "Checks if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the prime numbers from a list of integers.", "function_declaration": "def filter_primes(numbers):", "function_n...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "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_9
{ "original_instruction": "", "prompt_id": "00000096", "row_id": 96, "seed_ids": "[21554]" }
0.575042
Evol_96
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a48101697c2529c95ab7d5bec3631ea8fec32cb4
b378ce69fe47e33b11eee6bde25e458083dce5ba
v1.0
instruct
Evol
Evol_98_I
Write a function that takes a string of comma-separated integers and returns the sum of the factorial of each integer. You can assume that the input string is always valid and contains at least one integer. def sum_of_factorials(numbers: str) -> int: """Compute the sum of the factorials of each integer in the comm...
def factorial(n): """ Helper function to compute the factorial of a given number n. """ if n == 0: return 1 result = 1 for i in range(1, n + 1): result *= i return result def sum_of_factorials(numbers: str) -> int: """ Compute the sum of the factorials of each intege...
from solution import sum_of_factorials def test_sum_of_factorials(): assert sum_of_factorials('1,2,3') == 9 # 1! + 2! + 3! = 1 + 2 + 6 = 9 assert sum_of_factorials('4,5') == 144 # 4! + 5! = 24 + 120 = 144 assert sum_of_factorials('6') == 720 # 6! = 720 assert sum_of_factorials('0') == 1 #...
[ { "docstring": "Helper function to compute the factorial of a given number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Compute the sum of the factorials of each integer in the comma-separated input string.", "...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Helper function to compute the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000098", "row_id": 98, "seed_ids": "[38888]" }
0.677742
Evol_98
I
[ "factorial", "sum_of_factorials" ]
2
[ [ "sum_of_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b93464e1fc207fa5557893d4235bf3c00a137ff
fb5e9c1e8127cf7727395616a4c010955520c6d8
v1.0
instruct
Evol
Evol_110_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. Additionally, write a function that accepts a starting and ending integer, generates a list of all integers within that range, and uses your prime-filtering function to return only the ...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, filter_primes, range_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime(0) == False assert is_pr...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the provided list of integers.", "function_declaration": "def 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 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": "00000110", "row_id": 110, "seed_ids": "[31198]" }
0.64247
Evol_110
I
[ "is_prime", "filter_primes", "range_primes" ]
3
[ [ "filter_primes", "is_prime" ], [ "range_primes", "filter_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cbb8189a66b590c1f44f7d1104ff5c13b25c7ea7
354003d3a499e26b4204a0bbd2eb55d4be063ccd
v1.0
instruct
Evol
Evol_119_I
Design a function that takes a matrix of integers and returns the transpose of the matrix. The transpose of a matrix is a new matrix whose rows are the columns of the original. Additionally, write a function to calculate the determinant of the transposed matrix if it is a square matrix. Ensure your solution handles non...
def transpose(matrix): """ Returns the transpose of a given matrix. """ return [list(row) for row in zip(*matrix)] def determinant(matrix): """ Returns the determinant of the given square matrix. """ n = len(matrix) if n == 1: return matrix[0][0] if n == 2: retur...
from solution import transpose, determinant, transpose_and_determinant def test_transpose_square_matrix(): assert transpose([[1, 2], [3, 4]]) == [[1, 3], [2, 4]] def test_transpose_rectangular_matrix(): assert transpose([[1, 2, 3], [4, 5, 6]]) == [[1, 4], [2, 5], [3, 6]] def test_determinant_2x2_matrix(): ...
[ { "docstring": "Returns the transpose of a given matrix.", "function_declaration": "def transpose(matrix):", "function_name": "transpose", "parameter_list": "(matrix)" }, { "docstring": "Returns the determinant of the given square matrix.", "function_declaration": "def determinant(matrix...
[ 1, 1, 0, 0, 0, 1, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def transpose(matrix):\n \"\"\"\n Returns the transpose of the given matrix.\n \"\"\"\n return [list(row) for row in zip(*matrix)]\n\ndef determinant(m...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000119", "row_id": 119, "seed_ids": "[44625]" }
0.537874
Evol_119
I
[ "transpose", "determinant", "transpose_and_determinant" ]
3
[ [ "transpose_and_determinant", "determinant" ], [ "transpose_and_determinant", "transpose" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4690d98e4fcbf2c7591f5592fdbcd036d4d5ea2a
b12fc40ba6ec4d4644971232e8a69ca0bead2108
v1.0
instruct
Evol
Evol_135_I
You are given a list of strings, each representing a potentially valid IPv4 address. Write a Python function that filters out and returns only the valid IPv4 addresses from the list. Each string in the list should be checked to see if it follows the IPv4 format, which is four decimal numbers separated by dots (e.g., "1...
import re def is_valid_ipv4(ip): """ Check if the given IP address is a valid IPv4 address. """ pattern = r'^(\d{1,3}\.){3}\d{1,3}$' if re.match(pattern, ip): parts = ip.split('.') for part in parts: if int(part) < 0 or int(part) > 255: return False ...
from solution import filter_valid_ipv4_addresses, is_valid_ipv4 def test_is_valid_ipv4(): assert is_valid_ipv4("192.168.0.1") == True assert is_valid_ipv4("256.256.256.256") == False assert is_valid_ipv4("10.0.0.123") == True assert is_valid_ipv4("192.168.1") == False assert is_valid_ipv4("172.16.2...
[ { "docstring": "Check if the given IP address is a valid IPv4 address.", "function_declaration": "def is_valid_ipv4(ip):", "function_name": "is_valid_ipv4", "parameter_list": "(ip)" }, { "docstring": "Filters out the valid IPv4 addresses from the given list of IP addresses.\n\nParameters:\n ...
[ 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": "import re\n\ndef is_valid_ipv4(ip):\n \"\"\"\n Checks if the given IP address is a valid IPv4 address.\n \"\"\"\n try:\n parts = ip.split('.')\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000135", "row_id": 135, "seed_ids": "[42518]" }
0.646271
Evol_135
I
[ "is_valid_ipv4", "filter_valid_ipv4_addresses" ]
2
[ [ "filter_valid_ipv4_addresses", "is_valid_ipv4" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee60aac5613a36328edd6d74d1766593a1a111eb
0d01bc158ca08895190428750b4415f559d246ae
v1.0
instruct
Evol
Evol_141_I
Write a Python function named `is_prime` that takes a single integer argument `n` and returns `True` if `n` is a prime number, and `False` otherwise. Additionally, write a second function `prime_factors` that uses `is_prime` to return a list of all prime factors of a given integer `n` in ascending order. For the purpos...
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 prime_...
from solution import is_prime, prime_factors 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(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime factors of n in ascending order.", "function_declaration": "def prime_fa...
[ 1, 1, 0, 1, 1, 1, 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 Returns True if the input integer n is a prime number, else returns False.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000141", "row_id": 141, "seed_ids": "[35747]" }
0.777431
Evol_141
I
[ "is_prime", "prime_factors" ]
2
[ [ "prime_factors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a711b1018042da180dccb6e6917e8e2fc56ad9d2
e2f65d0f5d1a120d1d4e3e87b6f9eaacd2ca99d4
v1.0
instruct
Evol
Evol_147_I
Write a function in Python that accepts a list of integers and returns the list with all its elements removed except for the prime numbers, but with the primes sorted in descending order. Additionally, the function should return the sum of these prime numbers. Example input: [12, 3, 17, 4, 2, 8, 5, 11] Expected output...
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_and_sort_primes(lst): primes = [x for x in lst if is_prime(x)] primes.sort(reverse=True) prime_sum = sum(primes) return primes, prime_s...
from solution import filter_and_sort_primes def test_filter_and_sort_primes_with_mixed_numbers(): assert filter_and_sort_primes([12, 3, 17, 4, 2, 8, 5, 11]) == ([17, 11, 5, 3, 2], 38) def test_filter_and_sort_primes_all_primes(): assert filter_and_sort_primes([2, 3, 5, 7]) == ([7, 5, 3, 2], 17) def test_filt...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def filter_and_sort_primes(lst):", "function_name": "filter_and_sort_primes", "parameter_list": "(lst)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef is_prime(n: int) -> bool:\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": "00000147", "row_id": 147, "seed_ids": "[20842]" }
0.633647
Evol_147
I
[ "is_prime", "filter_and_sort_primes" ]
2
[ [ "filter_and_sort_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fd936b25c976c1be6033b1f625fd773b3f84266
d32a8dad91917eaaa84394620a712405078be3df
v1.0
instruct
Evol
Evol_225_I
Create a Python function that receives a list of integers. For each element in the list, perform the following operations: 1. Convert the integer to its hexadecimal equivalent. 2. Count the number of `1`s in the binary representation of this hexadecimal number. 3. Calculate the sum of these counts for all elements in t...
def count_ones_in_binary_of_hex(num): """ Takes an integer number and returns the number of 1's in the binary representation of its hexadecimal equivalent. """ # Convert to hexadecimal and remove '0x' prefix hex_num = hex(num)[2:] # Convert each hexadecimal digit to its binary form and count th...
from solution import sum_of_ones_in_hex_binary def test_single_number(): assert sum_of_ones_in_hex_binary([10]) == 2 # hexadecimal 'a' -> binary '1010' assert sum_of_ones_in_hex_binary([15]) == 4 # hexadecimal 'f' -> binary '1111' def test_multiple_numbers(): assert sum_of_ones_in_hex_binary([10, 15]) =...
[ { "docstring": "Takes an integer number and returns the number of 1's in the binary representation of its hexadecimal equivalent.", "function_declaration": "def count_ones_in_binary_of_hex(num):", "function_name": "count_ones_in_binary_of_hex", "parameter_list": "(num)" }, { "docstring": "Ta...
[ 0, 0, 0, 1, 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 count_ones_in_hexadecimal_binary(my_list):\n \"\"\"\n For each integer in the list, converts it to its hexadecimal equivalent, counts the \n number of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000225", "row_id": 225, "seed_ids": "[12371]" }
0.656706
Evol_225
I
[ "count_ones_in_binary_of_hex", "sum_of_ones_in_hex_binary" ]
2
[ [ "sum_of_ones_in_hex_binary", "count_ones_in_binary_of_hex" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ed2ab42512b64bb88198c0f0f0afb92adb2fb94
970274cb92ef2d6568b7cdd38d63670326b9bd39
v1.0
instruct
Evol
Evol_228_I
Craft a Python function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. The result list should be sorted in descending order. For example, given the input list [10, 3, 5, 8, 15, 2], your function should return [5, 3, 2].
def is_prime(n): """Helper function to 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 p = 3 while p * p <= n: if n % p == 0: return False p +...
from solution import filter_and_sort_primes def test_filter_and_sort_primes_with_mixed_numbers(): assert filter_and_sort_primes([10, 3, 5, 8, 15, 2]) == [5, 3, 2] def test_filter_and_sort_primes_with_no_primes(): assert filter_and_sort_primes([4, 6, 8, 10, 15]) == [] def test_filter_and_sort_primes_with_only...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the prime numbers from the list and sorts them in descending order.", "function_declaratio...
[ 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 for i in range(2, in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000228", "row_id": 228, "seed_ids": "[38588]" }
0.673258
Evol_228
I
[ "is_prime", "filter_and_sort_primes" ]
2
[ [ "filter_and_sort_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0129eaf20bd70b53bdb219e282a92d7bab57826
2882009b027ccead8a7b8703366245ffc647ad54
v1.0
instruct
Evol
Evol_234_I
Write a Python function called `find_largest_prime` that takes a single integer argument `n` and returns the largest prime number that is less than or equal to `n`. If no such prime exists (i.e., if `n` is less than 2), the function should return `None`. To complete this task, implement a helper function `is_prime` tha...
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 find_largest_prime(...
from solution import is_prime, find_largest_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(17) == True assert is_prime(18) ==...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the largest prime number less than or equal to n.", "function_declaration": "def find_largest_prime(n):", "func...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the input number is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000234", "row_id": 234, "seed_ids": "[30136]" }
0.747365
Evol_234
I
[ "is_prime", "find_largest_prime" ]
2
[ [ "find_largest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b6ae65913625f7fc986ee872050363e9f34ac6ac
eaa0f6916469c9a98426bd7b01bd625d9452f689
v1.0
instruct
Evol
Evol_261_I
Write a Python program to find all the prime numbers in a given range of integers without using any libraries. Additionally, your program should be able to count the number of prime numbers found in the given range. Your task: 1. Write a function that checks whether a given number is prime. 2. Write a function that re...
def is_prime(n): """ Determines if the given 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 ...
from solution import is_prime, find_primes_in_range, count_primes_in_range def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(13) def test_find_primes_in_range(): assert find...
[ { "docstring": "Determines if the given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the given range [start, end).", "function_declaration": "def fi...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000261", "row_id": 261, "seed_ids": "[32448]" }
0.731842
Evol_261
I
[ "is_prime", "find_primes_in_range", "count_primes_in_range" ]
3
[ [ "count_primes_in_range", "find_primes_in_range" ], [ "find_primes_in_range", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aff9a3759be70a637f964f214e9b10df0416f50d
dfd2d7dc0e15a3f11442bbe76b5346e037e946a1
v1.0
instruct
Evol
Evol_264_I
Write a Python function that accepts a list of integers and returns a list of tuples. Each tuple consists of an integer from the input list and its corresponding Fibonacci value. The Fibonacci value of an integer `n` is defined as the `n`-th Fibonacci number in the sequence, where the 0th and 1st Fibonacci numbers are ...
def fibonacci(n): """ Returns the n-th Fibonacci number. """ if n < 0: raise ValueError("Fibonacci number is not defined for negative integers.") elif n == 0: return 0 elif n == 1: return 1 else: a, b = 0, 1 for _ in range(2, n + 1): a, b =...
from solution import fibonacci, list_fibonacci_values def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(10) == 55 def test_fibonacci_negative(): tr...
[ { "docstring": "Returns the n-th Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Returns a list of tuples. Each tuple consists of an integer from the input list and its corresponding Fibonacci value.", ...
[ 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 fib(n):\n \"\"\"\n Returns the n-th Fibonacci number.\n \"\"\"\n if n < 0:\n raise ValueError(\"Negative integers are not allowed\")\n el...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000264", "row_id": 264, "seed_ids": "[3347]" }
0.749721
Evol_264
I
[ "fibonacci", "list_fibonacci_values" ]
2
[ [ "list_fibonacci_values", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b3f7ea9ce9e67e86655b6ec8416b87782e5104e
142e2c6a632c30e542604203fe500d3df82a0f09
v1.0
instruct
Evol
Evol_272_I
Design and implement a system that detects and classifies anomalies in a series of time-stamped transactions using Python and scikit-learn. The system should be able to read data from a CSV file containing transaction details including 'timestamp', 'amount', 'category', etc. Your task includes preprocessing the data, s...
import pandas as pd from sklearn.ensemble import IsolationForest from sklearn.preprocessing import StandardScaler from datetime import datetime def preprocess_data(df): """ Preprocess the transaction data. """ # Convert 'timestamp' to datetime and extract important features df['timestamp'] = pd.to_...
import pandas as pd from solution import preprocess_data, detect_anomalies, update_model_with_new_data def test_preprocess_data(): data = { 'timestamp': ['2023-09-01 10:05:00', '2023-09-02 15:16:30'], 'amount': [100, 250], 'category': ['groceries', 'utilities'] } df = pd.DataFrame(d...
[ { "docstring": "Preprocess the transaction data.", "function_declaration": "def preprocess_data(df):", "function_name": "preprocess_data", "parameter_list": "(df)" }, { "docstring": "Detect anomalies in the transaction data using the IsolationForest algorithm.", "function_declaration": "...
[ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import pandas as pd\nfrom sklearn.ensemble import IsolationForest\nfrom sklearn.preprocessing import StandardScaler\nfrom datetime import datetime\n\nclass Anomaly...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000272", "row_id": 272, "seed_ids": "[528]" }
0.468805
Evol_272
I
[ "preprocess_data", "detect_anomalies", "update_model_with_new_data" ]
3
[ [ "detect_anomalies", "preprocess_data" ], [ "update_model_with_new_data", "detect_anomalies" ] ]
2
[]
false
[]
false
pytest
true
[ "pandas", "sklearn" ]
false
bc328789e67b760e7fee5adcab271dd5477309e3
5729a6676ef1f85c780071ab672406964501fa10
v1.0
instruct
Evol
Evol_278_I
Write a Python function that takes a string as input and returns a list of all valid IP addresses that can be formed by inserting three dots into the string. A valid IP address consists of exactly four integers (each ranging from 0 to 255), separated by dots. Each integer must not have leading zeros (unless the integer...
def is_valid(segment): """ Check if the segment is a valid IP address segment. """ return int(segment) <= 255 and (segment == "0" or segment[0] != "0") def restore_ip_addresses(s): """ Restore valid IP addresses from a string by inserting three dots. """ n = len(s) result = [] ...
from solution import restore_ip_addresses def test_restore_ip_addresses_example(): assert restore_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"] def test_restore_ip_addresses_empty(): assert restore_ip_addresses("") == [] def test_restore_ip_addresses_short_string(): assert restore_i...
[ { "docstring": "Check if the segment is a valid IP address segment.", "function_declaration": "def is_valid(segment):", "function_name": "is_valid", "parameter_list": "(segment)" }, { "docstring": "Restore valid IP addresses from a string by inserting three dots.", "function_declaration"...
[ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def restore_ip_addresses(s: str):\n \"\"\"\n Returns a list of all valid IP addresses that can be formed by inserting three dots into the string.\n \"\"\"...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000278", "row_id": 278, "seed_ids": "[6954]" }
0.638145
Evol_278
I
[ "is_valid", "restore_ip_addresses" ]
2
[ [ "restore_ip_addresses", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43af9aca70df7dd66a659e953e169adbe06f6ac4
c8646caa75a8d00059f836e904ccda59dd9c2b55
v1.0
instruct
Evol
Evol_311_I
Write a Python function that takes a list of integers and returns the sum of the elements that are both prime numbers and lie within a given range [min_value, max_value], inclusive. If no such elements exist in the list, return 0. Consider the list may contain negative numbers and non-prime numbers should be ignored. U...
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def sum_primes_in_range(lst, mi...
from solution import is_prime, sum_primes_in_range def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(-1) assert not is_prime(0) assert not is_prime(1) def test_sum_primes_in_range_no_primes(): assert sum_primes_in_r...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of prime numbers within the range [min_value, max_value] from the list.", "function_declaration": "def sum_pr...
[ 0, 0, 1, 0, 0, 1, 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 is_prime(n):\n \"\"\"Check if a number n is prime.\"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ==...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000311", "row_id": 311, "seed_ids": "[36880]" }
0.646663
Evol_311
I
[ "is_prime", "sum_primes_in_range" ]
2
[ [ "sum_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ab0f4a0ad3da036a53435d8466d5965ab6db7a3
d37dfcbae119abe2fa29af2d667f2799def21922
v1.0
instruct
Evol
Evol_332_I
Write a function in Python to perform k-means clustering on a given dataset. The function should take the number of clusters `k`, the dataset (a list of coordinates in two-dimensional space), and the number of iterations. Your implementation should showcase the initialization of centroids, assignment of points to the n...
import random import numpy as np def initialize_centroids(k, data): """ Randomly initializes centroids by selecting k unique points from the dataset. """ centroids = random.sample(data, k) return centroids def assign_points_to_clusters(centroids, data): """ Assigns each data point to the n...
from solution import k_means_clustering def test_initialize_centroids(): data = [[1, 2], [2, 3], [3, 4]] k = 2 centroids = initialize_centroids(k, data) assert len(centroids) == k assert all(c in data for c in centroids) def test_assign_points_to_clusters(): centroids = [[1, 2], [8, 7]] ...
[ { "docstring": "Randomly initializes centroids by selecting k unique points from the dataset.", "function_declaration": "def initialize_centroids(k, data):", "function_name": "initialize_centroids", "parameter_list": "(k, data)" }, { "docstring": "Assigns each data point to the nearest centr...
[ 0, 1, 1, 0, 1, 0, 1, 1, 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 random\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sq...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000332", "row_id": 332, "seed_ids": "[40266]" }
0.703374
Evol_332
I
[ "initialize_centroids", "assign_points_to_clusters", "update_centroids", "k_means_clustering" ]
4
[ [ "k_means_clustering", "assign_points_to_clusters" ], [ "k_means_clustering", "initialize_centroids" ], [ "k_means_clustering", "update_centroids" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy" ]
false
caf9dfa8d04ac2019dc8843abd84dfd72a625f71
2c03e2e63dca7d742564dcd4c77d4a3bff3076e1
v1.0
instruct
Evol
Evol_354_I
Design and implement a genetic algorithm to solve the Traveling Salesman Problem (TSP). Begin by creating a function to generate a random set of cities (each represented by x and y coordinates). Then, implement the genetic algorithm, which includes the following components: initialization, selection, crossover, mutatio...
import random import math import matplotlib.pyplot as plt def generate_cities(num_cities, seed=42): """ Generates a list of randomly placed cities represented by (x, y) coordinates. """ random.seed(seed) return [(random.uniform(0, 100), random.uniform(0, 100)) for _ in range(num_cities)] def dista...
from solution import generate_cities, distance, total_distance, generate_initial_population from solution import selection, crossover, mutate, genetic_algorithm, plot_tsp def test_generate_cities(): cities = generate_cities(10, seed=42) assert len(cities) == 10 assert cities[0] == (63.942679845788376, 2.50...
[ { "docstring": "Generates a list of randomly placed cities represented by (x, y) coordinates.", "function_declaration": "def generate_cities(num_cities, seed=42):", "function_name": "generate_cities", "parameter_list": "(num_cities, seed=42)" }, { "docstring": "Calculates the Euclidean dista...
[ 1, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\nimport math\nimport matplotlib.pyplot as plt\n\ndef generate_cities(num_cities, seed=42):\n \"\"\"\n Generates a list of randomly placed citie...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000354", "row_id": 354, "seed_ids": "[45212]" }
0.507688
Evol_354
I
[ "generate_cities", "distance", "total_distance", "generate_initial_population", "selection", "crossover", "mutate", "genetic_algorithm", "plot_tsp" ]
9
[ [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "generate_initial_population" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "selection" ], [ "genetic_algorithm", "total_distance" ], [ "total_distance", "distance" ] ]
6
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
6d3803b181100ce2f5f55e9bf32439dca52662a6
69c8c461805fefd157543659659031db667595a4
v1.0
instruct
Evol
Evol_362_I
Implement a function in Python that receives a list of integers and returns a new list containing only the prime numbers from the input list. Additionally, for each prime number found, attach the number of times it appears in the input list. Present the prime numbers in ascending order in the output list, where each pr...
def is_prime(n): 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 prime_frequencies(lst): prime_counts = {} for number in lst: ...
from solution import prime_frequencies def test_primes_mixed_frequencies(): assert prime_frequencies([7, 3, 5, 7, 3, 2, 7, 11, 5, 13, 2]) == [(2, 2), (3, 2), (5, 2), (7, 3), (11, 1), (13, 1)] def test_single_prime(): assert prime_frequencies([2, 2, 2]) == [(2, 3)] def test_no_primes(): assert prime_frequ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def prime_frequencies(lst):", "function_name": "prime_frequencies", "parameter_list": "(lst)" } ]
[ 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 the number n is prime.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n r...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000362", "row_id": 362, "seed_ids": "[37315]" }
0.707578
Evol_362
I
[ "is_prime", "prime_frequencies" ]
2
[ [ "prime_frequencies", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
106f13add19935c4225dd9ea090f79f13cd9c0a2
b440cf684492fb8651ec19a9cd79c4a799ebe823
v1.0
instruct
Evol
Evol_371_I
Write a program that implements a basic hill climbing algorithm to find the maximum value of a given mathematical function. The function to be maximized is f(x) = -x^2 + 6x - 5 on the interval [0, 5]. Parameters and requirements: 1. Start the search from a random point within the interval. 2. At each step, move to a ...
import random def f(x): """ The function to be maximized: f(x) = -x^2 + 6x - 5 """ return -x**2 + 6*x - 5 def hill_climb(start=None, step_size=0.1, interval=(0, 5)): """ Basic hill climbing algorithm to find the maximum value of f(x) on the interval [0, 5]. """ if start is None: ...
from solution import hill_climb, f import numpy as np def test_is_in_interval(): x, value = hill_climb(start=2.5) assert 0 <= x <= 5, f"x = {x} not within the interval [0, 5]." def test_maximum_value(): x, value = hill_climb(start=2.5) # As per the given quadratic function, maximum should be around x=...
[ { "docstring": "The function to be maximized: f(x) = -x^2 + 6x - 5", "function_declaration": "def f(x):", "function_name": "f", "parameter_list": "(x)" }, { "docstring": "Basic hill climbing algorithm to find the maximum value of f(x) on the interval [0, 5].", "function_declaration": "de...
[ 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\ndef hill_climbing(f, start, step_size, lower_bound, upper_bound):\n \"\"\"\n Hill climbing algorithm to find the maximum value of the functi...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000371", "row_id": 371, "seed_ids": "[9146]" }
0.476395
Evol_371
I
[ "f", "hill_climb" ]
2
[ [ "hill_climb", "f" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
4a3e3b260d5df0b92e8265995d615f1c40bf94ec
ba0f53d4f7ab63784a06f37bc09bfd4d1be47904
v1.0
instruct
Evol
Evol_387_I
Implement a function that takes a list of integers and returns a new list with only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no divisors other than 1 and itself. ```python def filter_primes(numbers): # Your code here # Example usage: numbers = [2, 3, 4, ...
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, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False assert is_prime(-7) == Fal...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list `numbers`.", "function_declaration": "def filter...
[ 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_6
{ "original_instruction": "", "prompt_id": "00000387", "row_id": 387, "seed_ids": "[9128]" }
0.678989
Evol_387
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1349ff25c2e003d19096ec216685a66c7ab56eb3
d1d7c9d58409eba8df9dd93b32e8bebc0ded6061
v1.0
instruct
Evol
Evol_408_I
Write a Python function that takes a list of numbers and returns the list sorted in ascending order. Use the merge sort algorithm to implement this function. Example: ``` Input: [34, 7, 23, 32, 5, 62] Output: [5, 7, 23, 32, 34, 62] ``` Hints: 1. Merge sort is a divide-and-conquer algorithm that splits the list into ...
def merge(left, right): """ Merges two sorted lists into one sorted list. """ result = [] i = j = 0 # Traverse both lists and insert the smallest element from either list into the result list while i < len(left) and j < len(right): if left[i] <= right[j]: result.appe...
from solution import merge_sort def test_merge_sort_simple(): assert merge_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62] def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted(): assert merge_so...
[ { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" }, { "docstring": "Sorts a list of numbers in ascending order using the merge sort algorithm.", "function_declara...
[ 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(left, right):\n \"\"\"\n Merge two sorted lists into one sorted list.\n \"\"\"\n result = []\n i = j = 0\n\n # Merge the two lists toge...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000408", "row_id": 408, "seed_ids": "[39386]" }
0.644756
Evol_408
I
[ "merge", "merge_sort" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4dee4e6527d06819c08b8ba15e9631ff55844a54
415137a5aebbde363ac5a9efec790dddae740420
v1.0
instruct
Evol
Evol_417_I
Write a program that takes a string containing an arithmetic expression with integers and the operators +, -, *, and /. The program should parse the string and compute the resulting value, taking into account the correct order of operations (PEMDAS/BODMAS rules). Additionally, enhance the program to handle expressions ...
import re operators = set(['+', '-', '*', '/', '(', ')']) priority = {'+': 1, '-': 1, '*': 2, '/': 2} def infix_to_postfix(expression): stack = [] output = '' for char in expression: if char not in operators: output+= char elif char=='(': stack.append...
from solution import compute_expression, validate_expression def test_simple_addition(): assert compute_expression("2+3") == 5 def test_simple_subtraction(): assert compute_expression("5-3") == 2 def test_simple_multiplication(): assert compute_expression("4*2") == 8 def test_simple_division(): asse...
[ { "docstring": null, "function_declaration": "def infix_to_postfix(expression):", "function_name": "infix_to_postfix", "parameter_list": "(expression)" }, { "docstring": null, "function_declaration": "def evaluate_postfix(expression):", "function_name": "evaluate_postfix", "param...
[ 0, 0, 0, 0, 0, 1, 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": "import re\n\ndef evaluate_expression(expression):\n \"\"\"\n Evaluates a given arithmetic expression with integers and operators +, -, *, and /.\n It hand...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000417", "row_id": 417, "seed_ids": "[4346]" }
0.569808
Evol_417
I
[ "infix_to_postfix", "evaluate_postfix", "validate_expression", "compute_expression" ]
4
[ [ "compute_expression", "evaluate_postfix" ], [ "compute_expression", "infix_to_postfix" ], [ "compute_expression", "validate_expression" ] ]
3
[]
false
[]
false
pytest
true
[]
true
37c1d360bb4253ee592ecd9043c33f9546d5b90d
8336d5d8ef0bebfddd6e6f8372652ae3132714c0
v1.0
instruct
Evol
Evol_435_I
Write a function that takes a list of integers and returns the list sorted in ascending order, but with all prime numbers positioned at the end of the list. The function should handle erroneous inputs gracefully: it should throw a custom error if the input is not a list, or if any element in the list is not an integer....
class InvalidInputException(Exception): pass 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 for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False ...
from solution import sort_misplaced_primes, InvalidInputException def test_sort_simple_case(): assert sort_misplaced_primes([10, 3, 5, 7, 2, 1]) == [1, 10, 3, 5, 7, 2] def test_sort_with_only_non_primes(): assert sort_misplaced_primes([8, 10, 4, 1]) == [1, 4, 8, 10] def test_sort_with_only_primes(): asse...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "class InputError(Exception):\n \"\"\"Custom error for invalid inputs\"\"\"\n pass\n\ndef is_prime(num):\n \"\"\"Returns True if the number is prime, else ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000435", "row_id": 435, "seed_ids": "[32013]" }
0.58849
Evol_435
I
[ "is_prime", "sort_misplaced_primes" ]
2
[ [ "sort_misplaced_primes", "is_prime" ] ]
1
[]
false
[ "InvalidInputException" ]
true
pytest
true
[]
true
6c35f6d6d0c1849b2ebd07cb6d3c7d9a6a3973b0
886326641d85cb06ef0a825807bb8bc5a4763bb4
v1.0
instruct
Evol
Evol_456_I
Design a Python function that takes an integer input representing the number of rows, and prints a Pascal's Triangle up to that row, using recursion. The function should handle invalid inputs gracefully by prompting the user to enter a valid integer if a non-numeric or negative value is provided. Additionally, implemen...
def generate_pascals_triangle(num_rows): """ Generates Pascal's Triangle up to the given number of rows using recursion. """ if num_rows < 0: raise ValueError("Number of rows must be a non-negative integer.") def generate_row(previous_row): row = [1] for i in range(1, le...
from solution import generate_pascals_triangle, formatted_pascals_triangle def test_generate_pascals_triangle(): assert generate_pascals_triangle(0) == [] assert generate_pascals_triangle(1) == [[1]] assert generate_pascals_triangle(2) == [[1], [1, 1]] assert generate_pascals_triangle(3) == [[1], [1, 1...
[ { "docstring": "Generates Pascal's Triangle up to the given number of rows using recursion.", "function_declaration": "def generate_pascals_triangle(num_rows):", "function_name": "generate_pascals_triangle", "parameter_list": "(num_rows)" }, { "docstring": "Generates and prints Pascal's Tria...
[ 1, 1, 0, 1, 0, 0, 0, 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 get_pascals_triangle_row(row_num):\n \"\"\"\n Recursively generates the row of Pascal's Triangle.\n \"\"\"\n if row_num == 0:\n return [1]\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000456", "row_id": 456, "seed_ids": "[20683]" }
0.54501
Evol_456
I
[ "generate_pascals_triangle", "formatted_pascals_triangle" ]
2
[ [ "formatted_pascals_triangle", "generate_pascals_triangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c525678eaae8aeead9441a2e3c5e3dcf2be44c5
7d1445a29bcb4e3e2002de739bdc45c7fb77a4b1
v1.0
instruct
Evol
Evol_465_I
Write a function that calculates the sum of all prime numbers less than a given positive integer N. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. The function should take an integer N as input and return the sum of all prime numbers less than N. For...
def is_prime(num): 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 sum_of_primes_less_than(N): """ Returns the sum of all prime...
from solution import is_prime, sum_of_primes_less_than def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(97) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers less than a given positive integer N.", "function_declaration": "def sum_of_primes_less_than(N):", "functi...
[ 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 <= 3:\n r...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000465", "row_id": 465, "seed_ids": "[42481]" }
0.70708
Evol_465
I
[ "is_prime", "sum_of_primes_less_than" ]
2
[ [ "sum_of_primes_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cca10fd03ec029a96cc87b767b0413b0cd82d028
35a3683ca3e60fb3354049a0bf0dfce4df598ced
v1.0
instruct
Evol
Evol_504_I
將給定範圍內的所有質數列出來。 範圍:[10, 50]
def is_prime(n): """ Check if a given 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 += ...
from solution import list_primes_in_range, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_list_primes_in_range(): assert list_prime...
[ { "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": "Lists all prime numbers in the given range [start, end].", "function_declaration": "def list_primes_in_range(...
[ 1, 1, 1, 0, 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 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_9
{ "original_instruction": "", "prompt_id": "00000504", "row_id": 504, "seed_ids": "[45980]" }
0.327512
Evol_504
I
[ "is_prime", "list_primes_in_range" ]
2
[ [ "list_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
014ad0bd86e8054a612cb14a51270c04242bed29
b38cbe869bdd018ea7efc018ae64c7c478d7c79c
v1.0
instruct
Evol
Evol_534_I
Design a Python program that takes a list of integers and returns a new list containing only the elements that are perfect squares from the original list. Constraints: Do not use any built-in functions that directly identify or check for perfect squares.
def is_perfect_square(n): """ Checks if a given integer n is a perfect square. """ if n < 0: return False root = int(n**0.5) return root*root == n def filter_perfect_squares(lst): """ Returns a list of perfect squares from the original list of integers. """ return [x for...
from solution import is_perfect_square, filter_perfect_squares def test_is_perfect_square(): assert is_perfect_square(0) == True assert is_perfect_square(1) == True assert is_perfect_square(4) == True assert is_perfect_square(9) == True assert is_perfect_square(16) == True assert is_perfect_squ...
[ { "docstring": "Checks if a given integer n is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Returns a list of perfect squares from the original list of integers.", "function_decla...
[ 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(n):\n \"\"\"\n This function checks if a number n is a perfect square.\n \"\"\"\n if n < 0:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000534", "row_id": 534, "seed_ids": "[43790]" }
0.652324
Evol_534
I
[ "is_perfect_square", "filter_perfect_squares" ]
2
[ [ "filter_perfect_squares", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0773941f77a101b9c78283513e401b30bae37aca
1c8e9249c401201bf36374eadbf2c8241ef821af
v1.0
instruct
Evol
Evol_577_I
Write a function that takes a list of integers and returns a new list containing only the prime numbers from the input list. Ensure the function handles negative numbers and zero correctly by excluding them, and validate input to handle non-numeric data. def filter_primes(input_list):
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...
import pytest from solution import filter_primes def test_filter_primes_with_positive_numbers(): assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_negative_numbers_and_zero(): assert filter_primes([-10, -5, 0, 1, 2, 3, 11]) == [2, 3, 11] def test_filter_primes_...
[ { "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 input list.\nExcludes negative numbers, zero, and...
[ 0, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is a prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000577", "row_id": 577, "seed_ids": "[25105]" }
0.647364
Evol_577
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a61ca6d07ad6945252a2c6bbd6d1205f562dd64b
eaca01ceebf50061cec4d11c022f13e0cb8c0f18
v1.0
instruct
Evol
Evol_605_I
Write a function to determine if two strings are anagrams of each other. Two strings are anagrams if they are made up of the same characters with the same frequencies, but in a different order. Your solution should be case-insensitive and should ignore spaces and punctuation. Additionally, provide a second version of y...
import string def clean_string(s): """ Cleans the input string by removing spaces, punctuation, and converting to lowercase. """ return ''.join(e for e in s if e.isalnum()).lower() def are_anagrams(s1, s2): """ Determines if two strings are anagrams of each other, ignoring case, spaces, and pu...
from solution import are_anagrams, are_anagrams_strict def test_are_anagrams(): assert are_anagrams("The eyes", "They see") assert are_anagrams("A gentleman", "Elegant man") assert are_anagrams("Hello, World!", "world Hello!") assert are_anagrams("Dormitory", "Dirty room") assert are_anagrams("Dorm...
[ { "docstring": "Cleans the input string by removing spaces, punctuation, and converting to lowercase.", "function_declaration": "def clean_string(s):", "function_name": "clean_string", "parameter_list": "(s)" }, { "docstring": "Determines if two strings are anagrams of each other, ignoring c...
[ 1, 0, 0, 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": "import re\nfrom collections import Counter\n\ndef clean_string(s):\n \"\"\"\n Helper function to clean the string by removing spaces, punctuations,\n and ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000605", "row_id": 605, "seed_ids": "[46181]" }
0.615016
Evol_605
I
[ "clean_string", "are_anagrams", "are_anagrams_strict" ]
3
[ [ "are_anagrams", "clean_string" ], [ "are_anagrams_strict", "clean_string" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e3ec00befd8a4b91479aa74687eceb99eddc06f2
614d8dcde6b7d9d99adec85d91c6526cf5c59c58
v1.0
instruct
Evol
Evol_626_I
Implement a function to detect and correct spelling mistakes in a given list of words using a Trie data structure. Your function should take a dictionary of correctly spelled words as input to build the Trie and then identify and suggest corrections for words in the list that are not in the dictionary. Suggest correcti...
class TrieNode: def __init__(self): self.children = {} self.is_end_of_word = False class Trie: def __init__(self): self.root = TrieNode() def insert(self, word): node = self.root for char in word: if char not in node.children: node.ch...
from solution import correct_spelling def test_correct_spelling_no_mistakes(): dictionary = ["apple", "banana", "cherry"] words = ["apple", "banana"] result = correct_spelling(words, dictionary) assert result == ["apple", "banana"] def test_correct_spelling_single_typo(): dictionary = ["apple", "b...
[]
[ 1, 0, 0, 0, 0, 0, 1, 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": "# We will implement a TrieNode, a Trie, and a function to find the closest word using Levenshtein distance.\n\nclass TrieNode:\n def __init__(self):\n se...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000626", "row_id": 626, "seed_ids": "[24301]" }
0.483899
Evol_626
I
[ "levenshtein_distance", "correct_spelling" ]
2
[ [ "correct_spelling", "levenshtein_distance" ] ]
1
[]
false
[ "TrieNode", "Trie" ]
true
pytest
true
[]
true
11378b0bd7ad0909af470b07e12ce1838ed670d8
c9c431388a350c5648f8ced6babde615d3d07c35
v1.0
instruct
Evol
Evol_661_I
Design a procedure, employing a programming language of your choice, to evaluate and display all palindromic substrings present within a specified string, such as "racecar".
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def palindromic_substrings(string): """ Finds and returns all palindromic substrings in a given string. """ n = len(string) palindromes = [] for i in range(n): #...
from solution import palindromic_substrings, is_palindrome def test_single_character(): assert palindromic_substrings("a") == ["a"] def test_no_palindromic_substring(): assert palindromic_substrings("abc") == ["a", "b", "c"] def test_all_same_characters(): assert palindromic_substrings("aaa") == ["a", "a...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Finds and returns all palindromic substrings in a given string.", "function_declarat...
[ 0, 0, 0, 0, 1, 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_palindrome(s):\n \"\"\"\n Checks if a given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palindromic_substrings(s):\n \"\"...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000661", "row_id": 661, "seed_ids": "[20596]" }
0.64979
Evol_661
I
[ "is_palindrome", "palindromic_substrings" ]
2
[ [ "palindromic_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fcd6adc016b4df31d666626b6417d9e25e68a08
ee9e2128aea9d76f761b8f4d8e9f85c6812684c9
v1.0
instruct
Evol
Evol_674_I
Implement a system to read a large text file and determine the frequency of each word in the file. You are to consider words in a case-insensitive manner and ignore all punctuation. The input text file could be several gigabytes in size, so your solution should be optimized for performance and memory usage. Your task ...
import os import string from collections import defaultdict, Counter import matplotlib.pyplot as plt def process_chunk(text): """ Normalizes the text by converting to lowercase and removing punctuation. Returns a list of words. """ translator = str.maketrans('', '', string.punctuation) return t...
from solution import process_chunk, count_word_frequencies, get_top_n_words, plot_word_frequencies def test_process_chunk(): assert process_chunk("Hello, world! This is a test.") == ['hello', 'world', 'this', 'is', 'a', 'test'] assert process_chunk("Python's flexibility & simplicity!") == ['pythons', 'flexibil...
[ { "docstring": "Normalizes the text by converting to lowercase and removing punctuation.\nReturns a list of words.", "function_declaration": "def process_chunk(text):", "function_name": "process_chunk", "parameter_list": "(text)" }, { "docstring": "Reads the file in chunks, normalizes the te...
[ 0, 0, 0, 0, 1, 0, 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 string\nfrom collections import Counter\nimport matplotlib.pyplot as plt\n\ndef word_frequency(file_path, chunk_size=1024*1024):\n \"\"\"\n Reads a la...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00000674", "row_id": 674, "seed_ids": "[42696]" }
0.695025
Evol_674
I
[ "process_chunk", "count_word_frequencies", "get_top_n_words", "plot_word_frequencies" ]
4
[ [ "count_word_frequencies", "process_chunk" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
72fb0926513c92737a5d952c0d80b1c7bda9806c
e1b9e2150d3e24d66bdfe1baa96c239dfaf0b3e0
v1.0
instruct
Evol
Evol_702_I
Write a function that takes an integer `n` and returns a list of all prime numbers up to and including `n`. Do not use any built-in libraries for checking prime numbers, and implement the function from scratch.
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 prime_numbers_up_to_n def test_primes_up_to_10(): assert prime_numbers_up_to_n(10) == [2, 3, 5, 7] def test_primes_up_to_1(): assert prime_numbers_up_to_n(1) == [] def test_primes_up_to_2(): assert prime_numbers_up_to_n(2) == [2] def test_primes_up_to_3(): assert prime_numbers_u...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers up to and including n.", "function_declaration": "def prime_numbers_up_to_n(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(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000702", "row_id": 702, "seed_ids": "[5067]" }
0.699818
Evol_702
I
[ "is_prime", "prime_numbers_up_to_n" ]
2
[ [ "prime_numbers_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb904098f685fca408f0bb0a4318d577b341464e
433b0551b45f86ffb9d80ea5819b8e593a88c9b4
v1.0
instruct
Evol
Evol_728_I
Given a list of integers, implement both the quicksort algorithm and the merge sort algorithm. Compare their efficiencies by analyzing the time complexities and suggesting which algorithm will perform better on average for large datasets. Correct any errors you might find in the following code snippets for both sorting...
def partition(arr, low, high): i = (low-1) pivot = arr[high] for j in range(low, high): if arr[j] < pivot: i = i+1 arr[i], arr[j] = arr[j], arr[i] arr[i+1], arr[high] = arr[high], arr[i+1] return (i+1) def quickSort(arr, low, high): if low < high: pi = pa...
from solution import quickSort, mergeSort, compare_efficiency def test_quickSort(): arr = [3, 7, 8, 5, 2, 1, 9, 5, 4] quickSort(arr, 0, len(arr)-1) assert arr == [1, 2, 3, 4, 5, 5, 7, 8, 9] def test_mergeSort(): arr = [3, 7, 8, 5, 2, 1, 9, 5, 4] mergeSort(arr, 0, len(arr)-1) assert arr == [1, ...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickSort(arr, low, high):", "function_name": "quickSort", "parameter_list": "(ar...
[ 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 partition(arr, low, high):\n i = (low-1)\n pivot = arr[high]\n for j in range(low, high):\n if arr[j] < pivot:\n i = i+1\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000728", "row_id": 728, "seed_ids": "[26417]" }
0.482332
Evol_728
I
[ "partition", "quickSort", "merge", "mergeSort", "compare_efficiency" ]
5
[ [ "mergeSort", "merge" ], [ "quickSort", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
41ee82ed569e2ca65aee1e20d1656e01e5c2f948
a5045024aa626ca44975eb53809bca3bcbce1f88
v1.0
instruct
Evol
Evol_730_I
Write a function that calculates the next date given a date string in the format "DD-MM-YYYY". Ensure your function takes into account leap years and the varying number of days in each month. For example, given the input "28-02-2020", the output should be "29-02-2020" and for "31-12-2021", the output should be "01-01-2...
def is_leap_year(year): """ Check if a given year is a leap year. """ return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) def next_date(date_str): """ Calculate the next date given a date string in the format "DD-MM-YYYY". """ days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 3...
from solution import next_date def test_next_date_simple_cases(): assert next_date("01-01-2022") == "02-01-2022" assert next_date("28-02-2021") == "01-03-2021" assert next_date("31-03-2021") == "01-04-2021" assert next_date("30-04-2021") == "01-05-2021" assert next_date("31-12-2021") == "01-01-2022...
[ { "docstring": "Check if a given year is a leap year.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Calculate the next date given a date string in the format \"DD-MM-YYYY\".", "function_declaration": "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 is_leap_year(year):\n \"\"\"Checks if a year is a leap year.\"\"\"\n return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)\n\ndef next_date(date_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000730", "row_id": 730, "seed_ids": "[33172]" }
0.621863
Evol_730
I
[ "is_leap_year", "next_date" ]
2
[ [ "next_date", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9229cb9b17a8f091bc94fd597d1d87edf265f89
7eed6bcce22da4098b4e25de5046086d02dc1c40
v1.0
instruct
Evol
Evol_732_I
Write a Python function that takes a list of integers and returns a new list containing only the prime numbers from the input list. Then, using this function, filter the prime numbers from the list `[12, 15, 7, 5, 8, 17]` and display the resulting list in the console. Make sure to include necessary helper functions for...
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def filter_primes(lst): """ Filter prime numbers from the input list. """ return ...
from solution import is_prime, filter_primes def test_is_prime_with_primes(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True assert is_prime(11) == True def test_is_prime_with_non_primes(): assert is_prime(1) == False assert is_p...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Filter prime numbers from the input list.", "function_declaration": "def filter_primes(lst):", "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(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n retu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000732", "row_id": 732, "seed_ids": "[2316]" }
0.620414
Evol_732
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb872a9ebcbab8a5c030fcc684ad1e9e149235fc
f10cda82f40824331c390efd7a0b00b8f861f562
v1.0
instruct
Evol
Evol_747_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 the function handles edge cases, such as an empty list or a list with no prime numbers, appropriately. ### Example ```python # Input find_primes([2, 3, 4, 5, 6, 7, 8, 9, 10...
def is_prime(n): """ Determines if a number n is prime. """ if n <= 1: return False if n in (2, 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 find_primes def test_find_primes_example_cases(): assert find_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] assert find_primes([15, 18, 21, 24]) == [] assert find_primes([]) == [] def test_find_primes_with_negative_numbers(): assert find_primes([-1, -2, -3, 2, 3, 5]) == [2,...
[ { "docstring": "Determines if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the original list.", "function_declaration": "def find_primes(lst):", "functio...
[ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000747", "row_id": 747, "seed_ids": "[24019]" }
0.657404
Evol_747
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fffe4f391fe72a4aa4c55304bc4ff8f2750e904f
384548de38db1fa1170287e9694a99769e51db3a
v1.0
instruct
Evol
Evol_756_I
Write a function to solve the N-Queens problem. The N-Queens problem involves placing N queens on an N x N chessboard in such a way that no two queens threaten each other. Your implementation should return all distinct solutions to the N-Queens puzzle, and each solution should be a permutation of the columns where the...
def solve_n_queens(n): """ Solves the N-Queens problem and returns a list of solutions. Each solution is represented as a list of strings. """ def is_valid(board, row, col): for i in range(row): # Check the column if board[i] == col: return False ...
from solution import solve_n_queens, validate_solutions def test_solve_n_queens_n1(): solutions = solve_n_queens(1) expected = [["Q"]] assert solutions == expected assert validate_solutions(1, [[0]]) def test_solve_n_queens_n2(): solutions = solve_n_queens(2) expected = [] assert solutions...
[ { "docstring": "Solves the N-Queens problem and returns a list of solutions. \nEach solution is represented as a list of strings.", "function_declaration": "def solve_n_queens(n):", "function_name": "solve_n_queens", "parameter_list": "(n)" }, { "docstring": "Converts the list of solutions f...
[ 1, 0, 0, 0, 1, 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 solve_n_queens(n):\n \"\"\"\n Solves the N-Queens problem and returns all distinct solutions.\n Each solution is represented by a list of strings wher...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000756", "row_id": 756, "seed_ids": "[36956]" }
0.579998
Evol_756
I
[ "solve_n_queens", "convert_solutions_to_strings", "validate_solutions" ]
3
[ [ "solve_n_queens", "convert_solutions_to_strings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a4fe8a871fd2b49637c5b2d8f559cc0e58b2a50
341e3f7fb1e401a0ce26d977cc3a318089d59cd1
v1.0
instruct
Evol
Evol_760_I
Given a list of integers, write a function to identify and return the subarray with the maximum sum. If there are multiple subarrays with the same maximum sum, return the one that appears latest in the list. Additionally, provide a helper function to ensure the input list is non-empty and does not contain nested lists....
def validate_input(lst): if not lst: raise ValueError("Input list must not be empty") if not all(isinstance(i, int) for i in lst): raise ValueError("Input list must only contain integers") def max_subarray(lst): validate_input(lst) max_sum = float('-inf') current_sum = 0 end = s...
from solution import max_subarray, validate_input def test_max_subarray_positive(): assert max_subarray([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_max_subarray_mixed(): assert max_subarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == [4, -1, 2, 1] def test_max_subarray_single_element(): assert max_subarray([5])...
[ { "docstring": null, "function_declaration": "def validate_input(lst):", "function_name": "validate_input", "parameter_list": "(lst)" }, { "docstring": null, "function_declaration": "def max_subarray(lst):", "function_name": "max_subarray", "parameter_list": "(lst)" } ]
[ 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 validate_input(lst):\n \"\"\"\n Validates that the input list is non-empty and does not contain nested lists.\n \"\"\"\n if not isinstance(lst, lis...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000760", "row_id": 760, "seed_ids": "[8364]" }
0.741894
Evol_760
I
[ "validate_input", "max_subarray" ]
2
[ [ "max_subarray", "validate_input" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f960a0f0872b3e799385b053cc764216ed720530
6f1132d7435487d22e8c544e7d5c09a4826ea9d0
v1.0
instruct
Evol
Evol_775_I
Develop a function in Python to implement a simple genetic algorithm based on the following specifications: ```python import random # Sample dataset target = "HELLO, WORLD!" population_size = 200 mutation_rate = 0.01 generations = 1000 # Genetic Algorithm functions def create_individual(length): # Create random ...
import random # Sample dataset target = "HELLO, WORLD!" population_size = 200 mutation_rate = 0.01 generations = 1000 # Genetic Algorithm functions def create_individual(length): # Create random individual with given length return ''.join(random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ, !") for _ in range(length)) ...
from solution import create_individual, calculate_fitness, mutate, crossover, genetic_algorithm def test_create_individual(): individual = create_individual(10) assert len(individual) == 10 assert all(char in "ABCDEFGHIJKLMNOPQRSTUVWXYZ, !" for char in individual) def test_calculate_fitness(): assert ...
[ { "docstring": null, "function_declaration": "def create_individual(length):", "function_name": "create_individual", "parameter_list": "(length)" }, { "docstring": null, "function_declaration": "def calculate_fitness(individual):", "function_name": "calculate_fitness", "parameter...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import random\n\n# Parameters for the Genetic Algorithm\ntarget = \"HELLO, WORLD!\"\npopulation_size = 200\nmutation_rate = 0.01\ngenerations = 1000\n\n# Genetic A...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000775", "row_id": 775, "seed_ids": "[18683]" }
0.4714
Evol_775
I
[ "create_individual", "calculate_fitness", "mutate", "crossover", "genetic_algorithm" ]
5
[ [ "genetic_algorithm", "calculate_fitness" ], [ "genetic_algorithm", "create_individual" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "mutate" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2bfd9aa2580902dabe1748f9204cfb7f47b51945
742a5fe8d62d5015d45e91cd4520025823a9b558
v1.0
instruct
Evol
Evol_792_I
Create a function in Python that takes an integer `n` as input and returns a list of the prime numbers less than `n`. Ensure that your function is optimized for performance, using appropriate algorithms to minimize time complexity. Additionally, provide a piece of erroneous sample code relating to this task and a corre...
def sieve_of_eratosthenes(n): """ Returns a list of prime numbers less than n using the Sieve of Eratosthenes algorithm. """ if n <= 2: return [] sieve = [True] * n sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers for start in range(2, int(n**0.5) + 1): ...
from solution import sieve_of_eratosthenes, erroneous_prime_list, corrected_prime_list def test_sieve_of_eratosthenes_basic(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] def test_sieve_of_eratosthenes_edge_case(): assert sieve_of_eratosthenes(0) == [] assert sieve_of_eratosthenes(1) == [] assert...
[ { "docstring": "Returns a list of prime numbers less than n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Erroneous method to return list of prime numb...
[ 1, 1, 1, 0, 1, 1, 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 sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers less than n.\n \"\"\"\n if n <= 2:\n return []\n \n prime = [...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000792", "row_id": 792, "seed_ids": "[3763]" }
0.671324
Evol_792
I
[ "sieve_of_eratosthenes", "erroneous_prime_list", "corrected_prime_list" ]
3
[ [ "corrected_prime_list", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abd64795e88d799ded2fbb8f29dc053eeef15294
7fe87d13996bc8282a44bd205b318c115e78cc87
v1.0
instruct
Evol
Evol_841_I
Write a function that accepts a list of integers and returns a list of the same integers but with all prime numbers replaced by their immediate next higher prime number. This task requires a good understanding of both prime number validation and list manipulation: def replace_with_next_prime(lst): """ This fun...
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def next_prim...
from solution import replace_with_next_prime, is_prime, next_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(17) == True assert is_prime(18) == False def test_next_prime(): assert next_...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Helper function to find the next prime number greater than n.", "function_declaration": "def next_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 check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00000841", "row_id": 841, "seed_ids": "[47820]" }
0.649166
Evol_841
I
[ "is_prime", "next_prime", "replace_with_next_prime" ]
3
[ [ "next_prime", "is_prime" ], [ "replace_with_next_prime", "is_prime" ], [ "replace_with_next_prime", "next_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
08d580f8a695c44aba2a8d2e8af35eac2302adbd
f747db1d025c6d9a5455a8548a26022994b346f3
v1.0
instruct
Evol
Evol_848_I
Write a function that takes a list of integers and returns a new list containing only the prime numbers from the given list. Implement the prime-checking function as a helper function within your main function. Optimize the solution to minimize the number of divisibility checks.
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False limit = int(n ** 0.5) + 1 for i in range(3, limit, 2): if n % i == 0: return False return True def g...
from solution import get_primes def test_get_primes_with_no_primes(): assert get_primes([1, 4, 6, 8, 9, 10, 12]) == [] def test_get_primes_with_all_primes(): assert get_primes([2, 3, 5, 7, 11, 13, 17]) == [2, 3, 5, 7, 11, 13, 17] def test_get_primes_with_mixed_values(): assert get_primes([10, 11, 12, 13,...
[ { "docstring": "Checks 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 prime numbers from the given list.", "function_declaration": "def get_primes(numbers):", "func...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_1_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\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000848", "row_id": 848, "seed_ids": "[14027]" }
0.614677
Evol_848
I
[ "is_prime", "get_primes" ]
2
[ [ "get_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2588b6a9b1ed3d6a1fa31de5a8443738a98af1fa
6413d73c8c6a210b30600314ac43b2f7509bb18e
v1.0
instruct
Evol
Evol_855_I
Create a Python function that takes an unsorted list of integers and returns a new list containing only the prime numbers from the input list, sorted in ascending order. Implement a helper function to determine if a number is prime. Use efficient algorithms to handle large lists and numbers, ensuring the solution remai...
import math def is_prime(n): """ Determines if the given 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...
from solution import is_prime, filter_and_sort_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False assert is_prime(1...
[ { "docstring": "Determines if the given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters the prime numbers from the input list and returns them sorted in ascending order.", "function_...
[ 1, 1, 0, 1, 1, 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": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000855", "row_id": 855, "seed_ids": "[39939]" }
0.703944
Evol_855
I
[ "is_prime", "filter_and_sort_primes" ]
2
[ [ "filter_and_sort_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1c8992041c54b57bdd8c91f882f663ea5a25f7fe
a36843c359eafee36067054c7d2dbee0ec44e20d
v1.0
instruct
Evol
Evol_860_I
Write a function to determine if a given string can be rearranged to form a palindrome. The function should return `True` if it is possible and `False` otherwise. After that, extend your function to consider if the given string can be rearranged to form a palindrome by removing at most one character. Demonstrate the fu...
from collections import Counter def can_form_palindrome(s): """ Determines if a given string can be rearranged to form a palindrome. """ count = Counter(s) odd_count = sum(1 for cnt in count.values() if cnt % 2 != 0) return odd_count <= 1 def can_form_palindrome_with_removal(s): """ De...
from solution import can_form_palindrome, can_form_palindrome_with_removal def test_can_form_palindrome(): assert can_form_palindrome("civic") == True assert can_form_palindrome("ivicc") == True assert can_form_palindrome("hello") == False assert can_form_palindrome("aabb") == True assert can_form_...
[ { "docstring": "Determines if a given string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if a given string can be rearranged to form a palindrome...
[ 0, 0, 1, 1, 1, 0, 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 can_form_palindrome(s):\n \"\"\"\n Checks if a given string can be rearranged to form a palindrome.\n \"\"\"\n from collections import Counter\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000860", "row_id": 860, "seed_ids": "[34241]" }
0.75712
Evol_860
I
[ "can_form_palindrome", "can_form_palindrome_with_removal" ]
2
[ [ "can_form_palindrome_with_removal", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
62a5b813c18eaa1dbc48779f7a7d28832b4d2af0
a7101374eae3e2170e5a6c97ba33dd3e8013f647
v1.0
instruct
Evol
Evol_879_I
Write a function that calculates the sum of all prime numbers up to and including a given number `n`. If the input is invalid (e.g., not a positive integer), the function should return 0. You are not allowed to use any external libraries or built-in functions for this task. Ensure your solution is efficient. ```python...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num == 2: return True # 2 is the only even prime number if num % 2 == 0: return False # Check for factors from 3 to sqrt(num), using step of 2 to skip even num...
from solution import sum_of_primes def test_sum_of_primes_with_small_number(): assert sum_of_primes(10) == 17 def test_sum_of_primes_with_large_number(): assert sum_of_primes(20) == 77 def test_sum_of_primes_with_negative_number(): assert sum_of_primes(-5) == 0 def test_sum_of_primes_with_non_integer():...
[ { "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 the sum of all prime numbers up to and including 'n'.\nReturns 0 if the input is not a positive...
[ 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 sum_of_primes(n):\n if not isinstance(n, int) or n < 2:\n return 0\n\n def is_prime(num):\n if num <= 1:\n return False\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000879", "row_id": 879, "seed_ids": "[1941]" }
0.671957
Evol_879
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d925da5668538df68f427254ef5a5bc50336b7af
cb7e723530f173c8c75432d1da640c030cf355c5
v1.0
instruct
Evol
Evol_931_I
Design and implement a Binary Search algorithm that operates on a descendingly sorted list of integers. The function should take a list and a target integer as inputs and return the index of the target integer if found, or -1 if not found. Assess the performance of your Binary Search algorithm by comparing it to a line...
def binary_search_desc(arr, target): """ Performs a binary search on a descendingly sorted list of integers. Returns the index of target if found, otherwise returns -1. """ left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: ...
from solution import binary_search_desc, linear_search def test_binary_search_found(): arr = [15, 10, 5, 3, 1] target = 10 assert binary_search_desc(arr, target) == 1 def test_binary_search_not_found(): arr = [20, 17, 15, 12, 10, 8, 6, 4, 2] target = 7 assert binary_search_desc(arr, target) ==...
[ { "docstring": "Performs a binary search on a descendingly sorted list of integers.\nReturns the index of target if found, otherwise returns -1.", "function_declaration": "def binary_search_desc(arr, target):", "function_name": "binary_search_desc", "parameter_list": "(arr, target)" }, { "do...
[ 0, 1, 1, 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 binary_search_desc(arr, target):\n \"\"\"\n Performs binary search on a descendingly sorted list.\n \n :param arr: List[int], a list of integers so...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000931", "row_id": 931, "seed_ids": "[9363]" }
0.639766
Evol_931
I
[ "binary_search_desc", "linear_search", "performance_test" ]
3
[ [ "performance_test", "binary_search_desc" ], [ "performance_test", "linear_search" ] ]
2
[]
false
[]
false
pytest
true
[]
true
922e1c9a6c173a98ec955d4df7e4daed20f96ec7
91e7793204f2a83798a5d8f74d51bd22ca607b63
v1.0
instruct
Evol
Evol_938_I
Write a Python function that takes a list of integers and returns a new list with the integers sorted in ascending order, but with all prime numbers appearing before non-prime numbers. Example: - Input: [3, 8, 5, 2, 11, 4] - Output: [2, 3, 5, 11, 4, 8] Note: To check if a number is prime, you can create a helper func...
def is_prime(n): """ Check if a number is a prime number. Returns True if n is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) =...
from solution import is_prime, sort_with_primes_first def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False assert is_prime(2...
[ { "docstring": "Check if a number is a prime number.\nReturns True if n is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a new list with\nthe integers sorted i...
[ 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 sqrt\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, and False otherwise.\n \"\"\"\n if n <= 1:\n return Fa...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000938", "row_id": 938, "seed_ids": "[46757]" }
0.680813
Evol_938
I
[ "is_prime", "sort_with_primes_first" ]
2
[ [ "sort_with_primes_first", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fbac67adc6a6ad82b3afcf2b2d63e503a9b633d6
d4fae67fb8563c7e7cfe0aa927d87038b3e0a117
v1.0
instruct
Evol
Evol_945_I
Write a Python function that, given a list of integers, returns a new list containing only the prime numbers from the original list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Avoid using built-in functions or libraries specifically designed to identify prime number...
def is_prime(n): """ Determines if a number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Returns a new list containing only the prime numbers from the origi...
from solution import filter_primes, is_prime def test_is_prime(): assert not is_prime(1) # 1 is not prime assert is_prime(2) # 2 is prime assert is_prime(3) # 3 is prime assert not is_prime(4) # 4 is not prime assert is_prime(7) # 7 is prime assert not is_prime(9) # 9 is not p...
[ { "docstring": "Determines 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 filter_primes...
[ 0, 1, 1, 1, 1, 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": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, n):\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000945", "row_id": 945, "seed_ids": "[45582]" }
0.727738
Evol_945
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f8be4472efbc58a5a428ea098c217abc9bb89b5b
9d4fb29f5f307b1db4f1088d418e528c83e79856
v1.0
instruct
Evol
Evol_973_I
Create a function `find_winning_moves(board)` that evaluates the current state of a Tic-Tac-Toe board represented as a 3x3 list of lists and returns all possible winning moves for the "X" player. Assume that "X" is always the next player to move, "O" represents the opponent, and empty spots are denoted by an empty stri...
def check_win(board, player, row, col): """ Helper function to check if placing a player's mark at the position (row, col) would result in a win. """ test_board = [row.copy() for row in board] test_board[row][col] = player # Check row if all(cell == player for cell in test_board[row]): ...
from solution import find_winning_moves def test_winning_move_in_row(): board = [ ["X", "X", ""], ["O", "O", ""], ["", "O", "X"] ] assert find_winning_moves(board) == [(0, 2)] def test_winning_move_in_column(): board = [ ["X", "O", ""], ["X", "", "O"], [...
[ { "docstring": "Helper function to check if placing a player's mark at the position (row, col) would result in a win.", "function_declaration": "def check_win(board, player, row, col):", "function_name": "check_win", "parameter_list": "(board, player, row, col)" }, { "docstring": "Returns a ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def find_winning_moves(board):\n \"\"\"\n Returns a list of all winning moves for 'X' player in a given Tic-Tac-Toe board.\n \"\"\"\n winning_moves = [...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000973", "row_id": 973, "seed_ids": "[31182]" }
0.551222
Evol_973
I
[ "check_win", "find_winning_moves" ]
2
[ [ "find_winning_moves", "check_win" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f2d7f64cd05252ec4cfa4d66fab53cd4327bb6b
c15ed3f21e7309b0cc742de42fddab25dd8f78f6
v1.0
instruct
Evol
Evol_996_I
Given a list of integers and the length n, write a Python function that performs the following operations: - Create a new list that contains only the prime numbers from the given list. - Next, return the difference between the smallest prime number in the list and the largest prime number in the list. If the list doe...
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 p...
from solution import prime_diff def test_no_primes(): assert prime_diff([4, 6, 8, 10], 4) == -1 def test_mixed_numbers(): assert prime_diff([10, 15, 3, 7, 2, 8, 5], 7) == 5 def test_only_primes(): assert prime_diff([3, 2, 5, 7], 4) == 5 def test_single_prime(): assert prime_diff([3], 1) == 0 def te...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given a list lst and its length n, returns the difference between the smallest \nprime number and the large...
[ 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 a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00000996", "row_id": 996, "seed_ids": "[7179]" }
0.652845
Evol_996
I
[ "is_prime", "prime_diff" ]
2
[ [ "prime_diff", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b6d4a2d45b7892495f823b1a5c314658cc49b19
d398d10e68c0e223b8ab4c89ced85e1acc52261c
v1.0
instruct
Evol
Evol_1004_I
Write a Python function that reads a CSV file containing data on daily weather observations. Each row represents an observation with columns for 'Date', 'Temperature', 'Wind Speed', and 'Precipitation'. The function should compute and display: 1. The average temperature and wind speed for the entire dataset. 2. The da...
import csv from datetime import datetime def parse_csv(file_path): """ Reads a CSV file and returns its contents as a list of dictionaries. """ try: with open(file_path, 'r') as file: reader = csv.DictReader(file) data = [row for row in reader] return data ex...
import pytest from solution import analyze_weather_data def test_analyze_weather_data(): file_path = 'test_weather_data.csv' with open(file_path, 'w') as file: file.write("Date,Temperature,Wind Speed,Precipitation\n") file.write("2023-01-01,30.0,5.0,0.2\n") file.write("2023-01-02,25.0,6...
[ { "docstring": "Reads a CSV file and returns its contents as a list of dictionaries.", "function_declaration": "def parse_csv(file_path):", "function_name": "parse_csv", "parameter_list": "(file_path)" }, { "docstring": "Analyzes weather data from a CSV file.\n\nOutput:\n1. Average temperatu...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import csv\n\ndef analyze_weather_data(file_path):\n total_temperature = 0.0\n total_wind_speed = 0.0\n highest_temperature = float('-inf')\n highest_t...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001004", "row_id": 1004, "seed_ids": "[38051]" }
0.698893
Evol_1004
I
[ "parse_csv", "analyze_weather_data" ]
2
[ [ "analyze_weather_data", "parse_csv" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a476d5015ab24f2d42ddb01febefb0b819d7c966
c31bd28392d4c8d66b9926af9abc48cb09d9ffba
v1.0
instruct
Evol
Evol_1007_I
Generate a Python script to implement a K-means clustering algorithm from scratch. The script should be able to: - Initialize centroids randomly - Assign data points to the nearest centroid - Update centroids based on the mean of assigned data points - Repeat the above steps until centroids do not change significantly ...
import numpy as np from sklearn.datasets import load_iris from sklearn.preprocessing import StandardScaler def initialize_centroids(X, k): np.random.seed(0) indices = np.random.choice(X.shape[0], k, replace=False) return X[indices] def assign_clusters(X, centroids): distances = np.linalg.norm(X[:, np....
import numpy as np from sklearn.datasets import load_iris from sklearn.preprocessing import StandardScaler from solution import initialize_centroids, assign_clusters, update_centroids, kmeans def test_initialize_centroids(): X = np.array([[1,2], [3,4], [5,6], [7,8]]) np.random.seed(0) centroids = initializ...
[ { "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...
[ 1, 1, 1, 0, 0, 1, 0, 1, 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 numpy as np\nfrom sklearn.datasets import load_iris\n\nclass KMeans:\n def __init__(self, n_clusters, max_iter=300, tol=1e-4):\n self.n_clusters =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001007", "row_id": 1007, "seed_ids": "[29679]" }
0.669426
Evol_1007
I
[ "initialize_centroids", "assign_clusters", "update_centroids", "kmeans" ]
4
[ [ "kmeans", "assign_clusters" ], [ "kmeans", "initialize_centroids" ], [ "kmeans", "update_centroids" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy", "sklearn" ]
false
f37d64f9619c21468f785cc75468d6178da90457
d6ae8f41f75084fdbe9132561d53866da7844759
v1.0
instruct
Evol
Evol_1021_I
Design a function that takes as input a list of integers and returns a new list containing only the prime numbers from the original list. Additionally, implement a method to optimize the prime number detection process. Finally, demonstrate the efficiency of your solution with a runtime analysis comparing it to a naive ...
import math 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 ...
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(29) == True assert is_prime(49) == False def test_filter_primes(): assert filter_primes([2, 3, 4, 5...
[ { "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 input list.", "function_declaration": "def filter_prime...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the on...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001021", "row_id": 1021, "seed_ids": "[3793]" }
0.618945
Evol_1021
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d8e75dd6e38e320f33f6667ae04689f1fd6a522
58c01f5079d66dae053c6ae18daaceffaf641553
v1.0
instruct
Evol
Evol_1032_I
Write a program that determines the optimal point of convergence for three randomly positioned drones in a 2D space, represented as points with floating-point coordinates (x, y). Each drone travels at a constant speed, but potentially different from one another. Your task is to calculate the minimum time needed for al...
import numpy as np from scipy.optimize import minimize def distance(point1, point2): """ Compute the Euclidean distance between two 2D points. """ return np.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def time_to_reach(convergence_point, starting_point, speed): """ Compute th...
from solution import distance, time_to_reach, total_time, optimal_convergence def test_distance(): assert np.isclose(distance((0, 0), (3, 4)), 5.0) assert np.isclose(distance((1, 1), (4, 5)), 5.0) def test_time_to_reach(): assert np.isclose(time_to_reach((3, 4), (0, 0), 1.0), 5.0) assert np.isclose(ti...
[ { "docstring": "Compute the Euclidean distance between two 2D points.", "function_declaration": "def distance(point1, point2):", "function_name": "distance", "parameter_list": "(point1, point2)" }, { "docstring": "Compute the time it takes for a drone to reach the convergence point from its ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom scipy.optimize import minimize\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Returns the Euclidean distance between two points p1 an...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00001032", "row_id": 1032, "seed_ids": "[24397]" }
0.506231
Evol_1032
I
[ "distance", "time_to_reach", "total_time", "optimal_convergence" ]
4
[ [ "optimal_convergence", "total_time" ], [ "time_to_reach", "distance" ], [ "total_time", "time_to_reach" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
f9844bb9304f32520301bfb5709e4a1260fe0c39
35394d7ed171c2ae650dcf1c910cac50735122e2
v1.0
instruct
Evol
Evol_1075_I
Write a function that takes a list of integers as input and returns a new list containing only the prime numbers from the original list. Additionally, the function should calculate and return the mean and median of these prime numbers. If there are no prime numbers in the input list, return an empty list for the primes...
import statistics def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True def prime_numbers_with_stats(nums...
from solution import prime_numbers_with_stats def test_prime_numbers_with_stats(): assert prime_numbers_with_stats([4, 6, 7, 9, 11, 13, 15, 18, 19]) == ([7, 11, 13, 19], 12.5, 12.0) assert prime_numbers_with_stats([4, 6, 8, 9, 10, 12]) == ([], None, None) assert prime_numbers_with_stats([2, 3, 5, 7, 11]) =...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def prime_numbers_with_stats(nums):", "function_name": "prime_numbers_with_stats", "parameter_list": "(nums)" }...
[ 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": "import statistics\n\ndef is_prime(n):\n \"\"\" Checks if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001075", "row_id": 1075, "seed_ids": "[37437]" }
0.568956
Evol_1075
I
[ "is_prime", "prime_numbers_with_stats" ]
2
[ [ "prime_numbers_with_stats", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6782be32ac8f7040c2d686f63919d553ce41e233
c1c7d4b5eae73c6c2258df2f483401279e42b2d1
v1.0
instruct
Evol
Evol_1092_I
Write a program to determine the probability of rolling a sum of 7 or 11 with two six-sided dice. The program should simulate the rolling of the dice a specified number of times and calculate how often sums of 7 or 11 occur. Ensure the output includes the total number of rolls, the number of times a 7 or 11 was rolled,...
import random def roll_dice(): """ Simulate rolling two six-sided dice and return their sum. """ return random.randint(1, 6) + random.randint(1, 6) def simulate_rolls(num_rolls): """ Simulate rolling two six-sided dice num_rolls times and determine the probability of rolling a sum of 7 or...
from solution import simulate_rolls def test_simulate_rolls_with_1000(): result = simulate_rolls(1000) assert result[0] == 1000 assert 0 <= result[1] <= 1000 assert 0 <= result[2] <= 1 def test_simulate_rolls_with_5000(): result = simulate_rolls(5000) assert result[0] == 5000 assert 0 <= r...
[ { "docstring": "Simulate rolling two six-sided dice and return their sum.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulate rolling two six-sided dice num_rolls times and \ndetermine the probability of rolling a sum...
[ 0, 0, 0, 0, 1, 0, 0, 1, 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 random\n\ndef roll_dice(num_rolls):\n \"\"\"\n Simulates rolling two six-sided dice a specified number of times and calculates the probability \n o...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001092", "row_id": 1092, "seed_ids": "[45382]" }
0.560002
Evol_1092
I
[ "roll_dice", "simulate_rolls" ]
2
[ [ "simulate_rolls", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f30ad9424a89c318d63711c5c2757ccac9c6bca
72127b088889e8d0733f095735a48f71789cdf75
v1.0
instruct
Evol
Evol_1157_I
Create a Python program that reads a list of student records from a text file and performs various operations on the data. Each student record consists of a name, ID, and a list of grades. The file format is as follows, with each student record on a separate line: ``` John Doe, 21, 90, 85, 92 Jane Smith, 22, 88, 79, 8...
def read_records(file_path): """ Reads student records from a text file and returns a list of dictionaries. :param file_path: Path to the input file :return: List of student records as dictionaries """ students = [] with open(file_path, 'r') as file: for line in file: ...
import pytest from solution import ( read_records, get_student_average, get_average_grades, get_highest_scorer, ) @pytest.fixture def dummy_data(tmp_path): data = """John Doe, 21, 90, 85, 92 Jane Smith, 22, 88, 79, 85 Alice Johnson, 23, 95, 92, 98""" file_path = tmp_path / "students.txt" fi...
[ { "docstring": "Reads student records from a text file and returns a list of dictionaries.\n\n:param file_path: Path to the input file\n:return: List of student records as dictionaries", "function_declaration": "def read_records(file_path):", "function_name": "read_records", "parameter_list": "(file...
[ 1, 0, 0, 0, 1, 1, 0, 1, 0 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def read_records(file_path):\n \"\"\"\n Reads student records from a text file and returns a list of dictionaries, \n where each dictionary represents a s...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001157", "row_id": 1157, "seed_ids": "[25220]" }
0.696809
Evol_1157
I
[ "read_records", "get_student_average", "get_average_grades", "get_highest_scorer" ]
4
[ [ "get_average_grades", "get_student_average" ], [ "get_highest_scorer", "get_student_average" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2e3b09f1de0a63cbbfbf73cc30cc5ce15c8e5762
83455027bbe2e732619ef691451a41c71bef3fa0
v1.0
instruct
Evol
Evol_1175_I
Build a Python application that reads a text file containing a list of numbers (one number per line) and calculates the median of these numbers. If the list has an odd number of elements, the median is the middle element. If it has an even number of elements, the median is the average of the two middle elements. The ap...
import os def read_numbers_from_file(file_path): """ Reads a list of numbers from a specified file. The file should contain one number per line. Returns the list of numbers. """ if not os.path.isfile(file_path): raise FileNotFoundError("The specified file does not exist.") numbers ...
import pytest from solution import read_numbers_from_file, calculate_median, find_median_from_file def test_read_numbers_from_file_valid(): with open('test_valid.txt', 'w') as f: f.write('1\n2\n3\n4\n5\n6\n7\n8\n9\n10') assert read_numbers_from_file('test_valid.txt') == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...
[ { "docstring": "Reads a list of numbers from a specified file.\nThe file should contain one number per line.\nReturns the list of numbers.", "function_declaration": "def read_numbers_from_file(file_path):", "function_name": "read_numbers_from_file", "parameter_list": "(file_path)" }, { "docs...
[ 1, 0, 1, 0, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import os\n\ndef read_numbers_from_file(filename):\n \"\"\"\n Reads a list of numbers from a specified file.\n \n Returns a list of numbers or raises a...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001175", "row_id": 1175, "seed_ids": "[6485]" }
0.744844
Evol_1175
I
[ "read_numbers_from_file", "calculate_median", "find_median_from_file" ]
3
[ [ "find_median_from_file", "calculate_median" ], [ "find_median_from_file", "read_numbers_from_file" ] ]
2
[]
false
[]
false
pytest
true
[]
true
015cef406166c88c3ac9a1615bababf93b0fb87a
a3140558a02d201cd24ed26bc712acce7bf88524
v1.0
instruct
Evol
Evol_1214_I
Write a Python function that accepts a list of sentences and returns a list of the lengths of the shortest and longest words in each sentence. Use multiprocessing to handle multiple sentences concurrently to optimize performance. The function should handle punctuation and special characters gracefully. Note: Each proc...
import multiprocessing import re def word_lengths(sentence): words = re.findall(r'\b\w+\b', sentence) if not words: return (0, 0) else: lengths = [len(word) for word in words] return (min(lengths), max(lengths)) def process_sentences(sentences_list): with multiprocessing.Pool(p...
from solution import word_lengths, process_sentences def test_word_lengths(): # Test for a sentence with varied word lengths assert word_lengths("The quick brown fox jumps over the lazy dog") == (3, 5) # Test for a sentence with punctuation assert word_lengths("To be, or not to be, that is the question...
[ { "docstring": null, "function_declaration": "def word_lengths(sentence):", "function_name": "word_lengths", "parameter_list": "(sentence)" }, { "docstring": null, "function_declaration": "def process_sentences(sentences_list):", "function_name": "process_sentences", "parameter_l...
[ 1, 0, 1, 0, 0, 0, 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 multiprocessing import Pool\n\ndef word_lengths(sentence):\n \"\"\"\n Function to calculate the length of shortest and longest words in the g...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001214", "row_id": 1214, "seed_ids": "[9354]" }
0.66081
Evol_1214
I
[ "word_lengths", "process_sentences" ]
2
[ [ "process_sentences", "word_lengths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
682958dba68a8152349381bc9ce1bc98bd2ed1e0
525d903b24be513c8281d9bf90ad8268b38b8ec6
v1.0
instruct
Evol
Evol_1218_I
Write a function that takes a list of integers and returns the same list with all prime numbers filtered out. You are not allowed to use any external libraries or built-in functions that directly identify or filter prime numbers. Example: Input: numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Expected output: [1, 4, 6, 8...
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 filter_non_primes # Helper function to check if a number is prime should not be tested directly # Tests to validate the filter_non_primes function def test_filter_non_primes_with_primes(): assert filter_non_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 4, 6, 8, 9, 10] def test_filter_non_pr...
[ { "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 integers with all prime numbers filtered out.", "function_declaration": "def filt...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001218", "row_id": 1218, "seed_ids": "[19305]" }
0.635294
Evol_1218
I
[ "is_prime", "filter_non_primes" ]
2
[ [ "filter_non_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a727f7ac03155b23940ffa22cb915370d68f4829
837b6e229ad6a0390927a6e01a67988f4a15f805
v1.0
instruct
Evol
Evol_1250_I
Given the frequency of fraudulent activities in credit card transactions, developing a reliable detection system is crucial. Implement a Python script using Scikit-learn to build a binary classification model based on the random forest algorithm to detect fraudulent transactions. The dataset you use should be preproces...
import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split, cross_val_score from sklearn.preprocessing import StandardScaler from sklearn.metrics import confusion_matrix from sklearn.impute import SimpleImputer def preprocess_data(df): # Handling mi...
import pandas as pd import numpy as np from solution import preprocess_data, train_random_forest, evaluate_model from sklearn.datasets import make_classification def generate_dummy_data(): # Generate a dummy dataset for testing X, y = make_classification(n_samples=1000, n_features=20, n_classes=2, random_state...
[ { "docstring": null, "function_declaration": "def preprocess_data(df):", "function_name": "preprocess_data", "parameter_list": "(df)" }, { "docstring": null, "function_declaration": "def train_random_forest(df, target):", "function_name": "train_random_forest", "parameter_list": ...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "import pandas as pd\nfrom sklearn.model_selection import train_test_split, cross_val_score\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.prepr...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00001250", "row_id": 1250, "seed_ids": "[44600]" }
0.324374
Evol_1250
I
[ "preprocess_data", "train_random_forest", "evaluate_model" ]
3
[ [ "evaluate_model", "preprocess_data" ], [ "train_random_forest", "preprocess_data" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "pandas", "sklearn" ]
false
7a1b977017252e0742954ac2005db443f887fcf9
347fb2945546ca91346b73bbc19fa7763011f6de
v1.0
instruct
Evol
Evol_1277_I
Create a function that receives an array of integers and returns a new array containing only the prime numbers from the original array. Each element in the returned array should be a prime number, and the order should follow their original occurrence. ### Input - An array of integers, e.g., `[10, 23, 4, 17, 18, 19, 21...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ 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...
from solution import filter_primes def test_filter_primes_with_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_small_array(): assert filter_primes([10, ...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from the given array.", "function_declaration": "def filter_prim...
[ 1, 0, 1, 1, 1, 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": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001277", "row_id": 1277, "seed_ids": "[18487]" }
0.669446
Evol_1277
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bbda2c3466811b576541ba995fd05c1f08e0a65b
8b05d1d1acf67d9ae8bbc70a32dcab8baa445829
v1.0
instruct
Evol
Evol_1368_I
Create a function that takes a list of integers and returns a list of the same integers but with all prime numbers at the beginning in ascending order, followed by all composite numbers in descending order. Example input: [7, 8, 4, 13, 18, 15, 3], example output: [3, 7, 13, 18, 15, 8, 4] def sort_primes_and_composites...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sort_primes_and_composites(numbers): """ Takes a list of integers and retur...
from solution import sort_primes_and_composites, 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_prim...
[ { "docstring": "Helper function to check 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 list with all prime numbers at the beginning in ascending order,\nfo...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_evol-i2i_10000_1735980704_sanitized_prepared_0_results_combined.jsonl", "solution_code": "def is_prime(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_9
{ "original_instruction": "", "prompt_id": "00001368", "row_id": 1368, "seed_ids": "[42686]" }
0.611454
Evol_1368
I
[ "is_prime", "sort_primes_and_composites" ]
2
[ [ "sort_primes_and_composites", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dfdd3dfb7463740f86fb263ab38b6cf410ca8f05
5adcee1931d6a151020bfe5cb241bc901c9d50e9