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
Filter
Filter_37192_I
Write a Python program to find all elements in the list that are prime numbers. Also, for each identified prime, find and return the nearest prime neighbors (one smaller and one bigger) if they exist. If there are no prime neighbors, return None for that position. Your returned output should be a list of tuples, where ...
def is_prime(n): """ Helper function to check if a number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +=...
from solution import prime_elements_with_neighbors, is_prime, find_nearest_primes 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(20) == False def test_find_nearest_pr...
[ { "docstring": "Helper function to check if a number is prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Helper function to find nearest smaller and bigger primes", "function_declaration": "def find_nearest_primes...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 == 0 or n % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037192", "row_id": 37192, "seed_ids": "['Qwen2-72B-Instruct_82688']" }
0.641337
Filter_37192
I
[ "is_prime", "find_nearest_primes", "prime_elements_with_neighbors" ]
3
[ [ "find_nearest_primes", "is_prime" ], [ "prime_elements_with_neighbors", "find_nearest_primes" ], [ "prime_elements_with_neighbors", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
7d083699b698a27452e7b92a733c3a7ef92fea4c
bf5abbd944af87468e93d0e87147a6758069431b
v1.0
instruct
Filter
Filter_37200_I
Write a python program to find and print all pairs of numbers in a given list whose product is a power of 2.
import math def is_power_of_2(n): """ Returns True if n is a power of 2, otherwise False. """ return n > 0 and (n & (n - 1)) == 0 def find_pairs_with_product_power_of_2(numbers): """ Finds and returns all pairs of numbers in the given list whose product is a power of 2. """ result = []...
from solution import find_pairs_with_product_power_of_2 def test_find_pairs_all_powers_of_2(): assert find_pairs_with_product_power_of_2([1, 2, 4, 8, 16]) == [ (1, 2), (1, 4), (1, 8), (1, 16), (2, 4), (2, 8), (2, 16), (4, 8), (4, 16), (8, 16) ] def test_find_pairs_mixed_numbers(): assert find_pair...
[ { "docstring": "Returns True if n is a power of 2, otherwise False.", "function_declaration": "def is_power_of_2(n):", "function_name": "is_power_of_2", "parameter_list": "(n)" }, { "docstring": "Finds and returns all pairs of numbers in the given list whose product is a power of 2.", "f...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_two(n):\n \"\"\"\n Checks if a given integer n is a power of two.\n \"\"\"\n return n > 0 and (n & (n - 1)) == 0\n\ndef find_pairs_with_power_of_two_product(nums):\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037200", "row_id": 37200, "seed_ids": "['Qwen2-72B-Instruct_82704']" }
0.602615
Filter_37200
I
[ "is_power_of_2", "find_pairs_with_product_power_of_2" ]
2
[ [ "find_pairs_with_product_power_of_2", "is_power_of_2" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c5487490c246bc4a485621a21f6c80d3dc190a0
9223f0f33d0a23f2a5ef9ee93c0ad49cc83b7985
v1.0
instruct
Filter
Filter_37203_I
Develop an array sorting algorithm in Python that sorts an array in place using the quicksort algorithm.
def quicksort(arr, low, high): """ Sorts an array in place using the quicksort algorithm. """ if low < high: # pi is partitioning index, arr[pi] is now at right place pi = partition(arr, low, high) # Recursively sort elements before # partition and after partitio...
from solution import quicksort def test_quicksort_sorted_array(): arr = [1, 2, 3, 4, 5] quicksort(arr, 0, len(arr) - 1) assert arr == [1, 2, 3, 4, 5] def test_quicksort_reverse_sorted_array(): arr = [5, 4, 3, 2, 1] quicksort(arr, 0, len(arr) - 1) assert arr == [1, 2, 3, 4, 5] def test_quickso...
[ { "docstring": "Sorts an array in place using the quicksort algorithm.", "function_declaration": "def quicksort(arr, low, high):", "function_name": "quicksort", "parameter_list": "(arr, low, high)" }, { "docstring": "This function takes the last element as pivot, places the pivot element at ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort(arr):\n \"\"\"\n Sorts an array in place using the quicksort algorithm.\n \"\"\"\n \n def _quicksort(items, low, high):\n if low < high:\n pi = p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037203", "row_id": 37203, "seed_ids": "['Qwen2-72B-Instruct_82710']" }
0.638456
Filter_37203
I
[ "quicksort", "partition" ]
2
[ [ "quicksort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
906829da870558908dd75bbb54d004adfde6d4f2
1df5b5bda4f60a90a390e0b42999150aa2ddfe7d
v1.0
instruct
Filter
Filter_37204_I
Develop a function that generates an array with the prime numbers within the range 0 - 100, not using any libraries, and incorporating a check mechanism to confirm the primality of each number. Here is Python code that accomplishes that task.
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 return True def generate_primes_in_range(limit):...
from solution import primes_up_to_100, is_prime, generate_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(97) == True assert is_prime(100) == False...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate an array with the prime numbers within the range 0 - limit.", "function_declaration": "def generate_primes_in_range(l...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037204", "row_id": 37204, "seed_ids": "['Qwen2-72B-Instruct_82711']" }
0.600079
Filter_37204
I
[ "is_prime", "generate_primes_in_range", "primes_up_to_100" ]
3
[ [ "generate_primes_in_range", "is_prime" ], [ "primes_up_to_100", "generate_primes_in_range" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a5937e26b698e810eb6729e80f1dcac98b27a34a
9dbaec622dfa74e605ae075fb9df151203951d71
v1.0
instruct
Filter
Filter_37211_I
New Prompt: Develop a Python function that converts rectangular coordinates to polar coordinates with respect to a user-given origin. The function `rect_to_polar_custom_origin` should accept three arguments: `x`, `y` for the point's rectangular coordinate, and `(ox, oy)` for the origin's rectangular coordinates. It nee...
import math def shift_to_custom_origin(x, y, ox, oy): """ Adjusts coordinates (x, y) to a custom origin defined by (ox, oy). """ shifted_x = x - ox shifted_y = y - oy return shifted_x, shifted_y def rect_to_polar_custom_origin(x, y, ox, oy): """ Converts rectangular coordinates (x, y) ...
from solution import rect_to_polar_custom_origin, shift_to_custom_origin def test_shift_to_custom_origin(): assert shift_to_custom_origin(3, 4, 1, 1) == (2, 3) assert shift_to_custom_origin(3, 4, 3, 4) == (0, 0) assert shift_to_custom_origin(3, 4, 0, 0) == (3, 4) assert shift_to_custom_origin(-3, -4, -...
[ { "docstring": "Adjusts coordinates (x, y) to a custom origin defined by (ox, oy).", "function_declaration": "def shift_to_custom_origin(x, y, ox, oy):", "function_name": "shift_to_custom_origin", "parameter_list": "(x, y, ox, oy)" }, { "docstring": "Converts rectangular coordinates (x, y) t...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shift_to_custom_origin(x, y, ox, oy):\n \"\"\"\n Shifts (x, y) coordinates to a custom origin (ox, oy).\n Returns the shifted coordinates (x', y').\n \"\"\"\n return x - ox,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037211", "row_id": 37211, "seed_ids": "['Qwen2-72B-Instruct_82719']" }
0.673992
Filter_37211
I
[ "shift_to_custom_origin", "rect_to_polar_custom_origin" ]
2
[ [ "rect_to_polar_custom_origin", "shift_to_custom_origin" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2bcce1d800bcae081524c0e76b72cd00396c9fa0
808c0554a0390ca844580cbf6394ea473285c0ab
v1.0
instruct
Filter
Filter_37212_I
Write a Pythonic function to act as a trampoline for mutually recursive functions to avoid hitting the maximum recursion depth.
def trampoline(func): """ A trampoline function to iteratively handle recursive function calls to avoid maximum recursion depth. """ def trampoline_wrapper(*args, **kwargs): result = func(*args, **kwargs) while callable(result): result = result() return result ret...
from solution import trampoline, is_even, is_odd, is_even_trampolined, is_odd_trampolined def test_is_even_trampolined_with_even_numbers(): assert is_even_trampolined(10) is True assert is_even_trampolined(20) is True assert is_even_trampolined(1000) is True def test_is_even_trampolined_with_odd_numbers()...
[ { "docstring": "A trampoline function to iteratively handle recursive function calls to avoid maximum recursion depth.", "function_declaration": "def trampoline(func):", "function_name": "trampoline", "parameter_list": "(func)" }, { "docstring": null, "function_declaration": "def is_even...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def trampoline(f):\n def wrapped(*args, **kwargs):\n result = f(*args, **kwargs)\n while callable(result):\n result = result()\n return result\n return wr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037212", "row_id": 37212, "seed_ids": "['Qwen2-72B-Instruct_82720']" }
0.466354
Filter_37212
I
[ "trampoline", "is_even", "is_odd" ]
3
[ [ "is_even", "is_odd" ], [ "is_odd", "is_even" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b6a6c4f6098382eddab1722ddbedb2d886aae13a
904e111e02f16e9d778c29b93f4bf83b55c8d016
v1.0
instruct
Filter
Filter_37218_I
Write a function in Python for calculating the area of a circle, but you are not allowed to use the built-in `math` module or any other library that provides a method for calculating the value of pi. Additionally, you should implement your own algorithm for approximating the value of pi.
def calculate_pi(n_terms=10000): """ Approximates the value of pi using the Gregory-Leibniz series. The more terms you use, the closer the approximation will be. 𝜋 ≈ 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...) Args: n_terms (int): Number of terms to use in the approximation. ...
from solution import calculate_pi, area_of_circle def test_calculate_pi_accuracy(): pi_approx = calculate_pi(10000) assert abs(pi_approx - 3.1415) < 0.001 def test_area_of_circle_with_positive_radius(): assert abs(area_of_circle(1) - 3.1415) < 0.001 # Approximate area of a circle with radius 1 assert...
[ { "docstring": "Approximates the value of pi using the Gregory-Leibniz series.\nThe more terms you use, the closer the approximation will be.\n\n𝜋 ≈ 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...)\n\nArgs:\nn_terms (int): Number of terms to use in the approximation.\n\nReturns:\nfloat: Approximated value of pi.",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def approximate_pi(n_terms=100000):\n \"\"\"\n Approximate the value of π using the Leibniz formula.\n \n Parameters:\n n_terms (int): the number of terms to include in the appr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037218", "row_id": 37218, "seed_ids": "['Qwen2-72B-Instruct_82729']" }
0.512844
Filter_37218
I
[ "calculate_pi", "area_of_circle" ]
2
[ [ "area_of_circle", "calculate_pi" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6439739f801e1575d6bbfa9c58acad8648f83887
012e186f83d8e86d4ad976b04af81af9bf52acd2
v1.0
instruct
Filter
Filter_37231_I
Write a Python program that reads three integer inputs from a user. The program should calculate and print the average of those three numbers only if the numbers form a Pythagorean triplet. If they don't form a Pythagorean triplet, the program should print an appropriate message instead. Remember, a Pythagorean triplet...
def is_pythagorean_triplet(a, b, c): """ Checks if the given numbers form a Pythagorean triplet. """ nums = sorted([a, b, c]) return nums[0]**2 + nums[1]**2 == nums[2]**2 def average_of_triplet(a, b, c): """ Returns the average of the three numbers if they form a Pythagorean triplet, ot...
from solution import is_pythagorean_triplet, average_of_triplet def test_is_pythagorean_triplet(): assert is_pythagorean_triplet(3, 4, 5) == True assert is_pythagorean_triplet(5, 12, 13) == True assert is_pythagorean_triplet(1, 2, 3) == False assert is_pythagorean_triplet(6, 8, 10) == True assert i...
[ { "docstring": "Checks if the given numbers form a Pythagorean triplet.", "function_declaration": "def is_pythagorean_triplet(a, b, c):", "function_name": "is_pythagorean_triplet", "parameter_list": "(a, b, c)" }, { "docstring": "Returns the average of the three numbers if they form a Pythag...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_pythagorean_triplet(a, b, c):\n \"\"\"\n Checks if the given numbers form a Pythagorean triplet.\n \"\"\"\n nums = sorted([a, b, c])\n return nums[0]**2 + nums[1]**2 == n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037231", "row_id": 37231, "seed_ids": "['Qwen2-72B-Instruct_82747']" }
0.559227
Filter_37231
I
[ "is_pythagorean_triplet", "average_of_triplet" ]
2
[ [ "average_of_triplet", "is_pythagorean_triplet" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c11bbdfec7b9aae4b4310c336c8f1af57d03cbf9
dd34dd7473653e14ad927815f6b6ae9beed8a6f4
v1.0
instruct
Filter
Filter_37236_I
Use Python to write a code that displays a multiplication table of a given number, but the table should only display the multiplication results for prime numbers less than or equal to the given number. Additionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers.
def sieve_of_eratosthenes(n): """ Returns a list of all prime numbers less than or equal to n. """ primes = [True] * (n + 1) p = 2 while (p * p <= n): if (primes[p] == True): for i in range(p * p, n + 1, p): primes[i] = False p += 1 prime_numbers =...
from solution import sieve_of_eratosthenes, multiplication_table_for_primes def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(2) == [2] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] assert sieve_of_eratosthenes(1) == [] d...
[ { "docstring": "Returns a list of all prime numbers less than or equal to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Displays the multiplication table of the given number 'n' but only for ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n primes = [True] * (limit ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037236", "row_id": 37236, "seed_ids": "['Qwen2-72B-Instruct_82755']" }
0.57838
Filter_37236
I
[ "sieve_of_eratosthenes", "multiplication_table_for_primes" ]
2
[ [ "multiplication_table_for_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
39fab0697cc3e2900e1155f5335518ed60ca844d
a54b3e6ff5cb7b1ac0791de7e90eea952d444710
v1.0
instruct
Filter
Filter_37251_I
Create a dictionary in Python whose keys are the integers from 1 to 1000 and whose values are the cubes of the keys. The dictionary should only include keys that are prime numbers and the cubes should be calculated using a recursive function. Additionally, the implementation should have a time complexity of O(n) and a ...
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 cube_recursive(n): n = abs(n) if n...
from solution import is_prime, cube_recursive, generate_prime_cubes_dict def test_is_prime(): assert is_prime(2) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(19) == True assert is_prime(20) == False assert is_prime(1) == False def test_cube_recursive(): a...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def cube_recursive(n):", "function_name": "cube_recursive", "parameter_list": "(n)" }, { "docstring": nul...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037251", "row_id": 37251, "seed_ids": "['Qwen2-72B-Instruct_82784']" }
0.611212
Filter_37251
I
[ "is_prime", "cube_recursive", "generate_prime_cubes_dict" ]
3
[ [ "generate_prime_cubes_dict", "cube_recursive" ], [ "generate_prime_cubes_dict", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
199d3f0ded80363bd595d02b8dd9d355f948e768
35ac3c84bb747fd8192d20b25fc96e9c8c9a5316
v1.0
instruct
Filter
Filter_37261_I
Write a python program to print the first 50 prime numbers in a given range using functional programming concepts.
from itertools import islice from math import sqrt def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(sqrt(n)) + 1, 2): if n % i == 0: retu...
from solution import is_prime, first_n_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False assert is_prime(11) == True def test_first_n_primes(): assert first_n_primes(1) == [2]...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "first_n...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import islice\nfrom math import sqrt\n\ndef 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:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037261", "row_id": 37261, "seed_ids": "['Qwen2-72B-Instruct_82798']" }
0.623722
Filter_37261
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46274632e6843c9946780aa876929b7dac3b54aa
37116adb645a586bcb7c1838fab88422489ee07b
v1.0
instruct
Filter
Filter_37270_I
Write a code segment that generates a prime number pyramid with the height of 7. Additionally, make sure to include a function that checks whether the generated numbers are indeed prime.
import itertools def is_prime(num): """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 generate_prime_pyramid(height): """Generate a pyramid of prime numbers with given height."...
from solution import is_prime, generate_prime_pyramid def test_is_prime(): assert is_prime(2) == True assert is_prime(11) == True assert is_prime(15) == False assert is_prime(41) == True assert is_prime(1) == False assert is_prime(-5) == False def test_generate_prime_pyramid_height_3(): py...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate a pyramid of prime numbers with given height.", "function_declaration": "def generate_prime_pyramid(height):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks whether a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037270", "row_id": 37270, "seed_ids": "['Qwen2-72B-Instruct_82814']" }
0.545585
Filter_37270
I
[ "is_prime", "generate_prime_pyramid" ]
2
[ [ "generate_prime_pyramid", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d511dd281a2049cdee9c34e42d8b52b65a45b574
735218aa96c39032aefd672d90b4d0d321a8e230
v1.0
instruct
Filter
Filter_37306_I
Given two numbers x and y, write a Python function that returns their sum, difference, product, and division results (both integer and floating-point divisions). However, do not use the built-in arithmetic operators (+, -, *, /, //).
def arithmetic_operations(x, y): """ Returns the sum, difference, product, and division results (both integer and floating-point divisions) of x and y without using built-in arithmetic operators. """ # Sum sum_ = add(x, y) # Difference diff = subtract(x, y) # Product pr...
from solution import arithmetic_operations def test_sum(): assert arithmetic_operations(5, 10)[0] == 15 def test_diff(): assert arithmetic_operations(10, 5)[1] == 5 def test_product(): assert arithmetic_operations(3, 4)[2] == 12 assert arithmetic_operations(-3, 4)[2] == -12 def test_float_divisi...
[ { "docstring": "Returns the sum, difference, product, and division results (both integer and floating-point divisions)\nof x and y without using built-in arithmetic operators.", "function_declaration": "def arithmetic_operations(x, y):", "function_name": "arithmetic_operations", "parameter_list": "(...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def arithmetic_operations(x, y):\n \"\"\"\n Returns the sum, difference, product, and both integer and floating-point division of x and y.\n \"\"\"\n def add(a, b):\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037306", "row_id": 37306, "seed_ids": "['Qwen2-72B-Instruct_82869']" }
0.651167
Filter_37306
I
[ "arithmetic_operations", "add", "subtract", "multiply", "divide", "integer_divide" ]
6
[ [ "arithmetic_operations", "add" ], [ "arithmetic_operations", "divide" ], [ "arithmetic_operations", "integer_divide" ], [ "arithmetic_operations", "multiply" ], [ "arithmetic_operations", "subtract" ], [ "divide", "add" ], [ "divide", ...
11
[]
false
[]
false
pytest
true
[]
true
8fd702fcdac504e5701aff74de0ab4cc47a1632b
6f0655b476259fcb8a3ca94ed997a80e1c942855
v1.0
instruct
Filter
Filter_37336_I
Using pseudocode, design an algorithm for in-place quicksort 2 (a variation of the quicksort algorithm), then implement it in your preferred programming language. Discuss the time and space complexity of your implementation. Compare this with standard quicksort and explain why in-place quicksort has advantages in terms...
def quicksort_in_place(arr, low, high): """ In-place quicksort algorithm. This function sorts the array between indexes low and high inclusive. """ if low < high: pi = partition(arr, low, high) quicksort_in_place(arr, low, pi - 1) quicksort_in_place(arr, pi + 1, high) def partit...
from solution import quicksort_in_place def test_quicksort_in_place_with_positive_numbers(): arr = [10, 7, 8, 9, 1, 5] quicksort_in_place(arr, 0, len(arr) - 1) assert arr == [1, 5, 7, 8, 9, 10] def test_quicksort_in_place_with_negative_numbers(): arr = [-3, -1, -2, -4] quicksort_in_place(arr, 0, l...
[ { "docstring": "In-place quicksort algorithm. This function sorts the array between indexes low and high inclusive.", "function_declaration": "def quicksort_in_place(arr, low, high):", "function_name": "quicksort_in_place", "parameter_list": "(arr, low, high)" }, { "docstring": "Partition fu...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n \"\"\"\n This function takes the last element as the pivot, places the pivot element at its correct \n position in the sorted...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037336", "row_id": 37336, "seed_ids": "['Qwen2-72B-Instruct_82916']" }
0.368485
Filter_37336
I
[ "quicksort_in_place", "partition" ]
2
[ [ "quicksort_in_place", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb17be221cf9625d4c35688de1629dffb37843d0
29bc82f44c4db0ed78adab0bb88c41637e6a7b0d
v1.0
instruct
Filter
Filter_37344_I
Design an algorithm to solve the Eight-Queens puzzle using Backtracking. You must use a 2D array as your data structure and display the final configuration of the board on the console in a visual format, that clearly identifies the location of the queens. Additionally, incorporate a feature in your solution that allows...
import threading import sys import time def print_board(board): """ Helper function to print the chessboard """ for row in board: print(" ".join(row)) print() def is_safe(board, row, col): """ Check if it is safe to place a queen at board[row][col]. This means checking the curr...
import pytest from solution import solve_n_queens, is_safe def test_is_safe(): board = [ ['Q', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '....
[ { "docstring": "Helper function to print the chessboard", "function_declaration": "def print_board(board):", "function_name": "print_board", "parameter_list": "(board)" }, { "docstring": "Check if it is safe to place a queen at board[row][col].\nThis means checking the current row, upper dia...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import threading\nimport os\nimport time\n\ndef is_safe(board, row, col):\n \"\"\"\n Checks if placing a queen at board[row][col] is safe\n \"\"\"\n for i in range(col):\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037344", "row_id": 37344, "seed_ids": "['Qwen2-72B-Instruct_82926']" }
0.503337
Filter_37344
I
[ "print_board", "is_safe", "solve_n_queens_util", "solve_n_queens", "solve_n_queens_background" ]
5
[ [ "solve_n_queens", "solve_n_queens_util" ], [ "solve_n_queens_util", "is_safe" ], [ "solve_n_queens_util", "print_board" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a23b23fcc885eda4fc1f14af1ab64ff9d7025f8b
c63f3d4383e9f1e2d43522a7df8c75698f6a1636
v1.0
instruct
Filter
Filter_37345_I
Write a Python program to find all the prime numbers in the range between 1 to 100 and print the product of all the prime numbers found.
def is_prime(n): """ Returns True if n is a prime number, else 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 i ...
from solution import is_prime, prime_product_in_range 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(97) == True assert is_prime(98) == False def test_prime_product_in_range(): assert prime_p...
[ { "docstring": "Returns True if n is a prime number, else False", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all prime numbers between 1 and 100 and returns their product.", "function_declaration": "def prime_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037345", "row_id": 37345, "seed_ids": "['Qwen2-72B-Instruct_82927']" }
0.683894
Filter_37345
I
[ "is_prime", "prime_product_in_range" ]
2
[ [ "prime_product_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9239f1e7762022477966dd7ac60a0162a38a086a
c18821669a7b567fb8071d9b9a48cb87fb1eaf01
v1.0
instruct
Filter
Filter_37352_I
Print all the odd numbers from 1 to 100 using a for loop in Python. Additionally, modify the code to only print prime numbers among those odd numbers.
def is_prime(n): """ Returns True if n is a prime number, else 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 print_odd_primes(): """ Prints all the prime numbers among the odd numbers from...
from solution import is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(25) == False assert is_prime(1) == False def test_print_odd_primes(capsys): from solution import print_odd_primes...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints all the prime numbers among the odd numbers from 1 to 100.", "function_declaration": "def print_od...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037352", "row_id": 37352, "seed_ids": "['Qwen2-72B-Instruct_82939']" }
0.622641
Filter_37352
I
[ "is_prime", "print_odd_primes" ]
2
[ [ "print_odd_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ce9678855c55b400ea193688a27957e8a2732ff
b657681dc290a65ff1e4a64a4e3fc38cdb8c7dca
v1.0
instruct
Filter
Filter_37359_I
Using python, create a function that takes a string and returns a new string with each character replaced with the next character in the alphabet. However, the function should also handle wrapping around the alphabet, uppercase characters, lowercase characters, and exclude certain characters from being replaced.
def shift_character(c): """ Shifts a character to the next character in the alphabet. Wraps around if necessary and retains case. If the character is non-alphabetic, returns it unchanged. """ if 'a' <= c <= 'z': return chr((ord(c) - ord('a') + 1) % 26 + ord('a')) elif 'A' <= c <= 'Z'...
from solution import shift_string def test_shift_lowercase(): assert shift_string("abc") == "bcd" assert shift_string("xyz") == "yza" def test_shift_uppercase(): assert shift_string("ABC") == "BCD" assert shift_string("XYZ") == "YZA" def test_shift_mixed_case(): assert shift_string("aBcXyZ") ...
[ { "docstring": "Shifts a character to the next character in the alphabet.\nWraps around if necessary and retains case.\nIf the character is non-alphabetic, returns it unchanged.", "function_declaration": "def shift_character(c):", "function_name": "shift_character", "parameter_list": "(c)" }, { ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def next_char(s, exclude=\"aeiouAEIOU\"):\n \"\"\"\n Replaces each character in the string s with the next character in the alphabet.\n Wraps around 'z' to 'a' and 'Z' to 'A'.\n Ch...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037359", "row_id": 37359, "seed_ids": "['Qwen2-72B-Instruct_82947']" }
0.686803
Filter_37359
I
[ "shift_character", "shift_string" ]
2
[ [ "shift_string", "shift_character" ] ]
1
[]
false
[]
false
pytest
true
[]
true
353ee446ccb23eaebaf41cf79156158087239fff
38511e0d7482dda636981b8a3c21e5854427c4f8
v1.0
instruct
Filter
Filter_37384_I
Complete this basic recursive binary search algorithm in Python, including handling for an unsorted data array. Assure that the solution is not simply copying code from standard libraries or online resources, but rather reveals the logic and principles behind the binary search algorithm.
def binary_search_recursive(arr, target, low, high): """ Perform binary search recursively to find the target in the sorted array. Params: arr (list): The sorted array in which to search. target: The target value to find. low (int): The lower index of the search range. high (int): The u...
from solution import binary_search def test_binary_search_sorted(): arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] target = 7 assert binary_search(arr, target) == 6 # Since array is already sorted, directly gives index def test_binary_search_unsorted(): arr = [10, 1, 5, 3, 2, 6, 9, 7, 8, 4] target = 7 ...
[ { "docstring": "Perform binary search recursively to find the target in the sorted array.\n\nParams:\narr (list): The sorted array in which to search.\ntarget: The target value to find.\nlow (int): The lower index of the search range.\nhigh (int): The upper index of the search range.\n\nReturns:\nint: The index...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(arr, target):\n \"\"\"\n Perform a binary search to find the target in the array.\n\n :param arr: List of elements to search through. Must be sorted.\n :param tar...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037384", "row_id": 37384, "seed_ids": "['Qwen2-72B-Instruct_82999']" }
0.67511
Filter_37384
I
[ "binary_search_recursive", "binary_search" ]
2
[ [ "binary_search", "binary_search_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
81d98cd22214e5dc4bffc423e2b9fc461e663265
baa6915f07447a477dcd914cb8bc660f0bbaa104
v1.0
instruct
Filter
Filter_37390_I
Construct a program that prints the first 1000 prime numbers and calculates the sum of all these prime numbers. Additionally, the program should identify and correct any errors in the provided erroneous code.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, first_n_primes, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_first_n_primes(): primes = first...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "first_n_primes",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037390", "row_id": 37390, "seed_ids": "['Qwen2-72B-Instruct_83013']" }
0.487529
Filter_37390
I
[ "is_prime", "first_n_primes", "sum_of_primes" ]
3
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e0988cfcce32ee98853ce7c588fef0d65fedb33
8e0df18ebd6a97591da8b91e8e5652150fdc6035
v1.0
instruct
Filter
Filter_37404_I
Please write a python function that takes in a list of numbers as input, finds the maximum and minimum values, and returns the difference between them. Then, modify this function to handle cases where the list might contain non-numeric values, such as strings or None, and prevent any errors from occurring. Finally, fin...
def max_min_difference(numbers): """ Returns the difference between the maximum and minimum values from a list of numbers, ignoring non-numeric values. """ numeric_values = [num for num in numbers if isinstance(num, (int, float))] if not numeric_values: raise ValueError("The list co...
from solution import max_min_difference, shuffled_and_reversed_difference def test_max_min_difference_normal_case(): assert max_min_difference([1, 2, 3, 4, 5]) == 4 def test_max_min_difference_with_negative_values(): assert max_min_difference([1, -2, 3, -4, 5]) == 9 def test_max_min_difference_with_non_numer...
[ { "docstring": "Returns the difference between the maximum and minimum values from a list of numbers,\nignoring non-numeric values.", "function_declaration": "def max_min_difference(numbers):", "function_name": "max_min_difference", "parameter_list": "(numbers)" }, { "docstring": "Shuffles a...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_min_diff(numbers):\n \"\"\"\n Returns the difference between the maximum and minimum numeric values in the list.\n Any non-numeric values are ignored.\n \"\"\"\n numeric...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037404", "row_id": 37404, "seed_ids": "['Qwen2-72B-Instruct_83039']" }
0.753021
Filter_37404
I
[ "max_min_difference", "shuffled_and_reversed_difference" ]
2
[ [ "shuffled_and_reversed_difference", "max_min_difference" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef67ad28984f2d13e98523cecc81f9c3e2c9ecd2
dcef442388fa5beaede657985940c4b25f1cd766
v1.0
instruct
Filter
Filter_37414_I
Output the below binary tree level by level, with each level on a new line, using a Python function. However, you are not allowed to use any built-in data structures such as lists or queues. You can only use basic data types like integers and strings, as well as pointers.
class Node: def __init__(self, key): self.data = key self.left = None self.right = None class QueueNode: def __init__(self, node): self.tree_node = node self.next = None class Queue: def __init__(self): self.front = None self.rear = None def...
def test_level_order_traversal(): root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root.right.right = Node(6) expected_output = "1\n2 3\n4 5 6" assert level_order_traversal(root) == expected_output def test_level_order_trave...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, key):\n self.data = key\n self.left = None\n self.right = None\n\nclass QueueNode:\n def __init__(self, node):\n self.tree_no...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037414", "row_id": 37414, "seed_ids": "['Qwen2-72B-Instruct_83053']" }
0.528687
Filter_37414
I
[ "level_order_traversal", "CountNodesInCurrentLevel" ]
2
[ [ "level_order_traversal", "CountNodesInCurrentLevel" ] ]
1
[]
false
[ "Node", "QueueNode", "Queue" ]
true
pytest
false
[]
true
dc512af212b3fa64701abd3c15049f8c3605a48f
c90d42b7de3778ec437c2c809b71b60feb09bbf3
v1.0
instruct
Filter
Filter_37433_I
Simulate a biased coin toss using Python. The coin has a 60% chance of landing on heads and a 40% chance of landing on tails. Perform the simulation 1000 times and print the number of times each side landed.
import random def biased_coin_toss(): """ Simulates a biased coin toss with a 60% chance of landing on heads and a 40% chance of landing on tails. Returns: str: "heads" or "tails" based on the biased probability. """ return "heads" if random.random() < 0.6 else "tails" def simulate_tosses...
from solution import biased_coin_toss, simulate_tosses def test_biased_coin_toss(): heads_count = 0 tails_count = 0 for _ in range(1000): result = biased_coin_toss() if result == 'heads': heads_count += 1 else: tails_count += 1 assert 550 <= heads_count <...
[ { "docstring": "Simulates a biased coin toss with a 60% chance of landing on heads and a 40% chance of landing on tails.\n\nReturns:\n str: \"heads\" or \"tails\" based on the biased probability.", "function_declaration": "def biased_coin_toss():", "function_name": "biased_coin_toss", "parameter_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef biased_coin_toss(prob_head=0.6, trials=1000):\n \"\"\"\n Simulates a biased coin toss. The coin has a `prob_head` chance of landing on heads and the remaining probab...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037433", "row_id": 37433, "seed_ids": "['Qwen2-72B-Instruct_83088']" }
0.446528
Filter_37433
I
[ "biased_coin_toss", "simulate_tosses" ]
2
[ [ "simulate_tosses", "biased_coin_toss" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e65220d90e52d34f1bbdf4946a7e59faa8c8f7fe
9b7dd88c967c6a8edd4f14c6c60bb2a9216e2242
v1.0
instruct
Filter
Filter_37453_I
Create a random list of 10 prime numbers in the range of 100 to 1000 in Python.
import random def is_prime(n): """ Checks 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 generate_random_primes(prime_count=10, start=100, end=1000): """ Generates a list of...
from solution import is_prime, generate_random_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False def test_generate_random_primes(): primes = gene...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list of random prime numbers within the given range.", "function_declaration": "def generate_random_primes(prime_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037453", "row_id": 37453, "seed_ids": "['Qwen2-72B-Instruct_83119']" }
0.559116
Filter_37453
I
[ "is_prime", "generate_random_primes" ]
2
[ [ "generate_random_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad9648b7e25728a9cfba07a6261aaed5ee6c7884
58f4286efb8d5b900f1f134a2ec540f192a0d272
v1.0
instruct
Filter
Filter_37457_I
Given an array of integers, write an algorithm to reorder the array so that all the prime numbers appear before all the non-prime numbers, while maintaining the relative order of the prime numbers and the relative order of the non-prime numbers. Your algorithm should have a time complexity of O(n) and should not use an...
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 i += 6...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_reorder_primes(): assert reorder_primes([3, 4, 5, 6, 7, 8, 9]) == [3, 5, 7, 4, 6, 8, 9] ass...
[ { "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": "Reorder the array so that primes come before non-primes.\nThis maintains the relative order of primes an...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 if n % 2 == 0 or n % 3 == 0:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037457", "row_id": 37457, "seed_ids": "['Qwen2-72B-Instruct_83125']" }
0.605811
Filter_37457
I
[ "is_prime", "reorder_primes" ]
2
[ [ "reorder_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
aadde245b5d4f4047f6adbf2662d112ff766e462
72a4c09241b28e0227edde57243bc33b21d040a2
v1.0
instruct
Filter
Filter_37461_I
Create an asyncio event loop and execute a coroutine that performs a CPU-intensive task. The coroutine should accept a list of integers as input and return a list containing the prime numbers from the input list. However, the prime numbers should be generated using a deterministic primality test algorithm such as AKS p...
import asyncio import math def is_prime(n): """ Check if a number is prime using a naive algorithm. """ 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: ...
import asyncio from solution import run_event_loop, 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(6) == False assert is_prime(29) == True def test_find_primes(): assert asyncio.run(...
[ { "docstring": "Check if a number is prime using a naive algorithm.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def run_event_loop(numbers):", "function_name": "run_event_loop", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import asyncio\nimport sympy\n\nasync def find_primes(input_list):\n \"\"\"\n This coroutine finds all prime numbers in the input_list using sympy isprime method.\n \"\"\"\n primes...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037461", "row_id": 37461, "seed_ids": "['Qwen2-72B-Instruct_83133']" }
0.544526
Filter_37461
I
[ "is_prime", "find_primes", "main", "run_main_with_numbers", "run_event_loop" ]
5
[ [ "find_primes", "is_prime" ], [ "run_event_loop", "run_main_with_numbers" ], [ "run_main_with_numbers", "main" ] ]
3
[]
false
[]
false
pytest
true
[]
true
366e55f938f58c06ae4ebef85a77b67a7f1368f0
656504054e05b6947c219b26cbcc917adebee6f7
v1.0
instruct
Filter
Filter_37462_I
Write a function in Python that takes in two integers and returns a list of all the prime numbers between the two, inclusive, in descending order. The function should implement the Sieve of Eratosthenes algorithm to optimize the prime number generation.
def sieve_of_eratosthenes(n): """ Generates a list of all prime numbers up to and including n using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if is_prime[p] == True: for i in range(p * p, n + 1, p): is_prime...
from solution import primes_between_desc def test_primes_between_desc_same_numbers(): assert primes_between_desc(5, 5) == [5] def test_primes_between_desc_single_prime(): assert primes_between_desc(10, 12) == [11] def test_primes_between_desc_no_prime(): assert primes_between_desc(14, 16) == [] def test...
[ { "docstring": "Generates a list of all prime numbers up to and including n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n The Sieve of Eratosthenes algorithm to find all primes <= n\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p <= n):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037462", "row_id": 37462, "seed_ids": "['Qwen2-72B-Instruct_83134']" }
0.670337
Filter_37462
I
[ "sieve_of_eratosthenes", "primes_between_desc" ]
2
[ [ "primes_between_desc", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7bca4512ead9475c376f1537c60a5f0297017dc2
3989cc001d00cc8eb7183f2e2be5bb5ac9a5718d
v1.0
instruct
Filter
Filter_37465_I
Write a python program using a do-while loop to print the first 10 numbers of the Fibonacci sequence. Also, incorporate error handling in your program such that it retry handling any instances of a RecursionError should one occur. Note that the program should only output even numbers from the Fibonacci sequence. Althou...
def fibonacci_even(n): fib_sequence = [] a, b = 0, 1 count = 0 while count < n: b = a + b a = b - a if b % 2 == 0: fib_sequence.append(b) count += 1 return fib_sequence def main_fibonacci_even(): attempt = 0 max_attempts = 3 while attem...
from solution import main_fibonacci_even def test_main_fibonacci_even(): fibonacci_evens = main_fibonacci_even() assert fibonacci_evens == [2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040]
[ { "docstring": null, "function_declaration": "def fibonacci_even(n):", "function_name": "fibonacci_even", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def main_fibonacci_even():", "function_name": "main_fibonacci_even", "parameter_list": "()" } ]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_fibonacci(limit=10):\n \"\"\"\n Generate the first ten Fibonacci numbers (even ones only).\n The Fibonacci sequence is calculated iteratively.\n \"\"\"\n fibonacci_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037465", "row_id": 37465, "seed_ids": "['Qwen2-72B-Instruct_83140']" }
0.71181
Filter_37465
I
[ "fibonacci_even", "main_fibonacci_even" ]
2
[ [ "main_fibonacci_even", "fibonacci_even" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec6e2d2181b66976f026611aabf47d2d317cfce1
7ad0854063fc94fb9b3bc0c533f6c776792106ba
v1.0
instruct
Filter
Filter_37504_I
Create a robust Python program that will sieve through the current contents of a directory you specify, identifying files of a particular type the user specifies (by including patterns like ".txt", ".jpg", etc.). To make the program more sophisticated, undertake the additional challenges: ignore files in subdirectories...
import os import hashlib def get_files_by_type(directory, pattern): """ Identifies files in the specified directory matching the pattern. Args: directory: str - The directory path to search in. pattern: str - The file type pattern to search for (e.g., ".txt"). Returns: ...
import os import pytest from solution import get_files_by_type, calculate_checksum # Mock directory setup MOCK_DIR = "mock_directory" MOCK_FILE_CONTENT = { "file1.txt": "Content of file 1", "file2.txt": "Content of file 2", "file3.jpg": "Content of file 3", "subdir/file4.txt": "Content of file 4" } @p...
[ { "docstring": "Identifies files in the specified directory matching the pattern.\n\nArgs:\n directory: str - The directory path to search in.\n pattern: str - The file type pattern to search for (e.g., \".txt\").\n \nReturns:\n tuple: (int, list) - Number of files found and list of file names along...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport hashlib\n\ndef find_files(directory, file_pattern):\n \"\"\"\n Search for files in the specified directory matching the file pattern.\n \n Args:\n directory (s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037504", "row_id": 37504, "seed_ids": "['Qwen2-72B-Instruct_83198']" }
0.613455
Filter_37504
I
[ "get_files_by_type", "calculate_checksum" ]
2
[ [ "get_files_by_type", "calculate_checksum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6acb1e457db3e4106988fb5961bc86ba93824673
d7d1381f1778a499c497974933786cd1b3a689c9
v1.0
instruct
Filter
Filter_37505_I
Design a program to solve a 9x9 Sudoku puzzle using only recursive backtracking algorithm and without using any additional data structures. The program should also validate the input Sudoku puzzle before solving it, and return an error message if the puzzle is invalid. Additionally, the program should implement a user-...
def is_valid_sudoku(grid): def is_valid_row(row): unique_num = [num for num in row if num != 0] return len(unique_num) == len(set(unique_num)) def is_valid_col(col): unique_num = [grid[row][col] for row in range(9) if grid[row][col] != 0] return len(unique_num) == len(set(unique...
def test_is_valid_sudoku(): valid_sudoku = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, ...
[ { "docstring": null, "function_declaration": "def is_valid_sudoku(grid):", "function_name": "is_valid_sudoku", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def find_empty_location(grid):", "function_name": "find_empty_location", "parameter_list": "(...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_sudoku(grid):\n def is_valid_row(row):\n unique_num = [num for num in row if num != 0]\n return len(unique_num) == len(set(unique_num))\n\n def is_valid_col(co...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037505", "row_id": 37505, "seed_ids": "['Qwen2-72B-Instruct_83199']" }
0.511128
Filter_37505
I
[ "is_valid_sudoku", "find_empty_location", "is_safe", "solve_sudoku", "display_grid", "input_sudoku", "main" ]
7
[ [ "solve_sudoku", "find_empty_location" ], [ "solve_sudoku", "is_safe" ] ]
2
[]
false
[]
false
pytest
false
[]
true
61f28b2cbbc2322ae8ccedad91956846eca59815
4ec94335b1e91ea807e7fa56dac3a40061703e70
v1.0
instruct
Filter
Filter_37511_I
Given a string s and a list of queries, find the kth character of the s after applying the caesar cipher using the shift given in the queries for the respective substring [L, R] in the s.
def caesar_cipher_shift(char, shift): """ Helper function to shift a character by a given number using Caesar Cipher. """ if char.islower(): return chr((ord(char) - ord('a') + shift) % 26 + ord('a')) elif char.isupper(): return chr((ord(char) - ord('A') + shift) % 26 + ord('A')) ...
from solution import apply_caesar_cipher def test_apply_caesar_cipher_single_query(): s = "abcdef" queries = [(0, 3, 2, 1)] # Shift "abcd" by 1 => "bcde" and find the 2nd character => 'c' assert apply_caesar_cipher(s, queries) == ['c'] def test_apply_caesar_cipher_multiple_queries(): s = "abcdef" ...
[ { "docstring": "Helper function to shift a character by a given number using Caesar Cipher.", "function_declaration": "def caesar_cipher_shift(char, shift):", "function_name": "caesar_cipher_shift", "parameter_list": "(char, shift)" }, { "docstring": "Applies the caesar cipher as per the giv...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_kth_character(s, queries):\n \"\"\"\n Given a string s and a list of queries, find the kth character of the s\n after applying the caesar cipher using the shift give...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037511", "row_id": 37511, "seed_ids": "['Qwen2-72B-Instruct_83215']" }
0.62393
Filter_37511
I
[ "caesar_cipher_shift", "apply_caesar_cipher" ]
2
[ [ "apply_caesar_cipher", "caesar_cipher_shift" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91444940246a29ee2c6f9d8180c4c2d87f1e7a23
9fb2dbc28b01f2480e56dec07f7ba3d05549313f
v1.0
instruct
Filter
Filter_37512_I
Given a set of numbers, write a Python program that returns the mean average of the numbers and the number of prime numbers in the input set. Additionally, if the set contains any numbers that are not integers, raise a ValueError with a descriptive error message.
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 return True def analyze_numbers(numbers): ""...
from solution import analyze_numbers, is_prime import pytest def test_is_prime_function(): 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 a...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the mean average of the numbers and the number of prime numbers in the input set.", "function_declaration": "def analy...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037512", "row_id": 37512, "seed_ids": "['Qwen2-72B-Instruct_83216']" }
0.588719
Filter_37512
I
[ "is_prime", "analyze_numbers" ]
2
[ [ "analyze_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87c01c3c6f1a9fa17099177ddcfdf91c78c892ce
d6f725a1d681a0f4497d5ed4a0b2782fd9abcbdf
v1.0
instruct
Filter
Filter_37513_I
Hello, how can I use recursion to print the Fibonacci sequence in Python?
def fibonacci(n): """ Returns the nth Fibonacci number. """ if n <= 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def print_fibonacci_sequence(count): """ Prints the Fibonacci sequence up to the given count. """ sequence =...
from solution import fibonacci, print_fibonacci_sequence 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(6) == 8 assert fibonacci(10) == 55 def t...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Prints the Fibonacci sequence up to the given count.", "function_declaration": "def print_fibonacci_sequence(count):",...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n, sequence=None):\n \"\"\"\n Generates the Fibonacci sequence up to the nth element using recursion.\n \"\"\"\n if sequence is None:\n sequence = []\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037513", "row_id": 37513, "seed_ids": "['Qwen2-72B-Instruct_83217']" }
0.716098
Filter_37513
I
[ "fibonacci", "print_fibonacci_sequence" ]
2
[ [ "print_fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7b756929187a22292ca0f1c129764b07a43bb82
abe83921606207dbc47d25831d36286516548f99
v1.0
instruct
Filter
Filter_37517_I
Write a function 'addToTuple' that takes a tuple of integers and an integer, and returns a new tuple with the integer added to the end. Also, write a function 'reverseTuple' that reverses the order of elements in a tuple. After performing these operations, serialize the results into JSON and return the serialized outpu...
import json def addToTuple(tpl, elem): """ Returns a new tuple with 'elem' added to the end of 'tpl'. """ if not isinstance(tpl, tuple) or not isinstance(elem, int): raise TypeError("First argument must be a tuple of integers and second argument must be an integer") return tpl + (elem,) de...
from solution import addToTuple, reverseTuple, processTuples import json def test_addToTuple(): assert addToTuple((1, 2, 3), 4) == (1, 2, 3, 4) assert addToTuple((), 1) == (1,) try: addToTuple((1, 2, 3), "a") except TypeError: assert True else: assert False def test_reverse...
[ { "docstring": "Returns a new tuple with 'elem' added to the end of 'tpl'.", "function_declaration": "def addToTuple(tpl, elem):", "function_name": "addToTuple", "parameter_list": "(tpl, elem)" }, { "docstring": "Returns a new tuple with elements in reverse order.", "function_declaration...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef addToTuple(input_tuple, elem):\n \"\"\"\n Returns a new tuple with elem added to the end of input_tuple.\n \"\"\"\n return input_tuple + (elem,)\n\ndef reverseTu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037517", "row_id": 37517, "seed_ids": "['Qwen2-72B-Instruct_83224']" }
0.652498
Filter_37517
I
[ "addToTuple", "reverseTuple", "serializeToJson", "processTuples" ]
4
[ [ "processTuples", "addToTuple" ], [ "processTuples", "reverseTuple" ], [ "processTuples", "serializeToJson" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3fb2c9a9c0077b6cadd9a395ba7b18f1fc5d29ac
7e1847d51b93a56e0bce62ae9a2d9045d8f6f9f9
v1.0
instruct
Filter
Filter_37549_I
Alter the following code to create a function called "find_largest" to find the largest prime number in a given list of integers. The function should return -1 if there are no prime numbers in the list. The function should also throw a ValueError if the input list is empty. The function should only use a maximum of two...
def is_prime(n): """Helper function to determine if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def find_largest(lst)...
from solution import find_largest def test_find_largest_with_prime_numbers(): assert find_largest([2, 3, 5, 7, 11, 13]) == 13 def test_find_largest_with_mixed_numbers(): assert find_largest([15, 21, 2, 3, 5, 97, 4, 6]) == 97 def test_find_largest_with_no_primes(): assert find_largest([4, 6, 8, 12]) == -1...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds the largest prime number in a given list.\nReturns -1 if there are no prime numbers.\nThrows ValueErr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037549", "row_id": 37549, "seed_ids": "['Qwen2-72B-Instruct_83280']" }
0.687778
Filter_37549
I
[ "is_prime", "find_largest" ]
2
[ [ "find_largest", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1c9f264c6bad2bb1d0e475100065e2931527a4e2
7751cb80af60d46c955afd174c06e46be8e576fa
v1.0
instruct
Filter
Filter_37557_I
Develop a Python algorithm for distinguishing prime numbers from a given list of integers. The function should sift through the array, identify prime numbers, and compile them into a new list. Additionally, it should incorporate functionality to sort these primes in reverse without using in-built Python sorting functio...
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 reverse_sort(arr): ...
from solution import is_prime, reverse_sort, find_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(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False asser...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Sorts an array in reverse order without using built-in sorting functions.", "function_declaration": "def reverse_sort(arr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037557", "row_id": 37557, "seed_ids": "['Qwen2-72B-Instruct_83290']" }
0.614926
Filter_37557
I
[ "is_prime", "reverse_sort", "find_and_sort_primes" ]
3
[ [ "find_and_sort_primes", "is_prime" ], [ "find_and_sort_primes", "reverse_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2808d87ae9652a42fd6d811c763184c6c539f765
bf7ad92b1e9e6413e59ecfaf5f9372564b7bda1f
v1.0
instruct
Filter
Filter_37564_I
Write a nested for loop in Python to print the first 10 prime numbers.
def is_prime(num): """ 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 get_first_n_primes(n): """ Get the first n prime numbers. """ primes = [] num = ...
from solution import is_prime, get_first_n_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False def test_get_first_n_primes(): assert get_first_n_primes(1) == [2] assert get_firs...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Get the first n prime numbers.", "function_declaration": "def get_first_n_primes(n):", "function_name": "get_first_n_p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037564", "row_id": 37564, "seed_ids": "['Qwen2-72B-Instruct_83298']" }
0.583172
Filter_37564
I
[ "is_prime", "get_first_n_primes", "print_first_10_primes" ]
3
[ [ "get_first_n_primes", "is_prime" ], [ "print_first_10_primes", "get_first_n_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
500b3af0814b8df713c9f9c2dd207350d4f9f444
b1dcf2ca0c69f63ebb099a82c464974cfa929e38
v1.0
instruct
Filter
Filter_37565_I
A GeoJSON file contains features that outline the boundary of Riverdale, a fictional town with real-world coordinates. If Archie's oreo radius is within the outer limit of the town boundary, he can operate normally. Your task is to write a Python function that validates any given GeoJSON file to ensure that it contains...
import json def is_polygon_or_multipolygon(geometry): """ Checks if the geometry type is either Polygon or MultiPolygon. """ return geometry.get('type') in ['Polygon', 'MultiPolygon'] def validate_geojson(geojson_data): """ Validates that the GeoJSON file is a valid feature collection for "Riv...
from solution import validate_geojson def test_valid_geojson_with_polygon(): geojson_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[[0, 0],...
[ { "docstring": "Checks if the geometry type is either Polygon or MultiPolygon.", "function_declaration": "def is_polygon_or_multipolygon(geometry):", "function_name": "is_polygon_or_multipolygon", "parameter_list": "(geometry)" }, { "docstring": "Validates that the GeoJSON file is a valid fe...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef is_polygon_or_multipolygon(geometry):\n \"\"\"\n Checks if the geometry type is either Polygon or MultiPolygon.\n \"\"\"\n return geometry.get('type') in ['Polyg...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037565", "row_id": 37565, "seed_ids": "['Qwen2-72B-Instruct_83300']" }
0.51175
Filter_37565
I
[ "is_polygon_or_multipolygon", "validate_geojson" ]
2
[ [ "validate_geojson", "is_polygon_or_multipolygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
771d6f861fea921e046b2a2e4fa8c5923a4b2fef
d9d2816ceac5fb25040a7032167a3109b6324bdf
v1.0
instruct
Filter
Filter_37578_I
Implement a linear search algorithm and a binary search algorithm to find the index of a specific character in a sorted char array, and compare their efficiencies.
def linear_search(arr, target): """ Performs a linear search to find the index of the target character in the array. """ for index, char in enumerate(arr): if char == target: return index return -1 def binary_search(arr, target): """ Performs a binary search to find the ...
from solution import linear_search, binary_search, compare_efficiency def test_linear_search(): arr = ['a', 'b', 'c', 'd', 'e'] assert linear_search(arr, 'c') == 2 assert linear_search(arr, 'e') == 4 assert linear_search(arr, 'z') == -1 def test_binary_search(): arr = ['a', 'b', 'c', 'd', 'e'] ...
[ { "docstring": "Performs a linear search to find the index of the target character in the array.", "function_declaration": "def linear_search(arr, target):", "function_name": "linear_search", "parameter_list": "(arr, target)" }, { "docstring": "Performs a binary search to find the index of t...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def linear_search(arr, target):\n \"\"\"\n Performs a linear search to find the index of target in arr.\n \n Args:\n arr (list): List of characters.\n target (str): The chara...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037578", "row_id": 37578, "seed_ids": "['Qwen2-72B-Instruct_83330']" }
0.651724
Filter_37578
I
[ "linear_search", "binary_search", "compare_efficiency" ]
3
[ [ "compare_efficiency", "binary_search" ], [ "compare_efficiency", "linear_search" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6aad87e5d3a4d04d9675a178635e8650d0a501ad
b71359c2c910fc0ff6f2df2385209b81681d17e8
v1.0
instruct
Filter
Filter_37592_I
Develop a Python program to calculate and print the first 10 Fibonacci numbers in reverse order, but also include exception handling for potential errors. The fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones. Usually starting with 0 and 1, the sequence goes like: 0, 1,...
def fibonacci_reverse(n): """ Returns the first n Fibonacci numbers in reverse order. """ try: if n <= 0: raise ValueError("The number of elements n must be a positive integer.") fibonacci_sequence = [0, 1] for i in range(2, n): fibonacci_sequence...
from solution import fibonacci_reverse, first_10_fibonacci_reverse def test_fibonacci_reverse(): expected_output = [34, 21, 13, 8, 5, 3, 2, 1, 1, 0] assert first_10_fibonacci_reverse() == expected_output def test_fibonacci_reverse_negative(): assert "The number of elements n must be a positive integer." i...
[ { "docstring": "Returns the first n Fibonacci numbers in reverse order.", "function_declaration": "def fibonacci_reverse(n):", "function_name": "fibonacci_reverse", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def first_10_fibonacci_reverse():", "function_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_reverse(n):\n \"\"\"\n Returns the first n Fibonacci numbers in reverse order.\n \"\"\"\n try:\n if n <= 0:\n raise ValueError(\"The number of eleme...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037592", "row_id": 37592, "seed_ids": "['Qwen2-72B-Instruct_83346']" }
0.772225
Filter_37592
I
[ "fibonacci_reverse", "first_10_fibonacci_reverse" ]
2
[ [ "first_10_fibonacci_reverse", "fibonacci_reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e16134c51a6a88af53cba9f931a142a3f8d29aa2
63940c6c105c3e8da248ab76d9aa36983ba94cce
v1.0
instruct
Filter
Filter_37599_I
Create a Python function to compute the factorial of a given number using both iterative and recursive approaches. Additionally, write a function to find the factorial of a range of numbers (e.g., from 1 to the given number). Optimize the code for time complexity and ensure to add necessary checks to prevent invalid in...
def factorial_iterative(n): """ Compute factorial of a number using iterative approach. Returns -1 for invalid input. """ if not isinstance(n, int) or n < 0: return -1 result = 1 for i in range(2, n + 1): result *= i return result def factorial_recursive(n): """ ...
from solution import factorial_iterative, factorial_recursive, factorial_range def test_factorial_iterative(): assert factorial_iterative(0) == 1 assert factorial_iterative(1) == 1 assert factorial_iterative(5) == 120 assert factorial_iterative(-1) == -1 assert factorial_iterative('a') == -1 d...
[ { "docstring": "Compute factorial of a number using iterative approach.\nReturns -1 for invalid input.", "function_declaration": "def factorial_iterative(n):", "function_name": "factorial_iterative", "parameter_list": "(n)" }, { "docstring": "Compute factorial of a number using recursive app...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def iterative_factorial(n):\n \"\"\"\n Computes the factorial of a given number iteratively.\n \"\"\"\n if n < 0:\n raise ValueError(\"Factorial is not defined for negative ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037599", "row_id": 37599, "seed_ids": "['Qwen2-72B-Instruct_83364']" }
0.691358
Filter_37599
I
[ "factorial_iterative", "factorial_recursive", "factorial_range" ]
3
[ [ "factorial_range", "factorial_iterative" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac8a6487fa51a85d263b66f8f235b0777ab16b1d
0a0163efd0754f9d5ab47d6d7579760420e9cae4
v1.0
instruct
Filter
Filter_37623_I
Expand the existing Python program that identifies prime numbers less than 1000, using the Sieve of Eratosthenes algorithm, to also include an algorithm comparison with the Trial Division method. Additionally, create an interface that allows users to input a range of numbers and select which algorithm to use, and visua...
import time import numpy as np def sieve_of_eratosthenes(limit): """ Identify prime numbers less than the limit using the Sieve of Eratosthenes algorithm. """ sieve = np.ones(limit, dtype=bool) sieve[:2] = False for i in range(2, int(np.sqrt(limit)) + 1): if sieve[i]: sieve[...
import time import numpy as np from solution import sieve_of_eratosthenes, trial_division, identify_primes, compare_algorithms def test_sieve_of_eratosthenes(): primes = sieve_of_eratosthenes(100) expected_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97...
[ { "docstring": "Identify prime numbers less than the limit using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Identify prime numbers less than the l...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef sieve_of_eratosthenes(limit):\n \"\"\"\n Returns a list of prime numbers less than the given limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n primes =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037623", "row_id": 37623, "seed_ids": "['Qwen2-72B-Instruct_83401']" }
0.605385
Filter_37623
I
[ "sieve_of_eratosthenes", "trial_division", "identify_primes", "compare_algorithms" ]
4
[ [ "compare_algorithms", "identify_primes" ], [ "identify_primes", "sieve_of_eratosthenes" ], [ "identify_primes", "trial_division" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy" ]
false
e62598b9aab114e3e6a81fd2c271b636595b94cd
ccb707b96ab2b847b01eac7556e7288f0314aa67
v1.0
instruct
Filter
Filter_37626_I
Implement a custom defined length function that works with strings. This function should count the number of characters in a string accurately, regardless of whether the string contains single-byte or multi-byte (Unicode) characters. Compare its output with the built-in len() function of Python for the strings provided...
def custom_length(string): """ Custom function to return the number of characters in a string. """ count = 0 for char in string: count += 1 return count def compare_length_with_builtin(strings): """ Compare the custom length function with the built-in len function for a list of ...
from solution import custom_length, compare_length_with_builtin def test_custom_length(): assert custom_length("hello") == 5 assert custom_length("你好") == 2 assert custom_length("") == 0 assert custom_length("👋🌎") == 2 assert custom_length("a😊c") == 3 def test_compare_length_with_builtin(): ...
[ { "docstring": "Custom function to return the number of characters in a string.", "function_declaration": "def custom_length(string):", "function_name": "custom_length", "parameter_list": "(string)" }, { "docstring": "Compare the custom length function with the built-in len function for a li...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def custom_len(s):\n \"\"\"\n Returns the length of the string s, counting each character accurately,\n regardless of whether it is a single-byte or multi-byte (Unicode) character.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037626", "row_id": 37626, "seed_ids": "['Qwen2-72B-Instruct_83405']" }
0.64356
Filter_37626
I
[ "custom_length", "compare_length_with_builtin" ]
2
[ [ "compare_length_with_builtin", "custom_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
707425fd28153617c7f8c5a9f8fc2602b2c58943
6ee5ee3276b1d4e47dc548a5cc0a4daed6f4a9d3
v1.0
instruct
Filter
Filter_37632_I
Create a list comprehension that prints each pair in a given list of tuples only if the first element of the pair is a palindrome string and the second element is a prime number.
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def is_palindrome(s): """ Checks if a string is a palindrome. """ return s == s[::-1] d...
from solution import filter_tuples def test_filter_tuples_empty_list(): assert filter_tuples([]) == [] def test_filter_tuples_no_valid_pairs(): assert filter_tuples([("abc", 4), ("xyz", 10), ("aa", 1)]) == [] def test_filter_tuples_all_valid_pairs(): assert filter_tuples([("aba", 5), ("civic", 3), ("deed...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_pali...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037632", "row_id": 37632, "seed_ids": "['Qwen2-72B-Instruct_83418']" }
0.584174
Filter_37632
I
[ "is_prime", "is_palindrome", "filter_tuples" ]
3
[ [ "filter_tuples", "is_palindrome" ], [ "filter_tuples", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f157e0c34effcaf889bb0b4ed27bba884d9c296
58732b9b1e33a9b23479b91a44d9001bc6f6b826
v1.0
instruct
Filter
Filter_37658_I
Write a function called `sum_primes` that takes in a list of integers and returns the sum of all prime numbers in the list. If the input list is empty or does not contain any prime numbers, the function should return 0.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_primes(lst): """ Returns the sum of all prime numbers in the list. """ ...
from solution import sum_primes def test_sum_primes_with_primes(): assert sum_primes([2, 3, 5, 7, 11]) == 28 # 2 + 3 + 5 + 7 + 11 = 28 def test_sum_primes_with_mixed_numbers(): assert sum_primes([10, 15, 3, 17, 20]) == 20 # 3 + 17 = 20 assert sum_primes([4, 6, 8, 9, 10]) == 0 # no primes def test_sum_pr...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the list.", "function_declaration": "def sum_primes(lst):", "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 return True\n if n % 2 == 0:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037658", "row_id": 37658, "seed_ids": "['Qwen2-72B-Instruct_83462']" }
0.684203
Filter_37658
I
[ "is_prime", "sum_primes" ]
2
[ [ "sum_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea7ed75be3ad8b538a688452deebd706a0eb09a9
7b96fd9284c072cc31c589170fd69efa078b738c
v1.0
instruct
Filter
Filter_37673_I
Create a program that implements the quicksort algorithm to sort a list of integers in non-decreasing order. The program should also determine the minimum, maximum, mean, median, and mode of the list.
from collections import Counter from statistics import mean, median, mode def quicksort(arr): """ Sorts a list of integers using the quicksort algorithm. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x ==...
from solution import quicksort, calculate_statistics def test_quicksort_empty(): assert quicksort([]) == [] def test_quicksort_single_element(): assert quicksort([1]) == [1] def test_quicksort_sorted(): assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_quicksort_reverse(): assert quickso...
[ { "docstring": "Sorts a list of integers using the quicksort algorithm.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Calculates the minimum, maximum, mean, median, and mode of a list of integers.", "function_d...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom statistics import mean, median, mode\n\ndef quicksort(arr):\n \"\"\"\n Implements the quicksort algorithm to sort a list of integers.\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037673", "row_id": 37673, "seed_ids": "['Qwen2-72B-Instruct_83492']" }
0.563242
Filter_37673
I
[ "quicksort", "calculate_statistics" ]
2
[ [ "calculate_statistics", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ce24dd164fb8329fb4608085020153cc7516973
1a797c066b03b315a2f025aa87273d1e317027eb
v1.0
instruct
Filter
Filter_37676_I
As a Python developer, you've been tasked with creating a program that simulates a simple text game. In this game, the user must input a keyword, and the program will interject that keyword into a pre-written story. The catch is, the program must also parse another keyword that the user inputs, and replace all instance...
import random def insert_keyword(story, keyword, insert_point): """ Inserts the user's keyword at the specified insert point in the story. """ return story.replace(insert_point, keyword) def replace_keyword(story, old_keyword, new_keyword): """ Replaces all instances of the old keyword with th...
from solution import insert_keyword, replace_keyword, random_error, process_story def test_insert_keyword(): story = "Once upon a time, there was a [hero]." assert insert_keyword(story, "knight", "[hero]") == "Once upon a time, there was a knight." def test_replace_keyword(): story = "The knight was brave...
[ { "docstring": "Inserts the user's keyword at the specified insert point in the story.", "function_declaration": "def insert_keyword(story, keyword, insert_point):", "function_name": "insert_keyword", "parameter_list": "(story, keyword, insert_point)" }, { "docstring": "Replaces all instance...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef insert_keyword(story, keyword, insert_point):\n \"\"\"\n Inserts the user's keyword at the specified insert point in the story.\n \"\"\"\n return story.replace...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037676", "row_id": 37676, "seed_ids": "['Qwen2-72B-Instruct_83496']" }
0.594398
Filter_37676
I
[ "insert_keyword", "replace_keyword", "random_error", "process_story" ]
4
[ [ "process_story", "insert_keyword" ], [ "process_story", "random_error" ], [ "process_story", "replace_keyword" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d889c87126d945ecc6150031bb2e7bf2d0d277bf
3e31774dab9b788ecd5f3a37a936d782b3cc5580
v1.0
instruct
Filter
Filter_37704_I
Reassign the value of variable 'b' to be the result of a function called 'f' which takes 'a' as an argument only if 'a' is a positive integer greater than zero. If 'a' is not a positive integer greater than zero, set 'b' to None. Additionally, if 'a' is a prime number, add 1 to the result of the function 'f' before ass...
def f(a): """ An example function that takes an integer a and returns some value. This function can be replaced with any specific implementation. """ return a * 2 def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False for i...
from solution import reassign_b, f, is_prime, is_power_of_2 def test_reassign_b_positive_integer(): assert reassign_b(4) == f(4) - 1 # Because 4 is a power of 2 assert reassign_b(3) == f(3) + 1 # Because 3 is a prime number assert reassign_b(10) == f(10) assert reassign_b(16) == f(16) - 1 # Because ...
[ { "docstring": "An example function that takes an integer a and returns some value.\nThis function can be replaced with any specific implementation.", "function_declaration": "def f(a):", "function_name": "f", "parameter_list": "(a)" }, { "docstring": "Returns True if n is a prime number, Fa...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Return True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037704", "row_id": 37704, "seed_ids": "['Qwen2-72B-Instruct_83542']" }
0.662168
Filter_37704
I
[ "f", "is_prime", "is_power_of_2", "reassign_b" ]
4
[ [ "reassign_b", "f" ], [ "reassign_b", "is_power_of_2" ], [ "reassign_b", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cd2401eea535e1e29c7f007bd810f9ab729f02ef
e233d0f5bca6cc316577486277f7bb8631bc8b0c
v1.0
instruct
Filter
Filter_37727_I
Create a program in Python that will identify and tally the number of unique words in a paragraph of text, provided by a user input. Additionally, your solution should ignore case sensitiveness (i.e. 'This' and 'this' should be treated as the same word) and punctuation marks (i.e. 'dog.' and 'dog' should be treated as ...
import string from collections import Counter def remove_punctuation(text): return text.translate(str.maketrans('', '', string.punctuation)) def count_unique_words(paragraph, n, stop_words=None): if stop_words is None: stop_words = {'a', 'and', 'is', 'the', 'in', 'at', 'of', 'on', 'for', 'with', 'to',...
from solution import count_unique_words def test_count_unique_words_basic(): text = "The cat in the hat. The cat is very cute." result = count_unique_words(text, 2) assert result == [('cat', 2), ('hat', 1)] or result == [('cat', 2), ('cute', 1)] or result == [('cat', 2), ('very', 1)] def test_count_unique...
[ { "docstring": null, "function_declaration": "def remove_punctuation(text):", "function_name": "remove_punctuation", "parameter_list": "(text)" }, { "docstring": null, "function_declaration": "def count_unique_words(paragraph, n, stop_words=None):", "function_name": "count_unique_wor...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nimport string\n\ndef tally_unique_words(paragraph, n, stop_words=None):\n \"\"\"\n Tally the number of unique words in a paragraph, ignoring case, punctu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037727", "row_id": 37727, "seed_ids": "['Qwen2-72B-Instruct_83582']" }
0.750289
Filter_37727
I
[ "remove_punctuation", "count_unique_words" ]
2
[ [ "count_unique_words", "remove_punctuation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab95ef3ea22c22b9617152cddeec34ab92b6de12
2e76bd44a3224a3c63f812ca300b6ca2c75290f5
v1.0
instruct
Filter
Filter_37733_I
Given two points in a coordinate plane, write a Python function that calculates the distance between them using the distance formula. Then, extend this function to calculate the perimeter of a polygon given a list of its vertices. You can assume the polygon is convex and the vertices are given in consecutive order.
import math def distance(point1, point2): """ Calculates the distance between two points in a coordinate plane. Args: point1 (tuple): The first point as a (x, y) coordinate. point2 (tuple): The second point as a (x, y) coordinate. Returns: float: The distance between the two points. ...
from solution import distance, polygon_perimeter def test_distance(): assert distance((0, 0), (3, 4)) == 5 assert distance((1, 1), (4, 5)) == 5 assert distance((2, 3), (2, 3)) == 0 assert distance((-1, -1), (1, 1)) == math.sqrt(8) def test_polygon_perimeter(): assert polygon_perimeter([(0, 0), (3,...
[ { "docstring": "Calculates the distance between two points in a coordinate plane.\n\nArgs:\npoint1 (tuple): The first point as a (x, y) coordinate.\npoint2 (tuple): The second point as a (x, y) coordinate.\n\nReturns:\nfloat: The distance between the two points.", "function_declaration": "def distance(point...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef distance(p1, p2):\n \"\"\"\n Returns the Euclidean distance between two points (p1 and p2) in 2D space.\n :param p1: tuple of (x, y) coordinates for the first point...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037733", "row_id": 37733, "seed_ids": "['Qwen2-72B-Instruct_83593']" }
0.594269
Filter_37733
I
[ "distance", "polygon_perimeter" ]
2
[ [ "polygon_perimeter", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60bffea8dca7449fcef1eeca7e004e8f7e5b2f06
eb7455c861f399d0a3ce971e861cfd73f2454ad2
v1.0
instruct
Filter
Filter_37747_I
Implement a random number generator in Python that returns a random odd number in the range of 1-20, and also include functionality to generate n number of random odd numbers in the stated range. Describe each step of your solution and validate your results using tests. Make sure your solution doesn't generate even num...
import random def generate_random_odd(): """ Returns a random odd number in the range of 1-20. """ return random.choice([i for i in range(1, 21) if i % 2 != 0]) def generate_n_random_odds(n): """ Returns a list of n random odd numbers in the range of 1-20. """ return [generate_random_o...
from solution import generate_random_odd, generate_n_random_odds def test_generate_random_odd(): for _ in range(100): # Running the test multiple times for randomness result = generate_random_odd() assert result % 2 != 0, f"Generated number {result} is not odd" assert 1 <= result <= 20, f"...
[ { "docstring": "Returns a random odd number in the range of 1-20.", "function_declaration": "def generate_random_odd():", "function_name": "generate_random_odd", "parameter_list": "()" }, { "docstring": "Returns a list of n random odd numbers in the range of 1-20.", "function_declaration...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_random_odd():\n \"\"\"\n Generate a random odd number between 1 and 20 (inclusive).\n \"\"\"\n odd_numbers = [n for n in range(1, 21) if n % 2 != 0]\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037747", "row_id": 37747, "seed_ids": "['Qwen2-72B-Instruct_83615']" }
0.598444
Filter_37747
I
[ "generate_random_odd", "generate_n_random_odds" ]
2
[ [ "generate_n_random_odds", "generate_random_odd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c598827db2eeac426f4114f3d4d25de81128df8
8fe5999759d3633a93a96aa37041663dfcdb45e8
v1.0
instruct
Filter
Filter_37783_I
Please assist in rewriting the following code using list comprehension in Python. Besides, you're also required to add functionality where you only store the tuple (x, y) if x is prime. You should further create a separate function to check if a number is prime.
def is_prime(n): """ Checks 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 create_list_tuples(x_values, y_values): """ Creates a list of tuples (x, y) using list comprehension,...
from solution import is_prime, create_list_tuples def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_create_list_tupl...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Creates a list of tuples (x, y) using list comprehension,\nbut only stores the tuple if x is a prime number.", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037783", "row_id": 37783, "seed_ids": "['Qwen2-72B-Instruct_83670']" }
0.661471
Filter_37783
I
[ "is_prime", "create_list_tuples" ]
2
[ [ "create_list_tuples", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78ba6137ef8a83f9772cfe42c38e82fbf7d208d5
cbb7db6af9e1ec51f0f586051b4d79477bfcd47d
v1.0
instruct
Filter
Filter_37794_I
Please write a code that creates a function named "merge_sort" which takes in a list of numbers as a parameter and returns a sorted list using the merge sort algorithm. Additionally, include a piece of erroneous code that attempts to sort a list using a non-existent sorting algorithm and produces an error message.
def merge_sort(arr): """ Sorts a list of numbers using the merge sort algorithm. """ if len(arr) <= 1: return arr middle = len(arr) // 2 left_half = merge_sort(arr[:middle]) right_half = merge_sort(arr[middle:]) return merge(left_half, right_half) def merge(left, right...
from solution import merge_sort, non_existent_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_multiple_elements(): assert merge_sort([3, 1, 2, 5, 4]) == [1, 2, 3, 4, 5] def test_merge_sort_reversed...
[ { "docstring": "Sorts a list of numbers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def merge(left, r...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list of numbers using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n # Split the array into two halves\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037794", "row_id": 37794, "seed_ids": "['Qwen2-72B-Instruct_83692']" }
0.634908
Filter_37794
I
[ "merge_sort", "merge", "non_existent_sort" ]
3
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bfe19bbd84de12856f20e54e8f1ff6f59c2e708f
0f6f2599853446d9e1088ebf7dcfb76d74cf03f8
v1.0
instruct
Filter
Filter_37808_I
Create code that will print the elements of a list in reverse order. Additionally, only print the elements that are prime numbers. The program should also check if the length of the list is a prime number and only execute the reverse printing if it is. The time complexity should still be O(n) and the space complexity s...
def is_prime(n): """ Utility 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 reverse_primes(lst): ...
from solution import is_prime, reverse_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(17) == True assert is_prime(1) == Fals...
[ { "docstring": "Utility function to check if a number is prime ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints the elements of a list in reverse order if the length of the list is prime. Only prints the prime eleme...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_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 = 5\n while i * i <= n:\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037808", "row_id": 37808, "seed_ids": "['Qwen2-72B-Instruct_83727']" }
0.558605
Filter_37808
I
[ "is_prime", "reverse_primes" ]
2
[ [ "reverse_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
16e527c337e66c8eee5c1bd20c3d0171df414d25
11163f321eb00e2437f57f623e061fcecfd08816
v1.0
instruct
Filter
Filter_37820_I
Given a set of edges with their length in a weighted graph, find the shortest path between two vertices using Dijkstra's algorithm. Also, modify the implementation to use a Fibonacci heap to improve the efficiency of the algorithm when dealing with large data sets. The vertices and edges of the graph, as well as the st...
import heapq from collections import defaultdict, namedtuple import sys # Create a named tuple to represent edges Edge = namedtuple('Edge', ['vertex', 'weight']) def dijkstra(graph, start): """ Implements Dijkstra's algorithm using a priority queue (min-heap). Adjusting for Fibonacci heap efficiency enhan...
from solution import shortest_path def test_shortest_path_simple_graph(): edges = [ ('A', 'B', 1), ('B', 'C', 2), ('A', 'C', 4), ] distances = shortest_path(edges, 'A', 'C') assert distances['A'] == 0 assert distances['B'] == 1 assert distances['C'] == 3 def test_shorte...
[ { "docstring": "Implements Dijkstra's algorithm using a priority queue (min-heap).\nAdjusting for Fibonacci heap efficiency enhancement will follow.\n:param graph: Dict of vertices and their associated edge (vertex, weight).\n:param start: The starting vertex.\n:return: A dict with the shortest path length to e...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\nfrom heapq import heappop, heappush\n\nclass FibonacciHeap:\n \"\"\"Implementation of a Fibonacci heap.\"\"\"\n\n # Placeholder for the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037820", "row_id": 37820, "seed_ids": "['Qwen2-72B-Instruct_83747']" }
0.606285
Filter_37820
I
[ "dijkstra", "construct_graph", "shortest_path" ]
3
[ [ "shortest_path", "construct_graph" ], [ "shortest_path", "dijkstra" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3bcc550f40594e6c93f1d5d6a83b57837c89bad0
9993f0bdaefe73c1d36113718fa3ba73b475148d
v1.0
instruct
Filter
Filter_37826_I
Write a method to sort a list of integers in Python without using any built-in sort methods or extra space i.e your solution should be in-place. Additionally, you will implement two different sorting algorithms: Bubble Sort and Quick Sort. For both cases, also determine and display the time complexity of your implement...
import time def bubble_sort(arr): """ Sorts a list in-place using Bubble Sort algorithm. Time Complexity: O(n^2) """ n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] def quick_sort(arr, low, ...
from solution import bubble_sort, quick_sort import random def test_bubble_sort(): arr = [64, 34, 25, 12, 22, 11, 90] bubble_sort(arr) assert arr == [11, 12, 22, 25, 34, 64, 90] def test_quick_sort(): arr = [10, 7, 8, 9, 1, 5] quick_sort(arr, 0, len(arr) - 1) assert arr == [1, 5, 7, 8, 9, 10] ...
[ { "docstring": "Sorts a list in-place using Bubble Sort algorithm.\nTime Complexity: O(n^2)", "function_declaration": "def bubble_sort(arr):", "function_name": "bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Sorts a list in-place using Quick Sort algorithm.\nTime Complexity: O(n ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort(arr):\n \"\"\"\n Sorts a list of integers using the Bubble Sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n # Last i elements are already in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037826", "row_id": 37826, "seed_ids": "['Qwen2-72B-Instruct_83756']" }
0.678853
Filter_37826
I
[ "bubble_sort", "quick_sort", "partition" ]
3
[ [ "quick_sort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e24bca195451508d16e73b015c1f676221088b2c
b38cf7eece54290dd56d1438a240aa4d267a4d9f
v1.0
instruct
Filter
Filter_37831_I
Construct a linked list data structure for outputting the first five prime numbers in a given list. Your solution should also include a function to check if a number is prime. The list to start with is as follows: [2, 3, 4, 5, 6, 7, 8, 9, 10].
class Node: """ Represents a node in the linked list. """ def __init__(self, data): self.data = data self.next = None class LinkedList: """ Represents the linked list. """ def __init__(self): self.head = None def append(self, data): """ Appen...
import pytest from solution import Node, LinkedList, is_prime, first_five_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == ...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n \"\"\"\n Represents a node in the linked list.\n \"\"\"\n def __init__(self, data):\n self.data = data\n self.next = None\n\nclass LinkedList:\n \"\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037831", "row_id": 37831, "seed_ids": "['Qwen2-72B-Instruct_83765']" }
0.581768
Filter_37831
I
[ "is_prime", "first_five_primes" ]
2
[ [ "first_five_primes", "is_prime" ] ]
1
[]
false
[ "Node", "LinkedList" ]
true
pytest
true
[]
true
b56e69eed694b7eac7b68a786c6d93cc79658c29
0616a74aa411b6cf814689005b9bb74e990c2f89
v1.0
instruct
Filter
Filter_37857_I
You are theти Middle School computer science teacher and just finished teaching a lesson on converting decimal numbers to binary. You want you students to practice but you don't have time to come up with practice questions for them. So you've decided to write a simple Python script which will generate custom number of ...
import random def decimal_to_binary(decimal_number): """ Convert a decimal number to its binary representation. """ return bin(decimal_number)[2:] def generate_random_decimals(count, lower_bound, upper_bound): """ Generate a list of random decimal numbers within the specified range. """ ...
from solution import decimal_to_binary, generate_random_decimals, validate_binary_conversions def test_decimal_to_binary(): assert decimal_to_binary(0) == "0" assert decimal_to_binary(1) == "1" assert decimal_to_binary(2) == "10" assert decimal_to_binary(10) == "1010" assert decimal_to_binary(255) ...
[ { "docstring": "Convert a decimal number to its binary representation.", "function_declaration": "def decimal_to_binary(decimal_number):", "function_name": "decimal_to_binary", "parameter_list": "(decimal_number)" }, { "docstring": "Generate a list of random decimal numbers within the specif...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef decimal_to_binary(decimal_number):\n \"\"\"\n Converts a decimal number to binary string.\n \"\"\"\n return bin(decimal_number)[2:]\n\ndef generate_random_deci...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037857", "row_id": 37857, "seed_ids": "['Qwen2-72B-Instruct_83804']" }
0.670299
Filter_37857
I
[ "decimal_to_binary", "generate_random_decimals", "validate_binary_conversions" ]
3
[ [ "validate_binary_conversions", "decimal_to_binary" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2073a52f38a36d92642f6e205abfe1c038605f1
b775e1bce94fb331074996d678f470af113adad7
v1.0
instruct
Filter
Filter_37859_I
Develop a Python function that finds the least number of modifications to an array of integers to make it strictly increasing while only using a subset of these integers and no more than 'limit' distinct subset element changes.
from bisect import bisect_left def length_of_lis(nums): """ Helper function to find the length of the longest increasing subsequence. """ if not nums: return 0 lis = [] for num in nums: pos = bisect_left(lis, num) if pos == len(lis): lis.append(num) e...
from solution import min_modifications_to_increasing def test_min_modifications_no_changes_needed(): assert min_modifications_to_increasing([1, 2, 3, 4], 2) == 0 def test_min_modifications_some_changes_needed(): assert min_modifications_to_increasing([3, 2, 1, 4], 3) == 2 def test_min_modifications_not_p...
[ { "docstring": "Helper function to find the length of the longest increasing subsequence.", "function_declaration": "def length_of_lis(nums):", "function_name": "length_of_lis", "parameter_list": "(nums)" }, { "docstring": "Finds the least number of modifications to make a given array of int...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from bisect import bisect_left\n\ndef length_of_lis(nums):\n \"\"\"\n Helper function to find the length of the longest increasing subsequence.\n \"\"\"\n if not nums:\n ret...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037859", "row_id": 37859, "seed_ids": "['Qwen2-72B-Instruct_83806']" }
0.594006
Filter_37859
I
[ "length_of_lis", "min_modifications_to_increasing" ]
2
[ [ "min_modifications_to_increasing", "length_of_lis" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78f7ad9079211ce6a66d0441f1e037f4c6136dfb
58e1a07a2026b9af3fef6a500fc8d375d140996b
v1.0
instruct
Filter
Filter_37867_I
Let's design an algorithm to detect plagiarism using text matching techniques for a social media platform. You've been given an article "professionally-written blog", and we need to compare it to other content on internet to check if it's a duplicate or copied. How can we achieve this using an algorithm with good accur...
import re from collections import defaultdict def preprocess_text(text): """ Preprocess the text by converting to lower case and removing non-alphanumeric characters. """ # Convert to lower case text = text.lower() # Remove non-alphanumeric characters (excluding spaces) text = re.sub(r'[^a-...
from solution import preprocess_text, n_grams, get_text_fingerprint, calculate_similarity, detect_plagiarism def test_preprocess_text(): assert preprocess_text("Hello, World!") == "hello world" assert preprocess_text("This is a Test...") == "this is a test" assert preprocess_text("123 456!") == "123 456" ...
[ { "docstring": "Preprocess the text by converting to lower case and removing non-alphanumeric characters.", "function_declaration": "def preprocess_text(text):", "function_name": "preprocess_text", "parameter_list": "(text)" }, { "docstring": "Generate n-grams from the text.", "function_...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\nfrom collections import Counter\n\ndef preprocess(text):\n \"\"\"\n Preprocess the input text by:\n 1. Lowercasing\n 2. Removing punctuation\n 3. Tokenizing\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037867", "row_id": 37867, "seed_ids": "['Qwen2-72B-Instruct_83823']" }
0.468163
Filter_37867
I
[ "preprocess_text", "n_grams", "get_text_fingerprint", "calculate_similarity", "detect_plagiarism" ]
5
[ [ "detect_plagiarism", "calculate_similarity" ], [ "detect_plagiarism", "get_text_fingerprint" ], [ "get_text_fingerprint", "n_grams" ], [ "get_text_fingerprint", "preprocess_text" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b931cc26a2ec9f0bf1f3328875c4190d9ad703d5
4f2686bf589a6d5d653eefa8d34a98605616fed8
v1.0
instruct
Filter
Filter_37871_I
Write a code snippet which verifies that a given number is not only within a specified range, but also an odd or prime number.
def is_odd_or_prime(n): """ Check if the number n is odd or prime. """ if n <= 1: return False if n % 2 != 0: return True for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def is_within_range_and_odd_or_prime(n, lower_bound, uppe...
from solution import is_within_range_and_odd_or_prime def test_within_range_and_odd_number(): assert is_within_range_and_odd_or_prime(5, 1, 10) == True assert is_within_range_and_odd_or_prime(9, 1, 10) == True def test_within_range_and_prime_number(): assert is_within_range_and_odd_or_prime(7, 1, 10) == T...
[ { "docstring": "Check if the number n is odd or prime.", "function_declaration": "def is_odd_or_prime(n):", "function_name": "is_odd_or_prime", "parameter_list": "(n)" }, { "docstring": "Check if the number n is within the [lower_bound, upper_bound] range\nand if it is either odd or prime.",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_odd_or_prime_and_in_range(number, start, end):\n \"\"\"\n Checks if the number is odd or prime and within the specified range [start, end].\n \"\"\"\n def is_prime(n):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037871", "row_id": 37871, "seed_ids": "['Qwen2-72B-Instruct_83827']" }
0.540493
Filter_37871
I
[ "is_odd_or_prime", "is_within_range_and_odd_or_prime" ]
2
[ [ "is_within_range_and_odd_or_prime", "is_odd_or_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1f7dfcbf3d6ed424496fba8f24eb900def73fb01
22374fdcefb5dc397f309978a052489ad1b697aa
v1.0
instruct
Filter
Filter_37882_I
Edit the given code so that the item at index 4 is multiplied by two only if it is a prime number. If it is not a prime number, add 1 to it instead. Also, the final code should use a recursive function to check for prime numbers. The array should have at least 6 elements.
def is_prime(n, divisor = None): """ Recursive function to check if a number is prime. """ if n <= 1: return False if divisor is None: divisor = n - 1 if divisor == 1: return True if n % divisor == 0: return False return is_prime(n, divisor - 1) def adjus...
from solution import is_prime, adjust_element def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == Fa...
[ { "docstring": "Recursive function to check if a number is prime.", "function_declaration": "def is_prime(n, divisor=None):", "function_name": "is_prime", "parameter_list": "(n, divisor=None)" }, { "docstring": "Adjust the element at index 4: multiply by 2 if it's prime, add 1 otherwise.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime_recursive(n, divisor=None):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if divisor is None:\n divisor = n - 1\n if n <= 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037882", "row_id": 37882, "seed_ids": "['Qwen2-72B-Instruct_83853']" }
0.614236
Filter_37882
I
[ "is_prime", "adjust_element" ]
2
[ [ "adjust_element", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4256021ae3afc3deb006460512e356cc1a86b7d7
5108707b96e40953d7c0587ff49abd5a3976ae6e
v1.0
instruct
Filter
Filter_37894_I
I am creating a series of 40×16 LED Dot Matrix and want a list of all the characters available on a ZX Spectrum storing them in a bitmap format on a Raspberry Pi using Python. Any suggestions how to do this?
def zx_spectrum_character_bitmap(char): """ Returns a bitmap (list of lists) representing the ZX Spectrum character. """ zx_spectrum_font = { 'A': [ '0111110', '1100011', '1111111', '1100011', '1100011' ], 'B': [ ...
from solution import zx_spectrum_character_bitmap, store_zx_spectrum_characters def test_zx_spectrum_character_bitmap_A(): expected_bitmap = [ '0111110', '1100011', '1111111', '1100011', '1100011' ] assert zx_spectrum_character_bitmap('A') == expected_bitmap def tes...
[ { "docstring": "Returns a bitmap (list of lists) representing the ZX Spectrum character.", "function_declaration": "def zx_spectrum_character_bitmap(char):", "function_name": "zx_spectrum_character_bitmap", "parameter_list": "(char)" }, { "docstring": null, "function_declaration": "def s...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def zx_spectrum_char_to_bitmap(char):\n \"\"\"\n Converts a ZX Spectrum character into an 8x8 bitmap representation.\n Assumes `char` is a valid ZX Spectrum character (ASCII 32-127).\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037894", "row_id": 37894, "seed_ids": "['Qwen2-72B-Instruct_83873']" }
0.430677
Filter_37894
I
[ "zx_spectrum_character_bitmap", "store_zx_spectrum_characters" ]
2
[ [ "store_zx_spectrum_characters", "zx_spectrum_character_bitmap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb4d68845a565d22777a992b072bfa948247e022
af06d4037f829ecb1bd98551d7bdebb249fd877c
v1.0
instruct
Filter
Filter_37895_I
I am new to Python programming, and I've been asked to write a program that is supposed to generate a list of palindromic numbers starting from 1 and ending at some maximum number 'M'. Palindromic numbers of course are those numbers that read the same backward or forward, like 121 or 12321, etc. How can I do this? Can ...
def is_palindromic_number(num): """ Checks if a given number is palindromic. """ return str(num) == str(num)[::-1] def generate_palindromic_numbers(max_num): """ Generates a list of palindromic numbers from 1 to max_num (inclusive). """ palindromic_numbers = [] for num in range(1, m...
from solution import is_palindromic_number, generate_palindromic_numbers def test_is_palindromic_number(): assert is_palindromic_number(121) == True assert is_palindromic_number(12321) == True assert is_palindromic_number(123) == False assert is_palindromic_number(5) == True def test_generate_palindro...
[ { "docstring": "Checks if a given number is palindromic.", "function_declaration": "def is_palindromic_number(num):", "function_name": "is_palindromic_number", "parameter_list": "(num)" }, { "docstring": "Generates a list of palindromic numbers from 1 to max_num (inclusive).", "function_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_palindromic_numbers(M):\n \"\"\"\n Generates a list of palindromic numbers from 1 to M (inclusive).\n\n Args:\n M (int): The maximum number up to which palindromic num...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037895", "row_id": 37895, "seed_ids": "['Qwen2-72B-Instruct_83875']" }
0.637126
Filter_37895
I
[ "is_palindromic_number", "generate_palindromic_numbers" ]
2
[ [ "generate_palindromic_numbers", "is_palindromic_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ed9d28296e3d7568842af32b36849b674f2016b
c86190aa672e869f8492bda0812b94574204bee1
v1.0
instruct
Filter
Filter_37939_I
Write a Python script that requires user input and verification of the input. The script should prompt the user to input their name and age as a number. The script should verify if the input for age is a valid number. If it is not a number, it should prompt the user to input age again. Upon successful input, the script...
def get_user_details(): """ Prompts the user for their name and age. Ensures the age input is a valid number and returns the name and age. """ name = input("Please enter your name: ") while True: age_input = input("Please enter your age: ") if age_input.isdigit(): age...
import pytest from unittest.mock import patch from solution import get_user_details, greet_user def test_get_user_details_valid_age(): with patch('builtins.input', side_effect=["John", "25"]): name, age = get_user_details() assert name == "John" assert age == 25 def test_get_user_details_i...
[ { "docstring": "Prompts the user for their name and age.\nEnsures the age input is a valid number and returns the name and age.", "function_declaration": "def get_user_details():", "function_name": "get_user_details", "parameter_list": "()" }, { "docstring": "Greets the user by their name an...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_user_input():\n \"\"\"\n This function prompts the user to input their name and age.\n It verifies that the input for age is a valid number.\n \"\"\"\n name = input(\"Pl...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037939", "row_id": 37939, "seed_ids": "['Qwen2-72B-Instruct_83943']" }
0.416581
Filter_37939
I
[ "get_user_details", "greet_user" ]
2
[ [ "greet_user", "get_user_details" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38f7f2e6258152711e7beb38d62c87d75bb9d617
e763cc0288e807c76c3f52dcf0c85786da62031e
v1.0
instruct
Filter
Filter_37952_I
Arithmetic operations can often be executed either recursively or iteratively. Write both iterative and recursive implementations of the following arithmetic operations: addition, multiplication, and power. Each implementation should be a function that gets as input two positive integers and returns the result as an in...
def iterative_add(a, b): """ Returns the sum of a and b iteratively. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def recursive_add(a, b): """ Returns the sum of a and b recursively. """ if b == 0: return a else: retur...
from solution import ( iterative_add, recursive_add, iterative_multiply, recursive_multiply, iterative_power, recursive_power ) # Testing Addition def test_iterative_add(): assert iterative_add(2, 3) == 5 assert iterative_add(0, 0) == 0 assert iterative_add(10, 15) == 25 def test_recursive_a...
[ { "docstring": "Returns the sum of a and b iteratively.", "function_declaration": "def iterative_add(a, b):", "function_name": "iterative_add", "parameter_list": "(a, b)" }, { "docstring": "Returns the sum of a and b recursively.", "function_declaration": "def recursive_add(a, b):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def iterative_addition(a, b):\n \"\"\"\n Returns the sum of a and b using an iterative approach.\n \"\"\"\n while b != 0:\n carry = a & b\n a = a ^ b\n b = car...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037952", "row_id": 37952, "seed_ids": "['Qwen2-72B-Instruct_83963']" }
0.634455
Filter_37952
I
[ "iterative_add", "recursive_add", "iterative_multiply", "recursive_multiply", "iterative_power", "recursive_power" ]
6
[ [ "iterative_multiply", "iterative_add" ], [ "iterative_power", "iterative_multiply" ], [ "recursive_multiply", "recursive_add" ], [ "recursive_power", "recursive_multiply" ] ]
4
[]
false
[]
false
pytest
true
[]
true
409331eaf947986bac819c33198b50d809b32b6e
27c56197356c6989b9e9224a53169b9f0065af07
v1.0
instruct
Filter
Filter_37960_I
Given a list of MAC addresses, write a program that identifies which addresses correspond to devices that have been registered with a specific governing body, such as IEEE. Additionally, implement a function to determine the manufacturer of the device based on the first three octets, or OUI (Organizationally Unique Ide...
import re # This is a simulated database of MAC OUIs with their corresponding manufacturers. OUI_DATABASE = { '00:00:0A': 'IBM', '00:0A:E6': 'Motorola', '00:14:22': 'Dell', '00:1B:77': 'Cisco', '00:1C:BF': 'Apple' } def normalize_mac_address(mac): """ Normalizes the MAC address to a standa...
from solution import normalize_mac_address, extract_oui, get_manufacturer, identify_registered_devices def test_normalize_mac_address(): assert normalize_mac_address('00:1B:77:6D:52:1C') == '00:1B:77:6D:52:1C' assert normalize_mac_address('001B.776D.521C') == '00:1B:77:6D:52:1C' assert normalize_mac_addres...
[ { "docstring": "Normalizes the MAC address to a standard format (XX:XX:XX:XX:XX:XX).", "function_declaration": "def normalize_mac_address(mac):", "function_name": "normalize_mac_address", "parameter_list": "(mac)" }, { "docstring": "Extracts the OUI (first three octets) from the MAC address....
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "oui_database = {\n \"00:1A:2B\": \"Company A\",\n \"00-1B-2C\": \"Company B\",\n \"00.1C.2D\": \"Company C\"\n}\n\ndef clean_mac_address(mac_address):\n \"\"\"\n Cleans a MAC ad...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037960", "row_id": 37960, "seed_ids": "['Qwen2-72B-Instruct_83977']" }
0.442678
Filter_37960
I
[ "normalize_mac_address", "extract_oui", "get_manufacturer", "identify_registered_devices" ]
4
[ [ "extract_oui", "normalize_mac_address" ], [ "get_manufacturer", "extract_oui" ], [ "identify_registered_devices", "get_manufacturer" ] ]
3
[]
false
[]
false
pytest
true
[]
true
613c3725ed897985a072eda796a629312060beb7
6b13910ba3901154c43cdc90206491787fbdc7cb
v1.0
instruct
Filter
Filter_37983_I
Create a Python function which takes an array of integers as input and returns an array of the prime numbers. The function should only use basic programming constructs and mathematical operations, and should not rely on any pre-defined functions or libraries for determining prime numbers.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) for d in range(3, max_divisor + 1, 2): if n % d == 0: return False ...
from solution import get_primes def test_get_primes_with_primes(): assert get_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_get_primes_with_mixed_numbers(): assert get_primes([2, 4, 6, 8, 10, 11, 13, 14, 15]) == [2, 11, 13] def test_get_primes_with_no_primes(): assert get_primes([4, 6, 8,...
[ { "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 an array of prime numbers from the given array of integers.", "function_declaration": "def get_prim...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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 True # 2 is the only even pr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037983", "row_id": 37983, "seed_ids": "['Qwen2-72B-Instruct_84020']" }
0.701983
Filter_37983
I
[ "is_prime", "get_primes" ]
2
[ [ "get_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b360055632b7cccebf0ca724162a6136d288f006
c86bb8eabf5d77f5925673460774a713c058af49
v1.0
instruct
Filter
Filter_37996_I
Write a python program that has the menu, "Temperature Converter","Number Checker","Exit". When a user selects 'Temperature Converter' the program will ask the user to for the format they are converting from and then to. The user then enters the temperature and the converted temperature of the switching from Celsius to...
def temperature_converter(): from_format = input("Enter the current temperature format (Celsius/Fahrenheit): ").strip().lower() to_format = input("Enter the format to convert to (Celsius/Fahrenheit): ").strip().lower() temp = float(input("Enter the temperature to convert: ")) if from_format == 'cel...
from solution import temperature_converter, number_checker def mock_input_temperature_converter(mock_inputs, monkeypatch): inputs = iter(mock_inputs) monkeypatch.setattr('builtins.input', lambda _: next(inputs)) return temperature_converter() def test_temperature_converter_c_to_f(monkeypatch): mock_in...
[ { "docstring": null, "function_declaration": "def temperature_converter():", "function_name": "temperature_converter", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def number_checker():", "function_name": "number_checker", "parameter_list": "()" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def temperature_converter():\n \"\"\"\n Converts temperature between Celsius and Fahrenheit.\n \"\"\"\n from_unit = input(\"Enter the unit you are converting from (C/F): \").strip(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037996", "row_id": 37996, "seed_ids": "['Qwen2-72B-Instruct_84046']" }
0.43903
Filter_37996
I
[ "temperature_converter", "number_checker", "main_menu" ]
3
[ [ "main_menu", "number_checker" ], [ "main_menu", "temperature_converter" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8487b116dd44aa4d0a2dcc7e9d0ef12b8a38fd17
1d7ec28a7e7b09f9720857ea3e7c94c62a03f90f
v1.0
instruct
Filter
Filter_37999_I
Develop a python code snippet to create a list, with elements of type integer from 0 to 1000. The list should only contain prime numbers.
def is_prime(n): """ Determine if the integer n is a prime number. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, generate_prime_list 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(997) == True assert is_prime(1000) == False def test_generate_prime_list(): prime_list = gene...
[ { "docstring": "Determine if the integer n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers from 0 to 1000.", "function_declaration": "def generate_prime_list():", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_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, int(n**0.5) + 1):\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037999", "row_id": 37999, "seed_ids": "['Qwen2-72B-Instruct_84051']" }
0.61455
Filter_37999
I
[ "is_prime", "generate_prime_list" ]
2
[ [ "generate_prime_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3023c91b51615404aadb8662eefbc5b4c67095c1
252f3b9c0c1b2da3261c703532783212790cac5f
v1.0
instruct
Filter
Filter_38011_I
Suggest and demonstrate a way in Python to generate random numbers between 1 and 6, simulating a dice roll, ensuring the results are uniformly distributed. Further, create a function to plot a histogram of a large number of these rolls to visually verify this.
import random import matplotlib.pyplot as plt def roll_dice(): """ Simulates rolling a dice by generating a random number between 1 and 6. """ return random.randint(1, 6) def plot_dice_rolls_histogram(num_rolls): """ Simulates rolling a dice num_rolls times and plots a histogram of the results...
import pytest from solution import roll_dice, plot_dice_rolls_histogram def test_roll_dice_within_range(): for _ in range(1000): result = roll_dice() assert 1 <= result <= 6 def test_roll_dice_uniform_distribution(): rolls_count = 10000 outcomes = [roll_dice() for _ in range(rolls_count)] ...
[ { "docstring": "Simulates rolling a dice by generating a random number between 1 and 6.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates rolling a dice num_rolls times and plots a histogram of the results.\n\nPara...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport matplotlib.pyplot as plt\n\ndef roll_dice():\n \"\"\"\n Simulates a roll of a dice, returning a random number between 1 and 6.\n \"\"\"\n return random.randin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038011", "row_id": 38011, "seed_ids": "['Qwen2-72B-Instruct_84069']" }
0.664912
Filter_38011
I
[ "roll_dice", "plot_dice_rolls_histogram" ]
2
[ [ "plot_dice_rolls_histogram", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
9b5e4bbb9b39dc9aeb220c5868762e937d9d368e
1068c22004bdf0147a93f5784b97f66d5ca8c949
v1.0
instruct
Filter
Filter_38033_I
Write the Python pseudocode algorithm for selecting the N-th smallest item from an unordered list of items, where N is any non-negative integer up to the length of the list. You are to use an efficient algorithm.
import random def partition(arr, left, right, pivot_index): pivot_value = arr[pivot_index] arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left for i in range(left, right): if arr[i] < pivot_value: arr[store_index], arr[i] = arr[i], arr[store_index] ...
from solution import nth_smallest_item def test_nth_smallest_item_normal_case(): assert nth_smallest_item([3, 1, 2, 1, 4, 5], 2) == 2 def test_nth_smallest_item_unique_elements(): assert nth_smallest_item([10, 4, 5, 8, 6, 11, 26], 3) == 8 def test_nth_smallest_item_with_duplicates(): assert nth_smallest_...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(arr, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(arr, left, right, n):", "function_name": "q...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quickselect(arr, n):\n \"\"\"\n Select the N-th smallest item from an unordered list.\n \n Parameters:\n arr (list): The list of unordered items.\n n (int): Zero-based in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038033", "row_id": 38033, "seed_ids": "['Qwen2-72B-Instruct_84110']" }
0.672858
Filter_38033
I
[ "partition", "quickselect", "nth_smallest_item" ]
3
[ [ "nth_smallest_item", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3e4f474e69ce16a6a89692a52a4094fd5baeda57
4b089cf17a01307d6fd5b1c0cc9c0055fde4e193
v1.0
instruct
Filter
Filter_38048_I
Write a Python script that evaluates whether a given year is a leap year or not. Your script should not only take the year as an input but should also handle invalid inputs (like strings, negative numbers, or future years beyond 2099) gracefully by displaying an appropriate error message. Additionally, the script shoul...
def is_leap_year(year): """ Evaluates whether a given year is a leap year. Args: year (int): The year to evaluate. Returns: bool: True if the year is a leap year, False otherwise. """ if isinstance(year, int) and 0 <= year <= 2099: if (year % 4 == 0 and year % 100 != 0)...
from solution import is_leap_year, evaluate_years def test_is_leap_year_valid(): assert is_leap_year(2000) == True assert is_leap_year(1900) == False assert is_leap_year(2004) == True assert is_leap_year(2001) == False def test_is_leap_year_invalid(): assert is_leap_year(-100) == False assert ...
[ { "docstring": "Evaluates whether a given year is a leap year.\n\nArgs:\nyear (int): The year to evaluate.\n\nReturns:\nbool: True if the year is a leap year, False otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Returns True if the year is a leap year, False otherwise.\n \"\"\"\n return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n\ndef evalu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038048", "row_id": 38048, "seed_ids": "['Qwen2-72B-Instruct_84139']" }
0.601079
Filter_38048
I
[ "is_leap_year", "evaluate_years" ]
2
[ [ "evaluate_years", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee4bfce8c9e598f5ee6bb20b26eafcaf4a1f7177
9a23e35a2f1d39478ab95e129e783e11adb32cf8
v1.0
instruct
Filter
Filter_38055_I
Write a python code for a for loop that iterates over a list of numbers and prints the square of each number, but only if the number is prime. Additionally, implement a check to ensure that the list contains only positive integers.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def print_square_of_prime_numbers(numbers): """ Iterate over a list of numbers and print the square of eac...
from solution import is_prime, print_square_of_prime_numbers 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 def test_print_square_of_prime_numbers(capsys): print_square_of_prime_numb...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Iterate over a list of numbers and print the square of each number if it is prime.\nEnsures the list contains only positive intege...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Check if the provided number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038055", "row_id": 38055, "seed_ids": "['Qwen2-72B-Instruct_84153']" }
0.701978
Filter_38055
I
[ "is_prime", "print_square_of_prime_numbers" ]
2
[ [ "print_square_of_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc2af4339ce28543b7a0072c381b905aacbbe071
55bd49f3770eb4ebb71e5a21e8ef768aedbca33b
v1.0
instruct
Filter
Filter_38063_I
Write a Python script to download (Wget) a web page from the internet and save it to disk without using any external libraries like BeautifulSoup, requests, etc. Additionally, write functions to validate the URL format and handle different HTTP status codes. Below is a piece of code with some errors. Find and correct t...
import re import urllib.request def validate_url(url): """ Validate the URL format. Return True if URL is valid, otherwise False. """ regex = re.compile( r'^(?:http|ftp)s?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' ...
from solution import validate_url, download_web_page import os def test_validate_url(): assert validate_url('http://www.example.com') == True assert validate_url('https://www.example.com') == True assert validate_url('ftp://www.example.com') == True assert validate_url('http://localhost') == True a...
[ { "docstring": "Validate the URL format.\nReturn True if URL is valid, otherwise False.", "function_declaration": "def validate_url(url):", "function_name": "validate_url", "parameter_list": "(url)" }, { "docstring": "Download the web page from the given URL and save it to disk with the give...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import socket\n\ndef validate_url(url):\n \"\"\"\n Validate the URL format to ensure it starts with 'http://' or 'https://'.\n \"\"\"\n return url.startswith('http://') or url.star...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038063", "row_id": 38063, "seed_ids": "['Qwen2-72B-Instruct_84171']" }
0.584603
Filter_38063
I
[ "validate_url", "download_web_page" ]
2
[ [ "download_web_page", "validate_url" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6f7ab72c5ae7f84f31671c9d1538e51464d8930
897169bf3f413848e948d3adf907b9aa0388deb6
v1.0
instruct
Filter
Filter_38064_I
Develop a function that calculates the factors of a given number, but only returns those that are prime numbers. Consider inputting larger numbers and handle any potential performance issues to ensure that the function operates smoothly. Include a verification segment to ascertain the correctness of your function throu...
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import prime_factors, is_prime def test_prime_factors_small(): assert prime_factors(10) == [2, 5] assert prime_factors(15) == [3, 5] def test_prime_factors_large(): assert prime_factors(101) == [101] assert prime_factors(13195) == [5, 7, 13, 29] def test_prime_factors_prime_number(): ...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return a list of prime factors of a given number n.", "function_declaration": "def prime_factors(n):", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determine if the given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038064", "row_id": 38064, "seed_ids": "['Qwen2-72B-Instruct_84173']" }
0.586719
Filter_38064
I
[ "is_prime", "prime_factors" ]
2
[ [ "prime_factors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec731edb895e2e0c4f895111b099985900a1a0c9
bf5a904ba627b1052bd3fa6b7b0f6a23d959672e
v1.0
instruct
Filter
Filter_38077_I
Formulate a Python-based computational mechanism to output the Fibonacci sequence, specifically focussing on a variant where the series starts from zero and one. Until an excluded ordinal number (representation of position) of 10, the sequential iterable numeric elements ought to be exhibited. The computational solutio...
def fibonacci(n, memo={}): """ Computes the nth Fibonacci number using memoization. """ if n in memo: return memo[n] if n <= 1: return n memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo) return memo[n] def fibonacci_sequence(upto): """ Returns a list containi...
from solution import fibonacci_sequence def test_fibonacci_starting_sequence(): assert fibonacci_sequence(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def test_fibonacci_single_element(): assert fibonacci_sequence(1) == [0] def test_fibonacci_two_elements(): assert fibonacci_sequence(2) == [0, 1] def test_f...
[ { "docstring": "Computes the nth Fibonacci number using memoization.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": "fibonacci", "parameter_list": "(n, memo={})" }, { "docstring": "Returns a list containing Fibonacci sequence up to the 'upto' position (exclusive).",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Returns the nth number in Fibonacci sequence using memoization.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 0:\n retu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038077", "row_id": 38077, "seed_ids": "['Qwen2-72B-Instruct_84194']" }
0.718302
Filter_38077
I
[ "fibonacci", "fibonacci_sequence" ]
2
[ [ "fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
825ccb25316fdd307d5219fb3f76c11f6e75f354
7a20ff0beb510a94cefdc1f31040335f7bfdabe7
v1.0
instruct
Filter
Filter_38093_I
Write a Python decorator that takes a function as an argument and returns a modified version of the function that only executes if the current date is a prime number and the weekday is not a weekend day (Monday to Friday only). Also, implement a check mechanism in function to confirm the date is in the correct format (...
import datetime 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 ...
import pytest from solution import is_prime, date_is_valid, only_on_prime_and_weekday 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 is_prime(13) assert not is_prime(20) def test_date_is_valid(): assert...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a date is in the valid format.", "function_declaration": "def date_is_valid(year, month, day):", "functi...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import datetime\n\ndef is_prime(n):\n \"\"\"\n Checks if a given number `n` is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) +...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038093", "row_id": 38093, "seed_ids": "['Qwen2-72B-Instruct_84217']" }
0.674672
Filter_38093
I
[ "is_prime", "date_is_valid", "only_on_prime_and_weekday", "sample_function" ]
4
[ [ "only_on_prime_and_weekday", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c2a89ad3e09ea2647e935d689cd99abc1511727e
c96b941e6871179304d5f8fbbf27b1c6979d9d38
v1.0
instruct
Filter
Filter_38095_I
Write a Python program that takes a list of numbers as input, and returns a list containing only the distinct prime numbers from the input list.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, distinct_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == F...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return a list of distinct prime numbers from the input list.", "function_declaration": "def distinct_primes(numbers):", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038095", "row_id": 38095, "seed_ids": "['Qwen2-72B-Instruct_84221']" }
0.607839
Filter_38095
I
[ "is_prime", "distinct_primes" ]
2
[ [ "distinct_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ecaa4ea89e438f0be6ec82bc902b2769a67d2d1b
e9d3b33519aba44998a7ba115a2951532dbdaa2e
v1.0
instruct
Filter
Filter_38106_I
Create a function in Python that takes two parameters, x and y, and prints out all prime numbers between x and y.
def is_prime(num): """ 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 print_primes(x, y): """ Print all prime numbers between x and y. """ for num in range(...
from solution import is_prime, print_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Print all prime numbers between x and y.", "function_declaration": "def print_primes(x, y):", "function_name": "print_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef print_primes_between(x...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038106", "row_id": 38106, "seed_ids": "['Qwen2-72B-Instruct_84242']" }
0.709131
Filter_38106
I
[ "is_prime", "print_primes" ]
2
[ [ "print_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
188e8c4f1a8de9e577cdc5c9444ec4cd6c95afa1
87633caf9ee7c09badb2a85b31131e094194d640
v1.0
instruct
Filter
Filter_38114_I
Write code for a series of recursive functions to compute the first 10 Fibonacci numbers. The code should not use any loops and should also avoid re-computing previously computed Fibonacci numbers.
def fib_memo(n, memo=None): """ Returns the nth Fibonacci number using memoization. """ if memo is None: memo = {} if n in memo: return memo[n] if n <= 0: return 0 elif n == 1: return 1 else: result = fib_memo(n-1, memo) + fib_memo(n-2, memo) ...
from solution import fib_memo, first_10_fibonacci def test_fib_memo(): assert fib_memo(0) == 0 assert fib_memo(1) == 1 assert fib_memo(2) == 1 assert fib_memo(3) == 2 assert fib_memo(4) == 3 assert fib_memo(5) == 5 assert fib_memo(6) == 8 assert fib_memo(7) == 13 assert fib_memo(8) ...
[ { "docstring": "Returns the nth Fibonacci number using memoization.", "function_declaration": "def fib_memo(n, memo=None):", "function_name": "fib_memo", "parameter_list": "(n, memo=None)" }, { "docstring": "Returns a list of the first 10 Fibonacci numbers.", "function_declaration": "def...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n, memo=None):\n \"\"\"\n Returns the nth Fibonacci number using recursion and memoization.\n \"\"\"\n if memo is None:\n memo = {}\n\n if n <= 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038114", "row_id": 38114, "seed_ids": "['Qwen2-72B-Instruct_84258']" }
0.682065
Filter_38114
I
[ "fib_memo", "first_10_fibonacci" ]
2
[ [ "first_10_fibonacci", "fib_memo" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94f5126bff6adac8471c95e066747d37cb352478
f937757834cc8839c7407e5f9dfa255181fb0a72
v1.0
instruct
Filter
Filter_38124_I
Write a Python generator function that generates the Fibonacci sequence. Instead of producing an infinite sequence, modify the sequence to stop when the number generated would be larger than 1 million. How can you use this generator to print the last number generated as well as the total number of numbers generated?
def fibonacci_generator(): """ A generator function that yields the Fibonacci sequence up to numbers <= 1,000,000. """ a, b = 0, 1 while a <= 1000000: yield a a, b = b, a + b def fibonacci_statistics(): """ Uses the fibonacci_generator to print the last number generated and ...
from solution import fibonacci_generator, fibonacci_statistics def test_fibonacci_generator(): fib_nums = list(fibonacci_generator()) # Check that all numbers are less than or equal to 1,000,000 assert all(x <= 1000000 for x in fib_nums) # Check that the sequence is correct expected_sequence = [0, ...
[ { "docstring": "A generator function that yields the Fibonacci sequence up to numbers <= 1,000,000.", "function_declaration": "def fibonacci_generator():", "function_name": "fibonacci_generator", "parameter_list": "()" }, { "docstring": "Uses the fibonacci_generator to print the last number ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(limit=1000000):\n \"\"\"\n A generator that yields Fibonacci numbers until the value would exceed 1,000,000.\n \"\"\"\n a, b = 0, 1\n while a <= limit:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038124", "row_id": 38124, "seed_ids": "['Qwen2-72B-Instruct_84281']" }
0.632136
Filter_38124
I
[ "fibonacci_generator", "fibonacci_statistics" ]
2
[ [ "fibonacci_statistics", "fibonacci_generator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1da77053e481c8c0dd3fb8341686e80e6cd28076
e9b56e869ae42b0975839652cbab8f96c59b983b
v1.0
instruct
Filter
Filter_38129_I
Modify a function to determine whether two given input strings include the same unique words, while disregarding case sensitivity, punctuation, and common English stop words. Additionally, identify and fix errors in the provided code snippet.
import string def get_unique_words(text): """ Returns a set of unique words found in the given text, excluding common English stop words, punctuation, and considering case-insensitivity. """ stop_words = set(["i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", ...
from solution import same_unique_words def test_same_unique_words_basic(): assert same_unique_words("Hello world!", "Hello World.") == True def test_same_unique_words_with_stopwords(): assert same_unique_words("This is a test.", "A test this is.") == True def test_different_unique_words(): assert same_un...
[ { "docstring": "Returns a set of unique words found in the given text, excluding common English stop words, \npunctuation, and considering case-insensitivity.", "function_declaration": "def get_unique_words(text):", "function_name": "get_unique_words", "parameter_list": "(text)" }, { "docstr...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "import string\n\ndef get_unique_words(text):\n \"\"\"\n Returns a set of unique words found in the given text, excluding common English stop words, \n punctua...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038129", "row_id": 38129, "seed_ids": "['Qwen2-72B-Instruct_84291']" }
0.673739
Filter_38129
I
[ "get_unique_words", "same_unique_words" ]
2
[ [ "same_unique_words", "get_unique_words" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f908498f326872f6d783c876914944b09042a73
a4684f3a40339f8b275b145044407e42b7f2b2b8
v1.0
instruct
Filter
Filter_38139_I
Write the Python code to find all prime numbers between 1 and N (both inclusive), where N is an integer given by the user. Also, your solution must incorporate function usage and error handling if the user input is not a valid integer or if the value of N is less than 1.
def is_prime(n): """ Check if a number is a prime number. Parameters: n (int): The number to check Returns: bool: 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 ...
import pytest from solution import is_prime, find_primes 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(27) == False assert is_prime(29) == True def test_find_primes_valid_input(): assert fi...
[ { "docstring": "Check if a number is a prime number.\n\nParameters:\nn (int): The number to check\n\nReturns:\nbool: True if n is a prime number, False otherwise", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all pr...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \n Parameters:\n n (int): The number to check\n \n Returns:\n bool: True if n is a prime number, Fals...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00038139", "row_id": 38139, "seed_ids": "['Qwen2-72B-Instruct_84309']" }
0.707847
Filter_38139
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b53605500d14dc361cfdb60f374942dd3ba23007
f230079c6dc5ee185e2a89ea0e37ccd5536e1b13
v1.0
instruct
Filter
Filter_38161_I
Input two strings and compile a regex to check if the second string is a subsequence of the first string. Moreover, the regex should also validate that the subsequence is not part of a larger, matching subsequence. For example, if the first string is "character" and the second is "car", the regex should fail to match "...
import re def compile_subsequence_regex(main_string, sub_string): """ Compiles a regex pattern to check if sub_string is a subsequence of main_string and is not part of a larger matching subsequence. """ escaped_sub_string = re.escape(sub_string) pattern = f'\\b{escaped_sub_string}\\b' # Word...
from solution import compile_subsequence_regex, is_valid_subsequence def test_compile_subsequence_regex(): regex = compile_subsequence_regex("character", "car") assert regex.pattern == r'\bcar\b' def test_is_valid_subsequence_exact_match(): assert is_valid_subsequence("car", "car") == True def test_is_va...
[ { "docstring": "Compiles a regex pattern to check if sub_string is a subsequence \nof main_string and is not part of a larger matching subsequence.", "function_declaration": "def compile_subsequence_regex(main_string, sub_string):", "function_name": "compile_subsequence_regex", "parameter_list": "(m...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef compile_subsequence_regex(main_string, sub_string):\n \"\"\"\n Compiles a regex pattern to check if sub_string is a subsequence \n of main_string and is not part of a...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00038161", "row_id": 38161, "seed_ids": "['Qwen2-72B-Instruct_84342']" }
0.676947
Filter_38161
I
[ "compile_subsequence_regex", "is_valid_subsequence" ]
2
[ [ "is_valid_subsequence", "compile_subsequence_regex" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0590218b8420c69f4e571ef0f7f1ef3e9caded0f
e5c03bdbb502f932395c69e4cb79fb46b3b5ea8c
v1.0
instruct
Filter
Filter_38166_I
Write a function named "log_squared" that takes one parameter, "num_array", which is an array of positive integers, and returns a new array where each element is the base 10 logarithm of the square of the corresponding element in the input array, rounded to 3 decimal places. Additionally, modify the function to filter ...
import math def is_perfect_square(n): return int(math.sqrt(n)) ** 2 == n def log_squared(num_array): """ Returns an array where each element is the base 10 logarithm of the square of the corresponding element in the input array that are perfect squares, rounded to 3 decimal places. """ r...
from solution import log_squared import math def test_log_squared_all_perfect_squares(): result = log_squared([1, 4, 9, 16]) expected = [round(math.log10(1**2), 3), round(math.log10(4**2), 3), round(math.log10(9**2), 3), round(math.log10(16**2), 3)] assert result == expected def test_log_squared_no_perfec...
[ { "docstring": null, "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Returns an array where each element is the base 10 logarithm of the square \nof the corresponding element in the input array that are per...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(n):\n return int(math.sqrt(n)) ** 2 == n\n\ndef log_squared(num_array):\n \"\"\"\n Returns an array where each element is the base 10 logarithm of...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00038166", "row_id": 38166, "seed_ids": "['Qwen2-72B-Instruct_84352']" }
0.507063
Filter_38166
I
[ "is_perfect_square", "log_squared" ]
2
[ [ "log_squared", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
00a03e2614dd68e128636dcc5e053f2ee422fc68
5ac1f950dcb6f0f4238623561e07dcb0de8ee0af
v1.0
instruct
Filter
Filter_38180_I
Write a Python function that takes in a list of homepage URLs of top 10 e-commerce websites and returns a dictionary with the domain names as keys and TLDs (top-level domains) as values. Additionally, use a Beautiful Soup library to scrape the homepage of each website and calculate the approximate number of products li...
from bs4 import BeautifulSoup import requests from urllib.parse import urlparse def get_domain_and_tld(url): """ Extracts the domain and top-level domain (TLD) from a given URL. Parameters: url (str): The URL to process. Returns: dict: A dictionary with the domain as the ...
from solution import get_domain_and_tld, count_product_cards, analyze_ecommerce_websites import requests from unittest.mock import patch, Mock def test_get_domain_and_tld(): url = "https://www.example.com" result = get_domain_and_tld(url) assert result == {"example": "com"} def test_count_product_cards():...
[ { "docstring": "Extracts the domain and top-level domain (TLD) from a given URL.\n\nParameters:\n url (str): The URL to process.\n \nReturns:\n dict: A dictionary with the domain as the key and the TLD as the value.", "function_declaration": "def get_domain_and_tld(url):", "function_name": "get...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nfrom urllib.parse import urlparse\n\ndef get_domain_and_tld(url):\n \"\"\"\n Extracts domain and top-level domain from a URL.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038180", "row_id": 38180, "seed_ids": "['Qwen2-72B-Instruct_84384']" }
0.517612
Filter_38180
I
[ "get_domain_and_tld", "count_product_cards", "analyze_ecommerce_websites" ]
3
[ [ "analyze_ecommerce_websites", "count_product_cards" ], [ "analyze_ecommerce_websites", "get_domain_and_tld" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
f977e85b724c84d142787c85910045f9afb30056
43cb0a4e3441dcef4ece86ca903415e77503f840
v1.0
instruct
Filter
Filter_38210_I
Explain the code in this Python snippet that utilizes a generator function to compute Fibonacci numbers. Now, also modify the code to add the ability to filter out all Fibonacci numbers that aren't primes (i.e., remove any Fibonacci numbers that are not primes) while ensuring the performance impact is minimal.
def fibonacci(): """ A generator function that yields Fibonacci numbers indefinitely. """ a, b = 0, 1 while True: yield a a, b = b, a + b def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True ...
from solution import fibonacci_primes def test_fibonacci_primes(): gen = fibonacci_primes() assert next(gen) == 2 assert next(gen) == 3 assert next(gen) == 5 assert next(gen) == 13 assert next(gen) == 89 def test_is_prime(): from solution import is_prime assert is_prime(0) == False ...
[ { "docstring": "A generator function that yields Fibonacci numbers indefinitely.", "function_declaration": "def fibonacci():", "function_name": "fibonacci", "parameter_list": "()" }, { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci():\n \"\"\"\n Generator function to compute Fibonacci numbers.\n Yields one Fibonacci number at a time.\n \"\"\"\n a, b = 0, 1\n while True:\n yield a\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038210", "row_id": 38210, "seed_ids": "['Qwen2-72B-Instruct_84436']" }
0.645435
Filter_38210
I
[ "fibonacci", "is_prime", "fibonacci_primes" ]
3
[ [ "fibonacci_primes", "fibonacci" ], [ "fibonacci_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e2efaec57b130412cd4f09e76ec3e77db8b8667f
8de5756d270ad358ffa75cafb2d2135424640ab5
v1.0
instruct
Filter
Filter_38219_I
Write a simple digital high-pass filter in Python using the Butterworth filter design.
import numpy as np from scipy.signal import butter, filtfilt def butter_highpass(cutoff, fs, order=5): """ Designs a Butterworth high-pass filter. Args: - cutoff (float): The cutoff frequency of the filter. - fs (float): The sample rate. - order (int): The order of the filter. Returns...
import numpy as np from solution import butter_highpass, highpass_filter def test_butter_highpass(): b, a = butter_highpass(10, 100) assert isinstance(b, np.ndarray) assert isinstance(a, np.ndarray) assert len(b) == 6 # order 5 filter -> b has length order+1 assert len(a) == 6 # order 5 filter ->...
[ { "docstring": "Designs a Butterworth high-pass filter.\n\nArgs:\n- cutoff (float): The cutoff frequency of the filter.\n- fs (float): The sample rate.\n- order (int): The order of the filter.\n\nReturns:\n- b, a (ndarray, ndarray): The filter coefficients.", "function_declaration": "def butter_highpass(cut...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from scipy.signal import butter, filtfilt\n\ndef butter_highpass(cutoff, fs, order=5):\n \"\"\"\n Design a digital high-pass filter using Butterworth filter.\n \n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038219", "row_id": 38219, "seed_ids": "['Qwen2-72B-Instruct_84458']" }
0.447322
Filter_38219
I
[ "butter_highpass", "highpass_filter" ]
2
[ [ "highpass_filter", "butter_highpass" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
cc231dd2c1be264a8872240eb1431760612e824d
b84717926153eea4b982b3cddd68878afa0f14ef
v1.0
instruct
Filter
Filter_38226_I
I am working on a project that requires me to develop a basic GAN (Generative Adversarial Network) using PyTorch. This is my first time handling GANs, and I require a detailed walkthrough on refining a script for implementing a basic GAN. Additionally, I would be grateful if you could also provide some essential instru...
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset # Define the generator network class Generator(nn.Module): def __init__(self, input_dim, output_dim): super(Generator, self).__init__() self.model = nn.Sequential( nn.Li...
import pytest import torch from torch.utils.data import DataLoader, TensorDataset from solution import Generator, Discriminator, initialize_models, train_gan def test_models_initialization(): generator_input_dim = 100 generator_output_dim = 784 discriminator_input_dim = 784 generator, discriminato...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torchvision import datasets, transforms\n\n# Generator Model\nclass Generator(nn.Module):\n def __init__(self, input_d...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038226", "row_id": 38226, "seed_ids": "['Qwen2-72B-Instruct_84466']" }
0.204017
Filter_38226
I
[ "weights_init", "initialize_models", "train_gan" ]
3
[ [ "initialize_models", "weights_init" ] ]
1
[]
false
[ "Generator", "Discriminator" ]
true
pytest
true
[ "torch" ]
false
90f1713b3eb621d8e3f0135e9e17515ddddec727
e98f842d19df0e3249108b1f1df238e92334088c
v1.0
instruct
Filter
Filter_38228_I
Write code to combine a series of dictionaries into a single one, while also ensuring that the resulting dictionary only contains key-value pairs where the key is a string and the value is a positive integer that is a prime number.
def is_prime(n): """ Checks if a given integer n is a prime number. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def combine_dicts(*dicts): """ Combines multiple dictionaries into a single dictionar...
from solution import is_prime, combine_dicts def test_is_prime(): assert is_prime(2) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False def test_combine_dicts(): dict1 = {'a': 2, 'b': 3, 'c': 4} dict2 = {'d': 5, 'e': '6',...
[ { "docstring": "Checks if a given integer n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Combines multiple dictionaries into a single dictionary,\nkeeping only key-value pairs where the key is a strin...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a given integer n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00038228", "row_id": 38228, "seed_ids": "['Qwen2-72B-Instruct_84471']" }
0.613058
Filter_38228
I
[ "is_prime", "combine_dicts" ]
2
[ [ "combine_dicts", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f880cbce117b8550bee7c7c6b8d0d49a1600ea90
960a9e0a1fef7fb14ca219b581caa58d458f22f8
v1.0
instruct
Filter
Filter_38230_I
Design a basic program module that, given a singly linked list of integral values, can redefine the list by eliminating any elements that are either less than zero or prime numbers. Such an algorithm should finally output the revised list, and your solution should also include input validation.
class Node: def __init__(self, data): self.data = data self.next = None 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: ...
from solution import Node, filter_linked_list def list_to_linked_list(array): if not array: return None head = Node(array[0]) current = head for item in array[1:]: current.next = Node(item) current = current.next return head def linked_list_to_list(head): current = head...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n \"\"\"\n Node in a singly linked list.\n \"\"\"\n def __init__(self, data=0, next_node=None):\n self.data = data\n self.next = next_node\n\ndef is_p...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038230", "row_id": 38230, "seed_ids": "['Qwen2-72B-Instruct_84476']" }
0.499265
Filter_38230
I
[ "is_prime", "filter_linked_list" ]
2
[ [ "filter_linked_list", "is_prime" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
23da4ab5bb1ed2f0bc6e3ab1c0077e7823a68e29
61a06f12212402e246f9238bd8436de09c6e2ae2
v1.0
instruct
Filter
Filter_38234_I
Now, considering a list of n elements where the list is unsorted, how would you modify your algorithm to locate the value x in the list? Write a Python function to implement the modified algorithm, taking into account the need to sort the list prior to applying binary search. You also need to include a check for empty ...
def binary_search(arr, x): """ This function takes a sorted list 'arr' and a value 'x', and returns the index of 'x' if present in 'arr', else returns -1. """ left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 # Check if x is present at mid ...
from solution import find_value_in_unsorted_list def test_find_value_in_unsorted_list_value_present(): assert find_value_in_unsorted_list([4, 2, 5, 1, 3], 3) == 2 def test_find_value_in_unsorted_list_value_absent(): assert find_value_in_unsorted_list([4, 2, 5, 1, 3], 6) == -1 def test_find_value_in_empty_lis...
[ { "docstring": "This function takes a sorted list 'arr' and a value 'x', and \nreturns the index of 'x' if present in 'arr', else returns -1.", "function_declaration": "def binary_search(arr, x):", "function_name": "binary_search", "parameter_list": "(arr, x)" }, { "docstring": "This functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def search_in_unsorted_list(data, x):\n \"\"\"\n Searches for the value x in an unsorted list data, using sorting and binary search.\n \n Parameters:\n data (list): The list of ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038234", "row_id": 38234, "seed_ids": "['Qwen2-72B-Instruct_84484']" }
0.603664
Filter_38234
I
[ "binary_search", "find_value_in_unsorted_list" ]
2
[ [ "find_value_in_unsorted_list", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
266556ee4945ea99865d412ca8d6368136038a20
08209ec8f059abae0e3690e638130786442cf37c
v1.0
instruct
Filter
Filter_38240_I
Design a Python function that identifies and returns all narcissistic numbers that are less than or equivalent to a given integer input.
def is_narcissistic(number): """ Checks if a number is a narcissistic number. A number is considered narcissistic if it is equal to the sum of its own digits each raised to the power of the number of digits. """ digits = [int(d) for d in str(number)] power = len(digits) return sum(d ** p...
from solution import is_narcissistic, find_narcissistic_numbers def test_is_narcissistic(): assert is_narcissistic(153) == True assert is_narcissistic(370) == True assert is_narcissistic(371) == True assert is_narcissistic(407) == True assert is_narcissistic(7) == True assert is_narcissistic(10...
[ { "docstring": "Checks if a number is a narcissistic number.\nA number is considered narcissistic if it is equal to the sum of its own digits each raised to the power\nof the number of digits.", "function_declaration": "def is_narcissistic(number):", "function_name": "is_narcissistic", "parameter_li...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_narcissistic(number):\n \"\"\"\n Helper function to check if a number is a narcissistic number.\n A narcissistic number is a number that is equal to the sum of its own digits e...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038240", "row_id": 38240, "seed_ids": "['Qwen2-72B-Instruct_84492']" }
0.586456
Filter_38240
I
[ "is_narcissistic", "find_narcissistic_numbers" ]
2
[ [ "find_narcissistic_numbers", "is_narcissistic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3667271fd4b2c3e2cc1f48f8112aaeeeab381260
9938379ca07e2859e788be13c1398f28214538f8
v1.0
instruct
Filter
Filter_38268_I
Write a Python program that implements the merge sort algorithm to sort a list of student exam scores in ascending order, then reverse the sorted list without using the reverse function. Also, add an error handling mechanism to catch and print a message if the list input is not valid (for example, it contains non-numer...
def merge_sort(arr): """ Implement the merge sort algorithm to sort a list of student exam scores in ascending order. """ 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)...
from solution import sort_and_reverse def test_sort_and_reverse_empty_list(): assert sort_and_reverse([]) == [] def test_sort_and_reverse_single_element(): assert sort_and_reverse([5]) == [5] def test_sort_and_reverse_multiple_elements(): assert sort_and_reverse([33, 21, 59, 40, 3]) == [59, 40, 33, 21, 3...
[ { "docstring": "Implement the merge sort algorithm to sort a list of student exam scores in ascending order.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Sorts the input list in ascending order using merge sort ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Function to perform merge sort on the given list.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038268", "row_id": 38268, "seed_ids": "['Qwen2-72B-Instruct_84546']" }
0.579681
Filter_38268
I
[ "merge_sort", "sort_and_reverse" ]
2
[ [ "sort_and_reverse", "merge_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e8b4ce6a371566fb0200896eaebb2a6e4a17077
4130e3bf342ee657674440bda72c477313552850
v1.0
instruct
Filter
Filter_38270_I
You are tasked with creating a Python function to find the closest cluster to a given location based on distance. The function should take in the current longitude and latitude of the location, as well as a list of clusters, and return the label of the closest cluster. Each cluster is represented as a dictionary contai...
import math def haversine_distance(lon1, lat1, lon2, lat2): """ Calculate the great circle distance in kilometers between two points on the earth (specified in decimal degrees). """ # convert decimal degrees to radians lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2]) #...
from solution import find_closest_cluster def test_find_closest_cluster_single_cluster(): clusters = [{'label': 'A', 'longitude': 0, 'latitude': 0}] assert find_closest_cluster(0, 0, clusters) == 'A' def test_find_closest_cluster_multiple_clusters(): clusters = [ {'label': 'A', 'longitude': 1, 'la...
[ { "docstring": "Calculate the great circle distance in kilometers between two points\non the earth (specified in decimal degrees).", "function_declaration": "def haversine_distance(lon1, lat1, lon2, lat2):", "function_name": "haversine_distance", "parameter_list": "(lon1, lat1, lon2, lat2)" }, {...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef haversine(lon1, lat1, lon2, lat2):\n \"\"\"\n Calculate the great-circle distance between two points\n on the Earth specified in decimal degrees.\n \"\"\"\n #...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038270", "row_id": 38270, "seed_ids": "['Qwen2-72B-Instruct_84552']" }
0.65041
Filter_38270
I
[ "haversine_distance", "find_closest_cluster" ]
2
[ [ "find_closest_cluster", "haversine_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b61acc19f92efe592d34c1eba011a05a60b14d9
2ac15dbd9c73fee7241bc034580b310bcae17699
v1.0
instruct
Filter
Filter_38282_I
How would you sort an array of integers using Merge Sort algorithm? Write a recursive function to implement it and also include any optimizations that can be applied to improve its efficiency.
def merge_sort(arr): """ Performs a merge sort on the input array and returns the sorted array. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right):...
from solution import merge_sort 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_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reversed(): assert merge_sort([5, 4, 3,...
[ { "docstring": "Performs a merge sort on the input array and returns the sorted array.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted arrays into a single sorted array.", "function_declaratio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sort an array of integers using the Merge Sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n L = arr[:mid]\n R...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038282", "row_id": 38282, "seed_ids": "['Qwen2-72B-Instruct_84570']" }
0.748738
Filter_38282
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f48107df7feaddfc684f19453f5386de7e2c570b
f23d15b4ef5f185b88aaef0b3eee918e763625cb
v1.0
instruct
Filter
Filter_38286_I
Prompt: Write a Python script that allows a user to increment or decrement any element in a multidimensional numpy array with shared memory capabilities using the multiprocessing library. The script should require the user to enter a password before making any changes to the array. Additionally, the script should have ...
import numpy as np import multiprocessing as mp import hashlib import os AUTH_PASSWORD = "securepassword" LOG_FILE = "changes.log" def authenticate(): password = input("Enter password: ") hashed_password = hashlib.sha256(password.encode()).hexdigest() if hashed_password == hashlib.sha256(AUTH_PASSWORD.enc...
import numpy as np import multiprocessing as mp import os def setup_module(module): """ setup any state specific to the execution of the given module.""" if os.path.exists("changes.log"): os.remove("changes.log") def test_authenticate(monkeypatch): from solution import authenticate, AUTH_PASSWORD ...
[ { "docstring": null, "function_declaration": "def authenticate():", "function_name": "authenticate", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def log_change(action, index, old_value, new_value):", "function_name": "log_change", "parameter_list": "(a...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport multiprocessing as mp\nimport getpass\n\ndef authenticate_user(password, attempts=3):\n while attempts > 0:\n entered_password = getpass.getpass(\"Enter pa...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038286", "row_id": 38286, "seed_ids": "['Qwen2-72B-Instruct_84576']" }
0.464523
Filter_38286
I
[ "authenticate", "log_change", "increment_element", "decrement_element", "main" ]
5
[ [ "decrement_element", "authenticate" ], [ "decrement_element", "log_change" ], [ "increment_element", "authenticate" ], [ "increment_element", "log_change" ] ]
4
[]
false
[]
false
pytest
true
[ "numpy" ]
false
518bdd2ed6cd165df2a5d939dbfecc5163a0cb72
5a62d9e67bf9ddbf5c11d5db0b2676d69d9234dc
v1.0
instruct
Filter
Filter_38303_I
Construct a cellular automaton that simulates the spread of a contagious disease in a population. Assume the population is modeled as a 2D grid, with each cell representing an individual that can be in one of three states: susceptible, infected, or recovered. The disease spreads via contact between infected and suscept...
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import random # Constants SUSCEPTIBLE = 0 INFECTED = 1 RECOVERED = 2 def initialize_grid(size, initial_infected_pct): grid = np.zeros((size, size), dtype=int) num_initial_infected = int(size * size * initial_infected_p...
import numpy as np from solution import initialize_grid, spread_disease def test_initialize_grid(): size = 10 initial_infected_pct = 0.1 grid = initialize_grid(size, initial_infected_pct) assert grid.shape == (10, 10) num_infected = np.sum(grid == 1) expected_infected = int(size * size * initia...
[ { "docstring": null, "function_declaration": "def initialize_grid(size, initial_infected_pct):", "function_name": "initialize_grid", "parameter_list": "(size, initial_infected_pct)" }, { "docstring": null, "function_declaration": "def spread_disease(grid, transmission_rate, recovery_time...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n# Define the states\nSUSCEPTIBLE = 0\nINFECTED = 1\nRECOVERED = 2\n\ndef create_grid(size, init...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00038303", "row_id": 38303, "seed_ids": "['Qwen2-72B-Instruct_84618']" }
0.451056
Filter_38303
I
[ "initialize_grid", "spread_disease", "update_plot", "animate_disease_spread" ]
4
[ [ "animate_disease_spread", "initialize_grid" ], [ "animate_disease_spread", "update_plot" ], [ "update_plot", "spread_disease" ] ]
3
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
2dff1459fa0df030e87657fdb8768085f68b91a2
a09497b71482c44ccf6f28bdd2eb7fdceb773f26
v1.0
instruct
Filter
Filter_38340_I
Create a function that not only checks if a given number is even, but also checks whether it is a prime number. Also, there is a bit of erroneous code given below that needs to be fixed before using. Try to identify and correct it.
def is_even(n): """ Returns True if n is even, otherwise False. """ return n % 2 == 0 def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False ...
def test_is_even(): assert is_even(2) == True assert is_even(3) == False assert is_even(10) == True assert is_even(11) == False def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(10) == False def test_is_even_and_prime...
[ { "docstring": "Returns True if n is even, otherwise False.", "function_declaration": "def is_even(n):", "function_name": "is_even", "parameter_list": "(n)" }, { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_even(n):\n \"\"\"\n Returns True if the number is even, otherwise False.\n \"\"\"\n return n % 2 == 0\n\ndef is_prime(n):\n \"\"\"\n Returns True if the number is a pr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00038340", "row_id": 38340, "seed_ids": "['Qwen2-72B-Instruct_84681']" }
0.604352
Filter_38340
I
[ "is_even", "is_prime", "is_even_and_prime" ]
3
[ [ "is_even_and_prime", "is_even" ], [ "is_even_and_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
false
[]
true
bac6c90012fdacaba05e0ea4fa434c6be19cc0b6
e152e3b1a36ec5df5b5366f70e7d0ae57c163e99