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_24702_C | def primeOnesCount(N: int) -> int:
"""
Given a positive integer N, determine whether the number of 1's in its binary representation is a prime number or not.
>>> primeOnesCount(5)
1
>>> primeOnesCount(10)
1
>>> primeOnesCount(15)
0
""" | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import primeOnesCount
def test_primeOnesCount_1():
assert primeOnesCount(5) == 1 # Binary: 101 has two 1s, 2 is prime
def test_primeOnesCount_2():
assert primeOnesCount(10) == 1 # Binary: 1010 has two 1s, 2 is prime
def test_primeOnesCount_3():
assert primeOnesCount(15) == 0 # Binary: 11... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns 1 if the number of 1's in the binary representation of N is a prime number, else returns 0.",
"... | [
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 Helper function to determine if a given number is prime.\n \"\"\"\n if num < 2:\n return False\n if num == 2:\n... | trial_gpt4o_1 | {
"original_instruction": "Given a positive integer N, write a function to determine whether the number of 1's in its binary representation is a prime number or not.\nExample 1:\nInput:\nN = 5\nOutput: 1\nExplanation: The Binary Representation of 5 is 101, which has two 1's. Since 2 is a prime number, the function sh... | 0.72202 | Taco_24702 | C | [
"is_prime",
"primeOnesCount"
] | 2 | [
[
"primeOnesCount",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2c970a80f1e06324acdd010c95501dedc137d5d4 | ba7f0f83ecbff85235a82ad25cd449b1e0b7debe | |||
v1.0 | complete | Taco | Taco_24503_C | def matrix_mult(A, B):
"""
Multiplies two matrices A and B.
"""
pass
def matrix_pow(matrix, n):
"""
Raises the matrix to the power of n using exponentiation by squaring.
"""
pass
def fib(n):
"""
Returns the nth Fibonacci number using matrix exponentiation.
"""
pass
def... | def matrix_mult(A, B):
"""
Multiplies two matrices A and B.
"""
return [
[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],
[A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]
]
def matrix_pow(matrix, n):
"""
Raises the... | from solution import process_fibonacci_sums, sum_fib_upto_n
def test_sum_fib_upto_0():
assert sum_fib_upto_n(0) == 0
def test_sum_fib_upto_1():
assert sum_fib_upto_n(1) == 1
def test_sum_fib_upto_2():
assert sum_fib_upto_n(2) == 2
def test_sum_fib_upto_3():
assert sum_fib_upto_n(3) == 4
def test_su... | [
{
"docstring": "Multiplies two matrices A and B.",
"function_declaration": "def matrix_mult(A, B):",
"function_name": "matrix_mult",
"parameter_list": "(A, B)"
},
{
"docstring": "Raises the matrix to the power of n using exponentiation by squaring.",
"function_declaration": "def matrix_p... | [
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 matrix_mult(A, B, mod):\n \"\"\"\n Multiplies two 2x2 matrices A and B under modulo `mod`.\n \"\"\"\n return [\n [(A[0][0] * B[0][0] + A[0][... | trial_gpt4o_4 | {
"original_instruction": "Shannon is fascinated by sequences and their properties. She recently learned about the Fibonacci sequence and wants to explore it further. The Fibonacci sequence is defined as:\n- F(0) = 0\n- F(1) = 1\n- F(n) = F(n-1) + F(n-2) for n >= 2\n\nShannon is interested in the large Fibonacci numb... | 0.739125 | Taco_24503 | C | [
"matrix_mult",
"matrix_pow",
"fib",
"sum_fib_upto_n",
"process_fibonacci_sums"
] | 5 | [
[
"fib",
"matrix_pow"
],
[
"matrix_pow",
"matrix_mult"
],
[
"process_fibonacci_sums",
"sum_fib_upto_n"
],
[
"sum_fib_upto_n",
"fib"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fc8e05f957b8f1dea5531e9bc545f1aaf300a74b | 84032f55d795c3cd95cf34e4e054e80812c58894 | |||
v1.0 | complete | Taco | Taco_24015_C | def preprocess_prefix_sums(arr):
"""
This function preprocesses the given array into a prefix sum array for efficient range sum queries.
Params:
arr (List[int]): The original array of integers.
Returns:
List[int]: The prefix sum array.
"""
pass
def range_sum_queries(arr, queries... | def preprocess_prefix_sums(arr):
"""
This function preprocesses the given array into a prefix sum array for efficient range sum queries.
"""
n = len(arr)
prefix_sums = [0] * n
prefix_sums[0] = arr[0]
for i in range(1, n):
prefix_sums[i] = prefix_sums[i - 1] + arr[i]
ret... | from solution import range_sum_queries
def test_example():
arr = [3, 1, 4, 1, 5]
queries = [(0, 2), (1, 3), (0, 4)]
assert range_sum_queries(arr, queries) == [8, 6, 14]
def test_single_element_array():
arr = [5]
queries = [(0, 0)]
assert range_sum_queries(arr, queries) == [5]
def test_identic... | [
{
"docstring": "This function preprocesses the given array into a prefix sum array for efficient range sum queries.",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "This function uses the pre... | [
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 preprocess_prefix_sums(arr):\n \"\"\"\n Given an array, preprocess the prefix sums.\n \"\"\"\n prefix_sums = [0] * len(arr)\n prefix_sums[0] = a... | trial_gpt4o_2 | {
"original_instruction": "**Problem Description:**\n\nIn the world of competitive programming, efficiency is key. One frequently encountered operation is finding the sum of elements within a specific range in an array. Given the rapid pace required during contests, doing this repeatedly through brute force can be to... | 0.56794 | Taco_24015 | C | [
"preprocess_prefix_sums",
"range_sum_queries"
] | 2 | [
[
"range_sum_queries",
"preprocess_prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80430217db42a32b00fafaf5c56043f11c8f72fd | c13a23fc21f10d1674c1358624e60b7271ce5dc7 | |||
v1.0 | complete | Taco | Taco_24282_C | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def test_max_spanning_tree():
input_lines = "4 5\n1 2 3\n1 3 2\n2 3 4\n2 4 1\n3 4 5"
assert read_input_and_calculate_mst(input_lines) == 12
def test_no_edges():
input_lines = "1 0"
assert read_input_and_calculate_mst(input_lines) == 0
def test_two_nodes_one_edge():
input_lines = "2 1\n1 2 10"
... | [
{
"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_maximum_spanning_tree(n, edges):\n \"\"\"\n Returns the weight of the maximum spanning tree of a graph using Kruskal's algorithm.\n \n n: Numb... | trial_gpt4o_1 | {
"original_instruction": "You're given an undirected weighted graph with n nodes and m edges. Each edge has a weight associated with it. The graph may contain cycles. \n\nWrite a program to find the weight of the maximum spanning tree of the graph. A maximum spanning tree is a spanning tree having maximum total edge... | 0.673034 | Taco_24282 | C | [
"find",
"union",
"max_spanning_tree",
"read_input_and_calculate_mst"
] | 4 | [
[
"max_spanning_tree",
"find"
],
[
"max_spanning_tree",
"union"
],
[
"read_input_and_calculate_mst",
"max_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 0b35870c64a6a38230ffc1ea8b327554f835649f | 570ca4728f6e023be33bb011fc67648c23f8bcdb | |||
v1.0 | complete | Taco | Taco_24200_C | def min_partition_difference(skill_levels):
"""
Function to find the minimum difference between two partitions of skill_levels.
Args:
skill_levels (list of int): List of skill levels of participants.
Returns:
int: Minimum possible difference in the sum of skill levels between two groups.
... | def min_partition_difference(skill_levels):
"""
Function to find the minimum difference between two partitions of skill_levels.
Args:
skill_levels (list of int): List of skill levels of participants.
Returns:
int: Minimum possible difference in the sum of skill levels between two groups.
... | from solution import min_partition_difference, minimal_diff_of_partitions
def test_min_partition_difference_example():
assert min_partition_difference([3, 1, 4, 2]) == 0
def test_min_partition_difference_small_diff():
assert min_partition_difference([10, 11, 23, 20]) == 2
def test_min_partition_differenc... | [
{
"docstring": "Function to find the minimum difference between two partitions of skill_levels.\n\nArgs:\nskill_levels (list of int): List of skill levels of participants.\n\nReturns:\nint: Minimum possible difference in the sum of skill levels between two groups.",
"function_declaration": "def min_partitio... | [
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 min_partition_difference(N, skills):\n from itertools import combinations\n \n total_sum = sum(skills)\n min_diff = float('inf')\n \n for i i... | trial_gpt4o_2 | {
"original_instruction": "A group of friends have decided to organize a small team programming contest. For the contest, they've decided to use an algorithm to pair up the participants based on their skill levels to make the teams as balanced as possible. The skill level of each participant is represented as an inte... | 0.604172 | Taco_24200 | C | [
"min_partition_difference",
"minimal_diff_of_partitions"
] | 2 | [
[
"minimal_diff_of_partitions",
"min_partition_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5fde166eb3018dfd98aa6e285013a5f5cdb510ae | eed307999dbeccf608112847485baa8ee6ddbcf5 | |||
v1.0 | complete | Taco | Taco_24146_C | def min_peaks_and_valleys(n: int, arr: List[int]) -> int:
""" Determine the minimum number of peaks and valleys in the sequence after at most one modification.
Parameters:
n (int): the number of integers in the sequence.
arr (List[int]): the elements of the sequence.
Returns:
int: the minimum ... | def find_peaks_and_valleys(arr):
peaks_valleys = []
for i in range(1, len(arr) - 1):
if (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]) or (arr[i] < arr[i - 1] and arr[i] < arr[i + 1]):
peaks_valleys.append(i)
return peaks_valleys
def count_peaks_and_valleys(arr):
count = 0
for i ... | import pytest
from solution import min_peaks_and_valleys
def test_min_peaks_and_valleys_example_1():
assert min_peaks_and_valleys(5, [1, 3, 2, 4, 5]) == 0
def test_min_peaks_and_valleys_example_2():
assert min_peaks_and_valleys(7, [10, 5, 3, 7, 2, 9, 8]) == 1
def test_min_peaks_and_valleys_example_3():
a... | [
{
"docstring": null,
"function_declaration": "def find_peaks_and_valleys(arr):",
"function_name": "find_peaks_and_valleys",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def count_peaks_and_valleys(arr):",
"function_name": "count_peaks_and_valleys",
"... | [
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 find_peaks_and_valleys(arr):\n peaks_valleys = []\n for i in range(1, len(arr) - 1):\n if (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]) or (arr[i]... | trial_gpt4o_0 | {
"original_instruction": "You are given a sequence of n integers. A \"peak\" is an element which is greater than its immediate neighbors. Similarly, a \"valley\" is an element which is smaller than its immediate neighbors. You are allowed to modify the sequence by changing any element to any value. The goal is to mi... | 0.591193 | Taco_24146 | C | [
"find_peaks_and_valleys",
"count_peaks_and_valleys",
"min_peaks_and_valleys"
] | 3 | [
[
"min_peaks_and_valleys",
"count_peaks_and_valleys"
],
[
"min_peaks_and_valleys",
"find_peaks_and_valleys"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a948a7b9f87d020fa2403dc02ef48bd17c27d726 | c7073f30dbd983b3c413fd5947fab444c50af842 | |||
v1.0 | complete | Taco | Taco_23404_C | from typing import List, Tuple
def find_minimum_soldiers(n: int, soldiers: List[int], roads: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Find the minimum number of soldiers that can be obtained by traveling from city u to city v along the path that connects them.
Args:
n :... | from collections import defaultdict, deque
def bfs(graph, start, soldiers):
queue = deque([start])
visited = {start}
dist = {start: soldiers[start - 1]}
parent = {start: None}
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if neighbor not in visited:
... | def test_find_minimum_soldiers():
# Example 1
n = 5
soldiers = [10, 20, 30, 40, 50]
roads = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [(1, 5), (2, 4), (4, 5)]
expected = [10, 10, 30]
result = find_minimum_soldiers(n, soldiers, roads, queries)
assert result == expected, f"expected {... | [
{
"docstring": null,
"function_declaration": "def bfs(graph, start, soldiers):",
"function_name": "bfs",
"parameter_list": "(graph, start, soldiers)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_soldiers(n, soldiers, roads, queries):",
"function_name": "find_mini... | [
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 collections import defaultdict, deque\n\ndef bfs(graph, start, soldiers):\n queue = deque([start])\n visited = {start}\n dist = {start: soldiers[star... | trial_gpt4o_0 | {
"original_instruction": "In a faraway magical land, there is a kingdom with $n$ cities connected by $n-1$ roads in such a way that there is exactly one path between any two cities. Each city has a certain amount of soldiers. The king wants to know the minimum number of soldiers that can be obtained by traveling fro... | 0.658703 | Taco_23404 | C | [
"bfs",
"find_minimum_soldiers"
] | 2 | [
[
"find_minimum_soldiers",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f14a841aa878dab421a76f3fb6a7b92334c338ff | ed37d828bdfcfa24d00924b7caa8d9cc4750684b | |||
v1.0 | complete | Taco | Taco_23791_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def handle_input_to_tree(N, values, edges):
if N == 0:
return None
nodes = {i + 1: TreeNode(val) for i, val in enumerate(values)}
for u, v in edges:
if not ... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def handle_input_to_tree(N, values, edges):
if N == 0:
return None
nodes = {i + 1: TreeNode(val) for i, val in enumerate(values)}
for u, v in edges:
if not node... | def test_handle_input_to_tree():
# Test the helper function to construct the binary tree from input data
N = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
root = handle_input_to_tree(N, values, edges)
assert root.value == 1
assert root.left.value == 2
asse... | [] | [
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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef b... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree of N nodes. Each node of the tree contains a positive integer value. You need to perform the following task:\n\n1. Find all possible paths from the root to leaf nodes.\n2. For each path, compute the sum of the values of the nodes in the path.\n\nYour task is to r... | 0.635106 | Taco_23791 | C | [
"handle_input_to_tree",
"get_all_paths_sums",
"count_distinct_path_sums"
] | 3 | [
[
"count_distinct_path_sums",
"get_all_paths_sums"
],
[
"count_distinct_path_sums",
"handle_input_to_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 95aeef0f32ccf6ac517f283fed3a04485c2888c6 | f9f5df4ef6db73092e48689f1b8ee3088a84d5d9 | |||
v1.0 | complete | Taco | Taco_24327_C | def activate_element(B, i):
"""
Activate the element at index i in the array B.
"""
def deactivate_element(B, i):
"""
Deactivate the element at index i in the array B.
"""
def range_sum(A, B, l, r):
"""
Compute the sum of all active elements in the range [l, r].
"""
de... | def activate_element(B, i):
"""
Activate the element at index i in the array B.
"""
B[i-1] = 1
def deactivate_element(B, i):
"""
Deactivate the element at index i in the array B.
"""
B[i-1] = 0
def range_sum(A, B, l, r):
"""
Compute the sum of all active elements in the range [... | def test_activate_element():
B = [0, 0, 0]
activate_element(B, 1)
assert B == [1, 0, 0]
activate_element(B, 3)
assert B == [1, 0, 1]
def test_deactivate_element():
B = [1, 1, 1]
deactivate_element(B, 2)
assert B == [1, 0, 1]
deactivate_element(B, 3)
assert B == [1, 0, 0]
... | [
{
"docstring": "Activate the element at index i in the array B.",
"function_declaration": "def activate_element(B, i):",
"function_name": "activate_element",
"parameter_list": "(B, i)"
},
{
"docstring": "Deactivate the element at index i in the array B.",
"function_declaration": "def dea... | [
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 perform_operations(N, A, B, queries):\n results = []\n active_prefix_sum = [0] * (N + 1)\n \n # Initial calculation of prefix sums for active eleme... | trial_gpt4o_2 | {
"original_instruction": "Chef has an array $A$ containing $N$ distinct integers. Chef also has another array $B$ of the same length $N$, with each element either 0 or 1, representing the state of corresponding element in $A$. If $B[i] = 1$, the element $A[i]$ is considered 'active'; otherwise, the element $A[i]$ is... | 0.564175 | Taco_24327 | C | [
"activate_element",
"deactivate_element",
"range_sum",
"process_queries"
] | 4 | [
[
"process_queries",
"activate_element"
],
[
"process_queries",
"deactivate_element"
],
[
"process_queries",
"range_sum"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 126975a28ef9402364153bcb2ae12da7984e9b8c | 525faaa7431ca03c83202341bb0b23c657f3d5fa | |||
v1.0 | complete | Taco | Taco_24221_C | def minimal_bridges(n, edges):
"""
Returns the minimal total length of the bridges required to connect all the treehouses.
>>> minimal_bridges(4, [(1, 2, 1), (2, 3, 4), (1, 3, 2), (3, 4, 3)])
6
>>> minimal_bridges(4, [(1, 2, 1), (1, 3, 3), (4, 2, 2), (4, 3, 4), (1, 4, 5)])
6
>>> minima... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | from solution import minimal_bridges
def test_minimal_bridges_case1():
edges = [
(1, 2, 1),
(2, 3, 4),
(1, 3, 2),
(3, 4, 3)
]
assert minimal_bridges(4, edges) == 6
def test_minimal_bridges_case2():
edges = [
(1, 2, 1),
(1, 3, 3),
(4, 2, 2),
... | [
{
"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,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u... | trial_gpt4o_3 | {
"original_instruction": "Treehouse is a popular recreational development located in the center of a large natural reserve. To better cater to visitors, the management has decided to build a series of bridges that connect the various treehouses. The objective is to ensure that visitors can travel between any two tre... | 0.608992 | Taco_24221 | C | [
"find",
"union",
"minimal_total_length",
"minimal_bridges"
] | 4 | [
[
"minimal_bridges",
"minimal_total_length"
],
[
"minimal_total_length",
"find"
],
[
"minimal_total_length",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 127e2aeb29e24a7b786e6d85078be399d67f4356 | eea26646614de5ea2cac3a1681060be0be2550b7 | |||
v1.0 | complete | Taco | Taco_24452_C | def gcd(a: int, b: int) -> int:
""" Find the greatest common divisor of two numbers.
>>> gcd(6, 9) 3
>>> gcd(12, 15) 3
>>> gcd(24, 36) 12
>>> gcd(7, 3) 1
>>> gcd(100, 1000) 100
"""
def max_plot_area(m: int, n: int) -> int:
""" Find the maximum possible area of each of the smaller plots.... | def gcd(a, b):
while b:
a, b = b, a % b
return a
def max_plot_area(m, n):
greatest_common_divisor = gcd(m, n)
return greatest_common_divisor ** 2
def solve_garden_division(test_cases):
results = []
for m, n in test_cases:
results.append(max_plot_area(m, n))
return results | from solution import gcd, max_plot_area, solve_garden_division
def test_gcd():
assert gcd(6, 9) == 3
assert gcd(12, 15) == 3
assert gcd(24, 36) == 12
assert gcd(7, 3) == 1
assert gcd(100, 1000) == 100
def test_max_plot_area():
assert max_plot_area(6, 9) == 9
assert max_plot_area(12, 15) ==... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def max_plot_area(m, n):",
"function_name": "max_plot_area",
"parameter_list": "(m, n)"
},
{
"docstring": nul... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\n\ndef max_plot_area(test_cases):\n results = []\n for m, n in test_cases:\n # Calculate the greatest common divisor of m and n\n... | trial_gpt4o_5 | {
"original_instruction": "Dmitry has a large rectangular garden which he wants to divide into smaller rectangular plots. Each plot should have an equal area and should be as large as possible. To achieve this, Dmitry needs to find the largest possible integer area for each of the smaller plots that the garden can be... | 0.599691 | Taco_24452 | C | [
"gcd",
"max_plot_area",
"solve_garden_division"
] | 3 | [
[
"max_plot_area",
"gcd"
],
[
"solve_garden_division",
"max_plot_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6ccb765bb7c3319566756f45668581c5385fb089 | 50c4b9c23b2f6ca74e4fc329e0ef4e1a7c06cbe5 | |||
v1.0 | complete | Taco | Taco_24163_C | def find_path(R: int, C: int, lines: List[str]) -> str:
""" Determines if there is a path from 'S' to 'E' in the given grid.
Parameters:
R (int): Number of rows.
C (int): Number of columns.
lines (list of str): The grid represented as a list of strings.
Returns:
str: "YES" if a pat... | from collections import deque
def path_exists(grid, R, C):
"""
Determines if there is a path from 'S' to 'E' in the given grid.
Parameters:
grid (list of list of str): The grid representing the map.
R (int): Number of rows in the grid.
C (int): Number of columns in the grid.
Retur... | def test_find_path_case_1():
R = 4
C = 4
lines = [
"S..#",
".#.#",
".#.E",
"####"
]
assert find_path(R, C, lines) == "YES"
def test_find_path_case_2():
R = 3
C = 3
lines = [
"S#.",
"###",
".#E"
]
assert find_path(R, C, line... | [
{
"docstring": "Determines if there is a path from 'S' to 'E' in the given grid.\n\nParameters:\ngrid (list of list of str): The grid representing the map.\nR (int): Number of rows in the grid.\nC (int): Number of columns in the grid.\n\nReturns:\nstr: \"YES\" if a path exists, otherwise \"NO\".",
"function... | [
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 is_path_exists(R, C, grid):\n from collections import deque\n\n def get_neighbors(x, y):\n for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:\n ... | trial_gpt4o_3 | {
"original_instruction": "You are given a rectangular grid representing a map where 'S' denotes the starting point, 'E' represents the endpoint, and '.' represents a path. All other characters represent obstacles. The objective is to find a path from the starting point 'S' to the endpoint 'E' such that a person trav... | 0.606102 | Taco_24163 | C | [
"path_exists",
"find_path"
] | 2 | [
[
"find_path",
"path_exists"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f076845ab73b5877fd833c980e8b9a78e3aaaaa2 | 235d6d0d7e48fb375bdf2e7e82be80ba489b040a | |||
v1.0 | complete | Taco | Taco_24486_C | from typing import List
def largest_empty_rectangle(N: int, M: int, grid: List[str]) -> int:
"""Find the largest rectangle of empty cells ('.') in a grid of size NxM.
>>> largest_empty_rectangle(5, 6, ["......", ".##...", ".#....", "....#.", "....##"])
9
>>> largest_empty_rectangle(4, 4, ["####", "####... | def max_histogram_area(histogram):
"""
Finds the largest rectangular area possible in a given histogram
where the width of each bar is 1.
"""
stack = []
max_area = 0
index = 0
while index < len(histogram):
if not stack or histogram[stack[-1]] <= histogram[index]:
... | from solution import largest_empty_rectangle
def test_largest_empty_rectangle():
N = 5
M = 6
grid = [
"......",
".##...",
".#....",
"....#.",
"....##"
]
assert largest_empty_rectangle(N, M, grid) == 9
N = 4
M = 4
grid = [
"####",
... | [
{
"docstring": "Finds the largest rectangular area possible in a given histogram\nwhere the width of each bar is 1.",
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": "Returns the area of th... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(histogram):\n \"\"\"\n Finds the largest rectangular area possible in a given histogram\n where the width of each bar is 1.\n \"... | trial_gpt4o_0 | {
"original_instruction": "problem\n\nConsider a grid of size $N \\times M$. Each cell in the grid can either be empty or occupied by a block. You are required to find the largest rectangle composed entirely of empty cells. The rectangle must be aligned with the grid (no diagonal rectangles) and can be of any size.\n... | 0.62162 | Taco_24486 | C | [
"max_histogram_area",
"largest_rectangle_area",
"largest_empty_rectangle"
] | 3 | [
[
"largest_empty_rectangle",
"largest_rectangle_area"
],
[
"largest_rectangle_area",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 12d7731546d694b097039aa6fa0e3219f684bc97 | 9a2786ff40e8c2f68b0d4959764237bd0a2f58ca | |||
v1.0 | complete | Taco | Taco_24406_C | def is_suitable_problem(problem: str) -> bool:
""" Determines if a given problem string is suitable for practice.
A problem string is suitable if characters are unique and in strictly increasing order.
>>> is_suitable_problem("abc") == True
>>> is_suitable_problem("acb") == False
>>> is_suitable_pro... | def is_suitable_problem(problem):
"""
Determines if a given problem string is suitable for practice.
A problem string is suitable if characters are unique and in strictly increasing order.
"""
return list(problem) == sorted(problem) and len(set(problem)) == len(problem)
def check_problems(t, pr... | from solution import is_suitable_problem, check_problems
def test_is_suitable_problem():
assert is_suitable_problem("abc") == True
assert is_suitable_problem("acb") == False
assert is_suitable_problem("aaa") == False
assert is_suitable_problem("def") == True
assert is_suitable_problem("xyz") == Tru... | [
{
"docstring": "Determines if a given problem string is suitable for practice.\nA problem string is suitable if characters are unique and in strictly increasing order.",
"function_declaration": "def is_suitable_problem(problem):",
"function_name": "is_suitable_problem",
"parameter_list": "(problem)"... | [
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_suitable_problem_string(p):\n \"\"\"\n Determines if the problem string is suitable for practice.\n A string is suitable if it contains no duplicat... | trial_gpt4o_1 | {
"original_instruction": "Luke is training a team of developers for a coding competition. He has a sequence of strings, each string representing a problem where each character denotes the difficulty of a specific subtask ('a' being the easiest and 'z' the hardest).\n\nLuke wants to ensure that the developers practic... | 0.682898 | Taco_24406 | C | [
"is_suitable_problem",
"check_problems"
] | 2 | [
[
"check_problems",
"is_suitable_problem"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a33e6d285faeb065c11091e2dfdd3965dd3249f3 | 724b37f851482fcf9834005d580231dbe5444058 | |||
v1.0 | complete | Taco | Taco_24790_C | def medians(arr, k):
"""
Implement a function that takes a list of integers and returns a new list containing the median of every contiguous subarray of length `k`.
A median is the middle number in a sorted, odd-length list, or the average of the two middle numbers in an even-length list.
>>> med... | def find_median(arr):
n = len(arr)
arr.sort()
if n % 2 == 0:
return (arr[n//2 - 1] + arr[n//2]) / 2
else:
return arr[n//2]
def medians(arr, k):
"""
Returns a list of medians for every contiguous subarray of length `k`.
"""
if k == 1:
return arr # each element is... | from solution import medians
def test_medians_example1():
assert medians([1, 3, 4, 2, 5], k=3) == [3, 3, 4]
def test_medians_example2():
assert medians([7, 2, 1, 6, 5], k=2) == [4.5, 1.5, 3.5, 5.5]
def test_medians_single_element_subarray():
assert medians([10, -5, 3, 8], k=1) == [10, -5, 3, 8]
def test... | [
{
"docstring": null,
"function_declaration": "def find_median(arr):",
"function_name": "find_median",
"parameter_list": "(arr)"
},
{
"docstring": "Returns a list of medians for every contiguous subarray of length `k`.",
"function_declaration": "def medians(arr, k):",
"function_name":... | [
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 medians(nums, k):\n \"\"\"\n Returns a list of medians for every contiguous subarray of length `k`.\n \n Parameters:\n nums (list of int): List ... | trial_gpt4o_2 | {
"original_instruction": "Implement a function that takes a list of integers and returns a new list containing the median of every contiguous subarray of length `k`.\n\nA median is the middle number in a sorted, odd-length list, or the average of the two middle numbers in an even-length list.\n\n### Input\n\n- list ... | 0.845002 | Taco_24790 | C | [
"find_median",
"medians"
] | 2 | [
[
"medians",
"find_median"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18e1ecc50be86ae076429f4f8aeba64a7880994e | f8efe56573380d2ba81f87609ec6cfee93368694 | |||
v1.0 | complete | Taco | Taco_24825_C | from typing import List, Tuple, Union
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first N Fibonacci numbers.
>>> generate_fibonacci(1)
[0]
>>> generate_fibonacci(5)
[0, 1, 1, 2, 3]
"""
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
>>> is_prim... | def generate_fibonacci(n):
"""
Generate the first N Fibonacci numbers.
"""
if n == 1:
return [0]
fib_nums = [0, 1]
while len(fib_nums) < n:
fib_nums.append(fib_nums[-1] + fib_nums[-2])
return fib_nums
def is_prime(num):
"""
Check if a number is prime.
"""
if ... | from solution import generate_fibonacci, is_prime, fibonacci_primes, format_output
def test_generate_fibonacci():
assert generate_fibonacci(1) == [0]
assert generate_fibonacci(2) == [0, 1]
assert generate_fibonacci(5) == [0, 1, 1, 2, 3]
def test_is_prime():
assert is_prime(2) == True
assert is_pri... | [
{
"docstring": "Generate the first N Fibonacci numbers.",
"function_declaration": "def generate_fibonacci(n):",
"function_name": "generate_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"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_fibonacci(n):\n if n < 1:\n return []\n fibs = [0, 1]\n for i in range(2, n):\n fibs.append(fibs[-1] + fibs[-2])\n return fi... | trial_gpt4o_2 | {
"original_instruction": "Alice has recently learned about Fibonacci sequences and wants to generate a list of the first N Fibonacci numbers. Moreover, she wants to know which of these numbers are prime.\n\nA Fibonacci sequence is defined as follows:\n- F(0) = 0\n- F(1) = 1\n- F(n) = F(n-1) + F(n-2) for n > 1\n\nA p... | 0.834005 | Taco_24825 | C | [
"generate_fibonacci",
"is_prime",
"fibonacci_primes",
"format_output"
] | 4 | [
[
"fibonacci_primes",
"generate_fibonacci"
],
[
"fibonacci_primes",
"is_prime"
],
[
"format_output",
"fibonacci_primes"
]
] | 3 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 05e00cd734b382658182892abeb705c74c96f3fd | ead466bac3b9f3d9672a53540d4983b2708f871e | |||
v1.0 | complete | Taco | Taco_24659_C | from typing import List
def is_prime(n: int) -> bool:
"""
Checks if a number n is a prime number.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
Examples:
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def sp... | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import is_prime, special_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
def test_special_primes():
assert special_primes(2) == [... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds all special primes up to and including N.\nA special prime is a prime number whose reverse is also a prime numbe... | [
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(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if... | trial_gpt4o_2 | {
"original_instruction": "My friend Lexi loves coding and the magic of prime numbers. She is working on a project for which she needs to identify \"special primes.\" A \"special prime\" is a prime number such that when you reverse its digits, the resulting number is also a prime. Your task is to help Lexi write a pr... | 0.810427 | Taco_24659 | C | [
"is_prime",
"special_primes",
"main"
] | 3 | [
[
"special_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b24d356b767920910d33c5425baafa7062298de0 | aed9702bf85c6534d255221a4e631688f83fd161 | |||
v1.0 | complete | Taco | Taco_24780_C | def is_prime(num):
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
...
def sieve_of_eratosthenes(n):
""" Generate a list of prime numbers up to n (inclusive if n is prime).
>>> sieve_of_eratosthenes(10)
[2, 3, 5, 7]
>>> sieve_of_eratos... | from math import isqrt
def is_prime(num):
if num < 2:
return False
if num in (2, 3):
return True
if num % 2 == 0 or num % 3 == 0:
return False
for i in range(5, isqrt(num) + 1, 6):
if num % i == 0 or num % (i + 2) == 0:
return False
return True
def sieve... | from solution import is_prime, sieve_of_eratosthenes, sum_of_digits, generate_prime_lists_and_check, process_test_cases
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(25) == False
def test_sieve_of_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
... | [
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 isqrt\n\ndef is_prime(num):\n if num < 2:\n return False\n if num in (2, 3):\n return True\n if num % 2 == 0 or num % 3 == ... | trial_gpt4o_0 | {
"original_instruction": "Write a program that reads an integer $N$ and generates two lists. The first list contains the prime numbers up to $N$ (inclusive if $N$ is prime). The second list contains the sum of the digits of each prime number from the first list. The program should then check if any number from the s... | 0.710538 | Taco_24780 | C | [
"is_prime",
"sieve_of_eratosthenes",
"sum_of_digits",
"generate_prime_lists_and_check",
"process_test_cases"
] | 5 | [
[
"generate_prime_lists_and_check",
"is_prime"
],
[
"generate_prime_lists_and_check",
"sieve_of_eratosthenes"
],
[
"generate_prime_lists_and_check",
"sum_of_digits"
],
[
"process_test_cases",
"generate_prime_lists_and_check"
]
] | 4 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 31471f4a64d499e6851c26ff65efdba32a63779c | a4abc2f2ea30c40865196db6e71eb1c5c6a4766e | |||
v1.0 | complete | Taco | Taco_24752_C | def merge_sort(arr):
"""
Function to implement merge sort algorithm on an array.
"""
def sort_array(n, array):
""" Given an array of n integers, sort the elements in non-decreasing order using the merge sort algorithm.
>>> sort_array(8, [38, 27, 43, 3, 9, 82, 10, -5])
"-5 3 9 10 27 38 43 82"
... | def merge_sort(arr):
"""
Function to implement merge sort algorithm on an array.
"""
if len(arr) > 1:
mid = len(arr) // 2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] ... | from solution import sort_array
def test_merge_sort():
assert sort_array(8, [38, 27, 43, 3, 9, 82, 10, -5]) == "-5 3 9 10 27 38 43 82"
assert sort_array(5, [5, 2, 9, 1, 5, 6]) == "1 2 5 5 6 9"
assert sort_array(3, [3, -1, -2]) == "-2 -1 3"
assert sort_array(1, [1]) == "1"
assert sort_array(10, [10,... | [
{
"docstring": "Function to implement merge sort algorithm on an array.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Function to handle input and output for the merge sort problem.",
"function_declaration": ... | [
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_sort(arr):\n \"\"\"\n Function to perform merge sort on a list of integers.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an array of n integers, you are required to sort the elements in non-decreasing order using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that works as follows:\n\n1. Divide the unsorted list into n sublists, each containing one element.\n2. Repeatedly merge s... | 0.7115 | Taco_24752 | C | [
"merge_sort",
"sort_array"
] | 2 | [
[
"sort_array",
"merge_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b7939aaaa41a9d5cff73a085c3b281f64113a16 | 40f39394bd2f6b96f59fbefaf563ae62ffaaafbb | |||
v1.0 | complete | Taco | Taco_24762_C | from typing import List, Tuple
def preprocess_array(arr: List[int]) -> List[int]:
"""
Preprocess the array to create a prefix sum array.
"""
pass
def query_sum(prefix_sum: List[int], L: int, R: int) -> int:
"""
Returns the sum of the subarray from L to R (inclusive) using the prefix sum array.... | def preprocess_array(arr):
"""
Preprocess the array to create a prefix sum array.
"""
N = len(arr)
prefix_sum = [0] * (N + 1)
for i in range(N):
prefix_sum[i + 1] = prefix_sum[i] + arr[i]
return prefix_sum
def query_sum(prefix_sum, L, R):
"""
Returns the sum of the subarray ... | def test_preprocess_array():
assert preprocess_array([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sum = preprocess_array([1, 2, 3, 4, 5])
assert query_sum(prefix_sum, 1, 3) == 6
assert query_sum(prefix_sum, 2, 4) == 9
assert query_sum(prefix_sum, 1, 5) == 15
def test_proce... | [
{
"docstring": "Preprocess the array to create a prefix sum array.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the subarray from L to R (inclusive) using the prefix sum array.\nL ... | [
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 preprocess_array(arr):\n \"\"\"\n Preprocesses the array to create a prefix sum array.\n \"\"\"\n n = len(arr)\n prefix_sum = [0] * (n + 1)\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of $N$ integers and a set of $Q$ queries. Each query consists of two integers, $L$ and $R$ ($1 \\leq L \\leq R \\leq N$). For each query, find the sum of the integers in the subarray from index $L$ to $R$ inclusive. Your task is to process all the queries efficiently.... | 0.585396 | Taco_24762 | C | [
"preprocess_array",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_array"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 776dfad85411b1b728054e29d95c1e011259536b | dc51afc62f154217ad4118fa7574c1ae2129f810 | |||
v1.0 | complete | Taco | Taco_25044_C | def solve(N: int, grid: List[List[int]], Q: int, queries: List[Tuple[int, int, int, int]]) -> List[int]:
""" Solve the problem of finding the sum of building heights in specified rectangular regions.
Arguments:
N -- the size of the grid (N x N)
grid -- a 2D list of integers representing building he... | def compute_prefix_sum(grid, N):
prefix_sum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, N + 1):
prefix_sum[i][j] = grid[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1]
return prefix_sum
def query_sum(pr... | def test_solve():
N = 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
Q = 2
queries = [
(0, 0, 1, 1),
(1, 1, 2, 2)
]
expected = [12, 28]
assert solve(N, grid, Q, queries) == expected
def test_single_block_query():
N = 3
grid = [
[1, 2... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_sum(grid, N):",
"function_name": "compute_prefix_sum",
"parameter_list": "(grid, N)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, i1, j1, i2, j2):",
"function_name": "query_sum",
"param... | [
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 preprocess(grid):\n N = len(grid)\n prefix_sum = [[0] * (N + 1) for _ in range(N + 1)]\n \n for i in range(1, N + 1):\n for j in range(1, N ... | trial_gpt4o_2 | {
"original_instruction": "The city of Alphaville has a peculiar street layout. The city is organized into a grid of N x N blocks, each with a unique integer value representing the building height. The mayor of Alphaville wants to build new infrastructure that spans several blocks, but she needs to know the sum of th... | 0.689645 | Taco_25044 | C | [
"compute_prefix_sum",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"compute_prefix_sum"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | df49193ca9ee74eafc684d08d6c65f7ab19f5e51 | 4ce28a149d858bdd91a76ada05883bceb55e7460 | |||
v1.0 | complete | Taco | Taco_24543_C | from collections import deque, defaultdict
from typing import List, Tuple
def solve(t: int, test_cases: List[Tuple[int, List[Tuple[int, int]]]]) -> None:
""" Determine the minimum possible diameter after removing and adding one edge.
>>> solve(2, [(5, [(1, 2), (1, 3), (1, 4), (1, 5)]), (4, [(1, 2), (2, 3), (2,... | from collections import deque, defaultdict
def bfs_to_get_farthest_node(tree, start):
"""
Perform BFS to find the farthest node from the start node.
Also returns the distances of each node from the start.
"""
n = len(tree)
distances = [-1] * n
queue = deque([start])
distances[start] = 0... | def test_solve(capsys):
t = 2
test_cases = [
(5, [(1, 2), (1, 3), (1, 4), (1, 5)]),
(4, [(1, 2), (2, 3), (2, 4)]),
]
expected_output = "2\n2\n"
solve(t, test_cases)
captured = capsys.readouterr()
assert captured.out == expected_output
def test_diagram():
t... | [
{
"docstring": "Perform BFS to find the farthest node from the start node.\nAlso returns the distances of each node from the start.",
"function_declaration": "def bfs_to_get_farthest_node(tree, start):",
"function_name": "bfs_to_get_farthest_node",
"parameter_list": "(tree, start)"
},
{
"doc... | [
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 collections import deque, defaultdict\n\ndef bfs_to_get_farthest_node(tree, start):\n \"\"\"\n Perform BFS to find the farthest node from the start node... | trial_gpt4o_0 | {
"original_instruction": "A tree is an undirected connected acyclic graph.\n\nThe length of a path between two vertices in a tree is the number of edges in this path.\n\nThe diameter of a tree is the maximum length of a path between any two vertices.\n\nYou are given a tree with n vertices and you are allowed to rem... | 0.546622 | Taco_24543 | C | [
"bfs_to_get_farthest_node",
"calculate_diameter",
"find_minimum_diameter",
"process_test_cases",
"solve"
] | 5 | [
[
"calculate_diameter",
"bfs_to_get_farthest_node"
],
[
"find_minimum_diameter",
"calculate_diameter"
],
[
"process_test_cases",
"find_minimum_diameter"
],
[
"solve",
"process_test_cases"
]
] | 4 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | d7fe254c1f989f0830ef01f676e354d1472c13ac | 0e9854b3fed605e20f05a06f10859069e94e5b97 | |||
v1.0 | complete | Taco | Taco_24890_C | def evaluate_expression(expression: str) -> str:
""" Evaluates a mathematical expression and returns the result as a float with two decimal places.
>>> evaluate_expression("3+5*2")
"13.00"
>>> evaluate_expression("10/2+1")
"6.00"
>>> evaluate_expression("7*(2+3)")
"35.00"
>>> evaluate_ex... | def evaluate_expression(expression):
"""
Evaluates a mathematical expression and returns the result as a float with two decimal places.
"""
# Evaluating the expression using eval
result = eval(expression)
# Formatting the result to two decimal places
return format(result, ".2f")
def process... | from solution import evaluate_expression, process_expressions
import io
import sys
def test_evaluate_expression():
assert evaluate_expression("3+5*2") == "13.00"
assert evaluate_expression("10/2+1") == "6.00"
assert evaluate_expression("7*(2+3)") == "35.00"
assert evaluate_expression("8/3*3") == "8.00"... | [
{
"docstring": "Evaluates a mathematical expression and returns the result as a float with two decimal places.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Processes a list of exp... | [
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 evaluate_expression(expression):\n \"\"\"\n Evaluates a mathematical expression and returns the result as a float with two decimal places.\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "Create a program that evaluates mathematical expressions from strings and computes their results. Your program should correctly interpret the four basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/), while respecting the order of operations (PEMD... | 0.567039 | Taco_24890 | C | [
"evaluate_expression",
"process_expressions"
] | 2 | [
[
"process_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a70dcfb9203aee4034464077275e0188ca5631ca | 59296ce6ae1a0d84be1c8e2e4514bd46c408a732 | |||
v1.0 | complete | Taco | Taco_24949_C | import sys
from typing import List, Tuple
def minimum_cost_to_connect_all_stations(n: int, tracks: List[Tuple[int, int, int]]) -> int:
"""
Determines the minimum cost to connect all stations such that every station
can be reached from any other station. If it's impossible, returns -1.
Args:
n (int... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | def test_case_1():
n = 6
tracks = [
(1, 2, 3),
(2, 3, 2),
(3, 4, 1),
(4, 5, 4),
(5, 6, 5),
(1, 3, 6),
(2, 4, 7),
(3, 5, 8),
(4, 6, 9)
]
assert minimum_cost_to_connect_all_stations(n, tracks) == 15
def test_case_2():
n = 4
t... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"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 parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren... | trial_gpt4o_0 | {
"original_instruction": "A famous railway network consists of n stations connected by bidirectional tracks. Each track connects two different stations and is associated with a specific length. The government wants to determine the minimum cost to connect all the stations such that every station can be reached from ... | 0.693314 | Taco_24949 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_all_stations"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_all_stations",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | cb6691394e8d10cc4c9d192cfff1863c0162e096 | 8202a3dcd3eaa321f43f1120dd2003d8b2b27e6d | |||
v1.0 | complete | Taco | Taco_24719_C | from typing import List, Tuple
def solve_tree_path_queries(n: int, A: List[int], edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Return the minimum value in the path from node u to node v for each query.
Args:
n (int): The number of nodes in the tree.
A (List[int]):... | from collections import defaultdict
import sys
import math
sys.setrecursionlimit(200000)
def dfs(node, parent, depth, A, adj, P, min_val):
P[node][0] = parent
min_val[node][0] = A[node]
for i in range(1, len(P[node])):
if P[node][i-1] != -1:
P[node][i] = P[P[node][i-1]][i-1]
... | def test_case_1():
n = 5
A = [4, 2, 5, 7, 3]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(1, 4), (4, 5), (3, 5)]
result = solve_tree_path_queries(n, A, edges, queries)
expected = [2, 2, 2]
assert result == expected
def test_case_2():
n = 3
A = [1, 2, 3]
edges = [(1, 2), ... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, depth, A, adj, P, min_val):",
"function_name": "dfs",
"parameter_list": "(node, parent, depth, A, adj, P, min_val)"
},
{
"docstring": null,
"function_declaration": "def find_lca_and_min(u, v, depth, P, min_val):",
"f... | [
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport collections\nimport math\n\ndef preprocess(n, values, edges):\n # Create a tree (adjacency list)\n tree = collections.defaultdict(list)\n ... | trial_gpt4o_5 | {
"original_instruction": "You are given a tree, which is a connected undirected graph with no cycles. The tree consists of $n$ nodes numbered from 1 to $n$, and $n-1$ edges connecting them.\n\nEach node in the tree has a value assigned to it, represented by an array $A$ of length $n$, where $A[i]$ represents the val... | 0.668839 | Taco_24719 | C | [
"dfs",
"find_lca_and_min",
"solve_tree_path_queries"
] | 3 | [
[
"solve_tree_path_queries",
"dfs"
],
[
"solve_tree_path_queries",
"find_lca_and_min"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 53ef651184bbb58063975c6307d8f6d24af2170b | 23da4c819b2222c807b4bd64500d8170aabf8f5d | |||
v1.0 | complete | Taco | Taco_24978_C | def longest_common_subsequence(a: str, b: str) -> int:
""" Calculate the longest common subsequence (LCS) length between two strings.
>>> longest_common_subsequence("abc", "abc")
3
>>> longest_common_subsequence("abc", "def")
0
>>> longest_common_subsequence("abc", "aebdc")
3
>>> longest... | def longest_common_subsequence(a, b):
m, n = len(a), len(b)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if a[i - 1] == b[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j... | from solution import find_best_answer, longest_common_subsequence
def test_longest_common_subsequence():
assert longest_common_subsequence("abc", "abc") == 3
assert longest_common_subsequence("abc", "def") == 0
assert longest_common_subsequence("abc", "aebdc") == 3
assert longest_common_subsequence("ab... | [
{
"docstring": null,
"function_declaration": "def longest_common_subsequence(a, b):",
"function_name": "longest_common_subsequence",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def find_best_answer(n, qa_pairs, user_question):",
"function_name": "find_... | [
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 lcs(X, Y):\n \"\"\" Function to compute the Longest Common Subsequence of X and Y \"\"\"\n matrix = [[0] * (len(Y) + 1) for _ in range(len(X) + 1)]\n ... | trial_gpt4o_2 | {
"original_instruction": "Marta is working on a chatbot service that should respond to a user's question with the best possible answer from a given set of predefined answers. The chatbot service has a set of predefined questions and their respective predefined answers stored in the form of strings. The aim is to fin... | 0.637423 | Taco_24978 | C | [
"longest_common_subsequence",
"find_best_answer"
] | 2 | [
[
"find_best_answer",
"longest_common_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d97f40a7ef56bdf6b1413e49df4eff1dfcd2e46 | dacb61b7bd06139b96b8e261010d10efede1499f | |||
v1.0 | complete | Taco | Taco_25067_C | def is_valid_license_plate(s):
"""
Checks if the given string is a valid license plate.
The valid formats are two uppercase letters followed by four digits,
or four digits followed by two uppercase letters.
"""
if len(s) != 6:
return "Invalid"
if (s[:2].isupper() and s[2:].isdig... | def is_valid_license_plate(s):
"""
Checks if the given string is a valid license plate.
The valid formats are two uppercase letters followed by four digits,
or four digits followed by two uppercase letters.
"""
if len(s) != 6:
return "Invalid"
if (s[:2].isupper() and s[2:].isdig... | def test_is_valid_license_plate():
assert is_valid_license_plate("AB1234") == "Valid"
assert is_valid_license_plate("1234AB") == "Valid"
assert is_valid_license_plate("abcd12") == "Invalid"
assert is_valid_license_plate("1A2B3C") == "Invalid"
assert is_valid_license_plate("ABCD12") == "Invalid"
... | [
{
"docstring": "Checks if the given string is a valid license plate.\nThe valid formats are two uppercase letters followed by four digits,\nor four digits followed by two uppercase letters.",
"function_declaration": "def is_valid_license_plate(s):",
"function_name": "is_valid_license_plate",
"parame... | [
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 re\n\ndef is_valid_license_plate(plate):\n \"\"\"\n Check whether the given plate is a valid license plate.\n Pattern: XXDDDD or DDDDXX where X is ... | trial_gpt4o_1 | {
"original_instruction": "In a certain country, license plates are formed based on specific patterns: they either start with two uppercase letters followed by four digits, or four digits followed by two uppercase letters. Given a set of strings, your objective is to identify which among them are valid license plates... | 0.578547 | Taco_25067 | C | [
"is_valid_license_plate",
"check_license_plates"
] | 2 | [
[
"check_license_plates",
"is_valid_license_plate"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 357a1516e762773e1a2528ede4c5c74a3198ce6a | 558b201c752fe5aea90a3b685ca94d6bc09c6fd5 | |||
v1.0 | complete | Taco | Taco_24906_C | def k_means_clustering(k, n, documents, embeddings_list):
"""
Classify the documents into k clusters using k-means clustering.
Parameters:
k (int): Number of clusters.
n (int): Number of documents.
documents (List[str]): List of n documents, each represented as a space-separated list of w... | import numpy as np
from sklearn.cluster import KMeans
def avg_vector(document, embeddings):
vectors = [embeddings[word] for word in document if word in embeddings]
return np.mean(vectors, axis=0) if vectors else np.zeros(300)
def k_means_clustering(k, n, documents, embeddings_list):
embeddings = {emb.spli... | from solution import k_means_clustering
def test_k_means_clustering():
k = 2
n = 3
documents = [
"apple banana fruit",
"fruit apple",
"dog cat pet"
]
embeddings_list = [
"apple 0.1 0.2 0.3 ..." + ' '.join(['0.299'] * 296),
"banana 0.4 0.5 0.6 ..." + ' '.join(... | [
{
"docstring": null,
"function_declaration": "def avg_vector(document, embeddings):",
"function_name": "avg_vector",
"parameter_list": "(document, embeddings)"
},
{
"docstring": null,
"function_declaration": "def k_means_clustering(k, n, documents, embeddings_list):",
"function_name"... | [
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": "import numpy as np\nfrom sklearn.cluster import KMeans\n\ndef convert_document_to_vector(document, word_embeddings):\n \"\"\"\n Conv... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with implementing a modified k-means clustering algorithm to automatically classify the topics of a set of documents. Each document is represented as a list of words and you will use a given pre-trained word embedding model to convert words to vectors.\n\nTo simplify, you wil... | 0.734966 | Taco_24906 | C | [
"avg_vector",
"k_means_clustering"
] | 2 | [
[
"k_means_clustering",
"avg_vector"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"sklearn"
] | false | 616d98af217701973d510d89be756db5bbac25d6 | 8a337ba6de14609efd56dbabdcd8bb7da9a1d0c6 | |||
v1.0 | complete | Taco | Taco_25138_C | from typing import List, Tuple
def preprocess_prefix_sums(arr: List[int]) -> List[int]:
"""
Preprocess the array to get the prefix sums which help in finding the sum of
any subarray efficiently.
"""
pass
def query_sum(prefix_sums: List[int], l: int, r: int) -> int:
"""
Returns the sum of t... | def preprocess_prefix_sums(arr):
"""
Preprocess the array to get the prefix sums which help in finding the sum of
any subarray efficiently.
"""
prefix_sums = [0] * (len(arr) + 1)
for i in range(len(arr)):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def query_sum(... | def test_preprocess_prefix_sums():
arr = [1, 2, 3, 4, 5]
assert preprocess_prefix_sums(arr) == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert query_sum(prefix_sums, 2, 4) == 9
assert query_sum(prefix_sums, 1, 5) == 15
assert query_sum(prefix_sums, 3, 3) == ... | [
{
"docstring": "Preprocess the array to get the prefix sums which help in finding the sum of\nany subarray efficiently.",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the... | [
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 process_queries(n, m, a, queries):\n \"\"\"\n This function processes the queries to get the sum of elements between indices l and r \n (1-based inclu... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of $n$ integers and a list of $m$ queries. Each query consists of two indices $l$ and $r$, and the task is to calculate the sum of the elements in the subarray from index $l$ to index $r$ (1-based inclusive). After answering all the queries, the array is modified by i... | 0.603356 | Taco_25138 | C | [
"preprocess_prefix_sums",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_prefix_sums"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 7e3f44d2891ddb34a3f199ac70e39b599276971b | 29fcdf13f699a1b3e2909a7f8094de505ac5202c | |||
v1.0 | complete | Taco | Taco_25477_C | def dijkstra(graph, n, start):
"""
Dijkstra's algorithm for finding the shortest paths from a given start vertex.
"""
# Implement the algorithm here
pass
def floyd_warshall(graph, n):
"""
Floyd-Warshall algorithm for finding shortest paths between all pairs of vertices.
"""
# Impl... | import heapq
def dijkstra(graph, n, start):
distances = [float('inf')] * n
distances[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_vertex = heapq.heappop(pq)
if current_distance > distances[current_vertex]:
continue
for neighbor, weight in graph[cu... | import sys
from io import StringIO
from solution import main
def run_test(input_data, expected_output):
old_stdin = sys.stdin
sys.stdin = StringIO(input_data)
try:
main()
finally:
sys.stdin = old_stdin
def test_case_1():
input_data = """5 6
1 2
2 3
3 4
4 1
4 5
5 2
3
0 4 1
0 1 2
0 5... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, n, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, n, start)"
},
{
"docstring": null,
"function_declaration": "def floyd_warshall(graph, n):",
"function_name": "floyd_warshall",
"parameter_list": ... | [
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": "import heapq\n\ndef dijkstra(graph, n, start):\n distances = [float('inf')] * n\n distances[start] = 0\n pq = [(0, start)]\n while pq:\n current... | trial_gpt4o_0 | {
"original_instruction": "You are given a directed graph with n vertices and m edges.\n\nSome operations need to be performed on this graph:\n\n* Reverse the direction of an existing edge.\n* Find the length of the shortest cycle in the graph.\n\nInitially, and after each operation, you should determine the length o... | 0.57998 | Taco_25477 | C | [
"dijkstra",
"floyd_warshall",
"shortest_cycle_length",
"reverse_edge",
"main"
] | 5 | [
[
"shortest_cycle_length",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 095a54d19f3906751960fcc15643b60379437cb4 | 796e7f13d71e3284be38f8946ea321069e9c1114 | |||
v1.0 | complete | Taco | Taco_25651_C | def is_prime(n: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(0) False
>>> is_prime(1) False
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
"""
# Implement the function here
def sumOfPrimes(numbers: List[int]) -> int:
""" Returns the sum of all prim... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import sumOfPrimes
def test_sumOfPrimes_with_primes():
numbers = [2, 3, 4, 5, 10]
assert sumOfPrimes(numbers) == 10
def test_sumOfPrimes_without_primes():
numbers = [10, 15, 20]
assert sumOfPrimes(numbers) == 0
def test_sumOfPrimes_empty_list():
numbers = []
assert sumOfPrimes(n... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list.",
"function_declaration": "def sumOfPrimes(numbers):",
"function_name": ... | [
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": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. Your task is to find the sum of all prime numbers in the list. If there are no prime numbers in the list, return 0. \n\nA prime number is defined as a number greater than 1 with no positive divisors other than 1 and itself.\n\nExample 1:\nInput:\nnumbers = ... | 0.785297 | Taco_25651 | C | [
"is_prime",
"sumOfPrimes"
] | 2 | [
[
"sumOfPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c9cecfd5542a85bae33ccbc46e0e7f93bfc25b14 | 4dbac1c76b8073932809983196a1816eceb16442 | |||
v1.0 | complete | Taco | Taco_25718_C | def min_path_costs(input_text):
""" Determine the minimum cost path in the grid from top-left to bottom-right.
>>> input_text = "2\n3 3\n1 3 1\n1 5 1\n4 2 1\n2 2\n1 2\n1 1"
>>> min_path_costs(input_text)
7
3
""" | def min_path_cost(grid):
N = len(grid)
M = len(grid[0])
# Initialize dp table
dp = [[0] * M for _ in range(N)]
dp[0][0] = grid[0][0]
# Fill the first row
for j in range(1, M):
dp[0][j] = dp[0][j-1] + grid[0][j]
# Fill the first column
for i in range(1, N):
dp[i][0]... | from solution import min_path_costs
def test_min_path_costs(capsys):
input_text = """2
3 3
1 3 1
1 5 1
4 2 1
2 2
1 2
1 1"""
expected_output = "7\n3\n"
min_path_costs(input_text)
captured = capsys.readouterr()
assert captured.out == expected_output | [
{
"docstring": null,
"function_declaration": "def min_path_cost(grid):",
"function_name": "min_path_cost",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_text):",
"function_name": "process_input",
"parameter_list": "(input_text... | [
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 min_path_cost(grid):\n N = len(grid)\n M = len(grid[0])\n\n # Initialize dp table\n dp = [[0] * M for _ in range(N)]\n dp[0][0] = grid[0][0]\n\n... | trial_gpt4o_0 | {
"original_instruction": "Alice loves playing board games. Recently, she bought a game where she needs to find paths in a grid. The grid is represented by a 2D array of size N x M, and each cell contains an integer that represents the difficulty of the cell. The game requires Alice to find the path from the top-left... | 0.662868 | Taco_25718 | C | [
"min_path_cost",
"process_input",
"min_path_costs"
] | 3 | [
[
"min_path_costs",
"process_input"
],
[
"process_input",
"min_path_cost"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 4e75bad16aca5d17cb50d519fa98caea4b778732 | d73224de526c93c73b2c028c809d6fc4cb9fa5c9 | |||
v1.0 | complete | Taco | Taco_25813_C | from typing import List
def number_of_unique_balanced_bsts(a: List[int]) -> int:
""" Determine the number of unique balanced binary search trees (BSTs)
that can be formed from a given sorted array of integers.
>>> number_of_unique_balanced_bsts([10]) == 1
>>> number_of_unique_balanced_bsts([10, 2... | from functools import lru_cache
@lru_cache(None)
def count_unique_bsts(n):
if n <= 1:
return 1
total_trees = 0
for i in range(n):
left_trees = count_unique_bsts(i)
right_trees = count_unique_bsts(n - 1 - i)
total_trees += left_trees * right_trees
return total_trees
def ... | from solution import number_of_unique_balanced_bsts
def test_small_arrays():
assert number_of_unique_balanced_bsts([10]) == 1
assert number_of_unique_balanced_bsts([10, 20]) == 2
assert number_of_unique_balanced_bsts([10, 20, 30]) == 5
def test_medium_arrays():
assert number_of_unique_balanced_bsts([1... | [
{
"docstring": null,
"function_declaration": "def count_unique_bsts(n):",
"function_name": "count_unique_bsts",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def number_of_unique_balanced_bsts(a):",
"function_name": "number_of_unique_balanced_bsts",
"pa... | [
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\ndef count_balanced_bsts(n):\n \"\"\"\n Returns the number of unique balanced BSTs that can be formed\n with n unique elements usi... | trial_gpt4o_2 | {
"original_instruction": "Alex loves to grow a different kind of tree today, a balanced binary search tree (BST) from an array of integers. A BST is a binary tree in which each node has at most two children, where the left child contains only nodes with values less than the parent node, and the right child only node... | 0.63735 | Taco_25813 | C | [
"count_unique_bsts",
"number_of_unique_balanced_bsts"
] | 2 | [
[
"number_of_unique_balanced_bsts",
"count_unique_bsts"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e188b96168112a7f4d3faac23ecb3454ec61927c | a57dac9970c49c1a5171b294644da303b6c63a3f | |||
v1.0 | complete | Taco | Taco_26187_C | def rotate_matrix_90_degrees(matrix):
"""
Rotate the given N x N matrix 90 degrees to the right.
>>> rotate_matrix_90_degrees([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
"""
def rotate_matrix(matrix, k):
"""
Rotate the given N x N matrix 90 degrees to the right ... | def rotate_matrix_90_degrees(matrix):
n = len(matrix)
rotated = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
rotated[j][n - 1 - i] = matrix[i][j]
return rotated
def rotate_matrix(matrix, k):
rotations = k % 4 # As 4 rotations bring the matrix to the initial... | def test_rotate_matrix_90_degrees():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_matrix_90_degrees(matrix) == expected
def test_rotate_matrix():
matrix = [
[1, 2, 3],
[4... | [
{
"docstring": null,
"function_declaration": "def rotate_matrix_90_degrees(matrix):",
"function_name": "rotate_matrix_90_degrees",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def rotate_matrix(matrix, k):",
"function_name": "rotate_matrix",
"para... | [
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 rotate_matrix_90_degrees(matrix):\n n = len(matrix)\n rotated = [[0] * n for _ in range(n)]\n for i in range(n):\n for j in range(n):\n ... | trial_gpt4o_0 | {
"original_instruction": "A group of friends are working on a project to design a game. In this game, a player has to solve sequences of transformations on matrices. Each transformation involves rotating a square matrix 90 degrees to the right, k times. The game has multiple levels, and each level gives the player a... | 0.576191 | Taco_26187 | C | [
"rotate_matrix_90_degrees",
"rotate_matrix",
"solve_game_configuration",
"main"
] | 4 | [
[
"rotate_matrix",
"rotate_matrix_90_degrees"
],
[
"solve_game_configuration",
"rotate_matrix"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 779596f5ff8b60626baa8c2398c38a42e5519464 | 4a7765dacc1c5b482a9c838ff04bcead07227cd8 | |||
v1.0 | complete | Taco | Taco_26394_C | def is_prime(num: int) -> bool:
""" Helper function to determine if a number is a prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(10) False
>>> is_prime(11) True
"""
def sum_of_primes(n: int) -> int:
""" Returns the sum o... | def is_prime(num):
"""
Helper function to determine if a number is a 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
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(11) == True
def test_sum_of_primes():
assert sum_of_primes(2) == 2... | [
{
"docstring": "Helper function to determine if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers less than or equal to n.",
"function_declaration": "def sum_... | [
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 sum_of_primes(n):\n \"\"\"\n Calculates the sum of all prime numbers less than or equal to n.\n \n Parameters:\n n (int): The upper limit intege... | trial_gpt4o_2 | {
"original_instruction": "Write a function that calculates the sum of all prime numbers less than or equal to a given integer n.\n\nInput\n\nAn integer n (2 ≤ n ≤ 1000) is given on a line.\n\nOutput\n\nPrint the sum of all prime numbers less than or equal to n on a line.\n\nExample\n\nInput\n\n10\n\nOutput\n\n17",
... | 0.800196 | Taco_26394 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6d78c136c6e9bb6236c5ca94906f21b91a829f7 | 9b6718c3e1c73398bff7a14717e140fb38d13b42 | |||
v1.0 | complete | Taco | Taco_25654_C | from typing import List, Tuple, Union
def kingdom_path(n: int, m: int, roads: List[str]) -> Union[int, Tuple[int, List[int]]]:
""" Finds the shortest possible path the king must travel through from Town 1 to Town n, without re-using any road.
If there is no possible route, returns -1.
Args:
n (int... | from collections import deque, defaultdict
def shortest_path(n, roads):
adj_list = defaultdict(list)
for u, v in roads:
adj_list[u].append(v)
adj_list[v].append(u)
dist = [-1] * (n + 1)
parent = [-1] * (n + 1)
dist[1] = 0
q = deque([1])
while q:
u = q.pople... | def test_kingdom_path_short_direct_route():
result = kingdom_path(5, 5, ["1 2", "2 3", "3 4", "4 5", "1 5"])
assert result == (1, [1, 5])
def test_kingdom_path_no_possible_route():
result = kingdom_path(5, 3, ["1 2", "2 3", "4 5"])
assert result == -1
def test_kingdom_path_complex_route():
result ... | [
{
"docstring": null,
"function_declaration": "def shortest_path(n, roads):",
"function_name": "shortest_path",
"parameter_list": "(n, roads)"
},
{
"docstring": null,
"function_declaration": "def kingdom_path(n, m, roads):",
"function_name": "kingdom_path",
"parameter_list": "(n, ... | [
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, defaultdict\n\ndef shortest_path(n, m, roads):\n graph = defaultdict(list)\n \n for u, v in roads:\n graph[u].append... | trial_gpt4o_2 | {
"original_instruction": "A kingdom is filled with numerous interconnected towns. Each pair of towns is either connected by a direct road or not. The king wants to travel from the capital city, Town 1, to his summer palace in Town n in the shortest number of steps possible. However, there's a twist: once he travels ... | 0.711046 | Taco_25654 | C | [
"shortest_path",
"kingdom_path"
] | 2 | [
[
"kingdom_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 453b0c0ba38d9d5d84529a0160205cce43f0b1f6 | 623c37c7bbc90915a304b09d3b9062a3b1fbe321 | |||
v1.0 | complete | Taco | Taco_26380_C | from typing import List
def prime_palindromes(n: int) -> List[int]:
""" Write a function that takes a positive integer `n` as an input and returns the list of all prime numbers less than `n` that are also palindromes.
A **palindrome number** is a number that reads the same backward as forward.
A **pri... | from typing import List
def is_prime(num: int) -> bool:
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
retur... | from solution import prime_palindromes
def test_prime_palindromes_less_than_30():
assert prime_palindromes(30) == [2, 3, 5, 7, 11]
def test_prime_palindromes_less_than_100():
assert prime_palindromes(100) == [2, 3, 5, 7, 11]
def test_prime_palindromes_less_than_200():
assert prime_palindromes(200) == [2,... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring... | [
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 typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or n... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes a positive integer `n` as an input and returns the list of all prime numbers less than `n` that are also palindromes.\n\nA **palindrome number** is a number that reads the same backward as forward (e.g., 101, 131, 151).\n\nA **prime number** is a number greater t... | 0.666835 | Taco_26380 | C | [
"is_prime",
"is_palindrome",
"prime_palindromes"
] | 3 | [
[
"prime_palindromes",
"is_palindrome"
],
[
"prime_palindromes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 955bb8d5aa5fba64a5a944bab8468bd67b133163 | 73e57b239f5c1e245267bc27de357e772572a9ca | |||
v1.0 | complete | Taco | Taco_26400_C | def is_prime(n):
"""
Determine if a number is prime.
>>> is_prime(1) == False
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(13) == True
"""
def thoneo_is_prime(b, queries):
"""
Process Thoneo's queries to up... | def is_prime(n):
"""
Determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def thoneo_is_prime(b, queries):... | def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(13) == True
def test_thoneo_is_prime():
b = [3, 5, 7, 9, 11]
queries = [(2, 3), (1, 2, 4), (2, 2), (2, 5)]
re... | [
{
"docstring": "Determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def thoneo_is_prime(b, queries):",
"function_name": "thoneo_is_prime",
"parameter_li... | [
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 Determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n ... | trial_gpt4o_0 | {
"original_instruction": "Professor Thoneo recently invented a new function, which she named ThoneoisPrime. For a given integer array `b`, indexed from `1` to `n`, the function ThoneoisPrime(b, k) represents the count of prime numbers in the subarray from the 1st to the kth element.\n\nThoneo has posed a challenge f... | 0.711727 | Taco_26400 | C | [
"is_prime",
"thoneo_is_prime"
] | 2 | [
[
"thoneo_is_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a3145ffd45b1a3632f83a5d6fe63f68460a1fa3e | 3b4754a7eb28e5b6fb91ca6e795bf5d9dde5bd47 | |||
v1.0 | complete | Taco | Taco_26397_C | def total_cooking_time(test_cases):
"""
Determines the minimum total cooking time for a chef to cook all ingredients sequentially.
Args:
test_cases (List[Tuple[int, List[int]]]): A list of test cases, where each test case is a tuple
containing an inte... | def total_cooking_time(test_cases):
results = []
for case in test_cases:
N, times = case
total_time = sum(times)
results.append(total_time)
return results
def parse_input(input_data):
lines = input_data.strip().split('\n')
T = int(lines[0])
test_cases = []
index = 1
... | from solution import cooking_time_wrapper
def test_cooking_time_example_cases():
input_data = "2\n3\n10 20 30\n4\n5 10 15 20\n"
assert cooking_time_wrapper(input_data) == [60, 50]
def test_cooking_time_single_case_small():
input_data = "1\n1\n100\n"
assert cooking_time_wrapper(input_data) == [100]
de... | [
{
"docstring": null,
"function_declaration": "def total_cooking_time(test_cases):",
"function_name": "total_cooking_time",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"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": "def cooking_time(test_cases):\n \"\"\"\n Returns the minimum total cooking time for each test case.\n \"\"\"\n results = []\n for case in test_cases... | trial_gpt4o_2 | {
"original_instruction": "A chef is preparing a special dish that requires cooking multiple ingredients in a sequence. Each ingredient i needs a certain cooking time ti, and the ingredients must be cooked in a specific order. The chef can cook only one ingredient at a time. Given the cooking times of the ingredients... | 0.616353 | Taco_26397 | C | [
"total_cooking_time",
"parse_input",
"cooking_time_wrapper"
] | 3 | [
[
"cooking_time_wrapper",
"parse_input"
],
[
"cooking_time_wrapper",
"total_cooking_time"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 89831293346373522d03a4b582abd4c7e32f6849 | 1eb038fddb891a384110137eb1fb2f528ff14f20 | |||
v1.0 | complete | Taco | Taco_26432_C | def is_path_exist(N: int, M: int, grid: List[List[int]]) -> str:
""" Determines if there is a path from the top-left corner to the bottom-right corner of a grid.
>>> is_path_exist(3, 3, [
... [0, 0, 0],
... [1, 0, 1],
... [1, 0, 0]
... ])
"YES"
>>> is_path_exist(3,... | def can_reach_destination(grid):
from collections import deque
N = len(grid)
M = len(grid[0])
# Directions for exploring adjacent cells: up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
# Queue for BFS, starting from (0, 0)
queue = deque([(0, 0)])
# Se... | def test_simple_path():
N, M = 3, 3
grid = [
[0, 0, 0],
[1, 0, 1],
[1, 0, 0]
]
assert is_path_exist(N, M, grid) == "YES"
def test_no_path():
N, M = 3, 3
grid = [
[0, 0, 0],
[1, 1, 1],
[1, 0, 0]
]
assert is_path_exist(N, M, grid) == "NO"
d... | [
{
"docstring": null,
"function_declaration": "def can_reach_destination(grid):",
"function_name": "can_reach_destination",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def is_path_exist(N, M, grid):",
"function_name": "is_path_exist",
"parameter_lis... | [
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 can_reach_bottom_right(grid):\n from collections import deque\n\n N = len(grid)\n M = len(grid[0])\n\n # Directions for moving {Up, Down, Left, Rig... | trial_gpt4o_2 | {
"original_instruction": "In a grid-based puzzle game, the player can move from one cell to any adjacent cell. Adjacent cells are those that share a side (up, down, left, right). The grid is represented by a 2D array of integers, where the player starts at the top-left corner (0, 0) and needs to move to the bottom-r... | 0.668564 | Taco_26432 | C | [
"can_reach_destination",
"is_path_exist"
] | 2 | [
[
"is_path_exist",
"can_reach_destination"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 46484caea90ab20b1a2876579272f6c2eecdc7a4 | 443f532cebe0d88ba7ea14b379561fc06f9b7f95 | |||
v1.0 | complete | Taco | Taco_25670_C | def max_bandwidth(n: int, m: int, connections: List[Tuple[int, int, int]], s: int, t: int) -> int:
""" Calculate the maximum bandwidth that can be routed from server s to server t without exceeding the bandwidth limits of any connections.
>>> max_bandwidth(4, 5, [(1, 2, 10), (1, 3, 5), (2, 3, 15), (2, 4, 10), (... | from collections import defaultdict, deque
def bfs(capacity, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
u = queue.popleft()
for v in capacity[u]:
if v not in visited and capacity[u][v] > 0:
... | from solution import max_bandwidth
def test_single_path():
n = 2
m = 1
connections = [(1, 2, 10)]
s = 1
t = 2
assert max_bandwidth(n, m, connections, s, t) == 10
def test_multiple_paths():
n = 4
m = 5
connections = [
(1, 2, 10),
(1, 3, 5),
(2, 3, 15),
... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, edges, source, sink):",
"function_name": "edmonds... | [
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": "import heapq\n\ndef dijkstra(n, adj_list, source, target):\n max_bandwidth = [0] * (n + 1)\n max_bandwidth[source] = float('inf')\n priority_queue = [(flo... | trial_gpt4o_1 | {
"original_instruction": "Alicia is working on a large distributed system composed of multiple servers. She wants to optimize the use of the network bandwidth when transferring data between servers. Each server is directly connected to several other servers, and each connection has a certain bandwidth limit. Alicia ... | 0.538995 | Taco_25670 | C | [
"bfs",
"edmonds_karp",
"max_bandwidth"
] | 3 | [
[
"edmonds_karp",
"bfs"
],
[
"max_bandwidth",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e021c61d32e85393295af1c5d73205f697b9caa4 | be15ac16568da823810d80d7d27dc6e5cd999e79 | |||
v1.0 | complete | Taco | Taco_26461_C | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(value) for value in values]
for a, b in edges:
nodes[a - 1].children.append(nodes[b - 1])
nodes[b - 1].children.append(nodes[a - 1])
retur... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(value) for value in values]
for a, b in edges:
nodes[a - 1].children.append(nodes[b - 1])
nodes[b - 1].children.append(nodes[a - 1])
retur... | from solution import sum_path_between_nodes
def test_sum_path_between_nodes_example1():
n = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
u, v = 2, 4
assert sum_path_between_nodes(n, values, edges, u, v) == 10
def test_sum_path_between_nodes_example2():
n = 3
values =... | [] | [
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 TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(values, edges):\n nodes = [TreeNode(va... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree with n nodes, each node having a positive integer value. Your task is to calculate the sum of values of all nodes lying in the path between two given nodes u and v (inclusive, considering the values of u and v themselves in the sum).\n\n-----Input-----\n\nThe fir... | 0.63537 | Taco_26461 | C | [
"build_tree",
"dfs",
"sum_path_between_nodes"
] | 3 | [
[
"sum_path_between_nodes",
"build_tree"
],
[
"sum_path_between_nodes",
"dfs"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | cf6c73fbee46a6bf3bd28b2542456731ac8bc37b | c32a3b162732baa81fbf489453f8052849688657 | |||
v1.0 | complete | Taco | Taco_26931_C | def count_queens(N: int) -> int:
""" Determine the maximum possible number of queens that can be placed on the N x N chessboard without any two queens attacking each other.
>>> count_queens(4) 4
>>> count_queens(2) 0
>>> count_queens(8) 8
""" | def is_safe(board, row, col, n):
# Check the same column
for i in range(row):
if board[i][col] == 'Q':
return False
# Check the upper left diagonal
for i, j in zip(range(row, -1, -1), range(col, -1, -1)):
if board[i][j] == 'Q':
return False
# Check the upper... | from solution import count_queens
def test_count_queens_1():
assert count_queens(1) == 1
def test_count_queens_2():
assert count_queens(2) == 0
def test_count_queens_3():
assert count_queens(3) == 0
def test_count_queens_4():
assert count_queens(4) == 4
def test_count_queens_5():
assert count_q... | [
{
"docstring": null,
"function_declaration": "def is_safe(board, row, col, n):",
"function_name": "is_safe",
"parameter_list": "(board, row, col, n)"
},
{
"docstring": null,
"function_declaration": "def solve_n_queens(board, row, n, result):",
"function_name": "solve_n_queens",
"... | [
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 solveNQueens(N):\n \"\"\" Returns the solution to the N-Queens problem \"\"\"\n def isSafe(board, row, col):\n # Check this row on the left side\n... | trial_gpt4o_8 | {
"original_instruction": "Ming is a chess enthusiast and likes to place queens on a chessboard. One day, a friend challenged him to place as many queens as possible on an N x N chessboard such that no two queens can attack each other. You may recall that a queen in chess can move horizontally, vertically, or diagona... | 0.537319 | Taco_26931 | C | [
"is_safe",
"solve_n_queens",
"max_queens",
"count_queens"
] | 4 | [
[
"max_queens",
"solve_n_queens"
],
[
"solve_n_queens",
"is_safe"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e44747be758ce4904dea11a27fcfa72c2c820a77 | f4e925a8c094cfef2b6566d634f3b8e323a0074c | |||
v1.0 | complete | Taco | Taco_26727_C | from typing import List
def shortest_transformation_sequence(start: str, target: str, word_list: List[str]) -> int:
"""Returns the length of the shortest transformation sequence from start to target
using words from word_list.
Example:
>>> shortest_transformation_sequence("hit", "cog", ["hot","dot... | from collections import deque
def is_one_char_diff(word1, word2):
"""
Helper function to check if two words differ by exactly one character.
"""
count = 0
for c1, c2 in zip(word1, word2):
if c1 != c2:
count += 1
if count > 1:
return False
return count == ... | from solution import shortest_transformation_sequence
def test_example_1():
start = "hit"
target = "cog"
word_list = ["hot", "dot", "dog", "lot", "log", "cog"]
assert shortest_transformation_sequence(start, target, word_list) == 5
def test_example_2():
start = "hit"
target = "cog"
word_lis... | [
{
"docstring": "Helper function to check if two words differ by exactly one character.",
"function_declaration": "def is_one_char_diff(word1, word2):",
"function_name": "is_one_char_diff",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Returns the length of the shortest transformation... | [
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 shortest_transformation_sequence(start, target, word_list):\n if target not in word_list:\n return 0\n\n word_set... | trial_gpt4o_2 | {
"original_instruction": "Write a program to find the length of the shortest transformation sequence from a starting word to a target word, given a list of intermediate words. Each intermediate word represents a valid transformation if it is one character change away from the current word, and all transformations mu... | 0.68956 | Taco_26727 | C | [
"is_one_char_diff",
"shortest_transformation_sequence"
] | 2 | [
[
"shortest_transformation_sequence",
"is_one_char_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c5ba324a162cb13bee2946cf9353afaf6601253b | e43e2e5cdbe5c85bd2848d4a00fd0d76d8327b7f | |||
v1.0 | complete | Taco | Taco_26477_C | def find_kth_highest_sales(test_cases):
"""Calculate the K-th highest sales amount across various days.
Args:
test_cases: List of dictionaries containing days data and queries
Returns:
List of integers representing the K-th highest sales amount for each query
>>> test_cases = [
... | def find_kth_highest_sales(test_cases):
results = []
for case in test_cases:
N, Q, days_data, queries = case['N'], case['Q'], case['days'], case['queries']
all_sales = []
for sales in days_data:
all_sales.extend(sales)
all_sales.sort(reverse=Tru... | import pytest
def test_example_case():
input_str = "1\n3 2\n10 20 30\n15 25 35\n5 50\n2\n5"
expected_output = [35, 20]
assert get_results(input_str) == expected_output
def test_all_identical_sales():
input_str = "1\n2 2\n10 10 10\n10 10\n3\n6"
expected_output = [10, None]
assert get_results(in... | [
{
"docstring": null,
"function_declaration": "def find_kth_highest_sales(test_cases):",
"function_name": "find_kth_highest_sales",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"para... | [
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 find_kth_highest_sales(num_test_cases, test_cases):\n results = []\n for test_case in test_cases:\n N, Q, days_sales, queries = test_case\n ... | trial_gpt4o_2 | {
"original_instruction": "Read problem statements in CSV format here\n\nA large retail company wants to analyze its sales performance on different days of the week. Each day's sales data is represented as an integer array. The company wants to find out the K-th highest sales amount across all the days combined for v... | 0.625758 | Taco_26477 | C | [
"find_kth_highest_sales",
"parse_input",
"get_results"
] | 3 | [
[
"get_results",
"find_kth_highest_sales"
],
[
"get_results",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 6722a7ed89fcab51521073643ce21c8742f37106 | 8d38bccdc1912fca580e9561e8d3b3cec6a1f781 | |||
v1.0 | complete | Taco | Taco_26837_C | from typing import Union, Tuple
def find_prime_pair(S: int) -> Union[Tuple[int, int], str]:
""" Snuke has a favorite number S and he is very fond of prime numbers. He decides to find a pair of prime numbers (p1, p2) such that p1 + p2 = S and |p1 - p2| is minimized. If there is more than one pair with the same diff... | import math
def sieve_of_eratosthenes(max_num):
"""
Generates a list of booleans indicating primality of numbers up to max_num.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers
for start in range(2, int(math.sqrt(max_num)) + 1):
... | def test_find_prime_pair():
assert find_prime_pair(10) == (3, 7) or find_prime_pair(10) == (5, 5)
assert find_prime_pair(34) == (17, 17)
assert find_prime_pair(40) == (17, 23)
assert find_prime_pair(2) == "No pair found"
assert find_prime_pair(20) == (7, 13)
def test_prime_pairs_large_input():
... | [
{
"docstring": "Generates a list of booleans indicating primality of numbers up to max_num.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": null,
"function_declaration": "def find_p... | [
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": "def find_prime_pair(S):\n \"\"\"\n Find two prime numbers p1 and p2 such that:\n - p1 + p2 == S\n - |p1 - p2| is minimized\n - If multiple pairs hav... | trial_gpt4o_9 | {
"original_instruction": "Snuke has a favorite number S and he is very fond of prime numbers. He decides to find a pair of prime numbers (p1, p2) such that p1 + p2 = S and |p1 - p2| is minimized. If there is more than one pair with the same difference, choose the one with the largest p1. If no such pair exists, outp... | 0.700416 | Taco_26837 | C | [
"sieve_of_eratosthenes",
"find_prime_pair"
] | 2 | [
[
"find_prime_pair",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 87c05a6825376fb67787bcf63b5966946b8fbea9 | a4d86685c5ad5ed884570d27b061a7eccaf9587a | |||
v1.0 | complete | Taco | Taco_26126_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(levels):
"""Build a binary tree from the list of level order traversal values."""
pass
def calculate_mystic_sum(node, depth=1):
"""Calculate... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(levels):
if not levels or levels[0] == -1:
return None
root = TreeNode(levels[0])
queue = [(root, 1)]
i = 1
while i < len(lev... | def test_build_tree():
levels = [1, 2, 3, 4, 5, 6, -1, -1, -1, -1, -1, -1, -1]
root = build_tree(levels)
assert root.value == 1
assert root.left.value == 2
assert root.right.value == 3
assert root.left.left.value == 4
assert root.left.right.value == 5
assert root.right.left.value == 6
d... | [] | [
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 deque\n\nclass TreeNode:\n def __init__(self, value=0):\n self.value = value\n self.left = None\n self.right = None... | trial_gpt4o_3 | {
"original_instruction": "In a magical land called Algorithmia, there is a special kind of tree with nodes that hold valuable information. Each node in this binary tree has a numerical value. The people of Algorithmia have developed a ritual where they must calculate the \"mystic sum\" of the tree before they can us... | 0.540137 | Taco_26126 | C | [
"build_tree",
"calculate_mystic_sum",
"mystic_sum"
] | 3 | [
[
"mystic_sum",
"build_tree"
],
[
"mystic_sum",
"calculate_mystic_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | edd279c3d7816a2e076ac2e5369fbdd1cc9eb102 | 520a245fa147b3c2d4ec2383b7b16e5d0283798a | |||
v1.0 | complete | Taco | Taco_26927_C | def process_input(M: int, N: int, K: int, grid_lines: List[str]) -> List[str]:
""" Simulates the Game of Life and returns the state of the grid after K iterations.
The game follows these rules:
1. Any live cell with fewer than two live neighbors dies (underpopulation).
2. Any live cell with two or ... | def get_next_state(grid, M, N):
def get_live_neighbors_count(grid, x, y):
live_neighbors = 0
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < M and 0 <= ny < N and grid[n... | from solution import process_input
def test_example_case_1():
M, N, K = 3, 3, 1
grid_lines = ['.O.', 'OOO', '.O.']
expected_output = ['OOO', 'O.O', 'OOO']
assert process_input(M, N, K, grid_lines) == expected_output
def test_minimal_case():
M, N, K = 1, 1, 1
grid_lines = ['.']
expected_out... | [
{
"docstring": null,
"function_declaration": "def get_next_state(grid, M, N):",
"function_name": "get_next_state",
"parameter_list": "(grid, M, N)"
},
{
"docstring": null,
"function_declaration": "def game_of_life(grid, M, N, K):",
"function_name": "game_of_life",
"parameter_list... | [
0,
0,
0,
0,
0,
0,
1,
0,
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 game_of_life(M, N, K, grid):\n def count_live_neighbors(board, r, c):\n directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (... | trial_gpt4o_6 | {
"original_instruction": "A game involves a grid of cells, where each cell can be either alive or dead. This game follows specific rules:\n\n1. Any live cell with fewer than two live neighbors dies (underpopulation).\n2. Any live cell with two or three live neighbors lives on to the next generation.\n3. Any live cel... | 0.541906 | Taco_26927 | C | [
"get_next_state",
"game_of_life",
"process_input"
] | 3 | [
[
"game_of_life",
"get_next_state"
],
[
"process_input",
"game_of_life"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d1e44ba2c766959317598143c12bd8e92f9253f4 | 790cfe7685ff109870f81365c9a80aea750d21fd | |||
v1.0 | complete | Taco | Taco_26782_C | def percy_gemstones(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""" Given the number of test cases T and a list of tuples (n, beauty values), determine the maximum possible beauty value of the last remaining gemstone for each test case.
Parameters:
T (int): number of test cases.
test... | def median_of_three(a, b, c):
"""
Given three numbers a, b, and c, return their median.
"""
return sorted([a, b, c])[1]
def max_beauty_value(n, beauties):
"""
Given the number of gemstones and their beauty values, return the maximum possible beauty value
of the gemstone if Percy keeps apply... | from solution import percy_gemstones
def test_case_1():
T = 1
test_cases = [(3, [1, 3, 2])]
assert percy_gemstones(T, test_cases) == [2]
def test_case_2():
T = 1
test_cases = [(4, [4, 2, 5, 1])]
assert percy_gemstones(T, test_cases) == [4]
def test_case_3():
T = 1
test_cases = [(5... | [
{
"docstring": "Given three numbers a, b, and c, return their median.",
"function_declaration": "def median_of_three(a, b, c):",
"function_name": "median_of_three",
"parameter_list": "(a, b, c)"
},
{
"docstring": "Given the number of gemstones and their beauty values, return the maximum poss... | [
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 max_beauty_value(n, beauties):\n \"\"\"\n Determine the maximum possible beauty value of the last remaining gemstone.\n :param n: Number of gemstones\... | trial_gpt4o_3 | {
"original_instruction": "Percy the Hedgehog loves collecting shiny objects, and he's particularly fond of gemstones. He organizes his gemstones in a linear sequence based on their intrinsic beauty values, represented as a sequence of integers.\n\nTo upgrade his collection, Percy engages in the following magical ope... | 0.570354 | Taco_26782 | C | [
"median_of_three",
"max_beauty_value",
"percy_gemstones"
] | 3 | [
[
"percy_gemstones",
"max_beauty_value"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4caecd9aa8dacf742f4ee1a3e6ca1055332b7bd | 7cb10069f0b11eaa894415dca272c04ae6d131bc | |||
v1.0 | complete | Taco | Taco_27076_C | def smallest_palindromic_prime_greater_than(n: int) -> int:
""" Finds the smallest palindromic prime greater than a given number n.
>>> smallest_palindromic_prime_greater_than(31)
101
>>> smallest_palindromic_prime_greater_than(11)
101
>>> smallest_palindromic_prime_greater_than(101)
131
... | 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 is_palindrome(num):
re... | from solution import smallest_palindromic_prime_greater_than
def test_example_1():
assert smallest_palindromic_prime_greater_than(31) == 101
def test_example_2():
assert smallest_palindromic_prime_greater_than(11) == 101
def test_example_3():
assert smallest_palindromic_prime_greater_than(101) == 131
de... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring... | [
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(num):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef is_prime(num):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "Your friend has recently learned about prime numbers and palindrome numbers. They are now interested in finding numbers that are both prime and palindrome, which we call \"palindromic primes\". To help your friend, you decide to write a program that finds the smallest palindromic prime grea... | 0.681028 | Taco_27076 | C | [
"is_prime",
"is_palindrome",
"smallest_palindromic_prime_greater_than"
] | 3 | [
[
"smallest_palindromic_prime_greater_than",
"is_palindrome"
],
[
"smallest_palindromic_prime_greater_than",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8e4e1bac54a8b9f279e26c8c7178d7992cafe602 | 7db34995dd48fb78c327e3770e3dbd6bb1069dcd | |||
v1.0 | complete | Taco | Taco_26664_C | def is_prime(n: int) -> bool:
"""Check if a number is prime."""
pass
def check_prime_in_subarray(arr: List[int], queries: List[Tuple[int, int]]) -> List[str]:
"""Given a rotated sorted array and a list of queries, check if the subarray for each query contains at least one prime number.
Args:
arr: ... | # To check for prime numbers
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 check_prime_i... | from solution import is_prime, check_prime_in_subarray
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
def test_check_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def check_prime_in_subarray(arr, queries):",
"function_name": "check_prime_in_subarray",
"parameter_list": "(arr,... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"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 \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return Tru... | trial_gpt4o_9 | {
"original_instruction": "Alex is a fan of prime numbers and loves solving problems involving them. One day, his friend gave him a challenge involving a rotated sorted array.\n\nAlex is given a rotated sorted array of $N$ integers and is then provided with a list of $Q$ queries. Each query consists of two integers $... | 0.718493 | Taco_26664 | C | [
"is_prime",
"check_prime_in_subarray"
] | 2 | [
[
"check_prime_in_subarray",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6f5b7a3c29e3e5f439eea0ba94247d5193df86a | 14f6b4f3f8459e2e2e60dd61a2eb90971d187876 | |||
v1.0 | complete | Taco | Taco_27189_C | import re
def is_valid_email(email: str) -> str:
"""
Validates an email address based on the given rules.
>>> is_valid_email("user.name@example.com")
"valid"
>>> is_valid_email("user--name@example-domain.com")
"invalid"
"""
pass
def process_emails(M: int, emails: List[str]) -> List[str... | import re
def is_valid_email(email):
"""
Validates an email address based on the given rules.
"""
email_regex = re.compile(
r'^[a-z0-9]+[a-z0-9._-]*[a-z0-9]+@[a-z0-9]+\.[a-z0-9]+$',
re.IGNORECASE
)
local_part = re.compile(r'^[a-z0-9]+([._-][a-z0-9]+)*$', re.IGNORECASE)
... | from solution import is_valid_email, process_emails
def test_single_valid_emails():
assert is_valid_email("user.name@example.com") == "valid"
assert is_valid_email("abc.def@mail.com") == "valid"
def test_single_invalid_emails():
assert is_valid_email("user--name@example-domain.com") == "invalid"
asser... | [
{
"docstring": "Validates an email address based on the given rules.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": null,
"function_declaration": "def process_emails(M, emails):",
"function_name... | [
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 re\n\ndef validate_emails(email_list):\n \"\"\"\n Given a list of email addresses, return a list indicating whether each email is 'valid' or 'invalid'... | trial_gpt4o_1 | {
"original_instruction": "Given a list of up to 100,000 email addresses, write a program that processes them to identify which of the email addresses are valid, according to the following rules:\n1. The email address must start with a local part, followed by the \"@\" symbol, and then a domain part.\n2. The local pa... | 0.646634 | Taco_27189 | C | [
"is_valid_email",
"process_emails"
] | 2 | [
[
"process_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f924f7a5e46bc076cd5dde8dcc5a9b9ddfee9823 | 722f86373f4a3d1db59765a2e4a6fcd4b9ccf433 | |||
v1.0 | complete | Taco | Taco_26987_C | def create_prefix_sum(arr):
"""
Creates a prefix sum array for the given array.
>>> create_prefix_sum([1, 2, 3, 4, 5]) [0, 1, 3, 6, 10, 15]
>>> create_prefix_sum([10**6, 10**6, 10**6]) [0, 10**6, 2*10**6, 3*10**6]
>>> create_prefix_sum([-1, -2, -3, -4]) [0, -1, -3, -6, -10]
"""
def subarray... | def create_prefix_sum(arr):
"""
Creates a prefix sum array for the given array.
"""
prefix_sum = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1]
return prefix_sum
def subarray_sum(arr, queries):
"""
Given an array and queries,... | def test_create_prefix_sum():
arr = [1, 2, 3, 4, 5]
expected = [0, 1, 3, 6, 10, 15]
assert create_prefix_sum(arr) == expected
def test_subarray_sum():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 5), (1, 5)]
expected = [6, 14, 15]
assert subarray_sum(arr, queries) == expected
def test_suba... | [
{
"docstring": "Creates a prefix sum array for the given array.",
"function_declaration": "def create_prefix_sum(arr):",
"function_name": "create_prefix_sum",
"parameter_list": "(arr)"
},
{
"docstring": "Given an array and queries, returns the sum of the subarrays for each query.\n\nParamete... | [
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 precompute_prefix_sums(arr):\n \"\"\"\n Precompute prefix sums for the array.\n \"\"\"\n prefix_sums = [0] * (len(arr) + 1)\n for i in range(1, ... | trial_gpt4o_2 | {
"original_instruction": "You are given a sequence of integers. You need to answer several queries about the sum of the elements in a subarray. More formally, each query is defined by two integers `L` and `R`. You need to output the sum of the elements in the subarray that starts at position `L` and ends at position... | 0.615757 | Taco_26987 | C | [
"create_prefix_sum",
"subarray_sum"
] | 2 | [
[
"subarray_sum",
"create_prefix_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 66fc4c86c76a236c71a45170f86b43051bfa5e3d | aa43507c1975a134fc215848fe3d318e528799b0 | |||
v1.0 | complete | Taco | Taco_27244_C | from typing import Optional, List
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def hasPathSum(root: Optional[TreeNode], targetSum: int) -> bool:
if not root:
return False
targetSum -= root.val
if not root.left and not root.... | from typing import Optional, List
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def hasPathSum(root: Optional[TreeNode], targetSum: int) -> bool:
if not root:
return False
targetSum -= root.val
if not root.left and not root.... | import pytest
from solution import determine_path_sum_exists
def test_basic_case():
test_data = [
[5, 22, [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1]],
[3, 5, [1, 2, 3]]
]
assert determine_path_sum_exists(2, test_data) == ["Yes", "No"]
def test_single_node_tree():
test_data =... | [] | [
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\ndef hasPath... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with N nodes. Each node has an integer value associated with it. Your task is to determine if there exists a path from the root to any leaf such that the sum of the values of the nodes along the path equals a given integer targetSum.\n\nA binary tree is defined a... | 0.590748 | Taco_27244 | C | [
"hasPathSum",
"build_tree",
"determine_path_sum_exists"
] | 3 | [
[
"determine_path_sum_exists",
"build_tree"
],
[
"determine_path_sum_exists",
"hasPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | f08a1513f2b299f52a676159d626d32ec8a84efd | 1c7e07af410275f6888b4d9885bb28d9955aecd0 | |||
v1.0 | complete | Taco | Taco_26749_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def find_paths(root, target_sum):
"""
Find all root-to-leaf paths in a binary tree where each path's sum equals the target sum.
Parameters:
root (T... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def find_paths(root, target_sum):
if not root:
return []
def dfs(node, current_sum, path, results):
if not node:
return
... | from solution import parse_input, build_tree, find_paths, run_tests
def test_parse_input():
input_data = "1\n22\n5 4 8 11 None 13 4 7 2 None None None 1"
expected = [(22, [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1])]
assert parse_input(input_data) == expected
def test_build_tree():
level_ord... | [] | [
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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_t... | trial_gpt4o_4 | {
"original_instruction": "Problem Description\n\nA very powerful alien race has challenged you to solve a puzzle to prove human intelligence. The puzzle is called \"Binary Tree Path Sum\". \n\nYou are given a binary tree where each node contains an integer value (which can be negative or positive). Your task is to f... | 0.601408 | Taco_26749 | C | [
"find_paths",
"build_tree",
"parse_input",
"run_tests"
] | 4 | [
[
"run_tests",
"build_tree"
],
[
"run_tests",
"find_paths"
],
[
"run_tests",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 75b6cbbe0cddd88ceb39f81d3bead513d591d12f | 2c411156a3129f868e74afa63dac2a9ff0977997 | |||
v1.0 | complete | Taco | Taco_27508_C | def is_perfect_square(n: int) -> bool:
"""
Check if a number is a perfect square.
"""
pass
def is_perfect_cube(n: int) -> bool:
"""
Check if a number is a perfect cube.
"""
pass
def check_perfect_square_and_cube(t: int, numbers: List[int]) -> List[str]:
"""
For each number in t... | def is_perfect_square(n):
"""
Check if a number is a perfect square.
"""
root = int(n**0.5)
return root * root == n
def is_perfect_cube(n):
"""
Check if a number is a perfect cube.
"""
root = int(n**(1/3))
return root * root * root == n or (root + 1) * (root + 1) * (root + 1) ==... | from solution import is_perfect_square, is_perfect_cube, check_perfect_square_and_cube
def test_is_perfect_square():
assert is_perfect_square(64) == True
assert is_perfect_square(65) == False
assert is_perfect_square(729) == True
assert is_perfect_square(1000) == False
def test_is_perfect_cube():
... | [
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a perfect cube.",
"function_declaration": "def is_perfect_cube(n):",
"fu... | [
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_perfect_square(n):\n \"\"\"Check if n is a perfect square.\"\"\"\n root = int(n**0.5) \n return root * root == n\n\ndef is_perfect_cube(n):\n \"... | trial_gpt4o_2 | {
"original_instruction": "Lisa is passionate about numbers and loves to explore interesting properties about them. She is particularly fascinated by numbers that satisfy both of the following conditions:\n\n1. **Perfect square**: A number that can be expressed as the square of an integer.\n2. **Perfect cube**: A num... | 0.696624 | Taco_27508 | C | [
"is_perfect_square",
"is_perfect_cube",
"check_perfect_square_and_cube"
] | 3 | [
[
"check_perfect_square_and_cube",
"is_perfect_cube"
],
[
"check_perfect_square_and_cube",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c1ea875cd6195c0d996d7f3895f10994135197aa | 046453b724492b4ad3581e192e03224e7443bcba | |||
v1.0 | complete | Taco | Taco_27324_C | from typing import List
def solve(n: int, C: List[int]) -> int:
"""
Given a sequence C, where each element is an integer, calculate the sum of g(D) for
all subsequences D, modulo 998 244 353.
Parameters:
n (int): Length of the sequence C.
C (List[int]): The sequence of integers.
Re... | from itertools import combinations
MOD = 998244353
def max_subarray_sum(arr):
max_ending_here = max_so_far = 0
for x in arr:
max_ending_here = max(0, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
def prefix_sum(arr):
p = [0] * len(arr)
p[0] =... | def test_solve_example_1():
async def validate():
assert solve(4, [1, -2, 3, -4]) == 36
def test_solve_example_2():
async def validate():
assert solve(3, [5, -4, 2]) == 27
def test_solve_single_element_positive():
async def validate():
assert solve(1, [10]) == 10
def test_solve_si... | [
{
"docstring": null,
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def prefix_sum(arr):",
"function_name": "prefix_sum",
"parameter_list": "(arr)"
},
{
... | [
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 itertools import combinations\nfrom functools import lru_cache\n\nMOD = 998244353\n\ndef calculate_prefix_sums(sequence):\n prefix_sums = [0] * (len(sequen... | trial_gpt4o_2 | {
"original_instruction": "You are given a sequence C, where each element is an integer.\n\nFor such a sequence S, define g(S) as follows:\n\n * Iteratively compute the prefix-sum array P of S, where P[i] = S[0] + S[1] + ... + S[i].\n * Find the maximum sum of any contiguous subsequence of P.\n * g(S) is defined a... | 0.683449 | Taco_27324 | C | [
"max_subarray_sum",
"prefix_sum",
"compute_g",
"solve"
] | 4 | [
[
"compute_g",
"max_subarray_sum"
],
[
"compute_g",
"prefix_sum"
],
[
"solve",
"compute_g"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 3d88436eacc47290fbe2ffe572977b17eddcfb58 | 0d699bf6627867dc024ddf7912a8daae3cfee58b | |||
v1.0 | complete | Taco | Taco_27406_C | from typing import List
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
>>> is_prime(29) True
>>> is_prime(1) False
>>> is_prime(-5) False
"""
def sum_of... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes(numbers):
"""
Function to return the sum of prime numbers i... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(-5) == False
def test_sum_of_primes():
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to return the sum of prime numbers in the list.",
"function_declaration": "def sum_of_primes(n... | [
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 Checks if the number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, find the sum of the prime numbers present in the list. \n\nInput Format\n\nThe first line contains $n$, the number of integers in the list. The second line contains an array $\\mbox{A}[$ $\\mathrm{~l~}$ of $n$ integers each separated by a space.\n\nConstraints\n\n$... | 0.792161 | Taco_27406 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 223a360b4ee66da4bf2b3277ec3d4f0c276ae0b1 | cb1973664dc106a86e6ed68684ff3534b245830d | |||
v1.0 | complete | Taco | Taco_27410_C | def sum_of_primes(n: int) -> int:
"""
Returns the sum of all prime numbers less than or equal to n.
"""
pass # Your implementation here
def solve_prime_sums(rounds: int, numbers: List[int]) -> List[int]:
"""
Solves the game by calculating the sum of all prime numbers for each provided number.
... | def sum_of_primes(n):
"""
Returns the sum of all prime numbers less than or equal to n.
"""
if n < 2:
return 0
# Initialize a list to track prime numbers
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers
for i in range(2, int(n**0.5)... | from solution import sum_of_primes, solve_prime_sums
def test_sum_of_primes():
assert sum_of_primes(10) == 17
assert sum_of_primes(20) == 77
assert sum_of_primes(30) == 129
assert sum_of_primes(2) == 2
assert sum_of_primes(1) == 0
assert sum_of_primes(0) == 0
assert sum_of_primes(100) == 10... | [
{
"docstring": "Returns the sum of all prime numbers less than or equal to n.",
"function_declaration": "def sum_of_primes(n):",
"function_name": "sum_of_primes",
"parameter_list": "(n)"
},
{
"docstring": "Solves the game by calculating the sum of all prime numbers for each provided number.\... | [
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(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ... | trial_gpt4o_1 | {
"original_instruction": "Anna is playing a game with her younger brother where she needs to solve some problems on prime numbers to win. The game consists of different rounds, and in each round, her brother gives her a number, and she needs to determine the sum of all prime numbers less than or equal to that number... | 0.607859 | Taco_27410 | C | [
"sum_of_primes",
"solve_prime_sums"
] | 2 | [
[
"solve_prime_sums",
"sum_of_primes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 222382e732d115d367b11a4dfef4912ec89ff63d | 5c8a50c636aef16caac7761a01d7edf66622f7dd | |||
v1.0 | complete | Taco | Taco_27762_C | def solve_problem(input_str: str) -> int:
""" Given the positions of the communication towers and the distance limit D, determine the minimum number of communication links required to ensure that every tower can indirectly communicate with every other tower. If it's not possible to connect all the towers under the ... | import math
from heapq import heappop, heappush
def euclidean_distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def min_communication_links(N, D, coordinates):
edges = []
for i in range(N):
x1, y1 = coordinates[i]
for j in range(i + 1, N):
x2, y2 ... | from solution import solve_problem
def test_case_1():
input_data = "4 5\n0 0\n0 4\n4 0\n4 4\n"
assert solve_problem(input_data) == 3
def test_case_2():
input_data = "3 100\n0 0\n70 70\n140 140\n"
assert solve_problem(input_data) == 2
def test_case_3():
input_data = "3 3\n0 0\n10 0\n20 0\n"
as... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(x1, y1, x2, y2):",
"function_name": "euclidean_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def min_communication_links(N, D, coordinates):",
"function_name": "min... | [
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 math\nfrom heapq import heappop, heappush\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef min_comm_... | trial_gpt4o_9 | {
"original_instruction": "Problem\n\nIn a city, a new communication system has been implemented, where information is relayed through a series of communication towers. Each tower can only communicate with another tower that satisfies a specific distance condition.\n\nThe city has a total of `N` communication towers,... | 0.568018 | Taco_27762 | C | [
"euclidean_distance",
"min_communication_links",
"solve_problem"
] | 3 | [
[
"min_communication_links",
"euclidean_distance"
],
[
"solve_problem",
"min_communication_links"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 99b47bbbb7a3720a489ecab048d4e1bd54aeb20d | 2404146ceb4983516e59f63fc9ed6cbe6cf8eaf7 | |||
v1.0 | complete | Taco | Taco_27452_C | def count_unique_postal_codes(datasets):
"""
Given a list of datasets where each dataset contains a list of postal codes,
return a list of integers representing the count of unique postal codes in each dataset.
"""
pass
def process_input(input_string):
"""
Converts the input string conta... | def count_unique_postal_codes(datasets):
results = []
for dataset in datasets:
unique_codes = set(dataset)
results.append(len(unique_codes))
return results
def process_input(input_string):
lines = input_string.strip().split('\n')
datasets = []
i = 0
while i < len(lines) and ... | from solution import solve, process_input, count_unique_postal_codes
def test_process_input():
input_data = """5
12345
23456
12345
34567
12300
3
00100
00101
00100
#"""
expected_output = [['12345', '23456', '12345', '34567', '12300'], ['00100', '00101', '00100']]
assert process_input(input_data) == expected... | [
{
"docstring": null,
"function_declaration": "def count_unique_postal_codes(datasets):",
"function_name": "count_unique_postal_codes",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_string):",
"function_name": "process_input",
... | [
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 count_unique_postal_codes(input_lines):\n \"\"\"\n Returns a list of integers where each integer represents the number of unique postal codes \n in ea... | trial_gpt4o_4 | {
"original_instruction": "In Japan, a custom called \"Nengajo\" exists, where people send greeting cards for the new year. The Japanese post office delivers these cards precisely on New Year's Day. However, they sort the collected cards in advance, based on a unique 5-digit postal code written on each of them. The p... | 0.570672 | Taco_27452 | C | [
"count_unique_postal_codes",
"process_input",
"solve"
] | 3 | [
[
"solve",
"count_unique_postal_codes"
],
[
"solve",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d8663db01be1fd2a5c0d9e5a91f036fd710a5cd3 | 2ca469a6749dcbff587353113fb61311516b49da | |||
v1.0 | complete | Taco | Taco_27193_C | def process_queries(grid: List[List[int]], queries: List[Tuple[int, int, int, int]]) -> List[int]:
""" Process a list of queries to calculate the sum of values in specified sub-grids.
Args:
grid (List[List[int]]): A 2D list of integers representing the grid.
queries (List[Tuple[int, int, int, int]]... | def prefix_sum(grid):
N = len(grid)
M = len(grid[0])
prefix = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N+1):
for j in range(1, M+1):
prefix[i][j] = grid[i-1][j-1] + prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1]
return prefix
def sum_subgrid(... | from solution import process_queries
def test_example_case():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [
(1, 1, 2, 2),
(2, 2, 3, 3)
]
expected = [12, 28]
assert process_queries(grid, queries) == expected
def test_single_element_grid():
gr... | [
{
"docstring": null,
"function_declaration": "def prefix_sum(grid):",
"function_name": "prefix_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def sum_subgrid(prefix, r1, c1, r2, c2):",
"function_name": "sum_subgrid",
"parameter_list": "(prefix, ... | [
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 calculate_sum(grid, queries):\n \"\"\"\n Returns a list of sums for each query sub-grid from the input grid.\n \n Parameters:\n grid (list of li... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size N x M, filled with integer values. You need to answer Q queries for the grid. Each query requires you to calculate the sum of all values in a sub-grid.\n\nINPUT\n\nThe first line of input will contain two integers, N and M, the number of rows and columns in the ... | 0.580561 | Taco_27193 | C | [
"prefix_sum",
"sum_subgrid",
"process_queries"
] | 3 | [
[
"process_queries",
"prefix_sum"
],
[
"process_queries",
"sum_subgrid"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 86571ec3118da9a4ee654b04db1cf62ee7ae4d8c | 1aac4a167691831f42e06f38d89c22f8ce630d73 | |||
v1.0 | complete | Taco | Taco_27834_C | from typing import List
def filter_primes(nums: List[int]) -> List[int]:
""" Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list.
Prime numbers are integers greater than 1 that are only divisible by 1 and themselves.
>>> filte... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_div = int(n**0.5) + 1
for d in range(3, max_div, 2):
if n % d == 0:
return False
return True
def filter_pr... | from solution import filter_primes
def test_filter_primes_are_correct():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_all_large_primes():
assert filter_primes([31, 33, 37, 39, 41, 43, 47]) == [31, 37, 41, 43, 47]
def test_filter_primes_includes_negatives_and_zero(... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the list and returns only the prime numbers.",
"function_declaration": "def filter_primes(nums):",
"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 filter_primes(nums):\n \"\"\"\n Filters the prime numbers from the input list of integers.\n\n Parameters:\n nums (list): List of integers.\n\n ... | trial_gpt4o_2 | {
"original_instruction": "Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Prime numbers are integers greater than 1 that are only divisible by 1 and themselves.\n\nYour function should adhere to the following rules:\n- The input list ca... | 0.689096 | Taco_27834 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fddb7da65fff5066ad00fcb29463460e7bb976c8 | d4233551bfee9ffafc1d34f45c03f897144dccde | |||
v1.0 | complete | Taco | Taco_28061_C | def min_energy_from_input(raw_input: str) -> int:
""" Computes the minimum energy required for a car to navigate from the top-left corner to the bottom-right corner of the grid.
>>> min_energy_from_input("3\n1 2 3\n4 5 6\n7 8 9")
8
>>> min_energy_from_input("4\n1 3 5 7\n2 4 6 8\n3 5 7 9\n4 6 8 10")
... | import heapq
def min_energy(grid):
N = len(grid)
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
pq = [(0, 0, 0)] # (cost, x, y)
costs = {(0, 0): 0}
while pq:
cost, x, y = heapq.heappop(pq)
if (x, y) == (N-1, N-1):
return cost
for dx, dy i... | from solution import min_energy_from_input
def test_case_1():
raw_input = "3\n1 2 3\n4 5 6\n7 8 9"
assert min_energy_from_input(raw_input) == 8
def test_case_2():
raw_input = "4\n1 3 5 7\n2 4 6 8\n3 5 7 9\n4 6 8 10"
assert min_energy_from_input(raw_input) == 9
def test_case_3():
raw_input = "2\n0... | [
{
"docstring": null,
"function_declaration": "def min_energy(grid):",
"function_name": "min_energy",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(raw_input):",
"function_name": "parse_input",
"parameter_list": "(raw_input)"
},
{
... | [
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": "import heapq\n\ndef min_energy_required(grid):\n N = len(grid)\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def valid(x, y):\n return ... | trial_gpt4o_4 | {
"original_instruction": "The Society of Self-Driving Cars (SSDC) has been testing its fleet in the simulated city of Autoville, which comprises a grid of $N \\times N$ intersections. The goal of the tests is to navigate from the top-left corner of the grid to the bottom-right corner using the minimum amount of ener... | 0.590691 | Taco_28061 | C | [
"min_energy",
"parse_input",
"min_energy_from_input"
] | 3 | [
[
"min_energy_from_input",
"min_energy"
],
[
"min_energy_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | beffc3f083d6265fe04150374c7d1da5d8a7f968 | 1828a543205a39916c831e8ca1321832d4e77fe6 | |||
v1.0 | complete | Taco | Taco_28072_C | def sum_of_digits(number: int) -> int:
""" Returns the sum of the digits of a given number.
>>> sum_of_digits(123)
6
>>> sum_of_digits(456)
15
>>> sum_of_digits(789)
24
>>> sum_of_digits(0)
0
>>> sum_of_digits(100000)
1
"""
pass # Your implementation here
def sum_of... | def sum_of_digits(number):
"""
Returns the sum of the digits of a given number.
"""
return sum(int(digit) for digit in str(number))
def sum_of_digits_in_list(numbers):
"""
Given a list of numbers, returns a list containing the sum of digits of each number.
"""
return [sum_of_digits(numb... | from solution import sum_of_digits, sum_of_digits_in_list
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
assert sum_of_digits(0) == 0
assert sum_of_digits(100000) == 1
def test_sum_of_digits_in_list():
assert sum_of_digi... | [
{
"docstring": "Returns the sum of the digits of a given number.",
"function_declaration": "def sum_of_digits(number):",
"function_name": "sum_of_digits",
"parameter_list": "(number)"
},
{
"docstring": "Given a list of numbers, returns a list containing the sum of digits of each number.",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sum_of_digits_of_list(nums):\n \"\"\"\n Returns a list of the sum of digits of each number in the input list.\n \"\"\"\n r... | trial_gpt4o_2 | {
"original_instruction": "Alice loves playing with numbers. She often finds the sum of digits of a number amusing. However, sometimes she gets confused when there are multiple numbers. Can you help Alice by writing a program that calculates the sum of digits of each number in a list?\n\nInput:\nThe first line contai... | 0.765447 | Taco_28072 | C | [
"sum_of_digits",
"sum_of_digits_in_list"
] | 2 | [
[
"sum_of_digits_in_list",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3796a5c864d0a991cfcab9a6acfa60d0eba0eb93 | dd378ac07db117ba3476ed918fd7ecf119180a49 | |||
v1.0 | complete | Taco | Taco_27524_C | from typing import List, Tuple
def sum_of_degrees_in_mst(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Given an undirected graph with N nodes and M edges, find the minimum spanning tree (MST) of the graph, and then calculate the sum of the degrees of all nodes in the MST.
Args:
N: An... | 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[rootX] = rootY
elif rank[rootX] > rank[rootY]:
... | def test_sum_of_degrees_in_mst_case_1():
N = 4
M = 5
edges = [
(1, 2, 1),
(1, 3, 2),
(1, 4, 3),
(2, 3, 4),
(3, 4, 5)
]
result = sum_of_degrees_in_mst(N, M, edges)
assert result == 6
def test_sum_of_degrees_in_mst_case_2():
N = 3
M = 3
edges = ... | [
{
"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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_1 | {
"original_instruction": "You are given an undirected graph with N nodes and M edges. Each of the edges has a positive weight. You need to find the minimum spanning tree (MST) of the graph, and then you have to calculate the sum of the degrees of all nodes in the MST.\n\nInput\nThe first line contains two space-sepa... | 0.63344 | Taco_27524 | C | [
"find",
"union",
"kruskals_mst",
"sum_of_degrees_in_mst"
] | 4 | [
[
"kruskals_mst",
"find"
],
[
"kruskals_mst",
"union"
],
[
"sum_of_degrees_in_mst",
"kruskals_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 787e2267acfc2b1ec24c18c39c7585667ab3bee1 | 088fceafa30b6f7f58d2f9e1a0fb685106b8d70b | |||
v1.0 | complete | Taco | Taco_28023_C | def golden_tree_fruits(D: int, days: List[int]) -> List[int]:
""" Compute the number of golden fruits for each day in `days`.
The number of golden fruits follows the Fibonacci sequence and results are modulo 10^9+7.
>>> golden_tree_fruits(2, [5, 13]) == [5, 233]
>>> golden_tree_fruits(3, [3, 7, 10]) == ... | MOD = 10**9 + 7
def fib(n, memo={1: 1, 2: 1}):
"""
Compute the nth Fibonacci number modulo 10**9 + 7 using memoization.
"""
if n in memo:
return memo[n]
memo[n] = (fib(n - 1, memo) + fib(n - 2, memo)) % MOD
return memo[n]
def golden_tree_fruits(D, days):
"""
For each day i... | from solution import golden_tree_fruits
def test_single_day():
assert golden_tree_fruits(1, [1]) == [1]
assert golden_tree_fruits(1, [2]) == [1]
def test_multiple_days():
assert golden_tree_fruits(2, [5, 13]) == [5, 233]
assert golden_tree_fruits(3, [3, 7, 10]) == [2, 13, 55]
def test_large_day_v... | [
{
"docstring": "Compute the nth Fibonacci number modulo 10**9 + 7 using memoization.",
"function_declaration": "def fib(n, memo={1: 1, 2: 1}):",
"function_name": "fib",
"parameter_list": "(n, memo={1: 1, 2: 1})"
},
{
"docstring": "For each day in `days`, return the number of golden fruits th... | [
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": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B):\n return [[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD,\n (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % MOD]... | trial_gpt4o_1 | {
"original_instruction": "A wandering traveler decided to take a journey through a vast and enchanted forest. Along the way, he happened to find a magical map that led him to a golden tree. This tree was extraordinary as it could bear fruits of pure gold! Interestingly, the tree bore golden fruits in a special patte... | 0.614999 | Taco_28023 | C | [
"fib",
"golden_tree_fruits"
] | 2 | [
[
"golden_tree_fruits",
"fib"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4eb5bcb5ff9521907b9a94909079bbdfcb37e181 | 67357a9d02bf40c50ab182a9ac722a5dc0490857 | |||
v1.0 | complete | Taco | Taco_28349_C | def longest_increasing_subsequence(pages: List[int]) -> int:
""" Finds the length of the longest increasing subsequence in the list of page numbers.
>>> longest_increasing_subsequence([100, 101, 102, 3, 4, 50, 200])
4
>>> longest_increasing_subsequence([10, 20, 10, 30, 40])
4
>>> longest_increas... | from bisect import bisect_left
def longest_increasing_subsequence(pages):
"""
Finds the length of the longest increasing subsequence in the list of page numbers.
"""
if not pages:
return 0
lis = []
for page in pages:
pos = bisect_left(lis, page)
if pos < len(lis):
... | def test_longest_increasing_subsequence():
test_cases = [
(7, [100, 101, 102, 3, 4, 50, 200], 4),
(5, [10, 20, 10, 30, 40], 4),
(8, [5, 1, 6, 2, 7, 3, 8, 4], 4),
(5, [1, 2, 3, 4, 5], 5),
(5, [5, 4, 3, 2, 1], 1),
(0, [], 0),
(1, [42], 1),
]
for n, p, e... | [
{
"docstring": "Finds the length of the longest increasing subsequence in the list of page numbers.",
"function_declaration": "def longest_increasing_subsequence(pages):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(pages)"
},
{
"docstring": null,
"function_dec... | [
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 bisect import bisect_left\n\ndef longest_increasing_subsequence(pages):\n \"\"\"\n Finds the length of the longest increasing subsequence in the list of... | trial_gpt4o_0 | {
"original_instruction": "A: 02 Longest Page Sequence\n\nproblem\n\nYou are given an integer array P, where P[i] represents the page number of a book in which a particular event happens on the i-th day. Your task is to find the length of the longest subsequence of pages where every page in the subsequence is greater... | 0.639767 | Taco_28349 | C | [
"longest_increasing_subsequence",
"solve_longest_page_sequence"
] | 2 | [
[
"solve_longest_page_sequence",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5dc8a458aae968694248b28ab5de01e5ff27fadb | 4b96dc785ce22c0c77b1bb6a1c945f6b3189ee13 | |||
v1.0 | complete | Taco | Taco_28284_C | def merge(arr, left, mid, right):
"""Merge function that merges two halves of an array.
>>> merge([4, 1, 5, 3, 2], 0, 2, 4)
[1, 2, 3, 4, 5]
"""
pass
def merge_sort(arr, left, right):
"""Sort function that applies merge sort on the array.
>>> merge_sort([4, 1, 5, 3, 2], 0, 4)
[1, 2, 3, 4... | def merge(arr, left, mid, right):
# Create temporary arrays to hold left and right subarrays
left_sub = arr[left:mid+1]
right_sub = arr[mid+1:right+1]
# Initial indexes for left, right and merged subarrays
i = 0
j = 0
k = left
# Merging the subarrays back to arr
while i < l... | from solution import merge_sort, merge, sort_and_trace
def test_simple_case():
arr = [4, 1, 5, 3, 2]
sort_and_trace(arr)
def test_reverse_sorted():
arr = [8, 7, 6, 5]
sort_and_trace(arr)
def test_already_sorted():
arr = [1, 2, 3, 4, 5]
sort_and_trace(arr)
def test_all_elements_same():
ar... | [
{
"docstring": null,
"function_declaration": "def merge(arr, left, mid, right):",
"function_name": "merge",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort(arr, left, right):",
"function_name": "merge_sort",
"parameter_l... | [
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 merge_sort(arr):\n \"\"\"\n Perform merge sort on the array and prints the state of the array after each merge operation.\n \"\"\"\n if len(arr) <=... | trial_gpt4o_8 | {
"original_instruction": "Write a program that implements the Merge Sort algorithm to sort an array of integers in ascending order. The algorithm must follow this high-level pseudo code structure:\n\n1. If the array has one element or is empty, it is already sorted.\n2. Divide the array into two halves.\n3. Recursiv... | 0.635574 | Taco_28284 | C | [
"merge",
"merge_sort",
"sort_and_trace",
"main"
] | 4 | [
[
"merge_sort",
"merge"
],
[
"sort_and_trace",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9360df8c73034346c886fdbc9cf9c193636f4611 | c2e11e36f1e528734d38d98891bd3a5184e5e35c | |||
v1.0 | complete | Taco | Taco_28079_C | def is_magic_string(input_string):
"""Determine if a string can be transformed into a magic string.
A magic string meets the following criteria:
1. All alphabetic characters are in uppercase.
2. All special characters remain as they are.
3. The string contains no numeric characters.
4. The ... | def is_magic_string(input_string):
# Filter out numeric characters and uppercase the alphabetic ones
transformed_string = ''.join([ch.upper() if ch.isalpha() else ch for ch in input_string if not ch.isdigit()])
# Check if the transformed string is a palindrome
if transformed_string == transformed_strin... | from solution import is_magic_string, magic_strings
def test_is_magic_string():
assert is_magic_string("he!l@lo") == "Not Magic"
assert is_magic_string("@123#") == "Not Magic"
assert is_magic_string("Rac#car") == "Magic"
assert is_magic_string("A1!a") == "Magic"
assert is_magic_string("!a!b!a!") ==... | [
{
"docstring": null,
"function_declaration": "def is_magic_string(input_string):",
"function_name": "is_magic_string",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declaration": "def magic_strings(n, strings):",
"function_name": "magic_strings",
"parameter... | [
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_magic_string(s):\n \"\"\"Determines if a string can be transformed into a magic string.\"\"\"\n # Remove numeric characters\n transformed = ''.join... | trial_gpt4o_2 | {
"original_instruction": "A group of friends play a game called \"Magic Strings.\" In this game, each player receives a string containing both alphabetic characters and special characters (such as '!', '@', '#', etc.). The goal is to transform the string into a \"magic string\" following these rules:\n\n1. All alpha... | 0.640979 | Taco_28079 | C | [
"is_magic_string",
"magic_strings"
] | 2 | [
[
"magic_strings",
"is_magic_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be067b43aa8999fea1cbda611280456c9e0610a2 | 47f168fd9c508e77272f519e3f08a1941ed5023f | |||
v1.0 | complete | Taco | Taco_28107_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
node_list = [None] * len(nodes)
for i, (v, l, r) in enumerate(nodes):
if node_list[i] is None:
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
node_list = [None] * len(nodes)
for i, (v, l, r) in enumerate(nodes):
if node_list[i] is None:
... | from solution import orbital_link_checksum
def test_example_case():
nodes = [
(10, 1, 2),
(5, -1, -1),
(12, 3, 4),
(6, -1, -1),
(7, -1, -1)
]
assert orbital_link_checksum(5, nodes) == 29
def test_single_node():
nodes = [
(10, -1, -1),
]
assert or... | [] | [
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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_t... | trial_gpt4o_0 | {
"original_instruction": "In a distant future, a new form of interplanetary communication called \"Orbital Link\" has been established. An Orbital Link is represented by a binary tree, with each node containing an integer value. To ensure message integrity, a mechanism called \"Link Checksum\" is used. The Checksum ... | 0.594189 | Taco_28107 | C | [
"build_tree",
"max_root_to_leaf_sum",
"orbital_link_checksum"
] | 3 | [
[
"orbital_link_checksum",
"build_tree"
],
[
"orbital_link_checksum",
"max_root_to_leaf_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1844804d507743e448a0aa717e3de75c21c4b129 | 7927bdaa5a4081365394a37d12aabc997056b356 | |||
v1.0 | complete | Taco | Taco_28100_C | def is_eligible_for_bonus(N, R, S):
"""
Determines if an employee is eligible for a bonus based on years of service N,
required ratings R, and service years S.
:param N: Minimum years of service required
:param R: Minimum performance rating required
:param S: Actual years of service of the... | def is_eligible_for_bonus(N, R, S):
"""
Determines if an employee is eligible for a bonus based on years of service N,
required ratings R, and service years S.
:param N: Minimum years of service required
:param R: Minimum performance rating required
:param S: Actual years of service of the... | def test_is_eligible_for_bonus():
assert is_eligible_for_bonus(5, 7, 10) == "YES"
assert is_eligible_for_bonus(3, 5, 5) == "YES"
assert is_eligible_for_bonus(10, 8, 12) == "YES"
assert is_eligible_for_bonus(6, 6, 4) == "NO"
assert is_eligible_for_bonus(10, 5, 9) == "NO"
assert is_eligible_for_bo... | [
{
"docstring": "Determines if an employee is eligible for a bonus based on years of service N, \nrequired ratings R, and service years S.\n\n:param N: Minimum years of service required\n:param R: Minimum performance rating required\n:param S: Actual years of service of the employee\n:return: \"YES\" if the empl... | [
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_eligible_for_bonus(N, R, S):\n \"\"\"\n Determines if an employee is eligible for a bonus based on years of service N, \n required ratings R, and s... | trial_gpt4o_0 | {
"original_instruction": "A company wants to give a bonus to its employees based on their years of service and performance rating. The criteria for receiving the bonus are as follows:\n\n- An employee must have at least N years of service.\n- The performance rating must be greater than or equal to R.\n\nGiven the nu... | 0.599361 | Taco_28100 | C | [
"is_eligible_for_bonus",
"determine_bonus_eligibility",
"parse_input"
] | 3 | [
[
"determine_bonus_eligibility",
"is_eligible_for_bonus"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 9361ae6482de97444f5fdeceee1cfdce59dc3d5b | 28551d1d523ef4b9482c4436cdfc4aa9681d1cbb | |||
v1.0 | complete | Taco | Taco_28108_C | class TreeNode:
"""
Definition for a binary tree node.
"""
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def buildTree(nodes):
"""
Helper function to build a tree from the level order traversal list.
"""
def maxDepth(root):
"""
Funct... | class TreeNode:
"""
Definition for a binary tree node.
"""
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def buildTree(nodes):
"""
Helper function to build a tree from the level order traversal list.
"""
if not nodes or nodes[0] == "N":
... | from solution import solve_max_depth
def test_case_1():
test_cases = ["3 9 20 N N 15 7"]
results = solve_max_depth(test_cases)
assert results == [3], f"Expected [3], but got {results}"
def test_case_2():
test_cases = ["1 2 3 N 4 N 5 N N 6 7"]
results = solve_max_depth(test_cases)
assert result... | [] | [
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 TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef buildTree(nodes):\n \"\"\"\n Th... | trial_gpt4o_1 | {
"original_instruction": "You are given the root of a binary tree. You need to determine the maximum depth of the binary tree. The depth of a binary tree is the length of the longest path from the root node to a leaf. This path may or may not pass through the root.\n\nInput:\nFirst line of input contains the number ... | 0.527736 | Taco_28108 | C | [
"buildTree",
"maxDepth",
"solve_max_depth"
] | 3 | [
[
"solve_max_depth",
"buildTree"
],
[
"solve_max_depth",
"maxDepth"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | bfd5c59a8377e5f507d9f906df13adae1afc593e | 81f560df3b1c512411a6d44bb069f1e2f6074ec9 | |||
v1.0 | complete | Taco | Taco_28432_C | def gcd(a, b):
while b:
a, b = b, a % b
return a
def max_total_energy(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""Determine the maximum possible total energy level for the society's stones after a series of optimal energy transfers.
Args:
T : int : Number of test case... | def gcd(a, b):
while b:
a, b = b, a % b
return a
def max_total_energy(T, test_cases):
results = []
for i in range(T):
N, energies = test_cases[i]
total_energy = sum(energies)
max_energy = total_energy
# Check all pairs for possible optimal energy transfer
... | from solution import max_total_energy
def test_case_1():
assert max_total_energy(2, [(3, [6, 9, 12]), (2, [10, 15])]) == [27, 25]
def test_single_stone():
assert max_total_energy(1, [(1, [7])]) == [7]
def test_two_stones_no_transfer_possible():
assert max_total_energy(1, [(2, [7, 11])]) == [18]
def test... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def max_total_energy(T, test_cases):",
"function_name": "max_total_energy",
"parameter_list": "(T, test_cases)"
}
] | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import Counter\n\ndef maximum_total_energy(test_cases):\n results = []\n\n for energies in test_cases:\n if len(energies... | trial_gpt4o_4 | {
"original_instruction": "A secluded island is governed by a peculiar society that believes in balancing energy to maintain peace. Each member of the society possesses a stone, the energy level of which is represented by a positive integer. The society has decided to balance these stones by transferring energy betwe... | 0.621454 | Taco_28432 | C | [
"gcd",
"max_total_energy"
] | 2 | [
[
"max_total_energy",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f6250d2ffe87f12be61fb332395a6d8c481d85bd | c6749834528117999ca83ffcc3698fea67de3a04 | |||
v1.0 | complete | Taco | Taco_28317_C | def max_continuous_data_files(grid: List[List[int]]) -> int:
""" Determine the maximum number of data files the robot can transfer in one continuous move within the grid.
The robot starts from a cell with a data file and can only move horizontally or vertically to adjacent cells that also contain data file... | def max_continuous_data_files(grid):
def dfs(i, j):
if i < 0 or j < 0 or i >= n or j >= m or grid[i][j] == 0:
return 0
grid[i][j] = 0
return 1 + dfs(i+1, j) + dfs(i-1, j) + dfs(i, j+1) + dfs(i, j-1)
n = len(grid)
m = len(grid[0])
max_files = 0
for i in r... | # Test cases for max_continuous_data_files function
def test_single_cell_grid():
assert max_continuous_data_files([[0]]) == 0
assert max_continuous_data_files([[1]]) == 1
def test_no_data_files():
assert max_continuous_data_files([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
]) == 0
def ... | [
{
"docstring": null,
"function_declaration": "def max_continuous_data_files(grid):",
"function_name": "max_continuous_data_files",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def max_continuous_data_files_input():",
"function_name": "max_continuous_dat... | [
0,
0,
0,
0,
0,
1,
0,
0,
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_data_files_transfer(n, m, grid):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] != 1:\n return 0\n grid... | trial_gpt4o_5 | {
"original_instruction": "A delivery robot moves data files between rows of servers arranged in a grid. Each server in the grid is represented as a cell that can either be occupied by data files (`1`) or be empty (`0`). The robot can only move horizontally or vertically to an adjacent cell, but not diagonally. \n\nY... | 0.57168 | Taco_28317 | C | [
"max_continuous_data_files",
"max_continuous_data_files_input"
] | 2 | [
[
"max_continuous_data_files_input",
"max_continuous_data_files"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6b7c2cf5df771f994fb9119b7d4ef5145a8fc49f | 6f2d9948eb30a46c61301b96280a3861546166a6 | |||
v1.0 | complete | Taco | Taco_28595_C | def find_min_max_pages(pages, n, m):
"""
Determine the maximum number of pages a student has to read in an optimal allocation.
Parameters:
pages (List[int]): A list of integers representing the number of pages in each book.
n (int): The number of books.
m (int): The number of students.
... | def is_feasible(pages, n, m, curr_min):
students_required = 1
curr_sum = 0
for i in range(n):
if (pages[i] > curr_min):
return False
if (curr_sum + pages[i] > curr_min):
students_required += 1
curr_sum = pages[i]
if s... | def test_find_min_max_pages():
assert find_min_max_pages([12, 34, 67, 90], 4, 2) == 113
assert find_min_max_pages([10, 20, 30, 40, 50], 5, 3) == 60
assert find_min_max_pages([10, 20, 30], 3, 3) == 30
assert find_min_max_pages([10, 20, 30], 3, 1) == 60
assert find_min_max_pages([5, 17, 100, 11], 4, 2... | [
{
"docstring": null,
"function_declaration": "def is_feasible(pages, n, m, curr_min):",
"function_name": "is_feasible",
"parameter_list": "(pages, n, m, curr_min)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(pages, n, m):",
"function_name": "find_min_max_p... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def allocate_books(n, m, pages):\n \"\"\"\n Allocates books to students such that the maximum number of pages any student has to read is minimized.\n \"\"... | trial_gpt4o_3 | {
"original_instruction": "You are given a list of $n$ books, each with a certain number of pages. Your task is to allocate these books to $m$ students in such a way that each student gets at least one book, and the maximum number of pages assigned to a student is minimized.\n\nDetermine the maximum number of pages a... | 0.667413 | Taco_28595 | C | [
"is_feasible",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_feasible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d256b1d87281f9a3dc458c07a039d28c8e2e43d5 | 36e24e143bab0cb21f877a83d06c1a5266f4841d | |||
v1.0 | complete | Taco | Taco_28640_C | def treasure_hunt(city_data: List[str]) -> List[int]:
""" Determine the minimum total travel distance to visit all the treasure locations and return to the origin.
Parameters:
city_data: A list of strings representing the input data for multiple datasets. The first line in each dataset
... | from itertools import permutations
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def calculate_total_distance(route, coords):
total_distance = 0
total_distance += manhattan_distance(0, 0, coords[route[0]][0], coords[route[0]][1])
for i in range(len(route) - 1):
tot... | from solution import treasure_hunt
def test_sample_input():
input_data = ["3",
"1 1",
"2 1",
"2 2",
"2",
"1 2",
"3 4",
"0"]
expected_output = [8, 14]
assert treasure_hunt(inp... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def calculate_total_distance(route, coords):",
"function_name": "calcul... | [
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 manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\ndef minimum_travel_distance(treasure_l... | trial_gpt4o_3 | {
"original_instruction": "Treasure Hunt\n\nA group of archaeologists in a hidden valley discovered coordinates on an ancient map pointing to several potential treasure locations. Each location is marked with an (x, y) coordinate on a 2D grid.\n\nTo maximize the treasure collected, the archaeologists decide that they... | 0.582885 | Taco_28640 | C | [
"manhattan_distance",
"calculate_total_distance",
"minimum_total_travel_distance",
"treasure_hunt"
] | 4 | [
[
"calculate_total_distance",
"manhattan_distance"
],
[
"minimum_total_travel_distance",
"calculate_total_distance"
],
[
"treasure_hunt",
"minimum_total_travel_distance"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ee29e99931195972610f9161c0ed47d754f1d675 | adb9e1cce32e429fb35b9c17528f42c89c477836 | |||
v1.0 | complete | Taco | Taco_27869_C | def floyd_warshall(matrix):
"""
Implements the Floyd-Warshall algorithm to find the shortest paths between all pairs of nodes.
Parameters:
matrix (list of list of int): The adjacency matrix representing the time between rooms.
Returns:
list of list of int: The matrix of the shortest paths betw... | def floyd_warshall(matrix):
"""
Implements the Floyd-Warshall algorithm to find the shortest paths between all pairs of nodes.
Parameters:
matrix (list of list of int): The adjacency matrix representing the time between rooms.
Returns:
list of list of int: The matrix of the shortest paths betw... | def test_process_input_data():
input_data = [
"3",
"0 2 1000000",
"2 0 3",
"1000000 3 0",
"0 2",
"4",
"0 3 1000000 7",
"3 0 1 8",
"1000000 1 0 1000000",
"7 8 1000000 0",
"0 3",
"-1"
]
expected_output = [5, 7]
... | [
{
"docstring": "Implements the Floyd-Warshall algorithm to find the shortest paths between all pairs of nodes.\n\nParameters:\nmatrix (list of list of int): The adjacency matrix representing the time between rooms.\n\nReturns:\nlist of list of int: The matrix of the shortest paths between all pairs of nodes.",
... | [
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_shortest_delivery_time(n, hallway_matrix, start, target):\n \"\"\"\n Uses Dijkstra's algorithm to find the shortest path in a graph with non-negativ... | trial_gpt4o_1 | {
"original_instruction": "A robotics company is designing a delivery system where autonomous robots deliver packages within a building. The building consists of a series of rooms connected by hallways. The number of rooms is represented by N, and the hallways are represented as a matrix where the element at the i-th... | 0.695651 | Taco_27869 | C | [
"floyd_warshall",
"find_shortest_delivery",
"process_input_data"
] | 3 | [
[
"find_shortest_delivery",
"floyd_warshall"
],
[
"process_input_data",
"find_shortest_delivery"
]
] | 2 | [
"process_input_data"
] | false | [] | false | pytest | false | [] | true | 155985c4a819281c52722841ce3f1d846866b04f | 60856366cc6baf9383a82f4096b626ff4e1c0400 | |||
v1.0 | complete | Taco | Taco_28802_C | from typing import List
def longest_prime_consecutive_subsequence(numbers: List[int]) -> int:
""" Find the length of the longest Prime Consecutive Subsequence in the list of numbers.
>>> longest_prime_consecutive_subsequence([1, 2, 3, 5, 4, 7, 11, 13, 4, 6])
3
>>> longest_prime_consecutive_subsequence(... | import math
def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def longest_prime_consecutive_subsequence(numbers):
max_lengt... | from solution import longest_prime_consecutive_subsequence
def test_sample_input():
numbers = [1, 2, 3, 5, 4, 7, 11, 13, 4, 6]
assert longest_prime_consecutive_subsequence(numbers) == 3
def test_all_primes():
numbers = [2, 3, 5, 7, 11, 13, 17, 19]
assert longest_prime_consecutive_subsequence(numbers) ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_consecutive_subsequence(numbers):",
"function_name": "longest_prime_consecutive_subsequence",
"... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"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 check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n... | trial_gpt4o_4 | {
"original_instruction": "Dan loves playing with numbers and is particularly fascinated by properties of prime numbers. He came up with a unique problem involving consecutive subsequences of prime numbers. A \"Prime Consecutive Subsequence\" is a consecutive subsequence in a sequence where all the numbers are prime.... | 0.636344 | Taco_28802 | C | [
"is_prime",
"longest_prime_consecutive_subsequence"
] | 2 | [
[
"longest_prime_consecutive_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48a6206720ffb72ca84a2f617418d05057188cd3 | f7602461528bb6cbbc511d66d12c1792cc2bb5d9 | |||
v1.0 | complete | Taco | Taco_28573_C | import unicodedata
import re
def normalize_country_name(country: str) -> str:
"""
Normalize a country name by removing accents, extra spaces, and punctuation. Convert to lowercase.
"""
# Normalize the string to remove accents
normalized = unicodedata.normalize('NFKD', country).encode('ASCII', 'igno... | import unicodedata
import re
def normalize_country_name(country: str) -> str:
"""
Normalize a country name by removing accents, extra spaces, and punctuation. Convert to lowercase.
"""
# Normalize the string to remove accents
normalized = unicodedata.normalize('NFKD', country).encode('ASCII', 'igno... | from solution import capital_city
def test_capital_city_france():
assert capital_city("France") == "Paris"
assert capital_city("france") == "Paris"
assert capital_city("FRANCE") == "Paris"
assert capital_city("FrAnCe") == "Paris"
assert capital_city(" France ") == "Paris"
assert capital_city("... | [
{
"docstring": "Normalize a country name by removing accents, extra spaces, and punctuation. Convert to lowercase.",
"function_declaration": "def normalize_country_name(country):",
"function_name": "normalize_country_name",
"parameter_list": "(country)"
},
{
"docstring": "Return the capital ... | [
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 unicodedata\n\ndef normalize_text(text: str) -> str:\n \"\"\"\n Normalize the text by removing accents, extra spaces, and converting to lowercase.\n ... | trial_gpt4o_1 | {
"original_instruction": "Write a function ```capital_city``` that takes a country name as an input and returns its capital city. The function should be able to handle different variations in spelling and capitalization, as well as missing or additional accents. If the function does not recognize the country name, i... | 0.569321 | Taco_28573 | C | [
"normalize_country_name",
"capital_city"
] | 2 | [
[
"capital_city",
"normalize_country_name"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3c0b669074578d6368fdba3c63d6c05e3713dd2a | 72d9c4a823ca0147c5ead8d3d929acad9ba6c4bd | |||
v1.0 | complete | Taco | Taco_28016_C | class Node:
def __init__(self, name, is_file=False):
self.name = name
self.is_file = is_file
self.children = {}
def parse_path(path):
"""Helper function to parse a Unix-like path into its components.
>>> parse_path('/a/b/c')
['a', 'b', 'c']
>>> parse_path('/')
['/']
... | class Node:
def __init__(self, name, is_file=False):
self.name = name
self.is_file = is_file
self.children = {}
def parse_path(path):
# Parses the path into components
if path == '/':
return ['/']
return path.strip('/').split('/')
def find_node(root, path_parts):
# ... | def test_simple_structure():
n = 6
operations = [
"mkdir /a",
"mkdir /a/b",
"mkdir /a/b/c",
"mkfile /a/b/c/file1",
"mkdir /a/b/d",
"move /a/b/c /a/b/d"
]
expected_output = """
/
a
b
d
c
-file1
"""
import io
import sys
... | [] | [
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 Node:\n def __init__(self, name, is_file=False):\n self.name = name\n self.is_file = is_file\n self.children = {}\n\nclass FileSystem... | trial_gpt4o_1 | {
"original_instruction": "You've just joined a new project team tasked with working on a file system that closely resembles a Unix-like directory system. The file system you are working on is represented by a tree structure where each node is either a directory or a file. Each directory can contain other directories... | 0.541376 | Taco_28016 | C | [
"parse_path",
"find_node",
"process_operations",
"print_tree",
"process_and_print"
] | 5 | [
[
"process_and_print",
"print_tree"
],
[
"process_and_print",
"process_operations"
],
[
"process_operations",
"find_node"
],
[
"process_operations",
"parse_path"
]
] | 4 | [] | false | [
"Node"
] | true | pytest | false | [] | true | 60acb0a8654de28990a7a8ff642321fc90bd3f7f | 7577c295d0e8c64ddc0f715646ebe42c23a01fd4 | |||
v1.0 | complete | Taco | Taco_28574_C | from typing import List
def minimum_max_distance(n: int, roads: List[List[int]], k: int) -> int:
""" Determine the minimum maximum distance for any castle in the network from its nearest communication tower.
>>> minimum_max_distance(5, [[1, 2], [1, 3], [3, 4], [3, 5]], 2)
1
>>> minimum_max_distance(6, ... | from collections import defaultdict, deque
def bfs_farthest_node(start, n, graph):
"""
Perform BFS to find the farthest node from the start node and the distance to it.
"""
visited = [False] * (n + 1)
queue = deque([(start, 0)])
visited[start] = True
farthest_node = start
max_dista... | from solution import solve
def test_example1():
input_data = "5\n1 2\n1 3\n3 4\n3 5\n2"
assert solve(input_data) == 1
def test_example2():
input_data = "6\n1 2\n1 3\n2 4\n2 5\n3 6\n3"
assert solve(input_data) == 1
def test_example3():
input_data = "4\n1 2\n1 3\n2 4\n1"
assert solve(input_data... | [
{
"docstring": "Perform BFS to find the farthest node from the start node and the distance to it.",
"function_declaration": "def bfs_farthest_node(start, n, graph):",
"function_name": "bfs_farthest_node",
"parameter_list": "(start, n, graph)"
},
{
"docstring": null,
"function_declaration... | [
0,
0,
0,
0,
0,
1,
0,
0,
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 collections import deque\nfrom typing import List, Tuple\n\ndef minimum_max_distance(n: int, edges: List[Tuple[int, int]], k: int) -> int:\n def bfs(src: i... | trial_gpt4o_5 | {
"original_instruction": "In Treeland, there are multiple kingdoms with various castles connected by bidirectional roads. Treeland's road system forms an undirected tree, meaning there is exactly one path between any two castles. Recently, the treelandian government has decided to establish a wireless communication ... | 0.655792 | Taco_28574 | C | [
"bfs_farthest_node",
"minimum_max_distance",
"solve"
] | 3 | [
[
"minimum_max_distance",
"bfs_farthest_node"
],
[
"solve",
"minimum_max_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1cc2b2fc22c2947051aeaa7698e4a60b08ffe990 | 4d4d6e0c265075bbd2fa9fcbf7cb38c9da61e94a | |||
v1.0 | complete | Taco | Taco_28864_C | import random
def simulate_lottery_draw():
"""Simulates the lottery draw process and returns a list of 6 unique drawn numbers."""
...
def count_matches(drawn_numbers, chosen_numbers):
"""
Counts how many numbers in chosen_numbers match the drawn_numbers.
Args:
drawn_numbers (list): The list o... | import random
def simulate_lottery_draw():
"""
Simulates the lottery draw process and returns a list of 6 unique drawn numbers.
"""
return sorted(random.sample(range(1, 50), 6))
def count_matches(drawn_numbers, chosen_numbers):
"""
Counts how many numbers in chosen_numbers match the drawn_numb... | import pytest
from unittest.mock import patch
from solution import simulate_lottery_draw, count_matches, lottery_simulation
def test_simulate_lottery_draw():
drawn_numbers = simulate_lottery_draw()
assert len(drawn_numbers) == 6
assert all(1 <= num <= 49 for num in drawn_numbers)
assert len(set(drawn_n... | [
{
"docstring": "Simulates the lottery draw process and returns a list of 6 unique drawn numbers.",
"function_declaration": "def simulate_lottery_draw():",
"function_name": "simulate_lottery_draw",
"parameter_list": "()"
},
{
"docstring": "Counts how many numbers in chosen_numbers match the d... | [
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 random\n\ndef generate_lottery_numbers():\n \"\"\"\n Generates a set of 6 unique random numbers between 1 and 49 inclusive.\n \"\"\"\n return so... | trial_gpt4o_1 | {
"original_instruction": "Create a program that simulates the lottery draw process for a 6/49 type lottery where the player must pick 6 different numbers from a set of 49 consecutive numbers (1 through 49). The draw will randomly select 6 different numbers. The program will then compare the player's chosen numbers w... | 0.610995 | Taco_28864 | C | [
"simulate_lottery_draw",
"count_matches",
"lottery_simulation"
] | 3 | [
[
"lottery_simulation",
"count_matches"
],
[
"lottery_simulation",
"simulate_lottery_draw"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d009baf2eb1c3eb0de8ffab31a1cfd80f5ecc39e | fc867ae26827b308f1d9fac790e0aed86def9fa4 | |||
v1.0 | complete | Taco | Taco_28962_C | def validate_email(email: str) -> bool:
""" Validates the email address according to specified rules:
- Username contains only letters (a-z, A-Z), digits (0-9), dashes (-), underscores (_), and dots (.).
- Domain contains only letters (a-z, A-Z) and digits (0-9).
- Extension contains only letters (a-z) ... | import re
def validate_email(email):
"""
Validates the email address according to specified rules.
- Username contains only letters, digits, dashes, underscores, and dots.
- Domain contains only letters and digits.
- Extension contains only letters and is 2 to 3 characters long.
"""
pattern... | from solution import validate_email, get_valid_emails
def test_validate_email():
assert validate_email('username@domain.com') == True
assert validate_email('user-name@domain.net') == True
assert validate_email('user_name@domain.org') == True
assert validate_email('user.name@domain.co.in') == False # in... | [
{
"docstring": "Validates the email address according to specified rules.\n- Username contains only letters, digits, dashes, underscores, and dots.\n- Domain contains only letters and digits.\n- Extension contains only letters and is 2 to 3 characters long.",
"function_declaration": "def validate_email(emai... | [
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 re\n\ndef validate_email(email):\n \"\"\"\n Validates the email address according to specified rules.\n - Username contains only letters, digits, d... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of email addresses. Each email address in the list follows the format `username@domain.extension`. Your task is to filter out the invalid email addresses and print the valid ones in alphabetical order.\n\nAn email address is considered valid if:\n1. The username contain... | 0.601926 | Taco_28962 | C | [
"validate_email",
"get_valid_emails"
] | 2 | [
[
"get_valid_emails",
"validate_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f1325855df5f631c0bcc0589fadc07da25a19fca | 6421e8d86e10570d5173f052e1cd24524bc4e1bd | |||
v1.0 | complete | Taco | Taco_28681_C | def modinv(a, p):
"""
Returns the modular inverse of a under modulo p using Fermat's little theorem.
"""
return pow(a, p - 2, p)
def nCr_mod_p(n, r, p):
"""
Returns C(n, r) % p using Fermat's little theorem for the modulus.
"""
if r > n:
return 0
if r == 0 or n == r:
... | def modinv(a, p):
"""
Returns the modular inverse of a under modulo p using Fermat's little theorem.
"""
return pow(a, p - 2, p)
def nCr_mod_p(n, r, p):
"""
Returns C(n, r) % p using Fermat's little theorem for the modulus.
"""
if r > n:
return 0
if r == 0 or n == r:
... | def test_unique_combinations():
assert unique_combinations(5, 3) == 10
assert unique_combinations(6, 2) == 15
assert unique_combinations(10, 5) == 252
assert unique_combinations(1, 1) == 1
assert unique_combinations(1000, 2) == 499500
assert unique_combinations(1000000, 1) == 1000000
assert ... | [
{
"docstring": "Returns the modular inverse of a under modulo p using Fermat's little theorem.",
"function_declaration": "def modinv(a, p):",
"function_name": "modinv",
"parameter_list": "(a, p)"
},
{
"docstring": "Returns C(n, r) % p using Fermat's little theorem for the modulus.",
"fun... | [
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": "MOD = 10**9 + 7\n\ndef mod_inv(a, p):\n \"\"\"\n Compute the modular multiplicative inverse of a under modulo p\n using Fermat's ... | trial_gpt4o_2 | {
"original_instruction": "Eve is a skilled botanist who loves exploring the fascinating world of plants. She recently came across an intriguing problem involving the beautiful gardens she studies. She decided to ask you for help in solving it. Can you help Eve with her problem?\n\nYou are given an integer $N$ repres... | 0.58778 | Taco_28681 | C | [
"modinv",
"nCr_mod_p",
"unique_combinations"
] | 3 | [
[
"nCr_mod_p",
"modinv"
],
[
"unique_combinations",
"nCr_mod_p"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d7ac1f5d5384dcad3f6831cc830da2219522148c | 4012fa5f7c8041db25448aa019bc1225cc308ae6 | |||
v1.0 | complete | Taco | Taco_28246_C | class NumberList:
def __init__(self, numbers):
self.numbers = numbers
self.prefix_sum = self._compute_prefix_sum(numbers)
def _compute_prefix_sum(self, numbers):
prefix_sum = [0] * (len(numbers) + 1)
for i in range(1, len(numbers) + 1):
prefix_sum[i] = prefix_sum[i -... | class NumberList:
def __init__(self, numbers):
self.numbers = numbers
self.prefix_sum = self._compute_prefix_sum(numbers)
def _compute_prefix_sum(self, numbers):
prefix_sum = [0] * (len(numbers) + 1)
for i in range(1, len(numbers) + 1):
prefix_sum[i] = prefix_sum[i -... | import pytest
from solution import run_solution
def test_example_1():
N = 4
Q = 3
numbers = [2, 4, 6, 8]
queries = [(1, 3), (2, 2, 5), (1, 4)]
expected = [12, 21]
assert run_solution(N, Q, numbers, queries) == expected
def test_example_2():
N = 5
Q = 4
numbers = [1, 2, 3, 4, 5]
... | [] | [
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": "class NumberList:\n def __init__(self, numbers):\n self.numbers = numbers\n self.prefix_sum = self._compute_prefix_sum(numbers)\n\n def _comput... | trial_gpt4o_0 | {
"original_instruction": "## Problem\n\nYou are given a list of N numbers {n1, n2, ..., nN} and Q queries. There are two types of queries:\n\n1. When i is input, it refers to a query of the form `accumulate(i)` which means you need to compute the accumulated sum of the first i numbers from the list, i.e., n1 + n2 + ... | 0.601885 | Taco_28246 | C | [
"process_queries",
"run_solution"
] | 2 | [
[
"run_solution",
"process_queries"
]
] | 1 | [
"process_queries"
] | false | [
"NumberList"
] | true | pytest | true | [] | true | c878a82b70e842ee0798a8f3a5f10f494f30d4ba | 3ca760de05dc0af20b7611d1d67fa7a7a8f8d439 | |||
v1.0 | complete | Taco | Taco_29044_C | def is_palindrome(number):
"""
Check if a given number is a palindrome.
"""
def can_partition_palindromic_segments(n, sequence):
"""
Given a sequence of positive integers, determine whether it can be partitioned into
contiguous palindromic segments. Each segment must be a palindromic number.
... | def is_palindrome(number):
"""
Check if a given number is a palindrome.
"""
str_number = str(number)
return str_number == str_number[::-1]
def can_partition_palindromic_segments(n, sequence):
"""
Determine if a sequence of numbers can be partitioned into contiguous palindromic segments.
... | from solution import is_palindrome, can_partition_palindromic_segments
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(11) == True
assert is_palindrome(1331) == True
assert is_palindrome(12321) == True
assert is_palindrome(1234... | [
{
"docstring": "Check if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Determine if a sequence of numbers can be partitioned into contiguous palindromic segments.",
... | [
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_palindrome(num):\n \"\"\"\n Checks if the given number (as an integer) is a palindrome.\n \"\"\"\n num_str = str(num)\n return num_str == num... | trial_gpt4o_2 | {
"original_instruction": "Jasmine loves palindromic numbers. A palindromic number reads the same forwards and backwards, such as 121, 1331, or 7. She is also fascinated by sequences of numbers that can be split into multiple palindromic segments.\n\nGiven a sequence of positive integers, determine whether it can be ... | 0.720694 | Taco_29044 | C | [
"is_palindrome",
"can_partition_palindromic_segments"
] | 2 | [
[
"can_partition_palindromic_segments",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3a2d8518abd92d885c00fd770249e2a73553fca8 | 33256ea21e01c3d7d6f579ab228ad29280f21dda | |||
v1.0 | complete | Taco | Taco_28993_C | def handle_queries(N, arr, Q, queries):
""" Process multiple sum queries on the array arr.
Args:
N: int, the size of the array.
arr: List[int], list of integers representing the elements of the array.
Q: int, the number of queries.
queries: List[Tuple[int, int]], list of tuples where each t... | def prepare_prefix_sum(arr):
"""
Prepare the prefix sum array for the given array arr.
"""
n = len(arr)
prefix_sum = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1]
return prefix_sum
def sum_query(prefix_sum, l, r):
"""
Calculate the su... | from solution import handle_queries
def test_single_query():
N = 5
arr = [1, 2, 3, 4, 5]
Q = 1
queries = [(1, 3)]
assert handle_queries(N, arr, Q, queries) == [6]
def test_multiple_queries():
N = 5
arr = [1, 2, 3, 4, 5]
Q = 3
queries = [(1, 3), (2, 5), (1, 5)]
assert handle_que... | [
{
"docstring": "Prepare the prefix sum array for the given array arr.",
"function_declaration": "def prepare_prefix_sum(arr):",
"function_name": "prepare_prefix_sum",
"parameter_list": "(arr)"
},
{
"docstring": "Calculate the sum of the subarray from index l to r (1-indexed) using the prefix... | [
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 subarray_sums(arr, queries):\n # Compute the prefix sum array\n prefix_sums = [0] * (len(arr) + 1)\n for i in range(len(arr)):\n prefix_sums[i ... | trial_gpt4o_2 | {
"original_instruction": "You are given an integer array `arr` consisting of N$N$ positive integers. Your task is to handle multiple queries that ask for the sum of numbers in a specific subarray of `arr`. Each query provides the starting and ending index of the subarray, and you need to calculate the sum of the ele... | 0.622637 | Taco_28993 | C | [
"prepare_prefix_sum",
"sum_query",
"handle_queries"
] | 3 | [
[
"handle_queries",
"prepare_prefix_sum"
],
[
"handle_queries",
"sum_query"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 6237d43b0ee5791f614a6c492eceec9bcad7a5b4 | ed8c3dfe6de0f5c474dbe28bbdf5006281b9e4b2 | |||
v1.0 | complete | Taco | Taco_29084_C | def read_and_sort_entries(n: int, entry_list: str) -> list:
""" Read a list of mixed entries (numbers and strings) and return them sorted
such that:
- All strings come before any number.
- Strings are sorted in lexicographical order.
- Numbers are sorted in non-decreasing order.
Args:
n (in... | def sort_entries(entries):
"""
This function takes a list of mixed entries (numbers and strings) and sorts them
so that:
- All strings appear before any numbers.
- Strings are sorted in lexicographical order.
- Numbers are sorted in non-decreasing order.
:param entries: List of strings ... | from solution import read_and_sort_entries
def test_example_1():
assert read_and_sort_entries(6, "banana 7 apple 42 -15 orange") == ["apple", "banana", "orange", -15, 7, 42]
def test_example_2():
assert read_and_sort_entries(4, "10 -1 apple3 apple5") == ["apple3", "apple5", -1, 10]
def test_single_string():
... | [
{
"docstring": "This function takes a list of mixed entries (numbers and strings) and sorts them\nso that:\n- All strings appear before any numbers.\n- Strings are sorted in lexicographical order.\n- Numbers are sorted in non-decreasing order.\n\n:param entries: List of strings and integers\n:return: A sorted 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 sort_entries(entries):\n \"\"\"\n This function sorts a list of entries where strings come before numbers.\n Strings are sorted lexicographically and ... | trial_gpt4o_2 | {
"original_instruction": "A software company has developed a new system that needs to store and retrieve both numbers and strings efficiently. One requirement is that the system needs to compare different entries to sort and perform quick lookups. The entries are either strings or integers, and they follow a strict ... | 0.771578 | Taco_29084 | C | [
"sort_entries",
"read_and_sort_entries"
] | 2 | [
[
"read_and_sort_entries",
"sort_entries"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 572faf10297fdfc3eacb825564ee77e6eb9909f4 | 4a2afe6c845a77a8b46497e82c72c54248939848 | |||
v1.0 | complete | Taco | Taco_28712_C | def longest_common_subsequence_length(X_str: str, Y_str: str) -> int:
""" Determine the longest common subsequence (LCS) of the stock prices for the two companies.
Args:
X_str (str): space-separated integers representing the stock prices of the first company.
Y_str (str): space-separated integers repre... | def lcs_length(X, Y):
"""
Returns the length of the longest common subsequence (LCS) of two sequences.
"""
m = len(X)
n = len(Y)
# Create a 2D array to store the lengths of longest common subsequence.
L = [[0 for j in range(n+1)] for i in range(m+1)]
# Following steps build L[m... | from solution import longest_common_subsequence_length
def test_lcs_length_example_1():
assert longest_common_subsequence_length("1 3 4 1 2 1 5", "3 4 1 2 1 3") == 5
def test_lcs_length_example_2():
assert longest_common_subsequence_length("7 8 9 10", "1 2 3 4") == 0
def test_lcs_length_different_lengths():
... | [
{
"docstring": "Returns the length of the longest common subsequence (LCS) of two sequences.",
"function_declaration": "def lcs_length(X, Y):",
"function_name": "lcs_length",
"parameter_list": "(X, Y)"
},
{
"docstring": "Given two space-separated strings of integers, return the length of the... | [
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 lcs_stock_prices(prices1, prices2):\n \"\"\"\n Returns the length of the longest common subsequence of the stock prices for two companies.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "Problem Statement\n\nAs a developer in a software company, you are responsible for designing algorithms to handle large-scale data processing. One of your assignments is to analyze the daily stock prices of multiple companies. You are given a list of stock prices for two companies over a pe... | 0.692761 | Taco_28712 | C | [
"lcs_length",
"longest_common_subsequence_length"
] | 2 | [
[
"longest_common_subsequence_length",
"lcs_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 295f2aa0a481c903826e2a61b8ff72725688bf93 | 77af3d4d658cf2e88e3a5f17d680820194180463 | |||
v1.0 | complete | Taco | Taco_29179_C | def is_prime(n: int) -> bool:
"""
Helper function to check if a number is a prime number.
"""
pass
def prime_sum_ranges(N: int, arr: List[int], queries: List[Tuple[int, int]]) -> List[int]:
"""
Given a list of N integers and a list of queries,
each query specifies a range [L, R] (1-indexed)... | 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 % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | def test_prime_sum_ranges():
# Test case 1
N = 6
arr = [1, 2, 3, 4, 5, 6]
queries = [(1, 3), (2, 5), (4, 6)]
assert prime_sum_ranges(N, arr, queries) == [5, 10, 5]
# Test case 2
N = 5
arr = [11, 15, 17, 19, 23]
queries = [(1, 2), (2, 4), (1, 5)]
assert prime_sum_ranges(N, arr, q... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of N integers and a list of queries, \neach query specifies a range [L, R] (1-indexed). \... | [
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 Helper function to check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "## Problem Statement: Prime Sum Ranges\nGiven a list of N integers and Q queries, each query specifies a range [L, R] (1-indexed). For each query, output the sum of all prime numbers within that range of the list.\n\n### Input Format\n- The first line contains an integer N, the size of the ... | 0.677787 | Taco_29179 | C | [
"is_prime",
"prime_sum_ranges"
] | 2 | [
[
"prime_sum_ranges",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e7c08e5370ce2b6e7471902e836ec5a760b76e9b | 6058d151e493385cfa046f3e7f9aedc1d1c7badf | |||
v1.0 | complete | Taco | Taco_28989_C | def largest_cross_in_grid(n: int, grid: List[List[int]]) -> int:
""" Given a grid of size n x n, identify the largest cross of 1s in that grid.
A cross consists of one vertical and one horizontal line of 1s, intersecting at a single point.
Both the vertical and horizontal lines must be of equal lengths, cen... | def largest_cross_in_grid(n, grid):
def compute_arm_lengths(matrix, n):
left = [[0] * n for _ in range(n)]
right = [[0] * n for _ in range(n)]
top = [[0] * n for _ in range(n)]
bottom = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
... | def test_get_largest_crosses_single():
input_string = "5\n1 0 1 1 1\n1 1 1 0 0\n1 1 1 1 1\n0 0 1 0 1\n1 1 1 1 1\n0"
assert get_largest_crosses(input_string) == [3]
def test_get_largest_crosses_multiple():
input_string = (
"5\n1 0 1 1 1\n1 1 1 0 0\n1 1 1 1 1\n0 0 1 0 1\n1 1 1 1 1\n"
"5\n0 0 ... | [
{
"docstring": null,
"function_declaration": "def largest_cross_in_grid(n, grid):",
"function_name": "largest_cross_in_grid",
"parameter_list": "(n, grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter... | [
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_cross_length(n, grid):\n if n == 0 or not grid:\n return 0\n \n def calculate_arm_lengths():\n left = [[0] * n for _ in range(n)]\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a grid of size n x n, you have to write a program that helps you identify the largest cross of 1s in that grid. A cross consists of one vertical and one horizontal line of 1s, intersecting at a single point. Both the vertical and horizontal lines must be of equal lengths, centered at ... | 0.535346 | Taco_28989 | C | [
"largest_cross_in_grid",
"parse_input",
"get_largest_crosses"
] | 3 | [
[
"get_largest_crosses",
"largest_cross_in_grid"
],
[
"get_largest_crosses",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | d1bddde9c4698246a1b88515d882bc6044cca740 | fd152143ac3e0ac7c7acf30775c7e4c4f5876038 | |||
v1.0 | complete | Taco | Taco_29122_C | def collatz_steps(x):
"""
Returns the number of steps required for a given starting number x to reach 1
using the Collatz transformation.
>>> collatz_steps(6)
8
>>> collatz_steps(19)
20
>>> collatz_steps(27)
111
>>> collatz_steps(1)
0
>>> collatz_steps(2)
1
... | def collatz_steps(x):
"""
Returns the number of steps required for a given starting number x to reach 1
using the Collatz transformation.
"""
steps = 0
while x != 1:
if x % 2 == 0:
x //= 2
else:
x = 3 * x + 1
steps += 1
return steps
def colla... | from solution import collatz_steps, collatz_steps_for_multiple_numbers
def test_collatz_steps():
assert collatz_steps(6) == 8
assert collatz_steps(19) == 20
assert collatz_steps(27) == 111
assert collatz_steps(1) == 0
assert collatz_steps(2) == 1
def test_collatz_steps_for_multiple_numbers():
... | [
{
"docstring": "Returns the number of steps required for a given starting number x to reach 1 \nusing the Collatz transformation.",
"function_declaration": "def collatz_steps(x):",
"function_name": "collatz_steps",
"parameter_list": "(x)"
},
{
"docstring": "Returns a list with the number of ... | [
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 collatz_steps(x):\n \"\"\"\n Returns the number of steps required for a given starting number x to reach 1 \n using the Collatz transformation.\n \... | trial_gpt4o_0 | {
"original_instruction": "Eva loves to play with numbers and create new sequences. One day, she came up with a sequence by starting with a positive integer and repeatedly applying a specific transformation until she gets the number 1. The transformation she uses is: if the number is even, she divides it by 2; if the... | 0.665947 | Taco_29122 | C | [
"collatz_steps",
"collatz_steps_for_multiple_numbers"
] | 2 | [
[
"collatz_steps_for_multiple_numbers",
"collatz_steps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b2630ab2be9bbfeb3d6a7e78c7aae5e2e56b6ba7 | 520a5f498c4670b9f96442a73d15f55962afd964 | |||
v1.0 | complete | Taco | Taco_29252_C | def unique_ranking_count(heights_input: str) -> int:
""" Determine the number of unique ranking lists based on the heights of the players.
>>> unique_ranking_count("4 3 2 1")
1
>>> unique_ranking_count("3 3 2 1")
12
>>> unique_ranking_count("1 1 1 1")
1
>>> unique_ranking_count("1 2")
... | from itertools import permutations
def count_unique_rankings(heights):
"""
Returns the number of unique ranking lists.
"""
unique_rankings = set()
for perm in permutations(heights):
unique_rankings.add(perm)
return len(unique_rankings)
# Function to be called for the task... | from solution import unique_ranking_count
def test_unique_ranking_count_all_unique():
assert unique_ranking_count("4 3 2 1") == 24
def test_unique_ranking_count_duplicates():
assert unique_ranking_count("3 3 2 1") == 12
def test_unique_ranking_count_all_same():
assert unique_ranking_count("1 1 1 1") == 1... | [
{
"docstring": "Returns the number of unique ranking lists.",
"function_declaration": "def count_unique_rankings(heights):",
"function_name": "count_unique_rankings",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def unique_ranking_count(heights_input):",... | [
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 unique_ranking_lists(heights):\n \"\"\"\n Returns the number of unique ranking lists based on heights of players.\n \"\"\"\n # Converting list to a... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of positive integers where each integer represents the height of a player. You are organizing a game in which any two players can play a match. During the match, the taller player always wins. If two players have the same height, either one can win. A tournament is he... | 0.619813 | Taco_29252 | C | [
"count_unique_rankings",
"unique_ranking_count"
] | 2 | [
[
"unique_ranking_count",
"count_unique_rankings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 702c3975fbb7f51e5a2892ea7a10833ca2fa1de1 | 4e9af2cf5627fa9e9cce1eccc3cb6e24c6da5c31 | |||
v1.0 | complete | Taco | Taco_29414_C | from typing import List
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(5)
True
"""
def filter_primes(lst: List[int]) -> List[int]:
"""Returns a list of prime number... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(0)
def test_filter_primes():
assert filter_primes(... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list.",
"function_declaration": "def filter_primes(lst):",
... | [
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 \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ... | trial_gpt4o_1 | {
"original_instruction": "Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, in the same order they appeared. Additionally, ensure your function handles an empty list and lists with no prime numbers appropriately.\n\nFor example:\n```\nfilt... | 0.748455 | Taco_29414 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a043ca2567936b3c0f9189aa12e6da47c6209401 | 125235e2845e7e0bb7274266d260c600626dfc70 | |||
v1.0 | complete | Taco | Taco_29198_C | def process_traps(traps: List[int]) -> int:
""" A kingdom is being attacked by a dragon, and the king wants to capture the dragon
by laying traps along its possible flight path.
There are N traps laid out in a straight line, each with a defined capture limit.
The longest sequence of traps such that e... | def longest_increasing_subsequence(traps):
"""
This function takes a list of trap limits and returns the length of the longest increasing subsequence.
"""
if not traps:
return 0
n = len(traps)
lis = [1] * n # Initialize LIS length array with 1 for each position
for i in ra... | from solution import process_traps
def test_sample_input():
traps = [1, 3, 2, 4, 6, 5]
assert process_traps(traps) == 4
def test_single_trap():
traps = [5]
assert process_traps(traps) == 1
def test_all_equal_traps():
traps = [2, 2, 2, 2, 2]
assert process_traps(traps) == 1
def test_strictly_... | [
{
"docstring": "This function takes a list of trap limits and returns the length of the longest increasing subsequence.",
"function_declaration": "def longest_increasing_subsequence(traps):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(traps)"
},
{
"docstring": nul... | [
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 longest_increasing_subsequence(traps):\n \"\"\"\n Finds the length of the longest increasing subsequence in trap limits.\n \n Args:\n traps (lis... | trial_gpt4o_2 | {
"original_instruction": "A kingdom is being attacked by a dragon, and the king wants to capture the dragon by laying traps along its possible flight path. There are N traps laid out in a straight line, each with a defined capture limit. The dragon follows a zigzag flight path, which means it can be captured if the ... | 0.539499 | Taco_29198 | C | [
"longest_increasing_subsequence",
"process_traps"
] | 2 | [
[
"process_traps",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 34eb49304c8c514b8f1fb83093663b28887cba53 | 455fab09029dc0cea99c6e52e79c7f9f0a787bfb | |||
v1.0 | complete | Taco | Taco_29558_C | def generate_primes(n: int) -> list:
"""
Generates the first n prime numbers.
:param n: The number of primes to generate
:type n: int
:return: A list of the first n prime numbers
:rtype: list
"""
# Implementation goes here
def format_prime_sequence(n: int) -> str:
"""
Gener... | def generate_primes(n):
"""
Generates the first n prime numbers.
:param n: The number of primes to generate
:type n: int
:return: A list of the first n prime numbers
:rtype: list
"""
primes = []
candidate = 2
while len(primes) < n:
is_prime = all(candidate % prime !=... | def test_generate_primes():
assert generate_primes(1) == [2]
assert generate_primes(2) == [2, 3]
assert generate_primes(5) == [2, 3, 5, 7, 11]
assert generate_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_format_prime_sequence():
assert format_prime_sequence(1) == "P1: 2"
assert f... | [
{
"docstring": "Generates the first n prime numbers.\n\n:param n: The number of primes to generate\n:type n: int\n:return: A list of the first n prime numbers\n:rtype: list",
"function_declaration": "def generate_primes(n):",
"function_name": "generate_primes",
"parameter_list": "(n)"
},
{
"... | [
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 generate_primes(n):\n \"\"\"\n Generates the first n prime numbers.\n \n :param n: The number of primes to generate\n :type n: int\n :return:... | trial_gpt4o_0 | {
"original_instruction": "## Task\nDesign a program that generates a sequence of prime numbers, and then organizes them into a specific formatted string. The length of the sequence is determined by the input provided by the user.\n\n### Example\nFor `n = 5`, the prime sequence is `[2, 3, 5, 7, 11]` and the resultant... | 0.700425 | Taco_29558 | C | [
"generate_primes",
"format_prime_sequence"
] | 2 | [
[
"format_prime_sequence",
"generate_primes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | de9f9d4ec807b85059593966add870f3fb744495 | 4ad932668637a7486c417d43a478cb8c95e4a24e | |||
v1.0 | complete | Taco | Taco_29270_C | def min_path_sum(grid: List[List[int]]) -> int:
"""
Find the minimum sum path from the top-left to the bottom-right corner of the grid.
Only moves to the right and down are allowed.
Args:
grid (List[List[int]]): A 2D list representing the grid with non-negative numbers.
Returns:
in... | def min_path_sum(grid):
"""
Finds the minimum sum path from the top-left to bottom-right corner of the grid.
Only moves to the right and down are allowed.
"""
if not grid or not grid[0]:
return 0
m, n = len(grid), len(grid[0])
dp = [[0] * n for _ in range(m)]
dp[0][0] = grid[0]... | def test_min_path_sum():
grid1 = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_path_sum(grid1) == 7
grid2 = [
[1, 2],
[1, 1]
]
assert min_path_sum(grid2) == 3
def test_parse_input():
input_str = "3 3\n1 3 1\n1 5 1\n4 2 1\n2 2\n1 2\n1 1\n0 0"... | [
{
"docstring": "Finds the minimum sum path from the top-left to bottom-right corner of the grid.\nOnly moves to the right and down are allowed.",
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"functi... | [
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 min_path_sum(grid):\n \"\"\"\n Finds the minimum sum path from the top-left to bottom-right corner of the grid.\n Only moves to the right and down are... | trial_gpt4o_0 | {
"original_instruction": "**Problem**\n\nYou are working as an assistant to a game developer who is creating a new puzzle game involving grids. One of the main components of the game is to find paths within a grid.\n\nThe grid is an m x n grid filled with non-negative numbers, where each number represents the cost o... | 0.728809 | Taco_29270 | C | [
"min_path_sum",
"parse_input",
"process_grids",
"main"
] | 4 | [
[
"process_grids",
"min_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 24e16d2d13b4e5560e408b38c70e953deed6abc7 | d9388cbc7a91a2380f8a00d2f43a6302e31f9e7e | |||
v1.0 | complete | Taco | Taco_29275_C | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def dfs(node):
""" Perform depth-first search to find the maximum sum of a downward path.
>>> node1 = TreeNode(1)
>>> node2 = TreeNode(2)
>>> node3 = TreeNode(3)
>>> node1.left =... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def dfs(node):
if not node:
return 0
left_sum = dfs(node.left)
right_sum = dfs(node.right)
max_single = max(max(left_sum, right_sum) + node.val, node.val)
return max_sing... | def test_dfs():
node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node1.left = node2
node1.right = node3
assert dfs(node1) == 4
def test_max_path_sum_single_node():
assert max_path_sum([], 1) == 1
def test_max_path_sum_small_tree():
edges = [(1, 2), (1, 3)]
assert max_pat... | [] | [
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": "class TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\ndef build_tree(edges, n):\n node... | trial_gpt4o_4 | {
"original_instruction": "You are given a binary tree where each node contains a value. A path in this binary tree is defined as a sequence of nodes starting from any node and ending at any node, directed downwards (i.e., only from parent nodes to child nodes). The sum of a path is defined as the sum of node values ... | 0.613584 | Taco_29275 | C | [
"dfs",
"max_path_sum",
"maximum_sum_of_paths",
"parse_input",
"main"
] | 5 | [
[
"max_path_sum",
"dfs"
],
[
"maximum_sum_of_paths",
"max_path_sum"
]
] | 2 | [
"parse_input"
] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 13b92ce1ac8e68e82c2d0e950d26ebb48f67e1d1 | 3b1f3c756cb8cb01a7ff5f01249d96430889b139 | |||
v1.0 | complete | Taco | Taco_29465_C | def charity_auction(n: int, bids_input: List[str]) -> List[str]:
""" Determines the winners for each item along with the winning bid amount.
Args:
n: an integer, the number of bids placed in the auction.
bids_input: a list of strings, where each string contains the item name, bid amount, and bidder... | def determine_winners(n, bids):
"""
Determines the winners for each item along with the winning bid amount.
Args:
n: an integer, the number of bids placed in the auction.
bids: a list of tuples, where each tuple contains (item name, bid amount, bidder name)
Returns:
A sorted list of st... | from solution import charity_auction
def test_charity_auction():
bids_input = [
"painting 300 John",
"vase 150 Alice",
"sculpture 200 Bob",
"vase 200 Charlie",
"painting 350 Emma",
"sculpture 250 John"
]
n = len(bids_input)
expected_output = [
"pa... | [
{
"docstring": "Determines the winners for each item along with the winning bid amount.\n\nArgs:\nn: an integer, the number of bids placed in the auction.\nbids: a list of tuples, where each tuple contains (item name, bid amount, bidder name)\n\nReturns:\nA sorted list of strings in the format \"item_name winni... | [
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 determine_winners(bids):\n \"\"\"\n Determines the winners for each item in the auction.\n :param bids: List of tuples where each tuple contains (item... | trial_gpt4o_1 | {
"original_instruction": "Gyan is organising a charity auction event where various items will be sold to the highest bidders. Each bidder can place multiple bids on different items. Gyan keeps track of all the bids and at the end of the auction, he wants to determine the winners for each item along with the winning ... | 0.525528 | Taco_29465 | C | [
"determine_winners",
"charity_auction"
] | 2 | [
[
"charity_auction",
"determine_winners"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61c229281c2488966ea0fcd5acf493cd88518ce2 | 0385f211111af9b572a3630acacf20c2463097ef |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.