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_26463_I
Your mission is to output "Hello Multiverse" to the console. However, to make things more interesting, you will need to write a function that can take in a string and output it to the console, but with a twist. The function should only output the string if the length of the string is a prime number. If the length of th...
def is_prime(n): """ Helper function to determine if a number is prime. A prime number is greater than 1 and has no divisors other than 1 and itself. """ 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...
import sys from io import StringIO from solution import hello_multiverse def test_hello_multiverse_prime_length_string(): captured_output = StringIO() # Create StringIO object sys.stdout = captured_output # Redirect stdout. hello_multiverse("Hello Multiverse") # The length of "Hello Mult...
[ { "docstring": "Helper function to determine if a number is prime.\nA prime number is greater than 1 and has no divisors other than 1 and itself.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints the input string if i...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026463", "row_id": 26463, "seed_ids": "['Qwen2-72B-Instruct_64608']" }
0.667375
Filter_26463
I
[ "is_prime", "hello_multiverse" ]
2
[ [ "hello_multiverse", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
34bf1031cb5861c4af4cf1fa577df59bb1e492a2
ef99c07150ba4db201f8684131b20f0dbcf92c7c
v1.0
instruct
Filter
Filter_26464_I
Create a code to save the first ten prime numbers in an array and additionally, calculate the sum of these prime numbers. Make sure to implement an efficient algorithm for the prime number checking function as the code will also be tested for performance, especially in finding large prime numbers.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False sqrt_n = int(n**0.5) + 1 for i in range(3, sqrt_n, 2): if n % i == 0: return False return T...
from solution import is_prime, first_n_primes, sum_of_primes, get_first_ten_primes_and_sum def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(25) == False def test_first_n_primes(): assert first_n_p...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n 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": "00026464", "row_id": 26464, "seed_ids": "['Qwen2-72B-Instruct_64609']" }
0.532623
Filter_26464
I
[ "is_prime", "first_n_primes", "sum_of_primes", "get_first_ten_primes_and_sum" ]
4
[ [ "first_n_primes", "is_prime" ], [ "get_first_ten_primes_and_sum", "first_n_primes" ], [ "get_first_ten_primes_and_sum", "sum_of_primes" ] ]
3
[]
false
[]
false
pytest
true
[]
true
15a7d0039aa7dd9b2858da25443b464e4983ecf1
84baa841d76875cb0ad5daa5cf039e73917154d8
v1.0
instruct
Filter
Filter_26501_I
Generate a code snippet for sorting an array of integers in descending order using the bubble sort algorithm. Additionally, implement a function that checks if the array is already sorted in descending order before performing the sort. The code should have a time complexity of O(n^2) for the sorting algorithm and O(n) ...
def is_sorted_desc(arr): """ Check if the array is sorted in descending order. Parameters: arr (list): The array to check. Returns: bool: True if sorted in descending order, False otherwise. """ for i in range(len(arr) - 1): if arr[i] < arr[i + 1]: return Fa...
from solution import is_sorted_desc, bubble_sort_desc, sort_if_not_sorted def test_is_sorted_desc(): assert is_sorted_desc([5, 4, 3, 2, 1]) == True assert is_sorted_desc([1, 2, 3, 4, 5]) == False assert is_sorted_desc([3, 3, 2, 2]) == True assert is_sorted_desc([1]) == True assert is_sorted_desc([]...
[ { "docstring": "Check if the array is sorted in descending order.\n\nParameters:\narr (list): The array to check.\n\nReturns:\nbool: True if sorted in descending order, False otherwise.", "function_declaration": "def is_sorted_desc(arr):", "function_name": "is_sorted_desc", "parameter_list": "(arr)"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_sorted_desc(arr):\n \"\"\"\n Checks if the array is sorted in descending order.\n \n :param arr: list of integers\n :return: True if sorted in descending order, False oth...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026501", "row_id": 26501, "seed_ids": "['Qwen2-72B-Instruct_64673']" }
0.577787
Filter_26501
I
[ "is_sorted_desc", "bubble_sort_desc", "sort_if_not_sorted" ]
3
[ [ "sort_if_not_sorted", "bubble_sort_desc" ], [ "sort_if_not_sorted", "is_sorted_desc" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b831d3fe58c4a621244c7a6d6782ea620925f9ea
0ddbb6aab6b3345d14f3f820921b24d3160a0e4b
v1.0
instruct
Filter
Filter_26515_I
Write a function that takes an array of integers as input and sorts it using the Heapsort algorithm.
def heapify(arr, n, i): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[i] < arr[left]: largest = left if right < n and arr[largest] < arr[right]: largest = right if largest != i: arr[i], arr[largest] = arr[largest], arr[i] heapify(arr, n, la...
from solution import heapsort def test_heapsort_sorted_input(): assert heapsort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heapsort_reverse_sorted_input(): assert heapsort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_heapsort_unsorted_input(): assert heapsort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1...
[ { "docstring": null, "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": null, "function_declaration": "def heapsort(arr):", "function_name": "heapsort", "parameter_list": "(arr)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n Helper function to maintain the heap property of a subtree rooted at index i,\n which is an index in arr[]. n is the size of the heap.\n \"\"\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026515", "row_id": 26515, "seed_ids": "['Qwen2-72B-Instruct_64693']" }
0.760734
Filter_26515
I
[ "heapify", "heapsort" ]
2
[ [ "heapsort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
220c4d7ffbc6ba53892e74ac46704ecd3f36b32b
8c55838437b162b0a2d1f248fe2de7f92d58dca0
v1.0
instruct
Filter
Filter_26527_I
Write a Python function that takes in three parameters: `message`, `key`, and `mode`. The function should implement the Caesar Cipher algorithm for encryption and decryption based on the `mode` parameter. The Caesar Cipher is a type of substitution cipher in which each letter in the plaintext is 'shifted' a certain num...
def caesar_cipher(message, key, mode): """ Encrypts or decrypts a message using the Caesar Cipher algorithm. :param message: str, the message to be encrypted or decrypted :param key: int, the number of places each letter is shifted :param mode: str, either 'encrypt' or 'decrypt' to specify the ...
from solution import caesar_cipher def test_caesar_cipher_encrypt(): assert caesar_cipher('ABCD', 1, 'encrypt') == 'BCDE' assert caesar_cipher('xyz', 2, 'encrypt') == 'zab' assert caesar_cipher('Hello, World!', 3, 'encrypt') == 'Khoor, Zruog!' def test_caesar_cipher_decrypt(): assert caesar_cipher('BC...
[ { "docstring": "Encrypts or decrypts a message using the Caesar Cipher algorithm.\n\n:param message: str, the message to be encrypted or decrypted\n:param key: int, the number of places each letter is shifted\n:param mode: str, either 'encrypt' or 'decrypt' to specify the operation mode\n:return: str, the encry...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher(message, key, mode):\n \"\"\"\n Encrypts or decrypts a message using the Caesar Cipher algorithm.\n \n :param message: The input message to encrypt or decrypt.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026527", "row_id": 26527, "seed_ids": "['Qwen2-72B-Instruct_64712']" }
0.687144
Filter_26527
I
[ "caesar_cipher", "shift_character" ]
2
[ [ "caesar_cipher", "shift_character" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1fda86aea3185c620eb606436bfbe1144b9d0c0b
bbe6edb57eaae8cd336a00f77500f048b6921c06
v1.0
instruct
Filter
Filter_26529_I
Write a code to reverse a stack using only recursion and without using any additional data structures.
def reverse_stack(stack): """ Reverses a stack using only recursion and without using any additional data structures. """ if not stack: return # Remove the bottom element from stack and store it in a variable bottom = pop_bottom(stack) # Recursively reverse the rest of the stack ...
from solution import reverse_stack def test_reverse_stack_even_number_of_elements(): stack = [1, 2, 3, 4] reverse_stack(stack) assert stack == [4, 3, 2, 1] def test_reverse_stack_odd_number_of_elements(): stack = [1, 2, 3, 4, 5] reverse_stack(stack) assert stack == [5, 4, 3, 2, 1] def test_re...
[ { "docstring": "Reverses a stack using only recursion and without using any additional data structures.", "function_declaration": "def reverse_stack(stack):", "function_name": "reverse_stack", "parameter_list": "(stack)" }, { "docstring": "Helper function to remove the bottom element from th...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insert_at_bottom(stack, item):\n \"\"\"Helper function to insert an item at the bottom of the stack.\"\"\"\n if not stack:\n stack.append(item)\n else:\n top = stack...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026529", "row_id": 26529, "seed_ids": "['Qwen2-72B-Instruct_64714']" }
0.49826
Filter_26529
I
[ "reverse_stack", "pop_bottom" ]
2
[ [ "reverse_stack", "pop_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec082f8205d123c76acb67e2d7988569653b9bd9
176f4d15de3c8b51a4ca6f3886d2e4951c910ae2
v1.0
instruct
Filter
Filter_26534_I
I want to create a moving plot, refresh it every 2 seconds and identify a given point on the plot with respect to the previously plotted data. Can matplotlib in Python do that or is there another library which can help me with this problem?
import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np def update_point(new_data_x, new_data_y, history_x, history_y, threshold): """ Identifies a given point with respect to the previously plotted data. Args: new_data_x (float) : The x coordinate of the new data po...
from solution import update_point def test_update_point_no_history(): assert update_point(1, 1, [], [], 1.0) is None def test_update_point_within_threshold(): history_x = [0, 2, 4] history_y = [0, 2, 4] assert update_point(1.5, 1.5, history_x, history_y, 2.0) == (2, 2) def test_update_point_outside_t...
[ { "docstring": "Identifies a given point with respect to the previously plotted data.\nArgs:\nnew_data_x (float) : The x coordinate of the new data point.\nnew_data_y (float) : The y coordinate of the new data point.\nhistory_x (list) : The list of x coordinates of previous data points.\nhistory_y (list) : ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\nimport numpy as np\n\ndef moving_plot_interval(interval=2000, duration=10000, point=None):\n \"\"\"\n Cre...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026534", "row_id": 26534, "seed_ids": "['Qwen2-72B-Instruct_64723']" }
0.440254
Filter_26534
I
[ "update_point", "animate_plot" ]
2
[ [ "animate_plot", "update_point" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
9269aee3fdc359da5e2e236e2844b09ec1ac2f0b
490f0bb15aa50c41d924e06faaab21d8ec812914
v1.0
instruct
Filter
Filter_26542_I
Generate the Fibonacci sequence using a Python generator. Additionally, implement a feature to return the sequence in reverse order.
def fibonacci_generator(): """ A generator function for creating a Fibonacci sequence. Yields the next number in the sequence indefinitely. """ a, b = 0, 1 while True: yield a a, b = b, a + b def get_fibonacci_sequence(n, reverse=False): """ Returns the first n numbers i...
from solution import fibonacci_generator, get_fibonacci_sequence def test_fibonacci_first_ten(): expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] assert get_fibonacci_sequence(10) == expected def test_fibonacci_first_ten_reversed(): expected = [34, 21, 13, 8, 5, 3, 2, 1, 1, 0] assert get_fibonacci_sequenc...
[ { "docstring": "A generator function for creating a Fibonacci sequence.\nYields the next number in the sequence indefinitely.", "function_declaration": "def fibonacci_generator():", "function_name": "fibonacci_generator", "parameter_list": "()" }, { "docstring": "Returns the first n numbers ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_generator():\n \"\"\"\n A generator function that yields the Fibonacci sequence indefinitely.\n \"\"\"\n a, b = 0, 1\n while True:\n yield a\n a, b =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026542", "row_id": 26542, "seed_ids": "['Qwen2-72B-Instruct_64731']" }
0.708201
Filter_26542
I
[ "fibonacci_generator", "get_fibonacci_sequence" ]
2
[ [ "get_fibonacci_sequence", "fibonacci_generator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19e60fbf1872e157274cd74738002280afc8cc82
891d03cd353ffb2a1ec464408e4ff9161c059481
v1.0
instruct
Filter
Filter_26545_I
Create a 2D array with five rows and five columns. Each element in the array must be a unique prime number greater than 100. Additionally, include a piece of erroneous code that mistakenly assigns non-prime numbers less than 100 to some elements in the array, which should be identified and fixed.
import sympy def generate_prime_grid(rows, cols, start_value): """ Generates a grid with unique prime numbers starting from a given value. """ prime_array = [[None for _ in range(cols)] for _ in range(rows)] prime_gen = sympy.primepi(start_value) # Start from the first prime greater than start_val...
from solution import generate_prime_grid, generate_erroneous_grid, fix_erroneous_grid, is_prime def test_generate_prime_grid(): grid = generate_prime_grid(5, 5, 100) for row in grid: for num in row: assert num > 100 assert is_prime(num) def test_generate_erroneous_grid(): e...
[ { "docstring": "Generates a grid with unique prime numbers starting from a given value.", "function_declaration": "def generate_prime_grid(rows, cols, start_value):", "function_name": "generate_prime_grid", "parameter_list": "(rows, cols, start_value)" }, { "docstring": "Erroneously assigns ...
[ 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.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True \n if n % 2 == 0 or n % 3 == 0:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026545", "row_id": 26545, "seed_ids": "['Qwen2-72B-Instruct_64735']" }
0.582312
Filter_26545
I
[ "generate_prime_grid", "generate_erroneous_grid", "is_prime", "fix_erroneous_grid" ]
4
[ [ "fix_erroneous_grid", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
09fc684dc1df4ce3ae96083567457cf425332ca3
c59a677fc32d84e77edf77869a3e8d00713fb4d6
v1.0
instruct
Filter
Filter_26547_I
Write a Python program to find the number of days in a month specified by the user. However, instead of using the calendar module, implement the logic by creating a dictionary that maps each month to its respective number of days, taking into account leap years. The program should also handle invalid inputs gracefully....
def is_leap_year(year): """ Returns True if the given year is a leap year, False otherwise. """ if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True return False def days_in_month(month, year): """ Returns the number of days in the specified month of a given year...
import pytest from solution import days_in_month, is_leap_year def test_is_leap_year(): assert is_leap_year(2020) == True assert is_leap_year(2021) == False assert is_leap_year(2000) == True assert is_leap_year(1900) == False def test_days_in_january(): assert days_in_month(1, 2021) == 31 def tes...
[ { "docstring": "Returns True if the given year is a leap year, False otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Returns the number of days in the specified month of a given year.\nHandles leap...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def days_in_month(month, year):\n \"\"\"\n Returns the number of days in a given month of a specified year. Handles leap years for February.\n Args:\n month (int): Month number (1-...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026547", "row_id": 26547, "seed_ids": "['Qwen2-72B-Instruct_64743']" }
0.643336
Filter_26547
I
[ "is_leap_year", "days_in_month" ]
2
[ [ "days_in_month", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53d123f750d895c9cb781154334f06319e76bd4a
b9ca3b9698f31057ca7e80d3a84916b859f0d50b
v1.0
instruct
Filter
Filter_26558_I
Write a Python function to randomly generate a set of 50 unique integers within the range of -1000 to 1000 and return the sum of all the numbers in the set. However, there's a twist - the function should not use any in-built Python libraries or functions to generate random numbers.
def simple_random(seed): """ Simple Linear Congruential Generator (LCG) to generate pseudo-random numbers. The generated numbers will be in the range [-2**31, 2**31]. """ a = 1664525 c = 1013904223 m = 2**32 return (a * seed + c) % m def generate_unique_integers(n, min_val, max_val): ...
from solution import sum_of_unique_integers, generate_unique_integers def test_generate_unique_integers_length(): result = generate_unique_integers(50, -1000, 1000) assert len(result) == 50 def test_generate_unique_integers_range(): result = generate_unique_integers(50, -1000, 1000) for num in result:...
[ { "docstring": "Simple Linear Congruential Generator (LCG) to generate pseudo-random numbers.\nThe generated numbers will be in the range [-2**31, 2**31].", "function_declaration": "def simple_random(seed):", "function_name": "simple_random", "parameter_list": "(seed)" }, { "docstring": "Gen...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def simple_random(seed):\n \"\"\"\n Simple Linear Congruential Generator (LCG) to generate pseudo-random numbers.\n The generated numbers will be in the range [-2**31, 2**31].\n \"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026558", "row_id": 26558, "seed_ids": "['Qwen2-72B-Instruct_64761']" }
0.692725
Filter_26558
I
[ "simple_random", "generate_unique_integers", "sum_of_unique_integers" ]
3
[ [ "generate_unique_integers", "simple_random" ], [ "sum_of_unique_integers", "generate_unique_integers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1c5cc951dfd763f946d2f29babf4952e6086a47e
d71a103a4d789bb9cf8f4a9f76d4b0ad4c9c0138
v1.0
instruct
Filter
Filter_26581_I
How to do binary linear classification using logistic regression by numpy and matplotlib in python?
import numpy as np import matplotlib.pyplot as plt # Function for sigmoid activation def sigmoid(z): return 1 / (1 + np.exp(-z)) # Function to train logistic regression model def train_logistic_regression(X, y, learning_rate=0.01, iterations=1000): m, n = X.shape X = np.hstack((np.ones((m, 1)), X)) # Add...
from solution import sigmoid, train_logistic_regression, predict def test_sigmoid(): assert np.isclose(sigmoid(0), 0.5) assert np.isclose(sigmoid(1), 0.7310585786300049) assert np.isclose(sigmoid(-1), 0.2689414213699951) def test_train_logistic_regression(): X = np.array([[0.5, 1.5], [1.5, 1.9], [2.1,...
[ { "docstring": null, "function_declaration": "def sigmoid(z):", "function_name": "sigmoid", "parameter_list": "(z)" }, { "docstring": null, "function_declaration": "def train_logistic_regression(X, y, learning_rate=0.01, iterations=1000):", "function_name": "train_logistic_regression...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\n# Function for sigmoid activation\ndef sigmoid(z):\n return 1 / (1 + np.exp(-z))\n\n# Function to train logistic regression model\ndef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026581", "row_id": 26581, "seed_ids": "['Qwen2-72B-Instruct_64792']" }
0.668392
Filter_26581
I
[ "sigmoid", "train_logistic_regression", "predict", "plot_decision_boundary" ]
4
[ [ "predict", "sigmoid" ], [ "train_logistic_regression", "sigmoid" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
0f090fda57d2f4798c9b3be006fd0a8729788bd3
fa975a861c224f1a766355e7b4de913a0b8e5e2f
v1.0
instruct
Filter
Filter_26588_I
Develop a Python script that converts a given list of temperatures from Kelvin to Celsius and then finds the average of these Celsius temperatures. The script should be able to take a list of temperatures as input and return the average, rounded to two decimal places. For an added challenge, ensure that the script incl...
def kelvin_to_celsius(kelvin): """ Converts a temperature from Kelvin to Celsius. """ return kelvin - 273.15 def average_celsius_from_kelvin(temperatures): """ Converts a list of temperatures from Kelvin to Celsius and returns the average of these Celsius temperatures, rounded to two decima...
from solution import kelvin_to_celsius, average_celsius_from_kelvin import pytest def test_kelvin_to_celsius(): assert kelvin_to_celsius(0) == -273.15 assert kelvin_to_celsius(273.15) == 0 assert kelvin_to_celsius(373.15) == 100 def test_average_celsius_from_kelvin_valid(): assert average_celsius_from...
[ { "docstring": "Converts a temperature from Kelvin to Celsius.", "function_declaration": "def kelvin_to_celsius(kelvin):", "function_name": "kelvin_to_celsius", "parameter_list": "(kelvin)" }, { "docstring": "Converts a list of temperatures from Kelvin to Celsius and returns the average\nof ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kelvin_to_celsius(kelvin):\n \"\"\"\n Converts a temperature from Kelvin to Celsius.\n \"\"\"\n return kelvin - 273.15\n\ndef average_temperature_in_celsius(temperatures):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026588", "row_id": 26588, "seed_ids": "['Qwen2-72B-Instruct_64799']" }
0.555423
Filter_26588
I
[ "kelvin_to_celsius", "average_celsius_from_kelvin" ]
2
[ [ "average_celsius_from_kelvin", "kelvin_to_celsius" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d89664873eb3f2963270712b77aa56ffc668d570
947daf2801b352a78eb93747bb30217392f1de7f
v1.0
instruct
Filter
Filter_26597_I
How can I simulate a scenario in Python where I have 100 prisoners and 100 boxes, each with a unique number from 1 to 100, in random order? The prisoners also have numbers from 1 to 100. Each prisoner can open 50 boxes to try to find their matching number and if all prisoners find their number, they all win. How can I ...
import random def find_number(strategy, boxes, prisoner_number): """Simulates a prisoner following a given strategy to find their number.""" box_to_open = prisoner_number for _ in range(50): if boxes[box_to_open] == prisoner_number: return True box_to_open = boxes[box_to_open] ...
from solution import find_number, simulate_prisoners_game, probability_simulation def test_find_number(): boxes = list(range(100)) assert find_number(find_number, boxes, 0) == True shuffled_boxes = boxes.copy() random.shuffle(shuffled_boxes) all_results = [find_number(find_number, shuffled_boxes, i...
[ { "docstring": "Simulates a prisoner following a given strategy to find their number.", "function_declaration": "def find_number(strategy, boxes, prisoner_number):", "function_name": "find_number", "parameter_list": "(strategy, boxes, prisoner_number)" }, { "docstring": "Simulates the game f...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef simulate_prisoner_game(num_prisoners=100, num_boxes=100, attempts=50):\n \"\"\"\n Simulate the prisoner game where each prisoner tries to find their matching number ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026597", "row_id": 26597, "seed_ids": "['Qwen2-72B-Instruct_64816']" }
0.469905
Filter_26597
I
[ "find_number", "simulate_prisoners_game", "probability_simulation" ]
3
[ [ "probability_simulation", "simulate_prisoners_game" ], [ "simulate_prisoners_game", "find_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
05155bd46acbbc8b4af5c1b40b70d82a3d94f658
35b2d254f4ae26f452910cdb93675e5a8d2df94b
v1.0
instruct
Filter
Filter_26598_I
Build a Python program that calculates the harmonic mean of a series of numbers stored in a CSV file. The program should handle exceptions for non-numeric values and should report an error if the file cannot be located or opened. The output should display both the harmonic mean of the data and the number of numeric val...
import csv import statistics def harmonic_mean(numbers): """ Calculate the harmonic mean of a list of numbers. Handles cases where the list is empty or contains non-positive numbers by raising ValueError. """ if not numbers: raise ValueError("The list of numbers is empty.") return stat...
import os import pytest from solution import harmonic_mean, read_numbers_from_csv, calculate_harmonic_mean_from_csv def test_harmonic_mean_of_positive_numbers(): assert harmonic_mean([1, 2, 4]) == 1.7142857142857142 def test_harmonic_mean_of_single_number(): assert harmonic_mean([7]) == 7 def test_harmon...
[ { "docstring": "Calculate the harmonic mean of a list of numbers.\nHandles cases where the list is empty or contains non-positive numbers by raising ValueError. ", "function_declaration": "def harmonic_mean(numbers):", "function_name": "harmonic_mean", "parameter_list": "(numbers)" }, { "doc...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nfrom statistics import harmonic_mean\nfrom typing import Tuple\n\ndef read_csv_and_calculate_harmonic_mean(filepath: str) -> Tuple[float, int]:\n \"\"\"\n Reads a CSV file an...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026598", "row_id": 26598, "seed_ids": "['Qwen2-72B-Instruct_64817']" }
0.586772
Filter_26598
I
[ "harmonic_mean", "read_numbers_from_csv", "calculate_harmonic_mean_from_csv" ]
3
[ [ "calculate_harmonic_mean_from_csv", "harmonic_mean" ], [ "calculate_harmonic_mean_from_csv", "read_numbers_from_csv" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e27712f454511f53bbe2e6f94db5845038de04a2
30fe8dcdeadda471417f849fafca977d802e9faa
v1.0
instruct
Filter
Filter_26616_I
Write a python program to simulate a biased coin flip, where the probability of landing on heads is 0.6 and on tails is 0.4. The program should record the outcomes of 1000 coin flips and print the total number of heads and tails.
import random def biased_coin_flip(): """ Simulates a biased coin flip with a 0.6 probability of landing on heads and 0.4 probability of landing on tails. """ return 'heads' if random.random() < 0.6 else 'tails' def simulate_coin_flips(n): """ Simulates n biased coin flips and returns the...
from solution import biased_coin_flip, simulate_coin_flips def test_biased_coin_flip(): # Perform multiple trials and check if heads occur more frequently than tails results = {'heads': 0, 'tails': 0} trials = 100000 for _ in range(trials): result = biased_coin_flip() results[result] +=...
[ { "docstring": "Simulates a biased coin flip with a 0.6 probability of landing on heads \nand 0.4 probability of landing on tails.", "function_declaration": "def biased_coin_flip():", "function_name": "biased_coin_flip", "parameter_list": "()" }, { "docstring": "Simulates n biased coin flips...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef biased_coin_flip():\n \"\"\"\n Simulates a biased coin flip with a 0.6 probability of landing on heads \n and 0.4 probability of landing on tails.\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026616", "row_id": 26616, "seed_ids": "['Qwen2-72B-Instruct_64838']" }
0.437485
Filter_26616
I
[ "biased_coin_flip", "simulate_coin_flips" ]
2
[ [ "simulate_coin_flips", "biased_coin_flip" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3eee0995e4cd29aad4fda61e94b6c7a8e27d8b4d
e0d0f90dcc17d138bf64c8a319e1fb0d4d0cc6a3
v1.0
instruct
Filter
Filter_26620_I
Write a script in Python for drawing a hollow irregular hexagon on the screen with user-defined sides. The program should validate the input to ensure that it is possible to form an irregular hexagon with the given sides.
import turtle def validate_hexagon_sides(sides): """ Validates if the given sides can form an irregular hexagon. Each pair of adjacent sides should sum up to more than the opposite side. """ if len(sides) != 6: return False for i in range(6): if sides[i] + sides[(i + 1) % 6] <=...
from solution import validate_hexagon_sides, draw_hollow_irregular_hexagon import pytest def test_validate_hexagon_sides_valid(): assert validate_hexagon_sides([50, 60, 50, 60, 50, 60]) == True assert validate_hexagon_sides([70, 80, 70, 80, 70, 80]) == True def test_validate_hexagon_sides_invalid(): asser...
[ { "docstring": "Validates if the given sides can form an irregular hexagon.\nEach pair of adjacent sides should sum up to more than the opposite side.", "function_declaration": "def validate_hexagon_sides(sides):", "function_name": "validate_hexagon_sides", "parameter_list": "(sides)" }, { "...
[ 1, 0, 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_irregular_hexagon(sides):\n \"\"\"\n Draws an irregular hexagon based on the provided sides.\n \n sides: A list of 6 positive numbers representing the len...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026620", "row_id": 26620, "seed_ids": "['Qwen2-72B-Instruct_64846']" }
0.549498
Filter_26620
I
[ "validate_hexagon_sides", "draw_hollow_irregular_hexagon" ]
2
[ [ "draw_hollow_irregular_hexagon", "validate_hexagon_sides" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18f0a3f30b628d8aafa03589406aa3a434bf4016
5cbe2efc6d68d7a0fa2835ceef522e8ae2bd66db
v1.0
instruct
Filter
Filter_26626_I
Develop a Python program that generates a list of Twin Primes between 1 and n, where n is a user input. Twin Primes are pairs of primes that are two units apart (like 11 and 13). Alongside this, make a function that checks the correctness of the generated list by comparing it against known values for certain intervals....
def is_prime(num): """ Checks if a number is a prime number. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, generate_twin_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(29) == True assert is_prime(51) == False def test_generate_twi...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a list of twin primes up to n.", "function_declaration": "def generate_twin_primes(n):", "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 Checks 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_0
{ "original_instruction": "", "prompt_id": "00026626", "row_id": 26626, "seed_ids": "['Qwen2-72B-Instruct_64853']" }
0.539144
Filter_26626
I
[ "is_prime", "generate_twin_primes" ]
2
[ [ "generate_twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ff57cf73f996457256d71c8b000e87b2c1c23d4
2fce4a70685fd566578e5a42a25c6e257e117e9e
v1.0
instruct
Filter
Filter_26634_I
Utilizing the provided list and dictionary data, develop a Python code snippet with a function that not only identifies all the dictionaries with a prime number age value but also returns the average age of these prime-aged individuals. The function should handle scenarios where the database may contain duplicate names...
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 r...
from solution import avg_prime_age, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_avg_prime_age_no_primes(): db = [ {'name': 'John Doe', 'age': 4}, ...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Identifies all the dictionaries with a prime number age value and \nreturns the average age of these prime-aged individu...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026634", "row_id": 26634, "seed_ids": "['Qwen2-72B-Instruct_64868']" }
0.604743
Filter_26634
I
[ "is_prime", "avg_prime_age" ]
2
[ [ "avg_prime_age", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c1103e77d07ba1009dc3ad5b59366e5b127480cc
06b873e935a4688b2cc94c85d09eb5013a093add
v1.0
instruct
Filter
Filter_26644_I
Write a recursive function in Python to compute the nth Fibonacci number. Then, modify the function to return the sequence of all Fibonacci numbers up to and including the nth number. The sequence should be returned as a list.
def fibonacci_recursive(n): """ Returns the nth Fibonacci number. """ if n <= 0: raise ValueError("n should be a positive integer.") elif n == 1: return 0 elif n == 2: return 1 else: return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2) def fibonacci...
from solution import fibonacci_recursive, fibonacci_sequence def test_fibonacci_recursive_single(): assert fibonacci_recursive(1) == 0 assert fibonacci_recursive(2) == 1 assert fibonacci_recursive(3) == 1 assert fibonacci_recursive(4) == 2 assert fibonacci_recursive(5) == 3 assert fibonacci_rec...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci_recursive(n):", "function_name": "fibonacci_recursive", "parameter_list": "(n)" }, { "docstring": "Returns the sequence of all Fibonacci numbers up to and including the nth number.", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_recursive(n):\n \"\"\"\n Computes the nth Fibonacci number.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer.\")\n elif n == 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026644", "row_id": 26644, "seed_ids": "['Qwen2-72B-Instruct_64887']" }
0.815681
Filter_26644
I
[ "fibonacci_recursive", "fibonacci_sequence" ]
2
[ [ "fibonacci_sequence", "fibonacci_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65c3813d8712d7d87c987989fce49a25842d4dd3
1ebb3d83fa8cc12fd88bab1d76c6cada24d1cac7
v1.0
instruct
Filter
Filter_26654_I
Write a Python function that takes an array of integers as input and returns the array sorted in ascending order using the heap sort algorithm. The function should be named `heap_sort`.
def heapify(arr, n, i): """ To heapify a subtree rooted with node i which is an index in arr[]. n is the size of heap. """ largest = i # Initialize largest as root left = 2 * i + 1 # left = 2*i + 1 right = 2 * i + 2 # right = 2*i + 2 # See if left child of root exists and is greater ...
from solution import heap_sort def test_heap_sort_general_case(): assert heap_sort([12, 11, 13, 5, 6, 7]) == [5, 6, 7, 11, 12, 13] def test_heap_sort_empty_array(): assert heap_sort([]) == [] def test_heap_sort_single_element(): assert heap_sort([1]) == [1] def test_heap_sort_sorted_array(): assert ...
[ { "docstring": "To heapify a subtree rooted with node i which is an index in arr[].\nn is the size of heap.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Main function to do heap sort.", "function_decla...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n To heapify a subtree rooted with node i which is an index in arr[]. n is the size of the heap.\n \"\"\"\n largest = i # Initialize largest ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026654", "row_id": 26654, "seed_ids": "['Qwen2-72B-Instruct_64899']" }
0.767348
Filter_26654
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
be4d16a1518b7896696ce66f9a7c4ca2095c9dd1
0777430f01eaba4899258aa07b2628203a16ce23
v1.0
instruct
Filter
Filter_26655_I
Create a function that takes a list of strings as input and performs multiple steps to find the string with the highest number of vowels. If there are multiple strings with the same highest number of vowels, return the one that comes first lexicographically (i.e., 'apple' before 'banana'). If the list is empty, the fun...
import string def count_vowels(s): """ Count the number of vowels in a given string. """ vowels = 'aeiouAEIOU' return sum(1 for char in s if char in vowels) def strip_punctuation(s): """ Remove punctuation from a given string. """ return s.translate(str.maketrans("", "", string.pun...
from solution import string_with_most_vowels def test_empty_list(): assert string_with_most_vowels([]) is None def test_single_string(): assert string_with_most_vowels(["hello"]) == "hello" def test_multiple_strings(): assert string_with_most_vowels(["hello", "world"]) == "hello" assert string_with_m...
[ { "docstring": "Count the number of vowels in a given string.", "function_declaration": "def count_vowels(s):", "function_name": "count_vowels", "parameter_list": "(s)" }, { "docstring": "Remove punctuation from a given string.", "function_declaration": "def strip_punctuation(s):", "...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\ndef strip_punctuation_and_count_vowels(s):\n \"\"\"\n Removes punctuation from the string and counts the number of vowels.\n \"\"\"\n vowels = \"aeiouAEIOU\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026655", "row_id": 26655, "seed_ids": "['Qwen2-72B-Instruct_64900']" }
0.717624
Filter_26655
I
[ "count_vowels", "strip_punctuation", "string_with_most_vowels" ]
3
[ [ "string_with_most_vowels", "count_vowels" ], [ "string_with_most_vowels", "strip_punctuation" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6c2c5d1008c68ecfdec6c27475c4421f8f6ab4df
b634ad4670ffca78f45c183d1dba9069342749eb
v1.0
instruct
Filter
Filter_26673_I
Devise a sorting mechanism using parallel computing in Python. Your solution should make use of the multiprocessing module to sort a large array of randomly generated numbers. Ensure to compare the performance of your parallel sorting algorithm against a standard, non-parallel sorting algorithm by measuring and compari...
import multiprocessing import random import time def merge_sort(arr): if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(arr[mid:]) return merge(left, right) def merge(left, right): result = [] i = j = 0 while i < len(left...
from solution import merge_sort, parallel_merge_sort, compare_sorting_algorithms import random def test_merge_sort(): arr = [random.randint(0, 100) for _ in range(100)] assert merge_sort(arr) == sorted(arr) def test_parallel_merge_sort(): arr = [random.randint(0, 100) for _ in range(100)] assert paral...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" }, { "docst...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import multiprocessing\nimport random\nimport time\n\ndef merge_sort(arr):\n if len(arr) <= 1:\n return arr\n mid = len(arr) // 2\n left = merge_sort(arr[:mid])\n right = me...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026673", "row_id": 26673, "seed_ids": "['Qwen2-72B-Instruct_64929']" }
0.604341
Filter_26673
I
[ "merge_sort", "merge", "parallel_merge_sort", "compare_sorting_algorithms" ]
4
[ [ "compare_sorting_algorithms", "merge_sort" ], [ "compare_sorting_algorithms", "parallel_merge_sort" ], [ "merge_sort", "merge" ], [ "parallel_merge_sort", "merge" ], [ "parallel_merge_sort", "merge_sort" ] ]
5
[]
false
[]
false
pytest
true
[]
true
07fcb06ae5a5029ac852cf77ecd2f81da58b52b4
d99c07eea81ab3354514dd2fb77276f5209a146a
v1.0
instruct
Filter
Filter_26699_I
Propose a method to get the intersection of two lists without using built-in functions and also take into account that these lists can contain nested lists (depth of nesting can be one). The intersection should also preserve the original order of elements in the lists. Also, write code that is efficient in terms of tim...
def flatten(lst): """ This function flattens a list by one level, which means it returns a new list where elements of any nested list become part of the main list. """ flattened = [] for item in lst: if isinstance(item, list): flattened.extend(item) else: ...
from solution import list_intersection def test_simple_intersection(): assert list_intersection([1, 2, 3], [2, 3, 4]) == [2, 3] def test_no_intersection(): assert list_intersection([1, 2, 3], [4, 5, 6]) == [] def test_nested_lists_intersection(): assert list_intersection([1, [2, 3], 4], [[2, 5], 3, 4]) =...
[ { "docstring": "This function flattens a list by one level, which means it returns a new list \nwhere elements of any nested list become part of the main list.", "function_declaration": "def flatten(lst):", "function_name": "flatten", "parameter_list": "(lst)" }, { "docstring": "This functio...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_nested_list_intersection(list1, list2):\n \"\"\"\n Returns the intersection of two lists, including nested lists (one level deep).\n The intersection should preserve the order...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026699", "row_id": 26699, "seed_ids": "['Qwen2-72B-Instruct_64960']" }
0.614565
Filter_26699
I
[ "flatten", "list_intersection" ]
2
[ [ "list_intersection", "flatten" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e85e76fcf9d09caf035abcdc38e34f3e44ab382
02507eca0331cdac2110051e4a043279e6bc01c2
v1.0
instruct
Filter
Filter_26726_I
Given a list of numbers, develop a code snippet in Python to find the maximum number that is divisible by all the numbers in the list. The length of the list will be between 2 and 10, and the numbers in the list will be between 1 and 10^6.
import math from functools import reduce def gcd(a, b): """ Computes the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b): """ Computes the least common multiple of a and b. """ return a * b // gcd(a, b) def find_max_number_divisible_...
from solution import find_max_number_divisible_by_all def test_single_pair(): assert find_max_number_divisible_by_all([2, 3]) == 6 assert find_max_number_divisible_by_all([5, 10]) == 10 def test_multiple_numbers(): assert find_max_number_divisible_by_all([2, 3, 5]) == 30 assert find_max_number_divisib...
[ { "docstring": "Computes the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Computes the least common multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_name...
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef find_max_divisible(numbers):\n \"\"\"\n Finds t...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026726", "row_id": 26726, "seed_ids": "['Qwen2-72B-Instruct_65008']" }
0.72194
Filter_26726
I
[ "gcd", "lcm", "find_max_number_divisible_by_all" ]
3
[ [ "find_max_number_divisible_by_all", "lcm" ], [ "lcm", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b28f4a8b82ac421e7fa447fb8e0057e3734ad2d6
7ff5eea32a41d2c16e63871cc7e85c9d39fd2adc
v1.0
instruct
Filter
Filter_26736_I
Write a Monte Carlo simulation to estimate pi. Your program should output the estimated value of pi as well as the percentage error compared to the actual value of pi. Additionally, implement the simulation using parallel processing to improve performance. The number of iterations should be adjustable through an argume...
import random import math from multiprocessing import Pool def monte_carlo_pi_part(samples): count_inside_circle = 0 for _ in range(samples): x, y = random.random(), random.random() if x*x + y*y <= 1: count_inside_circle += 1 return count_inside_circle def monte_carlo_pi(total_...
from solution import monte_carlo_pi, calculate_percentage_error import math def test_monte_carlo_pi_accuracy(): estimated_pi = monte_carlo_pi(1000000, num_processes=4) percentage_error = calculate_percentage_error(estimated_pi) assert abs(estimated_pi - math.pi) < 0.01, f"Estimated Pi is too far from actua...
[ { "docstring": null, "function_declaration": "def monte_carlo_pi_part(samples):", "function_name": "monte_carlo_pi_part", "parameter_list": "(samples)" }, { "docstring": null, "function_declaration": "def monte_carlo_pi(total_samples, num_processes=4):", "function_name": "monte_carlo...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport multiprocessing\nimport math\n\ndef monte_carlo_pi_part(iterations):\n count = 0\n for _ in range(iterations):\n x, y = random.uniform(0, 1), random.uniform(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026736", "row_id": 26736, "seed_ids": "['Qwen2-72B-Instruct_65026']" }
0.519762
Filter_26736
I
[ "monte_carlo_pi_part", "monte_carlo_pi", "calculate_percentage_error" ]
3
[ [ "monte_carlo_pi", "monte_carlo_pi_part" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc12b7950cc09825defd3a6fe812f67da24f5287
83cdfa1b7b5cfadc6e0b1bb441ed01117bfd2414
v1.0
instruct
Filter
Filter_26747_I
Create all permutations of an array of integers with parallel processing. Consider the scenario where the input array could potentially contain duplicate integers.
from itertools import permutations from multiprocessing import Pool def unique_permutations(iterable): """ Return unique permutations of the iterable. """ seen = set() unique_perms = [] for perm in set(permutations(iterable)): if perm not in seen: seen.add(perm) ...
from solution import parallel_permutations def test_parallel_permutations_empty_array(): assert parallel_permutations([]) == [] def test_parallel_permutations_single_element(): assert parallel_permutations([1]) == [(1,)] def test_parallel_permutations_no_duplicates(): perms = parallel_permutations([1, 2,...
[ { "docstring": "Return unique permutations of the iterable.", "function_declaration": "def unique_permutations(iterable):", "function_name": "unique_permutations", "parameter_list": "(iterable)" }, { "docstring": "Generate all unique permutations of the array `arr` using parallel processing....
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nfrom multiprocessing import Pool\n\ndef permute(arr):\n \"\"\"\n Returns all permutations of the input array arr using parallel processing.\n \"\"\"\n def worker(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026747", "row_id": 26747, "seed_ids": "['Qwen2-72B-Instruct_65043']" }
0.606299
Filter_26747
I
[ "unique_permutations", "parallel_permutations" ]
2
[ [ "parallel_permutations", "unique_permutations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13fb53fc7cfc4b5782d510ecef82495d6044015b
1b8ca9ae0e2f1cdfc319817f6686535796c717db
v1.0
instruct
Filter
Filter_26749_I
Write a program that would simulate a simple Rock Paper Scissors game. The game should accept inputs from one player competing against a computer opponent. Ensure your solution includes a way to handle game states (i.e., win, lose, draw), track the number of rounds played and the player's score. Incorporate error handl...
import random def get_computer_choice(): """ Randomly returns 'rock', 'paper', or 'scissors'. """ choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(player_choice, computer_choice): """ Determines the outcome of a rock-paper-scissors round. Retur...
from solution import get_computer_choice, determine_winner, validate_choice, play_round def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] assert get_computer_choice() in choices def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'win' assert determine_win...
[ { "docstring": "Randomly returns 'rock', 'paper', or 'scissors'.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the outcome of a rock-paper-scissors round.\nReturns 'win', 'lose', or 'draw'....
[ 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 get_computer_choice():\n \"\"\"\n Randomly returns 'rock', 'paper', or 'scissors'.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors'])\n\ndef determ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026749", "row_id": 26749, "seed_ids": "['Qwen2-72B-Instruct_65048']" }
0.528909
Filter_26749
I
[ "get_computer_choice", "determine_winner", "validate_choice", "play_round" ]
4
[ [ "play_round", "determine_winner" ], [ "play_round", "validate_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
590f0efdc6232cfafe7cdbc33f1155b91c300dd6
4ff95206b8157ff4ee255cf1752282e5d3a3b2a8
v1.0
instruct
Filter
Filter_26751_I
Develop a Python script that can continuously monitor the CPU usage of a specific process by reading data from the /proc file system. The script should include a function that uses the inotify framework to receive notifications when the process's stat file is modified. This function should be able to parse the updated ...
import os import struct import time import psutil def get_process_cpu_percentage(pid): """ Returns the CPU usage percentage of a specified process by its PID. """ if not psutil.pid_exists(pid): return None proc = psutil.Process(pid) return proc.cpu_percent(interval=1.0) def monitor_cp...
from solution import get_process_cpu_percentage import os import psutil def test_get_process_cpu_percentage_existing_process(): pid = os.getpid() # Get current process PID cpu_usage = get_process_cpu_percentage(pid) assert cpu_usage is not None def test_get_process_cpu_percentage_non_existing_process(): ...
[ { "docstring": "Returns the CPU usage percentage of a specified process by its PID.", "function_declaration": "def get_process_cpu_percentage(pid):", "function_name": "get_process_cpu_percentage", "parameter_list": "(pid)" }, { "docstring": "Monitors CPU usage of a specified process by its P...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport time\nimport inotify.adapters\nfrom collections import namedtuple\n\n_process_times = namedtuple('ProcessTimes', ['utime', 'stime', 'cutime', 'cstime'])\n\ndef _parse_process...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026751", "row_id": 26751, "seed_ids": "['Qwen2-72B-Instruct_65052']" }
0.682057
Filter_26751
I
[ "get_process_cpu_percentage", "monitor_cpu_usage" ]
2
[ [ "monitor_cpu_usage", "get_process_cpu_percentage" ] ]
1
[]
false
[]
false
pytest
true
[ "psutil" ]
false
ac030e985d77400dbf5f91899f8a720b54dee39d
f06e44bce47e13cd91d9262212d18c7792ffef2e
v1.0
instruct
Filter
Filter_26757_I
Use Python to filter out all the prime numbers from a given list of integers. Additionally, handle any errors that may occur during the filtering process and provide appropriate error messages.
def is_prime(n): """ Helper function to determine if n is a prime number. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(nums): """ Filters out prime numbers from a given list of integ...
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_filter_primes_with_only_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_p...
[ { "docstring": "Helper function to determine if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters out prime numbers from a given list of integers.\n\nParameters:\nnums (list): List of integers to...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even prime number\n if ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026757", "row_id": 26757, "seed_ids": "['Qwen2-72B-Instruct_65060']" }
0.63384
Filter_26757
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ad12e168dd3f8b2171691e530493ba13b0350e9f
a5a1608648bae117c5412e1c2c60d098075ee824
v1.0
instruct
Filter
Filter_26779_I
Devise a sorting algorithm that not only sorts an array consisting of 20 distinct integers in non-descending order, but also finds the median. Moreover, implement it without using any built-in sorting functions or data structures, and optimize it for better time complexity.
def quicksort(arr): """ Performs quicksort on the input array and returns the sorted array. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return qu...
from solution import sort_and_find_median def test_sort_and_find_median_distinct(): arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, -2, 10, 8, -6, 7, 12] sorted_arr, median = sort_and_find_median(arr) assert sorted_arr == [-6, -2, 1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 7, 7, 8, 9, 9, 9, 10, 12] assert med...
[ { "docstring": "Performs quicksort on the input array and returns the sorted array.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Finds and returns the median value of the sorted array.", "function_declaration"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort(arr):\n \"\"\"\n Helper function to perform quicksort on the array.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026779", "row_id": 26779, "seed_ids": "['Qwen2-72B-Instruct_65096']" }
0.692515
Filter_26779
I
[ "quicksort", "find_median", "sort_and_find_median" ]
3
[ [ "sort_and_find_median", "find_median" ], [ "sort_and_find_median", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e1be6d2377b60cf2679d4b9bba52a652dccfc8b8
7eed1e3a0652e72167786cc8cd4d0e0e18282665
v1.0
instruct
Filter
Filter_26807_I
Write a script in Python that counts from 0 to 10, but also prints whether the current number is an even or odd number. Additionally, the script should raise an exception if the number is a prime number and the number should be checked for primality using a recursive function.
def is_prime(n, i=2): """ Recursively checks if a number n is a prime number. """ if n <= 2: return n == 2 if n % i == 0: return False if i * i > n: return True return is_prime(n, i + 1) def count_and_check(): """ Counts from 0 to 10, prints whether the curre...
import pytest from solution import is_prime, count_and_check def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_count_and_check(): with pytest.ra...
[ { "docstring": "Recursively checks if a number n is a prime number.", "function_declaration": "def is_prime(n, i=2):", "function_name": "is_prime", "parameter_list": "(n, i=2)" }, { "docstring": "Counts from 0 to 10, prints whether the current number is even or odd, \nand raises an exception...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n, i=2):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n Checks for primality using a recursive function.\n \"\"\"\n if n <= 2:\n return n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026807", "row_id": 26807, "seed_ids": "['Qwen2-72B-Instruct_65140']" }
0.648387
Filter_26807
I
[ "is_prime", "count_and_check" ]
2
[ [ "count_and_check", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58e8e480d0b2753aa501b874f936fc1a2a98b065
6d18be83bfd111de3c8be64de737ec11fb1a55db
v1.0
instruct
Filter
Filter_26819_I
Write a Python script that takes a list of temperatures in Fahrenheit as input, and prints out the sum, average, minimum, and maximum temperatures in Celsius. Make sure to handle any possible errors, such as non-numeric input.
def fahrenheit_to_celsius(fahrenheit): """ Converts a temperature from Fahrenheit to Celsius. Formula: (Fahrenheit - 32) * 5/9 """ try: return (float(fahrenheit) - 32) * 5/9 except ValueError: raise ValueError("Temperature must be a number") def process_temperatures(temperatures...
import pytest from solution import fahrenheit_to_celsius, process_temperatures def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(98.6) == pytest.approx(37, rel=1e-2) def test_fahrenheit_to_celsius_invalid_input(): ...
[ { "docstring": "Converts a temperature from Fahrenheit to Celsius.\nFormula: (Fahrenheit - 32) * 5/9", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Takes a list of temperatures ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convert_fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts Fahrenheit to Celsius.\n \"\"\"\n return (fahrenheit - 32) * 5.0 / 9.0\n\ndef process_temperatures(fahrenheit_tem...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026819", "row_id": 26819, "seed_ids": "['Qwen2-72B-Instruct_65156']" }
0.520526
Filter_26819
I
[ "fahrenheit_to_celsius", "process_temperatures" ]
2
[ [ "process_temperatures", "fahrenheit_to_celsius" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c2d4141439f4d2867dd6f78718a02e0a159df44
1a41c5a5dce05ee7d5d138450eebe651442e513c
v1.0
instruct
Filter
Filter_26826_I
Your task is to generate a random 5 digit number using the function given in the example below. Additionally, you need to modify the program to ensure that the generated number is not divisible by any prime number less than or equal to 10. You cannot use any additional libraries or functions to check for prime numbers....
import random def is_divisible_by_any_prime(n, primes): for prime in primes: if n % prime == 0: return True return False def generate_random_5_digit_number(): primes_upto_10 = [2, 3, 5, 7] while True: num = random.randint(10000, 99999) if not is_divisible_by_any_pri...
from solution import generate_random_5_digit_number, is_divisible_by_any_prime def test_generate_random_5_digit_number_not_divisible_by_primes(): primes_upto_10 = [2, 3, 5, 7] for _ in range(1000): # Test through 1000 iterations to check robustness num = generate_random_5_digit_number() assert...
[ { "docstring": null, "function_declaration": "def is_divisible_by_any_prime(n, primes):", "function_name": "is_divisible_by_any_prime", "parameter_list": "(n, primes)" }, { "docstring": null, "function_declaration": "def generate_random_5_digit_number():", "function_name": "generate_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_random_number():\n \"\"\"\n Generates a random 5-digit number that is not divisible by any prime number ≤ 10.\n \"\"\"\n primes = [2, 3, 5, 7]\n \n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026826", "row_id": 26826, "seed_ids": "['Qwen2-72B-Instruct_65168']" }
0.504047
Filter_26826
I
[ "is_divisible_by_any_prime", "generate_random_5_digit_number" ]
2
[ [ "generate_random_5_digit_number", "is_divisible_by_any_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
227f8cd5e636b65f57127220ad5a4ba5f4f8619e
ee6850b4d8e10a6a6aa22e6391996e94625daae7
v1.0
instruct
Filter
Filter_26829_I
I have a function called `svmClassifier`, I want to use it with another function called `calculateAccuracy`. The `svmClassifier` takes in three arguments: `features_train`, `labels_train`, and `features_test` as well as `kernel`, `C`, and `verbose` as keyword arguments. The `calculateAccuracy` function takes in the `pr...
def svmClassifier(features_train, labels_train, features_test, kernel='linear', C=1.0, verbose=False): from sklearn import svm clf = svm.SVC(kernel=kernel, C=C, verbose=verbose) clf.fit(features_train, labels_train) return clf.predict(features_test) def calculateAccuracy(features_train, labels_train, f...
import numpy as np from solution import svmClassifier, calculateAccuracy def test_svmClassifier(): features_train = np.array([[1, 2], [2, 3], [3, 4], [4, 5]]) labels_train = np.array([0, 1, 0, 1]) features_test = np.array([[1, 2], [4, 5]]) predictions = svmClassifier(features_train, labels_train, ...
[ { "docstring": null, "function_declaration": "def svmClassifier(features_train, labels_train, features_test, kernel='linear', C=1.0, verbose=False):", "function_name": "svmClassifier", "parameter_list": "(features_train, labels_train, features_test, kernel='linear', C=1.0, verbose=False)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def svmClassifier(features_train, labels_train, features_test, kernel='linear', C=1.0, verbose=False):\n \"\"\"\n Trains an SVM classifier with the given training data and predicts the l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026829", "row_id": 26829, "seed_ids": "['Qwen2-72B-Instruct_65172']" }
0.458312
Filter_26829
I
[ "svmClassifier", "calculateAccuracy" ]
2
[ [ "calculateAccuracy", "svmClassifier" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "sklearn" ]
false
1945f6a9a4a180e0cb2ca256a278912e63aa40f4
49c653740f09c8a8a088d91fd451464f8090dc35
v1.0
instruct
Filter
Filter_26833_I
Create a two player turn based game that awards points to the player that wins the turn. Use the random module in python to generate the moves for each player.
import random def generate_move(): """ Generates a random move for the player. Returns a random integer between 1 and 100. """ return random.randint(1, 100) def play_turn(player1, player2): """ Plays a turn and returns the name of the winner of the turn and the moves of both players. "...
from solution import generate_move, play_turn, play_game def test_generate_move(): move = generate_move() assert 1 <= move <= 100 def test_play_turn(): winner, move1, move2 = play_turn('Alice', 'Bob') assert move1 != move2 assert (winner == 'Alice' and move1 > move2) or (winner == 'Bob' and move1 ...
[ { "docstring": "Generates a random move for the player.\nReturns a random integer between 1 and 100.", "function_declaration": "def generate_move():", "function_name": "generate_move", "parameter_list": "()" }, { "docstring": "Plays a turn and returns the name of the winner of the turn and t...
[ 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\nclass Game:\n def __init__(self):\n self.player_1_score = 0\n self.player_2_score = 0\n \n def play_turn(self):\n \"\"\"\n Simulate a turn...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026833", "row_id": 26833, "seed_ids": "['Qwen2-72B-Instruct_65177']" }
0.462673
Filter_26833
I
[ "generate_move", "play_turn", "play_game" ]
3
[ [ "play_game", "play_turn" ], [ "play_turn", "generate_move" ] ]
2
[]
false
[]
false
pytest
true
[]
true
41780dc1fc3524d750e5005f250ffd29a9f16bff
883ee771bb69afa6ae7b29f6f4bc0c63ac88234c
v1.0
instruct
Filter
Filter_26856_I
Write a function to create a complex 3D parametric equation for a moving particle in Python, taking into account an elaborate trajectory characterized by periodicity, non-linearity, and a variable velocity, then animate the motion using Matplotlib's animation library.
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from mpl_toolkits.mplot3d import Axes3D def complex_3d_parametric_equation(t): """ Calculate the x, y, z coordinates of a particle in a complex 3D parametric equation. Parameters: t : float : Time parameter...
from solution import complex_3d_parametric_equation def test_3d_parametric_equation_initial(): x, y, z = complex_3d_parametric_equation(0) assert np.isclose(x, 0) assert np.isclose(y, 0) assert np.isclose(z, 1) def test_3d_parametric_equation_positive_t(): x, y, z = complex_3d_parametric_equation(...
[ { "docstring": "Calculate the x, y, z coordinates of a particle in a complex 3D parametric equation.\n\nParameters:\nt : float : Time parameter\n\nReturns:\n(x, y, z) : tuple of floats : The x, y, z coordinates of the particle at time t", "function_declaration": "def complex_3d_parametric_equation(t):", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\nfrom mpl_toolkits.mplot3d import Axes3D\n\ndef complex_3d_parametric_equation(t):\n \"\"\"\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026856", "row_id": 26856, "seed_ids": "['Qwen2-72B-Instruct_65217']" }
0.419751
Filter_26856
I
[ "complex_3d_parametric_equation", "animate", "create_animation" ]
3
[ [ "animate", "complex_3d_parametric_equation" ], [ "create_animation", "animate" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "mpl_toolkits", "numpy" ]
false
2534f6b4a12054eeb61642c16868e32a0112c74e
d2c43582d25f1e9747edbefb95348111901aca9d
v1.0
instruct
Filter
Filter_26861_I
Write a Python function that takes two positive integers a and b and returns the least common multiple and greatest common divisor of a and b using Euclidean algorithm.
def gcd(a, b): """ Returns the greatest common divisor of a and b using the Euclidean algorithm. """ while b != 0: a, b = b, a % b return a def lcm(a, b): """ Returns the least common multiple of a and b. """ return a * b // gcd(a, b) def gcd_lcm(a, b): """ Returns ...
from solution import gcd_lcm def test_gcd_lcm_simple(): assert gcd_lcm(6, 8) == (2, 24) assert gcd_lcm(12, 15) == (3, 60) def test_gcd_lcm_with_prime_numbers(): assert gcd_lcm(13, 17) == (1, 221) assert gcd_lcm(7, 5) == (1, 35) def test_gcd_lcm_same_numbers(): assert gcd_lcm(10, 10) == (10, 10) ...
[ { "docstring": "Returns the greatest common divisor of a and b using the Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple of a and b.", "function_declaration": "def lcm...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b using the Euclidean algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026861", "row_id": 26861, "seed_ids": "['Qwen2-72B-Instruct_65226']" }
0.792353
Filter_26861
I
[ "gcd", "lcm", "gcd_lcm" ]
3
[ [ "gcd_lcm", "gcd" ], [ "gcd_lcm", "lcm" ], [ "lcm", "gcd" ] ]
3
[]
false
[]
false
pytest
true
[]
true
166b13e111ddee23be0f380a44567922b677079a
c214d6c503c3d2745c4e58f9683e6204746fce4c
v1.0
instruct
Filter
Filter_26889_I
Generate an AI agent to play the game of Connect Four with perfect play.
import math import numpy as np # Constants for the game ROWS = 6 COLUMNS = 7 PLAYER_PIECE = 1 AI_PIECE = 2 EMPTY = 0 WINDOW_LENGTH = 4 def create_board(): return np.zeros((ROWS, COLUMNS), dtype=int) def drop_piece(board, row, col, piece): board[row][col] = piece def is_valid_location(board, col): return...
import pytest from solution import * def test_create_board(): board = create_board() assert board.shape == (ROWS, COLUMNS) assert np.all(board == 0) def test_drop_piece(): board = create_board() drop_piece(board, 0, 0, PLAYER_PIECE) assert board[0][0] == PLAYER_PIECE def test_is_valid_locatio...
[ { "docstring": null, "function_declaration": "def create_board():", "function_name": "create_board", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def drop_piece(board, row, col, piece):", "function_name": "drop_piece", "parameter_list": "(board, row, co...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport numpy as np\n\n# Constants for the game\nROWS = 6\nCOLUMNS = 7\nPLAYER_PIECE = 1\nAI_PIECE = 2\nEMPTY = 0\nWINDOW_LENGTH = 4\n\ndef create_board():\n return np.zeros((RO...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026889", "row_id": 26889, "seed_ids": "['Qwen2-72B-Instruct_65272']" }
0.395773
Filter_26889
I
[ "create_board", "drop_piece", "is_valid_location", "get_next_open_row", "print_board", "winning_move", "score_position", "evaluate_window", "is_terminal_node", "minimax", "get_valid_locations", "pick_best_move" ]
12
[ [ "get_valid_locations", "is_valid_location" ], [ "is_terminal_node", "get_valid_locations" ], [ "is_terminal_node", "winning_move" ], [ "minimax", "drop_piece" ], [ "minimax", "get_next_open_row" ], [ "minimax", "get_valid_locations" ], [ ...
14
[]
false
[]
false
pytest
true
[ "numpy" ]
false
979ddff24d6a38524d3db3fe1790ecd6f244d87e
8885de0a3de44ad4584858714dc778799e127f52
v1.0
instruct
Filter
Filter_26890_I
Given a text file containing a list of strings, write a program that removes all vowels from each string in the list, and prints the resulting strings in a table format, where each row of the table corresponds to a string in the list, and each column of the table corresponds to a vowel-less string of the corresponding ...
def remove_vowels(strings): """ Given a list of strings, removes all vowels from each string and returns the resulting strings. """ vowels = "aeiouAEIOUауоыиэяюёеУОЫИЭЯЮЁЕ" # English and Russian vowels result = [] for s in strings: no_vowels = ''.join(char for char in s if char not in v...
from solution import remove_vowels, print_table import io import sys def test_remove_vowels(): assert remove_vowels(["Hello World!"]) == ["Hll Wrld!"] assert remove_vowels(["Привет мир!"]) == ["Првт мр!"] assert remove_vowels(["你好,世界!"]) == ["你好,世界!"] assert remove_vowels(["Hello World!", "Привет мир!"...
[ { "docstring": "Given a list of strings, removes all vowels from each string and returns the resulting strings.", "function_declaration": "def remove_vowels(strings):", "function_name": "remove_vowels", "parameter_list": "(strings)" }, { "docstring": "Prints the given list of strings in a ta...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def remove_vowels(s):\n \"\"\"\n Remove all vowels from a string.\n\n Parameters:\n s (str): The input string.\n\n Returns:\n str: The string with all vowels removed.\n \"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00026890", "row_id": 26890, "seed_ids": "['Qwen2-72B-Instruct_65273']" }
0.73507
Filter_26890
I
[ "remove_vowels", "print_table" ]
2
[ [ "print_table", "remove_vowels" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4347a671504a00bafb6190dbff8b40e542f5da2c
86c93d39a08c1d2e858bd59e91040208d50adcb3
v1.0
instruct
Filter
Filter_26894_I
Develop a function in Python that calculates the factorial of all Fibonacci numbers between 1 and N, where N is a user-provided input. For the purpose of this task, assume that the Fibonacci sequence starts with 1 and 1 (not 0 and 1). Furthermore, implement this function using recursion. Python's built-in recursion lim...
def fibonacci(n, memo={}): """ Returns the nth Fibonacci number using recursion with memoization. """ if n in memo: return memo[n] if n <= 0: return 0 elif n == 1: return 1 memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo) return memo[n] def factorial(n): ...
from solution import fibonacci, factorial, factorial_of_fibonacci_up_to_n def test_fibonacci(): assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 def test_factorial(): assert factorial(0) ==...
[ { "docstring": "Returns the nth Fibonacci number using recursion with memoization.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": "fibonacci", "parameter_list": "(n, memo={})" }, { "docstring": "Returns the factorial of n using recursion.", "function_declaration...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fib(n, memo={}):\n if n in memo:\n return memo[n]\n if n <= 2:\n return 1\n memo[n] = fib(n-1, memo) + fib(n-2, memo)\n return memo[n]\n\ndef factorial(n):\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026894", "row_id": 26894, "seed_ids": "['Qwen2-72B-Instruct_65278']" }
0.714534
Filter_26894
I
[ "fibonacci", "factorial", "factorial_of_fibonacci_up_to_n" ]
3
[ [ "factorial_of_fibonacci_up_to_n", "factorial" ], [ "factorial_of_fibonacci_up_to_n", "fibonacci" ] ]
2
[]
false
[]
false
pytest
true
[]
true
70a728ff9e53f8712f8fadf02132c7f7ce9a668e
f41ba0da84d3143be46bc01d931831f592571047
v1.0
instruct
Filter
Filter_26924_I
Given a JSON string, write a program to convert it into an equivalent XML string. The JSON string will contain nested objects and arrays. You need to handle any level of nesting in the JSON data.
import json import xml.etree.ElementTree as ET def json_to_xml(json_obj, line_padding=""): """ Converts a JSON object to an XML string. """ elem = ET.Element('root') _convert_json_to_xml(json_obj, elem) return ET.tostring(elem, encoding='unicode') def _convert_json_to_xml(json_obj, parent): ...
from solution import json_to_xml import json def test_json_to_xml_basic(): json_str = '{"greeting": "Hello", "target": {"name": "World"}}' json_obj = json.loads(json_str) xml_str = json_to_xml(json_obj) assert xml_str == '<root><greeting>Hello</greeting><target><name>World</name></target></root>' def ...
[ { "docstring": "Converts a JSON object to an XML string.", "function_declaration": "def json_to_xml(json_obj, line_padding=''):", "function_name": "json_to_xml", "parameter_list": "(json_obj, line_padding='')" }, { "docstring": null, "function_declaration": "def _convert_json_to_xml(json...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nfrom xml.etree.ElementTree import Element, tostring, ElementTree\n\ndef json_to_xml(json_str):\n def build_xml_element(data, parent_element):\n if isinstance(data, dict)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026924", "row_id": 26924, "seed_ids": "['Qwen2-72B-Instruct_65320']" }
0.704462
Filter_26924
I
[ "json_to_xml", "_convert_json_to_xml" ]
2
[ [ "json_to_xml", "_convert_json_to_xml" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ee75d3d2a34822bb4e44095c042f8cee2ce913f
b8cbb664e0d95c28b6e4a33a9263a40dd715db89
v1.0
instruct
Filter
Filter_26937_I
Write a code snippet that adds two matrices of equal sizes and then multiply the resulting matrix by a scalar value. Also, define a function that checks if two matrices are of equal size.
def are_matrices_equal_size(matrix1, matrix2): """ Checks if two matrices are of equal size. Parameters: matrix1 (list of lists): The first matrix. matrix2 (list of lists): The second matrix. Returns: bool: True if matrices are of equal size, False otherwise. """ if len(matrix1) !=...
from solution import are_matrices_equal_size, add_matrices, multiply_matrix_by_scalar def test_are_matrices_equal_size(): assert are_matrices_equal_size([[1, 2], [3, 4]], [[5, 6], [7, 8]]) == True assert are_matrices_equal_size([[1, 2]], [[5, 6], [7, 8]]) == False assert are_matrices_equal_size([[1, 2], [3...
[ { "docstring": "Checks if two matrices are of equal size.\n\nParameters:\nmatrix1 (list of lists): The first matrix.\nmatrix2 (list of lists): The second matrix.\n\nReturns:\nbool: True if matrices are of equal size, False otherwise.", "function_declaration": "def are_matrices_equal_size(matrix1, matrix2):"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_matrices_equal_size(A, B):\n \"\"\"\n Check if two matrices A and B are of equal sizes.\n \"\"\"\n if len(A) != len(B):\n return False\n for row_a, row_b in zip(A...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026937", "row_id": 26937, "seed_ids": "['Qwen2-72B-Instruct_65337']" }
0.473449
Filter_26937
I
[ "are_matrices_equal_size", "add_matrices", "multiply_matrix_by_scalar" ]
3
[ [ "add_matrices", "are_matrices_equal_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
54a8f382363856cc39ac56b379f60581c2445cd5
340088cf80a8a70f559e56a82b7336d178fef567
v1.0
instruct
Filter
Filter_26950_I
Write a Python program to create a dictionary with five elements. Each element should have a key-value pair, where the key is a string and the value is a list of integers. However, each integer in the list should be a prime number. Additionally, ensure that the keys in the dictionary are in lexicographical order. Here ...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def generate_prime_list(size): """Generate a list of prime numbers of specified size.""" primes = [] num = 2 # ...
from solution import create_prime_dict, generate_prime_list, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(17) == True def test_generate_prime_list(): a...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers of specified size.", "function_declaration": "def generate_prime_list(size):", "function_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\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...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026950", "row_id": 26950, "seed_ids": "['Qwen2-72B-Instruct_65358']" }
0.550312
Filter_26950
I
[ "is_prime", "generate_prime_list", "create_prime_dict" ]
3
[ [ "create_prime_dict", "generate_prime_list" ], [ "generate_prime_list", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6f8d9030b8f38daf5ef5e0150de6d1a6c4effa40
06b46d68a40b3c24a63a59c88362266568c15bf2
v1.0
instruct
Filter
Filter_26955_I
Create a list of the first 1000 prime numbers using Python, but without using any built-in functions or libraries for prime number generation or checking. Your solution should have a time complexity of O(n^2) or better.
def is_prime(number): """ Helper function to determine if a number is prime. """ if number <= 1: return False for i in range(2, int(number ** 0.5) + 1): if number % i == 0: return False return True def generate_primes(n): """ Generates first n prime numbers. ...
from solution import generate_primes, is_prime def test_is_prime(): assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(29) assert not is_prime(30) def test_generate_primes(): primes = generat...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Generates first n prime numbers.", "function_declaration": "def generate_primes(n):", "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 Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True # 2 is t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026955", "row_id": 26955, "seed_ids": "['Qwen2-72B-Instruct_65365']" }
0.573211
Filter_26955
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d91439b33d67ce13f05e890e4ca2efb755525c59
a3b762cf1e55cef88ab3409e49de668bc7fb6256
v1.0
instruct
Filter
Filter_26971_I
Write a function in Python that takes two date objects, `date1` and `date2`, as arguments. The function should return a string in the format "Day, Month Day, Year" representing the date that is the middle date between `date1` and `date2`. If `date1` and `date2` are on the same day, return `date1` or `date2`. Ensure you...
from datetime import date, timedelta def format_date(dt): """ Convert a date object to a string in the format "Day, Month Day, Year". """ return dt.strftime("%A, %B %d, %Y") def middle_date(date1, date2): """ Return the middle date between date1 and date2 as a formatted string. If date1 an...
from datetime import date from solution import middle_date def test_middle_date_same_dates(): assert middle_date(date(2023, 9, 19), date(2023, 9, 19)) == "Tuesday, September 19, 2023" def test_middle_date_different_dates_same_month(): assert middle_date(date(2023, 9, 18), date(2023, 9, 20)) == "Tuesday, Septe...
[ { "docstring": "Convert a date object to a string in the format \"Day, Month Day, Year\".", "function_declaration": "def format_date(dt):", "function_name": "format_date", "parameter_list": "(dt)" }, { "docstring": "Return the middle date between date1 and date2 as a formatted string.\nIf da...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import date, timedelta\n\ndef format_date(dt):\n \"\"\"\n Convert a date object to a string in the format \"Day, Month Day, Year\".\n \"\"\"\n return dt.strftime(\"%A...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026971", "row_id": 26971, "seed_ids": "['Qwen2-72B-Instruct_65392']" }
0.632097
Filter_26971
I
[ "format_date", "middle_date" ]
2
[ [ "middle_date", "format_date" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0de680bb96966c3fdb868fe4fa60a021171e57c2
222cf2c2287d1b6d4b5cb54e7bd72a4f1e3ce4ad
v1.0
instruct
Filter
Filter_26974_I
Use the softmax function and cross-entropy loss function to implement a multi-class classifier in Python.
import numpy as np def softmax(logits): """ Compute the softmax of a list of numbers. Args: logits (np.array): An array of logits (raw class scores). Returns: np.array: The softmax probabilities. """ exp_values = np.exp(logits - np.max(logits)) probabilities = exp_values /...
from solution import softmax, cross_entropy_loss, predict import numpy as np def test_softmax(): logits = np.array([1.0, 2.0, 3.0]) probabilities = softmax(logits) assert np.isclose(np.sum(probabilities), 1.0, atol=1e-6) assert probabilities.shape == logits.shape def test_cross_entropy_loss(): pre...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef softmax(logits):\n \"\"\"\n Compute the softmax of vector logits.\n \"\"\"\n exp_logits = np.exp(logits - np.max(logits))\n return exp_logits / np.sum(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00026974", "row_id": 26974, "seed_ids": "['Qwen2-72B-Instruct_65396']" }
0.500131
Filter_26974
I
[ "softmax", "cross_entropy_loss", "predict" ]
3
[ [ "predict", "softmax" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
d3eb903bddaae3f5343b31d5c8f694a9035de343
37adc0301ed7ebec7460982851f958e80f2ffdd7
v1.0
instruct
Filter
Filter_26980_I
Use the turtle graphics library in the Python programming language to produce a visual output resembling the Fibonacci sequence, while implementing a recursive function that can handle input values up to 100. Incorporate proper exception handling for invalid inputs. Note that the Fibonacci sequence begins with 0 and 1,...
import turtle def draw_fibonacci_spiral(n, length): """ Draws a Fibonacci spiral for the first `n` Fibonacci numbers. Parameters: n (int): The number of Fibonacci numbers to include in the spiral. length (int): The initial length of the sides of the squares. """ screen = turtle.Screen(...
from solution import get_fibonacci_sequence def test_get_fibonacci_sequence_zero_terms(): assert get_fibonacci_sequence(0) == [] def test_get_fibonacci_sequence_one_term(): assert get_fibonacci_sequence(1) == [0] def test_get_fibonacci_sequence_two_terms(): assert get_fibonacci_sequence(2) == [0, 1] def...
[ { "docstring": "Draws a Fibonacci spiral for the first `n` Fibonacci numbers.\n\nParameters:\nn (int): The number of Fibonacci numbers to include in the spiral.\nlength (int): The initial length of the sides of the squares.", "function_declaration": "def draw_fibonacci_spiral(n, length):", "function_nam...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import turtle\n\ndef draw_fibonacci_spiral(n, length):\n \"\"\"\n Draws a Fibonacci spiral for the first `n` Fibonacci numbers.\n \n Parameters:\n n (int): The number of Fibonac...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00026980", "row_id": 26980, "seed_ids": "['Qwen2-72B-Instruct_65406']" }
0.654949
Filter_26980
I
[ "draw_fibonacci_spiral", "draw_square", "get_fibonacci_sequence" ]
3
[ [ "draw_fibonacci_spiral", "draw_square" ], [ "draw_fibonacci_spiral", "get_fibonacci_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f74f58f9f93d7f8f6836cc203ec2e630c8d90a3
95bdece08201804b9478da4d0662f4e858fd865f
v1.0
instruct
Filter
Filter_27008_I
Write a Python program to print the prime numbers from a specified list of integers, but also check and handle possible exceptions elegantly. Your input list will include negative numbers, zero, non-integer types, and strings which need to be filtered out. For instance, your program should be able to handle inputs like...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def filter_primes(nums): """Filter pri...
from solution import filter_primes def test_filter_primes_with_mixed_inputs(): input_data = [11, "string", 4, 19.5, -7, 0, 13] expected_output = [11, 13] assert filter_primes(input_data) == expected_output def test_filter_primes_with_all_primes(): input_data = [2, 3, 5, 7, 11, 13, 17] expected_out...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filter prime numbers from a specified list of integers.", "function_declaration": "def filter_primes(nums):", "function_na...
[ 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 Determines if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027008", "row_id": 27008, "seed_ids": "['Qwen2-72B-Instruct_65454']" }
0.652726
Filter_27008
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad320e26ecbe0bba9a5e0da01f315f7d5320ac41
1cfb3ad3e37f86593246f3ceb39c7c3135035524
v1.0
instruct
Filter
Filter_27010_I
How can you modify the given code to add a new functionality that allows the user to input a range of numbers and print the sum of all prime numbers in that range?
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_of_primes_in_range(start, end): """ Returns the sum of all prime numbers in the g...
from solution import is_prime, sum_of_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_sum_of_primes_in_range(): assert sum_of_primes_in_range(2, 10) == 17 #...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers in the given range [start, end].", "function_declaration": "def sum_of_prime...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027010", "row_id": 27010, "seed_ids": "['Qwen2-72B-Instruct_65456']" }
0.557836
Filter_27010
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
da28ec4858a5ae1b490d03bdc9ed350b1db0a290
654029e2fd64e33aebce78a50c2866ab919d7d63
v1.0
instruct
Filter
Filter_27023_I
Create a function that applies a gated linear unit (GLU) activation function to the input data. The GLU function takes a weight matrix, an input vector, and a bias vector as inputs. The weight matrix should have a shape of (input_size, output_size), the input vector should have a shape of (input_size,), and the bias ve...
import numpy as np def glu(weight_matrix, input_vector, bias_vector): """ Applies the Gated Linear Unit (GLU) activation function to the input data. Parameters: weight_matrix (numpy.ndarray): Weight matrix of shape (input_size, output_size). input_vector (numpy.ndarray): Input vector of shape (inp...
import numpy as np from solution import glu, sigmoid def test_glu_output_shape(): weight_matrix = np.random.rand(4, 4) input_vector = np.random.rand(4) bias_vector = np.random.rand(4) output = glu(weight_matrix, input_vector, bias_vector) assert output.shape == (2,), "Output shape is incorrect" de...
[ { "docstring": "Applies the Gated Linear Unit (GLU) activation function to the input data.\n\nParameters:\nweight_matrix (numpy.ndarray): Weight matrix of shape (input_size, output_size).\ninput_vector (numpy.ndarray): Input vector of shape (input_size,).\nbias_vector (numpy.ndarray): Bias vector of shape (outp...
[ 1, 0, 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 glu(weight_matrix, input_vector, bias_vector):\n \"\"\"\n Applies the Gated Linear Unit (GLU) activation function to the input data.\n\n Parameters:\n wei...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027023", "row_id": 27023, "seed_ids": "['Qwen2-72B-Instruct_65471']" }
0.37564
Filter_27023
I
[ "glu", "sigmoid" ]
2
[ [ "glu", "sigmoid" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
704a6c6ae3f76e091e8624eefb6e23656bab5115
5fc33eab574fb2ef231ec491cf09966defe72cc7
v1.0
instruct
Filter
Filter_27061_I
Write a Python code snippet to check if an integer is both prime and between 5 and 10 (including both). The code should handle incorrect input types gracefully and return an error message for invalid inputs.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def is_prime_between_5_and_10(n): """ Checks if an integer is both prime and be...
from solution import is_prime_between_5_and_10 def test_is_prime_between_5_and_10_with_prime_numbers(): assert is_prime_between_5_and_10(5) == True assert is_prime_between_5_and_10(7) == True def test_is_prime_between_5_and_10_with_non_prime_numbers(): assert is_prime_between_5_and_10(6) == False asse...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Checks if an integer is both prime and between 5 and 10 (inclusive).\nReturns:\n True if the number is p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime_and_in_range(n):\n \"\"\"\n Check if the input integer is prime and between 5 and 10 (inclusive).\n \"\"\"\n if not isinstance(n, int):\n return \"Invalid input...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027061", "row_id": 27061, "seed_ids": "['Qwen2-72B-Instruct_65538']" }
0.686105
Filter_27061
I
[ "is_prime", "is_prime_between_5_and_10" ]
2
[ [ "is_prime_between_5_and_10", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72c14e71967637f523adccad6b8729c158246548
3db431cb6ffc404f736926faab206a2bbeb7f776
v1.0
instruct
Filter
Filter_27071_I
Write a Python script that identifies and prints the first 10 prime numbers between 1 and 1000 that are also palindromes. Factor in efficiency and ensure your code is optimized for speed.
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 is_palindrome(n): """Check if...
from solution import is_prime, is_palindrome, first_10_palindromic_primes_in_range def test_is_prime(): # Test some known primes and non-primes assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(97) == True assert is...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palind...
[ 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_2
{ "original_instruction": "", "prompt_id": "00027071", "row_id": 27071, "seed_ids": "['Qwen2-72B-Instruct_65549']" }
0.662031
Filter_27071
I
[ "is_prime", "is_palindrome", "first_10_palindromic_primes_in_range" ]
3
[ [ "first_10_palindromic_primes_in_range", "is_palindrome" ], [ "first_10_palindromic_primes_in_range", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e5eca9ceceed6c34cb9d9d6c50c62be30e90693f
5ed6b36db115b6af717ea1d6165b7be297d4d5e6
v1.0
instruct
Filter
Filter_27089_I
Create a program that can generate a sequence of prime numbers between 10,000 and 20,000 using the Sieve of Eratosthenes algorithm. The program should be able to handle larger numerical ranges with optimized performance, taking into account memory and processing limitations. Additionally, the program should provide the...
def sieve_of_eratosthenes(start, end): """ Generates a list of prime numbers in the given range [start, end] using the Sieve of Eratosthenes algorithm. """ if end < 2: return [] sieve = [True] * (end + 1) p = 2 while (p * p <= end): if sieve[p]: for i in ran...
from solution import sieve_of_eratosthenes, format_prime_table def test_sieve_of_eratosthenes_default_range(): primes = sieve_of_eratosthenes(10000, 20000) assert 10007 in primes assert 19997 in primes assert 10000 not in primes assert 20000 not in primes def test_sieve_of_eratosthenes_small_range...
[ { "docstring": "Generates a list of prime numbers in the given range [start, end]\nusing the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(start, end):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(start, end)" }, { "docstring": "Form...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(start, end):\n \"\"\"\n Generates a list of prime numbers in the given range [start, end]\n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n if en...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027089", "row_id": 27089, "seed_ids": "['Qwen2-72B-Instruct_65588']" }
0.534616
Filter_27089
I
[ "sieve_of_eratosthenes", "format_prime_table", "generate_and_print_primes" ]
3
[ [ "generate_and_print_primes", "format_prime_table" ], [ "generate_and_print_primes", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5024d6da845dd5ed62a2063f1f668a28b227eec6
b00ee6c152fc7d5e513bb4ad6fbcb46a9d76c3c5
v1.0
instruct
Filter
Filter_27095_I
Generate a random letter from the string provided without using any built-in random functions or libraries. The string must contain at least 100 characters. The time complexity of your solution should be O(log n) and the space complexity should be O(1), where n is the length of the string. Additionally, the generated r...
def pseudo_random(seed): """ Generates a pseudo-random integer based on a seed using linear congruential generator algorithm. """ a = 1664525 c = 1013904223 m = 2 ** 32 return (a * seed + c) % m def get_random_index(num_chars, seed): """ Generates a pseudo-random index based on the ...
from solution import get_random_letter def test_random_letter_uniformity(): large_string = "a" * 100 + "b" * 100 + "c" * 100 seed = 12345 counts = {"a": 0, "b": 0, "c": 0} num_trials = 300 for _ in range(num_trials): char = get_random_letter(large_string, seed) counts[char] += ...
[ { "docstring": "Generates a pseudo-random integer based on a seed using linear congruential generator algorithm.", "function_declaration": "def pseudo_random(seed):", "function_name": "pseudo_random", "parameter_list": "(seed)" }, { "docstring": "Generates a pseudo-random index based on the ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def pseudo_random(seed):\n \"\"\"\n Generates a pseudo-random integer based on a seed using linear congruential generator algorithm.\n \"\"\"\n a = 1664525\n c = 1013904223\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027095", "row_id": 27095, "seed_ids": "['Qwen2-72B-Instruct_65596']" }
0.614834
Filter_27095
I
[ "pseudo_random", "get_random_index", "get_random_letter" ]
3
[ [ "get_random_index", "pseudo_random" ], [ "get_random_letter", "get_random_index" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fa9104cbc3f7bac4d534c7fbdb7b1d85e3c47429
59dd8d34a03ac5ced8fa1bc206bee021be8d8fc4
v1.0
instruct
Filter
Filter_27104_I
Devise a coding test question asking for the creation of a binary search tree (BST) from a list of integers. Additionally, include a requirement for a function to verify the BST property.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) ...
from solution import create_bst_from_list, is_bst, TreeNode def test_create_bst_from_list(): values = [10, 5, 15, 3, 7, 12, 18] bst = create_bst_from_list(values) assert bst.value == 10 assert bst.left.value == 5 assert bst.left.left.value == 3 assert bst.left.right.value == 7 assert b...
[]
[ 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef construct_bst(lst):\n if not lst:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027104", "row_id": 27104, "seed_ids": "['Qwen2-72B-Instruct_65613']" }
0.479949
Filter_27104
I
[ "insert_into_bst", "create_bst_from_list", "is_bst" ]
3
[ [ "create_bst_from_list", "insert_into_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
558bd54c81084d5e02971449642de9aa7792cb41
6f56398d7067bafa12dfa032c3270c9adfef03bb
v1.0
instruct
Filter
Filter_27121_I
Can you explain how the function merge_sort() works in the given Python code for sorting an array? Specifically, could you provide a detailed explanation of the base case of the recursion, how the input array is split and merged, and how the sorted subarrays are recursively produced? Additionally, please describe the t...
def merge_sort(arr): """ Sorts an array using the merge sort algorithm. Parameters: arr (list): The list to be sorted. Returns: list: The sorted list. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr...
import pytest from solution import merge_sort def test_merge_sort_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_array(): assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_merge_sort_unsorted_array(): assert merge_sort([3, 1, 4, 1, 5,...
[ { "docstring": "Sorts an array using the merge sort algorithm.\n\nParameters:\narr (list): The list to be sorted.\n\nReturns:\nlist: The sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorte...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half = arr[mid:]\n \n left_sorted = merge_sort(left_h...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027121", "row_id": 27121, "seed_ids": "['Qwen2-72B-Instruct_65642']" }
0.587567
Filter_27121
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b0febe5a0fd28928b61aa51d41639c04f36bd00
2ae1c87bfb07a7b2fb36f3b436dc0fa53fec5be8
v1.0
instruct
Filter
Filter_27128_I
Write a piece of code to print the first 20 Fibonacci numbers in Python. Additionally, implement the program using recursion and ensure that the program can handle a scenario where the user can request the 'n'th Fibonacci number (where n can be any positive integer) without computing the entire sequence up to 'n'. Be s...
def fibonacci_recursive(n): """ Returns the nth Fibonacci number using recursion. Parameters: n (int): The position in the Fibonacci sequence (1-based index) Returns: int: The nth Fibonacci number """ if not isinstance(n, int) or n < 1: raise ValueError("Input should be...
from solution import fibonacci_recursive, first_n_fibonacci def test_fibonacci_recursive(): assert fibonacci_recursive(1) == 0 assert fibonacci_recursive(2) == 1 assert fibonacci_recursive(3) == 1 assert fibonacci_recursive(5) == 3 assert fibonacci_recursive(10) == 34 def test_fibonacci_recursive_...
[ { "docstring": "Returns the nth Fibonacci number using recursion.\n\nParameters:\nn (int): The position in the Fibonacci sequence (1-based index)\n\nReturns:\nint: The nth Fibonacci number", "function_declaration": "def fibonacci_recursive(n):", "function_name": "fibonacci_recursive", "parameter_lis...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Returns the n-th Fibonacci number.\n Handles memoization to improve performance.\n \"\"\"\n if not isinstance(n, int) or n < 0:\n ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027128", "row_id": 27128, "seed_ids": "['Qwen2-72B-Instruct_65650']" }
0.781951
Filter_27128
I
[ "fibonacci_recursive", "first_n_fibonacci" ]
2
[ [ "first_n_fibonacci", "fibonacci_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c2fe9de60ac5533b5106c627091120a9d7f9db8
49873f374782b0592dc8b8d526a0c901bd0f6f33
v1.0
instruct
Filter
Filter_27129_I
Create a python function that performs an exponential search on a sorted list. This function should include exception handling for cases where the list is not sorted or does not contain the target number.
def exponential_search(arr, target): """ Performs an exponential search on a sorted list for the target value. Parameters: arr (list): A sorted list of numbers target (int/float): The number to search for Returns: int: The index of the target in the list, or -1 if the target is not...
import pytest from solution import exponential_search def test_exponential_search_found(): arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert exponential_search(arr, 5) == 4 assert exponential_search(arr, 1) == 0 assert exponential_search(arr, 10) == 9 def test_exponential_search_not_found(): arr = [1, ...
[ { "docstring": "Performs an exponential search on a sorted list for the target value.\n\nParameters:\narr (list): A sorted list of numbers\ntarget (int/float): The number to search for\n\nReturns:\nint: The index of the target in the list, or -1 if the target is not found\n\nRaises:\nValueError: If the list is ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def exponential_search(arr, target):\n \"\"\"\n Performs an exponential search on a sorted list.\n \n Parameters:\n arr (list): A sorted list of elements to search.\n target ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027129", "row_id": 27129, "seed_ids": "['Qwen2-72B-Instruct_65656']" }
0.660748
Filter_27129
I
[ "exponential_search", "binary_search" ]
2
[ [ "exponential_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0203becde91639048d1790923b4c6ee767c660d
8220830f23c8701d4292e135da71e7702ae63d26
v1.0
instruct
Filter
Filter_27139_I
Write a Python function to generate a random password using a mix of uppercase characters, lowercase characters, digits, and special characters. Also add functionality to generate multiple passwords - the number of passwords and the length of each password should be parameters of the function. The password should not c...
import random import string def has_sequential(s): """ Checks if the string contains any sequential characters. """ for i in range(len(s) - 2): if (ord(s[i]) + 1 == ord(s[i + 1]) and ord(s[i + 1]) + 1 == ord(s[i + 2])): return True return False def generate_password(length): ...
from solution import generate_passwords def test_generate_password_length(): for length in range(4, 10): passwords = generate_passwords(1, length) assert len(passwords[0]) == length def test_generate_password_count(): passwords = generate_passwords(5, 8) assert len(passwords) == 5 for ...
[ { "docstring": "Checks if the string contains any sequential characters.", "function_declaration": "def has_sequential(s):", "function_name": "has_sequential", "parameter_list": "(s)" }, { "docstring": "Generates a single password with the given length.\nThe password will contain at least on...
[ 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 string\n\ndef has_sequential(s):\n \"\"\"\n Checks if the string contains any sequential characters.\n \"\"\"\n for i in range(len(s) - 2):\n if (ord(s...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027139", "row_id": 27139, "seed_ids": "['Qwen2-72B-Instruct_65673']" }
0.794556
Filter_27139
I
[ "has_sequential", "generate_password", "generate_passwords" ]
3
[ [ "generate_password", "has_sequential" ], [ "generate_passwords", "generate_password" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a1fbdbf62f68dad6c9bbd8ab6c6256a1ebd94784
0fee3aef86079f93b3c507ab161a2efd93d0c1e2
v1.0
instruct
Filter
Filter_27161_I
I want to create an AI program that can optimize the route for a package delivery system. How can I achieve this using Python?
import itertools import sys def calculate_distance(point1, point2): """ Calculate the Euclidean distance between two points. Each point is a tuple of (x, y) """ return ((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) ** 0.5 def optimize_route(locations): """ Optimize the deliv...
from solution import calculate_distance, optimize_route def test_calculate_distance(): assert calculate_distance((0, 0), (3, 4)) == 5 assert calculate_distance((1, 1), (4, 5)) == 5 assert calculate_distance((2, 3), (5, 1)) == 3.605551275463989 def test_optimize_route_single_location(): locations = [(0...
[ { "docstring": "Calculate the Euclidean distance between two points.\nEach point is a tuple of (x, y)", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Optimize the delivery rout...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start):\n \"\"\"\n Implementation of the Dijkstra algorithm to find the shortest paths from start node.\n \"\"\"\n queue = [(0, start)]\n dis...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027161", "row_id": 27161, "seed_ids": "['Qwen2-72B-Instruct_65713']" }
0.416901
Filter_27161
I
[ "calculate_distance", "optimize_route" ]
2
[ [ "optimize_route", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad9c6eb6e0ce4380ef448e864a8c98cd8d6087c3
861c992d29a5ccf6d7de6099525bd39958a7adb9
v1.0
instruct
Filter
Filter_27217_I
Develop a Python program to implement the K-Means Clustering algorithm without using any machine learning libraries, such as scikit-learn. Your code should be able to take a dataset as input and output the cluster labels for each data point.
import random def initialize_centroids(data, k): """ Initialize k centroids randomly from the data points. """ return random.sample(data, k) def assign_clusters(data, centroids): """ Assign each data point to the nearest centroid. """ clusters = [[] for _ in range(len(centroids))] ...
from solution import k_means, initialize_centroids, assign_clusters, calculate_new_centroids, euclidean_distance, calculate_mean def test_initialize_centroids(): data = [[1.0, 2.0], [1.5, 1.8], [5.0, 8.0]] k = 2 centroids = initialize_centroids(data, k) assert len(centroids) == k assert all(centroi...
[ { "docstring": "Initialize k centroids randomly from the data points.", "function_declaration": "def initialize_centroids(data, k):", "function_name": "initialize_centroids", "parameter_list": "(data, k)" }, { "docstring": "Assign each data point to the nearest centroid.", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport math\n\ndef k_means_clustering(dataset, k, max_iterations=100):\n def euclidean_distance(point1, point2):\n return math.sqrt(sum((x - y) ** 2 for x, y in zip(po...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027217", "row_id": 27217, "seed_ids": "['Qwen2-72B-Instruct_65811']" }
0.683879
Filter_27217
I
[ "initialize_centroids", "assign_clusters", "calculate_new_centroids", "euclidean_distance", "calculate_mean", "k_means" ]
6
[ [ "assign_clusters", "euclidean_distance" ], [ "calculate_new_centroids", "calculate_mean" ], [ "k_means", "assign_clusters" ], [ "k_means", "calculate_new_centroids" ], [ "k_means", "initialize_centroids" ] ]
5
[]
false
[]
false
pytest
true
[]
true
e90fce7e7f521b3792454b8f7d98888f3ee34eed
341952f5b4788f59df769e97189c1996b8baea52
v1.0
instruct
Filter
Filter_27239_I
Write a recursive function in Python to calculate the Least Common Multiple (L.C.M) of a list of numbers. Furthermore, to make this challenge more interesting, the function should handle any amount of numbers in the list and also manage errors if unsuitable data types or negative numbers are given in the list.
def gcd(a, b): """ Helper function to calculate the Greatest Common Divisor (GCD) of two numbers. """ while b: a, b = b, a % b return a def lcm(a, b): """ Helper function to calculate the Least Common Multiple (LCM) of two numbers. """ return abs(a * b) // gcd(a, b) def lcm...
import pytest from solution import gcd, lcm, lcm_list def test_gcd(): assert gcd(12, 15) == 3 assert gcd(100, 25) == 25 assert gcd(7, 5) == 1 def test_lcm(): assert lcm(12, 15) == 60 assert lcm(3, 5) == 15 assert lcm(7, 5) == 35 assert lcm(0, 5) == 0 # Note: lcm involving 0 should be hand...
[ { "docstring": "Helper function to calculate the Greatest Common Divisor (GCD) of two numbers.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Helper function to calculate the Least Common Multiple (LCM) of two numbers.", ...
[ 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 lcm(a, b):\n \"\"\"\n Returns the least common multiple of two numbers a and b.\n \"\"\"\n return abs(a * b) // math.gcd(a, b)\n \ndef lcm_of_list(numbers):\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027239", "row_id": 27239, "seed_ids": "['Qwen2-72B-Instruct_65847']" }
0.615219
Filter_27239
I
[ "gcd", "lcm", "lcm_list" ]
3
[ [ "lcm", "gcd" ], [ "lcm_list", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
29527b7031264464b9ba6924aac39c6fcf0199b3
a3bd3f8c4cd0e747dc81f7e6baf5c375e127ca43
v1.0
instruct
Filter
Filter_27248_I
Build a Python code snippet to print the diamond structure with the specified number of rows. This code should include two functions: one for generating a single row of the diamond pattern, and another for rendering the complete diamond figure. Incorporate input validation to ensure the row number is an odd integer and...
def generate_diamond_row(n, row): """ Generates a single row of the diamond pattern. Args: n (int): Total number of rows in the diamond. row (int): The current row number to generate. Returns: str: A string representation of the row in the diamond. """ spaces = abs((n // 2)...
from solution import generate_diamond_row, print_diamond def test_generate_diamond_row(): assert generate_diamond_row(5, 0) == ' * ' assert generate_diamond_row(5, 1) == ' *** ' assert generate_diamond_row(5, 2) == '*****' assert generate_diamond_row(5, 3) == ' *** ' assert generate_diamond_row(5...
[ { "docstring": "Generates a single row of the diamond pattern.\n\nArgs:\nn (int): Total number of rows in the diamond.\nrow (int): The current row number to generate.\n\nReturns:\nstr: A string representation of the row in the diamond.", "function_declaration": "def generate_diamond_row(n, row):", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_row(row_num, total_rows):\n \"\"\"\n Generates a single row of the diamond pattern.\n Each row consists of spaces followed by stars.\n \n Args:\n row_num: The cu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027248", "row_id": 27248, "seed_ids": "['Qwen2-72B-Instruct_65857']" }
0.443327
Filter_27248
I
[ "generate_diamond_row", "print_diamond" ]
2
[ [ "print_diamond", "generate_diamond_row" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc0351a9e46f8ad581dd831e5c2e64d2be23b525
411d0d10afe0e0d250f6193a1968697417b35aa9
v1.0
instruct
Filter
Filter_27249_I
Write code to print the first 100 prime numbers in reverse order, but exclude any numbers that are palindromic primes.
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 r...
from solution import is_prime, is_palindrome, first_100_primes_excluding_palindromes 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(97) == True assert is_prime(1) == False assert is_prime(0) ...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_pali...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027249", "row_id": 27249, "seed_ids": "['Qwen2-72B-Instruct_65858']" }
0.527348
Filter_27249
I
[ "is_prime", "is_palindrome", "first_100_primes_excluding_palindromes" ]
3
[ [ "first_100_primes_excluding_palindromes", "is_palindrome" ], [ "first_100_primes_excluding_palindromes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
639cf846894c80f6addcac7356a4cd0bc17d6164
821602d4f701cf3f390388590b8ca64de30ff790
v1.0
instruct
Filter
Filter_27250_I
Given a set of coordinates representing cities on a map, write a Python program to find the shortest path that visits each city exactly once and returns to the original city (the traveling salesman problem). Use the nearest neighbor algorithm for simplicity. Note that the optimal solution uses the minimum spanning tree...
def calculate_distance(city1, city2): """ Calculates the Euclidean distance between two cities. """ import math return math.sqrt((city2[0] - city1[0])**2 + (city2[1] - city1[1])**2) def nearest_neighbor_tsp(cities): """ Implements the nearest neighbor algorithm to approximate the solution ...
from solution import nearest_neighbor_tsp, calculate_distance def test_calculate_distance(): assert calculate_distance((0, 0), (3, 4)) == 5.0 assert calculate_distance((1, 1), (4, 5)) == 5.0 assert calculate_distance((2, 3), (2, 3)) == 0.0 def test_nearest_neighbor_tsp(): cities = [(0, 0), (2, 2), (2,...
[ { "docstring": "Calculates the Euclidean distance between two cities.", "function_declaration": "def calculate_distance(city1, city2):", "function_name": "calculate_distance", "parameter_list": "(city1, city2)" }, { "docstring": "Implements the nearest neighbor algorithm to approximate the s...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def nearest_neighbor_tsp(cities):\n \"\"\"\n Implements the nearest neighbor algorithm to find an approximate solution to the traveling salesman problem.\n \n :param cities: List o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027250", "row_id": 27250, "seed_ids": "['Qwen2-72B-Instruct_65860']" }
0.61965
Filter_27250
I
[ "calculate_distance", "nearest_neighbor_tsp" ]
2
[ [ "nearest_neighbor_tsp", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87f22ef8d42542c0a99094ebe7bc86b977795bd2
0d5e37f03bc1322052c92df4057ac4062ff4bdc1
v1.0
instruct
Filter
Filter_27288_I
Write a Python code that creates a dictionary where keys are the first five factorial numbers and their values are the Fibonacci numbers corresponding to the length of their binary representations. Additionally, include a function that computes the factorial and the Fibonacci sequence. Both functions must implement and...
def factorial(n): """ Returns the factorial of n using recursion. """ if n == 0 or n == 1: return 1 else: return n * factorial(n-1) def fibonacci(n): """ Returns the nth Fibonacci number using recursion. """ if n == 0: return 0 elif n == 1: ...
from solution import factorial, fibonacci, factorial_fibonacci_mapping def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 def test_fibonacci(): assert fibonacci(0) ==...
[ { "docstring": "Returns the factorial of n using recursion.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the nth Fibonacci number using recursion.", "function_declaration": "def fibonacci(n):", "functi...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Recursive function to compute the factorial of a number.\n \"\"\"\n if n == 0:\n return 1\n else:\n return n * factorial(n - 1)\n\ndef...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027288", "row_id": 27288, "seed_ids": "['Qwen2-72B-Instruct_65934']" }
0.703575
Filter_27288
I
[ "factorial", "fibonacci", "factorial_fibonacci_mapping" ]
3
[ [ "factorial_fibonacci_mapping", "factorial" ], [ "factorial_fibonacci_mapping", "fibonacci" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3d846aa75c1a425ea391739c3fe6ac7aa7c5835d
01c51f271ad4ecb13bdd01f47628cf21a859c2f9
v1.0
instruct
Filter
Filter_27302_I
Fibonacci sequence in Python using list comprehension vs for loop, which is faster?
import time # Function to generate Fibonacci sequence using list comprehension def fibonacci_list_comprehension(n): fib = [0, 1] [fib.append(fib[-2] + fib[-1]) for _ in range(2, n)] return fib[:n] # Function to generate Fibonacci sequence using for loop def fibonacci_for_loop(n): fib = [0, 1] for ...
from solution import ( fibonacci_list_comprehension, fibonacci_for_loop, compare_fibonacci_methods ) def test_fibonacci_list_comprehension(): assert fibonacci_list_comprehension(0) == [] assert fibonacci_list_comprehension(1) == [0] assert fibonacci_list_comprehension(2) == [0, 1] assert fi...
[ { "docstring": null, "function_declaration": "def fibonacci_list_comprehension(n):", "function_name": "fibonacci_list_comprehension", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def fibonacci_for_loop(n):", "function_name": "fibonacci_for_loop", "para...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef fibonacci_list_comprehension(n):\n \"\"\"\n Generates the first n Fibonacci numbers using list comprehension.\n \"\"\"\n fib = [0, 1]\n [fib.append(fib[-1] + ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027302", "row_id": 27302, "seed_ids": "['Qwen2-72B-Instruct_65954']" }
0.517698
Filter_27302
I
[ "fibonacci_list_comprehension", "fibonacci_for_loop", "compare_fibonacci_methods" ]
3
[ [ "compare_fibonacci_methods", "fibonacci_for_loop" ], [ "compare_fibonacci_methods", "fibonacci_list_comprehension" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b2f62485ce8fb61b9ea9616ff8ba2135d8641000
79d07fea0f9a5bd76a78cabb53e22723ce36f299
v1.0
instruct
Filter
Filter_27325_I
I want to generate a list of prime numbers between two given numbers. Can you provide a code for that in Python?
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 max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True def ...
from solution import is_prime, prime_numbers_between def test_is_prime(): assert not is_prime(-10) assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(11) def test_prime...
[ { "docstring": "Check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers between a and b (exclusive).", "function_declaration": "def prime_numbers_between(a, b):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027325", "row_id": 27325, "seed_ids": "['Qwen2-72B-Instruct_65996']" }
0.60248
Filter_27325
I
[ "is_prime", "prime_numbers_between" ]
2
[ [ "prime_numbers_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b16caff71de23edb995e04ceeca5c334eb4918bc
bb6b73eee1a5310b98db0f756465b0ccca5b7e25
v1.0
instruct
Filter
Filter_27330_I
Craft a sequence displaying the initial 10 numbers in the Fibonacci series, utilizing any coding language. Instead of using arrays, implement the code using recursion and without the assistance of any libraries or built-in functions specifically designed for the Fibonacci sequence. Additionally, include a functionality...
def fib(n): """ Recursively calculates the n-th Fibonacci number. """ if n <= 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) def fib_sequence(n_terms): """ Generates the first n_terms of the Fibonacci sequence. """ sequence = [] fo...
from solution import fib, fib_sequence, sum_fib_sequence def test_fib(): assert fib(0) == 0 assert fib(1) == 1 assert fib(2) == 1 assert fib(3) == 2 assert fib(4) == 3 assert fib(5) == 5 assert fib(6) == 8 assert fib(7) == 13 assert fib(8) == 21 assert fib(9) == 34 def test_fib...
[ { "docstring": "Recursively calculates the n-th Fibonacci number.", "function_declaration": "def fib(n):", "function_name": "fib", "parameter_list": "(n)" }, { "docstring": "Generates the first n_terms of the Fibonacci sequence.", "function_declaration": "def fib_sequence(n_terms):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fibonacci(n-1)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027330", "row_id": 27330, "seed_ids": "['Qwen2-72B-Instruct_66001']" }
0.716965
Filter_27330
I
[ "fib", "fib_sequence", "sum_fib_sequence" ]
3
[ [ "fib_sequence", "fib" ] ]
1
[]
false
[]
false
pytest
true
[]
true
62c6fa7628420bdcdd84f32de7dffb2e1f99b83c
d17efa6ca718c5270aa374bd65ecff63e1862682
v1.0
instruct
Filter
Filter_27331_I
Write a simple python code that given a number N, print all prime numbers till N.
def is_prime(num): """ Returns True if the number is prime, 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: r...
from solution import is_prime, print_primes_till_n def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(29) == True def test_print_primes_till_10(): assert print_prime...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given a number N, print all prime numbers till N.", "function_declaration": "def print_primes_ti...
[ 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 == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027331", "row_id": 27331, "seed_ids": "['Qwen2-72B-Instruct_66003']" }
0.708845
Filter_27331
I
[ "is_prime", "print_primes_till_n" ]
2
[ [ "print_primes_till_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b5cce46b734432787d449c2767fc25c186b3e04
554c93c6e3bf1b95e82019985108f9b1856983a2
v1.0
instruct
Filter
Filter_27334_I
Given a string containing mixed uppercase, lowercase letters, and special characters, create a dictionary in Python mapping the uppercase English alphabet letters to their corresponding ordinal values ranging from 1 to 26. Additionally, write a function that takes this string as an input, processes it character by char...
def create_uppercase_dict(): uppercase_dict = {chr(i): i - ord('A') + 1 for i in range(ord('A'), ord('Z') + 1)} return uppercase_dict def replace_uppercase(input_string): uppercase_dict = create_uppercase_dict() result = "" for char in input_string: if char in uppercase_dict: re...
from solution import replace_uppercase def test_replace_uppercase_all_uppercase(): assert replace_uppercase("ABCDEFGHIJKLMNOPQRSTUVWXYZ") == "1234567891011121314151617181920212223242526" def test_replace_uppercase_mixed_characters(): assert replace_uppercase("aBc!D") == "a2c!4" def test_replace_uppercase_no_...
[ { "docstring": null, "function_declaration": "def create_uppercase_dict():", "function_name": "create_uppercase_dict", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def replace_uppercase(input_string):", "function_name": "replace_uppercase", "parameter_l...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def map_uppercase_to_ordinal():\n \"\"\"\n Returns a dictionary mapping uppercase letters to their ordinal values from 1 to 26.\n \"\"\"\n return {chr(i): i - 64 for i in range(65,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027334", "row_id": 27334, "seed_ids": "['Qwen2-72B-Instruct_66009']" }
0.695643
Filter_27334
I
[ "create_uppercase_dict", "replace_uppercase" ]
2
[ [ "replace_uppercase", "create_uppercase_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
917239ed1102ce8d2c64ed40ac08c22dd107be5f
b8a234e58856aae9b2708135fa1c1202b7703ae9
v1.0
instruct
Filter
Filter_27347_I
Write a Python program that utilizes a generator function to print the first n prime numbers.
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, prime_generator def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(17) is True assert is_prime(19) is True assert is_prime(20) is False assert is_prime(1) is False assert is_prime(0) is Fa...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generator function to yield the first n prime numbers.", "function_declaration": "def prime_generator(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 Helper function to determine if a given number is a prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027347", "row_id": 27347, "seed_ids": "['Qwen2-72B-Instruct_66025']" }
0.647883
Filter_27347
I
[ "is_prime", "prime_generator" ]
2
[ [ "prime_generator", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7b45525cb6129a9bf59916b8dcf5d2c7f6e7eeb
711b92695b22b724a7dceee8427d38176320c1f9
v1.0
instruct
Filter
Filter_27350_I
Write code for displaying the Fibonacci sequence up to the nth term, where the nth term is provided as input by the user. Additionally, implement a method to calculate the sum of all the Fibonacci numbers up to the nth term and display it. The code should be written in a way that ensures the time complexity of the Fibo...
def fibonacci_sequence(n): """ Generate the Fibonacci sequence up to the nth term and return the sequence as a list. Args: n (int): The number of terms in the Fibonacci sequence to generate. Returns: list: A list containing the Fibonacci sequence up to the nth term. """ if n <= 0: ...
import pytest from solution import fibonacci_sequence, sum_fibonacci_sequence def test_fibonacci_sequence(): assert fibonacci_sequence(1) == [0] assert fibonacci_sequence(2) == [0, 1] assert fibonacci_sequence(5) == [0, 1, 1, 2, 3] assert fibonacci_sequence(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def...
[ { "docstring": "Generate the Fibonacci sequence up to the nth term and return the sequence as a list.\nArgs:\nn (int): The number of terms in the Fibonacci sequence to generate.\n\nReturns:\nlist: A list containing the Fibonacci sequence up to the nth term.", "function_declaration": "def fibonacci_sequence(...
[ 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):\n \"\"\"\n Generates the Fibonacci sequence up to the nth term.\n \n :param n: The number of terms to generate.\n :return: A list containing the Fibon...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027350", "row_id": 27350, "seed_ids": "['Qwen2-72B-Instruct_66033']" }
0.708201
Filter_27350
I
[ "fibonacci_sequence", "sum_fibonacci_sequence" ]
2
[ [ "sum_fibonacci_sequence", "fibonacci_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bab445e9f68f5a15745f6543cd6f6265137e074e
deccf40e8ac0b816b6703cc544cb394ff55d2319
v1.0
instruct
Filter
Filter_27388_I
In Python, write a program that prints out the first 100 prime numbers in reverse order. The program should also calculate and display the average value of these prime numbers. Additionally, the program should ensure that the prime numbers are only printed if they are also palindrome numbers.
def is_prime(n): """ Returns if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return ...
from solution import * def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(11) == True asse...
[ { "docstring": "Returns if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns if a number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindr...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns if a number n 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_0
{ "original_instruction": "", "prompt_id": "00027388", "row_id": 27388, "seed_ids": "['Qwen2-72B-Instruct_66091']" }
0.573721
Filter_27388
I
[ "is_prime", "is_palindrome", "first_n_primes", "main" ]
4
[ [ "first_n_primes", "is_palindrome" ], [ "first_n_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f67d0e8e35bdfbd3036e52a7d239f0feeb5c917b
cfff7a1d765745522fa1c6b91992ec29943d7b07
v1.0
instruct
Filter
Filter_27410_I
Write a program that takes in a list of integers and returns a new list containing only the prime numbers in the original list.
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0: return False return True ...
from solution import filter_primes def test_empty_list(): assert filter_primes([]) == [] def test_no_primes(): assert filter_primes([1, 4, 6, 8, 10, 12]) == [] def test_only_primes(): assert filter_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13] def test_mixed_numbers(): assert filter_primes([4...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given a list of integers, returns a list containing only the prime numbers.", "function_declaration...
[ 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 the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ==...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027410", "row_id": 27410, "seed_ids": "['Qwen2-72B-Instruct_66121']" }
0.614642
Filter_27410
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68a9c39dfbee58e1cfba15e62f28c4b53c0547f0
7883e292dccb5fcb5c5b066a8cfe90dd2bf22c71
v1.0
instruct
Filter
Filter_27411_I
Create 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 count of prime numbers and their sum. Additionally, the program should use multithreading to speed up the prime number checking process. The function...
import threading from queue import Queue 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: ...
from solution import find_primes def test_find_primes_simple(): # Test with a simple list of numbers result_primes, count, sum_primes = find_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) assert sorted(result_primes) == [2, 3, 5, 7] assert count == 4 assert sum_primes == 17 def test_find_primes_no_primes...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Worker function to check primes and add to the result list.", "function_declaration": "def prime_worker(queue, primes...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import threading\nfrom queue import Queue\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027411", "row_id": 27411, "seed_ids": "['Qwen2-72B-Instruct_66122']" }
0.658955
Filter_27411
I
[ "is_prime", "prime_worker", "find_primes" ]
3
[ [ "prime_worker", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e94c3cc8c62d743d6dc63bb4f501417f985edfc8
5b2a39c889d7863cd59ca6658c1d1d43969f40ff
v1.0
instruct
Filter
Filter_27424_I
Write a script in Python to find the geometric and harmonic mean of all the numbers in a list of multiple nested lists. You should also consider exceptions, such as the presence of zero and negative numbers in the list.
import math import functools def geometric_mean(numbers): """ Returns the geometric mean of a flat list of numbers. """ if any(n <= 0 for n in numbers): raise ValueError("Geometric mean is undefined for non-positive values.") product = functools.reduce(lambda x, y: x * y, numbers) retur...
from solution import geometric_mean, harmonic_mean, flatten, calculate_means def test_geometric_mean(): numbers = [1, 2, 3, 4, 5] assert geometric_mean(numbers) == (1 * 2 * 3 * 4 * 5) ** (1 / 5) def test_harmonic_mean(): numbers = [1, 2, 3, 4, 5] assert math.isclose(harmonic_mean(numbers), 5 / (1 + 0....
[ { "docstring": "Returns the geometric mean of a flat list of numbers.", "function_declaration": "def geometric_mean(numbers):", "function_name": "geometric_mean", "parameter_list": "(numbers)" }, { "docstring": "Returns the harmonic mean of a flat list of numbers.", "function_declaration...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef flatten_list(nested_list):\n \"\"\"\n Flattens a nested list of lists.\n \"\"\"\n flat_list = []\n for sublist in nested_list:\n for item in sublist:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027424", "row_id": 27424, "seed_ids": "['Qwen2-72B-Instruct_66139']" }
0.590459
Filter_27424
I
[ "geometric_mean", "harmonic_mean", "flatten", "calculate_means" ]
4
[ [ "calculate_means", "flatten" ], [ "calculate_means", "geometric_mean" ], [ "calculate_means", "harmonic_mean" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1896ad294c04912b6f8c8fc857b37f2d6726214d
edf3e51900c638e27e464b1b91495afa3a612fa5
v1.0
instruct
Filter
Filter_27428_I
Write a code to list out the unique prime numbers in an array and count the frequency of each unique prime number in the array. Return the prime numbers along with their frequencies as a dictionary.
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 prime_frequency(arr): """ ...
from solution import prime_frequency def test_prime_frequency(): assert prime_frequency([2, 3, 4, 5, 6, 7, 8, 9, 2, 5, 7, 7]) == {2: 2, 3: 1, 5: 2, 7: 3} assert prime_frequency([17, 17, 19, 19, 19, 1, 2]) == {17: 2, 19: 3, 2: 1} assert prime_frequency([0, 1, 4, 6, 8, 10]) == {} assert prime_frequency([...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "List out the unique prime numbers in an array and count the frequency\nof each unique prime number. Return the prime numbers along...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef is_prime(n):\n \"\"\"Returns True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027428", "row_id": 27428, "seed_ids": "['Qwen2-72B-Instruct_66146']" }
0.652245
Filter_27428
I
[ "is_prime", "prime_frequency" ]
2
[ [ "prime_frequency", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d2413563ed9cb913c16c517a2b04a539d776ce33
5ac75177c88be797af29cf77fb1ada5d800bf7e0
v1.0
instruct
Filter
Filter_27431_I
Given the input list of size N, write a code to print out the sum of the first N-1 elements, where N is a prime number. Additionally, the program should output the product of the first N-2 elements if N is a perfect square. If N is not prime or a perfect square, the program should output an error message.
import math def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def is_perfect_square(n): """ Checks if a number is a perfect square. """...
from solution import is_prime, is_perfect_square, sum_or_product # Test for is_prime function 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 # Test for is_perfect_square function def te...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if a number is a perfect square.", "function_declaration": "def is_perfect_square(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 is_prime(num):\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n if num < 9:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027431", "row_id": 27431, "seed_ids": "['Qwen2-72B-Instruct_66150']" }
0.596615
Filter_27431
I
[ "is_prime", "is_perfect_square", "sum_or_product" ]
3
[ [ "sum_or_product", "is_perfect_square" ], [ "sum_or_product", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d89ef5fc34c408fe57c528700a53380219412d1b
8d8f0af6425d8e403fe029a522ad111eb62190d2
v1.0
instruct
Filter
Filter_27434_I
Given a list of phone numbers, write a code to find the one with the highest number of repeated digits. The phone numbers may contain special characters such as parentheses, hyphens, or spaces. Your code should consider the repeated digits only when comparing the phone numbers. Additionally, the code should handle inte...
import re from collections import Counter def clean_phone_number(phone_number): """ Cleans the phone number by removing special characters and spaces. """ return re.sub(r'[^\d]', '', phone_number) def find_highest_repeated_digit_phone(phone_numbers): """ Finds the phone number with the highest...
from solution import clean_phone_number, find_highest_repeated_digit_phone def test_clean_phone_number(): assert clean_phone_number("+1 (305) 123-4567") == "13051234567" assert clean_phone_number("(123) 456-7890") == "1234567890" assert clean_phone_number("+44 20 7946 0958") == "442079460958" def test_fin...
[ { "docstring": "Cleans the phone number by removing special characters and spaces.", "function_declaration": "def clean_phone_number(phone_number):", "function_name": "clean_phone_number", "parameter_list": "(phone_number)" }, { "docstring": "Finds the phone number with the highest number of...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nfrom collections import Counter\n\ndef clean_phone_number(phone_number):\n \"\"\"\n Cleans the given phone number by removing all special characters and returns the cleaned st...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027434", "row_id": 27434, "seed_ids": "['Qwen2-72B-Instruct_66153']" }
0.541134
Filter_27434
I
[ "clean_phone_number", "find_highest_repeated_digit_phone" ]
2
[ [ "find_highest_repeated_digit_phone", "clean_phone_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30fb0cae2cef45c4e423f300eaa644c95c441989
427ef61e8817393905e30a984cc23702dcd5ae03
v1.0
instruct
Filter
Filter_27438_I
At work, we are attempting to optimize a function to minimize its output. It is a black-box optimization problem and Derivative-Free Optimization (DFO) would be suitable. Can you provide a step-by-step guide to implementing the algorithm in Python using the SciPy library? Additionally, could you provide some general gu...
import numpy as np from scipy.optimize import minimize def objective_function(params): """ Example objective function: A simple quadratic function. """ x, y = params return x**2 + y**2 + x*y + 1 def optimize_function(): # Initial guess initial_guess = np.array([1.0, 1.0]) # Perfor...
import numpy as np from solution import objective_function, optimize_function def test_objective_function(): # Test known inputs and outputs assert objective_function([0, 0]) == 1 assert objective_function([1, 0]) == 2 assert objective_function([0, 1]) == 2 assert objective_function([1, 1]) == 4 d...
[ { "docstring": "Example objective function: A simple quadratic function.", "function_declaration": "def objective_function(params):", "function_name": "objective_function", "parameter_list": "(params)" }, { "docstring": null, "function_declaration": "def optimize_function():", "funct...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from scipy.optimize import minimize\n\ndef black_box_function(x):\n \"\"\"\n This is a placeholder for the black-box function we are attempting to optimize.\n The function should take...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027438", "row_id": 27438, "seed_ids": "['Qwen2-72B-Instruct_66157']" }
0.313972
Filter_27438
I
[ "objective_function", "optimize_function" ]
2
[ [ "optimize_function", "objective_function" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
77dfca0bea5446535e476982980c1766843fd233
45d369c03ece018c2c8a69de406b1d59ac3f4815
v1.0
instruct
Filter
Filter_27457_I
Code a Python script that converts temperatures in celsius to fahrenheit. The script should also include error handling to ensure that the user enters a valid temperature. Additionally, the script should provide an option for the user to convert the temperature in reverse, from fahrenheit to celsius. The user should be...
def celsius_to_fahrenheit(celsius): """ Converts Celsius temperature to Fahrenheit. """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit temperature to Celsius. """ return (fahrenheit - 32) * 5/9 def convert_temperatures(temperatures, to_unit):...
from solution import celsius_to_fahrenheit, fahrenheit_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 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsi...
[ { "docstring": "Converts Celsius temperature to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts Fahrenheit temperature to Celsius.", "function_declaration": "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n :param celsius: float or int\n :return: float\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027457", "row_id": 27457, "seed_ids": "['Qwen2-72B-Instruct_66188']" }
0.44137
Filter_27457
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperatures" ]
3
[ [ "convert_temperatures", "celsius_to_fahrenheit" ], [ "convert_temperatures", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
eb590402dda04ecfc69412815cf913fa448671c7
d44aaf75c59e2f3f98841ef5dc23f06289c81b15
v1.0
instruct
Filter
Filter_27482_I
Create a Python script for a web application that implements a genetic algorithm for optimizing a given function. The script should include a Flask server, an endpoint for running the optimization, and a visualization of the results.
from flask import Flask, jsonify, request import random import numpy as np import matplotlib.pyplot as plt import io import base64 app = Flask(__name__) def objective_function(x): return x**2 def create_individual(size): return [random.uniform(-10, 10) for _ in range(size)] def create_population(pop_size, i...
import pytest from solution import create_individual, create_population, calculate_fitness, selection, crossover, mutate, genetic_algorithm def test_create_individual(): ind_size = 5 individual = create_individual(ind_size) assert len(individual) == ind_size assert all(-10 <= gene <= 10 for gene in ind...
[ { "docstring": null, "function_declaration": "def objective_function(x):", "function_name": "objective_function", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def create_individual(size):", "function_name": "create_individual", "parameter_list": "(size...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, jsonify, request\nimport random\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport io\nimport base64\n\napp = Flask(__name__)\n\ndef objective_function(x):\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027482", "row_id": 27482, "seed_ids": "['Qwen2-72B-Instruct_66227']" }
0.361741
Filter_27482
I
[ "objective_function", "create_individual", "create_population", "calculate_fitness", "selection", "crossover", "mutate", "genetic_algorithm", "optimize" ]
9
[ [ "calculate_fitness", "objective_function" ], [ "create_population", "create_individual" ], [ "genetic_algorithm", "create_population" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "selection" ...
8
[]
false
[]
false
pytest
true
[ "flask", "matplotlib", "numpy" ]
false
ccdab7eaa70f5b16c8890fea4c8bb8d685ca682d
7b7770eb9d926898cecb6948f90011e3df18296f
v1.0
instruct
Filter
Filter_27485_I
Create a program that converts temperatures from Fahrenheit to Celsius and vice versa. The program should allow the user to choose the conversion direction and handle invalid input gracefully.
def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0 / 9.0 def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return (celsius * 9.0 / 5.0) + 32 def convert_temperature(value, to_scale): """ Conver...
from solution import fahrenheit_to_celsius, celsius_to_fahrenheit, convert_temperature # Unit tests for fahrenheit_to_celsius def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert abs(fahrenheit_to_celsius(212) - 100) < 0.001 assert abs(fahrenheit_to_celsius(-40) - (-40)) < 0.001 ...
[ { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahr...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Convert Fahrenheit to Celsius.\n \"\"\"\n try:\n fahrenheit = float(fahrenheit)\n except ValueError:\n return \"I...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027485", "row_id": 27485, "seed_ids": "['Qwen2-72B-Instruct_66231']" }
0.413687
Filter_27485
I
[ "fahrenheit_to_celsius", "celsius_to_fahrenheit", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d29a613abc6fc909d8899ea29bfdcb4ba4a4f267
d6e8de9138b42f2cc65a66663001878366df398b
v1.0
instruct
Filter
Filter_27493_I
Construct a while loop to print out all prime numbers between 1 and 1000 in reverse order, but only if their sum of digits is a prime number as well. Additionally, the program should output the number of prime numbers found and the sum of all prime numbers.
def is_prime(n): """Check if a number is a prime""" if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_o...
from solution import is_prime, sum_of_digits, prime_numbers_with_prime_digit_sum def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_sum_of_digits(): assert sum_of_digits(123) =...
[ { "docstring": "Check if a number is a prime", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return the sum of the digits of a number", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digi...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n 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 sum_of_digits(n):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027493", "row_id": 27493, "seed_ids": "['Qwen2-72B-Instruct_66245']" }
0.572676
Filter_27493
I
[ "is_prime", "sum_of_digits", "prime_numbers_with_prime_digit_sum" ]
3
[ [ "prime_numbers_with_prime_digit_sum", "is_prime" ], [ "prime_numbers_with_prime_digit_sum", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0898332a04526a62a8748415caa52e10c9fd2408
08419960e9682a2ca3e685cfe1282323603efb42
v1.0
instruct
Filter
Filter_27501_I
Create a detailed guide on how to create a Python function that checks if a number is prime or not. The function should include an explanation of the algorithm used, and should be written in a clear and concise manner. Additionally, create a table that displays the execution time of the function for various input sizes...
import math import time def is_prime(n): """ Checks if a number is prime or not. Parameters: n (int): The number to check. Returns: bool: True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == ...
from solution import is_prime def test_is_prime_with_small_primes(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True def test_is_prime_with_small_non_primes(): assert is_prime(1) == False assert is_prime(4) == False assert is_prim...
[ { "docstring": "Checks if a number is prime or not.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "f...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport time\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if n is prime,...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027501", "row_id": 27501, "seed_ids": "['Qwen2-72B-Instruct_66259']" }
0.646534
Filter_27501
I
[ "is_prime", "measure_execution_time", "generate_execution_time_table" ]
3
[ [ "generate_execution_time_table", "measure_execution_time" ], [ "measure_execution_time", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bcab6addf846445d054ed47f830d46f8396e8ac8
facc044f8df0dc46e68572ece741535f30ef01d1
v1.0
instruct
Filter
Filter_27539_I
Create a function that checks if two given phrases contain the same unique letters. Additionally, ensure the function evaluates the case sensitivity and ignores special characters or numbers.
import string def sanitize_phrase(phrase): """ Removes special characters and numbers, and lowercases the letters. """ return ''.join(filter(lambda x: x in string.ascii_letters, phrase)).lower() def same_unique_letters(phrase1, phrase2): """ Checks if the two given phrases contain the same uni...
from solution import same_unique_letters def test_same_unique_letters_identical_phrases(): assert same_unique_letters("Hello, World!", "world! Hello,") == True def test_same_unique_letters_case_sensitivity(): assert same_unique_letters("abc", "ABC") == True def test_same_unique_letters_different_special_char...
[ { "docstring": "Removes special characters and numbers, and lowercases the letters.", "function_declaration": "def sanitize_phrase(phrase):", "function_name": "sanitize_phrase", "parameter_list": "(phrase)" }, { "docstring": "Checks if the two given phrases contain the same unique letters.",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef normalize_phrase(phrase):\n \"\"\"\n Helper function to normalize the phrase by converting to lower case and\n removing all non-alphabetic characters.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027539", "row_id": 27539, "seed_ids": "['Qwen2-72B-Instruct_66316']" }
0.653356
Filter_27539
I
[ "sanitize_phrase", "same_unique_letters" ]
2
[ [ "same_unique_letters", "sanitize_phrase" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bc3e2a7f0d01db7b1fe22121397e7d649c423dcb
ba6490fc47247ca75fd1465c5917f3aee89b4b9d
v1.0
instruct
Filter
Filter_27543_I
Design a program that uses a loop to generate 25 random prime numbers between 0 and 100.
import random 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 generate_prime_numbers(count, lower_bound, upper_bound): primes = [] while len(primes) < count: num = random.randint(lower_boun...
from solution import is_prime, generate_prime_numbers, generate_25_random_primes_between_0_and_100 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 asser...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_prime_numbers(count, lower_bound, upper_bound):", "function_name": "generate_prime_numbers", "parame...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport sympy\n\ndef generate_random_primes(n, start, end):\n \"\"\"\n Generate `n` random prime numbers between `start` and `end`.\n\n Parameters:\n - n (int): numbe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027543", "row_id": 27543, "seed_ids": "['Qwen2-72B-Instruct_66323']" }
0.490894
Filter_27543
I
[ "is_prime", "generate_prime_numbers", "generate_25_random_primes_between_0_and_100" ]
3
[ [ "generate_25_random_primes_between_0_and_100", "generate_prime_numbers" ], [ "generate_prime_numbers", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7c9dc8a30b29d7d2f8f51e4174f34ffc57ef2dc0
9ffac129e3e869f4a7987690e040b4e6c7263d72
v1.0
instruct
Filter
Filter_27544_I
Convert the following Python nested list comprehension into generator expression but also, implement an if-else statement that checks if the integer is prime. If it is, provide its square, if not - the integer itself.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def prime_...
from solution import is_prime, prime_square_or_self def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False def test_prime_square_or_self(): nested_list = [[2, 3, 4], [5, 6, 7], [8, 9, 10]] ...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generator that yields the square of a number if it is prime, otherwise the number itself,\nfor each numb...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027544", "row_id": 27544, "seed_ids": "['Qwen2-72B-Instruct_66324']" }
0.543063
Filter_27544
I
[ "is_prime", "prime_square_or_self" ]
2
[ [ "prime_square_or_self", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e0b1477e1f9bcd0f6e29c3617619c6cad6c47e8
1f7dcda1d44bd75d5fa0f02110013905cce80411
v1.0
instruct
Filter
Filter_27545_I
Given a list of integers, write a function in Python to sort the list in non-decreasing order. However, you are not allowed to use any built-in sorting functions or methods, and your solution should have a time complexity of O(n log n) or better.
def merge_sort(arr): """ Sorts a list of integers in non-decreasing order using merge sort algorithm. :param arr: List of integers :return: Sorted list of integers """ if len(arr) <= 1: return arr # Finding the middle point to divide the array into two halves mid = len(arr) // 2...
from solution import merge_sort def test_sorted_list(): assert merge_sort([1, 2, 3, 4]) == [1, 2, 3, 4] def test_unsorted_list(): assert merge_sort([4, 2, 1, 3]) == [1, 2, 3, 4] def test_reverse_sorted_list(): assert merge_sort([4, 3, 2, 1]) == [1, 2, 3, 4] def test_list_with_duplicates(): assert me...
[ { "docstring": "Sorts a list of integers in non-decreasing order using merge sort algorithm.\n:param arr: List of integers\n:return: Sorted list of integers", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges tw...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list of integers in non-decreasing order using the Merge Sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027545", "row_id": 27545, "seed_ids": "['Qwen2-72B-Instruct_66325']" }
0.692523
Filter_27545
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea8dca46f439054795c6458eabe01912bb555b74
9800ac2fcee991551db988c3f1e09313ac621432
v1.0
instruct
Filter
Filter_27564_I
Write a function that takes a string and a sorted list of strings as input. Return the Kth shortest string from the list that is a valid subsequence of the given string. If no such string exists, return an empty string.
def is_subsequence(s, subseq): """ Helper function to determine if subseq is a subsequence of s. """ it = iter(s) return all(char in it for char in subseq) def kth_shortest_subsequence(string, lst, k): """ Returns the K-th shortest string from the sorted list that is a valid subsequence of ...
from solution import kth_shortest_subsequence def test_no_valid_subsequence(): assert kth_shortest_subsequence("abc", ["d", "e", "f"], 1) == "" def test_valid_subsequence_present(): assert kth_shortest_subsequence("abc", ["a", "b", "c"], 2) == "b" def test_kth_out_of_range(): assert kth_shortest_...
[ { "docstring": "Helper function to determine if subseq is a subsequence of s.", "function_declaration": "def is_subsequence(s, subseq):", "function_name": "is_subsequence", "parameter_list": "(s, subseq)" }, { "docstring": "Returns the K-th shortest string from the sorted list that is a vali...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(s, t):\n \"\"\"\n Check if string s is a subsequence of string t.\n \"\"\"\n it = iter(t)\n return all(c in it for c in s)\n\ndef kth_shortest_subsequence(k, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027564", "row_id": 27564, "seed_ids": "['Qwen2-72B-Instruct_66354']" }
0.643715
Filter_27564
I
[ "is_subsequence", "kth_shortest_subsequence" ]
2
[ [ "kth_shortest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65fdf5d00c81cc09b5ed683ba63932c34a4b472c
abc2e821c8263eff63b93adb75276e3790cfb548
v1.0
instruct
Filter
Filter_27565_I
Write a Python program that prints all prime numbers from 1 to 100. Additionally, you should also print a message for each number stating whether it is a prime number or not.
def is_prime(num): """ Returns True if the number is prime, else False. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0: return False return True d...
from solution import is_prime, print_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_is_prime_edge_cases(): assert is_prime(0) == False...
[ { "docstring": "Returns True if the number is prime, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Prints all prime numbers from 1 to 100 with a message indicating \nwhether each number is a prime number ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00027565", "row_id": 27565, "seed_ids": "['Qwen2-72B-Instruct_66355']" }
0.674138
Filter_27565
I
[ "is_prime", "print_primes" ]
2
[ [ "print_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1abb8c1314167981893e8c6b380cb95c4ce03824
116d2ee85750523d655a0409f3573c3070c22d76
v1.0
instruct
Filter
Filter_27576_I
Write a Python code that turns the given input into a list of dictionaries, where each dictionary should have a 'name' key and an 'age' key. The 'name' key should store a string and the 'age' key should store an integer. The input should be a list of strings in the format 'name,age' and the output should be a list of d...
def validate_data(name, age): """ Validates if the 'name' is a valid string and 'age' is a positive integer. """ if not isinstance(name, str) or not name.isalpha(): raise ValueError("Invalid name: must be a string containing only alphabetical characters.") if not isinstance(age, int) or...
from solution import convert_input_to_list_of_dicts, validate_data def test_convert_input_to_list_of_dicts_valid_input(): input_list = ["John,21", "Jane,27", "Jack,38"] expected_output = [ {'name': 'John', 'age': 21, 'id': 1}, {'name': 'Jane', 'age': 27, 'id': 2}, {'name': 'Jack', 'age'...
[ { "docstring": "Validates if the 'name' is a valid string and 'age' is a positive integer.", "function_declaration": "def validate_data(name, age):", "function_name": "validate_data", "parameter_list": "(name, age)" }, { "docstring": "Converts the input list of strings into a list of diction...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def validate_data(name, age):\n \"\"\"\n Validates the name and age values.\n \n :param name: str, should be a valid name (non-empty string)\n :param age: str, should be a posit...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027576", "row_id": 27576, "seed_ids": "['Qwen2-72B-Instruct_66370']" }
0.548989
Filter_27576
I
[ "validate_data", "convert_input_to_list_of_dicts" ]
2
[ [ "convert_input_to_list_of_dicts", "validate_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
867d219a3908ff872ab20988f9e7b2bfdc4c5251
6acf7680675f2e082266a490af1c38e45c1395e3
v1.0
instruct
Filter
Filter_27595_I
Write a Python script to find the first 1000 prime numbers.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: retur...
from solution import is_prime, first_n_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == Fals...
[ { "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 the first n prime numbers.", "function_declaration": "def first_n_primes(n):", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027595", "row_id": 27595, "seed_ids": "['Qwen2-72B-Instruct_66408']" }
0.589799
Filter_27595
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c4c89555aca672854a518752d386206c0bfb9341
8ed6ea8cd6efb47c92d6601ad2ae74de58a7aa3c
v1.0
instruct
Filter
Filter_27598_I
Using the programming language Python, write a function that takes a list of integers as input and returns the median value. The function should also handle cases where the input list contains an even number of values by returning the average of the two middle values. Additionally, the input list should be sorted using...
def bubble_sort(arr): """ Sorts a list in ascending order using the bubble sort algorithm. """ n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr def calculate_median(arr): """ ...
from solution import bubble_sort, calculate_median def test_bubble_sort(): assert bubble_sort([2, 3, 5, 4, 1]) == [1, 2, 3, 4, 5] assert bubble_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] assert bubble_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert bubble_sort([3, 3, 3, 3, 3]) == [3, 3, 3, 3, 3] asse...
[ { "docstring": "Sorts a list in ascending order using the bubble sort algorithm.", "function_declaration": "def bubble_sort(arr):", "function_name": "bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Returns the median value of a list of integers.\nIf the list contains an even numbe...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort(arr):\n \"\"\"\n Sort an array using the bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in range(0, n - i - 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027598", "row_id": 27598, "seed_ids": "['Qwen2-72B-Instruct_66412']" }
0.82007
Filter_27598
I
[ "bubble_sort", "calculate_median" ]
2
[ [ "calculate_median", "bubble_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6632809f0e1b67b53d2425853dcf89af4d1a992b
bf7682f8260904d6375d3d738d3f22f129535f8c
v1.0
instruct
Filter
Filter_27602_I
Create a Python function that calculates the greatest common divisor (GCD) of two numbers using recursion. Then, expand this function to work with an array of integers by finding the GCD of all the numbers in the array. Also, implement error handling for situations where the input array is empty or contains non-integer...
def gcd(a, b): """ Returns the greatest common divisor of a and b using recursion. """ if b == 0: return a else: return gcd(b, a % b) def gcd_array(arr): """ Returns the greatest common divisor of an array of integers. Implements error handling for empty arrays and non-i...
from solution import gcd, gcd_array def test_gcd(): assert gcd(48, 18) == 6 assert gcd(56, 98) == 14 assert gcd(101, 103) == 1 assert gcd(12, 0) == 12 assert gcd(0, 12) == 12 def test_gcd_array(): assert gcd_array([48, 18, 30]) == 6 assert gcd_array([56, 98, 28]) == 14 assert gcd_array...
[ { "docstring": "Returns the greatest common divisor of a and b using recursion.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the greatest common divisor of an array of integers.\nImplements error handling for empty ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b using recursion.\n \"\"\"\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\ndef gc...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027602", "row_id": 27602, "seed_ids": "['Qwen2-72B-Instruct_66417']" }
0.738359
Filter_27602
I
[ "gcd", "gcd_array" ]
2
[ [ "gcd_array", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0dd90996c2872de7fa713a974fc07edf5efac3ce
373a9eecf8b73fdf67013b12bc9b5be734f7998a
v1.0
instruct
Filter
Filter_27608_I
Create a nested for loop that prints all prime numbers within the range of 1 to 50, but exclude the number 2 and 3. Additionally, the program should also calculate and print the sum of all the prime numbers.
def is_prime(num): """ Checks if a number is prime. """ if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def print_and_sum_primes(): """ Prints all prime numbers in the range 1 to 50 excluding 2 and 3....
from solution import is_prime, print_and_sum_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(1) == False def test_print_and_sum_primes(capsys): expected_primes = [5, 7, 11, 13, 17, 19, 23,...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Prints all prime numbers in the range 1 to 50 excluding 2 and 3.\nReturns the sum of these prime numbers.", "function_dec...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks 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_0
{ "original_instruction": "", "prompt_id": "00027608", "row_id": 27608, "seed_ids": "['Qwen2-72B-Instruct_66430']" }
0.542136
Filter_27608
I
[ "is_prime", "print_and_sum_primes" ]
2
[ [ "print_and_sum_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7bbf2816a29a4c186505baf05e4dabf2cabc78ae
a503ebeacb570ec2f2b41c08a5a8cc7317e0c1e5
v1.0
instruct
Filter
Filter_27612_I
Write a Python function that checks if a number is within a given range both inclusive. Then, use that function in a program which checks whether each element in a list of integers is within the range of 1 to 10 inclusive, and returns a list of boolean values correspondingly.
def is_within_range(number, start, end): """ Check if a number is within a given range [start, end] inclusive. Parameters: number (int): The number to be checked. start (int): The start of the range. end (int): The end of the range. Returns: bool: True if nu...
from solution import is_within_range, check_numbers_in_range def test_is_within_range_inside(): assert is_within_range(5, 1, 10) == True assert is_within_range(1, 1, 10) == True assert is_within_range(10, 1, 10) == True def test_is_within_range_outside(): assert is_within_range(-1, 1, 10) == False ...
[ { "docstring": "Check if a number is within a given range [start, end] inclusive.\n\nParameters:\n number (int): The number to be checked.\n start (int): The start of the range.\n end (int): The end of the range.\n \nReturns:\n bool: True if number is within the range [start, end], False otherwis...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_within_range(number, start, end):\n \"\"\"\n Check if 'number' is within the range from 'start' to 'end' inclusive.\n \"\"\"\n return start <= number <= end\n\ndef check_lis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00027612", "row_id": 27612, "seed_ids": "['Qwen2-72B-Instruct_66437']" }
0.581536
Filter_27612
I
[ "is_within_range", "check_numbers_in_range" ]
2
[ [ "check_numbers_in_range", "is_within_range" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b6b46bf41184203950e6fbda6c5f99dbaec331d
243dfae5b8ae5b593d3988ff6e908eb592149493
v1.0
instruct
Filter
Filter_27622_I
Write a code function that identifies prime numbers within a given list, distinguishing between odd and even numbers while optimizing for runtime efficiency. Use the list [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as your input, and include a segment of flawed code for reference to enhance analytical processing skills. Analyze t...
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def identify_primes_and_odds_evens(...
from solution import is_prime, identify_primes_and_odds_evens def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_p...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of numbers, identify which are prime and\nalso categorize them into odd and even numbers.", "function_declaratio...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00027622", "row_id": 27622, "seed_ids": "['Qwen2-72B-Instruct_66452']" }
0.57796
Filter_27622
I
[ "is_prime", "identify_primes_and_odds_evens" ]
2
[ [ "identify_primes_and_odds_evens", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d4be343bf380bdab78e708327e0bb2b8d0abafd
1d5cb5f5f0c03b3c95ccd581790906a28571d6ca