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_51141_I
I'm working on a project that requires me to analyze large text files, and I've decided to use Python for this task. Specifically, I'm interested in creating a Python script that can read a large text file, process it line by line, and then write the processed data into a new file. Can you guide me on how to achieve th...
def process_line(line): """ Processes a single line of text and returns the processed line. This is a placeholder function and should be adapted to the specific processing needed. """ # Example processing: stripping whitespace and converting to uppercase return line.strip().upper() def read_and...
import os # Importing the functions from the solution from solution import process_line, read_and_process_file def test_process_line(): assert process_line(" hello ") == "HELLO" assert process_line("World") == "WORLD" assert process_line("Python Programming") == "PYTHON PROGRAMMING" def test_read_and_p...
[ { "docstring": "Processes a single line of text and returns the processed line.\nThis is a placeholder function and should be adapted to the specific processing needed.", "function_declaration": "def process_line(line):", "function_name": "process_line", "parameter_list": "(line)" }, { "docs...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_line(line):\n \"\"\"\n Process a single line of text.\n Modify this function based on your processing needs.\n \"\"\"\n # Example processing: make the text uppercase...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051141", "row_id": 51141, "seed_ids": "['Qwen2.5-72B-Instruct_106152']" }
0.476103
Filter_51141
I
[ "process_line", "read_and_process_file" ]
2
[ [ "read_and_process_file", "process_line" ] ]
1
[]
false
[]
false
pytest
true
[]
true
90a2d7c99bc93cbbef38bad29b49b7f963e765af
9412d0661ab459431e9f644a2c0293b47c4a69bf
v1.0
instruct
Filter
Filter_51173_I
I'm trying to create a basic machine learning model to predict stock prices using Python. What are the essential steps I should follow to get started?
import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error def prepare_data(data, feature_cols, target_col): """ Prepares the data for training by splitting it into features and tar...
from solution import prepare_data, predict_stock_prices import pandas as pd import numpy as np def test_prepare_data(): data = pd.DataFrame({ 'feature1': [1, 2, 3, 4, 5], 'feature2': [10, 20, 30, 40, 50], 'target': [100, 200, 300, 400, 500] }) feature_cols = ['feature1', 'feature2']...
[ { "docstring": "Prepares the data for training by splitting it into features and target.\nAlso splits into training and testing datasets.\n\nArgs:\ndata (DataFrame): The dataframe containing the data.\nfeature_cols (list): List of column names to be used as features.\ntarget_col (str): The column name to be use...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_stock_prediction_model():\n \"\"\"\n Outline the essential steps to create a basic machine learning model \n to predict stock prices.\n \"\"\"\n steps = [\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051173", "row_id": 51173, "seed_ids": "['Qwen2.5-72B-Instruct_106197']" }
0.443206
Filter_51173
I
[ "prepare_data", "predict_stock_prices" ]
2
[ [ "predict_stock_prices", "prepare_data" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "pandas", "sklearn" ]
false
0703a94adb1b5ad80a2faeec41c885e05ee9d829
19ce7f7fe0bc6fa75d5ced49abeb237f222a1dbc
v1.0
instruct
Filter
Filter_51187_I
Write a program in Python that generates a list of the first 10 prime numbers. Make sure to include comments that explain your code.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, generate_first_n_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_generate_f...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of the first n prime numbers.", "function_declaration": "def generate_first_n_primes(n):", "function_name"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is 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": "00051187", "row_id": 51187, "seed_ids": "['Qwen2.5-72B-Instruct_106224']" }
0.531989
Filter_51187
I
[ "is_prime", "generate_first_n_primes" ]
2
[ [ "generate_first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86aec2ef4b6da1bab988ef45162c66b47a76042a
2f6b4aedd6132ba10095fd95fda2aafdc0324479
v1.0
instruct
Filter
Filter_51228_I
I want to write a script to simulate the diffusion of heat in a 2D plate over time using the finite difference method. How can I do this in Python? I would like the simulation to consider an initial temperature distribution and boundary conditions. Also, I want to visualize the temperature distribution at different tim...
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation def initialize_plate(N, initial_temp): """ Initializes the plate with a given temperature distribution. Parameters: N (int): The size of the plate (N x N). initial_temp (function): A function that...
from solution import initialize_plate, apply_boundary_conditions, update_temperature, simulate_heat_diffusion import numpy as np def test_initialize_plate(): initial_temp = lambda i, j: 100 if (i == 5 and j == 5) else 0 plate = initialize_plate(10, initial_temp) assert plate[5, 5] == 100 assert plate[0...
[ { "docstring": "Initializes the plate with a given temperature distribution.\n\nParameters:\nN (int): The size of the plate (N x N).\ninitial_temp (function): A function that provides the initial temperature distribution.\n\nReturns:\nnp.ndarray: The initialized temperature distribution.", "function_declara...
[ 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_heat_diffusion(initial_temp, alpha, delta_t, delta_x, steps, boundary_conditions):\n \"\"\"\n Simulates the diffusion ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051228", "row_id": 51228, "seed_ids": "['Qwen2.5-72B-Instruct_106289']" }
0.444971
Filter_51228
I
[ "initialize_plate", "apply_boundary_conditions", "update_temperature", "simulate_heat_diffusion", "visualize_heat_diffusion" ]
5
[ [ "simulate_heat_diffusion", "apply_boundary_conditions" ], [ "simulate_heat_diffusion", "initialize_plate" ], [ "simulate_heat_diffusion", "update_temperature" ], [ "visualize_heat_diffusion", "apply_boundary_conditions" ], [ "visualize_heat_diffusion", "init...
6
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
0a0cd208b49b091dc0a682ed53c6abe3aa5b0ac3
cffefb3d0b52d7fb8b691225bb8baa9684557455
v1.0
instruct
Filter
Filter_51248_I
I need to create a Python script to monitor the disk usage of my server and alert me if it exceeds 80%. Can you help me with that?
import shutil import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def get_disk_usage(): """ Returns the disk usage percentage of the root directory. """ total, used, free = shutil.disk_usage("/") return used / total * 100 def send_alert_email(disk_usa...
import pytest from unittest.mock import patch, MagicMock from solution import get_disk_usage, send_alert_email, monitor_disk_usage @patch("solution.shutil.disk_usage") def test_get_disk_usage(mock_disk_usage): # Set up the mock return value for shutil.disk_usage mock_disk_usage.return_value = (100, 80, 20) # ...
[ { "docstring": "Returns the disk usage percentage of the root directory.", "function_declaration": "def get_disk_usage():", "function_name": "get_disk_usage", "parameter_list": "()" }, { "docstring": "Sends an email alerting that the disk usage has exceeded the threshold.", "function_dec...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import shutil\nimport smtplib\nfrom email.message import EmailMessage\n\ndef send_alert_email(disk_usage):\n \"\"\"\n Send an alert email about high disk usage.\n \"\"\"\n msg = Em...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051248", "row_id": 51248, "seed_ids": "['Qwen2.5-72B-Instruct_106327']" }
0.479892
Filter_51248
I
[ "get_disk_usage", "send_alert_email", "monitor_disk_usage" ]
3
[ [ "monitor_disk_usage", "get_disk_usage" ], [ "monitor_disk_usage", "send_alert_email" ] ]
2
[]
false
[]
false
pytest
true
[]
true
902bf90e3742edb6ef647d6ef1dda9ccad49397f
ece773fa5aa4d4167599f5db10af3e4ae76f9086
v1.0
instruct
Filter
Filter_51281_I
Write a Python script that converts a given temperature from Celsius to Fahrenheit and vice versa. The user should be able to specify which conversion they want to perform. The script should be user-friendly, allowing the user to input the temperature and the desired conversion type. It should also handle invalid input...
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 convert_temperature(temp, conversion_type): """ Converts tem...
from solution import convert_temperature, celsius_to_fahrenheit, fahrenheit_to_celsius def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "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 Convert Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Conv...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051281", "row_id": 51281, "seed_ids": "['Qwen2.5-72B-Instruct_106383']" }
0.442406
Filter_51281
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
365e124c69686d6a58cb83c24594436d4bb8f7ee
d825518d3097422862be98e0906e0cfd0b7c3e2a
v1.0
instruct
Filter
Filter_51305_I
Can you assist me with a basic Python script that checks if a specific service is running on a Linux machine? I want to use this script to monitor a service called `httpd` and get a notification if it's not running.
import os import smtplib from email.mime.text import MIMEText def check_service(service_name): """ Check if the specified service is running on a Linux machine. Args: service_name (str): The name of the service to check. Returns: bool: True if the service is running, False otherwise. ...
from solution import check_service, notify_admin import pytest import os from unittest.mock import patch @patch('os.system') def test_check_service_running(mock_system): mock_system.return_value = 0 assert check_service('httpd') == True @patch('os.system') def test_check_service_not_running(mock_system): ...
[ { "docstring": "Check if the specified service is running on a Linux machine.\n\nArgs:\nservice_name (str): The name of the service to check.\n\nReturns:\nbool: True if the service is running, False otherwise.", "function_declaration": "def check_service(service_name):", "function_name": "check_service"...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import subprocess\n\ndef is_service_running(service_name):\n \"\"\"\n Checks if a specific service is running on a Linux machine.\n :param service_name: Name of the service to check.\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051305", "row_id": 51305, "seed_ids": "['Qwen2.5-72B-Instruct_106418']" }
0.495321
Filter_51305
I
[ "check_service", "notify_admin" ]
2
[ [ "notify_admin", "check_service" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c673f77c4c9f13342c7bfb60454a127d50321343
4e1059fb85100010b7d25d99107e8fd8e55264f3
v1.0
instruct
Filter
Filter_51323_I
Can you create a function in Python that takes a list of integers and returns a new list containing only the integers that are palindromes? A number is a palindrome if it reads the same backward as forward, like 121 or 1331. The function should be efficient and concise.
def is_palindrome(n): """Helper function to check if a number is a palindrome.""" s = str(n) return s == s[::-1] def filter_palindromes(numbers): """ Returns a list of palindrome numbers from the input list. Parameters: numbers (list of int): List of integers to be filtered. Retur...
from solution import filter_palindromes, is_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1331) == True assert is_palindrome(1) == True assert is_palindrome(0) == True assert is_palindrome(-121) == False # negativ...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns a list of palindrome numbers from the input list.\n\nParameters:\nnumbers (list of int...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n str_n = str(n)\n return str_n == str_n[::-1]\n\ndef filter_palindromes(nums):\n \"\"\"\n Re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051323", "row_id": 51323, "seed_ids": "['Qwen2.5-72B-Instruct_106447']" }
0.695606
Filter_51323
I
[ "is_palindrome", "filter_palindromes" ]
2
[ [ "filter_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bde5c0c3e25eb46ad54f47705ef99606fdb6559c
a4742ba32dd9d288164bc7d44518c2d08a72f90b
v1.0
instruct
Filter
Filter_51326_I
Design a Python program that simulates a simple version of a game similar to "Rock, Paper, Scissors." In this game, the computer randomly selects one of the options (Rock, Paper, Scissors), and the user inputs their choice. The program should then determine the winner based on the classic rules of the game and display ...
import random def get_computer_choice(): choices = ['Rock', 'Paper', 'Scissors'] return random.choice(choices) def determine_winner(user_choice, computer_choice): if user_choice == computer_choice: return "It's a tie!" elif (user_choice == 'Rock' and computer_choice == 'Scissors') or \ ...
from solution import get_computer_choice, determine_winner, play_game def test_get_computer_choice(): choice = get_computer_choice() assert choice in ['Rock', 'Paper', 'Scissors'] def test_determine_winner(): assert determine_winner('Rock', 'Scissors') == 'You win!' assert determine_winner('Paper', 'R...
[ { "docstring": null, "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def determine_winner(user_choice, computer_choice):", "function_name": "determine_winner", "p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n choices = [\"Rock\", \"Paper\", \"Scissors\"]\n return random.choice(choices)\n\ndef get_winner(user_choice, computer_choice):\n if user_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051326", "row_id": 51326, "seed_ids": "['Qwen2.5-72B-Instruct_106451']" }
0.523701
Filter_51326
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1203e3c2764c6e3e24bbd1b21fc99caaed91da2d
4059ffc6263b70efdf258043a40b481398ede8da
v1.0
instruct
Filter
Filter_51373_I
Create a Python script that takes a directory path as input and prints out the size of the directory in a human-readable format (e.g., KB, MB, GB). The script should handle any errors gracefully, such as if the directory does not exist or if it is a file instead of a directory.
import os def get_directory_size(path): """Get the size of a directory in bytes.""" total_size = 0 if not os.path.exists(path): raise FileNotFoundError(f"The path '{path}' does not exist.") if not os.path.isdir(path): raise NotADirectoryError(f"The path '{path}' is not a directory.") ...
import os import tempfile from solution import get_human_readable_directory_size, get_directory_size, size_to_human_readable import pytest def test_get_directory_size(): # Create a temporary directory with some files with tempfile.TemporaryDirectory() as tmpdirname: tmpfile1 = os.path.join(tmpdirname, ...
[ { "docstring": "Get the size of a directory in bytes.", "function_declaration": "def get_directory_size(path):", "function_name": "get_directory_size", "parameter_list": "(path)" }, { "docstring": "Convert size in bytes to a human-readable format.", "function_declaration": "def size_to_h...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef get_size_format(size):\n \"\"\"Convert size in bytes to a human readable string (KB, MB, GB, etc.)\"\"\"\n for unit in ['B', 'KB', 'MB', 'GB', 'TB']:\n if size < ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051373", "row_id": 51373, "seed_ids": "['Qwen2.5-72B-Instruct_106540']" }
0.597665
Filter_51373
I
[ "get_directory_size", "size_to_human_readable", "get_human_readable_directory_size" ]
3
[ [ "get_human_readable_directory_size", "get_directory_size" ], [ "get_human_readable_directory_size", "size_to_human_readable" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9377a83e71c9d0047b1cd0ca61cb4ed04f6dc466
4697251b64bbcce0f051a57ce5eba1774349c56f
v1.0
instruct
Filter
Filter_51392_I
Create a Python program that prompts the user to enter a number and then checks whether the number is a prime number. If the number is a prime, print "The number is a prime number." Otherwise, print "The number is not a prime number." Make sure to handle input validation to ensure the user enters a valid integer.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i...
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(13) == True assert is_prime(16) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert i...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prompts the user to enter a number and checks whether the number is a prime.", "function_declaration": "d...
[ 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 the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if nu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051392", "row_id": 51392, "seed_ids": "['Qwen2.5-72B-Instruct_106565']" }
0.737503
Filter_51392
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d241e083bdb41f464364b61235b6c779dda52d60
20fb4247c963ed1c0e0b7bdbc52b94c54003b37b
v1.0
instruct
Filter
Filter_51404_I
Create a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. The function should be optimized for performance as it may need to handle large lists. Additionally, provide a piece of erroneous code that attempts to solve the problem but fails due ...
import math def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = math.isqrt(n) for divisor in range(3, max_divisor + 1, 2): if n % divisor == 0: return False return True def filter_primes(numbers):...
from solution import filter_primes def test_prime_numbers(): assert filter_primes([2, 3, 4, 5, 10, 11, 12, 13, 17, 19]) == [2, 3, 5, 11, 13, 17, 19] def test_no_primes(): assert filter_primes([4, 6, 8, 10, 12]) == [] def test_mixed_numbers(): assert filter_primes([15, 23, 24, 29, 35]) == [23, 29] ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list.", "function_declaration": "def filter_primes(numbers):", "function_name": "fi...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051404", "row_id": 51404, "seed_ids": "['Qwen2.5-72B-Instruct_106585']" }
0.563243
Filter_51404
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
136b659f3bb98a45940844c907b515de79d0d747
60a179b48a427c0face5fefb36673efed00711c2
v1.0
instruct
Filter
Filter_51406_I
Create a Python program to find all prime numbers up to a given number n. The program should also check if a given number m is prime and return a message indicating whether m is prime or not.
def is_prime(num): """ Checks if a given number is prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def primes_up_to(n): """ Returns a list of all prime numbers up to n. """ primes ...
from solution import is_prime, primes_up_to, check_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False def test_primes_up_to(): assert primes_up_to(1...
[ { "docstring": "Checks if a given number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers up to n.", "function_declaration": "def primes_up_to(n):", "function_name":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051406", "row_id": 51406, "seed_ids": "['Qwen2.5-72B-Instruct_106588']" }
0.741894
Filter_51406
I
[ "is_prime", "primes_up_to", "check_prime" ]
3
[ [ "check_prime", "is_prime" ], [ "primes_up_to", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2d4383ad37fb265d1c5ca51bd1ef9c5fb42638f1
cd6aa7a1312cce7a5ecbe568fb7ac307ddee2831
v1.0
instruct
Filter
Filter_51408_I
Write a Python program that implements a simple version of a genetic algorithm to find an optimal solution for a given function. The function to optimize is f(x) = x^2, where x is an integer and -10 <= x <= 10. The genetic algorithm should include the following components: initialization of a population, selection, cro...
import random def initialize_population(size, xmin, xmax): """ Initializes a population of given size with random integers within [xmin, xmax]. """ population = [random.randint(xmin, xmax) for _ in range(size)] return population def fitness(x): """ Fitness function to evaluate the individu...
from solution import initialize_population, fitness, select, crossover, mutate, genetic_algorithm def test_initialize_population(): population = initialize_population(10, -10, 10) assert len(population) == 10 assert all(-10 <= x <= 10 for x in population) def test_fitness(): assert fitness(0) == 0 ...
[ { "docstring": "Initializes a population of given size with random integers within [xmin, xmax].", "function_declaration": "def initialize_population(size, xmin, xmax):", "function_name": "initialize_population", "parameter_list": "(size, xmin, xmax)" }, { "docstring": "Fitness function to e...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef initialize_population(size):\n \"\"\"\n Initialize a population with given size. Each individual is a random integer between -10 and 10.\n \"\"\"\n return [ran...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051408", "row_id": 51408, "seed_ids": "['Qwen2.5-72B-Instruct_106592']" }
0.427928
Filter_51408
I
[ "initialize_population", "fitness", "select", "crossover", "mutate", "genetic_algorithm" ]
6
[ [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "initialize_population" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "select" ], [ "select", "fitness" ] ]
5
[]
false
[]
false
pytest
true
[]
true
7842540b7db16ba5b42c484dcf294aa8f49c7f7b
7bb561998234a4186a4447dac306a750528c507f
v1.0
instruct
Filter
Filter_51412_I
Create a Python script that can be used to check the disk usage of the system and notify the user if the disk usage exceeds a certain threshold. The script should also include a function to display the total, used, and free disk space in a human-readable format (e.g., GB or TB). Make sure to include comments and docume...
import shutil import os def check_disk_usage(threshold): """ Checks the disk usage of the system and return True if the disk usage exceeds the given threshold, otherwise return False. Parameters: threshold (float): The percentage threshold to check against. Returns: bool: True if the disk...
from solution import check_disk_usage, human_readable_size, display_disk_info import shutil def test_check_disk_usage(monkeypatch): # Mocking shutil.disk_usage to return controlled values def mock_disk_usage(path): return (100, 85, 15) # 85% used monkeypatch.setattr(shutil, 'disk_usage', mock_disk...
[ { "docstring": "Checks the disk usage of the system and return True if the disk usage exceeds\nthe given threshold, otherwise return False.\n\nParameters:\nthreshold (float): The percentage threshold to check against.\n\nReturns:\nbool: True if the disk usage exceeds the threshold, else False.", "function_d...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import shutil\nimport psutil\n\ndef get_disk_usage(path='/'):\n \"\"\"\n Returns a dictionary containing the total, used, and free disk space in bytes.\n \"\"\"\n usage = shutil.di...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051412", "row_id": 51412, "seed_ids": "['Qwen2.5-72B-Instruct_106599']" }
0.548914
Filter_51412
I
[ "check_disk_usage", "human_readable_size", "display_disk_info" ]
3
[ [ "display_disk_info", "human_readable_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1da08b06a514c3480a842e6f51c897131def5feb
f4745225934ca431b986c6a915db3c3f0d3b79b8
v1.0
instruct
Filter
Filter_51438_I
Can you help me with a Python code to print all the prime numbers between two given numbers? Let's say from 10 to 50.
def is_prime(n): """ 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 False i += 6 ...
from solution import is_prime, prime_numbers_between def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True def test_prime_numbers_between(): assert prime_num...
[ { "docstring": "Checks if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between start and end (inclusive).", "function_declaration": "def prime_number...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051438", "row_id": 51438, "seed_ids": "['Qwen2.5-72B-Instruct_106643']" }
0.628319
Filter_51438
I
[ "is_prime", "prime_numbers_between" ]
2
[ [ "prime_numbers_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70cdd413b3c9d70d2e354111c7f0a055a400d962
3a13a1d867f5e0b2f33997db4dd48726b1a5c801
v1.0
instruct
Filter
Filter_51439_I
Can you help me write a program in Python that calculates the sum of the first 100 prime numbers? I'm trying to improve my coding skills and I think this would be a good challenge.
def is_prime(n): """ Checks if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def sum_of_first_100_p...
from solution import is_prime, sum_of_first_100_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False def test_sum_of_first_100_primes(): assert sum_of_first_100_primes() == 24133
[ { "docstring": "Checks if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculates the sum of the first 100 prime numbers.", "function_declaration": "def sum_of_first_100_primes():", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n re...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00051439", "row_id": 51439, "seed_ids": "['Qwen2.5-72B-Instruct_106644']" }
0.572923
Filter_51439
I
[ "is_prime", "sum_of_first_100_primes" ]
2
[ [ "sum_of_first_100_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e341b29a4463482de56daf7a568cba8c045f56b0
e5f10af7ee2a2c0387213290f0b39077d439a54b
v1.0
instruct
Filter
Filter_51476_I
Write a Python program that generates the first 100 numbers of the Fibonacci sequence and prints them to the console. Additionally, the program should efficiently handle large numbers and optimize for performance. Consider using a generator to create the sequence.
def fibonacci_generator(limit): """ Generates the first 'limit' Fibonacci numbers. """ a, b = 0, 1 for _ in range(limit): yield a a, b = b, a + b def generate_fibonacci_sequence(limit=100): """ Generates and returns the first 'limit' Fibonacci numbers as a list. """ ...
from solution import generate_fibonacci_sequence def test_fibonacci_sequence_length(): assert len(generate_fibonacci_sequence(100)) == 100 def test_first_10_fibonacci_numbers(): expected_result = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] assert generate_fibonacci_sequence(10) == expected_result def test_large_fi...
[ { "docstring": "Generates the first 'limit' Fibonacci numbers.", "function_declaration": "def fibonacci_generator(limit):", "function_name": "fibonacci_generator", "parameter_list": "(limit)" }, { "docstring": "Generates and returns the first 'limit' Fibonacci numbers as a list.", "funct...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Generates the first n numbers of the Fibonacci sequence.\n \n :param n: The number of Fibonacci numbers to generate.\n :return: A generator...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051476", "row_id": 51476, "seed_ids": "['Qwen2.5-72B-Instruct_106704']" }
0.685467
Filter_51476
I
[ "fibonacci_generator", "generate_fibonacci_sequence" ]
2
[ [ "generate_fibonacci_sequence", "fibonacci_generator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b82a780728852500dc446b05157cffa7970f03b
b19111cb821208b9699eaeb94887d48378068a83
v1.0
instruct
Filter
Filter_51498_I
Use Python to illustrate the Heapsort algorithm. Please include comments to explain the steps.
def heapify(arr, n, i): """ Converts a subtree rooted with node i into a heap. """ largest = i # Initialize largest as root left = 2 * i + 1 # left = 2*i + 1 right = 2 * i + 2 # right = 2*i + 2 # See if left child of root exists and is greater than root if left < n and arr[large...
from solution import heap_sort def test_heap_sort_empty(): assert heap_sort([]) == [] def test_heap_sort_single_element(): assert heap_sort([1]) == [1] def test_heap_sort_sorted_array(): assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_heap_sort_reverse_sorted_array(): assert heap_sort(...
[ { "docstring": "Converts a subtree rooted with node i into a heap.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Main function to sort an array using heapsort algorithm.", "function_declaration": "def h...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i):\n \"\"\"\n Function to heapify the subtree rooted at index i.\n n is the size of the heap.\n \"\"\"\n largest = i # Initialize largest as root\n left...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051498", "row_id": 51498, "seed_ids": "['Qwen2.5-72B-Instruct_106734']" }
0.649947
Filter_51498
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4409daeabd4bcae05a9004d26b6213c0e76b34a6
81b83d7323df256b2226a85447ac9a0fd24c9f93
v1.0
instruct
Filter
Filter_51511_I
write a python code to implement a simple game of rock paper scissors. The game should be able to handle a single round where the user inputs their choice and the computer randomly selects its choice. The program should then determine the winner based on the rules of the game and print the result.
import random def get_computer_choice(): """ Returns the computer's choice randomly. """ choices = ["rock", "paper", "scissors"] return random.choice(choices) def determine_winner(user_choice, computer_choice): """ Determines the winner of the rock-paper-scissors game. Returns 'Us...
import pytest from solution import determine_winner, play_round def test_determine_winner_user_wins(): assert determine_winner("rock", "scissors") == "User" assert determine_winner("paper", "rock") == "User" assert determine_winner("scissors", "paper") == "User" def test_determine_winner_computer_wins(): ...
[ { "docstring": "Returns the computer's choice randomly.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner of the rock-paper-scissors game.\n\nReturns 'User' if the user wins, 'Comput...
[ 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 rock_paper_scissors(user_choice):\n choices = [\"rock\", \"paper\", \"scissors\"]\n \n if user_choice not in choices:\n return \"Invalid choice\"\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051511", "row_id": 51511, "seed_ids": "['Qwen2.5-72B-Instruct_106756']" }
0.438805
Filter_51511
I
[ "get_computer_choice", "determine_winner", "play_round" ]
3
[ [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ce543be2b8f9abaf1239cf8fdf035a55ac9e3e46
e1afd7498bae8d04a35c54a190f250bebe77201b
v1.0
instruct
Filter
Filter_51537_I
Can you please write a python program to generate the Fibonacci series till a given number of terms using recursion? Also, please explain how the program works.
def fibonacci(n): """ Returns the nth Fibonacci number using recursion. """ if n <= 0: raise ValueError("Number of terms must be a positive integer.") elif n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def fibonacci_s...
from solution import fibonacci, fibonacci_series def test_fibonacci_base_cases(): assert fibonacci(1) == 0 assert fibonacci(2) == 1 def test_fibonacci_regular_cases(): assert fibonacci(3) == 1 assert fibonacci(4) == 2 assert fibonacci(5) == 3 assert fibonacci(6) == 5 def test_fibonacci_invali...
[ { "docstring": "Returns the nth Fibonacci number using recursion.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Generates a list containing the Fibonacci series up to the given number of terms.", "function_declarat...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the Fibonacci series till n terms.\n \"\"\"\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051537", "row_id": 51537, "seed_ids": "['Qwen2.5-72B-Instruct_106795']" }
0.67306
Filter_51537
I
[ "fibonacci", "fibonacci_series" ]
2
[ [ "fibonacci_series", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
daa8cb39fa3b0067b740b9b534b3c1f78a2ce6d6
dd0d60a6abfc043b17a1bfa791af2d0a564a481e
v1.0
instruct
Filter
Filter_51555_I
How can I create a Python program that automatically sends emails to a list of recipients with personalized greetings?
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def send_email(sender_email, sender_password, recipient_email, subject, body): """ Sends an email from the sender to a recipient with the given subject and body. """ # Set up the server details smtp_s...
import pytest from unittest.mock import patch, call # We assume that 'send_email' and 'send_greetings' are imported from solution def test_send_email(): with patch('smtplib.SMTP') as mock_smtp: mock_server = mock_smtp.return_value send_email('sender@example.com', 'password', 'recipient@example.com...
[ { "docstring": "Sends an email from the sender to a recipient with the given subject and body.", "function_declaration": "def send_email(sender_email, sender_password, recipient_email, subject, body):", "function_name": "send_email", "parameter_list": "(sender_email, sender_password, recipient_email...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email(smtp_server, port, sender_email, sender_password, recipients):\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051555", "row_id": 51555, "seed_ids": "['Qwen2.5-72B-Instruct_106824']" }
0.492863
Filter_51555
I
[ "send_email", "send_greetings" ]
2
[ [ "send_greetings", "send_email" ] ]
1
[]
false
[]
false
pytest
false
[]
true
25c6390ba2c85a26ebd9766d33365aa6683f7cce
3e973b59efe7a9ac04ea65aaa0050a96f2f08189
v1.0
instruct
Filter
Filter_51592_I
How can I create a simple Python script to monitor my website's uptime and send me an email if the site goes down?
import requests import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def check_website(url): """ Checks the status of the website. """ try: response = requests.get(url) if response.status_code == 200: return True except reque...
import pytest import requests from requests.models import Response from unittest.mock import patch from solution import check_website, send_alert_email, monitor_website @patch('requests.get') def test_check_website_up(mock_get): mock_response = Response() mock_response.status_code = 200 mock_get.return_val...
[ { "docstring": "Checks the status of the website.", "function_declaration": "def check_website(url):", "function_name": "check_website", "parameter_list": "(url)" }, { "docstring": "Sends an email alert.", "function_declaration": "def send_alert_email(subject, body, from_email, to_email,...
[ 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 requests\nfrom time import sleep\n\ndef send_email(subject, message, from_addr, to_addrs, smtp_server, smtp_port, login, password):\n \"\"\"\n Sends an email with ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051592", "row_id": 51592, "seed_ids": "['Qwen2.5-72B-Instruct_106878']" }
0.464717
Filter_51592
I
[ "check_website", "send_alert_email", "monitor_website" ]
3
[ [ "monitor_website", "check_website" ], [ "monitor_website", "send_alert_email" ] ]
2
[]
false
[]
false
pytest
true
[ "requests" ]
false
662731a77d1a15af30e5b3477e47531b12f068f9
f5ac5acafeea8be2a881d34cc5e0172681f3b74f
v1.0
instruct
Filter
Filter_51606_I
Write a Python function to filter out prime numbers from a given list of integers. The function should accept a list of integers and return a list of only the prime numbers found in the input list. Use a list comprehension in your solution.
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0: return False return True def filter_primes(nums...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13, 17]) == [2, 3, 5, 7, 11, 13, 17] def test_filter_primes_with_no_primes(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Filters out and returns only the prime numbers from the input list.", "function_declaration": "def filter_primes(nums):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051606", "row_id": 51606, "seed_ids": "['Qwen2.5-72B-Instruct_106894']" }
0.646265
Filter_51606
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
49730aa6a5bc52edcce5f22446d8ca3b3f408c27
7debca54f6833339e2ca42ffa8d953d983e266d0
v1.0
instruct
Filter
Filter_51636_I
Create a Python script that simulates a simple dice rolling game. The game should allow a player to roll a six-sided die multiple times. After each roll, the script should print the result. The player can choose to roll the die again or stop the game. At the end of the game, the script should display the highest and lo...
import random def roll_dice(): """ Simulates rolling a six-sided die and returns the result. """ return random.randint(1, 6) def play_dice_game(): """ Manages the dice rolling game flow. """ rolls = [] while True: roll = roll_dice() rolls.append(roll) print(...
from solution import roll_dice, play_dice_game def test_roll_dice(): results = [roll_dice() for _ in range(100)] assert all(1 <= result <= 6 for result in results) def test_play_dice_game(monkeypatch): inputs = iter(['y', 'y', 'n']) monkeypatch.setattr('builtins.input', lambda _: next(inputs)) ...
[ { "docstring": "Simulates rolling a six-sided die and returns the result.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Manages the dice rolling game flow.", "function_declaration": "def play_dice_game():", "func...
[ 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 \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_game():\n \"\"\"\n M...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051636", "row_id": 51636, "seed_ids": "['Qwen2.5-72B-Instruct_106937']" }
0.55954
Filter_51636
I
[ "roll_dice", "play_dice_game" ]
2
[ [ "play_dice_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2736fac46af9d18bbed04ff228bcd383f0c3621a
9c9b47fbe7b636ac455cd1af8ac4d651033cb27f
v1.0
instruct
Filter
Filter_51650_I
Design a Python program that creates a set of circles inside a square. The square will have a side length of 10 units. The circles should be placed such that their centers are randomly located inside the square, and their radii should be randomly chosen between 0.5 and 1.5 units. The program should ensure that no circl...
import random import math class Circle: def __init__(self, x, y, r): self.x = x self.y = y self.r = r def is_circle_valid(circle, circles): for existing_circle in circles: distance = math.sqrt((circle.x - existing_circle.x) ** 2 + (circle.y - existing_circle.y) ** 2) if...
from solution import Circle, create_circles_in_square, calculate_circle_areas, estimate_uncovered_area def test_create_circles_in_square_no_overlap(): square_side = 10 min_radius = 0.5 max_radius = 1.5 num_circles = 5 circles = create_circles_in_square(square_side, min_radius, max_radius, num_circl...
[]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport math\n\ndef random_circle(radius_range, side_length):\n \"\"\"\n Generate a circle with a random center within the given side_length and a random radius within the ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051650", "row_id": 51650, "seed_ids": "['Qwen2.5-72B-Instruct_106960']" }
0.577279
Filter_51650
I
[ "is_circle_valid", "create_circles_in_square", "calculate_circle_areas", "estimate_uncovered_area" ]
4
[ [ "create_circles_in_square", "is_circle_valid" ] ]
1
[]
false
[ "Circle" ]
true
pytest
true
[]
true
a5993f0594c3a05bcc7ebf1ffebd5260f7e7792b
5dc5935cb5042ac1f6f577bc5f3e6322083292b5
v1.0
instruct
Filter
Filter_51663_I
I'm working on a project that involves processing a large number of images. I need to crop the images to a standard size of 512x512 pixels. The images I have are in various resolutions and formats (JPG, PNG, etc.). Can you provide a Python script that can automate this cropping process, ensuring that the cropped area i...
from PIL import Image import os def crop_center(image, new_width, new_height): """ Crop the given image to the specified width and height, ensuring the crop is centered and maintaining the aspect ratio. """ width, height = image.size # Ensure original aspect ratio is maintained aspect_rati...
import pytest from PIL import Image import os from solution import crop_center, process_images def test_crop_center_square_image(): image = Image.new('RGB', (600, 600)) cropped_image = crop_center(image, 512, 512) assert cropped_image.size == (512, 512) def test_crop_center_landscape_image(): image = ...
[ { "docstring": "Crop the given image to the specified width and height,\nensuring the crop is centered and maintaining the aspect ratio.", "function_declaration": "def crop_center(image, new_width, new_height):", "function_name": "crop_center", "parameter_list": "(image, new_width, new_height)" },...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from PIL import Image\nimport os\n\ndef crop_center(image, size=(512, 512)):\n \"\"\"\n Crops the given image to the specified size, centered and maintaining aspect ratio.\n \n Par...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051663", "row_id": 51663, "seed_ids": "['Qwen2.5-72B-Instruct_106987']" }
0.449972
Filter_51663
I
[ "crop_center", "process_images" ]
2
[ [ "process_images", "crop_center" ] ]
1
[]
false
[]
false
pytest
true
[ "PIL" ]
false
41fa40b62224d449e2d53f2b884789b000b9e04c
b16437053a9d6f8f4769579a646f67db7aca94c5
v1.0
instruct
Filter
Filter_51676_I
I need to create a Python script that simulates a dice roll game. The game should simulate rolling two six-sided dice and then display the sum of the two dice. It should also keep track of how many times the user has rolled the dice and display this number at the end. How can I do this?
import random def roll_dice(): """ Simulate rolling two six-sided dice and return their sum. """ dice1 = random.randint(1, 6) dice2 = random.randint(1, 6) return dice1 + dice2 def simulate_dice_rolls(number_of_rolls): """ Simulate rolling the dice a specified number of times. ...
from solution import roll_dice, simulate_dice_rolls def test_roll_dice(): for _ in range(100): # Running the test 100 times to cover randomness result = roll_dice() assert 2 <= result <= 12 # Since two six-sided dice can sum from 2 to 12 def test_simulate_dice_rolls(): number_of_rolls = 10 ...
[ { "docstring": "Simulate rolling two six-sided dice and return their sum.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulate rolling the dice a specified number of times.\n\nParams:\n number_of_rolls (int): Number...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling two six-sided dice and returns their sum.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051676", "row_id": 51676, "seed_ids": "['Qwen2.5-72B-Instruct_107010']" }
0.632263
Filter_51676
I
[ "roll_dice", "simulate_dice_rolls" ]
2
[ [ "simulate_dice_rolls", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d73c18a59817a8c628f90b69f1d224db6170134
9ce66206fe8aece598e2760ecbbff98ec1998d45
v1.0
instruct
Filter
Filter_51704_I
write a Python program that finds all prime numbers between 2 and a given number n. The program should also measure the time taken to find the primes and print this time along with the list of primes. Optimize the program to handle large numbers efficiently.
import time def sieve_of_eratosthenes(n): """ Finds all prime numbers up to n using the Sieve of Eratosthenes algorithm. """ primes = [] is_prime = [True] * (n + 1) p = 2 while p ** 2 <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = F...
from solution import find_primes def test_find_primes_small_range(): primes, time_taken = find_primes(10) assert primes == [2, 3, 5, 7] assert time_taken > 0 # we expect some time to be taken def test_find_primes_medium_range(): primes, time_taken = find_primes(50) assert primes == [2, 3, 5, 7, 1...
[ { "docstring": "Finds all prime numbers up to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_primes(n):", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers between 2 and n using the Sieve of Eratosthenes.\n \"\"\"\n if n < 2:\n return []...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051704", "row_id": 51704, "seed_ids": "['Qwen2.5-72B-Instruct_107061']" }
0.670103
Filter_51704
I
[ "sieve_of_eratosthenes", "find_primes" ]
2
[ [ "find_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bab68512709dc37e9d489c190823cadf18da5d25
db0fc871bf8175aa8f490bff75446ab9bd4dba3b
v1.0
instruct
Filter
Filter_51743_I
Create a Python program to convert the temperature from Celsius to Fahrenheit. Additionally, include an option for the user to convert from Fahrenheit to Celsius. The program should prompt the user to select the conversion type and then enter the temperature value. Ensure the program handles invalid inputs gracefully.
def celsius_to_fahrenheit(celsius): """ Convert Celsius to Fahrenheit. """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Convert Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5/9 def convert_temperature(conversion_type, temperature): if conversion_t...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Convert Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Convert Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(f...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051743", "row_id": 51743, "seed_ids": "['Qwen2.5-72B-Instruct_107127']" }
0.414017
Filter_51743
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
93076ce0f32fa59bb9042d408820881fa9a621cf
e8b0eba9b994de9e0530ed39378b833bf04fccb6
v1.0
instruct
Filter
Filter_51763_I
Create a basic encryption function using Python that takes a string and a key as parameters and returns the encrypted string using a simple substitution cipher. Ensure that the function can also decrypt the string when provided with the correct key. The function should maintain the case of the letters and ignore non-al...
def encrypt(text, key): """ Encrypts the given text using a simple substitution cipher based on the provided key. Parameters: text (str): The string to be encrypted. key (int): The encryption key. Returns: str: The encrypted string. """ encrypted_text = [] for char in ...
from solution import encrypt, decrypt def test_encrypt_lowercase(): assert encrypt("hello", 3) == "khoor" def test_encrypt_uppercase(): assert encrypt("HELLO", 3) == "KHOOR" def test_encrypt_mixed_case(): assert encrypt("Hello", 3) == "Khoor" def test_encrypt_with_non_alpha(): assert enc...
[ { "docstring": "Encrypts the given text using a simple substitution cipher based on the provided key.\n\nParameters:\ntext (str): The string to be encrypted.\nkey (int): The encryption key.\n\nReturns:\nstr: The encrypted string.", "function_declaration": "def encrypt(text, key):", "function_name": "enc...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encrypt_decrypt(text, key):\n \"\"\"\n Encrypts or decrypts the given text using a simple substitution cipher with the provided key.\n Maintains the case of the characters and ign...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051763", "row_id": 51763, "seed_ids": "['Qwen2.5-72B-Instruct_107168']" }
0.74488
Filter_51763
I
[ "encrypt", "decrypt" ]
2
[ [ "decrypt", "encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0169684dba0809622f656cc96a97a48029b48765
d3fc50b018afa19d45bec2ae37d3f84e2a8092a7
v1.0
instruct
Filter
Filter_51766_I
Can you write a simple Python program that checks if a number is prime or not? It would be great if the program could also handle multiple numbers at once and return the results in a dictionary format where the key is the number and the value is a boolean indicating if it's prime or not.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import is_prime, check_primes def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-1) assert is_prime(29) assert is_prime(97) assert not is_prime(100)...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check multiple numbers for primality.\n\nArgs:\nnumbers: a list of integers\n\nReturns:\nA dictionary where keys are numbers and v...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00051766", "row_id": 51766, "seed_ids": "['Qwen2.5-72B-Instruct_107174']" }
0.789337
Filter_51766
I
[ "is_prime", "check_primes" ]
2
[ [ "check_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f56fdcb86180136d3e145f44b2bda9c50b699a5c
73eadf77d5667ed17c1ede463de368709d893b60
v1.0
instruct
Filter
Filter_51767_I
Write a code in Python to implement a game of Rock, Paper, Scissors. The game should allow a user to play against the computer. The computer's choice should be randomly generated. The game should keep track of the score and allow the user to play multiple rounds until they decide to quit. Display the score after each r...
import random def get_computer_choice(): """ Randomly select between 'rock', 'paper', and 'scissors' for the computer. """ choices = ["rock", "paper", "scissors"] return random.choice(choices) def determine_winner(user_choice, computer_choice): """ Determine the winner of a rock, paper, sc...
from solution import get_computer_choice, determine_winner, play_round def test_get_computer_choice(): choices = ["rock", "paper", "scissors"] for _ in range(100): # test multiple times to ensure randomness choice = get_computer_choice() assert choice in choices def test_determine_winner(): ...
[ { "docstring": "Randomly select between 'rock', 'paper', and 'scissors' for the computer.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determine the winner of a rock, paper, scissors round.", "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly select between 'rock', 'paper', and 'scissors' for the computer.\n \"\"\"\n choices = [\"rock\", \"paper\", \"scisso...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00051767", "row_id": 51767, "seed_ids": "['Qwen2.5-72B-Instruct_107175']" }
0.485806
Filter_51767
I
[ "get_computer_choice", "determine_winner", "play_round" ]
3
[ [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1c6e1f2c639d419c56f83114bf4e5e8a99883e6d
7953b4cb6d52a3e96dcd7be9f1c4d677ec9d7c37
v1.0
instruct
Filter
Filter_51800_I
How can I create a Python script to monitor my website's uptime and notify me if the site goes down?
import requests import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def send_email_notification(message, to_email): """ Sends an email notification with the given message to the specified email. """ from_email = "your_email@example.com" from_password =...
import pytest import requests from unittest.mock import patch from solution import check_website_uptime, send_email_notification @patch("solution.requests.get") @patch("solution.send_email_notification") def test_check_website_uptime_up(mock_send_email, mock_get): mock_get.return_value.status_code = 200 check_...
[ { "docstring": "Sends an email notification with the given message to the specified email.", "function_declaration": "def send_email_notification(message, to_email):", "function_name": "send_email_notification", "parameter_list": "(message, to_email)" }, { "docstring": "Checks the website's ...
[ 1, 1, 0 ]
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\n\ndef send_email(subject, body, to_email, from_email, smtp_server, smtp_p...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051800", "row_id": 51800, "seed_ids": "['Qwen2.5-72B-Instruct_107233']" }
0.486314
Filter_51800
I
[ "send_email_notification", "check_website_uptime" ]
2
[ [ "check_website_uptime", "send_email_notification" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
2df84d4da86352951c1783fe66014a7b838f0be0
a36885fc08832f5dc93b94ac18024aed73980462
v1.0
instruct
Filter
Filter_51865_I
Write a python program to parse an XML file and convert it into a JSON format, handling nested elements and attributes. The program should read the XML from a file, convert it, and then write the resulting JSON to another file.
import xml.etree.ElementTree as ET import json def xml_to_dict(element): """ Converts an XML element and its children into a dictionary. """ node = {} if element.attrib: node.update(("@{}".format(k), v) for k, v in element.attrib.items()) text = element.text.strip() if element.text...
import os import json from solution import xml_file_to_json_file def test_xml_file_to_json_file(): sample_xml_content = """ <root> <child1 attribute1="value1">Text1</child1> <child2 attribute2="value2"> <subchild>Text2</subchild> </child2> </root> """ expect...
[ { "docstring": "Converts an XML element and its children into a dictionary.", "function_declaration": "def xml_to_dict(element):", "function_name": "xml_to_dict", "parameter_list": "(element)" }, { "docstring": "Reads an XML file, converts it to JSON, and writes to another file.", "funct...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import xml.etree.ElementTree as ET\nimport json\n\ndef xml_to_dict(element):\n \"\"\"\n Converts an XML element and its children into a dictionary.\n \"\"\"\n node = {}\n if ele...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00051865", "row_id": 51865, "seed_ids": "['Qwen2.5-72B-Instruct_107333']" }
0.753412
Filter_51865
I
[ "xml_to_dict", "xml_file_to_json_file" ]
2
[ [ "xml_file_to_json_file", "xml_to_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
90f5161ef92d69ea3a977069eddb735ddb97a021
4bf06220a2c7a455dfc2d96bfb3b8788a7863490
v1.0
instruct
Filter
Filter_51877_I
Design a function in Python that will multiply a matrix by a vector. This function should take two parameters: a 2D NumPy array representing the matrix and a 1D NumPy array representing the vector. The function should return the result of the multiplication as a 1D NumPy array. Additionally, include a check function th...
import numpy as np def multiply_matrix_vector(matrix, vector): """ Multiplies a given 2D matrix by a 1D vector. Parameters: matrix (numpy.ndarray): 2D array representing the matrix. vector (numpy.ndarray): 1D array representing the vector. Returns: numpy.ndarray: Resulting 1D arra...
from solution import multiply_matrix_vector import numpy as np def test_multiply_square_matrix_vector(): matrix = np.array([[1, 2], [3, 4]]) vector = np.array([1, 2]) result = multiply_matrix_vector(matrix, vector) expected = np.array([5, 11]) assert np.array_equal(result, expected) def test_multi...
[ { "docstring": "Multiplies a given 2D matrix by a 1D vector.\n\nParameters:\nmatrix (numpy.ndarray): 2D array representing the matrix.\nvector (numpy.ndarray): 1D array representing the vector.\n\nReturns:\nnumpy.ndarray: Resulting 1D array after multiplication.", "function_declaration": "def multiply_matri...
[ 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 multiply_matrix_vector(matrix, vector):\n \"\"\"\n Multiplies a given 2D matrix by a 1D vector.\n \n Parameters:\n matrix (numpy.ndarray): 2D array rep...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00051877", "row_id": 51877, "seed_ids": "['Qwen2.5-72B-Instruct_107346']" }
0.566578
Filter_51877
I
[ "multiply_matrix_vector", "check_specific_example" ]
2
[ [ "check_specific_example", "multiply_matrix_vector" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
e8993e16670cffd35efa85c96e9c1d888e300585
34f5a5fa26c5e03bb0260582a6261e40581dcf0f
v1.0
instruct
Filter
Filter_51889_I
Write a Python program that asks the user to enter a string, then checks if the string is a palindrome. If the string is a palindrome, the program should print "The string is a palindrome." Otherwise, it should print "The string is not a palindrome." Remember to ignore spaces and capitalization when determining if the ...
def is_palindrome(s): """ Checks if the input string is a palindrome, ignoring spaces and capitalization. """ # Removing spaces and converting to lowercase cleaned_string = ''.join(s.split()).lower() # Checking if the cleaned string is equal to its reverse return cleaned_string == cleaned_st...
from solution import is_palindrome, check_palindrome def test_is_palindrome(): assert is_palindrome("A man a plan a canal Panama") assert is_palindrome("racecar") assert is_palindrome("No lemon no melon") assert is_palindrome(" ") assert not is_palindrome("hello") assert not is_palindrome("worl...
[ { "docstring": "Checks if the input string is a palindrome, ignoring spaces and capitalization.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def check_palindrome(s):", "fu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Checks if the input string is a palindrome, ignoring spaces and capitalization.\n \"\"\"\n s_cleaned = ''.join(char.lower() for char in s if char.i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051889", "row_id": 51889, "seed_ids": "['Qwen2.5-72B-Instruct_107361']" }
0.82485
Filter_51889
I
[ "is_palindrome", "check_palindrome" ]
2
[ [ "check_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abcc570f4d0a4b6f9fca0f97a6bf609e69f6b945
fbb85cd1e9618d1655bba7cc5f04e9859849087c
v1.0
instruct
Filter
Filter_51903_I
Can you write a Python function that generates a list of the first N prime numbers? I want to use it for a cryptography project where I need to work with prime numbers.
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 Tr...
from solution import generate_primes def test_generate_primes_first_5(): assert generate_primes(5) == [2, 3, 5, 7, 11] def test_generate_primes_zero(): assert generate_primes(0) == [] def test_generate_primes_one(): assert generate_primes(1) == [2] def test_generate_primes_ten(): assert generate_pri...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list of the first N prime numbers.", "function_declaration": "def generate_primes(n):", "function_name": "gene...
[ 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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051903", "row_id": 51903, "seed_ids": "['Qwen2.5-72B-Instruct_107381']" }
0.657719
Filter_51903
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
80794a36aa3658a7a19e686aee7a283bd1564192
1d5737d5edf1d712c87de2045769f0f61a0e88dc
v1.0
instruct
Filter
Filter_51906_I
Create a Python program that reads a CSV file and displays the data in a tabular format. The program should also include an option to sort the data based on a column of the user's choice. The CSV file will contain columns for "ID", "Name", "Age", and "City". Provide the Python code and a brief explanation of how it wor...
import csv from operator import itemgetter from tabulate import tabulate def read_csv(file_path): """ Reads a CSV file and returns the data as a list of dictionaries. """ with open(file_path, mode='r') as file: csv_reader = csv.DictReader(file) data = [row for row in csv_reader] ret...
from solution import read_csv, display_table, sort_data import pytest # Test data test_csv_data = [ {'ID': '1', 'Name': 'Alice', 'Age': '30', 'City': 'New York'}, {'ID': '2', 'Name': 'Bob', 'Age': '25', 'City': 'Los Angeles'}, {'ID': '3', 'Name': 'Charlie', 'Age': '35', 'City': 'Chicago'}, ] def test_read...
[ { "docstring": "Reads a CSV file and returns the data as a list of dictionaries.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Displays the data in a tabular format.", "function_declaration": "def dis...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nfrom tabulate import tabulate\n\ndef read_csv(filepath):\n \"\"\"\n Reads a CSV file and returns the data as a list of dictionaries.\n \"\"\"\n data = []\n with open...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051906", "row_id": 51906, "seed_ids": "['Qwen2.5-72B-Instruct_107385']" }
0.55327
Filter_51906
I
[ "read_csv", "display_table", "sort_data", "read_and_display_sorted_csv" ]
4
[ [ "read_and_display_sorted_csv", "display_table" ], [ "read_and_display_sorted_csv", "read_csv" ], [ "read_and_display_sorted_csv", "sort_data" ] ]
3
[]
false
[]
false
pytest
true
[ "tabulate" ]
false
5618215a0de4994f159a719d2fe0716d4b807edc
fa2bea3d1ad53d31668fcf9e5b64ca10a5c2a84c
v1.0
instruct
Filter
Filter_51914_I
Create a Python function that checks whether a given number is a prime number and returns `True` if it is, and `False` otherwise. Additionally, the function should be able to handle a list of numbers, returning a list of tuples, where each tuple contains the original number and a boolean indicating whether it is prime....
def is_prime(n): """ Check whether a given number is a prime number. Returns True if it is prime, 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: ...
from solution import is_prime, check_prime_numbers def test_is_prime_single(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(25) == False def test_is_prime_edge_cases(): assert is_pri...
[ { "docstring": "Check whether a given number is a prime number.\nReturns True if it is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check a list of numbers to see whether each number is prime.\nR...
[ 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 Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00051914", "row_id": 51914, "seed_ids": "['Qwen2.5-72B-Instruct_107397']" }
0.801171
Filter_51914
I
[ "is_prime", "check_prime_numbers" ]
2
[ [ "check_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0b9646b4fa950fa7afd63612d66cd6b03bdeea7
b61625bdd73d457ff50641df1f0ef1663566a673
v1.0
instruct
Filter
Filter_51996_I
I need to create a Python script that fetches the most recent file from a specific directory on my local machine and renames it to "latest_file.txt". Can you provide a sample code for this?
import os import glob def get_most_recent_file(directory_path): """ Gets the most recent file in the given directory. Parameters: directory_path (str): The path to the directory Returns: str: The path to the most recent file """ list_of_files = glob.glob(os.path.join(directory...
import os import tempfile import time from solution import get_most_recent_file, rename_to_latest_file def create_temp_file(directory, name, content): temp_file_path = os.path.join(directory, name) with open(temp_file_path, 'w') as temp_file: temp_file.write(content) return temp_file_path def test...
[ { "docstring": "Gets the most recent file in the given directory.\n\nParameters:\ndirectory_path (str): The path to the directory\n\nReturns:\nstr: The path to the most recent file", "function_declaration": "def get_most_recent_file(directory_path):", "function_name": "get_most_recent_file", "parame...
[ 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 glob\n\ndef fetch_and_rename_latest_file(directory):\n \"\"\"\n Fetches the most recent file from the specified directory and renames it to 'latest_file.txt'.\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00051996", "row_id": 51996, "seed_ids": "['Qwen2.5-72B-Instruct_107536']" }
0.510714
Filter_51996
I
[ "get_most_recent_file", "rename_to_latest_file" ]
2
[ [ "rename_to_latest_file", "get_most_recent_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
91bcb6a8e88432bb496199361db1ca39b3f98aaa
fbbdca10a4d0317891af025ceb9df0243dc44243
v1.0
instruct
Filter
Filter_52003_I
Write a Python program to print all prime numbers between two given numbers. Make sure to optimize the code for efficiency.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True...
from solution import prime_numbers_between def test_no_primes(): assert prime_numbers_between(14, 16) == [] assert prime_numbers_between(0, 1) == [] def test_primes_in_small_range(): assert prime_numbers_between(2, 5) == [2, 3, 5] assert prime_numbers_between(10, 20) == [11, 13, 17, 19] def test_sing...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers between a and b (inclusive).", "function_declaration": "def prime_numbers_between(a, b):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False. \n Optimized by checking only up to the square root of n.\n \"\"\"\n if n <= 1:\n return Fals...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052003", "row_id": 52003, "seed_ids": "['Qwen2.5-72B-Instruct_107544']" }
0.627343
Filter_52003
I
[ "is_prime", "prime_numbers_between" ]
2
[ [ "prime_numbers_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf5bf8ce09d18ad47599f8996f9c1eb6b000b56b
92a7df5d7abc62c344dc4a1535922b1ea0128fa2
v1.0
instruct
Filter
Filter_52016_I
Develop a Python function that can calculate the perimeter of a triangle when the coordinates of its three vertices are provided. Ensure the function is easy to use and well-documented, including a method to validate the correctness of your function with given data points. Avoid using any external libraries for the cal...
import math def distance(x1, y1, x2, y2): """ Calculate the distance between two points (x1, y1) and (x2, y2). """ return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def perimeter_of_triangle(x1, y1, x2, y2, x3, y3): """ Calculate the perimeter of a triangle given the coordinates of its vertice...
from solution import perimeter_of_triangle, distance def test_distance(): assert distance(0, 0, 3, 4) == 5.0 # distance on a right triangle def test_perimeter_of_triangle(): assert math.isclose(perimeter_of_triangle(0, 0, 3, 0, 3, 4), 12.0) # standard right triangle assert math.isclose(perimeter_of_tria...
[ { "docstring": "Calculate the distance between two points (x1, y1) and (x2, y2).", "function_declaration": "def distance(x1, y1, x2, y2):", "function_name": "distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": "Calculate the perimeter of a triangle given the coordinates of its ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n \"\"\"\n Calculates the distance between two points (x1, y1) and (x2, y2).\n \"\"\"\n return math.sqrt((x2 - x1) ** 2 + (y2...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052016", "row_id": 52016, "seed_ids": "['Qwen2.5-72B-Instruct_107561']" }
0.684217
Filter_52016
I
[ "distance", "perimeter_of_triangle" ]
2
[ [ "perimeter_of_triangle", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
315bae92d6e3a5db843c02c37446909863ef5ee0
4539ba77b9f9d26630fdee47dd983ab44f6e75ad
v1.0
instruct
Filter
Filter_52047_I
Can you help me with a Python script to convert temperatures from Celsius to Fahrenheit and vice versa? It would be great if the script could take user input for the temperature and the scale (Celsius or Fahrenheit) they want to convert from, and then output the converted temperature.
def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. Formula: (C * 9/5) + 32 """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. Formula: (F - 32) * 5/9 """ return (fahrenheit - 32) * 5/9 def convert_temp...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Converts Celsius to Fahrenheit.\nFormula: (C * 9/5) + 32", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts Fahrenheit to Celsius.\nFormula: (F - 32) * 5/9", ...
[ 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 temperature to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052047", "row_id": 52047, "seed_ids": "['Qwen2.5-72B-Instruct_107611']" }
0.40798
Filter_52047
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
68ab028f65e8373e1f0747dc9714ce2fd043bfbd
3f2288c822673ba2b3c877c2e17e3bc019f07bf9
v1.0
instruct
Filter
Filter_52053_I
Implement a Python function `find_sum_in_list` that takes two arguments: `numbers`, a list of integers, and `target_sum`, an integer representing the target sum. The function should return `True` if any two distinct numbers within the list add up to the target sum, and `False` otherwise. Ensure your solution is efficie...
def find_sum_in_list(numbers, target_sum): """ Returns True if there are two distinct numbers in the list that add up to the target_sum, otherwise returns False. """ seen_numbers = set() for number in numbers: complement = target_sum - number if complement in seen_numbers: ...
from solution import find_sum_in_list, verify_function def test_find_sum_in_list(): assert find_sum_in_list([1, 2, 3, 4, 5], 9) == True assert find_sum_in_list([1, 2, 3, 4, 5], 10) == False assert find_sum_in_list([], 5) == False assert find_sum_in_list([7], 7) == False assert find_sum_in_list([3, ...
[ { "docstring": "Returns True if there are two distinct numbers in the list that add up to the target_sum,\notherwise returns False.", "function_declaration": "def find_sum_in_list(numbers, target_sum):", "function_name": "find_sum_in_list", "parameter_list": "(numbers, target_sum)" }, { "doc...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_sum_in_list(numbers, target_sum):\n \"\"\"\n Returns True if any two distinct numbers within the list add up to the target sum, False otherwise.\n \"\"\"\n num_set = set()...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052053", "row_id": 52053, "seed_ids": "['Qwen2.5-72B-Instruct_107622']" }
0.625641
Filter_52053
I
[ "find_sum_in_list", "verify_function" ]
2
[ [ "verify_function", "find_sum_in_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd3d90cb7172514b2901dafe7c768a028514f303
828c2b2c4dd2860536d65aa261cc5c06d283da97
v1.0
instruct
Filter
Filter_52062_I
Develop a Python program that simulates the rolling of a six-sided die, and then modify it to allow for a die with any number of sides. The program should use a function to generate the random numbers and return the result. Additionally, implement a feature that allows the user to specify the number of rolls and displa...
import random def roll_die(sides=6): """ Simulates the rolling of a die with the given number of sides. Parameters: sides (int): The number of sides on the die. Returns: int: The result of the die roll. """ return random.randint(1, sides) def roll_dice(num_rolls, ...
from solution import roll_die, roll_dice def test_roll_die_six_sided(): result = roll_die(6) assert 1 <= result <= 6 def test_roll_die_twenty_sided(): result = roll_die(20) assert 1 <= result <= 20 def test_roll_dice_with_default_six_sided_dice(): results = roll_dice(5) assert len(results) ==...
[ { "docstring": "Simulates the rolling of a die with the given number of sides.\n\nParameters:\n sides (int): The number of sides on the die.\n \nReturns:\n int: The result of the die roll.", "function_declaration": "def roll_die(sides=6):", "function_name": "roll_die", "parameter_list": "(s...
[ 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 the roll of a die with the given number of sides.\n \n Args:\n sides (int): Number of sides on the die. Default is 6...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052062", "row_id": 52062, "seed_ids": "['Qwen2.5-72B-Instruct_107634']" }
0.588449
Filter_52062
I
[ "roll_die", "roll_dice" ]
2
[ [ "roll_dice", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94fe9cfd40da0f9d354cc501ab339236b7c75c98
c7dfe2285ca1dba248c04e751f2c8e671a63c4c7
v1.0
instruct
Filter
Filter_52077_I
Given a list of countries and their population in millions, create a function in Python that sorts this list by population in descending order. Each country is represented as a tuple (Country, Population). The function should return the sorted list. Additionally, implement a feature that allows the user to specify a co...
def sort_countries_by_population(countries): """ Sorts a list of countries by population in descending order. Parameters: countries (list of tuples): A list of tuples where each tuple contains a country and its population in millions. Returns: list of tuples: The list sorted by populat...
from solution import sort_countries_by_population, get_country_rank def test_sort_countries_by_population(): countries = [("A", 50), ("B", 20), ("C", 30)] expected = [("A", 50), ("C", 30), ("B", 20)] assert sort_countries_by_population(countries) == expected def test_sort_countries_by_population_with_ties...
[ { "docstring": "Sorts a list of countries by population in descending order.\n\nParameters:\n countries (list of tuples): A list of tuples where each tuple contains a country and its population in millions.\n\nReturns:\n list of tuples: The list sorted by population in descending order.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_countries_by_population(countries):\n \"\"\"\n Sorts a list of countries by their population in descending order.\n \n Parameters:\n countries (list of tuples): Each tu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052077", "row_id": 52077, "seed_ids": "['Qwen2.5-72B-Instruct_107660']" }
0.516174
Filter_52077
I
[ "sort_countries_by_population", "get_country_rank" ]
2
[ [ "get_country_rank", "sort_countries_by_population" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d327aaab8f0cbae2fe14ff35f2ae1c0f026462ca
6c928a73ff40769a63a46ffbf7feaad6feaf085b
v1.0
instruct
Filter
Filter_52081_I
Please design a simple game using Python that can be run in the console. The game should be a basic version of the classic "Rock, Paper, Scissors". The player should be able to input their choice, and the computer should randomly select one of the options. The game should then determine the winner based on the classic ...
import random def get_computer_choice(): choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(player_choice, computer_choice): if player_choice == computer_choice: return "It's a tie!" elif (player_choice == 'rock' and computer_choice == 'scissors') or \ ...
from solution import get_computer_choice, determine_winner def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] for _ in range(100): assert get_computer_choice() in choices def test_determine_winner(): assert determine_winner('rock', 'scissors') == "You win!" assert determin...
[ { "docstring": null, "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def determine_winner(player_choice, computer_choice):", "function_name": "determine_winner", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly selects and returns one of 'rock', 'paper', 'scissors'.\n \"\"\"\n choices = ['rock', 'paper', 'scissors']\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052081", "row_id": 52081, "seed_ids": "['Qwen2.5-72B-Instruct_107665']" }
0.458678
Filter_52081
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ], [ "play_game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d664ff31acc613bd5ddd19a2056d1395e15e943d
36b6fe517a18e85702e2bad3d1378c459b22fb78
v1.0
instruct
Filter
Filter_52119_I
Explain the process of creating a Python script that reads and processes a CSV file to extract specific data and generate a summary report. Include a step-by-step guide and sample code snippets to illustrate the process.
import csv def read_csv(file_path): """ Reads a CSV file and returns the data as a list of dictionaries. Each dictionary represents a row in the CSV file with the keys as the column headers. """ with open(file_path, mode='r', newline='', encoding='utf-8') as file: reader = csv.DictReade...
import pytest from solution import read_csv, extract_specific_data, generate_summary_report @pytest.fixture def sample_csv(tmp_path): data = """Name,Age,Country John Doe,28,USA Jane Smith,22,Canada Jim Brown,28,USA Jake Blues,35,Canada Elwood Blues,35,USA """ file_path = tmp_path / "test.csv" file_path.wri...
[ { "docstring": "Reads a CSV file and returns the data as a list of dictionaries.\nEach dictionary represents a row in the CSV file with the keys\nas the column headers.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "do...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "import csv\nfrom collections import defaultdict\n\ndef read_csv(file_path):\n \"\"\"\n Reads a CSV file and returns the data as a list of dictionaries.\n Each...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052119", "row_id": 52119, "seed_ids": "['Qwen2.5-72B-Instruct_107732']" }
0.538105
Filter_52119
I
[ "read_csv", "extract_specific_data", "generate_summary_report" ]
3
[ [ "generate_summary_report", "extract_specific_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
125973b6048f7b27832e6ce73384b9cfef0036d9
feb999f0779bcb9507af5a8e3d23f5eb8ae64b2d
v1.0
instruct
Filter
Filter_52131_I
Is it possible for me to teach a person who knows nothing about programming to create a simple calculator in Python? How would I start?
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, simple_calculator def test_add(): assert add(2, 3) == 5 assert add(-2, 3) == 1 assert add(0, 0) == 0 def test_subtract(): assert subtract(5, 3) == 2 assert subtract(3, 5) == -2 assert subtract(0, 0) == 0 def test_multiply(): assert mul...
[ { "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 \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef subtract(a, b):\n \"\"\"\n Returns the difference between a and b.\n \"\"\"\n retur...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052131", "row_id": 52131, "seed_ids": "['Qwen2.5-72B-Instruct_107750']" }
0.471873
Filter_52131
I
[ "add", "subtract", "multiply", "divide", "simple_calculator" ]
5
[ [ "simple_calculator", "add" ], [ "simple_calculator", "divide" ], [ "simple_calculator", "multiply" ], [ "simple_calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
5e76eef10cb3e7ba40e649b65cd57152f78ba84e
d48ad604fb34d2e194310ddaec504e0295cd8451
v1.0
instruct
Filter
Filter_52134_I
Write a Python function to reverse the words in a sentence but not the characters in each word. For example, if the input is "Hello World", the output should be "World Hello". Include a simple check function to test if your code works as expected.
def reverse_words(sentence): """ Reverses the words in a sentence but not the characters within each word. :param sentence: A string containing the sentence to be reversed. :return: A string with words in reversed order. """ words = sentence.split() return ' '.join(reversed(words)) # S...
from solution import reverse_words def test_reverse_words(): assert reverse_words("Hello World") == "World Hello" assert reverse_words("The sky is blue") == "blue is sky The" assert reverse_words("Python is fun") == "fun is Python" assert reverse_words("a b c d") == "d c b a" # Edge case assert...
[ { "docstring": "Reverses the words in a sentence but not the characters within each word.\n\n:param sentence: A string containing the sentence to be reversed.\n:return: A string with words in reversed order.", "function_declaration": "def reverse_words(sentence):", "function_name": "reverse_words", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_words(sentence):\n \"\"\"\n Reverses the words in a sentence but not the characters within each word.\n \n :param sentence: A string containing the sentence to be rever...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052134", "row_id": 52134, "seed_ids": "['Qwen2.5-72B-Instruct_107753']" }
0.730278
Filter_52134
I
[ "reverse_words", "check_reverse_words" ]
2
[ [ "check_reverse_words", "reverse_words" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58d7d9500cce0a30bf838a0fe6d04c3e2fbc25c9
c9bd1b64101a4500f823d7231955bfd46e88d6aa
v1.0
instruct
Filter
Filter_52145_I
Implement an in-place algorithm to sort a list of integers in Python. The algorithm should be efficient and use as little additional space as possible. Additionally, provide a brief explanation of the algorithm you use and its time and space complexity.
def quicksort(arr, low, high): """ Sorts the array in-place using the quicksort algorithm. Parameters: arr - The list to be sorted low - The starting index of the segment of the list to be sorted high - The ending index of the segment of the list to be sorted """ if low < high:...
from solution import sort_in_place def test_sort_in_place(): arr1 = [3, 6, 8, 10, 1, 2, 1] sort_in_place(arr1) assert arr1 == [1, 1, 2, 3, 6, 8, 10] def test_sort_empty(): arr2 = [] sort_in_place(arr2) assert arr2 == [] def test_sort_single_element(): arr3 = [1] sort_in_place(arr3) ...
[ { "docstring": "Sorts the array in-place using the quicksort algorithm.\n\nParameters:\narr - The list to be sorted\nlow - The starting index of the segment of the list to be sorted\nhigh - The ending index of the segment of the list to be sorted", "function_declaration": "def quicksort(arr, low, high)...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort(arr, low, high):\n \"\"\"\n In-place QuickSort algorithm.\n\n Parameters:\n arr (list of int): List of integers to be sorted.\n low (int): Lower index.\n high (...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052145", "row_id": 52145, "seed_ids": "['Qwen2.5-72B-Instruct_107770']" }
0.609335
Filter_52145
I
[ "quicksort", "partition", "sort_in_place" ]
3
[ [ "quicksort", "partition" ], [ "sort_in_place", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
081156c7bd3f7ec7c1abc1c79b526f33af908a47
f3f22db6ab4040cf11f43e631555e00c9f74fddf
v1.0
instruct
Filter
Filter_52160_I
Write a Python function to compute the sum of all prime numbers from 1 to a given number `n`. The function should efficiently handle large numbers.
def is_prime(num): """ Returns True if the number is prime, else 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 return True def...
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(29) == True assert is_prime(1) == False assert is_prime(0) == False def test_sum_of_primes_small(): assert sum_of_primes(10) =...
[ { "docstring": "Returns True if the number is prime, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers from 1 to n (inclusive).", "function_declaration": "def sum_of_p...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ==...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052160", "row_id": 52160, "seed_ids": "['Qwen2.5-72B-Instruct_107790']" }
0.669253
Filter_52160
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
681ce19f53ddce008ab87f9f6dbe794ec536940c
e2b3da49549de7e353a7dcdce15a84a37784793e
v1.0
instruct
Filter
Filter_52175_I
Write a Python program to generate the first N prime numbers, where N is input by the user. The program should use a function to determine if a number is prime and should efficiently handle large inputs. Ensure the program is user-friendly and outputs the primes in a readable format.
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 i +=...
from solution import is_prime, generate_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False def test_is_prime_large(): assert is_prime(7919) == True ...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates the first N prime numbers.", "function_declaration": "def generate_primes(N):", "funct...
[ 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 Determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052175", "row_id": 52175, "seed_ids": "['Qwen2.5-72B-Instruct_107808']" }
0.715458
Filter_52175
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1c67c60f2ab4252c01acba3a1480a4b33a26924
2c974329fada196cb192f9dc3fda76a58d878dca
v1.0
instruct
Filter
Filter_52217_I
Create a Python function that takes an integer and returns its binary representation as a string, with a minimum length of 8 characters, padding with leading zeros if necessary. Then, apply this function to a list of integers and return a list of their binary string representations. For example, if the integer is 7, it...
def int_to_binary_string(n): """ Convert an integer to its binary representation string with at least 8 characters. """ return format(n, '08b') def list_int_to_binary_string(lst): """ Convert a list of integers to a list of their binary representation strings with at least 8 characters. """...
from solution import int_to_binary_string, list_int_to_binary_string def test_int_to_binary_string(): assert int_to_binary_string(7) == '00000111' assert int_to_binary_string(0) == '00000000' assert int_to_binary_string(255) == '11111111' assert int_to_binary_string(1) == '00000001' assert int_to_b...
[ { "docstring": "Convert an integer to its binary representation string with at least 8 characters.", "function_declaration": "def int_to_binary_string(n):", "function_name": "int_to_binary_string", "parameter_list": "(n)" }, { "docstring": "Convert a list of integers to a list of their binar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_binary_string(n):\n \"\"\"\n Takes an integer and returns its binary representation as a string, \n with a minimum length of 8 characters, padding with leading zeros if nec...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052217", "row_id": 52217, "seed_ids": "['Qwen2.5-72B-Instruct_107866']" }
0.699706
Filter_52217
I
[ "int_to_binary_string", "list_int_to_binary_string" ]
2
[ [ "list_int_to_binary_string", "int_to_binary_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
17d80fb7c61d3ada0fd8512fceddf45dae35dd48
1cb3037492bed401715c8a2bd944704964f734d8
v1.0
instruct
Filter
Filter_52219_I
Can you help me understand the process of implementing a neural network from scratch in Python, without using high-level libraries like TensorFlow or PyTorch?
import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): return x * (1 - x) def initialize_weights(input_size, hidden_size, output_size): np.random.seed(42) W1 = np.random.randn(input_size, hidden_size) b1 = np.zeros((1, hidden_size)) W2 = np.random.randn(hidd...
import numpy as np from solution import train, predict def test_neural_network(): # Create a simple logical OR dataset X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) y = np.array([[0], [1], [1], [1]]) input_size = 2 hidden_size = 2 outp...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 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\nclass SimpleNeuralNetwork:\n def __init__(self, input_size, h...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052219", "row_id": 52219, "seed_ids": "['Qwen2.5-72B-Instruct_107869']" }
0.277396
Filter_52219
I
[ "sigmoid", "sigmoid_derivative", "initialize_weights", "forward_propagation", "backward_propagation", "update_weights", "compute_loss", "train", "predict" ]
9
[ [ "backward_propagation", "sigmoid_derivative" ], [ "forward_propagation", "sigmoid" ], [ "predict", "forward_propagation" ], [ "train", "backward_propagation" ], [ "train", "compute_loss" ], [ "train", "forward_propagation" ], [ "train", ...
8
[]
false
[]
false
pytest
true
[ "numpy" ]
false
2306b08319f20a697c10e41efc18497e3c328906
e5e5f923743fc587545844676aae6f6b216feedb
v1.0
instruct
Filter
Filter_52265_I
Create a python program that simulates a simple game where a player can roll a six-sided die. The player wins if they roll a 6. Display the outcome of each roll and a message indicating whether they won or lost. The game continues until the player decides to quit by entering 'q'.
import random def roll_die(): return random.randint(1, 6) def play_game(): while True: cmd = input("Press Enter to roll the die (or 'q' to quit): ").strip().lower() if cmd == 'q': print("Game ended.") break roll = roll_die() print(f"Rolled a {roll}")...
import pytest from unittest.mock import patch from solution import roll_die, play_game def test_roll_die(): for _ in range(100): assert 1 <= roll_die() <= 6 @patch('builtins.input', side_effect=['', '', 'q']) @patch('builtins.print') def test_play_game_quit(mock_print, mock_input): play_game() moc...
[ { "docstring": null, "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def play_game():", "function_name": "play_game", "parameter_list": "()" } ]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided die and returns the outcome.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_game():\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052265", "row_id": 52265, "seed_ids": "['Qwen2.5-72B-Instruct_107947']" }
0.550923
Filter_52265
I
[ "roll_die", "play_game" ]
2
[ [ "play_game", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3cf3cc61d0eb40881aa6a8a7b8a1aeac2484a624
cc24244c418e67badc3f5678b345aa68794f98f1
v1.0
instruct
Filter
Filter_52267_I
Can you generate a small Python program that simulates a simple dice roll game? The game should allow a user to roll two dice and then display the results. The user should also have the option to play again.
import random def roll_dice(): """ Simulates rolling two dice and returns the result as a tuple. """ die1 = random.randint(1, 6) die2 = random.randint(1, 6) return (die1, die2) def play_game(): """ Simulates a simple dice roll game allowing the user to roll two dice and displays th...
from solution import roll_dice def test_roll_dice_range(): die1, die2 = roll_dice() assert 1 <= die1 <= 6 assert 1 <= die2 <= 6 def test_roll_dice_type(): die1, die2 = roll_dice() assert isinstance(die1, int) assert isinstance(die2, int) def test_roll_dice_length(): result = roll_dice() ...
[ { "docstring": "Simulates rolling two dice and returns the result as a tuple.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates a simple dice roll game allowing the user to roll two dice\nand displays the result. 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_dice():\n \"\"\"\n Simulates rolling two dice and returns the result as a tuple.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052267", "row_id": 52267, "seed_ids": "['Qwen2.5-72B-Instruct_107949']" }
0.544781
Filter_52267
I
[ "roll_dice", "play_game" ]
2
[ [ "play_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2cba718ec5c2bc7ae4dedaccb75d72c33ef2f746
59d08b483225f2fc1ca521dd4c8551a2727a80f1
v1.0
instruct
Filter
Filter_52296_I
Design a Python function to convert a given list of temperatures from Fahrenheit to Celsius, and add the results as a new column in a pandas DataFrame. The DataFrame initially contains the temperatures in Fahrenheit under the column 'Fahrenheit'. The function should also include proper error handling for temperatures t...
import pandas as pd def fahrenheit_to_celsius(fahrenheit): """ Convert Fahrenheit to Celsius. """ if fahrenheit < -459.67: # Absolute zero in Fahrenheit raise ValueError("Temperature below absolute zero is not possible") return (fahrenheit - 32) * 5.0/9.0 def add_celsius_column(df): "...
import pytest import pandas as pd from solution import fahrenheit_to_celsius, add_celsius_column def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(-40) == -40 with pytest.raises(ValueError): fahrenheit_t...
[ { "docstring": "Convert Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Adds a new column 'Celsius' to the DataFrame which contains temperatures\nconverted...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\n\ndef fahrenheit_to_celsius(temp_f):\n \"\"\"\n Converts temperature from Fahrenheit to Celsius.\n Raises ValueError if temperature is below absolute zero (-459.6...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052296", "row_id": 52296, "seed_ids": "['Qwen2.5-72B-Instruct_107993']" }
0.540263
Filter_52296
I
[ "fahrenheit_to_celsius", "add_celsius_column" ]
2
[ [ "add_celsius_column", "fahrenheit_to_celsius" ] ]
1
[]
false
[]
false
pytest
true
[ "pandas" ]
false
8e8c65e0441e95b2c47ccf8c013c2584bfd39587
1cdd8546959d8c91a3cc8e9ff07bfff06237d227
v1.0
instruct
Filter
Filter_52317_I
Design a Python function that, when provided with a list of positive integers, identifies and returns the smallest positive integer that is a multiple of every number in the given list. This function should be optimized for performance and suitable for handling lists of varying lengths. Additionally, include a snippet ...
import math from functools import reduce def lcm(a, b): """ Helper function to calculate the least common multiple (LCM) of two numbers. """ return abs(a*b) // math.gcd(a, b) def smallest_multiple(lst): """ Returns the smallest positive integer that is a multiple of every number in the given l...
from solution import smallest_multiple def test_smallest_multiple_basic(): assert smallest_multiple([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2520 def test_smallest_multiple_single_element(): assert smallest_multiple([5]) == 5 def test_smallest_multiple_two_elements(): assert smallest_multiple([4, 6]) == 12 d...
[ { "docstring": "Helper function to calculate the least common multiple (LCM) of two numbers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest positive integer that is a multiple of every number in the given...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple (LCM) of two positive integers a and b.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef smallest_m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052317", "row_id": 52317, "seed_ids": "['Qwen2.5-72B-Instruct_108025']" }
0.691493
Filter_52317
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22b7c92ebb799cdbe141c36c0360937e912e49a5
cc078a19e11349ce95305e62377a588e712d64ed
v1.0
instruct
Filter
Filter_52332_I
Write a Python function to check if a number is a prime number. The function should be efficient for numbers up to 10^9. Use the function to find all prime numbers between 1 and 1000 and return them as a list.
def is_prime(n): """ Check if a number is a prime. Parameters: n (int): The number to check. Returns: bool: True if n is a prime, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i ...
from solution import is_prime, find_primes_between_1_and_1000 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(30) == False assert is_prime(1) == False assert is_...
[ { "docstring": "Check if a number is a prime.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all prime numbers b...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052332", "row_id": 52332, "seed_ids": "['Qwen2.5-72B-Instruct_108044']" }
0.76936
Filter_52332
I
[ "is_prime", "find_primes_between_1_and_1000" ]
2
[ [ "find_primes_between_1_and_1000", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d4ae02192d9e6ae2c2e22032e61ee72b15f7711
70e3bfbcd7bd2c95919d10ba8b36eef8789001d6
v1.0
instruct
Filter
Filter_52333_I
How can I create a game using Python that involves player choices affecting the story?
def start_game(): """ Starts the game and returns the opening scene. """ return scene_1() def scene_1(): """ The first scene of the game. """ story = "You find yourself at a crossroads. Do you go left or right?" choices = {"left": scene_2a, "right": scene_2b} return story, choic...
from solution import start_game, scene_1, scene_2a, scene_2b, scene_3a, scene_3b, end_game, end_game_win def test_start_game(): story, choices = start_game() assert story == "You find yourself at a crossroads. Do you go left or right?" assert "left" in choices assert "right" in choices def test_scene_...
[ { "docstring": "Starts the game and returns the opening scene.", "function_declaration": "def start_game():", "function_name": "start_game", "parameter_list": "()" }, { "docstring": "The first scene of the game.", "function_declaration": "def scene_1():", "function_name": "scene_1", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def start_game():\n \"\"\"\n Starts the game and manages the story flow based on player choices.\n \"\"\"\n print(\"Welcome to the Adventure Game!\")\n print(\"You are in a dark...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052333", "row_id": 52333, "seed_ids": "['Qwen2.5-72B-Instruct_108045']" }
0.425872
Filter_52333
I
[ "start_game", "scene_1", "scene_2a", "scene_2b", "scene_3a", "scene_3b", "end_game", "end_game_win" ]
8
[ [ "start_game", "scene_1" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9455aac757e49796ae9b1e7fb2f4a1147fad617e
4e5098c0a75223b9ab26c546d1995f91d110182f
v1.0
instruct
Filter
Filter_52362_I
Create a Python program that simulates a simple dice game. The game should involve two players who each roll a six-sided die. The player with the highest roll wins the round. If both players roll the same number, it's a tie. The program should simulate 10 rounds of the game and print the outcome of each round, as well ...
import random def roll_die(): return random.randint(1, 6) def play_round(): player1_roll = roll_die() player2_roll = roll_die() if player1_roll > player2_roll: return 1 elif player2_roll > player1_roll: return 2 else: return 0 def play_game(num_rounds=10): pla...
from solution import roll_die, play_round, play_game def test_roll_die(): # Roll the die 100 times and check that the results are between 1 and 6 for _ in range(100): roll = roll_die() assert 1 <= roll <= 6 def test_play_round(): # Simulate 100 rounds and ensure the result is either 0, 1, ...
[ { "docstring": null, "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def play_round():", "function_name": "play_round", "parameter_list": "()" }, { "docstring": null, "func...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef roll_die():\n \"\"\"Simulates rolling a six-sided die.\"\"\"\n return random.randint(1, 6)\n\ndef simulate_round():\n \"\"\"Simulates a single round of the dice g...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052362", "row_id": 52362, "seed_ids": "['Qwen2.5-72B-Instruct_108085']" }
0.54412
Filter_52362
I
[ "roll_die", "play_round", "play_game" ]
3
[ [ "play_game", "play_round" ], [ "play_round", "roll_die" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7fdbf3a3069b20a5ea8595fca48a20509f57b5c5
b63204c9f95e907162a89bf3cd8ebd14935ec624
v1.0
instruct
Filter
Filter_52372_I
Create a Python program to convert a list of temperatures from Celsius to Fahrenheit, and display them in a formatted table. The table should have two columns: one for the Celsius temperatures and one for the Fahrenheit temperatures. Use the temperatures [0, 15, 25, 30, 100] as an example.
def celsius_to_fahrenheit(celsius_list): """ Converts a list of temperatures from Celsius to Fahrenheit. :param celsius_list: List of temperatures in Celsius :return: List of temperatures in Fahrenheit """ return [(c * 9 / 5) + 32 for c in celsius_list] def display_temperature_table(celsiu...
from solution import celsius_to_fahrenheit, display_temperature_table def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit([0]) == [32] assert celsius_to_fahrenheit([100]) == [212] assert celsius_to_fahrenheit([0, 15, 25, 30, 100]) == [32, 59, 77, 86, 212] assert celsius_to_fahrenheit([-40]) ...
[ { "docstring": "Converts a list of temperatures from Celsius to Fahrenheit.\n\n:param celsius_list: List of temperatures in Celsius\n:return: List of temperatures in Fahrenheit", "function_declaration": "def celsius_to_fahrenheit(celsius_list):", "function_name": "celsius_to_fahrenheit", "parameter_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return celsius * 9/5 + 32\n\ndef generate_temperature_table(celsius_temps):\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052372", "row_id": 52372, "seed_ids": "['Qwen2.5-72B-Instruct_108100']" }
0.488442
Filter_52372
I
[ "celsius_to_fahrenheit", "display_temperature_table" ]
2
[ [ "display_temperature_table", "celsius_to_fahrenheit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ecc1b905fdc0c7629371c6f99b23a62c31b9264
9ca90d680f72106e9cb36e2324134f4de06badc7
v1.0
instruct
Filter
Filter_52388_I
Write a function in Python that calculates the square root of a number using the Newton-Raphson method. The function should take two arguments: the number for which the square root is to be calculated, and an optional argument for the initial guess, which defaults to half of the number. The function should return the s...
def sqrt_newton_raphson(number, guess=None, tolerance=1e-10): """ Calculate the square root of a number using the Newton-Raphson method. :param number: The number to find the square root of. :param guess: Initial guess for the root, defaults to half the number if not provided. :param tolerance:...
from solution import sqrt_newton_raphson def test_sqrt_positive_numbers(): assert abs(sqrt_newton_raphson(4) - 2) < 1e-10 assert abs(sqrt_newton_raphson(9) - 3) < 1e-10 assert abs(sqrt_newton_raphson(16) - 4) < 1e-10 assert abs(sqrt_newton_raphson(25) - 5) < 1e-10 def test_sqrt_special_cases(): as...
[ { "docstring": "Calculate the square root of a number using the Newton-Raphson method.\n\n:param number: The number to find the square root of.\n:param guess: Initial guess for the root, defaults to half the number if not provided.\n:param tolerance: The tolerance for the accuracy of the result.\n:return: The s...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def newton_sqrt(number, initial_guess=None, precision=10):\n \"\"\"\n Calculates the square root of a number using the Newton-Raphson method.\n \n Parameters:\n number (float): ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052388", "row_id": 52388, "seed_ids": "['Qwen2.5-72B-Instruct_108130']" }
0.64216
Filter_52388
I
[ "sqrt_newton_raphson", "check_sqrt" ]
2
[ [ "check_sqrt", "sqrt_newton_raphson" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ca1a897b5799c6b8ddc3af293bebed28447e799
5a1106064824b5447e1eaa8ffcd4bf0b74342f67
v1.0
instruct
Filter
Filter_52405_I
Design a Python function that reads a file containing paired data, processes it to compute the Euclidean distance between the points represented by the pairs, and writes the distances to a new file. The input file will have three columns: `id1`, `id2`, and `id3`, with each line representing a 3D point. The function sho...
import math def compute_euclidean_distance(point1, point2): """ Compute the Euclidean distance between two 3D points. Parameters: point1 (tuple): The first point as a tuple `(x1, y1, z1)`. point2 (tuple): The second point as a tuple `(x2, y2, z2)`. Returns: float: The Euclidean di...
from solution import compute_euclidean_distance, process_file, check_distances import os def test_compute_euclidean_distance(): assert compute_euclidean_distance((0, 0, 0), (0, 0, 0)) == 0 assert compute_euclidean_distance((1, 1, 1), (1, 1, 1)) == 0 assert math.isclose(compute_euclidean_distance((0, 0, 0),...
[ { "docstring": "Compute the Euclidean distance between two 3D points.\n\nParameters:\npoint1 (tuple): The first point as a tuple `(x1, y1, z1)`.\npoint2 (tuple): The second point as a tuple `(x2, y2, z2)`.\n\nReturns:\nfloat: The Euclidean distance between the points.", "function_declaration": "def compute_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef compute_distance(point1, point2):\n \"\"\"\n Compute the Euclidean distance between two 3D points.\n \"\"\"\n return math.sqrt((point1[0] - point2[0])**2 + (poin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052405", "row_id": 52405, "seed_ids": "['Qwen2.5-72B-Instruct_108160']" }
0.616007
Filter_52405
I
[ "compute_euclidean_distance", "process_file", "check_distances" ]
3
[ [ "process_file", "compute_euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b06a65907893c2ed67718f16c4f2b48605975828
a2d13d5d9d9ca37e74ead8a4e6026abc8f7359cb
v1.0
instruct
Filter
Filter_52429_I
Write a script in Python to find all prime numbers within a given range. Make sure to optimize the algorithm for better performance.
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import is_prime, find_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True def test_find_primes_in_range(): assert find_primes...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all prime numbers in the given range [start, end].", "function_declaration": "def find_primes_in_range(start, en...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even pr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052429", "row_id": 52429, "seed_ids": "['Qwen2.5-72B-Instruct_108188']" }
0.579082
Filter_52429
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7e6668ce70b62d65fa18c32547e5d376c024377c
07217c491eb4801fc492084c807f9dc8e3003111
v1.0
instruct
Filter
Filter_52436_I
I need to understand how to create a web crawler using Python to extract data from a specific website. Can you guide me through the process, including any legal and ethical considerations?
import requests from bs4 import BeautifulSoup def fetch_page(url): """ Fetches the content of a web page. Args: url (str): The URL of the web page to fetch. Returns: str: The HTML content of the web page. """ response = requests.get(url) response.raise_for_status() ret...
from unittest.mock import patch from solution import fetch_page, parse_html, web_crawler def test_fetch_page(): with patch('requests.get') as mock_get: class MockResponse: def raise_for_status(self): pass @property def text(self): ...
[ { "docstring": "Fetches the content of a web page.\n\nArgs:\nurl (str): The URL of the web page to fetch.\n\nReturns:\nstr: The HTML content of the web page.", "function_declaration": "def fetch_page(url):", "function_name": "fetch_page", "parameter_list": "(url)" }, { "docstring": "Parses t...
[ 0, 1, 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\n\ndef web_crawl(url):\n \"\"\"\n Crawl the specified URL and return a dictionary containing title and meta description of the page.\n A...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052436", "row_id": 52436, "seed_ids": "['Qwen2.5-72B-Instruct_108200']" }
0.610502
Filter_52436
I
[ "fetch_page", "parse_html", "web_crawler" ]
3
[ [ "web_crawler", "fetch_page" ], [ "web_crawler", "parse_html" ] ]
2
[]
false
[]
false
pytest
true
[ "bs4", "requests" ]
false
e94fa687b5d7196ed28bcbe1e6c85a76142b24c6
23e3d091255df897e919bf5e57f8e52be5567cab
v1.0
instruct
Filter
Filter_52441_I
Write a Python program that can take a list of integers as input and return a new list containing only the prime numbers from the original list. Ensure your code is well-commented to explain the logic and steps involved.
from typing import List def is_prime(num: int) -> bool: """ Helper function to determine if a number is prime. Returns True if the number is prime, False otherwise. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False ...
from solution import filter_primes def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 10]) == [] def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_mixed(): assert filter_primes([10, 15, 3, 17, 23, 25, 29, 30]) == [3, ...
[ { "docstring": "Helper function to determine if a number is prime.\nReturns True if the number is prime, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Takes a list of integers and returns a list cont...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n A prime number is only divisible by 1 and itself,\n and must be greater than 1.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052441", "row_id": 52441, "seed_ids": "['Qwen2.5-72B-Instruct_108209']" }
0.626727
Filter_52441
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6414b599d292e11be6ce38e65f0f6afa895b582d
2387c00410a78cf15b7a0ee783985a25b77feaa7
v1.0
instruct
Filter
Filter_52443_I
Write a program that calculates the product of all odd numbers between 1 and a given number n, inclusive. The program should also be able to handle large numbers efficiently. Write the program in Python, and ensure it includes a function that validates the input to ensure it is a positive integer. Additionally, provide...
def validate_input(n): """ Validates that the input is a positive integer. """ if isinstance(n, int) and n > 0: return True return False def product_of_odds(n): """ Calculates the product of all odd numbers between 1 and n, inclusive. """ if not validate_input(n): ra...
from solution import validate_input, product_of_odds def test_validate_input(): assert validate_input(5) == True assert validate_input(1) == True assert validate_input(0) == False assert validate_input(-3) == False assert validate_input('a') == False assert validate_input(3.5) == False def tes...
[ { "docstring": "Validates that the input is a positive integer.", "function_declaration": "def validate_input(n):", "function_name": "validate_input", "parameter_list": "(n)" }, { "docstring": "Calculates the product of all odd numbers between 1 and n, inclusive.", "function_declaration"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def validate_input(n):\n \"\"\"\n Validates that the input n is a positive integer.\n \"\"\"\n if isinstance(n, int) and n > 0:\n return True\n return False\n\ndef produc...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052443", "row_id": 52443, "seed_ids": "['Qwen2.5-72B-Instruct_108212']" }
0.635403
Filter_52443
I
[ "validate_input", "product_of_odds" ]
2
[ [ "product_of_odds", "validate_input" ] ]
1
[]
false
[]
false
pytest
true
[]
true
25f4bd474c46ef7bdae5ec5a38ea80f2adef8c9b
989ae2043ce1e29a622f5d9aac7514a79f30bd8c
v1.0
instruct
Filter
Filter_52445_I
Create a step-by-step guide on how to create a simple calculator application using Python. Include explanations for each step and code snippets where applicable. The calculator should be able to perform basic operations like addition, subtraction, multiplication, and division.
# Step-by-step guide to creating a simple calculator in Python # 1. Define the basic functions for the calculator. 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): """ ...
from solution import add, subtract, multiply, divide def test_add(): assert add(1, 2) == 3 assert add(-1, 1) == 0 assert add(0, 0) == 0 assert add(1.5, 2.5) == 4.0 def test_subtract(): assert subtract(2, 1) == 1 assert subtract(-1, 1) == -2 assert subtract(0, 0) == 0 assert subtract(2....
[ { "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, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Step-by-step guide to creating a simple calculator in Python\n\n# 1. Define the basic functions for the calculator.\ndef add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052445", "row_id": 52445, "seed_ids": "['Qwen2.5-72B-Instruct_108215']" }
0.522694
Filter_52445
I
[ "add", "subtract", "multiply", "divide", "menu", "calculator" ]
6
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "menu" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
5
[]
false
[]
false
pytest
true
[]
true
464bd48b0e432629e0fa889d3e54dcfec5509c53
c061993243b0d4240fb2df5818bd1bec5b018527
v1.0
instruct
Filter
Filter_52463_I
Write a Python program that computes the factorial of a number using recursion and handles potential stack overflow by setting a maximum recursion depth. The program should also allow the user to input the number and display the result or an error message if the input is invalid or the recursion depth is exceeded.
import sys def factorial(n, max_depth, current_depth=0): """ Computes the factorial of a number using recursion, with a maximum recursion depth. Args: n (int): The number to compute the factorial of. max_depth (int): Maximum allowed recursion depth. current_depth (int): Current depth of th...
from solution import factorial def test_factorial_base_cases(): assert factorial(0, 10) == 1 assert factorial(1, 10) == 1 def test_factorial_small_numbers(): assert factorial(2, 10) == 2 assert factorial(3, 10) == 6 assert factorial(4, 10) == 24 def test_factorial_large_numbers(): assert fact...
[ { "docstring": "Computes the factorial of a number using recursion, with a maximum recursion depth.\n\nArgs:\nn (int): The number to compute the factorial of.\nmax_depth (int): Maximum allowed recursion depth.\ncurrent_depth (int): Current depth of the recursion (default is 0).\n\nReturns:\nint: Factorial of th...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\n\ndef factorial(n, max_depth, current_depth=0):\n \"\"\"\n Recursively calculates the factorial of a number n.\n \n Params:\n n (int): the number to calculate the fa...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052463", "row_id": 52463, "seed_ids": "['Qwen2.5-72B-Instruct_108243']" }
0.596559
Filter_52463
I
[ "factorial", "user_factorial_calculation" ]
2
[ [ "user_factorial_calculation", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e00e241348840677809f28a79748754fb0283d69
a05ccdc18f537441f2cdd0fc634fc113dccf9ee8
v1.0
instruct
Filter
Filter_52479_I
Hello, can you help me with a quick programming question? I'm trying to understand how to use the map function in Python to apply a function to all items in a list.
def square(number): """ Returns the square of a number. """ return number * number def apply_map_to_square(numbers): """ Applies the square function to all items in the list using map. """ return list(map(square, numbers))
from solution import square, apply_map_to_square def test_square(): assert square(3) == 9 assert square(-2) == 4 assert square(0) == 0 def test_apply_map_to_square(): assert apply_map_to_square([1, 2, 3, 4, 5]) == [1, 4, 9, 16, 25] assert apply_map_to_square([-1, -2, -3]) == [1, 4, 9] assert a...
[ { "docstring": "Returns the square of a number.", "function_declaration": "def square(number):", "function_name": "square", "parameter_list": "(number)" }, { "docstring": "Applies the square function to all items in the list using map.", "function_declaration": "def apply_map_to_square(n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def square(x):\n \"\"\"\n Returns the square of x.\n \"\"\"\n return x ** 2\n\ndef apply_function_to_list(func, lst):\n \"\"\"\n Applies a given function to all items in a li...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052479", "row_id": 52479, "seed_ids": "['Qwen2.5-72B-Instruct_108274']" }
0.451186
Filter_52479
I
[ "square", "apply_map_to_square" ]
2
[ [ "apply_map_to_square", "square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a07b86dce6c8ff0584c630f6a39b448677f47a3
6bbbe8b7df1bae0a9ab15294f2c0db19c45b90c2
v1.0
instruct
Filter
Filter_52493_I
Explain the purpose and main features of the 'map' function in Python, and provide an example of how it can be used to transform a list of numbers.
def square(number): """ Returns the square of a number. """ return number ** 2 def square_list(numbers): """ Applies the square function to each number in the list using map. """ return list(map(square, numbers))
from solution import square, square_list def test_square(): assert square(3) == 9 assert square(-2) == 4 assert square(0) == 0 def test_square_list(): assert square_list([1, 2, 3, 4, 5]) == [1, 4, 9, 16, 25] assert square_list([-1, -2, -3]) == [1, 4, 9] assert square_list([0, 3, 6]) == [0, 9, ...
[ { "docstring": "Returns the square of a number.", "function_declaration": "def square(number):", "function_name": "square", "parameter_list": "(number)" }, { "docstring": "Applies the square function to each number in the list using map.", "function_declaration": "def square_list(numbers...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def square(n):\n \"\"\"\n Returns the square of n.\n \"\"\"\n return n * n\n\ndef transform_list(numbers):\n \"\"\"\n Accepts a list of numbers and returns a new list with ea...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052493", "row_id": 52493, "seed_ids": "['Qwen2.5-72B-Instruct_108297']" }
0.510366
Filter_52493
I
[ "square", "square_list" ]
2
[ [ "square_list", "square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c4c458e46452a2df4491b9cb7f97b8ea266d8dc
5e93b62c13d2ee228de1622e82c8b0ffe31cc2de
v1.0
instruct
Filter
Filter_52514_I
Design a Python script that performs the following task: Given a directory path as input, the script should scan the directory (not recursively) and calculate the total size of all files found in the directory. The output should display the total size in bytes, as well as in a more human-readable form (KB, MB, GB, etc....
import os def get_total_size(directory_path): """ Calculate the total size of all files in the given directory (non-recursively). Parameters: directory_path (str): The path to the directory. Returns: tuple: The total size in bytes and as a human-readable string. """ # Check if the dir...
import pytest from solution import get_total_size, human_readable_size import os def create_test_files(dir_path, files): if not os.path.exists(dir_path): os.makedirs(dir_path) for file_name, size in files.items(): with open(os.path.join(dir_path, file_name), 'wb') as f: f.write(b'\0...
[ { "docstring": "Calculate the total size of all files in the given directory (non-recursively).\n\nParameters:\ndirectory_path (str): The path to the directory.\n\nReturns:\ntuple: The total size in bytes and as a human-readable string.", "function_declaration": "def get_total_size(directory_path):", "f...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef get_total_size(directory_path):\n \"\"\"\n Calculate the total size of all files in the given directory (non-recursively).\n\n Parameters:\n directory_path (str): ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052514", "row_id": 52514, "seed_ids": "['Qwen2.5-72B-Instruct_108329']" }
0.656436
Filter_52514
I
[ "get_total_size", "human_readable_size" ]
2
[ [ "get_total_size", "human_readable_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
122b66789b175d079224ee7da6691650218dca57
fd3b0418c9eff0b3c043f0ff48d207ebc5e37b74
v1.0
instruct
Filter
Filter_52515_I
Given a positive integer n, write a Python function to find the n-th Fibonacci number using matrix exponentiation. The Fibonacci sequence is defined as follows: F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1. The function should efficiently compute large Fibonacci numbers.
def matrix_mult(A, B): """ Multiplies two 2x2 matrices A and B. """ return [ [A[0][0]*B[0][0] + A[0][1]*B[1][0], A[0][0]*B[0][1] + A[0][1]*B[1][1]], [A[1][0]*B[0][0] + A[1][1]*B[1][0], A[1][0]*B[0][1] + A[1][1]*B[1][1]] ] def matrix_pow(M, power): """ Raises the matrix M to ...
from solution import fibonacci def test_fibonacci_first_elements(): assert fibonacci(0) == 0 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_fibonacci_larger_numbers(): ...
[ { "docstring": "Multiplies two 2x2 matrices A and B.", "function_declaration": "def matrix_mult(A, B):", "function_name": "matrix_mult", "parameter_list": "(A, B)" }, { "docstring": "Raises the matrix M to the specified power using exponentiation by squaring.", "function_declaration": "d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052515", "row_id": 52515, "seed_ids": "['Qwen2.5-72B-Instruct_108330']" }
0.710494
Filter_52515
I
[ "matrix_mult", "matrix_pow", "fibonacci" ]
3
[ [ "fibonacci", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1a8a20ce830c38015905ecab7170e35856ad8532
a96ea55b9acb7b5cac48e1ee5edb8ab3e875a283
v1.0
instruct
Filter
Filter_52534_I
Design a Python function to implement a simple linear regression model using only numpy, without using any external libraries like scikit-learn. The function should accept training data and their corresponding labels, and return the learned parameters (slope and intercept). Additionally, create a check function to vali...
import numpy as np def simple_linear_regression(X, y): """ Simple linear regression using numpy. Parameters: X (numpy array): 1D array of input features. y (numpy array): 1D array of target values. Returns: (float, float): tuple containing slope and intercept of the best fit line....
import numpy as np from solution import simple_linear_regression, check_simple_linear_regression def test_simple_linear_regression_known_values(): X = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 5, 4, 5]) slope, intercept = simple_linear_regression(X, y) correct_slope, correct_intercept = 0...
[ { "docstring": "Simple linear regression using numpy.\n\nParameters:\nX (numpy array): 1D array of input features.\ny (numpy array): 1D array of target values.\n\nReturns:\n(float, float): tuple containing slope and intercept of the best fit line.", "function_declaration": "def simple_linear_regression(X, y...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef simple_linear_regression(X, y):\n \"\"\"\n Simple linear regression using numpy.\n \n Parameters:\n X (numpy array): 1D array of input features.\n y...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052534", "row_id": 52534, "seed_ids": "['Qwen2.5-72B-Instruct_108360']" }
0.641444
Filter_52534
I
[ "simple_linear_regression", "check_simple_linear_regression" ]
2
[ [ "check_simple_linear_regression", "simple_linear_regression" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
eb31f95798e6de65636efcc30d3d3500870b2b49
a04d5b31711631ab3e7245d344f959d9830f123e
v1.0
instruct
Filter
Filter_52556_I
Write a Python function to check if a number is a prime number. Then, write another function to list all prime numbers up to a given number. Ensure both functions are efficient and well-documented.
def is_prime(n): """ Check if a given number n is a prime number. Parameters: n (int): The number to check. Returns: bool: True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: ...
from solution import is_prime, list_primes_up_to def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime(0) == F...
[ { "docstring": "Check if a given number n is a prime number.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Li...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \n Parameters:\n n (int): The number to be checked.\n \n Returns:\n bool: True if the ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052556", "row_id": 52556, "seed_ids": "['Qwen2.5-72B-Instruct_108401']" }
0.737825
Filter_52556
I
[ "is_prime", "list_primes_up_to" ]
2
[ [ "list_primes_up_to", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f6f39a16a89d8d37f4f0bb0bfbd44714e6dd70f
34f04bd0cbab075df6f6be2fe62ceb9f9729d223
v1.0
instruct
Filter
Filter_52559_I
How can I create a custom encryption algorithm in Python that is simple but effective for small projects?
def encrypt_caesar_cipher(plaintext, shift): """ Encrypts the given plaintext using a Caesar cipher with the provided shift. Parameters: plaintext (str): The message to be encrypted. shift (int): The number of positions to shift each character. Returns: str: The encrypted message. ...
from solution import encrypt_caesar_cipher, decrypt_caesar_cipher def test_encrypt_caesar_cipher(): assert encrypt_caesar_cipher("HELLO", 3) == "KHOOR" assert encrypt_caesar_cipher("hello", 3) == "khoor" assert encrypt_caesar_cipher("xyz", 3) == "abc" assert encrypt_caesar_cipher("XYZ", 3) == "ABC" ...
[ { "docstring": "Encrypts the given plaintext using a Caesar cipher with the provided shift.\n\nParameters:\nplaintext (str): The message to be encrypted.\nshift (int): The number of positions to shift each character.\n\nReturns:\nstr: The encrypted message.", "function_declaration": "def encrypt_caesar_ciph...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def encrypt(text, shift):\n \"\"\"\n Encrypts the text using a simple substitution cipher by shifting letters.\n \"\"\"\n encrypted_text = \"\"\n for char in text:\n if c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052559", "row_id": 52559, "seed_ids": "['Qwen2.5-72B-Instruct_108405']" }
0.555144
Filter_52559
I
[ "encrypt_caesar_cipher", "decrypt_caesar_cipher" ]
2
[ [ "decrypt_caesar_cipher", "encrypt_caesar_cipher" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c5af11d84269e66a2f4ead39b29b966355832f4
47f82b9701e8e89ead991b1f67dd1429c3cf8233
v1.0
instruct
Filter
Filter_52564_I
Create a Python script that can convert a given temperature from Fahrenheit to Celsius and back. It should have a user-friendly interface and handle errors gracefully, such as input validation for temperature and scale.
def fahrenheit_to_celsius(f_temp): """ Converts Fahrenheit to Celsius. """ return (f_temp - 32) * 5.0/9.0 def celsius_to_fahrenheit(c_temp): """ Converts Celsius to Fahrenheit. """ return c_temp * 9.0/5.0 + 32 def convert_temperature(temp, scale): """ Converts a given temperatu...
from solution import fahrenheit_to_celsius, celsius_to_fahrenheit, convert_temperature def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(-40) == -40 def test_celsius_to_fahrenheit(): assert celsius_to_fahrenhei...
[ { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(f_temp):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(f_temp)" }, { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(c...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts Fahrenheit to Celsius.\n \"\"\"\n return (fahrenheit - 32) * 5.0 / 9.0\n\ndef celsius_to_fahrenheit(celsius):\n \"\"\"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052564", "row_id": 52564, "seed_ids": "['Qwen2.5-72B-Instruct_108410']" }
0.429507
Filter_52564
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
b94dcbb360f5ec2b3bba715e3b453c62d0d1aa9d
4f8a5b530c698ac90e433c7e918a33013f39aaf0
v1.0
instruct
Filter
Filter_52588_I
Write a Python program to implement a simple recommendation system using a dataset of movie ratings. The program should be able to recommend movies to a user based on their previous ratings. Use the collaborative filtering method. Explain the steps and provide the code.
from math import sqrt def pearson_similarity(user1_ratings, user2_ratings): common_ratings = {} for movie in user1_ratings: if movie in user2_ratings: common_ratings[movie] = 1 num_ratings = len(common_ratings) if num_ratings == 0: return 0 user1_sum = sum([user1_ratin...
import pytest from solution import pearson_similarity, recommend_movies def test_pearson_similarity_perfect(): user1 = {'Movie1': 5, 'Movie2': 3, 'Movie3': 4} user2 = {'Movie1': 5, 'Movie2': 3, 'Movie3': 4} assert pearson_similarity(user1, user2) == 1 def test_pearson_similarity_no_overlap(): user1 = ...
[ { "docstring": null, "function_declaration": "def pearson_similarity(user1_ratings, user2_ratings):", "function_name": "pearson_similarity", "parameter_list": "(user1_ratings, user2_ratings)" }, { "docstring": null, "function_declaration": "def recommend_movies(user, ratings):", "fun...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import sqrt\n\ndef pearson_similarity(user1_ratings, user2_ratings):\n common_ratings = {}\n for movie in user1_ratings:\n if movie in user2_ratings:\n common...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052588", "row_id": 52588, "seed_ids": "['Qwen2.5-72B-Instruct_108441']" }
0.426066
Filter_52588
I
[ "pearson_similarity", "recommend_movies" ]
2
[ [ "recommend_movies", "pearson_similarity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
584f049f2513f76cc11caa3b453c0001dea9bf39
7e4de4d0e7fab247b0dd3e82b74d45d277d395bd
v1.0
instruct
Filter
Filter_52589_I
Can you assist me with a basic Python script to monitor the availability of a website? It should check if the website is up and running, and if not, send an email notification.
import smtplib import requests def send_email(subject, message, from_email, to_email, smtp_server, smtp_port, username, password): """ Send an email notification. """ with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() server.login(username, password) email_me...
from solution import check_website, send_email import pytest import requests from unittest.mock import patch def test_send_email(): with patch("smtplib.SMTP") as mock_smtp: send_email("Test Subject", "Test Message", "from@example.com", "to@example.com", "smtp.example.com", 587, "username", "password") ...
[ { "docstring": "Send an email notification.", "function_declaration": "def send_email(subject, message, from_email, to_email, smtp_server, smtp_port, username, password):", "function_name": "send_email", "parameter_list": "(subject, message, from_email, to_email, smtp_server, smtp_port, username, pa...
[ 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 requests\n\ndef check_website(url):\n \"\"\"\n Checks if the website is up and running.\n \n Parameters:\n url (str): The URL of the website to check.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052589", "row_id": 52589, "seed_ids": "['Qwen2.5-72B-Instruct_108442']" }
0.534668
Filter_52589
I
[ "send_email", "check_website" ]
2
[ [ "check_website", "send_email" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
c864917c85830ab312327742af345d38ef941d7b
5cc3e485f85e2162294253e0936ee22acd19847f
v1.0
instruct
Filter
Filter_52593_I
Generate a code snippet in Python that takes a user's input, which is expected to be a positive integer, and checks if the input is a prime number. Make sure to handle invalid inputs (non-integer values, negative numbers, and zero). If the input is invalid, print an appropriate message. If the number is a prime, print ...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(10) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(-3) == False def test_check_prime(monkeypatch, capsys): ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a user's input and checks if it's a prime number.\nHandles invalid inputs and prints appropriate messag...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052593", "row_id": 52593, "seed_ids": "['Qwen2.5-72B-Instruct_108448']" }
0.753363
Filter_52593
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f06019c5af1e84aa0dfbbb5f26d9e9ac3a36cf9e
029b0d540d8b318177afc3754e25bd803dcb269d
v1.0
instruct
Filter
Filter_52618_I
Design a basic chatbot using Python that can respond to simple user greetings and farewells. The chatbot should be able to recognize phrases like "hello," "hi," "good morning," "goodbye," and "see you later." For greetings, it should respond with "Hello! How can I help you today?" and for farewells, it should respond w...
def chatbot_response(user_input): """ Responds to user greetings and farewells based on the given input. Parameters: user_input (str): The user's input message. Returns: str: The chatbot's response. """ greetings = ["hello", "hi", "good morning"] farewells = ["goodbye", "se...
from solution import chatbot_response def test_chatbot_greetings(): assert chatbot_response("hello") == "Hello! How can I help you today?" assert chatbot_response("hi") == "Hello! How can I help you today?" assert chatbot_response("good morning") == "Hello! How can I help you today?" def test_chatbot_fare...
[ { "docstring": "Responds to user greetings and farewells based on the given input.\n\nParameters:\nuser_input (str): The user's input message.\n\nReturns:\nstr: The chatbot's response.", "function_declaration": "def chatbot_response(user_input):", "function_name": "chatbot_response", "parameter_list...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Chatbot:\n def __init__(self):\n self.greetings = [\"hello\", \"hi\", \"good morning\"]\n self.farewells = [\"goodbye\", \"see you later\"]\n \n def respond(self, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052618", "row_id": 52618, "seed_ids": "['Qwen2.5-72B-Instruct_108491']" }
0.405513
Filter_52618
I
[ "chatbot_response", "run_chatbot" ]
2
[ [ "run_chatbot", "chatbot_response" ] ]
1
[]
false
[]
false
pytest
true
[]
true
109a4a190c038dcc8d197ebd7cc0c38ea155379f
1c5d1f621589a7adeb902b487b63f10563290242
v1.0
instruct
Filter
Filter_52626_I
Write a Python program that implements a basic calculator with addition, subtraction, multiplication, and division. The program should take two numbers as input and then ask the user which operation to perform. It should then output the result of the operation. Make sure to handle division by zero errors gracefully.
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: return "Error: Division by zero" return a / b def calculator(a, b, operation): if operation == 'add': return add(a, b) elif operation == 'subtract': ...
from solution import add, subtract, multiply, divide, calculator def test_add(): assert add(3, 5) == 8 assert add(-2, 4) == 2 def test_subtract(): assert subtract(10, 5) == 5 assert subtract(2, 4) == -2 def test_multiply(): assert multiply(3, 5) == 15 assert multiply(-2, 4) == -8 def test_di...
[ { "docstring": null, "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_list": "(a, b)" }, { "docstring": null, "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n return \"Error: Division by zer...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052626", "row_id": 52626, "seed_ids": "['Qwen2.5-72B-Instruct_108504']" }
0.608148
Filter_52626
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
e391e21ca200314116b861235412c2c7f7e2cac7
87ad24e7c6da1c67ae4a13abb5194ed94b0870d1
v1.0
instruct
Filter
Filter_52642_I
Write a program that generates a random 4-digit number, where the digits are unique and do not form a sequence (like 1234 or 4321).
import random def generate_unique_non_sequential_number(): while True: digits = random.sample(range(10), 4) if is_non_sequential(digits): return int(''.join(map(str, digits))) def is_non_sequential(digits): for i in range(len(digits) - 1): if digits[i] + 1 == digits[i + 1] ...
from solution import generate_unique_non_sequential_number, is_non_sequential def test_is_non_sequential(): assert is_non_sequential([1, 3, 5, 7]) == True assert is_non_sequential([1, 2, 3, 4]) == False assert is_non_sequential([4, 3, 2, 1]) == False assert is_non_sequential([9, 7, 5, 3]) == True def ...
[ { "docstring": null, "function_declaration": "def generate_unique_non_sequential_number():", "function_name": "generate_unique_non_sequential_number", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def is_non_sequential(digits):", "function_name": "is_non_seq...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_unique_non_sequence_4digit_number():\n while True:\n number = random.sample(range(10), 4)\n if all((number[i] + 1 != number[i + 1] and number[i] ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052642", "row_id": 52642, "seed_ids": "['Qwen2.5-72B-Instruct_108533']" }
0.514443
Filter_52642
I
[ "generate_unique_non_sequential_number", "is_non_sequential" ]
2
[ [ "generate_unique_non_sequential_number", "is_non_sequential" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e41a4c25d1ea3755b6e1b47b6f531459ad1ce15d
ec24e7d629de85d7f2b2e1e949fdbb9287f4bd9d
v1.0
instruct
Filter
Filter_52655_I
Develop a simple calculator in Python that can perform basic arithmetic operations (addition, subtraction, multiplication, division) and also handle floating point numbers. It should include a user interface where users can input two numbers and choose an operation. The program should then display the result. Make sure...
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 division of a ...
from solution import add, subtract, multiply, divide, calculator def test_add(): assert add(2, 3) == 5 assert add(-1, 5) == 4 assert add(0, 0) == 0 assert add(2.5, 3.1) == 5.6 def test_subtract(): assert subtract(5, 3) == 2 assert subtract(2, 4) == -2 assert subtract(-1, -1) == 0 asser...
[ { "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...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef subtract(a, b):\n \"\"\"\n Returns the result of subtracting b from a.\n \"\"\"\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052655", "row_id": 52655, "seed_ids": "['Qwen2.5-72B-Instruct_108552']" }
0.530657
Filter_52655
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b8a567a0dfa8f5828ac041343fc15a17776c6868
204275216a4ea68f045858508aab40a8bbac8b22
v1.0
instruct
Filter
Filter_52662_I
Can you create a Python script that automates the process of converting a list of temperatures from Fahrenheit to Celsius and stores the converted temperatures in a CSV file? The script should take a list of temperatures in Fahrenheit as input and write the converted temperatures to a CSV file with two columns: one for...
import csv def fahrenheit_to_celsius(fahrenheit_temp): """ Converts a temperature from Fahrenheit to Celsius. Parameters: fahrenheit_temp (float): The temperature in Fahrenheit. Returns: float: The temperature in Celsius. """ return (fahrenheit_temp - 32) * 5.0/9.0 def conver...
from solution import fahrenheit_to_celsius, convert_and_store_temperatures import os import csv def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert abs(fahrenheit_to_celsius(98.6) - 37) < 0.1 assert fahrenheit_to_celsius(-40) == -40 d...
[ { "docstring": "Converts a temperature from Fahrenheit to Celsius.\n\nParameters:\nfahrenheit_temp (float): The temperature in Fahrenheit.\n\nReturns:\nfloat: The temperature in Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit_temp):", "function_name": "fahrenheit_to_celsius", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts a temperature from Fahrenheit to Celsius.\n \"\"\"\n return (fahrenheit - 32) * 5.0/9.0\n\ndef convert_and_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052662", "row_id": 52662, "seed_ids": "['Qwen2.5-72B-Instruct_108561']" }
0.59573
Filter_52662
I
[ "fahrenheit_to_celsius", "convert_and_store_temperatures" ]
2
[ [ "convert_and_store_temperatures", "fahrenheit_to_celsius" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cdfc39825548b74fd810557d712dc10a4a9c2e42
e8ad2232613304fd535f14266b3ea9ee965c8c1f
v1.0
instruct
Filter
Filter_52710_I
Create a Python function to sort a list of dictionaries based on a specific key. The key can be a nested key, and the function should handle nested keys gracefully. The function should also allow for sorting in both ascending and descending order, with ascending being the default. The function should be able to handle ...
def get_nested_value(d, keys): """ Helper function to get the value from a nested dictionary using a list of keys. """ for key in keys: if isinstance(d, dict) and key in d: d = d[key] else: return None return d def sort_dicts(dicts, key, reverse=False): "...
from solution import sort_dicts def test_sort_basic(): data = [ {'name': 'John', 'age': 30}, {'name': 'Jane', 'age': 25}, {'name': 'Doe', 'age': 35} ] sorted_data = sort_dicts(data, ['age']) assert sorted_data == [ {'name': 'Jane', 'age': 25}, {'name': 'John', 'a...
[ { "docstring": "Helper function to get the value from a nested dictionary using a list of keys.", "function_declaration": "def get_nested_value(d, keys):", "function_name": "get_nested_value", "parameter_list": "(d, keys)" }, { "docstring": "Sorts a list of dictionaries by a specific key, in...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_dicts(dict_list, key, descending=False):\n \"\"\"\n Sorts a list of dictionaries based on a specific (possibly nested) key.\n \n Parameters:\n dict_list (list): List of...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052710", "row_id": 52710, "seed_ids": "['Qwen2.5-72B-Instruct_108643']" }
0.675709
Filter_52710
I
[ "get_nested_value", "sort_dicts" ]
2
[ [ "sort_dicts", "get_nested_value" ] ]
1
[]
false
[]
false
pytest
true
[]
true
260119d8f00c25c40e44d194dfb3b2db3cf9f17b
73a1d0e6eb2b2ec3655ce827862a29dffbe959db
v1.0
instruct
Filter
Filter_52714_I
Can you write a Python function to calculate the product of elements in a specific row of a 2D array? The function should take two parameters: the 2D array and the row index. Make sure to include a check function with provided data points to verify the correctness of your solution.
def row_product(matrix, row_index): """ Returns the product of elements in a specific row of a 2D array. :param matrix: List of lists representing the 2D array :param row_index: Integer representing the index of the row :return: The product of elements in the specified row """ if not 0 ...
from solution import row_product, check def test_row_product(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert row_product(matrix, 0) == 6 assert row_product(matrix, 1) == 120 assert row_product(matrix, 2) == 504 def test_row_product_single_element_rows(): mat...
[ { "docstring": "Returns the product of elements in a specific row of a 2D array.\n\n:param matrix: List of lists representing the 2D array\n:param row_index: Integer representing the index of the row\n:return: The product of elements in the specified row", "function_declaration": "def row_product(matrix, ro...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def row_product(matrix, row_index):\n \"\"\"\n Returns the product of elements in a specific row of a 2D array.\n \n Parameters:\n matrix (list of list of int/float): The 2D arr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052714", "row_id": 52714, "seed_ids": "['Qwen2.5-72B-Instruct_108650']" }
0.674566
Filter_52714
I
[ "row_product", "check" ]
2
[ [ "check", "row_product" ] ]
1
[]
false
[]
false
pytest
true
[]
true
324ce76ae96a8660b1a4b7a605fb8aab3bf413b7
12faea8a46fcff753e09e0ccc705e44e92e5f1d1
v1.0
instruct
Filter
Filter_52767_I
Can you provide a detailed explanation of the Merge Sort algorithm, and how it can be implemented in Python? Please include a step-by-step breakdown of the algorithm, and an example implementation.
def merge_sort(arr): """ Sorts an array using the Merge Sort algorithm. """ if len(arr) <= 1: return arr # Divide the array into two halves mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] # Recursively sort both halves sorted_left = merge_sort(left_half...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert...
[ { "docstring": "Sorts an array using the Merge Sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def merge(left, right):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n L = arr[:mid]\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052767", "row_id": 52767, "seed_ids": "['Qwen2.5-72B-Instruct_108731']" }
0.568417
Filter_52767
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f9a72ced616ff4be60a16cb52a13747d079244f8
4dd101c00344ef8eb3cb5b1da105aad75cfe6154
v1.0
instruct
Filter
Filter_52768_I
write python program to print prime numbers between 1 to 100
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def prime_numbers_between_1_to_100(): """ Returns a list of prime numbers between 1...
from solution import is_prime, prime_numbers_between_1_to_100 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_pri...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers between 1 to 100.", "function_declaration": "def prime_numbers_between_1_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_primes_between_1_to_100():\n \"\"\"\n Returns a list of prime numbers between 1 and 100.\n \"\"\"\n primes = []\n for num in range(2, 101):\n is_prime = True\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052768", "row_id": 52768, "seed_ids": "['Qwen2.5-72B-Instruct_108732']" }
0.643687
Filter_52768
I
[ "is_prime", "prime_numbers_between_1_to_100" ]
2
[ [ "prime_numbers_between_1_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42b2bb6cde0dcd7170a6bff0c31ad26e5595a7dc
4922b78b92cc33734299cb93676782f77e823456
v1.0
instruct
Filter
Filter_52774_I
I need to create a Python script that will monitor a folder for new files and automatically process them. How can I achieve this using Python? Can you provide a basic example?
import time import os def process_file(filepath): """ Process the given file. For this example, we'll just print the file name. """ print(f"Processing file: {filepath}") def monitor_folder(folder_path, interval=1): """ Monitors the given folder for new files and processes them. Pa...
import time import os import shutil import pytest from solution import process_file, monitor_folder TEST_FOLDER = "test_folder" @pytest.fixture def setup_test_folder(): # Setup test folder os.makedirs(TEST_FOLDER, exist_ok=True) yield # Teardown test folder shutil.rmtree(TEST_FOLDER) def test_pro...
[ { "docstring": "Process the given file.\nFor this example, we'll just print the file name.", "function_declaration": "def process_file(filepath):", "function_name": "process_file", "parameter_list": "(filepath)" }, { "docstring": "Monitors the given folder for new files and processes them.\n...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport os\n\ndef monitor_folder(folder_path, process_file_callback):\n \"\"\"\n Monitors a folder for new files and processes them using the provided callback function.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052774", "row_id": 52774, "seed_ids": "['Qwen2.5-72B-Instruct_108744']" }
0.510413
Filter_52774
I
[ "process_file", "monitor_folder" ]
2
[ [ "monitor_folder", "process_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ddacb5c39e808230e0d3af6996944bb2235580f7
c29a247c09895d8c1c87bd6c9f44c4edc8fadc03
v1.0
instruct
Filter
Filter_52809_I
I need help with a basic Python script to automate the process of checking if my website is up and running. Can you guide me on how to write this script? I want it to send an email notification if the website is down.
import smtplib import requests from email.mime.text import MIMEText def check_website_status(url): """ Checks if the website is up and running by sending a GET request. Returns True if the website is up, False otherwise. """ try: response = requests.get(url) return response.status_c...
from solution import check_website_status, send_email_notification, monitor_website from unittest.mock import patch, Mock def test_check_website_status_up(): with patch('requests.get') as mock_get: mock_get.return_value.status_code = 200 assert check_website_status('http://example.com') == True de...
[ { "docstring": "Checks if the website is up and running by sending a GET request.\nReturns True if the website is up, False otherwise.", "function_declaration": "def check_website_status(url):", "function_name": "check_website_status", "parameter_list": "(url)" }, { "docstring": "Sends an em...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import smtplib\nimport requests\nfrom email.mime.text import MIMEText\n\ndef check_website_status(url):\n \"\"\"\n Checks if the website is up and running by sending a GET request.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052809", "row_id": 52809, "seed_ids": "['Qwen2.5-72B-Instruct_108802']" }
0.520044
Filter_52809
I
[ "check_website_status", "send_email_notification", "monitor_website" ]
3
[ [ "monitor_website", "check_website_status" ], [ "monitor_website", "send_email_notification" ] ]
2
[]
false
[]
false
pytest
true
[ "requests" ]
false
5a9d2d28cbe7eee346f7be4ead9f7f0227c24a36
edbeea4b7ce194b39e0ada17ab6510eb3fd994ad
v1.0
instruct
Filter
Filter_52854_I
Implement a function in Python that takes a 1-dimensional array as input and returns the indices of the top K elements in descending order. For instance, if you have an array `A = [5.5, 6.5, 2.5, 4.5, 3.5]` and you are asked to find the top 3 elements, the function should return the indices `[1, 0, 4]`, corresponding t...
def top_k_indices(arr, k): """ Returns the indices of the top K elements in descending order. Parameters: arr (list): 1-dimensional array of elements k (int): the number of top elements to retrieve Returns: list: indices of the top K elements in descending order """ # Sort indi...
from solution import top_k_indices def test_top_k_indices_standard_case(): A = [5.5, 6.5, 2.5, 4.5, 3.5] assert top_k_indices(A, 3) == [1, 0, 3] def test_top_k_indices_k_equals_one(): A = [5.5, 6.5, 2.5, 4.5, 3.5] assert top_k_indices(A, 1) == [1] def test_top_k_indices_k_equals_zero(): A = [5.5,...
[ { "docstring": "Returns the indices of the top K elements in descending order.\n\nParameters:\narr (list): 1-dimensional array of elements\nk (int): the number of top elements to retrieve\n\nReturns:\nlist: indices of the top K elements in descending order", "function_declaration": "def top_k_indices(arr, k...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def top_k_indices(arr, k):\n \"\"\"\n Returns the indices of the top K elements in descending order.\n \n Parameters:\n arr (list): 1-dimensional array of elements\n k (int):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052854", "row_id": 52854, "seed_ids": "['Qwen2.5-72B-Instruct_108876']" }
0.605528
Filter_52854
I
[ "top_k_indices", "check" ]
2
[ [ "check", "top_k_indices" ] ]
1
[]
false
[]
false
pytest
true
[]
true
389d87dc513ebfaef132163ceed57b45cdd9a794
cf9b8adff5b8f5766e2f6d56cd87c5ed1a49b46b
v1.0
instruct
Filter
Filter_52893_I
I want to simulate a reaction-diffusion system on a 2D grid using Python. The system should follow the Gray-Scott model. How can I code this simulation?
import numpy as np import matplotlib.pyplot as plt def initialize_grid(grid_size, initial_fill=0.2): """ Initialize the grid for the Gray-Scott model. grid_size: tuple of two integers, the size of the 2D grid. initial_fill: proportion of the area to be initially filled with U and V. """ U = np....
import numpy as np from solution import initialize_grid, update, simulate def test_initialize_grid(): grid_size = (100, 100) initial_fill = 0.2 U, V = initialize_grid(grid_size, initial_fill) assert U.shape == grid_size assert V.shape == grid_size assert np.sum(U <= 1) == np.prod(grid_size...
[ { "docstring": "Initialize the grid for the Gray-Scott model.\ngrid_size: tuple of two integers, the size of the 2D grid.\ninitial_fill: proportion of the area to be initially filled with U and V.", "function_declaration": "def initialize_grid(grid_size, initial_fill=0.2):", "function_name": "initialize...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef initialize_grid(size, feed, kill):\n U = np.ones((size, size))\n V = np.zeros((size, size))\n \n mid = size // 2\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052893", "row_id": 52893, "seed_ids": "['Qwen2.5-72B-Instruct_108935']" }
0.382745
Filter_52893
I
[ "initialize_grid", "update", "simulate" ]
3
[ [ "simulate", "initialize_grid" ], [ "simulate", "update" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
577d78a4b2648462603e4eb5e374e0cc85000005
e87bc06b7a779d1e0ba0141f1f9aad38ec9e9529
v1.0
instruct
Filter
Filter_52894_I
Design a Python program that implements a genetic algorithm to optimize a simple mathematical function, such as finding the maximum value of a function within a specific range. Include comments in your code to explain each part of the algorithm. Additionally, provide a brief explanation of the genetic algorithm and how...
import numpy as np def fitness_function(x): """ Fitness function to evaluate the fitness of an individual. We use a simple quadratic function f(x) = x^2 as the fitness function. """ return x ** 2 def initialize_population(size, lower_bound, upper_bound): """ Initialize a population with ra...
import numpy as np from solution import fitness_function, initialize_population, select_parents, crossover, mutate, genetic_algorithm def test_fitness_function(): assert fitness_function(0) == 0 assert fitness_function(2) == 4 assert fitness_function(-2) == 4 def test_initialize_population(): populati...
[ { "docstring": "Fitness function to evaluate the fitness of an individual.\nWe use a simple quadratic function f(x) = x^2 as the fitness function.", "function_declaration": "def fitness_function(x):", "function_name": "fitness_function", "parameter_list": "(x)" }, { "docstring": "Initialize ...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef fitness_function(x):\n \"\"\"\n Fitness function to evaluate the fitness of an individual.\n We use a simple quadratic function f(x)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052894", "row_id": 52894, "seed_ids": "['Qwen2.5-72B-Instruct_108938']" }
0.441754
Filter_52894
I
[ "fitness_function", "initialize_population", "select_parents", "crossover", "mutate", "genetic_algorithm" ]
6
[ [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "initialize_population" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "select_parents" ] ]
4
[]
false
[]
false
pytest
true
[ "numpy" ]
false
649e52d21d4218d51418ebd56edefe49f84ddd36
95695cde106472561e05d47ef890c1da502105ce
v1.0
instruct
Filter
Filter_52916_I
Is it possible to create a neural network from scratch using only numpy and matplotlib for visualizations? If yes, could you provide a simple example to get started?
import numpy as np # Sigmoid activation function def sigmoid(x): return 1 / (1 + np.exp(-x)) # Derivative of the Sigmoid function def sigmoid_derivative(x): return x * (1 - x) def train_neural_network(X, y, iterations, learning_rate): # Initialize weights randomly with mean 0 input_size = X.shape[1] ...
from solution import train_neural_network, predict import numpy as np def test_train_neural_network(): # XOR problem X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) y = np.array([[0], [1], [1], [0]]) ...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\nclass SimpleNeuralNetwork:\n def __init__(self, input_size, hidden_size, output_size):\n self.W1 = np.random.randn(input_size, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052916", "row_id": 52916, "seed_ids": "['Qwen2.5-72B-Instruct_108973']" }
0.381161
Filter_52916
I
[ "sigmoid", "sigmoid_derivative", "train_neural_network", "predict" ]
4
[ [ "predict", "sigmoid" ], [ "train_neural_network", "sigmoid" ], [ "train_neural_network", "sigmoid_derivative" ] ]
3
[]
false
[]
false
pytest
true
[ "numpy" ]
false
c9bb4531af439f78e33f5a4c71bea6c1a7b2fefb
b0fec298afaf608320815c9d83b2515a721c7d1d
v1.0
instruct
Filter
Filter_52926_I
write a code in python to create a simple calculator which can perform addition, subtraction, multiplication, and division. The user should be able to input two numbers and choose the operation they want to perform. After the operation, the result should be displayed and the program should ask if the user wants to perf...
def add(a, b): """ Returns the sum of a and b. """ return a + b def subtract(a, b): """ Returns the result of a minus b. """ return a - b def multiply(a, b): """ Returns the product of a and b. """ return a * b def divide(a, b): """ Returns the result of a divi...
from solution import add, subtract, multiply, divide def test_add(): assert add(3, 4) == 7 assert add(-1, 1) == 0 assert add(0, 0) == 0 def test_subtract(): assert subtract(10, 5) == 5 assert subtract(-1, -1) == 0 assert subtract(0, 0) == 0 def test_multiply(): assert multiply(3, 4) == 12...
[ { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Returns the result of a minus b.", "function_declaration": "def subtract(a, b):", "function_name": "subtract", "parameter_...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def simple_calculator():\n while True:\n # Input two numbers\n try:\n num1 = float(input(\"Enter the first number: \"))\n num2 = float(input(\"Enter the ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052926", "row_id": 52926, "seed_ids": "['Qwen2.5-72B-Instruct_108991']" }
0.615475
Filter_52926
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6c63d880f343bbd25f197b416a01601aa7ce6805
a1899571898fdd0d071334220cd25de452d8ab0c
v1.0
instruct
Filter
Filter_52930_I
How can I create a Python script that monitors a directory for new files and then processes them? I want to be able to detect when a new file is added and then run a specific function on that file.
import os import time def process_new_file(file_path): """ Function to process the new file. Replace this with actual processing logic. """ print(f"Processing file: {file_path}") def monitor_directory(directory_path, interval=1): """ Monitor the specified directory for new files and process th...
import os import tempfile import time import pytest from solution import monitor_directory, process_new_file @pytest.fixture def temp_dir(): with tempfile.TemporaryDirectory() as temp_dir: yield temp_dir def test_process_new_file(capfd): test_file = "new_file.txt" process_new_file(test_file) c...
[ { "docstring": "Function to process the new file. Replace this with actual processing logic.", "function_declaration": "def process_new_file(file_path):", "function_name": "process_new_file", "parameter_list": "(file_path)" }, { "docstring": "Monitor the specified directory for new files and...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport os\n\ndef monitor_directory(directory, callback):\n \"\"\"\n Monitors a given directory for new files and runs a callback function on each new file.\n\n :param dir...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052930", "row_id": 52930, "seed_ids": "['Qwen2.5-72B-Instruct_108995']" }
0.510039
Filter_52930
I
[ "process_new_file", "monitor_directory" ]
2
[ [ "monitor_directory", "process_new_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c1404d15fcff6701a7adbc69904bbc8e9491124
9bce9b5da39c97d0027ecbb3f7529414c7d6729e