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_25376_I
Use a for loop to print all prime numbers from 1 to 100 in separate lines, and calculate and print the sum of all the prime numbers. Additionally, generate and print the list of all prime numbers in a dictionary where each key-value pair comprises the number and its corresponding square.
def is_prime(n): """ Returns True if the number n is prime, otherwise False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def prim...
from solution import is_prime, prime_numbers_up_to_100 def test_is_prime(): 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(13) == True assert is_prime(17) == True assert is_prime(1...
[ { "docstring": "Returns True if the number n is prime, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints all prime numbers from 1 to 100 in separate lines, \nand prints the sum of all prime numbers.\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 if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef prime_number...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025376", "row_id": 25376, "seed_ids": "['Qwen2-72B-Instruct_62822']" }
0.575155
Filter_25376
I
[ "is_prime", "prime_numbers_up_to_100" ]
2
[ [ "prime_numbers_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c7f381f0a54b1a1ae71dade87b00eb05f7021e9f
2150b632503d09dc37fbe7a39315ce654a9e0a3c
v1.0
instruct
Filter
Filter_25379_I
Develop an efficient algorithm for sorting a given list of integers in ascending order. Your algorithm should have a time complexity of O(nlogn) and should not use any built-in sorting functions or libraries. Additionally, the algorithm should be implemented in a way that it can handle duplicate integers in the list an...
def merge_sort(my_list): """ Sorts a list of integers in ascending order using the merge sort algorithm. Time Complexity: O(nlogn) """ if len(my_list) <= 1: return my_list mid = len(my_list) // 2 left_half = merge_sort(my_list[:mid]) right_half = merge_sort(my_list[mid:]) r...
from solution import merge_sort def test_sort_single_element(): assert merge_sort([1]) == [1] def test_sort_multiple_elements(): assert merge_sort([3, 1, 2]) == [1, 2, 3] def test_sort_with_duplicates(): assert merge_sort([3, 1, 2, 1, 2, 3]) == [1, 1, 2, 2, 3, 3] def test_sort_large_range_of_integers():...
[ { "docstring": "Sorts a list of integers in ascending order using the merge sort algorithm.\nTime Complexity: O(nlogn)", "function_declaration": "def merge_sort(my_list):", "function_name": "merge_sort", "parameter_list": "(my_list)" }, { "docstring": "Merges two sorted lists into one sorted...
[ 1, 0, 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 \"\"\"\n Sorts a list of integers in ascending order using merge sort.\n Time complexity: O(nlogn)\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025379", "row_id": 25379, "seed_ids": "['Qwen2-72B-Instruct_62827']" }
0.577382
Filter_25379
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e107717c9ac188e31da88c5f23bc127cea8f4a15
9e40e60d9fc3deb52f3f2b014f10627a0c9c8c80
v1.0
instruct
Filter
Filter_25384_I
Create a text-based game in Python that includes a character creation system, multiple branching storylines, a complex leveling and skill system, and dynamic difficulty scaling based on player actions and choices.
class Character: def __init__(self, name, char_class): self.name = name self.char_class = char_class self.level = 1 self.exp = 0 self.skills = {'strength': 1, 'agility': 1, 'intelligence': 1} self.hp = 100 def gain_experience(self, amount): self.exp += am...
from solution import Character, fight_dragon def test_character_creation(): char = Character("Test", "Warrior") assert char.name == "Test" assert char.char_class == "Warrior" assert char.level == 1 assert char.skills == {'strength': 1, 'agility': 1, 'intelligence': 1} assert char.hp == 100 def...
[]
[ 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": "class Character:\n def __init__(self, name, char_class):\n self.name = name\n self.char_class = char_class\n self.level = 1\n self.exp =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025384", "row_id": 25384, "seed_ids": "['Qwen2-72B-Instruct_62834']" }
0.414658
Filter_25384
I
[ "character_creation", "branching_storyline", "fight_dragon", "play_game" ]
4
[ [ "branching_storyline", "fight_dragon" ], [ "play_game", "branching_storyline" ], [ "play_game", "character_creation" ] ]
3
[]
false
[ "Character" ]
true
pytest
true
[]
true
7974036dfa6d8e883ca953ad00398a73d56913c1
ab4fb0972e25b45a2fb0e29353481e18103c038d
v1.0
instruct
Filter
Filter_25402_I
我想知道 given an unsorted list of integers, how do you find the kth largest number using the quickselect algorithm in Python, and explain why the time complexity is better than that of sorting the array first?
def partition(arr, left, right, pivot_index): pivot_value = arr[pivot_index] # Move the pivot to the end arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left for i in range(left, right): if arr[i] < pivot_value: arr[store_index], arr[i] = arr[i], ar...
from solution import find_kth_largest def test_kth_largest_basic(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 def test_kth_largest_single_element(): assert find_kth_largest([1], 1) == 1 def test_kth_largest_already_sorted(): assert find_kth_largest([1, 2, 3, 4, 5, 6], 1) == 6 assert find_kt...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(arr, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(arr, left, right, k_smallest):", "function_...
[ 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": "import random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] > pivot:\n arr[i], ar...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025402", "row_id": 25402, "seed_ids": "['Qwen2-72B-Instruct_62872']" }
0.562857
Filter_25402
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
090cdbfcafb80c785e7bdb89b9708a17cad2e123
22beb1a88f4915f598ff61b832647793f89617ff
v1.0
instruct
Filter
Filter_25404_I
Engineer a software module to execute the calculation of the n-th node's value in the mathematic structure of a Fibonacci sequence, by deeply utilising the conceptually precise principles of matrix exponentiation. Here is a python program that uses the concept of matrix exponentiation to calculate the n-th node's value...
def matrix_multiply(A, B): """ Multiplies two 2x2 matrices A and B and returns the result. """ return [ [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]] ] def matrix_exponen...
from solution import fibonacci def test_fibonacci_0(): assert fibonacci(0) == 0 def test_fibonacci_1(): assert fibonacci(1) == 1 def test_fibonacci_2(): assert fibonacci(2) == 1 def test_fibonacci_3(): assert fibonacci(3) == 2 def test_fibonacci_4(): assert fibonacci(4) == 3 def test_fibonacci...
[ { "docstring": "Multiplies two 2x2 matrices A and B and returns the result.", "function_declaration": "def matrix_multiply(A, B):", "function_name": "matrix_multiply", "parameter_list": "(A, B)" }, { "docstring": "Raises the matrix to the power of n using matrix exponentiation by squaring.",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0]*B[0][0] + A[0][1]*B[1][0], A[0][0]*B[0][1] + A[0][1]*B[1][1]],\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025404", "row_id": 25404, "seed_ids": "['Qwen2-72B-Instruct_62875']" }
0.618095
Filter_25404
I
[ "matrix_multiply", "matrix_exponentiation", "fibonacci" ]
3
[ [ "fibonacci", "matrix_exponentiation" ], [ "matrix_exponentiation", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c772098481c0b28826e6219c9e10f7417562d290
57fa8372abfd7ed4fcc0361c0c0a9833b879184d
v1.0
instruct
Filter
Filter_25409_I
Build an algorithm to find all prime numbers within a given range and print them in ascending order. Additionally, implement a function that checks if a given number is a prime number and use it within your algorithm. The algorithm should also be able to handle large range inputs efficiently.
import math def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, find_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(25) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) ...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all prime numbers in the given range [start, end] and returns them in a list.", "function_declaration": "def find_pri...
[ 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 == 2 or n == 3:\n return True\n if n % ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025409", "row_id": 25409, "seed_ids": "['Qwen2-72B-Instruct_62882']" }
0.613619
Filter_25409
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8358f7cc448184936f70eb7cc7ee3585ff47cf18
29e2597eb93219f84578fcaedac90f5cc3eecc29
v1.0
instruct
Filter
Filter_25425_I
Populate a 10x10 matrix with random numbers between 0 and 9. Then, write a function to print the matrix. Additionally, write a function to find and print the sum of the elements in each row and each column of the matrix. Finally, sort the rows of the matrix in descending order based on the sum of their elements and pri...
import random def generate_matrix(rows=10, cols=10, lower=0, upper=9): matrix = [[random.randint(lower, upper) for _ in range(cols)] for _ in range(rows)] return matrix def print_matrix(matrix): for row in matrix: print(row) def sum_rows(matrix): return [sum(row) for row in matrix] def sum_c...
import pytest from solution import generate_matrix, sum_rows, sum_columns, sort_matrix_by_row_sum def test_generate_matrix(): matrix = generate_matrix() assert len(matrix) == 10 assert all(len(row) == 10 for row in matrix) assert all(0 <= elem <= 9 for row in matrix for elem in row) def test_sum_rows(...
[ { "docstring": null, "function_declaration": "def generate_matrix(rows=10, cols=10, lower=0, upper=9):", "function_name": "generate_matrix", "parameter_list": "(rows=10, cols=10, lower=0, upper=9)" }, { "docstring": null, "function_declaration": "def print_matrix(matrix):", "function...
[ 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_matrix(rows=10, cols=10, lower=0, upper=9):\n matrix = [[random.randint(lower, upper) for _ in range(cols)] for _ in range(rows)]\n return matrix\n\ndef pri...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025425", "row_id": 25425, "seed_ids": "['Qwen2-72B-Instruct_62909']" }
0.584612
Filter_25425
I
[ "generate_matrix", "print_matrix", "sum_rows", "sum_columns", "sort_matrix_by_row_sum" ]
5
[ [ "sort_matrix_by_row_sum", "sum_rows" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa0e09d24acbda0a5c8c38d5e16a9751f2223a01
6bcb98e7b8dab818b952400c59ba03323c861d3e
v1.0
instruct
Filter
Filter_25434_I
Using the provided "Human" class, implement a solution that dynamically creates an array of Human objects. Your solution should take an integer parameter that determines the size of the array, create that many Human objects, and fill an array with them. Moreover, each human object should be populated with unique values...
import string import random class Human: """ A simple Human class with name and age attributes. """ def __init__(self, name, age): self.name = name self.age = age def generate_unique_name(existing_names): """ Generate a unique name that is not present in the existing_names list...
from solution import Human, create_human_array def test_create_human_array_basic(): humans = create_human_array(5) assert len(humans) == 5 assert all(isinstance(human, Human) for human in humans) names = [human.name for human in humans] ages = [human.age for human in humans] assert len(set(name...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\nclass Human:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n\ndef generate_humans(size):\n \"\"\"\n Generates an array of unique ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025434", "row_id": 25434, "seed_ids": "['Qwen2-72B-Instruct_62932']" }
0.36844
Filter_25434
I
[ "generate_unique_name", "create_human_array" ]
2
[ [ "create_human_array", "generate_unique_name" ] ]
1
[]
false
[ "Human" ]
true
pytest
true
[]
true
0079e5a5aebc3c59792cd4ff1d31906fd645961e
b62eaeb6c235677e90f8770004a0daafe8ef6139
v1.0
instruct
Filter
Filter_25443_I
Create an XML response from the following Python object. Additionally, include a method to convert the XML response back to the Python object. Ensure that the conversion from XML to Python object is robust and can handle various types of data.
import xml.etree.ElementTree as ET def dict_to_xml(tag, d): """ Turn a simple dict of key/value pairs into XML """ elem = ET.Element(tag) for key, val in d.items(): child = ET.SubElement(elem, key) child.text = str(val) return elem def xml_to_dict(elem): """ Turn an XML...
import xml.etree.ElementTree as ET from solution import dict_to_xml, xml_to_dict, python_obj_to_xml_and_back def test_dict_to_xml(): py_obj = {'name': 'John', 'age': '30'} # Age is a string as XML text is always string expected_xml_str = '<root><name>John</name><age>30</age></root>' xml_elem = dict_to_xm...
[ { "docstring": "Turn a simple dict of key/value pairs into XML", "function_declaration": "def dict_to_xml(tag, d):", "function_name": "dict_to_xml", "parameter_list": "(tag, d)" }, { "docstring": "Turn an XML element back into a dict", "function_declaration": "def xml_to_dict(elem):", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import xml.etree.ElementTree as ET\n\ndef dict_to_xml(tag, d):\n \"\"\"\n Turn a simple dict of key/value pairs into XML\n \"\"\"\n elem = ET.Element(tag)\n for key, val in d.it...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025443", "row_id": 25443, "seed_ids": "['Qwen2-72B-Instruct_62945']" }
0.577409
Filter_25443
I
[ "dict_to_xml", "xml_to_dict", "python_obj_to_xml_and_back" ]
3
[ [ "python_obj_to_xml_and_back", "dict_to_xml" ], [ "python_obj_to_xml_and_back", "xml_to_dict" ] ]
2
[]
false
[]
false
pytest
true
[]
true
551db916e7407ef1cecd394328bd52713ac0e109
e69af7083e3ccd6f56d0ceddc0569cff7f7c90ec
v1.0
instruct
Filter
Filter_25447_I
Use the while loop and error handling in Python to print all prime numbers between a given range. The program should also account for potential errors if the inputs are not integer values or if the start of the range is greater than the end.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False ...
from solution import print_primes_in_range def test_primes_in_valid_range(): assert print_primes_in_range(10, 20) == [11, 13, 17, 19] assert print_primes_in_range(1, 10) == [2, 3, 5, 7] def test_invalid_range(): assert print_primes_in_range(20, 10) == "Start of the range must be less than or equal to the ...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints all prime numbers in the range [start, end].", "function_declaration": "def print_primes_in_range(st...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def print_prime_numbers(start, end):\n \"\"\"\n Prints all prime numbers between a given range [start, end].\n Handles the error if start is greater than end or if inputs are not inte...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025447", "row_id": 25447, "seed_ids": "['Qwen2-72B-Instruct_62949']" }
0.621754
Filter_25447
I
[ "is_prime", "print_primes_in_range" ]
2
[ [ "print_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
605acc8359973b8fe18bda93333f07bc642ade82
47dce962b41c20b524f6c092112584adc3ada7c8
v1.0
instruct
Filter
Filter_25459_I
Write a python code to check for a number being prime or not. The number should be provided by the user as input. The program should also display all the prime numbers between 2 and the user-provided number.
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, primes_up_to, primes_information def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_pr...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 2 up to n.", "function_declaration": "def primes_up_to(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(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": "00025459", "row_id": 25459, "seed_ids": "['Qwen2-72B-Instruct_62966']" }
0.781596
Filter_25459
I
[ "is_prime", "primes_up_to", "primes_information" ]
3
[ [ "primes_information", "is_prime" ], [ "primes_information", "primes_up_to" ], [ "primes_up_to", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a820975f6e5feee234bc30330849fd64a6dea6bc
79fb75d7faab3e48476bd6df07516a9954589c60
v1.0
instruct
Filter
Filter_25499_I
Generate a 10-digit pseudo-random number using the built-in random function in Python, ensuring that the number is prime. Additionally, provide a piece of erroneous code that attempts to generate a prime number but contains a logical error.
import random def is_prime(n): """Check if a number n is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def generate_prime_number...
from solution import is_prime, generate_prime_number, incorrect_generate_prime_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(18) == False def test_generate_prime_number_length(): prime_n...
[ { "docstring": "Check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a 10-digit prime number.", "function_declaration": "def generate_prime_number():", "function_name": "generate_p...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime\n\ndef generate_prime_10_digit_number():\n while True:\n num = random.randint(10**9, 10**10-1)\n if isprime(num):\n return ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025499", "row_id": 25499, "seed_ids": "['Qwen2-72B-Instruct_63032']" }
0.516839
Filter_25499
I
[ "is_prime", "generate_prime_number", "incorrect_generate_prime_number" ]
3
[ [ "generate_prime_number", "is_prime" ], [ "incorrect_generate_prime_number", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a816813bec2ba57ee70859a283a63c0c656e786e
be5d3bb705fe6f576c199d71f4a2260b7a486c24
v1.0
instruct
Filter
Filter_25523_I
Write a Python script to extract the year, month, and day from a given date in the format "dd-mm-yyyy". Additionally, calculate and print the number of days remaining in the current year.
from datetime import datetime def extract_date_info(date_str): """ Extracts the year, month, and day from the given date string in the format "dd-mm-yyyy". Args: date_str (str): The date string in "dd-mm-yyyy" format. Returns: tuple: A tuple containing (year, month, day) as integers. ...
from solution import extract_date_info, days_remaining_in_year def test_extract_date_info(): assert extract_date_info("01-01-2023") == (2023, 1, 1) assert extract_date_info("28-02-2022") == (2022, 2, 28) assert extract_date_info("31-12-2020") == (2020, 12, 31) def test_days_remaining_in_year(): assert...
[ { "docstring": "Extracts the year, month, and day from the given date string in the format \"dd-mm-yyyy\".\n\nArgs:\ndate_str (str): The date string in \"dd-mm-yyyy\" format.\n\nReturns:\ntuple: A tuple containing (year, month, day) as integers.", "function_declaration": "def extract_date_info(date_str):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import datetime\n\ndef extract_date_info(date_str):\n \"\"\"\n Extracts year, month, and day from a date string in the format \"dd-mm-yyyy\".\n \"\"\"\n try:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025523", "row_id": 25523, "seed_ids": "['Qwen2-72B-Instruct_63071']" }
0.612847
Filter_25523
I
[ "extract_date_info", "days_remaining_in_year" ]
2
[ [ "days_remaining_in_year", "extract_date_info" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4bf4d8238531b4cc11e162adf2f4008b5cd3774d
683eed58783d38f5c5167c113eebd43bc5859959
v1.0
instruct
Filter
Filter_25525_I
Write a script in Python for drawing a hollow irregular hexagon on the screen with user-defined sides. The user will input six points, and the program will connect them, only if it forms an irregular hexagon. If a hexagon cannot be formed, the program should notify the user.
import matplotlib.pyplot as plt def is_irregular_hexagon(points): """ Checks if 6 points can form an irregular hexagon. """ return len(points) == 6 def draw_irregular_hexagon(points): """ Draws an irregular hexagon on the screen with the provided points. `points` should be a list of 6 tupl...
from solution import is_irregular_hexagon, draw_irregular_hexagon def test_is_irregular_hexagon_valid(): points = [(1, 2), (2, 3), (3, 2), (4, 3), (5, 2), (3, 1)] assert is_irregular_hexagon(points) == True def test_is_irregular_hexagon_invalid(): points = [(1, 2), (2, 3), (3, 2), (4, 3), (5, 2)] asse...
[ { "docstring": "Checks if 6 points can form an irregular hexagon.", "function_declaration": "def is_irregular_hexagon(points):", "function_name": "is_irregular_hexagon", "parameter_list": "(points)" }, { "docstring": "Draws an irregular hexagon on the screen with the provided points.\n`point...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import turtle\n\ndef draw_hollow_irregular_hexagon(points):\n \"\"\"\n Draws a hollow irregular hexagon with turtle graphics.\n \n Parameters:\n points (list of tuple): A list o...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025525", "row_id": 25525, "seed_ids": "['Qwen2-72B-Instruct_63073']" }
0.58184
Filter_25525
I
[ "is_irregular_hexagon", "draw_irregular_hexagon" ]
2
[ [ "draw_irregular_hexagon", "is_irregular_hexagon" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
641e584394d14be0c177f41efe9b60e44873672b
edcc16580baa1a03b75524fbb9a6ebf5b64f5126
v1.0
instruct
Filter
Filter_25540_I
Write a Python script to perform a traceroute from your local machine to a specified server and provide a visual representation of the route. Additionally, include the functionality to do a reverse lookup on each IP address to get the hostname and write the results to a file. You should also handle network errors and t...
import subprocess import socket def traceroute(destination): """ Performs a traceroute to the specified destination and returns the results. """ try: result = subprocess.run(['traceroute', destination], capture_output=True, text=True, timeout=300) if result.returncode != 0: ...
from unittest.mock import patch, MagicMock def test_traceroute(): with patch('subprocess.run') as mock_run: mock_result = MagicMock() mock_result.returncode = 0 mock_result.stdout = "1 192.168.0.1\n2 10.0.0.1\n3 8.8.8.8" mock_run.return_value = mock_result result = ...
[ { "docstring": "Performs a traceroute to the specified destination and returns the results.", "function_declaration": "def traceroute(destination):", "function_name": "traceroute", "parameter_list": "(destination)" }, { "docstring": "Performs a reverse DNS lookup for the specified IP address...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import subprocess\nimport socket\nimport json\n\ndef traceroute(destination):\n \"\"\"\n Performs a traceroute to the specified destination and returns the route information.\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025540", "row_id": 25540, "seed_ids": "['Qwen2-72B-Instruct_63094']" }
0.469326
Filter_25540
I
[ "traceroute", "reverse_lookup", "visualize_traceroute", "write_results_to_file", "perform_traceroute_and_visualize" ]
5
[ [ "perform_traceroute_and_visualize", "traceroute" ], [ "perform_traceroute_and_visualize", "visualize_traceroute" ], [ "perform_traceroute_and_visualize", "write_results_to_file" ], [ "visualize_traceroute", "reverse_lookup" ] ]
4
[]
false
[]
false
pytest
false
[]
true
ebe76746a5d31aa0612045916121635e70f15998
79ff469f5889f41288c432a9167b8dd7ce247367
v1.0
instruct
Filter
Filter_25542_I
Given a list of URLs, write a function that checks each URL for validity. If a URL is valid, fetch the HTML document using HTTP and then parse it to extract and print its title tag. If a URL is invalid, the function should handle the exception and print out a specific error message.
import requests from bs4 import BeautifulSoup from urllib.parse import urlparse def is_valid_url(url): """ Checks if a URL is valid. """ try: result = urlparse(url) return all([result.scheme, result.netloc]) except ValueError: return False def fetch_and_print_title(url): ...
import pytest from solution import is_valid_url, fetch_and_print_title, process_urls def test_is_valid_url(): assert is_valid_url("http://example.com") == True assert is_valid_url("https://example.com/path") == True assert is_valid_url("ftp://example.com") == True assert is_valid_url("invalid-url") == ...
[ { "docstring": "Checks if a URL is valid.", "function_declaration": "def is_valid_url(url):", "function_name": "is_valid_url", "parameter_list": "(url)" }, { "docstring": "Fetches the HTML document of the given URL and prints its title tag.", "function_declaration": "def fetch_and_print_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nfrom urllib.parse import urlparse\n\ndef is_valid_url(url):\n \"\"\"\n Checks if a URL is valid.\n \"\"\"\n try:\n result = u...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025542", "row_id": 25542, "seed_ids": "['Qwen2-72B-Instruct_63098']" }
0.735516
Filter_25542
I
[ "is_valid_url", "fetch_and_print_title", "process_urls" ]
3
[ [ "fetch_and_print_title", "is_valid_url" ], [ "process_urls", "fetch_and_print_title" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
65eac9ac4ed0b129f7fc0b6f43f578cbc150416e
0f7c9e2ccbcb312f6575e5a6abe28f37141ef499
v1.0
instruct
Filter
Filter_25560_I
I have a large list of URLs (~100,000) that I need to check if they are still active. What's the most efficient way to do this using Python?
import requests from concurrent.futures import ThreadPoolExecutor def is_url_active(url): """ Returns True if the given URL is active, otherwise False. """ try: response = requests.head(url, timeout=5) return response.status_code == 200 except requests.RequestException: retu...
from unittest.mock import patch from solution import is_url_active, check_urls def test_is_url_active_active_url(): with patch('requests.head') as mock_head: mock_head.return_value.status_code = 200 assert is_url_active('http://example.com') == True def test_is_url_active_inactive_url(): with...
[ { "docstring": "Returns True if the given URL is active, otherwise False.", "function_declaration": "def is_url_active(url):", "function_name": "is_url_active", "parameter_list": "(url)" }, { "docstring": "Checks a list of URLs to see if they are active using multithreading.\n\nArgs:\n ur...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom concurrent.futures import ThreadPoolExecutor\n\ndef is_url_active(url):\n \"\"\"\n Returns True if the given URL is active, otherwise False.\n \"\"\"\n try:\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025560", "row_id": 25560, "seed_ids": "['Qwen2-72B-Instruct_63134']" }
0.584643
Filter_25560
I
[ "is_url_active", "check_urls" ]
2
[ [ "check_urls", "is_url_active" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
9363019585c0f874b82103f9038fc08265af8c3f
ee0c93863c64b3248fbb6c1c993a17e72f1bb132
v1.0
instruct
Filter
Filter_25562_I
Write a script in Python that will find the average of a list of numbers. However, the list may contain both integers and strings. Your script should handle this situation by excluding any strings from the calculation and considering only the numbers in the list. The script should also handle cases where the list conta...
def flatten_and_filter_numbers(lst): """ Flattens a nested list and filters out non-numeric elements. Parameters: lst (list): The input list which may contain nested lists and both integers and strings. Returns: list: A flat list with only numeric values. """ result = [] fo...
from solution import flatten_and_filter_numbers, calculate_average def test_flatten_and_filter_numbers_simple_list(): assert flatten_and_filter_numbers([1, 2, 'a', 3, 'b']) == [1, 2, 3] def test_flatten_and_filter_numbers_nested_list(): assert flatten_and_filter_numbers([1, [2, 'a', [3, 'b']], 4, '5']) == [1,...
[ { "docstring": "Flattens a nested list and filters out non-numeric elements.\n\nParameters:\nlst (list): The input list which may contain nested lists and both integers and strings.\n\nReturns:\nlist: A flat list with only numeric values.", "function_declaration": "def flatten_and_filter_numbers(lst):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def flatten(lst):\n \"\"\"\n Flattens a nested list.\n \"\"\"\n for item in lst:\n if isinstance(item, list):\n yield from flatten(item)\n else:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025562", "row_id": 25562, "seed_ids": "['Qwen2-72B-Instruct_63139']" }
0.638198
Filter_25562
I
[ "flatten_and_filter_numbers", "calculate_average" ]
2
[ [ "calculate_average", "flatten_and_filter_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2dd020c258b50959171ec453024c5e6d5f2d8671
da1165575671a995928391419566ecd4f44ffc46
v1.0
instruct
Filter
Filter_25563_I
How can I implement the concept of "cause and effect" in Python? Can you provide an example of how to create a function that takes in two variables, where one is the cause and the other is the effect, and returns a statement explaining the relationship between them? Additionally, can you show how to write a script that...
import pandas as pd def cause_and_effect(cause, effect): """ Returns a statement explaining the relationship between cause and effect. """ return f"The effect of {cause} is {effect}." def generate_cause_and_effect_statements_from_excel(file_path): """ Reads pairs of cause and effect from an Ex...
from solution import cause_and_effect, generate_cause_and_effect_statements_from_excel import pandas as pd import pytest def test_cause_and_effect(): assert cause_and_effect("Rain", "Wet ground") == "The effect of Rain is Wet ground." assert cause_and_effect("Sun", "Drying") == "The effect of Sun is Drying." ...
[ { "docstring": "Returns a statement explaining the relationship between cause and effect.", "function_declaration": "def cause_and_effect(cause, effect):", "function_name": "cause_and_effect", "parameter_list": "(cause, effect)" }, { "docstring": "Reads pairs of cause and effect from an Exce...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def cause_and_effect(cause, effect):\n \"\"\"\n Returns a statement that shows the relationship between cause and effect.\n \"\"\"\n return f\"The cause is '{cause}' and the effect...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025563", "row_id": 25563, "seed_ids": "['Qwen2-72B-Instruct_63142']" }
0.425358
Filter_25563
I
[ "cause_and_effect", "generate_cause_and_effect_statements_from_excel" ]
2
[ [ "generate_cause_and_effect_statements_from_excel", "cause_and_effect" ] ]
1
[]
false
[]
false
pytest
true
[ "pandas" ]
false
2a1b4d65944432d851bffa309b11fa569f05cef0
53d194dc56391677584cc5fae091e02cd16f6b69
v1.0
instruct
Filter
Filter_25568_I
Design an algorithm to solve the Eight Queens puzzle and implement it in a programming language of your choice. The Eight Queens puzzle is a classic chess problem in which a chess board must be filled with eight queens, with no two queens attacking each other. That is, no two queens can share the same row, column, or d...
def solve_n_queens(n): def is_safe(board, row, col): # Check this row on left side for i in range(col): if board[row][i] == 1: return False # Check upper diagonal on left side for i, j in zip(range(row, -1, -1), range(col, -1, -1)): if board[i...
from solution import solve_n_queens, solve_eight_queens def test_solve_n_queens(): solutions_4 = solve_n_queens(4) assert len(solutions_4) == 2 solutions_5 = solve_n_queens(5) assert len(solutions_5) == 10 solutions_8 = solve_n_queens(8) assert len(solutions_8) == 92 def test_solve_eight_que...
[ { "docstring": null, "function_declaration": "def solve_n_queens(n):", "function_name": "solve_n_queens", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def solve_eight_queens():", "function_name": "solve_eight_queens", "parameter_list": "()" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_safe(board, row, col, n):\n # Check this row on left side\n for i in range(col):\n if board[row][i] == 1:\n return False\n\n # Check upper diagonal on left si...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025568", "row_id": 25568, "seed_ids": "['Qwen2-72B-Instruct_63147']" }
0.513891
Filter_25568
I
[ "solve_n_queens", "solve_eight_queens" ]
2
[ [ "solve_eight_queens", "solve_n_queens" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ed6aa52d9eb20ca872c9e296bb4872de11a8fa4
43854a92668ba7a7780a05a9700fc2e5af7510b3
v1.0
instruct
Filter
Filter_25573_I
Generate a list of 1000 strings containing random characters of length between 20 and 50, inclusive. Each string must contain at least one uppercase letter and one lowercase letter.
import random import string def generate_random_string(length): """ Generate a random string of given length that contains at least one uppercase and one lowercase letter. """ if length < 20 or length > 50: raise ValueError("Length must be between 20 and 50") characters = string.as...
from solution import generate_random_string, generate_list_of_strings def test_generate_random_string_length(): string = generate_random_string(25) assert len(string) == 25 def test_generate_random_string_contains_upper_and_lower(): string = generate_random_string(30) assert any(c.islower() for c in s...
[ { "docstring": "Generate a random string of given length that contains at least one uppercase and one lowercase letter.", "function_declaration": "def generate_random_string(length):", "function_name": "generate_random_string", "parameter_list": "(length)" }, { "docstring": "Generate a list ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ndef generate_random_string(length):\n \"\"\"\n Generates a random string of the specified length that contains at least one uppercase and one lowercase le...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025573", "row_id": 25573, "seed_ids": "['Qwen2-72B-Instruct_63155']" }
0.743223
Filter_25573
I
[ "generate_random_string", "generate_list_of_strings" ]
2
[ [ "generate_list_of_strings", "generate_random_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c90d101ab708fda6fd320e4316e6283876417e2b
ff43e7d7b825421f4afe84c76044004eefcc9423
v1.0
instruct
Filter
Filter_25594_I
In a Python programming environment, construct a function that executes the summation operation on two specific integers. Then, extend this function to recursively perform this operation on a list of integers, showcasing the versatility of the initial function in handling more complex tasks.
def add(a, b): """ Returns the sum of a and b. """ return a + b def recursive_sum(numbers): """ Recursively sums a list of integers. """ # Base case: if the list is empty, return 0 if not numbers: return 0 # Recursive case: add the first element to the sum of the rest of...
from solution import add, recursive_sum def test_add_positive_numbers(): assert add(2, 3) == 5 def test_add_with_zero(): assert add(0, 5) == 5 assert add(5, 0) == 5 def test_add_negative_numbers(): assert add(-1, -1) == -2 def test_add_mixed_sign_numbers(): assert add(-1, 3) == 2 def test_recur...
[ { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Recursively sums a list of integers.", "function_declaration": "def recursive_sum(numbers):", "function_name": "recursive_sum"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef recursive_sum(lst):\n \"\"\"\n Returns the sum of all integers in the list.\n \"\"\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025594", "row_id": 25594, "seed_ids": "['Qwen2-72B-Instruct_63183']" }
0.707306
Filter_25594
I
[ "add", "recursive_sum" ]
2
[ [ "recursive_sum", "add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
880bcc2b839b41cf67219306e44806c4f834296c
9f8761c8a7f0ff2113f95e62fab4ec281fccb25b
v1.0
instruct
Filter
Filter_25605_I
Design a function in Python that not only executes a search operation for a specific element within a list, but also checks if the list is sorted. If the list is not sorted, the function should sort the list before executing the binary search operation. Additionally, to increase complexity, the function should catch an...
def binary_search(sorted_list, target): """ Performs binary search on a sorted list. """ left, right = 0, len(sorted_list) - 1 while left <= right: mid = (left + right) // 2 if sorted_list[mid] == target: return mid elif sorted_list[mid] < target: left...
from solution import safe_search def test_safe_search_found(): assert safe_search([1, 3, 2, 4, 5], 3) == 2 def test_safe_search_not_found(): assert safe_search([1, 3, 2, 4, 5], 6) == -1 def test_safe_search_empty_list(): assert safe_search([], 1) == -1 def test_safe_search_already_sorted(): assert s...
[ { "docstring": "Performs binary search on a sorted list.", "function_declaration": "def binary_search(sorted_list, target):", "function_name": "binary_search", "parameter_list": "(sorted_list, target)" }, { "docstring": "Executes a search operation for a specific element within a list.\nChec...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(sorted_list, target):\n \"\"\"\n Performs binary search on a sorted list.\n \"\"\"\n left, right = 0, len(sorted_list) - 1\n while left <= right:\n mid ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025605", "row_id": 25605, "seed_ids": "['Qwen2-72B-Instruct_63200']" }
0.618118
Filter_25605
I
[ "binary_search", "safe_search" ]
2
[ [ "safe_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9634afc669ac48b08c237e5553aab7b2663d3712
d40256e9bb3a32029c04d36e7c580e5aee29a2ef
v1.0
instruct
Filter
Filter_25610_I
Write a python program to print the first 50 prime numbers with a difference of 10 between each line of output. Additionally, implement a function to check if a number is prime and use it in your program.
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def print_first_50_primes(...
from solution import is_prime, print_first_50_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(15) == False assert is_prime(0) == False assert is_prime(1) == False def test_print_first_...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints the first 50 prime numbers with a difference of 10 between each line.", "function_declaration": "def print_fi...
[ 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 for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025610", "row_id": 25610, "seed_ids": "['Qwen2-72B-Instruct_63208']" }
0.619652
Filter_25610
I
[ "is_prime", "print_first_50_primes" ]
2
[ [ "print_first_50_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ce4f7fa1569e524b69ad47e5557026803a897b5
0eb6f54fe4e1c9b516263b874c626e04a4beb09e
v1.0
instruct
Filter
Filter_25611_I
Create a for loop that outputs all prime numbers between 1 and 20, but instead of using trial division, implement the Sieve of Eratosthenes algorithm for finding prime numbers.
def sieve_of_eratosthenes(limit): """ Implement the Sieve of Eratosthenes algorithm to find all prime numbers up to a specified limit. """ primes = [] sieve = [True] * (limit + 1) for num in range(2, limit + 1): if sieve[num]: primes.append(num) for multiple in ra...
from solution import sieve_of_eratosthenes, primes_between_1_and_20 def test_sieve_of_eratosthenes_simple(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] def test_sieve_of_eratosthenes_20(): assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_primes_between_1_and_20(): assert pr...
[ { "docstring": "Implement the Sieve of Eratosthenes algorithm to find all prime numbers up to a specified limit.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Returns all prime numbers b...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of prime numbers up to and including n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n primes = []\n if n < 2:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025611", "row_id": 25611, "seed_ids": "['Qwen2-72B-Instruct_63209']" }
0.583169
Filter_25611
I
[ "sieve_of_eratosthenes", "primes_between_1_and_20" ]
2
[ [ "primes_between_1_and_20", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a722d8acb8279b50382699f39433d77a56ae90a4
65615da2ebcfaf55741a0acd7b452a5e95136901
v1.0
instruct
Filter
Filter_25613_I
Write a python program to implement quick sort algorithm with a pivot chosen as the first element of the list. Also compare the performance with merge sort algorithm for a dataset of 10,000 numbers. Make sure to import the time module to calculate the execution time of each sorting algorithm.
import time import random def quick_sort(arr): """ Perform quick sort on the array using the first element as pivot. """ if len(arr) <= 1: return arr else: pivot = arr[0] less_than_pivot = [x for x in arr[1:] if x <= pivot] greater_than_pivot = [x for x in arr[1:] if...
from solution import quick_sort, merge_sort, compare_sorting_algorithms def test_quick_sort(): assert quick_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10] assert quick_sort([]) == [] assert quick_sort([1]) == [1] assert quick_sort([4, 4, 4, 4]) == [4, 4, 4, 4] def test_merge_sort(): assert...
[ { "docstring": "Perform quick sort on the array using the first element as pivot.", "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" }, { "docstring": "Perform merge sort on the array.", "function_declaration": "def merge_sort(arr):...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport random\n\ndef quick_sort(arr):\n if len(arr) <= 1:\n return arr\n else:\n pivot = arr[0]\n less = [x for x in arr[1:] if x <= pivot]\n gre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025613", "row_id": 25613, "seed_ids": "['Qwen2-72B-Instruct_63214']" }
0.47244
Filter_25613
I
[ "quick_sort", "merge_sort", "merge", "compare_sorting_algorithms" ]
4
[ [ "compare_sorting_algorithms", "merge_sort" ], [ "compare_sorting_algorithms", "quick_sort" ], [ "merge_sort", "merge" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c01f19c3907d957ee3dcec3b4706a84f6880998c
ebadfcfdc1744482491ec39efff4810ebfab01ba
v1.0
instruct
Filter
Filter_25621_I
Write a program in Python to print out the first n prime numbers, where n is a positive integer provided by the user. The program should also calculate and display the sum of the first n prime numbers.
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def first_n_primes(n): """ Returns the first n prime numbers and their sum. """ primes = [...
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(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False assert is_prime(0) == Fal...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the first n prime numbers and their sum.", "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 Helper function to 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 nu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025621", "row_id": 25621, "seed_ids": "['Qwen2-72B-Instruct_63232']" }
0.673084
Filter_25621
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f2f88fc6005384ef92f1f31591b134f4f05ac8e
f6511e6a4517504565d51e347306ae19e954fa64
v1.0
instruct
Filter
Filter_25622_I
Design a Python function that can identify prime numbers from an array of integers, including negative integers and zero. This function should be capable of handling exceptions for inputs that are non-numerical, floating point numbers, or even numbers that exceed Python's integer limit. The output should be structured ...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def find_primes_and_product(arr): """ ...
from solution import is_prime, find_primes_and_product 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(-1) == False assert is_prime...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Identifies prime numbers in the input array and returns a tuple\nwith primes in ascending order and their product.", "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(num):\n \"\"\"\n Determines 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 r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025622", "row_id": 25622, "seed_ids": "['Qwen2-72B-Instruct_63233']" }
0.719189
Filter_25622
I
[ "is_prime", "find_primes_and_product" ]
2
[ [ "find_primes_and_product", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d52a56553a75e55d85f7c2ca8dbd215b2612638d
3ff7f6d9e8e413b59c3e9306ff3cf14cd3200cab
v1.0
instruct
Filter
Filter_25640_I
Generate a Python script to print the first 100 prime numbers.
def is_prime(n): """ Check if a number is a prime. Args: n (int): The number to check. Returns: bool: True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i...
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(29) == True assert is_prime(30) == False def test_first_n_primes(): assert first_n_primes(1) == [2] assert first_n_primes(5) ...
[ { "docstring": "Check if a number is a prime.\n\nArgs:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate the first n 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 a prime.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if n is a prime number, False otherwise....
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025640", "row_id": 25640, "seed_ids": "['Qwen2-72B-Instruct_63263']" }
0.555877
Filter_25640
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9561c71192761668e20efa6cbf73d12a1bd36f65
3ccbfde9b78d4f8458f5bbb4b9f90636c7c0929f
v1.0
instruct
Filter
Filter_25651_I
Create a Python script that prints out the first N prime numbers, where N is provided as an input by the user. Additionally, modify the script to check if each prime number is a palindrome and print only the palindromic prime numbers.
def is_prime(n): if n <= 1: return False elif n <= 3: return True elif n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is_palindrome(n): return str(n) ==...
from solution import is_prime, is_palindrome, palindromic_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(20) == False assert is_prime(29) == True def test_is_palindrome(): assert is_p...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": null,...
[ 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 elif n <= 3:\n return True\n elif n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025651", "row_id": 25651, "seed_ids": "['Qwen2-72B-Instruct_63279']" }
0.615267
Filter_25651
I
[ "is_prime", "is_palindrome", "palindromic_primes" ]
3
[ [ "palindromic_primes", "is_palindrome" ], [ "palindromic_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8fec77d61823d06b18997105567bdd7c46f2135c
a043050f411dc190bce0f9623567399e3a12ca00
v1.0
instruct
Filter
Filter_25662_I
Write a Python program for a game of Hangman. The game should include a way to select a word for the player to guess, allow the player to enter guesses, keep track of the number of incorrect guesses, and display the current state of the word being guessed.
import random def select_word(word_list): return random.choice(word_list) def display_current_state(word, guessed_letters): display = ''.join(letter if letter in guessed_letters else '_' for letter in word) return display def hangman(word_list): word = select_word(word_list) guessed_letters = set...
import pytest from solution import select_word, display_current_state def test_select_word(): word_list = ["python", "hangman", "programming", "challenge"] word = select_word(word_list) assert word in word_list def test_display_current_state_empty(): word = "hangman" guessed_letters = set() st...
[ { "docstring": null, "function_declaration": "def select_word(word_list):", "function_name": "select_word", "parameter_list": "(word_list)" }, { "docstring": null, "function_declaration": "def display_current_state(word, guessed_letters):", "function_name": "display_current_state", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef select_word(word_list):\n \"\"\"\n Select a random word from the word_list.\n \"\"\"\n return random.choice(word_list)\n\ndef display_word(word, correct_guesse...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025662", "row_id": 25662, "seed_ids": "['Qwen2-72B-Instruct_63303']" }
0.500641
Filter_25662
I
[ "select_word", "display_current_state", "hangman" ]
3
[ [ "hangman", "display_current_state" ], [ "hangman", "select_word" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f5031684470a04f51b15d9834d74ffc76f813b75
9e6fed0c127903ab6743b224199204d01d7d4a0e
v1.0
instruct
Filter
Filter_25702_I
Write an algorithm in Python to search for the first non-repeating prime number in a given array. The array may contain both positive and negative integers. The array may also contain duplicate elements. If there are no non-repeating prime numbers, return None.
def is_prime(n): """ Checks whether a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def first_non_repeati...
from solution import first_non_repeating_prime def test_all_non_primes(): assert first_non_repeating_prime([-1, 0, 1, 4, 6, 8, 9, 10]) == None def test_mixed_primes_and_non_primes(): assert first_non_repeating_prime([4, 6, 7, 4, 7, 12, 11]) == 11 def test_all_repeating_primes(): assert first_non_repeatin...
[ { "docstring": "Checks whether a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds the first non-repeating prime number in the given array.", "function_declaration": "def first_non_repeati...
[ 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 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_1
{ "original_instruction": "", "prompt_id": "00025702", "row_id": 25702, "seed_ids": "['Qwen2-72B-Instruct_63370']" }
0.614274
Filter_25702
I
[ "is_prime", "first_non_repeating_prime" ]
2
[ [ "first_non_repeating_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ba618e40815c73ace75e1a4eb168d5a2601b437
4396b28b9785bf3629f65a4c4a83a27c045a153a
v1.0
instruct
Filter
Filter_25704_I
How to sort an array in-place using the quick sort algorithm in Python without using any additional libraries?
def quicksort(arr, low, high): """ Sorts an array in place using the quicksort algorithm. Parameters: arr (list): The list of elements to be sorted. low (int): The starting index of the array to sort. high (int): The ending index of the array to sort. """ if low < high: # Pa...
def test_empty_array(): arr = [] quicksort(arr, 0, len(arr) - 1) assert arr == [] def test_single_element(): arr = [1] quicksort(arr, 0, len(arr) - 1) assert arr == [1] def test_sorted_array(): arr = [1, 2, 3, 4, 5] quicksort(arr, 0, len(arr) - 1) assert arr == [1, 2, 3, 4, 5] def...
[ { "docstring": "Sorts an array in place using the quicksort algorithm.\n\nParameters:\narr (list): The list of elements to be sorted.\nlow (int): The starting index of the array to sort.\nhigh (int): The ending index of the array to sort.", "function_declaration": "def quicksort(arr, low, high):", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort(arr):\n \"\"\"\n Sorts an array in-place using the quick sort algorithm.\n \"\"\"\n def _quick_sort(arr, low, high):\n if low < high:\n pi = _parti...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025704", "row_id": 25704, "seed_ids": "['Qwen2-72B-Instruct_63373']" }
0.583157
Filter_25704
I
[ "quicksort", "partition" ]
2
[ [ "quicksort", "partition" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ea2bdfa6f52ec9fa016535e2e4d68f74b960874d
ae03d1e63a6690a474e9abd461574cf08009a863
v1.0
instruct
Filter
Filter_25741_I
Create a sorting algorithm for an array that only needs 1 for loop and has a time complexity of O(n log n) and space complexity of O(1). The algorithm must be able to handle arrays with up to 1 million elements. In addition, the algorithm should be able to handle arrays with elements in the range of -10^9 to 10^9. Arra...
def quicksort(arr, low, high): """ A function to perform in-place quicksort. """ if low < high: # pivot_index is partitioning index, arr[pivot_index] is now at the right place pivot_index = partition(arr, low, high) # Separately sort elements before partition and after partition...
from solution import sort_array def test_sort_array(): assert sort_array([7, -3, 2, 9, -2, 1000000000, -1000000000]) == [-1000000000, -3, -2, 2, 7, 9, 1000000000] def test_sort_array_with_duplicates(): assert sort_array([5, 1, 4, 2, 5, 5, 3]) == [1, 2, 3, 4, 5, 5, 5] def test_sort_empty_array(): assert s...
[ { "docstring": "A function to perform in-place quicksort.", "function_declaration": "def quicksort(arr, low, high):", "function_name": "quicksort", "parameter_list": "(arr, low, high)" }, { "docstring": "This function takes the last element as a pivot, places the pivot element at its correct...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shell_sort(arr):\n \"\"\"\n Sorts an array using the Shell Sort algorithm.\n The algorithm works using a gap sequence to compare and sort elements\n \"\"\"\n n = len(arr)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025741", "row_id": 25741, "seed_ids": "['Qwen2-72B-Instruct_63435']" }
0.546573
Filter_25741
I
[ "quicksort", "partition", "sort_array" ]
3
[ [ "quicksort", "partition" ], [ "sort_array", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3c9d5a20426b0e8a2eefed9343b779883f17f58d
e2e664ec5af489c894a6a7e6163316fdeaed10d0
v1.0
instruct
Filter
Filter_25743_I
Replace the "TODO" comment in the code with the proper code to print the sum of all prime numbers up to a given number n.
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 sum_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_sum_of_primes_small()...
[ { "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 up to and including n.", "function_declaration": "def sum_of_primes(n):", "funct...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_primes(n):\n \"\"\"\n Returns the sum of all prime numbers up to and including n, if n is a prime.\n \"\"\"\n def is_prime(num):\n if num < 2:\n return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025743", "row_id": 25743, "seed_ids": "['Qwen2-72B-Instruct_63442']" }
0.576796
Filter_25743
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e77b5754eaae6f6b27167ec6e11598dd434689c0
2014c0e52e42464bec7473d04d2ecca45084786b
v1.0
instruct
Filter
Filter_25764_I
Given a number n, write a Fibonacci sequence generator in Python that uses matrix exponentiation to efficiently calculate the nth number in the sequence. Your function should also be able to handle large values of n (up to 10^9) without significant performance drop. Additionally, implement a function to prove the corre...
def matrix_mult(A, B): """Multiplies two 2x2 matrices A and B""" return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]] def matrix_pow(matrix, n): """Perfor...
from solution import fib_matrix_exponentiation, fib_recursive, verify_fibonacci_solution def test_fib_matrix_exponentiation(): # Test known numbers in Fibonacci sequence assert fib_matrix_exponentiation(0) == 0 assert fib_matrix_exponentiation(1) == 1 assert fib_matrix_exponentiation(2) == 1 assert...
[ { "docstring": "Multiplies two 2x2 matrices A and B", "function_declaration": "def matrix_mult(A, B):", "function_name": "matrix_mult", "parameter_list": "(A, B)" }, { "docstring": "Performs matrix exponentiation", "function_declaration": "def matrix_pow(matrix, n):", "function_name"...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_mult(A, B):\n \"\"\"Multiples two 2x2 matrices.\"\"\"\n return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],\n [A[1][0] * B[0][0]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025764", "row_id": 25764, "seed_ids": "['Qwen2-72B-Instruct_63471']" }
0.723602
Filter_25764
I
[ "matrix_mult", "matrix_pow", "fib_matrix_exponentiation", "fib_recursive", "verify_fibonacci_solution" ]
5
[ [ "fib_matrix_exponentiation", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ], [ "verify_fibonacci_solution", "fib_matrix_exponentiation" ], [ "verify_fibonacci_solution", "fib_recursive" ] ]
4
[]
false
[]
false
pytest
true
[]
true
e6c8cfebb128d17e82bdfc0df942ff53939a8ddf
33bfcf0bc9b623581d0b090eeddf9a0376966932
v1.0
instruct
Filter
Filter_25778_I
Write a Python program to create a complete functional implementation of the classic Tic-Tac-Toe (Noughts and Crosses) game. Not only should the game allow two players to play against each other, but it should also have the capability to check the game state to determine if there's a winner or if the game is a draw.
def initialize_board(): return [[' ' for _ in range(3)] for _ in range(3)] def print_board(board): for row in board: print('|'.join(row)) print('-' * 5) def check_winner(board): # Check rows for row in board: if row[0] == row[1] == row[2] and row[0] != ' ': return r...
from solution import initialize_board, print_board, check_winner, check_draw, make_move, switch_player def test_initialize_board(): board = initialize_board() assert board == [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] def test_check_winner_row(): board = [['X', 'X', 'X'], [' ', ' ', ' '], [' ', '...
[ { "docstring": null, "function_declaration": "def initialize_board():", "function_name": "initialize_board", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def print_board(board):", "function_name": "print_board", "parameter_list": "(board)" }, { ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TicTacToe:\n def __init__(self):\n self.board = [[' ' for _ in range(3)] for _ in range(3)]\n self.current_turn = 'X'\n\n def print_board(self):\n for row in s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025778", "row_id": 25778, "seed_ids": "['Qwen2-72B-Instruct_63493']" }
0.419802
Filter_25778
I
[ "initialize_board", "print_board", "check_winner", "check_draw", "make_move", "switch_player", "play_game" ]
7
[ [ "play_game", "check_draw" ], [ "play_game", "check_winner" ], [ "play_game", "initialize_board" ], [ "play_game", "make_move" ], [ "play_game", "print_board" ], [ "play_game", "switch_player" ] ]
6
[]
false
[]
false
pytest
true
[]
true
c9074a07dd330efe1607e149f1fa8724ec4b60b5
1fbf8d5c59338b859b728f6930e79dadccffe956
v1.0
instruct
Filter
Filter_25794_I
Develop a program that not only executes the Penrose unilattice and P2 Penrose tiling substitution rules but also the Ammann-Beenker and Robinson Triangle substitution rules. The program should take 'n' levels of subdivision as an input parameter. The program should demonstrate the progression of the tiling from an ini...
import time def penrose_tiling(n): # This function generates Penrose tiling based on P2 substitution rules tiles = ['P2 initial tile'] # Simplified for illustration for i in range(n): tiles = substitute_p2(tiles) return tiles def unilattice_tiling(n): # This function generates Penrose uni...
from solution import penrose_tiling, unilattice_tiling, amm_beenker_tiling, rob_triangle_tiling, comparative_analysis def test_penrose_tiling(): tiles = penrose_tiling(1) assert len(tiles) == 2 # One initial and one new tile def test_unilattice_tiling(): tiles = unilattice_tiling(1) assert len(tiles)...
[ { "docstring": null, "function_declaration": "def penrose_tiling(n):", "function_name": "penrose_tiling", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def unilattice_tiling(n):", "function_name": "unilattice_tiling", "parameter_list": "(n)" }, { ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport math\n\n# Placeholder function for Penrose unilattice substitution\ndef penrose_unilattice_substitution(tiles, level):\n # Placeholder for actual substitution rule\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025794", "row_id": 25794, "seed_ids": "['Qwen2-72B-Instruct_63525']" }
0.493912
Filter_25794
I
[ "penrose_tiling", "unilattice_tiling", "amm_beenker_tiling", "rob_triangle_tiling", "substitute_p2", "substitute_unilattice", "substitute_ammann_beenker", "substitute_robinson_triangle", "analyze_tiling", "comparative_analysis" ]
10
[ [ "amm_beenker_tiling", "substitute_ammann_beenker" ], [ "comparative_analysis", "analyze_tiling" ], [ "penrose_tiling", "substitute_p2" ], [ "rob_triangle_tiling", "substitute_robinson_triangle" ], [ "unilattice_tiling", "substitute_unilattice" ] ]
5
[]
false
[]
false
pytest
true
[]
true
44db85189220621d4bad9e6061212b0ed8230700
e383a3fcf9128ab6855215d76497972278100fa7
v1.0
instruct
Filter
Filter_25796_I
Build a Python program to generate a prime numbers list in a given range, where the range is from 1 to 1,000,000 and the program should use a multi-threading approach to improve performance.
import threading def is_prime(n): """ Check if the number n is a prime number. """ if n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def generate_primes(start, end, result): """ Generate prime numbers in the...
from solution import prime_numbers_in_range, is_prime def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(17) assert not is_prime(18) assert not is_prime(1) def test_prime_numbers_in_range_small_range(): primes = prime_numbers_in_range(1, 10) ...
[ { "docstring": "Check if the number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate prime numbers in the range from start to end and store them in result list.", "function_declaration": "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import threading\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025796", "row_id": 25796, "seed_ids": "['Qwen2-72B-Instruct_63528']" }
0.590936
Filter_25796
I
[ "is_prime", "generate_primes", "prime_numbers_in_range" ]
3
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dbfa095b50f361f72aba30c1288366211bc0c000
1e3c392e527288583cd2ed8262a25f5886afe767
v1.0
instruct
Filter
Filter_25807_I
Rephrase this code into a function that calculates the sum of two parameters and if the sum is greater than 10, it should return -999. Additionally, the function should check if the sum is a prime number and return a tuple containing the prime factors of the sum if it is a prime number. If the sum is not a prime number...
from math import sqrt 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 Fals...
from solution import sum_and_prime_factors, is_prime, prime_factors def test_sum_and_prime_factors_sum_greater_than_10(): assert sum_and_prime_factors(8, 5) == -999 assert sum_and_prime_factors(10, 1) == -999 def test_sum_and_prime_factors_prime_sum(): assert sum_and_prime_factors(2, 3) == (5,) assert...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate the prime factors of a given number.", "function_declaration": "def prime_factors(n):", "function_name":...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_and_check(a, b):\n \"\"\"\n Calculates the sum of two numbers a and b.\n If the sum is greater than 10, the function returns -999.\n If the sum is a prime number, it return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025807", "row_id": 25807, "seed_ids": "['Qwen2-72B-Instruct_63548']" }
0.580659
Filter_25807
I
[ "is_prime", "prime_factors", "sum_and_prime_factors" ]
3
[ [ "prime_factors", "is_prime" ], [ "sum_and_prime_factors", "is_prime" ], [ "sum_and_prime_factors", "prime_factors" ] ]
3
[]
false
[]
false
pytest
true
[]
true
22b1d261da5caff45c169390926706a0d91e5d92
79e2984a41ef30a371cc98a0fa1afcb621bb1860
v1.0
instruct
Filter
Filter_25821_I
Create a Python program that generates a random list of 1,000,000 integers between 0 and 10,000. The program should then calculate the sum of all the prime numbers in the list and print it out. Additionally, the program should ensure that the sum is calculated using parallel processing to improve performance. Furthermo...
import random from multiprocessing import Pool, cpu_count import itertools 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 o...
from solution import is_prime, sum_of_primes, generate_random_list, parallel_sum_of_primes def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-3) def test_sum_of_primes(): ...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculate the sum of all prime numbers in the given data list.", "function_declaration": "def sum_of_primes(data):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom multiprocessing import Pool, cpu_count\nimport itertools\n\ndef is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025821", "row_id": 25821, "seed_ids": "['Qwen2-72B-Instruct_63579']" }
0.588663
Filter_25821
I
[ "is_prime", "sum_of_primes", "generate_random_list", "parallel_sum_of_primes", "main" ]
5
[ [ "parallel_sum_of_primes", "sum_of_primes" ], [ "sum_of_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
407e4e6bda2273f0db0cd9f3e9feda60705188ab
99e97bcaf3668a2890b08e87302ef8aed352db86
v1.0
instruct
Filter
Filter_25822_I
Here is a list of strings and an additional string. Write a code to find the Levenshtein distance between the additional string and all the strings in the list. Then, identify which string in the list has the smallest Levenshtein distance to the additional string.
def levenshtein_distance(s1, s2): """ Compute the Levenshtein distance between two strings s1 and s2. """ if len(s1) < len(s2): return levenshtein_distance(s2, s1) if len(s2) == 0: return len(s1) previous_row = range(len(s2) + 1) for i, c1 in enumerate(s1): current_...
from solution import levenshtein_distance, find_closest_string def test_levenshtein_distance_identical_strings(): assert levenshtein_distance("kitten", "kitten") == 0 def test_levenshtein_distance_different_strings(): assert levenshtein_distance("kitten", "sitting") == 3 def test_levenshtein_distance_empty_a...
[ { "docstring": "Compute the Levenshtein distance between two strings s1 and s2.", "function_declaration": "def levenshtein_distance(s1, s2):", "function_name": "levenshtein_distance", "parameter_list": "(s1, s2)" }, { "docstring": "Find the string in the list that has the smallest Levenshtei...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def levenshtein_distance(s1, s2):\n \"\"\"\n Compute the Levenshtein distance between two strings.\n \"\"\"\n if len(s1) < len(s2):\n return levenshtein_distance(s2, s1)\n\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025822", "row_id": 25822, "seed_ids": "['Qwen2-72B-Instruct_63580']" }
0.626742
Filter_25822
I
[ "levenshtein_distance", "find_closest_string" ]
2
[ [ "find_closest_string", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9ee91b9cdefdcb9da0fe87ad0a5950af6e4be9d
2e59e427ebc5953b7134211b118245615f28dda3
v1.0
instruct
Filter
Filter_25844_I
Develop a Python code that will extract and print all the words in a given sentence in reverse order. However, the words themselves should remain in their original form. Also, include a function that will print the number of vowels and consonants in each word before the main function is invoked.
def count_vowels_and_consonants(word): """ Counts the vowels and consonants in a given word. """ vowels = "aeiouAEIOU" num_vowels = sum(1 for letter in word if letter in vowels) num_consonants = len([letter for letter in word if letter.isalpha() and letter not in vowels]) return num_vowels, ...
from solution import count_vowels_and_consonants, print_vowels_and_consonants, reverse_words_order def test_count_vowels_and_consonants(): assert count_vowels_and_consonants("hello") == (2, 3) assert count_vowels_and_consonants("world") == (1, 4) assert count_vowels_and_consonants("AEIOU") == (5, 0) as...
[ { "docstring": "Counts the vowels and consonants in a given word.", "function_declaration": "def count_vowels_and_consonants(word):", "function_name": "count_vowels_and_consonants", "parameter_list": "(word)" }, { "docstring": "Prints the number of vowels and consonants in each word of the s...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_vowels_and_consonants(word):\n \"\"\"\n Returns the number of vowels and consonants in a given word.\n \"\"\"\n vowels = set(\"aeiouAEIOU\")\n num_vowels = sum(1 for l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025844", "row_id": 25844, "seed_ids": "['Qwen2-72B-Instruct_63613']" }
0.665935
Filter_25844
I
[ "count_vowels_and_consonants", "print_vowels_and_consonants", "reverse_words_order" ]
3
[ [ "print_vowels_and_consonants", "count_vowels_and_consonants" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9bdce842ceae763322ca875d46f41393774607e
f1ec0f38ae82e2b7c3d374cd414407d9ca11bb3b
v1.0
instruct
Filter
Filter_25846_I
Create a dictionary in Python mapping the following characters to numbers: A = 1, B = 2, C = 3, D = 4, E = 5, F = 6, G = 7, H = 8, I = 9, J = 10. The function should also check if the input string contains only characters from A to J. If the input string contains any other character, the function should raise a ValueEr...
def create_mapping_dict(): """ Creates and returns a dictionary mapping characters A-J to numbers 1-10. """ return {chr(i + 64): i for i in range(1, 11)} def validate_and_map_string(input_string): """ Validates if the input_string contains only characters A to J. If valid, returns a list of...
from solution import validate_and_map_string def test_valid_string(): assert validate_and_map_string("ABC") == [1, 2, 3] assert validate_and_map_string("J") == [10] assert validate_and_map_string("ABCDEFGHIJ") == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_invalid_string(): try: validate_and_map_...
[ { "docstring": "Creates and returns a dictionary mapping characters A-J to numbers 1-10.", "function_declaration": "def create_mapping_dict():", "function_name": "create_mapping_dict", "parameter_list": "()" }, { "docstring": "Validates if the input_string contains only characters A to J.\nI...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_char_to_number_dict():\n \"\"\"\n Returns a dictionary mapping characters A-J to numbers 1-10.\n \"\"\"\n return {chr(i + 65): i + 1 for i in range(10)}\n\ndef validate_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025846", "row_id": 25846, "seed_ids": "['Qwen2-72B-Instruct_63618']" }
0.646847
Filter_25846
I
[ "create_mapping_dict", "validate_and_map_string" ]
2
[ [ "validate_and_map_string", "create_mapping_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87235e5ab0b399504567fa1f0e7bcc4f00a3a12b
2381db2dec5e4f2a7508b7b535214b9fd29393e7
v1.0
instruct
Filter
Filter_25847_I
2. Write a Python program to create a list of first 10 Fibonacci numbers.
def generate_fibonacci(n): """ Generates a list of first n Fibonacci numbers. """ fibonacci_sequence = [0, 1] while len(fibonacci_sequence) < n: next_value = fibonacci_sequence[-1] + fibonacci_sequence[-2] fibonacci_sequence.append(next_value) return fibonacci_sequence[:n] def f...
from solution import first_10_fibonacci, generate_fibonacci def test_first_10_fibonacci(): expected_result = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] assert first_10_fibonacci() == expected_result def test_generate_fibonacci(): assert generate_fibonacci(1) == [0] assert generate_fibonacci(2) == [0, 1] as...
[ { "docstring": "Generates a list of first n Fibonacci numbers.", "function_declaration": "def generate_fibonacci(n):", "function_name": "generate_fibonacci", "parameter_list": "(n)" }, { "docstring": "Returns a list of the first 10 Fibonacci numbers.", "function_declaration": "def first_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(n=10):\n \"\"\"\n Generate a list of the first n Fibonacci numbers.\n By default, generates the first 10 Fibonacci numbers.\n \"\"\"\n if n <= 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025847", "row_id": 25847, "seed_ids": "['Qwen2-72B-Instruct_63620']" }
0.694251
Filter_25847
I
[ "generate_fibonacci", "first_10_fibonacci" ]
2
[ [ "first_10_fibonacci", "generate_fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8630d5ec22cf8623a74ab6961306367f126164d
35792f76210a1cd3b9c3be7d2aceeec8362015ce
v1.0
instruct
Filter
Filter_25853_I
Reorganize the given Python code such that two functions are created. The first function, greet_to(name), should print a greeting to the name provided. The second function, greet_to_all(names), should take a list of names as input and print a greeting to each name in the list. Both functions should raise an exception i...
def greet_to(name): """ Prints a greeting to the given name. Raises a TypeError if the input is not a string. """ if not isinstance(name, str): raise TypeError("Expected a string") print(f"Hello, {name}!") def greet_to_all(names): """ Prints a greeting to each name in the given ...
import pytest from solution import greet_to, greet_to_all def test_greet_to_with_valid_string(capsys): greet_to("Alice") captured = capsys.readouterr() assert captured.out == "Hello, Alice!\n" def test_greet_to_with_invalid_input(): with pytest.raises(TypeError): greet_to(123) def test_greet_...
[ { "docstring": "Prints a greeting to the given name.\nRaises a TypeError if the input is not a string.", "function_declaration": "def greet_to(name):", "function_name": "greet_to", "parameter_list": "(name)" }, { "docstring": "Prints a greeting to each name in the given list.\nRaises a TypeE...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def greet_to(name):\n \"\"\"\n Print a greeting message to the given name.\n Raises a TypeError if the input is not a string.\n \"\"\"\n if not isinstance(name, str):\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025853", "row_id": 25853, "seed_ids": "['Qwen2-72B-Instruct_63631']" }
0.444874
Filter_25853
I
[ "greet_to", "greet_to_all" ]
2
[ [ "greet_to_all", "greet_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
607b47110fa7994b480ce0aca13228b8d1065b12
9c4c4387f876e2a3394bdee9370a3e9649263b06
v1.0
instruct
Filter
Filter_25863_I
Create a function that prints a list of all the prime numbers from a given list of integers. If the input list contains any non-integer values or negative numbers, raise a ValueError with the message "Input list should only contain positive integers.". The function should have a time complexity of O(n * sqrt(m)), where...
import math def is_prime(num): if num < 2: return False for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: return False return True def primes_from_list(lst): """ Returns a list of all prime numbers from the input list of integers. Raises ValueError i...
from solution import primes_from_list, is_prime def test_primes_from_list_only_primes(): assert primes_from_list([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_primes_from_list_mixed_numbers(): assert primes_from_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_primes_from_list_no_prime...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers from the input list of integers.\n\nRaises ValueError if the input list contains any non-integer values or negative...
[ 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_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3, int(math.sqr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025863", "row_id": 25863, "seed_ids": "['Qwen2-72B-Instruct_63643']" }
0.690957
Filter_25863
I
[ "is_prime", "primes_from_list" ]
2
[ [ "primes_from_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad93847ea293df301b90ff66fefe6ca2b3adea73
1178d79ed749e494770e59685b22112b01202dee
v1.0
instruct
Filter
Filter_25892_I
Write a program that generates all unique combinations of 6 digits from 0 to 9 where the order matters. Ensure no combination is repeated and each digit can only appear once per combination. Additionally, implement a function that checks the validity of these combinations based on a provided set of rules for what const...
import itertools def generate_combinations(): """ Generates all unique combinations of 6 digits from 0 to 9 where the order matters and no combination is repeated. Each digit can appear only once per combination. """ digits = range(10) return list(itertools.permutations(digits, 6)) def is...
from solution import generate_combinations, is_valid_combination, filter_valid_combinations def test_generate_combinations_length(): combinations = generate_combinations() assert len(combinations) == 151200 # 10P6 = 10! / (10-6)! def test_is_valid_combination(): assert is_valid_combination((1, 3, 5, 7, 9...
[ { "docstring": "Generates all unique combinations of 6 digits from 0 to 9 \nwhere the order matters and no combination is repeated.\nEach digit can appear only once per combination.", "function_declaration": "def generate_combinations():", "function_name": "generate_combinations", "parameter_list": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef generate_combinations():\n \"\"\"\n Generates all unique valid combinations of 6 digits where each digit \n from 0 to 9 can appear only once ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025892", "row_id": 25892, "seed_ids": "['Qwen2-72B-Instruct_63682']" }
0.625529
Filter_25892
I
[ "generate_combinations", "is_valid_combination", "filter_valid_combinations" ]
3
[ [ "filter_valid_combinations", "is_valid_combination" ] ]
1
[]
false
[]
false
pytest
true
[]
true
743acb07d9e239f02420dcad5a119c88b5191426
f1f71cbb10d6cecbffb2a52515371da34dfd845d
v1.0
instruct
Filter
Filter_25908_I
Write a program that simulates a game of Rock, Paper, Scissors against the computer. The program should prompt the user for their choice and then randomly generate a choice for the computer. After both choices are made, the program should determine the winner and display the results.
import random def get_computer_choice(): """ Randomly returns either 'rock', 'paper', or 'scissors' as the computer's choice. """ return random.choice(['rock', 'paper', 'scissors']) def determine_winner(user_choice, computer_choice): """ Determines the winner of a rock, paper, scissors game. ...
import pytest from solution import get_computer_choice, determine_winner, play_game def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'user' assert determine_winner('rock', 'paper') == 'computer' assert determine_winner('rock', 'rock') == 'tie' assert determine_winner('paper',...
[ { "docstring": "Randomly returns either 'rock', 'paper', or 'scissors' as the computer's choice.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner of a rock, paper, scissors game.\n\...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly returns either 'rock', 'paper', or 'scissors' as the computer's choice.\n \"\"\"\n return random.choice(['rock', 'pa...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025908", "row_id": 25908, "seed_ids": "['Qwen2-72B-Instruct_63705']" }
0.536198
Filter_25908
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ], [ "play_game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b3a9a97d5c90ffc4207e125f0ab445fc0e3d7a4c
1bc285c4999914b8a3c38a67afc9ca1218f37fe7
v1.0
instruct
Filter
Filter_25911_I
Create a nested for loop for iterating through a 2-dimensional array and printing out each element. However, instead of printing out the elements that are prime numbers, you need to print out the reverse of each non-prime number.
def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def reverse_number(n): reversed_n = 0 while n > 0: reversed_n = reversed_n * 10 + n % 10 n = n // 10 return reversed_n def process_...
from solution import is_prime, reverse_number, process_2d_array 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_reverse_number(): assert reverse_number(123) == 321 asser...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": nul...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n 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 reverse_number(n):\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025911", "row_id": 25911, "seed_ids": "['Qwen2-72B-Instruct_63710']" }
0.609468
Filter_25911
I
[ "is_prime", "reverse_number", "process_2d_array" ]
3
[ [ "process_2d_array", "is_prime" ], [ "process_2d_array", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a8daf62dce2855051da63245b3234962e8799e85
08a5c3f82f3b78855effeac684a12b1b4c0cadaa
v1.0
instruct
Filter
Filter_25937_I
Briefly, how would you do script that runs GeoNet download script, but only when there is internet connection and also checks if the file is already up-to-date.
import requests import os import hashlib def is_internet_connected(url="http://www.google.com/", timeout=5): """ Checks if the internet connection is available. """ try: response = requests.get(url, timeout=timeout) return True except (requests.ConnectionError, requests.Timeout): ...
from unittest import mock from solution import ( is_internet_connected, file_hash, download_file, is_file_up_to_date, run_geonet_download_script ) def test_is_internet_connected(): with mock.patch('requests.get') as mock_get: mock_get.return_value = mock.Mock(ok=True) assert is_internet_con...
[ { "docstring": "Checks if the internet connection is available.", "function_declaration": "def is_internet_connected(url='http://www.google.com/', timeout=5):", "function_name": "is_internet_connected", "parameter_list": "(url='http://www.google.com/', timeout=5)" }, { "docstring": "Returns ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport requests\nimport hashlib\n\ndef is_connected_to_internet(test_url='http://www.google.com/'):\n \"\"\"\n Checks if the machine has an active internet connection by sendi...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025937", "row_id": 25937, "seed_ids": "['Qwen2-72B-Instruct_63756']" }
0.394614
Filter_25937
I
[ "is_internet_connected", "file_hash", "download_file", "is_file_up_to_date", "run_geonet_download_script" ]
5
[ [ "is_file_up_to_date", "file_hash" ], [ "run_geonet_download_script", "download_file" ], [ "run_geonet_download_script", "is_file_up_to_date" ], [ "run_geonet_download_script", "is_internet_connected" ] ]
4
[]
false
[]
false
pytest
true
[ "requests" ]
false
b3c710347aa6d74de49a2ea59f6c0f9ee63bc7de
e66803445085aa02ce171f97d67c3c05c0b08b00
v1.0
instruct
Filter
Filter_25939_I
Craft a Python code that can substitute each given character in a sequence of letters with its immediate successor in the English alphabet, and in addition, your solution should account for edge cases such as the transition from 'z' to 'a', and appropriately handle both uppercase and lowercase letters.
def next_alphabet_char(char): """ Returns the immediate successor of the given character in the English alphabet. Handles the transition from 'z' to 'a' and 'Z' to 'A'. """ if 'a' <= char <= 'y' or 'A' <= char <= 'Y': return chr(ord(char) + 1) elif char == 'z': return 'a' eli...
from solution import next_alphabet_char, substitute_with_next_char def test_next_alphabet_char(): assert next_alphabet_char('a') == 'b' assert next_alphabet_char('y') == 'z' assert next_alphabet_char('z') == 'a' assert next_alphabet_char('A') == 'B' assert next_alphabet_char('Y') == 'Z' assert ...
[ { "docstring": "Returns the immediate successor of the given character in the English alphabet.\nHandles the transition from 'z' to 'a' and 'Z' to 'A'.", "function_declaration": "def next_alphabet_char(char):", "function_name": "next_alphabet_char", "parameter_list": "(char)" }, { "docstring...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def successor_characters(sequence):\n \"\"\"\n Returns a sequence where each character is replaced by its immediate successor in the alphabet.\n \"\"\"\n def get_successor_char(c):...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025939", "row_id": 25939, "seed_ids": "['Qwen2-72B-Instruct_63760']" }
0.623126
Filter_25939
I
[ "next_alphabet_char", "substitute_with_next_char" ]
2
[ [ "substitute_with_next_char", "next_alphabet_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce3ccddb7cba9c7afc59400d9ace11ab1a4e4696
d79fcefc9e56a4eeba02f6adf55c5721331183a2
v1.0
instruct
Filter
Filter_25950_I
Write a program that generates a random maze using Prim's algorithm and then finds a path through the maze using Depth-First Search (DFS). The maze should be visualized as ASCII art.
import random def generate_maze(rows, cols): """ Generates a random maze using Prim's algorithm. """ def add_walls(walls, x, y): if x > 1: walls.append((x - 2, y)) if x < rows - 2: walls.append((x + 2, y)) if y > 1: walls.append((x, y - 2)) ...
from solution import generate_maze, find_path, print_maze def test_generate_maze_size(): maze = generate_maze(9, 9) assert len(maze) == 9 assert all(len(row) == 9 for row in maze) def test_generate_maze_structure(): maze = generate_maze(11, 11) assert maze[0][0] == '#' assert maze[-1][-1] == '...
[ { "docstring": "Generates a random maze using Prim's algorithm.", "function_declaration": "def generate_maze(rows, cols):", "function_name": "generate_maze", "parameter_list": "(rows, cols)" }, { "docstring": "Finds a path through the maze using Depth-First Search (DFS).", "function_decl...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_maze(width, height):\n \"\"\" Generate a maze using Prim's algorithm. \"\"\"\n maze = [['#'] * width for _ in range(height)]\n walls = []\n start_pos ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00025950", "row_id": 25950, "seed_ids": "['Qwen2-72B-Instruct_63779']" }
0.472487
Filter_25950
I
[ "generate_maze", "find_path", "print_maze", "generate_and_solve_maze" ]
4
[ [ "generate_and_solve_maze", "find_path" ], [ "generate_and_solve_maze", "generate_maze" ], [ "generate_and_solve_maze", "print_maze" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0082f25e6d7d99e45e273fe0f69ea161d26f537d
0ecc1fdf4d21ba11f017be77442bf77b6bfe184d
v1.0
instruct
Filter
Filter_25962_I
Create a Python dictionary that stores square roots of prime numbers from 1 to 15. Moreover, implement a function that checks the integrity of the dictionary by verifying if the keys are indeed prime numbers and the values are their accurate square roots. Be sure to handle any potential errors that may arise from fault...
import math def is_prime(n): """Check if a number is a prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(math.sqrt(n)) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return T...
from solution import is_prime, create_prime_sqrt_dict, check_prime_sqrt_dict def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False def test_create_prime_sqrt_dict(): prime_sqrt_dict = crea...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Create a dictionary of prime numbers and their square roots from 1 to 15.", "function_declaration": "def create_prime_sqrt_d...
[ 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_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025962", "row_id": 25962, "seed_ids": "['Qwen2-72B-Instruct_63797']" }
0.551147
Filter_25962
I
[ "is_prime", "create_prime_sqrt_dict", "check_prime_sqrt_dict" ]
3
[ [ "check_prime_sqrt_dict", "is_prime" ], [ "create_prime_sqrt_dict", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9cbfdbb1f1c6533df189d3c5c7812e6a14b36990
e7bb84868ed606fd5dfe2107c3868784948e5b69
v1.0
instruct
Filter
Filter_25972_I
Write a Python program to identify all prime numbers within a given range. The program should accept two integers as input, representing the lower and upper bounds of the range, and output a list of all prime numbers within that range. Additionally, the program should implement the Sieve of Eratosthenes algorithm for f...
import random def is_prime_miller_rabin(n, k=5): if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False s, d = 0, n - 1 while d % 2 == 0: d //= 2 s += 1 def miller_rabin_trial(a, d, n, s): x = pow(a, d, n) if x == 1 or x == n - 1: ...
from solution import is_prime_miller_rabin, sieve_of_eratosthenes, find_primes_in_range def test_is_prime_miller_rabin(): assert is_prime_miller_rabin(2) assert is_prime_miller_rabin(3) assert is_prime_miller_rabin(5) assert not is_prime_miller_rabin(4) assert is_prime_miller_rabin(13) assert n...
[ { "docstring": null, "function_declaration": "def is_prime_miller_rabin(n, k=5):", "function_name": "is_prime_miller_rabin", "parameter_list": "(n, k=5)" }, { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(lower, upper):", "function_name": "sieve_of_eratosthene...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(lower, upper):\n \"\"\"\n Identify all prime numbers within a given range using the Sieve of Eratosthenes.\n \n Parameters:\n lower (int): Lower bound ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00025972", "row_id": 25972, "seed_ids": "['Qwen2-72B-Instruct_63815']" }
0.654849
Filter_25972
I
[ "is_prime_miller_rabin", "sieve_of_eratosthenes", "find_primes_in_range" ]
3
[ [ "find_primes_in_range", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43cdfe58593a5ae5011faa0dd198866311f3e624
9910ff042ff6d14959959a169ccd668f29a21db3
v1.0
instruct
Filter
Filter_25980_I
Write a script to sort an array of numbers from largest to smallest using quick sort. The script should also handle duplicate numbers in the array and sort them based on their original positions. You are not allowed to use any built-in sorting functions or libraries. The time complexity of the script should be O(n log ...
def quicksort(arr, low, high): if low < high: pi = partition(arr, low, high) quicksort(arr, low, pi-1) quicksort(arr, pi+1, high) def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] > pivot: i = i + 1 ...
from solution import sort_array def test_sort_positive_numbers(): assert sort_array([1, 3, 2, 5, 4]) == [5, 4, 3, 2, 1] def test_sort_with_zero(): assert sort_array([0, 5, 3, 0, 1]) == [5, 3, 1, 0, 0] def test_sort_negative_numbers(): assert sort_array([-1, -3, -2, -5, -4]) == [-1, -2, -3, -4, -5] def t...
[ { "docstring": null, "function_declaration": "def quicksort(arr, low, high):", "function_name": "quicksort", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(ar...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort(arr, low, high):\n if low < high:\n pi = partition(arr, low, high)\n quicksort(arr, low, pi-1)\n quicksort(arr, pi+1, high)\n\ndef partition(arr, low, hig...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025980", "row_id": 25980, "seed_ids": "['Qwen2-72B-Instruct_63826']" }
0.603335
Filter_25980
I
[ "quicksort", "partition", "sort_array" ]
3
[ [ "quicksort", "partition" ], [ "sort_array", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
85b5fa10a4b75572ddc97918b0346f1b46ceb07f
7fde74abd38098ebe04e5e0b2b4caf896f93111d
v1.0
instruct
Filter
Filter_25983_I
With the XML and JSON data provided below, write a program that demonstrates the complete process of data transformation from XML to JSON in Python. Also, the program should handle any errors during transformation.
import json import xml.etree.ElementTree as ET def xml_to_json(xml_data): """ Converts XML data to JSON format. :param xml_data: str, Input XML data as a string. :return: str, JSON formatted string or error message. """ try: # Parse the XML data root = ET.fromstring(xml_dat...
from solution import xml_to_json def test_xml_to_json_valid_data(): xml_data = """<note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>""" expected_j...
[ { "docstring": "Converts XML data to JSON format.\n\n:param xml_data: str, Input XML data as a string.\n:return: str, JSON formatted string or error message.", "function_declaration": "def xml_to_json(xml_data):", "function_name": "xml_to_json", "parameter_list": "(xml_data)" }, { "docstring...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nimport xml.etree.ElementTree as ET\n\ndef xml_to_json(xml_data):\n \"\"\"\n Converts XML data to JSON format.\n \n :param xml_data: str, Input XML data as a string.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00025983", "row_id": 25983, "seed_ids": "['Qwen2-72B-Instruct_63831']" }
0.694807
Filter_25983
I
[ "xml_to_json", "etree_to_dict" ]
2
[ [ "xml_to_json", "etree_to_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2699c562f369f5282cf6a66220ae0fedb659c98
d7c9e73fa4833d16b4f7b55b4f3c748cf91de000
v1.0
instruct
Filter
Filter_26010_I
Given the following erroneous Python code, correct and modify it to write a Python program that not only converts the temperature given in Celsius to Fahrenheit but also handles conversions in the opposite direction and Kelvin scale. Your solution should also be able to handle arbitrary number of temperature inputs at ...
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 celsius_to_kelvin(celsius): """ Converts Celsius to Kelvin. ...
from solution import ( celsius_to_fahrenheit, fahrenheit_to_celsius, celsius_to_kelvin, kelvin_to_celsius, convert_temperatures ) def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40...
[ { "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, 0, 0 ]
1
medium
0.333
{ "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 return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026010", "row_id": 26010, "seed_ids": "['Qwen2-72B-Instruct_63871']" }
0.404614
Filter_26010
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "celsius_to_kelvin", "kelvin_to_celsius", "convert_temperatures" ]
5
[ [ "convert_temperatures", "celsius_to_fahrenheit" ], [ "convert_temperatures", "celsius_to_kelvin" ], [ "convert_temperatures", "fahrenheit_to_celsius" ], [ "convert_temperatures", "kelvin_to_celsius" ] ]
4
[]
false
[]
false
pytest
true
[]
true
7d7afd1bdf5e51de72e18579aa028d5e0484f1f4
b676ca493c33d3d4ca4405e53189fb1431a1536e
v1.0
instruct
Filter
Filter_26011_I
I want to create a basic blockchain in Python to understand its fundamentals. Can you guide me on how to do this?
import hashlib import time class Block: def __init__(self, index, previous_hash, timestamp, data, hash): self.index = index self.previous_hash = previous_hash self.timestamp = timestamp self.data = data self.hash = hash def calculate_hash(index, previous_hash, timestamp, da...
from solution import Block, calculate_hash, create_genesis_block, create_new_block, is_valid_new_block def test_create_genesis_block(): genesis_block = create_genesis_block() assert genesis_block.index == 0 assert genesis_block.previous_hash == "0" assert genesis_block.data == "Genesis Block" asser...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, previous_hash, timestamp, data, hash):\n self.index = index\n self.previous_hash = previous_hash\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026011", "row_id": 26011, "seed_ids": "['Qwen2-72B-Instruct_63872']" }
0.352325
Filter_26011
I
[ "calculate_hash", "create_genesis_block", "create_new_block", "is_valid_new_block" ]
4
[ [ "create_genesis_block", "calculate_hash" ], [ "create_new_block", "calculate_hash" ], [ "is_valid_new_block", "calculate_hash" ] ]
3
[]
false
[ "Block" ]
true
pytest
true
[]
true
0e5c2f341a3348a82c8ad945b2a2ab6b230c8a73
776ff77120c89831755d0288df9110c9a3877e01
v1.0
instruct
Filter
Filter_26036_I
Write a Python program to print a dictionary where the keys are prime numbers between 1 and 1000 (both included) and the values are the squares of the keys. Additionally, ensure that the program uses a function to check for prime numbers, and the program should also include error handling for potential invalid input.
def is_prime(n): """ Check if the number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def generate_prime_squa...
from solution import is_prime, generate_prime_square_dict def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(6) == False assert is_prime(7) == True assert is_prime(11) == True assert is_prime(...
[ { "docstring": "Check if the number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a dictionary where keys are prime numbers between `start` and `end` (both inclusive)\nand values are the squ...
[ 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 Check if a number n 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_1
{ "original_instruction": "", "prompt_id": "00026036", "row_id": 26036, "seed_ids": "['Qwen2-72B-Instruct_63922']" }
0.595207
Filter_26036
I
[ "is_prime", "generate_prime_square_dict" ]
2
[ [ "generate_prime_square_dict", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3cc0799aeb7f4d640894086c0260c7024df681e2
992ea45ec4cb57037004343d157a6d28c7cbd253
v1.0
instruct
Filter
Filter_26045_I
I have 500 URLs from various websites from which I want to scrape product information like product name, price, description, and image URLs. The websites are all e-commerce sites but have different structures. The product data is in HTML format and I need the output in CSV format for further analysis. Can you help me w...
import requests from bs4 import BeautifulSoup import pandas as pd from random import randint from time import sleep from fake_useragent import UserAgent import logging # Set up logging logging.basicConfig(level=logging.INFO, filename='scraping.log', filemode='a', format='%(name)s - %(levelname)s - %(message)s') def g...
from solution import get_headers, parse_html, scrape_product_info, scrape_urls, save_to_csv def test_get_headers(): headers = get_headers() assert 'User-Agent' in headers def test_parse_html(): html_content = ''' <div class="product-name">Sample Product</div> <div class="price">$10.00</div> <d...
[ { "docstring": null, "function_declaration": "def get_headers():", "function_name": "get_headers", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def parse_html(html_content):", "function_name": "parse_html", "parameter_list": "(html_content)" }, { ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nimport pandas as pd\nimport random\nimport time\nimport csv\n\ndef fetch_product_info(url):\n headers = {\n 'User-Agent': 'Mozilla/5.0...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026045", "row_id": 26045, "seed_ids": "['Qwen2-72B-Instruct_63938']" }
0.657898
Filter_26045
I
[ "get_headers", "parse_html", "scrape_product_info", "scrape_urls", "save_to_csv" ]
5
[ [ "scrape_product_info", "get_headers" ], [ "scrape_product_info", "parse_html" ], [ "scrape_urls", "scrape_product_info" ] ]
3
[]
false
[]
false
pytest
true
[ "bs4", "fake_useragent", "pandas", "requests" ]
false
f6bcaffebd7bf726ca91af7b42359abb51b6ac4d
e3c89223a9f37d68518e3694e041394f2fc901cd
v1.0
instruct
Filter
Filter_26055_I
Given the following list of numbers [1,2,3,4,5,6,7,8,9,10], write a Python function to separate them into two different lists: one for prime numbers and one for composite numbers. Make sure to check the time complexity of your solution and optimize it to the best of your ability.
def is_prime(n): """ Check if n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return Tr...
from solution import is_prime, separate_prime_composite def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(20) == False assert is_prime(1) == False assert is_prime...
[ { "docstring": "Check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Separate the given list into prime and composite numbers.", "function_declaration": "def separate_prime_composite(numbers):"...
[ 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 n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026055", "row_id": 26055, "seed_ids": "['Qwen2-72B-Instruct_63961']" }
0.588325
Filter_26055
I
[ "is_prime", "separate_prime_composite" ]
2
[ [ "separate_prime_composite", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32dfc5db481149b2bb46371071a3c30acd699773
8198826bcf57c2f55cdb772900b8f6b0acdf0943
v1.0
instruct
Filter
Filter_26075_I
Write a python function to print the multiplication table of a given number, but only for the numbers that are prime and less than or equal to the given number. The function should also return the sum of all the prime numbers in the multiplication table.
def is_prime(n): """ Check if the number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def prime_multiplication_table_and_sum(num): """ Print the multiplication table for prime numbers less t...
from solution import is_prime, prime_multiplication_table_and_sum def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) def test_prime_multiplication_table_and_sum_with_10(capsys): result = prime_multiplication_table_and_sum...
[ { "docstring": "Check if the number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Print the multiplication table for prime numbers less than or equal to num\nand return the sum of these prime numbers.", "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026075", "row_id": 26075, "seed_ids": "['Qwen2-72B-Instruct_64000']" }
0.62363
Filter_26075
I
[ "is_prime", "prime_multiplication_table_and_sum" ]
2
[ [ "prime_multiplication_table_and_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06176962bb5a443142d2285e1c0aac7bc4cecd36
5f91abb6d6121cf4fdd39437bf695842cd428393
v1.0
instruct
Filter
Filter_26076_I
Use PyTorch to write a function that predicts a class label based on five numerical features. Additionally, implement a data preprocessing step that includes normalization, and add error handling for potential missing values. You are provided with an erroneous code as reference below which lacks these essential compone...
import torch import torch.nn as nn import torch.optim as optim import numpy as np from sklearn.preprocessing import StandardScaler class SimpleNN(nn.Module): def __init__(self): super(SimpleNN, self).__init__() self.fc1 = nn.Linear(5, 10) self.fc2 = nn.Linear(10, 2) def forward...
import numpy as np import pytest from solution import predict, SimpleNN def test_preprocess_data_valid(): valid_data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0], [5.0, 4.0, 3.0, 2.0, 1.0]]) assert predict(valid_data).shape == (2,) def test_preprocess_data_with_nan(): data_with_nan = n...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\n\nclass SimpleNN(nn.Module):\n def __init__(self):\n super(SimpleNN, self).__init__()\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026076", "row_id": 26076, "seed_ids": "['Qwen2-72B-Instruct_64001']" }
0.478493
Filter_26076
I
[ "preprocess_data", "predict" ]
2
[ [ "predict", "preprocess_data" ] ]
1
[]
false
[ "SimpleNN" ]
true
pytest
true
[ "numpy", "sklearn", "torch" ]
false
b69ae8882f8d713cc5f038bd10c6773fdbe9a240
e905408d536d1b10a555048d117e5ca55d2a5a16
v1.0
instruct
Filter
Filter_26083_I
Take a positive integer input greater than 1 and output the Fibonacci sequence up to that number, but only include the Fibonacci numbers that are also prime numbers. Additionally, make sure that the program runs in O(n) time complexity, where n is the input number.
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 fibonacci_primes_up_to_n(n...
from solution import is_prime, fibonacci_primes_up_to_n 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(12) == False def test_fibonacci_primes_up_to_10(): asser...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def fibonacci_primes_up_to_n(n):", "function_name": "fibonacci_primes_up_to_n", "parameter_list": "(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 number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026083", "row_id": 26083, "seed_ids": "['Qwen2-72B-Instruct_64009']" }
0.744146
Filter_26083
I
[ "is_prime", "fibonacci_primes_up_to_n" ]
2
[ [ "fibonacci_primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb1cc823e89dda3f142881c58f4080a8e019249e
5c3de13f38f3196509ece65ab53d226797bc6f1f
v1.0
instruct
Filter
Filter_26109_I
I want to create a program in Python that can check if a given list is sorted. How can I do this? Also, how can I modify the program to sort the list if it is not already sorted?
def is_sorted(lst): """ Checks if the given list is sorted in ascending order. Parameters: lst (list): The list to check. Returns: bool: True if the list is sorted, False otherwise. """ return all(lst[i] <= lst[i+1] for i in range(len(lst) - 1)) def sort_list_if_not_sorted(lst): "...
from solution import is_sorted, sort_list_if_not_sorted def test_is_sorted_with_sorted_list(): assert is_sorted([1, 2, 3, 4, 5]) == True def test_is_sorted_with_unsorted_list(): assert is_sorted([5, 3, 1, 4, 2]) == False def test_is_sorted_with_empty_list(): assert is_sorted([]) == True def test_is_sort...
[ { "docstring": "Checks if the given list is sorted in ascending order.\n\nParameters:\nlst (list): The list to check.\n\nReturns:\nbool: True if the list is sorted, False otherwise.", "function_declaration": "def is_sorted(lst):", "function_name": "is_sorted", "parameter_list": "(lst)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_sorted(lst):\n \"\"\"\n Check if the given list is sorted in non-decreasing order.\n \n Args:\n lst (list): List of elements to check.\n \n Returns:\n bool: True...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026109", "row_id": 26109, "seed_ids": "['Qwen2-72B-Instruct_64050']" }
0.728079
Filter_26109
I
[ "is_sorted", "sort_list_if_not_sorted" ]
2
[ [ "sort_list_if_not_sorted", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98592a3fc9b1600a9db5c857c48b8166f4b2bc08
222465b49234da78cb868eb7a4cf55df7f0a0060
v1.0
instruct
Filter
Filter_26122_I
Create a method to print all the prime numbers up to n, but the method should be written using a recursive approach instead of an iterative one.
def is_prime(num, divisor=None): """ Helper function to check if a number is prime. A number is prime if it has no divisors other than 1 and itself. """ if divisor is None: divisor = num - 1 if num <= 1: return False if divisor == 1: return True if num % divisor =...
from io import StringIO import sys from solution import is_prime, print_primes_recursive 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(...
[ { "docstring": "Helper function to check if a number is prime.\nA number is prime if it has no divisors other than 1 and itself.", "function_declaration": "def is_prime(num, divisor=None):", "function_name": "is_prime", "parameter_list": "(num, divisor=None)" }, { "docstring": "Prints 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(num, divisor=None):\n \"\"\"\n Helper function to check if a number is prime using recursion.\n \"\"\"\n if num <= 1:\n return False\n if divisor is None:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026122", "row_id": 26122, "seed_ids": "['Qwen2-72B-Instruct_64071']" }
0.672319
Filter_26122
I
[ "is_prime", "print_primes_recursive" ]
2
[ [ "print_primes_recursive", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1bb8197752c671162c0eccbaf17f84443846138a
c47131018cdc7e9b7206951d42608d9c7f8f77b7
v1.0
instruct
Filter
Filter_26140_I
With reference to the given observation, develop a recursive function to navigate through every node of a binary tree with the structure like the one mentioned below, and print the node values in pre-order traversal. Additionally, implement a functionality to calculate and return the sum of all the node values in the r...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def pre_order_traversal(node): if node is None: return print(node.value) pre_order_traversal(node.left) pre_order_traversal(node.right) def sum...
from solution import TreeNode, pre_order_traversal, get_sum_of_right_subtree def test_pre_order_traversal(capfd): # Construct the tree # 1 # / \ # 2 3 # / \ \ # 4 5 6 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left =...
[]
[ 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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef pre_order_traversal(root):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026140", "row_id": 26140, "seed_ids": "['Qwen2-72B-Instruct_64101']" }
0.568187
Filter_26140
I
[ "pre_order_traversal", "sum_of_right_subtree", "get_sum_of_right_subtree" ]
3
[ [ "get_sum_of_right_subtree", "sum_of_right_subtree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
17f9716734dff81f53a70178a69b4f4534cbb2b2
63b1e4e91509f25a0c9b2ccf07cf5e83b2da19ae
v1.0
instruct
Filter
Filter_26142_I
Rewrite the following python code to an equivalent code using lambda and sorted function, also add error handling to handle cases where the input list might contain non-integer values.
def sort_list(input_list): """ Sorts the list in increasing order. """ # Ensure all elements are integers try: return sorted(input_list, key=lambda x: int(x) if isinstance(x, int) else _raise(ValueError("List must contain only integers"))) except ValueError as e: return str(e) d...
from solution import sort_list def test_sort_list_with_integers(): assert sort_list([3, 1, 4, 1, 5, 9]) == [1, 1, 3, 4, 5, 9] def test_sort_list_with_negative_integers(): assert sort_list([2, -5, 3, -7, 0]) == [-7, -5, 0, 2, 3] def test_sort_list_with_mixed_non_integer(): assert sort_list([3, 'a', 1]...
[ { "docstring": "Sorts the list in increasing order.", "function_declaration": "def sort_list(input_list):", "function_name": "sort_list", "parameter_list": "(input_list)" }, { "docstring": null, "function_declaration": "def _raise(exception):", "function_name": "_raise", "paramet...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_list(input_list):\n \"\"\"\n Sorts a list of integers in ascending order.\n Handles errors if the list contains non-integer values.\n \"\"\"\n try:\n # Using lam...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026142", "row_id": 26142, "seed_ids": "['Qwen2-72B-Instruct_64103']" }
0.732849
Filter_26142
I
[ "sort_list", "_raise" ]
2
[ [ "sort_list", "_raise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fed83bbc0bb9d0dfbd2afa673a8b87f9fa8f02fc
dc93d25e515984fa09dbb44bd57d44c8b0fba5df
v1.0
instruct
Filter
Filter_26146_I
Develop a Python program to display odd numbers from 11 to 100 that are prime numbers.
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def odd_prime_numbers_betwe...
from solution import is_prime, odd_prime_numbers_between_11_and_100 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(11) == True assert is_prime(4) == False assert is_prime(9) == False assert is_prime(97) == True assert is_prime(1) == False def tes...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of odd numbers that are prime in the range from 11 to 100.", "function_declaration": "def odd_prime_nu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n retur...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026146", "row_id": 26146, "seed_ids": "['Qwen2-72B-Instruct_64107']" }
0.599158
Filter_26146
I
[ "is_prime", "odd_prime_numbers_between_11_and_100" ]
2
[ [ "odd_prime_numbers_between_11_and_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b0021340279ee40fb99321c32280505b623f795
06cf5e1b701e9292e2bd76addfa78bece7772ae6
v1.0
instruct
Filter
Filter_26170_I
Write a Python program that takes a list of integers and returns a new list containing only the prime numbers from the original list. The program should also display the number of prime numbers in the resulting list. Additionally, the program should validate that all input integers are positive before processing.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Takes a list of integers and returns a new list...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(20) == False assert is_prime(1) == False # 1 is not a prime number assert is_prime(-3) == False # ...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a new list containing only the prime numbers from the original list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026170", "row_id": 26170, "seed_ids": "['Qwen2-72B-Instruct_64143']" }
0.666044
Filter_26170
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30921893f5cc8339507727f6287218440ab3f5c3
9282073d0576d9d56120806c02223e77daa009c4
v1.0
instruct
Filter
Filter_26195_I
Develop a program that identifies the operating system, the version and the architecture (32 or 64 bits) of the system it's being run on. Moreover, your program should also detect if it's running on a physical machine or virtual machine. Lastly, implement a feature to detect the current user and his/her privilege level...
import platform import os import ctypes import sys import getpass def get_system_info(): system_info = { "os": platform.system(), "version": platform.version(), "architecture": platform.architecture()[0], "machine": platform.machine(), "node": platform.node() } if h...
from solution import get_system_info, is_admin def test_get_system_info_structure(): info = get_system_info() keys = ['os', 'version', 'architecture', 'machine', 'node', 'physical_or_virtual', 'current_user', 'is_admin'] for key in keys: assert key in info def test_architecture(): info = get_s...
[ { "docstring": null, "function_declaration": "def get_system_info():", "function_name": "get_system_info", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def is_admin():", "function_name": "is_admin", "parameter_list": "()" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import platform\nimport os\nimport ctypes\nimport sys\nimport getpass\n\ndef get_system_info():\n system_info = {\n \"os\": platform.system(),\n \"version\": platform.version(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026195", "row_id": 26195, "seed_ids": "['Qwen2-72B-Instruct_64176']" }
0.48082
Filter_26195
I
[ "get_system_info", "is_admin" ]
2
[ [ "get_system_info", "is_admin" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1663f4adaf469305f71b88d1696f861b1dd3fe27
dcb8c3b6c5359c3c14b327078c2582eddd155a12
v1.0
instruct
Filter
Filter_26200_I
Construct a Python function to simulate the traditional two-player game of Noughts and Crosses, also known as Tic-Tac-Toe. The implemented function should also feature an AI opponent with different levels of difficulty: beginner(user wins most of the time), intermediate(equal chance of user or AI winning), and advanced...
import random def create_board(): return [['' for _ in range(3)] for _ in range(3)] def print_board(board): for row in board: print('|'.join(cell or ' ' for cell in row)) def check_winner(board, player): # Check rows, columns, and diagonals win_conditions = ( [board[0][0], board[0][1]...
from solution import create_board, check_winner, is_full, get_valid_moves def test_create_board(): board = create_board() assert board == [['', '', ''], ['', '', ''], ['', '', '']] assert len(board) == 3 assert all(len(row) == 3 for row in board) def test_check_winner(): board = [ ['X', 'X...
[ { "docstring": null, "function_declaration": "def create_board():", "function_name": "create_board", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def print_board(board):", "function_name": "print_board", "parameter_list": "(board)" }, { "docstri...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef print_board(board):\n for row in board:\n print(\" | \".join(row))\n print(\"-\" * 5)\n\ndef check_winner(board, player):\n win_conditions = [\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026200", "row_id": 26200, "seed_ids": "['Qwen2-72B-Instruct_64182']" }
0.488049
Filter_26200
I
[ "create_board", "print_board", "check_winner", "is_full", "get_valid_moves", "minimax", "ai_move", "advanced_move", "play_game" ]
9
[ [ "advanced_move", "get_valid_moves" ], [ "advanced_move", "minimax" ], [ "ai_move", "advanced_move" ], [ "ai_move", "get_valid_moves" ], [ "minimax", "check_winner" ], [ "minimax", "get_valid_moves" ], [ "minimax", "is_full" ], [ ...
12
[]
false
[]
false
pytest
true
[]
true
66774e9621237f67aeffa2f8d905d8cecbde445e
de8a6350c29f110cd4ae848ff74ea0c826637a1c
v1.0
instruct
Filter
Filter_26202_I
Create a method that accepts an integer parameter n and provides a four-dimensional array of size nxnxnxn made up of prime numbers starting from 2 up to the nth power of 4 in a sequence that is not only uniform but also ensures that each dimensionstitially, the numbers are in ascending order. The Algorithm should sieve...
def is_prime(num): """ Returns True if num is a prime number, otherwise False. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: ...
from solution import create_prime_4d_array, is_prime def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) def test_generate_primes(): primes = generate_primes(10) assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] d...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers up to the given limit.", "function_declaration": "def generate...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026202", "row_id": 26202, "seed_ids": "['Qwen2-72B-Instruct_64188']" }
0.545978
Filter_26202
I
[ "is_prime", "generate_primes", "create_prime_4d_array" ]
3
[ [ "create_prime_4d_array", "generate_primes" ], [ "generate_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
edc62ea474ceb182597789b89f377a2bb065ed81
68f8c9a61644f8d38995aeedc11929203d8e2b25
v1.0
instruct
Filter
Filter_26225_I
You are a magnificent AI professor and I am your student. I am trying to learn advanced topics in NLP. Could you teach me how to fine-tune BERT for text classification using PyTorch and Transformers?
import torch from torch.utils.data import DataLoader, Dataset from transformers import BertTokenizer, BertForSequenceClassification, AdamW class TextClassificationDataset(Dataset): def __init__(self, texts, labels, tokenizer, max_len): self.texts = texts self.labels = labels self.tokenizer ...
from solution import train_model, TextClassificationDataset import pytest def test_dataset(): texts = ["Hello world!", "Love this!", "Hate this!"] labels = [0, 1, 0] tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') dataset = TextClassificationDataset(texts, labels, tokenizer, max_len=128)...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Below is a simplified outline to teach how to fine-tune BERT for text classification using PyTorch and Transformers\n\nimport torch\nfrom torch.utils.data import DataLoader, Dataset\nfrom tr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026225", "row_id": 26225, "seed_ids": "['Qwen2-72B-Instruct_64222']" }
0.408314
Filter_26225
I
[ "train_epoch", "eval_model", "train_model" ]
3
[ [ "train_model", "train_epoch" ] ]
1
[]
false
[ "TextClassificationDataset" ]
true
pytest
true
[ "torch", "transformers" ]
false
b50493ac5d5edafde31464a519188018440d11e7
9179d3ef2633b34a7417436bbba216ce0c2feab1
v1.0
instruct
Filter
Filter_26242_I
Given a set of numbers, let's say [15, 39, 8, 2, 7, 11]. I want to create a function that can rearrange these numbers so that I get the maximum possible number from them. Can you help me write this function in Python? I also want to understand the complexity of this solution.
from functools import cmp_to_key def compare(a, b): """ Custom comparator: returns -1 if a should come before b, 1 otherwise. """ if a + b > b + a: return -1 elif a + b < b + a: return 1 else: return 0 def largest_possible_number(nums): """ Rearranges a list of ...
from solution import largest_possible_number def test_regular_case(): assert largest_possible_number([15, 39, 8, 2, 7, 11]) == "873921511" def test_all_single_digits(): assert largest_possible_number([1, 2, 3, 4, 5, 6, 7, 8, 9]) == "987654321" def test_with_zeros(): assert largest_possible_number([3, 30,...
[ { "docstring": "Custom comparator: returns -1 if a should come before b, 1 otherwise.", "function_declaration": "def compare(a, b):", "function_name": "compare", "parameter_list": "(a, b)" }, { "docstring": "Rearranges a list of numbers so that the largest possible number is formed.\n\nArgs:...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef compare(x, y):\n \"\"\"\n Helper comparison function to decide the order based on concatenated results.\n \"\"\"\n if x + y > y + x:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026242", "row_id": 26242, "seed_ids": "['Qwen2-72B-Instruct_64249']" }
0.671889
Filter_26242
I
[ "compare", "largest_possible_number" ]
2
[ [ "largest_possible_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
020bc28c38316df5a84c512948d64f73d4c4a458
ab806a4d3c3313b590f175234c6b435d6cc84510
v1.0
instruct
Filter
Filter_26265_I
Create a Python dictionary that stores square roots of prime numbers from 1 to 15. Additionally, implement functionality for checking if the input number is prime.
import math def is_prime(n): """ Checks 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(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def p...
from solution import is_prime, prime_square_roots def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False def test_prime_square_roots(): expected = {2: math.s...
[ { "docstring": "Checks if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a dictionary with prime numbers as keys and their square roots as values, \nup to the given upper limit (inclu...
[ 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_prime(num):\n \"\"\"\n Returns True if the number is prime, else False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026265", "row_id": 26265, "seed_ids": "['Qwen2-72B-Instruct_64286']" }
0.612947
Filter_26265
I
[ "is_prime", "prime_square_roots" ]
2
[ [ "prime_square_roots", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
32bf6a453f4417c47137c7e793ff0c79e366278e
3b114030e7814b988e8a22bda50b94675e5c9873
v1.0
instruct
Filter
Filter_26275_I
Write a Python program that illustrates the concept of variable scoping, demonstrating the differences between local, enclosing, and global variables.
# Global variable global_var = "I am a global variable" def outer_function(): # Enclosing variable enclosing_var = "I am an enclosing variable" def inner_function(): # Local variable local_var = "I am a local variable" print(local_var) # Accessing local variable...
from solution import demonstrate_scoping def test_variable_scoping(capfd): demonstrate_scoping() # Running the function to demonstrate scoping out, _ = capfd.readouterr() # Capturing printed output # The expected output when running demonstrate_scoping expected_output = ( "I am a local v...
[ { "docstring": null, "function_declaration": "def outer_function():", "function_name": "outer_function", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def demonstrate_scoping():", "function_name": "demonstrate_scoping", "parameter_list": "()" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Global variable\nx = \"global\"\n\ndef outer_function():\n # Enclosing variable\n x = \"enclosing\"\n \n def inner_function():\n # Local variable\n x = \"local\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026275", "row_id": 26275, "seed_ids": "['Qwen2-72B-Instruct_64302']" }
0.402912
Filter_26275
I
[ "outer_function", "demonstrate_scoping" ]
2
[ [ "demonstrate_scoping", "outer_function" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f89e4b30aed32bbbc5f7bf226c17c563662d806
30d0fc1320f586f9a8cba86595680eebb18b435d
v1.0
instruct
Filter
Filter_26282_I
Refine the subsequent Python code into a procedure that detects prime numbers from a supplied list, returning a catalogue containing only the prime integers in ascending sequence.
def is_prime(n): """ Check whether a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False retur...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-3) == False def test_filter_primes_mixed_...
[ { "docstring": "Check whether a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters and returns a sorted list of prime numbers from the provided list.", "function_declaration": "def filter...
[ 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 Determines if the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True # 2 is the onl...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026282", "row_id": 26282, "seed_ids": "['Qwen2-72B-Instruct_64313']" }
0.659806
Filter_26282
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
03ef5fc880b787da34577df79a26e4c17d012976
5902bf387278e1b8963b6edc9e6b9a5c49873eac
v1.0
instruct
Filter
Filter_26283_I
Design a Python function that can identify prime numbers from a set of numbers. This function should be designed to handle errors and exceptions. The input will be a list of numbers, which can include negative numbers, zero, decimals, strings, and complex numbers. The function should verify the validity of the input an...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import identify_primes def test_identify_primes_with_valid_integers(): assert identify_primes([2, 3, 4, 5, 10]) == {2: 0, 3: 1, 5: 3} def test_identify_primes_with_negative_and_zero(): assert identify_primes([-1, 0, 1, 2, 3]) == {2: 3, 3: 4} def test_identify_primes_with_decimals_and_strings():...
[ { "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": "Identifies prime numbers in the given list of numbers.\n\nArgs:\nnumbers (list): List of numbers which c...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026283", "row_id": 26283, "seed_ids": "['Qwen2-72B-Instruct_64314']" }
0.725538
Filter_26283
I
[ "is_prime", "identify_primes" ]
2
[ [ "identify_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2b85cabb4f8131140f18816a5680479c0a3080a0
685cb0f0a692222fdbce4dbdf5c10b683972da5b
v1.0
instruct
Filter
Filter_26286_I
I am trying to find the best way to generate a unique ID for a new user in my Python application. The ID should be a combination of the user's first name, last name, and a sequence number. Can you help me implement a function that takes the first name, last name, and a sequence number as input and returns the unique ID...
def generate_unique_id(first_name, last_name, sequence_number): """ Generates a unique ID based on given first name, last name, and sequence number. Args: first_name (str): The first name of the user. last_name (str): The last name of the user. sequence_number (int): The sequence number. ...
from solution import generate_unique_id, validate_unique_id def test_generate_unique_id(): assert generate_unique_id("John", "Doe", 1) == "John_Doe_1" assert generate_unique_id("Jane", "Smith", 0) == "Jane_Smith_0" assert generate_unique_id("Alice", "Johnson", 999) == "Alice_Johnson_999" assert generat...
[ { "docstring": "Generates a unique ID based on given first name, last name, and sequence number.\n\nArgs:\nfirst_name (str): The first name of the user.\nlast_name (str): The last name of the user.\nsequence_number (int): The sequence number.\n\nReturns:\nstr: The unique ID generated.", "function_declaratio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_user_id(first_name, last_name, sequence_number):\n \"\"\"\n Generates a unique ID based on the first name, last name, and sequence number.\n \n Args:\n first_name (...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026286", "row_id": 26286, "seed_ids": "['Qwen2-72B-Instruct_64319']" }
0.51175
Filter_26286
I
[ "generate_unique_id", "validate_unique_id" ]
2
[ [ "validate_unique_id", "generate_unique_id" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1351a75175fd89a728ca86b191aace996e2b2d2
adb5013456314badfbadfbdf650b4c2dd82211cc
v1.0
instruct
Filter
Filter_26294_I
Create a function that takes two parameters, a number and a string, and returns an array with those two values in it. Additionally, the function should check if the provided number is a prime number and if the string is a palindrome. The function should return the array only if both conditions are met; otherwise, retur...
def is_prime(num): """ Checks if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def is_palindrome(s): """ Checks if a string is a palindrome. """ return s == ...
from solution import create_array_if_prime_and_palindrome def test_prime_and_palindrome(): assert create_array_if_prime_and_palindrome(7, "racecar") == [7, "racecar"] assert create_array_if_prime_and_palindrome(11, "level") == [11, "level"] def test_non_prime_and_palindrome(): assert create_array_if_prime...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Checks if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_...
[ 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 Helper function to check if the number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026294", "row_id": 26294, "seed_ids": "['Qwen2-72B-Instruct_64329']" }
0.594837
Filter_26294
I
[ "is_prime", "is_palindrome", "create_array_if_prime_and_palindrome" ]
3
[ [ "create_array_if_prime_and_palindrome", "is_palindrome" ], [ "create_array_if_prime_and_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8f8ac0c7fa1f869687d148849a2e0c4891a05ada
34692ce517ba263ac6fb58fa264af7dc455f0fb3
v1.0
instruct
Filter
Filter_26297_I
Modify the following python code using a decorator to add a delay of 1 second before executing the function.
import time from functools import wraps def delay(seconds): """ Decorator that delays executing the function by a specified number of seconds. """ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): time.sleep(seconds) return func(*args, **kwargs) ...
import time from solution import example_function def test_delay_decorator(): start_time = time.time() result = example_function() end_time = time.time() assert result == "Function executed" assert end_time - start_time >= 1.0
[ { "docstring": "Decorator that delays executing the function by a specified number of seconds.", "function_declaration": "def delay(seconds):", "function_name": "delay", "parameter_list": "(seconds)" }, { "docstring": "A simple function to demonstrate the delay decorator.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nfrom functools import wraps\n\ndef delay(seconds):\n \"\"\"\n Decorator that delays execution of the function it decorates.\n \"\"\"\n def decorator(func):\n @w...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026297", "row_id": 26297, "seed_ids": "['Qwen2-72B-Instruct_64335']" }
0.457219
Filter_26297
I
[ "delay", "example_function" ]
2
[ [ "example_function", "delay" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bee380893c24053cbfdbed6ffd9be38d91d8093e
8ca8ef2950e14c3f2eab63f45a25b668af9f964b
v1.0
instruct
Filter
Filter_26306_I
Develop an algorithm that performs a ternary search on a balanced ternary tree. Additionally, incorporate functionality to handle cases when the tree is not balanced. The function should adjust the tree to maintain balance (using AVL tree rules) before performing the search.
class Node: def __init__(self, key): self.key = key self.left = None self.mid = None self.right = None self.height = 1 def height(node): if node is None: return 0 return node.height def update_height(node): if node is not None: node.height = 1 + ...
import pytest from solution import Node, insert, balanced_ternary_search def test_balanced_ternary_search(): root = None # Inserting nodes keys = [50, 30, 70, 20, 40, 60, 80, 50, 50, 50] for key in keys: root = insert(root, key) # Searching existing and non-existing keys assert bal...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.middle = None\n self.right = None\n self.height = 1 # For bal...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026306", "row_id": 26306, "seed_ids": "['Qwen2-72B-Instruct_64351']" }
0.611861
Filter_26306
I
[ "height", "update_height", "balance_factor", "rotate_left", "rotate_right", "balance", "insert", "ternary_search", "balanced_ternary_search" ]
9
[ [ "balance", "balance_factor" ], [ "balance", "rotate_left" ], [ "balance", "rotate_right" ], [ "balance", "update_height" ], [ "balance_factor", "height" ], [ "balanced_ternary_search", "balance" ], [ "balanced_ternary_search", "ternar...
11
[]
false
[ "Node" ]
true
pytest
true
[]
true
78ee4dd9eb95624c77fddb9e43e613d05aaba432
8073608c24db5e782ed353ec7eeb1cc42fab85ea
v1.0
instruct
Filter
Filter_26320_I
Create a function in Python that takes an integer input and returns the sum of the first n prime numbers. The function should handle cases where n is not a positive integer and return an appropriate error message. The function should also handle cases where n is a very large number (e.g. greater than 10^6) efficiently.
import math def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return ...
from solution import sum_of_first_n_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(-3) == False def test_sum_of_first_n_primes(): assert sum_of_f...
[ { "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 sum of the first n prime numbers. If n is not a positive integer,\nreturns an appropriate error...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026320", "row_id": 26320, "seed_ids": "['Qwen2-72B-Instruct_64374']" }
0.684108
Filter_26320
I
[ "is_prime", "sum_of_first_n_primes" ]
2
[ [ "sum_of_first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4a7e76b3f824d0fc694e67b9e0db692fe92ef64f
76c2f3e39b15d5670100acb2e87a0bcee0206cf5
v1.0
instruct
Filter
Filter_26329_I
How do I find the Fibonacci sequence in a given list of numbers using Python?
def is_fibonacci(n): """ Helper function to check if a number is a Fibonacci number. """ if n < 0: return False # A number is a Fibonacci number if and only 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_sq...
from solution import find_fibonacci_numbers def test_find_fibonacci_numbers_with_fibonacci_numbers(): assert find_fibonacci_numbers([0, 1, 2, 3, 5, 8, 13, 21, 34]) == [0, 1, 2, 3, 5, 8, 13, 21, 34] def test_find_fibonacci_numbers_without_fibonacci_numbers(): assert find_fibonacci_numbers([4, 6, 7, 9, 10]) == ...
[ { "docstring": "Helper function to check if a number is a Fibonacci number.", "function_declaration": "def is_fibonacci(n):", "function_name": "is_fibonacci", "parameter_list": "(n)" }, { "docstring": "Helper function to check if a number is a perfect square.", "function_declaration": "d...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_fibonacci(n):\n \"\"\"\n Check if a given number 'n' is a Fibonacci number.\n A number 'n' is a Fibonacci number if and only if one (or both) of\n (5*n^2 + 4) or (5*n^2 - 4)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026329", "row_id": 26329, "seed_ids": "['Qwen2-72B-Instruct_64391']" }
0.642035
Filter_26329
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
d88c2d9a7a1d2e192625e1d89ba06cb7680960ce
6a97b2d2756c6a351e6b6414ff330a1f8c56aec8
v1.0
instruct
Filter
Filter_26350_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): """ Computes the factorial of a provided integer n using recursion. """ if n == 0 or n == 1: return 1 return n * recursive_factorial(n - 1) def safe_factorial(n): """ Validates the input and computes the factorial using recursion if valid. Returns an ...
from solution import recursive_factorial, safe_factorial def test_recursive_factorial_positive(): assert recursive_factorial(5) == 120 assert recursive_factorial(0) == 1 assert recursive_factorial(1) == 1 def test_recursive_factorial_edge(): assert recursive_factorial(10) == 3628800 def test_safe_fac...
[ { "docstring": "Computes the factorial of a provided integer n using recursion.", "function_declaration": "def recursive_factorial(n):", "function_name": "recursive_factorial", "parameter_list": "(n)" }, { "docstring": "Validates the input and computes the factorial using recursion if valid....
[ 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 Returns the factorial of a positive integer n using recursion.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n return n * factorial_re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026350", "row_id": 26350, "seed_ids": "['Qwen2-72B-Instruct_64427']" }
0.666704
Filter_26350
I
[ "recursive_factorial", "safe_factorial" ]
2
[ [ "safe_factorial", "recursive_factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87ac1934989afffc7ff80f0b007ed9a0f5ceb7f0
89a092ca4f532c621749cda7fa18a71fa79c9a62
v1.0
instruct
Filter
Filter_26354_I
Create a Monte Carlo simulation using Python to estimate the value of Pi. Your simulation should take into account the convergence of the estimated value over a large number of iterations. Additionally, implement a function that calculates the error between the estimated value of Pi and the actual value of Pi (3.141592...
import random import matplotlib.pyplot as plt def monte_carlo_pi_simulation(num_points): """ Perform a Monte Carlo simulation to estimate the value of Pi. Args: num_points (int): The number of random points to generate. Returns: float: Estimated value of Pi. """ inside_circle ...
from solution import monte_carlo_pi_simulation, error_between_estimates def test_monte_carlo_pi_simulation(): estimate = monte_carlo_pi_simulation(10000) assert 3.0 < estimate < 3.25 # A rough estimate, actual test may vary based on random points. def test_error_between_estimates(): estimated_pi = 3.1 ...
[ { "docstring": "Perform a Monte Carlo simulation to estimate the value of Pi.\n\nArgs:\n num_points (int): The number of random points to generate.\n\nReturns:\n float: Estimated value of Pi.", "function_declaration": "def monte_carlo_pi_simulation(num_points):", "function_name": "monte_carlo_pi_s...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport math\nimport matplotlib.pyplot as plt\n\ndef monte_carlo_pi(num_points: int) -> float:\n \"\"\"\n Performs the Monte Carlo simulation to estimate the value of Pi.\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026354", "row_id": 26354, "seed_ids": "['Qwen2-72B-Instruct_64434']" }
0.496045
Filter_26354
I
[ "monte_carlo_pi_simulation", "error_between_estimates", "plot_error_convergence" ]
3
[ [ "plot_error_convergence", "error_between_estimates" ], [ "plot_error_convergence", "monte_carlo_pi_simulation" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
78fad9ae2c8e4e1cdf07652806ff8834c05e3333
65a498b4464e1d514325b96a21fdf59df281f7e2
v1.0
instruct
Filter
Filter_26362_I
Write a recursive function in Python to calculate the factorial of a given number, but you are not allowed to use any loops or the multiplication operator in your solution.
def add(a, b): """ Adds two numbers without using the + operator. """ while b: carry = a & b a = a ^ b b = carry << 1 return a def factorial(n): """ Returns the factorial of a given number n using recursion, without using any loops or the multiplication operator....
from solution import factorial def test_factorial_0(): assert factorial(0) == 1 def test_factorial_1(): assert factorial(1) == 1 def test_factorial_2(): assert factorial(2) == 2 def test_factorial_3(): assert factorial(3) == 6 def test_factorial_4(): assert factorial(4) == 24 def test_factoria...
[ { "docstring": "Adds two numbers without using the + operator.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Returns the factorial of a given number n using recursion,\nwithout using any loops or the multiplication operator....
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Adds two numbers without using the + operator.\n \"\"\"\n while b:\n carry = a & b\n a = a ^ b\n b = carry << 1\n return a\n\ndef ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026362", "row_id": 26362, "seed_ids": "['Qwen2-72B-Instruct_64445']" }
0.715136
Filter_26362
I
[ "add", "factorial" ]
2
[ [ "factorial", "add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e01c5ca4ef6af8c8af822b7aa75d8eec202ccb3
06368a25b2bb0dd8dbfdf954cba71d0140fd994b
v1.0
instruct
Filter
Filter_26364_I
Given the input list of integers, write a function to find the maximum element in the list. However, you are not allowed to use any built-in sorting functions or any linear scan algorithm to solve this problem. Instead, you need to implement a divide-and-conquer algorithm using a binary tree structure for finding the m...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(nums, start, end): if start > end: return None mid = (start + end) // 2 node = TreeNode(nums[mid]) node.left = build_tree(nums, start, mid - 1) ...
from solution import find_max def test_find_max_positive_integers(): assert find_max([1, 3, 5, 7, 9]) == 9 def test_find_max_negative_integers(): assert find_max([-1, -3, -5, -7, -9]) == -1 def test_find_max_mixed_integers(): assert find_max([-10, 0, 5, 10, 20, 30]) == 30 def test_find_max_single_elemen...
[]
[ 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, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_binary_tree(arr, start, end):\n if start > end:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026364", "row_id": 26364, "seed_ids": "['Qwen2-72B-Instruct_64448']" }
0.692127
Filter_26364
I
[ "build_tree", "find_max_in_tree", "find_max" ]
3
[ [ "find_max", "build_tree" ], [ "find_max", "find_max_in_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
69c96507e3e4686c228deb95ed4f2d92dcec7167
76c4c52ca5f7c38ed2ec8bb47fe4744edbedd4a1
v1.0
instruct
Filter
Filter_26367_I
In Python, write a function that takes a pair of sentences and determines if they are anagrams of each other when punctuations, spaces, letter cases are disregarded, and words are ordered alphabetically. Furthermore, consider an additional condition - if the sentences contain identical sequences of unique words, they s...
import string def clean_sentence(sentence): """ Removes punctuation, converts to lowercase, and sorts the words. """ # Remove punctuation translator = str.maketrans('', '', string.punctuation) cleaned_sentence = sentence.translate(translator) # Convert to lowercase and split into words...
from solution import are_anagrams def test_are_anagrams_identical_sentences(): assert are_anagrams("The wolf is at the door!", "The wolf is at the door!") def test_are_anagrams_anagram_sentences(): assert are_anagrams("The wolf is at the door!", "The door is at the wolf.") def test_are_anagrams_with_punctuat...
[ { "docstring": "Removes punctuation, converts to lowercase, and sorts the words.", "function_declaration": "def clean_sentence(sentence):", "function_name": "clean_sentence", "parameter_list": "(sentence)" }, { "docstring": "Returns True if two sequences are anagrams of each other\nwhile ign...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\ndef normalize_sentence(sentence):\n \"\"\"\n Normalize a given sentence by:\n - Removing punctuations\n - Converting to lowercase\n - Sorting words alphabetical...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026367", "row_id": 26367, "seed_ids": "['Qwen2-72B-Instruct_64453']" }
0.568202
Filter_26367
I
[ "clean_sentence", "are_anagrams" ]
2
[ [ "are_anagrams", "clean_sentence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb9b89c26d95faabd8485ff55c73303dd5c8c5c1
ea42aec401baa3cf8dfcf13483dafbbb1997a92a
v1.0
instruct
Filter
Filter_26368_I
Explain how you can implement a basic neural network using NumPy and what are some of the challenges you might face in the process. Implementing a basic neural network using NumPy would involve various steps, including initializing parameters, defining the model architecture, forward propagation, loss function, backwar...
import numpy as np def sigmoid(Z): return 1 / (1 + np.exp(-Z)) def sigmoid_derivative(Z): return Z * (1 - Z) def initialize_parameters(layers_dims): np.random.seed(1) parameters = {} for l in range(1, len(layers_dims)): parameters['W' + str(l)] = np.random.randn(layers_dims[l], layers_dim...
import numpy as np from solution import (initialize_parameters, forward_propagation, compute_cost, backward_propagation, update_parameters, nn_model, predict) def test_initialize_parameters(): layers_dims = [2, 4, 1] parameters = initialize_parameters(layers_dims) ...
[ { "docstring": null, "function_declaration": "def sigmoid(Z):", "function_name": "sigmoid", "parameter_list": "(Z)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(Z):", "function_name": "sigmoid_derivative", "parameter_list": "(Z)" }, { "docstring...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef initialize_parameters(layers_dims):\n np.random.seed(1)\n parameters = {}\n for l in range(1, len(layers_dims)):\n parameters['W' + str(l)] = np.rando...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026368", "row_id": 26368, "seed_ids": "['Qwen2-72B-Instruct_64455']" }
0.327263
Filter_26368
I
[ "sigmoid", "sigmoid_derivative", "initialize_parameters", "forward_propagation", "compute_cost", "backward_propagation", "update_parameters", "nn_model", "predict" ]
9
[ [ "backward_propagation", "sigmoid_derivative" ], [ "forward_propagation", "sigmoid" ], [ "nn_model", "backward_propagation" ], [ "nn_model", "compute_cost" ], [ "nn_model", "forward_propagation" ], [ "nn_model", "initialize_parameters" ], [ ...
8
[]
false
[]
false
pytest
true
[ "numpy" ]
false
eac6c05effced2746cd59aa238b92effb5dd4166
c2fb6c1299b32d8b1300c64fede002f67542cdbb
v1.0
instruct
Filter
Filter_26377_I
Create a for-loop in Python that iterates through a list of numbers and prints out only the prime numbers in the list that are divisible by 7, without any remainders. The list should contain at least 10000 elements.
def is_prime(n): """ Helper function to 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 ...
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(49) == False # 7*7 def test_print_primes_divisible_by_7(capsys): large_list = list(range(10000, 20000)) p...
[ { "docstring": "Helper function to check if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Iterate through a list of numbers and print the prime numbers that are divisible by 7.\n\n:param num_li...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_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 ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026377", "row_id": 26377, "seed_ids": "['Qwen2-72B-Instruct_64468']" }
0.559298
Filter_26377
I
[ "is_prime", "print_primes_divisible_by_7" ]
2
[ [ "print_primes_divisible_by_7", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c6d26fc04ff8aa7a0d39033b71038f49b53e57e6
4e4b216a9603d074f80ade72b929983eb8244633
v1.0
instruct
Filter
Filter_26397_I
Given two strings, s1, and s2, write a program to check if s2 is a rotation of s1 using only one call to isSubstring function.
def is_rotation(s1, s2): """ Returns True if s2 is a rotation of s1, otherwise returns False. """ if len(s1) != len(s2): return False return is_substring(s1 + s1, s2) def is_substring(s1, s2): """ Checks if s2 is a substring of s1. """ return s2 in s1
from solution import is_rotation def test_is_rotation(): assert is_rotation("waterbottle", "erbottlewat") == True def test_is_not_rotation(): assert is_rotation("waterbottle", "bottlewaterx") == False def test_different_lengths(): assert is_rotation("abc", "abcd") == False def test_empty_strings(): ...
[ { "docstring": "Returns True if s2 is a rotation of s1, otherwise returns False.", "function_declaration": "def is_rotation(s1, s2):", "function_name": "is_rotation", "parameter_list": "(s1, s2)" }, { "docstring": "Checks if s2 is a substring of s1.", "function_declaration": "def is_subs...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_rotation(s1, s2):\n \"\"\"\n Check if s2 is a rotation of s1 using only one call to isSubstring function.\n \"\"\"\n def isSubstring(s1, s2):\n # Check if s2 is a sub...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026397", "row_id": 26397, "seed_ids": "['Qwen2-72B-Instruct_64495']" }
0.678619
Filter_26397
I
[ "is_rotation", "is_substring" ]
2
[ [ "is_rotation", "is_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
287849fb81dd2e1eea5890575ec5f504a2cb1d04
8f9cb583d2db1753d9579e9ac872c7f7bf3fba55
v1.0
instruct
Filter
Filter_26399_I
Write a Python program that calculates the area and perimeter of a triangle given the lengths of its three sides. The program should also check if the given sides can form a valid triangle. If not, it should print an error message.
import math def is_valid_triangle(a, b, c): """ Check if sides a, b, c can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def triangle_area(a, b, c): """ Calculate the area of a triangle with sides a, b, c using Heron's formula. """ s = (a + b + c) / 2 retu...
from solution import is_valid_triangle, triangle_area, triangle_perimeter, triangle_properties def test_is_valid_triangle(): assert is_valid_triangle(3, 4, 5) == True assert is_valid_triangle(1, 1, 2) == False assert is_valid_triangle(5, 5, 5) == True def test_triangle_area(): assert math.isclose(tria...
[ { "docstring": "Check if sides a, b, c can form a valid triangle.", "function_declaration": "def is_valid_triangle(a, b, c):", "function_name": "is_valid_triangle", "parameter_list": "(a, b, c)" }, { "docstring": "Calculate the area of a triangle with sides a, b, c using Heron's formula.", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_triangle(a, b, c):\n \"\"\"\n Checks if the sides a, b, and c can form a valid triangle.\n \"\"\"\n return a + b > c and a + c > b and b + c > a\n\ndef calculate_area(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026399", "row_id": 26399, "seed_ids": "['Qwen2-72B-Instruct_64499']" }
0.80229
Filter_26399
I
[ "is_valid_triangle", "triangle_area", "triangle_perimeter", "triangle_properties" ]
4
[ [ "triangle_properties", "is_valid_triangle" ], [ "triangle_properties", "triangle_area" ], [ "triangle_properties", "triangle_perimeter" ] ]
3
[]
false
[]
false
pytest
true
[]
true
848d186167ea0c5ef42f773bc2962448b23dbc8c
434234d79ff69a235383aa7663acbdfcd3c392f5
v1.0
instruct
Filter
Filter_26405_I
Can you create a Flask route for handling REST requests in Python to add a new car to a database? The route should also include input validation to check for missing or invalid data and return appropriate error messages. Additionally, the route should only allow authorized users to add a new car by checking for a valid...
from flask import Flask, request, jsonify, abort import re app = Flask(__name__) # A mock in-memory database db = [] VALID_API_KEY = "your_valid_api_key" def validate_input(data): required_fields = ["make", "model", "year", "price"] for field in required_fields: if field not in data: ret...
import json from flask import Flask from solution import app, VALID_API_KEY, db, validate_input app.testing = True client = app.test_client() def test_validate_input(): valid_input = { "make": "Toyota", "model": "Corolla", "year": 2020, "price": 20000 } invalid_input_year =...
[ { "docstring": null, "function_declaration": "def validate_input(data):", "function_name": "validate_input", "parameter_list": "(data)" }, { "docstring": null, "function_declaration": "def add_car():", "function_name": "add_car", "parameter_list": "()" } ]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\nCARS_DB = []\nVALID_API_KEYS = {\"valid_api_key_123\"}\n\ndef validate_new_car_data(data):\n required_fields = [\"make\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026405", "row_id": 26405, "seed_ids": "['Qwen2-72B-Instruct_64510']" }
0.526075
Filter_26405
I
[ "validate_input", "add_car" ]
2
[ [ "add_car", "validate_input" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
3e98b40dc76b20ccb8e5d44502afed406fefe095
a73f972e4a798fbc13dbaa15d4e116b7a9fab38d
v1.0
instruct
Filter
Filter_26416_I
Given a positive integer n, write a recursive function to compute the n-th Fibonacci number. Assume you have a function to add two integers.
def add(a, b): """ Returns the sum of a and b. """ return a + b def fibonacci(n): """ Returns the n-th Fibonacci number using recursion. """ if n <= 0: raise ValueError("Input must be a positive integer") elif n == 1: return 0 elif n == 2: return 1 el...
from solution import add, fibonacci def test_add_positive_numbers(): assert add(2, 3) == 5 def test_add_with_zero(): assert add(0, 5) == 5 assert add(5, 0) == 5 def test_add_negative_numbers(): assert add(-1, -1) == -2 def test_add_mixed_sign_numbers(): assert add(-1, 3) == 2 def test_fibonacci...
[ { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Returns the n-th Fibonacci number using recursion.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number recursively.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026416", "row_id": 26416, "seed_ids": "['Qwen2-72B-Instruct_64531']" }
0.688403
Filter_26416
I
[ "add", "fibonacci" ]
2
[ [ "fibonacci", "add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
654f0cc09e52a1017c22aa0090ca3ad371f51ab1
87fd4d9574e643a8dbba430d3052d81d93756f8b
v1.0
instruct
Filter
Filter_26418_I
What do you think of tuple unpacking in Python and how can it be used in a function argument list?
def calculate(a, b, c): """ Returns a tuple containing the sum, difference, and product of the three arguments. """ return (a + b + c, a - b - c, a * b * c) def calculate_with_tuple(input_tuple): """ Unpacks a tuple and passes the values to the calculate function. """ return calcula...
from solution import calculate, calculate_with_tuple def test_calculate(): assert calculate(1, 2, 3) == (6, -4, 6) assert calculate(-1, -2, -3) == (-6, 4, -6) assert calculate(0, 0, 0) == (0, 0, 0) assert calculate(1, 0, -1) == (0, 2, 0) def test_calculate_with_tuple(): assert calculate_with_tuple...
[ { "docstring": "Returns a tuple containing the sum, difference,\nand product of the three arguments.", "function_declaration": "def calculate(a, b, c):", "function_name": "calculate", "parameter_list": "(a, b, c)" }, { "docstring": "Unpacks a tuple and passes the values to the calculate func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def print_coordinates(x, y):\n \"\"\"\n Prints the x and y coordinates.\n \"\"\"\n print(f\"x: {x}, y: {y}\")\n\n# Using tuple unpacking in a function call\ncoordinates = (10, 20)\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026418", "row_id": 26418, "seed_ids": "['Qwen2-72B-Instruct_64533']" }
0.620139
Filter_26418
I
[ "calculate", "calculate_with_tuple" ]
2
[ [ "calculate_with_tuple", "calculate" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9cdaa57262d9fd71a54607d253dc577e38a265a4
f48ca84f5184d198ca7d59178b50c50751de9175
v1.0
instruct
Filter
Filter_26443_I
Write a recursive function in Python which takes an integer as input and prints the Fibonacci series up to that number. Also, incorporate memoization to optimize the function for larger input values. Bonus point if you can modify the function to return the series in reverse order.
def fibonacci_series(n, memo=None): """ Returns the Fibonacci series up to the nth number using memoization. Also returns the series in reverse order. """ if memo is None: memo = {} if n in memo: return memo[n] if n <= 0: return [] if n == 1: return [0] ...
from solution import fibonacci_series, reverse_fibonacci_series def test_fibonacci_series_zero(): assert fibonacci_series(0) == [] def test_fibonacci_series_one(): assert fibonacci_series(1) == [0] def test_fibonacci_series_two(): assert fibonacci_series(2) == [0, 1] def test_fibonacci_series_five(): ...
[ { "docstring": "Returns the Fibonacci series up to the nth number using memoization.\nAlso returns the series in reverse order.", "function_declaration": "def fibonacci_series(n, memo=None):", "function_name": "fibonacci_series", "parameter_list": "(n, memo=None)" }, { "docstring": "Returns ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_series(n, memo=None):\n \"\"\"\n Returns the Fibonacci series up to the nth number using memoization.\n Also returns the series in reverse order.\n \"\"\"\n if mem...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026443", "row_id": 26443, "seed_ids": "['Qwen2-72B-Instruct_64574']" }
0.756896
Filter_26443
I
[ "fibonacci_series", "reverse_fibonacci_series" ]
2
[ [ "reverse_fibonacci_series", "fibonacci_series" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4b5ac837bfa0bf973689ba4434a53cea6c79a7b
719b338919bbe5735847f6acca25f39e462c23be
v1.0
instruct
Filter
Filter_26444_I
You are provided with a JSON file containing a list of records. Each record consists of multiple fields, including a `name` field. Your task is to convert this JSON file into a CSV file while keeping only the records where the `age` field has a value greater than 25. Also, only include fields that are specified in a gi...
import json import csv def filter_json_to_csv(json_data, fieldnames, output_csv_path): """ Converts JSON data to a CSV file, filtering records with `age` > 25 and considering only specified fields. :param json_data: List of dictionaries containing the JSON data. :param fieldnames: List of fields t...
import json import os from solution import filter_json_to_csv, convert_json_file_to_csv def test_filter_json_to_csv(tmp_path): # Sample JSON data json_data = [ {"name": "John", "age": 30, "city": "New York"}, {"name": "Jane", "age": 22, "city": "San Francisco"}, {"name": "Doe", "age": 3...
[ { "docstring": "Converts JSON data to a CSV file, filtering records with `age` > 25 and considering only specified fields.\n\n:param json_data: List of dictionaries containing the JSON data.\n:param fieldnames: List of fields to include in the CSV output.\n:param output_csv_path: Path to the output CSV file.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nimport csv\n\ndef filter_and_convert_json_to_csv(json_file_path, csv_file_path, fields_to_output):\n \"\"\"\n Reads a JSON file, filters records where the 'age' field is gre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026444", "row_id": 26444, "seed_ids": "['Qwen2-72B-Instruct_64575']" }
0.610044
Filter_26444
I
[ "filter_json_to_csv", "convert_json_file_to_csv" ]
2
[ [ "convert_json_file_to_csv", "filter_json_to_csv" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f5c14d003763310b85082afeca2548e04b56dea
3eb4bc252a1a8e4ed7a2a1848089d3c5957a14c5