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_27624_I | Develop a recursive function to calculate the product of all prime numbers in an array. The function also needs to incorporate error handling for cases where the array is empty or contains non-integer or negative values. Furthermore, ensure that the recursive function can handle large arrays without running into stack ... | def is_prime(n):
"""Helper function to check if a number is 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:
return False
i +... | from solution import product_of_primes
def test_empty_array():
try:
product_of_primes([])
except ValueError as e:
assert str(e) == "Array is empty"
def test_non_integer_values():
try:
product_of_primes([2, 3, "5", 7])
except ValueError as e:
assert str(e) == "Array cont... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the product of all prime numbers in the array.\nRaises ValueError if the array is empty or contains non... | [
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 Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027624",
"row_id": 27624,
"seed_ids": "['Qwen2-72B-Instruct_66458']"
} | 0.572693 | Filter_27624 | I | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd9e533cc74c1da6813ed0b0a49006f7da91a993 | 6b44eae9f4afb442da3403ed374f24638e0f7c8f | |||
v1.0 | instruct | Filter | Filter_27652_I | >Create a function that takes an array of strings and returns an array of their lengths. The function should also filter out any strings that contain numbers and only consider strings that have at least one vowel in them. | def has_vowel(s):
"""
Returns True if the string contains at least one vowel; otherwise, returns False.
"""
vowels = "aeiouAEIOU"
return any(char in vowels for char in s)
def contains_number(s):
"""
Returns True if the string contains any numerical digits; otherwise, returns False.
"""
... | from solution import filter_and_length
def test_filter_and_length_all_valid():
assert filter_and_length(["hello", "world", "alpha", "omega"]) == [5, 5, 5, 5]
def test_filter_and_length_with_numbers():
assert filter_and_length(["hello2", "world", "alpha3", "omega"]) == [5, 5]
def test_filter_and_length_with_n... | [
{
"docstring": "Returns True if the string contains at least one vowel; otherwise, returns False.",
"function_declaration": "def has_vowel(s):",
"function_name": "has_vowel",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the string contains any numerical digits; otherwise, retur... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def string_lengths_filter(strings):\n \"\"\"\n Takes an array of strings and returns an array of their lengths.\n Filters out any strings that contain numbers and considers strings th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027652",
"row_id": 27652,
"seed_ids": "['Qwen2-72B-Instruct_66501']"
} | 0.635143 | Filter_27652 | I | [
"has_vowel",
"contains_number",
"filter_and_length"
] | 3 | [
[
"filter_and_length",
"contains_number"
],
[
"filter_and_length",
"has_vowel"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e57b4c47ca81272dbc2c9a3f503efab85ebe4ca3 | 27a90aebff36e67c54c8d09ab7c76bbfcaf00321 | |||
v1.0 | instruct | Filter | Filter_27653_I | Develop a regex statement to evaluate if a specific string contains a palindrome sequence of characters. Your solution should also accommodate letter case sensitivity, punctuation and spaces, meaning that these should not disrupt the functionality of identifying a palindrome (e.g. "Madam, in Eden, I'm Adam" , ignoring ... | import re
def is_palindrome(s):
"""
Evaluate if a specific string contains a palindrome sequence of characters.
This accommodates letter case sensitivity, punctuation and spaces.
"""
# Remove non-alphanumeric characters and convert to lowercase
cleaned_s = re.sub(r'[^A-Za-z0-9]', '', s).lower()... | from solution import is_palindrome, identify_palindromes
def test_basic_palindromes():
assert is_palindrome("A man, a plan, a canal: Panama")
assert is_palindrome("No lemon, no melon")
assert is_palindrome("Madam, in Eden, I'm Adam")
assert is_palindrome("Able was I ere I saw Elba")
def test_non_palin... | [
{
"docstring": "Evaluate if a specific string contains a palindrome sequence of characters.\nThis accommodates letter case sensitivity, punctuation and spaces.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Iden... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string `s` is a palindrome, ignoring case, punctuation, and spaces.\n \"\"\"\n # Remove non-alphanumeric character... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027653",
"row_id": 27653,
"seed_ids": "['Qwen2-72B-Instruct_66502']"
} | 0.651985 | Filter_27653 | I | [
"is_palindrome",
"identify_palindromes"
] | 2 | [
[
"identify_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e8a84a925490daa7cc6c48537bcb06ab9aab186c | fba668e87bbf5f6a3acda7941e42ed8b41e2afcd | |||
v1.0 | instruct | Filter | Filter_27672_I | Create a Python function that takes two arguments, a positive integer and a boolean, and return the word "yes" if the boolean is true and the number is a prime number, or return the word "no" otherwise. | def is_prime(n):
"""
Helper function to 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 check_prime_and_boolean(number, flag):
"""
Returns the word "yes" if the flag is Tr... | from solution import check_prime_and_boolean
def test_prime_true():
assert check_prime_and_boolean(5, True) == "yes"
assert check_prime_and_boolean(13, True) == "yes"
def test_prime_false():
assert check_prime_and_boolean(4, True) == "no"
assert check_prime_and_boolean(9, True) == "no"
def test_flag_... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the word \"yes\" if the flag is True and the number is a prime number,\nor returns the word \"no\" othe... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determines if a given positive integer n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027672",
"row_id": 27672,
"seed_ids": "['Qwen2-72B-Instruct_66541']"
} | 0.759123 | Filter_27672 | I | [
"is_prime",
"check_prime_and_boolean"
] | 2 | [
[
"check_prime_and_boolean",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 47bc92349d83933195e71dccbdb73208da001359 | bd528ce415bea93f6cb97fbfc61d8f626e7527f6 | |||
v1.0 | instruct | Filter | Filter_27702_I | Create a command-line calculator program using Python that accepts two numbers as input and performs basic arithmetic operations (addition, subtraction, multiplication, division). The program should handle the case where the user enters an invalid input, such as a non-numeric value or a division by zero. Additionally, ... | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
return "Error: Division by zero"
return a / b
def calculator():
while True:
try:
print("Enter 'exit' to quit")
num1 = input("Ente... | # Assuming the functions are saved in a file named 'solution.py'
from solution import add, subtract, multiply, divide
def test_add():
assert add(1, 2) == 3
assert add(-1, 2) == 1
assert add(0, 0) == 0
def test_subtract():
assert subtract(3, 2) == 1
assert subtract(0, 2) == -2
assert subtract(5... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n return \"Error: Division by zer... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027702",
"row_id": 27702,
"seed_ids": "['Qwen2-72B-Instruct_66588']"
} | 0.578868 | Filter_27702 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fecb2aee38df518e343e2914827836c5e2ad80dc | 3954c19147c1649a78c1611c71e2d02f1a8f8b37 | |||
v1.0 | instruct | Filter | Filter_27703_I | Write a Python program to simulate a biased coin toss. The bias is determined by a probability p of landing on heads (0 <= p <= 1). If p is not provided, the coin should be fair (p = 0.5). The program should provide an option to run the simulation for a specified number of trials and output the number and proportion of... | import random
def biased_coin_toss(p=0.5):
"""
Simulates a single biased coin toss.
Returns 'H' for heads or 'T' for tails based on the bias p.
"""
return 'H' if random.random() < p else 'T'
def run_simulation(trials, p=0.5):
"""
Runs a biased coin toss simulation for a specified numbe... | import pytest
from solution import biased_coin_toss, run_simulation
def test_biased_coin_toss():
# Since it's probabilistic, we'll run a large number of trials
heads_count = sum(1 for _ in range(10000) if biased_coin_toss(0.7) == 'H')
assert 6800 <= heads_count <= 7200 # Allowing for some variation
def t... | [
{
"docstring": "Simulates a single biased coin toss.\nReturns 'H' for heads or 'T' for tails based on the bias p.",
"function_declaration": "def biased_coin_toss(p=0.5):",
"function_name": "biased_coin_toss",
"parameter_list": "(p=0.5)"
},
{
"docstring": "Runs a biased coin toss simulation f... | [
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 biased_coin_toss(p=0.5, trials=1):\n \"\"\"\n Simulate biased coin toss. The bias is determined by probability p of landing on heads.\n If p is not provided, the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027703",
"row_id": 27703,
"seed_ids": "['Qwen2-72B-Instruct_66589']"
} | 0.46058 | Filter_27703 | I | [
"biased_coin_toss",
"run_simulation"
] | 2 | [
[
"run_simulation",
"biased_coin_toss"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 10b4af6d40a7caa2d7d9f6acd9ce67b9d8e08663 | 0064df282bc9ab788ccfe4272c5aa2f68233cad5 | |||
v1.0 | instruct | Filter | Filter_27723_I | Design a radix sort algorithm for an array of 16-bit unsigned integers. Additionally, adapt the algorithm to handle sorting of integers in varying sizes (from 16 bit up to 32 bit). Consider time and space complexity in your solution for optimal performance. | def counting_sort(arr, exp):
"""
A function to do counting sort of arr[] according to the digit represented by exp.
Here exp is 10^i where i is the current digit number
"""
n = len(arr)
# The output array elements that will have sorted arr
output = [0] * n
# Initialize count ar... | from solution import radix_sort
def test_radix_sort_basic():
arr = [170, 45, 75, 90, 802, 24, 2, 66]
radix_sort(arr)
assert arr == sorted([170, 45, 75, 90, 802, 24, 2, 66])
def test_radix_sort_all_zeros():
arr = [0, 0, 0, 0, 0]
radix_sort(arr)
assert arr == [0, 0, 0, 0, 0]
def test_radix_sort... | [
{
"docstring": "A function to do counting sort of arr[] according to the digit represented by exp.\nHere exp is 10^i where i is the current digit number",
"function_declaration": "def counting_sort(arr, exp):",
"function_name": "counting_sort",
"parameter_list": "(arr, exp)"
},
{
"docstring"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def counting_sort(arr, exp):\n \"\"\"\n A function to do counting sort of arr[] according to the digit represented by exp.\n Here exp is 10^i where i is the current digit number\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027723",
"row_id": 27723,
"seed_ids": "['Qwen2-72B-Instruct_66619']"
} | 0.547412 | Filter_27723 | I | [
"counting_sort",
"radix_sort"
] | 2 | [
[
"radix_sort",
"counting_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b01fe04c11a4376b32b826e827527c28e750002 | 0e92e4e7cf82c8a06cfbfeeec4f723e1a3e9e7ec | |||
v1.0 | instruct | Filter | Filter_27726_I | Write a function in Python that takes a list of strings as input and returns a list with only the strings that have more than 3 vowels. | def has_more_than_three_vowels(s):
"""
Returns True if the string s has more than 3 vowels, otherwise False.
"""
vowels = set("aeiouAEIOU")
count = sum(1 for char in s if char in vowels)
return count > 3
def filter_strings_with_more_than_three_vowels(strings):
"""
Takes a list of string... | from solution import has_more_than_three_vowels, filter_strings_with_more_than_three_vowels
def test_has_more_than_three_vowels():
assert has_more_than_three_vowels("education") == True
assert has_more_than_three_vowels("hello") == False
assert has_more_than_three_vowels("beautiful") == True
assert has... | [
{
"docstring": "Returns True if the string s has more than 3 vowels, otherwise False.",
"function_declaration": "def has_more_than_three_vowels(s):",
"function_name": "has_more_than_three_vowels",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a list of string... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_vowels(string):\n vowels = set('aeiouAEIOU')\n return sum(1 for char in string if char in vowels)\n\ndef filter_strings_with_vowels(strings):\n \"\"\"\n Returns a list of... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027726",
"row_id": 27726,
"seed_ids": "['Qwen2-72B-Instruct_66623']"
} | 0.761207 | Filter_27726 | I | [
"has_more_than_three_vowels",
"filter_strings_with_more_than_three_vowels"
] | 2 | [
[
"filter_strings_with_more_than_three_vowels",
"has_more_than_three_vowels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 33c0a76039ad3b6ea6fb3883b31a0d65c42fabef | 8507b69bb697643459be286c8ce0b64a3c4b1507 | |||
v1.0 | instruct | Filter | Filter_27728_I | Write a program that reads a binary file and encrypts its content using an XOR cipher with a user-provided key. The program will then write the encrypted content to another binary file. Additionally, implement a function to decrypt the file using the same key. | def xor_cipher(data, key):
"""
Encrypts or decrypts the data using XOR cipher with the provided key.
"""
key_byte = key.to_bytes(1, 'little')
return bytes([b ^ key_byte[0] for b in data])
def encrypt_file(input_filename, output_filename, key):
"""
Encrypts the content of the input binary fi... | import os
def test_encrypt_decrypt():
# Create a temporary file for testing
test_data = b"this is a test"
input_filename = "test_input.bin"
encrypted_filename = "test_encrypted.bin"
decrypted_filename = "test_decrypted.bin"
key = 123 # Example key for XOR cipher
try:
# Write t... | [
{
"docstring": "Encrypts or decrypts the data using XOR cipher with the provided key.",
"function_declaration": "def xor_cipher(data, key):",
"function_name": "xor_cipher",
"parameter_list": "(data, key)"
},
{
"docstring": "Encrypts the content of the input binary file using XOR cipher with ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def xor_cipher(data, key):\n \"\"\"\n Encrypt or decrypt data with XOR cipher using the provided key.\n \n Args:\n data (bytes): The data to be encrypted or decrypted.\n key ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027728",
"row_id": 27728,
"seed_ids": "['Qwen2-72B-Instruct_66626']"
} | 0.491936 | Filter_27728 | I | [
"xor_cipher",
"encrypt_file",
"decrypt_file"
] | 3 | [
[
"decrypt_file",
"xor_cipher"
],
[
"encrypt_file",
"xor_cipher"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | a82d36d6a2fe93d2cf2b1e3240a813663d14cff8 | e2852a787e296804abf6b9459efea9e04e2dd66f | |||
v1.0 | instruct | Filter | Filter_27733_I | Write a function that takes a list of integers as input and returns a new list with only the prime numbers from the input list, in the same order. The function should be implemented using list comprehension. | def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def primes_from_list(numbers):
"""
Returns a list of prime numbers from the input list using l... | from solution import primes_from_list
def test_primes_from_list_with_mixed_numbers():
assert primes_from_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_primes_from_list_with_all_primes():
assert primes_from_list([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
def test_primes_from_list_with_no_p... | [
{
"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 prime numbers from the input list using list comprehension.",
"function_declaration": "def 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 is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027733",
"row_id": 27733,
"seed_ids": "['Qwen2-72B-Instruct_66635']"
} | 0.639634 | Filter_27733 | I | [
"is_prime",
"primes_from_list"
] | 2 | [
[
"primes_from_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd5950bc61c1c9e3b9029eef9e0f615f33bf9dfe | f0f65f71531dc0d227338dce32f789aeb458617b | |||
v1.0 | instruct | Filter | Filter_27775_I | Plot the first 10 numbers of the Fibonacci sequence using Matplotlib in Python. | import matplotlib.pyplot as plt
def fibonacci(n):
"""
Generates the first n numbers in the Fibonacci sequence.
"""
fib_sequence = [0, 1]
while len(fib_sequence) < n:
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[:n]
def plot_fibonacci_sequence(n):
"""... | from solution import fibonacci, plot_fibonacci_sequence
def test_fibonacci_sequence_length():
assert len(fibonacci(10)) == 10
def test_fibonacci_sequence_values():
assert fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_plot_function_runs_without_error():
try:
plot_fibonacci_sequence(1... | [
{
"docstring": "Generates the first n numbers in the Fibonacci sequence.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Plots the first n numbers of the Fibonacci sequence using Matplotlib.",
"function_declaration":... | [
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\n\ndef fibonacci(n):\n \"\"\"\n Returns the first n Fibonacci numbers.\n \"\"\"\n fib_sequence = [0, 1]\n while len(fib_sequence) < n:\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027775",
"row_id": 27775,
"seed_ids": "['Qwen2-72B-Instruct_66725']"
} | 0.607636 | Filter_27775 | I | [
"fibonacci",
"plot_fibonacci_sequence"
] | 2 | [
[
"plot_fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib"
] | false | 945c757cb2fbeb141b0977adf86e24e3348993af | 3c776ba996f1e6dcabba8dcd8a8cc0866d01bbd1 | |||
v1.0 | instruct | Filter | Filter_27786_I | Write a Python program that prints the prime numbers between 2 and 1000, each on a separate line. Additionally, the program should only use a single loop and should not make use of the modulus operator (%) to check for divisibility. | def is_prime(n):
"""
Helper function to determine if a number n is prime
using prime by trial division method without using modulus operator.
"""
if n < 2:
return False
for i in range(2, n):
if n // i * i == n:
return False
return True
def print_primes_2_to_1000(... | from solution import is_prime, print_primes_2_to_1000
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(25) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0... | [
{
"docstring": "Helper function to determine if a number n is prime\nusing prime by trial division method without using modulus operator.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints prime numbers between 2 and 1... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number n is prime\n using prime by trial division method without using modulus operator.\n \"\"\"\n if n < 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027786",
"row_id": 27786,
"seed_ids": "['Qwen2-72B-Instruct_66743']"
} | 0.634459 | Filter_27786 | I | [
"is_prime",
"print_primes_2_to_1000"
] | 2 | [
[
"print_primes_2_to_1000",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cfbae2e86fe3b983ca699c8ebe3d2fb4e3ac93d | 1e4a8b59800b625afbe39988436726f1566eea44 | |||
v1.0 | instruct | Filter | Filter_27789_I | Create a recursive function to showcase the first n numbers in the Fibonacci sequence, ensuring the function is optimized for a large value of n. Additionally, implement a function to calculate the n-th Fibonacci number using Binet’s formula. Compare the performance of both functions using a time complexity analysis. | def fibonacci_recursive(n, computed={0: 0, 1: 1}):
"""
Returns the first n numbers in the Fibonacci sequence using a recursive approach.
The function is optimized with memoization for large values of n.
"""
if n in computed:
return computed[n]
computed[n] = fibonacci_recursive(n-1, com... | from solution import fibonacci_recursive, fibonacci_binet, get_fibonacci_sequence
def test_fibonacci_recursive_first_10():
expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
assert get_fibonacci_sequence(10) == expected
def test_fibonacci_recursive_large_value():
# Testing a larger value and seeing execution ti... | [
{
"docstring": "Returns the first n numbers in the Fibonacci sequence using a recursive approach.\nThe function is optimized with memoization for large values of n.",
"function_declaration": "def fibonacci_recursive(n, computed={0: 0, 1: 1}):",
"function_name": "fibonacci_recursive",
"parameter_list... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_recursive(n, computed={0: 0, 1: 1}):\n \"\"\"\n Returns the first n numbers in the Fibonacci sequence using a recursive approach.\n The function is optimized with memoiz... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027789",
"row_id": 27789,
"seed_ids": "['Qwen2-72B-Instruct_66746']"
} | 0.676364 | Filter_27789 | I | [
"fibonacci_recursive",
"get_fibonacci_sequence",
"fibonacci_binet"
] | 3 | [
[
"get_fibonacci_sequence",
"fibonacci_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5e962f70a998193b78a840fa8324a92a95ec115 | f26a46e4941d25ce21530b55efd3d3f21e6456bf | |||
v1.0 | instruct | Filter | Filter_27791_I | Automate the process of formatting and sending messages for a WhatsApp broadcast list using Python. | from typing import List, Dict
def format_message(template: str, personalization: Dict[str, str]) -> str:
"""
Formats a message template with the provided personalization details.
Args:
template (str): The message template containing placeholders.
personalization (Dict[str, str]): Dictionary co... | from solution import format_message, send_messages
def test_format_message():
template = "Hello, {{name}}! Your order {{order_id}} will be delivered on {{delivery_date}}."
personalization = {
"name": "John",
"order_id": "1234",
"delivery_date": "2023-10-01"
}
expected_messa... | [
{
"docstring": "Formats a message template with the provided personalization details.\n\nArgs:\ntemplate (str): The message template containing placeholders.\npersonalization (Dict[str, str]): Dictionary containing the placeholder keys and their replacement values.\n\nReturns:\nstr: The formatted message.",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\nfrom twilio.rest import Client\n\ndef send_whatsapp_broadcast(account_sid: str, auth_token: str, from_whatsapp: str, broadcast_list: List[str], message: str) -> None:\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027791",
"row_id": 27791,
"seed_ids": "['Qwen2-72B-Instruct_66748']"
} | 0.376624 | Filter_27791 | I | [
"format_message",
"send_messages"
] | 2 | [
[
"send_messages",
"format_message"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b991559f17961992a111dd050db5eee469806cbe | 831f9da5f0d9f32430371196443ae2fec1fdf4c3 | |||
v1.0 | instruct | Filter | Filter_27799_I | Create a Python function to find the second smallest prime number in a given list of integers. The list will contain at least 100 elements and at most 10,000 elements. All elements in the list will be positive integers between 1 and 1,000,000. The function should return the second smallest prime number found in the lis... | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def second_smallest_prime(numbers):
... | from solution import second_smallest_prime
def test_second_smallest_prime_no_primes():
numbers = [4, 6, 8, 10, 12, 14, 16, 18, 20]
assert second_smallest_prime(numbers) == -1
def test_second_smallest_prime_single_prime():
numbers = [4, 6, 8, 10, 11, 14, 16, 18, 20]
assert second_smallest_prime(numbers... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the second smallest prime number in the given list.",
"function_declaration": "def second_smallest_prime(numbers... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027799",
"row_id": 27799,
"seed_ids": "['Qwen2-72B-Instruct_66760']"
} | 0.662348 | Filter_27799 | I | [
"is_prime",
"second_smallest_prime"
] | 2 | [
[
"second_smallest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b881b86abeb7111c3cd525262d649525bf4ccce5 | a71fd7f2034c3c284adbc7d68daa74f31242499f | |||
v1.0 | instruct | Filter | Filter_27825_I | Create a Python program that reads a CSV file named 'data.csv' and prints the sum of values in the 'age' column. Then, implement a function that returns the average age from the CSV file. | import csv
def read_csv_and_sum_ages(file_path):
total_age = 0
count = 0
with open(file_path, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
try:
age = int(row['age'])
total_age += age
count += 1
... | import pytest
from solution import average_age, read_csv_and_sum_ages
def test_read_csv_and_sum_ages(tmp_path):
# prepare a temporary CSV file
csv_file = tmp_path / "data.csv"
with open(csv_file, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['name', 'age'])
writer.w... | [
{
"docstring": null,
"function_declaration": "def read_csv_and_sum_ages(file_path):",
"function_name": "read_csv_and_sum_ages",
"parameter_list": "(file_path)"
},
{
"docstring": null,
"function_declaration": "def average_age(file_path):",
"function_name": "average_age",
"paramete... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\n\ndef sum_of_ages(filename):\n \"\"\"\n Returns the sum of values in the 'age' column in the given CSV file.\n \"\"\"\n total_age = 0\n with open(filename, mode='r')... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027825",
"row_id": 27825,
"seed_ids": "['Qwen2-72B-Instruct_66789']"
} | 0.682223 | Filter_27825 | I | [
"read_csv_and_sum_ages",
"average_age"
] | 2 | [
[
"average_age",
"read_csv_and_sum_ages"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 66258f5d18c3d6cf488baa9ad96793b5153e82b5 | b778a838d0b7cab2bce5922d9c7c2000c5174a8f | |||
v1.0 | instruct | Filter | Filter_27832_I | Write a Python code snippet to define a function that calculates the highest common factor (HCF) of three given integer inputs, a, b, and c. The function should also validate if the inputs are integers and non-zero. | from math import gcd
from functools import reduce
def validate_inputs(a, b, c):
if not all(isinstance(i, int) and i != 0 for i in [a, b, c]):
raise ValueError("All inputs must be non-zero integers.")
def hcf_of_three(a, b, c):
"""
Returns the highest common factor (HCF) of the three given non-zero... | from solution import hcf_of_three, validate_inputs
import pytest
def test_hcf_positive_numbers():
assert hcf_of_three(8, 12, 16) == 4
def test_hcf_negative_numbers():
assert hcf_of_three(-8, -12, -16) == 4
def test_hcf_mixed_sign_numbers():
assert hcf_of_three(-8, 12, 16) == 4
def test_hcf_no_common_fac... | [
{
"docstring": null,
"function_declaration": "def validate_inputs(a, b, c):",
"function_name": "validate_inputs",
"parameter_list": "(a, b, c)"
},
{
"docstring": "Returns the highest common factor (HCF) of the three given non-zero integers a, b, and c.",
"function_declaration": "def hcf_... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def hcf(x, y):\n \"\"\"\n Returns the highest common factor (HCF) of two numbers x and y.\n \"\"\"\n while y:\n x, y = y, x % y\n return x\n\ndef highest_common_factor(a,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027832",
"row_id": 27832,
"seed_ids": "['Qwen2-72B-Instruct_66797']"
} | 0.576531 | Filter_27832 | I | [
"validate_inputs",
"hcf_of_three"
] | 2 | [
[
"hcf_of_three",
"validate_inputs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2544a8fe6a95c75756f2d1bcb0dec65daeb1a685 | 46f3013223c7523989ecb77db9236930305d2f63 | |||
v1.0 | instruct | Filter | Filter_27858_I | Write two Python functions. The first function should take in a string and return the number of vowels in the string. The second function should take in a sentence and return how many vowels are in the sentence using the first function. To increase difficulty, I've included a piece of erroneous code for you to correct. | def count_vowels_in_string(s):
"""
Returns the number of vowels in the given string s.
"""
vowels = 'aeiouAEIOU'
return sum(1 for char in s if char in vowels)
def count_vowels_in_sentence(sentence):
"""
Returns the number of vowels in the given sentence using count_vowels_in_string.
"""... | from solution import count_vowels_in_string, count_vowels_in_sentence
def test_count_vowels_in_string():
assert count_vowels_in_string("hello") == 2
assert count_vowels_in_string("HELLO") == 2
assert count_vowels_in_string("") == 0
assert count_vowels_in_string("bcdfg") == 0
assert count_vowels_in_... | [
{
"docstring": "Returns the number of vowels in the given string s.",
"function_declaration": "def count_vowels_in_string(s):",
"function_name": "count_vowels_in_string",
"parameter_list": "(s)"
},
{
"docstring": "Returns the number of vowels in the given sentence using count_vowels_in_strin... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_vowels(word):\n \"\"\"\n Returns the number of vowels in the given word.\n \"\"\"\n vowels = 'aeiouAEIOU'\n return sum(1 for letter in word if letter in vowels)\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027858",
"row_id": 27858,
"seed_ids": "['Qwen2-72B-Instruct_66836']"
} | 0.853508 | Filter_27858 | I | [
"count_vowels_in_string",
"count_vowels_in_sentence"
] | 2 | [
[
"count_vowels_in_sentence",
"count_vowels_in_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8deaaafe488fffd86b16dc558111ee13bb6bad3f | 4d43ee9afb5e5f48fe5aa8be9460437de15a11cc | |||
v1.0 | instruct | Filter | Filter_27889_I | Write a python function that checks if one string is a substring of another. However, things are not that easy. Your function should not rely on any built-in string functions such as str.find() or str.index(). It should instead implement the KMP (Knuth-Morris-Pratt) algorithm for string matching. Also, write test cases... | def compute_lps(pattern):
"""
Compute the LPS (Longest Prefix which is also Suffix) array used in KMP algorithm.
"""
lps = [0] * len(pattern)
length = 0 # length of the previous longest prefix suffix
i = 1
while i < len(pattern):
if pattern[i] == pattern[length]:
length ... | from solution import is_substring
def test_is_substring_present():
assert is_substring("abc", "abcdef") == True
assert is_substring("def", "abcdef") == True
assert is_substring("a", "a") == True
assert is_substring("abc", "abcabcabc") == True
def test_is_substring_not_present():
assert is_substrin... | [
{
"docstring": "Compute the LPS (Longest Prefix which is also Suffix) array used in KMP algorithm.",
"function_declaration": "def compute_lps(pattern):",
"function_name": "compute_lps",
"parameter_list": "(pattern)"
},
{
"docstring": "KMP algorithm for substring search.",
"function_decla... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_lps(pattern):\n \"\"\"\n Compute the LPS (Longest Prefix which is also Suffix) array used in KMP algorithm.\n \"\"\"\n lps = [0] * len(pattern)\n length = 0 # lengt... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027889",
"row_id": 27889,
"seed_ids": "['Qwen2-72B-Instruct_66908']"
} | 0.692148 | Filter_27889 | I | [
"compute_lps",
"kmp_substring_search",
"is_substring"
] | 3 | [
[
"is_substring",
"kmp_substring_search"
],
[
"kmp_substring_search",
"compute_lps"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 791d4d7c07b8b5c2052c95b1771d27e417530d0c | d6c4e4e5f313a86355b9c5f11ef7386f86a64925 | |||
v1.0 | instruct | Filter | Filter_27896_I | Design a Python function that can identify prime numbers from a collection of integers, including negative integers and zero. This function should be capable of handling exceptions for inputs that are non-numerical, floating point numbers, or even numbers that exceed Python's integer limit. The output should be arrange... | def is_prime(n):
"""
Helper function to 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
... | from solution import prime_numbers_info
def test_prime_numbers_info_with_prime_numbers():
assert prime_numbers_info([2, 3, 5, 7]) == ([2, 3, 5, 7], 210, 17)
def test_prime_numbers_info_with_no_primes():
assert prime_numbers_info([0, 1, 4, 6, 8, 10]) == ([], 0, 0)
def test_prime_numbers_info_with_mixed_number... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "This function takes a collection of integers and returns a tuple consisting of:\n- A list of prime num... | [
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):\n \"\"\"\n Helper function to 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 =... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027896",
"row_id": 27896,
"seed_ids": "['Qwen2-72B-Instruct_66918']"
} | 0.719204 | Filter_27896 | I | [
"is_prime",
"prime_numbers_info"
] | 2 | [
[
"prime_numbers_info",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 21bdfda039920a9877922f62ecd48df123454a67 | e3e6ee717d08e62aa0d46c5b70f65f0e12c26907 | |||
v1.0 | instruct | Filter | Filter_27900_I | Create an efficient algorithm to find the median of an unsorted array of numbers without using built-in sorting functions. Additionally, implement the algorithm in such a way that it performs well for large datasets. The solution should be self-contained, making use of no external libraries apart from Python's stdlib. | def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i = i + 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if low == high:
... | from solution import find_median
def test_odd_length():
assert find_median([3, 1, 2]) == 2
def test_even_length():
assert find_median([4, 2, 3, 1]) == 2.5
def test_negative_numbers():
assert find_median([-3, -1, -4, -2]) == -2.5
def test_single_element():
assert find_median([1]) == 1
def test_large... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_median(nums):\n \"\"\"\n Finds the median of an unsorted list of numbers using the\n Quickselect algorithm (a variant of QuickSort).\n \"\"\"\n if not nums:\n ra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027900",
"row_id": 27900,
"seed_ids": "['Qwen2-72B-Instruct_66923']"
} | 0.727894 | Filter_27900 | I | [
"partition",
"quickselect",
"find_median"
] | 3 | [
[
"find_median",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9d03a45532e5859abd513c165ed1a52595d87476 | cb96edd987d2a63e1b64c346c36b9548760f83ae | |||
v1.0 | instruct | Filter | Filter_27906_I | Write a code to generate the Fibonacci series for the first n numbers, and then modify it to print only the even numbers in the generated series. | def fibonacci(n):
"""
Generates the first n numbers of the Fibonacci series.
"""
fib_series = [0, 1]
if n <= 0:
return []
elif n == 1:
return [0]
else:
while len(fib_series) < n:
next_value = fib_series[-1] + fib_series[-2]
fib_series.append(ne... | from solution import fibonacci, even_fibonacci
def test_fibonacci_10():
assert fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_fibonacci_1():
assert fibonacci(1) == [0]
def test_fibonacci_0():
assert fibonacci(0) == []
def test_fibonacci_5():
assert fibonacci(5) == [0, 1, 1, 2, 3]
def t... | [
{
"docstring": "Generates the first n numbers of the Fibonacci series.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first n numbers of the Fibonacci series and returns only the even numbers.",
"funct... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n):\n \"\"\"\n Generates the first n numbers of the Fibonacci series.\n \"\"\"\n fib_series = [0, 1]\n if n <= 0:\n return []\n elif n == 1:\n ret... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027906",
"row_id": 27906,
"seed_ids": "['Qwen2-72B-Instruct_66934']"
} | 0.600872 | Filter_27906 | I | [
"fibonacci",
"even_fibonacci"
] | 2 | [
[
"even_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 059a78268572e45a4e05b5eed32a2088711e256c | e595ddfafea698821b6e9674832290356f0931bf | |||
v1.0 | instruct | Filter | Filter_27912_I | Generate a program to simulate flipping a biased coin, where the probability of landing on heads is 70% and tails is 30%. The program should keep track of the number of consecutive heads and tails flipped, and display the maximum streak of heads and tails after a specified number of flips. Additionally, the program sho... | import random
def biased_coin_flip():
"""
Simulates a biased coin flip.
Returns 'H' for heads with 70% probability, and 'T' for tails with 30% probability.
"""
return 'H' if random.random() < 0.7 else 'T'
def simulate_flips(num_flips):
"""
Simulates a specified number of biased coin flips ... | from solution import biased_coin_flip, simulate_flips
def test_biased_coin_flip_distribution():
heads_count = 0
tails_count = 0
for _ in range(10000):
flip = biased_coin_flip()
if flip == 'H':
heads_count += 1
else:
tails_count += 1
# We expect about 70% ... | [
{
"docstring": "Simulates a biased coin flip.\nReturns 'H' for heads with 70% probability, and 'T' for tails with 30% probability.",
"function_declaration": "def biased_coin_flip():",
"function_name": "biased_coin_flip",
"parameter_list": "()"
},
{
"docstring": "Simulates a specified number ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef simulate_biased_coin_flips(num_flips, head_probability=0.7):\n \"\"\"\n Simulate flipping a biased coin and track the longest streak of heads and tails.\n \n :... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027912",
"row_id": 27912,
"seed_ids": "['Qwen2-72B-Instruct_66947']"
} | 0.521439 | Filter_27912 | I | [
"biased_coin_flip",
"simulate_flips"
] | 2 | [
[
"simulate_flips",
"biased_coin_flip"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a02a4a6d5dcf2ae771fc08831a39fa3d3423965c | 9bcbf3e72f2256787de50c1fa2e18a9a3f1aaa2a | |||
v1.0 | instruct | Filter | Filter_27920_I | Write a Python program to identify all prime numbers within a given range. The program should accept two integers as input, representing the lower and upper bounds of the range, and output a list of all prime numbers within that range. Ensure that the program handles invalid input gracefully. | def is_prime(n):
"""
Helper function to determine 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
... | from solution import find_primes_in_range
def test_find_primes_in_range_positive_bounds():
assert find_primes_in_range(10, 20) == [11, 13, 17, 19]
def test_find_primes_in_range_negative_and_positive_bounds():
assert find_primes_in_range(-10, 10) == [2, 3, 5, 7]
def test_find_primes_in_range_single_number():
... | [
{
"docstring": "Helper function to determine 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 within the given range [lower, upper].",
"function_declaration": "def f... | [
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 Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027920",
"row_id": 27920,
"seed_ids": "['Qwen2-72B-Instruct_66956']"
} | 0.652768 | Filter_27920 | I | [
"is_prime",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cd31a05f5e461d0b8a58d87d8d15cf960b94f02 | 13d778cec035fa221c6996246f9961848735cb71 | |||
v1.0 | instruct | Filter | Filter_27923_I | Write a Python function that takes a positive integer as an argument and returns the square of that number. Additionally, the function should check if the input is a prime number and if so, return a message stating that the number is prime along with its square. If the input is not a prime number, the function should r... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import square_and_check_prime
def test_square_of_non_prime():
assert square_and_check_prime(4) == 16
assert square_and_check_prime(9) == 81
assert square_and_check_prime(20) == 400
def test_square_of_prime():
assert square_and_check_prime(2) == "2 is a prime number. Its square is 4."
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the square of the number n. If n is a prime number,\nreturns a message stating that n is prime along wi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027923",
"row_id": 27923,
"seed_ids": "['Qwen2-72B-Instruct_66962']"
} | 0.674661 | Filter_27923 | I | [
"is_prime",
"square_and_check_prime"
] | 2 | [
[
"square_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e4a3322da382a2c6b783c9ec9b8c4710d1ddd99 | 19a00ac41b8922990f0614de3271a2ccc7ed3d68 | |||
v1.0 | instruct | Filter | Filter_27945_I | Use a sorting algorithm to sort a list of 10,000 randomly generated integers between 1 and 1,000,000 in ascending order. Additionally, the algorithm must have a time complexity of O(n log n) and must not use any built-in sorting functions or libraries. The sorted list should be stored in a new list and the original lis... | def merge_sort(arr):
"""
Sorts an input list using the merge sort algorithm and returns a new sorted list.
This approach ensures that the input list remains unchanged.
"""
if len(arr) <= 1:
return arr
# Recursive case: split the array into halves
mid_point = len(arr) // 2
le... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([42]) == [42]
def test_merge_sort_already_sorted():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_order():
assert merge... | [
{
"docstring": "Sorts an input list using the merge sort algorithm and returns a new sorted list.\nThis approach ensures that the input list remains unchanged.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges... | [
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 merge_sort(arr):\n \"\"\"\n Sorts the given array in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n mid ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027945",
"row_id": 27945,
"seed_ids": "['Qwen2-72B-Instruct_66994']"
} | 0.542092 | Filter_27945 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fd2ce14e78f27443c3a51aebf771810e381a2a78 | e277a29d6d1fb6e992bb39831a216691a9d93899 | |||
v1.0 | instruct | Filter | Filter_27963_I | How do I convert a hexadecimal number to binary in Python? And then, can you write a function that takes an IP address in hexadecimal format and converts it to binary format? For example, the hexadecimal IP address '1F2A:3B4C:5D6E:7F89:9A2B:C3D4:E5F6:789A' should be converted to its equivalent binary representation. | def hex_to_bin(hex_num):
"""
Converts a hexadecimal number to binary.
Parameters:
hex_num (str): Hexadecimal number as a string
Returns:
str: Binary representation of the input hexadecimal number
"""
return bin(int(hex_num, 16))[2:]
def hex_ip_to_bin_ip(hex_ip):
""... | from solution import hex_to_bin, hex_ip_to_bin_ip
def test_hex_to_bin():
assert hex_to_bin('1F2A') == '1111100101010'
assert hex_to_bin('3B4C') == '11101101001100'
assert hex_to_bin('5D6E') == '101110101101110'
assert hex_to_bin('7F89') == '111111110001001'
assert hex_to_bin('9A2B') == '10011010001... | [
{
"docstring": "Converts a hexadecimal number to binary.\n\nParameters:\n hex_num (str): Hexadecimal number as a string\n\nReturns:\n str: Binary representation of the input hexadecimal number",
"function_declaration": "def hex_to_bin(hex_num):",
"function_name": "hex_to_bin",
"parameter_list"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def hex_to_bin(hex_ip):\n \"\"\"\n Converts a hexadecimal IP address to a binary IP address.\n \n Parameters:\n hex_ip (str): The hexadecimal IP address\n \n Returns:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027963",
"row_id": 27963,
"seed_ids": "['Qwen2-72B-Instruct_67026']"
} | 0.672442 | Filter_27963 | I | [
"hex_to_bin",
"hex_ip_to_bin_ip"
] | 2 | [
[
"hex_ip_to_bin_ip",
"hex_to_bin"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6213225aab063df90fdbc7358676d02f9b86a0a | 22e1ec4e09cdc1bb8528d013ac57910e315b8cf6 | |||
v1.0 | instruct | Filter | Filter_27965_I | Create a Python program to find out the prime numbers in a given range. The program should accept two integers as input, representing the range's lower and upper bounds. Make sure to include error handling for situations where the user enters invalid input, such as non-integer or negative values. After identifying all ... | def is_prime(n):
"""
Helper function to determine 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
... | from solution import find_primes_in_range, is_prime
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(5) is True
assert is_prime(10) is False
assert is_prime(11) is True
def test_find_primes_in_range_valid():
assert find_... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to find prime numbers in a given range.",
"function_declaration": "def find_primes_in_range(lo... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if n is a prime number or not.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n %... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027965",
"row_id": 27965,
"seed_ids": "['Qwen2-72B-Instruct_67032']"
} | 0.63444 | Filter_27965 | I | [
"is_prime",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3f1a9dfd3afcd7bf18784e72f15b26f8448cee6 | 798e9d5431d1d40fc3b52d469b4048e5c8fd2f93 | |||
v1.0 | instruct | Filter | Filter_27981_I | Write a code that takes a list of numbers and returns a list of their square roots, rounded to two decimal points. Limit the length of the output list to a specified number of elements. Ensure this code is written without using built-in functions for calculating square roots and rounding. Also, include handling for inv... | import math
def custom_sqrt(x):
"""
Custom function to calculate the square root of a number using the Babylonian method.
"""
if x < 0:
raise ValueError("Cannot calculate square root of negative numbers")
if x == 0:
return 0
guess = x / 2.0
tolerance = 1e-10
... | from solution import get_square_roots, custom_sqrt, custom_round
def test_custom_sqrt():
assert round(custom_sqrt(4), 2) == 2.00
assert round(custom_sqrt(9), 2) == 3.00
assert round(custom_sqrt(2), 2) == 1.41
assert round(custom_sqrt(16), 2) == 4.00
def test_custom_round():
assert custom_round(1.2... | [
{
"docstring": "Custom function to calculate the square root of a number using the Babylonian method.",
"function_declaration": "def custom_sqrt(x):",
"function_name": "custom_sqrt",
"parameter_list": "(x)"
},
{
"docstring": "Custom function to round a number to a specified number of decimal... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def custom_sqrt(n):\n \"\"\"\n Returns the square root of n using the Babylonian method (also known as Heron's method).\n \"\"\"\n if n < 0:\n raise ValueError(\"Cannot take... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027981",
"row_id": 27981,
"seed_ids": "['Qwen2-72B-Instruct_67061']"
} | 0.661118 | Filter_27981 | I | [
"custom_sqrt",
"custom_round",
"get_square_roots"
] | 3 | [
[
"get_square_roots",
"custom_round"
],
[
"get_square_roots",
"custom_sqrt"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f0dd352ac2d7bc296c434903b3789f79e0364611 | dce31ddca3fcc891b625ab5fc0c74008a4d259d4 | |||
v1.0 | instruct | Filter | Filter_27993_I | Using Python, write a function that takes in a list of integers, and returns a sorted list of integers that are only divisible by 1 and themselves. The function should also remove any duplicates in the list. Test this function with the following list of integers: [47, 11, 47, 2, 43, 11, 2, 59, 23, 17, 29, 37, 41, 53, 2... | def is_prime(n):
"""Helper function to check if a number is prime."""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
re... | from solution import extract_primes
def test_extract_primes():
test_input = [47, 11, 47, 2, 43, 11, 2, 59, 23, 17, 29, 37, 41, 53, 2, 11, 43, 47]
expected_output = [2, 11, 17, 23, 29, 37, 41, 43, 47, 53, 59]
assert extract_primes(test_input) == expected_output
def test_extract_primes_empty_list():
ass... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, return a sorted list of unique integers that are prime.",
"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 Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027993",
"row_id": 27993,
"seed_ids": "['Qwen2-72B-Instruct_67075']"
} | 0.642147 | Filter_27993 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | adf1423b71207be58f9a1ce0fbc0de92e3e31d8a | ec571f9e6f7f29f8149dd1a046ff1e975e3d7754 | |||
v1.0 | instruct | Filter | Filter_28002_I | Develop a Python program to convert a given temperature from Celsius to Fahrenheit. Additionally, implement a feature that allows the user to input the temperature and choose the unit of measurement (Celsius or Fahrenheit) for the conversion. The program should handle erroneous input gracefully and provide appropriate ... | def celsius_to_fahrenheit(celsius):
"""
Converts Celsius to Fahrenheit.
"""
return (celsius * 9/5) + 32
def fahrenheit_to_celsius(fahrenheit):
"""
Converts Fahrenheit to Celsius.
"""
return (fahrenheit - 32) * 5/9
def convert_temperature(value, unit):
"""
Converts the given tem... | def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(-40) == -40
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(37) == 98.6
def test_fahrenheit_to_celsius():
assert fahrenheit_to_celsius(32) == 0
assert fahrenheit_to_celsius... | [
{
"docstring": "Converts Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius)"
},
{
"docstring": "Converts Fahrenheit to Celsius.",
"function_declaration": "def fahrenheit_to_celsius... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius temperature to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028002",
"row_id": 28002,
"seed_ids": "['Qwen2-72B-Instruct_67092']"
} | 0.424808 | Filter_28002 | I | [
"celsius_to_fahrenheit",
"fahrenheit_to_celsius",
"convert_temperature"
] | 3 | [
[
"convert_temperature",
"celsius_to_fahrenheit"
],
[
"convert_temperature",
"fahrenheit_to_celsius"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 6d1ed9c47e8e4b64afc0e39a2ee586e68b91c645 | 87411082de90a63f2904280c446dcadb24689bf3 | |||
v1.0 | instruct | Filter | Filter_28026_I | Create an empty set in Python and add the following items into it in reverse alphabetical order: "C", "B", "A". Ensure that the set does not contain any duplicate elements. Additionally, implement a function that checks if a given character is a vowel or a consonant and add the result as a tuple along with the characte... | def is_vowel(char):
"""
Check if a given character is a vowel.
"""
vowels = 'aeiouAEIOU'
if char in vowels:
return True
return False
def add_to_set():
"""
Create an empty set and add items in reverse alphabetical order (C, B, A).
Then, add characters along with "vowel" or "c... | from solution import is_vowel, add_to_set
def test_is_vowel():
assert is_vowel('A') == True
assert is_vowel('a') == True
assert is_vowel('B') == False
assert is_vowel('b') == False
assert is_vowel('E') == True
assert is_vowel('z') == False
def test_add_to_set():
result = add_to_set()
... | [
{
"docstring": "Check if a given character is a vowel.",
"function_declaration": "def is_vowel(char):",
"function_name": "is_vowel",
"parameter_list": "(char)"
},
{
"docstring": "Create an empty set and add items in reverse alphabetical order (C, B, A).\nThen, add characters along with \"vow... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def create_and_populate_set():\n items = [\"C\", \"B\", \"A\"]\n s = set()\n\n for item in reversed(items):\n s.add(item)\n \n return s\n\ndef is_vowel_or_consonant(char)... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028026",
"row_id": 28026,
"seed_ids": "['Qwen2-72B-Instruct_67136']"
} | 0.717306 | Filter_28026 | I | [
"is_vowel",
"add_to_set"
] | 2 | [
[
"add_to_set",
"is_vowel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6a1b209411ab9b3df29db672a0b373831ca27613 | eb0fd850de4a9cff24ef421b593a83958447558e | |||
v1.0 | instruct | Filter | Filter_28028_I | Write a program that prints the Lucas sequence of numbers up to the nth term. The Lucas sequence is similar to the Fibonacci sequence, but starts with 2 and 1 instead of 0 and 1. Your program should include error handling for invalid input and should be implemented using recursion. | def lucas(n):
"""
Returns the nth term in the Lucas sequence using recursion.
"""
if n < 0:
raise ValueError("Input must be a non-negative integer.")
if n == 0:
return 2
elif n == 1:
return 1
else:
return lucas(n - 1) + lucas(n - 2)
def lucas_sequence(n):
... | import pytest
from solution import lucas, lucas_sequence
def test_lucas():
assert lucas(0) == 2
assert lucas(1) == 1
assert lucas(2) == 3
assert lucas(3) == 4
assert lucas(4) == 7
assert lucas(5) == 11
assert lucas(6) == 18
def test_lucas_invalid_input():
with pytest.raises(ValueError)... | [
{
"docstring": "Returns the nth term in the Lucas sequence using recursion.",
"function_declaration": "def lucas(n):",
"function_name": "lucas",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of Lucas sequence numbers up to the nth term.",
"function_declaration": "def lucas_se... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def lucas_sequence(n):\n \"\"\"\n Returns the nth term in the Lucas sequence.\n \n Parameters:\n n (int): The position in the Lucas sequence to retrieve. Must be non-negative.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028028",
"row_id": 28028,
"seed_ids": "['Qwen2-72B-Instruct_67141']"
} | 0.718848 | Filter_28028 | I | [
"lucas",
"lucas_sequence"
] | 2 | [
[
"lucas_sequence",
"lucas"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 29212b7561f2eab541d9ee98cb50e0fbcec50995 | 22b8358a08efb82ab62fd3286be1004321fb4ce6 | |||
v1.0 | instruct | Filter | Filter_28038_I | Develop a Python program that is capable of executing real-time conversion of pressure quantities from Pascal to Bar units, incorporating decision-making features to handle varied user input intelligently. | def pascal_to_bar(pascal):
"""
Converts pressure from Pascal to Bar.
Parameters:
- pascal (float): pressure in Pascal
Returns:
- float: pressure in Bar
"""
return pascal / 1e5
def convert_pressure(pressure, from_unit, to_unit):
"""
Converts pressure between different u... | from solution import pascal_to_bar, convert_pressure
def test_pascal_to_bar():
assert pascal_to_bar(100000) == 1
assert pascal_to_bar(50000) == 0.5
assert pascal_to_bar(0) == 0
assert pascal_to_bar(1e5) == 1
def test_convert_pressure_pascal_to_bar():
assert convert_pressure(100000, "pascal", "bar"... | [
{
"docstring": "Converts pressure from Pascal to Bar.\n\nParameters:\n- pascal (float): pressure in Pascal\n\nReturns:\n- float: pressure in Bar",
"function_declaration": "def pascal_to_bar(pascal):",
"function_name": "pascal_to_bar",
"parameter_list": "(pascal)"
},
{
"docstring": "Converts ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def pascal_to_bar(pascal):\n \"\"\"\n Converts pressure from Pascal to Bar.\n \n Parameters:\n pascal (float): The pressure in Pascal.\n \n Returns:\n float: The pressu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028038",
"row_id": 28038,
"seed_ids": "['Qwen2-72B-Instruct_67161']"
} | 0.393643 | Filter_28038 | I | [
"pascal_to_bar",
"convert_pressure"
] | 2 | [
[
"convert_pressure",
"pascal_to_bar"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 152c0d9fa535da05363440ce3f0468ce82f7eb42 | 7a486bbfdba3b6de9f4224c1dfb974a9530f8775 | |||
v1.0 | instruct | Filter | Filter_28042_I | Create a function in Python to evaluate if a given number is prime and has exactly three distinct prime factors, where the number is less than 1000. Additionally, provide a piece of erroneous code as a reference to increase misdirection. | def is_prime(n):
"""
Returns whether 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 distinct_prime_factors_count(n):
"""
Returns the count of distinct prime factors of n.
""... | from solution import is_prime, distinct_prime_factors_count, has_three_distinct_prime_factors
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(0)
assert not is_prime(1)
def test_distinct_prime_factors_count():
assert d... | [
{
"docstring": "Returns whether a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of distinct prime factors of n.",
"function_declaration": "def distinct_prime_factors_count(n):",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns whether a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028042",
"row_id": 28042,
"seed_ids": "['Qwen2-72B-Instruct_67168']"
} | 0.73175 | Filter_28042 | I | [
"is_prime",
"distinct_prime_factors_count",
"has_three_distinct_prime_factors"
] | 3 | [
[
"distinct_prime_factors_count",
"is_prime"
],
[
"has_three_distinct_prime_factors",
"distinct_prime_factors_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c76164ef577f3cb01c90d597a3ab88450cd41918 | 27bf8ef3b231c79837fa0691bced9aa3240a31f9 | |||
v1.0 | instruct | Filter | Filter_28077_I | Create a Python program to create a list of the first 20 prime numbers, where each prime number is a palindrome. The program should also calculate and print the sum of the prime numbers in the list. | def is_prime(n):
"""Checks if a number is prime."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def is_palindrome(n):
"""Checks if a numb... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(131) == True
def test_generate_palindromic_... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028077",
"row_id": 28077,
"seed_ids": "['Qwen2-72B-Instruct_67231']"
} | 0.558765 | Filter_28077 | I | [
"is_prime",
"is_palindrome",
"generate_palindromic_primes",
"sum_of_palindromic_primes"
] | 4 | [
[
"generate_palindromic_primes",
"is_palindrome"
],
[
"generate_palindromic_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e622b8ec9329428580163cc58f8c8ccd50673ffa | 5c8f2ace626a37511cb028bf9bd76c66a42092db | |||
v1.0 | instruct | Filter | Filter_28085_I | Write a Python function that takes a list of positive integers as an argument and returns a dictionary. The dictionary should map each unique integer to a tuple containing three elements: boolean values indicating whether it is a prime number, whether it is divisible by any number in the input list (excluding itself), ... | def is_prime(n):
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 divisors(n, num_list):
divs = [x for x in num_list if x != n and n % x == 0]... | from solution import analyze_numbers
def test_single_prime_number():
assert analyze_numbers([7]) == {7: (True, False, [])}
def test_single_non_prime_number():
assert analyze_numbers([6]) == {6: (False, False, [])}
def test_multiple_numbers_no_divisors():
assert analyze_numbers([2, 3, 5]) == {
2: ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def divisors(n, num_list):",
"function_name": "divisors",
"parameter_list": "(n, num_list)"
},
{
"docstri... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n wh... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028085",
"row_id": 28085,
"seed_ids": "['Qwen2-72B-Instruct_67246']"
} | 0.695705 | Filter_28085 | I | [
"is_prime",
"divisors",
"analyze_numbers"
] | 3 | [
[
"analyze_numbers",
"divisors"
],
[
"analyze_numbers",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6c802c043e99b804c2c5f5208e7ba49ef57e0bc9 | 7186a5019636669b44517f370e467a05f070e29d | |||
v1.0 | instruct | Filter | Filter_28087_I | Given two integers, implement a Python program to find their LCM (Least Common Multiple) using the GCD (Greatest Common Divisor). Your solution must work for any pair of positive integers and should be efficient, with a time complexity of O(log min(a, b)) where a and b are the two given integers. You are required to wr... | def gcd(a, b):
"""
Returns the Greatest Common Divisor of a and b.
"""
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
"""
Returns the Least Common Multiple of a and b using the Euclidean algorithm for GCD.
"""
return a * b // gcd(a, b) | from solution import gcd, lcm
def test_gcd():
assert gcd(48, 18) == 6
assert gcd(18, 48) == 6
assert gcd(101, 103) == 1
assert gcd(1000000, 2) == 2
def test_lcm():
assert lcm(4, 5) == 20
assert lcm(48, 18) == 144
assert lcm(101, 103) == 10403
assert lcm(1000000, 2) == 1000000
asser... | [
{
"docstring": "Returns the Greatest Common Divisor of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the Least Common Multiple of a and b using the Euclidean algorithm for GCD.",
"function_declaration": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b using the Euclidean algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028087",
"row_id": 28087,
"seed_ids": "['Qwen2-72B-Instruct_67249']"
} | 0.689114 | Filter_28087 | I | [
"gcd",
"lcm"
] | 2 | [
[
"lcm",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 31a84e1b3043b5e1444b1dc1fd3369b2744ca190 | ecc6aff7ddf20e812fe9ba14e0c93ecda8794820 | |||
v1.0 | instruct | Filter | Filter_28088_I | What is the correct syntax for defining a recursive function in Python that calculates the factorial of a given number? Provide the code for the recursive function and also include a code snippet with an intentional error for misdirection. Additionally, include a comment explaining the purpose of each line of code in t... | def factorial(n):
"""
Calculate the factorial of a given number n using recursion.
:param n: An integer for which the factorial is calculated
:return: Factorial of the number n
"""
# Base case: if n is 0 or 1, return 1 since factorial(0) and factorial(1) are 1.
if n == 0 or n == 1:
... | from solution import factorial, faulty_factorial
def test_factorial_base_cases():
assert factorial(0) == 1
assert factorial(1) == 1
def test_factorial_recursive_cases():
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
def test_faulty_fact... | [
{
"docstring": "Calculate the factorial of a given number n using recursion.\n\n:param n: An integer for which the factorial is calculated\n:return: Factorial of the number n",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"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\") # ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028088",
"row_id": 28088,
"seed_ids": "['Qwen2-72B-Instruct_67250']"
} | 0.639983 | Filter_28088 | I | [
"factorial",
"faulty_factorial"
] | 2 | [
[
"faulty_factorial",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d83c0d0d871d0880bef3bdb636bd7a218aedb74c | 49f9b23f35448251a52ee07a38ee6cde256020f8 | |||
v1.0 | instruct | Filter | Filter_28091_I | Create a python function for calculating the area of a triangle given three side lengths. The function should also check if the given side lengths form a valid triangle before calculating the area. | import math
def is_valid_triangle(a, b, c):
"""
Checks if the given sides can form a valid triangle.
"""
return a + b > c and a + c > b and b + c > a
def triangle_area(a, b, c):
"""
Returns the area of a triangle given sides a, b, and c.
First checks if the sides form a valid triangle.
... | from solution import triangle_area, is_valid_triangle
import pytest
def test_is_valid_triangle():
assert is_valid_triangle(3, 4, 5) == True
assert is_valid_triangle(1, 1, 2) == False
assert is_valid_triangle(7, 10, 5) == True
assert is_valid_triangle(3, 7, 3) == False
def test_triangle_area_valid_tria... | [
{
"docstring": "Checks if the given sides can form a valid triangle.",
"function_declaration": "def is_valid_triangle(a, b, c):",
"function_name": "is_valid_triangle",
"parameter_list": "(a, b, c)"
},
{
"docstring": "Returns the area of a triangle given sides a, b, and c.\nFirst checks if th... | [
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_valid_triangle(a, b, c):\n \"\"\"\n Returns True if the given sides form a valid triangle, otherwise False.\n \"\"\"\n return a + b > c and a + c > b and b + ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028091",
"row_id": 28091,
"seed_ids": "['Qwen2-72B-Instruct_67257']"
} | 0.877097 | Filter_28091 | I | [
"is_valid_triangle",
"triangle_area"
] | 2 | [
[
"triangle_area",
"is_valid_triangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dfd178bab6e59fb81272b62426f79a56fb12f20c | d69bfa5f420e09bedd573fc86a14bb6c198248fe | |||
v1.0 | instruct | Filter | Filter_28096_I | Write a function that checks for duplicates in a 2D list. The function should return the coordinates of duplicate elements if any exist. Also, write a function that uses a try/except block to methodically handle scenarios in which the input is not a list or is a list of non-integer/float values. Despite the presence of... | def find_duplicates(matrix):
"""
Finds and returns the coordinates of duplicate elements in a 2D list.
Arguments:
matrix -- the 2D list (list of lists) to check for duplicates
Returns:
List of tuples where each tuple contains the coordinates (row, column) of duplicates
"""
if n... | from solution import find_duplicates, safe_find_duplicates
def test_find_duplicates_with_integers():
matrix = [
[1, 2, 3],
[4, 5, 1],
[2, 6, 7]
]
assert find_duplicates(matrix) == [(1, 2), (0, 0), (2, 0), (0, 1)]
def test_find_duplicates_with_floats():
matrix = [
[1.1, ... | [
{
"docstring": "Finds and returns the coordinates of duplicate elements in a 2D list.\n\nArguments:\nmatrix -- the 2D list (list of lists) to check for duplicates\n\nReturns:\nList of tuples where each tuple contains the coordinates (row, column) of duplicates",
"function_declaration": "def find_duplicates(... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_duplicates(matrix):\n \"\"\"\n Finds and returns the coordinates of duplicate elements in a 2D list.\n Only numbers (integers and floats) will be checked for duplicates.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028096",
"row_id": 28096,
"seed_ids": "['Qwen2-72B-Instruct_67266']"
} | 0.649906 | Filter_28096 | I | [
"find_duplicates",
"safe_find_duplicates"
] | 2 | [
[
"safe_find_duplicates",
"find_duplicates"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 151e49d5cacd7f34d6510a00f9919a659e6a83ad | 64d2acdf266b81b9adab3b22b925a0bca40e138b | |||
v1.0 | instruct | Filter | Filter_28110_I | Develop a procedure to register a fresh client (real name, electronic mail, confidential code, residential location) into a data structure referred to as 'users', also ensure new clients do not reside within prohibited zones. Implement a password strength checker too. | users = []
prohibited_zones = {'ZoneA', 'ZoneB', 'ZoneC'}
def is_strong_password(password):
"""
Check if the provided password is strong.
A strong password should be at least 8 characters long,
contain at least one uppercase letter, one lowercase letter,
one digit, and one special character.
... | from solution import register_client, is_strong_password, users
def test_password_strength():
assert is_strong_password('Strong1!') == True
assert is_strong_password('Weak') == False
assert is_strong_password('short1!') == False
assert is_strong_password('NoDigits!') == False
assert is_strong_passw... | [
{
"docstring": "Check if the provided password is strong. \nA strong password should be at least 8 characters long, \ncontain at least one uppercase letter, one lowercase letter,\none digit, and one special character.",
"function_declaration": "def is_strong_password(password):",
"function_name": "is_st... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "users = []\nprohibited_zones = {'ZoneA', 'ZoneB', 'ZoneC'}\n\ndef is_strong_password(password):\n \"\"\"\n Check if the provided password is strong. \n A strong password should be at ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028110",
"row_id": 28110,
"seed_ids": "['Qwen2-72B-Instruct_67285']"
} | 0.230639 | Filter_28110 | I | [
"is_strong_password",
"register_client"
] | 2 | [
[
"register_client",
"is_strong_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 940a8e5939c5b9b0d73c5c00aee8e1b58b3c6176 | e64f0a3808611a164511ab89397ba9e7b961c3d4 | |||
v1.0 | instruct | Filter | Filter_28120_I | Given a sorted list of integers `lst` and a target number `target`, write a function `find_target_indices` that returns a list of indices where `target` is found in `lst`. If `target` is not found, return an empty list. Your solution should have a time complexity of O(log n) and should not use built-in search functions... | def binary_search_left(lst, target):
left, right = 0, len(lst)
while left < right:
mid = (left + right) // 2
if lst[mid] < target:
left = mid + 1
else:
right = mid
return left
def binary_search_right(lst, target):
left, right = 0, len(lst)
while left ... | from solution import find_target_indices
def test_find_target_indices_single_occurrence():
assert find_target_indices([1, 2, 3, 4, 5], 3) == [2]
def test_find_target_indices_multiple_occurrences():
assert find_target_indices([1, 2, 2, 2, 3, 4, 5], 2) == [1, 2, 3]
def test_find_target_indices_no_occurrence():... | [
{
"docstring": null,
"function_declaration": "def binary_search_left(lst, target):",
"function_name": "binary_search_left",
"parameter_list": "(lst, target)"
},
{
"docstring": null,
"function_declaration": "def binary_search_right(lst, target):",
"function_name": "binary_search_right... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_target_indices(lst, target):\n \"\"\"\n Returns a list of indices where the target is found in the sorted list lst.\n If the target is not found, returns an empty list.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028120",
"row_id": 28120,
"seed_ids": "['Qwen2-72B-Instruct_67304']"
} | 0.550372 | Filter_28120 | I | [
"binary_search_left",
"binary_search_right",
"find_target_indices"
] | 3 | [
[
"find_target_indices",
"binary_search_left"
],
[
"find_target_indices",
"binary_search_right"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2fd1ebafcb81355fce58c543e9bbdcef1b211341 | 5c7bf0f0279a4badb94c6f8f8cb5cf715adf18b5 | |||
v1.0 | instruct | Filter | Filter_28146_I | Write a Python program which includes a feature that can calculate the sum of all the prime numbers from 1 to the user's given number. Additionally, the program should also be able to handle and validate user inputs to ensure they are positive integers. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
def su... | from solution import is_prime, sum_of_primes, validate_input
import pytest
def test_is_prime():
assert is_prime(5) == True
assert is_prime(4) == False
assert is_prime(2) == True
assert is_prime(1) == False
assert is_prime(11) == True
assert is_prime(0) == False
assert is_prime(-3) == False
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of all prime numbers from 1 to 'upto'.",
"function_declaration": "def sum_of_primes(upto):",
"function_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_prime(num):\n \"\"\"\n Check if the number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028146",
"row_id": 28146,
"seed_ids": "['Qwen2-72B-Instruct_67344']"
} | 0.617676 | Filter_28146 | I | [
"is_prime",
"sum_of_primes",
"validate_input"
] | 3 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 24205a59e1ed8d56a35b27d7eeefda46c192739e | 3ec8d1271e6a3e057191bcb29db6d5710ddbd49e | |||
v1.0 | instruct | Filter | Filter_28147_I | Use the given code, which defines a function 'analyze_word' and a list 'words', to write a program that uses the 'analyze_word' function to analyze each word in the 'words' list and print the results. The 'analyze_word' function takes a string as input, reverses it, and returns it. Ensure that the program handles cases... | def analyze_word(word):
"""
Takes a string as input, reverses it, and returns it.
"""
return word[::-1]
def analyze_words(words):
"""
Takes a list of words, analyzes each word using the analyze_word function
and returns a list of the analysis results. It handles non-string elements in the ... | from solution import analyze_word, analyze_words
def test_analyze_word_reverses_string():
assert analyze_word("hello") == "olleh"
assert analyze_word("world") == "dlrow"
def test_analyze_words_with_valid_strings():
words = ["hello", "world"]
expected = ["olleh", "dlrow"]
assert analyze_words(words... | [
{
"docstring": "Takes a string as input, reverses it, and returns it.",
"function_declaration": "def analyze_word(word):",
"function_name": "analyze_word",
"parameter_list": "(word)"
},
{
"docstring": "Takes a list of words, analyzes each word using the analyze_word function \nand returns a ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def analyze_word(word):\n \"\"\"\n Reverses the given word.\n \n Parameters:\n word (str): The word to reverse.\n \n Returns:\n str: The reversed word.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028147",
"row_id": 28147,
"seed_ids": "['Qwen2-72B-Instruct_67345']"
} | 0.578014 | Filter_28147 | I | [
"analyze_word",
"analyze_words"
] | 2 | [
[
"analyze_words",
"analyze_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f09f19b3d22619634baa8ade9df530bea0d61691 | ec58875f5d0e70404b55807d6b95d76d44bb73be | |||
v1.0 | instruct | Filter | Filter_28151_I | Please write a Python function that computes the Lowest Common Multiple (LCM) of an array of integers. In addition, ensure that the solution is optimized for larger number sets and can handle edge cases, such as when the array is empty or includes negative integers. | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Returns the Least Common Multiple of a and b.
"""
if a == 0 or b == 0:
return 0
return abs(a * b) // gcd(a, b)
def lcm_of_array(numbers):
"""
Returns the Least Common Multiple of an array of integers.
"""
... | from solution import lcm_of_array
def test_lcm_of_array_positive_numbers():
assert lcm_of_array([2, 3, 5]) == 30
assert lcm_of_array([1, 2, 3, 4, 5]) == 60
def test_lcm_of_array_with_zero():
assert lcm_of_array([0, 2, 3]) == 0
assert lcm_of_array([0, 0, 0]) == 0
def test_lcm_of_array_negative_numbers... | [
{
"docstring": "Returns the Least Common Multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the Least Common Multiple of an array of integers.",
"function_declaration": "def lcm_of_array(numbers):... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple of a and b.\n \"\"\"\n if a == 0 or b == 0:\n return 0\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028151",
"row_id": 28151,
"seed_ids": "['Qwen2-72B-Instruct_67351']"
} | 0.699324 | Filter_28151 | I | [
"lcm",
"lcm_of_array"
] | 2 | [
[
"lcm_of_array",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 96793b3434c01e1d3750145dcba0b662bf796d8f | 4f87ca5fa5fa6297137a9f1c277f38401390eb32 | |||
v1.0 | instruct | Filter | Filter_28152_I | Given a list of integers, generate two new lists: one in reverse order and one with every second element. Additionally, interleave the two generated lists element-wise, starting with the reversed list. Do not use built-in functions to reverse the list or to get every second element. | def reverse_list(lst):
"""
Returns the reverse of the given list.
"""
reversed_lst = []
for i in range(len(lst) - 1, -1, -1):
reversed_lst.append(lst[i])
return reversed_lst
def every_second_element(lst):
"""
Returns a list containing every second element of the given list.
... | from solution import reverse_list, every_second_element, interleave_lists, process_list
def test_reverse_list():
assert reverse_list([1, 2, 3, 4]) == [4, 3, 2, 1]
assert reverse_list([1]) == [1]
assert reverse_list([]) == []
def test_every_second_element():
assert every_second_element([1, 2, 3, 4]) ==... | [
{
"docstring": "Returns the reverse of the given list.",
"function_declaration": "def reverse_list(lst):",
"function_name": "reverse_list",
"parameter_list": "(lst)"
},
{
"docstring": "Returns a list containing every second element of the given list.",
"function_declaration": "def every_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_list(lst):\n \"\"\"\n Returns the reversed list without using built-in reverse functions.\n \"\"\"\n reversed_list = []\n for i in range(len(lst)-1, -1, -1):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028152",
"row_id": 28152,
"seed_ids": "['Qwen2-72B-Instruct_67352']"
} | 0.696486 | Filter_28152 | I | [
"reverse_list",
"every_second_element",
"interleave_lists",
"process_list"
] | 4 | [
[
"process_list",
"every_second_element"
],
[
"process_list",
"interleave_lists"
],
[
"process_list",
"reverse_list"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b465c1382d8be043f7328687af99fe1e166aad09 | 37c33864f4c839b5dce1b23d93dea7f3aeda8ebd | |||
v1.0 | instruct | Filter | Filter_28156_I | How can I write a Python program to generate unique 12-digit hexadecimal codes, where each code must contain at least one uppercase letter, one lowercase letter, one number, and one special character? Additionally, the program should also be able to check if any generated code is already in use by querying a remote dat... | import random
import string
import requests
def generate_random_code():
characters = string.ascii_letters + string.digits + string.punctuation
while True:
code = ''.join(random.choices(characters, k=12))
if (any(c.isupper() for c in code) and
any(c.islower() for c in code) and
... | def test_generate_random_code_uniqueness():
codes = {generate_random_code() for _ in range(1000)}
assert len(codes) == 1000
def test_generate_random_code_length():
for _ in range(1000):
assert len(generate_random_code()) == 12
def test_generate_random_code_contains_uppercase():
for _ in range(... | [
{
"docstring": null,
"function_declaration": "def generate_random_code():",
"function_name": "generate_random_code",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def is_code_in_use(code):",
"function_name": "is_code_in_use",
"parameter_list": "(code)"
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\nimport requests\nfrom time import sleep\n\ndef generate_hex_code():\n while True:\n code = ''.join(random.choices(string.ascii_letters + string.digits +... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028156",
"row_id": 28156,
"seed_ids": "['Qwen2-72B-Instruct_67359']"
} | 0.546549 | Filter_28156 | I | [
"generate_random_code",
"is_code_in_use",
"generate_unique_codes"
] | 3 | [
[
"generate_unique_codes",
"generate_random_code"
],
[
"generate_unique_codes",
"is_code_in_use"
]
] | 2 | [] | false | [] | false | pytest | false | [
"requests"
] | false | 9dd3a9f2e83af032e6fa6f8d491b88d3169b633e | bdae6afe0ebc9d53459115eccf07c9f94c8ebf20 | |||
v1.0 | instruct | Filter | Filter_28176_I | Write a python program to implement the Sieve of Eratosthenes algorithm and find all the prime numbers between 1 to 50. Then, modify the program so that it can efficiently find and return all 'n' prime numbers instead, where 'n' is a user-provided input. | def sieve_of_eratosthenes(limit):
"""
Returns a list of all prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.
"""
if limit < 2:
return []
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(limit ** 0.5) + 1):
... | from solution import sieve_of_eratosthenes, find_n_primes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(50) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(0)... | [
{
"docstring": "Returns a list of all prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns a list of the f... | [
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(limit):\n \"\"\"\n Returns a list of all prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n primes = []\n is_pri... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028176",
"row_id": 28176,
"seed_ids": "['Qwen2-72B-Instruct_67392']"
} | 0.609789 | Filter_28176 | I | [
"sieve_of_eratosthenes",
"find_n_primes"
] | 2 | [
[
"find_n_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ff95f7fd836de32324fba8e04ead502f09d962f | 4cfb3a194d0517a64c4910cb4f59cae7b23f20af | |||
v1.0 | instruct | Filter | Filter_28240_I | Develop a Python function that utilizes the binary search technique for sorted data lists and handles exceptions for unsorted lists and non-integer values as well. To make it more complex, the function should also prompt the user for the value they want to search for and provide an appropriate response whether the valu... | def binary_search(data, target):
"""
Performs binary search on sorted data to find the target value.
Raises ValueError if data is not sorted or contains non-integer values.
"""
if any(not isinstance(x, int) for x in data):
raise ValueError("Data contains non-integer values")
if data... | import pytest
from solution import binary_search
def test_binary_search_found():
assert binary_search([1, 2, 3, 4, 5], 3) == 2
def test_binary_search_not_found():
assert binary_search([1, 2, 3, 4, 5], 6) == -1
def test_binary_search_unsorted_list():
with pytest.raises(ValueError, match="Data is not sorte... | [
{
"docstring": "Performs binary search on sorted data to find the target value.\nRaises ValueError if data is not sorted or contains non-integer values.",
"function_declaration": "def binary_search(data, target):",
"function_name": "binary_search",
"parameter_list": "(data, target)"
},
{
"do... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_search(data, target):\n \"\"\"\n Performs binary search on sorted data to find the target value.\n Raises ValueError if data is not sorted or contains non-integer values.\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028240",
"row_id": 28240,
"seed_ids": "['Qwen2-72B-Instruct_67495']"
} | 0.618184 | Filter_28240 | I | [
"binary_search",
"search_value"
] | 2 | [
[
"search_value",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fab91ff753102cb20379274b97ac504850b65727 | a709107c9c759ee6b95daacd6719b8d825a2200a | |||
v1.0 | instruct | Filter | Filter_28244_I | How can I generate a list of all possible anagrams using letters from multiple words in a given list, and ensure that the output only contains real English words? Please provide a Python code that takes a list of words as input and outputs a list of anagrams. You may use an English dictionary API to verify if a generat... | import itertools
import requests
# API URL for checking if a word is a valid English word
API_URL = "https://api.dictionaryapi.dev/api/v2/entries/en/"
def is_real_word(word):
response = requests.get(API_URL + word)
return response.status_code == 200
def generate_anagrams(word_list):
# Generate all possib... | from solution import generate_anagrams, is_real_word
def mock_is_real_word(word):
# Mock function for unit testing without calling the real API
valid_words = {"stop", "pots", "tops", "opts", "spot"}
return word in valid_words
def generate_anagrams_testable(word_list):
# Use the mock function instead o... | [
{
"docstring": null,
"function_declaration": "def is_real_word(word):",
"function_name": "is_real_word",
"parameter_list": "(word)"
},
{
"docstring": null,
"function_declaration": "def generate_anagrams(word_list):",
"function_name": "generate_anagrams",
"parameter_list": "(word_... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport requests\n\n# API URL for checking if a word is a valid English word\nAPI_URL = \"https://api.dictionaryapi.dev/api/v2/entries/en/\"\n\ndef is_real_word(word):\n re... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028244",
"row_id": 28244,
"seed_ids": "['Qwen2-72B-Instruct_67501']"
} | 0.596583 | Filter_28244 | I | [
"is_real_word",
"generate_anagrams"
] | 2 | [
[
"generate_anagrams",
"is_real_word"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | adff68219da94da79134cf929e382ab9c448d5aa | c30cdf0240276c58e6ce00fdf201ebfa12d2e471 | |||
v1.0 | instruct | Filter | Filter_28258_I | Write a python program to print all prime numbers 1 to n. | def is_prime(num):
"""
Helper function to check if a number is prime.
Returns True if num is prime, else False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
limit = int(num ** 0.5) + 1
for i in range(3, limit, 2):
... | from solution import primes_up_to_n
def test_primes_up_to_10():
assert primes_up_to_n(10) == [2, 3, 5, 7]
def test_primes_up_to_1():
assert primes_up_to_n(1) == []
def test_primes_up_to_20():
assert primes_up_to_n(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_primes_up_to_0():
assert primes_up_to_n(0... | [
{
"docstring": "Helper function to check if a number is prime.\nReturns True if num is prime, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers from 1 to n (inclusive).",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if num is prime, else False.\n \"\"\"\n if num <= 1:\n return False\n if nu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028258",
"row_id": 28258,
"seed_ids": "['Qwen2-72B-Instruct_67522']"
} | 0.714528 | Filter_28258 | I | [
"is_prime",
"primes_up_to_n"
] | 2 | [
[
"primes_up_to_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2db532b9403720be505791cc4a18ffe15d25409f | 541b2f3659b3d12de25870179045328658196adf | |||
v1.0 | instruct | Filter | Filter_28263_I | Write a Python program to generate a set of pseudo-random numbers with a uniform distribution between -1 and 1 using the Mersenne Twister algorithm, and then apply a transformation function that follows a normal distribution with mean 0 and standard deviation 1, resulting in a set of normally distributed random numbers... | import random
import math
def generate_uniform_random_numbers(n):
"""Generate a set of n uniformly distributed random numbers between -1 and 1."""
random_numbers = [random.uniform(-1, 1) for _ in range(n)]
return random_numbers
def transform_to_normal_distribution(uniform_random_numbers):
"""Transform... | from solution import generate_uniform_random_numbers, transform_to_normal_distribution, generate_normal_random_numbers
import numpy as np
def test_generate_uniform_random_numbers_length():
uniform_random_numbers = generate_uniform_random_numbers(1000)
assert len(uniform_random_numbers) == 1000
def test_genera... | [
{
"docstring": "Generate a set of n uniformly distributed random numbers between -1 and 1.",
"function_declaration": "def generate_uniform_random_numbers(n):",
"function_name": "generate_uniform_random_numbers",
"parameter_list": "(n)"
},
{
"docstring": "Transform a set of uniformly distribu... | [
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 generate_normal_random_numbers(n):\n \"\"\"\n Generates `n` normally distributed random numbers with mean 0 and standard deviation 1.\n\n Args:\n n (int):... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028263",
"row_id": 28263,
"seed_ids": "['Qwen2-72B-Instruct_67531']"
} | 0.535605 | Filter_28263 | I | [
"generate_uniform_random_numbers",
"transform_to_normal_distribution",
"generate_normal_random_numbers"
] | 3 | [
[
"generate_normal_random_numbers",
"generate_uniform_random_numbers"
],
[
"generate_normal_random_numbers",
"transform_to_normal_distribution"
]
] | 2 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 6fb0d799949ded6fffe149805b5b49cc48557c89 | 032807c68a016aefd5169a503f7b386d49f7d893 | |||
v1.0 | instruct | Filter | Filter_28269_I | Can you code a function for the language Python that solves the task of finding the smallest common multiple (also known as Least Common Multiple, LCM) for a list of numbers? Additionally, implement an efficient algorithm for handling large input sets. The function should return the LCM for all numbers in the input lis... | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Returns the Least Common Multiple (LCM) of two numbers a and b.
"""
return abs(a * b) // gcd(a, b)
def lcm_of_list(numbers):
"""
Returns the LCM of a list of numbers.
"""
if not all(isinstance(x, (int, float)) for x i... | from solution import lcm_of_list
def test_lcm_of_small_numbers():
assert lcm_of_list([4, 6]) == 12
assert lcm_of_list([3, 5, 7]) == 105
assert lcm_of_list([1, 2, 3, 4, 5]) == 60
def test_lcm_of_large_numbers():
assert lcm_of_list([100, 200, 300]) == 600
assert lcm_of_list([12, 15, 35]) == 420
def... | [
{
"docstring": "Returns the Least Common Multiple (LCM) of two numbers a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the LCM of a list of numbers.",
"function_declaration": "def lcm_of_list(numbers):",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"Return the least common multiple of a and b.\"\"\"\n return a * b // gcd(a, b)\n\ndef lcm_for_list(numbers):\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028269",
"row_id": 28269,
"seed_ids": "['Qwen2-72B-Instruct_67540']"
} | 0.688066 | Filter_28269 | I | [
"lcm",
"lcm_of_list"
] | 2 | [
[
"lcm_of_list",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b7b1afb65980ed393cca2803b39a5d8ed5cd963 | 39a70801fe5a82118a35761a43f3fc936ed84a66 | |||
v1.0 | instruct | Filter | Filter_28273_I | Develop a Python function that determines the phase of the moon for any specified date in the Gregorian calendar. Your function should also account for any potential leap years, and should calculate the phase based on the date provided without using any built-in or external lunar phase calculation libraries. Additional... | import datetime
def moon_phase_on_date(year, month, day):
"""
Determines the phase of the moon for a given date.
Parameters:
year (int): The year of the date.
month (int): The month of the date.
day (int): The day of the date.
Returns:
str: The lunar phase.
"""
date = ... | import datetime
from solution import moon_phase_on_date
def test_known_new_moon():
assert moon_phase_on_date(2000, 1, 6) == 'New Moon'
def test_first_quarter():
assert moon_phase_on_date(2000, 1, 12) == 'First Quarter'
def test_full_moon():
assert moon_phase_on_date(2000, 1, 20) == 'Full Moon'
def test_... | [
{
"docstring": "Determines the phase of the moon for a given date.\n\nParameters:\nyear (int): The year of the date.\nmonth (int): The month of the date.\nday (int): The day of the date.\n\nReturns:\nstr: The lunar phase.",
"function_declaration": "def moon_phase_on_date(year, month, day):",
"function_n... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def moon_phase(year, month, day):\n \"\"\"\n Determines the phase of the moon for a given date.\n \n Args:\n year (int): Year of the date.\n month (int): Month of the date.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028273",
"row_id": 28273,
"seed_ids": "['Qwen2-72B-Instruct_67544']"
} | 0.704298 | Filter_28273 | I | [
"moon_phase_on_date",
"get_user_input_for_moon_phase"
] | 2 | [
[
"get_user_input_for_moon_phase",
"moon_phase_on_date"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71694d635a5705fabcb57c811f85183820ceef6e | b19c3760b0b1119e0208be5a3ba61a522ec77e30 | |||
v1.0 | instruct | Filter | Filter_28287_I | Write code to parse a given IP address into its octets, convert each octet into its binary representation using bitwise operations, and then calculate the sum of all the binary values. | def ip_to_octets(ip):
"""
Parses the given IP address into its octets.
"""
return [int(octet) for octet in ip.split('.')]
def octet_to_binary(octet):
"""
Converts an octet into its binary representation using bitwise operations.
"""
binary = ""
for i in range(7, -1, -1):
bin... | from solution import ip_to_octets, octet_to_binary, sum_binary_values
def test_ip_to_octets():
assert ip_to_octets("192.168.1.1") == [192, 168, 1, 1]
assert ip_to_octets("255.255.255.255") == [255, 255, 255, 255]
assert ip_to_octets("0.0.0.0") == [0, 0, 0, 0]
def test_octet_to_binary():
assert octet_t... | [
{
"docstring": "Parses the given IP address into its octets.",
"function_declaration": "def ip_to_octets(ip):",
"function_name": "ip_to_octets",
"parameter_list": "(ip)"
},
{
"docstring": "Converts an octet into its binary representation using bitwise operations.",
"function_declaration"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ip_to_octets(ip):\n \"\"\"\n Parses the given IP address into its octets.\n \"\"\"\n return [int(octet) for octet in ip.split('.')]\n\ndef octet_to_binary(octet):\n \"\"\"\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028287",
"row_id": 28287,
"seed_ids": "['Qwen2-72B-Instruct_67567']"
} | 0.481103 | Filter_28287 | I | [
"ip_to_octets",
"octet_to_binary",
"sum_binary_values"
] | 3 | [
[
"sum_binary_values",
"ip_to_octets"
],
[
"sum_binary_values",
"octet_to_binary"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c0bc899e721f43670109d8a6892b7668c6e73293 | 7c2f5b49848411a10b9af6483f658048af991e4a | |||
v1.0 | instruct | Filter | Filter_28291_I | Can you implement a function to invert a binary tree in Python, and then modify it to return a mirrored version of the same tree? Additionally, provide a short explanation of how to invert and mirror a binary tree. | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def invert_tree(root):
"""
Inverts a binary tree such that the left and right children of all nodes are swapped.
"""
if root is None:
return Non... | from solution import TreeNode, invert_tree, mirror_tree
def test_invert_tree():
# Construct the initial binary tree
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root.left.right = TreeNode(5)
root.right.left = TreeNode(6)
root.right.rig... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef invert_tree(root):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028291",
"row_id": 28291,
"seed_ids": "['Qwen2-72B-Instruct_67573']"
} | 0.500574 | Filter_28291 | I | [
"invert_tree",
"mirror_tree"
] | 2 | [
[
"mirror_tree",
"invert_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1e9d51cc3a7a7f36d18f9656de9d7a55cbdaf3e4 | 623df95021900eb344152b94f37d8d0d2c82f517 | |||
v1.0 | instruct | Filter | Filter_28299_I | Implement a modified version of the quicksort algorithm to sort a large, unsorted integer array. The modified quicksort algorithm should use the median of three pivot selection strategy to improve its efficiency. Additionally, the algorithm should be implemented in a way that avoids recursive calls and instead uses an ... | def median_of_three(arr, low, high):
mid = (low + high) // 2
if arr[low] > arr[mid]:
arr[low], arr[mid] = arr[mid], arr[low]
if arr[low] > arr[high]:
arr[low], arr[high] = arr[high], arr[low]
if arr[mid] > arr[high]:
arr[mid], arr[high] = arr[high], arr[mid]
return mid
def p... | from solution import quicksort
def test_quicksort_empty_array():
assert quicksort([]) == []
def test_quicksort_single_element():
assert quicksort([1]) == [1]
def test_quicksort_sorted_array():
assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_quicksort_reverse_sorted_array():
assert quic... | [
{
"docstring": null,
"function_declaration": "def median_of_three(arr, low, high):",
"function_name": "median_of_three",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def median_of_three(arr, low, mid, high):\n if arr[low] > arr[mid]:\n arr[low], arr[mid] = arr[mid], arr[low]\n if arr[low] > arr[high]:\n arr[low], arr[high] = arr[high], ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028299",
"row_id": 28299,
"seed_ids": "['Qwen2-72B-Instruct_67585']"
} | 0.522111 | Filter_28299 | I | [
"median_of_three",
"partition",
"quicksort"
] | 3 | [
[
"partition",
"median_of_three"
],
[
"quicksort",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 21a078e2866010e691e69f8ac5cb14bbd26f55bb | 52e3c2a6524220dd5e70017b3f22ce499defe17d | |||
v1.0 | instruct | Filter | Filter_28303_I | Similar to the provided code, create a method that calculates the number of days between two dates. However, instead of using the datetime module, use the calendar module to perform the calculation. Also, consider the case where one or both of the input dates are invalid. In such situations, the function should return ... | import calendar
def is_valid_date(mm, dd, yyyy):
"""
Checks if the provided date is valid.
"""
if yyyy < 1 or mm < 1 or mm > 12 or dd < 1 or dd > 31:
return False
if dd > calendar.monthrange(yyyy, mm)[1]:
return False
return True
def days_in_year_days(year):
"""
... | from solution import days_between_dates
def test_days_between_same_dates():
assert days_between_dates("01/01/2020", "01/01/2020") == 0
def test_days_between_adjacent_days():
assert days_between_dates("01/01/2020", "01/02/2020") == 1
def test_days_between_normal_dates():
assert days_between_dates("01/01/2... | [
{
"docstring": "Checks if the provided date is valid.",
"function_declaration": "def is_valid_date(mm, dd, yyyy):",
"function_name": "is_valid_date",
"parameter_list": "(mm, dd, yyyy)"
},
{
"docstring": "Returns the number of days in a year.",
"function_declaration": "def days_in_year_da... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import calendar\n\ndef is_valid_date(mm, dd, yyyy):\n \"\"\"\n Checks if the provided date is valid.\n \"\"\"\n if yyyy < 1 or mm < 1 or mm > 12 or dd < 1 or dd > 31:\n retu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028303",
"row_id": 28303,
"seed_ids": "['Qwen2-72B-Instruct_67593']"
} | 0.593797 | Filter_28303 | I | [
"is_valid_date",
"days_in_year_days",
"date_to_ordinal",
"days_between_dates"
] | 4 | [
[
"date_to_ordinal",
"days_in_year_days"
],
[
"days_between_dates",
"date_to_ordinal"
],
[
"days_between_dates",
"is_valid_date"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ed0b6f2c916ad83e52174ac6373f9d8d8f0837c7 | 1a1e055a1a5499d593de913c72e748824b390b3c | |||
v1.0 | instruct | Filter | Filter_28306_I | Develop a Python function that can identify Fibonacci numbers from a list of integers, including negative integers and floating point numbers. This function should be designed to handle exceptions for non-numeric inputs, empty lists, and should distinguish between Fibonacci numbers, non-Fibonacci numbers, and non-integ... | import math
def is_fibonacci_number(n):
"""
Check if a number is a Fibonacci number by using the property that
a number x is a Fibonacci number if and only if one or both of
(5 * x^2 + 4) or (5 * x^2 - 4) is a perfect square.
"""
if n < 0:
return False
x1 = 5 * n * n + 4
x2 = ... | from solution import analyze_numbers
def test_analyze_numbers_basic():
lst = [8, 2, 10, 1, 13, 21]
result = analyze_numbers(lst)
assert result["fibonacci_numbers"] == [{'value': 8, 'position': 0},
{'value': 2, 'position': 1},
... | [
{
"docstring": "Check if a number is a Fibonacci number by using the property that \na number x is a Fibonacci number if and only if one or both of \n(5 * x^2 + 4) or (5 * x^2 - 4) is a perfect square.",
"function_declaration": "def is_fibonacci_number(n):",
"function_name": "is_fibonacci_number",
"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_fibonacci(n):\n \"\"\"\n Checks if a given number is a Fibonacci number.\n \"\"\"\n if n < 0:\n return False\n x, y = 0, 1\n while y < n:\n x, y = y, x +... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028306",
"row_id": 28306,
"seed_ids": "['Qwen2-72B-Instruct_67597']"
} | 0.781835 | Filter_28306 | I | [
"is_fibonacci_number",
"is_perfect_square",
"analyze_numbers"
] | 3 | [
[
"analyze_numbers",
"is_fibonacci_number"
],
[
"is_fibonacci_number",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 86ac2e2603f7570fe89050fde778631bae460b9e | d41b9fd2330674f3fa24b8f32a1b40d82ea7a0a7 | |||
v1.0 | instruct | Filter | Filter_28315_I | Write a Python function that takes a list of strings as an argument and returns a dictionary where each string is a key and the value is the number of vowels in the string. The dictionary should be sorted by the values in descending order. | def count_vowels(s):
"""
Helper function to count vowels in a single string.
"""
vowels = 'aeiouAEIOU'
return sum(1 for char in s if char in vowels)
def vowels_in_strings(strings_list):
"""
Takes a list of strings and returns a dictionary where each string is a key
and the value is the... | from solution import vowels_in_strings
def test_vowels_in_strings_simple_case():
assert vowels_in_strings(["hello", "world"]) == {"hello": 2, "world": 1}
def test_vowels_in_strings_single_string_with_vowels():
assert vowels_in_strings(["education"]) == {"education": 5}
def test_vowels_in_strings_empty_list()... | [
{
"docstring": "Helper function to count vowels in a single string.",
"function_declaration": "def count_vowels(s):",
"function_name": "count_vowels",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a dictionary where each string is a key \nand the value is the... | [
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 \"\"\"\n Helper function to count the number of vowels in a string.\n \"\"\"\n return sum(1 for char in s.lower() if char in 'aeiou')\n\ndef strings_to_vowel... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028315",
"row_id": 28315,
"seed_ids": "['Qwen2-72B-Instruct_67607']"
} | 0.78948 | Filter_28315 | I | [
"count_vowels",
"vowels_in_strings"
] | 2 | [
[
"vowels_in_strings",
"count_vowels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6234f2b9ec9a6de5e790456adcb6a75150bd2e62 | 332bb663a8a8d0b885394bef2b30521599ebc43e | |||
v1.0 | instruct | Filter | Filter_28316_I | Write a return statement for a function that adds two numbers and returns the result. However, the function should also check if the sum is a prime number and return a tuple containing the sum and a boolean value indicating whether it is prime or not. | def is_prime(n):
"""
Checks 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
i += 6
return T... | from solution import add_and_check_prime
def test_add_and_check_prime_positive_numbers():
assert add_and_check_prime(2, 3) == (5, True)
def test_add_and_check_prime_with_zero():
assert add_and_check_prime(0, 5) == (5, True)
assert add_and_check_prime(5, 0) == (5, True)
def test_add_and_check_prime_negati... | [
{
"docstring": "Checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Adds two numbers a and b and returns a tuple containing the sum and\na boolean indicating whether the sum is a prime number.",
... | [
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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028316",
"row_id": 28316,
"seed_ids": "['Qwen2-72B-Instruct_67609']"
} | 0.669621 | Filter_28316 | I | [
"is_prime",
"add_and_check_prime"
] | 2 | [
[
"add_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2c3e1a322e82543ad7d97e86ff8a7ce676c46944 | 5ed2521679da689c2cc6e0a9f0b2267acd581c55 | |||
v1.0 | instruct | Filter | Filter_28326_I | Write a script in Python that will find the average of a list of numbers. However, the list may contain both integers and strings. Your script should handle this situation by excluding any strings from the calculation and considering only the numbers in the list. The script should also handle cases where the list conta... | def flatten_and_filter_numbers(input_list):
"""
Flatten the nested list structure and filter out non-numeric values.
Args:
input_list (list): The nested input list containing integers, strings, and other lists.
Returns:
list: A flattened list containing only the numeric values.
"""... | from solution import calculate_average
def test_average_of_flat_list_with_numbers_and_strings():
assert calculate_average([1, 2, '3', 4, 'test']) == 2.3333333333333335
def test_average_with_no_numbers():
assert calculate_average(['a', 'b', 'c']) == 0.0
def test_average_with_nested_lists():
assert calcula... | [
{
"docstring": "Flatten the nested list structure and filter out non-numeric values.\n\nArgs:\ninput_list (list): The nested input list containing integers, strings, and other lists.\n\nReturns:\nlist: A flattened list containing only the numeric values.",
"function_declaration": "def flatten_and_filter_num... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def average_of_numbers(data):\n \"\"\"\n Calculate the average of numbers in a list, ignoring strings and flattening nested lists.\n \"\"\"\n def flatten(data):\n for item i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028326",
"row_id": 28326,
"seed_ids": "['Qwen2-72B-Instruct_67626']"
} | 0.627192 | Filter_28326 | I | [
"flatten_and_filter_numbers",
"calculate_average"
] | 2 | [
[
"calculate_average",
"flatten_and_filter_numbers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 530633ded6b3f615e5cace4e78a263ba1b6d2b91 | 74401c4841a96e98eca3e24f383fadd70c822fba | |||
v1.0 | instruct | Filter | Filter_28335_I | Develop a Python function that calculates the product of all prime numbers less than or equal to n. Also, modify the function to return the product modulo m, where m is a large prime number (e.g. 10^9+7). Consider edge cases, such as when n is less than 2, and handle errors and exceptions gracefully. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import is_prime, product_of_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(18) == False
def test_product_of_primes():
assert product_of_primes(10) == 210 # Primes are 2, 3,... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the product of all prime numbers less than or equal to n, modulo m.",
"function_declaration": "... | [
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(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028335",
"row_id": 28335,
"seed_ids": "['Qwen2-72B-Instruct_67639']"
} | 0.614773 | Filter_28335 | I | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7fca73be07ebda804b443f232c8657c24a9b8974 | f03f515bcae2f0fbdeef266591be86eea06f8c37 | |||
v1.0 | instruct | Filter | Filter_28337_I | You have a large file that you need to process line by line, and for each line, you need to extract all the email addresses. The email addresses can be in various formats, but they all must follow the standard pattern of "username@domain.extension". The username can contain uppercase and lowercase letters, digits, dots... | import re
def extract_emails(text):
"""
Extracts and returns all email addresses from the given text.
"""
email_pattern = r'\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,63}\.[A-Za-z]{2,6}\b'
return re.findall(email_pattern, text)
# A sample code snippet to process text string
def process_large_text(te... | from solution import extract_emails, process_large_text
def test_extract_emails_simple():
text = "Contact us at support@example.com for more details."
assert extract_emails(text) == ["support@example.com"]
def test_extract_emails_multiple():
text = "Send emails to alice@example.com, bob.smith@another-exam... | [
{
"docstring": "Extracts and returns all email addresses from the given text.",
"function_declaration": "def extract_emails(text):",
"function_name": "extract_emails",
"parameter_list": "(text)"
},
{
"docstring": "Processes the given text line by line to extract email addresses.",
"funct... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef extract_emails(text):\n \"\"\"\n Extracts all email addresses from the given text.\n \n Args:\n text (str): The input string containing email addresses.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028337",
"row_id": 28337,
"seed_ids": "['Qwen2-72B-Instruct_67641']"
} | 0.624478 | Filter_28337 | I | [
"extract_emails",
"process_large_text"
] | 2 | [
[
"process_large_text",
"extract_emails"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f30d8d5bd3baf36fd765728f7e546d6ffc576c5 | 81796f255b21358c80db6226f999a1f4b7076a91 | |||
v1.0 | instruct | Filter | Filter_28342_I | Using tree sort algorithm, sort the following array of numbers in ascending order. Detect any possible edge cases in this array that may affect the sorting process, such as repeated numbers, negative numbers or null values and explicitly handle them in your implementation. Implement your solution in Python. | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.right = insert(root.right, key)
else:
root.left = ins... | from solution import tree_sort
def test_tree_sort_with_positive_numbers():
assert tree_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]
def test_tree_sort_with_negative_numbers():
assert tree_sort([0, -1, -3, 2, 2, -1, 5, 3]) == [-3, -1, -1, 0, 2, 2, 3, 5]
def test_tree_sort_with_... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n \"\"\"\n Inserts a new node with th... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028342",
"row_id": 28342,
"seed_ids": "['Qwen2-72B-Instruct_67646']"
} | 0.627443 | Filter_28342 | I | [
"insert",
"inorder_traversal",
"tree_sort"
] | 3 | [
[
"tree_sort",
"inorder_traversal"
],
[
"tree_sort",
"insert"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e97e141f944bace3bd22cb421d6474bcfd26927d | b260ec417e3a7463af87418f514fa51e89950959 | |||
v1.0 | instruct | Filter | Filter_28353_I | Write a script to generate a random string of a user-specified length. The string should only include alphanumeric characters. The script should also provide the option to include or exclude uppercase and lowercase letters and digits. Additionally, the script should allow the user to generate multiple random strings at... | import random
import string
def generate_random_string(length, include_uppercase=True, include_lowercase=True, include_digits=True):
"""
Generates a random string of the specified length.
Parameters:
- length (int): The length of the random string.
- include_uppercase (bool): Whether to includ... | from solution import generate_random_string, generate_multiple_random_strings
def test_generate_random_string_length():
assert len(generate_random_string(10)) == 10
def test_generate_random_string_uppercase():
result = generate_random_string(10, include_lowercase=False, include_digits=False)
assert result... | [
{
"docstring": "Generates a random string of the specified length.\n\nParameters:\n- length (int): The length of the random string.\n- include_uppercase (bool): Whether to include uppercase letters in the random string.\n- include_lowercase (bool): Whether to include lowercase letters in the random string.\n- i... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_random_string(length, include_uppercase=True, include_lowercase=True, include_digits=True):\n \"\"\"\n Generates a random string of specified... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028353",
"row_id": 28353,
"seed_ids": "['Qwen2-72B-Instruct_67664']"
} | 0.704016 | Filter_28353 | I | [
"generate_random_string",
"generate_multiple_random_strings"
] | 2 | [
[
"generate_multiple_random_strings",
"generate_random_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f1e3670b65d15bbff78961ca30db2d37afbd389 | 70a54404f9b9ed6da6fef22610ac63e82e592ed7 | |||
v1.0 | instruct | Filter | Filter_28359_I | Develop a Python function that calculates the aggregate quantity of prime numbers within a specified list. This function must be equipped to process substantial lists efficiently. Furthermore, the function should be capable of recognizing and ignoring non-integer and negative values within the list. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import count_primes
def test_count_primes_with_mixed_values():
assert count_primes([2, 3, 4, 5, 6, "seven", 11, -13, 14]) == 4
def test_count_primes_with_only_primes():
assert count_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 10
def test_count_primes_with_no_primes():
assert count_p... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the aggregate quantity of prime numbers within a specified list.\nIgnores non-integer and negati... | [
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 Helper function to determine 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 %... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028359",
"row_id": 28359,
"seed_ids": "['Qwen2-72B-Instruct_67670']"
} | 0.710626 | Filter_28359 | I | [
"is_prime",
"count_primes"
] | 2 | [
[
"count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e893a08eea883de59f37a2f5e6a6f8ad3514ece8 | 4a30b523cdcb68bd75a0b1d8cc57c6aa43b51699 | |||
v1.0 | instruct | Filter | Filter_28365_I | Develop a cryptographic hash function in Python that also includes a salting feature to add more security. Explain how it can be used in securely storing passwords. | import hashlib
import os
def hash_password(password, salt=None):
"""
Hashes a password with an optional salt for added security.
:param password: The password to be hashed.
:param salt: Optional salt. If not provided, a new salt will be generated.
:return: A tuple (salt, hashed_password) where... | from solution import hash_password, verify_password
def test_hash_password_creates_salt():
password = "secure_password"
salt, hashed = hash_password(password)
assert salt is not None
assert hashed is not None
assert len(salt) == 32 # 16 bytes in hex is 32 characters
def test_hash_password_with_pr... | [
{
"docstring": "Hashes a password with an optional salt for added security.\n\n:param password: The password to be hashed.\n:param salt: Optional salt. If not provided, a new salt will be generated.\n:return: A tuple (salt, hashed_password) where both are hex-encoded strings.",
"function_declaration": "def ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\nimport os\n\ndef hash_password(password, salt=None):\n \"\"\"\n Hashes a password with an optional salt using SHA-256.\n \n :param password: The password to hash.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028365",
"row_id": 28365,
"seed_ids": "['Qwen2-72B-Instruct_67679']"
} | 0.615632 | Filter_28365 | I | [
"hash_password",
"verify_password"
] | 2 | [
[
"verify_password",
"hash_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a081f7f8ed9374ce7a5913fb7b713211850cc06e | 1f57ccd5633077851a49a478871f00a330cd2219 | |||
v1.0 | instruct | Filter | Filter_28371_I | Iterate through the given array and print the prime numbers in ascending order. Additionally, ensure that the program runs in O(n) time complexity and uses only constant extra space. | def is_prime(n):
"""
Helper function to check if a number is 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:
return False... | from solution import primes_in_ascending_order
def test_primes_in_positive_integers():
assert primes_in_ascending_order([3, 5, 1, 4, 2, 6]) == [2, 3, 5]
def test_primes_with_duplicates_and_non_primes():
assert primes_in_ascending_order([11, 4, 8, 11, 23, 15, 17]) == [11, 11, 17, 23]
def test_primes_in_empty_... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given an array, returns the prime numbers in ascending order.\nEnsure the program runs in O(n) time complexity ... | [
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(max_num):\n \"\"\"\n Implements the sieve of Eratosthenes to return a boolean array where True denotes that \n the index is a prime number.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028371",
"row_id": 28371,
"seed_ids": "['Qwen2-72B-Instruct_67686']"
} | 0.632012 | Filter_28371 | I | [
"is_prime",
"primes_in_ascending_order"
] | 2 | [
[
"primes_in_ascending_order",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8290b2aec5587ee157abacf92b37fc1f72d0dd02 | 0b8a437ad55fe06c585cfe81b9975f58dea1ff6b | |||
v1.0 | instruct | Filter | Filter_28403_I | Write a Python program that takes an integer as input and checks if it's a prime number. If it is prime, the program should print "The number is prime." If not, it should print "The number is not prime." Additionally, the program should also list all factors of the number it is being checked. Lastly, include a function... | def is_prime(n):
"""
Checks 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
i... | from solution import is_prime, list_factors, next_prime, prime_check_and_factors
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == ... | [
{
"docstring": "Checks if the given integer n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Lists all factors of the given integer n.",
"function_declaration": "def list_factors(n):",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if the given integer 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 ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028403",
"row_id": 28403,
"seed_ids": "['Qwen2-72B-Instruct_67743']"
} | 0.778542 | Filter_28403 | I | [
"is_prime",
"list_factors",
"next_prime",
"prime_check_and_factors"
] | 4 | [
[
"next_prime",
"is_prime"
],
[
"prime_check_and_factors",
"is_prime"
],
[
"prime_check_and_factors",
"list_factors"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 90652dbdb1784e3cb8c6080b1bc762e1a79ca83f | dd0420b2fb3c4ba48ec331185753e4321b043385 | |||
v1.0 | instruct | Filter | Filter_28424_I | Formulate a Boolean function that not only evaluates if the provided sequence of alphanumeric characters is a mirror image of itself, also known as a palindrome, but also validates if the input is in fact a valid alphanumeric string. Check for the absence of special characters, whitespace and ensure that string is not ... | def is_valid_alphanumeric(s):
"""
Check if the input string is a valid alphanumeric string.
"""
return s.isalnum() and not any(char.isspace() for char in s)
def is_palindrome(s):
"""
Check if the provided alphanumeric string is a palindrome.
"""
if not is_valid_alphanumeric(s):
... | from solution import is_valid_palindrome, is_valid_alphanumeric, is_palindrome
def test_is_valid_alphanumeric():
assert is_valid_alphanumeric("A1B2C3") == True
assert is_valid_alphanumeric("123") == True
assert is_valid_alphanumeric("abc") == True
assert is_valid_alphanumeric("A B C") == False
asse... | [
{
"docstring": "Check if the input string is a valid alphanumeric string.",
"function_declaration": "def is_valid_alphanumeric(s):",
"function_name": "is_valid_alphanumeric",
"parameter_list": "(s)"
},
{
"docstring": "Check if the provided alphanumeric string is a palindrome.",
"function... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_alphanumeric_string(s):\n \"\"\"\n Validates if the string is composed of only alphanumeric characters and is not empty.\n \"\"\"\n return bool(re.match(\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028424",
"row_id": 28424,
"seed_ids": "['Qwen2-72B-Instruct_67775']"
} | 0.610008 | Filter_28424 | I | [
"is_valid_alphanumeric",
"is_palindrome",
"is_valid_palindrome"
] | 3 | [
[
"is_palindrome",
"is_valid_alphanumeric"
],
[
"is_valid_palindrome",
"is_palindrome"
],
[
"is_valid_palindrome",
"is_valid_alphanumeric"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ab4200166858ddae184f312cc7a6221acc205480 | 41b7e68817fef2c87a11f12e089ff6432a9392a1 | |||
v1.0 | instruct | Filter | Filter_28437_I | Propose an algorithm in Python for sorting a given list of integers in descending order, without using any built-in sorting functions or libraries. Additionally, ensure that your algorithm has a time complexity of O(n log n) and a space complexity of O(log n). In this updated version, you are not allowed to use any add... | def heapify(arr, n, i):
""" Helper function to maintain the heap property """
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:
... | from solution import heap_sort
def test_heap_sort_empty_list():
arr = []
heap_sort(arr)
assert arr == []
def test_heap_sort_single_element():
arr = [1]
heap_sort(arr)
assert arr == [1]
def test_heap_sort_sorted_list():
arr = [5, 4, 3, 2, 1]
heap_sort(arr)
assert arr == [5, 4, 3, 2... | [
{
"docstring": "Helper function to maintain the heap property ",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": "Sorts the given list of integers in descending order using heap sort.\nTime complexity: O(n log n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_descending(arr):\n \"\"\"\n Sorts a list of integers in descending order using an in-place approach.\n This implementation uses the quicksort algorithm to achieve O(n log n) ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028437",
"row_id": 28437,
"seed_ids": "['Qwen2-72B-Instruct_67798']"
} | 0.707131 | Filter_28437 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cffa7b57ead90df8cfc3e15c46a2dbbf49e5b5e4 | 2dd998794c12f7945ad34896dc44e034f0aae521 | |||
v1.0 | instruct | Filter | Filter_28444_I | Write a code script that yields the Fibonacci sequence within a specified range m to n, where m and n are integers. Additionally, implement a feature to output sequences with only prime numbers and validate on conditions. | 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 fibonacci_within_range(m, n):
"""
Generate the Fibonacci sequence within the range m to n.
... | from solution import is_prime, fibonacci_within_range, prime_fibonacci_within_range
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate the Fibonacci sequence within the range m to n.",
"function_declaration": "def fibonacci_within_range(m, n):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_within_range(m, n):\n \"\"\"\n Generate Fibonacci sequence within range m to n (inclusive) and returns it.\n Also filters out the sequence to include only prime numbers ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028444",
"row_id": 28444,
"seed_ids": "['Qwen2-72B-Instruct_67809']"
} | 0.647005 | Filter_28444 | I | [
"is_prime",
"fibonacci_within_range",
"prime_fibonacci_within_range"
] | 3 | [
[
"prime_fibonacci_within_range",
"fibonacci_within_range"
],
[
"prime_fibonacci_within_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 17405ccf951f2ce7728350a307851bb0547db147 | 052949ab1265d6f3ed2db1ed159e62536e39c679 | |||
v1.0 | instruct | Filter | Filter_28459_I | Help me to write a PEP8 compliant Python program. The program is a simple command-line unit converter that can convert between Celsius and Fahrenheit, and between kilometers and miles. The conversion formulas are: Celsius to Fahrenheit: F = C * 9/5 + 32 and vice versa. Kilometers to miles: M = K * 0.621371 and vice ver... | def celsius_to_fahrenheit(celsius):
"""
Converts Celsius to Fahrenheit.
Formula: F = C * 9/5 + 32
"""
return celsius * 9/5 + 32
def fahrenheit_to_celsius(fahrenheit):
"""
Converts Fahrenheit to Celsius.
Formula: C = (F - 32) * 5/9
"""
return (fahrenheit - 32) * 5/9
def kilomete... | from solution import celsius_to_fahrenheit, fahrenheit_to_celsius
from solution import kilometers_to_miles, miles_to_kilometers
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(-40) == -40
def test_fahrenheit_to_c... | [
{
"docstring": "Converts Celsius to Fahrenheit.\nFormula: F = C * 9/5 + 32",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius)"
},
{
"docstring": "Converts Fahrenheit to Celsius.\nFormula: C = (F - 32) * 5/9"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n Formula: F = C * 9/5 + 32\n \"\"\"\n return celsius * 9/5 + 32\n\ndef fahrenheit_to_celsius(fahr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028459",
"row_id": 28459,
"seed_ids": "['Qwen2-72B-Instruct_67832']"
} | 0.404232 | Filter_28459 | I | [
"celsius_to_fahrenheit",
"fahrenheit_to_celsius",
"kilometers_to_miles",
"miles_to_kilometers",
"unit_converter"
] | 5 | [
[
"unit_converter",
"celsius_to_fahrenheit"
],
[
"unit_converter",
"fahrenheit_to_celsius"
],
[
"unit_converter",
"kilometers_to_miles"
],
[
"unit_converter",
"miles_to_kilometers"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 83b6bdf0294eb3417c0e9149bb6835d5994f08ab | d7ff36b9236aeeddb8cd54da3ef84d8b95e4854e | |||
v1.0 | instruct | Filter | Filter_28477_I | Write a function in Python that takes in a list of integers and returns the sum of all the prime numbers in the list. If there are no prime numbers, the function should return 0. Additionally, the function should only consider positive integers in the list. | 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 sum_of_primes(lst):
"""
Returns the sum of all prime numbers in the list lst.
... | from solution import sum_of_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(7) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
def test_sum_of_primes_with_pr... | [
{
"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 sum of all prime numbers in the list lst.\nConsiders only positive integers.",
"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_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028477",
"row_id": 28477,
"seed_ids": "['Qwen2-72B-Instruct_67866']"
} | 0.663252 | Filter_28477 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77110e2b5c8a0f1879ff2b4e916cc894fd15675f | e3e8f178b118e8e2bad5648c8438be1df05dada4 | |||
v1.0 | instruct | Filter | Filter_28479_I | I want to write a Python code to compare the performance of different sorting algorithms. I have the following algorithms to consider: Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, and Merge Sort. Can you help me write a code that runs each of these algorithms on a randomly generated list of numbers and give... | import time
import random
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i-1
... | from solution import bubble_sort, insertion_sort, selection_sort, quick_sort, merge_sort, compare_sorting_algorithms
def test_bubble_sort():
arr = [64, 25, 12, 22, 11]
assert bubble_sort(arr) == [11, 12, 22, 25, 64]
def test_insertion_sort():
arr = [64, 25, 12, 22, 11]
assert insertion_sort(arr) == [1... | [
{
"docstring": null,
"function_declaration": "def bubble_sort(arr):",
"function_name": "bubble_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def insertion_sort(arr):",
"function_name": "insertion_sort",
"parameter_list": "(arr)"
},
{
"d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport random\n\ndef bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028479",
"row_id": 28479,
"seed_ids": "['Qwen2-72B-Instruct_67869']"
} | 0.512244 | Filter_28479 | I | [
"bubble_sort",
"insertion_sort",
"selection_sort",
"quick_sort",
"merge_sort",
"measure_time",
"compare_sorting_algorithms"
] | 7 | [
[
"compare_sorting_algorithms",
"measure_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65aff20ec069a13453fe72519b5c9f45ff0f636e | f4b9eb74141e7228da2cd771fd526f3f79d883eb | |||
v1.0 | instruct | Filter | Filter_28488_I | Given a list of strings and a target string, write a Python program to find the longest string in the list that is a subsequence of the target string. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. | def is_subsequence(s, target):
"""
Helper function to check if s is a subsequence of target.
"""
it = iter(target)
return all(char in it for char in s)
def longest_subsequence(strings, target):
"""
Returns the longest string from the list `strings` that is a subsequence of `target`.
"""... | from solution import longest_subsequence
def test_longest_subsequence_single_match():
assert longest_subsequence(["abc", "def", "ghi"], "abcdefghi") == "abc"
def test_longest_subsequence_multiple_matches():
assert longest_subsequence(["abc", "def", "abcd"], "abcde") == "abcd"
def test_longest_subsequence_no_... | [
{
"docstring": "Helper function to check if s is a subsequence of target.",
"function_declaration": "def is_subsequence(s, target):",
"function_name": "is_subsequence",
"parameter_list": "(s, target)"
},
{
"docstring": "Returns the longest string from the list `strings` that is a subsequence... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(s, target):\n \"\"\"\n Check if s is a subsequence of target\n \"\"\"\n it = iter(target)\n return all(char in it for char in s)\n\ndef longest_subsequence(st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028488",
"row_id": 28488,
"seed_ids": "['Qwen2-72B-Instruct_67883']"
} | 0.688624 | Filter_28488 | I | [
"is_subsequence",
"longest_subsequence"
] | 2 | [
[
"longest_subsequence",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cec51998e8b39916d8944de5fc7458066e27141 | 3c90d1665094378b394446412dd93ed5007f1630 | |||
v1.0 | instruct | Filter | Filter_28501_I | Write a Python code that utilizes the Gregory-Leibniz series algorithm to calculate and print the first 5 digits of Pi (3.1415). Additionally, include a function that calculates the absolute error between the estimated value and the actual value of Pi for each iteration of the algorithm. Display the estimated value, ac... | import math
def calculate_pi_gregory_leibniz(iterations):
"""
Calculates Pi using the Gregory-Leibniz series for a given number of iterations.
"""
pi_estimate = 0
for i in range(iterations):
pi_estimate += ((-1)**i) / (2*i + 1)
pi_estimate *= 4
return pi_estimate
def calculate_abso... | from solution import calculate_pi_gregory_leibniz, calculate_absolute_error, print_first_5_digits_pi
def test_calculate_pi_gregory_leibniz():
assert round(calculate_pi_gregory_leibniz(1), 10) == 4.0
assert round(calculate_pi_gregory_leibniz(2), 10) == 2.6666666667
assert round(calculate_pi_gregory_leibniz(... | [
{
"docstring": "Calculates Pi using the Gregory-Leibniz series for a given number of iterations.",
"function_declaration": "def calculate_pi_gregory_leibniz(iterations):",
"function_name": "calculate_pi_gregory_leibniz",
"parameter_list": "(iterations)"
},
{
"docstring": "Calculates the abso... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_pi(num_iterations):\n \"\"\"\n Calculate Pi using the Gregory-Leibniz series up to the given number of iterations.\n \"\"\"\n pi_estimate = 0\n for ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028501",
"row_id": 28501,
"seed_ids": "['Qwen2-72B-Instruct_67902']"
} | 0.62428 | Filter_28501 | I | [
"calculate_pi_gregory_leibniz",
"calculate_absolute_error",
"display_pi_estimation_table",
"print_first_5_digits_pi"
] | 4 | [
[
"display_pi_estimation_table",
"calculate_absolute_error"
],
[
"display_pi_estimation_table",
"calculate_pi_gregory_leibniz"
],
[
"print_first_5_digits_pi",
"calculate_pi_gregory_leibniz"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d963c58d5300b097da3bd5614552769175f092dd | b96885b1d361ec4d34b8ba8a348f10b2846699dc | |||
v1.0 | instruct | Filter | Filter_28531_I | Modify a given code implementing list comprehension that produces a list of prime numbers from a given list of numbers. Additionally, introduce error handling for non-integer types and negative numbers. If a non-integer or negative number is encountered, throw an exception with an appropriate error message. | 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 get_primes(numbers):
"""
Returns a list of prime numbers from the given list... | from solution import get_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(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
def test_get_primes_all_primes():... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of numbers.\nThrows an exception if the list contain... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028531",
"row_id": 28531,
"seed_ids": "['Qwen2-72B-Instruct_67952']"
} | 0.590853 | Filter_28531 | I | [
"is_prime",
"get_primes"
] | 2 | [
[
"get_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fb0aa8b3cf035e51da595bb90f907f5d1b54d146 | 5b2ec898a170983dcc74947ae662077fd251a82a | |||
v1.0 | instruct | Filter | Filter_28542_I | Write a Python script to iterate over a given list and print the square of the numbers in the list. Additionally, the script should only print the squares of the numbers that are prime. The script should also calculate and print the sum of all the squared prime numbers. | def is_prime(n):
"""Return True if n is a prime number, else False."""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def prime_squares(numbers):
"""
Given a list of numbers, prints the square of the prime numbers ... | from solution import is_prime, prime_squares
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
def test_prime_squares():
# Use a StringIO object to captu... | [
{
"docstring": "Return True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of numbers, prints the square of the prime numbers in the list\nand returns the sum of all square... | [
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 \"\"\"Check if a given number is a prime number.\"\"\"\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": "00028542",
"row_id": 28542,
"seed_ids": "['Qwen2-72B-Instruct_67977']"
} | 0.702223 | Filter_28542 | I | [
"is_prime",
"prime_squares"
] | 2 | [
[
"prime_squares",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2da95daee4eae9f6d8fb6814b3f41e942c0067f5 | 0fc99ecb1d761817063154ad7c4423450bed1d1d | |||
v1.0 | instruct | Filter | Filter_28564_I | Implement a function that takes an input of two positive integers and generates a random number between them (including the two numbers). Then, create an interface to test your function with user input. You should also check for the validity of the inputs (e.g. the second number should not be less than the first number... | import random
def generate_random_number(a: int, b: int) -> int:
"""
Generates a random number between a and b, inclusive.
"""
if not (isinstance(a, int) and isinstance(b, int)):
raise ValueError("Inputs must be integers.")
if a < 0 or b < 0:
raise ValueError("Inputs must be positiv... | from solution import generate_random_number, validate_and_generate
import pytest
def test_generate_random_number_valid_input():
assert 1 <= generate_random_number(1, 10) <= 10
assert 10 <= generate_random_number(10, 20) <= 20
def test_generate_random_number_invalid_input():
with pytest.raises(ValueError):... | [
{
"docstring": "Generates a random number between a and b, inclusive.",
"function_declaration": "def generate_random_number(a, b):",
"function_name": "generate_random_number",
"parameter_list": "(a, b)"
},
{
"docstring": "Validates the user input and generates a random number between the two... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_between(a, b):\n \"\"\"\n Returns a random number between a and b (including a and b).\n If a is greater than b, a ValueError is raised.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028564",
"row_id": 28564,
"seed_ids": "['Qwen2-72B-Instruct_68012']"
} | 0.51523 | Filter_28564 | I | [
"generate_random_number",
"validate_and_generate"
] | 2 | [
[
"validate_and_generate",
"generate_random_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9edebc9944f30eabefb4fe84a84ac77793fca2f8 | f5e3c41434af1156763545dc17b9f6bf34999aaa | |||
v1.0 | instruct | Filter | Filter_28569_I | Given a pair of non-negative integers, write code that outputs the lesser number without using any comparison operators like '<', '>', '==', etc. | def lesser_number(a, b):
"""
Returns the lesser of two non-negative integers without using any comparison operators.
"""
return (a + b - abs(a - b)) // 2
# Helper function to calculate absolute value without using comparison operators
def abs(x):
return (x**2)**0.5 | from solution import lesser_number
def test_lesser_number_equal():
assert lesser_number(5, 5) == 5
def test_lesser_number_first_smaller():
assert lesser_number(2, 3) == 2
def test_lesser_number_second_smaller():
assert lesser_number(7, 6) == 6
def test_lesser_number_with_zero():
assert lesser_number... | [
{
"docstring": "Returns the lesser of two non-negative integers without using any comparison operators.",
"function_declaration": "def lesser_number(a, b):",
"function_name": "lesser_number",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def abs(x):",
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def lesser_number(a, b):\n \"\"\"\n Returns the lesser of two non-negative integers without using any comparison operators.\n \"\"\"\n return (a + b - abs(a - b)) // 2\n\n# Helper ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028569",
"row_id": 28569,
"seed_ids": "['Qwen2-72B-Instruct_68017']"
} | 0.579295 | Filter_28569 | I | [
"lesser_number",
"abs"
] | 2 | [
[
"lesser_number",
"abs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ffe63c59eeb4059a97dce1aaa179f957793ed1c | 50e727872db4da8543bd328a6f1068c5488d6ebd | |||
v1.0 | instruct | Filter | Filter_28594_I | Write a code that will check if a given string is a palindrome or not without using extra space. The code should ignore case sensitivity. Additionally, the code should only use recursion for the palindrome check. The string will have at most 1000 characters. | def is_palindrome_recursive(s, left, right):
"""
Check if a substring s[left:right+1] is a palindrome using recursion.
"""
# Base case: if left >= right, we've checked all characters
if left >= right:
return True
# Ignore case by converting characters to lower case
if s[left].lower()... | from solution import is_palindrome
def test_palindrome_even_length():
assert is_palindrome("abba") == True
def test_palindrome_odd_length():
assert is_palindrome("racecar") == True
def test_not_palindrome():
assert is_palindrome("hello") == False
def test_single_character():
assert is_palindrome("a"... | [
{
"docstring": "Check if a substring s[left:right+1] is a palindrome using recursion.",
"function_declaration": "def is_palindrome_recursive(s, left, right):",
"function_name": "is_palindrome_recursive",
"parameter_list": "(s, left, right)"
},
{
"docstring": "Check if a given string is a pal... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome_recursive(s, start, end):\n \"\"\"\n Checks if the given string is a palindrome.\n Ignores case sensitivity and only uses recursion.\n \"\"\"\n # Convert the s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028594",
"row_id": 28594,
"seed_ids": "['Qwen2-72B-Instruct_68062']"
} | 0.725032 | Filter_28594 | I | [
"is_palindrome_recursive",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"is_palindrome_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ea9639bbf71ea340a5397214c1e26fd33b8f0474 | 402c4924457c2c8b06399b64ad88e239bc007907 | |||
v1.0 | instruct | Filter | Filter_28602_I | Design a program in Python that generates the first 10 prime numbers between 1000 and 2000, and then calculates the sum of their digits. Additionally, the program must output the prime numbers in a table format and the sum of the digits must be converted to binary before displaying the result. | 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 generate_primes(start, end, count):
"""
Generates the first `count` prime nu... | from solution import is_prime, generate_primes, sum_of_digits
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(12) == False
def test_generate_primes():
primes = gene... | [
{
"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": "Generates the first `count` prime numbers in the range [start, end].",
"function_declaration": "def ... | [
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(n):\n \"\"\"Check if a number is a prime\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028602",
"row_id": 28602,
"seed_ids": "['Qwen2-72B-Instruct_68072']"
} | 0.593257 | Filter_28602 | I | [
"is_prime",
"generate_primes",
"sum_of_digits",
"main"
] | 4 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4d6bf467bbe7f3f1365eea6a66ec6a656d2acc29 | 0ef2d54d3e4cd1bb5b43dd755992b6b9ca17da0f | |||
v1.0 | instruct | Filter | Filter_28611_I | Given the python functions `add(i : int, j : int) -> int`, `substract(i : int, j : int) -> int` and `multiply(i : int, j : int) -> int` that respectively return the result of adding, subtracting, and multiplying `i` and `j`, create a function `calculate(i : int, j : int, operation : str) -> int` that calls one of the f... | def add(i: int, j: int) -> int:
return i + j
def subtract(i: int, j: int) -> int:
return i - j
def multiply(i: int, j: int) -> int:
return i * j
def calculate(i: int, j: int, operation: str) -> int:
if operation == "add":
return add(i, j)
elif operation == "subtract":
return subtr... | from solution import add, subtract, multiply, calculate
def test_add():
assert add(2, 3) == 5
assert add(-1, -1) == -2
assert add(-3, 3) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(-1, -1) == 0
assert subtract(-3, 3) == -6
assert subtract(... | [
{
"docstring": null,
"function_declaration": "def add(i, j):",
"function_name": "add",
"parameter_list": "(i, j)"
},
{
"docstring": null,
"function_declaration": "def subtract(i, j):",
"function_name": "subtract",
"parameter_list": "(i, j)"
},
{
"docstring": null,
"fu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(i: int, j: int) -> int:\n \"\"\"\n Returns the sum of i and j.\n \"\"\"\n return i + j\n\ndef subtract(i: int, j: int) -> int:\n \"\"\"\n Returns the result of subtra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028611",
"row_id": 28611,
"seed_ids": "['Qwen2-72B-Instruct_68084']"
} | 0.70695 | Filter_28611 | I | [
"add",
"subtract",
"multiply",
"calculate"
] | 4 | [
[
"calculate",
"add"
],
[
"calculate",
"multiply"
],
[
"calculate",
"subtract"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ac890f4563058a619cbb86030884f329f9754344 | aac01d01526c9a2f935ba86af62dc421acf60cf8 | |||
v1.0 | instruct | Filter | Filter_28629_I | Write a program to generate a random traversal sequence for a binary tree with n nodes. The program should also define the conditions under which a traversal sequence (be it pre-order, in-order, or post-order) can be considered valid. | import random
class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def generate_random_tree(n):
nodes = [TreeNode(i) for i in range(1, n+1)]
if n == 0:
return None
random.shuffle(nodes)
root = nodes[0]
for node in ... | from solution import generate_random_tree, pre_order_traversal, in_order_traversal, post_order_traversal
from solution import is_valid_pre_order_sequence, is_valid_in_order_sequence, is_valid_post_order_sequence
def test_pre_order_traversal():
tree = generate_random_tree(5)
pre_order_seq = pre_order_traversal(... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\nclass TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef generate_binary_tree(n):\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028629",
"row_id": 28629,
"seed_ids": "['Qwen2-72B-Instruct_68113']"
} | 0.495524 | Filter_28629 | I | [
"generate_random_tree",
"pre_order_traversal",
"in_order_traversal",
"post_order_traversal",
"is_valid_pre_order_sequence",
"is_valid_in_order_sequence",
"is_valid_post_order_sequence"
] | 7 | [
[
"is_valid_in_order_sequence",
"in_order_traversal"
],
[
"is_valid_post_order_sequence",
"post_order_traversal"
],
[
"is_valid_pre_order_sequence",
"pre_order_traversal"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d807d0c876f741608bd9ef47623dc01c21437efa | 36dadfd8daa52b26ed33d345546f94e532521e52 | |||
v1.0 | instruct | Filter | Filter_28635_I | Human: Write a shifting cipher script that creates a new character set based on a given key, and also apply this script to encode a message. Observe the hint for the direction to proceed. | def create_cipher_set(key):
"""
Creates a cipher set based on the given key by shifting the alphabet.
Args:
key (int): The number of positions to shift the alphabet.
Returns:
dict: A dictionary mapping each character in the original set to the shifted character.
"""
alphabet = 'abc... | from solution import create_cipher_set, encode_message
def test_create_cipher_set():
assert create_cipher_set(3) == {
'a': 'd', 'b': 'e', 'c': 'f', 'd': 'g', 'e': 'h',
'f': 'i', 'g': 'j', 'h': 'k', 'i': 'l', 'j': 'm',
'k': 'n', 'l': 'o', 'm': 'p', 'n': 'q', 'o': 'r',
'p': 's', 'q... | [
{
"docstring": "Creates a cipher set based on the given key by shifting the alphabet.\n\nArgs:\nkey (int): The number of positions to shift the alphabet.\n\nReturns:\ndict: A dictionary mapping each character in the original set to the shifted character.",
"function_declaration": "def create_cipher_set(key)... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def shift_character_set(key):\n \"\"\"\n Creates a new character set by shifting the original character set based on the given key.\n \"\"\"\n original_charset = \"abcdefghijklmnop... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028635",
"row_id": 28635,
"seed_ids": "['Qwen2-72B-Instruct_68120']"
} | 0.566479 | Filter_28635 | I | [
"create_cipher_set",
"encode_message"
] | 2 | [
[
"encode_message",
"create_cipher_set"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d5641602942edc05f6b256f5dd824157a4f0434c | 030b617168a66f23cb3d37b0b6db022884e9681c | |||
v1.0 | instruct | Filter | Filter_28650_I | Create a function to encrypt a string using the XOR operator and a randomly generated key of length 10. 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
def xor_encrypt_decrypt(text, key):
"""
Encrypt or decrypt text using XOR with the given key.
"""
return ''.join(chr(ord(char) ^ ord(key[i % len(key)])) for i, char in enumerate(text))
def generate_key(length=10):
"""
Generate a cryptographically secure random key of a given length.
... | import pytest
from solution import xor_encrypt_decrypt, generate_key, encrypt_string
def test_generate_key_length():
key = generate_key(10)
assert len(key) == 10
def test_generate_key_uniqueness():
key1 = generate_key(10)
key2 = generate_key(10)
assert key1 != key2
def test_xor_encrypt_decrypt():... | [
{
"docstring": "Encrypt or decrypt text using XOR with the given key.",
"function_declaration": "def xor_encrypt_decrypt(text, key):",
"function_name": "xor_encrypt_decrypt",
"parameter_list": "(text, key)"
},
{
"docstring": "Generate a cryptographically secure random key of a given length."... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef xor_encrypt_decrypt(text, key):\n \"\"\"\n Encrypt or decrypt text using XOR with the given key.\n \"\"\"\n return ''.join(chr(ord(char) ^ ord(key[i % len(key)])) ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028650",
"row_id": 28650,
"seed_ids": "['Qwen2-72B-Instruct_68140']"
} | 0.552309 | Filter_28650 | I | [
"xor_encrypt_decrypt",
"generate_key",
"encrypt_string"
] | 3 | [
[
"encrypt_string",
"generate_key"
],
[
"encrypt_string",
"xor_encrypt_decrypt"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f897db4537f3ae6039a5402f3ba26041a7d079e8 | 8f4a1bc888dbf9430e0a4d0adf05471138906e1f | |||
v1.0 | instruct | Filter | Filter_28651_I | Write a script that prints out the first 100 prime numbers and their corresponding square roots. Additionally, write the logic to identify twin prime pairs from these first 100 prime numbers and print them out. Make sure to write functions for each operation to ensure code modularity and reusability. | import math
def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
def generate_primes(n):
"""
Generate the first n prime numbers.
"""
pri... | from solution import is_prime, generate_primes, calculate_square_roots, find_twin_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(18) == False
def test_generate_primes():
assert generate_p... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate the first n prime numbers.",
"function_declaration": "def generate_primes(n):",
"function_name": "generate_pr... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n %... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028651",
"row_id": 28651,
"seed_ids": "['Qwen2-72B-Instruct_68141']"
} | 0.517219 | Filter_28651 | I | [
"is_prime",
"generate_primes",
"calculate_square_roots",
"find_twin_primes",
"main"
] | 5 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 483fda5b1491cae023953e0ac29b038f8129f07c | 4bfc382fa08a73e6e5c4558bb587e33f9824676c | |||
v1.0 | instruct | Filter | Filter_28653_I | Write a Python program to create a simple calculator application with basic operations: addition, subtraction, multiplication, and division. The program should prompt users to enter two numbers and then provide an option to select the operation they want to perform. Make sure to validate user input and show appropriate... | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
def simple_calculator(a, b, operation):
if operation == 'add':
return add(a, b)
elif operatio... | import pytest
from solution import add, subtract, multiply, divide, simple_calculator
def test_add():
assert add(3, 5) == 8
assert add(-1, 2) == 1
def test_subtract():
assert subtract(7, 5) == 2
assert subtract(0, 2) == -2
def test_multiply():
assert multiply(3, 5) == 15
assert multiply(-1, 2... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028653",
"row_id": 28653,
"seed_ids": "['Qwen2-72B-Instruct_68143']"
} | 0.601273 | Filter_28653 | I | [
"add",
"subtract",
"multiply",
"divide",
"simple_calculator"
] | 5 | [
[
"simple_calculator",
"add"
],
[
"simple_calculator",
"divide"
],
[
"simple_calculator",
"multiply"
],
[
"simple_calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 6facad3a282d90b3d86e24d7b64da9c7dc36f6b4 | 90fb2f60f5a4fee9e84fe6b003f6aa560b7fffd2 | |||
v1.0 | instruct | Filter | Filter_28679_I | Create a python code to generate a dictionary that has all the prime numbers between 1 and 100 as keys and their corresponding cubes as values. | def is_prime(num):
"""
Checks 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 generate_prime_cubes():
"""
Generates a dictionary with prime numbers between 1 an... | from solution import is_prime, generate_prime_cubes
def test_is_prime():
# Test known primes
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
# Test known non-primes
assert is_prime(1) == False
assert is_prime(4) == False
as... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a dictionary with prime numbers between 1 and 100 as keys \nand their cubes as values.",
"function_dec... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if the number n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n %... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028679",
"row_id": 28679,
"seed_ids": "['Qwen2-72B-Instruct_68183']"
} | 0.583464 | Filter_28679 | I | [
"is_prime",
"generate_prime_cubes"
] | 2 | [
[
"generate_prime_cubes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | afb84b493bbf4c733a25c034f911cb07ee1e7483 | c932d4ec18acab8f2a4afd165bb4e66e47eaf642 | |||
v1.0 | instruct | Filter | Filter_28715_I | Given a set of numbers, write a function that removes all duplicate elements and sorts the remaining elements in ascending order. Your implementation should have a time complexity of O(nlogn), where n is the number of elements in the set. Additionally, your implementation should not use any built-in functions or librar... | def remove_duplicates_and_sort(numbers):
"""
Removes duplicate elements and sorts the remaining elements in ascending order.
:param numbers: A list of integers
:return: A list of sorted integers with duplicates removed
"""
if not numbers:
return []
# Step 1: Remove duplicat... | from solution import remove_duplicates_and_sort
def test_remove_duplicates_and_sort_with_duplicates():
assert remove_duplicates_and_sort([4, 2, 5, 1, 2, 4, 5, 6]) == [1, 2, 4, 5, 6]
def test_remove_duplicates_and_sort_without_duplicates():
assert remove_duplicates_and_sort([3, 1, 2, 4]) == [1, 2, 3, 4]
def t... | [
{
"docstring": "Removes duplicate elements and sorts the remaining elements in ascending order.\n\n:param numbers: A list of integers\n:return: A list of sorted integers with duplicates removed",
"function_declaration": "def remove_duplicates_and_sort(numbers):",
"function_name": "remove_duplicates_and_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def remove_duplicates_and_sort(numbers):\n \"\"\"\n Removes all duplicate elements from the given list of numbers and sorts the remaining elements in ascending order.\n Time complexit... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028715",
"row_id": 28715,
"seed_ids": "['Qwen2-72B-Instruct_68239']"
} | 0.629003 | Filter_28715 | I | [
"remove_duplicates_and_sort",
"quicksort"
] | 2 | [
[
"remove_duplicates_and_sort",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ef78470f854802961b5b6088af784988912d347 | 731f337a65f9f1b4465d654764847d7ebfd5af97 | |||
v1.0 | instruct | Filter | Filter_28723_I | Design a "web crawler" that can find and print out all the hyperlinks in a given website recursively, including both internal and external links. Additionally, the crawler should also be able to differentiate and categorize links based on their target extensions (e.g., .html, .pdf, .jpg). | import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
import re
def categorize_links(links):
categorized = {'html': [], 'pdf': [], 'jpg': [], 'other': []}
for link in links:
if link.endswith('.html') or '.' not in link:
categorized['html'].append(link)
... | from solution import web_crawler, categorize_links, get_links
def test_categorize_links():
links = ['http://example.com/page.html', 'http://example.com/document.pdf', 'http://example.com/image.jpg', 'http://example.com/unknown.xyz']
categories = categorize_links(links)
assert categories['html'] == ['http:/... | [
{
"docstring": null,
"function_declaration": "def categorize_links(links):",
"function_name": "categorize_links",
"parameter_list": "(links)"
},
{
"docstring": "Fetches all the hyperlinks from the given URL.",
"function_declaration": "def get_links(url):",
"function_name": "get_links... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom bs4 import BeautifulSoup\nfrom urllib.parse import urljoin, urlparse\nimport re\n\ndef categorize_links(links):\n categorized = {'html': [], 'pdf': [], 'jpg': [], 'oth... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028723",
"row_id": 28723,
"seed_ids": "['Qwen2-72B-Instruct_68251']"
} | 0.556614 | Filter_28723 | I | [
"categorize_links",
"get_links",
"web_crawler"
] | 3 | [
[
"web_crawler",
"categorize_links"
],
[
"web_crawler",
"get_links"
]
] | 2 | [] | false | [] | false | pytest | true | [
"bs4",
"requests"
] | false | 5b71ea5c340cef1a01ca74f11c83ddd46f8a9bec | 09a7ebe7be23906a6148c74a434d68510efb0a12 | |||
v1.0 | instruct | Filter | Filter_28727_I | Write a method to sort a list of integers in Python without using any built-in sort methods or extra memory i.e., sort in-place. Also, implement your method to handle duplicate integers in the list. Finally, your solution must work in O(n log n) time complexity. | def quicksort(arr, low, high):
if low < high:
pi = partition(arr, low, high)
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(low, high):
if arr[j] <= pivot:
i += 1
... | from solution import sort_list_in_place
def test_sort_empty_list():
arr = []
sort_list_in_place(arr)
assert arr == []
def test_sort_single_element_list():
arr = [1]
sort_list_in_place(arr)
assert arr == [1]
def test_sort_already_sorted_list():
arr = [1, 2, 3, 4, 5]
sort_list_in_place(... | [
{
"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": "def quicksort(arr, low, high):\n \"\"\"\n Sorts the list in place using the QuickSort algorithm.\n \"\"\"\n if low < high:\n pi = partition(arr, low, high)\n quicksor... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028727",
"row_id": 28727,
"seed_ids": "['Qwen2-72B-Instruct_68257']"
} | 0.681937 | Filter_28727 | I | [
"quicksort",
"partition",
"sort_list_in_place"
] | 3 | [
[
"quicksort",
"partition"
],
[
"sort_list_in_place",
"quicksort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 52297c693bc2cc77d5af0c333843244dc20823cb | 5f030e6749ab12fc49e14142937311a82735ee80 | |||
v1.0 | instruct | Filter | Filter_28729_I | Please write a Python code to subtract two matrices of different dimensions. The program should be able to handle matrices of any size, and should display an error message if the matrices cannot be subtracted due to incompatible dimensions. Additionally, include a table showing the dimensions of the input matrices, and... | def can_subtract_matrices(A, B):
"""
Returns True if matrices A and B can be subtracted (i.e., have the same dimensions), otherwise returns False.
"""
return len(A) == len(B) and all(len(row) == len(B[idx]) for idx, row in enumerate(A))
def subtract_matrices(A, B):
"""
Subtracts matrix B from ... | from solution import subtract_and_display, can_subtract_matrices, subtract_matrices
def test_can_subtract_matrices():
assert can_subtract_matrices(
[[1, 2], [3, 4]],
[[5, 6], [7, 8]]
) == True
assert can_subtract_matrices(
[[1, 2], [3, 4]],
[[5, 6]]
) == False
ass... | [
{
"docstring": "Returns True if matrices A and B can be subtracted (i.e., have the same dimensions), otherwise returns False.",
"function_declaration": "def can_subtract_matrices(A, B):",
"function_name": "can_subtract_matrices",
"parameter_list": "(A, B)"
},
{
"docstring": "Subtracts matrix... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def subtract_matrices(matrix1, matrix2):\n \"\"\"\n Subtract two matrices element-wise if they have the same dimensions.\n \n Parameters:\n matrix1 (list of list of int/float): ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028729",
"row_id": 28729,
"seed_ids": "['Qwen2-72B-Instruct_68262']"
} | 0.440759 | Filter_28729 | I | [
"can_subtract_matrices",
"subtract_matrices",
"display_matrix",
"subtract_and_display"
] | 4 | [
[
"subtract_and_display",
"can_subtract_matrices"
],
[
"subtract_and_display",
"display_matrix"
],
[
"subtract_and_display",
"subtract_matrices"
],
[
"subtract_matrices",
"can_subtract_matrices"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 57b33028fc8da252dbdbd47700fb3d6e68afa37b | c81017123f7d417fab4b42e43580b3ed31595760 | |||
v1.0 | instruct | Filter | Filter_28736_I | Define a python function that takes as input a mutable object of arbitrary type (for instance, a list or a dictionary). The function should check whether the input is indeed mutable and then add 1 to each numerical element in the object. The function should handle both numerical elements at the top level of the object ... | def is_mutable(obj):
"""
Checks if the object is mutable.
"""
mutable_types = (dict, list, set)
return isinstance(obj, mutable_types)
def increment_numbers_in_object(obj):
"""
Recursively increment all numeric values in a mutable object.
Raises TypeError if a non-numeric value is encoun... | from solution import increment_numbers_in_object, is_mutable
import pytest
def test_non_mutable_object():
with pytest.raises(TypeError):
increment_numbers_in_object(1)
def test_list_with_numbers():
obj = [1, 2, 3]
expected = [2, 3, 4]
assert increment_numbers_in_object(obj) == expected
def te... | [
{
"docstring": "Checks if the object is mutable.",
"function_declaration": "def is_mutable(obj):",
"function_name": "is_mutable",
"parameter_list": "(obj)"
},
{
"docstring": "Recursively increment all numeric values in a mutable object.\nRaises TypeError if a non-numeric value is encountered... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def increment_mutable_elements(obj):\n \"\"\"\n Increment each numerical element in the mutable object by 1.\n Raise TypeError for non-numeric elements.\n \"\"\"\n if isinstance... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028736",
"row_id": 28736,
"seed_ids": "['Qwen2-72B-Instruct_68276']"
} | 0.501662 | Filter_28736 | I | [
"is_mutable",
"increment_numbers_in_object"
] | 2 | [
[
"increment_numbers_in_object",
"is_mutable"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2aa5264b28cb984b7e55eb703419d5894d9271f3 | e0d32c653b86a3232aa2b6907c2029889ac81fc3 | |||
v1.0 | instruct | Filter | Filter_28740_I | Build a Python function that generates a list of the first N Fibonacci numbers, where N is an input parameter. Additionally, modify the function to return the list of Fibonacci numbers that are even only. Include error handling for scenarios where the input is not an integer or is less than 1. | def fibonacci(N):
"""
Generates a list of the first N Fibonacci numbers.
"""
if not isinstance(N, int):
raise ValueError("N must be an integer")
if N < 1:
raise ValueError("N must be greater than 0")
fib_sequence = []
a, b = 0, 1
for _ in range(N):
fib_sequen... | from solution import fibonacci, even_fibonacci
def test_fibonacci_positive_int():
assert fibonacci(5) == [0, 1, 1, 2, 3]
def test_fibonacci_single_value():
assert fibonacci(1) == [0]
def test_fibonacci_invalid_input():
try:
fibonacci(-5)
except ValueError as e:
assert str(e) == "N mus... | [
{
"docstring": "Generates a list of the first N Fibonacci numbers.",
"function_declaration": "def fibonacci(N):",
"function_name": "fibonacci",
"parameter_list": "(N)"
},
{
"docstring": "Generates a list of the first N Fibonacci numbers specifically comprising only even numbers.",
"funct... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_numbers(n):\n \"\"\"\n Generates a list of the first N Fibonacci numbers, where N is the input parameter.\n If N is not an integer or less than 1, an appropriate error m... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028740",
"row_id": 28740,
"seed_ids": "['Qwen2-72B-Instruct_68283']"
} | 0.764694 | Filter_28740 | I | [
"fibonacci",
"even_fibonacci"
] | 2 | [
[
"even_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 53d2d1c6613f7a7dbe6d168c2189fb7ccc3b9232 | 4189ced1e432443885f6a2931fea72ac33b83a7f | |||
v1.0 | instruct | Filter | Filter_28742_I | Implement the KMP (Knuth-Morris-Pratt) algorithm in Python to not only find a pattern in a given text but also return the starting indexes of all occurrences of the pattern. Furthermore, your function should account for overlap in pattern occurrences. | def compute_lps(pattern):
"""
Compute the longest prefix which is also suffix array (LPS array)
"""
lps = [0] * len(pattern)
length = 0
i = 1
while i < len(pattern):
if pattern[i] == pattern[length]:
length += 1
lps[i] = length
i += 1
else:... | from solution import compute_lps, kmp_search
def test_compute_lps():
assert compute_lps("abcdabca") == [0, 0, 0, 0, 1, 2, 3, 1]
assert compute_lps("aaaa") == [0, 1, 2, 3]
assert compute_lps("abcaby") == [0, 0, 0, 1, 2, 0]
assert compute_lps("") == []
def test_kmp_search():
assert kmp_search("ababc... | [
{
"docstring": "Compute the longest prefix which is also suffix array (LPS array)",
"function_declaration": "def compute_lps(pattern):",
"function_name": "compute_lps",
"parameter_list": "(pattern)"
},
{
"docstring": "Knuth-Morris-Pratt search algorithm to find all starting indexes of patter... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_lps(pattern):\n \"\"\"\n Compute the longest prefix which is also suffix array (LPS array)\n \"\"\"\n lps = [0] * len(pattern)\n length = 0\n i = 1\n while i <... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028742",
"row_id": 28742,
"seed_ids": "['Qwen2-72B-Instruct_68286']"
} | 0.6257 | Filter_28742 | I | [
"compute_lps",
"kmp_search"
] | 2 | [
[
"kmp_search",
"compute_lps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c793475642365ad9d9c328b99ae013847e536e1 | 3c77c7ede30659659f07bef730edd45568daf091 | |||
v1.0 | instruct | Filter | Filter_28762_I | Use the following code, and write a script to efficiently print out all the numbers in the list that are prime, and also their positions in the list. Additionally, the script should compute and print the average position of the prime numbers in the list. Do not use any external libraries beyond the default Python libra... | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_div = int(n**0.5) + 1
for d in range(3, max_div, 2):
if n % d == 0:
return False
return True
def f... | from solution import is_prime, find_primes_and_average_position, print_primes_and_average_position
import io
import sys
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers in the list and their positions.\nReturns a tuple containing:\n1. A list of tuples where each tupl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028762",
"row_id": 28762,
"seed_ids": "['Qwen2-72B-Instruct_68316']"
} | 0.622547 | Filter_28762 | I | [
"is_prime",
"find_primes_and_average_position",
"print_primes_and_average_position"
] | 3 | [
[
"find_primes_and_average_position",
"is_prime"
],
[
"print_primes_and_average_position",
"find_primes_and_average_position"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c9f5f7238a802242a8fb6b5ba7bb975b8d1dbb3b | 94ced866dad5d96dbd63477f7b559cc849eb2c6a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.