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
Prefill
Prefill_1148_I
Write a function to perform a merge sort on an array.
def merge_sort(arr): """ Perform a merge sort on an array. """ if len(arr) <= 1: return arr # Split the array into two halves mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] # Recursively split and merge the halves left_sorted = merge_sort(left_half) ...
from solution import merge_sort def test_merge_sort_empty_array(): assert 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(): ass...
[ { "docstring": "Perform a merge sort on an array.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merge two sorted arrays into one sorted array.", "function_declaration": "def merge(left, right):", "functio...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Function to perform merge sort on an array.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left = merge_sort(...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001148", "row_id": 1148, "seed_ids": "['magpie_prefill_1148']" }
0.917863
Prefill_1148
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
33ebcdc5f943e367b078514d23633e3a780f66f9
dbc956d26da0b1f8a0bd09ff6e2125bf0fac67d7
v1.0
instruct
Prefill
Prefill_1173_I
Write a function to identify all prime numbers within a given range. The function should return a list of prime numbers that are greater than or equal to the start of the range and less than the end of the range. A prime number is defined as a natural number greater than 1 that has no positive divisors other than 1 and...
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import primes_in_range def test_empty_range(): assert primes_in_range(10, 10) == [] assert primes_in_range(25, 20) == [] def test_no_primes_in_range(): assert primes_in_range(4, 6) == [5] assert primes_in_range(24, 25) == [] def test_primes_in_small_range(): assert primes_in_range(2...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers in the range [start, end).", "function_declaration": "def primes_in_ran...
[ 1, 1, 0, 1, 1, 1, 0, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00001173", "row_id": 1173, "seed_ids": "['magpie_prefill_1173']" }
0.666294
Prefill_1173
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4aa468a3f2e31e95afc272de62c220fe5acf2d57
a7c9b6a582d86528144cdc794650dff71a8075b2
v1.0
instruct
Prefill
Prefill_1223_I
Write a function to reverse a stack using recursion. The stack is represented as a list in Python.
def reverse_stack(stack): """ Reverses the stack using recursion. """ if not stack: return top = stack.pop() reverse_stack(stack) insert_at_bottom(stack, top) def insert_at_bottom(stack, item): """ Helper function to insert an element at the bottom of the stack. """ ...
from solution import reverse_stack def test_reverse_stack_empty(): stack = [] reverse_stack(stack) assert stack == [] def test_reverse_stack_single_element(): stack = [1] reverse_stack(stack) assert stack == [1] def test_reverse_stack_two_elements(): stack = [1, 2] reverse_stack(stack...
[ { "docstring": "Reverses the stack using recursion.", "function_declaration": "def reverse_stack(stack):", "function_name": "reverse_stack", "parameter_list": "(stack)" }, { "docstring": "Helper function to insert an element at the bottom of the stack.", "function_declaration": "def inse...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_stack(stack):\n \"\"\"\n Reverses a stack represented as a list using recursion.\n \"\"\"\n if not stack:\n return\n top = stack.pop()\n reverse_stack(sta...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001223", "row_id": 1223, "seed_ids": "['magpie_prefill_1223']" }
0.588735
Prefill_1223
I
[ "reverse_stack", "insert_at_bottom" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae40004cce155f733007baaaf9fea3254768c01d
f7492467544fb21518566b205d2231b711123088
v1.0
instruct
Prefill
Prefill_1296_I
Write a function to find the maximum subarray sum in a given array of integers. The function should use a divide and conquer approach.
def max_crossing_sum(arr, left, mid, right): """ Helper function to find the maximum sum of the crossing subarray. """ # Include elements on left of mid. left_sum = float('-inf') total = 0 for i in range(mid, left - 1, -1): total += arr[i] if total > left_sum: lef...
import pytest from solution import find_maximum_subarray_sum def test_max_subarray_sum_all_positive(): assert find_maximum_subarray_sum([1, 2, 3, 4, 5]) == 15 def test_max_subarray_sum_mixed(): assert find_maximum_subarray_sum([1, -2, 3, 4, -1, 2, 1, -5, 4]) == 9 def test_max_subarray_sum_all_negative(): ...
[ { "docstring": "Helper function to find the maximum sum of the crossing subarray.", "function_declaration": "def max_crossing_sum(arr, left, mid, right):", "function_name": "max_crossing_sum", "parameter_list": "(arr, left, mid, right)" }, { "docstring": "Returns the maximum sum of the subar...
[ 1, 1, 1, 1, 0, 1, 0, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, l, m, h):\n left_sum = float('-inf')\n sum = 0\n for i in range(m, l - 1, -1):\n sum += arr[i]\n if sum > left_sum:\n left_sum = su...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001296", "row_id": 1296, "seed_ids": "['magpie_prefill_1296']" }
0.761495
Prefill_1296
I
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_subarray_sum" ]
3
[ [ "find_maximum_subarray_sum", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d65f6d6177fe7b65d81f083f37d84f1b271b6415
084c4db61618f1fefc0afbaa945595f080b05a85
v1.0
instruct
Prefill
Prefill_1428_I
Write a function to delete a node from a binary tree in Python. The function should take in the root of the binary tree and the key of the node to be deleted. The function should return the root of the modified tree.
class TreeNode: def __init__(self, key, left=None, right=None): self.key = key self.left = left self.right = right def delete_node(root, key): if root is None: return root if key < root.key: root.left = delete_node(root.left, key) elif key > root.key: ro...
from solution import TreeNode, delete_node def inorder_traversal(root): return inorder_traversal(root.left) + [root.key] + inorder_traversal(root.right) if root else [] def test_delete_leaf_node(): root = TreeNode(5, TreeNode(3), TreeNode(7)) root = delete_node(root, 3) assert inorder_traversal(root) ...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key=0, left=None, right=None):\n self.key = key\n self.left = left\n self.right = right\n\ndef deleteNode(root, key):\n if not ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001428", "row_id": 1428, "seed_ids": "['magpie_prefill_1428']" }
0.497006
Prefill_1428
I
[ "delete_node", "find_min" ]
2
[ [ "delete_node", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c0bb5d38832b381c3189227bb0e01b1b33ff0878
b3dad25367a8f1bb8eed82dae1a74b8d733d49a3
v1.0
instruct
Prefill
Prefill_1576_I
Write a function to sort an array of integers using the merge sort algorithm. The function should return the sorted array. The merge sort algorithm is a divide and conquer algorithm that divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves. The merge() function...
def merge(arr, l, m, r): """ Merges two sub-arrays of arr. First sub-array is arr[l..m] Second sub-array is arr[m+1..r] """ n1 = m - l + 1 n2 = r - m # Create temp arrays L = arr[l:l + n1] R = arr[m + 1:m + 1 + n2] # Merge the temp arrays back into arr[l..r] i = 0 j...
from solution import sort_array def test_sort_array(): assert sort_array([38, 27, 43, 3, 9, 82, 10]) == [3, 9, 10, 27, 38, 43, 82] assert sort_array([12, 11, 13, 5, 6, 7]) == [5, 6, 7, 11, 12, 13] assert sort_array([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert sort_array([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5...
[ { "docstring": "Merges two sub-arrays of arr.\nFirst sub-array is arr[l..m]\nSecond sub-array is arr[m+1..r]", "function_declaration": "def merge(arr, l, m, r):", "function_name": "merge", "parameter_list": "(arr, l, m, r)" }, { "docstring": "Sorts an array using merge sort algorithm", "...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on an array.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2 # Finding the middle of the array\n left_half = ar...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001576", "row_id": 1576, "seed_ids": "['magpie_prefill_1576']" }
0.748007
Prefill_1576
I
[ "merge", "merge_sort", "sort_array" ]
3
[ [ "merge_sort", "merge" ], [ "sort_array", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1ffc4c6fc6eacfa922df13c13893989a8c2f9660
75fccf5b6db51174cd8db12a6716b04539722e4b
v1.0
instruct
Prefill
Prefill_1583_I
Write a function to delete a node from the binary tree. Given the root of the tree and the key to be deleted, delete the node and return the new root.
class TreeNode: def __init__(self, key=0, left=None, right=None): self.key = key self.left = left self.right = right def delete_node(root, key): """ Deletes the node with the specified key from the binary tree rooted at root. Returns the new root of the tree. """ if root...
from solution import TreeNode, delete_node, get_min def tree_to_list(root): """ Utility function to convert binary search tree to sorted list. Useful for validation in tests. """ if root is None: return [] return tree_to_list(root.left) + [root.key] + tree_to_list(root.right) def test_...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.value = key\n\ndef deleteNode(root, key):\n \"\"\"\n Deletes a node with...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00001583", "row_id": 1583, "seed_ids": "['magpie_prefill_1583']" }
0.574395
Prefill_1583
I
[ "delete_node", "get_min" ]
2
[ [ "delete_node", "get_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2e3afe46ef563b0ff4b37e192104f6540921054f
071f9fb3c5473f333a1dc97c333c8cb7ea88aad6
v1.0
instruct
Prefill
Prefill_1695_I
Write a function to check if a number is a Mersenne prime. A Mersenne prime is a prime number that can be written as 2^p - 1 for some integer p. The function should also identify whether the number is a perfect square or a perfect cube. Provide the code in Python.
import math def is_prime(n): """ Returns True if n is prime, else False. """ if n <= 1: return False if n in (2, 3): return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_mersenne_prime def test_is_mersenne_prime(): # Test Mersenne prime numbers assert is_mersenne_prime(3)["mersenne_prime"] == True assert is_mersenne_prime(7)["mersenne_prime"] == True assert is_mersenne_prime(31)["mersenne_prime"] == True # Test non-Mersenne prime number ...
[ { "docstring": "Returns True if n is prime, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a dictionary with the results if n is a Mersenne prime,\na perfect square, or a perfect cube.", "function_...
[ 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is prime, else False.\n \"\"\"\n if n <= 1:\n return False\n if n in (2, 3):\n return True\n if n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001695", "row_id": 1695, "seed_ids": "['magpie_prefill_1695']" }
0.669368
Prefill_1695
I
[ "is_prime", "is_mersenne_prime" ]
2
[ [ "is_mersenne_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15f5a4f3661103caa05c6056ab51322724551ec7
f1d191118d87971d983ff6c98ff1c46227d4ee1a
v1.0
instruct
Prefill
Prefill_1826_I
Write a function to perform a merge sort on an array of integers using a bottom-up approach. The function should take an array of integers as input and return a new array that is sorted in ascending order. Additionally, the function should be able to handle arrays with duplicate values.
def merge_sort_bottom_up(arr): """ Perform a bottom-up merge sort on an array of integers. :param arr: List of integers to sort :return: New list with sorted integers in ascending order """ if len(arr) <= 1: return arr width = 1 n = len(arr) while width < n: ...
from solution import merge_sort_bottom_up def test_merge_sort_bottom_up_empty_array(): assert merge_sort_bottom_up([]) == [] def test_merge_sort_bottom_up_single_element(): assert merge_sort_bottom_up([1]) == [1] def test_merge_sort_bottom_up_two_elements(): assert merge_sort_bottom_up([2, 1]) == [1, 2] ...
[ { "docstring": "Perform a bottom-up merge sort on an array of integers.\n\n:param arr: List of integers to sort\n:return: New list with sorted integers in ascending order", "function_declaration": "def merge_sort_bottom_up(arr):", "function_name": "merge_sort_bottom_up", "parameter_list": "(arr)" ...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort_bottom_up(arr):\n \"\"\"\n Perform a merge sort on an array of integers using a bottom-up approach.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n n = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001826", "row_id": 1826, "seed_ids": "['magpie_prefill_1826']" }
0.771155
Prefill_1826
I
[ "merge_sort_bottom_up", "merge" ]
2
[ [ "merge_sort_bottom_up", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d0b8b6fc06c4756bb4ac107f2fbf635b2d20177
f5435285ff44d3f3946e1d333ffbedf0a596ffdc
v1.0
instruct
Prefill
Prefill_1896_I
Write a function to calculate the number of ways to arrange 'n' distinct items in a circle, considering two arrangements identical if one can be obtained from the other by rotation.
def circular_permutations(n): """ Returns the number of distinct ways to arrange 'n' distinct items in a circle. """ if n <= 0: return 0 elif n == 1: return 1 else: return factorial(n - 1) def factorial(num): """ Helper function to compute the factorial of a give...
from solution import circular_permutations def test_circular_permutations_zero(): assert circular_permutations(0) == 0 def test_circular_permutations_one(): assert circular_permutations(1) == 1 def test_circular_permutations_two(): assert circular_permutations(2) == 1 def test_circular_permutations_thre...
[ { "docstring": "Returns the number of distinct ways to arrange 'n' distinct items in a circle.", "function_declaration": "def circular_permutations(n):", "function_name": "circular_permutations", "parameter_list": "(n)" }, { "docstring": "Helper function to compute the factorial of a given n...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def circular_permutations(n):\n \"\"\"\n Returns the number of ways to arrange n distinct items in a circle,\n considering two arrangements identical if one can be obtained from the ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001896", "row_id": 1896, "seed_ids": "['magpie_prefill_1896']" }
0.637295
Prefill_1896
I
[ "circular_permutations", "factorial" ]
2
[ [ "circular_permutations", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
27e2c1779c05b98e719577cdb15e51726a18a3f9
3dc58a19fdcaac2ca88da8b019fdae0dc8386e79
v1.0
instruct
Prefill
Prefill_1921_I
Write a function to generate all subsequences of a string with removal of consecutive duplicates.
def remove_consecutive_duplicates(s): """ Returns a string by removing consecutive duplicates from the input string s. """ if not s: return s result = [s[0]] for char in s[1:]: if char != result[-1]: result.append(char) return ''.join(result) def all_s...
from solution import remove_consecutive_duplicates, all_subsequences def test_remove_consecutive_duplicates(): assert remove_consecutive_duplicates("aabbcc") == "abc" assert remove_consecutive_duplicates("aaaa") == "a" assert remove_consecutive_duplicates("ab") == "ab" assert remove_consecutive_duplica...
[ { "docstring": "Returns a string by removing consecutive duplicates from the input string s.", "function_declaration": "def remove_consecutive_duplicates(s):", "function_name": "remove_consecutive_duplicates", "parameter_list": "(s)" }, { "docstring": "Returns all unique subsequences of the ...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_subsequences(s: str) -> list:\n \"\"\"\n Generates all subsequences of the given string 's' with removal of consecutive duplicates.\n \"\"\"\n subsequences = set()\n\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00001921", "row_id": 1921, "seed_ids": "['magpie_prefill_1921']" }
0.758462
Prefill_1921
I
[ "remove_consecutive_duplicates", "all_subsequences" ]
2
[ [ "all_subsequences", "remove_consecutive_duplicates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a4508222897c1e37a42814cebb4592e9564154d
1117e06568a943c914dfc75bf802f38e6e81593f
v1.0
instruct
Prefill
Prefill_2000_I
Write a function to filter out invalid ISBN-10 numbers from a list of strings, where a valid ISBN-10 must consist of 10 characters long, with the first 9 characters being digits and the last character being either a digit or an 'X' representing the value 10. Also, the check digit must be valid according to the given IS...
def is_valid_isbn10(isbn): """ Checks if an ISBN-10 number is valid. """ if len(isbn) != 10: return False if not isbn[:9].isdigit(): return False if not (isbn[9].isdigit() or isbn[9] == 'X'): return False # calculate the checksum using ISBN-10 validation me...
from solution import is_valid_isbn10, filter_valid_isbn10 def test_is_valid_isbn10_valid(): assert is_valid_isbn10("0306406152") == True assert is_valid_isbn10("0471117099") == True assert is_valid_isbn10("123456789X") == True def test_is_valid_isbn10_invalid_length(): assert is_valid_isbn10("03064061...
[ { "docstring": "Checks if an ISBN-10 number is valid.", "function_declaration": "def is_valid_isbn10(isbn):", "function_name": "is_valid_isbn10", "parameter_list": "(isbn)" }, { "docstring": "Filters out valid ISBN-10 numbers from a list of strings.", "function_declaration": "def filter_...
[ 1, 1, 0, 1, 1, 0, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_isbn10(isbn):\n \"\"\"\n Validate an ISBN-10 number.\n \"\"\"\n\n if len(isbn) != 10:\n return False\n\n # Check the first 9 characters are all digits\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002000", "row_id": 2000, "seed_ids": "['magpie_prefill_2000']" }
0.595184
Prefill_2000
I
[ "is_valid_isbn10", "filter_valid_isbn10" ]
2
[ [ "filter_valid_isbn10", "is_valid_isbn10" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8bd8bae89a43858b2ba4c7805ac4adf0fef51cf8
08f88cabdb9cb7b8ce878cbb49d783423c6979bd
v1.0
instruct
Prefill
Prefill_2159_I
Write a function to calculate the sum of all prime numbers within a given range. The range is specified using two integers, `start` and `end`. The function should return the sum of all prime numbers between `start` and `end`, inclusive. If there are no prime numbers in the range, the function should return 0.
def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_primes_in_range(start, end): """ Returns the sum of all prime numbers between start and end, inclusive. If there are no prime numbers in ...
from solution import sum_of_primes_in_range def test_sum_of_primes_within_small_range(): assert sum_of_primes_in_range(10, 20) == 60 # primes are 11, 13, 17, 19 def test_sum_of_primes_within_large_range(): assert sum_of_primes_in_range(1, 100) == 1060 def test_no_primes_in_range(): assert sum_of_primes_...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between start and end, inclusive.\nIf there are no prime numbers in the range, returns 0.", "function_declaration"...
[ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ==...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002159", "row_id": 2159, "seed_ids": "['magpie_prefill_2159']" }
0.614046
Prefill_2159
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
867f6f8cb36a3dd63341c81bdc23aeecc4bb7e46
616f537b4262a382c48c189f951088282f561bdc
v1.0
instruct
Prefill
Prefill_2186_I
Write a function to solve and display the solution to a given Sudoku puzzle.
def is_valid(board, row, col, num): """ Check if placing num in board[row][col] is valid according to Sudoku rules. """ for i in range(9): if board[row][i] == num or board[i][col] == num: return False if board[(row // 3) * 3 + i // 3][(col // 3) * 3 + i % 3] == num: ...
from solution import solve_sudoku, print_board def test_sudoku_solver(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0...
[ { "docstring": "Check if placing num in board[row][col] is valid according to Sudoku rules.", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Solve the given Sudoku puzzle using backtrac...
[ 0, 1, 0, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n Check if it's valid to place the number at board[row][col].\n \"\"\"\n for i in range(9):\n if board[row][i] == num or board[...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002186", "row_id": 2186, "seed_ids": "['magpie_prefill_2186']" }
0.466845
Prefill_2186
I
[ "is_valid", "solve_sudoku", "print_board" ]
3
[ [ "solve_sudoku", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e1899f8eb4f93ea6d5a9ad7870a0e388555471c
e798260c3a67b393fff543d79adb40ac4cc1befa
v1.0
instruct
Prefill
Prefill_2205_I
Write a function to compute the nth Fibonacci number using a recursive approach. The function should also include a check function to verify the correctness of the solution with provided data points.
def fibonacci(n): """ Returns the nth Fibonacci number using recursion. """ if n <= 0: return 0 elif n == 1: return 1 else: return fibonacci(n - 1) + fibonacci(n - 2) def check_fibonacci(): """ Verify the correctness of the fibonacci function with provided da...
from solution import fibonacci, check_fibonacci def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_recursive(): assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 ...
[ { "docstring": "Returns the nth Fibonacci number using recursion.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Verify the correctness of the fibonacci function with provided data points.", "function_declaration": ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number using a recursive approach.\n \"\"\"\n if n <= 0:\n raise ValueError(\"Input must be a positive integer.\")\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002205", "row_id": 2205, "seed_ids": "['magpie_prefill_2205']" }
0.690441
Prefill_2205
I
[ "fibonacci", "check_fibonacci" ]
2
[ [ "check_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c94240c9084919c9645bf4b5087f71f1ffe47e7
e3a055751a253017927ed5da0a4902ac16753eb0
v1.0
instruct
Prefill
Prefill_2211_I
Write a function to generate the longest palindromic substring in a given string. For example, for input "babad", the function should return "bab" or "aba" since both are the longest palindromic substrings. The function should be efficient and work for strings of various lengths.
def longest_palindromic_substring(s): """ Returns the longest palindromic substring in the provided string. """ n = len(s) if n == 0: return "" start = 0 end = 0 for i in range(n): len1 = expand_from_center(s, i, i) len2 = expand_from_center(s, i, i + 1) ...
from solution import longest_palindromic_substring def test_longest_palindromic_substring(): assert longest_palindromic_substring("babad") in ["bab", "aba"] assert longest_palindromic_substring("cbbd") == "bb" assert longest_palindromic_substring("") == "" assert longest_palindromic_substring("a") == "...
[ { "docstring": "Returns the longest palindromic substring in the provided string.", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def expand_from_...
[ 0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring in a given string.\n \"\"\"\n if len(s) <= 1:\n return s\n\n start, max_length...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002211", "row_id": 2211, "seed_ids": "['magpie_prefill_2211']" }
0.830489
Prefill_2211
I
[ "longest_palindromic_substring", "expand_from_center" ]
2
[ [ "longest_palindromic_substring", "expand_from_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c67b12219906840d730ff9f486a98275cb5fe1e
a776c93565332771f6e3297685b914dbdd6dff5b
v1.0
instruct
Prefill
Prefill_2261_I
Write a function to calculate the factorial of a number using both iterative and recursive approaches in Python. Compare their performance and speed for large numbers.
import time def factorial_iterative(n): """ Returns the factorial of a number using an iterative approach. """ if n < 0: raise ValueError("Factorial is not defined for negative numbers") result = 1 for i in range(2, n + 1): result *= i return result def factorial_recursive(...
import pytest from solution import factorial_iterative, factorial_recursive, compare_performance def test_factorial_iterative(): assert factorial_iterative(0) == 1 assert factorial_iterative(1) == 1 assert factorial_iterative(5) == 120 assert factorial_iterative(10) == 3628800 def test_factorial_recur...
[ { "docstring": "Returns the factorial of a number using an iterative approach.", "function_declaration": "def factorial_iterative(n):", "function_name": "factorial_iterative", "parameter_list": "(n)" }, { "docstring": "Returns the factorial of a number using a recursive approach.", "func...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef factorial_iterative(n):\n \"\"\"\n Calculate factorial using iterative approach.\n \"\"\"\n result = 1\n for i in range(2, n + 1):\n result *= i\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002261", "row_id": 2261, "seed_ids": "['magpie_prefill_2261']" }
0.691473
Prefill_2261
I
[ "factorial_iterative", "factorial_recursive", "compare_performance" ]
3
[ [ "compare_performance", "factorial_iterative" ], [ "compare_performance", "factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
83bce12651e2b2e6d220c0130c95599c03e6c6e5
0bf37e7bd34f75df6927c363d968adb7d6e72695
v1.0
instruct
Prefill
Prefill_2329_I
Write a function to generate all possible palindromic partitions of a given string `s`. A palindromic partition cuts the string into some substrings which are all palindromes. Return a list of all possible partitions.
def is_palindrome(s): return s == s[::-1] def palindromic_partition(s): def find_partitions(start, path): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): path.append(s[...
from solution import palindromic_partition def test_palindromic_partition_empty_string(): assert palindromic_partition('') == [[]] def test_palindromic_partition_single_character(): assert palindromic_partition('a') == [['a']] def test_palindromic_partition_two_characters(): assert palindromic_partition(...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindromic_partition(s):", "function_name": "palindromic_partition", "parameter_list": "(s)" }, ...
[ 0, 1, 1, 0, 1, 1, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(sub):\n \"\"\"\n Check if the provided substring is a palindrome.\n \"\"\"\n return sub == sub[::-1]\n\ndef palindromic_partitions(s):\n \"\"\"\n Generate ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002329", "row_id": 2329, "seed_ids": "['magpie_prefill_2329']" }
0.73709
Prefill_2329
I
[ "is_palindrome", "palindromic_partition" ]
2
[ [ "palindromic_partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce642e083bdac8ff3ec009332227a43ccd66acfa
8bb6f34d17559edb22cc2879314bb9971ec445ba
v1.0
instruct
Prefill
Prefill_2412_I
Write a function to calculate the sum of all prime numbers up to a given number `n`. For example, if `n` is 10, the prime numbers up to 10 are 2, 3, 5, 7, so the function should return 17.
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def sum_of_primes(n): retu...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(17) == True assert is_prime(1) == False...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_primes(n):", "function_name": "sum_of_primes", "parameter_list": "(n)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= nu...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002412", "row_id": 2412, "seed_ids": "['magpie_prefill_2412']" }
0.67836
Prefill_2412
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e6b5807855fdafa2909a3627092c4431cc85575
bcbf55d5f558fea2ee1c6476774a2a03eac7baa8
v1.0
instruct
Prefill
Prefill_2514_I
Write a function to sort an array of integers using the merge sort algorithm and return the sorted array.
def merge_sort(arr): """ Sorts an array of integers using the merge sort algorithm and returns the sorted array. Parameters: arr (list): The array of integers to be sorted. Returns: list: The sorted array. """ if len(arr) <= 1: return arr # Split the array into...
from solution import merge_sort def test_merge_sort_empty_array(): assert 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(): ass...
[ { "docstring": "Sorts an array of integers using the merge sort algorithm and returns the sorted array.\n\nParameters:\narr (list): The array of integers to be sorted.\n\nReturns:\nlist: The sorted array.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_lis...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array of integers using the merge sort algorithm and returns the sorted array.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n # S...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002514", "row_id": 2514, "seed_ids": "['magpie_prefill_2514']" }
0.888493
Prefill_2514
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63e39e2bd5fff1cfe26fec9f0a094e52b9e91a37
3491d7d5ce7f16e1cc18507c5f387551a10c35d1
v1.0
instruct
Prefill
Prefill_2602_I
Write a function to solve the Maximum Subarray problem using a divide and conquer approach.
def max_crossing_subarray(arr, left, mid, right): """ Helper function to find the maximum subarray sum crossing the midpoint. """ left_sum = float('-inf') max_left = mid total = 0 for i in range(mid, left - 1, -1): total += arr[i] if total > left_sum: left_sum = ...
from solution import find_maximum_subarray def test_single_element_array(): assert find_maximum_subarray([1]) == (1, 0, 0) assert find_maximum_subarray([-1]) == (-1, 0, 0) def test_all_positive_elements(): assert find_maximum_subarray([1, 2, 3, 4, 5]) == (15, 0, 4) def test_all_negative_elements(): a...
[ { "docstring": "Helper function to find the maximum subarray sum crossing the midpoint.", "function_declaration": "def max_crossing_subarray(arr, left, mid, right):", "function_name": "max_crossing_subarray", "parameter_list": "(arr, left, mid, right)" }, { "docstring": "Function to find the...
[ 0, 0, 1, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, low, mid, high):\n \"\"\"\n Helper function to find the maximum possible sum in arr[] such that\n the sum is also a part of the crossing subarray.\n \"\"...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00002602", "row_id": 2602, "seed_ids": "['magpie_prefill_2602']" }
0.804754
Prefill_2602
I
[ "max_crossing_subarray", "max_subarray", "find_maximum_subarray" ]
3
[ [ "find_maximum_subarray", "max_subarray" ], [ "max_subarray", "max_crossing_subarray" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2044d1fd1146600f796e813545866588d5e9b920
57066a52898ae156887dc90533df3ec155f200b7
v1.0
instruct
Prefill
Prefill_2658_I
Write a function to sort an array in increasing order using the merge sort algorithm.
def merge_sort(arr): """ Sorts an array in increasing order using the merge sort algorithm. :param arr: List of integers to be sorted :return: List of integers sorted in increasing order """ if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) ...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_array(): assert me...
[ { "docstring": "Sorts an array in increasing order using the merge sort algorithm.\n\n:param arr: List of integers to be sorted\n:return: List of integers sorted in increasing order", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array in increasing order using the merge sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = ar...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002658", "row_id": 2658, "seed_ids": "['magpie_prefill_2658']" }
0.889828
Prefill_2658
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9834239b0405623a5558fdb0d27b32a430cda3c7
055b27cfc773f7d3138ec513862c9844b6955478
v1.0
instruct
Prefill
Prefill_2903_I
Write a function to select the optimal route for a delivery truck using a given set of delivery points in a city. The function should take a list of delivery points as input and return the shortest route that the delivery truck can follow to complete all deliveries.
import itertools def calculate_distance(point1, point2): """ Calculate the Euclidean distance between two points. Each point is represented as a tuple (x, y). """ return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) ** 0.5 def total_route_distance(route): """ Calculate the tota...
from solution import optimal_route def test_optimal_route_square(): delivery_points = [(0, 0), (0, 1), (1, 1), (1, 0)] route = optimal_route(delivery_points) assert route == ((0, 0), (0, 1), (1, 1), (1, 0)) or route == ((1, 0), (0, 0), (0, 1...
[ { "docstring": "Calculate the Euclidean distance between two points.\nEach point is represented as a tuple (x, y).", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Calculate the...
[ 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef calculate_distance(point1, point2):\n \"\"\"\n Returns the distance between two points.\n \"\"\"\n return ((point1[0] - point2[0])**2 + (...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002903", "row_id": 2903, "seed_ids": "['magpie_prefill_2903']" }
0.573783
Prefill_2903
I
[ "calculate_distance", "total_route_distance", "optimal_route" ]
3
[ [ "total_route_distance", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e5b03e8d4ada05deede4cbdb3943966be7c4092
d8f3d9ccfd67abe31a216a46466a6e45bc60e19d
v1.0
instruct
Prefill
Prefill_2917_I
Write a function to solve the Sudoku puzzle. The function should take a 2D list representing the Sudoku board and return the solved board. The function should follow the standard rules for Sudoku: no row, column, or 3x3 sub-grid can contain duplicate digits from 1 to 9.
def solve_sudoku(board): """ Solves the Sudoku puzzle using backtracking. :param board: 2D list representing the Sudoku board with empty cells as 0s :return: Solved 2D list of the Sudoku board """ if solve(board): return board else: return "No solution exists" def s...
from solution import solve_sudoku def test_sudoku_solver(): board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0,...
[ { "docstring": "Solves the Sudoku puzzle using backtracking.\n\n:param board: 2D list representing the Sudoku board with empty cells as 0s\n:return: Solved 2D list of the Sudoku board", "function_declaration": "def solve_sudoku(board):", "function_name": "solve_sudoku", "parameter_list": "(board)" ...
[ 1, 0, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_sudoku(board):\n def is_valid(board, row, col, num):\n for i in range(9):\n if board[row][i] == num or board[i][col] == num or \\\n board[row // 3...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002917", "row_id": 2917, "seed_ids": "['magpie_prefill_2917']" }
0.488911
Prefill_2917
I
[ "solve_sudoku", "solve", "find_empty", "is_valid" ]
4
[ [ "solve", "find_empty" ], [ "solve", "is_valid" ], [ "solve_sudoku", "solve" ] ]
3
[]
false
[]
false
pytest
true
[]
true
dad6aca4acd2374d3bc8a3d3a829ea71db561f6a
ab5d765a7227535edbd8b49756b3715d9993c4ce
v1.0
instruct
Prefill
Prefill_2930_I
Write a function to find the next node in the InOrder Traversal of a Binary Tree for a given node. The function should return `None` if there is no such node.
class TreeNode: def __init__(self, value=0, left=None, right=None, parent=None): self.value = value self.left = left self.right = right self.parent = parent def find_inorder_successor(node): """ Returns the in-order successor of the given node in a binary tree. """ i...
from solution import TreeNode, find_inorder_successor def test_node_with_right_child(): root = TreeNode(20) node1 = TreeNode(10, parent=root) node2 = TreeNode(30, parent=root) root.left = node1 root.right = node2 node3 = TreeNode(25, parent=node2) node4 = TreeNode(35, parent=node2) node...
[]
[ 1, 1, 1, 1, 0, 1, 0, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None, parent=None):\n self.value = value\n self.left = left\n self.right = right\n self.parent = ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002930", "row_id": 2930, "seed_ids": "['magpie_prefill_2930']" }
0.563753
Prefill_2930
I
[ "find_inorder_successor", "get_leftmost_child" ]
2
[ [ "find_inorder_successor", "get_leftmost_child" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7665954eb30a6497028922ae1b08ff49805e531f
dd28a86b54e606e6ac4edfe05cf6a350a7003796
v1.0
instruct
Prefill
Prefill_3136_I
Write a function to generate all possible paliindrome combinations of a given string. A palindrome is a word, phrase, number, or other sequences of characters which reads the same forward and backward (ignoring spaces, punctuation, and capitalization).
def is_palindrome(s): """ Check if a given string is a palindrome. """ return s == s[::-1] def generate_palindrome_combinations(s): """ Generate all possible palindrome combinations of a given string. """ def backtrack(start, path, result): if start == len(s): result...
from solution import generate_palindrome_combinations def test_single_letter(): assert generate_palindrome_combinations("a") == [["a"]] def test_two_letters_palindrome(): assert generate_palindrome_combinations("aa") == [["a", "a"], ["aa"]] def test_two_letters_non_palindrome(): assert generate_palindrom...
[ { "docstring": "Check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Generate all possible palindrome combinations of a given string.", "function_declaration": "def generat...
[ 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_palindrome_combinations(s):\n \"\"\"\n Function to generate all possible palindrome combinations from the given string.\n \n Parameters:\n s (str): The input strin...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00003136", "row_id": 3136, "seed_ids": "['magpie_prefill_3136']" }
0.73766
Prefill_3136
I
[ "is_palindrome", "generate_palindrome_combinations" ]
2
[ [ "generate_palindrome_combinations", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96ddfc2f24978051caf130e4435eb89ac0e93760
d31d159292bf777aefa2495b397b98523663e90e
v1.0
instruct
Prefill
Prefill_3228_I
Write a function to find the largest prime number within a given range. The range will be provided as two integers, `start` and `end`. The function should return the largest prime number within this range, including both endpoints. If there are no prime numbers in the range, the function should return `None`.
import math def is_prime(n): """ Utility function to check if n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return F...
from solution import largest_prime_in_range def test_largest_prime_in_typical_range(): assert largest_prime_in_range(10, 50) == 47 def test_largest_prime_in_single_prime_range(): assert largest_prime_in_range(25, 29) == 29 def test_largest_prime_with_no_prime_in_range(): assert largest_prime_in_range(1, ...
[ { "docstring": "Utility function to check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the largest prime number within the given range.\nIf no prime number is found, returns None.", "...
[ 1, 1, 0, 1, 1, 1, 0, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Utility function to check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003228", "row_id": 3228, "seed_ids": "['magpie_prefill_3228']" }
0.615721
Prefill_3228
I
[ "is_prime", "largest_prime_in_range" ]
2
[ [ "largest_prime_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d8698ed7eed906e92c606cfab3acf0bb1d5656b1
ec92853006e13065b86f41447530ec6c11e9d40d
v1.0
instruct
Prefill
Prefill_3247_I
Write a function to iterate through a list of strings, find the longest palindromic substring in each string, and return a list of these substrings.
def longest_palindromic_substring(s): """ Returns the longest palindromic substring of s. """ def expand_around_center(s, left, right): while left >= 0 and right < len(s) and s[left] == s[right]: left -= 1 right += 1 return s[left + 1:right] longest = "" ...
from solution import longest_palindromic_substrings def test_single_palindrome(): input_list = ["babad"] expected_output = ["bab"] assert longest_palindromic_substrings(input_list) == expected_output def test_multiple_palindromes(): input_list = ["babad", "cbbd"] expected_output = ["bab", "bb"] ...
[ { "docstring": "Returns the longest palindromic substring of s.", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter_list": "(s)" }, { "docstring": "Returns a list of the longest palindromic substrings from each input...
[ 1, 0, 1, 1, 1, 0, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring(s: str) -> str:\n \"\"\"\n This function returns the longest palindromic substring in s.\n \"\"\"\n def expand_around_center(left: int, right: in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003247", "row_id": 3247, "seed_ids": "['magpie_prefill_3247']" }
0.87319
Prefill_3247
I
[ "longest_palindromic_substring", "longest_palindromic_substrings" ]
2
[ [ "longest_palindromic_substrings", "longest_palindromic_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
081b2e3acb0732d3bafe946b2ae208a79ef5661e
6bf5cfee17624694c71b2ffa37020fbbfe82f88f
v1.0
instruct
Prefill
Prefill_3416_I
Write a function to validate a date in the format "YYYY-MM-DD". The function should check if the date is valid considering leap years and the number of days in each month. Assume the input date is a string.
def is_leap_year(year): """ Check if a year is a leap year. """ return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) def validate_date(date_str): """ Validate a date string in the format YYYY-MM-DD. """ if len(date_str) != 10 or date_str[4] != '-' or date_str[7] != '-': ...
from solution import validate_date def test_valid_dates(): assert validate_date("2020-02-29") == True assert validate_date("2021-12-31") == True assert validate_date("2000-01-01") == True def test_invalid_format(): assert validate_date("20200229") == False assert validate_date("2020-2-29") == Fals...
[ { "docstring": "Check if a year is a leap year.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Validate a date string in the format YYYY-MM-DD.", "function_declaration": "def validate_date(date_str):", ...
[ 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import datetime\n\ndef is_valid_date(date_str):\n \"\"\"\n Validates a date string in the format \"YYYY-MM-DD\".\n \n Args:\n date_str (str): The date string to v...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003416", "row_id": 3416, "seed_ids": "['magpie_prefill_3416']" }
0.791146
Prefill_3416
I
[ "is_leap_year", "validate_date" ]
2
[ [ "validate_date", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2df75280d0b1810e5fa5db3c7a1d8036d2725e80
c3b093b69a825aee1a0c999bc98e90d409dfdb14
v1.0
instruct
Prefill
Prefill_3668_I
Write a function to detect if a binary tree is a subtree of another binary tree.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(root, subRoot): """ Determines if subRoot is a subtree of root. Args: root (TreeNode): The root of the main binary tree. subRoot (TreeNode...
from solution import TreeNode, is_subtree def test_is_subtree(): # Tree 1 root = TreeNode(3) root.left = TreeNode(4) root.right = TreeNode(5) root.left.left = TreeNode(1) root.left.right = TreeNode(2) # Tree 2 subRoot = TreeNode(4) subRoot.left = TreeNode(1) subRoot.right = Tre...
[]
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 is_subtree(s, t):\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003668", "row_id": 3668, "seed_ids": "['magpie_prefill_3668']" }
0.710964
Prefill_3668
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
65de0ae438d6edce0d40bd19d4be798708aadbe8
e381fbab2c939879ece93de7cb80d7679705221a
v1.0
instruct
Prefill
Prefill_3704_I
Write a function to find the minimum cost to connect all points. The function takes a list of points, where each point is represented as a tuple (x, y), and returns the minimum cost to connect all points. You can only connect points that are within a specified radius. The cost to connect two points is the Manhattan dis...
import heapq def manhattan_distance(p1, p2): return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def min_cost_connect_points(points): if not points: return 0 n = len(points) connected = [False] * n min_heap = [(0, 0)] # (cost, point_index) total_cost = 0 while min_heap: ...
from solution import min_cost_connect_points def test_min_cost_connect_points_example(): points = [(0, 0), (2, 2), (3, 10), (5, 2), (7, 0)] assert min_cost_connect_points(points) == 20 def test_min_cost_connect_points_two_points(): points = [(0, 0), (1, 1)] assert min_cost_connect_points(points) == 2 ...
[ { "docstring": null, "function_declaration": "def manhattan_distance(p1, p2):", "function_name": "manhattan_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def min_cost_connect_points(points):", "function_name": "min_cost_connect_points", ...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minCostConnectPoints(points):\n \"\"\"\n Returns the minimum cost to connect all points.\n Points are represented as a list of tuples (x, y).\n \"\"\"\n N =...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00003704", "row_id": 3704, "seed_ids": "['magpie_prefill_3704']" }
0.578415
Prefill_3704
I
[ "manhattan_distance", "min_cost_connect_points" ]
2
[ [ "min_cost_connect_points", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ade1869595c9ea7c2efb50836db4e8d8b74595e
689c954098169e6625e60d245043b892f51ac44d
v1.0
instruct
Prefill
Prefill_3710_I
Write a function to solve a Sudoku puzzle. The Sudoku puzzle is represented as a 2D list where 0 represents an empty cell.
def is_valid(board, row, col, num): # Check if num is valid at board[row][col] for i in range(9): if board[row][i] == num or board[i][col] == num: return False box_row_start = (row // 3) * 3 box_col_start = (col // 3) * 3 for i in range(3): for j in range(3): ...
from solution import solve_sudoku, is_valid def test_full_sudoku_solved(): board = [ [5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], ...
[ { "docstring": null, "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": null, "function_declaration": "def solve_sudoku(board):", "function_name": "solve_sudoku", "parameter_list...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n This function checks whether it will be valid to assign num to the given row, col.\n \"\"\"\n # Check the row and column\n for i ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003710", "row_id": 3710, "seed_ids": "['magpie_prefill_3710']" }
0.526637
Prefill_3710
I
[ "is_valid", "solve_sudoku", "find_empty_position" ]
3
[ [ "solve_sudoku", "find_empty_position" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9e85c953a5be3e6d7b802521918a58d80805bb7b
a504465d81048690f3c77538409889d2ee992e8f
v1.0
instruct
Prefill
Prefill_3712_I
Write a function to find the smallest prime number greater than a given integer `n`. Your function should take an integer `n` as input and return the smallest prime number greater than `n`. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
def is_prime(num): """Check if a number is prime.""" if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_divisor = int(num ** 0.5) + 1 for d in range(3, max_divisor, 2): if num % d == 0: return False return True de...
from solution import is_prime, smallest_prime_greater_than def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_smallest_prime_greater_than(): assert smallest_prime_greater_than(...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find the smallest prime number greater than n.", "function_declaration": "def smallest_prime_greater_than(n):", "funct...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n wh...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003712", "row_id": 3712, "seed_ids": "['magpie_prefill_3712']" }
0.618372
Prefill_3712
I
[ "is_prime", "smallest_prime_greater_than" ]
2
[ [ "smallest_prime_greater_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1125af7a6cc8005da7c7c90c0e058bbd53b3d66c
0115a74bd85ae343c003da5b8e0818ca02897077
v1.0
instruct
Prefill
Prefill_3777_I
Write a function to find the longest palindromic substring in a given string s. Examples: `longest_palindrome("babad")` should return `"bab"` or `"aba"`, and `longest_palindrome("cbbd")` should return `"bb"`. Discuss the algorithmic approach and then provide the Python code.
def longest_palindrome(s): """ Finds the longest palindromic substring in the given string `s`. Args: s (str): The input string. Returns: str: The longest palindromic substring. """ if not s or len(s) == 1: return s start, end = 0, 0 for i in range(len...
from solution import longest_palindrome def test_longest_palindrome_basic(): assert longest_palindrome("babad") in ["bab", "aba"] assert longest_palindrome("cbbd") == "bb" def test_longest_palindrome_single_char(): assert longest_palindrome("a") == "a" def test_longest_palindrome_two_same_chars(): as...
[ { "docstring": "Finds the longest palindromic substring in the given string `s`.\n\nArgs:\ns (str): The input string.\n\nReturns:\nstr: The longest palindromic substring.", "function_declaration": "def longest_palindrome(s):", "function_name": "longest_palindrome", "parameter_list": "(s)" }, { ...
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Prefill-43K_sanitized_prepared1_results_combined.jsonl", "solution_code": "def longest_palindrome(s):\n \"\"\"\n Finds the longest palindromic substring in a given string.\n \"\"\"\n if not s:\n return \"\"\n\n n = len(...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003777", "row_id": 3777, "seed_ids": "['magpie_prefill_3777']" }
0.823755
Prefill_3777
I
[ "longest_palindrome", "expand_around_center" ]
2
[ [ "longest_palindrome", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae4ff0a0bed10eb499b6398ad276311df869f20e
a69ef3f938b1cbf65c83dbbd66c7f04e3a19a1d6
v1.0
instruct
Prefill
Prefill_3808_I
Write a function to calculate the number of unique IP addresses from a given list of IP addresses, where you need to filter out any IP addresses that are invalid. An invalid IP address consists of at least one segment that contains characters other than digits or segments with more than three digits.
import re def is_valid_ip(ip): """ Validates if the given IP address is valid. """ segments = ip.split(".") if len(segments) != 4: return False for segment in segments: if not segment.isdigit() or not (0 <= int(segment) <= 255) or len(segment) > 3: return False ...
from solution import unique_valid_ips, is_valid_ip def test_valid_ip(): assert is_valid_ip("192.168.1.1") == True assert is_valid_ip("255.255.255.255") == True assert is_valid_ip("0.0.0.0") == True def test_invalid_ip(): assert is_valid_ip("256.256.256.256") == False assert is_valid_ip("192.168.1"...
[ { "docstring": "Validates if the given IP address is valid.", "function_declaration": "def is_valid_ip(ip):", "function_name": "is_valid_ip", "parameter_list": "(ip)" }, { "docstring": "Returns the count of unique valid IP addresses from the given list.", "function_declaration": "def uni...
[ 0, 0, 0, 0, 0, 1, 1, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_ip(ip):\n segments = ip.split('.')\n if len(segments) != 4:\n return False\n for segment in segments:\n if not segment.isdigit() or len(segment) > 3:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003808", "row_id": 3808, "seed_ids": "['magpie_prefill_3808']" }
0.548171
Prefill_3808
I
[ "is_valid_ip", "unique_valid_ips" ]
2
[ [ "unique_valid_ips", "is_valid_ip" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85b73f3601d7a31a656fa21e6acd06796184dcb3
25e77e370bc45c239313ec171241ff15bba5b018
v1.0
instruct
Prefill
Prefill_3885_I
Write a function to check if a binary tree is a binary search tree (BST). In a BST, each node has a key, a left child, and a right child. For a node x, all nodes in its left subtree have keys less than x's key, all nodes in its right subtree have keys greater than x's key, and x has no more than two children.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def is_bst_util(node, left, right): # Base case: empty trees are BST by definition if node is None: return True # Invalid BST if outside valid range if node.val <= left or node...
from solution import TreeNode, is_bst def test_bst_empty_tree(): assert is_bst(None) == True def test_bst_single_node(): node = TreeNode(10) assert is_bst(node) == True def test_bst_valid_small_tree(): root = TreeNode(10) root.left = TreeNode(5) root.right = TreeNode(15) assert is_bst(roo...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key, left=None, right=None):\n self.key = key\n self.left = left\n self.right = right\n\ndef is_bst(node, min_key=float('-inf'), m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003885", "row_id": 3885, "seed_ids": "['magpie_prefill_3885']" }
0.680449
Prefill_3885
I
[ "is_bst_util", "is_bst" ]
2
[ [ "is_bst", "is_bst_util" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b7f04aa41f380cfcf697d6d5d70280757e9a5bc1
cc683af030fda4e84ffb9b639fa39047ab05cee3
v1.0
instruct
Prefill
Prefill_3921_I
Write a function to sort a linked list in ascending order. You should not use any built-in sorting functions. Explain your approach and any trade-offs you might consider when writing such a function.
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def merge_sort(head): if not head or not head.next: return head # Split the list into two halves slow, fast = head, head.next while fast and fast.next: slow = slow.next ...
from solution import ListNode, sort_linked_list def linked_list_to_list(node): """ Helper function to convert linked list to Python list for easy comparison """ result = [] while node: result.append(node.val) node = node.next return result def test_empty_list(): assert sort_linked_...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 find_middle(head):\n slow = head\n fast = head.next\n while fast a...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00003921", "row_id": 3921, "seed_ids": "['magpie_prefill_3921']" }
0.593555
Prefill_3921
I
[ "merge_sort", "merge_two_sorted_lists", "sort_linked_list" ]
3
[ [ "merge_sort", "merge_two_sorted_lists" ], [ "sort_linked_list", "merge_sort" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
65ebf1b07199937522a1c107a51de124224b255a
4c8f3979dbfa024310d5a860542bb38bb38d75cc
v1.0
instruct
Prefill
Prefill_3970_I
Write a function to calculate the number of days in a given year. The function should take into account leap years and the transition from the Julian calendar to the Gregorian calendar, which occurred in 1582 with the adoption of the Gregorian calendar in most countries in 1582. The Gregorian calendar skips two的日子 in l...
def is_leap_year(year): """ Helper function to determine if a year is a leap year. Supports both Julian and Gregorian calendar system. """ if year <= 1582: # Julian calendar leap year rule return year % 4 == 0 else: # Gregorian calendar leap year rule return (year...
from solution import days_in_year def test_days_in_julian_leap_year(): assert days_in_year(1500) == 366 # 1500 is a leap year in Julian calendar def test_days_in_julian_common_year(): assert days_in_year(1501) == 365 # 1501 is not a leap year in Julian calendar def test_days_in_gregorian_leap_year(): a...
[ { "docstring": "Helper function to determine if a year is a leap year.\nSupports both Julian and Gregorian calendar system.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Calculate the number of days in a gi...
[ 0, 1, 0, 1, 0, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Returns True if the given year is a leap year, taking into account the transition from the Julian\n calendar to the Gregorian calendar in 1582. The...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003970", "row_id": 3970, "seed_ids": "['magpie_prefill_3970']" }
0.61072
Prefill_3970
I
[ "is_leap_year", "days_in_year" ]
2
[ [ "days_in_year", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a149a42d0b5f4ecb0aa89bb835117de89a24d895
dc1d1290b2cd52e623236f17b8983566f227b313
v1.0
instruct
Prefill
Prefill_4025_I
Write a function to generate a Fibonacci sequence up to a number n, and then find the sum of all even numbers in the Fibonacci sequence.
def fibonacci_sequence_up_to_n(n): """ Generates Fibonacci sequence up to number n (inclusive). :param n: The upper limit of the Fibonacci sequence. :return: A list containing the Fibonacci sequence up to n. """ fib_sequence = [0, 1] while fib_sequence[-1] + fib_sequence[-2] <= n: ...
from solution import fibonacci_sequence_up_to_n, sum_of_even_fibonacci_numbers def test_fibonacci_sequence_up_to_n(): assert fibonacci_sequence_up_to_n(10) == [0, 1, 1, 2, 3, 5, 8] assert fibonacci_sequence_up_to_n(0) == [0, 1] assert fibonacci_sequence_up_to_n(1) == [0, 1, 1] assert fibonacci_sequence...
[ { "docstring": "Generates Fibonacci sequence up to number n (inclusive).\n\n:param n: The upper limit of the Fibonacci sequence.\n:return: A list containing the Fibonacci sequence up to n.", "function_declaration": "def fibonacci_sequence_up_to_n(n):", "function_name": "fibonacci_sequence_up_to_n", ...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Generate a Fibonacci sequence up to a number n and return the sequence.\n \"\"\"\n fib_sequence = []\n a, b = 0, 1\n while a <= n:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004025", "row_id": 4025, "seed_ids": "['magpie_prefill_4025']" }
0.625256
Prefill_4025
I
[ "fibonacci_sequence_up_to_n", "sum_of_even_fibonacci_numbers" ]
2
[ [ "sum_of_even_fibonacci_numbers", "fibonacci_sequence_up_to_n" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92dfd60149b087687fb88219b6b8ddd2050c0b05
0a0d4daf71081cda033fc95842e9d62860ea3d11
v1.0
instruct
Prefill
Prefill_4037_I
Write a function to traverse a binary search tree in a specific manner. It should maintain the balance property of the tree after each insertion and deletion. The function should insert and delete nodes while ensuring the tree remains a valid binary search tree.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): """ Inserts a key into BST and returns the root of the modified tree. """ if root is None: return TreeNode(key) if key < root.val: root.left ...
from solution import TreeNode, insert, delete_node, in_order_traversal def test_insert_single_node(): root = None root = insert(root, 10) assert in_order_traversal(root) == [10] def test_insert_multiple_nodes(): root = None keys = [20, 10, 30, 5, 15, 25, 35] for key in keys: root = ins...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key, left=None, right=None):\n self.key = key\n self.left = left\n self.right = right\n\nclass BST:\n def __init__(self):\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004037", "row_id": 4037, "seed_ids": "['magpie_prefill_4037']" }
0.649941
Prefill_4037
I
[ "insert", "find_min", "delete_node", "in_order_traversal" ]
4
[ [ "delete_node", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b9b2c40b2fd0241355c6f7b727a79a20879bf83b
6d9fcddcd7f4403187e32c1fa8c53ec9b7ecaa59
v1.0
instruct
Prefill
Prefill_4079_I
Write a function to find the kth largest element in an unsorted array. The function should have a time complexity of O(n). Please provide a solution in C#.
import random def partition(arr, left, right): pivot_index = random.randint(left, right) pivot = arr[pivot_index] arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left for i in range(left, right): if arr[i] > pivot: arr[i], arr[store_index] = arr[store_i...
from solution import find_kth_largest def test_kth_largest(): assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5 assert find_kth_largest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4 assert find_kth_largest([1, 2, 3, 4, 5, 6], 1) == 6 assert find_kth_largest([1, 2, 3, 4, 5, 6], 6) == 1 assert find_kth_larg...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right):", "function_name": "partition", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def quickselect(arr, left, right, k_smallest):", "function_name": "quickselect", ...
[ 0, 1, 1, 1, 0, 1, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef partition(nums, left, right):\n pivot_index = random.randint(left, right)\n pivot_value = nums[pivot_index]\n nums[pivot_index], nums[right] = nums[right], nums[...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004079", "row_id": 4079, "seed_ids": "['magpie_prefill_4079']" }
0.59745
Prefill_4079
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
06ec35c0f411e15e43d756a2b9caab027ad245cb
afbb527cefd5aac6cd51b1f3b393c53918541702
v1.0
instruct
Prefill
Prefill_4095_I
Write a function to calculate the sum of all prime numbers less than a given limit.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import is_prime, sum_of_primes def test_is_prime(): # Test edge cases assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) # Test larger primes assert is_prime(97) assert not is_prime(99) def test_sum_of_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 the sum of all prime numbers less than the given limit.", "function_declaration": "def sum_of_prime...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004095", "row_id": 4095, "seed_ids": "['magpie_prefill_4095']" }
0.69348
Prefill_4095
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c47fe946d9916e783c2a579c77089c655ee3ffd
818351b6775787f303f25820d1adbaf3c0575b71
v1.0
instruct
Prefill
Prefill_4223_I
Write a function to implement the classic game "Tic-Tac-Toe". The function should take a list of moves as input. Each move is a tuple containing two elements: the first is the player ('X' or 'O') and the second is the tuple indicating the row and column of the board (0-indexed). The function should print the board afte...
def print_board(board): for row in board: print(" | ".join(row)) print("-" * 5) def check_winner(board, player): # Check rows for row in board: if all([cell == player for cell in row]): return True # Check columns for col in range(3): if all([board[row][...
from solution import tic_tac_toe def test_tic_tac_toe_x_wins_row(): moves = [('X', (0, 0)), ('O', (1, 1)), ('X', (0, 1)), ('O', (2, 2)), ('X', (0, 2))] tic_tac_toe(moves) def test_tic_tac_toe_o_wins_column(): moves = [('X', (0, 0)), ('O', (1, 1)), ('X', (0, 2)), ('O', (0, 1)), ('X', (2, 0)), ('O', (2, 1))...
[ { "docstring": null, "function_declaration": "def print_board(board):", "function_name": "print_board", "parameter_list": "(board)" }, { "docstring": null, "function_declaration": "def check_winner(board, player):", "function_name": "check_winner", "parameter_list": "(board, play...
[ 1, 1, 1, 0, 0, 1, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def print_board(board):\n for row in board:\n print(\" | \".join(row))\n print(\"-\" * 5)\n print()\n\ndef check_winner(board, player):\n for row in board:\n if ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004223", "row_id": 4223, "seed_ids": "['magpie_prefill_4223']" }
0.534809
Prefill_4223
I
[ "print_board", "check_winner", "tic_tac_toe" ]
3
[ [ "tic_tac_toe", "check_winner" ], [ "tic_tac_toe", "print_board" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c9e3d302ec71aaaad59d675d40947b92d6b214e4
9ee03b20a5009269ef4816e9b2cdc87cc70c59ac
v1.0
instruct
Prefill
Prefill_4284_I
Write a function to calculate the sum of numbers in an array, but only for those numbers that are less than or equal to 100 and are prime. How can we implement this in Python using a simple loop and a function to check if a number is prime?
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def sum_primes_upto_1...
from solution import is_prime, sum_primes_upto_100 def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-3) == False def test_sum_primes_upt...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculate the sum of numbers in the array that are less than or equal to 100 and are prime.", "function_declaration...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004284", "row_id": 4284, "seed_ids": "['magpie_prefill_4284']" }
0.624781
Prefill_4284
I
[ "is_prime", "sum_primes_upto_100" ]
2
[ [ "sum_primes_upto_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e947683113da07c82e11c06562da82a50490b251
ac0e132b790f3454391229d3b623d9baf2ccaf45
v1.0
instruct
Prefill
Prefill_4319_I
Write a function to find all prime numbers in a given range. The function should return a list of all prime numbers between a start number and an end number, inclusive.
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 def find...
from solution import find_primes_in_range def test_find_primes_no_primes(): assert find_primes_in_range(0, 1) == [] def test_find_primes_small_range(): assert find_primes_in_range(2, 5) == [2, 3, 5] def test_find_primes_larger_range(): assert find_primes_in_range(10, 20) == [11, 13, 17, 19] def test_fin...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between start and end, inclusive.", "function_declaration": "def find_primes_in_range(star...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004319", "row_id": 4319, "seed_ids": "['magpie_prefill_4319']" }
0.577597
Prefill_4319
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77e3e44cb6619c24d14db7640385de88eb7329f1
6e7c5776be77f608f4bc411f456b11817cb216ef
v1.0
instruct
Prefill
Prefill_4422_I
Write a function to calculate the factorial of a given number using recursion. Then, write a function to calculate the sum of the factorial of numbers from 1 to n using memoization. Finally, create a test function to verify the correctness of the implementation.
def factorial(n, memo={}): """ Returns the factorial of n using recursion and memoization. """ if n in memo: return memo[n] if n <= 1: return 1 else: memo[n] = n * factorial(n-1, memo) return memo[n] def sum_of_factorials(n): """ Returns the sum of the fa...
from solution import factorial, sum_of_factorials def test_factorial_base_cases(): assert factorial(0) == 1 assert factorial(1) == 1 def test_factorial_general_cases(): assert factorial(5) == 120 assert factorial(6) == 720 def test_sum_of_factorials(): assert sum_of_factorials(1) == 1 assert ...
[ { "docstring": "Returns the factorial of n using recursion and memoization.", "function_declaration": "def factorial(n, memo={}):", "function_name": "factorial", "parameter_list": "(n, memo={})" }, { "docstring": "Returns the sum of the factorials of numbers from 1 to n.", "function_decl...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n, memo={}):\n \"\"\"\n Recursively calculates the factorial of a given number n using memoization.\n \"\"\"\n if n == 0:\n return 1\n if n not in memo:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004422", "row_id": 4422, "seed_ids": "['magpie_prefill_4422']" }
0.627835
Prefill_4422
I
[ "factorial", "sum_of_factorials" ]
2
[ [ "sum_of_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a2c7fcab6fd00336e100ce0d73f474fe0afe7018
dacc0bd5f8a2398e117241e025d131a655284f58
v1.0
instruct
Prefill
Prefill_4504_I
Write a function to calculate the sum of all prime numbers within a given range. The function should take two parameters: the start and end of the range (inclusive). Additionally, write a main function to test your prime sum function with specific test cases.
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 for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_pr...
from solution import sum_primes_in_range def test_sum_primes_in_small_range(): assert sum_primes_in_range(1, 10) == 17 # primes are 2, 3, 5, 7 def test_sum_primes_in_medium_range(): assert sum_primes_in_range(10, 20) == 60 # primes are 11, 13, 17, 19 def test_sum_primes_include_bounds(): assert sum_pri...
[ { "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 sum of all prime numbers in the range from start to end (inclusive).", "function_declara...
[ 0, 1, 1, 1, 0, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00004504", "row_id": 4504, "seed_ids": "['magpie_prefill_4504']" }
0.618002
Prefill_4504
I
[ "is_prime", "sum_primes_in_range" ]
2
[ [ "sum_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1091b1ef4a1e39f56f5afb922c5791f34bf08bc3
8e5992eadfb47adbb0431f7dcfd7a43b9ce78b6e
v1.0
instruct
Prefill
Prefill_4587_I
Write a function to implement a merge sort algorithm.
def merge_sort(arr): """ Sorts an array of numbers using the merge sort algorithm. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right): """ ...
from solution import merge_sort def test_merge_sort_already_sorted(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted(): assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_merge_sort_mixed_numbers(): assert merge_sort([4, 1, 3, 9, 7]) == [1, 3, 4, 7, 9...
[ { "docstring": "Sorts an array of numbers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted arrays into one sorted array.", "function_declaration": "def merge(lef...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array in ascending order using the merge sort algorithm.\n \n Parameters:\n arr (list): A list of comparable elements to be sorted.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004587", "row_id": 4587, "seed_ids": "['magpie_prefill_4587']" }
0.8207
Prefill_4587
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dbc246e3304299d3c69634042f78b72967a22672
0900aa6ec8c910475cc07a35a82707587720d3f8
v1.0
instruct
Prefill
Prefill_4712_I
Write a function to check if two strings are Pangrams or not in Python. A pangram is a sentence containing every letter of the English alphabet at least once.
def is_pangram(s): """ Check if the given string `s` is a pangram. A pangram is a sentence containing every letter of the English alphabet at least once. Parameters: s (str): The input string to check. Returns: bool: True if the string is a pangram, False otherwise. """ ...
from solution import is_pangram, are_both_pangrams def test_is_pangram(): assert is_pangram("The quick brown fox jumps over the lazy dog") == True assert is_pangram("Sphinx of black quartz, judge my vow") == True assert is_pangram("Hello, World!") == False assert is_pangram("") == False def test_are_b...
[ { "docstring": "Check if the given string `s` is a pangram.\n\nA pangram is a sentence containing every letter of the English alphabet at least once.\n\nParameters:\ns (str): The input string to check.\n\nReturns:\nbool: True if the string is a pangram, False otherwise.", "function_declaration": "def is_pan...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import string\n\ndef are_both_pangrams(s1, s2):\n \"\"\"\n Check if both strings are pangrams.\n \n Parameters:\n s1 (str): The first string to check.\n s2 (str): The second...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004712", "row_id": 4712, "seed_ids": "['magpie_prefill_4712']" }
0.625471
Prefill_4712
I
[ "is_pangram", "are_both_pangrams" ]
2
[ [ "are_both_pangrams", "is_pangram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42939f17be762312810f2cbfa22dd48837a824ac
e66ab8af8f733cd84ce0171257c7091f57d76b5c
v1.0
instruct
Prefill
Prefill_4784_I
Write a function to perform merge sort on an array of integers. Additionally, implement a recursive function to merge two sorted arrays.
def merge_sort(arr): """ Perform merge sort on an array of integers. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right): """ Merge ...
from solution import merge_sort, merge def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_single_element_array(): 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_unsorted_array(): ...
[ { "docstring": "Perform merge sort on an array of integers.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merge two sorted arrays into one sorted array.", "function_declaration": "def merge(left, right):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on array arr.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left_half = merge_sort(arr[:m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004784", "row_id": 4784, "seed_ids": "['magpie_prefill_4784']" }
0.775129
Prefill_4784
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d5e9372e84785647689a1a784e84fa9afff3f12
93e61ca3cdc4057781522bda8d57f415bbd9027e
v1.0
instruct
Prefill
Prefill_4820_I
Write a function to find the largest prime number less than a given number `n`. Your function should be efficient and avoid unnecessary computations.
def is_prime(num): """Helper function to check if a number is prime.""" if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import largest_prime_less_than def test_largest_prime_less_than_10(): assert largest_prime_less_than(10) == 7 def test_largest_prime_less_than_20(): assert largest_prime_less_than(20) == 19 def test_largest_prime_less_than_2(): assert largest_prime_less_than(2) is None def test_largest_pri...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find the largest prime number less than a given number n.", "function_declaration": "def largest_prime_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num < 2:\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 largest_prim...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00004820", "row_id": 4820, "seed_ids": "['magpie_prefill_4820']" }
0.641362
Prefill_4820
I
[ "is_prime", "largest_prime_less_than" ]
2
[ [ "largest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b0f093ef67dd94d72ed2a56e6b303a126939c69
fbddf5e37b3fde071b11316668dd55ca98f08e5e
v1.0
instruct
Prefill
Prefill_4824_I
Write a function to find the maximum area of a rectangle in a binary matrix where all the elements in the rectangle are 1's. The binary matrix has dimensions n x m.
def maxRectangle(matrix): """ Finds the maximum area of a rectangle in a binary matrix where all the elements in the rectangle are 1's. Parameters: matrix (List[List[int]]): A binary matrix of dimensions n x m. Returns: int: The maximum area of a rectangle consisting of all 1's. "...
import pytest from solution import maxRectangle def test_maxRectangle_single_row(): matrix = [[1, 1, 1, 1]] assert maxRectangle(matrix) == 4 def test_maxRectangle_single_column(): matrix = [ [1], [1], [1], [1] ] assert maxRectangle(matrix) == 4 def test_maxRectangl...
[ { "docstring": "Finds the maximum area of a rectangle in a binary matrix where all the elements \nin the rectangle are 1's.\n\nParameters:\nmatrix (List[List[int]]): A binary matrix of dimensions n x m.\n\nReturns:\nint: The maximum area of a rectangle consisting of all 1's.", "function_declaration": "def m...
[ 0, 1, 0, 1, 1, 0, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n \"\"\"\n Finds the maximal rectangle of 1s in a binary matrix.\n \"\"\"\n if not matrix or not matrix[0]:\n return 0\n \n max_area = 0...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004824", "row_id": 4824, "seed_ids": "['magpie_prefill_4824']" }
0.678843
Prefill_4824
I
[ "maxRectangle", "largestRectangleArea" ]
2
[ [ "maxRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d41679c3cf12e75766ec6a66b7c0c3abc5594101
dea48e5a1968c508518770f6e5c238cd7441b908
v1.0
instruct
Prefill
Prefill_4904_I
Write a function to calculate the nth Fibonacci number using both recursion and iteration. Compare the performance for large values of n.
import time def fibonacci_recursive(n): """ Calculates the nth Fibonacci number using recursion. """ if n <= 1: return n else: return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2) def fibonacci_iterative(n): """ Calculates the nth Fibonacci number using iteration....
from solution import fibonacci_recursive, fibonacci_iterative, performance_comparison def test_fibonacci_recursive_base_cases(): assert fibonacci_recursive(0) == 0 assert fibonacci_recursive(1) == 1 def test_fibonacci_recursive(): assert fibonacci_recursive(2) == 1 assert fibonacci_recursive(3) == 2 ...
[ { "docstring": "Calculates the nth Fibonacci number using recursion.", "function_declaration": "def fibonacci_recursive(n):", "function_name": "fibonacci_recursive", "parameter_list": "(n)" }, { "docstring": "Calculates the nth Fibonacci number using iteration.", "function_declaration": ...
[ 0, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_recursive(n):\n \"\"\"\n Returns the nth Fibonacci number using recursion.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer.\")\n el...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004904", "row_id": 4904, "seed_ids": "['magpie_prefill_4904']" }
0.658043
Prefill_4904
I
[ "fibonacci_recursive", "fibonacci_iterative", "performance_comparison" ]
3
[ [ "performance_comparison", "fibonacci_iterative" ], [ "performance_comparison", "fibonacci_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
609b437a67bb0a87912c494343e361c36ea6009a
e2ad5deb80138b8c287a16438aa28d8c6ce434a2
v1.0
instruct
Prefill
Prefill_4951_I
Write a function to find the sum of all prime numbers less than a given number `n`. The function should return the sum as an integer.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False p = 3 while p * p <= num: if num % p == 0: return False p += 2 return True d...
from solution import is_prime, sum_of_primes def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(29) assert not is_prime(100) def test_sum_of_primes_below_10(): assert sum_of_primes(10) == 17 d...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers less than n.", "function_declaration": "def sum_of_primes(n):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_primes(n):\n \"\"\"\n Returns the sum of all prime numbers less than n.\n \"\"\"\n if n <= 2:\n return 0\n\n sieve = [True] * n\n sieve[0] = sieve[1] = Fal...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00004951", "row_id": 4951, "seed_ids": "['magpie_prefill_4951']" }
0.656158
Prefill_4951
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e00ab343c339b316b9bd2a976718016548a87f29
f9f3319654ea396976299f6e973c914c2f950679
v1.0
instruct
Prefill
Prefill_4981_I
Write a function to implement the Bubble Sort algorithm in Python. The function should take a list of integers as input and sort the list in ascending order using the Bubble Sort algorithm. Additionally, implement a helper function to verify the correctness of your Bubble Sort implementation by sorting a sample list an...
def bubble_sort(arr): """ Sorts a list of integers in ascending order using the Bubble Sort algorithm. """ n = len(arr) for i in range(n): # Last i elements are already sorted for j in range(0, n - i - 1): # Traverse the array from 0 to n-i-1 # Swap if the ele...
from solution import bubble_sort, is_bubble_sort_correct def test_bubble_sort_empty_list(): assert bubble_sort([]) == [] def test_bubble_sort_single_element_list(): assert bubble_sort([1]) == [1] def test_bubble_sort_sorted_list(): assert bubble_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_bubble_s...
[ { "docstring": "Sorts a list of integers in ascending order using the Bubble Sort algorithm.", "function_declaration": "def bubble_sort(arr):", "function_name": "bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Verifies the correctness of the bubble_sort function by comparing its o...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort(lst):\n \"\"\"\n Sorts a list of integers in ascending order using the Bubble Sort algorithm.\n \"\"\"\n n = len(lst)\n for i in range(n):\n # Flag to de...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004981", "row_id": 4981, "seed_ids": "['magpie_prefill_4981']" }
0.566562
Prefill_4981
I
[ "bubble_sort", "is_bubble_sort_correct" ]
2
[ [ "is_bubble_sort_correct", "bubble_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
154d67f32a59be62e4b450ce6b5dbf7995dbc00b
baf724abf79d6c0830d6bff5ad0e2a5be7c42b0b
v1.0
instruct
Prefill
Prefill_5086_I
Write a function to traverse a binary tree in preorder traversal and convert it to a min-heap. In addition, for each node, keep track of the number of nodes in the subtree rooted at that node and return it.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def preorder_traversal(root): if root is None: return [] return [root.val] + preorder_traversal(root.left) + preorder_traversal(root.right) def build_min_hea...
from solution import TreeNode, convert_to_min_heap_and_count_nodes def test_convert_to_min_heap_and_count_nodes_single_node(): root = TreeNode(10) assert convert_to_min_heap_and_count_nodes(root) == 1 assert root.val == 10 def test_convert_to_min_heap_and_count_nodes_complete_tree(): root = TreeNode(1...
[]
[ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 preorder_traversal(root):\n if r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005086", "row_id": 5086, "seed_ids": "['magpie_prefill_5086']" }
0.616589
Prefill_5086
I
[ "preorder_traversal", "build_min_heap", "to_heap_tree", "convert_to_min_heap_and_count_nodes" ]
4
[ [ "convert_to_min_heap_and_count_nodes", "build_min_heap" ], [ "convert_to_min_heap_and_count_nodes", "preorder_traversal" ], [ "convert_to_min_heap_and_count_nodes", "to_heap_tree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f6baa61a3f4bdce5cfff4d3b75a10d7b5d928119
f4ed4f2504ca1cca0fd191000f44ab5db78d9fcb
v1.0
instruct
Prefill
Prefill_5150_I
Write a function to sort an array using the Merge Sort algorithm. can you solve this in Python?
def merge_sort(arr): """ Sorts an array using the Merge Sort algorithm. Parameters: arr (list): a list of elements to be sorted Returns: list: a new sorted list """ if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_...
from solution import merge_sort def test_merge_sort(): assert merge_sort([]) == [] assert merge_sort([1]) == [1] assert merge_sort([3, 2, 1]) == [1, 2, 3] assert merge_sort([1, 2, 3]) == [1, 2, 3] assert merge_sort([4, 1, 5, 3, 2]) == [1, 2, 3, 4, 5] assert merge_sort([5, 4, 3, 2, 1]) == [1, 2,...
[ { "docstring": "Sorts an array using the Merge Sort algorithm.\n\nParameters:\narr (list): a list of elements to be sorted\n\nReturns:\nlist: a new sorted list", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array using the Merge Sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2 # Finding the mid of the array\n le...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005150", "row_id": 5150, "seed_ids": "['magpie_prefill_5150']" }
0.83316
Prefill_5150
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79eeec54fa2d519db0fb3049f085cc463fdcbd84
e022df6cc84a5c9d7fe2eb754de5d9a6c2374afa
v1.0
instruct
Prefill
Prefill_5209_I
Write a function to search for a given integer in a sorted array and return its index. If the integer is not present, return -1. Use a recursive approach to implement this function.
def binary_search(arr, low, high, target): """ Recursively searches for the target in the sorted array. """ if high >= low: mid = (high + low) // 2 # If the element is present at the middle itself if arr[mid] == target: return mid # If the element is smaller...
from solution import search_in_sorted_array def test_search_exists_in_middle(): assert search_in_sorted_array([1, 2, 3, 4, 5, 6, 7], 4) == 3 def test_search_exists_at_beginning(): assert search_in_sorted_array([1, 2, 3, 4, 5, 6, 7], 1) == 0 def test_search_exists_at_end(): assert search_in_sorted_array([...
[ { "docstring": "Recursively searches for the target in the sorted array.", "function_declaration": "def binary_search(arr, low, high, target):", "function_name": "binary_search", "parameter_list": "(arr, low, high, target)" }, { "docstring": "Wrapper function for binary search in a sorted ar...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search_recursive(arr, target, left=0, right=None):\n \"\"\"\n Recursively searches for a target value in a sorted array and returns its index.\n If the target is not found...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005209", "row_id": 5209, "seed_ids": "['magpie_prefill_5209']" }
0.690297
Prefill_5209
I
[ "binary_search", "search_in_sorted_array" ]
2
[ [ "search_in_sorted_array", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87c71de693b6c4a8c549da7a0ed300b0f97b66d9
90327e86eeb6cbb38bb92adc0d8982af959b10c6
v1.0
instruct
Prefill
Prefill_5220_I
Write a function to implement a Promise that operates similarly to Promise.all but only returns the first resolved value. If any of the Promises reject, the returned Promise should reject with the reason of the first rejection.
import asyncio from typing import List, Any async def promise_first_or_reject(promises: List[asyncio.Future]) -> Any: """ Returns the first resolved value from a list of promises, or rejects with the reason of the first rejection. """ try: return await asyncio.wait_for(asyncio.ensure_future(fir...
import pytest import asyncio from solution import promise_first_or_reject @pytest.mark.asyncio async def test_promise_first_resolved(): async def task1(): await asyncio.sleep(0.3) return "task1_result" async def task2(): await asyncio.sleep(0.1) return "task2_result" ...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import asyncio\n\nasync def promise_any(promises):\n \"\"\"\n Takes an iterable of awaitable objects and returns the first one\n that resolves. If any of the promises reject, it will...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005220", "row_id": 5220, "seed_ids": "['magpie_prefill_5220']" }
0.328244
Prefill_5220
I
[ "promise_first_or_reject", "first_completed" ]
2
[ [ "promise_first_or_reject", "first_completed" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d0fd3fe205e0d1611631cd4116192a3c96fe4cf9
a41a920e8e37b634adc7ef6714c4e33beef83a14
v1.0
instruct
Prefill
Prefill_5388_I
Write a function to find the largest palindrome number that can be formed by the product of two numbers within a given range. The range will be provided as two parameters: the starting number and the ending number.
def is_palindrome(n): """ Checks if a given number n is a palindrome. """ return str(n) == str(n)[::-1] def largest_palindrome_product(start, end): """ Finds the largest palindrome number that can be formed by the product of two numbers within a given range. Parameters: start (...
from solution import largest_palindrome_product, is_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1221) == True assert is_palindrome(12321) == True assert is_palindrome(12345) == False def test_largest_palindrome_prod...
[ { "docstring": "Checks if a given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Finds the largest palindrome number that can be formed by the product of two numbers within a given rang...
[ 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num):\n \"\"\"\n Checks if a given number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef largest_palindrome_product(start, end):\n \"\"\...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005388", "row_id": 5388, "seed_ids": "['magpie_prefill_5388']" }
0.787569
Prefill_5388
I
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e389330814f6fa55a82cab4d61c02132ca2a900b
ec3a5b1d4229347b88d1216a8c8e92407c71a07b
v1.0
instruct
Prefill
Prefill_5407_I
Write a function to calculate the factorial of a number and then find the sum of all digits in the factorial. For example, 5! = 120, and the sum of the digits is 3 (1+2+0).
def factorial(n): """ Returns the factorial of a number n. """ if n == 0: return 1 result = 1 for i in range(1, n + 1): result *= i return result def sum_of_digits_in_factorial(n): """ Returns the sum of the digits in the factorial of a number n. """ fac = fa...
from solution import factorial, sum_of_digits_in_factorial def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(5) == 120 assert factorial(7) == 5040 assert factorial(10) == 3628800 def test_sum_of_digits_in_factorial(): assert sum_of_digits_in_factorial(0) ...
[ { "docstring": "Returns the factorial of a number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the sum of the digits in the factorial of a number n.", "function_declaration": "def sum_of_digits_in_facto...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial_digit_sum(n):\n \"\"\"\n Calculate the factorial of n and then find the sum of the digits in the factorial.\n \n Args:\n n (int): The number to calculate the fact...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005407", "row_id": 5407, "seed_ids": "['magpie_prefill_5407']" }
0.616321
Prefill_5407
I
[ "factorial", "sum_of_digits_in_factorial" ]
2
[ [ "sum_of_digits_in_factorial", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d4da6ba91ee45da2d9e88447de24db6a2b39dc4d
c4827a13b47c951edcbcfc03dd00c181a193ea6d
v1.0
instruct
Prefill
Prefill_5506_I
Write a function to calculate the total number of days in a given month, considering whether the input year is a leap year or not.
def is_leap_year(year): """ Check if the given year is a leap year. A leap year is divisible by 4, but years divisible by 100 are not leap years unless they are also divisible by 400. """ if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True else: return False ...
from solution import is_leap_year, days_in_month def test_is_leap_year(): assert is_leap_year(2000) == True # Divisible by 400 assert is_leap_year(1900) == False # Divisible by 100 but not by 400 assert is_leap_year(2004) == True # Divisible by 4 but not by 100 assert is_leap_year(2001) == False # No...
[ { "docstring": "Check if the given year is a leap year.\nA leap year is divisible by 4, but years divisible by 100 are not leap years unless they are also divisible by 400.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Check if a given year is a leap year.\n \"\"\"\n return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)\n\ndef days_in_month(year, month)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005506", "row_id": 5506, "seed_ids": "['magpie_prefill_5506']" }
0.717254
Prefill_5506
I
[ "is_leap_year", "days_in_month" ]
2
[ [ "days_in_month", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2228e2bf315717f6dc9d3d2e1b1a0ffe61dcea52
a887b009111a4165b26248a9cd509dcc6e337532
v1.0
instruct
Prefill
Prefill_5517_I
Write a function to perform a binary search on a sorted list of numbers. The function should return the index of the target number if it exists in the list, and -1 if it does not. The function should be recursive.
def binary_search_recursive(arr, target, low, high): """ Perform a binary search on a sorted list of numbers recursively. :param arr: List[int] - A sorted list of numbers :param target: int - The target number to search for :param low: int - The lower index of the current search range :para...
from solution import binary_search def test_binary_search_found(): assert binary_search([1, 2, 3, 4, 5], 3) == 2 assert binary_search([10, 20, 30, 40, 50], 50) == 4 assert binary_search([5, 15, 25, 35, 45], 5) == 0 def test_binary_search_not_found(): assert binary_search([1, 2, 3, 4, 5], 6) == -1 ...
[ { "docstring": "Perform a binary search on a sorted list of numbers recursively.\n\n:param arr: List[int] - A sorted list of numbers\n:param target: int - The target number to search for\n:param low: int - The lower index of the current search range\n:param high: int - The upper index of the current search rang...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(arr, target, left=0, right=None):\n \"\"\"\n Recursively performs binary search on a sorted list.\n \n Parameters:\n - arr: List of sorted numbers\n - targ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005517", "row_id": 5517, "seed_ids": "['magpie_prefill_5517']" }
0.774819
Prefill_5517
I
[ "binary_search_recursive", "binary_search" ]
2
[ [ "binary_search", "binary_search_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa8cd6b4a5087e54cb1a2cd2e00ede1ad84fbfec
c9ece6b00c3562ba84fa5f4ac9a94f4fc18ebaf9
v1.0
instruct
Prefill
Prefill_5710_I
Write a function to calculate the sum of all prime numbers up to a given number n. The function should be efficient and avoid unnecessary calculations.
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False p = 3 while p * p <= num: if num % p == 0: return False p += 2 return True def sum_of_primes(n): """ Returns the sum of all prime numbe...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime(0) == False def test_sum_of_primes_with_s...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers up to a given number n.", "function_declaration": "def sum_of_primes(n):", "function_name": "sum_of_primes...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_primes(n):\n \"\"\"\n Returns the sum of all prime numbers up to a given number n.\n \"\"\"\n if n < 2:\n return 0\n\n primes = [True] * (n + 1)\n p = 2\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00005710", "row_id": 5710, "seed_ids": "['magpie_prefill_5710']" }
0.606204
Prefill_5710
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5c6e97445884332cd4cf9049739295da18e0989
53bf3794fa3fd817747e56f7ccfb95775b0cfa96
v1.0
instruct
Prefill
Prefill_5757_I
Write a function to find the sum of all the prime numbers between two given positive integers (inclusive).
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 sum_of_primes def test_sum_of_primes_within_range(): assert sum_of_primes(10, 20) == 60 # primes are 11, 13, 17, 19 def test_sum_of_primes_single_prime(): assert sum_of_primes(3, 3) == 3 # prime is 3 def test_sum_of_primes_no_primes(): assert sum_of_primes(8, 10) == 0 # no ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between start and end inclusive.", "function_declaration": "def sum_of_primes(start, end)...
[ 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005757", "row_id": 5757, "seed_ids": "['magpie_prefill_5757']" }
0.616751
Prefill_5757
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
726dbd435446aba098b9657ce68602617d8c4a78
0f4ec9bff75a6987466909e993b6a87a545fd536
v1.0
instruct
Prefill
Prefill_5863_I
Write a function to print all even numbers in a list using recursion.
def print_even_numbers(numbers, index=0, even_numbers=None): """ Recursively prints all even numbers in the provided list. :param numbers: List of integers. :param index: Current index in the recursive call. :param even_numbers: Used to collect even numbers recursively. :return: List of eve...
from solution import get_even_numbers def test_print_even_with_mixed_numbers(): assert get_even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6] def test_print_even_with_all_even_numbers(): assert get_even_numbers([2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10] def test_print_even_with_all_odd_numbers(): assert get_even_n...
[ { "docstring": "Recursively prints all even numbers in the provided list.\n\n:param numbers: List of integers.\n:param index: Current index in the recursive call.\n:param even_numbers: Used to collect even numbers recursively.\n:return: List of even numbers.", "function_declaration": "def print_even_numbers...
[ 0, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def print_even_numbers(lst, index=0):\n \"\"\"\n Recursively prints all even numbers in the list.\n \n Parameters:\n lst (list) : List of integers to check\n index (int): Cu...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005863", "row_id": 5863, "seed_ids": "['magpie_prefill_5863']" }
0.763935
Prefill_5863
I
[ "print_even_numbers", "get_even_numbers" ]
2
[ [ "get_even_numbers", "print_even_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
12de83f24aa59eacdee2addc09f6b48cca8836c3
0e1c461a8b356f8975f8e329effb53951f8552cf
v1.0
instruct
Prefill
Prefill_5869_I
Write a function to reverse a string in Python. Also, write a function that uses this reverse function to check if a given string is a palindrome.
def reverse_string(s): """ Returns the reverse of the given string s. """ return s[::-1] def is_palindrome(s): """ Returns True if the given string s is a palindrome, False otherwise. A string is considered a palindrome if it reads the same forwards and backwards. """ reversed_...
from solution import reverse_string, is_palindrome def test_reverse_string(): assert reverse_string("hello") == "olleh" assert reverse_string("world") == "dlrow" assert reverse_string("") == "" assert reverse_string("a") == "a" def test_is_palindrome(): assert is_palindrome("racecar") == True ...
[ { "docstring": "Returns the reverse of the given string s.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Returns True if the given string s is a palindrome, False otherwise.\n\nA string is considered a palind...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_string(s):\n \"\"\"\n Reverses the given string.\n \n Parameters:\n s (str): The string to be reversed.\n \n Returns:\n str: The reversed string.\n \"\"...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005869", "row_id": 5869, "seed_ids": "['magpie_prefill_5869']" }
0.76622
Prefill_5869
I
[ "reverse_string", "is_palindrome" ]
2
[ [ "is_palindrome", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e8a988a22f7f6f39e53e4868da1321abacc2214
ff2897941e77461e2e0a3d4f3a05fabe710f580e
v1.0
instruct
Prefill
Prefill_5910_I
Write a function to find the nth Fibonacci number in Python. The function should be efficient and have a time complexity of O(log n). The solution should use matrix exponentiation to achieve this. Explain the approach and the final code.
def matrix_multiply(A, B): """ Multiplies two 2x2 matrices A and B. """ return [ [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]] ] def matrix_power(matrix, n): """ ...
from solution import fibonacci def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_small_numbers(): assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 def test_fibonacci_larger_numbers(): as...
[ { "docstring": "Multiplies two 2x2 matrices A and B.", "function_declaration": "def matrix_multiply(A, B):", "function_name": "matrix_multiply", "parameter_list": "(A, B)" }, { "docstring": "Computes the power of a 2x2 matrix using exponentiation by squaring.", "function_declaration": "d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_mult(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005910", "row_id": 5910, "seed_ids": "['magpie_prefill_5910']" }
0.664199
Prefill_5910
I
[ "matrix_multiply", "matrix_power", "fibonacci" ]
3
[ [ "fibonacci", "matrix_power" ], [ "matrix_power", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
114db12ebf9ddfde75cfcd0e7ae7cce6277ffa9b
b90f617037dfbb1f0d123007f0ad12368768918f
v1.0
instruct
Prefill
Prefill_5989_I
Write a function to solve the 8 puzzle problem which can move, left, right, up, and down.
import heapq def heuristic(state, goal): h = 0 for i in range(1, 9): xi, yi = divmod(state.index(i), 3) xg, yg = divmod(goal.index(i), 3) h += abs(xi - xg) + abs(yi - yg) return h def get_neighbors(state): neighbors = [] zero_index = state.index(0) zero_x, zero_y = divm...
from solution import solve_8_puzzle def test_solve_8_puzzle_start_is_goal(): start = [1, 2, 3, 4, 5, 6, 7, 8, 0] goal = [1, 2, 3, 4, 5, 6, 7, 8, 0] assert solve_8_puzzle(start, goal) == [[1, 2, 3, 4, 5, 6, 7, 8, 0]] def test_solve_8_puzzle_one_move(): start = [1, 2, 3, 4, 5, 6, 7, 0, 8] goal =...
[ { "docstring": null, "function_declaration": "def heuristic(state, goal):", "function_name": "heuristic", "parameter_list": "(state, goal)" }, { "docstring": null, "function_declaration": "def get_neighbors(state):", "function_name": "get_neighbors", "parameter_list": "(state)" ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_zero_position(state):\n \"\"\"\n Find the position of the zero (empty space) in the puzzle.\n \"\"\"\n for i, row in enumerate(state):\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00005989", "row_id": 5989, "seed_ids": "['magpie_prefill_5989']" }
0.519073
Prefill_5989
I
[ "heuristic", "get_neighbors", "a_star", "solve_8_puzzle" ]
4
[ [ "a_star", "get_neighbors" ], [ "a_star", "heuristic" ], [ "solve_8_puzzle", "a_star" ] ]
3
[]
false
[]
false
pytest
true
[]
true
db20574b0f99891082572ff328048134195507ba
cb481c1ea74d5115675a74c5701a6e7608433cb0
v1.0
instruct
Prefill
Prefill_5994_I
Write a function to reverse a list in Python. You should not use the built-in `reverse()` method or slicing (`[::-1]`). Additionally, implement your own method to check if the reversed list is correctly reversed or not.
def reverse_list(lst): """ Reverses the given list without using the built-in reverse() method or slicing. """ reversed_lst = [] for i in range(len(lst) - 1, -1, -1): reversed_lst.append(lst[i]) return reversed_lst def is_reversed(original, reversed_lst): """ Checks if the rever...
from solution import reverse_list, is_reversed def test_reverse_list_empty(): assert reverse_list([]) == [] def test_reverse_list_single_element(): assert reverse_list([1]) == [1] def test_reverse_list_multiple_elements(): assert reverse_list([1, 2, 3]) == [3, 2, 1] def test_is_reversed_true(): orig...
[ { "docstring": "Reverses the given list without using the built-in reverse() method or slicing.", "function_declaration": "def reverse_list(lst):", "function_name": "reverse_list", "parameter_list": "(lst)" }, { "docstring": "Checks if the reversed_lst is the correct reverse of the original ...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_list(lst):\n \"\"\"\n Reverses the given list without using reverse() method or slicing.\n \"\"\"\n reversed_lst = []\n for item in lst:\n reversed_lst.inser...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00005994", "row_id": 5994, "seed_ids": "['magpie_prefill_5994']" }
0.674843
Prefill_5994
I
[ "reverse_list", "is_reversed" ]
2
[ [ "is_reversed", "reverse_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
990ee39ba860a3128e3ccf6b9fa0ae5a03b3cc89
661bbf6e2d8d5435167a2d8b1efa5c942fafa9a8
v1.0
instruct
Prefill
Prefill_6110_I
Write a function to find the sum of all prime numbers within a non-empty range `[startRange, endRange]`. For example, for the range `[1, 10]`, the function should return `17` (since the prime numbers are 2, 3, 5, and 7).
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 def sum_...
from solution import sum_of_primes def test_sum_of_primes(): assert sum_of_primes(1, 10) == 17 # 2, 3, 5, 7 -> sum is 17 assert sum_of_primes(10, 20) == 60 # 11, 13, 17, 19 -> sum is 60 assert sum_of_primes(1, 5) == 10 # 2, 3, 5 -> sum is 10 assert sum_of_primes(4, 4) == 0 # No prime numbers in thi...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers within the given range [startRange, endRange].", "function_declaration": "def sum_of_prim...
[ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00006110", "row_id": 6110, "seed_ids": "['magpie_prefill_6110']" }
0.640026
Prefill_6110
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5189ab569a7b2747d8d51db842482dfb91672ea0
93c0590f658edc60ecc9f1285802b70a35eac192
v1.0
instruct
Prefill
Prefill_6178_I
Write a function to find the largest prime number in an array of integers. If the array is empty or contains no prime numbers, the function should return -1.
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 max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False ...
from solution import is_prime, largest_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(25) == False assert is_prime(-3) == False def test_largest_prime_with_primes(): assert largest_pri...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the largest prime number in an array of integers.\nIf the array is empty or contains no prime numbers, ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 largest_prime...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006178", "row_id": 6178, "seed_ids": "['magpie_prefill_6178']" }
0.625132
Prefill_6178
I
[ "is_prime", "largest_prime" ]
2
[ [ "largest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d20b406d7461936e005915b7c3c75e9b508b49c
6d149257f5933f96789ed2053b836ff8e9e2cc89
v1.0
instruct
Prefill
Prefill_6227_I
Write a function to sort a stack in ascending order using Python. You are not allowed to create any additional data structures like lists, arrays, etc.
def sort_stack(stack): """ Sort a stack in ascending order using only the stack itself. """ if not stack: return # Step 1: Remove the top element from the stack top = stack.pop() # Step 2: Sort the remaining stack recursively sort_stack(stack) # Step 3: Insert the top elem...
from solution import sort_stack def test_sort_stack_already_sorted(): stack = [1, 2, 3, 4, 5] sort_stack(stack) assert stack == [1, 2, 3, 4, 5] def test_sort_stack_reverse_sorted(): stack = [5, 4, 3, 2, 1] sort_stack(stack) assert stack == [1, 2, 3, 4, 5] def test_sort_stack_unsorted(): s...
[ { "docstring": "Sort a stack in ascending order using only the stack itself.", "function_declaration": "def sort_stack(stack):", "function_name": "sort_stack", "parameter_list": "(stack)" }, { "docstring": "Helper function to insert an element into a sorted stack.", "function_declaration...
[ 1, 1, 0, 0, 1, 1, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_stack(stack):\n \"\"\"\n Sorts a stack in ascending order (top to bottom).\n\n Args:\n stack (list): A list representing the stack.\n\n Returns:\n list: A sorted st...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006227", "row_id": 6227, "seed_ids": "['magpie_prefill_6227']" }
0.571101
Prefill_6227
I
[ "sort_stack", "insert_sorted" ]
2
[ [ "sort_stack", "insert_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e803aaf0ea773b34a6663907a09c6dfd1d9143f1
429958d1bbfce0fcae591366de5d2dbe1a78cb29
v1.0
instruct
Prefill
Prefill_6428_I
Write a function to find the closest pair of points in a 2D plane. The function should take a list of tuples representing points in 2D. Each point is a tuple (x, y). The function should return the distance between the closest pair of points and the pair itself.
import math def distance(point1, point2): """ Calculates the Euclidean distance between two points in 2D space. """ return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) def closest_pair_of_points(points): """ Finds the closest pair of points in a 2D plane. :pa...
from solution import closest_pair_of_points def test_closest_pair_positive_points(): points = [(1, 1), (4, 5), (13, 6), (2, 2)] distance, pair = closest_pair_of_points(points) assert pair == ((1, 1), (2, 2)) assert distance == math.sqrt(2) def test_closest_pair_with_negative_points(): points = [(-...
[ { "docstring": "Calculates the Euclidean distance between two points in 2D space.", "function_declaration": "def distance(point1, point2):", "function_name": "distance", "parameter_list": "(point1, point2)" }, { "docstring": "Finds the closest pair of points in a 2D plane.\n\n:param points: ...
[ 1, 0, 0, 1, 0, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef closest_pair_of_points(points):\n \"\"\"\n Find the closest pair of points in a 2D plane.\n \n :param points: List of tuples...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006428", "row_id": 6428, "seed_ids": "['magpie_prefill_6428']" }
0.638192
Prefill_6428
I
[ "distance", "closest_pair_of_points" ]
2
[ [ "closest_pair_of_points", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9f7dcf0a6c52766a262278421e78b6394e4cac1
ef4f95221783f8527af0d1a38cecc93d818affe1
v1.0
instruct
Prefill
Prefill_6455_I
Write a function to calculate the total number of permutations of a given string. For example, if the input is "abc", the output should be 6.
def factorial(n): """ Calculates the factorial of a number n. """ if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) def total_permutations(s): """ Returns the total number of permutations of the given string s. """ return factorial(len(s))
from solution import factorial, total_permutations def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 def test_total_permutations_empty_string(): assert total_permutations("") == 1 def test_total_...
[ { "docstring": "Calculates the factorial of a number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the total number of permutations of the given string s.", "function_declaration": "def total_permutation...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import factorial\n\ndef count_permutations(s):\n \"\"\"\n Returns the total number of permutations of a given string s.\n \"\"\"\n return factorial(len(s))", "test_c...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006455", "row_id": 6455, "seed_ids": "['magpie_prefill_6455']" }
0.713577
Prefill_6455
I
[ "factorial", "total_permutations" ]
2
[ [ "total_permutations", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b052b47b7a6c02c3cc03a824e8f1b69cebde070
543175709456fcd541514e6f7db61b110c8f5f47
v1.0
instruct
Prefill
Prefill_6491_I
Write a function to calculate the sum of prime numbers within a given range (inclusive). The function should consider only positive integers and exclude the number zero and one.
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, sum_of_primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-7) == False def test_sum_of_prime...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of prime numbers in a given range [start, end].", "function_declaration": "def sum_of_p...
[ 1, 1, 1, 0, 1, 1, 0, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 elif n <= 3:\n return True\n elif n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006491", "row_id": 6491, "seed_ids": "['magpie_prefill_6491']" }
0.600551
Prefill_6491
I
[ "is_prime", "sum_of_primes_in_range" ]
2
[ [ "sum_of_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5fe4937e24fdfdedbe3928f6eab5e8c1799e7dec
4ef653d805a4c82f948dd8436236747a68516549
v1.0
instruct
Prefill
Prefill_6494_I
Write a function to find the maximum sum of a subarray in a given 2D array of integers.
def max_sum_subarray_2d(arr): """ Finds the maximum sum of a subarray in a given 2D array of integers. """ if not arr or not arr[0]: return 0 rows = len(arr) cols = len(arr[0]) max_sum = float('-inf') for left_col in range(cols): temp_row_sum = [0] * rows ...
from solution import max_sum_subarray_2d def test_max_sum_subarray_2d_all_positive(): arr = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_sum_subarray_2d(arr) == 45 def test_max_sum_subarray_2d_with_negatives(): arr = [ [1, -2, 3], [-4, 5, -6], [7, -8, ...
[ { "docstring": "Finds the maximum sum of a subarray in a given 2D array of integers.", "function_declaration": "def max_sum_subarray_2d(arr):", "function_name": "max_sum_subarray_2d", "parameter_list": "(arr)" }, { "docstring": "Helper function to perform Kadane's algorithm. \nFinds the maxi...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subarray_2d(arr):\n \"\"\"\n Finds the maximum sum of a subarray in a given 2D array of integers.\n \"\"\"\n if not arr or not arr[0]:\n return 0\n\n rows = ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006494", "row_id": 6494, "seed_ids": "['magpie_prefill_6494']" }
0.756155
Prefill_6494
I
[ "max_sum_subarray_2d", "kadane" ]
2
[ [ "max_sum_subarray_2d", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1dacbead3dcc87090268ca5fa2e8b21681947b56
04b03a9b8a9ca321e373508f0b9f2591ec71ba8d
v1.0
instruct
Prefill
Prefill_6511_I
Write a function to simulate a tank battle game where two tanks move towards each other and "bang" when they collide. The tanks are represented as objects with properties for x, y coordinates, width, height, speed, and direction (1 for moving to the right, -1 for moving to the left). The function should take the tanks ...
class Tank: def __init__(self, x, y, width, height, speed, direction): self.x = x self.y = y self.width = width self.height = height self.speed = speed self.direction = direction def simulate_tank_battle(tank1, tank2): """ Simulates the tank battle by moving ...
from solution import Tank, simulate_tank_battle, has_collided def test_collide_tanks(): tank1 = Tank(x=0, y=0, width=5, height=5, speed=1, direction=1) tank2 = Tank(x=10, y=0, width=5, height=5, speed=1, direction=-1) assert simulate_tank_battle(tank1, tank2) == "bang" def test_initially_collided_tan...
[]
[ 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Tank:\n def __init__(self, x, y, width, height, speed, direction):\n self.x = x\n self.y = y\n self.width = width\n self.height = height\n self.spe...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00006511", "row_id": 6511, "seed_ids": "['magpie_prefill_6511']" }
0.412103
Prefill_6511
I
[ "simulate_tank_battle", "has_collided" ]
2
[ [ "simulate_tank_battle", "has_collided" ] ]
1
[]
false
[ "Tank" ]
true
pytest
true
[]
true
5c17e105c3b8d0c1c255347c46f070ea857c83d5
d066acdab485012f0e24f8508e3f69db7ef26d39
v1.0
instruct
Prefill
Prefill_6580_I
Write a function to calculate the factorial of a given number using recursion. The function should be able to handle the input of a single integer and return the factorial of that number raised to the power of its digit sum. For example, if the input number is 5, the factorial of 5 is 120, and the sum of its digits (5)...
def factorial(n): """ Returns the factorial of n using recursion. """ if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) def digit_sum(n): """ Returns the sum of the digits of n. """ return sum(int(digit) for digit in str(n)) def factorial_power_digit_s...
from solution import factorial_power_digit_sum def test_factorial_power_digit_sum_base_case(): assert factorial_power_digit_sum(0) == 1 assert factorial_power_digit_sum(1) == 1 def test_factorial_power_digit_sum_single_digit(): assert factorial_power_digit_sum(5) == 120**5 assert factorial_power_digit...
[ { "docstring": "Returns the factorial of n using recursion.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the sum of the digits of n.", "function_declaration": "def digit_sum(n):", "function_name": "dig...
[ 1, 1, 1, 0, 1, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial_digit_sum_power(n):\n \"\"\"\n Returns the factorial of n raised to the power of the sum of its digits.\n \"\"\"\n def factorial(x):\n if x == 0 or x == 1:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006580", "row_id": 6580, "seed_ids": "['magpie_prefill_6580']" }
0.644579
Prefill_6580
I
[ "factorial", "digit_sum", "factorial_power_digit_sum" ]
3
[ [ "factorial_power_digit_sum", "digit_sum" ], [ "factorial_power_digit_sum", "factorial" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3fc9ab2d6b4a79e47226d122e0a725e6e794b042
6ca7c8f706f8898db626f1e218b5c730715a2050
v1.0
instruct
Prefill
Prefill_6674_I
Write a function to sort a list of integers using the merge sort algorithm.
def merge_sort(arr): """ Sorts an array of integers using the merge sort algorithm. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right): """ ...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert...
[ { "docstring": "Sorts an array of integers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted arrays into one sorted array.", "function_declaration": "def merge(le...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list of integers using the merge sort algorithm.\n \"\"\"\n\n if len(arr) <= 1:\n return arr\n\n def merge(left, right):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006674", "row_id": 6674, "seed_ids": "['magpie_prefill_6674']" }
0.800674
Prefill_6674
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e89a90fea811f0fc19bb31e72a9cf6ee29fcfee
2d180378bde641fbdada6811ff4b3a6c5bde2706
v1.0
instruct
Prefill
Prefill_6754_I
Write a function to find the maximum size of rectangle in a binary matrix. The binary matrix is a 2D array of integers where each element is either 0 or 1. The function should return the area of the largest rectangle that can be formed by consecutive 1s.
def max_histogram_area(heights): # Find maximum rectangular area in a histogram with given heights stack = [] max_area = 0 index = 0 while index < len(heights): if not stack or heights[stack[-1]] <= heights[index]: stack.append(index) index += 1 else: ...
from solution import max_rectangle_area def test_max_rectangle_area_empty(): assert max_rectangle_area([]) == 0 def test_max_rectangle_area_one_element(): assert max_rectangle_area([[0]]) == 0 assert max_rectangle_area([[1]]) == 1 def test_max_rectangle_area_one_row(): assert max_rectangle_area([[1, ...
[ { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_list": "(heights)" }, { "docstring": null, "function_declaration": "def max_rectangle_area(matrix):", "function_name": "max_rectangle_area", "paramet...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n \"\"\"\n Returns the maximal rectangle area of consecutive 1s in a binary matrix.\n \n :param matrix: List of List of integer (0s and 1s)\n :ret...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006754", "row_id": 6754, "seed_ids": "['magpie_prefill_6754']" }
0.700745
Prefill_6754
I
[ "max_histogram_area", "max_rectangle_area" ]
2
[ [ "max_rectangle_area", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1210ea1a7da432f6eb74a240f3c0c8a98ea16357
0654bdc16e84ad413dbdb72756743f325a43f1ee
v1.0
instruct
Prefill
Prefill_6764_I
Write a function to find the closest prime number less than the given number 'n'. If 'n' is 2 or less, return -1 indicating no prime number exists.
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def closest_prime_less_than(n): """ Returns the closest prime nu...
from solution import closest_prime_less_than def test_no_prime_for_2_or_less(): assert closest_prime_less_than(2) == -1 assert closest_prime_less_than(1) == -1 assert closest_prime_less_than(0) == -1 assert closest_prime_less_than(-3) == -1 def test_closest_prime_basic_cases(): assert closest_prim...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the closest prime number less than the given number 'n'.\nIf 'n' is 2 or less, return -1 indicating no prime number exists.", "function_dec...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(x):\n \"\"\"\n Check if the given number x is a prime number.\n \"\"\"\n if x <= 1:\n return False\n for i in range(2, int(x ** 0.5) + 1):\n if x % i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00006764", "row_id": 6764, "seed_ids": "['magpie_prefill_6764']" }
0.731045
Prefill_6764
I
[ "is_prime", "closest_prime_less_than" ]
2
[ [ "closest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac77ed4bec6991d882443543df127b6739510e9e
5e22cf6945875f7cd9da21f1f91fe0c0d2d2f109
v1.0
instruct
Prefill
Prefill_6778_I
Write a function to filter prime numbers from a given list of integers and return the filtered list. The function should ensure that the list contains only prime numbers and no duplicates. The input list can contain negative numbers, and the output should only include positive prime numbers.
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 filter_primes...
from solution import filter_primes def test_with_mixed_numbers(): assert set(filter_primes([2, 3, 4, 5, -3, 6, -7, 11, 13])) == {2, 3, 5, 11, 13} def test_with_negative_numbers(): assert filter_primes([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == [] def test_with_prime_numbers(): assert set(filter_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": "Filters the prime numbers from a given list of integers and returns the filtered list \nwith unique positive pr...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ==...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006778", "row_id": 6778, "seed_ids": "['magpie_prefill_6778']" }
0.600558
Prefill_6778
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ffce2fe04c6617adba185351efa33c688e5a0df7
d0b7a65f5c2ec16ff108a2da2a3bcd241327dc4f
v1.0
instruct
Prefill
Prefill_6808_I
Write a function to return the sum of all the prime numbers up to and including n. For example, if n is 10, the output should be 17 because the prime numbers up to 10 are 2, 3, 5, and 7, and their sum is 17.
def is_prime(num): """ Returns True if the number is prime, else False. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0: return False return True d...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(13) == True def test_sum_of_primes(): a...
[ { "docstring": "Returns True if the number is prime, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers up to and including n.", "function_declaration": "def sum_of_pri...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00006808", "row_id": 6808, "seed_ids": "['magpie_prefill_6808']" }
0.679327
Prefill_6808
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac71475f1a9c2ca8db9806d76ca497ceb0634c0e
48ce1446f48c3924c304b5d6139277a965f38049
v1.0
instruct
Prefill
Prefill_6846_I
Write a function to recursively convert any JSON object into a sorted string, where all keys are sorted alphabetically. The output string should represent the sorted JSON object in a JSON string format.
import json def sort_json(obj): """ Recursively sorts a JSON object by its keys and returns it as a JSON string. """ if isinstance(obj, dict): sorted_obj = {k: sort_json(v) for k, v in sorted(obj.items())} elif isinstance(obj, list): sorted_obj = [sort_json(elem) for elem in obj] ...
from solution import json_to_sorted_string def test_simple_json(): assert json_to_sorted_string({"b": 1, "a": 2}) == '{\n "a": 2,\n "b": 1\n}' def test_nested_json(): input_json = {"c": {"b": 1, "a": 3}, "a": 2} expected_output = '{\n "a": 2,\n "c": {\n "a": 3,\n "b": 1\n }\n}' assert json_...
[ { "docstring": "Recursively sorts a JSON object by its keys and returns it as a JSON string.", "function_declaration": "def sort_json(obj):", "function_name": "sort_json", "parameter_list": "(obj)" }, { "docstring": "Converts a JSON object into a sorted string with keys sorted alphabetically...
[ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef json_to_sorted_string(obj):\n \"\"\"\n Recursively converts a JSON object into a sorted string,\n with all keys sorted alphabetically.\n \"\"\"\n if isinstan...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00006846", "row_id": 6846, "seed_ids": "['magpie_prefill_6846']" }
0.465571
Prefill_6846
I
[ "sort_json", "json_to_sorted_string" ]
2
[ [ "json_to_sorted_string", "sort_json" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b9a5468d7f462761c08572f519b4f7f92068e11
1c5a4147fb206291186c227327be540321b67cce
v1.0
instruct
Prefill
Prefill_6871_I
Write a function to crack a Caesar cipher. Explain the steps involved and provide code in Python.
def caesar_shift(text, shift): """ Shifts text by the given amount in the Caesar cipher manner. """ result = [] for char in text: if char.isalpha(): shift_base = ord('A') if char.isupper() else ord('a') result.append(chr((ord(char) - shift_base + shift) % 26 + shift_b...
from solution import caesar_shift, crack_caesar_cipher def test_caesar_shift(): assert caesar_shift("ABC", 1) == "BCD" assert caesar_shift("xyz", 3) == "abc" assert caesar_shift("Hello, World!", 5) == "Mjqqt, Btwqi!" def test_crack_caesar_cipher(): cipher_text = "Uifsf jt b tfdsfu nfttbhf" pr...
[ { "docstring": "Shifts text by the given amount in the Caesar cipher manner.", "function_declaration": "def caesar_shift(text, shift):", "function_name": "caesar_shift", "parameter_list": "(text, shift)" }, { "docstring": null, "function_declaration": "def crack_caesar_cipher(cipher_text...
[ 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_crack(ciphertext):\n \"\"\"\n Attempts to crack a Caesar cipher by trying all possible shifts (1 to 25).\n This function returns a list of possible plaintexts for e...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006871", "row_id": 6871, "seed_ids": "['magpie_prefill_6871']" }
0.589254
Prefill_6871
I
[ "caesar_shift", "crack_caesar_cipher" ]
2
[ [ "crack_caesar_cipher", "caesar_shift" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ca53a517c3cac095f8bfb1b96911f8406ec68d4
4a91a9c1d168b964647ce67210507eccbcd600a1
v1.0
instruct
Prefill
Prefill_7185_I
Write a function to calculate the sum of all prime numbers less than a given number n. Additionally, implement a function to check if a number is prime and use it within your main function to find the sum of all primes less than n.
def is_prime(num): """ Checks if a number is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def sum_of_pri...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_sum_of_primes(): ...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers less than n.", "function_declaration": "def sum_of_primes(n):", "functi...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num %...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007185", "row_id": 7185, "seed_ids": "['magpie_prefill_7185']" }
0.644494
Prefill_7185
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1c01ad7dc726115a8a3332c2c5b9162c116e9c1
3a25ad145052012096a3e9cad2c20550260ad3b6
v1.0
instruct
Prefill
Prefill_7349_I
Write a function to find the minimum cut in a network given the source and sink nodes, number of nodes, and the adjacency matrix representing the capacities. The function should return the minimum cut capacity.
from collections import deque def bfs_capacity_flow(residual_graph, source, sink, parent): """ Performs BFS to find if a path exists from source to sink. Fills parent to store the path and returns True if path is found, else False. """ visited = [False] * len(residual_graph) queue = deque([sou...
from solution import min_cut def test_min_cut_simple(): capacity_matrix = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0] ] assert min_cut(0, 5, 6, capacity_matrix) == 23 def test...
[ { "docstring": "Performs BFS to find if a path exists from source to sink. \nFills parent to store the path and returns True if path is found, else False.", "function_declaration": "def bfs_capacity_flow(residual_graph, source, sink, parent):", "function_name": "bfs_capacity_flow", "parameter_list":...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs_capacity_flow(residual_graph, source, sink, parent):\n \"\"\"\n Performs BFS to find if a path exists from source to sink. \n Fills parent to...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007349", "row_id": 7349, "seed_ids": "['magpie_prefill_7349']" }
0.522205
Prefill_7349
I
[ "bfs_capacity_flow", "min_cut" ]
2
[ [ "min_cut", "bfs_capacity_flow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a8e73dd31147d25b106dafb1927eab56cf942f1
81615f830be7ee7ebc8116f0f4d24c8ac3fc07a8
v1.0
instruct
Prefill
Prefill_7402_I
Write a function to return a list of all prime numbers between two given positive integers start and end (both inclusive). Make sure to include error handling for non-integer inputs and inputs where the start number is greater than the end number.
def is_prime(n): """Helper function to check if a number is prime.""" if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def primes_between(start, end): """ Returns a list of all prime numbers between start and end (bo...
import pytest from solution import primes_between def test_primes_between_valid_range(): assert primes_between(10, 20) == [11, 13, 17, 19] def test_primes_between_single_prime(): assert primes_between(5, 5) == [5] def test_primes_between_no_primes(): assert primes_between(8, 10) == [] def test_primes_be...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between start and end (both inclusive).\nHandles errors for non-integer inp...
[ 1, 1, 0, 1, 0, 1, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007402", "row_id": 7402, "seed_ids": "['magpie_prefill_7402']" }
0.647201
Prefill_7402
I
[ "is_prime", "primes_between" ]
2
[ [ "primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a1346efdc4f4aa6749691491428691355fda2c0
e8372d08cce4a1ed0cf22de112dfd9261332bc59
v1.0
instruct
Prefill
Prefill_7470_I
Write a function to find all the prime numbers within a given range. Your function should take two integers, start and end, as input and return a list of all prime numbers within that range.
def is_prime(n): """ Helper function to check if a number is a prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i...
from solution import find_primes_in_range, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(19) == True assert is_prime(20) == False def test_find_primes_in_range(): assert find_prime...
[ { "docstring": "Helper function to check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers within the given range [start, end].", "function_declaration": "def f...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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_8
{ "original_instruction": "", "prompt_id": "00007470", "row_id": 7470, "seed_ids": "['magpie_prefill_7470']" }
0.600712
Prefill_7470
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
860985580c68759a1c4801c02feda6a46d38d2d2
ac21cac8f3828d082397d70be3a5625a6e413a65
v1.0
instruct
Prefill
Prefill_7567_I
Write a function to perform mergesort on a list of integers.
def merge_sort(arr): """ Perform mergesort on a list of integers. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left, right): """ Merge two...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5, 6]) == [1, 2, 3, 4, 5, 6] def test_merge_sort_reverse_sorted_list(): asser...
[ { "docstring": "Perform mergesort on a list of integers.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merge two sorted lists into one sorted list.", "function_declaration": "def merge(left, right):", "fu...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on a list of integers.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n mid = len(arr) // 2\n left_half = merge_sort(a...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007567", "row_id": 7567, "seed_ids": "['magpie_prefill_7567']" }
0.759311
Prefill_7567
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a46b29ab12c1c45503d79314f0515278f0ac1951
55db7100f89b1f9df57696fee8ab81abc7a8ae55
v1.0
instruct
Prefill
Prefill_7654_I
Write a function to calculate the sum of the series 1/1! + 1/2! + 1/3! + ... + 1/n!, where n is a positive integer. The function should use a loop to iterate through the series and calculate the sum.
def factorial(n): """ Returns the factorial of n. """ if n == 0 or n == 1: return 1 else: result = 1 for i in range(2, n+1): result *= i return result def sum_of_series(n): """ Returns the sum of the series 1/1! + 1/2! + 1/3! + ... + 1/n!. """...
from solution import sum_of_series, factorial def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 def test_sum_of_series(): assert abs(sum_of_series(1) - 1.0) < 1e-10 ...
[ { "docstring": "Returns the factorial of n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the sum of the series 1/1! + 1/2! + 1/3! + ... + 1/n!.", "function_declaration": "def sum_of_series(n):", "funct...
[ 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Helper function to calculate factorial of a number n.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n factorial = 1\n for i in range(2, n+1)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007654", "row_id": 7654, "seed_ids": "['magpie_prefill_7654']" }
0.506409
Prefill_7654
I
[ "factorial", "sum_of_series" ]
2
[ [ "sum_of_series", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87e7b6e09ce40cd4714ddc2dc1986edb7184a1c0
57a6828c08b610f6bbc7b673b605bdc7b297042d
v1.0
instruct
Prefill
Prefill_7681_I
Write a function to calculate the sum of integers from 1 to `n`, without using any arithmetic operators. You can only use bitwise operators and looping constructs.
def add(a, b): """ Returns the sum of a and b using bitwise operators. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def sum_to_n(n): """ Returns the sum of integers from 1 to `n` using bitwise operators and loop constructs. """ total = 0 ...
from solution import sum_to_n def test_sum_to_1(): assert sum_to_n(1) == 1 def test_sum_to_5(): assert sum_to_n(5) == 15 # 1 + 2 + 3 + 4 + 5 = 15 def test_sum_to_10(): assert sum_to_n(10) == 55 # 1 + 2 + 3 + ... + 10 = 55 def test_sum_to_0(): assert sum_to_n(0) == 0 def test_sum_to_large_number()...
[ { "docstring": "Returns the sum of a and b using bitwise operators.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Returns the sum of integers from 1 to `n` using bitwise operators and loop constructs.", "function_declara...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add_without_arithmetic(a, b):\n \"\"\"\n Helper function to add two integers a and b using bitwise operators.\n \"\"\"\n while b != 0:\n # carry contains common set bit...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007681", "row_id": 7681, "seed_ids": "['magpie_prefill_7681']" }
0.638344
Prefill_7681
I
[ "add", "sum_to_n" ]
2
[ [ "sum_to_n", "add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
daf599f05f4578217897b04ec69420a8c5e743eb
1ded70cfd523c88b43910b40604133a29372acf3
v1.0
instruct
Prefill
Prefill_7704_I
Write a function to convert a depth-first search (DFS) traversal of a binary tree into a balanced binary search tree (BST). The conversion should be done iteratively.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def sorted_array_to_bst(arr): if not arr: return None mid = len(arr) // 2 root = TreeNode(arr[mid]) stack = [(root, arr[:mid], arr[mid+1:])] whi...
from solution import TreeNode, dfs_to_balanced_bst def inorder_traversal(root): """ Helper function to check the inorder traversal of BST """ return inorder_traversal(root.left) + [root.val] + inorder_traversal(root.right) if root else [] def is_balanced(root): """ Helper function to check if the tree is ...
[]
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef sorted_array_to_bst(nums):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007704", "row_id": 7704, "seed_ids": "['magpie_prefill_7704']" }
0.620863
Prefill_7704
I
[ "sorted_array_to_bst", "dfs_to_balanced_bst" ]
2
[ [ "dfs_to_balanced_bst", "sorted_array_to_bst" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
fa2c1b5ba8741994c737e21f756855fdb622a4d0
64d012f4cf82141c6981b144adb3e3c4a60efe08
v1.0
instruct
Prefill
Prefill_7735_I
Write a function to find the length of the longest palindromic substring in a given string. I need a detailed explanation with the code in Python.
def longest_palindromic_substring(s): """ Returns the length of the longest palindromic substring in the given string. :param s: Input string :return: Length of the longest palindromic substring """ n = len(s) if n == 0: return 0 # Starting and ending indices of the longest...
from solution import longest_palindromic_substring def test_longest_palindromic_substring_empty_string(): assert longest_palindromic_substring("") == 0 def test_longest_palindromic_substring_single_character(): assert longest_palindromic_substring("a") == 1 def test_longest_palindromic_substring_no_palindrom...
[ { "docstring": "Returns the length of the longest palindromic substring in the given string.\n\n:param s: Input string\n:return: Length of the longest palindromic substring", "function_declaration": "def longest_palindromic_substring(s):", "function_name": "longest_palindromic_substring", "parameter...
[ 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_length(s):\n \"\"\"\n Returns the length of the longest palindromic substring in the given string.\n \"\"\"\n n = len(s)\n if n == 0:\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007735", "row_id": 7735, "seed_ids": "['magpie_prefill_7735']" }
0.839785
Prefill_7735
I
[ "longest_palindromic_substring", "expand_around_center" ]
2
[ [ "longest_palindromic_substring", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3cd271758ec1af3feffa8e8c304b6d7fbe822308
e2513f3109257ab4b43ab4d918af40cfcd391c8e
v1.0
instruct
Prefill
Prefill_7889_I
Write a function to calculate the length of the longest palindrome substring in a given string. A palindrome is a string that reads the same backward as forward. For example, "racecar" is a palindrome. Your function should return the length of the longest such substring. For instance, given the string "babad", the func...
def longest_palindrome_substring_length(s): """ Returns the length of the longest palindromic substring in the given string s. """ if not s: return 0 n = len(s) longest_length = 0 for i in range(n): # check for odd length palindromes centered at i length = expand_ar...
from solution import longest_palindrome_substring_length def test_longest_palindrome_substring_length(): # Test with example case assert longest_palindrome_substring_length("babad") == 3 # Test with no palindrome assert longest_palindrome_substring_length("abcd") == 1 # Test with all characters s...
[ { "docstring": "Returns the length of the longest palindromic substring in the given string s.", "function_declaration": "def longest_palindrome_substring_length(s):", "function_name": "longest_palindrome_substring_length", "parameter_list": "(s)" }, { "docstring": "Expands around the center...
[ 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_length(s):\n \"\"\"\n Returns the length of the longest palindromic substring in the given string s.\n \"\"\"\n n = len(s)\n if n == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007889", "row_id": 7889, "seed_ids": "['magpie_prefill_7889']" }
0.843837
Prefill_7889
I
[ "longest_palindrome_substring_length", "expand_around_center" ]
2
[ [ "longest_palindrome_substring_length", "expand_around_center" ] ]
1
[]
false
[]
false
pytest
true
[]
true
209f66dac852369737dfb98fd8fbf9be0b030001
66ce70e88dd37f32e01ebc549c785b6a051366b6
v1.0
instruct
Prefill
Prefill_7937_I
Write a function to calculate the sum of all prime numbers in a given list of integers.
def is_prime(n): """ Checks 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 sum_of_primes(numbers): """ Returns the sum of all prime numbers in a given list of integers. "...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prime(1) == False assert is_prime(0) == Fals...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in a given list of integers.", "function_declaration": "def sum_of_primes(numbers):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00007937", "row_id": 7937, "seed_ids": "['magpie_prefill_7937']" }
0.674328
Prefill_7937
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0aad3f624505f64590cfd1f3854252f55ab69761
a2588a338d236ebaaabca43570963eda40b35973
v1.0
instruct
Prefill
Prefill_7991_I
Write a function to delete a node in a Binary Search Tree (BST) without using a parent pointer. The function should return the root of the BST after the deletion.
class TreeNode: def __init__(self, key, left=None, right=None): self.key = key self.left = left self.right = right def delete_node(root, key): """ Deletes a node with the given key in a Binary Search Tree (BST) and returns the root of the new BST. """ if root is None: ...
from solution import TreeNode, delete_node def inorder_traversal(root): """ Helper function to return the inorder traversal of the BST. """ return inorder_traversal(root.left) + [root.key] + inorder_traversal(root.right) if root else [] def test_delete_node_leaf(): root = TreeNode(4, TreeNode(2, T...
[]
[ 0, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_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 deleteNode(root, key):\n if not ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007991", "row_id": 7991, "seed_ids": "['magpie_prefill_7991']" }
0.448435
Prefill_7991
I
[ "delete_node", "min_value_node" ]
2
[ [ "delete_node", "min_value_node" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0a9bb4cf2765601d8afec8dee2199b1053567956
7fe2fcff957f70adc968e5fdebf9f76037fa921a
v1.0
instruct
Prefill
Prefill_8132_I
Write a function to determine if a given integer is a palindrome and if so, find the number of steps required to transform it into a palindrome by repeatedly reversing and adding the number to itself.
def is_palindrome(n): """ Checks if the given integer n is a palindrome. """ return str(n) == str(n)[::-1] def steps_to_palindrome(n): """ Returns a tuple (is_palindrome, steps) where: - is_palindrome is a boolean indicating if n is already a palindrome. - steps is the number of steps r...
from solution import is_palindrome, steps_to_palindrome, palindrome_transformation def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(10) == False def test_steps_to_palindrome(): assert steps_to_pa...
[ { "docstring": "Checks if the given integer n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns a tuple (is_palindrome, steps) where:\n- is_palindrome is a boolean indicating if n is alread...
[ 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if the given integer n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef steps_to_palindrome(n):\n \"\"\"\n Returns th...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008132", "row_id": 8132, "seed_ids": "['magpie_prefill_8132']" }
0.720194
Prefill_8132
I
[ "is_palindrome", "steps_to_palindrome", "palindrome_transformation" ]
3
[ [ "palindrome_transformation", "is_palindrome" ], [ "palindrome_transformation", "steps_to_palindrome" ], [ "steps_to_palindrome", "is_palindrome" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6562635cf4b43ef86345b975aec9a66c7e9bd1bd
015d068b1998f695393d9ab12c44c662a056e55a
v1.0
instruct
Prefill
Prefill_8167_I
Write a function to check if two strings are anagrams without using any built-in functions or data structures like dictionaries.
def are_anagrams(str1, str2): """ Check if two strings are anagrams by comparing the sorted versions of the strings. """ # If lengths are not equal, they cannot be anagrams if len(str1) != len(str2): return False # Sorting both strings sorted_str1 = sorted_characters(str1) sorte...
from solution import are_anagrams def test_anagrams_positive(): assert are_anagrams("listen", "silent") == True assert are_anagrams("triangle", "integral") == True assert are_anagrams("earth", "heart") == True def test_anagrams_negative(): assert are_anagrams("hello", "bello") == False assert are_...
[ { "docstring": "Check if two strings are anagrams by comparing the sorted versions of the strings.", "function_declaration": "def are_anagrams(str1, str2):", "function_name": "are_anagrams", "parameter_list": "(str1, str2)" }, { "docstring": "Helper function to sort characters in a string wi...
[ 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_anagrams(str1, str2):\n \"\"\"\n Check if two strings are anagrams without using any built-in functions or data structures.\n \"\"\"\n if len(str1) != len(str2):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008167", "row_id": 8167, "seed_ids": "['magpie_prefill_8167']" }
0.542201
Prefill_8167
I
[ "are_anagrams", "sorted_characters" ]
2
[ [ "are_anagrams", "sorted_characters" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4cc1ba76345938b1b3ddb7a9baaa0596e0cffced
2d7bd267c13b5b06f0afc74754ded7436143b195