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_54424_I | I am trying to develop a simple web application using Flask, a micro web framework in Python. I want to add a feature where users can upload images, and the application will display a thumbnail of the uploaded image. How can I achieve this? Can you provide a step-by-step guide or some code snippets to help me get start... | from flask import Flask, request, redirect, url_for, send_from_directory, render_template
from werkzeug.utils import secure_filename
from PIL import Image
import os
app = Flask(__name__)
# Configurations
UPLOAD_FOLDER = 'uploads/'
THUMBNAIL_SIZE = (128, 128)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Ensure the u... | 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()
yield client
def test_upload_file(client):
# Create a test image
image = Image.new('RGB', (100, 100), color = (73, 109... | [
{
"docstring": null,
"function_declaration": "def upload_file():",
"function_name": "upload_file",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def generate_thumbnail(image_path):",
"function_name": "generate_thumbnail",
"parameter_list": "(image_path)"... | [
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, redirect, url_for, send_from_directory, render_template\nfrom werkzeug.utils import secure_filename\nfrom PIL import Image\nimport os\n\napp = Flask(__name__)... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00054424",
"row_id": 54424,
"seed_ids": "['Qwen2.5-72B-Instruct_111482']"
} | 0.397892 | Filter_54424 | I | [
"upload_file",
"generate_thumbnail",
"uploaded_file"
] | 3 | [
[
"upload_file",
"generate_thumbnail"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL",
"flask",
"werkzeug"
] | false | 521fe1a659fc3adf29e6b41b59977a8ccea082e4 | b65e85bc77eee40ca89edfd19390b785cdf270a7 | |||
v1.0 | instruct | Filter | Filter_54442_I | Can you help me with a Python code that simulates the flipping of a coin 100 times and counts how many times each side comes up? I want to see the results printed out. | import random
def flip_coin(times):
"""
Simulates flipping a coin 'times' number of times.
:param times: The number of times to flip the coin.
:return: A dictionary with the counts of 'Heads' and 'Tails'.
"""
results = {'Heads': 0, 'Tails': 0}
for _ in range(times):
if random.c... | from solution import flip_coin
def test_flip_coin_total_flips():
results = flip_coin(100)
assert results['Heads'] + results['Tails'] == 100
def test_flip_coin_non_negative_counts():
results = flip_coin(100)
assert results['Heads'] >= 0
assert results['Tails'] >= 0
def test_flip_coin_edge_case_0_f... | [
{
"docstring": "Simulates flipping a coin 'times' number of times.\n\n:param times: The number of times to flip the coin.\n:return: A dictionary with the counts of 'Heads' and 'Tails'.",
"function_declaration": "def flip_coin(times):",
"function_name": "flip_coin",
"parameter_list": "(times)"
},
... | [
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 flip_coin(num_flips=100):\n \"\"\"\n Simulates flipping a coin `num_flips` times and counts the occurrences of heads and tails.\n\n Args:\n num_flips (int): Th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054442",
"row_id": 54442,
"seed_ids": "['Qwen2.5-72B-Instruct_111506']"
} | 0.454133 | Filter_54442 | I | [
"flip_coin",
"simulate_flips_and_print"
] | 2 | [
[
"simulate_flips_and_print",
"flip_coin"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e52536721ec7ee05e83b399b73f7cbc5cdfd4b8d | 35d729f7854bd70181024d11c786154009492bf9 | |||
v1.0 | instruct | Filter | Filter_54452_I | Design a Python script that reads a list of numbers from a text file, calculates the median, and writes the result back to another text file. Ensure your script handles potential errors such as non-numeric values and missing files gracefully. | import os
def calculate_median(numbers):
"""
Calculate and return the median of a list of numbers.
"""
sorted_numbers = sorted(numbers)
n = len(sorted_numbers)
if n == 0:
raise ValueError("The list is empty, cannot calculate median.")
mid = n // 2
if n % 2 == 0:
ret... | import os
import pytest
from solution import calculate_median, read_numbers_from_file, write_median_to_file, process_median
def test_calculate_median_odd():
assert calculate_median([1, 3, 2]) == 2
def test_calculate_median_even():
assert calculate_median([1, 2, 3, 4]) == 2.5
def test_calculate_median_single(... | [
{
"docstring": "Calculate and return the median of a list of numbers.",
"function_declaration": "def calculate_median(numbers):",
"function_name": "calculate_median",
"parameter_list": "(numbers)"
},
{
"docstring": "Reads a list of numbers from a given text file.\nReturns a list of numbers. ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import statistics\n\ndef read_numbers_from_file(file_path):\n with open(file_path, 'r') as file:\n lines = file.readlines()\n numbers = []\n for line in lines:\n try:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054452",
"row_id": 54452,
"seed_ids": "['Qwen2.5-72B-Instruct_111521']"
} | 0.74669 | Filter_54452 | I | [
"calculate_median",
"read_numbers_from_file",
"write_median_to_file",
"process_median"
] | 4 | [
[
"process_median",
"calculate_median"
],
[
"process_median",
"read_numbers_from_file"
],
[
"process_median",
"write_median_to_file"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 151a0772ab2a64a5527a038ca3e0de83b0c6d661 | 2b975f6d7b5e5f4e7d04f3aba9e27cba1a0548f7 | |||
v1.0 | instruct | Filter | Filter_54484_I | I need to understand how to use the Python `map()` function with a list of tuples. Can you provide an example where `map()` is used to manipulate a list of tuples, perhaps by applying a function to each element within the tuples? | def double_elements(tup):
"""
Returns a tuple with each element doubled.
"""
return (tup[0] * 2, tup[1] * 2)
def double_elements_in_list_of_tuples(lst):
"""
Applies the double_elements function to each tuple in the list using map.
"""
return list(map(double_elements, lst))
# Example us... | from solution import double_elements, double_elements_in_list_of_tuples
def test_double_elements():
assert double_elements((1, 2)) == (2, 4)
assert double_elements((0, -1)) == (0, -2)
def test_double_elements_in_list_of_tuples():
assert double_elements_in_list_of_tuples([(1, 2), (3, 4), (5, 6)]) == [(2, 4... | [
{
"docstring": "Returns a tuple with each element doubled.",
"function_declaration": "def double_elements(tup):",
"function_name": "double_elements",
"parameter_list": "(tup)"
},
{
"docstring": "Applies the double_elements function to each tuple in the list using map.",
"function_declara... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def manipulate_tuples(tuples_list, func):\n \"\"\"\n Applies a given function to each element within the tuples in the list.\n\n Args:\n tuples_list (list of tuples): The list of t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054484",
"row_id": 54484,
"seed_ids": "['Qwen2.5-72B-Instruct_111565']"
} | 0.516913 | Filter_54484 | I | [
"double_elements",
"double_elements_in_list_of_tuples"
] | 2 | [
[
"double_elements_in_list_of_tuples",
"double_elements"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dfb2beeacc940f87814f87d502aa6f8500b750df | a724c07981803dde048a3ce82f19eeb85812cd30 | |||
v1.0 | instruct | Filter | Filter_54506_I | Design a Python script that reads a list of FTP server connections (including server IP, username, and password) from a configuration file, connects to each server, and checks if a specified directory exists. If the directory does not exist, the script should create it. The script should log its actions, including any ... | import ftplib
import configparser
import logging
# Initialize logging
logging.basicConfig(filename='ftp_directory_check.log', level=logging.INFO)
def read_config(config_file):
config = configparser.ConfigParser()
config.read(config_file)
return config
def check_and_create_directory(ftp_conn, directory):
... | import pytest
from unittest.mock import patch, MagicMock
from solution import process_ftp_servers, read_config, check_and_create_directory
def test_read_config():
config_content = """
[server1]
server_ip = 127.0.0.1
username = user
password = pass
[server2]
server_ip = 192.168.1.1
user... | [
{
"docstring": null,
"function_declaration": "def read_config(config_file):",
"function_name": "read_config",
"parameter_list": "(config_file)"
},
{
"docstring": null,
"function_declaration": "def check_and_create_directory(ftp_conn, directory):",
"function_name": "check_and_create_d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport ftplib\nimport logging\nimport configparser\n\ndef connect_and_check_directory(server_ip, username, password, directory):\n \"\"\"\n Connects to the FTP server and ensu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054506",
"row_id": 54506,
"seed_ids": "['Qwen2.5-72B-Instruct_111601']"
} | 0.655425 | Filter_54506 | I | [
"read_config",
"check_and_create_directory",
"process_ftp_servers"
] | 3 | [
[
"process_ftp_servers",
"check_and_create_directory"
],
[
"process_ftp_servers",
"read_config"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 482ccd0c75571231d6357516cd40856496cb5c22 | f693176ba7408673980c3728151730b2a33d9302 | |||
v1.0 | instruct | Filter | Filter_54525_I | Write a Python script that takes a list of names as input and creates a greeting message for each name in the list. The greeting message should be in the format "Hello, [name]!". The script should then print all the greeting messages. | def generate_greetings(names):
"""
Takes a list of names and generates a greeting message for each name.
:param names: List of names.
:return: List of greeting messages.
"""
greetings = []
for name in names:
greeting = f"Hello, {name}!"
greetings.append(greeting)
ret... | from solution import generate_greetings, print_greetings
def test_generate_greetings():
assert generate_greetings(["Alice", "Bob", "Charlie"]) == [
"Hello, Alice!",
"Hello, Bob!",
"Hello, Charlie!"
]
assert generate_greetings([]) == []
assert generate_greetings(["Daisy"]) == ["H... | [
{
"docstring": "Takes a list of names and generates a greeting message for each name.\n\n:param names: List of names.\n:return: List of greeting messages.",
"function_declaration": "def generate_greetings(names):",
"function_name": "generate_greetings",
"parameter_list": "(names)"
},
{
"docs... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_greetings(names):\n \"\"\"\n Takes a list of names and returns a list of greeting messages for each name.\n \"\"\"\n greetings = [f\"Hello, {name}!\" for name in names... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054525",
"row_id": 54525,
"seed_ids": "['Qwen2.5-72B-Instruct_111629']"
} | 0.425564 | Filter_54525 | I | [
"generate_greetings",
"print_greetings"
] | 2 | [
[
"print_greetings",
"generate_greetings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84275a6fa112a6258d212d41dcc6d745dc6e5526 | babbd133ad119a54a74a09a9ef1afea3f470e5d0 | |||
v1.0 | instruct | Filter | Filter_54528_I | I need to create a Python function that checks if a given integer is a prime number. The function should return `True` if the number is prime and `False` otherwise. Additionally, I would like to use this function to filter a list of integers to return only the prime numbers. How can I accomplish this? | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(97) == True
assert is_prime(100) == Fal... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the input list.",
"function_declaration": "def filter_primes(nu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else returns False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054528",
"row_id": 54528,
"seed_ids": "['Qwen2.5-72B-Instruct_111633']"
} | 0.735889 | Filter_54528 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fd8bedd22bb89a798fd9dc890518f8f30e764ecd | 9c48190eb52b19bb4e568d75bb8e73daf9345f08 | |||
v1.0 | instruct | Filter | Filter_54529_I | Write a Python program to find all the prime numbers from 1 to 1000 and output them in a formatted list. The program should also calculate and print the total number of prime numbers found within this range. Additionally, the program should execute in a time-efficient manner. Optimize the algorithm to the best of your ... | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def find... | from solution import is_prime, find_primes_up_to_1000
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(1000) == False
def test_find_primes_up_to_1000():
primes_list, total_primes = find_primes_up_... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers from 1 to 1000 and return them in a list along with the count.",
"function_declaration": "def find_prim... | [
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 n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054529",
"row_id": 54529,
"seed_ids": "['Qwen2.5-72B-Instruct_111637']"
} | 0.651833 | Filter_54529 | I | [
"is_prime",
"find_primes_up_to_1000"
] | 2 | [
[
"find_primes_up_to_1000",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a865b4ba4717bef172e01facdf432530edfbb6cf | b0374f75c5fe9be3da6e4990d2d653c6224e5264 | |||
v1.0 | instruct | Filter | Filter_54531_I | How can I design a simple automated email responder using Python that sends a standard reply to all incoming emails? Can you provide a basic script to get started? | import imaplib
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
IMAP_SERVER = 'imap.gmail.com'
SMTP_SERVER = 'smtp.gmail.com'
EMAIL = 'your-email@gmail.com'
PASSWORD = 'your-email-password'
def check_email():
"""
Check for new emails.
"""
mail = imapli... | import pytest
from unittest.mock import patch, MagicMock
from solution import check_email, send_reply, auto_respond
@patch('imaplib.IMAP4_SSL')
def test_check_email(mock_imap):
mock_mail = MagicMock()
mock_mail.search.return_value = ('OK', [b'1 2 3'])
mock_imap.return_value = mock_mail
email_ids = che... | [
{
"docstring": "Check for new emails.",
"function_declaration": "def check_email():",
"function_name": "check_email",
"parameter_list": "()"
},
{
"docstring": "Send an automatic reply to an email.",
"function_declaration": "def send_reply(to_email, subject, body):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import imaplib\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nimport email\n\ndef simple_email_responder(imap_server, email_user, email_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054531",
"row_id": 54531,
"seed_ids": "['Qwen2.5-72B-Instruct_111646']"
} | 0.57779 | Filter_54531 | I | [
"check_email",
"send_reply",
"auto_respond"
] | 3 | [
[
"auto_respond",
"check_email"
],
[
"auto_respond",
"send_reply"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ef69a4c53fafe0bf02541ae0a2128ac49f623461 | 9cd150323493053fd47e25c8e05b519a57ae2822 | |||
v1.0 | instruct | Filter | Filter_54534_I | Write a function that checks whether a number is even or odd and then use this function to filter out all odd numbers from a given list of integers. The function should return a new list containing only the even numbers. Make sure the code is self-contained, with all necessary imports included. Additionally, include a ... | def is_even(number):
"""
Check if a number is even.
"""
return number % 2 == 0
def filter_even_numbers(numbers):
"""
Filter out all odd numbers from a given list of integers and return a list of even numbers.
"""
return [num for num in numbers if is_even(num)]
def check_solution():
... | from solution import is_even, filter_even_numbers
def test_is_even():
assert is_even(4) == True
assert is_even(3) == False
assert is_even(0) == True
assert is_even(-2) == True
assert is_even(-1) == False
def test_filter_even_numbers_mixed_list():
assert filter_even_numbers([1, 2, 3, 4, 5, 6]) ... | [
{
"docstring": "Check if a number is even.",
"function_declaration": "def is_even(number):",
"function_name": "is_even",
"parameter_list": "(number)"
},
{
"docstring": "Filter out all odd numbers from a given list of integers and return a list of even numbers.",
"function_declaration": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(number):\n \"\"\"\n Returns True if the number is even, False otherwise.\n \"\"\"\n return number % 2 == 0\n\ndef filter_even_numbers(numbers):\n \"\"\"\n Filters... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054534",
"row_id": 54534,
"seed_ids": "['Qwen2.5-72B-Instruct_111649']"
} | 0.756826 | Filter_54534 | I | [
"is_even",
"filter_even_numbers",
"check_solution"
] | 3 | [
[
"check_solution",
"filter_even_numbers"
],
[
"filter_even_numbers",
"is_even"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f128f4575d8d4f1a4f0f4c79acdbd336208c61ff | bf0f66c67cd9b65775740e34ec17a2e7570f39fd | |||
v1.0 | instruct | Filter | Filter_54588_I | Write a function in Python to simulate a game where a player rolls two 6-sided dice. If the sum is 7 or 11, the player wins. If the sum is 2, 3, or 12, the player loses. If the sum is any other number, the player continues to roll until they match the initial sum to win or roll a 7 to lose. The function should return t... | import random
def roll_dice():
"""
Simulates rolling two 6-sided dice and returns their sum.
"""
return random.randint(1, 6) + random.randint(1, 6)
def play_game():
"""
Simulates a game where a player rolls two 6-sided dice.
The player wins if the sum of the first roll is 7 or 11.
... | import pytest
from solution import roll_dice, play_game
# Since the solution uses random, we cannot directly test it without fixing the seed.
# We will mock roll_dice to provide predictable results for our tests.
def test_initial_win():
# Simulates roll_dice returning 7 on the first roll.
with pytest.MonkeyPa... | [
{
"docstring": "Simulates rolling two 6-sided dice and returns their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a game where a player rolls two 6-sided dice.\n\nThe player wins if the sum of the first r... | [
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 roll_dice():\n \"\"\"\n Simulates rolling two 6-sided dice and returns the sum.\n \"\"\"\n return random.randint(1, 6) + random.randint(1, 6)\n\ndef dice_game(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054588",
"row_id": 54588,
"seed_ids": "['Qwen2.5-72B-Instruct_111730']"
} | 0.555432 | Filter_54588 | I | [
"roll_dice",
"play_game"
] | 2 | [
[
"play_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 300ea5efd161d30a06bf052761e877b047ce8f97 | 33d771c1670a652b318b2914440f2e0987db7051 | |||
v1.0 | instruct | Filter | Filter_54592_I | Design a simple calculator application in Python that can perform addition, subtraction, multiplication, and division. Include a user interface that allows the user to input two numbers and select an operation. The application should then display the result of the operation. Ensure that the application handles division... | def add(a, b):
"""
Returns the sum of a and b.
"""
return a + b
def subtract(a, b):
"""
Returns the difference of a and b.
"""
return a - b
def multiply(a, b):
"""
Returns the product of a and b.
"""
return a * b
def divide(a, b):
"""
Returns the quotient of a ... | from solution import add, subtract, multiply, divide, calculator
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(0, 5) == -5
def test_multiply():
assert multiply(4, 3) == 12
assert multiply(0, 5) == 0
def test_divid... | [
{
"docstring": "Returns the sum of a and b.",
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the difference of a and b.",
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"paramete... | [
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 \"Cannot divide by zero\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054592",
"row_id": 54592,
"seed_ids": "['Qwen2.5-72B-Instruct_111736']"
} | 0.594897 | Filter_54592 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | eed4222e7848cc48a0269aa3da99b3870fd5602a | 47c7c304a3882556759ee35617af26f9c8e2f821 | |||
v1.0 | instruct | Filter | Filter_54604_I | I'm trying to optimize a specific function in Python using gradient descent. The function I'm working with is defined as \( f(x) = (x-2)^2 + 1 \). I need to find the value of \( x \) that minimizes this function. Can you guide me through the process of implementing this in Python, from defining the function, calculatin... | def function_to_minimize(x):
"""
Returns the value of the function f(x) = (x - 2)^2 + 1 at a given x.
"""
return (x - 2) ** 2 + 1
def derivative_function(x):
"""
Returns the derivative of the function f(x) = (x - 2)^2 + 1 at a given x.
"""
return 2 * (x - 2)
def gradient_descent(starti... | from solution import function_to_minimize, derivative_function, gradient_descent
def test_function_to_minimize():
assert function_to_minimize(2) == 1
assert function_to_minimize(1) == 2
assert function_to_minimize(3) == 2
def test_derivative_function():
assert derivative_function(2) == 0
assert de... | [
{
"docstring": "Returns the value of the function f(x) = (x - 2)^2 + 1 at a given x.",
"function_declaration": "def function_to_minimize(x):",
"function_name": "function_to_minimize",
"parameter_list": "(x)"
},
{
"docstring": "Returns the derivative of the function f(x) = (x - 2)^2 + 1 at a ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def f(x):\n \"\"\"\n Function to minimize: f(x) = (x-2)^2 + 1\n \"\"\"\n return (x - 2) ** 2 + 1\n\ndef df(x):\n \"\"\"\n Derivative of the function: df(x) = 2*(x-2)\n \"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054604",
"row_id": 54604,
"seed_ids": "['Qwen2.5-72B-Instruct_111758']"
} | 0.465163 | Filter_54604 | I | [
"function_to_minimize",
"derivative_function",
"gradient_descent"
] | 3 | [
[
"gradient_descent",
"derivative_function"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61d6f09e2312c653a42b436382c6da1b24b6fc54 | 1af8fb4a2efd6fc193a4140f4ae3e32d3f359e97 | |||
v1.0 | instruct | Filter | Filter_54628_I | Design a Python function that simulates a stochastic process for generating sequences of event times over a fixed interval, using a time-varying intensity function. The intensity function should be defined as the absolute value of a cubic polynomial: \(|\lambda(t)| = |a + bt + ct^3|\), where \(a\), \(b\), and \(c\) are... | import numpy as np
import matplotlib.pyplot as plt
def intensity_function(t, a, b, c):
"""
Computes the intensity function lambda(t) = |a + bt + ct^3|.
"""
return abs(a + b*t + c*t**3)
def simulate_poisson_process(a, b, c, T, max_intensity, rng=None):
"""
Simulates a Poisson process using the ... | from solution import simulate_poisson_process, intensity_function, plot_event_times
import numpy as np
def test_intensity_function():
assert intensity_function(0, 1, 1, 1) == 1
assert intensity_function(1, 1, 1, 1) == abs(1 + 1*1 + 1*1**3)
assert intensity_function(-1, 1, 1, 1) == abs(1 - 1 + 1*(-1)**3)
d... | [
{
"docstring": "Computes the intensity function lambda(t) = |a + bt + ct^3|.",
"function_declaration": "def intensity_function(t, a, b, c):",
"function_name": "intensity_function",
"parameter_list": "(t, a, b, c)"
},
{
"docstring": "Simulates a Poisson process using the thinning algorithm.\n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef simulate_events(a, b, c, T, dt=0.01):\n \"\"\"\n Simulates a stochastic process with a time-varying intensity function.\n \n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054628",
"row_id": 54628,
"seed_ids": "['Qwen2.5-72B-Instruct_111810']"
} | 0.587965 | Filter_54628 | I | [
"intensity_function",
"simulate_poisson_process",
"plot_event_times"
] | 3 | [
[
"simulate_poisson_process",
"intensity_function"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy"
] | false | 8bb4c002fcb52507b55a0add772c0bc3dbe442b4 | 9eb5e8e772d8a37c65a2d26450a04e26214e706b | |||
v1.0 | instruct | Filter | Filter_54643_I | I need to create a script that can monitor a website for changes and send an email notification when a change is detected. Can you help me with the basic structure of the script? I would prefer it in Python. | import requests
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from difflib import Differ
def fetch_website_content(url):
"""
Fetches the content of the website at the given URL.
"""
response = requests.get(url)
response.raise_for_status()
ret... | from solution import fetch_website_content, detect_changes, send_email_notification, monitor_website
import pytest
from unittest.mock import Mock, patch
def test_fetch_website_content():
with patch('requests.get') as mock_get:
mock_get.return_value.text = "test content"
assert fetch_website_content... | [
{
"docstring": "Fetches the content of the website at the given URL.",
"function_declaration": "def fetch_website_content(url):",
"function_name": "fetch_website_content",
"parameter_list": "(url)"
},
{
"docstring": "Detects changes between two pieces of content.",
"function_declaration"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport hashlib\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nfrom time import sleep\n\ndef get_website_content(url):\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054643",
"row_id": 54643,
"seed_ids": "['Qwen2.5-72B-Instruct_111835']"
} | 0.402614 | Filter_54643 | I | [
"fetch_website_content",
"detect_changes",
"send_email_notification",
"monitor_website"
] | 4 | [
[
"monitor_website",
"detect_changes"
],
[
"monitor_website",
"fetch_website_content"
],
[
"monitor_website",
"send_email_notification"
]
] | 3 | [] | false | [] | false | pytest | true | [
"requests"
] | false | feb5a5a93cf8f89554cd18580123d0def725fc81 | eef85b0d3dc5eb7e2996653ed74cb6301b4fd25d | |||
v1.0 | instruct | Filter | Filter_54646_I | Can you help me design a simple AI chatbot for my website using Python and Flask? I want it to greet users, answer some basic questions about my business, and direct them to relevant pages. | from flask import Flask, request, jsonify
app = Flask(__name__)
# Define the responses
greetings = ["Hi", "Hello", "Hey"]
business_questions = {
"What do you do?": "We provide the best products and services for our customers.",
"Where are you located?": "Our main office is located in New York City.",
"Wha... | import pytest
from solution import get_response
def test_greeting():
assert get_response("Hi") == "Hello! How can I help you today?"
assert get_response("hello") == "Hello! How can I help you today?"
assert get_response("Hey") == "Hello! How can I help you today?"
def test_business_questions():
assert... | [
{
"docstring": null,
"function_declaration": "def get_response(message):",
"function_name": "get_response",
"parameter_list": "(message)"
},
{
"docstring": null,
"function_declaration": "def chatbot():",
"function_name": "chatbot",
"parameter_list": "()"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n@app.route('/chatbot', methods=['POST'])\ndef chatbot():\n user_message = request.json.get(\"message\")\n response =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054646",
"row_id": 54646,
"seed_ids": "['Qwen2.5-72B-Instruct_111844']"
} | 0.337733 | Filter_54646 | I | [
"get_response",
"chatbot"
] | 2 | [
[
"chatbot",
"get_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 83e6329e383e1407222331d5195f7b769dd93986 | 28564cbef4223cf6402386d2dc94f2f3bdfaa470 | |||
v1.0 | instruct | Filter | Filter_54648_I | Given a list of hotel reviews, write a Python function to categorize them into positive, negative, and neutral sentiments. Assume the function `is_positive(review: str) -> bool` is already implemented and works as expected, returning `True` if the sentiment of the review is positive. Use this function to categorize the... | def categorize_reviews(reviews):
"""
Categorizes a list of reviews into positive, negative, and neutral.
:param reviews: List of hotel reviews
:return: Dictionary with keys 'positive', 'negative', 'neutral' and corresponding lists of reviews
"""
categorized_reviews = {'positive': [], 'negative'... | from solution import categorize_reviews
def test_all_positive():
reviews = ["This hotel is amazing!", "We had a wonderful stay.", "Excellent service!"]
categorized = categorize_reviews(reviews)
assert len(categorized['positive']) == 3
assert len(categorized['negative']) == 0
assert len(categorized[... | [
{
"docstring": "Categorizes a list of reviews into positive, negative, and neutral.\n\n:param reviews: List of hotel reviews\n:return: Dictionary with keys 'positive', 'negative', 'neutral' and corresponding lists of reviews",
"function_declaration": "def categorize_reviews(reviews):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def categorize_reviews(reviews):\n \"\"\"\n Categorizes reviews into positive, negative, and neutral based on their sentiment.\n \n Args:\n reviews (list of str): List of hotel ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054648",
"row_id": 54648,
"seed_ids": "['Qwen2.5-72B-Instruct_111848']"
} | 0.639135 | Filter_54648 | I | [
"categorize_reviews",
"is_positive",
"is_negative"
] | 3 | [
[
"categorize_reviews",
"is_negative"
],
[
"categorize_reviews",
"is_positive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3d478b0b62459cfaeaa29ce4d74095725966f47c | 369dbbdac87863e6d71e3897c0d77d46fc81765e | |||
v1.0 | instruct | Filter | Filter_54660_I | I am facing a challenge at work where I need to automate the process of generating personalized emails for a large list of clients. Each client has specific details that need to be included in the email, such as their name, account number, and a brief summary of their recent transactions. How can I automate this using ... | import pandas as pd
from string import Template
def generate_email(template_str, client_info):
"""
Generates a personalized email for a client using the provided template and client information.
Parameters:
template_str (str): The email template in string format.
client_info (dict): A dictiona... | import pytest
import pandas as pd
from solution import generate_email, generate_emails_for_clients
def test_generate_email():
template_str = "Hello, $name!\nYour account number is $account_number.\nHere is your summary: $summary"
client_info = {
"name": "John Doe",
"account_number": "12345678",... | [
{
"docstring": "Generates a personalized email for a client using the provided template and client information.\n\nParameters:\ntemplate_str (str): The email template in string format.\nclient_info (dict): A dictionary containing the client's details.\n\nReturns:\nstr: The personalized email.",
"function_de... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_personalized_email(client_info):\n \"\"\"\n Generates a personalized email for a client based on their information.\n \n Parameters:\n client_info (dict): A dic... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054660",
"row_id": 54660,
"seed_ids": "['Qwen2.5-72B-Instruct_111870']"
} | 0.49895 | Filter_54660 | I | [
"generate_email",
"generate_emails_for_clients"
] | 2 | [
[
"generate_emails_for_clients",
"generate_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"pandas"
] | false | b0e65cca1d6fa11da5661ba1a0d7601d21d22484 | d17e0e8eeef13f122fefa13db2038aec01388eac | |||
v1.0 | instruct | Filter | Filter_54667_I | Write a Python program that finds the nth Fibonacci number using an iterative approach. The program should be efficient and easy to understand. Also, include a function to test if the program is working correctly with the first 10 Fibonacci numbers. | def fibonacci(n):
"""
Returns the nth Fibonacci number using an iterative approach.
"""
if n <= 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for _ in range(2, n+1):
a, b = b, a + b
return b
def test_fibonacci():
"""
Checks the first 10 Fibonacci num... | from solution import fibonacci, test_fibonacci
def test_fibonacci_implementation():
test_fibonacci()
def test_fibonacci_specific_cases():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
... | [
{
"docstring": "Returns the nth Fibonacci number using an iterative approach.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Checks the first 10 Fibonacci numbers to verify the implementation.",
"function_declaratio... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def nth_fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number using an iterative approach.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n should be a positive integer\")\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054667",
"row_id": 54667,
"seed_ids": "['Qwen2.5-72B-Instruct_111880']"
} | 0.745891 | Filter_54667 | I | [
"fibonacci",
"test_fibonacci"
] | 2 | [
[
"test_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6952b1314848e5022d529cfe354d1ef57f0e7027 | 726cd72903788a3cf6553408ff34d2065f08201b | |||
v1.0 | instruct | Filter | Filter_54677_I | Can you assist me in creating a Python script that uses the SciPy library for interpolating from a 2D grid to an unstructured 3D point cloud? The script should be able to handle 3D coordinates (x, y, z) and their associated values (Bx, By, Bz) and interpolate these values onto a set of unstructured 3D points. The outpu... | import numpy as np
from scipy.interpolate import RegularGridInterpolator
def interpolate_3d_to_unstructured(grid_x, grid_y, grid_z, values_Bx, values_By, values_Bz, points):
"""
Interpolates given 3D grid data onto unstructured 3D points.
Parameters:
grid_x, grid_y, grid_z: 1D arrays representing the... | import numpy as np
from solution import interpolate_3d_to_unstructured, verify_interpolation
def test_interpolate_3d_to_unstructured():
grid_x = np.array([0, 1, 2])
grid_y = np.array([0, 1, 2])
grid_z = np.array([0, 1, 2])
values_Bx = np.array([
[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[10,... | [
{
"docstring": "Interpolates given 3D grid data onto unstructured 3D points. \n\nParameters:\ngrid_x, grid_y, grid_z: 1D arrays representing the coordinates of the 3D grid.\nvalues_Bx, values_By, values_Bz: 3D arrays representing the values at each point of the grid.\npoints: 2D array of shape (N, 3) representi... | [
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 scipy.interpolate import griddata\n\ndef interpolate_3d_grid_to_points(grid_x, grid_y, grid_z, values, points):\n \"\"\"\n Interpolates values from a 2D grid to ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054677",
"row_id": 54677,
"seed_ids": "['Qwen2.5-72B-Instruct_111895']"
} | 0.458551 | Filter_54677 | I | [
"interpolate_3d_to_unstructured",
"verify_interpolation"
] | 2 | [
[
"verify_interpolation",
"interpolate_3d_to_unstructured"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 9c1438ea017d81491c38b4370ecc51d7d3789fbc | d368c2ddf9ca784b3a60524f16925f94607c7a56 | |||
v1.0 | instruct | Filter | Filter_54679_I | How can I create a basic Python script to monitor CPU usage on a Linux system and alert via email when usage exceeds a certain threshold? | import psutil
import smtplib
from email.mime.text import MIMEText
def monitor_cpu(threshold, recipient_email, sender_email, sender_password, smtp_server, smtp_port):
"""
Monitors the CPU usage and sends an alert email if usage exceeds the threshold.
Args:
- threshold: CPU usage percentage threshold to ... | import psutil
from unittest.mock import patch
from solution import monitor_cpu, send_email
def test_monitor_cpu_threshold_exceeded():
with patch("psutil.cpu_percent", return_value=90), \
patch("solution.send_email") as mock_send_email:
monitor_cpu(80, "recipient@example.com", "sender@example.com"... | [
{
"docstring": "Monitors the CPU usage and sends an alert email if usage exceeds the threshold.\nArgs:\n- threshold: CPU usage percentage threshold to trigger the alert.\n- recipient_email: Email address to send the alert to.\n- sender_email: Email address to send the alert from.\n- sender_password: Password fo... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport psutil\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email_alert(subject, body, to_email, from_email, smtp_server, sm... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054679",
"row_id": 54679,
"seed_ids": "['Qwen2.5-72B-Instruct_111902']"
} | 0.644981 | Filter_54679 | I | [
"monitor_cpu",
"send_email"
] | 2 | [
[
"monitor_cpu",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | ba992d78d28bfc83b808e1903fd00c513df540eb | e9a3681f5f3a8c7aa2ed0e621875937eec54051d | |||
v1.0 | instruct | Filter | Filter_54681_I | How can I efficiently solve a system of nonlinear equations using Python? Specifically, I'm dealing with equations that are quadratic in nature. Can you provide a basic example? | from scipy.optimize import fsolve
def equations(vars):
x, y = vars
eq1 = x**2 + y**2 - 4
eq2 = x**2 - y - 1
return [eq1, eq2]
def solve_nonlinear_system():
initial_guess = [1, 1] # Initial guess for x and y
solution = fsolve(equations, initial_guess)
return solution | from solution import solve_nonlinear_system
def test_solve_nonlinear_system():
solution = solve_nonlinear_system()
x, y = solution
# Check that the solution satisfies the equations
assert abs(x**2 + y**2 - 4) < 1e-6, f"Expected the equation to be nearly zero, but got {x**2 + y**2 - 4}"
assert ... | [
{
"docstring": null,
"function_declaration": "def equations(vars):",
"function_name": "equations",
"parameter_list": "(vars)"
},
{
"docstring": null,
"function_declaration": "def solve_nonlinear_system():",
"function_name": "solve_nonlinear_system",
"parameter_list": "()"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy.optimize import fsolve\n\ndef equations(vars):\n \"\"\"\n Defines a system of equations to solve.\n For example, solving the system:\n x^2 + y^2 - 4 = 0\n x^2 - y^2 -... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054681",
"row_id": 54681,
"seed_ids": "['Qwen2.5-72B-Instruct_111905']"
} | 0.401805 | Filter_54681 | I | [
"equations",
"solve_nonlinear_system"
] | 2 | [
[
"solve_nonlinear_system",
"equations"
]
] | 1 | [] | false | [] | false | pytest | true | [
"scipy"
] | false | 4b9c1101fe4e2fd49c37e5d06586fbc7f53baac5 | 98534d434f4965e9b60f053bcaad9d3bca766bf4 | |||
v1.0 | instruct | Filter | Filter_54684_I | Write a program in Python that can find the sum of all prime numbers up to a given number n. The user should be able to input n, and the program should output the sum of all prime numbers less than or equal to n. Make sure to include comments in your code to explain key parts of your program. | def is_prime(num):
"""
Returns True if the given number is a prime number, otherwise False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
... | 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(5) == True
assert is_prime(0) == False
assert is_prime(1) == False
def test_sum_of_primes():
assert sum_of_primes(10) == 17 #... | [
{
"docstring": "Returns True if the given number is a prime number, otherwise False.",
"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_declara... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is a prime.\n Returns True if the number is prime, False otherwise.\n \"\"\"\n if num <= 1:\n return Fa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054684",
"row_id": 54684,
"seed_ids": "['Qwen2.5-72B-Instruct_111908']"
} | 0.613562 | Filter_54684 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5f8f4037ffc818b08eb8a0a644ad25989c1252f0 | 4e05332941702482ee9963046f9c5d7abdb49ef4 | |||
v1.0 | instruct | Filter | Filter_54712_I | How do I create a basic Alexa skill using Python? | import json
def lambda_handler(event, context):
if event['request']['type'] == "LaunchRequest":
return on_launch(event)
elif event['request']['type'] == "IntentRequest":
return on_intent(event)
else:
return handle_error()
def on_launch(event):
return build_response("Welcome to ... | import json
from solution import lambda_handler
def test_launch_request():
event = {
'request': {
'type': "LaunchRequest"
}
}
response = lambda_handler(event, None)
assert response['response']['outputSpeech']['text'] == "Welcome to my test skill. How can I help you today?"
... | [
{
"docstring": null,
"function_declaration": "def lambda_handler(event, context):",
"function_name": "lambda_handler",
"parameter_list": "(event, context)"
},
{
"docstring": null,
"function_declaration": "def on_launch(event):",
"function_name": "on_launch",
"parameter_list": "(e... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# Building a Basic Alexa Skill using the Python programming language\n\n# To build a basic Alexa skill using Python, you generally need to follow these steps:\n# 1. Set up an AWS Lambda functi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054712",
"row_id": 54712,
"seed_ids": "['Qwen2.5-72B-Instruct_111966']"
} | 0.322566 | Filter_54712 | I | [
"lambda_handler",
"on_launch",
"on_intent",
"build_response",
"handle_error"
] | 5 | [
[
"handle_error",
"build_response"
],
[
"lambda_handler",
"handle_error"
],
[
"lambda_handler",
"on_intent"
],
[
"lambda_handler",
"on_launch"
],
[
"on_intent",
"build_response"
],
[
"on_launch",
"build_response"
]
] | 6 | [] | false | [] | false | pytest | true | [] | true | 8851fe034c43e9759356c4d400ac237a9614f7ed | 2f695e2ead4e060be2e406641803e50d67f19f03 | |||
v1.0 | instruct | Filter | Filter_54749_I | Can you assist me with writing an algorithm to solve a Sudoku puzzle? I'm looking for a step-by-step explanation of the approach, and if possible, a simple example in Python. | def is_valid(board, row, col, num):
"""
Check if a number can be placed at a given position.
"""
# Check if the number is not in the current row or column.
for i in range(9):
if board[row][i] == num or board[i][col] == num:
return False
# Check if the number is not in the cu... | from solution import solve_sudoku, is_valid, find_empty_position
def test_is_valid():
board = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6... | [
{
"docstring": "Check if a number can be placed at a given position.",
"function_declaration": "def is_valid(board, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": "Solves the given Sudoku board using a backtracking algorithm.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def solve_sudoku(board):\n empty_cell = find_empty_cell(board)\n if not empty_cell:\n # No empty cell is found; puzzle solved\n return True\n row, col = empty_cell\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054749",
"row_id": 54749,
"seed_ids": "['Qwen2.5-72B-Instruct_112017']"
} | 0.370891 | Filter_54749 | I | [
"is_valid",
"solve_sudoku",
"find_empty_position"
] | 3 | [
[
"solve_sudoku",
"find_empty_position"
],
[
"solve_sudoku",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 730e15224d786bcd853860498a9cbe9aa0cda847 | 633e3919967265c8aad7e43636a02cf60f46039f | |||
v1.0 | instruct | Filter | Filter_54792_I | Design a function to verify if a given number is a prime number. Then, write a small program that uses this function to print all prime numbers between 1 and 100. The program should be efficient and concise, making use of modern Python features. Additionally, ensure your code is well-commented for clarity. | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, print_primes_up_to
import io
import sys
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
as... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints all prime numbers between 1 and max_number (inclusive).",
"function_declaration": "def print_... | [
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 given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054792",
"row_id": 54792,
"seed_ids": "['Qwen2.5-72B-Instruct_112087']"
} | 0.716082 | Filter_54792 | I | [
"is_prime",
"print_primes_up_to"
] | 2 | [
[
"print_primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7bd3b61b7238788b152e1137813b673041f3ceed | 5a7bc2bd52e8516c8206dc051e378958357de9c5 | |||
v1.0 | instruct | Filter | Filter_54811_I | Describe the process of creating a simple chatbot using Python and the Flask framework. Include the basics of setting up the environment, structuring the project, and a simple example of a chatbot that responds to user inputs. | from flask import Flask, request, jsonify
app = Flask(__name__)
def simple_chatbot(message):
"""
A very simple chatbot that responds with fixed responses.
"""
if 'hello' in message.lower():
return "Hello! How can I help you today?"
elif 'bye' in message.lower():
return "Goodbye! Ha... | from solution import simple_chatbot
def test_chatbot_hello():
assert simple_chatbot('hello') == "Hello! How can I help you today?"
assert simple_chatbot('Hello there!') == "Hello! How can I help you today?"
def test_chatbot_bye():
assert simple_chatbot('bye') == "Goodbye! Have a great day!"
assert sim... | [
{
"docstring": "A very simple chatbot that responds with fixed responses.",
"function_declaration": "def simple_chatbot(message):",
"function_name": "simple_chatbot",
"parameter_list": "(message)"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat",... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\ndef simple_chatbot(message):\n \"\"\"\n A very simple chatbot that responds with fixed responses.\n \"\"\"\n i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00054811",
"row_id": 54811,
"seed_ids": "['Qwen2.5-72B-Instruct_112122']"
} | 0.392623 | Filter_54811 | I | [
"simple_chatbot",
"chat"
] | 2 | [
[
"chat",
"simple_chatbot"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 601a710f8738edbb65460105812b82fcd1c0a694 | d628567f645db4d5edf6f9adc607d9bd523d1180 | |||
v1.0 | instruct | Filter | Filter_54814_I | Write a function in Python that authenticates a username and password. The function should take two parameters: username and password. It should return True if the username is "admin" and the password is "123456", otherwise it should return False. For added security, the function should hash the password using a crypto... | import hashlib
def hash_password(password):
"""
Hashes the password using SHA-256 algorithm.
"""
return hashlib.sha256(password.encode()).hexdigest()
def authenticate(username, password):
"""
Authenticates the user by comparing the hashed password.
"""
stored_username = "admin"
sto... | from solution import authenticate, hash_password
def test_authenticate_valid_credentials():
assert authenticate("admin", "123456") == True
def test_authenticate_invalid_username():
assert authenticate("user", "123456") == False
def test_authenticate_invalid_password():
assert authenticate("admin", "wrong... | [
{
"docstring": "Hashes the password using SHA-256 algorithm.",
"function_declaration": "def hash_password(password):",
"function_name": "hash_password",
"parameter_list": "(password)"
},
{
"docstring": "Authenticates the user by comparing the hashed password.",
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\n\ndef authenticate(username, password):\n \"\"\"\n Authenticates a user by checking if the username is \"admin\" and the hashed\n password matches the stored hash.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054814",
"row_id": 54814,
"seed_ids": "['Qwen2.5-72B-Instruct_112128']"
} | 0.61521 | Filter_54814 | I | [
"hash_password",
"authenticate"
] | 2 | [
[
"authenticate",
"hash_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 575cd45a7ee9d81cce73fa0f146e2053e6482a3a | fc737a17ed2f2606ece7c4317ebf2ac7e013c391 | |||
v1.0 | instruct | Filter | Filter_54824_I | Write a Python code to simulate the Monty Hall problem and verify the probabilities of winning if the player switches or stays with their initial choice. Run the simulation for 10,000 trials. | import random
def simulate_monty_hall(num_trials: int, switch: bool) -> float:
win_count = 0
for _ in range(num_trials):
doors = [0, 0, 1] # 0 represents goat, 1 represents car
random.shuffle(doors) # Shuffle the doors
# Player makes an initial choice
player_choice = ran... | from solution import simulate_monty_hall, monty_hall_simulation
def test_simulate_monty_hall_switch():
win_probability = simulate_monty_hall(10000, switch=True)
# Theoretical value is around 0.66; allowing a tolerance
assert 0.65 <= win_probability <= 0.7
def test_simulate_monty_hall_stay():
win_proba... | [
{
"docstring": null,
"function_declaration": "def simulate_monty_hall(num_trials, switch):",
"function_name": "simulate_monty_hall",
"parameter_list": "(num_trials, switch)"
},
{
"docstring": null,
"function_declaration": "def monty_hall_simulation(num_trials=10000):",
"function_name... | [
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 monty_hall_simulation(trials=10000):\n \"\"\"\n Simulates the Monty Hall problem.\n \n Parameters:\n trials (int): Number of trials to run the simulation. D... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054824",
"row_id": 54824,
"seed_ids": "['Qwen2.5-72B-Instruct_112139']"
} | 0.47918 | Filter_54824 | I | [
"simulate_monty_hall",
"monty_hall_simulation"
] | 2 | [
[
"monty_hall_simulation",
"simulate_monty_hall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 035b5213b5537deb5d3f7bfcbc9d004ae0e32f1e | f60982782407e9c04cebfc96a4402e73753ed236 | |||
v1.0 | instruct | Filter | Filter_54841_I | Write a Python code that prints the prime numbers between 1 and 100. Also, for each prime number found, check if it is also a palindrome number and print a message if it is. A palindrome number reads the same backward as forward, like 131 or 787. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def is_palindrome(n):
"""
Check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
... | from solution import is_prime, is_palindrome, print_primes_and_palindromes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(30) == False
assert is_prime(97) == True
assert is_prime(100) == Fals... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
... | [
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": "00054841",
"row_id": 54841,
"seed_ids": "['Qwen2.5-72B-Instruct_112168']"
} | 0.606447 | Filter_54841 | I | [
"is_prime",
"is_palindrome",
"print_primes_and_palindromes"
] | 3 | [
[
"print_primes_and_palindromes",
"is_palindrome"
],
[
"print_primes_and_palindromes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ab27c6d44822d9feaad08ee01f2b1bf89f3932df | 4bbd827c47c05f84d692e97b0a65e72a6362488a | |||
v1.0 | instruct | Filter | Filter_54855_I | Write a script that performs a simple Caesar cipher encryption and decryption. The script should take a string and a shift value as input for encryption and the encrypted string and the same shift value for decryption. It should support both uppercase and lowercase letters, and non-alphabetic characters should remain u... | def caesar_cipher_encrypt(text, shift):
"""
Encrypts a given text using a Caesar cipher with a specific shift.
Parameters:
text (str): The text to be encrypted.
shift (int): The number of positions to shift each letter.
Returns:
str: The encrypted text.
"""
encrypted_text =... | from solution import caesar_cipher_encrypt, caesar_cipher_decrypt
def test_encrypt_lowercase():
assert caesar_cipher_encrypt("abc", 1) == "bcd"
assert caesar_cipher_encrypt("xyz", 3) == "abc"
def test_encrypt_uppercase():
assert caesar_cipher_encrypt("ABC", 1) == "BCD"
assert caesar_cipher_encrypt... | [
{
"docstring": "Encrypts a given text using a Caesar cipher with a specific shift.\n\nParameters:\ntext (str): The text to be encrypted.\nshift (int): The number of positions to shift each letter.\n\nReturns:\nstr: The encrypted text.",
"function_declaration": "def caesar_cipher_encrypt(text, shift):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_cipher_encrypt(text, shift):\n \"\"\"\n Encrypts the input text using Caesar cipher with the given shift.\n \n Parameters:\n text (str): The input text to be encrypte... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054855",
"row_id": 54855,
"seed_ids": "['Qwen2.5-72B-Instruct_112191']"
} | 0.680036 | Filter_54855 | I | [
"caesar_cipher_encrypt",
"caesar_cipher_decrypt"
] | 2 | [
[
"caesar_cipher_decrypt",
"caesar_cipher_encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c5dfc3a47c18a82a926969d8975d0879499e94d6 | b5b6de04ae7e4169bd053d3aec80bb40ba40a2a2 | |||
v1.0 | instruct | Filter | Filter_54868_I | I need to write a Python function that can filter a list of integers, returning only those that are prime numbers. Additionally, I want the function to accept an optional parameter to include a specific set of numbers in the result, regardless of whether they are prime or not. How can I implement this function efficien... | def is_prime(n):
"""
Helper function that checks if a number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return Fal... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(4) is False
assert is_prime(17) is True
assert is_prime(18) is False
assert is_prime(19) is True
assert is_prime(1) is False
assert is_prime(-3) is Fal... | [
{
"docstring": "Helper function that checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters a list of integers, returning only those that are prime numbers.\nAn optional parameter `... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n 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_2 | {
"original_instruction": "",
"prompt_id": "00054868",
"row_id": 54868,
"seed_ids": "['Qwen2.5-72B-Instruct_112215']"
} | 0.631296 | Filter_54868 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9360deff5b359fe155678af5cdfcd52fa02828fc | b169a361f5e3d44399f261df2a44fce1af8f811d | |||
v1.0 | instruct | Filter | Filter_54889_I | Design a function in Python that uses recursion to calculate the sum of all even numbers within a given list of integers. The function should disregard any nested lists or non-integer values and should be able to handle an empty list by returning 0. Additionally, implement a wrapper function that allows the user to inp... | def sum_even_numbers(lst):
"""
Recursively calculates the sum of all even numbers in a list of integers.
Ignores non-integer values and nested lists.
"""
if lst == []:
return 0
if isinstance(lst[0], int) and lst[0] % 2 == 0:
return lst[0] + sum_even_numbers(lst[1:])
else:
... | from solution import sum_even_numbers, wrapper_function
def test_sum_even_numbers_empty_list():
assert sum_even_numbers([]) == 0
def test_sum_even_numbers_all_even():
assert sum_even_numbers([2, 4, 6, 8]) == 20
def test_sum_even_numbers_mixed():
assert sum_even_numbers([1, 2, 3, 4, 5, 6]) == 12
def test... | [
{
"docstring": "Recursively calculates the sum of all even numbers in a list of integers.\nIgnores non-integer values and nested lists.",
"function_declaration": "def sum_even_numbers(lst):",
"function_name": "sum_even_numbers",
"parameter_list": "(lst)"
},
{
"docstring": "Wrapper function t... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_even_numbers_recursive(lst):\n \"\"\"\n Recursively calculates the sum of all even numbers in the given list of integers.\n Ignores nested lists and non-integer values.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054889",
"row_id": 54889,
"seed_ids": "['Qwen2.5-72B-Instruct_112249']"
} | 0.80145 | Filter_54889 | I | [
"sum_even_numbers",
"wrapper_function"
] | 2 | [
[
"wrapper_function",
"sum_even_numbers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 975b24f7497851921714f043cc878c6d2b96d9ec | 03d60ed461edbb0252624f685183ceee9e0a06aa | |||
v1.0 | instruct | Filter | Filter_54890_I | Write a python function that converts a decimal number to a binary string, and also include a simple check function to verify the correctness of the conversion for the numbers 0 through 10. | def decimal_to_binary(n):
"""
Converts a decimal number to a binary string.
"""
if n == 0:
return '0'
binary_str = ''
while n > 0:
binary_str = str(n % 2) + binary_str
n = n // 2
return binary_str
def check_conversion():
"""
Checks the binary conversion corre... | from solution import decimal_to_binary, check_conversion
def test_decimal_to_binary():
assert decimal_to_binary(0) == '0'
assert decimal_to_binary(1) == '1'
assert decimal_to_binary(2) == '10'
assert decimal_to_binary(3) == '11'
assert decimal_to_binary(4) == '100'
assert decimal_to_binary(5) =... | [
{
"docstring": "Converts a decimal number to a binary string.",
"function_declaration": "def decimal_to_binary(n):",
"function_name": "decimal_to_binary",
"parameter_list": "(n)"
},
{
"docstring": "Checks the binary conversion correctness from 0 to 10.",
"function_declaration": "def chec... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_binary(n):\n \"\"\"\n Converts a decimal number to a binary string.\n \n Parameters:\n n (int): Decimal number to be converted.\n \n Returns:\n str: Bina... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054890",
"row_id": 54890,
"seed_ids": "['Qwen2.5-72B-Instruct_112251']"
} | 0.876218 | Filter_54890 | I | [
"decimal_to_binary",
"check_conversion"
] | 2 | [
[
"check_conversion",
"decimal_to_binary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cc4ff884dc75432f04daed371c4d688d2a3745f | b8dfffe2066405fd753a460d1c0ce804eef4be8b | |||
v1.0 | instruct | Filter | Filter_54904_I | Design a Python function that efficiently checks if a given string is a palindrome. A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., "madam" or "racecar". Your function should ignore spaces, punctuation, and capitalization. For example, "A man, a plan, a canal, Panama!" should ... | import re
def is_palindrome(s):
"""
Check if the provided string is a palindrome, ignoring spaces,
punctuation, and capitalization.
"""
cleaned_s = re.sub(r'[^A-Za-z0-9]', '', s).lower() # remove non-alphanumeric characters and convert to lower case
return cleaned_s == cleaned_s[::-1]
def fin... | from solution import is_palindrome, find_palindromic_lines
def test_is_palindrome_basic():
assert is_palindrome("madam") == True
assert is_palindrome("racecar") == True
def test_is_palindrome_with_spaces_and_punctuation():
assert is_palindrome("A man, a plan, a canal, Panama!") == True
assert is_palin... | [
{
"docstring": "Check if the provided string is a palindrome, ignoring spaces,\npunctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Read a text file line by line and print out all pal... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Check if the provided string is a palindrome, ignoring spaces,\n punctuation, and capitalization.\n \"\"\"\n cleaned_s = re.sub(r'[... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00054904",
"row_id": 54904,
"seed_ids": "['Qwen2.5-72B-Instruct_112277']"
} | 0.783339 | Filter_54904 | I | [
"is_palindrome",
"find_palindromic_lines"
] | 2 | [
[
"find_palindromic_lines",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ce8b05b8104910419785786edc8ea9d1e7587988 | ab9b07acb8e9173d825ce8a480467d897cd0ac8c | |||
v1.0 | instruct | Filter | Filter_54916_I | In Python, if I have a function that returns a tuple, how can I unpack the contents of the tuple into separate variables? Consider an example where the function returns a tuple of a username and a user_id. | def get_user_details():
"""
Returns a tuple with username and user_id.
"""
return ("JohnDoe", 12345)
def unpack_user_details():
"""
Unpacks the tuple returned by get_user_details into separate variables.
"""
username, user_id = get_user_details()
return username, user_id | from solution import get_user_details, unpack_user_details
def test_get_user_details():
assert get_user_details() == ("JohnDoe", 12345)
def test_unpack_user_details():
username, user_id = unpack_user_details()
assert username == "JohnDoe"
assert user_id == 12345 | [
{
"docstring": "Returns a tuple with username and user_id.",
"function_declaration": "def get_user_details():",
"function_name": "get_user_details",
"parameter_list": "()"
},
{
"docstring": "Unpacks the tuple returned by get_user_details into separate variables.",
"function_declaration":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_user_info():\n \"\"\"\n Example function that returns a tuple of username and user_id.\n \"\"\"\n username = \"user123\"\n user_id = 101\n return (username, user_id)\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054916",
"row_id": 54916,
"seed_ids": "['Qwen2.5-72B-Instruct_112297']"
} | 0.650866 | Filter_54916 | I | [
"get_user_details",
"unpack_user_details"
] | 2 | [
[
"unpack_user_details",
"get_user_details"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e26bde758e919f8a5c93067248c2339084592886 | 4b7051bacb51606a7f92bcc2e4fa68f2523547b9 | |||
v1.0 | instruct | Filter | Filter_54921_I | I need to encode a given text using a Caesar cipher with a shift of 3. Can you write a Python function to do this? Also, can you include a function to decode the text back to its original form? | def caesar_cipher_encode(text, shift=3):
"""
Encodes text using Caesar cipher with a shift of 3.
"""
encoded = ""
for char in text:
if char.isalpha():
shift_base = 65 if char.isupper() else 97
encoded += chr((ord(char) - shift_base + shift) % 26 + shift_base)
... | from solution import caesar_cipher_encode, caesar_cipher_decode
def test_caesar_cipher_encode():
assert caesar_cipher_encode("HELLO") == "KHOOR"
assert caesar_cipher_encode("WORLD") == "ZRUOG"
assert caesar_cipher_encode("abc") == "def"
assert caesar_cipher_encode("xyz") == "abc"
assert caesar_ciph... | [
{
"docstring": "Encodes text using Caesar cipher with a shift of 3.",
"function_declaration": "def caesar_cipher_encode(text, shift=3):",
"function_name": "caesar_cipher_encode",
"parameter_list": "(text, shift=3)"
},
{
"docstring": "Decodes text using Caesar cipher with a shift of 3.",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_cipher_encode(text, shift=3):\n \"\"\"\n Encode the given text using Caesar cipher with a shift of 3.\n \n Args:\n text (str): The input text to encode.\n shift (i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054921",
"row_id": 54921,
"seed_ids": "['Qwen2.5-72B-Instruct_112306']"
} | 0.655624 | Filter_54921 | I | [
"caesar_cipher_encode",
"caesar_cipher_decode"
] | 2 | [
[
"caesar_cipher_decode",
"caesar_cipher_encode"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 021ff1d4e5291d8bcf857de1444741482a24c899 | 8cf7385808e980ab1231d935dc9c286a7a86e275 | |||
v1.0 | instruct | Filter | Filter_54926_I | Can you assist me in creating a Python script that can automatically add a watermark to images? I want to be able to specify the text of the watermark and the position where it should appear. It would also be great if the script can handle multiple images in a folder. | from PIL import Image, ImageDraw, ImageFont
import os
def add_watermark(input_folder, watermark_text, position, output_folder='watermarked'):
"""
Adds a watermark to all images in the specified folder.
Parameters:
- input_folder: str, path to the folder containing images to be watermarked
- wa... | from solution import add_watermark, watermark_image
from PIL import Image
import tempfile
import os
def test_add_watermark():
# Set up temporary directories
with tempfile.TemporaryDirectory() as input_dir, tempfile.TemporaryDirectory() as output_dir:
# Create a test image
img = Image.new('RGB',... | [
{
"docstring": "Adds a watermark to all images in the specified folder.\n\nParameters:\n- input_folder: str, path to the folder containing images to be watermarked\n- watermark_text: str, text of the watermark to be added\n- position: tuple of 2 int, position (x, y) where the watermark will be placed\n- output_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from PIL import Image, ImageDraw, ImageFont\nimport os\n\ndef add_watermark(input_folder, output_folder, watermark_text, position):\n \"\"\"\n Adds a watermark to all images in the input... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054926",
"row_id": 54926,
"seed_ids": "['Qwen2.5-72B-Instruct_112314']"
} | 0.358709 | Filter_54926 | I | [
"add_watermark",
"watermark_image"
] | 2 | [
[
"add_watermark",
"watermark_image"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | 8a670fa3caf70325cf95c76e36b5e8388160ae05 | cbcee599c3ee87c61c423301b9f93d79dbcfd430 | |||
v1.0 | instruct | Filter | Filter_54928_I | How can I use Python to detect the gender of a person from an image? | import cv2
def load_models(face_model_path, gender_model_path):
face_net = cv2.dnn.readNet(face_model_path)
gender_net = cv2.dnn.readNet(gender_model_path)
return face_net, gender_net
def get_gender_label(gender_pred):
return 'Male' if gender_pred[0] > 0.5 else 'Female'
def detect_gender(image_path, ... | import os
import cv2
import numpy as np
from solution import load_models, detect_gender
def test_detect_gender_male():
face_model_path = "deploy.prototxt.txt"
gender_model_path = "gender_net.caffemodel"
if not os.path.exists(face_model_path) or not os.path.exists(gender_model_path):
return # ... | [
{
"docstring": null,
"function_declaration": "def load_models(face_model_path, gender_model_path):",
"function_name": "load_models",
"parameter_list": "(face_model_path, gender_model_path)"
},
{
"docstring": null,
"function_declaration": "def get_gender_label(gender_pred):",
"functio... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import cv2\nimport numpy as np\nfrom tensorflow.keras.models import load_model\n\ndef load_pretrained_model(model_path='gender_model.h5'):\n \"\"\"\n Loads and returns a pre-trained mode... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054928",
"row_id": 54928,
"seed_ids": "['Qwen2.5-72B-Instruct_112320']"
} | 0.423009 | Filter_54928 | I | [
"load_models",
"get_gender_label",
"detect_gender"
] | 3 | [
[
"detect_gender",
"get_gender_label"
]
] | 1 | [] | false | [] | false | pytest | true | [
"cv2",
"numpy"
] | false | 1b3db1920682b39674e841b879c17ddb88e87315 | 97b28b53c55e4a788dc0fcf01c4d208ec0832939 | |||
v1.0 | instruct | Filter | Filter_54938_I | Write a Python script that can automatically download the latest version of Google Chrome browser for Windows and save it to a specified directory. The script should also check the downloaded file's integrity by comparing it against a known SHA-256 checksum provided by the official Google Chrome release page. If the ch... | import os
import hashlib
import requests
from pathlib import Path
import logging
logging.basicConfig(level=logging.INFO)
def download_chrome(destination_directory, expected_checksum):
"""
Download the latest version of Google Chrome for Windows and save it to the specified directory.
Verify the file's int... | import os
from solution import download_chrome, verify_checksum
import hashlib
import tempfile
def test_verify_checksum():
# Create a temporary file and compute its checksum
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(b"Google Chrome installer")
temp_path = temp... | [
{
"docstring": "Download the latest version of Google Chrome for Windows and save it to the specified directory.\nVerify the file's integrity using the provided SHA-256 checksum.\n\nParameters:\n- destination_directory: str, the directory where the file should be saved.\n- expected_checksum: str, the expected S... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport hashlib\nimport os\n\ndef download_chrome(url, save_path, expected_checksum):\n \"\"\"\n Downloads Google Chrome from the specified URL and saves it to the given ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054938",
"row_id": 54938,
"seed_ids": "['Qwen2.5-72B-Instruct_112335']"
} | 0.489759 | Filter_54938 | I | [
"download_chrome",
"verify_checksum"
] | 2 | [
[
"download_chrome",
"verify_checksum"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 0bc7c1a2a8650a07ec3753c46326f6c6d9619939 | 04aed8218f2d2e932f916c1f1d1f48478eb57435 | |||
v1.0 | instruct | Filter | Filter_54946_I | Can you write a Python program that uses a while loop to find the first 5 prime numbers and print them in a formatted manner? Make sure to properly comment your code to explain the logic behind your solution. | def is_prime(n):
"""
Check if a number n is prime.
A prime number is only divisible by 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 first_n_primes(n):
"""
Find and return the f... | from solution import is_prime, first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(0) == False
assert is_prime(-5) == Fal... | [
{
"docstring": "Check if a number n is prime.\nA prime number is only divisible by 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find and return the first n 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(num):\n \"\"\"\n Check if a number is prime.\n A prime number is only divisible by 1 and itself.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054946",
"row_id": 54946,
"seed_ids": "['Qwen2.5-72B-Instruct_112344']"
} | 0.573384 | Filter_54946 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 854c32ba141c93a13b510a2629af2e43f46b0a23 | f443f0a9c02d825752964ef5a06e0b47b739ee3e | |||
v1.0 | instruct | Filter | Filter_54978_I | Write a program in Python that generates a random string of 10 characters. The string should consist of uppercase letters and digits. The program should also include a function to check if the generated string starts with a letter. If it does not, the program should regenerate the string until a valid one is produced. ... | import random
import string
def generate_random_string():
"""
Generate a random string of 10 characters consisting of uppercase letters and digits.
"""
characters = string.ascii_uppercase + string.digits
return ''.join(random.choice(characters) for _ in range(10))
def is_valid_string(s):
"... | from solution import generate_random_string, is_valid_string, generate_valid_string
def test_generate_random_string_length():
assert len(generate_random_string()) == 10
def test_generate_random_string_content():
s = generate_random_string()
assert all(c in string.ascii_uppercase + string.digits for c in s... | [
{
"docstring": "Generate a random string of 10 characters consisting of uppercase letters and digits.",
"function_declaration": "def generate_random_string():",
"function_name": "generate_random_string",
"parameter_list": "()"
},
{
"docstring": "Check if the string starts with an uppercase l... | [
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_string():\n \"\"\"\n Generates a random string of 10 characters consisting of uppercase letters and digits.\n If the generated stri... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00054978",
"row_id": 54978,
"seed_ids": "['Qwen2.5-72B-Instruct_112393']"
} | 0.738652 | Filter_54978 | I | [
"generate_random_string",
"is_valid_string",
"generate_valid_string"
] | 3 | [
[
"generate_valid_string",
"generate_random_string"
],
[
"generate_valid_string",
"is_valid_string"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0eae733eec1d450c625769e6ff7045fabc020e8a | e2054819d84ac92ae682e29ca7be8ff2661e43ba | |||
v1.0 | instruct | Filter | Filter_54980_I | Write a program in Python that prompts the user to input a number and then determines if the number is a prime number. If the number is a prime, the program should print "The number is a prime number." Otherwise, it should print "The number is not a prime number." | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_... | [
{
"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": "Checks if the given number is prime and prints the result.",
"function_declaration": "def check_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(number):\n \"\"\"\n Determines if a number is a prime number.\n Returns True if the number is prime, otherwise False.\n \"\"\"\n if number <= 1:\n return Fal... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054980",
"row_id": 54980,
"seed_ids": "['Qwen2.5-72B-Instruct_112395']"
} | 0.800267 | Filter_54980 | I | [
"is_prime",
"check_prime_number"
] | 2 | [
[
"check_prime_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 902f12aeb91eae26594c5917811746a4b2a8b7e3 | 8e847e0505cc40a146be81356dc84927b9a8f7a6 | |||
v1.0 | instruct | Filter | Filter_54989_I | Given the function `return_two_values`, which is intended to return two values but currently does not work as expected. Without altering the function's implementation, your task is to create a function `fetch_values` that will call `return_two_values` and return the first value only. Additionally, ensure to include a c... | def return_two_values():
"""
This is a placeholder function. Assume this function returns
two values (value1, value2) when called.
"""
return 1, 2
def fetch_values():
"""
This function calls `return_two_values` and returns only the first value.
"""
value1, _ = return_two_values()
... | from solution import fetch_values, check_solution
def test_fetch_values():
assert fetch_values() == 1, "fetch_values did not return the expected first value."
def test_check_solution():
check_solution() # If the assertion fails, this will raise an AssertionError | [
{
"docstring": "This is a placeholder function. Assume this function returns\ntwo values (value1, value2) when called.",
"function_declaration": "def return_two_values():",
"function_name": "return_two_values",
"parameter_list": "()"
},
{
"docstring": "This function calls `return_two_values`... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def return_two_values():\n \"\"\"\n This function is assumed to return two values but its implementation is not provided.\n \"\"\"\n return 1, 2 # Example output\n\ndef fetch_valu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00054989",
"row_id": 54989,
"seed_ids": "['Qwen2.5-72B-Instruct_112412']"
} | 0.467026 | Filter_54989 | I | [
"return_two_values",
"fetch_values",
"check_solution"
] | 3 | [
[
"check_solution",
"fetch_values"
],
[
"fetch_values",
"return_two_values"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e2277aa96c9a0626ed3a13da899fe59ed652a19e | a8ab1604eae37ec87d3faefc06c3942e6400ddec | |||
v1.0 | instruct | Filter | Filter_55007_I | write a Python script to check the availability and response time of a list of websites, and log the results to a file. The script should also send an email alert if any website is down. Assume that we have a function `send_emailalert(to_list,subject,content)` that sends an email and it is already defined in the script... | import requests
from datetime import datetime
def check_websites(websites, log_file, to_list):
with open(log_file, 'a') as f:
for website in websites:
try:
start_time = datetime.now()
response = requests.get(website)
end_time = datetime.now()
... | import tempfile
import os
import pytest
from unittest.mock import patch
from solution import check_websites
mocked_websites_success = ["http://example.com"]
mocked_websites_failure = ["http://nonexistentwebsite.com"]
def mock_send_email_alert(to_list, subject, content):
pass
@patch("solution.send_email_alert", ... | [
{
"docstring": null,
"function_declaration": "def check_websites(websites, log_file, to_list):",
"function_name": "check_websites",
"parameter_list": "(websites, log_file, to_list)"
},
{
"docstring": null,
"function_declaration": "def send_email_alert(to_list, subject, content):",
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom datetime import datetime\n\ndef check_websites(websites, log_file, to_list):\n with open(log_file, 'a') as f:\n for website in websites:\n try:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055007",
"row_id": 55007,
"seed_ids": "['Qwen2.5-72B-Instruct_112437']"
} | 0.563848 | Filter_55007 | I | [
"check_websites",
"send_email_alert"
] | 2 | [
[
"check_websites",
"send_email_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 136125337f92033d5710b5c7d8a8b64c594dc95f | 56962f12c9899a0de81c0969d385aadb33ea2fc9 | |||
v1.0 | instruct | Filter | Filter_55008_I | Please consider the problem of sorting an array of integers using a merge sort algorithm. Could you provide a Python implementation of the merge sort algorithm and also include a brief explanation of how it works and its time complexity? | def merge_sort(arr):
"""
Sorts an array of integers using the merge sort algorithm.
:param arr: List[int], list of integers to be sorted
:return: List[int], sorted list of integers
"""
if len(arr) <= 1:
return arr
# Recursive case: split the array into two halves
mid = ... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_two_elements():
assert merge_sort([2, 1]) == [1, 2]
def test_merge_sort_multiple_elements():
assert merge_sort([4, 3, 2, 1]... | [
{
"docstring": "Sorts an array of integers using the merge sort algorithm.\n\n:param arr: List[int], list of integers to be sorted\n:return: List[int], sorted list of integers",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"doc... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "[Solution Code in Python]",
"test_code": "[Unit Test Code in Python]",
"test_coverage": null,
"test_result": "Fail"
},
"trial_gpt4o_1": {
"file_source": "Magpie-Filter-89K_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055008",
"row_id": 55008,
"seed_ids": "['Qwen2.5-72B-Instruct_112441']"
} | 0.613759 | Filter_55008 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c08e7760562cff05ba90fa0734cc83fe1383396f | 9717b82fc6dd9f66a551c3079f8151dcb9440b82 | |||
v1.0 | instruct | Filter | Filter_55023_I | Design a Python function that simulates the rolling of a fair six-sided die and then, using 1000 simulations, calculate the average of the outcomes. Based on the simulations, what is the average value you obtained? Note that your function should also be able to handle a variable number of sides for the die, not just si... | import random
def roll_die(num_sides=6):
"""
Simulates rolling a fair die with a given number of sides.
"""
return random.randint(1, num_sides)
def average_rolls(num_sides=6, num_simulations=1000):
"""
Simulates rolling a fair die with a given number of sides for num_simulations times
and ... | from solution import roll_die, average_rolls
def test_roll_die():
outcomes = {roll_die() for _ in range(1000)}
assert outcomes == {1, 2, 3, 4, 5, 6} # all sides should be possible
def test_average_rolls_six_sided():
avg = average_rolls(num_sides=6, num_simulations=1000)
assert 3 < avg < 4 # expected... | [
{
"docstring": "Simulates rolling a fair die with a given number of sides.",
"function_declaration": "def roll_die(num_sides=6):",
"function_name": "roll_die",
"parameter_list": "(num_sides=6)"
},
{
"docstring": "Simulates rolling a fair die with a given number of sides for num_simulations t... | [
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(sides=6):\n \"\"\"\n Simulates a roll of a fair die with 'sides' number of sides.\n \"\"\"\n return random.randint(1, sides)\n\ndef average_rolls(side... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055023",
"row_id": 55023,
"seed_ids": "['Qwen2.5-72B-Instruct_112463']"
} | 0.596204 | Filter_55023 | I | [
"roll_die",
"average_rolls"
] | 2 | [
[
"average_rolls",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee6c9a88dee6e612b5c15c99f2e1b03f4200ac2a | 1eedb2fec38d3ce2e6614bead67944cff035d945 | |||
v1.0 | instruct | Filter | Filter_55031_I | How can I create a Python program to monitor CPU usage on a Linux system and send an alert via email if the usage exceeds a certain threshold, say 75%? | import psutil
import smtplib
from email.mime.text import MIMEText
from datetime import datetime
def check_cpu_usage(threshold=75):
"""
Checks the CPU usage and sends an email alert if the usage exceeds the specified threshold.
:param threshold: The CPU usage percentage threshold.
"""
cpu_usage... | import pytest
from unittest.mock import patch, MagicMock
from solution import check_cpu_usage, send_email_alert
@patch('psutil.cpu_percent', return_value=80)
def test_check_cpu_usage(mock_cpu_percent):
assert check_cpu_usage() == 80
@patch('smtplib.SMTP_SSL')
def test_send_email_alert(mock_smtp_ssl):
mock_ser... | [
{
"docstring": "Checks the CPU usage and sends an email alert if the usage exceeds the specified threshold.\n\n:param threshold: The CPU usage percentage threshold.",
"function_declaration": "def check_cpu_usage(threshold=75):",
"function_name": "check_cpu_usage",
"parameter_list": "(threshold=75)"
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import psutil\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom datetime import datetime\n\ndef check_cpu_usage(threshold=75):\n \"\"\"\n Checks the CPU usage and sends an emai... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055031",
"row_id": 55031,
"seed_ids": "['Qwen2.5-72B-Instruct_112473']"
} | 0.648756 | Filter_55031 | I | [
"check_cpu_usage",
"send_email_alert",
"monitor_cpu"
] | 3 | [
[
"monitor_cpu",
"check_cpu_usage"
],
[
"monitor_cpu",
"send_email_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | c451b8d0e9f7b286ef69e931670e079b6f1d45be | 33bf939474d93cec05c9134e0180773d6e3dca4a | |||
v1.0 | instruct | Filter | Filter_55059_I | I have a list of 100 users who have subscribed to a newsletter. I want to send them personalized emails thanking them for their subscription. Each email should contain the recipient's first name and a unique discount code. How can I automate this process using Python? Can you provide some sample code? | import random
import string
def generate_discount_code():
"""
Generates a unique discount code.
"""
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
def send_email(user_list):
"""
Generates personalized emails for each user in the user_list.
Returns a list of em... | from solution import generate_discount_code, send_email
def test_generate_discount_code_length():
code = generate_discount_code()
assert len(code) == 10
def test_generate_discount_code_characters():
code = generate_discount_code()
assert all(char in string.ascii_uppercase + string.digits for char in c... | [
{
"docstring": "Generates a unique discount code.",
"function_declaration": "def generate_discount_code():",
"function_name": "generate_discount_code",
"parameter_list": "()"
},
{
"docstring": "Generates personalized emails for each user in the user_list.\nReturns a list of email messages.",... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_discount_code():\n \"\"\"\n Generates a unique discount code consisting of 8 random uppercase letters and digits.\n \"\"\"\n return ''.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055059",
"row_id": 55059,
"seed_ids": "['Qwen2.5-72B-Instruct_112517']"
} | 0.441938 | Filter_55059 | I | [
"generate_discount_code",
"send_email"
] | 2 | [
[
"send_email",
"generate_discount_code"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4d581f0b03b379d7be85cc0fb6df78c61be47c0d | 1a1313d309d1ae20d2c22d552f24ff861f5dd016 | |||
v1.0 | instruct | Filter | Filter_55063_I | Can you write a Python program that calculates the quadratic mean (root mean square) of a list of numbers? The program should be self-contained, importing any necessary packages at the beginning. The function should take a list of numbers as input and return the quadratic mean. For demonstration, include a check functi... | import math
def quadratic_mean(numbers):
"""
Calculates the quadratic mean (root mean square) of a list of numbers.
Args:
numbers (list of float): A list of numbers for which to calculate the quadratic mean.
Returns:
float: The quadratic mean of the numbers.
"""
if not numbers... | from solution import quadratic_mean
def test_quadratic_mean_empty_list():
assert quadratic_mean([]) == 0
def test_quadratic_mean_single_element():
assert quadratic_mean([2]) == 2.0
def test_quadratic_mean_multiple_elements():
assert quadratic_mean([1, 2, 3, 4, 5]) == 3.3166247903554
assert quadratic_... | [
{
"docstring": "Calculates the quadratic mean (root mean square) of a list of numbers.\n\nArgs:\nnumbers (list of float): A list of numbers for which to calculate the quadratic mean.\n\nReturns:\nfloat: The quadratic mean of the numbers.",
"function_declaration": "def quadratic_mean(numbers):",
"functio... | [
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 quadratic_mean(numbers):\n \"\"\"\n Calculates the quadratic mean (root mean square) of a list of numbers.\n \n Args:\n numbers (list of float or int): A list... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055063",
"row_id": 55063,
"seed_ids": "['Qwen2.5-72B-Instruct_112522']"
} | 0.617167 | Filter_55063 | I | [
"quadratic_mean",
"check_quadratic_mean"
] | 2 | [
[
"check_quadratic_mean",
"quadratic_mean"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6ce7930926e839d02ccacee22e2499a47dc5a75 | 966dee669f1295f2889e0fcaa9b150dc237d43c3 | |||
v1.0 | instruct | Filter | Filter_55097_I | Given the objective to develop a Python function that evaluates a list of floating-point numbers, identifying the position of the greatest value within this list. The function should return the index of the first occurrence in case of multiple highest values. Illustrate the creation of this function, ensuring its accur... | def find_position_of_max(nums):
"""
Returns the index of the first occurrence of the greatest value in the list of floating-point numbers.
:param nums: List of floating-point numbers.
:return: Index of the first occurrence of the greatest value.
"""
if not nums:
raise ValueError("Th... | from solution import find_position_of_max, find_position_of_max_with_loop
def test_find_position_of_max_no_value_error():
try:
find_position_of_max([])
assert False, "Expected ValueError"
except ValueError:
pass
def test_find_position_of_max_with_loop_no_value_error():
try:
... | [
{
"docstring": "Returns the index of the first occurrence of the greatest value in the list of floating-point numbers.\n\n:param nums: List of floating-point numbers.\n:return: Index of the first occurrence of the greatest value.",
"function_declaration": "def find_position_of_max(nums):",
"function_nam... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_max_index(nums):\n \"\"\"\n Returns the index of the highest value in the list of floating-point numbers.\n If there are multiple occurrences of the highest value, return the... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055097",
"row_id": 55097,
"seed_ids": "['Qwen2.5-72B-Instruct_112575']"
} | 0.636366 | Filter_55097 | I | [
"find_position_of_max",
"find_position_of_max_with_loop",
"compare_performance"
] | 3 | [
[
"compare_performance",
"find_position_of_max"
],
[
"compare_performance",
"find_position_of_max_with_loop"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c21cf7c7e8d8c7144d1d33500611d8271bb9a0bf | 5bdf84559843e58db89f2bf298cfe24299680730 | |||
v1.0 | instruct | Filter | Filter_55119_I | Create a python function that takes a range of years and returns a list of all the dates of Easter Sunday within that range. The function should be efficient and well-optimized. | from datetime import date
def calculate_easter_sunday(year):
"""
Returns the date of Easter Sunday for a given year using the Anonymous Gregorian algorithm.
"""
a = year % 19
b = year // 100
c = year % 100
d = b // 4
e = b % 4
f = (b + 8) // 25
g = (b - f + 1) // 3
h = (19 *... | from solution import get_easter_sundays, calculate_easter_sunday
from datetime import date
def test_calculate_easter_sunday():
assert calculate_easter_sunday(2023) == date(2023, 4, 9)
assert calculate_easter_sunday(2024) == date(2024, 3, 31)
assert calculate_easter_sunday(2025) == date(2025, 4, 20)
ass... | [
{
"docstring": "Returns the date of Easter Sunday for a given year using the Anonymous Gregorian algorithm.",
"function_declaration": "def calculate_easter_sunday(year):",
"function_name": "calculate_easter_sunday",
"parameter_list": "(year)"
},
{
"docstring": "Returns a list of all Easter S... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import datetime\n\ndef easter_sunday(year):\n \"\"\"\n Calculate the date of Easter Sunday for a given year using the \"Anonymous Gregorian algorithm\".\n Returns a datetime.date obje... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055119",
"row_id": 55119,
"seed_ids": "['Qwen2.5-72B-Instruct_112608']"
} | 0.532854 | Filter_55119 | I | [
"calculate_easter_sunday",
"get_easter_sundays"
] | 2 | [
[
"get_easter_sundays",
"calculate_easter_sunday"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1a2c984a8d9f454627464a78cc122d08a0ba5944 | 8e4a5e7e9353eaa7027c14f66c2a586610501e35 | |||
v1.0 | instruct | Filter | Filter_55215_I | Can you write a Python script that converts temperatures from Fahrenheit to Celsius and also from Celsius to Fahrenheit? The script should take the temperature and the unit as input, and output the converted temperature with its unit. It should handle invalid inputs gracefully. | def fahrenheit_to_celsius(f):
"""
Converts Fahrenheit to Celsius.
"""
return (f - 32) * 5.0/9.0
def celsius_to_fahrenheit(c):
"""
Converts Celsius to Fahrenheit.
"""
return (c * 9.0/5.0) + 32
def convert_temperature(value, unit):
"""
Converts the temperature based on the unit p... | from solution import convert_temperature
def test_fahrenheit_to_celsius():
assert convert_temperature(32, 'F') == "0.0 C"
assert convert_temperature(212, 'F') == "100.0 C"
assert convert_temperature(98.6, 'F') == "37.0 C"
def test_celsius_to_fahrenheit():
assert convert_temperature(0, 'C') == "32.0 F"... | [
{
"docstring": "Converts Fahrenheit to Celsius.",
"function_declaration": "def fahrenheit_to_celsius(f):",
"function_name": "fahrenheit_to_celsius",
"parameter_list": "(f)"
},
{
"docstring": "Converts Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(c):",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def convert_temperature(temp, unit):\n \"\"\"\n Converts temperature from Fahrenheit to Celsius and from Celsius to Fahrenheit.\n \n Args:\n temp (float): The temperature value.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055215",
"row_id": 55215,
"seed_ids": "['Qwen2.5-72B-Instruct_112789']"
} | 0.411991 | Filter_55215 | I | [
"fahrenheit_to_celsius",
"celsius_to_fahrenheit",
"convert_temperature"
] | 3 | [
[
"convert_temperature",
"celsius_to_fahrenheit"
],
[
"convert_temperature",
"fahrenheit_to_celsius"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b77ca1172bb94be0f1ff53e97b9d95d88c422bff | dce97d4fefcbce28e5c995de90c0dd116dfb2487 | |||
v1.0 | instruct | Filter | Filter_55222_I | Write a Python code to generate a random number between 1 and 100, and then write a function that allows a user to guess the number. The function should provide feedback on whether the guess is too low, too high, or correct. The game should continue until the correct number is guessed. | import random
def generate_random_number():
"""
Generates a random number between 1 and 100.
"""
return random.randint(1, 100)
def guess_number_game():
"""
Runs the number guessing game. The user keeps guessing until they guess the correct number.
Feedback is provided whether the guess is ... | import pytest
from unittest.mock import patch
from solution import generate_random_number, guess_number_game
def test_generate_random_number():
number = generate_random_number()
assert 1 <= number <= 100
@patch('builtins.input', side_effect=[50, 75, 62, 88, 70])
@patch('solution.generate_random_number', retur... | [
{
"docstring": "Generates a random number between 1 and 100.",
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": "Runs the number guessing game. The user keeps guessing until they guess the correct num... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_number():\n \"\"\"\n Generates a random number between 1 and 100.\n \"\"\"\n return random.randint(1, 100)\n\ndef guess_number_game():\n \"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055222",
"row_id": 55222,
"seed_ids": "['Qwen2.5-72B-Instruct_112797']"
} | 0.534716 | Filter_55222 | I | [
"generate_random_number",
"guess_number_game"
] | 2 | [
[
"guess_number_game",
"generate_random_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9acd2d882232461088b3629c91cc38fbc63c2b8 | f3f454e6fe409547f8fc7c0623f2f16b2c696dbc | |||
v1.0 | instruct | Filter | Filter_55240_I | Design a Python function to simulate the rolling of a die with a variable number of sides, and then use this function to simulate the rolling of a 6-sided die 1000 times. After the simulation, calculate the mean and standard deviation of the outcomes. Also, create a histogram to visualize the distribution of the outcom... | import random
import matplotlib.pyplot as plt
import numpy as np
def roll_die(sides=6):
"""
Simulates the rolling of a die with a given number of sides.
"""
return random.randint(1, sides)
def simulate_die_rolls(sides, rolls):
"""
Simulates rolling a die with the specified number of sides a gi... | from solution import roll_die, simulate_die_rolls, calculate_statistics, plot_histogram
import numpy as np
def test_roll_die():
result = roll_die(6)
assert 1 <= result <= 6
def test_simulate_die_rolls():
results = simulate_die_rolls(6, 100)
assert len(results) == 100
assert all(1 <= r <= 6 for r i... | [
{
"docstring": "Simulates the rolling of a die with a given number of sides.",
"function_declaration": "def roll_die(sides=6):",
"function_name": "roll_die",
"parameter_list": "(sides=6)"
},
{
"docstring": "Simulates rolling a die with the specified number of sides a given number of times.\n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport matplotlib.pyplot as plt\nimport numpy as np\n\ndef roll_die(sides=6):\n \"\"\"\n Simulates the rolling of a die with a given number of sides.\n \"\"\"\n retu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055240",
"row_id": 55240,
"seed_ids": "['Qwen2.5-72B-Instruct_112822']"
} | 0.694515 | Filter_55240 | I | [
"roll_die",
"simulate_die_rolls",
"calculate_statistics",
"plot_histogram"
] | 4 | [
[
"simulate_die_rolls",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy"
] | false | c332f155fdd2819993b03e2952ffbb5550913da2 | 329195cf0cc2088422999714ac0bf0d3563beb72 | |||
v1.0 | instruct | Filter | Filter_55243_I | Write a piece of Python code that creates a list of all prime numbers between 1 and 100. For each prime number found, the code should print the number along with a message "is a prime number". If the number is not prime, it should be skipped, and the code should move on to the next number. | def is_prime(n):
"""
Check if a number is prime
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def list_primes_up_to_100():
"""
List all prime numbers between 1 and 100, and print each prime number
... | from solution import is_prime, list_primes_up_to_100
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert is_prime(5)
assert is_prime(7)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(4)
assert not is_prime(6)
assert not is_prime(8)
assert not is_pri... | [
{
"docstring": "Check if a number is prime",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "List all prime numbers between 1 and 100, and print each prime number \nalong with a message \"is a prime number\".",
"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 n is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055243",
"row_id": 55243,
"seed_ids": "['Qwen2.5-72B-Instruct_112826']"
} | 0.738898 | Filter_55243 | I | [
"is_prime",
"list_primes_up_to_100"
] | 2 | [
[
"list_primes_up_to_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9392748a611c03c215e3c05d56762149656fbd13 | 5c5e276e9d192aadf21f950c5d3174f7c2d475ab | |||
v1.0 | instruct | Filter | Filter_55268_I | Implement the k-means clustering algorithm from scratch in Python and provide a detailed explanation of the steps involved. Also, show how to evaluate the performance of the clustering using silhouette score. | import numpy as np
def initialize_centroids(X, k):
"""
Randomly initialize the centroids by selecting k unique points from the dataset.
"""
indices = np.random.choice(X.shape[0], size=k, replace=False)
centroids = X[indices]
return centroids
def closest_centroid(X, centroids):
"""
Assi... | import numpy as np
from solution import initialize_centroids, closest_centroid, move_centroids, kmeans, evaluate_kmeans
def test_initialize_centroids():
np.random.seed(42)
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
k = 2
centroids = initialize_centroids(X, k)
assert centroids.shape == ... | [
{
"docstring": "Randomly initialize the centroids by selecting k unique points from the dataset.",
"function_declaration": "def initialize_centroids(X, k):",
"function_name": "initialize_centroids",
"parameter_list": "(X, k)"
},
{
"docstring": "Assign each data point to the closest centroid.... | [
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\nfrom scipy.spatial.distance import cdist\nfrom sklearn.metrics import silhouette_score\n\ndef initialize_centroids(X, k):\n \"\"\"\n Randomly initialize centroids fro... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055268",
"row_id": 55268,
"seed_ids": "['Qwen2.5-72B-Instruct_112871']"
} | 0.633529 | Filter_55268 | I | [
"initialize_centroids",
"closest_centroid",
"move_centroids",
"kmeans",
"evaluate_kmeans"
] | 5 | [
[
"kmeans",
"closest_centroid"
],
[
"kmeans",
"initialize_centroids"
],
[
"kmeans",
"move_centroids"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy",
"sklearn"
] | false | ec6b68ba58351bedbd62a5d4090211f5fc0a816c | 2471fc9d15faf273080682c6ce50c92fb5a7cde1 | |||
v1.0 | instruct | Filter | Filter_55273_I | I need to create a Python script that checks the disk usage of a local directory and sends an email alert if the usage exceeds a certain threshold. How can I do that? | import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import shutil
def check_disk_usage(directory, threshold):
"""
Checks the disk usage of the given directory and compares it to the threshold.
If the usage exceeds the threshold, sends an email alert.... | import pytest
from unittest.mock import patch, Mock
from solution import check_disk_usage, send_email_alert
@patch('solution.shutil.disk_usage')
@patch('solution.send_email_alert')
def test_check_disk_usage_above_threshold(mock_send_email_alert, mock_disk_usage):
mock_disk_usage.return_value = (1000, 900, 100)
... | [
{
"docstring": "Checks the disk usage of the given directory and compares it to the threshold.\nIf the usage exceeds the threshold, sends an email alert.",
"function_declaration": "def check_disk_usage(directory, threshold):",
"function_name": "check_disk_usage",
"parameter_list": "(directory, thres... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\nimport smtplib\nfrom email.mime.text import MIMEText\n\ndef check_disk_usage(directory, threshold):\n \"\"\"\n Checks the disk usage of the specified directory ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055273",
"row_id": 55273,
"seed_ids": "['Qwen2.5-72B-Instruct_112886']"
} | 0.49763 | Filter_55273 | I | [
"check_disk_usage",
"send_email_alert"
] | 2 | [
[
"check_disk_usage",
"send_email_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d354c46f944b0710e10e44e589fa09a68dc3bfb1 | d0cab0c15baeca2c9a630dfacb669704aa5ec0c4 | |||
v1.0 | instruct | Filter | Filter_55277_I | I'm trying to use a Python script to automate a task, and I need to pass a list of parameters to a function. How can I do this in Python? Specifically, if I have a function that takes multiple arguments, how can I pass a list of values to this function so that each value in the list is treated as a separate argument? | def process_parameters(param1, param2, param3):
"""
Example function that takes three parameters.
"""
return f"Processed parameters: {param1}, {param2}, {param3}"
def pass_list_as_arguments(params):
"""
Function to pass a list of parameters to another function.
"""
return process_parame... | from solution import process_parameters, pass_list_as_arguments
def test_process_parameters():
assert process_parameters(1, 2, 3) == "Processed parameters: 1, 2, 3"
assert process_parameters("a", "b", "c") == "Processed parameters: a, b, c"
def test_pass_list_as_arguments():
assert pass_list_as_arguments(... | [
{
"docstring": "Example function that takes three parameters.",
"function_declaration": "def process_parameters(param1, param2, param3):",
"function_name": "process_parameters",
"parameter_list": "(param1, param2, param3)"
},
{
"docstring": "Function to pass a list of parameters to another f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def example_function(a, b, c):\n \"\"\"\n Example function that takes three arguments.\n \"\"\"\n return a + b + c\n\ndef call_function_with_list(function, arg_list):\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055277",
"row_id": 55277,
"seed_ids": "['Qwen2.5-72B-Instruct_112894']"
} | 0.451129 | Filter_55277 | I | [
"process_parameters",
"pass_list_as_arguments"
] | 2 | [
[
"pass_list_as_arguments",
"process_parameters"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 32b4f4052616a36d80aa7114637bb45f6eb601eb | b5cd51e00d8f7b5e9628c6e06dc68c4abf518054 | |||
v1.0 | instruct | Filter | Filter_55286_I | Create a Python program to determine if a number is a Lychrel number. A Lychrel number is a number that does not form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. For the purpose of this program, let's assume that any number that doesn't form a palindro... | def is_palindrome(n):
return str(n) == str(n)[::-1]
def is_lychrel(n, max_iterations=50):
for _ in range(max_iterations):
n += int(str(n)[::-1])
if is_palindrome(n):
return False
return True | from solution import is_palindrome, is_lychrel
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(123321) == True
assert is_palindrome(123456) == False
def test_is_not_lychrel():
assert is_lych... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_lychrel(n, max_iterations=50):",
"function_name": "is_lychrel",
"parameter_list": "(n, max_itera... | [
0,
1,
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 Check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef is_lychrel(n, max_iterations=50):\n \"\"\"\n Determines if... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055286",
"row_id": 55286,
"seed_ids": "['Qwen2.5-72B-Instruct_112910']"
} | 0.558995 | Filter_55286 | I | [
"is_palindrome",
"is_lychrel"
] | 2 | [
[
"is_lychrel",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef3f35705decb7285eba587040ef22f574252515 | bbe7dfd8399559bbc639b6742445454410ae6cb2 | |||
v1.0 | instruct | Filter | Filter_55341_I | Create a Python script for a simple command-line note-taking app that allows users to add, view, and delete notes. Each note should have a title and a body, and all notes should be stored in a JSON file. The app should have a menu to select operations. Ensure to include error handling for file operations and user input... | import json
import os
NOTES_FILE = 'notes.json'
def read_notes():
"""Reads notes from the JSON file."""
if not os.path.exists(NOTES_FILE):
return {}
with open(NOTES_FILE, 'r') as file:
return json.load(file)
def write_notes(notes):
"""Writes notes to the JSON file."""
with open(NO... | import os
import json
from solution import read_notes, write_notes, add_note, view_notes, delete_note, NOTES_FILE
# Test data setup and teardown function
def setup_function():
if os.path.exists(NOTES_FILE):
os.remove(NOTES_FILE)
def teardown_function():
if os.path.exists(NOTES_FILE):
os.remove... | [
{
"docstring": "Reads notes from the JSON file.",
"function_declaration": "def read_notes():",
"function_name": "read_notes",
"parameter_list": "()"
},
{
"docstring": "Writes notes to the JSON file.",
"function_declaration": "def write_notes(notes):",
"function_name": "write_notes",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport os\n\nNOTES_FILE = 'notes.json'\n\ndef load_notes():\n if os.path.exists(NOTES_FILE):\n with open(NOTES_FILE, 'r') as file:\n try:\n not... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055341",
"row_id": 55341,
"seed_ids": "['Qwen2.5-72B-Instruct_112996']"
} | 0.458277 | Filter_55341 | I | [
"read_notes",
"write_notes",
"add_note",
"view_notes",
"delete_note",
"menu"
] | 6 | [
[
"add_note",
"read_notes"
],
[
"add_note",
"write_notes"
],
[
"delete_note",
"read_notes"
],
[
"delete_note",
"write_notes"
],
[
"menu",
"add_note"
],
[
"menu",
"delete_note"
],
[
"menu",
"view_notes"
],
[
"view_notes",
"re... | 8 | [] | false | [] | false | pytest | true | [] | true | b2117ba212fff3be49bead14f26856cf9ff335b9 | 048950941ebc2f4d2f69061971c9d599b6b02c4e | |||
v1.0 | instruct | Filter | Filter_55348_I | write the python code to generate a Fibonacci number sequence and display the first 10 numbers in the sequence. | def fibonacci_sequence(n):
"""
Generates the Fibonacci sequence up to the n-th element.
"""
sequence = []
a, b = 0, 1
for _ in range(n):
sequence.append(a)
a, b = b, a + b
return sequence
def first_10_fibonacci_numbers():
"""
Returns the first 10 numbers in the Fibon... | from solution import first_10_fibonacci_numbers, fibonacci_sequence
def test_first_10_fibonacci_numbers():
assert first_10_fibonacci_numbers() == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_fibonacci_sequence_base_cases():
assert fibonacci_sequence(0) == []
assert fibonacci_sequence(1) == [0]
assert fi... | [
{
"docstring": "Generates the Fibonacci sequence up to the n-th element.",
"function_declaration": "def fibonacci_sequence(n):",
"function_name": "fibonacci_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first 10 numbers in the Fibonacci sequence.",
"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 Returns the first n numbers of the Fibonacci sequence.\n \"\"\"\n sequence = []\n a, b = 0, 1\n for _ in range(n):\n sequence.app... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055348",
"row_id": 55348,
"seed_ids": "['Qwen2.5-72B-Instruct_113010']"
} | 0.703075 | Filter_55348 | I | [
"fibonacci_sequence",
"first_10_fibonacci_numbers"
] | 2 | [
[
"first_10_fibonacci_numbers",
"fibonacci_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fda28fb1390bac8af748fdd99c324511a52dcc73 | 75080274827ac0bd04374f575a6fd37b27c841f5 | |||
v1.0 | instruct | Filter | Filter_55385_I | Write a Python script that will find the first 100 prime numbers and save them in a file named `primes.txt`, each prime number on a new line. | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tru... | from solution import is_prime, first_n_primes, save_primes_to_file
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
def test_first_n_primes():
assert fi... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_name": "first_... | [
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_0 | {
"original_instruction": "",
"prompt_id": "00055385",
"row_id": 55385,
"seed_ids": "['Qwen2.5-72B-Instruct_113073']"
} | 0.56276 | Filter_55385 | I | [
"is_prime",
"first_n_primes",
"save_primes_to_file"
] | 3 | [
[
"first_n_primes",
"is_prime"
],
[
"save_primes_to_file",
"first_n_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 288149a9df126ed8ca181c4468da4b4bfea8b451 | 91fea5474c2a4421c331890e4a3ddbf73d8516f1 | |||
v1.0 | instruct | Filter | Filter_55406_I | Can you help me design a simple experiment to test the efficiency of two different sorting algorithms in Python? I am particularly interested in comparing the time it takes for Bubble Sort and Quick Sort to sort an array of 10,000 random integers. | import random
import time
def bubble_sort(arr):
"""
Sorts an array using the bubble sort algorithm.
"""
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
def quick_sort(arr):
""... | from solution import bubble_sort, quick_sort, generate_random_array, measure_sorting_time, run_experiment
def test_bubble_sort():
arr = [3, 2, 1]
sorted_arr = bubble_sort(arr)
assert sorted_arr == [1, 2, 3]
def test_quick_sort():
arr = [3, 2, 1]
sorted_arr = quick_sort(arr)
assert sorted_arr =... | [
{
"docstring": "Sorts an array using the bubble sort algorithm.",
"function_declaration": "def bubble_sort(arr):",
"function_name": "bubble_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts an array using the quick sort algorithm.",
"function_declaration": "def quick_sort(arr):",... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport time\n\ndef bubble_sort(arr):\n \"\"\"\n Sorts an array using the bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in ran... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055406",
"row_id": 55406,
"seed_ids": "['Qwen2.5-72B-Instruct_113106']"
} | 0.462349 | Filter_55406 | I | [
"bubble_sort",
"quick_sort",
"generate_random_array",
"measure_sorting_time",
"run_experiment"
] | 5 | [
[
"run_experiment",
"bubble_sort"
],
[
"run_experiment",
"generate_random_array"
],
[
"run_experiment",
"measure_sorting_time"
],
[
"run_experiment",
"quick_sort"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 460905587b64925d1ecb50a67b96d3f074d8a408 | 96c3571f68c8b9a2d851e1bd4aec93bac3a77859 | |||
v1.0 | instruct | Filter | Filter_55407_I | Write a Python function that generates a list of all prime numbers within a given range. The function should take two positive integer parameters, `start` and `end`, and return a list of all prime numbers between `start` and `end` inclusive. The function should be optimized for performance to handle ranges up to 1,000,... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import generate_primes_in_range
def test_generate_primes_in_small_range():
assert generate_primes_in_range(5, 10) == [5, 7]
def test_generate_primes_single_number():
assert generate_primes_in_range(11, 11) == [11]
assert generate_primes_in_range(4, 4) == []
def test_generate_primes_range_wi... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers in the range [start, end].",
"function_declaration": "def generate_prim... | [
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 within a given range [start, end].\n\n Parameters:\n start (int): The starting integer of the rang... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055407",
"row_id": 55407,
"seed_ids": "['Qwen2.5-72B-Instruct_113108']"
} | 0.636816 | Filter_55407 | I | [
"is_prime",
"generate_primes_in_range"
] | 2 | [
[
"generate_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6357fd9ae831aab271e4c65bc5f30ab84e91c61b | cc77d9e5cbbbdf81cb4c6c74c3037ab1ee3bd6a0 | |||
v1.0 | instruct | Filter | Filter_55412_I | Hey Qwen, I'm working on a project and I need to efficiently calculate the Fibonacci sequence for a series of numbers. My input will be a list of integers, and I expect the output to be the corresponding Fibonacci numbers for each integer in the list. I found a piece of code online, but it's not optimized for large num... | def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
if n <= 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
def fibonacci_list(nums):
"""
Returns a list of Fibonacci numbers corresponding to the giv... | from solution import fibonacci, fibonacci_list
def test_fibonacci_0():
assert fibonacci(0) == 0
def test_fibonacci_1():
assert fibonacci(1) == 1
def test_fibonacci_small_numbers():
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
def test_fi... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of Fibonacci numbers corresponding to the given list of integers.",
"function_declaration": "def fibona... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fib(n, memo={}):\n \"\"\"\n Returns the nth Fibonacci number using memoization to optimize for large inputs.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 1:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055412",
"row_id": 55412,
"seed_ids": "['Qwen2.5-72B-Instruct_113118']"
} | 0.659015 | Filter_55412 | I | [
"fibonacci",
"fibonacci_list"
] | 2 | [
[
"fibonacci_list",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 62f37311d26135fcc7109efd251aeeae41e50557 | aa7edb0040612c5dc46d629ae4074519075e4844 | |||
v1.0 | instruct | Filter | Filter_55414_I | Design a Python program that simulates rolling a pair of dice 500 times, and then construct a bar chart to illustrate the frequency of each possible outcome (2 through 12). Assume each die is a standard six-sided die. | import random
import matplotlib.pyplot as plt
def roll_dice():
"""
Roll a pair of six-sided dice and return their sum.
"""
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
return die1 + die2
def simulate_dice_rolls(num_rolls):
"""
Simulates rolling a pair of dice num_rolls times... | from solution import roll_dice, simulate_dice_rolls
def test_roll_dice_within_range():
for _ in range(100):
result = roll_dice()
assert 2 <= result <= 12
def test_simulate_dice_rolls_sum_counts():
frequencies = simulate_dice_rolls(500)
assert sum(frequencies.values()) == 500
def test_simu... | [
{
"docstring": "Roll a pair of six-sided dice and return their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates rolling a pair of dice num_rolls times.\n\nArgs:\n num_rolls (int): The number of times to ro... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport matplotlib.pyplot as plt\n\ndef roll_dice(num_rolls):\n \"\"\"\n Simulate rolling a pair of dice `num_rolls` times.\n \n Args:\n num_rolls (int): The numbe... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055414",
"row_id": 55414,
"seed_ids": "['Qwen2.5-72B-Instruct_113121']"
} | 0.768 | Filter_55414 | I | [
"roll_dice",
"simulate_dice_rolls",
"plot_dice_frequencies"
] | 3 | [
[
"simulate_dice_rolls",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib"
] | false | 9c1e52ca12c18bdbf0c0ea229535a2b41b5557da | aacea06356b423f13612da5d71efadab75a8d8d7 | |||
v1.0 | instruct | Filter | Filter_55416_I | Write a program in Python to implement the RSA algorithm for encryption and decryption. Provide an example of its usage. | import random
from sympy import isprime, mod_inverse
def generate_rsa_keys(bits=1024):
def generate_prime_candidate(length):
p = random.getrandbits(length)
p |= (1 << length - 1) | 1
return p
def generate_prime_number(length):
p = 4
while not isprime(p):
p =... | from solution import generate_rsa_keys, encrypt_rsa, decrypt_rsa
def test_generate_rsa_keys():
public_key, private_key = generate_rsa_keys(16)
assert len(public_key) == 2
assert len(private_key) == 2
assert public_key[1] == private_key[1]
def test_rsa_encryption_decryption():
public_key, private_k... | [
{
"docstring": null,
"function_declaration": "def generate_rsa_keys(bits=1024):",
"function_name": "generate_rsa_keys",
"parameter_list": "(bits=1024)"
},
{
"docstring": null,
"function_declaration": "def encrypt_rsa(public_key, plaintext):",
"function_name": "encrypt_rsa",
"para... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n while b != 0:\n a, b = b, a % b\n return a\n\ndef modinv(a, m):\n m0, x0, x1 = m, 0, 1\n if m == 1:\n return 0\n while a > 1:\n q = a // m\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055416",
"row_id": 55416,
"seed_ids": "['Qwen2.5-72B-Instruct_113123']"
} | 0.59611 | Filter_55416 | I | [
"generate_rsa_keys",
"encrypt_rsa",
"decrypt_rsa",
"gcd"
] | 4 | [
[
"generate_rsa_keys",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | a161fb90868897b9cb7b0afd221b9f4d9334b89c | 07177722fd72fef3687223fc9202252ec6441113 | |||
v1.0 | instruct | Filter | Filter_55430_I | Implement a function to calculate the next prime number greater than a given integer. The function should efficiently find the next prime number, even for large integers. Additionally, write a function to test the correctness of this prime number generator by checking if the generated numbers are indeed prime and great... | import math
def is_prime(n):
"""
Checks if the given number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return Fal... | from solution import is_prime, next_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(4) == False
assert is_prime(1) == False
def test_next_prime():
assert next_prime(3) == 5
assert next_prime(8) == 11
assert nex... | [
{
"docstring": "Checks if the given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next prime number greater than a given integer n.",
"function_declaration": "def next_prime(n)... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if the given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055430",
"row_id": 55430,
"seed_ids": "['Qwen2.5-72B-Instruct_113144']"
} | 0.639826 | Filter_55430 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dfed89c42784d59081a2f742a3fd7f5ebc5edda | 065dced49fc076c4f4d2f91995b6ae5f506134ec | |||
v1.0 | instruct | Filter | Filter_55436_I | I am a beginner in machine learning and I'm trying to set up a simple service that can read and process data from a text file, then apply some basic text analysis, such as counting the frequency of words. I'm using Python and I'm a bit overwhelmed by all the tutorials I've found. Could you guide me on how to get starte... | from collections import Counter
import re
def read_text_file(file_path):
"""
Reads the content of a text file and returns it as a string.
"""
with open(file_path, 'r') as file:
return file.read()
def process_text(text):
"""
Processes the text by converting it to lowercase, removing spe... | import tempfile
import os
from solution import read_text_file, process_text, count_word_frequency, analyze_text_file
def test_read_text_file():
content = "Hello world\nThis is a test file."
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(content.encode())
temp_file_... | [
{
"docstring": "Reads the content of a text file and returns it as a string.",
"function_declaration": "def read_text_file(file_path):",
"function_name": "read_text_file",
"parameter_list": "(file_path)"
},
{
"docstring": "Processes the text by converting it to lowercase, removing special ch... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef read_file(file_path):\n \"\"\"\n Reads the content of the file located at file_path.\n \n Args:\n file_path (str): The path to the fil... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055436",
"row_id": 55436,
"seed_ids": "['Qwen2.5-72B-Instruct_113152']"
} | 0.496039 | Filter_55436 | I | [
"read_text_file",
"process_text",
"count_word_frequency",
"analyze_text_file"
] | 4 | [
[
"analyze_text_file",
"count_word_frequency"
],
[
"analyze_text_file",
"process_text"
],
[
"analyze_text_file",
"read_text_file"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 27e2d64d1f5426a5e8f690fb427efeea4a5b89f6 | 8c97d8e99768adbda079bb5b7547db738fdab28b | |||
v1.0 | instruct | Filter | Filter_55458_I | Develop a Python program to calculate the square root of a number using the Newton-Raphson method. The program should be able to handle both positive and negative inputs, returning the complex square root for negative numbers. Ensure the program is robust, handling edge cases and providing informative error messages. A... | import cmath
def newton_raphson_sqrt(value, tolerance=1.0e-10, max_iterations=1000):
"""
Calculates the square root of a given number using the Newton-Raphson method.
Handles both positive and negative inputs, returning complex square roots for negative inputs.
"""
if value == 0:
return 0
... | from solution import sqrt
def test_sqrt_positive_numbers():
assert abs(sqrt(4) - 2) < 1.0e-10
assert abs(sqrt(16) - 4) < 1.0e-10
assert abs(sqrt(25) - 5) < 1.0e-10
def test_sqrt_with_zero():
assert sqrt(0) == 0
def test_sqrt_negative_numbers():
assert abs(sqrt(-4) - complex(0, 2)) < 1.0e-10
a... | [
{
"docstring": "Calculates the square root of a given number using the Newton-Raphson method.\nHandles both positive and negative inputs, returning complex square roots for negative inputs.",
"function_declaration": "def newton_raphson_sqrt(value, tolerance=1e-10, max_iterations=1000):",
"function_name"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def newton_raphson_sqrt(value, tolerance=1e-10, max_iterations=1000):\n \"\"\"\n Calculate the square root of a number using the Newton-Raphson method.\n\n Parameters:\n - value (f... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055458",
"row_id": 55458,
"seed_ids": "['Qwen2.5-72B-Instruct_113186']"
} | 0.59368 | Filter_55458 | I | [
"newton_raphson_sqrt",
"sqrt"
] | 2 | [
[
"sqrt",
"newton_raphson_sqrt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d03f50e642a3deef9d52d181c6366c36f7a2f7bd | 9bfcdc354a0389e333cd5f263823258e60ca7b2e | |||
v1.0 | instruct | Filter | Filter_55468_I | Can you help me design a simple inverted pendulum simulation using Python and matplotlib? | import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
class InvertedPendulum:
def __init__(self, length=1.0, mass=1.0, theta=0.1, omega=0.0, dt=0.01):
self.length = length # Length of the pendulum (m)
self.mass = mass # Mass of the pendulu... | from solution import InvertedPendulum
def test_initial_position():
pendulum = InvertedPendulum(length=1.0, theta=np.pi/4)
x, y = pendulum.position()
assert np.isclose(x, np.sin(np.pi/4))
assert np.isclose(y, -np.cos(np.pi/4))
def test_step():
pendulum = InvertedPendulum(length=1.0, theta=np.pi/4, ... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\n\nclass InvertedPendulum:\n def __init__(self, length=1.0, mass=1.0, theta=0.1, omega=0.... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055468",
"row_id": 55468,
"seed_ids": "['Qwen2.5-72B-Instruct_113203']"
} | 0.436817 | Filter_55468 | I | [
"animate",
"simulate_pendulum"
] | 2 | [
[
"simulate_pendulum",
"animate"
]
] | 1 | [] | false | [
"InvertedPendulum"
] | true | pytest | true | [
"matplotlib",
"numpy"
] | false | 3f2b107f5a91fd4c5c1caf768345ec5a509e39ba | 161f8599a4627ca82f52f4d18e458a7424c32291 | |||
v1.0 | instruct | Filter | Filter_55486_I | How can I design a basic chatbot using Python? I want to start with a simple project to understand the basics before moving on to more complex systems. Can you guide me through the process? | def get_response(user_input):
"""
Returns an appropriate response based on the user input.
"""
responses = {
"hello": "Hi there! How can I help you today?",
"how are you": "I'm just a chatbot, but I'm here to help!",
"bye": "Goodbye! Have a great day!",
"help": "I can ass... | from solution import get_response
def test_get_response_hello():
assert get_response("HELLO") == "Hi there! How can I help you today?"
assert get_response("hello") == "Hi there! How can I help you today?"
assert get_response("Hello, how are you?") == "Hi there! How can I help you today?"
def test_get_resp... | [
{
"docstring": "Returns an appropriate response based on the user input.",
"function_declaration": "def get_response(user_input):",
"function_name": "get_response",
"parameter_list": "(user_input)"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat"... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_response(user_input):\n \"\"\"\n Returns a pre-defined response based on the user input.\n \"\"\"\n responses = {\n \"hello\": \"Hi there!\",\n \"how are you?... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055486",
"row_id": 55486,
"seed_ids": "['Qwen2.5-72B-Instruct_113238']"
} | 0.389585 | Filter_55486 | I | [
"get_response",
"chat"
] | 2 | [
[
"chat",
"get_response"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 482b5f6486832b51ae0855bedda45439d201cc04 | 7a86f97be1f93cd0dcab23ee772ed1a1fab355a2 | |||
v1.0 | instruct | Filter | Filter_55487_I | Develop a Python template to solve Sudoku puzzles using backtracking, and explain the key concepts and steps involved in your solution. | def is_valid(board, row, col, num):
"""
Check if it's valid to place num in the board at (row, col)
"""
# Check row
if num in board[row]:
return False
# Check column
for r in range(9):
if board[r][col] == num:
return False
# Check 3x3 subgrid
sta... | 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, 0, 2, 8, 0],
[0, 0, 0, 4, ... | [
{
"docstring": "Check if it's valid to place num in the board at (row, col)",
"function_declaration": "def is_valid(board, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": "Solves the given Sudoku puzzle using backtracking.",
"fu... | [
0,
1,
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 whether `num` can be placed at board[row][col].\n \"\"\"\n for x in range(9):\n if board[row][x] == num or board[x][col]... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055487",
"row_id": 55487,
"seed_ids": "['Qwen2.5-72B-Instruct_113239']"
} | 0.422323 | Filter_55487 | I | [
"is_valid",
"solve_sudoku"
] | 2 | [
[
"solve_sudoku",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 46ff3b264fe0f643411d56da78f471d35988575a | bb89bfc0091031fcdc712616204f66339c5fae99 | |||
v1.0 | instruct | Filter | Filter_55495_I | Can you write a code snippet to simulate a dice roll game in Python where a user competes against the computer? The game should keep track of the scores and decide who wins after five rounds. | import random
def roll_dice():
"""
Simulates rolling a six-sided die.
"""
return random.randint(1, 6)
def dice_game():
"""
Simulates a dice roll game between a user and the computer over five rounds.
"""
user_score = 0
computer_score = 0
for _ in range(5):
user_rol... | from solution import roll_dice, dice_game
def test_roll_dice():
roll = roll_dice()
assert roll in [1, 2, 3, 4, 5, 6]
def test_dice_game():
result = dice_game()
assert result in ["User wins!", "Computer wins!", "It's a tie!"]
def test_dice_game_runs_multiple_times():
results = {"User wins!": ... | [
{
"docstring": "Simulates rolling a six-sided die.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a dice roll game between a user and the computer over five rounds.",
"function_declaration": "def dice_game()... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided dice.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_dice_game():\n user_score = 0\n computer_s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055495",
"row_id": 55495,
"seed_ids": "['Qwen2.5-72B-Instruct_113251']"
} | 0.510456 | Filter_55495 | I | [
"roll_dice",
"dice_game"
] | 2 | [
[
"dice_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58947d5259f7e58e04175ab4487a33ec01237bf3 | 40262baa97981fc8886caef4cfdc944a83c21b6c | |||
v1.0 | instruct | Filter | Filter_55506_I | If I am working on a project to model the spread of a virus in a city using Python, could you recommend a specific library or tool that would be useful, and provide an example of how to use it? | import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def SIR_model(y, t, beta, gamma):
"""
Function to compute SIR model differential equations.
Parameters:
y : list : Initial conditions vector
t : int : Time points at which to solve the equations
beta : fl... | import numpy as np
from solution import SIR_model, model_virus_spread, plot_SIR
def test_SIR_model():
# Test the differential equation function with initial values
S0, I0, R0 = 999, 1, 0
beta, gamma = 0.3, 0.1
t0 = 0
dSdt, dIdt, dRdt = SIR_model((S0, I0, R0), t0, beta, gamma)
assert dSdt == -be... | [
{
"docstring": "Function to compute SIR model differential equations.\n\nParameters:\ny : list : Initial conditions vector\nt : int : Time points at which to solve the equations\nbeta : float : Rate of infection per susceptible and infected individual\ngamma : float : Rate of recovery of infected individuals\n\... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef sir_model(S, I, R, beta, gamma, days):\n \"\"\"\n SIR model to simulate virus spread.\n\n Parameters:\n S (int): number of susceptible individuals\n I ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055506",
"row_id": 55506,
"seed_ids": "['Qwen2.5-72B-Instruct_113274']"
} | 0.400375 | Filter_55506 | I | [
"SIR_model",
"model_virus_spread",
"plot_SIR"
] | 3 | [
[
"model_virus_spread",
"SIR_model"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"scipy"
] | false | f772e531305b74d15001a5e93c0f1cdd5120c780 | 5217acf0391e2006d45a2cd2646d1ee68f019884 | |||
v1.0 | instruct | Filter | Filter_55523_I | Implement a simple 2-layer neural network in Python using NumPy. The neural network should be a fully-connected network with ReLU activation for the hidden layer and a linear output for the final layer. Assume the input dimension is 10, and the output dimension is 1. The hidden layer has 5 neurons. Initialize the weigh... | import numpy as np
def relu(x):
"""
Applies the ReLU activation function.
"""
return np.maximum(0, x)
def initialize_parameters(input_dim, hidden_dim, output_dim):
"""
Initializes the network parameters (weights and biases) using a normal distribution for weights
and zeros for biases.
... | import numpy as np
from solution import initialize_parameters, forward_pass, mean_squared_error
def test_relu():
from solution import relu
assert np.array_equal(relu(np.array([-1, 0, 1])), np.array([0, 0, 1]))
def test_initialize_parameters():
W1, b1, W2, b2 = initialize_parameters(10, 5, 1)
assert W1... | [
{
"docstring": "Applies the ReLU activation function.",
"function_declaration": "def relu(x):",
"function_name": "relu",
"parameter_list": "(x)"
},
{
"docstring": "Initializes the network parameters (weights and biases) using a normal distribution for weights\nand zeros for biases.",
"fu... | [
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 initialize_parameters(input_dim, hidden_dim, output_dim):\n \"\"\"\n Initialize the weights and biases for a 2-layer neural network.\n \"\"\"\n W1 = np.ra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055523",
"row_id": 55523,
"seed_ids": "['Qwen2.5-72B-Instruct_113315']"
} | 0.508148 | Filter_55523 | I | [
"relu",
"initialize_parameters",
"forward_pass",
"mean_squared_error"
] | 4 | [
[
"forward_pass",
"relu"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 133dd05e80adc92e957e9c19415c85f881f518f4 | 33b05fb1c522011893034644ae9580e22154db0c | |||
v1.0 | instruct | Filter | Filter_55534_I | I need to write a Python script that periodically checks a website for updates. The script should download the HTML content of the page and compare it to the last known version. If the content has changed, it should send an email notification. How can I achieve this? | import requests
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
# Global variable to store the last known version of the page
last_known_content = None
def fetch_page(url):
"""
Fetch the HTML cont... | from solution import fetch_page, send_email_notification
from unittest import mock
import pytest
@mock.patch('requests.get')
def test_fetch_page(mock_get):
class MockResponse:
def __init__(self, text, status_code):
self.text = text
self.status_code = status_code
def... | [
{
"docstring": "Fetch the HTML content of the page.",
"function_declaration": "def fetch_page(url):",
"function_name": "fetch_page",
"parameter_list": "(url)"
},
{
"docstring": "Sends an email notification with the specified subject and body.",
"function_declaration": "def send_email_not... | [
0,
0,
1
] | 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.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nimport time\nimport hashlib\n\ndef get_website_content(url):\n \"\"\"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055534",
"row_id": 55534,
"seed_ids": "['Qwen2.5-72B-Instruct_113329']"
} | 0.505943 | Filter_55534 | I | [
"fetch_page",
"send_email_notification",
"check_for_updates"
] | 3 | [
[
"check_for_updates",
"fetch_page"
],
[
"check_for_updates",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | b63e2e2aae0e010bc4ccaf97f174add1634f5029 | 31b22110e80d06ea8df494e062fcf5f923e94d27 | |||
v1.0 | instruct | Filter | Filter_55574_I | Create a Python script that continuously reads a temperature sensor and checks for a specified temperature range. If the temperature goes outside this range, it should send an email alert. However, to avoid sending too many alerts, it should only send an alert if the temperature has been out of range for more than 5 mi... | import time
import random
from datetime import datetime, timedelta
import smtplib
from email.mime.text import MIMEText
HIGH_LIMIT = 75.0 # Example high temperature limit
LOW_LIMIT = 60.0 # Example low temperature limit
ALERT_THRESHOLD_MINUTES = 5 # Alert threshold in minutes
EMAIL_ADDRESS = 'your_email@example.com... | import pytest
from solution import read_fake_temperature_sensor, send_email_alert
def test_read_fake_temperature_sensor():
temperature = read_fake_temperature_sensor()
assert 55.0 <= temperature <= 80.0
def test_send_email_alert_success(monkeypatch):
class MockSMTP:
def __init__(self, *args, **kwa... | [
{
"docstring": "Simulates reading from a temperature sensor by returning a random temperature.",
"function_declaration": "def read_fake_temperature_sensor():",
"function_name": "read_fake_temperature_sensor",
"parameter_list": "()"
},
{
"docstring": "Sends an email alert with the given tempe... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport random\nfrom datetime import datetime, timedelta\nimport smtplib\nfrom email.mime.text import MIMEText\n\nHIGH_LIMIT = 75.0 # Example high temperature limit\nLOW_LIMIT = 6... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055574",
"row_id": 55574,
"seed_ids": "['Qwen2.5-72B-Instruct_113399']"
} | 0.34932 | Filter_55574 | I | [
"read_fake_temperature_sensor",
"send_email_alert",
"monitor_temperature"
] | 3 | [
[
"monitor_temperature",
"read_fake_temperature_sensor"
],
[
"monitor_temperature",
"send_email_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f1386c9a0fed8ab0e38095f9230479f6669cfd74 | cbe2b65c5275e696260fc0f5125f80edf88022a1 | |||
v1.0 | instruct | Filter | Filter_55594_I | Code a recursive function in Python to generate the Fibonacci sequence up to the n-th number. Also, include a simple check function to verify the correctness of the generated sequence against known values. | def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
def generate_fibonacci_sequence(n):
"""
Generates a list containing the Fibonacci sequence up to the nth number.... | from solution import fibonacci, generate_fibonacci_sequence, check_fibonacci_sequence
def test_fibonacci_base_cases():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
def test_fibonacci_intermediate_cases():
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fi... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list containing the Fibonacci sequence up to the nth number.",
"function_declaration": "def generate_fibon... | [
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 Fibonacci sequence up to the n-th number.\n \"\"\"\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055594",
"row_id": 55594,
"seed_ids": "['Qwen2.5-72B-Instruct_113427']"
} | 0.772202 | Filter_55594 | I | [
"fibonacci",
"generate_fibonacci_sequence",
"check_fibonacci_sequence"
] | 3 | [
[
"generate_fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77e8d8417aa64d34ef28ba88c35adbcddb47d7be | da455b4e3c2aace1047c071043fbc5ff2f091105 | |||
v1.0 | instruct | Filter | Filter_55597_I | Design a basic program in Python to simulate a simple dice roll game. The player rolls two six-sided dice and wins if the sum of the numbers on both dice equals 7 or 11. The program should let the player know if they won or lost after each roll. | import random
def roll_dice():
"""
Simulates rolling two six-sided dice. Returns the sum of the numbers on the two dice.
"""
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
return dice1 + dice2
def check_win(sum_of_dice):
"""
Determines if the player wins based on the sum of ... | from solution import roll_dice, check_win, play_dice_game
def test_roll_dice():
result = roll_dice()
assert 2 <= result <= 12
def test_check_win():
assert check_win(7) == True
assert check_win(11) == True
assert check_win(2) == False
assert check_win(8) == False
def test_play_dice_gam... | [
{
"docstring": "Simulates rolling two six-sided dice. Returns the sum of the numbers on the two dice.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Determines if the player wins based on the sum of the dice.\nPlayer wins... | [
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 roll_dice():\n \"\"\"\n Simulates rolling two six-sided dice and returns the outcome.\n \"\"\"\n dice1 = random.randint(1, 6)\n dice2 = random.randint(1, 6)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055597",
"row_id": 55597,
"seed_ids": "['Qwen2.5-72B-Instruct_113434']"
} | 0.560207 | Filter_55597 | I | [
"roll_dice",
"check_win",
"play_dice_game"
] | 3 | [
[
"play_dice_game",
"check_win"
],
[
"play_dice_game",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 62b6cca16855fae42a02653b1853b26b010fe09a | 8ecdfa354f3d59f367baebbf261e27a43a4d1317 | |||
v1.0 | instruct | Filter | Filter_55604_I | Develop a basic chatbot in Python using the Flask framework for a customer service application. The chatbot should be able to answer simple questions, such as the operating hours, how to contact customer service, and where the nearest branch is located. Provide a brief explanation of the steps involved, and include the... | from flask import Flask, request, jsonify
app = Flask(__name__)
def get_response(message):
"""
Returns a chatbot response based on the input message.
"""
lower_message = message.lower()
if "hours" in lower_message or "operating hours" in lower_message:
return "Our operating hours are from ... | import pytest
from solution import app, get_response
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_get_response_hours():
assert get_response("What are your operating hours?") == "Our operating hours are from 9 AM to 5 PM, from Monday to Friday."
def test_get_re... | [
{
"docstring": "Returns a chatbot response based on the input message.",
"function_declaration": "def get_response(message):",
"function_name": "get_response",
"parameter_list": "(message)"
},
{
"docstring": null,
"function_declaration": "def chatbot():",
"function_name": "chatbot",
... | [
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\n@app.route('/chatbot', methods=['POST'])\ndef chatbot():\n user_message = request.json.get('message').lower()\n \n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055604",
"row_id": 55604,
"seed_ids": "['Qwen2.5-72B-Instruct_113442']"
} | 0.404579 | Filter_55604 | I | [
"get_response",
"chatbot"
] | 2 | [
[
"chatbot",
"get_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 8fff8f185462d442cee6224eca6aeb8c3537f8c8 | a7031abcf821e16b97ec499a23119220f9e34953 | |||
v1.0 | instruct | Filter | Filter_55610_I | How can I create a Python script to monitor the real-time status of a web server and notify me if it goes down? | import requests
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import time
def send_email_notification(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_user, smtp_password):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_em... | import pytest
from unittest.mock import patch
import requests
from solution import send_email_notification, check_server_status
# Mocking the requests and smtplib libraries for testing
@patch('smtplib.SMTP')
def test_send_email_notification(mock_smtp):
send_email_notification(
subject="Test Subject",
... | [
{
"docstring": null,
"function_declaration": "def send_email_notification(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_user, smtp_password):",
"function_name": "send_email_notification",
"parameter_list": "(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_user, ... | [
1,
0,
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\nfrom email.mime.multipart import MIMEMultipart\nimport time\n\ndef send_email_notification(subject, body, to_email, from_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055610",
"row_id": 55610,
"seed_ids": "['Qwen2.5-72B-Instruct_113453']"
} | 0.555088 | Filter_55610 | I | [
"send_email_notification",
"check_server_status",
"monitor_server"
] | 3 | [
[
"check_server_status",
"send_email_notification"
],
[
"monitor_server",
"check_server_status"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 35265df36e1c1b498ebb30437c70aa7d1e5129a2 | 3f182aeeb8b7c51ebcd48313ca8487593fd76993 | |||
v1.0 | instruct | Filter | Filter_55635_I | Design a Python function to calculate the mean and median of a given list of numbers. Your function should be robust against input that includes `None` or non-numeric values by ignoring them. Additionally, provide a way to test the correctness of your function using predefined data points, including edge cases such as ... | def filter_numbers(lst):
"""
Filters out None and non-numeric values from a list.
"""
return [x for x in lst if isinstance(x, (int, float))]
def calculate_mean_median(numbers):
"""
Calculates and returns the mean and median of a given list of numbers.
Non-numeric values and None are ignore... | from solution import calculate_mean_median
def test_empty_list():
assert calculate_mean_median([]) == (None, None)
def test_all_none_values():
assert calculate_mean_median([None, None, None]) == (None, None)
def test_all_non_numeric_values():
assert calculate_mean_median(["a", "b", "c"]) == (None, None)
... | [
{
"docstring": "Filters out None and non-numeric values from a list.",
"function_declaration": "def filter_numbers(lst):",
"function_name": "filter_numbers",
"parameter_list": "(lst)"
},
{
"docstring": "Calculates and returns the mean and median of a given list of numbers.\nNon-numeric value... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def mean_and_median(numbers):\n \"\"\"\n Calculate the mean and median of a given list of numbers.\n Ignores None or non-numeric values.\n \n Parameters:\n numbers (list): A ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055635",
"row_id": 55635,
"seed_ids": "['Qwen2.5-72B-Instruct_113489']"
} | 0.741577 | Filter_55635 | I | [
"filter_numbers",
"calculate_mean_median"
] | 2 | [
[
"calculate_mean_median",
"filter_numbers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd3f490faea40e0a298e020e78aaf475afb65562 | 485b0f69160155b98a318728ebdaca3191f31d88 | |||
v1.0 | instruct | Filter | Filter_55663_I | Create a Python script that can list the files in a given directory, including files in subdirectories, and provide their sizes in human-readable format. The script should be able to accept the directory path as an argument when running from the command line. Additionally, the script should have an option to sort the o... | import os
import argparse
from humanize import naturalsize
def get_file_size(file_path):
"""
Returns the size of the file in human-readable format.
"""
size = os.path.getsize(file_path)
return naturalsize(size)
def list_files_in_directory(directory_path, sort_by_size=False):
"""
Lists al... | import os
import tempfile
from solution import get_file_size, list_files_in_directory
def create_test_files(base_dir, file_structure):
for file_path, size in file_structure.items():
full_path = os.path.join(base_dir, file_path)
os.makedirs(os.path.dirname(full_path), exist_ok=True)
with ope... | [
{
"docstring": "Returns the size of the file in human-readable format.",
"function_declaration": "def get_file_size(file_path):",
"function_name": "get_file_size",
"parameter_list": "(file_path)"
},
{
"docstring": "Lists all files in a given directory and subdirectories with their sizes.",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport argparse\nfrom humanize import naturalsize\n\n\ndef get_file_size(file_path):\n \"\"\"\n Returns the size of the file in human-readable format.\n \"\"\"\n size = ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055663",
"row_id": 55663,
"seed_ids": "['Qwen2.5-72B-Instruct_113542']"
} | 0.639942 | Filter_55663 | I | [
"get_file_size",
"list_files_in_directory"
] | 2 | [
[
"list_files_in_directory",
"get_file_size"
]
] | 1 | [] | false | [] | false | pytest | true | [
"humanize"
] | false | 2400dddb6c2984a6ba74fa8a6076dc3ef01e7819 | 9a660ba9e0f19b743eb07fa03f63b0f2653444c3 | |||
v1.0 | instruct | Filter | Filter_55665_I | Create a Python script that will create 1000 unique 100-character long random strings, save them into a text file, each on a new line, and then read and print out the 100th and 500th strings. Ensure that no two strings are the same. | import random
import string
def generate_random_string(length=100):
"""
Generate a random string of the specified length.
"""
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
def create_unique_strings(count=1000, length=100, filename='random_strings.txt'):
"""
Gen... | import os
from solution import generate_random_string, create_unique_strings, read_and_print_strings
def test_generate_random_string_length():
random_string = generate_random_string()
assert len(random_string) == 100
def test_generate_random_strings_unique():
strings = {generate_random_string() for _ in r... | [
{
"docstring": "Generate a random string of the specified length.",
"function_declaration": "def generate_random_string(length=100):",
"function_name": "generate_random_string",
"parameter_list": "(length=100)"
},
{
"docstring": "Generate a specified count of unique random strings, each of a... | [
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_string(length=100):\n \"\"\"\n Generate a random string of the specified length.\n \"\"\"\n return ''.join(random.choices(string... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055665",
"row_id": 55665,
"seed_ids": "['Qwen2.5-72B-Instruct_113544']"
} | 0.568813 | Filter_55665 | I | [
"generate_random_string",
"create_unique_strings",
"read_and_print_strings"
] | 3 | [
[
"create_unique_strings",
"generate_random_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a1bf2459f9ca1f55e4a5eeafc8bca7ff729ab205 | e0e8a51fbdbfe55838c5e02288eaacc119148e36 | |||
v1.0 | instruct | Filter | Filter_55674_I | Write a function in Python that finds the largest number in a given list that is not a prime number. If no such number exists, the function should return `None`. | def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def largest_non_prime(lst):
non_primes = [num for num in lst if not is_prime(num)]
return max(non_primes, default=None) | from solution import largest_non_prime
def test_largest_non_prime_basic():
assert largest_non_prime([2, 3, 4, 5, 6, 7, 8]) == 8
def test_largest_non_prime_all_primes():
assert largest_non_prime([2, 3, 5, 7]) == None
def test_largest_non_prime_mixed():
assert largest_non_prime([2, 6, 8, 11, 13]) == 8
def... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def largest_non_prime(lst):",
"function_name": "largest_non_prime",
"parameter_list": "(lst)"
}
] | [
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 for i in range(2, int(n**0.5) + 1):\n if n % i ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055674",
"row_id": 55674,
"seed_ids": "['Qwen2.5-72B-Instruct_113556']"
} | 0.720266 | Filter_55674 | I | [
"is_prime",
"largest_non_prime"
] | 2 | [
[
"largest_non_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5595c5eaa9a99ed77e4cc41cb129bb5019477d57 | bd8e037f719006c6f1b2e629714c67d0bc090b4b | |||
v1.0 | instruct | Filter | Filter_55689_I | Write a Python code that simulates the rolling of two six-sided dice and prints the result of each roll. Then, the code should also determine and print how many times a double (both dice showing the same number) was rolled out of 100 trials. | import random
def roll_dice():
"""
Simulates the rolling of two six-sided dice and returns the result of each roll.
"""
return random.randint(1, 6), random.randint(1, 6)
def simulate_dice_rolls(trials=100):
"""
Simulates rolling two six-sided dice for a given number of trials.
Determines a... | from solution import roll_dice, simulate_dice_rolls
import pytest
def test_roll_dice():
die1, die2 = roll_dice()
assert 1 <= die1 <= 6
assert 1 <= die2 <= 6
def test_simulate_dice_rolls_length():
results, double_count = simulate_dice_rolls(100)
assert len(results) == 100
def test_simulate_dice_ro... | [
{
"docstring": "Simulates the rolling of two six-sided dice and returns the result of each roll.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates rolling two six-sided dice for a given number of trials.\nDetermine... | [
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), random.randint(1, 6)\n\ndef simulate_dice_rolls_and_count_doubles(trials=100):\n \"\"\"\n Simulates rolling two six-si... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055689",
"row_id": 55689,
"seed_ids": "['Qwen2.5-72B-Instruct_113581']"
} | 0.569576 | Filter_55689 | I | [
"roll_dice",
"simulate_dice_rolls"
] | 2 | [
[
"simulate_dice_rolls",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 268cc82a46b594c06a52549e9ec157c1c942e5cc | 707f9bd96e4fe235101313c8d2b38f6e1f60bbdb | |||
v1.0 | instruct | Filter | Filter_55694_I | Create a simple Python program that acts as a temperature converter. The program should prompt the user to choose between converting from Celsius to Fahrenheit or from Fahrenheit to Celsius. It should then accept the temperature in the chosen scale and print the converted temperature. Make sure to handle exceptions for... | def celsius_to_fahrenheit(celsius):
"""
Converts Celsius to Fahrenheit.
"""
return (celsius * 9/5) + 32
def fahrenheit_to_celsius(fahrenheit):
"""
Converts Fahrenheit to Celsius.
"""
return (fahrenheit - 32) * 5/9
def temperature_converter(choice, temperature):
"""
Converts the... | from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, temperature_converter
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(-40) == -40
def test_fahrenheit_to_celsius():
assert fahrenheit_to_cels... | [
{
"docstring": "Converts Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius)"
},
{
"docstring": "Converts Fahrenheit to Celsius.",
"function_declaration": "def fahrenheit_to_celsius... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055694",
"row_id": 55694,
"seed_ids": "['Qwen2.5-72B-Instruct_113587']"
} | 0.38989 | Filter_55694 | I | [
"celsius_to_fahrenheit",
"fahrenheit_to_celsius",
"temperature_converter"
] | 3 | [
[
"temperature_converter",
"celsius_to_fahrenheit"
],
[
"temperature_converter",
"fahrenheit_to_celsius"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e1261d68d9fe82a4bd56096112a2ca8131bfd8c7 | 11ca020a0ffbd1cc636b98f1d4b8ec823536dbfe | |||
v1.0 | instruct | Filter | Filter_55712_I | Write a Python program to implement a simple linear regression model using only built-in Python libraries (without using any external libraries like NumPy or scikit-learn). | def mean(values):
return sum(values) / len(values)
def variance(values, mean_value):
return sum((x - mean_value) ** 2 for x in values)
def covariance(x, y, mean_x, mean_y):
return sum((x[i] - mean_x) * (y[i] - mean_y) for i in range(len(x)))
def simple_linear_regression(x, y):
mean_x, mean_y = mean(x... | from solution import mean, variance, covariance, simple_linear_regression, predict
def test_mean():
assert mean([1, 2, 3, 4, 5]) == 3
assert mean([10, 20, 30, 40, 50]) == 30
def test_variance():
assert variance([1, 2, 3, 4, 5], 3) == 10
assert variance([10, 20, 30, 40, 50], 30) == 1000
def test_covar... | [
{
"docstring": null,
"function_declaration": "def mean(values):",
"function_name": "mean",
"parameter_list": "(values)"
},
{
"docstring": null,
"function_declaration": "def variance(values, mean_value):",
"function_name": "variance",
"parameter_list": "(values, mean_value)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def mean(values):\n return sum(values) / len(values)\n\ndef variance(values, mean_value):\n return sum((x - mean_value) ** 2 for x in values)\n\ndef covariance(x, y, mean_x, mean_y):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055712",
"row_id": 55712,
"seed_ids": "['Qwen2.5-72B-Instruct_113614']"
} | 0.56151 | Filter_55712 | I | [
"mean",
"variance",
"covariance",
"simple_linear_regression",
"predict"
] | 5 | [
[
"simple_linear_regression",
"covariance"
],
[
"simple_linear_regression",
"mean"
],
[
"simple_linear_regression",
"variance"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d7aa36738faaff4abc3f8592a58501709b66d555 | e959a481b8f79c948b6985e80dcf0b77208202f9 | |||
v1.0 | instruct | Filter | Filter_55717_I | Write a script in Python that implements a simple genetic algorithm to find the maximum value of a function within a given range. The function to optimize is \( f(x) = -x^2 + 5x \). The range of x is from 0 to 5. Your script should include mutation, crossover, and selection mechanisms. Initialize a population of 10 ind... | import random
def fitness(x):
"""
Fitness function that returns the value of the function -x^2 + 5x.
"""
return -x**2 + 5*x
def binary_to_decimal(binary):
"""
Convert a binary string to a decimal integer.
"""
return int(binary, 2)
def decimal_to_binary(decimal, length=3):
"""
... | from solution import fitness, binary_to_decimal, decimal_to_binary, initialize_population, selection, crossover, mutate, genetic_algorithm
def test_fitness():
assert fitness(0) == 0
assert fitness(1) == 4
assert fitness(2) == 6
assert fitness(3) == 6
assert fitness(4) == 4
assert fitness(5) == ... | [
{
"docstring": "Fitness function that returns the value of the function -x^2 + 5x.",
"function_declaration": "def fitness(x):",
"function_name": "fitness",
"parameter_list": "(x)"
},
{
"docstring": "Convert a binary string to a decimal integer.",
"function_declaration": "def binary_to_de... | [
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 initialize_population(size, length):\n return [random.choices([0, 1], k=length) for _ in range(size)]\n\ndef binary_to_decimal(binary):\n return int(\"\".join(map(st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055717",
"row_id": 55717,
"seed_ids": "['Qwen2.5-72B-Instruct_113620']"
} | 0.443787 | Filter_55717 | I | [
"fitness",
"binary_to_decimal",
"decimal_to_binary",
"initialize_population",
"selection",
"crossover",
"mutate",
"genetic_algorithm"
] | 8 | [
[
"genetic_algorithm",
"binary_to_decimal"
],
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"fitness"
],
[
"genetic_algorithm",
"initialize_population"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"selection"
],
[... | 8 | [] | false | [] | false | pytest | true | [] | true | 75d972880914208cc868a772112df4ea42402fd4 | 37349e8591a7803cbc81b8f999ef88472bd25fbd | |||
v1.0 | instruct | Filter | Filter_55723_I | Write a Python generator to generate the Fibonacci sequence. The generator should be able to generate values up to a specified number `n`. Additionally, create a function that uses this generator to print the Fibonacci sequence up to `n` in a formatted way. Ensure the code is self-contained and include necessary commen... | def fibonacci_generator(n):
"""
A generator to yield Fibonacci numbers up to `n`.
Parameters:
n (int): The upper limit for the Fibonacci sequence values.
Yields:
int: The next Fibonacci number in the sequence.
"""
a, b = 0, 1
while a <= n:
yield a
... | from solution import fibonacci_generator, print_fibonacci_sequence
import io
import pytest
def test_fibonacci_generator():
assert list(fibonacci_generator(0)) == [0]
assert list(fibonacci_generator(1)) == [0, 1, 1]
assert list(fibonacci_generator(5)) == [0, 1, 1, 2, 3, 5]
assert list(fibonacci_generato... | [
{
"docstring": "A generator to yield Fibonacci numbers up to `n`.\n\nParameters:\n n (int): The upper limit for the Fibonacci sequence values.\n \nYields:\n int: The next Fibonacci number in the sequence.",
"function_declaration": "def fibonacci_generator(n):",
"function_name": "fibonacci_gener... | [
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 Generator to yield Fibonacci sequence values up to n.\n \"\"\"\n a, b = 0, 1\n while a <= n:\n yield a\n a, b = b, a + b\n\nd... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055723",
"row_id": 55723,
"seed_ids": "['Qwen2.5-72B-Instruct_113627']"
} | 0.720642 | Filter_55723 | I | [
"fibonacci_generator",
"print_fibonacci_sequence"
] | 2 | [
[
"print_fibonacci_sequence",
"fibonacci_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0bc72073069aff327aa3d454193927083dc2f174 | 3ea15616cb60a1bfccf88406925f9ec2a7cc1217 | |||
v1.0 | instruct | Filter | Filter_55752_I | Create a program in Python that generates a random 12-digit number and checks if it is a palindrome. A number is a palindrome if it reads the same backward as forward. The program should output the number and a message stating whether it is a palindrome or not. | import random
def generate_random_12_digit_number():
"""
Generates a random 12-digit number.
"""
return random.randint(10**11, 10**12 - 1)
def is_palindrome(n):
"""
Checks if a given number n is a palindrome.
"""
s = str(n)
return s == s[::-1]
def random_12_digit_palindrome_check(... | from solution import generate_random_12_digit_number, is_palindrome, random_12_digit_palindrome_check
def test_generate_random_12_digit_number():
number = generate_random_12_digit_number()
assert 10**11 <= number <= 10**12 - 1
assert len(str(number)) == 12
def test_is_palindrome():
assert is_palindrom... | [
{
"docstring": "Generates a random 12-digit number.",
"function_declaration": "def generate_random_12_digit_number():",
"function_name": "generate_random_12_digit_number",
"parameter_list": "()"
},
{
"docstring": "Checks if a given number n is a palindrome.",
"function_declaration": "def... | [
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_12_digit_number():\n return random.randint(100000000000, 999999999999)\n\ndef is_palindrome(number):\n number_str = str(number)\n return number_st... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055752",
"row_id": 55752,
"seed_ids": "['Qwen2.5-72B-Instruct_113680']"
} | 0.701076 | Filter_55752 | I | [
"generate_random_12_digit_number",
"is_palindrome",
"random_12_digit_palindrome_check"
] | 3 | [
[
"random_12_digit_palindrome_check",
"generate_random_12_digit_number"
],
[
"random_12_digit_palindrome_check",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dd5e76a467b26bbea8c9e381dac4da42515ff677 | 8b4469f7b7628ef74328cdaa4b5605fa6d8e5df1 | |||
v1.0 | instruct | Filter | Filter_55764_I | Can you create a Python script that can monitor and alert on CPU usage? It should send an email if the CPU usage exceeds a certain threshold. | import smtplib
import psutil
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email_alert(subject, message, to_email, from_email, smtp_server, smtp_port, smtp_user, smtp_password):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subje... | import pytest
from unittest.mock import patch, MagicMock
from solution import send_email_alert, monitor_cpu_usage
@patch('smtplib.SMTP')
def test_send_email_alert(mock_smtp):
email_config = {
'subject': 'Test Subject',
'message': 'Test Message',
'to_email': 'test@example.com',
'fro... | [
{
"docstring": null,
"function_declaration": "def send_email_alert(subject, message, to_email, from_email, smtp_server, smtp_port, smtp_user, smtp_password):",
"function_name": "send_email_alert",
"parameter_list": "(subject, message, to_email, from_email, smtp_server, smtp_port, smtp_user, smtp_pas... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport psutil\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email_alert(subject, message, to_email, from_email, smtp_server,... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055764",
"row_id": 55764,
"seed_ids": "['Qwen2.5-72B-Instruct_113706']"
} | 0.605796 | Filter_55764 | I | [
"send_email_alert",
"monitor_cpu_usage"
] | 2 | [
[
"monitor_cpu_usage",
"send_email_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | 6ca01fa985563a25efcaecd608a4a2450592f97b | f6a5c72643b39b497008a25829236374fd91a30f | |||
v1.0 | instruct | Filter | Filter_55774_I | Write a Python function that checks if a number is a prime number and returns `True` if it is, and `False` otherwise. Additionally, the function should validate if the input is a positive integer greater than 1. If the input is invalid, the function should raise a `ValueError` with an appropriate error message. Use thi... | def is_prime(num):
"""
Returns True if 'num' is a prime number, otherwise False.
Raises a ValueError if 'num' is not a positive integer greater than 1.
"""
if not isinstance(num, int) or num <= 1:
raise ValueError("Input must be a positive integer greater than 1.")
if num == 2:
... | from solution import is_prime, filter_primes
def test_is_prime_valid_prime_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(13) == True
assert is_prime(29) == True
def test_is_prime_non_prime_numbers():
assert is_prime(4) == False
... | [
{
"docstring": "Returns True if 'num' is a prime number, otherwise False.\nRaises a ValueError if 'num' is not a positive integer greater than 1.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Filters the list 'number... | [
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(number):\n \"\"\"\n Check if the number is a prime number.\n \n Args:\n number (int): The number to check.\n \n Returns:\n bool: True if the number is a pr... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055774",
"row_id": 55774,
"seed_ids": "['Qwen2.5-72B-Instruct_113719']"
} | 0.73366 | Filter_55774 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dcd62df8572064f539e941c759ce21682658b8d5 | 815a2e373399765a7fcc877b29887af8f47cdddf | |||
v1.0 | instruct | Filter | Filter_55783_I | How can I implement a basic blockchain in Python? I've heard a bit about how blockchains work, but I'm not sure where to start. Can you provide a simple example? | import hashlib
import time
class Block:
def __init__(self, index, previous_hash, timestamp, data, hash):
self.index = index
self.previous_hash = previous_hash
self.timestamp = timestamp
self.data = data
self.hash = hash
def calculate_hash(index, previous_hash, timestamp, da... | from solution import Block, create_genesis_block, create_new_block, calculate_hash
import time
def test_genesis_block():
genesis_block = create_genesis_block()
assert genesis_block.index == 0
assert genesis_block.previous_hash == "0"
assert genesis_block.data == "Genesis Block"
assert calculate_has... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, timestamp, data, previous_hash):\n self.index = index\n self.timestamp = timestamp\n self.data =... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055783",
"row_id": 55783,
"seed_ids": "['Qwen2.5-72B-Instruct_113737']"
} | 0.389259 | Filter_55783 | I | [
"calculate_hash",
"create_genesis_block",
"create_new_block"
] | 3 | [
[
"create_genesis_block",
"calculate_hash"
],
[
"create_new_block",
"calculate_hash"
]
] | 2 | [] | false | [
"Block"
] | true | pytest | true | [] | true | 71b59f4f2a928a3fb1b42a0b9f740c5e5f49ff66 | 39a2030a6f6660771b4ae5568105b17f5d9cd340 | |||
v1.0 | instruct | Filter | Filter_55789_I | Develop a Python script for scraping a website to extract information from HTML tables and save the data into a CSV file. The script should be able to handle different table structures such as nested tables and tables with colspan and rowspan. Additionally, ensure the script checks if the target website's content has b... | import requests
from bs4 import BeautifulSoup
import pandas as pd
import os
import datetime
def fetch_html(url, check_modified=False, last_modified=None):
headers = {}
if check_modified and last_modified:
headers['If-Modified-Since'] = last_modified
response = requests.get(url, headers=headers)
... | import os
from unittest.mock import patch, MagicMock
from solution import fetch_html, parse_html_to_df, save_dfs_to_csv, scrape_website_to_csv
def test_fetch_html_no_modified_check():
url = "http://example.com"
expected_html = "<html><head></head><body><table></table></body></html>"
with patch("reques... | [
{
"docstring": null,
"function_declaration": "def fetch_html(url, check_modified=False, last_modified=None):",
"function_name": "fetch_html",
"parameter_list": "(url, check_modified=False, last_modified=None)"
},
{
"docstring": null,
"function_declaration": "def parse_html_to_df(html):",... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom bs4 import BeautifulSoup\nimport pandas as pd\nimport os\nimport datetime\n\ndef fetch_html(url, check_modified=False, last_modified=None):\n headers = {}\n if chec... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00055789",
"row_id": 55789,
"seed_ids": "['Qwen2.5-72B-Instruct_113745']"
} | 0.739669 | Filter_55789 | I | [
"fetch_html",
"parse_html_to_df",
"save_dfs_to_csv",
"scrape_website_to_csv"
] | 4 | [
[
"scrape_website_to_csv",
"fetch_html"
],
[
"scrape_website_to_csv",
"parse_html_to_df"
],
[
"scrape_website_to_csv",
"save_dfs_to_csv"
]
] | 3 | [] | false | [] | false | pytest | true | [
"bs4",
"pandas",
"requests"
] | false | 54d39fd004fb5648cb560fa638aa6447845c014f | 565007b8f164da15ad87e2795eac4519aa956ec0 | |||
v1.0 | instruct | Filter | Filter_55810_I | Write a Python function to generate a list of all prime numbers between two given numbers, inclusive. The function should take two arguments, `start` and `end`, and return a list of prime numbers in that range. Also, write a simple check function to validate the correctness of your solution using predetermined data poi... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import generate_primes
def test_generate_primes_basic_range():
assert generate_primes(10, 20) == [11, 13, 17, 19]
def test_generate_primes_single_prime():
assert generate_primes(17, 17) == [17]
def test_generate_primes_no_primes():
assert generate_primes(8, 10) == []
def test_generate_prim... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of all prime numbers between `start` and `end`, inclusive.",
"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(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055810",
"row_id": 55810,
"seed_ids": "['Qwen2.5-72B-Instruct_113780']"
} | 0.609901 | Filter_55810 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2d81b5fe785ee38a336f7a7e2639f3e03a2a3806 | 04dc4a23b6bc24eed3d1b1a04ba816e9c939b2a6 | |||
v1.0 | instruct | Filter | Filter_55822_I | How can I write a function in Python that converts a list of integers into a human-readable ordinal format, such as "1st", "2nd", "3rd", etc.? | def ordinal_suffix(n):
"""
Returns the ordinal suffix for a given integer n.
"""
if 11 <= n % 100 <= 13:
suffix = "th"
else:
suffix = {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
return suffix
def to_ordinal(integers):
"""
Converts a list of integers to a list of their ... | from solution import to_ordinal
def test_single_digit_numbers():
assert to_ordinal([1, 2, 3, 4]) == ["1st", "2nd", "3rd", "4th"]
assert to_ordinal([5, 6, 7, 8, 9]) == ["5th", "6th", "7th", "8th", "9th"]
def test_teen_numbers():
assert to_ordinal([11, 12, 13, 14, 15]) == ["11th", "12th", "13th", "14th", "1... | [
{
"docstring": "Returns the ordinal suffix for a given integer n.",
"function_declaration": "def ordinal_suffix(n):",
"function_name": "ordinal_suffix",
"parameter_list": "(n)"
},
{
"docstring": "Converts a list of integers to a list of their ordinal string representation.",
"function_de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def int_to_ordinal(n):\n \"\"\"\n Converts an integer to its ordinal representation as a string.\n e.g., 1 -> '1st', 2 -> '2nd', 3 -> '3rd', 4 -> '4th', etc.\n \"\"\"\n if 10 <=... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00055822",
"row_id": 55822,
"seed_ids": "['Qwen2.5-72B-Instruct_113800']"
} | 0.514352 | Filter_55822 | I | [
"ordinal_suffix",
"to_ordinal"
] | 2 | [
[
"to_ordinal",
"ordinal_suffix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 69f416b594afc60d9440ef84b810a5bd50ce9465 | bb8d85700836b4189a06eed773a3819557b671eb | |||
v1.0 | instruct | Filter | Filter_55826_I | Write a Python function that implements the backpropagation process for a simple feedforward neural network. The function should be self-contained, with all necessary imports and explanations included in the comments. The function should perform the backpropagation process and update the weights of the network based on... | import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input.
"""
return 1 / (1 + np.exp(-x))
def sigmoid_derivative(x):
"""
Compute the derivative of the sigmoid function.
"""
return x * (1 - x)
def backpropagation(X, y, learning_rate, weights):
"""
Perfo... | from solution import backpropagation, sigmoid, sigmoid_derivative
import numpy as np
def test_forward_pass():
X = np.array([[0.1, 0.2]])
weights = {
'hidden': np.array([[0.1, 0.2], [0.3, 0.4]]),
'output': np.array([[0.5], [0.6]])
}
hidden_input = np.dot(X, weights['hidden'])
hi... | [
{
"docstring": "Compute the sigmoid function for the input.",
"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):",
"fun... | [
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 sigmoid(x):\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n return x * (1 - x)\n\ndef backpropagation(X, y, weights_input_hidden, weights_hidden_o... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00055826",
"row_id": 55826,
"seed_ids": "['Qwen2.5-72B-Instruct_113804']"
} | 0.446213 | Filter_55826 | I | [
"sigmoid",
"sigmoid_derivative",
"backpropagation"
] | 3 | [
[
"backpropagation",
"sigmoid"
],
[
"backpropagation",
"sigmoid_derivative"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 78688bbdeb8095debf02b5ec812183da445f1a06 | ef5a31cf89d61a64c41c003f2107559c1ae85d98 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.