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_34793_I | Create two functions. The first function should generate a list of N integers. The second function should take this list as an input and return a new list where each element is replaced by the next greatest prime number which is greater than the current number in the list. Should there be no such prime number, that num... | def generate_integers_list(N):
"""
Generates a list of N integers starting from 1.
"""
return list(range(1, N + 1))
def is_prime(num):
"""
Determines if a number is a prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
... | from solution import generate_integers_list, next_greatest_prime
def test_generate_integers_list():
assert generate_integers_list(0) == []
assert generate_integers_list(1) == [1]
assert generate_integers_list(5) == [1, 2, 3, 4, 5]
assert generate_integers_list(10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
de... | [
{
"docstring": "Generates a list of N integers starting from 1.",
"function_declaration": "def generate_integers_list(N):",
"function_name": "generate_integers_list",
"parameter_list": "(N)"
},
{
"docstring": "Determines if a number is a prime.",
"function_declaration": "def is_prime(num... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n 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 <... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034793",
"row_id": 34793,
"seed_ids": "['Qwen2-72B-Instruct_78520']"
} | 0.650162 | Filter_34793 | I | [
"generate_integers_list",
"is_prime",
"next_greatest_prime"
] | 3 | [
[
"next_greatest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cda2752eac104b26831c98f8f41c3a093f06f2ad | 79c8efe854244614511706be598c0f4ecfdca4b4 | |||
v1.0 | instruct | Filter | Filter_34799_I | Create a dictionary using comprehension technique in Python language, where keys are prime numbers within the range 1 to 50 and their values are their cubes. Additionally, include a method to check the dictionary's correctness, such that it verifies both: the keys are prime within given range and the values are accurat... | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def generate_prime_cubes_dict():
"""
Generate a dictionary where the keys are prime numbers within the rang... | from solution import is_prime, generate_prime_cubes_dict, verify_prime_cubes_dict
def test_is_prime():
assert not is_prime(1) # 1 is not a prime number
assert is_prime(2) # 2 is a prime number
assert is_prime(3) # 3 is a prime number
assert not is_prime(4) # 4 is not a prime number
asse... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a dictionary where the keys are prime numbers within the range 1 to 50 and their values are their cubes.",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n 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_1 | {
"original_instruction": "",
"prompt_id": "00034799",
"row_id": 34799,
"seed_ids": "['Qwen2-72B-Instruct_78530']"
} | 0.617787 | Filter_34799 | I | [
"is_prime",
"generate_prime_cubes_dict",
"verify_prime_cubes_dict"
] | 3 | [
[
"generate_prime_cubes_dict",
"is_prime"
],
[
"verify_prime_cubes_dict",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e8b9edb153002be2c52fe83231d862c68a7616c5 | 777cb1e3d6eea62e8c987ff533cb1c4a8dac08f3 | |||
v1.0 | instruct | Filter | Filter_34800_I | Write a Python program that simulates two spaceships moving in opposite directions from a space station starting with the same position. After a certain amount of time, calculate their distances from the space station considering their acceleration due to gravity and fuel consumption, which impacts their velocity. Also... | import random
def calculate_distance(time, initial_velocity, acceleration, error_rate=0.05):
"""
Calculate the distance traveled considering acceleration and initial velocity,
and applying a random error rate.
"""
# Simulating possible errors in time and velocity measurements
time_error = time ... | from solution import calculate_distance, spaceship_distances
def test_calculate_distance():
# Simple test to check if calculation works within error bounds (considering margin of 10%)
time = 10
initial_velocity = 20
acceleration = 2
error_margin = 0.1
expected_distance = (initial_velocity * tim... | [
{
"docstring": "Calculate the distance traveled considering acceleration and initial velocity,\nand applying a random error rate.",
"function_declaration": "def calculate_distance(time, initial_velocity, acceleration, error_rate=0.05):",
"function_name": "calculate_distance",
"parameter_list": "(tim... | [
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 spaceship_distance(time, initial_velocity, acceleration, measurement_error):\n \"\"\"\n Calculate the distance of the spaceship from the space station after a certain ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034800",
"row_id": 34800,
"seed_ids": "['Qwen2-72B-Instruct_78531']"
} | 0.43747 | Filter_34800 | I | [
"calculate_distance",
"spaceship_distances"
] | 2 | [
[
"spaceship_distances",
"calculate_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bfc677f10833960aa8543ae2b199e73d2d51ae20 | 89e60254bf3a52d04ed69912f6975e2ef90b8c60 | |||
v1.0 | instruct | Filter | Filter_34804_I | Create a 2D array with three rows and two columns. Each element in the array must be a unique prime number. Additionally, include a function that checks if a given number is prime, and use it to validate the array. | def is_prime(n):
"""
Check if a given number n is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def generate_prime_2d_array():
"""
Generate a 2D array with three rows and two columns,... | from solution import is_prime, generate_prime_2d_array
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
def test_generate_prime_2d_array():
prime_2d_array = generate_prime_2d_array()
... | [
{
"docstring": "Check if a given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a 2D array with three rows and two columns,\nwhere each element is a unique prime number.",
"functio... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034804",
"row_id": 34804,
"seed_ids": "['Qwen2-72B-Instruct_78536']"
} | 0.579837 | Filter_34804 | I | [
"is_prime",
"generate_prime_2d_array"
] | 2 | [
[
"generate_prime_2d_array",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b58cd80d4abf23b7fbb0222542624daa1cf5ca5 | b4b90ee9c6a95f55c6225def5089d81f12f447d2 | |||
v1.0 | instruct | Filter | Filter_34816_I | Given a list of integers and a given number, write a function to determine if any two numbers in the list sum up to the given number using a hash table data structure. Additionally, implement a performance counter, to measure how long the function takes to execute. | import time
def two_sum(nums, target):
"""
Determines if any two numbers in the list sum up to the given number using a hash table.
:param nums: List of integers
:param target: Integer target sum
:return: Boolean indicating if any two numbers sum up to the target
"""
hash_table = {}
... | from solution import two_sum, timed_two_sum
def test_two_sum_found():
assert two_sum([1, 2, 3, 4], 5) == True
assert two_sum([10, 2, 3, 7], 9) == True
def test_two_sum_not_found():
assert two_sum([1, 2, 3, 4], 10) == False
assert two_sum([10, 2, 3, 7], 20) == False
def test_two_sum_empty_list():
... | [
{
"docstring": "Determines if any two numbers in the list sum up to the given number using a hash table.\n\n:param nums: List of integers\n:param target: Integer target sum\n:return: Boolean indicating if any two numbers sum up to the target",
"function_declaration": "def two_sum(nums, target):",
"funct... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef has_pair_with_sum(nums, target):\n \"\"\"\n Determines if there are any two numbers in the nums list that add up to the target number.\n \"\"\"\n start_time = ti... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034816",
"row_id": 34816,
"seed_ids": "['Qwen2-72B-Instruct_78553']"
} | 0.573703 | Filter_34816 | I | [
"two_sum",
"timed_two_sum"
] | 2 | [
[
"timed_two_sum",
"two_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 963a1809dacd9701ded7c4d07c7d9905c5e0ef17 | 8fd674f603692e48011159410745269c651f9302 | |||
v1.0 | instruct | Filter | Filter_34830_I | create a python program that creates a list of prime numbers from 1 to 100 | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def list_primes_u... | from solution import is_prime, list_primes_up_to_100
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
def test_list_primes_up_to_100():
expected_primes... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from 1 to 100.",
"function_declaration": "def list_primes_up_to_100():",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034830",
"row_id": 34830,
"seed_ids": "['Qwen2-72B-Instruct_78585']"
} | 0.576144 | Filter_34830 | I | [
"is_prime",
"list_primes_up_to_100"
] | 2 | [
[
"list_primes_up_to_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2dabb8491f201f29a5d2a69c18568c9e12cd96ae | d4f3384970f6da82e3d44c127d42de2ab6aca90f | |||
v1.0 | instruct | Filter | Filter_34834_I | Amend the following program. Firstly, it should only obtain numbers from the user until a non-numeric input is given rather than a predetermined set of inputs. Secondly, instead of summing up the numbers, the program should find the prime numbers out of the inputs and print them out at the end. | def is_prime(num):
"""
Returns True if the number is prime, otherwise False.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def get_prime_numbers():
"""
Continuously obtains numbers from user un... | from solution import is_prime, get_prime_numbers
def test_is_prime_with_primes():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(11) == True
def test_is_prime_with_non_primes():
assert is_prime(1) == False
assert ... | [
{
"docstring": "Returns True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Continuously obtains numbers from user until a non-numeric input is given.\nReturns a list of prime ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is 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 re... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034834",
"row_id": 34834,
"seed_ids": "['Qwen2-72B-Instruct_78591']"
} | 0.554866 | Filter_34834 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba7f7f8531c71b75ebee3e6fb4b8387881e4d933 | d32e26457806e80a8995820f30f9f4ac7c9d9e79 | |||
v1.0 | instruct | Filter | Filter_34853_I | Write a function that takes a list of numbers as input and returns the list sorted in ascending order using a heap sort algorithm. | def heapify(arr, n, i):
"""
Turns a subtree rooted with node i into a max heap.
n is size of heap.
"""
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... | from solution import heap_sort
def test_heap_sort_already_sorted():
assert heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_heap_sort_reverse_sorted():
assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_heap_sort_unsorted():
assert heap_sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [1, 1, 2, 3, 4... | [
{
"docstring": "Turns a subtree rooted with node i into a max heap.\nn is size of heap.",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": "Sorts an array in ascending order using heap sort.",
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heap_sort(nums):\n \"\"\"\n Takes a list of numbers and returns the list sorted in ascending order using heap sort algorithm.\n \"\"\"\n def heapify(nums, heap_size, root_index... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034853",
"row_id": 34853,
"seed_ids": "['Qwen2-72B-Instruct_78621']"
} | 0.879475 | Filter_34853 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7c32c5cccd671fcf7e1a736ab47c8aeb458d2fe | 6a7836917d0f7617fcbf244419c1c33ebca2d11f | |||
v1.0 | instruct | Filter | Filter_34864_I | Write a Python program that takes a list of positive integers as input and returns the count of unique prime factors for each number in the list. The program should handle numbers up to 10^12. | def count_prime_factors(n):
"""
Returns the count of unique prime factors of n.
"""
i = 2
factors = set()
# Check for number of 2s as a factor
while n % i == 0:
factors.add(i)
n //= i
# Check for odd factors from 3 onwards
i = 3
while i * i <= n:
while n %... | def test_count_prime_factors():
assert count_prime_factors(28) == 2 # 28 = 2 * 2 * 7
assert count_prime_factors(30) == 3 # 30 = 2 * 3 * 5
assert count_prime_factors(17) == 1 # 17 is a prime number
assert count_prime_factors(1) == 0 # 1 has no prime factors
assert count_prime_factors(84) == 3 #... | [
{
"docstring": "Returns the count of unique prime factors of n.",
"function_declaration": "def count_prime_factors(n):",
"function_name": "count_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list with counts of unique prime factors for every number in lst.",
"funct... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_prime_factors_count(numbers):\n \"\"\"\n Returns a list containing the count of unique prime factors for each number in the input list.\n \"\"\"\n def is_prime(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034864",
"row_id": 34864,
"seed_ids": "['Qwen2-72B-Instruct_78644']"
} | 0.692942 | Filter_34864 | I | [
"count_prime_factors",
"prime_factors_count"
] | 2 | [
[
"prime_factors_count",
"count_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dc186bc543349a48b068269fdbfe69e1e4b87b78 | 694f2e2654b10dc8f88becd268bf2cc68cdf7b52 | |||
v1.0 | instruct | Filter | Filter_34887_I | Design a basic program that will accept integers as input and print a list of these integers in descending order. The program should not incorporate built-in sorting functions to arrange the list, rather, it should implement its own sorting algorithm. | def bubble_sort_descending(arr):
"""
Sorts a list of integers in descending order using bubble sort algorithm.
"""
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] < arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
def get_sorted_in... | from solution import get_sorted_integers
def test_sorted_integers_with_positive_numbers():
assert get_sorted_integers([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [9, 6, 5, 5, 4, 3, 2, 1, 1]
def test_sorted_integers_with_negative_numbers():
assert get_sorted_integers([-1, -3, -2, -5, -4]) == [-1, -2, -3, -4, -5]
def test... | [
{
"docstring": "Sorts a list of integers in descending order using bubble sort algorithm.",
"function_declaration": "def bubble_sort_descending(arr):",
"function_name": "bubble_sort_descending",
"parameter_list": "(arr)"
},
{
"docstring": "Accepts a list of integers and returns it sorted in ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def insertion_sort_descending(arr):\n \"\"\"\n Sort the list in descending order using insertion sort algorithm.\n \"\"\"\n for i in range(1, len(arr)):\n key = arr[i]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034887",
"row_id": 34887,
"seed_ids": "['Qwen2-72B-Instruct_78678']"
} | 0.585117 | Filter_34887 | I | [
"bubble_sort_descending",
"get_sorted_integers"
] | 2 | [
[
"get_sorted_integers",
"bubble_sort_descending"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e16383511063b2ee4f15f819316844a588cf4cc1 | a08190d76f04d9c08a49f5c40a611ab4285d4f3f | |||
v1.0 | instruct | Filter | Filter_34896_I | Create a Python function that implements an insertion sort algorithm, sorts a list of floating point numbers in descending order, and includes a functionality to check correctness by comparing sorted and unsorted list. | def insertion_sort_descending(arr):
"""
Sorts a list of floating point numbers in descending order using the insertion sort algorithm.
Args:
arr (list of float): The list of floating point numbers to sort.
Returns:
list of float: The sorted list in descending order.
"""
n = len... | from solution import insertion_sort_descending, is_sorted_descending, sort_and_check
def test_insertion_sort_descending():
assert insertion_sort_descending([4.5, 1.2, 3.3]) == [4.5, 3.3, 1.2]
assert insertion_sort_descending([2.2, 2.2, 1.1]) == [2.2, 2.2, 1.1]
assert insertion_sort_descending([5.5, 6.6, -4... | [
{
"docstring": "Sorts a list of floating point numbers in descending order using the insertion sort algorithm.\n\nArgs:\narr (list of float): The list of floating point numbers to sort.\n\nReturns:\nlist of float: The sorted list in descending order.",
"function_declaration": "def insertion_sort_descending(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def insertion_sort_descending(arr):\n \"\"\"\n Performs an insertion sort on the input list of floating point numbers in descending order.\n Returns the sorted list and a correctness ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034896",
"row_id": 34896,
"seed_ids": "['Qwen2-72B-Instruct_78697']"
} | 0.595915 | Filter_34896 | I | [
"insertion_sort_descending",
"is_sorted_descending",
"sort_and_check"
] | 3 | [
[
"sort_and_check",
"insertion_sort_descending"
],
[
"sort_and_check",
"is_sorted_descending"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 253c61db81ab02805d953f989c8490a54b74919e | 61c0816dd2d8f6cf1ed4427864d179b433903f2b | |||
v1.0 | instruct | Filter | Filter_34899_I | Write a Python program that defines a function to calculate the smallest common multiple (SCM), also known as the least common multiple (LCM), of two positive integers using the greatest common divisor (GCD) method. Implement this function and call it `smallest_common_multiple`. Additionally, write a check function tha... | def gcd(a, b):
"""
Returns the greatest common divisor (GCD) of a and b.
"""
while b:
a, b = b, a % b
return a
def smallest_common_multiple(a, b):
"""
Returns the smallest common multiple (LCM) of a and b.
"""
return abs(a * b) // gcd(a, b) | from solution import smallest_common_multiple
def test_scm_same_numbers():
assert smallest_common_multiple(10, 10) == 10
def test_scm_coprime_numbers():
assert smallest_common_multiple(3, 7) == 21
def test_scm_general_case():
assert smallest_common_multiple(4, 5) == 20
assert smallest_common_multiple... | [
{
"docstring": "Returns the greatest common divisor (GCD) of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the smallest common multiple (LCM) of a and b.",
"function_declaration": "def smallest_common_mu... | [
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 smallest_common_multiple(a, b):\n \"\"\"\n Returns the smallest common multiple (LCM) of two positive integers a and b.\n \"\"\"\n if a <= 0 or b <= 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034899",
"row_id": 34899,
"seed_ids": "['Qwen2-72B-Instruct_78704']"
} | 0.671665 | Filter_34899 | I | [
"gcd",
"smallest_common_multiple"
] | 2 | [
[
"smallest_common_multiple",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3f7c799cf0acf69f170b7a10af27a78866a01956 | f776bc6c88cb84a6edec8fd9c69e833e41527a82 | |||
v1.0 | instruct | Filter | Filter_34905_I | Develop a recursive function in Python that calculates the factorial of a number. Additionally, create another function to measure the time required to calculate the factorial of a number and also assess the memory used by the recursive function. Implement both memory profiling and time profiling in the program, which ... | import time
import tracemalloc
def factorial(n):
"""
Returns the factorial of n using recursion.
"""
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
def measure_performance(n):
"""
Measures the execution time and memory usage of the factorial computation.
"""
# St... | from solution import factorial, measure_performance
def test_factorial_base_cases():
assert factorial(0) == 1
assert factorial(1) == 1
def test_factorial_small_numbers():
assert factorial(3) == 6
assert factorial(5) == 120
def test_factorial_large_numbers():
assert factorial(10) == 3628800
def t... | [
{
"docstring": "Returns the factorial of n using recursion.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Measures the execution time and memory usage of the factorial computation.",
"function_declaration": "def me... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport tracemalloc\n\ndef factorial(n):\n \"\"\"\n Returns the factorial of a number n using recursion.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n else:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034905",
"row_id": 34905,
"seed_ids": "['Qwen2-72B-Instruct_78715']"
} | 0.507604 | Filter_34905 | I | [
"factorial",
"measure_performance"
] | 2 | [
[
"measure_performance",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 31abb526d437b0c52c292cd0895df89ca5e0f8b4 | 341df231aaf6f413478fe01e27fccd6fae1b6974 | |||
v1.0 | instruct | Filter | Filter_34941_I | Create an encryption function that uses an XOR cipher with a randomly generated key of minimum length 16 bits and maximum length 65536 bits, where each byte of the key is restricted to a specific range of ASCII characters (33-126). The input string must be ASCII encoded. | import random
def generate_random_key(length):
"""
Generates a random key of the given length with each byte in the range of 33-126 ASCII characters.
"""
return bytes([random.randint(33, 126) for _ in range(length)])
def xor_encrypt(input_string):
"""
Encrypts the input_string using XOR encryp... | def test_generate_random_key_length():
key = generate_random_key(16)
assert len(key) == 16
key = generate_random_key(100)
assert len(key) == 100
key = generate_random_key(8192)
assert len(key) == 8192
def test_generate_random_key_value():
key = generate_random_key(50)
for byte in key:
... | [
{
"docstring": "Generates a random key of the given length with each byte in the range of 33-126 ASCII characters.",
"function_declaration": "def generate_random_key(length):",
"function_name": "generate_random_key",
"parameter_list": "(length)"
},
{
"docstring": "Encrypts the input_string u... | [
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 xor_encryption(input_string):\n \"\"\"\n Encrypts the input string using XOR cipher with a randomly generated key.\n key length is between 2 bytes (16 bits) to 81... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034941",
"row_id": 34941,
"seed_ids": "['Qwen2-72B-Instruct_78772']"
} | 0.538425 | Filter_34941 | I | [
"generate_random_key",
"xor_encrypt",
"xor_decrypt"
] | 3 | [
[
"xor_encrypt",
"generate_random_key"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | cb0345c73cb386eeb2ea4708c50601c22f6c2009 | f796e6cdfb469909d28853ace9e5b55b34a2b97e | |||
v1.0 | instruct | Filter | Filter_34957_I | Write python code for initializing 1000 random variables in the range of 1 to 100 and determine how many of those variables can be divisible by 3. Further, filter these results to find how many of these numbers are also prime. | import random
def initialize_random_variables(n=1000, low=1, high=100):
"""
Initialize n random variables within the range [low, high].
"""
return [random.randint(low, high) for _ in range(n)]
def count_divisible_by(numbers, divisor):
"""
Count the numbers in the list that are divisible by the... | from solution import initialize_random_variables, count_divisible_by, is_prime, filter_primes
def test_initialize_random_variables():
variables = initialize_random_variables(n=1000, low=1, high=100)
assert len(variables) == 1000
assert all(1 <= num <= 100 for num in variables)
def test_count_divisible_by(... | [
{
"docstring": "Initialize n random variables within the range [low, high].",
"function_declaration": "def initialize_random_variables(n=1000, low=1, high=100):",
"function_name": "initialize_random_variables",
"parameter_list": "(n=1000, low=1, high=100)"
},
{
"docstring": "Count the number... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef initialize_random_variables(n=1000, low=1, high=100):\n \"\"\"\n Initialize n random variables within the range [low, high].\n \"\"\"\n return [random.randint(... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034957",
"row_id": 34957,
"seed_ids": "['Qwen2-72B-Instruct_78795']"
} | 0.585313 | Filter_34957 | I | [
"initialize_random_variables",
"count_divisible_by",
"is_prime",
"filter_primes"
] | 4 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | baa623d6ad43073b196568cab9cd623a8cdc24fe | a1e7a79f4a3847eb640447286e491621f06e248c | |||
v1.0 | instruct | Filter | Filter_34977_I | Write a type annotation for a function that takes a list of integers as an input, and returns a list of tuples, where each tuple contains the integer and a boolean value indicating if the integer is prime. Additionally, filter out all the non-prime numbers from the list. | from typing import List, Tuple
def is_prime(n: int) -> bool:
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_list(input_list: List[int]) -> List[Tuple[int, bool]]:
return [(num, True) for num in input_list if is_... | from solution import prime_list
def test_prime_list_with_mixed_numbers():
assert prime_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [(2, True), (3, True), (5, True), (7, True)]
def test_prime_list_with_duplicates():
assert prime_list([2, 3, 3, 4, 5, 11, 11]) == [(2, True), (3, True), (3, True), (5, True), (11, Tr... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_list(input_list):",
"function_name": "prime_list",
"parameter_list": "(input_list)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num < 2:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034977",
"row_id": 34977,
"seed_ids": "['Qwen2-72B-Instruct_78827']"
} | 0.550577 | Filter_34977 | I | [
"is_prime",
"prime_list"
] | 2 | [
[
"prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7be02efb4ad3d44675cd4641f118d68956048d57 | 0bbed9304f65560dca4108c9bdc63ab64986d48d | |||
v1.0 | instruct | Filter | Filter_34979_I | How can I calculate the factorial of a number using Python without any built-in function or external library and additionally, perform this operation recursively and iteratively in one combined function? | def factorial(n, method="iterative"):
"""
Calculate the factorial of a number using the specified method (iterative or recursive).
:param n: Number to calculate the factorial.
:param method: Method of calculation, either "iterative" or "recursive".
:return: Factorial of the number n.
"""
... | from solution import factorial
def test_factorial_iterative():
assert factorial(0, "iterative") == 1
assert factorial(1, "iterative") == 1
assert factorial(5, "iterative") == 120
assert factorial(7, "iterative") == 5040
def test_factorial_recursive():
assert factorial(0, "recursive") == 1
asse... | [
{
"docstring": "Calculate the factorial of a number using the specified method (iterative or recursive).\n\n:param n: Number to calculate the factorial.\n:param method: Method of calculation, either \"iterative\" or \"recursive\".\n:return: Factorial of the number n.",
"function_declaration": "def factorial... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial(n, method=\"iterative\"):\n \"\"\"\n Returns the factorial of n using either iterative or recursive method.\n \n Parameters:\n n (int): The number to compute the f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034979",
"row_id": 34979,
"seed_ids": "['Qwen2-72B-Instruct_78829']"
} | 0.695027 | Filter_34979 | I | [
"factorial",
"factorial_iterative",
"factorial_recursive"
] | 3 | [
[
"factorial",
"factorial_iterative"
],
[
"factorial",
"factorial_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f7521f106f61d1064ec7b6c93e9b5d05d2b0c9a1 | 7911fc90e1d91e51cbd831270be84e74284cf9b5 | |||
v1.0 | instruct | Filter | Filter_34983_I | Write a Python function that accepts a number n and generates a list of n stringified numbers starting from 1. Furthermore, each string in the list should be padded to a length of 3 with leading zeros, and the function should handle the case where n is greater than 999 by converting the n-th number to Roman Numerals an... | def int_to_roman(num):
"""
Converts an integer to a Roman Numeral.
"""
val = [
1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4,
1
]
syb = [
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
]
ro... | from solution import generate_stringified_numbers
def test_generate_less_than_999():
assert generate_stringified_numbers(5) == ['001', '002', '003', '004', '005']
assert generate_stringified_numbers(1) == ['001']
def test_generate_exactly_999():
result = generate_stringified_numbers(999)
assert len(re... | [
{
"docstring": "Converts an integer to a Roman Numeral.",
"function_declaration": "def int_to_roman(num):",
"function_name": "int_to_roman",
"parameter_list": "(num)"
},
{
"docstring": "Generates a list of n stringified numbers starting from 1,\nwith each string padded to a length of 3 with ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def int_to_roman(num):\n val = [\n 1000, 900, 500, 400,\n 100, 90, 50, 40,\n 10, 9, 5, 4,\n 1\n ]\n syb = [\n \"M\", \"CM\", \"D\", \"CD\",\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034983",
"row_id": 34983,
"seed_ids": "['Qwen2-72B-Instruct_78838']"
} | 0.639246 | Filter_34983 | I | [
"int_to_roman",
"generate_stringified_numbers"
] | 2 | [
[
"generate_stringified_numbers",
"int_to_roman"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ecc94fcafa488672dceef93895e7c6f7f5a41fe3 | f17dba078a0d6dfd74b38ce040c5134cf6faf1a2 | |||
v1.0 | instruct | Filter | Filter_34985_I | I'm running a recursive function in Python which uses yield from to implement a depth-first traversal of a tree data structure. I'd like to implement a timeout on the traversal, so that if it doesn't spit out any output after 5 seconds (sleeps, waits, pauses, etc), it moves on to the next point. Where do you think I sh... | import signal
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException
def depth_first_traversal(node, timeout=5):
"""
Generator function to yield nodes in a depth-first traversal
of a tree structure. It includes a timeout to prevent infinite recursion.
... | from solution import depth_first_traversal
def test_depth_first_traversal():
tree = {
'value': 1,
'children': [
{'value': 2, 'children': [
{'value': 4}, {'value': 5}
]},
{'value': 3, 'children': [
{'value': 6}, {'value': 7}
... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import signal\n\nclass TimeoutException(Exception):\n pass\n\ndef timeout_handler(signum, frame):\n raise TimeoutException\n\ndef depth_first_traversal(node, timeout=5):\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00034985",
"row_id": 34985,
"seed_ids": "['Qwen2-72B-Instruct_78844']"
} | 0.399908 | Filter_34985 | I | [
"timeout_handler",
"depth_first_traversal",
"_depth_first_traversal"
] | 3 | [
[
"depth_first_traversal",
"_depth_first_traversal"
],
[
"depth_first_traversal",
"timeout_handler"
]
] | 2 | [] | false | [
"TimeoutException"
] | true | pytest | true | [] | true | 017138dd4ec9f640fb14ba6de2237635ccbfb69e | 245d411accb36c1129a1ef28e1af744e9b3dcf8b | |||
v1.0 | instruct | Filter | Filter_34991_I | Generate a code snippet for finding the kth smallest element in an array using Quickselect algorithm. | def quickselect(arr, k):
"""
Finds the k-th smallest element in an array using the Quickselect algorithm.
:param arr: List of elements
:param k: The k-th position to find (1-based index)
:return: The k-th smallest element
"""
if k < 1 or k > len(arr):
raise ValueError("k is out of b... | from solution import quickselect
def test_quickselect_basic():
arr = [3, 2, 1, 5, 4]
assert quickselect(arr, 2) == 2
def test_quickselect_single_element():
arr = [1]
assert quickselect(arr, 1) == 1
def test_quickselect_sorted_array():
arr = [1, 2, 3, 4, 5]
assert quickselect(arr, 3) == 3
def... | [
{
"docstring": "Finds the k-th smallest element in an array using the Quickselect algorithm.\n\n:param arr: List of elements\n:param k: The k-th position to find (1-based index)\n:return: The k-th smallest element",
"function_declaration": "def quickselect(arr, k):",
"function_name": "quickselect",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def partition(arr, low, high):\n \"\"\"\n Partition the array using the last element as pivot.\n \"\"\"\n pivot = arr[high]\n i = low - 1\n for j in range(low, high):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034991",
"row_id": 34991,
"seed_ids": "['Qwen2-72B-Instruct_78852']"
} | 0.607737 | Filter_34991 | I | [
"quickselect",
"quickselect_helper",
"partition"
] | 3 | [
[
"quickselect",
"quickselect_helper"
],
[
"quickselect_helper",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5eda2df027e399614aeb9df2f8fff1bb8e584a83 | 05da014aa6301c372e86f007e80537c761c8a1a0 | |||
v1.0 | instruct | Filter | Filter_35006_I | Given the following block of code that attempts to implement the Kadane's algorithm for finding the maximum subarray sum in an array of integers. However, the code is not functioning correctly. Your task is to correct and optimize the existing code, making necessary modifications, and also to increase its complexity by... | def kadane_algorithm(arr):
"""
Returns the maximum subarray sum using Kadane's algorithm.
"""
max_current = max_global = arr[0]
for num in arr[1:]:
max_current = max(num, max_current + num)
if max_current > max_global:
max_global = max_current
return max_global
def k... | from solution import kadane_algorithm, kadane_algorithm_min, kadane_algorithm_max_and_min
def test_kadane_algorithm_with_positive_numbers():
assert kadane_algorithm([1, 2, 3, 4, 5]) == 15
def test_kadane_algorithm_with_negative_numbers():
assert kadane_algorithm([-1, -2, -3, -4, -5]) == -1
def test_kadane_al... | [
{
"docstring": "Returns the maximum subarray sum using Kadane's algorithm.",
"function_declaration": "def kadane_algorithm(arr):",
"function_name": "kadane_algorithm",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the minimum subarray sum using a variation of Kadane's algorithm.",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def kadane_algorithm(arr):\n \"\"\"\n Returns the maximum subarray sum using Kadane's algorithm.\n \"\"\"\n max_current = max_global = arr[0]\n for num in arr[1:]:\n max_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035006",
"row_id": 35006,
"seed_ids": "['Qwen2-72B-Instruct_78875']"
} | 0.685068 | Filter_35006 | I | [
"kadane_algorithm",
"kadane_algorithm_min",
"kadane_algorithm_max_and_min"
] | 3 | [
[
"kadane_algorithm_max_and_min",
"kadane_algorithm"
],
[
"kadane_algorithm_max_and_min",
"kadane_algorithm_min"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 94e46509f6a1b4980bc65594c8a2f26982c4e51c | b34f9cb8b394b276a2b99e0435ad343d1f704087 | |||
v1.0 | instruct | Filter | Filter_35010_I | In Python, create a function that accomplishes the task of determining the largest common divisor, aka the greatest common divisor (GCD), for a pair of specified integer inputs, subsequent to calculating and outputting the least common multiple (LCM) for the identical pair of integers. These values should essentially b... | def gcd(a, b):
"""
Returns the greatest common divisor (GCD) of a and b.
"""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""
Returns the least common multiple (LCM) of a and b.
"""
return abs(a * b) // gcd(a, b)
def calculate_lcm_and_gcd(a, b):
"""
Returns a tu... | from solution import calculate_lcm_and_gcd, gcd, lcm
def test_gcd():
assert gcd(9, 6) == 3
assert gcd(15, 5) == 5
assert gcd(28, 20) == 4
assert gcd(7, 1) == 1
def test_lcm():
assert lcm(9, 6) == 18
assert lcm(15, 5) == 15
assert lcm(28, 20) == 140
assert lcm(7, 1) == 7
def test_calcu... | [
{
"docstring": "Returns the greatest common divisor (GCD) of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least common multiple (LCM) of a and b.",
"function_declaration": "def lcm(a, b):",
"fun... | [
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 gcd_lcm(a, b):\n \"\"\"\n Returns a tuple containing the greatest common divisor (GCD) and \n the least common multiple (LCM) of the given two integers a and b.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035010",
"row_id": 35010,
"seed_ids": "['Qwen2-72B-Instruct_78879']"
} | 0.760757 | Filter_35010 | I | [
"gcd",
"lcm",
"calculate_lcm_and_gcd"
] | 3 | [
[
"calculate_lcm_and_gcd",
"gcd"
],
[
"calculate_lcm_and_gcd",
"lcm"
],
[
"lcm",
"gcd"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a42e99f39e4931f6ac96f667490d36c3866d15e5 | 03b299ffd919d1ebb097310c01d090ebb521643a | |||
v1.0 | instruct | Filter | Filter_35013_I | Rewrite the Fibonacci sequence logic using recursive function in Python. Also, include a functionality to calculate the Fibonacci sequence up to n terms, where n is a user input. Additionally, implement memoization to increase the efficiency of the recursive function. | def fibonacci_recursive(n, memo=None):
"""
Recursive function to calculate the nth Fibonacci number using memoization.
"""
if memo is None:
memo = {}
if n in memo:
return memo[n]
if n <= 1:
return n
memo[n] = fibonacci_recursive(n-1, memo) + fibonacci_recursive(n-2, m... | from solution import fibonacci_recursive, fibonacci_sequence_up_to
def test_fibonacci_recursive():
assert fibonacci_recursive(0) == 0
assert fibonacci_recursive(1) == 1
assert fibonacci_recursive(5) == 5
assert fibonacci_recursive(10) == 55
assert fibonacci_recursive(15) == 610
def test_fibonacci_... | [
{
"docstring": "Recursive function to calculate the nth Fibonacci number using memoization.",
"function_declaration": "def fibonacci_recursive(n, memo=None):",
"function_name": "fibonacci_recursive",
"parameter_list": "(n, memo=None)"
},
{
"docstring": "Returns the Fibonacci sequence up to t... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Returns the nth Fibonacci number using memoization for efficiency.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 1:\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035013",
"row_id": 35013,
"seed_ids": "['Qwen2-72B-Instruct_78882']"
} | 0.756286 | Filter_35013 | I | [
"fibonacci_recursive",
"fibonacci_sequence_up_to"
] | 2 | [
[
"fibonacci_sequence_up_to",
"fibonacci_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9fba12781a517295fb241603a989d837b92c6248 | b5c326e1c9d2af80fdda7e2ae6f56f7a902d89dc | |||
v1.0 | instruct | Filter | Filter_35052_I | Alter the accompanying Python script so that it displays odd integers within the bracket of one to twelve. Additionally, write a function that checks if a given number is prime. Use this function to print all prime numbers (not necessarily odd) in the range between one and twenty. | def print_odd_numbers():
"""
Prints odd integers within the range of 1 to 12.
"""
for i in range(1, 13):
if i % 2 != 0:
print(i)
def is_prime(n):
"""
Checks if a given number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
... | from solution import is_prime
def test_is_prime_with_prime_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(11) == True
assert is_prime(13) == True
assert is_prime(17) == True
assert is_prime(19) == Tr... | [
{
"docstring": "Prints odd integers within the range of 1 to 12.",
"function_declaration": "def print_odd_numbers():",
"function_name": "print_odd_numbers",
"parameter_list": "()"
},
{
"docstring": "Checks if a given number is prime.",
"function_declaration": "def is_prime(n):",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def print_odds():\n \"\"\"\n Prints odd integers from 1 to 12 (inclusive).\n \"\"\"\n for num in range(1, 13):\n if num % 2 != 0:\n print(num)\n\ndef is_prime(n):... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035052",
"row_id": 35052,
"seed_ids": "['Qwen2-72B-Instruct_78956']"
} | 0.546299 | Filter_35052 | I | [
"print_odd_numbers",
"is_prime",
"print_prime_numbers"
] | 3 | [
[
"print_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bdd79f6bd9c7e8b3a4cbc6a8a186171e96180670 | 64908d5b0cab6a7cd9f0dcb1a7cabb72508eff47 | |||
v1.0 | instruct | Filter | Filter_35065_I | Given two unsorted linked lists, write code to sort them in ascending order. After sorting, merge them into one sorted linked list. Your solution should have a time complexity as close to O(n log n) as possible. | class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def mergeTwoLists(l1, l2):
dummy = ListNode()
current = dummy
while l1 and l2:
if l1.value < l2.value:
current.next = l1
l1 = l1.next
else:
cu... | from solution import ListNode, sortAndMergeLinkedLists, linkedListToList, listToLinkedList
def test_sortAndMerge_empty_lists():
l1 = None
l2 = None
merged = sortAndMergeLinkedLists(l1, l2)
assert linkedListToList(merged) == []
def test_sortAndMerge_single_element_each():
l1 = listToLinkedList([3])... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, data):\n self.data = data\n self.next = None\n\ndef merge_sort_linked_list(head):\n if not head or not head.next:\n return head\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035065",
"row_id": 35065,
"seed_ids": "['Qwen2-72B-Instruct_78979']"
} | 0.407506 | Filter_35065 | I | [
"mergeTwoLists",
"sortList",
"linkedListToList",
"listToLinkedList",
"sortAndMergeLinkedLists"
] | 5 | [
[
"sortAndMergeLinkedLists",
"mergeTwoLists"
],
[
"sortAndMergeLinkedLists",
"sortList"
],
[
"sortList",
"mergeTwoLists"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | ff1bf2381da9dc45e5cc2e8afd2905197d0c5b89 | 88d9580d2f1f9092cc852ee877e3ebde2525cdcf | |||
v1.0 | instruct | Filter | Filter_35069_I | Create a program that reads 10 numbers from the user and finds the biggest prime number among them. If no prime number is found, the program should display a message indicating so. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import is_prime, find_biggest_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(15) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_find_biggest_prime_with_primes():
numbers = [4, 6, 7, 10, 13, 17, 23, 28,... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the biggest prime number in the list of numbers. If no prime number is found, returns None.",
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035069",
"row_id": 35069,
"seed_ids": "['Qwen2-72B-Instruct_78984']"
} | 0.548388 | Filter_35069 | I | [
"is_prime",
"find_biggest_prime"
] | 2 | [
[
"find_biggest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1103367cbe23a190ca1e7c72a15d9e0e632ec522 | 4b494543ca6b54591ff1b8ebc0de7ddb0e33ca96 | |||
v1.0 | instruct | Filter | Filter_35074_I | Develop a Python function that not only verifies if a list of strings is alphabetically arranged in descending order, but also implements a sorting algorithm to rearrange the list to adhere to the descending alphabetical order if it's not. Additionally, the function should handle case sensitivity and ignore non-alphabe... | import re
def clean_string(s):
"""
Removes non-alphabetical characters from the string and converts it to lower case.
"""
return ''.join(re.findall(r'[a-zA-Z]', s)).lower()
def is_descending_sorted(lst):
"""
Checks if the list is in descending alphabetical order considering only alphabetical c... | from solution import verify_and_sort
def test_alphabetical_order():
assert verify_and_sort(['apple', 'banana', 'cherry']) == (['cherry', 'banana', 'apple'], False)
def test_alphabetical_order_with_case_sensitivity():
assert verify_and_sort(['Apple', 'banana', 'Cherry']) == (['Cherry', 'banana', 'Apple'], Fals... | [
{
"docstring": "Removes non-alphabetical characters from the string and converts it to lower case.",
"function_declaration": "def clean_string(s):",
"function_name": "clean_string",
"parameter_list": "(s)"
},
{
"docstring": "Checks if the list is in descending alphabetical order considering ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef clean_string(s):\n \"\"\"\n Helper function to remove non-alphabetical characters and convert to lowercase.\n \"\"\"\n return re.sub(r'[^a-zA-Z]', '', s).lower()\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035074",
"row_id": 35074,
"seed_ids": "['Qwen2-72B-Instruct_78991']"
} | 0.630677 | Filter_35074 | I | [
"clean_string",
"is_descending_sorted",
"sort_descending",
"verify_and_sort"
] | 4 | [
[
"is_descending_sorted",
"clean_string"
],
[
"sort_descending",
"clean_string"
],
[
"verify_and_sort",
"is_descending_sorted"
],
[
"verify_and_sort",
"sort_descending"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | cef73068a95e6e9ea66dc63394a5ea8162e93750 | 26fa0a560f1a5c4726ba2db9ab95bd3e940f17d7 | |||
v1.0 | instruct | Filter | Filter_35082_I | Write a python script that asks for your name at the beginning and then it prints out a personalized greeting. After greeting, the script will ask for a positive integer number. The script will then check if the given number is even or odd and prints a respectively statement. Additionally, if the number is even, the sc... | def personalized_greeting_and_prime_check(name, num):
"""
Greets the user by name, checks if the given number is even or odd, and prints out the respective prime numbers.
"""
greeting = f"Hello, {name}!"
print(greeting)
if num <= 0:
raise ValueError("The number must be a positive intege... | from solution import personalized_greeting_and_prime_check, find_even_primes_less_than, find_odd_primes_less_than
def test_even_number():
assert personalized_greeting_and_prime_check("Alice", 10) == [2]
def test_odd_number():
assert personalized_greeting_and_prime_check("Bob", 10) == [2]
assert person... | [
{
"docstring": "Greets the user by name, checks if the given number is even or odd, and prints out the respective prime numbers.",
"function_declaration": "def personalized_greeting_and_prime_check(name, num):",
"function_name": "personalized_greeting_and_prime_check",
"parameter_list": "(name, num)... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def greet_and_check_number():\n \"\"\"\n Asks for the user's name and greets them.\n Asks for a positive integer number and checks if it is even or odd.\n Prints even prime numbers... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035082",
"row_id": 35082,
"seed_ids": "['Qwen2-72B-Instruct_79006']"
} | 0.546584 | Filter_35082 | I | [
"personalized_greeting_and_prime_check",
"is_prime",
"find_even_primes_less_than",
"find_odd_primes_less_than"
] | 4 | [
[
"find_odd_primes_less_than",
"is_prime"
],
[
"personalized_greeting_and_prime_check",
"find_even_primes_less_than"
],
[
"personalized_greeting_and_prime_check",
"find_odd_primes_less_than"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9f85c16d3ad00aa6d2fbca75004077d618c880d1 | 580b86d2e7476a1791e0a36ee98bc915b27ea54c | |||
v1.0 | instruct | Filter | Filter_35118_I | Water in a tank is being drained at a rate that is proportional to the square root of the height of the water. Develop a python code that solves time varying differential equation using scipy odeint for a given constant of proportionality and initial height. | import numpy as np
from scipy.integrate import odeint
def water_height_model(h, t, k):
"""
Differential equation model for the height of water being drained from a tank.
Parameters:
h : float
The height of the water at time t.
t : float
The time variable.
k : float
... | import numpy as np
from solution import solve_water_height
def test_water_height_zero_time():
k = 0.1
h0 = 10
t = [0] # Only initial time
result = solve_water_height(k, h0, t)
assert np.allclose(result, [10], atol=1e-6)
def test_water_height_single_step():
k = 0.1
h0 = 10
t = np.linsp... | [
{
"docstring": "Differential equation model for the height of water being drained from a tank.\n\nParameters:\nh : float\n The height of the water at time t.\nt : float\n The time variable.\nk : float\n The proportionality constant.\n \nReturns:\ndhdt : float\n The rate of change of the height of... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy.integrate import odeint\nimport numpy as np\n\ndef water_height_drain(h, t, k):\n \"\"\"\n Function representing the differential equation\n governing the water height drai... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035118",
"row_id": 35118,
"seed_ids": "['Qwen2-72B-Instruct_79070']"
} | 0.451757 | Filter_35118 | I | [
"water_height_model",
"solve_water_height"
] | 2 | [
[
"solve_water_height",
"water_height_model"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 295818faa5ea27b5dc4e453ba390599614601542 | 387a853bf4d53fbf929e6940517d6b894232260c | |||
v1.0 | instruct | Filter | Filter_35127_I | Create a 5x5 array with all its elements equal to 1, but ensure that the array is initialized using a recursive function rather than a simple array creation method. | def create_array(rows, cols):
"""
Creates a 2D array with the specified number of rows and columns,
and initializes all elements to 1 using recursion.
"""
if rows == 0:
return []
else:
return [create_row(cols)] + create_array(rows - 1, cols)
def create_row(cols):
"""
Cr... | from solution import create_array
def test_create_5x5_array():
array_5x5 = create_array(5, 5)
expected_array = [
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]
]
assert array_5x5 == expected_array
def test_create_2x3_array():... | [
{
"docstring": "Creates a 2D array with the specified number of rows and columns, \nand initializes all elements to 1 using recursion.",
"function_declaration": "def create_array(rows, cols):",
"function_name": "create_array",
"parameter_list": "(rows, cols)"
},
{
"docstring": "Creates a row... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def recursive_array(n, current=None):\n \"\"\"\n Returns a 5x5 array filled with 1s using a recursive approach.\n \"\"\"\n if current is None:\n current = []\n if len(cur... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035127",
"row_id": 35127,
"seed_ids": "['Qwen2-72B-Instruct_79079']"
} | 0.539612 | Filter_35127 | I | [
"create_array",
"create_row"
] | 2 | [
[
"create_array",
"create_row"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2bf5b58ab358008d3831463add1b3c889f1051b2 | a87ffdecaecd9a3d045cba8100b65ec3665f978b | |||
v1.0 | instruct | Filter | Filter_35130_I | Create a Python function that takes a list of numbers as input and returns a new list containing only the pronic numbers from the input list. | def is_pronic(n):
"""Check if a number is pronic."""
if n < 0:
return False
x = int((n) ** 0.5)
return x * (x + 1) == n
def get_pronic_numbers(numbers):
"""
Returns a list of pronic numbers from the input list.
"""
return [num for num in numbers if is_pronic(num)] | from solution import get_pronic_numbers
def test_get_pronic_numbers_all_pronic():
assert get_pronic_numbers([0, 2, 6, 12, 20]) == [0, 2, 6, 12, 20]
def test_get_pronic_numbers_mixed_numbers():
assert get_pronic_numbers([0, 1, 2, 3, 4, 5, 6, 7, 12, 20]) == [0, 2, 6, 12, 20]
def test_get_pronic_numbers_no_pron... | [
{
"docstring": "Check if a number is pronic.",
"function_declaration": "def is_pronic(n):",
"function_name": "is_pronic",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of pronic numbers from the input list.",
"function_declaration": "def get_pronic_numbers(numbers):",
"fu... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_pronic(n):\n \"\"\"\n Checks if a number is a pronic number.\n A pronic number is a number which is the product of two consecutive integers.\n Example: 0, 2, 6, 12, 20, etc.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035130",
"row_id": 35130,
"seed_ids": "['Qwen2-72B-Instruct_79083']"
} | 0.609368 | Filter_35130 | I | [
"is_pronic",
"get_pronic_numbers"
] | 2 | [
[
"get_pronic_numbers",
"is_pronic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e08c26bf0ca33fdd7d31e4a73451986d35475c3 | 6437b07bc4140d2443ae7145732ccaa291b28383 | |||
v1.0 | instruct | Filter | Filter_35157_I | Write some code that makes a list of prime numbers less than 100. Ensure that your code is as efficient as possible, explain your approach, and further, modify your code to determine and print if each prime number is part of the Fibonacci sequence. | def calculate_primes_up_to_100():
"""
Calculate the list of prime numbers less than 100.
"""
limit = 100
sieve = [True] * limit
sieve[0] = sieve[1] = False
for start in range(2, int(limit ** 0.5) + 1):
if sieve[start]:
for multiple in range(start * start, limit, start):
... | from solution import calculate_primes_up_to_100, is_fibonacci_number, get_fibonacci_set_up_to_100, primes_in_fibonacci
def test_calculate_primes_up_to_100():
expected_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
assert calculate_primes_up_to_100() ==... | [
{
"docstring": "Calculate the list of prime numbers less than 100.",
"function_declaration": "def calculate_primes_up_to_100():",
"function_name": "calculate_primes_up_to_100",
"parameter_list": "()"
},
{
"docstring": "Check if a number `n` is a Fibonacci number using a set of precalculated\... | [
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 Returns True if n is a prime number; False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n =... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035157",
"row_id": 35157,
"seed_ids": "['Qwen2-72B-Instruct_79117']"
} | 0.695468 | Filter_35157 | I | [
"calculate_primes_up_to_100",
"is_fibonacci_number",
"get_fibonacci_set_up_to_100",
"primes_in_fibonacci"
] | 4 | [
[
"primes_in_fibonacci",
"calculate_primes_up_to_100"
],
[
"primes_in_fibonacci",
"get_fibonacci_set_up_to_100"
],
[
"primes_in_fibonacci",
"is_fibonacci_number"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fe3ad0f9dccb14224ba92309375c98360eaf6a2b | 36792522817d14b46d33c277852861d1be51d29b | |||
v1.0 | instruct | Filter | Filter_35161_I | Design a Python function that identifies and returns all narcissistic numbers that are less than or equivalent to a given integer input. Additionally, the function should be able to handle negative numbers and non-integer inputs by converting them to positive integers and then performing the operation. | def is_narcissistic(number):
"""
Check if a number is a narcissistic number.
"""
digits = list(map(int, str(number)))
power = len(digits)
return number == sum(digit ** power for digit in digits)
def find_narcissistic_numbers(upto):
"""
Returns a list of all narcissistic numbers up to an... | from solution import is_narcissistic, find_narcissistic_numbers
def test_is_narcissistic():
assert is_narcissistic(153) == True
assert is_narcissistic(9474) == True
assert is_narcissistic(10) == False
assert is_narcissistic(407) == True
def test_find_narcissistic_numbers_positive_integers():
asser... | [
{
"docstring": "Check if a number is a narcissistic number.",
"function_declaration": "def is_narcissistic(number):",
"function_name": "is_narcissistic",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of all narcissistic numbers up to and including 'upto'.\nIf the input is no... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_narcissistic(num):\n \"\"\"\n Returns True if num is a narcissistic number, False otherwise.\n \"\"\"\n num_str = str(num)\n num_len = len(num_str)\n total = sum(int(d... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035161",
"row_id": 35161,
"seed_ids": "['Qwen2-72B-Instruct_79130']"
} | 0.551248 | Filter_35161 | I | [
"is_narcissistic",
"find_narcissistic_numbers"
] | 2 | [
[
"find_narcissistic_numbers",
"is_narcissistic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5558761a07d8c334a01797549ae637e0a6fd829 | db54d6c587d362f13d80a2575215c6437671ca67 | |||
v1.0 | instruct | Filter | Filter_35194_I | Write a Python program that prompts the user to input a list of integers, then sorts the list using the bubble sort algorithm and prints the sorted list. The program should handle cases where the user enters a non-integer value or an empty list. | def bubble_sort(arr):
"""
Sorts the input list using the bubble sort algorithm.
"""
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
def sort_integers():
"""
Promp... | from solution import bubble_sort, sort_integers
def test_bubble_sort_simple():
assert bubble_sort([4, 2, 7, 1, 3]) == [1, 2, 3, 4, 7]
def test_bubble_sort_empty():
assert bubble_sort([]) == []
def test_bubble_sort_single_element():
assert bubble_sort([5]) == [5]
def test_bubble_sort_already_sorted():
... | [
{
"docstring": "Sorts the input list using the bubble sort algorithm.",
"function_declaration": "def bubble_sort(arr):",
"function_name": "bubble_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Prompts the user to input a list of integers, sorts the list using bubble sort, and prints the... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def bubble_sort(arr):\n \"\"\"\n Sorts the input list using the bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in range(0, n - i - 1):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035194",
"row_id": 35194,
"seed_ids": "['Qwen2-72B-Instruct_79186']"
} | 0.69252 | Filter_35194 | I | [
"bubble_sort",
"sort_integers"
] | 2 | [
[
"sort_integers",
"bubble_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eac2f4624299cb540d5646586013a9e65dfa1852 | 7df9b5b7841462b9a405b0d3ec1970f9f060ebdf | |||
v1.0 | instruct | Filter | Filter_35215_I | Can you create a Python script that precisely formats a given directory path to display its size in a human-readable format, specifically in kilobytes (K), megabytes (M), or gigabytes (G) based on the directory's total size? The path to the directory for which the size needs to be determined will be "/volume1/abc". | import os
def get_directory_size(path):
"""
Calculate the total size of files in a directory.
:param path: The directory path
:return: Total size in bytes
"""
total_size = 0
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
filepath = os.path... | import os
from solution import format_directory_size, get_directory_size, human_readable_size
def test_get_directory_size(tmpdir):
# Create files in the temp directory for testing
file1 = tmpdir.join("file1.txt")
file1.write("a" * 1024) # 1KB
file2 = tmpdir.join("file2.txt")
file2.write("a" * 204... | [
{
"docstring": "Calculate the total size of files in a directory.\n\n:param path: The directory path\n:return: Total size in bytes",
"function_declaration": "def get_directory_size(path):",
"function_name": "get_directory_size",
"parameter_list": "(path)"
},
{
"docstring": "Convert the size ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef get_directory_size(path):\n \"\"\"\n Returns the total size of the directory at the given path.\n \"\"\"\n total_size = 0\n for dirpath, dirnames, filenames in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035215",
"row_id": 35215,
"seed_ids": "['Qwen2-72B-Instruct_79221']"
} | 0.599229 | Filter_35215 | I | [
"get_directory_size",
"human_readable_size",
"format_directory_size"
] | 3 | [
[
"format_directory_size",
"get_directory_size"
],
[
"format_directory_size",
"human_readable_size"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bc0a3b82b8463255fefe6ac29bba248f385d39c3 | 8a066633cf0b97a5f0f341eb2cb95eb77f4e3076 | |||
v1.0 | instruct | Filter | Filter_35228_I | Can you explain what the O(1) space complexity of a function means in Python? Suppose a function can only use a fixed amount of space or memory, and whether the input size increases or decreases does not affect it. This condition is where an algorithm's space complexity is said to be constant, or O(1). To illustrate, c... | def flip_bits(num):
"""
Returns the bitwise NOT (~) of the given number.
This operation is performed in O(1) space complexity because it does not
use any extra space that scales with the size of the input.
"""
return ~num
def flip_bits_in_list(input_list):
"""
Takes a list of integers, ... | from solution import flip_bits, flip_bits_in_list
def test_flip_bits():
assert flip_bits(0) == -1
assert flip_bits(1) == -2
assert flip_bits(-1) == 0
assert flip_bits(10) == -11
assert flip_bits(-10) == 9
def test_flip_bits_in_list():
input_list = [0, 1, 2, 3, 4, 5]
expected_output = [-1, ... | [
{
"docstring": "Returns the bitwise NOT (~) of the given number.\nThis operation is performed in O(1) space complexity because it does not\nuse any extra space that scales with the size of the input.",
"function_declaration": "def flip_bits(num):",
"function_name": "flip_bits",
"parameter_list": "(n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def flip_bits(numbers):\n \"\"\"\n Flips the bits of each binary number in the list 'numbers'.\n The space complexity of this function is O(1) since it\n modifies the list in place... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035228",
"row_id": 35228,
"seed_ids": "['Qwen2-72B-Instruct_79246']"
} | 0.432946 | Filter_35228 | I | [
"flip_bits",
"flip_bits_in_list"
] | 2 | [
[
"flip_bits_in_list",
"flip_bits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 948aa147947c996aeff57e96484ad595240a9963 | 76592ce99bc248bf8362c40e3a8ab964e4d38210 | |||
v1.0 | instruct | Filter | Filter_35245_I | Write a function that takes as input two binary trees and returns true if the second tree is a subtree of the first one. A subtree of a tree T is a tree S consisting of a node in T and all of this node's descendants. The tree T could also be considered as a subtree of itself. | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def is_subtree(s, t):
"""
Returns True if the tree t is a subtree of s, otherwise False.
"""
if not t:
return True
if not s:
return False
if is_same_tree(s, t):
... | from solution import TreeNode, is_subtree
def test_t_is_subtree_of_s():
s = TreeNode(3)
s.left = TreeNode(4)
s.right = TreeNode(5)
s.left.left = TreeNode(1)
s.left.right = TreeNode(2)
t = TreeNode(4)
t.left = TreeNode(1)
t.right = TreeNode(2)
assert is_subtree(s, t) == True
def t... | [] | [
1,
0,
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 isSubtree(root, subRoot):\n if no... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035245",
"row_id": 35245,
"seed_ids": "['Qwen2-72B-Instruct_79270']"
} | 0.612462 | Filter_35245 | I | [
"is_subtree",
"is_same_tree"
] | 2 | [
[
"is_subtree",
"is_same_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b63e0d5ba3e3084f6ab87c26b6e3a99b80c2814e | 3b9a5d33826edb0b1b2730e1ac9825fbed930591 | |||
v1.0 | instruct | Filter | Filter_35249_I | Formulate a programming script that accurately determines and visually presents the series of numbers which exclusively consist of odd digits (i.e., 1, 3, 5, 7, 9), operating in an ascending sequential order starting from 1 up until a pre-specified stopping point 'n'. Also, the application should efficiently handle lar... | def is_all_odd_digits(num):
"""
Check if all digits of the number are odd.
"""
odd_digits = {'1', '3', '5', '7', '9'}
return all(digit in odd_digits for digit in str(num))
def get_odd_digit_numbers(n):
"""
Generate a list of numbers from 1 to n that consist exclusively of odd digits.
""... | from solution import get_odd_digit_numbers, is_all_odd_digits
def test_is_all_odd_digits():
assert is_all_odd_digits(13579) == True
assert is_all_odd_digits(2468) == False
assert is_all_odd_digits(111) == True
assert is_all_odd_digits(0) == False
assert is_all_odd_digits(9) == True
def test_get_od... | [
{
"docstring": "Check if all digits of the number are odd.",
"function_declaration": "def is_all_odd_digits(num):",
"function_name": "is_all_odd_digits",
"parameter_list": "(num)"
},
{
"docstring": "Generate a list of numbers from 1 to n that consist exclusively of odd digits.",
"functio... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_odd_digit_numbers(n):\n \"\"\"\n Generate numbers consisting only of odd digits from 1 up to 'n'.\n \"\"\"\n def is_odd_digit_number(num):\n return all(digit in... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035249",
"row_id": 35249,
"seed_ids": "['Qwen2-72B-Instruct_79274']"
} | 0.562052 | Filter_35249 | I | [
"is_all_odd_digits",
"get_odd_digit_numbers"
] | 2 | [
[
"get_odd_digit_numbers",
"is_all_odd_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76ade6194544152c231e866e8a52851a5565b9a7 | 8679c7a464a1c5949146ba33bd20a5a60b083ee1 | |||
v1.0 | instruct | Filter | Filter_35257_I | Develop a Python implementation to process a list of integers and not only rearrange them in the descending order but also find the prime numbers from the list. Filtered prime numbers should then be rearranged in ascending order. | def is_prime(n):
"""
Determines 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 process_integers(numbers):
... | from solution import process_integers, 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(10) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(0) == Fa... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of integers to:\n1. Rearrange them in descending order.\n2. Extract prime numbers and rearrange them in asce... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return Fa... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035257",
"row_id": 35257,
"seed_ids": "['Qwen2-72B-Instruct_79287']"
} | 0.617507 | Filter_35257 | I | [
"is_prime",
"process_integers"
] | 2 | [
[
"process_integers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 797f76e95906494a2bc844c0616d313350b8182b | 329eff51dd0cb44bd24b453753d36378f3e03ef6 | |||
v1.0 | instruct | Filter | Filter_35278_I | Orchestrate a URL短链接服务 through 'flask' framework, 个人化 the short URL domain for user's discretionary choice. This mini project should include the features of error handling, integration of a database to keep record of the URL mappings, and optimization of the URL shortening algorithm. | from flask import Flask, request, redirect, jsonify
import sqlite3
import hashlib
app = Flask(__name__)
DATABASE = 'url_shortener.db'
BASE_URL = 'http://short.url/'
def init_db():
with sqlite3.connect(DATABASE) as conn:
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS url_map... | import pytest
import requests
from flask import Flask
from solution import app, init_db, shorten_url
@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
with app.app_context():
init_db()
yield client
def test_shorten_url(client):
respon... | [
{
"docstring": null,
"function_declaration": "def init_db():",
"function_name": "init_db",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def shorten_url(url):",
"function_name": "shorten_url",
"parameter_list": "(url)"
},
{
"docstring": null,
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify, redirect, abort\nfrom flask_sqlalchemy import SQLAlchemy\nimport string\nimport random\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035278",
"row_id": 35278,
"seed_ids": "['Qwen2-72B-Instruct_79315']"
} | 0.468735 | Filter_35278 | I | [
"init_db",
"shorten_url",
"shorten",
"redirect_short_url"
] | 4 | [
[
"shorten",
"shorten_url"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask",
"requests"
] | false | 0283ab5e6b887801ce3aa16b9780bec50f643746 | b6152fa93ee7e6db37e7345656757108e4c9505c | |||
v1.0 | instruct | Filter | Filter_35289_I | Create a for loop that prints the numbers 0 to 100 and prints if the number is a prime number or not. Additionally, the program should calculate and display the sum of all prime numbers encountered during the loop. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def print_numbers_and_check_primes():
"""
Prints the numbers from 0 to 100 and... | from solution import is_prime, print_numbers_and_check_primes
def test_is_prime():
assert is_prime(-1) == False
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is... | [
{
"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": "Prints the numbers from 0 to 100 and checks if they're prime.\nCalculates and returns the sum of all pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035289",
"row_id": 35289,
"seed_ids": "['Qwen2-72B-Instruct_79334']"
} | 0.616644 | Filter_35289 | I | [
"is_prime",
"print_numbers_and_check_primes"
] | 2 | [
[
"print_numbers_and_check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 629b9f63e2ca2e3b0e4e96c7691baa19de5b47f3 | 739f56f41e6ba91ebedb5ce5252a4182b8fe1f40 | |||
v1.0 | instruct | Filter | Filter_35294_I | Create a function that checks whether a given number is a prime number using the Sieve of Eratosthenes algorithm. The function should also return the smallest prime factor of the number if it is not a prime number. The function should efficiently handle numbers up to 10^9 and should be optimized for performance. | def sieve_of_eratosthenes(n):
"""
Generates a list of boolean values representing primality of numbers from 0 to n.
True indicates the number is prime, False indicates not prime.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in ... | from solution import is_prime_or_smallest_prime_factor
def test_small_prime_number():
assert is_prime_or_smallest_prime_factor(7) == (True, None)
def test_large_prime_number():
assert is_prime_or_smallest_prime_factor(9999991) == (True, None)
def test_not_prime_number():
assert is_prime_or_smallest_prime... | [
{
"docstring": "Generates a list of boolean values representing primality of numbers from 0 to n.\nTrue indicates the number is prime, False indicates not prime.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of boolean values where True indicates that the index is a prime number.\n It also returns a list where the index value is the ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035294",
"row_id": 35294,
"seed_ids": "['Qwen2-72B-Instruct_79341']"
} | 0.667711 | Filter_35294 | I | [
"sieve_of_eratosthenes",
"smallest_prime_factor",
"is_prime_or_smallest_prime_factor"
] | 3 | [
[
"is_prime_or_smallest_prime_factor",
"sieve_of_eratosthenes"
],
[
"is_prime_or_smallest_prime_factor",
"smallest_prime_factor"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6a255948554c50eb23b10d67cd1e38d26b9556af | 36cdf105b9a3361af6e07c6bff859523880aefd7 | |||
v1.0 | instruct | Filter | Filter_35316_I | Modify a program that accepts a sentence and a number as input. Instead of simply repeating each word in the sentence, the program should now scramble the letters of each word, maintaining only the correct first and last letter in each word, and repeat this "scrambled" sentence a specified number of times. The scramble... | import random
def scramble_word(word):
"""
Scramble the word by shuffling the characters between the first and last character.
"""
if len(word) <= 3:
return word
# Get the middle characters
middle_chars = list(word[1:-1])
random.shuffle(middle_chars)
# Combine the first characte... | from solution import scramble_word, scramble_sentence
def test_scramble_word():
# Test that short words are not scrambled
assert scramble_word("a") == "a"
assert scramble_word("it") == "it"
assert scramble_word("the") == "the"
# Test that three-letter words are not scrambled
assert scramble_wo... | [
{
"docstring": "Scramble the word by shuffling the characters between the first and last character.",
"function_declaration": "def scramble_word(word):",
"function_name": "scramble_word",
"parameter_list": "(word)"
},
{
"docstring": "Scrambles each word within a sentence, maintaining the fir... | [
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 scramble_word(word):\n \"\"\"\n Scramble the inner characters of a word, leaving the first and last characters in place.\n \"\"\"\n if len(word) > 2:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035316",
"row_id": 35316,
"seed_ids": "['Qwen2-72B-Instruct_79374']"
} | 0.73478 | Filter_35316 | I | [
"scramble_word",
"scramble_sentence"
] | 2 | [
[
"scramble_sentence",
"scramble_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a3a4505f3738c985ca2923add85baf5819b2666f | 9052ae393590537be8dbde54481dc479d350a4c6 | |||
v1.0 | instruct | Filter | Filter_35334_I | Create a loop that will print numbers from 3 to 100, but only those which are both prime and Fibonacci numbers. Additionally, the loop should determine if each prime Fibonacci number is a palindrome and print out the palindromic numbers in reverse order. | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def is_fibonacci(num):
x1 = 5 * num * num + 4
x2 = 5 * num * num - 4
return int(x1**0.5)**2 == x1 or int(x2**0.5)**2 == x2
def is_palindrome(... | from solution import is_prime, is_fibonacci, is_palindrome
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-1)
def test_is_fibonacci():
assert is_fibonacci(0)
asse... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_fibonacci(num):",
"function_name": "is_fibonacci",
"parameter_list": "(num)"
},
{
"docstring":... | [
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 if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef is_fibonacci(n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035334",
"row_id": 35334,
"seed_ids": "['Qwen2-72B-Instruct_79411']"
} | 0.604989 | Filter_35334 | I | [
"is_prime",
"is_fibonacci",
"is_palindrome",
"print_prime_fibonacci_palindromes"
] | 4 | [
[
"print_prime_fibonacci_palindromes",
"is_fibonacci"
],
[
"print_prime_fibonacci_palindromes",
"is_palindrome"
],
[
"print_prime_fibonacci_palindromes",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b2fce512b1ecd9a11c0918a667d8615d0bdd5fea | 702a9f10e6a5219fc26c0acd6c74577468ed4c9b | |||
v1.0 | instruct | Filter | Filter_35352_I | Utilizing the programming language Python, construct a script that executes the task of printing the numerical integers ranging from the minimum value of 0 to a maximum boundary of 100. However, instead of printing in a straightforward manner, the program should display each integer only if it is a perfect square or a ... | import math
def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def is_perfect_sq... | import pytest
from solution import is_prime, is_perfect_square, print_special_numbers
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_is_perfect_square():
assert is_perfect_... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect... | [
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 Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035352",
"row_id": 35352,
"seed_ids": "['Qwen2-72B-Instruct_79445']"
} | 0.594959 | Filter_35352 | I | [
"is_prime",
"is_perfect_square",
"print_special_numbers"
] | 3 | [
[
"print_special_numbers",
"is_perfect_square"
],
[
"print_special_numbers",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 143f40a37f02b04341f4759ceaf628f2ac8e8381 | 697db7d521ba13670f806325678f1efd681414c7 | |||
v1.0 | instruct | Filter | Filter_35356_I | Given a series of numbers from 1 to 100, use a for loop and an if statement to print only the prime numbers and the sum of all prime numbers. Additionally, you are required to implement this functionality as a function called "print_prime_numbers_and_sum" that takes no arguments and returns the sum of all prime numbers... | def print_prime_numbers_and_sum():
"""
Prints prime numbers from 1 to 100 and returns the sum of all prime numbers in this range.
"""
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
r... | from solution import print_prime_numbers_and_sum, check_sum_of_primes
def test_print_prime_numbers_and_sum():
# Capture the printed output (if necessary)
import io
import sys
# Assigning the original stdout to a variable to restore later
original_stdout = sys.stdout
captured_output = io.String... | [
{
"docstring": "Prints prime numbers from 1 to 100 and returns the sum of all prime numbers in this range.",
"function_declaration": "def print_prime_numbers_and_sum():",
"function_name": "print_prime_numbers_and_sum",
"parameter_list": "()"
},
{
"docstring": null,
"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 if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <= n:\n if n % p == 0:\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035356",
"row_id": 35356,
"seed_ids": "['Qwen2-72B-Instruct_79458']"
} | 0.602186 | Filter_35356 | I | [
"print_prime_numbers_and_sum",
"check_sum_of_primes"
] | 2 | [
[
"check_sum_of_primes",
"print_prime_numbers_and_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dee71601eaa2877a3f8057f8c34b842be7751f6 | 219dde03e5b147a65a93d9e71b909f6a4cc1e815 | |||
v1.0 | instruct | Filter | Filter_35362_I | Find and compare the algorithms used for sorting a given list of numbers in descending order using only bitwise operations. Provide a detailed explanation of each algorithm's approach, time complexity, and space complexity. Additionally, include practical implementations and code snippets for each algorithm to further ... | def bitwise_swap(a, b):
if a != b:
a = a ^ b
b = a ^ b
a = a ^ b
return a, b
def bitwise_bubble_sort(arr):
"""
Sorts an array in descending order using Bitwise Bubble Sort.
"""
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j... | from solution import bitwise_bubble_sort, bitwise_odd_even_sort
def test_bitwise_bubble_sort():
assert bitwise_bubble_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [9, 6, 5, 5, 5, 4, 3, 3, 2, 1, 1]
assert bitwise_bubble_sort([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]
assert bitwise_bubble_sort([5, 4, 3, 2, 1]) == [5... | [
{
"docstring": null,
"function_declaration": "def bitwise_swap(a, b):",
"function_name": "bitwise_swap",
"parameter_list": "(a, b)"
},
{
"docstring": "Sorts an array in descending order using Bitwise Bubble Sort.",
"function_declaration": "def bitwise_bubble_sort(arr):",
"function_na... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def counting_sort_by_bit(arr, bit):\n n = len(arr)\n output = [0] * n\n count = [0] * 2 # Since each bit can only be 0 or 1\n\n # Store count of occurrences of 0s and 1s in bit 'b... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035362",
"row_id": 35362,
"seed_ids": "['Qwen2-72B-Instruct_79470']"
} | 0.597516 | Filter_35362 | I | [
"bitwise_swap",
"bitwise_bubble_sort",
"bitwise_odd_even_sort"
] | 3 | [
[
"bitwise_bubble_sort",
"bitwise_swap"
],
[
"bitwise_odd_even_sort",
"bitwise_swap"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6a6777fe48b02b8828a85ff8eb8b08910db826ca | a97fdb332e2d47da82ee9a19ed8e9bcc268869f8 | |||
v1.0 | instruct | Filter | Filter_35386_I | As a programmer writing Python code, you are tasked with creating a basic blockchain. Please provide a step-by-step guide on how to achieve this. Your explanation should be concise and easy to understand for beginners, and should include code examples for each step. | import hashlib
import time
class Block:
def __init__(self, index, previous_hash, timestamp, data, hash):
self.index = index
self.previous_hash = previous_hash
self.timestamp = timestamp
self.data = data
self.hash = hash
def calculate_hash(index, previous_hash, timestamp, da... | from solution import Block, calculate_hash, create_genesis_block, create_new_block, create_blockchain
def test_calculate_hash():
assert calculate_hash(0, "0", 1625199075, "Genesis Block") != ""
assert calculate_hash(1, "hash", 1625199075, "Block Data") != ""
def test_create_genesis_block():
genesis_block ... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, previous_hash, timestamp, data, hash):\n self.index = index\n self.previous_hash = previous_hash\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035386",
"row_id": 35386,
"seed_ids": "['Qwen2-72B-Instruct_79507']"
} | 0.383713 | Filter_35386 | I | [
"calculate_hash",
"create_genesis_block",
"create_new_block",
"create_blockchain"
] | 4 | [
[
"create_blockchain",
"create_genesis_block"
],
[
"create_blockchain",
"create_new_block"
],
[
"create_genesis_block",
"calculate_hash"
],
[
"create_new_block",
"calculate_hash"
]
] | 4 | [] | false | [
"Block"
] | true | pytest | true | [] | true | 0cc8234a413c8815f55d3ef1577629465bd7ccf1 | 07bd0c4ae10d0095581633bde0d874651bc81487 | |||
v1.0 | instruct | Filter | Filter_35389_I | Given multiple YAML formatted strings, write a program that converts these strings into JSON objects, merges them on a defined key, and finally sorts their keys in a hierarchical order based on a given set of rules. | import yaml
import json
def parse_and_convert(yaml_strings):
"""
Parses multiple YAML formatted strings and converts them into JSON objects.
"""
json_objects = [yaml.safe_load(yaml_str) for yaml_str in yaml_strings]
return json_objects
def merge_json_objects(json_objects, merge_key):
"""
M... | from solution import process_yaml_strings
def test_parse_and_convert():
yaml_strings = [
"id: 1\nname: Test1",
"id: 2\nname: Test2"
]
expected = [{'id': 1, 'name': 'Test1'}, {'id': 2, 'name': 'Test2'}]
assert parse_and_convert(yaml_strings) == expected
def test_merge_json_objects():
... | [
{
"docstring": "Parses multiple YAML formatted strings and converts them into JSON objects.",
"function_declaration": "def parse_and_convert(yaml_strings):",
"function_name": "parse_and_convert",
"parameter_list": "(yaml_strings)"
},
{
"docstring": "Merges JSON objects based on a defined key... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import yaml\nimport json\n\ndef parse_and_convert(yaml_strings):\n \"\"\"\n Parses multiple YAML formatted strings and converts them into JSON objects.\n \"\"\"\n json_objects = [y... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035389",
"row_id": 35389,
"seed_ids": "['Qwen2-72B-Instruct_79511']"
} | 0.463574 | Filter_35389 | I | [
"parse_and_convert",
"merge_json_objects",
"sort_keys_hierarchical",
"process_yaml_strings"
] | 4 | [
[
"process_yaml_strings",
"merge_json_objects"
],
[
"process_yaml_strings",
"parse_and_convert"
],
[
"process_yaml_strings",
"sort_keys_hierarchical"
]
] | 3 | [] | false | [] | false | pytest | true | [
"yaml"
] | false | efcc5bc9adc95caab1e5ddf2a201a292e7aae592 | 157f88459d8938f2a873feb33b1609433da9cf6b | |||
v1.0 | instruct | Filter | Filter_35397_I | I want to simulate a poker game which uses 5 community cards and 2 cards for each player (as in Texas Holdem). Given that we know all the cards used in the hand (i.e. 7 cards for each player), how can I best create a function in Python that evaluates the best 5-card combination of each possible player's hands and then ... | from itertools import combinations
# Rank of the cards and suits
RANKS = "23456789TJQKA"
SUITS = "CDHS"
# Map between numerical values and ranks
VALUES = {rank: i for i, rank in enumerate(RANKS, start=2)}
def evaluate_hand(cards):
"""
Evaluate the best 5-card poker hand from 7 cards. Return the (ranking, bes... | from solution import evaluate_hand, determine_best_hand
def test_high_card():
hand = ['2H', '5D', '7S', '9C', 'KD', 'JD', 'TC']
ranking, best_hand = evaluate_hand(hand)
assert ranking == (0, [13, 11, 10, 9, 7])
def test_pair():
hand = ['2H', '5D', '7S', '9C', '7C', 'JD', 'TC']
ranking, best_hand =... | [
{
"docstring": "Evaluate the best 5-card poker hand from 7 cards. Return the (ranking, best_hand).",
"function_declaration": "def evaluate_hand(cards):",
"function_name": "evaluate_hand",
"parameter_list": "(cards)"
},
{
"docstring": "Determines the ranking of a 5-card poker hand. Returns a ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\nCARD_RANKS = \"23456789TJQKA\"\nCARD_VALUES = {rank: i for i, rank in enumerate(CARD_RANKS)}\n\nHAND_RANKS = (\n \"High Card\", \"One Pair\", \"Two Pai... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035397",
"row_id": 35397,
"seed_ids": "['Qwen2-72B-Instruct_79530']"
} | 0.626025 | Filter_35397 | I | [
"evaluate_hand",
"hand_ranking",
"determine_best_hand"
] | 3 | [
[
"determine_best_hand",
"evaluate_hand"
],
[
"evaluate_hand",
"hand_ranking"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 644121d4fbecdbca54bed106c7aaf7da1c27048b | 751860b23722da9c2b8a45f3d02d775ce6a574cf | |||
v1.0 | instruct | Filter | Filter_35411_I | Write a Python function that implements the merge sort algorithm to sort an array of integers. Also, include a test harness at the bottom of your code to check the function's correctness with some test details. The test should verify the function by providing both positive and negative integers, as well as an already s... | def merge_sort(arr):
"""
Function to implement merge sort algorithm.
Parameter:
arr (list): list of integers to sort
Returns:
sorted list of integers
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(ar... | from solution import merge_sort
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_array():
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_mer... | [
{
"docstring": "Function to implement merge sort algorithm.\nParameter:\narr (list): list of integers to sort\nReturns:\nsorted list of integers",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Function to merge two... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Implements the merge sort algorithm to sort an array of integers.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035411",
"row_id": 35411,
"seed_ids": "['Qwen2-72B-Instruct_79559']"
} | 0.653082 | Filter_35411 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 752d21e53ff835a1c23cb083f77576dc106a7ff0 | 8b57c11ea64e2f6ea435fdf04fbf727c2bacb0fa | |||
v1.0 | instruct | Filter | Filter_35417_I | Write a code that computes the product of all prime numbers within a list. If there are no prime numbers in the list, the code should return 1. | 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_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return True
def pro... | from solution import product_of_primes
def test_no_primes():
assert product_of_primes([1, 4, 6, 8, 9]) == 1
def test_some_primes():
assert product_of_primes([2, 3, 4, 5, 6]) == 30
def test_all_primes():
assert product_of_primes([2, 3, 5, 7]) == 210
def test_empty_list():
assert product_of_primes([])... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the product of all prime numbers in the list.\nIf there are no prime numbers, return 1.",
"function_declarati... | [
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 number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035417",
"row_id": 35417,
"seed_ids": "['Qwen2-72B-Instruct_79568']"
} | 0.627934 | Filter_35417 | I | [
"is_prime",
"product_of_primes"
] | 2 | [
[
"product_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70c415ded623dd01a613c4edc459bc47d2ae2956 | ac7181f814fd42e8c5226498c90251cdf3bc3909 | |||
v1.0 | instruct | Filter | Filter_35428_I | Convert the following number from decimal to octal in python: 12345. Validate that your function works by converting the octal back to decimal and checking if it equals the input. Also, format your output in such a way that the octal number is prefixed with '0o'. Moreover, implement a function that measures the efficie... | def decimal_to_octal(n):
"""
Convert a decimal number to its octal representation prefixed with '0o'.
:param n: Decimal number to be converted.
:return: Octal representation of the number as a string prefixed with '0o'.
"""
return oct(n)
def octal_to_decimal(octal_str):
"""
Convert... | from solution import decimal_to_octal, octal_to_decimal, measure_efficiency
def test_decimal_to_octal():
assert decimal_to_octal(12345) == '0o30071'
def test_octal_to_decimal():
assert octal_to_decimal('0o30071') == 12345
def test_conversion():
decimal_number = 12345
octal_representation = decimal_to... | [
{
"docstring": "Convert a decimal number to its octal representation prefixed with '0o'.\n\n:param n: Decimal number to be converted.\n:return: Octal representation of the number as a string prefixed with '0o'.",
"function_declaration": "def decimal_to_octal(n):",
"function_name": "decimal_to_octal",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_octal(n):\n \"\"\"\n Converts a decimal number to an octal number as a string prefixed with '0o'.\n \"\"\"\n return oct(n)\n\ndef octal_to_decimal(o):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035428",
"row_id": 35428,
"seed_ids": "['Qwen2-72B-Instruct_79586']"
} | 0.831118 | Filter_35428 | I | [
"decimal_to_octal",
"octal_to_decimal",
"measure_efficiency"
] | 3 | [
[
"measure_efficiency",
"decimal_to_octal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b9371be5ad809f4f5ae08929592f1d63b6fa1d3 | 6806fbc61f2bc358dc70271d33d846cbddbb3f4b | |||
v1.0 | instruct | Filter | Filter_35429_I | Hello, I am trying to write a program that rebalances a binary tree. I assume the original binary tree is an unbalanced tree. I want to finish rebalancing it and produce a new balanced binary tree. Could you provide me some help on how to solve this problem? | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def inorder_traversal(node, nodes):
"""
Traverses the binary tree in-order and stores the nodes in a list.
"""
if not node:
return
inorder_travers... | def tree_to_list_inorder(root):
"""
Utility function to convert a binary tree to a list using in-order traversal.
This helps in verifying the structure of the tree.
"""
result = []
if root:
result = tree_to_list_inorder(root.left)
result.append(root.val)
result = result +... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"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 store_inorder(node, inorder_list):\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035429",
"row_id": 35429,
"seed_ids": "['Qwen2-72B-Instruct_79589']"
} | 0.649509 | Filter_35429 | I | [
"inorder_traversal",
"build_balanced_bst",
"balance_bst"
] | 3 | [
[
"balance_bst",
"build_balanced_bst"
],
[
"balance_bst",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | f12395199ce4d5292c42120529a3028553571a64 | 70d7ab37f4c6c58d273da2c3bdfd4c8bba858c13 | |||
v1.0 | instruct | Filter | Filter_35431_I | Create a function in Python that takes an integer as input and returns a list of all prime numbers up to that integer. The prime numbers should be in ascending order. The function should have a time complexity of O(n * sqrt(m)), where n is the input integer and m is the largest number being checked for primality. | def is_prime(n):
"""
Determines 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 += 6
... | from solution import is_prime, prime_numbers_up_to
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(29)
def test_prime_numbers_up_to():
assert prime_numbers_up_to(1) == []
... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers up to and including n.",
"function_declaration": "def prime_numbers_up_to(n):",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef primes_up_to(n):\n \"\"\"\n Returns a list of all prime numbers up to n (inclusive).\n \"\"\"\n if n < 2:\n return []\n\n primes = []\n is_prime = [... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035431",
"row_id": 35431,
"seed_ids": "['Qwen2-72B-Instruct_79597']"
} | 0.703546 | Filter_35431 | I | [
"is_prime",
"prime_numbers_up_to"
] | 2 | [
[
"prime_numbers_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 001f3275aff437fd78678a4f849386dfe697b05a | fe3141a09e25cecd14b94e36db5b9305cea533f1 | |||
v1.0 | instruct | Filter | Filter_35432_I | Given a function `solveMeFirst` that takes two integer arguments `a` and `b`, your task is to complete it by returning their sum. Then, you need to call this function inside the `getInput` function, which reads two integers from the standard input and passes them to `solveMeFirst` before printing the result. | def solveMeFirst(a, b):
"""
Returns the sum of a and b.
"""
return a + b
def getInput():
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
result = solveMeFirst(a, b)
print(result) | from solution import solveMeFirst
def test_solveMeFirst_positive_numbers():
assert solveMeFirst(2, 3) == 5
def test_solveMeFirst_with_zero():
assert solveMeFirst(0, 5) == 5
assert solveMeFirst(5, 0) == 5
def test_solveMeFirst_negative_numbers():
assert solveMeFirst(-1, -1) == -2
def test_solveMeFirs... | [
{
"docstring": "Returns the sum of a and b.",
"function_declaration": "def solveMeFirst(a, b):",
"function_name": "solveMeFirst",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def getInput():",
"function_name": "getInput",
"parameter_list": "()"
}
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def solveMeFirst(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef getInput():\n \"\"\"\n Reads two integers from standard input, passes them to so... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035432",
"row_id": 35432,
"seed_ids": "['Qwen2-72B-Instruct_79598']"
} | 0.541315 | Filter_35432 | I | [
"solveMeFirst",
"getInput"
] | 2 | [
[
"getInput",
"solveMeFirst"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 190165eb7af02414d776a2e42ca051f771eeb8db | a79cf127e437444a3e3a2421e47b22d6fc0d0b96 | |||
v1.0 | instruct | Filter | Filter_35458_I | Given the coordinates of two points, write a Python function to calculate the distance between them. Then, write a program to read the coordinates of N such points from the standard input and calculate the distance between each pair of points. Your program should output the pair of points that are closest to each other... | def distance_squared(x1, y1, x2, y2):
"""
Returns the squared distance between two points (x1, y1) and (x2, y2).
"""
return (x2 - x1) ** 2 + (y2 - y1) ** 2
def closest_pair(points):
"""
Given a list of points, returns the pair of points that are closest to each other and their distance.
Use... | from solution import distance_squared, closest_pair, read_points
def test_distance_squared():
assert distance_squared(0, 0, 3, 4) == 25 # 3-4-5 triangle
assert distance_squared(1, 1, 4, 5) == 25 # shift triangle by (1,1)
assert distance_squared(0, 0, 0, 0) == 0
assert distance_squared(-1, -1, 1, 1) =... | [
{
"docstring": "Returns the squared distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def distance_squared(x1, y1, x2, y2):",
"function_name": "distance_squared",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Given a list of points, returns the pair of p... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_distance_no_sqrt(point1, point2):\n \"\"\"\n Calculates the squared distance between two points to avoid floating point inaccuracies.\n \"\"\"\n return (point1[0] - p... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035458",
"row_id": 35458,
"seed_ids": "['Qwen2-72B-Instruct_79644']"
} | 0.61538 | Filter_35458 | I | [
"distance_squared",
"closest_pair",
"read_points"
] | 3 | [
[
"closest_pair",
"distance_squared"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d46bd68f94996a83d06c7a798b14e6ccd9eb839d | fe4121f3dfe5d102ecd3eb8c7d64a9b5bd84b8b2 | |||
v1.0 | instruct | Filter | Filter_35464_I | Create a Python function that generates all numbers between 1 and a provided number n, but with the order of their digits reversed. The function should also handle errors, such as the input not being a positive integer, and return an error message in such cases. | def reverse_number(num):
"""
Returns the number with its digits reversed.
"""
return int(str(num)[::-1])
def reversed_numbers_upto_n(n):
"""
Generates all numbers between 1 and n with their digits reversed.
Returns an error message if n is not a positive integer.
"""
if not isinstan... | from solution import reverse_number, reversed_numbers_upto_n
def test_reverse_number():
assert reverse_number(123) == 321
assert reverse_number(100) == 1
assert reverse_number(400) == 4
assert reverse_number(98765) == 56789
def test_reversed_numbers_upto_n_positive():
assert reversed_numbers_upto_... | [
{
"docstring": "Returns the number with its digits reversed.",
"function_declaration": "def reverse_number(num):",
"function_name": "reverse_number",
"parameter_list": "(num)"
},
{
"docstring": "Generates all numbers between 1 and n with their digits reversed.\nReturns an error message if n ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_and_generate(n):\n \"\"\"\n Generates all numbers between 1 and n with their digits reversed.\n \"\"\"\n if not isinstance(n, int) or n <= 0:\n return \"Error: I... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035464",
"row_id": 35464,
"seed_ids": "['Qwen2-72B-Instruct_79653']"
} | 0.688986 | Filter_35464 | I | [
"reverse_number",
"reversed_numbers_upto_n"
] | 2 | [
[
"reversed_numbers_upto_n",
"reverse_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9935da8dfc11916ee44c03eaa4370cd8bc70d03 | 81b9f156d4c5e9c110d29f006e2697834fb8d4f7 | |||
v1.0 | instruct | Filter | Filter_35465_I | Create a python program that can convert temperatures between celsius, fahrenheit, and kelvin, while also handling inputs in the form of a range of temperatures. The program should be able to convert the following conversions: celsius to fahrenheit, celsius to kelvin, fahrenheit to celsius, fahrenheit to kelvin, kelvin... | def celsius_to_fahrenheit(c):
return round((c * 9/5) + 32, 2)
def celsius_to_kelvin(c):
return round(c + 273.15, 2)
def fahrenheit_to_celsius(f):
return round((f - 32) * 5/9, 2)
def fahrenheit_to_kelvin(f):
return round((f + 459.67) * 5/9, 2)
def kelvin_to_celsius(k):
return round(k - 273.15, 2)... | import pytest
from solution import convert_temperatures
def test_celsius_to_fahrenheit_single_value():
assert convert_temperatures("0", "c", "f") == [32.00]
assert convert_temperatures("100", "c", "f") == [212.00]
def test_celsius_to_kelvin_single_value():
assert convert_temperatures("0", "c", "k") == [27... | [
{
"docstring": null,
"function_declaration": "def celsius_to_fahrenheit(c):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(c)"
},
{
"docstring": null,
"function_declaration": "def celsius_to_kelvin(c):",
"function_name": "celsius_to_kelvin",
"parameter_list": "(c... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef convert_temp(value, from_unit, to_unit):\n \"\"\"\n Convert temperature from one unit to another.\n \n Parameters:\n - value: float, the temperature value to co... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035465",
"row_id": 35465,
"seed_ids": "['Qwen2-72B-Instruct_79654']"
} | 0.454084 | Filter_35465 | I | [
"celsius_to_fahrenheit",
"celsius_to_kelvin",
"fahrenheit_to_celsius",
"fahrenheit_to_kelvin",
"kelvin_to_celsius",
"kelvin_to_fahrenheit",
"parse_input",
"convert_temperatures"
] | 8 | [
[
"convert_temperatures",
"celsius_to_fahrenheit"
],
[
"convert_temperatures",
"celsius_to_kelvin"
],
[
"convert_temperatures",
"fahrenheit_to_celsius"
],
[
"convert_temperatures",
"fahrenheit_to_kelvin"
],
[
"convert_temperatures",
"kelvin_to_celsius"
],
... | 7 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | b1797993fb57be826e08fc6821ece60111f64acb | 75bd7dc01e90016a66a1d61924d434a210ed4cc2 | |||
v1.0 | instruct | Filter | Filter_35505_I | How do I create a process monitoring tool for a software application using Python? | import psutil
def get_process_info(pid):
"""
Retrieve information about a specified process.
Parameters:
pid (int): The process ID.
Returns:
dict: A dictionary containing process information.
"""
try:
p = psutil.Process(pid)
return {
'pid': pid,
... | from solution import get_process_info, monitor_processes
import psutil
def test_get_process_info_existing_process():
# Using psutil to find the current process PID for testing
current_pid = psutil.Process().pid
info = get_process_info(current_pid)
assert info['pid'] == current_pid
assert 'name... | [
{
"docstring": "Retrieve information about a specified process.\n\nParameters:\npid (int): The process ID.\n\nReturns:\ndict: A dictionary containing process information.",
"function_declaration": "def get_process_info(pid):",
"function_name": "get_process_info",
"parameter_list": "(pid)"
},
{
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import psutil\n\ndef is_process_running(process_name):\n \"\"\"\n Check if there is any running process that contains the given name process_name.\n Returns True if the process is fou... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035505",
"row_id": 35505,
"seed_ids": "['Qwen2-72B-Instruct_79727']"
} | 0.555364 | Filter_35505 | I | [
"get_process_info",
"monitor_processes"
] | 2 | [
[
"monitor_processes",
"get_process_info"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | 41f3e6884be9ab90b651943da5b2f979e71e31bf | a4d3b31fa1dd81cf1e53e7d6ac26000c6a331d80 | |||
v1.0 | instruct | Filter | Filter_35524_I | Develop a Python function capable of differentiating between prime numbers and composite numbers from a provided list of integers. The function should be designed to handle large numbers as well. Additionally, rectify any errors in the provided erroneous code snippet to complete the task. | def is_prime(n):
"""Return True if n is a prime number, otherwise False."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import is_prime, differentiate_primes_and_composites
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
asse... | [
{
"docstring": "Return True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Differentiates prime numbers from composite numbers in a list.\n\nParameters:\nnumbers (list): List of in... | [
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 \"\"\"Return True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035524",
"row_id": 35524,
"seed_ids": "['Qwen2-72B-Instruct_79761']"
} | 0.670913 | Filter_35524 | I | [
"is_prime",
"differentiate_primes_and_composites"
] | 2 | [
[
"differentiate_primes_and_composites",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8498c136d15fc409eb2a680d129269316172de91 | 9272ea7a27e12c17bf1a61dec548886174161146 | |||
v1.0 | instruct | Filter | Filter_35526_I | Generate a snippet of Python script capable of recursively scanning a base directory, including all subdirectories, for the presence of a specified .txt file. Additionally, the script should list all unique words present in the file, highlight the frequency of each word, should ignore case sensitivity and punctuation m... | import os
import re
from collections import Counter
def scan_dir_for_txt_files(base_dir):
"""
Recursively scans the base directory for .txt files and returns a list of their paths.
"""
txt_files = []
for dirpath, _, filenames in os.walk(base_dir):
for filename in filenames:
if f... | import tempfile
import os
from collections import Counter
from solution import scan_dir_for_txt_files, extract_words_from_file, scan_and_count_words
def test_scan_dir_for_txt_files():
with tempfile.TemporaryDirectory() as tmpdir:
os.makedirs(os.path.join(tmpdir, 'subdir'))
open(os.path.join(tmpdir,... | [
{
"docstring": "Recursively scans the base directory for .txt files and returns a list of their paths.",
"function_declaration": "def scan_dir_for_txt_files(base_dir):",
"function_name": "scan_dir_for_txt_files",
"parameter_list": "(base_dir)"
},
{
"docstring": "Reads a file, extracts all un... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport string\nfrom collections import defaultdict\n\ndef scan_directory_for_text_files(base_directory):\n \"\"\"\n Recursively scans the base directory and its subdirectories... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035526",
"row_id": 35526,
"seed_ids": "['Qwen2-72B-Instruct_79763']"
} | 0.697596 | Filter_35526 | I | [
"scan_dir_for_txt_files",
"extract_words_from_file",
"scan_and_count_words"
] | 3 | [
[
"scan_and_count_words",
"extract_words_from_file"
],
[
"scan_and_count_words",
"scan_dir_for_txt_files"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7884a2f0838615954566de1e3c39ad67d1858a3f | aa80f70ceadd71fcbef141f2c07025e52fbe7352 | |||
v1.0 | instruct | Filter | Filter_35544_I | You are given a string of characters. The task is to find the number and type of all possible palindromic partitions in the string. A palindromic partition is a segmentation of a string into substrings where every substring is a palindrome. For example, "ababa" has the following possible palindromic partitions: {"a", "... | def is_palindrome(s):
"""Check if the string s is a palindrome."""
return s == s[::-1]
def palindromic_partitions(s):
"""Find all palindromic partitions of a given string."""
result = []
def backtrack(start, path):
if start == len(s):
result.append(path[:])
retu... | from solution import is_palindrome, palindromic_partitions
def test_is_palindrome():
assert is_palindrome("a") == True
assert is_palindrome("aa") == True
assert is_palindrome("ab") == False
assert is_palindrome("aba") == True
assert is_palindrome("abcba") == True
assert is_palindrome("abccba") ... | [
{
"docstring": "Check if the string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Find all palindromic partitions of a given string.",
"function_declaration": "def palindromic_partitions(... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a substring is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palindromic_partitions(s):\n \"\"\"\n Function... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035544",
"row_id": 35544,
"seed_ids": "['Qwen2-72B-Instruct_79795']"
} | 0.740086 | Filter_35544 | I | [
"is_palindrome",
"palindromic_partitions"
] | 2 | [
[
"palindromic_partitions",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be8cf8e5cfc19010d039258636ba770c27b48686 | 9949fe2d934c40ec0328a36197b125a80cc0d42d | |||
v1.0 | instruct | Filter | Filter_35569_I | Merge two sorted lists into one using two different approaches: one employing a priority queue and the other using a two-pointer technique. Also, for each approach, your code should have error detection capabilities to check if the input is indeed a list and if all elements in the list are integers. | from heapq import merge
from collections.abc import Iterable
def check_valid_list(lst):
if not isinstance(lst, list):
raise ValueError("Input should be a list.")
if not all(isinstance(x, int) for x in lst):
raise ValueError("All elements in the list should be integers.")
def merge_sorted_lists... | from solution import merge_sorted_lists_priority_queue, merge_sorted_lists_two_pointer
def test_merge_sorted_lists_priority_queue():
assert merge_sorted_lists_priority_queue([1, 3, 5], [2, 4, 6]) == [1, 2, 3, 4, 5, 6]
assert merge_sorted_lists_priority_queue([], [2, 4, 6]) == [2, 4, 6]
assert merge_sorted_... | [
{
"docstring": null,
"function_declaration": "def check_valid_list(lst):",
"function_name": "check_valid_list",
"parameter_list": "(lst)"
},
{
"docstring": "Merge two sorted lists into one using priority queue approach.",
"function_declaration": "def merge_sorted_lists_priority_queue(lst... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef is_valid_list(l):\n if not isinstance(l, list):\n return False\n return all(isinstance(i, int) for i in l)\n\ndef merge_sorted_lists_priority_queue(list1, list... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035569",
"row_id": 35569,
"seed_ids": "['Qwen2-72B-Instruct_79838']"
} | 0.577453 | Filter_35569 | I | [
"check_valid_list",
"merge_sorted_lists_priority_queue",
"merge_sorted_lists_two_pointer"
] | 3 | [
[
"merge_sorted_lists_priority_queue",
"check_valid_list"
],
[
"merge_sorted_lists_two_pointer",
"check_valid_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e71a5670c9aaf89a970eab84b5ee402853fa2231 | 9afd74a49d7f7e52b154a2262c2c2c9ea6959323 | |||
v1.0 | instruct | Filter | Filter_35581_I | Create a tree with nodes A, B, C, D, E, F, G, H, and I. Traverse the tree using pre-order traversal and print the nodes in reverse order. | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def pre_order_traversal(root):
if root is None:
return []
return [root.value] + pre_order_traversal(root.left) + pre_order_traversal(root.right)
def create_tree():
# Creatin... | from solution import create_tree, pre_order_traversal, pre_order_traversal_reverse
def test_pre_order_traversal():
tree = create_tree()
assert pre_order_traversal(tree) == ['A', 'B', 'D', 'E', 'H', 'I', 'C', 'F', 'G']
def test_pre_order_traversal_reverse():
tree = create_tree()
assert pre_order_traver... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n \"\"\"\n Definition for a binary tree node.\n \"\"\"\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef pr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035581",
"row_id": 35581,
"seed_ids": "['Qwen2-72B-Instruct_79861']"
} | 0.525715 | Filter_35581 | I | [
"pre_order_traversal",
"create_tree",
"pre_order_traversal_reverse"
] | 3 | [
[
"pre_order_traversal_reverse",
"pre_order_traversal"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 6cef7909b5ab91aa34be30e433d8add26d1772a4 | 98cd51553703040eaa6ba7ee00337636da8f0e9a | |||
v1.0 | instruct | Filter | Filter_35599_I | Given a list of strings, output a new list where the order of the characters in each string is reversed. However, you are not allowed to use any built-in functions or methods that directly reverse a string, and your solution should have a time complexity better than O(n^2). You must implement your own algorithm to reve... | def reverse_string(s):
"""
Reverses the characters in a string.
"""
char_list = list(s)
left, right = 0, len(char_list) - 1
while left < right:
char_list[left], char_list[right] = char_list[right], char_list[left]
left += 1
right -= 1
return ''.join(char... | from solution import reverse_strings_in_list
def test_reverse_strings_in_list():
assert reverse_strings_in_list(["abc", "def"]) == ["cba", "fed"]
assert reverse_strings_in_list(["madam", "racecar"]) == ["madam", "racecar"]
assert reverse_strings_in_list(["a", ""]) == ["a", ""]
assert reverse_strings_in... | [
{
"docstring": "Reverses the characters in a string.",
"function_declaration": "def reverse_string(s):",
"function_name": "reverse_string",
"parameter_list": "(s)"
},
{
"docstring": "Reverses the characters in each string within a list.",
"function_declaration": "def reverse_strings_in_l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_strings_in_list(strings_list):\n \"\"\"\n Takes a list of strings and returns a new list where the order of the characters in each string is reversed.\n \"\"\"\n def re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035599",
"row_id": 35599,
"seed_ids": "['Qwen2-72B-Instruct_79893']"
} | 0.774 | Filter_35599 | I | [
"reverse_string",
"reverse_strings_in_list"
] | 2 | [
[
"reverse_strings_in_list",
"reverse_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6745d362f5da0b21d489331330f79498218468d2 | 24913a2f15043d530c70dc8744e9b0a3c6c0497d | |||
v1.0 | instruct | Filter | Filter_35621_I | Consider a sorted linked list and perform a binary search on this list. Additionally, ensure your algorithm can handle duplicates and returns the first index of the target in the list. If the target is not found, return -1. | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def find_length(head):
length = 0
while head:
length += 1
head = head.next
return length
def get_node_at_index(head, index):
current = head
for _ in range(index):
curre... | from solution import ListNode, binary_search_linked_list
def list_to_linked_list(lst):
dummy = ListNode(0)
current = dummy
for val in lst:
current.next = ListNode(val)
current = current.next
return dummy.next
def test_binary_search_single_element():
head = list_to_linked_list([5])
... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef get_list_length(head):\n length = 0\n while head:\n head = head... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035621",
"row_id": 35621,
"seed_ids": "['Qwen2-72B-Instruct_79937']"
} | 0.64533 | Filter_35621 | I | [
"find_length",
"get_node_at_index",
"binary_search_linked_list"
] | 3 | [
[
"binary_search_linked_list",
"find_length"
],
[
"binary_search_linked_list",
"get_node_at_index"
]
] | 2 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 861061a592f800a46eaa3509a977a25bfef27ee4 | 8db0f3909ff9055854d2b860eb992abb6645b9d8 | |||
v1.0 | instruct | Filter | Filter_35629_I | Implement a selection sort algorithm in Python to sort an array of integer numbers in ascending order. You can not use any built-in sort methods or functions. After that, modify your code to use a binary search to find the correct position for the selected element (in the sorted part of the array), this should be imple... | def binary_search(arr, val, start, end):
"""
Perform binary search to find the index where `val` should be inserted.
"""
while start < end:
mid = (start + end) // 2
if arr[mid] < val:
start = mid + 1
else:
end = mid
return start
def selection_sort(arr... | from solution import selection_sort
def test_selection_sort_unsorted():
assert selection_sort([64, 25, 12, 22, 11]) == [11, 12, 22, 25, 64]
def test_selection_sort_sorted():
assert selection_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_selection_sort_reversed():
assert selection_sort([5, 4, 3, 2, 1]... | [
{
"docstring": "Perform binary search to find the index where `val` should be inserted.",
"function_declaration": "def binary_search(arr, val, start, end):",
"function_name": "binary_search",
"parameter_list": "(arr, val, start, end)"
},
{
"docstring": "Perform selection sort using binary se... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_search(arr, start, end, key):\n \"\"\"\n A binary search function that finds the appropriate position\n for the key in the sorted part of the array.\n \"\"\"\n while ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035629",
"row_id": 35629,
"seed_ids": "['Qwen2-72B-Instruct_79949']"
} | 0.658656 | Filter_35629 | I | [
"binary_search",
"selection_sort"
] | 2 | [
[
"selection_sort",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4f2bd7c6a89753476cce889b91493b06bf2c6bb | 520bcfbc09cf67c402e4114dee74d8c3b32cf751 | |||
v1.0 | instruct | Filter | Filter_35630_I | How can I use AWS Step Functions to validate the format and content of uploaded XML files before passing them to another function for further processing? Could you please provide a sample code that demonstrates this workflow? | import boto3
def create_step_function():
"""
Creates an AWS Step Function that validates the format and content of uploaded XML files.
"""
client = boto3.client('stepfunctions')
definition = {
"Comment": "A state machine that validates XML files.",
"StartAt": "ValidateXMLFormat",
... | from solution import validate_xml_format, validate_xml_content, process_valid_xml
def test_validate_xml_format_valid():
# Valid XML string
xml_data = "<root><content>test</content></root>"
assert validate_xml_format(xml_data) == {"status": "ValidFormat"}
def test_validate_xml_format_invalid():
# Inval... | [
{
"docstring": "Creates an AWS Step Function that validates the format and content of uploaded XML files.",
"function_declaration": "def create_step_function():",
"function_name": "create_step_function",
"parameter_list": "()"
},
{
"docstring": "Entry point for the Lambda function.",
"fu... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport boto3\n\ndef lambda_handler(event, context):\n # Extract the file information from the event\n bucket = event['Records'][0]['s3']['bucket']['name']\n key = event['... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035630",
"row_id": 35630,
"seed_ids": "['Qwen2-72B-Instruct_79952']"
} | 0.366087 | Filter_35630 | I | [
"create_step_function",
"lambda_handler",
"validate_xml_format",
"validate_xml_content",
"process_valid_xml"
] | 5 | [
[
"lambda_handler",
"process_valid_xml"
],
[
"lambda_handler",
"validate_xml_content"
],
[
"lambda_handler",
"validate_xml_format"
]
] | 3 | [] | false | [] | false | pytest | true | [
"boto3"
] | false | 236b5d65cbbda1d5a29bdfcc17c98713cc620e15 | 6fb8405ec3ad584b1926e7ff83c6a375b913e8e0 | |||
v1.0 | instruct | Filter | Filter_35651_I | Design a binary expression tree for the arithmetic equation (2+3)*4 and implement a program to evaluate it. The program should also handle potential divide by zero exceptions. Here is a Python solution using a simple binary expression tree. This program only solve the equation 2+3*4 but you can easily extend it to hand... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def evaluate_tree(node):
if not node:
return 0
if not node.left and not node.right:
return node.value
left_value = evaluate_tree(node.left)
right_value = ev... | from solution import evaluate_expression, TreeNode, evaluate_tree
def test_evaluate_expression():
assert evaluate_expression() == 20
def test_addition():
root = TreeNode('+')
root.left = TreeNode(5)
root.right = TreeNode(3)
assert evaluate_tree(root) == 8
def test_subtraction():
root = TreeNo... | [] | [
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, value):\n self.value = value\n self.left = None\n self.right = None\n \ndef evaluate_expression_tree(node):\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035651",
"row_id": 35651,
"seed_ids": "['Qwen2-72B-Instruct_79992']"
} | 0.552013 | Filter_35651 | I | [
"evaluate_tree",
"evaluate_expression"
] | 2 | [
[
"evaluate_expression",
"evaluate_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 791054398ee00287b26d9a88ebba8f75b4075cf4 | aa21a7db72ef21533949d840188949a3f18f29e4 | |||
v1.0 | instruct | Filter | Filter_35664_I | Write a Python function that takes a list of positive integers as an input and returns a set containing the squares of the unique, prime numbers from the input list. Use the Sieve of Eratosthenes algorithm to find primes. | def sieve_of_eratosthenes(n):
"""
Returns a list of all primes less than or equal to n.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
primes = []
... | from solution import unique_prime_squares
def test_unique_prime_squares_with_no_primes():
assert unique_prime_squares([4, 6, 8, 9]) == set()
def test_unique_prime_squares_with_primes():
assert unique_prime_squares([2, 3, 5, 7, 11]) == {4, 9, 25, 49, 121}
def test_unique_prime_squares_with_mixed_numbers():
... | [
{
"docstring": "Returns a list of all primes less than or equal to n.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns a set containing the squares of unique prime numbers from the input li... | [
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 is_prime = [True] * (limit + 1)\n p = 2\n while p * p <= limit:\n if is_prime[p]:\n for i in range(p * p, limit + 1, p):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035664",
"row_id": 35664,
"seed_ids": "['Qwen2-72B-Instruct_80019']"
} | 0.608504 | Filter_35664 | I | [
"sieve_of_eratosthenes",
"unique_prime_squares"
] | 2 | [
[
"unique_prime_squares",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9425c40698414aee50f167d1ec1eea80780f2d3f | 36bd8f04a7d91268e7d5d00e70c0f2f96dce49f9 | |||
v1.0 | instruct | Filter | Filter_35667_I | Write a Python function that accepts a list of numbers and returns the sum of all prime numbers present in the list. If the list is empty or contains no prime numbers, return 0. Use explicit prime checking algorithm instead of relying on libraries. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import sum_of_primes
def test_sum_of_primes_all_primes():
assert sum_of_primes([2, 3, 5, 7, 11, 13]) == 41
def test_sum_of_primes_mixed_numbers():
assert sum_of_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 17
def test_sum_of_primes_no_primes():
assert sum_of_primes([1, 4, 6, 8, 10, 12]) == 0
... | [
{
"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 present in the list numbers.\nIf the list is empty or contains no prime ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\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": "00035667",
"row_id": 35667,
"seed_ids": "['Qwen2-72B-Instruct_80025']"
} | 0.673984 | Filter_35667 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 56fdf85ce0dd93ca1bbd5259e61c9bc1d2c99ef3 | 19dbac82906b3692ea77d78cd605d3adf037bab9 | |||
v1.0 | instruct | Filter | Filter_35679_I | Given two sets A and B, write a function in Python to find the power set (set of all possible subsets) of A whose union with set B results an identical set B. Note that the input sets will only contain distinct positive integers. Your solution should also consider the performance for larger sets. | from itertools import chain, combinations
def power_set(s):
"""Returns the powerset of set s."""
return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
def subsets_with_desired_union(A, B):
"""
Returns all subsets of A whose union with B is identical to B.
Args:
A: Set ... | from solution import subsets_with_desired_union
def test_case_basic():
A = {1, 2}
B = {3, 4}
result = subsets_with_desired_union(A, B)
assert result == [set()]
def test_case_B_subset_A():
A = {1, 2, 3}
B = {3}
result = subsets_with_desired_union(A, B)
assert set(map(frozenset, result))... | [
{
"docstring": "Returns the powerset of set s.",
"function_declaration": "def power_set(s):",
"function_name": "power_set",
"parameter_list": "(s)"
},
{
"docstring": "Returns all subsets of A whose union with B is identical to B.\n\nArgs:\nA: Set of distinct positive integers.\nB: Set of dis... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import chain, combinations\n\ndef powerset(iterable):\n \"\"\"\n Returns the power set of a given iterable.\n \"\"\"\n s = list(iterable)\n return list(chain.from... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035679",
"row_id": 35679,
"seed_ids": "['Qwen2-72B-Instruct_80047']"
} | 0.462895 | Filter_35679 | I | [
"power_set",
"subsets_with_desired_union"
] | 2 | [
[
"subsets_with_desired_union",
"power_set"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63273feaf303a972c6e4d539e47aaca580ebf286 | 2b2aac16f25ba75dfd44872fb320c26dc756d286 | |||
v1.0 | instruct | Filter | Filter_35696_I | Execute the merge sort algorithm to sort a provided numerical dataset in ascending order, but introduce an additional complexity by doing so iteratively instead of recursively. | def iterative_merge_sort(arr):
"""
Sorts an array using an iterative approach to merge sort.
"""
if len(arr) < 2:
return arr
# Create a list of single item lists
work = [[x] for x in arr]
# Iterate merging lists pairwise
while len(work) > 1:
# Prepare for the ne... | from solution import iterative_merge_sort
def test_iterative_merge_sort_empty():
assert iterative_merge_sort([]) == []
def test_iterative_merge_sort_single_element():
assert iterative_merge_sort([1]) == [1]
def test_iterative_merge_sort_two_elements():
assert iterative_merge_sort([2, 1]) == [1, 2]
def t... | [
{
"docstring": "Sorts an array using an iterative approach to merge sort.",
"function_declaration": "def iterative_merge_sort(arr):",
"function_name": "iterative_merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"function_declaratio... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort_iterative(data):\n \"\"\"\n Sorts the provided numerical dataset using the iterative version of the merge sort algorithm.\n \"\"\"\n # Create a list of single-elemen... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035696",
"row_id": 35696,
"seed_ids": "['Qwen2-72B-Instruct_80077']"
} | 0.587343 | Filter_35696 | I | [
"iterative_merge_sort",
"merge"
] | 2 | [
[
"iterative_merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 73071ab0d024e0927c9ea1749b6fabef993bd657 | ed88fc2e0f6775433af7eb56fd540c5f9c93ec84 | |||
v1.0 | instruct | Filter | Filter_35697_I | How do I create a simple internet search engine using Python? | import os
from collections import defaultdict
def collect_documents(folder_path):
"""
Collects documents from the specified folder.
Each document is a text file with a .txt extension.
Returns a dictionary where keys are filenames and values are their content.
"""
documents = {}
for fil... | import tempfile
import os
from solution import collect_documents, create_index, search
def test_collect_documents():
with tempfile.TemporaryDirectory() as temp_dir:
file1 = os.path.join(temp_dir, "doc1.txt")
file2 = os.path.join(temp_dir, "doc2.txt")
with open(file1, 'w') as f:
... | [
{
"docstring": "Collects documents from the specified folder.\nEach document is a text file with a .txt extension.\n\nReturns a dictionary where keys are filenames and values are their content.",
"function_declaration": "def collect_documents(folder_path):",
"function_name": "collect_documents",
"pa... | [
1,
1,
0
] | 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 collections import defaultdict\nimport math\nimport re\n\nclass SimpleSearchEngine:\n def __init__(self):\n self.index = defaultd... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035697",
"row_id": 35697,
"seed_ids": "['Qwen2-72B-Instruct_80078']"
} | 0.50739 | Filter_35697 | I | [
"collect_documents",
"tokenize",
"create_index",
"search"
] | 4 | [
[
"create_index",
"tokenize"
],
[
"search",
"tokenize"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f4e29c9dd7e8c971a1b6d0eea755355c170bc065 | a53ad5519cfb0d621a5bd50c8cef72e195f8e26f | |||
v1.0 | instruct | Filter | Filter_35698_I | "Create an algorithm that can efficiently filter out and eliminate numbers that are not prime from an input array consisting of integers, producing a refined list of prime numbers as the output. Your solution should be able to handle different array sizes, elements, and input forms, such as files containing lists of in... | def is_prime(n):
"""
Determine whether a number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(input_a... | from solution import filter_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
def test_filter_primes():
# Test with an empty array
assert filter_primes([]) == []
# Test with an array of p... | [
{
"docstring": "Determine whether a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filter out non-prime numbers from the input array, returning an array of prime numbers.",
"function_declaration": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035698",
"row_id": 35698,
"seed_ids": "['Qwen2-72B-Instruct_80079']"
} | 0.607346 | Filter_35698 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9b0229f6d149d97ddcf1491bed7a23f885a93c3 | 1257bb301551dd5d0c0ef4c9df6fcdab55b1bc1a | |||
v1.0 | instruct | Filter | Filter_35720_I | Enumerate the first 8 numbers in the Fibonacci sequence, but do so implementing a generator function in Python. Also, modify this function so it could theoretically generate an arbitrarily long Fibonacci sequence (beyond 8 terms). | def fibonacci_generator():
"""
Generator function to return the Fibonacci sequence.
"""
a, b = 0, 1
while True:
yield a
a, b = b, a + b
# To get the first 8 numbers in the Fibonacci sequence:
def first_n_fibonacci(n):
fib_gen = fibonacci_generator()
return [next(fib_gen) for... | from solution import first_n_fibonacci, fibonacci_generator
def test_first_8_fibonacci():
assert first_n_fibonacci(8) == [0, 1, 1, 2, 3, 5, 8, 13]
def test_first_10_fibonacci():
assert first_n_fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_first_fibonacci_is_zero():
assert first_n_fibonacci(... | [
{
"docstring": "Generator function to return the Fibonacci sequence.",
"function_declaration": "def fibonacci_generator():",
"function_name": "fibonacci_generator",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def first_n_fibonacci(n):",
"function_name": "f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_gen():\n \"\"\"\n Generator function to yield Fibonacci numbers indefinitely.\n \"\"\"\n a, b = 0, 1\n while True:\n yield a\n a, b = b, a + b\n\ndef... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035720",
"row_id": 35720,
"seed_ids": "['Qwen2-72B-Instruct_80117']"
} | 0.690001 | Filter_35720 | I | [
"fibonacci_generator",
"first_n_fibonacci"
] | 2 | [
[
"first_n_fibonacci",
"fibonacci_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e86120786fff2a56f16539736bebbd11290c71d | 9eb8386ff5428e3d1cda60175f1f75adcce219bf | |||
v1.0 | instruct | Filter | Filter_35732_I | Can you create a Python function that distinguishes prime numbers from a given list of integers, including negative integers and zero? | def is_prime(n):
"""
Determine if a number is prime.
Args:
- n (int): The number to check.
Returns:
- bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in rang... | from solution import is_prime, filter_primes
def test_is_prime():
# Test prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(11) == True
# Test non-prime numbers
assert is_prime(0) == False
assert is_prime(1) == False
asser... | [
{
"docstring": "Determine if a number is prime.\n\nArgs:\n- n (int): The number to check.\n\nReturns:\n- bool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filter and return... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035732",
"row_id": 35732,
"seed_ids": "['Qwen2-72B-Instruct_80141']"
} | 0.666279 | Filter_35732 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e968057a47d39b8abf56bed9aba61952ee6b305a | 5bbc1b7024757ca88552a590307e8508fde58a72 | |||
v1.0 | instruct | Filter | Filter_35738_I | Please read the following two arrays of integers, sort them in ascending order and then merge them into a single sorted array in Python. You should not use built-in Python sorting methods. Instead implement your own sort using an efficient sort algorithm. Algorithms efficiency is determined by its time complexity. Try ... | def merge_sort(arr):
if len(arr) > 1:
mid = len(arr)//2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
i += ... | from solution import merge_arrays
def test_merge_with_positive_numbers():
assert merge_arrays([3, 1, 2], [6, 5, 4]) == [1, 2, 3, 4, 5, 6]
def test_merge_with_negative_numbers():
assert merge_arrays([-3, -1, -2], [-6, -5, -4]) == [-6, -5, -4, -3, -2, -1]
def test_merge_mixed_sign_numbers():
assert merge_a... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def merge_arrays(arr1, arr2):",
"function_name": "merge_arrays",
"parameter_list": "(arr1, arr2)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sorted_arrays(arr1, arr2):\n \"\"\"\n Merges two sorted arrays into a single sorted array.\n \"\"\"\n merged = []\n i, j = 0, 0\n\n while i < len(arr1) and j < len(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035738",
"row_id": 35738,
"seed_ids": "['Qwen2-72B-Instruct_80152']"
} | 0.633712 | Filter_35738 | I | [
"merge_sort",
"merge_arrays"
] | 2 | [
[
"merge_arrays",
"merge_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 83c11f8b63968a9bf9978d1882cc1ecc276e770f | e6643bdc82109329fb2bca497cf760e157bb88b2 | |||
v1.0 | instruct | Filter | Filter_35741_I | Write a code to group the elements in a list into a dictionary with the list element as the key and the number of times the element is repeated in the list as the value. The input list can contain any type of element, including nested lists and dictionaries. The code should be able to handle any number of nested levels... | from collections import Counter
def flatten_list(nested_list):
"""
Helper function to flatten a nested list.
"""
for item in nested_list:
if isinstance(item, list):
yield from flatten_list(item)
else:
yield item
def element_count(input_list):
"""
Returns... | from solution import element_count
def test_element_count_simple():
assert element_count([1, 2, 2, 3, 3, 3]) == {1: 1, 2: 2, 3: 3}
def test_element_count_mixed_nested():
assert element_count([1, [2, 3], 2, [3, 3, [1]]]) == {1: 2, 2: 2, 3: 3}
def test_element_count_empty_list():
assert element_count([]) =... | [
{
"docstring": "Helper function to flatten a nested list.",
"function_declaration": "def flatten_list(nested_list):",
"function_name": "flatten_list",
"parameter_list": "(nested_list)"
},
{
"docstring": "Returns a dictionary with elements as the keys and the number of times \neach element is... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef flatten_list(mixed_list):\n \"\"\"\n Flattens a nested list into a single list of elements.\n \"\"\"\n for element in mixed_list:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035741",
"row_id": 35741,
"seed_ids": "['Qwen2-72B-Instruct_80163']"
} | 0.663056 | Filter_35741 | I | [
"flatten_list",
"element_count"
] | 2 | [
[
"element_count",
"flatten_list"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fd7d5d4bd1c255cd2c2fcf0f80cec43970f87f27 | 9a6239f1022e281bec08f20e2fdc4edeb549a0e5 | |||
v1.0 | instruct | Filter | Filter_35763_I | Create a program in Python to output the number of prime numbers between 1 and 100. Also, provide a function that validates if a number is prime or not. Use the function within your code instead of using pre-existing packages or methods. Here is an erroneous piece of code as a reference. Identify and correct the mistak... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return Fal... | from solution import is_prime, count_primes_between_1_and_100
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(17)
assert not is_prime(18)
assert is_prime(19)
def test_count_primes_between_1_... | [
{
"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 the number of prime numbers between 1 and 100.",
"function_declaration": "def count_primes_b... | [
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 Determine if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035763",
"row_id": 35763,
"seed_ids": "['Qwen2-72B-Instruct_80196']"
} | 0.692586 | Filter_35763 | I | [
"is_prime",
"count_primes_between_1_and_100"
] | 2 | [
[
"count_primes_between_1_and_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | daa1ccf549c28aa69691a4950ef5d29fe98cbf63 | 60b8b70464749b3d4339c4d4cd9f7e907d35a07e | |||
v1.0 | instruct | Filter | Filter_35764_I | Write an algorithm to sort an array using Hybrid quicksort. | def insertion_sort(array, low, high):
for i in range(low + 1, high + 1):
key = array[i]
j = i - 1
while j >= low and key < array[j]:
array[j + 1] = array[j]
j -= 1
array[j + 1] = key
def partition(array, low, high):
pivot = array[high]
i = low - 1
... | from solution import sort
def test_sort_empty_array():
assert sort([]) == []
def test_sort_single_element_array():
assert sort([5]) == [5]
def test_sort_sorted_array():
assert sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_sort_reverse_sorted_array():
assert sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, ... | [
{
"docstring": null,
"function_declaration": "def insertion_sort(array, low, high):",
"function_name": "insertion_sort",
"parameter_list": "(array, low, high)"
},
{
"docstring": null,
"function_declaration": "def partition(array, low, high):",
"function_name": "partition",
"param... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def insertion_sort(arr, low, high):\n for i in range(low + 1, high + 1):\n key = arr[i]\n j = i - 1\n while j >= low and arr[j] > key:\n arr[j + 1] = arr[j]\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035764",
"row_id": 35764,
"seed_ids": "['Qwen2-72B-Instruct_80198']"
} | 0.677945 | Filter_35764 | I | [
"insertion_sort",
"partition",
"hybrid_quicksort",
"sort"
] | 4 | [
[
"hybrid_quicksort",
"insertion_sort"
],
[
"hybrid_quicksort",
"partition"
],
[
"sort",
"hybrid_quicksort"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1a7cc3ffd5185a7bb545492111730219ca2dee3c | d39f9b70f0abdc7d28842466baea9f3031c450e7 | |||
v1.0 | instruct | Filter | Filter_35775_I | Write a lexer and parser in Python for a simple language that only has numbers and the binary addition operation. | import re
# Lexer part
def lexer(input_string):
tokens = []
token_specification = [
('NUMBER', r'\d+'), # Integer
('PLUS', r'\+'), # Addition operator
('SKIP', r'[ \t]+'), # Skip over spaces and tabs
('MISMATCH', r'.'), # Any other character
]
token_re ... | from solution import lexer, parser, evaluate_expression
def test_lexer_single_number():
assert lexer("123") == [('NUMBER', 123)]
def test_lexer_addition():
assert lexer("123 + 456") == [('NUMBER', 123), ('PLUS', '+'), ('NUMBER', 456)]
def test_parser_single_number():
assert parser([('NUMBER', 123)]) == 1... | [
{
"docstring": null,
"function_declaration": "def lexer(input_string):",
"function_name": "lexer",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declaration": "def parser(tokens):",
"function_name": "parser",
"parameter_list": "(tokens)"
},
{
"docst... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\n# Token types\nNUMBER = 'NUMBER'\nPLUS = 'PLUS'\nEOF = 'EOF'\n\n# Token class\nclass Token:\n def __init__(self, type, value):\n self.type = type\n self.value = v... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035775",
"row_id": 35775,
"seed_ids": "['Qwen2-72B-Instruct_80220']"
} | 0.535 | Filter_35775 | I | [
"lexer",
"parser",
"evaluate_expression"
] | 3 | [
[
"evaluate_expression",
"lexer"
],
[
"evaluate_expression",
"parser"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 75f46e05fa32943811824069b95ca647ba97b2ed | e54c811398ec7738c1a1829f226b3b5557444618 | |||
v1.0 | instruct | Filter | Filter_35776_I | Implement a program that creates an accurate JSON data structure compliant with ECMAScript 2019 standards, given the specific detailed input data, including handling invalid input data gracefully. The program should also include data validation and proper error handling. | import json
class InvalidDataError(Exception):
pass
def validate_data(data):
if not isinstance(data, dict):
raise InvalidDataError("Input data must be a dictionary.")
if not all(isinstance(key, str) and key for key in data.keys()):
raise InvalidDataError("All keys must be non-empty strings... | from solution import create_json, InvalidDataError
def test_create_json_valid_data():
data = {
"name": "Alice",
"age": 30,
"is_student": False,
"courses": ["Math", "Science"],
"details": {
"height": 170.5,
"employed": True
},
"null_val... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef create_json_structure(input_data):\n \"\"\"\n Creates a JSON data structure from input data, ensuring it is compliant with ECMAScript 2019 standards.\n Throws Value... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035776",
"row_id": 35776,
"seed_ids": "['Qwen2-72B-Instruct_80222']"
} | 0.437122 | Filter_35776 | I | [
"validate_data",
"create_json"
] | 2 | [
[
"create_json",
"validate_data"
]
] | 1 | [] | false | [
"InvalidDataError"
] | true | pytest | true | [] | true | 066003d09a05a34d3b434370ac94e0b5f8121198 | fbe6e942242b931c0cce4bafdb71b6da5c636a53 | |||
v1.0 | instruct | Filter | Filter_35799_I | Modify the code snippet so that it prints the **kth largest** element in the given list, without using any built-in sorting functions. Additionally, the solution should have a time complexity of O(n) and a space complexity of O(1). | def partition(arr, left, right):
pivot = arr[right]
i = left - 1
for j in range(left, right):
if arr[j] >= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[right] = arr[right], arr[i + 1]
return i + 1
def kth_largest(arr, k):
left, right = 0, len(arr... | from solution import kth_largest
def test_kth_largest_1():
assert kth_largest([3, 2, 1, 5, 6, 4], 2) == 5
def test_kth_largest_2():
assert kth_largest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4
def test_kth_largest_3():
assert kth_largest([1, 2, 3, 4, 5, 6], 1) == 6
def test_kth_largest_4():
assert kth_la... | [
{
"docstring": null,
"function_declaration": "def partition(arr, left, right):",
"function_name": "partition",
"parameter_list": "(arr, left, right)"
},
{
"docstring": null,
"function_declaration": "def kth_largest(arr, k):",
"function_name": "kth_largest",
"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 kth_largest(arr, k):\n \"\"\"\n Returns the kth largest element in the given list arr.\n This implementation uses the Quickselect algorithm which has an average time complexity of... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035799",
"row_id": 35799,
"seed_ids": "['Qwen2-72B-Instruct_80269']"
} | 0.683437 | Filter_35799 | I | [
"partition",
"kth_largest"
] | 2 | [
[
"kth_largest",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c0c6d54855367161bb59b2a87b5bff79350e4c9 | 0a9cf6f054f2d97363cc1111eb987feb83afa236 | |||
v1.0 | instruct | Filter | Filter_35854_I | Write a program to encrypt a message using RSA encryption algorithm. The user should be able to input their own message and choose two prime numbers for the public and private keys. The program should output the encrypted message along with the generated public and private keys. | import random
from sympy import isprime
def gcd(a, b):
while b:
a, b = b, a % b
return a
def modinv(a, m):
m0, x0, x1 = m, 0, 1
if m == 1:
return 0
while a > 1:
q = a // m
m, a = a % m, m
x0, x1 = x1 - q * x0, x0
if x1 < 0:
x1 += m0
return x1... | from solution import rsa_encrypt, encrypt, decrypt, rsa_keys
def test_rsa_keys_generate_valid_keys():
p, q = 61, 53
public_key, private_key = rsa_keys(p, q)
assert public_key != private_key
def test_encrypt_decrypt():
p, q = 61, 53
message = "HELLO"
encrypted_message, public_key, private_key =... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def modinv(a, m):",
"function_name": "modinv",
"parameter_list": "(a, m)"
},
{
"docstring": null,
"functi... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nfrom sympy import isprime, mod_inverse\n\ndef generate_keys(p, q):\n \"\"\"\n Generate RSA keys given two prime numbers p and q.\n \"\"\"\n if not (isprime(p) and is... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035854",
"row_id": 35854,
"seed_ids": "['Qwen2-72B-Instruct_80373']"
} | 0.53701 | Filter_35854 | I | [
"gcd",
"modinv",
"rsa_keys",
"encrypt",
"decrypt",
"rsa_encrypt"
] | 6 | [
[
"rsa_encrypt",
"encrypt"
],
[
"rsa_encrypt",
"rsa_keys"
],
[
"rsa_keys",
"gcd"
],
[
"rsa_keys",
"modinv"
]
] | 4 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | 1c24edf093bef13b41ee0838926d432aeeade0a3 | db28c713821a6b7cfe10e634959357c1ac9112b9 | |||
v1.0 | instruct | Filter | Filter_35856_I | The following python code simulates the flipping of a fair coin 100 times. Now, I want you to modify the code to flip a biased coin, where the probability of getting heads is 70% and tails is 30%. Please provide the modified code. | import random
def flip_biased_coin():
"""
Flips a biased coin with a 70% chance of heads (represented by 1)
and a 30% chance of tails (represented by 0).
"""
return 1 if random.random() < 0.7 else 0
def flip_biased_coin_n_times(n):
"""
Flips a biased coin n times and returns the result as ... | from solution import flip_biased_coin, flip_biased_coin_n_times
def test_flip_biased_coin():
results = [flip_biased_coin() for _ in range(1000)]
heads = sum(results)
tails = len(results) - heads
# With 1000 trials and a 70% chance of heads, we expect heads to be around 700 and tails around 300
asse... | [
{
"docstring": "Flips a biased coin with a 70% chance of heads (represented by 1)\nand a 30% chance of tails (represented by 0).",
"function_declaration": "def flip_biased_coin():",
"function_name": "flip_biased_coin",
"parameter_list": "()"
},
{
"docstring": "Flips a biased coin n times and... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef flip_biased_coin():\n \"\"\"\n Simulates flipping a biased coin where the probability \n of getting heads is 70% and tails is 30%.\n \n Returns:\n st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035856",
"row_id": 35856,
"seed_ids": "['Qwen2-72B-Instruct_80375']"
} | 0.402154 | Filter_35856 | I | [
"flip_biased_coin",
"flip_biased_coin_n_times"
] | 2 | [
[
"flip_biased_coin_n_times",
"flip_biased_coin"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5806f33e93cdfbc216b666ac1f7ee70730893987 | 899eeae5f16e9a4e9f8616e9e76acb0912aacd1d | |||
v1.0 | instruct | Filter | Filter_35859_I | Write a Python function that prints the first n Fibonacci numbers in reverse order. Additionally, the function must check if n is a prime number before executing and return a meaningful message if it is not. The implemented function must also handle negative and floating-point number inputs effectively. | def is_prime(n):
"""
Checks 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 fibonacci_reverse(n):
"""
Prints the first n Fibonacci numbers in reverse order if n is a prime numbe... | from solution import fibonacci_reverse, 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(11) is True
assert is_prime(1) is False
assert is_prime(0) is False
assert is_prime(-1) is False
def test_fibonacci_revers... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints the first n Fibonacci numbers in reverse order if n is a prime number.\nReturns an error message if n is not a prime numbe... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035859",
"row_id": 35859,
"seed_ids": "['Qwen2-72B-Instruct_80380']"
} | 0.738094 | Filter_35859 | I | [
"is_prime",
"fibonacci_reverse"
] | 2 | [
[
"fibonacci_reverse",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efadd36f0f32f1af003150bb82a5a3010bb0ec30 | b57c22d45c9413405af40aee5de08e79002352ce | |||
v1.0 | instruct | Filter | Filter_35860_I | Develop an algorithm using a Python function to filter out all the prime numbers from an initially provided list, irrespective of its length or the values of the numbers it contains. For instance, your function should transform the list [10, "orange", 3.14, "优质的", 29, 7] to [29, 7]. | import math
def is_prime(n):
"""
Returns True if n is a prime number, else False. Assumes n is an integer > 1.
"""
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... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(15) == False
assert is_prime(17) == True
assert is_prime(21) == Fals... | [
{
"docstring": "Returns True if n is a prime number, else False. Assumes n is an integer > 1.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out prime numbers from the provided list and returns a new list with pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False. Assumes n is an integer > 1.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035860",
"row_id": 35860,
"seed_ids": "['Qwen2-72B-Instruct_80381']"
} | 0.624492 | Filter_35860 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 66bc58efbb059281bf2c7fd4600c24d2d6233901 | 990ede9adde993e1051dba4df9a34c89420dc2b1 | |||
v1.0 | instruct | Filter | Filter_35862_I | Develop a Python program that converts a given binary number into its equivalent hexadecimal form. Add error checking to ensure that the user input is a valid binary number. Additionally, provide a brief explanation and the algorithm used in the conversion. | def is_binary(s):
"""
Check if the string s is a valid binary number.
"""
return all(char in '01' for char in s)
def binary_to_hexadecimal(binary_str):
"""
Convert a binary number (given as a string) to its hexadecimal equivalent.
Algorithm:
1. Validate if the input string is a val... | from solution import binary_to_hexadecimal, is_binary
def test_is_binary():
assert is_binary('1010') == True
assert is_binary('1020') == False
assert is_binary('') == True
assert is_binary('00001111') == True
def test_binary_to_hexadecimal():
assert binary_to_hexadecimal('1010') == 'A'
assert ... | [
{
"docstring": "Check if the string s is a valid binary number.",
"function_declaration": "def is_binary(s):",
"function_name": "is_binary",
"parameter_list": "(s)"
},
{
"docstring": "Convert a binary number (given as a string) to its hexadecimal equivalent.\n\nAlgorithm:\n1. Validate if the... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_to_hex(binary_str):\n \"\"\"\n Converts a binary number (as string) to its hexadecimal equivalent.\n \n Parameters:\n binary_str (str): The binary number as a string.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035862",
"row_id": 35862,
"seed_ids": "['Qwen2-72B-Instruct_80384']"
} | 0.627742 | Filter_35862 | I | [
"is_binary",
"binary_to_hexadecimal"
] | 2 | [
[
"binary_to_hexadecimal",
"is_binary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 025ffd13b78e2f431ccd2519c0d5e81e42a28a82 | bef1dcf2564dad0707558ff2a7783f51736c96d9 | |||
v1.0 | instruct | Filter | Filter_35866_I | Create two lists of random non-negative integers, each with a length specified by the user. Write a program that merges the two lists element by element to create a new list. If the length provided by the user exceeds 10, a function should be called to divide the list into sub-lists of maximum length 10. Then these sub... | import random
def create_random_list(length):
"""
Generates a list of random non-negative integers of a given length.
"""
return [random.randint(0, 99) for _ in range(length)]
def merge_lists(list1, list2):
"""
Merges two lists element by element.
"""
return [val for pair in zip(list1,... | from solution import create_random_list, merge_lists, divide_into_sublists, handle_lists
def test_create_random_list():
result = create_random_list(5)
assert len(result) == 5
for num in result:
assert 0 <= num <= 99
def test_merge_lists():
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = m... | [
{
"docstring": "Generates a list of random non-negative integers of a given length.",
"function_declaration": "def create_random_list(length):",
"function_name": "create_random_list",
"parameter_list": "(length)"
},
{
"docstring": "Merges two lists element by element.",
"function_declara... | [
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_list(length):\n return [random.randint(0, 100) for _ in range(length)]\n\ndef merge_lists(list1, list2):\n merged_list = []\n for item1, item2 in ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035866",
"row_id": 35866,
"seed_ids": "['Qwen2-72B-Instruct_80392']"
} | 0.548774 | Filter_35866 | I | [
"create_random_list",
"merge_lists",
"divide_into_sublists",
"handle_lists"
] | 4 | [
[
"handle_lists",
"create_random_list"
],
[
"handle_lists",
"divide_into_sublists"
],
[
"handle_lists",
"merge_lists"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a3a7188c2ee95bae6947df2a0d5297ececef26b4 | 2802f648625ce33cacd58146889c550412a93647 | |||
v1.0 | instruct | Filter | Filter_35868_I | Develop a program that simulates a faulty memory register that may occasionally flip bits. Given a binary number, the program should also allow for a 'correction' function that attempts to fix these flippings. If the flippings were limited to a single bit-flip, your program should be able to identify and correct the er... | def bit_flip(binary_str, flip_position):
"""
Flip the bit at the specified position in the binary string.
Args:
- binary_str (str): A string representing a binary number.
- flip_position (int): The position of the bit to flip.
Returns:
- str: The new binary string with the flipped ... | def test_bit_flip():
assert bit_flip("1010", 0) == "0010"
assert bit_flip("1010", 1) == "1110"
assert bit_flip("1010", 2) == "1000"
assert bit_flip("1010", 3) == "1011"
try:
bit_flip("1010", 4)
except ValueError as e:
assert str(e) == 'flip_position is out of the range of the bi... | [
{
"docstring": "Flip the bit at the specified position in the binary string.\n\nArgs:\n- binary_str (str): A string representing a binary number.\n- flip_position (int): The position of the bit to flip.\n\nReturns:\n- str: The new binary string with the flipped bit.",
"function_declaration": "def bit_flip(b... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def flip_bit(binary_str):\n \"\"\"\n Simulates a single bit flip in a binary string. \n Just randomly flipping a bit somewhere.\n \"\"\"\n import random\n\n if not binary_str... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035868",
"row_id": 35868,
"seed_ids": "['Qwen2-72B-Instruct_80401']"
} | 0.471625 | Filter_35868 | I | [
"bit_flip",
"correct_bit_flip"
] | 2 | [
[
"correct_bit_flip",
"bit_flip"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ed21be458e54d70dc42034f130780dbc77a1f799 | d110d96bbf0d356ca71a3e6e81e747b12e21a3f8 | |||
v1.0 | instruct | Filter | Filter_35873_I | Write a Python program that takes a positive integer as input and prints all prime numbers up to and including that number. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return F... | from solution import is_prime, primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(1) == False
def test_primes_up_to():
as... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers up to and including n.",
"function_declaration": "def primes_up_to(n):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035873",
"row_id": 35873,
"seed_ids": "['Qwen2-72B-Instruct_80409']"
} | 0.710244 | Filter_35873 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ebc6f9c816ece3f85fe5de3e193833886a78760 | 966ed9dc8f1757f324c3ee0cb19671ed4ea47edd | |||
v1.0 | instruct | Filter | Filter_35876_I | Develop a function to separate numbers in a given list into prime and composite numbers. The function should also handle edge cases, such as negative numbers and non-integer data types. Here is a piece of erroneous code for reference, identify the mistakes and correct them in your solution. | def is_prime(n):
"""
Helper function to determine if a number n is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def separate_prime_composite(items):
"""
Separates the numbers in `items` into pr... | from solution import separate_prime_composite
def test_mixed_list():
result = separate_prime_composite([3, 4, 5, 6, 7, 8, 'a', 0, -1])
assert result == ([3, 5, 7], [4, 6, 8])
def test_only_primes():
result = separate_prime_composite([2, 3, 5, 11, 13])
assert result == ([2, 3, 5, 11, 13], [])
def test... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Separates the numbers in `items` into prime and composite numbers.\n\nParameters:\n- items: a list that c... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <= n:\n if n % p == 0:\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035876",
"row_id": 35876,
"seed_ids": "['Qwen2-72B-Instruct_80413']"
} | 0.559994 | Filter_35876 | I | [
"is_prime",
"separate_prime_composite"
] | 2 | [
[
"separate_prime_composite",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed191b182ea04d0f74932763fc7feed7056cd7c7 | 722280352c0bc96462eb0ee2c6e419da81755a3a | |||
v1.0 | instruct | Filter | Filter_35889_I | Can you write a Python program that reads a list of numbers from user input, sorts them in decreasing order using a custom sorting algorithm, and logs the execution time using a logger? | import logging
import time
# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(message)s')
logger = logging.getLogger()
def custom_sort(arr):
"""
Sorts an array in decreasing order using Bubble Sort.
"""
n = len(arr)
for i in range(n):
for j in range(0, n-i... | from solution import custom_sort, sort_numbers_decreasing
def test_custom_sort():
assert custom_sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [9, 6, 5, 5, 4, 3, 2, 1, 1]
assert custom_sort([]) == []
assert custom_sort([2]) == [2]
assert custom_sort([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]
def test_sort_numbers_decr... | [
{
"docstring": "Sorts an array in decreasing order using Bubble Sort.",
"function_declaration": "def custom_sort(arr):",
"function_name": "custom_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Takes a list of numbers, sorts them in decreasing order using custom_sort, and logs the execut... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import logging\nimport time\n\n# Configure logging\nlogging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(message)s')\nlogger = logging.getLogger()\n\ndef custom_sort(arr):\n \"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035889",
"row_id": 35889,
"seed_ids": "['Qwen2-72B-Instruct_80434']"
} | 0.613564 | Filter_35889 | I | [
"custom_sort",
"sort_numbers_decreasing"
] | 2 | [
[
"sort_numbers_decreasing",
"custom_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 86528850966102226dc410bbff875f35f9254118 | b3b0931b1431600eca8dccd75a5cc16fb56752a7 | |||
v1.0 | instruct | Filter | Filter_35891_I | Given a matrix of m*n size, write a program to find the maximum sum of all subarrays in the matrix. Your program should be optimized for time complexity and should not use more than O(m*n) extra space. Ensure your program also considers submatrices of size 1x1 as valid subarrays. | def max_sum_submatrix(matrix):
if not matrix or not matrix[0]:
return 0
max_sum = float('-inf')
rows = len(matrix)
cols = len(matrix[0])
for left in range(cols):
row_sum = [0] * rows
for right in range(left, cols):
for i in range(rows):
r... | from solution import max_sum_submatrix
def test_single_element_matrix():
assert max_sum_submatrix([[3]]) == 3
assert max_sum_submatrix([[-2]]) == -2
def test_multiple_rows_and_columns():
assert max_sum_submatrix([
[1, 2, -1],
[-3, 4, 5],
[1, -3, 2]
]) == 10 # Submatrix is {4, ... | [
{
"docstring": null,
"function_declaration": "def max_sum_submatrix(matrix):",
"function_name": "max_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_submatrix(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n max_sum = float('-inf')\n rows = len(matrix)\n cols = len(matrix[0])\n \n for left ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035891",
"row_id": 35891,
"seed_ids": "['Qwen2-72B-Instruct_80437']"
} | 0.634313 | Filter_35891 | I | [
"max_sum_submatrix",
"max_subarray_sum"
] | 2 | [
[
"max_sum_submatrix",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4eaff08d3e1fa71076246062b760fb4c499d1402 | e39479148b0d724e2b63f32549004fc50cc198b8 | |||
v1.0 | instruct | Filter | Filter_35894_I | Write a program that accepts a positive integer N as input and creates a N x N matrix with random numbers from 0 to 9. After that, the program should print the matrix, calculate and print its determinant, and then check if it is invertible. If it is invertible, calculate and print its inverse matrix. | import numpy as np
def generate_matrix(N):
"""
Generates an NxN matrix with random integers from 0 to 9.
"""
return np.random.randint(0, 10, (N, N))
def print_matrix(matrix):
"""
Prints the given matrix.
"""
for row in matrix:
print(" ".join(map(str, row)))
def compute_determi... | from solution import generate_matrix, compute_determinant, is_invertible, compute_inverse
import numpy as np
def test_generate_matrix():
N = 3
matrix = generate_matrix(N)
assert matrix.shape == (N, N)
assert (matrix >= 0).all() and (matrix < 10).all()
def test_compute_determinant():
matrix = n... | [
{
"docstring": "Generates an NxN matrix with random integers from 0 to 9.",
"function_declaration": "def generate_matrix(N):",
"function_name": "generate_matrix",
"parameter_list": "(N)"
},
{
"docstring": "Prints the given matrix.",
"function_declaration": "def print_matrix(matrix):",
... | [
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_random_matrix(N):\n \"\"\"\n Generates an N x N matrix with random numbers from 0 to 9.\n \"\"\"\n return np.random.randint(0, 10, (N, N))\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035894",
"row_id": 35894,
"seed_ids": "['Qwen2-72B-Instruct_80441']"
} | 0.447433 | Filter_35894 | I | [
"generate_matrix",
"print_matrix",
"compute_determinant",
"is_invertible",
"compute_inverse",
"main"
] | 6 | [
[
"is_invertible",
"compute_determinant"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 7c6e747c11a18ed6103db67c80d1c4b1f9b51508 | cb78c312cfb6e8e2eebcd7f4438f89258a57e532 | |||
v1.0 | instruct | Filter | Filter_35922_I | Hello! How can I create an algorithm to find the k-th smallest element in a given array using QuickSelect? Can you provide a detailed explanation and code example? | def quickselect(arr, left, right, k):
"""
This function returns the k-th smallest element of the list within left..right.
"""
if left == right: # If the list contains only one element,
return arr[left] # return that element
pivot_index = partition(arr, left, right)
# The pivo... | from solution import find_kth_smallest
def test_find_kth_smallest_single_element():
assert find_kth_smallest([3], 1) == 3
def test_find_kth_smallest_multiple_elements():
assert find_kth_smallest([3, 1, 2], 1) == 1
assert find_kth_smallest([3, 1, 2], 2) == 2
assert find_kth_smallest([3, 1, 2], 3) == 3
... | [
{
"docstring": "This function returns the k-th smallest element of the list within left..right.",
"function_declaration": "def quickselect(arr, left, right, k):",
"function_name": "quickselect",
"parameter_list": "(arr, left, right, k)"
},
{
"docstring": "This function takes the last element... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quickselect(arr, left, right, k):\n \"\"\"\n This function returns the k-th smallest element of the list within left..right.\n \"\"\"\n if left == right: # If the list contain... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035922",
"row_id": 35922,
"seed_ids": "['Qwen2-72B-Instruct_80499']"
} | 0.541649 | Filter_35922 | I | [
"quickselect",
"partition",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 73494cb1a3fa9e5f1fa41a72b5801b48ddb155bf | aee1b2b48639e363626d48cdb36f575df6d39909 | |||
v1.0 | instruct | Filter | Filter_35967_I | Is there a way to create a program that generates the first 15 prime numbers using Python? Could you provide a code example? Also, it would be helpful if you could explain the logic behind the code. | def is_prime(n):
"""
Check if a number is a prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def generate_primes(count):
""... | from solution import first_15_primes, is_prime, generate_primes
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert not is_prime(9)
def test_generate_primes():
assert generate_primes(5) == [2, 3, 5, 7, 11]
... | [
{
"docstring": "Check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate the first `count` prime numbers.",
"function_declaration": "def generate_primes(count):",
"function_name": "gen... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035967",
"row_id": 35967,
"seed_ids": "['Qwen2-72B-Instruct_80568']"
} | 0.55325 | Filter_35967 | I | [
"is_prime",
"generate_primes",
"first_15_primes"
] | 3 | [
[
"first_15_primes",
"generate_primes"
],
[
"generate_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b6def7e923983255b79835fce94e1537034d5252 | cf399cb3ae71feea1cd92c2f240f3a1160698a08 | |||
v1.0 | instruct | Filter | Filter_35970_I | Develop a Python program to display odd numbers from 11 to 3000 and also identify and classify those numbers which are primes. | def is_prime(num):
"""
Returns True if num is a prime number, else returns False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
retu... | from solution import odd_numbers_and_primes, is_prime
def test_is_prime():
assert is_prime(11) == True
assert is_prime(15) == False
assert is_prime(2) == True
assert is_prime(1) == False
def test_odd_numbers_and_primes():
odd_numbers, prime_numbers = odd_numbers_and_primes(11, 21)
assert odd_n... | [
{
"docstring": "Returns True if num is a prime number, else returns False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of odd numbers within the range start to end (inclusive)\nand a list of prime nu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if the number n is prime, 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": "00035970",
"row_id": 35970,
"seed_ids": "['Qwen2-72B-Instruct_80571']"
} | 0.579806 | Filter_35970 | I | [
"is_prime",
"odd_numbers_and_primes"
] | 2 | [
[
"odd_numbers_and_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b09e789541ed19bdfa8b86c7c720eb5a3efcef63 | b9b6ba69d5ecc88c9d48bd2f6e06531857bc31df |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.