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_39592_I
Given strings a and b, implement a function to check if b is a rotation of a using only one call to the is Substring method.
def is_rotation(a, b): """ Check if string b is a rotation of string a. """ if len(a) != len(b): return False return is_substring(a + a, b) def is_substring(string, sub): """ Check if sub is a substring of string. """ return sub in string
from solution import is_rotation def test_is_rotation_true_cases(): assert is_rotation("waterbottle", "erbottlewat") == True assert is_rotation("abcd", "cdab") == True def test_is_rotation_false_cases(): assert is_rotation("apple", "ppale") == False assert is_rotation("abcd", "abdc") == False def tes...
[ { "docstring": "Check if string b is a rotation of string a.", "function_declaration": "def is_rotation(a, b):", "function_name": "is_rotation", "parameter_list": "(a, b)" }, { "docstring": "Check if sub is a substring of string.", "function_declaration": "def is_substring(string, sub):"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_rotation(a, b):\n \"\"\"\n Checks if string b is a rotation of string a.\n \n :param a: Original string\n :param b: String to check if it is a rotation of a\n :return:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039592", "row_id": 39592, "seed_ids": "['Qwen2-72B-Instruct_86815']" }
0.700952
Filter_39592
I
[ "is_rotation", "is_substring" ]
2
[ [ "is_rotation", "is_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c3adea67893132e84623f0f86398397d3d4638e2
c50f5d3959a87f9822c782540993ada1f21cf7b9
v1.0
instruct
Filter
Filter_39600_I
Write a code to find the first 3 prime numbers that are also present in the list of 15 numbers provided. The list includes: 10, 3, 5, 6, 9, 2, 11, 15, 17, 19, 4, 8, 21, 23, 20. Optimize your code for performance.
def is_prime(n): """ Determines if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def find_first_three_p...
from solution import is_prime, find_first_three_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(15) == False assert is_prime(23) == True def test_find_first_three_primes(): numbers = [...
[ { "docstring": "Determines if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds the first 3 prime numbers in the given list of numbers.", "function_declaration": "def find_first_three_pr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if the number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039600", "row_id": 39600, "seed_ids": "['Qwen2-72B-Instruct_86833']" }
0.594129
Filter_39600
I
[ "is_prime", "find_first_three_primes" ]
2
[ [ "find_first_three_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a007c5b1442b81bb1531a1037762accf4fe701ee
b532c2816e2e524b58c74ee6291fafc266f155bd
v1.0
instruct
Filter
Filter_39604_I
Use a daisy-chain approach to create this code and add comments to explain your thought process and how you arrived at the final solution. Your solution should implement a custom reduce function instead of using the built-in reduce function in Python. You are not allowed to use any external libraries or built-in functi...
def custom_reduce(function, iterable, initializer=None): """ Apply a function of two arguments cumulatively to the items of a sequence, from left to right, to reduce the sequence to a single value. If `initializer` is provided, it is placed before the items of the sequence in the calculation, and se...
from solution import custom_reduce, flatten, calculate_average def test_custom_reduce(): assert custom_reduce(lambda x, y: x + y, [1, 2, 3, 4]) == 10 assert custom_reduce(lambda x, y: x * y, [1, 2, 3, 4]) == 24 assert custom_reduce(lambda x, y: min(x, y), [4, 2, 3, 1]) == 1 def test_flatten(): assert ...
[ { "docstring": "Apply a function of two arguments cumulatively to the items of a sequence,\nfrom left to right, to reduce the sequence to a single value. If `initializer`\nis provided, it is placed before the items of the sequence in the calculation,\nand serves as a default when the sequence is empty.", "f...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Custom reduce function that can handle nested lists\ndef custom_reduce(function, iterable, initializer=None):\n iterator = iter(iterable)\n if initializer is None:\n # Start wit...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039604", "row_id": 39604, "seed_ids": "['Qwen2-72B-Instruct_86843']" }
0.623021
Filter_39604
I
[ "custom_reduce", "flatten", "calculate_average" ]
3
[ [ "calculate_average", "custom_reduce" ], [ "calculate_average", "flatten" ] ]
2
[]
false
[]
false
pytest
true
[]
true
58c2ffd48d87ce5cf58c38b8cefd3657751aabcb
3384a54b93e362a7d301389b7cc83411afaff733
v1.0
instruct
Filter
Filter_39634_I
Implement Dijkstra's algorithm to find the shortest path between two nodes in a weighted graph represented by an adjacency matrix. However, the graph is guaranteed to be a complete graph (every pair of distinct vertices is connected by a unique edge) and the weight of each edge is the Euclidean distance between the two...
import math import heapq def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points in 2D space. """ return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def build_adjacency_matrix(points): """ Build adjacency matrix using Euclidean...
from solution import build_adjacency_matrix, dijkstra def test_euclidean_distance(): assert round(euclidean_distance([0, 0], [0, 1]), 2) == 1.00 assert round(euclidean_distance([0, 0], [1, 0]), 2) == 1.00 assert round(euclidean_distance([0, 0], [1, 1]), 2) == 1.41 assert round(euclidean_distance([1, 1]...
[ { "docstring": "Calculate the Euclidean distance between two points in 2D space.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Build adjacency matrix using Euclidean distance...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport heapq\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points in 2D space.\n \"\"\"\n return math.sqrt((point1...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039634", "row_id": 39634, "seed_ids": "['Qwen2-72B-Instruct_86908']" }
0.567011
Filter_39634
I
[ "euclidean_distance", "build_adjacency_matrix", "dijkstra" ]
3
[ [ "build_adjacency_matrix", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94a8ec13560d35d70fec49e57bd19d1ab9f1e4d7
4ce94e0a54ff504606fd7dbd482f2ec0b26b6d4a
v1.0
instruct
Filter
Filter_39641_I
How to calculate train loss and validation loss after every epoch using PyTorch for model training in a binary classification? Your explanation should include the appropriate code, detailed steps, and also account for a scenario where the train and validation data are not of equal size.
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset # Sample Binary Classification Model class BinaryClassificationModel(nn.Module): def __init__(self): super(BinaryClassificationModel, self).__init__() self.linear = nn.Linear(10, 1)...
import pytest import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset from solution import BinaryClassificationModel, compute_loss, train_model def test_loss_computation(): device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') m...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import DataLoader, TensorDataset\n\n# Sample Binary Classification Model\nclass BinaryClassificationMode...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039641", "row_id": 39641, "seed_ids": "['Qwen2-72B-Instruct_86920']" }
0.462343
Filter_39641
I
[ "compute_loss", "train_model" ]
2
[ [ "train_model", "compute_loss" ] ]
1
[]
false
[ "BinaryClassificationModel" ]
true
pytest
true
[ "torch" ]
false
617bcff677d30012a8865d33ae64c430bb4446e0
01211ab283956a106f4998d32503d0e4700e7540
v1.0
instruct
Filter
Filter_39648_I
Transform a randomly sorted list into Heap form using the construction method, after this, implement the heap sort algorithm to sort the list in ascending order. The expected output should be a sorted list, however ensuring that the heap properties are maintained throughout the sorting process.
def heapify(arr, n, i): """ Helper function to maintain the heap property of a subtree rooted at node i. Given n is the size of the heap. """ largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] > arr[largest]: largest = left if right < n and...
from solution import heap_sort def test_empty_list(): assert heap_sort([]) == [] def test_single_element(): assert heap_sort([1]) == [1] def test_sorted_list(): assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_list(): assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] ...
[ { "docstring": "Helper function to maintain the heap property of a subtree rooted at node i.\nGiven n is the size of the heap.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Function to build a heap from the...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n To maintain max-heap property for an element at index i.\n \"\"\"\n largest = i # Initialize largest as root\n left = 2 * i + 1 # left = 2*i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039648", "row_id": 39648, "seed_ids": "['Qwen2-72B-Instruct_86930']" }
0.67902
Filter_39648
I
[ "heapify", "build_heap", "heap_sort" ]
3
[ [ "build_heap", "heapify" ], [ "heap_sort", "build_heap" ], [ "heap_sort", "heapify" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b8ae32224efcfdfed94b66f914c50b0fe7a4d180
01eddfce8864fd9478205d447a8a0331623a8f4d
v1.0
instruct
Filter
Filter_39674_I
Write a Python list comprehension for generating a list of all odd numbers between 1 and 50. Additionally, write a function that uses this list to return the sum of these odd numbers. You need to also write a conditional statement that validates if the sum falls within a pre-determined range.
# Generate a list of all odd numbers between 1 and 50 odd_numbers = [num for num in range(1, 51) if num % 2 != 0] def sum_of_odd_numbers(): """ Returns the sum of all odd numbers between 1 and 50. """ return sum(odd_numbers) def is_sum_within_range(lower_bound, upper_bound): """ Validates if t...
from solution import odd_numbers, sum_of_odd_numbers, is_sum_within_range def test_odd_numbers_list(): expected_odd_numbers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49] assert odd_numbers == expected_odd_numbers def test_sum_of_...
[ { "docstring": "Returns the sum of all odd numbers between 1 and 50.", "function_declaration": "def sum_of_odd_numbers():", "function_name": "sum_of_odd_numbers", "parameter_list": "()" }, { "docstring": "Validates if the sum of all odd numbers between 1 and 50 falls within the specified ran...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_odd_numbers():\n \"\"\"\n Generate a list of all odd numbers between 1 and 50.\n \"\"\"\n return [num for num in range(1, 51) if num % 2 != 0]\n\ndef sum_odd_numbers(o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039674", "row_id": 39674, "seed_ids": "['Qwen2-72B-Instruct_86978']" }
0.7142
Filter_39674
I
[ "sum_of_odd_numbers", "is_sum_within_range" ]
2
[ [ "is_sum_within_range", "sum_of_odd_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
659c8e61e9af38f6eff2486f22183a4e39a20814
927ee9dba0c1504c075862268dab490f60709f32
v1.0
instruct
Filter
Filter_39686_I
In a programming language that supports functional paradigm, write a recursive function that finds the product of all prime numbers less than or equal to N. Additionally, write a driver function that accepts an argument for N, validates it to ensure it's a positive integer, then calls your recursive function. Handle po...
def is_prime(num): """Check if the number is prime.""" if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def product_of_primes(n, current...
from solution import is_prime, product_of_primes, driver def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(-1) == False assert is_prime(0) == False assert is_prime(1) == False def test_product_...
[ { "docstring": "Check if the number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Recursively compute the product of all prime numbers less than or equal to n.", "function_declaration": "def product_of_...
[ 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(num):\n \"\"\"Check if the number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039686", "row_id": 39686, "seed_ids": "['Qwen2-72B-Instruct_87000']" }
0.574267
Filter_39686
I
[ "is_prime", "product_of_primes", "driver" ]
3
[ [ "driver", "product_of_primes" ], [ "product_of_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a42c56641230f91924344b80a743af9de0881237
08730d0db3e1f2dd7b86f64b86875620896d5bc7
v1.0
instruct
Filter
Filter_39716_I
Create a Python-Flask application for monitoring a web server's disk usage. The app should have an endpoint for querying the server's current disk usage information and display it in a readable format.
from flask import Flask, jsonify import os import shutil app = Flask(__name__) def get_disk_usage(): total, used, free = shutil.disk_usage("/") return { "total": total, "used": used, "free": free } @app.route("/disk-usage", methods=["GET"]) def disk_usage(): disk_usage_info = ...
import pytest from flask import Flask from flask.testing import FlaskClient import os from solution import app, get_disk_usage @pytest.fixture def client(): app.config["TESTING"] = True with app.test_client() as client: with app.app_context(): yield client def test_get_disk_usage(): d...
[ { "docstring": null, "function_declaration": "def get_disk_usage():", "function_name": "get_disk_usage", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def disk_usage():", "function_name": "disk_usage", "parameter_list": "()" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, jsonify\nimport shutil\n\napp = Flask(__name__)\n\n@app.route('/disk-usage', methods=['GET'])\ndef get_disk_usage():\n total, used, free = shutil.disk_usage(\"/\")\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039716", "row_id": 39716, "seed_ids": "['Qwen2-72B-Instruct_87052']" }
0.450153
Filter_39716
I
[ "get_disk_usage", "disk_usage" ]
2
[ [ "disk_usage", "get_disk_usage" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
a3b036776f84f8c048951a00e0ddc3853b2368af
bc3e1d5bfdfe447878ee387804d2b031e010ce91
v1.0
instruct
Filter
Filter_39722_I
Write a script in Python for drawing a detailed star with intricate geometrical patterns on the sides using the turtle graphics module. Further, add an animation effect such that the star appears to be revolving or spinning.
import turtle import math def draw_star(x, y, size, color): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.color(color) angle = 144 for _ in range(5): turtle.forward(size) turtle.right(angle) turtle.forward(size) turtle.right(72 - angle) def draw_patte...
def test_draw_star(): # Verifying if 'draw_star' function exists assert callable(draw_star) def test_draw_patterned_star(): # Verifying if 'draw_patterned_star' function exists assert callable(draw_patterned_star) def test_animate_star(): # Verifying if 'animate_star' function exists a...
[ { "docstring": null, "function_declaration": "def draw_star(x, y, size, color):", "function_name": "draw_star", "parameter_list": "(x, y, size, color)" }, { "docstring": null, "function_declaration": "def draw_patterned_star(x, y, size, color):", "function_name": "draw_patterned_star...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import turtle\nimport math\n\ndef draw_star(turtle_obj, size, sides):\n # Function to draw star with intricate geometrical patterns on the sides.\n for _ in range(sides):\n turtle...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039722", "row_id": 39722, "seed_ids": "['Qwen2-72B-Instruct_87066']" }
0.457281
Filter_39722
I
[ "draw_star", "draw_patterned_star", "animate_star" ]
3
[ [ "animate_star", "draw_patterned_star" ], [ "draw_patterned_star", "draw_star" ] ]
2
[]
false
[]
false
pytest
false
[]
true
bd1f3ad41a77b9e349525472fee204dd8449d661
26cafbe614efef8176af70b0a483980b2b308d0d
v1.0
instruct
Filter
Filter_39752_I
Develop a Python function that retrains the existing machine learning model using an augmented dataset. The function should dynamically adjust the model's parameters based on the new data added. The function should also perform pre-processing tasks like feature extraction, data cleaning, handling missing data values, a...
import pandas as pd from sklearn.preprocessing import StandardScaler from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import classification_report import sqlite3 import pickle def preprocess_data(data): """ Perform pre-processing task...
import pandas as pd import sqlite3 import os from sklearn.datasets import load_iris from sklearn.ensemble import RandomForestClassifier import pickle from solution import preprocess_data, retrain_model def setup_module(module): # Create a sample model and data, save to disk iris = load_iris() X, y = iris.d...
[ { "docstring": "Perform pre-processing tasks like data cleaning, handling missing values, and normalization.", "function_declaration": "def preprocess_data(data):", "function_name": "preprocess_data", "parameter_list": "(data)" }, { "docstring": "Retrains the existing model using augmented d...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.ensemble imp...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039752", "row_id": 39752, "seed_ids": "['Qwen2-72B-Instruct_87126']" }
0.327809
Filter_39752
I
[ "preprocess_data", "retrain_model" ]
2
[ [ "retrain_model", "preprocess_data" ] ]
1
[]
false
[]
false
pytest
true
[ "pandas", "sklearn" ]
false
1a3b62559056d044df5357066702978823e7290f
5f002a6e436c75c0c3b4bbd8436ea8cbcb61fd43
v1.0
instruct
Filter
Filter_39754_I
Build a Python function that determines an outcome's category from a reduction theorem perspective, focusing on complex numbers. Given a complex number's magnitude, the function should ascertain whether the magnitude meets the criteria of being part of a specific reduction set. Your task involves broadening the functio...
def in_reduction_set(magnitude): """ Determines if the magnitude is part of the specific reduction set. For this example, let's say the reduction set contains all numbers which are even. """ return magnitude % 2 == 0 def detect_sequences(magnitudes): """ Detects sequences of magnitudes that...
from solution import in_reduction_set, detect_sequences def test_in_reduction_set(): assert in_reduction_set(2) == True assert in_reduction_set(3) == False assert in_reduction_set(10) == True assert in_reduction_set(11) == False def test_detect_sequences_single_sequence(): magnitudes = [2, 4, 6, 8...
[ { "docstring": "Determines if the magnitude is part of the specific reduction set.\nFor this example, let's say the reduction set contains all numbers which are even.", "function_declaration": "def in_reduction_set(magnitude):", "function_name": "in_reduction_set", "parameter_list": "(magnitude)" ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_in_reduction_set(magnitude):\n \"\"\"\n Determines if a given magnitude is part of a specific reduction set.\n Here, let's define the reduction set criteria as magnitudes that ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039754", "row_id": 39754, "seed_ids": "['Qwen2-72B-Instruct_87130']" }
0.412372
Filter_39754
I
[ "in_reduction_set", "detect_sequences" ]
2
[ [ "detect_sequences", "in_reduction_set" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c2770cac6ab856b09734c152b83ff1eb3c697687
2568b03723231d3c6ffe2bad21889ba6a2cbc75e
v1.0
instruct
Filter
Filter_39761_I
Write a Python program to check if a given number is a prime number. The program should also determine if the number is a "Super Prime" number. A "Super Prime" number is a prime number that holds the property of being a prime number when counted from right to left. For example, 317 is a "Super Prime" because both 317 a...
def is_prime(n): """ Check if a given 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, is_super_prime def test_prime_positive_cases(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(17) == True assert is_prime(317) == True def test_prime_negative_cases(): assert is_prime(1) == False assert is_prime(4) == False assert is_p...
[ { "docstring": "Check if a given number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a given number is a super prime number.", "function_declaration": "def is_super_prime(n):", "funct...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a given number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039761", "row_id": 39761, "seed_ids": "['Qwen2-72B-Instruct_87140']" }
0.738235
Filter_39761
I
[ "is_prime", "is_super_prime" ]
2
[ [ "is_super_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e24cb8375a74f3137ed051d92377587fb0fe7760
d3b57bf81f4e990fe0bf204b0d6d3301e66566dc
v1.0
instruct
Filter
Filter_39766_I
Write a script in Python to take an age as an input and return a boolean if the person is a minor or not. Additionally, include a function to validate if the input is a valid integer and falls within the range of 0 to 150. Make sure to handle exceptions where the input is not a numeric value or if it's out of the expec...
def is_valid_age(age): """ Validates if the input age is a valid integer and falls within the range of 0 to 150. """ if not isinstance(age, int): raise ValueError("Age must be an integer.") if age < 0 or age > 150: raise ValueError("Age must be between 0 and 150.") return True d...
from solution import is_valid_age, is_minor def test_is_valid_age(): assert is_valid_age(25) == True assert is_valid_age(0) == True assert is_valid_age(150) == True def test_is_valid_age_exceptions(): try: is_valid_age(-1) except ValueError as e: assert str(e) == "Age must be betwe...
[ { "docstring": "Validates if the input age is a valid integer and falls within the range of 0 to 150.", "function_declaration": "def is_valid_age(age):", "function_name": "is_valid_age", "parameter_list": "(age)" }, { "docstring": "Returns True if the person is a minor (under 18), otherwise ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_minor(age):\n \"\"\"\n Returns True if the person is a minor (age < 18), else False.\n \"\"\"\n return age < 18\n\ndef validate_age(age_input):\n \"\"\"\n Validates if...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039766", "row_id": 39766, "seed_ids": "['Qwen2-72B-Instruct_87145']" }
0.452112
Filter_39766
I
[ "is_valid_age", "is_minor" ]
2
[ [ "is_minor", "is_valid_age" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8618d69fb0aa90ba57a9890bf864f77ef0bb9db9
622c53338119c79beaca96bc7f944bbb8f5bc83b
v1.0
instruct
Filter
Filter_39774_I
Given a set of numbers represented as a binary search tree (BST), write a Python function to find the missing number in the sequence by performing a depth-first search (DFS). The sequence of numbers is continuous, and exactly one number is missing.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def inorder_traversal(root, result): if root: inorder_traversal(root.left, result) result.append(root.val) inorder_traversal(root.right, result) def find_missing_number_bs...
from solution import TreeNode, find_missing_number_bst def test_find_missing_number_in_bst(): # BST structure: # 4 # / \ # 2 6 # / \ / \ # 1 3 5 7 root = TreeNode(4) root.left = TreeNode(2) root.right = TreeNode(6) root.left.left = TreeNode(1) ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef dfs_inorder(node, elements):\n if...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039774", "row_id": 39774, "seed_ids": "['Qwen2-72B-Instruct_87160']" }
0.548463
Filter_39774
I
[ "inorder_traversal", "find_missing_number_bst" ]
2
[ [ "find_missing_number_bst", "inorder_traversal" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f4ae89be7452cf2ed660733f7d8a52b30f237d0d
90d9475b1a12223c320d7307c3215955315a5c68
v1.0
instruct
Filter
Filter_39780_I
Create a Python script that generates two lists of numbers between 1 and 50, one consisting of only prime numbers and the other consisting of Fibonacci numbers. The script should then find the intersection and the union of these two sets without duplicates and output four final lists: Prime numbers not in the Fibonacci...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def generate_primes(limit): """ Generate a list of prime numbers up to a given limit....
import pytest import solution def test_is_prime(): assert not solution.is_prime(1) assert solution.is_prime(2) assert solution.is_prime(3) assert not solution.is_prime(4) assert solution.is_prime(5) assert not solution.is_prime(15) assert solution.is_prime(17) def test_generate_primes(): ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers up to a given limit.", "function_declaration": "def generate_primes(limi...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime.\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": "00039780", "row_id": 39780, "seed_ids": "['Qwen2-72B-Instruct_87172']" }
0.605161
Filter_39780
I
[ "is_prime", "generate_primes", "generate_fibonacci", "find_intersection_and_union" ]
4
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b05386fa2f749c15f15ecb249d6ca21d22b348e6
3fc08421625636b2537644fcb753fff3198a080a
v1.0
instruct
Filter
Filter_39781_I
Formulate a for loop to verify the primality condition for all integers from 1 up to a specified inclusive numerical limit. Additionally, optimize the algorithm for the best possible time complexity. The solution must also account for potential memory constraints.
def is_prime(n): """ Check if a number is prime. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 whi...
from solution import is_prime, list_primes def test_is_prime(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(17) == True assert is_prime(18) == False assert is_prime(23) == True ...
[ { "docstring": "Check if a number is prime.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "List all prime numbers ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check whether a number is prime.\n \"\"\"\n if n <= 1:\n return False\n \n if n <= 3:\n return True\n \n if n % 2 == 0 or n % ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039781", "row_id": 39781, "seed_ids": "['Qwen2-72B-Instruct_87173']" }
0.533952
Filter_39781
I
[ "is_prime", "list_primes" ]
2
[ [ "list_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8bfa58230c9d39c8c406eb0a87c007b247f55c3
896a5b1d81a6ab4e009c57749e5f6a9d39ceb6fd
v1.0
instruct
Filter
Filter_39789_I
Please write a Python program to find the 16th and 17th prime numbers using a function that generates a sequence of prime numbers using the Sieve of Eratosthenes algorithm. Additionally, modify the program to output the sum of the first 100 prime numbers.
def sieve_of_eratosthenes(limit): """ Generate all primes up to a given limit using the Sieve of Eratosthenes. """ primes = [] sieve = [True] * (limit + 1) sieve[0] = sieve[1] = False for start in range(2, limit + 1): if sieve[start]: primes.append(start) ...
from solution import sieve_of_eratosthenes, find_16th_and_17th_primes, sum_of_first_100_primes def test_sieve_of_eratosthenes(): primes = sieve_of_eratosthenes(30) expected_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] assert primes == expected_primes def test_find_16th_and_17th_primes(): primes_16th,...
[ { "docstring": "Generate all primes up to a given limit using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Return the 16th and 17th prime numbers.", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"Generate all prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\"\"\"\n is_prime = [True for _ in range(limit+1)]\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039789", "row_id": 39789, "seed_ids": "['Qwen2-72B-Instruct_87185']" }
0.583208
Filter_39789
I
[ "sieve_of_eratosthenes", "find_16th_and_17th_primes", "sum_of_first_100_primes" ]
3
[ [ "find_16th_and_17th_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
beff6e4d0af1aa84b46c408d870cd82e04768f76
553f316309928c660f06f233ba1000d664f20eef
v1.0
instruct
Filter
Filter_39791_I
denouveaUK_nolBot: Write a Python function to find the product of all prime numbers below a given positive integer. Include type hints in your function definition.
from typing import List def is_prime(n: int) -> bool: """ Check if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 ...
from solution import product_of_primes_below def test_no_primes_below_2(): assert product_of_primes_below(2) == 1 def test_primes_below_10(): # Primes below 10 are 2, 3, 5, 7 # The product is 2*3*5*7 == 210 assert product_of_primes_below(10) == 210 def test_primes_below_20(): # Primes below 20 ar...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the product of all prime numbers below the given positive integer n.", "function_declaration": "def product_of_p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039791", "row_id": 39791, "seed_ids": "['Qwen2-72B-Instruct_87192']" }
0.629938
Filter_39791
I
[ "is_prime", "product_of_primes_below" ]
2
[ [ "product_of_primes_below", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
08157588d1921fc8cb2f643d14d68b4523ba86ca
6d933af48b6c387e1ab02d1352d54c1de81482a9
v1.0
instruct
Filter
Filter_39811_I
Create a function in Python to compute the factorial of a number. Also, design a dynamic programming solution for the problem and compare the execution time of both approaches. First solution: Traditional approach to calculate factorial using recursive function.
import time def factorial_recursive(n): """ Compute factorial of a number using recursion. """ if n == 0 or n == 1: return 1 else: return n * factorial_recursive(n - 1) def factorial_dp(n): """ Compute factorial of a number using dynamic programming. """ dp = [1] * ...
from solution import factorial_recursive, factorial_dp, compare_execution_time def test_factorial_recursive_base_cases(): assert factorial_recursive(0) == 1 assert factorial_recursive(1) == 1 def test_factorial_recursive_general_cases(): assert factorial_recursive(5) == 120 assert factorial_recursive(...
[ { "docstring": "Compute factorial of a number using recursion.", "function_declaration": "def factorial_recursive(n):", "function_name": "factorial_recursive", "parameter_list": "(n)" }, { "docstring": "Compute factorial of a number using dynamic programming.", "function_declaration": "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef factorial_recursive(n):\n \"\"\"\n Compute the factorial of a number using a recursive approach.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n return n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039811", "row_id": 39811, "seed_ids": "['Qwen2-72B-Instruct_87222']" }
0.593027
Filter_39811
I
[ "factorial_recursive", "factorial_dp", "compare_execution_time" ]
3
[ [ "compare_execution_time", "factorial_dp" ], [ "compare_execution_time", "factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ab415865ebbb44d0fc97d2e3cc14244cbcbbd139
19c96c88347fa85cb27145a885bc60571c7349e3
v1.0
instruct
Filter
Filter_39813_I
Implement a python program that simulates coin flipping, with considerations for fairness. The coin toss outcomes (Heads and Tails) must be randomized. Add functionality for the program to perform multiple coin tosses defined by a variable n (1 ≤ n ≤ 100), and display both the outcomes and the count of heads versus tai...
import random def coin_flip(): """ Simulates a single coin flip. Returns 'Heads' or 'Tails' based on a random outcome. """ return 'Heads' if random.choice([True, False]) else 'Tails' def multiple_coin_flips(n): """ Simulates n coin flips and returns the results and counts of heads and tail...
from solution import coin_flip, multiple_coin_flips, investigate_fairness def test_coin_flip(): outcome = coin_flip() assert outcome in ['Heads', 'Tails'] def test_multiple_coin_flips(): outcomes, heads_count, tails_count = multiple_coin_flips(10) assert len(outcomes) == 10 assert heads_count + ta...
[ { "docstring": "Simulates a single coin flip.\nReturns 'Heads' or 'Tails' based on a random outcome.", "function_declaration": "def coin_flip():", "function_name": "coin_flip", "parameter_list": "()" }, { "docstring": "Simulates n coin flips and returns the results and counts of heads and ta...
[ 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 coin_toss(n):\n \"\"\"\n Simulates coin tossing n times and returns the outcomes and counts of heads and tails.\n\n Args:\n n (int): Number of coin tosses.\n\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039813", "row_id": 39813, "seed_ids": "['Qwen2-72B-Instruct_87227']" }
0.460455
Filter_39813
I
[ "coin_flip", "multiple_coin_flips", "investigate_fairness" ]
3
[ [ "investigate_fairness", "multiple_coin_flips" ], [ "multiple_coin_flips", "coin_flip" ] ]
2
[]
false
[]
false
pytest
true
[]
true
14ef1153d281160c874d410268b34c3c19e430dd
56d9b106da5f85e9b0f9117f4e0772d7a12e876a
v1.0
instruct
Filter
Filter_39832_I
Implement a heapsort algorithm to sort a given array of integers, but your algorithm must be written in such a way that it cannot rely on inbuilt sort functions or the use of a secondary collection data structure. After completing the implementation, validate the correctness of your solution by writing tests for it.
def heapify(arr, n, i): """ Heapify the subtree rooted at index i. n is the size of the heap """ largest = i left = 2 * i + 1 right = 2 * i + 2 # If left child is larger than root if left < n and arr[left] > arr[largest]: largest = left # If right child is larger than l...
from solution import heapsort def test_heapsort_sorted_array(): assert heapsort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heapsort_reverse_sorted_array(): assert heapsort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_heapsort_unsorted_array(): assert heapsort([3, 2, 5, 1, 4]) == [1, 2, 3, 4, 5] def te...
[ { "docstring": "Heapify the subtree rooted at index i.\nn is the size of the heap", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Perform heapsort on a list of integers.", "function_declaration": "def hea...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n Helper function to maintain the heap property of a subtree with root at index i\n and n is the size of the heap.\n \"\"\"\n largest = i # Ini...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039832", "row_id": 39832, "seed_ids": "['Qwen2-72B-Instruct_87263']" }
0.676985
Filter_39832
I
[ "heapify", "heapsort" ]
2
[ [ "heapsort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d914af6a63c118824963d57866aab17ac2fd60a
f48c13141dbc0a672a83ab41cb7de0ed77714e14
v1.0
instruct
Filter
Filter_39837_I
write code to find the shortest path from RDA polymer farm to grinder layer, using ecs control as the root node
import heapq def dijkstra(graph, start, end): """ Finds the shortest path in a graph using Dijkstra's algorithm. """ # Priority queue to store (cost, vertex) queue = [(0, start)] # Dictionary to store the shortest path to each node distances = {node: float('infinity') for node in graph} ...
from solution import dijkstra, find_shortest_path def test_dijkstra(): graph = { 'ECS_Control': {'RDA_Polymer_Farm': 2, 'Node3': 1}, 'RDA_Polymer_Farm': {'ECS_Control': 2, 'Node4': 4}, 'Grinder_Layer': {'Node3': 3, 'Node4': 1}, 'Node3': {'ECS_Control': 1, 'Grinder_Layer': 3}, ...
[ { "docstring": "Finds the shortest path in a graph using Dijkstra's algorithm.", "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": null, "function_declaration": "def find_shortest_path():", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start, end):\n \"\"\"\n Finds the shortest path in a graph using Dijkstra's algorithm.\n \"\"\"\n # Priority queue to store (cost, vertex)\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039837", "row_id": 39837, "seed_ids": "['Qwen2-72B-Instruct_87270']" }
0.398063
Filter_39837
I
[ "dijkstra", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b697ccde36c214f5114e119be7f297288f778b5e
0f1ab9b3b63d8f5aeac5dc13336a5e2e157b72de
v1.0
instruct
Filter
Filter_39847_I
Write a Python function that determines whether a number is a perfect number. A perfect number is a number that is equal to the sum of its proper divisors. Remember that proper divisors of a number do not include the number itself. In addition, write a second function that finds and prints all perfect numbers in a give...
def is_perfect_number(n): """ Determines if the given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself. :param n: Integer number to check if it is perfect. :return: True if n is a perfect num...
from solution import is_perfect_number, find_perfect_numbers_in_range def test_is_perfect_number(): assert is_perfect_number(6) == True assert is_perfect_number(28) == True assert is_perfect_number(496) == True assert is_perfect_number(8128) == True assert is_perfect_number(1) == False assert i...
[ { "docstring": "Determines if the given number is a perfect number.\n\nA perfect number is a positive integer that is equal to the sum of its proper divisors,\nexcluding the number itself.\n\n:param n: Integer number to check if it is perfect.\n:return: True if n is a perfect number, False otherwise.", "fun...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_number(n):\n \"\"\"\n Determines if the given number is a perfect number.\n \n A perfect number is a positive integer that is equal to the sum of its proper divisors...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039847", "row_id": 39847, "seed_ids": "['Qwen2-72B-Instruct_87291']" }
0.575884
Filter_39847
I
[ "is_perfect_number", "find_perfect_numbers_in_range" ]
2
[ [ "find_perfect_numbers_in_range", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
11cce0e4a009427531b50390b1625a5092f25c3a
e067fa3415e29fbb78344201aa149d37232a08f6
v1.0
instruct
Filter
Filter_39859_I
Write a function that fits a sine wave to a set of coordinates using Python and Numpy. Assume no prior knowledge of the wave's properties. Consider the sine wave form `y = A * sin(θ + ϕ) + B` where `A` is the amplitude, `θ` is the angle in radians, `ϕ` is phase shift in radians, and `B` is the height offset for the y-a...
import numpy as np from scipy.optimize import curve_fit def sine_wave(x, A, theta, phi, B): """ Sine wave function. Parameters: x (array-like): x-coordinates A (float): amplitude of the sine wave theta (float): angle in radians (frequency component) phi (float): phase shift in radians ...
import numpy as np from solution import sine_wave, fit_sine_wave def test_sine_wave_basic(): x = np.linspace(0, 2 * np.pi, 100) A, theta, phi, B = 1, 1, 0, 0 y = sine_wave(x, A, theta, phi, B) assert np.allclose(y, np.sin(x), atol=1e-6) def test_fit_sine_wave_exact(): x = np.linspace(0, 2 * np.pi,...
[ { "docstring": "Sine wave function.\n\nParameters:\nx (array-like): x-coordinates\nA (float): amplitude of the sine wave\ntheta (float): angle in radians (frequency component)\nphi (float): phase shift in radians\nB (float): height offset on the y-axis\n\nReturns:\narray-like: y-coordinates", "function_decl...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom scipy.optimize import curve_fit\n\ndef sine_wave(x, A, theta, phi, B):\n \"\"\"\n Sine wave function.\n \n Parameters:\n x (array-like): x-coordinates\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039859", "row_id": 39859, "seed_ids": "['Qwen2-72B-Instruct_87319']" }
0.675505
Filter_39859
I
[ "sine_wave", "fit_sine_wave" ]
2
[ [ "fit_sine_wave", "sine_wave" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
efac1eba91e970358ec9469842ae3d9c7a35dfed
b9b27d95abf0e41c8deccb1be017ea53a01e246a
v1.0
instruct
Filter
Filter_39872_I
Using numpy and matplotlib libraries, solve the system of equations: 3x + 2y - z = 1, x - y + 4z = -2, 2x + 2y + 2z = 0. Then plot the system of equations in a 3D graph. In preparation for this, define and utilise a function to solve the system of equations before plotting. Also, catch and handle any exceptions that ma...
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def solve_system_of_equations(): """ Solves the system of equations: 3x + 2y - z = 1 x - y + 4z = -2 2x + 2y + 2z = 0 Returns the solution as a numpy array [x, y, z]. """ try: A = np.array...
from solution import solve_system_of_equations def test_solve_system_of_equations_validity(): solution = solve_system_of_equations() # Check solution is not None and is of the correct shape assert solution is not None assert solution.shape == (3,) # Coefficients of the original system of equat...
[ { "docstring": "Solves the system of equations:\n3x + 2y - z = 1\nx - y + 4z = -2\n2x + 2y + 2z = 0\nReturns the solution as a numpy array [x, y, z].", "function_declaration": "def solve_system_of_equations():", "function_name": "solve_system_of_equations", "parameter_list": "()" }, { "docst...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\ndef solve_system_of_equations():\n A = np.array([[3, 2, -1], [1, -1, 4], [2, 2, 2]])\n B =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039872", "row_id": 39872, "seed_ids": "['Qwen2-72B-Instruct_87337']" }
0.467886
Filter_39872
I
[ "solve_system_of_equations", "plot_system" ]
2
[ [ "plot_system", "solve_system_of_equations" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "mpl_toolkits", "numpy" ]
false
5d8561da58591af26a7e986b0fb6717f98fbe895
21a537dd6f9c3221a51bd09bfd7c0519c8cbe84a
v1.0
instruct
Filter
Filter_39903_I
Write a function in any programming language that takes a string email address as input and returns an HTML code snippet to create an email link for that email address. The function should also include error handling to ensure the input is a valid email address.
import re def create_email_link(email): """ Takes an email address as input and returns an HTML code snippet to create an email link if the email address is valid. Args: email (str): The email address. Returns: str: HTML code snippet for the email link or an error message if inval...
from solution import create_email_link, is_valid_email def test_valid_emails(): assert create_email_link("test@example.com") == '<a href="mailto:test@example.com">test@example.com</a>' assert create_email_link("user.name+label@domain.co.uk") == '<a href="mailto:user.name+label@domain.co.uk">user.name+label@dom...
[ { "docstring": "Takes an email address as input and returns an HTML code snippet to create an email link\nif the email address is valid.\n\nArgs:\n email (str): The email address.\n\nReturns:\n str: HTML code snippet for the email link or an error message if invalid.", "function_declaration": "def cre...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef create_email_link(email):\n \"\"\"\n Returns an HTML code snippet for the given email address.\n Ensures the input is a valid email address.\n \"\"\"\n # Regula...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039903", "row_id": 39903, "seed_ids": "['Qwen2-72B-Instruct_87384']" }
0.53244
Filter_39903
I
[ "create_email_link", "is_valid_email" ]
2
[ [ "create_email_link", "is_valid_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ae9c8520a33f0d2bc094007beec5d618ad5f28c
5b120505587644321fbb437eda0f62fd63f9130d
v1.0
instruct
Filter
Filter_39911_I
Write a Python method using the boto3 library for working with Amazon S3 service. This method should handle uploading and downloading of files, listing all files within a bucket, and also deleting files. Additionally, implement error handling for these operations.
import boto3 from botocore.exceptions import NoCredentialsError, ClientError def s3_client(): return boto3.client('s3') def upload_file(file_name, bucket, object_name=None): if object_name is None: object_name = file_name try: s3_client().upload_file(file_name, bucket, object_name) ...
import pytest from unittest.mock import patch, MagicMock from solution import upload_file, download_file, list_files, delete_file def test_upload_file_success(): with patch('solution.s3_client') as mock_s3_client: mock_s3 = MagicMock() mock_s3.upload_file.return_value = None mock_s3_client...
[ { "docstring": null, "function_declaration": "def s3_client():", "function_name": "s3_client", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def upload_file(file_name, bucket, object_name=None):", "function_name": "upload_file", "parameter_list": "(file_...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import boto3\nfrom botocore.exceptions import NoCredentialsError, PartialCredentialsError, ClientError\n\nclass S3Manager:\n def __init__(self, bucket_name, aws_access_key_id=None, aws_secr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039911", "row_id": 39911, "seed_ids": "['Qwen2-72B-Instruct_87406']" }
0.53591
Filter_39911
I
[ "s3_client", "upload_file", "download_file", "list_files", "delete_file" ]
5
[ [ "delete_file", "s3_client" ], [ "download_file", "s3_client" ], [ "list_files", "s3_client" ], [ "upload_file", "s3_client" ] ]
4
[]
false
[]
false
pytest
true
[ "boto3", "botocore" ]
false
46638d34e6e584d06883d5d742e96126e603c8ae
db3b98441688ffc18ccc939ecf8fffa6c9b5ab96
v1.0
instruct
Filter
Filter_39938_I
Create a unittest for an out-of-place, in-place and recursive version of the quicksort algorithm. Not only must your test suite cover basic functionality of each algorithm, but should also cover edge cases including, but not limited to, already sorted lists, reverse sorted lists, and lists with identical elements. Addi...
from typing import List def quicksort_out_of_place(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort_out_of_place(left)...
import pytest from solution import quicksort_out_of_place, quicksort_in_place, quicksort_recursive def test_quicksort_out_of_place(): assert quicksort_out_of_place([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10] assert quicksort_out_of_place([]) == [] assert quicksort_out_of_place([1]) == [1] assert ...
[ { "docstring": null, "function_declaration": "def quicksort_out_of_place(arr):", "function_name": "quicksort_out_of_place", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def quicksort_in_place(arr, low, high):", "function_name": "quicksort_in_place", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef quicksort_out_of_place(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039938", "row_id": 39938, "seed_ids": "['Qwen2-72B-Instruct_87463']" }
0.438002
Filter_39938
I
[ "quicksort_out_of_place", "quicksort_in_place", "partition", "quicksort_recursive" ]
4
[ [ "quicksort_in_place", "partition" ], [ "quicksort_recursive", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ea8591ced9e83449d62ffc886789113134423145
85da6a0586848d3f72259b17f5154d612e825d87
v1.0
instruct
Filter
Filter_39947_I
Develop an application in python using recursion and threads to check multiple conditions on an array of n numbers. The primary condition is to check if any of the numbers is greater than 50 and is a prime number. Other conditions include checking for the numbers greater than 20 and less than 10. All these checks shoul...
import threading def is_prime(n): """Check if a number is a prime.""" if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def check_greater_than_50_and_prime(numbers, result): """Check if any number is greater than 50 and ...
from solution import is_prime, check_conditions def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_check_conditions(...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if any number is greater than 50 and prime.", "function_declaration": "def check_greater_than_50_and_prime(numbers, re...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import threading\n\ndef is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039947", "row_id": 39947, "seed_ids": "['Qwen2-72B-Instruct_87482']" }
0.572674
Filter_39947
I
[ "is_prime", "check_greater_than_50_and_prime", "check_greater_than_20", "check_less_than_10", "check_conditions" ]
5
[ [ "check_greater_than_50_and_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a3a3523c338579ba25da8713bf4cae5675703972
51a769526ac7ef303388b961b4036e946ea42c98
v1.0
instruct
Filter
Filter_39955_I
Use Python to write a code that displays a multiplication table of a given number, but the table should only display the multiplication results for prime numbers less than or equal to the given number.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False elif n <= 3: return True elif n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, prime_multiplication_table def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False assert is_prime(11) == True def test_prime_multiplication_table(): res...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a dictionary where keys are prime numbers less than or equal to num\nand values are the list of ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n elif n % 2...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00039955", "row_id": 39955, "seed_ids": "['Qwen2-72B-Instruct_87494']" }
0.622894
Filter_39955
I
[ "is_prime", "prime_multiplication_table" ]
2
[ [ "prime_multiplication_table", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85296aff3fe71f1aa921461662f6aa82464fd7e1
18b224061585cab166d524bc5dc9d315e4541c3c
v1.0
instruct
Filter
Filter_39976_I
I have a set of RGB pixel values in Python, how can I compress it using Huffman coding and then decompress it back to the original set of pixel values? Also, how can I measure the compression ratio and the improvement in terms of compression?
import heapq from collections import defaultdict, Counter # Node structure for Huffman Tree class Node: def __init__(self, value, frequency): self.value = value self.frequency = frequency self.left = None self.right = None # Comparison operators for priority queue def __lt_...
import pytest from solution import huffman_compress, huffman_decompress, calculate_compression_ratio, compression_improvement def test_huffman_compression_decompression(): data = [123, 234, 123, 456, 123, 234, 234, 123, 123, 456, 123] compressed_data, huffman_codes, root = huffman_compress(data) decom...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, Counter\nfrom heapq import heappush, heappop, heapify\nfrom typing import Dict, List, Tuple\n\n\nclass Node:\n def __init__(self, symbol, freq):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00039976", "row_id": 39976, "seed_ids": "['Qwen2-72B-Instruct_87537']" }
0.530729
Filter_39976
I
[ "build_huffman_tree", "build_codes", "huffman_compress", "huffman_decompress", "calculate_compression_ratio", "compression_improvement" ]
6
[ [ "huffman_compress", "build_codes" ], [ "huffman_compress", "build_huffman_tree" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
e6ab45c9ad8ffdf1d8d3dcc8441acd78ffa71333
b759143db108700ce6005e50a6ab228a74c2046e
v1.0
instruct
Filter
Filter_39998_I
Create a nested loop that prints all prime numbers within a given range from x to y inclusive, where x and y are positive integers. Make sure your code performs efficiently even for large values of x and y.
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True d...
from solution import is_prime, print_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(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_primes_in_ra...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints all prime numbers within the range from x to y inclusive.", "function_declaration": "def print_primes_in_range(x, y)...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039998", "row_id": 39998, "seed_ids": "['Qwen2-72B-Instruct_87582']" }
0.619885
Filter_39998
I
[ "is_prime", "print_primes_in_range" ]
2
[ [ "print_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2ccff75480cb1d3377b1183700a627fbfec20728
530a7b268ca858c327cb20c9e34b1b76ce24267a
v1.0
instruct
Filter
Filter_40017_I
Create a Tic-Tac-Toe game in Python using the curses library for console based UI
import curses def draw_board(stdscr, board): stdscr.clear() stdscr.addstr(0, 0, "Tic-Tac-Toe Game") for y in range(3): for x in range(3): stdscr.addstr(y * 2 + 1, x * 4, board[y][x] if board[y][x] else "_") stdscr.refresh() def check_winner(board): for row in board: if ...
from solution import check_winner, is_full def test_check_winner_row(): board = [ ["X", "X", "X"], [None, None, None], [None, None, None] ] assert check_winner(board) == "X" def test_check_winner_column(): board = [ ["O", None, None], ["O", None, None], ...
[ { "docstring": null, "function_declaration": "def draw_board(stdscr, board):", "function_name": "draw_board", "parameter_list": "(stdscr, board)" }, { "docstring": null, "function_declaration": "def check_winner(board):", "function_name": "check_winner", "parameter_list": "(board...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import curses\n\ndef draw_board(stdscr, board):\n stdscr.clear()\n for i in range(3):\n for j in range(3):\n if board[i][j] == '':\n stdscr.addstr(2 * i ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040017", "row_id": 40017, "seed_ids": "['Qwen2-72B-Instruct_87614']" }
0.406523
Filter_40017
I
[ "draw_board", "check_winner", "is_full", "tic_tac_toe", "main" ]
5
[ [ "tic_tac_toe", "check_winner" ], [ "tic_tac_toe", "draw_board" ], [ "tic_tac_toe", "is_full" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1eb0163a3c5e3d95eb0fa7977c7cf46ea2ce529a
2970474e3c5b44de1390417dd3d60f4e456dc6c6
v1.0
instruct
Filter
Filter_40025_I
Generate a multi-part blockchain-like hash challenge for a cryptocurrency task. The output should not only incorporate the sender, recipient, and transaction amount, but also other properties such as the transaction timestamp, ID, a random nonce, and a previous hash from the previous transaction to simulate a blockchai...
import hashlib import time import random def generate_transaction_id(): return str(int(time.time() * 1000)) + str(random.randint(1000, 9999)) def get_sha256_hash(data): return hashlib.sha256(data.encode('utf-8')).hexdigest() def generate_nonce(): return str(random.randint(0, 999999)) def create_transact...
import time from solution import create_transaction, verify_transaction def test_create_transaction(): sender = "Alice" recipient = "Bob" amount = 10.5 previous_hash = "0000a1b2c3d4e5f67890" transaction = create_transaction(sender, recipient, amount, previous_hash) assert transaction["sen...
[ { "docstring": null, "function_declaration": "def generate_transaction_id():", "function_name": "generate_transaction_id", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_sha256_hash(data):", "function_name": "get_sha256_hash", "parameter_list": "(...
[ 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\nimport random\n\nclass Block:\n def __init__(self, sender, recipient, amount, previous_hash):\n self.sender = sender\n self.recipient = recipient\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040025", "row_id": 40025, "seed_ids": "['Qwen2-72B-Instruct_87634']" }
0.465635
Filter_40025
I
[ "generate_transaction_id", "get_sha256_hash", "generate_nonce", "create_transaction", "verify_transaction" ]
5
[ [ "create_transaction", "generate_nonce" ], [ "create_transaction", "generate_transaction_id" ], [ "create_transaction", "get_sha256_hash" ], [ "verify_transaction", "get_sha256_hash" ] ]
4
[]
false
[]
false
pytest
true
[]
true
f9a4e6167abd0029a2d2823181ef02a189973459
9b6165323902d3f5cc73cac00445a551669efbb9
v1.0
instruct
Filter
Filter_40041_I
Can you modify this Python script to include a timer feature that waits for five seconds before executing the put博block code and乙肝xibo adds a condition to check if the temperature exceeds a threshold of 30 degrees Celsius before executing the 商green眨ks? Moreover, you are also required to add a condition to check if the...
import time def check_temperature(temperature): """ Checks if the temperature exceeds 30 degrees Celsius. """ return temperature > 30 def check_pressure(pressure): """ Checks if the air pressure is below 950 millibars. """ return pressure < 950 def execute_code(temperature, pressure):...
from solution import check_temperature, check_pressure, execute_code import time def test_check_temperature(): assert check_temperature(31) == True assert check_temperature(30) == False assert check_temperature(25) == False def test_check_pressure(): assert check_pressure(949) == True assert check...
[ { "docstring": "Checks if the temperature exceeds 30 degrees Celsius.", "function_declaration": "def check_temperature(temperature):", "function_name": "check_temperature", "parameter_list": "(temperature)" }, { "docstring": "Checks if the air pressure is below 950 millibars.", "function...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef check_temperature(temperature):\n \"\"\"\n Checks if the temperature exceeds the threshold.\n Returns True if temperature > 30 degrees Celsius, otherwise False.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040041", "row_id": 40041, "seed_ids": "['Qwen2-72B-Instruct_87673']" }
0.366572
Filter_40041
I
[ "check_temperature", "check_pressure", "execute_code", "puts博block_code" ]
4
[ [ "execute_code", "check_pressure" ], [ "execute_code", "check_temperature" ], [ "execute_code", "puts博block_code" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1435d4221f3c0996e5c6501b6020ee458ab18220
5dbd8ba008eb675ea2947b2a54ac678e3d0aa9a5
v1.0
instruct
Filter
Filter_40049_I
Given an integer array, sort it in ascending order using Quicksort algorithm. Additionally, your implementation must be done without using any built-in sort functions. Furthermore, add a functionality to your code to measure and print the time taken to sort the array.
import time def quicksort(arr): """ Sorts an array in ascending order using the Quicksort algorithm. """ if len(arr) <= 1: return arr else: pivot = arr[len(arr) // 2] less = [x for x in arr if x < pivot] equal = [x for x in arr if x == pivot] greater = [x for...
from solution import quicksort, timed_quicksort def test_empty_array(): assert quicksort([]) == [] def test_single_element_array(): assert quicksort([1]) == [1] def test_sorted_array(): assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert quicksort([5, 4, 3, 2...
[ { "docstring": "Sorts an array in ascending order using the Quicksort algorithm.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def timed_quicksort(arr):", "function_name": "tim...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef quicksort(arr):\n \"\"\"\n Sorts the array in ascending order using the Quicksort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n else:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040049", "row_id": 40049, "seed_ids": "['Qwen2-72B-Instruct_87686']" }
0.589446
Filter_40049
I
[ "quicksort", "timed_quicksort" ]
2
[ [ "timed_quicksort", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d76ab2eba478ab5c847b95d8833e0cf181feb4f
a2041dfb4ae05a80dd9461f23792b4feb9ee0a1e
v1.0
instruct
Filter
Filter_40075_I
Sort an array of integers from largest to smallest, ensuring that the time complexity of the sorting algorithm is O(n log n) or better. Additionally, the algorithm should handle duplicate integers correctly, preserving their relative order in the sorted array. The algorithm should also be implemented using a divide-and...
def merge_sort_desc(array): """ Sorts an array of integers in descending order using merge sort. """ if len(array) <= 1: return array # Split the array into two halves mid = len(array) // 2 left_half = merge_sort_desc(array[:mid]) right_half = merge_sort_desc(array[mid:]) ...
from solution import merge_sort_desc def test_merge_sort_desc_single_element(): assert merge_sort_desc([1]) == [1] def test_merge_sort_desc_sorted(): assert merge_sort_desc([5, 4, 3, 2, 1]) == [5, 4, 3, 2, 1] def test_merge_sort_desc_unsorted(): assert merge_sort_desc([5, 1, 3, 2, 4]) == [5, 4, 3, 2, 1] ...
[ { "docstring": "Sorts an array of integers in descending order using merge sort.", "function_declaration": "def merge_sort_desc(array):", "function_name": "merge_sort_desc", "parameter_list": "(array)" }, { "docstring": "Merges two sorted arrays into one sorted array in descending order.", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort_descending(arr):\n \"\"\"\n Sorts an array of integers from largest to smallest using merge sort algorithm.\n Time Complexity: O(n log n)\n \"\"\"\n if len(arr) <...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040075", "row_id": 40075, "seed_ids": "['Qwen2-72B-Instruct_87739']" }
0.624056
Filter_40075
I
[ "merge_sort_desc", "merge_desc" ]
2
[ [ "merge_sort_desc", "merge_desc" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd504ae9fb5683cd273ced60bb3d73dc8092c7a5
112f0e9fd4ab5a056cadee113f342533d2cd6d98
v1.0
instruct
Filter
Filter_40085_I
Human: Create a pseudocode for a function that takes an integer n as input, and prints out a list of all the prime numbers up to and including n. Then, implement your function in your preferred language. Also, add error handling for situations where the input is less than 2, as the smallest prime number is 2.
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def prime_numbers_up_to_n(n): """ Returns a list of all prime numbers up to and including...
from solution import prime_numbers_up_to_n def test_prime_numbers_up_to_n_with_valid_input(): assert prime_numbers_up_to_n(10) == [2, 3, 5, 7] assert prime_numbers_up_to_n(20) == [2, 3, 5, 7, 11, 13, 17, 19] assert prime_numbers_up_to_n(2) == [2] def test_prime_numbers_up_to_n_with_input_less_than_2(): ...
[ { "docstring": "Check if a number is a prime number.", "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.\nRaises a ValueError if n is less than 2.", "function_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040085", "row_id": 40085, "seed_ids": "['Qwen2-72B-Instruct_87757']" }
0.649842
Filter_40085
I
[ "is_prime", "prime_numbers_up_to_n" ]
2
[ [ "prime_numbers_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2749f9b29862fcebec21711b46e88df5a2fa6613
84d29c45700b617cb4a0474c2855d185939d349f
v1.0
instruct
Filter
Filter_40091_I
You are assigned the task to develop a proficient Web Scraper using Beautiful Soup. The scraper should navigate a target website recursively to gather and save textual contents and metadata such as author, publish date, etc., from all articles.
import requests from bs4 import BeautifulSoup def get_page_content(url): """Retrieve the HTML content of a web page.""" response = requests.get(url) return response.content def extract_article_data(soup): """Extract article data such as title, author, publish date, and content from a BeautifulSoup obj...
import pytest from bs4 import BeautifulSoup from unittest.mock import patch, MagicMock from solution import get_page_content, extract_article_data, scrape_website def test_get_page_content(): mock_response = MagicMock() mock_response.content = "<html></html>" with patch('requests.get', return_value=m...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nfrom urllib.parse import urljoin\n\ndef scrape_article(url):\n \"\"\"Scrape a single article for its content and metadata.\"\"\"\n respons...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040091", "row_id": 40091, "seed_ids": "['Qwen2-72B-Instruct_87770']" }
0.673484
Filter_40091
I
[ "get_page_content", "extract_article_data", "scrape_website" ]
3
[ [ "scrape_website", "extract_article_data" ], [ "scrape_website", "get_page_content" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
19b1a54668c3578818883ae290afd4ddfd2da3c3
c42cff78cd5f7f8102d12b7a7844539fb1850060
v1.0
instruct
Filter
Filter_40092_I
Create a Rogue-Like game loop in Python that includes a turn-based combat system, a randomized dungeon generator, and incorporates elements of fantasy lore and mythical creatures.
import random # Define the dungeon size DUNGEON_WIDTH = 5 DUNGEON_HEIGHT = 5 # Define the creatures and their stats creatures = { "goblin": {"HP": 10, "Attack": 2}, "orc": {"HP": 20, "Attack": 4}, "dragon": {"HP": 50, "Attack": 10} } # Define player stats player = { "HP": 30, "Attack": 5, "Po...
from solution import generate_dungeon, move_player, combat, player, creatures def test_generate_dungeon(): dungeon = generate_dungeon() assert len(dungeon) == 5 assert len(dungeon[0]) == 5 assert any(any(cell != '.' for cell in row) for row in dungeon) def test_move_player(): initial_position = pl...
[ { "docstring": null, "function_declaration": "def generate_dungeon():", "function_name": "generate_dungeon", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def display_dungeon(dungeon):", "function_name": "display_dungeon", "parameter_list": "(dungeon)" ...
[ 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\nclass Dungeon:\n def __init__(self, width, height):\n self.width = width\n self.height = height\n self.map = self.generate_map()\n \n def gen...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040092", "row_id": 40092, "seed_ids": "['Qwen2-72B-Instruct_87771']" }
0.453608
Filter_40092
I
[ "generate_dungeon", "display_dungeon", "move_player", "combat", "game_loop" ]
5
[ [ "game_loop", "combat" ], [ "game_loop", "display_dungeon" ], [ "game_loop", "generate_dungeon" ], [ "game_loop", "move_player" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3566c11c3ba0c8136c83c6f1c5968a3a7870a10d
331d8571782ceb84564a09d57b734aa1541793e4
v1.0
instruct
Filter
Filter_40103_I
Create three functions for three different algorithms for sorting a list of numbers, such as a list of twelve numbers: 10, 19, 3, 2, 15, 11, 9, 5, 13, 8, 7, and 6. Additionally, include a function to measure the time taken by each algorithm to sort the list. Then, write a function that would allow a user to input a lis...
import time def bubble_sort(arr): """ Bubble sort algorithm to sort a list of numbers. """ n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr def selection_sort(arr): """ Sel...
from solution import bubble_sort, selection_sort, insertion_sort, measure_time, sort_list def test_bubble_sort(): assert bubble_sort([10, 19, 3, 2, 15, 11, 9, 5, 13, 8, 7, 6]) == [2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 15, 19] assert bubble_sort([]) == [] assert bubble_sort([1, 2, 3]) == [1, 2, 3] assert bub...
[ { "docstring": "Bubble sort algorithm to sort a list of numbers.", "function_declaration": "def bubble_sort(arr):", "function_name": "bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Selection sort algorithm to sort a list of numbers.", "function_declaration": "def selection_so...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef bubble_sort(arr):\n \"\"\"\n Implementing bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040103", "row_id": 40103, "seed_ids": "['Qwen2-72B-Instruct_87794']" }
0.571685
Filter_40103
I
[ "bubble_sort", "selection_sort", "insertion_sort", "measure_time", "sort_list" ]
5
[ [ "sort_list", "bubble_sort" ], [ "sort_list", "insertion_sort" ], [ "sort_list", "selection_sort" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6ba3dfff078c4340a67110065dfa80c4410c0ed8
8cd4d6d9b4de3f1f39b2a1319615c543037c3b15
v1.0
instruct
Filter
Filter_40108_I
Using vanilla Python, create a weighted logical regression function with parameter estimation capabilities. Be sure to categorically manipulate input matrices to fit the most proficient sigmoid distribution, generating predictions and residual analysis post-results, and implementing exhaustive data-fit evaluation techn...
import numpy as np from scipy.special import expit # This is the sigmoid function def sigmoid(z): """ Compute the sigmoid of z """ return expit(z) def weighted_logistic_regression(X, y, weights, num_iters=1000, learning_rate=0.01): """ Performs weighted logistic regression using gradient desc...
import numpy as np import pytest from solution import weighted_logistic_regression, predict, residual_analysis, sigmoid def test_sigmoid(): assert np.allclose(sigmoid(0), 0.5) assert np.allclose(sigmoid(np.array([0, 2, -2])), expit(np.array([0, 2, -2]))) def test_weighted_logistic_regression(): X = np.arr...
[ { "docstring": "Compute the sigmoid of z", "function_declaration": "def sigmoid(z):", "function_name": "sigmoid", "parameter_list": "(z)" }, { "docstring": "Performs weighted logistic regression using gradient descent.\n\nParameters:\nX : np.array\n Input feature matrix (m x n), where m i...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom scipy.special import expit # This is the sigmoid function\n\ndef sigmoid(z):\n \"\"\"\n Compute the sigmoid of z\n \"\"\"\n return expit(z)\n\ndef weighte...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040108", "row_id": 40108, "seed_ids": "['Qwen2-72B-Instruct_87803']" }
0.48869
Filter_40108
I
[ "sigmoid", "weighted_logistic_regression", "predict", "residual_analysis" ]
4
[ [ "predict", "sigmoid" ], [ "weighted_logistic_regression", "sigmoid" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
e127fd23876d063369f569f46f9913b89a13acbb
6b2aa0b3aa70cc3962416283f2a36cfc5d2c7e15
v1.0
instruct
Filter
Filter_40124_I
Create a script in Python that will identify and print all integers less than 100 with a ones place of 7 and are also prime numbers.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if (n % i == 0) or (n % (i + 2) == 0): return False ...
from solution import is_prime, primes_with_ones_place_7 def test_is_prime(): # Test some known primes assert is_prime(2) assert is_prime(3) assert is_prime(17) assert is_prime(97) # Test some known non-primes assert not is_prime(1) assert not is_prime(4) assert not is_prime(100...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers less than 100 with a ones place of 7.", "function_declaration": "def prim...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040124", "row_id": 40124, "seed_ids": "['Qwen2-72B-Instruct_87832']" }
0.566132
Filter_40124
I
[ "is_prime", "primes_with_ones_place_7" ]
2
[ [ "primes_with_ones_place_7", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a45cbcf597b6aa854760681cb902d466a4b185d
a01d6b7d0bd7de2cdbe87c6ff5655e9d91a02844
v1.0
instruct
Filter
Filter_40130_I
Write a program to sort a given array of integers in non-decreasing order using heap sort algorithm.
def heapify(arr, n, i): """ Helper function to create a heapify tree. """ largest = i # Initialize largest as root left = 2 * i + 1 # left = 2*i + 1 right = 2 * i + 2 # right = 2*i + 2 # See if left child of root exists and is greater than root if left < n and arr[i] < arr[left]: ...
from solution import heap_sort def test_heap_sort_already_sorted(): assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heap_sort_reverse_order(): assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_heap_sort_mixed_numbers(): assert heap_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, ...
[ { "docstring": "Helper function to create a heapify tree.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Function to perform heap sort on a given array.", "function_declaration": "def heap_sort(arr):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n Function to heapify a subtree rooted with node i which is an index in arr.\n n is size of heap.\n \"\"\"\n largest = i # Initialize largest a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040130", "row_id": 40130, "seed_ids": "['Qwen2-72B-Instruct_87847']" }
0.827384
Filter_40130
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf5565959ffe13c352de7548bd20196e70b764d2
001a5f4b470367d5934f230cd266e843c7068ff6
v1.0
instruct
Filter
Filter_40132_I
Debug the given code for sorting an array using the Quick Sort algorithm, and modify it to be more efficient by using an in-place partition algorithm. Bonus points for implementing a randomized pivot selection.
import random def quicksort(arr, low, high): """ Sorts an array in place using the quick sort algorithm. """ if low < high: pi = partition(arr, low, high) quicksort(arr, low, pi - 1) quicksort(arr, pi + 1, high) def partition(arr, low, high): """ In-place partitioning o...
from solution import quick_sort def test_quick_sort_sorted(): assert quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_quick_sort_reverse(): assert quick_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_quick_sort_random(): array = [3, 6, 8, 10, 1, 2, 1] assert quick_sort(array) == [1, 1, 2, 3...
[ { "docstring": "Sorts an array in place using the quick sort algorithm.", "function_declaration": "def quicksort(arr, low, high):", "function_name": "quicksort", "parameter_list": "(arr, low, high)" }, { "docstring": "In-place partitioning of the array.", "function_declaration": "def par...
[ 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 quick_sort(arr, low, high):\n \"\"\"\n The main function that implements QuickSort.\n :param arr: List to be sorted\n :param low: Starting index\n :param hi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040132", "row_id": 40132, "seed_ids": "['Qwen2-72B-Instruct_87849']" }
0.504925
Filter_40132
I
[ "quicksort", "partition", "quick_sort" ]
3
[ [ "quick_sort", "quicksort" ], [ "quicksort", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0205cee10485fdecd9dc3ef03f6ba4a8cad7eb5a
167652e6a4f3ac20b2bbec144adb54646f59f91b
v1.0
instruct
Filter
Filter_40138_I
Devise a do-while loop structure in a programming language that persistently requests for user input until the entry satisfies the condition of not only being an anagram but also a palindrome, two intricate aspects of string manipulation. Your instruction should encompass tackling the complexities of validating whether...
def is_anagram_and_palindrome(s: str) -> bool: """ Checks if the string s is both an anagram and a palindrome. """ s = s.lower().replace(" ", "") # Convert to lower case and remove spaces return s == s[::-1] # Check if the string is a palindrome def get_valid_input(): """ Continuously req...
from solution import is_anagram_and_palindrome def test_is_anagram_and_palindrome(): assert is_anagram_and_palindrome("a") == True # Single char is an anagram of itself and a palindrome assert is_anagram_and_palindrome("aba") == True # Palindrome and trivially an anagram of itself assert is_anagram_and_p...
[ { "docstring": "Checks if the string s is both an anagram and a palindrome.", "function_declaration": "def is_anagram_and_palindrome(s):", "function_name": "is_anagram_and_palindrome", "parameter_list": "(s)" }, { "docstring": "Continuously requests user input until the input is both an anag...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_anagram_and_palindrome(s: str) -> bool:\n \"\"\"\n Checks if the string s is both an anagram and a palindrome.\n \"\"\"\n s = s.lower().replace(\" \", \"\") # Convert to lo...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040138", "row_id": 40138, "seed_ids": "['Qwen2-72B-Instruct_87859']" }
0.610757
Filter_40138
I
[ "is_anagram_and_palindrome", "get_valid_input" ]
2
[ [ "get_valid_input", "is_anagram_and_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c0408082260ef1507c0c5b1c5f78f75108a8a2fa
fbe4c938bc541008dc4e9ee08489fb3208aa01f1
v1.0
instruct
Filter
Filter_40149_I
Write a Python script that utilizes SciPy and NumPy libraries to perform an exponential fit on a dataset. The script should be able to handle data that is inputted in a CSV file format. Make sure to include error handling and provide documentation for each function. Also, ensure that the output of the script includes n...
import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy.optimize import curve_fit import tkinter as tk from tkinter import filedialog import tkinter.messagebox as messagebox def exponential_func(x, a, b): """ Exponential function to fit the data. Parameters: x (array_like): I...
import pytest import numpy as np import pandas as pd from solution import exponential_func, read_csv_file, perform_exponential_fit def test_exponential_func(): assert exponential_func(0, 1, 1) == 1 assert exponential_func(1, 1, 0) == 1 assert np.isclose(exponential_func(1, 1, 1), np.exp(1)) def test_read_...
[ { "docstring": "Exponential function to fit the data.\n\nParameters:\nx (array_like): Independent variable.\na (float): Scale factor.\nb (float): Rate constant.\n\nReturns:\narray_like: Exponential function values.", "function_declaration": "def exponential_func(x, a, b):", "function_name": "exponential...
[ 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 pandas as pd\nfrom scipy.optimize import curve_fit\nimport matplotlib.pyplot as plt\nfrom tkinter import Tk, Label, Button, Entry, filedialog, messagebox\nimport tki...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040149", "row_id": 40149, "seed_ids": "['Qwen2-72B-Instruct_87877']" }
0.595284
Filter_40149
I
[ "exponential_func", "read_csv_file", "perform_exponential_fit", "plot_data_and_fit", "main" ]
5
[ [ "perform_exponential_fit", "exponential_func" ], [ "plot_data_and_fit", "exponential_func" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy", "pandas", "scipy" ]
false
11b09adba4d0c66415ad044b0c1cbcbbbd358d63
bdc127ac4acc4789bd73aa6255136728153ebbc9
v1.0
instruct
Filter
Filter_40151_I
Implement a multi-threaded software algorithm capable of performing a prime number check on the value 1,234,567. Moreover, the prime checking function should be reusable for any numeric value and optimized for performance.
import math import threading def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: ...
from solution import is_prime, check_prime_concurrently def test_is_prime_small_numbers(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False def test_is_prime_large_number(): assert is_prime(1234567) == False def test_is_prime_edge_cases...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if a number n is prime using threading.", "function_declaration": "def check_prime_concurrently(n):", "function_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nimport threading\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return Tr...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040151", "row_id": 40151, "seed_ids": "['Qwen2-72B-Instruct_87886']" }
0.561165
Filter_40151
I
[ "is_prime", "check_prime_concurrently" ]
2
[ [ "check_prime_concurrently", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c6bb05cef3c35106b14b730b9d3569cfcb3c056
fd8b1d28dc62ae6821e35bede2e600c02c5d282e
v1.0
instruct
Filter
Filter_40154_I
Great. Could you conceive a related Jupyter Notebook script corresponding to this, where we start with the creation of a DataFrame featuring two columns (x, y)? Post that, devise a function that introduces a new column titled "z", with values derived from the computation of the square root of the multiplication result ...
import pandas as pd def babylonian_sqrt(value, tolerance=1e-10): """ Approximates the square root of a value using the Babylonian method. :param value: The value to find the square root of :param tolerance: The tolerance for approximating the square root :return: The approximated square root value ...
import pandas as pd from solution import babylonian_sqrt, add_z_column def test_babylonian_sqrt(): assert abs(babylonian_sqrt(4) - 2) < 1e-10 assert abs(babylonian_sqrt(9) - 3) < 1e-10 assert abs(babylonian_sqrt(16) - 4) < 1e-10 assert abs(babylonian_sqrt(0) - 0) < 1e-10 assert abs(babylonian_sqrt(...
[ { "docstring": "Approximates the square root of a value using the Babylonian method.\n:param value: The value to find the square root of\n:param tolerance: The tolerance for approximating the square root\n:return: The approximated square root value", "function_declaration": "def babylonian_sqrt(value, toler...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\n\ndef babylonian_sqrt(n, tolerance=1e-10):\n \"\"\"\n Approximates the square root of n using the Babylonian method.\n \"\"\"\n if n < 0:\n raise ValueE...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040154", "row_id": 40154, "seed_ids": "['Qwen2-72B-Instruct_87891']" }
0.571345
Filter_40154
I
[ "babylonian_sqrt", "add_z_column" ]
2
[ [ "add_z_column", "babylonian_sqrt" ] ]
1
[]
false
[]
false
pytest
true
[ "pandas" ]
false
f542f1dc9183225ee972037f2a9ff4c1acbd3261
266460feee68dbc793052917e944df0b042ae131
v1.0
instruct
Filter
Filter_40173_I
Can you specify the total quantity of uninterrupted sub-segments present within the string labeled as "abcabcbb"? This is a typical problem that may be asked in a coding interview, which can be solved by a sliding window algorithm.
def length_of_longest_substring(s): """ Function to find the length of the longest substring without repeating characters in the given string. """ char_map = {} left = 0 max_length = 0 for right in range(len(s)): if s[right] in char_map: left = max(left, char_map[s[right...
from solution import uninterrupted_subsegments_count def test_uninterrupted_subsegments_count(): assert uninterrupted_subsegments_count("abcabcbb") == 3 # The longest substrings without repeating characters are "abc" assert uninterrupted_subsegments_count("bbbbb") == 1 # The longest substring without repe...
[ { "docstring": "Function to find the length of the longest substring without repeating characters in the given string.", "function_declaration": "def length_of_longest_substring(s):", "function_name": "length_of_longest_substring", "parameter_list": "(s)" }, { "docstring": "Function to count...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def length_of_longest_substring(s):\n \"\"\"\n Returns the length of the longest substring without repeating characters.\n \"\"\"\n char_map = {}\n left = 0\n max_length = 0\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040173", "row_id": 40173, "seed_ids": "['Qwen2-72B-Instruct_87931']" }
0.609375
Filter_40173
I
[ "length_of_longest_substring", "uninterrupted_subsegments_count" ]
2
[ [ "uninterrupted_subsegments_count", "length_of_longest_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73d09a737f17be6561abd961480822eb6c5fb2c2
f375e02e41e201e449598f2f1b4e7135fbf2a897
v1.0
instruct
Filter
Filter_40177_I
Implement a generic solution for finding the closest pair of points among a given set of points using a divide-and-conquer algorithm. Additionally, show the testing, validation, and analyzing steps you took to ensure your implementation is correct and efficiently handle edge-cases, such as dealing with point sets that ...
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points. Each point is a tuple (x, y). """ return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def closest_pair_of_points(points): """ Find the closest pair of points i...
from solution import closest_pair_of_points def test_closest_pair_basic(): points = [(0, 0), (3, 4), (5, 12)] result = closest_pair_of_points(points) assert result[1] == 5 def test_closest_pair_with_duplicates(): points = [(0, 0), (0, 0), (3, 4), (5, 12)] result = closest_pair_of_points(points) ...
[ { "docstring": "Calculate the Euclidean distance between two points.\nEach point is a tuple (x, y).", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the closest pair of poi...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef distance(p1, p2):\n return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)\n\ndef closest_pair_of_points(points):\n def closest_pair_recursive(points_sorted_by_x, p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040177", "row_id": 40177, "seed_ids": "['Qwen2-72B-Instruct_87942']" }
0.502101
Filter_40177
I
[ "euclidean_distance", "closest_pair_of_points" ]
2
[ [ "closest_pair_of_points", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4bc8eb50f366dc7adcf42413f9dd545810a9f6e9
68cd5169e655c2f44e5bbf3d29efa8eb1e57c14f
v1.0
instruct
Filter
Filter_40190_I
Develop a subnet calculator in Python that accepts an IP address and subnet mask, and returns the network address, broadcast address, and IP range for the given subnet. The program should: 1) Verify the IP address and subnet are valid. 2) Determine the prefix length from the subnet mask. 3) Identify network address by ...
import ipaddress def validate_ip_and_mask(ip: str, mask: str) -> bool: """ Validates the given IP address and subnet mask. """ try: ipaddress.IPv4Address(ip) ipaddress.IPv4Network(f"0.0.0.0/{mask}") return True except ValueError: return False def calculate_subne...
from solution import validate_ip_and_mask, calculate_subnet_details def test_validate_ip_and_mask(): assert validate_ip_and_mask("192.168.1.1", "255.255.255.0") == True assert validate_ip_and_mask("192.168.1.1", "255.255.0") == False assert validate_ip_and_mask("999.999.999.999", "255.255.255.0") == False ...
[ { "docstring": "Validates the given IP address and subnet mask.", "function_declaration": "def validate_ip_and_mask(ip, mask):", "function_name": "validate_ip_and_mask", "parameter_list": "(ip, mask)" }, { "docstring": "Calculates and returns the network address, broadcast address, and IP ra...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import ipaddress\n\ndef subnet_calculator(ip, subnet_mask):\n \"\"\"\n Calculate network address, broadcast address, and IP range based on given IP and subnet mask.\n \n Parameters...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040190", "row_id": 40190, "seed_ids": "['Qwen2-72B-Instruct_87967']" }
0.592216
Filter_40190
I
[ "validate_ip_and_mask", "calculate_subnet_details" ]
2
[ [ "calculate_subnet_details", "validate_ip_and_mask" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ad2e568796871b71761ae212a3b0c2473ec8d78
ae339dc2520a5e92616ae9b21f2fb8e9007f28bc
v1.0
instruct
Filter
Filter_40197_I
Below is an erroneous code snippet. Your task is to fix it and develop an optimized function to calculate and return the Least Common Multiple (LCM) of two numbers 'a' and 'b'. Additionally, create a check function to validate your LCM function for a set of predefined test cases.
def gcd(a, b): """ Returns the Greatest Common Divisor (GCD) of a and b using Euclidean algorithm. """ while b: a, b = b, a % b return a def lcm(a, b): """ Returns the Least Common Multiple (LCM) of a and b. """ return abs(a * b) // gcd(a, b)
from solution import lcm def test_lcm_positive_numbers(): assert lcm(4, 5) == 20 assert lcm(6, 8) == 24 assert lcm(12, 15) == 60 def test_lcm_with_one(): assert lcm(1, 10) == 10 assert lcm(1, 1) == 1 def test_lcm_same_numbers(): assert lcm(7, 7) == 7 assert lcm(20, 20) == 20 def test_lcm...
[ { "docstring": "Returns the Greatest Common Divisor (GCD) of a and b using Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the Least Common Multiple (LCM) of a and b.", "function_declaration": ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Returns the Greatest Common Divisor (GCD) of a and b using Euclidean algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040197", "row_id": 40197, "seed_ids": "['Qwen2-72B-Instruct_87978']" }
0.607671
Filter_40197
I
[ "gcd", "lcm" ]
2
[ [ "lcm", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
01df81f654f508430e05cd729cfd9fac00b2ddc7
f287e85f21418b25b01492f31e7e55b543fa0467
v1.0
instruct
Filter
Filter_40198_I
Decorators are a popular feature in Python that allow developers to modify the behavior of functions, classes, or methods without changing the source code. Think about a scenario where you want to log the function calls or enforce specific conditions before executing the function. Write a decorator that could be used t...
def check_permissions(required_permission): def decorator(func): def wrapper(user, *args, **kwargs): if required_permission in user.get('permissions', []): return func(user, *args, **kwargs) else: raise PermissionError("User does not have the required ...
from solution import deleteFile, check_permissions import pytest def test_delete_file_with_permissions(): user = {'name': 'John Doe', 'permissions': ['delete']} try: deleteFile(user, 'example.txt') except PermissionError: pytest.fail("PermissionError was raised incorrectly.") def t...
[ { "docstring": null, "function_declaration": "def check_permissions(required_permission):", "function_name": "check_permissions", "parameter_list": "(required_permission)" }, { "docstring": "Deletes the specified file.", "function_declaration": "def deleteFile(user, filename):", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def requires_permission(permission):\n def decorator(func):\n def wrapper(user, *args, **kwargs):\n if user.has_permission(permission):\n return func(user, ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040198", "row_id": 40198, "seed_ids": "['Qwen2-72B-Instruct_87979']" }
0.442769
Filter_40198
I
[ "check_permissions", "deleteFile" ]
2
[ [ "deleteFile", "check_permissions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4454845d361a40a6ed4f07b6b40fcbde9e41a7aa
6a1e716dcbfb20b802c326f5d6976373b2b82d23
v1.0
instruct
Filter
Filter_40201_I
Create a function that compares two serialized JSON objects with nested structures. As part of your challenge, sample erroneous code is provided below, which you need to rectify and improve upon. The function should thoroughly check if both JSON objects are identical, including their nested structures, regardless of th...
import json def compare_json(json1, json2): """ Compares two serialized JSON objects with nested structures, considering their contents irrespective of the order of elements. """ obj1 = json.loads(json1) obj2 = json.loads(json2) return _compare_nested_structures(obj1, obj2) def _comp...
from solution import compare_json def test_compare_identical_json(): json1 = '{"name": "John", "age": 30, "city": "New York"}' json2 = '{"name": "John", "age": 30, "city": "New York"}' assert compare_json(json1, json2) == True def test_compare_different_json(): json1 = '{"name": "John", "age": 30, "ci...
[ { "docstring": "Compares two serialized JSON objects with nested structures, \nconsidering their contents irrespective of the order of elements.", "function_declaration": "def compare_json(json1, json2):", "function_name": "compare_json", "parameter_list": "(json1, json2)" }, { "docstring": ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef compare_json(json1, json2):\n \"\"\"\n Compare two JSON objects to see if they are deeply equivalent, regardless of order.\n \"\"\"\n def sort_json(json_obj):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040201", "row_id": 40201, "seed_ids": "['Qwen2-72B-Instruct_87982']" }
0.467506
Filter_40201
I
[ "compare_json", "_compare_nested_structures" ]
2
[ [ "compare_json", "_compare_nested_structures" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5977618994fde54c93cb06189e01429b2d37261b
30e0d4c921907dd513beb868f6d4eb09364d1122
v1.0
instruct
Filter
Filter_40217_I
Develop a piece of code, applying an algorithm of your choice, to calculate the net price of a commodity after implementing the Value Added Tax (VAT) at a rate of 5%. But the condition is, your code should also accomodate different purchase quantities and return a price chart for quantities ranging from 1 to 10.
def calculate_net_price(base_price, vat_rate, quantity): """ Returns the net price for a given quantity after applying the VAT rate. """ return base_price * quantity * (1 + vat_rate) def price_chart(base_price, vat_rate=0.05): """ Returns a price chart for quantities ranging from 1 to 10. "...
from solution import calculate_net_price, price_chart def test_calculate_net_price(): assert calculate_net_price(100, 0.05, 1) == 105.0 assert calculate_net_price(200, 0.05, 2) == 420.0 assert calculate_net_price(50, 0.05, 10) == 525.0 assert calculate_net_price(150, 0.05, 3) == 472.5 def test_price_c...
[ { "docstring": "Returns the net price for a given quantity after applying the VAT rate.", "function_declaration": "def calculate_net_price(base_price, vat_rate, quantity):", "function_name": "calculate_net_price", "parameter_list": "(base_price, vat_rate, quantity)" }, { "docstring": "Return...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_net_price(price, vat_rate=0.05):\n \"\"\"\n Calculates the net price of a commodity after applying VAT.\n \n Parameters:\n price (float): The original price of...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040217", "row_id": 40217, "seed_ids": "['Qwen2-72B-Instruct_88009']" }
0.467341
Filter_40217
I
[ "calculate_net_price", "price_chart" ]
2
[ [ "price_chart", "calculate_net_price" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24ba4f5e5e899191be262286be9b593fcf68c8c5
9e13fdcc6e593e3827252caa6aff57548cefdeba
v1.0
instruct
Filter
Filter_40220_I
Create a Flask endpoint that receives a string as a parameter and returns the string reversed. The endpoint should handle cases where the string contains special characters, numbers, and white spaces. Additionally, the solution should be implemented without using any built-in string manipulation functions or methods, s...
from flask import Flask, request, jsonify app = Flask(__name__) def reverse_string(s): """ Returns the reversed string without using built-in string manipulation functions. """ reversed_string = "" for char in s: reversed_string = char + reversed_string return reversed_string @app.rou...
from solution import reverse_string def test_reverse_empty_string(): assert reverse_string('') == '' def test_reverse_single_character(): assert reverse_string('a') == 'a' def test_reverse_string_with_spaces(): assert reverse_string('hello world') == 'dlrow olleh' def test_reverse_string_with_special_ch...
[ { "docstring": "Returns the reversed string without using built-in string manipulation functions.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Flask endpoint that receives a string as a query parameter and r...
[ 1, 1, 1 ]
3
easy
1
{ "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\ndef reverse_string(s):\n \"\"\"\n Returns the reversed string without using built-in string manipulation functions.\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040220", "row_id": 40220, "seed_ids": "['Qwen2-72B-Instruct_88014']" }
0.561908
Filter_40220
I
[ "reverse_string", "reverse_endpoint" ]
2
[ [ "reverse_endpoint", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
1c388adced49e7d650131ba83d4675418d2b68bd
e2833e7562785b28cfce3c96f4dcd075b009e0cc
v1.0
instruct
Filter
Filter_40249_I
Develop a Python function that requests the user to input a positive integer, then calculates and prints the multiplicative persistency of this number. The multiplicative persistency is determined by repeatedly multiplying all the digits of the number until the result is a single digit. The function should also include...
def multiplicative_persistence(n): """ Calculate the multiplicative persistence of a positive integer. """ def multiply_digits(num): product = 1 while num > 0: product *= num % 10 num //= 10 return product if not isinstance(n, int) or n < 0: r...
from solution import multiplicative_persistence def test_multiplicative_persistence_single_digit(): assert multiplicative_persistence(0) == 0 assert multiplicative_persistence(5) == 0 def test_multiplicative_persistence_double_digits(): assert multiplicative_persistence(10) == 1 assert multiplicative_...
[ { "docstring": "Calculate the multiplicative persistence of a positive integer.", "function_declaration": "def multiplicative_persistence(n):", "function_name": "multiplicative_persistence", "parameter_list": "(n)" }, { "docstring": "Requests user input for a positive integer and prints its ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiplicative_persistence():\n \"\"\"\n Prompts the user to input a positive integer and calculates the multiplicative persistence of the number.\n \"\"\"\n def get_multiplica...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040249", "row_id": 40249, "seed_ids": "['Qwen2-72B-Instruct_88073']" }
0.556665
Filter_40249
I
[ "multiplicative_persistence", "user_input" ]
2
[ [ "user_input", "multiplicative_persistence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
735b41fa99f9912f0c9a1a1133ad4f71db6efe1e
aabf2bf34827388bf8885e118f01229cdf247dae
v1.0
instruct
Filter
Filter_40251_I
Write a python program using a "do-while" loop that checks whether an integer input by the user is a prime number or not. If the number is not prime, the program should factor it. However, python does not support "do-while" loops natively, thus you have to emulate it. Additionally, the program should have measures to d...
def is_prime(n): """ Check if the number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def get_factors(n): """ Get factors of a non-prime number. """ factors = [] for i in range...
from solution import is_prime, get_factors def test_is_prime_with_prime_numbers(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(11) == True assert is_prime(13) == True def test_is_prime_with_non_prime_numbers(): assert is_prime(1) == False ...
[ { "docstring": "Check if the number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Get factors of a non-prime number.", "function_declaration": "def get_factors(n):", "function_name": "get_factors", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if the number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040251", "row_id": 40251, "seed_ids": "['Qwen2-72B-Instruct_88079']" }
0.673203
Filter_40251
I
[ "is_prime", "get_factors", "process_number" ]
3
[ [ "process_number", "get_factors" ], [ "process_number", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
835be4e810146ab98093801ea60da032c61d3340
4448647eed4669a692937524315c3ab2a9df969d
v1.0
instruct
Filter
Filter_40252_I
Using Python programming language, write a function that takes two integer arguments, 9 and 6 respectively, and returns the result of subtracting 6 from 9. Additionally, create a table that displays the binary representation of the integers, and include a brief explanation of two's complement representation. Finally, m...
def subtract(a, b): """ Returns the result of subtracting b from a. """ return a - b def to_binary(n, bits=8): """ Converts an integer to binary representation with given number of bits. Handles both positive and negative numbers. """ if n < 0: n = (1 << bits) + n return...
from solution import subtract, subtract_twos_complement, to_binary def test_subtract(): assert subtract(9, 6) == 3 def test_to_binary(): assert to_binary(9) == '00001001' assert to_binary(6) == '00000110' assert to_binary(3) == '00000011' assert to_binary(-1) == '11111111' assert to_binary(-6)...
[ { "docstring": "Returns the result of subtracting b from a.", "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_list": "(a, b)" }, { "docstring": "Converts an integer to binary representation with given number of bits.\nHandles both positive and negative ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def subtract(a, b):\n \"\"\"\n Returns the result of subtracting b from a.\n \"\"\"\n return a - b\n\ndef subtract_with_twos_complement(a, b):\n \"\"\"\n Returns the result o...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040252", "row_id": 40252, "seed_ids": "['Qwen2-72B-Instruct_88080']" }
0.612828
Filter_40252
I
[ "subtract", "to_binary", "subtract_twos_complement" ]
3
[ [ "subtract_twos_complement", "to_binary" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0941eca811234f2dbf2cc7bcba799a9b7034f27
a47673d8b9b99f1eddd82a4630a2ccf49fd8d55b
v1.0
instruct
Filter
Filter_40255_I
Modify and develop an enhanced software script that not only generates a 'triangle' pattern but also other polygonal patterns using prime numbers up to 'n'. The revised function should incorporate a condition to identify and print the largest prime number located in each pattern.
def is_prime(num): """ Check if a number is a prime number. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def generate_primes_up_to(n): """ Generate a list of prime numbers up to n. """ re...
from solution import is_prime, generate_primes_up_to, print_triangle_pattern, print_square_pattern def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(30) == False def test_generate_primes_up_to(): a...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate a list of prime numbers up to n.", "function_declaration": "def generate_primes_up_to(n):", "functio...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Check if a number is prime.\"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040255", "row_id": 40255, "seed_ids": "['Qwen2-72B-Instruct_88085']" }
0.467364
Filter_40255
I
[ "is_prime", "generate_primes_up_to", "print_triangle_pattern", "print_square_pattern" ]
4
[ [ "generate_primes_up_to", "is_prime" ], [ "print_square_pattern", "generate_primes_up_to" ], [ "print_triangle_pattern", "generate_primes_up_to" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1d443392e9f9bc44d821619328334f4ef7f6686c
a00237965385aee509812a1a3fd915b204e9634c
v1.0
instruct
Filter
Filter_40273_I
Given an array of integers, write a function that removes all duplicate numbers and returns a new array with only the unique values, while also sorting the resulting array in descending order. The function should have a time complexity of O(n log n). You are not allowed to use any built-in sort function.
def remove_duplicates_and_sort_desc(arr): """ Removes all duplicates from the input array and returns a new array with only unique values, sorted in descending order. :param arr: List of integers :return: List of unique integers, sorted in descending order """ unique_values = list(set(a...
from solution import remove_duplicates_and_sort_desc def test_remove_duplicates_and_sort_desc(): assert remove_duplicates_and_sort_desc([4, 5, 6, 5, 4, 3, 2, 1]) == [6, 5, 4, 3, 2, 1] assert remove_duplicates_and_sort_desc([1, 2, 3, 3, 2, 1]) == [3, 2, 1] assert remove_duplicates_and_sort_desc([10, 20, 10,...
[ { "docstring": "Removes all duplicates from the input array and returns a new array\nwith only unique values, sorted in descending order.\n\n:param arr: List of integers\n:return: List of unique integers, sorted in descending order", "function_declaration": "def remove_duplicates_and_sort_desc(arr):", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def remove_duplicates_and_sort(arr):\n \"\"\"\n Removes all duplicate numbers from an array and returns a new array with only \n the unique values, sorted in descending order. Time co...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040273", "row_id": 40273, "seed_ids": "['Qwen2-72B-Instruct_88120']" }
0.681534
Filter_40273
I
[ "remove_duplicates_and_sort_desc", "merge_sort_desc", "merge_desc" ]
3
[ [ "merge_sort_desc", "merge_desc" ], [ "remove_duplicates_and_sort_desc", "merge_sort_desc" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fd4858db4c3471ae69f0079dd59e1197f66456d9
1d4b153d207ca3033cbf82c1d11f7789b382a259
v1.0
instruct
Filter
Filter_40275_I
Create a basic Flask API using Routes that can access the final node of a graph using Breadth First Search.
from flask import Flask, request, jsonify app = Flask(__name__) def bfs(graph, start): visited = [] queue = [start] while queue: node = queue.pop(0) if node not in visited: visited.append(node) neighbors = graph.get(node, []) for neighbor in neighbo...
import pytest from flask import Flask import json from solution import app @pytest.fixture def client(): with app.test_client() as client: yield client def test_bfs_final_node(client): graph = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F'], 'D': [], 'E': ['F'],...
[ { "docstring": null, "function_declaration": "def bfs(graph, start):", "function_name": "bfs", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def final_node():", "function_name": "final_node", "parameter_list": "()" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, jsonify\n\napp = Flask(__name__)\n\ngraph = {\n 'A': ['B', 'C'],\n 'B': ['D', 'E'],\n 'C': ['F'],\n 'D': [],\n 'E': [],\n 'F': []\n}\n\ndef bfs_get_f...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040275", "row_id": 40275, "seed_ids": "['Qwen2-72B-Instruct_88123']" }
0.505817
Filter_40275
I
[ "bfs", "final_node" ]
2
[ [ "final_node", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
744dd726efb2406b9eaeb9b377a674f8c60aba6b
5ba2f25e23188e67e9cbd5eedc13a10bd8b086d9
v1.0
instruct
Filter
Filter_40298_I
Create a Python program that manages a dictionary containing the names of the months as keys and the numbers of days in each month as values. The program should be able to handle leap years by including an extra day for February. Additionally, implement a function that allows the user to input the year and determine if...
# Define the month dictionary months = { "January": 31, "February": 28, "March": 31, "April": 30, "May": 31, "June": 30, "July": 31, "August": 31, "September": 30, "October": 31, "November": 30, "December": 31 } def is_leap_year(year): """ Determine if a given ye...
from solution import is_leap_year, adjust_for_leap_year, months def test_is_leap_year(): assert is_leap_year(2000) == True assert is_leap_year(2001) == False assert is_leap_year(1900) == False assert is_leap_year(2004) == True def test_adjust_for_leap_year(): non_leap_year_months = adjust_for_leap...
[ { "docstring": "Determine if a given year is a leap year.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Adjust the months dictionary for a leap year.", "function_declaration": "def adjust_for_leap_year(...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Determines if the given year is a leap year.\n \n Parameters:\n year (int): The year to check.\n\n Returns:\n bool: True if the year is ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040298", "row_id": 40298, "seed_ids": "['Qwen2-72B-Instruct_88162']" }
0.578982
Filter_40298
I
[ "is_leap_year", "adjust_for_leap_year" ]
2
[ [ "adjust_for_leap_year", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13d5c12f1892f00475e2fba460870194fcf833d7
a199c8cd561a9bed2a9f93c3e282607412395516
v1.0
instruct
Filter
Filter_40307_I
Write a detailed Python program that sorts a list of 100 integers using the Optimized Bubble Sort algorithm. This program should also measure and print the runtime of the sorting algorithm. Furthermore, the program should produce the same sorted output even if it is run multiple times with different input list of 100 i...
import time import random def optimized_bubble_sort(arr): """ Sorts a list using the optimized Bubble Sort algorithm. """ n = len(arr) for i in range(n): swapped = False for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] ...
from solution import optimized_bubble_sort import random def test_sorted_order(): arr = [random.randint(0, 1000) for _ in range(100)] sorted_arr = optimized_bubble_sort(arr.copy()) assert sorted_arr == sorted(arr) def test_empty_list(): arr = [] sorted_arr = optimized_bubble_sort(arr.copy()) a...
[ { "docstring": "Sorts a list using the optimized Bubble Sort algorithm.", "function_declaration": "def optimized_bubble_sort(arr):", "function_name": "optimized_bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Generates a list of 100 random integers, sorts it using Optimized Bubble...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport time\n\ndef optimized_bubble_sort(arr):\n \"\"\"\n Sorts a list of integers using the Optimized Bubble Sort algorithm.\n \"\"\"\n n = len(arr)\n for i in r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040307", "row_id": 40307, "seed_ids": "['Qwen2-72B-Instruct_88180']" }
0.56869
Filter_40307
I
[ "optimized_bubble_sort", "generate_and_sort" ]
2
[ [ "generate_and_sort", "optimized_bubble_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f0532cb35cc48925c48eaa1735d4b29bc0fc62aa
44913bcb1e29e1b462a58be5b0ad604fbf8c9d00
v1.0
instruct
Filter
Filter_40329_I
Write Python code for re-implementing the quicksort algorithm without utilizing recursion. Additionally, your solution must work with multiple data types (integer, float, string) without any alterations. Ensure you handle the edge cases, including dealing with duplicate values and empty lists.
def quicksort(arr): """ Sorts an array using an iterative (non-recursive) version of quicksort. Handles multiple data types and edge cases. """ if len(arr) == 0: return arr # Stack for saving the ranges to sort stack = [(0, len(arr) - 1)] while stack: start, end...
from solution import quicksort def test_empty_list(): assert quicksort([]) == [] def test_single_element(): assert quicksort([1]) == [1] assert quicksort(['a']) == ['a'] def test_multiple_same_elements(): assert quicksort([5, 5, 5, 5]) == [5, 5, 5, 5] def test_integers(): assert quicksort([4, 2,...
[ { "docstring": "Sorts an array using an iterative (non-recursive) version of quicksort.\nHandles multiple data types and edge cases.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Partitions the array on the basis o...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort_iterative(arr):\n \"\"\"\n Sorts the list arr using the iterative version of quicksort algorithm.\n \"\"\"\n if len(arr) == 0:\n return []\n\n stack = [(0, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040329", "row_id": 40329, "seed_ids": "['Qwen2-72B-Instruct_88217']" }
0.519561
Filter_40329
I
[ "quicksort", "partition" ]
2
[ [ "quicksort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b85c93169cfca89b85477d7931773e90e67720d
b6c5fe1ca97c3055f4d27c61e52c8b3fe5f8f5f2
v1.0
instruct
Filter
Filter_40346_I
Implement a function that takes in an array of integers and prints out each element in the array. However, the function should only print out the element if it is a prime number.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def p...
import io import sys from solution import print_primes def test_print_primes_with_primes(): captured_output = io.StringIO() sys.stdout = captured_output print_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) sys.stdout = sys.__stdout__ assert captured_output.getvalue() == "2\n3\n5\n7\n" def test_print_primes_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Takes an array of integers and prints only the prime numbers.", "function_declaration": "def print_prim...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040346", "row_id": 40346, "seed_ids": "['Qwen2-72B-Instruct_88252']" }
0.655239
Filter_40346
I
[ "is_prime", "print_primes" ]
2
[ [ "print_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dda141c60a9b8f184dce234f0445e2d7e096821a
51741816c94f4081b93c868012e1daa709ae8f7e
v1.0
instruct
Filter
Filter_40367_I
Implement an O(n^2) algorithm for sorting a linked list, discuss its time complexity and identify the parts of the algorithm where the time complexity arises. Moreover, compare the performance of your algorithm to more efficient ones regarding time and space complexities.
class Node: def __init__(self, data): self.data = data self.next = None def insertion_sort_linked_list(head): if head is None or head.next is None: return head sorted_list = None # Initialize the sorted part of the list. current = head while current: next_node = c...
from solution import Node, insertion_sort_linked_list def linked_list_to_list(head): result = [] current = head while current: result.append(current.data) current = current.next return result def create_linked_list(lst): if not lst: return None head = Node(lst[0]) c...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef insertion_sort_list(head: ListNode) -> ListNode:\n \"\"\"\n Sorts a li...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040367", "row_id": 40367, "seed_ids": "['Qwen2-72B-Instruct_88282']" }
0.423721
Filter_40367
I
[ "insertion_sort_linked_list", "sorted_insert" ]
2
[ [ "insertion_sort_linked_list", "sorted_insert" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
079ec8f1cd7b299d44e4106ee85086efb43bfc3c
70b4888fe866287e95133a1b6e709ddf330bdab3
v1.0
instruct
Filter
Filter_40410_I
Create a function in Python to take a positive integer and return its factorial. However, the function should only work for prime numbers. If the input is not a prime number, the function should raise a ValueError with the error message "Input must be a prime number".
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def factorial_of_prime(n): """ Returns the factorial of a prime number n. If n is n...
from solution import factorial_of_prime, is_prime import pytest def test_factorial_of_prime_with_prime_input(): assert factorial_of_prime(2) == 2 assert factorial_of_prime(3) == 6 assert factorial_of_prime(5) == 120 assert factorial_of_prime(7) == 5040 def test_factorial_of_prime_with_non_prime_input(...
[ { "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 factorial of a prime number n.\nIf n is not prime, raises a ValueError.", "function_declaration...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040410", "row_id": 40410, "seed_ids": "['Qwen2-72B-Instruct_88355']" }
0.738886
Filter_40410
I
[ "is_prime", "factorial_of_prime" ]
2
[ [ "factorial_of_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c202d4c5feb99c77db8d829b4039d321cd3c31f8
17aa696c58fcc385d9dadb931572853a419a9cfd
v1.0
instruct
Filter
Filter_40418_I
Formulate a for loop to verify the primality condition for all integers from 1 up to a specified inclusive numerical limit. Also, optimize your solution to reduce the time complexity as much as possible. Implement error handling to ensure the numerical limit is a positive integer.
def is_prime(n): """Return True if n is a prime number, else False.""" if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i ...
from solution import is_prime, 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(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False ...
[ { "docstring": "Return True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers from 1 up to the given limit (inclusive).\n\nParameters:\n- limit: The numeri...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040418", "row_id": 40418, "seed_ids": "['Qwen2-72B-Instruct_88368']" }
0.516466
Filter_40418
I
[ "is_prime", "primes_up_to" ]
2
[ [ "primes_up_to", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2ea64ec24a5c85427ec56b2e902743598b8ecd4
5eaed52abbdd73fe1f4aeea8ca0ca350b80c9e2b
v1.0
instruct
Filter
Filter_40420_I
Is there a way to check in Python if all elements in a list can be casted as int? And then how to return the sum of those casted elements as int?
def can_cast_to_int(lst): """ Checks if all elements in the list can be casted to int. Returns True if all can be casted, otherwise False. """ try: [int(x) for x in lst] except ValueError: return False return True def sum_of_casted_ints(lst): """ Returns the sum of e...
from solution import can_cast_to_int, sum_of_casted_ints def test_can_cast_to_int_all_integers(): assert can_cast_to_int([1, 2, 3]) == True def test_can_cast_to_int_decimal_strings(): assert can_cast_to_int(["1", "2", "3"]) == True def test_can_cast_to_int_mix(): assert can_cast_to_int(["1", 2, "3"]) == ...
[ { "docstring": "Checks if all elements in the list can be casted to int.\nReturns True if all can be casted, otherwise False.", "function_declaration": "def can_cast_to_int(lst):", "function_name": "can_cast_to_int", "parameter_list": "(lst)" }, { "docstring": "Returns the sum of elements in...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_cast_to_int(lst):\n \"\"\"\n Checks if all elements in the list can be cast to int.\n Returns True if they can, otherwise False.\n \"\"\"\n try:\n [int(item) for ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040420", "row_id": 40420, "seed_ids": "['Qwen2-72B-Instruct_88371']" }
0.595999
Filter_40420
I
[ "can_cast_to_int", "sum_of_casted_ints" ]
2
[ [ "sum_of_casted_ints", "can_cast_to_int" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d27973b3de1069f774ec11d79a05e83c6ae9154c
0ee46147b37c186c7e33925e2fde3b04aa73d913
v1.0
instruct
Filter
Filter_40434_I
How can I check if a given number is a prime or not using Python and then find all the prime numbers in a list? Also, write a function to return the first prime number that exceeds a certain value from that list.
def is_prime(n): """ Check if the given number n is a prime number. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def find_primes(lst): """ Find all prime numbers in a given list. """ return ...
from solution import is_prime, find_primes, first_prime_exceeding 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(0) == False assert is_prime(1) == False def test_find_primes(): assert find_p...
[ { "docstring": "Check if the given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all prime numbers in a given list.", "function_declaration": "def find_primes(lst):", "function_na...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if the number n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040434", "row_id": 40434, "seed_ids": "['Qwen2-72B-Instruct_88397']" }
0.738076
Filter_40434
I
[ "is_prime", "find_primes", "first_prime_exceeding" ]
3
[ [ "find_primes", "is_prime" ], [ "first_prime_exceeding", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
adbb41af499f1ea333106194a3b1217e4d4d9227
970e23c964140c6d56c2e780de44cb7f666cdad4
v1.0
instruct
Filter
Filter_40444_I
Write a recursive function that computes the total number of inversions in an array. An inversion occurs when, for any pair of indices i and j, the element at index i is greater than the element at index j, and i < j.
def count_inversions(arr): """ Compute the total number of inversions in an array. """ if len(arr) < 2: return 0, arr mid = len(arr) // 2 left_inversions, left = count_inversions(arr[:mid]) right_inversions, right = count_inversions(arr[mid:]) split_inversions, sorted_arr = merg...
from solution import get_total_inversions def test_empty_array(): assert get_total_inversions([]) == 0 def test_single_element_array(): assert get_total_inversions([1]) == 0 def test_sorted_array(): assert get_total_inversions([1, 2, 3, 4, 5]) == 0 def test_reverse_sorted_array(): assert get_total_i...
[ { "docstring": "Compute the total number of inversions in an array.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_and_count(left, right):", "function_na...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_inversions(arr):\n \"\"\"\n Returns the total number of inversions in the array.\n An inversion is defined as a pair (i, j) where i < j and arr[i] > arr[j].\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040444", "row_id": 40444, "seed_ids": "['Qwen2-72B-Instruct_88416']" }
0.761657
Filter_40444
I
[ "count_inversions", "merge_and_count", "get_total_inversions" ]
3
[ [ "count_inversions", "merge_and_count" ], [ "get_total_inversions", "count_inversions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
444292a09a01dc503ebc6d6a59010d202d8906e5
679c5a941f0a55f4af839de7400d6e3d196f9327
v1.0
instruct
Filter
Filter_40472_I
Utilizing exclusively the alphabetic characters 'a', 'c', 'g', and 't', generate three distinct sequences, each consisting of precisely ten elements. But, ensure that the sequence doesn't repeat any consecutive tridental ("abc", "gta", etc) patterns. Please write a python program to solve this problem.
import random def generate_sequence(length): """ Generates a sequence of the provided length using the characters 'a', 'c', 'g', and 't' without repeating any consecutive "tridental" patterns. """ characters = ['a', 'c', 'g', 't'] sequence = [random.choice(characters) for _ in range(length)] ...
from solution import generate_three_sequences def test_sequences_length(): sequences = generate_three_sequences() assert len(sequences) == 3 for seq in sequences: assert len(seq) == 10 def test_no_consecutive_tridental(): sequences = generate_three_sequences() for seq in sequences: ...
[ { "docstring": "Generates a sequence of the provided length using the characters 'a', 'c', 'g', and 't'\nwithout repeating any consecutive \"tridental\" patterns.", "function_declaration": "def generate_sequence(length):", "function_name": "generate_sequence", "parameter_list": "(length)" }, { ...
[ 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 is_tridental_pattern(sequence):\n \"\"\"\n Check if the given sequence has any repeating consecutive tridental (\"abc\", \"gta\", etc) patterns.\n \"\"\"\n for...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040472", "row_id": 40472, "seed_ids": "['Qwen2-72B-Instruct_88478']" }
0.582079
Filter_40472
I
[ "generate_sequence", "generate_three_sequences" ]
2
[ [ "generate_three_sequences", "generate_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5965474d13c1135adab37d5b3e195ab2827dd4a2
e5e21a1e1051ec6669f9bacf4c69b5ccd4e35774
v1.0
instruct
Filter
Filter_40480_I
Create a method to generate a random password with a length of at least 12 characters, which must contain at least two capital letters, two numbers, and two special characters (e.g. @, #, $). The password should not contain any consecutive repeating characters.
import random import string def generate_random_password(length=12): """ Generate a random password of at least 'length' characters including: - At least 2 capital letters - At least 2 numbers - At least 2 special characters - No consecutive repeating characters """ if length < 12: ...
from solution import generate_random_password, has_no_consecutive_repeating_characters import string def test_password_length(): password = generate_random_password(12) assert len(password) >= 12 def test_password_length_longer(): password = generate_random_password(20) assert len(password) >= 20 def...
[ { "docstring": "Generate a random password of at least 'length' characters including:\n- At least 2 capital letters\n- At least 2 numbers\n- At least 2 special characters\n- No consecutive repeating characters", "function_declaration": "def generate_random_password(length=12):", "function_name": "genera...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ndef generate_random_password(length=12):\n \"\"\"\n Generate a random password of at least 'length' characters including:\n - At least 2 capital letter...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040480", "row_id": 40480, "seed_ids": "['Qwen2-72B-Instruct_88493']" }
0.698251
Filter_40480
I
[ "generate_random_password", "has_no_consecutive_repeating_characters" ]
2
[ [ "generate_random_password", "has_no_consecutive_repeating_characters" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c4839d1b48f5cb1017da7c17b460d0daeb1b6ad
c7c3485a15f0a43390c03f22399be2a2a6dc5b2f
v1.0
instruct
Filter
Filter_40520_I
In Python, turn a list of integers into a string where each integer is written out in English and the list items are separated by semicolons
num_to_word = { 0: "zero", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 20: "twenty", 30: "t...
from solution import list_to_english_string def test_single_digit_numbers(): assert list_to_english_string([1, 2, 3]) == "one;two;three" def test_two_digit_numbers(): assert list_to_english_string([21, 34, 45]) == "twenty-one;thirty-four;forty-five" def test_mixed_numbers(): assert list_to_english_string...
[ { "docstring": null, "function_declaration": "def convert_to_words(num):", "function_name": "convert_to_words", "parameter_list": "(num)" }, { "docstring": "Converts a list of integers into a string where each integer is written out in English and separated by semicolons.\n\nParameters:\nlst...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_english(n):\n \"\"\"\n Converts an integer to its English word representation\n \"\"\"\n if n == 0:\n return \"zero\"\n \n ones = [\"\", \"one\", \"two\", \...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040520", "row_id": 40520, "seed_ids": "['Qwen2-72B-Instruct_88563']" }
0.538321
Filter_40520
I
[ "convert_to_words", "list_to_english_string" ]
2
[ [ "list_to_english_string", "convert_to_words" ] ]
1
[]
false
[]
false
pytest
true
[]
true
82190e89e67fa02a8a2b5c579800443184664ede
b86b34a71d2f70fca70a610a0eb66e1d50f7f091
v1.0
instruct
Filter
Filter_40540_I
Define a Python function called "multiply_three_numbers" that takes in three integer inputs, x, y and z, and returns their product. Then write a Python script that calls the function with increasingly larger sequences of positive prime numbers starting with (2, 3, 5), (7, 11, 13), (17, 19, 23), and so on, until the pro...
def multiply_three_numbers(x, y, z): """ Returns the product of three integers x, y, and z. """ return x * y * z def check_overflow(): import sys maximum_value = sys.maxsize primes = [(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, 37), (41, 43, 47)] for prime_triplet in primes: ...
from solution import multiply_three_numbers def test_multiply_three_numbers_positive(): assert multiply_three_numbers(2, 3, 5) == 30 assert multiply_three_numbers(7, 11, 13) == 1001 assert multiply_three_numbers(17, 19, 23) == 7429 def test_multiply_three_numbers_with_zero(): assert multiply_three_num...
[ { "docstring": "Returns the product of three integers x, y, and z.", "function_declaration": "def multiply_three_numbers(x, y, z):", "function_name": "multiply_three_numbers", "parameter_list": "(x, y, z)" }, { "docstring": null, "function_declaration": "def check_overflow():", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiply_three_numbers(x, y, z):\n \"\"\"\n Returns the product of three integers x, y, and z.\n \"\"\"\n return x * y * z\n\nif __name__ == \"__main__\":\n import sys\n\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040540", "row_id": 40540, "seed_ids": "['Qwen2-72B-Instruct_88599']" }
0.647597
Filter_40540
I
[ "multiply_three_numbers", "check_overflow" ]
2
[ [ "check_overflow", "multiply_three_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
60ff2b10b5546a5b732ee2553fae58a3ddc115dc
a4fd07e3e14c531f1b9e301fa16d36dae7877248
v1.0
instruct
Filter
Filter_40542_I
vpnpopcorn's biz module utilizes a check balance function that deducts a specific amount of boosts from the available pool in a schema based table. the following criteria must be met for a successful deduction: it should solely subtract a positive sum of boosts that do not outstrip the current quantity and should decli...
import datetime max_allowable_deduction = 50000 def check_balance(userid, pool, amount): """ Deduct a specific amount of boosts from the available pool in a schema-based table. Parameters: - userid (str): Unique user identifier - pool (int): Current quantity in the pool - amount (int): Nu...
import pytest from solution import check_balance, max_allowable_deduction def test_deduct_successful(): remaining_pool = check_balance("user123", 10000, 3000) assert remaining_pool == 7000 def test_deduct_more_than_available(): result = check_balance("user123", 1000, 3000) assert result == "cant deduc...
[ { "docstring": "Deduct a specific amount of boosts from the available pool in a schema-based table.\n\nParameters:\n- userid (str): Unique user identifier\n- pool (int): Current quantity in the pool\n- amount (int): Number of boosts to deduct\n\nReturns:\n- int: Remaining quantity in the pool after a successful...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\n\n# Define the class and methods according to the given requirements\n\nclass BoostManager:\n max_allowable_deduction = 50000 # predefined value\n \n def __init__(se...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040542", "row_id": 40542, "seed_ids": "['Qwen2-72B-Instruct_88601']" }
0.308865
Filter_40542
I
[ "check_balance", "history_log" ]
2
[ [ "check_balance", "history_log" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76b1a3f4b2b9ea0808c7274b2ca559444aec9e5f
32643011c5167ccf1b733e93870a97c979acea33
v1.0
instruct
Filter
Filter_40545_I
Deleting all even values in a binary search tree containing integers can cause the BST to lose balance. Write a python program that takes as input a binary search tree and returns a new version of this binary search tree deleting every even valued node while maintaining the minimum property of the binary search tree. T...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.key = key def delete_even_nodes(root): if root is None: return None # Recursively process the left and right subtrees root.left = delete_even_nodes(root.left) root.right = delete_even_n...
from solution import TreeNode, delete_even_nodes, in_order_traversal def build_bst_from_list(arr): if not arr: return None mid = len(arr) // 2 root = TreeNode(arr[mid]) root.left = build_bst_from_list(arr[:mid]) root.right = build_bst_from_list(arr[mid+1:]) return root def test_dele...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is None:\n return TreeN...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040545", "row_id": 40545, "seed_ids": "['Qwen2-72B-Instruct_88605']" }
0.553474
Filter_40545
I
[ "delete_even_nodes", "find_min", "delete_node", "in_order_traversal" ]
4
[ [ "delete_even_nodes", "delete_node" ], [ "delete_even_nodes", "find_min" ], [ "delete_node", "find_min" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
966573fb3813c4d3318d26811fcd16e7bbbefdfc
f11c82d5c2eca3cd0037d242b38e38a37c477923
v1.0
instruct
Filter
Filter_40546_I
Create a version of the quicksort algorithm that works with a doubly linked list instead of an array. Your solution should also be able to handle cases where the linked list contains duplicate values. Starting code is provided below but note that this is an array-based quicksort and you will need to substantially rewri...
class Node: def __init__(self, data): self.data = data self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node ...
from solution import Node, DoublyLinkedList, quicksort, get_tail def test_empty_list(): dll = DoublyLinkedList() quicksort(dll.head, get_tail(dll.head)) assert dll.to_list() == [] def test_single_element_list(): dll = DoublyLinkedList() dll.append(1) quicksort(dll.head, get_tail(dll.head)) ...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, data):\n self.data = data\n self.next = None\n self.prev = None\n\nclass DoublyLinkedList:\n def __init__(self):\n self.head ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040546", "row_id": 40546, "seed_ids": "['Qwen2-72B-Instruct_88608']" }
0.470315
Filter_40546
I
[ "partition", "quicksort", "get_tail" ]
3
[ [ "quicksort", "partition" ] ]
1
[]
false
[ "Node", "DoublyLinkedList" ]
true
pytest
true
[]
true
84e2ea1187c3afc33df1fed853ec0a7d12ccb278
a308a0bce6557870315280bda3c02184d43c5b58
v1.0
instruct
Filter
Filter_40549_I
Combine the functionality of the two programs below into a single Python program that not only calculate the running sum of a list of numbers but also estimates the value of pi using the Leibniz formula. The program should then output both the running sum and the estimation of pi.
def running_sum(nums): """ Returns the running sum of the given list of numbers. """ result = [] current_sum = 0 for num in nums: current_sum += num result.append(current_sum) return result def estimate_pi(n_terms): """ Estimates the value of pi using the Leibniz for...
from solution import running_sum, estimate_pi, running_sum_and_pi def test_running_sum(): assert running_sum([1, 2, 3, 4]) == [1, 3, 6, 10] assert running_sum([0, 0, 0]) == [0, 0, 0] assert running_sum([5, -2, 3]) == [5, 3, 6] def test_estimate_pi(): assert round(estimate_pi(1), 2) == 4.00 assert ...
[ { "docstring": "Returns the running sum of the given list of numbers.", "function_declaration": "def running_sum(nums):", "function_name": "running_sum", "parameter_list": "(nums)" }, { "docstring": "Estimates the value of pi using the Leibniz formula up to n_term terms.", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def running_sum(numbers):\n \"\"\"\n Given a list of numbers, returns a list where each element is the\n running sum of the input list up to that point.\n \"\"\"\n if not number...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040549", "row_id": 40549, "seed_ids": "['Qwen2-72B-Instruct_88613']" }
0.492193
Filter_40549
I
[ "running_sum", "estimate_pi", "running_sum_and_pi" ]
3
[ [ "running_sum_and_pi", "estimate_pi" ], [ "running_sum_and_pi", "running_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
55ffbc85fed75c0e205ba42e3e7d1d5991e90dc7
d6dd4f8a3dc1a771111abd5879164c2e216b05dc
v1.0
instruct
Filter
Filter_40573_I
Develop a Python program to print the odd numbers from 1 to 50 that are prime, and also count the total number of these numbers. Additionally, the program must validate the generated list by checking if each of its elements are indeed a prime number. Here is a piece of code with some errors and omissions. Identify and ...
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 odd_primes_up_to_50(): """ Returns a list of odd prime numbers from 1 to 50 ...
from solution import is_prime, odd_primes_up_to_50, validate_prime_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(-1) == False assert is_prime(0) == False assert is_prime(1) == False de...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of odd prime numbers from 1 to 50 and the count of these numbers.", "function_declara...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040573", "row_id": 40573, "seed_ids": "['Qwen2-72B-Instruct_88659']" }
0.637317
Filter_40573
I
[ "is_prime", "odd_primes_up_to_50", "validate_prime_list" ]
3
[ [ "odd_primes_up_to_50", "is_prime" ], [ "validate_prime_list", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6e6dd632135006c59c20211a0853b3801e27f913
3bb0ab8e81ec108793e8f972bc72ea7f491f58f3
v1.0
instruct
Filter
Filter_40577_I
Create a program in Python that generates and prints the Twin Primes up to a given number N. Twin primes are pairs of primes which differ by two. For instance, (3, 5), (5, 7) and (11, 13) are twin primes.
def is_prime(n): """ Check if the number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import is_prime, generate_twin_primes def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(17) is True assert is_prime(20) is False def test_generate_twin_primes(): assert generate_twin_primes(10) == [(3, 5), (5, 7...
[ { "docstring": "Check if the number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate and return a list of twin primes up to the number N.", "function_declaration": "def generate_twin_primes...
[ 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(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040577", "row_id": 40577, "seed_ids": "['Qwen2-72B-Instruct_88664']" }
0.606912
Filter_40577
I
[ "is_prime", "generate_twin_primes", "print_twin_primes" ]
3
[ [ "generate_twin_primes", "is_prime" ], [ "print_twin_primes", "generate_twin_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4871f09a018edfc048b8e6804cfbebb8a7a547a6
c32b4648f49ae41acd2bafb122bac962bc1416e0
v1.0
instruct
Filter
Filter_40584_I
Write a Python function to calculate the factorial of a non-negative integer. However, you cannot use any built-in functions or libraries for calculating the factorial or for any numerical operations. You must implement the factorial calculation using basic arithmetic operations only. Additionally, your function should...
def factorial(n): """ Calculate the factorial of a non-negative integer n using basic arithmetic operations only. """ if n < 0: raise ValueError("Input must be a non-negative integer.") result = 1 for i in range(2, n + 1): result = multiply(result, i) return result ...
from solution import factorial, multiply def test_multiply(): assert multiply(0, 5) == 0 assert multiply(5, 0) == 0 assert multiply(3, 4) == 12 assert multiply(5, 5) == 25 def test_factorial_base_cases(): assert factorial(0) == 1 assert factorial(1) == 1 def test_factorial_small_numbers(): ...
[ { "docstring": "Calculate the factorial of a non-negative integer n using basic arithmetic operations only.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Multiply two integers using repeated addition.", "function_d...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Calculate the factorial of a non-negative integer n using basic arithmetic operations only.\n \"\"\"\n if n < 0:\n raise ValueError(\"Input must...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040584", "row_id": 40584, "seed_ids": "['Qwen2-72B-Instruct_88680']" }
0.72021
Filter_40584
I
[ "factorial", "multiply" ]
2
[ [ "factorial", "multiply" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f6bff8cec6eb8946c1b8c0be8f68a8a6d83ad11
a9fc1af635a9a102e25c645228ba5c08ada22176
v1.0
instruct
Filter
Filter_40595_I
Develop an efficient algorithm for sorting a given list in ascending order. Your algorithm should have a time complexity of O(n log n) and should not use any built-in sorting functions or libraries. Additionally, the algorithm should be implemented in a way that it can handle duplicate elements in the list and sort the...
def merge_sort(my_list): """ Sorts a list in ascending order using the merge sort algorithm. :param my_list: List of integers to be sorted :returns: Sorted list in ascending order """ if len(my_list) <= 1: return my_list # Split the list into two halves mid = len(my_lis...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_two_elements(): assert merge_sort([2, 1]) == [1, 2] def test_merge_sort_multiple_elements(): assert merge_sort([5, 3, 8, 4,...
[ { "docstring": "Sorts a list in ascending order using the merge sort algorithm.\n\n:param my_list: List of integers to be sorted\n:returns: Sorted list in ascending order", "function_declaration": "def merge_sort(my_list):", "function_name": "merge_sort", "parameter_list": "(my_list)" }, { "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(my_list):\n \"\"\"\n This function implements the Merge Sort algorithm to sort a list in ascending order.\n :param my_list: List of integers to sort\n :return: Sorte...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040595", "row_id": 40595, "seed_ids": "['Qwen2-72B-Instruct_88694']" }
0.548957
Filter_40595
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83541d085583b9281b6ef51864688a245c735d3e
beeddf0e69d65ead25881c5f169270eb557e37e1
v1.0
instruct
Filter
Filter_40604_I
Develop a Python program using BST (Binary Search Tree) to sort a given list of numbers. In addition to this, implement an algorithm to calculate the balance factor of the BST. If the BST is balanced, it should return True else False.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.value = key def insert(root, key): """Insert a new node with the given key in BST.""" if root is None: return TreeNode(key) if key < root.value: root.left = insert(root.left, ke...
import pytest from solution import TreeNode, insert, in_order_traversal, BST_sort, is_balanced, height def test_BST_sort_empty(): assert BST_sort([]) == [] def test_BST_sort_single_element(): assert BST_sort([5]) == [5] def test_BST_sort_multiple_elements(): assert BST_sort([5, 3, 8, 1, 4, 7, 9]) == [1, ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\nclass BinarySearchTree:\n def __init__(self):\n self.roo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040604", "row_id": 40604, "seed_ids": "['Qwen2-72B-Instruct_88706']" }
0.603474
Filter_40604
I
[ "insert", "in_order_traversal", "BST_sort", "height", "is_balanced" ]
5
[ [ "BST_sort", "in_order_traversal" ], [ "BST_sort", "insert" ], [ "is_balanced", "height" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c7e9142e2a5f60b03ec552d8e2c14231e8c5c616
17bb21a162d189088f541233d09f7d31d6192af5
v1.0
instruct
Filter
Filter_40625_I
Write a function to concatenate two strings in Python without using the in-built 'concat' function. Additionally, ensure your function can handle strings of any length and demonstrate its efficiency by comparing its runtime with that of the in-built function for large strings concatenation. Firstly, we create a functio...
def manual_concat(str1, str2): """ Concatenates two strings without using the in-built concatenation function. """ result = '' for char in str1: result += char for char in str2: result += char return result def time_comparison(str1, str2): """ Compares runtime of man...
from solution import manual_concat, time_comparison def test_manual_concat_basic(): assert manual_concat("Hello", "World") == "HelloWorld" assert manual_concat("", "World") == "World" assert manual_concat("Hello", "") == "Hello" assert manual_concat("", "") == "" def test_manual_concat_special_charact...
[ { "docstring": "Concatenates two strings without using the in-built concatenation function.", "function_declaration": "def manual_concat(str1, str2):", "function_name": "manual_concat", "parameter_list": "(str1, str2)" }, { "docstring": "Compares runtime of manual_concat function and in-buil...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def manual_concat(str1, str2):\n \"\"\"\n Concatenates two strings without using the in-built 'concat' function.\n \"\"\"\n result = \"\"\n for char in str1:\n result += ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040625", "row_id": 40625, "seed_ids": "['Qwen2-72B-Instruct_88737']" }
0.693458
Filter_40625
I
[ "manual_concat", "time_comparison" ]
2
[ [ "time_comparison", "manual_concat" ] ]
1
[]
false
[]
false
pytest
true
[]
true
073014b14480c803657d76a3fb4b29933317a413
5ddc8503a99aa3a4cd5ee8e46463cc4d3175fb88
v1.0
instruct
Filter
Filter_40654_I
Now, additional to calculating the edge cover number, I want the Python program to also identify the actual minimum edge cover set from the graph given as list of tuples e.g. G = [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e'), ('e', 'a')]. This should be implemented using a heuristic or an algorithm which you find fit...
def find_edge_cover(graph): """ Find the edge cover of a given graph. An Edge Cover of a graph is a set of edges such that every vertex of the graph is incident (connected) to at least one edge of the set. :param graph: List of tuples representing edges of a graph :return: List of edges represe...
import pytest from solution import find_edge_cover, is_valid_edge_cover def test_find_edge_cover(): graph = [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e'), ('e', 'a')] edge_cover = find_edge_cover(graph) assert is_valid_edge_cover(graph, edge_cover) def test_edge_cover_complete_graph(): graph = [('a'...
[ { "docstring": "Find the edge cover of a given graph.\nAn Edge Cover of a graph is a set of edges such that every vertex of the graph is incident (connected) to at least one edge of the set.\n\n:param graph: List of tuples representing edges of a graph\n:return: List of edges representing an edge cover of the g...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_edge_cover(graph):\n \"\"\"\n Find the edge cover of a given graph.\n An Edge Cover of a graph is a set of edges such that every vertex of the graph is incident (connected) t...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040654", "row_id": 40654, "seed_ids": "['Qwen2-72B-Instruct_88793']" }
0.433396
Filter_40654
I
[ "find_edge_cover", "get_all_vertices", "is_valid_edge_cover" ]
3
[ [ "find_edge_cover", "get_all_vertices" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ae788064e8b76b1dda5013b266b8b7a20a25727
73c44510e083beb952a7a2690a2ac2d2db761a65
v1.0
instruct
Filter
Filter_40659_I
Write two algorithms for sorting lists in Python: one that uses the quick sort technique, and another that uses the merge sort technique. Also, write a simple benchmark algorithm to compare the speed of the two sorting algorithms using time module.
def quicksort(arr): """Quicksort algorithm.""" if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] less = [x for x in arr if x < pivot] equal = [x for x in arr if x == pivot] greater = [x for x in arr if x > pivot] return quicksort(less) + equal + quicksort(greater) def merge_s...
from solution import quicksort, merge_sort, benchmark_sorting import random def test_quicksort(): assert quicksort([3, 6, 2, 7, 1, 8, 5, 4]) == [1, 2, 3, 4, 5, 6, 7, 8] assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert quicksort([]) == [] assert quicksort([2]) == [2] def test_merge_sort(): ...
[ { "docstring": "Quicksort algorithm.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef quick_sort(arr):\n \"\"\"\n Sorts a list using the quick sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n le...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040659", "row_id": 40659, "seed_ids": "['Qwen2-72B-Instruct_88802']" }
0.512248
Filter_40659
I
[ "quicksort", "merge_sort", "merge", "benchmark_sorting" ]
4
[ [ "benchmark_sorting", "merge_sort" ], [ "benchmark_sorting", "quicksort" ], [ "merge_sort", "merge" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3551cf588ab152af0611d408268e3f59dc6b9e7a
7175acc456079ba02bfd2677002c92e38f273181
v1.0
instruct
Filter
Filter_40680_I
Create a Python function that converts decimal numbers to ternary (base 3) representation for a given range.
def decimal_to_ternary(n): """ Convert a decimal number to its ternary (base 3) representation. """ if n == 0: return "0" ternary = '' positive = abs(n) while positive > 0: ternary += str(positive % 3) positive //= 3 if n < 0: ternary += '-' ...
from solution import decimal_to_ternary, convert_range_to_ternary def test_decimal_to_ternary(): assert decimal_to_ternary(0) == "0" assert decimal_to_ternary(1) == "1" assert decimal_to_ternary(2) == "2" assert decimal_to_ternary(3) == "10" assert decimal_to_ternary(10) == "101" assert decimal...
[ { "docstring": "Convert a decimal number to its ternary (base 3) representation.", "function_declaration": "def decimal_to_ternary(n):", "function_name": "decimal_to_ternary", "parameter_list": "(n)" }, { "docstring": "Converts a range of decimal numbers to their ternary representations.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def decimal_to_ternary(n):\n \"\"\"\n Converts a decimal number to its ternary (base 3) representation.\n \n Parameters:\n n (int): The decimal number to convert to ternary.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040680", "row_id": 40680, "seed_ids": "['Qwen2-72B-Instruct_88838']" }
0.641562
Filter_40680
I
[ "decimal_to_ternary", "convert_range_to_ternary" ]
2
[ [ "convert_range_to_ternary", "decimal_to_ternary" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1475d45c0e9f26863df8596eda77cdc56194faa1
e053b1e97b21559e13e718e3a8be97a03d07fc54
v1.0
instruct
Filter
Filter_40705_I
Write a Python function that returns the product of all prime numbers less than a given number 'n', inclusive of 1 and excluding 0 as a prime number. The function should filter out non-prime numbers from 1 up to 'n'. The function should include error handling for non-integer values and negative numbers.
def is_prime(num): """ Helper function to check if a number is prime. """ if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def product_of_primes(n): """ Returns the product of all prime numbers less th...
from solution import is_prime, product_of_primes def test_is_prime(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(17) == True assert is_prime(18) == False def test_product_of_primes...
[ { "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 product of all prime numbers less than a given number 'n',\ninclusive of 1 and excluding 0 as a...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(math.sqrt(num)) ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040705", "row_id": 40705, "seed_ids": "['Qwen2-72B-Instruct_88879']" }
0.67262
Filter_40705
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0c29c9c047e68b71a7bd199cdc6e3563a84aadc
1d64482f84aee2d83f546068b75d652cadfa745b
v1.0
instruct
Filter
Filter_40706_I
Imagine you're an innovator who can directly develop Fibonacci sequences. In Python, you write a sophisticated recursive function to fabricate this pattern. The code snippet is incomplete, and there's only a function shell and import statement present. Your mission is to proficiently conclude the parameters, function b...
def fibonacci(n): """ Returns the nth Fibonacci number. """ if n <= 0: raise ValueError('n must be a positive integer.') elif n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def verify_fibonacci_sequence(): """ Veri...
from solution import fibonacci, verify_fibonacci_sequence def test_fibonacci(): assert fibonacci(1) == 0 assert fibonacci(2) == 1 assert fibonacci(3) == 1 assert fibonacci(4) == 2 assert fibonacci(5) == 3 assert fibonacci(6) == 5 assert fibonacci(7) == 8 assert fibonacci(8) == 13 as...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Verifies the first 21 Fibonacci numbers.", "function_declaration": "def verify_fibonacci_sequence():", "function_n...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number using recursion.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n else:\n retu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040706", "row_id": 40706, "seed_ids": "['Qwen2-72B-Instruct_88880']" }
0.720466
Filter_40706
I
[ "fibonacci", "verify_fibonacci_sequence" ]
2
[ [ "verify_fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db411c5251325c0011dafcec7ecfa6f6ed172328
47abd99cecf563d6875a0c95faebfacbf90f4f26
v1.0
instruct
Filter
Filter_40729_I
code a while loop in python to find the first 10 prime numbers that are palindromic.
def is_prime(n): """Check if the number is a 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 is_palindromic(n): """Check if the...
from solution import is_prime, is_palindromic, find_first_10_palindromic_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(15) == False def test_is_palindromic(): assert is_palindromic(121) ...
[ { "docstring": "Check if the number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if the number is palindromic.", "function_declaration": "def is_palindromic(n):", "function_name": "is_palindrom...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if the number n is a prime number.\n \"\"\"\n if n < 2:\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": "00040729", "row_id": 40729, "seed_ids": "['Qwen2-72B-Instruct_88934']" }
0.561254
Filter_40729
I
[ "is_prime", "is_palindromic", "find_first_10_palindromic_primes" ]
3
[ [ "find_first_10_palindromic_primes", "is_palindromic" ], [ "find_first_10_palindromic_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bc1c65401e231234992468141d06292a8315256d
2b8626f6c37031c64fd891c0433850daab6b333f
v1.0
instruct
Filter
Filter_40806_I
Develop a recursive function in Python that calculates the factorial of a number. Additionally, create another function to measure the time required to calculate the factorial of a number using your recursive function. Also, determine how the time complexity of your recursive function changes with different input sizes...
import time def factorial(n): """ Returns the factorial of a given number n. Factorial of n (n!) is the product of all positive integers up to n. """ if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) def measure_time(n): """ Measures the time required to c...
from solution import factorial, measure_time def test_factorial_base_cases(): assert factorial(0) == 1 assert factorial(1) == 1 def test_factorial_regular_cases(): assert factorial(5) == 120 assert factorial(7) == 5040 def test_measure_time(): result, duration = measure_time(5) assert result ...
[ { "docstring": "Returns the factorial of a given number n.\nFactorial of n (n!) is the product of all positive integers up to n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Measures the time required to compute the f...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef factorial_recursive(n):\n \"\"\"\n Returns the factorial of n using recursion.\n \"\"\"\n if n == 0:\n return 1\n else:\n return n * factorial_r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040806", "row_id": 40806, "seed_ids": "['Qwen2-72B-Instruct_89055']" }
0.591645
Filter_40806
I
[ "factorial", "measure_time" ]
2
[ [ "measure_time", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
44a60b4105613ea49999b696c6fbbcb49ee63ad8
c57bac7bdf0538db4d9399194347e0badcb6ff1d
v1.0
instruct
Filter
Filter_40807_I
Define a generator in Python and explain how it works. Additionally, compare the generator to traditional list comprehension in terms of memory usage and performance.
def simple_generator(): """ A simple generator function that yields numbers from 1 to 3. """ yield 1 yield 2 yield 3 def compare_generator_and_list(): """ Compare generator and list memory usage and performance. Returns a tuple with memory usage of generator and list. The memor...
from solution import simple_generator, compare_generator_and_list, generator_vs_list def test_simple_generator(): gen = simple_generator() assert next(gen) == 1 assert next(gen) == 2 assert next(gen) == 3 def test_compare_generator_and_list(): gen_memory, gen_time, list_memory, list_time = compare...
[ { "docstring": "A simple generator function that yields numbers from 1 to 3.", "function_declaration": "def simple_generator():", "function_name": "simple_generator", "parameter_list": "()" }, { "docstring": "Compare generator and list memory usage and performance.\nReturns a tuple with memo...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def simple_generator():\n \"\"\"\n A simple generator that yields values from 1 to 3.\n \"\"\"\n yield 1\n yield 2\n yield 3\n\ndef generator_vs_list_comprehension():\n \"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040807", "row_id": 40807, "seed_ids": "['Qwen2-72B-Instruct_89056']" }
0.540105
Filter_40807
I
[ "simple_generator", "compare_generator_and_list", "generator_vs_list" ]
3
[ [ "generator_vs_list", "compare_generator_and_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bfe5b7cb47ff475d86ccab6cca5b3b5abbf95c8f
a2a17b69f49151db3a7d44df63e3c3cf42a7a272
v1.0
instruct
Filter
Filter_40815_I
Develop a segmentation model using Pytorch for segmenting an image into multiple classes. The model should be able to handle real-time video input from a webcam and perform accurate segmentation for each frame.
import torch import torch.nn as nn import torch.nn.functional as F import torchvision.transforms as transforms import cv2 import numpy as np class SimpleSegmentationModel(nn.Module): def __init__(self, n_classes): super(SimpleSegmentationModel, self).__init__() self.encoder = nn.Sequential( ...
import pytest import torch from solution import SimpleSegmentationModel, preprocess_frame, postprocess_frame def test_model_structure(): model = SimpleSegmentationModel(n_classes=10) input_tensor = torch.randn(1, 3, 128, 128) output_tensor = model(input_tensor) assert output_tensor.shape == (1, 10, 128...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torchvision.transforms as transforms\nimport cv2\nimport numpy as np\n\nclass SimpleSegmentationModel(nn.Module):\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00040815", "row_id": 40815, "seed_ids": "['Qwen2-72B-Instruct_89071']" }
0.443916
Filter_40815
I
[ "preprocess_frame", "postprocess_frame", "segment_video" ]
3
[ [ "segment_video", "postprocess_frame" ], [ "segment_video", "preprocess_frame" ] ]
2
[]
false
[ "SimpleSegmentationModel" ]
true
pytest
true
[ "cv2", "numpy", "torch", "torchvision" ]
false
8a7f3a6d8148f0c62769ae719c1bcd2613a765f2
29e7dd6d40fe169cc3afa41aa165d911693193f0
v1.0
instruct
Filter
Filter_40825_I
Propose code that generates a unique, random hex color with the constraint that no similar tone of color should be repeated i.e. no two hex colors should have same or similar hue, saturation, and lightness in the hue-saturation-lightness (HSL) color space.
import random used_colors = set() def generate_hex_color(): """ Generates a unique, random hex color that avoids similar tones being repeated. """ while True: # Generate random color hex_color = "#%06x" % random.randint(0, 0xFFFFFF) # Check if color is too similar to e...
from solution import generate_hex_color, used_colors, hex_to_hsl, is_hsl_similar def test_generate_unique_colors(): color1 = generate_hex_color() color2 = generate_hex_color() assert color1 != color2 assert not is_hsl_similar(hex_to_hsl(color1), hex_to_hsl(color2)) def test_no_similar_color(): col...
[ { "docstring": "Generates a unique, random hex color that avoids similar tones being repeated.", "function_declaration": "def generate_hex_color():", "function_name": "generate_hex_color", "parameter_list": "()" }, { "docstring": "Check if the hex_color is too similar to any of the already u...
[ 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 generate_unique_hex_color(existing_colors):\n \"\"\"\n Generates a unique, random hex color not similar in hue to any in existing_colors.\n\n Args:\n - existin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040825", "row_id": 40825, "seed_ids": "['Qwen2-72B-Instruct_89096']" }
0.580505
Filter_40825
I
[ "generate_hex_color", "is_similar", "hex_to_hsl", "is_hsl_similar" ]
4
[ [ "generate_hex_color", "is_similar" ], [ "is_similar", "hex_to_hsl" ], [ "is_similar", "is_hsl_similar" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b1d3f8751657984f3de5080cadad773bbdea60c8
1b167f2bf1db80b7331674467b7ea8184c88dfdc
v1.0
instruct
Filter
Filter_40829_I
Implement the optimizer program using PyTorch for the Elastic Stretch problem, ensuring to showcase how parameters such as learning rate, momentum, and weight decay influence the overall performance. Also, discuss their roles in the optimization process. Before getting into the code implementation, let's understand the...
import torch import torch.nn as nn import torch.optim as optim # Define a simple neural network model class SimpleNN(nn.Module): def __init__(self): super(SimpleNN, self).__init__() self.fc1 = nn.Linear(1, 10) self.fc2 = nn.Linear(10, 1) def forward(self, x): x = torch.relu(sel...
import pytest from solution import optimize_elastic_stretch def test_optimize_elastic_stretch_default_params(): model = optimize_elastic_stretch(0.01, 0.9, 0.001) # Test model parameters to ensure they have been optimized from their initial values for param in model.parameters(): assert param.requi...
[]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\n\nclass SimpleNN(nn.Module):\n def __init__(self):\n super(SimpleNN, self).__init__()\n self.fc1 = nn.Linear(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00040829", "row_id": 40829, "seed_ids": "['Qwen2-72B-Instruct_89101']" }
0.331499
Filter_40829
I
[ "create_data", "train", "optimize_elastic_stretch" ]
3
[ [ "optimize_elastic_stretch", "create_data" ], [ "optimize_elastic_stretch", "train" ] ]
2
[]
false
[ "SimpleNN" ]
true
pytest
true
[ "torch" ]
false
c59bf2c57b99ae81b5a1f76e3d6500b94c5b9d23
be47cf46e93083348d389e4bf343082d7cc9a276
v1.0
instruct
Filter
Filter_40834_I
Develop a Python algorithm implementing the Automated Clearing House (ACH) debiting process forcustomers' bank accounts while processing bulk payment files. The algorithm validates files format, fields accuracy and account's verification then returns the parsed movements correspondences to be debited into outcome files...
import re import csv def validate_account_number(account_number): """ Validates the account number format. Account numbers are assumed to be numeric with length 10 for this example. """ return re.match(r'^\d{10}$', account_number) is not None def validate_amount(amount): """ Validates that...
import tempfile import csv from solution import validate_account_number, validate_amount, parse_payment_file, process_debits def test_validate_account_number(): assert validate_account_number("1234567890") assert not validate_account_number("123456789") assert not validate_account_number("12345678901") ...
[ { "docstring": "Validates the account number format.\nAccount numbers are assumed to be numeric with length 10 for this example.", "function_declaration": "def validate_account_number(account_number):", "function_name": "validate_account_number", "parameter_list": "(account_number)" }, { "do...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef validate_file_format(file_path):\n \"\"\"\n Validates that the file is a CSV and returns True if valid, False otherwise.\n \"\"\"\n return file_path.endswith('.cs...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00040834", "row_id": 40834, "seed_ids": "['Qwen2-72B-Instruct_89120']" }
0.448598
Filter_40834
I
[ "validate_account_number", "validate_amount", "parse_payment_file", "process_debits" ]
4
[ [ "parse_payment_file", "validate_account_number" ], [ "parse_payment_file", "validate_amount" ] ]
2
[]
false
[]
false
pytest
true
[]
true
943f7e69db54be0b30bc31bfe214b07756fc9853
4f85e9f69d006c902cb3bacc51588be5906c764e