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_31383_I
Write a Bash script that runs a Python code and passes an argument to the Python function. The Python function should only accept lowercase alphabets as the name argument and should also check if the name is a palindrome (the same when read forwards and backwards). The Bash script should handle the case when the argume...
def is_palindrome(s): """ Returns True if s is a palindrome, False otherwise. """ return s == s[::-1] def validate_name(name): """ Validates if the name consists only of lowercase alphabets and is a palindrome. Returns an error message otherwise. """ if not name.isalpha() or not nam...
from solution import is_palindrome, validate_name def test_is_palindrome(): assert is_palindrome("madam") == True assert is_palindrome("abcba") == True assert is_palindrome("abccba") == True assert is_palindrome("hello") == False assert is_palindrome("world") == False def test_validate_name(): ...
[ { "docstring": "Returns True if s is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Validates if the name consists only of lowercase alphabets and is a palindrome.\nReturns an erro...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "# create_script.py\n\nimport sys\n\ndef is_palindrome(name):\n \"\"\"\n Check if the given name is a palindrome and contains only lowercase alphabets.\n \"\"\"\n if not name.isalph...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031383", "row_id": 31383, "seed_ids": "['Qwen2-72B-Instruct_72645']" }
0.611596
Filter_31383
I
[ "is_palindrome", "validate_name" ]
2
[ [ "validate_name", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b113e7ce392836bf720cf3d2b6d53334ea93952f
eb566a0fb155fd10579ccaa4e4f8f44bb1463357
v1.0
instruct
Filter
Filter_31393_I
Create a Python code to generate a list with the first 20 prime numbers greater than 100.
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, first_20_primes_greater_than_100 def test_is_prime(): assert is_prime(101) == True assert is_prime(102) == False assert is_prime(103) == True assert is_prime(104) == False assert is_prime(2) == True assert is_prime(1) == False def test_first_20_primes_greater_tha...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list with the first 20 prime numbers greater than 100.", "function_declaration": "def first_20_primes_grea...
[ 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, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031393", "row_id": 31393, "seed_ids": "['Qwen2-72B-Instruct_72662']" }
0.595417
Filter_31393
I
[ "is_prime", "first_20_primes_greater_than_100" ]
2
[ [ "first_20_primes_greater_than_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
27e100cb3bf38032ebdc8c7650329389a0e6a871
b080274e3d06d3eb15e39bef5a39f051ea536136
v1.0
instruct
Filter
Filter_31395_I
Print all the elements in the following array in descending order, without using any built-in sorting functions or methods. Additionally, the solution should have a time complexity of O(n log n). The array may contain duplicate elements and the solution should remove any duplicate elements before printing the result.
def merge_sort(arr): if len(arr) > 1: mid = len(arr) // 2 # Finding the mid of the array L = arr[:mid] # Dividing the elements into 2 halves R = arr[mid:] merge_sort(L) # Sorting the first half merge_sort(R) # Sorting the second half i = j = k ...
from solution import print_sorted_descending, sort_and_remove_duplicates def test_sort_and_remove_duplicates(): # Test with an example array arr = [5, 3, 8, 6, 5, 10, 7, 3] expected_result = [10, 8, 7, 6, 5, 3] assert sort_and_remove_duplicates(arr) == expected_result # Test with all duplicate ele...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def sort_and_remove_duplicates(arr):", "function_name": "sort_and_remove_duplicates", "parameter_list": "...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left = merge_sort(arr[:mid])\n right = merge_sort(arr[mid:])\n \n return merge(left...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031395", "row_id": 31395, "seed_ids": "['Qwen2-72B-Instruct_72666']" }
0.566107
Filter_31395
I
[ "merge_sort", "sort_and_remove_duplicates", "print_sorted_descending" ]
3
[ [ "print_sorted_descending", "sort_and_remove_duplicates" ], [ "sort_and_remove_duplicates", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e70f906d340eacd4067368db723e7717e6605b5d
f7da32e50b315064b5c7bc467a1a9a0544036e32
v1.0
instruct
Filter
Filter_31402_I
Using the "for" loop, print out all prime numbers from 1 to 100, excluding the number 2 and ensuring that the code runs within a time complexity of O(n log n). Additionally, implement the Sieve of Eratosthenes algorithm for finding prime numbers.
def sieve_of_eratosthenes(n): """ Implement the Sieve of Eratosthenes to find all prime numbers up to n """ # Initially assume all integers are prime is_prime = [True] * (n+1) p = 2 while p * p <= n: # If prime[p] is not changed, then it is a prime if is_prime[p]: ...
from solution import sieve_of_eratosthenes, prime_numbers_excluding_two def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [3, 5, 7] assert sieve_of_eratosthenes(20) == [3, 5, 7, 11, 13, 17, 19] assert sieve_of_eratosthenes(1) == [] assert sieve_of_eratosthenes(2) == [] def test_pri...
[ { "docstring": "Implement the Sieve of Eratosthenes to find all prime numbers up to n", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 1 to the specified limit,...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Implement the Sieve of Eratosthenes to find all prime numbers up to n\n \"\"\"\n # Initially assume all integers are prime\n is_prime = ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031402", "row_id": 31402, "seed_ids": "['Qwen2-72B-Instruct_72677']" }
0.623106
Filter_31402
I
[ "sieve_of_eratosthenes", "prime_numbers_excluding_two" ]
2
[ [ "prime_numbers_excluding_two", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31deecdd17ad3514f6e4c190e483e750339dddc2
eb016ce120934469516c15818f70077930f2b2c3
v1.0
instruct
Filter
Filter_31403_I
if the input is a list of numbers, for example, [1,2,3], how do I use the map function in python to return a list of its square? and please explain how the map function works in this context.
def square_number(n): """ Returns the square of the given number n. """ return n * n def square_list(numbers): """ Returns a list of squares of the given list of numbers. """ return list(map(square_number, numbers))
from solution import square_number, square_list def test_square_number(): assert square_number(2) == 4 assert square_number(-3) == 9 assert square_number(0) == 0 def test_square_list(): assert square_list([1, 2, 3]) == [1, 4, 9] assert square_list([0, -1, -2]) == [0, 1, 4] assert square_list([...
[ { "docstring": "Returns the square of the given number n.", "function_declaration": "def square_number(n):", "function_name": "square_number", "parameter_list": "(n)" }, { "docstring": "Returns a list of squares of the given list of numbers.", "function_declaration": "def square_list(num...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def square_list(numbers):\n \"\"\"\n Returns a list of squares of the given list of numbers.\n \"\"\"\n return list(map(lambda x: x ** 2, numbers))", "test_code": "from solutio...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031403", "row_id": 31403, "seed_ids": "['Qwen2-72B-Instruct_72678']" }
0.6109
Filter_31403
I
[ "square_number", "square_list" ]
2
[ [ "square_list", "square_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f59b0187cee9371a9a721e8dab276283752f86a0
d524a580574d48ac9e2494c4ade663929869e628
v1.0
instruct
Filter
Filter_31412_I
Write a code to find the factorial of the first 10 numbers. Instead of using a loop, try to implement it using recursion, taking care to manage the stack overflow possibility for the larger numbers.
def factorial(n): """ Returns the factorial of a given number n using recursion. """ if n == 0 or n == 1: return 1 return n * factorial(n - 1) def factorial_first_10_numbers(): """ Returns a list of factorials of the first 10 natural numbers. """ return [factorial(i) for i i...
from solution import factorial, factorial_first_10_numbers def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 assert factorial(6) == 720 assert factorial(7) == 504...
[ { "docstring": "Returns the factorial of a given number n using recursion.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns a list of factorials of the first 10 natural 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": "import sys\nsys.setrecursionlimit(1500)\n\ndef factorial(n, cache={0: 1, 1: 1}):\n \"\"\"\n Recursively calculates the factorial of a number n.\n Uses memoization to prevent stack ove...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031412", "row_id": 31412, "seed_ids": "['Qwen2-72B-Instruct_72688']" }
0.565001
Filter_31412
I
[ "factorial", "factorial_first_10_numbers" ]
2
[ [ "factorial_first_10_numbers", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd076e488ec4aab1a1f3c756af3b8b0f859c3d58
cf7f41e6f4d49f067c3dfbf5638658a3408279d9
v1.0
instruct
Filter
Filter_31424_I
Revise the existing Python program for calculating the roots of a quadratic equation to handle complex roots. The program should prompt the user for the values of a, b, and c, and then call a function that solves the equation using the quadratic formula. If the roots are complex, the program should print a message indi...
import cmath def solve_quadratic(a, b, c): """ Solves the quadratic equation ax^2 + bx + c = 0. Args: a (float): Coefficient of x^2 b (float): Coefficient of x c (float): Constant term Returns: tuple: A tuple containing both roots (could be real or complex) """ discrim...
from solution import solve_quadratic, parse_input, quadratic_solver_interface def test_solve_quadratic_real_roots(): root1, root2 = solve_quadratic(1, -3, 2) assert root1 == 2 assert root2 == 1 def test_solve_quadratic_single_real_root(): root1, root2 = solve_quadratic(1, 2, 1) assert root1 == -1 ...
[ { "docstring": "Solves the quadratic equation ax^2 + bx + c = 0.\n\nArgs:\na (float): Coefficient of x^2\nb (float): Coefficient of x\nc (float): Constant term\n\nReturns:\ntuple: A tuple containing both roots (could be real or complex)", "function_declaration": "def solve_quadratic(a, b, c):", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import cmath\n\ndef solve_quadratic(a, b, c):\n \"\"\"\n Solves the quadratic equation ax^2 + bx + c = 0 and returns the roots.\n Handles both real and complex roots.\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031424", "row_id": 31424, "seed_ids": "['Qwen2-72B-Instruct_72709']" }
0.585803
Filter_31424
I
[ "solve_quadratic", "parse_input", "quadratic_solver_interface" ]
3
[ [ "quadratic_solver_interface", "parse_input" ], [ "quadratic_solver_interface", "solve_quadratic" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
7258fffcc8befb24fd03f55d6c06fa404d32aed4
fb667ee2a3c8552de83a5b34c5ea120ccea8c41c
v1.0
instruct
Filter
Filter_31426_I
Write a Python script to convert a list of positive integers into a dictionary where the keys represent the original numbers converted to binary strings with an 'f' prefix and suffix, and the values represent the original numbers in hexadecimal format. Implement this solution without using the built-in bin() and hex() ...
def to_binary_string(n): """ Returns binary string of a positive integer n without using bin(). """ binary_num = "" while n > 0: binary_num = str(n % 2) + binary_num n = n // 2 return "f" + binary_num + "f" def to_hexadecimal_string(n): """ Returns hexadecimal string of ...
from solution import to_binary_string, to_hexadecimal_string, list_to_dict def test_to_binary_string(): assert to_binary_string(5) == "f101f" assert to_binary_string(10) == "f1010f" assert to_binary_string(1) == "f1f" assert to_binary_string(0) == "ff" def test_to_hexadecimal_string(): assert to_h...
[ { "docstring": "Returns binary string of a positive integer n without using bin().", "function_declaration": "def to_binary_string(n):", "function_name": "to_binary_string", "parameter_list": "(n)" }, { "docstring": "Returns hexadecimal string of a positive integer n without using hex().", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def list_to_dict(input_list):\n \"\"\"\n Converts a list of positive integers into a dictionary:\n - Keys: Binary strings with 'f' prefix and suffix\n - Values: Hexadecimal format ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031426", "row_id": 31426, "seed_ids": "['Qwen2-72B-Instruct_72713']" }
0.608944
Filter_31426
I
[ "to_binary_string", "to_hexadecimal_string", "list_to_dict" ]
3
[ [ "list_to_dict", "to_binary_string" ], [ "list_to_dict", "to_hexadecimal_string" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4ca621d0558a2cfe5ab3e10aeee51a1893c49a16
a5458acffff3c762dc540bb692fd226c87178353
v1.0
instruct
Filter
Filter_31437_I
Write a code for the Diffie–Hellman key exchange with a large prime number and a primitive root, ensuring that the private keys are securely generated and that the public keys are properly calculated. Additionally, implement a secure method for exchanging the public keys between the two parties without allowing a man-i...
import random import hashlib import time import secrets # Function to perform modular exponentiation def mod_exp(base, exponent, modulus): return pow(base, exponent, modulus) # Generate a large prime number and its primitive root def generate_large_prime_and_root(): # For simplicity, using well-known 2048-bit...
from solution import diffie_hellman_exchange, derive_key, calculate_public_key, calculate_shared_secret, generate_large_prime_and_root def test_diffie_hellman_shared_key(): shared_key = diffie_hellman_exchange() assert isinstance(shared_key, str) assert len(shared_key) == 64 def test_public_key_calculatio...
[ { "docstring": null, "function_declaration": "def mod_exp(base, exponent, modulus):", "function_name": "mod_exp", "parameter_list": "(base, exponent, modulus)" }, { "docstring": null, "function_declaration": "def generate_large_prime_and_root():", "function_name": "generate_large_pri...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport hashlib\nimport time\nimport secrets\n\n# Function to perform modular exponentiation\ndef mod_exp(base, exponent, modulus):\n return pow(base, exponent, modulus)\n\n# ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031437", "row_id": 31437, "seed_ids": "['Qwen2-72B-Instruct_72733']" }
0.409115
Filter_31437
I
[ "mod_exp", "generate_large_prime_and_root", "generate_private_key", "calculate_public_key", "calculate_shared_secret", "derive_key", "secure_key_exchange", "rate_limit", "diffie_hellman_exchange" ]
9
[ [ "calculate_public_key", "mod_exp" ], [ "calculate_shared_secret", "mod_exp" ], [ "diffie_hellman_exchange", "calculate_public_key" ], [ "diffie_hellman_exchange", "calculate_shared_secret" ], [ "diffie_hellman_exchange", "derive_key" ], [ "diffie_hel...
8
[]
false
[]
false
pytest
true
[]
true
6ec7ebdbb4d5caab0436efe226b245473a3b371e
94d61359ceed0fc9c6f04ae7360c2c878bbaf4dc
v1.0
instruct
Filter
Filter_31442_I
Given a set of numbers, create a list in Python that contains only the even numbers from the given set. However, you are not allowed to use any built-in Python functions or libraries such as filter(), list comprehension, or any form of iteration (for loop, while loop, etc.). You can only use basic programming construct...
def is_even(number): """ Determines if a number is even using bitwise operations. """ # Check the least significant bit using bitwise AND with 1. return (number & 1) == 0 def filter_even_numbers(numbers): """ Filters even numbers from the input list using only logical constructs. """ ...
from solution import filter_even_numbers def test_filter_even_numbers_all_even(): assert filter_even_numbers([2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10] def test_filter_even_numbers_all_odd(): assert filter_even_numbers([1, 3, 5, 7, 9]) == [] def test_filter_even_numbers_mixed(): assert filter_even_numbers([1,...
[ { "docstring": "Determines if a number is even using bitwise operations.", "function_declaration": "def is_even(number):", "function_name": "is_even", "parameter_list": "(number)" }, { "docstring": "Filters even numbers from the input list using only logical constructs.", "function_decla...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_even(number):\n \"\"\"\n Determine if a number is even using bitwise operations.\n \n Args:\n number (int): The number to be checked.\n \n Returns:\n bool: True ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031442", "row_id": 31442, "seed_ids": "['Qwen2-72B-Instruct_72742']" }
0.735772
Filter_31442
I
[ "is_even", "filter_even_numbers" ]
2
[ [ "filter_even_numbers", "is_even" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e62673dc72c0fa4f9163c798235d573496e8a553
e3669b0314c62fda25e0b9199ac467b6e01fdc5d
v1.0
instruct
Filter
Filter_31447_I
Given are three programming functions, `f1`, `f2`, and `f3`. `f1` accepts four parameters `x`, `y`, `z` and `w`. `f2` and `f3`, on the other hand, accept only two parameters each, specifically `x` and `y` for `f2` and `z` and `w` for `f3`. The task is to write a function that calculates the average of the outputs of `f...
def f1(x, y, z, w): # Sample implementation return x + y + z + w def f2(x, y): # Sample implementation return x * y def f3(z, w): # Sample implementation return z - w def average_functions(x, y, z, w): """ Returns the average of f1, f2, and f3 given the same parameters. """ ou...
from solution import average_functions, f1, f2, f3 def test_average_functions(): x, y, z, w = 1, 2, 3, 4 output_f1 = f1(x, y, z, w) output_f2 = f2(x, y) output_f3 = f3(z, w) expected_average = (output_f1 + output_f2 + output_f3) / 3 assert average_functions(x, y, z, w) == expecte...
[ { "docstring": null, "function_declaration": "def f1(x, y, z, w):", "function_name": "f1", "parameter_list": "(x, y, z, w)" }, { "docstring": null, "function_declaration": "def f2(x, y):", "function_name": "f2", "parameter_list": "(x, y)" }, { "docstring": null, "func...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def f1(x, y, z, w):\n \"\"\"\n Sample implementation of f1 which will be replaced by the actual implementation.\n For demonstration, returning sum of all parameters.\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031447", "row_id": 31447, "seed_ids": "['Qwen2-72B-Instruct_72751']" }
0.489932
Filter_31447
I
[ "f1", "f2", "f3", "average_functions" ]
4
[ [ "average_functions", "f1" ], [ "average_functions", "f2" ], [ "average_functions", "f3" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f10c2c040f75566be494b67fe84d285b5878a200
0243f0169baf8962d9b8e77975afbb39e7ca5e01
v1.0
instruct
Filter
Filter_31452_I
Devise a computational function for the purpose of generating the Fibonacci sequence up to the 'n'th term where 'n' is within the constraints of positive integers including 0. Additionally, implement a memoization technique to optimize the function for larger values of 'n'. Finally, create a wrapper function that accep...
def fibonacci(n, memo={}): """ Returns the 'n'th term in the Fibonacci sequence using memoization. """ if n in memo: return memo[n] if n == 0: return 0 if n == 1: return 1 memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo) return memo[n] def get_fibonacci_numb...
from solution import fibonacci, get_fibonacci_number def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_recursive_cases(): assert fibonacci(5) == 5 # 0, 1, 1, 2, 3, 5 assert fibonacci(10) == 55 # 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 def test_fibonac...
[ { "docstring": "Returns the 'n'th term in the Fibonacci sequence using memoization.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": "fibonacci", "parameter_list": "(n, memo={})" }, { "docstring": "Rounds the input float to the nearest integer and returns the 'n'th te...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Returns the nth Fibonacci number using memoization.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 0:\n return 0\n el...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031452", "row_id": 31452, "seed_ids": "['Qwen2-72B-Instruct_72757']" }
0.712979
Filter_31452
I
[ "fibonacci", "get_fibonacci_number" ]
2
[ [ "get_fibonacci_number", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
754db4f8602b3db22043e5d5152e9a5f38988013
2e6c9ff3611dc1c9e3dcd7264a90ad5dfed653c2
v1.0
instruct
Filter
Filter_31457_I
Write a code snippet that computes the sum of prime numbers from 1 to the given number 'n'. Additionally, provide the functionality to check if this sum is a palindrome. Here's a piece of erroneous code for reference. Identify the errors and correct them in your solution.
def is_prime(num): """ Returns True if num is a prime number, False otherwise. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def sum_primes(n): """ Returns the sum of all prime numbers from 1 t...
from solution import is_prime, sum_primes, is_palindrome, sum_primes_and_check_palindrome def test_is_prime(): assert is_prime(2) assert not is_prime(1) assert is_prime(13) assert not is_prime(4) def test_sum_primes(): assert sum_primes(10) == 17 # 2 + 3 + 5 + 7 = 17 assert sum_primes(1) == 0...
[ { "docstring": "Returns True if num is a prime number, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers from 1 to n.", "function_declaration": "def sum_primes(n)...
[ 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 Returns True if num is a prime number, False otherwise.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031457", "row_id": 31457, "seed_ids": "['Qwen2-72B-Instruct_72770']" }
0.556632
Filter_31457
I
[ "is_prime", "sum_primes", "is_palindrome", "sum_primes_and_check_palindrome" ]
4
[ [ "sum_primes", "is_prime" ], [ "sum_primes_and_check_palindrome", "is_palindrome" ], [ "sum_primes_and_check_palindrome", "sum_primes" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ddda56f0104b63c696f6911f7b49c03f034d8875
1b88a35af0b7f021f80d4fb851ae9b36a349bc66
v1.0
instruct
Filter
Filter_31474_I
Keep the existing code but add a requirement that the program must now also check for prime numbers between 0 and 1000. The program should output a list of all prime numbers found in this range.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, find_primes_up_to, primes_between_0_and_1000 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False ...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers up to the given limit.", "function_declaration": "def find_prime...
[ 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 Returns True if the number is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True #...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031474", "row_id": 31474, "seed_ids": "['Qwen2-72B-Instruct_72800']" }
0.584308
Filter_31474
I
[ "is_prime", "find_primes_up_to", "primes_between_0_and_1000" ]
3
[ [ "find_primes_up_to", "is_prime" ], [ "primes_between_0_and_1000", "find_primes_up_to" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a115adeda467255825a3a1f6cbe591c01b7122bd
d71f347f25c279ace0fb2d916faa1f39c1965488
v1.0
instruct
Filter
Filter_31478_I
Create a regex pattern to validate whether a given string is an acceptable email address according to standard email specifications. Additionally, build a function that checks if the given email address's domain exists and is reachable. You should include scenarios where the domain server may not respond quickly and ma...
import re import socket def is_valid_email(email): """ Validates the email address using regex pattern. """ pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' return re.match(pattern, email) is not None def is_domain_reachable(domain): """ Checks if the given domain is reachable...
from solution import is_valid_email, is_domain_reachable, check_email def test_is_valid_email(): assert is_valid_email("test@example.com") assert not is_valid_email("test@.com") assert not is_valid_email("test@com") assert not is_valid_email("test.com") assert is_valid_email("first.last@example.co....
[ { "docstring": "Validates the email address using regex pattern.", "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": "Checks if the given domain is reachable.", "function_declaration": "def is_domain_rea...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nimport socket\n\ndef is_valid_email(email):\n \"\"\"\n Validates an email address using regex.\n \n Args:\n email (str): The email address to be validated.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031478", "row_id": 31478, "seed_ids": "['Qwen2-72B-Instruct_72807']" }
0.44857
Filter_31478
I
[ "is_valid_email", "is_domain_reachable", "check_email" ]
3
[ [ "check_email", "is_domain_reachable" ], [ "check_email", "is_valid_email" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ffffc8a2a97123d82d7b94eb587808729c8dc9ea
784abdd51bfff6c6b43fcd3bf6f3e74347cf10ba
v1.0
instruct
Filter
Filter_31483_I
Please write a Python code to check if a given 2D array has any prime numbers. If a prime number is found, print its value along with its row and column indices. You are given the number of rows and columns in the 2D array as inputs. You should implement this logic as a function.
def is_prime(num): """ Helper function to check if the given 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 find_primes_in_2d_array(rows, cols, array): """ Finds and prints th...
from solution import is_prime, find_primes_in_2d_array 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(0) == False assert is_prime(1) == False assert is_prime(-1) == False def test_find_primes...
[ { "docstring": "Helper function to check if the given number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds and prints the prime numbers along with their positions in the given 2D array.\n\nParameters:...
[ 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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031483", "row_id": 31483, "seed_ids": "['Qwen2-72B-Instruct_72814']" }
0.629809
Filter_31483
I
[ "is_prime", "find_primes_in_2d_array" ]
2
[ [ "find_primes_in_2d_array", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e663838ff418a586deb71749679af95494e34fd5
b1b3e7fe0cd44864d90e4e9bc41f9e9f206322bc
v1.0
instruct
Filter
Filter_31492_I
How do you create a function in Python to add a suffix to a given word and return the new word? You should also ensure that the input word starts with a vowel, contains at least 3 characters and does not already end with the given suffix. Additionally, include a check function to validate the implementation with differ...
def add_suffix(word, suffix): """ Adds the given suffix to the word if it meets the following criteria: - The word must start with a vowel. - The word must contain at least 3 characters. - The word must not already end with the given suffix. Parameters: word (str): The input word. s...
from solution import add_suffix, validate def test_add_suffix_valid_case(): assert add_suffix('apple', 'pie') == 'applepie' def test_add_suffix_already_has_suffix(): assert add_suffix('applepie', 'pie') == 'applepie' def test_add_suffix_starts_with_consonant(): assert add_suffix('banana', 'split') == 'ba...
[ { "docstring": "Adds the given suffix to the word if it meets the following criteria:\n- The word must start with a vowel.\n- The word must contain at least 3 characters.\n- The word must not already end with the given suffix.\n\nParameters:\nword (str): The input word.\nsuffix (str): The suffix to be added.\n\...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add_suffix(word, suffix):\n \"\"\"\n Adds a suffix to the given word if it meets the following conditions:\n - The word starts with a vowel (a, e, i, o, u).\n - The word contai...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031492", "row_id": 31492, "seed_ids": "['Qwen2-72B-Instruct_72827']" }
0.595666
Filter_31492
I
[ "add_suffix", "validate" ]
2
[ [ "validate", "add_suffix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
81da43cfa2e3360c4391186099ddd3127130c479
c85e333808931ea50120fe3729b7b1505a212f0c
v1.0
instruct
Filter
Filter_31496_I
Design a Python program using a 'while' loop to compute the product of the first 10 prime numbers. Additionally, include logic to identify if a number is prime within this program.
def is_prime(n): """ Check if a given number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 r...
from solution import is_prime, product_of_first_10_primes def test_is_prime(): # Test typical prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True assert is_prime(11) == True # Test non-prime numbers assert is_prime(1)...
[ { "docstring": "Check if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Compute the product of the first 10 prime numbers.", "function_declaration": "def product_of_first_10_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 Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n elif n % 2...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031496", "row_id": 31496, "seed_ids": "['Qwen2-72B-Instruct_72835']" }
0.650151
Filter_31496
I
[ "is_prime", "product_of_first_10_primes" ]
2
[ [ "product_of_first_10_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ae52f4d805296ec20936fb0cec42573a0550303
9aa726dc01fd1b7a01e9865ada902b6f55c52212
v1.0
instruct
Filter
Filter_31504_I
Write a code to generate a list of prime numbers from 10 to 20 (inclusive), where the code should be implemented using a recursive function and must not use any built-in library functions to check for prime numbers.
def is_prime_recursive(n, divisor=None): """ Recursively checks if a number is prime. """ if divisor is None: divisor = n - 1 if divisor <= 1: return True if n % divisor == 0: return False return is_prime_recursive(n, divisor - 1) def list_primes_recursive(start, end...
from solution import list_primes_recursive def test_primes_10_to_20(): assert list_primes_recursive(10, 20) == [11, 13, 17, 19] def test_primes_empty_range(): assert list_primes_recursive(20, 10) == [] def test_primes_small_range_with_no_primes(): assert list_primes_recursive(14, 16) == [] def test_prim...
[ { "docstring": "Recursively checks if a number is prime.", "function_declaration": "def is_prime_recursive(n, divisor=None):", "function_name": "is_prime_recursive", "parameter_list": "(n, divisor=None)" }, { "docstring": "Generates a list of prime numbers in a given range [start, end].", ...
[ 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=2):\n \"\"\"\n Recursively checks if a number n is prime.\n \"\"\"\n if n <= 2:\n return n == 2\n if n % divisor == 0:\n return F...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031504", "row_id": 31504, "seed_ids": "['Qwen2-72B-Instruct_72850']" }
0.647382
Filter_31504
I
[ "is_prime_recursive", "list_primes_recursive" ]
2
[ [ "list_primes_recursive", "is_prime_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c92ef16e460436d29cec4d69945041afdf5f4d6
bf6ac17c02d89b2b6d81d5183d0f53eb29593a81
v1.0
instruct
Filter
Filter_31505_I
Using the given code, extract the year of the given dateTime object and display it in the desired format. Additionally, write a function to convert the year to Roman numerals and display it alongside the original year. However, the year must be displayed in Roman numerals using capital letters only if the month is in t...
from datetime import datetime def year_to_roman(year): """ Converts a given year to Roman numerals. """ val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] syb = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", ...
from datetime import datetime from solution import display_year def test_display_year_first_half(): dateTime = datetime(2023, 4, 15) assert display_year(dateTime) == (2023, "MMXXIII") def test_display_year_second_half(): dateTime = datetime(2011, 11, 3) assert display_year(dateTime) == (2011, "mmxi") ...
[ { "docstring": "Converts a given year to Roman numerals.", "function_declaration": "def year_to_roman(year):", "function_name": "year_to_roman", "parameter_list": "(year)" }, { "docstring": "Extracts the year and month from the datetime object.\nIf month is in the first half of the year (Jan...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\n\ndef to_roman_digit(digit, one, five, ten):\n if digit == 9:\n return one + ten\n if digit >= 5:\n return five + (one * (digit - 5))\n if digit == 4:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031505", "row_id": 31505, "seed_ids": "['Qwen2-72B-Instruct_72851']" }
0.568286
Filter_31505
I
[ "year_to_roman", "display_year" ]
2
[ [ "display_year", "year_to_roman" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e5ecd1495f9f7dbfe02d0b897d27785c12a18d2
bc94930e44b4aae66af323f3a853e0fa23e57b07
v1.0
instruct
Filter
Filter_31507_I
Create a program that prints the first n Fibonacci numbers in reverse order, where n is a positive integer provided as input by the user. The program should also check if each Fibonacci number is a prime number and, if so, print "This number is prime" next to it.
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += ...
from solution import fibonacci_reverse def test_fibonacci_reverse(capsys): fibonacci_reverse(5) captured = capsys.readouterr() assert captured.out.strip() == "3 This number is prime\n2 This number is prime\n1\n1\n0" fibonacci_reverse(10) captured = capsys.readouterr() assert captured.out.s...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Prints the first n Fibonacci numbers in reverse order with a check for prime numbers.", "function_declaration": "def fibo...
[ 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(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031507", "row_id": 31507, "seed_ids": "['Qwen2-72B-Instruct_72855']" }
0.750199
Filter_31507
I
[ "is_prime", "fibonacci_reverse" ]
2
[ [ "fibonacci_reverse", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d4c6ef14303510df8bba152f49c2c08f69fd5cd
874736b9826199c7ba4b440be2c6ad68b885b09c
v1.0
instruct
Filter
Filter_31519_I
Develop a Python native function that operates to identify and retrieve the second smallest numerical value within a provided list. The list may contain integers, floating-point numbers, strings, and nested lists. Your function should be able to ignore non-integer and non-floating point values, as well as handle nested...
def extract_numbers(lst): """ Extracts and flattens numerical values from a list, including nested lists. """ numbers = [] for item in lst: if isinstance(item, (int, float)): numbers.append(item) elif isinstance(item, list): numbers.extend(extract_numbers(item...
from solution import second_smallest def test_second_smallest_normal_list(): assert second_smallest([5, 3, 1, 2, 4]) == 2 def test_second_smallest_with_floats(): assert second_smallest([1.5, 3.2, 2.8, 1.1, 2.3]) == 1.5 def test_second_smallest_with_non_numerical(): assert second_smallest(['a', 4, 2, 'b',...
[ { "docstring": "Extracts and flattens numerical values from a list, including nested lists.", "function_declaration": "def extract_numbers(lst):", "function_name": "extract_numbers", "parameter_list": "(lst)" }, { "docstring": "Identifies and retrieves the second smallest numerical value fro...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_second_smallest(lst):\n \"\"\"\n Identifies and retrieves the second smallest numerical value within a provided list.\n The list may contain integers, floating-point numbers,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031519", "row_id": 31519, "seed_ids": "['Qwen2-72B-Instruct_72876']" }
0.772256
Filter_31519
I
[ "extract_numbers", "second_smallest" ]
2
[ [ "second_smallest", "extract_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61151f1b96f7581defe41fca7d21ad45188fc80d
ce8e1769a1563c38f444f0befad5e3c4fb01a2c7
v1.0
instruct
Filter
Filter_31526_I
Write a Python program to automate the process of creating a directory, writing data to a file inside that directory, and then compressing that file using zip.
import os import zipfile def create_directory(directory_path): """ Creates a directory if it doesn't exist. """ os.makedirs(directory_path, exist_ok=True) def write_to_file(file_path, data): """ Writes data to a file. """ with open(file_path, 'w') as file: file.write(data) def...
import os import zipfile from solution import create_directory, write_to_file, compress_file, automate_process def test_create_directory(): test_dir = 'test_dir' create_directory(test_dir) assert os.path.exists(test_dir) os.rmdir(test_dir) # Clean up def test_write_to_file(): test_dir = 'test_di...
[ { "docstring": "Creates a directory if it doesn't exist.", "function_declaration": "def create_directory(directory_path):", "function_name": "create_directory", "parameter_list": "(directory_path)" }, { "docstring": "Writes data to a file.", "function_declaration": "def write_to_file(fil...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport zipfile\n\ndef create_directory(directory_name):\n \"\"\"\n Create a new directory if it doesn't exist.\n \"\"\"\n if not os.path.exists(directory_name):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031526", "row_id": 31526, "seed_ids": "['Qwen2-72B-Instruct_72887']" }
0.642277
Filter_31526
I
[ "create_directory", "write_to_file", "compress_file", "automate_process" ]
4
[ [ "automate_process", "compress_file" ], [ "automate_process", "create_directory" ], [ "automate_process", "write_to_file" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f13999fdb399d01236fdf448fe8db82ea65d35de
eb2647f47fa9109d7de7c3748594e18981368041
v1.0
instruct
Filter
Filter_31550_I
Design a Python program that generates the first twenty factorial values of a given integer, but also add error handling for scenarios where the input is not valid, for instance, if it's a negative number or not an integer. Also, incorporate a feature that allows the user to input a range for the numbers they wish to c...
import math from typing import List, Union def is_valid_integer(num: Union[int, str]) -> bool: """ Check if the given input is a valid integer. """ if isinstance(num, int): return True if isinstance(num, str): if num.strip('-+').isdigit(): return True r...
import pytest from solution import calculate_factorials, display_factorials, is_valid_integer def test_is_valid_integer(): assert is_valid_integer(5) == True assert is_valid_integer("5") == True assert is_valid_integer("-3") == True assert is_valid_integer("abc") == False assert is_valid_integer(4....
[ { "docstring": "Check if the given input is a valid integer.", "function_declaration": "def is_valid_integer(num):", "function_name": "is_valid_integer", "parameter_list": "(num)" }, { "docstring": "Calculate the factorial for a given range of integers from range_start to range_end inclusive...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom typing import List, Union\n\ndef is_valid_integer(num: Union[int, str]) -> bool:\n \"\"\"\n Check if the given input is a valid integer.\n \"\"\"\n if isinstance(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031550", "row_id": 31550, "seed_ids": "['Qwen2-72B-Instruct_72927']" }
0.563907
Filter_31550
I
[ "is_valid_integer", "calculate_factorials", "display_factorials" ]
3
[ [ "calculate_factorials", "is_valid_integer" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72cda2d7c8c0f06259d6b67c0e4cd474bef627d0
eb953f98f7ebddda060153c84a475ea482a8d1dc
v1.0
instruct
Filter
Filter_31554_I
Create a simple Python script that prints the first 100 prime numbers and calculates the sum of those numbers.
def is_prime(n): """ Determines if n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def first_n_primes(n): ""...
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 def test_first_n_primes(): assert first_n_primes(5) == [2, 3, 5, 7, 11] ...
[ { "docstring": "Determines if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "...
[ 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 Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031554", "row_id": 31554, "seed_ids": "['Qwen2-72B-Instruct_72936']" }
0.560665
Filter_31554
I
[ "is_prime", "first_n_primes", "sum_of_primes" ]
3
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0179f6afd2b45f9d9f770ca799613191754ebd8c
4d0c36f183c098cf4d1b8be1354e3b55de0d1bca
v1.0
instruct
Filter
Filter_31558_I
Develop a Python function capable of distinguishing prime numbers from a collection of integers, including negative integers and zero. This function should be designed to handle exceptions for inputs that are non-numerical, floating point numbers, or even large numbers that exceed the maximum integer limit in Python. T...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import is_prime, find_primes_and_multiply 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(-10) == False assert is_prime(0) == False assert is_pri...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Function to find all prime numbers from the collection and multiply them.\nArgs:\n- numbers: a collection of in...
[ 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 Helper function to 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_0
{ "original_instruction": "", "prompt_id": "00031558", "row_id": 31558, "seed_ids": "['Qwen2-72B-Instruct_72945']" }
0.714919
Filter_31558
I
[ "is_prime", "find_primes_and_multiply" ]
2
[ [ "find_primes_and_multiply", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2215dec64717cf265ce95b6ccf97e2a9ef379e1
32e0c800a47b1d0e06be860f4c931ca5c80db8d1
v1.0
instruct
Filter
Filter_31585_I
Given the python method below, begin by modifying it to identify whether the individual score at each index of the two input arrays is a prime number or not. Then compare the prime numbers at corresponding indices in the arrays. Return "YES" if the prime numbers match at those indices and "NO" if they do not match or i...
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 retur...
from solution import is_prime, compare_prime_indices def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False assert is_prime(-1) == False assert is_prime(0) ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Compare if the prime numbers at corresponding indices in two arrays match.", "function_declaration": "def compare_prime_indice...
[ 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 compare_prime_indices(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031585", "row_id": 31585, "seed_ids": "['Qwen2-72B-Instruct_72985']" }
0.595481
Filter_31585
I
[ "is_prime", "compare_prime_indices" ]
2
[ [ "compare_prime_indices", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d0f2c483a9e8c6bab91f7bd5b002118c5e7b8998
6779c582da8bce30e2b0fc29e04995abf9e128be
v1.0
instruct
Filter
Filter_31613_I
Create a Python code snippet to calculate and display the compound interest for a given principal, rate, time, and the number of times interest is compounded per year. Your code should include error handling for invalid user inputs (e.g., non-numeric input, negative numbers). Moreover, provide a piece of erroneous code...
def calculate_compound_interest(principal, rate, time, n): """ Calculate compound interest. :param principal: Initial amount of money (P) :param rate: Annual interest rate (r) in decimal, e.g., 5% as 0.05 :param time: Time the money is invested for in years (t) :param n: Number of times interes...
from solution import calculate_compound_interest, display_compound_interest def test_calculate_compound_interest_basic(): assert round(calculate_compound_interest(1000, 0.05, 10, 12), 2) == 1647.01 def test_calculate_compound_interest_zero_principal(): assert calculate_compound_interest(0, 0.05, 10, 12) == 0 ...
[ { "docstring": "Calculate compound interest.\n\n:param principal: Initial amount of money (P)\n:param rate: Annual interest rate (r) in decimal, e.g., 5% as 0.05\n:param time: Time the money is invested for in years (t)\n:param n: Number of times interest is compounded per year\n:return: The amount of money aft...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_compound_interest(principal, rate, time, n):\n \"\"\"\n Calculate compound interest.\n\n :param principal: Initial amount of money (P)\n :param rate: Annual interest ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031613", "row_id": 31613, "seed_ids": "['Qwen2-72B-Instruct_73031']" }
0.397605
Filter_31613
I
[ "calculate_compound_interest", "display_compound_interest", "incorrect_calculate_compound_interest" ]
3
[ [ "display_compound_interest", "calculate_compound_interest" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ec3d1a58c0bf5698bcba5748246d7733ec93823
25bc5823282d0aac929c9379fd45340b354ecdfc
v1.0
instruct
Filter
Filter_31641_I
Please write a function in Python that takes a list of book titles and their cover images as URLs, and returns a list of titles sorted based on the color of the dominant pixel in their cover images.
import requests from PIL import Image from io import BytesIO import numpy as np def dominant_color(image): """ Returns the dominant color in the given image. """ image = image.resize((1, 1)) # Resize image to 1x1 pixel return image.getpixel((0, 0)) # Get RGB value of the pixel def sort_books_by_...
import pytest from unittest.mock import patch, Mock from solution import dominant_color, sort_books_by_dominant_color # Mock function to simulate image fetching and processing def mocked_requests_get(*args, **kwargs): class MockResponse: def __init__(self, content): self.content = content ...
[ { "docstring": "Returns the dominant color in the given image.", "function_declaration": "def dominant_color(image):", "function_name": "dominant_color", "parameter_list": "(image)" }, { "docstring": "Sorts books by the dominant color of their cover images.\n\nParameters:\n book_data (lis...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from PIL import Image\nimport requests\nfrom io import BytesIO\nimport colorsys\n\ndef get_dominant_color(image_url):\n \"\"\"\n Retrieves the dominant color from the image at the given ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031641", "row_id": 31641, "seed_ids": "['Qwen2-72B-Instruct_73077']" }
0.445369
Filter_31641
I
[ "dominant_color", "sort_books_by_dominant_color" ]
2
[ [ "sort_books_by_dominant_color", "dominant_color" ] ]
1
[]
false
[]
false
pytest
true
[ "PIL", "numpy", "requests" ]
false
b13cd39ac5ac890d1ed73664eca50f86b9d723c5
0fc2b51004a01452eaca6cdb6f163bf53fdf3357
v1.0
instruct
Filter
Filter_31655_I
Write a python function to convert the given list of strings into a dictionary where the key is a string from the list and the value is the number of vowels in the string.
def count_vowels(s): """ Returns the number of vowels in string s. """ vowels = 'aeiouAEIOU' return sum(1 for char in s if char in vowels) def strings_to_vowel_dict(strings): """ Converts a list of strings into a dictionary. The keys are the strings and the values are the number of vowe...
from solution import strings_to_vowel_dict def test_empty_list(): assert strings_to_vowel_dict([]) == {} def test_single_string_no_vowels(): assert strings_to_vowel_dict(["bcdfg"]) == {"bcdfg": 0} def test_single_string_with_vowels(): assert strings_to_vowel_dict(["hello"]) == {"hello": 2} def test_mult...
[ { "docstring": "Returns the number of vowels in string s.", "function_declaration": "def count_vowels(s):", "function_name": "count_vowels", "parameter_list": "(s)" }, { "docstring": "Converts a list of strings into a dictionary.\nThe keys are the strings and the values are the number of vow...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_vowels(s):\n \"\"\"\n Helper function to count the number of vowels in a string.\n \"\"\"\n vowels = \"aeiouAEIOU\"\n return sum(1 for char in s if char in vowels)\n\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031655", "row_id": 31655, "seed_ids": "['Qwen2-72B-Instruct_73106']" }
0.737345
Filter_31655
I
[ "count_vowels", "strings_to_vowel_dict" ]
2
[ [ "strings_to_vowel_dict", "count_vowels" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb9809d13d3241067095f8b831fc9395e79b442e
f6b9f3cfc6aa98a19b77f80bbb0c3906c85025fe
v1.0
instruct
Filter
Filter_31656_I
Code a Python script that converts temperatures in celsius to fahrenheit. The script should also include error handling to ensure that the user enters a valid temperature. Additionally, the script should provide an option for the user to convert the temperature in reverse, from fahrenheit to celsius. The script should ...
def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5/9 def calculate_average_temperatures(temperatures, scale='celsius'): "...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, calculate_average_temperatures, is_valid_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius()...
[ { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n try:\n celsius = float(celsius)\n return (celsius * 9.0/5) + 32\n except ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031656", "row_id": 31656, "seed_ids": "['Qwen2-72B-Instruct_73108']" }
0.457189
Filter_31656
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "calculate_average_temperatures", "is_valid_temperature" ]
4
[ [ "calculate_average_temperatures", "celsius_to_fahrenheit" ], [ "calculate_average_temperatures", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5648874d0ea2cf23399181a74329b8229f384498
782f2fd756550d1be0ddd1aeb87ca51b765824c8
v1.0
instruct
Filter
Filter_31660_I
Complete the code for a function which takes a string and returns a boolean value based on whether it is an anagram of a palindrome or not. Also, refactor the existing code to handle multiple string inputs in the form of an array, retaining the overall functionality.
from collections import Counter def is_anagram_of_palindrome(s): """ Returns True if the string s is an anagram of a palindrome, False otherwise. """ count = Counter(s) odd_count = sum(1 for count in count.values() if count % 2 != 0) # For a string to be an anagram of a palindrome, # ...
from solution import is_anagram_of_palindrome, are_anagrams_of_palindromes def test_is_anagram_of_palindrome_true(): assert is_anagram_of_palindrome("civic") == True assert is_anagram_of_palindrome("ivicc") == True assert is_anagram_of_palindrome("aabb") == True def test_is_anagram_of_palindrome_false(): ...
[ { "docstring": "Returns True if the string s is an anagram of a palindrome, False otherwise.", "function_declaration": "def is_anagram_of_palindrome(s):", "function_name": "is_anagram_of_palindrome", "parameter_list": "(s)" }, { "docstring": "Takes a list of strings and returns a list of boo...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_anagram_of_palindrome(s):\n \"\"\"\n Checks if the given string s is an anagram of a palindrome or not.\n \"\"\"\n from collections import Counter\n count = Counter(s)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031660", "row_id": 31660, "seed_ids": "['Qwen2-72B-Instruct_73113']" }
0.667243
Filter_31660
I
[ "is_anagram_of_palindrome", "are_anagrams_of_palindromes" ]
2
[ [ "are_anagrams_of_palindromes", "is_anagram_of_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fbb19af393056d259e2bc409d7b9a3b102b437c
a62bca950a7df6da5348433443d6316a4944968f
v1.0
instruct
Filter
Filter_31666_I
Formulate a for loop using Python that iterates 25 times, and at each iteration, checks a condition. If the condition is true, increment a counter, otherwise, continue to the next iteration. Condition: Check if the current iteration index (starting from 0) is a prime number. Remember, a prime number is a number that is...
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, count_primes_in_range def test_is_prime(): assert is_prime(-1) == False assert is_prime(0) == False assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10)...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Count how many numbers in the range from 0 to `limit` (exclusive) are prime.", "function_declaration": "def count_pri...
[ 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 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_0
{ "original_instruction": "", "prompt_id": "00031666", "row_id": 31666, "seed_ids": "['Qwen2-72B-Instruct_73126']" }
0.647804
Filter_31666
I
[ "is_prime", "count_primes_in_range" ]
2
[ [ "count_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
833bae5efb1cb1c3be04438207ec157f9b76bdc5
649acadec77a0c4a695fd9bd9776cd0f9d975ded
v1.0
instruct
Filter
Filter_31685_I
Write a Python script that generates random prime numbers within a given range. Additionally, implement the Miller-Rabin primality test to verify the primality of the generated numbers. You must also incorporate error handling for the input parameters and optimize the code for runtime efficiency.
import random def is_prime(n, k=5): """ Use Miller-Rabin primality test to check if n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False r, s = 0, n - 1 while s % 2 == 0: r += 1 s //= 2 for _ in...
from solution import generate_random_prime, is_prime def test_is_prime_with_known_primes(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(11) == True assert is_prime(6571) == True def test_is_prime_with_known_non_primes(): assert is_prime(1) =...
[ { "docstring": "Use Miller-Rabin primality test to check if n is a prime number.", "function_declaration": "def is_prime(n, k=5):", "function_name": "is_prime", "parameter_list": "(n, k=5)" }, { "docstring": "Generate a random prime number within the given range [start, end].", "function...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(n, k=5):\n \"\"\"\n Use Miller-Rabin primality test to check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031685", "row_id": 31685, "seed_ids": "['Qwen2-72B-Instruct_73159']" }
0.539005
Filter_31685
I
[ "is_prime", "generate_random_prime" ]
2
[ [ "generate_random_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5814c5ce1e6febe8b51555e45b9725e9cbfa0a38
e514ebfdd7be4be6722c305c39066d9a5a6bfafc
v1.0
instruct
Filter
Filter_31698_I
Write a code that checks if a given number is in the range of 0 to 100, and further verifies if the number is a prime number or not. If the number is not in the range, the program should print an error message. If the number is in the range, the program should state if the number is a prime number or not.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def check_number(n): """ Checks if n is in the range 0 to 100 and if so, che...
from solution import is_prime, check_number 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(100) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == Fal...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if n is in the range 0 to 100 and if so,\nchecks whether it is a prime number or not.\nReturns a ...
[ 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 Checks if a given number is prime or not.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031698", "row_id": 31698, "seed_ids": "['Qwen2-72B-Instruct_73190']" }
0.679046
Filter_31698
I
[ "is_prime", "check_number" ]
2
[ [ "check_number", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb55be5e37e3a5ba3ed820949ae7839684d82339
872a31c9cbd4f0c6a126c2ba3269392184001934
v1.0
instruct
Filter
Filter_31715_I
Write a function in Python that takes a list of integers as input and returns a new list containing only the prime numbers from the input list. The function should be implemented using list comprehension.
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(lst): """ Returns a list containing only the prime numbers from the input list. "...
from solution import filter_primes def test_all_prime_numbers(): assert filter_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_no_prime_numbers(): assert filter_primes([4, 6, 8, 10, 12]) == [] def test_mixed_numbers(): assert filter_primes([2, 4, 6, 7, 8, 9, 10, 11]) == [2, 7, 11] def test...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filter_primes(lst):", ...
[ 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, else False.\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_2
{ "original_instruction": "", "prompt_id": "00031715", "row_id": 31715, "seed_ids": "['Qwen2-72B-Instruct_73215']" }
0.651687
Filter_31715
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af26fc8c994c96593481dd022ea77d16e4d89d9a
5a6317365f2f5b58f37bc1b7b58eed4cfae8b313
v1.0
instruct
Filter
Filter_31717_I
Develop an algorithm to perform a ternary search on a single-dimensional, pre-arranged numeric dataset. The function should be able to return the location of the sought value if present. In addition, you should implement an efficient way to handle situations where the array is not sorted in ascending order, where it wo...
def ternary_search(arr, l, r, x): while r >= l: mid1 = l + (r - l) // 3 mid2 = r - (r - l) // 3 if arr[mid1] == x: return mid1 if arr[mid2] == x: return mid2 if x < arr[mid1]: r = mid1 - 1 elif x > arr[mid2]: ...
from solution import ternary_search_with_sort def test_ternary_search_found(): arr = [3, 2, 1, 5, 4] assert ternary_search_with_sort(arr, 3) == 2 def test_ternary_search_not_found(): arr = [10, -4, 6, 12, 8] assert ternary_search_with_sort(arr, 7) == -1 def test_ternary_search_first_element(): ar...
[ { "docstring": null, "function_declaration": "def ternary_search(arr, l, r, x):", "function_name": "ternary_search", "parameter_list": "(arr, l, r, x)" }, { "docstring": null, "function_declaration": "def merge(arr, l, m, r):", "function_name": "merge", "parameter_list": "(arr, l...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def ternary_search(arr, value):\n \"\"\"\n Perform a ternary search on a sorted array.\n If the array is not sorted, first sort it manually, without using built-in sort functions,\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031717", "row_id": 31717, "seed_ids": "['Qwen2-72B-Instruct_73220']" }
0.558998
Filter_31717
I
[ "ternary_search", "merge", "merge_sort", "ternary_search_with_sort" ]
4
[ [ "merge_sort", "merge" ], [ "ternary_search_with_sort", "merge_sort" ], [ "ternary_search_with_sort", "ternary_search" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5ae13c063e616d36763f44a29ab6899c1096558c
aed66a073b187fa43af777ae6a824928735ce460
v1.0
instruct
Filter
Filter_31731_I
Write a simple Python script to display the prime numbers from 1 to 100.
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import is_prime, prime_numbers_up_to_100 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(35) == False def test_prime_numbers_up_to_100(): expected_primes = [ 2, 3, 5, 7, 11,...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 1 to 100.", "function_declaration": "def prime_numbers_up_to_100():", "function_na...
[ 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 Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031731", "row_id": 31731, "seed_ids": "['Qwen2-72B-Instruct_73253']" }
0.6044
Filter_31731
I
[ "is_prime", "prime_numbers_up_to_100" ]
2
[ [ "prime_numbers_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
34a0d3ee6102089e1494d01c1a0db6617269c785
7ccad475f6db10bfe1f2f2b7038512498e034bac
v1.0
instruct
Filter
Filter_31733_I
Write a Bash script to display a given number's multiplication table up to 10. Additionally, also write a Python program for the same operation and compare the time taken by both scripts to generate the multiplication table for a given number.
import time def multiplication_table(number): """ Prints the multiplication table of a given number up to 10. """ for i in range(1, 11): print(f"{number} x {i} = {number * i}") def measure_time(number): """ Measures the time taken by the Python program to generate the multiplication ta...
import subprocess import time from solution import multiplication_table, measure_time def test_multiplication_table_python(): number = 7 table = [] for i in range(1, 11): table.append(f"{number} x {i} = {number * i}") expected_output = "\n".join(table) actual_output = subprocess.getout...
[ { "docstring": "Prints the multiplication table of a given number up to 10.", "function_declaration": "def multiplication_table(number):", "function_name": "multiplication_table", "parameter_list": "(number)" }, { "docstring": "Measures the time taken by the Python program to generate the mu...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef multiplication_table(num):\n \"\"\"\n Prints the multiplication table of a given number up to 10.\n \"\"\"\n for i in range(1, 11):\n print(f\"{num} * {i}...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031733", "row_id": 31733, "seed_ids": "['Qwen2-72B-Instruct_73255']" }
0.468481
Filter_31733
I
[ "multiplication_table", "measure_time" ]
2
[ [ "measure_time", "multiplication_table" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99b2a16e6e180dd4680013c258463b7467ee0d67
f4b9b72dfebe4974bd3a50593a33ed41a6284b56
v1.0
instruct
Filter
Filter_31736_I
Given a linked list that potentially contains a cycle, design an algorithm to not just detect the cycle but also find the length of the cycle. Your function should return the length of the cycle if present, or return -1 if there's no cycle.
class ListNode: def __init__(self, x): self.val = x self.next = None def cycle_length(head): """ This function detects a cycle in a linked list and returns the length of the cycle if present. If no cycle is present, it returns -1. :param head: ListNode :return: int """...
from solution import ListNode, cycle_length def test_no_cycle(): head = ListNode(1) head.next = ListNode(2) head.next.next = ListNode(3) head.next.next.next = ListNode(4) assert cycle_length(head) == -1 def test_single_node_no_cycle(): head = ListNode(1) assert cycle_length(head)...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef detect_cycle_length(head):\n \"\"\"\n Detects the cycle in a linked li...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031736", "row_id": 31736, "seed_ids": "['Qwen2-72B-Instruct_73260']" }
0.523289
Filter_31736
I
[ "cycle_length", "calculate_cycle_length" ]
2
[ [ "cycle_length", "calculate_cycle_length" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
31cc34da1ba7edd42e2a8ce91a245f90193c6af2
95bee3766632d7ba581e96ccc863366d9fb27de8
v1.0
instruct
Filter
Filter_31779_I
Please write a Python program that converts a given weight in kilograms to pounds and vice versa. Also, define the formulas for this conversion in your code. To make it more interesting, implement a function that allows the user to input the weight and choose the unit of measurement they want to convert from and to. He...
def kg_to_lb(kg): """ Convert weight from kilograms to pounds. 1 kilogram is approximately 2.20462 pounds. """ return kg * 2.20462 def lb_to_kg(lb): """ Convert weight from pounds to kilograms. 1 pound is approximately 0.453592 kilograms. """ return lb * 0.453592 def convert_we...
from solution import kg_to_lb, lb_to_kg, convert_weight def test_kg_to_lb(): assert abs(kg_to_lb(1) - 2.20462) < 0.0001 assert abs(kg_to_lb(5) - 11.0231) < 0.0001 assert abs(kg_to_lb(0) - 0) < 0.0001 def test_lb_to_kg(): assert abs(lb_to_kg(1) - 0.453592) < 0.0001 assert abs(lb_to_kg(10) - 4.53592...
[ { "docstring": "Convert weight from kilograms to pounds.\n1 kilogram is approximately 2.20462 pounds.", "function_declaration": "def kg_to_lb(kg):", "function_name": "kg_to_lb", "parameter_list": "(kg)" }, { "docstring": "Convert weight from pounds to kilograms.\n1 pound is approximately 0.4...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kg_to_lb(kg):\n \"\"\"\n Convert weight from kilograms to pounds.\n 1 kilogram is approximately 2.20462 pounds.\n \"\"\"\n return kg * 2.20462\n\ndef lb_to_kg(lb):\n \"\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031779", "row_id": 31779, "seed_ids": "['Qwen2-72B-Instruct_73328']" }
0.447867
Filter_31779
I
[ "kg_to_lb", "lb_to_kg", "convert_weight" ]
3
[ [ "convert_weight", "kg_to_lb" ], [ "convert_weight", "lb_to_kg" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7a7207db9f207ea29708ab6b7c1286de8d15fc16
5a9fc34bc1cdbbc3199da1bab0dc6a92dd24fb10
v1.0
instruct
Filter
Filter_31796_I
Write a program in Python that generates a list of all prime numbers within a given range. The program should take two integers as input, representing the start and end of the range, and should output a list of all prime numbers within that range, inclusive. The program should have a time complexity of O(n * sqrt(m)), ...
import math def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False for i in range(5, int(math.sqrt(n)) + 1, 6): if n % i == 0 or n % (i + 2) == 0: return False return True def generate_primes(start, end)...
from solution import generate_primes def test_generate_primes_basic(): assert generate_primes(1, 10) == [2, 3, 5, 7] assert generate_primes(10, 20) == [11, 13, 17, 19] def test_generate_primes_single_prime(): assert generate_primes(17, 17) == [17] def test_generate_primes_no_primes(): assert generate...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_primes(start, end):", "function_name": "generate_primes", "parameter_list": "(start, end)" } ]
[ 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 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": "00031796", "row_id": 31796, "seed_ids": "['Qwen2-72B-Instruct_73357']" }
0.618261
Filter_31796
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85d09a22244f2c6b3ab9e653e2b6cfaddb314bf5
b4200a1b6a0f701c815129484d2add8d1876acc7
v1.0
instruct
Filter
Filter_31827_I
Create a function that multiplies two large numbers (greater than 100 digits), represented as strings. This function should utilize the Karatsuba algorithm for multiplication, which is more efficient than the traditional grade-school multiplication approach for large numbers. The function should return the product as a...
def karatsuba(x, y): """ Multiplies two numbers using the Karatsuba algorithm. Parameters: x (str): The first number as a string. y (str): The second number as a string. Returns: str: The product of x and y as a string. """ # Remove leading zeros x = x.lstrip('0') y...
from solution import multiply_large_numbers def test_multiply_large_numbers(): num1 = "12345678901234567890123456789012345678901234567890123456789012345678901234567890" num2 = "987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210" expected_product = str(int(num1) * int...
[ { "docstring": "Multiplies two numbers using the Karatsuba algorithm.\n\nParameters:\nx (str): The first number as a string.\ny (str): The second number as a string.\n\nReturns:\nstr: The product of x and y as a string.", "function_declaration": "def karatsuba(x, y):", "function_name": "karatsuba", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def karatsuba_multiply(num1, num2):\n \"\"\"\n Multiplies two large numbers using the Karatsuba algorithm.\n \"\"\"\n # Handling leading zeros\n num1 = num1.lstrip('0')\n num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031827", "row_id": 31827, "seed_ids": "['Qwen2-72B-Instruct_73410']" }
0.674782
Filter_31827
I
[ "karatsuba", "multiply_large_numbers" ]
2
[ [ "multiply_large_numbers", "karatsuba" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c799044202f7ae22e066f9b51c4421210684ebd
e73dab0933d0ab0d8a279ed098f3f81323259df9
v1.0
instruct
Filter
Filter_31830_I
Develop a Python program that reads a list of URLs from a text file and retrieves the titles of the web pages using Beautiful Soup library. Save the titles along with their corresponding URLs in a JSON file.
import requests from bs4 import BeautifulSoup import json def fetch_titles_from_urls(file_path): with open(file_path, 'r') as file: urls = file.readlines() url_titles = {} for url in urls: url = url.strip() response = requests.get(url) soup = BeautifulSoup(response.cont...
import pytest import os import json from unittest.mock import patch, mock_open from solution import fetch_titles_from_urls, save_titles_to_json, process_urls # Mock data mock_urls = ["http://example.com", "http://anotherexample.com"] mock_responses = { "http://example.com": '<html><head><title>Example Domain</titl...
[ { "docstring": null, "function_declaration": "def fetch_titles_from_urls(file_path):", "function_name": "fetch_titles_from_urls", "parameter_list": "(file_path)" }, { "docstring": null, "function_declaration": "def save_titles_to_json(url_titles, output_file_path):", "function_name":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nimport json\n\ndef get_titles_from_urls(input_file, output_file):\n titles_with_urls = []\n\n with open(input_file, 'r') as file:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031830", "row_id": 31830, "seed_ids": "['Qwen2-72B-Instruct_73413']" }
0.710826
Filter_31830
I
[ "fetch_titles_from_urls", "save_titles_to_json", "process_urls" ]
3
[ [ "process_urls", "fetch_titles_from_urls" ], [ "process_urls", "save_titles_to_json" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
a7c2eb84ce959fad62bdf0ac7f865f73752e1029
a0c40fc07e8bc487a6b24581c9d7f9329faeda36
v1.0
instruct
Filter
Filter_31836_I
Write a code to create a 10 x 10 matrix containing all prime numbers. The code should only use the Sieve of Eratosthenes method for generating prime numbers and should not use any built-in functions or libraries for checking if a number is prime. Additionally, the code should be optimized to minimize the time complexit...
def sieve_of_eratosthenes(limit): """ Generate a list of prime numbers up to 'limit' using the Sieve of Eratosthenes. """ sieve = [True] * (limit + 1) sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers for start in range(2, int(limit**0.5) + 1): if sieve[start]: ...
from solution import sieve_of_eratosthenes, generate_10x10_prime_matrix def test_sieve_of_eratosthenes_small_known_limit(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_generate_10x10_prime_matrix_length(): matrix = generate...
[ { "docstring": "Generate a list of prime numbers up to 'limit' using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Generate a 10x10 matrix filled with the firs...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generate a list of prime numbers up to 'limit' using the Sieve of Eratosthenes.\n \"\"\"\n sieve = [True] * (limit + 1)\n sieve[0] =...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031836", "row_id": 31836, "seed_ids": "['Qwen2-72B-Instruct_73424']" }
0.5345
Filter_31836
I
[ "sieve_of_eratosthenes", "generate_10x10_prime_matrix" ]
2
[ [ "generate_10x10_prime_matrix", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4d096f403d6ce2614459a1b9dc6c7ae43593189d
b3106c351daa93d646062eb93d9127fea2f2b5d9
v1.0
instruct
Filter
Filter_31845_I
reverse a given array without using any built-in reverse function, any additional array or data structure, or any loop. The solution must be recursive and the time complexity should be O(n), where n is the size of the array. The recursive function should also take into account the case where the array contains duplicat...
def reverse_array(arr, start, end): """ Recursively reverse the array from start to end. """ if start >= end: return arr[start], arr[end] = arr[end], arr[start] reverse_array(arr, start + 1, end - 1) # Wrapper function to simplify the interface def reverse(arr): reverse_array(arr, 0...
from solution import reverse def test_reverse_even_length(): arr = [1, 2, 3, 4] reverse(arr) assert arr == [4, 3, 2, 1] def test_reverse_odd_length(): arr = [1, 2, 3, 4, 5] reverse(arr) assert arr == [5, 4, 3, 2, 1] def test_reverse_single_element(): arr = [1] reverse(arr) assert ...
[ { "docstring": "Recursively reverse the array from start to end.", "function_declaration": "def reverse_array(arr, start, end):", "function_name": "reverse_array", "parameter_list": "(arr, start, end)" }, { "docstring": null, "function_declaration": "def reverse(arr):", "function_nam...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_array(arr, start=0, end=None):\n \"\"\"\n Reverses the array recursively in-place.\n\n Args:\n - arr: List[int] - array to be reversed\n - start: int - starting inde...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031845", "row_id": 31845, "seed_ids": "['Qwen2-72B-Instruct_73441']" }
0.593283
Filter_31845
I
[ "reverse_array", "reverse" ]
2
[ [ "reverse", "reverse_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c73f170b9b93800e383c3f5e22f54ebf9da34633
dd6692f3d0d20bbff778349afa6bec70f85d5bd8
v1.0
instruct
Filter
Filter_31858_I
Explain how to find the greatest common divisor of two numbers in Python using recursion and implement a program to find the greatest common divisor of a list of numbers. In order to increase the difficulty, you should also explain and implement a method to find the least common multiple of the list of numbers.
def gcd(a, b): """ Returns the greatest common divisor (GCD) of a and b using recursion. """ if b == 0: return a return gcd(b, a % b) def gcd_list(numbers): """ Returns the GCD of a list of numbers. """ from functools import reduce return reduce(gcd, numbers) def lcm(a,...
from solution import gcd, gcd_list, lcm, lcm_list def test_gcd(): assert gcd(48, 18) == 6 assert gcd(101, 10) == 1 assert gcd(54, 24) == 6 def test_gcd_list(): assert gcd_list([48, 18, 30]) == 6 assert gcd_list([101, 10, 7]) == 1 assert gcd_list([54, 24, 36]) == 6 def test_lcm(): assert l...
[ { "docstring": "Returns the greatest common divisor (GCD) of a and b using recursion.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the GCD of a list of numbers.", "function_declaration": "def gcd_list(numbers):"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Returns the Greatest Common Divisor (GCD) of a and b using recursion.\n \"\"\"\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031858", "row_id": 31858, "seed_ids": "['Qwen2-72B-Instruct_73467']" }
0.726259
Filter_31858
I
[ "gcd", "gcd_list", "lcm", "lcm_list" ]
4
[ [ "gcd_list", "gcd" ], [ "lcm", "gcd" ], [ "lcm_list", "lcm" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cefaa09522f98bf2df56aad9bbcd5d399bacf113
1b7d50c9bcbbd5b1b884b1a6d386cceb1ae40037
v1.0
instruct
Filter
Filter_31879_I
Please write a Python script that can convert multiple CSV files into multiple JSON files, each with a unique identifier. The script should read all the CSV files from a specified directory, convert them to JSON, and save each JSON file with a unique identifier in the filename. The script should also create a log file ...
import os import csv import json import uuid import logging def setup_logger(log_file): """ Sets up the logger to record errors in the log file. """ logging.basicConfig(filename=log_file, level=logging.ERROR, format='%(asctime)s:%(levelname)s:%(message)s'...
import os import json import uuid from unittest.mock import patch, mock_open, MagicMock from solution import read_csv, write_json, convert_csv_to_json def test_read_csv(): mock_csv_content = "name,age\nAlice,30\nBob,40\n" expected_output = [{'name': 'Alice', 'age': '30'}, {'name': 'Bob', 'age': '40'}] ...
[ { "docstring": "Sets up the logger to record errors in the log file.", "function_declaration": "def setup_logger(log_file):", "function_name": "setup_logger", "parameter_list": "(log_file)" }, { "docstring": "Reads a CSV file and returns its content as a list of dictionaries.", "function...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport csv\nimport json\nimport uuid\nimport logging\n\ndef setup_logger(log_file):\n \"\"\"\n Sets up the logger to record errors in the log file.\n \"\"\"\n logging.ba...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031879", "row_id": 31879, "seed_ids": "['Qwen2-72B-Instruct_73506']" }
0.704439
Filter_31879
I
[ "setup_logger", "read_csv", "write_json", "convert_csv_to_json" ]
4
[ [ "convert_csv_to_json", "read_csv" ], [ "convert_csv_to_json", "setup_logger" ], [ "convert_csv_to_json", "write_json" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1efb3c97e85d692cda596f1b4b322d625662e9d0
cff16c3441e1ace0c8ae4d0c11c8bd491a580e25
v1.0
instruct
Filter
Filter_31882_I
Complete the following Python code so it prints the Fibonacci series up to the 10th term where each term shall be the product of two previous prime numbers instead of just summing up the two previous terms. The 0th and 1st term of the series are defined as 0 and 1.
def is_prime(n): """ Checks if a given number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, next_prime, fibonacci_prime_series 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 def test_next_prime(): assert next_prime(2) == 3 assert next_pri...
[ { "docstring": "Checks if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates the next prime number after n.", "function_declaration": "def next_prime(n):", "function_name": "next_p...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_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 retu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031882", "row_id": 31882, "seed_ids": "['Qwen2-72B-Instruct_73509']" }
0.721263
Filter_31882
I
[ "is_prime", "next_prime", "fibonacci_prime_series" ]
3
[ [ "fibonacci_prime_series", "next_prime" ], [ "next_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f4f1bddd1c58b9ceb2b7a100bcd9bfe03eaaef7b
4cfd750149adb9d69b3f16a4af9a8391fcaf63b4
v1.0
instruct
Filter
Filter_31885_I
Given the following erroneous code, identify the mistakes and correct them to generate a binary search tree from the given list of integers [35, 15, 33, 72, 11]. Additionally, implement a method to validate if the generated tree is a valid binary search tree or not.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) if key < root.val: root.left = insert(root.left, key) elif key > root.val: root.right = insert(root.ri...
import pytest from solution import TreeNode, insert, generate_bst, is_valid_bst def test_generate_bst_structure(): bst_root = generate_bst([35, 15, 33, 72, 11]) assert bst_root.val == 35 assert bst_root.left.val == 15 assert bst_root.left.left.val == 11 assert bst_root.left.right.val == 33 asse...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.value = key\n\ndef insert(root, key):\n if root is None:\n return Tre...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031885", "row_id": 31885, "seed_ids": "['Qwen2-72B-Instruct_73513']" }
0.508668
Filter_31885
I
[ "insert", "generate_bst", "is_valid_bst" ]
3
[ [ "generate_bst", "insert" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ad181e62cdf6826af3b4353683881089ed01b217
771663fe3ae7078cfd259a19de1b328389b20409
v1.0
instruct
Filter
Filter_31891_I
Create a loop to print the first 100 prime numbers, but make sure that the loop does not use any built-in prime number checking functions or libraries. Additionally, ensure that the implementation uses a separate function to check for prime numbers.
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def first_100_primes():...
from solution import is_prime, first_100_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(4) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(97) == True assert is_prime(99) == Fa...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Print the first 100 prime numbers.", "function_declaration": "def first_100_primes():", "function_name": "first...
[ 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 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": "00031891", "row_id": 31891, "seed_ids": "['Qwen2-72B-Instruct_73526']" }
0.552375
Filter_31891
I
[ "is_prime", "first_100_primes" ]
2
[ [ "first_100_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c26b747e5b080cf09db7c6df3c84fe65434d7599
aefa9779727a953a22100d457af1ef55343cfe4d
v1.0
instruct
Filter
Filter_31905_I
Develop a Python program that generates a list of twin primes between 1 and n, where n is a user input. Twin primes are pairs of prime numbers that differ by two (e.g., (3, 5), (5, 7), (11, 13)). Implement the Brun's constant formula to identify twin primes. Your program should also calculate and display the total numb...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def twin_primes(n): """ ...
from solution import is_prime, twin_primes, find_twin_primes_and_sum 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 def test_twin_primes(): assert twin_primes(10) == [(3, 5), (5, 7)...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of twin primes and calculates the sum.", "function_declaration": "def twin_primes(n):", "function_name": "twin_primes", "par...
[ 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(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031905", "row_id": 31905, "seed_ids": "['Qwen2-72B-Instruct_73551']" }
0.558421
Filter_31905
I
[ "is_prime", "twin_primes", "find_twin_primes_and_sum" ]
3
[ [ "find_twin_primes_and_sum", "twin_primes" ], [ "twin_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e619f9e7bce78427889a5ce4f856e2f81af12cd6
531d0507d4709afc2a60c66576fb49b462f2ff55
v1.0
instruct
Filter
Filter_31913_I
conceive a python code to encode a specific text string in base64 and also decode it back to its original form. Your code should also validate whether the decoded string is the same as the original. Additionally, conduct an analysis on the time complexity of your solution.
import base64 def encode_base64(text): """ Encodes the given text string in base64. """ text_bytes = text.encode('utf-8') base64_bytes = base64.b64encode(text_bytes) return base64_bytes.decode('utf-8') def decode_base64(base64_text): """ Decodes the given base64 string back to its orig...
from solution import encode_base64, decode_base64, validate_base64_encoding_decoding def test_encode_base64(): assert encode_base64("hello") == "aGVsbG8=" assert encode_base64("world") == "d29ybGQ=" assert encode_base64("Base64 Encoding in Python!") == "QmFzZTY0IEVuY29kaW5nIGluIFB5dGhvbiE=" def test_decod...
[ { "docstring": "Encodes the given text string in base64.", "function_declaration": "def encode_base64(text):", "function_name": "encode_base64", "parameter_list": "(text)" }, { "docstring": "Decodes the given base64 string back to its original text form.", "function_declaration": "def de...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import base64\n\ndef encode_base64(input_string):\n \"\"\"\n Encodes the input string in base64.\n \n Args:\n input_string (str): The string to encode.\n \n Returns:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031913", "row_id": 31913, "seed_ids": "['Qwen2-72B-Instruct_73567']" }
0.635863
Filter_31913
I
[ "encode_base64", "decode_base64", "validate_base64_encoding_decoding" ]
3
[ [ "validate_base64_encoding_decoding", "decode_base64" ], [ "validate_base64_encoding_decoding", "encode_base64" ] ]
2
[]
false
[]
false
pytest
true
[]
true
054aca1759ed1d90d6055bf79663f042c1af7f7e
9e6df156ab5e5c9c792a00aca4d929bac27edb06
v1.0
instruct
Filter
Filter_31960_I
Given a positive integer n > 1, output the smallest prime number p that is larger than n, but make sure that the programming language you use doesn't have any inbuilt functions that directly generates prime numbers. In other words, you'll need to implement your own function to check the primality of a number.
def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i +=...
from solution import is_prime, next_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(49) == False def test_next_prime(): assert next_prime(2) == 3 assert n...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number that is larger than n.", "function_declaration": "def next_prime(n):", "function_n...
[ 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 a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031960", "row_id": 31960, "seed_ids": "['Qwen2-72B-Instruct_73651']" }
0.617819
Filter_31960
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
169a65371db9ea672aa5861af0c85211e8b57d34
c0481bc13da0e1a295e7a1eba802a2868c2df29f
v1.0
instruct
Filter
Filter_31981_I
Given a string s, write a function that returns the longest palindromic substring of s. A palindrome is a string that reads the same backward as forward. The function should have a time complexity of O(n^2) and a space complexity of O(1).
def longest_palindromic_substring(s): """ Returns the longest palindromic substring in the given string s. """ n = len(s) if n == 0: return "" start = 0 end = 0 for i in range(n): len1 = expand_around_center(s, i, i) len2 = expand_around_center(s, i, i + 1) ...
from solution import longest_palindromic_substring def test_empty_string(): assert longest_palindromic_substring("") == "" def test_single_character_string(): assert longest_palindromic_substring("a") == "a" def test_two_character_palindrome(): assert longest_palindromic_substring("aa") == "aa" def test...
[ { "docstring": "Returns the longest palindromic substring in the given string s.", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter_list": "(s)" }, { "docstring": "Expand around the center and return the length of t...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def expand_around_center(s, left, right):\n \"\"\"\n Expand around the center to find the palindrome.\n \"\"\"\n while left >= 0 and right < len(s) and s[left] == s[right]:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031981", "row_id": 31981, "seed_ids": "['Qwen2-72B-Instruct_73686']" }
0.833701
Filter_31981
I
[ "longest_palindromic_substring", "expand_around_center" ]
2
[ [ "longest_palindromic_substring", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a41007d276000c3c9c508b5e1ec71b1efe8b6ce
776e294e3d77529f7ca52e6f1caf73dc46d140dd
v1.0
instruct
Filter
Filter_31992_I
Write a Python function that calculates the area and perimeter of a triangle given by 3 points in a 2D plane. Also, write a function to determine if the triangle is a right-angled triangle or not.
import math def triangle_sides(p1, p2, p3): """ Returns the lengths of the sides of a triangle given three points. """ side_1 = math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2) side_2 = math.sqrt((p3[0] - p2[0])**2 + (p3[1] - p2[1])**2) side_3 = math.sqrt((p1[0] - p3[0])**2 + (p1[1] - p3[1])*...
from solution import area_perimeter_triangle, is_right_angle_triangle, triangle_sides def test_triangle_sides(): assert triangle_sides((0, 0), (0, 3), (4, 0)) == (3.0, 5.0, 4.0) def test_area_perimeter_right_triangle(): area, perimeter = area_perimeter_triangle((0, 0), (0, 3), (4, 0)) assert math.isclose(...
[ { "docstring": "Returns the lengths of the sides of a triangle given three points.", "function_declaration": "def triangle_sides(p1, p2, p3):", "function_name": "triangle_sides", "parameter_list": "(p1, p2, p3)" }, { "docstring": "Returns the area and perimeter of a triangle given three poin...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef distance(p1, p2):\n \"\"\"\n Calculate the distance between two points in 2D.\n \"\"\"\n return math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)\n\ndef are...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031992", "row_id": 31992, "seed_ids": "['Qwen2-72B-Instruct_73701']" }
0.724646
Filter_31992
I
[ "triangle_sides", "area_perimeter_triangle", "is_right_angle_triangle" ]
3
[ [ "area_perimeter_triangle", "triangle_sides" ], [ "is_right_angle_triangle", "triangle_sides" ] ]
2
[]
false
[]
false
pytest
true
[]
true
141455dfc145881cb23e382b486f303645a966d1
3c973d5737560aefe922320a5d225fa3a48d7061
v1.0
instruct
Filter
Filter_31997_I
Write a function in Python that takes two parameters, a list of integers and a target integer. The function should return the number of times the target integer appears in the list. The list may contain duplicate values. The function should also check if the target integer is a prime number before counting its occurren...
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 count_tar...
from solution import count_target_in_list def test_target_not_prime(): assert count_target_in_list([1, 2, 3, 2, 5], 1) == -1 assert count_target_in_list([1, 2, 3, 2, 5], 4) == -1 assert count_target_in_list([2, 4, 6, 8], 4) == -1 def test_target_prime(): assert count_target_in_list([1, 2, 3, 2, 5], 2)...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the number of times the target integer appears in the list if \nthe target integer is a prime numbe...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sympy\n\ndef count_prime_occurrences(lst, target):\n \"\"\"\n Returns the number of times the target integer appears in the list.\n If the target integer is not a prime number,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031997", "row_id": 31997, "seed_ids": "['Qwen2-72B-Instruct_73709']" }
0.690274
Filter_31997
I
[ "is_prime", "count_target_in_list" ]
2
[ [ "count_target_in_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aa9e339ec27f9eb8524f0df0e8b8ee0da151246
af3fe3169df668c38b966f6f7838240fedb37216
v1.0
instruct
Filter
Filter_31999_I
Below is the code to add two numbers but you need to make sure that the function 'addNumbers' only accepts positive integers as inputs that are within a range of 1 to 1000 (inclusive). If the input is not within this range or not a positive integer, the function should throw an error with the message "Invalid input". A...
def addNumbers(a, b): """ Returns the sum of a and b if both are positive integers within the range of 1 to 1000 (inclusive). Also checks if the sum is a prime number and returns respective message. """ if not (isinstance(a, int) and isinstance(b, int)) or not (1 <= a <= 1000) or not (1 <= b <= 1000...
import pytest from solution import addNumbers, is_prime def test_addNumbers_positive_integers_within_range(): assert addNumbers(2, 3) == "The sum 5 is a prime number" assert addNumbers(10, 29) == "The sum 39 is not a prime number" def test_addNumbers_invalid_inputs(): with pytest.raises(ValueError, match=...
[ { "docstring": "Returns the sum of a and b if both are positive integers within the range of 1 to 1000 (inclusive).\nAlso checks if the sum is a prime number and returns respective message.", "function_declaration": "def addNumbers(a, b):", "function_name": "addNumbers", "parameter_list": "(a, b)" ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def addNumbers(a, b):\n \"\"\"\n Adds two numbers and checks if the sum is a prime number. Validates input to ensure \n both numbers are positive integers between 1 and 1000 (inclusiv...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031999", "row_id": 31999, "seed_ids": "['Qwen2-72B-Instruct_73712']" }
0.60793
Filter_31999
I
[ "addNumbers", "is_prime" ]
2
[ [ "addNumbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8525a1c4b3083a105d3719a40c262e67ef2b2895
4eedc38769d2dfaf1de1a52c95ecc111e5bf0b22
v1.0
instruct
Filter
Filter_32048_I
Write a Python function that checks if the first letter of a word is the same as the last character of a previous word in a given list of strings. The list can only contain words that are made up of the letters 'a' and 'b'.
def is_valid_list(words): """ Check if a list of words is valid. A valid word only contains 'a' and 'b'. """ for word in words: if not all(char in 'ab' for char in word): return False return True def check_first_last(words): """ Check if the first letter of each word mat...
import pytest from solution import check_first_last def test_valid_transitions(): assert check_first_last(['ab', 'ba', 'ab']) == True assert check_first_last(['a', 'ab', 'ba', 'aa']) == True def test_invalid_transitions(): assert check_first_last(['ab', 'aa', 'ba', 'bb']) == False assert check_first_l...
[ { "docstring": "Check if a list of words is valid. A valid word only contains 'a' and 'b'.", "function_declaration": "def is_valid_list(words):", "function_name": "is_valid_list", "parameter_list": "(words)" }, { "docstring": "Check if the first letter of each word matches the last letter of...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_list(words):\n \"\"\"\n Check if a list of words is valid. A valid word only contains 'a' and 'b'.\n \"\"\"\n for word in words:\n if not all(char in 'ab' for c...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032048", "row_id": 32048, "seed_ids": "['Qwen2-72B-Instruct_73785']" }
0.773719
Filter_32048
I
[ "is_valid_list", "check_first_last" ]
2
[ [ "check_first_last", "is_valid_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46553fd421a1ec8c3e7ef44e7473d73225511c55
aa558150550c802a533f0f4a1cdb5bc9b84ce307
v1.0
instruct
Filter
Filter_32052_I
Given a string s, write a program to partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
def is_palindrome(s: str) -> bool: return s == s[::-1] def partition_palindrome(s: str): def dfs(start, path): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): substring = s[start:end] if is_palindrome(sub...
from solution import is_palindrome, partition_palindrome def test_is_palindrome(): assert is_palindrome('a') == True assert is_palindrome('aa') == True assert is_palindrome('ab') == False assert is_palindrome('racecar') == True def test_partition_palindrome_single_character(): assert partition_pal...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def partition_palindrome(s):", "function_name": "partition_palindrome", "parameter_list": "(s)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef partition(s):\n \"\"\"\n Partition the given string s into all...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032052", "row_id": 32052, "seed_ids": "['Qwen2-72B-Instruct_73791']" }
0.778158
Filter_32052
I
[ "is_palindrome", "partition_palindrome" ]
2
[ [ "partition_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bf41a84ffa156aa93dccf84b7dcdd3bcd90bd4dc
8c7b223e6fd5c5ecaec982048f9490153b40b981
v1.0
instruct
Filter
Filter_32073_I
Print the first 20 prime numbers using a loop in Python. Additionally, implement error handling to display an error message if an unexpected input occurs during the program execution.
def is_prime(n): """ Check 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 first_20_primes(): """ Prints the first 20 prime numbers. """ try: primes = [...
from solution import is_prime, first_20_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 def test_first_20_primes(): expected_primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23,...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints the first 20 prime numbers.", "function_declaration": "def first_20_primes():", "function_name": "first_20...
[ 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 Returns True if n is a prime number, else False.\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_1
{ "original_instruction": "", "prompt_id": "00032073", "row_id": 32073, "seed_ids": "['Qwen2-72B-Instruct_73825']" }
0.641162
Filter_32073
I
[ "is_prime", "first_20_primes" ]
2
[ [ "first_20_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7efce195fd0bda6d50c9eb8d3532416230056a23
b710cb4b25a6282182269d37ff911649ebb4c2a2
v1.0
instruct
Filter
Filter_32079_I
Write a Python function that takes a list of integers as input and sorts it in descending order using the bubble sort algorithm. Then, modify the function to implement the optimized version of bubble sort that stops when the list is already sorted. Finally, write a separate function to verify whether the sorted (desc) ...
def bubble_sort_desc(arr): """ Sorts a list of integers in descending order using the optimized bubble sort algorithm. """ n = len(arr) for i in range(n): swapped = False for j in range(0, n-i-1): if arr[j] < arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] ...
from solution import bubble_sort_desc, is_sorted_desc, verify_sort_stability def test_bubble_sort_desc(): assert bubble_sort_desc([4, 2, 3, 1]) == [4, 3, 2, 1] assert bubble_sort_desc([1, 2, 3, 4]) == [4, 3, 2, 1] assert bubble_sort_desc([4, 3, 2, 1]) == [4, 3, 2, 1] assert bubble_sort_desc([-1, -3, -2...
[ { "docstring": "Sorts a list of integers in descending order using the optimized bubble sort algorithm.", "function_declaration": "def bubble_sort_desc(arr):", "function_name": "bubble_sort_desc", "parameter_list": "(arr)" }, { "docstring": "Checks if a list of integers is sorted in descendi...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort_desc(arr):\n \"\"\"\n Sorts a list of integers in descending order using the bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n swapped...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032079", "row_id": 32079, "seed_ids": "['Qwen2-72B-Instruct_73839']" }
0.624643
Filter_32079
I
[ "bubble_sort_desc", "is_sorted_desc", "verify_sort_stability" ]
3
[ [ "verify_sort_stability", "bubble_sort_desc" ], [ "verify_sort_stability", "is_sorted_desc" ] ]
2
[]
false
[]
false
pytest
true
[]
true
39c770dd6e7d1aa6ec3b8ad472d7d626db106312
865c673491edd9a5fdf6434c21002d3415ab5ec7
v1.0
instruct
Filter
Filter_32082_I
Develop a Python function to compute the factorial of a provided integer using recursion. After you have defined this recursive function, create a second function to handle and guard against potential errors or exceptions such as (0, negative numbers, and non-integer inputs). This second function should call the recurs...
def recursive_factorial(n): """ Returns the factorial of a given non-negative integer n using recursion. """ if n == 0: return 1 return n * recursive_factorial(n - 1) def safe_factorial(n): """ Returns the factorial of a given input n if it's a valid non-negative integer. Otherw...
from solution import recursive_factorial, safe_factorial # Tests for recursive_factorial function def test_recursive_factorial_zero(): assert recursive_factorial(0) == 1 def test_recursive_factorial_positive(): assert recursive_factorial(5) == 120 def test_recursive_factorial_one(): assert recursive_fact...
[ { "docstring": "Returns the factorial of a given non-negative integer n using recursion.", "function_declaration": "def recursive_factorial(n):", "function_name": "recursive_factorial", "parameter_list": "(n)" }, { "docstring": "Returns the factorial of a given input n if it's a valid non-ne...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial_recursive(n):\n \"\"\"\n Computes the factorial of a provided integer n using recursion.\n \"\"\"\n if n == 0:\n return 1\n else:\n return n * factor...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032082", "row_id": 32082, "seed_ids": "['Qwen2-72B-Instruct_73844']" }
0.642996
Filter_32082
I
[ "recursive_factorial", "safe_factorial" ]
2
[ [ "safe_factorial", "recursive_factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19083799d61e5a3c228bba85a098eb539d2b33ea
3ea1bc80b00ca67e3856451a8df4033807f0f056
v1.0
instruct
Filter
Filter_32102_I
Write a program that takes an integer input from the user and then prints that number of random numbers between 1 and 100. The program should use a function that generates a single random number between 1 and 100. In addition, implement an error handling mechanism to make sure the user enters a valid positive integer.
import random def generate_random_number(): """ Returns a single random number between 1 and 100. """ return random.randint(1, 100) def get_random_numbers(quantity): """ Returns a list containing 'quantity' random numbers between 1 and 100. """ if not isinstance(quantity, int) or quant...
from solution import generate_random_number, get_random_numbers def test_generate_random_number(): number = generate_random_number() assert 1 <= number <= 100 def test_get_random_numbers_valid_input(): random_numbers = get_random_numbers(5) assert len(random_numbers) == 5 assert all(1 <= number <=...
[ { "docstring": "Returns a single random number between 1 and 100.", "function_declaration": "def generate_random_number():", "function_name": "generate_random_number", "parameter_list": "()" }, { "docstring": "Returns a list containing 'quantity' random numbers between 1 and 100.", "func...
[ 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 generate_random_number():\n \"\"\"\n Generates a random number between 1 and 100.\n \"\"\"\n return random.randint(1, 100)\n\ndef get_random_numbers(count):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032102", "row_id": 32102, "seed_ids": "['Qwen2-72B-Instruct_73878']" }
0.525567
Filter_32102
I
[ "generate_random_number", "get_random_numbers", "main" ]
3
[ [ "get_random_numbers", "generate_random_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f97278bae6da396e1e49de40df847bb85e34c79e
a430c1f524c3ee7c4a7a0debe875f1f0c754dd4b
v1.0
instruct
Filter
Filter_32108_I
Given a set of points on a two-dimensional plane, design an algorithm in python that clusters the points into k clusters using the k-means clustering algorithm. Additionally, implement a method to determine the optimal number of clusters by using the elbow method. You should also provide a way to visualize the clusters...
import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import KMeans from sklearn.metrics import pairwise_distances_argmin_min def k_means_clustering(points, k): """ Clusters the points into k clusters using the k-means clustering algorithm. Parameters: points (np.ndarray): 2D array o...
import numpy as np from solution import k_means_clustering, find_optimal_clusters, plot_clusters def test_k_means_clustering_basic(): points = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]]) cluster_centers, labels, inertia = k_means_clustering(points, 2) assert len(cluster_centers) == 2 ass...
[ { "docstring": "Clusters the points into k clusters using the k-means clustering algorithm.\n\nParameters:\npoints (np.ndarray): 2D array of points to be clustered.\nk (int): Number of clusters.\n\nReturns:\ntuple: (cluster_centers, labels, inertia)\n - cluster_centers (np.ndarray): Coordinates of cluster ce...
[ 0, 0, 1 ]
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\nfrom sklearn.cluster import KMeans\nfrom sklearn.metrics import pairwise_distances_argmin_min\n\ndef k_means_clustering(points, k):\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032108", "row_id": 32108, "seed_ids": "['Qwen2-72B-Instruct_73888']" }
0.595976
Filter_32108
I
[ "k_means_clustering", "find_optimal_clusters", "plot_clusters" ]
3
[ [ "find_optimal_clusters", "k_means_clustering" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy", "sklearn" ]
false
7ddc0d7739ed695dad355404e73b7182bfc3c1bf
e10f2be884cfc1d02f8e75708f7f1464f99c2211
v1.0
instruct
Filter
Filter_32113_I
Swap two numbers in python without using a third variable and perform this operation for two lists of N numbers pairwise (i.e., the first element of the first list should be swapped with the first element of the second list, etc.) Your solution must work for any data types, not just numbers. Also, implement this in a f...
def swap_values(a, b): """ Swaps the values of variables a and b without using a third variable. """ a, b = b, a return a, b def swap_lists(list1, list2): """ Swaps values of two lists pairwise i.e., the first element of the first list is swapped with the first element of the second lis...
from solution import swap_values, swap_lists def test_swap_values(): a, b = 1, 2 a, b = swap_values(a, b) assert a == 2 assert b == 1 a, b = 'hello', 'world' a, b = swap_values(a, b) assert a == 'world' assert b == 'hello' def test_swap_lists(): list1 = [1, 2, 3] list2 = [4, 5...
[ { "docstring": "Swaps the values of variables a and b without using a third variable.", "function_declaration": "def swap_values(a, b):", "function_name": "swap_values", "parameter_list": "(a, b)" }, { "docstring": "Swaps values of two lists pairwise i.e., the first element\nof the first lis...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def swap_pairwise(list1, list2):\n \"\"\"\n Swaps elements of list1 and list2 pairwise. The first element of list1 is swapped with the first element of list2, \n the second element of...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032113", "row_id": 32113, "seed_ids": "['Qwen2-72B-Instruct_73897']" }
0.66299
Filter_32113
I
[ "swap_values", "swap_lists" ]
2
[ [ "swap_lists", "swap_values" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91ae2e696587328745d1a8f654e671fd22fd569b
05a0ccce4c9a883b7265bb07bc148940f1c079c7
v1.0
instruct
Filter
Filter_32116_I
Develop a Python function aimed to encode and decode a given text string and a file using a user-defined encoding and decoding algorithm. You should implement a one-time pad methodology for encryption and decryption. Your implementation should include the generation of a random key of definable length for the one time ...
import os import random import string def generate_key(length): """ Generates a random key of the specified length. """ return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=length)) def encode(text, key): """ Encodes the given text using the one-time...
from solution import generate_key, encode, decode, encrypt_file, decrypt_file import os def test_generate_key(): key = generate_key(10) assert len(key) == 10 assert all(c in string.ascii_uppercase + string.ascii_lowercase + string.digits for c in key) def test_encode_decode(): text = "Hello, World!" ...
[ { "docstring": "Generates a random key of the specified length.", "function_declaration": "def generate_key(length):", "function_name": "generate_key", "parameter_list": "(length)" }, { "docstring": "Encodes the given text using the one-time pad methodology with the provided key.", "func...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport random\n\ndef generate_key(length):\n \"\"\"\n Generates a random key of specified length using characters from the ASCII range 32 to 126.\n \"\"\"\n return ''.jo...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032116", "row_id": 32116, "seed_ids": "['Qwen2-72B-Instruct_73900']" }
0.620428
Filter_32116
I
[ "generate_key", "encode", "decode", "encrypt_file", "decrypt_file" ]
5
[ [ "decrypt_file", "decode" ], [ "encrypt_file", "encode" ] ]
2
[]
false
[]
false
pytest
true
[]
true
59af5f6f02df6264954f747dbf88097c72e5cce1
fd6bb002d1b349c225488b0a1880d0693341d384
v1.0
instruct
Filter
Filter_32129_I
Define a Python function that takes two strings as input. The first one should be an English word and the second one should be its synonyms separated by comma ("). The task of the function is to check if any of these synonyms are an anagram of the original English word. The function should return True if at least one o...
def are_anagrams(word1, word2): """ Helper function to check if two words are anagrams. """ return sorted(word1) == sorted(word2) def check_anagram_synonyms(word, synonyms): """ Checks if any of the synonyms are an anagram of the given word. Parameters: word (str): The original English...
def test_check_anagram_synonyms(): assert check_anagram_synonyms("listen", "enlist,silent,tinsel") == True assert check_anagram_synonyms("node", "deno,done,neon") == True assert check_anagram_synonyms("hello", "world,hi,hey") == False assert check_anagram_synonyms("evil", "vile,viles,live") == True ...
[ { "docstring": "Helper function to check if two words are anagrams.", "function_declaration": "def are_anagrams(word1, word2):", "function_name": "are_anagrams", "parameter_list": "(word1, word2)" }, { "docstring": "Checks if any of the synonyms are an anagram of the given word.\n\nParameter...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_anagrams(word1, word2):\n \"\"\"\n Helper function to check if two words are anagrams.\n \"\"\"\n return sorted(word1) == sorted(word2)\n\ndef check_anagram_synonyms(word, ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032129", "row_id": 32129, "seed_ids": "['Qwen2-72B-Instruct_73923']" }
0.589199
Filter_32129
I
[ "are_anagrams", "check_anagram_synonyms" ]
2
[ [ "check_anagram_synonyms", "are_anagrams" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d8a3ae9a519b3445d4c5a0e286e04538989f834b
ae0937e797b46dffe1ac63dadb64ba7d629658a5
v1.0
instruct
Filter
Filter_32143_I
Write a python function which, given a list of strings, finds the string which contains the largest number of vowels. In the case of a tie, return the string which appears earlier in the list.
def count_vowels(s): """ Helper function to count the number of vowels in a string. """ vowels = 'aeiouAEIOU' return sum(1 for char in s if char in vowels) def string_with_most_vowels(strings): """ Given a list of strings, finds the string which contains the largest number of vowels. In...
from solution import string_with_most_vowels def test_string_with_most_vowels_single_string(): assert string_with_most_vowels(["hello"]) == "hello" def test_string_with_most_vowels_multiple_strings(): assert string_with_most_vowels(["hello", "world"]) == "hello" assert string_with_most_vowels(["python", "...
[ { "docstring": "Helper function to count the number of vowels in a string.", "function_declaration": "def count_vowels(s):", "function_name": "count_vowels", "parameter_list": "(s)" }, { "docstring": "Given a list of strings, finds the string which contains the largest\nnumber of vowels. In ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_vowels(s):\n \"\"\"\n Returns the count of vowels in the string s.\n \"\"\"\n vowels = \"aeiouAEIOU\"\n return sum(1 for char in s if char in vowels)\n\ndef find_strin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032143", "row_id": 32143, "seed_ids": "['Qwen2-72B-Instruct_73949']" }
0.755579
Filter_32143
I
[ "count_vowels", "string_with_most_vowels" ]
2
[ [ "string_with_most_vowels", "count_vowels" ] ]
1
[]
false
[]
false
pytest
true
[]
true
160514eb75fc18fb1e3cc4aa71ff287ada46a844
215063bc1aec904ad3e5332bfa625b008bbd0935
v1.0
instruct
Filter
Filter_32157_I
I have a string list ["03-09-2000", "01-10-2023"], I want to sort it in chronological order using Python. However, this string list has a problem: some of the dates could be expressed in the DD-MM-YYYY format while others could be in the YYYY-MM-DD format. Your task is to write a function that can sort the list first b...
from datetime import datetime def identify_format(date_str): """Identify if the date format is DD-MM-YYYY or YYYY-MM-DD.""" try: datetime.strptime(date_str, "%Y-%m-%d") return "%Y-%m-%d" except ValueError: return "%d-%m-%Y" def sort_dates(date_list): """Sorts a list of dates in...
from solution import sort_dates def test_all_yyyy_mm_dd(): assert sort_dates(["2023-01-10", "2000-09-03"]) == ["2000-09-03", "2023-01-10"] def test_all_dd_mm_yyyy(): assert sort_dates(["01-10-2023", "03-09-2000"]) == ["03-09-2000", "01-10-2023"] def test_mixed_formats(): assert sort_dates(["03-09-2000", ...
[ { "docstring": "Identify if the date format is DD-MM-YYYY or YYYY-MM-DD.", "function_declaration": "def identify_format(date_str):", "function_name": "identify_format", "parameter_list": "(date_str)" }, { "docstring": "Sorts a list of dates in chronological order.", "function_declaration...
[ 0, 0, 1 ]
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 identify_date_format(date_str):\n \"\"\"\n Identifies the date format of the given date string.\n \"\"\"\n formats = [\"%d-%m-%Y\", \"%Y-%m-%d\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032157", "row_id": 32157, "seed_ids": "['Qwen2-72B-Instruct_73972']" }
0.607615
Filter_32157
I
[ "identify_format", "sort_dates" ]
2
[ [ "sort_dates", "identify_format" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22543cc14fdda45cf74d8975c1ec6ecff6d57f41
e7ad891aee78ddfb38546f52b8387994b081c4fd
v1.0
instruct
Filter
Filter_32180_I
Use the 'functools' module in Python and create a function that calculates the sum of all elements in a list of integers. Additionally, ensure that the function uses memoization to optimize the performance for large lists.
from functools import lru_cache @lru_cache(None) def sum_elements(lst): """ Calculates the sum of all elements in a list of integers with the help of memoization. Parameters: lst (tuple): A tuple of integers because lists are not hashable and cannot be used with lru_cache. Returns: int: T...
from solution import sum_elements_list def test_sum_empty_list(): assert sum_elements_list([]) == 0 def test_sum_single_element_list(): assert sum_elements_list([5]) == 5 def test_sum_multiple_elements_list(): assert sum_elements_list([1, 2, 3, 4]) == 10 def test_sum_large_elements_list(): assert su...
[ { "docstring": "Calculates the sum of all elements in a list of integers with the help of memoization.\n\nParameters:\nlst (tuple): A tuple of integers because lists are not hashable and cannot be used with lru_cache.\n\nReturns:\nint: The sum of all elements in the list.", "function_declaration": "def sum_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import lru_cache\n\n@lru_cache(None)\ndef sum_list(lst):\n \"\"\"\n Returns the sum of all elements in a list of integers.\n Uses memoization to optimize performance fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032180", "row_id": 32180, "seed_ids": "['Qwen2-72B-Instruct_74003']" }
0.676616
Filter_32180
I
[ "sum_elements", "sum_elements_list" ]
2
[ [ "sum_elements_list", "sum_elements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8afb5b557e8eb680e07945661c58618448888f4e
25ecbeeb5f892653f845ac14e6a11b92aba4e5e4
v1.0
instruct
Filter
Filter_32182_I
Write a Python program that accepts a user-inputted list of numbers and outputs the list in reverse order without using built-in functions like reverse(). The program should include input validation to ensure only integer values are accepted.
def reverse_numbers_list(numbers): """ Returns the list of numbers in reverse order. Parameters: numbers (list of int): The list of integers to be reversed. Returns: list of int: The reversed list of integers. """ reversed_list = [] for i in range(len(numbers) - 1, -1, -1):...
from solution import reverse_numbers_list, validate_and_reverse def test_reverse_numbers_list(): assert reverse_numbers_list([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1] assert reverse_numbers_list([10]) == [10] assert reverse_numbers_list([]) == [] assert reverse_numbers_list([-1, -2, -3]) == [-3, -2, -1] ...
[ { "docstring": "Returns the list of numbers in reverse order.\n\nParameters:\nnumbers (list of int): The list of integers to be reversed.\n\nReturns:\nlist of int: The reversed list of integers.", "function_declaration": "def reverse_numbers_list(numbers):", "function_name": "reverse_numbers_list", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_list(input_list):\n \"\"\"\n Reverses the input list without using built-in functions like reverse().\n \n :param input_list: list of integers\n :return: list of int...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032182", "row_id": 32182, "seed_ids": "['Qwen2-72B-Instruct_74005']" }
0.650172
Filter_32182
I
[ "reverse_numbers_list", "validate_and_reverse" ]
2
[ [ "validate_and_reverse", "reverse_numbers_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68cd6f7a3edc384e994b35b97d523c19f12efcbc
084572b0335fd4a034cac26ba762d587857c2dfd
v1.0
instruct
Filter
Filter_32207_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 string and the second element is a prime number.
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 get_valid_pairs(pairs): """ Returns a list of pairs where the first element is a ...
from solution import is_prime, get_valid_pairs 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(-3) == False def test_get_valid_pairs(): ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of pairs where the first element is a string and the second element is a prime number.", "...
[ 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, else False.\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": "00032207", "row_id": 32207, "seed_ids": "['Qwen2-72B-Instruct_74042']" }
0.581346
Filter_32207
I
[ "is_prime", "get_valid_pairs" ]
2
[ [ "get_valid_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4312809597da16cc99ac6f27b183a747ab699bbe
00e1f5691f9b8595c01ddd27aeb196adc5b4063b
v1.0
instruct
Filter
Filter_32215_I
Write a Python code to print out all the Thursdays of a leap year between two provided dates which fall in two consecutive leap years. The output should be in the format, 'DD-MM-YYYY'. Additionally, write a function to verify the correctness of your solution with at least 5 different test cases.
from datetime import datetime, timedelta def is_leap_year(year): """ Check if a year is a leap year. """ return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) def get_leap_year_thursdays(start_date, end_date): """ Return a list of all Thursdays in leap years between start_date and en...
from solution import get_leap_year_thursdays def test_thursdays_leap_year_within_single_leap_year(): assert get_leap_year_thursdays('01-01-2020', '31-12-2020') == [ '02-01-2020', '09-01-2020', '16-01-2020', '23-01-2020', '30-01-2020', '06-02-2020', '13-02-2020', '20-02-2020', '27-02-2020', '05-03-...
[ { "docstring": "Check if a year is a leap year.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Return a list of all Thursdays in leap years between start_date and end_date inclusive.\n\nParameters:\n star...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import date, timedelta\n\ndef is_leap_year(year):\n \"\"\"\n Returns True if the given year is a leap year, otherwise returns False.\n \"\"\"\n return year % 4 == 0 a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032215", "row_id": 32215, "seed_ids": "['Qwen2-72B-Instruct_74050']" }
0.566809
Filter_32215
I
[ "is_leap_year", "get_leap_year_thursdays" ]
2
[ [ "get_leap_year_thursdays", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8974a1bf360cdf013015320152a1bd180364be35
6a703a317ad5c211e8ff5664951af196f7b53b60
v1.0
instruct
Filter
Filter_32218_I
Write a Python program that determines whether a user-entered number is a prime number or not. The program should prompt the user to input a number, then output a message stating whether the number is prime or not. The program should use functions and error handling to ensure that the user enters a valid number.
def is_prime(number): """ Determines whether the given number is a prime number. Returns True if the number is prime, otherwise False. """ if number <= 1: return False if number == 2: return True if number % 2 == 0: return False for i in range(3, int(number**0.5) ...
from solution import is_prime, check_prime def test_is_prime_zero(): assert not is_prime(0), "0 is not a prime number" def test_is_prime_one(): assert not is_prime(1), "1 is not a prime number" def test_is_prime_two(): assert is_prime(2), "2 is a prime number" def test_is_prime_odd_prime(): assert i...
[ { "docstring": "Determines whether the given number is a prime number.\nReturns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Prompts the user to enter a number and...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(number):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if number <= 1:\n return False\n for i in range(2, int(number ** 0.5) + 1):\n if numbe...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032218", "row_id": 32218, "seed_ids": "['Qwen2-72B-Instruct_74054']" }
0.794651
Filter_32218
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a84e137a4b000cecaa66d9310663cbf94e96ed4d
05e2720ffe46a6a7f511e2c394227b8b3ef251ca
v1.0
instruct
Filter
Filter_32225_I
Write code to print a multiplication table of prime numbers between 1 and 100.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ 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_prime_numbers(lower, upper): """ Generates a list of prime number...
from solution import is_prime, generate_prime_numbers def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_generate_prime_numbers(): assert generate_prime_numbers(1, 10) == [2, 3,...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list of prime numbers between lower and upper (inclusive).", "function_declaration": "de...
[ 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(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": "00032225", "row_id": 32225, "seed_ids": "['Qwen2-72B-Instruct_74062']" }
0.555096
Filter_32225
I
[ "is_prime", "generate_prime_numbers", "print_prime_multiplication_table" ]
3
[ [ "generate_prime_numbers", "is_prime" ], [ "print_prime_multiplication_table", "generate_prime_numbers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
826e2f0c115e702a0ac047f41098b07e67731b9d
b738935df034d24ab6b93b6527c61913b9bfe325
v1.0
instruct
Filter
Filter_32249_I
Create a program which finds patterns in a stream of numbers and prints out the start of the pattern. But the program should be able to recognize and handle different types of patterns like geometric, arithmetic, and also Fibonacci series. The program should also handle the errors in data input and provide an appropria...
def find_pattern(input_string): """ Determines the type of pattern (arithmetic, geometric, Fibonacci) in the given string of comma-separated numbers. Prints out the start of the pattern. If no pattern is detected, prints an appropriate message. """ try: # Convert input to a list of inte...
from solution import find_pattern def test_arithmetic_pattern(): assert find_pattern("2,4,6,8,10") == "Arithmetic pattern starting with 2." assert find_pattern("5,8,11,14,17") == "Arithmetic pattern starting with 5." def test_geometric_pattern(): assert find_pattern("3,9,27,81") == "Geometric pattern star...
[ { "docstring": "Determines the type of pattern (arithmetic, geometric, Fibonacci) in the \ngiven string of comma-separated numbers. Prints out the start of the pattern.\nIf no pattern is detected, prints an appropriate message.", "function_declaration": "def find_pattern(input_string):", "function_name"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_pattern(stream):\n \"\"\"\n This function finds patterns in a stream of numbers and prints out the start of the pattern.\n It can recognize geometric, arithmetic, and Fibonac...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032249", "row_id": 32249, "seed_ids": "['Qwen2-72B-Instruct_74104']" }
0.618094
Filter_32249
I
[ "find_pattern", "is_arithmetic_pattern", "is_geometric_pattern", "is_fibonacci_pattern" ]
4
[ [ "find_pattern", "is_arithmetic_pattern" ], [ "find_pattern", "is_fibonacci_pattern" ], [ "find_pattern", "is_geometric_pattern" ] ]
3
[]
false
[]
false
pytest
true
[]
true
fd037efb4b214f47ab8797b874287d21791f21ea
07c78599476f82d00688e4534a195c9b3dfdf78c
v1.0
instruct
Filter
Filter_32257_I
Write a python program that reads in the first 10,000 non-negative integers from stdin and sorts them in ascending order using the bucket sort algorithm. Assume that the input will be well-formed and will not exceed 10,000 lines. Each line will contain a single non-negative integer. The program should output the sorted...
def bucket_sort(arr): """ Function to perform bucket sort on a list of non-negative integers. """ if not arr: return [] # Find the maximum value in the array to determine the range of numbers max_value = max(arr) # Create buckets bucket_count = max_value + 1 # Number of bucket...
from solution import bucket_sort def test_bucket_sort_empty(): assert bucket_sort([]) == [] def test_bucket_sort_single_element(): assert bucket_sort([5]) == [5] def test_bucket_sort_sorted(): assert bucket_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_bucket_sort_reverse_order(): assert bucket_...
[ { "docstring": "Function to perform bucket sort on a list of non-negative integers.", "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_sort", "parameter_list": "(arr)" }, { "docstring": "Reads up to 10,000 non-negative integers from stdin, sorts them using bucket sor...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bucket_sort(arr):\n \"\"\"\n Function to perform bucket sort on a list of non-negative integers.\n \"\"\"\n if not arr:\n return []\n\n # Find the maximum value in th...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032257", "row_id": 32257, "seed_ids": "['Qwen2-72B-Instruct_74116']" }
0.541634
Filter_32257
I
[ "bucket_sort", "read_and_sort" ]
2
[ [ "read_and_sort", "bucket_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e504b4d4abcca31a7359722d6806cfb22123306a
d3c64e7a9d3e44a801bb03e04da7ed6dc0b3574d
v1.0
instruct
Filter
Filter_32285_I
Create a query string from a given dictionary, where the dictionary may contain nested dictionaries and lists. The query string should be sorted in lexicographical order and all keys and values should be URL encoded. Additionally, any nested dictionaries should be prefixed with their parent key, separated by an undersc...
import urllib.parse def flatten_dict(d, parent_key=''): items = [] for k, v in sorted(d.items()): new_key = f"{parent_key}_{k}" if parent_key else k if isinstance(v, dict): items.extend(flatten_dict(v, new_key).items()) elif isinstance(v, list): for i, item in en...
from solution import dict_to_query_string def test_simple_dict(): assert dict_to_query_string({'key1': 'value1', 'key2': 'value2'}) == 'key1=value1&key2=value2' def test_dict_with_special_characters(): assert dict_to_query_string({'key1': 'value with spaces', 'key&2': 'value@with#chars'}) == 'key%262=value%40...
[ { "docstring": null, "function_declaration": "def flatten_dict(d, parent_key=''):", "function_name": "flatten_dict", "parameter_list": "(d, parent_key='')" }, { "docstring": null, "function_declaration": "def dict_to_query_string(d):", "function_name": "dict_to_query_string", "pa...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import urllib.parse\n\ndef encode_query_string(input_dict):\n \"\"\"\n Encodes a dictionary into a URL query string sorted by keys lexicographically.\n Handles nested dictionaries by ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032285", "row_id": 32285, "seed_ids": "['Qwen2-72B-Instruct_74158']" }
0.502673
Filter_32285
I
[ "flatten_dict", "dict_to_query_string" ]
2
[ [ "dict_to_query_string", "flatten_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d22f344da3ad148b710f58e9431e609312720f73
fbe4e2ab0b133bfecf1eff495c432ffacb10f6f5
v1.0
instruct
Filter
Filter_32295_I
Develop a function in Python that identifies all the palindromes in a given list of strings. Additionally, the function should be able to handle strings with uppercase and lowercase letters, and should disregard punctuation and spaces when identifying palindromes. The function will need to filter these from the strings...
import re def is_palindrome(s): """ Helper function that checks if a given string is a palindrome. """ cleaned = re.sub(r'[^A-Za-z0-9]', '', s.lower()) return cleaned == cleaned[::-1] def find_palindromes(strings): """ Returns a list of palindromes found in the given list of strings. "...
from solution import find_palindromes, is_palindrome def test_is_palindrome(): assert is_palindrome("A man, a plan, a canal, Panama") == True assert is_palindrome("No 'x' in Nixon") == True assert is_palindrome("Hello") == False assert is_palindrome("racecar") == True assert is_palindrome("12321") ...
[ { "docstring": "Helper function that checks if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns a list of palindromes found in the given list of strings.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef identify_palindromes(strings):\n \"\"\"\n Identifies all palindromes in a given list of strings, disregarding punctuation, spaces, and case.\n \n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032295", "row_id": 32295, "seed_ids": "['Qwen2-72B-Instruct_74172']" }
0.759938
Filter_32295
I
[ "is_palindrome", "find_palindromes" ]
2
[ [ "find_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5d80c68861c3e2fbae431d8edaf1187678a029b
25e6a27260cd7ab1b3cb560392359d25bc722c82
v1.0
instruct
Filter
Filter_32297_I
Write a script that prints out the first 100 prime numbers in reverse order. The script should use a time complexity of O(n√m), where n is the index of the prime number and m is the number being checked for primality.
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import is_prime, first_n_primes, first_100_primes_reverse 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 def test_first_n_primes(): assert first_n_primes(5) == [2, 3, ...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "first_n_prim...
[ 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": "00032297", "row_id": 32297, "seed_ids": "['Qwen2-72B-Instruct_74176']" }
0.588033
Filter_32297
I
[ "is_prime", "first_n_primes", "first_100_primes_reverse" ]
3
[ [ "first_100_primes_reverse", "first_n_primes" ], [ "first_n_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
903da23f047a977ca3f9f23b948b3c611b7450fd
bd18d7393ea76a608436f4a3595c5e93d2065db8
v1.0
instruct
Filter
Filter_32301_I
If I have a function such as the one defined below, which has a vector and a hyperparameter as its arguments, how should I define the gradient of this function in PyTorch? Additionally, I'm interested in understanding how the shape of the gradient relates to the input vector.
import torch def my_function(vector, hyperparameter): """ A sample function that takes a vector and a hyperparameter, and returns a scalar output. For this example, let's use a simple quadratic form. """ return hyperparameter * torch.sum(vector ** 2) def compute_gradient(vector, hyperparamet...
from solution import my_function, compute_gradient import torch def test_my_function_scalar_output(): vector = torch.tensor([1.0, 2.0, 3.0]) hyperparameter = 2.0 result = my_function(vector, hyperparameter) assert torch.is_tensor(result) assert result.item() == 2.0 * (1.0**2 + 2.0**2 + 3.0**2) def...
[ { "docstring": "A sample function that takes a vector and a hyperparameter, \nand returns a scalar output. For this example, let's use a \nsimple quadratic form.", "function_declaration": "def my_function(vector, hyperparameter):", "function_name": "my_function", "parameter_list": "(vector, hyperpar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\n\ndef my_function(vector, hyperparameter):\n \"\"\"\n Example function that takes a vector and a hyperparameter as input,\n and returns a scalar computed from these inpu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032301", "row_id": 32301, "seed_ids": "['Qwen2-72B-Instruct_74186']" }
0.267247
Filter_32301
I
[ "my_function", "compute_gradient" ]
2
[ [ "compute_gradient", "my_function" ] ]
1
[]
false
[]
false
pytest
true
[ "torch" ]
false
ff767c6ec607df7bdf556e4c9e575af3fe621eca
7424cb9b347d954baa6190b404671d17f3f5cba0
v1.0
instruct
Filter
Filter_32302_I
Calculate the first 10 prime numbers using python without using any built-in function for checking primes and without using any libraries. Additionally, optimize your solution so that it runs as efficiently as possible.
def is_prime(n): """ Helper function to determine if a number is prime. Returns True if n is prime, else False. """ if n <= 1: return False if n == 2: return True for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def first_n_...
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(29) == True assert is_prime(0) == False assert is_prime(1) == False assert is_prime(-5) == Fals...
[ { "docstring": "Helper function to determine if a number is prime.\nReturns True if n is prime, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of the first `limit` prime numbers.", "function...
[ 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.\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_2
{ "original_instruction": "", "prompt_id": "00032302", "row_id": 32302, "seed_ids": "['Qwen2-72B-Instruct_74187']" }
0.595194
Filter_32302
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f953e79ca8a0291877567ab8984c3ae33ce3b08
bdf1166ce5f982507eb1f5a27b092b448feeaf50
v1.0
instruct
Filter
Filter_32319_I
Implement a program to find the longest palindromic substring in a given string. The program should have a time complexity of O(n^2) and a space complexity of O(1).
def longest_palindromic_substring(s): """ Returns the longest palindromic substring of the given string s. """ if not s: return "" start, end = 0, 0 for i in range(len(s)): len1 = expand_around_center(s, i, i) len2 = expand_around_center(s, i, i + 1) max...
from solution import longest_palindromic_substring def test_empty_string(): assert longest_palindromic_substring("") == "" def test_single_character(): assert longest_palindromic_substring("a") == "a" def test_two_same_characters(): assert longest_palindromic_substring("aa") == "aa" def test_palindromic...
[ { "docstring": "Returns the longest palindromic substring of the given string s.", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def expand_around...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Find the longest palindromic substring in a given string.\n\n :param s: Input string\n :return: Longest palindromic substring\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032319", "row_id": 32319, "seed_ids": "['Qwen2-72B-Instruct_74221']" }
0.786003
Filter_32319
I
[ "longest_palindromic_substring", "expand_around_center" ]
2
[ [ "longest_palindromic_substring", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78f5d62da23f0395804799ead4debbf3e6338df6
1bfe593fe5d60a430c30bdf3aacf31f8053d39f2
v1.0
instruct
Filter
Filter_32332_I
Implement a function in a programming language of your choice that takes an array of integers as input and returns the sum of all the prime numbers in the array.
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 sum_of_primes(arr):...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(0) == False assert is_prime(1) == False assert is_prime(-5) == False def test_sum_of_primes_with_p...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers in the array.", "function_declaration": "def sum_of_primes(arr):", "function_nam...
[ 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 <= 3:\n return True\n if n % 2 == 0 or n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032332", "row_id": 32332, "seed_ids": "['Qwen2-72B-Instruct_74256']" }
0.614228
Filter_32332
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c452a9263356b3bc355a7d7a2468ea00edf01c52
2a4a3545df58195d25693f340e2259e6d7d0a983
v1.0
instruct
Filter
Filter_32357_I
Translate the following Python loop into a generator expression, but this time, instead of checking simple divisibility by 2, find all Fibonacci numbers in the data list. A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square. Remember that your solution should still be effic...
import math def is_fibonacci(n): """ Checks if a number is a Fibonacci number by checking if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square. """ x1 = 5 * n * n + 4 x2 = 5 * n * n - 4 return is_perfect_square(x1) or is_perfect_square(x2) def is_perfect_square(x): """ ...
from solution import is_fibonacci, is_perfect_square, find_fibonacci_numbers def test_is_perfect_square(): assert is_perfect_square(4) == True assert is_perfect_square(5) == False assert is_perfect_square(9) == True assert is_perfect_square(10) == False def test_is_fibonacci(): assert is_fibonacc...
[ { "docstring": "Checks if a number is a Fibonacci number by checking if one or both of \n(5*n^2 + 4) or (5*n^2 - 4) is a perfect square.", "function_declaration": "def is_fibonacci(n):", "function_name": "is_fibonacci", "parameter_list": "(n)" }, { "docstring": "Checks if a number x is a per...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_fibonacci(n):\n \"\"\"\n Checks if a given number n is a Fibonacci number by determining if one or both\n of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032357", "row_id": 32357, "seed_ids": "['Qwen2-72B-Instruct_74300']" }
0.625271
Filter_32357
I
[ "is_fibonacci", "is_perfect_square", "find_fibonacci_numbers" ]
3
[ [ "find_fibonacci_numbers", "is_fibonacci" ], [ "is_fibonacci", "is_perfect_square" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7afd9953d7bd45026693b8ec82a354f3ccef02e2
99d8c08d557730bf19a757e5294936c5f5411a1c
v1.0
instruct
Filter
Filter_32359_I
Create a Python script that converts temperature from Fahrenheit to Celsius and vice versa. The script should continuously prompt the user to enter a temperature to convert until the user chooses to exit the program. The user should be able to choose whether to convert from Fahrenheit to Celsius or vice versa.
def fahrenheit_to_celsius(fahrenheit): """ Convert temperature from Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0/9.0 def celsius_to_fahrenheit(celsius): """ Convert temperature from Celsius to Fahrenheit. """ return (celsius * 9.0/5.0) + 32 def convert_temperature(temp, sc...
from solution import fahrenheit_to_celsius, celsius_to_fahrenheit, convert_temperature def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(100) == 37.77777777777778 def test_celsius_to_fahrenheit(): assert celsiu...
[ { "docstring": "Convert temperature from Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Convert temperature from Celsius to Fahrenheit.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(f):\n \"\"\"\n Converts Fahrenheit to Celsius.\n :param f: temperature in Fahrenheit\n :return: temperature in Celsius\n \"\"\"\n return (f - 32) * ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032359", "row_id": 32359, "seed_ids": "['Qwen2-72B-Instruct_74304']" }
0.400189
Filter_32359
I
[ "fahrenheit_to_celsius", "celsius_to_fahrenheit", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d3a643a2866c2ea532ef9cd32b109492cefd0b86
477d255270bd11b4616b6a24098858f1901ec896
v1.0
instruct
Filter
Filter_32370_I
Suppose we have a data structure that represents a binary search tree, serve as a template for creating a height-balanced tree and write a method to populate it with the data that results in such a tree.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def sorted_array_to_bst(nums): """ Converts a sorted array to a height-balanced binary search tree. """ if not nums: return None mid = len(...
from solution import TreeNode, create_height_balanced_bst, inorder_traversal def test_create_height_balanced_bst_empty(): result = create_height_balanced_bst([]) assert result is None def test_create_height_balanced_bst_single_element(): result = create_height_balanced_bst([1]) assert result.value == ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n \"\"\"Node of a binary tree\"\"\"\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = righ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032370", "row_id": 32370, "seed_ids": "['Qwen2-72B-Instruct_74320']" }
0.530869
Filter_32370
I
[ "sorted_array_to_bst", "create_height_balanced_bst", "inorder_traversal" ]
3
[ [ "create_height_balanced_bst", "sorted_array_to_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
307ba6f14456f7c1581b3336816e54949bd111bb
8c222ff652c7cb08d935cfa107d504f73c3b3971
v1.0
instruct
Filter
Filter_32372_I
Develop a function "is_prime" that takes a number as an argument and returns whether the number is a prime number or not. Also, write a copious amount of test cases to verify your function. As an additional requirement, implement a separate function "prime_sequence" that generates a list of prime numbers up to a given ...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def prime_seque...
from solution import is_prime, prime_sequence def test_is_prime(): # Basic test cases assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False # Larger prime numbers assert is_prime(11) == True assert is_prime(101) == True # Larger non-prime numbers assert...
[ { "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": "Generates a list of prime numbers up to a given limit using the is_prime function.", "function_declaratio...
[ 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 == 2 or n == 3:\n return True\n if...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032372", "row_id": 32372, "seed_ids": "['Qwen2-72B-Instruct_74323']" }
0.706766
Filter_32372
I
[ "is_prime", "prime_sequence" ]
2
[ [ "prime_sequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4c44936f642a5a6a9ef07a129185e9804828747
1b113daaf40ab5cd854a9a5c3c35c38fd5e58b9c
v1.0
instruct
Filter
Filter_32375_I
How can I create a Python script that generates a Fibonacci sequence using a recursive function, but with a twist? The function should print the sequence starting from the nth term, where n is a given number. If the n-th term is 5, for instance, the program should print the sequence starting from the 5th term: 5, 8, 13...
def fibonacci(n): """ Returns the nth Fibonacci number. """ if n <= 0: return "Invalid position" elif n == 1: return 1 elif n == 2: return 1 else: return fibonacci(n - 1) + fibonacci(n - 2) def generate_fibonacci_sequence_from_nth(n, terms=10): """ Ge...
from solution import fibonacci, generate_fibonacci_sequence_from_nth def test_fibonacci(): assert fibonacci(-1) == "Invalid position" assert fibonacci(0) == "Invalid position" assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacc...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Generates a Fibonacci sequence starting from the nth term and prints the first 'terms' number of terms.", "function_de...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_twist(n, length=10):\n \"\"\"\n Generates and prints a Fibonacci sequence starting from the nth term, where n is a given number.\n If n is smaller than 1, prints \"Inval...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032375", "row_id": 32375, "seed_ids": "['Qwen2-72B-Instruct_74330']" }
0.654699
Filter_32375
I
[ "fibonacci", "generate_fibonacci_sequence_from_nth" ]
2
[ [ "generate_fibonacci_sequence_from_nth", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8be2e5d2f1702e3f0666469f25e33a90b97a37c
2d791844c8b7e41bd537ddfb82d1a99e9f3e64f6
v1.0
instruct
Filter
Filter_32378_I
Create a regex pattern for extracting emails from a text. Also, write a program to demonstrate using this regex pattern in Python. The program should print the domain names from the extracted emails separately.
import re def extract_emails(text): """ Extracts emails from a given text using a regex pattern. """ email_pattern = re.compile(r'\b[\w.-]+@[\w.-]+\.\w+\b') return email_pattern.findall(text) def extract_and_print_domains(text): """ Extracts emails from the text and prints their domain nam...
from solution import extract_emails, extract_and_print_domains def test_extract_emails(): text = "Please contact us at support@example.com for support or at sales@mydomain.org for sales inquiries." expected_emails = ['support@example.com', 'sales@mydomain.org'] assert extract_emails(text) == expected_email...
[ { "docstring": "Extracts emails from a given text using a regex pattern.", "function_declaration": "def extract_emails(text):", "function_name": "extract_emails", "parameter_list": "(text)" }, { "docstring": "Extracts emails from the text and prints their domain names.", "function_declar...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef extract_emails(text):\n \"\"\"\n Extract emails from the given text using regex and return a list of emails.\n \"\"\"\n email_pattern = r'[a-zA-Z0-9_.+-]+@[a-zA-Z0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032378", "row_id": 32378, "seed_ids": "['Qwen2-72B-Instruct_74333']" }
0.59445
Filter_32378
I
[ "extract_emails", "extract_and_print_domains" ]
2
[ [ "extract_and_print_domains", "extract_emails" ] ]
1
[]
false
[]
false
pytest
true
[]
true
09f971bc13719f891546d9bc8f4e6b5d95d90be2
7748741009891ce25b5ffaf7acff7097458e92c8
v1.0
instruct
Filter
Filter_32382_I
Create a program implementing a more complex control logic, using an if-else statement, to determine if a given numeric variable signifies a prime number. Besides identifying primes, the program should output the nearest prime number for any given number. If the provided number is a prime, it should return the number i...
def is_prime(num): """ Determines if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, nearest_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(15) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == Fal...
[ { "docstring": "Determines if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the nearest prime number.\nIf n is already a prime number, it returns n.\nIf n is not a prime number, it return...
[ 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 :param n: integer\n :return: boolean, True if n is prime else False\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032382", "row_id": 32382, "seed_ids": "['Qwen2-72B-Instruct_74338']" }
0.617442
Filter_32382
I
[ "is_prime", "nearest_prime" ]
2
[ [ "nearest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37b505a5128d001d8388a6442015b237b18d6dda
25c8bb5fdb9389663b70d66cfa676cd01463ccca
v1.0
instruct
Filter
Filter_32431_I
Write a Python function using list comprehension to generate a list of all prime numbers less than a given number N. Additionally, ensure your function checks for the correctness of the input, i.e., the input should be a positive integer. Create test cases for validating the correctness of your function.
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 += 6 re...
from solution import primes_less_than def test_primes_less_than_zero(): try: primes_less_than(0) except ValueError as e: assert str(e) == "Input must be a positive integer." def test_primes_less_than_negative(): try: primes_less_than(-10) except ValueError as e: assert ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers less than a given number N.\n\nParameters:\nN (int): The upper limit (exclu...
[ 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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032431", "row_id": 32431, "seed_ids": "['Qwen2-72B-Instruct_74419']" }
0.711097
Filter_32431
I
[ "is_prime", "primes_less_than" ]
2
[ [ "primes_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
920d7a8d44c679b5c28cc86e5d4d68c5b18cc022
aca912a51345c34d47d5b6130f07dc4315c53467
v1.0
instruct
Filter
Filter_32437_I
Write a python program using list comprehension that takes in a list of numbers and returns a list of only the prime numbers.
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 filter_prime_numbers(numbers): """ Returns a list of prime numbers from the input list using list comp...
from solution import filter_prime_numbers def test_filter_prime_numbers_with_primes(): assert filter_prime_numbers([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_prime_numbers_with_mixed(): assert filter_prime_numbers([1, 2, 4, 5, 6, 8, 11, 17]) == [2, 5, 11, 17] def test_filter_prime_numbers_with_no_...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the input list using list comprehension.", "function_declaration": "def filter_prime_numb...
[ 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, else 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": "00032437", "row_id": 32437, "seed_ids": "['Qwen2-72B-Instruct_74427']" }
0.660216
Filter_32437
I
[ "is_prime", "filter_prime_numbers" ]
2
[ [ "filter_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd1afe0eedb60cd1a65a9e12ba423dc1cadcda9f
31d3ca058009d96401e305da048413249ada40b7
v1.0
instruct
Filter
Filter_32439_I
Write a Python code snippet to generate an iterator for an infinite sequence of powers of 3 (3^0, 3^1, 3^2, 3^3,...). Additionally, implement a function that uses this iterator to calculate the sum of the first N terms of this sequence, where N is a user-provided input. Remember to consider edge cases like N being a ne...
import itertools def infinite_powers_of_3(): """ Generator function that yields an infinite sequence of powers of 3. """ i = 0 while True: yield 3 ** i i += 1 def sum_of_powers_of_3(n): """ Returns the sum of the first N terms of the sequence of powers of 3. Parame...
from solution import infinite_powers_of_3, sum_of_powers_of_3 def test_infinite_powers_of_3(): gen = infinite_powers_of_3() assert next(gen) == 1 # 3^0 assert next(gen) == 3 # 3^1 assert next(gen) == 9 # 3^2 assert next(gen) == 27 # 3^3 def test_sum_of_powers_of_3(): assert sum_of_powers_of...
[ { "docstring": "Generator function that yields an infinite sequence of powers of 3.", "function_declaration": "def infinite_powers_of_3():", "function_name": "infinite_powers_of_3", "parameter_list": "()" }, { "docstring": "Returns the sum of the first N terms of the sequence of powers of 3....
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def infinite_powers_of_3():\n \"\"\"\n An iterator that generates an infinite sequence of powers of 3 (3^0, 3^1, 3^2, 3^3,...)\n \"\"\"\n n = 0\n while True:\n yield 3 **...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032439", "row_id": 32439, "seed_ids": "['Qwen2-72B-Instruct_74430']" }
0.588604
Filter_32439
I
[ "infinite_powers_of_3", "sum_of_powers_of_3" ]
2
[ [ "sum_of_powers_of_3", "infinite_powers_of_3" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc50b685d14cf33dbf172d2e4806cfa4296b0eba
6d32b31a4e9a47de0bd8443c293b8d57f868e63c
v1.0
instruct
Filter
Filter_32462_I
Implement the quicksort algorithm in Python, but additionally, create a functionality where the user can choose the pivot strategy (first element, last element, or a random element). The default strategy should be selecting the first element as a pivot. Then, sort the list [8, 2, 7, 1, 5, 9, 6, 4, 3, 0]. Along with thi...
import random import time def quicksort(arr, pivot_strategy='first'): if len(arr) <= 1: return arr if pivot_strategy == 'first': pivot = arr[0] less = [x for x in arr[1:] if x <= pivot] greater = [x for x in arr[1:] if x > pivot] elif pivot_strategy == 'last': pivot...
from solution import quicksort, evaluate_pivot_strategy def test_quicksort_first_pivot(): arr = [8, 2, 7, 1, 5, 9, 6, 4, 3, 0] sorted_arr = quicksort(arr, 'first') assert sorted_arr == sorted(arr) def test_quicksort_last_pivot(): arr = [8, 2, 7, 1, 5, 9, 6, 4, 3, 0] sorted_arr = quicksort(arr, 'la...
[ { "docstring": null, "function_declaration": "def quicksort(arr, pivot_strategy='first'):", "function_name": "quicksort", "parameter_list": "(arr, pivot_strategy='first')" }, { "docstring": null, "function_declaration": "def evaluate_pivot_strategy(arr):", "function_name": "evaluate_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef quicksort(arr, pivot_strategy='first'):\n \"\"\"\n Quicksort algorithm with customizable pivot strategy.\n \n Parameters:\n arr (list): The list to be sorte...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00032462", "row_id": 32462, "seed_ids": "['Qwen2-72B-Instruct_74466']" }
0.569258
Filter_32462
I
[ "quicksort", "evaluate_pivot_strategy" ]
2
[ [ "evaluate_pivot_strategy", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3bf7220713e96f07aa7d8ab4cf366fdba44425be
f673f687ef1666afcfaff77f07ab3e876f629d12
v1.0
instruct
Filter
Filter_32483_I
Rewrite the following Bash code into Python to check if a given number is prime, and also print all the prime numbers within a given range.
def is_prime(num): """ Check if a given number is prime. :param num: Integer, the number to check. :return: Boolean, True if the number is prime, False otherwise. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False ...
from solution import is_prime, primes_in_range def test_is_prime_true(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(13) == True assert is_prime(89) == True def test_is_prime_false(): assert is_prime(0) == False assert is_prime(1) == Fal...
[ { "docstring": "Check if a given number is prime.\n:param num: Integer, the number to check.\n:return: Boolean, True if the number is prime, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Print all pr...
[ 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 :param n: int\n :return: boolean\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032483", "row_id": 32483, "seed_ids": "['Qwen2-72B-Instruct_74505']" }
0.680987
Filter_32483
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ecc24910cb5194a297aa7c3cd08b638d2eea0f2
6f9ae74e7df4d954f1cc60a1bd3710b3317f9e72
v1.0
instruct
Filter
Filter_32502_I
Create a function to select the kth smallest item from a list, where k can be any number between 1 and the length of the list. The function should have a time complexity of O(n) and a space complexity of O(1).
def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i+1], arr[high] = arr[high], arr[i+1] return i+1 def quickselect(arr, low, high, k): if low <= high: p...
from solution import select_kth_smallest def test_select_kth_smallest_normal(): assert select_kth_smallest([3, 1, 2, 5, 4], 1) == 1 assert select_kth_smallest([3, 1, 2, 5, 4], 2) == 2 assert select_kth_smallest([3, 1, 2, 5, 4], 3) == 3 assert select_kth_smallest([3, 1, 2, 5, 4], 4) == 4 assert sele...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n for j in range(low, high):\n if arr[j] <= pivot:\n i += 1\n arr[i], arr[j] = arr[j], ar...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032502", "row_id": 32502, "seed_ids": "['Qwen2-72B-Instruct_74534']" }
0.588768
Filter_32502
I
[ "partition", "quickselect", "select_kth_smallest" ]
3
[ [ "quickselect", "partition" ], [ "select_kth_smallest", "quickselect" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c78ccabb72f73debb502b05cdc2817ae02c9193a
e97f7e8b0a12fd86b184c5a89a2463befd51c17e
v1.0
instruct
Filter
Filter_32503_I
Write me a Python function that will process a list of strings. Each string can be a simple arithmetic expression using only integers, addition (+), subtraction (-), multiplication (*), and division (/). The function should evaluate these expressions and return a list of results. However, there's a catch: Python's buil...
def evaluate_expression(expr): def helper(expr_list): stack = [] num = 0 op = '+' while len(expr_list) > 0: char = expr_list.pop(0) if char.isdigit(): num = num * 10 + int(char) if char == '(': num = helper(expr_list...
from solution import process_expressions def test_simple_addition(): assert process_expressions(["2+3"]) == [5] def test_simple_subtraction(): assert process_expressions(["10-2"]) == [8] def test_multiplication(): assert process_expressions(["4*3"]) == [12] def test_division(): assert process_expres...
[ { "docstring": null, "function_declaration": "def evaluate_expression(expr):", "function_name": "evaluate_expression", "parameter_list": "(expr)" }, { "docstring": null, "function_declaration": "def process_expressions(expressions):", "function_name": "process_expressions", "para...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def evaluate_expression(expr):\n def helper(expr_list):\n stack = []\n num = 0\n op = '+'\n while len(expr_list) > 0:\n char = expr_list.pop(0)\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00032503", "row_id": 32503, "seed_ids": "['Qwen2-72B-Instruct_74536']" }
0.683854
Filter_32503
I
[ "evaluate_expression", "process_expressions" ]
2
[ [ "process_expressions", "evaluate_expression" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff8bde6f79ea4dbfb57969fa534f8c2a24c9b8f1
680df56aeb65f15551feef1ccf5c222834ffbf6c
v1.0
instruct
Filter
Filter_32517_I
Create a Python for loop that prints the square of numbers from 1 to 10, but only for numbers that are not divisible by both 3 and 5. Additionally, the program should only print the square and asterisk if the square is a prime number.
import math 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 ...
from solution import is_prime, print_squares def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(5) is True assert is_prime(10) is False assert is_prime(11) is True assert is_prime(25) is False def test_print_squares(capsys...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Print the square of numbers from 1 to 10, but only for numbers not divisible\nby both 3 and 5, and only if the square is a prime n...
[ 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 < 2:\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_square_and_asteri...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032517", "row_id": 32517, "seed_ids": "['Qwen2-72B-Instruct_74558']" }
0.598618
Filter_32517
I
[ "is_prime", "print_squares" ]
2
[ [ "print_squares", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
873e8b56bc9d6c51b71563df4e369013f33a6543
b42fc8855d9e02a0950d81b03da676cf9b4b50ec