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_9685_C
def sum_of_digits(n: int) -> int: """ Returns the sum of digits of the number n. >>> sum_of_digits(34) 7 >>> sum_of_digits(23) 5 >>> sum_of_digits(12) 3 >>> sum_of_digits(45) 9 >>> sum_of_digits(222) 6 >>> sum_of_digits(131) 5 """ def sort_by_digit_sum(lst: List[int]) -> List[int]: ...
def sum_of_digits(n): """ Returns the sum of digits of the number n. """ return sum(int(digit) for digit in str(n)) def sort_by_digit_sum(lst): """ Sorts the list of integers based on the sum of their digits. If two numbers have the same sum of digits, they are ordered by their original val...
from solution import sum_of_digits, sort_by_digit_sum def test_sum_of_digits(): assert sum_of_digits(34) == 7 assert sum_of_digits(23) == 5 assert sum_of_digits(12) == 3 assert sum_of_digits(45) == 9 assert sum_of_digits(222) == 6 assert sum_of_digits(131) == 5 def test_sort_by_digit_sum(): ...
[ { "docstring": "Returns the sum of digits of the number n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Sorts the list of integers based on the sum of their digits.\nIf two numbers have the same sum of digits,...
[ 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 sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of the number n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef sort_by_digit_s...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes a list of integers and returns the list sorted in ascending order based on the sum of their digits. If two numbers have the same sum of digits, they should be ordered by their original value.\n\nPreserve spacing before/after characters if present.\n\n## Examples\...
0.761194
Apps_9685
C
[ "sum_of_digits", "sort_by_digit_sum" ]
2
[ [ "sort_by_digit_sum", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ed21fefe2a18a50b054a5f349c98a4deda3e00b
5d3f1fcab42b5be2fdbb63bc9c3e131064720cb9
v1.0
complete
Apps
Apps_8992_C
def is_happy_number(num: int) -> bool: """ Check whether a number is a happy number. >>> is_happy_number(19) True >>> is_happy_number(2) False """ def find_next_happy_number(n: int) -> int: """ Find the next happy number greater than the given positive integer n. >>> find_next_happy...
def is_happy_number(num): 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 find_next_happy_number(n): n += 1 while not is_happy_number(n): n += 1 return n
from solution import find_next_happy_number, is_happy_number def test_is_happy_number(): assert is_happy_number(19) == True assert is_happy_number(1) == True assert is_happy_number(7) == True assert is_happy_number(2) == False assert is_happy_number(4) == False def test_find_next_happy_number(): ...
[ { "docstring": null, "function_declaration": "def is_happy_number(num):", "function_name": "is_happy_number", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_next_happy_number(n):", "function_name": "find_next_happy_number", "parameter_list": "...
[ 1, 1, 1, 0, 0, 0, 1, 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_happy_number(num):\n \"\"\"\n Helper function to determine if a number is a happy number.\n \"\"\"\n seen = set()\n while num != 1 and num not...
trial_gpt4o_7
{ "original_instruction": "Implement a function `find_next_happy_number(n)` that finds the next \"happy number\" greater than `n`.\n\nA \"happy number\" is defined by the following process: \n\n- Starting with any positive integer, replace the number by the sum of the squares of its digits.\n- Repeat the process unti...
0.602757
Apps_8992
C
[ "is_happy_number", "find_next_happy_number" ]
2
[ [ "find_next_happy_number", "is_happy_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
08ff4834a10f359fbc7734974ef489ce19e74b52
2bf6c4d4e1e8c848b1c064bd89d7a892a0bf4f47
v1.0
complete
Apps
Apps_10006_C
from typing import List def is_prime(num: int) -> bool: """Check if a number is prime.""" pass def primes_up_to(n: int) -> List[int]: """Create a function that receives an integer n and returns a list of prime numbers up to n (inclusive). >>> primes_up_to(7) [2, 3, 5, 7] >>> primes_up_to(10) ...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def primes_up_to(n): """ Returns a list of prime numbers up to n (inclusive) """ return [x for x in range(2, n + 1) if is_prime(x)]
from solution import is_prime, primes_up_to def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(10) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == Fals...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers up to n (inclusive)", "function_declaration": "def primes_up_to(n):", "function_name": "primes_up_to", "par...
[ 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 primes_up_to(n):\n \"\"\"\n Returns a list of prime numbers up to and including n.\n \"\"\"\n if n < 2:\n return []\n \n primes = []\n ...
trial_gpt4o_2
{ "original_instruction": "Create a function that receives an integer `n` and returns a list of prime numbers up to `n` (inclusive). A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. \n\n## Example\n\n```python\n7 # should return [2, 3, 5, 7]\n```", "prompt_id": "000...
0.797998
Apps_10006
C
[ "is_prime", "primes_up_to" ]
2
[ [ "primes_up_to", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
be3ebc1f4e2c7a9275e0c158ef0ce0f1aade9af5
6648ab6d98f397553210e5d42b97fea049ce1ce2
v1.0
complete
Apps
Apps_8121_C
def longest_palindromic_subsequence(seq): """ Given a sequence of integers, determine the length of the longest subsequence which forms a palindrome. >>> longest_palindromic_subsequence([1, 2, 3, 4, 3, 2, 1]) 7 >>> longest_palindromic_subsequence([5, 3, 4, 3, 5]) 5 """ pass def solve_p...
def longest_palindromic_subsequence(seq): N = len(seq) dp = [[0] * N for _ in range(N)] for i in range(N): dp[i][i] = 1 for cl in range(2, N + 1): for i in range(N - cl + 1): j = i + cl - 1 if seq[i] == seq[j] and cl == 2: dp[i][j] = 2 ...
import pytest from solution import solve_palindromic_subsequence, parse_input def test_example(): input_str = "2\n7\n1 2 3 4 3 2 1\n5\n5 3 4 3 5\n" test_cases = parse_input(input_str) results = solve_palindromic_subsequence(test_cases) assert results == [7, 5] def test_single_element(): input_str ...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(seq):", "function_name": "longest_palindromic_subsequence", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def solve_palindromic_subsequence(test_cases):", "function_name": "...
[ 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_subsequence_length(sequence):\n \"\"\"\n Returns the length of the longest palindromic subsequence in the given sequence.\n \"\"\"\...
trial_gpt4o_8
{ "original_instruction": "Yoda, the Jedi Master, is training a group of young Padawans to enhance their skills in using the Force. One of the crucial exercises is to understand and work with patterns and sequences in the Force. Yoda presents a challenge to his Padawans: given a sequence of integers, determine the le...
0.785051
Apps_8121
C
[ "longest_palindromic_subsequence", "solve_palindromic_subsequence", "parse_input" ]
3
[ [ "solve_palindromic_subsequence", "longest_palindromic_subsequence" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c579183a7db969ae12bc4a0d9dc0f9b96cf886d8
088bb74a2eea59000dc355169d0f581750c2a9c6
v1.0
complete
Apps
Apps_8066_C
def custom_sort_array(arr: List[int]) -> List[int]: """ Returns the array sorted such that even numbers appear before odd numbers, and both segments are individually sorted in ascending order. >>> custom_sort_array([9, 4, 2, 7, 3, 10, 1, 6]) == [2, 4, 6, 10, 1, 3, 7, 9] >>> custom_sort_array([5, 3, 2, 8...
def custom_sort_array(arr): """ Returns the array sorted such that even numbers appear before odd numbers, and both segments are individually sorted in ascending order. """ evens = [x for x in arr if x % 2 == 0] odds = [x for x in arr if x % 2 != 0] evens = custom_sort(evens) odds = cus...
from solution import custom_sort_array def test_custom_sort_array_even_odd(): assert custom_sort_array([9, 4, 2, 7, 3, 10, 1, 6]) == [2, 4, 6, 10, 1, 3, 7, 9] def test_custom_sort_array_mixed(): assert custom_sort_array([5, 3, 2, 8, 1, 12]) == [2, 8, 12, 1, 3, 5] def test_custom_sort_array_all_even(): as...
[ { "docstring": "Returns the array sorted such that even numbers appear before odd numbers,\nand both segments are individually sorted in ascending order.", "function_declaration": "def custom_sort_array(arr):", "function_name": "custom_sort_array", "parameter_list": "(arr)" }, { "docstring":...
[ 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 custom_sorted_array(arr):\n \"\"\"\n Sorts the array such that even numbers appear before the odd numbers,\n and both are sorted in ascending order wit...
trial_gpt4o_9
{ "original_instruction": "You are given an array of integers. Your task is to sort the array such that the even numbers appear before the odd numbers and both are sorted in ascending order within their respective segments. \n\nYou must accomplish this without using any built-in sort functions.\n\n___\n\n## Examples:...
0.778322
Apps_8066
C
[ "custom_sort_array", "custom_sort" ]
2
[ [ "custom_sort_array", "custom_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31b3c3608b8a4c4318b00bf8cb219d37826e4e70
48be24d5cdb7fdb212f8f814f05580551d980cc1
v1.0
complete
Apps
Apps_9434_C
def count_divisors(n: int) -> int: """ Returns the number of divisors of a given integer n. >>> count_divisors(1) 1 >>> count_divisors(6) 4 """ # Implement the function here def sort_by_divisors(lst: List[int]) -> List[Tuple[int, int]]: """ Accepts a list of integers and returns...
def count_divisors(n): """ Returns the number of divisors of n. """ if n == 1: return 1 count = 0 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: count += 1 if i != n // i: count += 1 return count def sort_by_divisors(lst): ""...
def test_count_divisors(): assert count_divisors(1) == 1 assert count_divisors(6) == 4 assert count_divisors(14) == 4 assert count_divisors(12) == 6 assert count_divisors(25) == 3 def test_sort_by_divisors(): assert sort_by_divisors([6, 1, 14, 12]) == [(1, 1), (6, 4), (14, 4), (12, 6)] asse...
[ { "docstring": "Returns the number of divisors of n.", "function_declaration": "def count_divisors(n):", "function_name": "count_divisors", "parameter_list": "(n)" }, { "docstring": "Accepts a list of integers and returns a list of tuples,\neach containing the integer and its number of divis...
[ 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": "def count_divisors(n):\n \"\"\"\n Returns the count of divisors of a given integer n.\n \"\"\"\n if n == 0:\n return 0\n divisors_count = 0\n ...
trial_gpt4o_1
{ "original_instruction": "Write a function that accepts a list of integers and returns a list of tuples, each containing two elements: the integer and its number of divisors. The returned list should be sorted by the number of divisors in ascending order. If two integers have the same number of divisors, sort those ...
0.767461
Apps_9434
C
[ "count_divisors", "sort_by_divisors" ]
2
[ [ "sort_by_divisors", "count_divisors" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1e23f3091f989c22136cfd1a1e3a5f317bbf4063
af859c5359d251dbd170c11fa5284c566dbdd99e
v1.0
complete
Apps
Apps_10012_C
def decimal_to_binary(num): """ Converts a given decimal number to its binary representation as a string. >>> decimal_to_binary(1) == "1" >>> decimal_to_binary(2) == "10" >>> decimal_to_binary(3) == "11" >>> decimal_to_binary(4) == "100" >>> decimal_to_binary(5) == "101" """ def generat...
def decimal_to_binary(num): """ Converts a given decimal number to its binary representation as a string. """ binary_str = "" while num > 0: binary_str = str(num % 2) + binary_str num = num // 2 return binary_str def generate_binary_representations(n): """ Generates the ...
def test_decimal_to_binary(): assert decimal_to_binary(1) == "1" assert decimal_to_binary(2) == "10" assert decimal_to_binary(3) == "11" assert decimal_to_binary(4) == "100" assert decimal_to_binary(5) == "101" def test_generate_binary_representations(): assert generate_binary_representations(1...
[ { "docstring": "Converts a given decimal number to its binary representation as a string.", "function_declaration": "def decimal_to_binary(num):", "function_name": "decimal_to_binary", "parameter_list": "(num)" }, { "docstring": "Generates the binary representations for all numbers from 1 to...
[ 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_binary_string(number):\n \"\"\"\n Convert an integer to its binary string representation without leading zeros.\n \"\"\"\n if number == 0:\n ...
trial_gpt4o_9
{ "original_instruction": "### Binary Array Representation\n\nYou are given an integer `n`. Your task is to generate a binary representation of all numbers from `1` to `n` and return them in the form of a list of strings.\n\n**Input**\n- An integer `n` where `1 <= n <= 100`.\n\n**Output**\n- A list of strings represe...
0.799013
Apps_10012
C
[ "decimal_to_binary", "generate_binary_representations" ]
2
[ [ "generate_binary_representations", "decimal_to_binary" ] ]
1
[]
false
[]
false
pytest
false
[]
true
86faf03e410c8c868807436bfcf18dce8eaef07f
68ee4fa81981313c562674c13dd4670dcf819f07
v1.0
complete
Apps
Apps_10076_C
from typing import List def is_palindrome(n: int) -> bool: """ Check if a given number n is a palindrome. >>> is_palindrome(121) True >>> is_palindrome(123) False >>> is_palindrome(1) True >>> is_palindrome(22) True """ pass def is_prime(n: int) -> bool: """ Check if a ...
def is_palindrome(n): """ Check if a given number n is a palindrome. """ return str(n) == str(n)[::-1] def is_prime(n): """ Check if a given number n is a prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False ...
from solution import is_palindrome, is_prime, palindromic_primes def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(22) == True def test_is_prime(): assert is_prime(2) == True assert is_prime(3) ==...
[ { "docstring": "Check if a given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Check if a given number n is a prime.", "function_declaration": "def is_prime(n):", "function_nam...
[ 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": "def is_palindrome(x):\n return str(x) == str(x)[::-1]\n\ndef sieve_of_eratosthenes(n):\n is_prime = [True] * (n + 1)\n is_prime[0] = is_prime[1] = False\n ...
trial_gpt4o_2
{ "original_instruction": "# Task\nA \"palindromic prime\" is a prime number that is also a palindrome. Given an integer range `[a, b]`, your task is to find all palindromic primes within this range, inclusive of `a` and `b`.\n\n# Input/Output\n\n`[input]` integer `a`\nInteger representing the start of the range (inc...
0.718755
Apps_10076
C
[ "is_palindrome", "is_prime", "palindromic_primes" ]
3
[ [ "palindromic_primes", "is_palindrome" ], [ "palindromic_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aff118da08eb46221a6b97ef9160648878d21d32
64cc01b4f672ca51fe68ced1060a89306f09e715
v1.0
complete
Apps
Apps_10018_C
def is_prime(num: int) -> bool: """Determines if the given number is a prime number. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, otherwise False. >>> is_prime(2) True >>> is_prime(4) False """ pass def filter_primes(...
def is_prime(num): """ Helper function to determine if a number is a prime number. Returns True if the number is prime, False otherwise. """ 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):...
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(16) == False assert is_prime(17) == True assert is_prime(1) == False assert is_prime(-5) == Fals...
[ { "docstring": "Helper function to determine if a number is a prime number.\nReturns True if the number is prime, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list containing only the prim...
[ 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 n is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu...
trial_gpt4o_9
{ "original_instruction": "Create a function that takes an array of integers and returns a new array containing only the numbers that are prime.\n\n## About prime numbers\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nFor instance, the number 2 is a prime ...
0.763297
Apps_10018
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
37292dccf047364bcab3a34f979647c264b2d1de
ad6eb3abb9545738ba68c275f860f4d163ef2838
v1.0
complete
Apps
Apps_9453_C
from typing import List def check_staircase_numbers(numbers: List[int]) -> List[bool]: """ Determine if each number in the list is a triangular number. A triangular number T_n is defined as T_n = n*(n+1)/2, where n is a positive integer. Parameters: numbers (List[int]): A list of integers representing...
import math def is_triangular_number(num): if num <= 0: return False n = (-1 + math.sqrt(1 + 8 * num)) / 2 return n.is_integer() def check_staircase_numbers(numbers): return [is_triangular_number(num) for num in numbers]
from solution import check_staircase_numbers def test_check_staircase_numbers_all_true(): assert check_staircase_numbers([1, 3, 6, 10, 15]) == [True, True, True, True, True] def test_check_staircase_numbers_all_false(): assert check_staircase_numbers([4, 7, 9, 13, 16]) == [False, False, False, False, False] ...
[ { "docstring": null, "function_declaration": "def is_triangular_number(num):", "function_name": "is_triangular_number", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def check_staircase_numbers(numbers):", "function_name": "check_staircase_numbers", "...
[ 0, 1, 1, 0, 1, 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_triangular_number(n):\n \"\"\"\n Checks if a given number n is a triangular number.\n \n A number n is triangular if and only if there exists a p...
trial_gpt4o_8
{ "original_instruction": "You are given a list of integers where each integer represents the number of steps a person has climbed. For each number, you need to determine if it represents the last step of a valid staircase. A valid staircase is formed if and only if the number of steps climbed follows a triangular nu...
0.573247
Apps_9453
C
[ "is_triangular_number", "check_staircase_numbers" ]
2
[ [ "check_staircase_numbers", "is_triangular_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6e0c85521b254bb6ec3f2678ca4668c212c1ee5
689cfe4319a8156c60e2ad9a9b76c64e3fb0dd16
v1.0
complete
Apps
Apps_10593_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, else False. """ def filter_primes(numbers: List[int]) -> List[int]: """ Filters out the prime numbers from a list of integers. >>> filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] >>> filter_primes([1, 4, 6, 8,...
def is_prime(n): """ Returns True if n is a prime number, else False. """ 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 filter_...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_filter_primes_no_...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters out the prime numbers from a list of integers.", "function_declaration": "def filter_primes(numbe...
[ 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 Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int...
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. For the purposes of this problem, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nExample:\n\nInput: [2...
0.779883
Apps_10593
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19f7cba2a305aa8e747e4093b620a66e3bd50bc2
7dd9f0fc9cfd1466878ebddfeb0cb46704c99f7c
v1.0
complete
Apps
Apps_10032_C
from typing import List def shortest_transformation_sequence(wordList: List[str], startWord: str, endWord: str) -> int: """ Returns the length of the shortest transformation sequence from startWord to endWord. >>> shortest_transformation_sequence(["hot","dot","dog","lot","log","cog"], "hit", "cog") == 5 >>...
from collections import deque def is_one_letter_diff(word1, word2): """ Checks if the two words differ by exactly one character. """ diff_count = 0 for c1, c2 in zip(word1, word2): if c1 != c2: diff_count += 1 if diff_count > 1: return False return diff_c...
from solution import shortest_transformation_sequence def test_example_1(): wordList = ["hot","dot","dog","lot","log","cog"] startWord = "hit" endWord = "cog" assert shortest_transformation_sequence(wordList, startWord, endWord) == 5 def test_example_2(): wordList = ["hot","dot","dog","lot","log"]...
[ { "docstring": "Checks if the two words differ by exactly one character.", "function_declaration": "def is_one_letter_diff(word1, word2):", "function_name": "is_one_letter_diff", "parameter_list": "(word1, word2)" }, { "docstring": "Returns the length of the shortest transformation sequence ...
[ 1, 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef differ_by_one(word1, word2):\n \"\"\"\n Check if word1 and word2 differ by exactly one character.\n \"\"\"\n return...
trial_gpt4o_6
{ "original_instruction": "You are given a list, `wordList`, that contains `n` words and a `startWord` and `endWord` that are both in the `wordList`. A transformation sequence from the `startWord` to `endWord` is a sequence of words such that:\n\n1. Each word in the sequence is in `wordList`.\n2. The first word in th...
0.580005
Apps_10032
C
[ "is_one_letter_diff", "shortest_transformation_sequence" ]
2
[ [ "shortest_transformation_sequence", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3532cef6d534fb3205b4f5050ed71c3ee4431139
53d0d8caf8b8b6ae0dd085cc446b47d653d1ef8e
v1.0
complete
Apps
Apps_8607_C
import random def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points in n-dimensional space. """ return sum((x - y) ** 2 for x, y in zip(point1, point2)) ** 0.5 def k_means_clustering(data, k): """ Perform k-means clustering on the given dataset. Args: data...
import random def euclidean_distance(point1, point2): return sum((x - y) ** 2 for x, y in zip(point1, point2)) ** 0.5 def get_initial_centroids(data, k): random_indices = random.sample(range(len(data)), k) return [data[idx] for idx in random_indices] def assign_clusters(data, centroids): clusters = [...
from solution import k_means_clustering def test_k_means_clustering_2_clusters(): data = [(1, 2), (1, 4), (1, 0), (4, 2), (4, 4), (4, 0)] k = 2 centroids, labels = k_means_clustering(data, k) assert len(centroids) == k assert len(labels) == len(data) assert all(label in range(k) for label ...
[ { "docstring": null, "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": null, "function_declaration": "def get_initial_centroids(data, k):", "function_name": "get_initial_cen...
[ 1, 0, 0, 0, 0, 0, 1, 0, 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 random\nimport math\n\ndef euclidean_distance(point1, point2):\n return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2)))\n\ndef find_closest_c...
trial_gpt4o_9
{ "original_instruction": "Your task is to develop a function to perform k-means clustering on a dataset. \n\nYou will receive a dataset and the number of clusters, k. Your function should return the cluster centroids and the cluster labels for each data point.\n\nYou should implement the k-means algorithm from scrat...
0.811876
Apps_8607
C
[ "euclidean_distance", "get_initial_centroids", "assign_clusters", "update_centroids", "k_means_clustering" ]
5
[ [ "assign_clusters", "euclidean_distance" ], [ "k_means_clustering", "assign_clusters" ], [ "k_means_clustering", "get_initial_centroids" ], [ "k_means_clustering", "update_centroids" ] ]
4
[]
false
[]
false
pytest
true
[]
true
e9f6e95438064213c45904c6d838e0abb27880d4
d842cb63be2f4dcfd6eb49f54c710b849dcd7275
v1.0
complete
Apps
Apps_10203_C
import math def is_perfect_square(x): """ Helper function to check if x is a perfect square. """ s = int(math.sqrt(x)) return s * s == x def fibonacci_checker(n): """ Returns True if n is a Fibonacci number, and False if it is not. >>> fibonacci_checker(0) True >>> fibonacci_checke...
import math def is_perfect_square(x): """ Helper function to check if x is a perfect square. """ s = int(math.sqrt(x)) return s * s == x def fibonacci_checker(n): """ Returns True if n is a Fibonacci number, and False if it is not. """ # A number is Fibonacci if and only if one or ...
from solution import fibonacci_checker def test_fibonacci_checker_with_fib_numbers(): assert fibonacci_checker(0) == True assert fibonacci_checker(1) == True assert fibonacci_checker(2) == True assert fibonacci_checker(3) == True assert fibonacci_checker(5) == True assert fibonacci_checker(8) =...
[ { "docstring": "Helper function to check if x is a perfect square.", "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": "Returns True if n is a Fibonacci number, and False if it is not.", "function_declarat...
[ 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": "import math\n\ndef is_perfect_square(x):\n s = int(math.sqrt(x))\n return s * s == x\n\ndef fibonacci_checker(n):\n \"\"\"\n Returns True if `n` is a Fi...
trial_gpt4o_9
{ "original_instruction": "Write a function `fibonacci_checker(n)` that takes an integer `n` as input and returns True if `n` is a part of the Fibonacci sequence, and False otherwise. The function should efficiently determine the status of `n` without generating the whole sequence up to `n`.\n\nThe Fibonacci sequence...
0.702362
Apps_10203
C
[ "is_perfect_square", "fibonacci_checker" ]
2
[ [ "fibonacci_checker", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed69369bd12fefbf36b94d5c5b35d1ab6853e2b7
d291a5160df9c415b49356cdff0d287e5c6074af
v1.0
complete
Apps
Apps_9844_C
def increasing_subsequence_exists(T: int, test_cases: List[Tuple[Tuple[int, int], List[int]]]) -> List[str]: """ Emma works as a data analyst and frequently deals with large datasets. She comes across a problem where she needs to analyze a sequence of integers and determine whether it contains an incr...
def increasing_subsequence_exists(T, test_cases): results = [] for t in range(T): N, K = test_cases[t][0] sequence = test_cases[t][1] if find_increasing_subseq_of_length_k(sequence, K): results.append("YES") else: results.append("NO") ret...
from solution import increasing_subsequence_exists def test_sample_cases(): assert increasing_subsequence_exists(2, [((5, 3), [1, 2, 3, 4, 5]), ((5, 6), [1, 2, 3, 4, 5])]) == ["YES", "NO"] def test_case_subsequence_of_length_1(): assert increasing_subsequence_exists(1, [((4, 1), [1, 7, 3, 4])]) == ["YES"] de...
[ { "docstring": null, "function_declaration": "def increasing_subsequence_exists(T, test_cases):", "function_name": "increasing_subsequence_exists", "parameter_list": "(T, test_cases)" }, { "docstring": null, "function_declaration": "def find_increasing_subseq_of_length_k(sequence, K):", ...
[ 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def increasing_subsequence_exists(test_cases):\n results = []\n for case in test_cases:\n N, K = case[0], case[1]\n sequence = case[2]\n ...
trial_gpt4o_6
{ "original_instruction": "Emma works as a data analyst and frequently deals with large datasets. She comes across a problem where she needs to analyze a sequence of integers and determine whether it contains an increasing subsequence of length $K$. An increasing subsequence is a sequence of integers where each eleme...
0.64637
Apps_9844
C
[ "increasing_subsequence_exists", "find_increasing_subseq_of_length_k", "binary_search_lis_position" ]
3
[ [ "find_increasing_subseq_of_length_k", "binary_search_lis_position" ], [ "increasing_subsequence_exists", "find_increasing_subseq_of_length_k" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a3de59246a453361e3bb4d353ccdee17be34a017
4eddcba2e80c421813381ac5519af8a4904fc9c2
v1.0
complete
Apps
Apps_9677_C
def process_bookstore_promotions(input_data: str) -> str: """Help the bookstore identify the K most available books in terms of their stock quantity. Each book is represented by a unique International Standard Book Number (ISBN), and its availability is represented by a positive integer indicating the numb...
def get_top_k_books(test_cases): results = [] for case in test_cases: N, K, books = case sorted_books = sorted(books, key=lambda x: (-x[1], x[0])) results.extend(sorted_books[:K]) results.append(None) # Marker for end of test case return results def parse_input(input_data):...
from solution import process_bookstore_promotions def test_single_case(): input_data = "1\n5 3\n9780321150793 7\n9780131103627 4\n9780201633610 12\n9780131101630 8\n9780201485677 10" expected_output = "9780201633610 12\n9780201485677 10\n9780131101630 8" assert process_bookstore_promotions(input_data) == e...
[ { "docstring": null, "function_declaration": "def get_top_k_books(test_cases):", "function_name": "get_top_k_books", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_data):", "function_name": "parse_input", "parameter_list": ...
[ 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 most_available_books(test_cases):\n results = []\n for test_case in test_cases:\n N, K, books = test_case\n sorted_books = sorted(books, key...
trial_gpt4o_9
{ "original_instruction": "An online bookstore keeps track of their inventory and sales using a specialized inventory management system. Each book is represented by a unique International Standard Book Number (ISBN), and its availability is represented by a positive integer indicating the number of copies in stock. T...
0.616184
Apps_9677
C
[ "get_top_k_books", "parse_input", "format_output", "process_bookstore_promotions" ]
4
[ [ "process_bookstore_promotions", "format_output" ], [ "process_bookstore_promotions", "get_top_k_books" ], [ "process_bookstore_promotions", "parse_input" ] ]
3
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
5db1f7087eec360f9f9fa1e4a002c180fec54048
09a3db6ed1518b3f036964f40c2ea2087ad262ff
v1.0
complete
Apps
Apps_10654_C
def shared_divisors(x: int, y: int) -> int: """ Write a function named `shared_divisors` that takes in two integers, `x` and `y`, and returns the number of common divisors they have. >>> shared_divisors(12, 18) # should return 4, since the common divisors are 1, 2, 3, 6 >>> shared_divisors(7, 13) # shoul...
def gcd(a, b): """ Returns the Greatest Common Divisor of `a` and `b` using the Euclidean algorithm. """ while b: a, b = b, a % b return a def shared_divisors(x, y): """ Returns the number of common divisors of `x` and `y`. """ def count_divisors(n): count = 0 ...
from solution import shared_divisors def test_shared_divisors_common(): assert shared_divisors(12, 18) == 4 # Common divisors: 1, 2, 3, 6 def test_shared_divisors_prime_numbers(): assert shared_divisors(7, 13) == 1 # Common divisor: 1 def test_shared_divisors_mixed(): assert shared_divisors(100, 75) ==...
[ { "docstring": "Returns the Greatest Common Divisor of `a` and `b` using the Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the number of common divisors of `x` and `y`.", "function_declaratio...
[ 0, 0, 0, 0, 0, 1, 1, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shared_divisors(x, y):\n \"\"\"\n Returns the number of common divisors of x and y.\n \"\"\"\n def gcd(a, b):\n \"\"\"Helper function to comp...
trial_gpt4o_9
{ "original_instruction": "Write a function named `shared_divisors` that takes in two integers, `x` and `y`, and returns the number of common divisors they have. A divisor of a number `n` is a number `d` such that `n % d == 0`.\n\n### Examples\n```python\nshared_divisors(12, 18) # should return 4, since the common d...
0.786919
Apps_10654
C
[ "gcd", "shared_divisors" ]
2
[ [ "shared_divisors", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4dc4c6aa6ff8fa92bc175112dd3a11a3491128d
dc6d9cbde616e4e2e43d946bd68d1955ce4b5c8c
v1.0
complete
Apps
Apps_10330_C
def sum_of_proper_divisors(num: int) -> int: """Helper function to calculate the sum of proper divisors of a given number.""" pass def amicable_numbers(n: int) -> List[Tuple[int, int]]: """ Function to find all pairs of amicable numbers less than or equal to n. Returns a list of tuples with each tu...
def sum_of_proper_divisors(num): """Helper function to calculate the sum of proper divisors of num.""" proper_divisors_sum = 1 # 1 is a proper divisor for any num > 1 for i in range(2, int(num**0.5) + 1): if num % i == 0: proper_divisors_sum += i if i != num // i: # Avoid a...
from solution import amicable_numbers def test_no_amicable_numbers(): assert amicable_numbers(1) == [] assert amicable_numbers(10) == [] def test_single_amicable_pair(): assert amicable_numbers(300) == [(220, 284)] def test_multiple_amicable_pairs(): assert amicable_numbers(10000) == [(220, 284), (11...
[ { "docstring": "Helper function to calculate the sum of proper divisors of num.", "function_declaration": "def sum_of_proper_divisors(num):", "function_name": "sum_of_proper_divisors", "parameter_list": "(num)" }, { "docstring": "Function to find all pairs of amicable numbers less than or eq...
[ 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_proper_divisors(num):\n \"\"\"\n Returns the sum of proper divisors of a given number 'num'.\n \"\"\"\n if num < 2:\n return 0\n pr...
trial_gpt4o_9
{ "original_instruction": "Write a function `amicable_numbers(n)` that finds all pairs of amicable numbers less than or equal to `n`. Two numbers are considered amicable if the sum of the proper divisors of each number equals the other number. For example, (220, 284) is an amicable pair because the sum of proper divi...
0.660991
Apps_10330
C
[ "sum_of_proper_divisors", "amicable_numbers" ]
2
[ [ "amicable_numbers", "sum_of_proper_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51ae6e4be84c093dfdb9ed3f7656a3793db4da75
1e06a369357619ff8ca4e16b98c0b9fe79edf1ad
v1.0
complete
Apps
Apps_10534_C
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot]...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot]...
def test_minimum_cost_to_connect_all_houses(): input_data = [ (2, [ (4, 5, [(1, 2, 10), (2, 3, 15), (3, 4, 10), (1, 4, 5), (2, 4, 10)]), (3, 3, [(1, 2, 1), (2, 3, 2), (3, 1, 3)]) ]), ] expected_results = [ [25, 3] ] for i, data in enumerate(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 ]
1
hard
0.111
{ "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 else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fin...
trial_gpt4o_0
{ "original_instruction": "A village is planning to build roads to connect all its houses. The village has N houses, and a set of M potential roads. Each road i connects two houses u[i] and v[i], and has a cost associated with it, w[i].\n\nTo facilitate trade and communication, the village chief wants to ensure that ...
0.613616
Apps_10534
C
[ "find", "union", "kruskal", "minimum_cost_to_connect_all_houses" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_all_houses", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
07c835630cf18bf015c7523de86c50ea42d9c309
673e1aeecd7d26e188da7dd3f3b54520f04137cf
v1.0
complete
Apps
Apps_9845_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def has_cycle(head): """ Checks if the linked list has a cycle. :param head: The head of the linked list. :return: True if there is a cycle, otherwise False. """ pass def build_linked_list...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def has_cycle(head): """ Checks if the linked list has a cycle. :param head: The head of the linked list. :return: True if there is a cycle, otherwise False. """ if not head: return...
from solution import detect_cycle_in_list, build_linked_list, has_cycle def test_no_cycle(): values = [1, 2, 3] next_indices = [1, 2, -1] head = build_linked_list(values, next_indices) assert not has_cycle(head) def test_one_cycle(): values = [1, 2, 3, 4] next_indices = [1, 2, 3, 1] head =...
[]
[ 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": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef has_cycle(head):\n slow, fast = head, h...
trial_gpt4o_9
{ "original_instruction": "In a linked list, each node contains two fields: an integer value and a reference to the next node in the sequence. Write a function to check if a given linked list contains a cycle. A linked list has a cycle if a node's reference links back to a previous node in the list, creating a loop. ...
0.494962
Apps_9845
C
[ "has_cycle", "build_linked_list", "detect_cycle_in_list" ]
3
[ [ "detect_cycle_in_list", "build_linked_list" ], [ "detect_cycle_in_list", "has_cycle" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
c088db2043187e846db17817947f84db03fbae41
f9187dd19deb0f29f0437a13f127a79bfa28c71c
v1.0
complete
Apps
Apps_10450_C
def is_valid_move(piece, start, end): """Determine if a given move is valid according to chess rules for the given piece. """ def are_moves_valid(moves): """Check if a sequence of chess moves is valid according to the movement rules for each piece. Args: moves (List[Tuple[str, str, str]]):...
def is_valid_move(piece, start, end): col_diff = ord(end[0]) - ord(start[0]) row_diff = int(end[1]) - int(start[1]) if piece == 'Pawn': # Assume it's a white Pawn for simplicity return (col_diff == 0 and row_diff == 1) or \ (abs(col_diff) == 1 and row_diff == 1) elif ...
from solution import are_moves_valid def test_valid_moves(): assert are_moves_valid([('Pawn', 'e2', 'e3'), ('Knight', 'g1', 'f3')]) == True assert are_moves_valid([('Rook', 'a1', 'a8'), ('Bishop', 'c1', 'g5')]) == True assert are_moves_valid([('Queen', 'd1', 'd4'), ('King', 'e1', 'e2')]) == True assert...
[ { "docstring": null, "function_declaration": "def is_valid_move(piece, start, end):", "function_name": "is_valid_move", "parameter_list": "(piece, start, end)" }, { "docstring": null, "function_declaration": "def are_moves_valid(moves):", "function_name": "are_moves_valid", "para...
[ 0, 1, 1, 0, 0, 0, 1, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_move(move):\n piece, start, end = move\n start_col, start_row = ord(start[0]) - ord('a'), int(start[1]) - 1\n end_col, end_row = ord(end[0]) -...
trial_gpt4o_1
{ "original_instruction": "Your task is to determine if a sequence of moves in a chess game is valid based on the movement rules for each piece.\n\n_________________________________________________\nRules:\n\n1. The chessboard is represented by an 8x8 grid with columns labeled from 'a' to 'h' and rows from '1' to '8'...
0.588928
Apps_10450
C
[ "is_valid_move", "are_moves_valid" ]
2
[ [ "are_moves_valid", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f65b3d9204741c77911095d800ca1489e5a1863d
a9e01d7b9b85fe4fe9f43dcee6162223c2c48cda
v1.0
complete
Apps
Apps_10784_C
def find_two_sum_indices(array, target): """Finds indices of two elements in the array that add up to the target. >>> find_two_sum_indices([2, 7, 11, 15, 1], 9) (0, 1) >>> find_two_sum_indices([3, 3, 4], 6) (0, 1) """ def solve_tests(test_cases): """Solves multiple test cases for finding tw...
def find_two_sum_indices(array, target): """Finds indices of two elements in the array that add up to the target.""" num_to_index = {} for index, num in enumerate(array): if target - num in num_to_index: return num_to_index[target - num], index num_to_index[num] = index retur...
import pytest from solution import find_two_sum_indices, solve_tests, process_input def test_find_two_sum_indices(): # Test case 1 array = [2, 7, 11, 15, 1] target = 9 assert find_two_sum_indices(array, target) == (0, 1) # Test case 2 array = [3, 3, 4] target = 6 assert find_two_sum_in...
[ { "docstring": "Finds indices of two elements in the array that add up to the target.", "function_declaration": "def find_two_sum_indices(array, target):", "function_name": "find_two_sum_indices", "parameter_list": "(array, target)" }, { "docstring": null, "function_declaration": "def so...
[ 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": "def find_two_sum_indices(array, target):\n \"\"\"\n Returns the indices of two numbers in an array that add up to the target value.\n If no such pair exist...
trial_gpt4o_3
{ "original_instruction": "You are given an array of integers and a target value. Your task is to determine whether there are two distinct elements in the array that add up to the target value. If such a pair exists, return the indices of the two numbers; otherwise, return `-1 -1`.\n\nNote that the indices returned s...
0.608476
Apps_10784
C
[ "find_two_sum_indices", "solve_tests", "process_input" ]
3
[ [ "solve_tests", "find_two_sum_indices" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
0cc7ff91fcb36666c1e35165f72b20f892729616
328a766f7e04d7ee1bdc5e06b9c56b038fbba6df
v1.0
complete
Apps
Apps_11052_C
from typing import List def sum_of_primes(numbers: List[int]) -> int: """ Given a list of integers, returns the sum of its elements that are prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples: >>> sum_of_primes([1, 2...
from typing import List def is_prime(n: int) -> bool: """ Helper function to determine if a number is a prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_primes(numbers: List[int]) -> int: ...
from solution import sum_of_primes def test_sum_of_primes_with_primes(): assert sum_of_primes([1, 2, 3, 4, 5]) == 10 def test_sum_of_primes_all_non_primes(): assert sum_of_primes([0, 1, 4, 6]) == 0 def test_sum_of_primes_mixed_numbers(): assert sum_of_primes([10, 11, 12, 13, 14]) == 24 def test_sum_of_p...
[ { "docstring": "Helper function to determine if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of prime numbers in the given list.", "function_declaration": "def sum_of_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": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_7
{ "original_instruction": "Given a list of integers, write a function that returns the sum of its elements that are prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. \n\nFor example:\n- If the list is [1, 2, 3, 4, 5], the prime numbers are [2, 3, 5...
0.6857
Apps_11052
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
515a76f9a40fc958c1caa251db753b172666512b
c11ad3f8ecf1172e9021a24318f18856cbc34503
v1.0
complete
Apps
Apps_11038_C
class Node: def __init__(self, value): self.value = value self.left = None self.right = None def construct_tree(values, edges): nodes = {i + 1: Node(values[i]) for i in range(len(values))} for u, v in edges: if not nodes[u].left: nodes[u].left = nodes[v] ...
class Node: def __init__(self, value): self.value = value self.left = None self.right = None def construct_tree(values, edges): nodes = {i + 1: Node(values[i]) for i in range(len(values))} for u, v in edges: if not nodes[u].left: nodes[u].left = nodes[v] ...
from solution import solve def test_example1(): test_cases = [ ([1, -2, 3], [(1, 2), (1, 3)]) ] assert solve(test_cases) == [4] def test_example2(): test_cases = [ ([-10, 9, 20, 15, 7], [(1, 2), (1, 3), (3, 4), (3, 5)]) ] assert solve(test_cases) == [42] def test_single_node()...
[]
[ 1, 0, 0, 0, 0, 1, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef construct_tree(values, edges):\n...
trial_gpt4o_0
{ "original_instruction": "You have been given a binary tree with N nodes. Each node has a value associated with it. The path sum of any path in this binary tree is defined as the sum of the values of the nodes that the path visits. A path does not necessarily need to pass through the root.\n\nYour task is to find an...
0.637661
Apps_11038
C
[ "construct_tree", "max_path_sum", "solve" ]
3
[ [ "solve", "construct_tree" ], [ "solve", "max_path_sum" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
899b7bb1fa9259e7474784f065481343657e3cb0
a97b2534e07907d85ee66e732b60280fb6046c0a
v1.0
complete
Apps
Apps_11040_C
from typing import List def is_prime(n: int) -> bool: """ Helper function to check if a number is a prime number. """ pass def filter_primes(numbers: List[int]) -> List[int]: """ Takes a list of integers and returns a list of prime numbers from that list. Example: >>> filter_primes([1...
def is_prime(n): """ Helper function to check if a number is a prime number. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Takes a list of integers and returns a list of...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([10, 15, 19, 21, 23, 29, 31, 39]) == [19, 23, 29, 31] def test_filter_primes_with_no_primes(): assert filter_primes([4, 6, 8, 9, 10]) == [] def test_filter_primes_with_all_primes(): assert filter_primes([...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a list of prime numbers from that list.", "function_declarati...
[ 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 if n == 2:\n return True\n if n % 2 =...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes a list of integers as input and returns a list containing all the prime numbers from the input list.\n\nExample:\n```python\nfilter_primes([10, 15, 19, 21, 23, 29, 31, 39]) => [19, 23, 29, 31]\nfilter_primes([4, 6, 8, 9, 10]) => []\nfilter_primes([2, 3, 5, 7, 11]...
0.779303
Apps_11040
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c32eb88a8c165889cd0ce090d2840f1405da3d6c
246169a4b1da29836abbe151c06209c3e7e19564
v1.0
complete
Apps
Apps_11334_C
def generate_fibonacci(n: int) -> List[int]: """ Helper function to generate the first `n` Fibonacci numbers. """ fib = [0] * n fib[0] = 1 if n > 1: fib[1] = 1 for i in range(2, n): fib[i] = fib[i - 1] + fib[i - 2] return fib def fibonacci_matrix(N: int) -> List[List[int]]: ...
def generate_fibonacci(n): """Helper function to generate the first `n` Fibonacci numbers.""" fib = [0] * n fib[0] = 1 if n > 1: fib[1] = 1 for i in range(2, n): fib[i] = fib[i - 1] + fib[i - 2] return fib def fibonacci_matrix(N): """Generates an N x N matrix filled with Fib...
import io from contextlib import redirect_stdout from solution import main def test_main(): input_data = "2\n2\n3\n" expected_output = "1 1\n2 3\n1 1 2\n3 5 8\n13 21 34\n" with io.StringIO() as buf, redirect_stdout(buf): main(input_data) output = buf.getvalue() assert output == expected...
[ { "docstring": "Helper function to generate the first `n` Fibonacci numbers.", "function_declaration": "def generate_fibonacci(n):", "function_name": "generate_fibonacci", "parameter_list": "(n)" }, { "docstring": "Generates an N x N matrix filled with Fibonacci sequence in a row-wise \nmann...
[ 0, 1, 0, 1, 1, 1, 1, 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 generate_fibonacci_matrix(N):\n def fibonacci_sequence(length):\n fibs = [0] * length\n fibs[0], fibs[1] = 1, 1\n for i in range(2, leng...
trial_gpt4o_9
{ "original_instruction": "You are given an integer $N$. Print the $N \\times N$ matrix where the elements of each row are the Fibonacci sequence starting from the next Fibonacci number after the last element of the previous row.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting...
0.742908
Apps_11334
C
[ "generate_fibonacci", "fibonacci_matrix", "print_fibonacci_matrices", "main" ]
4
[ [ "fibonacci_matrix", "generate_fibonacci" ], [ "print_fibonacci_matrices", "fibonacci_matrix" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c409e8568c958db3e500b8f821196252d4ee9a5c
ff0cb90b64940f7d485cfc3b0d16cf46c826d8ff
v1.0
complete
Apps
Apps_11769_C
def longest_path_length(n: int, connections: List[Tuple[int, int]]) -> int: """ Determine the length of the longest path between any two intersections in a hexagonal grid-shaped city. Each intersection has exactly three roads connecting to other intersections. Parameters: n (int): Number of interse...
from collections import deque, defaultdict def find_farthest_node(edges, start_node): farthest_node = start_node max_distance = 0 queue = deque([(start_node, 0)]) visited = set() visited.add(start_node) while queue: current_node, distance = queue.popleft() if distance > max...
def test_longest_path_length(): # Sample test case assert longest_path_length(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == 4 # Single node graph assert longest_path_length(1, []) == 0 # Two nodes graph (simplest tree) assert longest_path_length(2, [(1, 2)]) == 1 # Linea...
[ { "docstring": null, "function_declaration": "def find_farthest_node(edges, start_node):", "function_name": "find_farthest_node", "parameter_list": "(edges, start_node)" }, { "docstring": null, "function_declaration": "def longest_path_length(n, connections):", "function_name": "long...
[ 0, 1, 0, 1, 0, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef longest_path_length(N, edges):\n def bfs(start_node):\n distance = [-1] * (N + 1)\n queue = deque...
trial_gpt4o_9
{ "original_instruction": "A courier company operates in a city constructed as a hexagonal grid with unique intersections and roads. Each intersection is represented by a node and each road is an edge connecting two nodes. The city is designed in a way that each intersection connects to exactly three other intersecti...
0.65771
Apps_11769
C
[ "find_farthest_node", "longest_path_length" ]
2
[ [ "longest_path_length", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
9f30257b8f217dba4bab8f8f15e80f9ebd45b7ef
dbdcd99689145cec4fb8b93d737e5c351f8d233b
v1.0
complete
Apps
Apps_10344_C
def prim_minimum_spanning_tree(n, edges): """ Computes the minimum total cost required to upgrade the network so that all warehouses are connected. Parameters: n (int): The number of warehouses (nodes) edges (List[Tuple[int, int, int]]): Each tuple contains three integers u, v, and w representing a ...
import heapq def prim_minimum_spanning_tree(n, edges): # Adjacency list representation of the graph graph = {i: [] for i in range(1, n+1)} for u, v, w in edges: graph[u].append((w, v)) graph[v].append((w, u)) # Priority queue to pick the minimum weight edge min_heap = [(0, 1)] # S...
def test_case_1(): input_data = """2 4 5 1 2 1 1 3 4 1 4 3 2 3 2 3 4 5 3 3 1 2 2 2 3 3 1 3 4""" test_cases = parse_input(input_data) assert min_upgrade_cost(test_cases) == [6, 5] def test_case_2(): input_data = """1 5 6 1 2 2 1 3 3 1 4 1 1 5 4 2 3 5 4 5 6""" test_cases = parse_input(input_data) ...
[ { "docstring": null, "function_declaration": "def prim_minimum_spanning_tree(n, edges):", "function_name": "prim_minimum_spanning_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def min_upgrade_cost(test_cases):", "function_name": "min_upgrade_c...
[ 0, 1, 0, 1, 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 find_min_cost_to_upgrade_network(T, test_cases):\n \"\"\"\n Function to calculate minimum cost to upgrade the network using Kruskal's algorithm\n which...
trial_gpt4o_3
{ "original_instruction": "The company has a network of warehouses where products are stored before being shipped to customers. The network of warehouses can be represented as an undirected graph, with each warehouse as a node and each direct road between two warehouses as an edge. The company's goal is to upgrade th...
0.691657
Apps_10344
C
[ "prim_minimum_spanning_tree", "min_upgrade_cost", "parse_input" ]
3
[ [ "min_upgrade_cost", "prim_minimum_spanning_tree" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
18d0df90ab9a80342279fb83cdbbdc5c4a7b705e
df7288366c5800651ecba6085148bdd2e905a6d4
v1.0
complete
Apps
Apps_11668_C
def minimum_total_travel_cost(N: int, M: int, roads: List[Tuple[int, int, int]]) -> int: """ Compute the minimum total travel cost to ensure there is at most one unique path between any two towns. This function solves the problem by finding the Minimum Spanning Tree (MST) of the graph represented by the to...
def find(parent, i): if parent[i] == i: return i else: 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]: p...
def test_minimum_total_travel_cost(): # Test Case 1 N = 5 M = 6 roads = [ (1, 2, 3), (1, 3, 1), (3, 4, 2), (3, 5, 4), (4, 5, 5), (2, 4, 6) ] assert minimum_total_travel_cost(N, M, roads) == 10 # Test Case 2 N = 4 M = 5 roads = ...
[ { "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, 1, 1, 0, 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": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = fi...
trial_gpt4o_0
{ "original_instruction": "In a kingdom far away, there are N towns connected by M bidirectional roads. The kingdom's ruler wants to ensure that the kingdom is well-connected, and that for any two towns, there is at most one unique path connecting them. \n\n- Each town is uniquely identified by an integer from 1 to N...
0.736948
Apps_11668
C
[ "find", "union", "kruskal_min_spanning_tree", "minimum_total_travel_cost" ]
4
[ [ "kruskal_min_spanning_tree", "find" ], [ "kruskal_min_spanning_tree", "union" ], [ "minimum_total_travel_cost", "kruskal_min_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
da7b7e165a65b998a7ce3a4461b6c51262551709
676d66128e85568ff266784e115f8ed059353952
v1.0
complete
Apps
Apps_11244_C
def is_subsequence(s: str, word: str) -> bool: """ Check if the word is a subsequence of the string s. >>> is_subsequence("abc", "a") True >>> is_subsequence("abc", "d") False """ def longest_subsequence_length(s: str, words: List[str]) -> int: """ Given a list of words, find the length of the ...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def longest_subsequence_length(s, words): max_length = -1 for word in words: if is_subsequence(s, word): max_length = max(max_length, len(word)) return max_length
from solution import longest_subsequence_length def test_no_subsequence(): assert longest_subsequence_length("abc", ["def", "ghi"]) == -1 def test_one_subsequence(): assert longest_subsequence_length("abc", ["a", "d"]) == 1 def test_multiple_subsequences(): assert longest_subsequence_length("abpcplea", [...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def longest_subsequence_length(s, words):", "function_name": "longest_subsequence_length", ...
[ 1, 1, 0, 1, 1, 0, 1, 0, 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 longest_subsequence_word_length(s, words):\n \"\"\"\n Find the length of the longest word in the list 'words' that is a subsequence of the string 's'.\n ...
trial_gpt4o_6
{ "original_instruction": "Given a list of words, find the length of the longest word that is a subsequence of the given string. \n\nA subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.\n\nReturn the length of the longest...
0.759534
Apps_11244
C
[ "is_subsequence", "longest_subsequence_length" ]
2
[ [ "longest_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6e033585fda8eec32b430087c083866779df2be
e2846d66192956a393650da275e54a1a83413e19
v1.0
complete
Apps
Apps_11501_C
def minimizeMaxWorkingTime(tasks: List[int], k: int) -> int: """ Distribute tasks among workers to minimize the maximum working time of any worker. >>> minimizeMaxWorkingTime([10, 20, 30, 40], 2) 60 >>> minimizeMaxWorkingTime([10, 20, 30], 2) 30 >>> minimizeMaxWorkingTime([10, 25, 40, 5], 3) 40 """ ...
def canDistribute(tasks, k, mid): current_worker = 1 current_time = 0 for task in tasks: if current_time + task > mid: current_worker += 1 current_time = task if current_worker > k: return False else: current_time += task ...
from solution import minimizeMaxWorkingTime def test_example_1(): assert minimizeMaxWorkingTime([10, 20, 30, 40], 2) == 60 def test_example_2(): assert minimizeMaxWorkingTime([10, 20, 30], 2) == 30 def test_example_3(): assert minimizeMaxWorkingTime([10, 25, 40, 5], 3) == 40 def test_single_task(): ...
[ { "docstring": null, "function_declaration": "def canDistribute(tasks, k, mid):", "function_name": "canDistribute", "parameter_list": "(tasks, k, mid)" }, { "docstring": null, "function_declaration": "def minimizeMaxWorkingTime(tasks, k):", "function_name": "minimizeMaxWorkingTime", ...
[ 0, 1, 1, 1, 1, 0, 1, 0, 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 distribute_tasks(tasks, k):\n def is_valid(max_time):\n \"\"\"\n Helper function to check if it's possible to distribute tasks such that\n ...
trial_gpt4o_6
{ "original_instruction": "Given an array of integers representing the amount of time tasks take to complete, and a positive integer k representing the number of workers available, distribute the tasks among the workers to minimize the maximum working time of any worker. Each worker can only work on sequential tasks ...
0.653354
Apps_11501
C
[ "canDistribute", "minimizeMaxWorkingTime" ]
2
[ [ "minimizeMaxWorkingTime", "canDistribute" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f2f0193154c1e0e4018489bcc43a1f0f1556f0e
c6362c064c3f337256bf3f7baf39435af148ad47
v1.0
complete
Apps
Apps_11162_C
def encrypt(text): """ Encrypt the input text using the Alphabet Half-Shift Cipher. >>> encrypt("abcdefghijklmnopqrstuvwxyz") "nopqrstuvwxyzabcdefghijklm" >>> encrypt("ABCDEFGHIJKLMNOPQRSTUVWXYZ") "NOPQRSTUVWXYZABCDEFGHIJKLM" >>> encrypt("Hello, World!") "Uryyb, Jbeyq!" >>> encrypt("1234...
def encrypt(text): def shift_char(c): if 'a' <= c <= 'z': return chr((ord(c) - ord('a') + 13) % 26 + ord('a')) elif 'A' <= c <= 'Z': return chr((ord(c) - ord('A') + 13) % 26 + ord('A')) else: return c return ''.join(shift_char(c) for c in text) def d...
from solution import encrypt, decrypt def test_encrypt_lowercase(): assert encrypt("abcdefghijklmnopqrstuvwxyz") == "nopqrstuvwxyzabcdefghijklm" def test_encrypt_uppercase(): assert encrypt("ABCDEFGHIJKLMNOPQRSTUVWXYZ") == "NOPQRSTUVWXYZABCDEFGHIJKLM" def test_encrypt_mixed_case(): assert encrypt("Hello,...
[ { "docstring": null, "function_declaration": "def encrypt(text):", "function_name": "encrypt", "parameter_list": "(text)" }, { "docstring": null, "function_declaration": "def decrypt(cipher):", "function_name": "decrypt", "parameter_list": "(cipher)" }, { "docstring": nul...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shift_char(char, shift):\n \"\"\"\n Helper function to shift a character by 'shift' positions.\n \"\"\"\n if 'a' <= char <= 'z':\n return chr...
trial_gpt4o_9
{ "original_instruction": "In this problem, you need to implement a simple text encryption algorithm called the \"Alphabet Half-Shift Cipher\". The cipher involves shifting each letter to another letter halfway through the alphabet. For example, the letter 'a' will be shifted to 'n', the letter 'b' will be shifted to...
0.778148
Apps_11162
C
[ "encrypt", "decrypt" ]
2
[ [ "decrypt", "encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e63e13887e8dfcd18a7544d893a565afb6fe21a
82e401e1eba85d1a23360a9244667d3d0c5acf42
v1.0
complete
Apps
Apps_11897_C
def find_kth_smallest(nums, k): """ Write a function `find_kth_smallest(nums, k)` that takes a list of unique integers `nums` and an integer `k`, and returns the k-th smallest number in the list. To make it more challenging, do not sort the entire list. Instead, implement an efficient algorithm (such as Quickse...
def partition(arr, left, right, pivot_index): pivot_value = arr[pivot_index] arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = left for i in range(left, right): if arr[i] < pivot_value: arr[store_index], arr[i] = arr[i], arr[store_index] store_ind...
from solution import find_kth_smallest def test_kth_smallest_positive_numbers(): assert find_kth_smallest([3, 1, 2, 5, 4], 2) == 2 def test_kth_smallest_first_element(): assert find_kth_smallest([9, 8, 7, 6, 5, 4, 3, 2, 1], 1) == 1 def test_kth_smallest_mixed_numbers(): assert find_kth_smallest([10, 20, ...
[ { "docstring": null, "function_declaration": "def partition(arr, left, right, pivot_index):", "function_name": "partition", "parameter_list": "(arr, left, right, pivot_index)" }, { "docstring": null, "function_declaration": "def quickselect(arr, left, right, k):", "function_name": "q...
[ 1, 1, 0, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] < pivot:\n arr[i],...
trial_gpt4o_9
{ "original_instruction": "Write a function `find_kth_smallest(nums, k)` that takes a list of unique integers `nums` and an integer `k`, and returns the k-th smallest number in the list.\n\nTo make it more challenging, do not sort the entire list. Instead, implement an efficient algorithm (such as Quickselect) to fin...
0.730751
Apps_11897
C
[ "partition", "quickselect", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "quickselect" ], [ "quickselect", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
86a01bc9f6eaaed1947d9eb99a6633e02978a8a1
d60547cf69363093f202a39c0a8e531e1de7a197
v1.0
complete
Apps
Apps_11168_C
def calculate_subtree_strengths(N, values, edges, queries): """ Calculate the strength of the subtree rooted at any given node u in a tree with N nodes. Inputs: - N: Number of nodes in the tree. - values: A list of integers where values[i-1] is the value associated with node i. - edges: A ...
def calculate_subtree_strengths(N, values, edges, queries): from collections import defaultdict, deque # Build the tree graph from edges tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) # Strengths array to store the sum of values in the subtree roote...
def test_calculate_subtree_strengths(): N = 5 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] Q = 3 queries = [1, 2, 3] result = run_queries(N, values, edges, Q, queries) assert result == [15, 11, 3], f"Expected [15, 11, 3] but got {result}" def test_single_node(): N =...
[ { "docstring": null, "function_declaration": "def calculate_subtree_strengths(N, values, edges, queries):", "function_name": "calculate_subtree_strengths", "parameter_list": "(N, values, edges, queries)" }, { "docstring": null, "function_declaration": "def run_queries(N, values, edges, Q...
[ 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_subtree_strengths(N, values, edges, queries):\n from collections import defaultdict, deque\n\n # Build the tree structure using adjacency list\n...
trial_gpt4o_9
{ "original_instruction": "In a mystical forest, there is a magical tree with $N$ nodes. Each node is uniquely identified by an integer from $1$ to $N$. The tree is rooted at node $1$. Each node has an associated integer value $a_i$ (1 ≤ i ≤ N). \n\nA forest guardian is tasked with ensuring the health of the tree. To...
0.574593
Apps_11168
C
[ "calculate_subtree_strengths", "run_queries" ]
2
[ [ "run_queries", "calculate_subtree_strengths" ] ]
1
[]
false
[]
false
pytest
false
[]
true
08c45931c431e4328c7e36a32a30f676eb79e1c1
1a3f8c085ba6c77ffd936ce8fd71c74b9bbd9e29
v1.0
complete
Apps
Apps_11963_C
def largest_rectangle(matrix): """ Calculate the largest rectangle area containing only 1's in the matrix. >>> largest_rectangle([ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 0, 0, 1, 0] ... ]) == 6 >>> largest_rectangle([ ... [0, 1, 1],...
def largest_rectangle(matrix): if not matrix or not matrix[0]: return 0 max_area = 0 n = len(matrix[0]) heights = [0] * n for row in matrix: for i in range(n): heights[i] = heights[i] + 1 if row[i] == 1 else 0 max_area = max(max_area, max_histogram_area(heights)...
from solution import largest_rectangle def test_small_matrix(): matrix = [ [1, 0], [1, 1] ] assert largest_rectangle(matrix) == 2 def test_single_row(): matrix = [ [1, 0, 1, 1, 1] ] assert largest_rectangle(matrix) == 3 def test_single_column(): matrix = [ ...
[ { "docstring": null, "function_declaration": "def largest_rectangle(matrix):", "function_name": "largest_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def max_histogram_area(heights):", "function_name": "max_histogram_area", "parameter_...
[ 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 largest_rectangle(matrix):\n def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(his...
trial_gpt4o_4
{ "original_instruction": "A function receives a matrix ```m x n``` (m rows and n columns) with integers. The function should calculate the largest rectangle area containing only 1's in the matrix and return its area.\n\nThe order that the function receives its arguments is:\n```python\nlargest_rectangle(matrix)\n```...
0.721115
Apps_11963
C
[ "largest_rectangle", "max_histogram_area" ]
2
[ [ "largest_rectangle", "max_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b209ca3a9a9406bf0991189d38941cf94e349de
2ddac387cac45ec2b7cd8d1a4357ef5da0e2e8f2
v1.0
complete
Apps
Apps_11804_C
from typing import List def prime_pathways(N: int, M: int, board: List[List[int]]) -> str: """ Determines if there is a path from the top-left to the bottom-right on the checkerboard containing only prime numbers. >>> prime_pathways(3, 3, [[5, 4, 7], [13, 11, 9], [6, 2, 3]]) == "YES" >>> prime_pathways...
def is_prime(num): """ Check if a number is a prime number. """ if num < 2: return False if num == 2: return True if num % 2 == 0: return False sqr = int(num ** 0.5) + 1 for div in range(3, sqr, 2): if num % div == 0: return False return Tr...
import pytest from solution import prime_pathways def test_example_case(): board = [ [5, 4, 7], [13, 11, 9], [6, 2, 3] ] assert prime_pathways(3, 3, board) == "YES" def test_no_path(): board = [ [4, 4, 8], [6, 10, 15], [9, 8, 4] ] assert prime_pa...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determines if there is a path from the top-left to the bottom-right on the checkerboard\ncontaining only prime number...
[ 0, 1, 1, 1, 1, 1, 0, 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 is_prime(n):\n \"\"\"\n Checks if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n...
trial_gpt4o_5
{ "original_instruction": "In the bustling town of Numbertown, there's an annual festival called the Number Carnival where various puzzle contests are held. One of the most anticipated contests is the **\"Prime Pathways\"** game. \n\nThe game takes place on a large checkerboard where each cell contains a positive int...
0.574946
Apps_11804
C
[ "is_prime", "find_prime_path", "prime_pathways" ]
3
[ [ "find_prime_path", "is_prime" ], [ "prime_pathways", "find_prime_path" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0c1452eac073f24dbbe704f3191486a3855bcd00
2be5ffc9e0369c3d47a2a17e527eda262ba3428d
v1.0
complete
Apps
Apps_11602_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, otherwise returns False. """ pass def prime_products(a: List[int], b: List[int]) -> bool: """ Given two lists of positive integers a and b, returns True if the product of the integers in each list are both prime numbers,...
from math import isqrt def is_prime(n): """ Returns True if n is a prime number, otherwise returns False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == ...
from solution import is_prime, prime_products def test_is_prime(): assert is_prime(2) is True assert is_prime(3) is True assert is_prime(4) is False assert is_prime(17) is True assert is_prime(1) is False assert is_prime(0) is False assert is_prime(18) is False def test_prime_products_all_...
[ { "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": "Given two lists of positive integers a and b, returns True if the product of the integers in eac...
[ 1, 0, 0, 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": "def is_prime(number):\n \"\"\"\n Determines if a number is a prime number.\n \"\"\"\n if number <= 1:\n return False\n for i in range(2, int(n...
trial_gpt4o_9
{ "original_instruction": "Given two positive integer lists a and b each containing `n` elements (`1 <= n <= 100`), determine if the product of the integers in the two lists are both prime numbers. If both products are prime, return `True`, otherwise return `False`.\n\n## Example\n\n```\na = [3, 7]\nb = [5, 11]\n\npr...
0.737543
Apps_11602
C
[ "is_prime", "prime_products" ]
2
[ [ "prime_products", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d9b239591764506a06c718aaf980889463792ce
51c8292aec54c382768e24a3c3370987d3ba1851
v1.0
complete
Apps
Apps_11859_C
def lis_length(arr): """ Function to return the length of the longest increasing subsequence. >>> lis_length([5, 3, 4, 8, 6]) == 3 >>> lis_length([7, 7, 7]) == 1 >>> lis_length([1, 2, 3, 4, 5]) == 5 >>> lis_length([5, 4, 3, 2, 1]) == 1 >>> lis_length([1]) == 1 >>> lis_length([]) == 0 ...
def lis_length(arr): """ Function to return the length of the longest increasing subsequence. """ if not arr: return 0 n = len(arr) lis = [1] * n for i in range(1, n): for j in range(i): if arr[i] > arr[j]: lis[i] = max(lis[i], lis[j] + 1) retu...
def test_lis_length(): assert lis_length([5, 3, 4, 8, 6]) == 3 assert lis_length([7, 7, 7]) == 1 assert lis_length([1, 2, 3, 4, 5]) == 5 assert lis_length([5, 4, 3, 2, 1]) == 1 assert lis_length([1]) == 1 assert lis_length([]) == 0 def test_lds_length(): assert lds_length([5, 3, 4, 8, 6]) =...
[ { "docstring": "Function to return the length of the longest increasing subsequence.", "function_declaration": "def lis_length(arr):", "function_name": "lis_length", "parameter_list": "(arr)" }, { "docstring": "Function to return the length of the longest decreasing subsequence.", "funct...
[ 0, 1, 0, 0, 1, 1, 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 length_of_LIS(nums):\n if not nums:\n return 0\n dp = [1] * len(nums)\n for i in range(1, len(nums)):\n for j in range(i):\n i...
trial_gpt4o_9
{ "original_instruction": "You are given an array of integers. Your task is to find the maximum length of any subsequence in the array that is strictly increasing, and then the maximum length of any subsequence in the array that is strictly decreasing. You will then compute the difference between these two lengths.\n...
0.718963
Apps_11859
C
[ "lis_length", "lds_length", "difference_lis_lds" ]
3
[ [ "difference_lis_lds", "lds_length" ], [ "difference_lis_lds", "lis_length" ] ]
2
[]
false
[]
false
pytest
false
[]
true
158139ef93656ed7bf0eea6218d6abaf7c47031f
3ca27792d20d33d8cd78a0efe5f96622fadd87aa
v1.0
complete
Apps
Apps_11919_C
def minimum_cost_to_connect_all_cities(N: int, M: int, edges: List[List[int]]) -> int: """ Determine the minimum cost required to connect all the cities so that there is a path between any pair of cities. ---Input--- - N: int, number of vertices (cities) - M: int, number of edges (roads) - edges...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
from solution import minimum_cost_to_connect_all_cities def test_minimum_cost_basic(): edges = [[1, 2, 3], [2, 3, 2], [3, 4, 4], [4, 1, 1], [1, 3, 0]] assert minimum_cost_to_connect_all_cities(4, 5, edges) == 3 def test_minimum_cost_already_connected(): ...
[ { "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, 1, 0, 0, 1, 1, 0, 1 ]
5
medium
0.625
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "def find_minimum_cost_to_connect_cities(N, M, edges):\n \"\"\"\n Determines the minimum cost required to connect all cities.\n \n ...
trial_gpt4o_9
{ "original_instruction": "You are given an undirected graph with N vertices and M edges. Each vertex represents a city, and each edge represents a bidirectional road between two cities. Some of these edges have already been constructed, while others need to be constructed. Building a new road between two cities incu...
0.709634
Apps_11919
C
[ "find", "union", "minimum_cost_to_connect_all_cities" ]
3
[ [ "minimum_cost_to_connect_all_cities", "find" ], [ "minimum_cost_to_connect_all_cities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d78412d0a4f0ee13f46f4308d58d11e8801e96af
9c02fea612174f05e845a6e64aac4855412995ba
v1.0
complete
Apps
Apps_11113_C
from typing import List, Tuple def create_prefix_sum(grid: List[List[int]]) -> List[List[int]]: """ Create a prefix sum matrix for the given grid. """ pass def subgrid_sum(prefix_sum: List[List[int]], x1: int, y1: int, x2: int, y2: int) -> int: """ Calculate the sum of the subgrid from (x1, y1...
def create_prefix_sum(grid): """ Create a prefix sum matrix for the given grid. """ N = len(grid) M = len(grid[0]) 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] = grid[i-1][j-1] + prefix_sum[i-...
from solution import create_prefix_sum, subgrid_sum, process_queries def test_create_prefix_sum(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert create_p...
[ { "docstring": "Create a prefix sum matrix for the given grid.", "function_declaration": "def create_prefix_sum(grid):", "function_name": "create_prefix_sum", "parameter_list": "(grid)" }, { "docstring": "Calculate the sum of the subgrid from (x1, y1) to (x2, y2) using the prefix sum matrix....
[ 1, 1, 0, 1, 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 preprocess_grid(grid, n, m):\n \"\"\"\n Preprocess the grid to compute the prefix sum array.\n \"\"\"\n prefix_sum = [[0] * (m + 1) for _ in range(n...
trial_gpt4o_9
{ "original_instruction": "Alice has a rectangular grid of size N x M, filled with integers. Bob helps Alice by providing a subgrid of size k x k. Alice wants to find the sum of the elements in this subgrid. Since Bob can be busy, the task is to optimize the query to find the sum as quickly as possible. \n\nCan you h...
0.587946
Apps_11113
C
[ "create_prefix_sum", "subgrid_sum", "process_queries" ]
3
[ [ "process_queries", "create_prefix_sum" ], [ "process_queries", "subgrid_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
a7dd33a8175801201f9fac7941e34079ad4e1295
8af03e15266905ab37c5418935b587d22145516c
v1.0
complete
Apps
Apps_11815_C
def find_max_values(test_cases): """ Returns a list of maximum values for each input list of integers. :param test_cases: list of lists, where each inner list is a sequence of integers :return: list of maximum integers for each input list """ pass def parse_input(input_string): """ ...
def find_max_values(test_cases): """ Returns a list of maximum values for each input list of integers. :param test_cases: list of lists, where each inner list is a sequence of integers :return: list of maximum integers for each input list """ return [max(test_case) for test_case in test_cas...
from io import StringIO from solution import find_max_values, parse_input, process_input_outputs import pytest def test_find_max_values(): assert find_max_values([[1, 2, 3, 4, 5], [-10, -20, -30, -40, -50]]) == [5, -10] assert find_max_values([[5], [-5], [0]]) == [5, -5, 0] assert find_max_values([[1000, -...
[ { "docstring": "Returns a list of maximum values for each input list of integers.\n\n:param test_cases: list of lists, where each inner list is a sequence of integers\n:return: list of maximum integers for each input list", "function_declaration": "def find_max_values(test_cases):", "function_name": "fi...
[ 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 find_max_in_lists(list_of_lists):\n \"\"\"\n Given a list of lists of integers, return a list of the maximum values for each list.\n :param list_of_lis...
trial_gpt4o_9
{ "original_instruction": "-----Problem Statement-----\nWrite a program that reads a list of integers and outputs the maximum value in the list.\n\n-----Input-----\nThe first line contains an integer, t, the number of test cases. The next t lines each contain a sequence of space-separated integers representing a list...
0.601198
Apps_11815
C
[ "find_max_values", "parse_input", "process_input_outputs" ]
3
[ [ "process_input_outputs", "find_max_values" ], [ "process_input_outputs", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
fb8494aa51789fae905b0358fa6cb3cb5be5a216
80577fd16a36f444aa2463b88423bda2a73e1b5a
v1.0
complete
Apps
Apps_11674_C
def minimum_spanning_tree(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Compute the sum of the weights of the edges in the Minimum Spanning Tree (MST) of a given graph. Args: n (int): Number of nodes in the graph. m (int): Number of edges in the graph. edges (List[Tuple[int, int, in...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
import pytest from solution import minimum_spanning_tree def test_mst_example_case(): n, m = 4, 5 edges = [ (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 1, 2), (1, 3, 6) ] assert minimum_spanning_tree(n, m, edges) == 9 def test_mst_single_node(): n, m = 1, 0 edg...
[ { "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, 1, 0 ]
2
medium
0.333
{ "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 else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(parent...
trial_gpt4o_0
{ "original_instruction": "You are given an undirected graph with $N$ nodes and $M$ edges. Each edge connects two different nodes and has a positive integer weight. Your task is to compute the sum of the weights of the edges in the Minimum Spanning Tree (MST) of this graph.\n\n-----Input:-----\n- First line will cont...
0.682025
Apps_11674
C
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
c9c3ce47a068ecb9c0896f29841cb996c39a9df2
2623f07e2ab83c3c3ae25114c77bdf0116426a3c
v1.0
complete
Apps
Apps_12219_C
def is_prime(n): """ Returns True if the integer n is a prime number, otherwise returns False. """ def prime_status_list(num_list): """ Given a list of integers, returns a dictionary where each key is an integer from the list and the value is a boolean indicating whether the integer is a p...
def is_prime(n): """ Returns True if the integer n is a prime number, otherwise returns False. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def prime_status_list(num_list): """ Given a list of integ...
from solution import is_prime, prime_status_list def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_prime_status_list...
[ { "docstring": "Returns True if the integer n is a prime number, otherwise returns False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, returns a dictionary where each key is an integer from \nt...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if the integer n is a prime number, otherwise returns False.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_8
{ "original_instruction": "=====Function Descriptions=====\nis_prime(n)\n\nReturns True if the integer n is a prime number, otherwise returns False.\n\nCode\n\n>>> def is_prime(n):\n... if n <= 1:\n... return False\n... for i in range(2, int(n ** 0.5) + 1):\n... if n % i == 0:\n... ...
0.793099
Apps_12219
C
[ "is_prime", "prime_status_list" ]
2
[ [ "prime_status_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c0cb57256378b1190e6cc3bde5c7b49dc81ba80
35aa82b698383137354ee40240a9edf007456595
v1.0
complete
Apps
Apps_12199_C
import re def is_palindrome(s: str) -> bool: """ Check if the given string s is a palindrome, ignoring case and non-alphanumeric characters. """ # Remove non-alphanumeric characters and convert to lowercase cleaned = re.sub(r'[^a-zA-Z0-9]', '', s).lower() return cleaned == cleaned[::-1] def fi...
import re def is_palindrome(s): """ Check if the given string s is a palindrome, ignoring case and non-alphanumeric characters. """ # Remove non-alphanumeric characters and convert to lowercase cleaned = re.sub(r'[^a-zA-Z0-9]', '', s).lower() return cleaned == cleaned[::-1] def filter_palindro...
from solution import filter_palindromes def test_filter_palindromes_all_palindromes(): assert filter_palindromes(["level", "deified", "civic"]) == ["level", "deified", "civic"] def test_filter_palindromes_mixed(): assert filter_palindromes(["level", "world", "deified", "hello", "civic"]) == ["level", "deified...
[ { "docstring": "Check if the given string s is a palindrome, ignoring case and non-alphanumeric characters.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Filters a list of strings, returning only those which ar...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "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 stripped = re.sub(r'[^a-zA-Z0-9]', '', s).lower()\n return stripped == stripped[::-1]\n\ndef filter_palindromes(strings):...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes in a list of strings and returns a new list containing only those strings which are palindromes. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).\n...
0.78881
Apps_12199
C
[ "is_palindrome", "filter_palindromes" ]
2
[ [ "filter_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d75ee22759e89c7f1cfc7f47855228801e19b08d
b6dc44da4c80758bd67266bd507c3c9b3aaf62a6
v1.0
complete
Apps
Apps_12053_C
def is_palindrome(num: int) -> bool: """ Returns True if num is a palindrome, False otherwise. >>> is_palindrome(121) True >>> is_palindrome(123) False >>> is_palindrome(1) True >>> is_palindrome(22) True >>> is_palindrome(10) False """ def count_palindromes(A: int, B: int) -> int: ...
def is_palindrome(num): """ Returns True if num is a palindrome, False otherwise. """ return str(num) == str(num)[::-1] def count_palindromes(A, B): """ Returns the count of palindromic numbers between A and B (inclusive). """ count = 0 for i in range(A, B + 1): if is_palind...
from solution import is_palindrome, count_palindromes, process_test_cases def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(22) == True assert is_palindrome(10) == False def test_count_palindromes(): ...
[ { "docstring": "Returns True if num is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Returns the count of palindromic numbers between A and B (inclusive).", "function_decl...
[ 0, 0, 0, 0, 0, 1, 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 count_palindromic_numbers(a, b):\n \"\"\"\n Returns the number of palindromic numbers between a and b inclusive.\n \"\"\"\n def is_palindrome(n):\n ...
trial_gpt4o_8
{ "original_instruction": "Alice is participating in a coding competition, and she loves palindromic numbers. A number is a palindrome if it reads the same backward as forward. Alice is interested in finding out how many palindromic numbers exist within a specified range from $A$ to $B$ (both inclusive). Can you assi...
0.731298
Apps_12053
C
[ "is_palindrome", "count_palindromes", "process_test_cases" ]
3
[ [ "count_palindromes", "is_palindrome" ], [ "process_test_cases", "count_palindromes" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
5d96ba321a087af16be266d1b142ca0b00974627
80483547ab915ccdf195d740aec1c8d555ef434a
v1.0
complete
Apps
Apps_11969_C
def smallest_trailing_zeros(n: int) -> int: """ Design a function that takes an integer `n` and returns the smallest number of trailing zeros in the factorial of any number greater than or equal to `n`. The number of trailing zeros in the factorial of a number `x` can be counted by how many times `x` i...
def trailing_zeros(x): """ Helper function that calculates the number of trailing zeros in x factorial. """ count = 0 while x >= 5: x //= 5 count += x return count def smallest_trailing_zeros(n: int) -> int: """ Returns the smallest number of trailing zeros in the factor...
from solution import smallest_trailing_zeros def test_smallest_trailing_zeros_5(): assert smallest_trailing_zeros(5) == 1 def test_smallest_trailing_zeros_10(): assert smallest_trailing_zeros(10) == 2 def test_smallest_trailing_zeros_25(): assert smallest_trailing_zeros(25) == 6 def test_smallest_traili...
[ { "docstring": "Helper function that calculates the number of trailing zeros in x factorial.", "function_declaration": "def trailing_zeros(x):", "function_name": "trailing_zeros", "parameter_list": "(x)" }, { "docstring": "Returns the smallest number of trailing zeros in the factorial of any...
[ 0, 0, 1, 0, 1, 1, 0, 0, 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 count_trailing_zeros(x):\n \"\"\"\n A helper function that calculates the number of trailing zeros in the factorial of x.\n \"\"\"\n count = 0\n ...
trial_gpt4o_8
{ "original_instruction": "Design a function that takes an integer `n` and returns the smallest number of trailing zeros in the factorial of any number greater than or equal to `n`.\n\nLet's define the number of trailing zeros in the factorial of a number. For example, `5! = 120` has `1` trailing zero and `10! = 3628...
0.6219
Apps_11969
C
[ "trailing_zeros", "smallest_trailing_zeros" ]
2
[ [ "smallest_trailing_zeros", "trailing_zeros" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89a31751072418d353e382398bcb64501b179e55
edbd80b577068ee1264f584e4208e31994ff9aaf
v1.0
complete
Apps
Apps_12112_C
import math def is_triangular(n): """ Check if 'n' is a Triangular number. >>> is_triangular(3) True >>> is_triangular(6) True >>> is_triangular(10) True >>> is_triangular(15) True >>> is_triangular(21) True >>> is_triangular(8) False >>> is_triangular(14) False """ pass de...
import math def is_triangular(n): """ Check if 'n' is a Triangular number. Tn = n(n + 1)/2 => 8n + 1 is a perfect square """ x = 8 * n + 1 sqrt_x = int(math.isqrt(x)) return sqrt_x * sqrt_x == x def is_hexagonal(n): """ Check if 'n' is a Hexagonal number. Hn = n(2n - 1) => 8n +...
def test_is_triangular(): assert is_triangular(3) == True assert is_triangular(6) == True assert is_triangular(10) == True assert is_triangular(15) == True assert is_triangular(21) == True assert is_triangular(8) == False assert is_triangular(14) == False def test_is_hexagonal(): assert...
[ { "docstring": "Check if 'n' is a Triangular number.\nTn = n(n + 1)/2 => 8n + 1 is a perfect square", "function_declaration": "def is_triangular(n):", "function_name": "is_triangular", "parameter_list": "(n)" }, { "docstring": "Check if 'n' is a Hexagonal number.\nHn = n(2n - 1) => 8n + 1 is...
[ 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 math\n\ndef is_triangular(n):\n \"\"\"\n Check if n is a triangular number.\n \"\"\"\n k = (-1 + math.sqrt(1 + 8 * n)) / 2\n return k.is_integ...
trial_gpt4o_3
{ "original_instruction": "## Task\n\nYou need to write four functions: `isTriangular`, `isHexagonal`, `isTetrahedral`, and `isSquareTriangular` for the respective languages:\n\n- Functions: `isTriangular, isHexagonal, isTetrahedral, isSquareTriangular` (JS, Coffee)\n- Functions: `is_triangular, is_hexagonal, is_tetr...
0.605026
Apps_12112
C
[ "is_triangular", "is_hexagonal", "is_tetrahedral", "is_square_triangular" ]
4
[ [ "is_square_triangular", "is_triangular" ] ]
1
[]
false
[]
false
pytest
false
[]
true
7c2a1198895c5a811738ce708646e70d855a53a2
8ac8318115d5c436de139be1c5b5ddedd1cf8053
v1.0
complete
Apps
Apps_11738_C
from collections import deque from typing import List, Tuple def bfs_minimum_moves(grid: List[List[str]], n: int) -> int: """ Solve for the minimum number of moves required to travel from the top-left corner to the bottom-right corner of a grid. >>> bfs_minimum_moves([[".", ".", "."], [".", "*", "."], [".", "....
from collections import deque def bfs_minimum_moves(grid, n): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] visited = [[False] * n for _ in range(n)] queue = deque([(0, 0, 0)]) # (row, col, distance) while queue: r, c, dist = queue.popleft() if r == n - 1 and c == n - 1: ...
import pytest from solution import solve, parse_input def test_example_case_1(): input_data = "2\n3\n...\n.*.\n...\n3\n*..\n.*.\n...\n" t, test_cases = parse_input(input_data) assert solve(t, test_cases) == [4, -1] def test_impossible_start(): input_data = "1\n2\n*.\n..\n" t, test_cases = parse_in...
[ { "docstring": null, "function_declaration": "def bfs_minimum_moves(grid, n):", "function_name": "bfs_minimum_moves", "parameter_list": "(grid, n)" }, { "docstring": null, "function_declaration": "def solve(t, test_cases):", "function_name": "solve", "parameter_list": "(t, test_c...
[ 0, 0, 1, 0, 0, 1, 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": "from collections import deque\n\ndef min_moves(t, test_cases):\n results = []\n \n for i in range(t):\n n, grid = test_cases[i]\n if grid[0][...
trial_gpt4o_2
{ "original_instruction": "You are given a grid of size n x n where each cell contains either '.' (representing an empty cell) or '*' (representing a blocked cell). A piece can only move to an adjacent cell (up, down, left, right) if that cell is empty. You are tasked with finding the minimum number of moves required...
0.666208
Apps_11738
C
[ "bfs_minimum_moves", "solve", "parse_input" ]
3
[ [ "solve", "bfs_minimum_moves" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
fe3a965ca1bc24fe50dd00e0677460b3fa0490e4
6eed5e4dadb72cc311830f7fa93ed831c1d46884
v1.0
complete
Apps
Apps_11903_C
def filter_primes(int_list): """ Returns a list containing all prime numbers from the input list. >>> filter_primes([15, 3, 11, 20, 17, 4, 1, 2, 19]) == [3, 11, 17, 2, 19] >>> filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] >>> filter_primes([4, 6, 8, 9, 10]) == [] >>> filter_primes([5, 5, 6, 7,...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 9, 10]) == [] def test_filter_primes_mixed_numbers(): assert filter_primes([15, 3, 11, 20, 17, 4, 1, 2, 19]...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list containing all prime numbers from the input list.", "function_declaration": "def filter_primes(int_list):",...
[ 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": "Challenge:\n\nWrite a function that takes a list of integers and returns a new list that contains all the prime numbers from the original list, in the same order they appeared. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Consider the rang...
0.698165
Apps_11903
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0cd7d5209e72b0a1059a74691233bb08695d0eb3
e621337c00ed8152a4b20f959970a1f6c9ed54f7
v1.0
complete
Apps
Apps_12360_C
def factorial(n: int) -> int: """ Computes the factorial of a non-negative integer n. """ pass def list_factorials(int_list: List[int]) -> List[int]: """ Takes a list of integers and returns a list with the factorial of each integer. >>> list_factorials([1, 2, 3]) [1, 2, 6] >>> list...
def factorial(n): """ Computes the factorial of a non-negative integer n. """ if n == 0 or n == 1: return 1 result = 1 for i in range(2, n + 1): result *= i return result def list_factorials(int_list): """ Takes a list of integers and returns a list with the factoria...
from solution import factorial, list_factorials, main def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(2) == 2 assert factorial(3) == 6 assert factorial(4) == 24 assert factorial(5) == 120 assert factorial(6) == 720 assert factorial(10) == 3628800...
[ { "docstring": "Computes the factorial of a non-negative integer n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a list with the factorial of each integer.", "function_declarat...
[ 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 factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n for i in range(2, n...
trial_gpt4o_9
{ "original_instruction": "=====Problem Statement=====\nWrite a function that takes a list of integers and returns a new list containing the factorial of each integer in the original list. Do not use any built-in factorial function.\n\n=====Example=====\nIf the input list is [1, 2, 3], the output list should be [1, 2...
0.724326
Apps_12360
C
[ "factorial", "list_factorials", "main" ]
3
[ [ "list_factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd0373a94960d955030911fcbe75c5871ae11ed7
e5ebbf6d67cf8e48b61cafe71399c2d91eeaa0f7
v1.0
complete
Apps
Apps_12267_C
from typing import List def largestNumber(nums: List[int]) -> str: """ Given a list of non-negative integers nums, arrange them in such a way that they form the largest possible number. >>> largestNumber([10, 2]) '210' >>> largestNumber([3, 30, 34, 5, 9]) '9534330' >>> largestNumber([0, 0, 0, 0...
from functools import cmp_to_key def custom_compare(x, y): if x + y > y + x: return -1 else: return 1 def largestNumber(nums): # Convert nums to strings so we can concatenate them nums = list(map(str, nums)) # Sort nums by the custom comparator nums.sort(key=cmp_to_key(cus...
from solution import largestNumber def test_largest_number_example1(): assert largestNumber([10, 2]) == "210" def test_largest_number_example2(): assert largestNumber([3, 30, 34, 5, 9]) == "9534330" def test_largest_number_single_digit(): assert largestNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == "987654321...
[ { "docstring": null, "function_declaration": "def custom_compare(x, y):", "function_name": "custom_compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largestNumber(nums):", "function_name": "largestNumber", "parameter_list": "(nums)" } ]
[ 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 ]
5
medium
0.5
{ "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 Given a list of non-negative integers nums, arrange them such that they form the large...
trial_gpt4o_8
{ "original_instruction": "Given a list of non-negative integers nums, you are tasked with arranging them in such a way that they form the largest possible number. To clarify, the arrangement of the integers should form a number (concatenation of strings) and this number should be the largest possible.\n\nYou should ...
0.749603
Apps_12267
C
[ "custom_compare", "largestNumber" ]
2
[ [ "largestNumber", "custom_compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
334a1bb7df903a60cb0824508406e229c7f5d705
43ff6957a0d9f7ca733386a59101e8c6ee867a34
v1.0
complete
Apps
Apps_12348_C
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def insert_into_bst(root, value): """ Helper function to insert a new value into the BST. """ pass def construct_bst(values): """ Construct a BST from the given list of values. ...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.ri...
from solution import construct_bst_and_get_sorted_list def test_empty_list(): assert construct_bst_and_get_sorted_list([]) == [] def test_single_element(): assert construct_bst_and_get_sorted_list([5]) == [5] def test_multiple_elements(): assert construct_bst_and_get_sorted_list([7, 3, 9, 1, 6, 8]) == [1...
[]
[ 1, 1, 1, 1, 1, 0, 1, 1, 0, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is...
trial_gpt4o_7
{ "original_instruction": "In the world of programming, efficient data structures are crucial for performance. One such data structure is the binary search tree (BST), which allows for fast lookups, insertions, and deletions. \n\nWrite a function that takes a list of integers and constructs a binary search tree (BST)...
0.524458
Apps_12348
C
[ "insert_into_bst", "construct_bst", "inorder_traversal", "bst_to_sorted_list", "construct_bst_and_get_sorted_list" ]
5
[ [ "bst_to_sorted_list", "inorder_traversal" ], [ "construct_bst", "insert_into_bst" ], [ "construct_bst_and_get_sorted_list", "bst_to_sorted_list" ], [ "construct_bst_and_get_sorted_list", "construct_bst" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2b587f6dabcb9c54415b6af88fbf977aa3641bef
1a86b169c08dc11030afdf81b498ba14cdf2a6f8
v1.0
complete
Apps
Apps_12446_C
def roman_to_int(roman: str) -> int: """ Convert a Roman numeral to an integer. >>> roman_to_int("III") 3 >>> roman_to_int("IV") 4 >>> roman_to_int("IX") 9 >>> roman_to_int("LVIII") 58 >>> roman_to_int("MCMXCIV") 1994 """ pass def sum_roman_numerals(roman_nu...
def roman_to_int(roman): """ 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 roman[::-1]: # Traverse the string in reverse value = roman_dict[char] if value < ...
from solution import roman_to_int, sum_roman_numerals def test_roman_to_int(): assert roman_to_int("III") == 3 assert roman_to_int("IV") == 4 assert roman_to_int("IX") == 9 assert roman_to_int("LVIII") == 58 assert roman_to_int("MCMXCIV") == 1994 def test_sum_roman_numerals(): assert sum_roman...
[ { "docstring": "Convert a Roman numeral to an integer.", "function_declaration": "def roman_to_int(roman):", "function_name": "roman_to_int", "parameter_list": "(roman)" }, { "docstring": "Convert a list of Roman numerals to their integer values and return their sum.", "function_declarat...
[ 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 roman_to_int(s):\n \"\"\"\n Converts a single Roman numeral string to an integer.\n \"\"\"\n roman_values = {\n 'I': 1, 'V': 5, 'X': 10, 'L':...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes a list of Roman numeral strings and returns the sum of the numeral values. Roman numerals are represented by the following symbols:\n\n```\nSymbol Value\nI 1\nV 5\nX 10\nL 50\nC 100\nD 500\nM...
0.692541
Apps_12446
C
[ "roman_to_int", "sum_roman_numerals" ]
2
[ [ "sum_roman_numerals", "roman_to_int" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a653e61d1f7779361740409d718aa0948affb89e
2901f3caf6d84884aed8069d0ba2107fb0ee36c3
v1.0
complete
Apps
Apps_12140_C
from typing import List def is_prime(num: int) -> bool: """ Helper function to check if a number is a prime number. """ def first_n_primes(n: int) -> List[int]: """ Returns a list of the first n prime numbers. Example: >>> first_n_primes(1) [2] >>> first_n_primes(2) [2, 3]...
def is_prime(num): """ Helper function to check 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: ...
from solution import first_n_primes def test_first_prime(): assert first_n_primes(1) == [2] def test_first_two_primes(): assert first_n_primes(2) == [2, 3] def test_first_five_primes(): assert first_n_primes(5) == [2, 3, 5, 7, 11] def test_first_ten_primes(): assert first_n_primes(10) == [2, 3, 5, 7...
[ { "docstring": "Helper function to check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of the first n prime numbers.", "function_declaration": "def first_n_primes(n):...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes an integer `n` and returns a list of the first `n` prime numbers.\n\nFor example, the first prime number is 2, the second is 3, the third is 5, and so on.\n\n``` \nNote:\n\n- 1 <= n <= 10**5\n```", "prompt_id": "00012140", "row_id": 12140, "seed_ids": "[462...
0.808545
Apps_12140
C
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10de636f0735889a20565b7b6394f69135dc4bb7
4d05a2a0a735a659d06a1c7fd65cfc4ff235f3a1
v1.0
complete
Apps
Apps_12113_C
def tally_votes(votes): """ Given a list of votes, return a dictionary with each candidate's vote tally. If the input list is empty, return an empty dictionary. """ pass def get_winner(votes): """ Given a list of votes, determine the winner based on the highest number of votes. If there...
def tally_votes(votes): """ Given a list of votes, return a dictionary with each candidate's vote tally. If the input list is empty, return an empty dictionary. """ tally = {} for vote in votes: if vote in tally: tally[vote] += 1 else: tally[vote] = 1 ...
from solution import tally_votes, get_winner def test_tally_votes_basic(): votes = ["Alice", "Bob", "Alice", "Eve", "Bob", "Alice"] expected = {'Alice': 3, 'Bob': 2, 'Eve': 1} assert tally_votes(votes) == expected def test_tally_votes_empty(): votes = [] expected = {} assert tally_votes(votes)...
[ { "docstring": "Given a list of votes, return a dictionary with each candidate's vote tally.\nIf the input list is empty, return an empty dictionary.", "function_declaration": "def tally_votes(votes):", "function_name": "tally_votes", "parameter_list": "(votes)" }, { "docstring": "Given a li...
[ 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 voting_system(votes):\n \"\"\"\n Simulates a simple voting system for an election with multiple candidates.\n \n Parameters:\n votes (list of str...
trial_gpt4o_9
{ "original_instruction": "Create a function that simulates a simple voting system for an election with multiple candidates. Given an array of strings where each string represents a vote for a candidate, return a dictionary with each candidate's name as a key and their corresponding vote count as the value. If two or...
0.654741
Apps_12113
C
[ "tally_votes", "get_winner" ]
2
[ [ "get_winner", "tally_votes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9b54050fbbe442c208c384fed7d072800aff268
8a389f3df6f543dd18bf6f6b60ce030e9d65ebb0
v1.0
complete
Apps
Apps_12249_C
from collections import deque import sys from typing import List, Tuple def shortest_time_for_guards_to_gather(N: int, M: int, graph: List[List[int]], K: int, starts: List[List[int]]) -> List[int]: """ Calculate the shortest time for K guards to gather in one city. Args: N (int): Number of cities. M (...
from collections import deque import sys def shortest_time_for_guards_to_gather(N, M, graph, K, starts): # Initialize distance matrix inf = sys.maxsize dist = [[inf] * N for _ in range(N)] # Update the distances using BFS for i in range(N): dist[i][i] = 0 q = deque([i]) ...
def test_shortest_time_for_guards_to_gather(): input_data = '''1 4 4 2 1 2 2 3 3 4 4 1 3 1 3 2 4 1 2''' expected_output = '''1 1 1''' results = find_min_time_for_guards_gathering(input_data) assert results == expected_output def test_case_with_only_two_cities(): input_data = '''1 2 1 2 1 2 1 1 2'''...
[ { "docstring": null, "function_declaration": "def shortest_time_for_guards_to_gather(N, M, graph, K, starts):", "function_name": "shortest_time_for_guards_to_gather", "parameter_list": "(N, M, graph, K, starts)" }, { "docstring": null, "function_declaration": "def process_input(input_dat...
[ 0, 1, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict\nfrom typing import List, Tuple\n\ndef dijkstra(start_nodes: List[int], n: int, adj_list: List[List[Tuple[int, int...
trial_gpt4o_1
{ "original_instruction": "In a faraway kingdom, there exist N cities connected by M roads. The ruler of the kingdom wants to create a special event where a selected city will be visited by exactly K guards. Each road is bidirectional and it takes 1 hour to travel from one city to another using any of the roads.\n\nT...
0.709706
Apps_12249
C
[ "shortest_time_for_guards_to_gather", "process_input", "find_min_time_for_guards_gathering" ]
3
[ [ "find_min_time_for_guards_gathering", "process_input" ], [ "process_input", "shortest_time_for_guards_to_gather" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
b2a99557323cf66642c640011768dd069dbe2e7a
40511d9f342112ee681d0540cd0827916248c523
v1.0
complete
Apps
Apps_12015_C
def fibonacci(n: int) -> int: """ Returns the nth Fibonacci number. >>> fibonacci(0) 0 >>> fibonacci(1) 1 >>> fibonacci(2) 1 >>> fibonacci(3) 2 >>> fibonacci(4) 3 """ def list_to_fibonacci_dict(lst: List[int]) -> Dict[int, int]: """ Given a list of non-negative integers, returns a d...
def fibonacci(n): """ Returns the nth Fibonacci number. """ if n == 0: return 0 elif n == 1: return 1 a, b = 0, 1 for _ in range(2, n+1): a, b = b, a + b return b def list_to_fibonacci_dict(lst): """ Given a list of non-negative integers, returns a d...
def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 def test_list_to_fibonacci_dict(): assert list_to_fibonacci_dict([0, 1, 2, 3, 4]) == {0: 0, 1: 1, 2: 1, 3: 2, 4: 3} ...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Given a list of non-negative integers, returns a dictionary where the keys are the integers\nand the values are the corres...
[ 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 fibonacci(n):\n if n < 0:\n raise ValueError(\"Input list contains negative integers\")\n elif n == 0:\n return 0\n elif n == 1:\n ...
trial_gpt4o_9
{ "original_instruction": "Write a function in Python that takes a list of integers and returns a dictionary where the keys are the integers from the list and the values are the corresponding Fibonacci numbers. Ensure that the integers in the input list are non-negative. If the input list contains any negative intege...
0.752169
Apps_12015
C
[ "fibonacci", "list_to_fibonacci_dict" ]
2
[ [ "list_to_fibonacci_dict", "fibonacci" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fd9e5db21d79b7d05f15bba91c602b73414c377a
5d5594a3c001b651a711efedb2331970d5d29a9f
v1.0
complete
Apps
Apps_12211_C
def brute_force_paths(grid, m, n, i=0, j=0): """ Recursively count the number of distinct paths in the grid using brute force. """ def dp_paths(grid, m, n): """ Use dynamic programming to count the number of distinct paths in the grid. """ def count_paths(test_cases): """ Given multipl...
def brute_force_paths(grid, m, n, i=0, j=0): """ Recursively count the number of distinct paths in the grid using brute force. """ # If out of bounds or blocked cell if i >= m or j >= n or grid[i][j] == 1: return 0 # If we reached the bottom-right corner if i == m-1 and j == n-1: ...
import pytest from solution import brute_force_paths, dp_paths, count_paths def test_sample_case(): test_cases = [ ([[0, 0, 0], [0, 1, 0], [0, 0, 0]], 3, 3) ] results = count_paths(test_cases) assert results == [(2, 2)] def test_blocked_start(): test_cases = [ ([[1, 0, 0], [0, 1, 0...
[ { "docstring": "Recursively count the number of distinct paths in the grid using brute force.", "function_declaration": "def brute_force_paths(grid, m, n, i=0, j=0):", "function_name": "brute_force_paths", "parameter_list": "(grid, m, n, i=0, j=0)" }, { "docstring": "Use dynamic programming ...
[ 1, 1, 0, 1, 0, 1, 0, 0, 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 count_paths_brute_force(grid, m, n, i=0, j=0, memo=None):\n if memo is None:\n memo = {}\n \n if i >= m or j >= n or grid[i][j] == 1:\n ...
trial_gpt4o_5
{ "original_instruction": "You are given a rectangular grid of size `m x n` where each cell can either be `0` (empty) or `1` (blocked). Your task is to determine the number of distinct paths from the top-left corner to the bottom-right corner, moving only right or down, using Dynamic Programming.\n\nYou will solve th...
0.610811
Apps_12211
C
[ "brute_force_paths", "dp_paths", "count_paths" ]
3
[ [ "count_paths", "brute_force_paths" ], [ "count_paths", "dp_paths" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ee14e4ba8557cd7ff1f4482760af2e5460a891d1
3166d32fcd238acf43df808798c4e45ac5ce017a
v1.0
complete
Apps
Apps_12555_C
def convex_hull(points): """ Returns the points that make up the convex hull of a set of 2D points. The points are returned in counter-clockwise order starting from the leftmost point. >>> convex_hull([(0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (3, 1)]) [(0, 0), (2, 0), (3, 1), (2, 2), (1, 2)] >>> co...
def cross_product(o, a, b): """ Calculates the cross product of vectors OA and OB. A positive cross product indicates a counter-clockwise turn. """ return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) def convex_hull(points): """ Returns the points that make up the convex hu...
from solution import convex_hull def test_convex_hull_basic(): points = [(0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (3, 1)] result = convex_hull(points) expected = [(0, 0), (2, 0), (3, 1), (2, 2), (1, 2)] assert result == expected def test_convex_hull_with_collinear_points(): points = [(0, 0), (1, 1)...
[ { "docstring": "Calculates the cross product of vectors OA and OB.\nA positive cross product indicates a counter-clockwise turn.", "function_declaration": "def cross_product(o, a, b):", "function_name": "cross_product", "parameter_list": "(o, a, b)" }, { "docstring": "Returns the points that...
[ 0, 0, 0, 0, 1, 1, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convex_hull(points):\n \"\"\"\n Computes the Convex Hull of a given set of points using Graham's Scan algorithm.\n \n :param points: List of tuples,...
trial_gpt4o_5
{ "original_instruction": "Max loves convex shapes and geometry. He recently stumbled upon the notion of Convex Hulls and became fascinated by them. Given a set of points in a 2D plane, he wants to find the Convex Hull of these points.\n\nThe Convex Hull of a set of 2D points is the smallest convex polygon that conta...
0.541131
Apps_12555
C
[ "cross_product", "convex_hull" ]
2
[ [ "convex_hull", "cross_product" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a1784591540ed2e680bc602f220a86d35e9871b
da018d9697511b5c4665d528acceefdc18dacd68
v1.0
complete
Apps
Apps_12304_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, else False. >>> is_prime(1) == False >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(17) == True >>> is_prime(18) == False """ def countPrimeSetBi...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i...
from solution import countPrimeSetBits, is_prime 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(17) == True assert is_prime(18) == False def test_countPrimeSetBits...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Counts how many numbers between start and end inclusive have a prime number of set bits in binary representat...
[ 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": "def countPrimeSetBits(start, end):\n \"\"\"\n Returns the count of numbers in the range [start, end] that have a prime number of set bits.\n \"\"\"\n de...
trial_gpt4o_2
{ "original_instruction": "You are given two integers `start` and `end` representing a range of integers [start, end]. Your task is to determine how many numbers within this range have prime number of set bits (1-bits) in their binary representation. To assist, design a function `countPrimeSetBits(start, end)`. The f...
0.7438
Apps_12304
C
[ "is_prime", "countPrimeSetBits" ]
2
[ [ "countPrimeSetBits", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a0240a55afb7ff8aff39c543ae72b29472216d5
023d6e51320fff14e948450843594aa1819d9aa7
v1.0
complete
Apps
Apps_12627_C
def calculate_word_score(word: str) -> int: """ Calculate the score of a word based on alphabetical values of its letters. >>> calculate_word_score("hello") 52 >>> calculate_word_score("world") 72 >>> calculate_word_score("abc") 6 >>> calculate_word_score("cba") 6 >>> calcula...
def calculate_word_score(word): """ Calculate the score of a word based on alphabetical values of its letters. """ return sum(ord(char) - ord('a') + 1 for char in word) def highest_scoring_word(test_cases): """ Determine the highest scoring word(s) from a list of test cases. For each test c...
from solution import calculate_word_score, highest_scoring_word def test_calculate_word_score(): assert calculate_word_score("hello") == 52 assert calculate_word_score("world") == 72 assert calculate_word_score("abc") == 6 assert calculate_word_score("cba") == 6 assert calculate_word_score("a") == ...
[ { "docstring": "Calculate the score of a word based on alphabetical values of its letters.", "function_declaration": "def calculate_word_score(word):", "function_name": "calculate_word_score", "parameter_list": "(word)" }, { "docstring": "Determine the highest scoring word(s) from a list of ...
[ 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": "def highest_scoring_words(test_cases):\n def word_score(word):\n return sum(ord(char) - ord('a') + 1 for char in word)\n\n results = []\n for words ...
trial_gpt4o_2
{ "original_instruction": "Write a program that calculates the highest scoring word(s) from a list of words based on their alphabetical value.\n\nEach word's score is determined by summing the positional values of its letters (a=1, b=2, ... z=26). The program should find the word(s) with the highest score and return ...
0.72686
Apps_12627
C
[ "calculate_word_score", "highest_scoring_word", "main" ]
3
[ [ "highest_scoring_word", "calculate_word_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56e84b79bb4a90493e101b5d6c552e75c43c4ce2
944ed45a429009e573972491a47d7aab4fc36e3b
v1.0
complete
Apps
Apps_12678_C
def can_form_by_deleting(s: str, word: str) -> bool: """ Check if `word` can be formed from `s` by deleting some characters without rearranging the remaining characters. """ it = iter(s) return all(char in it for char in word) def find_longest_word(s: str, words: List[str]) -> int: """ Find...
def can_form_by_deleting(s, word): """ Check if `word` can be formed from `s` by deleting some characters without rearranging the remaining characters. """ it = iter(s) return all(char in it for char in word) def find_longest_word(s, words): """ Find the length of the longest word in `words...
from solution import find_longest_word def test_example_1(): assert find_longest_word("abpcplea", ["ale","apple","monkey","plea"]) == 5 def test_example_2(): assert find_longest_word("abpcplea", ["a","b","c"]) == 1 def test_example_3(): assert find_longest_word("abcdef", ["gh", "i", "jkl"]) == 0 def tes...
[ { "docstring": "Check if `word` can be formed from `s` by deleting some characters without rearranging the remaining characters.", "function_declaration": "def can_form_by_deleting(s, word):", "function_name": "can_form_by_deleting", "parameter_list": "(s, word)" }, { "docstring": "Find the ...
[ 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 can_form(s, word):\n \"\"\"\n Check if we can form 'word' by deleting some characters from 's' without rearranging the remaining characters.\n \"\"\"\n...
trial_gpt4o_9
{ "original_instruction": "Given a string s of lowercase English letters and a list of words. Find the length of the longest word in the list that can be formed by deleting some characters of the given string s without rearranging the remaining characters.\n\nReturn the length of the longest word in the list that can...
0.757017
Apps_12678
C
[ "can_form_by_deleting", "find_longest_word" ]
2
[ [ "find_longest_word", "can_form_by_deleting" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d56465382bae63125a5b839290457d223de5d868
eb728b0bfa891386db1c4706afd65954b50e9ab2
v1.0
complete
Apps
Apps_12406_C
from typing import List, Tuple def parse_input(data: str) -> List[List[List[Tuple[int, int]]]]: """ Parse the input data for the bird waypoint tracking problem. Args: data (str): The input data as a string. Returns: List[List[List[Tuple[int, int]]]]: The parsed data as a list of test ...
def longest_increasing_sequence(observations): """ Find the length of the longest increasing sequence of waypoints based on the observations of a single bird. """ observations.sort() dp = [1] * len(observations) for i in range(1, len(observations)): for j in range(i): if ...
from solution import longest_increasing_sequence, longest_sequence_for_all_birds def test_longest_increasing_sequence(): assert longest_increasing_sequence([(1, 2), (2, 3), (3, 4)]) == 3 assert longest_increasing_sequence([(1, 5), (2, 3), (3, 2), (4, 1)]) == 1 assert longest_increasing_sequence([(10, 12), ...
[ { "docstring": "Find the length of the longest increasing sequence\nof waypoints based on the observations of a single bird.", "function_declaration": "def longest_increasing_sequence(observations):", "function_name": "longest_increasing_sequence", "parameter_list": "(observations)" }, { "do...
[ 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 longest_increasing_subsequence(observations):\n \"\"\"\n Helper function to find the longest increasing subsequence based on the waypoint numbers.\n \n...
trial_gpt4o_4
{ "original_instruction": "A group of biologists is studying the migratory patterns of a certain species of birds. They have tracked the birds across different waypoints and logged observations for each bird at various timestamps during their journey. The goal is to determine the longest continuous sequence of waypoi...
0.551179
Apps_12406
C
[ "longest_increasing_sequence", "longest_sequence_for_all_birds", "parse_input" ]
3
[ [ "longest_sequence_for_all_birds", "longest_increasing_sequence" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
584598efe33838a51589a89e9f57cf194a599667
61118cd990cd1b21291eef14ab76a8a10feef927
v1.0
complete
Apps
Apps_12828_C
def preprocess_string(input_str: str) -> str: """ Preprocess the string by removing non-alphanumeric characters and converting to lowercase. >>> preprocess_string("A man, a plan, a canal, Panama!") "amanaplanacanalpanama" >>> preprocess_string("No lemon, no melon") "nolemonnomelon" >>> preprocess_string...
def preprocess_string(input_str: str) -> str: """ Preprocess the string by removing non-alphanumeric characters and converting to lowercase. """ return ''.join(char.lower() for char in input_str if char.isalnum()) def is_palindrome(input_str: str) -> bool: """ Determine if the given input strin...
from solution import preprocess_string, is_palindrome def test_preprocess_string(): assert preprocess_string("A man, a plan, a canal, Panama!") == "amanaplanacanalpanama" assert preprocess_string("No lemon, no melon") == "nolemonnomelon" assert preprocess_string("Hello, World!") == "helloworld" def test_i...
[ { "docstring": "Preprocess the string by removing non-alphanumeric characters and converting to lowercase.", "function_declaration": "def preprocess_string(input_str):", "function_name": "preprocess_string", "parameter_list": "(input_str)" }, { "docstring": "Determine if the given input stri...
[ 1, 0, 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": "import re\n\ndef preprocess_string(input_str: str) -> str:\n \"\"\"\n Remove non-alphanumeric characters from the string and convert to lowercase.\n \n ...
trial_gpt4o_9
{ "original_instruction": "A palindrome is a string that reads the same forward and backward, ignoring spaces, punctuation, and case. Write two functions that work together to determine if a given input string is actually a palindrome.\n\n1. The first function should preprocess the string, removing any non-alphanumer...
0.887601
Apps_12828
C
[ "preprocess_string", "is_palindrome" ]
2
[ [ "is_palindrome", "preprocess_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ab3b0557beeca7ab3b2463f685dc6056ad3afee
7ade19baee4d2200aef7028545f97de66982f4e1
v1.0
complete
Apps
Apps_12298_C
def schedule_tasks(n: int, D: int, N: int, tasks: List[int]) -> Tuple[str, Optional[List[int]]]: """ Determines if it is possible to schedule tasks without exceeding daytime and nighttime limits. Returns "YES" and a valid schedule if possible, otherwise returns "NO". >>> schedule_tasks(4, 10, 12, [3, 4...
def schedule_tasks(n, D, N, tasks): """ Determines if it is possible to schedule tasks without exceeding daytime and nighttime limits. Returns "YES" and a valid schedule if possible, otherwise returns "NO". """ day_tasks = [] night_tasks = [] day_total = 0 night_total = 0 def backtr...
def test_schedule_tasks(): # Test case 1 input_data = "4 10 12\n3 4 6 8" output_data = "YES\n0 1 0 1" assert wrapper_schedule_tasks(input_data) == output_data # Test case 2 input_data = "3 5 6\n4 5 3" output_data = "NO" assert wrapper_schedule_tasks(input_data) == output_data # Tes...
[ { "docstring": "Determines if it is possible to schedule tasks without exceeding daytime and nighttime limits.\nReturns \"YES\" and a valid schedule if possible, otherwise returns \"NO\".", "function_declaration": "def schedule_tasks(n, D, N, tasks):", "function_name": "schedule_tasks", "parameter_l...
[ 0, 0, 1, 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": "def can_schedule_tasks(n, D, N, durations):\n \"\"\"\n Determine if it's possible to schedule all tasks within the given day and night duration limits.\n \...
trial_gpt4o_2
{ "original_instruction": "You have been assigned to develop a scheduling algorithm for a new project. Your team is given n tasks to complete, each with a specific duration. Each task can either be scheduled during the day or during the night. The day and night times have different limitations on the total duration o...
0.518552
Apps_12298
C
[ "schedule_tasks", "wrapper_schedule_tasks" ]
2
[ [ "wrapper_schedule_tasks", "schedule_tasks" ] ]
1
[]
false
[]
false
pytest
false
[]
true
48d8284c3a3c4127b5457e111a6de7e555688d5a
b87395b6ad95d70c24cf85b84a1fc3e1f42c45fe
v1.0
complete
Apps
Apps_12521_C
from collections import deque from typing import List def is_one_letter_diff(s1: str, s2: str) -> bool: """ Checks whether strings s1 and s2 differ by exactly one letter """ pass def shortest_transformation_length(s: str, t: str, dict: List[str]) -> int: """ Determines the length of the shortest tran...
from collections import deque def is_one_letter_diff(s1, s2): """ Checks whether strings s1 and s2 differ by exactly one letter """ if len(s1) != len(s2): return False diff_count = sum(1 for a, b in zip(s1, s2) if a != b) return diff_count == 1 def shortest_transformation_length(s, t, dict): ...
from solution import shortest_transformation_length def test_example1(): s = "hit" t = "cog" dict = ["hot","dot","dog","lot","log"] assert shortest_transformation_length(s, t, dict) == 0 def test_example2(): s = "hit" t = "cog" dict = ["hot","dot","dog","lot","log", "cog"] assert short...
[ { "docstring": "Checks whether strings s1 and s2 differ by exactly one letter ", "function_declaration": "def is_one_letter_diff(s1, s2):", "function_name": "is_one_letter_diff", "parameter_list": "(s1, s2)" }, { "docstring": "Determines the length of the shortest transformation sequence fro...
[ 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": "from collections import deque\n\ndef ladderLength(s, t, word_dict):\n def all_variants(word):\n variants = set()\n for i in range(len(word)):\n ...
trial_gpt4o_7
{ "original_instruction": "Given a string s and a list of words dict, determine the length of the shortest transformation sequence from s to a target word t (where t is any word in dict), such that:\n\n1. Only one letter can be changed at a time.\n2. Each transformed word must exist in the list of words dict or be th...
0.650115
Apps_12521
C
[ "is_one_letter_diff", "shortest_transformation_length" ]
2
[ [ "shortest_transformation_length", "is_one_letter_diff" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e0ea2188d5d0ad95cda6737d9bab4ad6fb5043b7
5ab60f56588c35b8d7a0b4c5808f3181aa8ac198
v1.0
complete
Apps
Apps_12803_C
from typing import List def filter_primes(numbers: List[int]) -> List[int]: """ Returns a list of prime numbers filtered from the input list. If the length of the input list is greater than 10, the resulting list is sorted in ascending order. """ pass def test_example_cases(): assert filte...
def is_prime(n): """ Helper function to check if a number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_prim...
from solution import filter_primes def test_example_cases(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] assert filter_primes([12, 15, 18, 19, 23, 28, 29, 32, 33, 37, 41]) == [19, 23, 29, 37, 41] def test_empty_list(): assert filter_primes([]) == [] def test_no_primes(): assert...
[ { "docstring": "Helper function to check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers filtered from the input list.\nIf the length of the input list is greater tha...
[ 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": "def is_prime(n):\n \"\"\"\n Checks whether a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n...
trial_gpt4o_6
{ "original_instruction": "You are given a list of numbers. You are to return a new list which contains only the prime numbers from the original list. However, if the length of the list is greater than 10 elements, you must sort the final list of prime numbers in ascending order before returning it. \n\nPrimary Const...
0.701677
Apps_12803
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae93d3ccc39cb45646aa35d05e168b1995ddee12
17746f680d3030fcf8498ab4e4de1ea8b5ff4a45
v1.0
complete
Apps
Apps_12333_C
def count_peaks(arr: List[int], x: int, y: int) -> int: """ Counts the number of peaks in the subarray from index x to index y (inclusive). """ count = 0 for i in range(x, y - 1): if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]: count += 1 return count def sum_peaks(arr: Lis...
def count_peaks(arr, x, y): """ Counts the number of peaks in the subarray from index x to index y (inclusive). """ count = 0 for i in range(x, y - 1): if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]: count += 1 return count def sum_peaks(arr, x, y): """ Calculates th...
def test_count_peaks(): arr = [1, 5, 3, 7, 4, 8, 2, 6] assert count_peaks(arr, 1, 6) == 2 assert count_peaks(arr, 0, 8) == 3 assert count_peaks(arr, 2, 5) == 1 def test_sum_peaks(): arr = [1, 5, 3, 7, 4, 8, 2, 6] assert sum_peaks(arr, 1, 6) == 12 assert sum_peaks(arr, 0, 8) == 20 assert...
[ { "docstring": "Counts the number of peaks in the subarray from index x to index y (inclusive).", "function_declaration": "def count_peaks(arr, x, y):", "function_name": "count_peaks", "parameter_list": "(arr, x, y)" }, { "docstring": "Calculates the sum of peaks in the subarray from index x...
[ 1, 0, 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": "def count_peaks(arr, x, y):\n count = 0\n for i in range(x, y-1):\n if arr[i] > arr[i-1] and arr[i] > arr[i+1]:\n count += 1\n return cou...
trial_gpt4o_6
{ "original_instruction": "Sara loves to climb mountains, and she has become particularly fond of a mountain range that is represented as an array of integers, where each integer represents the height of a peak. This mountain range has several peaks and she wants to analyze these peaks based on different criteria. \n...
0.758502
Apps_12333
C
[ "count_peaks", "sum_peaks", "process_queries" ]
3
[ [ "process_queries", "count_peaks" ], [ "process_queries", "sum_peaks" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
561487aa04c2726920c05af0ea3565e8fb247470
921e738b4a687383a27bf4e73112e1d8c52986d7
v1.0
complete
Apps
Apps_12870_C
def word_search(grid: List[List[str]], words: List[str]) -> List[bool]: """Given a two-dimensional grid of characters and a list of words, find if each word in the list exists in the grid. A word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are horizontally or vert...
def exist(board, word): rows, cols = len(board), len(board[0]) def backtrack(r, c, index): if index == len(word): return True if r < 0 or r >= rows or c < 0 or c >= cols or board[r][c] != word[index]: return False # mark the cell as visited by tempor...
from solution import word_search def test_word_search_example1(): grid = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']] words = ['ABCCED', 'SEE', 'ABCB'] assert word_search(grid, words) == [True, True, False] def test_word_search_single_letter_grid(): grid =...
[ { "docstring": null, "function_declaration": "def exist(board, word):", "function_name": "exist", "parameter_list": "(board, word)" }, { "docstring": null, "function_declaration": "def word_search(grid, words):", "function_name": "word_search", "parameter_list": "(grid, words)" ...
[ 0, 1, 0, 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": "def exist(grid, word):\n rows, cols = len(grid), len(grid[0])\n \n def dfs(r, c, i):\n if i == len(word):\n return True\n if r < 0...
trial_gpt4o_4
{ "original_instruction": "## Task\nYou have been given a two-dimensional grid of characters, and a list of words. Your task is to find if each word in the list exists in the grid. A word can be constructed from letters of sequentially adjacent cells, where \"adjacent\" cells are horizontally or vertically neighborin...
0.627097
Apps_12870
C
[ "exist", "word_search" ]
2
[ [ "word_search", "exist" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98acc8bb4b200523267038f3b4060a05e9e642bc
8440ae00d6cb65fff87fbeb3c96fb440063f61e6
v1.0
complete
Apps
Apps_12651_C
def generate_pascals_triangle(n: int) -> List[List[int]]: """ Generates the first n rows of Pascal's triangle. :param n: The number of rows. :return: A list of lists containing the first n rows of Pascal's triangle. """ def generate_and_print_pascals_triangle(test_cases: List[int]) -> str:...
def generate_pascals_triangle(n): """ Generates first n rows of Pascal's triangle. :param n: The number of rows. :return: A list of lists containing the first n rows of Pascal's triangle. """ triangle = [] for i in range(n): row = [1] * (i + 1) for j in range(1, i): ...
import pytest from solution import generate_pascals_triangle, generate_and_print_pascals_triangle def test_generate_pascals_triangle(): assert generate_pascals_triangle(1) == [[1]] assert generate_pascals_triangle(2) == [[1], [1, 1]] assert generate_pascals_triangle(3) == [[1], [1, 1], [1, 2, 1]] asser...
[ { "docstring": "Generates first n rows of Pascal's triangle.\n\n:param n: The number of rows.\n:return: A list of lists containing the first n rows of Pascal's triangle.", "function_declaration": "def generate_pascals_triangle(n):", "function_name": "generate_pascals_triangle", "parameter_list": "(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 generate_pascals_triangle(N):\n \"\"\"\n Generates the first N rows of Pascal's Triangle.\n \"\"\"\n triangle = []\n \n for i in range(N):\n ...
trial_gpt4o_9
{ "original_instruction": "You are given an integer $N$. Your task is to generate the first $N$ rows of Pascal's Triangle.\n\nPascal's Triangle is defined as follows:\n- The topmost row is numbered as row 0 and has a single element, 1.\n- Each subsequent row has one more element than the previous row.\n- The elements...
0.584927
Apps_12651
C
[ "generate_pascals_triangle", "generate_and_print_pascals_triangle" ]
2
[ [ "generate_and_print_pascals_triangle", "generate_pascals_triangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
82923ea27be38ce0f2f465b1e5d40ce369fb3c53
a6a5cfefc12c0ff1d69ec86fd1da50f141906fa2
v1.0
complete
Apps
Apps_12964_C
def is_binary_palindrome(number): """ Returns True if the binary representation of 'number' is a palindrome, False otherwise. >>> is_binary_palindrome(3) == True # 3 -> '11' >>> is_binary_palindrome(5) == True # 5 -> '101' >>> is_binary_palindrome(6) == False # 6 -> '110' >>> is_binary_p...
def is_binary_palindrome(number): """ Returns True if the binary representation of 'number' is a palindrome, False otherwise. """ binary_str = bin(number)[2:] # Convert to binary and remove '0b' prefix return binary_str == binary_str[::-1] def binary_palindrome_tuples(integers): """ Return...
from solution import binary_palindrome_tuples, is_binary_palindrome def test_is_binary_palindrome(): assert is_binary_palindrome(3) == True # 3 -> '11' assert is_binary_palindrome(5) == True # 5 -> '101' assert is_binary_palindrome(6) == False # 6 -> '110' assert is_binary_palindrome(9) == True # 9...
[ { "docstring": "Returns True if the binary representation of 'number' is a palindrome, False otherwise.", "function_declaration": "def is_binary_palindrome(number):", "function_name": "is_binary_palindrome", "parameter_list": "(number)" }, { "docstring": "Returns a list of tuples where each ...
[ 1, 0, 1, 1, 1, 0, 1, 0, 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 binary_palindrome(lst):\n \"\"\"\n Given a list of integers, return a list of tuples where each tuple contains the original integer\n and a boolean ind...
trial_gpt4o_6
{ "original_instruction": "Create a function that takes a list of integers as input and returns a list of tuples. Each tuple will contain two elements:\n\n1. The original integer.\n2. A boolean that is True if the integer is a palindrome in its binary representation, and False otherwise.\n\nA palindrome is a sequence...
0.702661
Apps_12964
C
[ "is_binary_palindrome", "binary_palindrome_tuples" ]
2
[ [ "binary_palindrome_tuples", "is_binary_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c79220467c31e1470f26a7cef993043cda70ed0
de2d062e797f445b6cd6ef2ca207661a8135e6ac
v1.0
complete
Apps
Apps_13130_C
def digit_sum(n): """ Returns the sum of the digits of the given number. """ return sum(int(digit) for digit in str(n)) def is_smith_number(n): """ Determines if a number is a Smith number. >>> is_smith_number(58) True >>> is_smith_number(22) True >>> is_smith_number(4) ...
def digit_sum(n): """ Returns the sum of the digits of the given number. """ return sum(int(digit) for digit in str(n)) def is_smith_number(n): """ Determines if a number is a Smith number. """ def prime_factors(n): """ Returns the list of prime factors of the given numb...
import pytest from solution import is_smith_number def test_is_smith_number_58(): assert is_smith_number(58) == True def test_is_smith_number_22(): assert is_smith_number(22) == True def test_is_smith_number_4(): assert is_smith_number(4) == True def test_is_smith_number_7(): assert is_smith_number(...
[ { "docstring": "Returns the sum of the digits of the given number.", "function_declaration": "def digit_sum(n):", "function_name": "digit_sum", "parameter_list": "(n)" }, { "docstring": "Determines if a number is a Smith number.", "function_declaration": "def is_smith_number(n):", "f...
[ 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": "def digit_sum(n):\n \"\"\"\n Calculate the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef prime_factors(n):...
trial_gpt4o_6
{ "original_instruction": "A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors (excluding 1). For example, in base 10, the number '58' is a Smith number because:\n\n- Its prime factorization is 2 × 29.\n- The sum of its digits: 5 + 8 = 13.\n- The sum of the digi...
0.677007
Apps_13130
C
[ "digit_sum", "is_smith_number" ]
2
[ [ "is_smith_number", "digit_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5843c6d366928c18d3c493e4901ebe64a8dd0ae5
822792dddfa0ed9c2c0c07e35aa5a9541eed8438
v1.0
complete
Apps
Apps_12975_C
def is_mountain_sequence(s: str) -> bool: """ Check if a given string s is a valid mountain sequence. A mountain sequence is defined as a sequence with at least three elements where it strictly increases to a peak and then strictly decreases. Args: s (str): The string representing growth ra...
def is_mountain_sequence(s): """ Check if a given string s is a valid mountain sequence. """ n = len(s) if n < 3: return False peak_reached = False i = 1 # Ascend to the peak while i < n and s[i] > s[i - 1]: i += 1 # Peak must not be at the beginnin...
def test_is_mountain_sequence(): assert is_mountain_sequence("123") == False assert is_mountain_sequence("12321") == True assert is_mountain_sequence("123321") == False assert is_mountain_sequence("121") == True def test_can_partition_into_mountains(): assert can_partition_into_mountains("12343...
[ { "docstring": "Check if a given string s is a valid mountain sequence.", "function_declaration": "def is_mountain_sequence(s):", "function_name": "is_mountain_sequence", "parameter_list": "(s)" }, { "docstring": "Check if the string can be partitioned into valid mountain sequences.", "f...
[ 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": "def is_mountain_sequence(s, start, end):\n if end - start + 1 < 3:\n return False\n\n peak = start\n # Find the peak\n for i in range(start + 1, ...
trial_gpt4o_6
{ "original_instruction": "Eliza is a botanist tracking the growth patterns of multiple plants. One day, she comes up with a challenge to analyze the health of these plants. Given a string representing the growth rate of plants over several days, she wants to identify if there is a way to partition this string into c...
0.564355
Apps_12975
C
[ "is_mountain_sequence", "can_partition_into_mountains", "analyze_growth_patterns" ]
3
[ [ "analyze_growth_patterns", "can_partition_into_mountains" ], [ "can_partition_into_mountains", "is_mountain_sequence" ] ]
2
[]
false
[]
false
pytest
false
[]
true
f1eb1349b5e943ed1ce813e2a750c43468e9bcac
0623a1e47e339ef8943d7e75bdf4a60bed15c11d
v1.0
complete
Apps
Apps_13085_C
def look_and_say(n: int) -> str: """ Returns the nth term in the Look-and-say sequence. >>> look_and_say(1) '1' >>> look_and_say(2) '11' >>> look_and_say(3) '21' >>> look_and_say(4) '1211' >>> look_and_say(5) '111221' """ # You can use the 'next_term' helper function....
def look_and_say(n: int) -> str: """ Returns the nth term in the Look-and-say sequence. """ if n <= 0: raise ValueError("Input must be a positive integer") term = "1" for _ in range(1, n): term = next_term(term) return term def next_term(term: str) -> str: ...
def test_look_and_say_base_case(): assert look_and_say(1) == "1" def test_look_and_say_second_term(): assert look_and_say(2) == "11" def test_look_and_say_third_term(): assert look_and_say(3) == "21" def test_look_and_say_fourth_term(): assert look_and_say(4) == "1211" def test_look_and_say_fifth_te...
[ { "docstring": "Returns the nth term in the Look-and-say sequence.", "function_declaration": "def look_and_say(n):", "function_name": "look_and_say", "parameter_list": "(n)" }, { "docstring": "Generates the next term in the Look-and-say sequence from the current term.", "function_declara...
[ 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 look_and_say(n: int) -> str:\n \"\"\"\n Returns the nth term in the Look-and-say sequence.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must ...
trial_gpt4o_9
{ "original_instruction": "Implement a function that processes a list of integers in the \"Look-and-say\" sequence. The Look-and-say sequence is a sequence in which each term is given by describing the previous term. For example, the sequence starts with \"1\", which is read off as \"one 1\" or \"11\" in the second t...
0.588375
Apps_13085
C
[ "look_and_say", "next_term" ]
2
[ [ "look_and_say", "next_term" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ea4c66d2ff51e597a01f9328db76a170a3d33952
7b7860fdfe8b13e203a21a7e7a7f73c7be936f80
v1.0
complete
Apps
Apps_13032_C
from typing import List def meetingTime(speeds: List[int]) -> int: """ Returns the time in seconds when the two fastest runners will meet again at the starting point. Parameters: speeds (list of int): List of speeds of the runners in meters per second. Returns: int: Time in seconds w...
import math def lcm(a, b): """ Returns the least common multiple of two integers a and b. """ return abs(a*b) // math.gcd(a, b) def meetingTime(speeds): """ Returns the time in seconds when the two fastest runners will meet again at the starting point. Parameters: speeds (list of ...
from solution import meetingTime def test_meetingTime_case1(): assert meetingTime([5, 4, 3, 2]) == 20 def test_meetingTime_case2(): assert meetingTime([6, 8, 3]) == 24 def test_meetingTime_case3(): assert meetingTime([10, 15, 20]) == 60 def test_meetingTime_case4(): assert meetingTime([7, 14, 28]) =...
[ { "docstring": "Returns the least common multiple of two integers a and b.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the time in seconds when the two fastest runners will meet again at the starting point.\n\nPara...
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\nfrom typing import List\n\ndef lcm(a: int, b: int) -> int:\n \"\"\"\n Helper function to compute the Least Common Multip...
trial_gpt4o_9
{ "original_instruction": "You are organizing a charity run event, and athletes will run on a circular track. Each athlete has a different constant speed, and you need to determine the time at which the two fastest runners meet again at the starting point, assuming they start from the same point at the same time.\n\n...
0.561044
Apps_13032
C
[ "lcm", "meetingTime" ]
2
[ [ "meetingTime", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
85d37231c044ee39e61fdb820d814d8ec1dae4d7
4acf1db210c43a773f5a35beef2d13d379000eaa
v1.0
complete
Apps
Apps_12959_C
import math from typing import List def is_strong_number(num: int) -> bool: """ Determines whether the given number is a strong number. >>> is_strong_number(1) == True >>> is_strong_number(2) == True >>> is_strong_number(145) == True >>> is_strong_number(154) == False """ def find_stro...
import math def is_strong_number(num): """ Determines whether the given number is a strong number. """ return num == sum(math.factorial(int(digit)) for digit in str(num)) def find_strong_numbers(a, b): """ Returns a list of strong numbers within the given range [a, b]. """ return [x fo...
from solution import is_strong_number, find_strong_numbers def test_is_strong_number(): assert is_strong_number(1) == True assert is_strong_number(2) == True assert is_strong_number(145) == True assert is_strong_number(154) == False def test_find_strong_numbers_small_range(): assert find_strong_nu...
[ { "docstring": "Determines whether the given number is a strong number.", "function_declaration": "def is_strong_number(num):", "function_name": "is_strong_number", "parameter_list": "(num)" }, { "docstring": "Returns a list of strong numbers within the given range [a, b].", "function_de...
[ 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": "import math\n\ndef is_strong_number(num):\n \"\"\"\n Returns True if num is a strong number, else False.\n \"\"\"\n original_num = num\n sum_of_facto...
trial_gpt4o_9
{ "original_instruction": "Aman is learning about the concept of strong numbers. A strong number is a special number whose sum of the factorial of digits is equal to the original number. For example, 145 is a strong number because 1! + 4! + 5! = 145. \n\nAman's teacher has given him the task to find all strong number...
0.589209
Apps_12959
C
[ "is_strong_number", "find_strong_numbers" ]
2
[ [ "find_strong_numbers", "is_strong_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
007dfc5d683ee872644d9d96828f551756452d18
4ae50cae7cb83cb67815d4f251609e8248f769dd
v1.0
complete
Apps
Apps_12980_C
def min_max_normalize(numbers): """ This function normalizes a list of numbers using min-max normalization. >>> min_max_normalize([1, 2, 3, 4, 5]) [0.00, 0.25, 0.50, 0.75, 1.00] >>> min_max_normalize([1000, 2000, 3000, 10000]) [0.00, 0.11, 0.22, 1.00] >>> min_max_normalize([5,...
def min_max_normalize(numbers): """ This function normalizes a list of numbers using min-max normalization. """ min_val = min(numbers) max_val = max(numbers) # Handling the case where max and min are the same to avoid division by zero if max_val == min_val: return [0.00] * len(n...
import pytest from solution import min_max_normalize, read_input_and_normalize def test_min_max_normalize_simple_case(): assert min_max_normalize([1, 2, 3, 4, 5]) == [0.00, 0.25, 0.50, 0.75, 1.00] def test_min_max_normalize_with_large_numbers(): assert min_max_normalize([1000, 2000, 3000, 10000]) == [0.00, 0....
[ { "docstring": "This function normalizes a list of numbers using min-max normalization.", "function_declaration": "def min_max_normalize(numbers):", "function_name": "min_max_normalize", "parameter_list": "(numbers)" }, { "docstring": "Reads the input text, processes the numbers, and prints ...
[ 1, 1, 1, 1, 1, 0, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_max_normalize(data_points):\n \"\"\"\n Normalize a list of data points using min-max normalization.\n\n Args:\n data_points (list of int): List ...
trial_gpt4o_9
{ "original_instruction": "In this problem, you are required to normalize a list of numbers for statistical analysis. Normalization transforms the data to a standard scale without distorting differences in the ranges of values. For this exercise, you will use min-max normalization.\n\nThe formula for min-max normaliz...
0.655597
Apps_12980
C
[ "min_max_normalize", "read_input_and_normalize" ]
2
[ [ "read_input_and_normalize", "min_max_normalize" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a0efd09dcf767592077c15e456101cd0dc38db4
988773fd0298a94cf0cf1ab6334c579859fc619d
v1.0
complete
Apps
Apps_13178_C
def largest_clear_path_rectangle(grid, N, M): """ Determine the maximum size of the largest clear path rectangle that does not contain any trees within the grid. Args: - grid (List[str]): A list of strings representing the grid with '1' as trees and '0' as empty cells. - N (int): Number of rows in ...
def largest_clear_path_rectangle(grid, N, M): if N == 0 or M == 0: return 0, 0 # Initialize the lookup table for dynamic programming dp = [[0] * M for _ in range(N)] # Initialize variables to keep track of the maximum rectangle max_area = 0 max_rows = 0 max_cols = 0 # ...
from solution import largest_clear_path_rectangle, parse_input, solve_largest_clear_path_rectangle, main def test_largest_clear_path_rectangle(): grid = ['011', '001', '111'] assert largest_clear_path_rectangle(grid, 3, 3) == (1, 1) grid = ['0000', '0010', '0010', '0000'] assert largest_clear_path...
[ { "docstring": null, "function_declaration": "def largest_clear_path_rectangle(grid, N, M):", "function_name": "largest_clear_path_rectangle", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def parse_input(input_text):", "function_name": "parse_inpu...
[ 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": "def largest_clear_path_rectangle(t, test_cases):\n \"\"\"\n Determine the maximum size of the largest clear path rectangle that does not contain any trees wit...
trial_gpt4o_4
{ "original_instruction": "You are given a grid with N$N$ rows and M$M$ columns, where each cell is either empty or contains a tree. A \"tree\" is represented by a cell with the value 1, and an \"empty\" cell is represented by the value 0. You can walk from one cell to another if and only if there is a clear path con...
0.590704
Apps_13178
C
[ "largest_clear_path_rectangle", "parse_input", "solve_largest_clear_path_rectangle", "main" ]
4
[ [ "solve_largest_clear_path_rectangle", "largest_clear_path_rectangle" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
dc7cef493b2a9878aa0d8d0ca18bfb93d24a8225
c1cdf50e1f60bb02dd26b4e1f8e6a03a752aa09d
v1.0
complete
Apps
Apps_13308_C
def twin_prime_count(n: int) -> int: """ Returns the number of twin prime pairs less than or equal to n. If the input is not a positive integer or is less than 2, returns "Not valid". >>> twin_prime_count(10) == 2 >>> twin_prime_count(17) == 3 >>> twin_prime_count(30) == 4 >>> twin_prime_cou...
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...
from solution import twin_prime_count def test_twin_prime_count(): assert twin_prime_count(10) == 2 # (3, 5) and (5, 7) assert twin_prime_count(17) == 3 # (3, 5), (5, 7), (11, 13) assert twin_prime_count(30) == 4 # (3, 5), (5, 7), (11, 13), (17, 19) assert twin_prime_count(1) == "Not valid" 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 the number of twin prime pairs less than or equal to n.", "function_declaration": "def twin_pri...
[ 0, 0, 0, 0, 1, 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 for i in range(3, int(n *...
trial_gpt4o_9
{ "original_instruction": "A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A twin prime is a prime number that is either 2 less or 2 more than another prime number, for example, (11, 13), (17, 19), and (29, 31). A twin prime consists of two prime numbers with a...
0.651817
Apps_13308
C
[ "is_prime", "twin_prime_count" ]
2
[ [ "twin_prime_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96e2dd4832f3f3e5e6abd4fbf9204fd044ed2db9
bfd19234ed19cfbbf25b67a17eb48df3397f9bf4
v1.0
complete
Apps
Apps_13249_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ pass def sum_of_digits(n: int) -> int: """ Return the sum of the digits of a number. >>> sum_of_digits(123) 6 >>...
def is_prime(n): if n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_digits(n): return sum(int(digit) for digit in str(n)) def average_of_non_zero_digits(n): digits = [int(digit) for digit in str(n) if int(digi...
import pytest from solution import transform_list, is_prime, sum_of_digits, average_of_non_zero_digits, product_of_digits def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(19) == True assert is_prime(20) == False def test_sum_of_...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": null,...
[ 1, 0, 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": "def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\...
trial_gpt4o_0
{ "original_instruction": "Implement a function that takes a list of integers and returns a new list where each integer is replaced based on the following rules:\n\n1. If the integer is prime, replace it with the sum of its digits.\n2. If the integer is even but not prime, replace it with the average of its non-zero ...
0.686126
Apps_13249
C
[ "is_prime", "sum_of_digits", "average_of_non_zero_digits", "product_of_digits", "transform_list" ]
5
[ [ "transform_list", "average_of_non_zero_digits" ], [ "transform_list", "is_prime" ], [ "transform_list", "product_of_digits" ], [ "transform_list", "sum_of_digits" ] ]
4
[]
false
[]
false
pytest
true
[]
true
53ae1a8bc776565eff8b58915f610163507735ea
9452b9b052457c9f1a061a79c803ffa472a5191f
v1.0
complete
Apps
Apps_13328_C
def is_prime(n: int) -> bool: """ Returns True if n is a prime number, otherwise False. >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(11) True >>> is_prime(1) False >>> is_prime(-3) False """ def sum_primes(lst: List[int]) -> int: """ Returns the sum of all...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def su...
from solution import sum_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(-3) == False def test_sum_primes(): assert sum_primes([2, 3, 5, 7, 11, 13...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all unique prime numbers in the given list of integers.", "function_declaration":...
[ 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 <= 3:\n return T...
trial_gpt4o_6
{ "original_instruction": "Write a function to identify and sum all unique prime numbers in a given list of integers. The input list will not contain any repeating numbers, and all elements will be valid integers.\n\n```python\nsum_primes([2, 3, 5, 7, 11, 13]) # => 41\nsum_primes([4, 6, 8, 10, 12]) ...
0.734992
Apps_13328
C
[ "is_prime", "sum_primes" ]
2
[ [ "sum_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1003f86664dd02e57adf5a759836fa0a054f4708
df799803140a94b9f6bc9d6cd90e122d4f969299
v1.0
complete
Apps
Apps_13374_C
import math from typing import List def is_prime(n: int) -> bool: """ Check if a number n is a prime number. >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(17) True >>> is_prime(18) False """ def sum_of_primes(nums: List[int]) -> int: """ Returns the sum of all prime n...
import math def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def su...
from solution import is_prime, sum_of_primes, process_input 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(17) == True assert is_prime(18) == False def test_sum_of_primes(): assert sum_o...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the list nums.", "function_declaration": "def sum_of_primes(nums):", "f...
[ 1, 1, 1, 1, 1, 1, 1, 0, 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 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_5
{ "original_instruction": "Given a list of integers, write a program to find the sum of all prime numbers in the list.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of test cases. Then follow T lines, each line contains a list of space-separated integers.\n\n-----Output-----\n\nFor each...
0.74578
Apps_13374
C
[ "is_prime", "sum_of_primes", "process_input" ]
3
[ [ "process_input", "sum_of_primes" ], [ "sum_of_primes", "is_prime" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
32d118c8bc0069c775c52fbf9e2be8450bc8bba0
36dd26aa8992ee38cff7b7d4b475eaa32e62fe66
v1.0
complete
Apps
Apps_12960_C
from typing import List, Tuple def optimal_drone_route(grid_size: Tuple[int, int], start_point: Tuple[int, int], target_points: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]: """ Computes the optimal route for a single drone to visit all specified target points and return to the starting point in...
from itertools import permutations def manhattan_distance(p1, p2): return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) def optimal_drone_route(grid_size, start_point, target_points): points = [start_point] + target_points n = len(points) # Calculate the distance matrix dist = [[0] * n for _ in ran...
from solution import optimal_drone_route def test_single_target_point(): grid_size = (4, 4) start_point = (0, 0) target_points = [(1, 1)] assert optimal_drone_route(grid_size, start_point, target_points) == (4, [(0, 0), (1, 1), (0, 0)]) def test_multiple_target_points(): grid_size = (4, 4) sta...
[ { "docstring": null, "function_declaration": "def manhattan_distance(p1, p2):", "function_name": "manhattan_distance", "parameter_list": "(p1, p2)" }, { "docstring": null, "function_declaration": "def optimal_drone_route(grid_size, start_point, target_points):", "function_name": "opt...
[ 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": "from itertools import permutations\n\ndef calculate_manhattan_distance(p1, p2):\n \"\"\"\n Calculate the Manhattan distance between two points.\n \"\"\"\n ...
trial_gpt4o_4
{ "original_instruction": "A company is designing a fleet of autonomous drones that need to patrol a rectangular area divided into a grid of cells. Each cell is represented by a pair of coordinates `[x, y]`. The drones collect data in key locations and must visit all target cells efficiently.\n\nYou are to write a fu...
0.558088
Apps_12960
C
[ "manhattan_distance", "optimal_drone_route" ]
2
[ [ "optimal_drone_route", "manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff0e7b52b6af9c7bc9a01aea2f52b05f8276dd8b
9d2c5a97c92a0e6f6554b6840dd2e50f74550773
v1.0
complete
Apps
Apps_13282_C
def maximalRectangle(grid): """ Find the largest rectangular area of consecutive '1's in a given binary grid. Args: grid: List of List of str: 2D binary grid where each element is '1' or '0'. Returns: int: The area of the largest rectangle containing only '1's. Example: >>> maximalRect...
def maximalRectangle(grid): if not grid or not grid[0]: return 0 num_rows = len(grid) num_cols = len(grid[0]) max_area = 0 heights = [0] * num_cols for row in grid: for col in range(num_cols): if row[col] == '1': heights[col] += 1 else: ...
from solution import maximalRectangle def test_example(): grid = [ ["1", "0", "1", "0", "0"], ["1", "0", "1", "1", "1"], ["1", "1", "1", "1", "1"], ["1", "0", "0", "1", "0"] ] assert maximalRectangle(grid) == 6 def test_smallest_grid_with_1(): grid = [["1"]] assert ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(grid):", "function_name": "maximalRectangle", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_li...
[ 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 maximalRectangle(grid):\n if not grid or not grid[0]:\n return 0\n \n def maximalHistArea(heights):\n stack = []\n max_area = 0\n ...
trial_gpt4o_8
{ "original_instruction": "In a remote village, there is an ancient festival that requires villagers to arrange lanterns in a specific pattern. The lanterns are arranged in a grid, and each cell in the grid contains one lantern that can either be on ('1') or off ('0'). The aim of the villagers is to determine the lar...
0.683396
Apps_13282
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db9bc38ffb19c41a340b8004f3559504e5b032e9
3a66072f87772195c4b1509ab5e81a4655d9556c
v1.0
complete
Apps
Apps_13354_C
def sieve_of_eratosthenes(max_num): """ Function to create a boolean array where True represents that the index is a prime number. """ pass # Implement the sieve of Eratosthenes algorithm here def generate_prime_binary_arrays(T, test_cases): """ Function to generate the prime binary arrays fo...
def sieve_of_eratosthenes(max_num): """ Function to create a boolean array where True represents that the index is a prime number. """ is_prime = [True] * (max_num + 1) is_prime[0], is_prime[1] = False, False p = 2 while p * p <= max_num: if is_prime[p]: for i in ran...
def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0] assert sieve_of_eratosthenes(5) == [0, 0, 1, 1, 0, 1] def test_generate_prime_binary_arrays(): assert generate_prime_binary_arrays(2, [10, 5]) == [ "0 0 1 1 0 1 0 1 0 0 0", "0 0 1 1 0 1" ...
[ { "docstring": "Function to create a boolean array where True represents that the index is a prime number.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Function to generate the prim...
[ 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": "def sieve_of_eratosthenes(max_n):\n \"\"\"\n Returns a list where index i contains 1 if i is a prime number and 0 otherwise.\n Uses the Sieve of Eratosthen...
trial_gpt4o_7
{ "original_instruction": "Alex has recently learned about prime numbers and wants to create a binary array that indicates whether a number is prime or not. Given a number $N$, he needs to construct a binary array of length $N+1$ (i.e., indexed from 0 to $N$), where each position $i$ in the array will have the value ...
0.602436
Apps_13354
C
[ "sieve_of_eratosthenes", "generate_prime_binary_arrays" ]
2
[ [ "generate_prime_binary_arrays", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8b29952babbdaa8fdd1be118ae411c017aec6e89
79fc08168ed5d632d5927d3d3dca5c22218c762d
v1.0
complete
Apps
Apps_13474_C
class Node: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_info): nodes = {} for i, (value, left, right) in enumerate(node_info): if i not in nodes: nodes[i] = Node(value) if left != -1: no...
class Node: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(node_info): nodes = {} for i, (value, left, right) in enumerate(node_info): if i not in nodes: nodes[i] = Node(value) if left != -1: no...
from solution import maximum_sum_on_path def test_sample_case(): N = 5 node_info = [ (3, 1, 2), (4, -1, -1), (5, 3, 4), (7, -1, -1), (6, -1, -1) ] assert maximum_sum_on_path(N, node_info) == 15 def test_single_node(): N = 1 node_info = [ (10, -1,...
[]
[ 0, 1, 0, 0, 0, 1, 1, 0, 1, 1 ]
5
medium
0.5
{ "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.left = None\n self.right = None\n \ndef max_sum_path(root):\n ...
trial_gpt4o_8
{ "original_instruction": "Given a binary tree, you need to find the maximum sum of the values of nodes on any path from the root node to a leaf node.\n\nA binary tree is a tree data structure where each node has at most two children. Each node contains an integer value. You can traverse the tree starting from the ro...
0.64781
Apps_13474
C
[ "build_tree", "find_max_sum", "maximum_sum_on_path" ]
3
[ [ "maximum_sum_on_path", "build_tree" ], [ "maximum_sum_on_path", "find_max_sum" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
3b5fafbb43760b9b0f3a80bc4f430155d177f6f5
7a0aba39e04c9ffdfb76e1179a00dd3850fe5523
v1.0
complete
Apps
Apps_13086_C
def max_subsequence_length(s, words): """ Given a string s and an array of strings words, return the maximum length of a subsequence of s that is also a subsequence of a string in words. >>> max_subsequence_length("abcde", ["a", "bb", "acd", "ace"]) 3 >>> max_subsequence_length("abcdefg", [...
def is_subsequence(s, word): """Helper function to check if 'word' is a subsequence of 's'.""" it = iter(s) return all(char in it for char in word) def max_subsequence_length(s, words): """ Given a string s and an array of strings words, return the maximum length of a subsequence of s that is a...
from solution import max_subsequence_length def test_example_1(): assert max_subsequence_length("abcde", ["a", "bb", "acd", "ace"]) == 3 def test_example_2(): assert max_subsequence_length("abcdefg", ["abc", "def", "gh", "cde"]) == 3 def test_example_3(): assert max_subsequence_length("xyz", ["a", "b", "...
[ { "docstring": "Helper function to check if 'word' is a subsequence of 's'.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Given a string s and an array of strings words, return the maximum length ...
[ 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_subsequence(sub, s):\n \"\"\"\n Helper function to check if `sub` is a subsequence of `s`.\n \"\"\"\n iter_s = iter(s)\n return all(char in it...
trial_gpt4o_9
{ "original_instruction": "Given a string `s` and an array of strings `words`, return the maximum length of a subsequence of `s` that is also a subsequence of a string in `words`.\n\nA subsequence is defined as a sequence that can be derived from another sequence by deleting some elements without changing the order o...
0.753972
Apps_13086
C
[ "is_subsequence", "max_subsequence_length" ]
2
[ [ "max_subsequence_length", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ebc3f5f2e49ea4a42d927c4ea183fa11ba8fae7
9e9ef9206bb283963b40c1f4ec09fdeef33e5ff2
v1.0
complete
Apps
Apps_13599_C
import os def get_current_timestamp(): # This helper function is assumed to exist and return a formatted timestamp pass def log_event(event_description): """Logs an event to the 'event_log.txt' file with a timestamp. Each log entry should be written on a new line and follow this format: [YYYY...
import os def get_current_timestamp(): from datetime import datetime return datetime.now().strftime("%Y-%m-%d %H:%M:%S") def log_event(event_description): try: timestamp = get_current_timestamp() log_entry = f"[{timestamp}] - {event_description}\n" with open("event_log.txt...
import os from unittest.mock import patch from solution import log_event def test_log_event_file_creation(): if os.path.exists("event_log.txt"): os.remove("event_log.txt") log_event("Test Event Creation") assert os.path.exists("event_log.txt") def test_log_event_entry_format(): with patch('so...
[ { "docstring": null, "function_declaration": "def get_current_timestamp():", "function_name": "get_current_timestamp", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def log_event(event_description):", "function_name": "log_event", "parameter_list": "(eve...
[ 1, 0, 1, 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": "import os\n\ndef get_current_timestamp():\n \"\"\"\n This helper function is assumed to exist and return a formatted timestamp.\n In a real scenario, this ...
trial_gpt4o_8
{ "original_instruction": "You are working on a system that needs to log events to a file for auditing purposes. Each event is represented as a string, and every log entry should include a timestamp indicating when the event occurred.\n\nDesign a function that logs an event to a file named \"event_log.txt\". Each log...
0.701922
Apps_13599
C
[ "get_current_timestamp", "log_event" ]
2
[ [ "log_event", "get_current_timestamp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5cd228fc239f6f381a0991f43bc528fda9a0c4b8
edf3f2e48fda712128d97544eb84b7a158a655cc
v1.0
complete
Apps
Apps_13572_C
from typing import List def can_rotate_to_match(gridA: List[List[int]], gridB: List[List[int]]) -> bool: """ Determines if gridA can be transformed into gridB by rotating it 90 degrees clockwise any number of times (0, 1, 2, or 3 times). >>> gridA = [ ... [1, 2], ... [3, 4] ... ] >...
from typing import List def rotate_90_clockwise(grid: List[List[int]]) -> List[List[int]]: """ Rotates the grid 90 degrees clockwise. """ n = len(grid) new_grid = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): new_grid[j][n - 1 - i] = grid[i][j] return...
from solution import can_rotate_to_match def test_no_rotation_needed(): gridA = [ [1, 2], [3, 4] ] gridB = [ [1, 2], [3, 4] ] assert can_rotate_to_match(gridA, gridB) == True def test_one_rotation(): gridA = [ [1, 2], [3, 4] ] gridB = [ ...
[ { "docstring": "Rotates the grid 90 degrees clockwise.", "function_declaration": "def rotate_90_clockwise(grid):", "function_name": "rotate_90_clockwise", "parameter_list": "(grid)" }, { "docstring": "Determines if gridA can be transformed into gridB by rotating it\n90 degrees clockwise any ...
[ 1, 0, 0, 1, 1, 0, 0, 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": "from typing import List\n\ndef rotate_90(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Rotates the given n x n grid 90 degrees clockwise.\n \"\"\"\...
trial_gpt4o_9
{ "original_instruction": "**Grid Rotation Check**\n\nYou will receive two n x n integer grids `gridA` and `gridB`. Your task is to determine if `gridA` can be transformed into `gridB` by rotating it 90 degrees clockwise any number of times (0, 1, 2, or 3 times).\n\nEach grid contains only positive integers and will ...
0.602321
Apps_13572
C
[ "rotate_90_clockwise", "can_rotate_to_match" ]
2
[ [ "can_rotate_to_match", "rotate_90_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
097a361ef99fa3458fb2314874fdd1baec05bb56
9796a6b2e02bd25680d7966edf6b2c00aa7d9d0b
v1.0
complete
Apps
Apps_13613_C
from typing import List, Tuple def min_tree_types(n: int, m: int, edges: List[Tuple[int, int]]) -> Tuple[int, List[int]]: """ Determine the minimum number of different tree types required and the possible assignment of tree types to parks. >>> min_tree_types(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]) (2,...
from collections import deque def min_tree_types(n, m, edges): graph = [[] for _ in range(n)] # Build the adjacency list for u, v in edges: graph[u - 1].append(v - 1) graph[v - 1].append(u - 1) color = [-1] * n def bfs(start): queue = deque([start]) co...
def test_beautify_parks(): test_cases = [ (4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]), (3, 2, [(1, 2), (2, 3)]) ] expected_outputs = [ (2, [1, 2, 1, 2]), (2, [1, 2, 1]) ] results = solve_beautify_parks(test_cases) for result, expected in zip(results, expect...
[ { "docstring": null, "function_declaration": "def min_tree_types(n, m, edges):", "function_name": "min_tree_types", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def solve_beautify_parks(test_cases):", "function_name": "solve_beautify_parks", ...
[ 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": "from collections import defaultdict, deque\n\ndef min_tree_types(T, test_cases):\n results = []\n\n for _ in range(T):\n n, m, edges = test_cases[_]\n ...
trial_gpt4o_4
{ "original_instruction": "The city council is planning to beautify city parks by planting trees. There are `n` parks in the city, and some pairs of parks are connected by bidirectional roads. To maximize the beauty, the council wants to plant a tree in each park such that no two adjacent parks (i.e., parks connected...
0.554186
Apps_13613
C
[ "min_tree_types", "solve_beautify_parks" ]
2
[ [ "solve_beautify_parks", "min_tree_types" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a5d3bac3dd6f3cd2b45fc5bf743c85e7ee3bd906
4600b344906800686981fcd5af0222c8a7e11cea
v1.0
complete
Apps
Apps_13629_C
from typing import List, Tuple def exist(board: List[List[str]], word: str) -> bool: """ Given a grid of letters and a word, determine whether the word can be formed by sequentially adjacent letters in the grid (left, right, up, or down), without reusing any letter cell. """ pass def word_search(t...
def exist(board, word): def dfs(board, word, i, j, word_index): if word_index == len(word): return True if i < 0 or i >= len(board) or j < 0 or j >= len(board[0]) or board[i][j] != word[word_index]: return False temp = board[i][j] board[i][j] = "#" ...
from solution import word_search, parse_input def test_single_case(): input_string = "1\n3 4\na b c e\ns f c s\na d e e\n3\nabcced see sexe" test_cases = parse_input(input_string) result = word_search(test_cases) assert result == ["YES", "YES", "NO"] def test_multiple_cases(): input_string = ( ...
[ { "docstring": null, "function_declaration": "def exist(board, word):", "function_name": "exist", "parameter_list": "(board, word)" }, { "docstring": null, "function_declaration": "def word_search(test_cases):", "function_name": "word_search", "parameter_list": "(test_cases)" }...
[ 0, 0, 0, 0, 0, 1, 1, 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 exist(board, word):\n def dfs(i, j, k):\n if not (0 <= i < len(board) and 0 <= j < len(board[0])):\n return False\n if board[i][j] !...
trial_gpt4o_9
{ "original_instruction": "Given a grid of letters and a list of words, determine whether each word in the list can be formed by sequentially adjacent letters in the grid, such as left, right, up, or down, without reusing any letter cell.\n\n-----Input-----\nThe first line contains an integer T denoting the total num...
0.648688
Apps_13629
C
[ "exist", "word_search", "parse_input" ]
3
[ [ "word_search", "exist" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
2f5631fea478f2ab636c8bf4a67de587f63d0b24
274dbd38b4bc33a94544d98aae016fa2de64b816
v1.0
complete
Apps
Apps_13662_C
from typing import List def minimize_max_sum(arr: List[int], k: int) -> int: """ Write a function that takes a list of integers and groups them into a specified number of contiguous sublists such that the maximum sum of any sublist is minimized. Your function should return this minimized maximum sum. ...
def can_split(nums, k, max_sum): current_sum = 0 needed_splits = 1 for num in nums: if current_sum + num > max_sum: needed_splits += 1 current_sum = num if needed_splits > k: return False else: current_sum += num ...
from solution import minimize_max_sum def test_minimize_max_sum_example(): assert minimize_max_sum([7, 2, 5, 10, 8], 2) == 18 def test_minimize_max_sum_one_element(): assert minimize_max_sum([1], 1) == 1 def test_minimize_max_sum_all_equal_elements(): assert minimize_max_sum([5, 5, 5, 5], 2) == 10 as...
[ { "docstring": null, "function_declaration": "def can_split(nums, k, max_sum):", "function_name": "can_split", "parameter_list": "(nums, k, max_sum)" }, { "docstring": null, "function_declaration": "def minimize_max_sum(arr, k):", "function_name": "minimize_max_sum", "parameter_l...
[ 0, 0, 0, 0, 0, 1, 1, 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 minimize_max_sum(arr, k):\n \"\"\"\n This function takes a list of integers and groups them into a specified number\n of contiguous sublists such that ...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes a list of integers and groups them into a specified number of contiguous sublists such that the maximum sum of any sublist is minimized. Your function should return this minimized maximum sum.\n\nFor example, if you have the list [7, 2, 5, 10, 8] and you want to ...
0.690468
Apps_13662
C
[ "can_split", "minimize_max_sum" ]
2
[ [ "minimize_max_sum", "can_split" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7dcd2a296ace19c7ce85e2b8bafe3e8ca21ceb2c
78f386699dcc0ca4bc5c8573607443f5c8988cf7
v1.0
complete
Apps
Apps_13760_C
def merge_intervals(intervals): """ Merge overlapping intervals and return a list of merged intervals. Intervals is a list of tuples (start, end). """ pass def calculate_total_hours(entries): """ Calculate the total working hours for each employee. Entries is a dictionary with employee ...
def merge_intervals(intervals): """ Merge overlapping intervals and return a list of merged intervals. Intervals is a list of tuples (start, end). """ if not intervals: return [] # Sort intervals by start time intervals.sort() merged = [intervals[0]] for curren...
from solution import calculate_total_hours, merge_intervals def test_merge_intervals(): assert merge_intervals([(9, 12), (14, 17), (11, 13)]) == [(9, 13), (14, 17)] assert merge_intervals([(10, 13), (13, 16)]) == [(10, 16)] assert merge_intervals([(9, 10), (12, 14)]) == [(9, 10), (12, 14)] assert merge...
[ { "docstring": "Merge overlapping intervals and return a list of merged intervals.\nIntervals is a list of tuples (start, end).", "function_declaration": "def merge_intervals(intervals):", "function_name": "merge_intervals", "parameter_list": "(intervals)" }, { "docstring": "Calculate the to...
[ 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_total_hours(entries):\n def merge_intervals(intervals):\n if not intervals:\n return []\n\n # Sort intervals based on star...
trial_gpt4o_9
{ "original_instruction": "# Introduction\n\nA company has assigned you the task of improving their daily operations by automating the report generation process. Currently, they have a system that stores employee timesheet entries, and they need an end-of-day report summarizing each employee's total hours worked.\n\n...
0.568969
Apps_13760
C
[ "merge_intervals", "calculate_total_hours" ]
2
[ [ "calculate_total_hours", "merge_intervals" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce6444c298a5f0e62eda6ff1b9fe615132fe2600
f927bc68702fd3114856fc1ef44a535821304535
v1.0
complete
Apps
Apps_13638_C
import re from typing import List def convert_snake_to_camel(snake_str: str) -> str: """ Converts a snake_case string to camelCase string. >>> convert_snake_to_camel("create_user") "createUser" >>> convert_snake_to_camel("get_user_details") "getUserDetails" >>> convert_snake_to_camel("update") "update"...
import re def convert_snake_to_camel(snake_str): """ Converts a snake_case string to camelCase string. """ parts = snake_str.split('_') camel_str = parts[0] + ''.join(word.capitalize() for word in parts[1:]) return camel_str def refactor_script(script_lines): """ Refactors the given li...
def test_convert_snake_to_camel(): assert convert_snake_to_camel("create_user") == "createUser" assert convert_snake_to_camel("get_user_details") == "getUserDetails" assert convert_snake_to_camel("update") == "update" assert convert_snake_to_camel("save_user_data_locally") == "saveUserDataLocally" def ...
[ { "docstring": "Converts a snake_case string to camelCase string.", "function_declaration": "def convert_snake_to_camel(snake_str):", "function_name": "convert_snake_to_camel", "parameter_list": "(snake_str)" }, { "docstring": "Refactors the given list of script lines by converting all metho...
[ 1, 0, 0, 1, 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": "import re\n\ndef convert_snake_to_camel(snake_str):\n \"\"\"\n Converts a snake_case string to camelCase string.\n \"\"\"\n parts = snake_str.split('_')...
trial_gpt4o_0
{ "original_instruction": "A programming company intends to evaluate the efficiency of their code refactoring tool. The company will provide a script consisting of multiple methods, and they need to identify and refactor all method invocations to follow a new naming convention. Specifically, all method names must be ...
0.564626
Apps_13638
C
[ "convert_snake_to_camel", "refactor_script", "refactor_scripts" ]
3
[ [ "refactor_script", "convert_snake_to_camel" ], [ "refactor_scripts", "refactor_script" ] ]
2
[]
false
[]
false
pytest
false
[]
true
9411b98db1eb68faa0ef4f12a8604bb211a9d43e
84cdd339cc3776629bf34a0bf954cdfd2294b365
v1.0
complete
Apps
Apps_13956_C
from typing import List def is_prime(n: int) -> bool: """Returns True if n is a prime number, otherwise False.""" if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sort_p...
from solution import sort_primes_first def test_prime_and_non_prime_mix(): assert sort_primes_first([10, 3, 5, 2, 8, 13, 4, 6]) == [3, 5, 2, 13, 10, 8, 4, 6] def test_all_primes(): assert sort_primes_first([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_all_non_primes(): assert sort_primes_first([4, 6, 8,...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Sort the list such that all prime numbers appear before non-prime numbers\nwhile maintaining relative or...
[ 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 prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ...
trial_gpt4o_9
{ "original_instruction": "You are given a list of integers. Write a function to sort this list such that all prime numbers appear before all non-prime numbers, while maintaining the relative order of prime numbers and relative order of non-prime numbers from the original list.\n\nHere is the step-by-step explanation...
0.702635
Apps_13956
C
[ "is_prime", "sort_primes_first" ]
2
[ [ "sort_primes_first", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
447efe8625be3b0f392f6865d542b4edb209037d
830593ff2acd5e3ffb9467c6f85cea9d9d1e45f0
v1.0
complete
Apps
Apps_14020_C
from typing import List 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(17) == True >>> is_prime(18) == False """ def filter_prime_numbers(lst: List[int]) -> List[int]: """ Given a list ...
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_prime_numbers(lst): """ Returns a list containing only the prime numbers from the original list...
from solution import is_prime, filter_prime_numbers def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_filter_prime_numbers(): assert filter_prime_numbers([2, 3, 4, 5, 6]) == [...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the original list.", "function_declaration": "def filter_prime_numbers(l...
[ 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 Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n r...
trial_gpt4o_9
{ "original_instruction": "Given a list of integers, return a new list containing only the prime numbers found in the original list, maintaining their original order.\n\nThe list will never be empty and you do not need to account for non-integer values.", "prompt_id": "00014020", "row_id": 14020, "seed_ids": "[...
0.757663
Apps_14020
C
[ "is_prime", "filter_prime_numbers" ]
2
[ [ "filter_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07cfc4dd341a5b0ddc6444b3c2beb0e53a25eb42
ac6764374a9284c4edcc1d3844021ca2a8f89b82
v1.0
complete
Apps
Apps_14086_C
from typing import List def find_longest_word(words: List[str]) -> str: """ Implement a function that takes a list of words and finds the longest word that can be made from the combination of other words in the list. Each word in the list can only be used once and it cannot be constructed from the current wor...
def can_construct(word, word_set, original_word): if word in word_set and word != original_word: return True for i in range(1, len(word)): prefix = word[:i] suffix = word[i:] if prefix in word_set and can_construct(suffix, word_set, original_word): return True ret...
from solution import find_longest_word def test_example_case(): assert find_longest_word(["rat", "cat", "cats", "dog", "catsdog"]) == "catsdog" def test_no_constructible_word(): assert find_longest_word(["apple", "banana", "cherry"]) == "" def test_single_word(): assert find_longest_word(["apple"]) == ""...
[ { "docstring": null, "function_declaration": "def can_construct(word, word_set, original_word):", "function_name": "can_construct", "parameter_list": "(word, word_set, original_word)" }, { "docstring": null, "function_declaration": "def find_longest_word(words):", "function_name": "f...
[ 0, 0, 0, 0, 0, 1, 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_longest_word(words):\n \"\"\"\n Finds the longest word in the list that can be made from other words in the list.\n \"\"\"\n word_set = set(wor...
trial_gpt4o_5
{ "original_instruction": "**Task**\n Implement a function that takes a list of words and finds the longest word that can be made from the combination of other words in the list. Each word in the list can only be used once and it cannot be constructed from the current word itself.\n\n**Example**\n\nFor the input `w...
0.80324
Apps_14086
C
[ "can_construct", "find_longest_word" ]
2
[ [ "find_longest_word", "can_construct" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d60682f99771c4078e88a7e130c8f6ff63ddb21
f43b87e419fab0017c17e9b80926b37451e7be1a
v1.0
complete
Apps
Apps_13908_C
import heapq from typing import List, Tuple def min_max_diff(grid: List[List[int]], n: int, m: int) -> int: """ Determine the minimum possible maximum absolute difference in heights between any two consecutive cells for a path from (1, 1) to (n, m). >>> min_max_diff([[1, 3], [4, 2]], 2, 2) 2 >>> m...
import heapq def min_max_diff(grid, n, m): directions = [(0, 1), (1, 0)] max_diff = [[float('inf')] * m for _ in range(n)] max_diff[0][0] = 0 heap = [(0, 0, 0)] while heap: diff, x, y = heapq.heappop(heap) if (x, y) == (n - 1, m - 1): return diff for dx...
from solution import parse_input, solve def test_example_one(): input_string = "2\n2 2\n1 3\n4 2\n3 3\n8 5 9\n7 3 6\n2 4 1\n" t, test_cases = parse_input(input_string) expected = [2, 3] assert solve(t, test_cases) == expected def test_single_cell(): input_string = "1\n1 1\n0\n" t, test_cases =...
[ { "docstring": null, "function_declaration": "def min_max_diff(grid, n, m):", "function_name": "min_max_diff", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve(t, test_cases):", "function_name": "solve", "parameter_list": "(t, test_cases...
[ 0, 0, 0, 0, 1, 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": "import heapq\n\ndef min_max_path_difference(test_cases):\n results = []\n \n for grid in test_cases:\n n = len(grid)\n m = len(grid[0])\n ...
trial_gpt4o_6
{ "original_instruction": "You are given a grid with $n$ rows and $m$ columns. Each cell of the grid contains an integer value which represents the height of that cell. You need to find the path from the top-left corner $(1, 1)$ to the bottom-right corner $(n, m)$ such that the maximum absolute difference in heights ...
0.645238
Apps_13908
C
[ "min_max_diff", "solve", "parse_input" ]
3
[ [ "solve", "min_max_diff" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
9ba3e5f47689a5362c46aff597c081854f9706de
51ae41b79fa2282b9c9f70a20a656d1c638181ae
v1.0
complete
Apps
Apps_14147_C
from typing import List def extract_primes(arr: List[int]) -> List[int]: """ Write a function that accepts an array of integers and returns a new array containing only the prime numbers from the input array, preserving the original order. A prime number is a number greater than 1 that has no positive divi...
from typing import List def is_prime(n: int) -> bool: """ Check if a given number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for divisor in range(3, max_divisor, 2): if n % divi...
from solution import extract_primes def test_extract_primes_basic(): assert extract_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_extract_primes_all_primes(): assert extract_primes([11, 13, 17, 19, 22, 23, 25, 28, 29]) == [11, 13, 17, 19, 23, 29] def test_extract_primes_no_primes(): asser...
[ { "docstring": "Check if a given number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the input array.", "function_declaration": "def extract_primes(arr):", "functio...
[ 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(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ret...
trial_gpt4o_8
{ "original_instruction": "Write a function that accepts an array of integers and returns a new array containing only the prime numbers from the input array, preserving the original order. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.\n\n## Example\n```\nInput: [2, 3...
0.714742
Apps_14147
C
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9165813a3d6ed5143167c67c1e2d4df4ae412d47
96687270f6b49afe0d8c3d24386a7cf0de87a613
v1.0
complete
Apps
Apps_14140_C
def find(parent, node): """ Helper function to find the root of the node in the disjoint set. """ pass def union(parent, rank, node1, node2): """ Helper function to union two subsets in the disjoint set. """ pass def kruskal(N, edges): """ Function to calculate the cost of the Minimum Span...
from heapq import heappop, heappush from collections import defaultdict, deque def find(parent, node): if parent[node] == node: return node root = find(parent, parent[node]) parent[node] = root return root def union(parent, rank, node1, node2): root1 = find(parent, node1) root2 = find(...
def test_sample_case(): from io import StringIO import sys input = StringIO("""1 4 5 1 2 3 1 3 4 2 3 2 3 4 5 2 4 6 3 1 2 2 3 3 4 """) sys.stdin = input from solution import solve solve() def test_another_case(): from io import StringIO import sys input = StringIO("""1 4 4 1 2 1 2 3 ...
[ { "docstring": null, "function_declaration": "def find(parent, node):", "function_name": "find", "parameter_list": "(parent, node)" }, { "docstring": null, "function_declaration": "def union(parent, rank, node1, node2):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 1, 0, 0, 0, 1, 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = fin...
trial_gpt4o_7
{ "original_instruction": "In an isolated town, there is a network of roads connecting several houses. Each house is represented by a node in a graph, and each road is represented by an edge with a certain cost. The town's mayor wants to ensure that there is a way to travel between any two houses with the minimum pos...
0.682696
Apps_14140
C
[ "find", "union", "kruskal", "is_connected_after_removal", "solve" ]
5
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "solve", "is_connected_after_removal" ], [ "solve", "kruskal" ], [ "union", "find" ] ]
5
[]
false
[]
false
pytest
true
[]
true
db8b2d3ed262496ca22dd171bae2140658282be2
107e48244627da606537155b830ca2f8d0e44bf8