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_19210_C | import sys
from typing import List, Tuple
from collections import deque
def preprocess_tree(N: int, edges: List[Tuple[int, int]]) -> Tuple[List[int], List[int]]:
"""
Preprocess the tree to create adjacency list and depth/parent info for LCA.
N: int, number of nodes in the tree
edges: list of tuple... | import sys
from collections import deque
def preprocess_tree(N, edges):
"""
Preprocess the tree to create adjacency list and depth/parent info for LCA.
N: int, number of nodes in the tree
edges: list of tuples, each tuple representing an edge between two nodes (u, v)
"""
adjacency_list = [... | import pytest
from solution import preprocess_tree, shortest_path_length
def test_preprocess_tree():
N = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
parent, depth = preprocess_tree(N, edges)
assert parent == [-1, -1, 1, 1, 3, 3]
assert depth == [-1, 0, 1, 1, 2, 2]
def test_shortest_path_length():
... | [
{
"docstring": "Preprocess the tree to create adjacency list and depth/parent info for LCA.\n\nN: int, number of nodes in the tree\nedges: list of tuples, each tuple representing an edge between two nodes (u, v)",
"function_declaration": "def preprocess_tree(N, edges):",
"function_name": "preprocess_tre... | [
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 sys\nfrom collections import deque\n\n\nclass Tree:\n def __init__(self, n):\n self.adj = [[] for _ in range(n + 1)]\n self.depth = [-1] * ... | trial_gpt4o_4 | {
"original_instruction": "You are given a binary tree with N nodes, numbered 1 through N.\n\nThe i-th of the N-1 edges connects the vertices u_i and v_i.\n\nFor each query, you are given two vertices x and y. You need to determine the length of the shortest path between these two vertices.\n\nWrite a program that re... | 0.614189 | Taco_19210 | C | [
"preprocess_tree",
"lca",
"shortest_path_length",
"main"
] | 4 | [
[
"shortest_path_length",
"lca"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc473b4efbfe68a2fa07b53265e25e3da95349ce | 33659dec4aa6c21730df7436fe980b4f99c78e9d | |||
v1.0 | complete | Taco | Taco_20397_C | from typing import List
def is_prime(num: int) -> bool:
"""Check if a number is prime."""
# Add your implementation here
def is_palindrome(num: int) -> bool:
"""Check if a number is a palindrome."""
# Add your implementation here
def palindromic_prime_count(N: int) -> int:
""" Count the numbers t... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import palindromicPrimeCount
def test_palindromicPrimeCount_example1():
assert palindromicPrimeCount(10) == 4
def test_palindromicPrimeCount_example2():
assert palindromicPrimeCount(50) == 5
def test_palindromicPrimeCount_upper_limit():
assert palindromicPrimeCount(10000) == 20
def test_pa... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrom... | [
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_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <... | trial_gpt4o_3 | {
"original_instruction": "Given a positive integer N, determine how many numbers from 1 to N are both prime and palindrome.\n\nExample 1:\nInput:\nN = 10\nOutput:\n4\nExplanation:\nThe palindromic primes from 1 to 10 are {2, 3, 5, 7}.\n\nExample 2:\nInput:\nN = 50\nOutput:\n5\nExplanation:\nThe palindromic primes fr... | 0.702845 | Taco_20397 | C | [
"is_prime",
"is_palindrome",
"palindromicPrimeCount"
] | 3 | [
[
"palindromicPrimeCount",
"is_palindrome"
],
[
"palindromicPrimeCount",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6b88d12ec3fd1125341d9cc43dfc864addb66e52 | e6abc1d09b5f605ff0c131330188550b47bb9073 | |||
v1.0 | complete | Taco | Taco_20367_C | from typing import List
def largest_square(n: int, m: int, grid: List[str]) -> int:
""" Determine the largest side length of a square that can be placed on the grid without passing through any obstacles.
>>> largest_square(4, 5, [".....", "..#..", ".....", "....."])
2
>>> largest_square(3, 3, ["###", ... | def largest_square(n, m, grid):
def is_square_placable(x, y, size):
if x + size > n or y + size > m:
return False
for i in range(x, x + size):
for j in range(y, y + size):
if grid[i][j] == '#':
return False
return True
... | def test_largest_square():
assert roller_coaster_track(4, 5, [".....", "..#..", ".....", "....."]) == 2
assert roller_coaster_track(3, 3, ["###", "###", "###"]) == 0
assert roller_coaster_track(3, 4, ["....", ".##.", "...."]) == 1
assert roller_coaster_track(5, 5, [".....", ".....", ".....", ".....", ".... | [
{
"docstring": null,
"function_declaration": "def largest_square(n, m, grid):",
"function_name": "largest_square",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def roller_coaster_track(n, m, grid):",
"function_name": "roller_coaster_track",
"p... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_square(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Initialize a matrix to keep track of square sizes\n dp = [[0] * m for _ in range... | trial_gpt4o_2 | {
"original_instruction": "In a faraway kingdom, the king has an amusement park designed in the shape of a rectangular grid with n rows and m columns. Each cell in the grid can either be empty or contain an obstacle. The goal is to place a large roller coaster track in the park. The track must form a perfect square o... | 0.64294 | Taco_20367 | C | [
"largest_square",
"roller_coaster_track"
] | 2 | [
[
"roller_coaster_track",
"largest_square"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e574252bcaaa7b02c9a1443af0adca07351f758f | 965e0b5269a0e358bc5e0c4164e7255ebf16e155 | |||
v1.0 | complete | Taco | Taco_19791_C | def max_sum_subgrid(grid: List[List[int]], m: int, n: int) -> int:
""" Returns the maximum sum of all possible subgrids in a grid of dimensions m x n.
"""
pass
def kadane(arr: List[int]) -> int:
""" Returns the maximum sum of a contiguous subarray using Kadane's algorithm.
"""
pass
def max_sum... | def max_sum_subgrid(grid, m, n):
max_sum = float('-inf')
for left in range(n):
temp = [0] * m
for right in range(left, n):
for i in range(m):
temp[i] += grid[i][right]
current_max = kadane(temp)
max_sum = max(max_sum, current_... | def test_max_sum_subgrid():
test_cases = [
(2, [
(2, 2, [
[1, -2],
[-3, 4]
]),
(3, 3, [
[1, 2, 3],
[4, 5, 6],
[-1, -2, -3]
])
]),
]
expected_result = [4, 21]
... | [
{
"docstring": null,
"function_declaration": "def max_sum_subgrid(grid, m, n):",
"function_name": "max_sum_subgrid",
"parameter_list": "(grid, m, n)"
},
{
"docstring": null,
"function_declaration": "def kadane(arr):",
"function_name": "kadane",
"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": "def maximum_sum_subgrid(grid):\n \"\"\"\n Given a grid of dimensions MxN filled with integers,\n determine the maximum sum of all possible subgrids.\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a grid of dimensions MxN filled with integers, determine the maximum sum of all possible subgrids.\n\nInput Specifications:\n\nThe first line contains an integer T, the number of test cases. For each test case:\n- The first line contains two integers M and N, the dimensions of the gri... | 0.653164 | Taco_19791 | C | [
"max_sum_subgrid",
"kadane",
"max_sum_of_all_subgrids"
] | 3 | [
[
"max_sum_of_all_subgrids",
"max_sum_subgrid"
],
[
"max_sum_subgrid",
"kadane"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b412178397c270f4a57fb91a2268bf7c8fbf7ca9 | a976f598d238b8596c43da9f7d6317b9a1910642 | |||
v1.0 | complete | Taco | Taco_19951_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):
"""
Builds a binary tree from a list of values in level order traversal.
"""
pass
def left_view(root):
"""
Returns the left vi... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
"""
Builds a binary tree from a list of values in level order traversal.
"""
if not nodes or nodes[0] is None:
return None
... | from solution import left_view_of_tree
def test_left_view_small_tree():
n = 6
values = [1, 2, 3, 4, None, 5, 6]
expected_output = [1, 2, 4]
assert left_view_of_tree(n, values) == expected_output
def test_left_view_with_single_node():
n = 1
values = [1]
expected_output = [1]
assert left... | [] | [
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 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": "Petya has been experimenting with binary trees and their various properties. He recently came across a concept called \"Left View\" of a binary tree. The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side. Now, Petya wants to write a program to... | 0.543366 | Taco_19951 | C | [
"build_tree",
"left_view",
"left_view_of_tree"
] | 3 | [
[
"left_view_of_tree",
"build_tree"
],
[
"left_view_of_tree",
"left_view"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 659bbe72cd6227f5c3d38c0640cf2ecb6cd393dd | a5c7712086052c4e1b1e11d1c1e0559e34e4ff62 | |||
v1.0 | complete | Taco | Taco_20223_C | def task_order(t: int, task_descriptions: List[str]) -> str:
""" Determines the order in which tasks should be completed given their dependencies.
>>> task_order(4, ["1 2 3", "2", "3 4", "4"])
"2 4 3 1"
>>> task_order(2, ["1 2", "2 1"])
"IMPOSSIBLE"
"""
pass
# Unit Tests
def test... | from collections import defaultdict, deque
def find_task_order(t, tasks):
graph = defaultdict(list)
indegree = {i: 0 for i in range(1, t + 1)}
for task in tasks:
task_id = task[0]
dependencies = task[1]
for dep in dependencies:
graph[dep].append(task_id)
ind... | from solution import task_order
def test_sample_input_1():
assert task_order(4, ["1 2 3", "2", "3 4", "4"]) in ["2 4 3 1", "4 2 3 1", "4 3 2 1"]
def test_sample_input_2():
assert task_order(2, ["1 2", "2 1"]) == "IMPOSSIBLE"
def test_single_task():
assert task_order(1, ["1"]) == "1"
def test_no_dependen... | [
{
"docstring": null,
"function_declaration": "def find_task_order(t, tasks):",
"function_name": "find_task_order",
"parameter_list": "(t, tasks)"
},
{
"docstring": null,
"function_declaration": "def task_order(t, task_descriptions):",
"function_name": "task_order",
"parameter_lis... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_task_order(t, tasks):\n from collections import defaultdict, deque\n\n # Create adjacency list and in-degree dictionary\n adj_list = defaultdict(... | trial_gpt4o_2 | {
"original_instruction": "You are working on a project management tool where tasks need to be managed. Each task has a unique identifier and a list of dependencies (i.e., other tasks that must be completed before this one can be started). Implement a function to determine the order in which the tasks should be compl... | 0.470927 | Taco_20223 | C | [
"find_task_order",
"task_order"
] | 2 | [
[
"task_order",
"find_task_order"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76d0dd9f681878c32f690c647f26d8387853f89d | f72369a74929afff9516515aa20c7836adf4194e | |||
v1.0 | complete | Taco | Taco_20611_C | def can_reach_target(steps, target):
"""
Determine if it is possible to reach the target step by summing the elements
of the steps array exactly or their negatives.
Args:
steps: List[int] - list of distinct integers representing steps.
target: int - target step to reach.
Returns:
str: ... | def can_reach_target(steps, target):
"""
Determine if it is possible to reach the target step by summing the elements
of the steps array exactly or their negatives.
Args:
steps: List[int] - list of distinct integers representing steps.
target: int - target step to reach.
Returns:
... | def test_can_reach_target_yes():
assert can_reach_target([1, 3, 5, 7], 8) == "YES"
def test_can_reach_target_no():
assert can_reach_target([2, 4, 6], 5) == "NO"
def test_can_reach_target_single_step_positive():
assert can_reach_target([10], 10) == "YES"
def test_can_reach_target_single_step_negative():
... | [
{
"docstring": "Determine if it is possible to reach the target step by summing the elements\nof the steps array exactly or their negatives.\n\nArgs:\nsteps: List[int] - list of distinct integers representing steps.\ntarget: int - target step to reach.\n\nReturns:\nstr: \"YES\" if it's possible to reach the tar... | [
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 can_reach_target(steps, target):\n \"\"\"\n Determine if it is possible to reach the target step by summing the elements\n of the steps array exactly ... | trial_gpt4o_0 | {
"original_instruction": "Given an array of distinct integers representing steps and an integer target, determine if it is possible to reach exactly the target step by taking a specific sequence of steps. The sequence of steps must strictly follow one of two patterns: either always stepping forward or always steppin... | 0.555025 | Taco_20611 | C | [
"can_reach_target",
"can_sum_to_target"
] | 2 | [
[
"can_reach_target",
"can_sum_to_target"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d265457225828b93c05991f5a56d669248ef3d69 | 728d46e952e0a2f514d89fffadf25f757704a817 | |||
v1.0 | complete | Taco | Taco_20518_C | def composite_note_possible(data: str) -> str:
"""
Determines if it's possible to perfectly play the composite musical note
by blending the active pulses from the generators during the specified intervals.
:param data: Input data as a string containing information about generators,
... | def is_composite_note_possible(generators):
"""
Determines if it's possible to perfectly play the composite musical note
by blending the active pulses from the generators during the specified intervals.
:param generators: List of tuples containing generator information. Each tuple contains:
... | from solution import composite_note_possible
def test_single_generator_valid_intervals():
data = """1
8
11001010
2
0 7
8 15"""
assert composite_note_possible(data) == "possible"
def test_multiple_generators_invalid_intervals():
data = """2
4
1101
2
0 3
4 7
... | [
{
"docstring": "Determines if it's possible to perfectly play the composite musical note \nby blending the active pulses from the generators during the specified intervals.\n\n:param generators: List of tuples containing generator information. Each tuple contains:\n (pulse_sequence, intervals)... | [
0,
0,
1,
0
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_possible_to_blend(generators):\n def get_pulse_at(generator, time):\n pulse_index = time % len(generator[1])\n ret... | trial_gpt4o_3 | {
"original_instruction": "Your friend has recently developed an interest in creating composite musical notes using a circular array of digital sound generators. Each generator works on a sequence of binary pulses. A pulse is either `0` or `1`, and a musical note is created by blending the pulses from multiple genera... | 0.597984 | Taco_20518 | C | [
"is_composite_note_possible",
"process_input",
"composite_note_possible"
] | 3 | [
[
"composite_note_possible",
"is_composite_note_possible"
],
[
"composite_note_possible",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 0d5ccf4e4ca8a063b26952be6ba2385db695b1ce | 095bdf3ceb8880426c657e85da99672c997dbfaa | |||
v1.0 | complete | Taco | Taco_20400_C | def process_grid(N, M, grid, queries):
""" Process the grid and respond to the queries.
Args:
N (int): Number of rows in the grid.
M (int): Number of columns in the grid.
grid (List[List[str]]): The 2D grid consisting of '1's and '0's.
queries (List[Tuple]): A list of queries to process on ... | def largest_rectangle_area(heights):
"""
Helper function to calculate the largest rectangle area in a histogram.
"""
stack = [-1]
max_area = 0
for i, h in enumerate(heights):
while stack[-1] != -1 and heights[stack[-1]] >= h:
height = heights[stack.pop()]
width =... | import pytest
from solution import process_grid
def test_initial_grid():
grid = [
['1', '0', '1', '0', '1'],
['1', '1', '1', '0', '0'],
['1', '1', '0', '1', '0'],
['1', '1', '1', '1', '0']
]
queries = [(2,)]
assert process_grid(4, 5, grid, queries) == [6]
def test_updat... | [
{
"docstring": "Helper function to calculate the largest rectangle area in a histogram.",
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area",
"parameter_list": "(heights)"
},
{
"docstring": "Function to calculate the largest rectangle of... | [
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 maximum_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack or heights[stack[-1]... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid represented by a list of strings where each character in the string is either '1' or '0'. The grid is of size `N x M`, where `N` is the number of rows and `M` is the number of columns. You are required to process `Q` queries of two types:\n- `1` $A$ $B$ $X$: Update cell... | 0.573342 | Taco_20400 | C | [
"largest_rectangle_area",
"maximal_rectangle",
"process_grid"
] | 3 | [
[
"maximal_rectangle",
"largest_rectangle_area"
],
[
"process_grid",
"maximal_rectangle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3fd2605d615ea1aea6a10877ae69892f1634588d | 39edea22d20df10be3f92d6a7bef4254ccb9bcee | |||
v1.0 | complete | Taco | Taco_19607_C | import re
from typing import List
def is_weak_password(password: str) -> str:
"""
This function checks if a `password` is weak based on the criteria provided.
"""
pass
def check_passwords(password_list: List[str]) -> List[str]:
"""
This function takes a list of passwords and checks each one ... | import re
def is_weak_password(password):
"""
This function checks if a `password` is weak based on the criteria provided.
"""
if len(password) < 8:
return "Weak"
if not re.search(r'[A-Z]', password):
return "Weak"
if not re.search(r'[a-z]', password):
return "Weak"
... | from solution import is_weak_password, check_passwords
def test_is_weak_password():
# Test with strong passwords
assert is_weak_password("Password1!") == "Strong"
assert is_weak_password("Welc0me!") == "Strong"
# Test with weak passwords
assert is_weak_password("Pass1!") == "Weak" # Missing e... | [
{
"docstring": "This function checks if a `password` is weak based on the criteria provided.",
"function_declaration": "def is_weak_password(password):",
"function_name": "is_weak_password",
"parameter_list": "(password)"
},
{
"docstring": "This function takes a list of passwords and checks ... | [
1,
0
] | 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 re\n\ndef is_weak_password(password):\n \"\"\"\n This function checks if a `password` is weak based on the criteria provided.... | trial_gpt4o_1 | {
"original_instruction": "John is a software developer who is interested in ensuring the security of his applications. He decided to implement a feature that checks for weak passwords in a list of password candidates. A password is considered weak if it matches one of the following criteria:\n\n1. It contains fewer ... | 0.594908 | Taco_19607 | C | [
"is_weak_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"is_weak_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c1914a92ec58c77a30d0a29d9c9d8aec0a2e15a1 | f87424320f1a339812f374ff04cc80af90bd23a4 | |||
v1.0 | complete | Taco | Taco_20557_C | def twin_primes(a: int, b: int) -> List[Tuple[int, int]]:
""" Generate a list of twin prime pairs within a given range.
>>> twin_primes(10, 50) [(11, 13), (17, 19), (29, 31), (41, 43)]
>>> twin_primes(2, 20) [(3, 5), (5, 7), (11, 13), (17, 19)]
>>> twin_primes(14, 16) []
>>> twin_primes(950, 1000) [... | def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def twin_primes(a, b):
twin_prime_pairs = []
for i in range(a, b - 1):
if is_prime(i) and is_prime(i + 2):
twin_prime_pairs.append((i... | from solution import twin_primes
def test_twin_primes_range_10_50():
result = twin_primes(10, 50)
expected = [(11, 13), (17, 19), (29, 31), (41, 43)]
assert result == expected
def test_twin_primes_range_2_20():
result = twin_primes(2, 20)
expected = [(3, 5), (5, 7), (11, 13), (17, 19)]
assert ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def twin_primes(a, b):",
"function_name": "twin_primes",
"parameter_list": "(a, b)"
}
] | [
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 is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retur... | trial_gpt4o_5 | {
"original_instruction": "Diana is fascinated by prime numbers and their properties. She recently learned about twin primes, which are pairs of prime numbers that have a difference of 2 (e.g., (3, 5) and (11, 13)). She wants to generate a list of twin prime pairs within a given range. Write a program to help Diana b... | 0.69041 | Taco_20557 | C | [
"is_prime",
"twin_primes"
] | 2 | [
[
"twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0152c4d1ea7d02096671393a0e567741793fe59 | 153efcb188d6f17e78c124840c37bb46cda09c9a | |||
v1.0 | complete | Taco | Taco_18994_C | def fill_subrectangle(canvas, r1, c1, r2, c2, color):
"""
Fill a subrectangle of the canvas with a specific color.
Args:
canvas (List[List[int]]): The 2D canvas represented as a matrix.
r1 (int): The row index of the top-left corner of the subrectangle.
c1 (int): The column index of the top-lef... | def fill_subrectangle(canvas, r1, c1, r2, c2, color):
for i in range(r1, r2 + 1):
for j in range(c1, c2 + 1):
canvas[i][j] = color
def horizontal_flip(canvas):
for row in canvas:
row.reverse()
def vertical_flip(canvas):
n = len(canvas)
for j in range(n):
for i in ra... | from solution import fill_subrectangle, horizontal_flip, vertical_flip, rotate_90_clockwise, rotate_90_counterclockwise, manipulate_canvas
def test_fill_operation():
canvas = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
fill_subrectangle(canvas, 1, 1, 2, 2, 128... | [
{
"docstring": null,
"function_declaration": "def fill_subrectangle(canvas, r1, c1, r2, c2, color):",
"function_name": "fill_subrectangle",
"parameter_list": "(canvas, r1, c1, r2, c2, color)"
},
{
"docstring": null,
"function_declaration": "def horizontal_flip(canvas):",
"function_na... | [
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 fill_subrectangle(canvas, r1, c1, r2, c2, color):\n for i in range(r1, r2 + 1):\n for j in range(c1, c2 + 1):\n canvas[i][j] = color\n ... | trial_gpt4o_1 | {
"original_instruction": "Problem\n\nYou are tasked with writing a program that can simulate the behavior of a simple graphics editor. The editor can manipulate a 2D canvas of pixels (represented as a matrix) with the following operations:\n\n1. Fill a subrectangle with a specific color.\n2. Flip the contents of the... | 0.592944 | Taco_18994 | C | [
"fill_subrectangle",
"horizontal_flip",
"vertical_flip",
"rotate_90_clockwise",
"rotate_90_counterclockwise",
"manipulate_canvas"
] | 6 | [
[
"manipulate_canvas",
"fill_subrectangle"
],
[
"manipulate_canvas",
"horizontal_flip"
],
[
"manipulate_canvas",
"rotate_90_clockwise"
],
[
"manipulate_canvas",
"rotate_90_counterclockwise"
],
[
"manipulate_canvas",
"vertical_flip"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 142787d798c4412827a3147cc6087ec25838d9e9 | 9943b94f23405c6815c32b174dcaca7ea7575528 | |||
v1.0 | complete | Taco | Taco_20660_C | def merge_intervals(intervals):
"""
Merges overlapping intervals and returns a list of merged intervals.
"""
pass
def total_project_time(n, project_tasks):
"""
Returns the total time spent on each project by merging overlapping tasks.
Arguments:
n -- number of projects
project_... | def merge_intervals(intervals):
"""
Merges overlapping intervals and returns a list of merged intervals.
"""
if not intervals:
return []
intervals.sort(key=lambda x: x[0])
merged = [intervals[0]]
for current in intervals[1:]:
previous = merged[-1]
if current... | from solution import project_times_from_input
def test_example_case():
n = 2
tasks = [
[(1, 5), (2, 6), (8, 10)],
[(1, 3), (2, 5)]
]
assert project_times_from_input(n, tasks) == [7, 4]
def test_non_overlapping_intervals():
n = 1
tasks = [
[(1, 2), (3, 4), (5, 6)]
]
... | [
{
"docstring": "Merges overlapping intervals and returns a list of merged intervals.",
"function_declaration": "def merge_intervals(intervals):",
"function_name": "merge_intervals",
"parameter_list": "(intervals)"
},
{
"docstring": "Returns the total time spent on each project by merging ove... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def merge_intervals(intervals):\n \"\"\"\n Merges overlapping intervals and returns a list of merged intervals.\n \"\"\"\n if ... | trial_gpt4o_1 | {
"original_instruction": "You are part of a team developing an application that tracks time logs for different projects. Each project has several tasks, and each task has a start time and an end time. The application needs to generate a report indicating the total time spent on each project, ensuring that overlappin... | 0.565163 | Taco_20660 | C | [
"merge_intervals",
"total_project_time",
"project_times_from_input"
] | 3 | [
[
"project_times_from_input",
"total_project_time"
],
[
"total_project_time",
"merge_intervals"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 70778bc5670d99adfc7a2f77b6070294731508a5 | 138c6f0ce41dc29c370c7e6cbcab183a82e62dd9 | |||
v1.0 | complete | Taco | Taco_20343_C | def sum_of_digits(x: int) -> int:
""" Calculate the sum of the digits of an integer.
>>> sum_of_digits(12)
3
>>> sum_of_digits(15)
6
"""
def find_divisors(x: int) -> List[int]:
""" Find all divisors of an integer.
>>> find_divisors(12)
[1, 2, 3, 4, 6, 12]
>>> find_divisors(15)
... | def sum_of_digits(x):
return sum(int(digit) for digit in str(x))
def find_divisors(x):
divisors = []
for i in range(1, x + 1):
if x % i == 0:
divisors.append(i)
return divisors
def generate_output_list(numbers):
output = []
for number in numbers:
divisors = find_div... | from solution import sum_of_digits, find_divisors, generate_output_list
def test_sum_of_digits():
assert sum_of_digits(12) == 3
assert sum_of_digits(15) == 6
assert sum_of_digits(1) == 1
assert sum_of_digits(100) == 1
def test_find_divisors():
assert find_divisors(12) == [1, 2, 3, 4, 6, 12]
as... | [
{
"docstring": null,
"function_declaration": "def sum_of_digits(x):",
"function_name": "sum_of_digits",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def find_divisors(x):",
"function_name": "find_divisors",
"parameter_list": "(x)"
},
{
"docstri... | [
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_digits(n):\n \"\"\"\n Returns the sum of the digits of n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef get_divisors(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers. You have to generate a new list following these steps:\n\n1. Initialize an empty list called `output`.\n2. Process every integer `x` in the given list:\n - For each divisor of `x` (including 1 and `x` itself), calculate the sum of its digits.\n - Append... | 0.686508 | Taco_20343 | C | [
"sum_of_digits",
"find_divisors",
"generate_output_list"
] | 3 | [
[
"generate_output_list",
"find_divisors"
],
[
"generate_output_list",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cd605483ef5dddc072d06f85c366c9e42a299316 | d405616421cf69704e0853a98c2924b4ab5437aa | |||
v1.0 | complete | Taco | Taco_20826_C | from typing import List, Tuple
def maximalRectangle(matrix: List[List[int]]) -> int:
"""Given an integer matrix of size 'm x n' where each cell contains either a 0 or a 1,
find the largest rectangle containing only 1s and return its area.
"""
pass
def largestRectangleArea(heights: List[int]) -> int:
... | def maximalRectangle(matrix):
if not matrix:
return 0
m, n = len(matrix), len(matrix[0])
height = [0] * n
max_area = 0
for i in range(m):
for j in range(n):
if matrix[i][j] == 0:
height[j] = 0
else:
height[j] += 1
... | from solution import process_matrices
def test_sample_inputs():
T = 2
matrices = [
(4, 4, [
[1, 0, 1, 0],
[1, 0, 1, 1],
[1, 1, 1, 1],
[1, 0, 0, 0]
]),
(3, 3, [
[1, 1, 1],
[1, 1, 1],
[1, 1, 0]
])
... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
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 maximal_rectangle(matrix):\n def largest_histogram_area(heights):\n stack = []\n max_area = 0\n for i, h in enumerate(heights + [0]):\n... | trial_gpt4o_1 | {
"original_instruction": "Given an integer matrix of size $m \\times n$ where each cell contains either a 0 or a 1, find the largest rectangle containing only 1s and return its area.\n\nInput Format\n\nThe first line contains an integer, $\\boldsymbol{T}$, denoting the number of matrices you must process. Each of th... | 0.692918 | Taco_20826 | C | [
"maximalRectangle",
"largestRectangleArea",
"process_matrices"
] | 3 | [
[
"maximalRectangle",
"largestRectangleArea"
],
[
"process_matrices",
"maximalRectangle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 23d438a7bcb5c5654ada1e75758bd13350928f51 | 1b963d5856c22dee3dacaba7f6662141e3ed2889 | |||
v1.0 | complete | Taco | Taco_20542_C | def is_valid_integer(s: str) -> bool:
""" Checks if the string represents a valid integer.
"""
pass
def max_sum_of_valid_integers(strings: List[str]) -> int:
""" Given a list of strings where each string can be either a valid integer or a word, find the longest subsequence of the list such that only va... | def is_valid_integer(s):
"""
Checks if the string represents a valid integer.
"""
try:
int(s)
return True
except ValueError:
return False
def max_sum_of_valid_integers(strings):
"""
Returns the maximum sum of the longest subsequence of valid integers in the list.
... | from solution import is_valid_integer, max_sum_of_valid_integers
def test_is_valid_integer():
assert is_valid_integer("30") == True
assert is_valid_integer("apple") == False
assert is_valid_integer("-40") == True
assert is_valid_integer("40.5") == False
assert is_valid_integer("123abc") == False
d... | [
{
"docstring": "Checks if the string represents a valid integer.",
"function_declaration": "def is_valid_integer(s):",
"function_name": "is_valid_integer",
"parameter_list": "(s)"
},
{
"docstring": "Returns the maximum sum of the longest subsequence of valid integers in the list.",
"func... | [
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_valid_integer(s):\n \"\"\"\n Checks if the string represents a valid integer.\n \"\"\"\n try:\n int(s)\n return True\n except V... | trial_gpt4o_0 | {
"original_instruction": "Given a list of strings where each string can be either a valid integer or a word, find the longest subsequence of the list such that only valid integers are included and the sum of these integers is maximized. Return the maximum sum.\n\nExample:\n```\nInput: [\"apple\", \"30\", \"banana\",... | 0.627219 | Taco_20542 | C | [
"is_valid_integer",
"max_sum_of_valid_integers"
] | 2 | [
[
"max_sum_of_valid_integers",
"is_valid_integer"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9b83860b2d9c24357695d3a6f1a48146eb851eef | 8419d3968be49735791981bb4b76757a8aee5bb3 | |||
v1.0 | complete | Taco | Taco_20922_C | from typing import List
def custom_sort(numbers: List[int]) -> List[int]:
"""Sorts a list of integers such that all prime numbers appear first (in ascending order),
followed by all non-prime numbers (in ascending order).
>>> custom_sort([10, 2, 3, -1, 4, 1, 7])
[2, 3, 7, -1, 1, 4, 10]
>>> custom_so... | from typing import List
def is_prime(n: int) -> bool:
"""Helper function to determine if a number is prime."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
... | from solution import custom_sort
def test_all_primes():
assert custom_sort([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_no_primes():
assert custom_sort([4, 6, 8, 9, 10]) == [4, 6, 8, 9, 10]
def test_mixed_primes_non_primes():
assert custom_sort([10, 3, 2, 11, 1, 4, -5]) == [2, 3, 11, -5, 1, 4, 10]
def... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Sorts the list such that all prime numbers come first (in ascending order),\nfollowed by non-prime numbers ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if... | trial_gpt4o_2 | {
"original_instruction": "Chris is working on a custom number sorting algorithm for a class project. He wants to sort a list of numbers in a specific way: all the prime numbers should appear at the beginning of the list (sorted in ascending order), followed by all the non-prime numbers (also sorted in ascending orde... | 0.705991 | Taco_20922 | C | [
"is_prime",
"custom_sort"
] | 2 | [
[
"custom_sort",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ffbc7d2b4a26b28fe095d6e2cd45f40538ed8d9e | 09cc1f3f77fba2116218d802b204dbde30fdc33b | |||
v1.0 | complete | Taco | Taco_20584_C | def minimum_start_time_difference(n: int, speeds: List[int]) -> int:
"""
Given the number of runners and their respective speeds, calculates the minimum difference in
start times that ensures no two runners finish at the same time.
Args:
n (int): The number of runners.
speeds (List... | def gcd(a, b):
while b:
a, b = b, a % b
return a
def minimum_start_time_difference(n, speeds):
speeds_gcd = speeds[0]
for speed in speeds[1:]:
speeds_gcd = gcd(speeds_gcd, speed)
return speeds_gcd
# Reading input can be done as follows. Uncomment and use it if running as a scr... | from solution import minimum_start_time_difference
def test_case_1():
assert minimum_start_time_difference(4, [2, 3, 5, 7]) == 1
def test_case_2():
assert minimum_start_time_difference(3, [10, 20, 30]) == 10
def test_case_3():
assert minimum_start_time_difference(2, [4, 6]) == 2
def test_case_4():
a... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def minimum_start_time_difference(n, speeds):",
"function_name": "minimum_start_time_difference",
"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": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef minimum_start_time_difference(n, speeds):\n speeds_gcd = speeds[0]\n for speed in ... | trial_gpt4o_0 | {
"original_instruction": "Katie is organizing a marathon and wants to design a staggered start time schedule for the runners. Each runner starts at a slightly different time so that no two runners are expected to cross the finish line simultaneously, making it easier to track their times.\n\nKatie has a set of runne... | 0.556445 | Taco_20584 | C | [
"gcd",
"minimum_start_time_difference"
] | 2 | [
[
"minimum_start_time_difference",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 701ed75a8507b784e671050e064639570543ba77 | cf9addab0ad580ed316ed58185e4cf56c6d044bb | |||
v1.0 | complete | Taco | Taco_20281_C | import heapq
from typing import List, Tuple
def shortest_paths(n: int, edges: List[Tuple[int, int, int]], c: int) -> List[int]:
"""
Computes the shortest paths from the source node c to all other nodes using Dijkstra's algorithm.
Parameters:
n (int): Number of nodes (cities)
edges (List[Tuple[... | import heapq
def shortest_paths(n, edges, c):
"""
Computes the shortest paths from the source node c to all other nodes using Dijkstra's algorithm.
Parameters:
n (int): Number of nodes (cities)
edges (List[Tuple[int, int, int]]): List of edges represented as (u, v, t) tuples
c (int): The s... | def test_shortest_paths():
n, m = 5, 6
edges = [
(1, 2, 3),
(1, 3, 2),
(2, 4, 4),
(3, 4, 1),
(4, 5, 6),
(1, 5, 10)
]
c = 1
expected = [float('inf'), 0, 3, 2, 3, 9]
result = shortest_paths(n, edges, c)
assert result == expected
def test_travel_... | [
{
"docstring": "Computes the shortest paths from the source node c to all other nodes using Dijkstra's algorithm.\n\nParameters:\nn (int): Number of nodes (cities)\nedges (List[Tuple[int, int, int]]): List of edges represented as (u, v, t) tuples\nc (int): The source node (capital city)\n\nReturns:\nList[int]: ... | [
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, graph, start):\n \"\"\"\n Implements Dijkstra's algorithm to find the shortest paths from `start` to all other cities.\n \... | trial_gpt4o_1 | {
"original_instruction": "The Kingdom of Wasabia is known for its elaborate network of canals and boats used for transportation. The canals can be represented as a directed graph with $n$ cities (nodes) and $m$ canals (edges), each having a certain travel time. \n\nOne day, the Queen of Wasabia wants to know if it's... | 0.717588 | Taco_20281 | C | [
"shortest_paths",
"travel_queries"
] | 2 | [
[
"travel_queries",
"shortest_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a1ab8cec294ac110d82efedd2c5e1665b8323aed | 11d873f036e9dfac72425f33928b3ad0cb46da80 | |||
v1.0 | complete | Taco | Taco_21044_C | MOD = 10**9 + 7
def mod_factorial(n, mod):
"""Computes factorial of n modulo mod."""
if n == 0:
return 1
result = 1
for i in range(2, n+1):
result = (result * i) % mod
return result
def mod_comb(n, k, mod):
"""Computes the combination C(n, k) modulo mod."""
if k > n:
... | MOD = 10**9 + 7
def mod_factorial(n, mod):
if n == 0:
return 1
result = 1
for i in range(2, n+1):
result = (result * i) % mod
return result
def mod_comb(n, k, mod):
if k > n:
return 0
numerator = mod_factorial(n, mod)
denominator = (mod_factorial(k, mod) * mod_facto... | from solution import number_of_ways
def test_example():
assert number_of_ways(5, 3) == 60
def test_minimum_values():
assert number_of_ways(2, 2) == 2
def test_large_values():
# The specific output should be checked with an independent tool, such as a mathematical software.
assert number_of_ways(20000... | [
{
"docstring": null,
"function_declaration": "def mod_factorial(n, mod):",
"function_name": "mod_factorial",
"parameter_list": "(n, mod)"
},
{
"docstring": null,
"function_declaration": "def mod_comb(n, k, mod):",
"function_name": "mod_comb",
"parameter_list": "(n, k, mod)"
},
... | [
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": "MOD = 10**9 + 7\n\ndef comb(n, k):\n \"\"\" Helper function to calculate nCk % MOD \"\"\"\n if k > n:\n return 0\n if k == 0 or k == n:\n re... | trial_gpt4o_1 | {
"original_instruction": "John is planning his vacation trip and is fascinated by different routes cities can offer. There are N cities, numbered from 1 to N, and each pair of cities has a direct route between them. He wants to visit exactly K different cities during his trip. Wanderlust that he is, he wants to know... | 0.615199 | Taco_21044 | C | [
"mod_factorial",
"mod_comb",
"number_of_ways"
] | 3 | [
[
"mod_comb",
"mod_factorial"
],
[
"number_of_ways",
"mod_comb"
],
[
"number_of_ways",
"mod_factorial"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 755a01829e2d8418c9a86bd02d6f734538954326 | a1b9ac0206899ad79cfb22d8149fbc337afd676f | |||
v1.0 | complete | Taco | Taco_20874_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
node_dict = {}
for value, left, right in nodes:
if value not in node_dict:
node_dict[value] = TreeNode(value)
if left != -1:
... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
node_dict = {}
for value, left, right in nodes:
if value not in node_dict:
node_dict[value] = TreeNode(value)
if left != -1:
... | import pytest
from solution import find_longest_increasing_path_length
def test_example_case():
tree_nodes = [(10, 5, 20), (5, -1, -1), (20, 15, 30), (15, -1, -1), (30, -1, -1)]
assert find_longest_increasing_path_length(tree_nodes) == 3
def test_single_node_tree():
tree_nodes = [(1, -1, -1)]
assert f... | [] | [
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_2 | {
"original_instruction": "Given a binary tree, where each node contains an integer value, implement a function to determine the longest path of nodes that form a strictly increasing sequence from the root to any leaf. Your function should return the length of this longest increasing path. If there are multiple such ... | 0.573009 | Taco_20874 | C | [
"build_tree",
"longest_increasing_path_length",
"find_longest_increasing_path_length"
] | 3 | [
[
"find_longest_increasing_path_length",
"build_tree"
],
[
"find_longest_increasing_path_length",
"longest_increasing_path_length"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2b300d3b49cf42f5116f426c0dfc5a18fb36da7f | 20a9c9f047d4c87d9883834d203e66413569abce | |||
v1.0 | complete | Taco | Taco_20943_C | def num_islands(grid):
""" Computes the number of distinct islands in the given 2D grid.
Island is defined as a group of '1's connected 4-directionally (horizontal or vertical).
Two islands are distinct if they are not connected.
Args:
grid: List of List of str - 2D grid representing a map wher... | def num_islands(grid):
if not grid:
return 0
rows = len(grid)
cols = len(grid[0])
visited = set()
def dfs(r, c):
if (r < 0 or r >= rows or c < 0 or c >= cols or
grid[r][c] == '0' or (r, c) in visited):
return
visited.add((r, c))
dfs(r + 1, c)... | from solution import count_islands
def test_count_islands():
input_str = "11110\n11010\n11000\n00000\n\n11000\n11000\n00100\n00011\n\n"
assert count_islands(input_str) == [1, 3]
def test_single_island():
input_str = "111\n111\n111\n\n"
assert count_islands(input_str) == [1]
def test_no_island():
... | [
{
"docstring": null,
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_str)"
},
... | [
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 num_islands(grid):\n if not grid:\n return 0\n\n rows = len(grid)\n cols = len(grid[0])\n visited = set()\n\n def dfs(r, c):\n if ... | trial_gpt4o_0 | {
"original_instruction": "You are given a 2D grid representing a map where '1' represents land and '0' represents water. Your objective is to compute the number of distinct islands in the grid.\n\nAn island is defined as a group of '1's connected 4-directionally (horizontal or vertical). Two islands are distinct if ... | 0.530985 | Taco_20943 | C | [
"num_islands",
"parse_input",
"count_islands"
] | 3 | [
[
"count_islands",
"num_islands"
],
[
"count_islands",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | c46514caae97f1179870472d87462b4a90482046 | 2080b994d902fe4a88c2e52db6764132d73b6a92 | |||
v1.0 | complete | Taco | Taco_21278_C | def filter_primes(int_list):
""" Create a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. If the original list is empty or contains no prime numbers, return an empty list.
>>> filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10])
[2, 3, 5, 7]
... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def f... | from solution import filter_primes
def test_filter_primes_with_primes():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 10]) == []
def test_filter_primes_empty_list():
assert filter_primes([]) == []
def test_filt... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Filters and returns a list of prime numbers from the given list of integers.",
"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 is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_1 | {
"original_instruction": "Create a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. If the original list is empty or contains no prime numbers, return an empty list. Use the function name `filter_primes`.\n\n### Example\n```python\nfilter_prime... | 0.650438 | Taco_21278 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f550baa01b40b2d15ae48ef75e085415f9e7791e | 61f398764c59bfa9a836a030d9809ce97033e246 | |||
v1.0 | complete | Taco | Taco_21225_C | def min_swaps_to_rearrange(n: int, current: str, desired: str) -> int:
""" Calculate the minimum number of switches needed to rearrange friends in a circle dance to achieve the desired arrangement.
Args:
n (int): The number of friends.
current (str): The current arrangement of friends.
... | def count_inversions(arr):
if len(arr) < 2:
return arr, 0
mid = len(arr) // 2
left, left_inv = count_inversions(arr[:mid])
right, right_inv = count_inversions(arr[mid:])
merged, split_inv = merge_and_count(left, right)
return merged, left_inv + right_inv + split_inv
def merge_and_coun... | import pytest
from solution import min_swaps_to_rearrange
def test_example_case():
assert min_swaps_to_rearrange(6, "abcdef", "fabcde") == 5
def test_no_swaps_needed():
assert min_swaps_to_rearrange(4, "abcd", "abcd") == 0
def test_single_swap():
assert min_swaps_to_rearrange(2, "ab", "ba") == 1
def tes... | [
{
"docstring": null,
"function_declaration": "def count_inversions(arr):",
"function_name": "count_inversions",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def merge_and_count(left, right):",
"function_name": "merge_and_count",
"parameter_list": "(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 min_switches(n, current, desired):\n \"\"\"\n Returns the minimum number of switches needed to achieve the desired arrangement.\n \"\"\"\n def get_... | trial_gpt4o_8 | {
"original_instruction": "Anya is participating in a circle dance with her friends. The dance starts with each friend positioned in a circle. Each friend can either stay in their current position or switch places with one of the adjacent friends (the friends next to them in the circle). Anya wants to know the minimu... | 0.564234 | Taco_21225 | C | [
"count_inversions",
"merge_and_count",
"min_swaps_to_rearrange"
] | 3 | [
[
"count_inversions",
"merge_and_count"
],
[
"min_swaps_to_rearrange",
"count_inversions"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5a839a925ef5261e21ba087c6a8a05d9a6d5df18 | c3416f28b2f396d45f8351d0496ff151b22225f2 | |||
v1.0 | complete | Taco | Taco_21184_C | def is_prime(n: int) -> bool:
"""
Helper function to check if a number is a prime number.
"""
def filter_primes(numbers: List[int]) -> List[int]:
"""
Returns a list containing only the prime numbers from the input list.
>>> filter_primes([10, 15, 3, 7, 17, 22, 33])
[3, 7, 17]
>>> filte... | def is_prime(n):
"""
Helper function to check if a number is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(numbers):
"""
Returns a list containing only the prime numbe... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([10, 15, 3, 7, 17, 22, 33]) == [3, 7, 17]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 10]) == []
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5, 7, 11]... | [
{
"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": "Returns a list containing only the prime numbers from the input list.",
"function_declaration": "d... | [
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 Check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ... | trial_gpt4o_1 | {
"original_instruction": "Write a Python function that takes a list of integers as input and returns a new list containing only the prime numbers from the input list.\n\nInput Format\nA list of integers.\n\nOutput Format\nA list of integers containing only the prime numbers from the input list.\n\nSAMPLE INPUT\n[10,... | 0.751485 | Taco_21184 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a446e3274add4a5646697b35f4460b0856556832 | c35b819be72938d170081b9e6a26c22044c4a6e9 | |||
v1.0 | complete | Taco | Taco_21222_C | def solve(input_str):
""" Determines if it is possible to transport all K boxes to the final destination without exceeding any station's capacity.
Args:
input_str (str): The input string containing test cases.
Returns:
str: "YES" if possible for each test case, else "NO".
Example:... | def can_transport_boxes(t, test_cases):
results = []
for test_case in test_cases:
N, K = test_case['N'], test_case['K']
boxes = test_case['boxes']
capacities = test_case['capacities']
remaining_boxes = K
can_transport = True
for i in range(N):
... | def test_can_transport_boxes():
input_str = "2\n3 4\n3 2 1\n5 5 5\n4 10\n2 4 6 8\n10 10 10 10\n"
expected_output = "YES\nNO"
assert solve(input_str) == expected_output
def test_edge_case_all_stations_barely_fit():
input_str = "1\n3 2\n2 3 4\n4 6 6\n"
expected_output = "YES"
assert solve(input_s... | [
{
"docstring": null,
"function_declaration": "def can_transport_boxes(t, test_cases):",
"function_name": "can_transport_boxes",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"para... | [
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 can_transport_boxes(T, cases):\n results = []\n \n for case in cases:\n N, K, boxes, capacities = case\n boxes_needed = K\n \n ... | trial_gpt4o_9 | {
"original_instruction": "A train moves along a straight line in a data center, transporting storage boxes between different sections. The train stops at exactly N stations positioned along this line. Each station can hold a particular number of boxes and has a storage capacity C. However, the station can never be o... | 0.620254 | Taco_21222 | C | [
"can_transport_boxes",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"can_transport_boxes"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | aeb6704dd38f7650cbb3c9d42d7892721e5ff81a | 047a472279ca72a10bdb83177188b4b4b9224d2e | |||
v1.0 | complete | Taco | Taco_21092_C | def parse_input(input_str: str) -> List[Tuple[int, List[int]]]:
"""
Parse the input string and return a list of test cases.
Each test case is a tuple containing an integer N and a list of N integers.
"""
pass
def sort_even_before_odd(test_cases: List[Tuple[int, List[int]]]) -> List[List[int]]:
... | def sort_even_before_odd(test_cases):
results = []
for t in range(len(test_cases)):
N, array = test_cases[t]
even_numbers = sorted([x for x in array if x % 2 == 0])
odd_numbers = sorted([x for x in array if x % 2 != 0])
sorted_array = even_numbers + odd_numbers
results.ap... | def test_parse_input():
input_str = "2\n5\n3 1 2 7 4\n4\n-3 -5 -2 -8\n"
expected = [
(5, [3, 1, 2, 7, 4]),
(4, [-3, -5, -2, -8])
]
assert parse_input(input_str) == expected
def test_sort_even_before_odd():
test_cases = [
(5, [3, 1, 2, 7, 4]),
(4, [-3, -5, -2, -8])
... | [
{
"docstring": null,
"function_declaration": "def sort_even_before_odd(test_cases):",
"function_name": "sort_even_before_odd",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"paramete... | [
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 custom_sort(arr):\n \"\"\"\n Sorts the given list such that all even numbers appear before any odd number,\n and both even and odd numbers are sorted ... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, you are required to sort the list but in a specific way. Sort the list such that all even numbers appear before any odd number, and both even and odd numbers are sorted in ascending order within their respective groups.\n\nTry to solve this problem with a time comp... | 0.708336 | Taco_21092 | C | [
"sort_even_before_odd",
"parse_input",
"format_output",
"solution"
] | 4 | [
[
"solution",
"format_output"
],
[
"solution",
"parse_input"
],
[
"solution",
"sort_even_before_odd"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | 8580f111fed8310f456851401a8aa985183eb656 | 49123425336e54858bcaa40107c09cb20a4d58f7 | |||
v1.0 | complete | Taco | Taco_21162_C | def max_subarray_sum(arr):
""" Calculate the maximum sum of elements in a contiguous sub-array within the given array `arr`.
"""
pass
def process_test_cases(T, test_cases):
""" Process the test cases and calculate the maximum sum of a contiguous sub-array for each sub-array.
>>> T = 2
>>> test_... | def max_subarray_sum(arr):
current_max = global_max = arr[0]
for num in arr[1:]:
current_max = max(num, current_max + num)
global_max = max(global_max, current_max)
return global_max
def process_test_cases(T, test_cases):
results = []
for case_idx, case in enumerate(test_cases):
... | from solution import solution
def test_sample_input_1():
input_str = """2
2
9 -2 1 -3 4 -1 2 1 -5 4
3 1 2 3
1
4 1 -1 -1 1"""
expected_output = "Case #1: 6 6\nCase #2: 1"
assert solution(input_str) == expected_output
def test_large_negative_numbers():
input_str = """1
1
5 -10 -20 -30 -40 -50"""
exp... | [
{
"docstring": null,
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(T, test_cases):",
"function_name": "process_test_cases",
"parameter_li... | [
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 max_subarray_sum(arr):\n \"\"\"\n Returns the maximum sum of a contiguous sub-array within the given array.\n \"\"\"\n max_sum = arr[0]\n curren... | trial_gpt4o_1 | {
"original_instruction": "A large data set has been divided into multiple smaller sub-arrays, and each sub-array might have a different length. You are tasked with calculating the maximum sum of elements in a contiguous sub-array within each of the given sub-arrays. This problem is essentially a variation of the cla... | 0.716663 | Taco_21162 | C | [
"max_subarray_sum",
"process_test_cases",
"solution_input_parser",
"solution"
] | 4 | [
[
"process_test_cases",
"max_subarray_sum"
],
[
"solution",
"process_test_cases"
],
[
"solution",
"solution_input_parser"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | a69bfec83ea6b1e26470bf45ba0fae9ec2c53d03 | 09966b78b0e2fbcfd0c8f25d9b97fab06e3bc7e9 | |||
v1.0 | complete | Taco | Taco_21181_C | def count_knight_moves(position):
"""
Given a position on a chessboard, returns the number of valid moves a knight can make.
>>> count_knight_moves("d4")
8
>>> count_knight_moves("a1")
2
>>> count_knight_moves("h8")
2
>>> count_knight_moves("b2")
4
>>> count_knight_moves... | def count_knight_moves(position):
"""
Given a position on a chessboard, returns the number of valid moves a knight can make.
"""
column, row = position
column = ord(column) - ord('a') + 1 # convert column letter to number
row = int(row)
possible_moves = [
(2, 1), (2, -1), (-2, 1), ... | import pytest
from solution import count_knight_moves, process_positions
def test_count_knight_moves_center():
assert count_knight_moves("d4") == 8
def test_count_knight_moves_corner():
assert count_knight_moves("a1") == 2
assert count_knight_moves("h8") == 2
def test_count_knight_moves_edge():
asser... | [
{
"docstring": "Given a position on a chessboard, returns the number of valid moves a knight can make.",
"function_declaration": "def count_knight_moves(position):",
"function_name": "count_knight_moves",
"parameter_list": "(position)"
},
{
"docstring": "Processes multiple positions input an... | [
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 knight_moves(position):\n \"\"\"\n Given a position on a chessboard like 'a1', this function will return the number of valid moves a knight can make.\n ... | trial_gpt4o_2 | {
"original_instruction": "Yuki and Ken are avid chess players who enjoy creating new challenges for each other. Recently, they’ve devised a puzzle where given a certain position of a knight on a chessboard, they calculate how many legal moves it has. A knight moves in an \"L\" shape: two squares in one direction and... | 0.555125 | Taco_21181 | C | [
"count_knight_moves",
"process_positions"
] | 2 | [
[
"process_positions",
"count_knight_moves"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01a5ea1a87a959e6f5d0b2e7e6dfd4827cb1f23e | 0faf13a30122b53cfbaf30fcad5e34604bc5b1fe | |||
v1.0 | complete | Taco | Taco_21369_C | def findLargestBlock(n: int, m: int, grid: List[List[int]]) -> int:
"""Find the area of the largest continuous rectangular block of '1's in the given grid.
>>> findLargestBlock(3, 4, [
>>> [0, 1, 1, 0],
>>> [1, 1, 1, 0],
>>> [0, 1, 1, 1]
>>> ]) 6
>>> findLargestBlock(1,... | def maximalRectangle(matrix):
if not matrix or not matrix[0]:
return 0
n, m = len(matrix), len(matrix[0])
max_area = 0
height = [0] * m
left = [0] * m
right = [m] * m
for i in range(n):
cur_left, cur_right = 0, m
for j in range(m):
if matrix[... | from solution import findLargestBlock
def test_example_case():
n, m = 3, 4
grid = [
[0, 1, 1, 0],
[1, 1, 1, 0],
[0, 1, 1, 1]
]
assert findLargestBlock(n, m, grid) == 6
def test_single_cell():
n, m = 1, 1
grid = [
[1]
]
assert findLargestBlock(n, m, grid)... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def findLargestBlock(n, m, grid):",
"function_name": "findLargestBlock",
"parameter_lis... | [
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 maximalRectangle(matrix):\n if not matrix or not matrix[0]:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n max_area = 0\n heigh... | trial_gpt4o_0 | {
"original_instruction": "Little Timmy loves playing a particular game. In this game, he is given a rectangular grid of size `n x m`, and each cell in the grid contains either a '0' or a '1'. The objective of the game is to find the largest continuous rectangular block (submatrix) of '1's in the grid.\n\nFor example... | 0.667317 | Taco_21369 | C | [
"maximalRectangle",
"findLargestBlock"
] | 2 | [
[
"findLargestBlock",
"maximalRectangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c0493e5aa9b244816740507803487c55ececc25d | 15391b9e1e5bdb3c3c8f033361a598a284c72fc1 | |||
v1.0 | complete | Taco | Taco_21530_C | def is_magic_square(grid):
""" Check if the given 3x3 grid has Magic Number Symmetry.
>>> is_magic_square([[8, 1, 6], [3, 5, 7], [4, 9, 2]])
True
>>> is_magic_square([[8, 1, 6], [3, 5, 7], [4, 2, 9]])
False
"""
def magic_number_symmetry():
""" Determine if it is possible to fill a 3x3 g... | def is_magic_square(grid):
# Check rows
sum_list = [sum(row) for row in grid]
# Check columns
for i in range(3):
sum_list.append(sum(grid[j][i] for j in range(3)))
# Check diagonals
sum_list.append(grid[0][0] + grid[1][1] + grid[2][2])
sum_list.append(grid[0][2] + grid[1][1... | from solution import is_magic_square, magic_number_symmetry
def test_is_magic_square_valid():
grid = [
[8, 1, 6],
[3, 5, 7],
[4, 9, 2]
]
assert is_magic_square(grid) == True
def test_is_magic_square_invalid():
grid = [
[8, 1, 6],
[3, 5, 7],
[4, 2, 9]
... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(grid):",
"function_name": "is_magic_square",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def magic_number_symmetry():",
"function_name": "magic_number_symmetry",
"parameter_list": "(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_square(grid):\n # Check rows\n sum_list = [sum(row) for row in grid]\n \n # Check columns\n for i in range(3):\n sum_list.append... | trial_gpt4o_0 | {
"original_instruction": "Allie and Blake have been working on a group project that involves creating a 3x3 square grid. The project entails placing integers in each cell of the grid in such a way that the entire grid retains a specific property called \"Magic Number Symmetry.\"\n\nThe grid is considered to have Mag... | 0.683271 | Taco_21530 | C | [
"is_magic_square",
"magic_number_symmetry"
] | 2 | [
[
"magic_number_symmetry",
"is_magic_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e95cfe64e4e019f99f6bf05137259c904b695a1c | d21c6c22f3f33b17e6eb824f20d6ad83bd200591 | |||
v1.0 | complete | Taco | Taco_21281_C | def build_tree(preorder):
""" Build a tree from its preorder traversal. """
# Helper function to build the tree
def helper(index):
if index[0] >= len(preorder) or preorder[index[0]] == -1:
index[0] += 1
return None
node = {'val': preorder[index[0]], 'left': None, 'rig... | def build_tree(preorder):
def helper(index):
if index[0] >= len(preorder) or preorder[index[0]] == -1:
index[0] += 1
return None
node = {'val': preorder[index[0]], 'left': None, 'right': None}
index[0] += 1
node['left'] = helper(index)
node['right'] = ... | def test_binary_tree_depth_comparator():
test_cases = [
([[1, 2, -1, -1, 3, -1, -1], [1, 3, -1, -1, 2, -1, -1]], ["Yes"]),
([[1, 2, -1, 5, -1, 4, -1, -1, 3, -1, -1], [1, 3, -1, -1, 2, 5, -1, -1, 4, -1, -1]], ["No"]),
([[1, 2, -1, -1, 3, 4, -1, -1, -1], [1, 3, 4, -1, -1, -1, 2, -1, -1]], ["Ye... | [
{
"docstring": null,
"function_declaration": "def build_tree(preorder):",
"function_name": "build_tree",
"parameter_list": "(preorder)"
},
{
"docstring": null,
"function_declaration": "def same_structure(tree1, tree2):",
"function_name": "same_structure",
"parameter_list": "(tree... | [
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 build_tree(preorder):\n def helper(index):\n if index[0] >= len(preorder) or preorder[index[0]] == -1:\n index[0] += 1\n return... | trial_gpt4o_0 | {
"original_instruction": "Binary Tree Depth Comparator\n\nGiven two binary trees, your task is to determine if the two trees have the same structure. In other words, if one tree can be transformed into the other by swapping any subtree (left or right) at any level, the two trees are considered to have the same struc... | 0.571378 | Taco_21281 | C | [
"build_tree",
"same_structure",
"binary_tree_depth_comparator"
] | 3 | [
[
"binary_tree_depth_comparator",
"build_tree"
],
[
"binary_tree_depth_comparator",
"same_structure"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | dd9018287733f652badd7bb346074157897a5a3d | 7a4a161ee564d91c2c6bc13e590001f6c2724939 | |||
v1.0 | complete | Taco | Taco_21465_C | def sum_of_digits(n: int) -> int:
"""
Returns the sum of the digits of the integer n.
>>> sum_of_digits(56)
11
>>> sum_of_digits(1001)
2
"""
# Your code here
def largest_digit_sum(arr: List[int]) -> int:
"""
Returns the integer with the largest sum of digits from the array.
... | def sum_of_digits(n):
"""
Returns the sum of the digits of the integer n.
"""
return sum(int(digit) for digit in str(n))
def largest_digit_sum(arr):
"""
Returns the integer with the largest sum of digits from the array.
In case of a tie, returns the smallest integer among them.
"""
... | import pytest
from solution import sum_of_digits, largest_digit_sum, process_test_cases
# Tests for sum_of_digits function
def test_sum_of_digits_single_digit():
assert sum_of_digits(5) == 5
def test_sum_of_digits_multiple_digits():
assert sum_of_digits(56) == 11
def test_sum_of_digits_with_zeros():
asse... | [
{
"docstring": "Returns the sum of the digits of the integer n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns the integer with the largest sum of digits from the array.\nIn case of a tie, returns the sm... | [
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 sum_of_digits(number):\n \"\"\"\n Returns the sum of the digits of the given number.\n \"\"\"\n return sum(int(digit) for digit in str(number))\n\n... | trial_gpt4o_6 | {
"original_instruction": "You are given N non-negative integers in an array. Your task is to find the sum of the digits of each integer and then output the integer that has the largest sum of digits. If there is a tie, return the smallest integer among them.\n\n------ Input Format ------\n\nThe first line contains a... | 0.647492 | Taco_21465 | C | [
"sum_of_digits",
"largest_digit_sum",
"process_test_cases"
] | 3 | [
[
"largest_digit_sum",
"sum_of_digits"
],
[
"process_test_cases",
"largest_digit_sum"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | a3a955a94076830f59efc6b6819f3c8209985da1 | 9c7b780c6fe95108a844ba9797eb88a1b5c4182e | |||
v1.0 | complete | Taco | Taco_21626_C | def pair_sum_exists(test_cases):
"""
For each test case, determine if there exists a pair of elements
whose sum is equal to the given value.
"""
def parse_input(input_str):
"""
Parses the input string to extract the test cases.
"""
def pair_sum_exists_from_input(input_str):
"""
Ta... | def pair_sum_exists(test_cases):
"""
For each test case, determine if there exists a pair of elements
whose sum is equal to the given value.
"""
results = []
for case in test_cases:
N, elements, K = case
found = False
seen = set()
for num in elements:
... | def test_pair_sum_exists():
input_str = "2\n5\n1 4 45 6 10 8\n16\n4\n1 2 3 9\n8"
expected_output = ["YES", "NO"]
assert pair_sum_exists_from_input(input_str) == expected_output
def test_pair_sum_not_exists():
input_str = "1\n3\n1 2 4\n7"
expected_output = ["NO"]
assert pair_sum_exists_from_inpu... | [
{
"docstring": "For each test case, determine if there exists a pair of elements \nwhose sum is equal to the given value.",
"function_declaration": "def pair_sum_exists(test_cases):",
"function_name": "pair_sum_exists",
"parameter_list": "(test_cases)"
},
{
"docstring": "Parses the input str... | [
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 has_pair_with_sum(test_cases):\n \"\"\"\n For each test case, find if there is a pair of integers\n in the list whose sum is equal to the given value.... | trial_gpt4o_2 | {
"original_instruction": "Given a list of distinct integers, you need to determine if there exists a pair of elements whose sum is equal to a given value. If such a pair exists, print \"YES\", otherwise print \"NO\".\n\nInput:-\nThe first line of input contains an integer T, the number of test cases. Each test case ... | 0.706042 | Taco_21626 | C | [
"pair_sum_exists",
"parse_input",
"pair_sum_exists_from_input"
] | 3 | [
[
"pair_sum_exists_from_input",
"pair_sum_exists"
],
[
"pair_sum_exists_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 9296567fe17a5b25e906b6f4897e0f466c3abfb3 | 42eeacc766f2a749b0834b864727b850c4bccb95 | |||
v1.0 | complete | Taco | Taco_21558_C | from typing import List
def is_palindrome(s: str) -> bool:
""" Check if the given string is a palindrome.
>>> is_palindrome("a")
True
>>> is_palindrome("aba")
True
>>> is_palindrome("abca")
False
>>> is_palindrome("")
True
"""
pass
def determine_winner(s: str) -> str:
"... | def is_palindrome(s):
return s == s[::-1]
def determine_winner(s):
if is_palindrome(s):
return "Alice"
else:
return "Bob"
def main(t, cases):
results = []
for s in cases:
results.append(determine_winner(s))
return results | from solution import is_palindrome, determine_winner, main
def test_is_palindrome():
assert is_palindrome("a") == True
assert is_palindrome("aba") == True
assert is_palindrome("abca") == False
assert is_palindrome("") == True
def test_determine_winner():
assert determine_winner("a") == "Alice"
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def determine_winner(s):",
"function_name": "determine_winner",
"parameter_list": "(s)"
},
{
"d... | [
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_palindrome(s):\n return s == s[::-1]\n\ndef determine_winner(S):\n if is_palindrome(S):\n return \"Alice\"\n elif len(S) % 2 == 0:\n ... | trial_gpt4o_4 | {
"original_instruction": "Read problems statements in Mandarin Chinese, Russian, and Vietnamese as well.\n\nAlice and Bob are playing a game with a string S consisting of lowercase English letters. Players take turns, with Alice going first. \n\nOn each turn, the player selects a contiguous substring of the current ... | 0.673883 | Taco_21558 | C | [
"is_palindrome",
"determine_winner",
"main"
] | 3 | [
[
"determine_winner",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60228b804b0e19a67a4310f0b8ec2c4923f0ccb7 | 1d1b173a023fbbc4fb4d4a8ca3db44c8b2c9c7b8 | |||
v1.0 | complete | Taco | Taco_21721_C | def solve_puzzle_game(N: int, M: int, grid_lines: List[str]) -> int:
""" Determine the minimum number of moves required for the player to reach the bottom-right corner of the grid from the top-left corner.
>>> solve_puzzle_game(4, 4, ["....", ".#..", "..#.", "...."])
6
>>> solve_puzzle_game(4, 4, [... | from collections import deque
def min_moves_to_reach_end(N, M, grid):
# Directions for moving up, down, left, right
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# BFS queue initialization
queue = deque([(0, 0, 0)]) # (row, col, distance)
visited = set((0, 0))
while queue:
x, y... | from solution import solve_puzzle_game
def test_minimum_moves_possible_path():
N, M = 4, 4
grid = [
"....",
".#..",
"..#.",
"...."
]
assert solve_puzzle_game(N, M, grid) == 6
def test_no_possible_path_due_to_obstacle():
N, M = 4, 4
grid = [
"....",
... | [
{
"docstring": null,
"function_declaration": "def min_moves_to_reach_end(N, M, grid):",
"function_name": "min_moves_to_reach_end",
"parameter_list": "(N, M, grid)"
},
{
"docstring": null,
"function_declaration": "def solve_puzzle_game(N, M, grid_lines):",
"function_name": "solve_puzz... | [
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 minimum_moves(N, M, grid):\n # Directions for moving up, down, left, right\n directions = [(-1, 0), (1, 0), (0, -1), (0,... | trial_gpt4o_2 | {
"original_instruction": "Maxmillian is a game developer working on a new puzzle game. The game board is a grid of size N x M, and each cell in the grid can either be empty (represented by '.') or contain an obstacle (represented by '#'). The player starts at the top-left corner of the grid (1, 1) and wants to reach... | 0.702851 | Taco_21721 | C | [
"min_moves_to_reach_end",
"solve_puzzle_game"
] | 2 | [
[
"solve_puzzle_game",
"min_moves_to_reach_end"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45e20c6ef9af4ce3636ec558bc18c71a363603ee | 920e59ca48e9959d623aaba6b56286d1a61f33da | |||
v1.0 | complete | Taco | Taco_21576_C | def is_prime(num):
"""
Checks if a number is prime.
"""
pass
def arrange_coins(n, coins):
"""
Arranges the coins into prime and non-prime groups,
sorts the prime group in descending order,
and sorts the non-prime group in ascending order.
"""
pass
# Unit Tests
def test_is_prime... | def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
def arrange_coins(n, ... | from solution import is_prime, arrange_coins
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(17)
def test_arrange_coins():
assert arrange_coins(8, [3, 11, 4, 7, 8, 10, 2, ... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Arranges the coins into prime and non-prime groups,\nsorts the prime group in descending order,\nand sorts the non-prime grou... | [
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 Function to determine if a number is prime.\n \n Args:\n num: int - The number to check.\n\n Returns:\n bool - T... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nAlex has a collection of n unique coins, and each coin has a distinct positive integer value. He likes arranging his coins in a particular way. Specifically, he wants to separate them into two groups such that:\n\n1. The first group consists of coins whose values are prime number... | 0.614941 | Taco_21576 | C | [
"is_prime",
"arrange_coins"
] | 2 | [
[
"arrange_coins",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48ec7aa672dc0c24cd1d92d8a4a81b7b2aeca7a4 | c560c35ec5d9956b87eb509da88262d639966f8f | |||
v1.0 | complete | Taco | Taco_21810_C | def handle_queries(input_data: str) -> list:
""" Handle queries on a balanced binary search tree to either update a node's value or find the minimum value in the path between two nodes.
Args:
input_data (str): A multi-line string containing the number of nodes, the in-order traversal of the tree, the number... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_bst(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert_bst(root.left, value)
else:
root.right = insert... | def test_handle_queries():
input_data = "5\n10 5 3 8 2\n3\n2 3 10\n1 8 7\n2 2 5"
expected_output = [3, 2]
assert handle_queries(input_data) == expected_output
def test_single_update():
input_data = "5\n10 5 3 8 2\n1\n1 8 7"
expected_output = []
assert handle_queries(input_data) == expected_outp... | [] | [
0,
0,
0,
0,
0,
1,
1,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root i... | trial_gpt4o_9 | {
"original_instruction": "Alex is particularly fond of trees, especially binary trees. He enjoys the challenge of finding the minimum value in the path between two nodes in a binary tree. Recently, he encountered a large balanced binary search tree and posed the following problem to you:\n\nGiven a balanced binary s... | 0.553292 | Taco_21810 | C | [
"insert_bst",
"build_bst",
"find_node",
"lca_bst",
"min_in_path",
"min_from_node_to_value",
"min_path_util",
"handle_queries"
] | 8 | [
[
"build_bst",
"insert_bst"
],
[
"handle_queries",
"build_bst"
],
[
"handle_queries",
"find_node"
],
[
"handle_queries",
"min_in_path"
],
[
"min_in_path",
"lca_bst"
],
[
"min_in_path",
"min_path_util"
],
[
"min_path_util",
"min_from_nod... | 7 | [
"handle_queries"
] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 94e99d5ade2e88faf3f87bda7ed997c36c37e60c | 43a479e469b2b795e0101c7ca8e833f0262334c7 | |||
v1.0 | complete | Taco | Taco_22000_C | def look_and_say(n: int) -> str:
""" Generate the nth term in the 'look-and-say' series.
>>> look_and_say(1) "1"
>>> look_and_say(5) "111221"
""" | def next_in_sequence(s):
result = []
i = 0
while i < len(s):
count = 1
while i + 1 < len(s) and s[i] == s[i + 1]:
i += 1
count += 1
result.append(f"{count}{s[i]}")
i += 1
return ''.join(result)
def look_and_say(n):
if n == 1:
return "1... | from solution import look_and_say
def test_look_and_say_1():
assert look_and_say(1) == "1"
def test_look_and_say_2():
assert look_and_say(2) == "11"
def test_look_and_say_3():
assert look_and_say(3) == "21"
def test_look_and_say_4():
assert look_and_say(4) == "1211"
def test_look_and_say_5():
a... | [
{
"docstring": null,
"function_declaration": "def next_in_sequence(s):",
"function_name": "next_in_sequence",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def look_and_say(n):",
"function_name": "look_and_say",
"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": "def look_and_say(n):\n \"\"\"\n Returns the nth term in the look-and-say sequence.\n \"\"\"\n if n == 1:\n return \"1\"\n \n def next_sequ... | trial_gpt4o_1 | {
"original_instruction": "Create a function that takes an integer n and generates the nth sequence in the \"look-and-say\" series. The \"look-and-say\" series starts with \"1\" and each subsequent term is generated by describing the previous term's digits.\n\nFor example, starting with 1:\n- 1 is read as \"one 1\" o... | 0.618042 | Taco_22000 | C | [
"next_in_sequence",
"look_and_say"
] | 2 | [
[
"look_and_say",
"next_in_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f62c406a0c3a8ffe146dd69d756031d4d019cf44 | 976c2daeeafa171dc602569201f936ed93742e44 | |||
v1.0 | complete | Taco | Taco_21668_C | def minimum_cost_to_connect_pois(n: int, paths: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum total cost required to construct a network of paths that connect all POIs with no cycles.
Args:
n : int : Number of POIs
paths : List[Tuple[int, int, int]] : List of potential paths wi... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif r... | from solution import minimum_cost_to_connect_pois
def test_minimum_cost_example1():
n = 4
paths = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)]
assert minimum_cost_to_connect_pois(n, paths) == 6
def test_minimum_cost_example2():
n = 3
paths = [(1, 2, 1)]
assert minimum_cost_to_connec... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
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_minimum_cost(n, m, edges):\n \"\"\"\n This function uses Kruskal's algorithm to find the minimum cost to construct a network of paths satisfying the... | trial_gpt4o_2 | {
"original_instruction": "The mayor of a small town is planning a new park, and she wants to ensure that the park design is both beautiful and functional. One feature of the park will be a network of paths that connect all points of interest (POIs) directly, such as benches, fountains, and statues. Each path, howeve... | 0.619628 | Taco_21668 | C | [
"find",
"union",
"minimum_cost_to_connect_pois",
"main"
] | 4 | [
[
"minimum_cost_to_connect_pois",
"find"
],
[
"minimum_cost_to_connect_pois",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 748f39cff6e2746f7fd706d238d407dbddb4f35f | 75579f4042ac718285437cd512b5b302a3274801 | |||
v1.0 | complete | Taco | Taco_21838_C | from typing import List
def superhero_grid_path(n: int, m: int, grid: List[str], sx: int, sy: int, tx: int, ty: int) -> int:
"""Find the minimum number of moves the superhero needs to reach the target intersection in a grid city.
The superhero can move up, down, left, or right but cannot pass through buildings... | from collections import deque
def min_moves_to_target(grid, n, m, sx, sy, tx, ty):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'
# Convert 1-based coordinates to 0-based
start = (sx - ... | from solution import superhero_grid_path
def test_case_1():
grid = [
"....",
"..#.",
"....",
".#.."
]
assert superhero_grid_path(4, 4, grid, 1, 1, 4, 4) == 6
def test_case_2():
grid = [
"###",
"#.#",
"###"
]
assert superhero_grid_path(3, ... | [
{
"docstring": null,
"function_declaration": "def min_moves_to_target(grid, n, m, sx, sy, tx, ty):",
"function_name": "min_moves_to_target",
"parameter_list": "(grid, n, m, sx, sy, tx, ty)"
},
{
"docstring": null,
"function_declaration": "def superhero_grid_path(n, m, grid, sx, sy, tx, t... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_moves_to_target(grid, n, m, sx, sy, tx, ty):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right\... | trial_gpt4o_0 | {
"original_instruction": "A superhero is in a grid city consisting of n × m intersections, where each intersection can either have a building (represented by '#') or be an open space (represented by '.'). The superhero starts at a given intersection (sx, sy) and needs to reach a target intersection (tx, ty) to stop ... | 0.648468 | Taco_21838 | C | [
"min_moves_to_target",
"superhero_grid_path"
] | 2 | [
[
"superhero_grid_path",
"min_moves_to_target"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | da6ea225969e894c45abfaf345fd6fc7f61a76b4 | 3a9be0f02928b9d8bf1154547b3e1de2da7cc21d | |||
v1.0 | complete | Taco | Taco_21612_C | def number_of_connected_groups(T: int, test_cases: List[Tuple[Tuple[int, int], List[Tuple[int, int]]]]) -> List[int]:
""" Determine the number of distinct connected groups of players given a list of test cases.
Args:
T (int): The number of test cases.
test_cases (List[Tuple[Tuple[int, int], List[Tu... | def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if xroot != yroot:
if rank[xroot] > rank[yroot]:
parent[yroot] = ... | from solution import number_of_connected_groups
def test_example_case_1():
T = 2
test_cases = [
[(5, 3), [(1, 2), (2, 3), (4, 5)]],
[(4, 2), [(1, 2), (3, 4)]]
]
assert number_of_connected_groups(T, test_cases) == [2, 2]
def test_no_connections():
T = 1
test_cases = [
[(... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, y):\n... | trial_gpt4o_0 | {
"original_instruction": "A gaming company is developing a new simulation game and needs some help with the logic to manage player interactions. In the game, players can form connections with one another, similar to friendships. The connections follow these rules:\n\n1. A player can initiate a connection with anothe... | 0.578386 | Taco_21612 | C | [
"find_parent",
"union",
"number_of_connected_groups"
] | 3 | [
[
"number_of_connected_groups",
"find_parent"
],
[
"number_of_connected_groups",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | e2cb3543cfd4b98566c9f5040fabc9bf952352c9 | e73b4711ea5c298590c887d9762cd951bb433139 | |||
v1.0 | complete | Taco | Taco_21513_C | from collections import defaultdict, deque
from typing import List, Tuple
def preprocess_tree(n: int, edges: List[Tuple[int, int]]) -> List[int]:
""" Preprocess the tree to find the parents of each node.
Args:
n (int): Number of nodes in the tree.
edges (List[Tuple[int, int]]): List of edges in th... | from collections import defaultdict, deque
def preprocess_tree(n, edges):
parents = [-1] * (n + 1)
children = defaultdict(list)
for u, v in edges:
children[u].append(v)
children[v].append(u)
def bfs(root):
queue = deque([root])
visited = [False] * (n + 1)
... | from solution import preprocess_tree, kth_ancestor, process_queries
def test_preprocess_tree():
n = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
expected_parents = [-1, -1, 1, 1, 2, 2]
assert preprocess_tree(n, edges) == expected_parents
def test_kth_ancestor():
parents = [-1, -1, 1, 1, 2, 2]
as... | [
{
"docstring": null,
"function_declaration": "def preprocess_tree(n, edges):",
"function_name": "preprocess_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def kth_ancestor(v, k, parents):",
"function_name": "kth_ancestor",
"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": "from collections import defaultdict, deque\n\ndef preprocess_tree(n, edges):\n parents = [-1] * (n + 1)\n children = defaultdict(list)\n \n for u, v in... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree with `n` nodes, each node having a unique value between `1` and `n`. The tree is rooted at node `1` and you are given `q` queries. In each query, you are given a node `v` and an integer `k`. Your task is to determine the `k`-th ancestor of the node `v`. If the `k`-th an... | 0.587729 | Taco_21513 | C | [
"preprocess_tree",
"kth_ancestor",
"process_queries"
] | 3 | [
[
"process_queries",
"kth_ancestor"
],
[
"process_queries",
"preprocess_tree"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 254685701271f0108d2b1753d56ce34dc0aab6f9 | 80e5a8ee57a7c5d6a8f019f17f5139e38623f7aa | |||
v1.0 | complete | Taco | Taco_21977_C | def is_prime(num):
"""
Check if the number is a prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# Your code here
def can_form_magical_sequence(arr):
"""
Determine if the array can be rearranged into a magical sequence.
>>> can_form_magical_sequence([4, 6, 8, ... | def is_prime(num):
"""
Check if the number is a prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
limit = int(num ** 0.5) + 1
for i in range(3, limit, 2):
if num % i == 0:
return False
return True
... | 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(8) == False
assert is_prime(11) == True
def test_can_form_magical_sequence():
assert can_form_magical_sequence([4, 6, 8, 9, 3]) == True
asser... | [
{
"docstring": "Check if the number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine if the array can be rearranged into a magical sequence.",
"function_declaration": "def can_form_magical_sequ... | [
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 if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_2 | {
"original_instruction": "Chef loves magical sequences of integers and has recently discovered an interest in prime numbers. He defines a magical sequence as a sequence where exactly one element is a prime number and all other elements are composite numbers. Given an integer array, Chef wants to determine if it is ... | 0.62535 | Taco_21977 | C | [
"is_prime",
"can_form_magical_sequence",
"magical_sequences"
] | 3 | [
[
"can_form_magical_sequence",
"is_prime"
],
[
"magical_sequences",
"can_form_magical_sequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e227ea87a6916f96de02a4f7476f173483884906 | 9b80840f5d461e61d325ac5b2edccc77d281b6de | |||
v1.0 | complete | Taco | Taco_21673_C | def assign_buses_to_routes(routes, buses):
"""Assign buses to routes to minimize the penalty for unfulfilled demand.
Args:
routes (List[Tuple[int, int]]): List of tuples, each containing demand and penalty
for each route.
buses (List[int]): List of bus capacitie... | def assign_buses_to_routes(routes, buses):
# Sort buses by their seating capacity in descending order
buses.sort(reverse=True)
# Sort routes by their demand and penalty in descending order of demand
routes = sorted(routes, key=lambda x: (-x[1], -x[2]))
assigned_routes = []
total_penalt... | def test_sample_input_one():
route_demands_penalties = [
(100, 400),
(150, 200),
(200, 300),
(50, 100)
]
bus_capacities = [180, 60, 220]
solve(bus_capacities, route_demands_penalties)
# The expected result must be:
# Number of assigned routes: 3
# Total penalt... | [
{
"docstring": null,
"function_declaration": "def assign_buses_to_routes(routes, buses):",
"function_name": "assign_buses_to_routes",
"parameter_list": "(routes, buses)"
},
{
"docstring": null,
"function_declaration": "def solve(bus_capacities, route_demands_penalties):",
"function_n... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def assign_buses_to_routes(routes, buses):\n # Sort buses by their capacity in descending order\n buses = sorted([(i+1, c) for i, c in enumerate(buses)], key... | trial_gpt4o_9 | {
"original_instruction": "A transportation agency is modernizing their route planning system to increase efficiency. The agency manages a fleet of buses with different seating capacities, and there are a number of routes with specific passenger demands.\n\nEach bus can operate on only one route per day and once assi... | 0.617562 | Taco_21673 | C | [
"assign_buses_to_routes",
"solve"
] | 2 | [
[
"solve",
"assign_buses_to_routes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1e244ce81d6b14375d6841a71d36fa26f079ff72 | 57b2943c9daa7b62753641b99ca61fa9ffe409ee | |||
v1.0 | complete | Taco | Taco_22098_C | def can_partition_to_primes(s: str) -> bool:
""" Given a string that contains only digits (0-9), determine if the string can be partitioned into
one or more substrings such that each substring represents a prime number. A prime number cannot
have leading zeros, except for the number 0 itself, which is not... | def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return True
def can_partition_to_primes(s):
memo = {}
def can_partition(start):
if start == len(s):
return True
if start in memo:
... | from solution import can_partition_to_primes
def test_example_1():
assert can_partition_to_primes("11373") == True
def test_example_2():
assert can_partition_to_primes("1234") == False
def test_single_digit_primes():
assert can_partition_to_primes("2357") == True
def test_single_digit_non_primes():
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def can_partition_to_primes(s):",
"function_name": "can_partition_to_primes",
"parameter_list": "(s)"
},
{
... | [
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 if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n**... | trial_gpt4o_1 | {
"original_instruction": "Given a string that contains only digits (0-9), write a function to determine if the string can be partitioned into one or more substrings such that each substring represents a prime number. A prime number cannot have leading zeros, except for the number 0 itself, which is not considered a ... | 0.674205 | Taco_22098 | C | [
"is_prime",
"can_partition_to_primes"
] | 2 | [
[
"can_partition_to_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fbfa39c2b74102d186d5861009067d8f43c7485d | 802a46da9530db12d67ecd02a1bec8ed57c52545 | |||
v1.0 | complete | Taco | Taco_22133_C | import math
def distance(x1, y1, x2, y2):
"""
Calculates the distance between two points (x1, y1) and (x2, y2)
"""
def find_max_min_distances(vertices):
"""
Given the vertices of a convex quadrilateral, returns the maximum and minimum distances
between any two vertices.
Examples:
>>> ... | import math
def distance(x1, y1, x2, y2):
"""
Calculates the distance between two points (x1, y1) and (x2, y2)
"""
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def find_max_min_distances(vertices):
"""
Given the vertices of a convex quadrilateral, returns the maximum and minimum distances... | from solution import find_max_min_distances
def test_case_1():
vertices = [
(0, 0),
(0, 2),
(2, 2),
(2, 0)
]
max_dist, min_dist = find_max_min_distances(vertices)
assert math.isclose(max_dist, 2.83, abs_tol=0.01)
assert math.isclose(min_dist, 2.00, abs_tol=0.01)
def... | [
{
"docstring": "Calculates the distance between two points (x1, y1) and (x2, y2)",
"function_declaration": "def distance(x1, y1, x2, y2):",
"function_name": "distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Given the vertices of a convex quadrilateral, returns the maximum a... | [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distances(vertices):\n def distance(p1, p2):\n return math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)\n\n distance... | trial_gpt4o_8 | {
"original_instruction": "John loves to design weird shapes using straight lines on a 2D plane. One day he drew a convex quadrilateral and wondered what the maximum and minimum distances between pairs of points (vertices) of the quadrilateral were.\n\nYour task is to write a program that helps John calculate the max... | 0.613119 | Taco_22133 | C | [
"distance",
"find_max_min_distances"
] | 2 | [
[
"find_max_min_distances",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1d013ae66ab4c3bcd61f73fbab4dd64e69380ebf | bfe2a6d15c967121b9978c5214c2358bb7669999 | |||
v1.0 | complete | Taco | Taco_22030_C | import math
from typing import List
def is_prime(num: int) -> bool:
"""Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(9)
False
>>> is_prime(11)
True
"""
pass
def transform_sequenc... | import math
def is_prime(num):
"""Check if a number is prime."""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
def transform_s... | from solution import is_prime, transform_sequence
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_transform_sequence():
assert transform_se... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def transform_sequence(sequence):",
"function_name": "transform_sequence",
"paramete... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n ... | trial_gpt4o_1 | {
"original_instruction": "A programmer is working on a sequence transformation problem. The task is to transform a given sequence of integers into a new sequence by applying the following rules:\n1. If an element is a prime number, it should be increased by 2.\n2. If an element is an even number and not prime, it sh... | 0.733923 | Taco_22030 | C | [
"is_prime",
"transform_sequence"
] | 2 | [
[
"transform_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0a0fdc8b0faebd67fa6de2a0fbc63c794225fed7 | 441dd8f067f95cb482a2715f578a63d8ba249efe | |||
v1.0 | complete | Taco | Taco_22243_C | def is_prime(n: int) -> bool:
""" Determine if a given number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
pass
def filter_primes(numbers: List[int]) -> List[int]:
""" Return a list of prime numbers filtered from ... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers filtered from the provided list of numbers.",
"function_declaration": "de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retur... | trial_gpt4o_0 | {
"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.\n\nHint\n\nYou may want to write a helper function to determine whether a given number is prime. A number is prime if it has no divisors other than 1 and itself.\n... | 0.733235 | Taco_22243 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fcdd3fd82ce25d169045a56f3a28a5f34cb2b426 | bc0945f4dd208be54509fe066b8bcc91a8d6979f | |||
v1.0 | complete | Taco | Taco_21895_C | def solve(m: int, n: int, k: int, grid: List[List[int]], start_points: List[Tuple[int, int]], dest: Tuple[int, int]) -> int:
""" Determine the number of distinct paths from any starting point to the destination point.
All paths are considered modulo 10^9 + 7.
Args:
m (int): Number of rows in the gr... | from collections import deque
MOD = 10**9 + 7
def num_paths(grid, m, n, start_points, dest):
def bfs(start):
nonlocal dest
rows, cols = len(grid), len(grid[0])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([start])
visited = set([start])
whi... | from solution import solve
def test_case_1():
m, n, k = 4, 4, 2
grid = [
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 0]
]
start_points = [(1, 1), (3, 3)]
dest = (4, 4)
assert solve(m, n, k, grid, start_points, dest) == 2
def test_case_2():
m, n, k = ... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid, m, n, start_points, dest):",
"function_name": "num_paths",
"parameter_list": "(grid, m, n, start_points, dest)"
},
{
"docstring": null,
"function_declaration": "def solve(m, n, k, grid, start_points, dest):",
"function... | [
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": "MOD = 10**9 + 7\n\ndef is_valid(x, y, m, n, grid):\n return 0 <= x < m and 0 <= y < n and grid[x][y] == 0\n\ndef bfs_count_paths(grid, m, n, start, end):\n f... | trial_gpt4o_2 | {
"original_instruction": "You are given a 2D grid of dimensions m x n where each cell in the grid can either be 0 (empty) or 1 (obstacle). You are also given a list of points representing starting positions for a robot. The robot can move up, down, left, or right, but cannot move into or through a cell containing an... | 0.77329 | Taco_21895 | C | [
"num_paths",
"solve"
] | 2 | [
[
"solve",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7920866be17f5dc959bc464477532ff1d450cf11 | aeb2a5e3fd80bbf2416d91bcc46dce88e73238ab | |||
v1.0 | complete | Taco | Taco_21541_C | def floyd_warshall(n, graph):
"""
Apply Floyd-Warshall algorithm to find the shortest paths between all pairs of vertices in a graph.
:param n: Number of vertices
:param graph: Adjacency list representation of the graph
:return: Matrix of shortest paths between all pairs of vertices
"""
pa... | def floyd_warshall(n, graph):
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for u in range(n):
for v, w in graph[u]:
dist[u][v] = min(dist[u][v], w)
for k in range(n):
for i in range(n):
for j in range(n):
... | import pytest
from solution import floyd_warshall, tsp, solve, hiking_trails_solver
def test_floyd_warshall():
graph = [
[(1, 1), (2, 2), (3, 3)],
[(0, 1), (2, 4), (3, 2)],
[(0, 2), (1, 4), (3, 1)],
[(0, 3), (1, 2), (2, 1)]
]
expected_dist = [
[0, 1, 2, 3],
[... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, graph):",
"function_name": "floyd_warshall",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def tsp(n, dist):",
"function_name": "tsp",
"parameter_list": "(n, dist)"
},
{
... | [
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 prim_mst(n, adj):\n import heapq\n \n mst_cost = 0\n visited = [False] * (n + 1)\n min_heap = [(0, 1)] # (cost, trail)\n \n while min_hea... | trial_gpt4o_5 | {
"original_instruction": "A group of friends is planning a hiking trip to explore various hiking trails in a national park. The park has `n` different trails identified by numbers from `1` to `n`, and there are `m` connections between the trails. Each connection defines the time it takes to move from one trail to an... | 0.608344 | Taco_21541 | C | [
"floyd_warshall",
"tsp",
"solve",
"hiking_trails_solver"
] | 4 | [
[
"hiking_trails_solver",
"solve"
],
[
"solve",
"floyd_warshall"
],
[
"solve",
"tsp"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | bb3d610c302c22048a1d659600f72908b68045a5 | c17e88334e9800951a2ff391246f783a4f6a15ca | |||
v1.0 | complete | Taco | Taco_22416_C | def max_pyramid_height(N):
"""
Returns the maximum height of the pyramid that can be formed with N coins.
"""
pass
def process_cases(T, cases):
"""
Process the test cases and return the results.
"""
pass
def solve_pyramid_height_problem(input_string):
"""
Parses the input strin... | def max_pyramid_height(N):
"""
Returns the maximum height of the pyramid that can be formed with N coins.
"""
height = 0
while N >= (height + 1):
height += 1
N -= height
return height
def process_cases(T, cases):
"""
Process the test cases and return the results.
"""... | from solution import solve_pyramid_height_problem
def test_example_cases():
input_data = "3\n1\n5\n8"
expected_output = "1\n2\n3"
assert solve_pyramid_height_problem(input_data) == expected_output
def test_small_cases():
input_data = "2\n2\n3"
expected_output = "1\n2"
assert solve_pyramid_heig... | [
{
"docstring": "Returns the maximum height of the pyramid that can be formed with N coins.",
"function_declaration": "def max_pyramid_height(N):",
"function_name": "max_pyramid_height",
"parameter_list": "(N)"
},
{
"docstring": "Process the test cases and return the results.",
"function_... | [
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 maximum_height(T, test_cases):\n results = []\n for N in test_cases:\n height = 0\n while N >= (height + 1):\n height += 1\n ... | trial_gpt4o_1 | {
"original_instruction": "Tina loves collecting coins. She arranges her coin collection in rows, where each row contains at least as many coins as the previous row. Tina decides to form the shape of a pyramid with her coins, where the first row has exactly 1 coin, the second row has exactly 2 coins, and so on, formi... | 0.651579 | Taco_22416 | C | [
"max_pyramid_height",
"process_cases",
"solve_pyramid_height_problem"
] | 3 | [
[
"process_cases",
"max_pyramid_height"
],
[
"solve_pyramid_height_problem",
"process_cases"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 348665c643a56a06791364326f744733c6d24381 | c08de5ce0fb3957ea053f1d14e0e5c5946dc326e | |||
v1.0 | complete | Taco | Taco_22190_C | def min_operations_to_equalize(numbers):
"""
Given a list of integers, returns the minimum number of operations
required to make all the integers equal. Each operation can increase
or decrease an integer by 1.
"""
def median(nums):
"""
Find the median of a list of numbers.
"""
fr... | def min_operations_to_equalize(numbers):
"""
Given a list of integers, returns the minimum number of operations
required to make all the integers equal. Each operation can increase
or decrease an integer by 1.
"""
target = int(median(numbers))
return sum(abs(x - target) for x in numbers)
... | from solution import min_operations_to_equalize
def test_case_1():
assert min_operations_to_equalize([1, 2, 3]) == 2
def test_case_2():
assert min_operations_to_equalize([1, 2, 2, 3]) == 2
def test_case_3():
assert min_operations_to_equalize([10, 10, 10, 10, 10]) == 0
def test_case_4():
assert min_o... | [
{
"docstring": "Given a list of integers, returns the minimum number of operations \nrequired to make all the integers equal. Each operation can increase \nor decrease an integer by 1.",
"function_declaration": "def min_operations_to_equalize(numbers):",
"function_name": "min_operations_to_equalize",
... | [
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 minimum_operations_to_equalize(nums):\n \"\"\"\n Returns the minimum number of operations required to make all integers in the list equal.\n An operat... | trial_gpt4o_1 | {
"original_instruction": "Harry is given a list of integers and he wants to make all the integers equal by performing a series of operations. In one operation, he can increase or decrease any integer by 1. Your task is to write a program that determines the minimum number of operations required to make all the integ... | 0.66871 | Taco_22190 | C | [
"min_operations_to_equalize",
"median"
] | 2 | [
[
"min_operations_to_equalize",
"median"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca46d31fadb1604f55fcdb7aa98f2d43467613de | 3dd15201b151cb4c0ebc3bc8df57b0a980d9efe5 | |||
v1.0 | complete | Taco | Taco_21805_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverse_linked_list_section(head, k):
"""Reverses the first k nodes of the linked list starting from the given head node.
Args:
head (ListNode): The head node of the linked list section to be reve... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverse_linked_list_section(head, k):
prev = None
curr = head
next = None
count = 0
while curr is not None and count < k:
next = curr.next
curr.next = prev
prev = c... | import pytest
from solution import ListNode, reverse_linked_list_section, traverse_to_position, linked_list_from_list, list_from_linked_list, constrained_reversal
def test_linked_list_basic():
values = [1, 2, 3, 4, 5]
head = linked_list_from_list(values)
result = list_from_linked_list(head)
assert resu... | [] | [
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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef parse_linked_list(values):\n dummy = ListNod... | trial_gpt4o_2 | {
"original_instruction": "Linked List Reversal with Constraints\n\nproblem\n\nYou are given a singly linked list with N nodes and a non-negative integer K. Each node in the linked list contains an integer value. The linked list's nodes are numbered sequentially from 1 to N. You need to perform a constrained reversal... | 0.560838 | Taco_21805 | C | [
"reverse_linked_list_section",
"traverse_to_position",
"linked_list_from_list",
"list_from_linked_list",
"constrained_reversal"
] | 5 | [
[
"constrained_reversal",
"linked_list_from_list"
],
[
"constrained_reversal",
"list_from_linked_list"
],
[
"constrained_reversal",
"reverse_linked_list_section"
],
[
"constrained_reversal",
"traverse_to_position"
]
] | 4 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | e96302d7539c533d9c4d4cc58f20bea50d3def4f | 4a1427c26d0e6664e65c6128ab4ab3527b667e04 | |||
v1.0 | complete | Taco | Taco_22320_C | from typing import List, Tuple
def longest_increasing_subsequence(arr: List[int]) -> List[int]:
""" Find the longest increasing subsequence from the list of integers.
>>> longest_increasing_subsequence([5, 1, 2, 9, 2, 3])
[1, 2, 9]
>>> longest_increasing_subsequence([4, 3, 2, 1])
[4]
>>> longes... | def longest_increasing_subsequence(arr):
if not arr:
return []
n = len(arr)
dp = [1] * n
prev = [-1] * n
for i in range(1, n):
for j in range(i):
if arr[i] > arr[j] and dp[i] < dp[j] + 1:
dp[i] = dp[j] + 1
prev[i] = j
... | def test_longest_increasing_subsequence():
assert longest_increasing_subsequence([5, 1, 2, 9, 2, 3]) == [1, 2, 9]
assert longest_increasing_subsequence([4, 3, 2, 1]) == [4]
assert longest_increasing_subsequence([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
assert longest_increasing_subsequence([10, 22, 9, 33, 21,... | [
{
"docstring": null,
"function_declaration": "def longest_increasing_subsequence(arr):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(T, test_cases):",
"function_name": "process_te... | [
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 strictly_increasing_list(T, test_cases):\n \"\"\"\n Returns strictly increasing lists for each test case by removing the smallest possible number of elem... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers and your task is to form a new list which will be strictly increasing. The new list should be formed by removing the smallest possible number of elements from the original list.\n\n------ Input ------\nThe first line contains a single integer $T$ denoting t... | 0.64906 | Taco_22320 | C | [
"longest_increasing_subsequence",
"process_test_cases",
"input_output_handling",
"main"
] | 4 | [
[
"process_test_cases",
"longest_increasing_subsequence"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | ab0d8bf1aa13b93d3c36b8b355c2224f36b5563e | a3f377383b68d201efc1b7061bc8e8aaf47ad123 | |||
v1.0 | complete | Taco | Taco_22217_C | def can_form_palindrome_by_removing_one_char(s: str) -> bool:
""" Determine if a string can be transformed into a palindrome by removing exactly one character.
>>> can_form_palindrome_by_removing_one_char("abca") True
>>> can_form_palindrome_by_removing_one_char("racecarx") True
>>> can_form_palindrome_... | def can_form_palindrome_by_removing_one_char(s):
def is_palindrome(x):
return x == x[::-1]
n = len(s)
left, right = 0, n - 1
while left < right:
if s[left] != s[right]:
return is_palindrome(s[left+1:right+1]) or is_palindrome(s[left:right])
left += 1
right -... | from solution import solve
def test_solve():
assert solve(3, ["abca", "racecarx", "aaaa"]) == ["YES", "YES", "NO"]
def test_solve_single_char():
assert solve(1, ["a"]) == ["NO"]
def test_solve_two_chars():
assert solve(1, ["ab"]) == ["YES"]
def test_solve_already_palindrome():
assert solve(1, ["race... | [
{
"docstring": null,
"function_declaration": "def can_form_palindrome_by_removing_one_char(s):",
"function_name": "can_form_palindrome_by_removing_one_char",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def solve(T, strings):",
"function_name": "solve",
... | [
0,
0,
0,
0,
0,
0,
1,
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": "def can_transform_to_palindrome(s):\n def is_palindrome(s):\n return s == s[::-1]\n\n n = len(s)\n left, right = 0, n - 1\n \n while left < r... | trial_gpt4o_9 | {
"original_instruction": "Arjun loves playing with strings. One day, he came across a string S consisting of only lower-case alphabets. He wondered if it was possible to transform the string by removing exactly one character such that the transformed string is a palindrome. A palindrome is a string that reads the sa... | 0.780926 | Taco_22217 | C | [
"can_form_palindrome_by_removing_one_char",
"solve"
] | 2 | [
[
"solve",
"can_form_palindrome_by_removing_one_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccc44eb9be67df944901be1434730a96163752ff | 3db24bb09b5aea65d5385966691d7a1a3cc7dda1 | |||
v1.0 | complete | Taco | Taco_22047_C | from typing import List, Tuple
def floyd_warshall(n: int, adj_matrix: List[List[int]]) -> List[List[int]]:
"""
Computes shortest paths between all pairs of nodes using the Floyd-Warshall algorithm.
"""
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
... | def floyd_warshall(n, adj_matrix):
"""
Computes shortest paths between all pairs of nodes
using the Floyd-Warshall algorithm.
"""
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for u in range(n):
for v in range(n):
if... | def test_min_teleporters_needed():
# Test case 1
assert min_teleporters_needed(4, [(1, 2, 3), (2, 3, 4), (3, 4, 2), (4, 1, 6)], 5) == 1
# Test case 2
assert min_teleporters_needed(5, [(1, 2, 1), (2, 3, 2), (3, 4, 4), (4, 5, 5), (1, 3, 7), (2, 5, 6), (1, 4, 8)], 3) == 2
# Test case 3: No teleporter... | [
{
"docstring": "Computes shortest paths between all pairs of nodes\nusing the Floyd-Warshall algorithm.",
"function_declaration": "def floyd_warshall(n, adj_matrix):",
"function_name": "floyd_warshall",
"parameter_list": "(n, adj_matrix)"
},
{
"docstring": null,
"function_declaration": "... | [
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 floyd_warshall(graph, N):\n dist = [[float('inf')] * N for _ in range(N)]\n for i in range(N):\n dist[i][i] = 0\n for u in rang... | trial_gpt4o_1 | {
"original_instruction": "In the kingdom of Dreamland, there are N cities connected by M bidirectional roads. Each road has a known travel time associated with it, and any number of teleporter stations can be built, each offering an instant travel between two cities. \n\nYou are tasked with building the fewest possi... | 0.671896 | Taco_22047 | C | [
"floyd_warshall",
"min_teleporters_needed"
] | 2 | [
[
"min_teleporters_needed",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c2b6f42a6e875f74cf19b6c81e31f9ac6d8be52c | 1992c82e927ae46988401ccf829534342ff2c107 | |||
v1.0 | complete | Taco | Taco_22514_C | def filter_prime_numbers(numbers: list) -> list:
"""Returns a list of all integers in the input list that are prime numbers.
>>> filter_prime_numbers([2, 3, 4, 5, 6, 10, 13, 17, 19, 21, 23, 24, 29])
[2, 3, 5, 13, 17, 19, 23, 29]
>>> filter_prime_numbers([1, 4, 6, 8, 9, 10])
[]
>>> filter_pr... | def is_prime(num):
if num <= 1:
return False
if num == 2 or 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 filter_prime_n... | from solution import filter_prime_numbers
def test_filter_prime_numbers_mixed():
assert filter_prime_numbers([2, 3, 4, 5, 6, 10, 13, 17, 19, 21, 23, 24, 29]) == [2, 3, 5, 13, 17, 19, 23, 29]
def test_filter_prime_numbers_with_non_prime():
assert filter_prime_numbers([1, 4, 6, 8, 9, 10]) == []
def test_filter... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the input list of integers.",
"function_declaration": "def filter_prime_numbers(numbers):",
"function_name... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return... | trial_gpt4o_0 | {
"original_instruction": "Given a list of integers, write a function that returns a list of all integers in the input list that are prime numbers. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.\n\nFor example, given the input list `[2, 3, 4, 5, 6, 1... | 0.69774 | Taco_22514 | C | [
"is_prime",
"filter_prime_numbers"
] | 2 | [
[
"filter_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 364f6e2da353db643cc7b867f35af6c514953be8 | 5b5c3bb4503e97bdeb3c7f8c6714423adfc23c6b | |||
v1.0 | complete | Taco | Taco_22327_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def deserialize(data):
if not data or data[0] == -1:
return None
nodes = [TreeNode(val) if val != -1 else None for val in data]
root = nodes[0]
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def deserialize(data):
if not data or data[0] == -1:
return None
nodes = [TreeNode(val) if val != -1 else None for val in data]
root = nodes[0]
... | from solution import longest_path_length_from_list
def test_example_1():
assert longest_path_length_from_list([1, 2, 3, 4, -1, 5, -1, -1, -1, -1, -1]) == 5
def test_example_2():
assert longest_path_length_from_list([1, 2, -1, -1, -1]) == 2
def test_empty_tree():
assert longest_path_length_from_list([]) =... | [] | [
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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\nclass Solution:\n def __init__(self):\... | trial_gpt4o_2 | {
"original_instruction": "-----Task-----\nGiven a binary tree, implement an algorithm to find the length of the longest path in terms of number of nodes between any two nodes in the tree. The path may or may not pass through the root. Your function should compute this length efficiently.\n\n-----Input-----\nThe inpu... | 0.548413 | Taco_22327 | C | [
"deserialize",
"longest_path_length",
"longest_path_length_from_list"
] | 3 | [
[
"longest_path_length_from_list",
"deserialize"
],
[
"longest_path_length_from_list",
"longest_path_length"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9bd608100f1273a688a3c1d412d85fab2b3526e2 | 4ab86d7ddd4a0bb1438722abda45355af8e60888 | |||
v1.0 | complete | Taco | Taco_22714_C | from typing import List
def sort_strings_by_vowels(strings: List[str], N: int) -> List[str]:
""" Organize strings by vowel count in descending order and lexicographical order.
>>> sort_strings_by_vowels(["apple", "banana", "grape", "kiwi", "orange"], 5)
['banana', 'orange', 'apple', 'grape', 'kiwi']
>>... | from typing import List
def count_vowels(s: str) -> int:
vowels = {'a', 'e', 'i', 'o', 'u'}
return sum(1 for char in s if char in vowels)
def sort_strings_by_vowels(strings: List[str], N: int) -> List[str]:
return sorted(strings, key=lambda s: (-count_vowels(s), s)) | from solution import sort_strings_by_vowels
def test_example():
N = 5
strings = ["apple", "banana", "grape", "kiwi", "orange"]
assert sort_strings_by_vowels(strings, N) == ["banana", "orange", "apple", "grape", "kiwi"]
def test_identical_vowel_counts():
N = 4
strings = ["aa", "bb", "cc", "dd"]
... | [
{
"docstring": null,
"function_declaration": "def count_vowels(s):",
"function_name": "count_vowels",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def sort_strings_by_vowels(strings, N):",
"function_name": "sort_strings_by_vowels",
"parameter_list": "(... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_strings_by_vowels(strings, N):\n \"\"\"\n Sort the strings based on the number of vowels in descending order,\n and lexicographically in ascendin... | trial_gpt4o_2 | {
"original_instruction": "I: Organize Strings\n\nProblem Statement\n\nYou have an array of strings, `strings`, and an integer `N`. Your task is to sort the strings in such a way that for each string, you count the number of vowels (a, e, i, o, u) in it. The strings should be sorted based on the number of vowels in d... | 0.729151 | Taco_22714 | C | [
"count_vowels",
"sort_strings_by_vowels"
] | 2 | [
[
"sort_strings_by_vowels",
"count_vowels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f3caf8f8f6d19716e5c0a01a96c1d0bc2f7791c3 | 0cc56ba30bf1f2dfd2d38cacad5959feeeae52d4 | |||
v1.0 | complete | Taco | Taco_22264_C | def calculate_energy_cost(x, y, a):
"""
Calculates the total energy cost for moving to and attacking an enemy at (x, y) with attack cost a.
"""
pass
def max_enemies_defeated(energy, enemies):
"""
Determines the maximum number of enemies the warrior can defeat in N turns or less
without runn... | def calculate_energy_cost(x, y, a):
"""
Calculates the total energy cost for moving to and attacking an enemy at (x, y) with attack cost a.
"""
distance_cost = abs(x) + abs(y)
total_energy_cost = distance_cost + a
return total_energy_cost
def max_enemies_defeated(energy, enemies):
"""
D... | def test_calculate_energy_cost():
assert calculate_energy_cost(3, 4, 10) == 17
assert calculate_energy_cost(5, 6, 15) == 26
assert calculate_energy_cost(2, 8, 20) == 30
def test_max_enemies_defeated():
assert max_enemies_defeated(100, [(3, 4, 10), (5, 6, 15), (2, 8, 20)]) == 3
assert max_enemies_de... | [
{
"docstring": "Calculates the total energy cost for moving to and attacking an enemy at (x, y) with attack cost a.",
"function_declaration": "def calculate_energy_cost(x, y, a):",
"function_name": "calculate_energy_cost",
"parameter_list": "(x, y, a)"
},
{
"docstring": "Determines the maxim... | [
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": "def max_enemies_defeated(E, enemies):\n \"\"\"\n Determines the maximum number of enemies the warrior can defeat without running out of energy.\n Args:\n ... | trial_gpt4o_9 | {
"original_instruction": "You are a game developer working on a turn-based strategy game where the player controls a warrior with limited energy points. The warrior can perform different kinds of actions including moving and attacking, but each action costs a specific amount of energy. Your task is to determine the ... | 0.641896 | Taco_22264 | C | [
"calculate_energy_cost",
"max_enemies_defeated",
"max_enemies_per_turn"
] | 3 | [
[
"max_enemies_defeated",
"calculate_energy_cost"
],
[
"max_enemies_per_turn",
"max_enemies_defeated"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 102a0829f694d97b4ffb001c34d0796144676d00 | eac278ed81ae170da22c440d761d9bc61b9211b2 | |||
v1.0 | complete | Taco | Taco_22213_C | def max_treasures_from_any_start(n: int, m: int, grid: List[str]) -> int:
"""
Write a function that takes a grid as input and returns the maximum number of treasures that can be collected starting from any of the starting cells.
Each contestant starts from a designated starting cell and moves through the m... | from collections import deque
def bfs_max_treasures(grid, start, n, m):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * m for _ in range(n)]
max_treasures = 0
q = deque([start])
visited[start[0]][start[1]] = True
while q:
x, y = q.popleft()
fo... | from solution import max_treasures_from_any_start
def test_example_1():
n, m = 4, 5
grid = [
"S.T#.",
".#...",
"S...T",
"##T#S"
]
assert max_treasures_from_any_start(n, m, grid) == 3
def test_example_2():
n, m = 3, 4
grid = [
"S.T.",
"T..T",
... | [
{
"docstring": null,
"function_declaration": "def bfs_max_treasures(grid, start, n, m):",
"function_name": "bfs_max_treasures",
"parameter_list": "(grid, start, n, m)"
},
{
"docstring": null,
"function_declaration": "def max_treasures_from_any_start(n, m, grid):",
"function_name": "m... | [
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_treasures(grid):\n \"\"\"\n Returns the maximum number of treasures that can be collected starting from any of the starting cells.\n \n Paramet... | trial_gpt4o_2 | {
"original_instruction": "A prestigious treasure hunt competition is held in a large maze. The maze consists of several cells connected by bidirectional paths. Each cell in the maze may contain a valuable treasure, and the goal is to collect as many valuable items as possible while navigating the maze.\n\nEach conte... | 0.685879 | Taco_22213 | C | [
"bfs_max_treasures",
"max_treasures_from_any_start"
] | 2 | [
[
"max_treasures_from_any_start",
"bfs_max_treasures"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f0b0b31dc0a9d5935f32f7b90bcc5ff0a80b0335 | bd654900c3433f18b598d5893fc1aaa64df2242a | |||
v1.0 | complete | Taco | Taco_22216_C | def century_from_year(year):
""" Returns the century of a given year.
>>> century_from_year(1)
1
>>> century_from_year(100)
1
>>> century_from_year(101)
2
>>> century_from_year(1900)
19
>>> century_from_year(2000)
20
>>> century_from_year(2023)
21
"""
def org... | def century_from_year(year):
return (year - 1) // 100 + 1
def organize_books_by_century(books):
books.sort(key=lambda x: x[1])
result = []
for title, year in books:
century = century_from_year(year)
result.append(f'"{title}",{century}th century')
return result
def main(book_data):
... | from solution import century_from_year, organize_books_by_century, main
def test_century_from_year():
assert century_from_year(1) == 1
assert century_from_year(100) == 1
assert century_from_year(101) == 2
assert century_from_year(1900) == 19
assert century_from_year(2000) == 20
assert century_f... | [
{
"docstring": null,
"function_declaration": "def century_from_year(year):",
"function_name": "century_from_year",
"parameter_list": "(year)"
},
{
"docstring": null,
"function_declaration": "def organize_books_by_century(books):",
"function_name": "organize_books_by_century",
"pa... | [
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_books_by_century(books):\n \"\"\"\n Sorts the given list of books by their publication years and labels them by the century.\n\n :param books: Li... | trial_gpt4o_2 | {
"original_instruction": "Alice has a collection of old books and she wants to organize them by their publication dates. She decides she will group the books into different eras, defined as centuries. A century is defined as a period of 100 years, starting from the year 1. For example, books from 1901 to 2000 belong... | 0.514974 | Taco_22216 | C | [
"century_from_year",
"organize_books_by_century",
"main"
] | 3 | [
[
"organize_books_by_century",
"century_from_year"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2718d88ea6bc73392bfbcb3d4389a909aea5df0 | 21b9d909e14276e4f9d181a001437836338cc662 | |||
v1.0 | complete | Taco | Taco_22794_C | from typing import List
def canBreakIntoKPalindromes(s: str, k: int) -> bool:
""" Determine if a string can be broken into exactly k palindromes.
>>> canBreakIntoKPalindromes("aab", 2)
True
>>> canBreakIntoKPalindromes("abc", 2)
False
>>> canBreakIntoKPalindromes("aaabb", 3)
True
""" | def is_palindrome(sub):
return sub == sub[::-1]
def canBreakIntoKPalindromes(s, k):
"""
Determine if a string can be broken into exactly k palindromes.
"""
def can_partition(s, k, start):
if k == 0:
return start == len(s)
for end in range(start + 1, len(s) + 1):
... | from solution import canBreakIntoKPalindromes
def test_example_1():
assert canBreakIntoKPalindromes("aab", 2) == True
def test_example_2():
assert canBreakIntoKPalindromes("abc", 2) == False
def test_example_3():
assert canBreakIntoKPalindromes("aaabb", 3) == True
def test_single_character_palindromes()... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(sub):",
"function_name": "is_palindrome",
"parameter_list": "(sub)"
},
{
"docstring": "Determine if a string can be broken into exactly k palindromes.",
"function_declaration": "def canBreakIntoKPalindromes(s, k):",
"fun... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(sub):\n return sub == sub[::-1]\n\ndef canBreakIntoKPalindromes(s, k):\n n = len(s)\n\n # Helper function to check if we can partition t... | trial_gpt4o_9 | {
"original_instruction": "Given a string s of length n, your goal is to determine whether it can be broken into exactly `k` substrings where each substring is a palindrome. A palindrome is a word, phrase, or sequence of characters which reads the same backward as forward.\n\nWrite a function `canBreakIntoKPalindrome... | 0.733468 | Taco_22794 | C | [
"is_palindrome",
"canBreakIntoKPalindromes"
] | 2 | [
[
"canBreakIntoKPalindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e717bbe1fe13610e0a8e71497d15ef038181b29 | 6d4ab9907a47400ee310c7c12dc7231447950344 | |||
v1.0 | complete | Taco | Taco_22250_C | def solve(N: int, arr: List[int]) -> str:
"""
Given a sequence of integers, determine if it is possible to obtain a strictly increasing sequence by removing at most one element.
Parameters:
N (int): The length of the sequence.
arr (List[int]): The elements of the sequence.
Returns:
str: "Y... | def can_be_increasing_by_removing_one(arr):
"""
Determines if the sequence can be made strictly increasing by removing at most one element.
"""
def is_strictly_increasing(arr):
return all(arr[i] < arr[i + 1] for i in range(len(arr) - 1))
for i in range(len(arr)):
if is_strictly_... | from solution import solve
def test_first_case():
assert solve(5, [1, 2, 3, 4, 3]) == "YES"
def test_second_case():
assert solve(3, [1, 2, 2]) == "YES"
def test_third_case():
assert solve(4, [1, 3, 3, 2]) == "NO"
def test_fourth_case():
assert solve(6, [10, 1, 2, 3, 4, 5]) == "YES"
def test_no_chan... | [
{
"docstring": "Determines if the sequence can be made strictly increasing by removing at most one element.",
"function_declaration": "def can_be_increasing_by_removing_one(arr):",
"function_name": "can_be_increasing_by_removing_one",
"parameter_list": "(arr)"
},
{
"docstring": null,
"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 can_be_increasing(seq):\n \"\"\"\n Determines if it's possible to obtain a strictly increasing sequence by\n removing at most one element from the ori... | trial_gpt4o_2 | {
"original_instruction": "Problem statement\n\nGiven a sequence of integers, we want to check if it is possible to obtain a strictly increasing sequence by removing at most one element. Your task is to write a function that determines whether it is possible to achieve the desired sequence with this constraint.\n\nTh... | 0.739977 | Taco_22250 | C | [
"can_be_increasing_by_removing_one",
"solve"
] | 2 | [
[
"solve",
"can_be_increasing_by_removing_one"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3063c7a44e984258e7cc2c052e1c52f22bb05e12 | 25ab0af73d2a11cbc58707355b152a3a875ffe63 | |||
v1.0 | complete | Taco | Taco_22731_C | from collections import deque
def bfs_min_distance(grid, m, n):
# Your code here
def min_distance_to_hospital(m, n, grid):
""" Determine the minimum distance required so that every citizen has access to a hospital within that distance.
>>> min_distance_to_hospital(3, 3, [
... ".H.",
... "..."... | from collections import deque
def bfs_min_distance(grid, m, n):
# find all the hospitals
hospitals = []
for i in range(m):
for j in range(n):
if grid[i][j] == 'H':
hospitals.append((i, j))
# directions for movement: left, right, up, down
directio... | def test_small_grid():
m, n = 3, 3
grid = [
".H.",
"...",
"H.H"
]
assert min_distance_to_hospital(m, n, grid) == 1
def test_square_grid():
m, n = 4, 4
grid = [
"H..H",
"....",
"....",
"H..H"
]
assert min_distance_to_hospital(m, n, ... | [
{
"docstring": null,
"function_declaration": "def bfs_min_distance(grid, m, n):",
"function_name": "bfs_min_distance",
"parameter_list": "(grid, m, n)"
},
{
"docstring": null,
"function_declaration": "def min_distance_to_hospital(m, n, grid):",
"function_name": "min_distance_to_hospi... | [
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\n\ndef bfs_min_distance(grid, m, n):\n # find all the hospitals\n hospitals = []\n for i in range(m):\n for j in rang... | trial_gpt4o_0 | {
"original_instruction": "In a certain country, the health ministry wants to ensure that all citizens have access to a hospital within a certain distance. The country is represented as a large grid, with some cells containing hospitals while others are empty. Your task is to determine the minimum distance required s... | 0.59195 | Taco_22731 | C | [
"bfs_min_distance",
"min_distance_to_hospital"
] | 2 | [
[
"min_distance_to_hospital",
"bfs_min_distance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a764711a63f5b89683c70fdbaa0ef03b978a723e | 20defd7c29531fdd61874eb67fa55e437c915d36 | |||
v1.0 | complete | Taco | Taco_22472_C | def min_rectangle_size(test_cases):
""" Determine the minimum rectangle size required to accommodate all the departments.
Args:
test_cases (list of dict): A list of test case dictionaries, each containing the
number of departments and their dimensions.
Returns:
list ... | def min_rectangle_size(test_cases):
res = []
for case in test_cases:
dimensions = case['dimensions']
N = case['N']
max_width = 0
total_length = 0
for length, width in dimensions:
total_length += length
max_width = max(max_width, width)
res.... | def test_min_rectangle_size():
input_data = "2\n3\n4 5\n2 3\n6 2\n2\n3 6\n5 4"
expected_output = [(12, 5), (8, 6)]
assert solve(input_data) == expected_output
def test_min_rectangle_size_single_case():
input_data = "1\n1\n5 4"
expected_output = [(5, 4)]
assert solve(input_data) == expected_... | [
{
"docstring": null,
"function_declaration": "def min_rectangle_size(test_cases):",
"function_name": "min_rectangle_size",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def read_input(input_data):",
"function_name": "read_input",
"parameter_lis... | [
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 minimum_rectangle_size(test_cases):\n results = []\n for case in test_cases:\n n = case[0]\n departments = case[1:]\n total_length =... | trial_gpt4o_5 | {
"original_instruction": "A company is planning to build new office spaces, and they want to minimize the area of the space while ensuring all the necessary departments can be accommodated. Each department needs a rectangular area to function, and the new office space should be a single rectangle.\n\nYou have been a... | 0.554237 | Taco_22472 | C | [
"min_rectangle_size",
"read_input",
"solve"
] | 3 | [
[
"solve",
"min_rectangle_size"
],
[
"solve",
"read_input"
]
] | 2 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 8efacedff25690876dc2938fc15011083958ae22 | 411955449e171a002d21af3eb882b0ef5a6cb50e | |||
v1.0 | complete | Taco | Taco_22279_C | from collections import deque
def minimum_moves_to_reach_end_with_jump(grid):
"""
Determine the minimum number of moves required to reach
the bottom-right corner from the top-left corner of the maze.
:param List[List[str]] grid: The maze represented as a grid of size N x M.
:return: Minimum ... | from collections import deque
def minimum_moves_to_reach_end_with_jump(grid):
def is_valid(x, y, n, m):
return 0 <= x < n and 0 <= y < m
def bfs(n, m, grid):
# Directions for moving up, down, left, right
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(0, 0, 0, F... | import pytest
from solution import solve, parse_input
def test_simple_case():
input_text = "1\n2 2\n..\n.."
test_cases = parse_input(input_text)
assert solve(test_cases) == [2]
def test_case_with_jumps():
input_text = "1\n4 4\n....\n.#..\n..#.\n...."
test_cases = parse_input(input_text)
assert... | [
{
"docstring": null,
"function_declaration": "def minimum_moves_to_reach_end_with_jump(grid):",
"function_name": "minimum_moves_to_reach_end_with_jump",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
... | [
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": "from collections import deque\n\ndef min_moves_to_reach_end(grid, N, M):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def in_bounds(x, y):\n ... | trial_gpt4o_9 | {
"original_instruction": "There is a maze represented as a grid of size N x M. Each cell in the grid can be either open (represented by '.') or blocked (represented by '#'). You start at the top-left corner of the maze (0, 0) and your goal is to reach the bottom-right corner (N-1, M-1). You can only move up, down, l... | 0.598265 | Taco_22279 | C | [
"minimum_moves_to_reach_end_with_jump",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"minimum_moves_to_reach_end_with_jump"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3cad0e0248bcc519efbff5a83cd222fddaf40211 | 3d09a445724bcadcbe3f8b1960e8c707b71cea1c | |||
v1.0 | complete | Taco | Taco_22822_C | def is_prime(num):
""" Returns True if num is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(1)
False
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(9)
False
"""
def qualifies_for_prime_discount(customer_id):... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import is_prime, qualifies_for_prime_discount
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(1)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
def test_qualifies_for_prime_discount_yes():
assert qualifies_for_prime_discount(41... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if the customer ID qualifies for prime discount.\nA customer ID qualifies if the sum of... | [
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 Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n... | trial_gpt4o_0 | {
"original_instruction": "A popular e-commerce platform wants to improve its online shopping experience by adding a personalized discount system. Each customer is associated with a unique customer ID which is a positive integer. The platform offers different discounts based on certain properties of the customer ID.\... | 0.700043 | Taco_22822 | C | [
"is_prime",
"qualifies_for_prime_discount"
] | 2 | [
[
"qualifies_for_prime_discount",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 968d814cc96bafb1a524f5dd0837dc5f83767052 | 8e9e863cd43859c305f675246bb6a06158a76d83 | |||
v1.0 | complete | Taco | Taco_22991_C | def find_peaks(n, altitude):
""" Given the length of the hike and the altitude at each point, returns the indices of all peaks.
>>> find_peaks(5, [1, 3, 2, 5, 4])
'2 4'
>>> find_peaks(4, [1, 1, 1, 1])
'No peaks'
"""
def hiking_alex_homecoming(n, altitudes):
""" Function that takes input... | def find_peaks(n, altitude):
peaks = []
for i in range(1, n - 1):
if altitude[i] > altitude[i - 1] and altitude[i] > altitude[i + 1]:
peaks.append(i + 1) # Use 1-based index
if not peaks:
return "No peaks"
else:
return " ".join(map(str, peaks))
# Function ... | from solution import find_peaks, hiking_alex_homecoming
def test_find_peaks_example_1():
assert find_peaks(5, [1, 3, 2, 5, 4]) == "2 4"
def test_find_peaks_example_2():
assert find_peaks(4, [1, 1, 1, 1]) == "No peaks"
def test_find_peaks_single_peak():
assert find_peaks(3, [1, 3, 1]) == "2"
def ... | [
{
"docstring": null,
"function_declaration": "def find_peaks(n, altitude):",
"function_name": "find_peaks",
"parameter_list": "(n, altitude)"
},
{
"docstring": null,
"function_declaration": "def hiking_alex_homecoming(n, altitudes):",
"function_name": "hiking_alex_homecoming",
"p... | [
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 find_peaks(n, altitudes):\n \"\"\"\n Identifies all the peak points in the given list of altitudes.\n \n Parameters:\n n (int): Number of points... | trial_gpt4o_2 | {
"original_instruction": "**Problem Statement:**\n\nHiking Alex's Homecoming\n\nAlex loves hiking and often goes on long weekend trips into the mountains. He has recorded the altitude at each point along his hike. To better understand his trips, Alex wants to analyze the altitude data by segmenting his hike into ind... | 0.593728 | Taco_22991 | C | [
"find_peaks",
"hiking_alex_homecoming"
] | 2 | [
[
"hiking_alex_homecoming",
"find_peaks"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 975a5923a23cba1e8d35790cb18f78a12a63f133 | 18e79ff6f63222ce5728b9c779939970f668b8d2 | |||
v1.0 | complete | Taco | Taco_23014_C | def process_input_return_distinct_path_sums(N: int, M: int, grid_values: List[List[int]]) -> int:
""" Returns the number of distinct path sums from the top-left to the bottom-right of the grid.
>>> process_input_return_distinct_path_sums(3, 3, [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]) 5
... | def distinct_path_sums(grid):
"""
Returns the number of distinct path sums from the top-left to the bottom-right of the grid.
"""
N = len(grid)
M = len(grid[0])
from collections import defaultdict
dp = defaultdict(set)
dp[(0, 0)].add(grid[0][0])
for r in range(N):
f... | from solution import process_input_return_distinct_path_sums
def test_example_1():
N, M = 3, 3
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert process_input_return_distinct_path_sums(N, M, grid) == 5
def test_example_2():
N, M = 2, 2
grid = [
[1, 2],
[... | [
{
"docstring": "Returns the number of distinct path sums from the top-left to the bottom-right of the grid.",
"function_declaration": "def distinct_path_sums(grid):",
"function_name": "distinct_path_sums",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def pr... | [
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 distinct_path_sums(grid):\n n = len(grid)\n m = len(grid[0])\n \n # We'll use a set for maintaining distinct path sums at each cell\n dp = [[set... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nYou are given a rectangular grid with N rows and M columns. Each cell in the grid contains a positive integer. You want to find the number of distinct path sums when travelling from the top-left corner (cell (1,1)) to the bottom-right corner (cell (N,M)). You can only move right ... | 0.623983 | Taco_23014 | C | [
"distinct_path_sums",
"process_input_return_distinct_path_sums"
] | 2 | [
[
"process_input_return_distinct_path_sums",
"distinct_path_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 225a3bd40c930cf4765c271033be1d853cd30a5a | b605271fe29ccbd4321db24f1f4d15140eb05d46 | |||
v1.0 | complete | Taco | Taco_22672_C | def create_deck():
"""Create a standard deck of 52 cards."""
pass
def card_value(card):
"""Return the value of the card for comparison."""
pass
def deal_cards(deck, n, m):
"""Deal m cards to each of the n players from the deck."""
pass
def determine_winner(players_hands):
"""Determine the... | import random
def create_deck():
suits = ['H', 'D', 'C', 'S']
values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
return [value + suit for value in values for suit in suits]
def card_value(card):
value_order = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10... | import pytest
from solution import create_deck, deal_cards, determine_winner, card_value, simulate_card_game
def test_create_deck():
deck = create_deck()
assert len(deck) == 52
assert "AS" in deck # Ace of Spades
assert "10D" in deck # 10 of Diamonds
def test_card_value():
assert card_value("AS"... | [
{
"docstring": null,
"function_declaration": "def create_deck():",
"function_name": "create_deck",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def card_value(card):",
"function_name": "card_value",
"parameter_list": "(card)"
},
{
"docstring": 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": "import random\n\ndef create_deck():\n suits = ['H', 'D', 'C', 'S']\n values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']\n return ... | trial_gpt4o_0 | {
"original_instruction": "Create a program that simulates a basic card game involving a standard 52-card deck. The game will involve dealing five cards to each player and then determining the winner based on the highest card in hand. Aces are considered high cards.\n\n### Input\n\n- The first line of input contains ... | 0.571875 | Taco_22672 | C | [
"create_deck",
"card_value",
"deal_cards",
"determine_winner",
"simulate_card_game",
"card_game"
] | 6 | [
[
"card_game",
"simulate_card_game"
],
[
"determine_winner",
"card_value"
],
[
"simulate_card_game",
"create_deck"
],
[
"simulate_card_game",
"deal_cards"
],
[
"simulate_card_game",
"determine_winner"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | fef0fb0c41c1c96aec5a23be5698ecc59a78c815 | ba6e09b26c2b6e307ee736bf1e26e6b50bb1bac1 | |||
v1.0 | complete | Taco | Taco_23054_C | from typing import List
def can_be_palindrome(s: str) -> bool:
""" Helper function to check if a string can be transformed into a palindrome.
>>> can_be_palindrome("abca")
True
>>> can_be_palindrome("abc")
False
"""
def check_spell_worthy_strings(t: int, strings: List[str]) -> List[str]:
... | def can_be_palindrome(s):
"""
Helper function to check if a string can be transformed into a palindrome.
"""
def is_palindrome(s):
return s == s[::-1]
# Check if the string can be reduced to a palindrome
n = len(s)
i, j = 0, n - 1
while i < j:
if s[i] != s[j]:
... | from solution import can_be_palindrome, check_spell_worthy_strings
def test_can_be_palindrome():
assert can_be_palindrome("abca") == True
assert can_be_palindrome("abc") == False
assert can_be_palindrome("aab") == True
assert can_be_palindrome("a") == True
assert can_be_palindrome("racecar") == Tru... | [
{
"docstring": "Helper function to check if a string can be transformed into a palindrome.",
"function_declaration": "def can_be_palindrome(s):",
"function_name": "can_be_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def check_spell_worthy_strings(... | [
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": "def can_be_transformed_to_palindrome(s):\n \"\"\"\n Determines if a string can be transformed into a palindrome by removing zero or more characters.\n \"\... | trial_gpt4o_9 | {
"original_instruction": "In the magical land of Arithmeticia, a string is considered spell-worthy if it can be transformed into a palindrome by removing zero or more characters. A group of wizards is preparing for a great challenge where they need to transform a sequence of strings into spell-worthy strings.\n\nAs ... | 0.799504 | Taco_23054 | C | [
"can_be_palindrome",
"check_spell_worthy_strings"
] | 2 | [
[
"check_spell_worthy_strings",
"can_be_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a74f899d10f50588ddb2b8ead60f617bb69c9e16 | 698bd0c2b24e2bc38efa7d99cfa91301009d731b | |||
v1.0 | complete | Taco | Taco_22944_C | def find_start_and_end(grid):
""" Find the coordinates for the start (S) and end (E) points in the grid.
>>> find_start_and_end([
... ['S', '.', '.', '#'],
... ['.', '#', '.', 'E'],
... ['#', '.', '.', '.']
... ])
((0, 0), (1, 3))
"""
def longest_path(grid, start, end):
... | def find_start_and_end(grid):
start, end = None, None
for i in range(len(grid)):
for j in range(len(grid[i])):
if grid[i][j] == 'S':
start = (i, j)
if grid[i][j] == 'E':
end = (i, j)
return start, end
def longest_path(grid, start, end):
di... | def test_find_start_and_end():
grid = [
['S', '.', '.', '#'],
['.', '#', '.', 'E'],
['#', '.', '.', '.']
]
assert find_start_and_end(grid) == ((0, 0), (1, 3))
def test_longest_path():
grid = [
['S', '.', '.', '#'],
['.', '#', '.', 'E'],
['#', '.', '.', '.... | [
{
"docstring": null,
"function_declaration": "def find_start_and_end(grid):",
"function_name": "find_start_and_end",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def longest_path(grid, start, end):",
"function_name": "longest_path",
"parameter_list"... | [
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 longest_path(T, test_cases):\n def valid_move(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] != '#' and not visited[x][y]\n\n def dfs(x,... | trial_gpt4o_5 | {
"original_instruction": "Roman often loved complex mazes. Monica decided to give him a unique maze design on his birthday, where he has to find the longest path from the start to the end in a grid. Roman can only move up, down, left, or right, and he cannot move through walls. Each cell in the grid is either empty ... | 0.618199 | Taco_22944 | C | [
"find_start_and_end",
"longest_path",
"solve"
] | 3 | [
[
"solve",
"find_start_and_end"
],
[
"solve",
"longest_path"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 888db141908b7081999fdf42b3a99f30074d1b47 | 770cfbdb7a90d7085974aecbaf000143fbe1f6df | |||
v1.0 | complete | Taco | Taco_23093_C | def traverse_grid(n: int, m: int, patches: List[Tuple[int, int, int, int]], queries: List[Tuple[int, int, int, int]]) -> List[str]:
""" Determine if it is possible to traverse from the starting position to the ending position in an aquarium grid without crossing seaweed patches.
>>> traverse_grid(5, 5, [(1, 2, ... | from collections import deque
def is_valid(x, y, n, m, grid):
return 0 <= x < n and 0 <= y < m and grid[x][y] == 0
def bfs(n, m, grid, sx, sy, ex, ey):
if sx == ex and sy == ey:
return True
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(sx, sy)])
visited = [[False]*m ... | import pytest
from solution import traverse_grid
def test_basic_path_possible():
n = 5
m = 5
patches = [(1, 2, 2, 3), (4, 4, 5, 5)]
queries = [(1, 1, 5, 5), (2, 2, 4, 4), (1, 1, 3, 3)]
assert traverse_grid(n, m, patches, queries) == ["NO", "NO", "YES"]
def test_no_seaweed():
n = 3
m = 3
... | [
{
"docstring": null,
"function_declaration": "def is_valid(x, y, n, m, grid):",
"function_name": "is_valid",
"parameter_list": "(x, y, n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def bfs(n, m, grid, sx, sy, ex, ey):",
"function_name": "bfs",
"parameter_list": "(... | [
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": "def can_traverse(grid, visited, start, end):\n n = len(grid)\n m = len(grid[0])\n queue = [start]\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n ... | trial_gpt4o_9 | {
"original_instruction": "In an aquarium, there is a rectangular grid of dimensions $n \\times m$ representing water tiles. There are some rectangular patches of seaweed on this grid, given by their top-left and bottom-right coordinates $(r1, c1)$ and $(r2, c2)$. The seaweed patches are dense enough that they cannot... | 0.635018 | Taco_23093 | C | [
"is_valid",
"bfs",
"traverse_grid"
] | 3 | [
[
"bfs",
"is_valid"
],
[
"traverse_grid",
"bfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d249f1c5120dc5de44babbd7c9d9f22bed75ed1c | 927e0158aa685a9057ef45621fdedaf1c8b7018a | |||
v1.0 | complete | Taco | Taco_23385_C | def update_array(arr, idx, value):
"""Update the element at index idx in the array arr with the value."""
# Your code here
def sum_range(arr, l, r):
"""Calculate the sum of elements from index l to r (inclusive) in the array arr."""
# Your code here
def process_queries(N, Q, elements, queries):
""... | def update_array(arr, idx, value):
"""
Update the element at index idx in the array arr with the value.
"""
arr[idx - 1] = value
def sum_range(arr, l, r):
"""
Calculate the sum of elements from index l to r (inclusive) in the array arr.
"""
return sum(arr[l - 1:r])
def process_queries(... | from solution import update_array, sum_range, process_queries
def test_update_array():
arr = [1, 2, 3, 4, 5]
update_array(arr, 2, 10)
assert arr == [1, 10, 3, 4, 5]
def test_sum_range():
arr = [1, 2, 10, 4, 5]
assert sum_range(arr, 1, 3) == 13
assert sum_range(arr, 2, 4) == 16
assert sum_r... | [
{
"docstring": "Update the element at index idx in the array arr with the value.",
"function_declaration": "def update_array(arr, idx, value):",
"function_name": "update_array",
"parameter_list": "(arr, idx, value)"
},
{
"docstring": "Calculate the sum of elements from index l to r (inclusiv... | [
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 process_queries(n, q, arr, queries):\n \"\"\"\n This function processes a list of queries on the given array. \n Each query will either update an elem... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of N integers. You need to perform Q queries on this array. Each query is of the following form:\n\n- 1 x y: Update the element at index x to y.\n- 2 l r: Calculate the sum of elements from index l to r (inclusive).\n\nThe indexing is 1-based.\n\n------ Input ------\n... | 0.553188 | Taco_23385 | C | [
"update_array",
"sum_range",
"process_queries"
] | 3 | [
[
"process_queries",
"sum_range"
],
[
"process_queries",
"update_array"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 057f668e1c197c76ae25cb37d18f5cf3d47ee357 | 4438418e73ca118b0a91bf13a649cd41a969c603 | |||
v1.0 | complete | Taco | Taco_23389_C | def min_palindromic_substrings(N: int, S: str) -> int:
"""
Return the minimum number of contiguous substrings such that every substring is either
a palindrome or can be rearranged to form a palindrome.
>>> min_palindromic_substrings(7, "nooonan")
3
>>> min_palindromic_substrings(1, "a")
... | def can_form_palindrome(s):
"""
Returns True if the string s can be rearranged to form a palindrome.
"""
from collections import Counter
count = Counter(s)
odd_count = sum(1 for x in count.values() if x % 2 == 1)
return odd_count <= 1
def min_palindromic_substrings(N, S):
"""
Return... | from solution import min_palindromic_substrings
def test_example_case():
assert min_palindromic_substrings(7, "nooonan") == 3
def test_single_character():
assert min_palindromic_substrings(1, "a") == 1
def test_all_palindrome():
assert min_palindromic_substrings(5, "madam") == 1
def test_all_characters_... | [
{
"docstring": "Returns True if the string s can be rearranged to form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns the minimum number of contiguous substrings such that every... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_rearrange_to_palindrome(s):\n from collections import Counter\n count = Counter(s)\n odd_count = sum(1 for c in count if count[c] % 2 != 0)\n r... | trial_gpt4o_7 | {
"original_instruction": "Alex loves playing with a string S of length N. His goal is to determine the minimum number of contiguous substrings such that every substring is either a palindrome or can be rearranged to form a palindrome. \n\nYour task is to help Alex by writing a program that finds this minimum number.... | 0.819558 | Taco_23389 | C | [
"can_form_palindrome",
"min_palindromic_substrings"
] | 2 | [
[
"min_palindromic_substrings",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b26e84d8244be504464b47645aa76b6f2927420 | 36c1e93f44cf50442c7de5ee2460be47ab0b8795 | |||
v1.0 | complete | Taco | Taco_23442_C | def find_min_additional_cables(n: int, m: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of additional cables required to make all servers connected.
Args:
n: Number of servers (2 ≤ n ≤ 100)
m: Number of existing cables (0 ≤ m ≤ n*(n-1)/2)
connections: A list ... | def find_min_additional_cables(n, m, connections):
from collections import defaultdict, deque
def bfs(start, graph, visited):
queue = deque([start])
visited[start] = True
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if not visi... | def test_find_min_additional_cables_example_1():
assert find_min_additional_cables(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1
def test_find_min_additional_cables_example_2():
assert find_min_additional_cables(4, 0, []) == 3
def test_find_min_additional_cables_single_cable():
assert find_min_additional_cables(4,... | [
{
"docstring": null,
"function_declaration": "def find_min_additional_cables(n, m, connections):",
"function_name": "find_min_additional_cables",
"parameter_list": "(n, m, connections)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"par... | [
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 minimum_additional_cables(n, m, connections):\n from collections import defaultdict\n\n def dfs(node, visited, adj):\n stack = [node]\n whi... | trial_gpt4o_1 | {
"original_instruction": "A tech company has a network of servers connected by bidirectional cables. Each server is labeled uniquely with an id from 1 to n. The goal is to ensure that all servers are directly or indirectly connected to server 1 (the main server). If a server is not connected to the main server, the ... | 0.587938 | Taco_23442 | C | [
"find_min_additional_cables",
"solve"
] | 2 | [
[
"solve",
"find_min_additional_cables"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ecd9a028085d277e8c36d4db0cd92f2ede7f8d7a | ae6c75542645013d9e59fe48a72195951b18e0ba | |||
v1.0 | complete | Taco | Taco_22801_C | from collections import defaultdict, deque
import sys
def calculate_distances(n, edges):
"""
Calculates the distance (number of nodes in path) between all pairs of nodes in a tree.
"""
pass
def count_nodes_on_path(n, edges, queries):
"""
For each query (u, v) returns the number of nodes on the... | from collections import defaultdict, deque
def calculate_distances(n, edges):
"""
Calculates the distance (number of nodes in path) between all pairs of nodes in a tree.
"""
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def bfs(star... | import sys
from io import StringIO
from solution import main
def test_case_1():
input_data = """5
1 2
1 3
3 4
3 5
3
2 4
1 5
1 2
"""
expected_output = """4
3
2
"""
check_test_case(input_data, expected_output)
def test_case_2():
input_data = """6
1 2
1 3
2 4
2 5
3 6
4
5 6
1 4
3 4
6 1
"""
expected_ou... | [
{
"docstring": "Calculates the distance (number of nodes in path) between all pairs of nodes in a tree.",
"function_declaration": "def calculate_distances(n, edges):",
"function_name": "calculate_distances",
"parameter_list": "(n, edges)"
},
{
"docstring": "For each query (u, v) returns the ... | [
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": "import sys\nfrom collections import deque, defaultdict\n\ninput = sys.stdin.read\n\ndef lca_preprocess(tree, root, n):\n # Depth and LCA Arrays\n depth = [-1... | trial_gpt4o_2 | {
"original_instruction": "Given a tree with n nodes rooted at node 1, you are required to perform q queries on it. Each query gives you two integers $u$ and $v$, representing two nodes in the tree. For each query, you need to determine the number of nodes that lie on the path from $u$ to $v$ (both inclusive).\n\n---... | 0.710895 | Taco_22801 | C | [
"calculate_distances",
"count_nodes_on_path",
"main"
] | 3 | [
[
"count_nodes_on_path",
"calculate_distances"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 516f3bc2f324544eb7ac1d261a42d2f984b39015 | 1313b9e034e35e6fe5b5efa78f5ff8851c10053a | |||
v1.0 | complete | Taco | Taco_23282_C | def min_edges_to_remove(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
"""
Given an undirected graph with n nodes and m edges, determine the minimum number of edges that can be removed so
that there are no cycles in the resulting graph.
Parameters:
n (int): The number of nodes in the g... | def find_cycle_edges(n, edges):
"""
Finds and returns the edges that are part of cycles in the graph.
"""
parent = list(range(n + 1))
def find(u):
if u != parent[u]:
parent[u] = find(parent[u])
return parent[u]
def union(u, v):
root_u = find(u)
root_... | from solution import min_edges_to_remove
def test_example_1():
n, m = 6, 6
edges = [
(1, 2),
(1, 3),
(2, 3),
(2, 4),
(4, 5),
(5, 6)
]
assert min_edges_to_remove(n, m, edges) == 1
def test_example_2():
n, m = 5, 5
edges = [
(1, 2),
... | [
{
"docstring": "Finds and returns the edges that are part of cycles in the graph.",
"function_declaration": "def find_cycle_edges(n, edges):",
"function_name": "find_cycle_edges",
"parameter_list": "(n, edges)"
},
{
"docstring": "Given a graph with n nodes and m edges, find the minimum 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 min_edges_to_remove_to_avoid_cycles(N, M, edges):\n \"\"\"\n Function to determine the minimum number of edges that can be removed so that \n there ar... | trial_gpt4o_2 | {
"original_instruction": "Given an undirected graph with N nodes and M edges, your task is to determine the minimum number of edges that can be removed so that there are no cycles in the resulting graph. The input will provide the list of edges in the graph.\n\n### Input\n- The first line contains two integers, N an... | 0.711216 | Taco_23282 | C | [
"find_cycle_edges",
"min_edges_to_remove"
] | 2 | [
[
"min_edges_to_remove",
"find_cycle_edges"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc91f5ad60126e76c20e27a7a5f20f67557e77dc | 0795094d77d79a9ad4c06352b10661ec2a1ac5e9 | |||
v1.0 | complete | Taco | Taco_22650_C | from collections import defaultdict
from typing import List, Tuple
def connectu_analysis(n: int, m: int, friendships: List[Tuple[int, int]], s: int, t: int) -> Tuple[int, int]:
""" Analyze the ConnectU network to find the shortest path between two users and the most influential user.
Args:
n (int): Nu... | from collections import deque, defaultdict
def bfs_shortest_path(graph, start, goal):
"""
Uses BFS to find the shortest path from start to goal in an undirected graph.
Returns the length of the shortest path, or -1 if there is no path.
"""
if start == goal:
return 0
visited = set()... | def test_shortest_path():
friendships = [(1, 2), (2, 3), (3, 4), (4, 5)]
shortest_path_length, _ = connectu_analysis(5, 4, friendships, 1, 5)
assert shortest_path_length == 4
def test_no_path():
friendships = [(1, 2), (3, 4)]
shortest_path_length, _ = connectu_analysis(4, 2, friendships, 1, 4)
... | [
{
"docstring": "Uses BFS to find the shortest path from start to goal in an undirected graph.\nReturns the length of the shortest path, or -1 if there is no path.",
"function_declaration": "def bfs_shortest_path(graph, start, goal):",
"function_name": "bfs_shortest_path",
"parameter_list": "(graph, ... | [
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_shortest_path(graph, start, goal):\n \"\"\"\n Uses BFS to find the shortest path from start to goal in ... | trial_gpt4o_0 | {
"original_instruction": "In the near future, a new kind of social network called ConnectU has emerged, focusing on facilitating direct and indirect connections among its users. Each user on ConnectU has a unique user ID and a list of friends represented by their user IDs. Unlike traditional social networks, Connect... | 0.625955 | Taco_22650 | C | [
"bfs_shortest_path",
"calculate_user_influence",
"connectu_analysis"
] | 3 | [
[
"connectu_analysis",
"bfs_shortest_path"
],
[
"connectu_analysis",
"calculate_user_influence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d5b1e7ecbb3d77111dbcb6222afc5da561dda611 | 57866b6c40304ecf96dc769251a8bd0319493a88 | |||
v1.0 | complete | Taco | Taco_23512_C | def solve(t, test_cases):
""" A detective needs help finding numbers with exactly two distinct prime factors in a list of test cases.
Args:
t (int): Number of test cases.
test_cases (List[Tuple[int, List[int]]]): List of test cases, each with the count of numbers and the numbers themselves.... | def has_exactly_two_distinct_prime_factors(number):
prime_factors = set()
factor = 2
while factor * factor <= number:
while (number % factor) == 0:
prime_factors.add(factor)
number //= factor
factor += 1
if number > 1:
prime_factors.add(number)
return ... | from solution import solve
def test_case_1():
assert solve(3, [
(5, [10, 15, 21, 30, 35]),
(4, [16, 27, 64, 81]),
(3, [49, 77, 91])
]) == ["TRUE", "FALSE", "TRUE"]
def test_case_2():
assert solve(2, [
(3, [6, 10, 14]),
(2, [18, 20])
]) == ["TRUE", "TRUE"]
def t... | [
{
"docstring": null,
"function_declaration": "def has_exactly_two_distinct_prime_factors(number):",
"function_name": "has_exactly_two_distinct_prime_factors",
"parameter_list": "(number)"
},
{
"docstring": null,
"function_declaration": "def solve(t, test_cases):",
"function_name": "s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef has_two_distinct_prime_factors(num):\n prime_factors = set()\n # Check for number of 2s that divide num\n while num % 2 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "A famous detective is working on a case involving a secret society. The society communicates using a cipher based on prime factorization. The detective has a list of numbers, and he suspects that they are encoded messages. To start decoding, he needs to find all numbers in the list that hav... | 0.63688 | Taco_23512 | C | [
"has_exactly_two_distinct_prime_factors",
"solve"
] | 2 | [
[
"solve",
"has_exactly_two_distinct_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e77fa4d29d628329a9818f231a023a89fb74efd4 | 9c2d820b7d5ab9165b6e3fe4c82db96546fe79e4 | |||
v1.0 | complete | Taco | Taco_23156_C | def find_winner(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[str]:
""" Determine the winner of the game for each test case.
Parameters:
T (int): The number of test cases.
test_cases (List[Tuple[int, List[int]]]): A list of tuples. Each tuple contains an integer N,
... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | import pytest
from solution import find_winner
def test_sample_input():
T = 2
test_cases = [(5, [2, 3, 4, 5, 6]), (6, [7, 11, 14, 15, 18, 20])]
expected = ["ALICE", "CHARLIE"]
assert find_winner(T, test_cases) == expected
def test_no_prime_numbers():
T = 1
test_cases = [(5, [4, 6, 8, 9, 10])]
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines the winner of the game given the array.",
"function_declaration": "def determine_winner(arr)... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if... | trial_gpt4o_2 | {
"original_instruction": "In a faraway kingdom named CodeLand, the king has a peculiar interest in operations on arrays, especially involving prime numbers. The kingdom's advisors have challenged two of its greatest programmers, Alice and Charlie, to a friendly competition involving a game with arrays.\n\nThe game g... | 0.615069 | Taco_23156 | C | [
"is_prime",
"determine_winner",
"find_winner"
] | 3 | [
[
"determine_winner",
"is_prime"
],
[
"find_winner",
"determine_winner"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f2c0e81371309ad23c2b59605258ddc5fbb21ca9 | f0b6d60eaf295fe9f0f163f403bcfbd933315fee | |||
v1.0 | complete | Taco | Taco_23145_C | def can_rearrange(s: str, k: int) -> str:
""" Determine if it is possible to rearrange the string S such that there are at most K consecutive identical characters.
Args:
s (str): The input string consisting of lowercase English letters.
k (int): The maximum number of consecutive identical characters all... | def can_rearrange(s, k):
from collections import Counter
import heapq
# Get the frequency of each character
counter = Counter(s)
# Max-heap of the counts of the characters
max_heap = [-cnt for cnt in counter.values()]
heapq.heapify(max_heap)
# If the maximum frequency of any charac... | from solution import solve, preprocess_input
def test_sample_input():
input_data = "3\naabbcc 2\naabbcc 1\naaaabbbbcc 3"
tasks = preprocess_input(input_data)
assert solve(tasks) == ["YES", "NO", "YES"]
def test_identical_characters_k_1():
input_data = "1\naaaa 1"
tasks = preprocess_input(input_dat... | [
{
"docstring": null,
"function_declaration": "def can_rearrange(s, k):",
"function_name": "can_rearrange",
"parameter_list": "(s, k)"
},
{
"docstring": null,
"function_declaration": "def solve(tasks):",
"function_name": "solve",
"parameter_list": "(tasks)"
},
{
"docstring... | [
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 can_rearrange(s, k):\n from collections import Counter\n import heapq\n\n freq = Counter(s)\n max_freq = max(freq.values())\n\n if (max_freq - 1... | trial_gpt4o_3 | {
"original_instruction": "You are given a string S consisting of lowercase English letters and an integer K. Your goal is to determine whether it is possible to rearrange the characters in the string S such that there are at most K consecutive identical characters.\n\n-----Input:-----\n- The first line of input cont... | 0.679598 | Taco_23145 | C | [
"can_rearrange",
"solve",
"preprocess_input"
] | 3 | [
[
"solve",
"can_rearrange"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f79773bbe1db9437337e656c009cf84ad1bfff43 | 34485964d6105a097f76c65c003c21068fe8c948 | |||
v1.0 | complete | Taco | Taco_23590_C | def find_tree_clusters_from_input(n: int, m: int, grid_input: List[str]) -> int:
"""
Find the number of tree clusters in a grid.
Parameters:
n (int): Number of rows in the grid.
m (int): Number of columns in the grid.
grid_input (List[str]): List of strings representing the grid rows, each cont... | def find_tree_clusters(grid):
"""
Returns the number of tree clusters in the given grid.
Parameters:
grid (list of list of int): 2D grid representing the forest.
Returns:
int: Number of tree clusters.
"""
def dfs(x, y):
# If out of bounds or already visited or empty cell, retur... | from solution import find_tree_clusters_from_input
def test_find_tree_clusters_sample1():
n = 4
m = 4
grid_input = [
"1 1 0 0",
"1 0 0 1",
"0 0 1 0",
"0 1 1 1"
]
assert find_tree_clusters_from_input(n, m, grid_input) == 3
def test_find_tree_clusters_sample2():
n... | [
{
"docstring": "Returns the number of tree clusters in the given grid.\n\nParameters:\ngrid (list of list of int): 2D grid representing the forest.\n\nReturns:\nint: Number of tree clusters.",
"function_declaration": "def find_tree_clusters(grid):",
"function_name": "find_tree_clusters",
"parameter_... | [
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 find_tree_clusters(grid):\n \"\"\"\n Returns the number of tree clusters in the given grid.\n\n Parameters:\n grid (list o... | trial_gpt4o_1 | {
"original_instruction": "In a dense forest, there is a grid of square cells, each cell representing a portion of the forest. Some of these cells contain trees (marked with `1`), and some are empty (marked with `0`). A tree cluster is defined as a group of connected `1`s, where two `1`s are considered \"connected\" ... | 0.542983 | Taco_23590 | C | [
"find_tree_clusters",
"find_tree_clusters_from_input"
] | 2 | [
[
"find_tree_clusters_from_input",
"find_tree_clusters"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4ad4fcb248091f68627db0d6def42f530ab26aa | 9da4710c978398652e60bbaeacfa909a41a02547 | |||
v1.0 | complete | Taco | Taco_23761_C | from typing import List
def find_median(sequence: List[int]) -> float:
"""
Returns the median of a given sequence of integers.
>>> find_median([3, 1, 2])
2
>>> find_median([10, 20, 30, 40])
25.0
"""
def process_sequences(input_lines: List[str]) -> List[float]:
"""
Process... | def find_median(sequence):
"""
Returns the median of a given sequence of integers.
"""
sequence.sort()
n = len(sequence)
if n % 2 == 1:
median = sequence[n // 2]
else:
median = (sequence[n // 2 - 1] + sequence[n // 2]) / 2
return median
def process_sequences(input_lines... | from solution import find_median, process_sequences
def test_find_median_odd_length():
assert find_median([3, 1, 2]) == 2
assert find_median([10, 20, 30, 40, 50]) == 30
def test_find_median_even_length():
assert find_median([10, 20, 30, 40]) == 25
assert find_median([5, 3, 8, 1]) == 4
def test_proces... | [
{
"docstring": "Returns the median of a given sequence of integers.",
"function_declaration": "def find_median(sequence):",
"function_name": "find_median",
"parameter_list": "(sequence)"
},
{
"docstring": "Processes multiple lines of integer sequences and returns the medians.",
"function... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_median(seq):\n \"\"\"\n Calculate the median of a list of integers.\n \"\"\"\n seq.sort()\n n = len(seq)\n if n % 2 == 1:\n ... | trial_gpt4o_2 | {
"original_instruction": "Write a program that reads sequences of integers and outputs the median for each sequence.\n\nThe median is the middle number in a sorted, odd-length list of numbers, or the average of the two middle numbers in a sorted, even-length list.\n\nConstraints\n\n* Each sequence contains between 1... | 0.750261 | Taco_23761 | C | [
"find_median",
"process_sequences"
] | 2 | [
[
"process_sequences",
"find_median"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8dd4e51d02a704f10b0b459e4c0a24fe23415460 | 666cbc49353fc9be98c5fdcaed83a0e427e8ba87 | |||
v1.0 | complete | Taco | Taco_22980_C | def can_collect_mana(grid, N, target):
"""
Determines if a path exists from (0, 0) to (N-1, N-1) with the sum exactly equal to target.
"""
def dfs(grid, N, target, current_sum, x, y):
if x >= N or y >= N:
return False
current_sum += grid[x][y]
if current_sum > target:
return Fal... | def can_collect_mana(grid, N, target):
"""
Determines if a path exists from (0, 0) to (N-1, N-1) with the sum exactly equal to target.
"""
return dfs(grid, N, target, 0, 0, 0)
def dfs(grid, N, target, current_sum, x, y):
if x >= N or y >= N:
return False
current_sum += grid[x][y]
if... | def test_enchanted_forest():
test_cases = [
(4, 14,
[
[5, 3, 2, 1],
[1, 2, 3, 4],
[1, 1, 1, 1],
[4, 1, 2, 1]
]),
(4, 10,
[
[5, 3, 2, 1],
[1, 2, 3, 4],
[1, 1, 1, 1],
[4,... | [
{
"docstring": "Determines if a path exists from (0, 0) to (N-1, N-1) with the sum exactly equal to target.",
"function_declaration": "def can_collect_mana(grid, N, target):",
"function_name": "can_collect_mana",
"parameter_list": "(grid, N, target)"
},
{
"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": "def can_collect_mana(grid, N, target):\n \"\"\"\n Determines if a path exists from (0, 0) to (N-1, N-1) with the sum exactly equal to target.\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "In a land far away, there is an enchanted forest where magical tiles are laid out in a grid format. Each tile has a specific mana level, which is represented by an integer. The forest is guarded by an ancient spirit who only allows those who can collect a series of tiles such that the sum o... | 0.536782 | Taco_22980 | C | [
"can_collect_mana",
"dfs",
"enchanted_forest"
] | 3 | [
[
"can_collect_mana",
"dfs"
],
[
"enchanted_forest",
"can_collect_mana"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 97ea60cbbc141f9da8bd40c7b6493741b84fc250 | 33636f3e98070dee71a425fcc61ba6a335db2970 | |||
v1.0 | complete | Taco | Taco_23491_C | def is_prime(n: int) -> bool:
"""
Check if a number n is prime. A number is prime if it is greater than 1 and is only divisible by 1 and itself.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(29)
True
>>> is_prime(1)
False
>>> is_prime(0)
False
>>> is_pr... | def is_prime(n):
"""
Check if a number n is prime. A number is prime if it is greater than 1 and is only divisible by 1 and itself.
"""
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 % ... | from solution import is_prime, is_palindrome, smallest_prime_palindrome
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
de... | [
{
"docstring": "Check if a number n is prime. A number is prime if it is greater than 1 and is only divisible by 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number n is a palindrome. A number i... | [
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 Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ... | trial_gpt4o_2 | {
"original_instruction": "Polycarp is fascinated by prime numbers and enjoys playing with them. One day, he thought of a problem involving prime numbers and asked you to solve it.\n\nPolycarp defines a prime palindrome number as a number that is both prime and a palindrome. A palindrome is a number that remains the ... | 0.716317 | Taco_23491 | C | [
"is_prime",
"is_palindrome",
"smallest_prime_palindrome"
] | 3 | [
[
"smallest_prime_palindrome",
"is_palindrome"
],
[
"smallest_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1e0309af47123f934c7b304c572eb322b6e1d05b | dceced66a735d63e52bf29b0fa52a4bec2c6da4d | |||
v1.0 | complete | Taco | Taco_22915_C | from datetime import datetime
from typing import List, Tuple
def parse_time(time_str: str) -> datetime:
""" Convert a time string in 'hh:mm' format to a datetime object.
Args:
time_str (str): Time string in 'hh:mm' format.
Returns:
datetime: Corresponding datetime object.
"""
... | from datetime import datetime
def parse_time(time_str):
return datetime.strptime(time_str, '%H:%M')
def max_non_overlapping_tasks(tasks):
tasks.sort(key=lambda x: x[1]) # Sort by end time
count = 0
last_end_time = datetime.min
for start, end in tasks:
if start >= last_end_time:
... | def test_parse_time():
assert parse_time('09:00') == datetime.strptime('09:00', '%H:%M')
assert parse_time('23:59') == datetime.strptime('23:59', '%H:%M')
def test_max_non_overlapping_tasks():
tasks = [(parse_time('09:00'), parse_time('11:00')),
(parse_time('13:00'), parse_time('14:00')),
... | [
{
"docstring": null,
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def max_non_overlapping_tasks(tasks):",
"function_name": "max_non_overlapping_tasks",
"paramete... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef parse_time(time_str):\n return datetime.strptime(time_str, '%H:%M')\n\ndef max_non_overlapping_tasks(tasks):\n tasks.sor... | trial_gpt4o_0 | {
"original_instruction": "### Task Scheduling\n\nAlice works as a task manager and often has to deal with a series of tasks that need to be scheduled. Each task has a start time and an end time, and no two tasks can be active at the same time due to the constraints of the system. Your job is to write a program that ... | 0.614986 | Taco_22915 | C | [
"parse_time",
"max_non_overlapping_tasks",
"process_input",
"main"
] | 4 | [
[
"process_input",
"max_non_overlapping_tasks"
],
[
"process_input",
"parse_time"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 795c0c9f9a69ef1a56540019e580f41890b611c0 | f93b3f32367535183f726cd0f79e86a93d942941 | |||
v1.0 | complete | Taco | Taco_23818_C | def max_sum_subgrid(grid: List[List[int]]) -> int:
"""
Given a grid of positive integers, return the largest sum of any subgrid.
>>> max_sum_subgrid([[1, 2, 3], [4, 5, 6]])
21
>>> max_sum_subgrid([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
9
>>> max_sum_subgrid([[1, 2], [3, 4]])
10
>>> m... | def max_sum_subgrid(grid):
"""
Given a grid of positive integers, return the largest sum of any subgrid.
"""
m = len(grid)
n = len(grid[0])
max_sum = -float('inf')
for top_row in range(m):
row_sum = [0] * n
for bottom_row in range(top_row, m):
for col in... | def test_largest_sum_subgrid_case1():
grid = [
[1, 2, 3],
[4, 5, 6]
]
assert max_sum_subgrid(grid) == 21
def test_largest_sum_subgrid_case2():
grid = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
assert max_sum_subgrid(grid) == 9
def test_largest_sum_subgrid_case3... | [
{
"docstring": "Given a grid of positive integers, return the largest sum of any subgrid.",
"function_declaration": "def max_sum_subgrid(grid):",
"function_name": "max_sum_subgrid",
"parameter_list": "(grid)"
},
{
"docstring": "Helper function to find the maximum sum subarray using Kadane's ... | [
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 max_sum_subgrid(m, n, grid):\n def kadane(arr):\n max_sum = current_sum = arr[0]\n for num in arr[1:]:\n current_sum = max(num, cur... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid with $m$ rows and $n$ columns. Each cell in the grid contains a positive integer value. You want to find a subgrid (a rectangular part of the grid) such that the sum of the integers within it is as large as possible. \n\nNote that the subgrid must be at least $1 \\times... | 0.649093 | Taco_23818 | C | [
"max_sum_subgrid",
"kadane"
] | 2 | [
[
"max_sum_subgrid",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c63825c184264f31b0436c1ff5352a234efbd27e | 5e7e423ea23ea79bfa9d36da710d44c2d726dae1 | |||
v1.0 | complete | Taco | Taco_24039_C | def is_prime(num):
"""
Helper function to check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(11) True
>>> is_prime(15) False
"""
pass
def next_prime(n):
"""
Returns the smallest prime number greater than n.
>>> next_p... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
return... | from solution import is_prime, next_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_next_prime():
assert next_prime(10) == 11
assert next_prime(11) == 13
asser... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than n.",
"function_declaration": "def next_prime(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 Check 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": "Alice loves playing with numbers, especially prime numbers. She recently came up with a challenge to find the smallest prime number greater than a given input number 'n'. Write a program to help Alice out. The program should take an integer input 'n' and return the smallest prime number tha... | 0.864738 | Taco_24039 | C | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90c42d5c27b87b2164df7f886fe86efa7922fe8d | 9a47e14d52f61d4d4f7bcd3b8ead1225d1103b25 | |||
v1.0 | complete | Taco | Taco_24090_C | from typing import List, Tuple
def degrees_of_separation(n: int, m: int, friendships: List[Tuple[int, int]], q: int, queries: List[Tuple[int, int]]) -> List[int]:
"""Write a program to simulate a simple social network by reading a list of friendships and then processing queries to determine the degrees of separati... | from collections import deque, defaultdict
def build_graph(friendships, n):
graph = defaultdict(list)
for u, v in friendships:
graph[u].append(v)
graph[v].append(u)
return graph
def bfs_shortest_path(graph, start, goal):
if start == goal:
return 0
visited = set()
q... | from solution import degrees_of_separation
def test_degrees_of_separation():
n, m = 5, 4
friendships = [(1, 2), (2, 3), (3, 4), (4, 5)]
q = 3
queries = [(1, 5), (1, 3), (2, 5)]
expected_output = [4, 2, 3]
assert degrees_of_separation(n, m, friendships, q, queries) == expected_output
def t... | [
{
"docstring": null,
"function_declaration": "def build_graph(friendships, n):",
"function_name": "build_graph",
"parameter_list": "(friendships, n)"
},
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(graph, start, goal):",
"function_name": "bfs_shortest_path",
... | [
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": "from collections import deque, defaultdict\n\ndef bfs_degree_of_separation(n, friendships, queries):\n graph = defaultdict(list)\n for u, v in friendships:\n... | trial_gpt4o_2 | {
"original_instruction": "Write a program to simulate a simple social network by reading a list of friendships and then processing queries to determine the degrees of separation between users.\n\nConstraints\n\n* $2 \\leq n \\leq 200$ (number of users)\n* $1 \\leq m \\leq 10^4$ (number of friendships)\n\nInput\n\n- ... | 0.634708 | Taco_24090 | C | [
"build_graph",
"bfs_shortest_path",
"degrees_of_separation"
] | 3 | [
[
"degrees_of_separation",
"bfs_shortest_path"
],
[
"degrees_of_separation",
"build_graph"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9a866edc080a0fdbf40f5b6668cb0ba7e474db63 | 199c18cb2073a3237038f505b64dc0a37832071f | |||
v1.0 | complete | Taco | Taco_23952_C | from collections import defaultdict, deque
from typing import List, Tuple
def longest_path_dag(N: int, M: int, edges: List[Tuple[int, int, int]]) -> int:
""" Compute the length of the longest path in a directed graph that does not revisit any node.
Args:
N : int : number of nodes in the graph
M : ... | from collections import defaultdict, deque
def longest_path_dag(N, M, edges):
# Construct the adjacency list
graph = defaultdict(list)
indegree = [0] * (N + 1)
for u, v, w in edges:
graph[u].append((v, w))
indegree[v] += 1
# Topological Sort using Kahn's Algorithm
topo_sort = [... | def test_longest_path_dag():
# Test Case 1
N, M = 4, 4
edges = [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 3, 2)]
assert longest_path_dag(N, M, edges) == 12
# Test Case 2
N, M = 3, 2
edges = [(1, 2, 5), (2, 3, 7)]
assert longest_path_dag(N, M, edges) == 12
# Test Case 3
N, M = 3,... | [
{
"docstring": null,
"function_declaration": "def longest_path_dag(N, M, edges):",
"function_name": "longest_path_dag",
"parameter_list": "(N, M, edges)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_list": "()"
}
] | [
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": "from collections import defaultdict, deque\nimport sys\n\ndef longest_path(N, M, edges):\n def topological_sort():\n in_degree = [0] * (N + 1)\n f... | trial_gpt4o_9 | {
"original_instruction": "Lily has a directed graph with N nodes and M edges. Each edge has a weight associated with it. Lily wants to find the longest path in the graph that doesn't revisit any node. The graph may contain cycles.\n\nConstraints\n\n* 1 \\leq N \\leq 1000\n* 0 \\leq M \\leq 5000\n* 1 \\leq weight of ... | 0.569102 | Taco_23952 | C | [
"longest_path_dag",
"solve"
] | 2 | [
[
"solve",
"longest_path_dag"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1e5c7978523a5b6182fa7470327dffa241ec191f | 858fc710047064046b292078235d8572f4d7b56b | |||
v1.0 | complete | Taco | Taco_23895_C | def parse_input(M: int, areas_info: List[str], V: int, volunteer_info: List[str]) -> Tuple[Dict[str, Set[int]], Dict[str, List[str]]]:
""" Parse the input information to get areas and volunteers data
>>> parse_input(2, ["Area1 1 2 3", "Area2 2 4"], 1, ["Vol1 Area1 Area2"])
({"Area1": {1, 2, 3}, "Area2": {2... | from itertools import combinations
def parse_input(M, areas_info, V, volunteer_info):
areas = {} # Dictionary to store areas and their households
volunteers = {} # Dictionary to store volunteers and their coverage
for area_info in areas_info:
parts = area_info.split()
area_name = par... | def test_parse_input():
M = 2
areas_info = ["Area1 1 2 3", "Area2 2 4"]
V = 1
volunteer_info = ["Vol1 Area1 Area2"]
areas, volunteers = parse_input(M, areas_info, V, volunteer_info)
assert areas == {"Area1": {1, 2, 3}, "Area2": {2, 4}}
assert volunteers == {"Vol1": ["Area1", "Area2"]}
def t... | [
{
"docstring": null,
"function_declaration": "def parse_input(M, areas_info, V, volunteer_info):",
"function_name": "parse_input",
"parameter_list": "(M, areas_info, V, volunteer_info)"
},
{
"docstring": null,
"function_declaration": "def max_unique_households(M, areas_info, V, volunteer... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom typing import List, Dict, Set\n\ndef max_unique_households_covered(area_data: List[str], volunteer_data: List[str]) -> int... | trial_gpt4o_1 | {
"original_instruction": "Your small community organizes a network of volunteers who assist with delivering groceries to those unable to venture out, particularly focusing on elderly individuals and those with disabilities. Each volunteer is responsible for delivering to specific areas within the community, and each... | 0.58676 | Taco_23895 | C | [
"parse_input",
"max_unique_households"
] | 2 | [
[
"max_unique_households",
"parse_input"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 03dc16f61f6c1b0df6a1175b34f5cdca758943d5 | bd0de69e47c923404bcec9abebbfbe05f37cb5c0 | |||
v1.0 | complete | Taco | Taco_24054_C | import math
from typing import List
def is_prime(n: int) -> bool:
"""
Checks if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
... | import math
def is_prime(n):
"""
Checks if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6... | from solution import filterPrimes
def test_filterPrimes_all_prime():
assert filterPrimes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filterPrimes_no_prime():
assert filterPrimes([1, 4, 6, 8, 9, 10]) == []
def test_filterPrimes_mixed():
assert filterPrimes([10, 17, 18, 19, 20]) == [17, 19]
assert f... | [
{
"docstring": "Checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters a list of integers to return only the prime numbers.\n\n:param numbers: List of integers\n:return: List of prime intege... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_0 | {
"original_instruction": "You have been tasked with developing a function to analyze a list of integers and determine which of them are \"prime\". A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Given a list of integers, your function should return a new list containi... | 0.795263 | Taco_24054 | C | [
"is_prime",
"filterPrimes"
] | 2 | [
[
"filterPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 673c0b1bae47c04ad3259cc2a5835db0f2223546 | f25eb254b8b3fb80f3dd3dc73b8cf824132e7243 | |||
v1.0 | complete | Taco | Taco_24321_C | def palindrome_game(T: int, test_cases: List[Tuple[int, str, int, List[Tuple[int, int, int]]]]) -> List[str]:
"""Determine if the resulting string after performing a series of rotations is a palindrome for each test case.
>>> palindrome_game(2, [(5, "abcde", 2, [(1, 3, 1), (2, 5, 2)]), (3, "aab", 1, [(1, 3... | def rotate_substring(s, L, R, K):
"""
Rotates the substring s[L:R+1] to the right by K positions
"""
L -= 1
R -= 1
K %= (R - L + 1) # Adjust K to make sure it is within the length of the substring
rotated_part = s[L:R+1][-K:] + s[L:R+1][:-K]
return s[:L] + rotated_part + s[R+1:]
def is... | from solution import palindrome_game
def test_palindrome_game():
# Given example test cases
T = 2
test_cases = [
(5, "abcde", 2, [(1, 3, 1), (2, 5, 2)]), # After all rotations -> "cbdae" -> NOT a palindrome -> "NO"
(3, "aab", 1, [(1, 3, 2)]) # After all rotations -> "baa" -> a palindrome... | [
{
"docstring": "Rotates the substring s[L:R+1] to the right by K positions",
"function_declaration": "def rotate_substring(s, L, R, K):",
"function_name": "rotate_substring",
"parameter_list": "(s, L, R, K)"
},
{
"docstring": "Checks if the given string s is a palindrome",
"function_decl... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def perform_rotation(S, L, R, K):\n # Convert 1-based indices to 0-based\n L -= 1\n R -= 1\n # Extract substring to be rotated\n sub_str = S[L:R + 1... | trial_gpt4o_2 | {
"original_instruction": "Farah is teaching her students about string manipulation and palindrome checking. She created a fun game and wants to test her students' coding skills with this game. The rules of the game are as follows:\n\nFarah writes down a string $S$ of length $N$ consisting of lowercase English letter... | 0.738898 | Taco_24321 | C | [
"rotate_substring",
"is_palindrome",
"palindrome_game"
] | 3 | [
[
"palindrome_game",
"is_palindrome"
],
[
"palindrome_game",
"rotate_substring"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 724242ac0f4eb6d46c1b5d6122ba6d6da89dc0e2 | d2a9e1f64d9a14049d4b99ffbcc5a2aa78460884 | |||
v1.0 | complete | Taco | Taco_23970_C | from typing import List
class Node:
def __init__(self, age):
self.age = age
self.left = None
self.right = None
def insert_node(root, age):
if root is None:
return Node(age)
else:
if age < root.age:
root.left = insert_node(root.left, age)
elif age... | from collections import defaultdict
class Node:
def __init__(self, age):
self.age = age
self.left = None
self.right = None
def insert_node(root, age):
if root is None:
return Node(age)
else:
if age < root.age:
root.left = insert_node(root.left, age)
... | from solution import manage_zoo
def test_manage_zoo_case_1():
n = 6
animal_data = [
"lion 5",
"tiger 3",
"lion 3",
"elephant 7",
"tiger 2",
"lion 9"
]
output = manage_zoo(n, animal_data)
expected_output = ["lion", "5 3 9", "tiger", "3 2", "elephant", ... | [] | [
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, age):\n self.age = age\n self.left = None\n self.right = None\n\ndef insert(root, age):\n if root i... | trial_gpt4o_2 | {
"original_instruction": "Dreamoon has a new challenge for his zoo management program. He manages a zoo where the animals are categorized by their species and age. Given a list of species and the ages of animals from each species, Dreamoon wants to construct a binary tree for each species where each node represents ... | 0.471641 | Taco_23970 | C | [
"insert_node",
"pre_order_traversal",
"build_and_traverse_bst",
"manage_zoo"
] | 4 | [
[
"build_and_traverse_bst",
"insert_node"
],
[
"build_and_traverse_bst",
"pre_order_traversal"
],
[
"manage_zoo",
"build_and_traverse_bst"
]
] | 3 | [] | false | [
"Node"
] | true | pytest | true | [] | true | d222f54ae35d33aef3dd33bf6b21d0e728da7b24 | 71c913247847f051fac4a15fb1c6b11573851a9c | |||
v1.0 | complete | Taco | Taco_24340_C | def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, else False. """
pass
def level_checker(levels: Dict[str, int]) -> int:
"""
Returns the average level (rounded to the nearest integer) of names whose levels are prime numbers.
If there are no prime levels, returns 0.
Ex... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def level_check... | from solution import level_checker
def test_level_checker_with_prime_levels():
assert level_checker({"Alice": 2, "Bob": 4, "Charlie": 5, "David": 9, "Eve": 11}) == 6
def test_level_checker_without_prime_levels():
assert level_checker({"Anna": 8, "Ben": 10, "Cara": 15, "Dani": 20}) == 0
def test_level_checker... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the average level (rounded to the nearest integer) of names whose levels are prime numbers.\nIf there... | [
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 Determines if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\... | trial_gpt4o_1 | {
"original_instruction": "In this exercise, you need to create a function called **level_checker** that will take a dictionary of names and their corresponding levels as input. Each level is represented as an integer. The task is to assess the average level of the names whose levels are prime numbers and return the ... | 0.694115 | Taco_24340 | C | [
"is_prime",
"level_checker"
] | 2 | [
[
"level_checker",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0844a1cee76e806efc4ff2650f09b1f42dc535a5 | 3582b3c370ece11981136d57f1b5d717e910e81c | |||
v1.0 | complete | Taco | Taco_24096_C | def hilltops_surveillance(n, m, edges, k, r):
"""
Determine the optimal placement of the watchtowers to maximize the total number of hilltops that can be monitored
directly or indirectly.
Args:
n (int): number of hilltops
m (int): number of paths between hilltops
edges (List[Tuple[int, ... | from collections import deque
def bfs(graph, start, r):
"""
Perform BFS and return nodes covered within range limit `r` starting from `start` node.
"""
visited = set()
queue = deque([(start, 0)])
visited.add(start)
while queue:
current, dist = queue.popleft()
if dist < ... | from solution import hilltops_surveillance
def test_example_case():
n = 6
m = 7
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (4, 5), (5, 6)]
k = 3
r = 1
assert hilltops_surveillance(n, m, edges, k, r) == 6
def test_single_node():
n = 1
m = 0
edges = []
k = 1
r = 1
a... | [
{
"docstring": "Perform BFS and return nodes covered within range limit `r` starting from `start` node.",
"function_declaration": "def bfs(graph, start, r):",
"function_name": "bfs",
"parameter_list": "(graph, start, r)"
},
{
"docstring": "Returns the maximum number of hilltops that can be m... | [
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": "from collections import deque, defaultdict\n\ndef max_monitored_hilltops(n, m, paths, k, r):\n # Convert the list of paths into an adjacency list\n graph = d... | trial_gpt4o_4 | {
"original_instruction": "A city is planning to build a series of watchtowers on strategic hilltops for surveillance. Each hilltop is represented by a node, and there are possible paths (edges) between the hilltops. The city needs to place a specific number of watchtowers such that the surveillance area is maximized... | 0.635856 | Taco_24096 | C | [
"bfs",
"hilltops_surveillance"
] | 2 | [
[
"hilltops_surveillance",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ac9538cde9f6bb418960931063ecaf6e3ae089df | 3e33248f3f559af6050a51f35aabec95e388c90a | |||
v1.0 | complete | Taco | Taco_24425_C | def contains_magic_square(grid):
"""
Returns "YES" if the grid contains any magic square of size 3x3, otherwise "NO".
>>> contains_magic_square([[4, 9, 2, 3], [3, 5, 7, 8], [8, 1, 6, 3], [2, 7, 6, 9]])
'YES'
>>> contains_magic_square([[4, 8, 2, 4, 9], [3, 5, 7, 23, 5], [8, 1, 6, 4, 1], [1, 9, 8, 2,... | def is_magic_square(matrix, row, col):
"""
Helper function to check if a 3x3 grid with top-left corner at (row, col)
is a magic square.
"""
s = set()
# Sum of the first row
magic_sum = sum(matrix[row][col:col+3])
for i in range(3):
if sum(matrix[row+i][col:col+3]) != magic_s... | from solution import contains_magic_square
def test_magic_square_1():
grid = [
[4, 9, 2, 3],
[3, 5, 7, 8],
[8, 1, 6, 3],
[2, 7, 6, 9]
]
assert contains_magic_square(grid) == "YES"
def test_magic_square_2():
grid = [
[4, 8, 2, 4, 9],
[3, 5, 7, 23, 5],
... | [
{
"docstring": "Helper function to check if a 3x3 grid with top-left corner at (row, col)\nis a magic square.",
"function_declaration": "def is_magic_square(matrix, row, col):",
"function_name": "is_magic_square",
"parameter_list": "(matrix, row, col)"
},
{
"docstring": "Returns \"YES\" if t... | [
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_magic_square(grid, row, col):\n \"\"\"\n Check if the 3x3 grid starting at (row, col) is a magic square.\n \"\"\"\n target_sum = grid[row][col] ... | trial_gpt4o_2 | {
"original_instruction": "You are given an n x n grid of cells filled with different integers. Your task is to identify if there exists a \"magic square\" of size 3x3 within this grid. A \"magic square\" is a 3x3 grid where every row, column, and both diagonals all sum to the same value.\n\nInput\n\nThe first line c... | 0.634701 | Taco_24425 | C | [
"is_magic_square",
"contains_magic_square"
] | 2 | [
[
"contains_magic_square",
"is_magic_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d55e1ae209e3efa5b9f36fec87dfb0416175332 | b4af701d43fab4df711d6d52e81457c510a6deef |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.