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 | complete | Prefill | Prefill_9833_C | def merge_sort(arr):
"""
Sort an array of numbers using the merge sort algorithm.
"""
# Complete the implementation of merge sort.
pass
def merge(left, right):
"""
Merge two sorted arrays into one sorted array.
"""
# Complete the implementation of merge.
pass
from solution impo... | 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": "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 e... | 0.635214 | Prefill_9833 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a688510c3408ad8d0a28f80f9ea9f3257dcf7d70 | 42095ae763a3fe4544c9613548fccd59fb679728 | |||
v1.0 | complete | Prefill | Prefill_9323_C | def play_tic_tac_toe(moves):
"""
Simulates a game of Tic-Tac-Toe given a list of moves.
Moves should be provided as tuples of (player, row, col) where player is 'X' or 'O',
and row and col are the 0-indexed positions on the board.
Returns the result of the game: 'X', 'O', 'Draw', or 'Pending'.
... | 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": "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.",
"prompt_id": "00009323",
"row_id": 9323,
"seed_ids": "['magpie_prefill_9323']"
} | 0.554231 | Prefill_9323 | C | [
"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 | e41007683ace3db09a760374246ad9edfa04b7ff | 7a125f3ecda204591e75a1e68d7a313591189afb | |||
v1.0 | complete | Prefill | Prefill_10342_C | from typing import List
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(17) == True
>>> is_prime(20) == False
"""
def extract_primes(arr: List[int]) -> List[int]:
"""
Extracts ... | 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": "Write a function to extract all prime numbers from an array and return them in a new array.",
"prompt_id": "00010342",
"row_id": 10342,
"seed_ids": "['magpie_prefill_10342']"
} | 0.744942 | Prefill_10342 | C | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90d4a6db5bad35b6ce08f735bd25ad505d0cd6a0 | 2d6f60405dbaf6172df3e8d401a01680e3a0bbe4 | |||
v1.0 | complete | Prefill | Prefill_10445_C | def is_prime(n: int) -> bool:
"""Helper function to check if a number n is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(17) True
>>> is_prime(18) False
>>> is_prime(1) False
>>> is_prime(0) False
"""
def primes_up_to_n(N: int) -> List[int]:
... | 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": "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?",
"prompt_id": "00010445",
"row_id": 10445,
"seed_ids": "['magpie_prefill_10445']"
} | 0.830068 | Prefill_10445 | C | [
"is_prime",
"primes_up_to_n"
] | 2 | [
[
"primes_up_to_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3b6ea98ce61abd2ced3db7479777537f0d5f377 | 61f812b563cf62930744818d18c4cc8f7d9ae925 | |||
v1.0 | complete | Prefill | Prefill_11020_C | 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.
>>> s = TreeNode(3, TreeNode(4, TreeNode(1), TreeNode(2)), TreeNode(... | 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": "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.",
"prompt_id": "00011020",
"row_id": 11020,
"seed_ids": "['magpie_prefill_11020']"
} | 0.580652 | Prefill_11020 | C | [
"is_subtree",
"is_same_tree"
] | 2 | [
[
"is_subtree",
"is_same_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5cfa6ffc285a2c89392a598dde028309ac138e77 | c6444666ae2c47f6b72acf07930c14a1aa5568b6 | |||
v1.0 | complete | Prefill | Prefill_11050_C | 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.
>>> roo... | 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": "Write a function to find the minimum or maximum element in a binary tree based on the given direction (min or max).",
"prompt_id": "00011050",
"row_id": 11050,
"seed_ids": "['magpie_prefill_11050']"
} | 0.545538 | Prefill_11050 | C | [
"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 | 623a72c1ebf230886f4d76b7d1659a88028424a8 | 7e10227a346b404d4b464daa9813e2e1f719fd96 | |||
v1.0 | complete | Prefill | Prefill_11354_C | def fibonacci_recursive(n):
"""
Returns the nth Fibonacci number using recursion.
>>> fibonacci_recursive(1) == 0
>>> fibonacci_recursive(2) == 1
>>> fibonacci_recursive(3) == 1
>>> fibonacci_recursive(4) == 2
>>> fibonacci_recursive(5) == 3
>>> fibonacci_recursive(6) == 5
"""
pa... | 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": "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.",
"prompt_id": "00011354",
"row_id": 11354,
"seed_ids": "['magpie_prefill_11354']"
} | 0.72798 | Prefill_11354 | C | [
"fibonacci_recursive",
"fibonacci_iterative",
"compare_performance"
] | 3 | [
[
"compare_performance",
"fibonacci_iterative"
],
[
"compare_performance",
"fibonacci_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 691f05ea9997968e05601e921c1d6ab1a3d8621f | ba1fcd62502c6f201b815ede117f8c381944a022 | |||
v1.0 | complete | Prefill | Prefill_11656_C | def is_palindrome(n: int) -> bool:
"""
Checks if a number n is a palindrome.
>>> is_palindrome(121) True
>>> is_palindrome(123) False
>>> is_palindrome(1221) True
>>> is_palindrome(12321) True
>>> is_palindrome(13331) True
>>> is_palindrome(123456) False
"""
def largest_palindro... | 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": "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.",
"prompt_id": "00011656",
"row_id": 11656,
"seed_ids": "['magpie_prefi... | 0.695438 | Prefill_11656 | C | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 435b43bea4e5432d257778831f85e5ddc83c4ad9 | 2c2d971d71f85ea58edefae031f3144bef777698 | |||
v1.0 | complete | Prefill | Prefill_9923_C | from typing import Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def delete_node(root: Optional[TreeNode], key: int) -> Optional[TreeNode]:
"""
Delete a node with the given value in a BST and return the... | 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": "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.",
"prompt_id": "00009923",
"row_i... | 0.592005 | Prefill_9923 | C | [
"delete_node",
"find_min_value"
] | 2 | [
[
"delete_node",
"find_min_value"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | aaa3142189544dabd9736f331098d45f683a8595 | 0bdaebccddfccbefa18413a4506d6e98e0227401 | |||
v1.0 | complete | Prefill | Prefill_11131_C | def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(0) False
>>> is_prime(1) False
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(29) True
>>> is_prime(30) False
"""
pass
def next_pr... | 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": "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?",
"prompt_id": "00011131",
"row_id": 11131,
"seed_ids": "['magpie_prefill_11131']"
} | 0.84388 | Prefill_11131 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 080c0664e2c00b89bbeb51d81fbe6b914c657e33 | 3be569df54324c91e8381c41c96118017ebcabe8 | |||
v1.0 | complete | Prefill | Prefill_11349_C | def generate_binary_strings(n: int) -> list:
"""Generate all possible binary strings of length n.
Args:
n (int): The length of the binary strings to generate.
Returns:
list: A list containing all possible binary strings of length n.
>>> generate_binary_strings(1)
["0", "1"]
... | 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": "Write a function to generate all possible binary strings of length n. The function should return a list of all possible combinations.",
"prompt_id": "00011349",
"row_id": 11349,
"seed_ids": "['magpie_prefill_11349']"
} | 0.639115 | Prefill_11349 | C | [
"generate_binary_strings",
"generate_strings_helper"
] | 2 | [
[
"generate_binary_strings",
"generate_strings_helper"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3bc2082c16387e6bcf654c0f3c95bdcd1f44fe6 | b7e3381367d6dba61ec8f72b0c92893cb581b8d6 | |||
v1.0 | complete | Prefill | Prefill_11212_C | def merge_sort(arr):
"""
Sorts an array of integers in ascending order using the mergesort algorithm, which has a time complexity of O(N log N).
>>> merge_sort([]) == []
>>> merge_sort([5]) == [5]
>>> merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
>>> merge_sort([5, 4, 3, 2, 1]) == [1, 2, ... | 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": "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? Ex... | 0.621846 | Prefill_11212 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d209e5e7e0e2c559541fab3178bc30dc91314bad | c7fa94fb0713d852583a551c14ff3984073a2cc2 | |||
v1.0 | complete | Prefill | Prefill_12058_C | import math
def is_prime(num: int) -> bool:
""" 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... | 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": "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), ret... | 0.801878 | Prefill_12058 | C | [
"is_prime",
"closest_prime"
] | 2 | [
[
"closest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b56491c3b94fa2b0cff18b2d540d499dd4a8a397 | 68eb36691e73708ba4183bc4c1ae66fa71f1e558 | |||
v1.0 | complete | Prefill | Prefill_10939_C | 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... | 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": "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.",
"prompt_id": "00010939",
"row_id": 10939,
"seed_ids": "['magpi... | 0.557987 | Prefill_10939 | C | [
"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 | 7a153e7c3c8cc3222c9fcf8eee96c2901ac7cf7b | 3dd05967e2475cb56426c7f23145795f3233d657 | |||
v1.0 | complete | Prefill | Prefill_10162_C | from typing import List
def quicksort(arr: List[int], low: int, high: int):
"""
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 end... | 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": "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.",
"prompt_id": "00010162",
"row_id":... | 0.691669 | Prefill_10162 | C | [
"quicksort",
"sort_array"
] | 2 | [
[
"sort_array",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d470a5cc2443e5e5836082f381f18f4b07fdb20 | bc5af14c8211671cc8b4bb78f30bd8f5e47b7700 | |||
v1.0 | complete | Prefill | Prefill_11907_C | from math import comb
def max_points_on_circle_polygon(n: int) -> int:
"""
Returns the maximum number of points formed by intersections of diagonals
of a convex polygon with n vertices on the circumference of a circle.
>>> max_points_on_circle_polygon(4)
1
>>> max_points_on_circle_polygon(6)
... | 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": "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 th... | 0.567171 | Prefill_11907 | C | [
"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 | 95992eae6fcbfca506d016708cf0e93295e99eec | 1b3bdec7ae6cf39b84bee113d112d841fc6e4112 | |||
v1.0 | complete | Prefill | Prefill_10789_C | 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):
""" Helper function to check if two subtrees are mirror images of each other. """
pass
def is_symmetric(root):
""" Ch... | 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": "Write a function to check if a binary tree is a mirror of itself (i.e., a palindrome).",
"prompt_id": "00010789",
"row_id": 10789,
"seed_ids": "['magpie_prefill_10789']"
} | 0.63291 | Prefill_10789 | C | [
"is_mirror",
"is_symmetric"
] | 2 | [
[
"is_symmetric",
"is_mirror"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 72685e0c8b05eb098d4b115f3899423a532fff0c | 437a4269a81ac5b8ae89d350ef656098d61e9a0b | |||
v1.0 | complete | Prefill | Prefill_11106_C | 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.
>>> knight_moves(0, 0)
{(2, 1), (1, 2)}
>>> knight_moves(4, 4)
{(2, 3), (2, 5), (3, 2), (3, 6), (5, 2), (5, 6), (6, 3), (6, 5)}
>>> knight_m... | 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": "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 tw... | 0.649432 | Prefill_11106 | C | [
"knight_moves",
"distinct_knight_reachable_nodes"
] | 2 | [
[
"distinct_knight_reachable_nodes",
"knight_moves"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3c043a8b1481826b15224c3266fc645f0bab0d6 | 88f24ac74feb40e71820bf1c5418eccae42891a1 | |||
v1.0 | complete | Prefill | Prefill_11493_C | from math import factorial
from typing import List
def stirling_second_kind(n: int, k: int) -> int:
""" Returns the number of ways to distribute `n` distinct items into `k` distinct bins such that no bin is empty.
"""
pass
def distribute_items(n: int, k: int) -> int:
""" Calculates the number of ways ... | 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": "Write a function to calculate the number of ways to distribute `n` distinct items into `k` distinct bins such that no bin is empty.",
"prompt_id": "00011493",
"row_id": 11493,
"seed_ids": "['magpie_prefill_11493']"
} | 0.530083 | Prefill_11493 | C | [
"stirling_second_kind",
"distribute_items"
] | 2 | [
[
"distribute_items",
"stirling_second_kind"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dcc1399eaedf3757804680187dc21897b2b2586c | 215c3fc7de5cf134d96b2f7073a716455548c237 | |||
v1.0 | complete | Prefill | Prefill_11607_C | def subsets_as_lists(numbers) -> List[List[int]]:
"""
Generate subsets as lists of a set of numbers, including the empty set.
>>> subsets_as_lists([]) == [[]]
>>> subsets_as_lists([1]) == [[], [1]]
>>> subsets_as_lists([1, 2]) == [[], [1], [2], [1, 2]]
>>> subsets_as_lists([1, 2, 3]) == [[], [1... | 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": "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]].",
"prompt_id": "00011607",
"row_id": 11607,
"seed_ids": "['mag... | 0.63657 | Prefill_11607 | C | [
"generate_subsets",
"subsets_as_lists"
] | 2 | [
[
"subsets_as_lists",
"generate_subsets"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eda005efaefa6df3d2e3c2202a028ed3f77caac5 | 3ef2798f275d90e856597fec0314889cb040a09c | |||
v1.0 | complete | Prefill | Prefill_11960_C | import math
from functools import reduce
from typing import List
def lcm(a: int, b: int) -> int:
""" Returns the Least Common Multiple of two numbers a and b.
>>> lcm(4, 6) 12
>>> lcm(7, 5) 35
>>> lcm(0, 1) 0
>>> lcm(-4, 6) 12
"""
def lcm_of_list(numbers: List[int]) -> int:
""" Returns... | 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": "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.",
"prompt_id": "00011960",
"row_id": 11960,
"seed_ids": "['magpie_prefill_11960']"
} | 0.673719 | Prefill_11960 | C | [
"lcm",
"lcm_of_list"
] | 2 | [
[
"lcm_of_list",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fd672f2f7890f685421eb15ee0aeee2a3a4566d | 1813eab844d03f10c0b3f1bb8bcb6c2d7842b136 | |||
v1.0 | complete | Prefill | Prefill_12169_C | def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two positive integers using the Euclidean algorithm.
Limit: The inputs should be less than or equal to 1000.
>>> gcd(54, 24) 6
>>> gcd(48, 18) 6
>>> gcd(101, 103) 1
>>> gcd(1000, 1000) 1000
"""
...
de... | 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": "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.",
"prompt_id": ... | 0.818417 | Prefill_12169 | C | [
"gcd",
"lcm"
] | 2 | [
[
"lcm",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58d43745c32eb21a9a54db7ef7a7f5146c8e3c10 | 6a77d8a9f09695662d4dc36f79321f515a164ba7 | |||
v1.0 | complete | Prefill | Prefill_10964_C | def insert_at_bottom(stack, item):
""" Insert an item at the bottom of a stack using recursion without using an additional stack.
>>> stack = []
>>> insert_at_bottom(stack, 1)
>>> stack
[1]
>>> stack = [2, 3]
>>> insert_at_bottom(stack, 1)
>>> stack
[1, 2, 3]
"""
def reverse_sta... | 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": "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.",
"prompt_id": "00010964",
"row_id": 10964,
"seed_ids": "['magpie_prefill_10964']"
} | 0.519637 | Prefill_10964 | C | [
"insert_at_bottom",
"reverse_stack"
] | 2 | [
[
"reverse_stack",
"insert_at_bottom"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ec09b2da1672497a2eb68872b8dd62a99151f4ef | 89d759df5e3627562e8da7feafe6282865bb7e6d | |||
v1.0 | complete | Prefill | Prefill_11366_C | def max_subarray_kadane(arr):
"""
Finds the maximum sum of a subarray using Kadane's Algorithm.
>>> max_subarray_kadane([1, 2, 3, 4, 5]) == 15
>>> max_subarray_kadane([-2, -3, 4, -1, -2, 1, 5, -3]) == 7
>>> max_subarray_kadane([-1, -2, -3, -4]) == -1
>>> max_subarray_kadane([0, 0, 0, 0]) == 0
... | 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": "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.",
"prompt_id": "00011366",
"row_id": 11366,
"seed_ids": "['magpie_prefill_11366']"
} | 0.733489 | Prefill_11366 | C | [
"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 | d6a655477ccc60b4c816dcbc14dd22aa140b5994 | b4320f8c4ac7a568b87cc4cbfa6f825ee8badb52 | |||
v1.0 | complete | Prefill | Prefill_11542_C | def fibonacci(n: int) -> List[int]:
"""
Returns the Fibonacci sequence up to the given number 'n'.
>>> fibonacci(0) []
>>> fibonacci(1) [0]
>>> fibonacci(2) [0, 1]
>>> fibonacci(5) [0, 1, 1, 2, 3]
>>> fibonacci(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
"""
def check_fibonacci(n: int, expec... | 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": "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 a... | 0.789877 | Prefill_11542 | C | [
"fibonacci",
"check_fibonacci"
] | 2 | [
[
"check_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 40d691d3b3f2202a21b379fd5fc660ca40deaf0b | a87adabf2b1ef5367a237195ecdc86e3eb1cb5c7 | |||
v1.0 | complete | Prefill | Prefill_12929_C | def counting_sort_for_radix(arr, exp):
"""
A helper function to perform counting sort on arr[] according to the digit represented by exp (10^i)
"""
pass # Implement the function here
def radix_sort(arr):
"""
The main function to sort an array using the radix sort algorithm
>>> arr = [170, ... | def counting_sort_for_radix(arr, exp):
"""
A helper function to perform counting sort on arr[] according to the digit represented by exp (10^i)
"""
n = len(arr)
output = [0] * n
count = [0] * 10
# Store the count of occurrences in count[]
for i in range(n):
index = (arr[i] // ex... | from solution import radix_sort
def test_single_element():
arr = [1]
radix_sort(arr)
assert arr == [1]
def test_sorted_array():
arr = [1, 2, 3, 4, 5]
radix_sort(arr)
assert arr == [1, 2, 3, 4, 5]
def test_reverse_sorted_array():
arr = [5, 4, 3, 2, 1]
radix_sort(arr)
assert arr == ... | [
{
"docstring": "A helper function to perform counting sort on arr[] according to the digit represented by exp (10^i)",
"function_declaration": "def counting_sort_for_radix(arr, exp):",
"function_name": "counting_sort_for_radix",
"parameter_list": "(arr, exp)"
},
{
"docstring": "The main func... | [
0,
0,
0,
1,
0,
0,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def counting_sort(arr, exp):\n \"\"\"\n A function to perform counting sort on arr[] according to \n the digit represented by exp.\n \"\"\"\n n = len(arr)\n\n # The output a... | trial_gpt4o_8 | {
"original_instruction": "Write a function to sort an array using the radix sort algorithm in JavaScript.",
"prompt_id": "00012929",
"row_id": 12929,
"seed_ids": "['magpie_prefill_12929']"
} | 0.64139 | Prefill_12929 | C | [
"counting_sort_for_radix",
"radix_sort"
] | 2 | [
[
"radix_sort",
"counting_sort_for_radix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc4bdbab9ed943e74bc1f8990734d15873821eac | 1dd39473067d47b33a639efb7a55050cfa520d5f | |||
v1.0 | complete | Prefill | Prefill_12591_C | def is_prime(n: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(1)
False
>>> is_prime(0)
False
>>> is_prime(-3)
False
"""
def primes_up_to_n(N: int) -... | 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": "Write a function to display all the prime numbers from 1 to N. How can I implement this in Python?",
"prompt_id": "00012591",
"row_id": 12591,
"seed_ids": "['magpie_prefill_12591']"
} | 0.813084 | Prefill_12591 | C | [
"is_prime",
"primes_up_to_n"
] | 2 | [
[
"primes_up_to_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | beb9b6d2c7ddafff8dbfc45d98f411e1153eed97 | fb29e31e1a91b4d5cd23ed5f0f66426f3a1e0d33 | |||
v1.0 | complete | Prefill | Prefill_12752_C | from math import gcd
def lcm(a, b):
"""
Returns the Least Common Multiple (LCM) of two integers a and b.
"""
pass
def smallest_multiple(n):
"""
Returns the smallest positive integer that is evenly divisible by all numbers from 1 to n.
>>> smallest_multiple(1) 1
>>> smallest_multip... | 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": "Write a function to find the smallest positive integer that is evenly divisible by all numbers from 1 to n.",
"prompt_id": "00012752",
"row_id": 12752,
"seed_ids": "['magpie_prefill_12752']"
} | 0.725321 | Prefill_12752 | C | [
"lcm",
"smallest_multiple"
] | 2 | [
[
"smallest_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efc24c7eecacf1d56d14b46985f479320387b005 | eb963b74ebd3e6a47fa5dc93cded0fb291aca74f | |||
v1.0 | complete | Prefill | Prefill_12062_C | def find_kth_largest(nums: List[int], k: int) -> int:
"""
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 a... | 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": "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."... | 0.845338 | Prefill_12062 | C | [
"partition",
"quickselect",
"find_kth_largest"
] | 3 | [
[
"find_kth_largest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e0805b03a17ffa39f4f898b7b21d561756e30be6 | 863d167ec619ba9e044c7a89fd3ad8df3f4bb500 | |||
v1.0 | complete | Prefill | Prefill_12876_C | from typing import List
def is_prime(num: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
def sum_of_primes(n: int) -> int:
""" Retur... | 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": "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.",
"prompt_id": "00012876",
"row_id": 12876,
"seed_ids": "['mag... | 0.776784 | Prefill_12876 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e4de014bfcf8c10d2304bd1b1a383a957283ffa | 150bbba8eadc64e2929618a0b4b46d79d6c7b017 | |||
v1.0 | complete | Prefill | Prefill_12621_C | 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 the list is emp... | 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": "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.",... | 0.709448 | Prefill_12621 | C | [
"compare",
"max_concatenated_value"
] | 2 | [
[
"max_concatenated_value",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7279791189c8dd959f42abfe3803999084fe2b6d | 0bb87873e07d3acc0644df9e1c808b3a1e6b6f2b | |||
v1.0 | complete | Prefill | Prefill_12038_C | def manhattan_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> int:
"""
Calculate the Manhattan distance between two points.
>>> manhattan_distance((1, 2), (4, 6))
7
>>> manhattan_distance((0, 0), (0, 0))
0
>>> manhattan_distance((-1, -1), (-4, -5))
7
>>> manhattan... | 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": "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 a... | 0.678418 | Prefill_12038 | C | [
"manhattan_distance",
"min_distance_between_sets"
] | 2 | [
[
"min_distance_between_sets",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9d29c12f7a2fe4dedcfd1224608e5f402f9a7d51 | 253e6e5160745f0f0911d6ac2c623f01a1d4ad2f | |||
v1.0 | complete | Prefill | Prefill_13301_C | from typing import List
def find_max(arr: List[int]) -> int:
""" Find the maximum element in an array using a divide and conquer approach.
>>> find_max([3])
3
>>> find_max([1, 2, 3, 4, 5])
5
>>> find_max([-5, -4, -3, -2, -1])
-1
>>> find_max([-10, 5, -2, 3, 9])
9
>>> find_max([... | 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": "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.",
"prompt_id": "00013301",
"row_id": 13301,
"seed_ids": "['magpie_prefill_13301']"
} | 0.819773 | Prefill_13301 | C | [
"find_max",
"find_max_recursive"
] | 2 | [
[
"find_max",
"find_max_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1cd6469c918413d8fb6879dfcfb77108a7762ee5 | af0a7040a47eb9ce932d658bf695e86b3a586664 | |||
v1.0 | complete | Prefill | Prefill_12813_C | def insert_at_bottom(stack, item):
"""
Helper function to insert an item at the bottom of a stack.
"""
if len(stack) == 0:
stack.append(item)
else:
top = stack.pop()
insert_at_bottom(stack, item)
stack.append(top)
def reverse_stack(stack):
"""
Function to rev... | def insert_at_bottom(stack, item):
"""
Helper function to insert an item at the bottom of a stack.
"""
if len(stack) == 0:
stack.append(item)
else:
top = stack.pop()
insert_at_bottom(stack, item)
stack.append(top)
def reverse_stack(stack):
"""
Function to rev... | from solution import reverse_stack
def test_reverse_stack():
stack = [1, 2, 3, 4, 5]
reverse_stack(stack)
assert stack == [5, 4, 3, 2, 1]
def test_reverse_stack_single_element():
stack = [1]
reverse_stack(stack)
assert stack == [1]
def test_reverse_stack_empty():
stack = []
reverse_st... | [
{
"docstring": "Helper function to insert an item at the bottom of a stack.",
"function_declaration": "def insert_at_bottom(stack, item):",
"function_name": "insert_at_bottom",
"parameter_list": "(stack, item)"
},
{
"docstring": "Function to reverse a stack using recursion.",
"function_d... | [
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.889 | {
"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_7 | {
"original_instruction": "Write a function to reverse a stack using recursion in C++.",
"prompt_id": "00012813",
"row_id": 12813,
"seed_ids": "['magpie_prefill_12813']"
} | 0.49421 | Prefill_12813 | C | [
"insert_at_bottom",
"reverse_stack"
] | 2 | [
[
"reverse_stack",
"insert_at_bottom"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ec1ac32c10be4ea24c268acc6fe89e4de871eb55 | 0a90f3415a1ce972598861b603b25f7f54339439 | |||
v1.0 | complete | Prefill | Prefill_13010_C | def is_palindrome(s: str) -> bool:
"""Check if a given string is a palindrome."""
pass
def find_palindrome(strings: List[str]) -> str:
""" 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": "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.",
"prompt_id": "00013010",
"row_id": 13010,
"seed_ids": "['magpie_prefill_13010']"
} | 0.88134 | Prefill_13010 | C | [
"is_palindrome",
"find_palindrome"
] | 2 | [
[
"find_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45b31508f6737b0efd153bf7ddd8fd3570b236e4 | b1d5b8feaf9ab178a5bb342f8f3f1c54a2603f63 | |||
v1.0 | complete | Prefill | Prefill_13066_C | def quicksort(arr, low=0, high=None):
"""
Sort an array of integer 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.
... | 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": "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... | 0.707403 | Prefill_13066 | C | [
"quicksort",
"partition"
] | 2 | [
[
"quicksort",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5c0afda9e6068ceebcbbdf2c7f9ac97feed7245d | 6d14b7d7db3bbb2ad382fe62986236ff7b7f0552 | |||
v1.0 | complete | Prefill | Prefill_11738_C | 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.
"""
pass
def inorder_successor(root, node):
"""
Finds the in-order successor ... | 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": "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`.",
"prompt_id": "00011738",
"row_id": 11738,
... | 0.528634 | Prefill_11738 | C | [
"find_min",
"inorder_successor"
] | 2 | [
[
"inorder_successor",
"find_min"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e5c2f00642c66c84b0a420bfab63dddc4d7b61a0 | f280eec2e111130e4b53cb2880867267d2d313b7 | |||
v1.0 | complete | Prefill | Prefill_12329_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def sortList(head: ListNode) -> ListNode:
"""Sort a linked list in O(n log n) time complexity.
The function takes the head of a linked list as input and returns 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": "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.",
"prompt_id": "00012329",
"row_id": 12329,
"seed_ids": "['magpie... | 0.512403 | Prefill_12329 | C | [
"sortList",
"merge"
] | 2 | [
[
"sortList",
"merge"
]
] | 1 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 540d012910c947276e71cfbbf2d0276cc7dbf624 | 0ec6078034ca53a9c4620c2baa1552d6e7d23e1f | |||
v1.0 | complete | Prefill | Prefill_12938_C | from typing import List
def min_partition_cost(arr: List[int]) -> int:
""" 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 d... | 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": "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.",
"prompt_id": "0001293... | 0.687965 | Prefill_12938 | C | [
"is_power_of_two",
"min_partition_cost"
] | 2 | [
[
"min_partition_cost",
"is_power_of_two"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c79c9a751571877d8b27d6197c868ca6f668563c | 003bfc45e6f42adedfcdfe355d4377e8339b3bdb | |||
v1.0 | complete | Prefill | Prefill_13840_C | def next_prime(n: int) -> int:
""" Returns the next prime number greater than the input integer.
>>> next_prime(10)
11
>>> next_prime(11)
13
>>> next_prime(14)
17
>>> next_prime(17)
19
>>> next_prime(19)
23
>>> next_prime(23)
29
>>> next_prime(1)
2
>>> nex... | 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": "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 ... | 0.789868 | Prefill_13840 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17bac5dd997c20458d06f95f51cad2769c6d9abe | a41601c7488a176942d0332ca8ec81b0d019a56c | |||
v1.0 | complete | Prefill | Prefill_13221_C | import random
def card_value(card):
""" Return the value of a card according to Blackjack rules.
# Examples:
>>> card_value('2') == 2
>>> card_value('10') == 10
>>> card_value('J') == 10
>>> card_value('Q') == 10
>>> card_value('K') == 10
>>> card_value('A') == 11
"""
pass
def ... | 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": "Write a function to simulate a basic Blackjack game. How should the function be designed, and what rules should it include?",
"prompt_id": "00013221",
"row_id": 13221,
"seed_ids": "['magpie_prefill_13221']"
} | 0.62355 | Prefill_13221 | C | [
"card_value",
"adjust_for_ace",
"blackjack"
] | 3 | [
[
"blackjack",
"adjust_for_ace"
],
[
"blackjack",
"card_value"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7f85b4dd6d1fcb2f42f78828a5f614daeecd2cfb | 9bf0be3d0aa588c4d651b71d74f81c900dd55c92 | |||
v1.0 | complete | Prefill | Prefill_12428_C | def max_2d_subarray_sum(arr: List[List[int]]) -> int:
"""
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.
Example:
>>> max_2d_subarray_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": "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.",
"prompt_id": "00012428",
"row_id": 12428,
"seed_ids": "['magpie_prefill_12428']"
} | 0.689071 | Prefill_12428 | C | [
"max_2d_subarray_sum",
"kadane"
] | 2 | [
[
"max_2d_subarray_sum",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 25c9784e592a8c4443a4a6f180abbbe4fcf8a363 | bef99136b2f9309ee41183131e2d981b90939d96 | |||
v1.0 | complete | Prefill | Prefill_13661_C | def factorial(n: int) -> int:
"""Returns the factorial of the given number n.
Raises a ValueError if n is negative.
>>> factorial(0)
1
>>> factorial(1)
1
>>> factorial(5)
120
>>> factorial(10)
3628800
>>> factorial(-1)
ValueError
"""
def check_factorial() -> None:
... | 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": "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.",
"prompt_id": "00013661",
"row_id":... | 0.704553 | Prefill_13661 | C | [
"factorial",
"check_factorial"
] | 2 | [
[
"check_factorial",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2966ff9cc918318fef92b816e453be355eef228b | db932e374b0ce461ef2ff8c4565dd980452921df | |||
v1.0 | complete | Prefill | Prefill_13733_C | def is_prime(n):
""" Helper function to check if a number n is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def primes_less_than_100():
""" Returns a list of all prime numbers less than 100 using list comprehension.
>>> primes_less_than_100()
[2, 3, 5, 7, 11, 1... | 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": "Create a function that uses list comprehension to return a list of all prime numbers less than 100.",
"prompt_id": "00013733",
"row_id": 13733,
"seed_ids": "['magpie_prefill_13733']"
} | 0.846595 | Prefill_13733 | C | [
"is_prime",
"primes_less_than_100"
] | 2 | [
[
"primes_less_than_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ff6574d0ef18c74f43413a14be26e38876bb9f1a | 2ffea28969fd0731c1bc5bdc0b4737345a80a031 | |||
v1.0 | complete | Prefill | Prefill_9823_C | 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
"""
pass
def find_empty(board):
"""
Finds an empty cell in the ... | 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": "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 ... | 0.513694 | Prefill_9823 | C | [
"solve_sudoku",
"find_empty",
"is_valid"
] | 3 | [
[
"solve_sudoku",
"find_empty"
],
[
"solve_sudoku",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f10086488760eb5e089911591a2dbb1b9490d133 | 3d0525db1ebd65a19a450775b0a0063b3339307a | |||
v1.0 | complete | Prefill | Prefill_12978_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
"""Insert a node with the given key into the BST rooted at root."""
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.r... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.right = insert(root.right, key)
else:
root.left = ins... | from solution import TreeNode, construct_bst_from_array, inorder_traversal
def test_construct_bst_single_element():
arr = [10]
root = construct_bst_from_array(arr)
assert inorder_traversal(root) == [10]
def test_construct_bst_sorted_order():
arr = [1, 2, 3, 4, 5]
root = construct_bst_from_array(ar... | [] | [
0,
1,
0,
1,
1,
1,
1,
0,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "cpp\n#include <iostream>\n#include <vector>\n\nclass TreeNode {\npublic:\n int val;\n TreeNode* left;\n TreeNode* right;\n\n TreeNode(int value) : val(value), left(nullptr), right... | trial_gpt4o_9 | {
"original_instruction": "Write a function to represent a Binary Search Tree (BST) in C++. The function should accept an input array of integers and construct a BST from it. The function should return the root of the constructed BST.",
"prompt_id": "00012978",
"row_id": 12978,
"seed_ids": "['magpie_prefill_129... | 0.537678 | Prefill_12978 | C | [
"insert",
"construct_bst_from_array",
"inorder_traversal"
] | 3 | [
[
"construct_bst_from_array",
"insert"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 996c1d8963821f652b222d4cf74184606a1b6900 | a1ece22439a941e27b65857aa8ba1a1fda2793f4 | |||
v1.0 | complete | Prefill | Prefill_13156_C | def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(-1)
False
>>> is_prime(0)
False
>>> is_prime(1)
False
>>> is_prime(25)
False
>>> i... | 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": "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.",
"prompt_id": "00013156",
"row_id": 13156,
"seed_ids": "['magpie_prefill_13156']"
} | 0.827974 | Prefill_13156 | C | [
"is_prime",
"primes_less_than"
] | 2 | [
[
"primes_less_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7b84bc7c9ee98095c76af1afd0ffc7ac50337fc8 | 98f662bd3f8cdc330dbc75088db4935151aa431c | |||
v1.0 | complete | Prefill | Prefill_13950_C | 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: int) -> int:
"""
Create a function that receives an integer n as input and returns the least common multiple (LCM) of all numbers from 1 to n.
>>> lcm_range(1... | 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": "Create a function that receives an integer `n` as input and returns the least common multiple (LCM) of all numbers from 1 to `n`.",
"prompt_id": "00013950",
"row_id": 13950,
"seed_ids": "['magpie_prefill_13950']"
} | 0.724191 | Prefill_13950 | C | [
"lcm",
"lcm_range"
] | 2 | [
[
"lcm_range",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3c04b616cd5936083471c84cc201250e76af962 | 6eb8f2b7f35c38a19425fb9884d6a2982df7b179 | |||
v1.0 | complete | Prefill | Prefill_13965_C | from typing import List
def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def filter_primes(numbers: List[int]) -> List[int]:
""" Filters out prime numbers from a list and returns a new list containing only compo... | 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": "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?",
"prompt_id": "00013965",
"row_id": 13965,
"seed_ids": "['magpie_prefill... | 0.760255 | Prefill_13965 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c34fbb3cbe3846fc676cc790f011fea4c50b99d5 | 971ed7a3246b1aad12cb4583e20606dfed9a6a33 | |||
v1.0 | complete | Prefill | Prefill_14131_C | 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: int, b: int) -> int:
"""
Returns the sum of all prime numb... | 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": "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 ra... | 0.746109 | Prefill_14131 | C | [
"is_prime",
"sum_primes_between"
] | 2 | [
[
"sum_primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 805e13a4db1117c9c08c6628bfbc0c87cce786b2 | 21e02b8ef565d6226ac8c7bf8f3650b666d6c24b | |||
v1.0 | complete | Prefill | Prefill_13969_C | 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... | 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": "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`.",
"prompt_id": "00013969",
"row_id": 13969,
"s... | 0.740623 | Prefill_13969 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e28b16a847df6a6d12aab86024f8acac1b714713 | 9f0ffc98a97878457195b04ca906ce30d8453cfd | |||
v1.0 | complete | Prefill | Prefill_14492_C | def prime_factorial(n: int) -> int:
""" Returns the factorial of a number if it is prime, otherwise
returns 'Input is not a prime number'.
>>> prime_factorial(2) 2
>>> prime_factorial(3) 6
>>> prime_factorial(4) '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": "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\".",
"prompt_id": "00014492",
"row_id": 14492,
"seed_ids": "['magpie_prefill_14492']"
} | 0.77145 | Prefill_14492 | C | [
"is_prime",
"factorial",
"prime_factorial"
] | 3 | [
[
"prime_factorial",
"factorial"
],
[
"prime_factorial",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7232d719c3574c8ac0e627cda169d437e65f26ad | c3433017593bf3cadd3ccebfd0a309b68794508f | |||
v1.0 | complete | Prefill | Prefill_13059_C | 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.
"""
pass
def inorder_traversals(t1, t2, t3)... | 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": "Write a function to traverse three binary trees (t1, t2, and t3) and return their inorder traversal results.",
"prompt_id": "00013059",
"row_id": 13059,
"seed_ids": "['magpie_prefill_13059']"
} | 0.525462 | Prefill_13059 | C | [
"inorder_traversal",
"inorder_traversals"
] | 2 | [
[
"inorder_traversals",
"inorder_traversal"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 80e8fd0e7ce9ebcae9e10ad43c4252a00d3e190a | db1d0877aa6516f4e2616d29bd5c6dbddc5c19de | |||
v1.0 | complete | Prefill | Prefill_14214_C | def count_primes(arr):
""" 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.
>>> count_primes([-10, -5, 0, 1, 4, 6, 8, 9, 10]) == 0
>>> count_primes([2, ... | 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": "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.",
"prompt_id": "00014214",
"row_id": 14214,
"seed_ids": "['magpie_prefill_14214']"
} | 0.804558 | Prefill_14214 | C | [
"is_prime",
"count_primes"
] | 2 | [
[
"count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3d579233e629706c4f465aa232b0f76fe80cb07 | eef55d4496592da6243cd4a8ec0ca2d795726494 | |||
v1.0 | complete | Prefill | Prefill_14004_C | import math
from typing import List
def is_prime(n: int) -> bool:
"""
Check if the given number n is a prime number.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(17) == True
>>> is_prime(18) == False
>>> is_prime(29) == True
"""
pass
def... | 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": "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.",
"prompt_id": "00014004",
"row_id": 14004,
"seed_ids": "['magpie_prefill_... | 0.834346 | Prefill_14004 | C | [
"is_prime",
"smallest_prime_greater_than"
] | 2 | [
[
"smallest_prime_greater_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0670fc0ba3e3890835241359409b216315696e3b | 716fcfa9dc9c4e6d6246739a73ed1383bc5fee8e | |||
v1.0 | complete | Prefill | Prefill_14473_C | 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):
"""
... | 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": "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.",
"prompt_id": "00014473",
"row_id": 14473,
"seed_ids": "['magpie_pref... | 0.807866 | Prefill_14473 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b938ae73e51548b0c09ade1d841337114f83addb | f22d77d90e4e33b23b65a9fea088cb52e51547db | |||
v1.0 | complete | Prefill | Prefill_14258_C | def is_palindrome(n: int) -> bool:
"""
Checks if an integer n is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1221)
True
>>> is_palindrome(1)
True
>>> is_palindrome(-121)
False
"""
def palindrome_lengths(lst: List[int... | 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": "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.",
"prompt_id": "00014258",
"row_id": 14258,
"seed_ids": "['magpie_prefill_14258']"
} | 0.750062 | Prefill_14258 | C | [
"is_palindrome",
"palindrome_lengths"
] | 2 | [
[
"palindrome_lengths",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dee2c4c527cfb1a12c3a5a68781e43c3c077e61 | cc85ed4f6f6f9ed8a34a75753632dbd74a421890 | |||
v1.0 | complete | Prefill | Prefill_14038_C | def factorial(n: int) -> int:
"""Returns the factorial of a given number n using recursion.
>>> factorial(0)
1
>>> factorial(5)
120
"""
# Implement the function here
def list_factorials(lst: List[int]) -> List[int]:
"""Takes a list of integers and returns a list where each element
... | 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": "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 elem... | 0.733322 | Prefill_14038 | C | [
"factorial",
"list_factorials"
] | 2 | [
[
"list_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11df689b1ac5b2f67df203e16824f2842f7c25ac | da32021b5efcfb466d58bf5adb02249a8fed3674 | |||
v1.0 | complete | Prefill | Prefill_14544_C | def sum_of_primes(nums: List[int]) -> int:
"""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. If there are no prime numbers in the list, the func... | 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": "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 ... | 0.745131 | Prefill_14544 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3cc4a23abb9918a19b6651ab3c3eb40f91f1fbdb | 5fc8180aa9da070f318cd5b0e50f68fcb41df32e | |||
v1.0 | complete | Prefill | Prefill_12821_C | def days_in_month(year: int, month: int) -> int:
"""
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 n... | 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": "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.",
"prompt_id": "00012821",
"row_id": 12821,
"... | 0.602509 | Prefill_12821 | C | [
"days_in_month",
"is_leap_year"
] | 2 | [
[
"days_in_month",
"is_leap_year"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3a718c43c1fbc46ac82bcc5cc29cc909b72553fe | ca1c0ffb9130bcebec18f0d453882109110fb62d | |||
v1.0 | complete | Prefill | Prefill_14587_C | def hcf_factors(a: int, b: int) -> Tuple[int, List[int]]:
"""
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... | 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": "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 ... | 0.70979 | Prefill_14587 | C | [
"prime_factors",
"hcf_factors"
] | 2 | [
[
"hcf_factors",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d6e5dfaa28bc48db35e9ed68da1a770085467f3 | c84c5133323c31fe679c7be02e2b339307c8ca2a | |||
v1.0 | complete | Prefill | Prefill_14985_C | def is_prime(n: int) -> bool:
"""
Determines if a given number n is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(29)
True
"""
def find_primes(arr: List[int]) -> List[int]:
"""
Returns a list of all prime numbers in the given list arr.
>>> find_prime... | 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": "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.",
"prompt_id": "00014985",
"row_id": 14985,
"seed_ids": "['magpie_prefill_14985']"
} | 0.81921 | Prefill_14985 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76697256379df0f4873dc6b3c059467ddd18fb5d | 82c337b988bbf95aabbe20a316b2411fed3b9289 | |||
v1.0 | complete | Prefill | Prefill_14200_C | 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... | 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": "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.",
"prompt_id": "00014200",
"row_id": 14200,
"seed_ids": "['magpie_prefill_14200']"
} | 0.824084 | Prefill_14200 | C | [
"fibonacci",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b546c9f8c71339703f9c7d8430bc77f953f8cd9e | c840078c17f0cce8abbe36f332dd40f4c2335642 | |||
v1.0 | complete | Prefill | Prefill_15067_C | 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.
"""
def generate_fibonacci_sequence(n):
"... | 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": "Create a function that generates a Fibonacci sequence with memoization to improve performance.",
"prompt_id": "00015067",
"row_id": 15067,
"seed_ids": "['magpie_prefill_15067']"
} | 0.783066 | Prefill_15067 | C | [
"fibonacci",
"generate_fibonacci_sequence"
] | 2 | [
[
"generate_fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fbf2611697101d213fb31db54aa0fe62fa05ff32 | 0cd8e5f02bc6855e52952b1b6e1df942dc712586 | |||
v1.0 | complete | Prefill | Prefill_14403_C | def is_prime(n: int) -> bool:
"""
Check if a number is prime.
"""
pass
def filter_primes(numbers: List[int]) -> List[int]:
"""
Given a list of integers, return a new list with all the prime numbers from the original list.
>>> filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
[2, 3, 5, 7... | 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": "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.",
"prompt_id": "00014403",
"row_id": 14403,
"seed_ids": "['magp... | 0.795595 | Prefill_14403 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f2cce5e012d45b27400edc2dca7f49533af3c64f | c025c98a15eabdea7f647afe0b27fb487d64a243 | |||
v1.0 | complete | Prefill | Prefill_14599_C | def is_prime(num: int) -> bool:
"""
Helper function to determine if a number is prime.
Returns True if num is prime, False otherwise.
"""
# Your code here
def insert_special(arr: List[int], n: int) -> List[int]:
"""
Inserts the integer n at the beginning of the list arr.
If n is a prime... | 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": "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` ... | 0.699279 | Prefill_14599 | C | [
"is_prime",
"insert_special"
] | 2 | [
[
"insert_special",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ada0a2d62156d034647a8b086198b438a67a0bc | e7ac458ccbdd3cc6a974893965d95fecac310c4b | |||
v1.0 | complete | Prefill | Prefill_14891_C | import math
def is_sum_of_two_squares(n: int) -> bool:
""" Returns True if the integer n can be expressed as the sum of two squares.
>>> is_sum_of_two_squares(0) == True
>>> is_sum_of_two_squares(1) == True
>>> is_sum_of_two_squares(2) == True
>>> is_sum_of_two_squares(3) == False
>>> is_sum_of... | 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": "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.",
"promp... | 0.739444 | Prefill_14891 | C | [
"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 | 2012d96a23ba7e92a136ccbadbe2d355915cbf26 | f4e6186bbc61c7af5a2e0ba194d582a630af7139 | |||
v1.0 | complete | Prefill | Prefill_15501_C | def is_prime(num: int) -> bool:
""" Returns True if num is a prime number, otherwise False.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(17) True
>>> is_prime(18) False
"""
pass
def sum_of_primes(n: int) -> int:
""" Returns the sum of all prime number... | 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": "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?",
"prompt_id": "00015501",
"row_id": 15501,
"seed_ids": "['magpie_prefill_15501']"
} | 0.795891 | Prefill_15501 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | faaca64e2210a8419ffcc0814dcd14a4d993b1e5 | 7dc70358551c0b7e76ab67c2603adc92b863719d | |||
v1.0 | complete | Prefill | Prefill_15515_C | def rotate_strings(input_list: List[str]) -> List[List[str]]:
""" Create a function that takes a list of strings as input and returns a list of lists,
where each sublist contains strings that can be formed by rotating the strings in the input list
by a certain number of positions to the right.
>>> r... | def rotate_string(s, n):
"""
Rotates a string s to the right by n positions.
"""
return s[-n:] + s[:-n]
def rotate_strings(input_list):
"""
Returns a list of lists, where each sublist contains rotated versions of the strings from the input list.
"""
result = []
if not input_list:
... | from solution import rotate_strings
def test_rotate_strings_single_element():
assert rotate_strings(["abc"]) == [["abc", "cab", "bca"]]
def test_rotate_strings_multiple_elements():
assert rotate_strings(["abc", "def", "ghi"]) == [
["abc", "cab", "bca"],
["def", "fde", "efd"],
["ghi", "... | [
{
"docstring": "Rotates a string s to the right by n positions.",
"function_declaration": "def rotate_string(s, n):",
"function_name": "rotate_string",
"parameter_list": "(s, n)"
},
{
"docstring": "Returns a list of lists, where each sublist contains rotated versions of the strings from the ... | [
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": "def rotate_string(s, n):\n \"\"\"\n Returns a new string that is the result of rotating the input string s by n positions to the right.\n \"\"\"\n n = n % len(s)\n return s[-n:... | trial_gpt4o_7 | {
"original_instruction": "Create a function that takes a list of strings as input and returns a list of lists, where each sublist contains strings that can be formed by rotating the strings in the input list by a certain number of positions to the right. For example, if the input list is [\"abc\", \"def\", \"ghi\"],... | 0.65124 | Prefill_15515 | C | [
"rotate_string",
"rotate_strings"
] | 2 | [
[
"rotate_strings",
"rotate_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e34ba3349f46d329590d679d7857a37a794ee453 | 3ea1a99cf156a754770c0fe3daeef978b4e99747 | |||
v1.0 | complete | Prefill | Prefill_15292_C | def is_prime(n: int) -> bool:
"""
Check if a number is a prime number.
>>> is_prime(2) # True
>>> is_prime(4) # False
"""
def sum_of_primes(start: int, end: int) -> int:
"""
Calculate the sum of all prime numbers between two given positive integers, start and end inclusive.
>>... | 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": "Create a function that calculates the sum of all prime numbers between two given positive integers, `start` and `end`.",
"prompt_id": "00015292",
"row_id": 15292,
"seed_ids": "['magpie_prefill_15292']"
} | 0.692634 | Prefill_15292 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8792f31ac1936c752cc4eb3a049afbb15c5805c1 | 3f99c48fa187cc2d8bd196c6cd7e33f48eea0559 | |||
v1.0 | complete | Prefill | Prefill_15770_C | def is_palindrome(s: str) -> bool:
"""
Check if a given string is a palindrome.
>>> is_palindrome("madam") True
>>> is_palindrome("racecar") True
>>> is_palindrome("hello") False
>>> is_palindrome("") True
"""
pass
def split_into_two_palindromes(s: str) -> str:
"""
This function... | def is_palindrome(s):
"""
Check if a given string is a palindrome.
"""
return s == s[::-1]
def split_into_two_palindromes(s):
"""
This function checks if a string can be split into two palindromes using a minimum of one cut.
If possible, it returns the string concatenated with itself. Other... | from solution import is_palindrome, split_into_two_palindromes
def test_is_palindrome():
assert is_palindrome("madam") == True
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
assert is_palindrome("") == True # An empty string is technically a palindrome
def test_split_i... | [
{
"docstring": "Check if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "This function checks if a string can be split into two palindromes using a minimum of one cut.\nIf possible... | [
0,
0,
0,
0,
1,
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 split_palindromes(s):\n \"\"\"\n This function checks if the string `s` can be split into two palindromes using a minimum of one cut.\n If yes, it returns the concatenation of th... | trial_gpt4o_4 | {
"original_instruction": "Create a function that takes in a string and then tests if that string can be split into two palindromes using a minimum of one cut. A palindrome is a word that reads the same backward as forward. If the string can be split into two palindromes using a single cut, the string should be retur... | 0.815919 | Prefill_15770 | C | [
"is_palindrome",
"split_into_two_palindromes"
] | 2 | [
[
"split_into_two_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02b2a870988641ec792bd8eea444180b3c68dd50 | c3512cc5d74f5c3bcc529e85a284375b92275f65 | |||
v1.0 | complete | Prefill | Prefill_13016_C | def rotate_left_in_place(nums: List[int], k: int) -> None:
"""
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.
>>> arr = [1, 2, 3, 4, 5]
>>> rotate_left_in_place(a... | 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": "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.",
"prompt_id": "00013016",
"row_id": 13016,
"seed_ids": "['magpie_prefill_13016']"
} | 0.723365 | Prefill_13016 | C | [
"rotate_left_in_place",
"reverse"
] | 2 | [
[
"rotate_left_in_place",
"reverse"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 507ffa5a3fcc06d2fe2b37fb1254ffdbbe660a12 | 98cb2afa7333fbd6206199496de75682729ac365 | |||
v1.0 | complete | Prefill | Prefill_14737_C | import math
from typing import List
def is_prime(num: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(11)
True
>>> is_prime(4)
False
"""
pass
def sum_of_divisors(n: int) -> int:
""" Returns the sum of all divisors of n excluding n itself.
>>> sum_of_divisors(6)... | 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": "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`.",
"prompt_id": "00014737",
"row_id": 14737,
"seed_ids": "['magpie_prefill_14737']"
} | 0.764685 | Prefill_14737 | C | [
"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 | c872400dfa09741a6d07e5f1f6cca12eed30b478 | deccca498d898c1a80efa67319a23b96e31b3d8c | |||
v1.0 | complete | Prefill | Prefill_15817_C | def min_occurrence(input_string: str) -> dict:
"""
Returns a dictionary with characters as keys and their minimum occurrence in the string as values.
>>> min_occurrence("") {}
>>> min_occurrence("a") {'a': 1}
>>> min_occurrence("aabbcc") {'a': 2, 'b': 2, 'c': 2}
"""
def minimum_occurrence_char... | def min_occurrence(input_string):
"""
Returns a dictionary with characters as keys and their minimum occurrence in the string as values.
"""
char_count = {}
for char in input_string:
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
... | from solution import min_occurrence, minimum_occurrence_character
def test_empty_string():
assert min_occurrence("") == {}
assert minimum_occurrence_character("") == None
def test_single_character_string():
assert min_occurrence("a") == {'a': 1}
assert minimum_occurrence_character("a") == ['a']
def t... | [
{
"docstring": "Returns a dictionary with characters as keys and their minimum occurrence in the string as values.",
"function_declaration": "def min_occurrence(input_string):",
"function_name": "min_occurrence",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declar... | [
0,
1,
1,
0,
1,
1,
1,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef min_occurrence(s):\n \"\"\"\n Returns the minimum occurrence of any character in the string s.\n \"\"\"\n if not s:\n return None\n ... | trial_gpt4o_9 | {
"original_instruction": "Create a function that checks for minimum occurrence of characters in a string",
"prompt_id": "00015817",
"row_id": 15817,
"seed_ids": "['magpie_prefill_15817']"
} | 0.68199 | Prefill_15817 | C | [
"min_occurrence",
"minimum_occurrence_character"
] | 2 | [
[
"minimum_occurrence_character",
"min_occurrence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | afb749f05784c903082775b70797e5b618a91ab1 | 4b62bc280ea24ef0ee7d5cf65a17988b388259f7 | |||
v1.0 | complete | Prefill | Prefill_15760_C | def sum_primes_between(a: int, b: int) -> int:
"""
Returns the sum of all prime numbers between a and b (inclusive).
If the input integers are less than 2, the function returns 0.
>>> sum_primes_between(0, 1)
0
>>> sum_primes_between(1, 10)
17
>>> sum_primes_between(3, 1)
0
... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
limit = int(n ** 0.5) + 1
for divider in range(3, limit, 2):
if n % divider == 0:
return False
return True
def sum_primes_between(a, b):
"""
Returns th... | from solution import sum_primes_between
def test_sum_primes_between_both_less_than_2():
assert sum_primes_between(0, 1) == 0
def test_sum_primes_between_a_less_than_2_b_greater_than_2():
assert sum_primes_between(1, 10) == 17 # 2, 3, 5, 7
def test_sum_primes_between_b_less_than_2_a_greater_than_2():
asse... | [
{
"docstring": null,
"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 the input integers are less than 2, the function returns 0.",
"function_declarati... | [
0,
0,
0,
0,
0,
1,
1,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_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_6 | {
"original_instruction": "Create a function that takes two integers as input and returns the sum of all prime numbers between the two integers (inclusive). If the input integers are less than 2, the function should return 0.",
"prompt_id": "00015760",
"row_id": 15760,
"seed_ids": "['magpie_prefill_15760']"
} | 0.703065 | Prefill_15760 | C | [
"is_prime",
"sum_primes_between"
] | 2 | [
[
"sum_primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97e41c04f9d2c3e566c54ad654cf55bddaac8aec | c7be577ed970f93b32c16a830ddb0b65e8a1afc7 | |||
v1.0 | complete | Prefill | Prefill_15468_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_nearest_common_ancestor(root: TreeNode, n1: int, n2: int) -> int:
""" Create a function that takes in two integers and returns the nearest common ancestor (NCA) ... | 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": "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?",
"prompt_id": "00015468",
"row_... | 0.598448 | Prefill_15468 | C | [
"find_path",
"find_nearest_common_ancestor"
] | 2 | [
[
"find_nearest_common_ancestor",
"find_path"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d8bff9aa18f64c50670ccb76aef6a01533592866 | 5652ce853c30c605fb6e7c5c9a4fb1b535cbdc01 | |||
v1.0 | complete | Prefill | Prefill_15815_C | def min_steps_to_solve_rubiks_cube(start_state, end_state):
""" Returns the minimum number of steps required to switch from one state
to another state of a Rubik's cube.
Parameters:
- start_state: list of 54 integers representing the current state of the cube.
- end_state: list of 54 integers r... | def min_steps_to_solve_rubiks_cube(start_state, end_state):
"""
Returns the minimum number of steps required to switch from one state
to another state of a Rubik's cube.
Parameters:
- start_state: list of 54 integers representing the current state of the cube.
- end_state: list of 54 intege... | from solution import min_steps_to_solve_rubiks_cube
def test_min_steps_no_moves_needed():
start = [1] * 54
end = [1] * 54
assert min_steps_to_solve_rubiks_cube(start, end) == 0
def test_min_steps_one_move():
start = [1] * 54
end = [1] * 53 + [2]
# Since we have no actual moves, we return -1; i... | [
{
"docstring": "Returns the minimum number of steps required to switch from one state\nto another state of a Rubik's cube.\n\nParameters:\n- start_state: list of 54 integers representing the current state of the cube.\n- end_state: list of 54 integers representing the desired state of the cube.\n\nNote: This fu... | [
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef get_valid_moves(state):\n \"\"\"\n This is a placeholder function representing the generation of all possible states \n ... | trial_gpt4o_9 | {
"original_instruction": "Create a function that returns the minimum number of steps required to switch from one state to another state of a Rubik's cube. A step is defined as rotating a face of the cube. The two states are represented as 1-D arrays of length 54, where each element represents a color on the Rubik's ... | 0.505581 | Prefill_15815 | C | [
"min_steps_to_solve_rubiks_cube",
"generate_possible_moves"
] | 2 | [
[
"min_steps_to_solve_rubiks_cube",
"generate_possible_moves"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50f9adb56f329f594e5bf55a7ec9161f777a162c | 5394223e3a2bd62aec50f0779577ee9368e4f842 | |||
v1.0 | complete | Prefill | Prefill_15117_C | 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.
"""
def merge(left, right):
"""
Helper fun... | 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": "Create a function that implements the Merge Sort algorithm.",
"prompt_id": "00015117",
"row_id": 15117,
"seed_ids": "['magpie_prefill_15117']"
} | 0.656735 | Prefill_15117 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5caf42b6b61579470e1501e513875e399b0db48 | 397fc5c89624bcbe3701a2326c74d0fb7a5f90f3 | |||
v1.0 | complete | Prefill | Prefill_14512_C | 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.
"""
def merge(left, right):
"""
Merges two sorted lists... | 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": "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.",
"prompt_id": "00014512",
"row_id": 14512,
"seed_ids": "['magpie_prefill_14512']"
} | 0.613517 | Prefill_14512 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e4ca0473d525df22146c10c387a932024445cac2 | d4dbac7104fed3fa15621cc5f6c10a53aee124bc | |||
v1.0 | complete | Prefill | Prefill_16020_C | def gcd(a, b):
"""
Helper function to compute the Greatest Common Divisor (GCD) of two numbers.
"""
pass
def lcm(a, b):
"""
Returns the Least Common Multiple (LCM) of a and b.
>>> lcm(4, 5)
20
>>> lcm(7, 3)
21
>>> lcm(1, 1)
1
>>> lcm(6, 8)
24
>>> lcm(0, ... | def gcd(a, b):
"""
Helper function to compute the Greatest Common Divisor (GCD) of two numbers.
"""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""
Returns the Least Common Multiple (LCM) of a and b.
"""
if a == 0 or b == 0:
return 0
return abs(a * b) // gcd... | from solution import lcm
def test_lcm_small_numbers():
assert lcm(4, 5) == 20
assert lcm(7, 3) == 21
assert lcm(1, 1) == 1
assert lcm(6, 8) == 24
def test_lcm_with_zero():
assert lcm(0, 5) == 0
assert lcm(5, 0) == 0
def test_lcm_large_numbers():
assert lcm(123456, 789012) == 8117355456
... | [
{
"docstring": "Helper function to compute the Greatest Common Divisor (GCD) of two numbers.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the Least Common Multiple (LCM) of a and b.",
"function_declaration": "de... | [
1,
0,
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 gcd(a, b):\n \"\"\"\n Helper function to calculate the Greatest Common Divisor (GCD) of two numbers.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b... | trial_gpt4o_9 | {
"original_instruction": "Create a function that takes two positive integers, and returns their Least Common Multiple (LCM). The function should handle large integers effectively.",
"prompt_id": "00016020",
"row_id": 16020,
"seed_ids": "['magpie_prefill_16020']"
} | 0.827682 | Prefill_16020 | C | [
"gcd",
"lcm"
] | 2 | [
[
"lcm",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de7f856c1c7daeb82f1d5b88eea93dbfc3100316 | 3642d54a807686157f32cf49a04da76b8a511674 | |||
v1.0 | complete | Prefill | Prefill_16026_C | import math
def lcm(a, b):
"""Returns the least common multiple of a and b.
>>> lcm(4, 5) == 20
>>> lcm(6, 8) == 24
>>> lcm(5, 15) == 15
>>> lcm(7, 3) == 21
"""
pass
def smallest_multiple(n):
"""Returns the smallest positive number that is evenly divisible by all numbers from 1 to n.
... | import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a*b) // math.gcd(a, b)
def smallest_multiple(n):
"""
Returns the smallest positive number that is evenly divisible by all numbers from 1 to n.
"""
result = 1
for i in range(1, n+1):
... | from solution import lcm, smallest_multiple, smallest_multiple_1_to_20
def test_lcm():
assert lcm(4, 5) == 20
assert lcm(6, 8) == 24
assert lcm(5, 15) == 15
assert lcm(7, 3) == 21
def test_smallest_multiple():
assert smallest_multiple(1) == 1
assert smallest_multiple(2) == 2
assert smalles... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the smallest positive number that is evenly divisible by all numbers from 1 to n.",
"function_declaratio... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return abs(a * b) // math.gcd(a, b)\n\ndef smallest_multiple():\n \"\"\"\n ... | trial_gpt4o_9 | {
"original_instruction": "Create a function that returns the smallest number that is evenly divisible by all numbers from 1 to 20.",
"prompt_id": "00016026",
"row_id": 16026,
"seed_ids": "['magpie_prefill_16026']"
} | 0.660568 | Prefill_16026 | C | [
"lcm",
"smallest_multiple",
"smallest_multiple_1_to_20"
] | 3 | [
[
"smallest_multiple",
"lcm"
],
[
"smallest_multiple_1_to_20",
"smallest_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 413e65ecb4f1a2c4bbbb2673594509ef71575221 | b9510a968b5463d1925fc13436378a5420c9367d | |||
v1.0 | complete | Prefill | Prefill_16379_C | def sum_integers(n):
""" Returns the sum of all integers from 1 to n.
>>> sum_integers(1) 1
>>> sum_integers(5) 15
>>> sum_integers(10) 55
>>> sum_integers(100) 5050
>>> sum_integers(1000) 500500
"""
pass
import time
def measure_performance(n):
""" Measures the performance of the s... | def sum_integers(n):
"""
Returns the sum of all integers from 1 to n.
"""
return n * (n + 1) // 2
import time
def measure_performance(n):
"""
Measures the performance of the sum_integers function for a given n.
"""
start_time = time.time()
result = sum_integers(n)
end_time = ti... | from solution import sum_integers, measure_performance
def test_sum_integers_small_n():
assert sum_integers(1) == 1
assert sum_integers(5) == 15
assert sum_integers(10) == 55
def test_sum_integers_large_n():
assert sum_integers(100) == 5050
assert sum_integers(1000) == 500500
def test_measure_per... | [
{
"docstring": "Returns the sum of all integers from 1 to n.",
"function_declaration": "def sum_integers(n):",
"function_name": "sum_integers",
"parameter_list": "(n)"
},
{
"docstring": "Measures the performance of the sum_integers function for a given n.",
"function_declaration": "def m... | [
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": "def sum_integers(n):\n \"\"\"\n Returns the sum of all integers from 1 to n.\n \"\"\"\n return n * (n + 1) // 2\n\ndef measure_performance(n_values):\n \"\"\"\n Measures the... | trial_gpt4o_9 | {
"original_instruction": "Create a function that calculates the sum of all integers from 1 to `n`. How would you implement this in Python and measure its performance for different values of `n`?",
"prompt_id": "00016379",
"row_id": 16379,
"seed_ids": "['magpie_prefill_16379']"
} | 0.699346 | Prefill_16379 | C | [
"sum_integers",
"measure_performance"
] | 2 | [
[
"measure_performance",
"sum_integers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 523035adb77276bd33bbf1b3941fcc1be5ad10a3 | cd09e1e26da72d93cf0364eae95e7dd44e0915ab | |||
v1.0 | complete | Prefill | Prefill_16780_C | import pytest
def find_min_max(arr, low, high):
"""
Returns a tuple (min_value, max_value) representing the minimum and maximum values in the array.
"""
pass
def find_min_max_in_array(arr):
"""
Helper function to initiate the recursive call.
"""
if not arr:
raise ValueError("Ar... | def find_min_max(arr, low, high):
"""
Returns a tuple (min_value, max_value) representing the minimum and maximum values in the array.
"""
# If the array has only one element
if low == high:
return (arr[low], arr[low])
# If the array has two elements
if high == low + 1:
if a... | from solution import find_min_max_in_array
import pytest
def test_single_element():
assert find_min_max_in_array([5]) == (5, 5)
def test_two_elements_sorted():
assert find_min_max_in_array([1, 2]) == (1, 2)
def test_two_elements_unsorted():
assert find_min_max_in_array([2, 1]) == (1, 2)
def test_multipl... | [
{
"docstring": "Returns a tuple (min_value, max_value) representing the minimum and maximum values in the array.",
"function_declaration": "def find_min_max(arr, low, high):",
"function_name": "find_min_max",
"parameter_list": "(arr, low, high)"
},
{
"docstring": "Helper function to initiate... | [
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_max(arr, n, current_min, current_max):\n \"\"\"\n This function returns a tuple containing the minimum and maximum values in the array using recursion.\n \n Parameter... | trial_gpt4o_9 | {
"original_instruction": "Create a function that finds the maximum and minimum values in an array using recursion in C++. The function should return a pair of values where the first element is the minimum and the second element is the maximum.",
"prompt_id": "00016780",
"row_id": 16780,
"seed_ids": "['magpie_p... | 0.628823 | Prefill_16780 | C | [
"find_min_max",
"find_min_max_in_array"
] | 2 | [
[
"find_min_max_in_array",
"find_min_max"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 802ca533a9990b6fdfe196f7553ebed5621fb021 | b114f53997e4dd0822fe639178d59470c2885798 | |||
v1.0 | complete | Prefill | Prefill_16183_C | def is_prime(n: int) -> bool:
"""
Returns true if n is a prime number, otherwise false.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(17) == True
>>> is_prime(18) == False
>>> is_prime(1) == False
>>> is_prime(0) == False
>>> is_prime(-5) ... | def is_prime(n):
"""
Returns true if n is a prime number, otherwise false.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return Fal... | from solution import largest_prime, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == Fal... | [
{
"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 largest prime number in the array.\nIf there are no prime numbers, returns -1.",
"functi... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(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": "Create a function that processes an array of integers and returns the largest prime number in the array. If there are no prime numbers in the array, the function should return -1.",
"prompt_id": "00016183",
"row_id": 16183,
"seed_ids": "['magpie_prefill_16183']"
} | 0.766557 | Prefill_16183 | C | [
"is_prime",
"largest_prime"
] | 2 | [
[
"largest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc21585feb64787086cda9712daa96a677aa799f | 58dd420f197a0f0e0d03cbb579fdd80a23c20ae1 | |||
v1.0 | complete | Prefill | Prefill_16872_C | def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(0)
False
>>> is_prime(4)
False
>>> is_prime(17)
True
"""
def is_prime_matrix(matrix: List[List[int]]) -> bool:
"""
Checks if every element in the ... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def is_pri... | from solution import is_prime_matrix, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
def test_is_prime_matrix_al... | [
{
"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": "Checks if every element in the given matrix is a prime number.\n\nArgs:\n matrix: List of lists of nu... | [
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_7 | {
"original_instruction": "Create a function that takes a list of lists of numbers called \"matrix\" as an input and checks if every element in the matrix is a prime number. If every element is prime, the function should return True. Otherwise, it should return False.",
"prompt_id": "00016872",
"row_id": 16872,
... | 0.749092 | Prefill_16872 | C | [
"is_prime",
"is_prime_matrix"
] | 2 | [
[
"is_prime_matrix",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d4fa154ead547a7286017028b4eb31650f2ffef8 | 901d7fdb55488fab154898cf0a1b73e24866c845 | |||
v1.0 | complete | Prefill | Prefill_16254_C | def quick_sort(arr):
"""Quick Sort algorithm implementation.
>>> quick_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10]
>>> quick_sort([]) == []
>>> quick_sort([5]) == [5]
>>> quick_sort([3, 3, 3]) == [3, 3, 3]
"""
def binary_search(arr, target):
"""Binary Search algorithm implementa... | def quick_sort(arr):
"""
Quick Sort algorithm implementation.
"""
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quic... | from solution import sort_and_search, quick_sort, binary_search
def test_quick_sort():
assert quick_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10]
assert quick_sort([]) == []
assert quick_sort([5]) == [5]
assert quick_sort([3, 3, 3]) == [3, 3, 3]
def test_binary_search():
assert binary_sea... | [
{
"docstring": "Quick Sort algorithm implementation.",
"function_declaration": "def quick_sort(arr):",
"function_name": "quick_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Binary Search algorithm implementation.",
"function_declaration": "def binary_search(arr, target):",
"fun... | [
1,
0,
0,
0,
0,
1,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quick_sort(arr):\n \"\"\"\n Sorts the array using the Quick Sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n else:\n pivot = arr[len(arr) // 2]\n ... | trial_gpt4o_5 | {
"original_instruction": "Create a function that takes an integer array and a target number as inputs, and uses the Quick Sort algorithm to sort the array and then searches for the target number in the sorted array. If the target is found, return its index; otherwise, return -1.",
"prompt_id": "00016254",
"row_i... | 0.666297 | Prefill_16254 | C | [
"quick_sort",
"binary_search",
"sort_and_search"
] | 3 | [
[
"sort_and_search",
"binary_search"
],
[
"sort_and_search",
"quick_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b620ba0f82f298ab983bbde9091e5efac7c330d8 | 1afd8cd230f82b7397be303b2b56aab60827bfe1 | |||
v1.0 | complete | Prefill | Prefill_16487_C | def is_prime(num: int) -> bool:
""" Checks if a given number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# Your code here
def sum_of_primes(numbers: List[int]) -> int:
""" Returns the sum of all prime numbers in the given list.
If there are no prime numbers, return... | def is_prime(num):
"""
Checks if a given 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 sum_of_prim... | from solution import sum_of_primes
def test_sum_of_primes_normal_case():
assert sum_of_primes([2, 3, 4, 5, 6, 7, 8, 9]) == 17
def test_sum_of_primes_all_non_primes():
assert sum_of_primes([1, 4, 6, 8, 9, 10, 12, 15]) == 0
def test_sum_of_primes_all_primes():
assert sum_of_primes([2, 3, 5, 7, 11]) == 28
... | [
{
"docstring": "Checks if a given number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list.\nIf there are no prime numbers, returns 0.",
"function_decl... | [
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(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n... | trial_gpt4o_8 | {
"original_instruction": "Create a function that accepts a list of integers and returns the sum of all prime numbers in the list. If there are no prime numbers, the function should return 0.",
"prompt_id": "00016487",
"row_id": 16487,
"seed_ids": "['magpie_prefill_16487']"
} | 0.754133 | Prefill_16487 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 189ff812564892e3d16cfbe3d225206f14ee45b7 | 59e020f901427116f92dff8c715904992a57cd83 | |||
v1.0 | complete | Prefill | Prefill_17203_C | from typing import List
def fibonacci(n: int) -> int:
"""
Recursive function to calculate the nth Fibonacci number.
"""
def fibonacci_sequence(N: int) -> List[int]:
"""
Returns the Fibonacci sequence up to the Nth element.
"""
from solution import fibonacci, fibonacci_sequence
def te... | def fibonacci(n):
"""
Recursive function to calculate the nth Fibonacci number.
"""
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def fibonacci_sequence(N):
"""
Returns the Fibonacci sequence up to the Nth element.... | from solution import fibonacci, fibonacci_sequence
def test_fibonacci_base_cases():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
def test_fibonacci_recursion():
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
assert fibonacci(6) == 8... | [
{
"docstring": "Recursive function to calculate the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns the Fibonacci sequence up to the Nth element.",
"function_declaration": "def fibonacci... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n):\n \"\"\"\n Returns the Fibonacci sequence up to the given number n using recursion.\n The sequence starts with 0 and 1, and each subsequent number is the sum of the... | trial_gpt4o_9 | {
"original_instruction": "Create a function that calculates the Fibonacci sequence up to a given number \\(N\\). The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones. Given that the function is recursive, implement it using Python and ensure to handle the base c... | 0.788019 | Prefill_17203 | C | [
"fibonacci",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 439b87caf2034b94afd78a937ba939563db09c59 | ce4c0dd47c01a6264980045a4904753effa92914 | |||
v1.0 | complete | Prefill | Prefill_16933_C | def fibonacci_recursive(n, memo={}):
""" Returns the n-th Fibonacci number using recursion with memoization.
Also includes error handling for invalid input.
>>> fibonacci_recursive(0) 0
>>> fibonacci_recursive(1) 1
>>> fibonacci_recursive(2) 1
>>> fibonacci_recursive(3) 2
>>> fibonacci_recur... | def fibonacci_recursive(n, memo={}):
"""
Returns the n-th Fibonacci number using recursion with memoization.
Also includes error handling for invalid input.
"""
if n < 0:
raise ValueError("Input cannot be negative.")
elif n == 0:
return 0
elif n == 1:
return 1
if ... | from solution import generate_fibonacci_sequence, fibonacci_recursive
def test_fibonacci_recursive():
assert fibonacci_recursive(0) == 0
assert fibonacci_recursive(1) == 1
assert fibonacci_recursive(2) == 1
assert fibonacci_recursive(3) == 2
assert fibonacci_recursive(4) == 3
assert fibonacci_r... | [
{
"docstring": "Returns the n-th Fibonacci number using recursion with memoization.\nAlso includes error handling for invalid input.",
"function_declaration": "def fibonacci_recursive(n, memo={}):",
"function_name": "fibonacci_recursive",
"parameter_list": "(n, memo={})"
},
{
"docstring": "R... | [
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 fibonacci(n, memo={0: 0, 1: 1}):\n \"\"\"\n Returns the nth Fibonacci number using a recursive function with memoization.\n \"\"\"\n if n < 0:\n raise ValueError(\"Inpu... | trial_gpt4o_8 | {
"original_instruction": "Create a function that generates a tuple with the first 10 elements of the Fibonacci sequence. Each element in the tuple should be calculated using a recursive function. Also, make sure to include error handling in your recursive function to prevent infinite recursion and ensure that the fu... | 0.826743 | Prefill_16933 | C | [
"fibonacci_recursive",
"generate_fibonacci_sequence"
] | 2 | [
[
"generate_fibonacci_sequence",
"fibonacci_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 14fad198d06352c326e644ba54437c1ea480cd53 | 70a86c7267c00fe2146e4a051e6407e35ba2c07e | |||
v1.0 | complete | Prefill | Prefill_15853_C | from typing import Tuple
def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def gcd(a: int, b: int) -> int:
""" Calculate the greatest common divisor of two numbers a and b.
>>> gcd(8, 12)
4
>>> gcd(100, 50)
... | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
return Tr... | from solution import gcd_if_prime
def test_gcd_if_prime_prime():
# nb3 is a prime number
assert gcd_if_prime(8, 12, 3) == 4
assert gcd_if_prime(100, 50, 5) == 50
assert gcd_if_prime(7, 14, 2) == 7
def test_gcd_if_prime_not_prime():
# nb3 is not a prime number
assert gcd_if_prime(8, 12, 4) == 0... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the greatest common divisor of two numbers a and b.",
"function_declaration": "def gcd(a, b):",
"functi... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n... | trial_gpt4o_9 | {
"original_instruction": "Create a function that takes three arguments: nb1, nb2, and nb3, which represent three, non-negative integers. The function should return the greatest common divisor (GCD) of nb1 and nb2. However, the GCD should only be calculated if nb3 is a prime number. If nb3 is not a prime number, the ... | 0.682159 | Prefill_15853 | C | [
"is_prime",
"gcd",
"gcd_if_prime"
] | 3 | [
[
"gcd_if_prime",
"gcd"
],
[
"gcd_if_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 530ffe1f83fe8d063461e06426e591ce49655970 | e39f3de64b36eaa3e3263c0d2813a0b709490106 | |||
v1.0 | complete | Prefill | Prefill_16888_C | def is_prime(n: int) -> bool:
"""
Checks if a given number n is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(-1) == False
>>> is_prime(0) == False
>>> is_prime(1) == False
>>> is_prime(29) == True
>>... | def is_prime(n):
"""
Checks 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 contains_prime(lst):
... | from solution import contains_prime, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(-1) == False
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(29) == Tru... | [
{
"docstring": "Checks if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Checks if a given list of integers contains any prime numbers.",
"function_declaration": "def contains_prime(lst):",
... | [
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_9 | {
"original_instruction": "Create a function that checks if a given list of integers contains a prime number. If it does, the function returns True; otherwise, it returns False. You need to do this without using any external libraries.",
"prompt_id": "00016888",
"row_id": 16888,
"seed_ids": "['magpie_prefill_16... | 0.852614 | Prefill_16888 | C | [
"is_prime",
"contains_prime"
] | 2 | [
[
"contains_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c912972d285cb8f1d9ef82e676c601b22576ff7b | be894ac827363c56e3824a321797f4dc0d690838 | |||
v1.0 | complete | Prefill | Prefill_15801_C | class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def merge_two_sorted_lists(l1, l2):
"""
Merges two sorted linked lists and returns the head of the combined sorted linked list.
"""
pass
def append_merged_lists(first_list, l1, l2):
"""
Merges two sorted l... | class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def merge_two_sorted_lists(l1, l2):
"""
Merges two sorted linked lists and returns the head of the combined sorted linked list.
"""
dummy = ListNode(0)
current = dummy
while l1 and l2:
if l1.val < ... | import pytest
from solution import ListNode, merge_two_sorted_lists, append_merged_lists
def linked_list_to_list(head):
result = []
current = head
while current:
result.append(current.val)
current = current.next
return result
def list_to_linked_list(lst):
dummy = ListNode(0)
c... | [] | [
1,
0,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\nclass LinkedList:\n def __init__(self):\n self.head = None\n\n def... | trial_gpt4o_9 | {
"original_instruction": "Create a function that merges two sorted linked lists and append the result to a given linked list.",
"prompt_id": "00015801",
"row_id": 15801,
"seed_ids": "['magpie_prefill_15801']"
} | 0.489162 | Prefill_15801 | C | [
"merge_two_sorted_lists",
"append_merged_lists"
] | 2 | [
[
"append_merged_lists",
"merge_two_sorted_lists"
]
] | 1 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | e759509876817e2e73b7526bf52ea342e457b982 | c907840469cb6bf5110b8b306f2556b5a514ef62 | |||
v1.0 | complete | Prefill | Prefill_17798_C | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
"""
pass
def extract_primes(numbers: List[int]) -> List[int]:
"""
Given a list of integers, return a new list of the prime numbers in the input list.
>>> extract_primes([10, 15, 3, 8, 7, 4, 11, 28]) [3, 7... | def is_prime(n):
"""
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 False
return True
d... | from solution import extract_primes
def test_extract_primes_all_primes():
assert extract_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_extract_primes_no_primes():
assert extract_primes([1, 4, 6, 8, 9, 10]) == []
def test_extract_primes_mixed():
assert extract_primes([10, 15, 3, 8, 7, 4, 11, 28]) ... | [
{
"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 of the prime numbers in the input list.",
"function_declaration": "def extract_pri... | [
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": "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_8 | {
"original_instruction": "Create a function that takes a list of integers and returns a new list of all the prime numbers in the input list. The order of the prime numbers in the output list should be the same as their order in the input list.",
"prompt_id": "00017798",
"row_id": 17798,
"seed_ids": "['magpie_p... | 0.787483 | Prefill_17798 | C | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b539665a1f61ef9f22c189cd10d06352235a1d2c | 08a96c476c0aa6eaf85a4c99eb404ce34b0cfca2 | |||
v1.0 | complete | Prefill | Prefill_17513_C | def sum_of_primes(numbers: List[Union[int, float, str]]) -> int:
"""
Returns the sum of all prime numbers in the list 'numbers'.
>>> sum_of_primes([2, 3, 5, 7, 11]) == 28
>>> sum_of_primes([2, 3, 4, 5, 6, 7]) == 17
>>> sum_of_primes([-3, -2, 2, 3]) == 5
>>> sum_of_primes([2, 3.5, 5, '7', 11]) =... | def is_prime(n):
"""
Checks if the given number n is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_primes(numbers):
"""
Returns the sum of all prime numbers in the list 'numbers'.
... | from solution import sum_of_primes
def test_sum_of_primes_with_primes():
assert sum_of_primes([2, 3, 5, 7, 11]) == 28
def test_sum_of_primes_mixed():
assert sum_of_primes([2, 3, 4, 5, 6, 7]) == 17
def test_sum_of_primes_with_negatives():
assert sum_of_primes([-3, -2, 2, 3]) == 5
def test_sum_of_primes_w... | [
{
"docstring": "Checks if the given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list 'numbers'.",
"function_declaration": "def sum_of_primes(numbers):"... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(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_7 | {
"original_instruction": "Create a function that takes a list of numbers and return the sum of all prime numbers in the list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. The function should ignore non-integer values and negative numbers.",
"prompt_id": "00017513... | 0.669851 | Prefill_17513 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc7a05fb4e73ab4f0dcf729131252fe19f1323af | ddebc5f48c6b4629f0b0bae3dcc7abba068ba3d6 | |||
v1.0 | complete | Prefill | Prefill_17108_C | def find_primes_and_non_prime_count(numbers: List[int]) -> Tuple[List[int], int]:
"""
Create a function that takes a list of integers as input and returns a list of prime numbers found in the input list.
Additionally, the function should also return the count of non-prime numbers in the input list.
... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def find_primes_and_non_prime_count(numbers):
"""
Returns a tuple consisting of a l... | from solution import find_primes_and_non_prime_count
def test_primes_and_non_prime_count():
assert find_primes_and_non_prime_count([2, 3, 4, 5, 6, 7]) == ([2, 3, 5, 7], 2)
assert find_primes_and_non_prime_count([10, 11, 12, 13, 14, 15]) == ([11, 13], 4)
assert find_primes_and_non_prime_count([1, 3, 5, 7, 9... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a tuple consisting of a list of prime numbers and the count of non-prime numbers.\n\n:param numbers... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(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_9 | {
"original_instruction": "Create a function that takes a list of integers as input and returns a list of prime numbers found in the input list. Additionally, the function should also return the count of non-prime numbers in the input list.",
"prompt_id": "00017108",
"row_id": 17108,
"seed_ids": "['magpie_prefi... | 0.780451 | Prefill_17108 | C | [
"is_prime",
"find_primes_and_non_prime_count"
] | 2 | [
[
"find_primes_and_non_prime_count",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a8622952722c885279cdf5489f3a1cccd64d11d | 146c9a885df3de7bb82ec8f0e00b9a730210362b | |||
v1.0 | complete | Prefill | Prefill_17512_C | def list_to_words(nums: List[int]) -> str:
""" Takes a list of integers and returns a string with each number followed by its English word or 'out_of_range' if the number is not in the range of 0-9.
>>> list_to_words([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == "0 zero 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 ei... | def number_to_words(n):
"""
Helper function to convert a single digit number to its corresponding English word.
"""
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
return words[n]
def list_to_words(nums):
"""
Takes a list of integers and returns a st... | from solution import list_to_words
def test_list_to_words_single_digit():
assert list_to_words([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == "0 zero 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine"
def test_list_to_words_mixed_range():
assert list_to_words([1, 15, 3]) == "1 one 15 out_of_range 3 three"
d... | [
{
"docstring": "Helper function to convert a single digit number to its corresponding English word.",
"function_declaration": "def number_to_words(n):",
"function_name": "number_to_words",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a string with each numb... | [
0,
1,
1,
1,
1,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def number_to_words(n):\n \"\"\"\n Converts a single digit number to its corresponding English word.\n \"\"\"\n words = [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\",... | trial_gpt4o_8 | {
"original_instruction": "Create a function that takes in a list of integers and returns a string with each number followed by its corresponding English word.",
"prompt_id": "00017512",
"row_id": 17512,
"seed_ids": "['magpie_prefill_17512']"
} | 0.588079 | Prefill_17512 | C | [
"number_to_words",
"list_to_words"
] | 2 | [
[
"list_to_words",
"number_to_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b4f59af2dbceed3304d24125eb5a4bbfbb262bb | 1442169aa93cc9814df0c7fc3d88b80b626c0e2f | |||
v1.0 | complete | Prefill | Prefill_17849_C | def is_prime(n: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def fibonacci_up_to(n: int) -> List[int]:
"""
Generate Fibonacci numbers up to n.
>>> fibonacci_up_to(10)
[0, 1, 1, 2, 3, 5, 8]
"""
def prime_fibonacci_in_range(... | 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 fibonacci_up_to(n):
"""
... | from solution import prime_fibonacci_in_range
def test_prime_fibonacci_in_range_standard_case():
assert prime_fibonacci_in_range(2, 100) == [2, 3, 5, 13, 89]
def test_prime_fibonacci_in_range_no_primes():
assert prime_fibonacci_in_range(4, 4) == []
def test_prime_fibonacci_in_range_single_prime():
assert... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate Fibonacci numbers up to n.",
"function_declaration": "def fibonacci_up_to(n):",
"function_name": "fibonacci_up_to... | [
0,
0,
0,
0,
1,
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 sympy\n\ndef generate_fibonacci_primes(start, end):\n \"\"\"\n Returns a list of numbers that are both prime and Fibonacci within the given range.\n \"\"\"\n\n def is_fibon... | trial_gpt4o_4 | {
"original_instruction": "Create a function that generates a list of prime numbers that are also Fibonacci numbers within a given range. For example, the function should take the range [2, 100] as input and return [2, 3, 5, 13], as these are the prime and Fibonacci numbers within the range. The function should be ef... | 0.853895 | Prefill_17849 | C | [
"is_prime",
"fibonacci_up_to",
"prime_fibonacci_in_range"
] | 3 | [
[
"prime_fibonacci_in_range",
"fibonacci_up_to"
],
[
"prime_fibonacci_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c40aa51fc13c508ee5d7518e1afa4ded977b147e | 6500e797099fed13890ac042521c5784f3b73c4a | |||
v1.0 | complete | Prefill | Prefill_17806_C | def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
"""
pass
def classify_number(num: int) -> str:
"""
Classify a number as "Even", "Odd", "Single Prime" or "Composite Prime".
>>> classify_number(2) "Sin... | def is_prime(num):
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def classify_number(num):
if num % 2 == 0:
if is_prime(num):
return "Single Prime" if num in [2,3,5] else "Even Composite Prime"
... | from solution import classify_number
def test_even_numbers():
assert classify_number(2) == "Single Prime"
assert classify_number(4) == "Even"
assert classify_number(6) == "Even"
assert classify_number(10) == "Even"
assert classify_number(8) == "Even"
assert classify_number(12) == "Even"
def te... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def classify_number(num):",
"function_name": "classify_number",
"parameter_list": "(num)"
}
] | [
0,
1,
0,
1,
1,
1,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_number_type(num):\n \"\"\"\n Checks if the given number is \"Even\", \"Odd\", or \"Prime\".\n If the number is prime, further classify it as \"Single Prime\" or \"Composite... | trial_gpt4o_5 | {
"original_instruction": "Create a function that takes a number as input and returns a string indicating whether the number is \"Even\", \"Odd\", or \"Prime\". If the number is prime, also indicate whether it is a \"Composite Prime\" or a \"Single Prime\". A \"Composite Prime\" is a number that is a prime and also h... | 0.77313 | Prefill_17806 | C | [
"is_prime",
"classify_number"
] | 2 | [
[
"classify_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 79337f9733c29c0c314117d0fa8313f226bf9865 | c54d78d9c7d9db90413acdec1859b3ba54215adb | |||
v1.0 | complete | Prefill | Prefill_17173_C | def largest_prime_leq(n: int) -> int:
""" Returns the largest prime number less than or equal to n.
If there are no prime numbers less than or equal to n, return -1.
>>> largest_prime_leq(5) == 5
>>> largest_prime_leq(10) == 7
>>> largest_prime_leq(1) == -1
>>> largest_prime_leq(0) == -1
>>>... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import largest_prime_leq
def test_largest_prime_leq_prime_input():
assert largest_prime_leq(5) == 5
def test_largest_prime_leq_non_prime_input():
assert largest_prime_leq(10) == 7
def test_largest_prime_leq_no_prime_below():
assert largest_prime_leq(1) == -1
assert largest_prime_leq(0) ... | [
{
"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 largest prime number less than or equal to n.\nIf there are no prime numbers less than or equal... | [
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 if n <= 3:\n return True\n if n % 2 == 0 ... | trial_gpt4o_0 | {
"original_instruction": "Create a function that takes an integer as input and returns the largest prime number less than or equal to the input number. If there are no prime numbers less than or equal to the input, return -1.",
"prompt_id": "00017173",
"row_id": 17173,
"seed_ids": "['magpie_prefill_17173']"
} | 0.782009 | Prefill_17173 | C | [
"is_prime",
"largest_prime_leq"
] | 2 | [
[
"largest_prime_leq",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02cbcb13ddb57a586efbe63a4ff706847b44522d | 3a3a609efb54ff8026386d3e23ac032b4f69d074 | |||
v1.0 | complete | Prefill | Prefill_18059_C | import math
from typing import List
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(11) True
>>> is_prime(1) False
>>> is_prime(0) False
>>> is_prime(-5) False
"""
... | 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 c... | from solution import concatenate_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(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_concatenate_pri... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a string containing all the prime numbers less than n, concatenated together in ascending order."... | [
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 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_0 | {
"original_instruction": "Create a function that generates a string containing all the prime numbers less than n, concatenated together in ascending order.",
"prompt_id": "00018059",
"row_id": 18059,
"seed_ids": "['magpie_prefill_18059']"
} | 0.787235 | Prefill_18059 | C | [
"is_prime",
"concatenate_primes"
] | 2 | [
[
"concatenate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 27127b4f5ccd7744a3c11b6102c783bf33c97f5c | f1b6222c5faf2703fd2936bad8079059e9a6cb10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.