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_74222_I
How can I modify the given code to include a feature that reads a configuration file and uses its settings to set up the initial conditions for a simulation?
import configparser def read_config(config_file): """ Reads the configuration file and returns a dictionary with the settings. """ config = configparser.ConfigParser() config.read(config_file) settings = { 'initial_temperature': config.getfloat('Simulation', 'initial_temperature'), ...
import configparser import os from solution import read_config, initialize_simulation def create_test_config_file(content: str, filename='test_config.ini'): with open(filename, 'w') as f: f.write(content) return filename def test_read_config(): config_content = """ [Simulation] initial_tem...
[ { "docstring": "Reads the configuration file and returns a dictionary with the settings.", "function_declaration": "def read_config(config_file):", "function_name": "read_config", "parameter_list": "(config_file)" }, { "docstring": "Initializes the simulation using settings from the configur...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef read_configuration(file_path):\n \"\"\"\n Reads a JSON configuration file and returns the configuration settings.\n \"\"\"\n with open(file_path, 'r') as file:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074222", "row_id": 74222, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150544']" }
0.489262
Filter_74222
I
[ "read_config", "initialize_simulation" ]
2
[ [ "initialize_simulation", "read_config" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d94c13345d0e6489eda609a121a2df411497a2f
7ad1ca4f9053dae794a00e5591dcd6f54688dea4
v1.0
instruct
Filter
Filter_74231_I
How can I implement a weighted k-nearest neighbors (k-NN) classifier in Python?
import numpy as np from collections import Counter def euclidean_distance(a, b): return np.sqrt(np.sum((a - b) ** 2)) def weighted_knn(X_train, y_train, X_test, k=3): """ Implements a weighted k-nearest neighbors (k-NN) classifier. Parameters: - X_train: np.ndarray, shape (n_samples, n_features) ...
import numpy as np from solution import weighted_knn def test_weighted_knn_basic(): X_train = np.array([[1, 2], [2, 3], [3, 4], [4, 5]]) y_train = np.array([0, 1, 0, 1]) X_test = np.array([[1, 2], [4, 5]]) assert np.array_equal(weighted_knn(X_train, y_train, X_test, k=3), np.array([0, 1])) def te...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom collections import Counter\n\ndef weighted_knn_predict(X_train, y_train, X_test, k=3, distance_metric='euclidean'):\n \"\"\"\n Weighted k-NN prediction function....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074231", "row_id": 74231, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150566']" }
0.530963
Filter_74231
I
[ "euclidean_distance", "weighted_knn" ]
2
[ [ "weighted_knn", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
1fa42849ee852786cc56763f1bfd6dc0a89e36b1
4f6bb13d571cb227485d7c87146cb16acd854395
v1.0
instruct
Filter
Filter_74236_I
I want to create a simple game where you guess a number. Can you guide me through the process of creating this game in Python?
import random def generate_random_number(start, end): """ Generates a random number between start and end (inclusive). """ return random.randint(start, end) def check_guess(number, guess): """ Compares the player's guess to the actual number. Returns: - 'correct' if the guess is c...
from solution import generate_random_number, check_guess def test_generate_random_number_within_range(): start, end = 1, 100 number = generate_random_number(start, end) assert start <= number <= end def test_check_guess_correct(): number = 50 guess = 50 assert check_guess(number, guess) == 'co...
[ { "docstring": "Generates a random number between start and end (inclusive).", "function_declaration": "def generate_random_number(start, end):", "function_name": "generate_random_number", "parameter_list": "(start, end)" }, { "docstring": "Compares the player's guess to the actual number.\n...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef guess_the_number():\n \"\"\"\n A simple number guessing game.\n The player needs to guess a number between 1 and 100.\n \"\"\"\n number_to_guess = random.ra...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074236", "row_id": 74236, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150576']" }
0.534701
Filter_74236
I
[ "generate_random_number", "check_guess", "play_game" ]
3
[ [ "play_game", "check_guess" ], [ "play_game", "generate_random_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8247ef023eba43bd592412d47333012aa8291ab2
ac037c2579982303925cd0a8c32ac28fdd97ffac
v1.0
instruct
Filter
Filter_74243_I
Can you explain how the process of finding the kth smallest element in an unsorted array works, and provide a Python implementation?
def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quickselect(arr, low, high, k): if low <= high: ...
from solution import kth_smallest def test_kth_smallest(): assert kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2 assert kth_smallest([3, 2, 1, 5, 6, 4], 1) == 1 assert kth_smallest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 3 assert kth_smallest([1], 1) == 1 assert kth_smallest([7, 10, 4, 3, 20, 15], 3) == 7 ...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n \n for j in range(low, high):\n if arr[j] <= pivot:\n i += 1\n arr[...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074243", "row_id": 74243, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150592']" }
0.637878
Filter_74243
I
[ "partition", "quickselect", "kth_smallest" ]
3
[ [ "kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
613c62600125f696cf74e89b8e231d59960f9acb
093adb0aa8bcb125969b81c06b82ce63e66fe9d2
v1.0
instruct
Filter
Filter_74248_I
Can you help me with a Python code to simulate a simple lottery system where a user picks a set number of unique numbers from 1 to 50, and then the system randomly draws a set of numbers from the same range? The code should also check if the user's numbers match the drawn numbers and output the result?
import random def generate_random_numbers(num, start=1, end=50): """ Generates a set of unique random numbers within a given range. Parameters: num (int): Number of unique random numbers to generate. start (int): Start of the range (inclusive). end (int): End of the range (inclusive). ...
from solution import generate_random_numbers, check_winning, lottery def test_generate_random_numbers(): numbers = generate_random_numbers(6) assert len(numbers) == 6 assert all(1 <= num <= 50 for num in numbers) assert len(numbers) == len(set(numbers)) # Ensure all numbers are unique def test_check_...
[ { "docstring": "Generates a set of unique random numbers within a given range.\n\nParameters:\nnum (int): Number of unique random numbers to generate.\nstart (int): Start of the range (inclusive).\nend (int): End of the range (inclusive).\n\nReturns:\nset: A set containing the unique random numbers.", "func...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef pick_numbers(picks):\n \"\"\"\n Allow users to pick a set number of unique numbers from 1 to 50.\n \"\"\"\n if not 1 <= len(picks) <= 6:\n raise ValueEr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074248", "row_id": 74248, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150599']" }
0.442707
Filter_74248
I
[ "generate_random_numbers", "check_winning", "lottery" ]
3
[ [ "lottery", "check_winning" ], [ "lottery", "generate_random_numbers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0d7ae75fa7dbdb835039cf54529a709b25de9acd
3306a27d38b75f6054d29a68d67cec597f745440
v1.0
instruct
Filter
Filter_74269_I
I'm looking to evaluate the efficiency of a new algorithm for finding the shortest path in a graph, specifically a Dijkstra's algorithm variant. How can I implement this variant and compare its efficiency with the classic Dijkstra's algorithm using Python?
import heapq import time def dijkstra(graph, start): """ Classic Dijkstra's algorithm to find the shortest path from start node to all other nodes in a graph. """ distances = {vertex: float('infinity') for vertex in graph} distances[start] = 0 priority_queue = [(0, start)] while priority_q...
from solution import dijkstra, dijkstra_variant, compare_algorithms def test_dijkstra(): graph = { 'A': {'B': 1, 'C': 4}, 'B': {'A': 1, 'C': 2, 'D': 5}, 'C': {'A': 4, 'B': 2, 'D': 1}, 'D': {'B': 5, 'C': 1} } expected_result = {'A': 0, 'B': 1, 'C': 3, 'D': 4} assert dijks...
[ { "docstring": "Classic Dijkstra's algorithm to find the shortest path from start node to all other nodes in a graph.", "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": "A variant of Dijkstra's algorithm ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef classic_dijkstra(graph, start):\n \"\"\"\n Finds the shortest paths from the start node to all other nodes in the graph using classic Dijkstra's algorithm.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074269", "row_id": 74269, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150638']" }
0.398594
Filter_74269
I
[ "dijkstra", "dijkstra_variant", "compare_algorithms" ]
3
[ [ "compare_algorithms", "dijkstra" ], [ "compare_algorithms", "dijkstra_variant" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1c33333b282f162a73e8ddc0177d91a030993ddb
f500bcd65b1dc5c203fdf426fcc6c2373c289bfd
v1.0
instruct
Filter
Filter_74287_I
In a machine learning course, you are tasked with implementing a K-Means clustering algorithm from scratch in Python. You are provided with a dataset of 100 samples, each having two features. The objective is to cluster these samples into 3 clusters. However, the dataset is not labeled, and you do not have any prior in...
import numpy as np def initialize_centroids(X, k): """ Initialize centroids by randomly selecting k samples from the dataset X. Parameters: X (numpy array): The dataset (n_samples, n_features). k (int): The number of centroids. Returns: numpy array: Initialized centroids (k, n_feature...
import numpy as np from solution import initialize_centroids, assign_clusters, update_centroids, kmeans def test_initialize_centroids(): X = np.random.rand(100, 2) centroids = initialize_centroids(X, 3) assert centroids.shape == (3, 2) assert np.all(np.in1d(centroids, X)) def test_assign_clusters(): ...
[ { "docstring": "Initialize centroids by randomly selecting k samples from the dataset X.\n\nParameters:\nX (numpy array): The dataset (n_samples, n_features).\nk (int): The number of centroids.\n\nReturns:\nnumpy array: Initialized centroids (k, n_features).", "function_declaration": "def initialize_centroi...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef initialize_centroids(X, k):\n \"\"\"\n Randomly initialize the centroids from the data points.\n \"\"\"\n np.random.seed(42) # For reproducible results\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074287", "row_id": 74287, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150669']" }
0.693386
Filter_74287
I
[ "initialize_centroids", "assign_clusters", "update_centroids", "kmeans" ]
4
[ [ "kmeans", "assign_clusters" ], [ "kmeans", "initialize_centroids" ], [ "kmeans", "update_centroids" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy" ]
false
832532ffbc7628ae0f163ae6d722e3c56ed314cf
6843480cd5a671bcae9c57f43e88f5844ef69574
v1.0
instruct
Filter
Filter_74322_I
How can I create an XML document from a JSON object using Python?
import xml.etree.ElementTree as ET import json def json_to_xml(json_obj, line_padding=""): """ Converts a JSON object to an XML string. Args: json_obj (dict): JSON object to convert. line_padding (str): String padding for each line of XML. Returns: str: XML string representation of th...
from solution import convert_json_to_xml def test_convert_simple_json_to_xml(): json_obj = { "name": "John", "age": 30, "city": "New York" } expected_xml = "<root>\n<name>\n\tJohn\n</name>\n<age>\n\t30\n</age>\n<city>\n\tNew York\n</city>\n</root>" assert convert_json_to_xml(jso...
[ { "docstring": "Converts a JSON object to an XML string.\n\nArgs:\njson_obj (dict): JSON object to convert.\nline_padding (str): String padding for each line of XML.\n\nReturns:\nstr: XML string representation of the JSON object.", "function_declaration": "def json_to_xml(json_obj, line_padding=''):", "...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nimport xml.etree.ElementTree as ET\n\ndef json_to_xml(json_obj, root_tag=\"root\"):\n \"\"\"\n Converts a JSON object to an XML string.\n \n :param json_obj: A diction...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074322", "row_id": 74322, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150739']" }
0.703405
Filter_74322
I
[ "json_to_xml", "convert_json_to_xml" ]
2
[ [ "convert_json_to_xml", "json_to_xml" ] ]
1
[]
false
[]
false
pytest
true
[]
true
783634c7cc401429a4bdf12c4cb9ab837ef03f20
67c15c17ceb58ab1a6d0bb8466ed7f289c3f3bb5
v1.0
instruct
Filter
Filter_74326_I
Hey, I need help with creating a Python script that can read data from a JSON file, process it, and then write the processed data back to another JSON file. Can you guide me through the process?
import json def read_json(file_path): """ Reads data from a JSON file and returns it. """ with open(file_path, 'r') as file: data = json.load(file) return data def process_data(data): """ Processes the data. This function can be modified according to the specific processing nee...
import json import os import tempfile from solution import read_json, process_data, write_json, process_json_files def test_read_json(): test_data = {"key": "value"} with tempfile.NamedTemporaryFile(delete=False, mode='w+') as tmp: json.dump(test_data, tmp) tmp_path = tmp.name try: ...
[ { "docstring": "Reads data from a JSON file and returns it.", "function_declaration": "def read_json(file_path):", "function_name": "read_json", "parameter_list": "(file_path)" }, { "docstring": "Processes the data. This function can be modified according to the\nspecific processing needs. H...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef read_json(file_path):\n \"\"\"\n Reads a JSON file and returns the data as a Python object.\n \n :param file_path: The path to the JSON file\n :return: The da...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074326", "row_id": 74326, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150745']" }
0.652496
Filter_74326
I
[ "read_json", "process_data", "write_json", "process_json_files" ]
4
[ [ "process_json_files", "process_data" ], [ "process_json_files", "read_json" ], [ "process_json_files", "write_json" ] ]
3
[ "process_data" ]
false
[]
false
pytest
true
[]
true
07690d4a8e8f7ad079e01b57af2483b5e0ff11dd
e9eff56b298977b1101a32359b573b0383bd8ba9
v1.0
instruct
Filter
Filter_74344_I
Can you provide a Python code snippet to generate a spiral pattern using recursion?
import matplotlib.pyplot as plt import numpy as np def draw_spiral_pattern(ax, x, y, angle, length, scale, min_length): """ Recursively draws a spiral pattern. Parameters: ax (Axes): Matplotlib Axes object to draw on. x, y (float): Current coordinates. angle (float): Current angle (in radi...
import matplotlib.pyplot as plt import pytest from solution import draw_spiral_pattern def test_draw_spiral_pattern(): fig, ax = plt.subplots() initial_length = 10.0 reduction_scale = 0.9 minimum_length = 1.0 # Ensure the function runs without errors try: draw_spiral_pattern(ax, x=0, ...
[ { "docstring": "Recursively draws a spiral pattern.\n\nParameters:\nax (Axes): Matplotlib Axes object to draw on.\nx, y (float): Current coordinates.\nangle (float): Current angle (in radians).\nlength (float): Current length of the spiral segment.\nscale (float): Scaling factor for the length.\nmin_length (flo...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\nimport numpy as np\n\ndef draw_spiral(ax, x, y, radius, angle, step, limit):\n \"\"\"\n Draws a spiral pattern using recursion.\n\n Parameters:\n -...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074344", "row_id": 74344, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_150791']" }
0.611026
Filter_74344
I
[ "draw_spiral_pattern", "create_spiral_plot" ]
2
[ [ "create_spiral_plot", "draw_spiral_pattern" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
5165656fd0e63c2e00a724ba32f0461a76a45fcf
bcf5741175098d28e27fed7baa25d3a9d13e55ba
v1.0
instruct
Filter
Filter_74439_I
Write a Python function that accepts a list of integers and returns a new list where each element is the sum of its digits. If the sum of the digits is greater than 9, the process should be repeated until a single-digit number is obtained. This single-digit number should be the element in the new list. This process is ...
def digital_root(n): """ Helper function to calculate the digital root of a number. """ while n >= 10: n = sum(int(digit) for digit in str(n)) return n def list_digital_root(lst): """ Returns a new list where each element is the digital root of the corresponding element in the input...
from solution import list_digital_root def test_single_digit(): assert list_digital_root([1, 2, 3]) == [1, 2, 3] def test_double_digits(): assert list_digital_root([10, 55, 99]) == [1, 1, 9] def test_mixed_digits(): assert list_digital_root([123, 456, 789]) == [6, 6, 6] def test_single_element(): as...
[ { "docstring": "Helper function to calculate the digital root of a number.", "function_declaration": "def digital_root(n):", "function_name": "digital_root", "parameter_list": "(n)" }, { "docstring": "Returns a new list where each element is the digital root of the corresponding element in t...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(num):\n \"\"\"\n Returns the sum of the digits of the number.\n Keep on summing the digits until a single digit is obtained.\n \"\"\"\n while num >= 10:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074439", "row_id": 74439, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151019']" }
0.759605
Filter_74439
I
[ "digital_root", "list_digital_root" ]
2
[ [ "list_digital_root", "digital_root" ] ]
1
[]
false
[]
false
pytest
true
[]
true
970390f4952c8c1c0e91248dd49e5a56be67f4a5
b3ed7c2697cf965bf501f166a4b447b1feb31333
v1.0
instruct
Filter
Filter_74449_I
Write a Python function to filter out all the prime numbers from a given list of integers. The function should return a new list containing only the prime numbers. The function should be named `extract_primes` and should take a single argument, `numbers`, which is a list of integers. A prime number is a natural number ...
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 extract_primes(numbers): ...
from solution import extract_primes def test_extract_primes_only_primes(): assert extract_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_extract_primes_mixed_numbers(): assert extract_primes([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 3, 5, 7, 11] def test_extract_primes_no_primes(): assert extract_p...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list of integers.", "function_declaration": "def extract_primes(numbers):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074449", "row_id": 74449, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151038']" }
0.668181
Filter_74449
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b976c403cba89c67f3f4032acf8b1f2a89e86f61
6ccb132cd5e38c925196bcf453e1b2745582268d
v1.0
instruct
Filter
Filter_74476_I
Can you explain how to create a simple dice rolling game in Python?
import random def roll_dice(): """ Simulate rolling a six-sided dice and return the result (a number between 1 and 6). """ return random.randint(1, 6) def roll_dice_game(num_rolls): """ Simulate rolling a dice num_rolls times and return a list of results. """ results = [] for _ in ...
from solution import roll_dice, roll_dice_game def test_roll_dice_within_bounds(): for _ in range(100): result = roll_dice() assert 1 <= result <= 6 def test_roll_dice_game_length(): result = roll_dice_game(10) assert len(result) == 10 def test_roll_dice_game_values(): result = roll_d...
[ { "docstring": "Simulate rolling a six-sided dice and return the result (a number between 1 and 6).", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulate rolling a dice num_rolls times and return a list of results.", ...
[ 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 roll_dice():\n \"\"\"\n Simulates rolling a dice and returns a randomly chosen integer between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_dice...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074476", "row_id": 74476, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151090']" }
0.592787
Filter_74476
I
[ "roll_dice", "roll_dice_game" ]
2
[ [ "roll_dice_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05b9f3cbed04557425680313fcb0a0c6fa69f230
c83a916da36c8fd24223eda77ed16f3b1726e3e3
v1.0
instruct
Filter
Filter_74502_I
Can you write a Python script to simulate the integration of a logistic differential equation for a population growth model? The script should use the `odeint` function from `scipy.integrate` to solve the logistic equation and plot the results using `matplotlib`. Additionally, the script should include a feature to adj...
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def logistic_model(y, t, r, K): """ Defines the differential equation for the logistic model. Arguments: y -- current population size t -- current time r -- growth rate K -- carrying capacity Returns...
from solution import logistic_model, simulate_logistic_growth def test_logistic_model_zero_population(): assert logistic_model(0, 0, 0.1, 100) == 0 def test_logistic_model_max_capacity(): assert logistic_model(100, 0, 0.1, 100) == 0 def test_logistic_model_growth(): assert logistic_model(50, 0, 0.1, 100)...
[ { "docstring": "Defines the differential equation for the logistic model.\n\nArguments:\ny -- current population size\nt -- current time\nr -- growth rate\nK -- carrying capacity\n\nReturns:\ndydt -- change in population size", "function_declaration": "def logistic_model(y, t, r, K):", "function_name": ...
[ 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\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import odeint\n\ndef logistic_model(y, t, r, K):\n \"\"\"\n Defines the differential equation for the logistic m...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00074502", "row_id": 74502, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151135']" }
0.339363
Filter_74502
I
[ "logistic_model", "simulate_logistic_growth", "plot_logistic_growth", "main" ]
4
[ [ "plot_logistic_growth", "simulate_logistic_growth" ], [ "simulate_logistic_growth", "logistic_model" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy", "scipy" ]
false
23eb22c24e545cacd6f047afb1733fdafb306920
d1848c970f699e5b474c003cb360ce1450d01197
v1.0
instruct
Filter
Filter_74537_I
Hello Qwen, how can I generate a list of all prime numbers within a given range, say from 1 to 100, using Python?
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, 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(5) == True assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_primes_in_range(): ...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers in the given range [start, end].", "function_declaration": "def primes_in_range(start...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074537", "row_id": 74537, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151217']" }
0.620262
Filter_74537
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
376729bd8f216859ddf671652df431841aca43cc
106391b375a79e2bb272fe644bc483e0b0616d9d
v1.0
instruct
Filter
Filter_74584_I
How can I use the `message` parameter in a Python function that I want to pass through an HTTP request?
from flask import Flask, request, jsonify app = Flask(__name__) def echo_message(message): """ Echoes the given message. """ return f"Received: {message}" @app.route('/echo', methods=['GET']) def echo(): message = request.args.get('message', '') response = echo_message(message) return jso...
import pytest from flask import Flask from flask.testing import FlaskClient from solution import app, echo_message @pytest.fixture def client(): with app.test_client() as client: with app.app_context(): yield client def test_echo_message(): assert echo_message("Hello") == "Received: Hello"...
[ { "docstring": "Echoes the given message.", "function_declaration": "def echo_message(message):", "function_name": "echo_message", "parameter_list": "(message)" }, { "docstring": null, "function_declaration": "def echo():", "function_name": "echo", "parameter_list": "()" } ]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n@app.route('/echo', methods=['GET'])\ndef echo_message():\n \"\"\"\n Returns a JSON response containing the provided...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074584", "row_id": 74584, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151329']" }
0.58401
Filter_74584
I
[ "echo_message", "echo" ]
2
[ [ "echo", "echo_message" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
3976063a5d1ae085e8e28cd9cbce688ae0938a47
ba9a9998bfb1ee3a9a722807d6bff553c14d07f0
v1.0
instruct
Filter
Filter_74591_I
Can you provide a detailed explanation of the Quick Select algorithm and its implementation in Python? Quick Select is an algorithm used to find the k-th smallest element in an unordered list. It is related to the QuickSort algorithm, and both use the partitioning method. However, Quick Select only partially sorts the ...
def partition(arr, low, high): """ Partition function for Quick Select. """ pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def ...
from solution import kth_smallest def test_kth_smallest(): arr1 = [3, 2, 1, 5, 4] assert kth_smallest(arr1, 0) == 1 assert kth_smallest(arr1, 1) == 2 assert kth_smallest(arr1, 2) == 3 assert kth_smallest(arr1, 3) == 4 assert kth_smallest(arr1, 4) == 5 arr2 = [7, 10, 4, 3, 20, 15] a...
[ { "docstring": "Partition function for Quick Select.", "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": "Quick Select function to find the k-th smallest element.", "function_declaration": "def q...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n \"\"\"\n This function takes last element as pivot, places the pivot element at its correct\n position in sorted array, and places all smaller (smalle...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074591", "row_id": 74591, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151348']" }
0.509701
Filter_74591
I
[ "partition", "quick_select", "kth_smallest" ]
3
[ [ "kth_smallest", "quick_select" ], [ "quick_select", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1836af8501e340d9a2868ebb0aba6af29a10fdc4
adfc1c90661dc0249458964e5900d6ae9a05ccb0
v1.0
instruct
Filter
Filter_74637_I
Can I use Python to simulate a掷 dice game where players roll two dice and the player with the highest roll wins? If yes, then please provide a simple Python code example.
import random def roll_dice(): """ Simulates rolling two six-sided dice and returns their sum. """ die1 = random.randint(1, 6) die2 = random.randint(1, 6) return die1 + die2 def play_game(): """ Simulates a two-player dice game. Each player rolls two dice, and the player with the h...
from solution import roll_dice, play_game def test_roll_dice_range(): for _ in range(1000): # Run the test multiple times to ensure randomness roll = roll_dice() assert 2 <= roll <= 12 def test_play_game_results(): for _ in range(1000): # Run the test multiple times to ensure randomness ...
[ { "docstring": "Simulates rolling two six-sided dice and returns their sum.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates a two-player dice game. Each player rolls two dice,\nand the player with the highest rol...
[ 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 roll_dice():\n \"\"\"\n Simulates rolling two dice and returns their sum.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n return d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074637", "row_id": 74637, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151460']" }
0.461091
Filter_74637
I
[ "roll_dice", "play_game" ]
2
[ [ "play_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7fddd69e31b1abc571ae0afc57c28fc3bb95c25
780fd5e83801b56b254b4b97fabaa6ca41f51a9f
v1.0
instruct
Filter
Filter_74647_I
Hello, I need help with creating a program to balance a binary search tree (BST) in Python. Balancing a BST means rearranging the nodes in the tree so that the tree is balanced, i.e., the depth of the two subtrees of every node never differs by more than one. Can you provide a simple algorithm to achieve this?
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def inorder_traversal(root): """ Helper function to perform in-order traversal of a BST. Returns a sorted list of the node values. """ if root is No...
from solution import TreeNode, balance_bst def bst_to_list(root): """ Helper function for testing. Converts a BST to a sorted list using in-order traversal. """ if root is None: return [] return bst_to_list(root.left) + [root.value] + bst_to_list(root.right) def test_single_node(): ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef inorder_traversal(root):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074647", "row_id": 74647, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151480']" }
0.612436
Filter_74647
I
[ "inorder_traversal", "sorted_list_to_bst", "balance_bst" ]
3
[ [ "balance_bst", "inorder_traversal" ], [ "balance_bst", "sorted_list_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f2eac86fb4542a0576ef8a8903f85572ff131fec
130d69afaf629c1a4b8f9f368987f4e7800f1b8b
v1.0
instruct
Filter
Filter_74722_I
Can you assist in creating a Python script to automate the process of sending personalized emails to a list of recipients using a template? How can I handle errors such as invalid email addresses or failed deliveries?
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import re def is_valid_email(email): """ Validate the email address using a regular expression. """ regex = r'^\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' return re.match(regex, email) is not...
import pytest from unittest.mock import patch, call from solution import is_valid_email, send_email, send_personalized_emails def test_is_valid_email(): assert is_valid_email("test@example.com") == True assert is_valid_email("invalid-email") == False @patch("solution.smtplib.SMTP") def test_send_email_valid(m...
[ { "docstring": "Validate the email address using a regular expression.", "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": "Send an email using the SMTP server.", "function_declaration": "def send_email(...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nimport re\n\ndef send_personalized_email(sender_email, sender_password, recipient_email, s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074722", "row_id": 74722, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151620']" }
0.570633
Filter_74722
I
[ "is_valid_email", "send_email", "send_personalized_emails" ]
3
[ [ "send_email", "is_valid_email" ], [ "send_personalized_emails", "send_email" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1dac46d3ed2a0215d2fb6917855f1d7051aa2a2a
c0016723845fcbcb98e7150c52604d6eaab2a68d
v1.0
instruct
Filter
Filter_74740_I
Write a Python function to find the sum of all prime numbers within a given range. The function should take two parameters, representing the start and end of the range, and return the sum of all prime numbers within that range, inclusive. Make sure to include a brief docstring explaining the function's purpose.
def is_prime(n): """Checks if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def sum...
from solution import sum_of_primes def test_sum_of_primes_within_small_range(): assert sum_of_primes(1, 10) == 17 def test_sum_of_primes_within_large_range(): assert sum_of_primes(10, 20) == 60 def test_sum_of_primes_no_primes_in_range(): assert sum_of_primes(14, 16) == 0 def test_sum_of_primes_single_p...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers within the given range [start, end], inclusive.\n\nParameters:\nstart (int): The starting nu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Checks if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return Fals...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00074740", "row_id": 74740, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151651']" }
0.633503
Filter_74740
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89df3aa73d5730b55219684d084ed9f7a8cb91a3
90b69ba17c413ec6169ec289734b28368186bc8b
v1.0
instruct
Filter
Filter_74790_I
Can you generate a Python script that reads a JSON file and prints out the nested data in a structured format? Suppose the JSON file contains data about a book, including details like chapters, sections, and subsections?
import json def print_nested_data(data, indent=0): """ Recursively prints nested data from a dictionary. Args: data (dict): The dictionary containing nested data. indent (int): The current indentation level. """ indent_str = ' ' * indent if isinstance(data, dict): ...
import json from solution import print_nested_data, read_and_print_json def test_print_nested_data(): data = { "title": "Sample Book", "chapters": [ { "title": "Chapter 1", "sections": [ { "title": "Section 1.1"...
[ { "docstring": "Recursively prints nested data from a dictionary.\n\nArgs:\n data (dict): The dictionary containing nested data.\n indent (int): The current indentation level.", "function_declaration": "def print_nested_data(data, indent=0):", "function_name": "print_nested_data", "parameter_l...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef print_nested_data(data, indent=0):\n \"\"\"\n Recursively prints nested data from a dictionary with indentation.\n \"\"\"\n for key, value in data.items():\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074790", "row_id": 74790, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151754']" }
0.608162
Filter_74790
I
[ "print_nested_data", "read_and_print_json" ]
2
[ [ "read_and_print_json", "print_nested_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63d85c109e4f0f978cbfa3d558e38ad908aaba18
dc5059d4be230b386cf45bbe666f883b38ea67a1
v1.0
instruct
Filter
Filter_74806_I
How can I calculate the total distance of a trip using GPS coordinates in Python?
import math def haversine_distance(lat1, lon1, lat2, lon2): """ Calculate the Haversine distance between two points on the Earth. """ # Radius of Earth in kilometers R = 6371.0 d_lat = math.radians(lat2 - lat1) d_lon = math.radians(lon2 - lon1) a = math.sin(d_lat / 2)**2 + math.cos(mat...
import pytest from solution import total_trip_distance def test_single_point(): coordinates = [(0, 0)] assert total_trip_distance(coordinates) == 0 def test_two_points_same_location(): coordinates = [(0, 0), (0, 0)] assert total_trip_distance(coordinates) == 0 def test_straight_line(): coordinate...
[ { "docstring": "Calculate the Haversine distance between two points on the Earth.", "function_declaration": "def haversine_distance(lat1, lon1, lat2, lon2):", "function_name": "haversine_distance", "parameter_list": "(lat1, lon1, lat2, lon2)" }, { "docstring": "Calculate the total distance o...
[ 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 haversine_distance(coord1, coord2):\n \"\"\"\n Calculate the Haversine distance between two points on the earth (specified in decimal degrees)\n \n Parameters:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074806", "row_id": 74806, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151782']" }
0.551084
Filter_74806
I
[ "haversine_distance", "total_trip_distance" ]
2
[ [ "total_trip_distance", "haversine_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7ebe1e13611a4166b33ad1029225b2b3aec490b
5dfb48f3ede26210a9b87cdc42def225851ade75
v1.0
instruct
Filter
Filter_74877_I
Can you provide a Python function to convert a list of integers to a list of their corresponding English words?
def number_to_words(n): """ Converts an integer n to its corresponding English words. """ ones = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"] teens = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"] ...
from solution import number_to_words, numbers_list_to_words def test_number_to_words_single_digit(): assert number_to_words(0) == "Zero" assert number_to_words(5) == "Five" def test_number_to_words_teens(): assert number_to_words(10) == "Ten" assert number_to_words(15) == "Fifteen" assert number_t...
[ { "docstring": "Converts an integer n to its corresponding English words.", "function_declaration": "def number_to_words(n):", "function_name": "number_to_words", "parameter_list": "(n)" }, { "docstring": "Converts a list of integers to a list of their corresponding English words.", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def number_to_words(n):\n \"\"\"\n Converts a single digit number to its corresponding English word.\n \"\"\"\n num_words = {\n 0: \"zero\", 1: \"one\", 2: \"two\", 3: \"thr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074877", "row_id": 74877, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151906']" }
0.575284
Filter_74877
I
[ "number_to_words", "numbers_list_to_words" ]
2
[ [ "numbers_list_to_words", "number_to_words" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b2e7efcaaff7346e339b46e068c7dceb6841a8d
63aa070bd302c75bdf876a2dc2cda3d7b0e8eb03
v1.0
instruct
Filter
Filter_74879_I
What if I want to create a simple blockchain in Python? Can you provide a basic example?
import hashlib import time class Block: def __init__(self, index, previous_hash, timestamp, data, hash): self.index = index self.previous_hash = previous_hash self.timestamp = timestamp self.data = data self.hash = hash def calculate_hash(index, previous_hash, timestamp, da...
from solution import Block, calculate_hash, create_genesis_block, create_new_block import time def test_create_genesis_block(): genesis_block = create_genesis_block() assert genesis_block.index == 0 assert genesis_block.previous_hash == "0" assert genesis_block.data == "Genesis Block" assert isinst...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, previous_hash, timestamp, data, hash):\n self.index = index\n self.previous_hash = previous_hash\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074879", "row_id": 74879, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151911']" }
0.376033
Filter_74879
I
[ "calculate_hash", "create_genesis_block", "create_new_block" ]
3
[ [ "create_genesis_block", "calculate_hash" ], [ "create_new_block", "calculate_hash" ] ]
2
[]
false
[ "Block" ]
true
pytest
true
[]
true
2f5bc28a22368010f68048ee22a99437e7d8e63d
654f0063247863cee902e3f4a9891e9a54619631
v1.0
instruct
Filter
Filter_74918_I
How can I convert an array of strings to an array of their hashes in Python?
import hashlib def string_to_hash(string): """ Converts a string to its SHA256 hash. """ return hashlib.sha256(string.encode()).hexdigest() def array_of_strings_to_hashes(array): """ Converts an array of strings to an array of their hashes. """ return [string_to_hash(string) for string...
from solution import array_of_strings_to_hashes def test_array_of_strings_to_hashes(): input_data = ["hello", "world", "test"] expected_hashes = [ '5d41402abc4b2a76b9719d911017c592', '6dcd4ce23d88e2ee9568ba546c007c63', '098f6bcd4621d373cade4e832627b4f6' ] # Convert string to th...
[ { "docstring": "Converts a string to its SHA256 hash.", "function_declaration": "def string_to_hash(string):", "function_name": "string_to_hash", "parameter_list": "(string)" }, { "docstring": "Converts an array of strings to an array of their hashes.", "function_declaration": "def array...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convert_to_hashes(strings):\n \"\"\"\n Converts an array of strings to an array of their hashes.\n \n Args:\n strings (list of str): List of strings to be hashed.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074918", "row_id": 74918, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_151986']" }
0.543361
Filter_74918
I
[ "string_to_hash", "array_of_strings_to_hashes" ]
2
[ [ "array_of_strings_to_hashes", "string_to_hash" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f4af38e555d0f18461bdcd616b65e2d2f8a659f
8cece1e069ce53bf4d30d2dd9660a15c74533530
v1.0
instruct
Filter
Filter_74952_I
I am trying to write a function in Python that returns a list of all prime numbers up to a given number n. How can I do this?
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 max_divisor = int(num**0.5) + 1 for d in range(3, max_divisor, 2): if num % d == 0: r...
from solution import list_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(20) == False def test_list_primes_up_to_10(): assert list_primes(10) == [2, 3, 5, 7] def test_list_prime...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers up to and including n.", "function_declaration": "def list_prim...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00074952", "row_id": 74952, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152056']" }
0.710727
Filter_74952
I
[ "is_prime", "list_primes" ]
2
[ [ "list_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
338e460a94d4c300ec88c0ea102077209c855304
f877cc37b768c384e7b4cf12314ecfbf66a074b9
v1.0
instruct
Filter
Filter_74962_I
Create a Python script that simulates a dice game where two players roll a fair six-sided die. The game proceeds until one player reaches a score of 20 or more. Each player's score is the sum of their dice rolls. After each roll, the current scores are displayed. The script should include a function to roll the die and...
import random def roll_die(): """ Simulates rolling a fair six-sided die. Returns a random integer between 1 and 6, inclusive. """ return random.randint(1, 6) def play_dice_game(target_score=20): """ Simulates a dice game where two players roll a six-sided die until one player reaches ...
from solution import roll_die, play_dice_game def test_roll_die(): for _ in range(1000): # Roll the die 1000 times to test randomness result = roll_die() assert 1 <= result <= 6 def test_play_dice_game(): winner, score = play_dice_game() assert winner in ["Player 1", "Player 2"] asser...
[ { "docstring": "Simulates rolling a fair six-sided die.\nReturns a random integer between 1 and 6, inclusive.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Simulates a dice game where two players roll a six-sided die\nunti...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a fair six-sided die.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_dice_game():\n player1_score = 0\n play...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00074962", "row_id": 74962, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152077']" }
0.551585
Filter_74962
I
[ "roll_die", "play_dice_game" ]
2
[ [ "play_dice_game", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
526a400a18f46ab163669ad5bccd46353c3d4d1c
473cdd100ee368da519e5bacb5fb76f92593f26b
v1.0
instruct
Filter
Filter_74967_I
Write a Python code to simulate a simple game where the player tries to guess a random number within a certain range. The game should allow the player to make multiple attempts until they guess the correct number, and the program should provide feedback on whether the guess is too high, too low, or correct. After each ...
import random def guess_number_game(range_start=1, range_end=100): """ Runs a number guessing game where the player tries to guess a random number within the specified range. After each guess, feedback is provided on whether the guess is too high, too low, or correct. """ number_to_guess = ran...
from unittest.mock import patch import io def test_guess_number_game_correct_first_try(): with patch('builtins.input', side_effect=[42]): with patch('random.randint', return_value=42): attempts = guess_number_game(1, 100) assert attempts == 1 def test_guess_number_game_multiple_tri...
[ { "docstring": "Runs a number guessing game where the player tries to guess a random number \nwithin the specified range. After each guess, feedback is provided on whether\nthe guess is too high, too low, or correct.", "function_declaration": "def guess_number_game(range_start=1, range_end=100):", "func...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef guess_number_game(range_start=1, range_end=100):\n \"\"\"\n Runs a number guessing game where the player tries to guess a random number \n within the specified ra...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00074967", "row_id": 74967, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152090']" }
0.581871
Filter_74967
I
[ "guess_number_game", "play_guessing_game" ]
2
[ [ "play_guessing_game", "guess_number_game" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a5088f308926cefc61fedb979e75ae34bc3cca56
211e28905a7829bf6837dd0d27c6a300c777bbb7
v1.0
instruct
Filter
Filter_75017_I
Write a Python script to list all the files in a directory and its subdirectories, and print their sizes in a human-readable format. For example, sizes should be displayed in bytes, kilobytes, megabytes, or gigabytes as appropriate.
import os def human_readable_size(size): """ Convert a file size to a human readable format. """ for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']: if size < 1024: return f"{size:.2f} {unit}" size /= 1024 def list_files_with_sizes(directory): """ List all files in the...
import pytest from solution import list_files_with_sizes, human_readable_size def test_human_readable_size(): assert human_readable_size(512) == "512.00 B" assert human_readable_size(2048) == "2.00 KB" assert human_readable_size(1048576) == "1.00 MB" assert human_readable_size(1073741824) == "1.00 GB" ...
[ { "docstring": "Convert a file size to a human readable format.", "function_declaration": "def human_readable_size(size):", "function_name": "human_readable_size", "parameter_list": "(size)" }, { "docstring": "List all files in the given directory and its subdirectories, \nprinting their siz...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef human_readable_size(size):\n \"\"\"\n Convert a file size to a human readable format.\n \"\"\"\n for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']:\n if size ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075017", "row_id": 75017, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152203']" }
0.614035
Filter_75017
I
[ "human_readable_size", "list_files_with_sizes" ]
2
[ [ "list_files_with_sizes", "human_readable_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
da5be83b97ad33c7271a1c9c2163f0795068d948
2aa8d163dc4e7ef964d8be2c3c1d808eb432a1d9
v1.0
instruct
Filter
Filter_75030_I
How can I design a simple Sudoku puzzle generator in Python?
import random def create_empty_board(): return [[0] * 9 for _ in range(9)] def is_safe(board, row, col, num): for x in range(9): if board[row][x] == num or board[x][col] == num: return False start_row, start_col = 3 * (row // 3), 3 * (col // 3) for i in range(3): for j in ...
from solution import create_empty_board, is_safe, solve_sudoku, generate_sudoku def test_create_empty_board(): board = create_empty_board() assert len(board) == 9 for row in board: assert len(row) == 9 assert all(cell == 0 for cell in row) def test_is_safe(): board = create_empty_board...
[ { "docstring": null, "function_declaration": "def create_empty_board():", "function_name": "create_empty_board", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def is_safe(board, row, col, num):", "function_name": "is_safe", "parameter_list": "(board, row...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_valid(board, row, col, num):\n \"\"\"\n Check if num is a valid entry at board[row][col]\n \"\"\"\n for i in range(9):\n if board[row][i] == num or b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075030", "row_id": 75030, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152230']" }
0.447467
Filter_75030
I
[ "create_empty_board", "is_safe", "solve_sudoku", "find_empty_location", "remove_numbers_from_board", "generate_sudoku" ]
6
[ [ "generate_sudoku", "create_empty_board" ], [ "generate_sudoku", "remove_numbers_from_board" ], [ "generate_sudoku", "solve_sudoku" ], [ "solve_sudoku", "find_empty_location" ], [ "solve_sudoku", "is_safe" ] ]
5
[]
false
[]
false
pytest
true
[]
true
49343efcb165bb662c248ba0a3d1ecd506bb2fb9
0d790a19d53b7f63121c77fcce36ad29702baa6b
v1.0
instruct
Filter
Filter_75036_I
I need to sort an array of integers using the merge sort algorithm. Can you provide a Python implementation?
def merge_sort(arr): """ Sorts an array of integers using the merge sort algorithm. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right): ...
from solution import merge_sort def test_merge_sort_single_element(): assert merge_sort([1]) == [1] 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_s...
[ { "docstring": "Sorts an array of integers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted arrays into one sorted array.", "function_declaration": "def merge(le...
[ 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 an array of integers using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075036", "row_id": 75036, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152240']" }
0.668015
Filter_75036
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73fc61543300209cb71096428d54fc174299c414
d9f9e51681332f94d3c883aa4774772a19f664ce
v1.0
instruct
Filter
Filter_75046_I
Write a Python function to find the maximum sum of a subarray using the divide and conquer approach. The function should take an array of integers as input and return the maximum sum of any subarray within the array.
def max_crossing_sum(arr, left, mid, right): """ Helper function to find the maximum sum of a subarray crossing the midpoint. """ left_sum = float('-inf') total = 0 for i in range(mid, left-1, -1): total += arr[i] if total > left_sum: left_sum = total right_sum ...
from solution import find_maximum_subarray_sum def test_find_maximum_subarray_sum_single_element(): assert find_maximum_subarray_sum([1]) == 1 assert find_maximum_subarray_sum([-1]) == -1 def test_find_maximum_subarray_sum_entire_array(): assert find_maximum_subarray_sum([1, 2, 3, 4]) == 10 assert fin...
[ { "docstring": "Helper function to find the maximum sum of a subarray crossing the midpoint.", "function_declaration": "def max_crossing_sum(arr, left, mid, right):", "function_name": "max_crossing_sum", "parameter_list": "(arr, left, mid, right)" }, { "docstring": "Recursive function to fin...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, left, mid, right):\n # Include elements on the left of mid\n left_sum = float('-inf')\n sum_tmp = 0\n for i in range(mid, left-1, -1):\n sum_tmp +=...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075046", "row_id": 75046, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152257']" }
0.667478
Filter_75046
I
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_subarray_sum" ]
3
[ [ "find_maximum_subarray_sum", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5ab93103086555c4d4269b38f067577abbec359a
a47c5a9286a53146c9ddf20da10bc81fa6e242d6
v1.0
instruct
Filter
Filter_75100_I
As an AI Language Model, I want to generate a Python program that outputs the first 100 prime numbers. How can I do this?
def is_prime(n): """ Check if the number n is a prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
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(11) == True assert is_prime(20) == False assert is_prime(1) == False assert is_prime(-10) == False def test_first_n_primes():...
[ { "docstring": "Check if the number n is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if the number n is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n\n if n % 2 == 0 or n % 3 == 0:\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075100", "row_id": 75100, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152374']" }
0.5466
Filter_75100
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8d7b8bb9d9e9f3b10d61b95106c2ac0757a94f6
44f0ebaef76303066e6ac8546d45948281b55cb2
v1.0
instruct
Filter
Filter_75103_I
Can you generate a Python script that simulates a simple dice roll game where a player rolls a six-sided dice and tries to guess the number? Incorrect guesses should prompt the player to try again, and the game ends when the player guesses correctly.
import random def roll_dice(): """ Simulates rolling a six-sided dice and returns the result. """ return random.randint(1, 6) def dice_game(guess): """ Simulates the dice game where the player guesses the outcome of a dice roll. Continues until the correct guess is made. """ correc...
from solution import roll_dice, dice_game def test_roll_dice_range(): # Run the roll_dice function multiple times to ensure its output is within the 1-6 range. for _ in range(100): result = roll_dice() assert 1 <= result <= 6 def test_dice_game_correct_guess(monkeypatch): # Mock roll_dice ...
[ { "docstring": "Simulates rolling a six-sided dice and returns the result.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates the dice game where the player guesses the outcome of a dice roll.\nContinues until the c...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided dice and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_game(guess):\n \"\"\"\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075103", "row_id": 75103, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152381']" }
0.500707
Filter_75103
I
[ "roll_dice", "dice_game" ]
2
[ [ "dice_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94bd345fc99b382e0cade4b7758e8c14390b2cd2
b5e9550b23d4e55f70fca98246dde6a2d4d60068
v1.0
instruct
Filter
Filter_75128_I
The code snippet provided uses a while loop to determine if a number is prime. How can I modify the code to return all prime numbers within a given range, say from 10 to 50?
def is_prime(n): """ Determine 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 ...
from solution import is_prime, primes_in_range def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(7) def test_primes_in_range(): assert primes_in_range(10, 50) == [11, 13, 17, 19, 23, 29, 31, 37, 41, 4...
[ { "docstring": "Determine if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the given range [start, end].", "function_declaration": "def primes_in_ran...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075128", "row_id": 75128, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152428']" }
0.556391
Filter_75128
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6fd83bb7833f539ee8dff29bc9e4280a20e10562
06200804fe484915b72d30cfd89d0b7ef0480970
v1.0
instruct
Filter
Filter_75137_I
I want to create a simple data processing application using Python that reads a CSV file, processes the data, and writes the processed data to a new CSV file. Can you provide a basic example using the `pandas` library?
import pandas as pd def read_csv(file_path): """ Reads a CSV file and returns a DataFrame. """ return pd.read_csv(file_path) def process_data(df): """ Processes the data in the DataFrame. For the sake of this example, let's assume we want to add a new column 'Processed' which doubles the v...
import pandas as pd from solution import read_csv, process_data, write_csv, process_csv import os def test_read_csv(tmpdir): test_data = """Value 1 2 3 """ test_file = tmpdir.join("test.csv") test_file.write(test_data) df = read_csv(str(test_file)) assert df.shape == (3, 1) ass...
[ { "docstring": "Reads a CSV file and returns a DataFrame.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Processes the data in the DataFrame.\nFor the sake of this example, let's assume we want to add a ne...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\n\ndef process_csv(input_file_path, output_file_path):\n \"\"\"\n Reads a CSV file, processes the data, and writes the processed data to a new CSV file.\n\n Parame...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075137", "row_id": 75137, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152443']" }
0.543933
Filter_75137
I
[ "read_csv", "process_data", "write_csv", "process_csv" ]
4
[ [ "process_csv", "process_data" ], [ "process_csv", "read_csv" ], [ "process_csv", "write_csv" ] ]
3
[ "process_data" ]
false
[]
false
pytest
true
[ "pandas" ]
false
90e848c1f446a7446f4ee4dcbdf142672ea54066
9b1343ff4439ec3370fa96211d5255a87c0ffa7b
v1.0
instruct
Filter
Filter_75163_I
How can I create a binary tree and perform an in-order traversal on it in Python?
class TreeNode: """ Definition for a binary tree node. """ def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def in_order_traversal(root): """ Perform in-order traversal of a binary tree. Args: root (TreeNod...
from solution import TreeNode, in_order_traversal def test_in_order_traversal_empty_tree(): assert in_order_traversal(None) == [] def test_in_order_traversal_single_node(): root = TreeNode(1) assert in_order_traversal(root) == [1] def test_in_order_traversal_left_skewed_tree(): root = TreeNode(1, Tre...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef inorder_traversal(root):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075163", "row_id": 75163, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152497']" }
0.50641
Filter_75163
I
[ "in_order_traversal", "_in_order_helper" ]
2
[ [ "in_order_traversal", "_in_order_helper" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5ab606ecb171f3b505f06ffcf43f4cee4ac2beae
ea2a6849eb903559a932acc50c5bec8328310678
v1.0
instruct
Filter
Filter_75183_I
I want to create a Python script that calculates the sum of all the prime numbers in a given range. The range is defined by two numbers, `start` and `end`. How can I write this script?
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes_in_range(start, end): """ Returns the sum of all prime numbers...
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(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_sum_of_prime...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the given range [start, end].", "function_declaration": "def...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075183", "row_id": 75183, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152528']" }
0.610411
Filter_75183
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0da17a51257685bcf9db0b9a0daa04a1e8dd2dcc
465006a0fd12ce6f81fe46f3194139b0f2dbf10f
v1.0
instruct
Filter
Filter_75207_I
How can I create a Python script that prints the Fibonacci sequence up to the nth number?
def fibonacci(n): """ Returns a list of Fibonacci sequence up to the nth number. """ if n <= 0: return [] elif n == 1: return [0] elif n == 2: return [0, 1] sequence = [0, 1] while len(sequence) < n: sequence.append(sequence[-1] + sequence[-2]) re...
from solution import fibonacci, print_fibonacci import pytest from io import StringIO import sys def test_fibonacci_zero(): assert fibonacci(0) == [] def test_fibonacci_one(): assert fibonacci(1) == [0] def test_fibonacci_two(): assert fibonacci(2) == [0, 1] def test_fibonacci_five(): assert fibonac...
[ { "docstring": "Returns a list of Fibonacci sequence up to the nth number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Prints the Fibonacci sequence up to the nth number.", "function_declaration": "def print_fibo...
[ 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 Prints the Fibonacci sequence up to the nth number.\n \n Parameters:\n - n: The number of terms in the Fibonacci sequence to print.\n \n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075207", "row_id": 75207, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152580']" }
0.698819
Filter_75207
I
[ "fibonacci", "print_fibonacci" ]
2
[ [ "print_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63a5e7849b892271cd140bdc4a96978d5cf448c7
872923bea0fb267b7ab882afdab61c102ea987b9
v1.0
instruct
Filter
Filter_75241_I
How can I create a Python program that simulates a dice roll game where each player rolls a six-sided die and the player with the highest roll wins?
import random def roll_dice(): """ Simulates rolling a six-sided die and returns the result. """ return random.randint(1, 6) def simulate_game(player1, player2): """ Simulates a dice roll game between two players. Parameters: player1 (str): Name of the first player player2 (st...
from solution import roll_dice, simulate_game import pytest def test_roll_dice(): roll = roll_dice() assert 1 <= roll <= 6 def test_simulate_game_player1_wins(monkeypatch): rolls = iter([6, 3]) monkeypatch.setattr('solution.roll_dice', lambda: next(rolls)) assert simulate_game("Alice", "Bob") == "...
[ { "docstring": "Simulates rolling a six-sided die and returns the result.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates a dice roll game between two players.\n\nParameters:\nplayer1 (str): Name of the first pla...
[ 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 roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_roll_game(player1_name, pla...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075241", "row_id": 75241, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152651']" }
0.565324
Filter_75241
I
[ "roll_dice", "simulate_game" ]
2
[ [ "simulate_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bffd57e15cca67f209cd9e8cc87ed23eb45e173c
0797520e04002f051870dcbe34cdb32193d30fd2
v1.0
instruct
Filter
Filter_75264_I
How can I define a function to calculate the prime numbers within a given range in Python?
def is_prime(n): """ Helper function to check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, 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(5) == True assert is_prime(29) == True assert is_prime(30) == False def test_primes_in_range(): assert primes_in_range(1, 10...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers within the given range [start, end].", "function_declaration": "de...
[ 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 a prime number.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n elif n % 2 == 0 or n % 3...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075264", "row_id": 75264, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152716']" }
0.760446
Filter_75264
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
17e1a71b406bfcaaba37c4de74beeccaffde3645
5fcca22712b39884eb0603a6133d81b9eddb9951
v1.0
instruct
Filter
Filter_75287_I
How can I create a process that continuously generates and pushes code to a GitHub repository in Python?
import os import time from datetime import datetime REPO_DIR = 'path/to/repo' CHECK_INTERVAL = 3600 # Check every hour def generate_code(): """ Function to modify or generate new code. """ with open(os.path.join(REPO_DIR, 'example.py'), 'a') as f: f.write(f'# Auto-generated comment at {dateti...
import os import pytest import subprocess from solution import generate_code, commit_and_push_changes REPO_DIR = 'path/to/repo' def setup_module(module): """ Setup actions to initialize a temporary managed git repository for testing """ if os.path.exists(REPO_DIR): subprocess.run(['rm', '-rf',...
[ { "docstring": "Function to modify or generate new code.", "function_declaration": "def generate_code():", "function_name": "generate_code", "parameter_list": "()" }, { "docstring": "Function to add, commit, and push changes to the GitHub repository.", "function_declaration": "def commit...
[ 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\nfrom git import Repo\n\ndef create_and_push_code(repo_path, file_path):\n \"\"\"\n Create a Python file with code and push it to GitHub repository.\n :param re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075287", "row_id": 75287, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152752']" }
0.523322
Filter_75287
I
[ "generate_code", "commit_and_push_changes", "run_continuously" ]
3
[ [ "run_continuously", "commit_and_push_changes" ], [ "run_continuously", "generate_code" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c47201196647a9e9a87fb02c763676321f1c2390
3f6c8335c58111add8668bbb7e51bbc8c1e7e30a
v1.0
instruct
Filter
Filter_75303_I
WebSocket is a network protocol that enables full-duplex communication channels over a single TCP connection. How can I implement a WebSocket server in Python? How can I send messages to a connected client and handle incoming messages from the client?
import asyncio import websockets connected_clients = set() async def register_client(websocket): connected_clients.add(websocket) try: async for message in websocket: await handle_message(websocket, message) finally: connected_clients.remove(websocket) async def handle_message...
import asyncio import websockets from solution import register_client, send_message_to_all_clients async def mock_client(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello Server!") response = await websocket.recv() return response async def test_register_cl...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import asyncio\nimport websockets\n\nconnected_clients = set()\n\nasync def register_client(websocket):\n connected_clients.add(websocket)\n try:\n async for message in websocket:...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075303", "row_id": 75303, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152778']" }
0.503182
Filter_75303
I
[ "register_client", "handle_message", "send_message_to_all_clients", "main" ]
4
[ [ "register_client", "handle_message" ] ]
1
[]
false
[]
false
pytest
true
[ "websockets" ]
false
ebf97cffff698869eb84de4406874ef5f9b00ee5
23778c79c1f1c612d12cd9a8707c5aa19b8290ad
v1.0
instruct
Filter
Filter_75338_I
Can you provide a Python script to simulate a simple game of rock-paper-scissors with a computer opponent? The game should allow the user to play multiple rounds, keep score, and display the final results after all rounds are completed.
import random def get_computer_choice(): """ Randomly returns 'rock', 'paper', or 'scissors'. """ return random.choice(['rock', 'paper', 'scissors']) def decide_winner(user_choice, computer_choice): """ Determines the winner of a rock-paper-scissors game round. Returns 'user', 'computer', ...
from solution import get_computer_choice, decide_winner, play_round def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] for _ in range(100): # repeat the check multiple times to cover randomness assert get_computer_choice() in choices def test_decide_winner(): assert decide_wi...
[ { "docstring": "Randomly returns 'rock', 'paper', or 'scissors'.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner of a rock-paper-scissors game round.\nReturns 'user', 'computer', o...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly returns 'rock', 'paper', or 'scissors'.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors'])\n\ndef decide...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075338", "row_id": 75338, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152846']" }
0.386807
Filter_75338
I
[ "get_computer_choice", "decide_winner", "play_round", "play_game" ]
4
[ [ "play_game", "play_round" ], [ "play_round", "decide_winner" ], [ "play_round", "get_computer_choice" ] ]
3
[]
false
[]
false
pytest
true
[]
true
757b34a1ed7568e24be0ba344ddf0e804112c218
5c0bb0af7a399dd72c05bd64e99eb111df0bae2c
v1.0
instruct
Filter
Filter_75345_I
Hi, I want to create a Python script to find prime numbers up to a given number. How can I do that?
def is_prime(n): """ Check if a number is prime. 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 == 0: return False i = 5...
from solution import is_prime, find_primes_up_to def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False assert is_prime(29) == ...
[ { "docstring": "Check if a number is prime.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all prime num...
[ 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": "00075345", "row_id": 75345, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152858']" }
0.657158
Filter_75345
I
[ "is_prime", "find_primes_up_to" ]
2
[ [ "find_primes_up_to", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68ef16472d693f2cd8f4b3f65b64e00e9af5b77b
c84893f05c5044bc7265cc8094819ce76e8f0a6c
v1.0
instruct
Filter
Filter_75363_I
I need a simple program in Python to simulate a basic game of rock-paper-scissors. The game should allow a user to play against the computer. The computer's choice should be random, and the game should determine the winner based on the classic rules: rock crushes scissors, paper covers rock, and scissors cut paper. Cou...
import random def get_computer_choice(): """Returns a random choice of 'rock', 'paper', or 'scissors' for the computer.""" choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(player_choice, computer_choice): """Determines the winner of a rock-paper-scissors game....
def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] for _ in range(100): assert get_computer_choice() in choices def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'player' assert determine_winner('scissors', 'paper') == 'player' assert determine...
[ { "docstring": "Returns a random choice of 'rock', 'paper', or 'scissors' for the computer.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner of a rock-paper-scissors game.\n\nArgs:\...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Returns a random choice from 'rock', 'paper', 'scissors'.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors'])\n\nd...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075363", "row_id": 75363, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152888']" }
0.323181
Filter_75363
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ], [ "play_game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
false
[]
true
0245f148e465d6e6a721568a851c473e136fd8ff
d6542b52b90c4cfece410cc72f7b5d11331c02a5
v1.0
instruct
Filter
Filter_75371_I
Write a Python function to recursively convert all dictionary keys to snake_case. This function should handle nested dictionaries and lists as well. For example, a dictionary like `{'FooBar': {'BazQux': [{'QuuxCorge': 1}]}}` should be converted to `{'foo_bar': {'baz_qux': [{'quux_corge': 1}]}}`.
import re def snake_case(s): """ Converts a string to snake_case. """ return re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower() def convert_keys_to_snake_case(data): """ Recursively converts all dictionary keys to snake_case. """ if isinstance(data, dict): return {snake_case(key): conv...
import pytest from solution import convert_keys_to_snake_case def test_convert_simple_dict(): assert convert_keys_to_snake_case({'FooBar': 1}) == {'foo_bar': 1} def test_convert_nested_dict(): assert convert_keys_to_snake_case({'FooBar': {'BazQux': 2}}) == {'foo_bar': {'baz_qux': 2}} def test_convert_complex...
[ { "docstring": "Converts a string to snake_case.", "function_declaration": "def snake_case(s):", "function_name": "snake_case", "parameter_list": "(s)" }, { "docstring": "Recursively converts all dictionary keys to snake_case.", "function_declaration": "def convert_keys_to_snake_case(dat...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef to_snake_case(name):\n \"\"\"\n Convert camel case or Pascal case string to snake case.\n \"\"\"\n s1 = re.sub('([a-z])([A-Z])', r'\\1_\\2', name)\n return s1.l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075371", "row_id": 75371, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152910']" }
0.615754
Filter_75371
I
[ "snake_case", "convert_keys_to_snake_case" ]
2
[ [ "convert_keys_to_snake_case", "snake_case" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf0cccf79c6d1b7295af8de70eb1d632f4adbc18
4fc22c3e2e6df7d723eced0fa58f75efb3c8c808
v1.0
instruct
Filter
Filter_75373_I
Write a Python program that reads a text file and counts the occurrences of each word. The program should ignore common stop words like "the", "and", "is", etc. and also handle punctuation. The program should output the word counts in descending order of frequency.
import string from collections import Counter STOP_WORDS = {'the', 'and', 'is', 'in', 'to', 'with', 'a', 'an', 'of', 'for', 'on', 'it', 'this', 'that', 'these', 'those', 'there', 'here', 'by', 'as', 'at', 'be', 'but'} def clean_word(word): return word.strip(string.punctuation).lower() def count_words(filename): ...
import pytest from solution import count_words from collections import Counter import os # Create temporary text files for testing def create_temp_file(contents, filename): with open(filename, 'w') as file: file.write(contents) def test_count_words_simple_text(): text = "Hello world! Hello everyone." ...
[ { "docstring": null, "function_declaration": "def clean_word(word):", "function_name": "clean_word", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def count_words(filename):", "function_name": "count_words", "parameter_list": "(filename)" } ]
[ 0, 0, 1 ]
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\nSTOP_WORDS = {'the', 'and', 'is', 'in', 'it', 'of', 'to', 'a', 'that'}\n\ndef clean_word(word):\n \"\"\"\n Removes punctuation from the word...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075373", "row_id": 75373, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152912']" }
0.767772
Filter_75373
I
[ "clean_word", "count_words" ]
2
[ [ "count_words", "clean_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d1403f9b2c215a630e4d00e925c6b7f9d71206c
1e890b83001e77f338ce48493362a96fc00d0e19
v1.0
instruct
Filter
Filter_75395_I
I need help with writing a Python script to filter phone numbers from a text file and save them to a new file. The phone numbers can be in different formats, such as (123) 456-7890, 123-456-7890, or 123.456.7890. How can I do this?
import re def extract_phone_numbers(input_text): """ Extracts phone numbers from the given text. Phone numbers can be in different formats such as: - (123) 456-7890 - 123-456-7890 - 123.456.7890 Args: input_text (str): The text containing phone numbers. Returns: L...
from solution import extract_phone_numbers, filter_phone_numbers_from_file import tempfile def test_extract_phone_numbers(): sample_text = """ Here are some phone numbers: - (123) 456-7890 - 987-654-3210 - 456.789.1234 - Some random text - (555)123-4567 """ expected_output = ['(123)...
[ { "docstring": "Extracts phone numbers from the given text.\n\nPhone numbers can be in different formats such as:\n- (123) 456-7890\n- 123-456-7890\n- 123.456.7890\n\nArgs:\ninput_text (str): The text containing phone numbers.\n\nReturns:\nList of extracted phone numbers.", "function_declaration": "def extr...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef filter_phone_numbers(input_file, output_file):\n \"\"\"\n Reads phone numbers from the input file, filters them and saves them to the output file.\n Phone numbers can...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075395", "row_id": 75395, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152947']" }
0.531072
Filter_75395
I
[ "extract_phone_numbers", "filter_phone_numbers_from_file" ]
2
[ [ "filter_phone_numbers_from_file", "extract_phone_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3792a7c749929a920c3aa14528c274148881119b
69f3cdf61a946c952ca0658cbc206baec44ae322
v1.0
instruct
Filter
Filter_75405_I
Write a Python function that calculates the next date in a given month and year. The function should handle leap years correctly and account for the varying number of days in each month. Additionally, the function should return an error message if the input date is invalid (e.g., 31st of April).
def is_leap_year(year): """ Returns True if the given year is a leap year, else False. """ if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: return True return False def get_days_in_month(year, month): """ Returns the number of days in a given month of a given year. """...
def test_is_leap_year(): assert is_leap_year(2020) == True assert is_leap_year(2021) == False assert is_leap_year(1900) == False assert is_leap_year(2000) == True def test_get_days_in_month(): assert get_days_in_month(2021, 1) == 31 assert get_days_in_month(2021, 2) == 28 assert get_days_in...
[ { "docstring": "Returns True if the given year is a leap year, else False.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Returns the number of days in a given month of a given year.", "function_declarat...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\n\ndef next_date(year, month, day):\n \"\"\"\n Returns the next date for the given day, month, and year.\n Handles leap years correctly and accounts for the varying nu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075405", "row_id": 75405, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_152976']" }
0.67643
Filter_75405
I
[ "is_leap_year", "get_days_in_month", "next_date" ]
3
[ [ "get_days_in_month", "is_leap_year" ], [ "next_date", "get_days_in_month" ] ]
2
[]
false
[]
false
pytest
false
[]
true
950438950424008721b8868fa5bbcb304a7c2142
8aa65dfbd64e2c31281e0ba44019ce9c6ae9d55a
v1.0
instruct
Filter
Filter_75421_I
Can you explain how the `solve_sudoku` function works in Python, assuming it uses a backtracking algorithm?
def is_valid(board, row, col, num): """ Check if it's valid to place num in board[row][col]. """ # Check row for c in range(9): if board[row][c] == num: return False # Check column for r in range(9): if board[r][col] == num: return False # Ch...
from solution import solve_sudoku def test_sudoku_solver(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0,...
[ { "docstring": "Check if it's valid to place num in board[row][col].", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Find an empty location in the board. An empty location is denoted b...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_sudoku(board):\n \"\"\"\n Solves the given Sudoku puzzle using a backtracking algorithm.\n \n Args:\n board (List[List[int]]): A 9x9 list of lists representing the Sud...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075421", "row_id": 75421, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153003']" }
0.366519
Filter_75421
I
[ "is_valid", "find_empty_location", "solve_sudoku" ]
3
[ [ "solve_sudoku", "find_empty_location" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
41d1b53400876e1834bd13a9f6e9da6c202cb46b
95b176cdc9fc3ed5ba3213e8ce55d42f2174e072
v1.0
instruct
Filter
Filter_75422_I
Write a Python function that calculates the sum of all prime numbers within a given range, including the endpoints. The function should be efficient and handle both small and large ranges.
def is_prime(n): """Helper function to check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import sum_primes_in_range def test_sum_primes_small_range(): assert sum_primes_in_range(1, 10) == 17 # 2 + 3 + 5 + 7 def test_sum_primes_single_number(): assert sum_primes_in_range(5, 5) == 5 # 5 is prime assert sum_primes_in_range(4, 4) == 0 # 4 is not prime def test_sum_primes_lar...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Computes the sum of all prime numbers within the given range [start, end].", "function_declaration": "def s...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075422", "row_id": 75422, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153005']" }
0.677539
Filter_75422
I
[ "is_prime", "sum_primes_in_range" ]
2
[ [ "sum_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
11560fcefc0188ad45b1a21e3a744439bb7f3cd0
8af1cead4bff1cbf871b5821c8c421779d595379
v1.0
instruct
Filter
Filter_75438_I
In the given text, it is mentioned that the account with ID 123456 has been reviewed by user1 and will be disabled if the account does not comply with policies. Could you provide a Python code snippet that automates the process of checking if the account complies with the policies and disables it if it doesn't? For thi...
def check_compliance(account): """ Check if the account complies with the policies. For this example, the policy is that the account must not have made more than 100 transactions in the past month. Parameters: account (dict): A dictionary containing the account data, including its transaction h...
from solution import check_compliance, disable_account, review_and_disable_account def test_check_compliance_compliant_account(): account = {'id': 123456, 'transactions': [i for i in range(100)], 'active': True} assert check_compliance(account) == True def test_check_compliance_non_compliant_account(): ac...
[ { "docstring": "Check if the account complies with the policies.\nFor this example, the policy is that the account must not have made more than 100 transactions in the past month.\n\nParameters:\naccount (dict): A dictionary containing the account data, including its transaction history.\n\nReturns:\nbool: True...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_compliance(transactions):\n \"\"\"\n Checks if the account complies with the policy of making not more than 100 transactions in the past month.\n \n Parameters:\n tran...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075438", "row_id": 75438, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153050']" }
0.410943
Filter_75438
I
[ "check_compliance", "disable_account", "review_and_disable_account" ]
3
[ [ "review_and_disable_account", "check_compliance" ], [ "review_and_disable_account", "disable_account" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ead298c9f6299059546d0ea918a44595b4dcdc46
c8b581e7571446a1459de056bc0d03d45a19aa43
v1.0
instruct
Filter
Filter_75439_I
Can you provide a simple example of a Python program that uses RPC (Remote Procedure Call) through XML-RPC?
import xmlrpc.client from xmlrpc.server import SimpleXMLRPCServer # Server-side code def add(x, y): return x + y def start_server(): server = SimpleXMLRPCServer(('localhost', 9000)) server.register_function(add, 'add') print("Server is listening on port 9000...") server.serve_forever() # Client-s...
import subprocess import time import xmlrpc.client def start_server(): return subprocess.Popen( ['python', 'solution.py', 'server'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) def test_add_numbers_via_rpc(): server_process = start_server() time.sleep(2) # Give server some...
[ { "docstring": null, "function_declaration": "def add(x, y):", "function_name": "add", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def start_server():", "function_name": "start_server", "parameter_list": "()" }, { "docstring": null, "fu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import xmlrpc.client\nfrom xmlrpc.server import SimpleXMLRPCServer\n\n# Server code\ndef add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef start_serv...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075439", "row_id": 75439, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153052']" }
0.385384
Filter_75439
I
[ "add", "start_server", "add_numbers_via_rpc" ]
3
[ [ "start_server", "add" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1c02c1634bba054524064e1d4a4490edde3a49e8
2da0a14b62eed0417b9cad94dd63b5a031674ca5
v1.0
instruct
Filter
Filter_75447_I
I want to create a Python script that generates a list of prime numbers within a given range, say from 1 to 100. How can I do that?
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, generate_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(20) == False assert is_prime(-5) == False assert is_prime(0) == False assert is_prime(1) == F...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers within a given range [start, end].", "function_declaration": "def generate_primes(st...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075447", "row_id": 75447, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153074']" }
0.573314
Filter_75447
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1f3d8736ee33f1a7329f372cc312057aa3a669a1
7956dee67e6e9d71f704c37a71240dd3830128e0
v1.0
instruct
Filter
Filter_75477_I
Write a Python script to find the number of prime factors for each number in a given range [a, b]. The script should output the number along with its count of prime factors for each number in the range.
def prime_factors_count(num): """ Returns the number of prime factors of a given number. """ if num < 2: return 0 count = 0 n = num # Check for the number of 2s that divide num while n % 2 == 0: count += 1 n //= 2 # Check for odd factors from 3 onwa...
from solution import prime_factors_count, prime_factors_in_range def test_prime_factors_count(): assert prime_factors_count(1) == 0 assert prime_factors_count(2) == 1 assert prime_factors_count(3) == 1 assert prime_factors_count(4) == 2 assert prime_factors_count(5) == 1 assert prime_factors_co...
[ { "docstring": "Returns the number of prime factors of a given number.", "function_declaration": "def prime_factors_count(num):", "function_name": "prime_factors_count", "parameter_list": "(num)" }, { "docstring": "Returns a dictionary where keys are numbers in the range [a, b] and values \n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_prime_factors(num):\n \"\"\"\n Returns the number of prime factors of the given number.\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return False\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075477", "row_id": 75477, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153139']" }
0.645512
Filter_75477
I
[ "prime_factors_count", "prime_factors_in_range" ]
2
[ [ "prime_factors_in_range", "prime_factors_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1f456fda3f84e0346401451e19d2f564c5367bc5
f72acac950b5053091150eae93f534f75d6a3f07
v1.0
instruct
Filter
Filter_75482_I
Generate a Python function to find the k-th largest element in an unsorted list in O(n) time complexity.
import random def partition(arr, low, high): pivot = arr[high] i = low for j in range(low, high): if arr[j] > pivot: arr[i], arr[j] = arr[j], arr[i] i += 1 arr[i], arr[high] = arr[high], arr[i] return i def quickselect(arr, low, high, k): if low == high: ...
from solution import find_kth_largest def test_find_kth_largest(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 assert find_kth_largest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4 def test_find_kth_largest_single_element(): assert find_kth_largest([1], 1) == 1 def test_find_kth_largest_invalid_k(): t...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef quickselect(arr, left, right, k):\n \"\"\"\n Helper function to perform the Quickselect algorithm.\n \"\"\"\n if left == right: \n return arr[left]\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075482", "row_id": 75482, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153149']" }
0.642297
Filter_75482
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
65acf60e720c0fc4506549bb230595062a1b5fe5
5505447e7e8407ca489e6629ebeae0229d1381c3
v1.0
instruct
Filter
Filter_75489_I
I need to create a Python script to generate random usernames for a testing platform. The script should allow me to generate a specified number of usernames, with each username consisting of a random combination of letters (both uppercase and lowercase) and digits. The generated usernames should be saved to a file.
import random import string def generate_random_username(length=8): """ Generate a random username consisting of uppercase, lowercase letters, and digits. """ characters = string.ascii_letters + string.digits return ''.join(random.choice(characters) for _ in range(length)) def generate_usernames(c...
from solution import generate_random_username, generate_usernames, save_usernames_to_file import string import os def test_generate_random_username(): username = generate_random_username(8) assert len(username) == 8 assert all(c in string.ascii_letters + string.digits for c in username) def test_generate_...
[ { "docstring": "Generate a random username consisting of uppercase, lowercase letters, and digits.", "function_declaration": "def generate_random_username(length=8):", "function_name": "generate_random_username", "parameter_list": "(length=8)" }, { "docstring": "Generate a specified number o...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ndef generate_username(length=8):\n \"\"\"\n Generates a random username of a given length.\n The username consists of letters (both uppercase and lower...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075489", "row_id": 75489, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153161']" }
0.65291
Filter_75489
I
[ "generate_random_username", "generate_usernames", "save_usernames_to_file" ]
3
[ [ "generate_usernames", "generate_random_username" ] ]
1
[]
false
[]
false
pytest
true
[]
true
525c3d1f85f8b604feaf5c08d58c9ce87ce87b53
af94f9702b17a1effa0ee537801dc6e7bce1d6d4
v1.0
instruct
Filter
Filter_75519_I
I need to create a Python script that can parse an XML file and convert it into a JSON format. How can I achieve this using Python?
import xml.etree.ElementTree as ET import json def xml_to_dict(element): """ Converts an XML element and its children to a dictionary. """ def _element_to_dict(elem): """ Helper function to convert an element and its children recursively. """ result = {} for chil...
from solution import parse_xml_to_json import json def test_empty_xml(): empty_xml = "<root></root>" expected_json = json.dumps({"root": {}}, indent=4) assert parse_xml_to_json(empty_xml) == expected_json def test_simple_xml(): simple_xml = "<root><child>value</child></root>" expected_json = json....
[ { "docstring": "Converts an XML element and its children to a dictionary.", "function_declaration": "def xml_to_dict(element):", "function_name": "xml_to_dict", "parameter_list": "(element)" }, { "docstring": "Parses an XML string and converts it into JSON format.", "function_declaration...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import xml.etree.ElementTree as ET\nimport json\n\ndef xml_to_dict(element):\n \"\"\"\n Converts an XML element and its children to a dictionary.\n \"\"\"\n def _element_to_dict(el...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075519", "row_id": 75519, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153221']" }
0.719436
Filter_75519
I
[ "xml_to_dict", "parse_xml_to_json" ]
2
[ [ "parse_xml_to_json", "xml_to_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
00fda2e1c4f35eb256bbf8501db22b402639b7c7
f9c0effc46060f2dbb64bdd5e973302f185a350f
v1.0
instruct
Filter
Filter_75563_I
How can I implement the BFGS algorithm to solve an optimization problem in Python without using any external libraries like SciPy?
import numpy as np def bfgs(f, grad_f, x0, tol=1e-5, max_iter=100): """ BFGS optimization algorithm. :param f: Function to minimize. :param grad_f: Gradient of the function. :param x0: Initial guess. :param tol: Tolerance for stopping criteria. :param max_iter: Maximum number of iterations...
from solution import bfgs import numpy as np # Define a simple quadratic function and its gradient for testing def f(x): return (x[0] - 1)**2 + (x[1] - 2)**2 def grad_f(x): return np.array([2*(x[0] - 1), 2*(x[1] - 2)]) def test_bfgs_quadratic_function(): x0 = np.array([0.0, 0.0]) x_opt, f_opt = bfgs(...
[ { "docstring": "BFGS optimization algorithm.\n\n:param f: Function to minimize.\n:param grad_f: Gradient of the function.\n:param x0: Initial guess.\n:param tol: Tolerance for stopping criteria.\n:param max_iter: Maximum number of iterations.\n:return: The optimized variable and the function value at the optima...
[ 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 bfgs(f, grad, x0, tol=1e-5, max_iter=1000):\n \"\"\"\n BFGS algorithm for function optimization.\n \n Parameters:\n f : function to be minimized.\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075563", "row_id": 75563, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153314']" }
0.433238
Filter_75563
I
[ "bfgs", "line_search" ]
2
[ [ "bfgs", "line_search" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
02bc412d10e5d8635c3e45e7832c4527763ece9e
2aa924a4824436cf69143ef137c2322a3b80557a
v1.0
instruct
Filter
Filter_75571_I
Can you write a Python code that generates a list of all prime numbers within a given range?
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import generate_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(30) == False def test_generate_primes(): assert generate_primes(1, 10...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list of all prime numbers within a given range [start, end].", "function_declaration": "def generate_primes(start,...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_primes(start, end):\n \"\"\"\n Generates a list of all prime numbers within a given range from start to end (inclusive).\n \n Parameters:\n start (int): The startin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075571", "row_id": 75571, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153338']" }
0.666118
Filter_75571
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eeb6ec1c55f2861124a53b1414efa8a482d7d5f5
4b3385759d67a0b9ca0134ae97ff978fd8b368fc
v1.0
instruct
Filter
Filter_75598_I
Could you provide a Python code snippet to calculate the Extended GCD of two numbers and also find the modular multiplicative inverse?
def extended_gcd(a, b): """ Returns a tuple (gcd, x, y) such that gcd is the greatest common divisor of a and b, and x, y are the coefficients satisfying the equation ax + by = gcd. """ if b == 0: return a, 1, 0 else: gcd, x1, y1 = extended_gcd(b, a % b) x = y1 ...
from solution import extended_gcd, mod_inverse def test_extended_gcd(): gcd, x, y = extended_gcd(30, 20) assert gcd == 10 assert 30 * x + 20 * y == 10 gcd, x, y = extended_gcd(17, 31) assert gcd == 1 assert 17 * x + 31 * y == 1 gcd, x, y = extended_gcd(35, 15) assert gcd == 5 asse...
[ { "docstring": "Returns a tuple (gcd, x, y) such that gcd is the greatest common divisor\nof a and b, and x, y are the coefficients satisfying the equation\nax + by = gcd.", "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "d...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def extended_gcd(a, b):\n \"\"\"\n Performs the Extended Euclidean Algorithm to find the GCD of a and b.\n Returns a tuple (g, x, y) such that g = gcd(a, b) and g == a*x + b*y.\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075598", "row_id": 75598, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153391']" }
0.698955
Filter_75598
I
[ "extended_gcd", "mod_inverse" ]
2
[ [ "mod_inverse", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9760308de67885359ed3d269a2eb49c2a2b70f71
07a6ac834108b8e2610458316ff7e3c4a4b0c2d2
v1.0
instruct
Filter
Filter_75605_I
I need to automate a process that involves reading a CSV file, processing its contents, and then writing the processed data to a new CSV file. Can you provide a Python script that accomplishes this task?
import csv def read_csv(file_path): """ Reads a CSV file and returns its content as a list of dictionaries. """ with open(file_path, mode='r', newline='') as file: reader = csv.DictReader(file) return list(reader) def process_data(data): """ Processes the data read from the CSV...
import pytest import os from solution import read_csv, process_data, write_csv, process_csv def test_read_csv(): input_data = [ {'name': 'Alice', 'age': '30'}, {'name': 'Bob', 'age': '25'} ] input_file_path = 'test_input.csv' with open(input_file_path, mode='w', newline='') as file: ...
[ { "docstring": "Reads a CSV file and returns its content as a list of dictionaries.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Processes the data read from the CSV file.\nThis is a placeholder for actu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef process_data(row):\n \"\"\"\n Example processing function that could be customized.\n Here we'll assume processing simply means capitalizing each field value.\n \...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075605", "row_id": 75605, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153402']" }
0.65792
Filter_75605
I
[ "read_csv", "process_data", "write_csv", "process_csv" ]
4
[ [ "process_csv", "process_data" ], [ "process_csv", "read_csv" ], [ "process_csv", "write_csv" ] ]
3
[ "process_data" ]
false
[]
false
pytest
true
[]
true
115f1501b238dead8fdd65ba4170f06e34a4b6cf
303e2601aa3faf5e1c474975baecc9c35b0e9b22
v1.0
instruct
Filter
Filter_75632_I
Can you provide a Python code to visualize the distribution of prime numbers up to a certain number using a histogram?
import matplotlib.pyplot as plt import numpy as np def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False for i in range(2, int(np.sqrt(n)) + 1): if n % i == 0: return False return True def prime_distribution(limit): """ Generate a hist...
from solution import is_prime, prime_distribution def test_is_prime_known_values(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False assert is_prime(13) == True def test_is_prime_edge_cases(): assert is...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a histogram of prime numbers up to a certain number.", "function_declaration": "def prime_distribution(limit):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\nimport numpy as np\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075632", "row_id": 75632, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153460']" }
0.613322
Filter_75632
I
[ "is_prime", "prime_distribution" ]
2
[ [ "prime_distribution", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
029d88390ffe07887794c1715c6dac413146019d
e9fbe1dd443fe88a74dcaeb7ccf1c26368bd3dde
v1.0
instruct
Filter
Filter_75648_I
I want to create a Python script that prints the first 100 prime numbers. How can I do that?
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False divisor = 5 while divisor * divisor <= num: if num % divisor == 0 or num % (divisor + 2) == 0: ...
from solution import is_prime, first_n_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_first_n_primes(): assert first_n_primes(1) == [...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "first_n_prime...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075648", "row_id": 75648, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153491']" }
0.563379
Filter_75648
I
[ "is_prime", "first_n_primes", "print_first_100_primes" ]
3
[ [ "first_n_primes", "is_prime" ], [ "print_first_100_primes", "first_n_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8413520bd23d32ac016302275945030050c514fa
b286d366843d91ccdcf6e36dd54d58bd2417ca40
v1.0
instruct
Filter
Filter_75651_I
Write a Python script that uses the `random` module to simulate a simple dice roll game. The game should roll a six-sided dice and allow the user to guess the number. The user gets three attempts to guess correctly. If the user guesses the number correctly within the three attempts, they win. Otherwise, they lose. The ...
import random def roll_dice(): """ Rolls a six-sided dice and returns the result. """ return random.randint(1, 6) def display_rules(): """ Prints the rules of the dice roll game. """ print("Welcome to the Dice Roll Game!") print("You have three attempts to guess the number on a six...
from solution import roll_dice, display_rules, play_game def test_roll_dice(): for _ in range(100): # Perform the dice roll multiple times to ensure randomness result = roll_dice() assert 1 <= result <= 6 def test_display_rules(capsys): display_rules() captured = capsys.readouterr() a...
[ { "docstring": "Rolls a six-sided dice and returns the result.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Prints the rules of the dice roll game.", "function_declaration": "def display_rules():", "function_nam...
[ 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 roll_dice():\n \"\"\"\n Simulate rolling a six-sided dice.\n \"\"\"\n return random.randint(1, 6)\n\ndef display_rules():\n \"\"\"\n Display the rules of...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075651", "row_id": 75651, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153495']" }
0.480329
Filter_75651
I
[ "roll_dice", "display_rules", "play_game" ]
3
[ [ "play_game", "display_rules" ], [ "play_game", "roll_dice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4f9c7c94143ed4a2553cf0c0988c53772456fe42
f4f845c26f6271279a4d45f025f7154ab5b5f056
v1.0
instruct
Filter
Filter_75652_I
How can I create a Python script to simulate a simple dice game where two players roll a six-sided die multiple times and the player with the higher total score at the end of the game wins?
import random def roll_die(): """ Simulates rolling a six-sided die. Returns an integer between 1 and 6. """ return random.randint(1, 6) def simulate_dice_game(turns): """ Simulates a simple dice game between two players. Parameters: - turns: the number of times each player ro...
from solution import simulate_dice_game, determine_winner def test_simulate_dice_game(): score1, score2 = simulate_dice_game(5) assert 5 <= score1 <= 30 # Each die roll can range from 1 to 6, so 5 turns would range from 5 to 30 assert 5 <= score2 <= 30 def test_determine_winner_player1_wins(): result...
[ { "docstring": "Simulates rolling a six-sided die.\nReturns an integer between 1 and 6.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Simulates a simple dice game between two players.\n\nParameters:\n- turns: the number of...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_dice_game(rounds):\n \"\"\"\n Simulates a si...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075652", "row_id": 75652, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153496']" }
0.567474
Filter_75652
I
[ "roll_die", "simulate_dice_game", "determine_winner" ]
3
[ [ "simulate_dice_game", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
157ee937ea527b74df2539330ab10a4c67f238f7
c8e07192c57507c53cd058eb69196f0fa223e439
v1.0
instruct
Filter
Filter_75660_I
Can you provide a Python code snippet to find the largest prime number less than or equal to a given number n?
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return F...
from solution import is_prime, largest_prime_less_or_equal 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(29) is True assert is_prime(1) is False def test_largest_prime_less_or_equal(): assert largest_prime_less_or_equal(1...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the largest prime number less than or equal to n.", "function_declaration": "def largest_prime_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075660", "row_id": 75660, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153517']" }
0.737053
Filter_75660
I
[ "is_prime", "largest_prime_less_or_equal" ]
2
[ [ "largest_prime_less_or_equal", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c0e31f242eb114479b9f48580d22d63421f58b7a
edda5754e718b16dcf0ff8fe4518d081d127cad4
v1.0
instruct
Filter
Filter_75669_I
How can I process a directory of images using Python for image augmentation?
import os from PIL import Image, ImageEnhance, ImageOps def augment_image(image_path): """ Perform several augmentations on the input image and return a list of augmented images. """ image = Image.open(image_path) augmentations = [] # Rotation rotated_image = image.rotate(45) augme...
import os import shutil from PIL import Image from solution import process_directory, augment_image def setup_module(module): # Set up a temporary directory for input and output images os.makedirs("temp_input", exist_ok=True) os.makedirs("temp_output", exist_ok=True) # Create a sample image and s...
[ { "docstring": "Perform several augmentations on the input image and return a list of augmented images.", "function_declaration": "def augment_image(image_path):", "function_name": "augment_image", "parameter_list": "(image_path)" }, { "docstring": "Process all images in the directory for au...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nfrom PIL import Image\nimport numpy as np\n\ndef process_images(input_directory, output_directory, augmentation_function):\n \"\"\"\n Processes a directory of images using a g...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075669", "row_id": 75669, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153541']" }
0.482117
Filter_75669
I
[ "augment_image", "process_directory" ]
2
[ [ "process_directory", "augment_image" ] ]
1
[]
false
[]
false
pytest
true
[ "PIL" ]
false
f82314da60a97e396d9bb47110fe645f18770533
8a0583da64f9b0a1adeab1e5cb9bd81530919eec
v1.0
instruct
Filter
Filter_75694_I
Can you provide a code example for setting up a basic video streaming server using Python?
from flask import Flask, Response, render_template_string import cv2 app = Flask(__name__) @app.route('/') def index(): return render_template_string(''' <!doctype html> <html> <head> <title>Video Streaming</title> </head> <body> ...
from solution import app def test_index_route(): client = app.test_client() response = client.get('/') assert response.status_code == 200 assert b'Video Streaming' in response.data def test_video_feed_route(): client = app.test_client() response = client.get('/video_feed') assert response....
[ { "docstring": null, "function_declaration": "def index():", "function_name": "index", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def generate():", "function_name": "generate", "parameter_list": "()" }, { "docstring": null, "function_decla...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, Response, stream_with_context\nimport cv2\n\napp = Flask(__name__)\n\ndef generate_frames():\n camera = cv2.VideoCapture(0) # Open the default camera\n\n if not...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075694", "row_id": 75694, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153602']" }
0.454147
Filter_75694
I
[ "index", "generate", "video_feed" ]
3
[ [ "video_feed", "generate" ] ]
1
[]
false
[]
false
pytest
true
[ "cv2", "flask" ]
false
51f4437247f8f2d12be3b7a64d381c63628f8ba3
c66903048afb5b7d07765a58e45bf139ea00c511
v1.0
instruct
Filter
Filter_75724_I
Can you generate a code snippet to simulate a simple dice game where a player rolls two dice and tries to get a sum of 7 or 11 to win, otherwise, they lose?
import random def roll_dice(): """ Simulates rolling two dice and returns the sum of the face values. """ die1 = random.randint(1, 6) die2 = random.randint(1, 6) return die1 + die2 def dice_game(): """ Simulates a dice game where rolling a sum of 7 or 11 wins, otherwise lose. Retur...
import pytest from unittest import mock from solution import roll_dice, dice_game @mock.patch('random.randint', side_effect=[3, 4]) def test_roll_dice_sum7(mock_randint): assert roll_dice() == 7 @mock.patch('random.randint', side_effect=[5, 6]) def test_roll_dice_sum11(mock_randint): assert roll_dice() == 11 ...
[ { "docstring": "Simulates rolling two dice and returns the sum of the face values.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates a dice game where rolling a sum of 7 or 11 wins, otherwise lose.\nReturns a strin...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling two dice and returns their values as a tuple.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075724", "row_id": 75724, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153655']" }
0.484472
Filter_75724
I
[ "roll_dice", "dice_game" ]
2
[ [ "dice_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f75c1345771fa6bf783661d871c1e5718a1d1f2e
b9760080b1665df228d66a271df135f565be1b61
v1.0
instruct
Filter
Filter_75768_I
Write a Python function that takes a string representing an arithmetic expression in infix notation and converts it to a binary tree. The binary tree nodes should store the operators and operands as their data. Assume that the input string is a valid infix expression without any spaces and only contains single-digit nu...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def precedence(op): if op == '+' or op == '-': return 1 if op == '*' or op == '/': return 2 return 0 def construct_tree(infix): def build_tree(): right =...
from solution import TreeNode, construct_tree def inorder_traversal(root): if root is None: return "" return inorder_traversal(root.left) + root.value + inorder_traversal(root.right) def test_simple_expression(): root = construct_tree("2+3") assert inorder_traversal(root) == "2+3" def test_mu...
[]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef precedence(op):\n if op == '+' or op == '-':\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075768", "row_id": 75768, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153737']" }
0.529447
Filter_75768
I
[ "precedence", "construct_tree" ]
2
[ [ "construct_tree", "precedence" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b5cdd0e57cefb60b198f4204850dce31bae238f6
919ccfd2bfb8f3d8639fb69234e5753290f9a6a4
v1.0
instruct
Filter
Filter_75788_I
Can you generate a Python function that takes a string representing a ISBN number and checks if it is valid? The function should return `True` if the ISBN is valid, and `False` otherwise. It should handle both ISBN-10 and ISBN-13 formats.
def is_valid_isbn(isbn): """ Validates the given ISBN-10 or ISBN-13 string. Args: isbn (str): The ISBN number as a string. Returns: bool: 'True' if the ISBN is valid, 'False' otherwise. """ isbn = isbn.replace("-", "").replace(" ", "") if len(isbn) == 10: retur...
from solution import is_valid_isbn def test_valid_isbn10(): assert is_valid_isbn("0-306-40615-2") == True assert is_valid_isbn("0 306 40615 2") == True assert is_valid_isbn("0306406152") == True assert is_valid_isbn("0471958697") == True def test_invalid_isbn10(): assert is_valid_isbn("0306406153"...
[ { "docstring": "Validates the given ISBN-10 or ISBN-13 string.\n\nArgs:\nisbn (str): The ISBN number as a string.\n\nReturns:\nbool: 'True' if the ISBN is valid, 'False' otherwise.", "function_declaration": "def is_valid_isbn(isbn):", "function_name": "is_valid_isbn", "parameter_list": "(isbn)" },...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_isbn(isbn):\n \"\"\"\n Returns True if the given ISBN number is valid, otherwise returns False.\n \n Parameters:\n isbn (str): The ISBN number to check.\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075788", "row_id": 75788, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153788']" }
0.5928
Filter_75788
I
[ "is_valid_isbn", "is_valid_isbn10", "is_valid_isbn13" ]
3
[ [ "is_valid_isbn", "is_valid_isbn10" ], [ "is_valid_isbn", "is_valid_isbn13" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ea08271aa10789d5ef2f43a3a8e27126523fc3c1
5c14ae29e1eba3db5d0eeb22e814a1dbe8a3c8f4
v1.0
instruct
Filter
Filter_75805_I
Can you provide a Python script that generates a fractal pattern, specifically a Mandelbrot set?
import numpy as np import matplotlib.pyplot as plt def mandelbrot(c, max_iter): """ Determines whether a point is in the Mandelbrot set based on the number of iterations. """ z = 0 for n in range(max_iter): if abs(z) > 2: return n z = z*z + c return max_iter def gen...
import numpy as np from solution import mandelbrot, generate_mandelbrot def test_mandelbrot_max_iter(): c = 0.355 + 0.355j max_iter = 100 assert mandelbrot(c, max_iter) <= max_iter def test_mandelbrot_bailout(): c = 2 + 2j max_iter = 100 assert mandelbrot(c, max_iter) < max_iter def test_gene...
[ { "docstring": "Determines whether a point is in the Mandelbrot set based on the number of iterations.", "function_declaration": "def mandelbrot(c, max_iter):", "function_name": "mandelbrot", "parameter_list": "(c, max_iter)" }, { "docstring": "Generates a Mandelbrot fractal pattern.", "...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef mandelbrot(c, max_iter):\n \"\"\"\n Determines the number of iterations it takes for a point to escape the Mandelbrot set \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075805", "row_id": 75805, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153834']" }
0.395812
Filter_75805
I
[ "mandelbrot", "generate_mandelbrot", "plot_mandelbrot" ]
3
[ [ "generate_mandelbrot", "mandelbrot" ], [ "plot_mandelbrot", "generate_mandelbrot" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
f227f0462444332a667833290a77f33450b29125
d6dc1c146de0b176070e006c1698f4bd71f12262
v1.0
instruct
Filter
Filter_75814_I
Write a simple Python function to calculate the 10th Fibonacci number using a recursive approach.
def fibonacci(n): """ Returns the nth Fibonacci number using a recursive approach. """ if n <= 0: raise ValueError("n must be a positive integer.") if n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n - 1) + fibonacci(n - 2) # Function to calcul...
from solution import tenth_fibonacci, fibonacci def test_fibonacci_base_cases(): assert fibonacci(1) == 0 assert fibonacci(2) == 1 def test_fibonacci_recursive_case(): assert fibonacci(3) == 1 assert fibonacci(4) == 2 assert fibonacci(5) == 3 def test_tenth_fibonacci(): assert tenth_fibonacci...
[ { "docstring": "Returns the nth Fibonacci number using a recursive approach.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def tenth_fibonacci():", "function_name": "tenth_fibonacc...
[ 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 using a recursive approach.\n \"\"\"\n if n <= 0:\n raise ValueError(\"Input must be a positive integer.\")\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075814", "row_id": 75814, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153851']" }
0.729356
Filter_75814
I
[ "fibonacci", "tenth_fibonacci" ]
2
[ [ "tenth_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
878cd687837167dd14d54b97cb3f8af60f3ffade
102b97132ecdf49af4f8a42856de000daed5e895
v1.0
instruct
Filter
Filter_75816_I
Can you help me with a Python script that filters a list of numbers to only include those that are prime? A number is considered prime if it is greater than 1 and has no divisors other than 1 and itself.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n in (2, 3): return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return...
from solution import filter_primes def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_primes_with_mixed_numbers(): assert filter_primes([1, 2, 4, 5, 6, 7, 8, 10, 11]) == [2, 5, 7, 11] def test_filter_primes_with_no_primes(): assert filter_primes([...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filter a list of numbers to include only primes.", "function_declaration": "def filter_primes(numbers):", "function_name":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075816", "row_id": 75816, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153853']" }
0.630996
Filter_75816
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53bde59a60a78fa66522887f87ed7d2aa187194c
5fffdf8cdc418a7cf797af727db01b54fdae87d3
v1.0
instruct
Filter
Filter_75825_I
Write a Python function to build a min-heap from an array of integers. A min-heap is a binary tree where for every node other than the root, the value of each node is greater than or equal to the value of its parent. Implement the function `build_min_heap(arr)` that takes a list of integers and converts it into a min-h...
def heapify(arr, n, i): """ Heapify function to maintain the min-heap property. """ smallest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] < arr[smallest]: smallest = left if right < n and arr[right] < arr[smallest]: smallest = right if smallest ...
from solution import build_min_heap def test_build_min_heap_empty(): assert build_min_heap([]) == [] def test_build_min_heap_single_element(): assert build_min_heap([1]) == [1] def test_build_min_heap_sorted(): assert build_min_heap([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_build_min_heap_unsorted():...
[ { "docstring": "Heapify function to maintain the min-heap property.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Converts array into a min-heap in-place.", "function_declaration": "def build_min_heap(a...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n Heapify function to maintain the min-heap property.\n \"\"\"\n smallest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if left < n and a...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075825", "row_id": 75825, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153871']" }
0.69086
Filter_75825
I
[ "heapify", "build_min_heap" ]
2
[ [ "build_min_heap", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7895adbf2cd4e4dfc279a87bb2fee6e2a61fe863
9bff00b9cadc778b1a04407bb864ab61db78b029
v1.0
instruct
Filter
Filter_75829_I
What are the steps to create a simple alarm clock in Python?
import time from datetime import datetime def get_current_time(): """ Returns the current time in HH:MM format. """ return datetime.now().strftime("%H:%M") def check_alarm(alarm_time, current_time): """ Checks if the alarm time matches the current time. """ return alarm_time == current...
from datetime import datetime, timedelta from solution import get_current_time, check_alarm, alarm_clock def test_get_current_time_format(): current_time = get_current_time() assert len(current_time) == 5 assert current_time[2] == ':' assert current_time[:2].isdigit() and current_time[3:].isdigit() de...
[ { "docstring": "Returns the current time in HH:MM format.", "function_declaration": "def get_current_time():", "function_name": "get_current_time", "parameter_list": "()" }, { "docstring": "Checks if the alarm time matches the current time.", "function_declaration": "def check_alarm(alar...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nfrom datetime import datetime\n\ndef get_current_time():\n \"\"\"\n Returns the current time in HH:MM format.\n \"\"\"\n return datetime.now().strftime(\"%H:%M\")\n\nd...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075829", "row_id": 75829, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153878']" }
0.409577
Filter_75829
I
[ "get_current_time", "check_alarm", "alarm_clock" ]
3
[ [ "alarm_clock", "check_alarm" ], [ "alarm_clock", "get_current_time" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cc779e4ecb92ff1adb51c1bff4fe2aa68db2acb4
08ab9a248559e2317e522233560a738d33a8cf7f
v1.0
instruct
Filter
Filter_75837_I
Can you provide a Python code snippet that demonstrates how to use the turtle graphics library to draw a simple fractal, like the Sierpinski Triangle?
import turtle def draw_triangle(vertices, color, my_turtle): my_turtle.fillcolor(color) my_turtle.up() my_turtle.goto(vertices[0][0], vertices[0][1]) my_turtle.down() my_turtle.begin_fill() my_turtle.goto(vertices[1][0], vertices[1][1]) my_turtle.goto(vertices[2][0], vertices[2][1]) my_...
# Importing turtle makes it challenging to test the visual output directly # However, we can test the helper functions from solution import mid_point def test_mid_point(): assert mid_point((0, 0), (4, 4)) == (2, 2) assert mid_point((1, 1), (5, 1)) == (3, 1) assert mid_point((-1, -1), (3, 5)) == (1, 2) ...
[ { "docstring": null, "function_declaration": "def draw_triangle(vertices, color, my_turtle):", "function_name": "draw_triangle", "parameter_list": "(vertices, color, my_turtle)" }, { "docstring": null, "function_declaration": "def mid_point(point1, point2):", "function_name": "mid_po...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import turtle\n\ndef draw_triangle(vertices, color, tess):\n \"\"\"\n Draws a triangle using the turtle graphics.\n\n vertices: List of tuple coordinates for the triangle vertices [(x...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075837", "row_id": 75837, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153893']" }
0.547413
Filter_75837
I
[ "draw_triangle", "mid_point", "sierpinski", "draw_sierpinski_triangle" ]
4
[ [ "draw_sierpinski_triangle", "sierpinski" ], [ "sierpinski", "draw_triangle" ], [ "sierpinski", "mid_point" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3c9fbbf6a2dbbeed3d16959efefc17eab0afea93
8a2b51e50d45aa1bba117b86f541677d15db0193
v1.0
instruct
Filter
Filter_75887_I
Hello, I need help with a specific coding problem. I'm trying to write a program in Python that can convert temperatures between Celsius and Fahrenheit. I want the user to be able to input a temperature and then choose which conversion they want to perform. How can I implement this?
def celsius_to_fahrenheit(celsius): """ Convert Celsius to Fahrenheit. """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Convert Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5/9 def convert_temperature(value, conversion_type): """ Convert the t...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Convert Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Convert Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(f...
[ 1, 1, 0 ]
2
easy
0.667
{ "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 Formula: (Celsius * 9/5) + 32\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsiu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00075887", "row_id": 75887, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_153999']" }
0.415204
Filter_75887
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7ef69647d446aaf847f57084636ed7fc8d1af712
f5d7ba66559ea10b50af0d29bb284d05c656f1cb
v1.0
instruct
Filter
Filter_75925_I
Write a Python function to find the minimum number of steps a knight can take to reach a target position on a chessboard. The chessboard is an 8x8 grid, and the knight moves in an "L" shape: two squares in one direction and then one square perpendicular, or one square in one direction and then two squares perpendicular...
from collections import deque def is_within_bounds(x, y): """Check if the coordinates are within the chessboard limits.""" return 0 <= x < 8 and 0 <= y < 8 def min_knight_moves(start, target): """ Returns the minimum number of steps a knight can take to reach the target position on an 8x8 chessboard. ...
from solution import min_knight_moves def test_min_knight_moves_same_position(): assert min_knight_moves((0, 0), (0, 0)) == 0 def test_min_knight_moves_one_move_away(): assert min_knight_moves((0, 0), (2, 1)) == 1 assert min_knight_moves((0, 0), (1, 2)) == 1 def test_min_knight_moves_general_cases(): ...
[ { "docstring": "Check if the coordinates are within the chessboard limits.", "function_declaration": "def is_within_bounds(x, y):", "function_name": "is_within_bounds", "parameter_list": "(x, y)" }, { "docstring": "Returns the minimum number of steps a knight can take to reach the target pos...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_within_bounds(x, y):\n \"\"\"Check if the coordinates are within the chessboard limits.\"\"\"\n return 0 <= x < 8 and 0 <= y < 8\n\ndef min_knight...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00075925", "row_id": 75925, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154076']" }
0.648272
Filter_75925
I
[ "is_within_bounds", "min_knight_moves" ]
2
[ [ "min_knight_moves", "is_within_bounds" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e72452a0c1c247e6bf68a44a79c6a2f823f5a74a
5a24e262fec376546e2deb4bec830b1bdadac367
v1.0
instruct
Filter
Filter_75931_I
Can you provide a Python implementation of the k-means clustering algorithm from scratch without using any external libraries like NumPy or SciPy?
import random def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points. """ return sum((x - y) ** 2 for x, y in zip(point1, point2)) ** 0.5 def initialize_centroids(data, k): """ Randomly initialize k centroids from the data points. """ return ran...
from solution import kmeans, euclidean_distance, initialize_centroids, assign_clusters, calculate_new_centroids def test_euclidean_distance(): assert euclidean_distance([0, 0], [3, 4]) == 5.0 assert euclidean_distance([1, 2], [4, 6]) == 5.0 assert euclidean_distance([1, 1], [1, 1]) == 0.0 def test_initial...
[ { "docstring": "Calculate the Euclidean distance between two points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Randomly initialize k centroids from the data points.", ...
[ 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 math\n\ndef euclidean_distance(point1, point2):\n return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2)))\n\ndef initialize_centroids(points, k):\n retu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075931", "row_id": 75931, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154084']" }
0.579805
Filter_75931
I
[ "euclidean_distance", "initialize_centroids", "assign_clusters", "calculate_new_centroids", "kmeans" ]
5
[ [ "assign_clusters", "euclidean_distance" ], [ "kmeans", "assign_clusters" ], [ "kmeans", "calculate_new_centroids" ], [ "kmeans", "initialize_centroids" ] ]
4
[]
false
[]
false
pytest
true
[]
true
f23405fb8013832056e85fc5d2a432253d3d1d26
d9d7b9c48d5d244564ae9668d2dc1b15451f61e1
v1.0
instruct
Filter
Filter_75934_I
Given a positive integer `n`, write a Python function that returns the next palindrome number greater than `n`. A palindrome number is a number that remains the same when its digits are reversed.
def is_palindrome(num): """ Returns True if num is a palindrome, False otherwise. """ return str(num) == str(num)[::-1] def next_palindrome(n): """ Returns the next palindrome number greater than n. """ n += 1 while not is_palindrome(n): n += 1 return n
from solution import next_palindrome def test_next_palindrome_single_digit(): assert next_palindrome(1) == 2 assert next_palindrome(8) == 9 def test_next_palindrome_double_digits(): assert next_palindrome(10) == 11 assert next_palindrome(12) == 22 def test_next_palindrome_triple_digits(): assert ...
[ { "docstring": "Returns True if num is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the next palindrome number greater than n.", "function_declaration": "def next...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def next_palindrome(n):\n \"\"\"\n Given a positive integer n, return the next palindrome number greater than n.\n \"\"\"\n def is_palindrome(x):\n return str(x) == str(x)[:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00075934", "row_id": 75934, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154088']" }
0.759618
Filter_75934
I
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1821033271ad04680314e983d6397388e8ded0e
6789065757875c4a549c5308bd3b5ab4bac77db6
v1.0
instruct
Filter
Filter_76016_I
Hello! I'm working on a project using PyTorch, and I need to create tensors with a specific random seed for reproducibility. How can I set a random seed in PyTorch to ensure that the random tensors I generate are reproducible?
import torch def set_seed(seed): """ Sets the random seed in PyTorch for reproducibility. Args: seed (int): The seed value to set for the random number generator. """ torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed(seed) torch.cuda.manual_se...
from solution import set_seed, generate_random_tensor def test_set_seed_reproducibility_cpu(): set_seed(42) tensor1 = torch.rand((3, 3)) set_seed(42) tensor2 = torch.rand((3, 3)) assert torch.equal(tensor1, tensor2), "Tensors should be equal for the same seed on CPU" def test_generate_random_tenso...
[ { "docstring": "Sets the random seed in PyTorch for reproducibility.\n\nArgs:\nseed (int): The seed value to set for the random number generator.", "function_declaration": "def set_seed(seed):", "function_name": "set_seed", "parameter_list": "(seed)" }, { "docstring": "Generates a random ten...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\n\ndef set_seed(seed):\n \"\"\"\n Sets the random seed for PyTorch to ensure reproducibility.\n \n Parameters:\n seed (int): The seed value to set.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076016", "row_id": 76016, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154241']" }
0.422584
Filter_76016
I
[ "set_seed", "generate_random_tensor" ]
2
[ [ "generate_random_tensor", "set_seed" ] ]
1
[]
false
[]
false
pytest
true
[ "torch" ]
false
efbda454e8951d61b29187385bad0d39b7f6a260
67e1f464f1b9bd02075a0f9371ffad7e59975577
v1.0
instruct
Filter
Filter_76062_I
Design a Python script that implements a simple encryption and decryption system using the Caesar cipher technique. The Caesar cipher technique is a substitution cipher where each letter in the plaintext is shifted a certain number of places down the alphabet. For example, with a shift of 1, 'A' would be replaced by 'B...
def caesar_encrypt(plaintext, shift): """ Encrypts the plaintext using the Caesar cipher technique. Parameters: - plaintext (str): The text to encrypt. - shift (int): The number of places to shift each letter. Returns: - str: The encrypted text. """ encrypted_text = "" ...
from solution import caesar_encrypt, caesar_decrypt def test_caesar_encrypt(): assert caesar_encrypt("HELLO", 3) == "KHOOR" assert caesar_encrypt("hello", 3) == "khoor" assert caesar_encrypt("HELLO, World!", 3) == "KHOOR, Zruog!" def test_caesar_decrypt(): assert caesar_decrypt("KHOOR", 3) == "HELLO" ...
[ { "docstring": "Encrypts the plaintext using the Caesar cipher technique.\n\nParameters:\n- plaintext (str): The text to encrypt.\n- shift (int): The number of places to shift each letter.\n\nReturns:\n- str: The encrypted text.", "function_declaration": "def caesar_encrypt(plaintext, shift):", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encrypt_caesar_cipher(text, shift):\n \"\"\"\n Encrypt the given text using Caesar cipher with specified shift.\n \n :param text: String, the text to be encrypted.\n :param ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076062", "row_id": 76062, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154335']" }
0.674688
Filter_76062
I
[ "caesar_encrypt", "caesar_decrypt" ]
2
[ [ "caesar_decrypt", "caesar_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b3556ab482dc0bcdabd01e5180934f54db13d2a
d034009ddd401d5878a2d0841310cd7f57641146
v1.0
instruct
Filter
Filter_76082_I
What is the process of creating a neural network from scratch without using any pre-built libraries?
import numpy as np def sigmoid(x): """ Sigmoid activation function. """ return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): """ Derivative of the sigmoid function. """ return x * (1 - x) def initialize_weights(input_size, hidden_size, output_size): """ Initialize the weight...
import numpy as np from solution import sigmoid, sigmoid_derivative, initialize_weights, feedforward, backpropagate, train, predict def test_sigmoid(): assert sigmoid(0) == 0.5 assert np.allclose(sigmoid(np.array([-1, 0, 1])), [0.26894142, 0.5, 0.73105858]) def test_sigmoid_derivative(): assert sigmoid_de...
[ { "docstring": "Sigmoid activation function.", "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": "Derivative of the sigmoid function.", "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_deriv...
[ 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 sigmoid(z):\n return 1 / (1 + np.exp(-z))\n\ndef sigmoid_derivative(z):\n return sigmoid(z) * (1 - sigmoid(z))\n\ndef initialize_parameters(input_size, hidden_s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076082", "row_id": 76082, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154380']" }
0.199095
Filter_76082
I
[ "sigmoid", "sigmoid_derivative", "initialize_weights", "feedforward", "backpropagate", "train", "predict" ]
7
[ [ "backpropagate", "sigmoid_derivative" ], [ "feedforward", "sigmoid" ], [ "predict", "feedforward" ], [ "train", "backpropagate" ], [ "train", "feedforward" ], [ "train", "initialize_weights" ] ]
6
[]
false
[]
false
pytest
true
[ "numpy" ]
false
4a48133067b883d6b25446529e494d72ab0dd639
a5e56b4056845d882477abadc0d4199460ec099a
v1.0
instruct
Filter
Filter_76095_I
Write a Python script to find the sum of all prime numbers within a given range. The script should prompt the user to input a starting and an ending number for the range, and then calculate and display the sum of all prime numbers within that range, inclusive.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_of_primes...
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 assert is_prime(19) == True def test_sum_of_primes_in_range_1_to_10(): asser...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers within the given range [start, end].", "function_declaration": "def su...
[ 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 \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00076095", "row_id": 76095, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154411']" }
0.625199
Filter_76095
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac88eea8d0fd80090760ae5e873995d706c04d87
d3cb34423994d24e3004ff1db620fe3178d93eb1
v1.0
instruct
Filter
Filter_76129_I
Write a Python function to sort an array using the merge sort algorithm. Provide a brief explanation of the merge sort algorithm and how it works.
def merge_sort(arr): """ Sorts an array using the merge sort algorithm. :param arr: List of elements to be sorted :return: Sorted list of elements """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) ...
from solution import merge_sort def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] 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(): ass...
[ { "docstring": "Sorts an array using the merge sort algorithm.\n\n:param arr: List of elements to be sorted\n:return: Sorted list of elements", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_decla...
[ 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 an array using the merge sort algorithm.\n\n Parameters:\n arr (list): List of elements to be sorted.\n\n Returns:\n list: Sorted list.\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076129", "row_id": 76129, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154486']" }
0.674892
Filter_76129
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63ef3fd1f61f91b618f2b514d17661ee671f518f
71cdbb5d456ea7ef51a5d7449742ca094e0ae1e5
v1.0
instruct
Filter
Filter_76202_I
Write a Python program to implement a Caesar cipher encryption and decryption. The program should be able to handle both uppercase and lowercase letters, and leave non-alphabetic characters unchanged.
def caesar_cipher_encrypt(text, shift): """ Encrypts text using a Caesar cipher with the given shift. """ encrypted_text = [] for char in text: if char.isalpha(): shift_base = 'A' if char.isupper() else 'a' encrypted_char = chr((ord(char) - ord(shift_base) + shift) % ...
from solution import caesar_cipher_encrypt, caesar_cipher_decrypt def test_encrypt_all_lowercase(): assert caesar_cipher_encrypt("abcdef", 3) == "defghi" assert caesar_cipher_encrypt("xyz", 3) == "abc" def test_encrypt_all_uppercase(): assert caesar_cipher_encrypt("ABCDEF", 3) == "DEFGHI" assert caesa...
[ { "docstring": "Encrypts text using a Caesar cipher with the given shift.", "function_declaration": "def caesar_cipher_encrypt(text, shift):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(text, shift)" }, { "docstring": "Decrypts text using a Caesar cipher with the given shi...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar Cipher technique with specified shift.\n \"\"\"\n encrypted_text = []\n for char in text:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076202", "row_id": 76202, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154622']" }
0.680028
Filter_76202
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt" ]
2
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a511bb771af167ce3b56723aba8f4748252cdec
57a2534fa69bdfb10c3143175d546891a93a4bb9
v1.0
instruct
Filter
Filter_76257_I
How can I implement a text substitution cipher in Python?
def create_cipher_dict(key): """ Creates a cipher dictionary for substitution based on the provided key. """ alphabet = 'abcdefghijklmnopqrstuvwxyz' cipher_dict = {} for a, k in zip(alphabet, key): cipher_dict[a] = k return cipher_dict def encrypt(plaintext, key): """ Encryp...
from solution import encrypt, decrypt def test_encrypt_simple(): key = 'zyxwvutsrqponmlkjihgfedcba' plaintext = 'hello' assert encrypt(plaintext, key) == 'svool' def test_decrypt_simple(): key = 'zyxwvutsrqponmlkjihgfedcba' ciphertext = 'svool' assert decrypt(ciphertext, key) == 'hello' d...
[ { "docstring": "Creates a cipher dictionary for substitution based on the provided key.", "function_declaration": "def create_cipher_dict(key):", "function_name": "create_cipher_dict", "parameter_list": "(key)" }, { "docstring": "Encrypts the plaintext using the substitution cipher with the ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def substitution_cipher(text, key):\n \"\"\"\n Encrypts the given text using a substitution cipher with the provided key.\n\n Parameters:\n text (str): The input text to encrypt.\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076257", "row_id": 76257, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154725']" }
0.629789
Filter_76257
I
[ "create_cipher_dict", "encrypt", "decrypt" ]
3
[ [ "decrypt", "create_cipher_dict" ], [ "encrypt", "create_cipher_dict" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3dc700997a43a3c94bdc37b0010e6938886877c9
1b20a84d6442fb963cdb9a326f734be8e6c23869
v1.0
instruct
Filter
Filter_76309_I
Can you provide a Python script to add a new user to a Linux system via the command line? This script should check if the user already exists and prompt for confirmation if the user is to be added. It should also add the user to a specific group.
import subprocess import sys def user_exists(username): """ Checks if a user already exists in the system. """ try: subprocess.run(['id', username], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return True except subprocess.CalledProcessError: return False de...
from unittest.mock import patch import subprocess import pytest from solution import add_user, user_exists def test_user_exists(): # Note: You cannot create a user for testing here, so we mock the calls. with patch('subprocess.run') as mock_run: # Simulate user exists mock_run.return_value = su...
[ { "docstring": "Checks if a user already exists in the system.", "function_declaration": "def user_exists(username):", "function_name": "user_exists", "parameter_list": "(username)" }, { "docstring": "Adds a new user to the system and assigns the user to a specific group.", "function_dec...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import subprocess\nimport sys\n\ndef user_exists(username):\n \"\"\"\n Checks if a user already exists in the system.\n \"\"\"\n try:\n subprocess.run(['id', username], chec...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00076309", "row_id": 76309, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154825']" }
0.313412
Filter_76309
I
[ "user_exists", "add_user" ]
2
[ [ "add_user", "user_exists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c725cc0e9d005753be3620e68858ab155128a005
0045bd7045d9de76019d21aff6f71d5c434e267e
v1.0
instruct
Filter
Filter_76396_I
I want to use Python to create a script that reads a CSV file and extracts specific data. The CSV file contains information about employees, including their names, departments, and positions. How can I accomplish this task?
import csv def read_csv(file_path): """ Read a CSV file and return its contents as a list of dictionaries. Each dictionary represents a row with column names as keys. """ data = [] with open(file_path, mode='r', newline='') as file: reader = csv.DictReader(file) for row in reade...
from solution import read_csv, extract_employee_data def test_read_csv(tmp_path): # Create a temporary CSV file csv_content = "Name,Department,Position\nJohn Doe,HR,Manager\nJane Smith,IT,Developer" csv_file = tmp_path / "employees.csv" with open(csv_file, 'w', newline='') as file: file.write(c...
[ { "docstring": "Read a CSV file and return its contents as a list of dictionaries.\nEach dictionary represents a row with column names as keys.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Extract specif...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef read_csv_and_extract_data(file_path, department=None, position=None):\n \"\"\"\n Reads a CSV file and extracts data based on specified department and/or position.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076396", "row_id": 76396, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_154997']" }
0.57312
Filter_76396
I
[ "read_csv", "extract_employee_data" ]
2
[ [ "extract_employee_data", "read_csv" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac9ccf277b8c8353ff04f7e8b2047816553ced8e
8c5f16311dbf161b027f50f47b7002b5d59fd65b
v1.0
instruct
Filter
Filter_76399_I
Can you explain how the Divide and Conquer algorithm works and provide an example of its implementation in Python?
def merge_sort(arr): """ Sorts an array using the Merge Sort algorithm. """ if len(arr) <= 1: return arr # Divide mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] # Conquer left_sorted = merge_sort(left_half) right_sorted = merge_sort(right_half) ...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert...
[ { "docstring": "Sorts an array using the Merge Sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into a single sorted list.", "function_declaration": "def merge(left, right...
[ 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 Implements the merge sort algorithm using divide and conquer.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n # Divide the array into two ha...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076399", "row_id": 76399, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155002']" }
0.49367
Filter_76399
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bab864d1e0342fbcc98b1ffce4cf0e439d93f69b
b8b65faaaf6884e4e3aac75c30ffb2a57e6c50cd
v1.0
instruct
Filter
Filter_76445_I
Can you provide a detailed explanation of how to implement a genetic algorithm for optimizing a mathematical function, such as the sphere function, in Python? Implementing a genetic algorithm involves several key steps, including defining the genes, creating an initial population, evaluating fitness, selecting parents,...
import random # Sphere function definition def sphere_function(solution): return sum(x**2 for x in solution) # Create an initial population def create_initial_population(pop_size, gene_length): return [[random.uniform(-10, 10) for _ in range(gene_length)] for _ in range(pop_size)] # Evaluate the fitness of t...
import pytest from solution import ( sphere_function, create_initial_population, evaluate_fitness, tournament_selection, crossover, mutate, genetic_algorithm, ) def test_sphere_function(): assert sphere_function([0, 0, 0]) == 0 assert sphere_function([1, 1, 1]) == 3 assert spher...
[ { "docstring": null, "function_declaration": "def sphere_function(solution):", "function_name": "sphere_function", "parameter_list": "(solution)" }, { "docstring": null, "function_declaration": "def create_initial_population(pop_size, gene_length):", "function_name": "create_initial_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\n# Sphere function definition\ndef sphere_function(solution):\n return sum(x**2 for x in solution)\n\n# Create an initial population\ndef create_initial_population(pop_size,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00076445", "row_id": 76445, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155093']" }
0.363843
Filter_76445
I
[ "sphere_function", "create_initial_population", "evaluate_fitness", "tournament_selection", "crossover", "mutate", "genetic_algorithm" ]
7
[ [ "evaluate_fitness", "sphere_function" ], [ "genetic_algorithm", "create_initial_population" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "evaluate_fitness" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "tournamen...
6
[]
false
[]
false
pytest
true
[]
true
7286ec4fb32280cafb85f2f685eea8d9a6ea2e63
664d591ce5a66472f212520ad02c5e88760da9fb
v1.0
instruct
Filter
Filter_76477_I
Write a Python function that takes an integer as input and returns the next prime number greater than the given integer. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
def is_prime(n): """ Determine whether a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import next_prime, is_prime def test_next_prime(): assert next_prime(3) == 5 assert next_prime(8) == 11 assert next_prime(11) == 13 assert next_prime(14) == 17 assert next_prime(29) == 31 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is...
[ { "docstring": "Determine whether a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the next prime number greater than the given integer n.", "function_declaration": "def next_prime(n):", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determine whether 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:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00076477", "row_id": 76477, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155161']" }
0.710602
Filter_76477
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b97184690f87d1878b7cfd8fd67101c86c71277
385dd9b1f37d6659c7700c94417b1a1e604ec9ac
v1.0
instruct
Filter
Filter_76500_I
Given a string `s` and a list of strings `d`, write a function `findLongestWord` that returns the longest word in the list `d` that is a subsequence of the string `s`. In case there are multiple such words, return the one that is lexicographically smallest. If no such word exists, return an empty string.
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def findLongestWord(s, d): """ Returns the longest word in list d that is a subsequence of string s. If there are multiple such words, return the one that is lexicographically smallest. """ candidates = [word ...
from solution import findLongestWord def test_no_subsequence(): s = "apple" d = ["z", "y", "x"] assert findLongestWord(s, d) == "" def test_single_subsequence(): s = "apple" d = ["a", "b", "c"] assert findLongestWord(s, d) == "a" def test_multiple_subsequences_different_lengths(): s = "ab...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Returns the longest word in list d that is a subsequence of string s.\nIf there are multiple such words, return the one that is lex...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\ndef findLongestWord(s, d):\n d.sort(key=lambda x: (-len(x), x))\n for word in d:\n if is_subsequ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076500", "row_id": 76500, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155223']" }
0.696858
Filter_76500
I
[ "is_subsequence", "findLongestWord" ]
2
[ [ "findLongestWord", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c95a39b9f833b8e36b8f1aab33944b834750197a
f8cc9c43f5c75f1c78a0ad1ea28dabc568ef218f
v1.0
instruct
Filter
Filter_76507_I
Could you provide a Python code snippet to convert a list of nested dictionaries to a flat list of tuples? Each tuple should represent a path-value pair, where the path is a string representing the keys leading to the value in the nested dictionary structure.
def flatten_dict(d, parent_key=''): """ Flattens a nested dictionary into a list of (path, value) tuples. Args: d (dict): The dictionary to flatten. parent_key (str): Parent key string for nested keys (used in recursion). Returns: List[tuple]: List of tuples where each tuple is (path, ...
from solution import flatten_list_of_dicts def test_flatten_single_dict(): input_data = [{'a': {'b': 1, 'c': {'d': 3}}}] expected_output = [('a.b', 1), ('a.c.d', 3)] assert flatten_list_of_dicts(input_data) == expected_output def test_flatten_multiple_dicts(): input_data = [{'a': {'b': 1, 'c': 2}}, {'...
[ { "docstring": "Flattens a nested dictionary into a list of (path, value) tuples.\n\nArgs:\nd (dict): The dictionary to flatten.\nparent_key (str): Parent key string for nested keys (used in recursion).\n\nReturns:\nList[tuple]: List of tuples where each tuple is (path, value).", "function_declaration": "de...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def flatten_dict(d, parent_key='', sep='.'):\n \"\"\"\n Flattens a nested dictionary into a list of tuples representing path-value pairs.\n \n :param d: Dictionary to be flattened\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00076507", "row_id": 76507, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155233']" }
0.623574
Filter_76507
I
[ "flatten_dict", "flatten_list_of_dicts" ]
2
[ [ "flatten_list_of_dicts", "flatten_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab4f1549262e2e20a121c4a80c57bcceb178e54d
374f90005ff6da435576f4c5844a44a8ac6baa19
v1.0
instruct
Filter
Filter_76532_I
Can you help me with a Python solution for Project Euler Problem 35, which involves finding circular primes below a given limit?
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, get_rotations, is_circular_prime, count_circular_primes_below 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_get_rotations(): assert get_rota...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a set of all rotations of the digits of n.", "function_declaration": "def get_rotations(n):"...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00076532", "row_id": 76532, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155287']" }
0.533968
Filter_76532
I
[ "is_prime", "get_rotations", "is_circular_prime", "count_circular_primes_below" ]
4
[ [ "count_circular_primes_below", "is_circular_prime" ], [ "is_circular_prime", "get_rotations" ], [ "is_circular_prime", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cde89ac91c3c40ddff571cb763015c308f36ea77
c975edbd28570f2d4715bb091c82569655a05a0d
v1.0
instruct
Filter
Filter_76543_I
Can you assist with creating a Python script for a simple dice game? The game should allow a user to roll a six-sided die and aim to reach or exceed a target score. The user can roll the die as many times as they want until they either reach or exceed the target score or choose to stop rolling. The script should keep t...
import random def roll_die(): """Simulate rolling a six-sided die and return the result.""" return random.randint(1, 6) def play_game(target_score): """ Play the dice game where the user aims to reach or exceed the target score. target_score: int - The target score the user needs to reach or ...
from unittest.mock import patch from solution import roll_die, play_game def test_roll_die(): with patch('random.randint', return_value=4): assert roll_die() == 4 def test_play_game_reach_target(): inputs = iter(['y', 'y', 'n']) with patch('builtins.input', lambda _: next(inputs)): with pa...
[ { "docstring": "Simulate rolling a six-sided die and return the result.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Play the dice game where the user aims to reach or exceed the target score.\n\ntarget_score: int - The t...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die.\n Returns a random integer between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_gam...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00076543", "row_id": 76543, "seed_ids": "['Qwen2.5-Coder-32B-Instruct_155307']" }
0.53473
Filter_76543
I
[ "roll_die", "play_game" ]
2
[ [ "play_game", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc88963738d79c88541b522240dd9a50a28a8465
9104918fb8dd97c2645cf3d97c119807f9774dde