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_78539_I | I want to create a Python script that reads from a text file, processes the data, and then writes the processed data to a new text file. How can I achieve this? | def read_file(file_path):
"""
Reads the content of a file and returns it as a list of lines.
"""
with open(file_path, 'r') as file:
lines = file.readlines()
return lines
def process_data(lines):
"""
Processes the data by converting each line to uppercase.
"""
return [line.up... | import os
from solution import read_file, process_data, write_file, read_process_write
def test_read_file(tmp_path):
file_path = os.path.join(tmp_path, "test_read.txt")
content = "Hello\nWorld\n"
with open(file_path, 'w') as file:
file.write(content)
lines = read_file(file_path)
assert lin... | [
{
"docstring": "Reads the content of a file and returns it as a list of lines.",
"function_declaration": "def read_file(file_path):",
"function_name": "read_file",
"parameter_list": "(file_path)"
},
{
"docstring": "Processes the data by converting each line to uppercase.",
"function_decl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_data(data):\n \"\"\"\n Process data by converting it to uppercase.\n \"\"\"\n return data.upper()\n\ndef read_file(input_filename):\n \"\"\"\n Reads data from a t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078539",
"row_id": 78539,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159518']"
} | 0.475724 | Filter_78539 | I | [
"read_file",
"process_data",
"write_file",
"read_process_write"
] | 4 | [
[
"read_process_write",
"process_data"
],
[
"read_process_write",
"read_file"
],
[
"read_process_write",
"write_file"
]
] | 3 | [
"process_data"
] | false | [] | false | pytest | true | [] | true | b1c9d72b5033c419987123e5589b5d57cac441df | 308c5a0013819f4688865819fc5527b2824a4840 | |||
v1.0 | instruct | Filter | Filter_78548_I | Write a Python function to generate a list of prime numbers within a given range. The function should take two integers as input: `start` and `end`, and return a list of all prime numbers between `start` and `end` (inclusive). If `start` is greater than `end`, the function should return an empty list. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import generate_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(29) == True
def test_generate_primes_wit... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of prime numbers between start and end (inclusive).",
"function_declaration": "def generat... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078548",
"row_id": 78548,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159535']"
} | 0.652797 | Filter_78548 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b8e51078fd3d61b5293b674eba2264b4c85c3c4a | 61a3e4efdfe0a66e1e861ddd2649802c15e81296 | |||
v1.0 | instruct | Filter | Filter_78581_I | How can I create a Python function to retrieve a list of all existing categories from a specific shop on AliExpress, given its user ID? | import requests
def get_aliexpress_categories(user_id):
"""
Fetches a list of all existing categories from a specific shop on AliExpress using the shop's user ID.
Parameters:
user_id (int): The user ID of the shop on AliExpress.
Returns:
list: A list of categories available in... | from unittest.mock import patch
import pytest
from solution import get_aliexpress_categories, extract_categories_from_html
def test_extract_categories_from_html():
# This is a mock HTML content
mock_html_content = "<html><body><div>Electronics</div><div>Fashion</div></body></html>"
expected_categories = [... | [
{
"docstring": "Fetches a list of all existing categories from a specific shop on AliExpress using the shop's user ID.\n\nParameters:\n user_id (int): The user ID of the shop on AliExpress.\n\nReturns:\n list: A list of categories available in the shop.",
"function_declaration": "def get_aliexpress_ca... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\n\ndef get_aliexpress_categories(user_id):\n \"\"\"\n Retrieves a list of all existing categories from a specific shop on AliExpress, given its user ID.\n \n Parame... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078581",
"row_id": 78581,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159607']"
} | 0.364291 | Filter_78581 | I | [
"get_aliexpress_categories",
"extract_categories_from_html"
] | 2 | [
[
"get_aliexpress_categories",
"extract_categories_from_html"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 909c1a79ff176d4714f7f87c4f911dc376dd489e | c11d06cc6c9ab20c1049fdfc6836568a58a1b8a5 | |||
v1.0 | instruct | Filter | Filter_78629_I | Hello Qwen, I'm looking to create a Python program that can simulate a simple game of rock-paper-scissors. Could you guide me through the process? | import random
def get_computer_choice():
"""Randomly selects rock, paper, or scissors for the computer."""
choices = ["rock", "paper", "scissors"]
return random.choice(choices)
def get_winner(player_choice, computer_choice):
"""Determines the winner of the rock-paper-scissors game."""
if player_ch... | from solution import get_computer_choice, get_winner, play_game
def test_get_computer_choice():
choices = ["rock", "paper", "scissors"]
for _ in range(10): # Test multiple times to check randomness within bounds
assert get_computer_choice() in choices
def test_get_winner():
assert get_winner("roc... | [
{
"docstring": "Randomly selects rock, paper, or scissors for the computer.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner of the rock-paper-scissors game.",
"function_declara... | [
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', 'scissors']\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078629",
"row_id": 78629,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159700']"
} | 0.366933 | Filter_78629 | I | [
"get_computer_choice",
"get_winner",
"play_game"
] | 3 | [
[
"play_game",
"get_computer_choice"
],
[
"play_game",
"get_winner"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7ad75f50dab46bcdd8299a89d83f611ca1c4f6a9 | 44a8625a0aa3e80a0f9b7a893b010e2ad34339c7 | |||
v1.0 | instruct | Filter | Filter_78653_I | How can I retrieve a list of computers in a local network using Python? | import socket
import subprocess
import platform
def is_host_alive(host):
"""
Returns True if the host responds to a ping request, False otherwise.
"""
param = "-n" if platform.system().lower() == "windows" else "-c"
command = ["ping", param, "1", host]
return subprocess.call(command, stdout=sub... | import pytest
from unittest.mock import patch, call
from solution import is_host_alive, get_local_ip, get_ip_network, get_list_of_computers
@patch("solution.subprocess.call")
def test_is_host_alive_windows(mock_subprocess_call):
mock_subprocess_call.return_value = 0
assert is_host_alive("192.168.1.1") == True... | [
{
"docstring": "Returns True if the host responds to a ping request, False otherwise.",
"function_declaration": "def is_host_alive(host):",
"function_name": "is_host_alive",
"parameter_list": "(host)"
},
{
"docstring": "Returns the local IP address of the machine.",
"function_declaration... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import socket\nimport threading\n\ndef scan_ip(ip):\n try:\n sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n sock.settimeout(1)\n sock.connect((ip, 22)) # T... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078653",
"row_id": 78653,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159750']"
} | 0.52767 | Filter_78653 | I | [
"is_host_alive",
"get_local_ip",
"get_ip_network",
"get_list_of_computers"
] | 4 | [
[
"get_list_of_computers",
"get_ip_network"
],
[
"get_list_of_computers",
"get_local_ip"
],
[
"get_list_of_computers",
"is_host_alive"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 30fc7ee24b099254ce171904e2d3e28deab39809 | dd2a940ab222ae78d33c55b498e5ba5927ad2ad3 | |||
v1.0 | instruct | Filter | Filter_78681_I | Could you provide a Python script that simulates a simple physics-based particle system with 50 particles in a 2D space? The particles should interact with each other based on gravitational forces, and the simulation should be animated using matplotlib. The initial positions and velocities should be randomly generated.... | import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Constants
G = 6.67430e-11 # Gravitational constant
NUM_PARTICLES = 50 # Number of particles
TIME_STEP = 0.1 # Time step for simulation
class Particle:
def __init__(self, position, velocity, mass=1.0):
self.pos... | import pytest
from solution import Particle, compute_gravitational_force, update_particles
def test_particle_initialization():
p = Particle([0.0, 0.0], [1.0, 1.0])
assert np.array_equal(p.position, [0.0, 0.0])
assert np.array_equal(p.velocity, [1.0, 1.0])
assert p.mass == 1.0
def test_compute_gravitat... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n# Constants\nG = 1 # Gravitational constant\nNUM_PARTICLES = 50\nTIME_STEP = 0.01\n\n# Random ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078681",
"row_id": 78681,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159806']"
} | 0.3811 | Filter_78681 | I | [
"compute_gravitational_force",
"update_particles",
"main"
] | 3 | [
[
"update_particles",
"compute_gravitational_force"
]
] | 1 | [] | false | [
"Particle"
] | true | pytest | true | [
"matplotlib",
"numpy"
] | false | 3f3e05126f1661b4d55e7aa88d3c1e9af3159bef | 9c24b2b7cb507148f4f2bfc2d5060bfb5c1e568d | |||
v1.0 | instruct | Filter | Filter_78697_I | Given a string `s`, return all possible palindromic partitions of `s`. | def is_palindrome(s):
return s == s[::-1]
def partition(s):
"""
Returns all possible palindromic partitions of the string s.
"""
result = []
current_partition = []
def dfs(start):
if start >= len(s):
result.append(current_partition[:])
return
for... | from solution import partition
def test_single_character():
assert partition("a") == [["a"]]
def test_two_characters_palindrome():
assert partition("aa") == [["a", "a"], ["aa"]]
def test_two_characters_non_palindrome():
assert partition("ab") == [["a", "b"]]
def test_three_characters():
assert parti... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all possible palindromic partitions of the string s.",
"function_declaration": "def partition(s):",
"function_name": "partition",... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(sub):\n \"\"\"\n Checks if the given substring is a palindrome.\n \"\"\"\n return sub == sub[::-1]\n\ndef palindromic_partitions(s):\n \"\"\"\n Returns all ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078697",
"row_id": 78697,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159843']"
} | 0.660197 | Filter_78697 | I | [
"is_palindrome",
"partition"
] | 2 | [
[
"partition",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b3c30e2f9c1ff979a298158c5aa9ea058b85982 | a693ca2b6290e5468477c5ee4e614588b5e4510b | |||
v1.0 | instruct | Filter | Filter_78704_I | What is the process of converting a plaintext message into bitmap images in Python? | from PIL import Image
import binascii
def message_to_binary(message):
"""Converts a string message to its binary equivalent."""
return ''.join(format(ord(char), '08b') for char in message)
def binary_to_image(binary, width=100):
"""
Converts a binary string into a black and white image.
Param... | from solution import message_to_binary, binary_to_image, text_to_bitmap_image
from PIL import Image
import pytest
def test_message_to_binary():
assert message_to_binary("A") == "01000001"
assert message_to_binary("Hi") == "0100100001101001"
def test_binary_to_image():
binary = "0100000101000010" # Equiva... | [
{
"docstring": "Converts a string message to its binary equivalent.",
"function_declaration": "def message_to_binary(message):",
"function_name": "message_to_binary",
"parameter_list": "(message)"
},
{
"docstring": "Converts a binary string into a black and white image.\n\nParameters:\n b... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from PIL import Image\nimport binascii\n\ndef message_to_binary(message):\n \"\"\"Converts a string message to its binary equivalent.\"\"\"\n return ''.join(format(ord(char), '08b') for ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00078704",
"row_id": 78704,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159863']"
} | 0.490157 | Filter_78704 | I | [
"message_to_binary",
"binary_to_image",
"text_to_bitmap_image"
] | 3 | [
[
"text_to_bitmap_image",
"binary_to_image"
],
[
"text_to_bitmap_image",
"message_to_binary"
]
] | 2 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | 8a49173868d0a6e1ef480fed8e225c8504ff9a22 | 3ed4b3ef51e86df354cc67ae210abc9f1b7f4115 | |||
v1.0 | instruct | Filter | Filter_78712_I | Genetic Algorithms (GAs) are a class of optimization algorithms inspired by the process of natural selection and genetics. They are used to find approximate solutions to complex optimization problems. Can you provide a simple example of how a Genetic Algorithm can be implemented in Python? | import random
def generate_individual(length):
"""
Generates an individual with given length (chromosome).
"""
return [random.randint(0, 1) for _ in range(length)]
def generate_population(size, chromosome_length):
"""
Generates a population of given size.
"""
return [generate_individua... | from solution import generate_individual, generate_population, fitness, mutate, crossover, select_individuals, genetic_algorithm
def test_generate_individual():
individual = generate_individual(5)
assert len(individual) == 5
assert all(gene in [0, 1] for gene in individual)
def test_generate_population():... | [
{
"docstring": "Generates an individual with given length (chromosome).",
"function_declaration": "def generate_individual(length):",
"function_name": "generate_individual",
"parameter_list": "(length)"
},
{
"docstring": "Generates a population of given size.",
"function_declaration": "d... | [
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 genetic_algorithm(population, fitness_fn, mutation_fn, crossover_fn, generation_limit=100, mutation_rate=0.01):\n \"\"\"\n Runs a simple Genetic Algorithm.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078712",
"row_id": 78712,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159880']"
} | 0.328471 | Filter_78712 | I | [
"generate_individual",
"generate_population",
"fitness",
"mutate",
"crossover",
"select_individuals",
"genetic_algorithm"
] | 7 | [
[
"generate_population",
"generate_individual"
],
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"fitness"
],
[
"genetic_algorithm",
"generate_population"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"select_individual... | 6 | [] | false | [] | false | pytest | true | [] | true | 629f356f256ff87b7da1f9590382ec0a9f745530 | fc38cfdb075ef52d948bd19b874143200be5a9d5 | |||
v1.0 | instruct | Filter | Filter_78752_I | Can you explain how to use the `fcntl` module in Python for file locking? Can you provide a simple example? | import fcntl
import os
import time
def lock_file(file_path):
"""
Locks a file using the fcntl module.
Args:
file_path (str): The path to the file to lock.
Returns:
file object: A file object that is locked.
"""
file = open(file_path, 'w')
fcntl.flock(file.fileno(),... | import os
import pytest
from solution import lock_file, unlock_file, write_to_locked_file
def test_lock_and_unlock_file():
# Prepare a temporary file for testing
file_path = 'test_lock.txt'
with open(file_path, 'w') as f:
f.write("")
# Lock the file
file = lock_file(file_path)
try:... | [
{
"docstring": "Locks a file using the fcntl module.\n\nArgs:\n file_path (str): The path to the file to lock.\n\nReturns:\n file object: A file object that is locked.",
"function_declaration": "def lock_file(file_path):",
"function_name": "lock_file",
"parameter_list": "(file_path)"
},
{
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import fcntl\nimport os\nimport time\n\ndef lock_file(file_path):\n \"\"\"\n Locks a file using the fcntl module.\n \n Args:\n file_path (str): The path to the file to lock.... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00078752",
"row_id": 78752,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159949']"
} | 0.406051 | Filter_78752 | I | [
"lock_file",
"unlock_file",
"write_to_locked_file"
] | 3 | [
[
"write_to_locked_file",
"lock_file"
],
[
"write_to_locked_file",
"unlock_file"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fb8b61a74f12d588a3314aec9c620c6295b972b4 | f01a93b8f8b348078491f0ebeb2b14a1145dfe26 | |||
v1.0 | instruct | Filter | Filter_78766_I | Generate a Python program that simulates rolling a six-sided die 1000 times and prints the frequency of each outcome. Additionally, the program should also calculate and print the expected frequency for each outcome, assuming a fair die. | import random
def roll_die(num_rolls=1000):
outcomes = [0] * 6
for _ in range(num_rolls):
roll = random.randint(1, 6)
outcomes[roll - 1] += 1
return outcomes
def expected_frequency(num_rolls=1000):
return [num_rolls / 6] * 6
def simulate_die_rolls(num_rolls=1000):
actual_freq = ro... | from solution import roll_die, expected_frequency, simulate_die_rolls
def test_roll_die():
outcome = roll_die(6000)
for count in outcome:
assert 900 <= count <= 1100 # Fair margin of error for randomness
def test_expected_frequency():
assert expected_frequency(6000) == [1000, 1000, 1000, 1000, 10... | [
{
"docstring": null,
"function_declaration": "def roll_die(num_rolls=1000):",
"function_name": "roll_die",
"parameter_list": "(num_rolls=1000)"
},
{
"docstring": null,
"function_declaration": "def expected_frequency(num_rolls=1000):",
"function_name": "expected_frequency",
"param... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nfrom collections import Counter\n\ndef roll_die(times):\n \"\"\"\n Simulates rolling a six-sided die 'times' times and returns the frequency of each outcome.\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078766",
"row_id": 78766,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_159985']"
} | 0.734618 | Filter_78766 | I | [
"roll_die",
"expected_frequency",
"simulate_die_rolls"
] | 3 | [
[
"simulate_die_rolls",
"expected_frequency"
],
[
"simulate_die_rolls",
"roll_die"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c62095d19793d5ba56be76b0a829611ff8315049 | 59b5fd3f7feabdad16d16141cc885f054dc3c540 | |||
v1.0 | instruct | Filter | Filter_78827_I | Hello, I'm currently in the process of learning Python and I'm a bit stuck on generating a random number. I want to create a simple program that generates a random number between 1 and 100 and asks the user to guess it. After each guess, the program should tell the user if their guess is too high, too low, or correct. ... | import random
def generate_random_number():
return random.randint(1, 100)
def check_guess(user_guess, target_number):
if user_guess < target_number:
return "Your guess is too low."
elif user_guess > target_number:
return "Your guess is too high."
else:
return "Correct! You've g... | from solution import generate_random_number, check_guess
def test_generate_random_number_in_range():
number = generate_random_number()
assert 1 <= number <= 100
def test_check_guess_low():
assert check_guess(25, 50) == "Your guess is too low."
def test_check_guess_high():
assert check_guess(75, 50) =... | [
{
"docstring": null,
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def check_guess(user_guess, target_number):",
"function_name": "check_guess",
"paramete... | [
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 number_guessing_game():\n \"\"\"\n A number guessing game where the user tries to guess a randomly generated number between 1 and 100.\n \"\"\"\n number_to_gue... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078827",
"row_id": 78827,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160121']"
} | 0.506309 | Filter_78827 | I | [
"generate_random_number",
"check_guess",
"number_guessing_game"
] | 3 | [
[
"number_guessing_game",
"check_guess"
],
[
"number_guessing_game",
"generate_random_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 12f96b95f22aa8b4649e67ea8d4f915c5aff492f | 15b3ae572550665387bedf4b8dad73bc23116bd1 | |||
v1.0 | instruct | Filter | Filter_78837_I | Could you provide a detailed explanation of the Heap Sort algorithm, including its time complexity, space complexity, and provide a Python implementation? | def heapify(arr, n, i):
"""
Converts a subtree rooted with node i into a max heap, assuming the subtrees are already max heaps.
"""
largest = i
left = 2 * i + 1
right = 2 * i + 2
# Check if left child exists and is greater than root
if left < n and arr[left] > arr[largest]:
larg... | from solution import heap_sort
def test_heap_sort_empty():
arr = []
heap_sort(arr)
assert arr == []
def test_heap_sort_single_element():
arr = [1]
heap_sort(arr)
assert arr == [1]
def test_heap_sort_sorted():
arr = [1, 2, 3, 4, 5]
heap_sort(arr)
assert arr == [1, 2, 3, 4, 5]
def ... | [
{
"docstring": "Converts a subtree rooted with node i into a max heap, assuming the subtrees are already max heaps.",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": "Sorts an array in ascending order using the ... | [
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 To heapify a subtree rooted with node i which is an index in arr[].\n n is size of heap\n \"\"\"\n largest = i # Initialize largest as root\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078837",
"row_id": 78837,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160139']"
} | 0.696495 | Filter_78837 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5be5e3cb71eb2d4e58440c810bf62cf34d874b40 | 46874613a7e32f38a207443d544c67fdf3c6c2bc | |||
v1.0 | instruct | Filter | Filter_78845_I | What are the steps involved in processing a bulk document upload and conversion from one format to another using Python? | import os
from typing import List
def convert_document(file_path: str, output_format: str) -> str:
"""
Converts a document from its current format to the specified output format.
This is a placeholder for the actual conversion logic.
Args:
file_path (str): The path to the input docume... | from solution import bulk_upload_and_convert
def test_bulk_upload_and_convert_single_file():
input_files = ["test_document.docx"]
converted_files = bulk_upload_and_convert(input_files, "pdf")
assert len(converted_files) == 1
assert converted_files[0] == "test_document.pdf"
def test_bulk_upload_and_con... | [
{
"docstring": "Converts a document from its current format to the specified output format.\n\nThis is a placeholder for the actual conversion logic.\n\nArgs:\n file_path (str): The path to the input document.\n output_format (str): The desired output format.\n\nReturns:\n str: The path to the output d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\nfrom pathlib import Path\nfrom docx import Document # Assuming you are converting .docx to .txt\nfrom typing import List\n\ndef convert_documents(input_files: List[s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078845",
"row_id": 78845,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160158']"
} | 0.468531 | Filter_78845 | I | [
"convert_document",
"bulk_upload_and_convert"
] | 2 | [
[
"bulk_upload_and_convert",
"convert_document"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4046225fd441c1189276ac9781f89eefe0c13b99 | 1c5c59cea0604d21347d6e22079f9167a6916724 | |||
v1.0 | instruct | Filter | Filter_78856_I | Given a set of points in the 2D plane, implement a Python function to find the pair of points that are the closest together. The function should return the coordinates of the two closest points. If there are multiple pairs with the same minimum distance, return any one of them. | from math import sqrt
from itertools import combinations
def distance(point1, point2):
return sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
def closest_pair(points):
min_distance = float('inf')
closest_points = None
for (point1, point2) in combinations(points, 2):
dist = d... | from solution import closest_pair
def test_closest_pair_basic():
points = [(0, 0), (1, 1), (2, 2), (3, 3)]
assert closest_pair(points) == ((0, 0), (1, 1))
def test_closest_pair_single_candidate():
points = [(0, 0), (1, 1)]
assert closest_pair(points) == ((0, 0), (1, 1))
def test_closest_pair_multiple... | [
{
"docstring": null,
"function_declaration": "def distance(point1, point2):",
"function_name": "distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": null,
"function_declaration": "def closest_pair(points):",
"function_name": "closest_pair",
"parameter_list": "(points... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078856",
"row_id": 78856,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160187']"
} | 0.630019 | Filter_78856 | I | [
"distance",
"closest_pair"
] | 2 | [
[
"closest_pair",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 82c8493fab4312c48ceba35074e303beaa3d6070 | 5941af0ad0b41c069a7bc69c7687fc4f5a71eea8 | |||
v1.0 | instruct | Filter | Filter_78859_I | Can you provide a simple Python script that simulates a basic temperature monitoring system for a small room? This script should read temperature data from a simulated sensor (using random values for demonstration), and then log the temperatures to a file with timestamps. The script should run for a specified duration ... | import time
import random
from datetime import datetime
def read_temperature():
"""
Simulates reading the temperature from a sensor.
"""
# Simulating a temperature value between 15 and 30 degrees Celsius.
return round(random.uniform(15.0, 30.0), 1)
def log_temperature(duration, interval, file_name... | import os
from solution import read_temperature, log_temperature
def test_read_temperature():
temp = read_temperature()
assert 15.0 <= temp <= 30.0
def test_log_temperature():
# Use a short duration and interval to quickly complete the test
duration = 10
interval = 2
test_file = "test_temperat... | [
{
"docstring": "Simulates reading the temperature from a sensor.",
"function_declaration": "def read_temperature():",
"function_name": "read_temperature",
"parameter_list": "()"
},
{
"docstring": "Logs temperature readings to a file at regular intervals for a specified duration.\n\n:param du... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport random\nfrom datetime import datetime\n\ndef read_temperature():\n \"\"\"\n Simulates reading the temperature from a sensor.\n Returns a random temperature value b... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078859",
"row_id": 78859,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160193']"
} | 0.501003 | Filter_78859 | I | [
"read_temperature",
"log_temperature"
] | 2 | [
[
"log_temperature",
"read_temperature"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dd64a791195f3e87ec36e489d25c80e0ffcecb5 | f3e38af6147e5cb8bed16efd9ab3ef62187dd1ed | |||
v1.0 | instruct | Filter | Filter_78896_I | How do you create a simple game in Python that involves rolling a dice and guessing the number? | import random
def roll_dice():
"""
Simulates rolling a dice and returns a number between 1 and 6.
"""
return random.randint(1, 6)
def guess_number(guess, actual):
"""
Compares the player's guess with the actual dice roll result.
"""
if guess == actual:
return "Congratulations! ... | from solution import roll_dice, guess_number, play_game
def test_roll_dice():
result = roll_dice()
assert 1 <= result <= 6
def test_guess_number_correct():
assert guess_number(3, 3) == "Congratulations! You guessed it right."
def test_guess_number_incorrect():
assert guess_number(2, 4) == "Sorry, you... | [
{
"docstring": "Simulates rolling a dice and returns a number between 1 and 6.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Compares the player's guess with the actual dice roll result.",
"function_declaration": "de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided dice and returns the result (1-6).\n \"\"\"\n return random.randint(1, 6)\n\ndef guess_number():\n \"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078896",
"row_id": 78896,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160273']"
} | 0.515344 | Filter_78896 | I | [
"roll_dice",
"guess_number",
"play_game"
] | 3 | [
[
"play_game",
"guess_number"
],
[
"play_game",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7879067b0476477cf47915381d9f802dc25e8f00 | c104c08d41804a7d4e74d5fb6afe0a247efe57ef | |||
v1.0 | instruct | Filter | Filter_78898_I | I want to create a program to generate a randomly selected day of the week and then ask the user to guess it. The user has 3 attempts to guess correctly. If they guess correctly, they win; if not, they lose. How can I implement this in Python? | import random
def get_random_day_of_week():
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
return random.choice(days_of_week)
def guess_day_of_week():
correct_day = get_random_day_of_week()
attempts = 3
while attempts > 0:
guess = input("... | import random
from solution import get_random_day_of_week, guess_day_of_week
def test_get_random_day_of_week():
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
day = get_random_day_of_week()
assert day in days_of_week
def test_guess_day_of_week_correct(monkeyp... | [
{
"docstring": null,
"function_declaration": "def get_random_day_of_week():",
"function_name": "get_random_day_of_week",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def guess_day_of_week():",
"function_name": "guess_day_of_week",
"parameter_list": "()"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_random_day():\n \"\"\"\n Returns a randomly selected day of the week.\n \"\"\"\n days_of_week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Fr... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00078898",
"row_id": 78898,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160277']"
} | 0.483758 | Filter_78898 | I | [
"get_random_day_of_week",
"guess_day_of_week"
] | 2 | [
[
"guess_day_of_week",
"get_random_day_of_week"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b409a072886f42d738c71b7731da37906e510b82 | b3d2a7bf6e150951050a17f57b60bf031b322156 | |||
v1.0 | instruct | Filter | Filter_78916_I | Can you provide an example of a Python function that follows the Single Responsibility Principle? | def calculate_area(shape, dimensions):
"""
Calculate the area of a given shape with provided dimensions.
Parameters:
- shape: The type of shape (e.g., "rectangle", "circle").
- dimensions: A dictionary containing the dimensions of the shape.
Returns:
- The calculated area of the sh... | from solution import calculate_area, _rectangle_area, _circle_area
def test_calculate_area_rectangle():
dimensions = {'length': 5, 'width': 4}
assert calculate_area('rectangle', dimensions) == 20
def test_calculate_area_circle():
dimensions = {'radius': 3}
assert calculate_area('circle', dimensions) =... | [
{
"docstring": "Calculate the area of a given shape with provided dimensions.\n\nParameters:\n- shape: The type of shape (e.g., \"rectangle\", \"circle\").\n- dimensions: A dictionary containing the dimensions of the shape.\n\nReturns:\n- The calculated area of the shape.",
"function_declaration": "def calc... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_rectangle_area(length, width):\n \"\"\"\n Returns the area of a rectangle given its length and width.\n \"\"\"\n return length * width",
"test_code": "from soluti... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078916",
"row_id": 78916,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160327']"
} | 0.488999 | Filter_78916 | I | [
"calculate_area",
"_rectangle_area",
"_circle_area"
] | 3 | [
[
"calculate_area",
"_circle_area"
],
[
"calculate_area",
"_rectangle_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5c046b20e0e2b2d64c2174ca7e201c52cfd1fb2c | 710bf678746e8f3f464d07db6b53908990f1b363 | |||
v1.0 | instruct | Filter | Filter_78928_I | Can you provide a simple example of how to use structured data in a Python script to store and manipulate information about a list of employees in a company? | class Employee:
def __init__(self, employee_id, name, position, salary):
self.employee_id = employee_id
self.name = name
self.position = position
self.salary = salary
def give_raise(self, amount):
self.salary += amount
def add_employee(employees, employee_id, name, posi... | from solution import Employee, add_employee, get_employee, remove_employee
def test_add_employee():
employees = []
add_employee(employees, 1, "Alice", "Engineer", 80000)
assert len(employees) == 1
assert employees[0].name == "Alice"
def test_get_employee():
employees = []
add_employee(employee... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Employee:\n def __init__(self, id, name, position, salary):\n self.id = id\n self.name = name\n self.position = position\n self.salary = salary\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00078928",
"row_id": 78928,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160358']"
} | 0.466712 | Filter_78928 | I | [
"add_employee",
"get_employee",
"remove_employee"
] | 3 | [
[
"remove_employee",
"get_employee"
]
] | 1 | [] | false | [
"Employee"
] | true | pytest | true | [] | true | a7b54e3f57ea3071eac3cf8e9964e9df37fa459c | 4ccc7ab376e2979b8ab5bc117e8f7fe77a030c98 | |||
v1.0 | instruct | Filter | Filter_78944_I | write a Python code that demonstrates the use of a generator to yield prime numbers up to a given limit. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import prime_generator, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(16) == False
def test_prime_generator_empty():
primes = list(prime_generator(1))
assert primes ==... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generator function that yields prime numbers up to a given limit.",
"function_declaration": "def prime_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(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_0 | {
"original_instruction": "",
"prompt_id": "00078944",
"row_id": 78944,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160389']"
} | 0.588774 | Filter_78944 | I | [
"is_prime",
"prime_generator"
] | 2 | [
[
"prime_generator",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 35efe6e74faa7a000236668f5a31ec7feedd74cd | 4aa8dccdc43b83af521abf097a333cbb7ff48813 | |||
v1.0 | instruct | Filter | Filter_78963_I | Write a Python function to find the k-th smallest element in a list of numbers using the Quickselect algorithm. | import random
def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i = i + 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if ... | from solution import find_kth_smallest
def test_kth_smallest_general_case():
assert find_kth_smallest([3, 2, 1, 5, 4], 3) == 3
def test_kth_smallest_single_element():
assert find_kth_smallest([10], 1) == 10
def test_kth_smallest_duplicates():
assert find_kth_smallest([3, 3, 3, 3, 3], 1) == 3
def test_kt... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n for j in range(low, high):\n if arr[j] <= pivot:\n i = i + 1\n arr[i],... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00078963",
"row_id": 78963,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160418']"
} | 0.682941 | Filter_78963 | I | [
"partition",
"quickselect",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a61429f26f3dbf1b4c9b1013e635a5ca29361da7 | b95df71b2db56bd2e4ab268b0c9490e927c28e0e | |||
v1.0 | instruct | Filter | Filter_78966_I | How can I create a custom message handler in a Python web application using the Flask framework? | from flask import Flask, request, jsonify
app = Flask(__name__)
def custom_message_handler(message):
"""
Custom message handler function. This is where you define how you want to handle the message.
For demonstration, it simply returns the message reversed.
"""
reversed_message = message[::-1]
... | import pytest
from solution import app, custom_message_handler
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_custom_message_handler():
assert custom_message_handler("hello") == "olleh"
assert custom_message_handler("world") == "dlrow"
def test_message_endpo... | [
{
"docstring": "Custom message handler function. This is where you define how you want to handle the message.\nFor demonstration, it simply returns the message reversed.",
"function_declaration": "def custom_message_handler(message):",
"function_name": "custom_message_handler",
"parameter_list": "(m... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\ndef custom_message_handler(message):\n \"\"\"\n Custom message handler function. This is where you define how you wa... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00078966",
"row_id": 78966,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160422']"
} | 0.59437 | Filter_78966 | I | [
"custom_message_handler",
"message"
] | 2 | [
[
"message",
"custom_message_handler"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | ec5fb4cde79eb33f90a2fc7e9e911f8f541b9312 | 94970a57d82acf8707f6b13ade8418d3071704ce | |||
v1.0 | instruct | Filter | Filter_79071_I | Can you explain how to use the `filter` function in Python with a custom function? Can you provide an example? | def is_even(num):
"""
Returns True if the number is even, False otherwise.
"""
return num % 2 == 0
def filter_even_numbers(numbers):
"""
Returns a list of even numbers filtered from the provided list using the is_even function.
"""
return list(filter(is_even, numbers)) | from solution import is_even, filter_even_numbers
def test_is_even():
assert is_even(2) == True
assert is_even(3) == False
assert is_even(0) == True
assert is_even(-2) == True
assert is_even(-3) == False
def test_filter_even_numbers():
assert filter_even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6... | [
{
"docstring": "Returns True if the number is even, False otherwise.",
"function_declaration": "def is_even(num):",
"function_name": "is_even",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of even numbers filtered from the provided list using the is_even function.",
"funct... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(number):\n \"\"\"\n Custom function that returns True if the number is even, False otherwise.\n \"\"\"\n return number % 2 == 0\n\ndef filter_even_numbers(numbers):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079071",
"row_id": 79071,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160648']"
} | 0.655109 | Filter_79071 | I | [
"is_even",
"filter_even_numbers"
] | 2 | [
[
"filter_even_numbers",
"is_even"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d3359485233e70baa293a106d30afd301463cdd | a649b86a3a65e44700d2a784769079546b2ed289 | |||
v1.0 | instruct | Filter | Filter_79079_I | Can you provide a Python function that checks if a number is prime and returns all prime numbers up to a given number `n`? | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import is_prime, primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime(29) == True
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers up to a given number n.",
"function_declaration": "def primes_up_to(n):",
"functio... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the number is prime, else False.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079079",
"row_id": 79079,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160666']"
} | 0.776096 | Filter_79079 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84c64f1ca58028c9db4273e7627f2c3da57cd5af | 0b03e330146a1d4f17b06104cc7ec5186d064744 | |||
v1.0 | instruct | Filter | Filter_79082_I | Write a Python code to generate a table of prime numbers using the Sieve of Eratosthenes algorithm up to a given number `n`. The output should be formatted as a table with rows and columns, similar to multiplication tables. | def sieve_of_eratosthenes(n):
"""
Generates all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
... | from solution import sieve_of_eratosthenes, generate_prime_table
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_generate_prime_table_small():
expected_table_small = [
[4, 6, 10, 14],
... | [
{
"docstring": "Generates all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Generates a table of prime numbers up ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes_table(n):\n \"\"\"\n Generates a table of prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n # Step 1: Create a boolean array \"prime[0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079082",
"row_id": 79082,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160672']"
} | 0.589409 | Filter_79082 | I | [
"sieve_of_eratosthenes",
"generate_prime_table"
] | 2 | [
[
"generate_prime_table",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5b9f5f9b7192c16f3c67c52b4591eecc3827dd68 | fc9bbc0f8abaf8265376e534f37f8ba2bcaa8565 | |||
v1.0 | instruct | Filter | Filter_79129_I | Can you explain how to pass a value from a Python function to another function and then return it back through the call stack? | def function_a(value):
"""
Passes the value to function_b and returns the modified value.
"""
return function_b(value)
def function_b(value):
"""
Takes a value, modifies it, and returns it.
For example, it could add 10 to the value.
"""
return value + 10 | from solution import function_a, function_b
def test_function_a_with_positive_number():
result = function_a(5)
assert result == 15
def test_function_a_with_zero():
result = function_a(0)
assert result == 10
def test_function_b_with_positive_number():
result = function_b(7)
assert result == 17... | [
{
"docstring": "Passes the value to function_b and returns the modified value.",
"function_declaration": "def function_a(value):",
"function_name": "function_a",
"parameter_list": "(value)"
},
{
"docstring": "Takes a value, modifies it, and returns it.\nFor example, it could add 10 to the va... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def function_a(value):\n \"\"\"\n Takes a value and passes it to function_b, then returns the result.\n \"\"\"\n return function_b(value)\n\ndef function_b(value):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079129",
"row_id": 79129,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160758']"
} | 0.450441 | Filter_79129 | I | [
"function_a",
"function_b"
] | 2 | [
[
"function_a",
"function_b"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 86ef0c80bb519bb2c27c3d2f0cbbb2e825c885e3 | 0e0ab7f0ea0f2a0d1f06a1897339cad46397c588 | |||
v1.0 | instruct | Filter | Filter_79136_I | Can you provide a Python script that can encode and decode a string using a simple Caesar cipher? A Caesar cipher is a type of substitution cipher where each letter in the plaintext is shifted a certain number of places down the alphabet. For example, with a shift of 1, 'A' would be replaced by 'B', 'B' would become 'C... | def caesar_cipher_encode(text, shift):
"""
Encodes the given text using the Caesar cipher with the specified shift.
Parameters:
text (str): The input string to encode.
shift (int): The number of positions to shift each character.
Returns:
str: The encoded string.
"""
encode... | from solution import caesar_cipher_encode, caesar_cipher_decode
def test_caesar_cipher_encode_shift_1():
assert caesar_cipher_encode('ABC', 1) == 'BCD'
assert caesar_cipher_encode('xyz', 1) == 'yza'
def test_caesar_cipher_encode_shift_3():
assert caesar_cipher_encode('HELLO', 3) == 'KHOOR'
assert caes... | [
{
"docstring": "Encodes the given text using the Caesar cipher with the specified shift.\n\nParameters:\ntext (str): The input string to encode.\nshift (int): The number of positions to shift each character.\n\nReturns:\nstr: The encoded string.",
"function_declaration": "def caesar_cipher_encode(text, shif... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_cipher_encode(text, shift):\n \"\"\"\n Encodes a given text using a Caesar cipher with the specified shift.\n \"\"\"\n encoded_text = []\n for char in text:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079136",
"row_id": 79136,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160776']"
} | 0.653501 | Filter_79136 | I | [
"caesar_cipher_encode",
"caesar_cipher_decode"
] | 2 | [
[
"caesar_cipher_decode",
"caesar_cipher_encode"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fc05397a738226c471246d37150ff1456bc9746 | c2c7bc4edf72e896c78d38546aa70f864d6857bf | |||
v1.0 | instruct | Filter | Filter_79142_I | Create a Python function that generates a list of all the prime numbers within a given range. The function should accept two parameters, `start` and `end`, where `start` is the starting number of the range and `end` is the ending number of the range. The function should return a list containing all the prime numbers wi... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import generate_primes, is_prime
def test_generate_primes_basic():
assert generate_primes(10, 20) == [11, 13, 17, 19]
def test_generate_primes_single_number():
assert generate_primes(17, 17) == [17]
assert generate_primes(18, 18) == []
def test_generate_primes_no_primes():
assert genera... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of all prime numbers within the range [start, end].",
"function_declaration": "def generat... | [
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 elif n <= 3:\n return True\n elif n % 2 == 0 o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079142",
"row_id": 79142,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160784']"
} | 0.664988 | Filter_79142 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 328b8f873b900dc5b6441674d51b56fdb18494c3 | c1c7a7808eca2ba194ab34038e22f688379d6eab | |||
v1.0 | instruct | Filter | Filter_79144_I | Can you provide a Python code to simulate a simple game where a player rolls a dice and tries to reach a target score? The game should allow the player to roll the dice as many times as needed, and the game ends when the player's score reaches or exceeds the target score. The player should be informed of their current ... | import random
def roll_dice():
"""
Simulates rolling a six-sided dice and returns the result.
"""
return random.randint(1, 6)
def play_game(target_score):
"""
Simulates the dice rolling game. The player rolls the dice until
the target score is reached or exceeded.
Args:
- targ... | import pytest
from unittest.mock import patch
from io import StringIO
from solution import roll_dice, play_game
def test_roll_dice():
roll = roll_dice()
assert 1 <= roll <= 6
@patch('builtins.input', side_effect=['10'])
@patch('builtins.print')
@patch('solution.roll_dice', side_effect=[3, 3, 2, 2])
def test_p... | [
{
"docstring": "Simulates rolling a six-sided dice and returns the result.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates the dice rolling game. The player rolls the dice until\nthe target score is reached or ex... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided dice and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_game(target_score):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079144",
"row_id": 79144,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160788']"
} | 0.476465 | Filter_79144 | I | [
"roll_dice",
"play_game",
"main"
] | 3 | [
[
"play_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0886acc5f358c1c74405c8768f869093a15d9e35 | 17340f2633ce3f9d0096950cf1574185ec82e888 | |||
v1.0 | instruct | Filter | Filter_79152_I | Hello Qwen, I have a custom NLP model trained for language translation from German to English. I have several text files that I want to translate, and I want to automate this process using a Python script. Can you guide me on how to do this? | from pathlib import Path
from typing import List
def load_text_files(directory: str) -> List[str]:
"""
Load all text files from the specified directory and returns a list of their contents.
"""
text_files = Path(directory).glob('*.txt')
contents = [file.read_text(encoding='utf-8') for file in text_... | import pytest
from unittest.mock import MagicMock
from solution import load_text_files, translate_text, translate_files
def test_load_text_files(tmp_path):
# Create dummy text files
(tmp_path / "file1.txt").write_text("Hallo Welt", encoding='utf-8')
(tmp_path / "file2.txt").write_text("Guten Tag", encoding... | [
{
"docstring": "Load all text files from the specified directory and returns a list of their contents.",
"function_declaration": "def load_text_files(directory):",
"function_name": "load_text_files",
"parameter_list": "(directory)"
},
{
"docstring": "Translates the given text from German to ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from pathlib import Path\nfrom typing import List\n\ndef load_text_files(directory: str) -> List[str]:\n \"\"\"\n Load all text files from the specified directory and returns a list of t... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079152",
"row_id": 79152,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160803']"
} | 0.464529 | Filter_79152 | I | [
"load_text_files",
"translate_text",
"translate_files"
] | 3 | [
[
"translate_files",
"load_text_files"
],
[
"translate_files",
"translate_text"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 63a32eace39abc14d4ed78724f879704721f23c8 | cef15a746528d6520a03246f6deb59682d096b6d | |||
v1.0 | instruct | Filter | Filter_79199_I | Write a Python script to check the availability of a website and send an email notification if the website is down. This script should use the `requests` library to check the website status and `smtplib` to send an email. | import requests
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website(url):
"""
Checks if the website is available.
"""
try:
response = requests.get(url)
if response.status_code == 200:
return True
else:
... | from unittest.mock import patch, ANY
from solution import check_website, send_email, check_website_and_notify
def test_check_website(monkeypatch):
class MockResponse:
status_code = 200
def mock_get(url):
return MockResponse()
monkeypatch.setattr(requests, "get", mock_get)
asse... | [
{
"docstring": "Checks if the website is available.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
},
{
"docstring": "Sends an email notification.",
"function_declaration": "def send_email(smtp_server, port, login, passwor... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef check_website(url):\n \"\"\"\n Checks the availability of a w... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079199",
"row_id": 79199,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160897']"
} | 0.567859 | Filter_79199 | I | [
"check_website",
"send_email",
"check_website_and_notify"
] | 3 | [
[
"check_website_and_notify",
"check_website"
],
[
"check_website_and_notify",
"send_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 649202072ca5ab0f2c2b48ded23ba8e5d1194c21 | 007442f8ffd4fe3bf69bb68a30f6e9930ddd47fc | |||
v1.0 | instruct | Filter | Filter_79223_I | Prepare a Python script that reads data from a JSON file, processes it, and writes the processed data back to a new JSON file. The script should handle exceptions gracefully. The data in the JSON file consists of a list of dictionaries, each representing a user. Each user dictionary contains keys for id, name, and age.... | import json
def read_json_file(file_path):
try:
with open(file_path, 'r') as file:
data = json.load(file)
return data
except FileNotFoundError:
print(f"Error: File not found - {file_path}")
return None
except json.JSONDecodeError:
print(f"Error: Failed to... | import pytest
import os
import json
from solution import read_json_file, write_json_file, process_users, process_json_file
def test_read_json_file():
# Given a JSON file with valid content
file_path = "test_data.json"
test_data = [{'id': 1, 'name': 'John Doe', 'age': 20}]
with open(file_path, 'w')... | [
{
"docstring": null,
"function_declaration": "def read_json_file(file_path):",
"function_name": "read_json_file",
"parameter_list": "(file_path)"
},
{
"docstring": null,
"function_declaration": "def write_json_file(file_path, data):",
"function_name": "write_json_file",
"paramete... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef read_json_file(file_path):\n try:\n with open(file_path, 'r') as file:\n data = json.load(file)\n return data\n except FileNotFoundError:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079223",
"row_id": 79223,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160941']"
} | 0.581513 | Filter_79223 | I | [
"read_json_file",
"write_json_file",
"process_users",
"process_json_file"
] | 4 | [
[
"process_json_file",
"process_users"
],
[
"process_json_file",
"read_json_file"
],
[
"process_json_file",
"write_json_file"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 35bf8c36ee23478f35138167e682e325582c97bb | 89e3e5387bcb3eed50626f9fc1a4b73e2ad53974 | |||
v1.0 | instruct | Filter | Filter_79241_I | How can I use Python to traverse a JSON data structure stored in a file and print each key-value pair at every level? | import json
def print_json_data(file_path):
"""
Reads JSON data from a file and prints each key-value pair at every level.
"""
with open(file_path, 'r') as file:
data = json.load(file)
traverse_json(data)
def traverse_json(data, indent_level=0):
"""
Recursively traverses a JSON... | import json
from io import StringIO
from unittest.mock import patch
from solution import print_json_data
def test_traverse_json_simple():
test_json = {"name": "John Doe", "age": 30}
mock_file = StringIO(json.dumps(test_json))
with patch('builtins.open', return_value=mock_file):
with patch('bu... | [
{
"docstring": "Reads JSON data from a file and prints each key-value pair at every level.",
"function_declaration": "def print_json_data(file_path):",
"function_name": "print_json_data",
"parameter_list": "(file_path)"
},
{
"docstring": "Recursively traverses a JSON data structure and print... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef print_json_key_value_pairs(file_path):\n \"\"\"\n Traverses a JSON data structure stored in a file and prints each key-value pair at every level.\n \n :param fil... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079241",
"row_id": 79241,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_160981']"
} | 0.61533 | Filter_79241 | I | [
"print_json_data",
"traverse_json"
] | 2 | [
[
"print_json_data",
"traverse_json"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3331a3c049d53dfca2847e33c8db594040657606 | acc85917f064b4b11d44f1ab894cadbc4f1bfedb | |||
v1.0 | instruct | Filter | Filter_79271_I | Write a Python script for a simple calculator that performs basic operations like addition, subtraction, multiplication, and division. The script should include a function for each operation and take user input to decide which operation to perform. | def add(a, b):
"""
Returns the sum of a and b.
"""
return a + b
def subtract(a, b):
"""
Returns the difference of a and b.
"""
return a - b
def multiply(a, b):
"""
Returns the product of a and b.
"""
return a * b
def divide(a, b):
"""
Returns the quotient of a ... | from solution import add, subtract, multiply, divide, calculator
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(0, 0) == 0
assert subtract(3, 5) == -2
def test_multiply():
assert multiply(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,
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 of a and b.\n \"\"\"\n return a -... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079271",
"row_id": 79271,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161047']"
} | 0.608208 | Filter_79271 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | cf0e59bee0d00006a49b5aecb52179464f854c96 | 776065c12747e4d48caa18abfc9959d52a9af111 | |||
v1.0 | instruct | Filter | Filter_79274_I | How can I create a function to simulate a simple dice game where two players roll a dice and the player with the higher roll wins? | import random
def roll_dice():
"""
Simulates rolling a six-sided dice and returns the result.
"""
return random.randint(1, 6)
def dice_game():
"""
Simulates a simple dice game where two players roll a dice and the player with the higher roll wins.
Returns a tuple containing the rolls of Pl... | from solution import roll_dice, dice_game
def test_roll_dice_within_range():
for _ in range(100): # Test a large number of rolls to ensure randomness and range
roll = roll_dice()
assert 1 <= roll <= 6
def test_dice_game():
results = [dice_game() for _ in range(100)]
for player1_roll,... | [
{
"docstring": "Simulates rolling a six-sided dice and returns the result.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a simple dice game where two players roll a dice and the player with the higher roll wins... | [
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 dice_roll():\n \"\"\"\n Simulates a dice roll and returns a random integer between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef simple_dice_game():\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079274",
"row_id": 79274,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161053']"
} | 0.481294 | Filter_79274 | I | [
"roll_dice",
"dice_game"
] | 2 | [
[
"dice_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 34aec0e1f30e803d98922384cf084b6ba45acaa2 | 1a0b0520236248bcffc2057044477e14293c935b | |||
v1.0 | instruct | Filter | Filter_79287_I | Write a Python function named `calculate_square_and_cube` that takes a single integer argument and returns a tuple containing the square and cube of the input number. The function should be well-documented, including a docstring that explains what the function does, its parameters, and what it returns. Additionally, in... | def calculate_square_and_cube(n):
"""
Calculate the square and cube of the input number.
Parameters:
n (int): The input integer number.
Returns:
tuple: A tuple containing the square and cube of the input number.
"""
square = n * n
cube = n * n * n
return (square, cube)
def ver... | from solution import calculate_square_and_cube, verify_results
def test_calculate_square_and_cube_positive_number():
assert calculate_square_and_cube(3) == (9, 27)
def test_calculate_square_and_cube_negative_number():
assert calculate_square_and_cube(-2) == (4, -8)
def test_calculate_square_and_cube_zero():
... | [
{
"docstring": "Calculate the square and cube of the input number.\n\nParameters:\nn (int): The input integer number.\n\nReturns:\ntuple: A tuple containing the square and cube of the input number.",
"function_declaration": "def calculate_square_and_cube(n):",
"function_name": "calculate_square_and_cube... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_square_and_cube(n):\n \"\"\"\n Calculate the square and cube of the input number.\n\n Parameters:\n n (int): The input integer number.\n\n Returns:\n tuple: A t... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079287",
"row_id": 79287,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161075']"
} | 0.710509 | Filter_79287 | I | [
"calculate_square_and_cube",
"verify_results"
] | 2 | [
[
"verify_results",
"calculate_square_and_cube"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c06f7ddc547e7476031dc79d92c9cdad5149ebd | e06acf2e65ec60ba15b4c6044f1b47aa8b577160 | |||
v1.0 | instruct | Filter | Filter_79303_I | Can you help me with a Python function to check if a number is a prime number? How can I use this function to identify all prime numbers within a range, say from 1 to 100? | def is_prime(n):
"""
Check if 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
return Tr... | 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(17) == True
assert is_prime(20) == False
assert is_prime(1) == False
assert is_prime(-1) == False
def test_find_primes_... | [
{
"docstring": "Check if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers within the range from start to end (inclusive).",
"function_declaration": "def find_primes_in_range(s... | [
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.\n \n Args:\n n : int : the number to check\n \n Returns:\n bool : True if n is a prime number, False otherwise... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079303",
"row_id": 79303,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161107']"
} | 0.768979 | Filter_79303 | I | [
"is_prime",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc73dc66012dd7e80eb7a085f39f19fd66cd1d1d | eec6459f4b1d8afeb48c47fbd1ab27dd499a86fa | |||
v1.0 | instruct | Filter | Filter_79304_I | Hello, can you write a Python code to find the nth prime number? Here, n is a positive integer provided by the user. For example, if the user inputs 5, the output should be 11, as 11 is the 5th prime number. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import nth_prime
def test_nth_prime_first():
assert nth_prime(1) == 2
def test_nth_prime_fifth():
assert nth_prime(5) == 11
def test_nth_prime_tenth():
assert nth_prime(10) == 29
def test_nth_prime_twentieth():
assert nth_prime(20) == 71
def test_nth_prime_negative():
try:
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to find the nth prime number.",
"function_declaration": "def nth_prime(n):",
"function_nam... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079304",
"row_id": 79304,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161110']"
} | 0.723478 | Filter_79304 | I | [
"is_prime",
"nth_prime"
] | 2 | [
[
"nth_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f37090459a7a316a7a9f9836795fb01f59ece2a1 | 05abccd61b5f3eeb1934db36dd32f0998642545e | |||
v1.0 | instruct | Filter | Filter_79324_I | Given a positive integer `n`, how can I write a Python function to calculate the nth Fibonacci number using matrix exponentiation? | def matrix_multiply(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_power(matrix, n):
"""
... | from solution import fibonacci
def test_fibonacci_0():
assert fibonacci(0) == 0
def test_fibonacci_1():
assert fibonacci(1) == 1
def test_fibonacci_2():
assert fibonacci(2) == 1
def test_fibonacci_3():
assert fibonacci(3) == 2
def test_fibonacci_10():
assert fibonacci(10) == 55
def test_fibona... | [
{
"docstring": "Multiplies two 2x2 matrices A and B.",
"function_declaration": "def matrix_multiply(A, B):",
"function_name": "matrix_multiply",
"parameter_list": "(A, B)"
},
{
"docstring": "Raises a 2x2 matrix to the power of n using exponentiation by squaring.",
"function_declaration":... | [
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 matrix_fibonacci(n):\n \"\"\"\n Calculates the nth Fibonacci number using matrix exponentiation.\n\n Parameters:\n n (int): The position of the Fibonacci ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079324",
"row_id": 79324,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161159']"
} | 0.63645 | Filter_79324 | I | [
"matrix_multiply",
"matrix_power",
"fibonacci"
] | 3 | [
[
"fibonacci",
"matrix_power"
],
[
"matrix_power",
"matrix_multiply"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | feb45a5d63ce52cacab37fd50b16e0770d539ca6 | 8085c97746b109b22a4613a24991dfb5b83eb6c6 | |||
v1.0 | instruct | Filter | Filter_79332_I | I need help with a Python script that calculates the sum of the first 100 prime numbers. Can you provide a Python code snippet for this task? | 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 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(5) == True
assert is_prime(29) == True
assert is_prime(0) == False
assert is_prime(1) == False
def test_sum_of_first... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of the first 100 prime numbers.",
"function_declaration": "def sum_of_first_100_primes():",
"function_na... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079332",
"row_id": 79332,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161176']"
} | 0.560755 | Filter_79332 | I | [
"is_prime",
"sum_of_first_100_primes"
] | 2 | [
[
"sum_of_first_100_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1a8a3fcb922629c14a7a85deb84dd2180af935ba | 1c35ef7cc0cc8182819e9f683279ef7cb4a6c5aa | |||
v1.0 | instruct | Filter | Filter_79389_I | Can you explain how to implement a heapsort algorithm using a max heap in Python? | def heapify(arr, n, i):
"""
Helper function to ensure the max-heap property for the subtree rooted at index i.
:param arr: List of elements
:param n: Size of the heap
:param i: Index of the root element of the current subtree
"""
largest = i
left = 2 * i + 1
right = 2 * i + 2
if... | from solution import heapsort
def test_heapsort_with_positive_numbers():
arr = [4, 10, 3, 5, 1]
expected = [1, 3, 4, 5, 10]
heapsort(arr)
assert arr == expected
def test_heapsort_with_negative_numbers():
arr = [-1, -3, -2, -4, -5]
expected = [-5, -4, -3, -2, -1]
heapsort(arr)
assert ar... | [
{
"docstring": "Helper function to ensure the max-heap property for the subtree rooted at index i.\n:param arr: List of elements\n:param n: Size of the heap\n:param i: Index of the root element of the current subtree",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"p... | [
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 To heapify a subtree rooted with node i which is an index in arr[].\n n is the size of the heap.\n \"\"\"\n largest = i # Initialize largest ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079389",
"row_id": 79389,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161306']"
} | 0.619131 | Filter_79389 | I | [
"heapify",
"heapsort"
] | 2 | [
[
"heapsort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6e8fb7b2a69cbb6943020c5c9fad95e6bb60b05 | 2fab7eef29ff2afa684a8408f60d042b4353407e | |||
v1.0 | instruct | Filter | Filter_79397_I | Can you help me generate a Python script that creates a simple text-based calculator? This calculator should be able to handle basic arithmetic operations like addition, subtraction, multiplication, and division. It should also include error handling for cases like division by zero and invalid input. | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def calculator(operation, a, b):
if operation == 'add':
return add(a, b)
elif operation == 'su... | from solution import add, subtract, multiply, divide, calculator
import pytest
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():
ass... | [
{
"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... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculator(operation, a, b):\n \"\"\"\n A simple text-based calculator that performs basic arithmetic operations.\n \n Parameters:\n operation (str): The operation to be per... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079397",
"row_id": 79397,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161327']"
} | 0.499097 | Filter_79397 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | b8850890c7a7cea6615e7edc416a3e42bb8dde84 | 75b588c853a4f058770d565729939453784c3ce0 | |||
v1.0 | instruct | Filter | Filter_79400_I | I want to create a simple KNN classifier. Can you provide a step-by-step guide to building one from scratch in Python without using any external libraries like scikit-learn or pandas? | import math
from collections import Counter
def euclidean_distance(point1, point2):
"""
Calculate the Euclidean distance between two points.
"""
return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2)))
def knn_classifier(training_data, training_labels, test_point, k):
"""
Classify t... | from solution import euclidean_distance, knn_classifier
def test_euclidean_distance():
assert euclidean_distance([0, 0], [3, 4]) == 5.0
assert euclidean_distance([1, 1], [4, 5]) == 5.0
assert euclidean_distance([1, 2], [1, 2]) == 0.0
assert euclidean_distance([-1, -2], [-4, -6]) == 5.0
def test_knn_cl... | [
{
"docstring": "Calculate the Euclidean distance between two points.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Classify the test_point based on the k-nearest neighbors al... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import Counter\n\nclass KNNClassifier:\n def __init__(self, k=3):\n self.k = k\n self.train_X = []\n self.train_y = []\n\n def fit(self... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079400",
"row_id": 79400,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161334']"
} | 0.38249 | Filter_79400 | I | [
"euclidean_distance",
"knn_classifier"
] | 2 | [
[
"knn_classifier",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 987e54beeb49fcb9b385d3aedfef01244c9b5e86 | 02846916de5a230bfb7bc244f207672a920cac50 | |||
v1.0 | instruct | Filter | Filter_79418_I | Can you provide a detailed explanation of how to implement a simple command line calculator in Python? Building a command line calculator involves multiple steps. Could you guide me through the process, including setting up the environment, writing the code, and running the calculator? | def add(a, b):
"""Return the sum of two numbers."""
return a + b
def subtract(a, b):
"""Return the difference of two numbers."""
return a - b
def multiply(a, b):
"""Return the product of two numbers."""
return a * b
def divide(a, b):
"""Return the quotient of two numbers."""
if b == 0... | import pytest
from solution import add, subtract, multiply, divide
def test_add():
assert add(1, 2) == 3
assert add(-1, 1) == 0
assert add(-1, -1) == -2
assert add(0, 0) == 0
def test_subtract():
assert subtract(2, 1) == 1
assert subtract(-1, -1) == 0
assert subtract(1, -1) == 2
assert... | [
{
"docstring": "Return the sum of two numbers.",
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": "Return the difference of two numbers.",
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"pa... | [
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 return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079418",
"row_id": 79418,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161362']"
} | 0.473869 | Filter_79418 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | df2b1b0215f21015a02a14aca7178415be5b4feb | 1b6ed102b0c44f854b29e1d46f3a262ca8c417ef | |||
v1.0 | instruct | Filter | Filter_79443_I | Write a Python code to find all prime numbers within a given range [a, b], where a and b are user inputs. The code should also count the number of prime numbers found in that range. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def primes_in_range(a, ... | from solution import is_prime, 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(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(20) == Fa... | [
{
"docstring": "Check if a number 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 in the range [a, b] and counts them.",
"function_declaration": "def primes_in_ran... | [
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": "00079443",
"row_id": 79443,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161407']"
} | 0.66731 | Filter_79443 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d5b7966a2f409b8f3b6ee06da93a22570925549 | ab4c7f4b7810e1aee1653abfecb57695b343bf72 | |||
v1.0 | instruct | Filter | Filter_79517_I | Can you provide a Python code example that demonstrates how to estimate the parameters of a logistic regression model using maximum likelihood estimation? | import numpy as np
from scipy.optimize import minimize
from scipy.special import expit
def sigmoid(z):
return expit(z)
def log_likelihood(params, X, y):
linear_combination = np.dot(X, params)
likelihood = y * np.log(sigmoid(linear_combination)) + (1 - y) * np.log(1 - sigmoid(linear_combination))
retur... | from solution import log_likelihood, fit_logistic_regression
import numpy as np
from scipy.optimize import OptimizeResult
def test_log_likelihood():
X = np.array([[0.5, 1.5], [1.0, 1.0], [1.5, 0.5], [2.0, 0.2]])
y = np.array([0, 0, 1, 1])
params = np.array([1.0, 1.0])
log_likelihood_value = log_likelih... | [
{
"docstring": null,
"function_declaration": "def sigmoid(z):",
"function_name": "sigmoid",
"parameter_list": "(z)"
},
{
"docstring": null,
"function_declaration": "def log_likelihood(params, X, y):",
"function_name": "log_likelihood",
"parameter_list": "(params, 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\nfrom scipy.optimize import minimize\nfrom scipy.special import expit\n\ndef sigmoid(z):\n return expit(z)\n\ndef log_likelihood(params, X, y):\n linear_combination = ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079517",
"row_id": 79517,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161581']"
} | 0.489362 | Filter_79517 | I | [
"sigmoid",
"log_likelihood",
"fit_logistic_regression"
] | 3 | [
[
"fit_logistic_regression",
"log_likelihood"
],
[
"log_likelihood",
"sigmoid"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | d6a12a80b43c7cf9bc5c320f00651c7614b8b76c | f025243367765a1dab983fbccc9ba0d08dab1d1c | |||
v1.0 | instruct | Filter | Filter_79531_I | How can I generate a Python code to find the prime numbers within a given range using a function? | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def find_primes_in_range(start, end):
"""
Returns a list of prime numbers in the... | from solution import is_prime, find_primes_in_range
def test_is_prime_with_prime_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(11) == True
def test_is_prime_with_non_prime_numbers():
assert is_prime(1) == False
assert is_prime(4) ==... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers in the given range [start, end].",
"function_declaration": "def find... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_primes_in_range(start, end):\n \"\"\"\n Returns a list of prime numbers within the given range [start, end].\n\n :param start: Starting value of the range (inclusive)\n :p... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079531",
"row_id": 79531,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161606']"
} | 0.732457 | Filter_79531 | I | [
"is_prime",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b4fef15b8005af89bf111e8f31fc018a980d9a0 | 13c7a2e975296def5e1a0e008f72a8795a282408 | |||
v1.0 | instruct | Filter | Filter_79544_I | In Python, how can you create a generator function that yields an infinite sequence of Fibonacci numbers? An infinite sequence is a sequence that does not have a finite number of terms. How can I generate the first 10 Fibonacci numbers from this generator? | def fibonacci_generator():
"""
Generator function that yields an infinite sequence of Fibonacci numbers.
"""
a, b = 0, 1
while True:
yield a
a, b = b, a + b
# Function to get the first n Fibonacci numbers from the generator
def get_first_n_fibonacci(n):
"""
Generate the firs... | from solution import fibonacci_generator, get_first_n_fibonacci
def test_first_10_fibonacci():
assert get_first_n_fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_first_fibonacci():
assert get_first_n_fibonacci(1) == [0]
def test_first_5_fibonacci():
assert get_first_n_fibonacci(5) == [0, 1, 1... | [
{
"docstring": "Generator function that yields an infinite sequence of Fibonacci numbers.",
"function_declaration": "def fibonacci_generator():",
"function_name": "fibonacci_generator",
"parameter_list": "()"
},
{
"docstring": "Generate the first n Fibonacci numbers using the fibonacci_gener... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def infinite_fibonacci():\n \"\"\"\n Generator function that yields an infinite sequence of Fibonacci numbers.\n \"\"\"\n a, b = 0, 1\n while True:\n yield a\n a, ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079544",
"row_id": 79544,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161627']"
} | 0.655164 | Filter_79544 | I | [
"fibonacci_generator",
"get_first_n_fibonacci"
] | 2 | [
[
"get_first_n_fibonacci",
"fibonacci_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5985980d11b9bdad32e3df3afd9ff480f8f627e7 | 0432e070ddd9621d29a86ebd08468ead70d8ecf0 | |||
v1.0 | instruct | Filter | Filter_79548_I | Can you generate a Python function that converts a given JSON file into a CSV file? This function should take the input JSON file path and output CSV file path as arguments and handle cases where the JSON structure might not be flat (i.e., it may contain nested structures). | import json
import csv
from collections import OrderedDict
def flatten_json(json_object):
"""
Flattens a nested JSON object and returns an ordered dictionary.
"""
def recurse(obj, parent_key=''):
items = []
if isinstance(obj, dict):
for k, v in obj.items():
n... | import json
import os
import csv
from solution import flatten_json, json_to_csv
def test_flatten_json_with_nested_structure():
nested_json = {
"name": "John",
"address": {
"city": "New York",
"zip": "10001"
},
"phones": [
{"type": "home", "number"... | [
{
"docstring": "Flattens a nested JSON object and returns an ordered dictionary.",
"function_declaration": "def flatten_json(json_object):",
"function_name": "flatten_json",
"parameter_list": "(json_object)"
},
{
"docstring": "Converts a JSON file into a CSV file.\n\nArgs:\njson_file_path: s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport csv\n\ndef json_to_csv(json_file_path, csv_file_path):\n \"\"\"\n Converts a given JSON file to a CSV file. Handles nested JSON structures.\n \n Parameters:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079548",
"row_id": 79548,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161636']"
} | 0.81881 | Filter_79548 | I | [
"flatten_json",
"json_to_csv"
] | 2 | [
[
"json_to_csv",
"flatten_json"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 74de68bb2daf5da12ae334cca05d5ed53d9f3d13 | af2d5a8dbe8a4b4f4ff45147cab806e1fd737c36 | |||
v1.0 | instruct | Filter | Filter_79571_I | Can you write a Python function that identifies and returns all prime numbers within a given range, say from 1 to 100? Could you also provide a brief explanation of how the function works? | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import primes_in_range
def test_primes_in_range_1_to_10():
assert primes_in_range(1, 10) == [2, 3, 5, 7]
def test_primes_in_range_1_to_100():
assert primes_in_range(1, 100) == [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53, 59, 61, 67, 71, 73, 79, 83, 89, 97
]
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers within a given range.",
"function_declaration": "def primes_in_range(st... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079571",
"row_id": 79571,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161689']"
} | 0.689406 | Filter_79571 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 47bf7cefd47b985e99c5505f89109746ef654ef6 | 3aa1a7ec4ac515225a29583e37bcb4470ea82ad9 | |||
v1.0 | instruct | Filter | Filter_79619_I | Write a Python function that takes a list of integers as input and returns a new list with the elements sorted in ascending order. The sorting should be done using the heap sort algorithm. | def heapify(arr, n, i):
"""
Helper function to maintain the heap property.
Parameters:
arr (list): The list being sorted.
n (int): Size of the heap.
i (int): Index of the root element of the subtree.
"""
largest = i # Initialize largest as root
left = 2 * i + 1 # left child
... | 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_list():
assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_heap_sort_reverse_sorted_list():
assert heap_sort([5... | [
{
"docstring": "Helper function to maintain the heap property.\n\nParameters:\narr (list): The list being sorted.\nn (int): Size of the heap.\ni (int): Index of the root element of the subtree.",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heapify(arr, n, i):\n \"\"\"\n Helper function to maintain heap property.\n \"\"\"\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if left < n and arr[left] >... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079619",
"row_id": 79619,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161773']"
} | 0.790032 | Filter_79619 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 93aa340712e52149d56c3200ac12071194822530 | 6e8a4efaa9ff19866762ca61554c4bf349449a0a | |||
v1.0 | instruct | Filter | Filter_79628_I | Can you provide a Python code that generates a dataset of synthetic images with corresponding labels for a binary classification task? The images should be simple grayscale shapes (like circles, squares) with some noise added to them. | import numpy as np
import cv2
import random
import os
def generate_synthetic_image(shape, image_size=(64, 64), noise_level=0.1):
"""
Generates a synthetic image of a given shape (circle or square) with added noise.
Parameters:
shape (str): The shape of the object in the image ('circle' or 'square'... | import os
import cv2
import numpy as np
from solution import generate_synthetic_image, generate_dataset
def test_generate_synthetic_image():
circle_img = generate_synthetic_image('circle')
square_img = generate_synthetic_image('square')
assert circle_img.shape == (64, 64)
assert square_img.shape =... | [
{
"docstring": "Generates a synthetic image of a given shape (circle or square) with added noise.\n\nParameters:\nshape (str): The shape of the object in the image ('circle' or 'square').\nimage_size (tuple): The size of the image.\nnoise_level (float): The level of noise to add to the image.\n\nReturns:\nnumpy... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport cv2\nimport random\n\ndef generate_synthetic_image(shape='circle', size=(64, 64), noise_level=0.1):\n \"\"\"\n Generate a synthetic grayscale image of a given ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079628",
"row_id": 79628,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161785']"
} | 0.451829 | Filter_79628 | I | [
"generate_synthetic_image",
"generate_dataset"
] | 2 | [
[
"generate_dataset",
"generate_synthetic_image"
]
] | 1 | [] | false | [] | false | pytest | true | [
"cv2",
"numpy"
] | false | 6169600e784a39b04f0a5121ae7649fef68ac694 | bd295a864617dae483a3ad5e773229ca4640a9ca | |||
v1.0 | instruct | Filter | Filter_79629_I | Can you provide a Python function that generates a filtered list of prime numbers up to a given limit? The function should take an integer `n` as input and return a list of all prime numbers less than `n`. Additionally, it should use a helper function to check for primality. | def is_prime(num):
"""
Check if a number is a prime number.
Returns True if num is prime, otherwise False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
max_divisor = int(num**0.5) + 1
for i in range(3, max_divisor, 2):
... | from solution import is_prime, generate_primes
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(11)
def test_generate_primes():
assert generate_p... | [
{
"docstring": "Check if a number is a prime number.\nReturns True if num is prime, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a list of all prime numbers less than n.",
"function_de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n 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 == 0 or num % 3 == 0:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079629",
"row_id": 79629,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161786']"
} | 0.649965 | Filter_79629 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d2215edf5865ffbf2d5033d31d2f15faddc765c4 | 7ece6f13f80b2bab37ca98cd31fcaea36684695b | |||
v1.0 | instruct | Filter | Filter_79650_I | I need to find the closest pair of points in a set of points using the brute force method in Python. Can you provide me with a sample code? | import math
def distance(point1, point2):
"""
Calculate the Euclidean distance between two points.
"""
return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)
def closest_pair_brute_force(points):
"""
Find the closest pair of points using the brute force method.
"""
... | from solution import distance, closest_pair_brute_force
def test_distance():
assert distance((0, 0), (3, 4)) == 5.0
assert distance((1, 1), (4, 5)) == 5.0
assert distance((1, 1), (1, 1)) == 0.0
def test_closest_pair_brute_force():
points = [(0, 0), (1, 1), (2, 2), (3, 3)]
assert closest_pair_brute... | [
{
"docstring": "Calculate the Euclidean distance between two points.",
"function_declaration": "def distance(point1, point2):",
"function_name": "distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Find the closest pair of points using the brute force method.",
"function_d... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import sqrt\n\ndef closest_pair_brute_force(points):\n \"\"\"\n Calculates the closest pair of points using brute force method.\n \n :param points: List of tuples represe... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079650",
"row_id": 79650,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161836']"
} | 0.606459 | Filter_79650 | I | [
"distance",
"closest_pair_brute_force"
] | 2 | [
[
"closest_pair_brute_force",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e6fb68626ab057e8b33f77fdfd3abef162ad5c8 | 3b17cfbb8d5e4c1a4d97c38e0168b7dff8f4bf85 | |||
v1.0 | instruct | Filter | Filter_79653_I | How can I run a real-time simulation of air quality monitoring using Python? | import time
import random
def get_air_quality_data():
"""
Simulates getting air quality data with random values.
Returns a dictionary with PM2.5, PM10, CO, and quality status.
"""
air_quality_data = {
"PM2.5": round(random.uniform(0, 500) , 2), # µg/m³
"PM10": round(random.uniform(0... | from solution import get_air_quality_data
def test_air_quality_data_keys():
data = get_air_quality_data()
assert "PM2.5" in data
assert "PM10" in data
assert "CO" in data
assert "status" in data
def test_air_quality_pm25_range():
data = get_air_quality_data()
assert 0 <= data["PM2.5"] <= 5... | [
{
"docstring": "Simulates getting air quality data with random values.\nReturns a dictionary with PM2.5, PM10, CO, and quality status.",
"function_declaration": "def get_air_quality_data():",
"function_name": "get_air_quality_data",
"parameter_list": "()"
},
{
"docstring": "Runs the air qual... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport random\n\ndef get_air_quality_data():\n \"\"\"\n Simulates getting air quality data with random values.\n Returns a dictionary with PM2.5, PM10, CO, and quality st... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079653",
"row_id": 79653,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_161845']"
} | 0.465194 | Filter_79653 | I | [
"get_air_quality_data",
"run_air_quality_simulation"
] | 2 | [
[
"run_air_quality_simulation",
"get_air_quality_data"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af1e4882e416251b923928d1ef6ab75380edb264 | 045d99fa370857bee76301aec84d1742aeb61c16 | |||
v1.0 | instruct | Filter | Filter_79735_I | Can you provide a Python code snippet to calculate the Fibonacci sequence up to a given number `n` using memoization? | def fibonacci_memo(n, memo=None):
"""
Returns the Fibonacci sequence up to the nth number using memoization.
"""
if memo is None:
memo = {}
if n in memo:
return memo[n]
if n <= 1:
return n
memo[n] = fibonacci_memo(n - 1, memo) + fibonacci_me... | from solution import fibonacci_memo, fibonacci_sequence
def test_fibonacci_memo():
assert fibonacci_memo(0) == 0
assert fibonacci_memo(1) == 1
assert fibonacci_memo(2) == 1
assert fibonacci_memo(3) == 2
assert fibonacci_memo(4) == 3
assert fibonacci_memo(5) == 5
def test_fibonacci_sequence():
... | [
{
"docstring": "Returns the Fibonacci sequence up to the nth number using memoization.",
"function_declaration": "def fibonacci_memo(n, memo=None):",
"function_name": "fibonacci_memo",
"parameter_list": "(n, memo=None)"
},
{
"docstring": "Returns a list of the Fibonacci sequence up to the nt... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo=None):\n \"\"\"\n Returns the Fibonacci sequence up to the nth number using memoization.\n \"\"\"\n if memo is None:\n memo = {}\n \n if n in mem... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079735",
"row_id": 79735,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162017']"
} | 0.678047 | Filter_79735 | I | [
"fibonacci_memo",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci_memo"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efb377b3a75b7311594876ce767c073a9a7d47ee | 6686877c99fcf11d3b42df96022a65f14ccfd28d | |||
v1.0 | instruct | Filter | Filter_79743_I | Given a string `s` and a list of strings `d`, find the longest string in `d` that is a subsequence of `s`. If there are multiple such strings, return the lexicographically smallest one. A subsequence of a string is a new string generated from the original string with some characters (possibly none) deleted without chan... | def is_subsequence(s, sub):
"""
Helper function to check if `sub` is a subsequence of `s`.
"""
it = iter(s)
return all(char in it for char in sub)
def find_longest_subsequence(s, d):
"""
Returns the longest string in `d` that is a subsequence of `s`.
If there are multiple such strings, ... | from solution import find_longest_subsequence
def test_basic():
s = "abppplee"
d = ["able", "ale", "apple", "bale", "kangaroo"]
assert find_longest_subsequence(s, d) == "apple"
def test_empty_dictionary():
s = "abppplee"
d = []
assert find_longest_subsequence(s, d) == ""
def test_no_subsequen... | [
{
"docstring": "Helper function to check if `sub` is a subsequence of `s`.",
"function_declaration": "def is_subsequence(s, sub):",
"function_name": "is_subsequence",
"parameter_list": "(s, sub)"
},
{
"docstring": "Returns the longest string in `d` that is a subsequence of `s`.\nIf there are... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(x, y):\n it = iter(y)\n return all(c in it for c in x)\n\ndef find_longest_subsequence(s, d):\n \"\"\"\n Given a string `s` and a list of strings `d`, find the l... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079743",
"row_id": 79743,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162031']"
} | 0.749451 | Filter_79743 | I | [
"is_subsequence",
"find_longest_subsequence"
] | 2 | [
[
"find_longest_subsequence",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9981d6355a0c1cc4325d2cec37f1a9bbe1bffbc8 | 95168d1ec4166490b35ef92b38250aae36705839 | |||
v1.0 | instruct | Filter | Filter_79756_I | Create a Python function that sorts a list of integers in ascending order using the merge sort algorithm. Provide a detailed explanation of how the merge sort algorithm works with an example. | def merge_sort(arr):
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
Parameters:
arr (list): A list of integers.
Returns:
list: A new list of integers sorted in ascending order.
"""
# Base case: if the array has 0 or 1 element, it is already sorted
... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_unsorted_list():
assert merge_sort... | [
{
"docstring": "Sorts a list of integers in ascending order using the merge sort algorithm.\n\nParameters:\narr (list): A list of integers.\n\nReturns:\nlist: A new list of integers sorted in ascending order.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter... | [
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 a list of integers in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n # Divide the arr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079756",
"row_id": 79756,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162056']"
} | 0.551519 | Filter_79756 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52251844c0815af095afca97cd4b89487f545548 | 466344dff1d08b8dab2c4604a8ce050046fa202b | |||
v1.0 | instruct | Filter | Filter_79821_I | Write a Python program that prompts the user for a number of circles and then draws that number of circles randomly placed on a canvas using the `turtle` module. | import turtle
import random
def draw_circle(x, y, radius):
"""
Draws a circle at the given coordinates (x, y) with the provided radius.
"""
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.circle(radius)
def draw_random_circles(num_circles, canvas_width, canvas_height):
"""
... | # Since the turtle graphics library is interactive and visual, we cannot use typical unit tests to validate the output.
# Instead, we can test the underlying logic including random number generation and function composition.
# We will mock the turtle module functions and test that the correct number of circles are atte... | [
{
"docstring": "Draws a circle at the given coordinates (x, y) with the provided radius.",
"function_declaration": "def draw_circle(x, y, radius):",
"function_name": "draw_circle",
"parameter_list": "(x, y, radius)"
},
{
"docstring": "Draws the given number of circles randomly placed on a ca... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import turtle\nimport random\n\ndef draw_circle(x, y, radius):\n \"\"\"\n Draws a circle at the given coordinates (x, y) with the provided radius.\n \"\"\"\n turtle.penup()\n tu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079821",
"row_id": 79821,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162209']"
} | 0.718244 | Filter_79821 | I | [
"draw_circle",
"draw_random_circles"
] | 2 | [
[
"draw_random_circles",
"draw_circle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b81cad9fb9c414350d8dcb76c00dba8bc451fac | 6f284be31e4d14952298abaefbd8b2bd90111faa | |||
v1.0 | instruct | Filter | Filter_79822_I | I'm looking to create a simple menu system for a console application in Python. How can I create a menu that allows users to choose between different options by entering numbers corresponding to their choices? | def display_menu():
print("Please choose an option:")
print("1. Option 1")
print("2. Option 2")
print("3. Option 3")
print("4. Exit")
def main_menu():
while True:
display_menu() # Display the menu
choice = input("Enter your choice: ")
if choice == '1':
... | from solution import display_menu, main_menu
def test_display_menu(capsys):
display_menu()
captured = capsys.readouterr()
assert "Please choose an option:\n1. Option 1\n2. Option 2\n3. Option 3\n4. Exit\n" in captured.out
def test_main_menu(monkeypatch, capsys):
inputs = iter(['1', '2', '3', '4'])
... | [
{
"docstring": null,
"function_declaration": "def display_menu():",
"function_name": "display_menu",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def main_menu():",
"function_name": "main_menu",
"parameter_list": "()"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def display_menu(options):\n \"\"\"\n Displays a menu and returns the user's choice.\n\n Args:\n options (list of str): A list of strings representing the menu options.\n\n Retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079822",
"row_id": 79822,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162211']"
} | 0.358356 | Filter_79822 | I | [
"display_menu",
"main_menu"
] | 2 | [
[
"main_menu",
"display_menu"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed491117e79681525114d3bcb7b9505aba0093ea | 47e8dcc01b7424936ce8784abdaa360d432277cd | |||
v1.0 | instruct | Filter | Filter_79852_I | Hello Qwen, I want to create a simple text-based game in Python. Can you provide me with a basic framework for this game? | def welcome_message():
"""
Display a welcome message to the player.
"""
return "Welcome to the Text-Based Adventure Game!"
def main_menu():
"""
Display the main menu options to the player.
"""
return "Main Menu:\n1. Start Game\n2. Instructions\n3. Quit"
def instructions():
"""
... | from solution import welcome_message, main_menu, instructions, start_game, invalid_choice, handle_choice
def test_welcome_message():
assert welcome_message() == "Welcome to the Text-Based Adventure Game!"
def test_main_menu():
expected_output = "Main Menu:\n1. Start Game\n2. Instructions\n3. Quit"
assert ... | [
{
"docstring": "Display a welcome message to the player.",
"function_declaration": "def welcome_message():",
"function_name": "welcome_message",
"parameter_list": "()"
},
{
"docstring": "Display the main menu options to the player.",
"function_declaration": "def main_menu():",
"funct... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Game:\n def __init__(self):\n self.grid = [\n ['.', '.', '.', '.', '.'],\n ['.', 'I', '.', 'I', '.'],\n ['.', '.', 'P', '.', '.'],\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079852",
"row_id": 79852,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162260']"
} | 0.448137 | Filter_79852 | I | [
"welcome_message",
"main_menu",
"instructions",
"start_game",
"invalid_choice",
"handle_choice"
] | 6 | [
[
"handle_choice",
"instructions"
],
[
"handle_choice",
"invalid_choice"
],
[
"handle_choice",
"start_game"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 93acfeaa40a9ffa3820a80942c74d5e37208a688 | b6383e81c3d263649da0909bf4f374aa0fbe2549 | |||
v1.0 | instruct | Filter | Filter_79869_I | Can you provide a Python script that can generate a prime number within a given range? For example, if I input a range of 10 to 50, it should return a prime number within that range. | import random
def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def generate_prime_in_range(start, end):
"""
Generates and returns a prime number ... | from solution import is_prime, generate_prime_in_range
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(-3) == False
def test_generate_p... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates and returns a prime number within a given range [start, end].\nIf no prime number is found within the range, re... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079869",
"row_id": 79869,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162300']"
} | 0.565604 | Filter_79869 | I | [
"is_prime",
"generate_prime_in_range"
] | 2 | [
[
"generate_prime_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9377a1c4a70bb087c9d3b02c98d0c5dfff2801b4 | 04ec58f7505de215423689ecc5fa77eff99b090f | |||
v1.0 | instruct | Filter | Filter_79921_I | I need some help with a Python script that processes data from a CSV file. The script reads the CSV, performs some calculations, and writes the results to a new CSV file. Can you provide a basic template for such a script? | import csv
def read_csv(input_file):
"""
Reads a CSV file and returns a list of dictionaries,
where each dictionary represents a row in the CSV file.
"""
data = []
with open(input_file, mode='r') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
data... | import pytest
from solution import read_csv, calculate, write_csv, process_csv
import os
@pytest.fixture
def sample_data():
return [
{'value1': '1', 'value2': '2'},
{'value1': '3', 'value2': '4'},
{'value1': '5', 'value2': '6'}
]
@pytest.fixture
def sample_data_with_results():
retu... | [
{
"docstring": "Reads a CSV file and returns a list of dictionaries, \nwhere each dictionary represents a row in the CSV file.",
"function_declaration": "def read_csv(input_file):",
"function_name": "read_csv",
"parameter_list": "(input_file)"
},
{
"docstring": "Performs calculations on the ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\n\ndef read_csv(file_path):\n \"\"\"\n Reads data from a CSV file and returns a list of dictionaries.\n \"\"\"\n with open(file_path, mode='r', newline='') as file:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079921",
"row_id": 79921,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162442']"
} | 0.605131 | Filter_79921 | I | [
"read_csv",
"calculate",
"write_csv",
"process_csv"
] | 4 | [
[
"process_csv",
"calculate"
],
[
"process_csv",
"read_csv"
],
[
"process_csv",
"write_csv"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | de4e829cc54a9dd1a64c385691a6ec5df979579f | 4eb598861fe96130695d03b58869847b630cab64 | |||
v1.0 | instruct | Filter | Filter_79966_I | Generate a step-by-step guide to creating a simple chatbot using Python and the Flask framework. | # First, install Flask by running `pip install Flask`
# Create a file named `app.py` with the following content:
from flask import Flask, request, jsonify
app = Flask(__name__)
# Route to handle welcome message
@app.route('/welcome', methods=['GET'])
def welcome():
return "Welcome to the chatbot!"
# Route to h... | import json
from solution import app
# Create a test client using the Flask application configured for testing
def test_welcome():
tester = app.test_client()
response = tester.get('/welcome')
assert response.status_code == 200
assert response.data == b'Welcome to the chatbot!'
def test_chat_valid_inpu... | [
{
"docstring": null,
"function_declaration": "def welcome():",
"function_name": "welcome",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat",
"parameter_list": "()"
},
{
"docstring": null,
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# First, install Flask by running `pip install Flask`\n\n# Create a file named `app.py` with the following content:\n\nfrom flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n# R... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00079966",
"row_id": 79966,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162539']"
} | 0.367764 | Filter_79966 | I | [
"welcome",
"chat",
"generate_response"
] | 3 | [
[
"chat",
"generate_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 78a0517c58812a473e650900e850e1212010acf8 | 86a18822c30df38b5a949fdc9e1612afa7f6c721 | |||
v1.0 | instruct | Filter | Filter_79967_I | Can you help me write a Python program that simulates a simple calculator? The calculator should be able to handle basic arithmetic operations like addition, subtraction, multiplication, and division. It should also be able to handle errors like division by zero and invalid inputs. | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def calculator(operation, a, b):
"""
Performs the given operation with operands a and b.
:par... | from solution import calculator
def test_add():
assert calculator('add', 1, 2) == 3
def test_subtract():
assert calculator('subtract', 5, 3) == 2
def test_multiply():
assert calculator('multiply', 4, 3) == 12
def test_divide():
assert calculator('divide', 10, 2) == 5
def test_divide_by_zero():
... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef subtract(a, b):\n \"\"\"\n Returns the difference of a and b.\n \"\"\"\n return a -... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00079967",
"row_id": 79967,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162541']"
} | 0.488045 | Filter_79967 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | b5e2930d33a7bb914744f2bb82f5e810ba1820f7 | 4956c8cb8e6bdb619ab7f881c7d889991f94b72c | |||
v1.0 | instruct | Filter | Filter_79971_I | Can you provide an example of how to use the Python `itertools` module to create an infinite steam of prime numbers? | import itertools
def is_prime(n):
"""
Returns True if the number 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_generator():
"""
Generate an infinite stream o... | from solution import is_prime, prime_generator
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == F... | [
{
"docstring": "Returns True if the number n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate an infinite stream of prime numbers.",
"function_declaration": "def prime_generator()... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00079971",
"row_id": 79971,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_162550']"
} | 0.551435 | Filter_79971 | I | [
"is_prime",
"prime_generator"
] | 2 | [
[
"prime_generator",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e6fd78f556c45b17c983b8c8c941c2d8fbf4cd4 | d819fcba0ecf97cc1f41d6291fec52bb6d91fbe4 | |||
v1.0 | instruct | Filter | Filter_80022_I | You are given a list of integers. Write a Python function to find the maximum sum of a contiguous subarray within the list. For example, given the list [-2, 1, -3, 4, -1, 2, 1, -5, 4], the maximum sum of a contiguous subarray is 6 (the subarray [4, -1, 2, 1]). Use the divide-and-conquer approach to solve this problem. | def max_crossing_sum(arr, low, mid, high):
"""
Helper function to find the maximum sum of the subarray crossing the midpoint.
"""
left_sum = float('-inf')
total = 0
for i in range(mid, low - 1, -1):
total += arr[i]
if total > left_sum:
left_sum = total
... | from solution import find_max_subarray_sum
def test_find_max_subarray_sum_example():
assert find_max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
def test_find_max_subarray_sum_all_positive():
assert find_max_subarray_sum([1, 2, 3, 4, 5]) == 15
def test_find_max_subarray_sum_all_negative():
assert ... | [
{
"docstring": "Helper function to find the maximum sum of the subarray crossing the midpoint.",
"function_declaration": "def max_crossing_sum(arr, low, mid, high):",
"function_name": "max_crossing_sum",
"parameter_list": "(arr, low, mid, high)"
},
{
"docstring": "Returns the maximum sum of ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_crossing_sum(arr, left, mid, right):\n left_sum = float('-inf')\n total_sum = 0\n for i in range(mid, left-1, -1):\n total_sum += arr[i]\n if total_sum > left_su... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080022",
"row_id": 80022,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162630']"
} | 0.750758 | Filter_80022 | I | [
"max_crossing_sum",
"max_subarray_sum",
"find_max_subarray_sum"
] | 3 | [
[
"find_max_subarray_sum",
"max_subarray_sum"
],
[
"max_subarray_sum",
"max_crossing_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b71c9d7eaafeea56a137e50465b1d9d8615f729f | 3c8d01c2b74a3c1cfa0772b5ed87cec044e989a7 | |||
v1.0 | instruct | Filter | Filter_80042_I | I am working on a project where I need to convert a set of 3D points from one coordinate system to another. Specifically, I need to apply a transformation that includes translation, rotation, and scaling. Can you guide me on how to do this using Python? | import numpy as np
def translate(points, translation_vector):
"""
Translates the given points by the translation vector.
:param points: numpy array of shape (n, 3) representing the coordinates of n points in 3D space.
:param translation_vector: numpy array of shape (3,) representing the translatio... | from solution import translate, scale, rotate, apply_transformation
import numpy as np
def test_translate():
points = np.array([[1, 2, 3], [4, 5, 6]])
translation_vector = np.array([1, 1, 1])
translated_points = translate(points, translation_vector)
expected_points = np.array([[2, 3, 4], [5, 6, 7]])
... | [
{
"docstring": "Translates the given points by the translation vector.\n\n:param points: numpy array of shape (n, 3) representing the coordinates of n points in 3D space.\n:param translation_vector: numpy array of shape (3,) representing the translation vector.\n:return: numpy array of the same shape as points,... | [
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 transform_points(points, translation=(0, 0, 0), rotation=(0, 0, 0), scaling=(1, 1, 1)):\n \"\"\"\n Transforms a set of 3D points by applying translation, rotati... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080042",
"row_id": 80042,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162661']"
} | 0.422559 | Filter_80042 | I | [
"translate",
"scale",
"rotate",
"apply_transformation"
] | 4 | [
[
"apply_transformation",
"rotate"
],
[
"apply_transformation",
"scale"
],
[
"apply_transformation",
"translate"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 1246089b5dd90d76e075b91515b2ca8559e657da | f3d970b69a0cdbbf8c17aa5633885f1550d87ae7 | |||
v1.0 | instruct | Filter | Filter_80088_I | You are given a task to generate a list of 100 prime numbers. Write a Python program to do that. Also, explain the logic behind your program. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def generate_primes(count):
"""
... | 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(29) == True
assert is_prime(30) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == 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 'count' prime numbers.",
"function_declaration": "def generate_primes(count):",
"function_name": "gener... | [
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": "00080088",
"row_id": 80088,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162718']"
} | 0.631638 | Filter_80088 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 169a4b548cd257181511e431a11038b1415a6f32 | 6758ce3e197ec5320e77a4681f798f9371dae3d9 | |||
v1.0 | instruct | Filter | Filter_80157_I | Write a Python function to find the next prime number after a given number. The function should take an integer as input and return the next prime number as output. For example, the next prime number after 10 is 11, and the next prime number after 13 is 17. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | def test_next_prime_after_10():
assert next_prime(10) == 11
def test_next_prime_after_13():
assert next_prime(13) == 17
def test_next_prime_with_small_numbers():
assert next_prime(0) == 2
assert next_prime(1) == 2
def test_next_prime_after_2():
assert next_prime(2) == 3
def test_next_prime_after... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next prime number after the given number n.",
"function_declaration": "def next_prime(n):",
... | [
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 given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080157",
"row_id": 80157,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162816']"
} | 0.628613 | Filter_80157 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c1553185a0b253e777ac11c0844747bdd9bdf22a | f2af6739e822613f4b4985784e77063121afcdfc | |||
v1.0 | instruct | Filter | Filter_80173_I | I'm trying to solve the differential equation y'' + 3y' + 2y = 0 with initial conditions y(0) = 1 and y'(0) = 0 using the shooting method in Python. However, I'm having trouble implementing it. Can you help me with the code? | import numpy as np
from scipy.integrate import solve_ivp
def system(t, y):
"""
Defines the system of first-order ODEs.
y[0] = y1
y[1] = y2
"""
y1, y2 = y
dydt = [y2, -3 * y2 - 2 * y1]
return dydt
def solve_ode_using_shooting(y1_0, y2_0, t_span, t_eval):
"""
Solves the ODE syste... | import numpy as np
from solution import solve_ode_using_shooting
def test_solve_ode_with_trivial_solution():
# Test if the solution solves the given trivial ODE y'' + 3y' + 2y = 0 with y(0) = 1 and y'(0) = 0
t_span = (0, 10)
t_eval = np.linspace(0, 10, 100)
initial_conditions = (1, 0)
sol = solve_o... | [
{
"docstring": "Defines the system of first-order ODEs.\ny[0] = y1\ny[1] = y2",
"function_declaration": "def system(t, y):",
"function_name": "system",
"parameter_list": "(t, y)"
},
{
"docstring": "Solves the ODE system using initial conditions and returns the result.",
"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\nfrom scipy.integrate import solve_ivp\n\ndef shoot(t, Y):\n \"\"\"\n System of first-order differential equations equivalent to the given second-order differential eq... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080173",
"row_id": 80173,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162841']"
} | 0.269622 | Filter_80173 | I | [
"system",
"solve_ode_using_shooting"
] | 2 | [
[
"solve_ode_using_shooting",
"system"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 0cdf77629ee5f5eb0e65330afca8c2eaf4ae85a1 | 100ba280d0679b2cadd9b11e45180d71b3cb4e7c | |||
v1.0 | instruct | Filter | Filter_80228_I | Write a Python function that takes a positive integer \( n \) as input and returns the \( n \)-th prime number. You must use a functional programming approach, utilizing higher-order functions such as `map`, `filter`, and `reduce` from the `functools` module. Additionally, implement a lazy evaluation strategy to effici... | from itertools import count, islice
from functools import reduce
def is_prime(num):
"""
Returns True if the number is a prime number, otherwise False.
"""
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def ... | from solution import nth_prime
def test_nth_prime_6():
assert nth_prime(6) == 13
def test_nth_prime_10():
assert nth_prime(10) == 29
def test_nth_prime_10001():
assert nth_prime(10001) == 104743
def test_nth_prime_1():
assert nth_prime(1) == 2
def test_nth_prime_3():
assert nth_prime(3) == 5 | [
{
"docstring": "Returns True if the number is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the nth prime number using a functional programming approach.",
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import count\nfrom functools import reduce\n\ndef is_prime(num):\n \"\"\"Return True if num is a prime number.\"\"\"\n if num <= 1:\n return False\n if num == 2:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080228",
"row_id": 80228,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162931']"
} | 0.674407 | Filter_80228 | I | [
"is_prime",
"nth_prime"
] | 2 | [
[
"nth_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b102a626eb79d183cc4255059cb3639deee93f24 | bbd4a426cacbc4decdf1c24ae9751d5c026c99ae | |||
v1.0 | instruct | Filter | Filter_80241_I | I am working on a project that requires me to find the minimum value of a function using the Nelder-Mead method in Python. Can you provide me with a code example to help me get started? | from scipy.optimize import minimize
def objective_function(x):
"""
Example objective function to be minimized.
In this case, it is a simple quadratic function f(x) = (x-3)^2 + 4.
"""
return (x - 3)**2 + 4
def find_minimum_nelder_mead():
"""
Finds the minimum value of the objective function... | from solution import objective_function, find_minimum_nelder_mead
def test_objective_function():
assert objective_function(0) == 13 # (0 - 3)^2 + 4 = 9 + 4 = 13
assert objective_function(3) == 4 # (3 - 3)^2 + 4 = 0 + 4 = 4
assert objective_function(-3) == 40 # (-3 - 3)^2 + 4 = 36 + 4 = 40
def test_fin... | [
{
"docstring": "Example objective function to be minimized.\nIn this case, it is a simple quadratic function f(x) = (x-3)^2 + 4.",
"function_declaration": "def objective_function(x):",
"function_name": "objective_function",
"parameter_list": "(x)"
},
{
"docstring": "Finds the minimum value o... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy.optimize import minimize\n\ndef objective_function(x):\n \"\"\"\n Example objective function: f(x) = (x[0] - 1)^2 + (x[1] - 2)^2\n This function has a minimum at x = [1, 2]... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080241",
"row_id": 80241,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162946']"
} | 0.512148 | Filter_80241 | I | [
"objective_function",
"find_minimum_nelder_mead"
] | 2 | [
[
"find_minimum_nelder_mead",
"objective_function"
]
] | 1 | [] | false | [] | false | pytest | true | [
"scipy"
] | false | fd9e2e633da6a0d4a9c4c37a07179dcaf31db15e | a029920d27ad56697d921aa5e8d0d8ba9d9710aa | |||
v1.0 | instruct | Filter | Filter_80272_I | Write a Python function to find the sum of all the prime numbers in a given list of integers. The function should take a list of integers as an argument and return the sum of all the prime numbers in the list. If there are no prime numbers in the list, the function should return 0. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_primes(numbers):
"""... | from solution import sum_of_primes
def test_sum_of_primes_all_primes():
assert sum_of_primes([2, 3, 5, 7, 11]) == 28
def test_sum_of_primes_mixed_numbers():
assert sum_of_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 28
def test_sum_of_primes_no_primes():
assert sum_of_primes([4, 6, 8, 9, 10, 12]) == 0
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list of integers.",
"function_declaration": "def sum_of_primes(numbers):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080272",
"row_id": 80272,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_162994']"
} | 0.64063 | Filter_80272 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6dba8a5a9eaed7c969e68638c26684716d208a02 | 769fdf536a43198c83e33b47dd3aaa97d95497c2 | |||
v1.0 | instruct | Filter | Filter_80280_I | I am working on a project to design a Finite Impulse Response (FIR) filter using a genetic algorithm in Python. The goal is to optimize the filter coefficients to achieve a desired frequency response. Can you provide a basic outline or steps on how to approach this problem? | import random
import numpy as np
from scipy.signal import freqz
def create_initial_population(pop_size, num_coeffs):
"""
Initializes the population with random values.
"""
return [np.random.rand(num_coeffs) for _ in range(pop_size)]
def evaluate_fitness(individual, desired_response, frequencies):
... | from solution import genetic_algorithm, create_initial_population, evaluate_fitness
def test_create_initial_population():
pop_size = 30
num_coeffs = 10
population = create_initial_population(pop_size, num_coeffs)
assert len(population) == pop_size
assert all(len(individual) == num_coeffs for indivi... | [
{
"docstring": "Initializes the population with random values.",
"function_declaration": "def create_initial_population(pop_size, num_coeffs):",
"function_name": "create_initial_population",
"parameter_list": "(pop_size, num_coeffs)"
},
{
"docstring": "Evaluates the fitness of an individual ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.signal import freqz\n\n# FIR filter design using Genetic Algorithm (GA)\n\ndef initialize_population(pop_size, filter_length):\n # Initialize population with ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080280",
"row_id": 80280,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163007']"
} | 0.332886 | Filter_80280 | I | [
"create_initial_population",
"evaluate_fitness",
"select_parents",
"crossover",
"mutate",
"genetic_algorithm"
] | 6 | [
[
"genetic_algorithm",
"create_initial_population"
],
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"evaluate_fitness"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"select_parents"
]
] | 5 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | b9e2f0938a7b6e9b20992c77ef0c5fcc665f969f | 5fa26d46d9a89cb891afee96b03a894b5d473cb2 | |||
v1.0 | instruct | Filter | Filter_80288_I | I am working on a project to compare the performance of two different sorting algorithms: quicksort and mergesort. I need to implement these algorithms in Python and measure their execution times for various input sizes. Can you provide me with Python code for both algorithms and explain how I can measure their executi... | import time
import random
def quicksort(arr):
"""
Implements the Quicksort algorithm.
"""
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quickso... | from solution import quicksort, mergesort, measure_execution_time
import random
def test_quicksort():
unsorted_list = [random.randint(0, 1000) for _ in range(100)]
sorted_list = sorted(unsorted_list)
assert quicksort(unsorted_list) == sorted_list
def test_mergesort():
unsorted_list = [random.randint(0... | [
{
"docstring": "Implements the Quicksort algorithm.",
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(arr)"
},
{
"docstring": "Implements the Mergesort algorithm.",
"function_declaration": "def mergesort(arr):",
"function_name": "merge... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef quicksort(arr):\n \"\"\"\n Implements the quicksort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x fo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080288",
"row_id": 80288,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163019']"
} | 0.43296 | Filter_80288 | I | [
"quicksort",
"mergesort",
"merge",
"measure_execution_time"
] | 4 | [
[
"mergesort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dca58ab0df61c66cbbed1a8d24fa0c75b4e36df8 | eeb157fe80ae8585b0e3d1b3c012d12497482c3a | |||
v1.0 | instruct | Filter | Filter_80292_I | I'm working on a project where I need to evaluate the robustness of a model using adversarial attacks. Specifically, I want to use the Fast Gradient Sign Method (FGSM) in PyTorch. Can you guide me through the process step by step? | import torch
import torch.nn as nn
import torch.optim as optim
def fgsm_attack(image, epsilon, data_grad):
"""
Implements the Fast Gradient Sign Method (FGSM) attack.
:param image: The original input image
:param epsilon: The amount of perturbation
:param data_grad: Gradient of the loss w.r.t ... | import torch
def test_fgsm_attack_clamp():
image = torch.tensor([0.5, 0.5, 0.5, 0.5], requires_grad=True)
epsilon = 0.1
data_grad = torch.tensor([0.1, -0.1, 0.1, -0.1])
perturbed_image = fgsm_attack(image, epsilon, data_grad)
assert torch.all(torch.ge(perturbed_image, 0)), f'Perturbed image ha... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.autograd import Variable\n\ndef fgsm_attack(model, loss_fn, data, target, epsilon):\n \"\"\"\n Executes the F... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080292",
"row_id": 80292,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163026']"
} | 0.313654 | Filter_80292 | I | [
"fgsm_attack",
"generate_adversarial_example"
] | 2 | [
[
"generate_adversarial_example",
"fgsm_attack"
]
] | 1 | [] | false | [
"SimpleModel"
] | true | pytest | false | [
"torch"
] | false | 9d8e2b09d9692b6a1c92b092aafd9e49ecafebaf | 8387c57da34edcf374a12f05e61112e54f7f807f | |||
v1.0 | instruct | Filter | Filter_80325_I | I'm working on a problem where I need to find the largest palindrome made from the product of two 3-digit numbers. I'm using Python to solve this. Can you guide me on how to approach this problem? | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
return str(number) == str(number)[::-1]
def largest_palindrome_product():
"""
Finds the largest palindrome made from the product of two 3-digit numbers.
"""
max_palindrome = 0
for i in range(100, 1000):
... | from solution import is_palindrome, largest_palindrome_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(12321) == True
assert is_palindrome(12345) == False
def test_largest_palindrome_prod... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Finds the largest palindrome made from the product of two 3-digit numbers.",
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef largest_palindrome_product():\n \"\"\"\n Find... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080325",
"row_id": 80325,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163078']"
} | 0.675102 | Filter_80325 | I | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9322c42ae11409ee0eee4335963cf3b5ad8b6def | 67a7100df4e861181fbe73df0b4e9f03980033ee | |||
v1.0 | instruct | Filter | Filter_80357_I | I am working on a project that involves solving a system of differential equations numerically in Python. Can you guide me on how to approach this problem? | from scipy.integrate import solve_ivp
import numpy as np
def system_of_odes(t, z):
x, y = z
dxdt = x - y + t
dydt = x + y - t
return [dxdt, dydt]
def solve_system_of_odes(t_span, initial_conditions):
"""
Solves a system of differential equations numerically.
Args:
t_span (tuple): A tu... | from solution import solve_system_of_odes
def test_solve_system_of_odes():
t_span = (0, 10)
initial_conditions = [1, 0]
solution = solve_system_of_odes(t_span, initial_conditions)
assert solution.status == 0 # Ensures that the solver successfully reached the end of the integration interval.
assert... | [
{
"docstring": null,
"function_declaration": "def system_of_odes(t, z):",
"function_name": "system_of_odes",
"parameter_list": "(t, z)"
},
{
"docstring": "Solves a system of differential equations numerically.\n\nArgs:\nt_span (tuple): A tuple containing the start and end times (t0, tf).\nin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.integrate import odeint\n\ndef system_of_odes(y, t):\n \"\"\"\n Define the system of ODEs.\n \n Parameters:\n y : list or array of dependent varia... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080357",
"row_id": 80357,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163128']"
} | 0.255358 | Filter_80357 | I | [
"system_of_odes",
"solve_system_of_odes"
] | 2 | [
[
"solve_system_of_odes",
"system_of_odes"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 087c8845146514df842afccaed06fcb9bb170983 | c138265612ca2818aee6d0716a5e42302814ed5b | |||
v1.0 | instruct | Filter | Filter_80368_I | I am working on a project that involves solving the heat equation on a 2D grid. Can you provide me with a Python code snippet that uses the finite difference method to solve the heat equation? | import numpy as np
import matplotlib.pyplot as plt
def initialize_grid(nx, ny, init_temp=25.0):
u = np.ones((ny, nx)) * init_temp
return u
def apply_boundary_conditions(u, boundary_value=0.0):
u[0, :] = boundary_value
u[-1, :] = boundary_value
u[:, 0] = boundary_value
u[:, -1] = boundary_value... | def test_initialize_grid():
grid = initialize_grid(10, 10, init_temp=30.0)
assert grid.shape == (10, 10)
assert np.all(grid == 30.0)
def test_apply_boundary_conditions():
grid = np.ones((10, 10)) * 50.0
grid = apply_boundary_conditions(grid, boundary_value=0.0)
assert np.all(grid[0, :] == 0.0)
... | [
{
"docstring": null,
"function_declaration": "def initialize_grid(nx, ny, init_temp=25.0):",
"function_name": "initialize_grid",
"parameter_list": "(nx, ny, init_temp=25.0)"
},
{
"docstring": null,
"function_declaration": "def apply_boundary_conditions(u, boundary_value=0.0):",
"func... | [
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\n\ndef solve_heat_equation(u, dx, dy, alpha, dt, steps):\n \"\"\"\n Solves the heat equation using the finite difference method on a 2D grid.\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080368",
"row_id": 80368,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163145']"
} | 0.427203 | Filter_80368 | I | [
"initialize_grid",
"apply_boundary_conditions",
"solve_heat_equation",
"run_simulation"
] | 4 | [
[
"run_simulation",
"apply_boundary_conditions"
],
[
"run_simulation",
"initialize_grid"
],
[
"run_simulation",
"solve_heat_equation"
]
] | 3 | [] | false | [] | false | pytest | false | [
"matplotlib",
"numpy"
] | false | 4a851e5a75c2cab0a34ca73b6fcf6b0cfbcb1134 | f9976c32133a29c20497fa9599ac0a2ebc9e6759 | |||
v1.0 | instruct | Filter | Filter_80379_I | I am working on a project to implement a genetic algorithm in Python. Could you provide me with some key concepts and a basic example to get started? | import random
def create_individual(length):
"""Create a member of the population - a chromosome."""
return [random.randint(0, 1) for _ in range(length)]
def create_population(size, length):
"""Create initial population of chromosomes."""
return [create_individual(length) for _ in range(size)]
def fi... | from solution import create_individual, create_population, fitness, selection, crossover, mutate, genetic_algorithm
def test_create_individual_length():
length = 10
individual = create_individual(length)
assert len(individual) == length # Check if individual has correct length
def test_create_population_... | [
{
"docstring": "Create a member of the population - a chromosome.",
"function_declaration": "def create_individual(length):",
"function_name": "create_individual",
"parameter_list": "(length)"
},
{
"docstring": "Create initial population of chromosomes.",
"function_declaration": "def cre... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef create_individual(length):\n \"\"\"Create a member of the population - a chromosome.\"\"\"\n return [random.randint(0, 1) for _ in range(length)]\n\ndef create_popul... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080379",
"row_id": 80379,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163160']"
} | 0.345569 | Filter_80379 | I | [
"create_individual",
"create_population",
"fitness",
"selection",
"crossover",
"mutate",
"genetic_algorithm"
] | 7 | [
[
"create_population",
"create_individual"
],
[
"genetic_algorithm",
"create_population"
],
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"selection"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 46fc8e095ca3c2f60b63dd37330322e1c40833f9 | b2f54c97d6627ec810084c7b2f57e72976044e53 | |||
v1.0 | instruct | Filter | Filter_80440_I | Write a Python function to check if a given number is a prime number. Use the function to find all prime numbers between 1 and 100. Print the prime numbers. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def find_primes... | from solution import is_prime, find_primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == F... | [
{
"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 all prime numbers up to the given limit (inclusive).",
"function_declaration": "def fin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if the number 'n' is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080440",
"row_id": 80440,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163246']"
} | 0.771168 | Filter_80440 | I | [
"is_prime",
"find_primes_up_to"
] | 2 | [
[
"find_primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 493b2297af2b8cb588db2c88a9365a4581eca544 | aa05657ace2242536f8bafe69a86ee10374eb7e2 | |||
v1.0 | instruct | Filter | Filter_80445_I | I am trying to solve the differential equation y''(x) + 2y'(x) + y(x) = 0 with initial conditions y(0) = 1 and y'(0) = 0 using the shooting method in Python. I am having trouble implementing the method correctly. Can you guide me through the process? | import numpy as np
from scipy.integrate import solve_ivp
# Define the system of first-order ODEs
def system(t, y):
y1, y2 = y
dy1dt = y2
dy2dt = -2*y2 - y1
return [dy1dt, dy2dt]
# Shooting method to solve the BVP
def solve_bvp_shooting(initial_slope, t_span, y0=[1, 0]):
sol = solve_ivp(system, t_s... | import numpy as np
from solution import solve_differential_equation
def test_initial_conditions():
t, y = solve_differential_equation(0)
assert np.isclose(y[0], 1, atol=1e-2), f"Expected y(0) to be 1, but got {y[0]}"
def test_solution_at_large_t():
t, y = solve_differential_equation(0)
assert np.isclo... | [
{
"docstring": null,
"function_declaration": "def system(t, y):",
"function_name": "system",
"parameter_list": "(t, y)"
},
{
"docstring": null,
"function_declaration": "def solve_bvp_shooting(initial_slope, t_span, y0=[1, 0]):",
"function_name": "solve_bvp_shooting",
"parameter_l... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.integrate import solve_ivp\nfrom scipy.optimize import root\n\ndef odesys(t, y):\n \"\"\"\n Defines the system of first-order ODEs.\n y[0] = y, y[1] = y... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080445",
"row_id": 80445,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163256']"
} | 0.247978 | Filter_80445 | I | [
"system",
"solve_bvp_shooting",
"solve_differential_equation"
] | 3 | [
[
"solve_bvp_shooting",
"system"
],
[
"solve_differential_equation",
"solve_bvp_shooting"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 60d04226c7669ebd7c89100ebc349f5f5c98c054 | 3d025053680f2bb9e0309d253a36399e66ae78b0 | |||
v1.0 | instruct | Filter | Filter_80473_I | Twin primes are pairs of prime numbers that differ by 2. For example, (3, 5) and (11, 13) are twin primes. Given a positive integer \( n \), write a Python function to find all twin primes less than \( n \). If there are no twin primes less than \( n \), return an empty list. Use the provided code skeleton as a startin... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import find_twin_primes
def test_find_twin_primes_no_twin_primes():
assert find_twin_primes(5) == [(3, 5)]
def test_find_twin_primes_with_twin_primes():
result = find_twin_primes(20)
expected = [(3, 5), (5, 7), (11, 13), (17, 19)]
assert result == expected
def test_find_twin_pri... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of twin primes less than n as tuples.",
"function_declaration": "def find_twin_primes(n)... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(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_0 | {
"original_instruction": "",
"prompt_id": "00080473",
"row_id": 80473,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163299']"
} | 0.654605 | Filter_80473 | I | [
"is_prime",
"find_twin_primes"
] | 2 | [
[
"find_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 812ea645df0c8653fc673ed5eae15ae5e78aeaca | ccaa52b61a92c51aaf2ce585e800e8ea3603fbf2 | |||
v1.0 | instruct | Filter | Filter_80477_I | I am working on a project that involves solving a system of equations that can be written in the form \( A \mathbf{x} = \mathbf{b} \), where \( A \) is a symmetric positive definite matrix, \(\mathbf{x}\) is the vector of unknowns, and \(\mathbf{b}\) is the vector of constants. I need to implement the Cholesky decompos... | import numpy as np
def cholesky_decomposition(A):
"""
Perform Cholesky decomposition of a symmetric positive definite matrix A.
Returns the lower triangular matrix L such that A = L L^T.
"""
n = A.shape[0]
L = np.zeros_like(A)
for i in range(n):
for j in range(i + 1):
s... | import numpy as np
from solution import cholesky_decomposition, solve_cholesky
def test_cholesky_decomposition():
A = np.array([[4, 12, -16],
[12, 37, -43],
[-16, -43, 98]], dtype=float)
L = cholesky_decomposition(A)
# Expected lower triangular matrix
L_exp... | [
{
"docstring": "Perform Cholesky decomposition of a symmetric positive definite matrix A.\nReturns the lower triangular matrix L such that A = L L^T.",
"function_declaration": "def cholesky_decomposition(A):",
"function_name": "cholesky_decomposition",
"parameter_list": "(A)"
},
{
"docstring... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef cholesky_decomposition(A):\n \"\"\"\n Perform Cholesky decomposition of a symmetric positive definite matrix A.\n Returns the lower triangular matrix L such ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080477",
"row_id": 80477,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163309']"
} | 0.408694 | Filter_80477 | I | [
"cholesky_decomposition",
"solve_cholesky"
] | 2 | [
[
"solve_cholesky",
"cholesky_decomposition"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | dca488c98ea35f684c17176efe117af21175c9de | bd5d5878375eca72a0db52800c90f634f0c64458 | |||
v1.0 | instruct | Filter | Filter_80530_I | How can I write a Python function to determine if a number is prime, and then use this function to find all prime numbers between 1 and 2000? Additionally, how can I measure the time it takes to find these prime numbers? Finally, how can I modify the function to use parallel processing and compare the time it takes wit... | import time
from multiprocessing import Pool
def is_prime(n):
"""
Determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
... | from solution import is_prime, find_primes_in_range, measure_time_to_find_primes, find_primes_in_range_parallel, measure_time_to_find_primes_parallel
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers in the given range.",
"function_declaration": "def find_primes_in_range(start, end):",
"functio... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nimport time\nfrom multiprocessing import Pool\n\ndef is_prime(n):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080530",
"row_id": 80530,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163397']"
} | 0.656854 | Filter_80530 | I | [
"is_prime",
"find_primes_in_range",
"measure_time_to_find_primes",
"find_primes_in_range_parallel",
"find_primes_in_range_wrapper",
"measure_time_to_find_primes_parallel"
] | 6 | [
[
"find_primes_in_range",
"is_prime"
],
[
"find_primes_in_range_parallel",
"find_primes_in_range_wrapper"
],
[
"find_primes_in_range_wrapper",
"find_primes_in_range"
],
[
"measure_time_to_find_primes",
"find_primes_in_range"
],
[
"measure_time_to_find_primes_paral... | 5 | [] | false | [] | false | pytest | true | [] | true | f7a84431062a0179bf1385ab58b74e2f53d2fc47 | fd05b7aae53c4c1e155114f094d9f80e95d48188 | |||
v1.0 | instruct | Filter | Filter_80550_I | Is it possible to implement a genetic algorithm using only Python's built-in data structures and without using any additional libraries or frameworks? If so, could you provide a basic example or outline the steps involved? | import random
# Parameters
pop_size = 10
chromosome_length = 5
max_generations = 100
mutation_rate = 0.1
target_chromosome = [1, 2, 3, 4, 5]
# Fitness function
def fitness(chromosome):
return sum(1 for gene, target in zip(chromosome, target_chromosome) if gene == target)
# Initialize population
def initialize_po... | def test_fitness():
assert fitness([1, 2, 3, 4, 5]) == 5
assert fitness([1, 2, 2, 4, 5]) == 4
assert fitness([0, 2, 3, 4, 5]) == 4
def test_initialize_population():
population = initialize_population()
assert len(population) == pop_size
assert all(len(chromosome) == chromosome_length for chromo... | [
{
"docstring": null,
"function_declaration": "def fitness(chromosome):",
"function_name": "fitness",
"parameter_list": "(chromosome)"
},
{
"docstring": null,
"function_declaration": "def initialize_population():",
"function_name": "initialize_population",
"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\n# Parameters\npop_size = 10\nchromosome_length = 5\nmax_generations = 100\nmutation_rate = 0.1\ntarget_chromosome = [1, 2, 3, 4, 5]\n\n# Fitness function\ndef fitness(chromoso... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080550",
"row_id": 80550,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163429']"
} | 0.283017 | Filter_80550 | I | [
"fitness",
"initialize_population",
"select_parents",
"crossover",
"mutate",
"genetic_algorithm"
] | 6 | [
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"fitness"
],
[
"genetic_algorithm",
"initialize_population"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"select_parents"
]
] | 5 | [] | false | [] | false | pytest | false | [] | true | 5f686dbb8b19ef76637ca6a2a4ad952fe1c439fd | 57dc780cb78574f6f4919d54ee26de049ba3a24d | |||
v1.0 | instruct | Filter | Filter_80580_I | Write a Python program to find the next prime number after a given number. For example, the next prime number after 10 is 11. The next prime number after 23 is 29. Use a function to check if a number is prime. Use another function to find the next prime number after a given number. Use the main function to take input f... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, next_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(97) == True
assert is_prime(99) == False
def test_next_prime():
assert next_prime(10) == 11
asser... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next prime number after n.",
"function_declaration": "def next_prime(n):",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return Fals... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080580",
"row_id": 80580,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163467']"
} | 0.670689 | Filter_80580 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b940a07aadb29a77f7702f8beb2fe8fc102a4176 | 4e2ae4e5273f8429dcda59567ab2a086502373da | |||
v1.0 | instruct | Filter | Filter_80584_I | I am working on a project that involves solving the Traveling Salesman Problem (TSP) using the Ant Colony Optimization (ACO) algorithm in Python. I need to understand how to implement the ACO algorithm to find the shortest path that visits each city exactly once and returns to the origin city. Can you provide a detaile... | import numpy as np
def initialize_pheromone_matrix(num_cities):
return np.ones((num_cities, num_cities))
def initialize_distance_matrix(coordinates):
num_cities = len(coordinates)
distance_matrix = np.zeros((num_cities, num_cities))
for i in range(num_cities):
for j in range(num_cities):
... | from solution import (
initialize_pheromone_matrix,
initialize_distance_matrix,
choose_next_city,
construct_solution,
update_pheromone_matrix,
compute_tour_length,
aco_tsp
)
def test_pheromone_matrix_initialization():
num_cities = 5
pheromone_matrix = initialize_pheromone_matr... | [
{
"docstring": null,
"function_declaration": "def initialize_pheromone_matrix(num_cities):",
"function_name": "initialize_pheromone_matrix",
"parameter_list": "(num_cities)"
},
{
"docstring": null,
"function_declaration": "def initialize_distance_matrix(coordinates):",
"function_name... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef initialize_pheromone_matrix(num_cities):\n return np.ones((num_cities, num_cities))\n\ndef initialize_distance_matrix(coordinates):\n num_cities = len(coordinat... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080584",
"row_id": 80584,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163473']"
} | 0.414935 | Filter_80584 | I | [
"initialize_pheromone_matrix",
"initialize_distance_matrix",
"choose_next_city",
"construct_solution",
"update_pheromone_matrix",
"compute_tour_length",
"aco_tsp"
] | 7 | [
[
"aco_tsp",
"compute_tour_length"
],
[
"aco_tsp",
"construct_solution"
],
[
"aco_tsp",
"initialize_distance_matrix"
],
[
"aco_tsp",
"initialize_pheromone_matrix"
],
[
"aco_tsp",
"update_pheromone_matrix"
],
[
"construct_solution",
"choose_next_cit... | 7 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 76076a5f6da06ee6f418c878be621d2bd3e8972d | d37416089cfd91c980380dfb2f8e54b81eb6baeb | |||
v1.0 | instruct | Filter | Filter_80618_I | Write a Python program that asks the user to enter a word and then checks if the word is a palindrome. A palindrome is a word that reads the same forwards and backwards, like "racecar" or "madam". The program should print "The word is a palindrome" if the word is a palindrome, and "The word is not a palindrome" otherwi... | def is_palindrome(word):
"""
Check if the given word is a palindrome. Ignore case and non-alphanumeric characters.
:param word: str, the word to check
:return: bool, True if the word is a palindrome, False otherwise
"""
cleaned_word = ''.join(char.lower() for char in word if char.isalnum())... | from solution import is_palindrome, check_word
# Tests for is_palindrome
def test_is_palindrome_simple_cases():
assert is_palindrome("racecar") == True
assert is_palindrome("madam") == True
assert is_palindrome("hello") == False
def test_is_palindrome_case_insensitive():
assert is_palindrome("RaceCar"... | [
{
"docstring": "Check if the given word is a palindrome. Ignore case and non-alphanumeric characters.\n\n:param word: str, the word to check\n:return: bool, True if the word is a palindrome, False otherwise",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"para... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(word):\n \"\"\"\n Takes a word and returns True if the word is a palindrome, ignoring case and non-alphanumeric characters.\n Otherwise, returns False.\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080618",
"row_id": 80618,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163532']"
} | 0.780451 | Filter_80618 | I | [
"is_palindrome",
"check_word"
] | 2 | [
[
"check_word",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ffe9e370174e4af299a17e3c275968cfabd76c9 | d74467b2572273aba1ca8f2c6b9dd0f74ecc8af3 | |||
v1.0 | instruct | Filter | Filter_80625_I | I am working on a project where I need to use the K-Nearest Neighbors (KNN) algorithm to classify data points. I understand the basic concept of KNN, but I'm having trouble implementing it in Python. Can you guide me through the process? | import numpy as np
from collections import Counter
def euclidean_distance(point1, point2):
"""
Returns the Euclidean distance between two points.
"""
return np.sqrt(np.sum((np.array(point1) - np.array(point2)) ** 2))
def knn_classify(training_data, training_labels, test_point, k):
"""
Classifi... | from solution import euclidean_distance, knn_classify
def test_euclidean_distance():
assert euclidean_distance([0, 0], [3, 4]) == 5.0
assert euclidean_distance([1, 1], [4, 5]) == 5.0
assert np.isclose(euclidean_distance([2, 3], [6, 9]), 7.2111, atol=0.0001)
def test_knn_classify():
training_data = [
... | [
{
"docstring": "Returns the Euclidean distance between two points.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Classifies a test point based on the k-nearest neighbors algo... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom collections import Counter\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Returns the Euclidean distance between two points.\n \"\"\"\n return np.sq... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080625",
"row_id": 80625,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163546']"
} | 0.57846 | Filter_80625 | I | [
"euclidean_distance",
"knn_classify"
] | 2 | [
[
"knn_classify",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 6fc6a56fba0806305fd8ae72f9ef098347ec600d | 6620558bfb629d51fd9e0c08c922b4f51448ce1d | |||
v1.0 | instruct | Filter | Filter_80675_I | Given a set of 2D points, I need to find the point that is closest to a given point using the Euclidean distance. Can you provide a Python code snippet that accomplish this task? Also, could you explain the time complexity of your solution? | import math
def euclidean_distance(point1, point2):
"""
Calculate the Euclidean distance between two 2D points.
"""
return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
def closest_point(points, reference_point):
"""
Find the point in the set 'points' that is closest to 'r... | from solution import euclidean_distance, closest_point
def test_euclidean_distance():
assert math.isclose(euclidean_distance((0, 0), (3, 4)), 5.0)
assert math.isclose(euclidean_distance((1, 1), (4, 5)), 5.0)
assert math.isclose(euclidean_distance((10, 10), (10, 10)), 0.0)
def test_closest_point():
poi... | [
{
"docstring": "Calculate the Euclidean distance between two 2D points.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Find the point in the set 'points' that is closest to 'r... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculates the Euclidean distance between two 2D points.\n \"\"\"\n return math.sqrt((point1[0] - point2[0]) ** 2 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080675",
"row_id": 80675,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163625']"
} | 0.577846 | Filter_80675 | I | [
"euclidean_distance",
"closest_point"
] | 2 | [
[
"closest_point",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65c54f02953cc13ee4fbebe928f79749af13ae42 | 83d0fc44c3e544b4deb561d5442b160cc2f40346 | |||
v1.0 | instruct | Filter | Filter_80706_I | I am working on a project to simulate the behavior of a simple pendulum using Python. I need to solve the differential equation for the pendulum's motion and then plot the results. Can you guide me on how to do this? | import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
def pendulum_derivatives(t, y, L, g):
"""
Computes the derivatives for a simple pendulum.
Params:
t (float) - current time
y (list) - current values of theta and omega [theta, omega]
L (float) - length... | import numpy as np
from solution import pendulum_derivatives, simulate_pendulum
def test_pendulum_derivatives():
L = 1.0
g = 9.81
y = [np.pi / 4, 0.0] # theta = 45 degrees, omega = 0
t = 0
dtheta_dt, domega_dt = pendulum_derivatives(t, y, L, g)
expected_dtheta_dt = 0.0 # omega is initial... | [
{
"docstring": "Computes the derivatives for a simple pendulum.\n\nParams:\nt (float) - current time\ny (list) - current values of theta and omega [theta, omega]\nL (float) - length of the pendulum\ng (float) - acceleration due to gravity\n\nReturns:\ndydt (list) - derivatives [d(theta)/dt, d(omega)/dt]",
"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.integrate import solve_ivp\nimport matplotlib.pyplot as plt\n\ndef simple_pendulum(t, y, length, g):\n \"\"\"\n Differential equation for a simple pendulum... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080706",
"row_id": 80706,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163677']"
} | 0.324544 | Filter_80706 | I | [
"pendulum_derivatives",
"simulate_pendulum",
"plot_pendulum_motion"
] | 3 | [
[
"simulate_pendulum",
"pendulum_derivatives"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"scipy"
] | false | 0acabd616dbcdcf3143045ee7987665c2f5aba89 | 832f424e06b15bf0b428e8e5e50806f02bc506bb | |||
v1.0 | instruct | Filter | Filter_80742_I | I want to write a Python program that asks the user to enter a number and then prints out all the prime numbers up to that number. How can I do this? | def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes_up_to(num):
"""
Returns a list of all prime numbers up to the given number (inclusive).
"""
return [i for i in range(2, num + 1) if is_... | from solution import is_prime, primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
def test_primes_up_to():
assert primes_up_to(10) == [2, 3, 5, 7]
assert primes_up_to(20) == [2, 3, 5, 7, 11, 13, 17, 19... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers up to the given number (inclusive).",
"function_declaration": "def primes_up_to(num):",
"function_name": "prime... | [
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 if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef primes_up_to(num):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00080742",
"row_id": 80742,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163729']"
} | 0.663979 | Filter_80742 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9f0ed37a4bc11e7053b6b4a049fccc2b595e1f90 | 5ca84934fbfc780a014f08de57afe7076a974467 | |||
v1.0 | instruct | Filter | Filter_80744_I | In the context of a specific programming problem, what is the expected behavior of the function `sum`, and how should it interact with the function `num`? Specifically, if `num` is a function that returns the next number in a sequence, how does `sum` use `num` to calculate the sum of the first `n` numbers in the sequen... | def num(index):
"""
Returns the next number in a sequence.
For simplicity, let's assume it returns the index, i.e., numbers in an arithmetic sequence starting from 1.
"""
return index
def sum(n):
"""
Returns the sum of the first n numbers in the sequence generated by the num function.
"... | from solution import num, sum
def test_num():
assert num(1) == 1
assert num(2) == 2
assert num(3) == 3
assert num(10) == 10
def test_sum():
assert sum(1) == 1
assert sum(2) == 3 # 1 + 2
assert sum(3) == 6 # 1 + 2 + 3
assert sum(4) == 10 # 1 + 2 + 3 + 4
assert sum(5) == 15 # 1 + 2... | [
{
"docstring": "Returns the next number in a sequence.\nFor simplicity, let's assume it returns the index, i.e., numbers in an arithmetic sequence starting from 1.",
"function_declaration": "def num(index):",
"function_name": "num",
"parameter_list": "(index)"
},
{
"docstring": "Returns the ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num(n):\n \"\"\"\n Returns the n-th number in a sequence. \n For simplicity, this function will generate natural numbers starting from 1.\n \"\"\"\n return n\n\ndef sum(n):\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080744",
"row_id": 80744,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163733']"
} | 0.562108 | Filter_80744 | I | [
"num",
"sum"
] | 2 | [
[
"sum",
"num"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2ec74e6e7bcd1edd1fe422892f2665f5e4f5adc8 | d7efa27693ee574cbcfe4d525cb7ad3ef9d3f862 | |||
v1.0 | instruct | Filter | Filter_80769_I | I am a computer science student and I have a project about data compression. I want to implement Huffman coding in Python. Can you help me with that? | import heapq
from collections import defaultdict, Counter
class HuffmanNode:
def __init__(self, char, freq):
self.char = char
self.freq = freq
self.left = None
self.right = None
def __lt__(self, other):
return self.freq < other.freq
def build_frequency_dict(text):
... | from solution import (build_frequency_dict, build_huffman_tree, generate_huffman_codes,
encode_text, decode_text, huffman_encoding, huffman_decoding)
def test_build_frequency_dict():
text = "hello"
expected = {'h': 1, 'e': 1, 'l': 2, 'o': 1}
assert build_frequency_dict(text) == expec... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict, Counter\n\nclass Node:\n def __init__(self, char, freq):\n self.char = char\n self.freq = freq\n self.left = None\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080769",
"row_id": 80769,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163783']"
} | 0.46924 | Filter_80769 | I | [
"build_frequency_dict",
"build_huffman_tree",
"generate_huffman_codes",
"encode_text",
"decode_text",
"huffman_encoding",
"huffman_decoding"
] | 7 | [
[
"huffman_decoding",
"decode_text"
],
[
"huffman_encoding",
"build_frequency_dict"
],
[
"huffman_encoding",
"build_huffman_tree"
],
[
"huffman_encoding",
"encode_text"
],
[
"huffman_encoding",
"generate_huffman_codes"
]
] | 5 | [] | false | [
"HuffmanNode"
] | true | pytest | true | [] | true | eb80608ec95c1008ec82c1062076ad816f461e82 | 633ee1df59036521a9fc0d42de9f6854c8babb45 | |||
v1.0 | instruct | Filter | Filter_80771_I | I am working on a project that involves using the BFGS optimization algorithm in Python. I want to use the `scipy.optimize` module, but I am having trouble understanding how to use the `fmin_bfgs` function. Can you provide a simple example of how to use this function to minimize a function? | from scipy.optimize import fmin_bfgs
def quadratic_function(x):
"""
Simple quadratic function f(x) = (x - 3)^2
"""
return (x - 3) ** 2
def minimize_quadratic_function():
"""
Uses the BFGS algorithm to minimize the quadratic function.
"""
initial_guess = 0
result = fmin_bfgs(quadrat... | from solution import quadratic_function, minimize_quadratic_function
def test_quadratic_function():
# Test some known values of the quadratic function
assert quadratic_function(0) == 9
assert quadratic_function(3) == 0
assert quadratic_function(-1) == 16
def test_minimize_quadratic_function():
res... | [
{
"docstring": "Simple quadratic function f(x) = (x - 3)^2",
"function_declaration": "def quadratic_function(x):",
"function_name": "quadratic_function",
"parameter_list": "(x)"
},
{
"docstring": "Uses the BFGS algorithm to minimize the quadratic function.",
"function_declaration": "def ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy.optimize import fmin_bfgs\nimport numpy as np\n\ndef func_to_minimize(x):\n \"\"\"\n A simple quadratic function to minimize.\n Let's take f(x) = (x-3)**2 + 2 for this exam... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00080771",
"row_id": 80771,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163787']"
} | 0.406001 | Filter_80771 | I | [
"quadratic_function",
"minimize_quadratic_function"
] | 2 | [
[
"minimize_quadratic_function",
"quadratic_function"
]
] | 1 | [] | false | [] | false | pytest | true | [
"scipy"
] | false | 512f4a02190575506cc46be0d8e71e588ae347cf | a7da976c54804e17cb2423ac9e029590634672ee | |||
v1.0 | instruct | Filter | Filter_80797_I | In the context of a specific programming language, what is the `NextPrime` function and how does it work? Specifically, how does it handle negative numbers and what happens if the function is given a prime number as input? | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import next_prime
def test_next_prime_small_numbers():
assert next_prime(0) == 2
assert next_prime(1) == 2
def test_next_prime_primes():
assert next_prime(2) == 3
assert next_prime(3) == 5
assert next_prime(11) == 13
def test_next_prime_non_primes():
assert next_prime(4) == 5
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next prime number greater than the given num.\nIf num is prime, it will return the next prime numbe... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n 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_0 | {
"original_instruction": "",
"prompt_id": "00080797",
"row_id": 80797,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163836']"
} | 0.509999 | Filter_80797 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf1c2c6dd97118e37a8166656199efa121bc6fd9 | 017809233e2ae89417b61c0298b100b4fab0e372 | |||
v1.0 | instruct | Filter | Filter_80817_I | I want to create a website where people can input a number and get the factorial of that number. How can I do this using Python and a web framework like Flask? | from flask import Flask, request, jsonify
app = Flask(__name__)
def factorial(n):
"""
Returns the factorial of a non-negative integer n.
If n is 0, the factorial is defined as 1.
"""
if n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
... | import pytest
from solution import app, factorial
def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
@pytest.fixture
def client():
with app.test_client() as client:
... | [
{
"docstring": "Returns the factorial of a non-negative integer n.\nIf n is 0, the factorial is defined as 1.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "A route that takes a JSON payload with a 'number' and returns ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\ndef factorial(n):\n \"\"\"\n Returns the factorial of a non-negative integer n.\n \"\"\"\n if n == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00080817",
"row_id": 80817,
"seed_ids": "['Qwen2.5-Math-72B-Instruct_163867']"
} | 0.540575 | Filter_80817 | I | [
"factorial",
"factorial_route"
] | 2 | [
[
"factorial_route",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 21dd184dce0b88106cff318903319d8f53547b93 | 21e639770d844db35c53519fbbb8391397878f96 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.