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_28794_I | Using the given code, create a function "calculate_area" which will take two integer parameters and calculate the area of a rectangle. The length and width parameters should be positive integers and the function should return the area as a floating-point number. Additionally, the function should validate that the lengt... | class NonPrimeNumberError(Exception):
"""Exception raised for non-prime numbers."""
def __init__(self, value):
message = f"The number {value} is not a prime number."
self.value = value
self.message = message
super().__init__(self.message)
def is_prime(n):
"""Helper function ... | import pytest
from solution import calculate_area, NonPrimeNumberError, is_prime
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(19) == True
assert is_prime(1) == ... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class NonPrimeNumberError(Exception):\n def __init__(self, message):\n super().__init__(message)\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028794",
"row_id": 28794,
"seed_ids": "['Qwen2-72B-Instruct_68371']"
} | 0.676824 | Filter_28794 | I | [
"is_prime",
"calculate_area"
] | 2 | [
[
"calculate_area",
"is_prime"
]
] | 1 | [] | false | [
"NonPrimeNumberError"
] | true | pytest | true | [] | true | 63c20c11269be1a9f727a01d80a7b41f2f06168c | 48d5ec918d3e27432ec8494273b11579ef22f7ad | |||
v1.0 | instruct | Filter | Filter_28800_I | Write a program in Python to find the sum of all prime numbers between 1 to n, where n is a number entered by the user. The program should also display the number of prime numbers found in the range. | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
max_divisor = int(num ** 0.5) + 1
for d in range(3, max_divisor, 2):
if num % d == 0:
return False
... | from solution import is_prime, sum_and_count_primes
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(15) == False
def test_sum_and_count_primes():
assert sum_and_co... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find the sum of all prime numbers between 1 and n and their count.",
"function_declaration": "def sum_and_count_p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028800",
"row_id": 28800,
"seed_ids": "['Qwen2-72B-Instruct_68381']"
} | 0.656384 | Filter_28800 | I | [
"is_prime",
"sum_and_count_primes"
] | 2 | [
[
"sum_and_count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 044e33173ecc0b36d8cd1b95b8493c4660382077 | 79f8b2683749ce54b43bc853580ff8fae1dbc157 | |||
v1.0 | instruct | Filter | Filter_28802_I | To find unique palindromic substrings in a given string, we will use a brute force approach with three nested loops. The outer loop will iterate through each character in the string. The middle loop will iterate through each character after the current character in the outer loop. The innermost loop will check if the s... | def is_palindrome(string):
"""
Checks if a given string is a palindrome.
"""
return string == string[::-1]
def unique_palindromic_substrings(s):
"""
Returns a set of unique palindromic substrings from the input string.
"""
palindromic_subs = set()
n = len(s)
for i in range(n):
... | from solution import unique_palindromic_substrings, is_palindrome
def test_is_palindrome():
assert is_palindrome("racecar")
assert is_palindrome("madam")
assert is_palindrome("a")
assert not is_palindrome("hello")
assert not is_palindrome("world")
def test_unique_palindromic_substrings_empty():
... | [
{
"docstring": "Checks if a given string is a palindrome.",
"function_declaration": "def is_palindrome(string):",
"function_name": "is_palindrome",
"parameter_list": "(string)"
},
{
"docstring": "Returns a set of unique palindromic substrings from the input string.",
"function_declaratio... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(string):\n \"\"\"\n Checks if a given string is a palindrome.\n \"\"\"\n return string == string[::-1]\n\ndef unique_palindromic_substrings(s):\n \"\"\"\n R... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028802",
"row_id": 28802,
"seed_ids": "['Qwen2-72B-Instruct_68384']"
} | 0.75116 | Filter_28802 | I | [
"is_palindrome",
"unique_palindromic_substrings"
] | 2 | [
[
"unique_palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48cf0cd09c8145edc16b0e8661ed05a9479069fb | 366bde3b0c3e11b049d5cfbfd4df7041f6136acd | |||
v1.0 | instruct | Filter | Filter_28808_I | Write a code to check if the content of two strings is the same, but ignore any leading or trailing white spaces and any punctuation marks. The code should also handle cases where the strings contain special characters. | import string
def clean_string(s):
"""
Helper function to remove leading/trailing whitespaces and punctuations from the string.
"""
return s.strip().translate(str.maketrans('', '', string.punctuation + string.whitespace))
def strings_are_equal(s1, s2):
"""
Checks if the content of two strings ... | from solution import strings_are_equal
def test_strings_exactly_equal():
assert strings_are_equal("Hello, World!", "Hello, World!")
def test_strings_with_leading_trailing_whitespace():
assert strings_are_equal(" Hello, World! ", "Hello, World!")
def test_strings_with_punctuation():
assert strings... | [
{
"docstring": "Helper function to remove leading/trailing whitespaces and punctuations from the string.",
"function_declaration": "def clean_string(s):",
"function_name": "clean_string",
"parameter_list": "(s)"
},
{
"docstring": "Checks if the content of two strings is the same, ignoring le... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import string\n\ndef are_strings_equal(str1, str2):\n \"\"\"\n Checks if the content of two strings is the same, ignoring leading/trailing spaces and punctuation marks.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028808",
"row_id": 28808,
"seed_ids": "['Qwen2-72B-Instruct_68400']"
} | 0.649953 | Filter_28808 | I | [
"clean_string",
"strings_are_equal"
] | 2 | [
[
"strings_are_equal",
"clean_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a33768a398c330c8f7791057754bc515b06155c | 06232952f87dac0dca1a16f233f061e0463c798c | |||
v1.0 | instruct | Filter | Filter_28824_I | Write a method in Python that takes an integer value, checks if it's a prime number and returns the result as a Boolean. If the number is not prime, find the largest prime factor of this number and return it instead. Please also take into account the execution time of your function for large integers. | from math import isqrt
def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
... | import pytest
from solution import is_prime, check_prime_or_largest_prime_factor, largest_prime_factor
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
assert is_prime(13) == True
def test_is_prime_... | [
{
"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 the largest prime factor of n.",
"function_declaration": "def largest_prime_factor(n):",
"fun... | [
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 is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n whi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028824",
"row_id": 28824,
"seed_ids": "['Qwen2-72B-Instruct_68426']"
} | 0.807223 | Filter_28824 | I | [
"is_prime",
"largest_prime_factor",
"check_prime_or_largest_prime_factor"
] | 3 | [
[
"check_prime_or_largest_prime_factor",
"is_prime"
],
[
"check_prime_or_largest_prime_factor",
"largest_prime_factor"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e335dd0b2df970e46e584e360bee78bf85d2c7d4 | 9ab493b20188827dc6d3463b44496d2ed516ce31 | |||
v1.0 | instruct | Filter | Filter_28847_I | Create a python function to find the prime numbers between two given numbers. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import find_primes
def test_no_primes():
assert find_primes(0, 1) == []
assert find_primes(14, 16) == []
def test_single_prime():
assert find_primes(2, 2) == [2]
assert find_primes(29, 29) == [29]
def test_multiple_primes():
assert find_primes(10, 20) == [11, 13, 17, 19]
assert ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers between start and end (inclusive).",
"function_declaration": "def find_primes(start, end):",
... | [
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 \"\"\" Helper function to check if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0 or n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028847",
"row_id": 28847,
"seed_ids": "['Qwen2-72B-Instruct_68465']"
} | 0.732983 | Filter_28847 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 476bb4f650673437769aecb9a202d5d3ad6245a6 | e387971226f85d492abe6a4255e57c7c6c3bc7fc | |||
v1.0 | instruct | Filter | Filter_28868_I | Create a program that not only fetches and prints the first 50 prime numbers, but also computes and prints their corresponding Fibonacci sequences. Make sure your solution doesn't lose performance efficiency for large inputs. | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def first_n_primes(n):
"""
Returns the first n prime numbers.
"""
primes = []
... | from solution import is_prime, first_n_primes, fibonacci_sequence, primes_and_fibonacci
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
def test_first_n_primes():
assert first_n_prime... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_name": "firs... | [
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 == 2:\n return True\n if n % 2 == 0:\n return False\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028868",
"row_id": 28868,
"seed_ids": "['Qwen2-72B-Instruct_68503']"
} | 0.611136 | Filter_28868 | I | [
"is_prime",
"first_n_primes",
"fibonacci_sequence",
"primes_and_fibonacci"
] | 4 | [
[
"first_n_primes",
"is_prime"
],
[
"primes_and_fibonacci",
"fibonacci_sequence"
],
[
"primes_and_fibonacci",
"first_n_primes"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5a1cd98ae9f646e868e69020296b3d6b4f5df4d9 | 54113606dc0f1b46e1548f6c5315c62324ed727a | |||
v1.0 | instruct | Filter | Filter_28870_I | Write a recursive function to output "Thank you" for the first n prime numbers, where n is a positive integer. Additionally, implement the function in such a way that it does not use any global or static variables. | def is_prime(num):
"""
Check if a number is a prime number.
"""
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
... | from solution import is_prime, thank_you_primes
import pytest
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(13) == True
assert is_prime(25) == False
def test_output(capsys):
thank_you_primes... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Recursively outputs \"Thank you\" for the first n prime numbers.\n:param n: The number of prime numbers to process\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 Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n i... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028870",
"row_id": 28870,
"seed_ids": "['Qwen2-72B-Instruct_68506']"
} | 0.61353 | Filter_28870 | I | [
"is_prime",
"thank_you_primes"
] | 2 | [
[
"thank_you_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0b91116c3b90b20a8b0dba502fef3de22715097 | 614918d7aaeb20d72a59d582ecdf0a25c25a31fe | |||
v1.0 | instruct | Filter | Filter_28887_I | How can I modify the PyTorch implementation of a Fully-Connected Neural Network (FCNN) to predict a single continuous value for the YOLO bounding box regression task and incorporate the Intersection over Union (IoU) loss function to train the model. Specifically, I want the model to not only predict the center coordina... | import torch
import torch.nn as nn
import torch.nn.functional as F
class FCNN(nn.Module):
def __init__(self, input_dim):
super(FCNN, self).__init__()
self.fc1 = nn.Linear(input_dim, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64, 5) # (x_center, y_center, width, height,... | import torch
from solution import FCNN, iou_loss, combined_loss
def test_iou_loss():
pred = torch.tensor([[0.5, 0.5, 1.0, 1.0], [0.7, 0.7, 0.6, 0.6]])
target = torch.tensor([[0.5, 0.5, 1.0, 1.0], [0.6, 0.6, 0.8, 0.8]])
loss = iou_loss(pred, target)
assert loss.item() >= 0 and loss.item() <= 1, "IoU los... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass FCNN(nn.Module):\n def __init__(self, input_dim):\n super(FCNN, self).__init__()\n self.fc1 = nn.... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028887",
"row_id": 28887,
"seed_ids": "['Qwen2-72B-Instruct_68534']"
} | 0.329921 | Filter_28887 | I | [
"iou_loss",
"combined_loss"
] | 2 | [
[
"combined_loss",
"iou_loss"
]
] | 1 | [] | false | [
"FCNN"
] | true | pytest | true | [
"torch"
] | false | 774f22ee0b6448ba4fd9165c1b8cad6c62314b59 | 10190be7771d45312d9c6f5f914346842d7a0c89 | |||
v1.0 | instruct | Filter | Filter_28913_I | Write a Python program that implements the birthday attack on an ideal hash function using a hash table data structure. | import hashlib
import random
import string
def generate_random_string(length=10):
"""
Generates a random string of given length.
"""
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(length))
def hash_function(input_string):
"""
Returns the hash of the i... | from solution import generate_random_string, hash_function, birthday_attack
def test_generate_random_string_length():
assert len(generate_random_string(10)) == 10
assert len(generate_random_string(15)) == 15
def test_generate_random_string_content():
random_string = generate_random_string(10)
assert r... | [
{
"docstring": "Generates a random string of given length.",
"function_declaration": "def generate_random_string(length=10):",
"function_name": "generate_random_string",
"parameter_list": "(length=10)"
},
{
"docstring": "Returns the hash of the input string using SHA-256.",
"function_dec... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\nimport random\nimport string\n\ndef random_string(length=8):\n \"\"\"\n Generate a random string of fixed length\n \"\"\"\n letters = string.ascii_letters + string.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028913",
"row_id": 28913,
"seed_ids": "['Qwen2-72B-Instruct_68569']"
} | 0.498643 | Filter_28913 | I | [
"generate_random_string",
"hash_function",
"birthday_attack"
] | 3 | [
[
"birthday_attack",
"generate_random_string"
],
[
"birthday_attack",
"hash_function"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e249aca742101e96bd0ee22191c05d87a5d45176 | 6c04dfd4b472f0113694c8d451ef229f44eff73f | |||
v1.0 | instruct | Filter | Filter_28926_I | Modify the following code to implement a function called "findSmallestPrime" that takes in an array of integers as a parameter and returns the smallest prime number in the array. The function should also remove any duplicates from the array before searching for the smallest prime number. If no prime number is found, th... | def is_prime(n, i=2):
"""
Helper function to determine if a number is prime.
Uses recursion to check divisibility.
"""
if n <= 1:
return False
if i * i > n:
return True
if n % i == 0:
return False
return is_prime(n, i + 1)
def findSmallestPrime(arr):
"""
... | def test_findSmallestPrime():
# Test with mixed array containing primes and non-primes
assert findSmallestPrime([10, 7, 11, 3, 4, 2, 5, 3]) == 2
# Test with array containing only one prime number
assert findSmallestPrime([20, 3, 18, 15]) == 3
# Test with array containing only non-prime numbers... | [
{
"docstring": "Helper function to determine if a number is prime.\nUses recursion to check divisibility.",
"function_declaration": "def is_prime(n, i=2):",
"function_name": "is_prime",
"parameter_list": "(n, i=2)"
},
{
"docstring": "Returns the smallest prime number in the array.\nRemoves d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def findSmallestPrime(arr):\n \"\"\"\n Returns the smallest prime number in the array after removing duplicates.\n If no prime number is found, returns -1.\n This is implemented us... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028926",
"row_id": 28926,
"seed_ids": "['Qwen2-72B-Instruct_68586']"
} | 0.584561 | Filter_28926 | I | [
"is_prime",
"findSmallestPrime"
] | 2 | [
[
"findSmallestPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9a4fd1a865cf66717a59a0321797e49921449c8a | 47245d5e8f89069ce06131e2b85c0013a826732b | |||
v1.0 | instruct | Filter | Filter_28941_I | Modify a given code implementing list comprehension that generates a list of prime numbers from a given list of numbers. Additionally, introduce error handling for non-integer types and negative numbers. Also incorporate functionality to filter out unique prime numbers if the given list has duplicate values. | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def filter_unique_primes(lst):
"""
Filter out unique prime numbers from the given list.
Also... | from solution import is_prime, filter_unique_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(-5) == False
def test_filter_unique_primes_with_mix_types():
ass... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Filter out unique prime numbers from the given list.\nAlso handles non-integer and negative numbers.\n\nArgs:\nlst: list of nu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028941",
"row_id": 28941,
"seed_ids": "['Qwen2-72B-Instruct_68610']"
} | 0.604575 | Filter_28941 | I | [
"is_prime",
"filter_unique_primes"
] | 2 | [
[
"filter_unique_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ee59feebe67111addde4965e9b42162f91c200e | 7ed5a76cdc91b606bcf5b32fba97e394581a2d02 | |||
v1.0 | instruct | Filter | Filter_28951_I | Build a program to calculate the shortest path between two points in a 3D space, avoiding obstacles represented by a set of 3D polygons. The program should take as input the coordinates of the start and end points, as well as the vertices of the polygons, and output the shortest path as a list of 3D points. | import heapq
from collections import defaultdict
from typing import List, Tuple
class Graph:
def __init__(self):
self.edges = defaultdict(list)
def add_edge(self, from_node, to_node, weight):
self.edges[from_node].append((to_node, weight))
self.edges[to_node].append((from_node,... | from solution import shortest_path_3d
def test_shortest_path_simple():
start = (0, 0, 0)
end = (1, 1, 1)
obstacles = []
assert shortest_path_3d(start, end, obstacles) == [(0, 0, 0), (1, 1, 1)]
def test_shortest_path_with_simple_obstacles():
start = (0, 0, 0)
end = (2, 2, 2)
obstacles = [[(... | [] | [
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 namedtuple\nfrom typing import List, Tuple\n\n# Define type aliases for clarity\nPoint3D = namedtuple('Point3D', 'x y z')\nPolygon = List[Point3D]\n\ndef ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028951",
"row_id": 28951,
"seed_ids": "['Qwen2-72B-Instruct_68628']"
} | 0.514151 | Filter_28951 | I | [
"heuristic",
"astar",
"shortest_path_3d"
] | 3 | [
[
"astar",
"heuristic"
],
[
"shortest_path_3d",
"astar"
],
[
"shortest_path_3d",
"heuristic"
]
] | 3 | [] | false | [
"Graph"
] | true | pytest | true | [] | true | 320c0bd9580c44c8d079d57fd6361f202a681ff8 | 2067afdcec9778e5490acd2cc4c194141534cb87 | |||
v1.0 | instruct | Filter | Filter_29002_I | Create a function to encrypt a string using the XOR operator and a randomly generated key of length 16. The key must be generated using a cryptographically secure random number generator. The function should also include an additional input parameter to specify the encryption algorithm (e.g., AES, RSA) to be used along... | import os
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
def generate_secure_key(length=16):
"""
Generates a cryptographically secure random key of specified length.
"""
return os.urandom(length)
def xor_encrypt(dat... | from solution import generate_secure_key, xor_encrypt, encrypt
def test_generate_secure_key():
key = generate_secure_key(16)
assert len(key) == 16
def test_xor_encrypt():
data = b"hello world"
key = generate_secure_key(len(data))
encrypted_data = xor_encrypt(data, key)
decrypted_data = xor_enc... | [
{
"docstring": "Generates a cryptographically secure random key of specified length.",
"function_declaration": "def generate_secure_key(length=16):",
"function_name": "generate_secure_key",
"parameter_list": "(length=16)"
},
{
"docstring": "Encrypts the data using the XOR operator and the pr... | [
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 random\nfrom Crypto.Cipher import AES\nfrom Crypto.PublicKey import RSA\nfrom Crypto.Random import get_random_bytes\nfrom Crypto.Cipher import PKCS1_OAEP\n\ndef xor_encrypt_d... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029002",
"row_id": 29002,
"seed_ids": "['Qwen2-72B-Instruct_68705']"
} | 0.538678 | Filter_29002 | I | [
"generate_secure_key",
"xor_encrypt",
"encrypt"
] | 3 | [
[
"encrypt",
"generate_secure_key"
],
[
"encrypt",
"xor_encrypt"
]
] | 2 | [] | false | [] | false | pytest | true | [
"cryptography"
] | false | 568512398f6e90cfa361a1f967b2126e3d0f18f7 | 950978b8f364e78db58ba82002bc0f19ec076199 | |||
v1.0 | instruct | Filter | Filter_29015_I | Write a program that randomly generates a 4-digit number and allows the user to guess the number. The program should give hints such as "hot" for a correct digit in the correct position and "cold" for a correct digit in the wrong position. Limit the maximum number of attempts a user can make to guess the number correct... | import random
def generate_number():
"""
Generates a 4-digit random number as a string.
"""
return ''.join([str(random.randint(0, 9)) for _ in range(4)])
def get_feedback(secret_number, guess):
"""
Provides feedback on the guess in terms of 'hot' and 'cold'.
"""
feedback = []
... | from solution import generate_number, get_feedback
def test_generate_number_length():
assert len(generate_number()) == 4
def test_generate_number_digits():
number = generate_number()
assert number.isdigit()
def test_get_feedback_all_hot():
assert get_feedback('1234', '1234') == ['hot', 'hot', 'hot', ... | [
{
"docstring": "Generates a 4-digit random number as a string.",
"function_declaration": "def generate_number():",
"function_name": "generate_number",
"parameter_list": "()"
},
{
"docstring": "Provides feedback on the guess in terms of 'hot' and 'cold'.",
"function_declaration": "def get... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_number():\n \"\"\"\n Generates a 4-digit random number as a string.\n \"\"\"\n return ''.join([str(random.randint(0, 9)) for _ in range(4)])\n\ndef ge... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029015",
"row_id": 29015,
"seed_ids": "['Qwen2-72B-Instruct_68723']"
} | 0.456627 | Filter_29015 | I | [
"generate_number",
"get_feedback",
"guess_number_game"
] | 3 | [
[
"guess_number_game",
"generate_number"
],
[
"guess_number_game",
"get_feedback"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a33f0e6a2676846c9089e6c40a65bb30bd7f364f | 7c8b81dfc588b781ba523db29cbc0de559dd8deb | |||
v1.0 | instruct | Filter | Filter_29033_I | **Merge Sort Algorithm: Write a Python function that performs a merge sort on a given list of numbers.** | def merge_sort(arr):
"""
Performs a merge sort on the given list of numbers.
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])
return merge(left_half, right_half)
def merge(left, right):
"""
Merges... | from solution import merge_sort
def test_merge_sort_empty_list():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reversed_list():
assert merge... | [
{
"docstring": "Performs a merge sort on the given list of numbers.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"function_declaration": "def merge(left, right... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(array):\n \"\"\"\n Perform merge sort on the input array and return the sorted array.\n \"\"\"\n if len(array) <= 1:\n return array\n \n # Split the arr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029033",
"row_id": 29033,
"seed_ids": "['Qwen2-72B-Instruct_68745']"
} | 0.662916 | Filter_29033 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 92ad4e636691019a201764117b72d2cf3d0e9718 | 224a6bfadd65511b48063367778acdddc6dbdef5 | |||
v1.0 | instruct | Filter | Filter_29037_I | I need a function modified from the code given which takes a list of integers, it should return the last two maximum number in the list. However, it should not return numbers that are divisible by any number in the list except 1 and itself. | def is_prime(n, lst):
"""
Helper function to check if a number n is divisible
by any number in the list lst except 1 and itself.
"""
for num in lst:
if num != n and num != 1 and n % num == 0:
return False
return True
def last_two_max_prime(lst):
"""
Returns the last... | from solution import last_two_max_prime, is_prime
def test_is_prime():
assert is_prime(7, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True
assert is_prime(6, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False
assert is_prime(5, [1, 2, 5, 10]) == True
assert is_prime(10, [1, 2, 5, 10]) == False
def test_last_two_max_pr... | [
{
"docstring": "Helper function to check if a number n is divisible \nby any number in the list lst except 1 and itself.",
"function_declaration": "def is_prime(n, lst):",
"function_name": "is_prime",
"parameter_list": "(n, lst)"
},
{
"docstring": "Returns the last two maximum numbers in the... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n, lst):\n \"\"\"\n Helper function to check if a number n is divisible \n by any number in the list lst except 1 and itself.\n \"\"\"\n for num in lst:\n if... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029037",
"row_id": 29037,
"seed_ids": "['Qwen2-72B-Instruct_68751']"
} | 0.620709 | Filter_29037 | I | [
"is_prime",
"last_two_max_prime"
] | 2 | [
[
"last_two_max_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a1015acb1a645ff31e8d16445b5a6a4aba201436 | d1fb9b4ec918f0fc7912e3f9acd55c07de152ada | |||
v1.0 | instruct | Filter | Filter_29095_I | Write a function that takes a list of integers as input and returns a list of unique prime numbers present in the input list, sorted in ascending order. The function should have a time complexity of O(n√m), where n is the length of the input list and m is the maximum value in the input list. | import math
def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, unique_sorted_primes
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert is_prime(5)
assert is_prime(7)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(4)
assert not is_prime(6)
assert not is_prime(8)
assert not is_prim... | [
{
"docstring": "Checks 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 unique prime numbers present in the input list, sorted in ascending order.",
"function_declaration... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if 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... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029095",
"row_id": 29095,
"seed_ids": "['Qwen2-72B-Instruct_68857']"
} | 0.636941 | Filter_29095 | I | [
"is_prime",
"unique_sorted_primes"
] | 2 | [
[
"unique_sorted_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 508c4b98d270c272ade60879ff55946d6e3ecf69 | d2e48539665e5c8c98dace8aae7cf86816b7e105 | |||
v1.0 | instruct | Filter | Filter_29097_I | Develop an algorithmic solution leveraging the intricacies of QuickSort methodology, applied specifically to doubly linked data structures. This is opposed to the usual scenarios which frequently use arrays, thereby adding an extra layer of complexity to the programming challenge at hand.Let's consider the structure of... | class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
def partition(low, high):
pivot = high.data
i = low.prev
j = low
while j != high:
if j.data <= pivot:
if i is None:
i = low
else:
... | from solution import Node, quicksort_doubly_linked_list
def linked_list_to_array(head):
array = []
while head:
array.append(head.data)
head = head.next
return array
def test_quicksort_doubly_linked_list():
# Test case 1: Normal case
node1 = Node(4)
node2 = Node(2)
node3 = N... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, data):\n self.data = data\n self.prev = None\n self.next = None\n\ndef partition(low, high):\n pivot = high.data\n i = low.prev\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029097",
"row_id": 29097,
"seed_ids": "['Qwen2-72B-Instruct_68860']"
} | 0.398861 | Filter_29097 | I | [
"partition",
"quicksort",
"last_node",
"quicksort_doubly_linked_list"
] | 4 | [
[
"quicksort",
"partition"
],
[
"quicksort_doubly_linked_list",
"last_node"
],
[
"quicksort_doubly_linked_list",
"quicksort"
]
] | 3 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 3850ccd08c6d14ab05c83b6a476e6b581768fa92 | bd392cc386c4671b8911c979a3bc226bee8d8a48 | |||
v1.0 | instruct | Filter | Filter_29142_I | Given a list of integers (containing only unique elements) in Python, write a function that not only reverses the elements of the list but also finds the sum of all prime numbers in the reversed list. | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def reverse_and_sum_primes(arr):
"""
Reverses the elements of the list and retur... | from solution import reverse_and_sum_primes
def test_reverse_and_sum_primes_all_primes():
assert reverse_and_sum_primes([2, 3, 5, 7]) == ([7, 5, 3, 2], 17)
def test_reverse_and_sum_primes_mixed():
assert reverse_and_sum_primes([4, 6, 2, 3, 5]) == ([5, 3, 2, 6, 4], 10)
def test_reverse_and_sum_primes_no_prime... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Reverses the elements of the list and returns the sum of all prime numbers in the reversed list.",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n retur... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029142",
"row_id": 29142,
"seed_ids": "['Qwen2-72B-Instruct_68932']"
} | 0.591396 | Filter_29142 | I | [
"is_prime",
"reverse_and_sum_primes"
] | 2 | [
[
"reverse_and_sum_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 929b6035f6445a2d18035a8393ce928b3c5a7ece | 421aad8e89cc380c2eecd843610c248eae15b193 | |||
v1.0 | instruct | Filter | Filter_29157_I | Bogo sort, or permutation sort, is a highly inefficient sorting algorithm that works by randomly shuffling an array until it happens to be sorted. Write a Python function using numpy and random libraries to implement a bogo sort algorithm for an array of integers. Also, include a check for whether the array is sorted i... | import numpy as np
import random
def is_sorted(arr):
"""
Checks if the array is sorted in non-decreasing order.
"""
return all(arr[i] <= arr[i+1] for i in range(len(arr)-1))
def bogo_sort(arr):
"""
Sorts an array using the bogo sort algorithm, which shuffles the array until
it happens to b... | from solution import bogo_sort, is_sorted
def test_is_sorted():
assert is_sorted([1, 2, 3, 4, 5])
assert not is_sorted([5, 3, 8, 2, 1])
assert not is_sorted([1, 2, 3, 5, 4])
def test_bogo_sort_sorted_array():
arr = [1, 2, 3, 4, 5]
sorted_arr = bogo_sort(arr.copy())
assert is_sorted(sorted_arr)... | [
{
"docstring": "Checks if the array is sorted in non-decreasing order.",
"function_declaration": "def is_sorted(arr):",
"function_name": "is_sorted",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts an array using the bogo sort algorithm, which shuffles the array until\nit happens to be so... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport random\n\ndef is_sorted(arr):\n \"\"\"\n Helper function to check if the array is sorted.\n \"\"\"\n for i in range(len(arr) - 1):\n if arr[i] > a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029157",
"row_id": 29157,
"seed_ids": "['Qwen2-72B-Instruct_68956']"
} | 0.607827 | Filter_29157 | I | [
"is_sorted",
"bogo_sort"
] | 2 | [
[
"bogo_sort",
"is_sorted"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 5d22ff59ce3d671bc6f0f2825e9c42e579e7be19 | faf8e5777a058fd870a13a9a84c710e40d4d70d8 | |||
v1.0 | instruct | Filter | Filter_29159_I | Create an encryption algorithm that encodes a message by reversing the order of the letters and then shifting each letter by a random number of positions in the alphabet. The algorithm should also have the capability to add a random or predefined string of characters (cipher key) to further obfuscate the message. Decry... | import random
import string
def generate_cipher_key(length=10):
"""
Generates a random cipher key of the specified length.
"""
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
def shift_char(c, shift):
"""
Shifts a character by the specified number of positions in... | from solution import generate_cipher_key, encode_message, decode_message
def test_generate_cipher_key():
key = generate_cipher_key()
assert len(key) == 10
assert all(c in string.ascii_letters + string.digits for c in key)
def test_shift_char():
assert shift_char('a', 1) == 'b'
assert shift_char('z... | [
{
"docstring": "Generates a random cipher key of the specified length.",
"function_declaration": "def generate_cipher_key(length=10):",
"function_name": "generate_cipher_key",
"parameter_list": "(length=10)"
},
{
"docstring": "Shifts a character by the specified number of positions in the al... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_cipher_key(length=8):\n \"\"\"\n Generates a random string of letters to be used as the cipher key.\n Default length is 8 characters.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029159",
"row_id": 29159,
"seed_ids": "['Qwen2-72B-Instruct_68959']"
} | 0.618577 | Filter_29159 | I | [
"generate_cipher_key",
"shift_char",
"encode_message",
"decode_message"
] | 4 | [
[
"decode_message",
"shift_char"
],
[
"encode_message",
"shift_char"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b82d2df91adb33372bc99f9d25ef899defcf4b2d | b6fe5bc67bd098506cbd7f53e42bf7d14be729f1 | |||
v1.0 | instruct | Filter | Filter_29200_I | Write a Python program to find the kth smallest element in an unsorted array using quicksort algorithm. However, you are not allowed to use any built-in functions or libraries to implement quicksort. You must implement the quicksort algorithm from scratch. Additionally, you must ensure that the program has a time compl... | def partition(arr, low, high):
"""
Partition the array around the pivot element.
"""
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i ... | from solution import find_kth_smallest
def test_find_kth_smallest():
arr = [3, 1, 5, 2, 4]
assert find_kth_smallest(arr, 1) == 1
assert find_kth_smallest(arr, 2) == 2
assert find_kth_smallest(arr, 3) == 3
assert find_kth_smallest(arr, 4) == 4
assert find_kth_smallest(arr, 5) == 5
def test_find... | [
{
"docstring": "Partition the array around the pivot element.",
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": "Uses the quicksort partitioning method to find the kth smallest element.",
"func... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quickselect(arr, k):\n \"\"\"\n Function to find the kth smallest element in an unsorted array using the quicksort algorithm.\n \"\"\"\n def partition(low, high):\n pivo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029200",
"row_id": 29200,
"seed_ids": "['Qwen2-72B-Instruct_69027']"
} | 0.593487 | Filter_29200 | I | [
"partition",
"quick_select",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quick_select"
],
[
"quick_select",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9e56eaebfac9c60304a11cea80ac599c8f816c67 | a06d8a01828a85e5c5a5b6924db13e624580d8f7 | |||
v1.0 | instruct | Filter | Filter_29206_I | I'm trying to find the largest prime number that is less than a specified number. Can you help me design a function in Python to achieve this? Also, is there a way to optimize this function for larger numbers? | def is_prime(n):
"""
Helper function to check if a number n 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
... | from solution import is_prime, largest_prime_less_than
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
def test_largest_prime_less_than():
assert largest_prime_less_than(10) == 7
... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number less than the given number n.",
"function_declaration": "def largest_pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n elif n % 2 == 0 or n % 3 ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029206",
"row_id": 29206,
"seed_ids": "['Qwen2-72B-Instruct_69034']"
} | 0.733992 | Filter_29206 | I | [
"is_prime",
"largest_prime_less_than"
] | 2 | [
[
"largest_prime_less_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8107e2a2312b6ee26f533afc1e6e5b24440de4c5 | 41319fcba946d6548dc4e8f135877e0c7bc52971 | |||
v1.0 | instruct | Filter | Filter_29233_I | Create a program in Python that takes two strings as input and determines if they are anagrams of each other. The program should also check if the anagram pairs are also mirror words (palindromes). For example, "race" and "care" are anagrams, but not mirror words, whereas "deified" and "deified" are both anagrams and m... | def are_anagrams(str1, str2):
"""
Checks if two strings are anagrams of each other.
"""
return sorted(str1) == sorted(str2)
def is_palindrome(s):
"""
Checks if a string is a palindrome.
"""
return s == s[::-1]
def check_anagram_and_palindrome(str1, str2):
"""
Determines if two ... | from solution import are_anagrams, is_palindrome, check_anagram_and_palindrome
def test_are_anagrams():
assert are_anagrams("race", "care") == True
assert are_anagrams("hello", "billion") == False
assert are_anagrams("listen", "silent") == True
def test_is_palindrome():
assert is_palindrome("deified")... | [
{
"docstring": "Checks if two strings are anagrams of each other.",
"function_declaration": "def are_anagrams(str1, str2):",
"function_name": "are_anagrams",
"parameter_list": "(str1, str2)"
},
{
"docstring": "Checks if a string is a palindrome.",
"function_declaration": "def is_palindro... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def are_anagrams(str1, str2):\n \"\"\"\n Checks if two strings are anagrams of each other.\n \"\"\"\n return sorted(str1) == sorted(str2)\n\ndef is_palindrome(s):\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029233",
"row_id": 29233,
"seed_ids": "['Qwen2-72B-Instruct_69078']"
} | 0.607485 | Filter_29233 | I | [
"are_anagrams",
"is_palindrome",
"check_anagram_and_palindrome"
] | 3 | [
[
"check_anagram_and_palindrome",
"are_anagrams"
],
[
"check_anagram_and_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e501b0167f1bfb1412a60febc44942817406b929 | 0f5d6ebe2bbe9ca225e6c04eaf3fd43193d56d56 | |||
v1.0 | instruct | Filter | Filter_29244_I | Design a Python function that not only performs a binary search-based insertion sort on a list of n integers, but also does this on multiple lists concurrently using multi-threading. Each list will have a different length and they will be provided from a 2D array. Also, include functionality to measure and compare the ... | import threading
import time
from bisect import insort
def binary_insertion_sort(arr):
"""
Function to perform insertion sort using binary search.
"""
sorted_list = []
for elem in arr:
insort(sorted_list, elem)
return sorted_list
def threaded_sort(lst, results, idx):
"""
Sorts ... | from solution import multi_threaded_sort
def test_multi_threaded_sort_single_list():
lists = [[3, 1, 2]]
results = multi_threaded_sort(lists)
assert results[0][0] == [1, 2, 3]
def test_multi_threaded_sort_multiple_lists():
lists = [[3, 1, 2], [5, 2, 4, 3], [9, 8, 7, 6, 5]]
results = multi_threaded... | [
{
"docstring": "Function to perform insertion sort using binary search.",
"function_declaration": "def binary_insertion_sort(arr):",
"function_name": "binary_insertion_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts lst using binary insertion sort and stores the result along with s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import threading\nimport time\nfrom typing import List, Tuple\n\ndef binary_search(arr: List[int], val: int, start: int, end: int) -> int:\n \"\"\"Helper function to find index using binary... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029244",
"row_id": 29244,
"seed_ids": "['Qwen2-72B-Instruct_69103']"
} | 0.524969 | Filter_29244 | I | [
"binary_insertion_sort",
"threaded_sort",
"multi_threaded_sort"
] | 3 | [
[
"threaded_sort",
"binary_insertion_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c5bae4d1822365a3f8bd19dacee0f6369a835050 | a854dc8e478efc6a9b231ee7f03f9466c38f5284 | |||
v1.0 | instruct | Filter | Filter_29249_I | Create a code to sort this list in a descending order while ignoring any duplicate values. The code should also ensure that the time complexity of the sorting algorithm is O(nlogn). Additionally, the code should not use any built-in sorting functions or libraries. The code should be implemented in a recursive manner, a... | def merge_sort_descending(arr):
"""
Sorts the given array in descending order, ignoring duplicate values.
The sorting is implemented using a recursive merge sort algorithm.
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort_descending(arr[:mid])
right_ha... | from solution import sort_without_duplicates
def test_empty_list():
assert sort_without_duplicates([]) == []
def test_single_element():
assert sort_without_duplicates([5]) == [5]
def test_no_duplicates():
assert sort_without_duplicates([3, 1, 4, 2]) == [4, 3, 2, 1]
def test_with_duplicates():
assert... | [
{
"docstring": "Sorts the given array in descending order, ignoring duplicate values.\nThe sorting is implemented using a recursive merge sort algorithm.",
"function_declaration": "def merge_sort_descending(arr):",
"function_name": "merge_sort_descending",
"parameter_list": "(arr)"
},
{
"doc... | [
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 \"\"\"Sorts an array in descending order and removes duplicates using merge sort algorithm.\"\"\"\n def merge(left, right):\n result = []\n i = j = 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029249",
"row_id": 29249,
"seed_ids": "['Qwen2-72B-Instruct_69108']"
} | 0.572974 | Filter_29249 | I | [
"merge_sort_descending",
"merge",
"sort_without_duplicates"
] | 3 | [
[
"merge_sort_descending",
"merge"
],
[
"sort_without_duplicates",
"merge_sort_descending"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e8ffa421bc4f6539dcb232fd52216aade36c1d75 | d3a3ac01b18dff405a2f66ce9f46d3a1f6b108ae | |||
v1.0 | instruct | Filter | Filter_29254_I | Create a Python program that can classify an input string as either a palindrome, a number, or neither. Additionally, if the input is a number, the program should check if it is prime. If the input is a palindrome, the program should check if it is a numeric palindrome (e.g., "1331") or a string palindrome (e.g., "race... | def is_prime(n):
"""
Determines if the given integer 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
... | from solution import is_prime, classify_string
def test_is_prime():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(4) is False
assert is_prime(29) is True
assert is_prime(1) is False
assert is_prime(0) is False
assert is_prime(-5) is False
def test_classify_string():... | [
{
"docstring": "Determines if the given integer n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Classifies the input string as a palindrome, a number, or neither.\n- If it is a palindrome, specifies if... | [
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 prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029254",
"row_id": 29254,
"seed_ids": "['Qwen2-72B-Instruct_69114']"
} | 0.711485 | Filter_29254 | I | [
"is_prime",
"classify_string"
] | 2 | [
[
"classify_string",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b74224517733fbddcbe93bc8c047d85f9fc87b4c | 4a77d152049de690df79eff2307dfcae46767cef | |||
v1.0 | instruct | Filter | Filter_29255_I | How can I create a Python function that prints all the prime numbers in a given list? | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def print_primes(numbers):
"""
Prints all prime numbers in the given list.
"""
... | from solution import is_prime, print_primes
import io
import sys
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(6)
assert is_prime(7)
def test_print_primes():
# R... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints all prime numbers in the given list.",
"function_declaration": "def print_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 \"\"\"Returns True if n is a prime number, else False.\"\"\"\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": "00029255",
"row_id": 29255,
"seed_ids": "['Qwen2-72B-Instruct_69119']"
} | 0.699175 | Filter_29255 | I | [
"is_prime",
"print_primes"
] | 2 | [
[
"print_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 027a46336bb86dee1b57236f2ea62cdff53e78c3 | b2d92d05260d09ae30c189f677cecc5fc695df4e | |||
v1.0 | instruct | Filter | Filter_29264_I | Develop an algorithm for a breadth-first search that also tracks the shortest path from the starting node to each node in the graph. Additionally, the algorithm should handle graphs with weighted edges, where each edge has a different weight. The shortest path should be determined based on the sum of the weights of the... | import heapq
def dijkstra(graph, start):
"""
Runs Dijkstra's algorithm on a weighted graph to find the shortest path from start to all nodes.
Parameters:
graph (dict): A dictionary representing the adjacency list of the graph where keys are nodes,
and values are lists of ... | from solution import shortest_path_to
def test_shortest_path_to_simple_graph():
graph = {
'A': [('B', 1), ('C', 4)],
'B': [('A', 1), ('C', 2), ('D', 5)],
'C': [('A', 4), ('B', 2), ('D', 1)],
'D': [('B', 5), ('C', 1)]
}
path, distance = shortest_path_to(graph, 'A', 'D')
a... | [
{
"docstring": "Runs Dijkstra's algorithm on a weighted graph to find the shortest path from start to all nodes.\n\nParameters:\n graph (dict): A dictionary representing the adjacency list of the graph where keys are nodes,\n and values are lists of tuples (neighbor, weight).\n start (str... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start_node):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path from the start_node\n to all other nodes in the graph.\n Returns... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029264",
"row_id": 29264,
"seed_ids": "['Qwen2-72B-Instruct_69135']"
} | 0.545059 | Filter_29264 | I | [
"dijkstra",
"shortest_path_to"
] | 2 | [
[
"shortest_path_to",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5f7fa8b43202eacc65a36543d577b3f5a6ef4092 | df5edde3482e2a780653c7ee118e906195278965 | |||
v1.0 | instruct | Filter | Filter_29269_I | Write a Python code to implement the minimax algorithm for a game of Tic-Tac-Toe, but also include alpha-beta pruning and allow for an arbitrary sized board. | import math
def is_winner(board, player):
# Check rows, columns and diagonals for winner
size = len(board)
for row in board:
if all(cell == player for cell in row):
return True
for col in range(size):
if all(board[row][col] == player for row in range(size)):
... | from solution import is_winner, is_full, minimax, find_best_move
def test_is_winner():
board = [
["X", "X", "X"],
["O", "X", "O"],
["O", "O", "X"]
]
assert is_winner(board, "X") == True
assert is_winner(board, "O") == False
def test_is_full():
board = [
["X", "X", ... | [
{
"docstring": null,
"function_declaration": "def is_winner(board, player):",
"function_name": "is_winner",
"parameter_list": "(board, player)"
},
{
"docstring": null,
"function_declaration": "def is_full(board):",
"function_name": "is_full",
"parameter_list": "(board)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_winner(board, player):\n # Check rows, columns and diagonals for winner\n size = len(board)\n \n for row in board:\n if all(cell == player for cell in ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029269",
"row_id": 29269,
"seed_ids": "['Qwen2-72B-Instruct_69142']"
} | 0.453857 | Filter_29269 | I | [
"is_winner",
"is_full",
"minimax",
"find_best_move"
] | 4 | [
[
"find_best_move",
"minimax"
],
[
"minimax",
"is_full"
],
[
"minimax",
"is_winner"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a06249b8500fe288b87c3885e8c95698edf46ba8 | ff3c4fa8534152f303331f42cd1c6a02b3a32e91 | |||
v1.0 | instruct | Filter | Filter_29276_I | Write a python program to simulate Conway's Game of Life. You must use a 2D array and implement the rules yourself. The game should first create a random initial state for the board and then evolve it over a given number of iterations. | import numpy as np
def create_random_board(height, width):
"""
Create a random board of size height x width.
"""
return np.random.randint(2, size=(height, width))
def count_neighbors(board, row, col):
"""
Count the number of live neighbors for a cell at (row, col)
"""
neighbors = [
... | import numpy as np
from solution import create_random_board, count_neighbors, next_state, game_of_life
def test_create_random_board():
board = create_random_board(5, 5)
assert board.shape == (5, 5)
assert np.all(np.isin(board, [0, 1]))
def test_count_neighbors():
board = np.array([
[1, 0, 0],
... | [
{
"docstring": "Create a random board of size height x width.",
"function_declaration": "def create_random_board(height, width):",
"function_name": "create_random_board",
"parameter_list": "(height, width)"
},
{
"docstring": "Count the number of live neighbors for a cell at (row, col)",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef create_board(rows, cols):\n \"\"\"\n Create a game board with random initial state.\n \"\"\"\n return [[random.choice([0, 1]) for _ in range(cols)] for _ in ra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029276",
"row_id": 29276,
"seed_ids": "['Qwen2-72B-Instruct_69152']"
} | 0.408096 | Filter_29276 | I | [
"create_random_board",
"count_neighbors",
"next_state",
"game_of_life"
] | 4 | [
[
"game_of_life",
"create_random_board"
],
[
"game_of_life",
"next_state"
],
[
"next_state",
"count_neighbors"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 0dbcb0c1f38ad9251829309ac9da7b5ad3339509 | de30fc49ac05aa61e5e4e3160b0060803fa3562d | |||
v1.0 | instruct | Filter | Filter_29286_I | Write a Python code that creates a dictionary with names as keys and phone numbers as values. The names should be in uppercase and the phone numbers should be in the format "+1-XXX-XXX-XXXX" where XXX-XXX-XXXX is a random 10-digit number. The dictionary should be sorted in descending order based on the length of the na... | import random
def generate_phone_number():
"""Generates a random phone number in the format +1-XXX-XXX-XXXX."""
number = random.randint(1000000000, 9999999999)
return f"+1-{str(number)[:3]}-{str(number)[3:6]}-{str(number)[6:]}"
def create_phone_book(names):
"""
Creates a dictionary with names as k... | from solution import create_phone_book
def test_create_phone_book():
names = ["Alice", "Bob", "Charlie", "David", "Eve", "Francesca"]
phone_book = create_phone_book(names)
assert len(phone_book) == 4 # Alice, Charlie, David, Francesca
for name in ["BOB", "EVE"]:
assert name not in ph... | [
{
"docstring": "Generates a random phone number in the format +1-XXX-XXX-XXXX.",
"function_declaration": "def generate_phone_number():",
"function_name": "generate_phone_number",
"parameter_list": "()"
},
{
"docstring": "Creates a dictionary with names as keys and phone numbers as values.\nT... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_phone_number():\n \"\"\"Generates a random phone number in the format +1-XXX-XXX-XXXX.\"\"\"\n number = random.randint(1000000000, 9999999999)\n return f... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029286",
"row_id": 29286,
"seed_ids": "['Qwen2-72B-Instruct_69169']"
} | 0.524004 | Filter_29286 | I | [
"generate_phone_number",
"create_phone_book"
] | 2 | [
[
"create_phone_book",
"generate_phone_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70cee9ab99952dbdc5b2168831c85fb166e4062a | f5262b9792328833541fc0482f088ca95774fa74 | |||
v1.0 | instruct | Filter | Filter_29309_I | Create a Python function that takes a list of integers as input and returns a list containing only the prime numbers in the input list. | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import filter_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(11) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_filter_primes_empty_l... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers in the input list.",
"function_declaration": "def filter_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(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029309",
"row_id": 29309,
"seed_ids": "['Qwen2-72B-Instruct_69218']"
} | 0.670369 | Filter_29309 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 645f920aedb7c90924033e22496be12dd6fb1261 | 0664eaf112cceb4b09c838950c62902cc10d23da | |||
v1.0 | instruct | Filter | Filter_29312_I | Say we have the equation f(x) = 2x^2 + 3x + 1. Using Numpy, what is the Python code to approximate the derivative of f(x) at x = 1 using a numerical differentiation formula with a step size of h = 0.01? Additionally, how can we compare the accuracy of this approximation to a symbolic differentiation approach using SymP... | import numpy as np
import sympy as sp
def numerical_derivative(h=0.01):
"""
Approximate the derivative of f(x) = 2x^2 + 3x + 1 at x = 1 using the central difference formula.
"""
x = 1
f = lambda x: 2*x**2 + 3*x + 1
derivative = (f(x + h) - f(x - h)) / (2 * h)
return derivative
def symbolic... | from solution import numerical_derivative, symbolic_derivative, compare_derivatives
def test_numerical_derivative():
num_der = numerical_derivative()
expected_value = 7.0 # calculated manually or using a reliable method
assert np.isclose(num_der, expected_value, atol=0.01), f"Expected {expected_value} but... | [
{
"docstring": "Approximate the derivative of f(x) = 2x^2 + 3x + 1 at x = 1 using the central difference formula.",
"function_declaration": "def numerical_derivative(h=0.01):",
"function_name": "numerical_derivative",
"parameter_list": "(h=0.01)"
},
{
"docstring": "Calculate the derivative o... | [
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 sympy as sp\n\ndef numerical_derivative(f, x, h=0.01):\n \"\"\"\n Approximates the derivative of f at x using the limit definition of the derivative.\n \n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029312",
"row_id": 29312,
"seed_ids": "['Qwen2-72B-Instruct_69224']"
} | 0.495655 | Filter_29312 | I | [
"numerical_derivative",
"symbolic_derivative",
"compare_derivatives"
] | 3 | [
[
"compare_derivatives",
"numerical_derivative"
],
[
"compare_derivatives",
"symbolic_derivative"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy",
"sympy"
] | false | d6f3dc7a817e4906b12be770ac51b15aeec2237d | d1ffedf474f7262e744e96889ace1bb4bc501ce0 | |||
v1.0 | instruct | Filter | Filter_29321_I | Given a list of n positive integers where n > 10^4 find the median without sorting the list using Python. The complexity of your solution should not exceed O(n) time complexity. Additionally ensure that your solution does not use any in-built libraries or external packages. | def partition(arr, low, high):
pivot = arr[high]
i = low
for j in range(low, high):
if arr[j] <= pivot:
arr[i], arr[j] = arr[j], arr[i]
i += 1
arr[i], arr[high] = arr[high], arr[i]
return i
def quickselect(arr, low, high, k):
if low == high:
return arr[lo... | from solution import find_median
def test_find_median_odd():
assert find_median([3, 5, 7, 1, 9, 2, 6, 4, 8]) == 5
def test_find_median_even():
assert find_median([12, 3, 5, 7, 4, 19, 26, 13]) == (7 + 12) / 2
def test_find_median_single_element():
assert find_median([10]) == 10
def test_find_median_two_e... | [
{
"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... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] <= pivot:\n arr[i], arr[j] = arr[j, arr[i]\n i += 1\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029321",
"row_id": 29321,
"seed_ids": "['Qwen2-72B-Instruct_69245']"
} | 0.744298 | Filter_29321 | I | [
"partition",
"quickselect",
"find_median"
] | 3 | [
[
"find_median",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1fea6a896737c2c72e97d821cb2c10fff3862424 | 20b2fe23251d09ed531dfe632257cdb7b94e63da | |||
v1.0 | instruct | Filter | Filter_29336_I | Write a Python script that generates random equations of addition, subtraction, and multiplication for numbers between -10 and 10. The script should evaluate the correctness of the user's answer for a given number of rounds and track the number of correct answers. | import random
def generate_equation():
"""
Generates a random equation involving addition, subtraction, or multiplication
with numbers between -10 and 10. Returns the equation as a string and its result.
"""
operators = ['+', '-', '*']
a = random.randint(-10, 10)
b = random.randint(-10, 10)... | from solution import generate_equation, evaluate_answers
def test_generate_equation():
equation, result = generate_equation()
allowed_operators = ['+', '-', '*']
assert any(op in equation for op in allowed_operators)
a, operator, b = equation.split()
assert -10 <= int(a) <= 10
assert -10 <= int... | [
{
"docstring": "Generates a random equation involving addition, subtraction, or multiplication\nwith numbers between -10 and 10. Returns the equation as a string and its result.",
"function_declaration": "def generate_equation():",
"function_name": "generate_equation",
"parameter_list": "()"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_equation():\n \"\"\"\n Generates a random equation of addition, subtraction, or multiplication \n with numbers between -10 and 10. Returns a tuple... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029336",
"row_id": 29336,
"seed_ids": "['Qwen2-72B-Instruct_69277']"
} | 0.530824 | Filter_29336 | I | [
"generate_equation",
"evaluate_answers"
] | 2 | [
[
"evaluate_answers",
"generate_equation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b479e3b09c19196a41d7c3efc39c646d1734f62 | fa124a4c4c811e506b0359d2f914970533d07451 | |||
v1.0 | instruct | Filter | Filter_29337_I | Write a program in Python to calculate the factorial of a given number using recursion. The program should also check if the input number is negative and prompt the user to enter a positive number. The program should be able to handle large numbers and provide an accurate result. Additionally, implement the program in ... | def factorial(n):
"""
Returns the factorial of a given non-negative integer n using recursion.
Raises a ValueError if n is negative.
"""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers.")
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
def... | from solution import factorial, factorial_list
import pytest
def test_factorial_of_non_negative():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(5) == 120
def test_factorial_negative_number():
with pytest.raises(ValueError)... | [
{
"docstring": "Returns the factorial of a given non-negative integer n using recursion.\nRaises a ValueError if n is negative.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of factorials for the given l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of a given number n using recursion.\n \"\"\"\n if n < 0:\n raise ValueError(\"Input must be a non-negative integer.\")\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029337",
"row_id": 29337,
"seed_ids": "['Qwen2-72B-Instruct_69280']"
} | 0.659344 | Filter_29337 | I | [
"factorial",
"factorial_list"
] | 2 | [
[
"factorial_list",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a9d2cad7e2f9ce86e7d9870a647ca9842ff9c72 | d5aea7a842314af2609bec28359fccd185e2335c | |||
v1.0 | instruct | Filter | Filter_29358_I | Find all the prime numbers in a Python list using list comprehension. | def is_prime(n):
"""
Check if a number n is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def find_primes(numbers):
"""
Find all prime numbers in a list using list comprehension.
"""
ret... | from solution import is_prime, find_primes
def test_is_prime():
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)
def test_find_primes():
assert find_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
ass... | [
{
"docstring": "Check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers in a list using list comprehension.",
"function_declaration": "def find_primes(numbers):",
"funct... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029358",
"row_id": 29358,
"seed_ids": "['Qwen2-72B-Instruct_69314']"
} | 0.622863 | Filter_29358 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9caac1fd295e86f4e3a3738d57dbe8be2d25af86 | 92e93875263ecc209bf422fac939417a227be0cd | |||
v1.0 | instruct | Filter | Filter_29370_I | Implement a function that takes a list of integers as an argument and returns a dictionary. The keys of the dictionary should be the integers from the list, and the values should be tuples. Each tuple should contain three elements: the index of the integer in the list, the square of the integer, and a boolean value tha... | 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 process_list_of_integers(int_list):
"""
Takes a list of integers and returns... | from solution import process_list_of_integers
def test_process_list_with_primes():
input_list = [2, 3, 4, 5]
expected_output = {
2: (0, 4, True, 'Prime'),
3: (1, 9, False, 'Prime'),
4: (2, 16, True),
5: (3, 25, False, 'Prime')
}
assert process_list_of_integers(input_list... | [
{
"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": "Takes a list of integers and returns a dictionary.\n\nThe keys of the dictionary are the integers from t... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029370",
"row_id": 29370,
"seed_ids": "['Qwen2-72B-Instruct_69329']"
} | 0.674512 | Filter_29370 | I | [
"is_prime",
"process_list_of_integers"
] | 2 | [
[
"process_list_of_integers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e2367c2d217b47c9279e6d101a0a665848092a5 | d8b1cdcb1ffdae4ca602cf9c00ee5fe25ea3ee86 | |||
v1.0 | instruct | Filter | Filter_29389_I | Write a code to print the first 100 prime numbers in reverse order. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | from solution import is_prime, first_100_primes_reverse
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(6)
assert is_prime(7)
def test_first_100_primes_reverse_length():
primes = first_100_primes_reverse()
assert ... | [
{
"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 the first 100 prime numbers.",
"function_declaration": "def first_100_primes():",
"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(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 # 2 is the only even prime number\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029389",
"row_id": 29389,
"seed_ids": "['Qwen2-72B-Instruct_69357']"
} | 0.560508 | Filter_29389 | I | [
"is_prime",
"first_100_primes",
"first_100_primes_reverse"
] | 3 | [
[
"first_100_primes",
"is_prime"
],
[
"first_100_primes_reverse",
"first_100_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bee627eec8a055c15dba528579137108977da843 | 1f261cda085c7e1b6348a96db2b9ea727cbd3211 | |||
v1.0 | instruct | Filter | Filter_29392_I | Suggest a solution to store years in ISO 8601 format in Python, but also include the functionality to convert the ISO 8601 formatted date to a different date format, such as 'dd-mm-yyyy'. Additionally, implement a validation mechanism to ensure that the input ISO 8601 date is valid and strictly adheres to the format st... | from datetime import datetime
def validate_iso8601_date(date_str):
"""
Validates if the input date string is in ISO 8601 format.
"""
try:
datetime.fromisoformat(date_str)
return True
except ValueError:
return False
def convert_iso8601_to_ddmmyyyy(date_str):
"""
Conv... | from solution import validate_iso8601_date, convert_iso8601_to_ddmmyyyy
def test_validate_iso8601_date_valid():
assert validate_iso8601_date("2021-03-02") == True
assert validate_iso8601_date("2023-10-05") == True
def test_validate_iso8601_date_invalid():
assert validate_iso8601_date("03-02-2021") == Fals... | [
{
"docstring": "Validates if the input date string is in ISO 8601 format.",
"function_declaration": "def validate_iso8601_date(date_str):",
"function_name": "validate_iso8601_date",
"parameter_list": "(date_str)"
},
{
"docstring": "Converts an ISO 8601 formatted date string to 'dd-mm-yyyy'."... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef iso_to_custom_format(iso_date_str, custom_format_str):\n \"\"\"\n Converts an ISO 8601 formatted date string to a custom format.\n\n Parameters:\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029392",
"row_id": 29392,
"seed_ids": "['Qwen2-72B-Instruct_69365']"
} | 0.502305 | Filter_29392 | I | [
"validate_iso8601_date",
"convert_iso8601_to_ddmmyyyy"
] | 2 | [
[
"convert_iso8601_to_ddmmyyyy",
"validate_iso8601_date"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ea490872b20221e5adcb1e1c06500e80335045d | 92b6efa026988a044e971617f2bd8c94e217b063 | |||
v1.0 | instruct | Filter | Filter_29413_I | Create a function in Python to generate a list of consecutive prime numbers starting from 2 up to a given number. The given number should be greater than 2. Additionally, the function should include a parameter for the starting number and generate the list of consecutive prime numbers starting from the specified number... | def sieve_of_eratosthenes(n):
"""
Generate all prime numbers up to and including n using the Sieve of Eratosthenes algorithm.
"""
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
p = 2
while (p * p <= n):
if sieve[p]:
for i in range(p * p, n + 1, p):
... | from solution import generate_primes
def test_generate_primes_standard_case():
assert generate_primes(2, 10) == [2, 3, 5, 7]
def test_generate_primes_with_nonprime_start():
assert generate_primes(8, 20) == [11, 13, 17, 19]
def test_generate_primes_with_large_range():
assert generate_primes(10, 50) == [11... | [
{
"docstring": "Generate all prime numbers up to and including n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of consecutive prime num... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Uses the Sieve of Eratosthenes algorithm to determine prime numbers up to n.\n \"\"\"\n primes = []\n is_prime = [True] * (n + 1)\n p... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029413",
"row_id": 29413,
"seed_ids": "['Qwen2-72B-Instruct_69394']"
} | 0.663855 | Filter_29413 | I | [
"sieve_of_eratosthenes",
"generate_primes"
] | 2 | [
[
"generate_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 47f8caf8e88a97789342160343d9c0ac09872170 | 67050aa176a4bbb202c76acb8e206535d4af6fde | |||
v1.0 | instruct | Filter | Filter_29414_I | Build a Python function that not only calculates the Highest Common Factor (HCF) of four integers but also verifies whether those numbers are divisible by a user defined number or not. If they aren't divisible, the function should generate the closest numbers which are divisible by the defined number. | def gcd(a, b):
"""
Returns the Greatest Common Divisor (GCD) of a and b.
"""
while b:
a, b = b, a % b
return a
def hcf_of_four(a, b, c, d):
"""
Returns the Highest Common Factor (HCF) of four integers.
"""
return gcd(gcd(gcd(a, b), c), d)
def closest_divisible_by(num, divis... | from solution import gcd, hcf_of_four, closest_divisible_by, process_numbers
def test_gcd():
assert gcd(8, 12) == 4
assert gcd(17, 13) == 1
assert gcd(0, 10) == 10
assert gcd(18, 18) == 18
def test_hcf_of_four():
assert hcf_of_four(8, 12, 16, 20) == 4
assert hcf_of_four(15, 25, 35, 45) == 5
... | [
{
"docstring": "Returns the Greatest Common Divisor (GCD) of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the Highest Common Factor (HCF) of four integers.",
"function_declaration": "def hcf_of_four(a, ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef hcf_of_four(a, b, c, d):\n # Calculate HCF of four numbers\n hcf_ab = gcd(a, b)\n hcf_abc = gcd(hcf_ab, c)\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029414",
"row_id": 29414,
"seed_ids": "['Qwen2-72B-Instruct_69395']"
} | 0.670186 | Filter_29414 | I | [
"gcd",
"hcf_of_four",
"closest_divisible_by",
"process_numbers"
] | 4 | [
[
"hcf_of_four",
"gcd"
],
[
"process_numbers",
"closest_divisible_by"
],
[
"process_numbers",
"hcf_of_four"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 28cefb2194aa0791eaf8536232abbe65e0f785fa | 894e450ac2b22145ad6f44894fba511fb3bc7ff0 | |||
v1.0 | instruct | Filter | Filter_29419_I | Write a complete algorithm in Python for sorting an array using the Quick Sort technique. In addition, implement a function that visualizes the state of the array after each partition operation. You may use matplotlib for visualization purposes. | import matplotlib.pyplot as plt
import time
def quicksort(arr, low, high):
if low < high:
pi = partition(arr, low, high)
visualize(arr)
quicksort(arr, low, pi - 1)
quicksort(arr, pi + 1, high)
def partition(arr, low, high):
pivot = arr[high]
i = (low - 1)
for j in range... | import pytest
from solution import quicksort_with_visualization
def test_sort_empty_list():
arr = []
sorted_arr = quicksort_with_visualization(arr)
assert sorted_arr == []
def test_sort_single_element_list():
arr = [1]
sorted_arr = quicksort_with_visualization(arr)
assert sorted_arr == [1]
de... | [
{
"docstring": null,
"function_declaration": "def quicksort(arr, low, high):",
"function_name": "quicksort",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(ar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import matplotlib.pyplot as plt\nimport time\n\ndef quick_sort(arr):\n \"\"\"\n Sorts the array using the Quick Sort algorithm.\n \"\"\"\n quick_sort_recursive(arr, 0, len(arr) - 1... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029419",
"row_id": 29419,
"seed_ids": "['Qwen2-72B-Instruct_69404']"
} | 0.609179 | Filter_29419 | I | [
"quicksort",
"partition",
"visualize",
"quicksort_with_visualization"
] | 4 | [
[
"quicksort",
"partition"
],
[
"quicksort",
"visualize"
],
[
"quicksort_with_visualization",
"quicksort"
]
] | 3 | [] | false | [] | false | pytest | true | [
"matplotlib"
] | false | 33cfc7c4cf067b78a1b8e956fa2a7e05a456a677 | d0607c8ce54d368729002251557e30ebefe45064 | |||
v1.0 | instruct | Filter | Filter_29436_I | I have a list of words, and I want to filter out the ones that are palindromes (words that can be read the same way forwards and backwards). How can I write a program to accomplish this? | def is_palindrome(word):
"""
Checks if a given word is a palindrome.
"""
return word == word[::-1]
def filter_palindromes(words):
"""
Filters out palindromes from a list of words.
"""
return [word for word in words if not is_palindrome(word)] | from solution import is_palindrome, filter_palindromes
def test_is_palindrome_with_palindromes():
assert is_palindrome("madam") is True
assert is_palindrome("racecar") is True
assert is_palindrome("level") is True
def test_is_palindrome_with_non_palindromes():
assert is_palindrome("hello") is False
... | [
{
"docstring": "Checks if a given word is a palindrome.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Filters out palindromes from a list of words.",
"function_declaration": "def filter_palindromes(wo... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def filter_palindromes(words):\n \"\"\"\n Filters out the palindromes from a list of words.\n \n :param words: List of words to check.\n :return: List of non-palindrome words.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029436",
"row_id": 29436,
"seed_ids": "['Qwen2-72B-Instruct_69431']"
} | 0.652131 | Filter_29436 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee94e6e573194cce998172c698ef148be6324ecd | 5e1ff74463d686d43138a301a1c8e1cdec517832 | |||
v1.0 | instruct | Filter | Filter_29439_I | In Python, write a function that applies a given list of offsets to a copy of a given list of integers, ensuring the original list remains unchanged. The function should handle cases where the offset list is shorter than the integer list by repeating the offsets. For example, applying offsets [1, 2] to [4, 5, 6, 7] sho... | from typing import List
def apply_offsets(integers: List[int], offsets: List[int]) -> List[int]:
"""
Applies a given list of offsets to a copy of a given list of integers,
ensuring the original list remains unchanged. Repeats the offsets if
the offset list is shorter than the integer list.
"""
... | from solution import apply_offsets
def test_apply_offsets_even_case():
assert apply_offsets([4, 5, 6, 7], [1, 2]) == [5, 7, 7, 9]
def test_apply_offsets_single_offset():
assert apply_offsets([1, 2, 3], [1]) == [2, 3, 4]
def test_apply_offsets_zero_offset():
assert apply_offsets([0, 0, 0], [0]) == [0, 0, ... | [
{
"docstring": "Applies a given list of offsets to a copy of a given list of integers,\nensuring the original list remains unchanged. Repeats the offsets if \nthe offset list is shorter than the integer list.",
"function_declaration": "def apply_offsets(integers, offsets):",
"function_name": "apply_offs... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef apply_offsets(integers: List[int], offsets: List[int]) -> List[int]:\n \"\"\"\n Applies a given list of offsets to a copy of a given list of integers,\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029439",
"row_id": 29439,
"seed_ids": "['Qwen2-72B-Instruct_69434']"
} | 0.510866 | Filter_29439 | I | [
"apply_offsets",
"check_apply_offsets"
] | 2 | [
[
"check_apply_offsets",
"apply_offsets"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6a3afc1f4a7c62b3987267cc2089071fbfd719a | e4b7277290059268d6a1040ad17f86dbc9d897db | |||
v1.0 | instruct | Filter | Filter_29447_I | Create a program that generates an array of prime numbers from 0 to 100 in descending order. Use a function to check if a number is prime and incorporate a for loop to iterate through the numbers from 100 to 0. Utilize if/else statements to add only the prime numbers to the array. Finally, print the array of prime numb... | def is_prime(n):
"""
Check if the number n is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def generate_primes_descending(max_num):
"""
Generates an array of prime numbers from 0 to max_num i... | from solution import is_prime, generate_primes_descending
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(0) == False
assert is_prime(1) == False
def test_generat... | [
{
"docstring": "Check if the number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates an array of prime numbers from 0 to max_num in descending order.",
"function_declaration": "def generate_primes_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029447",
"row_id": 29447,
"seed_ids": "['Qwen2-72B-Instruct_69457']"
} | 0.618245 | Filter_29447 | I | [
"is_prime",
"generate_primes_descending"
] | 2 | [
[
"generate_primes_descending",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1f6c430328faff8a633481ad140b4b15194021c | a8763ffa7afe625e343dcaf254780ad1a2211e0c | |||
v1.0 | instruct | Filter | Filter_29464_I | Create a 3D cube list of size 4x4x4, filled with zeros. Additionally, implement a function to set every element in the nth layer to the nth number in the Fibonacci sequence, where n starts from 1. | def create_cube(size=4):
"""
Creates a 3D list (cube) of the given size, filled with zeros.
"""
return [[[0 for _ in range(size)] for _ in range(size)] for _ in range(size)]
def fibonacci(n):
"""
Returns the n-th number in the Fibonacci sequence.
"""
if n == 1: return 1
if n == 2: r... | from solution import create_cube, set_layer_to_fibonacci, fibonacci
def test_create_cube():
cube = create_cube()
assert len(cube) == 4
assert all(len(layer) == 4 for layer in cube)
assert all(len(row) == 4 for layer in cube for row in layer)
assert all(element == 0 for layer in cube for row in laye... | [
{
"docstring": "Creates a 3D list (cube) of the given size, filled with zeros.",
"function_declaration": "def create_cube(size=4):",
"function_name": "create_cube",
"parameter_list": "(size=4)"
},
{
"docstring": "Returns the n-th number in the Fibonacci sequence.",
"function_declaration"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def create_cube():\n \"\"\"\n Creates a 4x4x4 cube filled with zeros.\n \"\"\"\n return [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]\n\ndef fibonacci(n):\n \"\"... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029464",
"row_id": 29464,
"seed_ids": "['Qwen2-72B-Instruct_69485']"
} | 0.568352 | Filter_29464 | I | [
"create_cube",
"fibonacci",
"set_layer_to_fibonacci"
] | 3 | [
[
"set_layer_to_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 066ca8eab748511edea4af903cd6bcd113229e11 | 72968504109f29033dc9076e30a1bd08e8030f24 | |||
v1.0 | instruct | Filter | Filter_29468_I | Given a circular linked list, write a function to reverse it. Also, implement a function that checks if the reversed linked list is a palindrome. The function should return True if the reversed linked list is a palindrome, and False otherwise. | class Node:
def __init__(self, data):
self.data = data
self.next = None
def reverse_circular_linked_list(head):
if not head or not head.next:
return head
prev = None
current = head
next_node = None
while True:
next_node = current.next
current.next =... | from solution import Node, reverse_circular_linked_list, is_palindrome, check_reversed_is_palindrome
def test_empty_list():
assert check_reversed_is_palindrome(None) == True
def test_single_element_list():
head = Node(1)
head.next = head
assert check_reversed_is_palindrome(head) == True
def test_non_... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, data):\n self.data = data\n self.next = None\n\ndef reverse_circular_linked_list(head):\n \"\"\"\n Reverses a circular linked list.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029468",
"row_id": 29468,
"seed_ids": "['Qwen2-72B-Instruct_69491']"
} | 0.626364 | Filter_29468 | I | [
"reverse_circular_linked_list",
"is_palindrome",
"check_reversed_is_palindrome"
] | 3 | [
[
"check_reversed_is_palindrome",
"is_palindrome"
],
[
"check_reversed_is_palindrome",
"reverse_circular_linked_list"
]
] | 2 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 3928398cb87e1daa854941e7ef04214180b68152 | 51f2b65a367de7c1228588bab0563700b42ab59d | |||
v1.0 | instruct | Filter | Filter_29471_I | Write a python program to find all the prime numbers between 1 and 1000 and print them. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import is_prime, find_primes_between_1_and_1000
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_... | [
{
"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 between 1 and 1000.",
"function_declaration": "def find_primes_betwee... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_primes():\n \"\"\"\n Find and return a list of all prime numbers between 1 and 1000.\n \"\"\"\n primes = []\n for num in range(2, 1001): # Start from 2, as 1 is not a ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029471",
"row_id": 29471,
"seed_ids": "['Qwen2-72B-Instruct_69496']"
} | 0.639901 | Filter_29471 | I | [
"is_prime",
"find_primes_between_1_and_1000"
] | 2 | [
[
"find_primes_between_1_and_1000",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae016e1b5037befcfcd0c5dd0c432982698d778e | 30be894e1a38bb7089c2e93a1fe6e915917ebf69 | |||
v1.0 | instruct | Filter | Filter_29476_I | Design a recursive function that determines the Fibonacci sequence up to a given number n with an additional constraint of implementing it without using loops or the 'if' statement in Python. | def fibonacci(n):
"""
Returns the Fibonacci sequence up to the nth number.
"""
return _fibonacci(n, more_to_come=True)
def _fibonacci(n, more_to_come):
"""
Helper function to return Fibonacci sequence up to the nth number recursively.
"""
def fibo_rec(a, b, remaining):
return []... | from solution import fibonacci
def test_fibonacci_zero():
assert fibonacci(0) == []
def test_fibonacci_one():
assert fibonacci(1) == [0]
def test_fibonacci_two():
assert fibonacci(2) == [0, 1]
def test_fibonacci_five():
assert fibonacci(5) == [0, 1, 1, 2, 3]
def test_fibonacci_ten():
assert fib... | [
{
"docstring": "Returns the Fibonacci sequence up to the nth number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Helper function to return Fibonacci sequence up to the nth number recursively.",
"function_declarat... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, a=0, b=1, seq=None):\n \"\"\"\n Recursively generates the Fibonacci sequence up to the nth number.\n No loops or 'if' statements are used.\n \n Args:\n n : i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029476",
"row_id": 29476,
"seed_ids": "['Qwen2-72B-Instruct_69503']"
} | 0.703768 | Filter_29476 | I | [
"fibonacci",
"_fibonacci"
] | 2 | [
[
"fibonacci",
"_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 491ddc9f0e998718b02c005781c68ca509241a25 | 11c137f42c985b5b49ad5baa1b3d001c0b8aa0a8 | |||
v1.0 | instruct | Filter | Filter_29478_I | The following code snippet uses Python's "multiprocessing" and "concurrent.futures" to evaluate the calculation of "quadtribonacci" values. The "quadtribonacci" sequence is a variant of the Fibonacci sequence with four numbers preceding each subsequent number. The evaluation is performed using process-based parallelism... | from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
import multiprocessing
# Define the initial values of the quadtribonacci sequence
ARGS = [0, 0, 0, 1]
def quadtribonacci(n):
"""
Calculate the nth quadtribonacci number.
The quadtribonacci sequence starts with 0, 0, 0, 1 and each subse... | from solution import quadtribonacci, worker, use_process_pool, use_thread_pool, check_correctness
def test_quadtribonacci():
assert quadtribonacci(0) == 0
assert quadtribonacci(1) == 0
assert quadtribonacci(2) == 0
assert quadtribonacci(3) == 1
assert quadtribonacci(4) == 1
assert quadtribonacc... | [
{
"docstring": "Calculate the nth quadtribonacci number.\nThe quadtribonacci sequence starts with 0, 0, 0, 1 and each subsequent term\nis the sum of the previous four terms.",
"function_declaration": "def quadtribonacci(n):",
"function_name": "quadtribonacci",
"parameter_list": "(n)"
},
{
"d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor\nimport multiprocessing\n\n# defining ARGS initial values for the sequence \nARGS = [0, 1, 1, 2]\n\n# quadtribonacci func... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029478",
"row_id": 29478,
"seed_ids": "['Qwen2-72B-Instruct_69505']"
} | 0.614922 | Filter_29478 | I | [
"quadtribonacci",
"worker",
"use_process_pool",
"use_thread_pool",
"check_correctness"
] | 5 | [
[
"use_process_pool",
"worker"
],
[
"use_thread_pool",
"worker"
],
[
"worker",
"quadtribonacci"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b6605c83a790191c3b60cd9a62ace23c2bf77613 | 65e62740138aecb0cb69331bdbc6ba945e95de30 | |||
v1.0 | instruct | Filter | Filter_29509_I | How does one fill a 3x3 matrix with the first 9 prime numbers in Python? | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def fill_matrix_with_primes():
"""Fill a 3x3 matrix with the first 9 prime numbers."""
primes = []
num = 2
w... | from solution import fill_matrix_with_primes, is_prime
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)
def test_fill_matrix_with_primes():
expected_matrix = [
[2, 3, 5],
[7, 1... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Fill a 3x3 matrix with the first 9 prime numbers.",
"function_declaration": "def fill_matrix_with_primes():",
"function_na... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fill_prime_matrix():\n \"\"\"\n Fills a 3x3 matrix with the first 9 prime numbers.\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return False\n for i in r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029509",
"row_id": 29509,
"seed_ids": "['Qwen2-72B-Instruct_69568']"
} | 0.445985 | Filter_29509 | I | [
"is_prime",
"fill_matrix_with_primes"
] | 2 | [
[
"fill_matrix_with_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b685f96d5cbd0c223d64218186aabe772d84e7d9 | 6f9e4ff0aa3847b2de5fe39f45713ce820b35163 | |||
v1.0 | instruct | Filter | Filter_29521_I | Develop a function in Python for computing the cross product of two 3D vectors. Additionally, extend this function to compute the cross product of two vectors where the dimensions can be n. Note that for dimensions greater than three, the concept of cross product is not defined, hence in such cases the function should ... | def cross_product_3d(v1, v2):
"""
Returns the cross product of two 3D vectors.
Parameters:
v1 (list or tuple): A 3D vector.
v2 (list or tuple): A 3D vector.
Returns:
list: A 3D vector representing the cross product of v1 and v2.
"""
if len(v1) != 3 or len(v2) != 3:
... | from solution import cross_product, cross_product_3d
def test_cross_product_3d():
assert cross_product_3d([1, 0, 0], [0, 1, 0]) == [0, 0, 1]
assert cross_product_3d([0, 1, 0], [0, 0, 1]) == [1, 0, 0]
assert cross_product_3d([0, 0, 1], [1, 0, 0]) == [0, 1, 0]
assert cross_product_3d([1, 2, 3], [4, 5, 6]... | [
{
"docstring": "Returns the cross product of two 3D vectors.\n\nParameters:\nv1 (list or tuple): A 3D vector.\nv2 (list or tuple): A 3D vector.\n\nReturns:\nlist: A 3D vector representing the cross product of v1 and v2.",
"function_declaration": "def cross_product_3d(v1, v2):",
"function_name": "cross_p... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef cross_product(vector1, vector2):\n \"\"\"\n Compute the cross product of two vectors.\n \n Parameters:\n vector1 (list or tuple): First vector, should ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029521",
"row_id": 29521,
"seed_ids": "['Qwen2-72B-Instruct_69590']"
} | 0.50767 | Filter_29521 | I | [
"cross_product_3d",
"cross_product"
] | 2 | [
[
"cross_product",
"cross_product_3d"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6f5e118cc4173b1ee1df420b8ac9af4773197a5a | 43a2053a62891c6e6a7bd5d79b0ff3a290c319e8 | |||
v1.0 | instruct | Filter | Filter_29549_I | Write a python function to filter out all the prime numbers from a given list of integers. The function should also return the product of all the prime numbers in the list. If no prime number is found, return 0. | 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 filter_primes_and_p... | from solution import filter_primes_and_product
def test_no_primes():
assert filter_primes_and_product([1, 4, 6, 8, 10]) == 0
def test_all_primes():
assert filter_primes_and_product([2, 3, 5, 7]) == 210
def test_mixed_numbers():
assert filter_primes_and_product([1, 2, 4, 3, 6, 5, 15, 7]) == 210
def test_... | [
{
"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": "Filters out prime numbers from a given list of integers and returns the \nproduct of these primes. If no prim... | [
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 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": "00029549",
"row_id": 29549,
"seed_ids": "['Qwen2-72B-Instruct_69629']"
} | 0.628142 | Filter_29549 | I | [
"is_prime",
"filter_primes_and_product"
] | 2 | [
[
"filter_primes_and_product",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2324002f3b2aa1f92e69957910e1a1aa0d66dd9e | d3e73f635ca29b36a30faaa1f62d8b0d556f23c9 | |||
v1.0 | instruct | Filter | Filter_29562_I | Develop a regex pattern to extract all URLs from a given paragraph of text. Now, further refine the pattern to exclude URLs that contain specific substrings or patterns, such as "ad", "banner", or "affiliate". Additionally, write a function that validates the extracted URLs, ensuring they are active and return HTTP sta... | import re
import requests
def extract_urls(text):
"""
Extracts all URLs from the given paragraph of text, excluding URLs that contain
specific substrings such as 'ad', 'banner', or 'affiliate'.
"""
# Regex pattern to match URLs
url_pattern = re.compile(r'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+'... | from solution import extract_urls, validate_url, validate_urls
def test_extract_urls_with_valid_urls():
text = "Check out https://example.com and https://coolsite.org but not https://adsite.com or https://bannersite.com or https://affiliateexample.com"
urls = extract_urls(text)
assert urls == ["https://exa... | [
{
"docstring": "Extracts all URLs from the given paragraph of text, excluding URLs that contain\nspecific substrings such as 'ad', 'banner', or 'affiliate'.",
"function_declaration": "def extract_urls(text):",
"function_name": "extract_urls",
"parameter_list": "(text)"
},
{
"docstring": "Val... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nimport requests\n\ndef extract_urls(text):\n \"\"\"\n Extracts all URLs from the given paragraph of text, excluding URLs that contain\n specific substrings such as 'ad', 'b... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029562",
"row_id": 29562,
"seed_ids": "['Qwen2-72B-Instruct_69644']"
} | 0.609227 | Filter_29562 | I | [
"extract_urls",
"validate_url",
"validate_urls"
] | 3 | [
[
"validate_urls",
"validate_url"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 96565c3db021bd06bf800b466caea96b7c486170 | 7d4b7de6ed66f1375928d3e0173ae26b2b3a46a1 | |||
v1.0 | instruct | Filter | Filter_29568_I | Write a PEP8-compliant Python program that accepts two alphanumeric strings as input. Your program should not only compare if those strings are anagrams to each other ignoring the spaces and special characters, but also include a feature of timing your code execution. Add proper exception handling to manage any potenti... | import re
import time
def clean_string(s):
"""
Cleans the input string by removing non-alphanumeric characters and converting to lowercase.
"""
return re.sub(r'\W+', '', s).lower()
def are_anagrams(s1, s2):
"""
Checks whether two strings are anagrams of each other, ignoring spaces and special ... | from solution import are_anagrams, main
def test_clean_string():
assert clean_string("Hello, World!") == "helloworld"
assert clean_string(" ABC123 ") == "abc123"
assert clean_string("@!#$%^&*()") == ""
def test_are_anagrams():
assert are_anagrams("listen", "silent")
assert not are_anagrams("hello"... | [
{
"docstring": "Cleans the input string by removing non-alphanumeric characters and converting to lowercase.",
"function_declaration": "def clean_string(s):",
"function_name": "clean_string",
"parameter_list": "(s)"
},
{
"docstring": "Checks whether two strings are anagrams of each other, ig... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nimport time\n\ndef clean_string(s):\n \"\"\"\n Cleans the input string by removing non-alphanumeric characters and converting to lowercase.\n \"\"\"\n return re.sub(r'\\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029568",
"row_id": 29568,
"seed_ids": "['Qwen2-72B-Instruct_69652']"
} | 0.624051 | Filter_29568 | I | [
"clean_string",
"are_anagrams",
"main"
] | 3 | [
[
"are_anagrams",
"clean_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef1b978cfbe19f786115f106bb707d205005c049 | ecb2d3e3b8e7ec965e1f5b82e2f1973ced225eb2 | |||
v1.0 | instruct | Filter | Filter_29569_I | Write a code snippet for generating a random number between 1 and 100, but the generated number should not be divisible by any prime number between 2 and 10. Additionally, the code should also check if the generated number is a perfect square and if so, it should generate a new number until a non-perfect square is gene... | import random
import math
def is_not_divisible_by_primes(num):
for prime in [2, 3, 5, 7]:
if num % prime == 0:
return False
return True
def generate_number():
while True:
num = random.randint(1, 100)
if is_not_divisible_by_primes(num) and not math.isqrt(num) ** 2 == num... | from solution import generate_number, is_not_divisible_by_primes
import math
def test_is_not_divisible_by_primes():
assert is_not_divisible_by_primes(11) == True
assert is_not_divisible_by_primes(14) == False
assert is_not_divisible_by_primes(29) == True
assert is_not_divisible_by_primes(35) == False
... | [
{
"docstring": null,
"function_declaration": "def is_not_divisible_by_primes(num):",
"function_name": "is_not_divisible_by_primes",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def generate_number():",
"function_name": "generate_number",
"parameter_l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport math\n\ndef is_prime_factor(number, primes):\n \"\"\"\n Checks if the number is divisible by any of the specified prime numbers.\n \"\"\"\n for prime in prime... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029569",
"row_id": 29569,
"seed_ids": "['Qwen2-72B-Instruct_69654']"
} | 0.490494 | Filter_29569 | I | [
"is_not_divisible_by_primes",
"generate_number"
] | 2 | [
[
"generate_number",
"is_not_divisible_by_primes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccdb08537ccf2a5f867498ba4989110a06b23f11 | 48c12f806aeee649996999e9d6e53b13398ab2ee | |||
v1.0 | instruct | Filter | Filter_29576_I | Write a code snippet to implement a recursive binary search algorithm in a sorted linked list. Additionally, consider the time and space complexity of your solution. Binary search is an efficient search algorithm that works by repeatedly dividing in half the portion of the list that could contain the item, until you've... | class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def get_middle_node(start, end):
slow = fast = start
while fast != end and fast.next != end:
slow = slow.next
fast = fast.next.next
return slow
def recursive_binary_search(start,... | from solution import ListNode, sorted_linked_list_binary_search
def test_binary_search_found():
# Creating a sorted linked list: 1 -> 2 -> 3 -> 4 -> 5
node5 = ListNode(5)
node4 = ListNode(4, node5)
node3 = ListNode(3, node4)
node2 = ListNode(2, node3)
head = ListNode(1, node2)
assert s... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef get_middle(left, right):\n if left == right:\n return left\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029576",
"row_id": 29576,
"seed_ids": "['Qwen2-72B-Instruct_69664']"
} | 0.693989 | Filter_29576 | I | [
"get_middle_node",
"recursive_binary_search",
"sorted_linked_list_binary_search"
] | 3 | [
[
"recursive_binary_search",
"get_middle_node"
],
[
"sorted_linked_list_binary_search",
"recursive_binary_search"
]
] | 2 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 2b29bc4e02b1989d44961ea17e80498a7f79283c | 3c8e62036d3b7fc0e95236946369417cf976bd22 | |||
v1.0 | instruct | Filter | Filter_29577_I | Can you assist me in designing a Python program that performs encryption and decryption using a Caesar Cipher? | def caesar_cipher_encrypt(text, shift):
"""
Encrypts the given text using Caesar Cipher encryption with the specified shift.
Args:
text (str): The text to be encrypted.
shift (int): The number of positions to shift each character.
Returns:
str: The encrypted text.
"""
encry... | from solution import caesar_cipher_encrypt, caesar_cipher_decrypt
def test_encrypt_simple():
assert caesar_cipher_encrypt("HELLO", 3) == "KHOOR"
assert caesar_cipher_encrypt("hello", 3) == "khoor"
def test_decrypt_simple():
assert caesar_cipher_decrypt("KHOOR", 3) == "HELLO"
assert caesar_cipher_decry... | [
{
"docstring": "Encrypts the given text using Caesar Cipher encryption with the specified shift.\n\nArgs:\ntext (str): The text to be encrypted.\nshift (int): The number of positions to shift each character.\n\nReturns:\nstr: The encrypted text.",
"function_declaration": "def caesar_cipher_encrypt(text, shi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar Cipher with specified shift.\n \n Arguments:\n text -- the string to be encrypted\n shift -- ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029577",
"row_id": 29577,
"seed_ids": "['Qwen2-72B-Instruct_69666']"
} | 0.638118 | Filter_29577 | I | [
"caesar_cipher_encrypt",
"caesar_cipher_decrypt"
] | 2 | [
[
"caesar_cipher_decrypt",
"caesar_cipher_encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4fa0db497358d9aa154f00f05baaae01cfade651 | da52e01e268bf397ab8c4d123bc095c6f4fb8573 | |||
v1.0 | instruct | Filter | Filter_29593_I | Modify the following code to output Odd numbers from 1 to 1000 that are prime numbers, with the condition that the prime numbers should also be palindrome numbers. Additionally, the program should only use a single loop and should not use any built-in functions for checking primality or palindromicity. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5)+1, 2):
if n % i == 0:
return False
return True
def is_palindrome(n... | from solution import odd_prime_palindromes
def test_odd_prime_palindromes():
result = odd_prime_palindromes(1000)
expected_primes = [2, 3, 5, 7, 11, 101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929]
# Filtering by odd numbers
expected_odd_primes = [prime for prime in expected_p... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Helper function to check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n original_num = number\n reversed_num = 0\n while number > 0:\n remainder = number % 10\n reversed_num = reversed_num * 10 + remainder\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029593",
"row_id": 29593,
"seed_ids": "['Qwen2-72B-Instruct_69688']"
} | 0.656498 | Filter_29593 | I | [
"is_prime",
"is_palindrome",
"odd_prime_palindromes"
] | 3 | [
[
"odd_prime_palindromes",
"is_palindrome"
],
[
"odd_prime_palindromes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 99c69e165481fb240336ebd6b6016a8b790d3ddd | 1df6c16bc4d7e3f586759d0f93590edefb15b1a7 | |||
v1.0 | instruct | Filter | Filter_29604_I | Write a Python program to create a new list which contains all prime numbers from the given list, and sort them in descending order. If there are no prime numbers in the list, return an empty list. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def filter_and_sort_primes(lst):
"""
Returns a new list which contains all prim... | from solution import filter_and_sort_primes
def test_all_primes():
assert filter_and_sort_primes([2, 3, 5, 7, 11]) == [11, 7, 5, 3, 2]
def test_mixed_numbers():
assert filter_and_sort_primes([10, 1, 4, 3, 7, 6, 13]) == [13, 7, 3]
def test_no_primes():
assert filter_and_sort_primes([10, 1, 4, 6, 8]) =... | [
{
"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 new list which contains all prime numbers from the given list,\nsorted in descending order.",
... | [
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 a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even prime numbe... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029604",
"row_id": 29604,
"seed_ids": "['Qwen2-72B-Instruct_69710']"
} | 0.633936 | Filter_29604 | I | [
"is_prime",
"filter_and_sort_primes"
] | 2 | [
[
"filter_and_sort_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2cc40b7fbbd7d7f96d76d3559b37deafa2e70565 | 20b93ce1317df56c81c00c574e1c32d7d26e17c3 | |||
v1.0 | instruct | Filter | Filter_29605_I | Create a Python function that takes an array of strings and generates a dictionary with each string as a key and the number of vowels in the string as the value. | def count_vowels(s):
"""
Returns the number of vowels in a given string s.
"""
vowels = 'aeiouAEIOU'
return sum(1 for char in s if char in vowels)
def generate_vowel_dict(strings):
"""
Takes an array of strings and generates a dictionary with each string
as a key and the number of vowel... | from solution import count_vowels, generate_vowel_dict
def test_count_vowels_empty_string():
assert count_vowels('') == 0
def test_count_vowels_no_vowels():
assert count_vowels('bcdfg') == 0
def test_count_vowels_only_vowels():
assert count_vowels('aeiouAEIOU') == 10
def test_count_vowels_mixed_string()... | [
{
"docstring": "Returns the number of vowels in a given string s.",
"function_declaration": "def count_vowels(s):",
"function_name": "count_vowels",
"parameter_list": "(s)"
},
{
"docstring": "Takes an array of strings and generates a dictionary with each string\nas a key and the number of vo... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_vowels(s):\n \"\"\"Helper function to count the number of vowels in a string.\"\"\"\n vowels = 'aeiouAEIOU'\n return sum(1 for char in s if char in vowels)\n\ndef generate_v... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029605",
"row_id": 29605,
"seed_ids": "['Qwen2-72B-Instruct_69711']"
} | 0.79142 | Filter_29605 | I | [
"count_vowels",
"generate_vowel_dict"
] | 2 | [
[
"generate_vowel_dict",
"count_vowels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61eda968d36cd7b361447244fb45339232c1c226 | 78809ddae073f706c78b1ac5811724d81591738a | |||
v1.0 | instruct | Filter | Filter_29607_I | Create a for loop that prints the numbers 0 to 100 and prints if the number is a prime number or not. Additionally, the program should also calculate and display the sum of all prime numbers encountered during the loop. Implement this program using only a single for loop, without using any built-in functions or librari... | def is_prime(n):
"""
Helper function to check if a number is a prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes_and_sum():
"""
Prints numbers from 0 to 100 and indicates if they are prim... | from solution import primes_and_sum, is_prime
def test_is_prime():
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == Tr... | [
{
"docstring": "Helper function to check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints numbers from 0 to 100 and indicates if they are prime.\nAlso calculates and returns the sum of primes ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n is a prime number.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, n):\n if n % i == 0:\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029607",
"row_id": 29607,
"seed_ids": "['Qwen2-72B-Instruct_69713']"
} | 0.612211 | Filter_29607 | I | [
"is_prime",
"primes_and_sum"
] | 2 | [
[
"primes_and_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 66e8cb837cb622c56d855f425175f96dcb51a475 | 8b111c79e07d91f248b396e3946b3df8dfb9ba49 | |||
v1.0 | instruct | Filter | Filter_29610_I | Write a Python program that implements the Sieve of Eratosthenes to find all prime numbers within a given range. This range should be inputted by the user. Additionally, the program should display the time taken to execute the operation and space complexity involved. | import time
import math
def sieve_of_eratosthenes(n):
"""
Returns a list of all prime numbers up to n using the Sieve of Eratosthenes algorithm.
"""
if n < 2:
return []
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers.
for i in ran... | from solution import sieve_of_eratosthenes, find_primes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
assert sieve_of_eratosthenes(3) == [2, 3]
assert sieve_of_eratosthenes(20) == [2, 3... | [
{
"docstring": "Returns a list of all prime numbers up to n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def find_pr... | [
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 sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n primes = [True] * (n + 1)\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029610",
"row_id": 29610,
"seed_ids": "['Qwen2-72B-Instruct_69716']"
} | 0.613448 | Filter_29610 | I | [
"sieve_of_eratosthenes",
"find_primes"
] | 2 | [
[
"find_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7405a7749e15f516ab5df649d9d22cf658fde61e | b8231bd7be05be0f63e2c5a0a58253f9329fd97d | |||
v1.0 | instruct | Filter | Filter_29614_I | Create a random list of 10 prime numbers in the range of 100 to 1000 in Python, ensuring that all numbers in the list are unique and sorted in ascending order. | import random
def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def generate_prime_list(start, end, count):
"""
Generates a sorted lis... | from solution import is_prime, generate_prime_list, get_prime_list
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
def test_generate_prime_list():
primes = generate_prime_list(100, 1... | [
{
"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": "Generates a sorted list of unique prime numbers within a range.\n\n:param start: The starting range for gener... | [
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 n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029614",
"row_id": 29614,
"seed_ids": "['Qwen2-72B-Instruct_69725']"
} | 0.538281 | Filter_29614 | I | [
"is_prime",
"generate_prime_list",
"get_prime_list"
] | 3 | [
[
"generate_prime_list",
"is_prime"
],
[
"get_prime_list",
"generate_prime_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 14fbb5f676857b9eb27da6340c5ced57dc6e4a7d | 1fce71cf6ae962bc1745112608fdac3dcd0a827d | |||
v1.0 | instruct | Filter | Filter_29627_I | In Python, write a code snippet to calculate the average of prime numbers in a given list. | def is_prime(n):
"""
Check if a given number n 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 average_of_primes(numbers):
"""
Calculate the average of prime numbers in the given l... | from solution import is_prime, average_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
def test_average_of_prime... | [
{
"docstring": "Check if a given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the average of prime numbers in the given list.",
"function_declaration": "def average_of_primes(nu... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029627",
"row_id": 29627,
"seed_ids": "['Qwen2-72B-Instruct_69745']"
} | 0.633427 | Filter_29627 | I | [
"is_prime",
"average_of_primes"
] | 2 | [
[
"average_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d724813dd5ebc6100ef73471387634c7f3510c44 | 27528d501304e4d7ea93ea6dabab2794b5910e82 | |||
v1.0 | instruct | Filter | Filter_29650_I | I am using Ray-Tune for hyperparameter tuning in TensorFlow with the following command: `Analysis = tune.run(my_func, ..., name='trial_name')`. I would like to stop certain trials early based on their training loss, say if it is greater than a certain threshold. How can I achieve this through the `trial live info` that... | from ray import tune
from ray.tune import Stopper
import matplotlib.pyplot as plt
import os
class LossStopper(Stopper):
def __init__(self, threshold):
self.threshold = threshold
def __call__(self, trial_id, result):
return result["loss"] > self.threshold
def stop_all(self):
return... | from solution import LossStopper, run_tuning, plot_best_trials
import pytest
def test_loss_stopper():
stopper = LossStopper(threshold=0.5)
assert not stopper("trial_1", {"loss": 0.4})
assert stopper("trial_1", {"loss": 0.6})
def test_run_tuning_with_loss_stopper(monkeypatch):
def mock_tune_run(*args, ... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from ray import tune\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\n\ndef stop_trial(placement):\n def stop_condition(trial_id, result):\n return result[\"training_loss\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029650",
"row_id": 29650,
"seed_ids": "['Qwen2-72B-Instruct_69796']"
} | 0.341584 | Filter_29650 | I | [
"my_func",
"run_tuning",
"plot_best_trials"
] | 3 | [
[
"run_tuning",
"my_func"
]
] | 1 | [] | false | [
"LossStopper"
] | true | pytest | true | [
"matplotlib",
"ray"
] | false | f757126bc49460ae2fff80022c38ad658248ed8f | 5d7c1aae5ca7fcf2a9d544743001ca8461641756 | |||
v1.0 | instruct | Filter | Filter_29658_I | I have a Python script that generates a list of numbers. I need to modify it to filter out any numbers that are divisible by 3. However, I also want to check if the number is prime before excluding it. Can you help me with the correct code to accomplish this? | def is_prime(n):
"""
Returns True if the number n is prime, otherwise False.
"""
if n <= 1:
return False
if n == 2 or 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:
retur... | from solution import is_prime, filter_numbers
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_filter_numbers():
assert filter_numbers([1, 2, 3,... | [
{
"docstring": "Returns True if the number n is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of numbers that are not divisible by 3 unless they are prime.",
"function_declarati... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n 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": "00029658",
"row_id": 29658,
"seed_ids": "['Qwen2-72B-Instruct_69813']"
} | 0.640799 | Filter_29658 | I | [
"is_prime",
"filter_numbers"
] | 2 | [
[
"filter_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b2e663d0a35eb98038b9ad775712a2c83b6a9ee2 | 163b9a7f5f124a03bf408293c4098dd1ff63d90e | |||
v1.0 | instruct | Filter | Filter_29707_I | How can I generate the Fibonacci sequence efficiently up to the nth term using both recursive functions and dynamic programming in a program that can handle large inputs? Additionally, can you demonstrate how to display the resulting output in a formatted table that includes not only the index and value of each term, b... | import time
def fibonacci_recursive(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_seq = [0, 1]
def fib_recursive(k):
if k in memo:
return memo[k]
if k <= 1:
return k
... | from solution import fibonacci_recursive, fibonacci_dynamic, display_fibonacci
def test_fibonacci_recursive():
assert fibonacci_recursive(0) == []
assert fibonacci_recursive(1) == [0]
assert fibonacci_recursive(2) == [0, 1]
assert fibonacci_recursive(5) == [0, 1, 1, 2, 3]
def test_fibonacci_dynamic():... | [
{
"docstring": null,
"function_declaration": "def fibonacci_recursive(n):",
"function_name": "fibonacci_recursive",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def fibonacci_dynamic(n):",
"function_name": "fibonacci_dynamic",
"parameter_list": "(n)"
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nfrom collections import defaultdict\n\n# Recursive method with memoization for Fibonacci sequence\ndef fibonacci_recursive(n, memo=None):\n if memo is None:\n memo = {}\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029707",
"row_id": 29707,
"seed_ids": "['Qwen2-72B-Instruct_69892']"
} | 0.59238 | Filter_29707 | I | [
"fibonacci_recursive",
"fibonacci_dynamic",
"display_fibonacci"
] | 3 | [
[
"display_fibonacci",
"fibonacci_dynamic"
],
[
"display_fibonacci",
"fibonacci_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1691ea568bb8498d27475732fc205f439a8d0462 | 073f157bdeb8c33f7940183282106d0ab3787c50 | |||
v1.0 | instruct | Filter | Filter_29721_I | As a Python developer, I want to create a web spider that can search the web for "how to" guides and tutorials, but only scrape a small portion of the page to avoid copyright issues. How can I modify the given code to only scrape the introduction section of each article while still returning the article title, URL, and... | import requests
from bs4 import BeautifulSoup
def fetch_article_details(url):
"""
Fetches the title and introduction summary of the article from the given URL.
Args:
- url (str): The URL of the article to scrape.
Returns:
- dict: A dictionary containing the article's title, URL, and a... | import pytest
from solution import fetch_article_details, search_guides
def test_fetch_article_details():
article_details = fetch_article_details("https://example.com")
"""
To properly test this you should use a mock URL that contains a known page structure
"""
assert article_details is not None
... | [
{
"docstring": "Fetches the title and introduction summary of the article from the given URL.\n\nArgs:\n- url (str): The URL of the article to scrape.\n\nReturns:\n- dict: A dictionary containing the article's title, URL, and a summary of the introduction.",
"function_declaration": "def fetch_article_detail... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom bs4 import BeautifulSoup\n\ndef fetch_article_details(url):\n \"\"\"\n Fetches the title and introduction summary of the article from the given URL.\n \n Args... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029721",
"row_id": 29721,
"seed_ids": "['Qwen2-72B-Instruct_69910']"
} | 0.637722 | Filter_29721 | I | [
"fetch_article_details",
"search_guides"
] | 2 | [
[
"search_guides",
"fetch_article_details"
]
] | 1 | [] | false | [] | false | pytest | true | [
"bs4",
"requests"
] | false | 718af0f6f013318629f4543ab6c0f0ce8d78dda0 | e5db26c0e5729c9cedd08e2b102d5bb954562389 | |||
v1.0 | instruct | Filter | Filter_29723_I | Write a Python program to read in a sequence of integers from the user and print them out in reverse order. | def reverse_sequence(sequence):
"""
Returns the reversed sequence of integers.
"""
return sequence[::-1]
def get_sequence_from_user():
"""
Asks the user to input a sequence of integers separated by spaces and returns the list of integers.
"""
user_input = input("Enter a sequence of inte... | from solution import reverse_sequence
def test_reverse_sequence_empty():
assert reverse_sequence([]) == []
def test_reverse_sequence_single_element():
assert reverse_sequence([1]) == [1]
def test_reverse_sequence_two_elements():
assert reverse_sequence([1, 2]) == [2, 1]
def test_reverse_sequence_multipl... | [
{
"docstring": "Returns the reversed sequence of integers.",
"function_declaration": "def reverse_sequence(sequence):",
"function_name": "reverse_sequence",
"parameter_list": "(sequence)"
},
{
"docstring": "Asks the user to input a sequence of integers separated by spaces and returns the lis... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_sequence():\n \"\"\"\n Reads a sequence of integers from the user and prints them in reverse order.\n \"\"\"\n sequence = input(\"Enter a sequence of integers separated... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029723",
"row_id": 29723,
"seed_ids": "['Qwen2-72B-Instruct_69913']"
} | 0.647976 | Filter_29723 | I | [
"reverse_sequence",
"get_sequence_from_user"
] | 2 | [
[
"get_sequence_from_user",
"reverse_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 050b7710fee45e2c555c4ffa02cff011f44ceacc | 1f9fe3e4a353dc0e72ccc42f9e0fec65ec1a2732 | |||
v1.0 | instruct | Filter | Filter_29724_I | Develop a code to form a 5-dimensional tensor of size 3 x 3 x 3 x 3 x 3, filled with prime numbers ranging from 2 up to the maximum possible prime number that can be obtained considering the dimensions of the tensor. Also, ensure that your function handles the scenario when there are not enough prime numbers and throws... | import numpy as np
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def generate_primes(n):
... | import pytest
from solution import create_tensor, is_prime, generate_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
def test_generate_primes():
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def generate_primes(n):",
"function_name": "generate_primes",
"parameter_list": "(n)"
},
{
"docstring": n... | [
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 sympy\n\ndef generate_prime_tensor():\n \"\"\"\n Generates a 5-dimensional tensor of size 3 x 3 x 3 x 3 x 3 filled with prime numbers.\n If there are not en... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029724",
"row_id": 29724,
"seed_ids": "['Qwen2-72B-Instruct_69914']"
} | 0.559637 | Filter_29724 | I | [
"is_prime",
"generate_primes",
"create_tensor"
] | 3 | [
[
"create_tensor",
"generate_primes"
],
[
"generate_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 90b59fda5f651c69cf5866fbd5d241e7c446ea54 | 0039883fd788d659aa69ee79392885b6590f179f | |||
v1.0 | instruct | Filter | Filter_29753_I | Create a function that takes in two sorted arrays of integers and returns a new array containing the common elements between the two arrays. The function should handle arrays of any size and there should be no duplicate elements in the output. Additionally, the function should have a time complexity of O(log n), where ... | from bisect import bisect_left
def binary_search(arr, x):
"""
Helper function to perform binary search.
Returns True if x is found in arr, otherwise False.
"""
i = bisect_left(arr, x)
if i != len(arr) and arr[i] == x:
return True
return False
def common_elements(arr1, arr2):
""... | from solution import common_elements
def test_common_elements_basic():
assert common_elements([1, 2, 3], [2, 3, 4]) == [2, 3]
def test_common_elements_no_common():
assert common_elements([1, 2, 3], [4, 5, 6]) == []
def test_common_elements_identical():
assert common_elements([1, 2, 3], [1, 2, 3]) == [1, ... | [
{
"docstring": "Helper function to perform binary search.\nReturns True if x is found in arr, otherwise False.",
"function_declaration": "def binary_search(arr, x):",
"function_name": "binary_search",
"parameter_list": "(arr, x)"
},
{
"docstring": "Returns the common elements between two sor... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def common_elements(arr1, arr2):\n \"\"\"\n Returns a list of the common elements between the two sorted arrays \n without duplicates.\n \"\"\"\n # Convert arrays to sets\n s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029753",
"row_id": 29753,
"seed_ids": "['Qwen2-72B-Instruct_69963']"
} | 0.687732 | Filter_29753 | I | [
"binary_search",
"common_elements"
] | 2 | [
[
"common_elements",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e901422845cfe591c5516061dd15c5de65e42334 | c97c3d9d61eddfdbed624fd2bb24655fb688ea47 | |||
v1.0 | instruct | Filter | Filter_29759_I | Write a code that returns a 2-D array of size n by m containing all prime numbers where n and m are prime numbers greater than 2. n = 11 and m = 13 | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
re... | from solution import generate_prime_2d_array
def test_generate_prime_2d_array_dimension():
array = generate_prime_2d_array(11, 13)
assert len(array) == 11
assert all(len(row) == 13 for row in array)
def test_generate_prime_2d_array_prime_content():
array = generate_prime_2d_array(11, 13)
flat_list... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a 2-D array of size n by m containing prime numbers.",
"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(num):\n \"\"\"\n Check if a given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 o... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029759",
"row_id": 29759,
"seed_ids": "['Qwen2-72B-Instruct_69972']"
} | 0.645819 | Filter_29759 | I | [
"is_prime",
"generate_prime_2d_array"
] | 2 | [
[
"generate_prime_2d_array",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f887ee3e5aa3abc050ffba7d4ebde60d067f985f | 1426eb73ffe2fb0d8ad73f4cba06c22265b200e3 | |||
v1.0 | instruct | Filter | Filter_29768_I | Transform the following piece of code into a valid Python program that calculates the sum of two numbers, ensuring that the input is a valid positive integer and the sum is greater than 100. | def validate_positive_integer(value):
"""
Validates if the provided value is a positive integer.
Parameters:
value (int): The value to be validated.
Returns:
bool: True if the value is a positive integer, False otherwise.
"""
return isinstance(value, int) and value > 0
def cal... | from solution import validate_positive_integer, calculate_sum
def test_validate_positive_integer():
assert validate_positive_integer(5) == True
assert validate_positive_integer(-1) == False
assert validate_positive_integer(0) == False
assert validate_positive_integer("string") == False
assert valid... | [
{
"docstring": "Validates if the provided value is a positive integer.\n\nParameters:\nvalue (int): The value to be validated.\n\nReturns:\nbool: True if the value is a positive integer, False otherwise.",
"function_declaration": "def validate_positive_integer(value):",
"function_name": "validate_positi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_greater_than_100(num1, num2):\n \"\"\"\n Returns the sum of num1 and num2 if both are positive integers and the sum is greater than 100.\n Raises ValueError otherwise.\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029768",
"row_id": 29768,
"seed_ids": "['Qwen2-72B-Instruct_69983']"
} | 0.567256 | Filter_29768 | I | [
"validate_positive_integer",
"calculate_sum"
] | 2 | [
[
"calculate_sum",
"validate_positive_integer"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c408d3a823b67bfcb3b4a87233df8a5595a7c924 | 3beb38ba761c3dcb2dee847ec9a6bf7790aa3111 | |||
v1.0 | instruct | Filter | Filter_29787_I | How can I develop a Python program to print out the most recent prime numbers that are less than a provided input number? | def is_prime(n):
"""
Return True if the number is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True... | from solution import is_prime, find_primes_less_than
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(11) == True
def test_find_primes_less_than():
assert find_prim... | [
{
"docstring": "Return True if the number is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return a list of all prime numbers less than the given number n.",
"function_declaration": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Return True if the number is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029787",
"row_id": 29787,
"seed_ids": "['Qwen2-72B-Instruct_70017']"
} | 0.72018 | Filter_29787 | I | [
"is_prime",
"find_primes_less_than"
] | 2 | [
[
"find_primes_less_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b528961bec735d4927681dff06508db48ee2c2e3 | 94188811196369c1c0f276865b87c3f7b900a543 | |||
v1.0 | instruct | Filter | Filter_29793_I | Create a program that determines whether a given number is a prime and prints all the prime numbers between 1 and the given number. Additionally, the program should handle large numbers efficiently and provide an optimized solution that has a time complexity of O(sqrt(n)). | import math
def is_prime(n):
"""
Determines whether a given number n is a prime.
"""
if n <= 1:
return False
if n == 2 or 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:
... | from solution import is_prime, primes_up_to
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(25) == False
assert is_prime(31) == True
def test_primes_up_to():
a... | [
{
"docstring": "Determines whether a given number n is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from 1 to n.",
"function_declaration": "def primes_up_to(n):",
"functi... | [
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 Determines if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029793",
"row_id": 29793,
"seed_ids": "['Qwen2-72B-Instruct_70029']"
} | 0.652235 | Filter_29793 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | da4994ba70f08f3d7c3b49d80e13d00a40fd8ba3 | fa7d56e2ebdcee0c2e21ec2f550ef38814cdc399 | |||
v1.0 | instruct | Filter | Filter_29794_I | Write a function called `fibonacci_slice` that takes in two parameters: `sequence` (a list or tuple of integers) and `n` (an integer). The function should return a new list containing the first `n` elements of the `sequence` that are Fibonacci numbers. | def is_fibonacci(num):
"""
Helper function to check if a number is a Fibonacci number.
"""
a, b = 0, 1
while b < num:
a, b = b, a + b
return b == num or a == num
def fibonacci_slice(sequence, n):
"""
Returns the first n elements of the sequence that are Fibonacci numbers.
""... | from solution import fibonacci_slice
def test_fibonacci_numbers():
seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
assert fibonacci_slice(seq, 5) == [0, 1, 1, 2, 3]
def test_mixed_numbers():
seq = [10, 4, 5, 6, 7, 8, 13, 20, 21, 34, 56]
assert fibonacci_slice(seq, 4) == [5, 8, 13, 21]
def test_no_fib... | [
{
"docstring": "Helper function to check if a number is a Fibonacci number.",
"function_declaration": "def is_fibonacci(num):",
"function_name": "is_fibonacci",
"parameter_list": "(num)"
},
{
"docstring": "Returns the first n elements of the sequence that are Fibonacci numbers.",
"functi... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_fibonacci(num):\n \"\"\"\n Checks if a number is a Fibonacci number.\n \"\"\"\n if num <= 0:\n return False\n a, b = 0, 1\n while b < num:\n a, b = b, a ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029794",
"row_id": 29794,
"seed_ids": "['Qwen2-72B-Instruct_70031']"
} | 0.755855 | Filter_29794 | I | [
"is_fibonacci",
"fibonacci_slice"
] | 2 | [
[
"fibonacci_slice",
"is_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0aa60ddd01e0e41ac6e4b174795b01eff9328ecd | 61f26355a03ba5ba331749d91e0b11ae0c8d4669 | |||
v1.0 | instruct | Filter | Filter_29805_I | Formulate a for loop in Python that traverses a two-dimensional array. However, instead of simply printing each item, your task is to implement a function that identifies if each element is a prime number or not. If the element is a prime number, print out its position in the array along with the number. Consider the a... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return F... | from solution import is_prime, traverse_and_check_primes
def test_is_prime_with_primes():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(5) is True
assert is_prime(11) is True
def test_is_prime_with_non_primes():
assert is_prime(0) is False
assert is_prime(1) is False
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Traverses a 2D array (matrix). For each element, checks if it is a prime number.\nIf the element is a pr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is a prime number\n if ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029805",
"row_id": 29805,
"seed_ids": "['Qwen2-72B-Instruct_70047']"
} | 0.640745 | Filter_29805 | I | [
"is_prime",
"traverse_and_check_primes"
] | 2 | [
[
"traverse_and_check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 324f7364375b079fe4434e9a3f8328456042cf56 | eef5c365e06f5906b73ddf47336bf796673127fa | |||
v1.0 | instruct | Filter | Filter_29812_I | Design an algorithm that can identify and highlight all palindromic substrings within a given string. For example, if the input string is "racecar", the algorithm should output all palindromic substrings such as "aceca", "cec", "a", "c", "e", "r". | def is_palindrome(s):
"""
Helper function to check if a given string is a palindrome.
"""
return s == s[::-1]
def find_palindromic_substrings(s):
"""
Returns a list of all palindromic substrings in the given string s.
"""
n = len(s)
palindromic_substrings = []
for i in range(n)... | from solution import is_palindrome, find_palindromic_substrings
def test_is_palindrome():
assert is_palindrome("racecar")
assert is_palindrome("a")
assert is_palindrome("aa")
assert not is_palindrome("abc")
def test_find_palindromic_substrings():
assert set(find_palindromic_substrings("racecar")) ... | [
{
"docstring": "Helper function to check if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns a list of all palindromic substrings in the given string s.",
"function_decl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palindromic_substrings(s):\n \"\"\"\n Retur... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029812",
"row_id": 29812,
"seed_ids": "['Qwen2-72B-Instruct_70059']"
} | 0.682676 | Filter_29812 | I | [
"is_palindrome",
"find_palindromic_substrings"
] | 2 | [
[
"find_palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 381e056d4a006f3b1d749216aebc79507e3db565 | 7316004e004ecdefc660833bd9a9306bc64afcf3 | |||
v1.0 | instruct | Filter | Filter_29820_I | Compose a Python algorithm that extracts prime numbers from a provided series of numerical values, including an evaluation for the code's efficiency and its space complexity. | def is_prime(n):
"""
Helper function to check if a number n 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 extract_p... | from solution import extract_primes
def test_extract_primes_empty_list():
assert extract_primes([]) == []
def test_extract_primes_zeros_and_ones():
assert extract_primes([0, 1, 0, 1]) == []
def test_extract_primes_no_primes():
assert extract_primes([4, 6, 8, 10, 15]) == []
def test_extract_primes_all_pr... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to extract prime numbers from a provided series of numerical values.\n\nParameters:\nnumbers (list):... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Checks if a number n is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return Fa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029820",
"row_id": 29820,
"seed_ids": "['Qwen2-72B-Instruct_70074']"
} | 0.571954 | Filter_29820 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 794e9792726e18af843814ad771be20e68f3b191 | 3c9a4fe1bb75e3ab876ca126dbd51e8a693f957a | |||
v1.0 | instruct | Filter | Filter_29828_I | In the pursuit of developing a Python program that reads a text file and counts the frequency of each word, I'm encountering an issue: the code is not handling punctuation and case sensitivity correctly, leading to inaccurate results. Could you propose a method to preprocess the text so that words are separated, punctu... | import string
def preprocess_text(text):
"""
Preprocess the input text by converting it to lowercase, removing punctuation,
and returning a list of words.
"""
# Convert text to lowercase
text = text.lower()
# Remove punctuation
text = text.translate(str.maketrans('', '', string.pun... | from solution import preprocess_text, count_word_frequencies
def test_preprocess_text():
assert preprocess_text("Hello, World!") == ["hello", "world"]
assert preprocess_text("Python's awesome.") == ["pythons", "awesome"]
assert preprocess_text("Test, test; TEST!") == ["test", "test", "test"]
assert pre... | [
{
"docstring": "Preprocess the input text by converting it to lowercase, removing punctuation,\nand returning a list of words.",
"function_declaration": "def preprocess_text(text):",
"function_name": "preprocess_text",
"parameter_list": "(text)"
},
{
"docstring": "Counts the frequency of eac... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import Counter\n\ndef preprocess_text(text):\n \"\"\"\n Preprocess the text to remove punctuation, convert to lowercase and split into words.\n \n :para... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029828",
"row_id": 29828,
"seed_ids": "['Qwen2-72B-Instruct_70090']"
} | 0.702095 | Filter_29828 | I | [
"preprocess_text",
"count_word_frequencies"
] | 2 | [
[
"count_word_frequencies",
"preprocess_text"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0a157c3191a3285317094e30a49e1eaad231cd71 | 03584f2d713ff0fea5a2cba394eeee49cf539903 | |||
v1.0 | instruct | Filter | Filter_29844_I | Given two matrices of size `m x n`, find their transpose using Python. Additionally, implement matrix multiplication of the original matrices and their transposes, handling any potential dimension mismatches yourself. Use list comprehension, no library imports should be used for this task. | def transpose(matrix):
"""
Returns the transpose of the given matrix.
"""
return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]
def can_multiply_matrices(mat1, mat2):
"""
Checks if two matrices can be multiplied.
"""
return len(mat1[0]) == len(mat2)
def mul... | from solution import transpose, can_multiply_matrices, multiply_matrices
def test_transpose_square_matrix():
mat = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
assert transpose(mat) == expected
def test_transpose... | [
{
"docstring": "Returns the transpose of the given matrix.",
"function_declaration": "def transpose(matrix):",
"function_name": "transpose",
"parameter_list": "(matrix)"
},
{
"docstring": "Checks if two matrices can be multiplied.",
"function_declaration": "def can_multiply_matrices(mat1... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def transpose(matrix):\n \"\"\"\n Returns the transpose of the given matrix.\n \"\"\"\n return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]\n\ndef ca... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029844",
"row_id": 29844,
"seed_ids": "['Qwen2-72B-Instruct_70118']"
} | 0.495469 | Filter_29844 | I | [
"transpose",
"can_multiply_matrices",
"multiply_matrices"
] | 3 | [
[
"multiply_matrices",
"can_multiply_matrices"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 29a7e56508429a7bf9fb623ec9fdbbcbbeb4be72 | 2f7635f69a2c819b48744b6994bcaf11208fed48 | |||
v1.0 | instruct | Filter | Filter_29849_I | Create a fragment of code that is intended to evaluate whether a provided number is a perfect square or not. Your code must handle large numbers up to 2^64. Also, provide a function to calculate the square root (no use of library function) and incorporate error handling for non-integer or negative inputs. | def is_perfect_square(n):
"""
Determine whether n is a perfect square.
Returns True if n is a perfect square, otherwise False.
"""
if not isinstance(n, int) or n < 0:
raise ValueError("Input must be a non-negative integer.")
root = int(find_sqrt(n))
return root * root == n
def ... | from solution import is_perfect_square, find_sqrt
def test_is_perfect_square():
assert is_perfect_square(4) == True
assert is_perfect_square(16) == True
assert is_perfect_square(1) == True
assert is_perfect_square(0) == True
assert is_perfect_square(25) == True
assert is_perfect_square(26) == F... | [
{
"docstring": "Determine whether n is a perfect square.\nReturns True if n is a perfect square, otherwise False.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Computes the square root of a non-negative... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_perfect_square(n):\n \"\"\"\n Checks if the given number is a perfect square.\n\n :param n: int - the number to check\n :return: bool - True if n is a perfect square, False ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029849",
"row_id": 29849,
"seed_ids": "['Qwen2-72B-Instruct_70131']"
} | 0.637863 | Filter_29849 | I | [
"is_perfect_square",
"find_sqrt"
] | 2 | [
[
"is_perfect_square",
"find_sqrt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6e85f52d96186c9e0dc4ab2f01dc16502f18d1e | b2f6c06b78fc2e369b728f87c0dab137a1946936 | |||
v1.0 | instruct | Filter | Filter_29889_I | Write a program to sort a list of integers in ascending order without using any built-in sort functions or methods. Additionally, implement the sorting algorithm with a time complexity of O(n log n), and space complexity of O(1). | def heapify(arr, n, i):
largest = i
left = 2 * i + 1
right = 2 * i + 2
if left < n and arr[left] > arr[largest]:
largest = left
if right < n and arr[right] > arr[largest]:
largest = right
if largest != i:
arr[i], arr[largest] = arr[largest], arr[i]
heapify(... | from solution import heap_sort
def test_heap_sort_single_element():
assert heap_sort([1]) == [1]
def test_heap_sort_already_sorted():
assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_heap_sort_reverse_sorted():
assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_heap_sort_unsorted... | [
{
"docstring": null,
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": null,
"function_declaration": "def heap_sort(arr):",
"function_name": "heap_sort",
"parameter_list": "(arr)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heapify(arr, n, i):\n # Transform subtree rooted at index i into a max heap\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n \n # See if left child of root exists a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029889",
"row_id": 29889,
"seed_ids": "['Qwen2-72B-Instruct_70199']"
} | 0.610872 | Filter_29889 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 41e38973588a4795c8d9273e11ca432cb5613dd0 | b2b7174cdedc280516d8d8dad58ab7f3a3380d4d | |||
v1.0 | instruct | Filter | Filter_29891_I | Write a code to calculate the age of a person given their date of birth (year, month, and day), and also account for leap years. Additionally, include a validation check for the input dates to ensure they are valid (i.e., ensure the given month is not greater than 12, the day is appropriate for the given month, and the... | from datetime import date
def is_leap_year(year):
"""
Checks if a given year is a leap year.
"""
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
def validate_date(year, month, day):
"""
Validates if the given year, month and day form a valid date.
"""
if month < 1 or mo... | import pytest
from solution import calculate_age, validate_date, is_leap_year
def test_is_leap_year():
assert is_leap_year(2000) == True
assert is_leap_year(1900) == False
assert is_leap_year(2004) == True
assert is_leap_year(2001) == False
def test_validate_date():
assert validate_date(2023, 10, ... | [
{
"docstring": "Checks if a given year is a leap year.",
"function_declaration": "def is_leap_year(year):",
"function_name": "is_leap_year",
"parameter_list": "(year)"
},
{
"docstring": "Validates if the given year, month and day form a valid date.",
"function_declaration": "def validate... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef calculate_age(year, month, day):\n \"\"\"\n Calculate the age of a person given their date of birth.\n \n Parameters:\n year (int): Year of ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029891",
"row_id": 29891,
"seed_ids": "['Qwen2-72B-Instruct_70204']"
} | 0.571662 | Filter_29891 | I | [
"is_leap_year",
"validate_date",
"calculate_age"
] | 3 | [
[
"calculate_age",
"validate_date"
],
[
"validate_date",
"is_leap_year"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b579c9c458947a588cba84a554255e138e2f25c1 | aa3006662bbdfb834daf970429f4514477656bd1 | |||
v1.0 | instruct | Filter | Filter_29922_I | Create a python program to input an integer and find the next number which is a palindrome and also a prime number. | import math
def is_palindrome(num):
"""
Checks if a number is a palindrome.
"""
return str(num) == str(num)[::-1]
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
... | from solution import is_palindrome, is_prime, next_palindrome_prime
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(122) == False
assert is_palindrome(12321) == True
assert is_palindrome(12345) == False
def test_is_prime():
assert is_prime(2) == True
assert is_... | [
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_pr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_palindrome(num):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef is_prime(num):\n \"\"\"\n Checks if ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029922",
"row_id": 29922,
"seed_ids": "['Qwen2-72B-Instruct_70252']"
} | 0.649116 | Filter_29922 | I | [
"is_palindrome",
"is_prime",
"next_palindrome_prime"
] | 3 | [
[
"next_palindrome_prime",
"is_palindrome"
],
[
"next_palindrome_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7a57d76e463054557eff5f74d66cd05590bb189a | 6def294c696f8c7490e08967d4052738a8d2d63a | |||
v1.0 | instruct | Filter | Filter_29955_I | Implement a parallel (thread-based) version of the sequential algorithm to generate the first n prime numbers in Python. | import threading
def is_prime(num):
"""Returns True if the number is prime, else False."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import generate_primes
def test_generate_first_5_primes():
assert generate_primes(5) == [2, 3, 5, 7, 11]
def test_generate_first_10_primes():
assert generate_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_generate_first_prime():
assert generate_primes(1) == [2]
def test_no_pri... | [
{
"docstring": "Returns True if the number is prime, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates the first n prime numbers using a parallel approach.",
"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": "import threading\n\ndef is_prime(num):\n \"\"\"Returns True if the number is prime, else False.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029955",
"row_id": 29955,
"seed_ids": "['Qwen2-72B-Instruct_70301']"
} | 0.533951 | Filter_29955 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d2fed549bc69e13facf832c14346c936317d80f | 09a4882344d4b37bf88020012e94611a834a8652 | |||
v1.0 | instruct | Filter | Filter_29962_I | Devise a Python function that determines if the number of divisors for a given number is odd, compiles a list of these divisors, calculates the product of these divisors, and identifies the lowest composite number among the divisors. The function should handle edge cases, such as when the number is 0 or 1, and manage s... | import math
from functools import reduce
def is_odd_count_divisors(n):
"""
Determines if the number of divisors is odd, compiles a list of these divisors,
calculates the product of these divisors, and identifies the lowest composite number among the divisors.
Returns a tuple (is_odd_divisors, divisors... | from solution import is_odd_count_divisors, is_prime
def test_is_odd_count_divisors_with_0():
assert is_odd_count_divisors(0) == (False, [], 0, None)
def test_is_odd_count_divisors_with_1():
assert is_odd_count_divisors(1) == (True, [1], 1, None)
def test_is_odd_count_divisors_with_prime_number():
result... | [
{
"docstring": "Determines if the number of divisors is odd, compiles a list of these divisors, \ncalculates the product of these divisors, and identifies the lowest composite number among the divisors.\nReturns a tuple (is_odd_divisors, divisors_list, product_of_divisors, lowest_composite_divisor).",
"func... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef is_odd_count_divisors(n):\n \"\"\"\n Determines if the number of divisors is odd, compiles a list of these divisors, \n calculates the... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029962",
"row_id": 29962,
"seed_ids": "['Qwen2-72B-Instruct_70317']"
} | 0.732689 | Filter_29962 | I | [
"is_odd_count_divisors",
"is_prime"
] | 2 | [
[
"is_odd_count_divisors",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 78aed2e9b74adcd701e38eacb208fc57925d629a | a0f84d424574676e90a8790a56fa14fb93540a3e | |||
v1.0 | instruct | Filter | Filter_29977_I | Generate 5 random strings of length 10 in Python. Each string should include at least one uppercase letter, one lowercase letter, and one digit. | import random
import string
def generate_random_string():
"""
Generates a random string of length 10 containing at least one uppercase letter,
one lowercase letter, and one digit.
"""
upper = random.choice(string.ascii_uppercase)
lower = random.choice(string.ascii_lowercase)
digit = random.... | import string
from solution import generate_random_string, generate_random_strings
def test_length_of_string():
assert len(generate_random_string()) == 10
def test_contains_uppercase():
result = generate_random_string()
assert any(char.isupper() for char in result)
def test_contains_lowercase():
resu... | [
{
"docstring": "Generates a random string of length 10 containing at least one uppercase letter,\none lowercase letter, and one digit.",
"function_declaration": "def generate_random_string():",
"function_name": "generate_random_string",
"parameter_list": "()"
},
{
"docstring": "Generates n r... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_random_string(length=10):\n \"\"\"\n Generate a random string of given length which includes\n at least one uppercase letter, one lowercas... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029977",
"row_id": 29977,
"seed_ids": "['Qwen2-72B-Instruct_70339']"
} | 0.718709 | Filter_29977 | I | [
"generate_random_string",
"generate_random_strings"
] | 2 | [
[
"generate_random_strings",
"generate_random_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eae0150756d593ddde9da0c8ffbd22ff3871311f | 6cb74a5a017d560cc8a1fe7f8b0f8c6d37603173 | |||
v1.0 | instruct | Filter | Filter_30021_I | Use Python to filter out all the prime numbers from a given list of integers. Additionally, handle any errors that may occur during the filtering process and provide appropriate error messages to the user. However, you are not allowed to use any built-in functions or libraries to check if a number is prime. You must im... | def is_prime(n):
"""
Determines if a number is prime.
"""
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
def filter_primes(numbers):
"""
Filters out the prime numbers from a list of integers.
Parameters:
num... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_filter_primes():
... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out the prime numbers from a list of integers.\n\nParameters:\nnumbers (list): List of integers to filter.\n\nReturns... | [
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 Determines if a number is prime.\n\n Args:\n n (int): The number to check.\n\n Returns:\n bool: True if the number is prime, False otherwise.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030021",
"row_id": 30021,
"seed_ids": "['Qwen2-72B-Instruct_70422']"
} | 0.754306 | Filter_30021 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 503714b3ff924b09bffa800cb2b5552fd901cc66 | c0407140c9a10a6d8686b621f092560d7707d54c | |||
v1.0 | instruct | Filter | Filter_30092_I | Devise an algorithm to validate whether a specific array of integers represents a palindromic sequence. Additionally, implement a function checks if it's a perfect square palindrome sequence. Provide proper documentation and testing for your code. | def is_palindrome(arr):
"""
Returns True if the given array of integers is a palindrome, otherwise False.
A palindrome array reads the same backward as forward.
:param arr: List[int], the array to check
:return: bool, True if the array is a palindrome, otherwise False
"""
return arr == ... | from solution import is_palindrome, is_perfect_square, is_perfect_square_palindrome
def test_is_palindrome():
assert is_palindrome([1, 2, 3, 2, 1]) == True
assert is_palindrome([1, 2, 3, 4, 5]) == False
assert is_palindrome([1, 2, 2, 1]) == True
assert is_palindrome([1]) == True
assert is_palindrom... | [
{
"docstring": "Returns True if the given array of integers is a palindrome, otherwise False.\nA palindrome array reads the same backward as forward.\n\n:param arr: List[int], the array to check\n:return: bool, True if the array is a palindrome, otherwise False",
"function_declaration": "def is_palindrome(a... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_palindromic_sequence(arr):\n \"\"\"\n Check if the given array is a palindromic sequence.\n \n Parameters:\n arr (list): List of integers\n \n Return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030092",
"row_id": 30092,
"seed_ids": "['Qwen2-72B-Instruct_70527']"
} | 0.654004 | Filter_30092 | I | [
"is_palindrome",
"is_perfect_square",
"is_perfect_square_palindrome"
] | 3 | [
[
"is_perfect_square_palindrome",
"is_palindrome"
],
[
"is_perfect_square_palindrome",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | de5dd8caf7f5412a7c223bff5ebf519ad565a420 | 339b709864840c93623981b8676df30dd98b27e6 | |||
v1.0 | instruct | Filter | Filter_30102_I | Technical Interview: Explain merge sort algorithm and provide a piece of erroneous code that could potentially break the algorithm. | def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left = merge_sort(arr[:mid])
right = merge_sort(arr[mid:])
return merge(left, right)
def merge(left, right):
result = []
while left and right:
if left[0] <= right[0]:
result.append(left[0])
... | from solution import merge_sort
def test_merge_sort_with_positive_numbers():
assert merge_sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [1, 1, 2, 3, 4, 5, 5, 6, 9]
def test_merge_sort_with_negative_numbers():
assert merge_sort([-3, -1, -4, -1, -5, -9, -2, -6, -5]) == [-9, -6, -5, -5, -4, -3, -2, -1, -1]
def test_merg... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def merge(left, right):",
"function_name": "merge",
"parameter_list": "(left, right)"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n if len(arr) <= 1:\n return arr\n mid = len(arr) // 2\n left_half = merge_sort(arr[:mid])\n right_half = merge_sort(arr[mid:])\n return merge(left_h... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030102",
"row_id": 30102,
"seed_ids": "['Qwen2-72B-Instruct_70542']"
} | 0.544016 | Filter_30102 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eddd2959a90c47b11f596b9abba2fd8678069b3f | 864d7b4cda9b42143e29b1bf6ff9d85c6abbb3b0 | |||
v1.0 | instruct | Filter | Filter_30108_I | Develop a Python program that not only calculates the factorial of the each element present in a provided list, but also handles potential exceptions in case the list contains elements that are not integers or elements that are negative. Start your list as integers=[3,5,2,'a',-3,10]. | def calculate_factorial(n):
"""
Returns the factorial of a non-negative integer n.
"""
if not isinstance(n, int) or n < 0:
raise ValueError("n must be a non-negative integer")
if n == 0 or n == 1:
return 1
factorial = 1
for i in range(2, n + 1):
factorial *=... | from solution import calculate_factorial, factorial_list
def test_calculate_factorial():
assert calculate_factorial(3) == 6
assert calculate_factorial(0) == 1
assert calculate_factorial(1) == 1
assert calculate_factorial(5) == 120
def test_calculate_factorial_invalid_input():
try:
calculat... | [
{
"docstring": "Returns the factorial of a non-negative integer n.",
"function_declaration": "def calculate_factorial(n):",
"function_name": "calculate_factorial",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list of factorials of these integers.\nHandles... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef factorial_list(integers):\n \"\"\"\n Calculates the factorial for each integer in the provided list.\n For non-integer or negative values, it returns an error messa... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030108",
"row_id": 30108,
"seed_ids": "['Qwen2-72B-Instruct_70550']"
} | 0.600051 | Filter_30108 | I | [
"calculate_factorial",
"factorial_list"
] | 2 | [
[
"factorial_list",
"calculate_factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 72bf3acc6580e4456699c1480626a2d1b7369515 | d18672b2dc8c7ff006237f4b382e85d4d91cdd37 | |||
v1.0 | instruct | Filter | Filter_30114_I | Develop a Python script to generate 10 distinct random alphanumeric strings each of length 15. Furthermore, you should ensure that every generated string contains at least two digits and three uppercase letters. Validate each string to confirm the compliance before adding it to the final list. | import random
import string
def generate_random_string():
while True:
# Generates a random string of length 15
str_random = ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=15))
# Checks if it has at least 2 digits and 3 uppercase letters
if ... | from solution import generate_random_string, generate_list_of_random_strings
def test_generate_random_string_length():
random_str = generate_random_string()
assert len(random_str) == 15
def test_generate_random_string_digits():
random_str = generate_random_string()
assert sum(c.isdigit() for c in rand... | [
{
"docstring": null,
"function_declaration": "def generate_random_string():",
"function_name": "generate_random_string",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def generate_list_of_random_strings(n):",
"function_name": "generate_list_of_random_strings... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_random_string(length=15, min_digits=2, min_uppercase=3):\n \"\"\"\n Generates a random alphanumeric string of a given length that contains\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030114",
"row_id": 30114,
"seed_ids": "['Qwen2-72B-Instruct_70559']"
} | 0.697059 | Filter_30114 | I | [
"generate_random_string",
"generate_list_of_random_strings"
] | 2 | [
[
"generate_list_of_random_strings",
"generate_random_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7b4526b4b300ce548a1c0fa897ec2aae6dcef473 | 31652391e930764337a04f1eac4fa883e938b877 | |||
v1.0 | instruct | Filter | Filter_30146_I | Suppose I'm presented with two distinct arrays of whole numbers, could you devise a Python script that identifies every number from both lists that fall under the Fibonacci sequence? | def is_fibonacci(n):
"""
Helper function to check if a given number n is a Fibonacci number.
A number is a Fibonacci number if and only if one of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
"""
if n < 0:
return False
x1 = 5 * (n ** 2) + 4
x2 = 5 * (n ** 2) - 4
def is_perfect... | from solution import is_fibonacci, find_fibonacci_numbers
def test_is_fibonacci():
assert is_fibonacci(0) == True
assert is_fibonacci(1) == True
assert is_fibonacci(2) == True
assert is_fibonacci(3) == True
assert is_fibonacci(4) == False
assert is_fibonacci(5) == True
assert is_fibonacci(1... | [
{
"docstring": "Helper function to check if a given number n is a Fibonacci number.\nA number is a Fibonacci number if and only if one of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.",
"function_declaration": "def is_fibonacci(n):",
"function_name": "is_fibonacci",
"parameter_list": "(n)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_fibonacci(n):\n \"\"\"\n Checks if a number is a Fibonacci number.\n \"\"\"\n if n < 0: \n return False\n # Check if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030146",
"row_id": 30146,
"seed_ids": "['Qwen2-72B-Instruct_70614']"
} | 0.484592 | Filter_30146 | I | [
"is_fibonacci",
"find_fibonacci_numbers"
] | 2 | [
[
"find_fibonacci_numbers",
"is_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 287fd6ccf96bfb3d8bfe12966756fe638366ca01 | 2918d7571d439aede7fd3d9ac946d58d37378f56 | |||
v1.0 | instruct | Filter | Filter_30152_I | Please provide me with a Python code snippet that converts an image to JPG format using the Pillow library. The code must have an additional requirement where the image variable has to be greater than 1MB in size, and it must also include a function that checks the image's size before conversion. I expect the code to h... | from PIL import Image
import os
def check_image_size(image_path):
"""
Checks if the image size is greater than 1MB.
"""
image_size = os.path.getsize(image_path)
if image_size <= (1 * 1024 * 1024):
raise ValueError("Image size is less than 1MB")
return image_size
def convert_to_jpg(imag... | import os
import pytest
from PIL import Image
from solution import check_image_size, convert_to_jpg
def create_test_image(path, size):
"""
Creates a blank image with the specified size for testing purposes.
:param path: Path to save the image
:param size: Size of the image in bytes
"""
img... | [
{
"docstring": "Checks if the image size is greater than 1MB.",
"function_declaration": "def check_image_size(image_path):",
"function_name": "check_image_size",
"parameter_list": "(image_path)"
},
{
"docstring": "Converts the given image to JPG format if its size is greater than 1MB.\n\n:pa... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from PIL import Image\nimport os\n\ndef convert_to_jpg(image_path, output_filename='image.jpg'):\n \"\"\"\n Converts an image to JPG format and saves it with the specified filename.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030152",
"row_id": 30152,
"seed_ids": "['Qwen2-72B-Instruct_70623']"
} | 0.519606 | Filter_30152 | I | [
"check_image_size",
"convert_to_jpg"
] | 2 | [
[
"convert_to_jpg",
"check_image_size"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | 4792a70f7511d874230f27bec6f3b74360e06083 | c5d360058cf38c725e1dff4106a850df47d681b0 | |||
v1.0 | instruct | Filter | Filter_30153_I | Given the URL http://www.linkedin.com/home/profile? whose segments are separated by the forward slash ('/'), create a Python function that not only condenses the URL to its shortest possible length, but also returns a dictionary showing all the hierarchy of the URL segments with their corresponding positions along with... | def condense_url(url):
"""
Condenses the URL to its shortest possible length and returns a dictionary
showing all the hierarchy of the URL segments with their corresponding positions.
Args:
url (str): The URL to condense.
Returns:
tuple: A condensed string of the URL and dictionary of URL... | from solution import condense_url, top_n_segments
def test_condense_url_basic():
url = "http://www.linkedin.com/home/profile?"
condensed, hierarchy = condense_url(url)
assert condensed == "http:/www.linkedin.com/home/profile?"
assert hierarchy == {
1: "http:",
2: "www.linkedin.com",
... | [
{
"docstring": "Condenses the URL to its shortest possible length and returns a dictionary \nshowing all the hierarchy of the URL segments with their corresponding positions.\n\nArgs:\nurl (str): The URL to condense.\n\nReturns:\ntuple: A condensed string of the URL and dictionary of URL segments.",
"functi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from urllib.parse import urlparse, parse_qs\n\ndef condense_url(url):\n \"\"\"\n Condenses the given URL to its shortest possible length, and returns a dictionary \n showing the hiera... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030153",
"row_id": 30153,
"seed_ids": "['Qwen2-72B-Instruct_70625']"
} | 0.502425 | Filter_30153 | I | [
"condense_url",
"top_n_segments"
] | 2 | [
[
"top_n_segments",
"condense_url"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e362bdcc2b77e871cf1b2b412a864c3a80589d0 | 25dd4bf4f38518b66e6c3170f662c40cf1b70b79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.