version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | complete | Apps | Apps_14256_C | from typing import List
def minimize_max_pages(pages: List[int], people: int) -> int:
"""Redistribute books among people to minimize the maximum number of pages
any single person has to read. Each person gets a contiguous block of books.
Args:
pages (List[int]): List of integers where each intege... | from typing import List
def can_allocate(pages: List[int], people: int, max_pages_limit: int) -> bool:
required_people = 1
current_pages = 0
for page in pages:
if current_pages + page > max_pages_limit:
required_people += 1
current_pages = page
... | from solution import minimize_max_pages
def test_minimize_max_pages_example():
pages = [100, 200, 300, 400, 500]
people = 2
assert minimize_max_pages(pages, people) == 900
def test_minimize_max_pages_single_book():
pages = [300]
people = 1
assert minimize_max_pages(pages, people) == 300
def t... | [
{
"docstring": null,
"function_declaration": "def can_allocate(pages, people, max_pages_limit):",
"function_name": "can_allocate",
"parameter_list": "(pages, people, max_pages_limit)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_pages(pages, people):",
"function_... | [
0,
0,
0,
1,
0,
1,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef can_distribute(pages: List[int], people: int, max_pages: int) -> bool:\n \"\"\"\n Helper function to check if it's possible to ... | trial_gpt4o_5 | {
"original_instruction": "You are provided with a list of integers, where each integer represents the number of pages in a book. Your task is to redistribute these books among a group of people such that each person gets a contiguous block of books, and the maximum number of pages any single person has to read is mi... | 0.676759 | Apps_14256 | C | [
"can_allocate",
"minimize_max_pages"
] | 2 | [
[
"minimize_max_pages",
"can_allocate"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 05a50ecf8dcf3c1360175899becbb2b1b5690fe4 | 952596b6e323adf8249afa45e7f86c78e376845d | |||
v1.0 | complete | Apps | Apps_14136_C | def has_distinct_digits(number):
"""Checks whether the given number has all distinct digits.
>>> has_distinct_digits(102)
True
>>> has_distinct_digits(112)
False
>>> has_distinct_digits(12345)
True
>>> has_distinct_digits(122345)
False
"""
pass
def books_with_distinct_digits... | def has_distinct_digits(number):
"""Checks whether the given number has all distinct digits."""
digits = str(number)
return len(set(digits)) == len(digits)
def books_with_distinct_digits(n, m):
"""Returns a list of book identifiers within the range [n, m] with distinct digits."""
result = []
fo... | from solution import has_distinct_digits, books_with_distinct_digits, solve
def test_has_distinct_digits():
assert has_distinct_digits(102) == True
assert has_distinct_digits(112) == False
assert has_distinct_digits(12345) == True
assert has_distinct_digits(122345) == False
def test_books_with_distinc... | [
{
"docstring": "Checks whether the given number has all distinct digits.",
"function_declaration": "def has_distinct_digits(number):",
"function_name": "has_distinct_digits",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of book identifiers within the range [n, m] with disti... | [
1,
1,
0,
0,
0,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def distinct_digit_books(N, M):\n \"\"\"\n Return a list of integers in the range [N, M] that have distinct digits.\n \"\"\"\n def has_distinct_digits(x... | trial_gpt4o_9 | {
"original_instruction": "Jane is organizing a reading group and she wants to order the books for her group in a special way. Each book has a distinct identifier represented as a positive integer. Jane will pick up books in ascending order but with a twist: she will select only those books whose identifiers have dis... | 0.598854 | Apps_14136 | C | [
"has_distinct_digits",
"books_with_distinct_digits",
"solve"
] | 3 | [
[
"books_with_distinct_digits",
"has_distinct_digits"
],
[
"solve",
"books_with_distinct_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 33d3d3aa766f08c1fcd8e4d33aa35d671466eb7e | 4a7e2ee6c537a2ad9c4397808f52758d7a0d2cd3 | |||
v1.0 | complete | Apps | Apps_14087_C | from typing import List
def is_prime(num: int) -> bool:
""" Return True if num is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
"""
def is_palindrome(num: int) -> bool:
""" Return True if num is a palindrome number, otherwise False... | def is_prime(num):
"""Return True if num is a prime number, otherwise False."""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def... | from solution import is_prime, is_palindrome, palindrome_primes
def test_is_prime():
# Testing prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(13) == True
# Testing non-prime numbers
assert is_prime(1) == False
assert is_pr... | [
{
"docstring": "Return True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Return True if num is a palindrome number, otherwise False.",
"function_declaration": "def is_p... | [
1,
1,
1,
1,
1,
0,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\... | trial_gpt4o_8 | {
"original_instruction": "## Your story\nYou have recently become fascinated with palindrome numbers and decided to write a program to explore them further. You want to create a function that checks if a given number is a Palindrome Prime. A Palindrome Prime is a number that is both a palindrome and a prime number. ... | 0.736853 | Apps_14087 | C | [
"is_prime",
"is_palindrome",
"palindrome_primes"
] | 3 | [
[
"palindrome_primes",
"is_palindrome"
],
[
"palindrome_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8a0e11f8ac5a4a18c7bf968bf2131f16aef3d243 | e447bcb59a9e28638e58143dceede0c9053f82ea | |||
v1.0 | complete | Apps | Apps_14365_C | def is_palindrome(s: str) -> bool:
"""
Helper function to check if a string is a palindrome.
"""
return s == s[::-1]
def is_almost_palindrome(input_string: str) -> bool:
"""
A palindrome is a string that reads the same forward and backward, while an almost palindrome
is a string that would... | def is_palindrome(s):
"""
Helper function to check if a string is a palindrome.
"""
return s == s[::-1]
def is_almost_palindrome(input_string):
"""
Returns True if the input string is an almost palindrome, False otherwise.
"""
if is_palindrome(input_string):
return True
len... | from solution import is_almost_palindrome
def test_is_almost_palindrome_palindrome():
assert is_almost_palindrome("racecar") == True
def test_is_almost_palindrome_almost_palindrome():
assert is_almost_palindrome("radkar") == True
def test_is_almost_palindrome_not_almost_palindrome():
assert is_almost_pal... | [
{
"docstring": "Helper function to check if a string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the input string is an almost palindrome, False otherwise.",
"function_dec... | [
1,
0,
1,
1,
0,
0,
0,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_almost_palindrome(s):\n \"\"\"\n Determine if a string is an almost palindrome.\n\n Args:\n s (str): A non-empty string containing lowercase Engl... | trial_gpt4o_9 | {
"original_instruction": "# Task\nA palindrome is a string that reads the same forward and backward, while an almost palindrome is a string that would be a palindrome if at most one character were deleted.\n\nGiven a string, determine whether it is almost palindrome.\n\n# Example\n\nFor `input = \"radkar\"`, the out... | 0.858587 | Apps_14365 | C | [
"is_palindrome",
"is_almost_palindrome"
] | 2 | [
[
"is_almost_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3415e2c0bda85ac2fe57506cd0942dd1e719ce41 | f219c67fb6a8df64523e89d43a7b59c65dc1f90a | |||
v1.0 | complete | Apps | Apps_14103_C | def is_happy_number(n: int) -> bool:
""" Determine if a number is a happy number.
>>> is_happy_number(19)
True
>>> is_happy_number(2)
False
>>> is_happy_number(100)
True
>>> is_happy_number(1)
True
>>> is_happy_number(7)
True
"""
def determine_happy_numbers(numbers: List... | def is_happy_number(n):
def get_next(number):
return sum(int(ch)**2 for ch in str(number))
seen = set()
while n != 1 and n not in seen:
seen.add(n)
n = get_next(n)
return n == 1
def determine_happy_numbers(numbers):
results = []
for num in numbers:
if i... | from solution import is_happy_number, determine_happy_numbers, process_input
def test_is_happy_number():
assert is_happy_number(19) is True
assert is_happy_number(2) is False
assert is_happy_number(100) is True
assert is_happy_number(1) is True
assert is_happy_number(7) is True
def test_determine_... | [
{
"docstring": null,
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def determine_happy_numbers(numbers):",
"function_name": "determine_happy_numbers",
"parameter_list... | [
0,
1,
1,
0,
1,
0,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy(n):\n \"\"\"\n Determines if a given number n is a happy number.\n \n Args:\n n (int): a positive integer\n \n Returns:\n bool:... | trial_gpt4o_4 | {
"original_instruction": "A group of treasure hunters are trying to unlock a secret door to a hidden treasure. The door has a numeric keypad that accepts a positive integer input. The door opens if and only if the input number is a **happy number**. A happy number is defined as follows:\n\nStarting with any positive... | 0.587371 | Apps_14103 | C | [
"is_happy_number",
"determine_happy_numbers",
"process_input"
] | 3 | [
[
"determine_happy_numbers",
"is_happy_number"
],
[
"process_input",
"determine_happy_numbers"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 836cedaec7d25c75376477354210243acccab169 | bdc6f230c466989a1323583e05d6b95bcfef7fb0 | |||
v1.0 | complete | Apps | Apps_14637_C | def is_palindrome(num: int) -> bool:
""" Check if the number is a palindrome. """
return str(num) == str(num)[::-1]
def find_palindrome_steps(number: int) -> int:
"""
Returns the number of steps required to reach a palindrome according to the transformation rules.
If the number does not become a p... | def is_palindrome(num):
"""
Check if the number is a palindrome.
"""
return str(num) == str(num)[::-1]
def find_palindrome_steps(number):
"""
Returns the number of steps required to reach a palindrome.
If the number does not become a palindrome within 1000 steps, returns -1.
"""
ste... | from solution import find_palindrome_steps
def test_find_palindrome_steps_initial_palindrome():
assert find_palindrome_steps(121) == 0
assert find_palindrome_steps(44) == 0
def test_find_palindrome_steps_steps_required():
assert find_palindrome_steps(87) == 4
assert find_palindrome_steps(28) == 2
... | [
{
"docstring": "Check if the number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns the number of steps required to reach a palindrome.\nIf the number does not become a palindrome wit... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef find_palindrome_steps(number):\n if is_palindrome(number):\n return 0\n \n ste... | trial_gpt4o_7 | {
"original_instruction": "Andrew loves playing with numbers. He recently encountered a number game while solving puzzles, and he found it quite fascinating. The game involves taking an integer and performing a series of transformations on it until he reaches a palindrome or gets stuck in a loop. Your task is to help... | 0.757848 | Apps_14637 | C | [
"is_palindrome",
"find_palindrome_steps"
] | 2 | [
[
"find_palindrome_steps",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 98da5c4fdea1fbd03d9982276415ce50c4fc27f2 | 610dd87a456b8ad8166a8428ed9a1e1f77cee011 | |||
v1.0 | complete | Apps | Apps_14557_C | def matrix_sum(input_data: str) -> str:
""" Reads two matrices from the given input string and outputs their element-wise sum.
>>> matrix_sum("2 3\n1 2 3\n4 5 6\n7 8 9\n10 11 12")
'8 10 12\n14 16 18'
>>> matrix_sum("1 2\n-1000 -1000\n1000 1000")
'0 0'
>>> matrix_sum("3 3\n1 1 1\n1... | def read_matrix(n, m, matrix_input):
"""
Reads a matrix of size n by m from the given input list.
"""
matrix = []
for i in range(n):
row = matrix_input[i].split()
matrix.append([int(num) for num in row])
return matrix
def sum_matrices(matrix_a, matrix_b):
"""
Returns the... | from solution import matrix_sum
def test_matrix_sum_case1():
input_data = "2 3\n1 2 3\n4 5 6\n7 8 9\n10 11 12"
expected_output = "8 10 12\n14 16 18"
assert matrix_sum(input_data) == expected_output
def test_matrix_sum_case2():
input_data = "1 2\n-1000 -1000\n1000 1000"
expected_output = "0 0"
... | [
{
"docstring": "Reads a matrix of size n by m from the given input list.",
"function_declaration": "def read_matrix(n, m, matrix_input):",
"function_name": "read_matrix",
"parameter_list": "(n, m, matrix_input)"
},
{
"docstring": "Returns the summation of two matrices.",
"function_declar... | [
0,
1,
1,
1,
1,
0,
0,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def read_matrix(n, m):\n \"\"\"\n Reads a matrix of size n x m from standard input.\n \"\"\"\n matrix = []\n for _ in range(n):\n row = list(m... | trial_gpt4o_8 | {
"original_instruction": "-----General Statement:-----\nWrite a program that reads two matrices and outputs their sum.\n\n-----Input:-----\nThe input begins with two integers, n and m, specifying the number of rows and columns of the matrices (1 ≤ n, m ≤ 100). This is followed by 2 blocks, each consisting of n lines... | 0.584011 | Apps_14557 | C | [
"read_matrix",
"sum_matrices",
"parse_input",
"matrix_sum"
] | 4 | [
[
"matrix_sum",
"parse_input"
],
[
"matrix_sum",
"read_matrix"
],
[
"matrix_sum",
"sum_matrices"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 6988b8fd83e7fefb4f13a5b7df214ab789fb538f | 468d51387ad29b31d8108c8d113c35e7a01edc6c | |||
v1.0 | complete | Apps | Apps_14594_C | def is_prime(num: int) -> bool:
"""
Determines if a number is a prime number.
>>> is_prime(1) == False
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(9) == False
"""
# Your code here
def sum_of_three_primes(n: int) -... | def is_prime(num):
"""
Determines if a number is a prime number.
"""
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 Fals... | from solution import is_prime, sum_of_three_primes
def test_is_prime():
assert is_prime(1) == False
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
def test_sum_of_three_primes():
assert sum_of_three_p... | [
{
"docstring": "Determines if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if n can be expressed as the sum of three distinct prime numbers.",
"function_declaration": "def ... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef is_prime(n):\n \"\"\"Returns True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_7 | {
"original_instruction": "Given an integer `n`, create a function to determine if `n` can be expressed as the sum of three positive distinct integers each of which also must be a prime number. If such a combination exists, return the three prime numbers as a tuple. If multiple combinations are possible, return any o... | 0.738203 | Apps_14594 | C | [
"is_prime",
"sum_of_three_primes"
] | 2 | [
[
"sum_of_three_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fe8cdf92bed13c88b5abb69143d30efcd2c19437 | 5f222b81eb272d4021d8f03ee9dbd7f204982671 | |||
v1.0 | complete | Apps | Apps_14597_C | from typing import List
def is_balanced_string(S: str) -> bool:
""" Returns whether the string S is balanced or not.
>>> is_balanced_string("aabbcc")
True
>>> is_balanced_string("abcabcabc")
True
>>> is_balanced_string("aabbccdde")
False
>>> is_balanced_string("abcd")
True
"""
... | def is_balanced_string(S):
"""
Returns whether the string S is balanced or not.
"""
from collections import Counter
# Count frequency of each character
freq = Counter(S)
# Get all the frequency values
values = list(freq.values())
# Check if all frequency values are the... | from solution import is_balanced_string, check_balanced_strings
def test_is_balanced_string():
assert is_balanced_string("aabbcc") == True
assert is_balanced_string("abcabcabc") == True
assert is_balanced_string("aabbccdde") == False
assert is_balanced_string("abcd") == True
assert is_balanced_stri... | [
{
"docstring": "Returns whether the string S is balanced or not.",
"function_declaration": "def is_balanced_string(S):",
"function_name": "is_balanced_string",
"parameter_list": "(S)"
},
{
"docstring": "Returns a list indicating whether each string in strings is balanced.",
"function_dec... | [
1,
0,
1,
1,
0,
1,
0,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced_string(s):\n \"\"\"\n Returns 'YES' if the string s is balanced, 'NO' otherwise.\n A string is balanced if every character in the string ap... | trial_gpt4o_7 | {
"original_instruction": "In the world of programming, strings can often contain hidden meanings or patterns. One day, Aria discovered a special type of string called a \"Balanced String.\" A string is considered balanced if every character in the string appears the same number of times. Aria, being curious, wants t... | 0.657355 | Apps_14597 | C | [
"is_balanced_string",
"check_balanced_strings"
] | 2 | [
[
"check_balanced_strings",
"is_balanced_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 075c72f6b74f145671db98285bad2332bcbf077a | a4bcf6bc9bc136d33efc21d83189f2fa2f2a607b | |||
v1.0 | complete | Apps | Apps_14539_C | from typing import List
def count_palindromic_subarrays(arr: List[int]) -> int:
"""
Given a list of integers, count the number of subarrays (contiguous elements) that form a palindrome.
A palindrome is a sequence that reads the same backward as forward.
>>> count_palindromic_subarrays([1, 2,... | def is_palindrome(subarray):
"""
Helper function to check if a subarray is a palindrome.
"""
return subarray == subarray[::-1]
def count_palindromic_subarrays(arr):
"""
Returns the count of palindromic subarrays in the given list.
"""
count = 0
n = len(arr)
for start in ran... | from solution import count_palindromic_subarrays
def test_single_element_lists():
assert count_palindromic_subarrays([1]) == 1
assert count_palindromic_subarrays([2]) == 1
def test_two_element_lists():
assert count_palindromic_subarrays([1, 2]) == 2
assert count_palindromic_subarrays([1, 1]) == 3
def... | [
{
"docstring": "Helper function to check if a subarray is a palindrome.",
"function_declaration": "def is_palindrome(subarray):",
"function_name": "is_palindrome",
"parameter_list": "(subarray)"
},
{
"docstring": "Returns the count of palindromic subarrays in the given list.",
"function_... | [
0,
0,
1,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(arr):\n \"\"\"\n Helper function to check if a given list is a palindrome.\n \"\"\"\n return arr == arr[::-1]\n\ndef count_palindromic... | trial_gpt4o_7 | {
"original_instruction": "Given a list of integers, you need to count the number of subarrays (contiguous elements) that form a palindrome. A palindrome is a sequence that reads the same backward as forward.\n\nFor example:\n\n- `[1, 2, 1]` is a palindrome.\n- `[3, 4, 4, 3]` is a palindrome.\n- `[5, 6, 7]` is not a ... | 0.691913 | Apps_14539 | C | [
"is_palindrome",
"count_palindromic_subarrays"
] | 2 | [
[
"count_palindromic_subarrays",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b6e70cd6f04f2afdd4e2c86798560de4c473b0b | 93da56a172272f4a88856c41f03a5444947c97bc | |||
v1.0 | complete | Apps | Apps_14652_C | def is_valid_isbn_10(isbn):
""" Check if the given ISBN-10 is valid """
pass
def is_valid_isbn_13(isbn):
""" Check if the given ISBN-13 is valid """
pass
def find_isbn(text):
"""
Extract and validate an ISBN from the given text.
>>> find_isbn("This text contains an ISBN-10 like 0-306-4061... | import re
def is_valid_isbn_10(isbn):
""" Check if the given ISBN-10 is valid """
isbn = isbn.replace('-', '')
if len(isbn) != 10 or not isbn[:-1].isdigit() or (isbn[-1] not in '0123456789X'):
return False
total = 0
for i, char in enumerate(isbn):
if char == 'X':
total +... | from solution import find_isbn, is_valid_isbn_10, is_valid_isbn_13
def test_valid_isbn_10():
assert is_valid_isbn_10('0-306-40615-2') == True
assert is_valid_isbn_10('0306406152') == True
assert is_valid_isbn_10('030640615X') == False
assert is_valid_isbn_10('0-306-40615-X') == False
assert is_vali... | [
{
"docstring": "Check if the given ISBN-10 is valid ",
"function_declaration": "def is_valid_isbn_10(isbn):",
"function_name": "is_valid_isbn_10",
"parameter_list": "(isbn)"
},
{
"docstring": "Check if the given ISBN-13 is valid ",
"function_declaration": "def is_valid_isbn_13(isbn):",
... | [
0,
0,
1,
0,
1,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_isbn10(isbn):\n \"\"\" Validates an ISBN-10 number. \"\"\"\n isbn = isbn.replace('-', '')\n if len(isbn) != 10 or not isbn[:-1].i... | trial_gpt4o_9 | {
"original_instruction": "=====Function Descriptions=====\nfind_isbn(text)\nIn Python, the find_isbn(text) function can be used to extract and validate whether a given text contains a valid ISBN-10 or ISBN-13.\n\nISBN-10\nAn ISBN-10 is a ten-digit number, which may contain hyphens, and is validated by the following ... | 0.486654 | Apps_14652 | C | [
"is_valid_isbn_10",
"is_valid_isbn_13",
"find_isbn"
] | 3 | [
[
"find_isbn",
"is_valid_isbn_10"
],
[
"find_isbn",
"is_valid_isbn_13"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c4611d5d62e96a2f4761f1ac7a240959c42bfe39 | 62312fc1a69ce16322d49d917f916dfe8f91e851 | |||
v1.0 | complete | Apps | Apps_14862_C | def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, else returns False.
A prime number is a number that is greater than 1
and has no positive divisors other than 1 and itself.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
"""
def extract_sorted_primes(l... | def is_prime(n):
"""
Returns True if n is a prime number, else returns False.
A prime number is a number that is greater than 1
and has no positive divisors other than 1 and itself.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if ... | from solution import is_prime, extract_sorted_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(-5) == False
assert is_prime(0) == False
assert is_prime(1) == False
def test_extract_sorte... | [
{
"docstring": "Returns True if n is a prime number, else returns False.\nA prime number is a number that is greater than 1 \nand has no positive divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstri... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n ... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing all the prime numbers from the original list. The returned list should be sorted in ascending order. \n\nA prime number is a number that is greater than 1 and has no positive divisors other than 1 and itself.\n... | 0.761898 | Apps_14862 | C | [
"is_prime",
"extract_sorted_primes"
] | 2 | [
[
"extract_sorted_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36b0117f47de59711158716af3dfb7635163baee | 3ccbb0e3422251c566ebd1994d81b8315903a368 | |||
v1.0 | complete | Apps | Apps_15110_C | def can_form_sequence(blocks, sequence):
"""
Determines if the sequence can be formed using the given blocks.
>>> can_form_sequence(["1", "101", "11"], "11011")
True
>>> can_form_sequence(["1", "101", "11"], "10101")
False
"""
def check_sequences(n, blocks, t, sequences):
"""
Ch... | def can_form_sequence(blocks, sequence):
"""
Determines if the sequence can be formed using the given blocks.
"""
n = len(sequence)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
for block in blocks:
if i >= len(block) and sequence[i-len(block):i] == b... | from solution import can_form_sequence, check_sequences
def test_can_form_sequence():
blocks = ["1", "101", "11"]
assert can_form_sequence(blocks, "11011") == True
assert can_form_sequence(blocks, "10101") == False
assert can_form_sequence(blocks, "111011") == True
assert can_form_sequence(blocks, ... | [
{
"docstring": "Determines if the sequence can be formed using the given blocks.",
"function_declaration": "def can_form_sequence(blocks, sequence):",
"function_name": "can_form_sequence",
"parameter_list": "(blocks, sequence)"
},
{
"docstring": null,
"function_declaration": "def check_s... | [
0,
0,
1,
1,
1,
0,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_construct(sequence, blocks):\n n = len(sequence)\n dp = [False] * (n + 1)\n dp[0] = True\n\n for i in range(n):\n if dp[i]:\n ... | trial_gpt4o_7 | {
"original_instruction": "-----Problem-----\n\n\t\t\tEmily is a secret agent who communicates using numeric sequences. These sequences form codes that must follow a defined set of rules. A sequence is valid if it can be formed by concatenating one or more instances of a specific \"building block\" sequence.\n\n\t\t\... | 0.634209 | Apps_15110 | C | [
"can_form_sequence",
"check_sequences"
] | 2 | [
[
"check_sequences",
"can_form_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4cf75c24fbc5c41b8238ea7fd66e9185c70d481c | cdb79386d34e323a610552b8e351a6e62021b5e7 | |||
v1.0 | complete | Apps | Apps_14905_C | def calculate_final_total(purchase_amounts):
"""
This function takes a list of purchase amounts and returns a corresponding list of final amounts after applying the discount.
"""
def apply_discounts(N, amounts):
"""
Given the number of customers and a list of purchase amounts,
calculate the... | def calculate_final_total(purchase_amounts):
"""
This function takes a list of purchase amounts and returns a corresponding list of final amounts after applying the discount.
"""
final_amounts = []
for amount in purchase_amounts:
if amount <= 50:
final_amounts.append(round(a... | from solution import calculate_final_total, apply_discounts
def test_calculate_final_total_no_discount():
assert calculate_final_total([45.50]) == [45.50]
assert calculate_final_total([50.00]) == [50.00]
def test_calculate_final_total_ten_percent_discount():
assert calculate_final_total([75.00]) == [67.50... | [
{
"docstring": "This function takes a list of purchase amounts and returns a corresponding list of final amounts after applying the discount.",
"function_declaration": "def calculate_final_total(purchase_amounts):",
"function_name": "calculate_final_total",
"parameter_list": "(purchase_amounts)"
}... | [
1,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_amount(purchase_amount):\n \"\"\"\n Calculate the final purchase amount after applying the discount based on the rules provided.\n \n ... | trial_gpt4o_8 | {
"original_instruction": "=====Function Descriptions=====\nsorted(iterable[, cmp[, key[, reverse]]])\n\nThis function returns a new sorted list from the elements of any iterable. The can be specified and to determine the sorted order. The option determines whether the list is sorted in descending order.\n\nSample Co... | 0.572108 | Apps_14905 | C | [
"calculate_final_total",
"apply_discounts"
] | 2 | [
[
"apply_discounts",
"calculate_final_total"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8c6df673a4a0806776ced2db7318b063104dfa6 | 9272df590a88fae41f7a3342f69ce8701dbc72b8 | |||
v1.0 | complete | Apps | Apps_15029_C | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
d... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
d... | from solution import sum_of_primes
def test_sum_of_primes_with_primes():
assert sum_of_primes([2, 3, 4, 5, 6]) == 10
def test_sum_of_primes_without_primes():
assert sum_of_primes([4, 6, 8, 10, 12]) == 0
def test_sum_of_primes_with_repeated_primes():
assert sum_of_primes([1, 1, 2, 2, 2]) == 6
def test_su... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to calculate the sum of all prime numbers in an array.",
"function_declaration": "def sum_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T... | trial_gpt4o_9 | {
"original_instruction": "Given an array of integers, your task is to determine the sum of all elements in the array that are prime numbers. If there are no prime numbers in the array, return 0.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The first few p... | 0.793331 | Apps_15029 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 15420cbf3c319656bd24e5319ca59e182a3c6926 | 703cc528acdc03785152a6165f499c99c198e547 | |||
v1.0 | complete | Apps | Apps_14801_C | from typing import List, Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def generate_trees(n: int) -> List[Optional[TreeNode]]:
"""Create a list of all structurally unique BSTs with n nodes of unique values ... | from typing import List, Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def generate_trees(n: int) -> List[Optional[TreeNode]]:
if n == 0:
return []
def generate_trees_range(start, end):
... | from solution import generate_and_serialize_trees
def test_generate_trees_case_1():
result = generate_and_serialize_trees(1)
expected = [[1]]
assert result == expected
def test_generate_trees_case_2():
result = generate_and_serialize_trees(2)
expected = [
[1, "null", 2],
[2, 1]
... | [] | [
1,
0,
0,
1,
0,
1,
1,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef g... | trial_gpt4o_5 | {
"original_instruction": "Given an integer n, return all structurally unique Binary Search Trees (BSTs) that have n nodes of unique values from 1 to n.\n\nA Binary Search Tree is a binary tree with the following properties:\n - The left subtree of a node contains only nodes with keys less than the node’s key.\n - ... | 0.506061 | Apps_14801 | C | [
"generate_trees",
"serialize_tree",
"generate_and_serialize_trees"
] | 3 | [
[
"generate_and_serialize_trees",
"generate_trees"
],
[
"generate_and_serialize_trees",
"serialize_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9a65f95e5b02a22cdcc1d66317b5ab3f35e10dc2 | 114b0dbc19f667a5fa730b22cf92b00c26967f01 | |||
v1.0 | complete | Apps | Apps_15206_C | from typing import List, Dict
def prime_factors(n: int) -> List[int]:
""" Returns a list of prime factors of the given integer n.
>>> prime_factors(10)
[2, 5]
>>> prime_factors(15)
[3, 5]
"""
def solution(lst: List[int]) -> Dict[int, List[int]]:
""" Returns a dictionary with integers a... | def prime_factors(n):
"""
Returns a list of prime factors of the given integer n.
"""
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
if i not in factors:
factors.append(i)
if n > 1 and n not in factors:
... | from solution import solution, prime_factors
def test_prime_factors_single():
assert prime_factors(10) == [2, 5]
assert prime_factors(15) == [3, 5]
assert prime_factors(21) == [3, 7]
def test_prime_factors_prime_number():
assert prime_factors(13) == [13]
assert prime_factors(7) == [7]
def test_pr... | [
{
"docstring": "Returns a list of prime factors of the given integer n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns a dictionary with integers as keys and their prime factors as values.",
"functio... | [
1,
1,
0,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n \"\"\"\n Helper function to return the list of prime factors of a given number n.\n \"\"\"\n factors = []\n d = 2\n while ... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes a list of integers and returns a dictionary of the integers as keys and their corresponding list of prime factors (excluding 1) as values.\n\nPrime factors of a number are prime numbers that divide the number exactly, without leaving a remainder. For instance, th... | 0.666075 | Apps_15206 | C | [
"prime_factors",
"solution"
] | 2 | [
[
"solution",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4db13482b0bd4e66fbef6cd6eda2b7b302d4dd6b | 2d0f42b517ffe9f9097f9f2379441a1076e37462 | |||
v1.0 | complete | Apps | Apps_15060_C | def longest_vowel_substring(str1: str, str2: str) -> int:
"""
Determines the length of the longest substring made up of only vowels common in both input strings.
Args:
str1 (str): First input string.
str2 (str): Second input string.
Returns:
int: Length of the longest common vowel ... | def is_vowel(char):
"""
Check if a character is a vowel.
"""
return char in 'aeiou'
def longest_vowel_substring(str1, str2):
"""
Determines the longest substring made up of only vowels common in both input strings.
Params:
str1 (str): First input string.
str2 (str): Sec... | from solution import longest_vowel_substring
def test_common_vowel_substring():
assert longest_vowel_substring("aeiouxxaeiou", "xxaeiouxx") == 5
def test_no_common_vowel_substring():
assert longest_vowel_substring("aeiox", "bdfgh") == 0
def test_single_common_vowel_substring():
assert longest_vowel_subst... | [
{
"docstring": "Check if a character is a vowel.",
"function_declaration": "def is_vowel(char):",
"function_name": "is_vowel",
"parameter_list": "(char)"
},
{
"docstring": "Determines the longest substring made up of only vowels common in both input strings.\n\nParams:\n str1 (str): First... | [
1,
0,
1,
0,
0,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_vowel_substr(str1, str2):\n \"\"\"\n Returns the length of the longest common substring consisting only of vowels in str1 and str2.\n \"... | trial_gpt4o_7 | {
"original_instruction": "You are tasked with writing a function that determines the longest substring of two given strings, str1 and str2, that consists only of vowels (a, e, i, o, u).\n\n### Input\nTwo strings, `str1` and `str2`.\n\n### Output\nReturn the length of the longest common substring consisting only of v... | 0.66094 | Apps_15060 | C | [
"is_vowel",
"longest_vowel_substring"
] | 2 | [
[
"longest_vowel_substring",
"is_vowel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d016da2ed62964703e2fc0ceb83e045ce94a25d | 7b00330fef4e8437c519a108528b375225440e2d | |||
v1.0 | complete | Apps | Apps_15277_C | from typing import List
def is_prime(num: int) -> bool:
""" Returns True if num is a prime number, else False.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(11) == True
>>> is_prime(15) == False
>>> is_prime(1) == False
"""
def prime_triangle(n: ... | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
... | from solution import is_prime, prime_triangle
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
assert is_prime(1) == False
def test_prime_triangle_zero_rows():
assert prime_tr... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a pattern of prime numbers up to `n` rows.",
"function_declaration": "def prime_triangle(n)... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3,... | trial_gpt4o_7 | {
"original_instruction": "## Task:\n\nYou need to write a function **prime_triangle** that generates a pattern of prime numbers up to `n` rows.\n\n* If the argument is 0 or a negative integer then it should return \"\" i.e. an empty string.\n* The function should print prime numbers row-wise, one per row, for the fi... | 0.755042 | Apps_15277 | C | [
"is_prime",
"prime_triangle"
] | 2 | [
[
"prime_triangle",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | abe7db6a075f682e85481a021101391ea251f402 | 48de5f7606044c29d25d77d226cc7e960480c75d | |||
v1.0 | complete | Apps | Apps_15149_C | import itertools
import math
from typing import List
def is_perfect_square(x: int) -> bool:
"""
Checks if a number x is a perfect square.
"""
s = int(math.sqrt(x))
return s * s == x
def reorder_to_perfect_squares(n: int, nums: List[int]) -> List[int]:
"""
Reorders the array so that the sum... | import itertools
import math
def is_perfect_square(x):
"""
Checks if a number x is a perfect square.
"""
s = int(math.sqrt(x))
return s * s == x
def reorder_to_perfect_squares(n, nums):
"""
Reorders the array so that the sum of every pair of adjacent elements is a perfect square.
If th... | from solution import reorder_to_perfect_squares_from_input
def test_case_1():
input_string = "3\n1 17 8"
result = reorder_to_perfect_squares_from_input(input_string)
assert result == [17, 8, 1] or result == [1, 8, 17]
def test_case_2():
input_string = "4\n2 2 2 2"
result = reorder_to_perfect_squar... | [
{
"docstring": "Checks if a number x is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Reorders the array so that the sum of every pair of adjacent elements is a perfect square.\nIf the... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom itertools import permutations\n\ndef is_perfect_square(x):\n s = int(math.isqrt(x))\n return s * s == x\n\ndef reorder_to_perfect_squares(nu... | trial_gpt4o_6 | {
"original_instruction": "You are given an integer array nums consisting of positive integers. You need to reorder the array in a way such that the sum of every pair of adjacent elements is a perfect square. If there are multiple ways to reorder the array, return any of them, otherwise, return an empty array if no s... | 0.681944 | Apps_15149 | C | [
"is_perfect_square",
"reorder_to_perfect_squares",
"reorder_to_perfect_squares_from_input"
] | 3 | [
[
"reorder_to_perfect_squares",
"is_perfect_square"
],
[
"reorder_to_perfect_squares_from_input",
"reorder_to_perfect_squares"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8876384a1e3c6797cf83d01f481c0d85b53fefb1 | 378a107ef486f9f0347ad262e25c2b6fec5e0425 | |||
v1.0 | complete | Apps | Apps_15284_C | def is_prime(n: int) -> bool:
""" Determine if the input number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(18)
False
>>> is_prime(1)
False
>>> is_prime(-3)
False
"""
def filter_primes(numbers: List[int]) -> Li... | def is_prime(n):
"""
Determine if the input 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... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(-3) == Fal... | [
{
"docstring": "Determine if the input number 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.",
"function_declaration": "def filter_primes(numbers... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2... | trial_gpt4o_9 | {
"original_instruction": "## Task:\n\nGiven a list of integers, return a new list containing only the numbers that are prime. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\n### Example:\n\n```python\nfilter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10])\n```\nshould... | 0.789648 | Apps_15284 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50aa0345ecad68041fba173abc1ea4aac4be4ab1 | a5ffa4527308094d009a34713fde857441f9af14 | |||
v1.0 | complete | Apps | Apps_15225_C | from typing import List, Tuple
def minimum_cost_to_install_cameras(n: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Function to return the minimum cost required to monitor all the roads in the city.
The cost is based on the travel time of each road.
Args:
n (int): The number of intersect... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import minimum_cost_to_install_cameras
def test_example_1():
n = 4
roads = [(1, 2, 5), (1, 3, 10), (2, 3, 2), (2, 4, 7), (3, 4, 1)]
assert minimum_cost_to_install_cameras(n, roads) == 8
def test_example_2():
n = 3
roads = [(1, 2, 4), (1, 3, 6), (2, 3, 1)]
assert minimum_cost_to_i... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\n... | trial_gpt4o_0 | {
"original_instruction": "In a city known for its intricate network of roads, you are given a list of roads that connect various intersections. Each road has a travel time associated with it. The city authorities are planning to install a security camera on each road. Installing and maintaining security cameras cost... | 0.562789 | Apps_15225 | C | [
"find",
"union",
"minimum_cost_to_install_cameras"
] | 3 | [
[
"minimum_cost_to_install_cameras",
"find"
],
[
"minimum_cost_to_install_cameras",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 6c52bb00735214f0c8a77b6571aeec509e6d1100 | 04dac8964bed8584ae010ec07bb34ecbc3857135 | |||
v1.0 | complete | Apps | Apps_15601_C | def max_rectangle_area(matrix: List[List[int]]) -> int:
""" Write a function max_rectangle_area(matrix) that takes a 2D binary matrix filled with 0's and 1's and returns the area of the largest rectangle containing only 1's.
>>> matrix = [
... [1, 1, 0, 1],
... [1, 1, 1, 1],
... [0, 1, 1... | def max_histogram_area(heights):
"""
Helper function to find the maximum rectangular area under a histogram.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index ... | from solution import max_rectangle_area
def test_example1():
matrix = [
[1, 1, 0, 1],
[1, 1, 1, 1],
[0, 1, 1, 0],
[0, 1, 1, 1]
]
assert max_rectangle_area(matrix) == 6
def test_example2():
matrix = [
[0, 1, 0, 0, 1],
[1, 1, 1, 1, 0],
[1, 1, 1, 1,... | [
{
"docstring": "Helper function to find the maximum rectangular area under a histogram.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_ar... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or heights[index] >= ... | trial_gpt4o_9 | {
"original_instruction": "Write a function `max_rectangle_area(matrix)` that takes a 2D binary matrix filled with 0's and 1's and returns the area of the largest rectangle containing only 1's.\n\nFor example:\n```python\nmatrix = [\n [1, 1, 0, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 0],\n [0, 1, 1, 1]\n]\nmax_re... | 0.765235 | Apps_15601 | C | [
"max_histogram_area",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64be3583647743dab08e51d0ab9df58924c99f01 | c29663de8cfd854bcfa41297991b9d7497ce4ceb | |||
v1.0 | complete | Apps | Apps_15387_C | from typing import List, Tuple
def preprocess_sum_matrix(n: int, m: int, R: List[List[int]]) -> List[List[int]]:
"""Preprocess the rainfall matrix to create a prefix sum matrix."""
pass # Implement the function
def compute_submatrix_sum(prefix_sum: List[List[int]], iL: int, iR: int, jL: int, jR: int) -> ... | def preprocess_sum_matrix(n, m, R):
# Create prefix sum matrix
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n+1):
for j in range(1, m+1):
prefix_sum[i][j] = R[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1]
return prefix_su... | from solution import preprocess_sum_matrix, compute_submatrix_sum, solve_rainfall_queries
def test_preprocess_sum_matrix():
rainfall_matrix = [
[9, 5, 4],
[2, 6, 7],
[1, 9, 3]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 9, 14, 18],
[0, 11, 22, 33],
... | [
{
"docstring": null,
"function_declaration": "def preprocess_sum_matrix(n, m, R):",
"function_name": "preprocess_sum_matrix",
"parameter_list": "(n, m, R)"
},
{
"docstring": null,
"function_declaration": "def compute_submatrix_sum(prefix_sum, iL, iR, jL, jR):",
"function_name": "comp... | [
1,
1,
0,
1,
1,
0,
1,
1,
0,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_prefix_sums(matrix):\n \"\"\"Calculates the prefix sums matrix for a given rainfall matrix.\"\"\"\n n = len(matrix)\n m = len(matrix[0])\n ... | trial_gpt4o_9 | {
"original_instruction": "Lambda Inc. has hired you to track the rainfall in their experimental fields. They have provided you with a matrix `R` of dimensions `nxm`, where `Ri, j` represents the amount of rainfall in the ith row and the jth column. Lambda Inc. wants to investigate the rainfall data efficiently. To d... | 0.555187 | Apps_15387 | C | [
"preprocess_sum_matrix",
"compute_submatrix_sum",
"solve_rainfall_queries"
] | 3 | [
[
"solve_rainfall_queries",
"compute_submatrix_sum"
],
[
"solve_rainfall_queries",
"preprocess_sum_matrix"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3ca7f8a00a621460efb0f8c49f7365aecdfb3834 | 26f8b8dd02ae1e6bf872d9ab77efed63bc2927e9 | |||
v1.0 | complete | Apps | Apps_15741_C | def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise returns False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
"""
def filter_primes(arr: List[int]) -> List[int]:
"""
Returns a list of prime numbers from the given list of posi... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns 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 filter_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(13) == True
assert is_prime(17) == True
assert is_prime(19) == True... | [
{
"docstring": "Returns True if n is a prime number, otherwise returns False.",
"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 positive integers.",
"function_declar... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ... | trial_gpt4o_6 | {
"original_instruction": "Create a function that takes an array of positive integers and returns an array containing only the prime numbers from the input array. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should utilize an efficient algorithm... | 0.743102 | Apps_15741 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06224bd7758704b2de71a41f2ab07311ff0538b1 | 26f6e6ac2bd063b88b376747e9d601f62f55d06f | |||
v1.0 | complete | Apps | Apps_15739_C | def convert_to_seconds(time_str: str) -> int:
"""
Converts a time string in the format hh:mm:ss to the total number of seconds.
"""
def median_finish_times(times: List[str]) -> Union[str, List[str]]:
"""
Given a list of participants' finish times in the format hh:mm:ss,
returns the participant... | def convert_to_seconds(time_str):
"""
Converts a time string in the format hh:mm:ss to the total number of seconds.
"""
h, m, s = map(int, time_str.split(':'))
return h * 3600 + m * 60 + s
def median_finish_times(times):
"""
Given a list of participants' finish times in the format hh:mm:ss,... | from solution import median_finish_times
def test_odd_number_of_times():
times = ["03:15:30", "02:45:20", "04:20:50", "03:10:15", "01:50:40"]
assert median_finish_times(times) == "03:10:15"
def test_even_number_of_times():
times = ["04:05:20", "03:35:10", "06:45:30", "03:25:40", "02:15:50", "05:30:25"]
... | [
{
"docstring": "Converts a time string in the format hh:mm:ss to the total number of seconds.",
"function_declaration": "def convert_to_seconds(time_str):",
"function_name": "convert_to_seconds",
"parameter_list": "(time_str)"
},
{
"docstring": "Given a list of participants' finish times in ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def median_times(times):\n def time_to_seconds(t):\n hh, mm, ss = map(int, t.split(':'))\n return hh * 3600 + mm * 60 + ss\n\n # Convert the tim... | trial_gpt4o_9 | {
"original_instruction": "## Task\nYou are organizing a marathon and have a list of participants' finish times in hours, minutes, and seconds. Your task is to determine the participants who finished the marathon in the median time.\n\nGiven a list of participants' finish times in the format `hh:mm:ss`, find the part... | 0.599442 | Apps_15739 | C | [
"convert_to_seconds",
"median_finish_times"
] | 2 | [
[
"median_finish_times",
"convert_to_seconds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a1c916b472348211cc0cccab145c7f558d97f8ff | ad92ba7b48c7cf3ac4d8abd40200b5bb577f6af6 | |||
v1.0 | complete | Apps | Apps_15548_C | class TreeNode:
def __init__(self, index):
self.index = index
self.left = None
self.right = None
def build_tree(n, nodes_info):
tree = {}
for i in range(n):
u, v, w = nodes_info[i]
if u not in tree:
tree[u] = TreeNode(u)
if v != -1:
tr... | class TreeNode:
def __init__(self, index):
self.index = index
self.left = None
self.right = None
def build_tree(n, nodes_info):
tree = {}
for i in range(n):
u, v, w = nodes_info[i]
if u not in tree:
tree[u] = TreeNode(u)
if v != -1:
tr... | from solution import play_game
def test_play_game_case_1():
n = 5
nodes_info = [
(1, 2, 3),
(2, 4, 5),
(3, -1, -1),
(4, -1, -1),
(5, -1, -1)
]
q = 3
queries = [2, 3, 2]
expected_output = ["NO", "NO", "YES"]
assert play_game(n, nodes_info, q, queries) ... | [] | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_same_tree_after_swaps(n, edges, q, queries):\n from collections import deque\n\n def clone_tree(root, graph):\n cloned = {}\n queue = deq... | trial_gpt4o_9 | {
"original_instruction": "Larry and Sergei are playing a game on a binary tree. A binary tree is a tree data structure where each node has at most two children. The game is played with one special node called the \"queries node\" and in each query, one can swap all the left and right children of any node in the tree... | 0.561484 | Apps_15548 | C | [
"build_tree",
"compare_trees",
"swap_children",
"find_node",
"play_game"
] | 5 | [
[
"play_game",
"build_tree"
],
[
"play_game",
"compare_trees"
],
[
"play_game",
"swap_children"
],
[
"swap_children",
"find_node"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 028884b007065e5deb513c743c11b6ef61b9adde | 099b3e487a9004402d445b9569bf6629dce40f70 | |||
v1.0 | complete | Apps | Apps_15722_C | def sieve_of_eratosthenes(n: int) -> List[bool]:
""" Creates a list of boolean values representing whether numbers are prime up to n.
>>> sieve_of_eratosthenes(10) [False, False, True, True, False, True, False, True, False, False, False]
>>> sieve_of_eratosthenes(1) [False, False]
"""
def count_prime_p... | def sieve_of_eratosthenes(n):
"""
Creates a list of boolean values representing whether numbers are prime up to n.
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not primes
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + ... | import pytest
from solution import sieve_of_eratosthenes, count_prime_pairs, prime_pairs
def test_sieve():
assert sieve_of_eratosthenes(10) == [False, False, True, True, False, True, False, True, False, False, False]
assert sieve_of_eratosthenes(1) == [False, False]
def test_count_prime_pairs():
assert co... | [
{
"docstring": "Creates a list of boolean values representing whether numbers are prime up to n.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_prime_p... | [
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of boolean values indicating prime numbers up to n.\n \"\"\"\n is_pri... | trial_gpt4o_3 | {
"original_instruction": "Chef recently became interested in number theory and is exploring the mathematical beauty behind prime numbers. He has a special interest in prime pairs. Two numbers are considered a prime pair if both numbers are prime and the absolute difference between them is 2 (for example, 3 and 5, or... | 0.713417 | Apps_15722 | C | [
"sieve_of_eratosthenes",
"count_prime_pairs",
"prime_pairs"
] | 3 | [
[
"count_prime_pairs",
"sieve_of_eratosthenes"
],
[
"prime_pairs",
"count_prime_pairs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 74dc8fb3137b4f30b5dff94b8617edcfd96edb47 | b4be4ab238280bbf649b465138c0a46ca84c5ab1 | |||
v1.0 | complete | Apps | Apps_15710_C | from typing import List
from itertools import permutations
def is_valid_time(a: int, b: int, c: int, d: int) -> bool:
"""
Check if the given four digits can form a valid time (HH:MM) in a 24-hour format.
>>> is_valid_time(1, 8, 3, 2)
True
>>> is_valid_time(2, 4, 6, 9)
False
>>> is_valid_t... | from itertools import permutations
def is_valid_time(a, b, c, d):
hour = a * 10 + b
minute = c * 10 + d
return 0 <= hour < 24 and 0 <= minute < 60
def can_form_valid_time(digits):
for perm in permutations(digits):
if is_valid_time(perm[0], perm[1], perm[2], perm[3]):
return "1"
... | from solution import is_valid_time, can_form_valid_time, check_times
def test_is_valid_time():
assert is_valid_time(1, 8, 3, 2) == True
assert is_valid_time(2, 4, 6, 9) == False
assert is_valid_time(0, 9, 5, 0) == True
assert is_valid_time(2, 5, 0, 0) == False
def test_can_form_valid_time():
asser... | [
{
"docstring": null,
"function_declaration": "def is_valid_time(a, b, c, d):",
"function_name": "is_valid_time",
"parameter_list": "(a, b, c, d)"
},
{
"docstring": null,
"function_declaration": "def can_form_valid_time(digits):",
"function_name": "can_form_valid_time",
"parameter... | [
0,
1,
0,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef can_form_valid_time(digits):\n for perm in permutations(digits):\n hours = perm[0] * 10 + perm[1]\n minut... | trial_gpt4o_9 | {
"original_instruction": "Sarah has a unique digital clock that malfunctioned. Instead of displaying the correct time, it shows 4 random non-negative integers. She needs to determine if it's possible to rearrange these integers to form a valid 24-hour format time (HH:MM).\n\nA valid 24-hour format time ranges from 0... | 0.602742 | Apps_15710 | C | [
"is_valid_time",
"can_form_valid_time",
"check_times"
] | 3 | [
[
"can_form_valid_time",
"is_valid_time"
],
[
"check_times",
"can_form_valid_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 87f105c5da19b407c1005379d5641cdc48ea4f29 | a1204592a1c1c2b31521f5ae7ed40648e266ed17 | |||
v1.0 | complete | Apps | Apps_15980_C | from typing import List
def min_path_sum(grid: List[List[int]]) -> int:
""" Calculate minimum sum from top-left to bottom-right in a grid.
>>> min_path_sum([[1,3,1],[1,5,1],[4,2,1]]) == 7
>>> min_path_sum([[1,2],[1,1]]) == 3
"""
def solve_min_path_sum(test_cases: List[List[List[int]]]) -> List[int... | import heapq
def min_path_sum(grid):
N, M = len(grid), len(grid[0])
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
min_heap = [(grid[0][0], 0, 0)]
visited = set()
while min_heap:
current_sum, x, y = heapq.heappop(min_heap)
if (x, y) == (N-1, M-1):
return c... | from solution import solve_min_path_sum, process_input
def test_min_path_sum():
input_string = """2
3 3
1 3 1
1 5 1
4 2 1
2 2
1 2
1 1"""
test_cases = process_input(input_string)
result = solve_min_path_sum(test_cases)
assert result == [7, 3], f"Expected [7, 3] but got {result}"
def test_single_cell():... | [
{
"docstring": null,
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve_min_path_sum(test_cases):",
"function_name": "solve_min_path_sum",
"parameter_list": "(te... | [
0,
0,
0,
0,
1,
0,
0,
1,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_path_sum(grid):\n n = len(grid)\n m = len(grid[0])\n \n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n min_heap = [(grid[0... | trial_gpt4o_8 | {
"original_instruction": "You are given a grid of size \\(N \\times M\\) with non-negative integers in each cell. You can move from any cell to any of its 4 direct neighbors (up, down, left, right). You need to find a path from the top-left corner of the grid to the bottom-right corner such that the sum of integers ... | 0.601894 | Apps_15980 | C | [
"min_path_sum",
"solve_min_path_sum",
"process_input"
] | 3 | [
[
"solve_min_path_sum",
"min_path_sum"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 186338b7086bcfa629df607dc39e10839ba5a04a | de2b8586a4a45d78351cb4d43055e10a64e9cd1f | |||
v1.0 | complete | Apps | Apps_16051_C | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def label_binary_tree(n, level_order):
""" Label each node of a binary tree with a unique integer such that
the sum of all labels on the nodes in the left subtree of any given
node is ... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def label_tree(root):
# Helper function to perform in-order traversal and label the nodes
def in_order_traversal(node, current_label):
if node is not None:
current_label ... | from solution import label_binary_tree
def test_label_binary_tree_small():
n = 7
level_order = [1, 2, 3, 4, 5, 6, 7]
result = label_binary_tree(n, level_order)
assert len(result) == n
assert result == [4, 2, 6, 1, 3, 5, 7]
def test_label_binary_tree_single_node():
n = 1
level_order = [1]
... | [] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n s... | trial_gpt4o_8 | {
"original_instruction": "-----Binary Tree Labelling-----\nGiven a binary tree, we want to label each node of the tree with a unique integer in such a way that the sum of all labels on the nodes in the left subtree of any given node is less than the sum of all labels on the nodes in the right subtree of that node.\n... | 0.583638 | Apps_16051 | C | [
"label_tree",
"construct_tree_from_level_order",
"label_binary_tree"
] | 3 | [
[
"label_binary_tree",
"construct_tree_from_level_order"
],
[
"label_binary_tree",
"label_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 82d2e69497e0da6d260071a5441b520d2c520838 | e15763a7e5aeb8b5bb60c10025306bda1e9ab015 | |||
v1.0 | complete | Apps | Apps_16123_C | def roman_sum(s1: str, s2: str) -> str:
"""
Compute the sum of two Roman numerals given as strings and return the result as a Roman numeral.
>>> roman_sum("XIII", "IV")
"XVII"
>>> roman_sum("X", "X")
"XX"
>>> roman_sum("IX", "I")
"X"
"""
def roman_to_int(s: str) -> int:
"""
... | def roman_to_int(s):
"""
Convert a Roman numeral to an integer.
"""
roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
total = 0
prev_value = 0
for char in reversed(s):
value = roman_dict[char]
if value < prev_value:
total -= value... | from solution import roman_sum
def test_roman_sum_simple():
assert roman_sum("XIII", "IV") == "XVII"
assert roman_sum("X", "X") == "XX"
assert roman_sum("IX", "I") == "X"
assert roman_sum("I", "I") == "II"
def test_roman_sum_complex():
assert roman_sum("DCCC", "CC") == "M"
assert roman_sum("CD... | [
{
"docstring": "Convert a Roman numeral to an integer.",
"function_declaration": "def roman_to_int(s):",
"function_name": "roman_to_int",
"parameter_list": "(s)"
},
{
"docstring": "Convert an integer to a Roman numeral.",
"function_declaration": "def int_to_roman(num):",
"function_na... | [
1,
1,
0,
1,
1,
0,
1,
1,
0
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def roman_to_int(roman):\n roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n total = 0\n prev_value = 0\n \n for cha... | trial_gpt4o_8 | {
"original_instruction": "Write a function that takes two strings as input, representing two integers in Roman numeral format, and returns their sum as a Roman numeral. The input strings will not necessarily be in their simplest form, but the output must be.\n\nRoman numeral symbols:\n* `I = 1`\n* `V = 5`\n* `X = 10... | 0.679644 | Apps_16123 | C | [
"roman_to_int",
"int_to_roman",
"roman_sum"
] | 3 | [
[
"roman_sum",
"int_to_roman"
],
[
"roman_sum",
"roman_to_int"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 94300c97f972cf4c71d52d40790a5a68c75d2258 | efada10b27971b8cf80e6547cd233b3865b0855a | |||
v1.0 | complete | Apps | Apps_16158_C | def is_prime(num: int) -> bool:
"""Check if a given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(10)
False
>>> is_prime(11)
True
"""
def nearest_prime(n: int) -> int:
"""Finds the nearest prime number to the given number n.
>>> nearest_prime(10)
11
>>> nea... | def is_prime(num):
"""Check if a given number is a prime number."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i... | from solution import is_prime, nearest_prime, nearestPrimes
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_nearest_prime():
assert nearest_pri... | [
{
"docstring": "Check if a given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the nearest prime number to the given number n.",
"function_declaration": "def nearest_prime(n):",
... | [
0,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function that checks if the number n is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_8 | {
"original_instruction": "Develop a function that takes an array of numbers and returns an array where each number is replaced by the nearest prime number. If a number is equidistant to two primes, the smaller prime should be selected.\n\nTo determine the nearest prime, you may use a helper function that checks if a... | 0.667841 | Apps_16158 | C | [
"is_prime",
"nearest_prime",
"nearestPrimes"
] | 3 | [
[
"nearestPrimes",
"nearest_prime"
],
[
"nearest_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b72a229e17a06317ff123f4f30758f0b865c902f | d83496bbe67cb9ecd60d3124df774cb9ffc24231 | |||
v1.0 | complete | Apps | Apps_16165_C | def chef_loves_symmetry(T: int, test_cases: List[Tuple[int, int]]) -> List[str]:
""" Given two numbers A and B, find the greatest common divisor (GCD) of all the integers between A and B inclusive that are palindromes.
A number is called a palindrome if it reads the same backward as forward.
>>> chef_loves... | import math
def is_palindrome(n):
"""
Check if a given number n is a palindrome.
"""
return str(n) == str(n)[0:][::-1]
def find_palindromes(a, b):
"""
Find all palindromes in the range [a, b] inclusive.
"""
palindromes = [i for i in range(a, b + 1) if is_palindrome(i)]
return palin... | from solution import chef_loves_symmetry
def test_example_case1():
assert chef_loves_symmetry(1, [(10, 20)]) == ["Case #1: 11"]
def test_example_case2():
assert chef_loves_symmetry(1, [(5, 30)]) == ["Case #1: 1"]
def test_single_palindrome():
# Only one palindrome (11), GCD should be 11 itself
assert... | [
{
"docstring": "Check if a given number n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find all palindromes in the range [a, b] inclusive.",
"function_declaration": "def find_palindromes(a... | [
0,
0,
0,
1,
0,
0,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef gcd_of_palindr... | trial_gpt4o_9 | {
"original_instruction": "Chef loves symmetry. He often plays with numbers and tries to find patterns among them. Today, he has come across an interesting problem and would love your help to solve it. The problem goes like this: Given two numbers A and B, find the greatest common divisor (GCD) of all the integers be... | 0.682831 | Apps_16165 | C | [
"is_palindrome",
"find_palindromes",
"gcd_of_list",
"gcd_of_palindromes_in_range",
"chef_loves_symmetry"
] | 5 | [
[
"chef_loves_symmetry",
"gcd_of_palindromes_in_range"
],
[
"find_palindromes",
"is_palindrome"
],
[
"gcd_of_palindromes_in_range",
"find_palindromes"
],
[
"gcd_of_palindromes_in_range",
"gcd_of_list"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fcc7a8040d3146ec2db2e9cc325d8dc09ac63852 | 636ce48c4626633b5288a2f97802c49ac9ed8abb | |||
v1.0 | complete | Apps | Apps_16159_C | def evaluate_math_expression(expression: str) -> int:
"""
Evaluates a given mathematical expression containing non-negative integers and the operators + and *.
The expression obeys the BODMAS rule and does not contain any parentheses.
For example:
>>> evaluate_math_expression("3+5*2")
13
>... | def evaluate_math_expression(expression: str) -> int:
"""
Evaluates a given mathematical expression containing non-negative integers and the operators + and *.
The expression obeys the BODMAS rule and does not contain any parentheses.
"""
# Split the expression first by '+' to handle addition separa... | from solution import evaluate_math_expression
def test_single_number():
assert evaluate_math_expression("5") == 5
def test_simple_addition():
assert evaluate_math_expression("3+2") == 5
def test_simple_multiplication():
assert evaluate_math_expression("4*2") == 8
def test_combined_operations_1():
as... | [
{
"docstring": "Evaluates a given mathematical expression containing non-negative integers and the operators + and *.\nThe expression obeys the BODMAS rule and does not contain any parentheses.",
"function_declaration": "def evaluate_math_expression(expression):",
"function_name": "evaluate_math_express... | [
1,
1,
0,
1,
1,
0,
1,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evaluate_math_expression(expression: str) -> int:\n # Split expression by '+' keeping track of segments\n parts = expression.split('+')\n \n # Evalu... | trial_gpt4o_7 | {
"original_instruction": "## Math Evaluator\n\n## Story\n\nYou're hired by a company that specializes in providing tools for educational purposes. You have been tasked with developing a simple math expression evaluator which can take a string input representing some basic math operations and evaluates it to an integ... | 0.634223 | Apps_16159 | C | [
"evaluate_math_expression",
"eval_multiplication"
] | 2 | [
[
"evaluate_math_expression",
"eval_multiplication"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ac0c327bb195183fa0c99c03f6053f6e6f76059 | d4deeddb319288aaa80784adb26d1ef280adc1b3 | |||
v1.0 | complete | Apps | Apps_16178_C | def harmonic_divisors(x):
""" Return the first x harmonic divisor numbers in ascending order.
Args:
x : int : Number of harmonic divisor numbers to return
Returns:
List[int] : List of the first x harmonic divisor numbers in ascending order
>>> harmonic_divisors(5)
[1, 6, 28, 140, 270]
... | def harmonic_mean(lst):
"""
Compute the harmonic mean of a list of divisors.
"""
from fractions import Fraction
if not lst:
return 0
n = len(lst)
sum_reciprocal = sum(Fraction(1, d) for d in lst)
harmonic_mean_value = Fraction(n, sum_reciprocal)
return harmonic... | from solution import harmonic_divisors, is_harmonic_divisor_number, divisors
def test_is_harmonic_divisor_number():
assert is_harmonic_divisor_number(1) == True
assert is_harmonic_divisor_number(6) == True
assert is_harmonic_divisor_number(28) == True
assert is_harmonic_divisor_number(10) == False
def... | [
{
"docstring": "Compute the harmonic mean of a list of divisors.",
"function_declaration": "def harmonic_mean(lst):",
"function_name": "harmonic_mean",
"parameter_list": "(lst)"
},
{
"docstring": "Compute the divisors of a number n.",
"function_declaration": "def divisors(n):",
"func... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def harmonic_divisors(x):\n def harmonic_mean(divisors):\n n = len(divisors)\n sum_reciprocals = sum(1/d for d in divisors)\n return n / sum... | trial_gpt4o_7 | {
"original_instruction": "A **harmonic divisor number** is a positive integer whose divisors have a harmonic mean that is an integer.\n\nThe **harmonic mean** of a set of numbers is the reciprocal of the arithmetic mean of the reciprocals of the numbers. For example, the harmonic mean of 1, 2, and 4 is obtained by:\... | 0.661256 | Apps_16178 | C | [
"harmonic_mean",
"divisors",
"is_harmonic_divisor_number",
"harmonic_divisors"
] | 4 | [
[
"harmonic_divisors",
"is_harmonic_divisor_number"
],
[
"is_harmonic_divisor_number",
"divisors"
],
[
"is_harmonic_divisor_number",
"harmonic_mean"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ec7bbfd3cc8f0dabf0cd0d1f7ce1392256638204 | e26ee60d509edd96214959400278ed3b66a03a5d | |||
v1.0 | complete | Apps | Apps_16149_C | from typing import List
def best_day(sales_list: List[int]) -> int:
"""
Returns the day (0-based index) with the highest sales.
>>> best_day([200, 180, 220, 210, 150, 300, 170]) 5
>>> best_day([1, 2, 3, 4, 5]) 4
>>> best_day([1000, 1000, 1000]) 0
"""
pass
def worst_day(sales_list: List[int... | def best_day(sales_list):
"""
Returns the day (0-based index) with the highest sales.
"""
return sales_list.index(max(sales_list))
def worst_day(sales_list):
"""
Returns the day (0-based index) with the lowest sales.
"""
return sales_list.index(min(sales_list))
def average_sales(sales_... | from solution import best_day, worst_day, average_sales, above_average_days
def test_best_day():
assert best_day([200, 180, 220, 210, 150, 300, 170]) == 5
assert best_day([1, 2, 3, 4, 5]) == 4
assert best_day([1000, 1000, 1000]) == 0
def test_worst_day():
assert worst_day([200, 180, 220, 210, 150, 300... | [
{
"docstring": "Returns the day (0-based index) with the highest sales.",
"function_declaration": "def best_day(sales_list):",
"function_name": "best_day",
"parameter_list": "(sales_list)"
},
{
"docstring": "Returns the day (0-based index) with the lowest sales.",
"function_declaration":... | [
0,
1,
1,
0,
1,
1,
1,
1,
0,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def best_day(sales_list):\n \"\"\"\n Returns the 0-based index of the day with the highest sales.\n \"\"\"\n return sales_list.index(max(sales_list))\n\... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of integers representing the sales over a number of days in a bookstore. From this list, we want to generate a report that helps analyze sales performance over a period of time.\n\n# Task:\nWrite functions:\n```\n1. best_day(sales_list) - Returns the day (0-based index)... | 0.679978 | Apps_16149 | C | [
"best_day",
"worst_day",
"average_sales",
"above_average_days"
] | 4 | [
[
"above_average_days",
"average_sales"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c69585dfa0f9ab8fe1efe2d2bdf20596b31f91c3 | 8bd7cee2fd4ac0b04ee54946f5c7b056673bb913 | |||
v1.0 | complete | Apps | Apps_15987_C | def check_balanced_brackets(n: int, strings: List[str]) -> List[str]:
"""
Given a number of strings, determine for each string if it is balanced and properly nested.
Args:
n: int - An integer representing the number of strings to evaluate.
strings: List[str] - A list of strings that need to be... | def is_balanced(s):
"""
Check if the input string s is properly nested and balanced.
"""
stack = []
opening = '([{'
closing = ')]}'
matching = {')': '(', ']': '[', '}': '{'}
for char in s:
if char in opening:
stack.append(char)
elif char in closing:
... | from solution import check_balanced_brackets
def test_single_balanced_strings():
assert check_balanced_brackets(1, ["([]{})"]) == ["YES"]
assert check_balanced_brackets(1, ["[{}]"]) == ["YES"]
assert check_balanced_brackets(1, ["()[]{}"]) == ["YES"]
def test_single_unbalanced_strings():
assert check_b... | [
{
"docstring": "Check if the input string s is properly nested and balanced.",
"function_declaration": "def is_balanced(s):",
"function_name": "is_balanced",
"parameter_list": "(s)"
},
{
"docstring": "Given a number of strings, determine for each string if it is balanced and properly nested.... | [
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced_and_nested(strings):\n \"\"\"\n Checks if each string in the list is properly nested and balanced.\n \n :param strings: List of strings ... | trial_gpt4o_8 | {
"original_instruction": "Lilly is a software engineer working on a new string manipulation library. One of the functionalities she needs to implement is a function that checks the balance and proper nesting of a specific type of brackets used in a particular scientific notation. The notation uses three types of bra... | 0.742833 | Apps_15987 | C | [
"is_balanced",
"check_balanced_brackets"
] | 2 | [
[
"check_balanced_brackets",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 79beb853aa160bc9ff4ce2826e4c4e61f9cbd503 | 358f6a76db93d22142931ea6a3592c937570def4 | |||
v1.0 | complete | Apps | Apps_16238_C | def can_be_palindrome_by_removing_one_char(s: str) -> bool:
"""
Determines if a string can be converted to a palindrome
by removing exactly one character.
"""
def is_palindrome(x):
return x == x[::-1]
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[r... | def can_be_palindrome_by_removing_one_char(s):
"""
Determines if a string can be converted to a palindrome
by removing exactly one character.
"""
def is_palindrome(x):
return x == x[::-1]
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
... | import pytest
from solution import check_remove_one_char_palindrome
def test_example_case_1():
assert check_remove_one_char_palindrome("abca") == "YES"
def test_example_case_2():
assert check_remove_one_char_palindrome("abc") == "NO"
def test_full_palindrome():
assert check_remove_one_char_palindrome("ra... | [
{
"docstring": "Determines if a string can be converted to a palindrome\nby removing exactly one character.",
"function_declaration": "def can_be_palindrome_by_removing_one_char(s):",
"function_name": "can_be_palindrome_by_removing_one_char",
"parameter_list": "(s)"
},
{
"docstring": null,
... | [
0,
0,
1,
1,
0,
0,
0,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n def is_palindrome_range(i, j):\n return all(s[k] == s[j-k+i] for k in range(i, j))\n\n l, r = 0, len(s) - 1\n while l ... | trial_gpt4o_8 | {
"original_instruction": "You are given a string s consisting of lowercase English letters. Your task is to determine if you can remove exactly one character from the string to make it a palindrome. A palindrome is a string that reads the same backward as forward.\n\nWrite a function to check if it is possible to co... | 0.757877 | Apps_16238 | C | [
"can_be_palindrome_by_removing_one_char",
"check_remove_one_char_palindrome"
] | 2 | [
[
"check_remove_one_char_palindrome",
"can_be_palindrome_by_removing_one_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7548548e25ab77d10b83ac33edeb13787e9e8e2 | f7637a601bc086006cd658c2ef87d94294701781 | |||
v1.0 | complete | Apps | Apps_16465_C | import re
from typing import List
def is_palindrome(s: str) -> bool:
""" Checks if the given string is a palindrome considering only alphanumeric characters and ignoring case.
Args:
s (str): The string to check.
Returns:
bool: True if the string is a palindrome, False otherwise.
... | import re
def is_palindrome(s):
"""
Checks if the given string is a palindrome considering only alphanumeric characters and ignoring case.
"""
cleaned = re.sub(r'[^A-Za-z0-9]', '', s).lower()
return cleaned == cleaned[::-1]
def check_palindromes(strings):
"""
Takes a list of strings and re... | from solution import is_palindrome, check_palindromes
def test_is_palindrome():
assert is_palindrome("A man a plan a canal Panama") == True
assert is_palindrome("No lemon, no melon") == True
assert is_palindrome("Hello, World!") == False
assert is_palindrome("Madam In Eden, I'm Adam") == True
asser... | [
{
"docstring": "Checks if the given string is a palindrome considering only alphanumeric characters and ignoring case.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a list of... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if a given string s is a palindrome.\n Ignores spaces, punctuation, and capitalization.\n \"\"\"\n ... | trial_gpt4o_6 | {
"original_instruction": "Write a program that reads strings until an empty string is given.\nThe program needs to determine if each string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, ignoring spaces, punctuation, and capitalizati... | 0.878294 | Apps_16465 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c38be2b2f2743ddd353628c6eef71c5c27843b45 | 4375eb30ea8aac429903568fe8abad851e5719a0 | |||
v1.0 | complete | Apps | Apps_16349_C | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(values[i]) for i in range(n)]
for u, v in edges:
nodes[u - 1].children.append(nodes[v - 1])
nodes[v - 1].children.append(nodes[u - 1])
ret... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(values[i]) for i in range(n)]
for u, v in edges:
nodes[u - 1].children.append(nodes[v - 1])
nodes[v - 1].children.append(nodes[u - 1])
ret... | from solution import find_max_path_sum_in_trees
def test_max_path_sum_single_case():
T = 1
test_cases = [(6, [1, 2, -3, 4, -2, 6], [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)])]
result = find_max_path_sum_in_trees(T, test_cases)
assert result == [7]
def test_max_path_sum_multiple_cases():
T = 2
te... | [] | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(n, values, edges):\n nodes = [TreeNode(... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree structure with `n` nodes, each node containing a single integer value. The tree is rooted at node `1`. Your task is to implement a function that calculates the maximum path sum for any path in the tree.\n\nA path is defined as any sequence of nodes from some starting no... | 0.611877 | Apps_16349 | C | [
"build_tree",
"max_path_sum",
"find_max_path_sum_in_trees"
] | 3 | [
[
"find_max_path_sum_in_trees",
"build_tree"
],
[
"find_max_path_sum_in_trees",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | dc57d7d6486b9caba2867e8d84b3df64960aed58 | a9fefbe7298f0d97cf1240ae50aedb635d27175a | |||
v1.0 | complete | Apps | Apps_16467_C | def is_lucky_number(n: int) -> bool:
"""
Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.
>>> is_lucky_number(4) == True
>>> is_lucky_number(7) == True
>>> is_lucky_number(44) == True
>>> is_lucky_number(47) == True
>>> is_lucky_number(5) == False
>>> is_lu... | def is_lucky_number(n):
"""
Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.
"""
while n > 0:
digit = n % 10
if digit != 4 and digit != 7:
return False
n = n // 10
return True
def count_lucky_numbers(A, B):
"""
Returns the c... | from solution import is_lucky_number, count_lucky_numbers
def test_is_lucky_number():
# Test lucky numbers
assert is_lucky_number(4) == True
assert is_lucky_number(7) == True
assert is_lucky_number(44) == True
assert is_lucky_number(47) == True
# Test non-lucky numbers
assert is_lucky_numbe... | [
{
"docstring": "Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.",
"function_declaration": "def is_lucky_number(n):",
"function_name": "is_lucky_number",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of lucky numbers within the range [A, B] inclu... | [
1,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_lucky_number(n):\n \"\"\"\n Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.\n \"\"\"\n while n > 0:\n digi... | trial_gpt4o_0 | {
"original_instruction": "Chef loves playing with numbers and he recently discovered the concept of \"lucky numbers\". A lucky number is defined as a number that contains only the digits 4 and 7. Chef is curious to know how many lucky numbers exist within a given range \\([A, B]\\) inclusive. Can you help him?\n\n--... | 0.639386 | Apps_16467 | C | [
"is_lucky_number",
"count_lucky_numbers",
"main"
] | 3 | [
[
"count_lucky_numbers",
"is_lucky_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f634911adaada8349341e39ba5fa5ae83f3f0014 | 21697342bb490880e0839f77f647ae96fbb4e0c8 | |||
v1.0 | complete | Apps | Apps_16673_C | def max_non_consecutive_sum(arr):
""" Find the maximum sum of any subsequence such that no two consecutive elements are selected.
>>> max_non_consecutive_sum([3, 2, 5, 10])
13
>>> max_non_consecutive_sum([-1, -2, -3, -4])
0
"""
def process_input(input_str):
""" Process the input string ... | def max_non_consecutive_sum(arr):
if not arr:
return 0
including = 0
excluding = 0
for num in arr:
new_excluding = max(including, excluding)
including = excluding + num
excluding = new_excluding
return max(including, excluding)
def process_input(input_... | from solution import max_non_consecutive_sum, process_input, format_output, solve
def test_max_non_consecutive_sum():
assert max_non_consecutive_sum([3, 2, 5, 10]) == 13
assert max_non_consecutive_sum([-1, -2, -3, -4]) == 0
assert max_non_consecutive_sum([1, 2, 3, 4, 5]) == 9
assert max_non_consecutive... | [
{
"docstring": null,
"function_declaration": "def max_non_consecutive_sum(arr):",
"function_name": "max_non_consecutive_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_str):",
"function_name": "process_input",
"parameter_li... | [
1,
0,
1,
0,
0,
1,
0,
1,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_no_consecutive(arr):\n include = 0 # sum including the current element\n exclude = 0 # sum excluding the current element\n \n for num in a... | trial_gpt4o_7 | {
"original_instruction": "You are given an array of $N$ integers. Your task is to find the maximum sum of any subsequence such that no two consecutive elements are selected.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test ... | 0.650275 | Apps_16673 | C | [
"max_non_consecutive_sum",
"process_input",
"format_output",
"solve"
] | 4 | [
[
"process_input",
"max_non_consecutive_sum"
],
[
"solve",
"format_output"
],
[
"solve",
"process_input"
]
] | 3 | [
"process_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | c02ee9a33158589df44a0a6fdbc55ae4eec99dda | 8c6065819dbcb383ec9f9229b7aa629329828d1f | |||
v1.0 | complete | Apps | Apps_16622_C | from typing import List, Tuple
def create_grid_and_start(n: int, k: int) -> Tuple[List[List[str]], int, int]:
""" Creates an n x n grid with exactly k storage units and specifies a starting point (r, c) for unlocking.
>>> create_grid_and_start(5, 5)
([['1', '0', '0', '0', '0'],
['0', '1', '0', ... | def create_grid_and_start(n, k):
"""
Creates an n x n grid and specifies a starting point (r, c) such that
exactly k storage units can be unlocked without spreading corruption beyond k units.
"""
grid = [['0'] * n for _ in range(n)]
storage_units = k
# Start placing '1's in the diagonal... | import pytest
from solution import create_grid_and_start, format_output, place_and_unlock
def test_create_grid_and_start_with_5_and_5():
grid, r, c = create_grid_and_start(5, 5)
assert grid == [['1', '0', '0', '0', '0'],
['0', '1', '0', '0', '0'],
['0', '0', '1', '0', '0... | [
{
"docstring": "Creates an n x n grid and specifies a starting point (r, c) such that\nexactly k storage units can be unlocked without spreading corruption beyond k units.",
"function_declaration": "def create_grid_and_start(n, k):",
"function_name": "create_grid_and_start",
"parameter_list": "(n, k... | [
0,
0,
1,
1,
0,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def place_storage_units(n, k):\n \"\"\"\n This function places exactly k storage units on an n x n grid in such a way that corruption can be contained.\n I... | trial_gpt4o_3 | {
"original_instruction": "You are a programmer on a mission to retrieve ancient data from an abandoned server room. The room contains an n × n grid of lockers, each potentially containing a storage unit. Each locker is identified by its row and column in the grid, both ranging from 1 to n. To retrieve the data, you ... | 0.643512 | Apps_16622 | C | [
"create_grid_and_start",
"format_output",
"place_and_unlock"
] | 3 | [
[
"place_and_unlock",
"create_grid_and_start"
],
[
"place_and_unlock",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 14bddf102ccbd0f067a8d5c33d4126d8c7b52d98 | 10db4c9a138be7eace947f9868a7c4abdbf62c16 | |||
v1.0 | complete | Apps | Apps_16820_C | def palindromic_substrings(s: str) -> List[str]:
""" Returns all unique palindromic substrings of the input string in lexicographical order.
>>> palindromic_substrings("aabaa") ["a", "aa", "aabaa", "aba", "b"]
>>> palindromic_substrings("abccb") ["a", "b", "bccb", "c", "cc"]
""" | def is_palindrome(s):
"""
Checks if a given string is a palindrome.
"""
return s == s[::-1]
def palindromic_substrings(s):
"""
Returns all unique palindromic substrings of the input string in lexicographical order.
"""
palindromes = set()
for i in range(len(s)):
for j i... | from solution import palindromic_substrings
def test_single_character():
assert palindromic_substrings("a") == ["a"]
assert palindromic_substrings("b") == ["b"]
def test_no_palindromes():
assert palindromic_substrings("abc") == ["a", "b", "c"]
def test_all_palindromes():
assert palindromic_substrings... | [
{
"docstring": "Checks if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all unique palindromic substrings of the input string in lexicographical order.",
"function_de... | [
1,
0,
0,
0,
1,
0,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef find_palindromic_substrings(s):\n palindromic_substrings = set()\n n = len(s)\n \n # Generate all ... | trial_gpt4o_7 | {
"original_instruction": "Write a function that takes a string s as input and returns all possible substrings that are palindromes. A palindromic string is one that reads the same forward and backwards. The substrings should be returned in an array in lexicographical order and should not contain duplicates.\n\nFor e... | 0.741408 | Apps_16820 | C | [
"is_palindrome",
"palindromic_substrings"
] | 2 | [
[
"palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 37b1bcc54ae6366e0c2da9af5d15cc48b865f022 | d36cd597aabf0a072893df3ed0accd7d20c79426 | |||
v1.0 | complete | Apps | Apps_16867_C | def process_input(t: int, test_cases_input: List[str]) -> List[int]:
"""
Determine the largest rectangular section of the garden that only contains empty spaces for each test case.
Args:
t: The number of test cases
test_cases_input: A list of strings representing the grid input for each test c... | def maximal_rectangle(grid):
"""
This function takes a grid as input and returns the area of the largest rectangle
containing only 0s.
"""
if not grid:
return 0
n, m = len(grid), len(grid[0])
dp = [0] * m
max_area = 0
for i in range(n):
for j in range(m):
... | from solution import process_input
def test_example_cases():
t = 2
test_cases_input = [
"3 4",
"1 0 0 0",
"0 0 0 1",
"0 1 0 0",
"2 5",
"0 1 1 0 1",
"0 0 0 0 0"
]
expected_output = [4, 5]
assert process_input(t, test_cases_input) == ... | [
{
"docstring": "This function takes a grid as input and returns the area of the largest rectangle\ncontaining only 0s.",
"function_declaration": "def maximal_rectangle(grid):",
"function_name": "maximal_rectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration"... | [
1,
1,
0,
1,
0,
0,
1,
1,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0] * m\n\n f... | trial_gpt4o_1 | {
"original_instruction": "Polycarp has a garden represented as a grid with $n$ rows and $m$ columns. The garden can either be empty (represented by a 0) or have weeds (represented by a 1). Polycarp wants to plant a rectangular section of flowers in the garden. You need to determine the size of the largest rectangula... | 0.592115 | Apps_16867 | C | [
"maximal_rectangle",
"largest_rectangles",
"process_input"
] | 3 | [
[
"largest_rectangles",
"maximal_rectangle"
],
[
"process_input",
"largest_rectangles"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 1ad838eef9e1623935170dc4be1d2fa87e889885 | 75d761f018a03539d126ea581b5d310211897034 | |||
v1.0 | complete | Apps | Apps_16889_C | from typing import List
def is_happy_number(num: int) -> bool:
"""
Determine if a number is a happy number.
>>> is_happy_number(1) == True
>>> is_happy_number(7) == True
>>> is_happy_number(10) == True
>>> is_happy_number(13) == True
>>> is_happy_number(19) == True
>>> is_happy_number(... | def is_happy_number(num):
"""
Determine if a number is a happy number.
"""
seen = set()
while num != 1 and num not in seen:
seen.add(num)
num = sum(int(digit) ** 2 for digit in str(num))
return num == 1
def happy_number_index(n):
"""
Returns the nth happy number... | from solution import happy_number_index, is_happy_number
def test_happy_number_index():
assert happy_number_index(1) == 1
assert happy_number_index(2) == 7
assert happy_number_index(3) == 10
assert happy_number_index(4) == 13
assert happy_number_index(5) == 19
assert happy_number_index(10) == 4... | [
{
"docstring": "Determine if a number is a happy number.",
"function_declaration": "def is_happy_number(num):",
"function_name": "is_happy_number",
"parameter_list": "(num)"
},
{
"docstring": "Returns the nth happy number.",
"function_declaration": "def happy_number_index(n):",
"func... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy_number(num):\n \"\"\"\n Helper function to determine if a number is happy.\n \"\"\"\n visited = set()\n \n while num != 1 and num not... | trial_gpt4o_4 | {
"original_instruction": "Create a function `happy_number_index(n)` that returns the `n`th \"happy number\". A \"happy number\" is defined by the following process: \n\n1. Starting with any positive integer, replace the number by the sum of the squares of its digits in base 10.\n2. Repeat the process until the numbe... | 0.657723 | Apps_16889 | C | [
"is_happy_number",
"happy_number_index"
] | 2 | [
[
"happy_number_index",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02b355b8dacb3054ca0a0e236bd8b6de63ccb5b8 | e2a58947220c594df8a7e6d1f91a1eb37198e73b | |||
v1.0 | complete | Apps | Apps_16937_C | def maximum_sum_rectangle(matrix):
"""
Returns the maximum sum of any rectangle within the given 2D matrix.
>>> maximum_sum_rectangle([
... [1, 2, -1, -4, -20],
... [-8, -3, 4, 2, 1],
... [3, 8, 10, 1, 3],
... [-4, -1, 1, 7, -6]
... ])
29
>>> maximum_sum... | def maximum_sum_rectangle(matrix):
"""
Returns the maximum sum of any rectangle within the given 2D matrix.
"""
if not matrix or not matrix[0]:
return 0
m, n = len(matrix), len(matrix[0])
max_sum = float('-inf')
for left in range(n):
temp = [0] * m
for right in ... | from solution import maximum_sum_rectangle
def test_example1():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert maximum_sum_rectangle(matrix) == 29
def test_example2():
matrix = [
[2, 1, -3, -4, 5],
[0, 6,... | [
{
"docstring": "Returns the maximum sum of any rectangle within the given 2D matrix.",
"function_declaration": "def maximum_sum_rectangle(matrix):",
"function_name": "maximum_sum_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum of any contig... | [
0,
1,
1,
1,
1,
1,
0,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_rectangle(matrix):\n \"\"\"\n Given a 2D matrix, this function finds the maximum sum of any rectangle within the matrix.\n\n Parameters:\n m... | trial_gpt4o_5 | {
"original_instruction": "Given a 2D matrix of size m x n, your task is to find the maximum sum of any rectangle within the matrix.\n\n\nA rectangle in the matrix is defined by selecting two rows and two columns, and includes all the elements between and including the intersections of these rows and columns.\n\n\nEx... | 0.647811 | Apps_16937 | C | [
"maximum_sum_rectangle",
"kadane"
] | 2 | [
[
"maximum_sum_rectangle",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb6d2c753d5cc34e85106ed5f1178341ab2a6001 | 0ba3bfea5d24bb9b39a852b807643f13d6b9e0eb | |||
v1.0 | complete | Apps | Apps_16911_C | def elf_number_spiral(n: int, queries: List[Tuple[int, int]]) -> List[int]:
"""Answer queries about the positions of numbers in an n×n number spiral.
Args:
n (int): The size of the spiral (an odd number).
queries (List[Tuple[int, int]]): A list of queries where each query is a tuple (i, j).
Re... | def generate_spiral_matrix(n):
spiral = [[0] * n for _ in range(n)]
x, y = n // 2, n // 2 # starting at the center of the matrix
spiral[x][y] = 1
number = 2
for layer in range(1, (n // 2) + 1):
y += 1 # move right to the first new cell in this layer
spiral[x][y] = number
n... | import pytest
from solution import elf_number_spiral
def test_case_1():
n, t = 5, 3
queries = [(1, 1), (2, 3), (5, 4)]
expected = [17, 4, 24]
assert elf_number_spiral(n, queries) == expected
def test_case_2():
n, t = 3, 4
queries = [(1, 3), (2, 2), (3, 1), (3, 3)]
expected = [3, 1, 7, 9]
... | [
{
"docstring": null,
"function_declaration": "def generate_spiral_matrix(n):",
"function_name": "generate_spiral_matrix",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def elf_number_spiral(n, queries):",
"function_name": "elf_number_spiral",
"parameter... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_spiral_matrix(n):\n matrix = [[0] * n for _ in range(n)]\n x = y = n // 2\n dx, dy = 0, -1\n counter = 1\n \n for i in range(n * n):\... | trial_gpt4o_7 | {
"original_instruction": "A mysterious island is inhabited by elves, who love to play games to test their mathematical prowess. One such game is called \"Elf's Number Spiral\".\n\nThe game involves constructing a square spiral of size $n × n$ filled with integers starting from 1 and spiraling outwards in a clockwise... | 0.543997 | Apps_16911 | C | [
"generate_spiral_matrix",
"elf_number_spiral"
] | 2 | [
[
"elf_number_spiral",
"generate_spiral_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06afd1ea12df3c79c806240c892f7bf95deed9ed | 95b67f81e1dc23167b5a910a10838f76b4fced51 | |||
v1.0 | complete | Apps | Apps_17012_C | from typing import List
def is_unique(s: str) -> bool:
"""
Check if a string has all unique characters.
>>> is_unique("abcdef")
True
>>> is_unique("aabbcc")
False
>>> is_unique("abcdeff")
False
>>> is_unique("qwerty")
True
"""
pass
def longest_unique_string(test_cases: ... | def is_unique(s):
"""
Check if all characters in the string are unique.
"""
return len(s) == len(set(s))
def longest_unique_string(test_cases):
"""
For each test case, return the longest string with all unique characters.
If no such string exists, return 'NONE'.
"""
results = []
... | from solution import is_unique, longest_unique_string
def test_is_unique():
assert is_unique("abcdef") == True
assert is_unique("aabbcc") == False
assert is_unique("abcdeff") == False
assert is_unique("qwerty") == True
def test_longest_unique_string():
assert longest_unique_string([["abcdef", "abb... | [
{
"docstring": "Check if all characters in the string are unique.",
"function_declaration": "def is_unique(s):",
"function_name": "is_unique",
"parameter_list": "(s)"
},
{
"docstring": "For each test case, return the longest string with all unique characters.\nIf no such string exists, retur... | [
1,
1,
1,
0,
1,
0,
0,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_unique_string(T, test_cases):\n \"\"\"\n Finds the longest unique string from the given test cases.\n \n Parameters:\n - T (int): number ... | trial_gpt4o_7 | {
"original_instruction": "You are given a list of strings. A string is considered \"unique\" if it does not have any repeated characters. Your task is to find the longest unique string from the given list. If there are multiple strings with the same length, return the one that appears first in the list.\n\n-----Inpu... | 0.764916 | Apps_17012 | C | [
"is_unique",
"longest_unique_string"
] | 2 | [
[
"longest_unique_string",
"is_unique"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e93811b2d4dbc3739274665e02e1b3450a35ddf0 | 0409402f1fc04cd30dfdbf1cea0e3718b27c113b | |||
v1.0 | complete | Apps | Apps_17102_C | import math
from typing import List
def is_frond_number(n: int) -> bool:
""" Check if a number is a Frond Number.
A Frond Number is defined as a number for which the sum of the factorials of its digits equals the number itself.
"""
return n == sum(math.factorial(int(digit)) for digit in str(n))
def fi... | import math
def is_frond_number(n):
"""
Check if a number is a Frond Number.
A Frond Number is defined as a number for which the sum of the factorials of its digits equals the number itself.
"""
return n == sum(math.factorial(int(digit)) for digit in str(n))
def find_frond_numbers(start, end):
... | from solution import find_frond_numbers, is_frond_number
def test_is_frond_number():
assert is_frond_number(1) == True
assert is_frond_number(2) == True
assert is_frond_number(145) == True
assert is_frond_number(40585) == True
assert is_frond_number(123) == False
def test_find_frond_numbers_in_sma... | [
{
"docstring": "Check if a number is a Frond Number.\nA Frond Number is defined as a number for which the sum of the factorials of its digits equals the number itself.",
"function_declaration": "def is_frond_number(n):",
"function_name": "is_frond_number",
"parameter_list": "(n)"
},
{
"docst... | [
1,
0,
1,
0,
0,
0,
1,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_frond_number(number):\n \"\"\"\n Check if a given number is a Frond Number.\n \"\"\"\n return number == sum(math.factorial(int(dig... | trial_gpt4o_9 | {
"original_instruction": "A mysterious traveler has stumbled upon a magical garden. Amidst the verdant foliage and vibrant flowers, surreal voices echo with enigmatic math problems. One such voice whispers:\n\n\"In this realm lies a special type of number known as the 'Frond Number'. A Frond Number is defined by a u... | 0.618306 | Apps_17102 | C | [
"is_frond_number",
"find_frond_numbers"
] | 2 | [
[
"find_frond_numbers",
"is_frond_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f129e41718108552b1db6db3e6203532afe85df | f5b348ef2206f91d1bc6ff32db59fa7abda567d8 | |||
v1.0 | complete | Apps | Apps_17154_C | def sum_polynomials(poly1: str, poly2: str) -> str:
""" Given two strings representing simplified polynomials, sum them up and return the result as a string of a simplified polynomial in descending order of powers.
>>> sum_polynomials("3x^2+4x+1", "2x^2+5") "5x^2+4x+6"
>>> sum_polynomials("6a", "7a^2+2a+3")... | import re
from collections import defaultdict
def parse_polynomial(poly):
"""
Parses a polynomial string into a dictionary with keys as (variable, power) and values as coefficients.
"""
if not poly:
return defaultdict(int)
terms = poly.split('+')
poly_dict = defaultdict(int)
... | from solution import sum_polynomials
def test_sum_polynomials():
assert sum_polynomials("3x^2+4x+1", "2x^2+5") == "5x^2+4x+6"
assert sum_polynomials("6a", "7a^2+2a+3") == "7a^2+8a+3"
assert sum_polynomials("5z^3+2z^1+1", "") == "5z^3+2z+1"
assert sum_polynomials("", "3x^2+4z+1") == "3x^2+4z+1"
asse... | [
{
"docstring": "Parses a polynomial string into a dictionary with keys as (variable, power) and values as coefficients.",
"function_declaration": "def parse_polynomial(poly):",
"function_name": "parse_polynomial",
"parameter_list": "(poly)"
},
{
"docstring": "Sums up two polynomial strings a... | [
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_polynomials(poly1, poly2):\n def parse_polynomial(poly):\n terms = {}\n if not poly:\n return terms\n\n poly = poly.repla... | trial_gpt4o_2 | {
"original_instruction": "Given two strings representing simplified polynomials, your task is to create a function that sums them up and returns the result as a string of a simplified polynomial in descending order of powers.\n\nEach polynomial will contain:\n- Only positive integer coefficients.\n- Only non-negativ... | 0.578994 | Apps_17154 | C | [
"parse_polynomial",
"sum_polynomials"
] | 2 | [
[
"sum_polynomials",
"parse_polynomial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e0a5b1cd377305d41d7707f2570ec4616cfe7fc7 | e824fc7c921f0134d90cb937ad74cd505f4b04ae | |||
v1.0 | complete | Apps | Apps_17101_C | def sieve_of_eratosthenes(max_num):
""" Generate a list of boolean values representing the primality of numbers from 0 to max_num. """
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
p = 2
while p * p <= max_num:
if is_prime[p]:
for i in range(p * p, max_num +... | import bisect
def sieve_of_eratosthenes(max_num):
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
p = 2
while p * p <= max_num:
if is_prime[p]:
for i in range(p * p, max_num + 1, p):
is_prime[i] = False
p += 1
return is_prime
def prim... | from solution import prime_selection
def test_prime_selection_example_1():
n = 6
q = 3
elements = [2, 17, 11, 4, 7, 20]
queries = [1, 3, 5]
assert prime_selection(n, q, elements, queries) == [2, 11, -1]
def test_prime_selection_example_2():
n = 5
q = 2
elements = [1, 5, 3, 9, 6]
qu... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": null,
"function_declaration": "def prime_selection(n, q, elements, queries):",
"function_name": "prime_selecti... | [
1,
1,
1,
1,
0,
1,
0,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i... | trial_gpt4o_9 | {
"original_instruction": "`Prime Selection`\n\nYou're given multiple requests for selecting prime numbers from a given list, and your task is to respond to each request efficiently.\n\n---Input---\n\nThe input consists of multiple lines:\n- The first line contains two integers `n` and `q` (1 ≤ n, q ≤ 10^5) — the num... | 0.636092 | Apps_17101 | C | [
"sieve_of_eratosthenes",
"prime_selection"
] | 2 | [
[
"prime_selection",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36c471046e61f9369e1a86150d67a8032ea37a3c | ce745e9caf1213a390d60e92d121b99e1f5af193 | |||
v1.0 | complete | Apps | Apps_17195_C | from typing import List, Tuple
def find_gcds(pairs: List[Tuple[int, int]]) -> List[int]:
"""
Takes a list of integer pairs and returns a list of their greatest common divisors (GCD).
Each pair consists of two positive integers.
The order in the output list corresponds to the order of pairs in the inpu... | from typing import List, Tuple
def gcd(a: int, b: int) -> int:
"""
Computes the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.
"""
while b:
a, b = b, a % b
return a
def find_gcds(pairs: List[Tuple[int, int]]) -> List[int]:
"""
Takes a list of integer p... | from solution import find_gcds
def test_find_gcds():
assert find_gcds([(8, 12), (9, 27), (20, 30)]) == [4, 9, 10]
assert find_gcds([(14, 35), (18, 24)]) == [7, 6]
assert find_gcds([(42, 56), (100, 200)]) == [14, 100]
assert find_gcds([(81, 27), (49, 21)]) == [27, 7]
assert find_gcds([]) == []
def ... | [
{
"docstring": "Computes the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Takes a list of integer pairs and returns a list of their greatest commo... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\n\ndef gcd(a: int, b: int) -> int:\n \"\"\"\n Returns the greatest common divisor of a and b using the Euclidean algorithm.\n ... | trial_gpt4o_9 | {
"original_instruction": "Implement a function that takes a list of integer pairs as input and returns a list of their greatest common divisors (GCD). Each pair will consist of two positive integers. The order in the output list should correspond to the order of pairs in the input list.\n\nWrite the function `find_g... | 0.729232 | Apps_17195 | C | [
"gcd",
"find_gcds"
] | 2 | [
[
"find_gcds",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65b24f70f88b48db22181b091435608da268dedf | 32334e2973fca5aba3e21752aa07429711c889fa | |||
v1.0 | complete | Apps | Apps_17182_C | from typing import List
def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, False otherwise.
"""
pass
def filter_primes(numbers: List[int]) -> List[int]:
""" Given an array of integers, return a new array containing only the elements that are prime numbers.
>>> filter_prime... | 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 filter... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([2, 3, 4, 5, 6, 7]) == [2, 3, 5, 7]
assert filter_primes([10, 12, 15, 17, 19, 20]) == [17, 19]
assert filter_primes([1, 13, 22, 29]) == [13, 29]
def test_filter_primes_with_no_primes():
assert filter_p... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the given list 'numbers'.",
"function_decl... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T... | trial_gpt4o_8 | {
"original_instruction": "Given an array of integers, write a function that returns a new array containing only the elements that are prime numbers.\n\nExamples:\n\n```\n[2, 3, 4, 5, 6, 7] => [2, 3, 5, 7]\n\n[10, 12, 15, 17, 19, 20] => [17, 19]\n\n[1, 13, 22, 29] => [13, 29]\n```",
"prompt_id": "00017182",
"row_... | 0.780441 | Apps_17182 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a9cc7ee244eb5d3fd2a3960e385035ca93f5affd | 2a4a6c1430f3bf2f508498f0a1541cf764e3d764 | |||
v1.0 | complete | Apps | Apps_17237_C | from typing import List
def divisor_sort(arr: List[int]) -> List[int]:
"""
Sort an array based on the sum of divisors for each element.
The sorting should maintain the relative order of elements in case of a tie.
Args:
arr (List[int]): A list of distinct positive integers.
... | from typing import List
def sum_of_divisors(n: int) -> int:
"""
Calculate the sum of all divisors of a given number n.
"""
total = 0
for i in range(1, n + 1):
if n % i == 0:
total += i
return total
def divisor_sort(arr: List[int]) -> List[int]:
"""
Sort array based ... | from solution import divisor_sort
def test_divisor_sort_example():
assert divisor_sort([10, 6, 8]) == [6, 8, 10]
def test_divisor_sort_single_element():
assert divisor_sort([5]) == [5]
def test_divisor_sort_two_elements():
assert divisor_sort([28, 12]) == [12, 28]
def test_divisor_sort_multiple_elements... | [
{
"docstring": "Calculate the sum of all divisors of a given number n.",
"function_declaration": "def sum_of_divisors(n):",
"function_name": "sum_of_divisors",
"parameter_list": "(n)"
},
{
"docstring": "Sort array based on the sum of divisors of each element.",
"function_declaration": "d... | [
0,
0,
1,
0,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Returns the sum of all divisors of a number including 1 and the number itself.\n ... | trial_gpt4o_4 | {
"original_instruction": "Your task is to implement a function that sorts an array, but with a twist: the sorting should be done based on the sum of the divisors for each element. If two elements have the same sum of divisors, maintain their relative order from the original array.\n\nYou will receive an array of dis... | 0.672622 | Apps_17237 | C | [
"sum_of_divisors",
"divisor_sort"
] | 2 | [
[
"divisor_sort",
"sum_of_divisors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c092bc7a90a3156ef0aaec412fe094d8d08563b7 | 66c8e5b0c5099339f9d1db1aeb8382c13834fea9 | |||
v1.0 | complete | Apps | Apps_17289_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.value = key
def findMinAndMax(root: TreeNode) -> (int, int):
"""
Finds the minimum and maximum values in a Binary Search Tree.
Args:
root (TreeNode): The root of the Binary Search Tree.
... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.value = key
def findMin(root):
current = root
while current.left is not None:
current = current.left
return current.value
def findMax(root):
current = root
while current.right is no... | from solution import TreeNode, findMinAndMax
def test_find_min_and_max_single_node():
root = TreeNode(10)
assert findMinAndMax(root) == (10, 10)
def test_find_min_and_max_left_skewed():
root = TreeNode(10)
root.left = TreeNode(5)
root.left.left = TreeNode(2)
assert findMinAndMax(root) == (2, 1... | [] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 fi... | trial_gpt4o_6 | {
"original_instruction": "Binary Search Trees - Find Minimum and Maximum\n\nWrite a function, findMinAndMax(), which finds and returns the minimum and maximum values in a Binary Search Tree (BST). The function takes the root of a BST as its argument and should return a tuple containing the minimum and maximum values... | 0.551504 | Apps_17289 | C | [
"findMin",
"findMax",
"findMinAndMax"
] | 3 | [
[
"findMinAndMax",
"findMax"
],
[
"findMinAndMax",
"findMin"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b87af6f530391920852ce9a1d095b8c7b8948a9c | 5b06c8ff2ff1da1b32dff34ea702dc78287c5ee7 | |||
v1.0 | complete | Apps | Apps_17215_C | import math
from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(13)
True
>>> is_prime(15)
... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def path_sums(grid, n, m):
# ... | def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(13)
assert not is_prime(15)
def test_path_sums():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert path_sums(grid,... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def path_sums(grid, n, m):",
"function_name": "path_sums",
"parameter_list": "(grid, n, m)"
},
{
"docstri... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef 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... | trial_gpt4o_0 | {
"original_instruction": "Given a 2D array of integers representing a grid, determine if there exists a path from the top-left corner to the bottom-right corner such that you can only move right or down, and the sum of the numbers on the path is a prime number.\n\n-----Input-----\nFirst line of the input contains a ... | 0.651019 | Apps_17215 | C | [
"is_prime",
"path_sums",
"solve",
"read_input",
"main"
] | 5 | [
[
"solve",
"is_prime"
],
[
"solve",
"path_sums"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 83ab9b4718365c737fb5d0ddf617396bdd5cf4d7 | 2a5dc2718b3deed33af46d4f1cb055cd1f6863b2 | |||
v1.0 | complete | Apps | Apps_17401_C | def is_subsequence(s: str, t: str) -> bool:
""" Helper function to check if s is a subsequence of t.
>>> is_subsequence("abc", "ahbgdc") == True
>>> is_subsequence("axc", "ahbgdc") == False
>>> is_subsequence("apple", "abpcplea") == True
>>> is_subsequence("plea", "abpcplea") == True
"""
def lo... | def is_subsequence(s, t):
"""
Helper function to check if s is a subsequence of t.
"""
t_iter = iter(t)
return all(char in t_iter for char in s)
def longestWordFromDict(s, dictionary):
"""
Returns the longest word from the dictionary that can be formed by deleting some of the letters
f... | from solution import longestWordFromDict, is_subsequence
def test_is_subsequence():
assert is_subsequence("abc", "ahbgdc") == True
assert is_subsequence("axc", "ahbgdc") == False
assert is_subsequence("apple", "abpcplea") == True
assert is_subsequence("plea", "abpcplea") == True
def test_longestWordFr... | [
{
"docstring": "Helper function to check if s is a subsequence of t.",
"function_declaration": "def is_subsequence(s, t):",
"function_name": "is_subsequence",
"parameter_list": "(s, t)"
},
{
"docstring": "Returns the longest word from the dictionary that can be formed by deleting some of the... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(s, t):\n \"\"\"\n Helper function to check if s is a subsequence of t.\n \"\"\"\n t_iter = iter(t)\n return all(char in t_iter for... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes a string and a dictionary of words, and returns the longest word from the dictionary that can be formed by deleting some of the letters from the given string without reordering the remaining letters. If there are ties, return the longest word that appears first i... | 0.748703 | Apps_17401 | C | [
"is_subsequence",
"longestWordFromDict"
] | 2 | [
[
"longestWordFromDict",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b28db0f091a5573fa64eaff09d310328dd4eb5a4 | 677e6206e62c0269d1c62aac1bfab910ce2e017a | |||
v1.0 | complete | Apps | Apps_17551_C | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def sum_at_prime_indices(lst):
"""
Given a list of integers, determine wheth... | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def sum_at_prime_indices(lst):
"""
Given a list of integers, determine wheth... | from solution import sum_at_prime_indices
def test_example_case():
assert sum_at_prime_indices([5, 3, 8, 7, 1, 2]) == 'odd'
def test_empty_list():
assert sum_at_prime_indices([]) == 'even'
def test_single_element():
assert sum_at_prime_indices([10]) == 'even'
def test_no_prime_indices():
assert sum_... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Given a list of integers, determine whether the sum of the integers at prime indices is even or odd.\nR... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 i... | trial_gpt4o_7 | {
"original_instruction": "Given a list of integers, determine whether the sum of the integers at prime indices is even or odd. \n\nFor example, consider the list `[5, 3, 8, 7, 1, 2]`:\n- At index 2 (a prime number), the value is 8.\n- At index 3 (a prime number), the value is 7.\n- At index 5 (a prime number), the v... | 0.725734 | Apps_17551 | C | [
"is_prime",
"sum_at_prime_indices"
] | 2 | [
[
"sum_at_prime_indices",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3359bbaefe26aa4765980dfb4ead11c9634f460b | 2d9f1806f067934c2d23c9645ff63c600ecc1f20 | |||
v1.0 | complete | Apps | Apps_17436_C | import heapq
from typing import List, Tuple
def dijkstra(n: int, graph: List[List[Tuple[int, int]]], start: int) -> List[int]:
"""
Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.
"""
distances = {node: float('infinity') for node in range(1, n+1)}
distances[start] ... | import heapq
def dijkstra(n, graph, start):
"""
Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.
"""
distances = {node: float('infinity') for node in range(1, n+1)}
distances[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_node... | def test_navigation_system_simple_case():
n = 5
m = 6
edges = [
(1, 2, 10),
(1, 3, 3),
(2, 3, 1),
(3, 4, 2),
(4, 5, 5),
(2, 5, 9)
]
q = 3
queries = [
(1, 5),
(2, 4),
(1, 4)
]
assert navigation_system(n, m, edges, q,... | [
{
"docstring": "Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.",
"function_declaration": "def dijkstra(n, graph, start):",
"function_name": "dijkstra",
"parameter_list": "(n, graph, start)"
},
{
"docstring": null,
"function_declaration": "def navigatio... | [
1,
0,
0,
0,
0,
0,
0,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, adj, src):\n distances = [float('inf')] * (n + 1)\n distances[src] = 0\n pq = [(0, src)] # (distance, node)\n while pq:... | trial_gpt4o_9 | {
"original_instruction": "A city wants to develop a new navigation system to aid drivers. The road network is represented as a graph where intersections are nodes and roads are edges. Each road has a travel time associated with it (an integer).\n\nThe city wants to implement a system that can answer multiple queries... | 0.743714 | Apps_17436 | C | [
"dijkstra",
"navigation_system"
] | 2 | [
[
"navigation_system",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 50c05b00b7ea0ee8e826690765af50e7522e5ebf | 0d6761e6aa8c0652f923415f556f4b0b3cb864cc | |||
v1.0 | complete | Apps | Apps_17628_C | def format_solution(n, m, preferences):
""" Determine the maximum number of happy pairs and provide an arrangement.
A "happy pair" is defined as two adjacent kids who have the same preference for a toy.
The function should return the maximum number of happy pairs and any example arrangement.
>>> format... | def max_happy_pairs(n, m, preferences):
from collections import Counter
counts = Counter(preferences)
pairs = 0
remaining = []
for toy in counts:
pairs += counts[toy] // 2
if counts[toy] % 2:
remaining.append(toy)
arrangement = []
for toy, count in counts.i... | from solution import format_solution
def test_example1():
n = 6
m = 3
preferences = [1, 1, 3, 2, 2, 3]
expected_pairs = 3
result_pairs, result_arrangement = format_solution(n, m, preferences)
assert result_pairs == expected_pairs
assert len(result_arrangement) == n + 1
assert result_arr... | [
{
"docstring": null,
"function_declaration": "def max_happy_pairs(n, m, preferences):",
"function_name": "max_happy_pairs",
"parameter_list": "(n, m, preferences)"
},
{
"docstring": null,
"function_declaration": "def format_solution(n, m, preferences):",
"function_name": "format_solu... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef max_happy_pairs(n, m, preferences):\n \"\"\"\n Determines the maximum number of happy pairs and gives an example arrang... | trial_gpt4o_3 | {
"original_instruction": "Evelyn is planning a birthday party and wants to arrange games for the kids. One of the games involves arranging the kids in a circle. Evelyn wants the arrangement to have the maximum number of \"happy pairs.\" A \"happy pair\" is defined as two adjacent kids who have the same preference fo... | 0.611772 | Apps_17628 | C | [
"max_happy_pairs",
"format_solution"
] | 2 | [
[
"format_solution",
"max_happy_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 073d76cd8c8246d325590d63905219acc0b898f1 | b41e45a6bd299b4b8437211fad8611e6afc410c0 | |||
v1.0 | complete | Apps | Apps_17768_C | def is_prime(n: int) -> bool:
"""Check if a number is a prime number.
"""
pass
def filter_primes(nums: List[int]) -> List[int]:
"""Return a list of prime numbers from the given list of integers.
>>> filter_primes([2,3,4,5,6,7,8,9,10])
[2,3,5,7]
>>> filter_primes([15,21,22,23,25,29])
[2... | def is_prime(n):
"Check if a number is a prime number."
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(nums):
"Return a li... | from solution import filter_primes
def test_filter_primes_normal_case():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_with_larger_numbers():
assert filter_primes([15, 21, 22, 23, 25, 29]) == [23, 29]
def test_filter_primes_no_primes():
assert filter_primes([1,... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return a list of prime numbers from the given list of integers.",
"function_declaration": "def filter_primes(nums):",... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <=... | trial_gpt4o_9 | {
"original_instruction": "Given a list of integers, your task is to implement a function that returns the list of all prime numbers present in the initial list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Ensure the function efficiently determines whether a number... | 0.787853 | Apps_17768 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b8f2a6009c0224d2211bd0e42655a88abb35c873 | 715c55cdf2c8ed93ccb64ba404b5b96b0e7ecac2 | |||
v1.0 | complete | Apps | Apps_17791_C | from typing import List, Tuple
from math import sqrt
from itertools import permutations
def minimum_travel_distance(houses: List[Tuple[int, int]]) -> float:
"""Calculate the minimal total distance the postman must travel to deliver all the mail and return to the origin.
>>> minimum_travel_distance([(1, 2), (3... | from itertools import permutations
from math import sqrt
def euclidean_distance(point1, point2):
return sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2)
def total_distance(path):
# Path includes return to the origin
distance = 0
for i in range(len(path) - 1):
distance += euclidean... | from solution import minimum_travel_distance
def test_minimum_travel_distance_with_houses():
assert minimum_travel_distance([(1, 2), (3, 4), (6, 8), (2, 1)]) > 20 # Depends on optimal calculation
assert minimum_travel_distance([(0, 1), (0, 2)]) == 4 # Optimal path is (0,0) -> (0,1) -> (0,2) -> (0,0)
asse... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": null,
"function_declaration": "def total_distance(path):",
"function_name": "total_distance",
"par... | [
0,
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points p1 and p2.\n \"\"\"\n re... | trial_gpt4o_1 | {
"original_instruction": "The residents of Smalltown have recently implemented a new delivery system for their postal service. Each house is represented as a point on a 2D grid, and each point has coordinates (x, y).\n\nThe postman starts at the origin point (0, 0) and has a list of house coordinates he needs to del... | 0.609525 | Apps_17791 | C | [
"euclidean_distance",
"total_distance",
"minimum_travel_distance"
] | 3 | [
[
"minimum_travel_distance",
"total_distance"
],
[
"total_distance",
"euclidean_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1c13565c1a00f82d8b5cbd102cc0e5fe26263be8 | 678a0b98cd01138d7012fac7685996c45695e9e8 | |||
v1.0 | complete | Apps | Apps_17757_C | 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... | 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 filter_primes
def test_filter_primes_empty_list():
assert filter_primes([]) == []
def test_filter_primes_no_primes():
assert filter_primes([4, 6, 8, 10, 12]) == []
def test_filter_primes_with_primes():
assert filter_primes([2, 3, 4, 5, 10, 13, 17]) == [2, 3, 5, 13, 17]
def test_filt... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the original list.",
"function_declaration": "def filter_pr... | [
1,
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Ensure the function performs the prime-checking efficiently for large lists.",
"prompt_id": "00017757",
"row_id": 17757,
"seed_ids": "[3067]"
} | 0.802001 | Apps_17757 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f5d0fa85cb576d0034ff09a234a608d76a248df | 5167b369b132ca0a89cd05f7a79f2cd4c45a528d | |||
v1.0 | complete | Apps | Apps_17821_C | def filter_primes(numbers: List[int]) -> List[int]:
""" Returns a list of prime numbers from the given list of integers.
>>> filter_primes([4, 6, 7, 9, 11, 13, 15])
[7, 11, 13]
>>> filter_primes([0, 1, 2, 3])
[2, 3]
""" | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(number... | from solution import filter_primes
def test_filter_primes_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filter_primes_mixed():
assert filter_primes([4, 6, 7, 9, 11, 13, 15]) == [7, 11, 13]... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of integers.",
"function_declaration": "def filter_primes(numb... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if... | trial_gpt4o_8 | {
"original_instruction": "Write a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list, preserving their order.\n\n```\ninput: [4, 6, 7, 9, 11, 13, 15]\noutput: [7, 11, 13]\nexample: When the function is called with the above input, it s... | 0.672099 | Apps_17821 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1701ac01104da2cde18d376e508b1d045da1963a | 6b2cf1241d6ac412461f96c1e03ecd791a2fe227 | |||
v1.0 | complete | Apps | Apps_17585_C | import heapq
from collections import Counter
def rearrange_string(s: str) -> str:
""" Given a string s of length n consisting of uppercase and lowercase English letters,
construct a new string t by rearranging the characters of s such that no two adjacent
characters in t are the same. If it is not possib... | from collections import Counter
import heapq
def rearrange_string(s):
char_count = Counter(s)
max_heap = [(-count, char) for char, count in char_count.items()]
heapq.heapify(max_heap)
previous_char = None
previous_freq = 0
result = []
while max_heap:
current_freq, current_... | def test_rearrange_string():
assert solve("aabbcc") == "abcabc" or solve("aabbcc") == "acbacb"
assert solve("aaa") == "Impossible"
assert solve("a") == "a"
assert solve("ab") == "ab" or solve("ab") == "ba"
assert solve("aaabbbc") == "abababc" or solve("aaabbbc") == "ababacb" or solve("aaabbbc") == "... | [
{
"docstring": null,
"function_declaration": "def rearrange_string(s):",
"function_name": "rearrange_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def solve(s):",
"function_name": "solve",
"parameter_list": "(s)"
}
] | [
1,
0,
0,
0,
0,
1,
1,
1,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nimport heapq\n\ndef rearrange_string(s):\n \"\"\"\n Rearranges string s such that no two adjacent characters are the same.\n ... | trial_gpt4o_9 | {
"original_instruction": "You are given a string s of length n consisting of uppercase and lowercase English letters. Construct a new string t by rearranging the characters of s such that no two adjacent characters in t are the same. If it is not possible to construct such string t, output \"Impossible\".\n\n-----In... | 0.744608 | Apps_17585 | C | [
"rearrange_string",
"solve"
] | 2 | [
[
"solve",
"rearrange_string"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 944a6281a7c7ae80b96d2d0e939b3bc963df397a | c5f137ff126a551201809e0798d4f39f176cbda6 | |||
v1.0 | complete | Apps | Apps_17589_C | from typing import List, Tuple
def prime_sum_subsets(input_data: str) -> List[int]:
""" Determine the smallest length of subsets whose sum is a prime number.
Args:
input_data (str): String input containing multiple test cases.
Returns:
List[int]: List containing the size of the smallest subset... | from itertools import combinations
import math
def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
def smallest_prime... | from solution import prime_sum_subsets
def test_example_case():
input_data = '1\n5\n1 2 3 4 5'
assert prime_sum_subsets(input_data) == [1]
def test_no_prime_subsets():
input_data = '1\n4\n4 6 8 10'
assert prime_sum_subsets(input_data) == [-1]
def test_prime_subset_lengths():
input_data = '2\n3\n1... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def smallest_prime_subset_length(test_cases):",
"function_name": "smallest_prime_subset_length",
"parameter_l... | [
1,
1,
1,
0,
1,
0,
0,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom math import isqrt\n\ndef is_prime(number):\n if number < 2:\n return False\n for i in range(2, isqrt(number) +... | trial_gpt4o_8 | {
"original_instruction": "You are given an array of N$N$ integers. Your task is to determine if there exists a subset of this array whose sum is a prime number and if such a subset exists, find the smallest length of such a subset.\n\n-----Input-----\n- The first line of the input contains a single integer T$T$ deno... | 0.646069 | Apps_17589 | C | [
"is_prime",
"smallest_prime_subset_length",
"parse_input",
"prime_sum_subsets"
] | 4 | [
[
"prime_sum_subsets",
"parse_input"
],
[
"prime_sum_subsets",
"smallest_prime_subset_length"
],
[
"smallest_prime_subset_length",
"is_prime"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | a17d63c7a5447dae65ece056ce4befe7d4975328 | 4a8c50a92d20daf026cfcfa009a9622da44ca6ed | |||
v1.0 | complete | Apps | Apps_17804_C | def is_prime(n: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(13)
True
>>> is_prime(25)
False
>>> is_prime(89)
True
"""
pass
def smallest_prime_fibonacci(a: int, b: int) -> int:
... | def is_prime(n):
"""
Check if a number is prime.
"""
if n < 2:
return False
if n in (2, 3):
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return ... | def test_smallest_prime_fibonacci():
assert smallest_prime_fibonacci(10, 100) == 13
assert smallest_prime_fibonacci(50, 60) == -1
assert smallest_prime_fibonacci(1, 1) == -1
assert smallest_prime_fibonacci(1, 2) == 2
assert smallest_prime_fibonacci(60, 1000) == 89
assert smallest_prime_fibonacci... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest prime number that is also a Fibonacci number in the range [a, b].",
"function_declaration": "def smallest_pr... | [
0,
0,
0,
0,
1,
0,
1,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 ... | trial_gpt4o_7 | {
"original_instruction": "Kakashi is a fan of prime numbers and Fibonacci sequences. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A Fibonacci sequence is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with ... | 0.86105 | Apps_17804 | C | [
"is_prime",
"smallest_prime_fibonacci"
] | 2 | [
[
"smallest_prime_fibonacci",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9c9c166ea7f983d0cc36d1076604491fabe0d3a1 | 71ad0d9e100449b568f42262a9660899b69d704a | |||
v1.0 | complete | Apps | Apps_17894_C | from typing import List
def untangle_list(arr: List[int]) -> List[int]:
"""
Given an integer array `arr`, return a new array containing the prime numbers from
the input array followed by the non-prime numbers, both groups sorted in ascending order.
>>> untangle_list([11, 4, 6, 7, 9, 10, 5])
[5, 7,... | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + ... | from solution import untangle_list
def test_untangle_list_primes_and_non_primes():
assert untangle_list([11, 4, 6, 7, 9, 10, 5]) == [5, 7, 11, 4, 6, 9, 10]
def test_untangle_list_primes_and_non_primes_2():
assert untangle_list([29, 15, 14, 23, 8, 3]) == [3, 23, 29, 8, 14, 15]
def test_untangle_list_empty():... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing the prime numbers from the input array followed by\nthe non-prime numbers... | [
1,
0,
0,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n ... | trial_gpt4o_0 | {
"original_instruction": "Given an integer array ```arr```, write a function ```untangle_list()``` that returns a new array containing the prime numbers from the input array followed by the non-prime numbers, both groups sorted in ascending order. \n\nThe function signature is:\n```python\ndef untangle_list(arr: Lis... | 0.614483 | Apps_17894 | C | [
"is_prime",
"untangle_list"
] | 2 | [
[
"untangle_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 38a0057279923c5558e041dbf92238acb6226c63 | 38f1303bd11674e72c65b78ec843021327fc25d9 | |||
v1.0 | complete | Apps | Apps_17935_C | import fnmatch
from typing import List
def matches_patterns(filenames: List[str], patterns: List[str]) -> List[str]:
"""
Determine for each pattern if there is any filename from the email list that matches the pattern.
Wildcard '?' matches exactly one character while '*' matches zero or more characters of... | import fnmatch
def matches_patterns(filenames, patterns):
results = []
for pattern in patterns:
matched = any(fnmatch.fnmatch(filename, pattern) for filename in filenames)
results.append("YES" if matched else "NO")
return results
def solve(test_cases):
results = []
for case in test... | import pytest
from solution import matches_patterns
def test_matches_patterns_all_yes():
filenames = ["file1.txt", "backup.docx", "report2023.pdf"]
patterns = ["*.txt", "f?le?.*"]
assert matches_patterns(filenames, patterns) == ["YES", "YES"]
def test_matches_patterns_some_no():
filenames = ["file1.tx... | [
{
"docstring": null,
"function_declaration": "def matches_patterns(filenames, patterns):",
"function_name": "matches_patterns",
"parameter_list": "(filenames, patterns)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import fnmatch\n\ndef match_patterns(filenames, patterns):\n results = []\n for pattern in patterns:\n matched = any(fnmatch.fnmatch(filename, pattern)... | trial_gpt4o_2 | {
"original_instruction": "Ravi, a computer science student, accidentally deleted some important academic files from his computer and was very worried. However, he remembered that he had sent a backup of the files to his friend via email. The problem is that the backup files were named following a complex pattern, an... | 0.624674 | Apps_17935 | C | [
"matches_patterns",
"solve",
"process_input"
] | 3 | [
[
"process_input",
"solve"
],
[
"solve",
"matches_patterns"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 7992bcd99079109c24667ee1f4325cfaf2bd7b04 | 0a2a7b064fa82506b898994a879df92be4e68e9c | |||
v1.0 | complete | Apps | Apps_18022_C | from typing import List
def is_prime(n: int) -> bool:
""" Checks if a number is a prime number.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(17) == True
>>> is_prime(20) == False
>>> is_prime(1) == False
"""
def filter_primes(numbers: List[i... | def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(number... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(20) == False
assert is_prime(1) == False
def test_filter_primes():
assert filter_primes([10, 11, 1... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers from the input list of integers.",
"function_declaration": "def fil... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ... | trial_gpt4o_9 | {
"original_instruction": "Write a function that takes in a list of integers and returns a new list containing only the integers that are prime numbers. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. \n\n> Note: You may assume the list contains only positive in... | 0.785113 | Apps_18022 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 419aa6a3bac833d982816dfae9d765d06974e327 | 30179b674eebd9894c4a100615b3092c494e23a4 | |||
v1.0 | complete | Apps | Apps_18063_C | def is_prime(num: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(13)
True
>>> is_prime(1)
False
"""
pass
def primes_less_than_n(N: int) -> list:
""" Returns a list of a... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def p... | from solution import primes_less_than_n, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
def test_primes_less_than_n():
assert primes_less_than_n(10) == [2, 3, 5, 7]
asse... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all prime numbers less than N.",
"function_declaration": "def primes_less_than_n(N):"... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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, in... | trial_gpt4o_7 | {
"original_instruction": "=====Problem Statement=====\nYou are given a positive integer N. Write a Python program to generate a list of all prime numbers less than N.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, 2, 3, 5, 7, and 11 are primes.... | 0.845019 | Apps_18063 | C | [
"is_prime",
"primes_less_than_n"
] | 2 | [
[
"primes_less_than_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9d5227a0e0beadb4e8fd2ae6bfe0f606985144ea | e6933ade6c77a026305713e673196910a679185f | |||
v1.0 | complete | Apps | Apps_17972_C | def magical_forest_game(T: int, test_cases: List[List[List[int]]]) -> List[str]:
"""
Chef has started a new game called "Magical Forest". In this game, each player needs to collect magical
orbs scattered in the forest. Each player has a separate bag to store these orbs and the player with
most magica... | def calculate_magical_power(orbs):
unique_orbs = len(set(orbs))
additional_power = 0
if unique_orbs >= 5:
additional_power += 20
unique_orbs -= 5
if unique_orbs >= 4:
additional_power += 10
unique_orbs -= 4
if unique_orbs >= 3:
additional_power += 5
... | import pytest
from solution import magical_forest_game
def test_single_player_multiple_orb_types():
assert magical_forest_game(1, [[[1, 2, 3, 4, 5]]]) == ["chef"]
def test_multiple_players_with_different_powers():
assert magical_forest_game(1, [[[1, 2, 3], [1, 1, 2, 2, 3, 3], [1, 2, 3, 4, 5, 6]]]) == ["3"]
d... | [
{
"docstring": null,
"function_declaration": "def calculate_magical_power(orbs):",
"function_name": "calculate_magical_power",
"parameter_list": "(orbs)"
},
{
"docstring": null,
"function_declaration": "def find_winner(test_cases):",
"function_name": "find_winner",
"parameter_lis... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_magical_power(m, orbs):\n from collections import Counter\n orb_types = list(set(orbs))\n orb_count = len(orb_types)\n\n power = m\n\n ... | trial_gpt4o_9 | {
"original_instruction": "Chef has started a new game called \"Magical Forest\". In this game, each player needs to collect magical orbs scattered in the forest. Each player has a separate bag to store these orbs and the player with the most magical power wins the game. \n\nEach orb has a magical power associated wi... | 0.603681 | Apps_17972 | C | [
"calculate_magical_power",
"find_winner",
"magical_forest_game"
] | 3 | [
[
"find_winner",
"calculate_magical_power"
],
[
"magical_forest_game",
"find_winner"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 68a59ce0c5a7ac94ecc6cbff8566db25ce3b8d57 | 93ebe1c657ef70f6cb07c9a8700f596c39b6359d | |||
v1.0 | complete | Apps | Apps_18214_C | from typing import List
def length_of_lis(nums: List[int]) -> int:
"""
Returns the length of the longest increasing subsequence in the list of integers nums.
>>> length_of_lis([10, 9, 2, 5, 3])
2
>>> length_of_lis([0, 8, 4, 12, 2, 50])
4
>>> length_of_lis([])
0
>>> length_of_l... | def length_of_lis(nums):
"""
Returns the length of the longest increasing subsequence in the list of integers nums.
"""
if not nums:
return 0
dp = []
for num in nums:
idx = binary_search(dp, num)
if idx == len(dp):
dp.append(num)
else:
... | from solution import length_of_lis
def test_example_1():
assert length_of_lis([10, 9, 2, 5, 3]) == 2
def test_example_2():
assert length_of_lis([0, 8, 4, 12, 2, 50]) == 4
def test_empty_list():
assert length_of_lis([]) == 0
def test_single_element():
assert length_of_lis([5]) == 1
def test_all_incr... | [
{
"docstring": "Returns the length of the longest increasing subsequence in the list of integers nums.",
"function_declaration": "def length_of_lis(nums):",
"function_name": "length_of_lis",
"parameter_list": "(nums)"
},
{
"docstring": "Helper function to perform binary search and return the... | [
1,
1,
1,
0,
1,
1,
1,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_lis(n, stones):\n \"\"\"\n Returns the length of the longest increasing subsequence of the given sequence of stone identifiers.\n \n Args:... | trial_gpt4o_8 | {
"original_instruction": "During an archaeological expedition, scientists have discovered an ancient construct consisting of a sequence of stones with each stone numbered with an integer ranging from 1 to n. Each stone has a unique identifier. The identifier of the i-th stone is represented by the integer s_i.\n\nTh... | 0.666366 | Apps_18214 | C | [
"length_of_lis",
"binary_search"
] | 2 | [
[
"length_of_lis",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc91e5d870828af7e1acdfabed0c58df7e09d6ff | e23ac58010f9be1ed7e29a1d2d4ef855e378f996 | |||
v1.0 | complete | Apps | Apps_18218_C | def merge_sort(array):
""" Sorts an array in ascending order using the merge sort algorithm.
>>> merge_sort([4, 2, 6, 5, 1, 3]) == [1, 2, 3, 4, 5, 6]
>>> merge_sort([10, -1, 2, 5, 0, 6, 4, -5]) == [-5, -1, 0, 2, 4, 5, 6, 10]
>>> merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
>>> merge_sort([5, 4, 3,... | def merge_sort(array):
"""
Sorts an array in ascending order using the merge sort algorithm.
"""
if len(array) <= 1:
return array
mid = len(array) // 2
left = merge_sort(array[:mid])
right = merge_sort(array[mid:])
return merge(left, right)
def merge(left, right):
... | from solution import merge_sort
def test_merge_sort():
assert merge_sort([4, 2, 6, 5, 1, 3]) == [1, 2, 3, 4, 5, 6]
assert merge_sort([10, -1, 2, 5, 0, 6, 4, -5]) == [-5, -1, 0, 2, 4, 5, 6, 10]
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
... | [
{
"docstring": "Sorts an array in ascending order using the merge sort algorithm.",
"function_declaration": "def merge_sort(array):",
"function_name": "merge_sort",
"parameter_list": "(array)"
},
{
"docstring": "Merges two sorted arrays into one sorted array.",
"function_declaration": "d... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(array):\n \"\"\"\n Implements merge sort algorithm to sort the input array in ascending order.\n \n :param array: List of integers to be ... | trial_gpt4o_9 | {
"original_instruction": "Given an array of integers, write a function `merge_sort` that implements the merge sort algorithm to sort the array in ascending order. The function should accept one argument, the array, and return the sorted array.\n\nMerge sort is a divide-and-conquer algorithm that works as follows:\n1... | 0.706672 | Apps_18218 | C | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 801f2d96683134ebf1d45cc3e9dd3a7918e742e5 | b78c308bf48a900e460ae729f452604349e2ce5b | |||
v1.0 | complete | Apps | Apps_18500_C | from typing import List
def find_shortest_path(N: int, M: int, A: int, B: int, K: int, edges: List[str]) -> int:
"""
Determine the shortest possible time Alex can take to travel from city A to city B without exceeding the budget for tolls.
Parameters:
N (int): The number of cities.
M (int): T... | import heapq
import sys
from collections import defaultdict
def shortest_path_with_budget(N, M, A, B, K, roads):
graph = defaultdict(list)
for u, v, t, l in roads:
graph[u].append((v, t, l))
graph[v].append((u, t, l))
# Using a tuple (time, current_city, money_spent) for heapq
pq =... | from solution import find_shortest_path
def test_case_1():
N, M, A, B, K = 5, 6, 1, 5, 10
edges = [
"1 2 3 2",
"2 3 4 5",
"2 4 2 1",
"4 5 6 2",
"3 5 3 8",
"1 3 7 10"
]
assert find_shortest_path(N, M, A, B, K, edges) == 11
def test_case_2():
N, M, A, ... | [
{
"docstring": null,
"function_declaration": "def shortest_path_with_budget(N, M, A, B, K, roads):",
"function_name": "shortest_path_with_budget",
"parameter_list": "(N, M, A, B, K, roads)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(N, M, A, B, K, edges):",
... | [
0,
1,
0,
0,
1,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef shortest_path(N, M, A, B, K, roads):\n graph = [[] for _ in range(N + 1)]\n \n for u, v, t, l in roads:\n graph[u].a... | trial_gpt4o_5 | {
"original_instruction": "Alex wants to send a package from city A to city B in the shortest possible time. There are N cities and M roads connecting them. Each road connects two cities and takes a certain amount of time to traverse. Additionally, certain roads are toll roads, which means Alex needs to pay a certain... | 0.729508 | Apps_18500 | C | [
"shortest_path_with_budget",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path_with_budget"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ac83b273dafbc57ef9ffa9f1cf48d5a235b5861 | 9dfb84307ad47efb6f592b030f4182bf3c875d34 | |||
v1.0 | complete | Apps | Apps_18513_C | from typing import List
def largest_allied_group(R: int, C: int, matrix: List[List[int]]) -> int:
""" Given the number of rows R and columns C, and an R x C matrix where each cell contains
a positive integer representing the strength of a particular faction's unit, find the size
of the largest group of con... | from math import gcd
from collections import deque
def get_neighbors(r, c, R, C):
"""
Return valid neighbors (up, down, left, right) for cell (r, c)
"""
neighbors = []
if r - 1 >= 0:
neighbors.append((r - 1, c))
if r + 1 < R:
neighbors.append((r + 1, c))
if c - 1 >= 0:
... | from solution import largest_allied_group
def test_largest_allied_group():
R = 4
C = 4
matrix = [
[2, 3, 4, 5],
[6, 4, 3, 8],
[6, 9, 2, 7],
[1, 8, 9, 2]
]
assert largest_allied_group(R, C, matrix) == 5
def test_largest_allied_group_single_cell():
R = 1
C = 1... | [
{
"docstring": "Return valid neighbors (up, down, left, right) for cell (r, c)",
"function_declaration": "def get_neighbors(r, c, R, C):",
"function_name": "get_neighbors",
"parameter_list": "(r, c, R, C)"
},
{
"docstring": "Return whether two cell values are allied.",
"function_declarat... | [
1,
1,
0,
0,
0,
1,
0,
0,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\nfrom math import gcd\n\ndef find_factors(n):\n \"\"\"\n Returns set of factors of a number n.\n \"\"\"\n if n < 2:\n ... | trial_gpt4o_5 | {
"original_instruction": "In a dystopian future, a large matrix represents a battle grid where various factions are preparing for combat. Each cell in the matrix contains a positive integer representing the strength of a particular faction's unit. Two factions are allies if they have a common divisor greater than 1.... | 0.572652 | Apps_18513 | C | [
"get_neighbors",
"are_allies",
"bfs",
"largest_allied_group"
] | 4 | [
[
"bfs",
"are_allies"
],
[
"bfs",
"get_neighbors"
],
[
"largest_allied_group",
"bfs"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ce3696290ced2483ccd98890cc7b6a05893a7577 | 85f88f197912f583550317afab40b229ebad4686 | |||
v1.0 | complete | Apps | Apps_18815_C | from functools import cmp_to_key
from typing import List
def largest_number(nums: List[int]) -> str:
"""
Given an integer array nums, return the largest number you can form by concatenating its elements. The result should be in string format.
>>> largest_number([10, 2])
'210'
>>> largest_numbe... | 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 elements of nums.
"""
# Convert numbers to st... | from solution import largest_number
def test_example_1():
assert largest_number([10, 2]) == "210"
def test_example_2():
assert largest_number([3, 30, 34, 5, 9]) == "9534330"
def test_single_element():
assert largest_number([1]) == "1"
assert largest_number([10]) == "10"
def test_repeated_elements():... | [
{
"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 elements of nums.",
"function_declaration": "def largest_number(nums):",
"fu... | [
0,
1,
0,
0,
0,
0,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largestNumber(nums):\n \"\"\"\n Returns the largest number that can be formed by concatenating the elements of the arr... | trial_gpt4o_6 | {
"original_instruction": "Given an integer array nums, return the largest number you can form by concatenating its elements. The result should be in string format. \n\nExample 1:\n\nInput: [10, 2]\nOutput: \"210\"\nExplanation: Concatenating all the numbers in the array in different orders will yield: \"102\", \"210... | 0.739358 | Apps_18815 | C | [
"compare",
"largest_number"
] | 2 | [
[
"largest_number",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 898e51450373270cf6ad07ec2b6ee42282af55ef | 700e09c201a20c08dd468a5b4097a4afdeb39345 | |||
v1.0 | complete | Apps | Apps_18751_C | from typing import List
def find_prime_numbers(n: int, numbers: List[int]) -> List[int]:
"""
Given a list of positive integers, return a list of the integers that are prime numbers.
A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.
A... | from typing import List
def is_prime(num: int) -> bool:
"""
Returns True if num is a prime number, otherwise False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0... | from solution import find_prime_numbers
def test_find_prime_numbers_with_example_data():
assert find_prime_numbers(5, [2, 4, 6, 5, 7]) == [2, 5, 7]
assert find_prime_numbers(3, [4, 6, 8]) == []
def test_find_prime_numbers_all_primes():
assert find_prime_numbers(4, [2, 3, 5, 7]) == [2, 3, 5, 7]
def test_f... | [
{
"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 prime numbers from the given list of numbers.",
"function_declaration": "def... | [
0,
0,
0,
1,
1,
1,
0,
1,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(number: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if number <= 1:\n ... | trial_gpt4o_9 | {
"original_instruction": "Given a list of positive integers, write a function that returns a list of the integers that are prime numbers. \n\nA prime number is defined as a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.\n\n### Input\n- An integer `n` (1 <= n <= 10000),... | 0.761348 | Apps_18751 | C | [
"is_prime",
"find_prime_numbers"
] | 2 | [
[
"find_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cdd92a3db4f07524a42339f14a39f641c8e48cdf | 9d4e11c3a69434336708d8236d00af6613fe855b | |||
v1.0 | complete | Apps | Apps_18621_C | def minRequiredMaxTime(tasks: List[int], T: int) -> int:
"""
Determine the minimum value of maxTime such that all tasks can be completed within the T time slots.
>>> minRequiredMaxTime([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)
15
>>> minRequiredMaxTime([3, 2, 2, 4, 1, 4], 3)
6
>>> minRequired... | def canComplete(tasks, T, maxTime):
current_slot_time = 0
slots_used = 1
for task in tasks:
if current_slot_time + task <= maxTime:
current_slot_time += task
else:
slots_used += 1
current_slot_time = task
if slots_used > T:
... | from solution import minRequiredMaxTime
def test_example1():
tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
T = 5
assert minRequiredMaxTime(tasks, T) == 15
def test_example2():
tasks = [3, 2, 2, 4, 1, 4]
T = 3
assert minRequiredMaxTime(tasks, T) == 6
def test_example3():
tasks = [1, 2, 3, 1, 1]
... | [
{
"docstring": null,
"function_declaration": "def canComplete(tasks, T, maxTime):",
"function_name": "canComplete",
"parameter_list": "(tasks, T, maxTime)"
},
{
"docstring": null,
"function_declaration": "def minRequiredMaxTime(tasks, T):",
"function_name": "minRequiredMaxTime",
... | [
1,
1,
1,
0,
1,
1,
1,
0,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_complete(tasks, T, maxTime):\n time_slots = 1\n current_time_in_slot = 0\n \n for task in tasks:\n if current_time_in_slot + task <= maxT... | trial_gpt4o_9 | {
"original_instruction": "You are given a list of integers `tasks` where each integer represents the amount of time a task takes to complete, and an integer `T` which represents the total number of time slots available. Each time slot can accommodate one or more tasks, but the total duration of tasks assigned to any... | 0.628732 | Apps_18621 | C | [
"canComplete",
"minRequiredMaxTime"
] | 2 | [
[
"minRequiredMaxTime",
"canComplete"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d596550458e213d34a23bfb1ca0e2c689cd21ab9 | dfd202b56ebec4c56d842598b8f4e530f77c8200 | |||
v1.0 | complete | Apps | Apps_18820_C | def max_adjacent_pairs(animals: List[int]) -> int:
""" Determine the maximum possible number of pairs of adjacent animals that can be of the same species after performing at most one swap operation.
>>> max_adjacent_pairs([1, 2, 3, 3, 2, 1]) 3
>>> max_adjacent_pairs([1, 1, 1, 1]) 3
>>> max_adjacent_pair... | from typing import List
def count_adjacent_pairs(animals: List[int]) -> int:
count = 0
for i in range(1, len(animals)):
if animals[i] == animals[i - 1]:
count += 1
return count
def max_adjacent_pairs(animals: List[int]) -> int:
n = len(animals)
if n < 2:
return 0
... | from solution import max_adjacent_pairs
def test_example_1():
assert max_adjacent_pairs([1, 2, 3, 3, 2, 1]) == 3
def test_all_same_species():
assert max_adjacent_pairs([1, 1, 1, 1]) == 3
def test_no_pair_possible():
assert max_adjacent_pairs([1, 2, 3, 4]) == 0
def test_two_elements():
assert max_adj... | [
{
"docstring": null,
"function_declaration": "def count_adjacent_pairs(animals):",
"function_name": "count_adjacent_pairs",
"parameter_list": "(animals)"
},
{
"docstring": null,
"function_declaration": "def max_adjacent_pairs(animals):",
"function_name": "max_adjacent_pairs",
"pa... | [
1,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_adjacent_pairs(animals):\n \"\"\"\n Returns the maximum number of pairs of adjacent animals that can be of the same species after \n performing at ... | trial_gpt4o_2 | {
"original_instruction": "In a zoo, there are `n` cages arranged in a line, each containing a different species of animal. You have been tasked with determining the maximum possible number of pairs of adjacent animals that can be of the same species after performing the following operation: \n\n- You can swap any tw... | 0.577255 | Apps_18820 | C | [
"count_adjacent_pairs",
"max_adjacent_pairs"
] | 2 | [
[
"max_adjacent_pairs",
"count_adjacent_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36157e9d56e7fb313101af011aedefabd05827f0 | 7abea06e5e91f6c60a8125ac89d03ff0c6af6b11 | |||
v1.0 | complete | Apps | Apps_18857_C | [Completion Task in Python]
from typing import List
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime
"""
pass
def divisors(n: int) -> List[int]:
"""
Returns a list of all prime divisors of the given number n.
>>> divisors(28) -> [2, 7]
>>> divisors(30... | def is_prime(num):
"""
Helper function to check if a number is prime
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def di... | from solution import divisors
def test_divisors_case1():
assert divisors(28) == [2, 7]
def test_divisors_case2():
assert divisors(30) == [2, 3, 5]
def test_divisors_case3():
assert divisors(17) == [17]
def test_divisors_case4():
assert divisors(1) == []
def test_divisors_case5():
assert divisor... | [
{
"docstring": "Helper function to check if a number is prime",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime divisors of the given number n.",
"function_declaration": "def divisors(n):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n ret... | trial_gpt4o_7 | {
"original_instruction": "## Task\nWrite a function that takes a positive integer `n` and returns a list of all its divisors that are also prime numbers. The list should be sorted in ascending order.\n\n## Example\n```python\ndivisors(28) -> [2, 7]\ndivisors(30) -> [2, 3, 5]\ndivisors(17) -> [17]\ndivisors(1) -> []\... | 0.722053 | Apps_18857 | C | [
"is_prime",
"divisors"
] | 2 | [
[
"divisors",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f4596d75635a7ad1f0e818066b31374df18ccded | de94dfe678cc8e973c593053800c2db5dcaf1c78 | |||
v1.0 | complete | Apps | Apps_18769_C | from typing import List, Tuple
def dijkstra(graph: dict, start: int) -> dict:
"""
Returns the shortest distance from start to all other nodes using Dijkstra's algorithm.
"""
pass
def shortest_travel_time(m: int, n: int, roads: List[Tuple[int, int, int]], K: int, special_landmarks: List[int]) -> int:
... | import heapq
from itertools import permutations
def dijkstra(graph, start):
"""
Returns the shortest distance from start to all other nodes using Dijkstra's algorithm.
"""
min_heap = [(0, start)] # (distance, vertex)
distances = {node: float('inf') for node in graph}
distances[start] = 0
w... | def test_shortest_travel_time():
m, n = 5, 7
roads = [
(1, 2, 3),
(1, 3, 1),
(1, 4, 6),
(2, 3, 1),
(2, 5, 2),
(3, 5, 5),
(4, 5, 2),
]
K = 3
special_landmarks = [1, 3, 5]
assert shortest_travel_time(m, n, roads, K, special_landmarks) == 8
d... | [
{
"docstring": "Returns the shortest distance from start to all other nodes using Dijkstra's algorithm.",
"function_declaration": "def dijkstra(graph, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_t... | [
0,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom itertools import permutations\n\ndef shortest_travel_time(m, n, roads, K, special_landmarks):\n # Build graph (Adjacency list) wit... | trial_gpt4o_3 | {
"original_instruction": "In a city, there are m landmarks and n roads connecting them. Each landmark has a unique positive integer ID. The roads are bidirectional and each has a specific travel time associated with it. You are given the IDs of K landmarks that are considered special. A special landmark is defined a... | 0.718406 | Apps_18769 | C | [
"dijkstra",
"shortest_travel_time"
] | 2 | [
[
"shortest_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e09503fe7bbca667c9b8bc17771102ff99760c19 | 89167d6abe33512c692bf3f3999508b6dd4943e3 | |||
v1.0 | complete | Apps | Apps_18709_C | def min_fuel_needed(grid, N, M):
"""
Returns the minimum fuel needed to reach the bottom-right corner of the grid.
If it's impossible, returns -1.
"""
# Implementation goes here
pass
def driving_simulation(N, M, F, grid):
""" Calculate the minimum fuel needed for Mark to complete his journe... | def min_fuel_needed(grid, N, M):
"""
Returns the minimum fuel needed to reach the bottom-right corner of the grid.
If it's impossible, returns -1.
"""
dp = [[float('inf')] * M for _ in range(N)]
dp[0][0] = grid[0][0]
for i in range(N):
for j in range(M):
if i > 0:
... | def test_min_fuel_needed():
grid = [
[3, 4, 1],
[2, 8, 3],
[6, 2, 1]
]
assert min_fuel_needed(grid, 3, 3) == 12
def test_driving_simulation_possible():
grid = [
[3, 4, 1],
[2, 8, 3],
[6, 2, 1]
]
assert driving_simulation(3, 3, 15, grid) == 12
def... | [
{
"docstring": "Returns the minimum fuel needed to reach the bottom-right corner of the grid.\nIf it's impossible, returns -1.",
"function_declaration": "def min_fuel_needed(grid, N, M):",
"function_name": "min_fuel_needed",
"parameter_list": "(grid, N, M)"
},
{
"docstring": null,
"funct... | [
0,
0,
0,
1,
0,
0,
1,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_fuel_cost_to_reach_destination(N, M, F, grid):\n \"\"\"\n Finds the minimum fuel cost to reach the bottom-right corner of the grid.\n If the minimu... | trial_gpt4o_7 | {
"original_instruction": "Mark is participating in a driving simulation challenge where he has to drive through a grid of size NxM. Each cell in this grid contains a certain fuel cost. He starts at the top-left corner of the grid and must reach the bottom-right corner. However, he's only allowed to move right or dow... | 0.614084 | Apps_18709 | C | [
"min_fuel_needed",
"driving_simulation"
] | 2 | [
[
"driving_simulation",
"min_fuel_needed"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 79d79bd31f7a7214e0aca22c77b99e154d1b8631 | 465a17f9b765744c032606ccee75a0f87852e423 | |||
v1.0 | complete | Apps | Apps_18843_C | from typing import List
def generate_ip_addresses(s: str) -> List[str]:
""" Generate all possible valid IP addresses from a given string of digits.
A valid IP address consists of exactly four integers (each ranging from 0 to 255) separated by periods. The integers cannot have leading zeros.
>>> generate_i... | from typing import List
def is_valid(segment: str) -> bool:
"""
Check if the given string segment is a valid IP address segment.
"""
if len(segment) == 0 or len(segment) > 3:
return False
if segment[0] == '0' and len(segment) > 1:
return False
if int(segment) > 255:
retu... | from solution import generate_ip_addresses
def test_generate_ip_addresses_example_1():
assert generate_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"]
def test_generate_ip_addresses_example_2():
assert generate_ip_addresses("0000") == ["0.0.0.0"]
def test_generate_ip_addresses_example_3()... | [
{
"docstring": "Check if the given string segment is a valid IP address segment.",
"function_declaration": "def is_valid(segment):",
"function_name": "is_valid",
"parameter_list": "(segment)"
},
{
"docstring": "Generate all possible valid IP addresses from a given string.",
"function_dec... | [
1,
1,
0,
0,
0,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef generate_ip_addresses(s: str) -> List[str]:\n def is_valid(segment):\n return int(segment) <= 255 if segment[0] != '0' else... | trial_gpt4o_7 | {
"original_instruction": "Write a function to generate all possible valid IP addresses from a given string of digits. A valid IP address consists of exactly four integers (each ranging from 0 to 255) separated by periods. The integers cannot have leading zeros. For example, \"25525511135\" can be interpreted as the ... | 0.617751 | Apps_18843 | C | [
"is_valid",
"generate_ip_addresses"
] | 2 | [
[
"generate_ip_addresses",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ad74107c34920d2f6b11b34a3811778a18b94f4b | 08724856463b820f02d34196608efb9de4894a7b | |||
v1.0 | complete | Apps | Apps_18942_C | def validate_timestamps(timestamps: List[str]) -> List[str]:
""" Given a list of timestamps, validate each one and return the results.
Validation rules:
- Each timestamp must be exactly 19 characters long.
- It must follow the format: YYYY-MM-DD HH:MM:SS
- Year (YYYY) must be a 4-digit number that i... | import datetime
def is_leap_year(year):
"""
Returns True if the given year is a leap year, otherwise False.
"""
return (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0)
def validate_timestamp(timestamp):
"""
Validates the format and values of the given timestamp.
"""
if len(time... | from solution import validate_timestamps
def test_valid_timestamps():
timestamps = [
"2020-02-29 12:45:59", # Valid leap year and date
"2016-12-31 23:59:59", # Valid date and time
"2000-02-29 00:00:00" # Valid leap year
]
results = validate_timestamps(timestamps)
assert resu... | [
{
"docstring": "Returns True if the given year is a leap year, otherwise False.",
"function_declaration": "def is_leap_year(year):",
"function_name": "is_leap_year",
"parameter_list": "(year)"
},
{
"docstring": "Validates the format and values of the given timestamp.",
"function_declarat... | [
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom datetime import datetime\n\ndef is_leap_year(year):\n return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n\ndef validate_timestamp(t... | trial_gpt4o_9 | {
"original_instruction": "=====Problem Statement=====\nXYZ University is conducting an online examination for its students. As part of the test system, the university needs to validate the submission timestamps of the test answers.\n\nEach submission timestamp must follow the rules below:\n\nIt should be exactly 19 ... | 0.660398 | Apps_18942 | C | [
"is_leap_year",
"validate_timestamp",
"validate_timestamps"
] | 3 | [
[
"validate_timestamp",
"is_leap_year"
],
[
"validate_timestamps",
"validate_timestamp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fd52bdfd5ef442d0ad4462db41d11200bd7f9ebe | b8f954f832a834875bdb28f83c8f2cbcbed5c947 | |||
v1.0 | complete | Apps | Apps_18658_C | def is_prime(n: int) -> bool:
""" Check if a number is prime. """
pass
def find_twin_primes(numbers: List[int]) -> List[Tuple[int, int]]:
""" Find and return all pairs of twin primes in the given list of numbers.
>>> find_twin_primes([3, 5, 7, 11, 13, 17, 19, 23, 29, 31])
[(3, 5), (5, 7), (11, 13),... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def find_twin_primes(numbers):
... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
assert is_prime(19) == True
def test_find_twin_primes():
assert fin... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find and return all pairs of twin primes in the given list of numbers.",
"function_declaration": "def find_twin_primes(numbers... | [
1,
0,
0,
0,
1,
0,
1,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i... | trial_gpt4o_9 | {
"original_instruction": "Riya loves prime numbers and she is fascinated by their properties. Her latest interest is in twin primes. Twin primes are pairs of prime numbers that have a gap of two between them (for example, (3, 5), (11, 13), etc.). She comes up with a task where you are given a list of numbers and nee... | 0.675592 | Apps_18658 | C | [
"is_prime",
"find_twin_primes",
"process_twin_primes_output"
] | 3 | [
[
"find_twin_primes",
"is_prime"
],
[
"process_twin_primes_output",
"find_twin_primes"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 3fc663aeba59b1eb6128564c48b0fc0f2fe8620b | 0d5fa93623c1b06d9b3cca6566a95ee515a5caab | |||
v1.0 | complete | Apps | Apps_19077_C | def solve(T: int, test_cases: List[Tuple[int, int, List[int]]]) -> List[int]:
""" Determine the number of notifications for potential fraudulent activities for multiple test cases.
Args:
T : int : number of test cases
test_cases : List[Tuple[int, int, List[int]]] : list containing tuples of test ca... | from bisect import insort, bisect_left
def median(data, d):
k = d // 2
if d % 2 == 0:
return (data[k-1] + data[k]) / 2
else:
return data[k]
def count_notifications(exp, d):
cnt = 0
trailing = sorted(exp[:d])
for i in range(d, len(exp)):
med = median(trailing, d... | from solution import solve
def test_single_case():
T = 1
test_cases = [
(9, 5, [2, 3, 4, 2, 3, 6, 8, 4, 5])
]
assert solve(T, test_cases) == [2]
def test_multiple_cases():
T = 2
test_cases = [
(9, 5, [2, 3, 4, 2, 3, 6, 8, 4, 5]),
(5, 2, [1, 2, 3, 4, 5])
]
assert... | [
{
"docstring": null,
"function_declaration": "def median(data, d):",
"function_name": "median",
"parameter_list": "(data, d)"
},
{
"docstring": null,
"function_declaration": "def count_notifications(exp, d):",
"function_name": "count_notifications",
"parameter_list": "(exp, d)"
... | [
0,
1,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from bisect import insort, bisect_left\n\ndef find_median(trailing, d):\n if d % 2 == 1:\n return trailing[d // 2]\n else:\n return (trailing[d ... | trial_gpt4o_7 | {
"original_instruction": "A fraudulent activity detection system is being created to detect anomalies in a sequence of transactions. Given an array of integers representing the daily expenditures for a client, the system needs to find out how many notifications were sent for a potential fraudulent activity. A notifi... | 0.552943 | Apps_19077 | C | [
"median",
"count_notifications",
"solve"
] | 3 | [
[
"count_notifications",
"median"
],
[
"solve",
"count_notifications"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6a3d185ba1a00a310caf0a9261ac2d24b72516c8 | fe5ca5a5b65e1cc0d87419d738e3820af6fd854b | |||
v1.0 | complete | Apps | Apps_19018_C | from typing import List, Tuple
def partition_and_find_min_max_sum(T: int, test_cases: List[Tuple[Tuple[int, int], List[int]]]) -> List[int]:
""" Partition the array into k contiguous subarrays such that the maximum sum of any subarray is minimized.
>>> T = 2
>>> test_cases = [((7, 3), [7, 2, 5, 10, 8]), ((... | def can_partition(nums, max_sum, k):
subarray_sum, subarray_count = 0, 1
for num in nums:
if subarray_sum + num > max_sum:
subarray_sum = num
subarray_count += 1
if subarray_count > k:
return False
else:
subarray_sum += num
retu... | from solution import partition_and_find_min_max_sum
def test_single_case():
T = 1
test_cases = [
[(7, 3), [7, 2, 5, 10, 8]],
]
assert partition_and_find_min_max_sum(T, test_cases) == [14]
def test_multiple_cases():
T = 2
test_cases = [
[(7, 3), [7, 2, 5, 10, 8]],
[(5, 2... | [
{
"docstring": null,
"function_declaration": "def can_partition(nums, max_sum, k):",
"function_name": "can_partition",
"parameter_list": "(nums, max_sum, k)"
},
{
"docstring": null,
"function_declaration": "def min_max_subarray_sum(nums, k):",
"function_name": "min_max_subarray_sum",... | [
0,
1,
1,
0,
0,
0,
0,
1,
1,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimize_max_sum(A, k):\n def can_partition(max_sum):\n current_sum = 0\n required_subarrays = 1\n for num in A:\n if current... | trial_gpt4o_8 | {
"original_instruction": "A well-known problem in competitive programming is to partition an array into `k` contiguous subarrays such that the max sum of the subarrays is minimized.\n\nLet's define a problem around this concept.\n\nYou are given an array `A` of `N` integers. You are also given an integer `k`. Your t... | 0.661906 | Apps_19018 | C | [
"can_partition",
"min_max_subarray_sum",
"partition_and_find_min_max_sum"
] | 3 | [
[
"min_max_subarray_sum",
"can_partition"
],
[
"partition_and_find_min_max_sum",
"min_max_subarray_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7237199e150f00269913e4f486ea225e55bdf146 | 6fed2d4017e013c1195c91bf05a17efc99d2919c | |||
v1.0 | complete | Apps | Apps_19334_C | def can_be_balanced(weights):
"""
Determines if a collection of weights can be split into two groups with equal sum.
"""
# Implementation here
def process_test_cases(test_cases):
"""
Processes multiple test cases to determine if each set of weights can be balanced.
"""
results = []
... | def can_be_balanced(weights):
"""
Determines if a collection of weights can be split into two groups with equal sum.
"""
total_sum = sum(weights)
# If total sum is odd, it can't be split into two equal parts
if total_sum % 2 != 0:
return False
target = total_sum // 2
n = len(wei... | from solution import perfect_balance
def test_case_1():
input_data = "2\n4\n1 5 11 5\n3\n1 2 5"
assert perfect_balance(input_data) == ["YES", "NO"]
def test_case_2():
input_data = "1\n5\n3 1 4 2 2"
assert perfect_balance(input_data) == ["YES"]
def test_case_3():
input_data = "1\n3\n1 2 4"
ass... | [
{
"docstring": "Determines if a collection of weights can be split into two groups with equal sum.",
"function_declaration": "def can_be_balanced(weights):",
"function_name": "can_be_balanced",
"parameter_list": "(weights)"
},
{
"docstring": null,
"function_declaration": "def process_tes... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_be_perfectly_balanced(weights):\n total_sum = sum(weights)\n # If the total sum is odd, it can't be perfectly balanced\n if total_sum % 2 != 0:\n ... | trial_gpt4o_9 | {
"original_instruction": "-----\nPERFECT BALANCE\n-----\n\nAnna loves collecting weights. She has a collection of weights and she's always interested in balancing them perfectly on a scale. A weight collection is balanced if the sum of weights on the left side of the scale is equal to the sum on the right. Anna can ... | 0.557367 | Apps_19334 | C | [
"can_be_balanced",
"process_test_cases",
"perfect_balance"
] | 3 | [
[
"perfect_balance",
"process_test_cases"
],
[
"process_test_cases",
"can_be_balanced"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 2d65158b616e88fec732dd40b56ddea9a54a4b30 | 99268c281fbab25b48cb16ab1f9d4837707b2434 | |||
v1.0 | complete | Apps | Apps_19208_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def add_two_numbers(l1, l2):
""" Add two numbers represented by linked lists in reverse order and return the result as a linked list.
>>> l1 = list_to_linkedlist([2, 4, 3])
>>> l2 = list_to_linkedlist(... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def add_two_numbers(l1, l2):
dummy = ListNode()
current = dummy
carry = 0
while l1 or l2 or carry:
val1 = l1.val if l1 else 0
val2 = l2.val if l2 else 0
carry, out = di... | from solution import add_two_numbers, list_to_linkedlist, linkedlist_to_list, sum_linkedlists_linkedlist_format
def test_add_two_numbers():
l1 = list_to_linkedlist([2, 4, 3])
l2 = list_to_linkedlist([5, 6, 4])
result = add_two_numbers(l1, l2)
assert linkedlist_to_list(result) == [7, 0, 8]
l1 = lis... | [] | [
1,
0,
1,
1,
1,
1,
1,
0,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, x):\n self.val = x\n self.next = None\n\ndef addTwoNumbers(l1, l2):\n \"\"\"\n Returns the sum of two li... | trial_gpt4o_8 | {
"original_instruction": "You are given two linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. Each number does not contain any leading zero, except the number 0 itself.... | 0.567658 | Apps_19208 | C | [
"add_two_numbers",
"list_to_linkedlist",
"linkedlist_to_list",
"sum_linkedlists_linkedlist_format"
] | 4 | [
[
"sum_linkedlists_linkedlist_format",
"add_two_numbers"
],
[
"sum_linkedlists_linkedlist_format",
"linkedlist_to_list"
],
[
"sum_linkedlists_linkedlist_format",
"list_to_linkedlist"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 5f835752d68b8e73faf3b12c78b9c8f5ee48d9d3 | 962e7ec40e274146d58594d83d18cc0f6a1a5875 | |||
v1.0 | complete | Apps | Apps_19500_C | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
max_divisor = int(num ** 0.5) + 1
for divisor in range(3, max_divisor, 2):
if num % divisor == 0:
return False
return True
def prime_positions_are_prim... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
max_divisor = int(num ** 0.5) + 1
for divisor in range(3, max_divisor, 2):
if num % divisor == 0:
return False
return True
def prime_positions_are_prim... | from solution import main
def test_example():
input_str = "1\n6\n2 3 5 7 11 13\n"
assert main(input_str) == "YES"
def test_no_prime_positions_are_prime():
input_str = "1\n6\n4 6 8 12 18 22\n"
assert main(input_str) == "NO"
def test_some_prime_positions_are_not_prime():
input_str = "1\n6\n2 3 4 7 ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_positions_are_primes(arr):",
"function_name": "prime_positions_are_primes",
"parameter_list": "(arr... | [
0,
0,
0,
1,
0,
1,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <=... | trial_gpt4o_3 | {
"original_instruction": "-----\nPRIME POSITION\n-----\n\nChef is intrigued by prime numbers and their positions. He considers a number to be interesting if it lies in a position which is a prime number and the number itself is also a prime number in a given array. \n\nYou are given an array, and your task is to fin... | 0.806292 | Apps_19500 | C | [
"is_prime",
"prime_positions_are_primes",
"process_test_cases",
"main"
] | 4 | [
[
"prime_positions_are_primes",
"is_prime"
],
[
"process_test_cases",
"prime_positions_are_primes"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | a9746e1913bd4b2db04bb008760a4c7c540d3ac2 | 806e390814e92d17754c2ec0896886609f94e270 | |||
v1.0 | complete | Apps | Apps_19438_C | from typing import List
def is_prime(num: int) -> bool:
"""
Check if a number is a prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(11) True
"""
def is_palindrome(num: int) -> bool:
"""
Check if a number is a palindrome.... | def is_prime(num):
"""
Check if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import is_prime, is_palindrome, smallest_palindromic_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
def test_is_palindrome():
assert is_palindrome(121) == True
... | [
{
"docstring": "Check if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindr... | [
0,
0,
0,
0,
1,
0,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num < 2:\n return False\n if num == 2 or num == 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return F... | trial_gpt4o_8 | {
"original_instruction": "## Overview\nPalindromes are numbers or phrases that read the same backward as forward (ignoring spaces, punctuation, and capitalization). This task focuses on palindromic numbers. \n\n## Palindromic Primes\nA palindromic prime is a prime number that is also a palindrome. For example, 131 i... | 0.747061 | Apps_19438 | C | [
"is_prime",
"is_palindrome",
"smallest_palindromic_prime"
] | 3 | [
[
"smallest_palindromic_prime",
"is_palindrome"
],
[
"smallest_palindromic_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2820637546a00c7f0a0721fc84b8997070bbb308 | 161e8adea0b6ede7ce497fcd3d4cef051196d4cf | |||
v1.0 | complete | Apps | Apps_19393_C | from typing import List, Tuple
def can_form_straight_flush(deck: List[Tuple[int, str]]) -> str:
""" Checks if any subset of 5 cards in the given deck can form a straight flush.
>>> can_form_straight_flush([(3, "Hearts"), (4, "Hearts"), (5, "Hearts"), (6, "Hearts"), (7, "Hearts"), (9, "Diamonds"), (12, "Sp... | from collections import defaultdict
from typing import List, Tuple
def can_form_straight_flush(deck: List[Tuple[int, str]]) -> str:
# Organize cards by suit
suits = defaultdict(list)
for value, suit in deck:
suits[suit].append(value)
# Check each suit for possible straight flush
for ca... | from solution import can_form_straight_flush
def test_can_form_straight_flush_found():
deck = [(3, "Hearts"), (4, "Hearts"), (5, "Hearts"), (6, "Hearts"), (7, "Hearts"), (9, "Diamonds"), (12, "Spades")]
assert can_form_straight_flush(deck) == "Straight Flush Found!"
def test_can_form_straight_flush_not_found(... | [
{
"docstring": null,
"function_declaration": "def can_form_straight_flush(deck):",
"function_name": "can_form_straight_flush",
"parameter_list": "(deck)"
},
{
"docstring": null,
"function_declaration": "def has_straight(cards):",
"function_name": "has_straight",
"parameter_list":... | [
0,
0,
1,
0,
0,
1,
1,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom collections import defaultdict\n\ndef can_form_straight_flush(deck):\n def is_straight(cards):\n sorted_cards = s... | trial_gpt4o_9 | {
"original_instruction": "In a card game, each card has a numerical value from 1 to 13 and belongs to one of four suits: Spades, Hearts, Diamonds, Clubs. You are given a deck of cards as a list of tuples where each tuple represents a card with a value and a suit.\n\nFor example:\n```python\ndeck = [(3, \"Hearts\"), ... | 0.59886 | Apps_19393 | C | [
"can_form_straight_flush",
"has_straight"
] | 2 | [
[
"can_form_straight_flush",
"has_straight"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d361be2fd90bd2e70302132fb45a11bf34aa7569 | fcba4126ee5ae1dcb75f4f9ec3fd501a7e148e94 | |||
v1.0 | complete | Apps | Apps_19800_C | def filter_three_divisors(nums: List[int]) -> List[int]:
"""
Returns a list of numbers from the input list that have exactly three divisors.
>>> filter_three_divisors([2, 3, 4, 7, 9, 10, 16, 25, 36]) == [4, 9, 25]
>>> filter_three_divisors([1, 5, 8, 11, 12, 13]) == []
"""
from solution import... | def has_exactly_three_divisors(n):
"""
Helper function to check if a number has exactly three divisors.
"""
if n < 2:
return False
root = int(n**0.5)
return root * root == n and all(n % i != 0 for i in range(2, root))
def filter_three_divisors(nums):
"""
Returns a list of number... | from solution import filter_three_divisors
def test_has_three_divisors():
assert filter_three_divisors([2, 3, 4, 7, 9, 10, 16, 25, 36]) == [4, 9, 25]
assert filter_three_divisors([1, 5, 8, 11, 12, 13]) == []
assert filter_three_divisors([4, 9, 25, 49]) == [4, 9, 25, 49]
assert filter_three_divisors([3,... | [
{
"docstring": "Helper function to check if a number has exactly three divisors.",
"function_declaration": "def has_exactly_three_divisors(n):",
"function_name": "has_exactly_three_divisors",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of numbers from the input list that have e... | [
1,
1,
1,
0,
1,
0,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef has_exactly_three_divisors(n):\n \"\"\"\n Helper function to check if n has exactly three divisors.\n Returns True if n has exactly thre... | trial_gpt4o_9 | {
"original_instruction": "# Task\n\nWrite a function that takes a list of integers and returns a new list containing only the numbers that have exactly three divisors (1, the number itself, and one other divisor).\n\n# Notes\n\n* The input list contains integers greater than 1.\n* The list should maintain the origin... | 0.659429 | Apps_19800 | C | [
"has_exactly_three_divisors",
"filter_three_divisors"
] | 2 | [
[
"filter_three_divisors",
"has_exactly_three_divisors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2968ccc0a857d5e774d6112fd357c698a9fe6aec | 4811f16ca3b7438c7d2ffe0760a275c214cc005a | |||
v1.0 | complete | Apps | Apps_19940_C | def vending_machine_subset_sum(input_str):
""" Determines whether there is a subset of the weights that sum to exactly W.
The input is given in the following format:
N W
w1 w2 ... wN
Example:
>>> vending_machine_subset_sum("5 9\n3 34 4 12 5")
"YES"
>>> vending_machine_subset_sum("5 30\n... | def can_sum_to_weight(N, W, weights):
"""
Determines whether there is a subset of the weights that sum to exactly W.
"""
dp = [False] * (W + 1)
dp[0] = True
for weight in weights:
for j in range(W, weight - 1, -1):
if dp[j - weight]:
dp[j] = True
return ... | from solution import vending_machine_subset_sum
def test_case_1():
input_data = "5 9\n3 34 4 12 5"
assert vending_machine_subset_sum(input_data) == "YES"
def test_case_2():
input_data = "5 30\n3 34 4 12 5"
assert vending_machine_subset_sum(input_data) == "NO"
def test_case_3():
input_data = "1 10... | [
{
"docstring": "Determines whether there is a subset of the weights that sum to exactly W.",
"function_declaration": "def can_sum_to_weight(N, W, weights):",
"function_name": "can_sum_to_weight",
"parameter_list": "(N, W, weights)"
},
{
"docstring": null,
"function_declaration": "def ven... | [
1,
0,
1,
0,
0,
0,
0,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_required_weight(N, W, weights):\n # Initialize a DP table where dp[i] will be True if a subset with sum i can be formed from the given weights.\n ... | trial_gpt4o_8 | {
"original_instruction": "In a small town, there is a unique vending machine that dispenses items based on a specific pattern. The vending machine is filled with N items, each having a certain weight. You need to determine whether it's possible to select a subset of these items such that their combined weight is exa... | 0.556637 | Apps_19940 | C | [
"can_sum_to_weight",
"vending_machine_subset_sum"
] | 2 | [
[
"vending_machine_subset_sum",
"can_sum_to_weight"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aefdd5a2df5b6c953e1c32cecd9c42f4181f08f7 | 4b72b80d1984f34503762a778beb107d00c9c5fc | |||
v1.0 | complete | Apps | Apps_19644_C | def is_valid_password(password):
"""
Returns "VALID" if the password meets the given criteria, otherwise "INVALID".
The criteria for a valid password are:
- It must contain at least one uppercase letter (A to Z).
- It must contain at least one lowercase letter (a to z).
- It must contain at leas... | def is_valid_password(password):
"""
Returns "VALID" if the password meets the given criteria, otherwise "INVALID".
"""
if len(password) < 8:
return "INVALID"
has_upper = False
has_lower = False
has_digit = False
has_special = False
special_characters = {'$', '!', '#', '%', ... | import pytest
from solution import is_valid_password, validate_passwords
def test_is_valid_password():
assert is_valid_password("StrongPass1!") == "VALID"
assert is_valid_password("weakpass") == "INVALID"
assert is_valid_password("12345678!") == "INVALID"
assert is_valid_password("Valid_One1") == "VALI... | [
{
"docstring": "Returns \"VALID\" if the password meets the given criteria, otherwise \"INVALID\".",
"function_declaration": "def is_valid_password(password):",
"function_name": "is_valid_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def valid... | [
0,
1,
1,
1,
0,
0,
1,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_password(password):\n \"\"\"\n Check if a password is valid based on the given criteria.\n \"\"\"\n if len(password) < 8:\n return '... | trial_gpt4o_8 | {
"original_instruction": "A tech company has a new method for password validation. A password is considered valid if it satisfies the following conditions:\n\n- It must contain at least one uppercase letter (A to Z).\n- It must contain at least one lowercase letter (a to z).\n- It must contain at least one digit (0 ... | 0.586564 | Apps_19644 | C | [
"is_valid_password",
"validate_passwords"
] | 2 | [
[
"validate_passwords",
"is_valid_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1a656699ac1d1da4506586f399948c533138c3f1 | c75b9fc4baa24da02e00b1e6494a148746d50de7 | |||
v1.0 | complete | Apps | Apps_19819_C | def find_maximum_subarray(arr):
"""
Find the subarray with the maximum sum using the divide and conquer approach.
Inputs:
arr (list): A list of integers which could contain both positive and negative numbers.
Outputs:
tuple:
- An integer representing the maximum sum of the subarray... | def max_crossing_sum(arr, left, mid, right):
"""
Helper function to find the maximum sum of the subarray crossing the midpoint.
"""
# Initialize variables to store the maximum sums on the left and right of the midpoint
left_sum = float('-inf')
right_sum = float('-inf')
# Calculate the maxim... | from solution import find_maximum_subarray
def test_find_maximum_subarray():
# Example test case
assert find_maximum_subarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == (6, [4, -1, 2, 1])
# All positive numbers
assert find_maximum_subarray([1, 2, 3, 4, 5]) == (15, [1, 2, 3, 4, 5])
# All negative... | [
{
"docstring": "Helper function to find the maximum sum of the subarray crossing the midpoint.",
"function_declaration": "def max_crossing_sum(arr, left, mid, right):",
"function_name": "max_crossing_sum",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": "Helper function to find... | [
1,
1,
1,
0,
0,
0,
1,
1,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_crossing_sum(arr, left, mid, right):\n # Include elements on left of mid\n left_sum = float('-inf')\n sum = 0\n max_left = mid\n for i in ran... | trial_gpt4o_9 | {
"original_instruction": "Implement a function to calculate the maximum sum subarray using the divide and conquer approach.\n\n##### Inputs:\nA list of integers `arr` which could contain both positive and negative numbers.\n\n##### Outputs:\nA tuple with two elements:\n1. An integer representing the maximum sum of t... | 0.795944 | Apps_19819 | C | [
"max_crossing_sum",
"max_subarray_sum",
"find_maximum_subarray"
] | 3 | [
[
"find_maximum_subarray",
"max_subarray_sum"
],
[
"max_subarray_sum",
"max_crossing_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ced077fc428350425510f6d797ef8689da9d4475 | 2f4fdddbdfa3b81c3e792c96184a3b98cd730c73 | |||
v1.0 | complete | Apps | Apps_19727_C | from typing import List
def map_letters_to_primes(text: str) -> List[int]:
"""
Maps each letter in the input text to a unique prime number and computes the product for each word.
Parameters:
text (str): A string consisting of words separated by spaces.
Returns:
List[int]: A list of pr... | def map_letters_to_primes(text):
"""
Maps each letter in the input text to a unique prime number and computes the product for each word.
Parameters:
text (str): A string consisting of words separated by spaces.
Returns:
List[int]: A list of products for each word in the input string.
... | from solution import map_letters_to_primes
def test_map_letters_to_primes_single_word():
assert map_letters_to_primes("cat") == [710]
def test_map_letters_to_primes_multiple_words():
assert map_letters_to_primes("bat cat dog") == [426, 710, 5593]
def test_map_letters_to_primes_with_repeated_letters():
as... | [
{
"docstring": "Maps each letter in the input text to a unique prime number and computes the product for each word.\n\nParameters:\ntext (str): A string consisting of words separated by spaces.\n\nReturns:\nList[int]: A list of products for each word in the input string.",
"function_declaration": "def map_l... | [
0,
0,
1,
0,
0,
1,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def map_letters_to_primes(sentence):\n \"\"\"\n Maps each letter in the alphabet to a unique prime number and computes\n the product for each word in the g... | trial_gpt4o_9 | {
"original_instruction": "Your task is to write a function named `map_letters_to_primes` that receives a single string argument. This string will consist of multiple words separated by spaces. Each word contains only alphabetical characters and no punctuation.\n\nThe function should map each letter in the alphabet t... | 0.671804 | Apps_19727 | C | [
"map_letters_to_primes",
"product"
] | 2 | [
[
"map_letters_to_primes",
"product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8bf4e36c172a84d5a78718487951e2044c329a63 | 277fce40ec038ff591f20e1b7abd2c9891176720 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.