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_57591_I
Hello, Qwen! I heard you can generate code. Can you write a simple Python program that adds two numbers together and then prints the result?
def add_and_print(a, b): """ Adds two numbers and prints the result. """ result = add(a, b) print(result) def add(a, b): """ Returns the sum of a and b. """ return a + b
from io import StringIO import sys from solution import add_and_print, add def test_add_and_print_positive_numbers(): captured_output = StringIO() sys.stdout = captured_output add_and_print(2, 3) sys.stdout = sys.__stdout__ assert captured_output.getvalue().strip() == '5' def test_add_and_print_wi...
[ { "docstring": "Adds two numbers and prints the result.", "function_declaration": "def add_and_print(a, b):", "function_name": "add_and_print", "parameter_list": "(a, b)" }, { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add_numbers(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\nif __name__ == \"__main__\":\n num1 = float(input(\"Enter the first number: \"))\n nu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057591", "row_id": 57591, "seed_ids": "['Qwen2.5-72B-Instruct_116827']" }
0.577659
Filter_57591
I
[ "add_and_print", "add" ]
2
[ [ "add_and_print", "add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c3e2255896c6215ae535bb45cba4dd31a2933c2
79ba89d95105e10734e4216cc3d2c790c947c4c7
v1.0
instruct
Filter
Filter_57600_I
I need to sort a list of file names based on the version numbers in their names. How can I do this in Python?
import re from typing import List def extract_version_number(file_name: str) -> List[int]: """ Extracts version number from a file name. Example: 'file_v1.2.3.txt' -> [1, 2, 3] """ version_match = re.search(r'v(\d+(\.\d+)*)', file_name) if version_match: return [int(x) for x in version_...
import pytest from solution import sort_files_by_version def test_sort_files_by_version_simple(): files = ["file_v1.0.txt", "file_v2.0.txt", "file_v1.1.txt", "file_v1.0.1.txt"] sorted_files = ["file_v1.0.txt", "file_v1.0.1.txt", "file_v1.1.txt", "file_v2.0.txt"] assert sort_files_by_version(files) == sorte...
[ { "docstring": "Extracts version number from a file name.\nExample: 'file_v1.2.3.txt' -> [1, 2, 3]", "function_declaration": "def extract_version_number(file_name):", "function_name": "extract_version_number", "parameter_list": "(file_name)" }, { "docstring": "Compares two version numbers.\n...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef get_version_from_filename(filename):\n \"\"\"\n Extracts the version number from a filename using regex.\n For example, given 'file-2.10.txt', it extracts 2.10\n \...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057600", "row_id": 57600, "seed_ids": "['Qwen2.5-72B-Instruct_116842']" }
0.633209
Filter_57600
I
[ "extract_version_number", "compare_versions", "sort_files_by_version" ]
3
[ [ "sort_files_by_version", "extract_version_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
828e8e38a22aa8ff5ae4dee34fe93b13c2b240fa
8fa1ea074f81f85a589eec6aece708387b524a75
v1.0
instruct
Filter
Filter_57628_I
Can you provide code for training and inference of BERT model using PyTorch for text classification?
import torch from transformers import BertTokenizer, BertForSequenceClassification, AdamW from torch.utils.data import DataLoader, Dataset from sklearn.model_selection import train_test_split from tqdm import tqdm class TextDataset(Dataset): def __init__(self, texts, labels, tokenizer, max_len): self.texts...
import pytest from transformers import BertForSequenceClassification, BertTokenizer def test_load_model_for_training(): # Dummy data texts = ["This is a positive text.", "This is a negative text."] labels = [1, 0] try: model, tokenizer = train_bert_model(texts, labels, epochs=1) except Exc...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import torch\nfrom torch import nn\nfrom torch.optim import Adam\nfrom torch.utils.data import DataLoader, Dataset\nfrom transformers import BertTokenizer, BertForSequenceClassification\n\ncla...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057628", "row_id": 57628, "seed_ids": "['Qwen2.5-72B-Instruct_116890']" }
0.371592
Filter_57628
I
[ "train", "eval", "train_bert_model", "predict_texts" ]
4
[ [ "train_bert_model", "eval" ], [ "train_bert_model", "train" ] ]
2
[]
false
[ "TextDataset" ]
true
pytest
false
[ "sklearn", "torch", "tqdm", "transformers" ]
false
4f93c72c26fde1be2589fb3100cdb499441937a4
367aebed33479c17430eac68f4fa9a91ad1e0b5a
v1.0
instruct
Filter
Filter_57632_I
Describe the process of creating a basic calculator application in Python.
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b def calculator(operation, a, b): if operation == 'add': return add(a, b) elif operation == 'su...
import pytest from solution import add, subtract, multiply, divide, calculator def test_add(): assert add(2, 3) == 5 def test_subtract(): assert subtract(5, 3) == 2 def test_multiply(): assert multiply(4, 3) == 12 def test_divide(): assert divide(10, 2) == 5 def test_divide_by_zero(): with pyte...
[ { "docstring": null, "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_list": "(a, b)" }, { "docstring": null, "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef subtract(a, b):\n \"\"\"\n Returns the difference between a and b.\n \"\"\"\n retur...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057632", "row_id": 57632, "seed_ids": "['Qwen2.5-72B-Instruct_116897']" }
0.479276
Filter_57632
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
97a1f2c2191613d059d0dc9f33d0afc44c421874
75b588c853a4f058770d565729939453784c3ce0
v1.0
instruct
Filter
Filter_57641_I
Create a function in Python that accepts a list of integers and returns a new list where each element is the factorial of the original element. Use recursion for the factorial calculation and handle the case where the list might contain the number 0.
def factorial(n): """ Returns the factorial of a non-negative integer n using recursion. """ if n == 0: return 1 else: return n * factorial(n - 1) def list_factorials(input_list): """ Accepts a list of integers and returns a new list where each element is the factorial of th...
from solution import factorial, list_factorials def test_factorial_zero(): assert factorial(0) == 1 def test_factorial_positive_numbers(): assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 def test_list_factorials_single(): assert list_factor...
[ { "docstring": "Returns the factorial of a non-negative integer n using recursion.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Accepts a list of integers and returns a new list where each element is the factorial of ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)\n\ndef factorial_list(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057641", "row_id": 57641, "seed_ids": "['Qwen2.5-72B-Instruct_116913']" }
0.714931
Filter_57641
I
[ "factorial", "list_factorials" ]
2
[ [ "list_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fec1be8e32c762593934b32d097ae27aaad3f9ed
5bc3e04c995394c8b6ab569ba24f0606188c97e5
v1.0
instruct
Filter
Filter_57668_I
Can you help me write a code to simulate a simple game of rock, paper, scissors in Python? I want it to be a user vs. computer game where the user can input their choice, and the computer randomly selects its choice. The game should display the winner after each round and ask the user if they want to play again.
import random def get_computer_choice(): choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(user_choice, computer_choice): if user_choice == computer_choice: return 'draw' elif (user_choice == 'rock' and computer_choice == 'scissors') or \ (user...
import pytest from solution import get_computer_choice, determine_winner, play_round def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] for _ in range(10): # Test multiple times for randomness choice = get_computer_choice() assert choice in choices def test_determine_winn...
[ { "docstring": null, "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def determine_winner(user_choice, computer_choice):", "function_name": "determine_winner", "p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Returns the computer's choice for rock, paper, scissors.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors'])\n\nde...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057668", "row_id": 57668, "seed_ids": "['Qwen2.5-72B-Instruct_116958']" }
0.386135
Filter_57668
I
[ "get_computer_choice", "determine_winner", "play_round", "play_game" ]
4
[ [ "play_game", "play_round" ], [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6ff3a3dda9f5c8972aafcfd381eda9da3d91b3ad
e48d998ba9f365d0d99c6b2e83b03484ea80ee9c
v1.0
instruct
Filter
Filter_57675_I
How can I generate a Python program to create a simple calculator that can perform addition, subtraction, multiplication, and division? Can you also include a brief explanation of how the program works?
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b def calculator(a, b, operation): if operation == 'add': return add(a, b) elif operation == 'su...
from solution import add, subtract, multiply, divide, calculator def test_add(): assert add(1, 2) == 3 assert add(-1, -1) == -2 assert add(0, 0) == 0 def test_subtract(): assert subtract(2, 1) == 1 assert subtract(-1, -1) == 0 assert subtract(0, 0) == 0 def test_multiply(): assert multipl...
[ { "docstring": null, "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_list": "(a, b)" }, { "docstring": null, "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(x, y):\n return x + y\n\ndef subtract(x, y):\n return x - y\n\ndef multiply(x, y):\n return x * y\n\ndef divide(x, y):\n if y == 0:\n raise ValueError(\"Cannot divid...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057675", "row_id": 57675, "seed_ids": "['Qwen2.5-72B-Instruct_116972']" }
0.558278
Filter_57675
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
f71c7e90a2ff943bbb2a76f764a0a0ce4d220fa2
8ef51011188d775b8f21b3ff643d095c75f94835
v1.0
instruct
Filter
Filter_57680_I
How can I create a simple quiz game in Python that asks the user five math questions and then prints out the score at the end?
def ask_question(prompt, correct_answer): """ Asks a question and returns True if the answer is correct, otherwise False. """ user_answer = input(prompt) return user_answer.strip() == str(correct_answer) def run_quiz(): """ Runs a simple math quiz with five questions and prints the final sc...
import builtins import pytest from solution import ask_question, run_quiz def test_ask_question_correct_answer(monkeypatch): monkeypatch.setattr('builtins.input', lambda _: '8') assert ask_question("What is 5 + 3? ", 8) == True def test_ask_question_incorrect_answer(monkeypatch): monkeypatch.setattr('bui...
[ { "docstring": "Asks a question and returns True if the answer is correct, otherwise False.", "function_declaration": "def ask_question(prompt, correct_answer):", "function_name": "ask_question", "parameter_list": "(prompt, correct_answer)" }, { "docstring": "Runs a simple math quiz with fiv...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def ask_question(prompt, correct_answer):\n \"\"\"\n Asks a question and returns True if the answer is correct, otherwise False.\n \"\"\"\n user_answer = input(prompt)\n return ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00057680", "row_id": 57680, "seed_ids": "['Qwen2.5-72B-Instruct_116980']" }
0.48599
Filter_57680
I
[ "ask_question", "run_quiz" ]
2
[ [ "run_quiz", "ask_question" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41d390f390a479221b132581cfb2a4c35d44fa7a
c7bbd4a79655283a56f11d89080c29d01d835390
v1.0
instruct
Filter
Filter_57691_I
Write a Python program that takes a list of integers and returns the list in a random order. The program should not use any built-in functions for shuffling, such as `random.shuffle`. Instead, implement the Fisher-Yates algorithm to ensure that each permutation is equally likely. Also, include a simple check function t...
import random def fisher_yates_shuffle(nums): """ Shuffles the list of integers in place using the Fisher-Yates algorithm. """ n = len(nums) for i in range(n-1, 0, -1): j = random.randint(0, i) nums[i], nums[j] = nums[j], nums[i] return nums def check_shuffle(nums, iterations=1...
from solution import fisher_yates_shuffle, check_shuffle from collections import defaultdict def test_fisher_yates_shuffle_does_not_change_length(): nums = [1, 2, 3, 4, 5] original_length = len(nums) shuffled = fisher_yates_shuffle(nums[:]) assert len(shuffled) == original_length def test_fisher_yates...
[ { "docstring": "Shuffles the list of integers in place using the Fisher-Yates algorithm.", "function_declaration": "def fisher_yates_shuffle(nums):", "function_name": "fisher_yates_shuffle", "parameter_list": "(nums)" }, { "docstring": "Shuffles the input list multiple times and tracks the f...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef fisher_yates_shuffle(nums):\n \"\"\"\n Shuffles the list of integers in place using the Fisher-Yates algorithm.\n \"\"\"\n n = len(nums)\n for i in range(n-...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00057691", "row_id": 57691, "seed_ids": "['Qwen2.5-72B-Instruct_116998']" }
0.590173
Filter_57691
I
[ "fisher_yates_shuffle", "check_shuffle" ]
2
[ [ "check_shuffle", "fisher_yates_shuffle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f2c18f1f9b657f2adb449a4bd5333daec25fd3be
4e81aed4a22b5ddeb42d80c2906947156f3b0735
v1.0
instruct
Filter
Filter_57707_I
Write a program to implement a simple text-based hangman game in Python. The game should randomly pick a word from a predefined list, and the player has to guess the word letter by letter. The player has 6 chances to guess the word, and the program should display the state of the current word (with unguessed letters hi...
import random def pick_random_word(word_list): """ Picks a random word from the provided list of words. """ return random.choice(word_list) def display_word(word, guessed_letters): """ Returns the current state of the word to display, with unguessed letters as underscores. """ return '...
from solution import pick_random_word, display_word, hangman def test_pick_random_word(): word_list = ['apple', 'banana', 'grape', 'orange', 'strawberry'] word = pick_random_word(word_list) assert word in word_list def test_display_word_partial(): word = "apple" guessed_letters = {'a', 'p'} as...
[ { "docstring": "Picks a random word from the provided list of words.", "function_declaration": "def pick_random_word(word_list):", "function_name": "pick_random_word", "parameter_list": "(word_list)" }, { "docstring": "Returns the current state of the word to display, with unguessed letters ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef pick_random_word(word_list):\n \"\"\"\n Pick a random word from a predefined list.\n \"\"\"\n return random.choice(word_list)\n\ndef display_current_state(secr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057707", "row_id": 57707, "seed_ids": "['Qwen2.5-72B-Instruct_117020']" }
0.535163
Filter_57707
I
[ "pick_random_word", "display_word", "hangman" ]
3
[ [ "hangman", "display_word" ], [ "hangman", "pick_random_word" ] ]
2
[]
false
[]
false
pytest
true
[]
true
610958d5be9e4c16e6b9c80621a726506533182a
c2cd4ad0cc93be038d852dda6ca79a4efcb8644e
v1.0
instruct
Filter
Filter_57723_I
Write an algorithm in Python that implements a simple neural network using numpy for training a binary classifier. The neural network should have one input layer, one hidden layer with 3 neurons, and one output layer. Use the sigmoid activation function. The training data consists of 4 input features and corresponding ...
import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): return x * (1 - x) def train_neural_network(X, y, epochs, learning_rate): np.random.seed(1) # Initialize weights input_layer_size = X.shape[1] hidden_layer_size = 3 output_layer_size = 1 weight...
import numpy as np from solution import train_neural_network, predict, sigmoid def test_train_neural_network_single_iteration(): X = np.array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]]) y = np.array([[0], [1], [1], [0]]) epochs = 1 learn...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(x):\n \"\"\"\n Sigmoid activation function.\n \"\"\"\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n \"\"\"\n Derivative of th...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057723", "row_id": 57723, "seed_ids": "['Qwen2.5-72B-Instruct_117058']" }
0.476095
Filter_57723
I
[ "sigmoid", "sigmoid_derivative", "train_neural_network", "predict" ]
4
[ [ "predict", "sigmoid" ], [ "train_neural_network", "sigmoid" ], [ "train_neural_network", "sigmoid_derivative" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy" ]
false
227e0f59e84fb76cea8b22bbfbab452981f94a2c
4317c8be43f0ac17a47e79d97aea21d3bc65d4a3
v1.0
instruct
Filter
Filter_57753_I
Write Python code to create a function that calculates the product of all elements in a list of integers. Ensure your code is self-contained, including all necessary imports, and add a docstring to explain the functionality of your function. Additionally, implement a check function with provided data points to verify t...
def product_of_list(lst): """ Returns the product of all elements in a list of integers. Parameters: lst (list of int): A list containing integers. Returns: int: The product of all elements in the list. """ product = 1 for num in lst: product *= num return product # Ex...
from solution import product_of_list def test_product_of_list(): assert product_of_list([1, 2, 3, 4]) == 24 def test_product_with_zero(): assert product_of_list([0, 1, 2, 3]) == 0 def test_product_of_negative_values(): assert product_of_list([-1, 1, -1, 1]) == 1 def test_product_of_single_element_list()...
[ { "docstring": "Returns the product of all elements in a list of integers.\n\nParameters:\nlst (list of int): A list containing integers.\n\nReturns:\nint: The product of all elements in the list.", "function_declaration": "def product_of_list(lst):", "function_name": "product_of_list", "parameter_l...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def product_of_list(numbers):\n \"\"\"\n Returns the product of all elements in a list of integers.\n \n Parameters:\n numbers (list): List of integers\n\n Returns:\n int:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057753", "row_id": 57753, "seed_ids": "['Qwen2.5-72B-Instruct_117109']" }
0.738901
Filter_57753
I
[ "product_of_list", "check_solution" ]
2
[ [ "check_solution", "product_of_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea569a3afb24c8588b4f3db857be544d9a9e2f7b
f190194c6676c9306ee30f2600521ba380afa523
v1.0
instruct
Filter
Filter_57756_I
Can you write a Python function that finds the smallest prime number greater than or equal to a given positive integer? Make sure your function is efficient and can handle large inputs. Also, include a simple way to test your function with a few examples.
def is_prime(num): """ Helper function to check if a number is prime. Returns True if num is a prime number, otherwise False. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: ...
from solution import next_prime def test_next_prime_small_numbers(): assert next_prime(2) == 2 assert next_prime(3) == 3 assert next_prime(4) == 5 def test_next_prime_larger_numbers(): assert next_prime(14) == 17 assert next_prime(20) == 23 def test_next_prime_edge_cases(): assert next_prime(...
[ { "docstring": "Helper function to check if a number is prime.\nReturns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Function to find the smallest prime number greater...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return Fa...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00057756", "row_id": 57756, "seed_ids": "['Qwen2.5-72B-Instruct_117113']" }
0.63659
Filter_57756
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a42c1cba2ce72cc5414f79219e85980006af400f
8e207cf9ac610b329b345a0ba442ab0add2c37a0
v1.0
instruct
Filter
Filter_57761_I
Write a Python program to convert temperatures from Celsius to Fahrenheit and display a table of temperatures from 0°C to 100°C in increments of 10, along with their Fahrenheit equivalents.
def celsius_to_fahrenheit(celsius): """ Converts Celsius temperature to Fahrenheit. Args: celsius (float): Temperature in Celsius. Returns: float: Temperature in Fahrenheit. """ return (celsius * 9/5) + 32 def generate_temperature_table(): """ Generates a table of temperat...
from solution import celsius_to_fahrenheit, generate_temperature_table def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(50) == 122 assert celsius_to_fahrenheit(-40) == -40 def test_generate_temperature_table()...
[ { "docstring": "Converts Celsius temperature to Fahrenheit.\n\nArgs:\ncelsius (float): Temperature in Celsius.\n\nReturns:\nfloat: Temperature in Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts a temperature from Celsius to Fahrenheit.\n \n Parameters:\n celsius (float): The temperature in Celsius.\n\n Retu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057761", "row_id": 57761, "seed_ids": "['Qwen2.5-72B-Instruct_117124']" }
0.517033
Filter_57761
I
[ "celsius_to_fahrenheit", "generate_temperature_table" ]
2
[ [ "generate_temperature_table", "celsius_to_fahrenheit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b568fa974a969327171247bd3f04126fd5bdf32f
5b84b6ea2faa1fa96ceffa21c18aa5d03f85c9aa
v1.0
instruct
Filter
Filter_57762_I
I need to create a Python script that reads two lists of numbers from two separate CSV files and outputs the sum of the numbers in each list. Can you help me with that?
import csv def read_numbers_from_csv(file_path): """ Reads numbers from a CSV file and returns them as a list of integers. """ numbers = [] with open(file_path, mode='r', newline='') as file: reader = csv.reader(file) for row in reader: for number in row: ...
import os from solution import read_numbers_from_csv, sum_of_numbers_in_csv # Create temporary CSV files for testing TEMP_CSV_1 = 'temp_test_file_1.csv' TEMP_CSV_2 = 'temp_test_file_2.csv' def setup_module(module): with open(TEMP_CSV_1, mode='w', newline='') as file: writer = csv.writer(file) writ...
[ { "docstring": "Reads numbers from a CSV file and returns them as a list of integers.", "function_declaration": "def read_numbers_from_csv(file_path):", "function_name": "read_numbers_from_csv", "parameter_list": "(file_path)" }, { "docstring": "Reads numbers from a CSV file and returns the ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef read_numbers_from_csv(file_path):\n \"\"\"\n Reads a list of numbers from a CSV file.\n \n Args:\n - file_path (str): The path to the CSV file.\n\n Returns:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057762", "row_id": 57762, "seed_ids": "['Qwen2.5-72B-Instruct_117126']" }
0.518686
Filter_57762
I
[ "read_numbers_from_csv", "sum_of_numbers_in_csv" ]
2
[ [ "sum_of_numbers_in_csv", "read_numbers_from_csv" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4597146b4815485eac9fba4576a18ea31bc1cc1a
cbb56953dd09c13721be399e4ece7bd4f5ee5e35
v1.0
instruct
Filter
Filter_57764_I
Create a Python program to implement a simple game of Rock, Paper, Scissors, where the user plays against the computer. The game should allow multiple rounds and the user can choose when to stop playing. The final score should be displayed at the end. The game should handle invalid inputs gracefully, by asking the user...
import random def get_computer_choice(): return random.choice(['rock', 'paper', 'scissors']) def get_user_choice(): choice = input("Enter your choice (rock, paper, scissors): ").lower() while choice not in ['rock', 'paper', 'scissors']: print("Invalid choice. Please try again.") choice = i...
from solution import determine_winner, get_computer_choice def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'user' assert determine_winner('rock', 'paper') == 'computer' assert determine_winner('rock', 'rock') == 'tie' assert determine_winner('paper', 'rock') == 'user' as...
[ { "docstring": null, "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_user_choice():", "function_name": "get_user_choice", "parameter_list": "()" }, { ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n return random.choice(['rock', 'paper', 'scissors'])\n\ndef get_user_choice():\n choice = input(\"Enter your choice (rock, paper, scissors): ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057764", "row_id": 57764, "seed_ids": "['Qwen2.5-72B-Instruct_117131']" }
0.504365
Filter_57764
I
[ "get_computer_choice", "get_user_choice", "determine_winner", "display_score", "play_game" ]
5
[ [ "play_game", "determine_winner" ], [ "play_game", "display_score" ], [ "play_game", "get_computer_choice" ], [ "play_game", "get_user_choice" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0a1f7ef43b75af4d761e39acedfbfb4dca747068
39b0c05d1144a19bf437a1acce14df15d2929440
v1.0
instruct
Filter
Filter_57781_I
Can you assist me in developing a basic Python script that monitors a directory for any new files and automatically compresses them using gzip? I'm looking for a solution that is simple to understand and implement.
import os import gzip import shutil import time def compress_file(file_path): """ Compresses a file using gzip. """ with open(file_path, 'rb') as f_in, gzip.open(file_path + '.gz', 'wb') as f_out: shutil.copyfileobj(f_in, f_out) os.remove(file_path) def monitor_directory(directory, already...
import os import gzip from solution import compress_file, monitor_directory def test_compress_file(tmpdir): file_path = os.path.join(tmpdir, "testfile.txt") with open(file_path, "w") as f: f.write("This is a test file") compress_file(file_path) assert not os.path.isfile(file_path) assert ...
[ { "docstring": "Compresses a file using gzip.", "function_declaration": "def compress_file(file_path):", "function_name": "compress_file", "parameter_list": "(file_path)" }, { "docstring": "Monitors a directory for any new files and compresses them using gzip.", "function_declaration": "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport time\nimport gzip\nimport shutil\n\ndef compress_file(file_path):\n \"\"\"\n Compresses the given file using gzip.\n \"\"\"\n with open(file_path, 'rb') as f_in:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057781", "row_id": 57781, "seed_ids": "['Qwen2.5-72B-Instruct_117167']" }
0.645896
Filter_57781
I
[ "compress_file", "monitor_directory", "start_monitoring" ]
3
[ [ "monitor_directory", "compress_file" ], [ "start_monitoring", "monitor_directory" ] ]
2
[]
false
[]
false
pytest
true
[]
true
568cebbab571abafe19e5370d63599dad1e51eec
27ed1f2363dd9249b014300f2b566b48000443e3
v1.0
instruct
Filter
Filter_57788_I
Implement a basic version of Conway's Game of Life in Python. Make sure the implementation includes the ability to set an initial state and evolve the grid over a specified number of generations. For simplicity, assume a fixed grid size of 10x10. The initial state can be provided as a 10x10 list of lists, where each el...
def get_neighbors(x, y, grid): neighbors = [-1, 0, 1] count = 0 for i in neighbors: for j in neighbors: if not (i == 0 and j == 0): if 0 <= x + i < 10 and 0 <= y + j < 10: count += grid[x + i][y + j] return count def evol...
from solution import conways_game_of_life def test_initial_state(): initial_state = [[0 for _ in range(10)] for _ in range(10)] result = conways_game_of_life(initial_state, 1) assert result == initial_state def test_single_cell_dies(): initial_state = [[0 for _ in range(10)] for _ in range(10)] in...
[ { "docstring": null, "function_declaration": "def get_neighbors(x, y, grid):", "function_name": "get_neighbors", "parameter_list": "(x, y, grid)" }, { "docstring": null, "function_declaration": "def evolve_cell(x, y, grid):", "function_name": "evolve_cell", "parameter_list": "(x,...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_neighbors(grid, row, col):\n directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]\n count = 0\n for dr, dc in directions:\n nr, nc = ro...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057788", "row_id": 57788, "seed_ids": "['Qwen2.5-72B-Instruct_117181']" }
0.416686
Filter_57788
I
[ "get_neighbors", "evolve_cell", "evolve_grid", "conways_game_of_life" ]
4
[ [ "conways_game_of_life", "evolve_grid" ], [ "evolve_cell", "get_neighbors" ], [ "evolve_grid", "evolve_cell" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4326f534d35e0408055a2ba36c150e071f9fad44
0f767b01b04d90f13151269d20b485150101b502
v1.0
instruct
Filter
Filter_57792_I
I need to make a Python script for a system that automatically analyzes shipments of products and calculates the carbon footprint of the delivery based on the distance traveled and the weight of the shipment. The results should be output in a CSV file with the shipment ID, the distance traveled, the weight of the shipm...
import csv # Constants EMISSION_FACTOR = 0.005 # Example emission factor (kg CO2 per ton-km) def calculate_carbon_footprint(distance, weight): """ Calculate the carbon footprint of a shipment. :param distance: Distance traveled in kilometers :param weight: Weight of the shipment in tons :ret...
from solution import calculate_carbon_footprint, generate_report import os import csv def test_calculate_carbon_footprint(): assert calculate_carbon_footprint(100, 1) == 0.5 assert calculate_carbon_footprint(200, 2) == 2.0 assert calculate_carbon_footprint(50, 0.5) == 0.125 def test_generate_report(tmpdir...
[ { "docstring": "Calculate the carbon footprint of a shipment.\n\n:param distance: Distance traveled in kilometers\n:param weight: Weight of the shipment in tons\n:return: Carbon footprint in kg CO2", "function_declaration": "def calculate_carbon_footprint(distance, weight):", "function_name": "calculate...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef calculate_carbon_footprint(distance_km, weight_kg):\n \"\"\"\n Calculates the carbon footprint of a shipment based on distance traveled and weight.\n Assumes a carbo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057792", "row_id": 57792, "seed_ids": "['Qwen2.5-72B-Instruct_117189']" }
0.477923
Filter_57792
I
[ "calculate_carbon_footprint", "generate_report" ]
2
[ [ "generate_report", "calculate_carbon_footprint" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2aa0d26805cff2e426b5ae9b76ee239d78d92230
8c5678cfa0d569e47ea4acf997cf5ae6894ad927
v1.0
instruct
Filter
Filter_57802_I
Compose a Python program to generate a list of prime numbers using the Sieve of Eratosthenes algorithm, and also include a function to check if a given number is a prime. Your program should be optimized for efficiency and should handle numbers up to 1,000,000 efficiently. Additionally, provide a function to find the l...
def sieve_of_eratosthenes(limit): """ Generate a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm. """ primes = [] is_prime = [True] * (limit + 1) p = 2 while p * p <= limit: if is_prime[p]: for i in range(p * p, limit + 1, p): ...
from solution import sieve_of_eratosthenes, is_prime, largest_prime_less_than def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(1) == [] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_is_prime(): assert is_prime(2...
[ { "docstring": "Generate a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Check if the given number ...
[ 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 \"\"\"\n Generate a list of prime numbers up to 'limit' using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (limit + 1)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057802", "row_id": 57802, "seed_ids": "['Qwen2.5-72B-Instruct_117204']" }
0.663934
Filter_57802
I
[ "sieve_of_eratosthenes", "is_prime", "largest_prime_less_than" ]
3
[ [ "largest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5cdd56e4d5aa5ba9f6e8b0bce1f2b711d5b08678
aa323a392dcd824ca0e0a8f31f88f8b18f29ad20
v1.0
instruct
Filter
Filter_57850_I
Write a Python script that listens to a specific port and logs all incoming requests to a file, including the request data and timestamp. The script should use the Python `socket` library. Additionally, include a simple function to read and display the log file.
import socket import datetime LOG_FILE = 'server_logs.txt' def log_request(data): with open(LOG_FILE, 'a') as f: timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') f.write(f"[{timestamp}] {data}\n") def start_server(host='0.0.0.0', port=8080): server_socket = socket.socket(sock...
import os import socket import threading import time from solution import start_server, log_request, read_log, LOG_FILE def test_server_logging(): # Start the server in a separate thread server_thread = threading.Thread(target=start_server, args=('127.0.0.1', 8080), daemon=True) server_thread.start() ...
[ { "docstring": null, "function_declaration": "def log_request(data):", "function_name": "log_request", "parameter_list": "(data)" }, { "docstring": null, "function_declaration": "def start_server(host='0.0.0.0', port=8080):", "function_name": "start_server", "parameter_list": "(h...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import socket\nimport datetime\n\ndef log_request(data):\n timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')\n with open(\"requests_log.txt\", \"a\") as log_file:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057850", "row_id": 57850, "seed_ids": "['Qwen2.5-72B-Instruct_117279']" }
0.527869
Filter_57850
I
[ "log_request", "start_server", "read_log" ]
3
[ [ "start_server", "log_request" ] ]
1
[]
false
[]
false
pytest
true
[]
true
33ccf39c6d6573a398290dbe163643f56be83c7a
28fb260ca5537c30f87c391c74a60c96b2beab1a
v1.0
instruct
Filter
Filter_57862_I
How can I automate a computer to send an email whenever the CPU usage exceeds 80% using Python?
import smtplib import psutil from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def send_email(cpu_usage): """ Send an email if the CPU usage exceeds 80%. """ sender_email = "your_email@gmail.com" receiver_email = "receiver_email@gmail.com" password = "your_pass...
import smtplib import psutil from unittest.mock import patch from solution import send_email, monitor_cpu_usage def test_send_email(monkeypatch): class MockSMTP: def __init__(self, *args, **kwargs): pass def starttls(self): pass def login(self, *args, **kwargs): ...
[ { "docstring": "Send an email if the CPU usage exceeds 80%.", "function_declaration": "def send_email(cpu_usage):", "function_name": "send_email", "parameter_list": "(cpu_usage)" }, { "docstring": "Monitor the CPU usage and send an email if it exceeds 80%.", "function_declaration": "def ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import psutil\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef check_cpu_usage(threshold=80):\n \"\"\"\n Check the current CPU...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057862", "row_id": 57862, "seed_ids": "['Qwen2.5-72B-Instruct_117296']" }
0.603938
Filter_57862
I
[ "send_email", "monitor_cpu_usage" ]
2
[ [ "monitor_cpu_usage", "send_email" ] ]
1
[]
false
[]
false
pytest
true
[ "psutil" ]
false
47e21dad5c0bd881bad4eba107066fbe541fbe00
908801643093985de629e99504735c35eac8f01f
v1.0
instruct
Filter
Filter_57876_I
Can you assist me in generating a Python script that automates the process of checking a website's loading time and records it in a CSV file? I want to run this script periodically to monitor the website's performance over time.
import requests import csv import time from datetime import datetime def check_website_loading_time(url): """ Checks the website's loading time and returns it. """ start_time = time.time() response = requests.get(url) end_time = time.time() if response.status_code != 200: raise Exc...
import pytest from solution import check_website_loading_time, record_loading_time import os def mock_check_website_loading_time(url): """ Returns a mock loading time. """ return 1.23 # Test for check_website_loading_time def test_check_website_loading_time(monkeypatch): # Mock a real URL response...
[ { "docstring": "Checks the website's loading time and returns it.", "function_declaration": "def check_website_loading_time(url):", "function_name": "check_website_loading_time", "parameter_list": "(url)" }, { "docstring": "Records the website's loading time to a CSV file.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nimport time\nimport requests\nfrom datetime import datetime\n\ndef check_website_loading_time(url, timeout=10):\n \"\"\"\n Checks the loading time of the provided URL.\n A...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00057876", "row_id": 57876, "seed_ids": "['Qwen2.5-72B-Instruct_117321']" }
0.512694
Filter_57876
I
[ "check_website_loading_time", "record_loading_time" ]
2
[ [ "record_loading_time", "check_website_loading_time" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
f9a9ea606ad142cc06aac3a39e7112c0f4ed5275
51e039aecd9194a878eb7bda0f3b4d8d7ec8563f
v1.0
instruct
Filter
Filter_57920_I
Create a multi-step Python script that sucks out the asteroid from the terrestrial atmosphere and pushes it back into space to protect Earth. While being creative, ensure the script is plausible within the realm of current technology. You can assume the existence of a fictional spacecraft capable of high precision mane...
def deploy_spacecraft(spacecraft): """ Simulates the deployment of the spacecraft into space. """ print(f"{spacecraft} has been deployed.") def approach_asteroid(spacecraft, asteroid): """ Simulates the spacecraft approaching the asteroid. """ print(f"{spacecraft} is approaching the ast...
def test_deploy_spacecraft(capfd): deploy_spacecraft("SpaceX_BFR") captured = capfd.readouterr() assert "SpaceX_BFR has been deployed." in captured.out def test_approach_asteroid(capfd): approach_asteroid("SpaceX_BFR", "Asteroid_123") captured = capfd.readouterr() assert "SpaceX_BFR is approach...
[ { "docstring": "Simulates the deployment of the spacecraft into space.", "function_declaration": "def deploy_spacecraft(spacecraft):", "function_name": "deploy_spacecraft", "parameter_list": "(spacecraft)" }, { "docstring": "Simulates the spacecraft approaching the asteroid.", "function_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\nclass SpaceMission:\n def __init__(self, asteroid_mass, asteroid_velocity, spacecraft_power, transfer_velocity):\n \"\"\"\n Initialize the space mission paramet...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057920", "row_id": 57920, "seed_ids": "['Qwen2.5-72B-Instruct_117402']" }
0.347256
Filter_57920
I
[ "deploy_spacecraft", "approach_asteroid", "capture_asteroid", "adjust_trajectory", "release_asteroid", "protect_earth_from_asteroid" ]
6
[ [ "protect_earth_from_asteroid", "adjust_trajectory" ], [ "protect_earth_from_asteroid", "approach_asteroid" ], [ "protect_earth_from_asteroid", "capture_asteroid" ], [ "protect_earth_from_asteroid", "deploy_spacecraft" ], [ "protect_earth_from_asteroid", "rel...
5
[]
false
[]
false
pytest
false
[]
true
eb5658427e8b3f5f0e1f65af9f229c104d309e9a
6f68b7e99e4e05b73c285bdc79a08c95c33f8bea
v1.0
instruct
Filter
Filter_57933_I
Design an algorithm to sort a list of numbers using a Heap Sort method.
def heapify(arr, n, i): """ To heapify a subtree rooted with node i which is an index in arr[]. n is size of heap. """ largest = i # Initialize largest as root left = 2 * i + 1 # left = 2*i + 1 right = 2 * i + 2 # right = 2*i + 2 # See if left child of root exists and is greater tha...
from solution import heap_sort def test_heap_sort_empty(): assert heap_sort([]) == [] def test_heap_sort_single(): assert heap_sort([1]) == [1] def test_heap_sort_sorted(): assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heap_sort_reverse(): assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, ...
[ { "docstring": "To heapify a subtree rooted with node i which is an index in arr[].\nn is size of heap.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Main function to do heap sort.", "function_declarati...
[ 0, 1, 1 ]
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 Helper function to turn a subtree rooted with node i into a max heap,\n assuming the subtrees are already max heaps.\n \"\"\"\n largest = i\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00057933", "row_id": 57933, "seed_ids": "['Qwen2.5-72B-Instruct_117423']" }
0.843684
Filter_57933
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f6a96fa98ef80903e8032c382c2e7cb62d4998e
96ffc359ae1fc7244252710ec894326990c61f04
v1.0
instruct
Filter
Filter_58009_I
Design a Python function to produce all torsion angles for a given protein chain. The function should take as input the protein atoms, a list of dictionaries representing the atoms, and their order in the list should represent the residue connectivity. Each dictionary contains the atom's name (like 'N', 'CA', 'C', 'O')...
import math import numpy as np def calculate_dihedral(p0, p1, p2, p3): """ Calculate the dihedral angle (torsion angle) between four points (p0, p1, p2, p3). Using numpy to help with vector algebra. """ def unit_vector(vector): """ Returns the unit vector of the input vector. """ re...
from solution import calculate_torsion_angles def test_calculate_torsion_angles(): atoms = [ # Residue 1 {'name': 'N', 'coords': [1.0, 1.0, 1.0], 'residue': 'Res1'}, {'name': 'CA', 'coords': [2.0, 2.0, 2.0], 'residue': 'Res1'}, {'name': 'C', 'coords': [2.5, 2.5, 2.5], 'residue': 'Re...
[ { "docstring": "Calculate the dihedral angle (torsion angle) between four points (p0, p1, p2, p3).\nUsing numpy to help with vector algebra.", "function_declaration": "def calculate_dihedral(p0, p1, p2, p3):", "function_name": "calculate_dihedral", "parameter_list": "(p0, p1, p2, p3)" }, { "...
[ 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 numpy as np\n\ndef calculate_dihedral(p0, p1, p2, p3):\n \"\"\"\n Calculate the dihedral angle (torsion angle) between four points (p0, p1, p2, p3).\n Using numpy ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058009", "row_id": 58009, "seed_ids": "['Qwen2.5-72B-Instruct_117578']" }
0.407934
Filter_58009
I
[ "calculate_dihedral", "calculate_torsion_angles" ]
2
[ [ "calculate_torsion_angles", "calculate_dihedral" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
2ed0cc3aead38de8ca58ca613151d959f3a247db
406039a2215f503490f11af91052dc4bf41c63d3
v1.0
instruct
Filter
Filter_58020_I
Write a piece of Python code that takes a string and an integer as input, and repeats the string input n times, but each repetition is reversed. The reversed string should not reverse special characters and digits, only the letters. For example, 'a1b2c!d' with n = 2 would give 'd1c2b!a d1c2b!a'.
def reverse_string(s): """ Reverses the letters in the input string while keeping special characters and digits in their original positions. """ chars = list(s) letters = [c for c in chars if c.isalpha()] letters.reverse() it = iter(letters) result = [next(it) if c.isalpha() els...
from solution import reverse_string, repeat_reversed_string def test_reverse_string(): assert reverse_string('a1b2c!d') == 'd1c2b!a' assert reverse_string('abcd') == 'dcba' assert reverse_string('a1b1') == 'b1a1' assert reverse_string('123!abc$') == '123!cba$' def test_repeat_reversed_string(): as...
[ { "docstring": "Reverses the letters in the input string while keeping special characters\nand digits in their original positions.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Repeats the input string n time...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_string(s):\n \"\"\"\n Reverses the letters in the input string while keeping special characters\n and digits in their original positions.\n \"\"\"\n chars = list(s)\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058020", "row_id": 58020, "seed_ids": "['Qwen2.5-72B-Instruct_117598']" }
0.636002
Filter_58020
I
[ "reverse_string", "repeat_reversed_string" ]
2
[ [ "repeat_reversed_string", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0a97b02fd6ea71eabbb041c3ba72f1e0d6a3cb5
5a590133bb50e1137d30aeeee59a32e7d74ea08e
v1.0
instruct
Filter
Filter_58023_I
Write a Python function `prime_product` that takes an integer `n` and returns the product of `n` and the smallest prime number greater than `n`. Ensure the function is well-documented and your solution is efficient. Additionally, include a check function `test_prime_product` to verify your implementation with a few tes...
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 next_prime(n): """Helper function to find the smallest prime number greater than n.""" ...
from solution import prime_product def test_prime_product_5(): assert prime_product(5) == 5 * 7 # 7 is the smallest prime > 5 def test_prime_product_11(): assert prime_product(11) == 11 * 13 # 13 is the smallest prime > 11 def test_prime_product_20(): assert prime_product(20) == 20 * 23 # 23 is the sm...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Helper function to find the smallest prime number greater than n.", "function_declaration": "def next_p...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058023", "row_id": 58023, "seed_ids": "['Qwen2.5-72B-Instruct_117602']" }
0.640198
Filter_58023
I
[ "is_prime", "next_prime", "prime_product" ]
3
[ [ "next_prime", "is_prime" ], [ "prime_product", "next_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a54f3436a5d29c69038a81e6655aca116d5c6822
6144a8322dcd763fcba4b4a1b57e36f123246e0c
v1.0
instruct
Filter
Filter_58025_I
Write a short Python program that calculates and visualizes the Body Mass Index (BMI) for a list of users. The program should prompt the user to input the number of people, followed by their individual heights (in meters) and weights (in kilograms). It should then calculate the BMI for each individual and display it. A...
import matplotlib.pyplot as plt def calculate_bmi(weight, height): """ Calculate the BMI given weight in kg and height in meters. """ return weight / (height ** 2) def gather_user_data(): """ Gather height and weight data for a list of users. """ num_people = int(input("Enter the numbe...
from solution import calculate_bmi def test_calculate_bmi(): assert abs(calculate_bmi(60, 1.65) - 22.04) < 0.01 assert abs(calculate_bmi(72, 1.8) - 22.22) < 0.01 assert abs(calculate_bmi(80, 1.75) - 26.12) < 0.01 assert abs(calculate_bmi(50, 1.6) - 19.53) < 0.01
[ { "docstring": "Calculate the BMI given weight in kg and height in meters.", "function_declaration": "def calculate_bmi(weight, height):", "function_name": "calculate_bmi", "parameter_list": "(weight, height)" }, { "docstring": "Gather height and weight data for a list of users.", "funct...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\n\ndef calculate_bmi(weight, height):\n \"\"\"\n Calculate the BMI given weight in kg and height in meters.\n \"\"\"\n return weight / (height ** 2)...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058025", "row_id": 58025, "seed_ids": "['Qwen2.5-72B-Instruct_117607']" }
0.483756
Filter_58025
I
[ "calculate_bmi", "gather_user_data", "calculate_and_visualize_bmi" ]
3
[ [ "calculate_and_visualize_bmi", "calculate_bmi" ], [ "calculate_and_visualize_bmi", "gather_user_data" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib" ]
false
288fcebc2c37811f72b27c514644681b2ba06bac
42c5013f7fd682c5be702c0ff820d013db90bed6
v1.0
instruct
Filter
Filter_58043_I
Given a series of coordinates, write a Python program to find the shortest path that visits all points in the order they are given and returns to the starting point. Assume the Earth is a perfect sphere with a radius of 6371 km. The path should be calculated as the sum of the great-circle distances between the points.
import math def great_circle_distance(lat1, lon1, lat2, lon2, radius=6371): """ Calculate the great-circle distance between two points on the earth (specified in decimal degrees) """ # convert decimal degrees to radians lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) # ...
from solution import great_circle_distance, shortest_path def test_great_circle_distance(): assert math.isclose(great_circle_distance(0, 0, 0, 90), 10007.5434, rel_tol=1e-4) assert math.isclose(great_circle_distance(36.12, -86.67, 33.94, -118.40), 2886.4444, rel_tol=1e-4) def test_shortest_path_single_point()...
[ { "docstring": "Calculate the great-circle distance between two points\non the earth (specified in decimal degrees)", "function_declaration": "def great_circle_distance(lat1, lon1, lat2, lon2, radius=6371):", "function_name": "great_circle_distance", "parameter_list": "(lat1, lon1, lat2, lon2, radiu...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef haversine(lon1, lat1, lon2, lat2, radius=6371):\n \"\"\"\n Calculate the great-circle distance between two points on the Earth \n using their longitude and latitude...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058043", "row_id": 58043, "seed_ids": "['Qwen2.5-72B-Instruct_117642']" }
0.520709
Filter_58043
I
[ "great_circle_distance", "shortest_path" ]
2
[ [ "shortest_path", "great_circle_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
270d2f6308b8a6fcc00811f5f73e9f46a4a35b5b
99fcd439163b3ce8e34a3fa3c3bdf51216297ce0
v1.0
instruct
Filter
Filter_58057_I
Please create a Python script that runs only every 8 hours. It must print "Data collection initiated" and a timestamp at the start of the execution, and "Data collection completed" with the timestamp upon successful or 'failed' upon unsuccessful completion. Ensure it logs the output to a file.
import time import datetime import os def log_message(message): """ Logs a message with a timestamp to a file. """ with open("data_collection.log", "a") as log_file: log_file.write(f"{datetime.datetime.now()}: {message}\n") def data_collection(): """ Initiates the data collection proce...
from solution import log_message, data_collection import os def test_log_message(): """ Tests if log_message correctly writes to the file. """ log_message("Test message") with open("data_collection.log", "r") as log_file: lines = log_file.readlines() assert "Test message" in lines[-1] ...
[ { "docstring": "Logs a message with a timestamp to a file.", "function_declaration": "def log_message(message):", "function_name": "log_message", "parameter_list": "(message)" }, { "docstring": "Initiates the data collection process.", "function_declaration": "def data_collection():", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport datetime\nimport logging\nfrom logging.handlers import TimedRotatingFileHandler\n\n# Setup logging configuration\nlogger = logging.getLogger(\"DataCollectionLogger\")\nlogg...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058057", "row_id": 58057, "seed_ids": "['Qwen2.5-72B-Instruct_117673']" }
0.508838
Filter_58057
I
[ "log_message", "data_collection", "run_every_8_hours" ]
3
[ [ "data_collection", "log_message" ], [ "run_every_8_hours", "data_collection" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2ef5a7e67a205b7012053c6929c2bea5b4b609f1
7324db2ee7acc743623fd633d89cf0dc8e707b2c
v1.0
instruct
Filter
Filter_58059_I
Explain the difference between passing by value and passing by reference in programming, and provide examples to illustrate these concepts.
def modify_int(a): """ Attempts to modify an integer by value. """ a = 10 def modify_list(lst): """ Modifies a list by reference. """ lst.append(4) def passing_example(): """ Demonstrates passing by value and passing by reference concepts. """ # Passing by value exampl...
from solution import modify_int, modify_list, passing_example def test_modify_int(): number = 5 modify_int(number) assert number == 5 # number should remain unchanged to 5, as int is immutable in Python def test_modify_list(): lst = [1, 2, 3] modify_list(lst) assert lst == [1, 2, 3, 4] # lst...
[ { "docstring": "Attempts to modify an integer by value.", "function_declaration": "def modify_int(a):", "function_name": "modify_int", "parameter_list": "(a)" }, { "docstring": "Modifies a list by reference.", "function_declaration": "def modify_list(lst):", "function_name": "modify_...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def modify_list(lst):\n \"\"\"\n Appends 10 to the given list.\n \"\"\"\n lst.append(10)\n\ndef modify_int(num):\n \"\"\"\n Tries to add 10 to the given integer.\n \"\"\"\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058059", "row_id": 58059, "seed_ids": "['Qwen2.5-72B-Instruct_117678']" }
0.353951
Filter_58059
I
[ "modify_int", "modify_list", "passing_example" ]
3
[ [ "passing_example", "modify_int" ], [ "passing_example", "modify_list" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f20cd241f937fc5c6186a503d019e6e5d4ae24f6
e638be113e7f8716b7dbfd7d527921775db68e27
v1.0
instruct
Filter
Filter_58061_I
I want to learn how to code a simple neural network from scratch. Can you walk me through the process? I'm familiar with Python, so if you could explain using that language, it would be great.
import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): return x * (1 - x) def initialize_parameters(input_dim, hidden_dim, output_dim): np.random.seed(1) W1 = np.random.rand(input_dim, hidden_dim) b1 = np.zeros((1, hidden_dim)) W2 = np.random.rand(hidden_dim...
import numpy as np from solution import sigmoid, sigmoid_derivative, initialize_parameters, forward_propagation from solution import compute_cost, backward_propagation, update_parameters, train_model, predict def test_sigmoid(): assert np.isclose(sigmoid(0), 0.5) assert np.isclose(sigmoid(2), 0.880797077977882...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(x):\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n return x * (1 - x)\n\ndef initialize_parameters(input_dim, hidden_dim, output_dim):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058061", "row_id": 58061, "seed_ids": "['Qwen2.5-72B-Instruct_117681']" }
0.291362
Filter_58061
I
[ "sigmoid", "sigmoid_derivative", "initialize_parameters", "forward_propagation", "compute_cost", "backward_propagation", "update_parameters", "train_model", "predict" ]
9
[ [ "backward_propagation", "sigmoid_derivative" ], [ "forward_propagation", "sigmoid" ], [ "predict", "forward_propagation" ], [ "train_model", "backward_propagation" ], [ "train_model", "compute_cost" ], [ "train_model", "forward_propagation" ], ...
8
[]
false
[]
false
pytest
true
[ "numpy" ]
false
30d5bd16e5ab1c1413f719f23e293de1334fbeae
c6b74215127d25c7174208b58f3eb192c21230aa
v1.0
instruct
Filter
Filter_58080_I
Write a recursive program that computes and displays the Fibonacci sequence for a specific number of terms. The user should be able to input the number of terms they would like to see. Ensure to include error handling for invalid inputs (e.g., negative numbers, non-integer inputs).
def fibonacci(n): """ Returns the n-th term of the Fibonacci sequence using recursion. """ if n < 0: raise ValueError("Input can not be negative") if n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def generate_fibonacci_se...
import pytest from solution import fibonacci, generate_fibonacci_sequence def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_recursive_case(): assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 ...
[ { "docstring": "Returns the n-th term of the Fibonacci sequence using recursion.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Generates the Fibonacci sequence for a specific number of terms.", "function_declaratio...
[ 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 first n terms of the Fibonacci sequence.\n \"\"\"\n if n <= 0:\n raise ValueError(\"Number of terms must be a positive integer.\")\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058080", "row_id": 58080, "seed_ids": "['Qwen2.5-72B-Instruct_117708']" }
0.694348
Filter_58080
I
[ "fibonacci", "generate_fibonacci_sequence" ]
2
[ [ "generate_fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
659ab0070c7e07a6db5e31b80c9da6a7437d26fb
52e9d1e9da58c0e497f18aed2711e7dfb17835eb
v1.0
instruct
Filter
Filter_58103_I
Design a Python program that not only prints the Fibonacci sequence up to the nth term but also calculates and prints the sum of the even-valued terms and the largest prime number found within the sequence up to that term. The user should be able to input the value of n, and the program should display the sequence, the...
def is_prime(num): if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def fibonacci_sequence(n): if n <= 0: return [], 0, None sequence = [0, 1] while len(sequence) < n: sequence.append(sequence[-1...
from solution import is_prime, fibonacci_sequence, fibonacci_info 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(20) == False def test_fibonacci_sequence(): assert fibonacci_sequence(0) == ([], ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def fibonacci_sequence(n):", "function_name": "fibonacci_sequence", "parameter_list": "(n)" }, { "doc...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef fibonacci_seque...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058103", "row_id": 58103, "seed_ids": "['Qwen2.5-72B-Instruct_117744']" }
0.721617
Filter_58103
I
[ "is_prime", "fibonacci_sequence", "fibonacci_info" ]
3
[ [ "fibonacci_info", "fibonacci_sequence" ], [ "fibonacci_sequence", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
25fe984925e630bf2cea0b94a0dbdcdaba4c2793
ef78b7492e5ddfdcc69e31c217c4602b261a599d
v1.0
instruct
Filter
Filter_58158_I
Can you help me develop a small Python script that generates random user names and passwords? It should be able to generate a specified number of user accounts and store them in a CSV file. Each user name should be unique.
import csv import random import string def generate_username(length=8): """ Generates a random username of specified length. """ return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length)) def generate_password(length=12): """ Generates a random password of specified lengt...
import os from solution import generate_username, generate_password, generate_user_accounts, save_to_csv def test_generate_username(): username = generate_username(8) assert len(username) == 8 assert username.isalnum() def test_generate_password(): password = generate_password(12) assert len(passw...
[ { "docstring": "Generates a random username of specified length.", "function_declaration": "def generate_username(length=8):", "function_name": "generate_username", "parameter_list": "(length=8)" }, { "docstring": "Generates a random password of specified length.", "function_declaration"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nimport random\nimport string\n\ndef generate_random_string(length):\n \"\"\"\n Generate a random string of specified length.\n \"\"\"\n letters_and_digits = string.asci...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058158", "row_id": 58158, "seed_ids": "['Qwen2.5-72B-Instruct_117841']" }
0.586464
Filter_58158
I
[ "generate_username", "generate_password", "generate_user_accounts", "save_to_csv" ]
4
[ [ "generate_user_accounts", "generate_password" ], [ "generate_user_accounts", "generate_username" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d58e5ac65740e417e7a82e4d15b07099372a80c3
faf463c000f0f1588036ebb7cb142fddf16213ea
v1.0
instruct
Filter
Filter_58163_I
I want to encrypt a string using a simple Caesar cipher with a shift of 5. Can you provide a Python function to do this, and also a function to decrypt the string back to its original form?
def encrypt_caesar_cipher(text, shift=5): """ Encrypts the given text using a Caesar cipher with the specified shift. Default shift is 5. """ encrypted_text = '' for char in text: if char.isalpha(): shift_amount = shift % 26 if char.islower(): new_...
from solution import encrypt_caesar_cipher, decrypt_caesar_cipher def test_encrypt_caesar_cipher(): assert encrypt_caesar_cipher("Hello, World!") == "Mjqqt, Btwqi!" assert encrypt_caesar_cipher("abcxyz") == "fghcde" assert encrypt_caesar_cipher("ABCXYZ") == "FGHCDE" assert encrypt_caesar_cipher("12345"...
[ { "docstring": "Encrypts the given text using a Caesar cipher with the specified shift.\nDefault shift is 5.", "function_declaration": "def encrypt_caesar_cipher(text, shift=5):", "function_name": "encrypt_caesar_cipher", "parameter_list": "(text, shift=5)" }, { "docstring": "Decrypts the gi...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_encrypt(plain_text, shift=5):\n \"\"\"\n Encrypts the plain_text using a Caesar cipher with the specified shift.\n Default shift is 5.\n \"\"\"\n encrypted_text = []\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058163", "row_id": 58163, "seed_ids": "['Qwen2.5-72B-Instruct_117848']" }
0.680192
Filter_58163
I
[ "encrypt_caesar_cipher", "decrypt_caesar_cipher" ]
2
[ [ "decrypt_caesar_cipher", "encrypt_caesar_cipher" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b7bd9d5a9a3ae1fd6b4f6dd07e8ea171a3423aa
a38a757dbb05963f4966a554a7ec1a6f2f0b8e34
v1.0
instruct
Filter
Filter_58167_I
Filter the numbers from a list in Python using list comprehension that only leaves numbers that are prime.
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Returns a list of prime numbers from the given list. """ return [...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7]) == [2, 3, 5, 7] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 10]) == [] def test_filter_primes_mixed(): assert filter_primes([2, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 5, 7, 11] de...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list.", "function_declaration": "def filter_primes(numbers):", "function_n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Checks 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 % 3 == 0:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058167", "row_id": 58167, "seed_ids": "['Qwen2.5-72B-Instruct_117854']" }
0.576512
Filter_58167
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a4190a95e2445db6effa265065f1c9087162362
ba2592e91bb437a050526dd973602990fc452ef4
v1.0
instruct
Filter
Filter_58201_I
Design a Python function that generates an infinite sequence of numbers starting from a specified number. The function should be a custom generator, not rely on existing functions or libraries. The sequence should indefinitely yield the next number, starting from the initial number provided. Additionally, implement a c...
def infinite_sequence(start): """ Custom generator that yields an indefinite sequence of numbers starting from 'start'. """ current = start while True: yield current current += 1 def check_infinite_sequence(start): """ Function that checks the infinite_sequence generator by ...
from solution import infinite_sequence, check_infinite_sequence def test_infinite_sequence_starting_from_100(): generator = infinite_sequence(100) assert next(generator) == 100 assert next(generator) == 101 assert next(generator) == 102 assert next(generator) == 103 assert next(generator) == 10...
[ { "docstring": "Custom generator that yields an indefinite sequence of numbers starting from 'start'.", "function_declaration": "def infinite_sequence(start):", "function_name": "infinite_sequence", "parameter_list": "(start)" }, { "docstring": "Function that checks the infinite_sequence gen...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def infinite_sequence(start):\n \"\"\"\n A generator function that yields an infinite sequence of numbers \n starting from `start`.\n \"\"\"\n current = start\n while True:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058201", "row_id": 58201, "seed_ids": "['Qwen2.5-72B-Instruct_117910']" }
0.597377
Filter_58201
I
[ "infinite_sequence", "check_infinite_sequence" ]
2
[ [ "check_infinite_sequence", "infinite_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
deaf170d72ab185394c55f9069dd893bcf85d3a7
46c9da1d6eae8929ab21a1068b246b85f04edb20
v1.0
instruct
Filter
Filter_58213_I
How do I program a neural network from scratch in Python?
import numpy as np # Sigmoid activation function and its derivative def sigmoid(x): return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): return x * (1 - x) # Initialize weights and biases def initialize_parameters(input_size, hidden_size, output_size): np.random.seed(42) # For reproducibility weig...
from solution import (initialize_parameters, forward_pass, compute_loss, backward_pass, train) import numpy as np def test_initialize_parameters(): weights_input_hidden, weights_hidden_output, biases_hidden, biases_output = initialize_parameters(3, 2, 1) assert weights_input_hidden.shape == (3, 2) assert w...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\n# Sigmoid activation function and its derivative\ndef sigmoid(x):\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n return x * (1 - x)\n\n# Initialize w...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058213", "row_id": 58213, "seed_ids": "['Qwen2.5-72B-Instruct_117926']" }
0.346121
Filter_58213
I
[ "sigmoid", "sigmoid_derivative", "initialize_parameters", "forward_pass", "compute_loss", "backward_pass", "train" ]
7
[ [ "backward_pass", "sigmoid_derivative" ], [ "forward_pass", "sigmoid" ], [ "train", "backward_pass" ], [ "train", "compute_loss" ], [ "train", "forward_pass" ], [ "train", "initialize_parameters" ] ]
6
[]
false
[]
false
pytest
true
[ "numpy" ]
false
be9f10d7b2db35af7ceabfcb3061edc4c21c1f97
2c370c730f012e158aafe868b616b47ed66e50cd
v1.0
instruct
Filter
Filter_58223_I
I have some Python code that I want to use for my project. The code tests if a given input string is a palindrome. However, I want to extend its functionality. I would like the function to also test if the input string contains any palindrome substring of at least length 3, and return the longest palindrome substring f...
def is_palindrome(s): """ Checks if the given string s is a palindrome. """ return s == s[::-1] def longest_palindrome_substring(s): """ Returns the longest palindrome substring of length at least 3 from the given string s. If no such palindrome exists, returns an empty string. """ ...
from solution import is_palindrome, longest_palindrome_substring, palindrome_info def test_is_palindrome(): assert is_palindrome("racecar") == True assert is_palindrome("madam") == True assert is_palindrome("palindrome") == False assert is_palindrome("") == True assert is_palindrome("a") == True d...
[ { "docstring": "Checks if the given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the longest palindrome substring of length at least 3 from the given string s.\nIf no such pal...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Checks if the given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef longest_palindrome_substring(s):\n \"\"\"\n Returns the l...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058223", "row_id": 58223, "seed_ids": "['Qwen2.5-72B-Instruct_117937']" }
0.716041
Filter_58223
I
[ "is_palindrome", "longest_palindrome_substring", "palindrome_info" ]
3
[ [ "palindrome_info", "is_palindrome" ], [ "palindrome_info", "longest_palindrome_substring" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d904370ba01227114fbf674736e655195c323d18
f530b0a3834e80f697f26b294a9949452e6ed8cd
v1.0
instruct
Filter
Filter_58249_I
Create a Python program that implements a simple calculator. The calculator should be able to perform addition, subtraction, multiplication, and division. It should also handle errors such as division by zero and input of non-numeric data.
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b def simple_calculator(operation, a, b): """ Performs the given operation on numbers a and b. oper...
import pytest from solution import simple_calculator, add, subtract, multiply, divide def test_add(): assert add(2, 3) == 5 assert add(0, 5) == 5 assert add(-1, -1) == -2 assert add(-1, 3) == 2 def test_subtract(): assert subtract(3, 2) == 1 assert subtract(5, 0) == 5 assert subtract(-1, -...
[ { "docstring": null, "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_list": "(a, b)" }, { "docstring": null, "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n try:\n a, b = float(a), float(b)\n return a + b\n except ValueError:\n return \"Invalid input. Please enter numeric values.\"\n\ndef subtract(a, b):...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058249", "row_id": 58249, "seed_ids": "['Qwen2.5-72B-Instruct_117982']" }
0.581841
Filter_58249
I
[ "add", "subtract", "multiply", "divide", "simple_calculator" ]
5
[ [ "simple_calculator", "add" ], [ "simple_calculator", "divide" ], [ "simple_calculator", "multiply" ], [ "simple_calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
21917566e39615b86c7bd5a34565b88d8a131b64
0a1b41f1a714b8d0f075f8b0491d8ac68b766a60
v1.0
instruct
Filter
Filter_58261_I
Design a Python function that could transform JSON data representing a nested structure into a pandas DataFrame. Assume the JSON data represents a series of observations, each with a mix of scalar values, nested objects, and lists. The function should gracefully flatten this data, pushing nested dictionary structures o...
import pandas as pd import json from typing import Dict, Any def flatten_json(y: Dict[str, Any], parent_key: str = '', sep: str = '.') -> Dict[str, Any]: """ Helper function to flatten JSON objects. """ items = {} for k, v in y.items(): new_key = f"{parent_key}{sep}{k}" if parent_key else k...
from solution import json_to_dataframe import pandas as pd def test_json_to_dataframe_simple(): json_data = '[{"a": 1, "b": 2}, {"a": 3, "b": 4}]' df = json_to_dataframe(json_data) expected_df = pd.DataFrame({"a": [1, 3], "b": [2, 4]}) pd.testing.assert_frame_equal(df, expected_df) def test_json_to_da...
[ { "docstring": "Helper function to flatten JSON objects.", "function_declaration": "def flatten_json(y, parent_key='', sep='.'):", "function_name": "flatten_json", "parameter_list": "(y, parent_key='', sep='.')" }, { "docstring": "Transforms a nested JSON structure into a pandas DataFrame.\n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\nimport json\nfrom collections.abc import MutableMapping\n\ndef flatten_json(y):\n out = {}\n\n def flatten(x, name=''):\n if isinstance(x, MutableMapping):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058261", "row_id": 58261, "seed_ids": "['Qwen2.5-72B-Instruct_118007']" }
0.733951
Filter_58261
I
[ "flatten_json", "json_to_dataframe" ]
2
[ [ "json_to_dataframe", "flatten_json" ] ]
1
[]
false
[]
false
pytest
true
[ "pandas" ]
false
b395627cc2d618b5df788942f74291cd7276e546
a9de00e4388a4eea0e90dca3aa2aaecf3fc1f655
v1.0
instruct
Filter
Filter_58265_I
Write a code to simulate a polymerization reaction using the Monte Carlo method. The simulation should model a polymer chain growing in a 2D lattice. Assume that each monomer can only bond with its nearest neighbors and that the reaction probability is dependent on the number of bonds a monomer can form. Consider a sce...
import numpy as np import matplotlib.pyplot as plt import random # Constants LATTICE_SIZE = 100 START_POINT = (LATTICE_SIZE // 2, LATTICE_SIZE // 2) # Possible movements in 2D (up, down, left, right) MOVES = [(0, 1), (0, -1), (1, 0), (-1, 0)] def initialize_lattice(size): """ Initializes a lattice of given s...
from solution import initialize_lattice, is_within_bounds, get_neighbors, calculate_probability, monte_carlo_polymerization def test_initialize_lattice(): size = 20 lattice = initialize_lattice(size) assert lattice.shape == (size, size) assert np.all(lattice == 0) def test_is_within_bounds(): size...
[ { "docstring": "Initializes a lattice of given size with zeros.", "function_declaration": "def initialize_lattice(size):", "function_name": "initialize_lattice", "parameter_list": "(size)" }, { "docstring": "Checks if a position is within the lattice bounds.", "function_declaration": "de...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nimport random\n\n# Constants\nLATTICE_SIZE = 100\nSTART_POINT = (LATTICE_SIZE // 2, LATTICE_SIZE // 2)\n\n# Possible movements in 2D (up, d...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058265", "row_id": 58265, "seed_ids": "['Qwen2.5-72B-Instruct_118012']" }
0.352007
Filter_58265
I
[ "initialize_lattice", "is_within_bounds", "get_neighbors", "calculate_probability", "monte_carlo_polymerization", "visualize_lattice" ]
6
[ [ "monte_carlo_polymerization", "calculate_probability" ], [ "monte_carlo_polymerization", "get_neighbors" ], [ "monte_carlo_polymerization", "is_within_bounds" ] ]
3
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
dcf9499a4abe696b4c57e787b1a5ab53114b8a61
a7f3854ba0867692939c51d12d2a753841dc2f45
v1.0
instruct
Filter
Filter_58274_I
Write the code to create a Python program that calculates and prints the logistic function (1 / (1 + e^(-x))) for an array of values ranging from -10 to 10 with a step of 0.5. Use numpy for the calculation and matplotlib to plot the function with the y-axis limits set from -0.5 to 1.5. Your program should also save the...
import numpy as np import matplotlib.pyplot as plt def logistic_function(x): """ Calculate the logistic function. """ return 1 / (1 + np.exp(-x)) def plot_logistic_function(): """ Plot the logistic function over the range -10 to 10 with step size 0.5 and save as a PNG file. """ x_value...
import numpy as np from solution import logistic_function, plot_logistic_function def test_logistic_function_basic(): assert np.isclose(logistic_function(0), 0.5) def test_logistic_function_positive(): assert logistic_function(10) > 0.999 def test_logistic_function_negative(): assert logistic_function(-1...
[ { "docstring": "Calculate the logistic function.", "function_declaration": "def logistic_function(x):", "function_name": "logistic_function", "parameter_list": "(x)" }, { "docstring": "Plot the logistic function over the range -10 to 10 with step size 0.5 and save as a PNG file.", "funct...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef logistic_function(x):\n \"\"\"\n Returns the logistic function value for a given x.\n \"\"\"\n return 1 / (1 + np.exp(-x)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058274", "row_id": 58274, "seed_ids": "['Qwen2.5-72B-Instruct_118038']" }
0.52523
Filter_58274
I
[ "logistic_function", "plot_logistic_function" ]
2
[ [ "plot_logistic_function", "logistic_function" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
257a989b43c555106d22127acc398c768a393450
e787bad4e9d92e4d75c830401b2b7496b1f620ec
v1.0
instruct
Filter
Filter_58284_I
I'm trying to solve a problem with a multi-variate curve fitting task using Python. I have a set of data points, but I want to fit a model where one of the terms is fixed. Specifically, I want to fit a model where the formula is `z = a * x + b * y + c`, but I want to fix the coefficient `a` to a certain value. How can ...
import numpy as np from scipy.optimize import curve_fit def model(xy, b, c, a_fixed): x, y = xy return a_fixed * x + b * y + c def fit_fixed_a(x_data, y_data, z_data, a_fixed): # Combine x_data and y_data into a single array as required by curve_fit xy_data = np.vstack((x_data, y_data)) # Pro...
from solution import fit_fixed_a import numpy as np def test_fit_fixed_a(): # Generate some data points np.random.seed(0) x_data = np.random.rand(10) y_data = np.random.rand(10) # Define the true coefficients a_true = 2.0 b_true = 3.0 c_true = 1.0 # Generate the z data acc...
[ { "docstring": null, "function_declaration": "def model(xy, b, c, a_fixed):", "function_name": "model", "parameter_list": "(xy, b, c, a_fixed)" }, { "docstring": null, "function_declaration": "def fit_fixed_a(x_data, y_data, z_data, a_fixed):", "function_name": "fit_fixed_a", "pa...
[ 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 model(xy, b, c, a_fixed):\n x, y = xy\n return a_fixed * x + b * y + c\n\ndef fit_fixed_a(x_data, y_data, z_data, a_fixed)...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058284", "row_id": 58284, "seed_ids": "['Qwen2.5-72B-Instruct_118058']" }
0.557422
Filter_58284
I
[ "model", "fit_fixed_a" ]
2
[ [ "fit_fixed_a", "model" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
1df87d2c2975746e6cb670660d28e6ec8b943108
06fb8b23ecc5e10877f229e2cc982efe112f6e54
v1.0
instruct
Filter
Filter_58286_I
How can I create a simple web scraper using Python to extract text contents from a series of URLs stored in a CSV file?
import requests from bs4 import BeautifulSoup import csv def read_urls_from_csv(file_path): """ Reads URLs from a CSV file. Assumes the URLs are in the first column. """ urls = [] with open(file_path, newline='', encoding='utf-8') as csvfile: reader = csv.reader(csvfile) for row in ...
from solution import read_urls_from_csv, scrape_text_from_url, scrape_and_save_texts import os def test_read_urls_from_csv(): file_path = 'test_urls.csv' with open(file_path, 'w', newline='', encoding='utf-8') as csvfile: writer = csv.writer(csvfile) writer.writerow(['http://example.com']) ...
[ { "docstring": "Reads URLs from a CSV file. Assumes the URLs are in the first column.", "function_declaration": "def read_urls_from_csv(file_path):", "function_name": "read_urls_from_csv", "parameter_list": "(file_path)" }, { "docstring": "Scrapes text content from a given URL.", "functi...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nimport requests\nfrom bs4 import BeautifulSoup\n\ndef extract_text_from_url(url):\n \"\"\"\n Extracts text content from the given URL.\n \"\"\"\n response = requests.ge...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058286", "row_id": 58286, "seed_ids": "['Qwen2.5-72B-Instruct_118062']" }
0.724805
Filter_58286
I
[ "read_urls_from_csv", "scrape_text_from_url", "scrape_and_save_texts" ]
3
[ [ "scrape_and_save_texts", "read_urls_from_csv" ], [ "scrape_and_save_texts", "scrape_text_from_url" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
eca69b220be511b4550345750a8618051b200ac5
451f3d377b12e673a3e610fb6542e978643c1451
v1.0
instruct
Filter
Filter_58314_I
Implement a recommendation system using collaborative filtering in Python. Can you guide me through the steps and provide some code examples?
import numpy as np from sklearn.metrics.pairwise import cosine_similarity def user_similarity(ratings): """ Compute the similarity between users using cosine similarity """ return cosine_similarity(ratings) def predict_ratings(ratings, similarity): """ Predict ratings using the weighted sum o...
import numpy as np from solution import user_similarity, predict_ratings, recommend def test_user_similarity(): ratings = np.array([ [4, 0, 0, 5, 1, 0, 0], [5, 5, 4, 0, 0, 0, 0], [0, 0, 0, 2, 4, 5, 0], [0, 3, 0, 0, 0, 0, 3], ]) sim_matrix = user_similarity(ratings) asser...
[ { "docstring": "Compute the similarity between users using cosine similarity", "function_declaration": "def user_similarity(ratings):", "function_name": "user_similarity", "parameter_list": "(ratings)" }, { "docstring": "Predict ratings using the weighted sum of neighbors' ratings", "fun...
[ 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 sklearn.metrics.pairwise import cosine_similarity\n\ndef user_similarity(ratings):\n \"\"\"\n Compute the similarity between users using cosine similarity\n \...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058314", "row_id": 58314, "seed_ids": "['Qwen2.5-72B-Instruct_118130']" }
0.389207
Filter_58314
I
[ "user_similarity", "predict_ratings", "recommend" ]
3
[ [ "recommend", "predict_ratings" ], [ "recommend", "user_similarity" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "sklearn" ]
false
d5527f4557664e4baf5df2bbcef1cf9b71a8a6f1
469c7185cf75c71481c4408c80d77ea3478616c6
v1.0
instruct
Filter
Filter_58321_I
Provide code in Python for a simple game of Rock, Paper, Scissors. The game should allow a user to play against the computer, which makes its choices randomly. The game should ask the user for their choice, display the computer's choice, and declare the winner of each round. The game should continue until the user deci...
import random def get_computer_choice(): """ Returns the computer's choice randomly from 'rock', 'paper', 'scissors'. """ return random.choice(['rock', 'paper', 'scissors']) def determine_winner(user_choice, computer_choice): """ Determines the winner of the round. Args: - user_ch...
from solution import get_computer_choice, determine_winner, play_round def test_get_computer_choice(): choices = {'rock', 'paper', 'scissors'} for _ in range(100): # Run the test multiple times due to randomness assert get_computer_choice() in choices def test_determine_winner(): assert determine...
[ { "docstring": "Returns the computer's choice randomly from 'rock', 'paper', 'scissors'.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner of the round.\n\nArgs:\n- user_choice (str)...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Returns the computer's choice randomly from 'rock', 'paper', 'scissors'.\n \"\"\"\n return random.choice(['rock', 'paper', 's...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058321", "row_id": 58321, "seed_ids": "['Qwen2.5-72B-Instruct_118143']" }
0.465643
Filter_58321
I
[ "get_computer_choice", "determine_winner", "play_round", "game" ]
4
[ [ "game", "play_round" ], [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
3
[]
false
[]
false
pytest
true
[]
true
414ee21693cc4633ba235f8ac83a11d3619584bf
d6e0f9c93f1d9c30b00e55806527b3234596cc27
v1.0
instruct
Filter
Filter_58330_I
Develop a Python code snippet that identifies and prints all twin prime pairs between 1 and a given limit N. A twin prime is defined as a pair of numbers which are both prime and have a difference of two between them. Ensure your program also computes the total count of these pairs. For validation, use N = 30 as an exa...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, find_twin_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(25) == False def test_find_twin_primes_limit_30(): twin_primes, count = find_twin_primes(30) as...
[ { "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 twin primes (pairs) up to the given limit and the count of these pairs.", "functio...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058330", "row_id": 58330, "seed_ids": "['Qwen2.5-72B-Instruct_118160']" }
0.618081
Filter_58330
I
[ "is_prime", "find_twin_primes", "main" ]
3
[ [ "find_twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18050038e115114b82d33e9c83c49abf0f163cc4
7798e61875227f821091a46ea34f25f2dd251d5e
v1.0
instruct
Filter
Filter_58363_I
Given two integers, a and b, with the constraint that they are both positive and a < b, write a program to generate a list of prime numbers that are between a and b (inclusive) in ascending order. How should I approach this problem? Can you provide a Python solution?
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import generate_prime_numbers def test_generate_prime_numbers_basic(): assert generate_prime_numbers(10, 20) == [11, 13, 17, 19] assert generate_prime_numbers(1, 10) == [2, 3, 5, 7] def test_generate_prime_numbers_edge_cases(): assert generate_prime_numbers(2, 3) == [2, 3] assert generat...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers between a and b (inclusive).", "function_declaration": "def generate...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n 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_2
{ "original_instruction": "", "prompt_id": "00058363", "row_id": 58363, "seed_ids": "['Qwen2.5-72B-Instruct_118213']" }
0.64555
Filter_58363
I
[ "is_prime", "generate_prime_numbers" ]
2
[ [ "generate_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a4b1378ef0604be779a493c24d0e622b0f12950
b176e694034038d7721d75f2c5d06d9732880d8d
v1.0
instruct
Filter
Filter_58371_I
Write a function in Python that takes a list of integers and returns the product of all the prime numbers within the list. If there are no prime numbers, the function should return 1. If the list is empty, return 1. The function should be efficient and concise.
from math import isqrt def is_prime(num): """ Returns True if num is a prime number, otherwise returns False. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or...
from solution import product_of_primes def test_product_of_primes_with_all_primes(): assert product_of_primes([2, 3, 5, 7]) == 210 def test_product_of_primes_with_no_primes(): assert product_of_primes([4, 6, 8, 10]) == 1 def test_product_of_primes_with_mixed_numbers(): assert product_of_primes([4, 5, 6, ...
[ { "docstring": "Returns True if num is a prime number, otherwise returns False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the product of all prime numbers within the list. If \nthere are no 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 Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058371", "row_id": 58371, "seed_ids": "['Qwen2.5-72B-Instruct_118229']" }
0.690537
Filter_58371
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56c7559643e31595e339f4f6bb8fa812af3072f4
af66595c2845c8f3f46b0f9070b7715a0c86e16b
v1.0
instruct
Filter
Filter_58384_I
Can you write code to find prime numbers? If so, could you provide an example in Python?
def is_prime(number): """ Check if the given number is a prime number. :param number: Integer to check for being prime. :return: Boolean value indicating whether the number is prime or not. """ if number <= 1: return False if number == 2: return True if number % 2 == 0: ...
from solution import is_prime, find_primes def test_is_prime(): assert is_prime(0) == False assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(25) == False assert is_prime(29) == True ...
[ { "docstring": "Check if the given number is a prime number.\n\n:param number: Integer to check for being prime.\n:return: Boolean value indicating whether the number is prime or not.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(number):\n \"\"\"\n Check if the given number is a prime number.\n\n :param number: Integer to check for being prime.\n :return: Boolean value indicating whether the n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058384", "row_id": 58384, "seed_ids": "['Qwen2.5-72B-Instruct_118253']" }
0.689989
Filter_58384
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2de4dab9e969ad8d87fc042442ddbacb3a4f7189
d59690e04b277fb23c21748d806b8fb8f3fc2c72
v1.0
instruct
Filter
Filter_58410_I
Create a$is tic tac toe game in Python using the command line. The game should allow two players to take turns and should verify the winner or if the game is a draw.
def initialize_board(): return [[" " for _ in range(3)] for _ in range(3)] def print_board(board): for row in board: print("|".join(row)) print("-" * 5) def make_move(board, row, col, player): if board[row][col] == " ": board[row][col] = player return True else:...
from solution import initialize_board, make_move, check_winner, is_draw def test_initialize_board(): board = initialize_board() assert board == [[" " for _ in range(3)] for _ in range(3)] def test_make_move(): board = initialize_board() assert make_move(board, 0, 0, "X") == True assert board[0][0]...
[ { "docstring": null, "function_declaration": "def initialize_board():", "function_name": "initialize_board", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def print_board(board):", "function_name": "print_board", "parameter_list": "(board)" }, { ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def initialize_board():\n return [[\" \" for _ in range(3)] for _ in range(3)]\n\ndef print_board(board):\n for row in board:\n print(\"|\".join(row))\n print(\"-\" * 5)\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058410", "row_id": 58410, "seed_ids": "['Qwen2.5-72B-Instruct_118301']" }
0.415982
Filter_58410
I
[ "initialize_board", "print_board", "make_move", "check_winner", "is_draw", "tic_tac_toe" ]
6
[ [ "tic_tac_toe", "check_winner" ], [ "tic_tac_toe", "initialize_board" ], [ "tic_tac_toe", "is_draw" ], [ "tic_tac_toe", "make_move" ], [ "tic_tac_toe", "print_board" ] ]
5
[]
false
[]
false
pytest
true
[]
true
c9bc62f9a82e6efff9e57819ba7220f21ca9248f
b4dc5b1075198850f9bfebf027d015e5343fda82
v1.0
instruct
Filter
Filter_58420_I
Create a code to encrypt a string using a simple Caesar cipher, where each letter is replaced by a letter with a fixed number of positions down the alphabet. Then, create a function to decrypt the message back to its original form. Make sure to account for wraparound (e.g., 'z' encrypted becomes 'a' if the shift is 1)....
def caesar_encrypt(text, shift): """ Encrypts a text using Caesar cipher with a given shift. :param text: The text to be encrypted :param shift: The number of positions to shift each letter :return: The encrypted text """ encrypted_text = [] for char in text: if ch...
from solution import caesar_encrypt, caesar_decrypt def test_caesar_cipher(): text = "abc" shift = 1 encrypted_text = caesar_encrypt(text, shift) assert encrypted_text == "bcd" decrypted_text = caesar_decrypt(encrypted_text, shift) assert decrypted_text == text def test_caesar_cipher_with_uppe...
[ { "docstring": "Encrypts a text using Caesar cipher with a given shift.\n\n:param text: The text to be encrypted\n:param shift: The number of positions to shift each letter\n\n:return: The encrypted text", "function_declaration": "def caesar_encrypt(text, shift):", "function_name": "caesar_encrypt", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encrypt_caesar_cipher(plain_text, shift):\n \"\"\"\n Encrypts the plain_text using the Caesar cipher with the given shift.\n \"\"\"\n encrypted_text = []\n \n for char in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058420", "row_id": 58420, "seed_ids": "['Qwen2.5-72B-Instruct_118318']" }
0.720777
Filter_58420
I
[ "caesar_encrypt", "caesar_decrypt" ]
2
[ [ "caesar_decrypt", "caesar_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53f3696f297664f0e20d72361bb35787f3e7de0a
171cfedc0513b28e9816addd05713654c650ec26
v1.0
instruct
Filter
Filter_58452_I
Design a Python function to represent a simple neural network layer that applies a linear transformation followed by a ReLU activation function. The linear transformation should be defined by a weight matrix and a bias vector. Make sure to initialize these parameters with random values. The function should take an inpu...
import numpy as np def relu(x): return np.maximum(0, x) def neural_network_layer(input_vector, weight_matrix=None, bias_vector=None): input_size = len(input_vector) if weight_matrix is None: weight_matrix = np.random.randn(input_size, input_size) if bias_vector is None: b...
from solution import neural_network_layer, relu import numpy as np def test_relu(): assert np.array_equal(relu(np.array([-1, 0, 1, 2])), np.array([0, 0, 1, 2])) def test_neural_network_layer(): np.random.seed(42) # Setting seed for reproducibility input_vector = np.array([1, 2, 3]) weight_matrix...
[ { "docstring": null, "function_declaration": "def relu(x):", "function_name": "relu", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def neural_network_layer(input_vector, weight_matrix=None, bias_vector=None):", "function_name": "neural_network_layer", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef relu(x):\n \"\"\"\n Applies the ReLU activation function.\n \"\"\"\n return np.maximum(0, x)\n\ndef neural_network_layer(input_vector, weight_matrix, bias...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058452", "row_id": 58452, "seed_ids": "['Qwen2.5-72B-Instruct_118375']" }
0.419209
Filter_58452
I
[ "relu", "neural_network_layer" ]
2
[ [ "neural_network_layer", "relu" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
f91c7875bbbcf8512c32c7fa27cecb84ed05e8ed
bff53cd8998bd76cda15e196f30fa1a943d22fe2
v1.0
instruct
Filter
Filter_58463_I
How can I simulate a simple traffic flow using the cellular automata model in Python?
import numpy as np def initialize_road(length, car_density): """ Initialize the road with cars based on the given density. :param length: Length of the road :param car_density: Density of the cars (0 <= car_density <= 1) :return: Initialized road (a list of cells where 1 represents a car and 0...
from solution import initialize_road, update_road, simulate_traffic_flow import numpy as np def test_initialize_road(): road = initialize_road(10, 0.3) assert len(road) == 10 assert np.sum(road) == 3 # 30% of 10 is 3 def test_initialize_road_no_cars(): road = initialize_road(10, 0) assert len(roa...
[ { "docstring": "Initialize the road with cars based on the given density.\n\n:param length: Length of the road\n:param car_density: Density of the cars (0 <= car_density <= 1)\n:return: Initialized road (a list of cells where 1 represents a car and 0 represents an empty cell)", "function_declaration": "def ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef initialize_road(length, car_density):\n \"\"\"\n Initialize the road with cars based on the given density.\n \n :param length: Length of the road\n :pa...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058463", "row_id": 58463, "seed_ids": "['Qwen2.5-72B-Instruct_118391']" }
0.345884
Filter_58463
I
[ "initialize_road", "update_road", "simulate_traffic_flow" ]
3
[ [ "simulate_traffic_flow", "initialize_road" ], [ "simulate_traffic_flow", "update_road" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy" ]
false
11df1f85aa6400b807f3e076b88d73ab18c97765
75d65cebff8508ddb75a45a5d3cb87b8c0adf39a
v1.0
instruct
Filter
Filter_58470_I
I was recently asked to fix a tree structure in my code that had become corrupted with duplicate nodes. In this structure, a binary search tree (BST) had nodes with duplicate values, and my task was to remove these duplicates so that after each value was inserted or found, there would be only one unique value left. Wha...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def inorder_traversal(root): """ Perform an in-order traversal of the tree and return the list of values. """ result = [] if root: r...
from solution import TreeNode, remove_duplicates_bst, inorder_traversal def bst_to_list(root): """ Helper function to convert BST to list using in-order traversal. """ return inorder_traversal(root) def test_remove_duplicates_bst(): # Tree: # 2 # / \ # 1 3 # \ # ...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "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 inorder_traversal(root):\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058470", "row_id": 58470, "seed_ids": "['Qwen2.5-72B-Instruct_118403']" }
0.413321
Filter_58470
I
[ "inorder_traversal", "sorted_array_to_bst", "remove_duplicates_bst" ]
3
[ [ "remove_duplicates_bst", "inorder_traversal" ], [ "remove_duplicates_bst", "sorted_array_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4170c45811b1c3c052747130543863cb0438d453
cc00c17573548dd1cae7d7a3f8b03d036a12656e
v1.0
instruct
Filter
Filter_58478_I
Design a simple chatbot using撤回Python and Flask that responds to user inputs based on a predefined set of rules. For instance, if a user types "hello", the chatbot should respond with "Hi there! How can I assist you today?" Also, if the input contains the word "help", the chatbot should provide a list of commands or op...
from flask import Flask, request, jsonify app = Flask(__name__) def get_response(user_input): """ Generate a chatbot response based on the user input. """ if 'hello' in user_input.lower(): return "Hi there! How can I assist you today?" elif 'help' in user_input.lower(): return "Her...
import pytest from solution import app, get_response # Setup the Flask testing client @pytest.fixture def client(): with app.test_client() as client: yield client # Unit tests for the get_response function def test_response_to_hello(): assert get_response('hello') == "Hi there! How can I assist you to...
[ { "docstring": "Generate a chatbot response based on the user input.", "function_declaration": "def get_response(user_input):", "function_name": "get_response", "parameter_list": "(user_input)" }, { "docstring": "Handle incoming requests to the chatbot.", "function_declaration": "def cha...
[ 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 get_response(user_input):\n \"\"\"\n Generate a chatbot response based on the user input.\n \"\"\"\n if 'h...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058478", "row_id": 58478, "seed_ids": "['Qwen2.5-72B-Instruct_118419']" }
0.369
Filter_58478
I
[ "get_response", "chatbot" ]
2
[ [ "chatbot", "get_response" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
42364f173e10efa74b899d056149a24cda2e25a1
03bac7ecab872cc4f6bdaab57a6c8f62f2c94416
v1.0
instruct
Filter
Filter_58484_I
Write a Python code snippet to generate a list of 50 random numbers between 1 to 1000. Filter and print the numbers that are prime.
import random def is_prime(n): """ Check if a number is a prime number. """ 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, generate_random_numbers, filter_prime_numbers def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of random numbers.", "function_declaration": "def generate_random_numbers(count, lower, upper):", ...
[ 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 is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058484", "row_id": 58484, "seed_ids": "['Qwen2.5-72B-Instruct_118429']" }
0.574987
Filter_58484
I
[ "is_prime", "generate_random_numbers", "filter_prime_numbers" ]
3
[ [ "filter_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec98a64d1d352119d238e63769066ef679dfa0cc
07c420ee82e5df43e67c9dab37c76902801d8760
v1.0
instruct
Filter
Filter_58489_I
How can I solve a Sudoku puzzle using backtracking in Python? Provide a simple explanation and a code snippet.
def is_valid(board, row, col, num): """ Check if it's valid to place `num` in the `board` at (row, col). """ # Check the row for x in range(9): if board[row][x] == num: return False # Check the column for x in range(9): if board[x][col] == num: return...
from solution import is_valid, solve_sudoku, find_empty_location def test_is_valid(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6...
[ { "docstring": "Check if it's valid to place `num` in the `board` at (row, col).", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Solve the Sudoku puzzle using backtracking.\n\n:param b...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n # Check if 'num' is not in the current row, column, and the 3x3 sub-grid\n sub_grid_row_start = (row // 3) * 3\n sub_grid_col_start = (col // 3) ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058489", "row_id": 58489, "seed_ids": "['Qwen2.5-72B-Instruct_118435']" }
0.395981
Filter_58489
I
[ "is_valid", "solve_sudoku", "find_empty_location" ]
3
[ [ "solve_sudoku", "find_empty_location" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7e0c95b45be0b8c5c6c232469891a402b6fbc6a2
a17b96666f5d4e81f867756eaf7f32e1d67fdf4f
v1.0
instruct
Filter
Filter_58501_I
How can I generate a series of prime numbers in Python, specifically the prime numbers between 10 and 50?
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += ...
from solution import is_prime, generate_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_generate_primes(): assert generate_primes(10, 5...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a list of prime numbers between start and end.", "function_declaration": "def generate_primes(start, end):", ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058501", "row_id": 58501, "seed_ids": "['Qwen2.5-72B-Instruct_118454']" }
0.587737
Filter_58501
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d7b982051cc170a6dedf3ec70e5d54827e1bf52
0c7afce729edc5ef52e4f9aa6acd73eb5ef8137e
v1.0
instruct
Filter
Filter_58516_I
What are some popular count-and-say patterns in programming, and how do they work? Can you provide an example in Python?
def count_and_say(n): """ Generates the n-th term of the count-and-say sequence. """ if n == 1: return "1" prev_term = "1" for _ in range(1, n): prev_term = next_term(prev_term) return prev_term def next_term(s): """ Generates the next term in the count-and-say sequ...
from solution import count_and_say, next_term def test_count_and_say_1(): assert count_and_say(1) == "1" def test_count_and_say_2(): assert count_and_say(2) == "11" def test_count_and_say_3(): assert count_and_say(3) == "21" def test_count_and_say_4(): assert count_and_say(4) == "1211" def test_cou...
[ { "docstring": "Generates the n-th term of the count-and-say sequence.", "function_declaration": "def count_and_say(n):", "function_name": "count_and_say", "parameter_list": "(n)" }, { "docstring": "Generates the next term in the count-and-say sequence based on the current term s.", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_and_say(n):\n \"\"\"\n Generate the nth term in the count-and-say sequence.\n \n :param n: an integer indicating the position in sequence (1-indexed)\n :return: the nt...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058516", "row_id": 58516, "seed_ids": "['Qwen2.5-72B-Instruct_118488']" }
0.50009
Filter_58516
I
[ "count_and_say", "next_term" ]
2
[ [ "count_and_say", "next_term" ] ]
1
[]
false
[]
false
pytest
true
[]
true
36b19166139cabd04ebf7aeb90c90aadfd17e0fe
1baaaa11b4b7753a9214f0cd6aa1ed411eb2257e
v1.0
instruct
Filter
Filter_58525_I
Write a Python program to find all the prime numbers in a given range and store them in a list. The program should take start and end values for the range from the user and then print the list of prime numbers found within that range. Ensure to use a function to optimize readability and reusability.
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def find_primes_in_range(start, end): """ Returns a list of all prime numbe...
from solution import is_prime, find_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_find_primes_i...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers within the range [start, end].", "function_declaration": "def f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058525", "row_id": 58525, "seed_ids": "['Qwen2.5-72B-Instruct_118498']" }
0.610029
Filter_58525
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af7499bd69a7ce5620a59769e1acbe5c0df435b4
9d8b5c0f268684b6c1479bd01680134010220ac0
v1.0
instruct
Filter
Filter_58526_I
Explain the concept of call stack in programming and its role in function execution.
def func_a(): print("Entered func_a") func_b() print("Exited func_a") def func_b(): print("Entered func_b") func_c() print("Exited func_b") def func_c(): print("Entered func_c") print("Executed func_c") print("Exited func_c") # Initiate the function calls func_a()
from io import StringIO import sys def test_func_execution_order(): # Redirect stdout to capture print statements old_stdout = sys.stdout sys.stdout = StringIO() try: # Call the function func_a() # Get the output output = sys.stdout.getvalue().strip() ...
[ { "docstring": null, "function_declaration": "def func_a():", "function_name": "func_a", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def func_b():", "function_name": "func_b", "parameter_list": "()" }, { "docstring": null, "function_declara...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of a non-negative integer n using recursion.\n \"\"\"\n if n == 0:\n return 1\n else:\n return n * factorial(n -...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058526", "row_id": 58526, "seed_ids": "['Qwen2.5-72B-Instruct_118499']" }
0.340055
Filter_58526
I
[ "func_a", "func_b", "func_c" ]
3
[ [ "func_a", "func_b" ], [ "func_b", "func_c" ] ]
2
[]
false
[]
false
pytest
false
[]
true
078d4eafe039b47ccd8ee4081eeaf730062273aa
c441442bbf216ce89b094f9c421e1c54a18a7640
v1.0
instruct
Filter
Filter_58528_I
Task: Develop a Python program that reads a CSV file containing student grades, processes the data to calculate the average grade for each student, and then writes the results to a new CSV file with the student's name and their grade average.
import csv def read_grades(filename): grades = {} with open(filename, mode='r') as file: csv_reader = csv.reader(file) header = next(csv_reader) for row in csv_reader: student = row[0] scores = list(map(float, row[1:])) grades[student] = scores re...
import os import csv from solution import process_grades, read_grades, calculate_averages, write_averages def test_read_grades(tmp_path): input_file = tmp_path / "grades.csv" with open(input_file, mode='w', newline='') as file: csv_writer = csv.writer(file) csv_writer.writerow(["Student", "Grad...
[ { "docstring": null, "function_declaration": "def read_grades(filename):", "function_name": "read_grades", "parameter_list": "(filename)" }, { "docstring": null, "function_declaration": "def calculate_averages(grades):", "function_name": "calculate_averages", "parameter_list": "(...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef calculate_average_grades(input_filename, output_filename):\n \"\"\"\n Reads the CSV file containing student grades, calculates the average grade for each student,\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058528", "row_id": 58528, "seed_ids": "['Qwen2.5-72B-Instruct_118501']" }
0.693
Filter_58528
I
[ "read_grades", "calculate_averages", "write_averages", "process_grades" ]
4
[ [ "process_grades", "calculate_averages" ], [ "process_grades", "read_grades" ], [ "process_grades", "write_averages" ] ]
3
[]
false
[]
false
pytest
true
[]
true
12432bd4ad1970d63f26b8aa5453fdb5b4cb53f0
2ffbd9adab6b32f5cc0886709e05cb52185b8240
v1.0
instruct
Filter
Filter_58532_I
I'm looking for a basic guide on how to use functions in Python. Can you provide me with some key points on defining, calling, and the use of parameters and return values in functions?
# Key points on defining, calling, and using parameters and return values in functions in Python. def greet(name): """ Returns a greeting message for the given name. """ return f"Hello, {name}!" # Function definition def add(a, b): """ Returns the sum of a and b. """ return a + b # Fu...
from solution import greet, add, add_with_default, add_multiple, create_person, example_usage def test_greet(): assert greet("Alice") == "Hello, Alice!" assert greet("Bob") == "Hello, Bob!" def test_add(): assert add(2, 3) == 5 assert add(-1, 1) == 0 assert add(0, 0) == 0 def test_add_with_defaul...
[ { "docstring": "Returns a greeting message for the given name.", "function_declaration": "def greet(name):", "function_name": "greet", "parameter_list": "(name)" }, { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add", "pa...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def define_function_example(param1, param2):\n \"\"\"\n This function demonstrates a basic function with parameters and a return value.\n It takes two arguments, param1 and param2, an...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058532", "row_id": 58532, "seed_ids": "['Qwen2.5-72B-Instruct_118509']" }
0.532762
Filter_58532
I
[ "greet", "add", "add_with_default", "add_multiple", "create_person", "example_usage" ]
6
[ [ "example_usage", "add" ], [ "example_usage", "add_multiple" ], [ "example_usage", "add_with_default" ], [ "example_usage", "create_person" ], [ "example_usage", "greet" ] ]
5
[]
false
[]
false
pytest
true
[]
true
dd3824cb9d7a6f52eff5e62a5e83d70163674505
d6875ddec155d3d76cdd440f2b6db63e7f7be9ae
v1.0
instruct
Filter
Filter_58571_I
write a Python program to generate dictionary for Scrabble words. The program should load a list of words from a text file, then create a dictionary where the keys are the words and the values are the Scrabble scores of the words.
def load_words(filepath): """ Loads words from a text file and returns a list of words. Each word should be on a new line in the text file. """ with open(filepath, 'r') as file: words = file.read().splitlines() return words def calculate_scrabble_score(word): """ Calculates...
import os from solution import load_words, calculate_scrabble_score, generate_scrabble_dictionary def test_load_words(tmp_path): test_file = tmp_path / "test_words.txt" test_file.write_text("hello\nworld\nscrabble") words = load_words(test_file) assert words == ["hello", "world", "scrabble"] def ...
[ { "docstring": "Loads words from a text file and returns a list of words.\n\nEach word should be on a new line in the text file.", "function_declaration": "def load_words(filepath):", "function_name": "load_words", "parameter_list": "(filepath)" }, { "docstring": "Calculates and returns the ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def scrabble_score(word):\n \"\"\"\n Compute the Scrabble score for a given word.\n \"\"\"\n scores = {\n 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1,\n 'F': 4, 'G': 2, 'H...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058571", "row_id": 58571, "seed_ids": "['Qwen2.5-72B-Instruct_118585']" }
0.57446
Filter_58571
I
[ "load_words", "calculate_scrabble_score", "generate_scrabble_dictionary" ]
3
[ [ "generate_scrabble_dictionary", "calculate_scrabble_score" ], [ "generate_scrabble_dictionary", "load_words" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f10a756d7fa380b3a958b6d89f46f7d13c48b14
3edfec0455eb120b2ef6673efba46188b9b8db06
v1.0
instruct
Filter
Filter_58572_I
Create a Python function that serves as a simple logging utility, which not only prints a message but also writes it to a log file with a timestamp. The function should accept two parameters: the message to log and the log file's path. If the file does not exist, the function should create it. Format the timestamp to b...
from datetime import datetime def log_message(message, log_file_path): """ Logs a message to the console and writes it to the specified log file with a timestamp. If the log file does not exist, it creates it. :param message: The message to log. :param log_file_path: The path of the log file. ...
import os from solution import log_message, check_logging def test_log_message_creates_file(): log_file = 'test_log_creation.txt' if os.path.exists(log_file): os.remove(log_file) log_message("Testing file creation.", log_file) assert os.path.exists(log_file) def test_log_message_writes_correct...
[ { "docstring": "Logs a message to the console and writes it to the specified log file with a timestamp.\nIf the log file does not exist, it creates it.\n\n:param message: The message to log.\n:param log_file_path: The path of the log file.", "function_declaration": "def log_message(message, log_file_path):"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\n\ndef log_message(message, log_file_path):\n \"\"\"\n Logs a message to the specified log file with a timestamp.\n \n Parameters:\n message (str): The message t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058572", "row_id": 58572, "seed_ids": "['Qwen2.5-72B-Instruct_118588']" }
0.614694
Filter_58572
I
[ "log_message", "check_logging" ]
2
[ [ "check_logging", "log_message" ] ]
1
[]
false
[]
false
pytest
true
[]
true
177f8ffe08dd0b431b16e1bd071f307380d315e4
401e1859f3345b5591f1d873e3816e61b2ac4d62
v1.0
instruct
Filter
Filter_58574_I
Can you write a Python script that plots a>About two trigonometric functions, sine and cosine, with unique visual markers (one for each) over the range of 0 to \(2\pi\)? Make the sine markers square and the cosine markers diamond-shaped. Ensure the script is self-contained and includes necessary imports. Additionally, ...
import numpy as np import matplotlib.pyplot as plt def plot_trigonometric_functions(): """ Plots sine and cosine functions with unique visual markers over the range of 0 to 2π. """ x = np.linspace(0, 2 * np.pi, 100) y_sin = np.sin(x) y_cos = np.cos(x) plt.figure() # Plot sine ...
from solution import plot_trigonometric_functions def test_plot_trigonometric_functions(): # This is a visual check. Run the plot_trigonometric_functions() to visually verify. plot_trigonometric_functions()
[ { "docstring": "Plots sine and cosine functions with unique visual markers\nover the range of 0 to 2π.", "function_declaration": "def plot_trigonometric_functions():", "function_name": "plot_trigonometric_functions", "parameter_list": "()" }, { "docstring": null, "function_declaration": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\nimport numpy as np\n\ndef plot_trigonometric_functions():\n # Generate a range of values from 0 to 2*pi\n x = np.linspace(0, 2 * np.pi, 100)\n y_sin =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058574", "row_id": 58574, "seed_ids": "['Qwen2.5-72B-Instruct_118592']" }
0.615204
Filter_58574
I
[ "plot_trigonometric_functions", "check_plot" ]
2
[ [ "check_plot", "plot_trigonometric_functions" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
d19502de231cbf27498162c8dd9f3b033f2807e2
cc9f9d46f924eaeddd06b21bb56b31ae636a4ae1
v1.0
instruct
Filter
Filter_58619_I
Create a simple Hangman game in Python that works in the command line. The game should choose a random word from a list, and the player has 6 chances to guess the word. Display the correctly guessed letters and remaining attempts. Hints are optional.
import random def get_random_word(word_list): """ Selects a random word from a given list. """ return random.choice(word_list) def display_word_progress(word, guesses): """ Displays the current progress of the guessed word with underscores for missing letters. """ return ' '.join([lett...
import pytest from solution import get_random_word, display_word_progress, hangman def test_get_random_word(): word_list = ["python", "development", "hangman", "programming"] word = get_random_word(word_list) assert word in word_list def test_display_word_progress(): assert display_word_progress("hang...
[ { "docstring": "Selects a random word from a given list.", "function_declaration": "def get_random_word(word_list):", "function_name": "get_random_word", "parameter_list": "(word_list)" }, { "docstring": "Displays the current progress of the guessed word with underscores for missing letters....
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\nclass Hangman:\n def __init__(self, word_list):\n self.word_list = word_list\n self.word = random.choice(word_list)\n self.display = [\"_\"] * len(self...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058619", "row_id": 58619, "seed_ids": "['Qwen2.5-72B-Instruct_118686']" }
0.508417
Filter_58619
I
[ "get_random_word", "display_word_progress", "hangman" ]
3
[ [ "hangman", "display_word_progress" ], [ "hangman", "get_random_word" ] ]
2
[]
false
[]
false
pytest
true
[]
true
38a33a9800598b65b6f37f3b8da2a613b4f51b55
2fb171a3b2488f23ca6189b153e925db3fa14854
v1.0
instruct
Filter
Filter_58637_I
Create a Python function named `find_odd_kernel` that identifies the smallest odd number within the provided kernel size values of a 2D array (representing a part of an image or similar grid structure). The function should accept a 2D numpy array as input and return the smallest odd integer found within the array. If n...
import numpy as np def find_odd_kernel(kernel): """ Identifies the smallest odd number within the provided kernel values. Args: kernel (np.ndarray): 2D numpy array containing the kernel values. Returns: int or None: The smallest odd number found, or None if no odd numbers are present....
from solution import find_odd_kernel def test_no_odd_numbers(): assert find_odd_kernel(np.array([[2, 4, 6], [8, 10, 12]])) == None def test_multiple_odd_numbers(): assert find_odd_kernel(np.array([[3, 7, 9], [5, 1, 11]])) == 1 def test_all_odd_numbers(): assert find_odd_kernel(np.array([[1, 3, 5], [7, 9,...
[ { "docstring": "Identifies the smallest odd number within the provided kernel values.\n\nArgs:\nkernel (np.ndarray): 2D numpy array containing the kernel values.\n\nReturns:\nint or None: The smallest odd number found, or None if no odd numbers are present.", "function_declaration": "def find_odd_kernel(ker...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef find_odd_kernel(kernel):\n \"\"\"\n Identifies the smallest odd number within the provided 2D kernel.\n \n Parameters:\n kernel (np.ndarray): 2D array ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058637", "row_id": 58637, "seed_ids": "['Qwen2.5-72B-Instruct_118708']" }
0.624441
Filter_58637
I
[ "find_odd_kernel", "verify_solution" ]
2
[ [ "verify_solution", "find_odd_kernel" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
1b280becafa8b62190d1b33d98ec4f40621a796a
5f2e6ab36898b3c5d91cdffd727cf55d4f706c88
v1.0
instruct
Filter
Filter_58640_I
Write a Python program that generates a random 6-digit number, and then checks if the number is a palindrome. A palindrome is a number or word that reads the same backward as forward, such as 121 or 12321. The program should print the generated number and a message indicating whether it is a palindrome or not.
import random def generate_6_digit_number(): """ Generates a random 6-digit number. """ return random.randint(100000, 999999) def is_palindrome(number): """ Checks if a given number is a palindrome. """ str_number = str(number) return str_number == str_number[::-1] def check_palin...
from solution import generate_6_digit_number, is_palindrome def test_generate_6_digit_number_length(): number = generate_6_digit_number() assert 100000 <= number <= 999999 assert len(str(number)) == 6 def test_is_palindrome_true(): assert is_palindrome(123321) == True assert is_palindrome(111111) ...
[ { "docstring": "Generates a random 6-digit number.", "function_declaration": "def generate_6_digit_number():", "function_name": "generate_6_digit_number", "parameter_list": "()" }, { "docstring": "Checks if a given number is a palindrome.", "function_declaration": "def is_palindrome(numb...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_random_6_digit_number():\n \"\"\"\n Generates a random 6-digit number.\n \"\"\"\n return random.randint(100000, 999999)\n\ndef is_palindrome(number):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058640", "row_id": 58640, "seed_ids": "['Qwen2.5-72B-Instruct_118715']" }
0.72859
Filter_58640
I
[ "generate_6_digit_number", "is_palindrome", "check_palindrome" ]
3
[ [ "check_palindrome", "generate_6_digit_number" ], [ "check_palindrome", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b4372e4dea40b54dd3360ca3350d933d973decd6
36f74cd4c5e609108d5914cc075284023d517099
v1.0
instruct
Filter
Filter_58649_I
Design a Python subroutine to separate the digits from a given alphanumeric string and return them in a list. Additionally, ensure the function can also handle symbols or special characters gracefully, essentially ignoring them. Include a feature to optionally filter and return only prime numbers from the extracted dig...
def is_prime(n): """Check if a number is a prime number.""" if n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def extract_digits(s, only_primes=False): """ Extracts digits from the given alphanumeric string and retur...
from solution import extract_digits def test_extract_digits(): assert extract_digits('abc123!@#45D6') == [1, 2, 3, 4, 5, 6] def test_extract_digits_only_primes(): assert extract_digits('abc123!@#45D6', only_primes=True) == [2, 3, 5] def test_no_digits(): assert extract_digits('abc!@#D') == [] def test_o...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Extracts digits from the given alphanumeric string and returns them in a list.\nOptionally, return only prime numbers fro...
[ 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 \"\"\"Check if a number is a prime number.\"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n retu...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058649", "row_id": 58649, "seed_ids": "['Qwen2.5-72B-Instruct_118732']" }
0.592133
Filter_58649
I
[ "is_prime", "extract_digits" ]
2
[ [ "extract_digits", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ca946d8522c1afb9da6f85e8ca5de5be191aa44
f4695937fa530234401edaf792c069a6189f67ab
v1.0
instruct
Filter
Filter_58654_I
How can I automatically track user behavior on my website using Python, specifically capturing page views and clicks?
import datetime import json from flask import Flask, request, jsonify app = Flask(__name__) user_data_log = [] def log_user_behavior(user_id, action, details): """ Logs the user's behavior. """ entry = { 'timestamp': datetime.datetime.now().isoformat(), 'user_id': user_id, 'act...
import pytest from solution import app, user_data_log @pytest.fixture def client(): with app.test_client() as client: yield client def test_track_page_view(client): user_data_log.clear() response = client.post('/track', json={ 'user_id': 'user_123', 'action': 'page_view', '...
[ { "docstring": "Logs the user's behavior.", "function_declaration": "def log_user_behavior(user_id, action, details):", "function_name": "log_user_behavior", "parameter_list": "(user_id, action, details)" }, { "docstring": null, "function_declaration": "def track():", "function_name"...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\nimport json\nfrom flask import Flask, request, jsonify\n\napp = Flask(__name__)\nuser_data_log = []\n\ndef log_user_behavior(user_id, action, details):\n \"\"\"\n Logs t...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058654", "row_id": 58654, "seed_ids": "['Qwen2.5-72B-Instruct_118738']" }
0.416027
Filter_58654
I
[ "log_user_behavior", "track", "get_log" ]
3
[ [ "track", "log_user_behavior" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
ebeaf7dd778b6dac9a562bc06100ba0e99223f4d
ac14d8efa9599aaf404d41ef377d1489691d8e99
v1.0
instruct
Filter
Filter_58658_I
Write a Python program which takes a positive integer input from the user and checks whether the number is a prime number or not. The program should display an appropriate message based on the result.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime def test_prime_number(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True assert is_prime(11) == True def test_non_prime_number(): assert is_prime(1) == False assert is_prime(4) == False assert is_...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def check_prime():", "function_name": "check_prime", "paramete...
[ 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, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058658", "row_id": 58658, "seed_ids": "['Qwen2.5-72B-Instruct_118751']" }
0.764154
Filter_58658
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85f565b8949a7cc8c563ada8d21f14828fe582f9
acd26fda07d064c9307daff568595627bb86d9b6
v1.0
instruct
Filter
Filter_58676_I
Can you help me write a Python script that can monitor a directory for new files and automatically process them? I want to scan a specific folder for any new files added, and once a new file is detected, I want to run a function to process the file (e.g., print the file name to the console). How can I achieve this?
import os import time def process_file(filename): """ Function to process the new file. For demonstration, it prints the file name. """ print(f"Processing file: {filename}") def monitor_directory(directory): """ Monitor the specified directory for new files. """ print(f"Monitoring ...
import os import time from solution import process_file, monitor_directory import threading # Need to define some helper functions for the unit test def create_test_file(directory, filename, content="test"): with open(os.path.join(directory, filename), 'w') as f: f.write(content) def test_process_file(): ...
[ { "docstring": "Function to process the new file.\nFor demonstration, it prints the file name.", "function_declaration": "def process_file(filename):", "function_name": "process_file", "parameter_list": "(filename)" }, { "docstring": "Monitor the specified directory for new files.", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport time\n\ndef process_new_file(file_name):\n \"\"\"\n Function to process the new file\n \"\"\"\n print(f\"Processing new file: {file_name}\")\n\ndef monitor_direct...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058676", "row_id": 58676, "seed_ids": "['Qwen2.5-72B-Instruct_118781']" }
0.501899
Filter_58676
I
[ "process_file", "monitor_directory" ]
2
[ [ "monitor_directory", "process_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cff6d518df854bcd8ef2ad8d3e224d6227b54752
a9af5f72d9f25c49c1914b3cf7c3b2b94a8a5109
v1.0
instruct
Filter
Filter_58677_I
write python code to read from a file, encrypt its content using Caesar cipher and write the encrypted content to another file.
def caesar_cipher(text, shift): """ Encrypts the given text using the Caesar cipher with the specified shift. :param text: The input text to encrypt. :param shift: The number of positions to shift each character. :return: The encrypted text. """ result = [] for char in text: if ...
import os from solution import caesar_cipher, encrypt_file def test_caesar_cipher(): assert caesar_cipher("abc", 1) == "bcd" assert caesar_cipher("xyz", 3) == "abc" assert caesar_cipher("Hello, World!", 5) == "Mjqqt, Btwqi!" assert caesar_cipher("Mjqqt, Btwqi!", -5) == "Hello, World!" def test_encrypt...
[ { "docstring": "Encrypts the given text using the Caesar cipher with the specified shift.\n\n:param text: The input text to encrypt.\n:param shift: The number of positions to shift each character.\n:return: The encrypted text.", "function_declaration": "def caesar_cipher(text, shift):", "function_name":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar cipher with the specified shift.\n \n Parameters:\n text (str): The input text to be encr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058677", "row_id": 58677, "seed_ids": "['Qwen2.5-72B-Instruct_118782']" }
0.606134
Filter_58677
I
[ "caesar_cipher", "encrypt_file" ]
2
[ [ "encrypt_file", "caesar_cipher" ] ]
1
[]
false
[]
false
pytest
true
[]
true
923f1b3ded8883c654d3df2abd92977b4f680d5e
3efb43709f8a5e5f4ec31e4d05b88d4f7df1c05a
v1.0
instruct
Filter
Filter_58687_I
Write a python function that simulates the roll of a die (1-6) using random number generation, and then implement a loop that rolls the die 1000 times, keeping track of how many times each number is rolled. Finally, print the results. Include comments in your code to explain each part.
import random def roll_die(): """ Simulates the roll of a die and returns a number between 1 and 6. """ return random.randint(1, 6) def roll_die_1000_times(): """ Rolls the die 1000 times, keeping track of how many times each number is rolled. Prints the results. """ results = {i: ...
from solution import roll_die, roll_die_1000_times def test_roll_die(): # Check if the roll_die function returns a number between 1 and 6 for _ in range(100): result = roll_die() assert 1 <= result <= 6 def test_roll_die_1000_times(capsys): # Use capsys to capture print statements during t...
[ { "docstring": "Simulates the roll of a die and returns a number between 1 and 6.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Rolls the die 1000 times, keeping track of how many times each number is rolled.\nPrints the r...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates the roll of a die and returns a number between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef simulate_rolls(num_rolls...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058687", "row_id": 58687, "seed_ids": "['Qwen2.5-72B-Instruct_118796']" }
0.617858
Filter_58687
I
[ "roll_die", "roll_die_1000_times" ]
2
[ [ "roll_die_1000_times", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e55bf08a64eb0e7b70bf720ae3b0569f98d8168
89baf602b047fd7844c59dd6502ff38ef40c5b32
v1.0
instruct
Filter
Filter_58695_I
Sort an array using the merge sort algorithm. Input is an array of integers like [4, 2, 6, 1, 20, 11]. Implement merge sort in Python.
def merge_sort(arr): """ Sort an array using the merge sort algorithm. Parameters: arr (list): A list of integers to sort. Returns: list: A new sorted list. """ if len(arr) <= 1: return arr # Divide mid = len(arr) // 2 left = merge_sort(arr[:mid]) right...
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_sorted(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_unsorted(): assert merge_sort([4, 2, 6,...
[ { "docstring": "Sort an array using the merge sort algorithm.\n\nParameters:\narr (list): A list of integers to sort.\n\nReturns:\nlist: A new sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merge two ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array of integers using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n # Divide the array into two halve...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058695", "row_id": 58695, "seed_ids": "['Qwen2.5-72B-Instruct_118810']" }
0.714695
Filter_58695
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff701e4c9a0c14de1da062cfa0770158d197da00
fe8b9362228bf23f3a212b912341c6a320378026
v1.0
instruct
Filter
Filter_58711_I
Create a Python program that generates multiplication tables for numbers from 1 to 10 in a visually pleasing grid format. The output should look like a multiplication table where the left and top sides start at 0 and go up to 10, forming a square grid. The numbers in the grid should align properly for readability.
def generate_multiplication_table(): """ Generates and returns a multiplication table for numbers from 1 to 10. The table is formatted as a grid with proper alignment for readability. """ table = [] for i in range(11): row = [] for j in range(11): row.append(i * j) ...
from solution import generate_multiplication_table, format_table def test_generate_multiplication_table(): table = generate_multiplication_table() assert table[0] == [i * 0 for i in range(11)] assert table[1] == [i * 1 for i in range(11)] assert table[5] == [i * 5 for i in range(11)] assert table[1...
[ { "docstring": "Generates and returns a multiplication table for numbers from 1 to 10.\nThe table is formatted as a grid with proper alignment for readability.", "function_declaration": "def generate_multiplication_table():", "function_name": "generate_multiplication_table", "parameter_list": "()" ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_multiplication_table():\n \"\"\"\n Generates a multiplication table for numbers from 0 to 10.\n Returns a formatted string representing the multiplication table.\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058711", "row_id": 58711, "seed_ids": "['Qwen2.5-72B-Instruct_118842']" }
0.516961
Filter_58711
I
[ "generate_multiplication_table", "format_table", "print_multiplication_table" ]
3
[ [ "print_multiplication_table", "format_table" ], [ "print_multiplication_table", "generate_multiplication_table" ] ]
2
[]
false
[]
false
pytest
true
[]
true
86dd1a42af97976e7c79be5ddc88fd769efeeb2a
2676e06bdd84d02a47f622b74ba932c6ee47540c
v1.0
instruct
Filter
Filter_58746_I
Write a Python script to periodically check the availability of a list of websites and log the up-time and response time. The script should run every 5 minutes. How can this be done?
import requests import time import logging # Configure logging logging.basicConfig(filename='website_status.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def check_website(url): """ Check the availability and response time of a website. Args: u...
from solution import check_website import requests from unittest.mock import patch def test_check_website_up(): with patch('requests.get') as mocked_get: mocked_get.return_value.status_code = 200 mocked_get.return_value.elapsed.total_seconds.return_value = 0.123 availability, response_time ...
[ { "docstring": "Check the availability and response time of a website.\n\nArgs:\nurl (str): The URL of the website to check.\n\nReturns:\ntuple: availability (bool), response time in seconds (float or None)", "function_declaration": "def check_website(url):", "function_name": "check_website", "param...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nimport time\nfrom datetime import datetime\n\nwebsites = [\"https://www.google.com\", \"https://www.github.com\", \"https://www.python.org\"]\nlog_file = \"website_status.log\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058746", "row_id": 58746, "seed_ids": "['Qwen2.5-72B-Instruct_118903']" }
0.617042
Filter_58746
I
[ "check_website", "monitor_websites" ]
2
[ [ "monitor_websites", "check_website" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
43a26401695c47f2d5f764d0373a66866c591ee1
f5092e33c66f0cd0173655c1683dcce80c1952d6
v1.0
instruct
Filter
Filter_58748_I
Can you provide an example of a Python script that reads a list of file names from a directory, filters out only the `.txt` files, and prints them in alphabetical order?
import os def get_txt_files(directory): """ Reads a list of file names from the directory, filters out only the `.txt` files, and returns them in alphabetical order. :param directory: Path to the directory. :return: List of `.txt` files in alphabetical order. """ try: files = o...
import os import pytest from solution import get_txt_files def setup_module(module): os.makedirs('test_dir', exist_ok=True) open('test_dir/a.txt', 'a').close() open('test_dir/b.txt', 'a').close() open('test_dir/c.doc', 'a').close() open('test_dir/d.txt', 'a').close() open('test_dir/e.jpg', 'a')...
[ { "docstring": "Reads a list of file names from the directory, filters out only the `.txt` files,\nand returns them in alphabetical order.\n\n:param directory: Path to the directory.\n:return: List of `.txt` files in alphabetical order.", "function_declaration": "def get_txt_files(directory):", "functio...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef list_txt_files(directory):\n \"\"\"\n Reads the list of file names from a directory, filters out only the .txt files,\n and returns them in alphabetical order.\n \...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058748", "row_id": 58748, "seed_ids": "['Qwen2.5-72B-Instruct_118911']" }
0.620858
Filter_58748
I
[ "get_txt_files", "print_txt_files" ]
2
[ [ "print_txt_files", "get_txt_files" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14b038ca3b81b15b24e9ecf84835ba39ca38d504
9490d173b45d836b421281b73095f84baf9ee0d2
v1.0
instruct
Filter
Filter_58761_I
How can I train a neural network to perform sentiment analysis on product reviews using PyTorch?
import torch from torch.utils.data import DataLoader, TensorDataset from torch.nn import functional as F from torch import nn, optim from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder from sklearn.feature_extraction.text import CountVectorizer # Sample function to prepr...
def test_preprocess_data(): reviews = ["I love this product", "This is the worst purchase I have made"] labels = ["positive", "negative"] X, y, vectorizer = preprocess_data(reviews, labels) assert X.shape[0] == 2 assert X.shape[1] > 0 # Check that we have features assert len(y) == 2 as...
[]
[ 0, 0, 1 ]
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 torchtext.legacy.data import Field, LabelField, TabularDataset, BucketIterator\n\n# Define fields\nTEXT = Field(tokenize=...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058761", "row_id": 58761, "seed_ids": "['Qwen2.5-72B-Instruct_118933']" }
0.504547
Filter_58761
I
[ "preprocess_data", "train_sentiment_model" ]
2
[ [ "train_sentiment_model", "preprocess_data" ] ]
1
[]
false
[ "SentimentNet" ]
true
pytest
false
[ "sklearn", "torch" ]
false
ea5bd4eb2484fd73780f9511b42b708911f2b6e3
dff9b18cb6e6c9bb8c82d3b016c63a91659499d6
v1.0
instruct
Filter
Filter_58780_I
Write a Python function to find the number of records with prime numeric values in a given position of a list of integers. The function should take a list of integers and the index as inputs and return the count of those records whose value at the specified index is a prime number.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def count_primes_at_index(arr, index): """ Count the number of records with prime numeric values at a give...
from solution import is_prime, count_primes_at_index def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(0) == False assert is_prime(1) == False def test_count_primes_at_index(): assert count_prim...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Count the number of records with prime numeric values at a given index.", "function_declaration": "def count_primes_at_index(a...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import isqrt\n\ndef is_prime(n):\n if n < 2:\n return False\n for i in range(2, isqrt(n) + 1):\n if n % i == 0:\n return False\n return True\n\ndef ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058780", "row_id": 58780, "seed_ids": "['Qwen2.5-72B-Instruct_118966']" }
0.705893
Filter_58780
I
[ "is_prime", "count_primes_at_index" ]
2
[ [ "count_primes_at_index", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c2e84e929a20215f3b660a3e75493c60ff95721
92c7fb845f92d6d019b63bdd5887caaaf319ca74
v1.0
instruct
Filter
Filter_58800_I
Design a basic algorithm that creates a simple 3D representation of a cube using 2D graphics. Explain how the algorithm works and what programming concepts or tools it utilizes.
import matplotlib.pyplot as plt def project_vertex(vertex): """ Projects a 3D vertex to 2D using perspective projection. Args: vertex (tuple): A tuple of (x, y, z) coordinates in 3D. Returns: tuple: A tuple of (x, y) coordinates in 2D. """ x, y, z = vertex if z...
def test_project_vertex(): # Test the projection function for known inputs and outputs assert project_vertex((0, 0, 1)) == (0, 0) assert project_vertex((1, 0, 1)) == (1, 0) assert project_vertex((0, 1, 1)) == (0, 1) assert project_vertex((1, 1, 1)) == (1, 1) assert project_vertex((-1, -1, 1)) ==...
[ { "docstring": "Projects a 3D vertex to 2D using perspective projection.\n\nArgs:\n vertex (tuple): A tuple of (x, y, z) coordinates in 3D.\n \nReturns:\n tuple: A tuple of (x, y) coordinates in 2D.", "function_declaration": "def project_vertex(vertex):", "function_name": "project_vertex", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\n\ndef project_vertex(vertex):\n \"\"\"\n Projects a 3D vertex to 2D using perspective projection.\n \n Args:\n vertex (tuple): A tuple of (x...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058800", "row_id": 58800, "seed_ids": "['Qwen2.5-72B-Instruct_118997']" }
0.465774
Filter_58800
I
[ "project_vertex", "draw_cube" ]
2
[ [ "draw_cube", "project_vertex" ] ]
1
[]
false
[]
false
pytest
false
[ "matplotlib" ]
false
fdb1346072b1503d2e16a12f768d05bc02c95a0a
13c8f55f3466d7d3288e03d1478051e000c343e1
v1.0
instruct
Filter
Filter_58801_I
Write a Python function to model an exponential function with parameters that can be adjusted for the rate and the initial value. Then, write a function to simulate noisy data as a ‘ground truth’ to test this model. The noisy data should be based on the exponential function but with some random noise added to simulate ...
import numpy as np import scipy.optimize def exponential_model(x, a, b): """ Models an exponential function of the form: a * exp(b * x) Parameters: x (float): The input value. a (float): The initial value (scaling factor). b (float): The rate of growth. Returns: float: The val...
from solution import exponential_model, generate_noisy_data, fit_exponential_model import numpy as np def test_exponential_model(): assert np.isclose(exponential_model(0, 2, 0.5), 2) assert np.isclose(exponential_model(1, 2, 0.5), 2 * np.exp(0.5)) def test_generate_noisy_data(): x_vals = np.array([0, 1, 2...
[ { "docstring": "Models an exponential function of the form: a * exp(b * x)\n\nParameters:\nx (float): The input value.\na (float): The initial value (scaling factor).\nb (float): The rate of growth.\n\nReturns:\nfloat: The value of the exponential function at x.", "function_declaration": "def exponential_mo...
[ 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\nfrom scipy.optimize import curve_fit\n\ndef exponential_function(t, a, b):\n \"\"\"\n Exponential function a * exp(b * t).\n \n :param t: Time variable\n :pa...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058801", "row_id": 58801, "seed_ids": "['Qwen2.5-72B-Instruct_118998']" }
0.508684
Filter_58801
I
[ "exponential_model", "generate_noisy_data", "fit_exponential_model" ]
3
[ [ "fit_exponential_model", "exponential_model" ], [ "generate_noisy_data", "exponential_model" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
afa9ab529fa76db09bd248096bbc29f7aeba04ad
d19bdf78fefbe47e278cd13409294f809fa51c4e
v1.0
instruct
Filter
Filter_58857_I
What are the specific steps to create and train a deep learning model using PyTorch, and what best practices can be applied throughout this process?
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, Dataset # Define a simple Dataset class SimpleDataset(Dataset): def __init__(self, data, targets): super().__init__() self.data = data self.targets = targets def __len__(self): ...
import torch from solution import SimpleNN, train_model, SimpleDataset from torch.utils.data import DataLoader import torch.nn as nn import torch.optim as optim def test_model_initialization(): model = SimpleNN() assert isinstance(model.fc1, nn.Linear) assert isinstance(model.fc2, nn.Linear) def test_data...
[]
[ 1, 0 ]
1
medium
0.5
{ "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, Dataset\n\n# Define a simple Dataset\nclass SimpleDataset(Dataset):\n def __init__...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058857", "row_id": 58857, "seed_ids": "['Qwen2.5-72B-Instruct_119103']" }
0.27883
Filter_58857
I
[ "train_model", "run_training_example" ]
2
[ [ "run_training_example", "train_model" ] ]
1
[]
false
[ "SimpleDataset", "SimpleNN" ]
true
pytest
true
[ "torch" ]
false
859c52d464690c4b91f5ea92f8da730e473b5c5a
fbbac4af31e09c16c402463ecf63edf1b3def734
v1.0
instruct
Filter
Filter_58866_I
Write a Python program to check if a number is a prime palindrome. A prime palindrome is a number that is both a prime number and a palindrome. For instance, 131 and 3 are prime palindromes, but 10 and 22 are not. The program should take an integer as input and return True if the number is a prime palindrome, and False...
def is_prime(n): """ Returns True if the number n is a prime number, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return T...
from solution import is_prime_palindrome def test_is_prime_palindrome_true_cases(): assert is_prime_palindrome(2) == True assert is_prime_palindrome(3) == True assert is_prime_palindrome(5) == True assert is_prime_palindrome(7) == True assert is_prime_palindrome(11) == True assert is_prime_pali...
[ { "docstring": "Returns True if the number n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns True if the number n is a palindrome, False otherwise.", "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 Checks if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058866", "row_id": 58866, "seed_ids": "['Qwen2.5-72B-Instruct_119117']" }
0.705657
Filter_58866
I
[ "is_prime", "is_palindrome", "is_prime_palindrome" ]
3
[ [ "is_prime_palindrome", "is_palindrome" ], [ "is_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5f18d8f5e806564f1ef3cb6939e164dc9f610d4f
9c0110cc738fd9384525b920359be8ba520dd09c
v1.0
instruct
Filter
Filter_58869_I
Use Python to determine if two line segments intersect. The line segments are defined by their endpoints, for example, line segment 1 is defined by endpoints (x1, y1) and (x2, y2), and line segment 2 is defined by endpoints (x3, y3) and (x4, y4).
def on_segment(p, q, r): """ Given three collinear points p, q, r, check if point q lies on line segment 'pr' """ if (q[0] <= max(p[0], r[0]) and q[0] >= min(p[0], r[0]) and q[1] <= max(p[1], r[1]) and q[1] >= min(p[1], r[1])): return True return False def orientation(p, q, r): "...
from solution import do_intersect def test_no_intersection(): assert not do_intersect((1, 1), (10, 1), (1, 2), (10, 2)) def test_intersection(): assert do_intersect((1, 1), (10, 1), (1, 1), (10, 10)) def test_collinear_and_intersecting(): assert do_intersect((1, 1), (10, 1), (5, 1), (15, 1)) def test_co...
[ { "docstring": "Given three collinear points p, q, r, check if point q lies on line segment 'pr'", "function_declaration": "def on_segment(p, q, r):", "function_name": "on_segment", "parameter_list": "(p, q, r)" }, { "docstring": "Find the orientation of the ordered triplet (p, q, r).\n0 -> ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def on_segment(p, q, r):\n \"\"\"\n Given three collinear points p, q, r, check if point q lies on line segment 'pr'\n \"\"\"\n if (q[0] <= max(p[0], r[0]) and q[0] >= min(p[0], r[...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058869", "row_id": 58869, "seed_ids": "['Qwen2.5-72B-Instruct_119123']" }
0.532678
Filter_58869
I
[ "on_segment", "orientation", "do_intersect" ]
3
[ [ "do_intersect", "on_segment" ], [ "do_intersect", "orientation" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8d5096d652e160df5e9829bbc1ce43b3c1fd6018
1d00afd4c37332c5eaccb5e30a31ba159ccd72fe
v1.0
instruct
Filter
Filter_58888_I
How can I create a Python script that monitors the system's memory usage on a Linux system and sends an alert when the usage exceeds 80%?
import psutil import smtplib def send_alert(subject, message, from_email, to_email, smtp_server, smtp_port, smtp_user, smtp_password): """ Sends an email alert. """ with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() server.login(smtp_user, smtp_password) emai...
import pytest from unittest.mock import patch, Mock import psutil from solution import check_memory_usage, send_alert def test_check_memory_usage_below_threshold(): with patch.object(psutil, 'virtual_memory', return_value=Mock(percent=50)): usage = check_memory_usage(threshold=80) assert usage == 5...
[ { "docstring": "Sends an email alert.", "function_declaration": "def send_alert(subject, message, from_email, to_email, smtp_server, smtp_port, smtp_user, smtp_password):", "function_name": "send_alert", "parameter_list": "(subject, message, from_email, to_email, smtp_server, smtp_port, smtp_user, s...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import psutil\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nimport time\n\ndef send_alert(subject, body, to_email):\n \"\"\"\n Se...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058888", "row_id": 58888, "seed_ids": "['Qwen2.5-72B-Instruct_119157']" }
0.637423
Filter_58888
I
[ "send_alert", "check_memory_usage" ]
2
[ [ "check_memory_usage", "send_alert" ] ]
1
[]
false
[]
false
pytest
true
[ "psutil" ]
false
2b4148a21ee02aa338f1f49e674d50268213bd4f
f98bac07ee149ce082ca19601ccf8bffa58bf7e7
v1.0
instruct
Filter
Filter_58922_I
How can I use AWS Lambda to create a serverless application that processes images uploaded to an S3 bucket and resizes them?
import json import boto3 from PIL import Image import io s3_client = boto3.client('s3') def resize_image(image_data, resized_width, resized_height): with Image.open(io.BytesIO(image_data)) as img: img = img.resize((resized_width, resized_height)) output = io.BytesIO() img.save(output, form...
from solution import resize_image from PIL import Image import io def test_resize_image(): # Create a simple image original_image = Image.new('RGB', (256, 256), color = 'red') original_buffer = io.BytesIO() original_image.save(original_buffer, format="PNG") original_data = original_buffer.getvalue(...
[ { "docstring": null, "function_declaration": "def resize_image(image_data, resized_width, resized_height):", "function_name": "resize_image", "parameter_list": "(image_data, resized_width, resized_height)" }, { "docstring": null, "function_declaration": "def lambda_handler(event, context...
[ 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 PIL import Image\nimport io\n\ns3 = boto3.client('s3')\n\ndef lambda_handler(event, context):\n # Get the S3 bucket and object from the event data\n bucket_name = even...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00058922", "row_id": 58922, "seed_ids": "['Qwen2.5-72B-Instruct_119215']" }
0.356897
Filter_58922
I
[ "resize_image", "lambda_handler" ]
2
[ [ "lambda_handler", "resize_image" ] ]
1
[]
false
[]
false
pytest
true
[ "PIL", "boto3" ]
false
72219982d66f1d87f6a9dfc8529f9d59944ea603
3b2671dbb001513029a2e52ed2124853f0e51ef6
v1.0
instruct
Filter
Filter_58940_I
Design a convex optimization algorithm in Python to solve an optimization problem. The problem is to minimize the function f(x) = x^2, subject to the constraint x >= 0. Use the SciPy library for this purpose. Make sure your code is well-commented and include a check to verify that the solution is indeed x = 0.
from scipy.optimize import minimize def objective_function(x): """ The objective function to minimize: f(x) = x^2 """ return x**2 def solve_optimization(): """ Solves the optimization problem to minimize f(x) = x^2 subject to x >= 0. Returns: result: The optimization result ob...
from solution import solve_optimization def test_optimization_solution(): result = solve_optimization() # Check if the solver was successful assert result.success, "The optimization solver did not succeed." # Check if the solution is indeed x = 0 assert abs(result.x[0]) < 1e-6, "The solut...
[ { "docstring": "The objective function to minimize: f(x) = x^2", "function_declaration": "def objective_function(x):", "function_name": "objective_function", "parameter_list": "(x)" }, { "docstring": "Solves the optimization problem to minimize f(x) = x^2 subject to x >= 0.\n\nReturns:\n ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from scipy.optimize import minimize\n\ndef objective_function(x):\n \"\"\"\n The objective function to minimize: f(x) = x^2\n \"\"\"\n return x**2\n\ndef solve_optimization():\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00058940", "row_id": 58940, "seed_ids": "['Qwen2.5-72B-Instruct_119247']" }
0.48887
Filter_58940
I
[ "objective_function", "solve_optimization" ]
2
[ [ "solve_optimization", "objective_function" ] ]
1
[]
false
[]
false
pytest
true
[ "scipy" ]
false
1a5b0d9558ab11e9e0f35889c8ad81de4c50dbb8
fd55fd820dad4717d3eb6bbb020f486d4a7fe716
v1.0
instruct
Filter
Filter_58991_I
Write a Python function that takes in a single parameter, the name of a Nim number (not the actual number, but a string such as "six", "minusFive", or "zero"), and returns a list of possible Python variable names that represent the number 6 more than the given Nim number. The returned list should be sorted alphabetical...
import keyword def to_number(nim_number): nim_to_num = { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, "ten": 10, "minusFive": -5 # Add more mappings as per requirements } return nim_to_num.get(nim_number, None) def ge...
from solution import generate_variable_names def test_generate_variable_names_one(): assert generate_variable_names("one") == ["num_7", "number7", "val7", "value_7"] def test_generate_variable_names_zero(): assert generate_variable_names("zero") == ["num_6", "number6", "val6", "value_6"] def test_generate_va...
[ { "docstring": null, "function_declaration": "def to_number(nim_number):", "function_name": "to_number", "parameter_list": "(nim_number)" }, { "docstring": null, "function_declaration": "def generate_variable_names(nim_number):", "function_name": "generate_variable_names", "param...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import keyword\n\ndef nim_number_to_int(nim_number):\n \"\"\"\n Given the name of a Nim number as a string, returns the integer it represents.\n \"\"\"\n nim_to_int = {\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058991", "row_id": 58991, "seed_ids": "['Qwen2.5-72B-Instruct_119348']" }
0.520745
Filter_58991
I
[ "to_number", "generate_variable_names" ]
2
[ [ "generate_variable_names", "to_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a3b96704d757b6883d9ddaa78b6eceb75e2ae3da
c6a22736c2edc5b9a5cb34404300d661811fe1fd
v1.0
instruct
Filter
Filter_58993_I
Code a function in Python that downloads a large file from a URL and shows progress, ensuring that the download does not fail if the network is interrupted. The function should also verify the integrity of the downloaded file using MD5 checksum after the download completes.
import os import requests from tqdm import tqdm import hashlib def download_file_with_progress(url, output_path, checksum): """ Downloads a large file from a URL with a progress bar and verifies the file integrity using MD5 checksum. Parameters: - url: str, the URL from which to download the file....
import os import pytest from solution import download_file_with_progress, verify_md5_integrity # Sample URL and MD5 for testing TEST_URL = "https://example.com/samplefile.zip" TEST_OUTPUT_PATH = "samplefile.zip" TEST_MD5 = "d41d8cd98f00b204e9800998ecf8427e" # MD5 for an empty file (for example) def test_verify_md5_i...
[ { "docstring": "Downloads a large file from a URL with a progress bar and verifies the file integrity using MD5 checksum.\n\nParameters:\n- url: str, the URL from which to download the file.\n- output_path: str, the path to save the downloaded file.\n- checksum: str, the expected MD5 checksum of the file.\n\nRe...
[ 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 tqdm import tqdm\nimport hashlib\nimport os\n\ndef download_file_with_resume(url, dest_file, expected_md5=None):\n \"\"\"\n Download a file from a URL and show prog...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00058993", "row_id": 58993, "seed_ids": "['Qwen2.5-72B-Instruct_119354']" }
0.652561
Filter_58993
I
[ "download_file_with_progress", "verify_md5_integrity" ]
2
[ [ "download_file_with_progress", "verify_md5_integrity" ] ]
1
[]
false
[]
false
pytest
true
[ "requests", "tqdm" ]
false
81d1e3d9a7338848580dd18a804edd5fecf77625
797da766e8d091c8c1e025b6ec98c5814b633683
v1.0
instruct
Filter
Filter_59006_I
Design a CHARSET encoding converter that can convert between different character encoding formats, such as from UTF-8 to GBK. The tool should provide a user-friendly interface, support batch conversion of text files, and be able to handle conversion errors gracefully, logging them for review.
import os import logging # Setting up logging logging.basicConfig(filename='conversion_errors.log', level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') def convert_charset(file_path, src_encoding, dest_encoding): """ Convert the character set encoding of a file from sr...
import os import pytest from solution import convert_charset, batch_convert_charset # Create temporary files for testing @pytest.fixture def create_temp_files(tmp_path): # File paths file_paths = [] for i in range(3): file_path = tmp_path / f'test_file_{i}.txt' with open(file_path, 'w', enc...
[ { "docstring": "Convert the character set encoding of a file from src_encoding to dest_encoding.\nArgs:\nfile_path (str): Path to the text file to convert.\nsrc_encoding (str): Source encoding format.\ndest_encoding (str): Destination encoding format.\n\nReturns:\nbool: Returns True if conversion is successful,...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport logging\n\n# Setting up logging\nlogging.basicConfig(filename='conversion_errors.log', level=logging.ERROR,\n format='%(asctime)s - %(levelname)s - %(messa...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00059006", "row_id": 59006, "seed_ids": "['Qwen2.5-72B-Instruct_119373']" }
0.471822
Filter_59006
I
[ "convert_charset", "batch_convert_charset" ]
2
[ [ "batch_convert_charset", "convert_charset" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eef3b09a6aa2c324a78c80f7b4800b7c0c8ff516
84561b63fe426ef1b90d0082ef5a3d06cb237334
v1.0
instruct
Filter
Filter_59020_I
Can you help me design a small program that generates random numbers and uses them to simulate the rolling of a six-sided die? I want to be able to run the simulation multiple times and record the outcomes.
import random def roll_die(): """ Simulates rolling a six-sided die and returns the result. """ return random.randint(1, 6) def simulate_rolls(num_rolls): """ Simulates rolling a six-sided die num_rolls times and returns a list of outcomes. """ outcomes = [] for _ in range(num_roll...
from solution import roll_die, simulate_rolls def test_roll_die(): for _ in range(100): # Test multiple times to check different possible outcomes outcome = roll_die() assert 1 <= outcome <= 6, f"Outcome should be between 1 and 6, got {outcome}" def test_simulate_rolls_length(): num_rolls = 1...
[ { "docstring": "Simulates rolling a six-sided die and returns the result.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Simulates rolling a six-sided die num_rolls times and returns a list of outcomes.", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates the rolling of a six-sided die and returns the outcome.\n \"\"\"\n return random.randint(1, 6)\n\ndef simulate_rolls(n):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00059020", "row_id": 59020, "seed_ids": "['Qwen2.5-72B-Instruct_119395']" }
0.517221
Filter_59020
I
[ "roll_die", "simulate_rolls" ]
2
[ [ "simulate_rolls", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
391289f0e89eb01b00df8a3aee6972e85ab4fa22
54fd3cba511aaacee860d20a88a06940642dba9f
v1.0
instruct
Filter
Filter_59058_I
Generate an optimization algorithm in Python for the traveling salesman problem using a genetic algorithm. The goal is to find the shortest route that visits each city exactly once and returns to the origin city. Assume the cities and distances are provided in the form of a 2D list, with the distances between the citie...
import random import numpy as np def create_distance_matrix(num_cities): """Generates a random distance matrix for a given number of cities.""" matrix = np.random.randint(1, 100, size=(num_cities, num_cities)) np.fill_diagonal(matrix, 0) return matrix.tolist() def create_initial_population(pop_size, n...
from solution import create_distance_matrix, genetic_algorithm import numpy as np def test_create_distance_matrix(): matrix = create_distance_matrix(5) assert len(matrix) == 5 assert all(len(row) == 5 for row in matrix) assert all(matrix[i][i] == 0 for i in range(5)) def test_genetic_algorithm(): ...
[ { "docstring": "Generates a random distance matrix for a given number of cities.", "function_declaration": "def create_distance_matrix(num_cities):", "function_name": "create_distance_matrix", "parameter_list": "(num_cities)" }, { "docstring": "Generates an initial population of routes.", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport numpy as np\n\ndef create_distance_matrix(num_cities):\n \"\"\"Generates a random distance matrix for a given number of cities.\"\"\"\n matrix = np.random.randint(1...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00059058", "row_id": 59058, "seed_ids": "['Qwen2.5-72B-Instruct_119467']" }
0.534783
Filter_59058
I
[ "create_distance_matrix", "create_initial_population", "calculate_fitness", "selection", "crossover", "mutate", "genetic_algorithm" ]
7
[ [ "genetic_algorithm", "calculate_fitness" ], [ "genetic_algorithm", "create_initial_population" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "selection" ] ]
5
[]
false
[]
false
pytest
true
[ "numpy" ]
false
35def692b8a80d618d3d10979458fe067ccfc048
4ee66ac995ed6125546820c9183fea9289e2defe
v1.0
instruct
Filter
Filter_59065_I
Build a Python module to perform the Lane-Emden equation for spherically symmetric polytropes. The module should accept polytropic index (n) and density parameter (ψ) as inputs and return the dimensionless radius (ξ) and the dimensionless density (θ) as outputs. Make sure to use appropriate numerical methods for solvin...
import numpy as np from scipy.integrate import solve_ivp def lane_emden_rhs(xi, y, n): """ Right-hand side of the Lane-Emden equation. Parameters: xi (float): dimensionless radius. y (list of float): [theta, theta'] n (float): polytropic index. Returns: list of float: [theta', theta''...
import numpy as np from solution import lane_emden def test_lane_emden_boundary_conditions(): xi, theta = lane_emden(1) assert np.isclose(theta[0], 1), "Theta at xi=0 should be close to 1" assert np.isclose(xi[0], 1e-5), "xi should start from a small value close to 0" def test_lane_emden_polytropic_index_...
[ { "docstring": "Right-hand side of the Lane-Emden equation.\n\nParameters:\nxi (float): dimensionless radius.\ny (list of float): [theta, theta']\nn (float): polytropic index.\n\nReturns:\nlist of float: [theta', theta'']", "function_declaration": "def lane_emden_rhs(xi, y, n):", "function_name": "lane_...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom scipy.integrate import solve_ivp\n\ndef lane_emden(n, psi, max_xi=10, num_points=1000):\n \"\"\"\n Solves the Lane-Emden equation for a given polytropic index n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00059065", "row_id": 59065, "seed_ids": "['Qwen2.5-72B-Instruct_119484']" }
0.384736
Filter_59065
I
[ "lane_emden_rhs", "lane_emden" ]
2
[ [ "lane_emden", "lane_emden_rhs" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
6de369ccf0bd73b7196b41d679621d79b3ddcc5c
bceca3530a88936709b4fad6bf6599be05ac5189
v1.0
instruct
Filter
Filter_59067_I
Write a Python script to monitor a Raspberry Pi's temperature and log it to a file every 10 minutes.
import os import time from datetime import datetime def get_cpu_temperature(): """Returns the CPU temperature as a float.""" temp_str = os.popen("vcgencmd measure_temp").readline() temp = float(temp_str.replace("temp=", "").replace("'C\n", "")) return temp def log_temperature(filename): """Logs th...
from solution import get_cpu_temperature, log_temperature import tempfile import os def test_get_cpu_temperature(monkeypatch): # Simulate the output of 'vcgencmd measure_temp' command def mock_popen(*args, **kwargs): class MockProcess: def readline(self): return "temp=55.0'C...
[ { "docstring": "Returns the CPU temperature as a float.", "function_declaration": "def get_cpu_temperature():", "function_name": "get_cpu_temperature", "parameter_list": "()" }, { "docstring": "Logs the current CPU temperature to the given filename.", "function_declaration": "def log_tem...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport time\nfrom datetime import datetime\n\ndef get_temperature():\n \"\"\"\n Get the temperature of the Raspberry Pi.\n \"\"\"\n temp = os.popen(\"vcgencmd measure_te...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00059067", "row_id": 59067, "seed_ids": "['Qwen2.5-72B-Instruct_119487']" }
0.544357
Filter_59067
I
[ "get_cpu_temperature", "log_temperature", "start_logging" ]
3
[ [ "log_temperature", "get_cpu_temperature" ], [ "start_logging", "log_temperature" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9f90bd60a2559f8a0b3c31b776b96f21a760f481
c438d07aa6edd5b3c34630968ac16f74be05fa5b