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_46415_I | What is the best way to develop a deep learning model for text classification using PyTorch? | import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, Dataset
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.feature_extraction.text import CountVectorizer
class TextClassificationDataset(Dataset):
d... | import torch
from solution import TextClassifier, generate_batch, train_model, evaluate_model
# Check if the dataset construction is working correctly
def test_text_classification_dataset():
texts = ["I love programming", "PyTorch is great"]
labels = [0, 1]
dataset = TextClassificationDataset(texts, labels... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import DataLoader, Dataset\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preproces... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046415",
"row_id": 46415,
"seed_ids": "['Qwen2.5-72B-Instruct_98583']"
} | 0.412888 | Filter_46415 | I | [
"generate_batch",
"train_model",
"evaluate_model",
"construct_model"
] | 4 | [
[
"construct_model",
"evaluate_model"
],
[
"construct_model",
"train_model"
]
] | 2 | [] | false | [
"TextClassificationDataset",
"TextClassifier"
] | true | pytest | true | [
"sklearn",
"torch"
] | false | 6def5f9a991b746b0968ef5a8a578607c65ee611 | 8967f9a008ca0a23f947ba289bd5d738321240f7 | |||
v1.0 | instruct | Filter | Filter_46434_I | Given a list of integers, write a Python function to filter out the numbers that are multiples of 4. Then, from the remaining numbers, return a list of numbers that are also prime. Ensure your solution is efficient and clean. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | import pytest
from solution import filter_and_find_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(6) == False
assert is_prime(29) == True
def test_filter_and_find_primes_no_mult_... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, filter out the numbers that are multiples of 4\nand return a list of numbers that are also prim... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046434",
"row_id": 46434,
"seed_ids": "['Qwen2.5-72B-Instruct_98615']"
} | 0.608115 | Filter_46434 | I | [
"is_prime",
"filter_and_find_primes"
] | 2 | [
[
"filter_and_find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63e0b2081c47ae7b7269c36e0a5c2f01c01505e9 | 58cde5727be3130cd9e291c58b291271f1b92e6a | |||
v1.0 | instruct | Filter | Filter_46454_I | Write a Python function that generates a list of all prime numbers between two given positive integers (inclusive). The function should efficiently handle large ranges. Optimize the function for performance, especially for large inputs. | def sieve_of_eratosthenes(limit):
"""
Generates all prime numbers up to a given limit using the
Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (limit + 1)
p = 2
while p * p <= limit:
if is_prime[p]:
for i in range(p * p, limit + 1, p):
is_prime[i... | from solution import primes_in_range
def test_primes_in_small_range():
assert primes_in_range(10, 20) == [11, 13, 17, 19]
def test_primes_in_large_range():
assert primes_in_range(100, 120) == [101, 103, 107, 109, 113]
def test_primes_start_equals_end():
assert primes_in_range(17, 17) == [17]
assert p... | [
{
"docstring": "Generates all prime numbers up to a given limit using the\nSieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns a list of all prime numb... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(start, end):\n \"\"\"\n Generates a list of all prime numbers between two given positive integers (inclusive).\n \"\"\"\n def is_prime(n):\n if n <= 1:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046454",
"row_id": 46454,
"seed_ids": "['Qwen2.5-72B-Instruct_98650']"
} | 0.643577 | Filter_46454 | I | [
"sieve_of_eratosthenes",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb032c0679f12445c000cfe39d34ba349207cd43 | df18d8a0c7ae665b7b59919d23aaf8a253f3ec25 | |||
v1.0 | instruct | Filter | Filter_46485_I | Design a Python function to parse and organize a messy list of string elements, each containing a name, an email, and a phone number, into a neatly structured list of dictionaries. Each dictionary should store the name, email, and phone number extracted from the string. The names should be title-cased, the emails shoul... | import re
import logging
# Configure logging
logging.basicConfig(level=logging.ERROR)
def is_valid_email(email):
"""
Validates the email address.
"""
email_regex = re.compile(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
return email_regex.match(email) is not None
def standardize_phone_num... | from solution import parse_list
def test_parse_valid_entries():
messy_list = [
" John Doe, john.doe@example.com, 123-456-7890 ",
" Jane Smith, jane.smith@example.com, (987) 654-3210"
]
expected_output = [
{"name": "John Doe", "email": "john.doe@example.com", "phone": "+1-123-456-789... | [
{
"docstring": "Validates the email address.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Standardizes the phone number to the format +1-XXX-XXX-XXXX.\nOnly accepts 10-digit numbers.",
"function_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nimport logging\n\n# Configure logging\nlogging.basicConfig(level=logging.ERROR)\n\ndef is_valid_email(email):\n \"\"\"\n Validates the email address.\n \"\"\"\n email_re... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046485",
"row_id": 46485,
"seed_ids": "['Qwen2.5-72B-Instruct_98693']"
} | 0.581248 | Filter_46485 | I | [
"is_valid_email",
"standardize_phone_number",
"parse_list"
] | 3 | [
[
"parse_list",
"is_valid_email"
],
[
"parse_list",
"standardize_phone_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6a74f772d03bb018f6a77899d5c8d55bdd5ff40c | e0577b01a177ebd8f5674d5f3a77371d050876de | |||
v1.0 | instruct | Filter | Filter_46489_I | Design a Python function that implements the K-Nearest Neighbors (KNN) algorithm for a classification task. This function should be capable of accepting training and testing datasets, along with the number of neighbors to consider, as input parameters. The datasets are expected to be in the form of NumPy arrays, with t... | import numpy as np
from collections import Counter
import math
def euclidean_distance(row1, row2):
"""
Computes Euclidean distance between two data points
"""
distance = 0.0
for i in range(len(row1)-1):
distance += (row1[i] - row2[i])**2
return math.sqrt(distance)
def get_neighbors(tra... | import pytest
import numpy as np
from solution import knn_classification
def test_knn_single_test_point():
train_data = np.array([[1.0, 2.0, 0],
[1.1, 1.9, 0],
[4.0, 4.0, 1],
[4.1, 4.1, 1]])
test_data = np.array([[1.0, 1.0]])
... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom collections import Counter\n\ndef euclidean_distance(x1, x2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return np.sqrt(np.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046489",
"row_id": 46489,
"seed_ids": "['Qwen2.5-72B-Instruct_98701']"
} | 0.669182 | Filter_46489 | I | [
"euclidean_distance",
"get_neighbors",
"predict_classification",
"knn_classification"
] | 4 | [
[
"get_neighbors",
"euclidean_distance"
],
[
"knn_classification",
"predict_classification"
],
[
"predict_classification",
"get_neighbors"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | e99a69dbb0e08446e206902a3143c9a3f4b7ffd4 | 215321fb1ca5c305e4ad04269615011af88744a4 | |||
v1.0 | instruct | Filter | Filter_46517_I | Create a Python function to calculate the factorial of a number (a non-negative integer). The function should be able to handle a list of numbers and return a dictionary with the original number as the key and the factorial as the value. Optimize the function for better performance when dealing with large numbers and a... | def factorial(n):
"""
Calculate the factorial of a non-negative integer n.
"""
if not isinstance(n, int) or n < 0:
raise ValueError("Input must be a non-negative integer.")
if n in (0, 1):
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
de... | from solution import factorial, factorial_dict
import pytest
def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(5) == 120
assert factorial(10) == 3628800
# Testing error handling for negative numbers and non-integer inputs
with pytest.raises(ValueError... | [
{
"docstring": "Calculate the factorial of a non-negative integer n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the factorial for a list of non-negative integers.\nReturns a dictionary with the original nu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef factorial(numbers):\n \"\"\"\n Returns a dictionary with numbers as keys and their factorials as values.\n Handles invalid inputs by returning None in place of the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046517",
"row_id": 46517,
"seed_ids": "['Qwen2.5-72B-Instruct_98748']"
} | 0.738383 | Filter_46517 | I | [
"factorial",
"factorial_dict"
] | 2 | [
[
"factorial_dict",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1dd8405e76ee126830fb6f85c0a52f3b0726d329 | 20eb053211ca9e9ff8b256dec082aaad565156ff | |||
v1.0 | instruct | Filter | Filter_46556_I | Design a basic game for two players using Python. The game should be text-based and involve taking turns. Explain the rules and provide the Python code for the game. | def print_board(board):
"""
Prints the game board.
"""
for row in board:
print(" | ".join(row))
print("-" * 5)
def check_winner(board):
"""
Checks if there is a winner on the board.
Returns 'X' or 'O' if there's a winner, or None if there is no winner yet.
"""
lines ... | from solution import check_winner, is_board_full
def test_check_winner_row():
board = [['X', 'X', 'X'],
[' ', 'O', ' '],
[' ', ' ', 'O']]
assert check_winner(board) == 'X'
def test_check_winner_column():
board = [['O', 'X', ' '],
['O', 'X', ' '],
['O', '... | [
{
"docstring": "Prints the game board.",
"function_declaration": "def print_board(board):",
"function_name": "print_board",
"parameter_list": "(board)"
},
{
"docstring": "Checks if there is a winner on the board.\nReturns 'X' or 'O' if there's a winner, or None if there is no winner yet.",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def print_board(board):\n \"\"\"\n Prints the game board.\n \"\"\"\n for row in board:\n print(\" | \".join(row))\n print(\"-\" * 5)\n\ndef check_winner(board):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046556",
"row_id": 46556,
"seed_ids": "['Qwen2.5-72B-Instruct_98813']"
} | 0.455366 | Filter_46556 | I | [
"print_board",
"check_winner",
"is_board_full",
"play_game"
] | 4 | [
[
"play_game",
"check_winner"
],
[
"play_game",
"is_board_full"
],
[
"play_game",
"print_board"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d1093b05b752a7b949b211b6508a215180b57572 | b0f28af6b84ea3b88c9b3125f8d3dc2f4dad1f40 | |||
v1.0 | instruct | Filter | Filter_46574_I | How can I create a Python script that automatically sends an email when a specific condition is met? For example, if a stock price exceeds a certain threshold, an email should be sent with the current stock price. Can you provide a step-by-step guide including necessary Python libraries and sample code? | import smtplib
from email.mime.text import MIMEText
import requests
def get_stock_price(stock_symbol):
"""
Fetches the current stock price for the given stock symbol.
"""
# Mock API URL (In a real scenario, use a valid API URL and parameters)
api_url = f"https://financialmodelingprep.com/api/v3/quo... | from solution import get_stock_price, send_email, check_and_send_email
import pytest
from unittest.mock import patch
def test_get_stock_price():
with patch('solution.requests.get') as mock_get:
mock_response = [{'price': 150.0}]
mock_get.return_value.json.return_value = mock_response
result... | [
{
"docstring": "Fetches the current stock price for the given stock symbol.",
"function_declaration": "def get_stock_price(stock_symbol):",
"function_name": "get_stock_price",
"parameter_list": "(stock_symbol)"
},
{
"docstring": "Sends an email with the given subject and body to the given re... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nimport requests\n\ndef get_stock_price(stock_symbol):\n \"\"\"\n Fetches the current stock price for the given stock symbol.\n \"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046574",
"row_id": 46574,
"seed_ids": "['Qwen2.5-72B-Instruct_98847']"
} | 0.466067 | Filter_46574 | I | [
"get_stock_price",
"send_email",
"check_and_send_email"
] | 3 | [
[
"check_and_send_email",
"get_stock_price"
],
[
"check_and_send_email",
"send_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 297a1b2d1e37057b122f52b97665abb99621ae8a | 8c5e17eceab030277ea9439346c0901bfce4b54b | |||
v1.0 | instruct | Filter | Filter_46597_I | Create a Python program that implements a simple text-based calculator. The program should support the following operations: addition, subtraction, multiplication, and division. It should prompt the user to enter two numbers and then ask which operation they want to perform. After performing the operation, the program ... | 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:
return "Error: Division by zero is not allowed."
return a / b
def calculator():
while True:
try:
num1 = float(input("Enter first number: "))
... | from solution import add, subtract, multiply, divide
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(2, 5) == -3
assert subtract(0, 0) == 0
def test_multiply():
assert multiply(4, 5) == 20
... | [
{
"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 return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n return \"Error: Division by zer... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046597",
"row_id": 46597,
"seed_ids": "['Qwen2.5-72B-Instruct_98883']"
} | 0.570272 | Filter_46597 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 7d3574e6ac85c1ab6e8fe9a214b007e38bbeb72e | 581a19451ee2cf26c766d57b4c85fe3e9d5b2137 | |||
v1.0 | instruct | Filter | Filter_46598_I | Write a program that generates the first 10 Fibonacci numbers and prints them in a comma-separated list. You can use any programming language you prefer. | def generate_fibonacci(n):
"""
Generates the first n Fibonacci numbers and returns them as a list.
"""
fib_sequence = []
a, b = 0, 1
while len(fib_sequence) < n:
fib_sequence.append(a)
a, b = b, a + b
return fib_sequence
def fibonacci_comma_separated(n):
"""
Generate... | from solution import generate_fibonacci, fibonacci_comma_separated
def test_generate_fibonacci():
assert generate_fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_fibonacci_comma_separated():
assert fibonacci_comma_separated(10) == '0,1,1,2,3,5,8,13,21,34' | [
{
"docstring": "Generates the first n Fibonacci numbers and returns them as a list.",
"function_declaration": "def generate_fibonacci(n):",
"function_name": "generate_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first n Fibonacci numbers and returns them as\na string ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_fibonacci(n):\n \"\"\"\n Generates the first n Fibonacci numbers.\n \n Parameters:\n - n (int): The number of Fibonacci numbers to generate.\n \n Returns:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046598",
"row_id": 46598,
"seed_ids": "['Qwen2.5-72B-Instruct_98884']"
} | 0.688736 | Filter_46598 | I | [
"generate_fibonacci",
"fibonacci_comma_separated"
] | 2 | [
[
"fibonacci_comma_separated",
"generate_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90912797705394780ba4e4e133faf75a9d11c620 | 7f827834b58ac9fe6405f5b4ea04bcc194ae3efe | |||
v1.0 | instruct | Filter | Filter_46600_I | I want to create a simple Python script that can monitor the CPU usage of a Linux system and send an email alert if the usage exceeds a certain threshold. How can I achieve this? | import smtplib
import psutil
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body, from_email, to_email, smtp_server, smtp_port, login, password):
"""
Sends an email using the specified SMTP server.
Args:
subject: Subject of the email.
... | import smtplib
from unittest.mock import patch, call
from solution import send_email, monitor_cpu
def test_send_email():
with patch('smtplib.SMTP') as mock_smtp:
send_email('Test Subject', 'Test Body', 'from@example.com', 'to@example.com', 'smtp.example.com', 587, 'user', 'password')
instance = moc... | [
{
"docstring": "Sends an email using the specified SMTP server.\nArgs:\n subject: Subject of the email.\n body: Body of the email.\n from_email: Sender's email address.\n to_email: Receiver's email address.\n smtp_server: SMTP server address.\n smtp_port: SMTP server port.\n login: Login fo... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"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 monitor_cpu(threshold, email_to, email_from, email_subject, smtp_serv... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046600",
"row_id": 46600,
"seed_ids": "['Qwen2.5-72B-Instruct_98886']"
} | 0.629964 | Filter_46600 | I | [
"send_email",
"monitor_cpu"
] | 2 | [
[
"monitor_cpu",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | 03c1d562c7b30da730d0fd97eb791d28b7f485b1 | 39a2c96068bb1e77d756b79175ea335651e09f57 | |||
v1.0 | instruct | Filter | Filter_46616_I | Design a simple program that can encode and decode a message using a basic Caesar cipher. The program should take a string and a shift value as input for encoding, and for decoding, it should take the encoded string and the same shift value to return the original message. Make sure to handle both uppercase and lowercas... | def caesar_cipher_encode(message, shift):
"""
Encodes a message using a Caesar cipher with the given shift.
"""
encoded_message = []
for char in message:
if char.isalpha():
shift_base = ord('A') if char.isupper() else ord('a')
encoded_char = chr(shift_base + (ord(char... | from solution import caesar_cipher_encode, caesar_cipher_decode
def test_caesar_cipher_encode_with_positive_shift():
assert caesar_cipher_encode("Hello, World!", 3) == "Khoor, Zruog!"
def test_caesar_cipher_encode_with_negative_shift():
assert caesar_cipher_encode("Hello, World!", -3) == "Ebiil, Tloia!"
def ... | [
{
"docstring": "Encodes a message using a Caesar cipher with the given shift.",
"function_declaration": "def caesar_cipher_encode(message, shift):",
"function_name": "caesar_cipher_encode",
"parameter_list": "(message, shift)"
},
{
"docstring": "Decodes a message encoded with a Caesar cipher... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_cipher_encode(message, shift):\n \"\"\"\n Encodes the given message using a Caesar cipher with the specified shift.\n \n Parameters:\n message (str): The message to e... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046616",
"row_id": 46616,
"seed_ids": "['Qwen2.5-72B-Instruct_98911']"
} | 0.60863 | Filter_46616 | I | [
"caesar_cipher_encode",
"caesar_cipher_decode"
] | 2 | [
[
"caesar_cipher_decode",
"caesar_cipher_encode"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8777d18fcd01591c72949ee8e09b44c4e7fd4ccc | c88024403da2d600e302b71fd8d24df5ae6df0b4 | |||
v1.0 | instruct | Filter | Filter_46645_I | Write a function to find the kth largest element in an array, and optimize it to run in O(n) time complexity on average. The function should handle edge cases such as an empty array or k being out of bounds. | import random
def partition(nums, left, right):
pivot_index = random.randint(left, right)
nums[pivot_index], nums[right] = nums[right], nums[pivot_index]
pivot = nums[right]
i = left
for j in range(left, right):
if nums[j] > nums[right]:
nums[i], nums[j] = nums[j], nums[i]
... | from solution import find_kth_largest
import pytest
def test_find_kth_largest():
assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5
def test_find_kth_largest_with_duplicates():
assert find_kth_largest([3, 3, 3, 5, 6, 6, 4], 4) == 4
def test_find_kth_largest_k_is_one():
assert find_kth_largest([3, 2, 1, ... | [
{
"docstring": null,
"function_declaration": "def partition(nums, left, right):",
"function_name": "partition",
"parameter_list": "(nums, left, right)"
},
{
"docstring": null,
"function_declaration": "def quickselect(nums, left, right, k):",
"function_name": "quickselect",
"param... | [
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 find_kth_largest(nums, k):\n \"\"\"\n Finds the kth largest element in the array nums.\n \n Args:\n nums (list of int): The list of integers.\n k (int): ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046645",
"row_id": 46645,
"seed_ids": "['Qwen2.5-72B-Instruct_98952']"
} | 0.667189 | Filter_46645 | I | [
"partition",
"quickselect",
"find_kth_largest"
] | 3 | [
[
"find_kth_largest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d91f5225113150e0691ef05c7ada6cf473546161 | 8ba339e88490e5b79d30f8dd93532b11f15068a2 | |||
v1.0 | instruct | Filter | Filter_46666_I | How can I implement a user-based collaborative filtering recommendation system using Python? Could you provide a simple example? | import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
def get_user_similarity_matrix(user_item_matrix):
"""
Calculate the user similarity matrix based on the cosine similarity.
:param user_item_matrix: A 2D numpy array where rows are users and columns are items.
:return: A 2D numpy... | import numpy as np
from solution import get_user_similarity_matrix, get_top_n_similar_users, recommend_items
def test_get_user_similarity_matrix():
user_item_matrix = np.array([[1, 1, 0, 0],
[1, 1, 1, 0],
[0, 0, 1, 1],
... | [
{
"docstring": "Calculate the user similarity matrix based on the cosine similarity.\n\n:param user_item_matrix: A 2D numpy array where rows are users and columns are items.\n:return: A 2D numpy array representing the user similarity matrix.",
"function_declaration": "def get_user_similarity_matrix(user_ite... | [
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 collaborative_filtering(user_item_matrix, user_index, k=5):\n \"\"\"\n Implementation of a simple user-based collaborative filtering recommendation system.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00046666",
"row_id": 46666,
"seed_ids": "['Qwen2.5-72B-Instruct_98985']"
} | 0.41943 | Filter_46666 | I | [
"get_user_similarity_matrix",
"get_top_n_similar_users",
"recommend_items"
] | 3 | [
[
"recommend_items",
"get_top_n_similar_users"
],
[
"recommend_items",
"get_user_similarity_matrix"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy",
"sklearn"
] | false | 6a8cdbdee5fbc7fca766d22845e0d261f096f9f8 | 2b4c16abd66100f38b636debad530d744bc706c0 | |||
v1.0 | instruct | Filter | Filter_46693_I | Given a list of numbers, write a Python function that returns the largest number that is a prime and also a palindrome. If no such number exists in the list, the function should return `None`. Optimize the function for performance, considering the list might contain up to 10,000 numbers. | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
sqrt_n = int(n ** 0.5) + 1
for divisor in range(3, sqrt_n, 2):
if n % divisor == 0:
return False
return True
d... | from solution import largest_prime_palindrome
def test_no_prime_palindrome():
assert largest_prime_palindrome([10, 20, 30, 40, 50]) == None
def test_single_prime_palindrome():
assert largest_prime_palindrome([11, 13, 17]) == 11
def test_multiple_prime_palindromes():
assert largest_prime_palindrome([101, ... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046693",
"row_id": 46693,
"seed_ids": "['Qwen2.5-72B-Instruct_99026']"
} | 0.680002 | Filter_46693 | I | [
"is_prime",
"is_palindrome",
"largest_prime_palindrome"
] | 3 | [
[
"largest_prime_palindrome",
"is_palindrome"
],
[
"largest_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4fb8fb866a42ab35fbb627957db09ffd092b8816 | c641c153bfc849e4de78c198363c258f4cc8d50d | |||
v1.0 | instruct | Filter | Filter_46707_I | Create a program in Python that generates a random 6-digit number and checks if it is a palindrome. If it is, the program should print the number and a message indicating it is a palindrome. If not, it should print the number and a message indicating it is not a palindrome. | import random
def generate_random_number():
"""
Generates a random 6-digit number.
"""
return random.randint(100000, 999999)
def is_palindrome(number):
"""
Checks if a number is a palindrome.
"""
num_str = str(number)
return num_str == num_str[::-1]
def print_palindrome_message():... | from solution import generate_random_number, is_palindrome
def test_generate_random_number():
number = generate_random_number()
assert 100000 <= number <= 999999
assert len(str(number)) == 6
def test_is_palindrome_with_palindromes():
assert is_palindrome(123321) == True
assert is_palindrome(456654... | [
{
"docstring": "Generates a random 6-digit number.",
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
... | [
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 generate_random_number():\n return random.randint(100000, 999999)\n\ndef is_palindrome(number):\n str_num = str(number)\n return str_num == str_num[::-1]\n\ndef c... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00046707",
"row_id": 46707,
"seed_ids": "['Qwen2.5-72B-Instruct_99042']"
} | 0.692542 | Filter_46707 | I | [
"generate_random_number",
"is_palindrome",
"print_palindrome_message"
] | 3 | [
[
"print_palindrome_message",
"generate_random_number"
],
[
"print_palindrome_message",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f9483174aa9daa61fb3eea905a90b88535d7de2d | 553569a26bc72e520f6dbde56947c1a0b43e1313 | |||
v1.0 | instruct | Filter | Filter_46724_I | Design a Python function to calculate the nth Fibonacci number using a generator. The function should efficiently generate Fibonacci numbers, allowing the user to specify the position (n) of the number in the Fibonacci sequence they want to retrieve. The first two Fibonacci numbers are 0 and 1, and each subsequent numb... | def fibonacci_generator():
"""
Generator function to yield Fibonacci numbers indefinitely.
"""
a, b = 0, 1
while True:
yield a
a, b = b, a + b
def nth_fibonacci(n):
"""
Returns the nth Fibonacci number using the generator function.
"""
gen = fibonacci_generator()
... | from solution import nth_fibonacci
def test_nth_fibonacci_first_number():
assert nth_fibonacci(1) == 0
def test_nth_fibonacci_second_number():
assert nth_fibonacci(2) == 1
def test_nth_fibonacci_fifth_number():
assert nth_fibonacci(5) == 3
def test_nth_fibonacci_tenth_number():
assert nth_fibonacci(... | [
{
"docstring": "Generator function to yield Fibonacci numbers indefinitely.",
"function_declaration": "def fibonacci_generator():",
"function_name": "fibonacci_generator",
"parameter_list": "()"
},
{
"docstring": "Returns the nth Fibonacci number using the generator function.",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_generator():\n \"\"\"\n A generator function to yield Fibonacci numbers indefinitely.\n \"\"\"\n a, b = 0, 1\n while True:\n yield a\n a, b = b, a + ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046724",
"row_id": 46724,
"seed_ids": "['Qwen2.5-72B-Instruct_99080']"
} | 0.813862 | Filter_46724 | I | [
"fibonacci_generator",
"nth_fibonacci"
] | 2 | [
[
"nth_fibonacci",
"fibonacci_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1500d51a72fb6e7cacd16bb4cedba680b8d1e946 | 65a1416f94b351e0584389f692c940fc08be6dc3 | |||
v1.0 | instruct | Filter | Filter_46725_I | Write a Python function that takes a list of integers and returns a new list containing only the integers that are palindromes. A palindrome integer is an integer that reads the same backward as forward, such as 121 or 1221. Ensure your function is efficient and works with a list of integers of varying lengths. | def is_palindrome(num):
"""
Helper function to determine if an integer is a palindrome.
"""
return str(num) == str(num)[::-1]
def filter_palindromes(numbers):
"""
Returns a list of palindrome integers from the input list.
"""
return [num for num in numbers if is_palindrome(num)] | from solution import filter_palindromes
def test_filter_palindromes_all_palindromes():
assert filter_palindromes([121, 1221, 333, 44444]) == [121, 1221, 333, 44444]
def test_filter_palindromes_no_palindromes():
assert filter_palindromes([123, 456, 789]) == []
def test_filter_palindromes_mixed():
assert f... | [
{
"docstring": "Helper function to determine if an integer is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of palindrome integers from the input list.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Checks if a given integer is a palindrome.\n \"\"\"\n if num < 0:\n return False\n return str(num) == str(num)[::-1]\n\ndef filter_pali... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046725",
"row_id": 46725,
"seed_ids": "['Qwen2.5-72B-Instruct_99083']"
} | 0.727632 | Filter_46725 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c2c85e27d529279668d68ef73f55292e95a6478 | 742e063eea72d4f75576992b4b8249370c25fed4 | |||
v1.0 | instruct | Filter | Filter_46757_I | Write a program in Python that creates a virtual ecosystem simulation. The ecosystem should include at least three different species interacting with each other (e.g., predator-prey relationships, competition for resources). The program should simulate the population dynamics over a series of generations, taking into a... | import random
class Species:
def __init__(self, name, initial_population, birth_rate, death_rate):
self.name = name
self.population = initial_population
self.birth_rate = birth_rate
self.death_rate = death_rate
def simulate_generation(self, resource_factor):
births = in... | from solution import Species, Ecosystem
def test_species_creation():
rabbit = Species('Rabbit', 50, 0.1, 0.05)
assert rabbit.name == 'Rabbit'
assert rabbit.population == 50
assert rabbit.birth_rate == 0.1
assert rabbit.death_rate == 0.05
def test_species_simulation():
rabbit = Species('Rabbit'... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\nclass Species:\n def __init__(self, name, population, birthrate, deathrate):\n self.name = name\n self.population = population\n self.birthrate = birth... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046757",
"row_id": 46757,
"seed_ids": "['Qwen2.5-72B-Instruct_99127']"
} | 0.31752 | Filter_46757 | I | [
"display_results",
"run_simulation"
] | 2 | [
[
"run_simulation",
"display_results"
]
] | 1 | [] | false | [
"Species",
"Ecosystem"
] | true | pytest | true | [] | true | 75b67e0baf8e1b98b40ac7220372f19037179e2f | d282cd81b18c6147c72c19bd64541478b1fa17e0 | |||
v1.0 | instruct | Filter | Filter_46781_I | Create a function in Python that generates a random integer between 1 and 100, and then checks if the number is a prime number. The function should return the integer and a boolean indicating whether it is a prime number or not. | import random
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def generate_an... | from solution import is_prime, generate_and_check_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def generate_and_check_prime():",
"function_name": "generate_and_check_prime",
"parameter_list": "()"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef 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": "00046781",
"row_id": 46781,
"seed_ids": "['Qwen2.5-72B-Instruct_99160']"
} | 0.660574 | Filter_46781 | I | [
"is_prime",
"generate_and_check_prime"
] | 2 | [
[
"generate_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db65929c6c2180d8d873fb42e1cbedd3e3ad5f32 | 9de1ad9f14f9e5e52d694eee1a95b63adb2bbbde | |||
v1.0 | instruct | Filter | Filter_46803_I | Create a Python program to calculate the factorial of a number using recursion. Additionally, implement a feature to calculate the sum of all factorials from 1 to the given number. Ensure the program can handle input validation for positive integers only. | def factorial(n):
"""
Recursively calculates the factorial of a positive integer n.
"""
if n == 1 or n == 0:
return 1
else:
return n * factorial(n - 1)
def sum_of_factorials(n):
"""
Calculates the sum of all factorials from 1 to n.
"""
if n < 1:
raise ValueEr... | import pytest
from solution import factorial, sum_of_factorials
def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(5) == 120
assert factorial(7) == 5040
def test_sum_of_factorials():
assert sum_of_factorials(1) == 1
assert sum_of_factorials(2) == 3 # 1! +... | [
{
"docstring": "Recursively calculates the factorial of a positive integer n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the sum of all factorials from 1 to n.",
"function_declaration": "def sum_of_fa... | [
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 If n is 0 or 1, returns 1 (base case).\n Otherwise, returns n * factorial(n-1).\n \"\"\"\n if n == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046803",
"row_id": 46803,
"seed_ids": "['Qwen2.5-72B-Instruct_99191']"
} | 0.675844 | Filter_46803 | I | [
"factorial",
"sum_of_factorials"
] | 2 | [
[
"sum_of_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50e36208a3898b6f0985b58cc8ab0af35d2fad57 | c915aa8d953ada2976eaa3c68cbf9dffafe15651 | |||
v1.0 | instruct | Filter | Filter_46812_I | I am trying to find a way to convert a batch of CSV files to JSON format using Python. Can you guide me through the process? I want to automate this for all CSV files in a specific directory. | import os
import csv
import json
def csv_to_json(csv_file_path, json_file_path):
"""
Converts a CSV file to a JSON file.
Parameters:
csv_file_path (str): The path to the CSV file.
json_file_path (str): The path to the output JSON file.
"""
data = []
with open(csv_file_path, mode='r... | import os
import json
import pytest
from solution import csv_to_json, batch_convert_csv_to_json
def test_csv_to_json(tmpdir):
# Generate a sample CSV file
csv_file = tmpdir.join("sample.csv")
with csv_file.open("w") as f:
f.write("name,age\ndoe,30\nsmith,40")
# Expected JSON content
ex... | [
{
"docstring": "Converts a CSV file to a JSON file.\n\nParameters:\ncsv_file_path (str): The path to the CSV file.\njson_file_path (str): The path to the output JSON file.",
"function_declaration": "def csv_to_json(csv_file_path, json_file_path):",
"function_name": "csv_to_json",
"parameter_list": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport csv\nimport json\n\ndef csv_to_json(csv_file_path, json_file_path):\n \"\"\"\n Converts a CSV file to a JSON file.\n \n Parameters:\n csv_file_path (str): The ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046812",
"row_id": 46812,
"seed_ids": "['Qwen2.5-72B-Instruct_99204']"
} | 0.685124 | Filter_46812 | I | [
"csv_to_json",
"batch_convert_csv_to_json"
] | 2 | [
[
"batch_convert_csv_to_json",
"csv_to_json"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 85b2e361974e2ea82abe4893575ffe2b3cf24f5b | 473778f75988655aa97f4433fa669c75f708aae0 | |||
v1.0 | instruct | Filter | Filter_46837_I | I need to write a Python function to filter a list of integers and return a new list containing only the elements that are prime numbers. Can you help me with that? | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_with_no_primes():
assert filter_primes([1, 4, 6, 8, 9, 10, 12, 15]) == []
def test_filter_primes_with_only_primes():
assert filter_p... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the list of integers and returns a new list containing only the prime numbers.",
"function_declarat... | [
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 is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046837",
"row_id": 46837,
"seed_ids": "['Qwen2.5-72B-Instruct_99247']"
} | 0.641896 | Filter_46837 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 53df5dacfd826e1ff45a22fba99be7625eeb2c17 | 200ee4a3d2e7445c3f0dea1556b11ca7a38c6c97 | |||
v1.0 | instruct | Filter | Filter_46838_I | Can you explain how to implement a simple version of the k-means clustering algorithm in Python? It would be great if you could also provide a small example to demonstrate its functionality. | import numpy as np
def initialize_centroids(data, k):
"""
Initialize k centroids by randomly selecting k distinct points from the data.
"""
indices = np.random.choice(len(data), size=k, replace=False)
return data[indices]
def assign_clusters(data, centroids):
"""
Assign each data point to ... | import numpy as np
from solution import initialize_centroids, assign_clusters, update_centroids, k_means
def test_initialize_centroids():
data = np.array([[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]])
centroids = initialize_centroids(data, 2)
assert centroids.shape == (2, 2)
assert centroids[0] in data
asse... | [
{
"docstring": "Initialize k centroids by randomly selecting k distinct points from the data.",
"function_declaration": "def initialize_centroids(data, k):",
"function_name": "initialize_centroids",
"parameter_list": "(data, k)"
},
{
"docstring": "Assign each data point to the nearest centro... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef initialize_centroids(X, k):\n \"\"\"\n Randomly initialize the centroids by selecting k unique points from data.\n \"\"\"\n indices = np.random.choice(X.s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00046838",
"row_id": 46838,
"seed_ids": "['Qwen2.5-72B-Instruct_99248']"
} | 0.590735 | Filter_46838 | I | [
"initialize_centroids",
"assign_clusters",
"update_centroids",
"k_means"
] | 4 | [
[
"k_means",
"assign_clusters"
],
[
"k_means",
"initialize_centroids"
],
[
"k_means",
"update_centroids"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 658870e16052a88cb56000290d905ca192cf4f1d | ce9560fd92aa082708033906a9aefe26612abfcd | |||
v1.0 | instruct | Filter | Filter_46863_I | Design a Python function that implements the ElGamal encryption and decryption process using a safe prime for the generation of keys. The function should generate a public and private key pair, and allow for the encryption and decryption of a message, which is an integer. Make sure to also implement a function to find ... | import random
from sympy import isprime, mod_inverse, primitive_root
# Function to find a generator for the multiplicative group of integers modulo a safe prime
def find_generator(p):
if not isprime(p):
raise ValueError("p must be a prime number")
return primitive_root(p)
# Function to generate ElGama... | import pytest
from solution import find_generator, generate_keys, encrypt, decrypt
def test_find_generator():
assert find_generator(23) in {generator for generator in range(1, 23) if pow(generator, (23-1)//2, 23) != 1}
def test_generate_keys():
public_key, private_key = generate_keys(23)
p, g, y = pub... | [
{
"docstring": null,
"function_declaration": "def find_generator(p):",
"function_name": "find_generator",
"parameter_list": "(p)"
},
{
"docstring": null,
"function_declaration": "def generate_keys(p):",
"function_name": "generate_keys",
"parameter_list": "(p)"
},
{
"docst... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from sympy import nextprime, isprime, randprime, mod_inverse\nimport random\n\n# Generate a safe prime p where p = 2q + 1 and both p and q are prime\ndef generate_safe_prime(bits=256):\n wh... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046863",
"row_id": 46863,
"seed_ids": "['Qwen2.5-72B-Instruct_99284']"
} | 0.514251 | Filter_46863 | I | [
"find_generator",
"generate_keys",
"encrypt",
"decrypt"
] | 4 | [
[
"generate_keys",
"find_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | ef3e7ec706d36bee78a0af63b5e1bc8085d1205e | 379bee38e900ac26e909948727050883bc12cdbe | |||
v1.0 | instruct | Filter | Filter_46871_I | Write a Python program that calculates the sum of all prime numbers up to a given number n. The program should take an integer input from the user and output the sum of all prime numbers less than or equal to n. Ensure to include error handling for non-integer inputs. | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def sum_of_primes(n):
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == Fal... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers less than or equal to n.",
"function_declaration": "def sum_of_primes(n):",
"func... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046871",
"row_id": 46871,
"seed_ids": "['Qwen2.5-72B-Instruct_99295']"
} | 0.662802 | Filter_46871 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1fb389113b40dbb0688e6e8f916ddfd3b618900f | 7233e889ec3c968fac06a60817ab3a14d1d411d0 | |||
v1.0 | instruct | Filter | Filter_46890_I | Design a Python program that demonstrates the concept of a simple Genetic Algorithm to find the maximum value of a function. The function to be maximized is the sum of binary digits (i.e., the function should count the number of 1s in a binary string). The program should use a population of binary strings, and include ... | import random
def create_individual(length):
"""
Create a random binary string of a given length.
"""
return ''.join(random.choice('01') for _ in range(length))
def create_population(size, individual_length):
"""
Create a population of a given size with individuals of a given length.
"""
... | import pytest
from solution import (create_individual, create_population, fitness,
selection, crossover, mutate, genetic_algorithm)
def test_create_individual():
individual = create_individual(10)
assert len(individual) == 10
assert set(individual).issubset({'0', '1'})
def test_crea... | [
{
"docstring": "Create a random binary string of a given length.",
"function_declaration": "def create_individual(length):",
"function_name": "create_individual",
"parameter_list": "(length)"
},
{
"docstring": "Create a population of a given size with individuals of a given length.",
"fu... | [
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_population(size, length):\n \"\"\"\n Generate a population of binary strings.\n \"\"\"\n population = [''.join(random.choice('01') for _ in range(leng... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046890",
"row_id": 46890,
"seed_ids": "['Qwen2.5-72B-Instruct_99324']"
} | 0.47873 | Filter_46890 | I | [
"create_individual",
"create_population",
"fitness",
"selection",
"crossover",
"mutate",
"genetic_algorithm"
] | 7 | [
[
"create_population",
"create_individual"
],
[
"genetic_algorithm",
"create_population"
],
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"fitness"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"selection"
],
[
... | 7 | [] | false | [] | false | pytest | true | [] | true | f9def975556643ac42760d4bc2c22f417be8943e | 9d20db9129d600082a705718e2ba370ec01f1c61 | |||
v1.0 | instruct | Filter | Filter_46920_I | I want to create a simple web application that allows users to input a list of URLs and returns the number of images on each page. Can you guide me through the process of creating this application using Python and Flask? | from flask import Flask, request, jsonify
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
def count_images(url):
"""
Given a URL, this function will fetch the page content
and return the number of images on that page.
"""
try:
response = requests.get(url)
respon... | from solution import count_images, app
import pytest
def test_count_images(monkeypatch):
class MockResponse:
def __init__(self, content):
self.content = content
def raise_for_status(self):
pass # No-op for our test
def mock_get(url):
if url == "htt... | [
{
"docstring": "Given a URL, this function will fetch the page content\nand return the number of images on that page.",
"function_declaration": "def count_images(url):",
"function_name": "count_images",
"parameter_list": "(url)"
},
{
"docstring": "Endpoint to count images on a list of URLs."... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\nimport requests\nfrom bs4 import BeautifulSoup\n\napp = Flask(__name__)\n\ndef count_images(url):\n \"\"\"\n Given a URL, this function will fe... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046920",
"row_id": 46920,
"seed_ids": "['Qwen2.5-72B-Instruct_99374']"
} | 0.445193 | Filter_46920 | I | [
"count_images",
"count_images_in_urls"
] | 2 | [
[
"count_images_in_urls",
"count_images"
]
] | 1 | [] | false | [] | false | pytest | true | [
"bs4",
"flask",
"requests"
] | false | dee31a73e5de9a40c0989a982996b9f47e22a493 | 044a91b9f8125ac93469731a5161ae82a02e9487 | |||
v1.0 | instruct | Filter | Filter_46921_I | Can you help me with a programming problem in Python? I'm trying to create a simple calculator that can perform addition, subtraction, multiplication, and division. However, I'm not sure how to structure the program to allow the user to choose the operation and input the numbers. Could you provide a basic example? | 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:
return a / b
else:
return "Error: Division by zero"
def calculator(operation, a, b):
if operation == "add":
return add(a, b)
elif operation =... | def test_add():
assert add(5, 3) == 8
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(3, 5) == -2
assert subtract(0, 0) == 0
def test_multiply():
assert multiply(5, 3) == 15
assert multiply(-1, 1) == -1
assert multiply(0,... | [
{
"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 return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046921",
"row_id": 46921,
"seed_ids": "['Qwen2.5-72B-Instruct_99375']"
} | 0.61833 | Filter_46921 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 7f4ac27fe32bc833fce719936e5edc1e27281d5b | 82b988bbe7012ccf147e574209f431a792b1ccf2 | |||
v1.0 | instruct | Filter | Filter_46951_I | Write a Python script to automate the process of checking the availability of a website by pinging it and logging the result to a file. The script should also notify the user via email if the website is down (i.e., not reachable). Use the `smtplib` for sending emails and `subprocess` for pinging the website. The email ... | import subprocess
import smtplib
from email.mime.text import MIMEText
import datetime
import logging
import socket
def ping_website(website):
"""
Pings the given website to check for availability.
"""
try:
response = subprocess.run(['ping', '-c', '1', website], stdout=subprocess.PIPE, stderr=su... | import subprocess
import smtplib
import socket
from unittest.mock import patch, Mock
# Import the functions from solution
from solution import ping_website, get_ip_address, send_email, check_website
def test_ping_website_up():
with patch("subprocess.run") as mock_subprocess:
mock_subprocess.return_value =... | [
{
"docstring": "Pings the given website to check for availability.",
"function_declaration": "def ping_website(website):",
"function_name": "ping_website",
"parameter_list": "(website)"
},
{
"docstring": "Returns the IP address of the given website.",
"function_declaration": "def get_ip_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom datetime import datetime\nimport subprocess\nimport socket\nimport os\n\ndef ping_website(hostname):\n \"\"\"\n Pings the given... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00046951",
"row_id": 46951,
"seed_ids": "['Qwen2.5-72B-Instruct_99423']"
} | 0.613215 | Filter_46951 | I | [
"ping_website",
"get_ip_address",
"send_email",
"check_website"
] | 4 | [
[
"check_website",
"get_ip_address"
],
[
"check_website",
"ping_website"
],
[
"check_website",
"send_email"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 99e38d38243eab235f6b1050dfae42a23dc81403 | 0240b530321c1f2c7e9599a7c8a60b7f3a926945 | |||
v1.0 | instruct | Filter | Filter_46955_I | Please help me design a Python script to automate the process of checking if a list of URLs are active and accessible. I would like the script to print out the status of each URL (e.g., "200 OK" for successful connections, and any error messages for failed connections). Additionally, it should be able to handle a large... | import requests
from concurrent.futures import ThreadPoolExecutor
def check_url_status(url):
"""
Checks the status of the given URL.
Parameters:
url (str): The URL to check.
Returns:
str: The status of the URL, e.g., "200 OK", "404 Not Found", etc.
"""
try:
response = ... | import requests
from unittest.mock import patch, Mock
from solution import check_url_status, check_urls
def test_check_url_status_success():
with patch('requests.get') as mock_get:
mock_response = Mock()
mock_response.status_code = 200
mock_response.reason = "OK"
mock_get.return_val... | [
{
"docstring": "Checks the status of the given URL.\n\nParameters:\nurl (str): The URL to check.\n\nReturns:\nstr: The status of the URL, e.g., \"200 OK\", \"404 Not Found\", etc.",
"function_declaration": "def check_url_status(url):",
"function_name": "check_url_status",
"parameter_list": "(url)"
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom concurrent.futures import ThreadPoolExecutor\n\ndef check_url_status(url):\n \"\"\"\n Checks the status of a URL.\n \n Parameters:\n url (str): The URL to ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00046955",
"row_id": 46955,
"seed_ids": "['Qwen2.5-72B-Instruct_99427']"
} | 0.632198 | Filter_46955 | I | [
"check_url_status",
"check_urls"
] | 2 | [
[
"check_urls",
"check_url_status"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | f13b399674b570539f823934b393525b5258e4a7 | 6cfff5f9617155144432462d13632e2efd7c0536 | |||
v1.0 | instruct | Filter | Filter_46961_I | Can you help me write a Python function that generates a list of the first 10 prime numbers? I need it to be efficient and easy to understand. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def first_n_prime... | from solution import is_prime, first_n_primes, first_10_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(29) == True
assert is... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"func... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046961",
"row_id": 46961,
"seed_ids": "['Qwen2.5-72B-Instruct_99434']"
} | 0.589987 | Filter_46961 | I | [
"is_prime",
"first_n_primes",
"first_10_primes"
] | 3 | [
[
"first_10_primes",
"first_n_primes"
],
[
"first_n_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6d709e62a0792e7dd522d024a9060086321c3afc | 13be473b42b6e5b526badd5c9fa008d12c7dab48 | |||
v1.0 | instruct | Filter | Filter_46964_I | Design a simple AI chatbot using Python and the Flask framework to respond to user queries about a fictional bookstore. The chatbot should be able to provide information about book availability, book prices, and book authors. How would you structure the code and what libraries would you use? Provide a basic code outlin... | from flask import Flask, request, jsonify
app = Flask(__name__)
# Sample bookstore data
bookstore = {
"books": [
{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 10.99, "available": True},
{"title": "1984", "author": "George Orwell", "price": 8.99, "available": False},
... | import pytest
from flask import Flask, request, jsonify
from solution import app, process_query
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_chat_no_query(client):
response = client.post('/chat', json={})
assert response.status_code == 400
assert respon... | [
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def process_query(query):",
"function_name": "process_query",
"parameter_list": "(query)"
}
] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n# Sample bookstore data\nbookstore = {\n \"books\": [\n {\"title\": \"The Great Gatsby\", \"author\": \"F. Scott... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046964",
"row_id": 46964,
"seed_ids": "['Qwen2.5-72B-Instruct_99438']"
} | 0.29777 | Filter_46964 | I | [
"chat",
"process_query"
] | 2 | [
[
"chat",
"process_query"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | e5aa542b6b6de21f03e1b90594fcbba824dce36e | 96da9f4274b6aa96984abc7f1d9eaea6459d43ae | |||
v1.0 | instruct | Filter | Filter_46991_I | How can I generate a sine wave using Python, and plot it using Matplotlib? I want to be able to specify the frequency, amplitude, and duration of the wave. Can you provide a code snippet that accomplishes this? | import numpy as np
import matplotlib.pyplot as plt
def generate_sine_wave(frequency, amplitude, duration, sampling_rate=1000):
"""
Generates a sine wave based on the provided frequency, amplitude, and duration.
:param frequency: Frequency of the sine wave in Hertz
:param amplitude: Amplitude of th... | from solution import generate_sine_wave
def test_generate_sine_wave_shape():
frequency = 5
amplitude = 1
duration = 2
sampling_rate = 1000
t, y = generate_sine_wave(frequency, amplitude, duration, sampling_rate)
assert len(t) == len(y)
assert len(t) == int(sampling_rate * duration)
def tes... | [
{
"docstring": "Generates a sine wave based on the provided frequency, amplitude, and duration.\n\n:param frequency: Frequency of the sine wave in Hertz\n:param amplitude: Amplitude of the sine wave\n:param duration: Duration of the sine wave in seconds\n:param sampling_rate: Number of samples per second (defau... | [
1,
1,
0
] | 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 generate_sine_wave(frequency, amplitude, duration, sampling_rate=1000):\n \"\"\"\n Generates a sine wave based on the provided ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00046991",
"row_id": 46991,
"seed_ids": "['Qwen2.5-72B-Instruct_99490']"
} | 0.74053 | Filter_46991 | I | [
"generate_sine_wave",
"plot_sine_wave"
] | 2 | [
[
"plot_sine_wave",
"generate_sine_wave"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy"
] | false | 17140258764cad780186c64c041c84c86a53521b | d8548bf0a75fedcaf9056709cfa08ae36d2f7a14 | |||
v1.0 | instruct | Filter | Filter_47005_I | I need to develop a Python script to monitor the status of a list of websites and notify me via email if any of them go down. Can you provide a basic outline or template for such a script? | import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import requests
def send_email(subject, body, to_email):
from_email = "your_email@example.com"
from_password = "your_password"
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
... | import pytest
import requests
from unittest.mock import patch
from solution import check_website_status, monitor_websites
def test_check_website_status_up():
with patch('requests.get') as mock_get:
mock_get.return_value.status_code = 200
assert check_website_status("http://example.com")
def test_c... | [
{
"docstring": null,
"function_declaration": "def send_email(subject, body, to_email):",
"function_name": "send_email",
"parameter_list": "(subject, body, to_email)"
},
{
"docstring": null,
"function_declaration": "def check_website_status(url):",
"function_name": "check_website_stat... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nimport requests\n\ndef send_email(subject, body, to_email):\n from_email = \"your_email... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047005",
"row_id": 47005,
"seed_ids": "['Qwen2.5-72B-Instruct_99515']"
} | 0.502821 | Filter_47005 | I | [
"send_email",
"check_website_status",
"monitor_websites"
] | 3 | [
[
"monitor_websites",
"check_website_status"
],
[
"monitor_websites",
"send_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 373ee907b433bb40beed2d1b911cc2f0dc75347f | 123d167a1b50229fcfabf791170d39495d9bfa8c | |||
v1.0 | instruct | Filter | Filter_47018_I | Create a Python function that takes a list of strings and returns a list of tuples. Each tuple should contain a string from the input list and the count of vowels in that string. For example, if the input list is `["hello", "world"]`, the output should be `[("hello", 2), ("world", 1)]`. | def count_vowels(word):
vowels = "aeiouAEIOU"
return sum(1 for char in word if char in vowels)
def strings_with_vowel_counts(strings):
return [(string, count_vowels(string)) for string in strings] | from solution import strings_with_vowel_counts
def test_strings_with_vowel_counts_basic():
assert strings_with_vowel_counts(["hello", "world"]) == [("hello", 2), ("world", 1)]
def test_strings_with_vowel_counts_empty():
assert strings_with_vowel_counts([]) == []
def test_strings_with_vowel_counts_no_vowels()... | [
{
"docstring": null,
"function_declaration": "def count_vowels(word):",
"function_name": "count_vowels",
"parameter_list": "(word)"
},
{
"docstring": null,
"function_declaration": "def strings_with_vowel_counts(strings):",
"function_name": "strings_with_vowel_counts",
"parameter_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_vowels(strings):\n \"\"\"\n Takes a list of strings and returns a list of tuples. Each tuple contains \n a string from the input list and the count of vowels in that string.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047018",
"row_id": 47018,
"seed_ids": "['Qwen2.5-72B-Instruct_99532']"
} | 0.840855 | Filter_47018 | I | [
"count_vowels",
"strings_with_vowel_counts"
] | 2 | [
[
"strings_with_vowel_counts",
"count_vowels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b402edfa042441edb3c8785b73a87a3141ed0592 | cb350eb39136c0d36d6266f0fcd6dfbc90e2853e | |||
v1.0 | instruct | Filter | Filter_47021_I | I am trying to create a Python script that can read and write files. I want to be able to specify the file name and the content to write to the file, as well as read from the file and print its content. Can you help me write this script? | def write_to_file(file_name, content):
"""
Writes the specified content to the file with the given file name.
"""
with open(file_name, 'w') as file:
file.write(content)
def read_from_file(file_name):
"""
Reads content from the file with the given file name and returns it.
"""
wi... | import os
from solution import write_to_file, read_from_file, read_and_print_file_content
def test_write_to_file():
test_file = 'test_file.txt'
test_content = 'Hello, this is a test.'
write_to_file(test_file, test_content)
with open(test_file, 'r') as file:
content = file.read()
... | [
{
"docstring": "Writes the specified content to the file with the given file name.",
"function_declaration": "def write_to_file(file_name, content):",
"function_name": "write_to_file",
"parameter_list": "(file_name, content)"
},
{
"docstring": "Reads content from the file with the given file... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def write_to_file(file_name, content):\n \"\"\"\n Write the specified content to a file with the given file name.\n \"\"\"\n with open(file_name, 'w') as file:\n file.write(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047021",
"row_id": 47021,
"seed_ids": "['Qwen2.5-72B-Instruct_99536']"
} | 0.461631 | Filter_47021 | I | [
"write_to_file",
"read_from_file",
"read_and_print_file_content"
] | 3 | [
[
"read_and_print_file_content",
"read_from_file"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 38ab4bdac40df7642261c18e850d1c354cb0da3c | 59338a542dcac4e281858d07647f5e1a26894419 | |||
v1.0 | instruct | Filter | Filter_47054_I | Create a Python function that performs linear regression using the gradient descent method to find the best fit line for a given set of data points. The function should also plot the original data points and the best fit line on the same graph. Use the matplotlib library for plotting and numpy for numerical operations.... | import numpy as np
import matplotlib.pyplot as plt
def linear_regression_gradient_descent(x_values, y_values, learning_rate=0.01, epochs=1000):
"""
Perform linear regression using gradient descent to find the best fit line for given data points.
Parameters:
x_values (list or array): The indepe... | from solution import linear_regression_gradient_descent
import numpy as np
def test_linear_regression_gradient_descent():
x_values = [1, 2, 3, 4, 5]
y_values = [2, 4, 6, 8, 10]
m, c = linear_regression_gradient_descent(x_values, y_values, learning_rate=0.01, epochs=2000)
assert np.isclose(m, 2, at... | [
{
"docstring": "Perform linear regression using gradient descent to find the best fit line for given data points.\n\nParameters:\n x_values (list or array): The independent variable data points.\n y_values (list or array): The dependent variable data points.\n learning_rate (float): The step size for e... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef gradient_descent(x, y, learning_rate=0.01, num_iterations=1000):\n m = x.size\n theta0 = 0\n theta1 = 0\n for _ in range(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047054",
"row_id": 47054,
"seed_ids": "['Qwen2.5-72B-Instruct_99605']"
} | 0.654476 | Filter_47054 | I | [
"linear_regression_gradient_descent",
"check_linear_regression"
] | 2 | [
[
"check_linear_regression",
"linear_regression_gradient_descent"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy"
] | false | e92cc72132b2ebe506999ff951e43c2a59572a24 | 9602755568ae38e962a892efecfcec74144931c2 | |||
v1.0 | instruct | Filter | Filter_47061_I | Create a Python program that simulates a simple chatbot which can greet the user, ask for their name, and respond with a personalized greeting. The chatbot should also be able to handle simple questions like "What's your name?" and "How are you?". Implement the chatbot using functions for different responses and use a ... | def greet():
return "Hello! I am Chatbot. What's your name?"
def ask_name_response(user_name):
return f"Nice to meet you, {user_name}!"
def handle_questions(question, user_name):
if question.lower() == "what's your name?":
return "I am Chatbot."
elif question.lower() == "how are you?":
... | from solution import greet, ask_name_response, handle_questions
def test_greet():
assert greet() == "Hello! I am Chatbot. What's your name?"
def test_ask_name_response():
assert ask_name_response("Alice") == "Nice to meet you, Alice!"
assert ask_name_response("Bob") == "Nice to meet you, Bob!"
def test_h... | [
{
"docstring": null,
"function_declaration": "def greet():",
"function_name": "greet",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def ask_name_response(user_name):",
"function_name": "ask_name_response",
"parameter_list": "(user_name)"
},
{
"d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def greeting():\n return \"Hello! How can I help you today?\"\n\ndef ask_name():\n return \"What is your name?\"\n\ndef personalized_greeting(name):\n return f\"Nice to meet you, {nam... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047061",
"row_id": 47061,
"seed_ids": "['Qwen2.5-72B-Instruct_99614']"
} | 0.393905 | Filter_47061 | I | [
"greet",
"ask_name_response",
"handle_questions",
"chatbot"
] | 4 | [
[
"chatbot",
"ask_name_response"
],
[
"chatbot",
"greet"
],
[
"chatbot",
"handle_questions"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7fef181b739a0a125d6c68c539e958d8746f35de | 384646a16bcf9fb1b3ba2000782643bd773af354 | |||
v1.0 | instruct | Filter | Filter_47075_I | Write a Python function that generates a random color for each unique value in a column of a DataFrame and assigns these colors to a new column. This function should work for any DataFrame with a specified column name and should ensure that the same value in the original column always gets the same color in the new col... | import pandas as pd
import random
def generate_random_color():
"""
Returns a random color in hexadecimal format.
"""
return "#{:06x}".format(random.randint(0, 0xFFFFFF))
def assign_colors_to_unique_values(df, column_name):
"""
Assigns a random color to each unique value in the specified column... | import pandas as pd
from solution import assign_colors_to_unique_values
def test_assign_colors_to_unique_values():
# Test DataFrame
data = {'values': ['a', 'b', 'a', 'c', 'b']}
df = pd.DataFrame(data)
# Generate colors
df_colored = assign_colors_to_unique_values(df, 'values')
# Check ... | [
{
"docstring": "Returns a random color in hexadecimal format.",
"function_declaration": "def generate_random_color():",
"function_name": "generate_random_color",
"parameter_list": "()"
},
{
"docstring": "Assigns a random color to each unique value in the specified column of the DataFrame\nan... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pandas as pd\nimport random\n\ndef generate_random_color():\n \"\"\"Generates a random color in hexadecimal format.\"\"\"\n return \"#{:06x}\".format(random.randint(0, 0xFFFFFF))\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047075",
"row_id": 47075,
"seed_ids": "['Qwen2.5-72B-Instruct_99640']"
} | 0.637207 | Filter_47075 | I | [
"generate_random_color",
"assign_colors_to_unique_values"
] | 2 | [
[
"assign_colors_to_unique_values",
"generate_random_color"
]
] | 1 | [] | false | [] | false | pytest | true | [
"pandas"
] | false | ff8c753804eceb59ed595e17e1ed15bed39ad04d | 83cad918d0b1f7267910bc48af50114b9712f83a | |||
v1.0 | instruct | Filter | Filter_47083_I | Design a Python program that generates random graphs with a given number of nodes and edges, and then calculates and displays the diameter of the graph. The graph should be undirected and simple (no self-loops or multiple edges between the same pair of nodes). Use the NetworkX library for graph operations and ensure th... | import networkx as nx
import random
def generate_random_graph(num_nodes, num_edges):
"""
Generates a random undirected and simple graph with the given number of nodes and edges.
Ensures the graph is connected.
"""
if num_nodes < 1 or num_edges < num_nodes - 1:
raise ValueError("Number of no... | from solution import generate_random_graph, calculate_graph_diameter, verify_diameter_calculation
import networkx as nx
def test_generate_random_graph():
graph = generate_random_graph(5, 5)
assert nx.is_connected(graph)
assert len(graph.nodes) == 5
assert len(graph.edges) == 5
def test_calculate_graph... | [
{
"docstring": "Generates a random undirected and simple graph with the given number of nodes and edges.\nEnsures the graph is connected.",
"function_declaration": "def generate_random_graph(num_nodes, num_edges):",
"function_name": "generate_random_graph",
"parameter_list": "(num_nodes, num_edges)"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import networkx as nx\nimport random\n\ndef generate_connected_graph(num_nodes, num_edges):\n \"\"\"\n Generates a connected undirected graph with a given number of nodes and edges.\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047083",
"row_id": 47083,
"seed_ids": "['Qwen2.5-72B-Instruct_99649']"
} | 0.473961 | Filter_47083 | I | [
"generate_random_graph",
"calculate_graph_diameter",
"verify_diameter_calculation"
] | 3 | [
[
"verify_diameter_calculation",
"calculate_graph_diameter"
]
] | 1 | [] | false | [] | false | pytest | true | [
"networkx"
] | false | 9593c2eda335a15e36d9254822a9bf83166a6dbe | 1ae96b83f8e31b149c2a0a4c1ab7cc0edd4b3b2a | |||
v1.0 | instruct | Filter | Filter_47100_I | Create a Python function that performs an in-place reversal of a given string. This function should take a single string argument and modify it to be reversed without using any additional data structures. Note that Python strings are immutable, so you will need to convert the string to a mutable type first. Ensure that... | def reverse_string_in_place(s):
"""
Reverses the input string s in place.
Since Python strings are immutable, it will convert
the string to a list, reverse the list, then reassign
the characters to the original variables.
Arguments:
s -- a list of characters representing the string to r... | from solution import reverse_string
def test_reverse_string():
assert reverse_string('hello') == 'olleh'
assert reverse_string('Python') == 'nohtyP'
assert reverse_string('A') == 'A'
assert reverse_string('') == ''
assert reverse_string('madam') == 'madam'
assert reverse_string('12345') == '543... | [
{
"docstring": "Reverses the input string s in place.\nSince Python strings are immutable, it will convert\nthe string to a list, reverse the list, then reassign\nthe characters to the original variables.\n\nArguments:\ns -- a list of characters representing the string to reverse",
"function_declaration": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_string_in_place(s: str) -> str:\n \"\"\"\n Reverses the given string in place.\n Since strings are immutable in Python, we use a list to perform this operation.\n \"\"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047100",
"row_id": 47100,
"seed_ids": "['Qwen2.5-72B-Instruct_99676']"
} | 0.743845 | Filter_47100 | I | [
"reverse_string_in_place",
"reverse_string"
] | 2 | [
[
"reverse_string",
"reverse_string_in_place"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 79eb0560f9c92aa844a39f3cae892ba46ed4e785 | 06cb3468a3a8e55e9e3be254abf62f45f0cf8acf | |||
v1.0 | instruct | Filter | Filter_47123_I | Write a program in Python that checks if a number is prime or not. The program should prompt the user to enter a number and then display whether the number is prime or not. Make sure to include error handling for non-integer inputs. | def is_prime(n):
"""
Check if the input number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in ... | from solution import is_prime
def test_is_prime_with_primes():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(11) == True
assert is_prime(17) == True
def test_is_prime_with_non_primes():
assert is_prime(1) == False
assert is_prime(4) == False
assert is_prime(15) == F... | [
{
"docstring": "Check if the input number is prime.\n\nArgs:\nn (int): The number to check.\n\nReturns:\nbool: True if the number is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prompts the user ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \n Parameters:\n num (int): The number to check.\n \n Returns:\n bool: True if the number is pr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047123",
"row_id": 47123,
"seed_ids": "['Qwen2.5-72B-Instruct_99706']"
} | 0.730331 | Filter_47123 | I | [
"is_prime",
"check_prime"
] | 2 | [
[
"check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6eacebbb1f3bbd517de0b40ddbbcae63bea10de | 5433d2a626e34f6496aacb1d9732d072ba38ad55 | |||
v1.0 | instruct | Filter | Filter_47128_I | Design a Python program that creates a dictionary, `sample_dict`, containing 100 elements where the keys are strings of 5-character length generated randomly from the lowercase English alphabets, and the values are random floating-point numbers in the range from 0 (inclusive) to 10 (exclusive). Ensure that all keys are... | import random
import string
def generate_random_key(length=5):
"""
Generates a random string key of specified length from lowercase English alphabets.
"""
return ''.join(random.choices(string.ascii_lowercase, k=length))
def generate_sample_dict(size=100):
"""
Generates a dictionary with specif... | from solution import generate_sample_dict, filter_and_sort_dict
def test_generate_sample_dict():
sample = generate_sample_dict(100)
assert len(sample) == 100
for k, v in sample.items():
assert isinstance(k, str) and len(k) == 5
assert isinstance(v, float) and 0 <= v < 10
def test_filter_an... | [
{
"docstring": "Generates a random string key of specified length from lowercase English alphabets.",
"function_declaration": "def generate_random_key(length=5):",
"function_name": "generate_random_key",
"parameter_list": "(length=5)"
},
{
"docstring": "Generates a dictionary with specified ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_unique_key(existing_keys, length=5):\n \"\"\"Generates a unique key of specified length that is not in the existing_keys set.\"\"\"\n while T... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047128",
"row_id": 47128,
"seed_ids": "['Qwen2.5-72B-Instruct_99712']"
} | 0.645452 | Filter_47128 | I | [
"generate_random_key",
"generate_sample_dict",
"filter_and_sort_dict"
] | 3 | [
[
"generate_sample_dict",
"generate_random_key"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2dcae1f6dd9bf34dead38297c384f334b8acbe2d | 4bd25ed79d9c1488aa525a97f7e0b8ee771a9d85 | |||
v1.0 | instruct | Filter | Filter_47137_I | Given a 2D matrix, write a Python function to find the maximum sum of any rectangle within the matrix. The matrix can contain both positive and negative integers. How can I approach this problem? | def max_sum_submatrix(matrix):
"""
Returns the maximum sum of any rectangle within the given 2D matrix.
"""
if not matrix or not matrix[0]:
return 0
rows, cols = len(matrix), len(matrix[0])
max_sum = float('-inf')
for left in range(cols):
row_sum = [0] * rows
for ri... | from solution import max_sum_submatrix
def test_max_sum_submatrix_positive():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert max_sum_submatrix(matrix) == 29 # The max rectangle sum is 29
def test_max_sum_submatrix_negative_... | [
{
"docstring": "Returns the maximum sum of any rectangle within the given 2D matrix.",
"function_declaration": "def max_sum_submatrix(matrix):",
"function_name": "max_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum subarray using Kadane... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def kadane(arr):\n \"\"\"\n Helper function to perform Kadane's algorithm on a 1D array.\n \"\"\"\n max_sum = float('-inf')\n current_sum = 0\n\n for value in arr:\n c... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047137",
"row_id": 47137,
"seed_ids": "['Qwen2.5-72B-Instruct_99728']"
} | 0.700355 | Filter_47137 | I | [
"max_sum_submatrix",
"kadane"
] | 2 | [
[
"max_sum_submatrix",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04fd8ba90958fb319da23ff74bd96b79b46d2fa9 | c17f2aa326516ea2d7ad597ec6be6d780ece68c1 | |||
v1.0 | instruct | Filter | Filter_47144_I | Create a Python script that automates the process of checking a website's availability. The script should take a list of URLs from a text file, check each website, and write the status (up or down) to another text file. Additionally, the script should handle exceptions gracefully and log any errors encountered during t... | import requests
import logging
# Set up logging to file
logging.basicConfig(filename='website_check.log', level=logging.ERROR,
format='%(asctime)s %(levelname)s:%(message)s')
def check_website_availability(url):
"""
Check the availability of a website by sending a GET request.
Arg... | import os
import requests
from solution import check_website_availability, check_websites_from_file
def test_check_website_availability_up(monkeypatch):
class MockResponse:
status_code = 200
def mock_get(*args, **kwargs):
return MockResponse()
monkeypatch.setattr(requests, "get", mock_get... | [
{
"docstring": "Check the availability of a website by sending a GET request.\n\nArgs:\nurl (str): The URL of the website to check.\n\nReturns:\nstr: 'up' if the website is available, otherwise 'down'.",
"function_declaration": "def check_website_availability(url):",
"function_name": "check_website_avai... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport logging\n\n# Set up logging to file\nlogging.basicConfig(filename='website_check.log', level=logging.ERROR,\n format='%(asctime)s %(levelname)s:%(mes... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047144",
"row_id": 47144,
"seed_ids": "['Qwen2.5-72B-Instruct_99736']"
} | 0.616406 | Filter_47144 | I | [
"check_website_availability",
"check_websites_from_file"
] | 2 | [
[
"check_websites_from_file",
"check_website_availability"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 69ffd134d777eb0f99d5433de224f799c82e9cd2 | 020ad671c972e61ebb96c3d4f740ce0afb3e3a5a | |||
v1.0 | instruct | Filter | Filter_47149_I | Write a Python program to print the Fibonacci sequence up to the n-th term where n is a positive integer input by the user. The program should validate the input to ensure it is a positive integer and handle invalid inputs gracefully. | def fibonacci(n):
"""
Returns the Fibonacci sequence up to the n-th term.
"""
if not isinstance(n, int) or n <= 0:
raise ValueError("Input must be a positive integer")
sequence = []
a, b = 0, 1
for _ in range(n):
sequence.append(a)
a, b = b, a + b
return sequenc... | from solution import fibonacci, get_fibonacci_sequence
def test_fibonacci_normal_cases():
assert fibonacci(1) == [0]
assert fibonacci(2) == [0, 1]
assert fibonacci(5) == [0, 1, 1, 2, 3]
assert fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_fibonacci_invalid_input():
try:
fibon... | [
{
"docstring": "Returns the Fibonacci sequence up to the n-th term.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns a string representation of the Fibonacci sequence up to the n-th term.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Generates the Fibonacci sequence up to the n-th term.\n \"\"\"\n if not isinstance(n, int) or n <= 0:\n raise ValueError(\"Input must b... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047149",
"row_id": 47149,
"seed_ids": "['Qwen2.5-72B-Instruct_99741']"
} | 0.763336 | Filter_47149 | I | [
"fibonacci",
"get_fibonacci_sequence"
] | 2 | [
[
"get_fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18b3d32bf6458bb175cfd720748d3039c691d788 | 9d6fd60322929c381f91beb54b1c15494b7b3418 | |||
v1.0 | instruct | Filter | Filter_47159_I | How can I create a Python script to monitor the availability of a website and notify me if it goes down? | import requests
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website(url):
"""
Check the availability of the website.
Args:
url (str): The URL of the website to check.
Returns:
bool: True if the website is availab... | import requests
from unittest.mock import Mock, patch
from solution import check_website, send_notification_email, monitor_website
def test_check_website_up():
with patch('requests.get') as mocked_get:
mocked_get.return_value.status_code = 200
assert check_website('http://example.com') == True
de... | [
{
"docstring": "Check the availability of the website.\n\nArgs:\n url (str): The URL of the website to check.\n\nReturns:\n bool: True if the website is available, False otherwise.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
... | [
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 smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\nimport time\n\ndef send_email(subject, body, to_email, from_email, email_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047159",
"row_id": 47159,
"seed_ids": "['Qwen2.5-72B-Instruct_99759']"
} | 0.575896 | Filter_47159 | I | [
"check_website",
"send_notification_email",
"monitor_website"
] | 3 | [
[
"monitor_website",
"check_website"
],
[
"monitor_website",
"send_notification_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 868e7de742c355140ed9595b1b8ac14c1ab155fe | 7687082cacdb1292907abba63296b270da5db0ef | |||
v1.0 | instruct | Filter | Filter_47169_I | I need to create a Python function that will filter and return only the prime numbers from a given list of integers. Can you help me with the code? | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(numbers):
"""
Filters the list of numbers and retu... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
def test_filter_primes():
... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Filters the list of numbers and returns only the prime numbers.",
"function_declaration": "def... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if the number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047169",
"row_id": 47169,
"seed_ids": "['Qwen2.5-72B-Instruct_99777']"
} | 0.614806 | Filter_47169 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 99b2bcd72f8434d8288c2a3f3f9c21eaea0f446d | ecad76a654eb0b09726dd6cc44f3fe04df298d1c | |||
v1.0 | instruct | Filter | Filter_47179_I | Write a Python program that checks if a number is a prime number and then uses this function to find all prime numbers between 1 and 100. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def primes_between_1_and_10... | from solution import is_prime, primes_between_1_and_100
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(20) == False
assert is_prime(97) == True
assert is_prime(1) == False
assert is_prime... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers between 1 and 100.",
"function_declaration": "def primes_between_1_and_100():",
"function_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if the number is prime, False oth... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047179",
"row_id": 47179,
"seed_ids": "['Qwen2.5-72B-Instruct_99794']"
} | 0.75626 | Filter_47179 | I | [
"is_prime",
"primes_between_1_and_100"
] | 2 | [
[
"primes_between_1_and_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e4f534bca83b9e900565d1d24bf0f30f4de3ac0e | e21de2dd1914d008bf2ba476729e607875faf094 | |||
v1.0 | instruct | Filter | Filter_47188_I | Write a Python program that reads a file containing a list of integers, one per line, and calculates the mean, median, and mode of the numbers. The program should handle exceptions for file operations and print appropriate error messages if the file does not exist or if the file contains non-integer values. Finally, th... | import statistics
def read_numbers_from_file(filepath):
try:
with open(filepath, 'r') as file:
numbers = []
for line in file:
try:
numbers.append(int(line.strip()))
except ValueError:
raise ValueError(f"File con... | import pytest
from solution import calculate_statistics, print_statistics
def test_calculate_statistics_valid_file(tmpdir):
data = "1\n2\n3\n4\n5\n5\n"
file = tmpdir.join("valid_numbers.txt")
file.write(data)
mean_value, median_value, mode_value = calculate_statistics(str(file))
assert mean_value =... | [
{
"docstring": null,
"function_declaration": "def read_numbers_from_file(filepath):",
"function_name": "read_numbers_from_file",
"parameter_list": "(filepath)"
},
{
"docstring": null,
"function_declaration": "def calculate_statistics(filepath):",
"function_name": "calculate_statistic... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import statistics\nimport os\n\ndef read_integers_from_file(file_path):\n \"\"\"\n Reads integers from a specified file. Handles exceptions for file operations and \n non-integer valu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047188",
"row_id": 47188,
"seed_ids": "['Qwen2.5-72B-Instruct_99807']"
} | 0.685498 | Filter_47188 | I | [
"read_numbers_from_file",
"calculate_statistics",
"print_statistics"
] | 3 | [
[
"calculate_statistics",
"read_numbers_from_file"
],
[
"print_statistics",
"calculate_statistics"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8683b223d1a0dff606cb731cf72d7cfd673646aa | 1eef7d445b290818c960ec7ceb835fbaf94f03b3 | |||
v1.0 | instruct | Filter | Filter_47189_I | How can I automate the process of sending emails in bulk using Python, while ensuring they are sent at specific times? | import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from datetime import datetime, timedelta
import time
def send_email(to_email, subject, body, from_email, smtp_server, smtp_port, smtp_user, smtp_pass):
"""
Sends an email.
:param to_email: Recipient emai... | import pytest
from unittest.mock import patch, call
from solution import send_email, schedule_emails
@patch('smtplib.SMTP')
def test_send_email(mock_smtp):
send_email("test@example.com", "Test Subject", "Test Body", "from@example.com", "smtp.example.com", 587, "user", "pass")
instance = mock_smtp.return_v... | [
{
"docstring": "Sends an email.\n\n:param to_email: Recipient email address\n:param subject: Subject of the email\n:param body: Body content of the email\n:param from_email: Sender email address\n:param smtp_server: SMTP server address\n:param smtp_port: SMTP server port\n:param smtp_user: SMTP user for authent... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\nfrom datetime import datetime, timedelta\nimport time\n\ndef send_email(recipient_email, s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047189",
"row_id": 47189,
"seed_ids": "['Qwen2.5-72B-Instruct_99808']"
} | 0.490081 | Filter_47189 | I | [
"send_email",
"schedule_emails"
] | 2 | [
[
"schedule_emails",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6f620be05eba9f42ca41ee35fea801765928202 | 4eac18cb00df7e7faeac823813a9c49a755a868b | |||
v1.0 | instruct | Filter | Filter_47195_I | Write a Python program that generates a list of prime numbers up to a given limit, `n`, and then finds the product of all these prime numbers. If the product is too large, the program should return the product modulo `10^9 + 7`. Use efficient algorithms for both generating the list of primes and calculating the product... | def sieve_of_eratosthenes(n):
"""
Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.
"""
if n < 2:
return []
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
... | from solution import sieve_of_eratosthenes, product_of_primes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
assert sieve... | [
{
"docstring": "Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Finds the product of all prime numbers up to n.... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.\"\"\"\n if n < 2:\n return []\n \n primes = [True f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047195",
"row_id": 47195,
"seed_ids": "['Qwen2.5-72B-Instruct_99815']"
} | 0.566956 | Filter_47195 | I | [
"sieve_of_eratosthenes",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b5f81980ac381da71e066ee92690a3f2ddbcd8a | aac325005f409015c9c27f01b507910b5e3cd90d | |||
v1.0 | instruct | Filter | Filter_47219_I | Write a program in Python that simulates a simple dice game. The game should roll two six-sided dice, add the results, and then display the total. The game should allow the player to roll the dice multiple times until they choose to stop. Also, include a feature that tracks and displays the highest total roll achieved ... | import random
def roll_dice():
"""
Simulates rolling two six-sided dice and returns their sum.
"""
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
return die1 + die2
def play_game():
"""
Simulates the dice game allowing the player to roll multiple times.
Tracks and displays... | from solution import roll_dice, play_game
def test_roll_dice():
roll = roll_dice()
assert 2 <= roll <= 12 # The sum of two 6-sided dice should be between 2 and 12
def test_play_game(monkeypatch):
# Mock user input to simulate playing the game.
inputs = iter(['yes', 'yes', 'no'])
def mock_input(p... | [
{
"docstring": "Simulates rolling two six-sided dice and returns their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates the dice game allowing the player to roll multiple times.\nTracks and displays the highe... | [
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 \"\"\"Simulates rolling a six-sided die.\"\"\"\n return random.randint(1, 6)\n\ndef roll_dices():\n \"\"\"Rolls two six-sided dice and returns their... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047219",
"row_id": 47219,
"seed_ids": "['Qwen2.5-72B-Instruct_99852']"
} | 0.577243 | Filter_47219 | I | [
"roll_dice",
"play_game"
] | 2 | [
[
"play_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1035d5db1ba6df9d8fc90c1f3eec0c6db4006c33 | 007351ed95dd7f5326876c4c8682bdac5ebdcb89 | |||
v1.0 | instruct | Filter | Filter_47224_I | Write a Python function that implements the merge sort algorithm. The function should take a list of integers as input and return a new list that is sorted in ascending order. Make sure your function is efficient and follows best practices for Python code. | def merge_sort(arr):
"""
Function to perform merge sort on a list of integers.
Parameters:
arr (list): A list of integers to be sorted.
Returns:
list: A new list that is sorted in ascending order.
"""
if len(arr) <= 1:
return arr
# Split the array into two halv... | from solution import merge_sort
def test_merge_sort_empty_list():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_list():
assert... | [
{
"docstring": "Function to perform merge sort on a list of integers.\n\nParameters:\narr (list): A list of integers to be sorted.\n\nReturns:\nlist: A new list that is sorted in ascending order.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Implements the merge sort algorithm to sort a list of integers in ascending order.\n \n Parameters:\n arr (list): The list of integers to be ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047224",
"row_id": 47224,
"seed_ids": "['Qwen2.5-72B-Instruct_99860']"
} | 0.636689 | Filter_47224 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e885603f224c22c506385a2ecc05f4c4b0a0d4f1 | ab72727e48080829145ef3be36c3b8e74b0d09d6 | |||
v1.0 | instruct | Filter | Filter_47243_I | Can you help me write a function to check if a number is a prime number in Python? I want to use this function to generate a list of prime numbers up to a certain limit. | def is_prime(n):
"""
Check if a given number n is a prime number.
Args:
n (int): The number to check.
Returns:
bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return Fals... | 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(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime(29) == Tr... | [
{
"docstring": "Check if a given number n is a prime number.\n\nArgs:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate... | [
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 a prime number.\n\n :param n: Integer to check\n :return: True if n is a prime number, False otherwise\n \"\"\"\n if n <= 1... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047243",
"row_id": 47243,
"seed_ids": "['Qwen2.5-72B-Instruct_99889']"
} | 0.786703 | Filter_47243 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18781054dabbd4200102620419ea0080849e988d | 08efc7857bca1fd9fcc1828c0b24e552808cbfa9 | |||
v1.0 | instruct | Filter | Filter_47255_I | Can you generate a Python script that uses a recursive function to calculate the Fibonacci sequence up to the 20th number and prints each number in the sequence? | def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
if n <= 0:
raise ValueError("n must be a positive integer.")
if n == 1:
return 0
elif n == 2:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
def print_fibonacci_sequence(up_to):
"""
... | from solution import fibonacci
def test_fibonacci_first_number():
assert fibonacci(1) == 0
def test_fibonacci_second_number():
assert fibonacci(2) == 1
def test_fibonacci_third_number():
assert fibonacci(3) == 1
def test_fibonacci_fourth_number():
assert fibonacci(4) == 2
def test_fibonacci_fifth_n... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Prints the Fibonacci sequence up to the nth number.",
"function_declaration": "def print_fibonacci_sequence(up_to):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number using a recursive function.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n else:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047255",
"row_id": 47255,
"seed_ids": "['Qwen2.5-72B-Instruct_99911']"
} | 0.699749 | Filter_47255 | I | [
"fibonacci",
"print_fibonacci_sequence"
] | 2 | [
[
"print_fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4939e5d45aa30967cc5f7cb4825deb641c80ee50 | 1b2affb05d6c12805554c89ccb2c4b71ca22218b | |||
v1.0 | instruct | Filter | Filter_47261_I | Design a Python function that can accurately identify whether a given integer is a prime number. The function should be efficient and work well for large numbers. Additionally, create a second function to test the prime function with a set of numbers, including both prime and non-prime numbers, and output the results. ... | import math
def is_prime(n):
"""
Determine if a given integer n is a prime number.
Args:
n (int): The integer to check for primality.
Returns:
bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % ... | from solution import is_prime, check_prime_list
def test_is_prime_small_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
def test_is_prime_large_numbers():
assert is_prime(29) == True
assert is_prime(97) == True
assert ... | [
{
"docstring": "Determine if a given integer n is a prime number.\n\nArgs:\nn (int): The integer to check for primality.\n\nReturns:\nbool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \n A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047261",
"row_id": 47261,
"seed_ids": "['Qwen2.5-72B-Instruct_99923']"
} | 0.759719 | Filter_47261 | I | [
"is_prime",
"check_prime_list"
] | 2 | [
[
"check_prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf418b77a0452afe4587d5e2e62fbc158a55fc94 | 8a57c824deb1417c556e04dba91e7eb28d100c95 | |||
v1.0 | instruct | Filter | Filter_47289_I | How can I create a Python program to track the stock market and send alerts when certain conditions are met? | import requests
def get_stock_price(stock_symbol):
"""
Fetches the current stock price for the given stock symbol.
"""
# Using a mock URL for fetching stock price as an example
# In real scenario, we may be using an API like Alpha Vantage, Yahoo Finance or others
url = f"https://api.example.com... | from solution import get_stock_price, send_alert, track_stock
def mock_get_stock_price(stock_symbol):
"""
Mocked function to simulate stock price fetching.
"""
prices = {
"AAPL": 150,
"GOOGL": 2800,
"AMZN": 3400
}
return prices.get(stock_symbol, 0)
def mock_send_alert(m... | [
{
"docstring": "Fetches the current stock price for the given stock symbol.",
"function_declaration": "def get_stock_price(stock_symbol):",
"function_name": "get_stock_price",
"parameter_list": "(stock_symbol)"
},
{
"docstring": "Sends an alert with the given message.",
"function_declara... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\n\ndef get_stock_price(stock_symbol):\n \"\"\"\n Fetches the current stock price for the given stock symbol.\n \"\"\"\n # Using a mock URL for fetching stock price ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047289",
"row_id": 47289,
"seed_ids": "['Qwen2.5-72B-Instruct_99969']"
} | 0.481563 | Filter_47289 | I | [
"get_stock_price",
"send_alert",
"track_stock"
] | 3 | [
[
"track_stock",
"get_stock_price"
],
[
"track_stock",
"send_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 30b5739c815e0e33a9eb48f03e2b70ad511f7586 | 1d1408f89a5e8fc0e10a46382c0a08b28d2eae10 | |||
v1.0 | instruct | Filter | Filter_47297_I | How can I create a simple chatbot using Python and Flask that can answer basic questions? | from flask import Flask, request, jsonify
app = Flask(__name__)
def get_response(question):
responses = {
"hi": "Hello!",
"how are you": "I'm fine, thank you.",
"what's your name": "I'm a simple chatbot.",
"bye": "Goodbye!"
}
return responses.get(question.lower(), "I d... | import json
from solution import app
def test_chatbot_hi():
response = app.test_client().post('/chatbot',
data=json.dumps({"question": "hi"}),
content_type='application/json')
data = json.loads(response.data)
assert response.statu... | [
{
"docstring": null,
"function_declaration": "def get_response(question):",
"function_name": "get_response",
"parameter_list": "(question)"
},
{
"docstring": null,
"function_declaration": "def chatbot():",
"function_name": "chatbot",
"parameter_list": "()"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\ndef get_response(question):\n responses = {\n \"hi\": \"Hello!\",\n \"how are you\": \"I'm fine, thank yo... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047297",
"row_id": 47297,
"seed_ids": "['Qwen2.5-72B-Instruct_99985']"
} | 0.376099 | Filter_47297 | I | [
"get_response",
"chatbot"
] | 2 | [
[
"chatbot",
"get_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 7e0516fa6d520ee3ceb5c1c228e3c821857a04dd | 8c04e7587fd16b13bc9923cc079006369b8546d3 | |||
v1.0 | instruct | Filter | Filter_47303_I | I need to develop a Python function that can compute the perimeter of a triangle given the coordinates of its three vertices. The vertices will be provided as tuples of (x, y) coordinates. How can I do this? | import math
def distance(p1, p2):
"""
Returns the distance between two points p1 and p2.
"""
return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
def perimeter_of_triangle(vertex1, vertex2, vertex3):
"""
Returns the perimeter of a triangle given its three vertices.
The vertices should... | from solution import perimeter_of_triangle
def test_equilateral_triangle():
vertex1 = (0, 0)
vertex2 = (1, math.sqrt(3))
vertex3 = (2, 0)
assert math.isclose(perimeter_of_triangle(vertex1, vertex2, vertex3), 6)
def test_right_angle_triangle():
vertex1 = (0, 0)
vertex2 = (0, 3)
vertex3 = (4... | [
{
"docstring": "Returns the distance between two points p1 and p2.",
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": "Returns the perimeter of a triangle given its three vertices.\nThe vertices should be provided as... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef distance(p1, p2):\n \"\"\"\n Calculate the distance between two points p1 and p2.\n p1 and p2 are tuples representing coordinates (x, y).\n \"\"\"\n return ma... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047303",
"row_id": 47303,
"seed_ids": "['Qwen2.5-72B-Instruct_99992']"
} | 0.64559 | Filter_47303 | I | [
"distance",
"perimeter_of_triangle"
] | 2 | [
[
"perimeter_of_triangle",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c5fb94aa0c96c1573287ff5327b6ac730ff47a0 | 7a59018d265c0c6a4c6a6a0f95b60d505277b5af | |||
v1.0 | instruct | Filter | Filter_47305_I | I need to create a Python script that reads a JSON file and prints the sum of all numerical values within the file. The JSON file contains a dictionary with nested dictionaries and lists. How can I achieve this? | import json
def sum_numeric_values(json_data):
"""
Recursively sums all numeric values in a nested dictionary or list structure.
Args:
json_data (dict or list): The JSON data parsed.
Returns:
int/float: The sum of all numeric values.
"""
def _sum_values(data):
if isinstanc... | import json
from solution import sum_numeric_values, read_json_and_sum
def test_sum_numeric_values():
data = {
"a": 1,
"b": {"c": 2, "d": [3, 4]},
"e": [5, {"f": 6, "g": 7}],
"h": "non-numeric",
"i": [8.5, {"j": "text", "k": 9.5}]
}
assert sum_numeric_values(data) ==... | [
{
"docstring": "Recursively sums all numeric values in a nested dictionary or list structure.\n\nArgs:\njson_data (dict or list): The JSON data parsed.\n\nReturns:\nint/float: The sum of all numeric values.",
"function_declaration": "def sum_numeric_values(json_data):",
"function_name": "sum_numeric_val... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef sum_numerical_values(json_object):\n \"\"\"\n Recursively sum all numerical values in the json object.\n \"\"\"\n if isinstance(json_object, dict):\n retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047305",
"row_id": 47305,
"seed_ids": "['Qwen2.5-72B-Instruct_99994']"
} | 0.627674 | Filter_47305 | I | [
"sum_numeric_values",
"read_json_and_sum"
] | 2 | [
[
"read_json_and_sum",
"sum_numeric_values"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c93125f804ea708871137bff577952562ae1292f | f12deb548624a55eee2a154bc1759606f482e8bb | |||
v1.0 | instruct | Filter | Filter_47314_I | Can you help me with a Python script that checks if a website is up and running? I need to monitor a few websites for my job and would like to automate this process. It would be great if the script could send an email alert if a website is down. | import smtplib
import requests
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website(url):
try:
response = requests.get(url)
return response.status_code == 200
except requests.ConnectionError:
return False
def send_email_alert(sender_emai... | from unittest.mock import patch
from solution import check_website, send_email_alert, monitor_websites
def test_check_website_up():
with patch('requests.get') as mock_get:
mock_get.return_value.status_code = 200
assert check_website("http://example.com") == True
def test_check_website_down():
... | [
{
"docstring": null,
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
},
{
"docstring": null,
"function_declaration": "def send_email_alert(sender_email, receiver_email, smtp_server, smtp_port, smtp_password, subject, body):",... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.mime.text import MIMEText\n\ndef check_website(url):\n \"\"\"\n Checks if the given website is up and running.\n \"\"\"\n try:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047314",
"row_id": 47314,
"seed_ids": "['Qwen2.5-72B-Instruct_100006']"
} | 0.556577 | Filter_47314 | I | [
"check_website",
"send_email_alert",
"monitor_websites"
] | 3 | [
[
"monitor_websites",
"check_website"
],
[
"monitor_websites",
"send_email_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 8c6cd2baf26fdebd23af63a5a1de502057ada7ac | 9bdfde4caa4a4d1ca08a90a779d747a1ed5b7292 | |||
v1.0 | instruct | Filter | Filter_47321_I | Write a Python program to generate a list of prime numbers up to a given number n, and then find the sum of all prime numbers in the list. | def is_prime(num):
"""
Returns True if the number is prime, else False.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def generate_primes(n):
"""
Generates a list of prime numbers up to a given n... | from solution import is_prime, generate_primes, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_gen... | [
{
"docstring": "Returns True if the number is prime, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a list of prime numbers up to a given number n.",
"function_declaration": "def generate_pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047321",
"row_id": 47321,
"seed_ids": "['Qwen2.5-72B-Instruct_100015']"
} | 0.660121 | Filter_47321 | I | [
"is_prime",
"generate_primes",
"sum_of_primes"
] | 3 | [
[
"generate_primes",
"is_prime"
],
[
"sum_of_primes",
"generate_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0c0959fc5b83a0ad19ac1af1f2e46b3383c930d5 | b0ee95a8fbd45439353a294e75bf3a5e561b7fa3 | |||
v1.0 | instruct | Filter | Filter_47360_I | Design a Python program to simulate a simple game of rock-paper-scissors between a human player and the computer. The program should allow the human player to input their choice (rock, paper, or scissors), the computer should randomly select its choice, and then the program should determine the winner based on the stan... | import random
def get_computer_choice():
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(player_choice, computer_choice):
if player_choice == computer_choice:
return 'tie'
elif (player_choice == 'rock' and computer_choice == 'scissors') or \
(player_choice == 'sci... | from solution import get_computer_choice, determine_winner, update_score
def test_get_computer_choice():
for _ in range(100):
choice = get_computer_choice()
assert choice in ['rock', 'paper', 'scissors']
def test_determine_winner():
assert determine_winner('rock', 'scissors') == 'win'
asse... | [
{
"docstring": null,
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def determine_winner(player_choice, computer_choice):",
"function_name": "determine_winner",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly selects and returns one of 'rock', 'paper', or 'scissors' for the computer.\n \"\"\"\n return random.choice(['rock',... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047360",
"row_id": 47360,
"seed_ids": "['Qwen2.5-72B-Instruct_100071']"
} | 0.496019 | Filter_47360 | I | [
"get_computer_choice",
"determine_winner",
"update_score",
"play_game"
] | 4 | [
[
"play_game",
"determine_winner"
],
[
"play_game",
"get_computer_choice"
],
[
"play_game",
"update_score"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 35554be2c5498387ae25f906e031ca9f39253bfb | 6eb98c02990468ea05d75f35729f94b42ae60756 | |||
v1.0 | instruct | Filter | Filter_47378_I | Write a Python function that implements the backpropagation algorithm for a simple neural network with one hidden layer. The function should take as input the network's weights, biases, the input data, and the true labels, and return the gradients of the loss with respect to the weights and biases. Assume the activatio... | import numpy as np
def sigmoid(x):
"""
Compute the sigmoid of x.
"""
return 1 / (1 + np.exp(-x))
def sigmoid_derivative(x):
"""
Compute the derivative of the sigmoid function.
"""
return sigmoid(x) * (1 - sigmoid(x))
def mean_squared_error(y_true, y_pred):
"""
Compute the mean... | from solution import sigmoid, sigmoid_derivative, mean_squared_error, forward_pass, backward_pass, backpropagation
def test_sigmoid():
assert np.isclose(sigmoid(0), 0.5)
assert np.isclose(sigmoid(2), 0.8808, atol=1e-4)
def test_sigmoid_derivative():
assert np.isclose(sigmoid_derivative(0), 0.25)
a... | [
{
"docstring": "Compute the sigmoid of x.",
"function_declaration": "def sigmoid(x):",
"function_name": "sigmoid",
"parameter_list": "(x)"
},
{
"docstring": "Compute the derivative of the sigmoid function.",
"function_declaration": "def sigmoid_derivative(x):",
"function_name": "sigm... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef sigmoid(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": "00047378",
"row_id": 47378,
"seed_ids": "['Qwen2.5-72B-Instruct_100111']"
} | 0.42609 | Filter_47378 | I | [
"sigmoid",
"sigmoid_derivative",
"mean_squared_error",
"forward_pass",
"backward_pass",
"backpropagation"
] | 6 | [
[
"backpropagation",
"backward_pass"
],
[
"backpropagation",
"forward_pass"
],
[
"backward_pass",
"sigmoid_derivative"
],
[
"forward_pass",
"sigmoid"
],
[
"sigmoid_derivative",
"sigmoid"
]
] | 5 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 5ff5e444ac06e991e6efabcaaa685f6f95c4e249 | ddba297c6eaf4373e6cf50b864e7d1534d6ba29b | |||
v1.0 | instruct | Filter | Filter_47381_I | I have a series of files that need to be processed, and I want to create a Python script that will automatically iterate through a directory and apply a specific function to each file. How can I achieve this? | import os
def process_file(file_path):
"""
This function processes the file at the given file_path.
For demonstration purposes, it just reads the content and returns it.
You can modify this function to perform any processing needed.
"""
with open(file_path, 'r') as file:
content = file.... | import os
import tempfile
from solution import process_file, process_directory
def setup_test_directory(files):
"""
Creates a temporary directory and populates it with the provided files.
Args:
- files: A dictionary where keys are filenames and values are file contents
Returns:
The pa... | [
{
"docstring": "This function processes the file at the given file_path.\nFor demonstration purposes, it just reads the content and returns it.\nYou can modify this function to perform any processing needed.",
"function_declaration": "def process_file(file_path):",
"function_name": "process_file",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef process_file(file_path):\n \"\"\"\n This function processes the file at the given file_path.\n For demonstration purposes, it just reads the content and returns it.\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047381",
"row_id": 47381,
"seed_ids": "['Qwen2.5-72B-Instruct_100116']"
} | 0.502498 | Filter_47381 | I | [
"process_file",
"process_directory"
] | 2 | [
[
"process_directory",
"process_file"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cdc00815a53615d267390e50fff9fe5c31d4856b | ebcb2e7e1b27e98b6bcba58af06b70b36d7fa20f | |||
v1.0 | instruct | Filter | Filter_47398_I | Design a simple Python function to implement the merge sort algorithm. Your function should take a list of integers as input and return a new list that is sorted in ascending order. Make sure to include a brief explanation of how the merge sort algorithm works and any key points about your implementation. | def merge_sort(arr):
"""
Implement the merge sort algorithm to sort a list of integers in ascending order.
Merge sort is a divide and conquer algorithm that divides the input array into two halves,
calls itself for the two halves, and then merges the two sorted halves. The merge function
is u... | from solution import merge_sort
def test_merge_sort_empty_list():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_list():
assert... | [
{
"docstring": "Implement the merge sort algorithm to sort a list of integers in ascending order.\n\nMerge sort is a divide and conquer algorithm that divides the input array into two halves, \ncalls itself for the two halves, and then merges the two sorted halves. The merge function \nis used to merge the 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 Implements the merge sort algorithm to sort an array of integers in ascending order.\n \n Parameters:\n arr (list): The list of integers to sort.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047398",
"row_id": 47398,
"seed_ids": "['Qwen2.5-72B-Instruct_100149']"
} | 0.57407 | Filter_47398 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 982d88bda21494c02ce0ff95c8f6880f85b7e1c4 | 4e488ff9bd7d2f8437be2a471608f94b1a7205eb | |||
v1.0 | instruct | Filter | Filter_47469_I | Create a Python function to filter a list of numbers, keeping only those that are prime. Use list comprehension for this task. | def is_prime(n):
"""
Check if a number is prime.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def f... | from solution import filter_primes, is_prime
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(13)
assert not is_prime(15)
assert is_prime(17)
assert not is_prime(20)... | [
{
"docstring": "Check if a number is prime.\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filter the list of numbe... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047469",
"row_id": 47469,
"seed_ids": "['Qwen2.5-72B-Instruct_100264']"
} | 0.672924 | Filter_47469 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4c1fbd5d8248d6fd59155d62bc59f0899c8dd4a7 | 15ac0e5b30fdab2e08d29d42e8616f53c65dfad0 | |||
v1.0 | instruct | Filter | Filter_47479_I | Write a Python function to simulate a dice roll, where the number of sides on the dice is a parameter. The function should return a random integer representing the result of the roll. Ensure to use the `random` module for generating the random number. Additionally, provide a simple way to roll the dice multiple times a... | import random
def roll_dice(sides):
"""
Simulates a dice roll with the given number of sides.
Args:
sides (int): Number of sides on the dice.
Returns:
int: Result of the dice roll.
"""
if sides < 1:
raise ValueError("Number of sides must be at least 1")
return rand... | import pytest
from solution import roll_dice, roll_dice_multiple_times
def test_roll_dice_with_standard_sides():
result = roll_dice(6)
assert 1 <= result <= 6
def test_roll_dice_with_one_side():
result = roll_dice(1)
assert result == 1
def test_roll_dice_with_invalid_sides():
with pytest.raises(V... | [
{
"docstring": "Simulates a dice roll with the given number of sides.\n\nArgs:\nsides (int): Number of sides on the dice.\n\nReturns:\nint: Result of the dice roll.",
"function_declaration": "def roll_dice(sides):",
"function_name": "roll_dice",
"parameter_list": "(sides)"
},
{
"docstring": ... | [
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(sides):\n \"\"\"\n Simulate a roll of a dice with the specified number of sides.\n \n Args:\n sides (int): The number of sides on the dice.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047479",
"row_id": 47479,
"seed_ids": "['Qwen2.5-72B-Instruct_100277']"
} | 0.642274 | Filter_47479 | I | [
"roll_dice",
"roll_dice_multiple_times"
] | 2 | [
[
"roll_dice_multiple_times",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 56622ce3003e750b8aafe8939b166ebf92c9201f | 14991d9fd44030ca450f7033fbe6d7b836c18304 | |||
v1.0 | instruct | Filter | Filter_47493_I | Create a Python function that generates a list of prime numbers within a given range, and then use this function to find all prime numbers between 1 and 100. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def gener... | from solution import is_prime, generate_primes
def test_is_prime():
# Test cases for prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(29) == True
# Test cases for non-prime numbers
assert is_prime(1) == False
assert is_prime... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of prime numbers within the given range [start, end].",
"function_declaration": "de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047493",
"row_id": 47493,
"seed_ids": "['Qwen2.5-72B-Instruct_100296']"
} | 0.626075 | Filter_47493 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | df4738c895e7d5fc1ad2ad2178d2bd4e0d383bdb | 1269edead2f841fe091e41b5c8705c9f51c40add | |||
v1.0 | instruct | Filter | Filter_47527_I | Explain the concept of dynamic scoping in programming and how it differs from lexical scoping. Provide an example where dynamic scoping would be beneficial over lexical scoping. | dynamically_scoped_variable = None
def A():
global dynamically_scoped_variable
dynamically_scoped_variable = 'Hello from A'
B()
def B():
C()
def C():
return dynamically_scoped_variable | from solution import A, C
def test_dynamic_scoping():
A() # This sets dynamically_scoped_variable through A
assert C() == 'Hello from A' | [
{
"docstring": null,
"function_declaration": "def A():",
"function_name": "A",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def B():",
"function_name": "B",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def C():",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dynamic_scoping_example():\n \"\"\"\n Demonstrates a simple example of dynamic scoping.\n \"\"\"\n def inner_function():\n return x # Refers to the global x in dynamic ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047527",
"row_id": 47527,
"seed_ids": "['Qwen2.5-72B-Instruct_100355']"
} | 0.261326 | Filter_47527 | I | [
"A",
"B",
"C"
] | 3 | [
[
"A",
"B"
],
[
"B",
"C"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4c7c7e813ee556746f92f19e58defc1fd3aa71f4 | 445e8f5a5b143c00924de330280cc1bbfe42e285 | |||
v1.0 | instruct | Filter | Filter_47579_I | Design a sorting algorithm that can efficiently sort an array of integers, where the array size can be as large as 10^6, and the integers can range from -10^9 to 10^9. The algorithm should have a time complexity of O(n log n) or better. Describe the algorithm and provide a step-by-step explanation of how it works. | def merge_sort(arr):
"""
Function to sort an array using merge sort algorithm.
"""
if len(arr) <= 1:
return arr
# Divide the array into two halves
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])
# Merge the sorted halves
return m... | from solution import merge_sort
def test_merge_sort_empty_array():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_order():
assert mer... | [
{
"docstring": "Function to sort an array using merge sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Helper function to merge two sorted arrays into one sorted array.",
"function_declaration": ... | [
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 :param arr: List[int] - the array to be sorted\n :return: List[int] - the sorted array\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047579",
"row_id": 47579,
"seed_ids": "['Qwen2.5-72B-Instruct_100437']"
} | 0.560208 | Filter_47579 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e11c1d4379025f81e2c0aaa976acfc7091fc5f6f | 32bc5f379375d3affa327c9edcd01cf7dbda34f3 | |||
v1.0 | instruct | Filter | Filter_47585_I | How can I create a simple chatbot using Python and Flask that can respond to basic text-based commands? | from flask import Flask, request, jsonify
app = Flask(__name__)
def chatbot_response(user_input):
"""
Returns a simple response based on the user's input.
"""
user_input = user_input.lower()
if 'hello' in user_input:
return 'Hello! How can I assist you today?'
elif 'your name' in user_... | import pytest
from solution import chatbot_response
def test_chatbot_response_hello():
assert chatbot_response('Hello') == 'Hello! How can I assist you today?'
assert chatbot_response('hello') == 'Hello! How can I assist you today?'
def test_chatbot_response_name():
assert chatbot_response('What is your n... | [
{
"docstring": "Returns a simple response based on the user's input.",
"function_declaration": "def chatbot_response(user_input):",
"function_name": "chatbot_response",
"parameter_list": "(user_input)"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "c... | [
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 respond_to_command(command):\n \"\"\"\n This function takes a text command as input and returns a response based... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047585",
"row_id": 47585,
"seed_ids": "['Qwen2.5-72B-Instruct_100445']"
} | 0.384498 | Filter_47585 | I | [
"chatbot_response",
"chat"
] | 2 | [
[
"chat",
"chatbot_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 4dd937598c22851e1a6e1f952327a781fe6b3213 | 2128a47d9771eab99997cacfe922cb97d94570fb | |||
v1.0 | instruct | Filter | Filter_47604_I | Write a Python program to find the largest palindrome made from the product of two 3-digit numbers. Also, the program should be able to identify the two 3-digit numbers that produce this palindrome. Ensure the program is efficient and well-optimized. | def is_palindrome(n):
"""
Checks if `n` is a palindrome.
"""
return str(n) == str(n)[::-1]
def largest_palindrome_product():
"""
Finds the largest palindrome made from the product of two 3-digit numbers
and returns the palindrome along with the numbers.
"""
max_palindrome = 0
fa... | from solution import is_palindrome, largest_palindrome_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(12321) == True
assert is_palindrome(123321) == True
assert is_palindrome(123421) ... | [
{
"docstring": "Checks if `n` is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Finds the largest palindrome made from the product of two 3-digit numbers\nand returns the palindrome along with the ... | [
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(n):\n \"\"\"\n Checks if `n` is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef largest_palindrome_product():\n \"\"\"\n Finds the largest pal... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047604",
"row_id": 47604,
"seed_ids": "['Qwen2.5-72B-Instruct_100471']"
} | 0.688714 | Filter_47604 | I | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8e85e7e7fdbefc44fab6b5316471101ecc8a4625 | fa4a51c50f366925f7f23006e4384eaf9a1ceb85 | |||
v1.0 | instruct | Filter | Filter_47638_I | Create a basic Python program that reads a CSV file, where the first column contains dates in the format 'YYYY-MM-DD' and the second column contains numerical values. The program should calculate the moving average of the numerical values over a window of 3 days and output the result to a new CSV file, along with the c... | import csv
from datetime import datetime
from statistics import mean
def read_csv(file_path):
"""
Reads a CSV file and returns the data as a list of tuples (date, value).
"""
data = []
try:
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
for row in c... | import os
from solution import read_csv, write_csv, calculate_moving_average, process_csv
def test_read_csv_valid_input(tmp_path):
file_path = tmp_path / "test_input.csv"
file_path.write_text("2023-01-01,100\n2023-01-02,200\n2023-01-03,300\n")
data = read_csv(file_path)
assert data == [
(dateti... | [
{
"docstring": "Reads a CSV file and returns the data as a list of tuples (date, value).",
"function_declaration": "def read_csv(file_path):",
"function_name": "read_csv",
"parameter_list": "(file_path)"
},
{
"docstring": "Writes data to a CSV file.",
"function_declaration": "def write_c... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nfrom datetime import datetime\nfrom statistics import mean\n\ndef read_csv(file_path):\n \"\"\"\n Reads a CSV file and returns the data as a list of tuples (date, value).\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047638",
"row_id": 47638,
"seed_ids": "['Qwen2.5-72B-Instruct_100530']"
} | 0.593725 | Filter_47638 | I | [
"read_csv",
"write_csv",
"calculate_moving_average",
"process_csv"
] | 4 | [
[
"process_csv",
"calculate_moving_average"
],
[
"process_csv",
"read_csv"
],
[
"process_csv",
"write_csv"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 642aca67252bf271e351240e01f3b89d442e9f08 | d07745cae2903b89cd4aae995bd8b001b68bdbcf | |||
v1.0 | instruct | Filter | Filter_47664_I | Write a Python program that uses the Sieve of Eratosthenes to find all prime numbers up to a given limit, and then calculates the sum of these prime numbers. The program should take the limit as input from the user and print the sum of the primes. | def sieve_of_eratosthenes(limit):
"""
Returns a list of all prime numbers up to the given limit.
"""
sieve = [True] * (limit + 1)
primes = []
p = 2
while p * p <= limit:
if sieve[p]:
for i in range(p * p, limit + 1, p):
sieve[i] = False
p += 1... | from solution import sieve_of_eratosthenes, sum_of_primes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
assert sieve_of_eratosthenes(2) == [2]
assert sieve_of_eratosthenes(1) == []
def test_sum_of_pri... | [
{
"docstring": "Returns a list of all prime numbers up to the given limit.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns the sum of all prime numbers up to the given limit.",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Returns a list of all prime numbers up to the given limit.\n \"\"\"\n sieve = [True] * (limit + 1)\n primes = []\n p = 2\n \n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047664",
"row_id": 47664,
"seed_ids": "['Qwen2.5-72B-Instruct_100581']"
} | 0.5935 | Filter_47664 | I | [
"sieve_of_eratosthenes",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f831164e0c9168d9be2d4758a9cc59e7ee595692 | 07629c30a3f3c0b88463216c7e58563c2fb46f28 | |||
v1.0 | instruct | Filter | Filter_47718_I | Design a Python program that simulates a simple dice game. The game involves two players who each roll a six-sided die. The player with the higher number wins. If both roll the same number, it's a tie. The program should allow the user to play against the computer. After each round, the program should display the resul... | import random
def roll_dice():
"""
Simulates rolling a six-sided die and returns the result (an integer between 1 and 6).
"""
return random.randint(1, 6)
def play_round():
"""
Simulates a round of the dice game between the user and the computer.
Returns the result as a tuple (user_roll, co... | from solution import roll_dice, play_round
def test_roll_dice():
# Roll the dice 1000 times to ensure it produces values between 1 and 6
for _ in range(1000):
result = roll_dice()
assert 1 <= result <= 6
def test_play_round():
user_roll, computer_roll, result = play_round()
assert... | [
{
"docstring": "Simulates rolling a six-sided die and returns the result (an integer between 1 and 6).",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a round of the dice game between the user and the computer.\n... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n return random.randint(1, 6)\n\ndef play_dice_game(rounds):\n user_score = 0\n computer_score = 0\n \n for _ in range(rounds):\n user_r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047718",
"row_id": 47718,
"seed_ids": "['Qwen2.5-72B-Instruct_100658']"
} | 0.533247 | Filter_47718 | I | [
"roll_dice",
"play_round"
] | 2 | [
[
"play_round",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e95e86e141b535507706260873219ffe68cb89e | b64d96c8708a744b51085fdd1f63903b0e10412d | |||
v1.0 | instruct | Filter | Filter_47745_I | Write a Python program that simulates a simple game of rock, paper, scissors. The game should allow a user to play against the computer, which randomly selects its choice. The program should keep track of the score and allow the user to play multiple rounds until they decide to quit. The user should be able to input th... | import random
def get_computer_choice():
"""
Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice.
"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(user_choice, computer_choice):
"""
Determines the winner between the user and computer.
Return... | from solution import get_computer_choice, determine_winner, play_round
def test_get_computer_choice():
choice = get_computer_choice()
assert choice in ['rock', 'paper', 'scissors']
def test_determine_winner_tie():
assert determine_winner('rock', 'rock') == 'tie'
assert determine_winner('paper', 'paper... | [
{
"docstring": "Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner between the user and computer.\nReturns:\n... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice.\n \"\"\"\n return random.choice(['rock', 'paper', '... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047745",
"row_id": 47745,
"seed_ids": "['Qwen2.5-72B-Instruct_100700']"
} | 0.504659 | Filter_47745 | I | [
"get_computer_choice",
"determine_winner",
"play_round"
] | 3 | [
[
"play_round",
"determine_winner"
],
[
"play_round",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d65e643b455aff898af5ec6d4e6f60d91625422e | 18fd477209931bd84ba0c4f945e3ccdf00188e41 | |||
v1.0 | instruct | Filter | Filter_47760_I | Design a Python function that calculates the nth Fibonacci number using recursion. The function should be efficient and handle large values of n by utilizing memoization. Additionally, implement a check function that tests the correctness of your Fibonacci function with given data points. | def fibonacci(n, memo=None):
"""
Calculates the nth Fibonacci number using recursion with memoization.
"""
if memo is None:
memo = {}
if n in memo:
return memo[n]
if n <= 1:
return n
memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)
return memo[n]
def check_... | from solution import fibonacci
def test_fibonacci_small_numbers():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
def test_fibonacci_medium_numbers():
assert fibonacci(10) == 55
assert fibonacci(15) == 610
assert fibonacci(20) == 6765
d... | [
{
"docstring": "Calculates the nth Fibonacci number using recursion with memoization.",
"function_declaration": "def fibonacci(n, memo=None):",
"function_name": "fibonacci",
"parameter_list": "(n, memo=None)"
},
{
"docstring": "Check the correctness of the fibonacci function with known data ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Returns the nth Fibonacci number using recursion with memoization.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 1:\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047760",
"row_id": 47760,
"seed_ids": "['Qwen2.5-72B-Instruct_100722']"
} | 0.756818 | Filter_47760 | I | [
"fibonacci",
"check_fibonacci"
] | 2 | [
[
"check_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 884cef47b2ebdd361ab43d5d8a609987f01521b7 | 28b3c99811bf8f97a7fd5011b945751f422848af | |||
v1.0 | instruct | Filter | Filter_47791_I | Write a Python function that checks if a given number is an integer and, if so, rounds it to the nearest thousandth. If the number is not an integer, it should return an error message. Use the function to process a list of numbers and return a list of results. | def process_number(number):
"""
Checks if the given number is an integer and, if so, rounds it to the nearest thousandth.
If the number is not an integer, returns an error message.
"""
if not isinstance(number, (int, float)):
return "Error: Input is not a number"
if not isinstan... | from solution import process_number, process_list
def test_process_number_integer():
assert process_number(12345) == 12000
def test_process_number_negative_integer():
assert process_number(-12345) == -12000
def test_process_number_zero():
assert process_number(0) == 0
def test_process_number_not_integer... | [
{
"docstring": "Checks if the given number is an integer and, if so, rounds it to the nearest thousandth.\nIf the number is not an integer, returns an error message.",
"function_declaration": "def process_number(number):",
"function_name": "process_number",
"parameter_list": "(number)"
},
{
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def round_to_thousandth(num):\n \"\"\"\n Check if the given number is an integer. If so, round it to the nearest thousandth.\n If the number is not an integer, return an error message... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047791",
"row_id": 47791,
"seed_ids": "['Qwen2.5-72B-Instruct_100768']"
} | 0.677466 | Filter_47791 | I | [
"process_number",
"process_list"
] | 2 | [
[
"process_list",
"process_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4fbcb1c20b443a1167f9f0a1ceb463232da293b | 28826c35f13feadf82425ff07c4823f062f24331 | |||
v1.0 | instruct | Filter | Filter_47796_I | Explain the concept of mutual recursion in computer science, and provide a simple example using Python. | def is_even(n):
"""
Determines if the given number n is even.
Uses mutual recursion with is_odd.
"""
if n == 0:
return True
else:
return is_odd(n - 1)
def is_odd(n):
"""
Determines if the given number n is odd.
Uses mutual recursion with is_even.
"""
if n == ... | from solution import is_even, is_odd
def test_is_even_true():
assert is_even(0) == True
assert is_even(2) == True
assert is_even(4) == True
def test_is_even_false():
assert is_even(1) == False
assert is_even(3) == False
assert is_even(5) == False
def test_is_odd_true():
assert is_odd(1) =... | [
{
"docstring": "Determines if the given number n is even.\nUses mutual recursion with is_odd.",
"function_declaration": "def is_even(n):",
"function_name": "is_even",
"parameter_list": "(n)"
},
{
"docstring": "Determines if the given number n is odd.\nUses mutual recursion with is_even.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(n):\n \"\"\"\n Determines if n is an even number using mutual recursion.\n \"\"\"\n if n == 0:\n return True\n else:\n return is_odd(n - 1)\n \n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047796",
"row_id": 47796,
"seed_ids": "['Qwen2.5-72B-Instruct_100774']"
} | 0.429145 | Filter_47796 | I | [
"is_even",
"is_odd"
] | 2 | [
[
"is_even",
"is_odd"
],
[
"is_odd",
"is_even"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 101ee53a3391c59393523966947b50b7a9e02912 | 32632751a616f141ab3278832aa0519ad0e49de0 | |||
v1.0 | instruct | Filter | Filter_47797_I | How can I create a Python function to convert a list of temperatures from Celsius to Fahrenheit and display them in a formatted table? | def celsius_to_fahrenheit(celsius):
"""
Converts a temperature from Celsius to Fahrenheit.
"""
return celsius * 9 / 5 + 32
def display_temperatures(temperatures):
"""
Converts a list of temperatures from Celsius to Fahrenheit and displays them in a formatted table.
Args:
temperature... | from solution import celsius_to_fahrenheit, display_temperatures
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32.0
assert celsius_to_fahrenheit(100) == 212.0
assert celsius_to_fahrenheit(-40) == -40.0
assert celsius_to_fahrenheit(37) == 98.6
def test_display_temperatures(capsys... | [
{
"docstring": "Converts a temperature from Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius)"
},
{
"docstring": "Converts a list of temperatures from Celsius to Fahrenheit and displa... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def celsius_to_fahrenheit(celsius_temp):\n \"\"\"\n Converts a temperature from Celsius to Fahrenheit.\n \n :param celsius_temp: Temperature in Celsius.\n :return: Temperature i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047797",
"row_id": 47797,
"seed_ids": "['Qwen2.5-72B-Instruct_100775']"
} | 0.511907 | Filter_47797 | I | [
"celsius_to_fahrenheit",
"display_temperatures"
] | 2 | [
[
"display_temperatures",
"celsius_to_fahrenheit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ddbfaf845ddf6ed52206f03cb7d7e09d50edd5e5 | 73438e3138901655c590ac58f4a529942a2db871 | |||
v1.0 | instruct | Filter | Filter_47819_I | You are tasked with creating a function in Python that can encode and decode a string using a custom algorithm. The algorithm should take a string and a key, then encode the string by shifting each character by the key value. For decoding, the process should be reversed. The function should handle both uppercase and lo... | def encode_string(s, key):
"""
Encodes the string by shifting each character by key value.
Non-alphabet characters remain unchanged.
"""
def shift_char(c, key):
if c.isalpha():
start = ord('A') if c.isupper() else ord('a')
return chr((ord(c) - start + key) % 26 + star... | from solution import encode_string, decode_string
def test_encode_string_with_simple_key():
assert encode_string("ABC", 1) == "BCD"
assert encode_string("abc", 1) == "bcd"
assert encode_string("XYZ", 3) == "ABC"
assert encode_string("xyz", 2) == "zab"
def test_encode_string_with_large_key():
asser... | [
{
"docstring": "Encodes the string by shifting each character by key value.\nNon-alphabet characters remain unchanged.",
"function_declaration": "def encode_string(s, key):",
"function_name": "encode_string",
"parameter_list": "(s, key)"
},
{
"docstring": "Decodes the string by shifting each... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encode_decode_string(s, key, mode='encode'):\n \"\"\"\n Encodes or decodes a string using a shift cipher with the given key.\n \n :param s: String to be encoded or decoded.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047819",
"row_id": 47819,
"seed_ids": "['Qwen2.5-72B-Instruct_100808']"
} | 0.719569 | Filter_47819 | I | [
"encode_string",
"decode_string"
] | 2 | [
[
"decode_string",
"encode_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b14d7fccc8b6e42b457ac05b43bfa78cdd9a6122 | 0c30103281a5e3463f59e736486eed060bfe2ef9 | |||
v1.0 | instruct | Filter | Filter_47835_I | Create a Python script that automates the process of checking if a website is up and running. The script should take a list of URLs from a text file, check each website, and log the results (whether the site is up or down) into another text file. Additionally, the script should handle exceptions gracefully and provide ... | import requests
def check_website(url):
"""
Checks if the given URL is up and running.
"""
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
return True
else:
return False
except requests.RequestException:
return Fal... | from solution import check_website, check_websites_from_file
import tempfile
import os
def test_check_website_up(monkeypatch):
def mock_get(url, timeout):
class MockResponse:
status_code = 200
return MockResponse()
monkeypatch.setattr(requests, 'get', mock_get)
assert check_webs... | [
{
"docstring": "Checks if the given URL is up and running.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
},
{
"docstring": "Checks the list of URLs from the input file and logs the results to the output file.",
"function_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\n\ndef check_website_status(url):\n \"\"\"\n Checks if the given website is up and running.\n Returns True if the website is up, otherwise returns False.\n \"\"\"\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047835",
"row_id": 47835,
"seed_ids": "['Qwen2.5-72B-Instruct_100835']"
} | 0.590615 | Filter_47835 | I | [
"check_website",
"check_websites_from_file"
] | 2 | [
[
"check_websites_from_file",
"check_website"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | e2533874b32382a8c40d46b3f5024499a5a7771c | 3a7ca81d30d57b1ce01dbe886bff5bd698d10ad6 | |||
v1.0 | instruct | Filter | Filter_47847_I | Hello Qwen, I'm looking to create a basic web application that allows users to upload images and then apply various filters to them using Python. Could you guide me on how to set up the backend for this? I'm particularly interested in using Flask and Pillow for this project. | from flask import Flask, request, jsonify, send_file
from PIL import Image, ImageFilter
import io
import os
app = Flask(__name__)
# Ensure the upload folder exists
UPLOAD_FOLDER = 'uploads'
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Allowed ext... | import pytest
import os
from io import BytesIO
from PIL import Image
from solution import app
@pytest.fixture
def client():
app.config['TESTING'] = True
client = app.test_client()
# Ensure the upload folder is clean before running tests
if not os.path.exists(app.config['UPLOAD_FOLDER']):
os.ma... | [
{
"docstring": null,
"function_declaration": "def allowed_file(filename):",
"function_name": "allowed_file",
"parameter_list": "(filename)"
},
{
"docstring": null,
"function_declaration": "def upload_image():",
"function_name": "upload_image",
"parameter_list": "()"
},
{
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify, send_file\nfrom PIL import Image, ImageFilter\nimport io\nimport os\n\napp = Flask(__name__)\n\n# Ensure the upload folder exists\nUPLOAD_FOLDER = 'u... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047847",
"row_id": 47847,
"seed_ids": "['Qwen2.5-72B-Instruct_100854']"
} | 0.414236 | Filter_47847 | I | [
"allowed_file",
"upload_image",
"apply_filter"
] | 3 | [
[
"upload_image",
"allowed_file"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL",
"flask"
] | false | aa7674e65d16118c23979a69a4b089fc788b2351 | 2be5653bac18e6fe4ceb6fb4c5cbde7b71ead832 | |||
v1.0 | instruct | Filter | Filter_47871_I | I need to create a Python script that can take a directory path as an input and then calculate the total size of all files within that directory, including files in subdirectories. The script should also be able to output the size of each file in a human-readable format (e.g., KB, MB, GB). Can you help me with the code... | import os
def get_size_format(size_in_bytes):
"""
Converts size from bytes to a human-readable format (KB, MB, GB, etc.).
"""
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if size_in_bytes < 1024:
return f"{size_in_bytes:.2f} {unit}"
size_in_bytes /= 1024
def calculate_directo... | import os
from solution import get_size_format, calculate_directory_size
def test_get_size_format():
assert get_size_format(123) == "123.00 B"
assert get_size_format(1234) == "1.21 KB"
assert get_size_format(1234567) == "1.18 MB"
assert get_size_format(1234567890) == "1.15 GB"
def test_calculate_d... | [
{
"docstring": "Converts size from bytes to a human-readable format (KB, MB, GB, etc.).",
"function_declaration": "def get_size_format(size_in_bytes):",
"function_name": "get_size_format",
"parameter_list": "(size_in_bytes)"
},
{
"docstring": "Calculates the total size of all files within th... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef get_size_format(size_in_bytes):\n \"\"\"\n Converts size from bytes to a human-readable format (KB, MB, GB, etc.).\n \"\"\"\n for unit in ['B', 'KB', 'MB', 'GB', '... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047871",
"row_id": 47871,
"seed_ids": "['Qwen2.5-72B-Instruct_100885']"
} | 0.663815 | Filter_47871 | I | [
"get_size_format",
"calculate_directory_size"
] | 2 | [
[
"calculate_directory_size",
"get_size_format"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 517d292b771988d70fa81a8f1078716af2d31f06 | 3ac251883863e6bd32308bf720d98e2aed7c9a2b | |||
v1.0 | instruct | Filter | Filter_47904_I | I am working on a project that involves converting a large number of images into grayscale using Python. I've heard that using multiprocessing can speed up the process, but I'm not sure how to implement it effectively. Can you provide an example of how to use Python's multiprocessing to convert a list of images into gr... | from PIL import Image
import os
import multiprocessing
def convert_to_grayscale(image_path):
"""
Converts the given image to grayscale.
:param image_path: Path to the image file.
"""
img = Image.open(image_path).convert('L')
grayscale_image_path = os.path.splitext(image_path)[0] + "_graysc... | import os
from PIL import Image
from solution import convert_to_grayscale, process_images_in_parallel
def setup_module(module):
""" Setup a mock environment with a test image """
test_image = Image.new('RGB', (10, 10), color = 'red')
test_image.save('test_image_1.jpg')
test_image.save('test_image_2.jpg... | [
{
"docstring": "Converts the given image to grayscale.\n\n:param image_path: Path to the image file.",
"function_declaration": "def convert_to_grayscale(image_path):",
"function_name": "convert_to_grayscale",
"parameter_list": "(image_path)"
},
{
"docstring": "Converts a list of images to gr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from multiprocessing import Pool, cpu_count\nfrom PIL import Image\nimport os\n\ndef convert_to_grayscale(image_path):\n \"\"\"\n Converts an image to grayscale and saves it.\n \"\"\"... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00047904",
"row_id": 47904,
"seed_ids": "['Qwen2.5-72B-Instruct_100934']"
} | 0.489781 | Filter_47904 | I | [
"convert_to_grayscale",
"process_images_in_parallel"
] | 2 | [
[
"process_images_in_parallel",
"convert_to_grayscale"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | b753fe454f8588893baaaf93883a75e0c771f95c | 6dec84123e56fe6f416deffa1760762d2e5b60b7 | |||
v1.0 | instruct | Filter | Filter_47918_I | I need to write a function in Python that can sort a list of strings based on the numerical value within each string. The numerical value can be anywhere in the string, and it should be sorted in ascending order. If a string does not contain a number, it should be placed at the end of the list. How can I achieve this? | import re
def extract_number(s):
"""
Extracts the first found number in the string. If the string does not contain a number, returns None.
"""
match = re.search(r'\d+', s)
return int(match.group()) if match else None
def sort_strings_by_number(strings):
"""
Sorts a list of strings based on... | from solution import sort_strings_by_number
def test_sort_strings_by_number_basic():
input_list = ['a1', 'a3', 'a2']
expected_output = ['a1', 'a2', 'a3']
assert sort_strings_by_number(input_list) == expected_output
def test_sort_strings_by_number_mixed():
input_list = ['abc', 'a2', 'a1', 'xyz', 'a3']
... | [
{
"docstring": "Extracts the first found number in the string. If the string does not contain a number, returns None.",
"function_declaration": "def extract_number(s):",
"function_name": "extract_number",
"parameter_list": "(s)"
},
{
"docstring": "Sorts a list of strings based on the numeric... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef extract_number(s):\n \"\"\"\n Extract the first number found in the string s.\n If no number is found, return None.\n \"\"\"\n match = re.search(r'\\d+', s)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047918",
"row_id": 47918,
"seed_ids": "['Qwen2.5-72B-Instruct_100958']"
} | 0.72839 | Filter_47918 | I | [
"extract_number",
"sort_strings_by_number"
] | 2 | [
[
"sort_strings_by_number",
"extract_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ab4bc6bb96b358a82155803e1c5357486adc73d | 554a25560ad28f77b30d60eed4c14826f3959101 | |||
v1.0 | instruct | Filter | Filter_47947_I | Write a Python program to simulate a simple dice game. The game involves two players, and each player rolls a six-sided die. The player with the highest roll wins. If both players roll the same number, it's a tie. The program should allow the user to play against the computer. The computer's roll should be randomly gen... | import random
def roll_die():
"""
Simulates rolling a six-sided die.
Returns an integer in the range 1 to 6 inclusive.
"""
return random.randint(1, 6)
def play_dice_game():
"""
Simulates a dice game between the user and the computer.
"""
user_roll = roll_die()
computer_roll = r... | import pytest
from solution import roll_die, play_dice_game
def test_roll_die():
for _ in range(100): # Test 100 times to ensure appropriate randomness.
result = roll_die()
assert 1 <= result <= 6
def test_play_dice_game_tie(monkeypatch):
monkeypatch.setattr('solution.roll_die', lambda: 3)
... | [
{
"docstring": "Simulates rolling a six-sided die.\nReturns an integer in the range 1 to 6 inclusive.",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Simulates a dice game between the user and the computer.",
"function_d... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_dice_game(player_roll=None)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047947",
"row_id": 47947,
"seed_ids": "['Qwen2.5-72B-Instruct_100991']"
} | 0.496512 | Filter_47947 | I | [
"roll_die",
"play_dice_game"
] | 2 | [
[
"play_dice_game",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76a2c60eed8148e075038bb49a0adf7a2d174935 | 78081b310e293597dfa0e03a76c09342697a6393 | |||
v1.0 | instruct | Filter | Filter_47950_I | Please write a function in Python that calculates the least common multiple (LCM) of two positive integers. The function should be efficient and well-documented. Additionally, provide a simple way to test the function with a few examples to ensure it works correctly. | def gcd(a, b):
"""
Computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
"""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""
Computes the least common multiple (LCM) of two positive integers.
The LCM of two integers is the smallest positi... | from solution import lcm
def test_lcm_coprime_numbers():
assert lcm(4, 5) == 20
def test_lcm_same_numbers():
assert lcm(7, 7) == 7
def test_lcm_with_one():
assert lcm(1, 10) == 10
assert lcm(10, 1) == 10
def test_lcm_large_numbers():
assert lcm(123, 456) == 18696
def test_lcm_prime_and_multiple... | [
{
"docstring": "Computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Computes the least common multiple (LCM) of two positive integers.\nThe ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n \"\"\"\n Computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\nde... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047950",
"row_id": 47950,
"seed_ids": "['Qwen2.5-72B-Instruct_100994']"
} | 0.721455 | Filter_47950 | I | [
"gcd",
"lcm"
] | 2 | [
[
"lcm",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e01ecd1bf85c232ce9ed4dfd40af421df4044191 | 87107365497149cbdbbe8bc36d6b44f5c19dd8d0 | |||
v1.0 | instruct | Filter | Filter_47972_I | I need to create a Python function that can generate a list of strings. Each string should be a random combination of letters and numbers, and all strings in the list should be of the same length. How can I achieve this? | import random
import string
def generate_random_string(length):
"""
Generate a random string of letters and digits with the given length.
"""
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(length))
def generate_list_of_random_strings(n, le... | from solution import generate_random_string, generate_list_of_random_strings
def test_generate_random_string_length():
length = 10
result = generate_random_string(length)
assert len(result) == length
def test_generate_random_string_content():
result = generate_random_string(15)
for char in result:... | [
{
"docstring": "Generate a random string of letters and digits with the given length.",
"function_declaration": "def generate_random_string(length):",
"function_name": "generate_random_string",
"parameter_list": "(length)"
},
{
"docstring": "Generate a list of n random strings, each of the s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_random_strings(n, length):\n \"\"\"\n Generates a list of n random strings. Each string is a random combination of \n letters and numbers ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00047972",
"row_id": 47972,
"seed_ids": "['Qwen2.5-72B-Instruct_101032']"
} | 0.761543 | Filter_47972 | I | [
"generate_random_string",
"generate_list_of_random_strings"
] | 2 | [
[
"generate_list_of_random_strings",
"generate_random_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a204f58249fa5ed0087ec6ba5f11787e7ad7e0ee | abc808aacc2c76d21d20437916a0d7d3a85f61e9 | |||
v1.0 | instruct | Filter | Filter_47975_I | Write a Python program that calculates the sum of the digits of a given number. The program should also determine if the sum is a prime number and return a message stating whether the sum is prime or not. If the input is not a positive integer, the program should return an error message. | def is_prime(n):
"""
Determines if a number is prime.
"""
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_digits_and_check_prime(number):
"""
Calculates the sum of the digits of a given number an... | from solution import sum_of_digits_and_check_prime
def test_valid_prime_sum():
assert sum_of_digits_and_check_prime(23) == "The sum of digits is 5 and it is a prime number."
def test_valid_non_prime_sum():
assert sum_of_digits_and_check_prime(29) == "The sum of digits is 11 and it is a prime number."
asse... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the sum of the digits of a given number and checks if the sum is a prime number.\nReturns a message stating whethe... | [
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 Determines if a number is prime.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00047975",
"row_id": 47975,
"seed_ids": "['Qwen2.5-72B-Instruct_101039']"
} | 0.652268 | Filter_47975 | I | [
"is_prime",
"sum_of_digits_and_check_prime"
] | 2 | [
[
"sum_of_digits_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d257f4fe66d116d22e659119ca3f46dbaadb8399 | f8a75ea8e908bd45b9b3259d2eb7d8233784f6b0 | |||
v1.0 | instruct | Filter | Filter_48000_I | Write a Python function that generates a list of the first n Fibonacci numbers, starting from 0, and returns this list. The function should be efficient and use a generator to produce the sequence. Additionally, include a simple way to test the function with a few values to ensure its correctness. | def fibonacci_gen(n):
"""
Generates the first n Fibonacci numbers starting from 0.
"""
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
def first_n_fibonacci(n):
"""
Returns a list of the first n Fibonacci numbers using the generator.
"""
return list(fibonacci_... | from solution import first_n_fibonacci
def test_fibonacci_zero():
assert first_n_fibonacci(0) == []
def test_fibonacci_one():
assert first_n_fibonacci(1) == [0]
def test_fibonacci_two():
assert first_n_fibonacci(2) == [0, 1]
def test_fibonacci_seven():
assert first_n_fibonacci(7) == [0, 1, 1, 2, 3, ... | [
{
"docstring": "Generates the first n Fibonacci numbers starting from 0.",
"function_declaration": "def fibonacci_gen(n):",
"function_name": "fibonacci_gen",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of the first n Fibonacci numbers using the generator.",
"function_declar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n):\n \"\"\"\n Generates the first n Fibonacci numbers starting from 0.\n Yields the sequence using a generator for efficiency.\n \"\"\"\n a, b = 0, 1\n for _ i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048000",
"row_id": 48000,
"seed_ids": "['Qwen2.5-72B-Instruct_101080']"
} | 0.762859 | Filter_48000 | I | [
"fibonacci_gen",
"first_n_fibonacci"
] | 2 | [
[
"first_n_fibonacci",
"fibonacci_gen"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ebea5230cff00edbbca541098e37f111aa728a27 | 2c88384d42bce800f24d727b65ed22bfa014d8bf | |||
v1.0 | instruct | Filter | Filter_48024_I | Write a Python program to solve the Tower of Hanoi problem using recursion. The program should be able to print the steps required to move all the disks from the source peg to the destination peg, using an auxiliary peg. Make sure to include a function that demonstrates the solution with a specific number of disks, say... | def tower_of_hanoi(n, source, destination, auxiliary):
"""
Solves the Tower of Hanoi problem for n disks.
Parameters:
n (int): Number of disks
source (str): The source peg
destination (str): The destination peg
auxiliary (str): The auxiliary peg
Returns:
List of moves as tu... | from solution import tower_of_hanoi, example_tower_of_hanoi
def test_tower_of_hanoi_1_disk():
moves = tower_of_hanoi(1, 'A', 'C', 'B')
assert moves == [('A', 'C')]
def test_tower_of_hanoi_2_disks():
moves = tower_of_hanoi(2, 'A', 'C', 'B')
assert moves == [('A', 'B'), ('A', 'C'), ('B', 'C')]
def test... | [
{
"docstring": "Solves the Tower of Hanoi problem for n disks.\n\nParameters:\nn (int): Number of disks\nsource (str): The source peg\ndestination (str): The destination peg\nauxiliary (str): The auxiliary peg\n\nReturns:\nList of moves as tuples (source, destination)",
"function_declaration": "def tower_of... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tower_of_hanoi(n, source, target, auxiliary, moves):\n \"\"\"\n Solves the Tower of Hanoi problem.\n \n Parameters:\n - n: The number of disks.\n - source: The peg from w... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048024",
"row_id": 48024,
"seed_ids": "['Qwen2.5-72B-Instruct_101116']"
} | 0.425896 | Filter_48024 | I | [
"tower_of_hanoi",
"example_tower_of_hanoi"
] | 2 | [
[
"example_tower_of_hanoi",
"tower_of_hanoi"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 386fb8184ad1309b5f4fee48c5ec7ce35f731367 | 2c683df8c1a67bbc50d02b6695fa947872181aea | |||
v1.0 | instruct | Filter | Filter_48027_I | Write a Python program that implements the merge sort algorithm and sorts a list of numbers. Make sure to include comments explaining the key steps in the algorithm. | def merge_sort(arr):
"""
Sorts a list of numbers using the merge sort algorithm.
:param arr: List of numbers to be sorted
:return: Sorted list of numbers
"""
if len(arr) <= 1:
return arr
# Split the array into halves
middle = len(arr) // 2
left_half = arr[:middle]
right... | from solution import merge_sort
def test_merge_sort_empty_list():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_list():
assert... | [
{
"docstring": "Sorts a list of numbers using the merge sort algorithm.\n\n:param arr: List of numbers to be sorted\n:return: Sorted list of numbers",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Implements the merge sort algorithm to sort a list of numbers.\n \"\"\"\n if len(arr) > 1:\n # Finding the middle of the array\n mid =... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048027",
"row_id": 48027,
"seed_ids": "['Qwen2.5-72B-Instruct_101121']"
} | 0.531892 | Filter_48027 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9c7235345d6a9369e03f55f4bad7a75be930b85 | 9acfa10b6b5dfd80f197302d52d9bc2b9024419a | |||
v1.0 | instruct | Filter | Filter_48057_I | Can you help me with a Python code that solves a Sudoku puzzle? I'm trying to create a function that can take a 9x9 grid with some numbers filled in and solve the puzzle, returning the completed grid. I've seen some examples, but I'm struggling to get it to work properly. Any advice or a sample implementation would be ... | def isValid(board, row, col, num):
"""
Check if it's valid to place a number at the specified position in the board.
"""
for i in range(9):
if board[row][i] == num:
return False
if board[i][col] == num:
return False
if board[row - row % 3 + i // 3][col - c... | from solution import solveSudoku
def test_sudoku_solver():
board = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 6, 0, 0, 0, ... | [
{
"docstring": "Check if it's valid to place a number at the specified position in the board.",
"function_declaration": "def isValid(board, row, col, num):",
"function_name": "isValid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": "Solves the given Sudoku board by filling in ... | [
1,
0,
1
] | 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 \"\"\"\n Check if `num` can be placed in `board[row][col]` without violating Sudoku rules.\n \"\"\"\n # Check if num is not in the current row... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048057",
"row_id": 48057,
"seed_ids": "['Qwen2.5-72B-Instruct_101178']"
} | 0.499345 | Filter_48057 | I | [
"isValid",
"solveSudoku"
] | 2 | [
[
"solveSudoku",
"isValid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9bf459310408fdbfca5c849b0dc32c7f4ccb9257 | 18f0c53bc7b1857b383f5e4c5d3d4fa12c058681 | |||
v1.0 | instruct | Filter | Filter_48065_I | How can I create a function in Python to read a JSON file and print out the values of a specific key? | import json
def print_values_of_key(json_file_path, key):
"""
Reads a JSON file and prints out the values of a specific key
Parameters:
- json_file_path (str): The path to the JSON file.
- key (str): The key whose values need to be printed.
"""
try:
with open(json_file_path, 'r... | import json
import pytest
from io import StringIO
from unittest.mock import patch
from solution import print_values_of_key
def test_print_values_of_key():
json_data = {
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": "10001"
},
"con... | [
{
"docstring": "Reads a JSON file and prints out the values of a specific key\n\nParameters:\n- json_file_path (str): The path to the JSON file.\n- key (str): The key whose values need to be printed.",
"function_declaration": "def print_values_of_key(json_file_path, key):",
"function_name": "print_value... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef print_values_from_json(file_path, key):\n \"\"\"\n Reads a JSON file and prints out the values of the specified key.\n \n :param file_path: Path to the JSON file... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00048065",
"row_id": 48065,
"seed_ids": "['Qwen2.5-72B-Instruct_101190']"
} | 0.617286 | Filter_48065 | I | [
"print_values_of_key",
"find_and_print_values"
] | 2 | [
[
"print_values_of_key",
"find_and_print_values"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f26fbdfd5e2c4e3c95cb40aa492ce9c4e76138f | 6da1ba6a3bc5b431c4e660780c7943ff9a4f9e03 | |||
v1.0 | instruct | Filter | Filter_48076_I | I have a list of items and I want to sort them based on a specific condition. The items are represented as strings and I want to sort them based on the sum of the numerical values of their characters (assuming 'a' is 1, 'b' is 2, ..., 'z' is 26). How can I achieve this in Python? | def char_to_value(c):
"""
Returns the numerical value of a character assuming 'a' is 1, 'b' is 2, ..., 'z' is 26.
"""
return ord(c) - ord('a') + 1
def sum_of_string_values(s):
"""
Returns the sum of the numerical values of characters in the given string.
"""
return sum(char_to_value(c) ... | from solution import sort_items_by_char_values
def test_sort_items_by_char_values():
assert sort_items_by_char_values(["abc", "a", "zz", "aa"]) == ["a", "aa", "abc", "zz"]
assert sort_items_by_char_values(["cba", "a", "b", "aaa"]) == ["a", "b", "aaa", "cba"]
assert sort_items_by_char_values(["bc", "ad", "z... | [
{
"docstring": "Returns the numerical value of a character assuming 'a' is 1, 'b' is 2, ..., 'z' is 26.",
"function_declaration": "def char_to_value(c):",
"function_name": "char_to_value",
"parameter_list": "(c)"
},
{
"docstring": "Returns the sum of the numerical values of characters in the... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def char_value_sum(s):\n \"\"\"\n Compute the sum of numerical values of characters in the string s\n assuming 'a' is 1, 'b' is 2, ..., 'z' is 26.\n \"\"\"\n return sum(ord(char... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048076",
"row_id": 48076,
"seed_ids": "['Qwen2.5-72B-Instruct_101214']"
} | 0.640577 | Filter_48076 | I | [
"char_to_value",
"sum_of_string_values",
"sort_items_by_char_values"
] | 3 | [
[
"sum_of_string_values",
"char_to_value"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b23ba08b2470bc304d9e7475f3fbdc59639335f7 | 44e36cc48e7fae4e8b07177d16fa63e9bb91d6cd | |||
v1.0 | instruct | Filter | Filter_48105_I | How can I create a function in Python that generates a random number between 1 and 100, and how can I use this function to generate 10 random numbers? | import random
def generate_random_number():
"""
Generates a random number between 1 and 100 (inclusive).
"""
return random.randint(1, 100)
def generate_multiple_random_numbers(count=10):
"""
Generates a list of 'count' random numbers between 1 and 100 (inclusive).
Default count is 10.
... | from solution import generate_random_number, generate_multiple_random_numbers
def test_generate_random_number():
random_number = generate_random_number()
assert 1 <= random_number <= 100
def test_generate_multiple_random_numbers_length():
random_numbers = generate_multiple_random_numbers()
assert len(... | [
{
"docstring": "Generates a random number between 1 and 100 (inclusive).",
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": "Generates a list of 'count' random numbers between 1 and 100 (inclusive).\n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_number():\n \"\"\"\n Generates a random number between 1 and 100.\n \"\"\"\n return random.randint(1, 100)\n\ndef generate_n_random_numbers(n):... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00048105",
"row_id": 48105,
"seed_ids": "['Qwen2.5-72B-Instruct_101269']"
} | 0.587103 | Filter_48105 | I | [
"generate_random_number",
"generate_multiple_random_numbers"
] | 2 | [
[
"generate_multiple_random_numbers",
"generate_random_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c3506f794f1914ebbbdeeb01a63df139cfd2145 | 458093cc0325a2cfd8ed11b874ec6eeabd3856f4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.