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 | instruct | Taco | Taco_31176_I | In a distant galaxy, inhabitants use a unique numeric system based on unusual multiplication rules. They have a special 2-dimensional grid where numbers multiply differently based on their position.
The planet's grid is represented by an N x N matrix where matrix[i][j] represents the multiplication result. You have to... | def build_matrix(N):
matrix = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(N):
if i == j:
matrix[i][j] = i * i
elif j > i:
matrix[i][j] = i * j
else:
matrix[i][j] = i * j
return matrix
def... | from solution import build_matrix, format_matrix, solve
def test_example_1():
test_cases = [3]
expected_output = ["0 0 0 0 1 2 0 2 4"]
assert solve(test_cases) == expected_output
def test_example_2():
test_cases = [4]
expected_output = ["0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9"]
assert solve(test_case... | [
{
"docstring": null,
"function_declaration": "def build_matrix(N):",
"function_name": "build_matrix",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def format_matrix(matrix):",
"function_name": "format_matrix",
"parameter_list": "(matrix)"
},
{
... | [
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_matrix(N):\n matrix = [[0] * N for _ in range(N)]\n \n for i in range(N):\n for j in range(N):\n if i == j:\n m... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031176",
"row_id": 31176,
"seed_ids": "[15448]"
} | 0.719658 | Taco_31176 | I | [
"build_matrix",
"format_matrix",
"solve"
] | 3 | [
[
"solve",
"build_matrix"
],
[
"solve",
"format_matrix"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9635e53694434627d66d0c23cd469d942b40f8e3 | 89d4a7f8e8f439c430a43208e9e3fbc198f50e65 | |||
v1.0 | instruct | Taco | Taco_31185_I | An organization is considering numbers to be classified as "doubly prime." A number is doubly prime if both the number itself and the number minus two are prime.
For example, 5 is a doubly prime number because both 5 and 3 are prime, but 4 is not a doubly prime because neither 4 nor 2 is prime.
Given a positive integ... | 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 is_... | from solution import is_prime, is_doubly_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
def test_is_doubly_prime():
assert is_doubly_prime(5) == "yes"
assert is_doubly_prim... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to determine if a number is doubly prime.",
"function_declaration": "def is_doubly_prime(n):",... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n retu... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00031185",
"row_id": 31185,
"seed_ids": "[5335]"
} | 0.614452 | Taco_31185 | I | [
"is_prime",
"is_doubly_prime"
] | 2 | [
[
"is_doubly_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8d8bab48c83952f5bd6599fb8ed7cb25886641a | 2fe22e4f063a1c4a12cb0748c760baff93b6df7d | |||
v1.0 | instruct | Taco | Taco_31252_I | In an alphabetical string, a character's value is its position in the alphabet, a = 1, b = 2, ..., z = 26. Given a word, calculate the score of this word by summing up the values of all its characters.
For example, for the word "abc", its score would be 1 + 2 + 3 = 6.
In this task, you need to determine if there exi... | def calculate_char_value(c):
return ord(c) - ord('a') + 1
def find_subsequence_score(T, test_cases):
results = []
for i in range(T):
N, word, K = test_cases[i]
prefix_sum = [0] * (N + 1)
for j in range(N):
prefix_sum[j + 1] = prefix_sum[j] + calculate_char_value... | def test_sample_input_1():
T = 2
test_cases = [(3, "abc", 6), (5, "zyxwv", 15)]
expected_output = ["YES", "NO"]
assert find_subsequence_score(T, test_cases) == expected_output
def test_single_character_word():
T = 1
test_cases = [(1, "a", 1)]
expected_output = ["YES"]
assert find_subseq... | [
{
"docstring": null,
"function_declaration": "def calculate_char_value(c):",
"function_name": "calculate_char_value",
"parameter_list": "(c)"
},
{
"docstring": null,
"function_declaration": "def find_subsequence_score(T, test_cases):",
"function_name": "find_subsequence_score",
"... | [
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 character_position_score(char):\n \"\"\"\n Returns the alphabetical score of a lowercase character.\n \"\"\"\n return ord(char) - ord('a') + 1\n\nd... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031252",
"row_id": 31252,
"seed_ids": "[2904]"
} | 0.74651 | Taco_31252 | I | [
"calculate_char_value",
"find_subsequence_score"
] | 2 | [
[
"find_subsequence_score",
"calculate_char_value"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4fa16b950ef41b2b0a043627f8bfa2b2808c0428 | 518de612f03821d961cbe71a9ff1eb1de551443a | |||
v1.0 | instruct | Taco | Taco_31288_I | Given an m x n grid of characters representing a maze, your task is to determine if there is a valid path from the player's starting position 'S' to an exit 'E'. The maze contains walls represented by '#', free spaces represented by '.', and possibly some one-way doors represented by '^', 'v', '<', '>', which indicate ... | def find_start_end_positions(grid):
"""
Find the positions of 'S' and 'E' in the grid.
"""
start = end = None
for i, row in enumerate(grid):
for j, char in enumerate(row):
if char == 'S':
start = (i, j)
elif char == 'E':
end = (i, j)
... | def test_case_1():
grid = [["#","#","#","#","#"],
["#","S",".",".","#"],
["#",".","#","E","#"],
["#",".","#","#","#"],
["#","#","#","#","#"]]
assert is_valid_maze_path(grid) == True
def test_case_2():
grid = [["#","#","#","#","#"],
["#","S",".","#... | [
{
"docstring": "Find the positions of 'S' and 'E' in the grid.",
"function_declaration": "def find_start_end_positions(grid):",
"function_name": "find_start_end_positions",
"parameter_list": "(grid)"
},
{
"docstring": "Check if a move in the given direction is valid.",
"function_declarat... | [
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 has_valid_path(grid):\n from collections import deque\n\n directions = {\n 'up': (-1, 0),\n 'down': (1, 0),\n 'left': (0, -1),\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00031288",
"row_id": 31288,
"seed_ids": "[3142]"
} | 0.680816 | Taco_31288 | I | [
"find_start_end_positions",
"is_valid_move",
"find_path",
"is_valid_maze_path"
] | 4 | [
[
"find_path",
"is_valid_move"
],
[
"is_valid_maze_path",
"find_path"
],
[
"is_valid_maze_path",
"find_start_end_positions"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 380ee7b5ad0b09dd6e4f825374c6157633ca48c0 | 3a559cd6d96b7276481a81210a1395279d79248a | |||
v1.0 | instruct | Taco | Taco_31309_I | A famous restaurant chain wants to optimize its delivery routes to ensure meals are delivered as quickly as possible. They provide a map of the city, which is composed of a number of intersections connected by streets. Each street has a certain length in meters.
The problem is to determine the shortest possible delive... | import heapq
def dijkstra(graph, start, end, n):
pq = [(0, start)]
distances = {vertex: float('infinity') for vertex in range(1, n + 1)}
distances[start] = 0
previous_nodes = {vertex: None for vertex in range(1, n + 1)}
visited = set()
while pq:
current_distance, current_vertex = heapq... | def test_shortest_delivery_route():
n = 4
e = 4
roads = [(1, 2, 10), (2, 3, 20), (3, 4, 10), (4, 1, 40)]
start = 1
end = 3
assert shortest_delivery_route(n, e, roads, start, end) == (30, [1, 2, 3])
def test_shortest_delivery_route_impossible():
n = 4
e = 3
roads = [(1, 2, 5), (2, 3,... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, end, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_delivery_route(n, e, roads, start, end):",
"function_name": "short... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start, end, n):\n pq = [(0, start, [start])]\n visited = set()\n while pq:\n (distance, current_vertex, path) =... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00031309",
"row_id": 31309,
"seed_ids": "[13019]"
} | 0.778774 | Taco_31309 | I | [
"dijkstra",
"shortest_delivery_route"
] | 2 | [
[
"shortest_delivery_route",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7e8b4d652298493d33caaf6749a3d693544f21f3 | e3f6c661dbccc8a8d1234c4bb62fe1459620d9d8 | |||
v1.0 | instruct | Taco | Taco_31323_I | A large company wants to conduct an internal survey to analyze the communication efficiency between different departments. The company has n departments numbered from 1 to n. Each department communicates directly with specific other departments, and this communication is bidirectional. The efficiency of communication b... | import sys
from collections import defaultdict, deque
def find_furthest_node_and_distance(n, edges):
# Create a graph using adjacency list
graph = defaultdict(list)
for a, b in edges:
graph[a].append(b)
graph[b].append(a)
# Function to perform BFS and return the furthest node and i... | from solution import max_communication_efficiency
def test_example_case():
assert max_communication_efficiency(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 3
def test_line_structure():
assert max_communication_efficiency(4, [(1, 2), (2, 3), (3, 4)]) == 3
def test_star_structure():
assert max_communication_eff... | [
{
"docstring": null,
"function_declaration": "def find_furthest_node_and_distance(n, edges):",
"function_name": "find_furthest_node_and_distance",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def max_communication_efficiency(n, connections):",
"func... | [
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": "from collections import deque\n\ndef bfs_furthest_node(graph, start):\n \"\"\"\n Performs BFS to find the furthest node and its distance from the start node.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031323",
"row_id": 31323,
"seed_ids": "[22470]"
} | 0.588766 | Taco_31323 | I | [
"find_furthest_node_and_distance",
"max_communication_efficiency"
] | 2 | [
[
"max_communication_efficiency",
"find_furthest_node_and_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2c12b352c5c633a0493fb6fec67e7069ea15ca4 | 9fb03f234c6b86c7e0c5e62cce745b69e1ab9a0b | |||
v1.0 | instruct | Taco | Taco_31345_I | Given an integer `N`, generate a sequence of numbers such that the next number in the sequence is the sum of the squares of the digits of the current number. Return the N-th number in this sequence starting with 1.
Example 1:
Input: N = 3
Output: 10
Explanation: Starting from 1, the sequence is 1 -> 1 -> 1
Example 2:... | def sum_of_squares_of_digits(n):
"""
Returns the sum of the squares of the digits of 'n'.
"""
return sum(int(digit) ** 2 for digit in str(n))
def findNthNumber(N):
"""
Returns the N-th number in the sequence starting with 1
where the next number in the sequence is the sum of the squares of ... | from solution import findNthNumber
def test_findNthNumber_case1():
assert findNthNumber(3) == 1
def test_findNthNumber_case2():
assert findNthNumber(5) == 1
def test_findNthNumber_case3():
assert findNthNumber(10) == 1
def test_findNthNumber_case4():
assert findNthNumber(1) == 1
def test_findNthNum... | [
{
"docstring": "Returns the sum of the squares of the digits of 'n'.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns the N-th number in the sequence starting with 1\nwhere the next 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 sum_of_squares_of_digits(num):\n \"\"\"\n Helper function to compute the sum of the squares of the digits of a given number.\n \"\"\"\n return sum(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031345",
"row_id": 31345,
"seed_ids": "[21362]"
} | 0.606112 | Taco_31345 | I | [
"sum_of_squares_of_digits",
"findNthNumber"
] | 2 | [
[
"findNthNumber",
"sum_of_squares_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d542c74fc5c82ece3ff38b39c7c073f98a808268 | ac7de1d1d032ed8a714188c23fbbda42cd2767a7 | |||
v1.0 | instruct | Taco | Taco_31387_I | Binary Tree Restoration
Alex is given the task of restoring a binary tree from its in-order and pre-order traversals. As an expert coder, you have been asked to assist Alex in writing a program to reconstruct the binary tree from these traversals and then output the post-order traversal of the reconstructed tree.
###... | def build_tree(inorder, preorder):
if not inorder or not preorder:
return None
root_val = preorder.pop(0)
root_index = inorder.index(root_val)
root = TreeNode(root_val)
root.left = build_tree(inorder[:root_index], preorder)
root.right = build_tree(inorder[root_index + 1:], preo... | from solution import restore_binary_tree
def test_restore_binary_tree_one_node():
N = 1
inorder = [1]
preorder = [1]
assert restore_binary_tree(N, inorder, preorder) == [1]
def test_restore_binary_tree_example():
N = 5
inorder = [4, 2, 5, 1, 3]
preorder = [1, 2, 4, 5, 3]
assert restore... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(inorder, preorde... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031387",
"row_id": 31387,
"seed_ids": "[23275]"
} | 0.633885 | Taco_31387 | I | [
"build_tree",
"postorder_traversal",
"restore_binary_tree"
] | 3 | [
[
"restore_binary_tree",
"build_tree"
],
[
"restore_binary_tree",
"postorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8d9abc5831da8ae366916d2809fcaa5976acd2d5 | 8c92bcfd9ed74d91d2c7e8e5faa1180aedeacccd | |||
v1.0 | instruct | Taco | Taco_31408_I | #### Permutation to K-Distance Apart
You are given a permutation of integers from 1 to n inclusive. Your task is to transform the given permutation into a new permutation where for every pair of elements (i, j), where i < j and j - i = k (k-distance apart), the value of the element at position j is strictly greater th... | def transform_to_k_distance_apart(n, k, permutation):
"""
Transforms the given permutation into a new permutation where for every pair of elements (i, j),
where i < j and j - i = k (k-distance apart), the value of the element at position j is strictly
greater than the value of the element at position i.... | def test_transform_to_k_distance_apart_case_1():
assert transform_to_k_distance_apart_from_input("5 2\n1 3 2 5 4") == "1 3 2 5 4"
def test_transform_to_k_distance_apart_case_2():
assert transform_to_k_distance_apart_from_input("4 3\n4 2 3 1") == "-1"
def test_transform_to_k_distance_apart_case_3():
assert... | [
{
"docstring": "Transforms the given permutation into a new permutation where for every pair of elements (i, j),\nwhere i < j and j - i = k (k-distance apart), the value of the element at position j is strictly\ngreater than the value of the element at position i. If it is not possible, returns -1.",
"funct... | [
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 k_distance_apart(n, k, perm):\n \"\"\"\n Takes an integer n (length of permutation), an integer k (distance requirement),\n and a list perm (the permu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031408",
"row_id": 31408,
"seed_ids": "[4905]"
} | 0.759932 | Taco_31408 | I | [
"transform_to_k_distance_apart",
"parse_input",
"transform_to_k_distance_apart_from_input"
] | 3 | [
[
"transform_to_k_distance_apart_from_input",
"parse_input"
],
[
"transform_to_k_distance_apart_from_input",
"transform_to_k_distance_apart"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | b12245a1fc759c9bdc61edc4397a7bce9cb3674b | 1950ac557b4f6b26b06a575158a8329f277663f6 | |||
v1.0 | instruct | Taco | Taco_31514_I | The Grand Library is a vast collection of rare and ancient books. The library uses a unique system of categories and subcategories to organize its books. Each category is represented by a unique number, and each subcategory is a strictly descending sequence of numbers connected to a parent category.
A librarian is tas... | def can_add_books(existing_categories, new_books):
existing_numbers = set()
# Extract all category and subcategory numbers from existing categories
for category in existing_categories:
for number in category:
existing_numbers.add(number)
# Check each new book's category number
... | def test_example_1():
n = 4
existing_data = [
"10 9 8 7",
"5 4 3",
"12 11",
"20 15 10 5"
]
k = 3
new_books_data = ["6", "2", "13"]
assert check_library(n, existing_data, k, new_books_data) == "YES"
def test_example_2():
n = 3
existing_data = [
... | [
{
"docstring": null,
"function_declaration": "def can_add_books(existing_categories, new_books):",
"function_name": "can_add_books",
"parameter_list": "(existing_categories, new_books)"
},
{
"docstring": null,
"function_declaration": "def check_library(n, existing_data, k, new_books_data... | [
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_add_books(existing_categories, new_books):\n existing_set = set()\n for category in existing_categories:\n existing_set.update(category)\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031514",
"row_id": 31514,
"seed_ids": "[8759]"
} | 0.622754 | Taco_31514 | I | [
"can_add_books",
"check_library"
] | 2 | [
[
"check_library",
"can_add_books"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d9657bde8e452f782c5504b03c723649d0c9dcc7 | 94acd046dc874e9baeb5deead8a7ab76db3f0221 | |||
v1.0 | instruct | Taco | Taco_31524_I | Given a string s, determine if it is possible to rearrange the characters in the string to form a palindrome.
Input
The first line of input contains an integer T, denoting the number of test cases.
Each of the next T lines contains one string s.
Output
Print T lines, either "POSSIBLE" or "IMPOSSIBLE" (without quotes... | def can_form_palindrome(s):
"""
Determines if it's possible to rearrange the characters in the string `s` to form a palindrome.
"""
from collections import Counter
char_counts = Counter(s)
odd_count = sum(1 for count in char_counts.values() if count % 2 != 0)
return odd_count <= 1
... | from solution import can_form_palindrome, solve
def test_can_form_palindrome():
assert can_form_palindrome("civic") == True, "Test Case 1 Failed"
assert can_form_palindrome("ivicc") == True, "Test Case 2 Failed"
assert can_form_palindrome("google") == False, "Test Case 3 Failed"
assert can_form_palindr... | [
{
"docstring": "Determines if it's possible to rearrange the characters in the string `s` to form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def so... | [
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 can_form_palindrome(s):\n \"\"\"\n Determines if the characters in string s can be rearranged to form a palindrome.\n \"\"\"\n from collections imp... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031524",
"row_id": 31524,
"seed_ids": "[2414]"
} | 0.82642 | Taco_31524 | I | [
"can_form_palindrome",
"solve"
] | 2 | [
[
"solve",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8e478f26c7a874f0e9105507b91e93b70edd6d11 | b2e641fee548ca67f2de173536f0b9c7c3b7455a | |||
v1.0 | instruct | Taco | Taco_31580_I | Doctor offers to play a game with you using an unusual deck of 2N cards. Each card has a positive integer printed on it. The deck is called "balanced" if the sum of integers on the first N cards is equal to the sum of the integers on the last N cards.
For example, if N = 2 and the integers on the cards are [1, 3, 2, ... | def is_balanced_deck(cards):
N = len(cards) // 2
first_half_sum = sum(cards[:N])
second_half_sum = sum(cards[N:])
return first_half_sum == second_half_sum
def check_decks(test_cases):
results = []
for N, cards in test_cases:
if is_balanced_deck(cards):
results.append("YES")
... | from solution import is_balanced_deck, check_decks, process_input
def test_is_balanced_deck():
assert is_balanced_deck([1, 3, 2, 2]) == True
assert is_balanced_deck([1, 2, 3, 6, 1, 2]) == False
def test_check_decks():
assert check_decks([(2, [1, 3, 2, 2]), (3, [1, 2, 3, 6, 1, 2])]) == ["YES", "NO"]
def t... | [
{
"docstring": null,
"function_declaration": "def is_balanced_deck(cards):",
"function_name": "is_balanced_deck",
"parameter_list": "(cards)"
},
{
"docstring": null,
"function_declaration": "def check_decks(test_cases):",
"function_name": "check_decks",
"parameter_list": "(test_c... | [
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_balanced_deck(cards):\n N = len(cards) // 2\n first_half_sum = sum(cards[:N])\n second_half_sum = sum(cards[N:])\n return first_half_sum == seco... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031580",
"row_id": 31580,
"seed_ids": "[7471]"
} | 0.711382 | Taco_31580 | I | [
"is_balanced_deck",
"check_decks",
"process_input"
] | 3 | [
[
"check_decks",
"is_balanced_deck"
],
[
"process_input",
"check_decks"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | f4e9643cc697ecbbc34d590f627640dc36a392ab | 377c26615c50cbb29e05b0de09228347853bbac9 | |||
v1.0 | instruct | Taco | Taco_31600_I | Polycarp is fascinated by numbers and their properties. One day, he discovered a new kind of interesting number. He defines a positive integer as interesting if it does not contain the digit '7' in its decimal representation. For instance, numbers like 48, 56, and 123 are interesting, but numbers like 73, 278, and 417 ... | def is_interesting(n):
"""
Returns True if the number n does not contain the digit '7'
"""
return '7' not in str(n)
def find_nearest_interesting(k):
"""
Returns the nearest larger or equal interesting number to k
"""
while not is_interesting(k):
k += 1
return k | from solution import find_nearest_interesting
def test_nearest_interesting_from_70():
assert find_nearest_interesting(70) == 80
def test_nearest_interesting_from_123():
assert find_nearest_interesting(123) == 123
def test_nearest_interesting_from_678():
assert find_nearest_interesting(678) == 680
def te... | [
{
"docstring": "Returns True if the number n does not contain the digit '7'",
"function_declaration": "def is_interesting(n):",
"function_name": "is_interesting",
"parameter_list": "(n)"
},
{
"docstring": "Returns the nearest larger or equal interesting number to k",
"function_declaratio... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_interesting_number(k):\n \"\"\"\n Finds the smallest integer n >= k such that n does not contain the digit '7'.\n \n :param k: integer, the st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031600",
"row_id": 31600,
"seed_ids": "[4908]"
} | 0.588408 | Taco_31600 | I | [
"is_interesting",
"find_nearest_interesting"
] | 2 | [
[
"find_nearest_interesting",
"is_interesting"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 96d016ae9ab76eda56d9e350ac3caaf774741042 | 2f00c2eaffe803ccfc98f1e83129d798b570c62b | |||
v1.0 | instruct | Taco | Taco_31646_I | A popular persuasion technique involves a person posing as an emergency service operator trying to convince the “rescued” person to provide critical information. The technique relies on the ability to sound convincing, especially given the urgency of the situation. To simulate this technique in a computer program, you ... | def is_convincing(phrase):
"""
Check if the given phrase is convincing based on the criteria.
"""
keywords = {'urgent', 'emergency', 'help', 'immediate'}
exclamation_count = phrase.count('!')
has_keyword = any(keyword in phrase for keyword in keywords)
no_triple_repeats = not any(char * 3 in... | from solution import is_convincing, check_phrases
def test_is_convincing():
assert is_convincing("This is an urgent request! Please respond immediately!!") == "Convincing"
assert is_convincing("We need help!!! This is an emergency!") == "Not Convincing"
assert is_convincing("Please respond as soon as possi... | [
{
"docstring": "Check if the given phrase is convincing based on the criteria.",
"function_declaration": "def is_convincing(phrase):",
"function_name": "is_convincing",
"parameter_list": "(phrase)"
},
{
"docstring": "Returns a list of results for the given phrases.",
"function_declaratio... | [
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_convincing(phrase):\n \"\"\"\n Check if the given phrase is convincing based on the criteria.\n \"\"\"\n keywords = {'urgent', 'emergency', 'hel... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031646",
"row_id": 31646,
"seed_ids": "[58]"
} | 0.547344 | Taco_31646 | I | [
"is_convincing",
"check_phrases"
] | 2 | [
[
"check_phrases",
"is_convincing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 330b685718ce6e4c0aa8517f48203dc916a1308e | a8f7fed93d4e333cd599133868c8955e401933d0 | |||
v1.0 | instruct | Taco | Taco_31680_I | A telecommunications company is setting up a new routing system for its network of hubs. Each node in the network represents a hub and each edge represents a direct connection between two hubs with a specified latency. The company wants to ensure that there is a way to quickly determine the shortest path latency for da... | import heapq
def add_edge(graph, a, b, d):
if a not in graph:
graph[a] = {}
if b not in graph:
graph[b] = {}
graph[a][b] = d
graph[b][a] = d
def dijkstra(graph, start):
distances = {node: float('inf') for node in graph}
distances[start] = 0
priority_queue = [(0, start)]
... | import pytest
from solution import process_operations
def test_process_operations():
n = 5
q = 7
operations = [
"ADD 1 2 10",
"ADD 2 3 5",
"ADD 3 4 7",
"QUERY 1 4",
"ADD 1 4 15",
"ADD 4 5 1",
"QUERY 1 5"
]
expected = [22, 16]
assert proces... | [
{
"docstring": null,
"function_declaration": "def add_edge(graph, a, b, d):",
"function_name": "add_edge",
"parameter_list": "(graph, a, b, d)"
},
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, s... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\nclass Network:\n def __init__(self, n):\n self.n = n\n self.adj = {i: {} for i in range(1, n+1)}\n \n def add(self, a, b, d)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031680",
"row_id": 31680,
"seed_ids": "[12817]"
} | 0.638363 | Taco_31680 | I | [
"add_edge",
"dijkstra",
"process_operations"
] | 3 | [
[
"process_operations",
"add_edge"
],
[
"process_operations",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e465fd672e4de18112360f7fcb070fc86af4fba6 | 380e3ac103089a0bd4b8c0cad0139867dd88b9ed | |||
v1.0 | instruct | Taco | Taco_31755_I | ## Travel Distance Optimizer
You are required to write a function called **`optimizeTravel`** that helps in optimizing the travel distance for visiting multiple cities. The function takes two parameters:
1. **`cities`**: An array of strings, where each string represents the name of a city.
2. **`distances`**: An obje... | from itertools import permutations
def calculate_route_distance(route, distances):
total_distance = 0
for i in range(len(route) - 1):
total_distance += distances[route[i]][route[i+1]]
# Add distance to return to starting city
total_distance += distances[route[-1]][route[0]]
return total_dis... | from solution import optimizeTravel
def test_optimize_travel():
cities = ["A", "B", "C", "D"]
distances = {
"A": {"B": 10, "C": 15, "D": 20},
"B": {"A": 10, "C": 35, "D": 25},
"C": {"A": 15, "B": 35, "D": 30},
"D": {"A": 20, "B": 25, "C": 30}
}
result = optimizeTravel(c... | [
{
"docstring": null,
"function_declaration": "def calculate_route_distance(route, distances):",
"function_name": "calculate_route_distance",
"parameter_list": "(route, distances)"
},
{
"docstring": null,
"function_declaration": "def optimizeTravel(cities, distances):",
"function_name... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef calculate_total_distance(path, distances):\n total_distance = 0\n number_of_cities = len(path)\n for i in range(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031755",
"row_id": 31755,
"seed_ids": "[15495]"
} | 0.750603 | Taco_31755 | I | [
"calculate_route_distance",
"optimizeTravel"
] | 2 | [
[
"optimizeTravel",
"calculate_route_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e75d372955b90b439708f0d1b2656125c7853354 | 2dd0b99f1bf8b55c60ed9d86ea9708578b6cd19b | |||
v1.0 | instruct | Taco | Taco_31800_I | **Emergency Signal Relay**
You are given a city grid where each cell is either a building `B`, a street `S`, or a fire station `F`. The signal from a fire station can be relayed through streets to reach buildings, but cannot pass through other buildings. To ensure efficient emergency services, the city needs to determ... | def bfs_reachable_buildings(grid, h, w):
from collections import deque
fire_stations = []
buildings = set()
for i in range(h):
for j in range(w):
if grid[i][j] == 'F':
fire_stations.append((i, j))
elif grid[i][j] == 'B':
buildings... | def test_sample_1():
h = 4
w = 5
city_map = [
"BBSSB",
"BFFSB",
"BBSSB",
"BSSFB"
]
assert unreachable_buildings(h, w, city_map) == 2
def test_sample_2():
h = 3
w = 3
city_map = [
"BSB",
"BFB",
"BSB"
]
assert unreachable_bui... | [
{
"docstring": null,
"function_declaration": "def bfs_reachable_buildings(grid, h, w):",
"function_name": "bfs_reachable_buildings",
"parameter_list": "(grid, h, w)"
},
{
"docstring": null,
"function_declaration": "def unreachable_buildings(h, w, city_map):",
"function_name": "unreac... | [
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 unreachable_buildings(h, w, grid):\n from collections import deque\n \n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queue = deque()\n visi... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00031800",
"row_id": 31800,
"seed_ids": "[14294]"
} | 0.685349 | Taco_31800 | I | [
"bfs_reachable_buildings",
"unreachable_buildings"
] | 2 | [
[
"unreachable_buildings",
"bfs_reachable_buildings"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 56eb380b42d43aaba02b67d99393129f14b25548 | 27daa2612140ba25721157e19dbd545c59507c56 | |||
v1.0 | instruct | Taco | Taco_31802_I | Alex is designing a complex maze game that has numerous rooms interconnected by corridors. Each room is marked with a number from 1 to N, and each corridor connects two distinct rooms. Alex must ensure that it's possible to travel from any room to any other room. However, he also wants to maximize the number of rooms y... | from collections import deque
def bfs_distance(start_node, adj_list, N):
"""
Perform a breadth-first search to find the shortest path from start_node
to all other nodes. Returns the maximum distance found.
"""
distances = [-1] * (N + 1)
distances[start_node] = 0
queue = deque([start_node])
... | def test_sample_cases():
input_data = "2\n5 5\n1 2\n1 3\n2 4\n3 4\n4 5\n4 4\n1 2\n2 3\n3 4\n4 1"
expected_output = "3\n2"
assert main(input_data) == expected_output
def test_singe_case():
input_data = "1\n3 2\n1 2\n2 3"
expected_output = "2"
assert main(input_data) == expected_output
def test_... | [
{
"docstring": "Perform a breadth-first search to find the shortest path from start_node\nto all other nodes. Returns the maximum distance found.",
"function_declaration": "def bfs_distance(start_node, adj_list, N):",
"function_name": "bfs_distance",
"parameter_list": "(start_node, adj_list, N)"
}... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(graph, start, n):\n distances = [-1] * n\n distances[start] = 0\n queue = deque([start])\n \n while queue:\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031802",
"row_id": 31802,
"seed_ids": "[13071]"
} | 0.675226 | Taco_31802 | I | [
"bfs_distance",
"find_diameter",
"process_input",
"main"
] | 4 | [
[
"find_diameter",
"bfs_distance"
],
[
"process_input",
"find_diameter"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 175ca072e0840f5e50b50e6e35520092df2c069a | 1e9db513de4cbb8412302c9d19fcea434b34b806 | |||
v1.0 | instruct | Taco | Taco_31828_I | Anna loves playing with numbers. She especially enjoys working with numbers that have interesting properties. Recently, she has been fascinated by numbers whose sum of digits is equal to a specific value, S. She wants to find the smallest number that is greater than or equal to a given number X and has a sum of digits ... | def sum_of_digits(n):
"""
Returns the sum of digits of a given number n.
"""
return sum(int(digit) for digit in str(n))
def find_smallest_number(X, S):
"""
Finds the smallest number greater than or equal to X that has a sum of digits equal to S.
"""
current_number = X
while True:
... | from solution import find_smallest_number
def test_sample_inputs():
assert find_smallest_number(100, 5) == 104
assert find_smallest_number(10, 9) == 18
def test_edge_cases():
# Edge case where X is the smallest possible value
assert find_smallest_number(1, 1) == 1
# Edge case where X itself has th... | [
{
"docstring": "Returns the sum of digits of a given number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Finds the smallest number greater than or equal to X that has a sum of digits equal to S.",
"func... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_smallest_number_with_sum(X, S):\n \"\"\"\n Finds the smallest number greater than or equal to X that has a sum of digits equal to S.\n \"\"\"\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031828",
"row_id": 31828,
"seed_ids": "[20367]"
} | 0.715984 | Taco_31828 | I | [
"sum_of_digits",
"find_smallest_number"
] | 2 | [
[
"find_smallest_number",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4fce9df43ee55f323a543a3790465445d36e620 | fd5f63dbef5a0c02fe53ca6a17f0aec16ac74dad | |||
v1.0 | instruct | Taco | Taco_31835_I | A tree is a connected acyclic graph. In a tree, any two vertices are connected by exactly one path.
Given an undirected tree with \( N \) vertices labeled from \( 1 \) to \( N \). You need to find the K-th ancestor of a given node in the tree.
Input Format
The first line contains a single integer, \( N \) (1 ≤ \( N... | from collections import defaultdict, deque
def preprocess_tree(N, edges):
"""
Preprocess the tree to build the parent and depth information.
"""
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
parent = [-1] * (N + 1)
depth = [-1] * (N + 1)... | from solution import process_queries
def test_basic_case():
N = 7
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
queries = [(4, 1), (5, 2), (6, 1), (6, 3)]
assert process_queries(N, edges, queries) == [2, 1, 3, -1]
def test_no_kth_ancestor():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (3... | [
{
"docstring": "Preprocess the tree to build the parent and depth information.",
"function_declaration": "def preprocess_tree(N, edges):",
"function_name": "preprocess_tree",
"parameter_list": "(N, edges)"
},
{
"docstring": "Find the k-th ancestor of node x.",
"function_declaration": "de... | [
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.222 | {
"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_ancestors(n, edges):\n # Building the tree\n tree = defaultdict(list)\n \n for u, v in edg... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00031835",
"row_id": 31835,
"seed_ids": "[24358]"
} | 0.661358 | Taco_31835 | I | [
"preprocess_tree",
"find_kth_ancestor",
"process_queries"
] | 3 | [
[
"process_queries",
"find_kth_ancestor"
],
[
"process_queries",
"preprocess_tree"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | e7b84c3a823f12677fe43115abd8db4748198df4 | 444bd383e2bc82c24b5aecbdc7cdd20f2ceb974e | |||
v1.0 | instruct | Taco | Taco_31846_I | Write a program that determines if a string is a valid palindrome permutation.
A palindrome permutation is defined as a string that, when any permutation is formed from it, can be a palindrome. A palindrome is a word that reads the same backward as forward.
-----Input:-----
- The first line of the input contains a s... | def is_palindrome_permutation(s):
"""
Determines if the given string s is a valid palindrome permutation.
:param s: A string of lowercase English letters.
:return: True if the string is a valid palindrome permutation, otherwise False.
"""
from collections import Counter
# Count the... | from solution import is_palindrome_permutation, solve
def test_is_palindrome_permutation():
assert is_palindrome_permutation("civic") == True
assert is_palindrome_permutation("ivicc") == True
assert is_palindrome_permutation("hello") == False
assert is_palindrome_permutation("a") == True
assert is_... | [
{
"docstring": "Determines if the given string s is a valid palindrome permutation.\n\n:param s: A string of lowercase English letters.\n:return: True if the string is a valid palindrome permutation, otherwise False.",
"function_declaration": "def is_palindrome_permutation(s):",
"function_name": "is_pal... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome_permutation(s):\n \"\"\"\n Determines if the input string can be permuted to form a palindrome.\n \"\"\"\n from collections import Co... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031846",
"row_id": 31846,
"seed_ids": "[24551]"
} | 0.82166 | Taco_31846 | I | [
"is_palindrome_permutation",
"solve"
] | 2 | [
[
"solve",
"is_palindrome_permutation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f62fc3dea40f87bd208ce0306551fa61f65ae68a | fbd804334811b5996838fe3e16220e17210343f9 | |||
v1.0 | instruct | Taco | Taco_31856_I | Paul and Jenny are playing a number transformation game. Initially, a positive integer N is written on a blackboard. The players take turns, starting with Paul. On his or her turn, a player can replace N with N divided by any of its prime factors. The first player to reduce the number to 1 wins the game.
For example, ... | def is_prime(n):
"""Helper function to check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | import pytest
from solution import solve_game, div_game_winner
def test_prime_factors():
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(10) == [2, 5]
assert prime_factors(17) == [17]
def test_div_game_winner():
assert div_game_winner(18) == "YES"
assert div_game_winner(10) == "NO"
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Helper function to get the prime factors of a number.",
"function_declaration": "def prime_factors(n):",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_prime_factors(n):\n \"\"\"Compute the prime factors of a number n.\"\"\"\n i = 2\n factors = set()\n while i * i <= n:\n if n % i:\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031856",
"row_id": 31856,
"seed_ids": "[9590]"
} | 0.776575 | Taco_31856 | I | [
"is_prime",
"prime_factors",
"div_game_winner",
"solve_game"
] | 4 | [
[
"div_game_winner",
"prime_factors"
],
[
"solve_game",
"div_game_winner"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b42f274fe8ee1edff24346555e13f0703698d171 | 22f6507589b694214ef235ac7f39deadbb912a8a | |||
v1.0 | instruct | Taco | Taco_31924_I | Alex is working on a project that involves managing a network of computers represented by an undirected graph $\mathbf{G}$ with $N$ nodes and $M$ edges. Each edge connects two nodes $U_i$ and $V_i$ and has an associated transmission delay $D_i$.
Alex needs to find the shortest path between various pairs of computers, ... | import heapq
def preprocess_graph(N, edges):
graph = [[] for _ in range(N + 1)]
for u, v, d in edges:
graph[u].append((d, v))
graph[v].append((d, u))
return graph
def dijkstra(graph, start, N):
distances = [float('inf')] * (N + 1)
distances[start] = 0
priority_queue = [(0, star... | def test_shortest_paths():
N = 5
M = 6
edges = [
(1, 2, 10),
(1, 3, 5),
(2, 3, 2),
(3, 4, 1),
(4, 5, 7),
(2, 5, 10),
]
Q = 3
queries = [
(1, 5),
(2, 4),
(1, 4),
]
expected_output = [13, 3, 6]
assert shortest_path... | [
{
"docstring": null,
"function_declaration": "def preprocess_graph(N, edges):",
"function_name": "preprocess_graph",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, N):",
"function_name": "dijkstra",
"parameter_list": "(g... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef preprocess_network(n, edges):\n graph = [[] for _ in range(n + 1)]\n for u, v, d in edges:\n graph[u].append((v, d))\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031924",
"row_id": 31924,
"seed_ids": "[24922]"
} | 0.650121 | Taco_31924 | I | [
"preprocess_graph",
"dijkstra",
"shortest_paths"
] | 3 | [
[
"shortest_paths",
"dijkstra"
],
[
"shortest_paths",
"preprocess_graph"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d49257c8480ee3684d2b5863d33d9746f7924c1e | 4e8f0c172858eb9036db09440dbe13ade6cf457f | |||
v1.0 | instruct | Taco | Taco_31935_I | In a land far away, there is a unique kingdom with exactly one road connecting each pair of villages. The kingdom is represented as an undirected graph with V villages and E roads, where each road has a length associated with it.
The king wishes to improve the travel time by reducing the total length of the roads used... | def kruskal_mst(V, edges):
"""
Returns the total length of the roads in the minimum spanning tree using Kruskal's algorithm.
"""
# Sort edges by ascending edge weight
edges.sort(key=lambda x: x[2])
parent = list(range(V + 1))
rank = [0] * (V + 1)
def find(x):
if parent[... | def test_kruskal_mst():
assert kruskal_mst(4, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 4), (3, 4, 7)]) == 15
assert kruskal_mst(3, [(1, 2, 3), (2, 3, 5), (1, 3, 4)]) == 7
def test_solve_mst_cases():
test_cases = [
(4, 5, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 4), (3, 4, 7)]),
(3, 3, [(1... | [
{
"docstring": "Returns the total length of the roads in the minimum spanning tree using Kruskal's algorithm.",
"function_declaration": "def kruskal_mst(V, edges):",
"function_name": "kruskal_mst",
"parameter_list": "(V, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00031935",
"row_id": 31935,
"seed_ids": "[3981]"
} | 0.730542 | Taco_31935 | I | [
"kruskal_mst",
"solve_mst_cases",
"parse_input",
"main"
] | 4 | [
[
"solve_mst_cases",
"kruskal_mst"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 38558a443fdeb8441638503bc95067622a468bb5 | 624e9d35a507de764caa6b045cca2fa3550dedd7 | |||
v1.0 | instruct | Taco | Taco_31953_I | Given an integer n, find the nth Perfect Number.
A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself. Proper divisors of a number are all the divisors excluding the number itself.
Example 1:
Input:
n = 1
Output:
6
Explanation:
The first perfect number is 6, since it... | def is_perfect(num):
"""
Helper function to determine if a number is a perfect number.
"""
if num <= 1:
return False
sum_divisors = 1 # Starting with 1 since 1 is a proper divisor for all numbers > 1
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
sum_div... | from solution import nthPerfectNum, is_perfect
def test_is_perfect():
assert is_perfect(6) == True # 6 is a perfect number
assert is_perfect(28) == True # 28 is a perfect number
assert is_perfect(12) == False # 12 is not a perfect number
assert is_perfect(496) == True # 496 is a perfect number
... | [
{
"docstring": "Helper function to determine if a number is a perfect number.",
"function_declaration": "def is_perfect(num):",
"function_name": "is_perfect",
"parameter_list": "(num)"
},
{
"docstring": "Returns the nth Perfect Number.",
"function_declaration": "def nthPerfectNum(n):",
... | [
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 is_perfect_number(num):\n \"\"\"\n Checks if a given number is a perfect number.\n \"\"\"\n if num < 2:\n return False\n \n divisors_s... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00031953",
"row_id": 31953,
"seed_ids": "[5282]"
} | 0.583523 | Taco_31953 | I | [
"is_perfect",
"nthPerfectNum"
] | 2 | [
[
"nthPerfectNum",
"is_perfect"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6481092053c506ef00ce94c49c801cf5dbaae1a6 | e66cf1c050339e178cb0e67f650cc259caca08a8 | |||
v1.0 | instruct | Taco | Taco_31962_I | Consider a city where there are N office buildings connected by bi-directional roads. Each road connects exactly two buildings and has a travel time associated with it. People can go from one building to another through any number of intermediate buildings via these roads, and there might be multiple different paths be... | import sys
def floyd_warshall(n, dist):
# Initialize the distance array
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][k] != sys.maxsize and dist[k][j] != sys.maxsize:
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
return d... | from solution import minimum_travel_time
def test_minimum_travel_time():
N = 5
M = 6
roads = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 1),
(3, 4, 6),
(3, 5, 4),
(4, 5, 2),
]
Q = 3
queries = [
(1, 4),
(2, 5),
(1, 5),
]
expected... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, dist):",
"function_name": "floyd_warshall",
"parameter_list": "(n, dist)"
},
{
"docstring": null,
"function_declaration": "def minimum_travel_time(N, M, roads, Q, queries):",
"function_name": "minimum_travel_time",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def floyd_warshall(n, edges):\n # Initialize the distance matrix\n dist = [[float('inf')] * n for _ in range(n)]\n \n # Set the distance from a node to... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031962",
"row_id": 31962,
"seed_ids": "[23417]"
} | 0.802287 | Taco_31962 | I | [
"floyd_warshall",
"minimum_travel_time"
] | 2 | [
[
"minimum_travel_time",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2905da018d4f016c96cc5580dbbdb0e9e4e1c75a | 14bd4af27c7e9daf4315f6145646ec76a4c3e412 | |||
v1.0 | instruct | Taco | Taco_31975_I | You are given a binary tree with $n$ nodes. Each node has an integer value associated with it. Your task is to determine whether the tree contains a path from the root to any leaf such that the sum of the values of the nodes along this path is equal to a given target sum $S$.
-----Input-----
The first line contains t... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def has_path_sum(root, target_sum):
"""
Given a binary tree and a target sum, determines if there is a path from root to
any leaf such that the sum of the node values equals the target su... | def test_solution_case1():
n = 5
S = 6
node_values = [1, 2, 3, 4, 5]
# Expected output: YES
solution(n, S, node_values)
def test_solution_case2():
n = 3
S = 5
node_values = [1, 2, 3]
# Expected output: NO
solution(n, S, node_values)
def test_solution_case3():
n = 7
... | [] | [
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": "class TreeNode:\n def __init__(self, value=0):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(node_values):\... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00031975",
"row_id": 31975,
"seed_ids": "[8359]"
} | 0.652092 | Taco_31975 | I | [
"has_path_sum",
"create_tree",
"solution"
] | 3 | [
[
"solution",
"create_tree"
],
[
"solution",
"has_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 251b284cc261705906270b16879316a15ebacccc | c74c38ed2e5760e88e8cf3bb8c4daf27a107ab91 | |||
v1.0 | instruct | Taco | Taco_32002_I | Given a sequence of integers represented as a nested list where each inner list denotes a sub-sequence of integers. Your task is to find the least common multiple (LCM) of each sub-sequence and return the results in the same order.
The Least Common Multiple (LCM) of two integers is the smallest positive integer that i... | from math import gcd
from functools import reduce
from typing import List
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return a * b // gcd(a, b)
def find_lcm_of_list(numbers: List[int]) -> int:
"""
Returns the LCM of the given list of numbers.
"""
return reduce(... | from solution import find_lcm_of_subsequences
def test_example_case():
sequences = [
[2, 7, 3],
[4, 6, 12],
[10],
[12, 15, 75]
]
assert find_lcm_of_subsequences(sequences) == [42, 12, 10, 300]
def test_single_element_lists():
sequences = [
[1],
[5],
... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the LCM of the given list of numbers.",
"function_declaration": "def find_lcm_of_list(numbers):",
"f... | [
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 math import gcd\nfrom functools import reduce\nfrom typing import List\n\ndef lcm(a, b):\n \"\"\"Returns the least common multiple of a and b\"\"\"\n re... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032002",
"row_id": 32002,
"seed_ids": "[16773]"
} | 0.621542 | Taco_32002 | I | [
"lcm",
"find_lcm_of_list",
"find_lcm_of_subsequences"
] | 3 | [
[
"find_lcm_of_list",
"lcm"
],
[
"find_lcm_of_subsequences",
"find_lcm_of_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cf810436be4f56eea58190e4da81c81a62dcd981 | e3b858e911d9527c1d93a6d70af96e39cacbdb8e | |||
v1.0 | instruct | Taco | Taco_32009_I | Ryan is designing a security system for his office building. He wants to add a keycard system that only grants access during certain hours based on a log of keycard entries and exits. Each entry in the log is represented by a time in 24-hour format (HH:MM), and an action (either "enter" or "exit"). Ryan needs your help... | def is_within_allowed_hours(time, start_time, end_time):
return start_time <= time <= end_time
def find_invalid_access_times(start_time, end_time, n, log_entries):
invalid_entries = []
for entry in log_entries:
entry_time, action = entry.split()
if not is_within_allowed_hours(entry_time, s... | from solution import find_invalid_access_times
def test_all_access_times_valid():
start_time = "09:00"
end_time = "17:00"
n = 3
log_entries = ["09:00 enter", "12:00 exit", "17:00 exit"]
assert find_invalid_access_times(start_time, end_time, n, log_entries) == "ALL ACCESS TIMES VALID"
def test_some... | [
{
"docstring": null,
"function_declaration": "def is_within_allowed_hours(time, start_time, end_time):",
"function_name": "is_within_allowed_hours",
"parameter_list": "(time, start_time, end_time)"
},
{
"docstring": null,
"function_declaration": "def find_invalid_access_times(start_time,... | [
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 typing import List, Tuple\n\n\ndef parse_time(time_str: str) -> Tuple[int, int]:\n \"\"\"\n Parse a time string in HH:MM format and return a tuple of (h... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032009",
"row_id": 32009,
"seed_ids": "[14959]"
} | 0.520694 | Taco_32009 | I | [
"is_within_allowed_hours",
"find_invalid_access_times"
] | 2 | [
[
"find_invalid_access_times",
"is_within_allowed_hours"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af0fc1ec02dd8836dadf6569a5d313e540130e60 | d622b71f279cd4a50056221416774c537bb9a872 | |||
v1.0 | instruct | Taco | Taco_32036_I | In a small village, there is a unique river network consisting of several rivers and lakes. The rivers are in the form of directed edges connecting pairs of lakes. Each lake is assigned a numerical index from $1$ to $n$, and the lakes and rivers form a directed acyclic graph (DAG).
The village wants to control the fl... | from collections import defaultdict, deque
def find_minimum_barriers(n, m, rivers):
def topological_sort():
in_degree = [0] * (n + 1)
for u, v in rivers:
graph[u].append(v)
in_degree[v] += 1
zero_in_degree = deque([i for i in range(1, n + 1) if in_degree[i] ... | def test_minimum_barriers():
assert minimum_barriers(4, 4, [(1, 2), (2, 3), (3, 4), (1, 3)]) == [1, 1, 1, 0]
assert minimum_barriers(5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (1, 4)]) == [1, 1, 1, 1, 0]
assert minimum_barriers(3, 2, [(1, 2), (2, 3)]) == [1, 1, 0]
assert minimum_barriers(6, 6, [(1, 2), (2, ... | [
{
"docstring": null,
"function_declaration": "def find_minimum_barriers(n, m, rivers):",
"function_name": "find_minimum_barriers",
"parameter_list": "(n, m, rivers)"
},
{
"docstring": null,
"function_declaration": "def minimum_barriers(n, m, rivers):",
"function_name": "minimum_barri... | [
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\n\ndef min_barriers(n, m, rivers):\n def topo_sort(vertices, edges):\n graph = defaultdict(list)\n in_d... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00032036",
"row_id": 32036,
"seed_ids": "[8809]"
} | 0.654321 | Taco_32036 | I | [
"find_minimum_barriers",
"minimum_barriers"
] | 2 | [
[
"minimum_barriers",
"find_minimum_barriers"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8bf84cad026393ae5791d39dad30750bdbfdaa90 | bef9279f5f9832f86e9e8e91d5b8e9e892879596 | |||
v1.0 | instruct | Taco | Taco_32046_I | You are given an array of n integers and a series of m queries. Each query asks for the number of distinct subarrays of the given length k that can be formed from the array. A subarray is a contiguous part of an array.
For example, in the array `[1, 2, 1, 3, 2]` and with the query `k = 3`, the subarrays of length 3 ar... | def count_distinct_subarrays(arr, k):
"""
Counts the number of distinct subarrays of length k in the given array.
:param arr: List of integers
:param k: Length of subarrays to consider
:return: Number of distinct subarrays of length k
"""
subarrays = set()
for i in range(len(arr) - ... | from solution import solve
def test_single_query():
test_cases = [
([1, 2, 1, 3, 2], [3])
]
assert solve(test_cases) == [[3]]
def test_multiple_queries():
test_cases = [
([1, 2, 1, 3, 2], [3, 2])
]
assert solve(test_cases) == [[3, 4]]
def test_duplicate_elements():
test_ca... | [
{
"docstring": "Counts the number of distinct subarrays of length k in the given array.\n\n:param arr: List of integers\n:param k: Length of subarrays to consider\n:return: Number of distinct subarrays of length k",
"function_declaration": "def count_distinct_subarrays(arr, k):",
"function_name": "count... | [
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 distinct_subarrays(n, array, queries):\n results = []\n for k in queries:\n subarrays = set()\n for i in range(n - k + 1):\n sub... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032046",
"row_id": 32046,
"seed_ids": "[11404]"
} | 0.768104 | Taco_32046 | I | [
"count_distinct_subarrays",
"process_queries",
"solve"
] | 3 | [
[
"process_queries",
"count_distinct_subarrays"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 1be5cb08df05b616aa55e959991f81e3487c9a05 | 268bbaf05a9d8f3acd4d90c26c2d2435e0c2bed0 | |||
v1.0 | instruct | Taco | Taco_32110_I | A tourist is exploring a new city and needs help navigating the city streets. The city is represented as a grid of characters where '.' represents an open path the tourist can walk on, '#' represents a building the tourist cannot go through, 'S' represents the starting point of the tourist, and 'E' represents the desti... | def can_reach_destination(grid, n, m):
from collections import deque
# Finding the start 'S' and end 'E' points
start = None
end = None
for i in range(n):
for j in range(m):
if grid[i][j] == 'S':
start = (i, j)
elif grid[i][j] == 'E':
... | def test_example_1():
n = 4
m = 4
grid_lines = [
".S..",
"..#.",
"..#E",
"...."
]
assert explore_city(n, m, grid_lines) == "YES"
def test_example_2():
n = 3
m = 3
grid_lines = [
"S##",
".#.",
".##E"
]
assert explore_city(n,... | [
{
"docstring": null,
"function_declaration": "def can_reach_destination(grid, n, m):",
"function_name": "can_reach_destination",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def explore_city(n, m, grid_lines):",
"function_name": "explore_city",
... | [
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 can_reach_destination(n, m, grid):\n from collections import deque\n \n # Find the starting position 'S'\n for r in range(n):\n for c in ran... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032110",
"row_id": 32110,
"seed_ids": "[13713]"
} | 0.707217 | Taco_32110 | I | [
"can_reach_destination",
"explore_city"
] | 2 | [
[
"explore_city",
"can_reach_destination"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b61159e5a430684d78ae416e815afa5fb9163068 | 93194f80aafcb1eeb6832dad2df4de453dea35f9 | |||
v1.0 | instruct | Taco | Taco_32135_I | In a magical kingdom, there are N cities and M bidirectional roads connecting these cities. The roads form a fully connected graph, meaning there's a direct road between every pair of cities. A powerful wizard has cast a strange spell on the kingdom's road network, causing each road to have a unique magical weight.
Th... | from heapq import heappop, heappush
from math import inf
def floyd_warshall(n, graph):
dist = [[inf] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i == j:
dist[i][j] = 0
elif graph[i][j] != inf:
dist[i][j] = graph[i][j]
... | from solution import min_max_path_after_incantations
def test_example_case():
n = 5
m = 10
k = 5
roads = [
(1, 2, 10),
(1, 3, 20),
(1, 4, 15),
(1, 5, 30),
(2, 3, 25),
(2, 4, 30),
(2, 5, 10),
(3, 4, 35),
(3, 5, 40),
(4, 5, 2... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, graph):",
"function_name": "floyd_warshall",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def min_max_path_after_incantations(n, roads, k, queries):",
"function_name": "min_max_path... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef halve_road_weights(edges, K):\n # Create a priority queue of all edges with their initial weights\n pq = []\n for (u, v), weight in ed... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00032135",
"row_id": 32135,
"seed_ids": "[23624]"
} | 0.708602 | Taco_32135 | I | [
"floyd_warshall",
"min_max_path_after_incantations"
] | 2 | [
[
"min_max_path_after_incantations",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 94c63a2a070dc215fdfb8012b9443e7982efd161 | 4eed7af9e03d92304b968647b9e7947427fe1c81 | |||
v1.0 | instruct | Taco | Taco_32160_I | Write a program to generate a diamond-shaped pattern of a given size using asterisks (*) and spaces.
* The diamond has a width of (2n-1) characters, where n is the height of the top half of the diamond excluding the center line.
* The first half of the diamond incrementally widens, while the second half incrementally ... | def generate_diamond(n):
"""
Generates a diamond shape for a given size n and returns it as a list of strings.
Each string in the list represents a single line in the diamond.
"""
lines = []
# Upper part including the middle line
for i in range(n):
line = ' ' * (n - i - 1) + '*'... | from solution import parse_input, generate_diamonds, generate_diamond
def test_generate_diamond_size_1():
expected_output = [
"*"
]
assert generate_diamond(1) == expected_output
def test_generate_diamond_size_3():
expected_output = [
" *",
" * *",
"* *",
" * ... | [
{
"docstring": "Generates a diamond shape for a given size n and returns it as a list of strings.\nEach string in the list represents a single line in the diamond.",
"function_declaration": "def generate_diamond(n):",
"function_name": "generate_diamond",
"parameter_list": "(n)"
},
{
"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 generate_diamond(n):\n \"\"\"\n Generates a diamond pattern of given size n.\n \"\"\"\n diamond = []\n max_width = 2 * n - 1\n \n # Top ha... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032160",
"row_id": 32160,
"seed_ids": "[17527]"
} | 0.483146 | Taco_32160 | I | [
"generate_diamond",
"generate_diamonds",
"parse_input"
] | 3 | [
[
"generate_diamonds",
"generate_diamond"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 8efc3c1a15b85aa76c9b3c69907ef5fe92946786 | d421ac581e241f0fe33262efbbc50347904a056b | |||
v1.0 | instruct | Taco | Taco_32162_I | You are given an undirected graph with $N$ nodes and $M$ edges. Each edge has a weight associated with it. The task is to determine the longest path in the graph such that the sum of weights of the edges in the path is maximized.
-----Input-----
- The first line of the input contains two integers $N$ and $M$ denoting ... | def has_cycle_util(graph, visited, rec_stack, node):
visited[node] = True
rec_stack[node] = True
for neighbor, weight in graph[node]:
if not visited[neighbor]:
if has_cycle_util(graph, visited, rec_stack, neighbor):
return True
elif rec_stack[neighbor]:
... | from solution import parse_and_solve
def test_example_input():
input_data = """5 6
1 2 10
2 3 10
3 4 10
4 5 10
1 5 30
3 1 20"""
assert parse_and_solve(input_data) == "INF"
def test_no_cycle():
input_data = """4 4
1 2 5
2 3 5
3 4 5
1 4 15"""
assert parse_and_solve(input_data) == 15
def test_single_nod... | [
{
"docstring": null,
"function_declaration": "def has_cycle_util(graph, visited, rec_stack, node):",
"function_name": "has_cycle_util",
"parameter_list": "(graph, visited, rec_stack, node)"
},
{
"docstring": null,
"function_declaration": "def has_cycle(graph, N):",
"function_name": "... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef longest_path(N, M, edges):\n graph = defaultdict(list)\n for u, v, w in edges:\n graph[u].append((v,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032162",
"row_id": 32162,
"seed_ids": "[4998]"
} | 0.786734 | Taco_32162 | I | [
"has_cycle_util",
"has_cycle",
"longest_path",
"find_longest_path",
"parse_and_solve"
] | 5 | [
[
"find_longest_path",
"longest_path"
],
[
"has_cycle",
"has_cycle_util"
],
[
"longest_path",
"has_cycle"
],
[
"parse_and_solve",
"find_longest_path"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 7520e087e582eda9800971e354ffa5e223267173 | aa37b114345277e3933c6766a0c3beaad16cb5ff | |||
v1.0 | instruct | Taco | Taco_32209_I | A company wants to minimize the cost of transferring data between its distributed servers. There are n servers located in different geographical regions, and each server has a data volume that needs to be transferred. The servers are connected via m direct bidirectional links, each with an associated cost. The goal is ... | from heapq import heappop, heappush
def find(parents, i):
if parents[i] == i:
return i
parents[i] = find(parents, parents[i])
return parents[i]
def union(parents, ranks, u, v):
root_u = find(parents, u)
root_v = find(parents, v)
if root_u != root_v:
if ranks[root_u] > rank... | from solution import minimal_cost_to_connect_servers
def test_example_1():
n = 4
m = 3
edges = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 4)
]
queries = [
(1, 3),
(4, 1)
]
result = minimal_cost_to_connect_servers(n, m, edges, queries)
assert result == [6, 3]
... | [
{
"docstring": null,
"function_declaration": "def find(parents, i):",
"function_name": "find",
"parameter_list": "(parents, i)"
},
{
"docstring": null,
"function_declaration": "def union(parents, ranks, u, v):",
"function_name": "union",
"parameter_list": "(parents, ranks, u, v)"... | [
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 UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032209",
"row_id": 32209,
"seed_ids": "[8828]"
} | 0.65504 | Taco_32209 | I | [
"find",
"union",
"kruskal",
"minimal_cost_to_connect_servers"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimal_cost_to_connect_servers",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | e0760ed9ba24f39fb9e1795ed6ad67692d44b0cf | 10a618f17876a4ebebf57606a81af62c77bb719c | |||
v1.0 | instruct | Taco | Taco_32228_I | In a distant kingdom, there is a magical orchard where fruits grow in special numbers based on the Fibonacci sequence. The n-th type of fruit has a weight defined by the n-th Fibonacci number.
The king wants to create a fruit basket containing at least one type of each fruit. However, the basket must be optimal in wei... | def fibonacci_sequence(n):
"""
Generates a list of first n Fibonacci numbers.
"""
fibonacci = [1, 1]
for i in range(2, n):
fibonacci.append(fibonacci[-1] + fibonacci[-2])
return fibonacci[:n]
def fruit_basket_weights(n):
"""
Calculates the minimum and maximum weight of the fruit... | from solution import fibonacci_sequence, fruit_basket_weights
def test_fibonacci_sequence():
assert fibonacci_sequence(1) == [1]
assert fibonacci_sequence(2) == [1, 1]
assert fibonacci_sequence(3) == [1, 1, 2]
assert fibonacci_sequence(5) == [1, 1, 2, 3, 5]
assert fibonacci_sequence(7) == [1, 1, 2,... | [
{
"docstring": "Generates a list of first n Fibonacci numbers.",
"function_declaration": "def fibonacci_sequence(n):",
"function_name": "fibonacci_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the minimum and maximum weight of the fruit basket.",
"function_declaration"... | [
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 fib(n):\n \"\"\"\n Calculate the n-th Fibonacci number.\n \"\"\"\n if n == 1 or n == 2:\n return 1\n a, b = 1, 1\n for _ in range(3, n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00032228",
"row_id": 32228,
"seed_ids": "[14393]"
} | 0.614604 | Taco_32228 | I | [
"fibonacci_sequence",
"fruit_basket_weights"
] | 2 | [
[
"fruit_basket_weights",
"fibonacci_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ebec66741b3c5c9445ef9b35d2774fe260fef5f | 4e57b74350f2af2ee6244bb23cd8d46fedffe64b | |||
v1.0 | instruct | Taco | Taco_32350_I | In a given array, find the smallest possible sum of contiguous subarray whose product is a perfect square.
-----Input:-----
- The first line contains an integer $T$ denoting the number of test cases.
- The first line of each test case contains a single integer $N$ denoting the number of elements in the array.
- The ne... | def is_perfect_square(x):
"""
Helper function to determine if a number is a perfect square.
"""
return int(x ** 0.5) ** 2 == x
def smallest_sum_perfect_square_subarray(arr):
"""
Function to find the smallest possible sum of a contiguous subarray whose
product is a perfect square.
"""
... | from solution import process_test_cases, smallest_sum_perfect_square_subarray
def test_smallest_sum_perfect_square_subarray_case_1():
arr = [2, 4, 3, 9, 6]
assert smallest_sum_perfect_square_subarray(arr) == 4
def test_smallest_sum_perfect_square_subarray_case_2():
arr = [1, 7, 1, 2]
assert smallest_s... | [
{
"docstring": "Helper function to determine if a number is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Function to find the smallest possible sum of a contiguous subarray whose \npr... | [
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 math\n\ndef is_perfect_square(x):\n \"\"\"\n Check if a given number x is a perfect square.\n \"\"\"\n root = int(math.sqrt(x))\n return x ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032350",
"row_id": 32350,
"seed_ids": "[21231]"
} | 0.73317 | Taco_32350 | I | [
"is_perfect_square",
"smallest_sum_perfect_square_subarray",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"smallest_sum_perfect_square_subarray"
],
[
"smallest_sum_perfect_square_subarray",
"is_perfect_square"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 75c067549c0be13d35de4806661ca4e3026ccd1a | 6769c6fa29321efbdf6bcbb2e2cf4b650f980df5 | |||
v1.0 | instruct | Taco | Taco_32370_I | Given an array of integers, we want to find all possible permutations of this array. A permutation of an array is a rearrangement of its elements into a new sequence.
Input
The first line of input contains an integer n (1 ≤ n ≤ 7) — the number of elements in the array. The second line contains n space-separated integ... | from itertools import permutations
def generate_permutations(lst):
"""
Generates all possible permutations of the given list.
"""
all_permutations = list(permutations(lst))
return all_permutations
def format_permutations(lst):
"""
Returns all permutations in a formatted output (list of str... | from solution import generate_permutations, format_permutations
def test_generate_single_element():
assert generate_permutations([1]) == [(1,)]
def test_generate_two_elements():
result = generate_permutations([4, 5])
expected = [(4, 5), (5, 4)]
assert sorted(result) == sorted(expected)
def test_gener... | [
{
"docstring": "Generates all possible permutations of the given list.",
"function_declaration": "def generate_permutations(lst):",
"function_name": "generate_permutations",
"parameter_list": "(lst)"
},
{
"docstring": "Returns all permutations in a formatted output (list of strings).",
"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef find_permutations(n, array):\n \"\"\"\n Returns all permutations of a given array.\n\n :param n: Number of elements in the array\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032370",
"row_id": 32370,
"seed_ids": "[14697]"
} | 0.756143 | Taco_32370 | I | [
"generate_permutations",
"format_permutations"
] | 2 | [
[
"format_permutations",
"generate_permutations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8598dde3a1e86ee8ff65c2e1d9a17e29718799ca | f13f2fe30706646db5f8077d4db58011db0f9ecb | |||
v1.0 | instruct | Taco | Taco_32383_I | Aditi is fascinated by Binary Search Trees (BST) and loves working on them. One day, her friend Vikram challenged her with an interesting problem. He gave her a list of integers and asked her to construct a BST out of it. Once the BST is constructed, she needs to find the k-th smallest element in the BST. Can you help ... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.right = insert(root.right, key)
else:
root.left = ins... | from solution import process_input
def test_example():
input_data = "2\n5 3\n5 3 8 2 4\n7 4\n10 5 1 7 40 50 8"
assert process_input(input_data) == [4, 8]
def test_single_node():
input_data = "1\n1 1\n5"
assert process_input(input_data) == [5]
def test_all_nodes_same():
input_data = "1\n5 3\n7 7 7... | [] | [
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, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert_node(root, key):\n if r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032383",
"row_id": 32383,
"seed_ids": "[11357]"
} | 0.518515 | Taco_32383 | I | [
"insert",
"inorder_traversal",
"kth_smallest_element",
"find_kth_smallest_element",
"process_input"
] | 5 | [
[
"find_kth_smallest_element",
"insert"
],
[
"find_kth_smallest_element",
"kth_smallest_element"
],
[
"kth_smallest_element",
"inorder_traversal"
],
[
"process_input",
"find_kth_smallest_element"
]
] | 4 | [
"process_input"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d089d2a244b06462a0b14b4f7571623b19237dfa | 96f98fc763f17197c7ef542a0b21f65e94c33217 | |||
v1.0 | instruct | Taco | Taco_32387_I | In a software development contest, there was a problem of forming the largest number by rearranging a given set of non-negative integers. However, there was a constraint: a new rule was introduced that the final number should not contain any leading zeros, except for the number zero itself.
Given a list of non-negativ... | from functools import cmp_to_key
def largest_number(nums):
"""
Forms the largest possible number from the input list of non-negative integers.
"""
def compare(x, y):
# Custom comparator to decide the order based on concatenated result
if x + y > y + x:
return -1
... | from solution import form_largest_number
def test_sample_input():
assert form_largest_number(5, [10, 2, 9, 39, 17]) == "93921710"
def test_all_zeros():
assert form_largest_number(3, [0, 0, 0]) == "0"
def test_single_number():
assert form_largest_number(1, [5]) == "5"
def test_leading_zero_case():
as... | [
{
"docstring": "Forms the largest possible number from the input list of non-negative integers.",
"function_declaration": "def largest_number(nums):",
"function_name": "largest_number",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def form_largest_number(n,... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef compare(x, y):\n # Custom comparator to decide the order based on concatenation\n if x + y > y + x:\n return -... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032387",
"row_id": 32387,
"seed_ids": "[8995]"
} | 0.682979 | Taco_32387 | I | [
"largest_number",
"form_largest_number"
] | 2 | [
[
"form_largest_number",
"largest_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a90a434eb476067903afd2badbcff2865f5fad8f | 5e4130f38e80cdcd728bb9c1680da217108f40da | |||
v1.0 | instruct | Taco | Taco_32411_I | A factory produces a series of electronic devices each having a unique serial number. The serial number consists of digits only. The factory wants to ensure that each serial number is valid according to specific rules before the devices are shipped. A valid serial number must have the following properties:
1. It contai... | def is_valid_serial(serial):
"""
Checks if a given serial number is valid.
A valid serial number must:
1. Contain at least two different digits.
2. Have no consecutive identical digits.
"""
if len(set(serial)) < 2:
return "Invalid"
for i in range(1, len(serial)):
if seria... | def test_single_valid_serial():
assert is_valid_serial("12345") == "Valid"
def test_single_invalid_serial_identical_digits():
assert is_valid_serial("11111") == "Invalid"
def test_single_invalid_serial_consecutive_identical():
assert is_valid_serial("112233") == "Invalid"
def test_single_valid_serial_wit... | [
{
"docstring": "Checks if a given serial number is valid.\nA valid serial number must:\n1. Contain at least two different digits.\n2. Have no consecutive identical digits.",
"function_declaration": "def is_valid_serial(serial):",
"function_name": "is_valid_serial",
"parameter_list": "(serial)"
},
... | [
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_valid_serial(serial):\n \"\"\"\n Checks if the given serial number is valid according to the rules.\n A valid serial number must:\n 1. Contain a... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00032411",
"row_id": 32411,
"seed_ids": "[15995]"
} | 0.684361 | Taco_32411 | I | [
"is_valid_serial",
"check_serials"
] | 2 | [
[
"check_serials",
"is_valid_serial"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4ede4d49a73f8f876589ca1b697796d7277ed23a | 7b4f92a21dad1b8fffaf75cc89a34f0b28ffd96e | |||
v1.0 | instruct | Taco | Taco_32415_I | Problem Description
You are given the task of evaluating a series of mathematical expressions passed in a specific format, and turning them into their correct arithmetic results. Implement a program that can solve basic arithmetic expressions, ensuring to follow the order of operations (PEMDAS—parentheses, exponents, ... | import re
def evaluate_expression(expression):
try:
# Evaluate the expression and round the result to 2 decimal places
result = eval(expression)
return f"{result:.2f}"
except Exception as e:
return str(e)
def process_expressions(expressions):
results = []
for expression... | from solution import evaluate_expression, process_expressions
def test_evaluate_single_expression():
assert evaluate_expression("5+3*2") == "11.00"
assert evaluate_expression("4/2-1") == "1.00"
assert evaluate_expression("7*(3+2)") == "35.00"
assert evaluate_expression("9/3*3+2") == "11.00"
assert ... | [
{
"docstring": null,
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def process_expressions(expressions):",
"function_name": "process_expressions... | [
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 evaluate_expression(expression):\n \"\"\"\n Evaluates a given arithmetic expression string and returns the result rounded to two decimal precision.\n ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00032415",
"row_id": 32415,
"seed_ids": "[12946]"
} | 0.577149 | Taco_32415 | I | [
"evaluate_expression",
"process_expressions"
] | 2 | [
[
"process_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c763176dee57d5dffcd465e212c75bea997fc1a | f6ae4887d946eb1da9f05187bcc947ebaadab523 | |||
v1.0 | instruct | Taco | Taco_32462_I | Marco and Polo are designing a sequence of steps on a chessboard. The chessboard is an 8x8 grid, and each position on the board can be represented using standard chess notation (e.g., "a1", "h8"). Marco starts the knight at the "a1" position and provides a series of moves for the knight. Polo wants to confirm that the ... | def is_valid_knight_move(start, end):
"""
Determines if a move from start position to end position is a valid knight's move on a chessboard.
"""
# Mapping columns to indices
col_to_index = {chr(i + ord('a')): i for i in range(8)}
row_to_index = {str(i + 1): i for i in range(8)}
start_co... | from solution import check_moves
def test_sample_moves():
moves = ["a1->b3", "a1->c2", "h8->g6", "b1->c2"]
assert check_moves(moves) == ["VALID", "VALID", "VALID", "INVALID"]
def test_all_valid_moves():
moves = ["a1->c2", "c2->a3", "f3->g5", "h8->f7"]
assert check_moves(moves) == ["VALID", "VALID", "V... | [
{
"docstring": "Determines if a move from start position to end position is a valid knight's move on a chessboard.",
"function_declaration": "def is_valid_knight_move(start, end):",
"function_name": "is_valid_knight_move",
"parameter_list": "(start, end)"
},
{
"docstring": null,
"functio... | [
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_valid_knight_move(start, end):\n \"\"\"\n Given a start and end position representing a knight's move, \n determine if it ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00032462",
"row_id": 32462,
"seed_ids": "[3465]"
} | 0.687582 | Taco_32462 | I | [
"is_valid_knight_move",
"check_moves"
] | 2 | [
[
"check_moves",
"is_valid_knight_move"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5eb3ac1cf6a5e3349fe9b730e59f55a34b1bea6f | fd8ed2a1e4c5f17ac5dab1caf58679f649a43bad | |||
v1.0 | instruct | Taco | Taco_32514_I | You are given a list of integers and you need to determine if there exists a subset of the list that adds up to a given target sum.
------ Input Format ------
- The first line of input contains two space-separated integers n and target, where n is the number of integers in the list and target is the target sum.
- The... | def has_subset_sum(nums, target):
"""
Determines if there exists a subset of nums that adds up to the target sum.
"""
n = len(nums)
dp = [False] * (target + 1)
dp[0] = True # A sum of 0 can always be achieved with an empty set.
for num in nums:
for j in range(target, num - 1, -... | from solution import determine_subset_sum
def test_example_1():
assert determine_subset_sum(5, 9, [3, 34, 4, 12, 5, 2]) == "YES"
def test_example_2():
assert determine_subset_sum(5, 30, [3, 34, 4, 12, 5, 2]) == "NO"
def test_single_element_equal_to_target():
assert determine_subset_sum(1, 5, [5]) == "YES... | [
{
"docstring": "Determines if there exists a subset of nums that adds up to the target sum.",
"function_declaration": "def has_subset_sum(nums, target):",
"function_name": "has_subset_sum",
"parameter_list": "(nums, target)"
},
{
"docstring": null,
"function_declaration": "def determine_... | [
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 subset_sum_exists(n, target, nums):\n \"\"\"\n Determines if there exists a subset of the list `nums` that adds up to the target sum `target`.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032514",
"row_id": 32514,
"seed_ids": "[15259]"
} | 0.688332 | Taco_32514 | I | [
"has_subset_sum",
"determine_subset_sum"
] | 2 | [
[
"determine_subset_sum",
"has_subset_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 056c54b965ef607baea8ddb5eaffeea334e749ef | a7e6a832287775b2514f59b4e51c9832c2ef34a5 | |||
v1.0 | instruct | Taco | Taco_32580_I | Given an integer n, write a function that determines if the number is a prime power. A prime power is a number that can be expressed in the form \( p^k \) where p is a prime number and k is an integer greater than or equal to 1.
Example 1:
Input:
n = 16
Output: True
Explanation: 16 can be expressed as \( 2^4 \), wher... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def isPrimePower(n):
if n <= 1:
re... | from solution import isPrimePower
def test_example_cases():
assert isPrimePower(16) == True
assert isPrimePower(18) == False
def test_prime_numbers():
assert isPrimePower(2) == True
assert isPrimePower(3) == True
assert isPrimePower(5) == True
assert isPrimePower(7) == True
def test_non_prime... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def isPrimePower(n):",
"function_name": "isPrimePower",
"parameter_list": "(n)"
}
] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032580",
"row_id": 32580,
"seed_ids": "[12187]"
} | 0.626786 | Taco_32580 | I | [
"is_prime",
"isPrimePower"
] | 2 | [
[
"isPrimePower",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | affbc6c2237f809ef6527559c426eda834e5e97e | dec0d5d44f71ba3846e68665f115afa51e23006c | |||
v1.0 | instruct | Taco | Taco_32590_I | Endpoint Security Solutions Inc. wants to develop a software that can identify unique IP addresses that made 'n' number of access attempts within a given time interval from their server logs. The log file is a text file where each line contains an IP address and a timestamp (in the format YYYY-MM-DD HH:MM:SS). Your tas... | def parse_timestamp(timestamp):
from datetime import datetime
return datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
def find_unique_ips(log_file_path, start_interval, end_interval, n):
from collections import defaultdict
start_time = parse_timestamp(start_interval)
end_time = parse_timestam... | from solution import find_unique_ips
def test_no_access_attempts():
log_file_path = "log_test_1.txt"
with open(log_file_path, 'w') as file:
file.write("")
start_interval = "2023-01-01 12:00:00"
end_interval = "2023-01-01 12:30:00"
n = 3
assert find_unique_ips(log_file_path, start_interv... | [
{
"docstring": null,
"function_declaration": "def parse_timestamp(timestamp):",
"function_name": "parse_timestamp",
"parameter_list": "(timestamp)"
},
{
"docstring": null,
"function_declaration": "def find_unique_ips(log_file_path, start_interval, end_interval, n):",
"function_name":... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef unique_ips(log_file_path, start_interval, end_interval, n):\n start_dt = datetime.strptime(start_interval, \"%Y-%m-%d %H:%M... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032590",
"row_id": 32590,
"seed_ids": "[7446]"
} | 0.638365 | Taco_32590 | I | [
"parse_timestamp",
"find_unique_ips"
] | 2 | [
[
"find_unique_ips",
"parse_timestamp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2eadc03bcce47f5c5d396f86aeefc88f22f9c44f | 5b081374fa7410f658fe66f39ae621a8a73ba619 | |||
v1.0 | instruct | Taco | Taco_32614_I | You are given a rectangular grid of size n x m, where each cell in the grid can either be empty or contain an obstacle. Winnie-the-Pooh starts at the top-left corner of the grid (cell (1, 1)) and wants to traverse to the bottom-right corner of the grid (cell (n, m)). Winnie-the-Pooh can only move to the right or down o... | def num_paths(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == '1' or grid[n-1][m-1] == '1':
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '1':
dp[i][j] = 0
... | from solution import count_distinct_paths
def test_no_obstacles():
grid = [['0', '0', '0'],
['0', '0', '0'],
['0', '0', '0']]
assert count_distinct_paths(3, 3, grid) == 6
def test_one_obstacle():
grid = [['0', '0', '0'],
['0', '1', '0'],
['0', '0', '0']]
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def count_distinct_paths(n, m, grid):",
"function_name": "count_distinct_paths",
"parameter_list": "(n, m... | [
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 distinct_paths(n, m, grid):\n if grid[0][0] == '1' or grid[n-1][m-1] == '1':\n return 0\n \n dp = [[0] * m for _ in range(n)]\n dp[0][0]... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032614",
"row_id": 32614,
"seed_ids": "[24219]"
} | 0.729822 | Taco_32614 | I | [
"num_paths",
"count_distinct_paths"
] | 2 | [
[
"count_distinct_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f9c6c8b2d68729611ad44dfc95c1ed68aa9d5bfc | 4099ff56987f68511e748166546bd00ddbf8d6b6 | |||
v1.0 | instruct | Taco | Taco_32667_I | For an array of integers $B = \\{b_0, b_1, ..., b_{n-1}\\}$, find the subarray that has the maximum sum and print that sum.
Constraints
* $1 \leq n \leq 100,000$
* $-10,000 \leq b_i \leq 10,000$
Input
An array is given in the following format.
$n$
$b_0 \; b_1 \; ,..., \; b_{n-1}$
Output
Print the maximum sum of ... | def max_subarray_sum(arr):
"""
Returns the maximum sum of the contiguous subarray using Kadane's Algorithm.
"""
max_current = max_global = arr[0]
for num in arr[1:]:
max_current = max(num, max_current + num)
if max_current > max_global:
max_global = max_current
... | from solution import max_subarray_sum, max_subarray_sum_from_input
def test_max_subarray_sum_simple():
assert max_subarray_sum([5, -1, 5]) == 9
assert max_subarray_sum([1, 2, 3, 4]) == 10
assert max_subarray_sum([-1, -2, -3, -4]) == -1
assert max_subarray_sum([4, -1, 2, 1]) == 6
def test_max_subarray_... | [
{
"docstring": "Returns the maximum sum of the contiguous subarray using Kadane's Algorithm.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def max_subarray_sum_from_i... | [
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 subarray using Kadane's algorithm.\n \"\"\"\n max_current = max_global = ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032667",
"row_id": 32667,
"seed_ids": "[2797]"
} | 0.746623 | Taco_32667 | I | [
"max_subarray_sum",
"max_subarray_sum_from_input"
] | 2 | [
[
"max_subarray_sum_from_input",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f5977a44585a8c6802a517b6ffed042deed4ccac | 3bbbb20f7d44dd8a6f3ecbc3fba051f713252e0e | |||
v1.0 | instruct | Taco | Taco_32711_I | Alex is organizing a marathon event, and to manage the event efficiently, each runner will be assigned a unique bib number. The bib numbers have a special property: they need to be palindromes. A palindromic number is a number that remains the same when its digits are reversed.
Given a range of numbers [A, B], Alex ne... | def is_palindrome(num):
"""
Checks whether a number is a palindrome.
"""
return str(num) == str(num)[::-1]
def possible_palindromic_bibs(A, B, K):
"""
Determines if it is possible to assign K distinct palindromic bib numbers
within the range [A, B].
Returns "POSSIBLE" if feasible,... | from solution import is_palindrome, possible_palindromic_bibs, main
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
assert is_palindrome(10) == False
def test_possible_palindromic_bibs()... | [
{
"docstring": "Checks whether a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Determines if it is possible to assign K distinct palindromic bib numbers \nwithin the range [A, B].\n\... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a given number n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromes_in_range... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032711",
"row_id": 32711,
"seed_ids": "[14438]"
} | 0.70513 | Taco_32711 | I | [
"is_palindrome",
"possible_palindromic_bibs",
"main"
] | 3 | [
[
"possible_palindromic_bibs",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e0ed4e024ec4689bec7374543ffa391747f0567 | 60d1db11690c7479f6e928e3b19e895edf7eda0f | |||
v1.0 | instruct | Taco | Taco_32751_I | Given a binary tree:
- Perform a breadth-first search (BFS) traversal.
- For a given node, find and output the sum of values of its left and right children. If a node does not have a left or right child, treat it as 0.
Constraints:
* Each node's value is within the range $[-1,000,000, 1,000,000]$.
* The binary tree w... | from collections import deque, defaultdict
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(n, nodes_info):
nodes = {}
for value, left, right in nodes_info:
if value not in nodes:
nodes[value] = Tree... | def test_build_tree():
n = 3
nodes_info = [
(1, 2, 3),
(2, -1, -1),
(3, -1, -1)
]
nodes = build_tree(n, nodes_info)
assert nodes[1].value == 1
assert nodes[1].left.value == 2
assert nodes[1].right.value == 3
assert nodes[2].left == None
assert nodes[2].right =... | [] | [
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\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032751",
"row_id": 32751,
"seed_ids": "[20076]"
} | 0.6415 | Taco_32751 | I | [
"build_tree",
"breadth_first_search",
"find_children_sum",
"process_queries"
] | 4 | [
[
"process_queries",
"build_tree"
],
[
"process_queries",
"find_children_sum"
]
] | 2 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | false | [] | true | aec18cf48afff72924e8dc8f45cea0701c0c078d | d2718834758623faf94416c68ed191da0543d502 | |||
v1.0 | instruct | Taco | Taco_32795_I | Michelle is an avid mathematician who loves working with prime numbers. One day, she came up with the following problem while playing with her favorite numbers and started wondering if there was a pattern. The problem she came up with is this:
Given an integer N, find the largest prime factor of the number N! (N facto... | def sieve_of_eratosthenes(limit):
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(limit ** 0.5) + 1):
if is_prime[start]:
for multiple in range(start * start, limit + 1, start):
is_prime[multiple] = False
return [num for num... | from solution import solve_prime_factors_of_factorials, largest_prime_factorial, sieve_of_eratosthenes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_largest_... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns the largest prime factor of N!.",
"function_declaration": "def largest_prime_factorial(N):",
"function_na... | [
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 sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while p * ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032795",
"row_id": 32795,
"seed_ids": "[21520]"
} | 0.622265 | Taco_32795 | I | [
"sieve_of_eratosthenes",
"largest_prime_factorial",
"solve_prime_factors_of_factorials"
] | 3 | [
[
"largest_prime_factorial",
"sieve_of_eratosthenes"
],
[
"solve_prime_factors_of_factorials",
"largest_prime_factorial"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 24764d7a9e74ed40781e962ed1c62ae7d28e7c8f | 6b022a47d09e8890399dcdc4588e4af40c3fbc93 | |||
v1.0 | instruct | Taco | Taco_32808_I | In an ancient kingdom, there is a need to deliver crucial messages between cities using a system of couriers. The kingdom is represented as a graph with `n` cities and `m` potential roads between them. Each road has a specified weight that represents the time taken to traverse it. However, the construction of roads is ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i]) # path compression
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif... | from solution import min_max_weight_kruskal
def test_case_1():
n = 4
m = 5
edges = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 1),
(4, 1, 3),
(1, 3, 2)
]
result = min_max_weight_kruskal(n, edges)
assert result == 5
def test_case_2():
n = 3
m = 3
edges = ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_maximum_road(n, m, roads):\n parent = list(range(n + 1))\n rank = [0] * (n + 1)\n\n def find(x):\n if parent[x] != x:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032808",
"row_id": 32808,
"seed_ids": "[15282]"
} | 0.748149 | Taco_32808 | I | [
"find",
"union",
"min_max_weight_kruskal"
] | 3 | [
[
"min_max_weight_kruskal",
"find"
],
[
"min_max_weight_kruskal",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a184099df9738c98fd124fec8fbff00c5190664d | dbf4e31aeac114b82c346c26858c5b46fe721ad7 | |||
v1.0 | instruct | Taco | Taco_32816_I | A mysterious scroll has been found in an ancient library, and it contains encrypted messages believed to reveal the hidden location of a mythical treasure. The encryption method used is based on a unique set of rules involving prime numbers.
Your task is to write a program that decodes these messages. Each message con... | def sieve_of_eratosthenes(limit):
"""
Generate a list of booleans representing primality of numbers from 0 to limit.
True means the number is prime, False means it is not.
"""
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers
p = 2
wh... | def test_sieve_of_eratosthenes():
primes_up_to_10 = sieve_of_eratosthenes(10)
assert primes_up_to_10 == [False, False, True, True, False, True, False, True, False, False, False]
def test_count_primes_in_intervals():
intervals = [(2, 10), (11, 20), (20, 30)]
assert count_primes_in_intervals(intervals) =... | [
{
"docstring": "Generate a list of booleans representing primality of numbers from 0 to limit.\nTrue means the number is prime, False means it is not.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"do... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_primes_in_range(a, b):\n \"\"\"\n Returns the number of prime numbers in the interval [a, b] (inclusive).\n \"\"\"\n def is_prime(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032816",
"row_id": 32816,
"seed_ids": "[20244]"
} | 0.598068 | Taco_32816 | I | [
"sieve_of_eratosthenes",
"count_primes_in_intervals",
"decode_messages"
] | 3 | [
[
"count_primes_in_intervals",
"sieve_of_eratosthenes"
],
[
"decode_messages",
"count_primes_in_intervals"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 58369f091b07bf97de72af7248b476b59cc5ff57 | 2f1ae650e91c0eb7e7fb5a50a2adefde94fb2201 | |||
v1.0 | instruct | Taco | Taco_32920_I | #Min and Max Element Difference in a Rotated Array
You need to write a function that takes an array of integers and a rotation value as parameters. The function should rotate the array to the right by the given number of positions. Then, it should return the difference between the maximum and minimum element in the ro... | from typing import List
def rotate_array(arr: List[int], k: int) -> List[int]:
"""
Rotates the array to the right by k positions.
Parameters:
arr (List[int]): The input array.
k (int): The number of positions to rotate the array.
Returns:
List[int]: The rotated array.
"""
n = len(... | from solution import min_max_difference_in_rotated_array
def test_min_max_difference_in_rotated_array():
assert min_max_difference_in_rotated_array([3, 8, 9, 7, 6], 3) == 6
assert min_max_difference_in_rotated_array([1, 2, 3, 4, 5, 6], 2) == 5
assert min_max_difference_in_rotated_array([7, 4, 2, 9, 0], 1) ... | [
{
"docstring": "Rotates the array to the right by k positions.\n\nParameters:\narr (List[int]): The input array.\nk (int): The number of positions to rotate the array.\n\nReturns:\nList[int]: The rotated array.",
"function_declaration": "def rotate_array(arr, k):",
"function_name": "rotate_array",
"... | [
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 typing import List\n\ndef min_max_difference_in_rotated_array(arr: List[int], k: int) -> int:\n \"\"\"\n Rotates the array to the right by k positions a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032920",
"row_id": 32920,
"seed_ids": "[19895]"
} | 0.687514 | Taco_32920 | I | [
"rotate_array",
"min_max_difference_in_rotated_array"
] | 2 | [
[
"min_max_difference_in_rotated_array",
"rotate_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1dba74f9029b857a2573efd7ec3cc16dd195be0 | 9a92815955526830ebc5ddc98f81997f2cd69dee | |||
v1.0 | instruct | Taco | Taco_32924_I | Detect Cyclic Dependencies in a Directed Graph
**Problem**
You are given a directed graph represented by N vertices and M edges. Each edge is directed from vertex u_i to vertex v_i. Your task is to detect if there are any cyclic dependencies between the vertices in this graph.
**Input Format**
* The first line cont... | from collections import defaultdict, deque
def detect_cycle_in_directed_graph(N, M, edges):
def has_cycle():
indegree = [0] * (N + 1)
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
indegree[v] += 1
queue = deque()
... | from solution import detect_cycle
def test_cycle_in_graph():
assert detect_cycle(3, 3, [(1, 2), (2, 3), (3, 1)]) == "CYCLE"
def test_no_cycle_in_graph():
assert detect_cycle(4, 3, [(1, 2), (2, 3), (3, 4)]) == "NO CYCLE"
def test_another_cycle():
assert detect_cycle(4, 4, [(1, 2), (2, 3), (3, 4), (4, 2)])... | [
{
"docstring": null,
"function_declaration": "def detect_cycle_in_directed_graph(N, M, edges):",
"function_name": "detect_cycle_in_directed_graph",
"parameter_list": "(N, M, edges)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle(N, M, edges):",
"function_name": "de... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef detect_cycle(n, m, edges):\n def dfs(node):\n if node in visiting: # Cycle detected\n return True\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032924",
"row_id": 32924,
"seed_ids": "[14812]"
} | 0.791923 | Taco_32924 | I | [
"detect_cycle_in_directed_graph",
"detect_cycle"
] | 2 | [
[
"detect_cycle",
"detect_cycle_in_directed_graph"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19b8d7c8e8a64dd4b64504f3595ba5bef1048c7e | b1b73536c111cdbff555725451d05bf5f1c76846 | |||
v1.0 | instruct | Taco | Taco_32947_I | Given an undirected graph with `n` nodes and `m` edges, determine if there exists a valid path from the first node to the last node. If a valid path exists, print the length of the shortest path. If no such path exists, print -1.
Constraints
* 2 \leq n \leq 10^5
* 1 \leq m \leq 2 \times 10^5
* 1 \leq u, v \leq n for ... | from collections import deque, defaultdict
def bfs_shortest_path(n, edges):
# Create graph from edges
graph = defaultdict(list)
for u, v in edges:
graph[u-1].append(v-1)
graph[v-1].append(u-1)
# BFS to find the shortest path from node 0 to node n-1
queue = deque([0])
distances ... | def test_solution():
assert solution(5, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (2, 4), (1, 5)]) == 1
assert solution(4, 4, [(1, 2), (2, 3), (3, 4), (1, 3)]) == 2
assert solution(3, 2, [(1, 2), (2, 3)]) == 2
assert solution(3, 1, [(1, 2)]) == -1
assert solution(2, 1, [(1, 2)]) == 1
assert solution(6... | [
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(n, edges):",
"function_name": "bfs_shortest_path",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def solution(n, m, edges):",
"function_name": "solution",
"parameter_list": "(n, ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef bfs_shortest_path(n, edges):\n # Create graph from edges\n graph = defaultdict(list)\n for u, v in edges... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032947",
"row_id": 32947,
"seed_ids": "[9515]"
} | 0.810317 | Taco_32947 | I | [
"bfs_shortest_path",
"solution"
] | 2 | [
[
"solution",
"bfs_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 845e0e0736054884b5f40ec4c2f0bee1862d11f4 | 24dfaa023f621e3be9749d9b32b82d1afb1cbadf | |||
v1.0 | instruct | Taco | Taco_33004_I | You are given a matrix M of size N x N with distinct positive integers.
Consider all possible submatrices of M. Define the *value* of a submatrix as the sum of the elements on its boundary.
Find the submatrix with the maximum *value*. If multiple submatrices have the same *value*, consider the one which appears first... | def submatrix_boundary_sum(matrix, top_left, bottom_right):
"""
Returns the sum of the boundary elements of the submatrix defined by top_left and bottom_right.
"""
i1, j1 = top_left
i2, j2 = bottom_right
sum_val = 0
# Top boundary
for j in range(j1, j2 + 1):
sum_val += matri... | import pytest
from solution import submatrix_boundary_sum, find_max_boundary_sum_submatrix, process_test_cases
def test_submatrix_boundary_sum_case1():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert submatrix_boundary_sum(matrix, (0, 0), (2, 2)) == 40
def test_submatrix_bounda... | [
{
"docstring": "Returns the sum of the boundary elements of the submatrix defined by top_left and bottom_right.",
"function_declaration": "def submatrix_boundary_sum(matrix, top_left, bottom_right):",
"function_name": "submatrix_boundary_sum",
"parameter_list": "(matrix, top_left, bottom_right)"
}... | [
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 find_max_boundary_matrix(T, test_cases):\n def submatrix_value(matrix, top_left, bottom_right):\n top, left = top_left\n bottom, right = botto... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00033004",
"row_id": 33004,
"seed_ids": "[6435]"
} | 0.685206 | Taco_33004 | I | [
"submatrix_boundary_sum",
"find_max_boundary_sum_submatrix",
"process_test_cases"
] | 3 | [
[
"find_max_boundary_sum_submatrix",
"submatrix_boundary_sum"
],
[
"process_test_cases",
"find_max_boundary_sum_submatrix"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | d93cd5f2cad4a260eb2905642383628ff1066d1d | e420f3e56f5459817030e6899bfaeb63c42439e2 | |||
v1.0 | instruct | Taco | Taco_33067_I | Tara has a tree-structured data storage system. This tree is rooted at node 1 and has n nodes in total. Each node contains a certain amount of data. Tara needs to perform various operations on this tree. These operations are as follows:
1. Add Data: For a given node u, add a specific amount of data to it.
2. Retrieve ... | class TreeNode:
def __init__(self):
self.data = 0
self.children = []
def add_data(tree, u, d):
tree[u].data += d
def get_subtree_sum(tree, u):
def dfs(node):
total = node.data
for child in node.children:
total += dfs(tree[child])
return total
return ... | from solution import solve
def test_solve_example():
n, q = 5, 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(1, 2, 5), (1, 3, 10), (2, 2), (2, 1), (2, 3)]
assert solve(n, q, edges, queries) == [5, 15, 10]
def test_solve_no_data_operations():
n, q = 3, 2
edges = [(1, 2), (1, 3)]
qu... | [] | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass TreeDataStorage:\n def __init__(self, n):\n self.n = n\n self.tree = defaultdict(list)\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033067",
"row_id": 33067,
"seed_ids": "[14717]"
} | 0.618493 | Taco_33067 | I | [
"add_data",
"get_subtree_sum",
"solve"
] | 3 | [
[
"solve",
"add_data"
],
[
"solve",
"get_subtree_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 52d9a19d09ce62dcaf6985b3b96fad1656975834 | e7c3ed13f33ec3bae3e57faf39177ac7da025c37 | |||
v1.0 | instruct | Taco | Taco_33091_I | You are given a balanced binary search tree (BST) and an integer $k$. Your task is to determine whether there exist two different nodes in the BST whose values sum up to $k$.
Consider the following definition for a binary search tree node:
```python
class Node:
def __init__(self, data):
self.data = data
... | class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def insert(root, data):
if root is None:
return Node(data)
if data < root.data:
root.left = insert(root.left, data)
else:
root.right = insert(root.right, data)
r... | def test_exists_pair_with_sum_yes():
values = [4, 2, 6, 1, 3, 5, 7]
k = 9
root = build_bst_from_list(values)
assert exists_pair_with_sum(root, k) == True
def test_exists_pair_with_sum_no():
values = [4, 2, 6, 1, 3, 5, 7]
k = 14
root = build_bst_from_list(values)
assert exists_pair_with_... | [] | [
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 Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\ndef insert(root, data):\n if root i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033091",
"row_id": 33091,
"seed_ids": "[21179]"
} | 0.61586 | Taco_33091 | I | [
"insert",
"find_pair_with_sum",
"exists_pair_with_sum",
"build_bst_from_list"
] | 4 | [
[
"build_bst_from_list",
"insert"
],
[
"exists_pair_with_sum",
"find_pair_with_sum"
]
] | 2 | [] | false | [
"Node"
] | true | pytest | false | [] | true | b603572e5a7bc35c4293c5c3fde24cefe12d81ed | 2df6282ba4b35dffc0cd54582df9487d4e390c4a | |||
v1.0 | instruct | Taco | Taco_33099_I | ### Secret Santa Code:
Every year, the employees of a company participate in a Secret Santa gift exchange. Each participant must draw a name to determine who they will give a gift to. The company wants to ensure that each year, no one draws their own name, and that the same person doesn't give a gift to another person... | import random
def secret_santa(n, participants, last_year_pairs):
# Convert last year pairs into a dictionary for fast lookup
last_year_dict = {pair[0]: pair[1] for pair in last_year_pairs}
# Initial constraint where no one should get themselves
current_year = {name: None for name in participants}
... | def test_secret_santa_base_case():
n = 4
participants = ["Alice", "Bob", "Charlie", "Dave"]
last_year_pairs = ["Alice Bob", "Bob Charlie", "Charlie Dave", "Dave Alice"]
result = create_secret_santa_pairings(n, participants, last_year_pairs)
# Convert the results to a dictionary for easy ve... | [
{
"docstring": null,
"function_declaration": "def secret_santa(n, participants, last_year_pairs):",
"function_name": "secret_santa",
"parameter_list": "(n, participants, last_year_pairs)"
},
{
"docstring": null,
"function_declaration": "def create_secret_santa_pairings(n, participants, l... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef secret_santa(participants, last_year_pairs):\n \"\"\"\n Generates a new Secret Santa drawing that ensures no one draws their own name\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033099",
"row_id": 33099,
"seed_ids": "[10631]"
} | 0.608154 | Taco_33099 | I | [
"secret_santa",
"create_secret_santa_pairings"
] | 2 | [
[
"create_secret_santa_pairings",
"secret_santa"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | cc4f1020ba59432e6f4c53ffb32eb3025ee7af12 | 8fc7072e149090fd44cf976fe23443e206f2fb76 | |||
v1.0 | instruct | Taco | Taco_33194_I | In an ancient kingdom, there are N villages connected by M bidirectional roads, where each road connects exactly two different villages. The roads can have different lengths. The kingdom wants to minimize the total road length required to connect all villages so that there is a path between any pair of villages, essent... | from typing import List, Tuple
def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
... | def test_example_case():
N = 4
M = 5
roads = [(1, 2, 1), (1, 3, 3), (2, 3, 2), (3, 4, 4), (4, 2, 5)]
assert minimum_spanning_tree(N, M, roads) == 7
def test_disconnected_graph():
N = 4
M = 2
roads = [(1, 2, 1), (3, 4, 2)]
assert minimum_spanning_tree(N, M, roads) == -1
def test_single_... | [
{
"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 minimum_spanning_tree(N: int, M: int, roads):\n \"\"\"\n Returns the total length of the Minimum Spanning Tree (MST) connecting all N villages.\n If i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033194",
"row_id": 33194,
"seed_ids": "[11044]"
} | 0.703972 | Taco_33194 | I | [
"find",
"union",
"minimum_spanning_tree"
] | 3 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | eae1522525e3528e0cd4f16ede33e0e9d5b28046 | f5e4891cf6bd5ec354123d1d5db80b8c31da1bda | |||
v1.0 | instruct | Taco | Taco_33222_I | ### Rock, Paper, Scissors Tournament
You have been chosen to write a simulation for a "Rock, Paper, Scissors" tournament. In this tournament, players are paired up and play against each other, with the winners advancing to the next round until only one winner is left.
The rules for "Rock, Paper, Scissors" are as foll... | import random
def simulate_game(player1, player2):
choices = ['Rock', 'Paper', 'Scissors']
if player1 == 'Random':
player1 = random.choice(choices)
if player2 == 'Random':
player2 = random.choice(choices)
if player1 == player2:
return player1 # In the case of a ti... | from solution import rock_paper_scissors_tournament
import random
def test_single_case():
test_cases = [
["Rock", "Paper", "Scissors", "Random"]
]
result = rock_paper_scissors_tournament(test_cases)
assert result[0] in ["Rock", "Paper", "Scissors", "Random"]
def test_all_rock():
test_cases... | [
{
"docstring": null,
"function_declaration": "def simulate_game(player1, player2):",
"function_name": "simulate_game",
"parameter_list": "(player1, player2)"
},
{
"docstring": null,
"function_declaration": "def simulate_tournament(strategies):",
"function_name": "simulate_tournament"... | [
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 random\n\ndef simulate_match(player1, player2):\n winning_combinations = {\n (\"Rock\", \"Scissors\"): player1,\n (\"Scissors\", \"Rock\"):... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033222",
"row_id": 33222,
"seed_ids": "[8680]"
} | 0.775324 | Taco_33222 | I | [
"simulate_game",
"simulate_tournament",
"rock_paper_scissors_tournament"
] | 3 | [
[
"rock_paper_scissors_tournament",
"simulate_tournament"
],
[
"simulate_tournament",
"simulate_game"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3f92215fc9c2ec343bd7a65015fcea6363ef27a6 | 1362d71814f51597f5dc06c746df7666f7d27c0c | |||
v1.0 | instruct | Taco | Taco_33229_I | Alex is designing a new game where players hunt for treasure on a rectangular grid. Each cell in the grid either contains grass ('.') or is impassable rock ('#'). Players must move from a start cell to a treasure cell using the shortest path possible, but they can only move up, down, left, or right (no diagonal moves).... | from collections import deque
def min_moves_to_treasure(m, n, grid, x1, y1, x2, y2):
def is_valid(x, y):
return 0 <= x < m and 0 <= y < n and grid[x][y] == '.'
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(x1, y1, 0)]) # (current_x, current_y, current_distance)
visited = set... | from solution import solve_game
def test_example_1():
m, n = 5, 5
grid_lines = [".....", ".###.", ".....", ".#...", "....."]
start_end = (0, 0, 4, 4)
assert solve_game(m, n, grid_lines, start_end) == 8
def test_example_2():
m, n = 3, 4
grid_lines = ["....", "####", "...."]
start_end = (0, ... | [
{
"docstring": null,
"function_declaration": "def min_moves_to_treasure(m, n, grid, x1, y1, x2, y2):",
"function_name": "min_moves_to_treasure",
"parameter_list": "(m, n, grid, x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def solve_game(m, n, grid_lines, start_end):"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_moves_to_reach_treasure(m, n, grid, start, treasure):\n \"\"\"\n Determines the minimum number of moves needed to re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033229",
"row_id": 33229,
"seed_ids": "[9216]"
} | 0.76715 | Taco_33229 | I | [
"min_moves_to_treasure",
"solve_game"
] | 2 | [
[
"solve_game",
"min_moves_to_treasure"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 896156ea32d3b3fa20625f11f9ff5b9011dd1771 | 3be1d42e40db4b5b4aa35c8d1b3baa8746946a63 | |||
v1.0 | instruct | Taco | Taco_33261_I | Train Scheduling
A busy railway system consists of multiple tracks on which trains can travel. Each track connects two stations directly. However, each track allows only one train to travel at a given time. This means that once a train starts its journey on a track, no other train can use the same track until the firs... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot] ... | from solution import min_train_scheduling_time
def test_min_train_scheduling_time_case1():
n, m = 4, 4
track_list = [
(1, 2, 5),
(1, 3, 10),
(2, 4, 3),
(3, 4, 4)
]
assert min_train_scheduling_time(n, m, track_list) == 12
def test_min_train_scheduling_time_case2():
n... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033261",
"row_id": 33261,
"seed_ids": "[23400]"
} | 0.751944 | Taco_33261 | I | [
"find",
"union",
"kruskal",
"min_train_scheduling_time"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_train_scheduling_time",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 384334a64ae4bce172afcd588ae35747c0d69619 | 10dd59e4216a6d2fbbdf5c989a9ecf5e4efda0e4 | |||
v1.0 | instruct | Taco | Taco_33297_I | John has recently started practicing his mathematical skills and has taken a special interest in prime numbers. He came up with an engaging problem to challenge himself. The problem is to find the smallest prime number greater than a given number N.
Your task is to help John by writing a program that, for each test ca... | import math
def is_prime(num):
"""
Checks 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... | from solution import is_prime, smallest_prime_greater_than, solve
def test_is_prime():
assert is_prime(7) == True
assert is_prime(4) == False
assert is_prime(2) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(29) == True
def test_smallest_prime_greater_than():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest prime number greater than n.",
"function_declaration": "def smallest_prime_greater_than(n):",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033297",
"row_id": 33297,
"seed_ids": "[1159]"
} | 0.619587 | Taco_33297 | I | [
"is_prime",
"smallest_prime_greater_than",
"solve"
] | 3 | [
[
"smallest_prime_greater_than",
"is_prime"
],
[
"solve",
"smallest_prime_greater_than"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1b36c201236107fc6bcc15faae545b7c032af1a6 | f26848bcb4a166da8ac88dad36de2ab4a8dc2d12 | |||
v1.0 | instruct | Taco | Taco_33351_I | Sarah is preparing for a cooking competition and is practicing some advanced knife skills. She has a set of various knives, each with a different sharpness value. Given that a recipe involves cutting certain ingredients, she needs to ensure that each cut made is as smooth as possible. A smooth cut requires a knife shar... | def count_sharp_knives(knives, required_sharpness):
"""
Returns a list of counts of knives suitable for each ingredient's required sharpness.
Parameters:
knives (list): a list of integers representing the sharpness values of the knives.
required_sharpness (list): a list of integers representing... | from solution import count_sharp_knives
def test_example_1():
knives = [10, 15, 20]
required_sharpness = [12, 17]
assert count_sharp_knives(knives, required_sharpness) == [2, 1]
def test_example_2():
knives = [5, 9, 12, 16, 25]
required_sharpness = [10, 20, 8, 5]
assert count_sharp_knives(kniv... | [
{
"docstring": "Returns a list of counts of knives suitable for each ingredient's required sharpness.\n\nParameters:\nknives (list): a list of integers representing the sharpness values of the knives.\nrequired_sharpness (list): a list of integers representing the required sharpness for each ingredient.\n\nRetu... | [
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 suitable_knives(knives, ingredients):\n \"\"\"\n For each ingredient's required sharpness, count how many knives in the set \n have a sharpness value ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033351",
"row_id": 33351,
"seed_ids": "[11270]"
} | 0.712739 | Taco_33351 | I | [
"count_sharp_knives",
"binary_search"
] | 2 | [
[
"count_sharp_knives",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 42e9b4f8f4c5405fc21e9906c4545ceb41b6aa4d | 2e02ed4dd5fa11bc161fcfdbe1a30a20891dd789 | |||
v1.0 | instruct | Taco | Taco_33365_I | You are tasked with developing a system to manage the stock levels of a warehouse. The warehouse records the addition and removal of items continuously, and you need to write a program to track the current stock levels of each item in the inventory, as well as answer queries about the stock levels during specific perio... | def manage_stock(datasets):
results = []
for dataset in datasets:
transactions = dataset["transactions"]
queries = dataset["queries"]
stock_changes = {}
for trans in transactions:
t, i, v, a = trans
if i not in stock_changes:
... | import pytest
from solution import warehouse_stock_management
def test_single_dataset():
input_data = "3 5\n60 1 10 1\n120 2 20 0\n180 1 5 0\n240 3 15 1\n300 2 5 1\n3\n0 240 1\n60 300 2\n0 300 3\n0 0\n"
expected_output = [5, -15, 15]
assert warehouse_stock_management(input_data) == expected_output
def tes... | [
{
"docstring": null,
"function_declaration": "def manage_stock(datasets):",
"function_name": "manage_stock",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_data):",
"function_name": "process_input",
"parameter_list": "(inpu... | [
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 warehouse_stock_levels(datasets):\n output = []\n for data in datasets:\n n, t, transactions, q, queries = data\n\n # Initialize stock leve... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033365",
"row_id": 33365,
"seed_ids": "[9691]"
} | 0.631381 | Taco_33365 | I | [
"manage_stock",
"process_input",
"warehouse_stock_management"
] | 3 | [
[
"warehouse_stock_management",
"manage_stock"
],
[
"warehouse_stock_management",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 45203413568eb52c841dfbf72872f10e25634935 | 053df1d211878f1ef3aa69140dbb3bf2a8710cc7 | |||
v1.0 | instruct | Taco | Taco_33416_I | You are given a matrix of characters that represents a grid, and each cell contains a lowercase English letter. Your goal is to find the largest square sub-matrix such that all the cells in that sub-matrix contain the same character. The side length of this largest square sub-matrix is your result.
Write a program to ... | def largest_square_submatrix(matrix):
if not matrix:
return 0
M = len(matrix)
N = len(matrix[0])
# Initialize dp table
dp = [[0] * N for _ in range(M)]
max_side_length = 0
for i in range(M):
for j in range(N):
if i == 0 or j == 0:
dp... | def test_largest_square_submatrix():
# Test case from the example 1
input1 = "5 6\na a a b b b\na a a b b b\na a a c c c\nb b b c c c\nb b b c c c"
assert read_input_and_solve(input1) == 3
# Test case from the example 2
input2 = "4 4\np p q q\np p q q\nl l k k\nl l k k"
assert read_input_an... | [
{
"docstring": null,
"function_declaration": "def largest_square_submatrix(matrix):",
"function_name": "largest_square_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_solve(input_str):",
"function_name": "read_input_and_sol... | [
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 largest_square_submatrix(matrix):\n if not matrix:\n return 0\n \n M = len(matrix)\n N = len(matrix[0])\n \n # Initialize dp table\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033416",
"row_id": 33416,
"seed_ids": "[21476]"
} | 0.675521 | Taco_33416 | I | [
"largest_square_submatrix",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"largest_square_submatrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 42824317a62c1fb2f8fe4b2faa7c582c3b1ded55 | 58ec40f96ed8aeaaeab9b6111b95eb8d52929162 | |||
v1.0 | instruct | Taco | Taco_33446_I | You are tasked with managing a city's water distribution system comprised of a series of underground pipes. Each pipe connects two distinct water tanks in the city and ensures the flow of water between them. The city has a total of n water tanks, numbered from 1 to n, and m pipes. Each pipe has an associated maintenanc... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | from solution import minimum_cost_to_connect_water_tanks
def test_minimum_cost_example():
assert minimum_cost_to_connect_water_tanks(4, 5, [(1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (3, 4, 5)]) == 6
def test_minimum_cost_single_pipe():
assert minimum_cost_to_connect_water_tanks(2, 1, [(1, 2, 10)]) == 10
de... | [
{
"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(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033446",
"row_id": 33446,
"seed_ids": "[25118]"
} | 0.710414 | Taco_33446 | I | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_water_tanks"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_water_tanks",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 1a328003a1ddc0d3c91cd8787eb386c7cc6169dd | 40bbd8bdc4cc7002f7d476a52854242d6eadda4e | |||
v1.0 | instruct | Taco | Taco_33467_I | You are given a series of words and a text. For each word, you need to determine whether the word is a subsequence of the given text. A word is a subsequence of a text if it can be derived from the text by deleting some or no characters without changing the order of the remaining characters.
For each word, print "yes"... | def is_subsequence(word, text):
"""
Determines if the word is a subsequence of the text.
"""
it = iter(text)
return all(char in it for char in word)
def check_subsequences(text, words):
"""
For each word in words, check if it is a subsequence of the text.
Parameters:
- text (st... | def test_is_subsequence():
assert is_subsequence("hello", "helloworld") == True
assert is_subsequence("hero", "helloworld") == False
assert is_subsequence("low", "helloworld") == True
assert is_subsequence("helo", "helloworld") == True
assert is_subsequence("hellowolrdx", "helloworld") == False
... | [
{
"docstring": "Determines if the word is a subsequence of the text.",
"function_declaration": "def is_subsequence(word, text):",
"function_name": "is_subsequence",
"parameter_list": "(word, text)"
},
{
"docstring": "For each word in words, check if it is a subsequence of the text.\n\nParame... | [
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_subsequence(word, text):\n \"\"\"\n Determines if the word is a subsequence of the text.\n \"\"\"\n it = iter(text)\n return all(char in it f... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033467",
"row_id": 33467,
"seed_ids": "[3045]"
} | 0.696348 | Taco_33467 | I | [
"is_subsequence",
"check_subsequences"
] | 2 | [
[
"check_subsequences",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8fdbd7f6f977e4e2bbf70ad67750cf1e51d8b3ea | 7cf1df352cb81259065a53e9a568406a55117ec7 | |||
v1.0 | instruct | Taco | Taco_33490_I | This problem is about subsets of positive integers and their arithmetic properties. You're given an array of integers, and you need to determine if there exists a subset of this array whose sum is a prime number.
A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural... | from itertools import combinations
def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % i + 2 == 0:
return F... | from solution import exists_prime_subset_sum
def test_example_1():
assert exists_prime_subset_sum(5, [1, 2, 3, 4, 5]) == "YES"
def test_example_2():
assert exists_prime_subset_sum(4, [4, 6, 8, 10]) == "NO"
def test_single_element_prime():
assert exists_prime_subset_sum(1, [2]) == "YES"
def test_single_e... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determines if there exists a subset of the given array such that the sum of \nthe subset is a prime number.",
"function_decla... | [
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 itertools import combinations\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033490",
"row_id": 33490,
"seed_ids": "[23512]"
} | 0.652778 | Taco_33490 | I | [
"is_prime",
"exists_prime_subset_sum"
] | 2 | [
[
"exists_prime_subset_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f40661ce7cc0a1d0e135909b4b5a3cdf336df79 | 15237583ea628a257a91d3a5d742ec6241e095ef | |||
v1.0 | instruct | Taco | Taco_33500_I | You are given `n` points on a 2D plane, and you are to determine if a valid triangle can be formed from any three of these points. The coordinates of the points are given as integer pairs (x, y).
Input:
The first line contains one integer `n` (3 ≤ n ≤ 1000) — the number of points. Each of the next `n` lines contains t... | def is_valid_triangle(a, b, c):
"""
Check if three points a, b, c form a valid triangle.
The area of the triangle must be non-zero.
"""
# a, b, c are tuples of the form (x, y)
(x1, y1), (x2, y2), (x3, y3) = a, b, c
# The determinant of the matrix formed by the vectors
# (x2 - x1, y2 - y... | def test_is_valid_triangle():
assert is_valid_triangle((0, 0), (1, 1), (0, 1)) == True
assert is_valid_triangle((0, 0), (1, 1), (2, 2)) == False
assert is_valid_triangle((1, 1), (2, 3), (3, 2)) == True
assert is_valid_triangle((0, 0), (0, 1), (0, 2)) == False
def test_can_form_triangle_yes():
point... | [
{
"docstring": "Check if three points a, b, c form a valid triangle.\nThe area of the triangle must be non-zero.",
"function_declaration": "def is_valid_triangle(a, b, c):",
"function_name": "is_valid_triangle",
"parameter_list": "(a, b, c)"
},
{
"docstring": "Determine if there exists a set... | [
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_valid_triangle(points):\n \"\"\"\n Determines if a valid triangle can be formed from any three points.\n A triangle is valid if the area formed by ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033500",
"row_id": 33500,
"seed_ids": "[22755]"
} | 0.746931 | Taco_33500 | I | [
"is_valid_triangle",
"can_form_triangle"
] | 2 | [
[
"can_form_triangle",
"is_valid_triangle"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a5501ff11fce98f5ed4b5eb58dc952e694770a93 | e02a6efb8c9b6b15959634882c1d3c19361c3732 | |||
v1.0 | instruct | Taco | Taco_33529_I | Carol is organizing a friendly math competition in her school. As part of the competition, she has created a unique game involving prime numbers. The game is designed as follows: given two integers \(A\) and \(B\), the task is to find how many prime numbers exist between \(A\) and \(B\) (inclusive).
A prime number is ... | def prime_sieve(limit):
"""
Generate a list of booleans where True indicates that
the index is a prime number (valid up to the limit).
"""
primes = [True] * (limit + 1)
primes[0], primes[1] = False, False # 0 and 1 are not primes
p = 2
while (p * p <= limit):
if (primes[p] == T... | def test_prime_sieve():
limit = 20
primes = prime_sieve(limit)
expected_primes_indices = [2, 3, 5, 7, 11, 13, 17, 19]
for i in range(limit + 1):
if i in expected_primes_indices:
assert primes[i] == True
else:
assert primes[i] == False
def test_count_primes_in_ran... | [
{
"docstring": "Generate a list of booleans where True indicates that \nthe index is a prime number (valid up to the limit).",
"function_declaration": "def prime_sieve(limit):",
"function_name": "prime_sieve",
"parameter_list": "(limit)"
},
{
"docstring": "Count the number of prime numbers b... | [
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 prime_sieve(limit):\n \"\"\"\n Generate a list of booleans where True indicates that \n the index is a prime number (valid up to the limit).\n \"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033529",
"row_id": 33529,
"seed_ids": "[20566]"
} | 0.655868 | Taco_33529 | I | [
"prime_sieve",
"count_primes_in_range",
"number_of_primes"
] | 3 | [
[
"number_of_primes",
"count_primes_in_range"
],
[
"number_of_primes",
"prime_sieve"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | edad951ac0034f444389fa2bb655dc30f29a0a0b | 57d5df8b3db0c1b3c3f5e17060f8e7a4b7848af0 | |||
v1.0 | instruct | Taco | Taco_33557_I | Given an array of integers, implement a system that answers the following types of queries efficiently:
1. **Update Query:** Update the value at a specific index in the array.
2. **Range Query:** Calculate the product of values in a specified subarray.
### Input
The first line contains two integers `n` (1 ≤ n ≤ 10^5... | MOD = 10**9 + 7
def preprocess(arr):
"""
Create a prefix product array for efficient range product querying.
"""
n = len(arr)
prefix_prod = [1] * (n + 1)
for i in range(1, n + 1):
prefix_prod[i] = (prefix_prod[i - 1] * arr[i - 1]) % MOD
return prefix_prod
def update(arr, index, val... | from solution import process_queries
def test_example_1():
n = 5
arr = [1, 2, 3, 4, 5]
queries = [
[2, 1, 3],
[1, 3, 6],
[2, 1, 3],
[2, 3, 5],
[1, 5, 2],
]
expected = [6, 12, 120]
assert process_queries(n, arr, queries) == expected
def test_small_array()... | [
{
"docstring": "Create a prefix product array for efficient range product querying.",
"function_declaration": "def preprocess(arr):",
"function_name": "preprocess",
"parameter_list": "(arr)"
},
{
"docstring": "Update the array and rebuild the prefix product array.",
"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": "MOD = 10**9 + 7\n\nclass ProductArray:\n def __init__(self, array):\n self.array = array\n self.n = len(array)\n self.product_tree = [1] * ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033557",
"row_id": 33557,
"seed_ids": "[8777]"
} | 0.661959 | Taco_33557 | I | [
"preprocess",
"update",
"range_product",
"process_queries"
] | 4 | [
[
"process_queries",
"preprocess"
],
[
"process_queries",
"range_product"
],
[
"process_queries",
"update"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 8aba12c1304a1ecf56c3b7eddfcb886994a3201e | c0fdec9b158a59ca7de9530a8d17ae1c8536aafe | |||
v1.0 | instruct | Taco | Taco_33576_I | You have a grid of size `M x N` consisting of only 0s and 1s. You want to find the largest rectangle containing only 1s and return its area.
Input Format:
The first line contains two integers `M` and `N`, denoting the number of rows and columns in the grid respectively.
The next `M` lines each contain a string of `N... | def max_histogram_area(histogram):
"""
Helper function to calculate the largest rectangular area in a histogram.
"""
stack = []
max_area = 0
index = 0
while index < len(histogram):
if not stack or histogram[stack[-1]] <= histogram[index]:
stack.append(index)
... | def test_largest_rectangle_area_sample1():
matrix = [
"1010",
"1011",
"1110",
"1000"
]
assert largest_rectangle_area(matrix) == 4
def test_largest_rectangle_area_sample2():
matrix = [
"11100",
"11110",
"01110"
]
assert largest_rectangle_ar... | [
{
"docstring": "Helper function to calculate the largest rectangular area in a histogram.",
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": null,
"function_declaration": "def largest_re... | [
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_histogram_area(histogram):\n \"\"\"\n Helper function to calculate the largest rectangular area in a histogram.\n \"\"\"\n stack = []\n max_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033576",
"row_id": 33576,
"seed_ids": "[14433]"
} | 0.764355 | Taco_33576 | I | [
"max_histogram_area",
"largest_rectangle_area"
] | 2 | [
[
"largest_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e751a9bb5977e92830745b1f2f12c53f225c2657 | c63185f0baf792bf8ae6b71d46f42141c3b0e172 | |||
v1.0 | instruct | Taco | Taco_33587_I | Marie is learning about binary trees and she is building a tree where each node has an integer value. She would like to determine the sum of values on the path from the root to each leaf node in her binary tree.
Write a program that constructs Marie's binary tree and computes the required sums.
-----Input-----
The f... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
node_dict = {}
for node, left, right in nodes:
if node not in node_dict:
node_dict[node] = TreeNode(node)
if left != -1:
... | from solution import solve
def test_single_path_tree():
test_cases = [
{
'nodes': [(1, 2, -1), (2, 3, -1), (3, 4, -1), (4, 5, -1), (5, -1, -1)]
}
]
assert solve(test_cases) == [[15]]
def test_balanced_tree():
test_cases = [
{
'nodes': [
(... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "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_1 | {
"original_instruction": "",
"prompt_id": "00033587",
"row_id": 33587,
"seed_ids": "[12242]"
} | 0.661637 | Taco_33587 | I | [
"build_tree",
"collect_path_sums",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"collect_path_sums"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | dc296ac1d89edd4477fcd7ce4daacedba5beb1ef | d2763d625ffe8115f703f63b11eb433a263c713c | |||
v1.0 | instruct | Taco | Taco_33638_I | Given a list of words, write a program that will determine the word with the highest score. The score of a word is defined as the sum of the positions of its letters in the alphabet (i.e., a = 1, b = 2, ..., z = 26).
For example, the score of the word "abc" is 1 + 2 + 3 = 6.
If two words have the same score, the word... | def calculate_word_score(word):
"""
Calculate the score of a word based on the sum of positions of its letters in the alphabet.
"""
score = sum(ord(letter) - ord('a') + 1 for letter in word)
return score
def highest_scoring_word(words):
"""
Given a list of words, return the word with the hi... | from solution import calculate_word_score, highest_scoring_word
def test_calculate_word_score():
assert calculate_word_score('a') == 1
assert calculate_word_score('abc') == 6
assert calculate_word_score('cat') == 24
assert calculate_word_score('dog') == 26
assert calculate_word_score('zebra') == 52... | [
{
"docstring": "Calculate the score of a word based on the sum of positions of its letters in the alphabet.",
"function_declaration": "def calculate_word_score(word):",
"function_name": "calculate_word_score",
"parameter_list": "(word)"
},
{
"docstring": "Given a list of words, return the wo... | [
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 word_score(word):\n \"\"\"\n Returns the score of a given word.\n The score is computed as the sum of positions of its letters in the alphabet (a = 1,... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033638",
"row_id": 33638,
"seed_ids": "[5299]"
} | 0.718458 | Taco_33638 | I | [
"calculate_word_score",
"highest_scoring_word"
] | 2 | [
[
"highest_scoring_word",
"calculate_word_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d6794e18296c8089ed65eccad92810f9c788e19 | bab972fe1769b4e9500930c239b342bea3eec30f | |||
v1.0 | instruct | Taco | Taco_33643_I | Given a city represented as a grid with buildings and vacant lots, you need to determine the largest rectangular area that can be developed into a park. The city is represented by a 2D binary matrix where '1' represents a building and '0' represents a vacant lot. Your task is to find the maximum area of a rectangle mad... | def maximalRectangle(matrix):
if not matrix:
return 0
m, n = len(matrix), len(matrix[0])
heights = [0] * n
max_area = 0
for i in range(m):
for j in range(n):
if matrix[i][j] == '0':
heights[j] += 1
else:
heights[j] = 0... | from solution import maximalRectangle
def test_example1():
matrix = [
["1", "0", "1", "0", "0"],
["1", "0", "1", "1", "1"],
["1", "0", "1", "1", "1"],
["1", "0", "0", "0", "1"]
]
assert maximalRectangle(matrix) == 4
def test_example2():
matrix = [
["0", "1"],
... | [
{
"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 maximalRectangle(matrix):\n if not matrix:\n return 0\n max_area = 0\n row_len = len(matrix[0])\n heights = [0] * (row_len + 1)\n for row... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033643",
"row_id": 33643,
"seed_ids": "[20358]"
} | 0.660447 | Taco_33643 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 953717a019ae5519804e6f7cec5a9c06870db5cf | 7635f8bf0c9b6b5e230abd5b8d97cd73ce2f057f | |||
v1.0 | instruct | Taco | Taco_33680_I | Given a binary tree, determine if the tree is a mirror of itself (i.e., symmetric around its center).
### Input Format
- A single line containing a list of integers representing the values of nodes in the binary tree in level-order traversal. Use `null` to represent null nodes in the tree. For example: `[1,2,2,3,4,4,... | # Define TreeNode class to create a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def isSymmetric(root):
"""
Determines whether the binary tree with the given root is symmetric.
"""
def isMirror(t1, t2):
... | from solution import is_symmetric_tree
def test_symmetric_tree():
assert is_symmetric_tree([1, 2, 2, 3, 4, 4, 3]) == "true"
def test_asymmetric_tree():
assert is_symmetric_tree([1, 2, 2, None, 3, None, 3]) == "false"
def test_single_node_tree():
assert is_symmetric_tree([1]) == "true"
def test_empty_tre... | [] | [
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 typing import List, Optional\n\nclass TreeNode:\n def __init__(self, x: int):\n self.val = x\n self.left: Optional[TreeNode] = None\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033680",
"row_id": 33680,
"seed_ids": "[22968]"
} | 0.624634 | Taco_33680 | I | [
"isSymmetric",
"build_tree_from_level_order",
"is_symmetric_tree"
] | 3 | [
[
"is_symmetric_tree",
"build_tree_from_level_order"
],
[
"is_symmetric_tree",
"isSymmetric"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e84631375d892a14737500152c478a021490cffa | 37e0d36d1b117cda00bb51416a26281b8ab97dbb | |||
v1.0 | instruct | Taco | Taco_33762_I | A smartphone application requires users to set up a password that follows specific security rules. The rules are as follows:
- The password must be at least 8 characters long.
- The password must not contain any space characters.
- The password must contain at least one uppercase letter.
- The password must contain at ... | import re
def validate_passwords(test_cases):
results = []
special_characters = re.compile(r'[!@#$%^&*()]')
for password in test_cases:
if len(password) < 8:
results.append("INVALID")
elif ' ' in password:
results.append("INVALID")
elif not any(char.isup... | from solution import validate_passwords
def test_valid_passwords():
assert validate_passwords(["SecurePa$$word123"]) == ["VALID"]
def test_short_password():
assert validate_passwords(["123456"]) == ["INVALID"]
def test_password_with_space():
assert validate_passwords(["InvaliD @9"]) == ["INVALID"]
as... | [
{
"docstring": null,
"function_declaration": "def validate_passwords(test_cases):",
"function_name": "validate_passwords",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def validate_password_input():",
"function_name": "validate_password_input",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef validate_password(password):\n if len(password) < 8:\n return \"INVALID\"\n if ' ' in password:\n return \"INVALID\"\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033762",
"row_id": 33762,
"seed_ids": "[213]"
} | 0.64192 | Taco_33762 | I | [
"validate_passwords",
"validate_password_input"
] | 2 | [
[
"validate_password_input",
"validate_passwords"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 57bc387c5d665c5e378ef59779da4d42a474b10b | e9686615994cc99305238145fc362f6f207a1dc1 | |||
v1.0 | instruct | Taco | Taco_33771_I | Maze Solver
Bob and Alice are playing another board game. The game is played on an H by W grid. Initially, the grid contains open paths (.) and walls (#). Bob can play first and he can place a wall on any open path to block it. Alice’s goal is to start from the top-left corner of the grid and find a way to reach the... | from collections import deque
def valid(r, c, H, W, grid, visited):
return 0 <= r < H and 0 <= c < W and grid[r][c] == '.' and not visited[r][c]
def bfs(grid, H, W):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(0, 0)])
visited = [[False]*W for _ in range(H)]
visited[0][0] = True... | from solution import process_input
def test_sample_input():
input_data = [
"3 3",
"..#",
".#.",
"...",
"3 3",
"..#",
"###",
"...",
"4 4",
"....",
".#.#",
"....",
"....",
"0 0"
]
expected_output =... | [
{
"docstring": null,
"function_declaration": "def valid(r, c, H, W, grid, visited):",
"function_name": "valid",
"parameter_list": "(r, c, H, W, grid, visited)"
},
{
"docstring": null,
"function_declaration": "def bfs(grid, H, W):",
"function_name": "bfs",
"parameter_list": "(grid... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(grid, H, W):\n \"\"\" Perform Breadth-First Search to see if a path exists from start to end. \"\"\"\n if grid[0][0]... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033771",
"row_id": 33771,
"seed_ids": "[2599]"
} | 0.686823 | Taco_33771 | I | [
"valid",
"bfs",
"can_alice_escape",
"process_input"
] | 4 | [
[
"bfs",
"valid"
],
[
"can_alice_escape",
"bfs"
],
[
"process_input",
"can_alice_escape"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | e72009db0e31b1c0728ecd677f787550d9479e9b | 84f8ac29add9973b7bdee7db823164a993b6bcbf | |||
v1.0 | instruct | Taco | Taco_33869_I | You are given a list of integers. Your task is to determine which integers from the list are prime numbers. A prime number is defined as a number that has exactly two distinct positive divisors: 1 and itself.
Write a function to return a list of booleans where each element corresponds to whether the integer at that p... | def is_prime(n):
"""
Returns True if n is a prime number, else False
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i ... | from solution import is_prime_list
def test_is_prime_list_sample():
integers = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
result = [False, True, False, True, False, False, False, True, False, True]
assert is_prime_list(integers) == result
def test_is_prime_list_single_prime():
integers = [2]
result ... | [
{
"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 booleans indicating the primality of each integer in the input list.",
"function_declara... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033869",
"row_id": 33869,
"seed_ids": "[21495]"
} | 0.719634 | Taco_33869 | I | [
"is_prime",
"is_prime_list"
] | 2 | [
[
"is_prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 32d615fcd63cd1897496b3b5f5a21400a29815a1 | 0b5f8f11683a9956050938212bccef1343828f5d | |||
v1.0 | instruct | Taco | Taco_33880_I | Alice is working on analyzing chemical compositions found in various substances. To help with her research, she needs a program that can determine if two given chemical formulas correspond to the same composition, even if the formulas are written differently. For simplicity, these chemical formulas can be seen as strin... | from collections import defaultdict
import re
def parse_formula(formula):
"""
Parse the chemical formula into a dictionary of elements and their quantities.
"""
elements = defaultdict(int)
for elem, qty in re.findall(r'([A-Z][a-z]*)(\d*)', formula):
qty = int(qty) if qty else 1
elem... | import pytest
from solution import process_input
def test_formula_parsing():
assert process_input(["3", "H2O", "O1H2", "CH4", "C2H2", "H", "HH", "2", "O2", "O2", "N2", "N2O", "0"]) == ["yes", "no", "no", "yes", "no"]
def test_single_element():
assert process_input(["1", "H", "H2", "0"]) == ["no"]
assert p... | [
{
"docstring": "Parse the chemical formula into a dictionary of elements and their quantities.",
"function_declaration": "def parse_formula(formula):",
"function_name": "parse_formula",
"parameter_list": "(formula)"
},
{
"docstring": "Check if the two formulas have the same composition.",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n \"\"\"\n Parse a chemical formula into a dictionary of element counts.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033880",
"row_id": 33880,
"seed_ids": "[20732]"
} | 0.665299 | Taco_33880 | I | [
"parse_formula",
"is_same_composition",
"check_formula_pairs",
"process_input"
] | 4 | [
[
"check_formula_pairs",
"is_same_composition"
],
[
"is_same_composition",
"parse_formula"
],
[
"process_input",
"check_formula_pairs"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | b790499e423cb9d4c7966bd4e4d28ba8df3546b9 | f8a9f6ba64a65e714fcd9c3d44141889bae3e48d | |||
v1.0 | instruct | Taco | Taco_33915_I | A robot is placed in a 2D grid where certain cells are blocked, and it needs to find the shortest path from its starting position to a target position. The robot can move up, down, left, or right, but cannot move into any of the blocked cells.
-----Input-----
The input data consists of multiple lines. The first line ... | from collections import deque
def shortest_path(grid, start, end):
rows, cols = len(grid), len(grid[0])
sx, sy = start
ex, ey = end
# Directions for moving in the grid
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
# Helper function to check if a position is within bounds and open
... | from solution import solve
def test_case_1():
input_data = "5 6\n..#...\n....#.\n#..#..\n....#.\n..#...\n0 0 4 4\n"
assert solve(input_data) == 8
def test_case_2():
input_data = "3 3\n...\n.#.\n...\n0 0 2 2\n"
assert solve(input_data) == 4
def test_case_3():
input_data = "4 4\n....\n....\n....\n#... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, start, end):",
"function_name": "shortest_path",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def solve(lines):",
"function_name": "solve",
"parameter_list": "(lines)"... | [
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 shortest_path(grid, start, end):\n rows, cols = len(grid), len(grid[0])\n sx, sy = start\n ex, ey = end\n \n # ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033915",
"row_id": 33915,
"seed_ids": "[13427]"
} | 0.743116 | Taco_33915 | I | [
"shortest_path",
"solve",
"main"
] | 3 | [
[
"solve",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2be4631a55af52f75eda3b8089cee841bb7787a9 | 97dcfbbcf076543b9889ae122261af4254230250 | |||
v1.0 | instruct | Taco | Taco_33916_I | You have been given a square matrix `M` of size `NxN` containing integers. Your task is to rotate the matrix 90 degrees clockwise and output the new rotated matrix.
-----Input:-----
- The first line contains an integer $T$, the number of test cases.
- For each test case:
- The first line contains an integer $N$, the... | def rotate_matrix(matrix):
"""
Rotates the given NxN matrix 90 degrees clockwise.
:param matrix: List[List[int]] - NxN matrix to be rotated
:return: List[List[int]] - The rotated matrix
"""
N = len(matrix)
rotated = [[0] * N for _ in range(N)]
for i in range(N):
for j in ran... | import pytest
from solution import rotate_matrix, process_input_and_rotate_matrices, parse_input, format_output
def test_rotate_matrix_2x2():
matrix = [
[1, 2],
[3, 4]
]
rotated = rotate_matrix(matrix)
expected = [
[3, 1],
[4, 2]
]
assert rotated == expected
de... | [
{
"docstring": "Rotates the given NxN matrix 90 degrees clockwise.\n\n:param matrix: List[List[int]] - NxN matrix to be rotated\n:return: List[List[int]] - The rotated matrix",
"function_declaration": "def rotate_matrix(matrix):",
"function_name": "rotate_matrix",
"parameter_list": "(matrix)"
},
... | [
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 rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates the given square matrix 90 degrees clockwise.\n \"\"\"\n N = len(matrix)\n rotated = [[0]... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033916",
"row_id": 33916,
"seed_ids": "[10423]"
} | 0.671416 | Taco_33916 | I | [
"rotate_matrix",
"process_input_and_rotate_matrices",
"parse_input",
"format_output"
] | 4 | [
[
"process_input_and_rotate_matrices",
"rotate_matrix"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | beca4f9b034882484b892eab416ea7e4bbc144d5 | 87d321a0774cabe7e767fd01f1f3496891c9196d | |||
v1.0 | instruct | Taco | Taco_33924_I | Problem Statement
You are given an undirected graph represented as an adjacency list. Each node of the graph represents a city, and each edge represents a road connecting two cities. The length of each road is given. Your task is to determine the shortest path from a given starting city to all other cities and return ... | import heapq
def dijkstra(n, edges, start):
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
distances = {i: float('inf') for i in range(1, n+1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue... | import pytest
from solution import sum_of_shortest_paths
def test_sample_input_1():
n = 4
m = 4
edges = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 1),
(3, 4, 5)
]
start = 1
assert sum_of_shortest_paths(n, m, edges, start) == 12
def test_sample_input_2():
n = 3
m = 3... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def sum_of_shortest_paths(n, m, edges, start):",
"function_name": "sum_of_shortest_paths"... | [
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": "import heapq\n\ndef dijkstra(n, m, edges, start):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph[u].append((v, w))\n grap... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00033924",
"row_id": 33924,
"seed_ids": "[7148]"
} | 0.799087 | Taco_33924 | I | [
"dijkstra",
"sum_of_shortest_paths"
] | 2 | [
[
"sum_of_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4867a52dcda72c7970e2fb86cc9ae1e6dac67b31 | f370add377f72167caba9cecf913c5df698cbf1a | |||
v1.0 | instruct | Taco | Taco_33927_I | Bella is organizing a unique tournament where she uses trees. A tree is a connected acyclic graph. She labels each node starting from 1 to n. The tournament is constituted in such a way that two players play against each other if there is a direct path between the nodes they are on. Each game results in a score that de... | def node_strengths(n, edges, queries):
from collections import defaultdict
def build_degree_map(n, edges):
degree_map = defaultdict(int)
for u, v in edges:
degree_map[u] += 1
degree_map[v] += 1
return degree_map
degree_map = build_degree_map(n, edges... | from solution import process_tournament
def test_example1():
n = 5
edge_list = [(1, 2), (1, 3), (2, 4), (3, 5)]
q = 3
game_list = [(1, 2), (4, 5), (3, 5)]
expected_output = [(2, 2), (1, 1), (2, 1)]
assert process_tournament(n, edge_list, q, game_list) == expected_output
def test_example2():
... | [
{
"docstring": null,
"function_declaration": "def node_strengths(n, edges, queries):",
"function_name": "node_strengths",
"parameter_list": "(n, edges, queries)"
},
{
"docstring": null,
"function_declaration": "def process_tournament(n, edge_list, q, game_list):",
"function_name": "p... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tree_strengths(n, edges, q, games):\n from collections import defaultdict\n\n # Create a defaultdict to compute the degree of each node\n degree = def... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00033927",
"row_id": 33927,
"seed_ids": "[14420]"
} | 0.6845 | Taco_33927 | I | [
"node_strengths",
"process_tournament"
] | 2 | [
[
"process_tournament",
"node_strengths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06ce26eeaffa0b58d047ad5064d641ab0eee192c | 31af0d72b2f51f336884dec24e91ca97f0437192 | |||
v1.0 | instruct | Taco | Taco_33935_I | "Sherlock Holmes, the famous detective, received an urgent request for help: someone stole jewelry from a hotel but left a peculiar note! The note simply had a series of numbers. After some careful thinking, Holmes figured out that the numbers might represent the weight of connected components in a directed graph. Now,... | import heapq
def dijkstra(n, adj, start):
dist = [float('inf')] * (n + 1)
dist[start] = 0
heap = [(0, start)]
while heap:
current_dist, u = heapq.heappop(heap)
if current_dist > dist[u]:
continue
for neighbor, weight in adj[u]:
distance = current_dist + w... | from solution import find_shortest_paths
def test_single_path():
edges = [
(1, 2, 1)
]
queries = [
(1, 2),
(2, 1)
]
assert find_shortest_paths(2, edges, queries) == [1, -1]
def test_multiple_paths():
edges = [
(1, 2, 1),
(2, 3, 1),
(1, 3, 4)
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, adj, start):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, start)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_paths(n, edges, queries):",
"function_name": "find_shortest_paths",
"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": "import sys\nimport heapq\n\ndef dijkstra(graph, n, start):\n distances = [sys.maxsize] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033935",
"row_id": 33935,
"seed_ids": "[15164]"
} | 0.731042 | Taco_33935 | I | [
"dijkstra",
"find_shortest_paths"
] | 2 | [
[
"find_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9c39a7e2fd311162d12ad13c3ad7fd2be4eaafb | c72c763fa42160442018746fbf97eb29373e19a9 | |||
v1.0 | instruct | Taco | Taco_34075_I | You are given a list of numbers. For each number in the list, if it is a prime number, print it along with its position in the list. If the number is not prime, skip it.
Prime number is defined as an integer greater than 1 that has no positive divisors other than 1 and itself.
Constraints:
* Each number \( n \) in th... | def is_prime(n):
"""
Determine if n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
retur... | from solution import is_prime, find_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(23) == True
assert is_prime(50) == False
assert is_prime(31) == True
... | [
{
"docstring": "Determine if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Print the position and value of each prime number in the list.",
"function_declaration": "def find_primes(numbers):",
... | [
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 a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034075",
"row_id": 34075,
"seed_ids": "[19241]"
} | 0.672538 | Taco_34075 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f0d77a82e64a90e6f79db9581930cf354800b8d | 41dacb1d2cd3cfcc42c7a9fea56b4f124d2e56bb | |||
v1.0 | instruct | Taco | Taco_34163_I | # Task
Euler's Totient Function, φ(n), is an important function in number theory. It counts the number of positive integers up to n that are relatively prime to n. Two numbers are relatively prime if their greatest common divisor (gcd) is 1. Your task is to compute φ(n) for a given n.
# Input/Output
- `[input]` integ... | def gcd(a, b):
"""
Compute the Greatest Common Divisor of a and b.
"""
while b:
a, b = b, a % b
return a
def euler_totient(n):
"""
Compute Euler's Totient Function φ(n).
"""
if n == 1:
return 1
count = 0
for i in range(1, n + 1):
if gcd(n, i) == 1:
... | from solution import euler_totient
def test_euler_totient_basic():
assert euler_totient(1) == 1
assert euler_totient(2) == 1
assert euler_totient(3) == 2
assert euler_totient(4) == 2
assert euler_totient(5) == 4
def test_euler_totient_larger_numbers():
assert euler_totient(10) == 4
assert ... | [
{
"docstring": "Compute the Greatest Common Divisor of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Compute Euler's Totient Function φ(n).",
"function_declaration": "def euler_totient(n):",
"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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef euler_totient(n):\n count = 0\n for i in range(1, n + 1):\n if gcd(i, n) ==... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034163",
"row_id": 34163,
"seed_ids": "[6778]"
} | 0.524716 | Taco_34163 | I | [
"gcd",
"euler_totient"
] | 2 | [
[
"euler_totient",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5e2c6c5c4490d91a1c4006bcd44ac9de2c75dc14 | e4e9f88ff69b2a1b66b116fd4f55ef12344b7d01 | |||
v1.0 | instruct | Taco | Taco_34167_I | A logistics company is planning to optimize its delivery routes using a new software system. They have several delivery locations represented as nodes and the routes between them as edges in a graph. Each route between two locations has a specific travel time. The company needs to find the shortest time required to tra... | import heapq
def dijkstra(graph, start, end, n):
"""
Find the shortest path using Dijkstra's algorithm.
"""
distances = {i: float('infinity') for i in range(1, n+1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.... | def test_example():
input_string = "2\n5 6 1 5\n1 2 10\n1 3 5\n2 3 2\n3 4 2\n4 5 3\n3 5 20\n3 3 1 3\n1 2 5\n2 3 10\n1 3 15\n"
expected_output = [10, 15]
assert minimum_travel_times(input_string) == expected_output
def test_no_path():
input_string = "1\n3 2 1 3\n1 2 5\n2 3 10\n"
expected_output = [1... | [
{
"docstring": "Find the shortest path using Dijkstra's algorithm.",
"function_declaration": "def dijkstra(graph, start, end, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end, n)"
},
{
"docstring": null,
"function_declaration": "def find_min_travel_times(test_case... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, edges, start, end):\n graph = {i: [] for i in range(1, n + 1)}\n for u, v, w in edges:\n graph[u].append((v, w))\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034167",
"row_id": 34167,
"seed_ids": "[21081]"
} | 0.783124 | Taco_34167 | I | [
"dijkstra",
"find_min_travel_times",
"parse_input",
"minimum_travel_times"
] | 4 | [
[
"find_min_travel_times",
"dijkstra"
],
[
"minimum_travel_times",
"find_min_travel_times"
],
[
"minimum_travel_times",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 0b5c8aafeb9b226fc674fdd29db095b912fb1668 | afba3c7d3ec6ecc749be6ba3c1bf0a38751869d2 | |||
v1.0 | instruct | Taco | Taco_34203_I | Monocarp is organizing a small coding contest. He wants to design a custom sequence of integers that has special properties. Monocarp defines a "magic sequence" as a sequence of integers where for a given sequence length $k$, the sequence contains integers from $1$ to $k$ (inclusive) such that each integer appears exac... | def is_prime(n):
"""Helper function to check if the number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-3)
assert is_prime(17)
def test_can_form_magic_sequence():
assert can_form_magic_sequence(1) == [1]
assert can_... | [
{
"docstring": "Helper function to check if the number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a possible magic sequence of length k or -1 if not possible.",
"function_declaration": "def can_f... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\nimport sympy\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n return sympy.isprime(n)\n\ndef find_magic_se... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00034203",
"row_id": 34203,
"seed_ids": "[20997]"
} | 0.613886 | Taco_34203 | I | [
"is_prime",
"can_form_magic_sequence",
"magic_sequence"
] | 3 | [
[
"magic_sequence",
"can_form_magic_sequence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bb781d81ff85659f2b3710f4ea6caa480777bb9c | 1699ab1edff395a92900d196c97218607b596e9f | |||
v1.0 | instruct | Taco | Taco_34274_I | In the fictional city of Codeville, there is a unique traffic system organized in a grid layout. The city is divided into an n x m grid of intersections. Each intersection is represented by its coordinates (x, y) where 1 <= x <= n and 1 <= y <= m. Some intersections have traffic lights, while others do not.
Traffic li... | def max_distance_to_traffic_light(n, m, k, lights):
max_distance = 0
for x in range(1, n+1):
for y in range(1, m+1):
if (x, y) not in lights:
min_distance = float('inf')
for (lx, ly) in lights:
min_distance = min(min_distance, abs(x - ... | from solution import traffic_lights_max_distance
def test_traffic_lights_max_distance_basic():
input_str = '4 4 3\n1 2\n3 4\n4 1\n'
assert traffic_lights_max_distance(input_str) == 2
def test_traffic_lights_max_distance_single_traffic_light():
input_str = '3 3 1\n2 2\n'
assert traffic_lights_max_dista... | [
{
"docstring": null,
"function_declaration": "def max_distance_to_traffic_light(n, m, k, lights):",
"function_name": "max_distance_to_traffic_light",
"parameter_list": "(n, m, k, lights)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": ... | [
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 max_distance(n, m, k, traffic_lights):\n max_dist = 0\n\n # Iterate through each intersection in the grid\n for x in range(1, n+1):\n for y in ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00034274",
"row_id": 34274,
"seed_ids": "[12885]"
} | 0.662038 | Taco_34274 | I | [
"max_distance_to_traffic_light",
"parse_input",
"traffic_lights_max_distance"
] | 3 | [
[
"traffic_lights_max_distance",
"max_distance_to_traffic_light"
],
[
"traffic_lights_max_distance",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3daf6c4587b430e34ffecf68c99dadc1b343ea9e | 009777de77601a55ddc2dfcfd3d8c156994143b7 | |||
v1.0 | instruct | Taco | Taco_34329_I | Write a function that receives a string and a list of words, and returns the count of how many words from the list are found as a subsequence in the string.
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the... | def is_subsequence(s, word):
"""
Helper function to check if word is a subsequence of s.
"""
it = iter(s)
return all(char in it for char in word)
def count_subsequences(s, words):
"""
Returns the count of how many words from the list are found as subsequences in the string.
"""
coun... | from solution import count_subsequences
def test_subsequences_in_abc():
assert count_subsequences("abc", ["a", "b", "c", "d", "ac"]) == 4
def test_subsequences_in_abc_ab_bc_abc():
assert count_subsequences("abc", ["ab", "bc", "abc", "cab"]) == 3
def test_subsequences_in_empty_string():
assert count_subse... | [
{
"docstring": "Helper function to check if word is a subsequence of s.",
"function_declaration": "def is_subsequence(s, word):",
"function_name": "is_subsequence",
"parameter_list": "(s, word)"
},
{
"docstring": "Returns the count of how many words from the list are found as subsequences in... | [
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 count_subsequences(s, words):\n \"\"\"\n Counts how many words from the list are found as a subsequence in the string s.\n \n Parameters:\n s (s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034329",
"row_id": 34329,
"seed_ids": "[2943]"
} | 0.743416 | Taco_34329 | I | [
"is_subsequence",
"count_subsequences"
] | 2 | [
[
"count_subsequences",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d4526ce58ac655f8b5f074fd7ca7cfd8dd13f1f | 87fad80af14ee38d9e8693623724ea3c41dff499 | |||
v1.0 | instruct | Taco | Taco_34404_I | Alice is organizing a new reading corner for her friends. She has a list of books, each with a specific number of pages. Alice wants to distribute the books among her friends such that the time it takes for the friend reading the most pages is minimized.
Given a list of integers representing the number of pages of eac... | def is_possible(books, n, max_pages):
current_sum = 0
required_friends = 1
for pages in books:
if current_sum + pages > max_pages:
required_friends += 1
current_sum = pages
if required_friends > n:
return False
else:
current_sum... | from solution import minimize_max_pages
def test_minimize_max_pages_example1():
assert minimize_max_pages(2, [10, 20, 30, 40]) == 60
def test_minimize_max_pages_example2():
assert minimize_max_pages(3, [10, 20, 30, 40]) == 40
def test_minimize_max_pages_single_friend():
assert minimize_max_pages(1, [10, ... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, max_pages)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_pages(n, books):",
"function_name": "minimize_max_pages",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_max_pages(n, books):\n def can_distribute(books, n, max_pages):\n current_sum, num_friends = 0, 1\n for pages in books:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00034404",
"row_id": 34404,
"seed_ids": "[19576]"
} | 0.735317 | Taco_34404 | I | [
"is_possible",
"minimize_max_pages"
] | 2 | [
[
"minimize_max_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c1ec1cd9677ace2d03970b56036e4c51737e585 | 1af8cd363f6e4fb2967501fe7c37ea7a6f64a010 | |||
v1.0 | instruct | Taco | Taco_34428_I | You are given an array of $N$ integers, followed by $Q$ queries. Each query provides two integers, $L$ and $R$. Find the sum of the elements in the array between indices $L$ and $R$ (inclusive), for each query.
-----Input-----
- The first line of the input contains a single integer $N$ indicating the number of element... | def prefix_sums(arr):
"""
Returns an array of prefix sums
"""
prefix = [0] * (len(arr) + 1)
for i in range(1, len(prefix)):
prefix[i] = prefix[i-1] + arr[i-1]
return prefix
def range_sum_queries(arr, queries):
"""
Returns the sum of the elements in the array between indices L an... | from solution import range_sum_queries
def test_single_query():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3)]
assert range_sum_queries(arr, queries) == [6]
def test_multiple_queries():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 4), (1, 5)]
assert range_sum_queries(arr, queries) == [6, 9, 15]
def... | [
{
"docstring": "Returns an array of prefix sums",
"function_declaration": "def prefix_sums(arr):",
"function_name": "prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the elements in the array between indices L and R (inclusive) for each query.\nUtilizes prefix su... | [
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 array_query_sum(N, array, queries):\n \"\"\"\n Computes the sum of elements between indices L and R for each query.\n \n Parameters:\n N (int): ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034428",
"row_id": 34428,
"seed_ids": "[11428]"
} | 0.687671 | Taco_34428 | I | [
"prefix_sums",
"range_sum_queries"
] | 2 | [
[
"range_sum_queries",
"prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0536e00f536e081af2d9f704d356bb255fc03270 | b9ba3e97d66433543fbe0c1a5cfdbf5b16fd4a1f | |||
v1.0 | instruct | Taco | Taco_34498_I | Create a function that takes an array of integers and returns a new array containing only the elements that are prime numbers. A prime number is defined as a whole number greater than 1 that has no positive divisors other than 1 and itself. The order of the elements in the output array should match the order of their f... | import math
def is_prime(n):
"""
Helper function to determine if n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
retur... | from solution import is_prime, filter_primes
def test_is_prime():
# test non-prime numbers
assert is_prime(1) == False
assert is_prime(4) == False
assert is_prime(9) == False
assert is_prime(15) == False
# test prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
ass... | [
{
"docstring": "Helper function to determine if n 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": "def ... | [
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 == 2:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034498",
"row_id": 34498,
"seed_ids": "[8061]"
} | 0.700739 | Taco_34498 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | df3c935703e41d924226c8ebc261396b9bec082e | 072bfd1e075607fa6e831010dd8d429d27bf1889 | |||
v1.0 | instruct | Taco | Taco_34543_I | A large food distribution company wants to optimize its delivery routes across multiple cities. You are tasked to implement a program that helps in computing the shortest possible route to deliver food to all cities in a given list and return to the original city. This problem is often referred to as the "Travelling Sa... | import math
from itertools import permutations
def distance(city1, city2):
"""
Calculate Euclidean distance between two cities.
"""
return math.sqrt((city2[0] - city1[0])**2 + (city2[1] - city1[1])**2)
def travelling_salesman(cities):
"""
Calculates the shortest possible route to visit all cit... | from solution import solve_tsp_problems
def test_case_1():
input_data = "4\n0 0\n0 1\n1 0\n1 1\n"
output = solve_tsp_problems(input_data)
assert output == ["4.000000"]
def test_case_2():
input_data = "3\n0 0\n2 0\n4 0\n"
output = solve_tsp_problems(input_data)
assert output == ["8.000000"]
de... | [
{
"docstring": "Calculate Euclidean distance between two cities.",
"function_declaration": "def distance(city1, city2):",
"function_name": "distance",
"parameter_list": "(city1, city2)"
},
{
"docstring": "Calculates the shortest possible route to visit all cities and return to the starting c... | [
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 itertools import permutations\nimport math\n\ndef calculate_distance(city1, city2):\n \"\"\"\n Calculates and returns the Euclidean distance between two... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00034543",
"row_id": 34543,
"seed_ids": "[2512]"
} | 0.740175 | Taco_34543 | I | [
"distance",
"travelling_salesman",
"solve_tsp_problems"
] | 3 | [
[
"solve_tsp_problems",
"travelling_salesman"
],
[
"travelling_salesman",
"distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a951d04b2acf2f096ba383fdf140a9b10f4651d7 | 7be4f75cbbb097f19dfefa71d6bea273a6b46a79 | |||
v1.0 | instruct | Taco | Taco_34585_I | In a distant galaxy, there exists a special binary tree called "Magic-Tree". Each node in the Magic-Tree has a non-negative integer value associated with it. The special property of the Magic-Tree is that every path from the root to any leaf node has the same sum of values. Your task is to determine whether a given bin... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
if not nodes:
return None
tree_nodes = {i: TreeNode(value) for i, (value, _, _) in enumerate(nodes)}
for i, (value, left, right) in enumerate(nodes):
... | import pytest
from solution import is_magic_tree_multiple_cases
def test_single_case_no_root():
assert is_magic_tree_multiple_cases([(0, [])]) == ["YES"]
def test_single_case_single_node():
assert is_magic_tree_multiple_cases([(1, [(5, -1, -1)])]) == ["YES"]
def test_single_case_magic_tree():
nodes = [
... | [] | [
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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef b... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00034585",
"row_id": 34585,
"seed_ids": "[14609]"
} | 0.580779 | Taco_34585 | I | [
"build_tree",
"is_magic_tree",
"is_magic_tree_multiple_cases"
] | 3 | [
[
"is_magic_tree_multiple_cases",
"build_tree"
],
[
"is_magic_tree_multiple_cases",
"is_magic_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 18918c75a4c8b79bfc14de6d1fd6e3f29b898532 | 1dd9a7ab4a366a7dbf4df5f4f3c72c22845a46c5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.