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_22676_I | Create a function that takes in a JSON object and recursively converts all the keys and values to snake_case. | import re
import json
def to_snake_case(s):
"""
Convert a string to snake_case.
"""
s = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', s)
s = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s)
return s.lower()
def convert_to_snake_case(obj):
"""
Recursively convert all keys and string values of a JSON-lik... | from solution import to_snake_case, convert_to_snake_case
def test_to_snake_case():
assert to_snake_case("CamelCase") == "camel_case"
assert to_snake_case("camelCaseString") == "camel_case_string"
assert to_snake_case("anotherExampleTest") == "another_example_test"
assert to_snake_case("yetAnotherExamp... | [
{
"docstring": "Convert a string to snake_case.",
"function_declaration": "def to_snake_case(s):",
"function_name": "to_snake_case",
"parameter_list": "(s)"
},
{
"docstring": "Recursively convert all keys and string values of a JSON-like object to snake_case.",
"function_declaration": "d... | [
1,
1,
0,
1,
0,
1,
1,
0,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef to_snake_case(name):\n \"\"\"\n Convert a string to snake_case.\n \"\"\"\n s1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', name)\n return re.sub('([a-z0-9])([A-Z])... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00022676",
"row_id": 22676,
"seed_ids": "['magpie_prefill_22676']"
} | 0.618634 | Prefill_22676 | I | [
"to_snake_case",
"convert_to_snake_case"
] | 2 | [
[
"convert_to_snake_case",
"to_snake_case"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48c38c155cb430d6049c55c487b61b9733c5d7cd | 9c83f3c269a2a6818f518d73f6d3743a9e9acae4 | |||
v1.0 | instruct | Prefill | Prefill_22860_I | Create a function that takes a list of tuples as an argument and returns a new list containing only the tuples where the second element is a prime number. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def filter_tuples_with_prime_second_element(tuples_list):
"""
Takes a list of... | from solution import filter_tuples_with_prime_second_element
def test_empty_list():
assert filter_tuples_with_prime_second_element([]) == []
def test_all_prime_second_elements():
input_tuples = [(1, 2), (3, 3), (4, 5), (6, 7)]
expected_output = [(1, 2), (3, 3), (4, 5), (6, 7)]
assert filter_tuples_wit... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Takes a list of tuples and returns a new list containing only the tuples where\nthe second element is a pri... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00022860",
"row_id": 22860,
"seed_ids": "['magpie_prefill_22860']"
} | 0.633167 | Prefill_22860 | I | [
"is_prime",
"filter_tuples_with_prime_second_element"
] | 2 | [
[
"filter_tuples_with_prime_second_element",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ec12c242f624488c4514184f48ee9c921e6d54bb | d3521a7466660d41674703e1226bb61918e70b7b | |||
v1.0 | instruct | Prefill | Prefill_22945_I | Create a function that takes two parameters, `firstNumber` and `secondNumber`, and returns the product of these two numbers. If the product of these numbers is a palindrome, return the product. Otherwise, return the sum of the two input numbers. A palindrome number reads the same forward and backward. | def is_palindrome(number):
"""
Check if a number is a palindrome.
"""
return str(number) == str(number)[::-1]
def process_numbers(firstNumber, secondNumber):
"""
Returns the product of firstNumber and secondNumber if the product is a palindrome.
Otherwise, returns the sum of the two numbers... | from solution import process_numbers
def test_product_is_palindrome():
assert process_numbers(11, 11) == 121 # 11 * 11 = 121, which is a palindrome
def test_product_is_not_palindrome():
assert process_numbers(10, 13) == 23 # 10 * 13 = 130, which is not a palindrome (10 + 13 = 23)
def test_sum_instead_of_p... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns the product of firstNumber and secondNumber if the product is a palindrome.\nOtherwise, returns... | [
1,
1,
0,
0,
0,
0,
1,
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(number):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef process_numbers(firstNumber, ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00022945",
"row_id": 22945,
"seed_ids": "['magpie_prefill_22945']"
} | 0.685499 | Prefill_22945 | I | [
"is_palindrome",
"process_numbers"
] | 2 | [
[
"process_numbers",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 645443ddf8a5548bddb0c3e312efc1a57681b179 | 74974edaa2e71223ac94feca38196906ae9e881f | |||
v1.0 | instruct | Prefill | Prefill_23123_I | Create a function that converts a string into a binary representation, but only for a specific set of characters. In this case, we define a character to be "special" if it is a digit, a letter, or a punctuation mark. Non-special characters should not be included in the binary representation. Also, prepend each binary n... | def char_to_binary(c):
if c.isdigit():
return 'd' + bin(ord(c))[2:].zfill(8)
elif c.isalpha():
return 'l' + bin(ord(c))[2:].zfill(8)
elif c in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~':
return 'p' + bin(ord(c))[2:].zfill(8)
else:
return None
def string_to_special_binary(s):
... | from solution import string_to_special_binary
def test_only_special_characters():
assert string_to_special_binary("abc123!@#") == 'l01100001 l01100010 l01100011 d00110001 d00110010 d00110011 p00100001 p01000000 p00100011'
def test_mixed_characters():
assert string_to_special_binary("a1! b2@ c3# $%^") == 'l011... | [
{
"docstring": null,
"function_declaration": "def char_to_binary(c):",
"function_name": "char_to_binary",
"parameter_list": "(c)"
},
{
"docstring": null,
"function_declaration": "def string_to_special_binary(s):",
"function_name": "string_to_special_binary",
"parameter_list": "(s... | [
0,
0,
1,
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 char_type(char):\n \"\"\" Identify the type of character: digit, letter, or punctuation. \"\"\"\n if char.isdigit():\n return 'digit'\n elif char.isalpha():\n retur... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00023123",
"row_id": 23123,
"seed_ids": "['magpie_prefill_23123']"
} | 0.641795 | Prefill_23123 | I | [
"char_to_binary",
"string_to_special_binary"
] | 2 | [
[
"string_to_special_binary",
"char_to_binary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f4e07ece76f962dedc0a301372acf5e9f5c8f3b4 | 092e0711b58e4a2cba5bb62de22d5b9f79a94888 | |||
v1.0 | instruct | Prefill | Prefill_23232_I | Create a function that takes an integer `n` and returns the sum of all prime numbers less than `n` using Python. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import sum_of_primes_less_than
def test_sum_of_primes_less_than_10():
assert sum_of_primes_less_than(10) == 17 # 2 + 3 + 5 + 7
def test_sum_of_primes_less_than_20():
assert sum_of_primes_less_than(20) == 77 # 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19
def test_sum_of_primes_less_than_2():
assert 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 the sum of all prime numbers less than n.",
"function_declaration": "def sum_of_primes_less_tha... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num %... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00023232",
"row_id": 23232,
"seed_ids": "['magpie_prefill_23232']"
} | 0.802175 | Prefill_23232 | I | [
"is_prime",
"sum_of_primes_less_than"
] | 2 | [
[
"sum_of_primes_less_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 188f0baf9c8dabd777ac60b8d5bc9687da14786b | daf171dd5fb9bba5ef3979954b503775949f487b | |||
v1.0 | instruct | Prefill | Prefill_23392_I | Create a function that takes a list of integers and returns the sum of those integers. Additionally, the function should handle the potential ValueError that could occur if a non-integer value is passed in the list. To improve code readability and simplicity, use a helper function to verify that all elements in the lis... | def validate_integers(input_list):
"""
Helper function to verify that all elements in the list are integers.
Raises a ValueError if a non-integer value is found.
"""
for item in input_list:
if not isinstance(item, int):
raise ValueError(f"Non-integer value found: {item}")
def su... | from solution import validate_integers, sum_of_integers
def test_validate_integers_all_integers():
validate_integers([1, 2, 3, 4]) # Should not raise any error
def test_validate_integers_with_non_integer():
try:
validate_integers([1, 'a', 3]) # Should raise ValueError
except ValueError as e:
... | [
{
"docstring": "Helper function to verify that all elements in the list are integers.\nRaises a ValueError if a non-integer value is found.",
"function_declaration": "def validate_integers(input_list):",
"function_name": "validate_integers",
"parameter_list": "(input_list)"
},
{
"docstring":... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_integers(lst):\n \"\"\"\n Takes a list of integers and returns the sum of those integers.\n Raises a ValueError if a non-integer value is present in the list.\n \"\"\"\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00023392",
"row_id": 23392,
"seed_ids": "['magpie_prefill_23392']"
} | 0.650296 | Prefill_23392 | I | [
"validate_integers",
"sum_of_integers"
] | 2 | [
[
"sum_of_integers",
"validate_integers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cee08616968a435a6efb3c55b429b444448bfb5a | 6ee4025362288bc4dcf4f83f250f920d1b7440d8 | |||
v1.0 | instruct | Prefill | Prefill_23417_I | Create a function that calculates the area of a circle given its radius. Then, use a for loop to calculate the areas of circles with radii ranging from 1 to 10. | import math
def area_of_circle(radius):
"""
Returns the area of a circle given its radius.
"""
if radius < 0:
raise ValueError("Radius cannot be negative")
return math.pi * (radius ** 2)
def areas_of_circles_from_1_to_10():
"""
Calculates the areas of circles with radii ranging fro... | import pytest
from solution import area_of_circle, areas_of_circles_from_1_to_10
def test_area_of_circle():
assert math.isclose(area_of_circle(1), math.pi, rel_tol=1e-9)
assert math.isclose(area_of_circle(2), 4 * math.pi, rel_tol=1e-9)
assert math.isclose(area_of_circle(3), 9 * math.pi, rel_tol=1e-9)
def ... | [
{
"docstring": "Returns the area of a circle given its radius.",
"function_declaration": "def area_of_circle(radius):",
"function_name": "area_of_circle",
"parameter_list": "(radius)"
},
{
"docstring": "Calculates the areas of circles with radii ranging from 1 to 10.\nReturns a list of these... | [
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 circle_area(radius):\n \"\"\"\n Calculate and return the area of a circle given its radius.\n \"\"\"\n if radius < 0:\n raise ValueError(\"Radius cannot ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00023417",
"row_id": 23417,
"seed_ids": "['magpie_prefill_23417']"
} | 0.566552 | Prefill_23417 | I | [
"area_of_circle",
"areas_of_circles_from_1_to_10"
] | 2 | [
[
"areas_of_circles_from_1_to_10",
"area_of_circle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f4601a56aefa75e6c7d05fc95eaaf24275c1e9c8 | f23b9f72959c264b413de5ecfab541763c6f5889 | |||
v1.0 | instruct | Prefill | Prefill_23468_I | Create a function that takes two strings, and returns the string with the maximum repeated substring among the two strings. If there's a tie, return the one that appears first alphabetically. If neither string has a repeated substring, return an empty string. | def longest_repeated_substring(s):
"""
Helper function to find the longest repeated substring in a given string.
"""
n = len(s)
for length in range(n, 0, -1):
seen = set()
for start in range(n - length + 1):
substring = s[start:start + length]
if substring in ... | from solution import string_with_max_repeated_substring
def test_no_repeated_substring():
assert string_with_max_repeated_substring("abc", "def") == ""
def test_one_repeated_substring():
assert string_with_max_repeated_substring("abcabc", "def") == "abcabc"
def test_both_repeated_substring_different_lengths(... | [
{
"docstring": "Helper function to find the longest repeated substring in a given string.",
"function_declaration": "def longest_repeated_substring(s):",
"function_name": "longest_repeated_substring",
"parameter_list": "(s)"
},
{
"docstring": "Returns the string with maximum repeated substri... | [
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 longest_repeated_substring(s):\n \"\"\"\n Helper function to find the longest repeated substring in a given string.\n \"\"\"\n n = len(s)\n for length in range(n, 0, -1):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00023468",
"row_id": 23468,
"seed_ids": "['magpie_prefill_23468']"
} | 0.683092 | Prefill_23468 | I | [
"longest_repeated_substring",
"string_with_max_repeated_substring"
] | 2 | [
[
"string_with_max_repeated_substring",
"longest_repeated_substring"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccd460fa8d652c384a6bb724b9a71a9cb03c6572 | 6862b3f52084bf741cf6079c788127a2838530d0 | |||
v1.0 | instruct | Prefill | Prefill_23513_I | Create a function that can generate a list of prime numbers within a given range. The function should take two arguments, the lower and upper bounds of the range, and return a list of all prime numbers within that range. | def is_prime(n):
"""
Determines 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... | from solution import generate_primes
def test_generate_primes_no_primes():
assert generate_primes(8, 10) == []
def test_generate_primes_inclusive():
assert generate_primes(2, 5) == [2, 3, 5]
def test_generate_primes_single_prime():
assert generate_primes(13, 13) == [13]
def test_generate_primes_large_ra... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of prime numbers within the given range [lower, upper].",
"function_declaration": "def generate_primes(l... | [
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 check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00023513",
"row_id": 23513,
"seed_ids": "['magpie_prefill_23513']"
} | 0.609211 | Prefill_23513 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 88d253e7fe1db5920e57d4faa3ce662d9c2d30a1 | e96b7876f9467ba622e9bd3dcf128ab05b6c83fd | |||
v1.0 | instruct | Prefill | Prefill_23692_I | Create a function that takes in a list of integers and returns the sum of all the prime numbers in the list. Return -1 if the list does not contain any prime numbers. | 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_of_primes(lst):
"""
Returns the sum of all prime numbers in the list.
Retur... | from solution import sum_of_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(11) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_sum_of_primes_with_pr... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list.\nReturns -1 if there are no prime numbers in the list.",
... | [
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 sum_of_primes(numbers):\n \"\"\"\n Returns the sum of all the prime numbers in the list.\n Returns -1 if the list does not contain any prime numbers.\n \"\"\"\n def is_prim... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00023692",
"row_id": 23692,
"seed_ids": "['magpie_prefill_23692']"
} | 0.631601 | Prefill_23692 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 577ae26c58439e5d24dd14b5660824d277474b58 | 04dac376a607b22143bfec81827584b6d8f8ac8f | |||
v1.0 | instruct | Prefill | Prefill_23811_I | Create a function that returns the nth Fibonacci number. The code should not just return the number but also print the number of function calls made to calculate the result. Use a top-down approach with memoization to solve the problem. | def fibonacci(n, memo={}):
"""
Returns the nth Fibonacci number and prints the number of function calls made.
Uses a top-down approach with memoization.
"""
if n in memo:
return memo[n]
if n <= 0:
return 0
elif n == 1:
return 1
memo[n] = fibonacci(n - 1,... | from solution import get_fibonacci
def test_fibonacci_0():
assert get_fibonacci(0) == 0
def test_fibonacci_1():
assert get_fibonacci(1) == 1
def test_fibonacci_5():
assert get_fibonacci(5) == 5
def test_fibonacci_10():
assert get_fibonacci(10) == 55
def test_fibonacci_large():
assert get_fibona... | [
{
"docstring": "Returns the nth Fibonacci number and prints the number of function calls made.\nUses a top-down approach with memoization.",
"function_declaration": "def fibonacci(n, memo={}):",
"function_name": "fibonacci",
"parameter_list": "(n, memo={})"
},
{
"docstring": "Wrapper functio... | [
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 fibonacci(n):\n memo = {}\n calls = {'count': 0}\n \n def fib_memo(n):\n calls['count'] += 1\n if n in memo:\n return memo[n]\n if n <= 1:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00023811",
"row_id": 23811,
"seed_ids": "['magpie_prefill_23811']"
} | 0.72543 | Prefill_23811 | I | [
"fibonacci",
"get_fibonacci"
] | 2 | [
[
"get_fibonacci",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4bd56efc5e3244731b86e186a9209451bd3e2eb7 | 1ea1b47d559ec439add5a775d69449155c8c9dce | |||
v1.0 | instruct | Prefill | Prefill_23830_I | Create a function that checks each number in a given list to see if it is a prime number. If it is a prime number, add it to a new list. Return that list at the end. | def is_prime(n):
"""
Returns whether the given number 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 extrac... | from solution import extract_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(17) == True
assert is_prime(18) == False
assert is_prime(1) == Fal... | [
{
"docstring": "Returns whether the given number n is a prime number.",
"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 extra... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00023830",
"row_id": 23830,
"seed_ids": "['magpie_prefill_23830']"
} | 0.673406 | Prefill_23830 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c55190d3fd01267effbcd5e9c6b9efe0a94f45f | 113002cd3df74617c22220894acc095cf3928a64 | |||
v1.0 | instruct | Prefill | Prefill_23989_I | Create a function that prints all the prime numbers within an interval. | 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 print_primes_in_interval(start, end):
"""
Prints all prime numbers in the interva... | from solution import is_prime, print_primes_in_interval
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert is_prime(5)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(4)
assert not is_prime(9)
assert not is_prime(15)
def test_print_primes_in_interval(capfd... | [
{
"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": "Prints all prime numbers in the interval [start, end].",
"function_declaration": "def print_primes_in_int... | [
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 print_primes(start, end):\n \"\"\"\n Prints all prime numbers within the interval [start, end].\n \"\"\"\n primes = []\n for num in range(start, end + 1):\n if num >... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00023989",
"row_id": 23989,
"seed_ids": "['magpie_prefill_23989']"
} | 0.686635 | Prefill_23989 | I | [
"is_prime",
"print_primes_in_interval"
] | 2 | [
[
"print_primes_in_interval",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1637dd807424d26d49d1845d43d08f60460db21 | 36d3c2e23f4815759c3bf2f31132a5a7efaafd51 | |||
v1.0 | instruct | Prefill | Prefill_24105_I | Create a function that takes a 2D array of integers and returns the maximum sum of a subarray within the 2D array. The subarray can consist of elements from any contiguous rows and columns. | def maximum_sum_subarray_2d(matrix):
"""
Finds the maximum sum of a subarray within the given 2D array.
Args:
matrix (list of list of int): 2D array to find the subarray with the maximum sum.
Returns:
int: The maximum sum of a subarray.
"""
if not matrix:
return 0
max_sum =... | from solution import maximum_sum_subarray_2d
def test_empty_matrix():
assert maximum_sum_subarray_2d([]) == 0
def test_single_element_matrix():
assert maximum_sum_subarray_2d([[5]]) == 5
assert maximum_sum_subarray_2d([[-3]]) == -3
def test_positive_elements_matrix():
assert maximum_sum_subarray_2d([... | [
{
"docstring": "Finds the maximum sum of a subarray within the given 2D array.\nArgs:\nmatrix (list of list of int): 2D array to find the subarray with the maximum sum.\n\nReturns:\nint: The maximum sum of a subarray.",
"function_declaration": "def maximum_sum_subarray_2d(matrix):",
"function_name": "ma... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_2d_subarray_sum(matrix):\n def kadane_1d(array):\n max_ending_here = max_so_far = array[0]\n for x in array[1:]:\n max_ending_here = max(x, max_ending_here... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00024105",
"row_id": 24105,
"seed_ids": "['magpie_prefill_24105']"
} | 0.695615 | Prefill_24105 | I | [
"maximum_sum_subarray_2d",
"kadane_algorithm"
] | 2 | [
[
"maximum_sum_subarray_2d",
"kadane_algorithm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | acb8664542b458667d992213ffa931e6fcae1ee8 | f366a8e9a5f934b365b233c0d6b31ea23376c5a4 | |||
v1.0 | instruct | Prefill | Prefill_24290_I | Create a function that periodically checks the weather at a given location using an API and updates the UI accordingly. The user should be able to specify the location (city, country) and the frequency of updates. For simplicity, let's just print out the weather information to the console. | import requests
import time
def get_weather(api_key, city, country):
url = f'http://api.openweathermap.org/data/2.5/weather?q={city},{country}&appid={api_key}'
response = requests.get(url)
data = response.json()
if response.status_code == 200:
weather = data['weather'][0]['description']
... | import pytest
from unittest.mock import patch, MagicMock
from solution import get_weather
@patch('solution.requests.get')
def test_get_weather_success(mock_get):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
'weather': [{'description': 'clear sky'}... | [
{
"docstring": null,
"function_declaration": "def get_weather(api_key, city, country):",
"function_name": "get_weather",
"parameter_list": "(api_key, city, country)"
},
{
"docstring": null,
"function_declaration": "def start_weather_updates(api_key, city, country, frequency):",
"func... | [
0,
0,
1,
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 time\nimport requests\n\ndef get_weather(api_key, city, country):\n \"\"\"\n Fetches the weather data from OpenWeatherMap API for a given city and country.\n \"\"\"\n url =... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00024290",
"row_id": 24290,
"seed_ids": "['magpie_prefill_24290']"
} | 0.385108 | Prefill_24290 | I | [
"get_weather",
"start_weather_updates"
] | 2 | [
[
"start_weather_updates",
"get_weather"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | ca70594e2f31cfbdc64b3a1575041d4f088f1e3d | cdb92dc8459130f15e003a94f7d18ca432b35122 | |||
v1.0 | instruct | Prefill | Prefill_24367_I | Create a function that takes an integer N and computes the factorial of that number using recursion. Then, create a function that checks if the computed factorial is a perfect number. A perfect number is a positive integer that is equal to the sum of its positive divisors excluding the number itself. | def factorial(n):
"""
Returns the factorial of n using recursion.
"""
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
def is_perfect_number(num):
"""
Checks if the provided number is a perfect number.
"""
if num <= 1:
return False
... | from solution import factorial, is_perfect_number, factorial_is_perfect
def test_factorial():
# Testing factorial function
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(3) == 6
assert factorial(5) == 120
assert factorial(6) == 720
def test_is_perfect_number():
# Te... | [
{
"docstring": "Returns the factorial of n using recursion.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Checks if the provided number is a perfect number.",
"function_declaration": "def is_perfect_number(num):",
... | [
1,
0,
1,
1,
1,
1,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial(N):\n \"\"\"\n Returns the factorial of the integer N using recursion.\n \"\"\"\n if N == 0 or N == 1:\n return 1\n else:\n return N * factorial(N -... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00024367",
"row_id": 24367,
"seed_ids": "['magpie_prefill_24367']"
} | 0.662103 | Prefill_24367 | I | [
"factorial",
"is_perfect_number",
"factorial_is_perfect"
] | 3 | [
[
"factorial_is_perfect",
"factorial"
],
[
"factorial_is_perfect",
"is_perfect_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | af1afb478b66978dc598f7d9e1b824baa5253408 | 46d117e802f104ede9dc57a4ef886e4ef3e4dc2f | |||
v1.0 | instruct | Prefill | Prefill_24551_I | Create a function that checks if a word starts or ends with a consonant. | def is_consonant(char):
"""
Check if a given character is a consonant.
Consonants are all alphabetic characters that are not vowels (a, e, i, o, u).
"""
return char.lower() in "bcdfghjklmnpqrstvwxyz"
def starts_or_ends_with_consonant(word):
"""
Check if a word starts or ends with a consonan... | from solution import starts_or_ends_with_consonant
def test_word_starts_with_consonant():
assert starts_or_ends_with_consonant("cat") == True
assert starts_or_ends_with_consonant("dog") == True
def test_word_ends_with_consonant():
assert starts_or_ends_with_consonant("pineapple") == True
assert starts... | [
{
"docstring": "Check if a given character is a consonant.\nConsonants are all alphabetic characters that are not vowels (a, e, i, o, u).",
"function_declaration": "def is_consonant(char):",
"function_name": "is_consonant",
"parameter_list": "(char)"
},
{
"docstring": "Check if a word starts... | [
1,
0,
1,
1,
0,
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 starts_or_ends_with_consonant(word):\n \"\"\"\n Checks if a word starts or ends with a consonant.\n \"\"\"\n if not word:\n return False\n \n consonants = \"b... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00024551",
"row_id": 24551,
"seed_ids": "['magpie_prefill_24551']"
} | 0.709 | Prefill_24551 | I | [
"is_consonant",
"starts_or_ends_with_consonant"
] | 2 | [
[
"starts_or_ends_with_consonant",
"is_consonant"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a7439f84ba028aef9909af008acc5619a980350 | 8b0e8c94add7643fa13ebe0924f80395318f349f | |||
v1.0 | instruct | Prefill | Prefill_24666_I | Create a function that calculates and returns the sum of the first 100 prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. | def is_prime(n):
"""
Checks if the number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import is_prime, sum_of_first_100_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
def test_sum_of_fir... | [
{
"docstring": "Checks if the number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculates and returns the sum of the first 100 prime numbers.",
"function_declaration": "def sum_of_first_100_p... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n retur... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00024666",
"row_id": 24666,
"seed_ids": "['magpie_prefill_24666']"
} | 0.603112 | Prefill_24666 | I | [
"is_prime",
"sum_of_first_100_primes"
] | 2 | [
[
"sum_of_first_100_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c0d007374ea7a24663e514d520315b3a1dfe465 | f0d8ad9165208dd3b4112b9e94fe51fdb8dbea31 | |||
v1.0 | instruct | Prefill | Prefill_24845_I | Create a function that generates a list of prime numbers between two given numbers. The function should take two parameters, `lower_limit` and `upper_limit`, and return a list of all prime numbers within this range, inclusive. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import prime_numbers
def test_prime_numbers_typical_case():
assert prime_numbers(10, 20) == [11, 13, 17, 19]
def test_prime_numbers_with_lower_limit_zero():
assert prime_numbers(0, 10) == [2, 3, 5, 7]
def test_prime_numbers_no_primes():
assert prime_numbers(14, 16) == []
def test_prime_num... | [
{
"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 between lower_limit and upper_limit, inclusive.",
"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 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 for i in range(3, int(n**0.5) + 1, 2):\n if n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00024845",
"row_id": 24845,
"seed_ids": "['magpie_prefill_24845']"
} | 0.623048 | Prefill_24845 | I | [
"is_prime",
"prime_numbers"
] | 2 | [
[
"prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | faf7f8f618fc1e9f3bffed0f066dca317e16ee7a | 2d7f59ee79262ec664e7e73409e96b50c96c6522 | |||
v1.0 | instruct | Prefill | Prefill_25073_I | Create a function that takes an integer `n` as input and returns all the prime numbers greater than `n` up to and including `m`. Here `m` is the next nearest single digit integer greater than `n` that is divisible by 5. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
return... | from solution import prime_numbers_greater_than_n, next_nearest_divisible_by_five, 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
def test_next_nearest_divisible_by_five():
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Helper function to find the next nearest single digit integer greater than n that is divisible by 5.",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_nearest_greater_divisible_by_5(n):\n \"\"\"\n Finds the next nearest single digit integer greater than n that is divisible by 5.\n \"\"\"\n for i in range(n+1, 10):\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00025073",
"row_id": 25073,
"seed_ids": "['magpie_prefill_25073']"
} | 0.627283 | Prefill_25073 | I | [
"is_prime",
"next_nearest_divisible_by_five",
"prime_numbers_greater_than_n"
] | 3 | [
[
"prime_numbers_greater_than_n",
"is_prime"
],
[
"prime_numbers_greater_than_n",
"next_nearest_divisible_by_five"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ee064d79c5e4de9ad0e81df81c7d052da17e466 | 2c8c38a6f64e09d3a824483102b6374ce10a6de3 | |||
v1.0 | instruct | Prefill | Prefill_25082_I | Create a function that takes as input a list of integers. This function should return the largest number that can be formed by concatenating the numbers in any order. Note that the result may be very large, so return the result as a string. | from functools import cmp_to_key
def compare(x, y):
if x + y > y + x:
return -1
elif x + y < y + x:
return 1
else:
return 0
def largest_number(nums):
"""
Returns the largest number that can be formed by concatenating the input integers.
"""
# Convert integer list to... | from solution import largest_number
def test_single_number():
assert largest_number([5]) == '5'
def test_all_zeros():
assert largest_number([0, 0, 0]) == '0'
def test_simple_case():
assert largest_number([10, 2]) == '210'
def test_complex_case():
assert largest_number([3, 30, 34, 5, 9]) == '9534330'... | [
{
"docstring": null,
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": "Returns the largest number that can be formed by concatenating the input integers.",
"function_declaration": "def largest_number(nums):",
"func... | [
0,
0,
1,
1,
0,
1,
0,
0,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largest_number(nums):\n \"\"\"\n Returns the largest number that can be formed by concatenating the numbers in any order as a string.\n \n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00025082",
"row_id": 25082,
"seed_ids": "['magpie_prefill_25082']"
} | 0.691354 | Prefill_25082 | I | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a8998ff9844f65d386a301d2c30fda7ae74e145 | 50bd993c15a1ffeccf76e90f50775c7d8ff25f26 | |||
v1.0 | instruct | Prefill | Prefill_25297_I | Create a function that converts a given string in snake_case to PascalCase using C#. Speed up the conversion process using multithreading in C#. | import re
from multiprocessing import Pool
def convert_snake_to_pascal(snake_str):
"""
Converts a given snake_case string to PascalCase.
"""
# Splitting by underscores and capitalizing each word.
components = snake_str.split('_')
pascal_str = ''.join(x.capitalize() for x in components)
retu... | import pytest
from solution import convert_snake_to_pascal, multithread_convert_snake_to_pascal
def test_convert_simple_snake_case():
assert convert_snake_to_pascal('simple_case') == 'SimpleCase'
def test_convert_single_word():
assert convert_snake_to_pascal('word') == 'Word'
def test_convert_mixed_case():
... | [
{
"docstring": "Converts a given snake_case string to PascalCase.",
"function_declaration": "def convert_snake_to_pascal(snake_str):",
"function_name": "convert_snake_to_pascal",
"parameter_list": "(snake_str)"
},
{
"docstring": "Uses multithreading to convert a list of snake_case strings to... | [
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "csharp\nusing System;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\npublic class StringConverter\n{\n public static string SnakeCaseToPascalCase(string input)\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00025297",
"row_id": 25297,
"seed_ids": "['magpie_prefill_25297']"
} | 0.607863 | Prefill_25297 | I | [
"convert_snake_to_pascal",
"multithread_convert_snake_to_pascal"
] | 2 | [
[
"multithread_convert_snake_to_pascal",
"convert_snake_to_pascal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3dba5b84a6b35f62439d720fbeff0424f972caea | 268ab47b1995f1bc8a641593cc9de62586fd0644 | |||
v1.0 | instruct | Prefill | Prefill_25301_I | Create a function that takes two arguments: `value`, `bits`, and returns the least common multiple (LCM) of these as an integer. You can ignore the sign of the number for this computation. The function should handle both positive and negative integers. | def gcd(a, b):
"""
Helper function to return the greatest common divisor (GCD) of a and b using the Euclidean algorithm.
"""
while b:
a, b = b, a % b
return a
def lcm(value, bits):
"""
Returns the least common multiple (LCM) of value and bits.
"""
value = abs(value)
bits... | from solution import lcm
def test_lcm_positive_numbers():
assert lcm(4, 6) == 12
assert lcm(21, 6) == 42
assert lcm(8, 12) == 24
def test_lcm_negative_numbers():
assert lcm(-4, 6) == 12
assert lcm(21, -6) == 42
assert lcm(-8, -12) == 24
def test_lcm_with_zero():
assert lcm(0, 5) == 0
... | [
{
"docstring": "Helper function to return the greatest common divisor (GCD) of a and b using the Euclidean algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least common multiple (LCM) of value and bits.",... | [
1,
0,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef lcm(value, bits):\n \"\"\"\n Returns the least common multiple (LCM) of two integers, ignoring their signs.\n \"\"\"\n value = abs(value)\n bits = abs(bits)\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00025301",
"row_id": 25301,
"seed_ids": "['magpie_prefill_25301']"
} | 0.649027 | Prefill_25301 | I | [
"gcd",
"lcm"
] | 2 | [
[
"lcm",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9d14d5c62abbceee2902cab92086e61f4a882049 | d25cf53317a53ad421a73e786f41ccf98d26f94f | |||
v1.0 | instruct | Prefill | Prefill_25354_I | Create a function that takes a list of integers and returns the product of all the prime numbers in the list. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
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 prime_product(l... | from solution import prime_product, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_prime_product_with_primes():
assert prime_product([2, 3, 5, 7]) == 210 # 2*3*5*... | [
{
"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 product of all prime numbers in the list.",
"function_declaration": "def prime_product(lst):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00025354",
"row_id": 25354,
"seed_ids": "['magpie_prefill_25354']"
} | 0.643064 | Prefill_25354 | I | [
"is_prime",
"prime_product"
] | 2 | [
[
"prime_product",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61b73227161a11547b272e305a7b3aa5c54dec67 | eda747dd8c66af3f1a3c65777e93c3271da6d05c | |||
v1.0 | instruct | Prefill | Prefill_25455_I | Create a function that returns the largest positive integer that cannot be formed by any combination of given positive integers `a` and `b`. | def largest_unreachable_integer(a, b):
"""
Returns the largest positive integer that cannot be formed by any combination of given positive integers a and b.
"""
if a <= 0 or b <= 0:
return 0
if a == 1 or b == 1:
return None # Since a and b being 1 means we can form any integer
... | from solution import largest_unreachable_integer, gcd
def test_gcd():
assert gcd(8, 12) == 4
assert gcd(17, 13) == 1
assert gcd(100, 10) == 10
assert gcd(5, 5) == 5
def test_largest_unreachable_integer():
assert largest_unreachable_integer(6, 9) == None # not coprime
assert largest_unreachabl... | [
{
"docstring": "Returns the largest positive integer that cannot be formed by any combination of given positive integers a and b.",
"function_declaration": "def largest_unreachable_integer(a, b):",
"function_name": "largest_unreachable_integer",
"parameter_list": "(a, b)"
},
{
"docstring": "... | [
0,
0,
0,
1,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_unreachable(a, b):\n \"\"\"\n Returns the largest positive integer that cannot be formed by any combination of a and b.\n This is known as the Frobenius number when a and... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00025455",
"row_id": 25455,
"seed_ids": "['magpie_prefill_25455']"
} | 0.609862 | Prefill_25455 | I | [
"largest_unreachable_integer",
"gcd"
] | 2 | [
[
"largest_unreachable_integer",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a5e4cfcb48e68b877a09ae72e0166d14f07c8dd7 | 9b11e36e8189e3f240eed14cf78cf0e30c1c9784 | |||
v1.0 | instruct | Prefill | Prefill_25473_I | Create a function that takes in two lists of integers and returns a list that contains the intersection of the two lists, but only if the intersection contains at least one common prime factor. If there are no common prime factors, return an empty list. | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def prime_factors(num):
factors = []
for i in range(2, num + 1):
if num % i == 0 and is_prime(i):
factors.append(i)
return... | from solution import intersection_with_prime_factors, is_prime, prime_factors, has_common_prime_factors
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-5)
def test_prime_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(num):",
"function_name": "prime_factors",
"parameter_list": "(num)"
},
{
"docstring... | [
1,
0,
1,
1,
0,
1,
0,
0,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef prime_factors... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00025473",
"row_id": 25473,
"seed_ids": "['magpie_prefill_25473']"
} | 0.699443 | Prefill_25473 | I | [
"is_prime",
"prime_factors",
"has_common_prime_factors",
"intersection_with_prime_factors"
] | 4 | [
[
"has_common_prime_factors",
"prime_factors"
],
[
"intersection_with_prime_factors",
"has_common_prime_factors"
],
[
"prime_factors",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 785c748919c18c08a5f1a3f9864d3345716a0c32 | bf83f1067cce71bb1af55076105c3517961c94bb | |||
v1.0 | instruct | Prefill | Prefill_25508_I | Create a function that implements the quicksort algorithm, but instead of sorting an entire list, it performs a partial sort on the list. The function should take three arguments: a list of numbers, a start index, an end index, and a desired k-th position. The function should return a list that is partially sorted such... | def partition(arr, low, high):
i = low - 1
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if low <= high:
... | def test_find_kth_element_full_range():
arr = [10, 4, 5, 8, 6, 11, 26]
k = 3
result = find_kth_element(arr, 0, len(arr) - 1, k)
assert result[k] == sorted(arr)[k]
def test_find_kth_element_partial_range():
arr = [10, 4, 5, 8, 6, 11, 26]
k = 2
result = find_kth_element(arr, 1, 5, k)
asse... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
0,
0,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quickselect(arr, start, end, k):\n \"\"\"\n Rearranges the list such that the k-th element is in its correct position\n within a sorted list. All elements before the k-th element... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00025508",
"row_id": 25508,
"seed_ids": "['magpie_prefill_25508']"
} | 0.568693 | Prefill_25508 | I | [
"partition",
"quickselect",
"find_kth_element"
] | 3 | [
[
"find_kth_element",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c750455ea06d3d5566437b27aa4de5c1e5f337b2 | 7b14dd9b1e2cac50c0d3cdd8315eb43a3b78b545 | |||
v1.0 | instruct | Prefill | Prefill_25646_I | Create a function that takes an integer n as input and prints all prime numbers up to n. | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def print_primes_up_to(n):
"""
Returns a list of all prime numbers u... | from solution import is_prime, print_primes_up_to
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
def test_print_primes_up_to():
assert print_primes_up_to(10) == [2, 3, 5, 7]
assert print... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers up to n.",
"function_declaration": "def print_primes_up_to... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num %... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00025646",
"row_id": 25646,
"seed_ids": "['magpie_prefill_25646']"
} | 0.727657 | Prefill_25646 | I | [
"is_prime",
"print_primes_up_to"
] | 2 | [
[
"print_primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6141d327be06ca75db4a63c3535a51e78fbdfba | e62843763fb02b74c379b3e67044f511a68592b8 | |||
v1.0 | instruct | Prefill | Prefill_25672_I | Create a function that calculates the factorial of a given number. Then, extend it to calculate the factorial of a list of numbers. For example, if the input is [1, 2, 3, 4], the output should be [1, 2, 6, 24]. | def factorial(n):
"""
Returns the factorial of n.
"""
if n == 0:
return 1
result = 1
for i in range(1, n + 1):
result *= i
return result
def factorial_list(numbers):
"""
Returns the list of factorials for the given list of numbers.
"""
return [factorial(n) fo... | from solution import factorial, factorial_list
def test_factorial_zero():
assert factorial(0) == 1
def test_factorial_positive_numbers():
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
def test_factorial_list_emp... | [
{
"docstring": "Returns the factorial of n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns the list of factorials for the given list of numbers.",
"function_declaration": "def factorial_list(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 factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n for i in range(1, n + 1):\n result *= i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00025672",
"row_id": 25672,
"seed_ids": "['magpie_prefill_25672']"
} | 0.737469 | Prefill_25672 | I | [
"factorial",
"factorial_list"
] | 2 | [
[
"factorial_list",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63dcdee61cadb5b3d230ddd0410384c8cfa0f256 | ef775250e187a8ce4b88ebc2b5f0e98d5d6e637e | |||
v1.0 | instruct | Prefill | Prefill_25693_I | Create a function that accepts an integer `n` and outputs a list of all prime numbers up to `n`. | def is_prime(n):
"""
Helper function that returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2 or n == 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0... | from solution import primes_up_to
def test_primes_up_to_10():
assert primes_up_to(10) == [2, 3, 5, 7]
def test_primes_up_to_1():
assert primes_up_to(1) == []
def test_primes_up_to_2():
assert primes_up_to(2) == [2]
def test_primes_up_to_20():
assert primes_up_to(20) == [2, 3, 5, 7, 11, 13, 17, 19]
... | [
{
"docstring": "Helper function that 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 all prime numbers up to and including n.",
"function_declarat... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function that returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or n == 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00025693",
"row_id": 25693,
"seed_ids": "['magpie_prefill_25693']"
} | 0.741951 | Prefill_25693 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 147b45a506c54012876cc0aec7c096fa44fbcdba | 77cdb642326b7e6e114c340da71a867f9802f944 | |||
v1.0 | instruct | Prefill | Prefill_25930_I | Create a function that solves a Sudoku puzzle. The function should take a 2D list representing a Sudoku grid, where '0' represents an empty cell. The function should return True if the puzzle is solvable and False otherwise. The solution should also provide a completed grid if the puzzle is solveable. | def is_valid(board, row, col, num):
for x in range(9):
if board[row][x] == num or board[x][col] == num:
return False
if board[row // 3 * 3 + x // 3][col // 3 * 3 + x % 3] == num:
return False
return True
def solve_sudoku(board):
for row in range(9):
for col i... | from solution import sudoku_solver
def test_sudoku_solver_solvable():
puzzle = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, ... | [
{
"docstring": null,
"function_declaration": "def is_valid(board, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": null,
"function_declaration": "def solve_sudoku(board):",
"function_name": "solve_sudoku",
"parameter_list... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def solve_sudoku(board):\n \"\"\"\n Solves the given Sudoku puzzle.\n - board: A 2D list representing the Sudoku grid where empty cells are marked as 0.\n Returns True if the puzz... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00025930",
"row_id": 25930,
"seed_ids": "['magpie_prefill_25930']"
} | 0.496141 | Prefill_25930 | I | [
"is_valid",
"solve_sudoku",
"sudoku_solver"
] | 3 | [
[
"solve_sudoku",
"is_valid"
],
[
"sudoku_solver",
"solve_sudoku"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dbd701892ee56cf9dddde6055b32d19cb2dc63a3 | c3e411197cac65db61f54ac0ad39748ebcfe0f84 | |||
v1.0 | instruct | Prefill | Prefill_25996_I | Create a function that partitions the given list into K non-empty sublists such that the maximum sum of elements in any sublist is minimized. | def can_partition(nums, k, max_sum):
current_sum = 0
partitions = 1
for num in nums:
if current_sum + num > max_sum:
partitions += 1
current_sum = num
if partitions > k:
return False
else:
current_sum += num
return... | from solution import min_max_partition_sum
def test_min_max_partition_sum_example():
nums = [7, 2, 5, 10, 8]
k = 2
assert min_max_partition_sum(nums, k) == 18
def test_min_max_partition_sum_single_element():
nums = [10]
k = 1
assert min_max_partition_sum(nums, k) == 10
def test_min_max_partit... | [
{
"docstring": null,
"function_declaration": "def can_partition(nums, k, max_sum):",
"function_name": "can_partition",
"parameter_list": "(nums, k, max_sum)"
},
{
"docstring": null,
"function_declaration": "def min_max_partition_sum(nums, k):",
"function_name": "min_max_partition_sum... | [
1,
1,
1,
0,
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 can_partition(nums, k, max_sum):\n \"\"\"\n Utility function to check whether it's possible to partition the list into k sublists\n where each sublist has a sum less than or equa... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00025996",
"row_id": 25996,
"seed_ids": "['magpie_prefill_25996']"
} | 0.61778 | Prefill_25996 | I | [
"can_partition",
"min_max_partition_sum"
] | 2 | [
[
"min_max_partition_sum",
"can_partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a9e21cd024ef38db8153da8db133314090f485c0 | e5ccb4a58d5036d3cfb7126ade442eaa3e6eaa66 | |||
v1.0 | instruct | Prefill | Prefill_26034_I | Create a function that solves a given Sudoku puzzle. The function should take a 2D list called `sudoku_grid` as input, where each cell contains a number or is `0` if the cell is empty. The function should return the solved Sudoku puzzle as a 2D list. | def is_valid(board, row, col, num):
"""
Checks if placing the number 'num' in the position (row, col) is valid
according to Sudoku rules.
"""
# Check if 'num' is not in the given row
for x in range(9):
if board[row][x] == num:
return False
# Check if 'num' is not in the ... | from solution import solve_sudoku_puzzle
def test_solve_sudoku_puzzle():
grid = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0,... | [
{
"docstring": "Checks if placing the number 'num' in the position (row, col) is valid\naccording to Sudoku rules.",
"function_declaration": "def is_valid(board, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": "Solves the Sudoku puz... | [
1,
1,
1,
1,
1,
1,
0,
0,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def solve_sudoku(sudoku_grid):\n \"\"\"\n Solves a given Sudoku puzzle.\n \n Args:\n sudoku_grid (list of list of int): A 2D list representing the Sudoku grid, where 0 denotes ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026034",
"row_id": 26034,
"seed_ids": "['magpie_prefill_26034']"
} | 0.52039 | Prefill_26034 | I | [
"is_valid",
"solve_sudoku",
"find_empty",
"solve_sudoku_puzzle"
] | 4 | [
[
"solve_sudoku",
"find_empty"
],
[
"solve_sudoku",
"is_valid"
],
[
"solve_sudoku_puzzle",
"solve_sudoku"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | c9e04604b269721835c371de23aed306e2c79e22 | ae6cf32c97ba9cd18f5ec038b65be37eefe8c254 | |||
v1.0 | instruct | Prefill | Prefill_26157_I | Create a function that sorts an array using the merge sort algorithm. Merge sort should be implemented using recursion. | def merge_sort(arr):
"""
Sorts an array using the merge sort algorithm. Merge sort is implemented using recursion.
:param arr: List of elements to be sorted
:return: Sorted list
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
r... | from solution import merge_sort
def test_merge_sort_empty_array():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_array():
ass... | [
{
"docstring": "Sorts an array using the merge sort algorithm. Merge sort is implemented using recursion.\n\n:param arr: List of elements to be sorted\n:return: Sorted list",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstr... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array using the merge sort algorithm.\n \n Parameters:\n arr (list): List of elements to be sorted.\n \n Returns:\n list: New ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026157",
"row_id": 26157,
"seed_ids": "['magpie_prefill_26157']"
} | 0.794956 | Prefill_26157 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84f295b176930e841eaeda5fbaad41c381abbd33 | 9aaca3312491e179849bf7597b3125b5f904de2a | |||
v1.0 | instruct | Prefill | Prefill_26182_I | Create a function that accepts an integer as an argument and returns whether it is a Happy Number. Here is the definition of a Happy Number: A happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit, and eventually reaches 2 if it does not. In the implementation, both th... | def reachSlow(n):
"""
Returns the sum of squares of the digits of n.
"""
return sum(int(digit) ** 2 for digit in str(n))
def reachFast(n):
"""
Returns the next number by applying the sum of squares of the digits twice.
"""
return reachSlow(reachSlow(n))
def is_happy_number(n):
"""
... | from solution import is_happy_number
# Test cases
def test_happy_number_1():
assert is_happy_number(1) == True
def test_happy_number_19():
assert is_happy_number(19) == True
def test_happy_number_7():
assert is_happy_number(7) == True
def test_unhappy_number_2():
assert is_happy_number(2) == False
... | [
{
"docstring": "Returns the sum of squares of the digits of n.",
"function_declaration": "def reachSlow(n):",
"function_name": "reachSlow",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next number by applying the sum of squares of the digits twice.",
"function_declaration": "de... | [
0,
1,
0,
1,
1,
0,
0,
1,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_happy_number(n):\n \"\"\"\n Returns whether a number n is a Happy Number.\n A Happy Number is a number which eventually reaches 1 when replaced by the... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026182",
"row_id": 26182,
"seed_ids": "['magpie_prefill_26182']"
} | 0.538329 | Prefill_26182 | I | [
"reachSlow",
"reachFast",
"is_happy_number"
] | 3 | [
[
"is_happy_number",
"reachFast"
],
[
"is_happy_number",
"reachSlow"
],
[
"reachFast",
"reachSlow"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 593a85e690c52cde98c8cef585a3d10518a1a737 | 36f83d8f6cbc21e8df5b2c2605f182184f759ab4 | |||
v1.0 | instruct | Prefill | Prefill_26236_I | Create a function that generates and returns a list of all prime numbers within a given range, inclusive of the start and end of the range. The prime numbers should be in ascending order. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import generate_primes_in_range
def test_primes_in_standard_range():
assert generate_primes_in_range(10, 20) == [11, 13, 17, 19]
def test_primes_with_no_primes_in_range():
assert generate_primes_in_range(14, 16) == []
def test_primes_single_prime_in_range():
assert generate_primes_in_range(... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of all prime numbers within a given range, inclusive.",
"function_declaration": "def genera... | [
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 if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026236",
"row_id": 26236,
"seed_ids": "['magpie_prefill_26236']"
} | 0.631885 | Prefill_26236 | I | [
"is_prime",
"generate_primes_in_range"
] | 2 | [
[
"generate_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1fde288016b9a8ba4f8abdd2eeed3fa3baff775e | 42069241f05439e23e34a0ac6be6bffdcff501f9 | |||
v1.0 | instruct | Prefill | Prefill_26325_I | Create a function that generates the first `n` Fibonacci numbers using a generator function in Python. Then, write a loop to sum these numbers. | def fibonacci_generator(n):
"""
A generator function that yields the first n Fibonacci numbers.
"""
a, b = 0, 1
count = 0
while count < n:
yield a
a, b = b, a + b
count += 1
def sum_fibonacci(n):
"""
Sums the first n Fibonacci numbers.
"""
return sum(fibo... | from solution import fibonacci_generator, sum_fibonacci
def test_fibonacci_generator():
assert list(fibonacci_generator(0)) == []
assert list(fibonacci_generator(1)) == [0]
assert list(fibonacci_generator(2)) == [0, 1]
assert list(fibonacci_generator(5)) == [0, 1, 1, 2, 3]
def test_sum_fibonacci():
... | [
{
"docstring": "A generator function that yields the first n Fibonacci numbers.",
"function_declaration": "def fibonacci_generator(n):",
"function_name": "fibonacci_generator",
"parameter_list": "(n)"
},
{
"docstring": "Sums the first n Fibonacci numbers.",
"function_declaration": "def s... | [
1,
1,
1,
1,
1,
1,
0,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_generator(n):\n \"\"\"\n Generates the first n Fibonacci numbers.\n \n :param n: The number of Fibonacci numbers to generate.\n :yield: The next Fibonacci number ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026325",
"row_id": 26325,
"seed_ids": "['magpie_prefill_26325']"
} | 0.672987 | Prefill_26325 | I | [
"fibonacci_generator",
"sum_fibonacci"
] | 2 | [
[
"sum_fibonacci",
"fibonacci_generator"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 34e887e910b38541a6f7d861f3eec1d1ed051a7c | c1d45763f2190ce2a98bd3d829d5b0be855bef6e | |||
v1.0 | instruct | Prefill | Prefill_26394_I | Create a function that takes a list as an argument and returns a new list with all the list items containing vowels in them. | def contains_vowel(word):
"""
Helper function to check if a word contains a vowel
"""
vowels = 'aeiouAEIOU'
return any(char in vowels for char in word)
def filter_words_with_vowels(words_list):
"""
Function to filter out words containing vowels from a list.
"""
return [word for word... | from solution import filter_words_with_vowels
def test_filter_words_with_vowels_all_vowel_words():
assert filter_words_with_vowels(['apple', 'orange', 'grape']) == ['apple', 'orange', 'grape']
def test_filter_words_with_vowels_mixed_words():
assert filter_words_with_vowels(['sky', 'apple', 'try']) == ['apple'... | [
{
"docstring": "Helper function to check if a word contains a vowel",
"function_declaration": "def contains_vowel(word):",
"function_name": "contains_vowel",
"parameter_list": "(word)"
},
{
"docstring": "Function to filter out words containing vowels from a list.",
"function_declaration"... | [
1,
1,
1,
0,
1,
1,
1,
1,
0,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def filter_vowels(words):\n \"\"\"\n Returns a list of words that contain at least one vowel.\n \"\"\"\n vowels = set(\"aeiouAEIOU\")\n def has_vowel(word):\n return any... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00026394",
"row_id": 26394,
"seed_ids": "['magpie_prefill_26394']"
} | 0.699371 | Prefill_26394 | I | [
"contains_vowel",
"filter_words_with_vowels"
] | 2 | [
[
"filter_words_with_vowels",
"contains_vowel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0563456d7edddf7915ab6a09c837ae95d6af7217 | e3d471b5872c680064d84248891f7f7dd5895796 | |||
v1.0 | instruct | Prefill | Prefill_26403_I | Create a function that calculates the factorial of a number using recursion. The function should handle large numbers efficiently and manage potential stack overflow errors by setting a reasonable recursion limit (using a loop to call the function until the limit is reached). Additionally, the function should be able t... | import sys
def factorial(n):
"""
Returns the factorial of n using recursion.
Handles large numbers efficiently by adjusting the recursion limit and
raises a ValueError for negative inputs.
"""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers.")
if n == 0 or... | from solution import factorial
import pytest
def test_factorial_zero():
assert factorial(0) == 1
def test_factorial_one():
assert factorial(1) == 1
def test_factorial_small_number():
assert factorial(5) == 120
def test_factorial_large_number():
assert factorial(20) == 2432902008176640000
def test_f... | [
{
"docstring": "Returns the factorial of n using recursion.\n\nHandles large numbers efficiently by adjusting the recursion limit and\nraises a ValueError for negative inputs.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\n\ndef factorial(n):\n \"\"\"\n Returns the factorial of a number using recursion with a safeguard against\n large input that could cause stack overflow.\n \n Args:\... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00026403",
"row_id": 26403,
"seed_ids": "['magpie_prefill_26403']"
} | 0.653705 | Prefill_26403 | I | [
"factorial",
"_factorial_recursive"
] | 2 | [
[
"factorial",
"_factorial_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3f277221dac7e1d3dfba3cd6a62303bb810a523 | 1fbaaa27862b8176fcba0c3b5c7fa7ed59f83630 | |||
v1.0 | instruct | Prefill | Prefill_26511_I | Create a function that finds all the prime numbers within a given range of integers. The function should take two parameters, `start` and `end`, and return a list of all prime numbers between `start` and `end` (inclusive). | def is_prime_number(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return ... | from solution import find_primes_in_range
def test_find_primes_in_range_inclusive():
assert find_primes_in_range(10, 20) == [11, 13, 17, 19]
def test_find_primes_in_range_no_primes():
assert find_primes_in_range(24, 28) == []
def test_find_primes_in_range_single_prime():
assert find_primes_in_range(18, 1... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime_number(num):",
"function_name": "is_prime_number",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers between start and end (inclusive).",
"function_declar... | [
1,
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026511",
"row_id": 26511,
"seed_ids": "['magpie_prefill_26511']"
} | 0.629362 | Prefill_26511 | I | [
"is_prime_number",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1aa5b8eeab23a58413fccb4ead5c5f681440d33 | e6c939e27237c187a9aa80aa74fd67ff47a3a0fb | |||
v1.0 | instruct | Prefill | Prefill_26557_I | Create a function that generates a prime number greater than a given input number `n`. If the number is prime, return it; otherwise, find the next prime number and return it. | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def next_prime(n):
"""
Returns the next prime number greater than n. If n is prime, return n.
... | from solution import is_prime, next_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(23) == True
def test_next_prime_with_prime_input():
assert next_prime... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the next prime number greater than n. If n is prime, return n.",
"function_declaration": "def next_prime(n):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sympy\n\ndef next_prime(n):\n \"\"\"\n Returns the next prime number greater than or equal to n.\n \"\"\"\n if n <= 1:\n return 2\n prime_candidate = n\n while... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026557",
"row_id": 26557,
"seed_ids": "['magpie_prefill_26557']"
} | 0.662639 | Prefill_26557 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | db53d081915c645092b9207687d2e8ca47af01e3 | 0030fff65faf31e5588ff4c2a2702f424dccbd32 | |||
v1.0 | instruct | Prefill | Prefill_26593_I | Create a function that takes an integer as an input and returns a string that displays the integer in words. For example, if the input is 4, the output should be "forty". If the input is 123, the output should be "one hundred twenty-three". | def number_to_words(num):
# Helper function to handle numbers less than 1000
def helper(n):
if n < 20:
return below_20[n]
elif n < 100:
return tens[n // 10] + ('' if n % 10 == 0 else '-' + below_20[n % 10])
else:
return below_20[n // 100] + ' hundred' ... | from solution import number_to_words
def test_number_to_words_single_digits():
assert number_to_words(0) == "zero"
assert number_to_words(1) == "one"
assert number_to_words(9) == "nine"
def test_number_to_words_two_digits():
assert number_to_words(10) == "ten"
assert number_to_words(19) == "ninete... | [
{
"docstring": null,
"function_declaration": "def number_to_words(num):",
"function_name": "number_to_words",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def chunk_number(num):",
"function_name": "chunk_number",
"parameter_list": "(num)"
},
{
... | [
1,
1,
0,
1,
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": "def number_to_words(num):\n if num == 0:\n return \"zero\"\n \n ones = [\"\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"]\n te... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026593",
"row_id": 26593,
"seed_ids": "['magpie_prefill_26593']"
} | 0.629434 | Prefill_26593 | I | [
"number_to_words",
"chunk_number"
] | 2 | [
[
"number_to_words",
"chunk_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f2965fdb142f8f63a98b152e08d7ebba53dc7556 | cc7f5fe97eb3c4f4fd25b7d9b60dda220b038c11 | |||
v1.0 | instruct | Prefill | Prefill_26730_I | Create a function that generates a list of all prime numbers between the given range [start, end]. The function should efficiently check for primality. | def is_prime(n):
"""
Helper function to determine 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
... | from solution import primes_in_range
def test_primes_in_small_range():
assert primes_in_range(1, 10) == [2, 3, 5, 7]
def test_primes_in_medium_range():
assert primes_in_range(10, 30) == [11, 13, 17, 19, 23, 29]
def test_primes_with_no_primes():
assert primes_in_range(14, 16) == []
def test_primes_single... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers in the range [start, end].",
"function_declaration": "def primes_... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00026730",
"row_id": 26730,
"seed_ids": "['magpie_prefill_26730']"
} | 0.567154 | Prefill_26730 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 765e14ad684e37b22f00beb106d685048fbb8177 | 6c429eccb3faa59657a74297bee10033a27cc148 | |||
v1.0 | instruct | Prefill | Prefill_26955_I | Create a function that takes an integer as input and returns the sum of all prime numbers up to and including that integer. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | from solution import is_prime, sum_primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(30) == False
def test_sum_primes_up_to():
assert sum_primes_up_to(10... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers up to and including n.",
"function_declaration": "def sum_primes_up_to(n):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00026955",
"row_id": 26955,
"seed_ids": "['magpie_prefill_26955']"
} | 0.65555 | Prefill_26955 | I | [
"is_prime",
"sum_primes_up_to"
] | 2 | [
[
"sum_primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e1fa8471d8216d4ee9a5cee755feff7afaac6b9 | 083ba266c97a54f47560b77e6c88c3774621e3a2 | |||
v1.0 | instruct | Prefill | Prefill_26987_I | Create a function that takes an array of integers and returns the only prime number found in the array. If no prime number is found, return 0. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def find_prime_... | from solution import find_prime_in_array
def test_find_prime_in_array_single_prime():
assert find_prime_in_array([4, 6, 8, 11, 12]) == 11
def test_find_prime_in_array_no_primes():
assert find_prime_in_array([4, 6, 8, 10, 12]) == 0
def test_find_prime_in_array_multiple_primes():
assert find_prime_in_array... | [
{
"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 only prime number in the array.\nIf no prime number is found, return 0.",
"function_declaration... | [
1,
1,
0,
1,
0,
1,
0,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Helper function to determine if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00026987",
"row_id": 26987,
"seed_ids": "['magpie_prefill_26987']"
} | 0.634694 | Prefill_26987 | I | [
"is_prime",
"find_prime_in_array"
] | 2 | [
[
"find_prime_in_array",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 10457cf829d6fa2b200e4c13e25d656a75bf5ae0 | 3210b0f14307fb2c61a91b9ff694109505346fc2 | |||
v1.0 | instruct | Prefill | Prefill_27007_I | Create a function that takes two integers `a` and `b` as input and returns the sum of `a` and `b`. Validate the input to ensure both are integers and raise a ValueError if they are not. If the sum is an even number, return the sum multiplied by 3; otherwise, return the sum as is. | def validate_integer(value):
"""
Validates if the provided value is an integer.
"""
if not isinstance(value, int):
raise ValueError(f"Value {value} is not an integer.")
def custom_sum(a, b):
"""
Returns the sum of a and b with post-processing:
- If the sum is even, returns the sum m... | import pytest
from solution import custom_sum, validate_integer
def test_custom_sum_even_result():
assert custom_sum(2, 2) == 12 # 4 is even, 4 * 3 = 12
def test_custom_sum_odd_result():
assert custom_sum(1, 2) == 3 # 3 is odd, should return 3
def test_custom_sum_negative_numbers():
assert custom_sum(... | [
{
"docstring": "Validates if the provided value is an integer.",
"function_declaration": "def validate_integer(value):",
"function_name": "validate_integer",
"parameter_list": "(value)"
},
{
"docstring": "Returns the sum of a and b with post-processing:\n- If the sum is even, returns the sum... | [
0,
1,
0,
1,
0,
0,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def custom_add(a, b):\n \"\"\"\n Returns the sum of a and b after validating that both are integers.\n If the sum is an even number, returns the sum multiplied by 3.\n Otherwise, ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00027007",
"row_id": 27007,
"seed_ids": "['magpie_prefill_27007']"
} | 0.726509 | Prefill_27007 | I | [
"validate_integer",
"custom_sum"
] | 2 | [
[
"custom_sum",
"validate_integer"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 368fc05da47c0f07c00d4e38a0236e2d5e17ea19 | 4e0f5b06ec1d2af74d806ef6480a362f1767866b | |||
v1.0 | instruct | Prefill | Prefill_27075_I | Write a python function to find the second largest number in a list using recursion. The function should not use any loops and must be a pure recursive approach. | def find_max(nums):
"""
Recursive helper function to find the maximum number in a list.
"""
if len(nums) == 1:
return nums[0]
else:
return max(nums[0], find_max(nums[1:]))
def find_second_largest(nums):
"""
Recursive function to find the second largest number in a list.
... | from solution import find_second_largest
def test_find_second_largest_typical_case():
assert find_second_largest([1, 3, 4, 5, 0, 2]) == 4
def test_find_second_largest_with_negative_numbers():
assert find_second_largest([10, -1, -10, 20, -5, 2, -8, 20]) == 10
def test_find_second_largest_with_duplicates():
... | [
{
"docstring": "Recursive helper function to find the maximum number in a list.",
"function_declaration": "def find_max(nums):",
"function_name": "find_max",
"parameter_list": "(nums)"
},
{
"docstring": "Recursive function to find the second largest number in a list.",
"function_declarat... | [
0,
0,
1,
1,
0,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_second_largest(numbers):\n \"\"\"\n Find the second largest number in a list using recursion.\n \"\"\"\n if len(numbers) < 2:\n return None # Not enough elements ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00027075",
"row_id": 27075,
"seed_ids": "['magpie_prefill_27075']"
} | 0.629399 | Prefill_27075 | I | [
"find_max",
"find_second_largest"
] | 2 | [
[
"find_second_largest",
"find_max"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c05148f8bed7e8450d830cf182ec5eb48d600b64 | 72a7388e6ed2aeb7549e2b9b193db9bdfd6da4eb | |||
v1.0 | instruct | Prefill | Prefill_27188_I | Write a python function to delete a node from a binary search tree. The function should take the root of the tree, the key (the value of the node to be deleted), and return the root of the modified tree. | class TreeNode:
def __init__(self, key=0, left=None, right=None):
self.key = key
self.left = left
self.right = right
def delete_node(root, key):
"""
Deletes a node with the given key from the binary search tree rooted at the given root.
Returns the root of the modified tree.
... | from solution import TreeNode, delete_node
def bst_to_list(root):
"""
Converts a binary search tree to a sorted list.
"""
if root is None:
return []
return bst_to_list(root.left) + [root.key] + bst_to_list(root.right)
def test_delete_node_leaf():
root = TreeNode(5, TreeNode(3), TreeNod... | [] | [
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": "class TreeNode:\n def __init__(self, key=0, left=None, right=None):\n self.key = key\n self.left = left\n self.right = right\n\ndef delete_node(root, key):\n \"\"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027188",
"row_id": 27188,
"seed_ids": "['magpie_prefill_27188']"
} | 0.487986 | Prefill_27188 | I | [
"delete_node",
"get_min"
] | 2 | [
[
"delete_node",
"get_min"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9fe6c0ed72e4e2a346bc8bb578f531b31b3abcd9 | 6b27d788c24c0a95ce316d27115fb3b0f19a0502 | |||
v1.0 | instruct | Prefill | Prefill_27255_I | Write a python function to compute the shortest distance from a given point to a list of points using the Euclidean distance formula. | from math import sqrt
def euclidean_distance(point1, point2):
"""
Computes the Euclidean distance between two points.
Each point is represented as a tuple of coordinates (x, y).
"""
return sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
def shortest_distance(from_point, points_list):... | from solution import euclidean_distance, shortest_distance
def test_euclidean_distance():
assert round(euclidean_distance((0, 0), (3, 4)), 5) == 5.0
assert round(euclidean_distance((1, 2), (4, 6)), 5) == 5.0
assert round(euclidean_distance((0, 0), (0, 0)), 5) == 0.0
assert round(euclidean_distance((-1,... | [
{
"docstring": "Computes the Euclidean distance between two points.\nEach point is represented as a tuple of coordinates (x, y).",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": ... | [
1,
1,
1,
0,
1,
0,
1,
0,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt(sum((x - y) ** 2 for x, y in zip... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027255",
"row_id": 27255,
"seed_ids": "['magpie_prefill_27255']"
} | 0.666942 | Prefill_27255 | I | [
"euclidean_distance",
"shortest_distance"
] | 2 | [
[
"shortest_distance",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 092f48d76ad30cd3811363eb2d4a7bf645511571 | efb3ebaad67ea267362bd81bc9b320c9134fc3ab | |||
v1.0 | instruct | Prefill | Prefill_27385_I | Write a python function to solve the Sudoku puzzle. | def is_valid(board, row, col, num):
for x in range(9):
if board[row][x] == num or board[x][col] == num:
return False
start_row, start_col = 3 * (row // 3), 3 * (col // 3)
for i in range(3):
for j in range(3):
if board[i + start_row][j + start_col] == num:
... | from solution import solve_sudoku
def test_sudoku_solver():
board = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 6, 0, 0, 0,... | [
{
"docstring": null,
"function_declaration": "def is_valid(board, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, num)"
},
{
"docstring": null,
"function_declaration": "def solve_sudoku(board):",
"function_name": "solve_sudoku",
"parameter_list... | [
0,
0,
1,
1,
1,
1,
1,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def solve_sudoku(board):\n \"\"\"\n Solves a given Sudoku puzzle.\n \n :param board: List[List[int]] A 2D list representing the Sudoku board.\n :return: True if the Sudoku boar... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027385",
"row_id": 27385,
"seed_ids": "['magpie_prefill_27385']"
} | 0.502032 | Prefill_27385 | I | [
"is_valid",
"solve_sudoku",
"find_empty_location"
] | 3 | [
[
"solve_sudoku",
"find_empty_location"
],
[
"solve_sudoku",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3ac936bb2253304348f25093ba97bcc1a6368494 | 90be1aec68eb81611fe135b8b31b13cd4309ce9d | |||
v1.0 | instruct | Prefill | Prefill_27419_I | Write a python function to find the nearest greater node in a Binary Search Tree (BST) for each node's value. You need to return the results in a list where the index represents the index of the original node's value and the value at that index represents the nearest greater node value. If a node in the BST does not ha... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_nearest_greater_node_in_bst(root):
"""
Given the root of a Binary Search Tree (BST), this function finds the nearest greater node in the BST
for each nod... | from solution import TreeNode, find_nearest_greater_node_in_bst, nearest_greater_node_list
def test_single_node():
root = TreeNode(10)
assert nearest_greater_node_list([10], root) == [-1]
def test_multiple_nodes_with_successor():
root = TreeNode(10, TreeNode(5), TreeNode(15))
assert nearest_greate... | [] | [
0,
1,
0,
1,
1,
0,
1,
0,
1,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef find_nearest_greater_node_in_bst(ro... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00027419",
"row_id": 27419,
"seed_ids": "['magpie_prefill_27419']"
} | 0.515336 | Prefill_27419 | I | [
"find_nearest_greater_node_in_bst",
"nearest_greater_node_list"
] | 2 | [
[
"nearest_greater_node_list",
"find_nearest_greater_node_in_bst"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2f7f9a90d42160c143ef9ee0ba359f2d5de5bf84 | 152eee5392a759bb7f63358142ae23ee4accaa4a | |||
v1.0 | instruct | Prefill | Prefill_27511_I | Write a python function to find the sum of the first 100 prime numbers and return that sum. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_first_100_primes():
"""
Returns the sum of the first 100 prime numb... | from solution import is_prime, sum_of_first_100_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
assert is_prime(1) == False
assert is_prime(... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the first 100 prime numbers.",
"function_declaration": "def sum_of_first_100_prim... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00027511",
"row_id": 27511,
"seed_ids": "['magpie_prefill_27511']"
} | 0.631934 | Prefill_27511 | I | [
"is_prime",
"sum_of_first_100_primes"
] | 2 | [
[
"sum_of_first_100_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca5fc4050593aedaf4bfb66cb25bd1bca16eaa15 | e14f57d7b065bc8c0e812d8975a4463058696a13 | |||
v1.0 | instruct | Prefill | Prefill_27545_I | Write a python function to create a binary search tree and check if it is a binary search tree. | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def insert_into_bst(root, val):
if not root:
return TreeNode(val)
if val < root.val:
root.left = insert_into_bst(root.left, val)
else:
... | from solution import TreeNode, insert_into_bst, is_bst
def test_insert_and_is_bst():
values = [10, 5, 15, 3, 7, 12, 17]
tree = None
for value in values:
tree = insert_into_bst(tree, value)
assert is_bst(tree) == True
def test_is_bst_empty_tree():
assert is_bst(None) == True
def test_is_bs... | [] | [
1,
1,
1,
1,
0,
1,
1,
0,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef insert_into_bst(root, value):... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027545",
"row_id": 27545,
"seed_ids": "['magpie_prefill_27545']"
} | 0.680207 | Prefill_27545 | I | [
"insert_into_bst",
"is_bst_helper",
"is_bst"
] | 3 | [
[
"is_bst",
"is_bst_helper"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d4ec08b78509953d1e9da94d0eabcb03d23ec6e6 | 48934f6b137c77b4845a869ca42d5a3eb4c3c8fd | |||
v1.0 | instruct | Prefill | Prefill_27554_I | Write a python function to print all the numbers in a given list that are not perfect squares. | import math
def is_perfect_square(n):
"""
Returns True if n is a perfect square, else False.
"""
if n < 0:
return False
sqrt_n = int(math.sqrt(n))
return sqrt_n * sqrt_n == n
def filter_non_perfect_squares(numbers):
"""
Returns a list of numbers from the input list that are not... | from solution import filter_non_perfect_squares
def test_non_perfect_squares_mixed_list():
assert filter_non_perfect_squares([1, 2, 3, 4, 5, 16, 18]) == [2, 3, 5, 18]
def test_non_perfect_squares_only_perfect_squares():
assert filter_non_perfect_squares([1, 4, 9, 16, 25]) == []
def test_non_perfect_squares_o... | [
{
"docstring": "Returns True if n is a perfect square, else False.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of numbers from the input list that are not perfect squares.",
"functi... | [
1,
1,
0,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(n):\n \"\"\"\n Checks if the given number n is a perfect square.\n \"\"\"\n root = math.isqrt(n) # integer square root of n\n return n == ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027554",
"row_id": 27554,
"seed_ids": "['magpie_prefill_27554']"
} | 0.703453 | Prefill_27554 | I | [
"is_perfect_square",
"filter_non_perfect_squares"
] | 2 | [
[
"filter_non_perfect_squares",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2d9cd43e76ae46ff0ccf43ea2ebbc36a6c4d694 | ec0d9787e5fda50b5cee1da900b9a0d2a045b1fe | |||
v1.0 | instruct | Prefill | Prefill_27629_I | Write a python function to remove all invalid parentheses from a string so that the result string is valid. Return all possible results. Your solution should be able to handle multiple test cases efficiently. | from collections import deque
def removeInvalidParentheses(s):
"""
Removes all invalid parentheses from a string so that the result string is valid.
Returns all possible results.
"""
if not s:
return [""]
results = set()
queue = deque([s])
visited = set([s])
found = False
... | from solution import removeInvalidParentheses
def test_removeInvalidParentheses():
assert set(removeInvalidParentheses("()())()")) == set(["()()()", "(())()"])
assert set(removeInvalidParentheses("(a)())()")) == set(["(a)()()", "(a())()"])
assert set(removeInvalidParentheses(")(")) == set([""])
assert ... | [
{
"docstring": "Removes all invalid parentheses from a string so that the result string is valid.\nReturns all possible results.",
"function_declaration": "def removeInvalidParentheses(s):",
"function_name": "removeInvalidParentheses",
"parameter_list": "(s)"
},
{
"docstring": "Checks if a g... | [
1,
0,
1,
0,
0,
0,
0,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef remove_invalid_parentheses(s):\n \"\"\"\n Removes all invalid parentheses from the string s \n and returns all possible results.\n \"\"\"\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00027629",
"row_id": 27629,
"seed_ids": "['magpie_prefill_27629']"
} | 0.745872 | Prefill_27629 | I | [
"removeInvalidParentheses",
"isValid"
] | 2 | [
[
"removeInvalidParentheses",
"isValid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0cae9a53c9bf6ede7292315220ee859356af673d | 3dacc21b4e286a3dcdb38722d0cf5e262604a555 | |||
v1.0 | instruct | Prefill | Prefill_27648_I | Write a python function to find the count of an element in a sorted array using binary search. The function signature is `def find_count(arr, x)`, where 'arr' is the sorted array and 'x' is the element whose count needs to be found. If the element is not found, the function should return -1. | def binary_search(arr, x, search_first):
low = 0
high = len(arr) - 1
result = -1
while low <= high:
mid = (low + high) // 2
if arr[mid] == x:
result = mid
if search_first:
high = mid - 1
else:
low = mid + 1... | from solution import find_count
def test_element_present_multiple_times():
assert find_count([1, 2, 2, 2, 3, 4, 5], 2) == 3
def test_element_present_once():
assert find_count([1, 2, 3, 4, 5], 3) == 1
def test_element_not_present():
assert find_count([1, 2, 3, 4, 5], 6) == -1
def test_empty_array():
... | [
{
"docstring": null,
"function_declaration": "def binary_search(arr, x, search_first):",
"function_name": "binary_search",
"parameter_list": "(arr, x, search_first)"
},
{
"docstring": "Returns the count of 'x' in the sorted array 'arr'.\nIf 'x' is not present, returns -1.",
"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 find_count(arr, x):\n def binary_search(arr, x, search_first):\n low, high = 0, len(arr) - 1\n result = -1\n while low <= high:\n mid = (low + high) // ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027648",
"row_id": 27648,
"seed_ids": "['magpie_prefill_27648']"
} | 0.715016 | Prefill_27648 | I | [
"binary_search",
"find_count"
] | 2 | [
[
"find_count",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a65bccef229adf3a802cf30e9b1a2e148ba2aba1 | 0ab5f3122874d277fb83ce227196bd94c6ba2215 | |||
v1.0 | instruct | Prefill | Prefill_27659_I | Write a python function to find the largest prime number less than a given number n using the Sieve of Eratosthenes algorithm. | def sieve_of_eratosthenes(n):
"""
Returns a list of all prime numbers less than n using the Sieve of Eratosthenes algorithm.
"""
if n <= 2:
return []
is_prime = [True] * n
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if is_prime[i]:
for j ... | from solution import largest_prime_less_than
def test_prime_less_than_10():
assert largest_prime_less_than(10) == 7
def test_prime_less_than_20():
assert largest_prime_less_than(20) == 19
def test_prime_less_than_2():
assert largest_prime_less_than(2) is None
def test_prime_less_than_50():
assert la... | [
{
"docstring": "Returns a list of all prime numbers less than n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number less tha... | [
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 largest_prime_less_than(n):\n \"\"\"\n Returns the largest prime number less than n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n if n <= 2:\n return None # Th... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00027659",
"row_id": 27659,
"seed_ids": "['magpie_prefill_27659']"
} | 0.69969 | Prefill_27659 | I | [
"sieve_of_eratosthenes",
"largest_prime_less_than"
] | 2 | [
[
"largest_prime_less_than",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de626ed5a265f4f7d10eaaf943c07ba284410bde | 0e1a99b80d6f68d3275b4c912d2571b715348e54 | |||
v1.0 | instruct | Prefill | Prefill_27660_I | Write a python function to check if a binary tree is a sub-tree of another binary tree. A binary tree is a sub-tree of another binary tree if there exists a node in the larger binary tree such that the smaller binary tree rooted at this node is identical to the smaller binary tree. | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_subtree(s, t):
if not s:
return False
if is_same_tree(s, t):
return True
return is_subtree(s.left, t) or is_subtree(s.right, t)
def is_sam... | from solution import TreeNode, is_subtree, is_same_tree
def test_is_same_tree():
tree1 = TreeNode(1, TreeNode(2), TreeNode(3))
tree2 = TreeNode(1, TreeNode(2), TreeNode(3))
assert is_same_tree(tree1, tree2)
tree3 = TreeNode(1, TreeNode(2), TreeNode(4))
assert not is_same_tree(tree1, tree3)
... | [] | [
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_identical(tree1: TreeNode, tree2... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00027660",
"row_id": 27660,
"seed_ids": "['magpie_prefill_27660']"
} | 0.599144 | Prefill_27660 | I | [
"is_subtree",
"is_same_tree"
] | 2 | [
[
"is_subtree",
"is_same_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | daae6f82ca995a1c9705ad0b8c1ed5ed353bdc07 | 1c63536f2908241640470f86e089438fa241fa16 | |||
v1.0 | instruct | Prefill | Prefill_27703_I | Write a python function to compute n-th Fibonacci number using matrix exponentiation. | 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_power(matrix, n):
"""
Raises the matrix to... | from solution import fibonacci
def test_fibonacci_zero():
assert fibonacci(0) == 0
def test_fibonacci_one():
assert fibonacci(1) == 1
def test_fibonacci_small_numbers():
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
def test_fibonacci_lar... | [
{
"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 the matrix to the power of n using binary exponentiation.",
"function_declaration": "def matrix_po... | [
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 matrix_mult(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027703",
"row_id": 27703,
"seed_ids": "['magpie_prefill_27703']"
} | 0.65603 | Prefill_27703 | I | [
"matrix_mult",
"matrix_power",
"fibonacci"
] | 3 | [
[
"fibonacci",
"matrix_power"
],
[
"matrix_power",
"matrix_mult"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8d5d9ec209c64f68c5b4e70aee009ad2d3b7c038 | e20361244da3708dca8f8d76e53b96d9f9808087 | |||
v1.0 | instruct | Prefill | Prefill_28034_I | Write a python function to detect the "Longest Palindromic Subsequence" in a string. The function should return the longest palindromic subsequence. | def longest_palindromic_subsequence(s):
"""
Returns the longest palindromic subsequence in a string.
"""
n = len(s)
if n == 0:
return ""
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - c... | from solution import longest_palindromic_subsequence
def test_longest_palindromic_subsequence_single_char():
assert longest_palindromic_subsequence("a") == "a"
def test_longest_palindromic_subsequence_empty_string():
assert longest_palindromic_subsequence("") == ""
def test_longest_palindromic_subsequence_re... | [
{
"docstring": "Returns the longest palindromic subsequence in a string.",
"function_declaration": "def longest_palindromic_subsequence(s):",
"function_name": "longest_palindromic_subsequence",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def reconstruct_palin... | [
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 longest_palindromic_subsequence(s):\n \"\"\"\n Returns the longest palindromic subsequence in a given string s.\n \"\"\"\n n = len(s)\n \n # Create a table to store resu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028034",
"row_id": 28034,
"seed_ids": "['magpie_prefill_28034']"
} | 0.855539 | Prefill_28034 | I | [
"longest_palindromic_subsequence",
"reconstruct_palindrome"
] | 2 | [
[
"longest_palindromic_subsequence",
"reconstruct_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 16de056df0088d731541caa0c834d8e37a54e434 | b247e2a76e072b5c94b25db9a160069bdaeae6fa | |||
v1.0 | instruct | Prefill | Prefill_28130_I | Write a python function to return the smallest palindrome greater than the given number. The function should have at least 3 inputs: the given number, the length of the given number, and the number of possible digits. | def is_palindrome(n):
# Helper function to check if a number is a palindrome
s = str(n)
return s == s[::-1]
def next_palindrome(num, length, digits):
"""
Returns the smallest palindrome greater than the given number.
:param num: The given number
:param length: The length of the given number... | from solution import next_palindrome, is_palindrome
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
assert is_palindrome(123321) == True
def test_next_palindrome():
assert next_palin... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the smallest palindrome greater than the given number.\n:param num: The given number\n:param length: The length of the given number\n:par... | [
1,
1,
1,
1,
1,
0,
0,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef next_palindrome(n, length, num_digits):\n while True:\n n += 1\n if is_palindrome(n):\n return n",
... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00028130",
"row_id": 28130,
"seed_ids": "['magpie_prefill_28130']"
} | 0.815403 | Prefill_28130 | I | [
"is_palindrome",
"next_palindrome"
] | 2 | [
[
"next_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f09dd86d0f3856ab81d5474b24ae098e8c0bc22d | 485d6bfed176b2647131d4e8ef4b64b0ba5650e8 | |||
v1.0 | instruct | Prefill | Prefill_28196_I | Write a python function to generate all the prime numbers from 10 to 50. | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
... | from solution import primes_in_range
def test_primes_in_range_10_to_50():
expected_primes = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
assert primes_in_range(10, 50) == expected_primes
def test_primes_in_range_1_to_10():
expected_primes = [2, 3, 5, 7]
assert primes_in_range(1, 10) == expected_primes... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate all prime numbers in the given range [start, end].",
"function_declaration": "def primes_in_range(start, end... | [
1,
1,
0,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes_10_to_50():\n \"\"\"\n Generates all prime numbers in the range from 10 to 50 inclusive.\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return Fa... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00028196",
"row_id": 28196,
"seed_ids": "['magpie_prefill_28196']"
} | 0.645454 | Prefill_28196 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6e901fded4941cfc37f8022e3bd9a5bed5b1439 | 0c0cd5906d8b8cabd57ff734801efbf95ee7f1ca | |||
v1.0 | instruct | Prefill | Prefill_28356_I | Write a python function to create a list of all prime numbers up to a given limit `n`. The function should be efficient and avoid unnecessary computations. | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, list_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(25) == False
assert is_prime(1) == False
assert is_prime(0) == False
def test_list_primes():
ass... | [
{
"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 up to the given limit.",
"function_declaration": "def list_primes(l... | [
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 sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers up to the given limit `n` using the Sieve of Eratosthenes algorithm.\n \n :param n: int - The upper li... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00028356",
"row_id": 28356,
"seed_ids": "['magpie_prefill_28356']"
} | 0.69316 | Prefill_28356 | I | [
"is_prime",
"list_primes"
] | 2 | [
[
"list_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 636963c69197c24adfecb35c08545dd5b0692fde | f79e202cc4490f22399deab2c0cfa8b0e423cbab | |||
v1.0 | instruct | Prefill | Prefill_28427_I | Write a python function to generate the first n (n>0) numbers in the sequence where each number is the sum of the previous number and its reverse. | def reverse_number(n):
"""
Returns the reverse of a given integer n.
"""
reversed_n = int(str(n)[::-1])
return reversed_n
def generate_sequence(n):
"""
Generates the first n numbers in the sequence where each number is the
sum of the previous number and its reverse.
"""
if n <=... | from solution import generate_sequence
def test_generate_sequence_single_element():
assert generate_sequence(1) == [1]
def test_generate_sequence_two_elements():
assert generate_sequence(2) == [1, 2] # 1 + reversed(1) = 2
def test_generate_sequence_three_elements():
assert generate_sequence(3) == [1, 2,... | [
{
"docstring": "Returns the reverse of a given integer n.",
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first n numbers in the sequence where each number is the \nsum of the previous number and ... | [
1,
0,
0,
1,
0,
1,
1,
0,
1,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_sequence(n):\n \"\"\"\n Generates the first n numbers in the sequence where each number is the sum\n of the previous number and its reverse.\n \n Parameters:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00028427",
"row_id": 28427,
"seed_ids": "['magpie_prefill_28427']"
} | 0.633879 | Prefill_28427 | I | [
"reverse_number",
"generate_sequence"
] | 2 | [
[
"generate_sequence",
"reverse_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fbfea2a64e8a3ff2961fc1351b846cef17ec129b | a58d9b764c8d962fe173534131d9ba388214fe94 | |||
v1.0 | instruct | Prefill | Prefill_28573_I | Write a python function to find the minimum number of steps to move from the top-left corner to the bottom-right corner of an MxN matrix using DFS that outputs both least steps to reach the bottom-right corner and the path taken to reach it. The function should also handle cases where the matrix has obstacles. | def get_neighbors(position, matrix):
"""
Get the valid neighbors of a given position in the matrix.
"""
x, y = position
M, N = len(matrix), len(matrix[0])
neighbors = []
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny = x + dx, y + dy
if 0 <= nx < M and 0 <= ny < N ... | from solution import min_steps_and_path_DFS
def test_no_obstacles():
matrix = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
steps, path = min_steps_and_path_DFS(matrix)
assert steps == 4
assert path == [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)]
def test_with_obstacles():
matrix = [... | [
{
"docstring": "Get the valid neighbors of a given position in the matrix.",
"function_declaration": "def get_neighbors(position, matrix):",
"function_name": "get_neighbors",
"parameter_list": "(position, matrix)"
},
{
"docstring": "Find the minimum number of steps to move from the top-left ... | [
1,
0,
1,
1,
0,
1,
1,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_steps_with_path(matrix):\n \"\"\"\n Returns the minimum number of steps to move from the top-left to the bottom-right corner\n of an MxN matrix using DFS and the path taken t... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00028573",
"row_id": 28573,
"seed_ids": "['magpie_prefill_28573']"
} | 0.529095 | Prefill_28573 | I | [
"get_neighbors",
"min_steps_and_path_DFS"
] | 2 | [
[
"min_steps_and_path_DFS",
"get_neighbors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc64df76c6bca8dbea40e521152282c9fd4027a9 | cd24af862ce3bd8264c0881aeb006419e63f1752 | |||
v1.0 | instruct | Prefill | Prefill_28928_I | Write a python function to find the largest palindrome made from the product of two 3-digit numbers given that the largest palindrome made from the product of two 2-digit numbers is 9009 (91 x 99). | def is_palindrome(n):
"""
Check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def largest_palindrome_product():
"""
Returns the largest palindrome made from the product of two 3-digit numbers.
"""
max_palindrome = 0
for i in range(100, 1000):
for j in range(... | from solution import is_palindrome, largest_palindrome_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(12321) == True
assert is_palindrome(1234321) == True
assert is_palindrome(1234567) == False
def test_largest_palindrome... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest palindrome made from the product of two 3-digit numbers.",
"function_declaration": "def l... | [
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_palindrome(n):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef largest_palindrome_product():\n \"\"\"\n Returns the larg... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00028928",
"row_id": 28928,
"seed_ids": "['magpie_prefill_28928']"
} | 0.726414 | Prefill_28928 | I | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1348205c3a4c8300011c38a4a2278663d4a46764 | 8fd5530defcec2274eed70552c2d558efdefd11b | |||
v1.0 | instruct | Prefill | Prefill_29006_I | Write a python function to find all the prime numbers in a range of given numbers. For example, for a range from 10 to 20, the function should return [11, 13, 17, 19]. You can use a helper function to check if a number is prime or not. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import is_prime, primes_in_range
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(16) == False
assert is_prime(17) == True
def test_primes_in_range():
assert primes_in_range(10, 2... | [
{
"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 in the given range [start, end].",
"function_declaration": "def primes_in_r... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029006",
"row_id": 29006,
"seed_ids": "['magpie_prefill_29006']"
} | 0.689546 | Prefill_29006 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4bedaa0c710a6db179bae960b959a20a6a30097d | c92c66e74a3f744eb828fa85638bb6e4a1dc8ef1 | |||
v1.0 | instruct | Prefill | Prefill_29112_I | Write a python function to calculate the sum of the first N natural numbers and then find the common sum when you add up the sums of the first N natural numbers for the first M terms. That is, calculate \((1+2+3+...+N) + (1+2+3+...+(N+1)) + (1+2+3+...+(N+2)) + ... + (1+2+3+...+(N+M-1)) + (1+2+3+...+(N+M))\). | def sum_of_first_n_natural_numbers(n):
"""
Returns the sum of the first n natural numbers.
"""
return n * (n + 1) // 2
def common_sum(N, M):
"""
Returns the common sum when you add up the sums of the first N natural numbers
for the first M terms.
"""
total_sum = 0
for i in range... | from solution import sum_of_first_n_natural_numbers, common_sum
def test_sum_of_first_n_natural_numbers():
assert sum_of_first_n_natural_numbers(1) == 1
assert sum_of_first_n_natural_numbers(5) == 15
assert sum_of_first_n_natural_numbers(10) == 55
def test_common_sum():
assert common_sum(1, 1) == 1
... | [
{
"docstring": "Returns the sum of the first n natural numbers.",
"function_declaration": "def sum_of_first_n_natural_numbers(n):",
"function_name": "sum_of_first_n_natural_numbers",
"parameter_list": "(n)"
},
{
"docstring": "Returns the common sum when you add up the sums of the first N nat... | [
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 sum_natural_numbers(N):\n \"\"\"\n Returns the sum of the first N natural numbers.\n \"\"\"\n return N * (N + 1) // 2\n\ndef cumulative_sum_of_sums(N, M):\n \"\"\"\n Ret... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029112",
"row_id": 29112,
"seed_ids": "['magpie_prefill_29112']"
} | 0.640229 | Prefill_29112 | I | [
"sum_of_first_n_natural_numbers",
"common_sum"
] | 2 | [
[
"common_sum",
"sum_of_first_n_natural_numbers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c192346d14be031858505064631f962cb1fc11d | 6cd8268400e7b8f8c08912ef3307311e15c9127b | |||
v1.0 | instruct | Prefill | Prefill_29230_I | Write a python function to create a list of all prime numbers in a given range. The function should accept two arguments: the lower and upper limits of the range. The function should return a list of all prime numbers in the range. | def is_prime(n):
"""Helper function to check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import primes_in_range
def test_primes_in_small_range():
assert primes_in_range(10, 20) == [11, 13, 17, 19]
def test_no_primes_in_range():
assert primes_in_range(24, 28) == []
def test_single_prime_in_range():
assert primes_in_range(22, 23) == [23]
def test_large_range():
expected_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 all prime numbers in the range [lower, upper].",
"function_declaration": "def primes_in_r... | [
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 == 0... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029230",
"row_id": 29230,
"seed_ids": "['magpie_prefill_29230']"
} | 0.658109 | Prefill_29230 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c62942033fed55d2d9e9755c4b7fd70cf4c4e3b | 12d6aa33e54472a5d38a15b29a05666d887d0d99 | |||
v1.0 | instruct | Prefill | Prefill_29263_I | Write a python function to extract the largest area formed by consecutive 'X's in a given binary matrix. | def max_area_of_X(matrix):
"""
Returns the largest area formed by consecutive 'X's in a given binary matrix.
"""
if not matrix:
return 0
rows = len(matrix)
cols = len(matrix[0])
height = [0] * cols
max_area = 0
for i in range(rows):
for j in range(cols):
... | from solution import max_area_of_X
def test_max_area_of_X_empty_matrix():
assert max_area_of_X([]) == 0
def test_max_area_of_X_single_X():
assert max_area_of_X([['X']]) == 1
def test_max_area_of_X_single_row():
assert max_area_of_X([['X', 'X', '0', 'X']]) == 2
def test_max_area_of_X_single_column():
... | [
{
"docstring": "Returns the largest area formed by consecutive 'X's in a given binary matrix.",
"function_declaration": "def max_area_of_X(matrix):",
"function_name": "max_area_of_X",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to calculate the largest rectangle in a hist... | [
0,
0,
0,
0,
1,
0,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_area_of_X(matrix):\n \"\"\"\n Returns the largest area formed by consecutive 'X's in the given binary matrix.\n \n Parameters:\n matrix (list of list of str): A 2D ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029263",
"row_id": 29263,
"seed_ids": "['magpie_prefill_29263']"
} | 0.59062 | Prefill_29263 | I | [
"max_area_of_X",
"largest_rectangle_area"
] | 2 | [
[
"max_area_of_X",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dbc5bded13efdd0093ad144b8c10bbf58be6247c | 54a5b6ca16ff1e52afa5bd8634eac7c4685a8bb0 | |||
v1.0 | instruct | Prefill | Prefill_29269_I | Write a python function to find the first n prime numbers and return them in a list. For example, for n=4, the first 4 prime numbers are [2, 3, 5, 7]. | 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 first_n_primes(n):
"""
Returns the first n prime numbers.
"""
prim... | 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(29) == True
assert is_prime(1) == False
assert is_prime(-5) == False
def test_first_n_primes_1():
assert first_n_primes(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 the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"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": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num %... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029269",
"row_id": 29269,
"seed_ids": "['magpie_prefill_29269']"
} | 0.701158 | Prefill_29269 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f957e6f16900f98443421679298e6853ab4a1cb0 | d46d88f1401408353bfb746e8cc38779d50f1ff7 | |||
v1.0 | instruct | Prefill | Prefill_29357_I | Write a python function to reverse the order of the elements in a stack. You are not allowed to use any additional data structures (like list, array, etc.) and you should only use the built-in stack operations provided in the question. | def reverse_stack(stack):
"""
Reverses the order of the elements in a stack using only stack operations.
"""
if len(stack) > 0:
temp = stack.pop()
reverse_stack(stack)
insert_at_bottom(stack, temp)
def insert_at_bottom(stack, item):
if len(stack) == 0:
stack.append(i... | from solution import reverse_stack
def test_reverse_stack_with_multiple_elements():
stack = [1, 2, 3, 4, 5]
reverse_stack(stack)
assert stack == [5, 4, 3, 2, 1]
def test_reverse_stack_with_one_element():
stack = [1]
reverse_stack(stack)
assert stack == [1]
def test_reverse_stack_with_no_eleme... | [
{
"docstring": "Reverses the order of the elements in a stack using only stack operations.",
"function_declaration": "def reverse_stack(stack):",
"function_name": "reverse_stack",
"parameter_list": "(stack)"
},
{
"docstring": null,
"function_declaration": "def insert_at_bottom(stack, ite... | [
0,
0,
1,
0,
0,
1,
1,
1
] | 4 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Stack:\n def __init__(self):\n self.items = []\n\n def is_empty(self):\n return len(self.items) == 0\n\n def push(self, item):\n self.items.append(item)\n\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029357",
"row_id": 29357,
"seed_ids": "['magpie_prefill_29357']"
} | 0.559568 | Prefill_29357 | I | [
"reverse_stack",
"insert_at_bottom"
] | 2 | [
[
"reverse_stack",
"insert_at_bottom"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8e07af0481a6e7913491f471ca231ac3be8fa9e | e6801126e51c16daa30ce1b9d16ad35c1163fff1 | |||
v1.0 | instruct | Prefill | Prefill_29373_I | Write a python function to find all the prime factors of a given number using the sieve of Eratosthenes. The function should return a list of all prime factors of the input number in ascending order. | def sieve_of_eratosthenes(n):
"""
Helper function that returns a list of prime numbers up to n using the sieve of Eratosthenes.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
... | from solution import prime_factors
def test_prime_factors_of_1():
assert prime_factors(1) == []
def test_prime_factors_of_prime():
assert prime_factors(7) == [7]
def test_prime_factors_of_composite():
assert prime_factors(28) == [2, 2, 7]
def test_prime_factors_of_large_number():
assert prime_factor... | [
{
"docstring": "Helper function that returns a list of prime numbers up to n using the sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime factors of... | [
1,
1,
1,
1,
1,
1,
0,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"Generate a list of prime numbers up to n.\"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while p * p <= n:\n if is_prime[p]:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029373",
"row_id": 29373,
"seed_ids": "['magpie_prefill_29373']"
} | 0.725935 | Prefill_29373 | I | [
"sieve_of_eratosthenes",
"prime_factors"
] | 2 | [
[
"prime_factors",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ed419bb14d895beab0c567de7a78e2a582d5b58 | 575f98797eb1e75545771f2de2abd7eb3702f0dd | |||
v1.0 | instruct | Prefill | Prefill_29397_I | Write a python function to calculate the sum of all prime numbers less than `n`. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes_less_than_n(n):
"""
Returns the sum of all prime numbers less... | from solution import is_prime, sum_of_primes_less_than_n
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_sum_of_pr... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers less than n.",
"function_declaration": "def sum_of_primes_less_tha... | [
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 sum_of_primes(n):\n \"\"\"\n Returns the sum of all prime numbers less than n.\n \"\"\"\n def is_prime(num):\n if num <= 1:\n return False\n if num <=... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00029397",
"row_id": 29397,
"seed_ids": "['magpie_prefill_29397']"
} | 0.730689 | Prefill_29397 | I | [
"is_prime",
"sum_of_primes_less_than_n"
] | 2 | [
[
"sum_of_primes_less_than_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8097b803352761fffeeebfffd554f428c06304f6 | 87b949be58394c5c46940482d02badbaf4e8fb9c | |||
v1.0 | instruct | Prefill | Prefill_29401_I | Write a python function to find the sum of all prime numbers between two integers `n` and `m`. | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes_between(n, m):
"""
Returns the sum of all prime numbers between integ... | from solution import is_prime, sum_of_primes_between
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_sum_of_primes_between():
assert sum_of_primes_between(10, 20) == 60 # p... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers between integers n and m (inclusive).",
"function_declaration": "def sum_of_... | [
0,
0,
1,
1,
1,
1,
1,
0,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029401",
"row_id": 29401,
"seed_ids": "['magpie_prefill_29401']"
} | 0.727389 | Prefill_29401 | I | [
"is_prime",
"sum_of_primes_between"
] | 2 | [
[
"sum_of_primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3bd03a691e9a01d016174b8718dbd877cf49d5eb | 9a1dc826adc9111b0fab4736741363f5da6eccff | |||
v1.0 | instruct | Prefill | Prefill_29635_I | Write a python function to find all the Armstrong numbers within a given range. | def is_armstrong(number):
"""
Check if a number is an Armstrong number.
An Armstrong number of a given number of digits is a number such that the sum of its digits each raised
to the power of the number of digits is equal to the number itself.
"""
digits = list(map(int, str(number)))
num_d... | from solution import is_armstrong, find_armstrong_numbers
def test_is_armstrong():
assert is_armstrong(153) == True
assert is_armstrong(370) == True
assert is_armstrong(371) == True
assert is_armstrong(9474) == True
assert is_armstrong(123) == False
assert is_armstrong(10) == False
def test_fi... | [
{
"docstring": "Check if a number is an Armstrong number.\n\nAn Armstrong number of a given number of digits is a number such that the sum of its digits each raised \nto the power of the number of digits is equal to the number itself.",
"function_declaration": "def is_armstrong(number):",
"function_name... | [
1,
1,
0,
1,
1,
1,
0,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_armstrong_number(num):\n \"\"\"\n Check if a number is an Armstrong number.\n \"\"\"\n num_str = str(num)\n num_len = len(num_str)\n sum_of_powers = sum(int(digit)**n... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029635",
"row_id": 29635,
"seed_ids": "['magpie_prefill_29635']"
} | 0.526041 | Prefill_29635 | I | [
"is_armstrong",
"find_armstrong_numbers"
] | 2 | [
[
"find_armstrong_numbers",
"is_armstrong"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0e08157585cfe3463c69fdb3902349dcbe34649d | 9d111caac3f1344c0e47a0a24ec94027236ffbca | |||
v1.0 | instruct | Prefill | Prefill_29666_I | Write a python function to find the smallest number that is evenly divisible by all numbers from 1 to n. This number is known as the least common multiple (LCM). | from functools import reduce
import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return a * b // math.gcd(a, b)
def smallest_multiple(n):
"""
Returns the smallest number that is evenly divisible by all numbers from 1 to n.
"""
return reduce(lcm, range(1, n ... | 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": "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 number that is evenly divisible by all numbers from 1 to n.",
"function_declaration": "def ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef lcm_of_range(n):\n \"\"\"\n Function to find the smallest number that is evenly divisible by all numbers from 1 to n.\n \"\"\"\n def lcm(a, b):\n return ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029666",
"row_id": 29666,
"seed_ids": "['magpie_prefill_29666']"
} | 0.677634 | Prefill_29666 | I | [
"lcm",
"smallest_multiple"
] | 2 | [
[
"smallest_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 131f0d78da32fce592b8682cfc942151465304d4 | bfae204544c88e9856aa3152cf5ebe7934e90358 | |||
v1.0 | instruct | Prefill | Prefill_29728_I | Write a python function to solve a Sudoku puzzle. The function should take a 2D list representing a Sudoku board and solve it using backtracking. | def solve_sudoku(board):
"""
Solves the Sudoku puzzle using backtracking.
Args:
board: List[List[int]] -- 2D list representing the Sudoku board, with 0 representing empty cells.
Returns:
bool -- True if the Sudoku puzzle is solved, otherwise False.
"""
find = find_empty(board)
... | from solution import solve_sudoku
def test_solve_sudoku():
board = [
[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 6, 0, 0, 0, ... | [
{
"docstring": "Solves the Sudoku puzzle using backtracking.\n\nArgs:\nboard: List[List[int]] -- 2D list representing the Sudoku board, with 0 representing empty cells.\n\nReturns:\nbool -- True if the Sudoku puzzle is solved, otherwise False.",
"function_declaration": "def solve_sudoku(board):",
"funct... | [
1,
1,
0,
1,
1,
1,
1,
1,
0,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid(board, row, col, num):\n \"\"\"\n Check if num can be placed at board[row][col] according to Sudoku rules.\n \"\"\"\n for i in range(9):\n if board[row][i] == ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029728",
"row_id": 29728,
"seed_ids": "['magpie_prefill_29728']"
} | 0.458772 | Prefill_29728 | I | [
"solve_sudoku",
"find_empty",
"is_valid"
] | 3 | [
[
"solve_sudoku",
"find_empty"
],
[
"solve_sudoku",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4f96c2dce0f5042b1b15d00e5e36889462eaf7e0 | aec68c49262833e6c68d026ac1bfd0c84960ecc2 | |||
v1.0 | instruct | Prefill | Prefill_30129_I | Write a python function to create a list of rolling window_view of an array without using numpy. You should write the rolling window_view function and a main function that uses this window_view function to compute the moving average of an array. | def rolling_window(arr, window_size):
"""
Create a list of rolling windows from the input array.
Parameters:
arr (list): Input array.
window_size (int): Size of the rolling window.
Returns:
list: A list of rolling windows.
"""
if window_size > len(arr) or window_size <= 0:
... | from solution import rolling_window, moving_average
def test_rolling_window():
assert rolling_window([1, 2, 3, 4, 5], 3) == [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
assert rolling_window([1, 2, 3, 4, 5], 1) == [[1], [2], [3], [4], [5]]
assert rolling_window([1, 2, 3, 4, 5], 5) == [[1, 2, 3, 4, 5]]
assert roll... | [
{
"docstring": "Create a list of rolling windows from the input array.\n\nParameters:\narr (list): Input array.\nwindow_size (int): Size of the rolling window.\n\nReturns:\nlist: A list of rolling windows.",
"function_declaration": "def rolling_window(arr, window_size):",
"function_name": "rolling_windo... | [
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 rolling_window_view(arr, window_size):\n \"\"\"\n Generate a list of rolling windows of a specified size from an array.\n \n :param arr: List of numbers.\n :param window_si... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030129",
"row_id": 30129,
"seed_ids": "['magpie_prefill_30129']"
} | 0.520386 | Prefill_30129 | I | [
"rolling_window",
"moving_average"
] | 2 | [
[
"moving_average",
"rolling_window"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64fa8ce0e4034232b12d7baee8356041a2382125 | e37c8434f114da0cfd2d456ab3f150cdfa612441 | |||
v1.0 | instruct | Prefill | Prefill_30195_I | Write a python function to calculate the sum of the digits of a given positive integer. The function should also check if the sum is a prime number. If the sum is a prime number, return both the sum and a boolean value `True`. If the sum is not a prime number, return both the sum and a boolean value `False`. | def is_prime(n):
"""
Determines if the provided integer n is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_digits(n):
"""
Calculate the sum of the digits of a given positive ... | from solution import sum_of_digits
def test_single_digit_prime():
assert sum_of_digits(2) == (2, True)
assert sum_of_digits(3) == (3, True)
def test_single_digit_not_prime():
assert sum_of_digits(4) == (4, False)
assert sum_of_digits(6) == (6, False)
def test_multiple_digits_prime():
assert sum_o... | [
{
"docstring": "Determines if the provided integer n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of the digits of a given positive integer n.\nReturns a tuple containing the sum and... | [
0,
0,
1,
1,
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 \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030195",
"row_id": 30195,
"seed_ids": "['magpie_prefill_30195']"
} | 0.707039 | Prefill_30195 | I | [
"is_prime",
"sum_of_digits"
] | 2 | [
[
"sum_of_digits",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c7e5cf367d542e2ac78c15f66ba19fd77131ab3 | 67b395befaf009db049013d9c278a2ab59a502c3 | |||
v1.0 | instruct | Prefill | Prefill_30260_I | Write a python function to find all the prime numbers in a given list of numbers and return a list of those prime numbers. | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def find_primes(numbers):
"""
Returns a list of prime numbers from the given list o... | from solution import is_prime, find_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_find_primes_with_mixed_... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of numbers.",
"function_declaration": "def find_pri... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i =... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030260",
"row_id": 30260,
"seed_ids": "['magpie_prefill_30260']"
} | 0.667777 | Prefill_30260 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2f7edd7f8265d1bdf2aa9d919670ac5361d416be | 1db06a13e8f13e30250400752fd51b9b2b3ed13a | |||
v1.0 | instruct | Prefill | Prefill_30415_I | Write a python function to find the number of elements between a given start value and end value in a sorted array. The function should return the count of elements that are within the range [start, end], inclusive. | def count_elements_in_range(sorted_array, start, end):
"""
Returns the count of elements within the range [start, end] in a sorted array.
:param sorted_array: List[int] - A sorted list of integers
:param start: int - Start of the range (inclusive)
:param end: int - End of the range (inclusive)
... | from solution import count_elements_in_range
def test_count_elements_in_range_all_inclusive():
assert count_elements_in_range([1, 2, 3, 4, 5], 2, 4) == 3
def test_count_elements_in_range_empty_array():
assert count_elements_in_range([], 1, 3) == 0
def test_count_elements_in_range_none_in_range():
assert ... | [
{
"docstring": "Returns the count of elements within the range [start, end] in a sorted array.\n\n:param sorted_array: List[int] - A sorted list of integers\n:param start: int - Start of the range (inclusive)\n:param end: int - End of the range (inclusive)\n:return: int - The count of elements within the range ... | [
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 count_elements_in_range(arr, start, end):\n \"\"\"\n Returns the number of elements between start and end (inclusive)\n in a sorted array.\n \n Parameters:\n - arr: list... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030415",
"row_id": 30415,
"seed_ids": "['magpie_prefill_30415']"
} | 0.591674 | Prefill_30415 | I | [
"count_elements_in_range",
"binary_search_left",
"binary_search_right"
] | 3 | [
[
"count_elements_in_range",
"binary_search_left"
],
[
"count_elements_in_range",
"binary_search_right"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | af740401da241484e3eba7d1de82697bcd075e5a | 4948997ae2af4e844ff6c65a9e80bb0c9f33cdf2 | |||
v1.0 | instruct | Prefill | Prefill_30419_I | Write a python function to return all prime numbers within a given range | 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 primes_in_range(start, end):
"""
Returns a list of all prime numbers within the g... | from solution import primes_in_range
def test_primes_in_small_range():
assert primes_in_range(1, 10) == [2, 3, 5, 7]
def test_primes_in_large_range():
assert primes_in_range(10, 50) == [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
def test_primes_with_no_primes():
assert primes_in_range(14, 16) == []
... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers within the given range [start, end].",
"function_declaration": "def p... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
0
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 =... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030419",
"row_id": 30419,
"seed_ids": "['magpie_prefill_30419']"
} | 0.75495 | Prefill_30419 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 381f068e2490b219482be252ca6c1d9b69f310ee | 5ff92c1b338f3e5a2f1446d0154f4de24a217c95 | |||
v1.0 | instruct | Prefill | Prefill_30448_I | Write a python function to convert a decimal number to a specified base (between 2 and 36). The function should handle decimal numbers, both positive and negative, as well as numbers with fractional parts. The function should also be able to handle non-integer bases, such as 2.5, by rounding them to the nearest whole n... | from math import modf, floor
def decimal_to_base(decimal_number, base):
"""
Converts a decimal number to the specified base (between 2 and 36).
The base is rounded to the nearest integer if it is not an integer.
Args:
decimal_number (float): The decimal number to be converted.
base (float): T... | from solution import decimal_to_base
def test_decimal_to_base_positive_integer():
assert decimal_to_base(10, 2) == "1010"
assert decimal_to_base(10, 16) == "A"
assert decimal_to_base(255, 16) == "FF"
def test_decimal_to_base_negative_integer():
assert decimal_to_base(-10, 2) == "-1010"
assert deci... | [
{
"docstring": "Converts a decimal number to the specified base (between 2 and 36). \nThe base is rounded to the nearest integer if it is not an integer.\n\nArgs:\ndecimal_number (float): The decimal number to be converted.\nbase (float): The base to which the decimal number is to be converted.\n\nReturns:\nstr... | [
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_base(n, base):\n \"\"\"\n Convert a decimal number to a specified base (between 2 and 36).\n Handles both integer and non-integer bases (rounded to nearest whole numbe... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030448",
"row_id": 30448,
"seed_ids": "['magpie_prefill_30448']"
} | 0.757885 | Prefill_30448 | I | [
"decimal_to_base",
"convert_integral_part",
"convert_fractional_part"
] | 3 | [
[
"decimal_to_base",
"convert_fractional_part"
],
[
"decimal_to_base",
"convert_integral_part"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3d8811dd785968dac2f9e8c364e6baa25ebd8110 | fb83ca5dcfc2c26f3e1c14d143c03bfa7288160c | |||
v1.0 | instruct | Prefill | Prefill_30724_I | Write a python function to calculate the factorial of a given number using iteration and another function to calculate the factorial using recursion. Compare their performance and discuss the trade-offs. | def factorial_iterative(n):
"""
Returns the factorial of a given number using iteration.
"""
result = 1
for i in range(2, n + 1):
result *= i
return result
def factorial_recursive(n):
"""
Returns the factorial of a given number using recursion.
"""
if n == 0 or n == 1:
... | import pytest
from solution import factorial_iterative, factorial_recursive, discuss_tradeoffs
def test_factorial_iterative():
assert factorial_iterative(0) == 1
assert factorial_iterative(1) == 1
assert factorial_iterative(5) == 120
assert factorial_iterative(10) == 3628800
def test_factorial_recursi... | [
{
"docstring": "Returns the factorial of a given number using iteration.",
"function_declaration": "def factorial_iterative(n):",
"function_name": "factorial_iterative",
"parameter_list": "(n)"
},
{
"docstring": "Returns the factorial of a given number using recursion.",
"function_declar... | [
1,
1,
1,
1,
1,
1,
0,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef factorial_iterative(n):\n \"\"\"\n Returns the factorial of a given number n using an iterative approach.\n \"\"\"\n if n < 0:\n raise ValueError(\"Facto... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030724",
"row_id": 30724,
"seed_ids": "['magpie_prefill_30724']"
} | 0.62176 | Prefill_30724 | I | [
"factorial_iterative",
"factorial_recursive",
"compare_performance",
"discuss_tradeoffs"
] | 4 | [
[
"compare_performance",
"factorial_iterative"
],
[
"compare_performance",
"factorial_recursive"
],
[
"discuss_tradeoffs",
"compare_performance"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 62aa9d751e88dba313a9b9a3027581dfc30ec17b | f486d0743ab852f01d328c2e0a154cf27db1adcb | |||
v1.0 | instruct | Prefill | Prefill_30758_I | Write a python function to find the factorial of a number iteratively, and another function that compares the results iterating and recursively. | def factorial_iterative(n):
"""
Returns the factorial of n using an iterative approach.
"""
result = 1
for i in range(2, n + 1):
result *= i
return result
def factorial_recursive(n):
"""
Returns the factorial of n using a recursive approach.
"""
if n == 0 or n == 1:
... | from solution import factorial_iterative, factorial_recursive, compare_factorial_methods
def test_factorial_iterative():
assert factorial_iterative(0) == 1
assert factorial_iterative(1) == 1
assert factorial_iterative(5) == 120
assert factorial_iterative(10) == 3628800
def test_factorial_recursive():
... | [
{
"docstring": "Returns the factorial of n using an iterative approach.",
"function_declaration": "def factorial_iterative(n):",
"function_name": "factorial_iterative",
"parameter_list": "(n)"
},
{
"docstring": "Returns the factorial of n using a recursive approach.",
"function_declarati... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial_iterative(n):\n \"\"\"\n Returns the factorial of n using an iterative approach.\n \"\"\"\n result = 1\n for i in range(1, n + 1):\n result *= i\n retur... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030758",
"row_id": 30758,
"seed_ids": "['magpie_prefill_30758']"
} | 0.719766 | Prefill_30758 | I | [
"factorial_iterative",
"factorial_recursive",
"compare_factorial_methods"
] | 3 | [
[
"compare_factorial_methods",
"factorial_iterative"
],
[
"compare_factorial_methods",
"factorial_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 19bf9ae621a38945e8beb3e35932c8f1a28676df | f14c2f7386ef84f0653e0ccfafd9898d908ae4e4 | |||
v1.0 | instruct | Prefill | Prefill_30860_I | Write a python function to calculate the sum of all prime numbers within a given range. The function takes two integers `start` and `end` as input and returns the sum of prime numbers between `start` and `end` (inclusive). | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_pr... | from solution import sum_of_primes
def test_sum_of_primes_within_range():
assert sum_of_primes(1, 10) == 17 # 2, 3, 5, 7 are primes
assert sum_of_primes(10, 20) == 60 # 11, 13, 17, 19 are primes
assert sum_of_primes(1, 5) == 10 # 2, 3, 5 are primes
def test_sum_of_primes_no_primes():
assert sum_of_... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the range [start, end].",
"function_declaration": "def sum_of_p... | [
1,
1,
0,
1,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is prime, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n %... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030860",
"row_id": 30860,
"seed_ids": "['magpie_prefill_30860']"
} | 0.661689 | Prefill_30860 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4184d524d4ad288b54cfedbeb8030719927ca62 | 2a52103f0b27a42e604ecda715a1b3032006223e | |||
v1.0 | instruct | Prefill | Prefill_30879_I | Write a python function to find the sum of squares of all prime numbers upto n | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import is_prime, sum_of_squares_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_sum_of_squares_of_primes():
assert sum_... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of squares of all prime numbers up to n.",
"function_declaration": "def sum_of_squares_... | [
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef 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 <= 3:\n ret... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00030879",
"row_id": 30879,
"seed_ids": "['magpie_prefill_30879']"
} | 0.773502 | Prefill_30879 | I | [
"is_prime",
"sum_of_squares_of_primes"
] | 2 | [
[
"sum_of_squares_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6ba33766a74913494ad56b01337b7577bb2d74d6 | 4bc631e7ce4a1a53c293a5b0efb0cd6139a30ac5 | |||
v1.0 | instruct | Prefill | Prefill_30885_I | Write a python function to solve thePainter's Partition problem using a binary search approach. The function should take an array of non-negative integers representing the time taken to paint each board and an integer m representing the number of painters available. The function should return the minimum time required ... | def is_feasible(boards, n, m, max_time):
"""
Helper function to check if it is feasible to paint all boards within max_time
given m painters.
"""
painters_count = 1
current_time = 0
for time in boards:
if current_time + time <= max_time:
current_time += time
else... | from solution import minimum_time
def test_minimum_time_single_painter():
assert minimum_time([10, 20, 30, 40], 1) == 100
def test_minimum_time_multiple_painters():
assert minimum_time([10, 20, 30, 40], 2) == 60
def test_minimum_time_more_painters_than_boards():
assert minimum_time([10, 20, 30], 5) == 30... | [
{
"docstring": "Helper function to check if it is feasible to paint all boards within max_time\ngiven m painters.",
"function_declaration": "def is_feasible(boards, n, m, max_time):",
"function_name": "is_feasible",
"parameter_list": "(boards, n, m, max_time)"
},
{
"docstring": "Returns the ... | [
1,
0,
1,
0,
1,
1,
0,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_time_to_paint_boards(arr, m):\n \"\"\"\n Determines the minimum time required to paint all boards using binary search.\n \n Args:\n arr: List[int] - An array of non-neg... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030885",
"row_id": 30885,
"seed_ids": "['magpie_prefill_30885']"
} | 0.621428 | Prefill_30885 | I | [
"is_feasible",
"minimum_time"
] | 2 | [
[
"minimum_time",
"is_feasible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6465cd2c1cff6d51ec40f91c530af3a8f33eb00f | b804b8160db24ce0ab6ee4a6eada5378c4550fcf | |||
v1.0 | instruct | Prefill | Prefill_30896_I | Write a python function to find the nth Fibonacci number using the Matrix Exponentiation method. This method involves using matrix exponentiation to efficiently compute Fibonacci numbers, which is particularly useful for large n. Please provide a detailed explanation of the code and the method used. | def matrix_multiply(A, B):
"""
Multiplies two 2x2 matrices A and B.
"""
return [
[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],
[A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]
]
def matrix_power(matrix, n):
"""
... | from solution import matrix_multiply, matrix_power, fibonacci_matrix_exponentiation
def test_matrix_multiply():
A = [[1, 2], [3, 4]]
B = [[2, 0], [1, 2]]
result = matrix_multiply(A, B)
assert result == [[4, 4], [10, 8]]
def test_matrix_power():
matrix = [[1, 1], [1, 0]]
result = matrix_power(m... | [
{
"docstring": "Multiplies two 2x2 matrices A and B.",
"function_declaration": "def matrix_multiply(A, B):",
"function_name": "matrix_multiply",
"parameter_list": "(A, B)"
},
{
"docstring": "Raises the matrix to the power of n using exponentiation by squaring.",
"function_declaration": "... | [
1,
1,
1,
1,
1,
1,
0,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def matrix_mult(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030896",
"row_id": 30896,
"seed_ids": "['magpie_prefill_30896']"
} | 0.678324 | Prefill_30896 | I | [
"matrix_multiply",
"matrix_power",
"fibonacci_matrix_exponentiation"
] | 3 | [
[
"fibonacci_matrix_exponentiation",
"matrix_power"
],
[
"matrix_power",
"matrix_multiply"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 88e5203555b6ad0c9091af4ba0fa155cee8cf767 | 64923b62e35ae0f789ab95b5812713e2525fb6e7 | |||
v1.0 | instruct | Prefill | Prefill_30898_I | Write a python function to perform a merge sort on an array. | def merge_sort(arr):
"""
Performs a merge sort on the input array.
Parameters:
arr (list): The array to sort.
Returns:
list: The sorted array.
"""
if len(arr) <= 1:
return arr
# Find the middle point and divide it
mid = len(arr) // 2
left_half = merge_sort(... | from solution import merge_sort
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_array():
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_merge_sort_unsorted_array():
assert merge_sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) ... | [
{
"docstring": "Performs a merge sort on the input array.\n\nParameters:\narr (list): The array to sort.\n\nReturns:\nlist: The sorted array.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Perform a merge sort on an array.\n \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": "00030898",
"row_id": 30898,
"seed_ids": "['magpie_prefill_30898']"
} | 0.797982 | Prefill_30898 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 679b1099760f90a5d0c1cfed29b9d5e18fc8665b | 05a4f82321c58ccc981a98e9bf99c3dd32cd0ce0 | |||
v1.0 | instruct | Prefill | Prefill_30922_I | Write a python function to identify prime numbers within a given range. The function should find all prime numbers between two integers, inclusive. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Make sure to test your function with some examples to ensure its co... | def is_prime(n):
"""
Determines if a number is prime.
Args:
n (int): The number to check for primality.
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:
r... | from solution import prime_numbers_in_range, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(-... | [
{
"docstring": "Determines if a number is prime.\n\nArgs:\nn (int): The number to check for primality.\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": "Finds ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_primes_in_range(start, end):\n \"\"\"\n Finds all prime numbers in the range from start to end (inclusive).\n :param start: The lower bound of the range (inclusive).\n :p... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030922",
"row_id": 30922,
"seed_ids": "['magpie_prefill_30922']"
} | 0.71181 | Prefill_30922 | I | [
"is_prime",
"prime_numbers_in_range"
] | 2 | [
[
"prime_numbers_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9bd10b904aa3361ea0daa1a7a4bd69a9143f4a2b | 90c81f42fad08d402557069a4119b85af236c721 | |||
v1.0 | instruct | Prefill | Prefill_30959_I | Write a python function to print all the prime numbers between two given numbers (inclusive). The function should accept two integer parameters and print all the prime numbers from the smaller to the greater number. You should also consider edge cases. | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def print_pri... | from solution import is_prime, print_primes_between
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(17) == True
assert is_prime(19) == True
assert is_prime(21) ... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints all prime numbers between a and b (inclusive).",
"function_declaration": "def print_primes_betwe... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030959",
"row_id": 30959,
"seed_ids": "['magpie_prefill_30959']"
} | 0.677569 | Prefill_30959 | I | [
"is_prime",
"print_primes_between"
] | 2 | [
[
"print_primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e67f227d6a384709083c1e95fe2f43a15f891c32 | eb2e373ece702e25b0b3fbefd72376bc8e2f1196 | |||
v1.0 | instruct | Prefill | Prefill_31013_I | Write a python function to reverse a stack using recursion. You can use only one additional stack or no additional stack and you are allowed to use extra space on the recursion call stack. | def reverse_stack(stack):
"""
This function reverses the stack using recursion.
"""
if not stack:
return
# Pop the top element of the stack
top = stack.pop()
# Reverse the remaining stack
reverse_stack(stack)
# Insert the popped element at the bottom of the rev... | from solution import reverse_stack
def test_reverse_stack():
stack = [1, 2, 3, 4, 5]
reverse_stack(stack)
assert stack == [5, 4, 3, 2, 1]
def test_reverse_single_element_stack():
stack = [1]
reverse_stack(stack)
assert stack == [1]
def test_reverse_empty_stack():
stack = []
reverse_st... | [
{
"docstring": "This function reverses the stack using recursion.",
"function_declaration": "def reverse_stack(stack):",
"function_name": "reverse_stack",
"parameter_list": "(stack)"
},
{
"docstring": "A helper function to insert an item at the bottom of a stack.",
"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 insert_at_bottom(stack, item):\n if not stack:\n stack.append(item)\n else:\n top = stack.pop()\n insert_at_bottom(stack, item)\n stack.append(top)\n\nde... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031013",
"row_id": 31013,
"seed_ids": "['magpie_prefill_31013']"
} | 0.505263 | Prefill_31013 | I | [
"reverse_stack",
"insert_at_bottom"
] | 2 | [
[
"reverse_stack",
"insert_at_bottom"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4942186e43e349d8b37e2c07d5e0848b2354358a | 2e2dca494ba6129ef848eb1644bb3ab13468d9ed | |||
v1.0 | instruct | Prefill | Prefill_31039_I | Write a python function to sort an array and then solve a radix sort algorithm using bucket sort as a subroutine. | def bucket_sort(arr):
"""
Sorts an array using bucket sort algorithm.
"""
if len(arr) == 0:
return arr
# Determine minimum and maximum values
min_value = min(arr)
max_value = max(arr)
# Number of buckets
bucket_count = len(arr)
buckets = [[] for _ in range(bucket_count)... | from solution import bucket_sort, radix_sort
def test_bucket_sort_empty():
assert bucket_sort([]) == []
def test_bucket_sort_single_element():
assert bucket_sort([42]) == [42]
def test_bucket_sort_sorted():
assert bucket_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_bucket_sort_unsorted():
asser... | [
{
"docstring": "Sorts an array using bucket sort algorithm.",
"function_declaration": "def bucket_sort(arr):",
"function_name": "bucket_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts an array using radix sort algorithm with bucket sort as subroutine.",
"function_declaration": ... | [
0,
0,
0,
1,
1,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def counting_sort(arr, exp):\n n = len(arr)\n output = [0] * n \n count = [0] * 10\n\n for i in range(n):\n index = (arr[i] // exp) % 10\n count[index] += 1\n\n f... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00031039",
"row_id": 31039,
"seed_ids": "['magpie_prefill_31039']"
} | 0.614956 | Prefill_31039 | I | [
"bucket_sort",
"radix_sort",
"counting_sort_by_digit"
] | 3 | [
[
"radix_sort",
"counting_sort_by_digit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e20483e4880086932e6b239a9adaf4062c31790c | 5a9e82b7cfda00ff508d5048327188fb67da669e | |||
v1.0 | instruct | Prefill | Prefill_31156_I | Write a python function to find the all the fibonacci numbers in a list. Please make sure to handle edge cases properly, like if the list is empty or contains no fibonacci numbers. | def is_fibonacci(n):
if n < 0:
return False
if n == 0 or n == 1:
return True
a, b = 0, 1
while b < n:
a, b = b, a + b
return b == n
def find_fibonacci_in_list(nums):
"""
Finds all Fibonacci numbers in the given list.
Parameters:
nums (list... | from solution import find_fibonacci_in_list
def test_find_fibonacci_in_list_all_fib_numbers():
assert find_fibonacci_in_list([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_find_fibonacci_in_list_mixed_numbers():
assert find_fibonacci_in_list([4, 6, 8, 13, 20, 21]) == [8, 13, ... | [
{
"docstring": null,
"function_declaration": "def is_fibonacci(n):",
"function_name": "is_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Finds all Fibonacci numbers in the given list.\n\nParameters:\nnums (list): List of integers to check for Fibonacci numbers.\n\nReturns:\nlist: A l... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_fibonacci(n):\n \"\"\"\n Check if the number n is part of the Fibonacci sequence.\n \"\"\"\n if n < 0:\n return False\n # A number is Fibonacci if and only if one... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00031156",
"row_id": 31156,
"seed_ids": "['magpie_prefill_31156']"
} | 0.675089 | Prefill_31156 | I | [
"is_fibonacci",
"find_fibonacci_in_list"
] | 2 | [
[
"find_fibonacci_in_list",
"is_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ed3334e9e1b5c698e13820700829ad65e5acfc2 | 4f8dc5b37a75454e1b4e101c43dc24d3f929d63a | |||
v1.0 | instruct | Prefill | Prefill_31236_I | Write a python function to calculate the sum of all prime numbers between 1 and 100. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_primes():
"""
Returns the sum of all prime numbers between 1 and 100.... | from solution import sum_of_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(29) == True
assert is_prime(97) == True
assert is_prime(1) == False
def test_sum_of_primes():
assert sum_of_primes() == 1060 | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers between 1 and 100.",
"function_declaration": "def sum_of_primes... | [
1,
0,
1,
1,
1,
1,
0,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Prefill-43K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_primes_between_1_and_100():\n \"\"\"\n Returns the sum of all prime numbers between 1 and 100 inclusive.\n \"\"\"\n def is_prime(n):\n \"\"\"Helper function to chec... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031236",
"row_id": 31236,
"seed_ids": "['magpie_prefill_31236']"
} | 0.692112 | Prefill_31236 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19ef55bfc5a93bfb6fbda64155663189ee5a55cf | a85814ce5b9063fc594ebb868d2e7b5b5cad5447 | |||
v1.0 | instruct | Prefill | Prefill_31276_I | Write a python function to filter out all the prime numbers in a given list of integers. A prime number is a natural number greater than 1 and has no positive divisors other than 1 and itself. | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def filt... | from solution import filter_primes, is_prime
def test_single_prime():
assert filter_primes([7]) == [7]
def test_multiple_primes():
assert filter_primes([2, 3, 4, 5, 6, 7]) == [2, 3, 5, 7]
def test_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_primes_with_negative_numbers():
... | [
{
"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": "Filters out all the prime numbers in the given list of integers.",
"function_declaration": "def filt... | [
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 n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even prime num... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031276",
"row_id": 31276,
"seed_ids": "['magpie_prefill_31276']"
} | 0.669855 | Prefill_31276 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3989dfe3b37467f063eff93d7634b1d6f1e1062d | 784c893d6cd9e9cc109e93237c0dc206341fb160 | |||
v1.0 | instruct | Prefill | Prefill_31407_I | Write a python function to return a list containing only the prime numbers from the given list of integers. | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter... | from solution import filter_primes
def test_empty_list():
assert filter_primes([]) == []
def test_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_mixed_numbers():
assert filter_primes([1, 2, 4, 5, 8,... | [
{
"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 containing only the prime numbers from the given list of integers.",
"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": "def is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n r... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00031407",
"row_id": 31407,
"seed_ids": "['magpie_prefill_31407']"
} | 0.660624 | Prefill_31407 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ade40b5f8cd2c9bc3ff3ad2181927dd51910cea4 | 1744f84d441d0c8e5cbe603812467b7f332c2a4e | |||
v1.0 | instruct | Prefill | Prefill_31490_I | Write a python function to filter out numbers that are not perfect squares from a given list of integers. | import math
def is_perfect_square(n):
"""
Returns True if n is a perfect square, otherwise False.
"""
if n < 0:
return False
return math.isqrt(n) ** 2 == n
def filter_perfect_squares(numbers):
"""
Filters out numbers that are not perfect squares from the given list of integers.
... | from solution import filter_perfect_squares
def test_filter_all_perfect_squares():
assert filter_perfect_squares([1, 4, 9, 16, 25]) == [1, 4, 9, 16, 25]
def test_filter_no_perfect_squares():
assert filter_perfect_squares([2, 3, 5, 7, 8]) == []
def test_filter_mixed_numbers():
assert filter_perfect_square... | [
{
"docstring": "Returns True if n is a perfect square, otherwise False.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Filters out numbers that are not perfect squares from the given list of integers.\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": "import math\n\ndef filter_perfect_squares(numbers):\n \"\"\"\n Filters out numbers that are not perfect squares from the given list of integers.\n \n :param numbers: List of integ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031490",
"row_id": 31490,
"seed_ids": "['magpie_prefill_31490']"
} | 0.715698 | Prefill_31490 | I | [
"is_perfect_square",
"filter_perfect_squares"
] | 2 | [
[
"filter_perfect_squares",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2d441c0bb870b28e5ba2cfe6415b0ae8600e0088 | 310560eb4d3cd090a9d478cc788268687aeb96a8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.