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_8218_I
Write a function to find all the prime numbers within a given range [m, n].
def is_prime(num): """Helper function to check if a number is prime.""" if num <= 1: return False elif num == 2: return True elif 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 find_pr...
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(20) == False assert is_prime(1) == False assert is_prime(-5) == False def test_find_primes_...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers within the range [m, n].\n\nArguments:\nm -- Starting integer of the range ...
[ 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 prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008218", "row_id": 8218, "seed_ids": "['magpie_prefill_8218']" }
0.641573
Prefill_8218
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
451998a6fa66b03abf176adf0b9a156c99fd507b
9c52a87a380596ded640bf1a4a971bd18b7d17a6
v1.0
instruct
Prefill
Prefill_8331_I
Write a function to check if a given list of numbers can be divided into subsets with equal sum. The function should return `true` if it's possible, and `false` otherwise. The function should also printing the subsets if it's possible.
def can_partition(nums): """ Returns True if the given list nums can be partitioned into subsets with equal sum, otherwise returns False. """ total_sum = sum(nums) # If total sum is odd, it can't be partitioned into two subsets with equal sum if total_sum % 2 != 0: return False ...
from solution import can_partition, can_partition_with_subsets def test_can_partition_true(): assert can_partition([1, 5, 11, 5]) == True def test_can_partition_false(): assert can_partition([1, 2, 3, 5]) == False def test_can_partition_with_subsets_true(): assert can_partition_with_subsets([1, 5, 11, 5]...
[ { "docstring": "Returns True if the given list nums can be partitioned into subsets with equal sum, otherwise returns False.", "function_declaration": "def can_partition(nums):", "function_name": "can_partition", "parameter_list": "(nums)" }, { "docstring": "Helper function to find the subse...
[ 0, 0, 1, 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": "def can_partition(nums):\n \"\"\"\n Returns True if the array can be partitioned into two subsets with equal sum, False otherwise.\n Also, prints the subsets if it's possible.\n \...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00008331", "row_id": 8331, "seed_ids": "['magpie_prefill_8331']" }
0.685571
Prefill_8331
I
[ "can_partition", "find_subsets", "can_partition_with_subsets" ]
3
[ [ "can_partition_with_subsets", "can_partition" ], [ "can_partition_with_subsets", "find_subsets" ] ]
2
[]
false
[]
false
pytest
true
[]
true
222997db991b6d2e3c4d0b536d245db226685323
bb7ed61c5a7cbb14075ebac91272bea35db4bfe7
v1.0
instruct
Prefill
Prefill_8362_I
Write a function to calculate the factorial of a number using recursion. Then, write another function to calculate the factorial using iteration. Finally, compare the performance of both methods using a large input number (e.g., 10!).
import time def factorial_recursive(n): """ Returns the factorial of n using recursion. """ if n == 0 or n == 1: return 1 return n * factorial_recursive(n - 1) def factorial_iterative(n): """ Returns the factorial of n using iteration. """ result = 1 for i in range(2, n...
from solution import factorial_recursive, factorial_iterative, compare_performance def test_factorial_recursive_base_cases(): assert factorial_recursive(0) == 1 assert factorial_recursive(1) == 1 def test_factorial_recursive_general_cases(): assert factorial_recursive(5) == 120 assert factorial_recurs...
[ { "docstring": "Returns the factorial of n using recursion.", "function_declaration": "def factorial_recursive(n):", "function_name": "factorial_recursive", "parameter_list": "(n)" }, { "docstring": "Returns the factorial of n using iteration.", "function_declaration": "def factorial_ite...
[ 1, 1, 1, 0, 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": "import time\n\ndef factorial_recursive(n):\n \"\"\"\n Calculates the factorial of n using recursion.\n \"\"\"\n if n == 0:\n return 1\n return n * factorial_recursive(n-...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00008362", "row_id": 8362, "seed_ids": "['magpie_prefill_8362']" }
0.530831
Prefill_8362
I
[ "factorial_recursive", "factorial_iterative", "compare_performance" ]
3
[ [ "compare_performance", "factorial_iterative" ], [ "compare_performance", "factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7ad9fd403074a1ab44dec7485a118d13b9ea536c
23c35f08e3ad6474dd283e48e4b84577613e7644
v1.0
instruct
Prefill
Prefill_8389_I
Write a function to encode and decode a message using the Caesar cipher.
def caesar_cipher_encode(message, shift): """ Encodes the message using the Caesar cipher with a given shift. """ encoded_message = "" for char in message: if char.isalpha(): shift_base = ord('A') if char.isupper() else ord('a') encoded_message += chr((ord(char) - shi...
from solution import caesar_cipher_encode, caesar_cipher_decode def test_caesar_cipher_encode(): assert caesar_cipher_encode("HELLO", 3) == "KHOOR" assert caesar_cipher_encode("hello", 3) == "khoor" assert caesar_cipher_encode("HELLO world!", 3) == "KHOOR zruog!" def test_caesar_cipher_decode(): asser...
[ { "docstring": "Encodes the message using the Caesar cipher with a given shift.", "function_declaration": "def caesar_cipher_encode(message, shift):", "function_name": "caesar_cipher_encode", "parameter_list": "(message, shift)" }, { "docstring": "Decodes the message using the Caesar cipher ...
[ 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 caesar_cipher_encode(message, shift):\n \"\"\"\n Encode a message using Caesar cipher with a given shift.\n \"\"\"\n encoded_message = []\n for char in message:\n if...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008389", "row_id": 8389, "seed_ids": "['magpie_prefill_8389']" }
0.592705
Prefill_8389
I
[ "caesar_cipher_encode", "caesar_cipher_decode" ]
2
[ [ "caesar_cipher_decode", "caesar_cipher_encode" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43d37a80dc6c50d969d3e050ac390f307dffe165
598001b0988606eb8d24cdb6b0d8abc201988b71
v1.0
instruct
Prefill
Prefill_8511_I
Write a function to find the lowest common ancestor in a Binary Search Tree (BST). The function should return the root of the lowest common ancestor of two given nodes if they exist, and return null if either of nodes does not exist in the BST. Assume that both input nodes are distinct.
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_lowest_common_ancestor(root, p, q): """ Finds the lowest common ancestor in a Binary Search Tree (BST). Args: root (TreeNode): The root node of the BST. p (int): The valu...
from solution import TreeNode, find_lowest_common_ancestor def test_lca_both_nodes_exist(): root = TreeNode(6) root.left = TreeNode(2) root.right = TreeNode(8) root.left.left = TreeNode(0) root.left.right = TreeNode(4) root.right.left = TreeNode(7) root.right.right = TreeNode(9) root.le...
[]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 0 ]
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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef find(root, value):\n \"\"\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008511", "row_id": 8511, "seed_ids": "['magpie_prefill_8511']" }
0.516133
Prefill_8511
I
[ "find_lowest_common_ancestor", "find_node" ]
2
[ [ "find_lowest_common_ancestor", "find_node" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
debad5547b29fcd5e04b4394a4a0fbf09a0fa6ed
e2734ca751a307544c2994693381b4e6d7a98029
v1.0
instruct
Prefill
Prefill_8598_I
Write a function to interpret the value in a 2D array and return its corresponding color name based on the value.
def value_to_color(value): """ Maps a numeric value to its corresponding color name. """ color_map = { 0: 'Black', 1: 'White', 2: 'Red', 3: 'Green', 4: 'Blue', 5: 'Yellow' } return color_map.get(value, 'Unknown') def interpret_2D_array(array)...
from solution import interpret_2D_array def test_interpret_empty_array(): result = interpret_2D_array([]) expected = [] assert result == expected def test_interpret_single_element_array(): result = interpret_2D_array([[0]]) expected = [['Black']] assert result == expected result = int...
[ { "docstring": "Maps a numeric value to its corresponding color name.", "function_declaration": "def value_to_color(value):", "function_name": "value_to_color", "parameter_list": "(value)" }, { "docstring": "Interprets a 2D array of numeric values, translating each value into its correspondi...
[ 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 get_color_name(value):\n \"\"\"\n Returns the color name corresponding to the input value.\n \n Parameters:\n value (int): The value to interpret.\n \n Returns:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008598", "row_id": 8598, "seed_ids": "['magpie_prefill_8598']" }
0.51856
Prefill_8598
I
[ "value_to_color", "interpret_2D_array" ]
2
[ [ "interpret_2D_array", "value_to_color" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89fcb943c849d8e9504227a8613cf180bf145fbb
78c2c80fc7dc3c961214261b1784647dc015740b
v1.0
instruct
Prefill
Prefill_8637_I
Write a function to create a binary search tree from a list of keys. The function should return the root of the binary search tree.
class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None def insert(root, key): """ Inserts a key into the BST. """ if root is None: return TreeNode(key) if key < root.key: root.left = insert(root.left, key) else: ...
from solution import TreeNode, create_bst_from_list def inorder_traversal(root): """ Helper function to perform inorder traversal of a BST. It returns a list of all keys in sorted order. """ result = [] if root: result = inorder_traversal(root.left) result.append(root.key) ...
[]
[ 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": "class TreeNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\ndef insert(root, key):\n \"\"\"\n Helper function to insert...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008637", "row_id": 8637, "seed_ids": "['magpie_prefill_8637']" }
0.553317
Prefill_8637
I
[ "insert", "create_bst_from_list" ]
2
[ [ "create_bst_from_list", "insert" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
273b6de5e47956155c1702fce58ce96f625c4d4b
9af535c3ddca84aaaa8b8874e5b1a4fd063827d7
v1.0
instruct
Prefill
Prefill_8737_I
Write a function to generate a list of prime numbers within a given range [start, end].
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 for current in range(3, int(n**0.5) + 1, 2): if n % current == 0: return False return True def generate_...
from solution import generate_primes, is_prime def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(11) def test_generate_primes_normal_range(): assert generate_primes(10, 20) ...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a list of prime numbers within the given range [start, end].", "function_declaration": "def generate_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 \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n re...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008737", "row_id": 8737, "seed_ids": "['magpie_prefill_8737']" }
0.633536
Prefill_8737
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31b4b02c96b730ff66da9165dd0de0547104c1c7
a9516f193801c279125404cdaa86a703b6600787
v1.0
instruct
Prefill
Prefill_8831_I
Write a function to reverse a string in Python, and also create a function to check if a given string is a palindrome. A string is considered a palindrome if it reads the same backward as forward.
def reverse_string(s): """ Returns the reverse of the input string s. """ return s[::-1] def is_palindrome(s): """ Returns True if the input string s is a palindrome, False otherwise. """ reversed_s = reverse_string(s) return s == reversed_s
from solution import reverse_string, is_palindrome def test_reverse_string(): assert reverse_string('hello') == 'olleh' assert reverse_string('') == '' assert reverse_string('12345') == '54321' assert reverse_string('a') == 'a' def test_is_palindrome(): assert is_palindrome('racecar') == True ...
[ { "docstring": "Returns the reverse of the input string s.", "function_declaration": "def reverse_string(s):", "function_name": "reverse_string", "parameter_list": "(s)" }, { "docstring": "Returns True if the input string s is a palindrome, False otherwise.", "function_declaration": "def...
[ 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 Returns the reversed version of the input string s.\n \"\"\"\n return s[::-1]\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the input strin...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008831", "row_id": 8831, "seed_ids": "['magpie_prefill_8831']" }
0.787827
Prefill_8831
I
[ "reverse_string", "is_palindrome" ]
2
[ [ "is_palindrome", "reverse_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1227d3ddebf9fb1e97429f55d9c91b1d15049bd9
db42ed9d78e3ebcdae4c6e3e93052da4cdaefc56
v1.0
instruct
Prefill
Prefill_8920_I
Write a function to find the maximum area of a rectangle in a given binary matrix. The matrix contains only 0s and 1s, and each cell represents a square that is either empty or filled with a bar.
def maximalRectangle(matrix): if not matrix: return 0 max_area = 0 dp = [[0]*len(matrix[0]) for _ in range(len(matrix))] for i in range(len(matrix)): for j in range(len(matrix[0])): if matrix[i][j] == '1': dp[i][j] = dp[i][j-1] + 1 if j > 0 else 1 ...
from solution import maximalRectangle def test_empty_matrix(): assert maximalRectangle([]) == 0 def test_matrix_with_no_ones(): assert maximalRectangle([["0", "0"], ["0", "0"]]) == 0 def test_matrix_with_all_ones(): assert maximalRectangle([["1", "1"], ["1", "1"]]) == 4 def test_single_row_m...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n n = len(matrix[0])\n heights = [0] * n\n\n for row in matrix:\n for i in range(n):\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008920", "row_id": 8920, "seed_ids": "['magpie_prefill_8920']" }
0.664064
Prefill_8920
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
030b377b38eb5908f5f799f9be7b718fc2edf4ec
96091fcf4ab54228569aafef4cb80ecf0a57d32c
v1.0
instruct
Prefill
Prefill_9015_I
Write a function to reverse a stack of integers using recursion.
def insert_at_bottom(stack, item): """ Helper function to insert an item at the bottom of a given stack. """ if not stack: stack.append(item) else: temp = stack.pop() insert_at_bottom(stack, item) stack.append(temp) def reverse_stack(stack): """ Reverses a gi...
from solution import reverse_stack def test_reverse_stack_empty(): assert reverse_stack([]) == [] def test_reverse_stack_single_element(): assert reverse_stack([1]) == [1] def test_reverse_stack_multiple_elements(): assert reverse_stack([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1] def test_reverse_stack_already_...
[ { "docstring": "Helper function to insert an item at the bottom of a given stack.", "function_declaration": "def insert_at_bottom(stack, item):", "function_name": "insert_at_bottom", "parameter_list": "(stack, item)" }, { "docstring": "Reverses a given stack using recursion. The original sta...
[ 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 using recursion.\n \"\"\"\n if not stack:\n return\n \n top_element = stack.pop()\n reverse_stack(stack)\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009015", "row_id": 9015, "seed_ids": "['magpie_prefill_9015']" }
0.600006
Prefill_9015
I
[ "insert_at_bottom", "reverse_stack" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
017294155d4d726c20ba63458177478011b3ad67
1a60c4cf40e4619e1f88b4190ddd97bceb2d9603
v1.0
instruct
Prefill
Prefill_9110_I
Write a function to calculate the number of occurrences of each character in a given string and print the result in the format "character: count".
def count_characters(s): """ Returns a dictionary with the counts of each character in the string s. """ count_dict = {} for char in s: if char in count_dict: count_dict[char] += 1 else: count_dict[char] = 1 return count_dict def print_character_counts(s)...
from solution import count_characters, print_character_counts import io import sys def test_count_characters_empty_string(): assert count_characters("") == {} def test_count_characters_single_character(): assert count_characters("a") == {'a': 1} def test_count_characters_multiple_characters(): assert cou...
[ { "docstring": "Returns a dictionary with the counts of each character in the string s.", "function_declaration": "def count_characters(s):", "function_name": "count_characters", "parameter_list": "(s)" }, { "docstring": "Prints the counts of each character in the string s in the format \"ch...
[ 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 character_occurrences(s):\n \"\"\"\n Returns a dictionary with the number of occurrences of each character in the string s.\n \"\"\"\n occurrences = {}\n for char in s:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009110", "row_id": 9110, "seed_ids": "['magpie_prefill_9110']" }
0.860686
Prefill_9110
I
[ "count_characters", "print_character_counts" ]
2
[ [ "print_character_counts", "count_characters" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c21c673360fded7048305e68d14a0f4ac135127a
6cbb0427fa8cffb04232410eed232fa2bba344de
v1.0
instruct
Prefill
Prefill_9119_I
Write a function to provide an XML representation of a given JSON object.
import json from xml.etree.ElementTree import Element, tostring, ElementTree def json_to_xml(json_obj, line_padding=""): """ Converts a JSON object to an XML string. """ def _to_xml(element, json_obj): if isinstance(json_obj, dict): for tag_name, sub_obj in json_obj.items(): ...
import json from solution import json_to_xml, convert_json_to_xml_string def test_json_to_xml_simple(): json_obj = {"name": "John", "age": 30} expected_xml = b'<root><name>John</name><age>30</age></root>' assert json_to_xml(json_obj) == expected_xml def test_json_to_xml_list(): json_obj = {"employees"...
[ { "docstring": "Converts a JSON object to an XML string.", "function_declaration": "def json_to_xml(json_obj, line_padding=''):", "function_name": "json_to_xml", "parameter_list": "(json_obj, line_padding='')" }, { "docstring": null, "function_declaration": "def convert_json_to_xml_strin...
[ 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nimport xml.etree.ElementTree as ET\n\ndef json_to_xml(json_obj, line_padding=\"\"):\n \"\"\"\n Converts a JSON object to an XML string.\n\n Parameters:\n - json_obj: ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00009119", "row_id": 9119, "seed_ids": "['magpie_prefill_9119']" }
0.657698
Prefill_9119
I
[ "json_to_xml", "convert_json_to_xml_string" ]
2
[ [ "convert_json_to_xml_string", "json_to_xml" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3cc3d3d5ffef86c68d9d5849987224b2f1a73980
d0e20ec6ec0ff92b636a145368a18aaef4436a1c
v1.0
instruct
Prefill
Prefill_9167_I
Write a function to delete an element from a binary search tree (BST). The function should handle all possible cases including when the node to be deleted is a leaf, a node with one child, or a node with two children.
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 not root: return root if key < root.key: root.left = delete_node(root.left, key) elif key > root.key: root.r...
import pytest from solution import TreeNode, delete_node, insert_node, inorder_traversal def test_delete_leaf_node(): root = None nodes = [5, 3, 7, 2, 4, 6, 8] for key in nodes: root = insert_node(root, key) root = delete_node(root, 2) assert inorder_traversal(root) == [3, 4, 5, 6, 7, ...
[]
[ 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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef deleteNode(root, key):\n \"\"\"\n Deletes a node from t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00009167", "row_id": 9167, "seed_ids": "['magpie_prefill_9167']" }
0.545539
Prefill_9167
I
[ "delete_node", "find_minimum_node", "insert_node", "inorder_traversal" ]
4
[ [ "delete_node", "find_minimum_node" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
72c8fa6e74dd341070a7419e54602bfd5fcce609
f2218ea2c8093e01910f975faab52b80a94b89e6
v1.0
instruct
Prefill
Prefill_9206_I
Write a function to find the largest palindrome made from the product of two n-digit numbers. Given integer n, return the largest palindrome of length 2 * n. The function should return -1 if there is no such palindrome. For example, for n=2, the largest palindrome made from the product of two two-digit numbers is 9009 ...
def is_palindrome(num): """ Helper function to check if a number is a palindrome. """ return str(num) == str(num)[::-1] def largest_palindrome_product(n): """ Returns the largest palindrome made from the product of two n-digit numbers. """ if n < 1: return -1 max_nu...
from solution import largest_palindrome_product def test_largest_palindrome_product_2_digits(): assert largest_palindrome_product(2) == 9009 def test_largest_palindrome_product_3_digits(): assert largest_palindrome_product(3) == 906609 def test_largest_palindrome_product_1_digit(): assert largest_palindr...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the largest palindrome made from the product of two n-digit numbers.", "functi...
[ 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_palindrome_product(n):\n \"\"\"\n Returns the largest palindrome made from the product of two n-digit numbers.\n If there is no such palindrome, returns -1.\n \"\"\"\n...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00009206", "row_id": 9206, "seed_ids": "['magpie_prefill_9206']" }
0.775201
Prefill_9206
I
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c694dce8efdf30d8d3bc60f1f6c228ae3fbe7f1
f0d59fcd42dc9011cabd884f6be4a652cecabecc
v1.0
instruct
Prefill
Prefill_9212_I
Write a function to sort a linked list.
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def sort_linked_list(head): """ Sorts a linked list in ascending order and returns the head of the sorted list. :param head: ListNode, the head of the linked list :return: ListNode, the head o...
from solution import ListNode, sort_linked_list def list_to_linked_list(elements): head = ListNode(elements[0]) current = head for element in elements[1:]: current.next = ListNode(element) current = current.next return head def linked_list_to_list(head): elements = [] current =...
[]
[ 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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef sort_linked_list(head):\n \"\"\"\n Sorts a linked list in ascending o...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009212", "row_id": 9212, "seed_ids": "['magpie_prefill_9212']" }
0.698661
Prefill_9212
I
[ "sort_linked_list", "merge_sorted_lists" ]
2
[ [ "sort_linked_list", "merge_sorted_lists" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
8ee84f9b9d73066b73b26a0a38aa3a644b62bc88
73fce96132f7abdd803f95024a84412b70b80d65
v1.0
instruct
Prefill
Prefill_9316_I
Write a function to find the in-order successor of a node in a binary search tree (BST) where node values are unique. The in-order successor of a node is the node with the smallest value that is larger than the node's value. You may assume that each node in the tree has a link to its parent node in addition to its left...
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 min_value_node(node): current = node while current.left is not None: current = current.left return cur...
import pytest from solution import TreeNode, inorder_successor def create_sample_tree(): # Constructing the BST root = TreeNode(20) node8 = TreeNode(8) node22 = TreeNode(22) node4 = TreeNode(4) node12 = TreeNode(12) node10 = TreeNode(10) node14 = TreeNode(14) root.left = node8 ...
[]
[ 1, 1, 1, 1, 1, 0, 1, 1, 0 ]
7
easy
0.778
{ "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_0
{ "original_instruction": "", "prompt_id": "00009316", "row_id": 9316, "seed_ids": "['magpie_prefill_9316']" }
0.547744
Prefill_9316
I
[ "min_value_node", "inorder_successor" ]
2
[ [ "inorder_successor", "min_value_node" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
1830cda661e72f4c354e8973b1a0fd0f42a22880
0e7759d48d1da4ea14c861c74bc2498c5722c396
v1.0
instruct
Prefill
Prefill_9323_I
Write a function to implement the classic game "Tic-Tac-Toe" on a 3x3 grid using a 2D array. Your function should handle player inputs, check for a win or a draw, and continue the game until it ends.
def check_win(board, player): """ Checks if the given player has won the game. """ # Check rows, columns, and diagonals win_conditions = [ [board[0][0], board[0][1], board[0][2]], [board[1][0], board[1][1], board[1][2]], [board[2][0], board[2][1], board[2][2]], [board...
from solution import play_tic_tac_toe def test_tic_tac_toe_X_wins(): moves = [('X', 0, 0), ('O', 1, 1), ('X', 0, 1), ('O', 2, 2), ('X', 0, 2)] assert play_tic_tac_toe(moves) == 'X' def test_tic_tac_toe_O_wins(): moves = [('X', 0, 0), ('O', 1, 1), ('X', 0, 1), ('O', 0, 2), ('X', 2, 2), ('O', 2, 0)] ass...
[ { "docstring": "Checks if the given player has won the game.", "function_declaration": "def check_win(board, player):", "function_name": "check_win", "parameter_list": "(board, player)" }, { "docstring": "Checks if the game board is a draw.", "function_declaration": "def check_draw(board...
[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TicTacToe:\n def __init__(self):\n self.board = [[' ' for _ in range(3)] for _ in range(3)]\n self.current_player = 'X'\n\n def print_board(self):\n for row i...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00009323", "row_id": 9323, "seed_ids": "['magpie_prefill_9323']" }
0.523546
Prefill_9323
I
[ "check_win", "check_draw", "play_tic_tac_toe" ]
3
[ [ "play_tic_tac_toe", "check_draw" ], [ "play_tic_tac_toe", "check_win" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1455a11e2eddeea5c9b4099b5a79d9360ed61026
7a125f3ecda204591e75a1e68d7a313591189afb
v1.0
instruct
Prefill
Prefill_9521_I
Write a function to determine the largest prime number less than or equal to a given number `n`.
def is_prime(num): """ Helper function to determine 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: retu...
from solution import largest_prime def test_largest_prime_basic_cases(): assert largest_prime(10) == 7 assert largest_prime(20) == 19 def test_largest_prime_edge_cases(): assert largest_prime(2) == 2 assert largest_prime(3) == 3 assert largest_prime(4) == 3 def test_largest_prime_no_prime(): ...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the largest prime number less than or equal to n.\nIf no prime number is found, returns None.",...
[ 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 Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num %...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00009521", "row_id": 9521, "seed_ids": "['magpie_prefill_9521']" }
0.70219
Prefill_9521
I
[ "is_prime", "largest_prime" ]
2
[ [ "largest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c0e69c251cfa36f971ffffcfec471f86c3234ad4
5e83859b52bfd8abcb4d523b29f41601560ee7ba
v1.0
instruct
Prefill
Prefill_9600_I
Write a function to find the LCA (Lowest Common Ancestor) of an N-ary Tree.
class TreeNode: def __init__(self, val): self.val = val self.children = [] def find_path(root, path, k): if root is None: return False path.append(root.val) if root.val == k: return True for child in root.children: if find_path(child, path, k): ...
import pytest from solution import TreeNode, lca def test_lca_basic(): root = TreeNode(1) child1 = TreeNode(2) child2 = TreeNode(3) child3 = TreeNode(4) root.children.extend([child1, child2, child3]) assert lca(root, 2, 3) == 1 def test_lca_single_ancestor(): root = TreeNode(1) ch...
[]
[ 1, 1, 1, 0, 0, 1, 0, 1, 1, 1 ]
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, val):\n self.val = val\n self.children = []\n\ndef find_path(root, path, k):\n if root is None:\n return False\n \n path....
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00009600", "row_id": 9600, "seed_ids": "['magpie_prefill_9600']" }
0.544561
Prefill_9600
I
[ "find_path", "lca" ]
2
[ [ "lca", "find_path" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6616c25588cb900b4c5902ad56c0b6df2345e1c0
70063024cf551447256c7c71cdc22b1f43f626e2
v1.0
instruct
Prefill
Prefill_9664_I
Write a function to detect duplicate files using a rolling hash. Rolling hash is a type of hash in which the hash value changes little with little change in the data. It's often used for detecting file duplicates because it can be computationally efficient. Can you provide a Python implementation for this?
import hashlib import os def compute_hash(file_path): """ Compute the SHA-1 hash of the given file. This function uses a rolling hash technique by reading the file in chunks. """ hasher = hashlib.sha1() with open(file_path, 'rb') as file: while chunk := file.read(8192): hash...
import os import sys import shutil import tempfile import hashlib # Adding temporary directory and files to the system path for importing solution functions. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from solution import compute_hash, find_duplicate_files def create_temp_files_with_content(direc...
[ { "docstring": "Compute the SHA-1 hash of the given file.\nThis function uses a rolling hash technique by reading the file in chunks.", "function_declaration": "def compute_hash(file_path):", "function_name": "compute_hash", "parameter_list": "(file_path)" }, { "docstring": "Detect duplicate...
[ 0, 1, 1, 1, 1, 0, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\n\ndef rolling_hash(file_content: str, base: int=257, mod: int=1000000007) -> int:\n \"\"\"\n Computes a rolling hash for a given file content.\n \n Args:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009664", "row_id": 9664, "seed_ids": "['magpie_prefill_9664']" }
0.645051
Prefill_9664
I
[ "compute_hash", "find_duplicate_files" ]
2
[ [ "find_duplicate_files", "compute_hash" ] ]
1
[]
false
[]
false
pytest
true
[]
true
21a9d38cadb7efc386805b96910c4cfa0284458a
12e92758e7dd792b86dac0cc391945f43cceac33
v1.0
instruct
Prefill
Prefill_9764_I
Write a function to compute and display the sum of the first N prime numbers. Here is a Python function to find the sum of the first N prime numbers.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return F...
from solution import is_prime, sum_of_first_n_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(1) == False assert is_prime(0) ...
[ { "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 the first N prime numbers.", "function_declaration": "def sum_of_first_n_primes(N):"...
[ 1, 1, 1, 1, 1, 1, 0, 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(n):\n \"\"\"\n Helper function to determine 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:...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00009764", "row_id": 9764, "seed_ids": "['magpie_prefill_9764']" }
0.625188
Prefill_9764
I
[ "is_prime", "sum_of_first_n_primes" ]
2
[ [ "sum_of_first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3bc4d94e8a428732a3a771e9b650cc9d7a645e18
e19a08108899f73de05f212fb5ed7ac841b30902
v1.0
instruct
Prefill
Prefill_9823_I
Write a function to solve a given Sudoku puzzle. You can assume that the given Sudoku puzzle will always have a unique solution. The Sudoku puzzle is represented as a 2D array of numbers from 1 to 9. A "0" represents an empty cell. The function should fill in the empty cells to solve the puzzle.
def solve_sudoku(board): """ Solves the given Sudoku puzzle by filling the empty cells. :param board: 2D list representing the Sudoku board (0 represents an empty cell) :return: True if the Sudoku is solved, False otherwise """ empty = find_empty(board) if not empty: return True # No...
def test_sudoku_easy(): 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, 0, 2, 8, 0], [0, 0, 0, 4, 1,...
[ { "docstring": "Solves the given Sudoku puzzle by filling the empty cells.\n:param board: 2D list representing the Sudoku board (0 represents an empty cell)\n:return: True if the Sudoku is solved, False otherwise", "function_declaration": "def solve_sudoku(board):", "function_name": "solve_sudoku", ...
[ 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 solve_sudoku(board):\n \"\"\"\n Solves the given Sudoku puzzle by filling the empty cells.\n \n Parameters:\n board (list of list of int): A 2D list representing the Sudoku...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009823", "row_id": 9823, "seed_ids": "['magpie_prefill_9823']" }
0.509456
Prefill_9823
I
[ "solve_sudoku", "find_empty", "is_valid" ]
3
[ [ "solve_sudoku", "find_empty" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
false
[]
true
cf495da8d0e84d7cce6a3f54ab9ff74a3e5307a8
3d0525db1ebd65a19a450775b0a0063b3339307a
v1.0
instruct
Prefill
Prefill_9833_I
Write a function to sort an array of numbers using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that splits an array into halves, sorts them separately, and then merges them. The merging step is crucial as it combines the two halves while maintaining the order of elements. You can use recursio...
def merge_sort(arr): """ Sort an array of numbers using the merge sort algorithm. """ if len(arr) <= 1: return arr # Split the array into two halves middle = len(arr) // 2 left_half = arr[:middle] right_half = arr[middle:] # Recursively split and merge left_sorted = mer...
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(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted(): assert merge_sort([5,...
[ { "docstring": "Sort an array of numbers using the merge sort algorithm.", "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,...
[ 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 numbers using the merge sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n mid = len(arr) // 2\n left_hal...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00009833", "row_id": 9833, "seed_ids": "['magpie_prefill_9833']" }
0.789439
Prefill_9833
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e6f971520a4c73762e04f2495e7a09eb03e4b84a
42095ae763a3fe4544c9613548fccd59fb679728
v1.0
instruct
Prefill
Prefill_9877_I
Write a function to calculate the sum of two numbers in any base between 2 and 10.
def base_addition(num1, num2, base): """ Returns the sum of num1 and num2 in the specified base (between 2 and 10). """ if not (2 <= base <= 10): raise ValueError("Base must be between 2 and 10.") # Convert num1 and num2 from the given base to decimal dec_num1 = int(num1, base) ...
from solution import base_addition def test_base_addition_base_2(): assert base_addition('110', '101', 2) == '1011' assert base_addition('0', '0', 2) == '0' assert base_addition('1111', '1', 2) == '10000' def test_base_addition_base_3(): assert base_addition('21', '12', 3) == '110' assert base...
[ { "docstring": "Returns the sum of num1 and num2 in the specified base (between 2 and 10).", "function_declaration": "def base_addition(num1, num2, base):", "function_name": "base_addition", "parameter_list": "(num1, num2, base)" }, { "docstring": "Converts a decimal number to the specified ...
[ 0, 1, 1, 0, 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": "def add_in_base(a, b, base):\n \"\"\"\n Returns the sum of two numbers in a given base.\n\n Parameters:\n a (str): First number in string format.\n b (str): Second number in st...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00009877", "row_id": 9877, "seed_ids": "['magpie_prefill_9877']" }
0.63772
Prefill_9877
I
[ "base_addition", "to_base" ]
2
[ [ "base_addition", "to_base" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37b0e4bb57b99ac412e6a821f29bdd2dbac87b98
9cc2abaab72e3bca2e273908bdddda6970bdf221
v1.0
instruct
Prefill
Prefill_9923_I
Write a function to delete a node with a given value in a binary search tree (BST). The function should return the new root of the BST after the deletion. The BST can have integers, and the value to be deleted is provided as an argument to the function.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def delete_node(root, key): """ Delete a node with the given value in a BST and return the new root. """ if not root: return root if key < root.v...
from solution import TreeNode, delete_node def bst_to_list(root): if not root: return [] return bst_to_list(root.left) + [root.val] + bst_to_list(root.right) def test_delete_node_with_no_children(): root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(6) new_root = del...
[]
[ 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 delete_node(root, key):\n \"\"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00009923", "row_id": 9923, "seed_ids": "['magpie_prefill_9923']" }
0.549726
Prefill_9923
I
[ "delete_node", "find_min_value" ]
2
[ [ "delete_node", "find_min_value" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
8357dd3ccbf29df3f08146ecc7114d150418d14d
0bdaebccddfccbefa18413a4506d6e98e0227401
v1.0
instruct
Prefill
Prefill_9929_I
Write a function to check whether a given number is a perfect cube and then use it to find all perfect cubes between 1 and 1000.
def is_perfect_cube(n): """ Checks if n is a perfect cube. """ if n < 0: return False cube_root = round(n ** (1/3)) return cube_root ** 3 == n def find_perfect_cubes_between_1_and_1000(): """ Finds all perfect cubes between 1 and 1000. """ return [x for x in range(1, 100...
from solution import is_perfect_cube, find_perfect_cubes_between_1_and_1000 def test_is_perfect_cube(): assert is_perfect_cube(1) == True assert is_perfect_cube(8) == True assert is_perfect_cube(27) == True assert is_perfect_cube(64) == True assert is_perfect_cube(125) == True assert is_perfect...
[ { "docstring": "Checks if n is a perfect cube.", "function_declaration": "def is_perfect_cube(n):", "function_name": "is_perfect_cube", "parameter_list": "(n)" }, { "docstring": "Finds all perfect cubes between 1 and 1000.", "function_declaration": "def find_perfect_cubes_between_1_and_1...
[ 1, 1, 0, 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 is_perfect_cube(n):\n \"\"\"\n Check if a number n is a perfect cube.\n \"\"\"\n cube_root = round(n ** (1/3))\n return cube_root ** 3 == n\n\ndef find_perfect_cubes(start,...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00009929", "row_id": 9929, "seed_ids": "['magpie_prefill_9929']" }
0.656821
Prefill_9929
I
[ "is_perfect_cube", "find_perfect_cubes_between_1_and_1000" ]
2
[ [ "find_perfect_cubes_between_1_and_1000", "is_perfect_cube" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c190bcd4e2141e933d4e170d4b3b6543847c956d
5b326f0c90ff99f53ab29461ae9cf05cd574e457
v1.0
instruct
Prefill
Prefill_10132_I
Write a function to check if a given integer is a good number. A good number is defined as a number that is a prime and is also the result of adding 1 to a power of 2. In other words, it should satisfy the equation 2^k + 1 = n for some integer k.
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 += 6 ...
from solution import is_good_number def test_is_good_number(): assert is_good_number(3) == True # 2^1 + 1 = 3, and 3 is prime assert is_good_number(5) == True # 2^2 + 1 = 5, and 5 is prime assert is_good_number(7) == False # 7 is prime but not of the form 2^k + 1 assert is_good_number(9) == Fal...
[ { "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 True if the given integer is a good number.\nA good number is prime and in the form of 2^k + 1.", ...
[ 1, 0, 0, 0, 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 is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00010132", "row_id": 10132, "seed_ids": "['magpie_prefill_10132']" }
0.624712
Prefill_10132
I
[ "is_prime", "is_good_number" ]
2
[ [ "is_good_number", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e9fc939966ef3aa4ce3eabcf0c87937824ffdff
dc2c60bd30ede57e1eefd287d97dbbcd5ec1bfc2
v1.0
instruct
Prefill
Prefill_10141_I
Write a function to find the number of days in a month. You should handle both leap years and non-leap years properly.
def is_leap_year(year): """ Determines if a given year is a leap year. Args: year (int): The year to check. Returns: bool: True if the year is a leap year, False otherwise. """ if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True return False de...
import pytest from solution import days_in_month, is_leap_year def test_is_leap_year(): assert is_leap_year(2020) == True assert is_leap_year(2021) == False assert is_leap_year(2000) == True assert is_leap_year(1900) == False def test_days_in_month_regular_year(): assert days_in_month(2021, 1) == ...
[ { "docstring": "Determines if a given year is a leap year.\n\nArgs:\nyear (int): The year to check.\n\nReturns:\nbool: True if the year is a leap year, False otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docs...
[ 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 Determines if a year is a leap year.\n \"\"\"\n if year % 4 == 0:\n if year % 100 == 0:\n if year % 400 == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010141", "row_id": 10141, "seed_ids": "['magpie_prefill_10141']" }
0.702354
Prefill_10141
I
[ "is_leap_year", "days_in_month" ]
2
[ [ "days_in_month", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
48331cc288ab718790e15ce474fa0bf07b75114c
ad97272e18dab4dafb55b4c22be0e24315b1924e
v1.0
instruct
Prefill
Prefill_10162_I
Write a function to sort an array in ascending order using the quicksort algorithm. The function should take the array and its length as input, and sort the array in-place. Additionally, provide a way to test the function with different input arrays.
def quicksort(arr, low, high): """ Sorts the array in ascending order using the quicksort algorithm. Parameters: arr (list): The array to be sorted low (int): The starting index of the array/sub-array to be sorted high (int): The ending index of the array/sub-array to be sorted ...
from solution import sort_array def test_quicksort_on_positive_numbers(): arr = [64, 25, 12, 22, 11] sorted_arr = sort_array(arr) assert sorted_arr == [11, 12, 22, 25, 64] def test_quicksort_on_array_with_duplicates(): arr = [5, 2, 3, 5, 1, 5, 0] sorted_arr = sort_array(arr) assert sorted_arr ...
[ { "docstring": "Sorts the array in ascending order using the quicksort algorithm.\n\nParameters:\n arr (list): The array to be sorted\n low (int): The starting index of the array/sub-array to be sorted\n high (int): The ending index of the array/sub-array to be sorted", "function_declaration": "def...
[ 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 quicksort(arr, left, right):\n \"\"\"\n Sorts the array in-place in ascending order using the quicksort algorithm.\n \n Parameters:\n arr (list): The array to be sorted.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010162", "row_id": 10162, "seed_ids": "['magpie_prefill_10162']" }
0.657341
Prefill_10162
I
[ "quicksort", "sort_array" ]
2
[ [ "sort_array", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4d2f4f3b34d491f39bb070c1b297b2c5b39b6e1b
bc5af14c8211671cc8b4bb78f30bd8f5e47b7700
v1.0
instruct
Prefill
Prefill_10201_I
Write a function to create a graph from a list of directed edges and perform a topological sort on the graph. The function should be able to handle graphs with cycles and return an error message.
from collections import defaultdict, deque def create_graph(edges): """ Creates a graph from a list of directed edges. """ graph = defaultdict(list) for u, v in edges: graph[u].append(v) return graph def topological_sort(edges): """ Performs topological sort on the graph create...
from solution import create_graph, topological_sort def test_create_graph(): edges = [(1, 2), (2, 3), (3, 4)] graph = create_graph(edges) expected_graph = {1: [2], 2: [3], 3: [4]} assert dict(graph) == expected_graph def test_topological_sort_acyclic(): edges = [(1, 2), (2, 3), (3, 4)] order =...
[ { "docstring": "Creates a graph from a list of directed edges.", "function_declaration": "def create_graph(edges):", "function_name": "create_graph", "parameter_list": "(edges)" }, { "docstring": "Performs topological sort on the graph created from the list of edges.", "function_declarat...
[ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef topological_sort(vertices, edges):\n \"\"\"\n Performs topological sort on a graph defined by vertices and edges.\n Handles cycles b...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00010201", "row_id": 10201, "seed_ids": "['magpie_prefill_10201']" }
0.469201
Prefill_10201
I
[ "create_graph", "topological_sort" ]
2
[ [ "topological_sort", "create_graph" ] ]
1
[]
false
[]
false
pytest
true
[]
true
03a60d46b8adc635dd5d154dfa24807b98ddfe48
86048de653bb4d6f1c2e30e4880dbc478e52b728
v1.0
instruct
Prefill
Prefill_10252_I
Write a function to identify all the palindromes in an array using Python.
def is_palindrome(word): """ Checks if a word is a palindrome. """ return word == word[::-1] def find_palindromes(arr): """ Identifies all the palindromes in an array of strings. """ return [word for word in arr if is_palindrome(word)]
from solution import is_palindrome, find_palindromes def test_is_palindrome(): assert is_palindrome("madam") == True assert is_palindrome("racecar") == True assert is_palindrome("hello") == False assert is_palindrome("noon") == True assert is_palindrome("palindrome") == False assert is_palindro...
[ { "docstring": "Checks if a word is a palindrome.", "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": "Identifies all the palindromes in an array of strings.", "function_declaration": "def find_palindromes(a...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_palindromes(arr):\n \"\"\"\n Returns a list of palindromes found in the input array.\n \n A palindrome is a word that reads the same backward as forward.\n \"\"\"\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00010252", "row_id": 10252, "seed_ids": "['magpie_prefill_10252']" }
0.705448
Prefill_10252
I
[ "is_palindrome", "find_palindromes" ]
2
[ [ "find_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92563cd147b4c6f4766df28e8ac08d1ed82de625
ecc89d55a2fcfdb0a4c8b9b57682a60e297050c6
v1.0
instruct
Prefill
Prefill_10342_I
Write a function to extract all prime numbers from an array and return them in a new array.
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def extract_primes(arr): """ Extracts all prime numbers from the given array and returns them in a...
from solution import is_prime, extract_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(20) == False def test_extract_primes_with_no_primes(): assert extract_primes([4, 6, 8, 10, 12]) == []...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Extracts all prime numbers from the given array and returns them in a new array.", "function_declaration": "def extract_pr...
[ 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 Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0 or n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010342", "row_id": 10342, "seed_ids": "['magpie_prefill_10342']" }
0.598946
Prefill_10342
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff6f92f69b93b1816dc018f5c470f2fb4d815190
2d6f60405dbaf6172df3e8d401a01680e3a0bbe4
v1.0
instruct
Prefill
Prefill_10445_I
Write a function to print all the prime numbers between 1 to N. How would you approach this problem and write the code in Python?
def is_prime(n): """ Helper function to check if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i...
from solution import is_prime, primes_up_to_n def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(1) == False assert is_prime(0) == False def test_primes_up_to_n(): ...
[ { "docstring": "Helper function to check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between 1 and N.", "function_declaration": "def primes_up_to_n(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(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010445", "row_id": 10445, "seed_ids": "['magpie_prefill_10445']" }
0.708293
Prefill_10445
I
[ "is_prime", "primes_up_to_n" ]
2
[ [ "primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e573cb0ac465b6f6cb69c07c0ad0532ee10ea21c
61f812b563cf62930744818d18c4cc8f7d9ae925
v1.0
instruct
Prefill
Prefill_10789_I
Write a function to check if a binary tree is a mirror of itself (i.e., a palindrome).
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_mirror(left_subtree, right_subtree): if left_subtree is None and right_subtree is None: return True if left_subtree is None or right_subtree is None: ...
from solution import TreeNode, is_symmetric def test_symmetric_tree(): # Create a symmetric tree: # 1 # / \ # 2 2 # / \ / \ # 3 4 4 3 root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(2) root.left.left = TreeNode(3) root.left.r...
[]
[ 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": "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_mirror(t1, t2):\n if t1 is No...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010789", "row_id": 10789, "seed_ids": "['magpie_prefill_10789']" }
0.698286
Prefill_10789
I
[ "is_mirror", "is_symmetric" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
646e3aa617e8db1d14496de937312a1b64636b24
437a4269a81ac5b8ae89d350ef656098d61e9a0b
v1.0
instruct
Prefill
Prefill_10939_I
Write a function to merge two binary search trees (BSTs) into a single BST. The function should return the root of the new BST. The new BST should contain all the nodes from both input BSTs and maintain the BST property.
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def bst_to_sorted_list(root): """ Converts a BST to a sorted list. """ if not root: return [] return bst_to_sorted_list(root.left) + [root.v...
from solution import TreeNode, merge_bsts, bst_to_sorted_list def tree1(): a = TreeNode(1) b = TreeNode(3) c = TreeNode(2) d = TreeNode(5) c.left = a c.right = b b.right = d return c def tree2(): p = TreeNode(7) q = TreeNode(6) r = TreeNode(9) s = TreeNode(8) p.left...
[]
[ 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "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 inorder_traverse(root):\n \"\"\"...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00010939", "row_id": 10939, "seed_ids": "['magpie_prefill_10939']" }
0.404829
Prefill_10939
I
[ "bst_to_sorted_list", "sorted_list_to_bst", "merge_bsts" ]
3
[ [ "merge_bsts", "bst_to_sorted_list" ], [ "merge_bsts", "sorted_list_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
34b1b2eb1f0216bdf716efe4270a50850b1bfa8a
3dd05967e2475cb56426c7f23145795f3233d657
v1.0
instruct
Prefill
Prefill_10964_I
Write a function to reverse a stack using recursion without using an additional stack. Ensure that each function call does not store more than one item.
def insert_at_bottom(stack, item): if len(stack) == 0: stack.append(item) else: temp = stack.pop() insert_at_bottom(stack, item) stack.append(temp) def reverse_stack(stack): if len(stack) > 0: temp = stack.pop() reverse_stack(stack) insert_at_bottom(s...
from solution import reverse_stack def test_reverse_empty_stack(): stack = [] reverse_stack(stack) assert stack == [] def test_reverse_single_element_stack(): stack = [1] reverse_stack(stack) assert stack == [1] def test_reverse_two_element_stack(): stack = [1, 2] reverse_stack(stack)...
[ { "docstring": null, "function_declaration": "def insert_at_bottom(stack, item):", "function_name": "insert_at_bottom", "parameter_list": "(stack, item)" }, { "docstring": null, "function_declaration": "def reverse_stack(stack):", "function_name": "reverse_stack", "parameter_list...
[ 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 insert_at_bottom(stack, item):\n \"\"\"\n Helper function to insert an item at the bottom of the stack.\n \"\"\"\n if not stack:\n stack.append(item)\n else:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00010964", "row_id": 10964, "seed_ids": "['magpie_prefill_10964']" }
0.508338
Prefill_10964
I
[ "insert_at_bottom", "reverse_stack" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72c91161abad718de8322ffc2b325efb2f690f74
89d759df5e3627562e8da7feafe6282865bb7e6d
v1.0
instruct
Prefill
Prefill_11020_I
Write a function to check if a given binary tree is a subtree of another binary tree. A subtree of a binary tree T is a tree consisting of a node in T and all of its descendants in T.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(s, t): """ Returns True if tree t is a subtree of s, otherwise returns False. """ if not t: return True if not s: return Fa...
from solution import TreeNode, is_subtree def test_is_subtree_identical(): s = TreeNode(3, TreeNode(4, TreeNode(1), TreeNode(2)), TreeNode(5)) t = TreeNode(4, TreeNode(1), TreeNode(2)) assert is_subtree(s, t) def test_is_subtree_not_identical(): s = TreeNode(3, TreeNode(4, TreeNode(1), TreeNode(2, Tre...
[]
[ 1, 1, 1, 1, 1, 0, 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef isSubtree(s, t):\n \"\"\"\n R...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011020", "row_id": 11020, "seed_ids": "['magpie_prefill_11020']" }
0.629401
Prefill_11020
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
dcc55e501468b9ce58fed8cdf49775301426de6b
c6444666ae2c47f6b72acf07930c14a1aa5568b6
v1.0
instruct
Prefill
Prefill_11050_I
Write a function to find the minimum or maximum element in a binary tree based on the given direction (min or max).
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def find_extreme_element(root, direction): """ Given a binary tree root and a direction ('min' or 'max'), find the minimum or maximum element in the binary tree respectively. """ ...
from solution import TreeNode, find_extreme_element def test_find_min(): root = TreeNode(10) root.left = TreeNode(5) root.right = TreeNode(20) root.left.left = TreeNode(2) root.left.right = TreeNode(8) root.right.right = TreeNode(30) assert find_extreme_element(root, 'min') == 2 def t...
[]
[ 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.val = key\n\ndef find_extreme(root, direction):\n \"\"\"\n Returns the m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011050", "row_id": 11050, "seed_ids": "['magpie_prefill_11050']" }
0.640436
Prefill_11050
I
[ "find_extreme_element", "find_min", "find_max" ]
3
[ [ "find_extreme_element", "find_max" ], [ "find_extreme_element", "find_min" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2d2af9242cfbc64c2ec967451955b1ea70cd1646
7e10227a346b404d4b464daa9813e2e1f719fd96
v1.0
instruct
Prefill
Prefill_11106_I
Write a function to calculate the number of distinct nodes that can be reached by a knight in a chessboard. A knight can move in an 'L' shape, which means it can move two squares in one direction and then one square perpendicular to that direction, or one square in one direction and then two squares perpendicular to th...
def knight_moves(x, y): """ Returns the set of distinct positions that a knight can move to from the start position (x, y) on an 8x8 chessboard. """ moves = [ (2, 1), (2, -1), (-2, 1), (-2, -1), (1, 2), (1, -2), (-1, 2), (-1, -2) ] reachable_positions = set() for dx,...
from solution import distinct_knight_reachable_nodes, knight_moves def test_knight_moves_within_bounds(): moves = knight_moves(0, 0) assert (2, 1) in moves assert (1, 2) in moves assert len(moves) == 2 def test_knight_moves_from_center(): moves = knight_moves(4, 4) expected_moves = [ (...
[ { "docstring": "Returns the set of distinct positions that a knight can move to from the start position (x, y)\non an 8x8 chessboard.", "function_declaration": "def knight_moves(x, y):", "function_name": "knight_moves", "parameter_list": "(x, y)" }, { "docstring": "Returns the number of dist...
[ 0, 1, 1, 1, 1, 1, 0, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def knight_moves(x, y):\n \"\"\"\n Calculate the number of distinct nodes that can be reached by a knight in an 8x8 chessboard\n starting from position (x, y).\n\n :param x: integ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011106", "row_id": 11106, "seed_ids": "['magpie_prefill_11106']" }
0.578236
Prefill_11106
I
[ "knight_moves", "distinct_knight_reachable_nodes" ]
2
[ [ "distinct_knight_reachable_nodes", "knight_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
babf27a258365b84a1adc9a3b39052aa4b3835a2
88f24ac74feb40e71820bf1c5418eccae42891a1
v1.0
instruct
Prefill
Prefill_11131_I
Write a function to find the smallest prime number greater than or equal to a given number. Can you provide a code snippet in Python?
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import next_prime, is_prime def test_is_prime(): assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(29) assert not is_prime(30) def test_next_prime_at_small_numbers(): assert ne...
[ { "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 smallest prime number greater than or equal to n.", "function_declaration": "def next_prime(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(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": "00011131", "row_id": 11131, "seed_ids": "['magpie_prefill_11131']" }
0.690934
Prefill_11131
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
836008b435ac13dd0aabdbd565c028d35810e895
3be569df54324c91e8381c41c96118017ebcabe8
v1.0
instruct
Prefill
Prefill_11212_I
Write a function to sort an array of integers in ascending order. The function should take an array of integers as input and return the sorted array. The sorting algorithm should be of O(N log N) complexity. Which algorithm can be used for this purpose, quicksort, mergesort, or heapsort? Explain the choice and provide ...
def merge_sort(arr): """ Sorts an array of integers in ascending order using the mergesort 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, r...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([5]) == [5] 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 of integers in ascending order using the mergesort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted arrays into one sorted array.", "function_declarati...
[ 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 in ascending order using the Merge Sort algorithm.\n \n Parameters:\n arr (list): A list of integers\n \n Retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011212", "row_id": 11212, "seed_ids": "['magpie_prefill_11212']" }
0.636112
Prefill_11212
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d94ed8f4ca5041551fee13a1c6c00ee0a61fba6
c7fa94fb0713d852583a551c14ff3984073a2cc2
v1.0
instruct
Prefill
Prefill_11349_I
Write a function to generate all possible binary strings of length n. The function should return a list of all possible combinations.
def generate_binary_strings(n): """ Returns a list of all possible binary strings of length n. """ if n <= 0: return [] result = [] generate_strings_helper(n, "", result) return result def generate_strings_helper(n, prefix, result): if n == 0: result.append(prefix) ...
from solution import generate_binary_strings def test_generate_binary_strings_length_1(): assert generate_binary_strings(1) == ["0", "1"] def test_generate_binary_strings_length_2(): assert generate_binary_strings(2) == ["00", "01", "10", "11"] def test_generate_binary_strings_length_3(): assert generate...
[ { "docstring": "Returns a list of all possible binary strings of length n.", "function_declaration": "def generate_binary_strings(n):", "function_name": "generate_binary_strings", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_strings_helper(n, pref...
[ 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 generate_binary_strings(n):\n \"\"\"\n Generates all binary strings of length n.\n \n Args:\n n (int): Length of binary strings to generate.\n \n Returns:\n list: ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011349", "row_id": 11349, "seed_ids": "['magpie_prefill_11349']" }
0.68509
Prefill_11349
I
[ "generate_binary_strings", "generate_strings_helper" ]
2
[ [ "generate_binary_strings", "generate_strings_helper" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51e5c7e0d720578c46c4cce4554b3c85d16c43eb
b7e3381367d6dba61ec8f72b0c92893cb581b8d6
v1.0
instruct
Prefill
Prefill_11354_I
Write a function to compute the nth Fibonacci number using both iterative and recursive methods. Additionally, compare their performance for different values of n using time complexity.
import time def fibonacci_recursive(n): """ Returns the nth Fibonacci number using recursion. """ if n <= 0: raise ValueError("Input should be a positive integer") if n == 1: return 0 if n == 2: return 1 return fibonacci_recursive(n-1) + fibonacci_recursive(n-2) def...
from solution import fibonacci_recursive, fibonacci_iterative, compare_performance import pytest def test_fibonacci_recursive(): assert fibonacci_recursive(1) == 0 assert fibonacci_recursive(2) == 1 assert fibonacci_recursive(3) == 1 assert fibonacci_recursive(4) == 2 assert fibonacci_recursive(5)...
[ { "docstring": "Returns the nth Fibonacci number using recursion.", "function_declaration": "def fibonacci_recursive(n):", "function_name": "fibonacci_recursive", "parameter_list": "(n)" }, { "docstring": "Returns the nth Fibonacci number using iteration.", "function_declaration": "def f...
[ 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": "import time\n\ndef fibonacci_recursive(n):\n \"\"\"\n Returns the nth Fibonacci number using recursion.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011354", "row_id": 11354, "seed_ids": "['magpie_prefill_11354']" }
0.671512
Prefill_11354
I
[ "fibonacci_recursive", "fibonacci_iterative", "compare_performance" ]
3
[ [ "compare_performance", "fibonacci_iterative" ], [ "compare_performance", "fibonacci_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
064a9848494dbbb894df0db78b7470ef26618bc6
ba1fcd62502c6f201b815ede117f8c381944a022
v1.0
instruct
Prefill
Prefill_11366_I
Write a function to calculate the maximum sum of subarray within a given array. You should consider at least two different approaches to solve this problem.
def max_subarray_kadane(arr): """ Finds the maximum sum of a subarray using Kadane's Algorithm. """ max_current = max_global = arr[0] for num in arr[1:]: max_current = max(num, max_current + num) if max_current > max_global: max_global = max_current return max_global ...
from solution import max_subarray_kadane, max_subarray_dnc def test_max_subarray_kadane(): assert max_subarray_kadane([1, 2, 3, 4, 5]) == 15 assert max_subarray_kadane([-2, -3, 4, -1, -2, 1, 5, -3]) == 7 assert max_subarray_kadane([-1, -2, -3, -4]) == -1 assert max_subarray_kadane([0, 0, 0, 0]) == 0 ...
[ { "docstring": "Finds the maximum sum of a subarray using Kadane's Algorithm.", "function_declaration": "def max_subarray_kadane(arr):", "function_name": "max_subarray_kadane", "parameter_list": "(arr)" }, { "docstring": "Helper function to find the maximum sum of subarray crossing the midpo...
[ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_subarray_kadane(arr):\n \"\"\"\n Returns the maximum sum of a subarray using Kadane's algorithm.\n \"\"\"\n if not arr:\n return 0\n \n max_end_here = max...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011366", "row_id": 11366, "seed_ids": "['magpie_prefill_11366']" }
0.725663
Prefill_11366
I
[ "max_subarray_kadane", "max_crossing_sum", "max_subarray_divide_and_conquer", "max_subarray_dnc" ]
4
[ [ "max_subarray_divide_and_conquer", "max_crossing_sum" ], [ "max_subarray_dnc", "max_subarray_divide_and_conquer" ] ]
2
[]
false
[]
false
pytest
true
[]
true
97fa8962ff523cbad3f50b9c2989554b3f941b35
b4320f8c4ac7a568b87cc4cbfa6f825ee8badb52
v1.0
instruct
Prefill
Prefill_11493_I
Write a function to calculate the number of ways to distribute `n` distinct items into `k` distinct bins such that no bin is empty.
from math import factorial def stirling_second_kind(n, k): """ Returns the number of ways to distribute n distinct items into k distinct bins such that no bin is empty. """ if n == k: return 1 elif k == 0 or k > n: return 0 else: return k * stirling_second_kind(n - 1, k)...
from solution import distribute_items def test_distribute_items_one_bin(): assert distribute_items(5, 1) == 1 assert distribute_items(1, 1) == 1 def test_distribute_items_equal_items_and_bins(): assert distribute_items(5, 5) == 120 # 5! = 120 def test_distribute_items_more_items_than_bins(): assert ...
[ { "docstring": "Returns the number of ways to distribute n distinct items into k distinct bins such that no bin is empty.", "function_declaration": "def stirling_second_kind(n, k):", "function_name": "stirling_second_kind", "parameter_list": "(n, k)" }, { "docstring": "Calculates the number ...
[ 1, 1, 0, 1, 1, 0, 0, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import comb\n\ndef count_distributions(n, k):\n \"\"\"\n Calculate the number of ways to distribute n distinct items\n into k distinct bins such that no bin is empty.\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00011493", "row_id": 11493, "seed_ids": "['magpie_prefill_11493']" }
0.576797
Prefill_11493
I
[ "stirling_second_kind", "distribute_items" ]
2
[ [ "distribute_items", "stirling_second_kind" ] ]
1
[]
false
[]
false
pytest
true
[]
true
391f5f9a57417dd9da7191f66dbc7b3e2f424258
215c3fc7de5cf134d96b2f7073a716455548c237
v1.0
instruct
Prefill
Prefill_11542_I
Write a function to calculate and print the Fibonacci sequence up to a given number 'n'. The Fibonacci sequence should start with 0 and 1. Each subsequent number in the sequence is the sum of the two preceding ones. Your function should take an integer 'n' as input and return the sequence as a list. Additionally, imple...
def fibonacci(n): """ Returns the Fibonacci sequence up to the given number 'n'. """ if n <= 0: return [] elif n == 1: return [0] elif n == 2: return [0, 1] sequence = [0, 1] while len(sequence) < n: next_value = sequence[-1] + sequence[-2] se...
from solution import fibonacci, check_fibonacci def test_fibonacci_zero(): assert fibonacci(0) == [] def test_fibonacci_one(): assert fibonacci(1) == [0] def test_fibonacci_two(): assert fibonacci(2) == [0, 1] def test_fibonacci_five(): assert fibonacci(5) == [0, 1, 1, 2, 3] def test_fibonacci_ten(...
[ { "docstring": "Returns the Fibonacci sequence up to the given number 'n'.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Verifies if the generated Fibonacci sequence matches the expected sequence.", "function_decla...
[ 1, 1, 1, 0, 1, 1, 1, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Returns the Fibonacci sequence up to the given number 'n'.\n The sequence starts with 0 and 1.\n \"\"\"\n if n <= 0:\n return []\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011542", "row_id": 11542, "seed_ids": "['magpie_prefill_11542']" }
0.786369
Prefill_11542
I
[ "fibonacci", "check_fibonacci" ]
2
[ [ "check_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c34d0d56980f96ea275a1d95632ea9e2f2492bb7
a87adabf2b1ef5367a237195ecdc86e3eb1cb5c7
v1.0
instruct
Prefill
Prefill_11607_I
Write a function to generate a list of all possible subsets of a set of numbers, including the empty set. For instance, if the input is [1,2,3], the function should return [[], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]].
from itertools import chain, combinations def generate_subsets(numbers): """ Generates all possible subsets of a set of numbers, including the empty set. :param numbers: List of numbers to generate subsets for. :return: List of all possible subsets. """ return list(chain.from_iterable(comb...
from solution import subsets_as_lists def test_empty_set(): assert subsets_as_lists([]) == [[]] def test_single_element_set(): assert subsets_as_lists([1]) == [[], [1]] def test_two_element_set(): assert subsets_as_lists([1, 2]) == [[], [1], [2], [1, 2]] def test_three_element_set(): assert subsets_...
[ { "docstring": "Generates all possible subsets of a set of numbers, including the empty set.\n\n:param numbers: List of numbers to generate subsets for.\n:return: List of all possible subsets.", "function_declaration": "def generate_subsets(numbers):", "function_name": "generate_subsets", "parameter...
[ 0, 0, 1, 0, 1, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_subsets(nums):\n \"\"\"\n Generates all possible subsets of a given set of numbers.\n \n :param nums: List of integers\n :return: List of lists, where each list is...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011607", "row_id": 11607, "seed_ids": "['magpie_prefill_11607']" }
0.602631
Prefill_11607
I
[ "generate_subsets", "subsets_as_lists" ]
2
[ [ "subsets_as_lists", "generate_subsets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
48a1b5d43ac8e5dd3ec9a69422ceb50380fb50cc
3ef2798f275d90e856597fec0314889cb040a09c
v1.0
instruct
Prefill
Prefill_11656_I
Write a function to find the largest palindrome made from the product of two n-digit numbers. A palindrome is a number that reads the same backward as forward. For example, 121 is a palindrome, whereas 123 is not.
def is_palindrome(n): """ Checks if a number n is a palindrome. """ return str(n) == str(n)[::-1] def largest_palindrome_product(n): """ Returns the largest palindrome made from the product of two n-digit numbers. """ max_number = 10 ** n - 1 min_number = 10 ** (n - 1) max_palin...
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(13331) == True assert is_palindrome(123456) =...
[ { "docstring": "Checks if a number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns the largest palindrome made from the product of two n-digit numbers.", "function_declaration": "de...
[ 0, 1, 1, 1, 0, 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 largest_palindrome_product(n):\n \"\"\"\n Finds the largest palindrome made from the product of two n-digit numbers.\n \"\"\"\n upper_limit = 10**n - 1\n lower_limit = 10**...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011656", "row_id": 11656, "seed_ids": "['magpie_prefill_11656']" }
0.772632
Prefill_11656
I
[ "is_palindrome", "largest_palindrome_product" ]
2
[ [ "largest_palindrome_product", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a35062cadfc7e8e1d9142edaa40aa0bb1950369
2c2d971d71f85ea58edefae031f3144bef777698
v1.0
instruct
Prefill
Prefill_11738_I
Write a function to calculate the in-order successor of a given node in a binary search tree (BST). The in-order successor of a node in a BST is the next node in the in-order traversal. If the given node has no next successor, return `None`.
class TreeNode: def __init__(self, key, left=None, right=None): self.key = key self.left = left self.right = right def find_min(node): """ Function to find the minimum value node in a BST. """ current = node while current.left is not None: current = current.left ...
from solution import TreeNode, inorder_successor, find_min def test_inorder_successor_with_right_child(): root = TreeNode(20) root.left = TreeNode(10) root.right = TreeNode(30) root.left.right = TreeNode(15) succ = inorder_successor(root, root.left) assert succ.key == 15 def test_inorder_succe...
[]
[ 1, 0, 1, 1, 0, 1, 1, 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, key):\n self.val = key\n self.left = None\n self.right = None\n\ndef find_min(node):\n \"\"\"\n Helper function to find the ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00011738", "row_id": 11738, "seed_ids": "['magpie_prefill_11738']" }
0.554912
Prefill_11738
I
[ "find_min", "inorder_successor" ]
2
[ [ "inorder_successor", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a488d359802a69f8d07c7acd3571b41531a4e46f
f280eec2e111130e4b53cb2880867267d2d313b7
v1.0
instruct
Prefill
Prefill_11907_I
Write a function to determine the maximum number of points that can be formed by参加会议(point A, B, C, D, E), where each point is determined by the smallest angle formed by three points on the circumference of a circle. The function should use geometrical properties to efficiently calculate the maximum points possible.
from math import comb def max_points_on_circle_polygon(n): """ Returns the maximum number of points formed by intersections of diagonals of a convex polygon with n vertices on the circumference of a circle. """ if n < 4: return 0 # Less than 4 vertices, no intersection of diagonals ret...
from solution import max_points_with_5_points, max_points_on_circle_polygon def test_max_points_with_5_points(): assert max_points_with_5_points() == 5 def test_max_points_on_circle_polygon_with_4_points(): assert max_points_on_circle_polygon(4) == 1 def test_max_points_on_circle_polygon_with_6_points(): ...
[ { "docstring": "Returns the maximum number of points formed by intersections of diagonals\nof a convex polygon with n vertices on the circumference of a circle.", "function_declaration": "def max_points_on_circle_polygon(n):", "function_name": "max_points_on_circle_polygon", "parameter_list": "(n)" ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom itertools import combinations\n\ndef angle_between_three_points(A, B, C):\n \"\"\"\n Calculate the smallest angle formed by three points A, B, and C.\n Points are r...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00011907", "row_id": 11907, "seed_ids": "['magpie_prefill_11907']" }
0.484672
Prefill_11907
I
[ "max_points_on_circle_polygon", "max_points_with_5_points" ]
2
[ [ "max_points_with_5_points", "max_points_on_circle_polygon" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1973b4688dd2b1a80a5d6e1ab82f13c163a31783
1b3bdec7ae6cf39b84bee113d112d841fc6e4112
v1.0
instruct
Prefill
Prefill_11960_I
Write a function to find the LCM (Least Common Multiple) of two numbers in Python. Additionally, write a function to find the LCM of a list of numbers.
import math from functools import reduce def lcm(a, b): """ Returns the Least Common Multiple of two numbers a and b. """ return abs(a * b) // math.gcd(a, b) def lcm_of_list(numbers): """ Returns the Least Common Multiple of a list of numbers """ return reduce(lcm, numbers)
from solution import lcm, lcm_of_list def test_lcm_basic(): assert lcm(4, 6) == 12 assert lcm(7, 5) == 35 def test_lcm_with_zero(): assert lcm(0, 1) == 0 assert lcm(0, 5) == 0 def test_lcm_with_same_numbers(): assert lcm(5, 5) == 5 assert lcm(10, 10) == 10 def test_lcm_negative_numbers(): ...
[ { "docstring": "Returns the Least Common Multiple of two numbers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the Least Common Multiple of a list of numbers", "function_declaration": "def lcm_of_list(nu...
[ 0, 1, 1, 0, 0, 1, 0, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple (LCM) of two numbers a and b.\n \"\"\"\n return abs(a * b) // math.gcd(a, b)\n\ndef lcm_of_list(numbers)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00011960", "row_id": 11960, "seed_ids": "['magpie_prefill_11960']" }
0.789956
Prefill_11960
I
[ "lcm", "lcm_of_list" ]
2
[ [ "lcm_of_list", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c186b058319e0d36c3369cf8c3e3bb3543ee7446
1813eab844d03f10c0b3f1bb8bcb6c2d7842b136
v1.0
instruct
Prefill
Prefill_12038_I
Write a function to calculate the minimum distance between two sets of points using Manhattan distance. The function should take two lists of points, where each point is represented as a tuple of two integers (x, y), and return an integer representing the smallest minimum distance between any two points from the two se...
def manhattan_distance(point1, point2): """ Calculate the Manhattan distance between two points. """ return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1]) def min_distance_between_sets(set1, set2): """ Calculate the minimum Manhattan distance between two sets of points. """ min...
from solution import manhattan_distance, min_distance_between_sets def test_manhattan_distance(): assert manhattan_distance((1,2), (4,6)) == 7 assert manhattan_distance((0,0), (0,0)) == 0 assert manhattan_distance((-1,-1), (-4,-5)) == 7 assert manhattan_distance((2,3), (-2,-3)) == 10 def test_min_dist...
[ { "docstring": "Calculate the Manhattan distance between two points.", "function_declaration": "def manhattan_distance(point1, point2):", "function_name": "manhattan_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Calculate the minimum Manhattan distance between two sets o...
[ 0, 1, 0, 0, 0, 1, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def manhattan_distance(point1, point2):\n \"\"\"\n Calculate the Manhattan distance between two points.\n \"\"\"\n return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1])\n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00012038", "row_id": 12038, "seed_ids": "['magpie_prefill_12038']" }
0.691062
Prefill_12038
I
[ "manhattan_distance", "min_distance_between_sets" ]
2
[ [ "min_distance_between_sets", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c17118969768bb3ef6387cb7501e0622f1792a08
253e6e5160745f0f0911d6ac2c623f01a1d4ad2f
v1.0
instruct
Prefill
Prefill_12058_I
Write a function to find the closest prime number to a given integer `n`. If `n` is already a prime number, return `n`. If `n` is not a prime, return the closest prime number that is greater than `n`. If there is no such prime number (meaning all numbers greater than `n` are not prime), return `None`.
def is_prime(num): """ Helper function to determine if a number `num` 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: ...
from solution import closest_prime def test_prime_input(): assert closest_prime(3) == 3 assert closest_prime(13) == 13 def test_non_prime_input(): assert closest_prime(4) == 5 assert closest_prime(15) == 17 def test_large_non_prime_input(): assert closest_prime(100) == 101 def test_large_prime_i...
[ { "docstring": "Helper function to determine if a number `num` is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the closest prime number greater than or equal to `n`.\nIf `n` is already a prime number,...
[ 0, 1, 1, 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": "def is_prime(n):\n \"\"\" Helper function to check if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00012058", "row_id": 12058, "seed_ids": "['magpie_prefill_12058']" }
0.704657
Prefill_12058
I
[ "is_prime", "closest_prime" ]
2
[ [ "closest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5741611a45273810690ad8bb75a54cc28dbe63b
68eb36691e73708ba4183bc4c1ae66fa71f1e558
v1.0
instruct
Prefill
Prefill_12062_I
Write a function to find the kth largest element in an unsorted list. You may modify the input list to sort the elements, but you are not allowed to use any built-in sorting functions or libraries. Additionally, your function should be as efficient as possible, considering the constraints.
def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] >= pivot: i = i + 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def quickselect(arr, low, high, k): if low <= high: ...
from solution import find_kth_largest def test_find_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], 1) == 1 assert find_kth_largest([2, 1], 1) == 2 assert find_kth_largest([2, 1], 2) == 1 d...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quickselect(arr, low, high, k):", "function_name": "quickselect", "parameter_list...
[ 1, 1, 0, 1, 1, 1, 1, 0, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def partition(arr, low, high):\n pivot = arr[high]\n i = low - 1\n \n for j in range(low, high):\n if arr[j] >= pivot:\n i = i + 1\n arr[i], arr[j] = ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00012062", "row_id": 12062, "seed_ids": "['magpie_prefill_12062']" }
0.708042
Prefill_12062
I
[ "partition", "quickselect", "find_kth_largest" ]
3
[ [ "find_kth_largest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c674b8d8784ea0be548449e39960aa42f4745bea
863d167ec619ba9e044c7a89fd3ad8df3f4bb500
v1.0
instruct
Prefill
Prefill_12169_I
Write a function to calculate the Lowest Common Multiple (LCM) of two positive integers in Python. The function should handle cases where the input integers are less than or equal to 1000. Additionally, ensure that the function can process both prime and composite numbers.
def gcd(a, b): """ Calculate the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm. """ while b: a, b = b, a % b return a def lcm(a, b): """ Calculate the Lowest Common Multiple (LCM) of two positive integers. """ return abs(a * b) // gcd(a, b)
from solution import gcd, lcm def test_gcd(): assert gcd(54, 24) == 6 assert gcd(48, 18) == 6 assert gcd(101, 103) == 1 assert gcd(1000, 1000) == 1000 def test_lcm(): assert lcm(4, 5) == 20 assert lcm(21, 6) == 42 assert lcm(8, 9) == 72 assert lcm(101, 103) == 10403 assert lcm(1000...
[ { "docstring": "Calculate the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Calculate the Lowest Common Multiple (LCM) of two positive integers.", ...
[ 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 gcd(a, b):\n \"\"\"\n Helper function to calculate the Greatest Common Divisor (GCD) using Euclid's algorithm.\n \"\"\"\n while b != 0:\n a, b = b, a % b\n return a\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012169", "row_id": 12169, "seed_ids": "['magpie_prefill_12169']" }
0.763049
Prefill_12169
I
[ "gcd", "lcm" ]
2
[ [ "lcm", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d64250a249f30be5a6d8991242ba88c9af0a8033
6a77d8a9f09695662d4dc36f79321f515a164ba7
v1.0
instruct
Prefill
Prefill_12296_I
Write a function to count the average of all prime numbers up to a given number. In Python.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def average_prime_numbers(n): """ Returns the average of all prime numbers up ...
from solution import average_prime_numbers def test_no_prime_numbers(): assert average_prime_numbers(1) == 0 def test_average_up_to_10(): assert average_prime_numbers(10) == (2 + 3 + 5 + 7) / 4 def test_average_up_to_2(): assert average_prime_numbers(2) == 2 def test_average_up_to_20(): assert avera...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the average of all prime numbers up to a given number n.", "function_declaration": "def aver...
[ 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 is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n i...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00012296", "row_id": 12296, "seed_ids": "['magpie_prefill_12296']" }
0.796371
Prefill_12296
I
[ "is_prime", "average_prime_numbers" ]
2
[ [ "average_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac0db16da2ee94bb7f67be36ca691c6baf09e02b
27571fc135f9329bbecd05f79d56b4f8f0309ef1
v1.0
instruct
Prefill
Prefill_12329_I
Write a function to sort a linked list in O(n log n) time complexity. You can use a divide and conquer approach. The function should take the head of a linked list as input and return the sorted head of the linked list.
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def sortList(head): # Base case: if the list is empty or has a single node, it's already sorted if not head or not head.next: return head # Split the list into two halves using the...
from solution import ListNode, sortList def list_to_linkedlist(lst): dummy = ListNode() tail = dummy for value in lst: tail.next = ListNode(value) tail = tail.next return dummy.next def linkedlist_to_list(head): result = [] while head: result.append(head.val) he...
[]
[ 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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef sortList(head: ListNode) -> ListNode:\n if not head or not head.next:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012329", "row_id": 12329, "seed_ids": "['magpie_prefill_12329']" }
0.507778
Prefill_12329
I
[ "sortList", "merge" ]
2
[ [ "sortList", "merge" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
30064838c1fd6cc53606830e603ba2e5a1f5cca9
0ec6078034ca53a9c4620c2baa1552d6e7d23e1f
v1.0
instruct
Prefill
Prefill_12428_I
Write a function to find the maximum sum of a subarray within a given 2D array. The function should take the 2D array as input and return the maximum sum.
def max_2d_subarray_sum(arr): """ Finds the maximum sum of a subarray within a given 2D array. Parameters: arr (list of list of int): The 2D array of integers. Returns: int: The maximum sum of a subarray. """ if not arr or not arr[0]: return 0 rows = len(arr) c...
from solution import max_2d_subarray_sum def test_max_2d_subarray_sum(): arr1 = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_2d_subarray_sum(arr1) == 29 # Subarray from arr1[1][2] to arr1[2][4] arr2 = [ [1, 2, 3], ...
[ { "docstring": "Finds the maximum sum of a subarray within a given 2D array.\n\nParameters:\narr (list of list of int): The 2D array of integers.\n\nReturns:\nint: The maximum sum of a subarray.", "function_declaration": "def max_2d_subarray_sum(arr):", "function_name": "max_2d_subarray_sum", "param...
[ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_sum_subarray(arr):\n \"\"\"\n Finds the maximum sum of a subarray within a given 2D array.\n \"\"\"\n if not arr or not arr[0]:\n return 0\n\n max_sum = floa...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00012428", "row_id": 12428, "seed_ids": "['magpie_prefill_12428']" }
0.725198
Prefill_12428
I
[ "max_2d_subarray_sum", "kadane" ]
2
[ [ "max_2d_subarray_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb405999df634b942c48d5037eac854b2c1f4bcf
bef99136b2f9309ee41183131e2d981b90939d96
v1.0
instruct
Prefill
Prefill_12591_I
Write a function to display all the prime numbers from 1 to N. How can I implement this in Python?
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def primes_up_to_n(N): """ ...
from solution import is_prime, primes_up_to_n def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-3) def test_primes_up_to_n(): assert primes_up_to_n(1) == [] ass...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 1 to N.", "function_declaration": "def primes_up_to_n(N):", "function_name": "primes_...
[ 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 find_primes(n):\n \"\"\"\n Returns a list of prime numbers from 1 to n.\n \"\"\"\n if n < 2:\n return []\n \n primes = []\n for num in range(2, n + 1):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012591", "row_id": 12591, "seed_ids": "['magpie_prefill_12591']" }
0.708651
Prefill_12591
I
[ "is_prime", "primes_up_to_n" ]
2
[ [ "primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
108ddb58f28e9e013f134bcb86fcb2c5556476ed
fb29e31e1a91b4d5cd23ed5f0f66426f3a1e0d33
v1.0
instruct
Prefill
Prefill_12621_I
Write a function to determine the maximum possible value from a list of integers by concatenating the integers. For example, given a list [10, 2], the function should return 210 by concatenating 2 and 10. If the list is empty, return None. Ensure all integers in the list are non-negative.
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def max_concatenated_value(nums): """ Returns the maximum possible value from a list of integers by concatenating the integers. """ if not num...
from solution import max_concatenated_value def test_max_concatenated_value_single_element(): assert max_concatenated_value([1]) == '1' def test_max_concatenated_value_two_elements(): assert max_concatenated_value([10, 2]) == '210' def test_max_concatenated_value_with_zero(): assert max_concatenated_valu...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the maximum possible value from a list of integers by concatenating the integers.", "function_declaration": "def max_concatenated_value(num...
[ 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": "from typing import List, Optional\n\ndef max_concatenated_value(nums: List[int]) -> Optional[int]:\n \"\"\"\n Determine the maximum possible value by concatenating integers\n from th...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00012621", "row_id": 12621, "seed_ids": "['magpie_prefill_12621']" }
0.674594
Prefill_12621
I
[ "compare", "max_concatenated_value" ]
2
[ [ "max_concatenated_value", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
547fdae7db3fdf8c602f1ba683d4ebf959bd3764
0bb87873e07d3acc0644df9e1c808b3a1e6b6f2b
v1.0
instruct
Prefill
Prefill_12752_I
Write a function to find the smallest positive integer that is evenly divisible by all numbers from 1 to n.
from math import gcd def lcm(a, b): """ Returns the Least Common Multiple (LCM) of two integers a and b. """ return a * b // gcd(a, b) def smallest_multiple(n): """ Returns the smallest positive integer that is evenly divisible by all numbers from 1 to n. """ if n < 1: return N...
from solution import smallest_multiple, lcm from math import gcd def test_smallest_multiple_for_n_1(): assert smallest_multiple(1) == 1 def test_smallest_multiple_for_n_2(): assert smallest_multiple(2) == 2 def test_smallest_multiple_for_n_3(): assert smallest_multiple(3) == 6 def test_smallest_multiple...
[ { "docstring": "Returns the Least Common Multiple (LCM) of two integers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest positive integer that is evenly divisible by all numbers from 1 to 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": "from math import gcd\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef smallest_multiple(n):\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012752", "row_id": 12752, "seed_ids": "['magpie_prefill_12752']" }
0.65826
Prefill_12752
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed03f448fe7dc9ec72a3248f8bba5ed7c39ef817
eb963b74ebd3e6a47fa5dc93cded0fb291aca74f
v1.0
instruct
Prefill
Prefill_12821_I
Write a function to determine the number of days in a given month and year considering leap years. You should account for the different lengths of each month, and the fact that leap years have February with 29 days instead of the usual 28.
def days_in_month(year, month): """ Returns the number of days in a given month and year considering leap years. Parameters: - year (int): The year to consider (e.g., 2023) - month (int): The month to consider (1 for January, 2 for February, etc.) Returns: - int: The number of days in ...
from solution import days_in_month, is_leap_year def test_days_in_month_common_year(): assert days_in_month(2021, 1) == 31 assert days_in_month(2021, 2) == 28 assert days_in_month(2021, 3) == 31 assert days_in_month(2021, 4) == 30 assert days_in_month(2021, 5) == 31 assert days_in_month(2021, 6...
[ { "docstring": "Returns the number of days in a given month and year considering leap years.\n\nParameters:\n- year (int): The year to consider (e.g., 2023)\n- month (int): The month to consider (1 for January, 2 for February, etc.)\n\nReturns:\n- int: The number of days in the specified month of the specified ...
[ 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 days_in_month(year, month):\n \"\"\"\n Returns the number of days in a given month and year.\n \"\"\"\n if month < 1 or month > 12:\n raise ValueError(\"Month must be b...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00012821", "row_id": 12821, "seed_ids": "['magpie_prefill_12821']" }
0.650311
Prefill_12821
I
[ "days_in_month", "is_leap_year" ]
2
[ [ "days_in_month", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65514c8d0b55273f10bb61505118c29a0240c5be
ca1c0ffb9130bcebec18f0d453882109110fb62d
v1.0
instruct
Prefill
Prefill_12876_I
Write a function to calculate the sum of prime numbers up to a given number, `n`. For example, if `n` is 10, the function should return the sum of 2, 3, 5, and 7, which is 17. If `n` is 5, the sum should be 2 + 3 + 5 = 10.
def is_prime(num): """ Helper function to check if a number is prime. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_of_primes(n): """ Returns the sum of all prime numbers up to and includi...
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) def test_sum_of_primes_up_to_10(): assert sum_of_primes(10) == 17 def test_sum_of_primes_up_to_5(): assert sum_of_primes...
[ { "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 up to and including n.", "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(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if nu...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00012876", "row_id": 12876, "seed_ids": "['magpie_prefill_12876']" }
0.695778
Prefill_12876
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fae77b46b0cfde8b503e430b13062cacbf660258
150bbba8eadc64e2929618a0b4b46d79d6c7b017
v1.0
instruct
Prefill
Prefill_12938_I
Write a function to find the minimum cost to partition an array into subarrays such that the sum of elements in each subarray is a power of two. The cost is calculated as the length of the subarray. If there is no way to partition the array as described, return -1.
def is_power_of_two(x): return x != 0 and (x & (x - 1)) == 0 def min_partition_cost(arr): n = len(arr) dp = [float('inf')] * (n + 1) dp[0] = 0 for i in range(1, n+1): current_sum = 0 for j in range(i, 0, -1): current_sum += arr[j-1] if is_power_of_two(curren...
from solution import min_partition_cost def test_min_partition_cost_basic(): assert min_partition_cost([1, 1, 2, 4]) == 4 # [1], [1], [2], [4] def test_min_partition_cost_single_element(): assert min_partition_cost([8]) == 1 # [8] def test_min_partition_cost_no_valid_partition(): assert min_partition_c...
[ { "docstring": null, "function_declaration": "def is_power_of_two(x):", "function_name": "is_power_of_two", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def min_partition_cost(arr):", "function_name": "min_partition_cost", "parameter_list": "(arr)" }...
[ 0, 0, 1, 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 is_power_of_two(n):\n return (n != 0) and (n & (n - 1)) == 0\n\ndef min_cost_partition(arr):\n n = len(arr)\n dp = [float('inf')] * (n + 1)\n dp[0] = 0\n\n for i in range(n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00012938", "row_id": 12938, "seed_ids": "['magpie_prefill_12938']" }
0.666709
Prefill_12938
I
[ "is_power_of_two", "min_partition_cost" ]
2
[ [ "min_partition_cost", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
54097a728d0d484a7c4fb1a397b10a69a84db61e
003bfc45e6f42adedfcdfe355d4377e8339b3bdb
v1.0
instruct
Prefill
Prefill_13010_I
Write a function to check if an array of strings contains a palindrome. If it does, return the palindrome, otherwise return a message indicating no palindrome was found.
def is_palindrome(s): """ Helper function to check if a string is a palindrome. """ return s == s[::-1] def find_palindrome(strings): """ Returns the first palindrome from the list of strings if any. If no palindrome is found, returns a message indicating no palindrome was found. """ ...
from solution import find_palindrome def test_find_single_palindrome(): assert find_palindrome(["abc", "car", "radar"]) == "radar" def test_find_multiple_palindromes(): assert find_palindrome(["abc", "racecar", "amadama"]) == "racecar" def test_no_palindrome(): assert find_palindrome(["abc", "def", "ghi"...
[ { "docstring": "Helper function to check if a string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the first palindrome from the list of strings if any.\nIf no palindrome is found, retu...
[ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_palindrome(strings):\n \"\"\"\n Checks if the array of strings contains a palindrome.\n Returns the palindrome if found, else returns a message indicating no palindrome is f...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013010", "row_id": 13010, "seed_ids": "['magpie_prefill_13010']" }
0.708023
Prefill_13010
I
[ "is_palindrome", "find_palindrome" ]
2
[ [ "find_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f5c3078a0066964fd4ccc830c44c1787dfd6780
b1d5b8feaf9ab178a5bb342f8f3f1c54a2603f63
v1.0
instruct
Prefill
Prefill_13016_I
Write a function to rotate an array to the left by `k` steps. The rotation should be done in-place, meaning the array should be modified directly without using extra space for another array.
def rotate_left_in_place(nums, k): """ Rotates the elements of array nums to the left by k steps in-place. :param nums: List[int] - The array to be rotated. :param k: int - The number of steps to rotate the array. """ n = len(nums) k = k % n # To handle if k is greater than the length ...
from solution import rotate_left_in_place def test_rotate_left_in_place_single_rotation(): nums = [1, 2, 3, 4, 5] rotate_left_in_place(nums, 1) assert nums == [2, 3, 4, 5, 1] def test_rotate_left_in_place_multiple_rotations(): nums = [1, 2, 3, 4, 5] rotate_left_in_place(nums, 2) assert nums ==...
[ { "docstring": "Rotates the elements of array nums to the left by k steps in-place.\n\n:param nums: List[int] - The array to be rotated.\n:param k: int - The number of steps to rotate the array.", "function_declaration": "def rotate_left_in_place(nums, k):", "function_name": "rotate_left_in_place", ...
[ 0, 0, 1, 1, 1, 0, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_left(arr, k):\n \"\"\"\n Rotates array to the left by k steps in-place.\n \n Parameters:\n arr (list): The array to be rotated.\n k (int): Number of steps to rota...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013016", "row_id": 13016, "seed_ids": "['magpie_prefill_13016']" }
0.678918
Prefill_13016
I
[ "rotate_left_in_place", "reverse" ]
2
[ [ "rotate_left_in_place", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ebe9494cacb344d1aef60fb1c316c560e0d5db5
98cb2afa7333fbd6206199496de75682729ac365
v1.0
instruct
Prefill
Prefill_13059_I
Write a function to traverse three binary trees (t1, t2, and t3) and return their inorder traversal results.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def inorder_traversal(root): """ Performs an inorder traversal of a binary tree and returns the values in a list. """ if root is None: return [] ...
from solution import TreeNode, inorder_traversals def test_inorder_traversals_empty_trees(): assert inorder_traversals(None, None, None) == ([], [], []) def test_inorder_traversals_single_node_trees(): t1 = TreeNode(1) t2 = TreeNode(2) t3 = TreeNode(3) assert inorder_traversals(t1, t2, t3) == ([1]...
[]
[ 1, 0, 1, 1, 0, 1, 1, 1, 1, 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 inorder_traversal(root):\n \"\"\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013059", "row_id": 13059, "seed_ids": "['magpie_prefill_13059']" }
0.561165
Prefill_13059
I
[ "inorder_traversal", "inorder_traversals" ]
2
[ [ "inorder_traversals", "inorder_traversal" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0888b92e7b0453042846344fbbca89b78e5049ff
db1d0877aa6516f4e2616d29bd5c6dbddc5c19de
v1.0
instruct
Prefill
Prefill_13066_I
Write a function to sort an array of integers in ascending order using the quicksort algorithm. The function should take an array of integers and its length as parameters, and return the sorted array. Ensure that the function is efficient and handles various edge cases, such as empty arrays or arrays with duplicate val...
def quicksort(arr, low=0, high=None): """ Sorts an array of integers in ascending order using the quicksort algorithm. Parameters: arr (list): A list of integers to be sorted. low (int): The starting index of the array segment to sort. high (int): The ending index of the array segment to sort. ...
from solution import quicksort def test_quicksort_single_element(): assert quicksort([1]) == [1] def test_quicksort_sorted_array(): assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_quicksort_reverse_sorted_array(): assert quicksort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_quicksort_unso...
[ { "docstring": "Sorts an array of integers in ascending order using the quicksort algorithm.\n\nParameters:\narr (list): A list of integers to be sorted.\nlow (int): The starting index of the array segment to sort.\nhigh (int): The ending index of the array segment to sort.\n\nReturns:\nlist: The sorted array."...
[ 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 quicksort(arr):\n \"\"\"\n Sorts an array of integers in ascending order using the quicksort algorithm.\n\n Parameters:\n arr (list): The list of integers to be sorted.\n\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013066", "row_id": 13066, "seed_ids": "['magpie_prefill_13066']" }
0.620465
Prefill_13066
I
[ "quicksort", "partition" ]
2
[ [ "quicksort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c06c5bff4affdb7ebf154f7198b73240b030bcf
6d14b7d7db3bbb2ad382fe62986236ff7b7f0552
v1.0
instruct
Prefill
Prefill_13156_I
Write a function to check if a number is prime and then use this function to find all prime numbers less than a given number N.
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 for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def primes_less_than(N):...
from solution import is_prime, primes_less_than def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(-1) == False assert is_prime(0) == False assert is_prime(1) == False assert is_prime(25) == F...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Find all prime numbers less than a given number N.", "function_declaration": "def primes_less_than(N):", "function_nam...
[ 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 Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013156", "row_id": 13156, "seed_ids": "['magpie_prefill_13156']" }
0.70837
Prefill_13156
I
[ "is_prime", "primes_less_than" ]
2
[ [ "primes_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f7b0436de6f4f992b474bd81f43a8a3dfe1a4d2
98f662bd3f8cdc330dbc75088db4935151aa431c
v1.0
instruct
Prefill
Prefill_13221_I
Write a function to simulate a basic Blackjack game. How should the function be designed, and what rules should it include?
import random def card_value(card): if card in ['J', 'Q', 'K']: return 10 elif card == 'A': return 11 else: return int(card) def adjust_for_ace(hand): while sum(hand) > 21 and 11 in hand: hand[hand.index(11)] = 1 return hand def blackjack(): deck = ['2', '3', '...
from solution import card_value, adjust_for_ace, blackjack def test_card_value(): assert card_value('2') == 2 assert card_value('10') == 10 assert card_value('J') == 10 assert card_value('Q') == 10 assert card_value('K') == 10 assert card_value('A') == 11 def test_adjust_for_ace(): assert ...
[ { "docstring": null, "function_declaration": "def card_value(card):", "function_name": "card_value", "parameter_list": "(card)" }, { "docstring": null, "function_declaration": "def adjust_for_ace(hand):", "function_name": "adjust_for_ace", "parameter_list": "(hand)" }, { ...
[ 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef card_value(card):\n \"\"\"\n Calculates the value of a single card.\n \"\"\"\n if card in [\"J\", \"Q\", \"K\"]:\n return 10\n elif card == \"A\":\n...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00013221", "row_id": 13221, "seed_ids": "['magpie_prefill_13221']" }
0.423006
Prefill_13221
I
[ "card_value", "adjust_for_ace", "blackjack" ]
3
[ [ "blackjack", "adjust_for_ace" ], [ "blackjack", "card_value" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d1f3e8d2ea87be18afececaa0544de93d872a682
9bf0be3d0aa588c4d651b71d74f81c900dd55c92
v1.0
instruct
Prefill
Prefill_13301_I
Write a function to find the maximum element in an array using a divide and conquer approach. The function should be implemented in Python and should be efficient in terms of time complexity.
def find_max(arr): """ Returns the maximum element in an array using a divide and conquer approach. """ return find_max_recursive(arr, 0, len(arr) - 1) def find_max_recursive(arr, low, high): # Base case: Only one element if low == high: return arr[low] # Find the middle po...
from solution import find_max def test_find_max_single_element(): assert find_max([3]) == 3 def test_find_max_all_positive(): assert find_max([1, 2, 3, 4, 5]) == 5 def test_find_max_all_negative(): assert find_max([-5, -4, -3, -2, -1]) == -1 def test_find_max_mixed_values(): assert find_max([-10, 5,...
[ { "docstring": "Returns the maximum element in an array using a divide and conquer approach.", "function_declaration": "def find_max(arr):", "function_name": "find_max", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def find_max_recursive(arr, low, high):", ...
[ 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 find_maximum(arr):\n \"\"\"\n Function to find the maximum element in an array using divide and conquer approach.\n \n :param arr: List of integers\n :return: Maximum eleme...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013301", "row_id": 13301, "seed_ids": "['magpie_prefill_13301']" }
0.68347
Prefill_13301
I
[ "find_max", "find_max_recursive" ]
2
[ [ "find_max", "find_max_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d37dd8fae471399d4ae7a1619bd1bedb0bc6502e
af0a7040a47eb9ce932d658bf695e86b3a586664
v1.0
instruct
Prefill
Prefill_13661_I
Create a function that calculates the factorial of a number. The function should handle large numbers efficiently by using a loop. Additionally, include a check function to validate the correctness of the factorial function with provided data points.
def factorial(n): """ Returns the factorial of the given number n. """ 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 check_factorial(): """ Validates the correct...
from solution import factorial, check_factorial def test_factorial_base_cases(): assert factorial(0) == 1 assert factorial(1) == 1 def test_factorial_small_numbers(): assert factorial(5) == 120 assert factorial(3) == 6 def test_factorial_larger_numbers(): assert factorial(10) == 3628800 asser...
[ { "docstring": "Returns the factorial of the given number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Validates the correctness of the factorial function with known data points.", "function_declaration": "def ...
[ 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 factorial(n):\n \"\"\"\n Calculates the factorial of a non-negative integer n using an iterative approach.\n \"\"\"\n if n < 0:\n raise ValueError(\"Factorial is not de...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013661", "row_id": 13661, "seed_ids": "['magpie_prefill_13661']" }
0.637077
Prefill_13661
I
[ "factorial", "check_factorial" ]
2
[ [ "check_factorial", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
93881f6fe8be20c89420056a5473266d5f67abb5
db932e374b0ce461ef2ff8c4565dd980452921df
v1.0
instruct
Prefill
Prefill_13704_I
Create a function that takes a vector of integers as input and returns a vector of strings as output. The function should convert each integer in the vector to its corresponding Roman numeral representation. The function should handle integers in the range 1 to 1000 inclusive.
def int_to_roman(num): """ Convert an integer to a Roman numeral. Args: num (int): The integer to be converted. Range is 1 to 1000. Returns: str: The Roman numeral representation of the input integer. """ val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10,...
from solution import vector_to_roman def test_vector_to_roman(): assert vector_to_roman([1, 2, 3]) == ["I", "II", "III"] assert vector_to_roman([4, 5, 6]) == ["IV", "V", "VI"] assert vector_to_roman([10, 20, 30]) == ["X", "XX", "XXX"] assert vector_to_roman([50, 100, 500, 1000]) == ["L", "C", "D", "M"]...
[ { "docstring": "Convert an integer to a Roman numeral.\n\nArgs:\nnum (int): The integer to be converted. Range is 1 to 1000.\n\nReturns:\nstr: The Roman numeral representation of the input integer.", "function_declaration": "def int_to_roman(num):", "function_name": "int_to_roman", "parameter_list":...
[ 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 int_to_roman(num):\n \"\"\"\n Converts an integer to its corresponding Roman numeral.\n :param num: Integer between 1 and 1000 inclusive.\n :return: Roman numeral as a string....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013704", "row_id": 13704, "seed_ids": "['magpie_prefill_13704']" }
0.597608
Prefill_13704
I
[ "int_to_roman", "vector_to_roman" ]
2
[ [ "vector_to_roman", "int_to_roman" ] ]
1
[]
false
[]
false
pytest
true
[]
true
36ead35992da2489971afb2da239ef22b21fa17c
bcab473c9b790003767514cfa9846d7d617f67e2
v1.0
instruct
Prefill
Prefill_13733_I
Create a function that uses list comprehension to return a list of all prime numbers less than 100.
def is_prime(n): """ Helper function to check if a number n is a prime number. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def primes_less_than_100(): """ Returns a list of all prime numbers less tha...
from solution import is_prime, primes_less_than_100 def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-7) assert is_prime(97) assert not is_prime(100) def test_primes_less_than_100(): ...
[ { "docstring": "Helper function to check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers less than 100 using list comprehension.", "function_declarat...
[ 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 is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n %...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00013733", "row_id": 13733, "seed_ids": "['magpie_prefill_13733']" }
0.615195
Prefill_13733
I
[ "is_prime", "primes_less_than_100" ]
2
[ [ "primes_less_than_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8da5626de1e9f51c250388afc0c5a69107c8c947
2ffea28969fd0731c1bc5bdc0b4737345a80a031
v1.0
instruct
Prefill
Prefill_13840_I
Create a function that takes an integer as input and returns the next prime number greater than the input integer. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, the next prime number after 10 is 11. If the input number is already prime, the functio...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def next_prime(n): """ Returns the nex...
from solution import next_prime def test_next_prime_after_10(): assert next_prime(10) == 11 def test_next_prime_after_11(): assert next_prime(11) == 13 def test_next_prime_after_14(): assert next_prime(14) == 17 def test_next_prime_after_17(): assert next_prime(17) == 19 def test_next_prime_after_1...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the next prime number greater than the input integer.", "function_declaration": "def next_prime(n):", "function_name": "next_prime", "p...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00013840", "row_id": 13840, "seed_ids": "['magpie_prefill_13840']" }
0.654155
Prefill_13840
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c880496357419fa43d36dd638f553ee5f7312321
a41601c7488a176942d0332ca8ec81b0d019a56c
v1.0
instruct
Prefill
Prefill_13950_I
Create a function that receives an integer `n` as input and returns the least common multiple (LCM) of all numbers from 1 to `n`.
from math import gcd def lcm(a, b): """ Return the least common multiple of a and b. """ return a * b // gcd(a, b) def lcm_range(n): """ Return the least common multiple of all numbers from 1 to n. """ if n <= 0: raise ValueError("Input must be a positive integer") res...
from solution import lcm_range def test_lcm_range_1(): assert lcm_range(1) == 1 def test_lcm_range_2(): assert lcm_range(2) == 2 def test_lcm_range_3(): assert lcm_range(3) == 6 def test_lcm_range_4(): assert lcm_range(4) == 12 def test_lcm_range_5(): assert lcm_range(5) == 60 def test_lcm_ran...
[ { "docstring": "Return the least common multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Return the least common multiple of all numbers from 1 to n.", "function_declaration": "def lcm_range(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": "from math import gcd\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef lcm_of_range(n):\n \"\"\"\n Retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013950", "row_id": 13950, "seed_ids": "['magpie_prefill_13950']" }
0.667239
Prefill_13950
I
[ "lcm", "lcm_range" ]
2
[ [ "lcm_range", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9328ed1f5557ebc5cb6b541295684d17792c000d
6eb8f2b7f35c38a19425fb9884d6a2982df7b179
v1.0
instruct
Prefill
Prefill_13965_I
Create a function that filters out prime numbers from a list and returns a new list containing only the composite numbers. In Python, how can I write a function named `filter_primes` that accomplishes this task?
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_prime...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(17) == True assert is_prime(18) == False...
[ { "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 out prime numbers from a list and returns a new list containing only composite numbers.", "function...
[ 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 Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n i...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00013965", "row_id": 13965, "seed_ids": "['magpie_prefill_13965']" }
0.606631
Prefill_13965
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
93761df72a7342b503d1bbfadab5f86b9f943f4b
971ed7a3246b1aad12cb4583e20606dfed9a6a33
v1.0
instruct
Prefill
Prefill_13969_I
Create a function that takes two integers, `M` and `N`, and returns the list of prime numbers between `M` and `N` (inclusive). The function should efficiently find prime numbers and handle edge cases, such as when `M` is greater than `N`.
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 for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def f...
from solution import find_primes def test_find_primes_standard_range(): assert find_primes(10, 20) == [11, 13, 17, 19] def test_find_primes_single_prime(): assert find_primes(13, 13) == [13] def test_find_primes_no_primes(): assert find_primes(14, 16) == [] def test_find_primes_negative_range(): ass...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers between M and N (inclusive).", "function_declaration": "def find_primes...
[ 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 if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00013969", "row_id": 13969, "seed_ids": "['magpie_prefill_13969']" }
0.637058
Prefill_13969
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ee1b94cc80cd7b000b42964e7b04861e0a8eebe
9f0ffc98a97878457195b04ca906ce30d8453cfd
v1.0
instruct
Prefill
Prefill_14004_I
Create a function that identifies the smallest prime number greater than a given number. For example, if the input number is 11, the function should return 13 as it is the smallest prime number greater than 11.
import math def is_prime(n): """ Check if the given number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return Fals...
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 assert is_prime(29) == True def test_smallest_prime_greater_than(): ass...
[ { "docstring": "Check if the given number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the smallest prime number greater than the given number n.", "function_declaration": "def smallest_...
[ 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 a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014004", "row_id": 14004, "seed_ids": "['magpie_prefill_14004']" }
0.627668
Prefill_14004
I
[ "is_prime", "smallest_prime_greater_than" ]
2
[ [ "smallest_prime_greater_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87063ee8143eb34f4f55546a9ad40274ef826850
716fcfa9dc9c4e6d6246739a73ed1383bc5fee8e
v1.0
instruct
Prefill
Prefill_14038_I
Create a function that takes a list of integers as an argument and returns the factorial of the provided list of integers using recursion. The function should iterate over the provided list of integers, calculate the factorial for each integer and also consider the factorial of all the elements present so far in the li...
def factorial(n): """ Returns the factorial of a given number n. """ if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) def list_factorials(lst): """ Returns a list where each element is the factorial of all the elements present so far in the list. """ r...
from solution import list_factorials def test_list_factorials_single_element(): assert list_factorials([1]) == [1] assert list_factorials([2]) == [2] assert list_factorials([3]) == [6] def test_list_factorials_multiple_elements(): assert list_factorials([1, 2, 3]) == [1, 2, 12] assert list_factori...
[ { "docstring": "Returns the factorial of a given number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns a list where each element is the factorial of all the elements present so far in the list.", "functio...
[ 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"Helper function to calculate factorial of a single integer recursively.\"\"\"\n if n == 0 or n == 1:\n return 1\n return n * factorial(n - 1)\n\ndef ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014038", "row_id": 14038, "seed_ids": "['magpie_prefill_14038']" }
0.732828
Prefill_14038
I
[ "factorial", "list_factorials" ]
2
[ [ "list_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18043d1c56190609309408273ed944b6a8455fb6
da32021b5efcfb466d58bf5adb02249a8fed3674
v1.0
instruct
Prefill
Prefill_14131_I
Create a function that takes two integers as input and returns the sum of all prime numbers between the two integers (inclusive). If either of the input integers is less than 2, the function should return a default value of -1. Otherwise, return the sum of all prime numbers found. If the range does not contain any prim...
def is_prime(n): """ Helper function to determine if a number is prime. """ if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_primes_between(a, b): """ Returns the sum of all prime numbers between a and...
from solution import sum_primes_between def test_sum_primes_between_normal_case(): assert sum_primes_between(10, 20) == 60 # 11, 13, 17, 19 def test_sum_primes_between_include_two(): assert sum_primes_between(0, 5) == -1 # one value below 2 def test_sum_primes_between_no_primes(): assert sum_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 all prime numbers between a and b (inclusive).\nIf either a or b is less than 2, returns...
[ 1, 0, 0, 0, 1, 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 sum_of_primes_in_range(a, b):\n \"\"\"\n Returns the sum of all prime numbers between a and b (inclusive).\n If either of the input integers is less than 2, the function returns ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00014131", "row_id": 14131, "seed_ids": "['magpie_prefill_14131']" }
0.622788
Prefill_14131
I
[ "is_prime", "sum_primes_between" ]
2
[ [ "sum_primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05947a2137f759ce10f8f86e975d0790c41ef75c
21e02b8ef565d6226ac8c7bf8f3650b666d6c24b
v1.0
instruct
Prefill
Prefill_14200_I
Create a function that returns the Fibonacci sequence up to the nth term using recursion. The function should be efficient and handle large values of n without causing a stack overflow error.
def fibonacci(n, memo={}): """ Returns the nth term of the Fibonacci sequence using recursion and memoization. """ if n in memo: return memo[n] if n <= 0: return 0 elif n == 1: return 1 memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo) return mem...
from solution import fibonacci_sequence def test_fibonacci_sequence_positive(): assert fibonacci_sequence(5) == [0, 1, 1, 2, 3] assert fibonacci_sequence(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def test_fibonacci_sequence_zero(): assert fibonacci_sequence(0) == [] def test_fibonacci_sequence_one(): ...
[ { "docstring": "Returns the nth term of the Fibonacci sequence using recursion and memoization.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": "fibonacci", "parameter_list": "(n, memo={})" }, { "docstring": "Returns the fibonacci sequence up to the nth term.", "...
[ 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 fibonacci(n, memo = {}):\n \"\"\"\n Returns the Fibonacci sequence up to the nth term using recursion with memoization.\n \n Parameters:\n - n: The nth term up to which the...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014200", "row_id": 14200, "seed_ids": "['magpie_prefill_14200']" }
0.667158
Prefill_14200
I
[ "fibonacci", "fibonacci_sequence" ]
2
[ [ "fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ba50997b84369d1c7d2e0fe4ed0e4bfdd6b0b279
c840078c17f0cce8abbe36f332dd40f4c2335642
v1.0
instruct
Prefill
Prefill_14214_I
Create a function that takes an array of integers, counts the prime numbers in the array, and returns that count. Ensure to handle the case where the array may contain negative numbers and zeros.
def is_prime(n): 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 count_primes(arr): return sum(1 for x in arr if is_prime(x))
from solution import count_primes def test_no_primes(): assert count_primes([-10, -5, 0, 1, 4, 6, 8, 9, 10]) == 0 def test_some_primes(): assert count_primes([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 5 def test_all_primes(): assert count_primes([2, 3, 5, 7, 11]) == 5 def test_empty_array(): assert count_...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_primes(arr):", "function_name": "count_primes", "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 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_4
{ "original_instruction": "", "prompt_id": "00014214", "row_id": 14214, "seed_ids": "['magpie_prefill_14214']" }
0.740466
Prefill_14214
I
[ "is_prime", "count_primes" ]
2
[ [ "count_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
40c7d385cdc6aab57031f044f07c9ad684f78f73
eef55d4496592da6243cd4a8ec0ca2d795726494
v1.0
instruct
Prefill
Prefill_14258_I
Create a function that takes a list of integers and returns a new list containing the length of each integer if it is a palindrome and 0 otherwise.
def is_palindrome(n): """ Checks if an integer n is a palindrome. """ s = str(n) return s == s[::-1] def palindrome_lengths(lst): """ Takes a list of integers and returns a new list containing the length of each integer if it is a palindrome and 0 otherwise. """ result = [] ...
from solution import is_palindrome, palindrome_lengths def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1221) == True assert is_palindrome(1) == True assert is_palindrome(-121) == False # Negative numbers are not palindromes def t...
[ { "docstring": "Checks if an integer n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a new list containing the length of each integer \nif it is a palindrom...
[ 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 is_palindrome(n):\n \"\"\"\n Returns True if n is a palindrome, False otherwise.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef palindrome_lengths(numbers):\n \"\"\"...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014258", "row_id": 14258, "seed_ids": "['magpie_prefill_14258']" }
0.688684
Prefill_14258
I
[ "is_palindrome", "palindrome_lengths" ]
2
[ [ "palindrome_lengths", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ec86d392e46173edf99fc4a9c92e49457199547
cc85ed4f6f6f9ed8a34a75753632dbd74a421890
v1.0
instruct
Prefill
Prefill_14403_I
Create a function that takes in a list of integers and returns a new list with all the prime numbers from the original list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5)+1, 2): if n % i == 0: return False return True def filter_primes(numbers): """ ...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_no_primes(): assert filter_primes([1, 4, 6, 8, 9, 10]) == [] def test_filter_primes_with_only_primes(): assert filter_primes([2...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, return a new list with all the prime numbers from the original list.", "function_declaration": "def ...
[ 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 Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 =...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014403", "row_id": 14403, "seed_ids": "['magpie_prefill_14403']" }
0.633865
Prefill_14403
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d91ef7adb98b194c7efa43d72653dbfd2cf7c93e
c025c98a15eabdea7f647afe0b27fb487d64a243
v1.0
instruct
Prefill
Prefill_14473_I
Create a function that takes an integer `N` as input and returns the sum of all prime numbers less than or equal to `N`. For example, if `N` is 10, the function should return the sum of 2, 3, 5, and 7, which is 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): """ ...
from solution import sum_of_primes def test_sum_primes_under_10(): assert sum_of_primes(10) == 17 def test_sum_primes_under_1(): assert sum_of_primes(1) == 0 def test_sum_primes_under_2(): assert sum_of_primes(2) == 2 def test_sum_primes_under_20(): assert sum_of_primes(20) == 77 def test_sum_prime...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all prime numbers less than or equal to N.", "function_declaration": "def sum_of_primes(N):", "function_name": "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 \"\"\"Helper function to determine if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00014473", "row_id": 14473, "seed_ids": "['magpie_prefill_14473']" }
0.708013
Prefill_14473
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c6f288d3955a477bc7de9b3faad007f7f77a56e
f22d77d90e4e33b23b65a9fea088cb52e51547db
v1.0
instruct
Prefill
Prefill_14492_I
Create a function that takes a number as input and returns its factorial, but only if the number is a prime. If the number is not a prime, the function should return "Input is not a prime number".
def is_prime(n): """ Helper function that checks if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def factorial(n): """ Helper function that calculates the factorial of a number. ...
from solution import prime_factorial def test_prime_factorial_prime(): assert prime_factorial(2) == 2 assert prime_factorial(3) == 6 assert prime_factorial(5) == 120 assert prime_factorial(7) == 5040 def test_prime_factorial_not_prime(): assert prime_factorial(1) == "Input is not a prime number" ...
[ { "docstring": "Helper function that checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Helper function that calculates the factorial of a number.", "function_declaration": "def factorial(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(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i =...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00014492", "row_id": 14492, "seed_ids": "['magpie_prefill_14492']" }
0.674377
Prefill_14492
I
[ "is_prime", "factorial", "prime_factorial" ]
3
[ [ "prime_factorial", "factorial" ], [ "prime_factorial", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fe61563436e89feda7f012067b7dfed8bf3f8332
c3433017593bf3cadd3ccebfd0a309b68794508f
v1.0
instruct
Prefill
Prefill_14512_I
Create a function that sorts a list of strings in Python using the merge sort algorithm. Additionally, write a docstring to describe what your function does and explain its parameters.
def merge_sort(lst): """ Sorts a list of strings in ascending order using the merge sort algorithm. Parameters: lst (list of str): The list of strings to be sorted. Returns: list of str: The sorted list of strings. """ if len(lst) <= 1: return lst # Find the middle point t...
from solution import merge_sort def test_sorted_list(): assert merge_sort(["apple", "banana", "cherry"]) == ["apple", "banana", "cherry"] def test_reverse_sorted_list(): assert merge_sort(["cherry", "banana", "apple"]) == ["apple", "banana", "cherry"] def test_unsorted_list(): assert merge_sort(["banana"...
[ { "docstring": "Sorts a list of strings in ascending order using the merge sort algorithm.\n\nParameters:\nlst (list of str): The list of strings to be sorted.\n\nReturns:\nlist of str: The sorted list of strings.", "function_declaration": "def merge_sort(lst):", "function_name": "merge_sort", "para...
[ 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 merge_sort_strings(arr):\n \"\"\"\n Sorts a list of strings using the merge sort algorithm.\n \n Parameters:\n arr (list): A list of strings to be sorted.\n \n Return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014512", "row_id": 14512, "seed_ids": "['magpie_prefill_14512']" }
0.584793
Prefill_14512
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35fdec52a7e679354fa6570f14286b586385e579
d4dbac7104fed3fa15621cc5f6c10a53aee124bc
v1.0
instruct
Prefill
Prefill_14544_I
Create a function that takes in a list of integers, `nums`, and returns the sum of all prime numbers in the list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, 7, 11, and 13 are all prime numbers. If there are no prime numbers in the list,...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return Fal...
from solution import sum_of_primes def test_sum_no_primes(): assert sum_of_primes([]) == 0 assert sum_of_primes([0, 1, -1, -5, -17]) == 0 assert sum_of_primes([4, 6, 8, 10, 12]) == 0 def test_sum_single_prime(): assert sum_of_primes([2]) == 2 assert sum_of_primes([3]) == 3 assert 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 in the list.\nIf there are no prime numbers, returns 0.", "function_de...
[ 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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014544", "row_id": 14544, "seed_ids": "['magpie_prefill_14544']" }
0.682329
Prefill_14544
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b771237fa39d9c8d5dc538612ca737d065f7c76
5fc8180aa9da070f318cd5b0e50f68fcb41df32e
v1.0
instruct
Prefill
Prefill_14587_I
Create a function that will take two positive integers as parameters and return the number of HCF (Highest Common Factor) combinations between the two numbers. If the HCF is a prime number, return the prime factorization of that HCF as a list of its prime factors. If the HCF is not a prime number, return the HCF in its...
from math import gcd def prime_factors(n): """ Returns the prime factors of a number n as a list. """ factors = [] # Check for smallest factors first i = 2 while i * i <= n: while (n % i) == 0: factors.append(i) n //= i i += 1 if n > 1: fa...
from solution import hcf_factors def test_hcf_prime_result(): assert hcf_factors(40, 30) == (10, [1, 2, 5, 10]) def test_hcf_composite_result(): assert hcf_factors(27, 34) == (1, [1]) def test_hcf_self_factor(): assert hcf_factors(13, 13) == (13, [13]) def test_hcf_prime(): assert hcf_factors(13, 39...
[ { "docstring": "Returns the prime factors of a number n as a list.", "function_declaration": "def prime_factors(n):", "function_name": "prime_factors", "parameter_list": "(n)" }, { "docstring": "Returns the HCF and its decomposition based on whether\nthe HCF is a prime number or not.", "...
[ 0, 1, 0, 0, 0, 0, 1, 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 sympy import primefactors\n\ndef hcf_combinations(a, b):\n \"\"\"\n Returns the HCF (Highest Common Factor) between two positive integers `a` and `b`.\n If the HCF ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00014587", "row_id": 14587, "seed_ids": "['magpie_prefill_14587']" }
0.624201
Prefill_14587
I
[ "prime_factors", "hcf_factors" ]
2
[ [ "hcf_factors", "prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5dea22cfb193d6a2b2a17e4cb3de5704b245c660
c84c5133323c31fe679c7be02e2b339307c8ca2a
v1.0
instruct
Prefill
Prefill_14599_I
Create a function that takes a list of integers `arr` and an integer `n` as parameters. The function should insert the integer `n` at the beginning of the list `arr` and return the updated list. Additionally, the function should handle cases where `n` is a prime number special case: if `n` is a prime number, insert it ...
def is_prime(num): """ Helper function to determine if a number is prime. Returns True if num is prime, False otherwise. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def insert_special(arr, n): ...
from solution import insert_special def test_insert_special_non_prime(): assert insert_special([2, 3, 4], 5) == [2, 3, 4, 5] # 5 is prime assert insert_special([2, 4, 6], 4) == [4, 2, 4, 6] # 4 is not prime def test_insert_special_prime(): assert insert_special([1, 2, 3], 7) == [1, 2, 3, 7] # 7 is prim...
[ { "docstring": "Helper function to determine if a number is prime.\nReturns True if num is prime, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Inserts the integer n at the beginning of the list arr....
[ 0, 1, 1, 1, 1, 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(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014599", "row_id": 14599, "seed_ids": "['magpie_prefill_14599']" }
0.647413
Prefill_14599
I
[ "is_prime", "insert_special" ]
2
[ [ "insert_special", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8580f81791976bb9e30c30c1db2f8f870d6c0090
e7ac458ccbdd3cc6a974893965d95fecac310c4b
v1.0
instruct
Prefill
Prefill_14737_I
Create a function that calculates the sum of all divisors of a given number `n` (excluding `n` itself). If the sum of the divisors is a prime number, return `True`; otherwise, return `False`.
import math def is_prime(num): if num <= 1: return False for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: return False return True def sum_of_divisors(n): """ Returns the sum of all divisors of n excluding n itself. """ total_sum = 0 for i in ran...
from solution import sum_divisors_is_prime def test_sum_of_divisors_is_prime(): # 6 has divisors 1, 2, 3. Their sum is 6, which is not a prime number. assert sum_divisors_is_prime(6) == False # 28 has divisors 1, 2, 4, 7, 14. Their sum is 28, which is not a prime number. assert sum_divisors_is_prime(2...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of all divisors of n excluding n itself.", "function_declaration": "def sum_of_divisors(n):", "function_name": "sum_of_divisors...
[ 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": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(math.sqrt(num)) + 1):\n if num % i == 0:\n return False\n return True...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00014737", "row_id": 14737, "seed_ids": "['magpie_prefill_14737']" }
0.829018
Prefill_14737
I
[ "is_prime", "sum_of_divisors", "sum_divisors_is_prime" ]
3
[ [ "sum_divisors_is_prime", "is_prime" ], [ "sum_divisors_is_prime", "sum_of_divisors" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d54deb2a0fb80cf62e20861c62a3c48fb33a4449
deccca498d898c1a80efa67319a23b96e31b3d8c
v1.0
instruct
Prefill
Prefill_14891_I
Create a function that takes an integer n and outputs an array with all the integers in the range [0, n] where the integer can be expressed as the sum of two squares. To implement this, utilize the established theorems that relate to expressing integers as the sum of two squares.
import math def is_sum_of_two_squares(n): """ Returns True if the integer n can be expressed as the sum of two squares. """ for i in range(int(math.sqrt(n)) + 1): j = math.sqrt(n - i * i) if j == int(j): return True return False def sum_of_two_squares_range(n): """ ...
from solution import is_sum_of_two_squares, sum_of_two_squares_range def test_is_sum_of_two_squares(): assert is_sum_of_two_squares(0) == True # 0 = 0^2 + 0^2 assert is_sum_of_two_squares(1) == True # 1 = 1^2 + 0^2 assert is_sum_of_two_squares(2) == True # 2 = 1^2 + 1^2 assert is_sum_of_two_squares(...
[ { "docstring": "Returns True if the integer n can be expressed as the sum of two squares.", "function_declaration": "def is_sum_of_two_squares(n):", "function_name": "is_sum_of_two_squares", "parameter_list": "(n)" }, { "docstring": "Returns a list of integers in the range [0, n] that can be...
[ 1, 1, 1, 0, 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": "import math\n\ndef sum_of_two_squares(n):\n \"\"\"\n Returns a list of integers in the range [0, n] that can be\n expressed as the sum of two squares.\n \"\"\"\n result = []\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00014891", "row_id": 14891, "seed_ids": "['magpie_prefill_14891']" }
0.634115
Prefill_14891
I
[ "is_sum_of_two_squares", "sum_of_two_squares_range" ]
2
[ [ "sum_of_two_squares_range", "is_sum_of_two_squares" ] ]
1
[]
false
[]
false
pytest
true
[]
true
775183d1579f3ed861f9abdcd33f3df0227801bf
f4e6186bbc61c7af5a2e0ba194d582a630af7139
v1.0
instruct
Prefill
Prefill_14985_I
Create a function that finds all the prime numbers in a given list of integers. A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself.
def is_prime(n): """ Determines if a given number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def find_primes(arr): ...
from solution import find_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(28) == False assert is_prime(29) == True def test_find_primes_with_primes(): assert find_primes([2, 3...
[ { "docstring": "Determines if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the given list arr.", "function_declaration": "def find_primes(arr):", ...
[ 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": "def is_prime(n):\n \"\"\"\n Checks if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00014985", "row_id": 14985, "seed_ids": "['magpie_prefill_14985']" }
0.651883
Prefill_14985
I
[ "is_prime", "find_primes" ]
2
[ [ "find_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6bfdbabcde59734996b0b19fdab25c97168b42ad
82c337b988bbf95aabbe20a316b2411fed3b9289
v1.0
instruct
Prefill
Prefill_15067_I
Create a function that generates a Fibonacci sequence with memoization to improve performance.
def fibonacci(n, memo={}): """ Generates the nth Fibonacci number with memoization. :param n: The position in the Fibonacci sequence. :param memo: Dictionary to store previously computed Fibonacci numbers. :return: The nth Fibonacci number. """ if n in memo: return memo[n] i...
from solution import generate_fibonacci_sequence, fibonacci def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_known_values(): assert fibonacci(2) == 1 # 0, 1, 1 assert fibonacci(3) == 2 # 0, 1, 1, 2 assert fibonacci(4) == 3 # 0, 1, 1, 2, 3 ...
[ { "docstring": "Generates the nth Fibonacci number with memoization.\n\n:param n: The position in the Fibonacci sequence.\n:param memo: Dictionary to store previously computed Fibonacci numbers.\n:return: The nth Fibonacci number.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": ...
[ 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, memo={}):\n \"\"\"\n Returns the nth Fibonacci number using memoization.\n \"\"\"\n if n in memo:\n return memo[n]\n if n <= 1:\n return n\n m...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00015067", "row_id": 15067, "seed_ids": "['magpie_prefill_15067']" }
0.652374
Prefill_15067
I
[ "fibonacci", "generate_fibonacci_sequence" ]
2
[ [ "generate_fibonacci_sequence", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
edf8f6e3079e53e7581f1a8ecac8e6c502bbb686
0cd8e5f02bc6855e52952b1b6e1df942dc712586
v1.0
instruct
Prefill
Prefill_15117_I
Create a function that implements the Merge Sort algorithm.
def merge_sort(arr): """ Function that implements the Merge Sort algorithm. It recursively splits the array into halves and merges the sorted halves. Args: arr (list): List of elements to be sorted. Returns: list: A new sorted list. """ if len(arr) <= 1: return arr # Fin...
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_two_elements(): assert merge_sort([2, 1]) == [1, 2] def test_merge_sort_multiple_elements(): assert merge_sort([5, 3, 8, 6,...
[ { "docstring": "Function that implements the Merge Sort algorithm.\nIt recursively splits the array into halves and merges the sorted halves.\nArgs:\narr (list): List of elements to be sorted.\nReturns:\nlist: A new sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_s...
[ 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 if len(arr) <= 1:\n return arr\n \n # Find the middle poi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00015117", "row_id": 15117, "seed_ids": "['magpie_prefill_15117']" }
0.777253
Prefill_15117
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70a7e4411d7e8eae82be58d1268a6eaa8a7357f7
397fc5c89624bcbe3701a2326c74d0fb7a5f90f3
v1.0
instruct
Prefill
Prefill_15292_I
Create a function that calculates the sum of all prime numbers between two given positive integers, `start` and `end`.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes(start, end): """ Returns the sum of all prime numbers between start...
from solution import sum_of_primes def test_sum_of_primes_in_small_range(): assert sum_of_primes(2, 10) == 17 # 2, 3, 5, 7 are primes def test_sum_of_primes_single_value(): assert sum_of_primes(1, 1) == 0 # 1 is not a prime assert sum_of_primes(2, 2) == 2 # 2 is prime def test_sum_of_primes_no_...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between start and end (inclusive).", "function_declaration": "def su...
[ 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 ]
4
medium
0.4
{ "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 if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00015292", "row_id": 15292, "seed_ids": "['magpie_prefill_15292']" }
0.630891
Prefill_15292
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3aba5835f7b9559fe74d6a5b46dbe57bf89b269a
3f99c48fa187cc2d8bd196c6cd7e33f48eea0559
v1.0
instruct
Prefill
Prefill_15468_I
Create a function that takes in two integers and returns the nearest common ancestor (NCA) for both the integers, given they are both part of a Binary Search Tree (BST). How can you solve this problem by first finding the path from the root to each node?
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def find_path(root, path, k): if root is None: return False path.append(root) if root.val == k: return True if ((root.left != None and find_pa...
import pytest from solution import TreeNode, find_nearest_common_ancestor def test_nca_basic(): root = TreeNode(3) root.left = TreeNode(5) root.right = TreeNode(1) root.left.left = TreeNode(6) root.left.right = TreeNode(2) root.right.left = TreeNode(0) root.right.right = TreeNode(8) 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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_path(root, path, k):\n # Ba...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00015468", "row_id": 15468, "seed_ids": "['magpie_prefill_15468']" }
0.512608
Prefill_15468
I
[ "find_path", "find_nearest_common_ancestor" ]
2
[ [ "find_nearest_common_ancestor", "find_path" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7a6622650d406ebcf9c86a259cecd544b4d1d0fe
5652ce853c30c605fb6e7c5c9a4fb1b535cbdc01
v1.0
instruct
Prefill
Prefill_15501_I
Create a function that calculates the sum of all prime numbers up to a given number n, using Python. How can I make this function efficient?
def is_prime(num): """ Returns True if num is a prime number, otherwise 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 Tr...
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(1) == False assert is_prime(0) == False def test_sum_of_primes(): ...
[ { "docstring": "Returns True if num is a prime number, otherwise 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...
[ 0, 1, 1, 1, 0, 1, 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(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00015501", "row_id": 15501, "seed_ids": "['magpie_prefill_15501']" }
0.682919
Prefill_15501
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b6042e0cba83982d707244501d18dc005461f699
7dc70358551c0b7e76ab67c2603adc92b863719d