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 | Taco | Taco_48901_C | import math
from typing import List, Tuple
def prime_factors(n: int) -> dict:
""" Return a dictionary with prime factors as keys and their powers as values.
>>> prime_factors(1000)
{2: 3, 5: 3}
>>> prime_factors(50)
{2: 1, 5: 2}
"""
pass
def get_smallest_prime_greater_equal(n: int, k: int)... | import math
from collections import Counter
def prime_factors(n):
"""Return a dictionary with prime factors as keys and their powers as values."""
i = 2
factors = {}
while i * i <= n:
while (n % i) == 0:
if i in factors:
factors[i] += 1
else:
... | def test_prime_factors():
assert prime_factors(1000) == {2: 3, 5: 3}
assert prime_factors(50) == {2: 1, 5: 2}
assert prime_factors(13) == {13: 1}
assert prime_factors(1) == {}
def test_get_smallest_prime_greater_equal():
assert get_smallest_prime_greater_equal(1000, 3) == 5
assert get_smallest_... | [
{
"docstring": "Return a dictionary with prime factors as keys and their powers as values.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_smallest_prime_greater_equal(n,... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n \"\"\"Helper function to find the prime factors of a number n along with their highest power in n.\"\"\"\n factors = {}\n d = 2\n ... | trial_gpt4o_4 | {
"original_instruction": "Bob is exploring the concept of prime factorization and he stumbled upon an interesting problem. He has a natural number N and he wants to break it down into its constituent prime factors, but not just that, he is interested in using these prime factors to answer Q queries.\n\nEach query co... | 0.774529 | Taco_48901 | C | [
"prime_factors",
"get_smallest_prime_greater_equal",
"handle_queries"
] | 3 | [
[
"handle_queries",
"get_smallest_prime_greater_equal"
],
[
"handle_queries",
"prime_factors"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 7755cdf2afccede54c3f168a88f38472ec199858 | 03046f878da90c5e666401672e41e0eddc17022e | |||
v1.0 | complete | Taco | Taco_50586_C | def is_palindrome(n):
"""
Helper function to check if a number is a palindrome.
>>> is_palindrome(131) True
>>> is_palindrome(123) False
>>> is_palindrome(1) True
>>> is_palindrome(22) True
>>> is_palindrome(10) False
"""
pass
def is_prime(n):
"""
Helper function to check if... | def is_palindrome(n):
"""
Helper function to check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def is_prime(n):
"""
Helper function to check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % ... | from solution import is_palindrome, is_prime, isPalprime
def test_is_palindrome():
assert is_palindrome(131) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
assert is_palindrome(10) == False
def test_is_prime():
assert is_prime(2) == ... | [
{
"docstring": "Helper function to check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef is_prime(n):\n ... | trial_gpt4o_0 | {
"original_instruction": "A number is called Palprime if it is both a palindrome and a prime number. Given a number N, check whether it is a Palprime or not.\nExample 1:\nInput: N = 131\nOutput: 1\nExplanation: 131 is a prime number and also a palindrome. Thus 131 is a Palprime and so, the answer is 1.\nExample 2:\n... | 0.796818 | Taco_50586 | C | [
"is_palindrome",
"is_prime",
"isPalprime"
] | 3 | [
[
"isPalprime",
"is_palindrome"
],
[
"isPalprime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1faf8ee02d5e69d6a6f44d82f639b79dd43672fb | 450e749fbbd23547e14cbc217d15642033ac93e3 | |||
v1.0 | complete | Taco | Taco_58021_C | def count_connected_components(n: int, roads: List[Tuple[int, int]]) -> List[int]:
"""
Calculate the number of connected components after each new road is built in a city represented as a graph.
:param n: The number of intersections in the city.
:param roads: A list of roads, where each road is a t... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, 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] = rootX
elif rank[rootX] < rank[root... | from solution import count_connected_components
def test_case_1():
n = 5
roads = [(1, 2), (3, 4), (2, 4)]
expected = [4, 3, 2]
assert count_connected_components(n, roads) == expected
def test_case_2():
n = 2
roads = [(1, 2)]
expected = [1]
assert count_connected_components(n, 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,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, x):\n if parent[x] != x:\n parent[x] = find_parent(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n ... | trial_gpt4o_1 | {
"original_instruction": "A company is planning to design a new transportation system in Metro City. The city is represented as an unweighted, bidirectional graph with n intersections, numbered from 1 to n. Initially, there are no roads between the intersections.\n\nDuring the construction phase, m bidirectional roa... | 0.575625 | Taco_58021 | C | [
"find",
"union",
"count_connected_components"
] | 3 | [
[
"count_connected_components",
"find"
],
[
"count_connected_components",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 19ca60d98dfdcca6f7f11a812c5d0b863e60d5ce | d818fe4de14810c30d234181a91c345dae0c9b09 | |||
v1.0 | complete | Taco | Taco_49521_C | def find_largest_rectangle_area(grid: List[List[int]]) -> int:
""" You are given a grid of size N x M, filled with numbers 0 or 1.
Your task is to find the largest rectangle containing only 1's in the grid and return its area.
>>> find_largest_rectangle_area([[1, 1, 0, 1], [1, 1, 1, 1], [1, 1, 1, 0], [... | def maximalRectangle(matrix):
if not matrix:
return 0
n, m = len(matrix), len(matrix[0])
max_area = 0
heights = [0] * (m + 1)
for row in range(n):
for col in range(m):
if matrix[row][col] == 1:
heights[col] += 1
else:
... | from solution import find_largest_rectangle_area
def test_sample_input_1():
input_list = [4, 4,
[1, 1, 0, 1],
[1, 1, 1, 1],
[1, 1, 1, 0],
[0, 1, 0, 0]]
expected_output = 6
assert find_largest_rectangle_area(input_list) == expected_... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def find_largest_rectangle_area(input_list):",
"function_name": "find_largest_rectangle_are... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n max_area = 0\n heights = [0] * (m + 1... | trial_gpt4o_0 | {
"original_instruction": "You are given a grid of size $N \\times M$, filled with numbers. Your task is to find the largest rectangle containing only $1$s in the grid and return its area.\n\n------ Input ------\nThe first line contains two integers, $N$ and $M$, denoting the number of rows and columns of the grid.\... | 0.733909 | Taco_49521 | C | [
"maximalRectangle",
"find_largest_rectangle_area"
] | 2 | [
[
"find_largest_rectangle_area",
"maximalRectangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 35bd1d22d9d64678d19d7b9e8a2fb6ec05f43afc | 0be8be20fe99b5372ef36eb094d0db4295dd1652 | |||
v1.0 | complete | Taco | Taco_44298_C | def nth_fibonacci(n: int) -> int:
"""
Find the N-th Fibonacci number modulo 10**9 + 7.
Parameters:
n (int): The position in the Fibonacci sequence.
Returns:
int: The N-th Fibonacci number modulo 10**9 + 7.
Example:
>>> nth_fibonacci(0)
0
>>> nth_fibonacci(1)
1
>>> nth_... | MOD = 10**9 + 7
def matrix_multiply(A, B):
return [
[
(A[0][0]*B[0][0] + A[0][1]*B[1][0]) % MOD,
(A[0][0]*B[0][1] + A[0][1]*B[1][1]) % MOD
],
[
(A[1][0]*B[0][0] + A[1][1]*B[1][0]) % MOD,
(A[1][0]*B[0][1] + A[1][1]*B[1][1]) % MOD
]
... | from solution import nth_fibonacci, process_test_cases
def test_nth_fibonacci_basic():
assert nth_fibonacci(0) == 0
assert nth_fibonacci(1) == 1
assert nth_fibonacci(2) == 1
assert nth_fibonacci(10) == 55
def test_nth_fibonacci_large():
# Test for large input, manually computed
assert nth_fibo... | [
{
"docstring": null,
"function_declaration": "def matrix_multiply(A, B):",
"function_name": "matrix_multiply",
"parameter_list": "(A, B)"
},
{
"docstring": null,
"function_declaration": "def matrix_power(matrix, n):",
"function_name": "matrix_power",
"parameter_list": "(matrix, n... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef fibonacci(n):\n if n == 0:\n return 0\n if n == 1:\n return 1\n\n def multiply_matrices(m1, m2):\n return [\n ... | trial_gpt4o_4 | {
"original_instruction": "\"The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. For example, the first few numbers of this sequence are 0, 1, 1, 2, 3, 5, 8, and so on.\n\nYou need to find the N-th Fibonacci number. However, since Fibona... | 0.766086 | Taco_44298 | C | [
"matrix_multiply",
"matrix_power",
"nth_fibonacci",
"process_test_cases"
] | 4 | [
[
"matrix_power",
"matrix_multiply"
],
[
"nth_fibonacci",
"matrix_power"
],
[
"process_test_cases",
"nth_fibonacci"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 31b0da92441ed4887b7f0e30cd2cdcc63591f7b7 | a94419cef96ce12cc6e7ba657152ca9340f5d0d1 | |||
v1.0 | complete | Taco | Taco_59501_C | def partition_equal_sum(nums: List[int]) -> str:
""" You are given a list of n distinct integers, and you need to divide this list into two non-empty subsets such that the sum of the integers in each subset is equal. If it is not possible to do so, return "No". Otherwise, return "Yes".
>>> partition_equal_sum([... | def can_partition(nums):
total_sum = sum(nums)
# If the total sum is odd, it's not possible to divide into two subsets with equal sum
if total_sum % 2 != 0:
return "No"
target = total_sum // 2
n = len(nums)
# Initialize a list to track possible sums using dynamic programmi... | from solution import partition_equal_sum
def test_partition_equal_sum_case1():
assert partition_equal_sum([4, 1, 5, 11, 5]) == "Yes"
def test_partition_equal_sum_case2():
assert partition_equal_sum([3, 1, 2, 5]) == "No"
def test_partition_equal_sum_case3():
assert partition_equal_sum([5, 3, 1, 4, 2, 2]) ... | [
{
"docstring": null,
"function_declaration": "def can_partition(nums):",
"function_name": "can_partition",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def partition_equal_sum(nums):",
"function_name": "partition_equal_sum",
"parameter_list": "(nums... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_partition(n, nums):\n # Calculate the sum of the list\n total_sum = sum(nums)\n \n # If the total sum is odd, it's not possible to partition it... | trial_gpt4o_7 | {
"original_instruction": "You are given a list of n distinct integers, and you need to divide this list into two non-empty subsets such that the sum of the integers in each subset is equal. If it is not possible to do so, return \"No\". Otherwise, return \"Yes\".\n\n-----Input-----\n\nThe input consists of a single ... | 0.641061 | Taco_59501 | C | [
"can_partition",
"partition_equal_sum"
] | 2 | [
[
"partition_equal_sum",
"can_partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 51e73bf0ee56bed7fd61aaca449d30f623325c36 | eea6bf402881b7227bd620f96a8232e07cdaf66c | |||
v1.0 | complete | Taco | Taco_33229_C | from collections import deque
from typing import List, Tuple
def min_moves_to_treasure(m: int, n: int, grid: List[List[str]], x1: int, y1: int, x2: int, y2: int) -> int:
""" Determine the minimum number of moves needed to reach the treasure in a grid.
Args:
m (int): Number of rows in the grid.
n (... | from collections import deque
def min_moves_to_treasure(m, n, grid, x1, y1, x2, y2):
def is_valid(x, y):
return 0 <= x < m and 0 <= y < n and grid[x][y] == '.'
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(x1, y1, 0)]) # (current_x, current_y, current_distance)
visited = set... | from solution import solve_game
def test_example_1():
m, n = 5, 5
grid_lines = [".....", ".###.", ".....", ".#...", "....."]
start_end = (0, 0, 4, 4)
assert solve_game(m, n, grid_lines, start_end) == 8
def test_example_2():
m, n = 3, 4
grid_lines = ["....", "####", "...."]
start_end = (0, ... | [
{
"docstring": null,
"function_declaration": "def min_moves_to_treasure(m, n, grid, x1, y1, x2, y2):",
"function_name": "min_moves_to_treasure",
"parameter_list": "(m, n, grid, x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def solve_game(m, n, grid_lines, start_end):"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_moves_to_reach_treasure(m, n, grid, start, treasure):\n \"\"\"\n Determines the minimum number of moves needed to re... | trial_gpt4o_2 | {
"original_instruction": "Alex is designing a new game where players hunt for treasure on a rectangular grid. Each cell in the grid either contains grass ('.') or is impassable rock ('#'). Players must move from a start cell to a treasure cell using the shortest path possible, but they can only move up, down, left, ... | 0.635311 | Taco_33229 | C | [
"min_moves_to_treasure",
"solve_game"
] | 2 | [
[
"solve_game",
"min_moves_to_treasure"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | facf0b75c6194e0df33b66405787fca06728e5c8 | 3be1d42e40db4b5b4aa35c8d1b3baa8746946a63 | |||
v1.0 | complete | Taco | Taco_64912_C | def sum_of_two_primes(N: int):
""" Given a positive integer N, determine whether it can be expressed as the sum of two prime numbers.
If it can, return the two prime numbers in sorted order as a tuple.
If multiple pairs exist, return any one of them.
If it cannot be expressed as such, return -1.
>>... | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_of_two_primes(N):
for... | from solution import sum_of_two_primes
def test_example1():
assert sum_of_two_primes(10) in [(3, 7), (7, 3)]
def test_example2():
result = sum_of_two_primes(16)
assert result in [(3, 13), (13, 3), (5, 11), (11, 5)]
def test_example3():
assert sum_of_two_primes(11) == -1
def test_prime_sum_of_non_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_two_primes(N):",
"function_name": "sum_of_two_primes",
"parameter_list": "(N)"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True... | trial_gpt4o_1 | {
"original_instruction": "Given a positive integer N, determine whether it can be expressed as the sum of two prime numbers. If it can, return the two prime numbers in sorted order as a tuple. If multiple pairs exist, return any one of them. If it cannot be expressed as such, return -1.\n\nExample 1:\nInput:\nN=10\n... | 0.713249 | Taco_64912 | C | [
"is_prime",
"sum_of_two_primes"
] | 2 | [
[
"sum_of_two_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 130d98bba097d981d2dac5d1ae2a74fb54b20286 | 1ddd1debf4bdaeb649a75980bb4dcfedffb5b330 | |||
v1.0 | complete | Taco | Taco_45645_C | import math
from typing import List, Tuple
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(17) == True
>>> is_prime(21) == False
>>> is_prime(1) == False
>>> is_pri... | import math
def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True... | from solution import is_prime, primes_in_range, find_primes_in_multiple_ranges
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(21) == False
assert is_prime(1) == False
assert is_prime(0) == Fa... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers in the range [a, b] (both inclusive).",
"function_declaration": "def pr... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retur... | trial_gpt4o_2 | {
"original_instruction": "Mia has just started learning programming and is excited to write her first function. She loves prime numbers and wants to write a function that identifies prime numbers in a given range. Help Mia by writing a program that takes two integers, `a` and `b`, as input and returns a list of all ... | 0.685411 | Taco_45645 | C | [
"is_prime",
"primes_in_range",
"find_primes_in_multiple_ranges"
] | 3 | [
[
"find_primes_in_multiple_ranges",
"primes_in_range"
],
[
"primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b7b1c424d8ef8fbd16d8464be033fafc94a8374b | bb4d7237bcf38d90360e00c5437a797a3b7de393 | |||
v1.0 | complete | Taco | Taco_40119_C | def longest_increasing_subsequence_length(n: int, sequence: List[int]) -> int:
"""
Finds the length of the longest strictly increasing subsequence.
>>> longest_increasing_subsequence_length(5, [1, 2, 1, 5, 3])
3
>>> longest_increasing_subsequence_length(4, [9, 4, 7, 2])
2
>>> longest_increas... | def longest_increasing_subsequence_length(n, sequence):
"""
Finds the length of the longest strictly increasing subsequence.
"""
if n == 0:
return 0
# Initialize an array to store the smallest ending value for increasing subsequence of length i+1
dp = []
for num in sequence... | def test_longest_increasing_subsequence_length():
assert longest_increasing_subsequence_length(5, [1, 2, 1, 5, 3]) == 3, "Test case 1 failed"
assert longest_increasing_subsequence_length(4, [9, 4, 7, 2]) == 2, "Test case 2 failed"
assert longest_increasing_subsequence_length(6, [2, 2, 2, 2, 2, 2]) == 1, "Te... | [
{
"docstring": "Finds the length of the longest strictly increasing subsequence.",
"function_declaration": "def longest_increasing_subsequence_length(n, sequence):",
"function_name": "longest_increasing_subsequence_length",
"parameter_list": "(n, sequence)"
},
{
"docstring": "Helper function... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_lis(sequence):\n \"\"\"\n Returns the length of the longest increasing subsequence.\n \"\"\"\n if not sequence:\n return 0\n\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a sequence of $n$ integers, we want to remove elements so that the remaining sequence is strictly increasing. Specifically, for each integer $v_i$ in the sequence, either remove it or keep it such that the final sequence contains all elements sorted in strictly increasing order withou... | 0.695516 | Taco_40119 | C | [
"longest_increasing_subsequence_length",
"binary_search",
"process_input"
] | 3 | [
[
"longest_increasing_subsequence_length",
"binary_search"
],
[
"process_input",
"longest_increasing_subsequence_length"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 6838dfe8789ada4b14c2b2497158f53bd74d0009 | 0b3c73cdce7675fab531e28ade641dfd6fb521d4 | |||
v1.0 | complete | Taco | Taco_51111_C | def number_of_paths(n: int, m: int, k: int, dangerous_cells: set) -> int:
""" Determine the number of distinct paths the robot can take to reach the bottom-right corner (n-1, m-1)
from the top-left corner (0, 0) without stepping on a dangerous cell.
The number of paths should be calculated modulo 100... | def number_of_paths(n, m, k, dangerous_cells):
MOD = 1000000007
dp = [[0] * m for _ in range(n)]
if (0, 0) in dangerous_cells:
return 0
dp[0][0] = 1
for i in range(n):
for j in range(m):
if (i, j) in dangerous_cells:
dp[i][j] = 0
else:
... | def test_number_of_paths_case1():
assert number_of_paths(3, 3, 1, {(1, 1)}) == 2
def test_number_of_paths_case2():
assert number_of_paths(4, 4, 2, {(1, 1), (2, 2)}) == 4
def test_number_of_paths_case3():
assert number_of_paths(2, 2, 0, set()) == 2
def test_number_of_paths_no_path():
assert number... | [
{
"docstring": null,
"function_declaration": "def number_of_paths(n, m, k, dangerous_cells):",
"function_name": "number_of_paths",
"parameter_list": "(n, m, k, dangerous_cells)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_l... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef num_paths(n, m, k, dangers):\n # Initialize DP table with 0s\n dp = [[0] * m for _ in range(n)]\n\n # Mark dangerous cells in the ... | trial_gpt4o_7 | {
"original_instruction": "A robot is placed on a 2D grid at position (0, 0). The grid has n rows and m columns (1 ≤ n, m ≤ 1000). The robot can move to any of four directions: up, down, left, and right. However, some cells in the grid are considered dangerous and the robot cannot step on them. \n\nDetermine the numb... | 0.754301 | Taco_51111 | C | [
"number_of_paths",
"solve"
] | 2 | [
[
"solve",
"number_of_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b2400cd9dfde9e11278ce749dcf055a771a938a6 | f2d556e24e3147d10ff91ed94dd4f02221650d77 | |||
v1.0 | complete | Taco | Taco_56645_C | from typing import List
def max_number_of_flowers(n: int, bloom: List[int], wilt: List[int]) -> int:
""" Alice is planting flowers in her garden. Each flower blooms on a specific day and wilts on a specific day.
Find the maximum number of flowers that are in bloom simultaneously at any point in time.
... | def max_bloom_flowers(bloom, wilt):
events = []
for i in range(len(bloom)):
events.append((bloom[i], 1)) # +1 for bloom
events.append((wilt[i] + 1, -1)) # -1 for wilt (end of bloom day + 1)
# Sort events by days; if same day, end event (-1) comes before start event (+1)
events.sort(ke... | from solution import max_number_of_flowers
def test_sample_case():
assert max_number_of_flowers(5, [1, 2, 3, 4, 5], [3, 4, 5, 6, 7]) == 3
def test_no_overlap():
assert max_number_of_flowers(3, [1, 5, 10], [2, 6, 12]) == 1
def test_full_overlap():
assert max_number_of_flowers(3, [1, 1, 1], [5, 5, 5]) == 3... | [
{
"docstring": null,
"function_declaration": "def max_bloom_flowers(bloom, wilt):",
"function_name": "max_bloom_flowers",
"parameter_list": "(bloom, wilt)"
},
{
"docstring": null,
"function_declaration": "def max_number_of_flowers(n, bloom, wilt):",
"function_name": "max_number_of_fl... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_flowers_in_bloom(bloom, wilt):\n \"\"\"\n Determines the maximum number of flowers that are in bloom simultaneously.\n \"\"\"\n events = []\n ... | trial_gpt4o_2 | {
"original_instruction": "Alice is a gardener and she loves planting different types of flowers in her garden. She plants flowers in a straight line and wants to maximize the beauty of her garden by having contiguous segments of flowers that bloom. Each type of flower blooms at a certain time and lasts for a certain... | 0.586284 | Taco_56645 | C | [
"max_bloom_flowers",
"max_number_of_flowers"
] | 2 | [
[
"max_number_of_flowers",
"max_bloom_flowers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65e63c033fa5cf95af69f8778228d474868154de | 2e20836374496747cc670ec7272d998f5b1fe68f | |||
v1.0 | complete | Taco | Taco_49102_C | def merge_pages_input(N: int, input_data: List[str]) -> List[int]:
"""
Processes the input formatted data for merging the survey responses into a single sorted list.
:param N: Number of pages
:param input_data: List of strings, each corresponding to a page's responses
:return: Combined sorted r... | import heapq
def merge_sorted_responses(pages):
"""
Merges a list of sorted lists into a single sorted list.
:param pages: List of sorted lists
:return: A single sorted list with all elements from all input lists
"""
min_heap = []
result = []
# Initialize the min_heap with the... | from solution import merge_pages_input
def test_merge_pages_input_single_page():
assert merge_pages_input(1, ["3 1 2 3"]) == [1, 2, 3]
def test_merge_pages_input_multiple_pages():
assert merge_pages_input(3, ["3 10 20 30", "4 5 7 25 29", "2 1 100"]) == [1, 5, 7, 10, 20, 25, 29, 30, 100]
def test_merge_pages_... | [
{
"docstring": "Merges a list of sorted lists into a single sorted list.\n\n:param pages: List of sorted lists\n:return: A single sorted list with all elements from all input lists",
"function_declaration": "def merge_sorted_responses(pages):",
"function_name": "merge_sorted_responses",
"parameter_l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef merge_responses(N, pages):\n \"\"\"\n Merges multiple sorted lists into a single sorted list.\n \n Args:\n N : int : the number ... | trial_gpt4o_1 | {
"original_instruction": "Alice is conducting a survey and has a notebook with N pages, where each page contains a list of unique survey responses represented by integers. She wants to combine all the responses into a single final list, but while combining, she needs to ensure that the combined list maintains non-de... | 0.506027 | Taco_49102 | C | [
"merge_sorted_responses",
"merge_pages_input"
] | 2 | [
[
"merge_pages_input",
"merge_sorted_responses"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a389bd15658dee446307e3a4afba04e911b1355d | 5922968901b98c83524ae31b3a76e9f9b234f40e | |||
v1.0 | complete | Taco | Taco_50558_C | class ListNode:
def __init__(self, val=0):
self.val = val
self.next = None
def is_circular_linked_list(head):
"""
Function to check if the linked list is circular.
"""
def build_linked_list(node_values, circular_index=None):
"""
Function to build a linked list from the given no... | class ListNode:
def __init__(self, val=0):
self.val = val
self.next = None
def is_circular_linked_list(head):
"""
Function to check if the linked list is circular.
"""
if not head or not head.next:
return False
slow, fast = head, head.next
while fast and fast.ne... | from solution import build_linked_list, is_circular_linked_list
def test_non_circular_list():
head = build_linked_list([1, 2, 3])
assert not is_circular_linked_list(head), "Test case failed for non-circular list [1, 2, 3]"
def test_circular_list():
head = build_linked_list([10, 20, 30, 40], circular_index... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, value):\n self.value = value\n self.next = None\n\ndef is_circular(head):\n if not head or not head.next:\... | trial_gpt4o_1 | {
"original_instruction": "You are given a linked list containing unique integers. Your task is to determine if this linked list is a circular linked list. A circular linked list is one where the last node points back to any previous node in the list.\n\nInput:\n- The first line contains an integer T, the number of t... | 0.459685 | Taco_50558 | C | [
"is_circular_linked_list",
"parse_input",
"build_linked_list",
"process_input"
] | 4 | [
[
"parse_input",
"is_circular_linked_list"
],
[
"process_input",
"build_linked_list"
],
[
"process_input",
"parse_input"
]
] | 3 | [
"parse_input",
"process_input"
] | false | [
"ListNode"
] | true | pytest | true | [] | true | 51f4ab2e04346a08c9ca9fdb2578c4eab58a9713 | e7bb84c94d7f20109546460a72e4db02b40a7166 | |||
v1.0 | complete | Taco | Taco_51219_C | def calculate_distance(p1, p2):
"""Calculate Manhattan distance between two points"""
pass
def minimum_time_to_collect_all_coins_and_return(r, c, k, coins):
"""
Determine the minimum time needed to collect all coins and return to the starting point in the maze.
Parameters:
r (int): number ... | from itertools import permutations
def calculate_distance(p1, p2):
"""Calculate Manhattan distance between two points"""
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
def minimum_time_to_collect_all_coins_and_return(r, c, k, coins):
start = (0, 0)
min_time = float('inf')
# Generate all permutati... | import pytest
from solution import calculate_distance, minimum_time_to_collect_all_coins_and_return, optimal_timer_settings
def test_calculate_distance():
assert calculate_distance((0, 0), (0, 1)) == 1
assert calculate_distance((0, 0), (1, 1)) == 2
assert calculate_distance((2, 3), (5, 7)) == 7
assert ... | [
{
"docstring": "Calculate Manhattan distance between two points",
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_collect_all_coins_and_retu... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef minimum_collection_time(r, c, k, coins):\n def manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1... | trial_gpt4o_3 | {
"original_instruction": "Frank is a video game developer, and he is working on a level where the player needs to collect coins positioned around a maze. To make the game more challenging, he wants to calculate the optimal timer setting for players to gather all coins within a specific time frame.\n\nEach coin is po... | 0.567022 | Taco_51219 | C | [
"calculate_distance",
"minimum_time_to_collect_all_coins_and_return",
"optimal_timer_settings"
] | 3 | [
[
"minimum_time_to_collect_all_coins_and_return",
"calculate_distance"
],
[
"optimal_timer_settings",
"minimum_time_to_collect_all_coins_and_return"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d4af5f6f6df70c8559f931fe81d38c0347da4f23 | de4de1cf2c99f7c899f3593e7a3e382fe26117cf | |||
v1.0 | complete | Taco | Taco_50911_C | def is_palindrome(s, i, j):
"""
Helper function to check if the substring s[i:j+1] is a palindrome.
"""
def can_be_made_palindrome(s):
"""
Function to check if the string s can be made a palindrome by removing at most one character.
"""
def process_inputs(T, strings):
"""
Given a list ... | def is_palindrome(s, i, j):
"""
Helper function to check if the substring s[i:j+1] is a palindrome.
"""
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
def can_be_made_palindrome(s):
"""
Function to check if the string s can be made a... | from solution import process_inputs
def test_sample_inputs():
assert process_inputs(2, ['abca', 'abc']) == ["YES", "NO"]
def test_single_character():
assert process_inputs(1, ['a']) == ["YES"]
def test_two_character_palindrome():
assert process_inputs(1, ['aa']) == ["YES"]
def test_two_character_non_pal... | [
{
"docstring": "Helper function to check if the substring s[i:j+1] is a palindrome.",
"function_declaration": "def is_palindrome(s, i, j):",
"function_name": "is_palindrome",
"parameter_list": "(s, i, j)"
},
{
"docstring": "Function to check if the string s can be made a palindrome by removi... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_almost_palindrome(s):\n \"\"\"\n Checks if the string s can be made a palindrome by removing at most one character.\n \"\"\"\n def is_palindrome... | trial_gpt4o_1 | {
"original_instruction": "Uttu is fascinated by palindromes and often challenges Shil with different palindrome-related puzzles. Recently, Uttu introduced Shil to a new game involving strings and palindromes. Given a string, Shil needs to determine if it's possible to make the string a palindrome by removing at most... | 0.821979 | Taco_50911 | C | [
"is_palindrome",
"can_be_made_palindrome",
"process_inputs"
] | 3 | [
[
"can_be_made_palindrome",
"is_palindrome"
],
[
"process_inputs",
"can_be_made_palindrome"
]
] | 2 | [
"process_inputs"
] | false | [] | false | pytest | true | [] | true | d973ec4d8a4f21ba1d245c7b73922a386dbf4ca5 | 39f06ec9e699a890e6c659bb024b963008cdcfbf | |||
v1.0 | complete | Taco | Taco_65991_C | def collatz_sequence_length(n: int) -> int:
"""
Returns the length of the Collatz sequence starting with n.
>>> collatz_sequence_length(1) == 1
>>> collatz_sequence_length(2) == 2
>>> collatz_sequence_length(3) == 8
>>> collatz_sequence_length(5) == 6
>>> collatz_sequence_length(10) == 7
... | def collatz_sequence_length(n):
"""
Returns the length of the Collatz sequence starting with n.
"""
length = 1
while n != 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
length += 1
return length
def process_collatz_sequences(numbers):
"""
... | from solution import collatz_sequence_length, process_collatz_sequences
def test_collatz_sequence_length():
assert collatz_sequence_length(1) == 1
assert collatz_sequence_length(2) == 2
assert collatz_sequence_length(3) == 8
assert collatz_sequence_length(5) == 6
assert collatz_sequence_length(10) ... | [
{
"docstring": "Returns the length of the Collatz sequence starting with n.",
"function_declaration": "def collatz_sequence_length(n):",
"function_name": "collatz_sequence_length",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of numbers and returns list of lengths of their Col... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def collatz_sequence_length(n):\n \"\"\"\n Calculate the length of the Collatz sequence for a given integer n.\n \"\"\"\n if n <= 0:\n return 0\... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of non-negative integers. For each integer in the list, you need to determine the length of the Collatz sequence starting with that integer. The Collatz sequence is defined as follows:\n\n- Start with any integer n.\n- If n is even, divide it by 2.\n- If n is odd, multi... | 0.764483 | Taco_65991 | C | [
"collatz_sequence_length",
"process_collatz_sequences"
] | 2 | [
[
"process_collatz_sequences",
"collatz_sequence_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6ed7104df525db020d057a0c91bffd8890e99c5 | d795020e91b27280bccb41b27d97e115b732d6f6 | |||
v1.0 | complete | Taco | Taco_59496_C | def are_permutations(a: str, b: str) -> str:
""" Returns 'YES' if string 'b' is a permutation of string 'a', otherwise returns 'NO'.
>>> are_permutations('listen', 'silent')
'YES'
>>> are_permutations('apple', 'pale')
'NO'
"""
def check_permutations(test_cases: List[Tuple[str, str]]) -> List[st... | def are_permutations(a, b):
"""
Returns 'YES' if string 'b' is a permutation of string 'a', otherwise returns 'NO'.
"""
return "YES" if sorted(a) == sorted(b) else "NO"
def check_permutations(test_cases):
"""
Given a list of test cases, where each pair of strings is represented as a tuple,
... | from solution import are_permutations, check_permutations, process_input
def test_are_permutations():
assert are_permutations('listen', 'silent') == 'YES'
assert are_permutations('triangle', 'integral') == 'YES'
assert are_permutations('apple', 'pale') == 'NO'
assert are_permutations('abc', 'cab') == '... | [
{
"docstring": "Returns 'YES' if string 'b' is a permutation of string 'a', otherwise returns 'NO'.",
"function_declaration": "def are_permutations(a, b):",
"function_name": "are_permutations",
"parameter_list": "(a, b)"
},
{
"docstring": "Given a list of test cases, where each pair of strin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def are_permutations(a, b):\n \"\"\"\n Returns whether the given strings a and b are permutations of each other.\n \"\"\"\n return sorted(a) == sorted(... | trial_gpt4o_2 | {
"original_instruction": "You are given several pairs of strings a, b consisting of lowercase letters and you need to determine if one string is a permutation of the other. A permutation is a rearrangement of letters.\n\nInput\nThe first line contains T (number of test cases). 1 ≤ T ≤ 100\nEach of the next 2T lines ... | 0.57645 | Taco_59496 | C | [
"are_permutations",
"check_permutations",
"process_input"
] | 3 | [
[
"check_permutations",
"are_permutations"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c6e1da149a0362dba5d9c723dfe5797a1cec45c6 | d930a9e067a80ad68bccccf0b426a22578603dd6 | |||
v1.0 | complete | Taco | Taco_59548_C | def minimum_road_length(N: int, M: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum possible total length of roads required to connect all provinces.
If it is impossible to connect all the provinces, return -1.
:param N: Integer number of provinces
:param M: Integer number ... | def kruskal_minimum_spanning_tree(N, edges):
"""
Given number of nodes (N) and a list of edges (u, v, w),
this function computes the minimum possible total length
of roads required to connect all provinces using Kruskal's algorithm.
If it is impossible to connect all provinces, return -1.
"""
... | from solution import minimum_road_length
def test_example_case():
N = 4
M = 5
roads = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 3),
(1, 4, 4),
(1, 3, 5)
]
assert minimum_road_length(N, M, roads) == 6
def test_all_disconnected():
N = 4
M = 0
roads = []
a... | [
{
"docstring": "Given number of nodes (N) and a list of edges (u, v, w), \nthis function computes the minimum possible total length \nof roads required to connect all provinces using Kruskal's algorithm.\nIf it is impossible to connect all provinces, return -1.",
"function_declaration": "def kruskal_minimum... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_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 par... | trial_gpt4o_2 | {
"original_instruction": "In a land far away, the kingdom is divided into several provinces. The kingdom's defense council is considering connecting these provinces with roads to facilitate efficient troop movement. To ensure the shortest possible paths between any two provinces, they want to build roads in such a w... | 0.73272 | Taco_59548 | C | [
"kruskal_minimum_spanning_tree",
"minimum_road_length"
] | 2 | [
[
"minimum_road_length",
"kruskal_minimum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d40cc46970199a1c801c3542eef567938debda1d | 0264813a07a5ec98a38ce1268d5dd6cb63e3622e | |||
v1.0 | complete | Taco | Taco_49639_C | def gcd(a, b):
""" Computes the greatest common divisor (gcd) of two numbers using the Euclidean algorithm.
>>> gcd(28, 35) 7
>>> gcd(15, 25) 5
"""
pass
def prime_factors(n):
""" Returns the prime factors of a given number as a set.
>>> prime_factors(28) {2, 7}
>>> prime_factors(35) {5,... | def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def prime_factors(n):
i = 2
factors = set()
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.add(i)
if n > 1:
factors.add(n)
return factors
def common_prime_fac... | def test_gcd():
assert gcd(28, 35) == 7
assert gcd(15, 25) == 5
assert gcd(100, 10) == 10
assert gcd(17, 19) == 1
def test_prime_factors():
assert prime_factors(28) == {2, 7}
assert prime_factors(35) == {5, 7}
assert prime_factors(15) == {3, 5}
assert prime_factors(25) == {5}
def test_... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def common_prime_factors(a, b):\n def prime_factors(n):\n i = 2\n factors = set()\n while i * i <= n:\n if n % i:\n ... | trial_gpt4o_2 | {
"original_instruction": "Develop a program to identify the common prime factors of two given numbers.\n\nINPUT:\n\nThe first line contains the number of test cases t. For each test case, there are two space-separated integers, a and b.\n\nOUTPUT:\n\nFor each test case, output the common prime factors of the two num... | 0.695076 | Taco_49639 | C | [
"gcd",
"prime_factors",
"common_prime_factors",
"main"
] | 4 | [
[
"common_prime_factors",
"gcd"
],
[
"common_prime_factors",
"prime_factors"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | ba1e31517f303b3ee21c61bebba1409a3a32f231 | 5d43d78367af094f51e3cbcd367ca908f7869919 | |||
v1.0 | complete | Taco | Taco_64367_C | def min_bridge_cost(n, m, bridges):
"""
Determine the minimum cost required to connect all islands with a system of bridges.
Use Kruskal's or Prim's algorithm to find the Minimum Spanning Tree (MST).
Args:
n (int): Number of islands.
m (int): Number of potential bridges.
bridges (list ... | 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... | from solution import min_bridge_cost
def test_min_bridge_cost_example():
n = 4
m = 5
bridges = [
(0, 1, 1),
(0, 2, 2),
(0, 3, 3),
(1, 2, 4),
(2, 3, 5)
]
assert min_bridge_cost(n, m, bridges) == 6
def test_min_bridge_cost_single_bridge():
n = 2
m = 1
... | [
{
"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)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_bridge_cost(n, m, bridges):\n \"\"\"\n Determines the minimum cost required to connect all islands with a system of bridges.\n\n Parameters:\n ... | trial_gpt4o_1 | {
"original_instruction": "An island nation is exploring the feasibility of establishing a new transportation network consisting of bridges connecting various islands. Each island has several landmarks, and there are various potential bridge locations connecting these landmarks. The goal is to determine the minimum c... | 0.726952 | Taco_64367 | C | [
"find",
"union",
"min_bridge_cost"
] | 3 | [
[
"min_bridge_cost",
"find"
],
[
"min_bridge_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 92fe19a752c415cf18b3943f162c9b6ef78b395e | 03809f7bf47d0d6260809d49011f369c5bd45722 | |||
v1.0 | complete | Taco | Taco_65777_C | def is_valid_ipv4_address(ip: str) -> bool:
"""
Validates if the given IP address string is a valid IPv4 address.
>>> is_valid_ipv4_address("192.168.0.1")
True
>>> is_valid_ipv4_address("255.255.255.255")
True
>>> is_valid_ipv4_address("256.100.50.0")
False
>>> is_valid_ipv4_address... | def is_valid_ipv4_address(ip):
"""
Validates if the given IP address string is a valid IPv4 address.
"""
parts = ip.split('.')
if len(parts) != 4:
return False
for part in parts:
if not part.isdigit():
return False
num = int(part)
if num < 0 or num > 2... | def test_is_valid_ipv4_address():
assert is_valid_ipv4_address("192.168.0.1") == True
assert is_valid_ipv4_address("255.255.255.255") == True
assert is_valid_ipv4_address("0.0.0.0") == True
assert is_valid_ipv4_address("256.100.50.0") == False
assert is_valid_ipv4_address("192.168.0.1.1") == False
... | [
{
"docstring": "Validates if the given IP address string is a valid IPv4 address.",
"function_declaration": "def is_valid_ipv4_address(ip):",
"function_name": "is_valid_ipv4_address",
"parameter_list": "(ip)"
},
{
"docstring": "Validates a list of IP addresses and prints 'VALID' or 'INVALID'... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_ipv4_addresses(n, addresses):\n \"\"\"\n Check if each address in the list is a valid IPv4 address.\n \n Parameters:\n n (int): Number ... | trial_gpt4o_2 | {
"original_instruction": "A common type of data validation involves checking that a provided input adheres to a specified format. In this task, you are required to validate a sequence of strings to ensure they match a given format representing an IPv4 address.\n\nIPv4 addresses are written in the format `d.d.d.d`, w... | 0.655629 | Taco_65777 | C | [
"is_valid_ipv4_address",
"validate_ipv4_addresses"
] | 2 | [
[
"validate_ipv4_addresses",
"is_valid_ipv4_address"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a21c15b47291fa695a2f96bf55235cd615961802 | 6b4558f032ce78c56d63ca3558e0121a34f7a8dd | |||
v1.0 | complete | Taco | Taco_49978_C | from typing import List
def best_move(grid: List[List[int]]) -> str:
"""Create a 2048 game solver that takes an initial game state and suggests the next optimal move.
Parameters:
grid (List[List[int]]): A 4x4 2D list representing the game board.
Returns:
str: The best move. One of 'up', '... | import random
from typing import List
def evaluate_grid(grid):
eval_score = 0
for row in grid:
eval_score += sum(row)
return eval_score
def slide_left(grid):
out_grid = []
for row in grid:
new_row = [num for num in row if num != 0]
new_row += [0] * (len(row) - len(new_row))... | from solution import best_move
def test_scenario1():
grid = [
[2, 4, 2, 0],
[2, 0, 4, 2],
[8, 16, 32, 0],
[1024, 1024, 64, 0]
]
assert best_move(grid) in ['up', 'down', 'left', 'right']
def test_scenario2():
grid = [
[0, 0, 2, 2],
[2, 2, 2, 2],
[... | [
{
"docstring": null,
"function_declaration": "def evaluate_grid(grid):",
"function_name": "evaluate_grid",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def slide_left(grid):",
"function_name": "slide_left",
"parameter_list": "(grid)"
},
{
"d... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\nimport copy\nimport random\n\ndef best_move(grid: List[List[int]]) -> str:\n def merge_left(board):\n new_board = []\n fo... | trial_gpt4o_7 | {
"original_instruction": "Create a 2048 game solver in Python.\n\n## The Game \n\n2048 is a single-player sliding block puzzle game. The objective is to slide numbered tiles on a grid to combine them and create a tile with the number 2048. The game is played on a 4×4 grid, with tiles numbered in powers of 2 that mer... | 0.583306 | Taco_49978 | C | [
"evaluate_grid",
"slide_left",
"merge_left",
"move_left",
"move_right",
"move_up",
"move_down",
"generate_successors",
"best_move"
] | 9 | [
[
"best_move",
"evaluate_grid"
],
[
"best_move",
"generate_successors"
],
[
"generate_successors",
"move_down"
],
[
"generate_successors",
"move_left"
],
[
"generate_successors",
"move_right"
],
[
"generate_successors",
"move_up"
],
[
"move... | 11 | [] | false | [] | false | pytest | true | [] | true | 23e0f19afd6df76684b72afebb1561b4640af4f1 | 5d946028fc1c4aad3c546b5fca015ad0cfeea9bb | |||
v1.0 | complete | Taco | Taco_65344_C | def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int:
""" Determine the maximum distance between any two nodes in a tree.
>>> tree_diameter(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 3
>>> tree_diameter(1, []) == 0
>>> tree_diameter(4, [(1, 2), (1, 3), (1, 4)]) == 2
"""
import pytest
from ty... | from collections import deque
def find_farthest_node(n, graph, start):
# BFS to find the farthest node from the starting node "start"
dist = [-1] * (n + 1)
dist[start] = 0
queue = deque([start])
farthest_node = start
while queue:
node = queue.popleft()
for neighbor in graph[nod... | import pytest
from solution import tree_diameter
def test_tree_diameter_single_node():
assert tree_diameter(1, []) == 0
def test_tree_diameter_linear_tree():
assert tree_diameter(5, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 4
def test_tree_diameter_star_tree():
assert tree_diameter(4, [(1, 2), (1, 3), (1, 4)]... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(n, graph, start):",
"function_name": "find_farthest_node",
"parameter_list": "(n, graph, start)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tree_diameter(n, edges):\n from collections import defaultdict, deque\n \n if n == 1:\n return 0\n \n def bfs(start):\n distance =... | trial_gpt4o_2 | {
"original_instruction": "In a city, there is exactly one path between any two neighborhoods, forming a tree structure. Each neighborhood is represented as a node, and the path between two nodes is represented as an edge. Given this information, you are to determine the maximum distance between any two nodes in the ... | 0.619453 | Taco_65344 | C | [
"find_farthest_node",
"tree_diameter"
] | 2 | [
[
"tree_diameter",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8252fd17712fa13da5dce41903cbbbf39c290d17 | 4baa68826a7df74719a12746c612d8ac8d156fc2 | |||
v1.0 | complete | Taco | Taco_49454_C | import math
from typing import List, Tuple
def sum_of_divisors(n: int) -> int:
"""
Calculate the sum of divisors of a given number.
"""
total = 0
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0:
total += i
if i != n // i:
total += n // i
r... | import math
def sum_of_divisors(n):
total = 0
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0:
total += i
if i != n // i:
total += n // i
return total
def preprocess(array):
"""
Preprocess the array to calculate the sum of divisors for each e... | def test_sum_of_divisors():
assert sum_of_divisors(1) == 1
assert sum_of_divisors(2) == 3
assert sum_of_divisors(3) == 4
assert sum_of_divisors(4) == 7
assert sum_of_divisors(5) == 6
def test_preprocess():
array = [1, 2, 3, 4, 5]
assert preprocess(array) == [1, 3, 4, 7, 6]
def test_prefix_... | [
{
"docstring": null,
"function_declaration": "def sum_of_divisors(n):",
"function_name": "sum_of_divisors",
"parameter_list": "(n)"
},
{
"docstring": "Preprocess the array to calculate the sum of divisors for each element.",
"function_declaration": "def preprocess(array):",
"function... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_divisors_of_number(n):\n \"\"\"\n Returns the sum of all divisors of a given number.\n \"\"\"\n divisors_sum = 0\n for i in range(1, int(... | trial_gpt4o_7 | {
"original_instruction": "You are given an array of n positive integers. You need to process q queries, where each query gives two numbers: l and r. For each query, you need to return the sum of the divisors of all the numbers in the segment of the array from index l to r (both inclusive).\n\n-----Input-----\n\nThe ... | 0.709798 | Taco_49454 | C | [
"sum_of_divisors",
"preprocess",
"prefix_sums",
"query",
"solve"
] | 5 | [
[
"preprocess",
"sum_of_divisors"
],
[
"solve",
"prefix_sums"
],
[
"solve",
"preprocess"
],
[
"solve",
"query"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | f7c17268b477d692705f66b5be844fb4ab188c4d | fde4578a40cd54708ae0716b02ca94f43efe83e9 | |||
v1.0 | complete | Taco | Taco_66349_C | def is_prime(n):
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(15)
False
"""
def count_prime_pairs(test_cases):
""" Count the number of unique pairs (i, j) where i < j and the sum of the pair (nums[i] + nums[j]) is a prime number for each test case.
>>> coun... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def count_prime_pairs(test_cases):
resul... | import pytest
from solution import is_prime, count_prime_pairs, process_input, solve
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_count_prime_pairs():
test_cases = [
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_prime_pairs(test_cases):",
"function_name": "count_prime_pairs",
"parameter_list": "(test_cases)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_0 | {
"original_instruction": "Given a list of N integers, determine the number of unique pairs (i, j) where i < j and the sum of the pair (nums[i] + nums[j]) is a prime number.\n\nINPUT:\nThe first line contains an integer T, the number of test cases.\nEach test case consists of two lines: \n- The first line contains an... | 0.729684 | Taco_66349 | C | [
"is_prime",
"count_prime_pairs",
"process_input",
"solve"
] | 4 | [
[
"count_prime_pairs",
"is_prime"
],
[
"solve",
"count_prime_pairs"
],
[
"solve",
"process_input"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 0fb09bb611d3d0485ec447aa86f34596351729ac | 319d9997b8e1cfdc902e689f81269eecbcba800c | |||
v1.0 | complete | Taco | Taco_76597_C | def is_palindrome_in_both_bases(n: int) -> str:
""" Determine whether a positive integer is a palindrome in both decimal (base 10) representation and binary (base 2) representation.
>>> is_palindrome_in_both_bases(585)
'Yes'
>>> is_palindrome_in_both_bases(123)
'No'
""" | def is_palindrome(s):
return s == s[::-1]
def is_palindrome_in_both_bases(n):
decimal_str = str(n)
binary_str = bin(n)[2:]
if is_palindrome(decimal_str) and is_palindrome(binary_str):
return "Yes"
else:
return "No" | from solution import is_palindrome_in_both_bases
def test_palindrome_in_both_bases():
assert is_palindrome_in_both_bases(585) == "Yes"
assert is_palindrome_in_both_bases(123) == "No"
assert is_palindrome_in_both_bases(1) == "Yes"
assert is_palindrome_in_both_bases(9) == "Yes"
assert is_palindrome_i... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome_in_both_bases(n):",
"function_name": "is_palindrome_in_both_bases",
"parameter_list":... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to determine if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef is_palindrome_bo... | trial_gpt4o_2 | {
"original_instruction": "Given a positive integer n, your task is to determine whether it is a palindrome in both decimal (base 10) representation and binary (base 2) representation. A number is considered a palindrome if it reads the same backwards as forwards, both as a decimal number and a binary number.\n\n----... | 0.790918 | Taco_76597 | C | [
"is_palindrome",
"is_palindrome_in_both_bases"
] | 2 | [
[
"is_palindrome_in_both_bases",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65919af96d5f2af32fa8b5b52dcb4f8965cb3ae6 | 0317f2eaaf558ac7f52a2201afadb7ea88c92ae8 | |||
v1.0 | complete | Taco | Taco_65147_C | def max_non_overlapping_events(events):
"""
Determines the maximum number of non-overlapping events that can be attended.
Parameters:
events (List[Tuple[int, int]]): A list of tuples, each containing the start and end time of an event.
Returns:
int: The maximum number of non-overlappin... | def max_non_overlapping_events(events):
"""
Determines the maximum number of non-overlapping events that can be attended.
Parameters:
events (List[Tuple[int, int]]): A list of tuples, each containing the start and end time of an event.
Returns:
int: The maximum number of non-overlappin... | from solution import get_max_events_from_input
def test_case_1():
input_data = "3\n1 3\n2 4\n3 5"
assert get_max_events_from_input(input_data) == 2
def test_case_2():
input_data = "4\n1 2\n2 3\n3 4\n1 3"
assert get_max_events_from_input(input_data) == 3
def test_case_3():
input_data = "1\n1 2"
... | [
{
"docstring": "Determines the maximum number of non-overlapping events that can be attended.\n\nParameters:\nevents (List[Tuple[int, int]]): A list of tuples, each containing the start and end time of an event.\n\nReturns:\nint: The maximum number of non-overlapping events that can be attended.",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_overlapping_events(events):\n \"\"\"\n Determines the maximum number of non-overlapping events.\n \n Parameters:\n events (list of tuple... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with arranging a series of events in a timeline such that no two events overlap. Each event has a start time and an end time. Given a list of events, your task is to determine the maximum number of non-overlapping events you can attend.\n\nEach event will be represented by a ... | 0.585118 | Taco_65147 | C | [
"max_non_overlapping_events",
"get_max_events_from_input"
] | 2 | [
[
"get_max_events_from_input",
"max_non_overlapping_events"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1fccd78904a2a7f5a5afe822041cf6cfd61997b | f0aad000f5ae72ca7cc9a7bda135ee9eb6d7ec19 | |||
v1.0 | complete | Taco | Taco_59879_C | def preprocess_fruits(fruits):
"""
Preprocesses the fruits list to create a prefix sums array.
"""
pass
def query_sum(prefix_sums, l, r):
"""
Computes the sum of fruits in the range [l, r] using the prefix sums array.
l and r are 1-based indices.
"""
pass
def count_fruits(n, fruits... | def preprocess_fruits(fruits):
"""
Preprocesses the fruits list to create a prefix sums array.
"""
prefix_sums = [0] * (len(fruits) + 1)
for i in range(1, len(fruits) + 1):
prefix_sums[i] = prefix_sums[i - 1] + fruits[i - 1]
return prefix_sums
def query_sum(prefix_sums, l, r):
"""
... | def test_preprocess_fruits():
fruits = [4, 7, 2, 9, 5]
expected_prefix_sums = [0, 4, 11, 13, 22, 27]
assert preprocess_fruits(fruits) == expected_prefix_sums
def test_query_sum():
prefix_sums = [0, 4, 11, 13, 22, 27]
assert query_sum(prefix_sums, 1, 3) == 13
assert query_sum(prefix_sums, 2, 4) ... | [
{
"docstring": "Preprocesses the fruits list to create a prefix sums array.",
"function_declaration": "def preprocess_fruits(fruits):",
"function_name": "preprocess_fruits",
"parameter_list": "(fruits)"
},
{
"docstring": "Computes the sum of fruits in the range [l, r] using the prefix sums a... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def forest_fruits(n, fruits, q, queries):\n \"\"\"\n Computes the sum of fruits in specified ranges for multiple queries.\n \n :param n: int - Number o... | trial_gpt4o_2 | {
"original_instruction": "A forest is a collection of trees. Alice is a caretaker of a special forest where each tree has a distinct number of fruits. Alice wants to count the forest fruits in specific ranges but needs your help to do it efficiently. Given the fruits on the trees in an array and multiple queries whi... | 0.680606 | Taco_59879 | C | [
"preprocess_fruits",
"query_sum",
"count_fruits"
] | 3 | [
[
"count_fruits",
"preprocess_fruits"
],
[
"count_fruits",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 9d3308f75aebf45d7a4377258ff8130de6f8f123 | 87f6c59f8584c43306d76144091eb825a32782d1 | |||
v1.0 | complete | Taco | Taco_70767_C | from typing import List
def smallest_prime_subset_sum(n: int, array: List[int]) -> int:
"""
Given an array of integers, determine whether a subset of the array exists whose sum is prime.
If such a subset exists, return the smallest prime number that can be obtained, otherwise return -1.
>>> smalle... | import itertools
def is_prime(n):
"""
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 smallest_pri... | from solution import smallest_prime_subset_sum
def test_smallest_prime_subset_sum_example():
assert smallest_prime_subset_sum(5, [3, 5, 7, -2, 8]) == 3
def test_smallest_prime_subset_sum_no_primes():
assert smallest_prime_subset_sum(5, [4, 6, 8, 10, 12]) == -1
def test_smallest_prime_subset_sum_single_elemen... | [
{
"docstring": "Check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determine the smallest prime sum from any subset of the array.",
"function_declaration": "def smallest_prime_subset_sum(n, a... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\nimport math\n\ndef is_prime(num):\n \"\"\"\n Function to check if a given number is prime.\n \"\"\"\n if num <= 1:\n return Fa... | trial_gpt4o_1 | {
"original_instruction": "Given an array of integers, determine whether a subset of the array exists whose sum is prime. If such a subset exists, return the smallest prime number that can be obtained, otherwise return -1.\n\nInput Format\n\nThe first line of the input contains an integer ${n}$, which is the number o... | 0.628362 | Taco_70767 | C | [
"is_prime",
"smallest_prime_subset_sum"
] | 2 | [
[
"smallest_prime_subset_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d25ef40a91e2935f5f05a58190d381b9b15ec076 | 7914ecabfc5468e2dadca3303eeff661cc31866c | |||
v1.0 | complete | Taco | Taco_73652_C | from typing import List
def find_words_in_grid(n: int, grid: List[str], k: int, words: List[str]) -> List[str]:
""" For given square grid of characters and a list of words, determine if each word can be found within the grid.
Words can appear in horizontal or vertical directions, either forwards or backwa... | def find_word_in_grid(grid, word):
"""
Returns 'yes' if the word can be found in the grid in horizontal or vertical directions, either forwards or backwards.
Otherwise returns 'no'.
"""
n = len(grid)
word_len = len(word)
# Check horizontally and vertically
for i in range(n):
... | import pytest
from solution import find_words_in_grid
def test_case_sample_1():
n = 4
grid = [
"abcd",
"efgh",
"ijkl",
"mnop"
]
k = 2
words = ["abc", "ponm"]
expected = ["yes", "yes"]
assert find_words_in_grid(n, grid, k, words) == expected
def test_case_sam... | [
{
"docstring": "Returns 'yes' if the word can be found in the grid in horizontal or vertical directions, either forwards or backwards.\nOtherwise returns 'no'.",
"function_declaration": "def find_word_in_grid(grid, word):",
"function_name": "find_word_in_grid",
"parameter_list": "(grid, word)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_word_in_grid(grid, word):\n n = len(grid)\n word_len = len(word)\n \n def check_word(r, c, dr, dc):\n for i in range(word_len):\n ... | trial_gpt4o_4 | {
"original_instruction": "Alice loves to play a puzzle game in which she has a grid of characters and words hidden within the grid. Words can appear in the grid in horizontal or vertical directions, either forwards or backwards. Given a grid and a list of words, Alice wants to know if each word from the list can be ... | 0.616954 | Taco_73652 | C | [
"find_word_in_grid",
"find_words_in_grid"
] | 2 | [
[
"find_words_in_grid",
"find_word_in_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 384f821d46faf7806fa5c499b666ba5114f56a3b | df23e680e222479bbcc8bc7fa432e38ed10f0bd5 | |||
v1.0 | complete | Taco | Taco_67119_C | import re
from typing import List
def is_palindrome(s: str) -> bool:
""" Checks if the given string is a palindrome, ignoring spaces, punctuation, and capitalization.
>>> is_palindrome("A man a plan a canal Panama") == True
>>> is_palindrome("Hello world") == False
"""
def identify_palindromes(strings... | import re
def is_palindrome(s):
"""
Checks if the given string is a palindrome, ignoring spaces, punctuation, and capitalization.
"""
cleaned_string = re.sub(r'[^A-Za-z0-9]', '', s).lower()
return cleaned_string == cleaned_string[::-1]
def identify_palindromes(strings):
"""
Identifies all ... | from solution import is_palindrome, identify_palindromes
def test_is_palindrome():
assert is_palindrome("A man a plan a canal Panama") == True
assert is_palindrome("No lemon, no melon") == True
assert is_palindrome("Hello world") == False
assert is_palindrome("Was it a car or a cat I saw") == True
... | [
{
"docstring": "Checks if the given string is a palindrome, ignoring spaces, punctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Identifies all palindromes in the given list of string... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Returns True if the string s is a palindrome, False otherwise.\n \"\"\"\n # Filter out non-alphanumeric characters and... | trial_gpt4o_1 | {
"original_instruction": "Maria is fascinated by palindromes and wants to write a program to help her find them in a list of strings. A palindrome is a word, phrase, or sequence that reads the same backward as forward, ignoring spaces, punctuation, and capitalization.\n\nCan you help Maria by writing a function that... | 0.862334 | Taco_67119 | C | [
"is_palindrome",
"identify_palindromes"
] | 2 | [
[
"identify_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2e46e63dbf325b31d561fe1fc233ca7a25fba10 | a0be993c91eaeaefe4b79e51a246c080d22082b9 | |||
v1.0 | complete | Taco | Taco_75942_C | def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(11) True
>>> is_prime(15) False
"""
pass
def fibonacci_primes(n: int) -> List[int]:
"""
Returns the first n F... | def is_prime(num):
"""
Check if a number is prime.
"""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i != 0:
continue
return False
return True
def fibonacci_generator():
"""
An infinite generator of Fibonacci numbers.
"""... | from solution import is_prime, fibonacci_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(15) == False
def test_fibonacci_primes():
assert fibonacci_primes(1)... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "An infinite generator of Fibonacci numbers.",
"function_declaration": "def fibonacci_generator():",
"function_name": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True... | trial_gpt4o_1 | {
"original_instruction": "## Task\nGenerate Fibonacci Primes\n\nFibonacci numbers are a classic sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1.\n\nPrime numbers are numbers greater than 1 that are only divisible by 1 and themselves.\n\nA Fibonacci prime is a... | 0.910874 | Taco_75942 | C | [
"is_prime",
"fibonacci_generator",
"fibonacci_primes"
] | 3 | [
[
"fibonacci_primes",
"fibonacci_generator"
],
[
"fibonacci_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c23862eca6e03da0b57534e377df6f1a69e0610d | 6c2bf34336730c4f91af45b62600d3ae7f2044e3 | |||
v1.0 | complete | Taco | Taco_70306_C | MOD = 10**9 + 7
def factorial(n: int) -> int:
""" Calculate the factorial of a number n modulo 10**9 + 7.
>>> factorial(5) == 120
>>> factorial(0) == 1
"""
pass
def mod_inverse(n: int, mod: int) -> int:
""" Calculate the modular inverse of n modulo mod.
>>> mod_inverse(3, 1000000007) == 33... | MOD = 10**9 + 7
def factorial(n):
result = 1
for i in range(2, n + 1):
result = (result * i) % MOD
return result
def mod_inverse(n, mod):
return pow(n, mod-2, mod)
def combination(n, k):
if k == 0 or k == n:
return 1
numerator = factorial(n)
denominator = (factorial(k) * f... | from solution import number_of_ways_to_prepare_dish
def test_case_1():
N = 5
M = 3
ingredients = [1, 2, 3, 4, 5]
assert number_of_ways_to_prepare_dish(N, M, ingredients) == 10
def test_case_2():
N = 6
M = 2
ingredients = [1, 2, 3, 4, 5, 6]
assert number_of_ways_to_prepare_dish(N, M, in... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def mod_inverse(n, mod):",
"function_name": "mod_inverse",
"parameter_list": "(n, mod)"
},
{
"docstring... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import comb\n\nMOD = 10**9 + 7\n\ndef unique_ways(N, M, ingredients):\n \"\"\"\n Returns the number of unique ways to choose M ingredients from a l... | trial_gpt4o_1 | {
"original_instruction": "Our protagonist, Lek, is a budding chef who loves experimenting with new recipes. Today, he wants to determine the unique ways he can prepare a dish using specific ingredients. Can you help him find this out?\n\nYou are given a list of N distinct ingredients and an integer M representing th... | 0.574177 | Taco_70306 | C | [
"factorial",
"mod_inverse",
"combination",
"number_of_ways_to_prepare_dish"
] | 4 | [
[
"combination",
"factorial"
],
[
"combination",
"mod_inverse"
],
[
"number_of_ways_to_prepare_dish",
"combination"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ebb00b7d36c7f48805974cd654d6816bd3305d40 | dfecb9de983ede72c53162860e7beebac319285f | |||
v1.0 | complete | Taco | Taco_65015_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def merge_two_sorted_lists(l1: ListNode, l2: ListNode) -> ListNode:
""" Merge two sorted linked lists into one sorted linked list.
>>> list_from_linked_list(merge_two_sorted_lists(linked_list_from_list([1,... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def merge_two_sorted_lists(l1: ListNode, l2: ListNode) -> ListNode:
dummy = current = ListNode()
while l1 and l2:
if l1.val < l2.val:
current.next = l1
l1 = l1.next
... | from solution import merge_sorted_linked_lists
def test_merge_sorted_linked_lists():
assert merge_sorted_linked_lists([1, 3, 5, 7, 9], [2, 4, 6, 8]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
def test_merge_with_empty_list():
assert merge_sorted_linked_lists([], [2, 4, 6, 8]) == [2, 4, 6, 8]
assert merge_sorted_linke... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef mergeTwoLists(l1, l2):\n \"\"\"\n Merges ... | trial_gpt4o_1 | {
"original_instruction": "Write a function to merge two sorted linked lists into one sorted linked list. \n\nInput:\n- The first line contains an integer n1, the number of elements in the first linked list.\n- The second line contains n1 space-separated integers, the elements of the first linked list.\n- The third l... | 0.556315 | Taco_65015 | C | [
"merge_two_sorted_lists",
"linked_list_from_list",
"list_from_linked_list",
"merge_sorted_linked_lists"
] | 4 | [
[
"merge_sorted_linked_lists",
"linked_list_from_list"
],
[
"merge_sorted_linked_lists",
"list_from_linked_list"
],
[
"merge_sorted_linked_lists",
"merge_two_sorted_lists"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 80677354a85eed71c7798aa15b0de309a6a451a2 | d0efccd6e1971d4bc95403ee7eef90a24ab7fbd7 | |||
v1.0 | complete | Taco | Taco_70022_C | def num_islands(grid: List[str]) -> int:
"""
Find the number of distinct islands in a grid.
>>> num_islands(["11110", "11010", "11000", "00001"])
2
>>> num_islands(["111", "010", "111"])
1
"""
def count_islands(test_cases: List[Tuple[int, int, List[str]]]) -> List[int]:
"""
Get... | def num_islands(grid):
if not grid:
return 0
n, m = len(grid), len(grid[0])
visited = [[False for _ in range(m)] for _ in range(n)]
def dfs(x, y):
if x < 0 or y < 0 or x >= n or y >= m or grid[x][y] == '0' or visited[x][y]:
return
visited[x][y] = True
# ... | def test_num_islands():
assert num_islands(["11110", "11010", "11000", "00001"]) == 2
assert num_islands(["111", "010", "111"]) == 1
def test_count_islands():
test_cases = [
(4, 5, ["11110", "11010", "11000", "00001"]),
(3, 3, ["111", "010", "111"])
]
assert count_islands(test_cases... | [
{
"docstring": null,
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def count_islands(test_cases):",
"function_name": "count_islands",
"parameter_list": "(test_cases)"
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_islands(grid):\n if not grid:\n return 0\n\n n, m = len(grid), len(grid[0])\n visited = [[False for _ in range(m)] for _ in range(n)]\n\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given an n x m grid representing a field. Each cell of the grid can either be land or water. Your goal is to find all the islands in the grid and return the number of distinct islands. An island is a group of connected lands (1's) connected horizontally, vertically, or diagonally. T... | 0.565353 | Taco_70022 | C | [
"num_islands",
"count_islands",
"parse_input",
"main"
] | 4 | [
[
"count_islands",
"num_islands"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 3c287978e264091c230321ab34082b7b100a668f | 3abec815f52c6e9906cee9284b9ff6967eb88c01 | |||
v1.0 | complete | Taco | Taco_74750_C | def total_car_value_in_range(test_cases):
"""
Given a list of car prices and a list of queries, determine the total value of cars within given price ranges.
Each test case contains:
- N: The number of car prices.
- Q: The number of queries.
- car_prices: A list of integers representing the price... | def total_car_value_in_range(test_cases):
results = []
for case in test_cases:
N, Q, car_prices, queries = case['N'], case['Q'], case['car_prices'], case['queries']
prefix_sum = [0] * (N + 1)
# Compute prefix sums for car prices
for i in range(1, N + 1):
... | def test_solver_case_1():
test_cases = [
{
"N": 5,
"Q": 3,
"car_prices": [10000, 20000, 30000, 40000, 50000],
"queries": [(15000, 35000), (5000, 25000), (20000, 60000)]
}
]
expected_output = [[50000, 30000, 140000]]
assert total_car_value_i... | [
{
"docstring": null,
"function_declaration": "def total_car_value_in_range(test_cases):",
"function_name": "total_car_value_in_range",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def find_lower_bound(car_prices, L):",
"function_name": "find_lower... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def total_value_in_price_ranges(test_cases):\n results = []\n \n for test in test_cases:\n N, Q, prices, queries = test\n prices.sort()\n ... | trial_gpt4o_1 | {
"original_instruction": "A car dealership has a list of prices for vehicles in their inventory. The management wants to run some promotional offers, and they wish to determine the total value of cars within specific price ranges. To assist them, you need to write a program to process multiple queries regarding the ... | 0.562638 | Taco_74750 | C | [
"total_car_value_in_range",
"find_lower_bound",
"find_upper_bound"
] | 3 | [
[
"total_car_value_in_range",
"find_lower_bound"
],
[
"total_car_value_in_range",
"find_upper_bound"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 23ce3b647f17256af4c1d6f2e46396fd66e95ab2 | 28b4703300a88e73c0158b4510bb5bf0e056dbef | |||
v1.0 | complete | Taco | Taco_70310_C | def is_valid_palindrome(s: str) -> bool:
"""
Determines if the given string is a valid palindrome, considering only alphanumeric characters and ignoring case.
"""
# Implementation here
def check_palindrome(s: str) -> str:
"""
Outputs 'YES' if the given string is a valid palindrome and 'NO' othe... | def is_valid_palindrome(s):
"""
Determines if the given string is a valid palindrome, considering only alphanumeric characters and ignoring case.
"""
# Normalize the string: remove non-alphanumeric characters and convert to lower case
normalized_s = ''.join(char.lower() for char in s if char.isalnum... | from solution import check_palindrome
def test_example_1():
assert check_palindrome("A man, a plan, a canal: Panama") == "YES"
def test_example_2():
assert check_palindrome("racecar") == "YES"
def test_example_3():
assert check_palindrome("hello") == "NO"
def test_example_4():
assert check_palindrom... | [
{
"docstring": "Determines if the given string is a valid palindrome, considering only alphanumeric characters and ignoring case.",
"function_declaration": "def is_valid_palindrome(s):",
"function_name": "is_valid_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Outputs 'YES' if the g... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_palindrome(s: str) -> str:\n \"\"\"\n Check if the given string is a valid palindrome, considering only alphanumeric characters and ignoring cas... | trial_gpt4o_2 | {
"original_instruction": "Given a string, you need to determine if it is a valid palindrome, considering only alphanumeric characters and ignoring cases and spaces.\n\nA palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward (ignoring spaces, punctuation, and c... | 0.773686 | Taco_70310 | C | [
"is_valid_palindrome",
"check_palindrome"
] | 2 | [
[
"check_palindrome",
"is_valid_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ee82255143d5c7f086eafaf58844c8f2524f754 | b91d61bbfc9575643c977df616b709fbe96594f3 | |||
v1.0 | complete | Taco | Taco_50812_C | def generate_spiral_pattern(n, marbles):
"""Generate a spiral pattern for a given side length of the grid and a sequence of marble identifiers.
Args:
n (int): The side length of the square grid.
marbles (List[int]): A list of unique positive integers representing the identifiers of the marbles.
Ret... | def generate_spiral_pattern(n, marbles):
grid = [[0]*n for _ in range(n)]
top, bottom, left, right = 0, n-1, 0, n-1
direction = 0 # 0-right, 1-down, 2-left, 3-up
index = 0
while top <= bottom and left <= right:
if direction == 0: # Move right
for i in range(left, right + 1... | from solution import generate_spiral_pattern, process_input_and_generate_output, format_output
def test_generate_spiral_pattern_3x3():
marbles = [1, 2, 3, 4, 5, 6, 7, 8, 9]
grid = generate_spiral_pattern(3, marbles)
assert grid == [
[1, 2, 3],
[8, 9, 4],
[7, 6, 5]
]
def test_ge... | [
{
"docstring": null,
"function_declaration": "def generate_spiral_pattern(n, marbles):",
"function_name": "generate_spiral_pattern",
"parameter_list": "(n, marbles)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_generate_output(test_cases):",
"function_name":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_spiral_pattern(N, marbles):\n spiral = [[0] * N for _ in range(N)]\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # right, down, left, up\n ... | trial_gpt4o_2 | {
"original_instruction": "Alice has a collection of different colored marbles, and she loves to arrange them in patterns. She plans to create a spiral pattern on the floor, starting from the center and moving outwards in a clockwise direction. Each marble has a unique identifier (a positive integer). Given the seque... | 0.553061 | Taco_50812 | C | [
"generate_spiral_pattern",
"process_input_and_generate_output",
"format_output"
] | 3 | [
[
"process_input_and_generate_output",
"generate_spiral_pattern"
]
] | 1 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 5de4bef11e22bde82619fccb4587aad3eb8fce96 | 2c5e3f62055a8098cc242439d27daa539df66331 | |||
v1.0 | complete | Taco | Taco_66441_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(level_order):
"""Builds a binary tree from level-order traversal."""
# Implementation here
def tree_height_and_balance(root):
"""
Determines the height of the tree and whe... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(level_order):
from collections import deque
if not level_order or level_order[0] == 'null':
return None
root = TreeNode(int(level_order[0]))
queue = deque([roo... | from solution import process_test_cases
def test_case_1():
T = 2
test_cases = [
"3 9 20 null null 15 7",
"1 2 2 3 3 null null 4 4"
]
result = process_test_cases(T, test_cases)
assert result == ["3 1", "4 0"]
def test_case_single_node():
T = 1
test_cases = ["1"]
result =... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import collections\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right ... | trial_gpt4o_1 | {
"original_instruction": "Binary Tree Height and Balance Check\n\nYou are given the root node of a binary tree. Your task is to write a function to determine the height of the tree and whether the tree is balanced or not.\n\nIn a balanced binary tree, the difference in the height of the left and right subtrees of ev... | 0.630289 | Taco_66441 | C | [
"build_tree",
"tree_height_and_balance",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"build_tree"
],
[
"process_test_cases",
"tree_height_and_balance"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b0cbbfe6683dc456c892b25d2e86d0f1bc392963 | 4fe756d98e42a543271382c927091a3a51a63fa7 | |||
v1.0 | complete | Taco | Taco_82389_C | from typing import List
def max_score(tokens: List[int]) -> int:
""" Determine the maximum score Alex can achieve by selecting tokens according to the game rules.
Alex can pick any number of tokens, but he cannot pick two consecutive tokens. The score is the sum of the numbers on the tokens.
Args:
tok... | def max_score(tokens):
n = len(tokens)
if n == 0:
return 0
if n == 1:
return max(0, tokens[0])
dp = [0] * n
dp[0] = max(0, tokens[0])
dp[1] = max(dp[0], tokens[1])
for i in range(2, n):
dp[i] = max(dp[i - 1], dp[i - 2] + tokens[i])
return dp[-1]
def solve_game... | import pytest
from solution import solve_game, max_score
def test_case_1():
assert solve_game(4, [1, 2, 9, 4]) == 10
def test_case_2():
assert solve_game(5, [3, 2, 5, 10, 7]) == 15
def test_case_3():
assert solve_game(1, [5]) == 5
def test_case_4():
assert solve_game(2, [5, 5]) == 5
def test_case_... | [
{
"docstring": null,
"function_declaration": "def max_score(tokens):",
"function_name": "max_score",
"parameter_list": "(tokens)"
},
{
"docstring": null,
"function_declaration": "def solve_game(n, token_values):",
"function_name": "solve_game",
"parameter_list": "(n, token_values... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_score(tokens):\n n = len(tokens)\n if n == 0:\n return 0\n if n == 1:\n return max(0, tokens[0])\n\n dp = [0] * n\n dp[0] = ma... | trial_gpt4o_7 | {
"original_instruction": "Alex is playing a game with tokens. Each token has a number written on it, and the tokens are arranged in a straight line. The game involves selecting tokens from the line according to the following rules:\n\n1. Alex can pick any number of tokens, but he cannot pick two consecutive tokens.\... | 0.613745 | Taco_82389 | C | [
"max_score",
"solve_game"
] | 2 | [
[
"solve_game",
"max_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 43f6d5cba3303f4959d8d47a4c30b4d837d19e94 | 67fa934b7b86ead9c1bb99aeda94b4ed44086c69 | |||
v1.0 | complete | Taco | Taco_64958_C | def merge_sort(A, left, right):
if left < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid + 1, right)
merge(A, left, mid, right)
def merge(A, left, mid, right):
n1 = mid - left + 1
n2 = right - mid
L = [0] * n1
R = [0] * n2
for i in ... | def merge_sort(A, left, right):
if left < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid + 1, right)
merge(A, left, mid, right)
def merge(A, left, mid, right):
n1 = mid - left + 1
n2 = right - mid
L = [0] * n1
R = [0] * n2
for i in ... | def test_sort_array():
assert sort_array([38, 27, 43, 3, 9, 82, 10]) == [3, 9, 10, 27, 38, 43, 82]
assert sort_array([12, 11, 13, 5, 6]) == [5, 6, 11, 12, 13]
assert sort_array([4]) == [4]
assert sort_array([5, 2]) == [2, 5]
assert sort_array([1, 7, 3, 8, 5, 2, 6, 4]) == [1, 2, 3, 4, 5, 6, 7, 8]
de... | [
{
"docstring": null,
"function_declaration": "def merge_sort(A, left, right):",
"function_name": "merge_sort",
"parameter_list": "(A, left, right)"
},
{
"docstring": null,
"function_declaration": "def merge(A, left, mid, right):",
"function_name": "merge",
"parameter_list": "(A, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge(A, left, mid, right):\n n1 = mid - left + 1\n n2 = right - mid\n \n # Create temporary arrays\n L = [0] * n1\n R = [0] * n2\n \n ... | trial_gpt4o_2 | {
"original_instruction": "Write a program that implements the Merge Sort algorithm to sort an array of integers in ascending order. The algorithm should be based on the following pseudocode:\n\nMergeSort(A, left, right)\n1 if left < right\n2 mid = (left + right) / 2\n3 MergeSort(A, left, mid)\n4 MergeSor... | 0.691215 | Taco_64958 | C | [
"merge_sort",
"merge",
"sort_array"
] | 3 | [
[
"merge_sort",
"merge"
],
[
"sort_array",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 7833e17238857e932ba6e3b1aac8c157d302149d | 75860bf130243aff1b8947aae29165332b37c1c4 | |||
v1.0 | complete | Taco | Taco_78568_C | def product_of_weights_in_mst(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int:
""" You are given an undirected graph with n nodes and m edges. Each edge has a weight associated with it.
Your task is to find the minimum spanning tree (MST) of this graph and compute the product of the weights
of... | 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]... | import pytest
from solution import product_of_weights_in_mst
def test_example_case_1():
n = 4
m = 5
edge_list = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(2, 4, 6),
(3, 4, 2)
]
assert product_of_weights_in_mst(n, m, edge_list) == 6
def test_example_case_2():
n ... | [
{
"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)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\nMOD = 998244353\n\ndef find_mst_product(n, m, edges):\n if m == 0:\n return 1\n\n # Kruskal's algorithm with Union-Find data structure... | trial_gpt4o_9 | {
"original_instruction": "You are given an undirected graph with n nodes and m edges. Each edge has a weight associated with it. Your task is to find the minimum spanning tree (MST) of this graph and compute the product of the weights of all the edges in the MST. \n\nInput\n\nThe first line contains two integers n (... | 0.687642 | Taco_78568 | C | [
"find",
"union",
"kruskal_mst",
"product_of_weights_in_mst",
"main"
] | 5 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"product_of_weights_in_mst",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 7dadc57d742ca6ab538c770b179e74bf632b757b | bd86e8e1b7abb0237d5a00c007b584a5fb40c57b | |||
v1.0 | complete | Taco | Taco_74705_C | def sorted_substrings(S: str) -> list:
"""
Returns all possible substrings of the string S in lexicographic sorted order.
>>> sorted_substrings("bcda")
['a', 'b', 'bc', 'bcd', 'bcda', 'c', 'cd', 'cda', 'd', 'da']
>>> sorted_substrings("abc")
['a', 'ab', 'abc', 'b', 'bc', 'c']
>>> sorted_subs... | def sorted_substrings(S):
"""
Returns all possible substrings of the string S in lexicographic sorted order.
"""
substrings = set()
n = len(S)
for i in range(n):
for j in range(i + 1, n + 1):
substrings.add(S[i:j])
return sorted(substrings)
def print_sorted_substrings(S)... | from solution import sorted_substrings, print_sorted_substrings
import io
import pytest
import sys
def test_sorted_substrings():
assert sorted_substrings("bcda") == ['a', 'b', 'bc', 'bcd', 'bcda', 'c', 'cd', 'cda', 'd', 'da']
assert sorted_substrings("abc") == ['a', 'ab', 'abc', 'b', 'bc', 'c']
assert sort... | [
{
"docstring": "Returns all possible substrings of the string S in lexicographic sorted order.",
"function_declaration": "def sorted_substrings(S):",
"function_name": "sorted_substrings",
"parameter_list": "(S)"
},
{
"docstring": "Print all possible substrings of the string S in lexicographi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_lexicographic_substrings(s):\n \"\"\"\n Returns all possible substrings of the string s in lexicographic sorted order.\n \n :param s: A single ... | trial_gpt4o_2 | {
"original_instruction": "You are given a string $\\textbf{S}$.\n\nYour task is to print all possible substrings of the string $\\textbf{S}$ in lexicographic sorted order.\n\nInput Format\n\nA single line containing the string $\\textbf{S}$.\n\nConstraints\n\n$1 \\leq \\text{len}(S) \\leq 10$\n\nThe string contains ... | 0.62545 | Taco_74705 | C | [
"sorted_substrings",
"print_sorted_substrings"
] | 2 | [
[
"print_sorted_substrings",
"sorted_substrings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c2268c62aa95e8aba4e33c44f71731d7b70b025 | cf90f565bf7ddb03d379cbc98a7411d7e3516ace | |||
v1.0 | complete | Taco | Taco_66378_C | from typing import List
from collections import defaultdict
def find_anagram_groups(words: List[str]) -> List[List[str]]:
"""
Returns groups of anagram words from the given list of words.
:param words: List of words (lowercase English letters only)
:type words: List[str]
:return: List of anagr... | from collections import defaultdict
def find_anagram_groups(words):
"""
Returns groups of anagram words from the given list of words.
:param words: List of words (lowercase English letters only)
:type words: List[str]
:return: List of anagram groups
:rtype: List[List[str]]
"""
anag... | from solution import find_anagram_groups, format_output, group_anagrams
def test_find_anagram_groups():
words = ["listen", "silent", "enlist", "inlets", "stop", "tops", "pots"]
result = find_anagram_groups(words)
assert result == [['enlist', 'inlets', 'listen', 'silent'], ['pots', 'stop', 'tops']]
def tes... | [
{
"docstring": "Returns groups of anagram words from the given list of words.\n\n:param words: List of words (lowercase English letters only)\n:type words: List[str]\n:return: List of anagram groups\n:rtype: List[List[str]]",
"function_declaration": "def find_anagram_groups(words):",
"function_name": "f... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef find_anagram_groups(words):\n anagram_dict = defaultdict(list)\n \n for word in words:\n sorted_word = '... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of words. Your task is to find all the unique anagrams in the list and return the groups of words that are anagrams of each other.\n\nAn anagram of a word is a rearrangement of its letters to form another word. For example, the words \"listen\" and \"silent\" are anagra... | 0.623055 | Taco_66378 | C | [
"find_anagram_groups",
"format_output",
"group_anagrams"
] | 3 | [
[
"group_anagrams",
"find_anagram_groups"
],
[
"group_anagrams",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 1dc77953e980e331405ea41a66ca1c348a767358 | 1c2539a7f375bf3d789745c70790235f1056cfd3 | |||
v1.0 | complete | Taco | Taco_70430_C | from typing import List
def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(17)
True
>>> is_prime(19)
True
>>> is_prime(1)
False
>>> is_prime(0)
False
>>> is_prime(15)
False
"""
def prime_nonprime_sort(numbers: List[... | def is_prime(num):
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def prime_nonprime_sort(numbers):
primes = [num for num in number... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(15) == False
def test_prime_nonprime_sort():
assert prime_nonprime_sort([10, 29, 3, 20, 17, 5, 18, 2, 11, 19]) ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_nonprime_sort(numbers):",
"function_name": "prime_nonprime_sort",
"parameter_list": "(numbers)"
}... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_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 ... | trial_gpt4o_2 | {
"original_instruction": "$Aarav$ is an esteemed mathematician in the kingdom of $Mathland$. To protect the kingdom from invaders, he proposed a safeguard mechanism that uses prime numbers. As a result, the king has charged him with a special task to encrypt messages using prime numbers. Aarav has to arrange $N$ int... | 0.734869 | Taco_70430 | C | [
"is_prime",
"prime_nonprime_sort"
] | 2 | [
[
"prime_nonprime_sort",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ed246afbc0f94cd6c624950bd15ac387de4525d7 | 3c0ba54d1a09b9690078575cd5189c9c3699f9f5 | |||
v1.0 | complete | Taco | Taco_69557_C | from typing import List
def largest_square(matrix: List[List[int]]) -> int:
"""
Determines the largest square sub-matrix within a given binary matrix that contains only 1's.
Args:
matrix (List[List[int]]): A binary matrix containing only 0's and 1's.
Returns:
int: The size of the larg... | def largest_square(matrix):
"""
Returns the size of the largest square sub-matrix containing only 1's in the given binary matrix.
"""
if not matrix:
return 0
M = len(matrix)
N = len(matrix[0])
# Create a DP table to store the size of the largest square submatrix ending at (i, j... | def test_largest_square_basic():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert largest_square(matrix) == 2
def test_largest_square_all_ones():
matrix = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 0]
]
assert lar... | [
{
"docstring": "Returns the size of the largest square sub-matrix containing only 1's in the given binary matrix.",
"function_declaration": "def largest_square(matrix):",
"function_name": "largest_square",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_square(matrix):\n \"\"\"\n Returns the size of the largest square sub-matrix containing only 1's in the given binary matrix.\n \"\"\"\n if ... | trial_gpt4o_0 | {
"original_instruction": "A new startup called \"Binary Matrix Inc.\" is working on analyzing binary matrices. They want to identify specific patterns within these matrices. You have been enlisted to help them with one such problem.\n\nThe problem is to determine the largest square sub-matrix within a given binary m... | 0.561846 | Taco_69557 | C | [
"largest_square",
"analyze_matrices",
"parse_input",
"main"
] | 4 | [
[
"analyze_matrices",
"largest_square"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e3fed2eac4965cbc9d87066ef72e3d14d15be5b1 | 0f6c8963176300acd9bd50e6652f4efafb3dcbd4 | |||
v1.0 | complete | Taco | Taco_69690_C | def process_grid(n: int, grid: List[List[int]]) -> None:
"""
Perform a sequence of operations to transform the grid into a Latin square using the fewest number of operations.
The operations you can perform are swaps of entire rows or entire columns.
Input
The first line contains one integer n (... | def is_latin_square(grid, n):
for i in range(n):
if len(set(grid[i])) != n or len(set(row[i] for row in grid)) != n:
return False
return True
def transpose(grid):
return [list(row) for row in zip(*grid)]
def process_grid(n, grid):
from collections import defaultdict
row_swaps =... | from solution import process_grid
def test_process_grid_case_1():
n = 4
grid = [
[1, 2, 3, 4],
[4, 3, 2, 1],
[1, 3, 2, 4],
[4, 1, 2, 3]
]
process_grid(n, grid)
def test_process_grid_case_2():
n = 3
grid = [
[1, 2, 3],
[3, 2, 1],
[2, 3, 1]... | [
{
"docstring": null,
"function_declaration": "def is_latin_square(grid, n):",
"function_name": "is_latin_square",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def transpose(grid):",
"function_name": "transpose",
"parameter_list": "(grid)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_operations_to_latin_square(grid):\n n = len(grid)\n \n # Output list for operations\n operations = []\n \n # Check if a row needs to be ... | trial_gpt4o_8 | {
"original_instruction": "You are given a grid of size n x n (1 ≤ n ≤ 50) filled with integers. Your task is to perform a sequence of operations to transform the grid so that every row and every column contains the integers 1 through n exactly once (i.e., the grid should become a Latin square). The operations you ca... | 0.643594 | Taco_69690 | C | [
"is_latin_square",
"transpose",
"process_grid"
] | 3 | [
[
"process_grid",
"transpose"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1d35f70390b7dd0e157ad3f44f04cefcadfb33f2 | d66d84b67d43955cae2f36fe57c3a863bdaf4c55 | |||
v1.0 | complete | Taco | Taco_79874_C | def is_permuted_multiple(x: int, k: int) -> bool:
"""
Check if k * x is a permuted multiple of x.
>>> is_permuted_multiple(142857, 2)
True
>>> is_permuted_multiple(142857, 3)
True
>>> is_permuted_multiple(142857, 4)
True
>>> is_permuted_multiple(142857, 5)
True
>>> is_permut... | def is_permuted_multiple(x, k):
"""
Check if k * x is a permuted multiple of x.
"""
return sorted(str(x)) == sorted(str(k * x))
def find_permuted_multiple(n):
"""
Finds the smallest integer x such that 2x, 3x, 4x, 5x, and 6x are all permuted multiples of x.
The value of x should be greater ... | from solution import is_permuted_multiple, find_permuted_multiple
def test_is_permuted_multiple():
assert is_permuted_multiple(142857, 2)
assert is_permuted_multiple(142857, 3)
assert is_permuted_multiple(142857, 4)
assert is_permuted_multiple(142857, 5)
assert is_permuted_multiple(142857, 6)
a... | [
{
"docstring": "Check if k * x is a permuted multiple of x.",
"function_declaration": "def is_permuted_multiple(x, k):",
"function_name": "is_permuted_multiple",
"parameter_list": "(x, k)"
},
{
"docstring": "Finds the smallest integer x such that 2x, 3x, 4x, 5x, and 6x are all permuted multi... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_permuted_multiple(n):\n \"\"\"\n Finds the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x are all \n permuted multiples of x and x ... | trial_gpt4o_1 | {
"original_instruction": "A \"permuted multiple\" of a number is another number that contains the same digits but in a different order. For example, `142857` is a permuted multiple of `285714` since both numbers contain the same digits. \n\nWrite a function named `find_permuted_multiple` that takes an integer input ... | 0.642356 | Taco_79874 | C | [
"is_permuted_multiple",
"find_permuted_multiple"
] | 2 | [
[
"find_permuted_multiple",
"is_permuted_multiple"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ea9ded20441f0ab863def061e462fc867f626654 | 3632a40b132c2027a9e826f0caaece58c9dc799d | |||
v1.0 | complete | Taco | Taco_76661_C | def is_prime(num):
"""
Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(20)
False
"""
def find_primes_in_range(n, m):
"""
Find all prime numbers in the range from n to m (i... | def is_prime(num):
"""
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):
return False
... | from solution import is_prime, find_primes_in_range, sum_and_product_of_digits_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(20) == False
def test_find_primes_in_range():
assert find_... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find all prime numbers in the range from n to m (inclusive).",
"function_declaration": "def find_primes_in_range(... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5... | trial_gpt4o_1 | {
"original_instruction": "Dr. : John, have you ever worked with prime numbers?\n\nJohn: I've had some experience with them. Is there something specific you have in mind?\n\nDr. : Yes, I'd like you to create a program that identifies prime numbers within a certain range and performs some operations on them.\n\nJohn: ... | 0.727865 | Taco_76661 | C | [
"is_prime",
"find_primes_in_range",
"sum_and_product_of_digits_of_primes"
] | 3 | [
[
"find_primes_in_range",
"is_prime"
],
[
"sum_and_product_of_digits_of_primes",
"find_primes_in_range"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9c4059f855fa62da3fea34db22ff5bf3519a6be3 | 1eba57220a99e76977bcb0b4f7c9949d0352a9f5 | |||
v1.0 | complete | Taco | Taco_85938_C | def is_power_of_two(n: int) -> bool:
""" Check if a given integer is a power of 2.
>>> is_power_of_two(1) True
>>> is_power_of_two(2) True
>>> is_power_of_two(3) False
>>> is_power_of_two(4) True
>>> is_power_of_two(0) False
"""
def verify_bob_claim(t: int, integer_list: List[int]) -> s... | def is_power_of_two(n):
return (n > 0) and (n & (n - 1)) == 0
def verify_bob_claim(t, integer_list):
for num in integer_list:
if not is_power_of_two(num):
return "NO"
return "YES" | from solution import is_power_of_two, verify_bob_claim
def test_is_power_of_two():
assert is_power_of_two(1) == True
assert is_power_of_two(2) == True
assert is_power_of_two(4) == True
assert is_power_of_two(8) == True
assert is_power_of_two(3) == False
assert is_power_of_two(6) == False
as... | [
{
"docstring": null,
"function_declaration": "def is_power_of_two(n):",
"function_name": "is_power_of_two",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def verify_bob_claim(t, integer_list):",
"function_name": "verify_bob_claim",
"parameter_list": "(t... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_power_of_two(n):\n \"\"\"\n Checks if a given integer n is a power of two.\n \"\"\"\n return (n > 0) and (n & (n - 1)) == 0\n\ndef check_powers_... | trial_gpt4o_2 | {
"original_instruction": "Alice has received a list of integers from her friend Bob. Bob claims that each integer in the list is a power of 2. Alice wants to verify Bob's claim and needs your help to check if all integers in the list are indeed powers of 2. \n\nAn integer n is a power of 2 if there exists an integer... | 0.664022 | Taco_85938 | C | [
"is_power_of_two",
"verify_bob_claim"
] | 2 | [
[
"verify_bob_claim",
"is_power_of_two"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 643249721f61cd12c592d41cab9fcd805e5a5b04 | c2db7ae00fb99f2f04ea3fca3d6836a25a2f9e7a | |||
v1.0 | complete | Taco | Taco_66886_C | import heapq
from typing import List, Tuple, Union
def single_source_shortest_path(V: int, E: int, edges: List[Tuple[int, int, int]], source: int) -> List[Union[int, str]]:
"""Implement Dijkstra's algorithm to find the shortest path from a source vertex to all other vertices in a weighted graph.
Args:
... | import heapq
def dijkstra(V, edges, source):
graph = {i: [] for i in range(V)}
for u, v, w in edges:
graph[u].append((v, w))
distances = [float('inf')] * V
distances[source] = 0
priority_queue = [(0, source)]
while priority_queue:
current_distance, current_vertex = hea... | def test_single_source_shortest_path():
assert single_source_shortest_path(5, 6, [[0, 1, 2], [0, 2, 4], [1, 2, 1], [1, 3, 7], [2, 4, 3], [3, 4, 1]], 0) == [0, 2, 3, 9, 6]
assert single_source_shortest_path(4, 4, [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4]], 0) == [0, 1, 3, 6]
assert single_source_shortest_p... | [
{
"docstring": null,
"function_declaration": "def dijkstra(V, edges, source):",
"function_name": "dijkstra",
"parameter_list": "(V, edges, source)"
},
{
"docstring": null,
"function_declaration": "def single_source_shortest_path(V, E, edges, source):",
"function_name": "single_source... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(V, edges, source):\n graph = [[] for _ in range(V)]\n for u, v, w in edges:\n graph[u].append((v, w))\n \n distance... | trial_gpt4o_1 | {
"original_instruction": "A popular problem in graph theory is the Shortest Path Problem, where the goal is to find the shortest path between two vertices in a weighted graph. In this task, you are asked to implement Dijkstra's algorithm to solve the single-source shortest path problem for a given graph.\n\nWrite a ... | 0.664076 | Taco_66886 | C | [
"dijkstra",
"single_source_shortest_path"
] | 2 | [
[
"single_source_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 05f38ea8a6635bc81e917e15ab556638d928997f | 96c1923f9973798bc34fe44d16f5fa3c7db50093 | |||
v1.0 | complete | Taco | Taco_79652_C | import heapq
from typing import List, Tuple
def min_cost(N: int, M: int, edges: List[Tuple[int, int, int]], A: int, B: int) -> int:
""" Determine the minimum cost to traverse from Vertex A to Vertex B in an undirected graph.
Args:
N (int): Number of vertices.
M (int): Number of edges.
edges (L... | import heapq
def dijkstra(graph, start, end, n):
distances = {i: float('infinity') for i in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_vertex = heapq.heappop(priority_queue)
if current_vertex == end:
... | from solution import min_cost
def test_min_cost_basic():
N = 5
M = 6
edges = [
(1, 2, 2),
(1, 3, 4),
(2, 3, 1),
(2, 4, 7),
(3, 5, 3),
(4, 5, 2)
]
A = 1
B = 5
assert min_cost(N, M, edges, A, B) == 6
def test_no_path():
N = 4
M = 2
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, end, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end, n)"
},
{
"docstring": null,
"function_declaration": "def min_cost(N, M, edges, A, B):",
"function_name": "min_cost",
"parameter_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, end, n):\n distances = {i: float('infinity') for i in range(1, n + 1)}\n distances[start] = 0\n priority_queue ... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected graph with N vertices numbered 1 through N and M edges. Each edge has a weight assigned to it, representing the cost to travel along that edge. Your task is to determine the minimum cost required to traverse from Vertex A to Vertex B. Consider that there might be... | 0.681368 | Taco_79652 | C | [
"dijkstra",
"min_cost"
] | 2 | [
[
"min_cost",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c8f7f499fc347ba98d0173cc812952d73d808d55 | 7bc36f220382ca67f190f780d26edd77205b5e39 | |||
v1.0 | complete | Taco | Taco_85283_C | def sieve(n):
"""Generate a list of primes up to n using the Sieve of Eratosthenes."""
pass
def count_prime_pairs(k):
"""
Count the number of distinct pairs of prime numbers (p1, p2)
such that p1 + p2 = k, where (p1, p2) and (p2, p1) are considered the same pair.
>>> count_prime_pairs(10) == 2... | def sieve(n):
"""Generate a list of primes up to n using the Sieve of Eratosthenes."""
is_prime = [True] * (n+1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n+1, p):
is_prime[i] = False
p += 1
prime_numbers = [p for p in range... | import pytest
from solution import sieve, count_prime_pairs, solve_primes
def test_sieve():
assert sieve(10) == [2, 3, 5, 7]
assert sieve(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_count_prime_pairs():
assert count_prime_pairs(10) == 2 # (3, 7) and (5, 5)
assert count_prime_pairs(26) == 3 # (3, 23... | [
{
"docstring": "Generate a list of primes up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Count the number of distinct pairs of prime numbers (p1, p2) \nsuch that p1 + p2 = k, where (p1, ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ret... | trial_gpt4o_1 | {
"original_instruction": "Alice is learning about prime numbers and has come across an interesting sequence where each number is the sum of two prime numbers. She is curious about how often a given number can be represented as the sum of two prime numbers.\n\nYour task is to count the number of distinct pairs of pri... | 0.656155 | Taco_85283 | C | [
"sieve",
"count_prime_pairs",
"solve_primes"
] | 3 | [
[
"count_prime_pairs",
"sieve"
],
[
"solve_primes",
"count_prime_pairs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a0c00fd6b45ed85f2a2dd4418235465a94648d83 | 403c6a264506f949a1be1aa73adca0e455b2656a | |||
v1.0 | complete | Taco | Taco_85315_C | from typing import List, Tuple
def solve(N: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
"""
Process queries to find the maximum edge weight on the path from node u to node v in a tree.
Args:
N (int): The number of nodes in the tree.
edges (List[Tuple[int, ... | import sys
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
def build_tree(N, edges):
tree = defaultdict(list)
for u, v, w in edges:
tree[u].append((v, w))
tree[v].append((u, w))
return tree
def preprocess_lca(N, tree, root=1):
LOG = 20
parent = [[-1] * (N +... | def test_solution():
# Test case from the example
N = 5
edges = [
(1, 2, 3),
(1, 3, 2),
(2, 4, 4),
(2, 5, 6)
]
queries = [
(1, 4),
(3, 5),
(4, 5)
]
expected = [4, 6, 6]
assert solve(N, edges, queries) == expected
# Additional t... | [
{
"docstring": null,
"function_declaration": "def build_tree(N, edges):",
"function_name": "build_tree",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def preprocess_lca(N, tree, root=1):",
"function_name": "preprocess_lca",
"parameter_list": "(N... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(10**6)\n\ndef build_tree(N, edges):\n tree = defaultdict(list)\n for u, v, w ... | trial_gpt4o_0 | {
"original_instruction": "Problem\n\nYou are given a tree with $N$ nodes, where each node is labeled from 1 to $N$. The tree is represented as an undirected graph with $N-1$ edges, where each edge has a certain weight.\n\nYour task is to process $Q$ queries on the tree. Each query is of the form $(u, v)$ and asks fo... | 0.684317 | Taco_85315 | C | [
"build_tree",
"preprocess_lca",
"query_lca",
"solve"
] | 4 | [
[
"solve",
"build_tree"
],
[
"solve",
"preprocess_lca"
],
[
"solve",
"query_lca"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 356aa08a320189f132946a6b895ee39d079e57c3 | 573547c7cb44a460560a1a18afc6fcbf401f00dd | |||
v1.0 | complete | Taco | Taco_79010_C | def largest_rectangle_area(histogram):
""" Calculate the largest rectangle area in a histogram.
>>> largest_rectangle_area([2, 1, 5, 6, 2, 3, 2])
10
>>> largest_rectangle_area([6, 2, 5, 4, 5, 1, 6])
12
"""
pass
def process_histograms(test_cases):
""" Process multiple test cases for hist... | def largest_rectangle_area(histogram):
"""
Calculate the largest rectangle area in a histogram.
:param histogram: List of integers representing the heights of the histogram
:return: The area of the largest rectangle possible in the histogram
"""
# Create an empty stack. The stack holds indexes o... | def test_largest_rectangle_area():
# Test cases from the prompt
assert largest_rectangle_area([2, 1, 5, 6, 2, 3, 2]) == 10
# Additional test cases
assert largest_rectangle_area([6, 2, 5, 4, 5, 1, 6]) == 12
assert largest_rectangle_area([1, 1, 1, 1, 1, 1, 1]) == 7
assert largest_rectangle_area([1... | [
{
"docstring": "Calculate the largest rectangle area in a histogram.\n:param histogram: List of integers representing the heights of the histogram\n:return: The area of the largest rectangle possible in the histogram",
"function_declaration": "def largest_rectangle_area(histogram):",
"function_name": "l... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(histograms):\n def calculate_max_area(histogram):\n n = len(histogram)\n stack = []\n max_area = 0\n\n in... | trial_gpt4o_2 | {
"original_instruction": "Develop a program to determine the largest rectangle in a histogram.\n\nINPUT:\n\nThe first line contains the number of test cases t. For each test case, the first line contains n (the number of bars in the histogram). The second line contains n integers representing the heights of the bars... | 0.559417 | Taco_79010 | C | [
"largest_rectangle_area",
"process_histograms",
"parse_input",
"generate_output"
] | 4 | [
[
"process_histograms",
"largest_rectangle_area"
]
] | 1 | [
"parse_input",
"generate_output"
] | false | [] | false | pytest | false | [] | true | 9edf5fa3fcb9dd57e405ab62f945f9120101d1b7 | 0f066dc9aa113d8a3862f1b04257681bf1227f73 | |||
v1.0 | complete | Taco | Taco_90573_C | def remove_duplicate_logs(logs):
"""
Removes duplicate log entries from the list while maintaining the order of their first occurrence.
"""
pass
def process_log_file(log_file_content):
"""
Processes the log file contents. The first line contains the number of lines n, followed by the log entrie... | def remove_duplicate_logs(logs):
"""
Removes duplicate log entries from the list while maintaining the order of their first occurrence.
"""
seen = set()
unique_logs = []
for log in logs:
if log not in seen:
unique_logs.append(log)
seen.add(log)
... | from solution import remove_duplicate_logs, process_log_file
def test_remove_duplicate_logs():
logs = [
"Started processing",
"Started processing",
"Completed processing",
"Database connection established",
"Started processing",
"Database connection closed"
]
... | [
{
"docstring": "Removes duplicate log entries from the list while maintaining the order of their first occurrence.",
"function_declaration": "def remove_duplicate_logs(logs):",
"function_name": "remove_duplicate_logs",
"parameter_list": "(logs)"
},
{
"docstring": "Processes the log file cont... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def remove_duplicate_logs(logs):\n \"\"\"\n Removes duplicate log entries while preserving the order of their first occurrence.\n \n :param logs: List ... | trial_gpt4o_2 | {
"original_instruction": "You've been hired to develop a basic file handling utility that processes log files. The task is to remove duplicate entries and preserve the order of the first occurrences of each log entry.\n\nA log file contains multiple lines, each representing a log entry. The file can have duplicate l... | 0.52479 | Taco_90573 | C | [
"remove_duplicate_logs",
"process_log_file"
] | 2 | [
[
"process_log_file",
"remove_duplicate_logs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de3c8ccbec6391b7350c211c6c7dde88bc569020 | 39a4209f8d5239fa9f9be0aacb7af32b1324ae45 | |||
v1.0 | complete | Taco | Taco_75913_C | def floyd_warshall(n, dist):
"""Applies the Floyd-Warshall algorithm to find shortest paths between all pairs of nodes."""
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][k] != float('inf') and dist[k][j] != float('inf'):
dist[i][j] = m... | def floyd_warshall(n, dist):
"""Applies the Floyd-Warshall algorithm to find shortest paths between all pairs of nodes."""
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][k] != float('inf') and dist[k][j] != float('inf'):
dist[i][j] = m... | def test_shortest_path():
t = 2
test_cases = [
{'n': 4, 'm': 4, 's': 0, 'd': 3, 'roads': [(0, 1, 3), (1, 2, 1), (2, 3, 2), (0, 3, 10)]},
{'n': 4, 'm': 2, 's': 1, 'd': 3, 'roads': [(1, 2, 5), (2, 3, 7)]}
]
expected_output = [6, 12]
assert shortest_path(t, test_cases) == expe... | [
{
"docstring": "Applies the Floyd-Warshall algorithm to find shortest paths between all pairs of nodes.",
"function_declaration": "def floyd_warshall(n, dist):",
"function_name": "floyd_warshall",
"parameter_list": "(n, dist)"
},
{
"docstring": null,
"function_declaration": "def shortest... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def floyd_warshall(num_intersections, roads, start, destination):\n # Initialize the distance matrix with infinite distances\n inf = float('inf')\n dist =... | trial_gpt4o_2 | {
"original_instruction": "In a city, there are N intersections connected by M bidirectional roads. The distance between each pair of intersections is given in a matrix, with the entry distance[i][j] representing the distance between intersection i and intersection j. Some entries might contain -1, indicating no dire... | 0.668093 | Taco_75913 | C | [
"floyd_warshall",
"shortest_path"
] | 2 | [
[
"shortest_path",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 53f3788db27bda6a16f2b2b114af8f8c1c406b6a | 55e1edad539e2384d971886528e7367b8e7960ce | |||
v1.0 | complete | Taco | Taco_78988_C | def find_max_path_sum(n: int, level_order: List[int], edges: List[Tuple[int, int]]) -> int:
""" Ivy loves working with binary trees.
Find the maximum path sum in a binary tree.
A path in the binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them.
... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def build_tree(level_order, edges):
if not level_order:
return None
nodes = [None] + [TreeNode(val) for val in level_order]
for u, v in edges:
if nodes[v].left is None:
... | from solution import find_max_path_sum
def test_example_case():
n = 5
level_order = [1, 2, 3, 4, 5]
edges = [(2, 1), (3, 1), (4, 2), (5, 2)]
assert find_max_path_sum(n, level_order, edges) == 11
def test_single_node():
n = 1
level_order = [10]
edges = []
assert find_max_path_sum(n, lev... | [] | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(10**6)\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n ... | trial_gpt4o_6 | {
"original_instruction": "Ivy loves working with binary trees. She comes across a problem where she needs to find the maximum path sum in a binary tree. A path in the binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can be included in the path a... | 0.663867 | Taco_78988 | C | [
"build_tree",
"max_path_sum_helper",
"max_path_sum",
"find_max_path_sum"
] | 4 | [
[
"find_max_path_sum",
"build_tree"
],
[
"find_max_path_sum",
"max_path_sum"
],
[
"max_path_sum",
"max_path_sum_helper"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | ea217e1368fa65535ded1ea49fa103c94620510b | 70b42ee070ebe04be36e898260abe6c171708ed1 | |||
v1.0 | complete | Taco | Taco_91187_C | def minimum_moves_to_sort(lst):
"""
Returns the minimum number of adjacent swaps required to sort the list.
>>> minimum_moves_to_sort([4, 3, 2, 1, 5]) 6
>>> minimum_moves_to_sort([1, 2, 3, 4, 5]) 0
>>> minimum_moves_to_sort([5, 4, 3, 2, 1]) 10
>>> minimum_moves_to_sort([2, 4, 1, 3, 5]) 3
>>>... | def count_inversions(arr):
"""
Helper function to count inversions in the list using merge sort technique.
"""
if len(arr) < 2:
return arr, 0
mid = len(arr) // 2
left, left_inversions = count_inversions(arr[:mid])
right, right_inversions = count_inversions(arr[mid:])
me... | from solution import minimum_moves_to_sort
def test_example_case():
assert minimum_moves_to_sort([4, 3, 2, 1, 5]) == 6
def test_already_sorted():
assert minimum_moves_to_sort([1, 2, 3, 4, 5]) == 0
def test_reverse_sorted():
assert minimum_moves_to_sort([5, 4, 3, 2, 1]) == 10
def test_random_case():
... | [
{
"docstring": "Helper function to count inversions in the list using merge sort technique.",
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": "Merge two lists and count split inversions.",
"function_de... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_swaps_to_sort(arr):\n \"\"\"\n Returns the minimum number of swaps required to sort the array in non-decreasing order.\n \"\"\"\n n = len(a... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of integers. In one move, you can select any two adjacent integers in the list and swap them. Your task is to find the minimum number of moves required to sort the list in non-decreasing order.\n\n\n-----Input-----\n\nThe first line of the input contains a single intege... | 0.658484 | Taco_91187 | C | [
"count_inversions",
"merge_and_count",
"minimum_moves_to_sort"
] | 3 | [
[
"count_inversions",
"merge_and_count"
],
[
"minimum_moves_to_sort",
"count_inversions"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0e84fe1be282f7663fb3cbcd8ad0d28043c061bd | ae43bfb1664885cf8bf7a0ba4f385211e3ad90b6 | |||
v1.0 | complete | Taco | Taco_91021_C | from typing import List
def warehouse_delivery(m: int, n: int, grid: List[List[int]]) -> int:
"""
Determine if there exists a path for the robot from the top-left corner to the bottom-right corner.
If there is a path, return the length of the shortest path, otherwise return -1.
>>> warehouse_delivery(... | from collections import deque
def shortest_path(grid):
"""
Returns the length of the shortest path from top-left corner to bottom-right corner
in a grid avoiding obstacles, or -1 if no such path exists.
"""
m = len(grid)
n = len(grid[0])
if grid[0][0] == 1 or grid[m-1][n-1] == 1:
... | def test_warehouse_delivery():
grid1 = [
[0, 0, 1],
[0, 0, 1],
[1, 0, 0]
]
assert warehouse_delivery(3, 3, grid1) == 5
grid2 = [
[0, 0, 1],
[1, 1, 1],
[1, 0, 0]
]
assert warehouse_delivery(3, 3, grid2) == -1
grid3 = [
[0, 0, 0],
... | [
{
"docstring": "Returns the length of the shortest path from top-left corner to bottom-right corner\nin a grid avoiding obstacles, or -1 if no such path exists.",
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"parameter_list": "(grid)"
},
{
"docstring"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(grid):\n \"\"\"\n Determines the shortest path length from the top-left corner\n to the bottom-right co... | trial_gpt4o_1 | {
"original_instruction": "Alex is a delivery robot who has been assigned a task to deliver packages in a warehouse organized as an m x n grid. The robot starts at the top-left corner (grid[0][0]) and needs to reach the bottom-right corner (grid[m-1][n-1]) to deliver a package. The grid has cells that are either empt... | 0.590668 | Taco_91021 | C | [
"shortest_path",
"warehouse_delivery"
] | 2 | [
[
"warehouse_delivery",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | be840149b00c5ac758e74a58bf3d74f67d22618f | 39ac81de43022abc3fb0b53d4906be9502ae9a1a | |||
v1.0 | complete | Taco | Taco_85974_C | def is_prime(num):
""" Check if a number is prime.
Args:
num (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = ... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i <= num):
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def can_split_into_three_pri... | from solution import can_split_into_three_prime_sums
def test_example_1():
assert can_split_into_three_prime_sums(8, [2, 4, 5, 1, 2, 7, 3, 6]) == "NO"
def test_example_2():
assert can_split_into_three_prime_sums(5, [1, 1, 1, 1, 1]) == "NO"
def test_prime_splits_1():
assert can_split_into_three_prime_sums... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def can_split_into_three_prime_sums(n, lst):",
"function_name": "can_split_into_three_prime_sums",
"parameter... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers. Your goal is to split the list into exactly three contiguous subarrays such that the sum of the elements in each subarray is a prime number. Determine whether such a division is possible.\n\n\n-----Input-----\n\nThe first line contains a single integer $n$ ... | 0.722571 | Taco_85974 | C | [
"is_prime",
"can_split_into_three_prime_sums"
] | 2 | [
[
"can_split_into_three_prime_sums",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13b86970f5b81ead56e07db47d78fb957b8dec97 | cec1dcbf3ed42c158b41341847033bef5aa8b157 | |||
v1.0 | complete | Taco | Taco_90715_C | def sum_of_digits(n: int) -> int:
""" Compute the sum of the digits of the integer n.
>>> sum_of_digits(123) 6
>>> sum_of_digits(0) 0
>>> sum_of_digits(2021) 5
>>> sum_of_digits(1000000) 1
>>> sum_of_digits(987654) 39
"""
def f(n: int) -> int:
""" Compute the value of f(n) where f(n... | def sum_of_digits(n):
"""
Returns the sum of the digits of the integer n.
"""
return sum(int(digit) for digit in str(n))
def f(n):
"""
Returns the sum of the digits of n combined with the
value of n minus the sum of its digits.
f(n) = n + g(n)
"""
return n + sum_of_digits(n) | from solution import sum_of_digits, f
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(0) == 0
assert sum_of_digits(2021) == 5
assert sum_of_digits(1000000) == 1
assert sum_of_digits(987654) == 39
def test_f():
assert f(123) == 129
assert f(0) == 0 # should not... | [
{
"docstring": "Returns the sum of the digits of the integer n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the digits of n combined with the \nvalue of n minus the sum of its digits.\nf(n)... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of the integer n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef f(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "Anna wants to design a recursive function to solve a mathematical problem. The function takes an integer $n$ and returns the sum of the digits of $n$ combined with the value of $n$ minus the sum of its digits. She denotes this function as $f(n)$, where $f(n) = n + g(n)$, and $g(n)$ is a fun... | 0.771142 | Taco_90715 | C | [
"sum_of_digits",
"f"
] | 2 | [
[
"f",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f9e7635111f088be61785647881b93c72532bffe | 9a24477b8b53643d63e8faf7d3684573d2c42a16 | |||
v1.0 | complete | Taco | Taco_91308_C | def check_palindromic_numbers(numbers: List[str]) -> List[str]:
""" For each number in numbers, check if it is palindromic in both decimal and binary representations.
Args:
numbers (list of str): List of strings where each string is a decimal number.
Returns:
list of str: List of "Yes" or ... | def is_palindromic(s):
"""
Helper function to check if a string s is palindromic.
"""
return s == s[::-1]
def check_palindromic_numbers(numbers):
"""
For each number in numbers, check if it is palindromic in both decimal and binary representations.
Args:
numbers (list of str): List... | from solution import check_palindromic_numbers
def test_check_palindromic_numbers():
assert check_palindromic_numbers(['585', '5', '21', '65', '217']) == ['Yes', 'Yes', 'No', 'No', 'No']
def test_single_number_yes():
assert check_palindromic_numbers(['3']) == ['Yes']
def test_single_number_no():
asse... | [
{
"docstring": "Helper function to check if a string s is palindromic.",
"function_declaration": "def is_palindromic(s):",
"function_name": "is_palindromic",
"parameter_list": "(s)"
},
{
"docstring": "For each number in numbers, check if it is palindromic in both decimal and binary represent... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic(s):\n \"\"\"Check if the given string is palindromic.\"\"\"\n return s == s[::-1]\n\ndef check_palindromic_numbers(numbers):\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "Write a program that checks if the given strings are palindromic numbers when interpreted as decimal (base-10) and binary (base-2). A palindromic number is one that reads the same backward as forward. You need to verify both representations for each given number.\n\ninput\n\nThe input consi... | 0.785029 | Taco_91308 | C | [
"is_palindromic",
"check_palindromic_numbers"
] | 2 | [
[
"check_palindromic_numbers",
"is_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb41167108b0fe4a992188642b1105239a3d4272 | dd26b1b0cb1f5dd993d15ce7393204110d99b8b9 | |||
v1.0 | complete | Taco | Taco_70716_C | def sieve(max_num):
"""
Generate a list of booleans representing primality of numbers from 0 to max_num.
"""
# Implementation here
pass
def prime_product(l, r, primes, is_prime, MOD=10**9 + 7):
"""
Calculate the product of all prime numbers between l and r inclusive.
Return -1 if there ... | def sieve(max_num):
"""
Generate a list of booleans representing primality of numbers from 0 to max_num.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
for p in range(2, int(max_num**0.5) + 1):
if is_prime[p]:
for i in range(p * p, max_num + 1, p... | import pytest
from solution import sieve, prime_product, process_test_cases
def test_sieve():
is_prime, primes = sieve(30)
expected_primes_up_to_30 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
assert primes == expected_primes_up_to_30
assert is_prime[0] == False
assert is_prime[1] == False
assert is_... | [
{
"docstring": "Generate a list of booleans representing primality of numbers from 0 to max_num.",
"function_declaration": "def sieve(max_num):",
"function_name": "sieve",
"parameter_list": "(max_num)"
},
{
"docstring": "Calculate the product of all prime numbers between l and r inclusive.\n... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generate a list of prime numbers up to n (inclusive) using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_... | trial_gpt4o_8 | {
"original_instruction": "Alice and Bob love playing a game involving prime numbers. Together, they came up with a new challenge: finding the product of all prime numbers between two given numbers inclusive.\n\nGiven two positive integers, l and r, Alice wants to know the product of all prime numbers in this range m... | 0.597013 | Taco_70716 | C | [
"sieve",
"prime_product",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"prime_product"
],
[
"process_test_cases",
"sieve"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 5af6945e6da51c1131c27f36e9823ed6ad017e0e | b62eb6cedb16ac4f14b34328583795aa2f42ea54 | |||
v1.0 | complete | Taco | Taco_85802_C | def minimum_communication_cost(N: int, M: int, connections: List[List[int]]) -> int:
""" Find the minimum communication cost to connect all computers in the network.
The function takes the number of computers N, the number of connections M, and a list of connections.
Each connection is represented by a list... | def find(parent, i):
if parent[i] == i:
return i
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] = xroot
... | from solution import minimum_communication_cost
def test_sample_input():
N, M = 4, 5
connections = [
[1, 2, 1],
[1, 3, 4],
[2, 3, 2],
[3, 4, 3],
[2, 4, 5]
]
assert minimum_communication_cost(N, M, connections) == 6
def test_no_edges():
N, M = 4, 0
connec... | [
{
"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)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_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 = f... | trial_gpt4o_2 | {
"original_instruction": "You are managing a network of computers in a corporate office. Each computer in the network is represented as a node, and the connections between them are represented as edges. The network is represented by a graph where each edge has a weight associated with it, representing the cost of co... | 0.659738 | Taco_85802 | C | [
"find",
"union",
"kruskalMST",
"minimum_communication_cost"
] | 4 | [
[
"kruskalMST",
"find"
],
[
"kruskalMST",
"union"
],
[
"minimum_communication_cost",
"kruskalMST"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 3db3abdcd34a7469255ead20d4bcc66b9c54576b | cc5c8515cef76526ae066714c65c49ae9cf73e57 | |||
v1.0 | complete | Taco | Taco_92615_C | def count_vowels_and_consonants_output(s: str) -> str:
"""
Given a string S consisting of only lowercase alphabetic characters, determine
the number of vowels and consonants present in the string.
Vowels are 'a', 'e', 'i', 'o', and 'u'; all other alphabetic characters are consonants.
Parameters:... | def count_vowels_and_consonants(s):
"""
Returns the count of vowels and consonants in the given string s.
"""
vowels = 'aeiou'
n_vowels = sum(1 for char in s if char in vowels)
n_consonants = sum(1 for char in s if char not in vowels)
return n_vowels, n_consonants
def count_vowels_... | from solution import count_vowels_and_consonants_output
def test_hello():
assert count_vowels_and_consonants_output("hello") == "2 3"
def test_programming():
assert count_vowels_and_consonants_output("programming") == "3 8"
def test_minimum_length_string():
assert count_vowels_and_consonants_output("a") ... | [
{
"docstring": "Returns the count of vowels and consonants in the given string s.",
"function_declaration": "def count_vowels_and_consonants(s):",
"function_name": "count_vowels_and_consonants",
"parameter_list": "(s)"
},
{
"docstring": "Returns the count of vowels and consonants in the give... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_vowels_and_consonants(s):\n \"\"\"\n Returns the count of vowels and consonants in the string.\n \"\"\"\n vowels = 'aeiou'\n vowel_count =... | trial_gpt4o_2 | {
"original_instruction": "Given a string S consisting of only lowercase alphabetic characters, you need to determine how many vowels and consonants are present in the string. For the purpose of this question, vowels are 'a', 'e', 'i', 'o', and 'u', and all other alphabetic characters are consonants.\n\n------ Input ... | 0.868115 | Taco_92615 | C | [
"count_vowels_and_consonants",
"count_vowels_and_consonants_output"
] | 2 | [
[
"count_vowels_and_consonants_output",
"count_vowels_and_consonants"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f22f149c5d213d1e71e0cc35ef841d20c0138bd | 9a38f7ef5994f879e0541ae6eafbcc69b1174968 | |||
v1.0 | complete | Taco | Taco_96412_C | def isDigitProductPrime(N: int) -> int:
""" Given a positive integer N, determine if the product of its digits is a prime number.
A prime number is a number that is greater than 1 and has no positive divisors other than 1 and itself.
>>> isDigitProductPrime(23)
0
>>> isDigitProductPrime(37)
... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
def isDigitProductPrime(N):
digits = [int(d) for d in str(N)]
... | from solution import isDigitProductPrime
def test_example_1():
assert isDigitProductPrime(23) == 0
def test_example_2():
assert isDigitProductPrime(37) == 0
def test_example_3():
assert isDigitProductPrime(25) == 0
def test_single_digit_primes():
# 2, 3, 5, and 7 should all be prime
assert i... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def isDigitProductPrime(N):",
"function_name": "isDigitProductPrime",
"parameter_list": "(N)"
}
] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3... | trial_gpt4o_0 | {
"original_instruction": "Given a positive integer N, determine if the product of its digits is a prime number. A prime number is a number that is greater than 1 and has no positive divisors other than 1 and itself.\n\nExample 1:\nInput:\nN = 23\nOutput:\n1\nExplanation:\nThe product of digits of 23 is 2 * 3 = 6. Si... | 0.718007 | Taco_96412 | C | [
"is_prime",
"isDigitProductPrime"
] | 2 | [
[
"isDigitProductPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c540c009bc0295000ee7cc4ef29e1e43ef6bd2b | d99575512ccd693e3baaa598fd7a0a59b16b47a6 | |||
v1.0 | complete | Taco | Taco_73572_C | def solve_maze_escape_problem(m, n, maze):
"""
Determine the minimum number of steps required to escape the maze
starting from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1).
If it is not possible to escape the maze, return -1.
Constraints:
- 1 ≤ m, n ≤ 1000
Inpu... | from collections import deque
def min_steps_to_escape_maze(m, n, maze):
# Directions for movement: up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
def is_valid(x, y):
return 0 <= x < m and 0 <= y < n and maze[x][y] == '.'
# BFS from the top-left corner
queue ... | from solution import solve_maze_escape_problem
def test_maze_escape_example1():
m = 5
n = 5
maze = [
"...#.",
"#..#.",
"#..#.",
".#..#",
"#.#.."
]
assert solve_maze_escape_problem(m, n, maze) == 8
def test_maze_escape_example2():
m = 5
n = 5
maze... | [
{
"docstring": null,
"function_declaration": "def min_steps_to_escape_maze(m, n, maze):",
"function_name": "min_steps_to_escape_maze",
"parameter_list": "(m, n, maze)"
},
{
"docstring": null,
"function_declaration": "def solve_maze_escape_problem(m, n, maze):",
"function_name": "solv... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_escape_maze(m, n, maze):\n \"\"\"\n Returns the minimum number of steps required to escape the maze from to... | trial_gpt4o_9 | {
"original_instruction": "You are given an m x n grid representing a maze. Each cell in the maze can either be a wall (#) or a path (.). You want to escape the maze starting from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1). You can move up, down, left, or right, but not diagonally. Determine the... | 0.642797 | Taco_73572 | C | [
"min_steps_to_escape_maze",
"solve_maze_escape_problem"
] | 2 | [
[
"solve_maze_escape_problem",
"min_steps_to_escape_maze"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3f62fce6405b43b80b7559dfbf5791a7cfaed8a6 | 6cde4d2016f116d1ecd2309f998d2c72c8db53b3 | |||
v1.0 | complete | Taco | Taco_91218_C | def minimum_tour_time(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Ash wants to visit all the tourist attractions in his city. There are n attractions, and there are m direct roads connecting some of these attractions.
Ash is currently at attraction 1, and he wants to visit all attraction... | import itertools
def tsp(graph, n, start=0):
"""
Solve the Travelling Salesman Problem using dynamic programming and bit masking.
:param graph: 2D list representing the adjacency matrix of the graph.
:param n: Number of vertices in the graph.
:param start: The starting vertex.
:return: Min... | from solution import minimum_tour_time
def test_example_1():
n = 4
m = 6
roads = [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(2, 3, 35),
(2, 4, 25),
(3, 4, 30)
]
assert minimum_tour_time(n, m, roads) == 80
def test_example_2():
n = 4
m = 3
road... | [
{
"docstring": "Solve the Travelling Salesman Problem using dynamic programming and bit masking.\n\n:param graph: 2D list representing the adjacency matrix of the graph.\n:param n: Number of vertices in the graph.\n:param start: The starting vertex.\n:return: Minimum travel cost to visit all vertices and return... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef min_travel_time(n, m, roads):\n import sys\n from collections import defaultdict\n \n # Create a graph using ... | trial_gpt4o_3 | {
"original_instruction": "Ash wants to visit all the tourist attractions in his city. There are n attractions, and there are m direct roads connecting some of these attractions. Ash is currently at attraction 1, and he wants to visit all attractions at least once before returning to attraction 1. Each road has a tra... | 0.722533 | Taco_91218 | C | [
"tsp",
"minimum_tour_time"
] | 2 | [
[
"minimum_tour_time",
"tsp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ecbca2e655eb6ea16a668b2302501df9e84922ef | 52b478e38dd84297a3cebc6f8cc25c7568f3355e | |||
v1.0 | complete | Taco | Taco_65512_C | class Book:
def __init__(self, title, author, publication_year, genre, page_count):
self.title = title
self.author = author
self.publication_year = int(publication_year)
self.genre = genre
self.page_count = int(page_count)
def matches_filter(self, filters):
... | class Book:
def __init__(self, title, author, publication_year, genre, page_count):
self.title = title
self.author = author
self.publication_year = int(publication_year)
self.genre = genre
self.page_count = int(page_count)
def matches_filter(self, filters):
... | import pytest
from solution import digital_library
def test_single_query_single_filter():
input_str = """5
Harry_Potter_1 J.K.Rowling 1997 Fantasy 223
Harry_Potter_2 J.K.Rowling 1998 Fantasy 251
The_Hobbit J.R.R.Tolkien 1937 Fantasy 310
1984 George_Orwell 1949 Dystopian 328
To_Kill_a_Mockingbird Harper_Lee 1960 Fi... | [] | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def filter_and_sort_books(books, queries):\n def filter_books(book, conditions):\n for cond in conditions:\n key, value = cond.split('=')\n ... | trial_gpt4o_8 | {
"original_instruction": "You are designing a new database system called DigiLib for a digital library to manage books. Each book has several attributes including title, author, publication year, genre, and page count. Your system must support dynamic queries that allows users to retrieve a list of books based on di... | 0.526374 | Taco_65512 | C | [
"parse_input",
"parse_query",
"process_queries",
"digital_library"
] | 4 | [
[
"digital_library",
"parse_input"
],
[
"digital_library",
"process_queries"
],
[
"process_queries",
"parse_query"
]
] | 3 | [
"parse_input",
"process_queries"
] | false | [
"Book"
] | true | pytest | true | [] | true | f223742b1dfac637b5f0bc5d39de5ce0c9b70cc1 | 977d5d1d8c3ddecb054bbce97d5aa905078b1330 | |||
v1.0 | complete | Taco | Taco_92249_C | def is_palindrome(s: str) -> bool:
""" Checks if a given string s is a palindrome.
>>> is_palindrome("abccba")
True
>>> is_palindrome("abc")
False
>>> is_palindrome("a")
True
>>> is_palindrome("aa")
True
"""
def can_be_divided_into_three_palindromic_parts(s: str) -> str:
... | def is_palindrome(s):
"""
Checks if a given string s is a palindrome.
"""
return s == s[::-1]
def can_be_divided_into_three_palindromic_parts(s):
"""
Determines if a given string s can be divided into three non-empty
palindromic parts.
"""
n = len(s)
for i in range(1, n - 1):
... | from solution import is_palindrome, can_be_divided_into_three_palindromic_parts, process_test_cases
def test_is_palindrome():
assert is_palindrome("abccba") == True
assert is_palindrome("abc") == False
assert is_palindrome("a") == True
assert is_palindrome("aa") == True
def test_can_be_divided_into_th... | [
{
"docstring": "Checks if a given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Determines if a given string s can be divided into three non-empty \npalindromic parts.",
"function_... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef can_split_into_three_palindromes(s):\n n = len(s)\n for i in range(1, n-1):\n for j in range(i+1... | trial_gpt4o_6 | {
"original_instruction": "Katerina is preparing for her competitive programming exam. One of the important topics is understanding and working with strings, especially involving palindromes. Katerina decides to practice with a problem involving finding specific palindromes within a string.\n\nKaterina's task is to d... | 0.730317 | Taco_92249 | C | [
"is_palindrome",
"can_be_divided_into_three_palindromic_parts",
"process_test_cases"
] | 3 | [
[
"can_be_divided_into_three_palindromic_parts",
"is_palindrome"
],
[
"process_test_cases",
"can_be_divided_into_three_palindromic_parts"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 945a8c7982f08d00c4c4123d2de8157c70b15eef | 88d8a6dafc308f27c7e657267bca21a01c8ebecf | |||
v1.0 | complete | Taco | Taco_88276_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(node_map):
""" Build the binary tree from the given node map.
"""
pass
def lowest_common_ancestor(root, p, q):
""" Find the lowest common ancestor (LCA) of two nodes in a b... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(node_map):
if not node_map:
return None
nodes = {val: TreeNode(val) for val in node_map}
for val, (left, right) in node_map.items():
if left != -1:
n... | from solution import TreeNode, build_tree, lowest_common_ancestor, find_lca
def test_example_case():
n = 9
tree_data = [
(3, 5, 1),
(5, 6, 2),
(1, 0, 8),
(6, -1, -1),
(2, 7, 4),
(0, -1, -1),
(8, -1, -1),
(7, -1, -1),
(4, -1, -1)
]
... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes, val_to_node):\n ... | trial_gpt4o_1 | {
"original_instruction": "Time Limit: 8 sec / Memory Limit: 64 MB\n\nYou are given a binary tree structure where each node contains a unique integer value. The task is to find the lowest common ancestor (LCA) of two given nodes in the tree. The LCA of two nodes `p` and `q` in a binary tree is defined as the lowest n... | 0.581053 | Taco_88276 | C | [
"build_tree",
"lowest_common_ancestor",
"find_lca"
] | 3 | [
[
"find_lca",
"build_tree"
],
[
"find_lca",
"lowest_common_ancestor"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8219c61b5620f21bdb8e9c0267f8d1e030ebc6bf | f69cfb56c90d420bf04440bdeb64e80e5d8f5ce6 | |||
v1.0 | complete | Taco | Taco_97748_C | def find_palindromes(n: int) -> List[int]:
"""
Returns a list of all palindrome numbers from 1 to n.
>>> find_palindromes(100)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99]
>>> find_palindromes(10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> find_palindromes(1)
[1]
>>> find_p... | def is_palindrome(num):
"""Helper function to check if a given number is a palindrome."""
return str(num) == str(num)[::-1]
def find_palindromes(n):
"""
Returns a list of all palindrome numbers from 1 to n.
"""
return [i for i in range(1, n + 1) if is_palindrome(i)] | from solution import find_palindromes
def test_find_palindromes_small_range():
assert find_palindromes(10) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
def test_find_palindromes_medium_range():
assert find_palindromes(50) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44]
def test_find_palindromes_large_range():
assert fi... | [
{
"docstring": "Helper function to check if a given number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all palindrome numbers from 1 to n.",
"function_declaration": ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef p... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes an integer input n and returns a list of all integers from 1 to n that are palindromes. A palindrome is a number that reads the same forwards and backwards, such as 121 or 454. Your function should efficiently identify palindromic numbers within the given range a... | 0.74765 | Taco_97748 | C | [
"is_palindrome",
"find_palindromes"
] | 2 | [
[
"find_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 55f620f8d4f1e7a68e58a7a33c3cb1ca544d826a | 1053e14d17df4b33c71e5d069756793de44d2a5a | |||
v1.0 | complete | Taco | Taco_96575_C | def max_independent_set(N, edges):
""" Determine the maximum number of nodes that can be visited starting from any node under the constraint
that no two consecutive visited nodes are direct neighbors in the tree structure.
Args:
- N (int): Number of nodes in the tree.
- edges (List[Tuple[int, ... | def dfs(node, parent, adj, dp):
# Current node is either included or excluded in the independent set
included, excluded = 1, 0
for child in adj[node]:
if child != parent:
child_included, child_excluded = dfs(child, node, adj, dp)
included += child_excluded # If current node ... | import pytest
from solution import max_independent_set
def test_sample_input_1():
assert max_independent_set(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 3
def test_sample_input_2():
assert max_independent_set(4, [(1, 2), (2, 3), (3, 4)]) == 2
def test_single_node():
assert max_independent_set(1, []) == 1
de... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, adj, dp):",
"function_name": "dfs",
"parameter_list": "(node, parent, adj, dp)"
},
{
"docstring": null,
"function_declaration": "def max_independent_set(N, edges):",
"function_name": "max_independent_set",
"param... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dfs(node, parent, adj, dp):\n # Current node is either included or excluded in the independent set\n included, excluded = 1, 0\n for child in adj[node... | trial_gpt4o_0 | {
"original_instruction": "Consider a tree with N nodes, each uniquely labeled from 1 to N. A tree is defined as an acyclic connected graph. You are given the tree in the form of an adjacency list, where each node is associated with a list of its neighboring nodes.\n\nCreate a program that can determine the maximum n... | 0.571418 | Taco_96575 | C | [
"dfs",
"max_independent_set"
] | 2 | [
[
"max_independent_set",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c353eded39012bc310103a1e4f391d81610e9cfe | abab31d843b7481738608bd841f711c323e6e523 | |||
v1.0 | complete | Taco | Taco_91751_C | from typing import List
def perform_operations(operations: List[str]) -> List[int]:
""" Perform a series of operations on an array and return results of MaxSubArray operations.
Operations are defined as:
1. Append(x) - Append the integer x to the end of the array.
2. Remove(x) - Remove ... | def perform_operations(operations):
arr = []
results = []
for operation in operations:
parts = operation.split()
K = int(parts[0])
if K == 1:
x = int(parts[1])
arr.append(x)
elif K == 2:
x = int(parts[1])
arr = [y ... | from solution import perform_operations
def test_example_case():
operations = [
"1 1",
"1 -2",
"1 3",
"1 2",
"3 1 3",
"2 -2",
"3 1 3"
]
result = perform_operations(operations)
assert result == [3, 6]
def test_empty_array():
operations = []
... | [
{
"docstring": null,
"function_declaration": "def perform_operations(operations):",
"function_name": "perform_operations",
"parameter_list": "(operations)"
},
{
"docstring": null,
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"paramete... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_operations(Q, operations):\n \"\"\"\n Process the given operations on the array and return the results of K=3 operations.\n \n :param Q: An... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers and a series of operations to perform on the array. The operations are defined as follows:\n\n1. `K=1, Append(x)` - Append the integer `x` to the end of the array.\n2. `K=2, Remove(x)` - Remove all occurrences of the integer `x` from the array.\n3. `K=3, M... | 0.699501 | Taco_91751 | C | [
"perform_operations",
"max_subarray_sum"
] | 2 | [
[
"perform_operations",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0cd6f05516e11988656b3de71519cf0f76de1eec | 3d581fa9b2d1b64126a186a33b0b38f0058f22b1 | |||
v1.0 | complete | Taco | Taco_93729_C | from typing import List, Optional
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def reverse_level_order_traversal(nodes: List[Optional[int]]) -> List[List[int]]:
""" Return the level order traversal of the binary tree nodes' values in reverse or... | from collections import deque
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(nodes):
"""
Builds a binary tree from a list of integers where None represents missing nodes.
"""
if not nodes:
return None
... | from solution import reverse_level_order_traversal
def test_case_1():
assert reverse_level_order_traversal([3, 9, 20, None, None, 15, 7]) == [[15, 7], [9, 20], [3]]
def test_case_2():
assert reverse_level_order_traversal([1, 2, 3, 4, 5, None, 6, None, None, 7, 8]) == [[7, 8], [4, 5, 6], [2, 3], [1]]
def test... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nYou are given a binary tree, and your task is to write a function that returns the level order traversal of its nodes' values in reverse order. That is, the values should be returned from the bottom level to the top level, with each level's values from left to right.\n\nInput\n\n... | 0.534314 | Taco_93729 | C | [
"build_tree",
"level_order_bottom",
"reverse_level_order_traversal"
] | 3 | [
[
"reverse_level_order_traversal",
"build_tree"
],
[
"reverse_level_order_traversal",
"level_order_bottom"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2407f18ee06d0bbad45880740a9f4595dbace79f | 6103a3531912d4ee17847719a205ddab1972ebda | |||
v1.0 | complete | Taco | Taco_90489_C | def smallest_nonrepresentable_prefix_sum(arr):
""" Determine the smallest positive integer that cannot be represented
as the subset sum of some prefixes of the list arr.
>>> smallest_nonrepresentable_prefix_sum([1, 2, 3, 10, 20]) == 7
>>> smallest_nonrepresentable_prefix_sum([1, 1, 1, 1]) == 5
>>> ... | def smallest_nonrepresentable_prefix_sum(arr):
arr.sort()
smallest_missing_sum = 1
for num in arr:
if num > smallest_missing_sum:
break
smallest_missing_sum += num
return smallest_missing_sum
def solve(t, cases):
results = []
for case in cases:
n, a... | from solution import smallest_nonrepresentable_prefix_sum, solve, parse_input
def test_smallest_nonrepresentable_prefix_sum():
assert smallest_nonrepresentable_prefix_sum([1, 2, 3, 10, 20]) == 7
assert smallest_nonrepresentable_prefix_sum([1, 1, 1, 1]) == 5
assert smallest_nonrepresentable_prefix_sum([1, 2... | [
{
"docstring": null,
"function_declaration": "def smallest_nonrepresentable_prefix_sum(arr):",
"function_name": "smallest_nonrepresentable_prefix_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve(t, cases):",
"function_name": "solve",
"par... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def smallest_missing_positive_integer(test_cases):\n results = []\n for test_case in test_cases:\n _, numbers = test_case[0], test_case[1:]\n n... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. For each integer in the list, determine the smallest positive integer that cannot be represented as the subset sum of some of its prefixes.\n\nINPUT:\n\nFirst line contains an integer t, the number of test cases.\nThe next t lines each contain a single inte... | 0.648312 | Taco_90489 | C | [
"smallest_nonrepresentable_prefix_sum",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"smallest_nonrepresentable_prefix_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 366c18ea1942c1220ee447793dedf95d5892a838 | 09c1b4853719cdcba1f7c93dfaf53ed2a4eb2f4a | |||
v1.0 | complete | Taco | Taco_93084_C | def find_shortest_path(grid, start, end):
"""
You are given a grid representing a field with obstacles, empty cells, and a single destination cell. Your task is to navigate through the field from a given starting point to the destination using the shortest possible path. The grid has the following characters:
... | from collections import deque
def find_shortest_path(grid, start, end):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
rows, cols = len(grid), len(grid[0])
visited = [[False for _ in range(cols)] for _ in range(rows)]
queue = deque([(start[0], start[1], 0)]) # (row, col, distance)
while queu... | def test_sample_input1():
input_data = "5 5\nS....\n.....\n..#..\n.#.#.\n....D\n-1"
assert main(input_data) == [8]
def test_sample_input2():
input_data = "4 5\nS....\n#####\n#...#\n....D\n-1"
assert main(input_data) == ["Unreachable"]
def test_single_row():
input_data = "1 5\nS...D\n-1"
assert... | [
{
"docstring": null,
"function_declaration": "def find_shortest_path(grid, start, end):",
"function_name": "find_shortest_path",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_start_end(grid):",
"function_name": "find_start_end",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path_in_grid(grid):\n def bfs(start, destination, n, m):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid representing a field with obstacles, empty cells, and a single destination cell. Your task is to navigate through the field from a given starting point to the destination using the shortest possible path. The grid has the following characters:\n\n* '.' - an empty cell t... | 0.701136 | Taco_93084 | C | [
"find_shortest_path",
"find_start_end",
"solve_datasets",
"parse_input",
"main"
] | 5 | [
[
"solve_datasets",
"find_shortest_path"
],
[
"solve_datasets",
"find_start_end"
]
] | 2 | [
"solve_datasets",
"parse_input"
] | false | [] | false | pytest | false | [] | true | 921a36d6fc8570e28fd1b10ad2a818382eaedda9 | 91e1f2a376faf544796df094e34aabbabe5d3e10 | |||
v1.0 | complete | Taco | Taco_98150_C | def generate_prime_grid(n: int) -> List[List[int]]:
""" Generate an n x n grid filled with prime numbers where no two adjacent
cells (horizontally, vertically, or diagonally) contain the same prime number.
>>> generate_prime_grid(1)
[[2]]
>>> generate_prime_grid(2)
# Possible Output
... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def generate_primes(n):
pr... | import pytest
from solution import generate_prime_grid
def test_generate_prime_grid_1x1():
expected_output = [[2]]
assert generate_prime_grid(1) == expected_output
def test_generate_prime_grid_2x2():
result = generate_prime_grid(2)
assert len(result) == 2
assert all(len(row) == 2 for row in result... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def generate_primes(n):",
"function_name": "generate_primes",
"parameter_list": "(n)"
},
{
"docstring... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "Square Grid of Primes\n\nYou are given an `n x n` grid. Each cell in the grid should be filled with a number such that the number is prime and no two adjacent cells (horizontally, vertically, or diagonally) contain the same prime number. Write a program that generates a valid grid for given... | 0.630963 | Taco_98150 | C | [
"is_prime",
"generate_primes",
"generate_prime_grid",
"print_grid"
] | 4 | [
[
"generate_prime_grid",
"generate_primes"
],
[
"generate_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fdd5f0848e616e810a25f701fcac9aa910a8496e | 68dfa4c0e00a8f04b51be29bfa94c2749a8a40db | |||
v1.0 | complete | Taco | Taco_96798_C | from typing import List
def is_prime(n: int) -> bool:
"""
Checks if the number n is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(0)
False
>>> is_prime(1)
False
>>> is_prime(-5)
Fals... | def is_prime(n):
"""
Checks if the number n is a prime number.
Parameters:
n (int): The number to check.
Returns:
bool: True if n is prime, False otherwise.
"""
if n <= 1:
return False
if n in (2, 3):
return True
if n % 2 == 0 or n % 3 == 0:
return False... | from solution import is_prime, list_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-5) == False
assert is_prime(13) == True
... | [
{
"docstring": "Checks if the number n is a prime number.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "## Preface\n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Checking if a number is prime can be computationally intensive, especially for large numbers.\n\n## The Problem\n\nCreate a function `is_prime` that checks if a given posit... | 0.856188 | Taco_96798 | C | [
"is_prime",
"list_primes"
] | 2 | [
[
"list_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b59ca77f42047b7a5968db508e51556b237752c0 | b36ee82594f4a7f9a0c6cdfb6132169589d617b1 | |||
v1.0 | complete | Taco | Taco_96552_C | from typing import List, Tuple
def count_valid_triplets(nums: List[int]) -> int:
"""
Count the number of valid triplets that can form a triangle.
"""
pass
def count_triangles(test_cases: List[Tuple[int, int, List[int]]]) -> List[int]:
""" Return the number of valid triplets for each test case.
... | def count_valid_triplets(nums):
"""
Count the number of valid triplets that can form a triangle.
"""
nums.sort()
n = len(nums)
count = 0
for i in range(n-2):
k = i + 2
for j in range(i+1, n-1):
while (k < n and nums[i] + nums[j] > nums[k]):
k += 1... | from solution import count_triangles, parse_input, format_output
def test_count_triangles():
input_str = "2\n4 7\n2 2 3 4\n5 10\n1 2 3 4 5"
test_cases = parse_input(input_str)
results = count_triangles(test_cases)
assert results == [3, 3]
def test_parse_input():
input_str = "2\n4 7\n2 2 3 4\n... | [
{
"docstring": "Count the number of valid triplets that can form a triangle.",
"function_declaration": "def count_valid_triplets(nums):",
"function_name": "count_valid_triplets",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def count_triangles(test_cases):"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_valid_triplets(nums):\n \"\"\"\n Count the number of valid triplets that can form a triangle.\n \"\"\"\n nums.sort()\n n = len(nums)\n ... | trial_gpt4o_0 | {
"original_instruction": "Given an integer array `nums` and an integer `target`, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.\n\nA triplet is valid if it satisfies the condition: `a + b > c`, `a + c > b`, and `b + c > a`.\n\n------ Input F... | 0.629605 | Taco_96552 | C | [
"count_valid_triplets",
"count_triangles",
"parse_input",
"format_output"
] | 4 | [
[
"count_triangles",
"count_valid_triplets"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | b8d60bb82e58fbf1fb0703546b183a5c4aeb8270 | 978a2794bd4ab8760881df75c4b6337497926ad4 | |||
v1.0 | complete | Taco | Taco_99001_C | def is_prime(num: int) -> bool:
"""Helper function to determine if a number is prime."""
pass
def count_prime_subsequences(n: int, arr: List[int]) -> int:
""" Count the number of non-empty prime-subsequences in the array.
>>> count_prime_subsequences(4, [2, 3, 4, 6])
3
>>> count_prime_subs... | def is_prime(num):
"""Helper function to determine if a number is prime."""
if num <= 1:
return False
if num == 2:
return True # 2 is the smallest prime number
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return ... | from solution import is_prime, count_prime_subsequences
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
assert is_prime(1) == False
assert is_prime... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Count the number of non-empty prime-subsequences in the array.",
"function_declaration": "def count... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Helper function to determine if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tr... | trial_gpt4o_0 | {
"original_instruction": "Michael is a fan of prime numbers and subsequences. He defines a prime-subsequence as a subsequence of a given array that consists entirely of prime numbers. However, he finds it difficult to count all such prime-subsequences in a given array.\n\nGiven an array of integers, can you help Mic... | 0.76004 | Taco_99001 | C | [
"is_prime",
"count_prime_subsequences"
] | 2 | [
[
"count_prime_subsequences",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc34cda4ad2556d2ec5f41fbc26cbff422eb7f8d | 9623b863789d8b92d81fd4eacb33e791700bd7a3 | |||
v1.0 | complete | Taco | Taco_96671_C | def sieve(n):
""" Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if is_prime[p] == True:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
primes =... | def sieve(n):
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if is_prime[p] == True:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
primes = []
for p in range(2, n + 1):
if is_prime[p]:
primes.append(p)
return pr... | from solution import process_test_cases
def test_process_test_cases():
assert process_test_cases(2, [10, 20]) == [17, 77]
assert process_test_cases(1, [2]) == [2]
assert process_test_cases(3, [1, 4, 30]) == [0, 5, 129]
assert process_test_cases(2, [0, 7]) == [0, 17]
assert process_test_cases(1, [10... | [
{
"docstring": null,
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_sum(n):",
"function_name": "prime_sum",
"parameter_list": "(n)"
},
{
"docstring": null,
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\... | trial_gpt4o_2 | {
"original_instruction": "Peter has been fascinated by prime numbers recently. He wants to test his understanding by creating a function to find the sum of all prime numbers up to a given number N. Additionally, to ensure his code's efficiency, he wants to limit the runtime by checking only up to the square root of ... | 0.676709 | Taco_96671 | C | [
"sieve",
"prime_sum",
"process_test_cases"
] | 3 | [
[
"prime_sum",
"sieve"
],
[
"process_test_cases",
"prime_sum"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | c243a0182fd8ded972e22c7da7a6f5e69e55af24 | 90ed748100ff94500b5795395e702597702c1fd4 | |||
v1.0 | complete | Taco | Taco_98426_C | def max_area(heights):
"""
Return the maximum area of water that can be contained by two vertical lines.
"""
# Function implementation
def find_max_areas(datasets):
"""
For each dataset, find the maximum area of water the container can store
and return each output in one line.
"""
#... | def max_area(heights):
"""
Return the maximum area of water that can be contained by two vertical lines.
"""
left, right = 0, len(heights) - 1
max_area = 0
while left < right:
height = min(heights[left], heights[right])
width = right - left
current_area = height * wi... | from solution import max_area, find_max_areas, parse_input
def test_max_area():
assert max_area([1, 8, 6, 2, 5, 4, 8, 3, 7]) == 49
assert max_area([1, 1, 1, 1]) == 3
assert max_area([5, 2, 6]) == 10
def test_find_max_areas():
datasets = [
[1, 8, 6, 2, 5, 4, 8, 3, 7],
[1, 1, 1, 1],
... | [
{
"docstring": "Return the maximum area of water that can be contained by two vertical lines.",
"function_declaration": "def max_area(heights):",
"function_name": "max_area",
"parameter_list": "(heights)"
},
{
"docstring": "For each dataset, find the max area of water the container can store... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_water_container(heights):\n \"\"\"\n This function returns the maximum amount of water that can be stored between two lines represented by the height... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of non-negative integers, with each integer representing the height of a vertical line on a graph. Your task is to write a program that finds two lines that, together with the x-axis, form a container such that the container holds the most amount of water. Return the ma... | 0.660983 | Taco_98426 | C | [
"max_area",
"find_max_areas",
"parse_input"
] | 3 | [
[
"find_max_areas",
"max_area"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 0311a5175c16225fca0f2ae4775bb36f579ef868 | 17c841220c4638432c16c23cc573bd08f2d019b3 | |||
v1.0 | complete | Taco | Taco_98971_C | from typing import List
def can_transform(initial_sequence: List[int], target_sequence: List[int]) -> str:
"""
Given the initial and target sequence, determine whether it is possible to
transform the initial sequence into the target sequence using the game's
operations.
>>> can_transform([12, 15,... | from math import gcd
from functools import reduce
from collections import deque
def lcm(a, b):
"""
Returns the Least Common Multiple of a and b.
"""
return a * b // gcd(a, b)
def can_transform(initial_sequence, target_sequence):
"""
Given the initial and target sequence, determine whether it i... | import pytest
from solution import can_transform
def test_sample_case():
initial = [12, 15, 10, 20, 25]
target = [3, 60, 10, 20, 25]
assert can_transform(initial, target) == "YES"
def test_same_sequence():
initial = [1, 2, 3]
target = [1, 2, 3]
assert can_transform(initial, target) == "YES"
d... | [
{
"docstring": "Returns the Least Common Multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Given the initial and target sequence, determine whether it is possible to\ntransform the initial sequence into the ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\nfrom collections import deque\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple of a and b.\... | trial_gpt4o_0 | {
"original_instruction": "Alice and Bob are playing a game with sequences of positive integers. Alice gives Bob a sequence of integers and asks him to perform a series of operations to transform it. Bob needs your help writing a program to automate these operations. \n\nHere is how the game works:\n\n1. Start with a... | 0.575832 | Taco_98971 | C | [
"lcm",
"can_transform"
] | 2 | [
[
"can_transform",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f8ad72d276458e8cb0a971eee2b868befe4a6623 | ee4bc40f46f7538971091cbe3cf9c3aea6499600 | |||
v1.0 | complete | Taco | Taco_99981_C | def num_additions_for_palindrome(T: int, cases: List[int]) -> List[int]:
""" For each test case, return the number of additions required to obtain a palindromic number or -1 if it is impossible within 1000 additions.
>>> num_additions_for_palindrome(1, [56])
[1]
>>> num_additions_for_palindrome(1, [89])... | def reverse_number(n):
return int(str(n)[::-1])
def is_palindrome(n):
return str(n) == str(n)[::-1]
def num_additions_for_palindrome(T, cases):
results = []
for P in cases:
count = 0
while count < 1000:
if is_palindrome(P):
break
P = P + rev... | from solution import num_additions_for_palindrome
def test_basics():
assert num_additions_for_palindrome(1, [56]) == [1]
assert num_additions_for_palindrome(1, [89]) == [24]
assert num_additions_for_palindrome(2, [56, 89]) == [1, 24]
def test_small_palindromes():
assert num_additions_for_palindrome(1,... | [
{
"docstring": null,
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docst... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef num_additions_for_palindrome(T, cases):\n results = []\n \n for P in cases:\n steps... | trial_gpt4o_2 | {
"original_instruction": "Sarah is fascinated by palindromic numbers and decides to create new palindromic numbers by summing numbers and their reversals. She starts with any positive integer and adds it to its reverse. If the sum is a palindrome, she stops; otherwise, she repeats the process with the new sum until ... | 0.741842 | Taco_99981 | C | [
"reverse_number",
"is_palindrome",
"num_additions_for_palindrome"
] | 3 | [
[
"num_additions_for_palindrome",
"is_palindrome"
],
[
"num_additions_for_palindrome",
"reverse_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 962dbec8b202f59ccf9a5133f17d8cd905ab89b6 | 5e89deb111b8a2be42082fb2c33d173f9ac70737 | |||
v1.0 | complete | Taco | Taco_96665_C | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, False otherwise.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(1)
False
>>> is_prime(0)
False
"""
# (I... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | 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(1) == False
assert is_prime(0) == False
def test_longest_prime_increasing_subsequence_length():
assert longest_prime_increasing_subsequence_leng... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the length of the longest strictly increasing subsequence\nof prime numbers within the given seq... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a sequence of N integers, you need to find the length of the longest subsequence that is strictly increasing and consists only of prime numbers.\n\nFor example, consider the sequence:\n7 2 5 3 11 13 1 17 \n\nA strictly increasing subsequence composed exclusively of prime numbers is: 2... | 0.708091 | Taco_96665 | C | [
"is_prime",
"longest_prime_increasing_subsequence_length"
] | 2 | [
[
"longest_prime_increasing_subsequence_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 26a27c6278a4f1467d327d03420577ecf8b5dc85 | 0f7db6f1dc410c313ffd2ce51fe01fab0d1fe0b8 | |||
v1.0 | complete | Taco | Taco_99721_C | import math
from typing import List, Union
def solve(test_cases: List[int]) -> List[Union[str, int]]:
""" Given a list of integers, determine for each if it can be expressed
as the sum of two prime numbers. If possible, return any such pair of
prime numbers. Otherwise, return -1 for that integer.
... | import math
def is_prime(num):
"""
Checks if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fals... | from solution import solve
def test_case_1():
assert solve([10]) == ["3 7"]
def test_case_2():
assert solve([27]) == [-1]
def test_case_3():
assert solve([4]) == ["2 2"]
def test_case_4():
assert solve([20]) == ["3 17"]
def test_multiple_cases():
assert solve([10, 27, 4, 20]) == ["3 7", -1, "2 ... | [
{
"docstring": "Checks if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds a pair of prime numbers that sum up to n.",
"function_declaration": "def find_prime_pair(n):",
"function_name... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n re... | trial_gpt4o_0 | {
"original_instruction": "Given an integer n, your task is to determine if it is possible to express the number n as the sum of two prime numbers. If possible, return any such pair of prime numbers, otherwise return -1.\n\n------ Input Format ------\n\n- The first line contains a single integer T - the number of tes... | 0.638061 | Taco_99721 | C | [
"is_prime",
"find_prime_pair",
"solve"
] | 3 | [
[
"find_prime_pair",
"is_prime"
],
[
"solve",
"find_prime_pair"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4e7ad98dc5a12f2ff85c1151035a0c5cd6d370f7 | a8b4e4ecb398d79ded94c465a3bc2e93ca6397f1 | |||
v1.0 | complete | Taco | Taco_85188_C | def find_total_minimum_delay(N: int, M: int, P: int, legs: List[Tuple[int, int, int]], passengers: List[Tuple[int, int]]) -> int:
"""
Calculates the total minimum delay encountered by all passengers on the network.
Parameters:
N (int): Number of nodes.
M (int): Number of legs.
P (int): Numb... | import heapq
def dijkstra(graph, start, n):
"""
Implements Dijkstra's algorithm to find the shortest path from start to all other nodes.
"""
distances = {node: float('infinity') for node in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
... | from solution import find_total_minimum_delay
def test_example():
N = 4
M = 5
P = 2
legs = [
(1, 2, 10),
(1, 3, 5),
(2, 3, 1),
(3, 2, 3),
(3, 4, 2)
]
passengers = [
(1, 4),
(2, 4)
]
assert find_total_minimum_delay(N, M, P, legs, pa... | [
{
"docstring": "Implements Dijkstra's algorithm to find the shortest path from start to all other nodes.",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": "Calculates the total minimum delay for al... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\n# Dijkstra's algorithm to find the shortest path from a single source node to all other nodes\ndef dijkstra(N, graph, start):\n distances = [flo... | trial_gpt4o_8 | {
"original_instruction": "Your task is to design a scheduling algorithm for a new transportation service, \"FastMove\", which aims to reduce trip delays for passengers. Each trip consists of multiple legs, each represented by a series of connected nodes. Most passengers are trying to get from a start node to a desti... | 0.648688 | Taco_85188 | C | [
"dijkstra",
"find_total_minimum_delay"
] | 2 | [
[
"find_total_minimum_delay",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c92f6e9d83872d3cc6bd93cb220df6b5e342140f | 2c901661705a643a048ba8dc1611d166d0ba3a40 | |||
v1.0 | complete | Taco | Taco_98918_C | def is_strong_password(password: str) -> str:
"""
Check if the password is strong based on provided criteria.
A password is considered strong if it meets the following conditions:
1. It has at least 8 characters.
2. It contains at least one uppercase letter.
3. It contains at least one lowercase... | def is_strong_password(password):
"""
Check if the password is strong based on provided criteria.
"""
if len(password) < 8:
return "NO"
has_upper = any(c.isupper() for c in password)
has_lower = any(c.islower() for c in password)
has_digit = any(c.isdigit() for c in password)
... | from solution import is_strong_password, check_passwords
def test_is_strong_password():
assert is_strong_password("Password1!") == "YES"
assert is_strong_password("abcd1234") == "NO"
assert is_strong_password("A!c1") == "NO"
assert is_strong_password("StrongPass1$") == "YES"
assert is_strong_passwo... | [
{
"docstring": "Check if the password is strong based on provided criteria.",
"function_declaration": "def is_strong_password(password):",
"function_name": "is_strong_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def check_passwords(passwords)... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_strong_password(password):\n \"\"\"\n Check if the password is strong based on provided criteria.\n \"\"\"\n if len(password) < 8:\n retu... | trial_gpt4o_0 | {
"original_instruction": "Jason's company is conducting a security audit of their password storage system. One of the tasks involves determining the strength of stored passwords. A password is considered strong if it meets the following conditions:\n\n1. It has at least 8 characters.\n2. It contains at least one upp... | 0.586116 | Taco_98918 | C | [
"is_strong_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"is_strong_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e56bc706e84d2b94292452694148ddeafad8cdd | 755097dba474231127c64eb9565603002a1a2c46 | |||
v1.0 | complete | Taco | Taco_99650_C | def is_prime(num):
"""
Check if a number is prime.
"""
# Implement the function to check if a number is prime
def find_prime_pair(N):
"""
Find two prime numbers whose sum is N.
"""
# Implement the function to find two prime numbers whose sum is N
def prime_pairs(T, cases):
"""
... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_prime_pair(N):
... | from solution import is_prime, find_prime_pair, prime_pairs
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_find_prime_pair():
assert find_prime_pair(10) == (3, 7)
asser... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find two prime numbers whose sum is N.",
"function_declaration": "def find_prime_pair(N):",
"function_name": "find_pri... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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 return False\n return True\... | trial_gpt4o_1 | {
"original_instruction": "Harry and Sally love playing with numbers. Their favorite game is to transform numbers in a unique way. The rule of the game is simple: For any given number N, they check whether it is possible to split the number into two prime numbers whose sum is equal to N. If possible, they print the t... | 0.665002 | Taco_99650 | C | [
"is_prime",
"find_prime_pair",
"prime_pairs"
] | 3 | [
[
"find_prime_pair",
"is_prime"
],
[
"prime_pairs",
"find_prime_pair"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 14ab658cc291925f14bcd1b8c54a6eefd6008aeb | 167552a43d9a9f3f6019e58630f4822521b42019 | |||
v1.0 | complete | Taco | Taco_88123_C | def is_fibonacci(n):
"""
Check if a given number n is a Fibonacci number.
A number is a Fibonacci number if and only if one (or both) of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
"""
pass
def determine_level(score):
"""
Determine the level of a participant based on their efficiency sc... | def is_fibonacci(n):
"""
Check if a given number n is a Fibonacci number.
A number is a Fibonacci number if and only if one (or both) of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
"""
if n == 0 or n == 1:
return True
def is_perfect_square(x):
s = int(x**0.5)
return s... | from solution import determine_level, coding_competition_levels
def test_determine_level():
assert determine_level(25) == "Beginner"
assert determine_level(45) == "Intermediate"
assert determine_level(72) == "Advanced"
assert determine_level(21) == "Elite" # 21 is a Fibonacci number
assert determ... | [
{
"docstring": "Check if a given number n is a Fibonacci number.\nA number is a Fibonacci number if and only if one (or both) of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.",
"function_declaration": "def is_fibonacci(n):",
"function_name": "is_fibonacci",
"parameter_list": "(n)"
},
{
"do... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def categorize_participants_scores(scores):\n \"\"\"\n This function categorizes participant scores based on their efficiency.\n\n Parameters:\n scores... | trial_gpt4o_2 | {
"original_instruction": "You are tasked to organize a coding competition at your university. The system for assigning levels to participants works based on their efficiency scores. Participants with scores less than 40 are assigned the \"Beginner\" level, those reaching up to 70 are classified as \"Intermediate\", ... | 0.604477 | Taco_88123 | C | [
"is_fibonacci",
"determine_level",
"coding_competition_levels"
] | 3 | [
[
"coding_competition_levels",
"determine_level"
],
[
"determine_level",
"is_fibonacci"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f50c4d99dc023ebeafa9730f562f731206dc8f48 | c0ff7a8c27d5c0c6d2c651269ca8649dc40eba2b | |||
v1.0 | complete | Taco | Taco_73186_C | class BinaryTree:
def __init__(self, x):
"""
Initialize the node with the given value x and set left and right child to None.
"""
self.val = x
self.left = None
self.right = None
def add_left(self, left):
"""
Add a left child to the node.
... | class BinaryTree:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def add_left(self, left):
self.left = left
def add_right(self, right):
self.right = right
def has_path_sum(root, target_sum):
if not root:
return False
... | from solution import BinaryTree, has_path_sum, create_binary_tree_from_breadth_first, check_path_sum_from_input
def test_check_path_sum_from_input():
assert check_path_sum_from_input(5, [5, 4, 8, 11, 13], 22) == "YES"
assert check_path_sum_from_input(3, [1, 2, 3], 5) == "NO"
assert check_path_sum_from_inpu... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class BinaryTreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef has_path_sum(root, target_sum):... | trial_gpt4o_1 | {
"original_instruction": "**Problem**\n\nYou are given a binary tree where each node contains an integer value. You need to determine if there exists a path in this tree whose sum of values equals a given target sum. The path must start from the root node and end at any leaf node. \n\nA leaf node is a node with no c... | 0.649694 | Taco_73186 | C | [
"has_path_sum",
"create_binary_tree_from_breadth_first",
"check_path_sum_from_input"
] | 3 | [
[
"check_path_sum_from_input",
"create_binary_tree_from_breadth_first"
],
[
"check_path_sum_from_input",
"has_path_sum"
]
] | 2 | [] | false | [
"BinaryTree"
] | true | pytest | true | [] | true | cf7273742197dad5985d311d72c9d5e78d2ddd6d | 0fda693e60a04e246d2004ba7b41137d25477f5f | |||
v1.0 | complete | Taco | Taco_99180_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def reorderLeaves(root):
""" Reorder the leaves of a binary tree such that the leaf nodes are replaced with sorted values.
>>> root = TreeNode(5)
>>> root.l... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def collect_leaves(root):
if root is None:
return []
if root.left is None and root.right is None:
return [root.val]
leaves = collect_leaves(root.... | from solution import TreeNode, reorderLeaves
def get_inorder(root):
if not root:
return []
return get_inorder(root.left) + [root.val] + get_inorder(root.right)
def test_reorder_leaves_case_1():
root = TreeNode(5)
root.left = TreeNode(3)
root.right = TreeNode(8)
root.left.left = Tr... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\n\ndef colle... | trial_gpt4o_0 | {
"original_instruction": "Given a binary tree, you need to perform the following tasks:\n- Collect all the leaf nodes.\n- Sort the collected leaf nodes in non-decreasing order.\n- Replace the original leaf nodes in the tree with the sorted values.\n\nExample 1:\nInput:\n 5\n / \\\n 3 8\n /| |\\\n ... | 0.560172 | Taco_99180 | C | [
"collect_leaves",
"replace_leaves",
"reorderLeaves"
] | 3 | [
[
"reorderLeaves",
"collect_leaves"
],
[
"reorderLeaves",
"replace_leaves"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 04d11d4f1f6b676fd3ec93618713d3b3941e063e | 68405c30241144bc2f0d25d25ab2b4db72d8ccc5 | |||
v1.0 | complete | Taco | Taco_98974_C | def transform_grid(current_grid, r, c, transformations):
""" Transforms the grid according to the transformation rules.
Args:
current_grid: List of List of characters, representing the current state of grid
r: Integer, number of rows in the grid
c: Integer, number of columns in the grid
... | from collections import deque
def transform_grid(current_grid, r, c, transformations):
new_grid = [['.'] * c for _ in range(r)]
for i in range(r):
for j in range(c):
if current_grid[i][j] == '#':
if transformations[i][j] == 'U':
new_grid[(i - 1 + r) % r][... | import pytest
from solution import minimum_time_to_exit, transform_grid
def test_example_1():
r, c, m = 4, 4, 2
grid = [
"S..#",
"....",
".#..",
"..E#"
]
transformations = [
"DUDU",
"RLUD",
"LRLU",
"UDUD"
]
assert minimum_time_to_e... | [
{
"docstring": null,
"function_declaration": "def transform_grid(current_grid, r, c, transformations):",
"function_name": "transform_grid",
"parameter_list": "(current_grid, r, c, transformations)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_exit(r, c, m, grid, t... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_time_to_exit(r, c, m, grid, transform):\n \"\"\"\n Returns the minimum time required for the spaceship to reach the ... | trial_gpt4o_8 | {
"original_instruction": "You are the captain of a spaceship and have to navigate your ship through a complex asteroid field. The field is represented as a two-dimensional grid consisting of `r` rows and `c` columns. Each cell in the grid may contain an empty space, an asteroid, or the spaceship (your position).\n\n... | 0.564271 | Taco_98974 | C | [
"transform_grid",
"minimum_time_to_exit"
] | 2 | [
[
"minimum_time_to_exit",
"transform_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 902a9dd76fbc9b28192248dfa6feb29fc5eaad99 | 61ede2a35cf497ef9c0c7c7c66c42af7aae5961c | |||
v1.0 | complete | Codeforces | Codeforces_20_C | from typing import List
def calculate_subtree_sums(n: int, values: List[int]) -> List[int]:
"""
Precompute the subtree sums using a DFS approach.
Args:
n: number of nodes
values: list of values of the nodes
Returns:
subtree_sum: list where subtree_sum[i] is the sum of values in the sub... | def calculate_subtree_sums(n, values):
"""
Precompute the subtree sums using a DFS approach.
Args:
n: number of nodes
values: list of values of the nodes
Returns:
subtree_sum: list where subtree_sum[i] is the sum of values in the subtree rooted at node i+1
"""
subtree_sum = valu... | import pytest
from solution import subtree_query_sum
def test_example_case():
n = 5
q = 3
values = [1, 2, 3, 4, 5]
queries = [1, 2, 3]
expected_output = [15, 11, 3]
assert subtree_query_sum(n, q, values, queries) == expected_output
def test_single_node():
n = 1
q = 1
values = [10]
... | [
{
"docstring": "Precompute the subtree sums using a DFS approach.\nArgs:\nn: number of nodes\nvalues: list of values of the nodes\n\nReturns:\nsubtree_sum: list where subtree_sum[i] is the sum of values in the subtree rooted at node i+1",
"function_declaration": "def calculate_subtree_sums(n, values):",
... | [
1,
0,
0,
1,
0,
0,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_subtree_sums(n, values, queries):\n from collections import defaultdict, deque\n \n # Construct tree from level order values\n child... | trial_gpt4o_7 | {
"original_instruction": "You are given a binary tree with `n` nodes. Each node has a value v_i associated with it. The value of the root node is v_1, its left child (if it exists) is v_2, its right child (if it exists) is v_3, and so on in a level-order traversal.\n\nYour task is to perform `q` queries on this bina... | 0.487671 | Codeforces_20 | C | [
"calculate_subtree_sums",
"subtree_query_sum"
] | 2 | [
[
"subtree_query_sum",
"calculate_subtree_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | da2d79bdf37419b897d8064d081cdece8efdad0f | 395527ae6f123820d52c1060b85a382d73fd8a14 | |||
v1.0 | complete | Codeforces | Codeforces_50_C | def shortest_path(n, m, a, b, edges):
"""
Determine the shortest path from city A to city B in an undirected weighted graph and check if it's unique.
Args:
n (int): number of cities
m (int): number of roads
a (int): start city
b (int): target city
edges (List[Tuple[int, int, int]]):... | import heapq
def dijkstra(graph, start, n):
""" Returns the shortest distance from start to all other nodes and number of ways to reach each node. """
dist = {i: float('inf') for i in range(1, n + 1)}
dist[start] = 0
ways = {i: 0 for i in range(1, n + 1)}
ways[start] = 1
pq = [(0, start)]
... | def test_shortest_path_unique():
n = 4
m = 4
a = 1
b = 4
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (1, 3, 4)]
assert shortest_path(n, m, a, b, edges) == 4
def test_shortest_path_ambiguous():
n = 4
m = 4
a = 1
b = 4
edges = [(1, 2, 1), (2, 3, 2), (3, 4, 1), (1, 4, 4)]
ass... | [
{
"docstring": "Returns the shortest distance from start to all other nodes and number of ways to reach each node. ",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration... | [
0,
0,
1,
0,
0,
0,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_path_unique(n, m, A, B, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((v, w... | trial_gpt4o_6 | {
"original_instruction": "Steve is learning graph theory and wants to explore the shortest paths in an undirected weighted graph. The graph has cities connected by roads, and weights represent the travel time between each pair of cities. He is particularly interested in whether there is a unique shortest path betwee... | 0.722762 | Codeforces_50 | C | [
"dijkstra",
"shortest_path"
] | 2 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fc8a31d5bb836273e460f12b88986f1ff4017488 | 0c32104a17a4ddaff2f4941807568d5cf4182a30 | |||
v1.0 | complete | Codeforces | Codeforces_70_C | def find_min_max_pages(k: int, pages: List[int]) -> int:
"""You are given an array of integers representing the number of pages in several books arranged in a linear order on a bookshelf. You want to allocate these books to students such that each student gets at least one book, and the maximum number of pages allo... | def is_valid_distribution(pages, k, max_pages):
students_required = 1
current_pages_sum = 0
for page in pages:
if current_pages_sum + page > max_pages:
students_required += 1
current_pages_sum = page
if students_required > k:
return False
... | from solution import find_min_max_pages
def test_example_case():
assert find_min_max_pages(2, [12, 34, 67, 90]) == 113
def test_single_student():
assert find_min_max_pages(1, [12, 34, 67, 90]) == 203 # Sum of all pages
def test_equal_number_of_students_and_books():
assert find_min_max_pages(4, [12, 34, ... | [
{
"docstring": null,
"function_declaration": "def is_valid_distribution(pages, k, max_pages):",
"function_name": "is_valid_distribution",
"parameter_list": "(pages, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(k, pages):",
"function_name": "f... | [
0,
0,
1,
0,
0,
1,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_maximum_pages(k, pages):\n def is_possible(mid):\n students_required = 1\n current_sum = 0\n\n for page in pages:\n ... | trial_gpt4o_5 | {
"original_instruction": "You are given an array of integers representing the number of pages in several books arranged in a linear order on a bookshelf. You want to allocate these books to students such that each student gets at least one book, and the maximum number of pages allocated to a student is minimized. Yo... | 0.695451 | Codeforces_70 | C | [
"is_valid_distribution",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_valid_distribution"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c921bfadd3c9b535ad6dddf3cdc9baef79aaca8d | 26b73ca0ef7d55b8ef871a98143d607d365a0cb4 | |||
v1.0 | complete | Codeforces | Codeforces_122_C | import math
from typing import List
def find_closest_distance(n: int, coordinates: List[str]) -> float:
"""
Given the number of points n and their coordinates, find the closest Euclidean distance.
The coordinates should be provided as a list of strings, each containing space-separated integers representing... | import math
def euclidean_distance(p1, p2):
"""
Compute the Euclidean distance between two points p1 and p2.
Each point is represented as a tuple (x, y).
"""
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
def closest_pair(points):
"""
Find the closest pair of points in a list of... | from solution import find_closest_distance
def test_find_closest_distance_1():
n = 4
coordinates = ["0 0", "0 3", "4 0", "3 4"]
result = find_closest_distance(n, coordinates)
assert math.isclose(result, 3.000000, rel_tol=1e-6)
def test_find_closest_distance_2():
n = 2
coordinates = ["1 1", "4 ... | [
{
"docstring": "Compute the Euclidean distance between two points p1 and p2.\nEach point is represented as a tuple (x, y).",
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": "Find the closest pair... | [
1,
1,
1,
0,
1,
0,
0,
1,
0
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_codeforces-i2i_20000_1739005417_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Returns the Euclidean distance between points p1 and p2.\n \"\"\"\n return math.sqrt((p1... | trial_gpt4o_7 | {
"original_instruction": "You are given n pairs of integers representing the coordinates of points in 2D space. Your task is to find the two closest points and calculate the Euclidean distance between them.\n\nThe first line contains an integer n (2 ≤ n ≤ 5000), the number of points. Each of the next n lines contain... | 0.722603 | Codeforces_122 | C | [
"euclidean_distance",
"closest_pair",
"find_closest_distance"
] | 3 | [
[
"closest_pair",
"euclidean_distance"
],
[
"find_closest_distance",
"closest_pair"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ba9538080a1a61bef946fbc9611013ea9e97e96 | 5f5d375ff8b707806d8cdd6dcafdffd588e5d573 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.