version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Prefill
Prefill_31503_I
Write a python function to find the number of inversions in an array efficiently. Inversion count for an array is the count of pairs (i, j) such that i < j and arr[i] > arr[j].
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 # Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed right wh...
from solution import count_inversions def test_count_inversions_none(): assert count_inversions([]) == 0 def test_count_inversions_sorted(): assert count_inversions([1, 2, 3, 4, 5, 6, 7, 8]) == 0 def test_count_inversions_reverse_sorted(): assert count_inversions([8, 7, 6, 5, 4, 3, 2, 1]) == 28 def test...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray\n k = left # Starting inde...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00031503", "row_id": 31503, "seed_ids": "['magpie_prefill_31503']" }
0.894312
Prefill_31503
I
[ "merge_and_count", "merge_sort_and_count", "count_inversions" ]
3
[ [ "count_inversions", "merge_sort_and_count" ], [ "merge_sort_and_count", "merge_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f8b103cbb84e5c60859559750d2acd24b12cad06
7755d2fd982e4b5fe0527d41d910419dd823dbec
v1.0
instruct
Prefill
Prefill_31539_I
Write a python function to solve the 8 puzzle problem using the A* algorithm.
import heapq def heuristic(state, goal): """ Computes the Manhattan distance heuristic between the current state and the goal state. """ distance = 0 for i in range(1, 9): xi, yi = divmod(state.index(i), 3) xg, yg = divmod(goal.index(i), 3) distance += abs(xi - xg) + abs(yi ...
from solution import solve_8_puzzle def test_easy_puzzle(): start = [1, 2, 3, 4, 5, 6, 7, 8, 0] goal = [1, 2, 3, 4, 5, 6, 7, 8, 0] assert solve_8_puzzle(start, goal) == [[1, 2, 3, 4, 5, 6, 7, 8, 0]] def test_one_move_puzzle(): start = [1, 2, 3, 4, 5, 6, 7, 0, 8] goal = [1, 2, 3, 4, 5, 6, 7, 8, 0] ...
[ { "docstring": "Computes the Manhattan distance heuristic between the current state and the goal state.", "function_declaration": "def heuristic(state, goal):", "function_name": "heuristic", "parameter_list": "(state, goal)" }, { "docstring": "Returns the neighbors of the given state.", ...
[ 1, 0, 1, 0, 0, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\nclass PuzzleState:\n def __init__(self, state, parent=None, move=0, cost=0):\n self.state = state\n self.parent = parent\n self.move = move\n se...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00031539", "row_id": 31539, "seed_ids": "['magpie_prefill_31539']" }
0.473674
Prefill_31539
I
[ "heuristic", "get_neighbors", "astar_8_puzzle", "solve_8_puzzle" ]
4
[ [ "astar_8_puzzle", "get_neighbors" ], [ "astar_8_puzzle", "heuristic" ], [ "solve_8_puzzle", "astar_8_puzzle" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6dbf6236e90da1ca191185e6be86832b1f3c0f65
23dd013f3a7ab71fd95a9881ea586cb388c355bd
v1.0
instruct
Prefill
Prefill_31551_I
Write a python function to calculate the factorial of a number using recursion. Then, implement a check function to ensure your factorial function is working correctly.
def factorial(n): """ Returns the factorial of n using recursion. """ if n == 0: return 1 else: return n * factorial(n - 1) def check_factorial(): """ Checks the correctness of the factorial function by comparing its output with known values. """ test_cases = {0:...
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(2) == 2 assert factorial(3) == 6 def test_factorial_medium_numbers(): assert factorial(4) == 24 assert factor...
[ { "docstring": "Returns the factorial of n using recursion.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Checks the correctness of the factorial function by comparing its output\nwith known values.", "function_dec...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of a non-negative integer n using recursion.\n \"\"\"\n if n < 0:\n raise ValueError(\"Factorial is not defined for negat...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00031551", "row_id": 31551, "seed_ids": "['magpie_prefill_31551']" }
0.684783
Prefill_31551
I
[ "factorial", "check_factorial" ]
2
[ [ "check_factorial", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
01bf17308016471755e411921ae7f945f04d1606
a1ee24e6308e1757a3cb6856271caf105346c2fb
v1.0
instruct
Prefill
Prefill_31627_I
Write a python function to solve the Sudoku puzzle using depth-first search (DFS). The function should take a 2D list representing the Sudoku puzzle and return the solved puzzle. The empty cells are denoted by 0.
def is_valid(board, row, col, num): """ Check whether it is legal to assign num to the given row, col. """ # Check the row for j in range(9): if board[row][j] == num: return False # Check the column for i in range(9): if board[i][col] == num: retu...
from solution import solve_sudoku def test_valid_sudoku_solution(): 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, ...
[ { "docstring": "Check whether it is legal to assign num to the given row, col.", "function_declaration": "def is_valid(board, row, col, num):", "function_name": "is_valid", "parameter_list": "(board, row, col, num)" }, { "docstring": "Solve the Sudoku puzzle using DFS.", "function_declar...
[ 1, 0, 1, 0, 0, 1, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid(board, row, col, num):\n for x in range(9):\n if board[row][x] == num:\n return False\n\n for x in range(9):\n if board[x][col] == num:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00031627", "row_id": 31627, "seed_ids": "['magpie_prefill_31627']" }
0.471827
Prefill_31627
I
[ "is_valid", "solve_sudoku", "find_empty_cell" ]
3
[ [ "solve_sudoku", "find_empty_cell" ], [ "solve_sudoku", "is_valid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
756f0c140002a16416f5250e43d12a61de10dede
4501a20951f548c53ed0aad3b07e3adcf4880a7c
v1.0
instruct
Prefill
Prefill_31785_I
Write a python function to find all the prime numbers within an interval [l, r].
def is_prime(n): """ Helper function to determine if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import find_primes_in_interval, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(30) == False assert is_prime(1) == False def test_find_primes_in_interval_short_range(): ...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the interval [l, r].", "function_declaration": "def find_primes_...
[ 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 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_8
{ "original_instruction": "", "prompt_id": "00031785", "row_id": 31785, "seed_ids": "['magpie_prefill_31785']" }
0.742271
Prefill_31785
I
[ "is_prime", "find_primes_in_interval" ]
2
[ [ "find_primes_in_interval", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b94d2fdba115f28f55ffd3bc350b1c98abc6c988
cd347407deaba2bd76081677748d49d9f0232dd7
v1.0
instruct
Prefill
Prefill_31797_I
Write a python function to solve the equation of the form 2x^2 + 4x - 6 = 0, using the quadratic formula.
import math def solve_quadratic(a, b, c): """ Solves the quadratic equation of the form ax^2 + bx + c = 0. Args: a, b, c: Coefficients of the quadratic equation. Returns: A tuple of two solutions. """ discriminant = b ** 2 - 4 * a * c if discriminant < 0: return No...
from solution import solve_given_quadratic def test_solve_given_quadratic(): x1, x2 = solve_given_quadratic() assert round(x1, 6) == 1.0 assert round(x2, 6) == -3.0 def test_no_real_solution(): assert solve_quadratic(1, 0, 1) == (None, None) # x^2 + 1 = 0 has no real solution def test_double_root():...
[ { "docstring": "Solves the quadratic equation of the form ax^2 + bx + c = 0.\n\nArgs:\na, b, c: Coefficients of the quadratic equation.\n\nReturns:\nA tuple of two solutions.", "function_declaration": "def solve_quadratic(a, b, c):", "function_name": "solve_quadratic", "parameter_list": "(a, b, c)" ...
[ 1, 1, 1, 1, 0, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef solve_quadratic_equation(a, b, c):\n \"\"\"\n Solves the quadratic equation of the form ax^2 + bx + c = 0 using\n the quadratic formula.\n \n :param a: coeff...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00031797", "row_id": 31797, "seed_ids": "['magpie_prefill_31797']" }
0.616491
Prefill_31797
I
[ "solve_quadratic", "solve_given_quadratic" ]
2
[ [ "solve_given_quadratic", "solve_quadratic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8eb7f761c2b3b2b25dbbd3059efb4fdd74640382
be7aa86c236df97ec537ef64f621f7641b149400
v1.0
instruct
Prefill
Prefill_31877_I
Write a python function to calculate the product of all prime numbers in a given list. If there are no prime numbers, return `0`.
def is_prime(num): """ Helper function to check whether 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 product_of_primes(numbers): """ Returns the product of all prime numbe...
from solution import product_of_primes def test_product_of_primes_with_all_primes(): assert product_of_primes([2, 3, 5, 7]) == 210 def test_product_of_primes_with_some_primes(): assert product_of_primes([4, 6, 7, 9, 11]) == 77 def test_product_of_primes_with_no_primes(): assert product_of_primes([4, 6, 8...
[ { "docstring": "Helper function to check whether a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the product of all prime numbers in the given list.\nIf there are no prime numbers, returns 0....
[ 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 for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00031877", "row_id": 31877, "seed_ids": "['magpie_prefill_31877']" }
0.649617
Prefill_31877
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a27177c2f17f58ae7881353d6d52e34860af1774
9dd2c3f9ead892529b6cf768b17810d9bd5e62b5
v1.0
instruct
Prefill
Prefill_31936_I
Write a python function to calculate the nth Fibonacci number using both iterative and recursive methods. Compare their performance for large values of n.
import time def fib_recursive(n): """ Returns the nth Fibonacci number using recursion. """ if n <= 1: return n return fib_recursive(n - 1) + fib_recursive(n - 2) def fib_iterative(n): """ Returns the nth Fibonacci number using iteration. """ if n <= 1: return n ...
from solution import fib_recursive, fib_iterative, compare_fibonacci_performance def test_fib_recursive_base_cases(): assert fib_recursive(0) == 0 assert fib_recursive(1) == 1 def test_fib_recursive_general_case(): assert fib_recursive(10) == 55 assert fib_recursive(5) == 5 assert fib_recursive(7)...
[ { "docstring": "Returns the nth Fibonacci number using recursion.", "function_declaration": "def fib_recursive(n):", "function_name": "fib_recursive", "parameter_list": "(n)" }, { "docstring": "Returns the nth Fibonacci number using iteration.", "function_declaration": "def fib_iterative...
[ 1, 1, 1, 1, 0, 0, 0, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef fibonacci_iterative(n):\n \"\"\"\n Returns the nth Fibonacci number using an iterative method.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00031936", "row_id": 31936, "seed_ids": "['magpie_prefill_31936']" }
0.715935
Prefill_31936
I
[ "fib_recursive", "fib_iterative", "compare_fibonacci_performance" ]
3
[ [ "compare_fibonacci_performance", "fib_iterative" ], [ "compare_fibonacci_performance", "fib_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cfced5f594124c69b9f5181e3a4094b214e2f500
1396d43d7ae780d2cdd0cedb924eda0561259168
v1.0
instruct
Prefill
Prefill_32072_I
Write a python function to check if a number is anti-prime. An anti-prime (or highly composite number) is a positive integer with more divisors than any smaller positive integer. The function should take an integer as input and return True if it is anti-prime, False otherwise.
def count_divisors(n): """ Helper function to count the number of divisors of n. """ count = 0 for i in range(1, n+1): if n % i == 0: count += 1 return count def is_anti_prime(num): """ Returns True if num is an anti-prime, False otherwise. An anti-prime (or high...
from solution import is_anti_prime def test_is_anti_prime_1(): assert is_anti_prime(1) == True def test_is_anti_prime_2(): assert is_anti_prime(2) == True def test_is_anti_prime_3(): assert is_anti_prime(3) == False def test_is_anti_prime_4(): assert is_anti_prime(4) == True def test_is_anti_prime_...
[ { "docstring": "Helper function to count the number of divisors of n.", "function_declaration": "def count_divisors(n):", "function_name": "count_divisors", "parameter_list": "(n)" }, { "docstring": "Returns True if num is an anti-prime, False otherwise.\nAn anti-prime (or highly composite n...
[ 1, 1, 1, 1, 1, 0, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_anti_prime(n):\n \"\"\"\n Returns True if the given number is anti-prime, otherwise False.\n \"\"\"\n if n <= 0:\n return False\n\n def count_divisors(x):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032072", "row_id": 32072, "seed_ids": "['magpie_prefill_32072']" }
0.721741
Prefill_32072
I
[ "count_divisors", "is_anti_prime" ]
2
[ [ "is_anti_prime", "count_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ead101bee36545751df17ab3f5393b63eb1718fc
5e38a5d1edd38112d6dc53597bc329d06b6fbbfd
v1.0
instruct
Prefill
Prefill_32174_I
Write a python function to calculate the first 100 prime numbers and sum them up. The user should be able to run this function directly and print out the result. Please add comments for code understanding.
def is_prime(n): """Check if a number is a prime number.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_of_first_100_primes(): ""...
from solution import is_prime, sum_of_first_100_primes def test_is_prime(): # Test known prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(11) == True assert is_prime(13) == True # Test known non-prime numbers assert is_prime...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculate and return the sum of the first 100 prime numbers.", "function_declaration": "def sum_of_first_100_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 \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even prime number\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032174", "row_id": 32174, "seed_ids": "['magpie_prefill_32174']" }
0.629299
Prefill_32174
I
[ "is_prime", "sum_of_first_100_primes" ]
2
[ [ "sum_of_first_100_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
660336a4a4b019d3faa2746924d961da31ccb3bc
d6c51db90daf9b890e8a8b753950a46d67c5cfd8
v1.0
instruct
Prefill
Prefill_32200_I
Write a python function to implement merge sort algorithm. Merge Sort uses a divide-and-conquer approach to sort an array. It splits the array into two halves, recursively sorts them, and then merges them back together. The function should take a list of integers as input and return the sorted list.
def merge_sort(arr): """ Implements the merge sort algorithm. Takes a list of integers and returns the sorted list. """ 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)...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_ordered_elements(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_ordered_elements(): ...
[ { "docstring": "Implements the merge sort algorithm. \nTakes a list of integers and returns the sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into a single sorted 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 merge_sort(arr):\n \"\"\"\n Implement merge sort algorithm to sort a list of integers.\n \n Parameters:\n arr (list): List of integers to be sorted.\n \n Returns:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032200", "row_id": 32200, "seed_ids": "['magpie_prefill_32200']" }
0.678582
Prefill_32200
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76322d0a2bbdfebadf466f6ce742a788be327c94
defe5b45405987d7b9f2d3efc074d90b269265fd
v1.0
instruct
Prefill
Prefill_32302_I
Write a python function to generate the Fibonacci sequence with a given length. The function should take two parameters: `n` (the length of the sequence to generate) and `mode` (either 'loop' for iterative method or 'recursive' for recursive method). The function should return the Fibonacci sequence as a list.
def fibonacci(n, mode='loop'): """ Generates the Fibonacci sequence of length n. Parameters: n (int): Length of the sequence to generate. mode (str): Method to generate the sequence ('loop' for iterative, 'recursive' for recursive). Returns: list: Fibonacci sequence of length n. ...
from solution import fibonacci def test_fibonacci_loop(): assert fibonacci(0, 'loop') == [] assert fibonacci(1, 'loop') == [0] assert fibonacci(2, 'loop') == [0, 1] assert fibonacci(5, 'loop') == [0, 1, 1, 2, 3] assert fibonacci(10, 'loop') == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def test_fibonacci_r...
[ { "docstring": "Generates the Fibonacci sequence of length n.\n\nParameters:\nn (int): Length of the sequence to generate.\nmode (str): Method to generate the sequence ('loop' for iterative, 'recursive' for recursive).\n\nReturns:\nlist: Fibonacci sequence of length n.", "function_declaration": "def fibonac...
[ 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 fib(n, mode='loop'):\n \"\"\"\n Generates the Fibonacci sequence of length n using the specified mode.\n \n Parameters:\n n (int): Length of the Fibonacci sequence to gener...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032302", "row_id": 32302, "seed_ids": "['magpie_prefill_32302']" }
0.715091
Prefill_32302
I
[ "fibonacci", "fibonacci_loop", "fibonacci_recursive_helper", "fibonacci_recursive" ]
4
[ [ "fibonacci", "fibonacci_loop" ], [ "fibonacci", "fibonacci_recursive_helper" ], [ "fibonacci_recursive_helper", "fibonacci_recursive" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c80507bf496ab884c9b94c00c4f2f499144b09f5
dbe2db75574066355734f977dddafc612ee14a3d
v1.0
instruct
Prefill
Prefill_32437_I
Write a python function to find the maximum digital sum of a number a^b where a, b < 100
def max_digital_sum(limit): """ Finds the maximum digital sum of a number a^b where a, b < limit. """ def digital_sum(n): return sum(int(digit) for digit in str(n)) max_sum = 0 for a in range(1, limit): for b in range(1, limit): num = a ** b current_sum =...
from solution import max_digital_sum_100 def test_digital_sum_1_to_99(): result = max_digital_sum_100() assert result > 0 # There should be at least one maximum digital sum greater than zero. assert result == 972 # Verification of the known result for the specific limit of 100.
[ { "docstring": "Finds the maximum digital sum of a number a^b where a, b < limit.", "function_declaration": "def max_digital_sum(limit):", "function_name": "max_digital_sum", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def max_digital_sum_100():", "fu...
[ 1, 0, 0, 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 max_digit_sum():\n \"\"\"\n Returns the maximum digital sum of a number a^b where a, b < 100.\n \"\"\"\n def digital_sum(n):\n return sum(int(digit) for digit in str(n)...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032437", "row_id": 32437, "seed_ids": "['magpie_prefill_32437']" }
0.664667
Prefill_32437
I
[ "max_digital_sum", "max_digital_sum_100" ]
2
[ [ "max_digital_sum_100", "max_digital_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d46e7df86cb7b6f27a6840fb112267fad6867624
85eb71ee0c785ea0a3089a759d3b278c8d291496
v1.0
instruct
Prefill
Prefill_32532_I
Write a python function to identify prime numbers within a given range. Additionally, for each prime number identified, calculate and return the sum of its digits.
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def sum_...
from solution import is_prime, sum_of_digits, prime_numbers_with_digit_sums def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_sum_of_digits(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculate the sum of digits of a number.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digit...
[ 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_9
{ "original_instruction": "", "prompt_id": "00032532", "row_id": 32532, "seed_ids": "['magpie_prefill_32532']" }
0.711676
Prefill_32532
I
[ "is_prime", "sum_of_digits", "prime_numbers_with_digit_sums" ]
3
[ [ "prime_numbers_with_digit_sums", "is_prime" ], [ "prime_numbers_with_digit_sums", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2462c33b6c1cd98b6cf6bf2ae4dafc6a952b0d23
44705394610731ae70155566cec614ca22c275b8
v1.0
instruct
Prefill
Prefill_32550_I
Write a python function to filter out and return all prime numbers from a given list of integers, using list comprehension.
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Filters and returns a list of prime numbers from the given list of inte...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_no_primes(): assert filter_primes([4, 6, 8, 10, 12, 14]) == [] def test_filter_primes_with_only_primes(): assert filter_primes([2,...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters and returns a list of prime numbers from the given list of integers.", "function_declaration": "def filter_primes(n...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if an integer n is a prime number.\n Returns True if n is prime, else False.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032550", "row_id": 32550, "seed_ids": "['magpie_prefill_32550']" }
0.618952
Prefill_32550
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fba57f6ce9c8196e5b9ee381beb6b5192d7f44e
72d9246e5bd6b920bd53b1a3ef9a6491cf714cf6
v1.0
instruct
Prefill
Prefill_32585_I
Write a python function to solve a puzzle involving chess knights that can move in an "L" shape on a chessboard. The function should determine if a knight, starting from a given square, can reach a target square by making a series of legal knight moves. The function should also return the minimum number of moves requir...
from collections import deque def is_valid_move(x, y, n): """ Check if the given position (x, y) is within the bounds of the board. """ return 0 <= x < n and 0 <= y < n def min_knight_moves(n, start, target): """ Returns the minimum number of knight moves required to reach the target squa...
from solution import min_knight_moves def test_min_knight_moves_same_square(): assert min_knight_moves(8, (0, 0), (0, 0)) == 0 def test_min_knight_moves_standard_case(): assert min_knight_moves(8, (0, 0), (1, 2)) == 1 def test_min_knight_moves_two_moves(): assert min_knight_moves(8, (0, 0), (2, 4)) == 2 ...
[ { "docstring": "Check if the given position (x, y) is within the bounds of the board.", "function_declaration": "def is_valid_move(x, y, n):", "function_name": "is_valid_move", "parameter_list": "(x, y, n)" }, { "docstring": "Returns the minimum number of knight moves required to reach \nthe...
[ 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": "from collections import deque\n\ndef is_within_bounds(x, y):\n \"\"\"\n Check if (x, y) is within the bounds of an 8x8 chessboard.\n \"\"\"\n return 0 <= x < 8 and 0 <= y < 8\n\nd...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00032585", "row_id": 32585, "seed_ids": "['magpie_prefill_32585']" }
0.621841
Prefill_32585
I
[ "is_valid_move", "min_knight_moves" ]
2
[ [ "min_knight_moves", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1e587114b9d6346617cad3a344a79814634ef986
d67c32eeb5192a7e71612d3ac5d84a33f17a1da3
v1.0
instruct
Prefill
Prefill_32608_I
Write a python function to find the number of days in a given month and year. The function should handle both leap years and non-leap years. A typical non-leap year has 365 days, and a leap year has 366 days. The leap year condition is that the year is divisible by 4, except for years which are both divisible by 100 an...
def number_of_days_in_month(year, month): """ Returns the number of days in a given month and year. """ if month < 1 or month > 12: raise ValueError("Invalid month. Month should be between 1 and 12.") # Days in each month (index 1-based for months 1 to 12) month_days = [0, 31, 28, 31, 3...
from solution import number_of_days_in_month, is_leap_year def test_is_leap_year(): assert is_leap_year(2000) == True assert is_leap_year(1900) == False assert is_leap_year(2004) == True assert is_leap_year(2001) == False def test_number_of_days_in_month(): # February in leap year assert numbe...
[ { "docstring": "Returns the number of days in a given month and year.", "function_declaration": "def number_of_days_in_month(year, month):", "function_name": "number_of_days_in_month", "parameter_list": "(year, month)" }, { "docstring": "Returns True if the given year is a leap year, False o...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def days_in_month(year, month):\n \"\"\"\n Returns the number of days in the given month and year.\n \n Args:\n year (int): The year.\n month (int): The month (1 to 12).\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032608", "row_id": 32608, "seed_ids": "['magpie_prefill_32608']" }
0.686875
Prefill_32608
I
[ "number_of_days_in_month", "is_leap_year" ]
2
[ [ "number_of_days_in_month", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ecd898ad8e2d49e8fa9430d148a8b9f835290e7
31e69a797d05bac3dc999383d02242960488105b
v1.0
instruct
Prefill
Prefill_32618_I
Write a python function to check if a number in a binary tree is a perfect binary tree or not. In a perfect binary tree, all internal nodes have two children and all leaves are at the same level.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.value = key def get_depth(node): depth = 0 while node is not None: depth += 1 node = node.left return depth def is_perfect_binary_tree(root, depth, level=0): if root is None: ...
from solution import TreeNode, check_perfect_binary_tree def test_perfect_binary_tree(): # Constructing a perfect binary tree root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.left = TreeNode(6) root...
[]
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\n\ndef is_perfect_binary_tree(root: TreeNode) -> bool:\n if not roo...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00032618", "row_id": 32618, "seed_ids": "['magpie_prefill_32618']" }
0.609575
Prefill_32618
I
[ "get_depth", "is_perfect_binary_tree", "check_perfect_binary_tree" ]
3
[ [ "check_perfect_binary_tree", "get_depth" ], [ "check_perfect_binary_tree", "is_perfect_binary_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
93d8adc7199b0d8d0de663a215ab327f7c1af2b1
22f041ebbb3dcbd75dd5b7c7f25c7a6fcab1cacf
v1.0
instruct
Prefill
Prefill_32654_I
Write a python function to calculate the area of a triangle given the lengths of its three sides. Use Heron's formula. The function should also check if the input sides can form a valid triangle before calculating the area.
from math import sqrt def is_valid_triangle(a, b, c): """ Check if three sides can form a valid triangle. """ return a + b > c and a + c > b and b + c > a def triangle_area(a, b, c): """ Calculate the area of a triangle given the lengths of its three sides using Heron's formula. Ensure the...
import pytest from solution import is_valid_triangle, triangle_area def test_is_valid_triangle(): assert is_valid_triangle(3, 4, 5) == True assert is_valid_triangle(1, 1, 2) == False assert is_valid_triangle(5, 5, 5) == True assert is_valid_triangle(10, 1, 1) == False def test_triangle_area(): ass...
[ { "docstring": "Check if three sides can form a valid triangle.", "function_declaration": "def is_valid_triangle(a, b, c):", "function_name": "is_valid_triangle", "parameter_list": "(a, b, c)" }, { "docstring": "Calculate the area of a triangle given the lengths of its three sides using Hero...
[ 0, 1, 0, 0, 0, 1, 1, 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 validate_triangle_sides(a, b, c):\n \"\"\"\n Validate if the given sides can form a triangle using the triangle inequality theorem.\n \"\"\"\n return a + b > c ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032654", "row_id": 32654, "seed_ids": "['magpie_prefill_32654']" }
0.815516
Prefill_32654
I
[ "is_valid_triangle", "triangle_area" ]
2
[ [ "triangle_area", "is_valid_triangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
603d7796135146198385a49d1f7a3046e3f99c0c
7c3cbd5f58d2fec122bfb3e21346fba8e7897e31
v1.0
instruct
Prefill
Prefill_32661_I
Write a python function to generate a list of prime numbers between a given range. For example, if the range is between 10 and 20, the list should return [11, 13, 17, 19].
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 generate_primes(start, end): """ Returns a list of prime numbers between the...
from solution import generate_primes def test_primes_in_range_10_20(): assert generate_primes(10, 20) == [11, 13, 17, 19] def test_primes_in_range_1_10(): assert generate_primes(1, 10) == [2, 3, 5, 7] def test_primes_in_range_21_30(): assert generate_primes(21, 30) == [23, 29] def test_primes_in_range_s...
[ { "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 the given range [start, end].", "function_declaration": "def ge...
[ 1, 1, 1, 1, 1, 1, 0, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032661", "row_id": 32661, "seed_ids": "['magpie_prefill_32661']" }
0.635347
Prefill_32661
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
305fd94ae1c24ca65c2febfade2ae88aba1a5c96
5aaab6c089a1d11095f34dd09615ef123501a1da
v1.0
instruct
Prefill
Prefill_32755_I
Write a python function to identify a word in a sentence that is closest to the given word in terms of Levenshtein distance. Levenshtein distance is the minimum number of single-character edits (insertions, deletions or substitutions) required to change a word into the other.
def levenshtein_distance(word1, word2): """ Calculates the Levenshtein distance between two words. """ len1, len2 = len(word1), len(word2) dp = [[0] * (len2 + 1) for _ in range(len1 + 1)] for i in range(len1 + 1): dp[i][0] = i for j in range(len2 + 1): dp[0][j] = j ...
from solution import levenshtein_distance, closest_word def test_levenshtein_distance_same_words(): assert levenshtein_distance("kitten", "kitten") == 0 def test_levenshtein_distance_one_insertion(): assert levenshtein_distance("kitten", "kittens") == 1 def test_levenshtein_distance_one_substitution(): a...
[ { "docstring": "Calculates the Levenshtein distance between two words.", "function_declaration": "def levenshtein_distance(word1, word2):", "function_name": "levenshtein_distance", "parameter_list": "(word1, word2)" }, { "docstring": "Finds the word in the sentence that is closest to the tar...
[ 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef levenshtein_distance(word1, word2):\n \"\"\"\n Calculate the Levenshtein distance between two words.\n \"\"\"\n if len(word1) < len(word2):\n return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00032755", "row_id": 32755, "seed_ids": "['magpie_prefill_32755']" }
0.649744
Prefill_32755
I
[ "levenshtein_distance", "closest_word" ]
2
[ [ "closest_word", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
82bdf5608187b23b7b29486f8f4fd148c624e1af
2862f2f49c0d1ecf9d3336b4ea6e5ecd0a8833e4
v1.0
instruct
Prefill
Prefill_33127_I
Write a python function to find the smallest number greater than a given number that is composed only of prime digits (2, 3, 5, 7).
def is_prime_digit(num): """ Check if the given number is composed only of prime digits (2, 3, 5, 7). """ prime_digits = {'2', '3', '5', '7'} return all(char in prime_digits for char in str(num)) def next_number_with_prime_digits(n): """ Find the smallest number greater than n that is compo...
from solution import next_number_with_prime_digits def test_next_number_small_input(): assert next_number_with_prime_digits(1) == 2 assert next_number_with_prime_digits(2) == 3 def test_next_number_larger_input(): assert next_number_with_prime_digits(35) == 37 assert next_number_with_prime_digits(57) ...
[ { "docstring": "Check if the given number is composed only of prime digits (2, 3, 5, 7).", "function_declaration": "def is_prime_digit(num):", "function_name": "is_prime_digit", "parameter_list": "(num)" }, { "docstring": "Find the smallest number greater than n that is composed only of prim...
[ 1, 0, 0, 0, 1, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def next_prime_digit_number(n):\n \"\"\"\n Returns the smallest number greater than n that is composed only of prime digits (2, 3, 5, 7).\n \"\"\"\n prime_digits = {'2', '3', '5',...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00033127", "row_id": 33127, "seed_ids": "['magpie_prefill_33127']" }
0.679077
Prefill_33127
I
[ "is_prime_digit", "next_number_with_prime_digits" ]
2
[ [ "next_number_with_prime_digits", "is_prime_digit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
be14de0299fa5c0bebe70120b9f5e4f6ee2e8fbe
d3d3026a8a434b21541dab2ad5cdda1524f6e1a4
v1.0
instruct
Prefill
Prefill_33236_I
Write a python function to sort a given list in descending order using merge sort algorithm.
def merge_sort_desc(lst): """ Sorts the given list in descending order using the merge sort algorithm. """ if len(lst) <= 1: return lst mid = len(lst) // 2 left_half = merge_sort_desc(lst[:mid]) right_half = merge_sort_desc(lst[mid:]) return merge_desc(left_half, right_...
from solution import merge_sort_desc def test_merge_sort_desc_empty(): assert merge_sort_desc([]) == [] def test_merge_sort_desc_single_element(): assert merge_sort_desc([1]) == [1] def test_merge_sort_desc_sorted(): assert merge_sort_desc([5, 4, 3, 2, 1]) == [5, 4, 3, 2, 1] def test_merge_sort_desc_rev...
[ { "docstring": "Sorts the given list in descending order using the merge sort algorithm.", "function_declaration": "def merge_sort_desc(lst):", "function_name": "merge_sort_desc", "parameter_list": "(lst)" }, { "docstring": "Merges two lists into one in descending order.", "function_decl...
[ 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_descending(arr):\n \"\"\"\n Sorts the given list in descending order using the merge sort algorithm.\n \n Args:\n arr (list): List of elements to sort.\n \n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033236", "row_id": 33236, "seed_ids": "['magpie_prefill_33236']" }
0.729916
Prefill_33236
I
[ "merge_sort_desc", "merge_desc" ]
2
[ [ "merge_sort_desc", "merge_desc" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d41b00587bce00a43a6b447af90333266e836a4a
e08b7615e4f636984a40ee5d3a56feff699f610e
v1.0
instruct
Prefill
Prefill_33245_I
Write a python function to convert prefix to infix. Given a Prefix expression, write a function to convert it to an equivalent Infix expression. The prefix expression is in the form of a string.
def is_operator(c): return c in "+-*/" def prefix_to_infix(prefix_expression): stack = [] # Read the prefix expression in reverse order for ch in prefix_expression[::-1]: if is_operator(ch): # Pop two operands from stack op1 = stack.pop() op2 = stack.pop...
from solution import prefix_to_infix def test_simple_expression(): assert prefix_to_infix("+AB") == "(A+B)" def test_expression_with_multiple_operators(): assert prefix_to_infix("*+AB-CD") == "((A+B)*(C-D))" def test_expression_with_same_operators(): assert prefix_to_infix("-+A*BCD") == "((A+(B*C))-D)" ...
[ { "docstring": null, "function_declaration": "def is_operator(c):", "function_name": "is_operator", "parameter_list": "(c)" }, { "docstring": null, "function_declaration": "def prefix_to_infix(prefix_expression):", "function_name": "prefix_to_infix", "parameter_list": "(prefix_ex...
[ 1, 0, 1, 0, 0, 1, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_operator(c):\n \"\"\"\n Check if the character is an operator.\n \"\"\"\n return c in {'+', '-', '*', '/', '^'}\n\ndef prefix_to_infix(expression):\n \"\"\"\n Convert...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033245", "row_id": 33245, "seed_ids": "['magpie_prefill_33245']" }
0.619188
Prefill_33245
I
[ "is_operator", "prefix_to_infix" ]
2
[ [ "prefix_to_infix", "is_operator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b953ae694d1c90034ed894401f56128c90cf040
5053faef78bd2d0104f4b48d6ff370a0c36ef0b9
v1.0
instruct
Prefill
Prefill_33282_I
Write a python function to reverse a stack using recursion without the use of auxiliary stack.
def insert_at_bottom(stack, item): """ Helper function that inserts an item at the bottom of a stack using recursion. """ if not stack: stack.append(item) else: temp = stack.pop() insert_at_bottom(stack, item) stack.append(temp) def reverse_stack(stack): """ ...
from solution import reverse_stack def test_reverse_stack_empty(): assert reverse_stack([]) == [] def test_reverse_stack_single_element(): assert reverse_stack([1]) == [1] def test_reverse_stack_two_elements(): assert reverse_stack([1, 2]) == [2, 1] def test_reverse_stack_multiple_elements(): assert...
[ { "docstring": "Helper function that inserts an item at the bottom of a stack using recursion.", "function_declaration": "def insert_at_bottom(stack, item):", "function_name": "insert_at_bottom", "parameter_list": "(stack, item)" }, { "docstring": "Reverses a stack using recursion.", "fu...
[ 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 insert_at_bottom(stack, item):\n \"\"\"\n Helper function to insert an item at the bottom of a stack.\n \"\"\"\n if not stack:\n stack.append(item)\n else:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033282", "row_id": 33282, "seed_ids": "['magpie_prefill_33282']" }
0.512619
Prefill_33282
I
[ "insert_at_bottom", "reverse_stack" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d85ff5a469007b130b2fb1e0c087b9e0264fdde2
82a2b95c3885b2de83f49b0f57c4d8b38968d527
v1.0
instruct
Prefill
Prefill_33430_I
Write a python function to find all prime numbers between two given numbers. In this function, the function input will always be two positive non-negative numbers. The function output will be a list of all prime numbers between the given range.
def is_prime(n): """ Check if a number is a prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def find_primes_between(a, b): ...
from solution import find_primes_between def test_find_primes_between_10_and_20(): assert find_primes_between(10, 20) == [11, 13, 17, 19] def test_find_primes_between_1_and_10(): assert find_primes_between(1, 10) == [2, 3, 5, 7] def test_find_primes_between_20_and_30(): assert find_primes_between(20, 30)...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all prime numbers between two given non-negative numbers a and b (inclusive).\nReturns a list of prime numbers in the rang...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "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_9
{ "original_instruction": "", "prompt_id": "00033430", "row_id": 33430, "seed_ids": "['magpie_prefill_33430']" }
0.686409
Prefill_33430
I
[ "is_prime", "find_primes_between" ]
2
[ [ "find_primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bff0bb49274dcd194948195da2810bbf01484ce5
63319a27e26073ae26eb4b2f4cd2375fb8eb5cdc
v1.0
instruct
Prefill
Prefill_33467_I
Write a python function to determine if a given string is a palindrome, a permutation of a palindrome, or neither.
from collections import Counter def is_palindrome(s): """ Check if the given string is a palindrome. """ s = s.replace(" ", "").lower() return s == s[::-1] def can_form_palindrome(s): """ Check if any permutation of the given string can form a palindrome. """ s = s.replace(" ", "")...
from solution import determine_string_type def test_palindrome(): assert determine_string_type("A man a plan a canal Panama") == "palindrome" assert determine_string_type("racecar") == "palindrome" assert determine_string_type("madam") == "palindrome" assert determine_string_type("Never Odd Or Even") =...
[ { "docstring": "Check if the given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if any permutation of the given string can form a palindrome.", "function_declaration": "def ca...
[ 0, 0, 1, 1, 1, 0, 0, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef is_palindrome(s):\n \"\"\"\n Checks if the given string is a palindrome.\n \"\"\"\n s = ''.join(filter(str.isalnum, s)).lower()\n return ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00033467", "row_id": 33467, "seed_ids": "['magpie_prefill_33467']" }
0.751284
Prefill_33467
I
[ "is_palindrome", "can_form_palindrome", "determine_string_type" ]
3
[ [ "determine_string_type", "can_form_palindrome" ], [ "determine_string_type", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
35c8ecc0e9a78a2ee3ea9ac739a008b7c8da2cf7
2e7df38921cac95cfc99078b5cace7c025ac2b69
v1.0
instruct
Prefill
Prefill_33477_I
Write a python function to calculate the factorial of a number and then use this function in a loop to calculate the factorial of numbers from 1 to 5.
def factorial(n): """ Returns the factorial of a given number n. """ if n == 0: return 1 result = 1 for i in range(1, n + 1): result *= i return result def calculate_factorials_up_to_5(): """ Calculates the factorial of numbers from 1 to 5 and returns a list of the r...
from solution import factorial, calculate_factorials_up_to_5 def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 def test_calculate_factorials_up_to_5(): assert calcul...
[ { "docstring": "Returns the factorial of a given number n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Calculates the factorial of numbers from 1 to 5 and returns a list of the results.", "function_declaration": ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def factorial(n):\n \"\"\"\n Returns the factorial of n.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n else:\n return n * factorial(n - 1)\n\ndef factorials_in_ran...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033477", "row_id": 33477, "seed_ids": "['magpie_prefill_33477']" }
0.722113
Prefill_33477
I
[ "factorial", "calculate_factorials_up_to_5" ]
2
[ [ "calculate_factorials_up_to_5", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4292442f60821d40b1cab60b5ee44bf2f8f5884d
658eb7771ca3c6e2516af04c862cdde6be9a114f
v1.0
instruct
Prefill
Prefill_33585_I
Write a python function to find the smallest positive number that is evenly divisible by all the numbers from 1 to n, where n is a positive integer provided by the user. The function should be named `find_smallest_divisible` and take one parameter `n`.
from math import gcd from functools import reduce def lcm(a, b): """ Returns the least common multiple of a and b. """ return a * b // gcd(a, b) def find_smallest_divisible(n): """ Returns the smallest positive number that is evenly divisible by all the numbers from 1 to n. """ return ...
from solution import find_smallest_divisible def test_find_smallest_divisible_1(): assert find_smallest_divisible(1) == 1 def test_find_smallest_divisible_2(): assert find_smallest_divisible(2) == 2 def test_find_smallest_divisible_3(): assert find_smallest_divisible(3) == 6 def test_find_smallest_divis...
[ { "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 the numbers from 1 to n.", "function_declar...
[ 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 find_smallest_divisible(n):\n \"\"\"\n Returns the smallest positive number that is evenly divisible by all the numbers from 1 to n.\n \"\"\"\n def lcm(a, b):\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033585", "row_id": 33585, "seed_ids": "['magpie_prefill_33585']" }
0.671697
Prefill_33585
I
[ "lcm", "find_smallest_divisible" ]
2
[ [ "find_smallest_divisible", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af0394a04ab3e5f82046294cdc79b40486a2159f
6a7340de4f7f292df523543748ab401482564681
v1.0
instruct
Prefill
Prefill_33592_I
Write a python function to evaluate the value of two Roman numerals and return their sum. For example, if the input is `num1 = "MCDLXXI"` and `num2 = "MCMXCIV"`, the function should return the sum of these two Roman numerals, which should be `2445`.
def roman_to_int(s): """ Converts a Roman numeral to an integer. """ roman_to_int_map = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 } total = 0 prev_value = 0 for char in reversed(s): value = roman_to_int_map[char] if value < prev_va...
from solution import roman_to_int, sum_roman_numerals def test_roman_to_int(): assert roman_to_int("I") == 1 assert roman_to_int("IV") == 4 assert roman_to_int("IX") == 9 assert roman_to_int("XL") == 40 assert roman_to_int("XC") == 90 assert roman_to_int("M") == 1000 assert roman_to_int("MC...
[ { "docstring": "Converts a Roman numeral to an integer.", "function_declaration": "def roman_to_int(s):", "function_name": "roman_to_int", "parameter_list": "(s)" }, { "docstring": "Evaluates the value of two Roman numerals and returns their sum.", "function_declaration": "def sum_roman_...
[ 0, 0, 1, 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 roman_to_int(roman):\n roman_dict = {\n 'I': 1, 'V': 5, 'X': 10, 'L': 50,\n 'C': 100, 'D': 500, 'M': 1000\n }\n total = 0\n prev_value = 0\n\n for char in rev...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00033592", "row_id": 33592, "seed_ids": "['magpie_prefill_33592']" }
0.57077
Prefill_33592
I
[ "roman_to_int", "sum_roman_numerals" ]
2
[ [ "sum_roman_numerals", "roman_to_int" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f260d25fe4f9a385fb31c3f32d126240885c0c3
4a220975ad118af6a7871111a9e809f34f4e30cb
v1.0
instruct
Prefill
Prefill_33663_I
Write a python function to check if the input number is a Magical Triplet number or not. A Magical Triplet number is defined as a perfect square of a prime number. Your function should return `True` if the number is a Magical Triplet number, and `False` otherwise.
from math import isqrt def is_prime(n): """ Helper function to check if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, isqrt(n) + 1, 2): if n % i == 0: return False return ...
from solution import is_magical_triplet_number def test_prime_square(): assert is_magical_triplet_number(4) == True # 2^2 assert is_magical_triplet_number(9) == True # 3^2 assert is_magical_triplet_number(25) == True # 5^2 def test_non_prime_square(): assert is_magical_triplet_number(8) == Fal...
[ { "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 True if the input number n is a Magical Triplet number.\nA Magical Triplet number is defined as a per...
[ 0, 1, 0, 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": "import math\n\ndef 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 % ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00033663", "row_id": 33663, "seed_ids": "['magpie_prefill_33663']" }
0.632719
Prefill_33663
I
[ "is_prime", "is_magical_triplet_number" ]
2
[ [ "is_magical_triplet_number", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f180a5c6caecfeab695853113fb918b938b75afa
b0ef9280bf29d8c11f8d93d9964eadceecb0837c
v1.0
instruct
Prefill
Prefill_33796_I
Write a python function to check if a given number is a "weird number." A weird number is defined as a positive integer greater than 20 that is not a prime number but has a sum of its proper divisors (excluding itself) (sumexv) that is greater than the number itself.
def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_proper_divisors(n): divisors_sum = 1 for i in range(2, int(n**0.5) + 1): if n % i == 0: if i == n // i: div...
from solution import is_weird_number, is_prime, sum_of_proper_divisors def test_prime_checking(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(17) assert not is_prime(18) def test_sum_of_proper_divisors(): assert sum_of_proper_divisors...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_proper_divisors(n):", "function_name": "sum_of_proper_divisors", "parameter_list": "(n)" }, { ...
[ 0, 0, 1, 1, 0, 1, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sympy\n\ndef is_weird_number(n):\n \"\"\"\n Returns True if n is a weird number, else False.\n \n A weird number is defined as a positive integer greater than 20 that \n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00033796", "row_id": 33796, "seed_ids": "['magpie_prefill_33796']" }
0.59886
Prefill_33796
I
[ "is_prime", "sum_of_proper_divisors", "is_weird_number" ]
3
[ [ "is_weird_number", "is_prime" ], [ "is_weird_number", "sum_of_proper_divisors" ] ]
2
[]
false
[]
false
pytest
true
[]
true
483e915c96e5e451964993d33ebe054d1a98c343
7a7dbada928c49bcc4c9851bc51b67b212b71ff1
v1.0
instruct
Prefill
Prefill_33945_I
Write a python function to find the closest pair of points in a 2D plane. The function should take a list of tuples representing the points and return a tuple containing the two closest points and the distance between them.
import math from itertools import combinations def distance(p1, p2): """ Calculate the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def closest_pair_of_points(points): """ Returns the two closest points and the distance betw...
from solution import closest_pair_of_points def test_closest_pair_simple_case(): points = [(0, 0), (3, 4), (1, 1)] assert closest_pair_of_points(points) == (((0, 0), (1, 1)), math.sqrt(2)) def test_closest_pair_with_same_points(): points = [(0, 0), (3, 4), (0, 0)] assert closest_pair_of_points(points)...
[ { "docstring": "Calculate the Euclidean distance between two points p1 and p2.", "function_declaration": "def distance(p1, p2):", "function_name": "distance", "parameter_list": "(p1, p2)" }, { "docstring": "Returns the two closest points and the distance between them.", "function_declara...
[ 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom typing import List, Tuple\n\ndef euclidean_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float:\n \"\"\"\n Returns the Euclidean distance between two p...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033945", "row_id": 33945, "seed_ids": "['magpie_prefill_33945']" }
0.658882
Prefill_33945
I
[ "distance", "closest_pair_of_points" ]
2
[ [ "closest_pair_of_points", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aec85494d850119ef452b1f2c69678c1e4b0ec1a
2c065d6d3ca604929d183295f981ee7de0d10120
v1.0
instruct
Prefill
Prefill_33977_I
Write a python function to solve a 2D grid puzzle where the task is to fill in a grid with numbers such that each row and each column contains each number from 1 to N exactly once, where N is the size of the grid. The function should take the grid as a list of lists and return the solved grid.
def is_valid(grid, row, col, num): N = len(grid) for x in range(N): if grid[row][x] == num: return False if grid[x][col] == num: return False return True def solve_grid(grid, N): for row in range(N): for col in range(N): if grid[row][col] == 0...
from solution import solve_puzzle def test_solve_puzzle_1(): grid = [ [0, 2, 3], [3, 0, 2], [2, 3, 0] ] solved_grid = solve_puzzle(grid) assert solved_grid == [ [1, 2, 3], [3, 1, 2], [2, 3, 1] ] def test_solve_puzzle_2(): grid = [ [0, 0, ...
[ { "docstring": null, "function_declaration": "def is_valid(grid, row, col, num):", "function_name": "is_valid", "parameter_list": "(grid, row, col, num)" }, { "docstring": null, "function_declaration": "def solve_grid(grid, N):", "function_name": "solve_grid", "parameter_list": "...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_safe(grid, row, col, num):\n \"\"\"\n Check if it's safe to place a number in the given cell according\n to the puzzle's rules.\n \"\"\"\n N = len(grid)\n # Check if ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00033977", "row_id": 33977, "seed_ids": "['magpie_prefill_33977']" }
0.636054
Prefill_33977
I
[ "is_valid", "solve_grid", "solve_puzzle" ]
3
[ [ "solve_grid", "is_valid" ], [ "solve_puzzle", "solve_grid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
854f123ae1ef3b8058a9d5e87505593d65041e58
f32b0f649afecda2b804b721e02d46b95c3abaa3
v1.0
instruct
Prefill
Prefill_33988_I
Write a python function to find the sum of the digits in the number 100!
import math def sum_of_digits_in_factorial(n): """ Calculates the sum of the digits in the factorial of a given number n. :param n: An integer n :return: Sum of the digits in n! """ factorial_result = math.factorial(n) digits_sum = sum(int(digit) for digit in str(factorial_result)) ...
from solution import sum_of_digits_in_factorial, sum_of_digits_in_100_factorial def test_sum_of_digits_in_factorial_5(): assert sum_of_digits_in_factorial(5) == 3 # 5! = 120, sum of digits = 1 + 2 + 0 = 3 def test_sum_of_digits_in_factorial_10(): assert sum_of_digits_in_factorial(10) == 27 # 10! = 3628800, ...
[ { "docstring": "Calculates the sum of the digits in the factorial of a given number n.\n\n:param n: An integer n\n:return: Sum of the digits in n!", "function_declaration": "def sum_of_digits_in_factorial(n):", "function_name": "sum_of_digits_in_factorial", "parameter_list": "(n)" }, { "docs...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef sum_of_digits_in_factorial(n):\n \"\"\"\n Returns the sum of the digits in the factorial of n.\n \"\"\"\n factorial = math.factorial(n)\n return sum(int(digi...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00033988", "row_id": 33988, "seed_ids": "['magpie_prefill_33988']" }
0.731744
Prefill_33988
I
[ "sum_of_digits_in_factorial", "sum_of_digits_in_100_factorial" ]
2
[ [ "sum_of_digits_in_100_factorial", "sum_of_digits_in_factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f948aa8206eeaf1f984afa994232798b8eb0cbbe
ced5783613d2ec439de57c7eced9d9b421d83a4f
v1.0
instruct
Prefill
Prefill_34109_I
Write a python function to generate a valid date string representing the next business day using the datetime module, considering weekends and holidays. The function should also print this date string. Additionally, create a list of holidays that your function will take into consideration.
import datetime # List of holidays as date objects (year, month, day) HOLIDAYS = [ datetime.date(2023, 1, 1), # New Year's Day datetime.date(2023, 7, 4), # Independence Day datetime.date(2023, 12, 25), # Christmas ] def is_business_day(date): """ Check if a given date is a business day (i.e., no...
import datetime from solution import next_business_day, HOLIDAYS def test_next_business_day_on_weekday(): date = datetime.date(2023, 10, 17) # Tuesday assert next_business_day(date) == datetime.date(2023, 10, 18) # Wednesday def test_next_business_day_on_friday(): date = datetime.date(2023, 10, 20) # Frid...
[ { "docstring": "Check if a given date is a business day (i.e., not a weekend or a holiday).", "function_declaration": "def is_business_day(date):", "function_name": "is_business_day", "parameter_list": "(date)" }, { "docstring": "Given a date, returns the next business day considering weeken...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import datetime\n\ndef next_business_day(start_date):\n \"\"\"\n Returns the next business day date string, considering weekends and holidays.\n \"\"\"\n holidays = [\n dat...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034109", "row_id": 34109, "seed_ids": "['magpie_prefill_34109']" }
0.766916
Prefill_34109
I
[ "is_business_day", "next_business_day", "print_next_business_day" ]
3
[ [ "next_business_day", "is_business_day" ], [ "print_next_business_day", "next_business_day" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a68d35c6a6e5c0a800cd561321b5205f9a0f5426
cccf8ddbf601ab2e759c92339211dfcdf287e6a1
v1.0
instruct
Prefill
Prefill_34162_I
Write a python function to return the smallest positive integer `n` such that the sum of the nth-powered numbers of its digits is equal to `n`. This number is known as an "Narcissistic number" in base 10.
def is_narcissistic(number): """ Check if a number is a narcissistic number. A number is narcissistic if it is equal to the sum of its own digits each raised to the power of the number of digits. Args: number (int): The number to check. Returns: bool: True if the number is narcissi...
from solution import is_narcissistic, smallest_positive_narcissistic def test_is_narcissistic(): assert is_narcissistic(1) == True # 1^1 == 1 assert is_narcissistic(2) == True # 2^1 == 2 assert is_narcissistic(5) == True # 5^1 == 5 assert is_narcissistic(153) == True # 1^3 + 5^3 + 3^3 == 153 as...
[ { "docstring": "Check if a number is a narcissistic number.\nA number is narcissistic if it is equal to the sum of its own digits each raised to the power of the number of digits.\n\nArgs:\nnumber (int): The number to check.\n\nReturns:\nbool: True if the number is narcissistic, False otherwise.", "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_narcissistic(number):\n \"\"\"\n Check if a given number is a narcissistic number.\n \"\"\"\n digits = [int(d) for d in str(number)]\n power = len(digits)\n return nu...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00034162", "row_id": 34162, "seed_ids": "['magpie_prefill_34162']" }
0.588731
Prefill_34162
I
[ "is_narcissistic", "smallest_positive_narcissistic" ]
2
[ [ "smallest_positive_narcissistic", "is_narcissistic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a912c57c91f1be5681b3671ac7458f7011ff0749
069c75c25f6ed65d6c5caa14d2cd699594a55d72
v1.0
instruct
Prefill
Prefill_34202_I
Write a python function to find the maximum subarray problem using a divide-and-conquer strategy. The function should take in a list of integers.
def max_crossing_subarray(arr, low, mid, high): left_sum = float('-inf') total = 0 max_left = mid for i in range(mid, low - 1, -1): total += arr[i] if total > left_sum: left_sum = total max_left = i right_sum = float('-inf') total = 0 max_right = ...
from solution import find_maximum_subarray def test_single_element(): assert find_maximum_subarray([1]) == (0, 0, 1) assert find_maximum_subarray([-1]) == (0, 0, -1) def test_all_positive_elements(): assert find_maximum_subarray([1, 2, 3, 4, 5]) == (0, 4, 15) def test_all_negative_elements(): assert ...
[ { "docstring": null, "function_declaration": "def max_crossing_subarray(arr, low, mid, high):", "function_name": "max_crossing_subarray", "parameter_list": "(arr, low, mid, high)" }, { "docstring": null, "function_declaration": "def max_subarray(arr, low, high):", "function_name": "m...
[ 1, 1, 0, 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 find_max_crossing_subarray(arr, low, mid, high):\n left_sum = float('-inf')\n sum = 0\n max_left = mid\n for i in range(mid, low-1, -1):\n sum = sum + arr[i]\n i...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034202", "row_id": 34202, "seed_ids": "['magpie_prefill_34202']" }
0.686649
Prefill_34202
I
[ "max_crossing_subarray", "max_subarray", "find_maximum_subarray" ]
3
[ [ "find_maximum_subarray", "max_subarray" ], [ "max_subarray", "max_crossing_subarray" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4af3ea1fe1289cdcfaae7cbbd0a086a5369cc8d9
b10b4ba3d96aa7d877fa1133a66d645d3d63dc8c
v1.0
instruct
Prefill
Prefill_34207_I
Write a python function to generate all unique subsets of an array. The solution set must not contain duplicate subsets.
def subsets(nums): """ Generates all unique subsets of the array `nums`. """ nums.sort() # Sort to handle duplicates result = [] subset_helper(nums, 0, [], result) return result def subset_helper(nums, index, path, result): result.append(path) for i in range(index, len(nums)): ...
from solution import subsets def test_empty_array(): assert subsets([]) == [[]] def test_single_element(): assert subsets([1]) == [[], [1]] def test_two_elements(): assert subsets([1, 2]) == [[], [1], [1, 2], [2]] def test_duplicates(): assert subsets([1, 2, 2]) == [[], [1], [1, 2], [1, 2, 2], [2], ...
[ { "docstring": "Generates all unique subsets of the array `nums`.", "function_declaration": "def subsets(nums):", "function_name": "subsets", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def subset_helper(nums, index, path, result):", "function_name": "...
[ 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 subsets_with_dup(nums):\n \"\"\"\n Generates all unique subsets of the given list 'nums'.\n \"\"\"\n nums.sort() # Sort the array to handle duplicates\n result = []\n g...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034207", "row_id": 34207, "seed_ids": "['magpie_prefill_34207']" }
0.626938
Prefill_34207
I
[ "subsets", "subset_helper" ]
2
[ [ "subsets", "subset_helper" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d97d6b40a3a8c4f3900710fa88bc198dcf73d9d
b2bbe23255674ec21033b2146be6f1c042e17d75
v1.0
instruct
Prefill
Prefill_34215_I
Write a python function to calculate the sum of all prime numbers in a given range.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_primes_in_range(start, end): """ Returns the sum of all prime numbers in the gi...
from solution import sum_primes_in_range def test_sum_primes_in_small_range(): assert sum_primes_in_range(1, 10) == 17 # primes are 2, 3, 5, 7 def test_sum_primes_in_large_range(): assert sum_primes_in_range(10, 20) == 60 # primes are 11, 13, 17, 19 def test_sum_primes_with_no_primes(): assert sum_prim...
[ { "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 given range [start, end].", "function_declaration": "def sum_pr...
[ 1, 0, 1, 1, 0, 0, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00034215", "row_id": 34215, "seed_ids": "['magpie_prefill_34215']" }
0.752791
Prefill_34215
I
[ "is_prime", "sum_primes_in_range" ]
2
[ [ "sum_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
586da75bbcf7a49ed88d4511155d4b27c9337326
9cfda592af22ebf19fbd04ff65dcf88ace26adad
v1.0
instruct
Prefill
Prefill_34292_I
Write a python function to remove duplicates from a list. You should use a list comprehension and not the `set` data structure. You cannot use any built-in methods for removing duplicates (like `remove()`, `pop()`, `index()`, list slicing operations etc.). Additionally, your solution must be efficient in terms of both ...
def remove_duplicates(lst): """ Removes duplicates from a list using list comprehension. Parameters: lst (list): The input list from which duplicates are to be removed. Returns: list: A new list without duplicates. """ seen = {} return [x for x in lst if not (x in seen or s...
from solution import remove_duplicates def test_remove_duplicates_with_no_duplicates(): assert remove_duplicates([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_remove_duplicates_with_all_duplicates(): assert remove_duplicates([1, 1, 1, 1]) == [1] def test_remove_duplicates_with_some_duplicates(): assert re...
[ { "docstring": "Removes duplicates from a list using list comprehension.\n\nParameters:\nlst (list): The input list from which duplicates are to be removed.\n\nReturns:\nlist: A new list without duplicates.", "function_declaration": "def remove_duplicates(lst):", "function_name": "remove_duplicates", ...
[ 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 remove_duplicates(lst):\n \"\"\"\n Removes duplicates from a list using list comprehension.\n \n Parameters:\n lst (list): The list from which to remove duplicates.\n \n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034292", "row_id": 34292, "seed_ids": "['magpie_prefill_34292']" }
0.807371
Prefill_34292
I
[ "remove_duplicates", "seen_set" ]
2
[ [ "remove_duplicates", "seen_set" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c974c9e5fd92e87336789ee496944c06c3e3c03d
b61e99f07fcd2d4ac0fbb8ffc330d37cdb9fe4d8
v1.0
instruct
Prefill
Prefill_34340_I
Write a python function to sort a list in ascending order using the merge sort algorithm.
def merge_sort(arr): """ Perform merge sort on the input list and return the sorted list. """ if len(arr) <= 1: return arr # Split the array into two halves mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] # Recursively sort both halves left_sorted = mer...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([5]) == [5] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert...
[ { "docstring": "Perform merge sort on the input list and return the sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merge two sorted lists into one sorted list.", "function_declaration": "def merge...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list in ascending order using the merge sort algorithm.\n \n Parameters:\n arr (list): The list to sort.\n \n Returns:\n list: ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034340", "row_id": 34340, "seed_ids": "['magpie_prefill_34340']" }
0.726113
Prefill_34340
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
046b6ea9cb9f08c31bb0ec97ad6e7553ef797900
8fd73742802070b271bac0ade114869e8e711b51
v1.0
instruct
Prefill
Prefill_34388_I
Write a python function to calculate an n x n matrix (2D array) where each element at position [i, j] is the sum of digits of i*j (1 <= i <= n, 1 <= j <= n).
def sum_digits(number): """ Returns the sum of digits of a number. """ return sum(int(digit) for digit in str(number)) def calculate_matrix(n): """ Returns an n x n matrix where each element at position [i, j] is the sum of digits of i*j. """ matrix = [] for i in range(1, n + 1): ...
from solution import calculate_matrix def test_calculate_matrix_1x1(): assert calculate_matrix(1) == [[1]] def test_calculate_matrix_2x2(): assert calculate_matrix(2) == [ [1, 2], [2, 4] ] def test_calculate_matrix_3x3(): assert calculate_matrix(3) == [ [1, 2, 3], [2, ...
[ { "docstring": "Returns the sum of digits of a number.", "function_declaration": "def sum_digits(number):", "function_name": "sum_digits", "parameter_list": "(number)" }, { "docstring": "Returns an n x n matrix where each element at position [i, j] is the sum of digits of i*j.", "functio...
[ 0, 1, 0, 1, 1, 0, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(num):\n \"\"\"\n Returns the sum of digits of a given number.\n \"\"\"\n return sum(int(digit) for digit in str(num))\n\ndef generate_matrix(n):\n \"\"\"\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00034388", "row_id": 34388, "seed_ids": "['magpie_prefill_34388']" }
0.634634
Prefill_34388
I
[ "sum_digits", "calculate_matrix" ]
2
[ [ "calculate_matrix", "sum_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d8336d242730e731dd97fb7331474069c9b02bbd
4537d763e775daa7fec66ecbf482a546e35afec6
v1.0
instruct
Prefill
Prefill_34535_I
Write a python function to test if a given number is a beautiful number. A beautiful number is defined as a number that is both a palindrome (reads the same backward as forward) and the sum of its digits is also a palindrome.
def is_palindrome(n): """ Helper function to check if a given number n is a palindrome. """ return str(n) == str(n)[::-1] def sum_of_digits(n): """ Helper function to calculate the sum of the digits of a given number n. """ return sum(int(digit) for digit in str(n)) def is_beautiful_nu...
from solution import is_beautiful_number def test_beautiful_number_single_digit(): assert is_beautiful_number(5) == True def test_beautiful_number_double_digit(): assert is_beautiful_number(33) == True def test_beautiful_number_not_palindrome(): assert is_beautiful_number(123) == False def test_beautifu...
[ { "docstring": "Helper function to check if a given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Helper function to calculate the sum of the digits of a given number n.", "functio...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Helper function to check if a given number n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef sum_of_digits(n):\n \"\"\"\n H...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034535", "row_id": 34535, "seed_ids": "['magpie_prefill_34535']" }
0.658965
Prefill_34535
I
[ "is_palindrome", "sum_of_digits", "is_beautiful_number" ]
3
[ [ "is_beautiful_number", "is_palindrome" ], [ "is_beautiful_number", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7749d6c024a2fe47a01589523a01f008953c4f82
18ac24c4b8d163f7f6eacf1bb2ddcc5cfafc44d8
v1.0
instruct
Prefill
Prefill_34577_I
Write a python function to find all pairs of prime numbers whose sum is even. In python, a prime number is a whole number that has only two distinct factors: 1 and itself. For example, 2, 3, 5, 7, 11, etc.
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def find_prime_pairs(even_sum): if even_sum % 2 != 0 or even_sum < 4: ...
from solution import find_prime_pairs, 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(29) == True assert is_prime(30) == False def test_find_prime_pairs(): # Test with even sum 4 ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_prime_pairs(even_sum):", "function_name": "find_prime_pairs", "parameter_list": "(even_sum)" } ]
[ 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": "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_7
{ "original_instruction": "", "prompt_id": "00034577", "row_id": 34577, "seed_ids": "['magpie_prefill_34577']" }
0.736017
Prefill_34577
I
[ "is_prime", "find_prime_pairs" ]
2
[ [ "find_prime_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6f4cef0297ef376f81f2e4499e40337c6dc9985
94d5915a5450635b7307dc9cec58b7ec9472b92d
v1.0
instruct
Prefill
Prefill_34590_I
Write a python function to produce a list of all 4-characters long strings composed of ['A', 'B', 'C'].
from itertools import product def generate_combinations(chars, length): """ Returns a list of all strings of given length composed of given characters. """ return [''.join(p) for p in product(chars, repeat=length)] def all_4_char_combinations(): """ Returns a list of all 4-characters long stri...
from solution import all_4_char_combinations def test_all_4_char_combinations_length(): result = all_4_char_combinations() assert len(result) == 3**4 # 3 characters, 4 positions def test_all_4_char_combinations_content(): result = all_4_char_combinations() expected_set = set(['AAAA', 'AAAB', 'AAAC', ...
[ { "docstring": "Returns a list of all strings of given length composed of given characters.", "function_declaration": "def generate_combinations(chars, length):", "function_name": "generate_combinations", "parameter_list": "(chars, length)" }, { "docstring": "Returns a list of all 4-characte...
[ 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": "from itertools import product\n\ndef generate_4_char_strings():\n \"\"\"\n Returns a list of all 4-characters long strings composed of characters 'A', 'B', 'C'.\n \"\"\"\n charact...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034590", "row_id": 34590, "seed_ids": "['magpie_prefill_34590']" }
0.592339
Prefill_34590
I
[ "generate_combinations", "all_4_char_combinations" ]
2
[ [ "all_4_char_combinations", "generate_combinations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d5576eda773b85642a0fc63d5882b4fc19c80ed2
ccfc90d5b425b07391037d04cc85f5c14ac74c16
v1.0
instruct
Prefill
Prefill_34819_I
Write a python function to print prime numbers within a given range s and t. The function should consider both inclusive start and end values.
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num == 2 or 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 prime_numbers_in_range def test_primes_in_small_range(): assert prime_numbers_in_range(1, 10) == [2, 3, 5, 7] def test_primes_with_zero_and_negative(): assert prime_numbers_in_range(-10, 10) == [2, 3, 5, 7] def test_primes_in_large_range(): assert prime_numbers_in_range(10, 50) == [1...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers within the given range [s, t].", "function_declaration": "def prime_num...
[ 1, 1, 0, 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 is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00034819", "row_id": 34819, "seed_ids": "['magpie_prefill_34819']" }
0.659871
Prefill_34819
I
[ "is_prime", "prime_numbers_in_range" ]
2
[ [ "prime_numbers_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
098961434518742debad3cb61c75f8c1d233ad1c
e45636fe70b7995f7dd82fba9b3edcf57b39cecd
v1.0
instruct
Prefill
Prefill_34824_I
Write a python function to find all prime numbers within a range given by two integers, `start` and `end`. The function should return a list of all prime numbers in this range, inclusive.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False ...
from solution import find_primes_in_range, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(37) == True assert is_prime(38) == False def test_find_primes_in_range(): assert find_primes...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers within a given range [start, end].", "function_declaration": "def find_...
[ 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_8
{ "original_instruction": "", "prompt_id": "00034824", "row_id": 34824, "seed_ids": "['magpie_prefill_34824']" }
0.612735
Prefill_34824
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
39d0ebbc64913feca5d75e062c25a5bb7599c6fb
5446a2a31043d41bd59edafb853b506012a8c31c
v1.0
instruct
Prefill
Prefill_34918_I
Write a python function to check if a list contains only primes
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 contains_only_primes(lst): """ Returns True if all elements in the list are prime...
from solution import contains_only_primes def test_empty_list(): assert contains_only_primes([]) == True def test_single_element_prime(): assert contains_only_primes([2]) == True assert contains_only_primes([3]) == True assert contains_only_primes([13]) == True def test_single_element_non_prime(): ...
[ { "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 True if all elements in the list are prime numbers, else False.", "function_declaration": "def co...
[ 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_8
{ "original_instruction": "", "prompt_id": "00034918", "row_id": 34918, "seed_ids": "['magpie_prefill_34918']" }
0.72046
Prefill_34918
I
[ "is_prime", "contains_only_primes" ]
2
[ [ "contains_only_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e584be4a25cee08e8c612f5a8542e283878000ea
8a4cc725601169a2ce98e220d853cebaed87f4c4
v1.0
instruct
Prefill
Prefill_34979_I
Write a python function to check if a number is a prime number and then return the list of all prime factors of the number if it is a prime.
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, prime_factors def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False assert is_prime(37) == Tru...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime factors of n if n is a prime number.\nIf n is not a prime number, returns an...
[ 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 a prime number.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if n is a prime number, False o...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00034979", "row_id": 34979, "seed_ids": "['magpie_prefill_34979']" }
0.76184
Prefill_34979
I
[ "is_prime", "prime_factors" ]
2
[ [ "prime_factors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d26f78bd250708bbd542975c9d8dcab97b77fc64
950f18d5b247b8b29e23e83eb978140e486f479f
v1.0
instruct
Prefill
Prefill_35003_I
Write a python function to implement merge sort. Merge sort is a divide-and-conquer algorithm that splits the input array into n subarrays, each containing one element (an array with one element is considered sorted), and then repeatedly merges subarrays to produce new sorted subarrays until there is only one sorted su...
def merge_sort(arr): """ Function to perform merge sort on an array. Parameters: arr (list): List of elements to be sorted. Returns: list: Sorted list. """ if len(arr) <= 1: return arr # Finding the mid of the array mid = len(arr) // 2 # Dividing the elements into...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([6]) == [6] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert merg...
[ { "docstring": "Function to perform merge sort on an array.\n\nParameters:\narr (list): List of elements to be sorted.\n\nReturns:\nlist: Sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Function to mer...
[ 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 Implementation of merge sort algorithm.\n :param arr: List of elements to be sorted.\n :return: Sorted list of elements.\n \"\"\"\n if len(ar...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035003", "row_id": 35003, "seed_ids": "['magpie_prefill_35003']" }
0.695025
Prefill_35003
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
307bab4615b585d2a1b3831a9c1b72517bd2dd1d
0451ce2a8cb283345d03fd917c33331f97d5cd4d
v1.0
instruct
Prefill
Prefill_35088_I
Write a python function to implement K-Nearest Neighbors algorithm. The function should use 1D Euclidean distance as the metric for finding nearest neighbors.
import numpy as np from collections import Counter def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two 1D points. """ return np.abs(point1 - point2) def knn_predict(X_train, y_train, x_test, k): """ Implement K-Nearest Neighbors algorithm. Paramete...
import numpy as np from solution import euclidean_distance, knn_predict def test_euclidean_distance(): assert euclidean_distance(1, 2) == 1 assert euclidean_distance(5, 5) == 0 assert euclidean_distance(-1, 1) == 2 assert euclidean_distance(0, 0) == 0 def test_knn_predict(): X_train = np.array([1,...
[ { "docstring": "Calculate the Euclidean distance between two 1D points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Implement K-Nearest Neighbors algorithm.\n\nParameters:\...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nimport math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Computes the Euclidean distance between two 1D points.\n \"\"\"\n return math.fa...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035088", "row_id": 35088, "seed_ids": "['magpie_prefill_35088']" }
0.679129
Prefill_35088
I
[ "euclidean_distance", "knn_predict" ]
2
[ [ "knn_predict", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
74d670fbfb93cde96677434e088786236edc77ff
812be4507dc263d8bfecc0facc0d42ed5a9bf0c5
v1.0
instruct
Prefill
Prefill_35156_I
Write a python function to sort an array using the radix sort algorithm.
def radix_sort(arr): """ Sorts an array using the radix sort algorithm. """ if len(arr) == 0: return arr # Find the maximum number to decide number of digits max_num = max(arr) # Start with the least significant digit exp = 1 while max_num // exp > 0: counting_s...
from solution import radix_sort def test_radix_sort_empty(): assert radix_sort([]) == [] def test_radix_sort_single_element(): assert radix_sort([5]) == [5] def test_radix_sort_sorted(): assert radix_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_radix_sort_unsorted(): assert radix_sort([4, 2, 9,...
[ { "docstring": "Sorts an array using the radix sort algorithm.", "function_declaration": "def radix_sort(arr):", "function_name": "radix_sort", "parameter_list": "(arr)" }, { "docstring": "A utility function to do counting sort of arr[] according to\nthe digit represented by exp.", "func...
[ 0, 1, 1, 0, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def counting_sort(arr, exp):\n \"\"\"\n A function to do counting sort of arr[] according to\n the digit represented by exp (i.e., the exponent of 10).\n \"\"\"\n n = len(arr)\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00035156", "row_id": 35156, "seed_ids": "['magpie_prefill_35156']" }
0.714641
Prefill_35156
I
[ "radix_sort", "counting_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4875312b8361368bcbab68b4f8a7df0c2f01a832
d1852c08d6ff8c177344ac14ee2caff970684e28
v1.0
instruct
Prefill
Prefill_35256_I
Write a python function to check if a given number is a palindrome in both binary and decimal representation.
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def is_binary_decimal_palindrome(n): """ Check if a given number is a palindrome in both binary and decimal representation. Parameters: n (int): The number to check ...
from solution import is_binary_decimal_palindrome def test_number_9(): assert is_binary_decimal_palindrome(9) == True # 9 is '1001' in binary and both 9 and '1001' are palindromes. def test_number_33(): assert is_binary_decimal_palindrome(33) == True # 33 is '100001' in binary and both 33 and '100001' are p...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if a given number is a palindrome in both binary and decimal representation.\n\nPa...
[ 0, 1, 1, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(value):\n \"\"\"\n Checks if the given value is a palindrome.\n \"\"\"\n value_str = str(value)\n return value_str == value_str[::-1]\n\ndef is_palindrome_bot...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035256", "row_id": 35256, "seed_ids": "['magpie_prefill_35256']" }
0.694104
Prefill_35256
I
[ "is_palindrome", "is_binary_decimal_palindrome" ]
2
[ [ "is_binary_decimal_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
410ff0e8d254b0140a533dbdca3f771672c4882f
792cf95ecfc2677a97e554416a04c18af2dc91d2
v1.0
instruct
Prefill
Prefill_35264_I
Write a python function to find the largest prime number within a given range [m, n] where m and n are both inclusive. If there are no prime numbers in the range, the function should return -1.
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 largest_prime_in_ran...
from solution import largest_prime_in_range def test_prime_within_range(): assert largest_prime_in_range(10, 20) == 19 assert largest_prime_in_range(15, 30) == 29 def test_no_prime_in_range(): assert largest_prime_in_range(14, 16) == -1 assert largest_prime_in_range(0, 1) == -1 def test_entire_ran...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the largest prime number in the range [m, n]. If no primes are found, return -1.", "function_declaration": "def la...
[ 0, 1, 1, 1, 1, 1, 1, 0, 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 if num == 2:\n return True # 2 is the only ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035264", "row_id": 35264, "seed_ids": "['magpie_prefill_35264']" }
0.704255
Prefill_35264
I
[ "is_prime", "largest_prime_in_range" ]
2
[ [ "largest_prime_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b31a08f3c22901944274da945c5972ace9ae911
9fe2b11dc21bcae9b7b61d3cbb9071c9b327b116
v1.0
instruct
Prefill
Prefill_35300_I
Write a python function to search for a key in an in-order traversal result of a binary search tree (BST). The function should return the first occurrence of the key if it exists, and `None` if it doesn't. Assume the BST is not empty.
class TreeNode: def __init__(self, key, left=None, right=None): self.key = key self.left = left self.right = right def inorder_traversal(root, result=None): if result is None: result = [] if root is not None: inorder_traversal(root.left, result) result.a...
from solution import TreeNode, search_in_bst def test_search_existing_key(): # Create a sample BST root = TreeNode(2, TreeNode(1), TreeNode(3)) assert search_in_bst(root, 1) == 1 assert search_in_bst(root, 2) == 2 assert search_in_bst(root, 3) == 3 def test_search_non_existing_key(): # Create ...
[]
[ 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": "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_search(root, key):\n \"\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035300", "row_id": 35300, "seed_ids": "['magpie_prefill_35300']" }
0.52928
Prefill_35300
I
[ "inorder_traversal", "search_in_bst" ]
2
[ [ "search_in_bst", "inorder_traversal" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a52c981c5955adcc14958e13c2a9762e341703aa
ee507f57daf545bf797646a6aaf9372fc19675ad
v1.0
instruct
Prefill
Prefill_35306_I
Write a python function to print the first 10 prime numbers. How can I approach this problem?
def is_prime(num): """ Check if a number is prime. :param num: integer to check :return: True if num is prime, else False """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def first_10_primes(...
from solution import is_prime, first_10_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(-1) == False def test_first_10_primes(): ...
[ { "docstring": "Check if a number is prime.\n\n:param num: integer to check\n:return: True if num is prime, else False", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Print the first 10 prime numbers.", "function_d...
[ 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 first_10_primes():\n \"\"\"\n Returns a list of the first 10 prime numbers.\n \"\"\"\n primes = []\n num = 2 # Start with the first prime number\n \n while len(prime...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00035306", "row_id": 35306, "seed_ids": "['magpie_prefill_35306']" }
0.669955
Prefill_35306
I
[ "is_prime", "first_10_primes" ]
2
[ [ "first_10_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cfc2b8f2cc4c8bd5ef891f94827d416e0ec575e6
d726d7941fa82af3171e5c397d86269f4305cb9d
v1.0
instruct
Prefill
Prefill_35428_I
Write a python function to find the maximum sum of a subarray in a 2D array. You are allowed to move in four directions: up, down, left, and right. The function should take a 2D array of integers as input and return the maximum sum.
def max_sum_subarray_2d(arr): """ Finds the maximum sum of a subarray in a 2D array allowing moves in all four directions. Implementation uses Kadane's Algorithm for 2D arrays. """ if not arr or not arr[0]: return 0 rows = len(arr) cols = len(arr[0]) max_sum = float('-inf') ...
from solution import max_sum_subarray_2d def test_max_sum_subarray_2d_all_positive(): arr = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_sum_subarray_2d(arr) == 45 def test_max_sum_subarray_2d_all_negative(): arr = [ [-1, -2, -3], [-4, -5, -6], [-7, -8...
[ { "docstring": "Finds the maximum sum of a subarray in a 2D array allowing moves in all four directions.\nImplementation uses Kadane's Algorithm for 2D arrays.", "function_declaration": "def max_sum_subarray_2d(arr):", "function_name": "max_sum_subarray_2d", "parameter_list": "(arr)" }, { "d...
[ 0, 0, 0, 0, 1, 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 max_subarray_sum_2d(arr):\n \"\"\"\n Returns maximum sum of a subarray in a 2D array.\n \"\"\"\n if not arr or not arr[0]:\n return 0\n\n def kadane(arr):\n m...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00035428", "row_id": 35428, "seed_ids": "['magpie_prefill_35428']" }
0.659838
Prefill_35428
I
[ "max_sum_subarray_2d", "kadane" ]
2
[ [ "max_sum_subarray_2d", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a932303195aeb8d50d042c94162f1d4aa0ea3fcf
ee7a10a2115bf3283b6c2a9ce426823e5b7a16c7
v1.0
instruct
Prefill
Prefill_35655_I
Write a python function to identify prime numbers in a range of numbers.
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, primes_in_range def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(30) == False assert is_prime(-1) == False assert is_prime(0) == False assert is_prime(1) == F...
[ { "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 a list of prime numbers in the range [start, end] (inclusive).", "function_declaration": "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 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_9
{ "original_instruction": "", "prompt_id": "00035655", "row_id": 35655, "seed_ids": "['magpie_prefill_35655']" }
0.787549
Prefill_35655
I
[ "is_prime", "primes_in_range" ]
2
[ [ "primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e10271069399de76d13e83c1d89c332c97bce8a4
af8f1fd567323d537cc091dd93ddb96479db2376
v1.0
instruct
Prefill
Prefill_35757_I
Write a python function to find all the prime numbers in a given list of numbers.
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_div = int(n ** 0.5) + 1 for i in range(3, max_div, 2): if n % i == 0: return False return...
from solution import find_primes_in_list def test_find_primes_in_list_all_primes(): assert find_primes_in_list([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_find_primes_in_list_no_primes(): assert find_primes_in_list([4, 6, 8, 10, 12]) == [] def test_find_primes_in_list_mixed_numbers(): assert find_prim...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list of numbers.", "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 \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return Fal...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035757", "row_id": 35757, "seed_ids": "['magpie_prefill_35757']" }
0.710168
Prefill_35757
I
[ "is_prime", "find_primes_in_list" ]
2
[ [ "find_primes_in_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e7c8c07c289f8e0dca4a5e089de313d934de1b9
7dfa7f0b699d71e6096b75757b352ea6dacb11c8
v1.0
instruct
Prefill
Prefill_35983_I
Write a python function to partition an array into k subsets such that the maximum sum of any subset is minimum.
def can_partition(nums, k, max_sum): """ Helper function to check if we can partition the nums array into k subsets with each subset sum <= max_sum. """ current_sum = 0 required_subsets = 1 for num in nums: if current_sum + num > max_sum: required_subsets += 1 ...
from solution import min_max_partition_sum def test_partition_single_element(): assert min_max_partition_sum([5], 1) == 5 def test_partition_equal_elements(): assert min_max_partition_sum([5, 5, 5, 5], 2) == 10 def test_partition_varied_elements(): assert min_max_partition_sum([1, 2, 3, 4, 5], 2) == 9 d...
[ { "docstring": "Helper function to check if we can partition the nums array into k subsets\nwith each subset sum <= max_sum.", "function_declaration": "def can_partition(nums, k, max_sum):", "function_name": "can_partition", "parameter_list": "(nums, k, max_sum)" }, { "docstring": "Returns t...
[ 1, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_partition(nums, k, max_sum_limit):\n count = 0\n current_sum = 0\n for num in nums:\n if current_sum + num > max_sum_limit:\n count += 1\n curren...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00035983", "row_id": 35983, "seed_ids": "['magpie_prefill_35983']" }
0.654489
Prefill_35983
I
[ "can_partition", "min_max_partition_sum" ]
2
[ [ "min_max_partition_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4b50a8ecde2dcac0f045656cdabfbbfe760827ad
ccfd6044a040028dceeea6162b2bf95a4f9e446e
v1.0
instruct
Prefill
Prefill_35992_I
Write a python function to create a Binary Search Tree (BST) and perform an InOrder traversal on it. Given a list of integers as input, convert the list into a balanced BST, and then perform an InOrder traversal to print the elements in sorted order.
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def sorted_array_to_bst(arr): if not arr: return None mid = len(arr) // 2 root = TreeNode(arr[mid]) root.left = sorted_array_to_bst(arr[:mid]) root.right = s...
from solution import convert_list_to_bst_and_inorder def test_balanced_bst_inorder(): assert convert_list_to_bst_and_inorder([4, 2, 5, 1, 3]) == [1, 2, 3, 4, 5] def test_empty_list(): assert convert_list_to_bst_and_inorder([]) == [] def test_single_element(): assert convert_list_to_bst_and_inorde...
[]
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n\ndef sorted_array_to_bst(nums):\n if not nums:\n return ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035992", "row_id": 35992, "seed_ids": "['magpie_prefill_35992']" }
0.607174
Prefill_35992
I
[ "sorted_array_to_bst", "inorder_traversal", "convert_list_to_bst_and_inorder" ]
3
[ [ "convert_list_to_bst_and_inorder", "inorder_traversal" ], [ "convert_list_to_bst_and_inorder", "sorted_array_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0b40697bcc20d447cceaabab7b8758d9b730a438
38b10dd76c02447e09ffa9d52ba20e70cb57d6a8
v1.0
instruct
Prefill
Prefill_36267_I
Write a python function to sort a list of integers using the radix sort algorithm. Provide a step-by-step explanation of how the radix sort algorithm works.
def counting_sort(arr, exp): """ A function to perform counting sort on arr based on the digit represented by exp (10^i) """ n = len(arr) output = [0] * n # Output array to store sorted numbers count = [0] * 10 # Count array to store count of occurrences of digits (0 to 9) # Store the cou...
from solution import radix_sort def test_radix_sort_already_sorted(): assert radix_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_radix_sort_reverse_sorted(): assert radix_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_radix_sort_with_duplicates(): assert radix_sort([4, 2, 2, 8, 3, 3, 1]) == [1, 2,...
[ { "docstring": "A function to perform counting sort on arr based on the digit represented by exp (10^i)", "function_declaration": "def counting_sort(arr, exp):", "function_name": "counting_sort", "parameter_list": "(arr, exp)" }, { "docstring": "The function to sort arr[] of size n using Rad...
[ 1, 0, 0, 0, 0, 1, 0, 0, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def counting_sort_for_radix(arr, exp):\n n = len(arr)\n output = [0] * n # Output array to be filled\n count = [0] * 10 # Buckets for each digit (0-9)\n\n # Count occurrences of...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00036267", "row_id": 36267, "seed_ids": "['magpie_prefill_36267']" }
0.639319
Prefill_36267
I
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5be74f86acf7e7e40c3db87d6738ec7cb9715e97
52c0edc74ffcc744e18986d8b869a039be9d67fc
v1.0
instruct
Prefill
Prefill_36551_I
Write a python function to sort a list of integers using the merge sort algorithm. The function should return the sorted list.
def merge_sort(arr): """ Sorts a list of integers using the merge sort algorithm and returns the sorted list. """ if len(arr) <= 1: return arr # Split the list in half mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] # Recursively sort each half left...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert merg...
[ { "docstring": "Sorts a list of integers using the merge sort algorithm and returns the sorted list.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_dec...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list of integers using the merge sort algorithm and returns the sorted list.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00036551", "row_id": 36551, "seed_ids": "['magpie_prefill_36551']" }
0.678456
Prefill_36551
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a2e7ab2b77d0cfe2cef48d1b84aadbaa11ebaf5
236c621f7556000b49ff77f6b6979f53c4633ddc
v1.0
instruct
Prefill
Prefill_36669_I
Write a python function to generate a list of all prime numbers between two given numbers (both inclusive). The function should be optimized for large numbers.
import math 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 generate_primes_between(a, b)...
from solution import generate_primes_between def test_primes_between_1_and_10(): assert generate_primes_between(1, 10) == [2, 3, 5, 7] def test_primes_between_10_and_20(): assert generate_primes_between(10, 20) == [11, 13, 17, 19] def test_primes_between_50_and_60(): assert generate_primes_between(50, 60...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers between a and b (both inclusive).", "function_declaration": "def generate_primes_between(a, b):", "function_nam...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_primes(start, end):\n \"\"\"\n Returns a list of all prime numbers between start and end (both inclusive).\n \"\"\"\n if start > end:\n return []\n \n # ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00036669", "row_id": 36669, "seed_ids": "['magpie_prefill_36669']" }
0.630368
Prefill_36669
I
[ "is_prime", "generate_primes_between" ]
2
[ [ "generate_primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a81fd832b043f94c4eb9e3a0c103d84dab66037
899c94b6bf2a4bbd7bb92a20014d4d711819514c
v1.0
instruct
Prefill
Prefill_36777_I
Write a python function to find the largest prime number less than n that is also a palindrome.
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is...
from solution import is_prime, is_palindrome, largest_prime_palindrome 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(11) assert not is_prime(15) def test_is_palindrome(): assert is_palindrome(1) assert is_palind...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", ...
[ 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036777", "row_id": 36777, "seed_ids": "['magpie_prefill_36777']" }
0.725406
Prefill_36777
I
[ "is_prime", "is_palindrome", "largest_prime_palindrome" ]
3
[ [ "largest_prime_palindrome", "is_palindrome" ], [ "largest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2df79f7045659bf792f0cbbf0f49de423eda9fe3
5c6ad0290e0724ec3d0e422506e7c1dc9c7ea11a
v1.0
instruct
Prefill
Prefill_36881_I
Write a python function to reverse a stack using recursion. The function should take a stack as input and return the reversed stack without using any additional data structures like lists or arrays.
def reverse_stack(stack): """ Reverses a stack using recursion. Parameters: stack (list): A list representing a stack where the last element is the top. Returns: list: The reversed stack. """ if len(stack) == 0: return [] # Pop the top element top = stack.p...
from solution import reverse_stack def test_reverse_stack_empty(): assert reverse_stack([]) == [] def test_reverse_stack_single_element(): assert reverse_stack([1]) == [1] def test_reverse_stack_two_elements(): assert reverse_stack([1, 2]) == [2, 1] def test_reverse_stack_multiple_elements(): assert...
[ { "docstring": "Reverses a stack using recursion.\n\nParameters:\nstack (list): A list representing a stack where the last element is the top.\n\nReturns:\nlist: The reversed stack.", "function_declaration": "def reverse_stack(stack):", "function_name": "reverse_stack", "parameter_list": "(stack)" ...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
8
easy
0.889
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_stack(stack):\n \"\"\"\n Reverses a stack using recursion.\n \n :param stack: list, a stack to be reversed\n :return: reversed stack\n \"\"\"\n if not stack:\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00036881", "row_id": 36881, "seed_ids": "['magpie_prefill_36881']" }
0.551694
Prefill_36881
I
[ "reverse_stack", "insert_at_bottom" ]
2
[ [ "reverse_stack", "insert_at_bottom" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b70a2446fda982f043a30319072df760f39b234
c01bf2dcc89fd682484a4a4fc2bacf5fc998250f
v1.0
instruct
Prefill
Prefill_37093_I
Write a python function to return the value of nCr % P, where nCr is 'n choose r' and P is a prime number. The function should efficiently handle large values of n, r, and P up to 10^6, 10^6, and 10^9+7 respectively.
def mod_inverse(a, P): """ Returns the modular inverse of a under modulo P using Fermat's Little Theorem. P must be a prime number. """ return pow(a, P - 2, P) def nCr_mod_P(n, r, P): """ Returns the value of nCr % P, where nCr is 'n choose r' and P is a prime number. """ if r > n:...
from solution import nCr_mod_P def test_nCr_mod_P_small_numbers(): P = 1000000007 assert nCr_mod_P(5, 2, P) == 10 assert nCr_mod_P(5, 0, P) == 1 assert nCr_mod_P(5, 5, P) == 1 assert nCr_mod_P(6, 3, P) == 20 def test_nCr_mod_P_large_numbers(): P = 1000000007 assert nCr_mod_P(10**6, 500000,...
[ { "docstring": "Returns the modular inverse of a under modulo P using Fermat's Little Theorem.\nP must be a prime number.", "function_declaration": "def mod_inverse(a, P):", "function_name": "mod_inverse", "parameter_list": "(a, P)" }, { "docstring": "Returns the value of nCr % P, where nCr ...
[ 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 mod_inverse(x, p):\n \"\"\"\n Calculate modular multiplicative inverse of x under modulo p using\n Fermat's little theorem.\n \"\"\"\n return pow(x, p - 2, p)\n\ndef nCr_mo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037093", "row_id": 37093, "seed_ids": "['magpie_prefill_37093']" }
0.750361
Prefill_37093
I
[ "mod_inverse", "nCr_mod_P" ]
2
[ [ "nCr_mod_P", "mod_inverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78afb32d9a67b994906bf8b7d1f8c322b2590e7a
37c59002a03407b425bd2c9ce0560e49341c7311
v1.0
instruct
Prefill
Prefill_37101_I
Write a python function to encrypt and decrypt a message using the Caesar Cipher.
def caesar_cipher_encrypt(plain_text, shift): """ Encrypts the plain_text using Caesar Cipher with the given shift. """ encrypted_text = [] for char in plain_text: if char.isalpha(): shift_base = 65 if char.isupper() else 97 encrypted_text.append(chr((ord(char) - shif...
from solution import caesar_cipher_encrypt, caesar_cipher_decrypt def test_caesar_cipher_encrypt_lowercase(): assert caesar_cipher_encrypt("hello", 3) == "khoor" def test_caesar_cipher_encrypt_uppercase(): assert caesar_cipher_encrypt("HELLO", 3) == "KHOOR" def test_caesar_cipher_encrypt_mixed_case(): as...
[ { "docstring": "Encrypts the plain_text using Caesar Cipher with the given shift.", "function_declaration": "def caesar_cipher_encrypt(plain_text, shift):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(plain_text, shift)" }, { "docstring": "Decrypts the cipher_text using Cae...
[ 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 caesar_cipher_encrypt(message, shift):\n \"\"\"\n Encrypts the message using Caesar Cipher with the given shift.\n \"\"\"\n encrypted_message = \"\"\n for char in message:\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037101", "row_id": 37101, "seed_ids": "['magpie_prefill_37101']" }
0.679473
Prefill_37101
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt" ]
2
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac9d247c8c145959d104f8c5ccb07782d7f6b4d7
f4ba57cd27d6ba7a44259d65eab47c21f73f66f5
v1.0
instruct
Prefill
Prefill_37181_I
Write a python function to generate a list of prime numbers between two given numbers a and b. The function should return the list of prime numbers in increasing order.
def is_prime(n): """ Helper function to determine if n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def primes_...
from solution import is_prime, primes_between def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_primes_between_10_and_30(): assert primes_between(10, 30) == [11, 13, 17, 19, 2...
[ { "docstring": "Helper function to determine if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list of prime numbers between a and b (inclusive).", "function_declaration": "def 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 \"\"\" 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_9
{ "original_instruction": "", "prompt_id": "00037181", "row_id": 37181, "seed_ids": "['magpie_prefill_37181']" }
0.629798
Prefill_37181
I
[ "is_prime", "primes_between" ]
2
[ [ "primes_between", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc974d6274f9d71b7bd18209bc63b38b7b5fda46
a003141c300d713b35136f2196dc83da497b331c
v1.0
instruct
Prefill
Prefill_37234_I
Write a python function to convert a list of integers to their corresponding roman numerals. The function should handle numbers from 1 to 3999.
def int_to_roman(num): """ Convert an integer to a Roman numeral. Only handles numbers from 1 to 3999. """ val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] syms = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX"...
from solution import list_to_roman def test_list_to_roman_single_element(): assert list_to_roman([1]) == ["I"] assert list_to_roman([3999]) == ["MMMCMXCIX"] def test_list_to_roman_multiple_elements(): assert list_to_roman([1, 2, 3]) == ["I", "II", "III"] assert list_to_roman([4, 5, 6]) == ["IV", "...
[ { "docstring": "Convert an integer to a Roman numeral.\nOnly handles numbers from 1 to 3999.", "function_declaration": "def int_to_roman(num):", "function_name": "int_to_roman", "parameter_list": "(num)" }, { "docstring": "Convert a list of integers to their corresponding Roman numerals.\nHa...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_roman(num):\n \"\"\"\n Convert an integer to a Roman numeral.\n \"\"\"\n val = [\n 1000, 900, 500, 400,\n 100, 90, 50, 40,\n 10, 9, 5, 4,\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037234", "row_id": 37234, "seed_ids": "['magpie_prefill_37234']" }
0.707147
Prefill_37234
I
[ "int_to_roman", "list_to_roman" ]
2
[ [ "list_to_roman", "int_to_roman" ] ]
1
[]
false
[]
false
pytest
true
[]
true
682fd248acb70eae336fcc05af94bd79cbe6b5ac
3cc3107a991013331418749512c60b79f79686b8
v1.0
instruct
Prefill
Prefill_37327_I
Write a python function to generate the first 100 Fibonacci numbers using recursion. The function should return a list of the numbers.
def fibonacci(n, computed={0: 0, 1: 1}): """ Returns the n-th Fibonacci number using memoization to optimize recursive calls. """ if n not in computed: computed[n] = fibonacci(n - 1, computed) + fibonacci(n - 2, computed) return computed[n] def generate_fibonacci_numbers(count): """ ...
from solution import generate_fibonacci_numbers def test_generate_fibonacci_first_ten(): expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] assert generate_fibonacci_numbers(10) == expected def test_generate_fibonacci_first_twenty(): expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...
[ { "docstring": "Returns the n-th Fibonacci number using memoization to optimize recursive calls.", "function_declaration": "def fibonacci(n, computed={0: 0, 1: 1}):", "function_name": "fibonacci", "parameter_list": "(n, computed={0: 0, 1: 1})" }, { "docstring": "Generates the first 'count' F...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_recursive(n, computed={0: 0, 1: 1}):\n \"\"\"\n Returns the nth Fibonacci number using recursion with memoization.\n \"\"\"\n if n not in computed:\n computed...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037327", "row_id": 37327, "seed_ids": "['magpie_prefill_37327']" }
0.695478
Prefill_37327
I
[ "fibonacci", "generate_fibonacci_numbers" ]
2
[ [ "generate_fibonacci_numbers", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75d768f11f761be2f43665e4b75f74b049078255
0192ad18f29f19ee84bd8070f1569f20fa902bec
v1.0
instruct
Prefill
Prefill_37352_I
Write a python function to convert a string to a binary tree. Each character in the string will correspond to a node in the binary tree. The function should create a binary tree, with each node having a value corresponding to the ASCII value of the character, and left and right children corresponding to the binary repr...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def char_to_binary_tree(char): """ Converts a character to a binary tree, where each node has a value corresponding to the binary representation of the ASCII val...
from solution import TreeNode, string_to_binary_tree, char_to_binary_tree def node_to_list(node): """ Helper function to convert binary tree to list for easier testing """ if node is None: return [] result = [] while node: result.append(node.val) node = node.right return res...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef string_to_binary_tree(s):\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00037352", "row_id": 37352, "seed_ids": "['magpie_prefill_37352']" }
0.65018
Prefill_37352
I
[ "char_to_binary_tree", "string_to_binary_tree" ]
2
[ [ "string_to_binary_tree", "char_to_binary_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
94219f868fcecdddb32c4bcef91faa0dfc9a4d0b
d91546fcfb3b65317b830d7718513dcddcb18fc7
v1.0
instruct
Prefill
Prefill_37411_I
Write a python function to find the intersection of twosorted arrays A and B, and return the result as an array called C. The arrays A and B may contain duplicate elements. The function should have a time complexity of O(log n + log m), where n and m are the lengths of arrays A and B, respectively.
def binary_search(arr, target): """ Perform binary search to find the target in a sorted array. """ left, right = 0, len(arr) - 1 while left <= right: mid = left + (right - left) // 2 if arr[mid] == target: return True elif arr[mid] < target: left = mi...
def test_intersection_basic(): A = [1, 2, 2, 3, 4] B = [2, 2, 3, 5] C = intersection_of_sorted_arrays(A, B) assert C == [2, 3] def test_intersection_no_duplicates_in_result(): A = [1, 2, 3, 3, 5, 5, 6] B = [3, 3, 4, 5, 5, 7] C = intersection_of_sorted_arrays(A, B) assert C == [3, 5] de...
[ { "docstring": "Perform binary search to find the target in a sorted array.", "function_declaration": "def binary_search(arr, target):", "function_name": "binary_search", "parameter_list": "(arr, target)" }, { "docstring": "Find the intersection of two sorted arrays A and B.", "function_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(arr, x):\n \"\"\"\n Helper function to perform binary search in a sorted array 'arr'\n to find element 'x'. Returns the index if element is found, else -1.\n \"\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037411", "row_id": 37411, "seed_ids": "['magpie_prefill_37411']" }
0.604787
Prefill_37411
I
[ "binary_search", "intersection_of_sorted_arrays" ]
2
[ [ "intersection_of_sorted_arrays", "binary_search" ] ]
1
[]
false
[]
false
pytest
false
[]
true
eb03e859df273484e37e273406b02803ac4d6e22
265da7a962971aa9237c3fd85814cbea860295e6
v1.0
instruct
Prefill
Prefill_37547_I
Write a python function to find the maximum area of a triangle formed by connecting any three points from a given list of points.
from itertools import combinations def triangle_area(p1, p2, p3): """ Returns the area of a triangle given its vertex points p1, p2, p3 using the Shoelace formula. p1, p2, p3 are tuples of the form (x, y). """ x1, y1 = p1 x2, y2 = p2 x3, y3 = p3 return 0.5 * abs(x1*(y2 - y3) + x2*(y3 - ...
from solution import max_triangle_area def test_max_triangle_area(): points = [(0, 0), (0, 3), (4, 0), (1, 1)] assert max_triangle_area(points) == 6.0 def test_no_valid_triangle(): points = [(0, 0), (1, 0), (2, 0)] assert max_triangle_area(points) == 0.0 def test_single_point_multiple_times(): po...
[ { "docstring": "Returns the area of a triangle given its vertex points p1, p2, p3 using the Shoelace formula.\np1, p2, p3 are tuples of the form (x, y).", "function_declaration": "def triangle_area(p1, p2, p3):", "function_name": "triangle_area", "parameter_list": "(p1, p2, p3)" }, { "docstr...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef max_area_of_triangle(points):\n \"\"\"\n Returns the maximum area of a triangle formed by any three points from the list.\n \"\"\"\n def ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037547", "row_id": 37547, "seed_ids": "['magpie_prefill_37547']" }
0.666365
Prefill_37547
I
[ "triangle_area", "max_triangle_area" ]
2
[ [ "max_triangle_area", "triangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0ea3e18e396a9e0ac833de39dbcd1f877fc9fb21
ae7aa4d6c45fd50b2a3328325f0474cb72e47bd0
v1.0
instruct
Prefill
Prefill_37581_I
Write a python function to filter and return prime numbers from a given list of integers. The function should take a single parameter which is the list of integers. It should return a list containing only the prime numbers from the input list.
def is_prime(num): """ Checks 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 filter_primes(numbers): """ Filters and returns the prime numbers from a given list of inte...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 9, 10]) == [] def test_filter_primes_mixed_numbers(): assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 1...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Filters and returns the prime numbers from a given list of integers.", "function_declaration": "def filter_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 n is a prime number.\n Returns True if n is prime, else False.\n \"\"\"\n if n <= 1:\n return False\n if n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037581", "row_id": 37581, "seed_ids": "['magpie_prefill_37581']" }
0.62388
Prefill_37581
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aca41a26ae4713d4f8e3fe68068b703ba0d1da6d
1cdca9f05521962c30299c1b4de975f55129e010
v1.0
instruct
Prefill
Prefill_37658_I
Write a python function to encode a string with a given Caesar cipher and decrypt the same using the same cipher.
def caesar_cipher_encode(text, shift): """ Encodes the given text using Caesar cipher with the given shift. """ result = "" for char in text: if char.isalpha(): shift_base = ord('A') if char.isupper() else ord('a') result += chr((ord(char) - shift_base + shift) % 26 +...
from solution import caesar_cipher_encode, caesar_cipher_decode def test_caesar_cipher_encode_simple(): assert caesar_cipher_encode('abc', 3) == 'def' def test_caesar_cipher_encode_wrap_around(): assert caesar_cipher_encode('xyz', 3) == 'abc' def test_caesar_cipher_encode_with_capitals(): assert caesar_c...
[ { "docstring": "Encodes the given text using Caesar cipher with the given shift.", "function_declaration": "def caesar_cipher_encode(text, shift):", "function_name": "caesar_cipher_encode", "parameter_list": "(text, shift)" }, { "docstring": "Decodes the encoded text using Caesar cipher with...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_encode(s, shift):\n \"\"\"\n Encodes a string using the Caesar cipher with a given shift.\n \n :param s: The input string to encode\n :param shift: The number...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037658", "row_id": 37658, "seed_ids": "['magpie_prefill_37658']" }
0.690357
Prefill_37658
I
[ "caesar_cipher_encode", "caesar_cipher_decode" ]
2
[ [ "caesar_cipher_decode", "caesar_cipher_encode" ] ]
1
[]
false
[]
false
pytest
true
[]
true
02e4cc9f860efd4703d96261b228c0db14279f72
308f1583418dcd806d13406767acd2db74f11bdb
v1.0
instruct
Prefill
Prefill_37694_I
Write a python function to find the smallest positive integer that is evenly divisible by all the numbers from 1 to 20.
from math import gcd def lcm(a, b): """ Return the least common multiple of a and b. """ return a * b // gcd(a, b) def smallest_multiple(n): """ Returns the smallest positive integer that is evenly divisible by all the numbers from 1 to n. """ multiple = 1 for i in range(1, n + 1):...
from solution import smallest_multiple, smallest_multiple_1_to_20 def test_smallest_multiple_1_to_10(): assert smallest_multiple(10) == 2520 def test_smallest_multiple_1_to_20(): assert smallest_multiple_1_to_20() == 232792560 def test_smallest_multiple_1_to_1(): assert smallest_multiple(1) == 1 def tes...
[ { "docstring": "Return 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 integer that is evenly divisible by all the numbers from 1 to n.", "function_declar...
[ 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 return abs(a * b) // math.gcd(a, b)\n\ndef smallest_multiple(n):\n multiple = 1\n for i in range(1, n + 1):\n multiple = lcm(multiple, i)\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037694", "row_id": 37694, "seed_ids": "['magpie_prefill_37694']" }
0.643989
Prefill_37694
I
[ "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
e1a7641e98bc70677425316f004f6fc1d399b823
aca2e8d185f08b85147f32ef77459e7358b1fa92
v1.0
instruct
Prefill
Prefill_37788_I
Write a python function to find all Armstrong numbers between 100 and 999.
def is_armstrong_number(number): """ Checks if a given number is an Armstrong number. An Armstrong number (also called a narcissistic number) is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For a 3-digit number abc, it is an Armstrong number if a^...
from solution import is_armstrong_number, find_armstrong_numbers def test_is_armstrong_number(): assert is_armstrong_number(153) == True assert is_armstrong_number(370) == True assert is_armstrong_number(371) == True assert is_armstrong_number(407) == True assert is_armstrong_number(100) == False ...
[ { "docstring": "Checks if a given number is an Armstrong number.\nAn Armstrong number (also called a narcissistic number) is a number that is equal to the sum of its own digits each raised to the power of the number of digits.\nFor a 3-digit number abc, it is an Armstrong number if a^3 + b^3 + c^3 == abc.", ...
[ 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_armstrong_numbers():\n \"\"\"\n Returns a list of all Armstrong numbers between 100 and 999.\n \"\"\"\n armstrong_numbers = []\n for num in range(100, 1000):\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00037788", "row_id": 37788, "seed_ids": "['magpie_prefill_37788']" }
0.580312
Prefill_37788
I
[ "is_armstrong_number", "find_armstrong_numbers" ]
2
[ [ "find_armstrong_numbers", "is_armstrong_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8194caf03dfdd12b7594fe25437c0b046464832b
f419d7cde9186ab404f20216ad8345c963627933
v1.0
instruct
Prefill
Prefill_37952_I
Write a python function to find the number of ways to represent a given number as a sum of positive integers where each number in the sum must be a prime number.
def primes_up_to(n): """ Helper function to generate a list of primes up to n (inclusive). """ if n < 2: return [] sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for start in range(2, int(n**0.5) + 1): if sieve[start]: for i in range(start*start, n + 1, star...
from solution import count_prime_sum_ways def test_count_prime_sum_ways_0(): assert count_prime_sum_ways(0) == 1 def test_count_prime_sum_ways_2(): assert count_prime_sum_ways(2) == 1 # 2 def test_count_prime_sum_ways_3(): assert count_prime_sum_ways(3) == 1 # 3 def test_count_prime_sum_ways_4(): ...
[ { "docstring": "Helper function to generate a list of primes up to n (inclusive).", "function_declaration": "def primes_up_to(n):", "function_name": "primes_up_to", "parameter_list": "(n)" }, { "docstring": "Returns the number of ways to represent the given number 'n'\nas a sum of positive i...
[ 0, 0, 1, 1, 1, 0, 0, 1, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_prime_sums(n):\n \"\"\"\n Returns the number of ways to represent the given number n as a sum of positive prime integers.\n \"\"\"\n def sieve(limit):\n is_prime ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00037952", "row_id": 37952, "seed_ids": "['magpie_prefill_37952']" }
0.663072
Prefill_37952
I
[ "primes_up_to", "count_prime_sum_ways" ]
2
[ [ "count_prime_sum_ways", "primes_up_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
147b39f927d6cb12d3e4558c622275d3a9e61591
f40e800fe776cd7c6b932096bb7718922695584c
v1.0
instruct
Prefill
Prefill_38085_I
Write a python function to generate all unique subsets of a given list. The function should not contain duplicate subsets in the output.
def unique_subsets(nums): """ Generates all unique subsets of the given list. """ nums.sort() subsets = [] backtrack(nums, 0, [], subsets) return subsets def backtrack(nums, index, path, res): res.append(path) for i in range(index, len(nums)): if i > index and nums[i] == num...
from solution import unique_subsets def test_unique_subsets_empty(): assert unique_subsets([]) == [[]] def test_unique_subsets_single_element(): assert unique_subsets([1]) == [[], [1]] def test_unique_subsets_two_elements(): assert unique_subsets([1, 2]) == [[], [1], [1, 2], [2]] def test_unique_subsets...
[ { "docstring": "Generates all unique subsets of the given list.", "function_declaration": "def unique_subsets(nums):", "function_name": "unique_subsets", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def backtrack(nums, index, path, res):", "function_nam...
[ 0, 0, 1, 1, 1, 1, 1, 1, 1 ]
7
easy
0.778
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef unique_subsets(nums):\n \"\"\"\n Generates all unique subsets of a given list.\n \"\"\"\n nums = sorted(nums)\n subsets = set()\n\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00038085", "row_id": 38085, "seed_ids": "['magpie_prefill_38085']" }
0.652319
Prefill_38085
I
[ "unique_subsets", "backtrack" ]
2
[ [ "unique_subsets", "backtrack" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2512792ca5b9cd89c56b1b3fa66471a782dd1667
3979154d307913127224c04b45ea0c46f25747d9
v1.0
instruct
Prefill
Prefill_38136_I
Write a python function to find all the prime numbers within a given range [start, end].
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import find_primes_in_range def test_find_primes_in_range_start_greater_than_end(): assert find_primes_in_range(10, 5) == [] def test_find_primes_in_range_no_primes(): assert find_primes_in_range(14, 16) == [] def test_find_primes_in_range_one_prime(): assert find_primes_in_range(10, 11) ==...
[ { "docstring": "Checks 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 within the range [start, end].", "function_declaration": "def find_primes_in_range(star...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 =...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038136", "row_id": 38136, "seed_ids": "['magpie_prefill_38136']" }
0.714663
Prefill_38136
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e3d953ff7dc4c6bc58872ad50b7379949882f83b
ce429c9184f56c353f2a41eff216afe28139ea1b
v1.0
instruct
Prefill
Prefill_38168_I
Write a python function to find all the prime numbers from 100 to 200.
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def primes_between_100_and_200(): """ Finds all the prime numbers between 100 and 200. """ prime...
from solution import is_prime, primes_between_100_and_200 def test_is_prime(): assert is_prime(101) == True assert is_prime(102) == False assert is_prime(103) == True assert is_prime(104) == False assert is_prime(2) == True assert is_prime(1) == False def test_primes_between_100_and_200(): ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds all the prime numbers between 100 and 200.", "function_declaration": "def primes_between_100_and_200():", "function_...
[ 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 find_primes_100_to_200():\n \"\"\"\n Returns a list of prime numbers from 100 to 200.\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return False\n if n <...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00038168", "row_id": 38168, "seed_ids": "['magpie_prefill_38168']" }
0.683706
Prefill_38168
I
[ "is_prime", "primes_between_100_and_200" ]
2
[ [ "primes_between_100_and_200", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
80f2e20871c5b431da24c160f4095b5fe3a12e29
d5d8ee81b4cabc422ddc3e5cb6bc7bf49f2f2c24
v1.0
instruct
Prefill
Prefill_38183_I
Write a python function to return the number of substrings of a string that will form a palindrome when reversed and unpalindrome when not reversed. Let's call a function `count_palindrome_substrings(s)` where `s` is the input string. The function should return the count of such substrings.
def is_palindrome(s): """ Checks if a given string s is a palindrome. """ return s == s[::-1] def count_palindrome_substrings(s): """ Returns the number of substrings of s that are palindromes. """ n = len(s) count = 0 for i in range(n): for j in range(i+1, n+1): ...
from solution import count_palindrome_substrings def test_single_character(): assert count_palindrome_substrings("a") == 1 assert count_palindrome_substrings("b") == 1 def test_double_character(): assert count_palindrome_substrings("aa") == 3 assert count_palindrome_substrings("ab") == 2 def test_mul...
[ { "docstring": "Checks if a given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the number of substrings of s that are palindromes.", "function_declaration": "def count_pal...
[ 0, 0, 0, 1, 1, 1, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef count_palindrome_substrings(s):\n \"\"\"\n Retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038183", "row_id": 38183, "seed_ids": "['magpie_prefill_38183']" }
0.687804
Prefill_38183
I
[ "is_palindrome", "count_palindrome_substrings" ]
2
[ [ "count_palindrome_substrings", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
074f3bf3041d0579c1e686a2a15c3230b2d035d5
e4bfc0fe02aa8a432a6744f1fa68bf5085ed2cff
v1.0
instruct
Prefill
Prefill_38304_I
Write a python function to find the smallest number that is evenly divisible by all numbers in a given range.
from math import gcd from functools import reduce def lcm(a, b): return abs(a * b) // gcd(a, b) def smallest_multiple(n): """ Returns the smallest multiple that is evenly divisible by all numbers from 1 to n. """ return reduce(lcm, range(1, n + 1))
from solution import smallest_multiple def test_smallest_multiple_1(): assert smallest_multiple(1) == 1 def test_smallest_multiple_2(): assert smallest_multiple(2) == 2 def test_smallest_multiple_3(): assert smallest_multiple(3) == 6 def test_smallest_multiple_4(): assert smallest_multiple(4) == 12 ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest multiple that is evenly divisible by all numbers from 1 to n.", "function_declaration": "def smallest_multiple(n):", "function_nam...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a * b // math.gcd(a, b)\n\ndef smallest_multiple(n):\n \"\"\"\n Retu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038304", "row_id": 38304, "seed_ids": "['magpie_prefill_38304']" }
0.698053
Prefill_38304
I
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7ed6a92e9d1665e83d2c77eb7714b464587570e
6fa1632e37cce93bc6eb4b8b07715a96d52a86f0
v1.0
instruct
Prefill
Prefill_38482_I
Write a python function to get all prime numbers in a range. The function will take two arguments: start and end. It should return a list of all prime numbers within that range, inclusive. Follow Python conventions for function and variable names. Additionally, comment your code to explain what each part does, using th...
def is_prime(num): """ Helper function to check if a number is prime. Returns True if num is a prime number, else False. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def get_primes_in_range(start, e...
from solution import get_primes_in_range def test_primes_in_small_range(): assert get_primes_in_range(1, 10) == [2, 3, 5, 7] def test_primes_in_large_range(): assert get_primes_in_range(10, 20) == [11, 13, 17, 19] def test_primes_with_no_primes(): assert get_primes_in_range(14, 16) == [] def test_primes...
[ { "docstring": "Helper function to check if a number is prime.\nReturns True if num is a prime number, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers in the range [start...
[ 0, 1, 1, 1, 0, 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 get_primes_in_range(start, end):\n \"\"\"\n Returns a list of all prime numbers within the range [start, end], inclusive.\n \"\"\"\n def is_prime(n):\n /// Helper funct...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00038482", "row_id": 38482, "seed_ids": "['magpie_prefill_38482']" }
0.641696
Prefill_38482
I
[ "is_prime", "get_primes_in_range" ]
2
[ [ "get_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5e818e90f574041f9ff3efdd2c167fdb8babba49
ea10dacbcdb9dcc25beee048d75bfe260cf5c37e
v1.0
instruct
Prefill
Prefill_38541_I
Write a python function to calculate the nth Fibonacci number using the matrix exponentiation method. Matrix exponentiation provides an efficient way to compute Fibonacci numbers with a time complexity of O(log(n)).
def matrix_mult(A, B): """ Multiplies two 2x2 matrices A and B. """ return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]] def matrix_pow(M, n): """ Raises matrix M to th...
from solution import fibonacci def test_fibonacci_0(): assert fibonacci(0) == 0 def test_fibonacci_1(): assert fibonacci(1) == 1 def test_fibonacci_2(): assert fibonacci(2) == 1 def test_fibonacci_3(): assert fibonacci(3) == 2 def test_fibonacci_10(): assert fibonacci(10) == 55 def test_fibona...
[ { "docstring": "Multiplies two 2x2 matrices A and B.", "function_declaration": "def matrix_mult(A, B):", "function_name": "matrix_mult", "parameter_list": "(A, B)" }, { "docstring": "Raises matrix M to the power of n using binary exponentiation.", "function_declaration": "def matrix_pow(...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_mult(A, B):\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],\n [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038541", "row_id": 38541, "seed_ids": "['magpie_prefill_38541']" }
0.706708
Prefill_38541
I
[ "matrix_mult", "matrix_pow", "fibonacci" ]
3
[ [ "fibonacci", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b16e33760c1e7653217f310820388d96ee6c0eab
6fabfaa9adc694e93772c17228db06bcd721d8ea
v1.0
instruct
Prefill
Prefill_38549_I
Write a python function to generate a list of prime numbers between two given numbers (inclusive).
def is_prime(n): """ Checks if a number is prime. Parameters: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False ...
from solution import generate_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(0) == False assert is_prime(1) == False def test_generate_primes_general_case(): assert generate_...
[ { "docstring": "Checks if a number is prime.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a list o...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00038549", "row_id": 38549, "seed_ids": "['magpie_prefill_38549']" }
0.70254
Prefill_38549
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a968256ecff9dcf3633010c2fbf60e9fbf23337a
de21e8a31be29cf21dd950794c2a87da254ed7c8
v1.0
instruct
Prefill
Prefill_38628_I
Write a python function to return the sum of squares of all prime numbers in a given list of integers.
import math def is_prime(n): """ Check if n is a prime number. """ if n <= 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def sum_of_squares_of_primes(numbers): """ Returns the sum of squares of all prime nu...
from solution import sum_of_squares_of_primes def test_sum_of_squares_of_primes_only_primes(): assert sum_of_squares_of_primes([2, 3, 5, 7]) == 4 + 9 + 25 + 49 def test_sum_of_squares_of_primes_mixed_numbers(): assert sum_of_squares_of_primes([2, 4, 6, 7]) == 4 + 49 def test_sum_of_squares_of_primes_no_prime...
[ { "docstring": "Check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of squares of all prime numbers in the given list of integers.", "function_declaration": "def sum_of_squares...
[ 0, 1, 1, 0, 1, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <= n:\n if n % p == 0:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038628", "row_id": 38628, "seed_ids": "['magpie_prefill_38628']" }
0.730136
Prefill_38628
I
[ "is_prime", "sum_of_squares_of_primes" ]
2
[ [ "sum_of_squares_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a547ebd8eca973dff042ebbd4eef557180b5a7ec
86cae088fc2f62c64eb2871ed2a9ee0e5315cf81
v1.0
instruct
Prefill
Prefill_38742_I
Write a python function to print "Hello, World!" and then call a second function from the first function that prints "Goodbye, World!".
def print_hello(): """ Prints 'Hello, World!' and calls the print_goodbye function. """ print("Hello, World!") print_goodbye() def print_goodbye(): """ Prints 'Goodbye, World!'. """ print("Goodbye, World!")
from solution import print_hello, print_goodbye from io import StringIO import sys def test_print_hello(): captured_output = StringIO() # Create StringIO object to capture the output sys.stdout = captured_output # Redirect stdout to the StringIO object print_hello() sys.stdout = sys.__stdout__ # Re...
[ { "docstring": "Prints 'Hello, World!' and calls the print_goodbye function.", "function_declaration": "def print_hello():", "function_name": "print_hello", "parameter_list": "()" }, { "docstring": "Prints 'Goodbye, World!'.", "function_declaration": "def print_goodbye():", "function...
[ 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 print_hello_world():\n \"\"\"\n Prints 'Hello, World!' and then calls print_goodbye_world.\n \"\"\"\n print(\"Hello, World!\")\n print_goodbye_world()\n\ndef print_goodbye_...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038742", "row_id": 38742, "seed_ids": "['magpie_prefill_38742']" }
0.494369
Prefill_38742
I
[ "print_hello", "print_goodbye" ]
2
[ [ "print_hello", "print_goodbye" ] ]
1
[]
false
[]
false
pytest
true
[]
true
55dea38c4809e905331c4a2f40e5f91a5e27244c
1347b2bd05e3432566461c35b35cdb6c73f44908
v1.0
instruct
Prefill
Prefill_38842_I
Write a python function to identify if a given binary tree is Symmetric (mirrored symmetry).
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_mirror(left, right): if left is None and right is None: return True if left is None or right is None: return False return (left.val == righ...
from solution import TreeNode, is_symmetric def test_symmetric_tree(): node = TreeNode(1) node.left = TreeNode(2) node.right = TreeNode(2) node.left.left = TreeNode(3) node.left.right = TreeNode(4) node.right.left = TreeNode(4) node.right.right = TreeNode(3) assert is_symmetric(node) ==...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_symmetric(root):\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00038842", "row_id": 38842, "seed_ids": "['magpie_prefill_38842']" }
0.708381
Prefill_38842
I
[ "is_mirror", "is_symmetric" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
211ddc3319948cc0df0f08118caf426f7f38c8df
da108d6c4e378bf22b755b6b11a7cf4f3be558ec
v1.0
instruct
Prefill
Prefill_39015_I
Write a python function to find the smallest number that is evenly divisible by all numbers from 1 to n. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
def gcd(a, b): """ Calculate the Greatest Common Divisor of a and b. """ while b: a, b = b, a % b return a def lcm(a, b): """ Calculate the Least Common Multiple of a and b. """ return a * b // gcd(a, b) def smallest_multiple(n): """ Returns the smallest number that...
from solution import gcd, lcm, smallest_multiple def test_gcd(): assert gcd(48, 18) == 6 assert gcd(1071, 462) == 21 assert gcd(5, 10) == 5 def test_lcm(): assert lcm(4, 5) == 20 assert lcm(21, 6) == 42 assert lcm(3, 7) == 21 def test_smallest_multiple(): assert smallest_multiple(10) == 2...
[ { "docstring": "Calculate the Greatest Common Divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Calculate the Least Common Multiple of a and b.", "function_declaration": "def lcm(a, b):", "function_na...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef smallest_multiple(n):\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00039015", "row_id": 39015, "seed_ids": "['magpie_prefill_39015']" }
0.649112
Prefill_39015
I
[ "gcd", "lcm", "smallest_multiple" ]
3
[ [ "lcm", "gcd" ], [ "smallest_multiple", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fdb8ca5e9adc02988fb89182b90c59a6e24e5ab8
365eaf98f7df44805140ed1143b53e50d9a64418
v1.0
instruct
Prefill
Prefill_39018_I
Write a python function to implement the simple Caesar cipher encryption and decryption.
def caesar_cipher_encrypt(text, shift): """ Encrypts the text using Caesar Cipher with the given shift. """ encrypted_text = [] for char in text: if char.isupper(): encrypted_text.append(chr((ord(char) + shift - 65) % 26 + 65)) elif char.islower(): encrypted_t...
from solution import caesar_cipher_encrypt, caesar_cipher_decrypt def test_caesar_cipher_encrypt_basic(): assert caesar_cipher_encrypt("abc", 1) == "bcd" def test_caesar_cipher_encrypt_wrap_around(): assert caesar_cipher_encrypt("xyz", 3) == "abc" def test_caesar_cipher_encrypt_mixed_case(): assert caesa...
[ { "docstring": "Encrypts the text using Caesar Cipher with the given shift.", "function_declaration": "def caesar_cipher_encrypt(text, shift):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(text, shift)" }, { "docstring": "Decrypts the text using Caesar Cipher with the given...
[ 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 caesar_cipher_encrypt(plaintext, shift):\n \"\"\"\n Encrypts plaintext using Caesar Cipher with a given shift.\n :param plaintext: The text to be encrypted.\n :param shift: Th...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00039018", "row_id": 39018, "seed_ids": "['magpie_prefill_39018']" }
0.683595
Prefill_39018
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt" ]
2
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9496018567163b348503d70c00243739c32c126
478b53671f3168159c283a65ea596fe8e0f4bcdc
v1.0
instruct
Prefill
Prefill_39272_I
Write a python function to calculate the factorial of a number using both iterative and recursive methods and compare their performance for large numbers. Analyze the trade-offs between the two methods.
import time def factorial_iterative(n): """ Calculate the factorial of a number iteratively. """ result = 1 for i in range(1, n + 1): result *= i return result def factorial_recursive(n): """ Calculate the factorial of a number recursively. """ if n == 0 or n == 1: ...
from solution import factorial_iterative, factorial_recursive, compare_performance, analyze_tradeoffs import time def test_factorial_iterative(): assert factorial_iterative(5) == 120 assert factorial_iterative(0) == 1 assert factorial_iterative(1) == 1 assert factorial_iterative(10) == 3628800 def tes...
[ { "docstring": "Calculate the factorial of a number iteratively.", "function_declaration": "def factorial_iterative(n):", "function_name": "factorial_iterative", "parameter_list": "(n)" }, { "docstring": "Calculate the factorial of a number recursively.", "function_declaration": "def fac...
[ 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef factorial_iterative(n):\n \"\"\"\n Calculate the factorial of a number using the iterative method.\n \"\"\"\n if n < 0:\n raise ValueError(\"Factorial is...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00039272", "row_id": 39272, "seed_ids": "['magpie_prefill_39272']" }
0.638904
Prefill_39272
I
[ "factorial_iterative", "factorial_recursive", "compare_performance", "analyze_tradeoffs" ]
4
[ [ "compare_performance", "factorial_iterative" ], [ "compare_performance", "factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b97af5f91f98ba41567397cb109200a9c8fd3ef5
5ac7eb96d79dca2b43723c8371c44610fe160de8
v1.0
instruct
Prefill
Prefill_39413_I
Write a python function to find the nth prime number. What's the first prime number after 1000?
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += ...
from solution import is_prime, nth_prime, first_prime_after_1000 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(0) == False assert is_prime(1) == False assert is_prime(29) == True def test_nt...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds the nth prime number.", "function_declaration": "def nth_prime(n):", "function_name": "nth_prime", "paramet...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_nth_prime(n):\n \"\"\"\n Returns the nth prime number.\n \"\"\"\n if n < 1:\n raise ValueError(\"n must be a positive integer\")\n \n primes = []\n num = ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00039413", "row_id": 39413, "seed_ids": "['magpie_prefill_39413']" }
0.663719
Prefill_39413
I
[ "is_prime", "nth_prime", "first_prime_after_1000" ]
3
[ [ "first_prime_after_1000", "is_prime" ], [ "nth_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1a6ef17ee07aa59f26e31e3a53b392ad546db929
1214dfaf546a5973066e4fb52fdee7e8ae2f7548
v1.0
instruct
Prefill
Prefill_39553_I
Write a python function to find the closest pairs from a given list of tuples, where the distance is calculated based on Euclidean distance formula. The list of tuples represents points in a two-dimensional space.
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points. Each point is represented by a tuple (x, y). """ return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) def closest_pairs(points): """ Find the closest pair of po...
def test_euclidean_distance(): assert euclidean_distance((0, 0), (0, 0)) == 0 assert euclidean_distance((0, 0), (3, 4)) == 5 assert euclidean_distance((1, 1), (4, 5)) == 5 def test_closest_pairs_single_pair(): assert closest_pairs([(0, 0), (1, 1)]) == ((0, 0), (1, 1)) def test_closest_pairs_multiple_p...
[ { "docstring": "Calculate the Euclidean distance between two points.\nEach point is represented by a tuple (x, y).", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the clos...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def euclidean_distance(point1, point2):\n \"\"\"\n Computes the Euclidean distance between two points represented as tuples (x1, y1) and (x2, y2).\n \"\"\"\n return ((point1[0] - ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00039553", "row_id": 39553, "seed_ids": "['magpie_prefill_39553']" }
0.696844
Prefill_39553
I
[ "euclidean_distance", "closest_pairs" ]
2
[ [ "closest_pairs", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6871ca9841037acf9531415caeab2da642275d2a
aee4252d3e809a9eaaf4886e77f6d6af4ec3ea67
v1.0
instruct
Prefill
Prefill_39726_I
Write a python function to find the first n prime numbers.
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: retu...
from solution import first_n_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(10) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == Fals...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of the first n prime numbers.", "function_declaration": "def first_n_primes(n):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00039726", "row_id": 39726, "seed_ids": "['magpie_prefill_39726']" }
0.717995
Prefill_39726
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1bd6c7d269af41a89b48596772f3d9a53d06b08a
e25b6d093233ae23331fa623f4e983900d504069
v1.0
instruct
Prefill
Prefill_39744_I
Write a python function to find all the roots of a polynomial equation using the Newton's method.
import sympy as sp def find_roots(f_expr, x0, tolerance=1e-7, max_iters=1000): """ Finds a root of the polynomial f using Newton's method starting from x0. Parameters: f_expr (sympy.Expr): The polynomial expression. x0 (float): Initial guess for the root. tolerance (float): The...
import pytest from solution import find_all_roots import sympy as sp def polynomial_expr(coeffs): """ Creates a polynomial expression from a list of coefficients. Parameters: coeffs (list): List of coefficients [a_n, a_(n-1), ..., a_1, a_0] Returns: sympy.Expr: Polynomial expr...
[ { "docstring": "Finds a root of the polynomial f using Newton's method starting from x0.\n\nParameters:\n f_expr (sympy.Expr): The polynomial expression.\n x0 (float): Initial guess for the root.\n tolerance (float): The tolerance for convergence.\n max_iters (int): Maximum number of iterations.\n\n...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sympy import symbols, diff, N\n\ndef newton_raphson_roots(coefficients, initial_guess, tolerance=1e-7, max_iterations=1000):\n \"\"\"\n Finds the roots of a polynomial using Newton...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00039744", "row_id": 39744, "seed_ids": "['magpie_prefill_39744']" }
0.597903
Prefill_39744
I
[ "find_roots", "find_all_roots" ]
2
[ [ "find_all_roots", "find_roots" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
a3dfce0e21edc48a890291e40e554a2abfeddba0
0143d4730938589946c41f6c01b19cb04414e6df
v1.0
instruct
Prefill
Prefill_39765_I
Write a python function to check whether a binary tree is symmetric.
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_symmetric(root): """ Check whether a binary tree is symmetric. :param root: TreeNode :return: bool """ if root is None: return True ...
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.le...
[]
[ 1, 1, 1, 1, 1, 0, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef is_symmetric(root):\n \"\"\"\n Checks whether a binary tree...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00039765", "row_id": 39765, "seed_ids": "['magpie_prefill_39765']" }
0.785446
Prefill_39765
I
[ "is_symmetric", "is_mirror" ]
2
[ [ "is_symmetric", "is_mirror" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
583330d05870cac82fefd104ced4d31f68e1a81e
4e5394e8bb0ff00b90001cae79bd052c276400ed
v1.0
instruct
Prefill
Prefill_39845_I
Write a python function to find the first occurrence of a pattern in a string using the Knuth-Morris-Pratt (KMP) algorithm. The function should return the index of the first occurrence of the pattern or -1 if the pattern is not found.
def compute_lps(pattern): """ Computes the Longest Proper Prefix which is also suffix array for the pattern. """ lps = [0] * len(pattern) length = 0 # length of the previous longest prefix suffix i = 1 while i < len(pattern): if pattern[i] == pattern[length]: length += ...
from solution import kmp_search def test_kmp_search_found(): assert kmp_search("abxabcabcaby", "abcaby") == 6 assert kmp_search("hello", "ll") == 2 assert kmp_search("abcabcabc", "cab") == 2 def test_kmp_search_not_found(): assert kmp_search("abcdef", "gh") == -1 assert kmp_search("abcdef", "xyz")...
[ { "docstring": "Computes the Longest Proper Prefix which is also suffix array for the pattern.", "function_declaration": "def compute_lps(pattern):", "function_name": "compute_lps", "parameter_list": "(pattern)" }, { "docstring": "Finds the first occurrence of the pattern in the text using t...
[ 0, 0, 0, 1, 0, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kmp_search(pattern, text):\n \"\"\"\n Returns the index of the first occurrence of the pattern in text using the KMP algorithm.\n If the pattern is not found, return -1.\n \"\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00039845", "row_id": 39845, "seed_ids": "['magpie_prefill_39845']" }
0.59574
Prefill_39845
I
[ "compute_lps", "kmp_search" ]
2
[ [ "kmp_search", "compute_lps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
28d0cf9711766d0f985e1092d88fda48a7c1b392
a52a943c90574d4b96241adbfc2bbba5e7737e97