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_87350_I | Write a function that accepts a string of digits and generates all possible valid IP address combinations that can be formed by inserting three dots into the string. An IP address consists of four integer numbers between 0 and 255, separated by dots (e.g., '192.168.0.1'). Do not use leading zeros unless the segment is ... | from typing import List
def is_valid(segment: str) -> bool:
"""
Check if the segment is a valid IP address segment.
An IP address segment is valid if:
- It is not empty.
- It does not have leading zeros unless it is "0".
- It is a number between 0 and 255.
"""
return len(segment) > 0 an... | from solution import generate_ip_addresses
def test_generate_ip_addresses():
assert generate_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"]
assert generate_ip_addresses("0000") == ["0.0.0.0"]
assert generate_ip_addresses("1111") == ["1.1.1.1"]
assert generate_ip_addresses("010010")... | [
{
"docstring": "Check if the segment is a valid IP address segment.\nAn IP address segment is valid if:\n- It is not empty.\n- It does not have leading zeros unless it is \"0\".\n- It is a number between 0 and 255.",
"function_declaration": "def is_valid(segment):",
"function_name": "is_valid",
"par... | [
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 typing import List\n\ndef generate_ip_addresses(s: str) -> List[str]:\n def is_valid(segment: str) -> bool:\n \"\"\"\n Check if a segment of ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00087350",
"row_id": 87350,
"seed_ids": "[6989]"
} | 0.578262 | Taco_87350 | I | [
"is_valid",
"generate_ip_addresses"
] | 2 | [
[
"generate_ip_addresses",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8ad59ad050781bdba0b22e8fa0a03a58351765bf | f2b653a08ce9ab6ed47ee5025b4931407983d4cd | |||
v1.0 | instruct | Taco | Taco_87351_I | Alex is fascinated by prime numbers. For his latest project, he wants to generate a matrix of positive integers where the sum of elements in each row, column, and both main diagonals are all prime numbers. Given an integer $m$, help Alex determine if it is possible to create such an $m \times m$ matrix that meets these... | import sympy
def is_prime(n):
"""
Returns True if the given number n is prime, else False.
"""
return sympy.isprime(n)
def find_prime_greater_than(n):
"""
Returns the smallest prime number greater than n.
"""
prime = n + 1
while not is_prime(prime):
prime += 1
return pr... | from solution import prime_matrix
def test_prime_small_size_3():
result = prime_matrix(3).split("\n")
assert result[0] == "YES"
assert all(len(row.split()) == 3 for row in result[1:])
def test_prime_size_2():
assert prime_matrix(2) == "NO"
def test_prime_size_5():
result = prime_matrix(5)... | [
{
"docstring": "Returns True if the given number n is prime, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the smallest prime number greater than n.",
"function_declaration": "def find_prime_great... | [
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(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00087351",
"row_id": 87351,
"seed_ids": "[13302]"
} | 0.601321 | Taco_87351 | I | [
"is_prime",
"find_prime_greater_than",
"create_matrix",
"prime_matrix"
] | 4 | [
[
"create_matrix",
"find_prime_greater_than"
],
[
"find_prime_greater_than",
"is_prime"
],
[
"prime_matrix",
"create_matrix"
]
] | 3 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | 5d03882915826539f15daf89d9ba32550f4c909f | 04281fc15a77ee58137da30650ca5ffd62c56c71 | |||
v1.0 | instruct | Taco | Taco_87362_I | John has found a mysterious grid of characters. Each cell in the grid contains a lowercase English letter. John is fascinated with finding words in this grid by starting at any cell and moving in any of the 8 possible directions (left, right, up, down, and the four diagonals). He now seeks your help to determine if a s... | def search_word_in_grid(grid, word):
R = len(grid)
C = len(grid[0])
word_len = len(word)
# Directions: right, left, down, up, diagonals
directions = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
def is_valid(x, y):
return 0 <= x < R and 0 <= y < C
... | from solution import search_word_in_grid
def test_sample_input():
grid = [
['a', 'b', 'c', 'f'],
['b', 'd', 'e', 'f'],
['d', 'h', 'a', 'g'],
['e', 'h', 'k', 'f']
]
word = "beak"
assert search_word_in_grid(grid, word) == "YES"
def test_word_not_present():
grid = [
... | [
{
"docstring": null,
"function_declaration": "def search_word_in_grid(grid, word):",
"function_name": "search_word_in_grid",
"parameter_list": "(grid, word)"
},
{
"docstring": null,
"function_declaration": "def word_search_in_grid():",
"function_name": "word_search_in_grid",
"par... | [
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 find_word(grid, word):\n R, C = len(grid), len(grid[0])\n word_len = len(word)\n \n def is_valid(x, y):\n return 0 <= x < R and 0 <= y < C\n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00087362",
"row_id": 87362,
"seed_ids": "[10121]"
} | 0.742279 | Taco_87362 | I | [
"search_word_in_grid",
"word_search_in_grid"
] | 2 | [
[
"word_search_in_grid",
"search_word_in_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b048d3589a49d56a8d21210a5774a93aced02e1 | 803f9a077bff70e03b1f71c5a27c7a3e5cfc9dbd | |||
v1.0 | instruct | Taco | Taco_87364_I | In the mystical realm of Atlantis, there exists an ancient legend about a hidden treasure buried deep within the city. To find this treasure, one must solve a challenging problem involving arrays and ranges. The High Council of Atlantis has tasked you with solving this problem.
Given an array A consisting of N integer... | def get_prefix_sums(arr):
"""
This function returns the prefix sums of the input array.
"""
prefix_sums = [0] * (len(arr) + 1)
for i in range(1, len(prefix_sums)):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
return prefix_sums
def query_sums(prefix_sums, l, r):
"""
This fun... | def test_get_prefix_sums():
arr = [1, 2, 3, 4, 5]
expected = [0, 1, 3, 6, 10, 15]
assert get_prefix_sums(arr) == expected
def test_query_sums():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert query_sums(prefix_sums, 1, 3) == 6
assert query_sums(prefix_sums, 2, 4) == 9
assert query_sums(prefix_su... | [
{
"docstring": "This function returns the prefix sums of the input array.",
"function_declaration": "def get_prefix_sums(arr):",
"function_name": "get_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "This function returns the sum of the subarray from index l to r (inclusive)\nusing... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_sum_array(A):\n \"\"\"Preprocess the array to create a prefix sum array.\"\"\"\n prefix_sum = [0] * (len(A) + 1)\n for i in range(1, len(A)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087364",
"row_id": 87364,
"seed_ids": "[16728]"
} | 0.665275 | Taco_87364 | I | [
"get_prefix_sums",
"query_sums",
"find_subarray_sums"
] | 3 | [
[
"find_subarray_sums",
"get_prefix_sums"
],
[
"find_subarray_sums",
"query_sums"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1e7e087d83bc2253ea70674d78e5f5535faab905 | 5620645d22fd57483ba9c4f52081853252d97e9b | |||
v1.0 | instruct | Taco | Taco_87448_I | Dungeon Explorer is an adventurous game where a player needs to navigate through a dungeon to reach the exit. The dungeon is represented as an N x N grid, containing areas that are either walls or open spaces. The player starts at the top-left corner (1, 1) and needs to reach the bottom-right corner (N, N).
One day, t... | import sys
from collections import deque
def can_reach_exit(dungeon, N):
"""
Check if the player can reach the exit in the dungeon starting from (0, 0).
"""
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
start = (0, 0)
exit_pos = (N - 1, N - 1)
if dungeon[start[0]][start[1]] == '#' or... | from solution import dungeon_explorer
def test_example_case_1():
input_data = """4
.M#M
.#M.
M..M
###.
2
1 2
2 3
0"""
expected_output = ["YES", "YES"]
assert dungeon_explorer(input_data) == expected_output
def test_example_case_2():
input_data = """5
#####
#M###
##.##
###M#
####.
1
2 2
0"""
expect... | [
{
"docstring": "Check if the player can reach the exit in the dungeon starting from (0, 0).",
"function_declaration": "def can_reach_exit(dungeon, N):",
"function_name": "can_reach_exit",
"parameter_list": "(dungeon, N)"
},
{
"docstring": "Update the state of the magic wall at (x, y) if the ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import deque\n\ndef can_reach_exit(dungeon, N):\n \"\"\"\n Check if the player can reach the exit in the dungeon starting from (... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00087448",
"row_id": 87448,
"seed_ids": "[3810]"
} | 0.703847 | Taco_87448 | I | [
"can_reach_exit",
"update_magic_wall",
"process_dungeon",
"dungeon_explorer"
] | 4 | [
[
"dungeon_explorer",
"process_dungeon"
],
[
"process_dungeon",
"can_reach_exit"
],
[
"process_dungeon",
"update_magic_wall"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fc6c5587809f11a7120b62c21608dab1e9bf2b1f | 185d188b130fda6f59dd73986ece192054cd1e95 | |||
v1.0 | instruct | Taco | Taco_87486_I | A common problem faced by urban planners is the distribution of shelters in a city prone to sudden natural disasters. In the city, there are n shelters and m connecting roads between them. Each shelter can only store a limited number of supplies. A major challenge is ensuring that after a disaster, supplies can still b... | 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 check_supplies_network
def test_valid_network():
assert check_supplies_network(4, 3, [(1, 2), (2, 3), (3, 4)]) == "valid"
def test_invalid_network():
assert check_supplies_network(5, 5, [(1, 2), (1, 3), (2, 3), (3, 4), (4, 5)]) == "invalid"
def test_minimum_network():
assert check_su... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_network(n, m, roads):\n if m != n - 1:\n return \"invalid\"\n\n from collections import defaultdict, deque\n graph = defaultdict(list)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087486",
"row_id": 87486,
"seed_ids": "[12429]"
} | 0.711101 | Taco_87486 | I | [
"find",
"union",
"is_valid_network",
"check_supplies_network"
] | 4 | [
[
"check_supplies_network",
"is_valid_network"
],
[
"is_valid_network",
"find"
],
[
"is_valid_network",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 7f4c5da4560580f9d1ac0c2fb51529e8dd44af12 | bd762974b22a347de5d572552f8da5a71684f8b8 | |||
v1.0 | instruct | Taco | Taco_87530_I | The question is to determine if it is possible to organize a set of pairs such that all members can "see" each other. Here is the new question:
Input
4 2 1 4 3 2
1 4
2 3
Output
POSSIBLE | def is_bipartite(n, edges):
from collections import deque, defaultdict
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
color = [-1] * (n + 1)
def bfs(start):
queue = deque([start])
color[start] = 0
while q... | from solution import possible_to_organize
def test_possible_to_organize_possible_case():
pairs = [(1, 4), (2, 3)]
assert possible_to_organize(pairs) == "POSSIBLE"
def test_possible_to_organize_impossible_case():
pairs = [(1, 2), (2, 3), (3, 1)]
assert possible_to_organize(pairs) == "IMPOSSIBLE"
def t... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, edges):",
"function_name": "is_bipartite",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def possible_to_organize(pairs):",
"function_name": "possible_to_organize",
"parameter_list... | [
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_possible(n, pairs):\n from collections import defaultdict, deque\n \n # Create adjacency list from input pairs\n graph = defaultdict(list)\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00087530",
"row_id": 87530,
"seed_ids": "[4634]"
} | 0.511887 | Taco_87530 | I | [
"is_bipartite",
"possible_to_organize"
] | 2 | [
[
"possible_to_organize",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ac8044a02b43bf3b47e7a1e86b3d8557451cf40 | 20bd0e3cf9378c5c0fa022c79558e5f2c933a0e3 | |||
v1.0 | instruct | Taco | Taco_87561_I | A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 (91 × 99). Write a function that takes an integer `n` and finds the largest palindrome made from the product of two numbers, each with `n` digits. If no such palindrome exists, return -1.
Examples... | def is_palindrome(number):
return str(number) == str(number)[::-1]
def largest_palindrome(n):
if n < 1:
return -1
max_factor = 10**n - 1
min_factor = 10**(n - 1)
largest_palindrome = -1
for i in range(max_factor, min_factor - 1, -1):
for j in range(i, min_factor - 1, -1):
... | from solution import largest_palindrome
def test_largest_palindrome_2_digits():
assert largest_palindrome(2) == 9009
def test_largest_palindrome_3_digits():
assert largest_palindrome(3) == 906609
def test_largest_palindrome_1_digit():
assert largest_palindrome(1) == 9
def test_largest_palindrome_negativ... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": null,
"function_declaration": "def largest_palindrome(n):",
"function_name": "largest_palindrome",
"parameter_list": "(n)"
... | [
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 largest_palindrome(n):\n if n < 1:\n return -1\n\n max_num = 10**n - 1\n min_num = 10**(n-1)\n max_palindrome = -1\n\n for i in range(max... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00087561",
"row_id": 87561,
"seed_ids": "[2861]"
} | 0.775262 | Taco_87561 | I | [
"is_palindrome",
"largest_palindrome"
] | 2 | [
[
"largest_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 091abb4800083943da2e5fd7b2c673e165c46ff9 | 6377216deb5b2de55274a4049ac0894a7dd3c28f | |||
v1.0 | instruct | Taco | Taco_87617_I | You are given an array of strings representing mathematical expressions. Each expression will contain two numbers and an operator (+, -, *, or /). Your task is to evaluate these expressions and return the one that yields the highest result.
If the highest result is negative or zero, or if there are multiple expression... | def evaluate_expression(expression):
"""
Evaluates a single mathematical expression in string form.
Supports +, -, *, / operators.
"""
return eval(expression)
def find_highest_expression(expressions):
"""
Finds the mathematical expression from the list that yields the highest result.
If... | from solution import find_highest_expression
def test_find_highest_expression_basic():
expressions = ['3+4', '10-5', '6*2']
assert find_highest_expression(expressions) == '6*2'
def test_find_highest_expression_multiple_highest():
expressions = ['1+1', '2+2', '1+1']
assert find_highest_expression(expre... | [
{
"docstring": "Evaluates a single mathematical expression in string form.\nSupports +, -, *, / operators.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
},
{
"docstring": "Finds the mathematical expr... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evaluate_expression(expr):\n \"\"\"\n Evaluates a mathematical expression in string format.\n Supported operators: +, -, *, /\n \"\"\"\n try:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00087617",
"row_id": 87617,
"seed_ids": "[638]"
} | 0.569481 | Taco_87617 | I | [
"evaluate_expression",
"find_highest_expression"
] | 2 | [
[
"find_highest_expression",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 98124f9817c3bb0571db84c1e2ec4252eb20c4c2 | 041f76f693ff6ee9c223ff0512f91f910fe5cadd | |||
v1.0 | instruct | Taco | Taco_87625_I | Two robots, Alice and Bob, are placed on a two-dimensional grid. The grid has dimensions MxN. Alice and Bob can both move up, down, left, or right, but they can't move into cells occupied by obstacles. Alice and Bob start from their initial positions and try to reach their respective goal positions, coordinating their ... | from collections import deque
def is_valid_move(x, y, grid, M, N):
return 0 <= x < M and 0 <= y < N and grid[x][y] == '.'
def bfs(grid, M, N, start, goal):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(start[0], start[1], 0)])
visited = set((start[0], start[1]))
while queue:
... | def test_can_robots_reach_goals():
# Test case 1
M, N = 4, 4
Ax, Ay = 0, 0
Bx, By = 3, 3
Gx1, Gy1 = 3, 0
Gx2, Gy2 = 0, 3
grid = [
"..#.",
"..#.",
".#..",
"..#."
]
assert can_robots_reach_goals(M, N, Ax, Ay, Bx, By, Gx1, Gy1, Gx2, Gy2, grid) == "YES"
... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(x, y, grid, M, N):",
"function_name": "is_valid_move",
"parameter_list": "(x, y, grid, M, N)"
},
{
"docstring": null,
"function_declaration": "def bfs(grid, M, N, start, goal):",
"function_name": "bfs",
"parameter_li... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_valid(x, y, M, N, grid):\n return 0 <= x < M and 0 <= y < N and grid[x][y] == '.'\n\ndef bfs(start, goal, M, N, grid):\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00087625",
"row_id": 87625,
"seed_ids": "[13859]"
} | 0.759246 | Taco_87625 | I | [
"is_valid_move",
"bfs",
"can_robots_reach_goals",
"solve"
] | 4 | [
[
"bfs",
"is_valid_move"
],
[
"can_robots_reach_goals",
"bfs"
],
[
"solve",
"can_robots_reach_goals"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 45b20921fdb7ad4a60c1beecda9558381766b700 | 6255bd50e838aebad420ca7c8ae0d9e904c9486c | |||
v1.0 | instruct | Taco | Taco_87638_I | Miko is organizing a charity auction and has a list of items, each with a specified minimum price. Some bids have already been placed on the items, but Miko needs to determine if the current highest bid meets or exceeds the minimum price for each item.
Write a program that helps Miko by reading the list of items with ... | def auction_results(n, items):
"""
Determines if each item's highest bid meets or exceeds its minimum price.
:param n: number of items
:param items: list of tuples containing (name, minimum price, highest bid)
:return: list of "YES" or "NO" for each item
"""
results = []
for item in ite... | from solution import process_auction_input
def test_auction_results_example1():
n = 3
raw_items = [
"Painting 100 150",
"Vase 200 180",
"Sculpture 300 300"
]
assert process_auction_input(n, raw_items) == ["YES", "NO", "YES"]
def test_auction_results_example2():
n = 4
ra... | [
{
"docstring": "Determines if each item's highest bid meets or exceeds its minimum price.\n\n:param n: number of items\n:param items: list of tuples containing (name, minimum price, highest bid)\n:return: list of \"YES\" or \"NO\" for each item",
"function_declaration": "def auction_results(n, items):",
... | [
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 check_bids(n, items):\n results = []\n for item in items:\n name, price, bid = item\n if bid >= price:\n results.append(\"YES\")... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00087638",
"row_id": 87638,
"seed_ids": "[2787]"
} | 0.634229 | Taco_87638 | I | [
"auction_results",
"process_auction_input"
] | 2 | [
[
"process_auction_input",
"auction_results"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 03b100072d32607541be542a4961084298a64ae8 | fe54f4023f8828abc30074cc57cc15ff189b66e3 | |||
v1.0 | instruct | Taco | Taco_87644_I | Alex is fascinated by prime numbers and sequences. Every day, he writes down all the prime numbers in a list and tries to find interesting patterns in them. One day, he came across a challenge: He needs to determine the smallest prime number `p` such that `p + n` is also a prime number for a given integer `n`.
Your ta... | def is_prime(num):
"""
Determines if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import is_prime, smallest_prime_with_prime_sum
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(17) == True
def test_smallest_prime_with_prime_sum():
... | [
{
"docstring": "Determines if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number p such that p and p + n are both prime numbers.",
"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": "from sympy import isprime\n\ndef find_smallest_prime_pair(n):\n \"\"\"\n Finds the smallest prime number p such that both p and p + n are prime numbers.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00087644",
"row_id": 87644,
"seed_ids": "[10199]"
} | 0.657727 | Taco_87644 | I | [
"is_prime",
"smallest_prime_with_prime_sum"
] | 2 | [
[
"smallest_prime_with_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0929300c0df75ce65e8657fad00880e82530f139 | 39e2210079765b7fb64bf710a8dd878c5d228c79 | |||
v1.0 | instruct | Taco | Taco_87683_I | Write a function that checks if a given string can be rearranged to form a palindrome. A palindrome is a word that reads the same forwards and backwards.
For example, "level" and "radar" are palindromes. However, "hello" is not.
To check if the string can be rearranged to form a palindrome, we need to ensure that at ... | def can_form_palindrome(s):
"""
Checks if the input string can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each character in the string
char_count = Counter(s)
# A string can be rearranged to form a palindrome if at most one character has ... | from solution import can_form_palindrome, check_palindrome_possibility
def test_single_character():
assert can_form_palindrome("a") == "YES"
def test_even_length_palindrome():
assert can_form_palindrome("abccba") == "YES"
def test_odd_length_palindrome():
assert can_form_palindrome("abcba") == "YES"
def... | [
{
"docstring": "Checks if the input string can be rearranged to form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def check_palindrome_possibility(st... | [
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 Counter\n\ndef can_form_palindrome(s):\n \"\"\"\n Returns 'YES' if the string `s` can be rearranged to form a palindrome, otherwise '... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087683",
"row_id": 87683,
"seed_ids": "[268]"
} | 0.779422 | Taco_87683 | I | [
"can_form_palindrome",
"check_palindrome_possibility"
] | 2 | [
[
"check_palindrome_possibility",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f08d94f7552e1b09859a42da829aba9a283d3abe | 2fef5ecd3d61bab9739ac762fcafa042963ce1f5 | |||
v1.0 | instruct | Taco | Taco_87774_I | A number is called a happy number if repeatedly replacing it with the sum of the squares of its digits eventually leads to 1. If not, it will cycle through a sequence that does not include 1. Write a program to determine if a given positive integer is a happy number or not.
-----Constraints-----
- 1 \leq N \leq 10^9
... | def is_happy_number(n):
def get_next_number(num):
return sum(int(digit) ** 2 for digit in str(num))
seen = set()
while n != 1 and n not in seen:
seen.add(n)
n = get_next_number(n)
return n == 1
def happy_number_check(n):
return "YES" if is_happy_number(n) else "NO" | from solution import is_happy_number, happy_number_check
def test_happy_number():
assert is_happy_number(19) == True
assert is_happy_number(2) == False
assert is_happy_number(1) == True
assert is_happy_number(7) == True
assert is_happy_number(10) == True
def test_happy_number_check():
assert h... | [
{
"docstring": null,
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def happy_number_check(n):",
"function_name": "happy_number_check",
"parameter_list": "(n)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy_number(n):\n \"\"\"\n Determines if a given number n is a happy number.\n \n Parameters:\n n (int): The number to be checked.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087774",
"row_id": 87774,
"seed_ids": "[8850]"
} | 0.585905 | Taco_87774 | I | [
"is_happy_number",
"happy_number_check"
] | 2 | [
[
"happy_number_check",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8649b70190907ed642c51b2b0d039647087adeae | 4484d966dd72f3fbe1e6445087b4e38d4af30d42 | |||
v1.0 | instruct | Taco | Taco_87813_I | A company wants to place a number of sensors in a rectangular area to monitor environmental conditions. Each sensor has a specific range represented by a circle with a given radius. The goal is to determine if it is possible to cover the entire rectangular area with the given sensors. You need to write a program to ana... | import math
def is_covered(W, H, sensors, R):
# A function to check if each point in the rectanglar area is covered by at least one sensor
def point_covered(x, y):
for (sx, sy) in sensors:
if math.sqrt((sx - x)**2 + (sy - y)**2) <= R:
return True
return False
fo... | from solution import is_covered, analyze_coverage, read_input_data, main
def test_is_covered():
assert is_covered(5, 5, [(1, 1), (1, 4), (4, 1), (4, 4)], 2) == True
assert is_covered(10, 10, [(1, 1), (1, 9), (9, 1), (9, 9), (5, 5)], 3) == False
def test_analyze_coverage():
test_cases = [
((5, 5, 4... | [
{
"docstring": null,
"function_declaration": "def is_covered(W, H, sensors, R):",
"function_name": "is_covered",
"parameter_list": "(W, H, sensors, R)"
},
{
"docstring": null,
"function_declaration": "def analyze_coverage(test_cases):",
"function_name": "analyze_coverage",
"param... | [
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": "import math\n\ndef is_covered(W, H, sensors, R):\n def is_point_covered(x, y):\n for sx, sy in sensors:\n if math.hypot(sx - x, sy - y) <= R:\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00087813",
"row_id": 87813,
"seed_ids": "[23974]"
} | 0.688874 | Taco_87813 | I | [
"is_covered",
"analyze_coverage",
"read_input_data",
"main"
] | 4 | [
[
"analyze_coverage",
"is_covered"
]
] | 1 | [
"read_input_data"
] | false | [] | false | pytest | true | [] | true | d5d185e3347784fc8151854cbfb970eb4ca00390 | f762bf15661c5ef2574add59389e7c08d40a7472 | |||
v1.0 | instruct | Taco | Taco_87817_I | You are given a grid of size N x N with obstacles represented by 'X' and free cells represented by '.'. Your task is to determine the minimum number of steps required to move from the top-left corner (0,0) to the bottom-right corner (N-1,N-1) of the grid. You can move up, down, left, or right, and you cannot move throu... | from collections import deque
def min_steps_to_reach_end(grid):
N = len(grid)
if grid[0][0] == 'X' or grid[N-1][N-1] == 'X':
return -1 # If start or end is blocked
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(0, 0, 0)]) # (row, col, steps)
visited = set((0, 0))
wh... | import pytest
from solution import process_input_output, min_steps_to_reach_end
def test_single_case_1():
input_str = "1\n3\n...\n.X.\n...\n"
expected_output = [4]
assert process_input_output(input_str) == expected_output
def test_single_case_2():
input_str = "1\n3\n.X.\nX..\n...\n"
expected_outpu... | [
{
"docstring": null,
"function_declaration": "def min_steps_to_reach_end(grid):",
"function_name": "min_steps_to_reach_end",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(grid_cases):",
"function_name": "solve",
"parameter_list": "(grid_cas... | [
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 min_steps(grid):\n N = len(grid)\n if grid[0][0] == 'X' or grid[N-1][N-1] == 'X':\n return -1\n \n directio... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087817",
"row_id": 87817,
"seed_ids": "[501]"
} | 0.797728 | Taco_87817 | I | [
"min_steps_to_reach_end",
"solve",
"process_input_output"
] | 3 | [
[
"process_input_output",
"solve"
],
[
"solve",
"min_steps_to_reach_end"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | true | [] | true | 88ffe5c727e95c246070a8bd158f7cb8ec9c5c5b | 3c7d310402669313662465f62ef4f92289f4d2ae | |||
v1.0 | instruct | Taco | Taco_87970_I | Problem
A major delivery company is optimizing its delivery routes and needs your help to compute the minimum time it will take to deliver all the packages. The company operates a fleet of delivery vehicles, each with a maximum capacity of packages it can carry. Each delivery vehicle can be assigned to a subset of pac... | def min_delivery_time(num_vehicles, num_packages, capacities, delivery_times):
delivery_times.sort()
min_total_time = 0
for i in range(num_packages):
min_total_time += delivery_times[i]
return min_total_time
def solve_delivery_problem():
import sys
input = sys.stdin.read
data = in... | def test_min_delivery_time():
assert min_delivery_time(2, 5, [3, 2], [1, 2, 3, 4, 5]) == 15
assert min_delivery_time(3, 4, [2, 2, 1], [4, 5, 6, 7]) == 22
assert min_delivery_time(1, 1, [1], [10]) == 10
assert min_delivery_time(2, 5, [3, 2], [6, 7, 8, 9, 10]) == 40
def test_solve_delivery_problem(monkey... | [
{
"docstring": null,
"function_declaration": "def min_delivery_time(num_vehicles, num_packages, capacities, delivery_times):",
"function_name": "min_delivery_time",
"parameter_list": "(num_vehicles, num_packages, capacities, delivery_times)"
},
{
"docstring": null,
"function_declaration"... | [
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 min_delivery_time(V, P, capacities, delivery_times):\n \"\"\"\n Returns the minimum total delivery time when the packages are optimally assigned to the v... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00087970",
"row_id": 87970,
"seed_ids": "[24745]"
} | 0.737462 | Taco_87970 | I | [
"min_delivery_time",
"solve_delivery_problem"
] | 2 | [
[
"solve_delivery_problem",
"min_delivery_time"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f56cc0fb29cb1c55419b410b7ecd3581c77394d9 | aabafe7dc2c652a977c0f3eb46e50cfff96f67ec | |||
v1.0 | instruct | Taco | Taco_88011_I | In Farmville, there's a unique currency system where crops can be traded directly with each other without using any money. Each crop has a certain trading value, and the farmers want to maximize their trades beneficially.
You are given a list of crops and their respective values. Each day, you can trade one of your cr... | def max_trades(crop_values, initial_crop_value, available_trades):
"""
Function to calculate the maximum number of trades that can be performed starting with the initial crop value.
Parameters:
crop_values (list of int): List of crop values.
initial_crop_value (int): Initial crop value.
ava... | import pytest
from solution import max_trades, process_test_cases, from_input_string, to_output_string
def test_max_trades():
assert max_trades([10, 20, 30, 40, 50], 20, 3) == 3
assert max_trades([15, 25, 10], 10, 2) == 2
def test_process_test_cases():
T = 2
test_cases = [
(5, [10, 20, 30, 40,... | [
{
"docstring": "Function to calculate the maximum number of trades that can be performed starting with the initial crop value.\n\nParameters:\ncrop_values (list of int): List of crop values.\ninitial_crop_value (int): Initial crop value.\navailable_trades (int): Number of crops available to trade.\n\nReturns:\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 max_trades(num_crops, crop_values, initial_value, available_trades):\n \"\"\"\n Returns the maximum number of trades that can be performed in one day giv... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00088011",
"row_id": 88011,
"seed_ids": "[5060]"
} | 0.680983 | Taco_88011 | I | [
"max_trades",
"process_test_cases",
"from_input_string",
"to_output_string"
] | 4 | [
[
"process_test_cases",
"max_trades"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 9ddc5b4bd4e4b94006854ec63eee37f1b6bcd933 | d83ef28eb983f37905e0da370584de60e76d617c | |||
v1.0 | instruct | Taco | Taco_88058_I | Given a list of integers, you are tasked with creating a new list where each element in the new list is the product of all the elements in the original list except the one at the current index.
Input
The input consists of a single line containing a space-separated list of integers `a_1, a_2, ..., a_n` where `1 ≤ n ≤ ... | def product_except_self(nums):
"""
Returns a list such that each element is the product of all other elements except itself.
"""
n = len(nums)
if n == 0:
return []
# Initialize the result array with 1
result = [1] * n
# Calculate the left products
left_product = 1
f... | def test_product_except_self():
assert input_to_output("1 2 3 4") == "24 12 8 6"
assert input_to_output("2 3 4 5") == "60 40 30 24"
assert input_to_output("1 1 1 1") == "1 1 1 1"
assert input_to_output("0 1 2 3") == "6 0 0 0"
assert input_to_output("1 2 3") == "6 3 2"
assert input_to_output("5")... | [
{
"docstring": "Returns a list such that each element is the product of all other elements except itself.",
"function_declaration": "def product_except_self(nums):",
"function_name": "product_except_self",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def in... | [
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 product_except_self(nums):\n \"\"\"\n This function returns a new list where each element \n is the product of all the elements in the input list exce... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088058",
"row_id": 88058,
"seed_ids": "[24473]"
} | 0.683567 | Taco_88058 | I | [
"product_except_self",
"input_to_output"
] | 2 | [
[
"input_to_output",
"product_except_self"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 18aaade9fe08fd560b5ddb7681cb76816dc3bcf1 | 8f4da09afc0a1be15ce0a516ba717df081813893 | |||
v1.0 | instruct | Taco | Taco_88059_I | Jenny has a garden with different types of flowers. She wants to categorize them based on their blooming season. Each flower can only bloom in one of the four seasons: Spring, Summer, Autumn, or Winter.
Jenny has a list of flowers with the day of the year they start blooming (1 to 365). She needs your help to determin... | def determine_season(day):
"""
Determines the season for a given day of the year.
Args:
day (int): The day of the year (1 to 365).
Returns:
str: The season corresponding to the given day.
"""
if 60 <= day <= 151:
return "Spring"
elif 152 <= day <= 243:
return "Summe... | from solution import categorize_flowers, determine_season
def test_determine_season():
assert determine_season(60) == "Spring"
assert determine_season(151) == "Spring"
assert determine_season(152) == "Summer"
assert determine_season(243) == "Summer"
assert determine_season(244) == "Autumn"
asse... | [
{
"docstring": "Determines the season for a given day of the year.\n\nArgs:\nday (int): The day of the year (1 to 365).\n\nReturns:\nstr: The season corresponding to the given day.",
"function_declaration": "def determine_season(day):",
"function_name": "determine_season",
"parameter_list": "(day)"
... | [
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 determine_season(day):\n if 60 <= day <= 151:\n return \"Spring\"\n elif 152 <= day <= 243:\n return \"Summer\"\n elif 244 <= day <= 334... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088059",
"row_id": 88059,
"seed_ids": "[24308]"
} | 0.62776 | Taco_88059 | I | [
"determine_season",
"categorize_flowers"
] | 2 | [
[
"categorize_flowers",
"determine_season"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 218c2fd7e9bc75b747b01aa445a42a39f5273b79 | b7c9178bdab4d8909704837cc0639756acc26b9f | |||
v1.0 | instruct | Taco | Taco_88123_I | You are tasked to organize a coding competition at your university. The system for assigning levels to participants works based on their efficiency scores. Participants with scores less than 40 are assigned the "Beginner" level, those reaching up to 70 are classified as "Intermediate", and those crossing 70 are categor... | def is_fibonacci(n):
"""
Check if a given number n is a Fibonacci number.
A number is a Fibonacci number if and only if one (or both) of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
"""
if n == 0 or n == 1:
return True
def is_perfect_square(x):
s = int(x**0.5)
return s... | from solution import determine_level, coding_competition_levels
def test_determine_level():
assert determine_level(25) == "Beginner"
assert determine_level(45) == "Intermediate"
assert determine_level(72) == "Advanced"
assert determine_level(21) == "Elite" # 21 is a Fibonacci number
assert determ... | [
{
"docstring": "Check if a given number n is a Fibonacci number.\nA number is a Fibonacci number if and only if one (or both) of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.",
"function_declaration": "def is_fibonacci(n):",
"function_name": "is_fibonacci",
"parameter_list": "(n)"
},
{
"do... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def categorize_participants_scores(scores):\n \"\"\"\n This function categorizes participant scores based on their efficiency.\n\n Parameters:\n scores... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088123",
"row_id": 88123,
"seed_ids": "[19922]"
} | 0.659465 | Taco_88123 | I | [
"is_fibonacci",
"determine_level",
"coding_competition_levels"
] | 3 | [
[
"coding_competition_levels",
"determine_level"
],
[
"determine_level",
"is_fibonacci"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dc94e3873073a4aa0bb85db5e90375ef2758db53 | c0ff7a8c27d5c0c6d2c651269ca8649dc40eba2b | |||
v1.0 | instruct | Taco | Taco_88154_I | You need to develop a program that evaluates postfix mathematical expressions (also known as Reverse Polish Notation). Postfix expressions are mathematical expressions in which each operator follows all of its operands. For example, the postfix expression `5 1 2 + 4 * + 3 -` evaluates to `14`.
Here are the steps to ev... | def evaluate_postfix(expression):
stack = []
tokens = expression.split()
for token in tokens:
if token.isdigit():
stack.append(int(token))
else:
second_operand = stack.pop()
first_operand = stack.pop()
if token == '+':
result = ... | from solution import evaluate_postfix, evaluate_multiple_postfix
def test_evaluate_postfix():
assert evaluate_postfix("5 1 2 + 4 * + 3 -") == 14
assert evaluate_postfix("3 4 + 2 * 7 /") == 2
assert evaluate_postfix("4 2 3 * + 6 -") == 4
assert evaluate_postfix("2 3 +") == 5
assert evaluate_postfix(... | [
{
"docstring": null,
"function_declaration": "def evaluate_postfix(expression):",
"function_name": "evaluate_postfix",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def evaluate_multiple_postfix(expressions):",
"function_name": "evaluate_multiple_p... | [
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 evaluate_postfix(expr):\n \"\"\"\n Evaluates a postfix expression and returns the result.\n\n Args:\n expr (str): The postfix expression to evaluat... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088154",
"row_id": 88154,
"seed_ids": "[25254]"
} | 0.542007 | Taco_88154 | I | [
"evaluate_postfix",
"evaluate_multiple_postfix"
] | 2 | [
[
"evaluate_multiple_postfix",
"evaluate_postfix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c36aa0943e45487c7555cca932e22eaf17a4f457 | ec701a219eb57d501a62431f8c6771c77f0b53c3 | |||
v1.0 | instruct | Taco | Taco_88160_I | A wizard in the kingdom of Algorithmia has recently learned the art of prime summation. To practice his new skills, he wants to write a program that will help him find the sum of all unique prime numbers present in given ranges of integers. Given two integers a and b, the program should compute the sum of prime numbers... | 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 False
i += 6
return True
def s... | from solution import is_prime, sum_of_primes_in_range, compute_prime_sums
def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(11)
def test_sum_of_primes_in_range():
assert sum... | [
{
"docstring": "Checks if a number is prime. ",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all unique prime numbers in the range [a, b]. ",
"function_declaration": "def sum_of_primes_in_range(a, b... | [
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 sympy\n\ndef sum_primes_in_range(a, b):\n \"\"\"\n Given two integers a and b, return the sum of all prime numbers in the range [a, b], inclusive.\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00088160",
"row_id": 88160,
"seed_ids": "[10813]"
} | 0.610608 | Taco_88160 | I | [
"is_prime",
"sum_of_primes_in_range",
"compute_prime_sums"
] | 3 | [
[
"compute_prime_sums",
"sum_of_primes_in_range"
],
[
"sum_of_primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c0e4207f92f882f57b782fa71f583ec42b2d12d8 | a7036053e8dd82a3f30fabdcb27bec4d75b4cde9 | |||
v1.0 | instruct | Taco | Taco_88185_I | In a dense forest, there exists a network of magical trees connected by mystical paths. Each mystical path has an associated weight which influences magical energy flow between the trees it connects. This network is represented as an undirected graph where nodes are trees and edges are the mystical paths.
One day, a p... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif r... | def test_example_1():
n = 4
m = 5
edge_list = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(3, 4, 6),
(1, 4, 5)
]
assert solve(n, m, edge_list) == 9
def test_example_2():
n = 3
m = 1
edge_list = [
(1, 2, 2)
]
assert solve(n, m, edge_list) ==... | [
{
"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": "class DisjointSet:\n def __init__(self, n):\n self.parent = [i for i in range(n)]\n self.rank = [0] * n\n\n def find(self, x):\n if self... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088185",
"row_id": 88185,
"seed_ids": "[2664]"
} | 0.721628 | Taco_88185 | I | [
"find",
"union",
"minimum_spanning_tree",
"solve"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"solve",
"minimum_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | d9231d1d262afd0883d2ce5c5fb3d6836e3bbda5 | 995faf2df5f049cd8692c597dd5e1cb5fb2232a1 | |||
v1.0 | instruct | Taco | Taco_88209_I | Mary, a professional gardener, has a rectangular garden divided into an m x n grid of cells, where each cell can either contain a plant or be empty. Mary wants to plant new flowers in some of the empty cells, but she wants to ensure that no two adjacent cells (vertically or horizontally) contain flowers.
Your task is ... | def max_flowers(garden):
m = len(garden)
n = len(garden[0])
count = 0
for r in range(m):
for c in range(n):
if garden[r][c] == '.':
if (r == 0 or garden[r - 1][c] != 'F') and (c == 0 or garden[r][c - 1] != 'F'):
garden[r][c] = 'F'
... | from solution import solve
def test_example_1():
assert solve(3, 3, [
".#.",
"...",
"..#"
]) == 4
def test_example_2():
assert solve(4, 4, [
"....",
"....",
"....",
"...."
]) == 8
def test_single_cell_with_plant():
assert solve(1, 1, ["#"]) ... | [
{
"docstring": null,
"function_declaration": "def max_flowers(garden):",
"function_name": "max_flowers",
"parameter_list": "(garden)"
},
{
"docstring": null,
"function_declaration": "def solve(m, n, garden):",
"function_name": "solve",
"parameter_list": "(m, n, garden)"
}
] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_flowers(m, n, garden):\n def is_valid(x, y):\n return 0 <= x < m and 0 <= y < n and garden[x][y] == '.'\n\n def can_plant(x, y):\n # Ch... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00088209",
"row_id": 88209,
"seed_ids": "[23852]"
} | 0.654102 | Taco_88209 | I | [
"max_flowers",
"solve"
] | 2 | [
[
"solve",
"max_flowers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cfac61f981cc975e43982ef1403a794137a3b0f3 | 3183dc6296e394b04ebd33f98bdead3f04751b43 | |||
v1.0 | instruct | Taco | Taco_88216_I | A new startup Byteland Transit is planning to open a bus service that operates between different locations in the city. To ensure smooth operations, they need an optimal schedule to avoid any overlaps in bus services. Each bus route has a start and end time, and a bus route is considered active during this time interva... | def min_buses_needed(T, test_cases):
results = []
for i in range(T):
N = test_cases[i][0]
start_times = test_cases[i][1]
end_times = test_cases[i][2]
intervals = sorted(zip(start_times, end_times), key=lambda x: x[1])
count = 0
last_end_time = 0
... | from solution import min_buses_needed
def test_single_test_case():
T = 1
test_cases = [
(3, [1, 3, 5], [4, 8, 9])
]
assert min_buses_needed(T, test_cases) == [2]
def test_multiple_test_cases():
T = 2
test_cases = [
(3, [1, 3, 5], [4, 8, 9]),
(4, [2, 4, 6, 7], [5, 7, 8,... | [
{
"docstring": null,
"function_declaration": "def min_buses_needed(T, test_cases):",
"function_name": "min_buses_needed",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def get_min_buses(T, test_cases):",
"function_name": "get_min_buses",
"pa... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_buses_needed(T, test_cases):\n results = []\n for i in range(T):\n N = test_cases[i][0]\n start_times = test_cases[i][1]\n end_t... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088216",
"row_id": 88216,
"seed_ids": "[5257]"
} | 0.762251 | Taco_88216 | I | [
"min_buses_needed",
"get_min_buses"
] | 2 | [
[
"get_min_buses",
"min_buses_needed"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90aae05435525bb8e7fd09845672a5ddfa4791bc | cad58981c93e9d9a83c90157026bbfffa97efd1a | |||
v1.0 | instruct | Taco | Taco_88276_I | Time Limit: 8 sec / Memory Limit: 64 MB
You are given a binary tree structure where each node contains a unique integer value. The task is to find the lowest common ancestor (LCA) of two given nodes in the tree. The LCA of two nodes `p` and `q` in a binary tree is defined as the lowest node that has both `p` and `q` a... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(node_map):
if not node_map:
return None
nodes = {val: TreeNode(val) for val in node_map}
for val, (left, right) in node_map.items():
if left != -1:
n... | from solution import TreeNode, build_tree, lowest_common_ancestor, find_lca
def test_example_case():
n = 9
tree_data = [
(3, 5, 1),
(5, 6, 2),
(1, 0, 8),
(6, -1, -1),
(2, 7, 4),
(0, -1, -1),
(8, -1, -1),
(7, -1, -1),
(4, -1, -1)
]
... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(nodes, val_to_node):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088276",
"row_id": 88276,
"seed_ids": "[24900]"
} | 0.623928 | Taco_88276 | I | [
"build_tree",
"lowest_common_ancestor",
"find_lca"
] | 3 | [
[
"find_lca",
"build_tree"
],
[
"find_lca",
"lowest_common_ancestor"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | bca46c931df5ef69a82797e00ac76130e6f8c006 | f69cfb56c90d420bf04440bdeb64e80e5d8f5ce6 | |||
v1.0 | instruct | Taco | Taco_88298_I | Driveway is a simple strategic game involving placing segments on a grid and achieving the maximum connection value. The game is played on an n x n grid where you can place segments horizontally or vertically. Each segment has a length of 1 and a weight of 1. Positions are identified by coordinates (x, y), where 1 ≤ x,... | import math
def euclidean_distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def calculate_max_connection_value(n, m, segments):
total_connection_value = 0
for i in range(m):
x1, y1, x2, y2 = segments[i]
total_connection_value += euclidean_distance(x1, y1, x2, y2)
... | import math
from solution import calculate_max_connection_value, euclidean_distance
def test_euclidean_distance():
assert math.isclose(euclidean_distance(1, 1, 1, 2), 1.0, rel_tol=1e-9)
assert math.isclose(euclidean_distance(2, 3, 2, 4), 1.0, rel_tol=1e-9)
assert math.isclose(euclidean_distance(3, 3, 4, 3)... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(x1, y1, x2, y2):",
"function_name": "euclidean_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def calculate_max_connection_value(n, m, segments):",
"function_name": ... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n \"\"\"\n Calculate the Euclidean distance between two points (x1, y1) and (... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00088298",
"row_id": 88298,
"seed_ids": "[20680]"
} | 0.59096 | Taco_88298 | I | [
"euclidean_distance",
"calculate_max_connection_value"
] | 2 | [
[
"calculate_max_connection_value",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87094f09a67a1b6820352ef931db29373b95f099 | 1fd427742b1243611548fcc33b1ee2aa0d4b5632 | |||
v1.0 | instruct | Taco | Taco_88312_I | You are working on a project that involves collecting data from various sources to create a combined report. Each data source is represented as a file that contains a series of records. Every file consists of records with a timestamp and a value. The goal is to merge these records from all files into a single file in i... | from heapq import heappush, heappop
def merge_files(files):
"""
Merges multiple files with sorted records by timestamps.
Parameters:
files (list of list of tuples): List of files, each file is a list of (timestamp, value) tuples.
Returns:
list of tuples: Merged list of (timestamp, val... | def test_merge_files_small_example():
input_text = """3
3 1 100 3 150 5 200
2 2 50 4 250
3 1 60 3 160 6 300"""
output_text = """1 60
1 100
2 50
3 150
3 160
4 250
5 200
6 300"""
assert process(input_text) == output_text
def test_merge_files_single_file():
input_text = """1
3 2 50 4 250 6 300""... | [
{
"docstring": "Merges multiple files with sorted records by timestamps.\n\nParameters:\n files (list of list of tuples): List of files, each file is a list of (timestamp, value) tuples.\n\nReturns:\n list of tuples: Merged list of (timestamp, value) tuples sorted by timestamp.",
"function_declaration... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef merge_files(file_data):\n merged_data = []\n min_heap = []\n\n # Step 1: Prepare a list of iterators for each file's records\n iter... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088312",
"row_id": 88312,
"seed_ids": "[3702]"
} | 0.4931 | Taco_88312 | I | [
"merge_files",
"parse_input",
"format_output",
"process"
] | 4 | [
[
"process",
"format_output"
],
[
"process",
"merge_files"
],
[
"process",
"parse_input"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | fbda8f7e13a262872369a0228656ab43aa4f7f97 | 334db0db710c91b68631bddd58b617ae1ab66abf | |||
v1.0 | instruct | Taco | Taco_88341_I | Alex is a budding software engineer and wants to create a program that can detect prime numbers efficiently. He is aware that checking larger numbers for primality can be time-consuming, and thus intends to use a probabilistic method called the Miller-Rabin primality test.
Your task is to help Alex by implementing a f... | import random
def miller_rabin(n, k=5):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0:
return False
# Write n as d*2^r + 1
r, d = 0, n - 1
while d % 2 == 0:
r += 1
d //= 2
def is_composite(a):
if pow(a, d, n) == 1:
... | from solution import primality_test
def test_primality_sample_input():
assert primality_test([2, 17, 18, 19, 20]) == ["YES", "YES", "NO", "YES", "NO"]
def test_primality_small_primes():
assert primality_test([3, 5, 7, 11, 13]) == ["YES", "YES", "YES", "YES", "YES"]
def test_primality_small_composites():
... | [
{
"docstring": null,
"function_declaration": "def miller_rabin(n, k=5):",
"function_name": "miller_rabin",
"parameter_list": "(n, k=5)"
},
{
"docstring": null,
"function_declaration": "def primality_test(numbers):",
"function_name": "primality_test",
"parameter_list": "(numbers)"... | [
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 miller_rabin_primality_test(n, k=5):\n import random\n\n def is_prime(n, d, s):\n a = random.randint(2, n - 2)\n x = pow(a, d, n)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088341",
"row_id": 88341,
"seed_ids": "[352]"
} | 0.677756 | Taco_88341 | I | [
"miller_rabin",
"primality_test"
] | 2 | [
[
"primality_test",
"miller_rabin"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 09c5cabe806f746e616805c2c2cbc16a3e0dd4db | 6369278680d25bc34764f1f54150aa72aa337a07 | |||
v1.0 | instruct | Taco | Taco_88374_I | You are working at a software company where you need to implement a feature that auto-suggests corrections for misspelled words using a given dictionary. To achieve this, you decide to utilize a simple heuristic based on the Levenshtein distance (edit distance). The Levenshtein distance between two words is the minimum... | from typing import List
def levenshtein_distance(s1: str, s2: str) -> int:
"""
Compute the Levenshtein distance between two strings s1 and s2.
"""
if len(s1) < len(s2):
return levenshtein_distance(s2, s1)
if len(s2) == 0:
return len(s1)
previous_row = range(len(s2) + 1)
fo... | from solution import find_closest_matches
def test_exact_match():
dictionary = ["apple", "banana", "carrot"]
words_to_check = ["apple"]
assert find_closest_matches(dictionary, words_to_check) == ["apple"]
def test_single_edit_distance():
dictionary = ["apple", "banana", "carrot"]
words_to_check = ... | [
{
"docstring": "Compute the Levenshtein distance between two strings s1 and s2.",
"function_declaration": "def levenshtein_distance(s1, s2):",
"function_name": "levenshtein_distance",
"parameter_list": "(s1, s2)"
},
{
"docstring": null,
"function_declaration": "def find_closest_matches(d... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef levenshtein_distance(s1: str, s2: str) -> int:\n \"\"\"\n Compute the Levenshtein distance between two strings s1 and s2.\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088374",
"row_id": 88374,
"seed_ids": "[22591]"
} | 0.648029 | Taco_88374 | I | [
"levenshtein_distance",
"find_closest_matches"
] | 2 | [
[
"find_closest_matches",
"levenshtein_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 55a063d75568e4cf36e580c6fd038f3a0aeacce8 | cccc5cbf2edf363af7db81bbc00bfe4ed579e201 | |||
v1.0 | instruct | Taco | Taco_88377_I | The Kingdom of Booleania is known for its large network of road systems. The king of Booleania has decided to start a new project to improve the transportation system between cities. To minimize travel time, the king wants to ensure that the network of roads is efficiently connected, such that there is a way to travel ... | 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_total_travel_time
def test_case_1():
test_cases = [
(4, 5, [
(0, 1, 1),
(0, 2, 2),
(0, 3, 3),
(1, 2, 1),
(2, 3, 1),
]),
]
assert minimum_total_travel_time(test_cases) == [3]
def test_case_2():
test... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088377",
"row_id": 88377,
"seed_ids": "[6331]"
} | 0.822937 | Taco_88377 | I | [
"find",
"union",
"kruskal_mst",
"minimum_total_travel_time"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"minimum_total_travel_time",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | f2fc34e4dbfd5e476a68807c2240fe0f6260e585 | 45909168e19b585c42896d1de3cc99b8663c1e9f | |||
v1.0 | instruct | Taco | Taco_88381_I | India's prime minister has launched a new initiative to encourage students to study more mathematics. As part of this initiative, he introduced a coding competition. The problem to be solved is as follows:
Given an array of integers and an integer k, determine whether there are two distinct indices i and j in the arra... | def find_pairs_with_difference_k(nums, k):
"""
Determines if there are two distinct indices i and j in the array such that
the absolute difference between nums[i] and nums[j] is equal to k.
"""
num_set = set(nums)
for num in nums:
if (num + k) in num_set or (num - k) in num_set:
... | from solution import find_pairs_with_difference_k, solve, parse_input
def test_find_pairs_with_difference_k():
assert find_pairs_with_difference_k([10, 15, 3, 7], 5) == "YES"
assert find_pairs_with_difference_k([1, 2, 3, 4], 3) == "YES"
assert find_pairs_with_difference_k([1, 5, 9, 14], 6) == "NO"
asse... | [
{
"docstring": "Determines if there are two distinct indices i and j in the array such that\nthe absolute difference between nums[i] and nums[j] is equal to k.",
"function_declaration": "def find_pairs_with_difference_k(nums, k):",
"function_name": "find_pairs_with_difference_k",
"parameter_list": "... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_pairs_with_difference(test_cases):\n results = []\n \n for k, array in test_cases:\n found = False\n num_set = set(array)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088381",
"row_id": 88381,
"seed_ids": "[5153]"
} | 0.709001 | Taco_88381 | I | [
"find_pairs_with_difference_k",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"find_pairs_with_difference_k"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 1bdb3027050eb94e059d24042d6a2f0973330167 | db3e6835fe3bb84042a61f8bd6c208f3a08a77ae | |||
v1.0 | instruct | Taco | Taco_88394_I | You've been given a rectangular grid with `m` rows and `n` columns where each cell contains either a '0' (empty cell) or a '1' (land cell). The grid represents a map of a fictive Archipelago, and you need to find the number of distinct islands on this map. An island is defined as a group of '1's connected vertically an... | def count_islands(m, n, grid):
def dfs(x, y):
if x < 0 or x >= m or y < 0 or y >= n or grid[x][y] == '0':
return
grid[x][y] = '0' # Mark the cell as visited
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
dfs(x + dx, y + dy)
islands = 0
for i in range(m):
... | from solution import solve_islands_problem
def test_case_1():
m, n = 4, 5
grid_str = "11000\n11000\n00100\n00011"
assert solve_islands_problem(m, n, grid_str) == 3
def test_case_2():
m, n = 3, 3
grid_str = "111\n010\n111"
assert solve_islands_problem(m, n, grid_str) == 1
def test_case_3():
... | [
{
"docstring": null,
"function_declaration": "def count_islands(m, n, grid):",
"function_name": "count_islands",
"parameter_list": "(m, n, grid)"
},
{
"docstring": null,
"function_declaration": "def solve_islands_problem(m, n, input_grid_str):",
"function_name": "solve_islands_proble... | [
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 num_distinct_islands(grid):\n \"\"\"\n Returns the number of distinct islands in the grid.\n \n grid: list of list of str: The grid given as list o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088394",
"row_id": 88394,
"seed_ids": "[19730]"
} | 0.64446 | Taco_88394 | I | [
"count_islands",
"solve_islands_problem"
] | 2 | [
[
"solve_islands_problem",
"count_islands"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9926923930193fa1924ba84497842a10f75abd9e | 754021765aefd619aba6e88842276f948110303e | |||
v1.0 | instruct | Taco | Taco_88400_I | In the kingdom of Geometrica, there are several castles located on the x-y plane. Each castle is represented by its coordinates (xi, yi). The king wants to ensure that all castles are connected by building the minimum number of roads, such that each road connects two castles directly. A road between two castles (xi, yi... | import math
import heapq
class DisjointSet:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [1] * n
def find(self, a):
if self.parent[a] == a:
return a
self.parent[a] = self.find(self.parent[a]) # Path compression
return self.parent[a]
... | from solution import min_total_cost_to_connect_castles
def test_example_1():
castles = [(0, 0), (0, 1), (1, 0), (1, 1)]
result = min_total_cost_to_connect_castles(castles)
assert abs(result - 3.000000) < 1e-6
def test_example_2():
castles = [(0, 0), (1, 1), (2, 2)]
result = min_total_cost_to_conne... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nimport heapq\n\nclass DisjointSet:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088400",
"row_id": 88400,
"seed_ids": "[4805]"
} | 0.686291 | Taco_88400 | I | [
"calc_distance",
"min_total_cost_to_connect_castles"
] | 2 | [
[
"min_total_cost_to_connect_castles",
"calc_distance"
]
] | 1 | [] | false | [
"DisjointSet"
] | true | pytest | true | [] | true | a5b81c6c7ba79c3f67ce142639fef27cd3a8b68f | bee8764e7ae3854a926e075ab00aecd40d51b2f7 | |||
v1.0 | instruct | Taco | Taco_88416_I | The kingdom of Keploria is under attack by an army of goblins that march in from the east. The kingdom's defensive strategy requires understanding the patterns in which the goblins approach. The goblins' marching paths can be represented as a grid where each cell contains an integer height representing the terrain's el... | def is_valid_path(grid, n, m):
from collections import deque
directions = [(0, 1), (1, 0)]
visited = [[False for _ in range(m)] for _ in range(n)]
queue = deque([(0, 0)])
visited[0][0] = True
while queue:
x, y = queue.popleft()
if x == n - 1 and y == m - 1:
return ... | import pytest
from solution import parse_input, can_patrol
def test_can_patrol():
input_data = "2\n3 3\n1 2 3\n2 3 4\n3 4 5\n3 3\n1 3 5\n6 8 10\n11 13 15\n"
T, test_cases = parse_input(input_data)
results = can_patrol(T, test_cases)
assert results == ["YES", "NO"]
def test_single_case_yes():
input... | [
{
"docstring": null,
"function_declaration": "def is_valid_path(grid, n, m):",
"function_name": "is_valid_path",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def can_patrol(T, test_cases):",
"function_name": "can_patrol",
"parameter_list": "(T... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_valid_path(grid, n, m):\n \"\"\"\n Determines if there is a valid path from the top-left to the bottom-right cell\n by onl... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088416",
"row_id": 88416,
"seed_ids": "[22632]"
} | 0.653718 | Taco_88416 | I | [
"is_valid_path",
"can_patrol",
"parse_input"
] | 3 | [
[
"can_patrol",
"is_valid_path"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 4961673f0ef4309202f1762e8aa9faf204aae9e1 | 88ac8239bcdf31ebd6aa53be9720a08b519b5575 | |||
v1.0 | instruct | Taco | Taco_88438_I | Alice has recently learned about prime numbers and their significance in cryptography. To help her practice, Bob gave her a task: Given a number n, find the closest prime number greater than n. If there are multiple prime numbers at the same distance, return the smaller one.
Your task is to help Alice by writing a pro... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def next_prime(n):
if n <=... | from solution import is_prime, next_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_next_prime():
assert next_prime(7) == 11
assert n... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
}
] | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00088438",
"row_id": 88438,
"seed_ids": "[3985]"
} | 0.697841 | Taco_88438 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a7ec3e4d23a9f81da49194721f628c94fb21381e | d004fe7f97d44acc4376809cefefaf8f4cc202c6 | |||
v1.0 | instruct | Taco | Taco_88447_I | Given an array of integers scores, you are tasked with performing multiple queries on this array. Each query is defined by a range [l, r] (inclusive) for which you need to find the sum of the scores. Your task is to efficiently process these queries using prefix sums to provide the sum of elements in the specified rang... | def preprocess_prefix_sums(scores):
"""
Computes the prefix sums for the given scores array.
"""
prefix_sums = [0] * (len(scores) + 1)
for i in range(1, len(prefix_sums)):
prefix_sums[i] = prefix_sums[i-1] + scores[i-1]
return prefix_sums
def range_sum_queries(scores, queries):
"""
... | from solution import range_sum_queries
def test_range_sum_queries_basic():
scores = [1, 7, 3, 0, 9, 4]
queries = [[1, 3], [0, 4], [2, 5]]
assert range_sum_queries(scores, queries) == [10, 20, 16]
def test_range_sum_queries_single_element():
scores = [5]
queries = [[0, 0]]
assert range_sum_quer... | [
{
"docstring": "Computes the prefix sums for the given scores array.",
"function_declaration": "def preprocess_prefix_sums(scores):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(scores)"
},
{
"docstring": "Given an array of scores and a list of queries, returns the sum of ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum(scores):\n \"\"\"\n Generates the prefix sum array for the given scores.\n \"\"\"\n n = len(scores)\n prefix = [0] * (n + 1)\n for... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088447",
"row_id": 88447,
"seed_ids": "[2342]"
} | 0.602581 | Taco_88447 | I | [
"preprocess_prefix_sums",
"range_sum_queries"
] | 2 | [
[
"range_sum_queries",
"preprocess_prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aed824179a54c34a75f47bcf5667c865d228a2ae | 51f4cc74b2dd27f5cccd07d5a1ac699a10755325 | |||
v1.0 | instruct | Taco | Taco_88462_I | You are given a string s and you need to determine if it is possible to partition the string into three non-empty parts such that each part is a palindrome.
-----Input-----
The input contains a single string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.
-----Output-----
Print "YES" if it is possible t... | def is_palindrome(sub):
return sub == sub[::-1]
def can_partition_into_three_palindromic_parts(s):
n = len(s)
for i in range(1, n - 1):
for j in range(i + 1, n):
if is_palindrome(s[:i]) and is_palindrome(s[i:j]) and is_palindrome(s[j:]):
return "YES"
return "NO" | from solution import can_partition_into_three_palindromic_parts
def test_example_1():
assert can_partition_into_three_palindromic_parts("abcbdd") == "YES"
def test_example_2():
assert can_partition_into_three_palindromic_parts("abcd") == "NO"
def test_example_3():
assert can_partition_into_three_palindro... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(sub):",
"function_name": "is_palindrome",
"parameter_list": "(sub)"
},
{
"docstring": null,
"function_declaration": "def can_partition_into_three_palindromic_parts(s):",
"function_name": "can_partition_into_three_palindr... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to determine if a given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef can_partition_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088462",
"row_id": 88462,
"seed_ids": "[15386]"
} | 0.75042 | Taco_88462 | I | [
"is_palindrome",
"can_partition_into_three_palindromic_parts"
] | 2 | [
[
"can_partition_into_three_palindromic_parts",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 099be7fef1b5ea18d514e0ac209b059321166678 | 1439214d85a0ca63dd82620aff64464c72d7d36b | |||
v1.0 | instruct | Taco | Taco_88474_I | You are given an array of integers. You are required to find out if any three distinct elements in the array sum up to a given target number.
Write a function that checks if there exists any trio of numbers within the array that add up to the target.
------ Input Format ------
- The first line of input will contain a... | def three_sum_exists(nums, target):
"""
This function checks whether there exists any trio of numbers within the array that add up to the target.
Parameters:
nums (list): A list of integers.
target (int): The target sum.
Returns:
str: "YES" if there exists such a trio, otherwise "N... | from solution import three_sum_exists
def test_sample_input_1():
assert three_sum_exists([1, 2, 3, 4, 5, 6], 10) == "YES"
def test_sample_input_2():
assert three_sum_exists([1, 2, 3, 7, 8], 20) == "NO"
def test_no_possible_trio():
assert three_sum_exists([1, 1, 1, 1], 10) == "NO"
def test_all_negative_n... | [
{
"docstring": "This function checks whether there exists any trio of numbers within the array that add up to the target.\n\nParameters:\nnums (list): A list of integers.\ntarget (int): The target sum.\n\nReturns:\nstr: \"YES\" if there exists such a trio, otherwise \"NO\".",
"function_declaration": "def th... | [
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_trio_with_sum(arr, target):\n \"\"\"\n Checks if there exists a trio in the array that sums to the target value.\n\n Args:\n arr: List[int], t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088474",
"row_id": 88474,
"seed_ids": "[13852]"
} | 0.679825 | Taco_88474 | I | [
"three_sum_exists",
"trio_sum_solver"
] | 2 | [
[
"trio_sum_solver",
"three_sum_exists"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4a6564557967895d91f7ac8964a23855eab7049e | 1ea5843caf3445eab6d994b1437c9b82384646a8 | |||
v1.0 | instruct | Taco | Taco_88491_I | Zara is playing a card game where she makes sequences of cards placed in a row. The game allows only increasing sequences, where each card's number must be greater than the number of the previous card. Zara wants to know the length of the longest increasing subsequence she can make from a given sequence of cards.
Give... | def length_of_LIS(arr):
"""
Function to determine the length of the longest increasing subsequence.
"""
if not arr:
return 0
dp = [1] * len(arr)
for i in range(1, len(arr)):
for j in range(i):
if arr[i] > arr[j]:
dp[i] = max(dp[i], dp[j] + 1)
... | import pytest
from solution import parse_input, longest_increasing_subsequence, length_of_LIS
def test_length_of_LIS():
assert length_of_LIS([10, 22, 9, 33, 21, 50, 41, 60]) == 5
assert length_of_LIS([3, 10, 2, 1, 20, 19]) == 3
assert length_of_LIS([]) == 0
assert length_of_LIS([5]) == 1
assert len... | [
{
"docstring": "Function to determine the length of the longest increasing subsequence.",
"function_declaration": "def length_of_LIS(arr):",
"function_name": "length_of_LIS",
"parameter_list": "(arr)"
},
{
"docstring": "Function to process multiple test cases and return the results of longes... | [
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 length_of_lis(cards):\n \"\"\"\n Calculates the length of the longest increasing subsequence in a list of cards.\n \n Args:\n cards (list of int... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088491",
"row_id": 88491,
"seed_ids": "[18935]"
} | 0.708464 | Taco_88491 | I | [
"length_of_LIS",
"longest_increasing_subsequence",
"parse_input"
] | 3 | [
[
"longest_increasing_subsequence",
"length_of_LIS"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f2565b9bd3e9fe7b4a7b1ca59403ef331a76c9f5 | 569eb867d752d9418f454a404525fb4806408d96 | |||
v1.0 | instruct | Taco | Taco_88510_I | Dexter is playing a new game for coding practice. The game consists of a series of challenges where he needs to determine the largest rectangular submatrix, within a given binary matrix, that has all 1s. A binary matrix is a matrix where each element is either 0 or 1.
Dexter wants to write a program that, given a bina... | def maximalRectangle(matrix):
if not matrix:
return 0
max_area = 0
rows, cols = len(matrix), len(matrix[0])
heights = [0] * cols
for row in matrix:
for i in range(cols):
heights[i] = heights[i] + 1 if row[i] == 1 else 0
max_area = max(max_area, larg... | from solution import maximalRectangle
def test_maximalRectangle_example1():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maximalRectangle(matrix) == 6
def test_maximalRectangle_example2():
matrix = [
[0, 1, 0],
[... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n rows, cols = len(matrix), len(matrix[0])\n heights = [0] * cols\n\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088510",
"row_id": 88510,
"seed_ids": "[7134]"
} | 0.674609 | Taco_88510 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bcc41af53c7096dab3d603b5deb85fb04fc2d80b | f652f7537413dcd24c41a20ccbd61762a47a1c62 | |||
v1.0 | instruct | Taco | Taco_88512_I | In a given list of integers, you need to identify the first unique integer (an integer that appears exactly once in the list).
------ Input: ------
First line contains a single integer T, the number of test cases.
Each of the next T lines contains a list of space-separated integers.
------ Output: ------
For each ... | def first_unique_integer(test_cases):
"""
For each test case, returns the first unique integer in the list of integers.
If no unique integer is found, returns -1.
"""
results = []
for case in test_cases:
count = {}
for num in case:
if num in count:
... | from solution import find_first_unique_integers, first_unique_integer
def test_find_first_unique_integers():
assert find_first_unique_integers(4, [
[4, 5, 1, 2, 5, 1, 4, 3],
[1, 2, 2, 1, 3, 4, 3, 3],
[7, 7, 7, 6, 6, 6, 5, 5, 5],
[9]
]) == [2, 4, -1, 9]
assert find_first_... | [
{
"docstring": "For each test case, returns the first unique integer in the list of integers.\nIf no unique integer is found, returns -1.",
"function_declaration": "def first_unique_integer(test_cases):",
"function_name": "first_unique_integer",
"parameter_list": "(test_cases)"
},
{
"docstri... | [
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 first_unique_integer(lst):\n \"\"\"\n Given a list of integers, returns the first unique integer.\n If there is no unique integer, returns -1.\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088512",
"row_id": 88512,
"seed_ids": "[17581]"
} | 0.644688 | Taco_88512 | I | [
"first_unique_integer",
"find_first_unique_integers"
] | 2 | [
[
"find_first_unique_integers",
"first_unique_integer"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa461a9991ece4cb9e73cf320c432510868bbcd9 | f0694eb7c492cf5a0e9e046b0a4fbcf2254c9d7a | |||
v1.0 | instruct | Taco | Taco_88555_I | In a galaxy far, far away, there exists a unique species of flowering plants called Trivelleas. Each Trivellea plant has a binary DNA string of length n. The binary DNA string determines the color of the plant. Two Trivellea plants can be cross-pollinated to produce a new offspring Trivellea plant. The DNA string of th... | def calculate_xor_dna(dna1, dna2):
"""
Helper function to calculate the XOR DNA string from two binary DNA strings.
"""
return ''.join(str(int(b1) ^ int(b2)) for b1, b2 in zip(dna1, dna2))
def probability_equal_zeros_ones(dna1, dna2):
"""
Calculate the probability that the offspring of two Triv... | from solution import probability_equal_zeros_ones
def test_odd_length_dna():
assert probability_equal_zeros_ones("101", "010") == "0.00000"
def test_equal_zeros_ones():
assert probability_equal_zeros_ones("1100", "1010") == "1.00000"
assert probability_equal_zeros_ones("1111", "0000") == "0.00000"
def te... | [
{
"docstring": "Helper function to calculate the XOR DNA string from two binary DNA strings.",
"function_declaration": "def calculate_xor_dna(dna1, dna2):",
"function_name": "calculate_xor_dna",
"parameter_list": "(dna1, dna2)"
},
{
"docstring": "Calculate the probability that the offspring ... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def probability_of_equal_0s_1s(parent1, parent2):\n \"\"\"\n Returns the probability of producing an offspring with an equal number of 0s and 1s.\n \"\"\"... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00088555",
"row_id": 88555,
"seed_ids": "[9128]"
} | 0.5259 | Taco_88555 | I | [
"calculate_xor_dna",
"probability_equal_zeros_ones"
] | 2 | [
[
"probability_equal_zeros_ones",
"calculate_xor_dna"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee406c2ea17996b785fa6976e4e1302f5f85618e | c42c1cf7d7042f63778798dbd51e719191538f58 | |||
v1.0 | instruct | Taco | Taco_88569_I | Write a program that evaluates whether a series of brackets is correctly balanced. A correctly balanced sequence of brackets is one in which every opening bracket of a given type has a matching closing bracket of the same type, in the correct order.
There are three types of brackets to balance:
- Round brackets: `()`
... | def is_balanced(sequence):
"""
Check if the given sequence of brackets is balanced.
:param sequence: String containing the sequence of brackets.
:return: 'YES' if the sequence is balanced, 'NO' otherwise.
"""
bracket_map = {')': '(', ']': '[', '}': '{'}
open_brackets = {'(', '[', '{'}
s... | from solution import evaluate_sequences, is_balanced
def test_is_balanced():
assert is_balanced("()") == 'YES'
assert is_balanced("([])") == 'YES'
assert is_balanced("{[()()]}") == 'YES'
assert is_balanced("(") == 'NO'
assert is_balanced("([)]") == 'NO'
assert is_balanced("{[(])}") == 'NO'
... | [
{
"docstring": "Check if the given sequence of brackets is balanced.\n\n:param sequence: String containing the sequence of brackets.\n:return: 'YES' if the sequence is balanced, 'NO' otherwise.",
"function_declaration": "def is_balanced(sequence):",
"function_name": "is_balanced",
"parameter_list": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced(sequence):\n stack = []\n matching_bracket = {')': '(', ']': '[', '}': '{'}\n\n for char in sequence:\n if char in matching_bracket... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088569",
"row_id": 88569,
"seed_ids": "[4636]"
} | 0.664021 | Taco_88569 | I | [
"is_balanced",
"evaluate_sequences"
] | 2 | [
[
"evaluate_sequences",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 270217805c57974207adb0066a6347dc97cc20d5 | 86006cfe5d7fed75d57ec1ee252f18e15c6b0f93 | |||
v1.0 | instruct | Taco | Taco_88622_I | You are in charge of optimizing the inventory for a warehouse. The warehouse has a limited capacity, and you need to determine the optimal way to store different types of items to maximize the total value of the inventory. Each type of item has a specific weight and value, and you cannot store fractions of an item.
Cr... | def knapsack(W, n, items):
"""
Solves the 0/1 Knapsack problem.
W: Integer, capacity of the warehouse.
n: Integer, number of different types of items.
items: List of tuples [(wi, vi), ..., (wn, vn)]
"""
dp = [0] * (W + 1)
for weight, value in items:
for j in range(W, weight ... | from solution import knapsack, process_warehouse_data
def test_knapsack():
assert knapsack(50, 3, [(10, 60), (20, 100), (30, 120)]) == 220
assert knapsack(100, 2, [(50, 200), (50, 300)]) == 500
assert knapsack(10, 1, [(10, 100)]) == 100
assert knapsack(10, 1, [(11, 100)]) == 0
assert knapsack(15, 3... | [
{
"docstring": "Solves the 0/1 Knapsack problem.\nW: Integer, capacity of the warehouse.\nn: Integer, number of different types of items.\nitems: List of tuples [(wi, vi), ..., (wn, vn)]",
"function_declaration": "def knapsack(W, n, items):",
"function_name": "knapsack",
"parameter_list": "(W, n, it... | [
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 knapsack(W, items):\n \"\"\"\n Function to find the maximum value of items that can be stored in a warehouse with given capacity.\n \n Parameters:\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00088622",
"row_id": 88622,
"seed_ids": "[743]"
} | 0.716846 | Taco_88622 | I | [
"knapsack",
"process_warehouse_data"
] | 2 | [
[
"process_warehouse_data",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca5c7cdba1d43de5c2e474a828f1ff220b46a9d2 | 7fd7721f4327c56818b7ff508466f1f7712d4449 | |||
v1.0 | instruct | Taco | Taco_88647_I | Given an array of integers, and a target sum, determine whether there are three distinct integers in the array that add up to the target sum. You need to return a boolean indicating the presence of such a triplet.
Input
The first line contains 2 integers N and target denoting the number of elements in the array and th... | def find_triplet_sum(array, target):
"""
Determine whether there are three distinct integers in the array
that add up to the target sum.
Returns:
bool: True if such a triplet exists, else False.
"""
array.sort()
N = len(array)
for i in range(N - 2):
left = i + 1
... | from solution import find_triplet_sum
def test_find_triplet_sum_exists():
array = [-1, 2, 1, -4, 2]
target = 0
assert find_triplet_sum(array, target) == True
def test_find_triplet_sum_not_exists():
array = [1, 2, 3, 4, 5]
target = 50
assert find_triplet_sum(array, target) == False
def test_al... | [
{
"docstring": "Determine whether there are three distinct integers in the array \nthat add up to the target sum.\n\nReturns:\n bool: True if such a triplet exists, else False.",
"function_declaration": "def find_triplet_sum(array, target):",
"function_name": "find_triplet_sum",
"parameter_list":... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_triplet_sum(arr, target):\n \"\"\"\n Determines whether there are three distinct integers in the array that add up to the target sum.\n\n :param a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088647",
"row_id": 88647,
"seed_ids": "[15569]"
} | 0.660175 | Taco_88647 | I | [
"find_triplet_sum",
"solve"
] | 2 | [
[
"solve",
"find_triplet_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e336cd8d7f7e176c79355557a62a115e537bb85 | 3ef34d7035409de3d323f8d1e0be62e857699c60 | |||
v1.0 | instruct | Taco | Taco_88696_I | Problem:
Nina loves playing with numbers, especially prime numbers. One day, she decided to play a game where she picks any number and checks if any arrangement of its digits is a prime number.
Input:
The first line contains an integer T, the number of test cases. The next T lines contain an integer N.
Output:
For... | from itertools import permutations
def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return Tru... | from solution import is_prime, any_prime_permutation, process_test_cases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(25) == False
def test_any_prime_permutation():
... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if any permutation of the digits of num is a prime number.",
"function_declaration": "def any_prime_permutation... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088696",
"row_id": 88696,
"seed_ids": "[22004]"
} | 0.633841 | Taco_88696 | I | [
"is_prime",
"any_prime_permutation",
"process_test_cases"
] | 3 | [
[
"any_prime_permutation",
"is_prime"
],
[
"process_test_cases",
"any_prime_permutation"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 271f60149682e8cf2bc124627e5b63b66d5eeddf | 39b6c83e7edca97857b044c8a645832777ebed18 | |||
v1.0 | instruct | Taco | Taco_88708_I | The resistance group has captured an alien device which is able to analyze patterns in strings. They have discovered that the device can identify distinct substrings within a given string. However, the device starts to malfunction if there are too many distinct substrings to analyze. For a given string, your task is to... | def distinct_substrings_count(s):
"""
Returns the number of distinct substrings in the given string s.
"""
n = len(s)
substrings = set()
for i in range(n):
for j in range(i + 1, n + 1):
substrings.add(s[i:j])
return len(substrings)
def malfunction_check(t, limits_and_str... | from solution import malfunction_check
def test_malfunction_check_no_malfunction():
assert malfunction_check(1, [(10, "abc")]) == ["NO MALFUNCTION"]
def test_malfunction_check_malfunction():
assert malfunction_check(1, [(5, "ababa")]) == ["MALFUNCTION"]
def test_malfunction_check_multiple_cases():
assert... | [
{
"docstring": "Returns the number of distinct substrings in the given string s.",
"function_declaration": "def distinct_substrings_count(s):",
"function_name": "distinct_substrings_count",
"parameter_list": "(s)"
},
{
"docstring": "Returns a list of results (\"NO MALFUNCTION\" or \"MALFUNCT... | [
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 count_distinct_substrings(s):\n \"\"\"\n Function to count the number of distinct substrings in a string.\n \"\"\"\n n = len(s)\n substrings = s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088708",
"row_id": 88708,
"seed_ids": "[21037]"
} | 0.693241 | Taco_88708 | I | [
"distinct_substrings_count",
"malfunction_check"
] | 2 | [
[
"malfunction_check",
"distinct_substrings_count"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7cb4f64768ee8d78ea45e9f029fc231d3d0c451 | c0ad0822751a4e19b06fe072d57df4fa5f51268a | |||
v1.0 | instruct | Taco | Taco_88718_I | You are given a sentence in the form of a string. Write a function to replace each character in the sentence with its succeeding character in the alphabet. If the character is 'z' or 'Z', it should wrap around to 'a' or 'A', respectively. Maintain the case of the original character and avoid altering spaces and punctua... | def shift_char(c):
if 'a' <= c <= 'y' or 'A' <= c <= 'Y':
return chr(ord(c) + 1)
elif c == 'z':
return 'a'
elif c == 'Z':
return 'A'
else:
return c
def shift_sentence(sentence):
return ''.join(shift_char(c) for c in sentence) | from solution import shift_sentence
def test_single_lowercase_letter():
assert shift_sentence("a") == "b"
assert shift_sentence("m") == "n"
def test_single_uppercase_letter():
assert shift_sentence("A") == "B"
assert shift_sentence("M") == "N"
def test_wrap_around_lowercase():
assert shift_senten... | [
{
"docstring": null,
"function_declaration": "def shift_char(c):",
"function_name": "shift_char",
"parameter_list": "(c)"
},
{
"docstring": null,
"function_declaration": "def shift_sentence(sentence):",
"function_name": "shift_sentence",
"parameter_list": "(sentence)"
}
] | [
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 shift_characters(sentence):\n def shift_char(c):\n if 'a' <= c <= 'z':\n return chr((ord(c) - ord('a') + 1) % 26 + ord('a'))\n elif... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088718",
"row_id": 88718,
"seed_ids": "[18953]"
} | 0.663134 | Taco_88718 | I | [
"shift_char",
"shift_sentence"
] | 2 | [
[
"shift_sentence",
"shift_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed2d92099a041df3e750d94beb9c81f19b89c4c8 | 5bebae2e9840b4c585aabd8a6490f7c2cc3559a9 | |||
v1.0 | instruct | Taco | Taco_88883_I | You are given a string `s` and an array of strings `words`. Your task is to determine the number of strings in `words` that are subsequences of `s`. A subsequence of a string is defined as a new string generated from the original string with some characters deleted without changing the relative order of the remaining c... | def is_subsequence(s, word):
"""
Returns True if word is a subsequence of s.
"""
it = iter(s)
return all(char in it for char in word)
def num_matching_subseq(s, words):
"""
Returns the count of words that are subsequences of s.
"""
return sum(is_subsequence(s, word) for word in word... | from solution import is_subsequence, num_matching_subseq
def test_is_subsequence():
assert is_subsequence("abcde", "a") == True
assert is_subsequence("abcde", "ace") == True
assert is_subsequence("abcde", "acd") == True
assert is_subsequence("abcde", "bb") == False
assert is_subsequence("abcdefg", ... | [
{
"docstring": "Returns True 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 words that are subsequences of s.",
"function_declaration": "def ... | [
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(s, word):\n \"\"\"\n Returns True if word is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in it for char in word... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088883",
"row_id": 88883,
"seed_ids": "[14927]"
} | 0.78232 | Taco_88883 | I | [
"is_subsequence",
"num_matching_subseq"
] | 2 | [
[
"num_matching_subseq",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee9b33311a508a39c3869e0bd0797d09103ffa62 | 1bf9fbc357cc0f5010c97360bc7d054f4fd9a2d0 | |||
v1.0 | instruct | Taco | Taco_88884_I | Given an array of integers, you need to implement a function that sorts the array in ascending order based on the frequency of the values. If multiple values have the same frequency, they should appear in ascending order.
Input
First line contains an integer n, the number of elements in the array (1 <= n <= 100).
Se... | from collections import Counter
def sort_by_frequency(arr):
"""
Sort the array in ascending order based on the frequency of the values.
If multiple values have the same frequency, they should appear in ascending order.
"""
count = Counter(arr)
# Sort primarily by frequency, secondarily by value... | from solution import sort_by_frequency, formatted_output
def test_sort_by_frequency_case_1():
assert formatted_output(6, [4, 5, 6, 5, 4, 3]) == "3 6 4 4 5 5"
def test_sort_by_frequency_case_2():
assert formatted_output(5, [9, 9, 4, 8, 8]) == "4 8 8 9 9"
def test_sort_by_frequency_single_element():
as... | [
{
"docstring": "Sort the array in ascending order based on the frequency of the values.\nIf multiple values have the same frequency, they should appear in ascending order.",
"function_declaration": "def sort_by_frequency(arr):",
"function_name": "sort_by_frequency",
"parameter_list": "(arr)"
},
... | [
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 Counter\n\ndef sort_by_frequency(arr):\n \"\"\"\n Sorts the array based on the frequency of the values. Values with the same\n fre... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088884",
"row_id": 88884,
"seed_ids": "[23217]"
} | 0.636641 | Taco_88884 | I | [
"sort_by_frequency",
"formatted_output"
] | 2 | [
[
"formatted_output",
"sort_by_frequency"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19db41b7803e5fad24822c39a154b95436868f64 | dc5f7e18112614c21037b930e25760270c420fef | |||
v1.0 | instruct | Taco | Taco_88914_I | Alice loves solving problems using graphs. She has recently encountered an interesting problem where she needs to find the shortest path in a weighted, undirected graph. However, the graph has a special property: every edge can disappear at any given moment.
Due to this, Alice wants to know the shortest path not at t... | import heapq
def dijkstra_shortest_path(n, graph, start, end):
distances = {node: float('inf') for node in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_di... | from solution import solve
def test_single_case():
t = 1
test_cases = [
(
5, 6,
[
(1, 2, 10),
(1, 3, 3),
(2, 3, 1),
(2, 4, 2),
(3, 5, 6),
(4, 5, 7)
],
3,
... | [
{
"docstring": null,
"function_declaration": "def dijkstra_shortest_path(n, graph, start, end):",
"function_name": "dijkstra_shortest_path",
"parameter_list": "(n, graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def process_queries(n, edges, queries):",
"function... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, src, n):\n dist = [float('inf')] * n\n dist[src] = 0\n min_heap = [(0, src)]\n \n while min_heap:\n curre... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00088914",
"row_id": 88914,
"seed_ids": "[5885]"
} | 0.728439 | Taco_88914 | I | [
"dijkstra_shortest_path",
"process_queries",
"solve"
] | 3 | [
[
"process_queries",
"dijkstra_shortest_path"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 6dd2b49519f86de553e0596b4a091cf8d9c1cccd | f5dfb3417ba52c459c74fa8ea2a2612308d23be6 | |||
v1.0 | instruct | Taco | Taco_88916_I | Given a positive integer N, the task is to find the smallest prime number greater than N.
Example 1:
Input:
N = 10
Output:
11
Explanation:
The smallest prime number greater than 10 is 11.
Example 2:
Input:
N = 17
Output:
19
Explanation:
The smallest prime number greater than 17 is 19.
Your Task:
You don't need to re... | import math
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def nextPrime(N):... | from solution import nextPrime
def test_next_prime_after_10():
assert nextPrime(10) == 11
def test_next_prime_after_17():
assert nextPrime(17) == 19
def test_next_prime_after_1():
assert nextPrime(1) == 2
def test_next_prime_after_23():
assert nextPrime(23) == 29
def test_next_prime_after_1000000()... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than N.",
"function_declaration": "def nextPrime(N):",
"function_name": "nextPrime",
"parameter_l... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n if num in (2, 3):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00088916",
"row_id": 88916,
"seed_ids": "[14475]"
} | 0.566108 | Taco_88916 | I | [
"is_prime",
"nextPrime"
] | 2 | [
[
"nextPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab78da7a4a9a3c8e1380cada71369a69ed631245 | df394e616f19c8275a5fd1515cf2bbb3c5209702 | |||
v1.0 | instruct | Taco | Taco_88936_I | The kingdom of Geeklandia is represented as an undirected graph with `n` cities connected by `m` bidirectional roads. The cities are numbered from `1` to `n`. Each road has a certain length (positive integer). The citizens of Geeklandia want to know the shortest route between any two cities in the kingdom.
You are tas... | def floyd_warshall(n, edges):
"""
Floyd-Warshall algorithm to determine the shortest distance between all pairs of nodes.
"""
# Initialize distance array
dist = [[float('inf')] * (n + 1) for _ in range(n + 1)]
# Distance from any node to itself is 0
for i in range(1, n + 1):
dis... | def test_floyd_warshall_basic():
edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)]
n = 4
dist = floyd_warshall(n, edges)
assert dist[1][4] == 9
assert dist[2][4] == 8
assert dist[1][1] == 0
def test_shortest_distances():
n = 4
edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)]
... | [
{
"docstring": "Floyd-Warshall algorithm to determine the shortest distance between all pairs of nodes.",
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def shorte... | [
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 floyd_warshall(n, edges):\n dist = [[float('inf')] * (n + 1) for _ in range(n + 1)]\n \n for i in range(1, n + 1):\n dist[i][i] = 0\n \n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00088936",
"row_id": 88936,
"seed_ids": "[13323]"
} | 0.787886 | Taco_88936 | I | [
"floyd_warshall",
"shortest_distances"
] | 2 | [
[
"shortest_distances",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b56d807ed933e74fdac6b6fc9ebe63fc2855f58c | dd3a4b1446a0b3a9c881b8b5471fa4d56c0ec2b9 | |||
v1.0 | instruct | Taco | Taco_88971_I | In a land far away, there exist towns connected by highways. The king of this land has decreed that all citizens must be able to travel between any two towns. To achieve this, he plans to build some additional highways. Each highway connects exactly two towns and has a unique length. The objective is to minimize the to... | 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):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[r... | from solution import minimum_highway_length
def test_no_highways():
assert minimum_highway_length(4, []) == 0
def test_some_highways():
assert minimum_highway_length(4, [(1, 2, 3), (3, 4, 5)]) == 8
def test_already_connected():
assert minimum_highway_length(4, [(1, 2, 3), (2, 3, 4), (3, 4, 5)]) == 0
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"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_7 | {
"original_instruction": "",
"prompt_id": "00088971",
"row_id": 88971,
"seed_ids": "[14981]"
} | 0.79053 | Taco_88971 | I | [
"find",
"union",
"minimum_highway_length",
"main"
] | 4 | [
[
"minimum_highway_length",
"find"
],
[
"minimum_highway_length",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | cac913ceed47a9d1c8309ffe57d69b97026bbbfb | df7f313e8f03da737649ed2659afd0117c02ebea | |||
v1.0 | instruct | Taco | Taco_88997_I | # Sum of Primes
Create a function that finds the sum of all prime numbers below a given positive integer `n`. Recall that a prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
The function should return the sum as an integer.
## Example
```python
sum_of_primes(10) #--> 1... | def is_prime(num):
"""
Helper function to determine if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import sum_of_primes
def test_sum_of_primes_below_10():
assert sum_of_primes(10) == 17
def test_sum_of_primes_below_20():
assert sum_of_primes(20) == 77
def test_sum_of_primes_below_2():
assert sum_of_primes(2) == 0
def test_sum_of_primes_below_1():
assert sum_of_primes(1) == 0
def te... | [
{
"docstring": "Helper function to determine if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers below the given positive integer n.",
"function_declaration"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00088997",
"row_id": 88997,
"seed_ids": "[5205]"
} | 0.751841 | Taco_88997 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d2c268db9041bb01a7d2e59eacb613a6617ca34 | eaaf24afc132840f8c53454f1dd2d8e67d9cfa31 | |||
v1.0 | instruct | Taco | Taco_89100_I | Chef needs your help to analyze customer preferences in his restaurant. He is interested in finding out the most common prefix length of dishes that different customers order. For this problem, you are given an array of strings, where each string represents the name of a dish ordered by a customer.
Your task is to det... | def longest_common_prefix(strs):
"""
Returns the longest common prefix of an array of strings.
"""
if not strs:
return 0
# The shortest string will limit the comparison of the common prefix.
min_length = min(len(s) for s in strs)
for i in range(min_length):
char = s... | def test_longest_common_prefix():
assert longest_common_prefix(["spaghetti", "spanakopita", "spicy"]) == 2
assert longest_common_prefix(["pizza", "pizzicato"]) == 4
assert longest_common_prefix(["applepie", "applejuice", "applecrumble", "appletart"]) == 5
assert longest_common_prefix([""]) == 0
asse... | [
{
"docstring": "Returns the longest common prefix of an array of strings.",
"function_declaration": "def longest_common_prefix(strs):",
"function_name": "longest_common_prefix",
"parameter_list": "(strs)"
},
{
"docstring": null,
"function_declaration": "def find_longest_common_prefix_len... | [
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 longest_common_prefix_length(dishes):\n \"\"\"\n Finds the length of the longest common prefix among all the given dishes.\n \n Args:\n dishes (... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00089100",
"row_id": 89100,
"seed_ids": "[387]"
} | 0.67968 | Taco_89100 | I | [
"longest_common_prefix",
"find_longest_common_prefix_length",
"process_input"
] | 3 | [
[
"find_longest_common_prefix_length",
"longest_common_prefix"
],
[
"process_input",
"find_longest_common_prefix_length"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 73b4b54606b5e8e8931b2affc5bbdfc8b8a14fbb | 36ffc59178f2c4d63a7845d9eb0183e56a760c53 | |||
v1.0 | instruct | Taco | Taco_89111_I | A researcher is studying the growth patterns of a rare species of plant. Each day, the researcher records the height of the plant and calculates the average growth rate over certain periods. The growth rate is defined as the difference in height between the start and the end of the period, divided by the number of days... | def record_height_and_query_growth(n, operations):
"""
Record the height of the plant on given days and query the average growth rate over periods.
:param n: number of operations
:param operations: list of operations
:return: list of results for each query operation
"""
heights = {}
... | def test_basic_functionality():
operations = [
"record 1 3",
"record 2 8",
"record 3 10",
"record 4 15",
"record 5 18",
"query 2 5"
]
assert plant_growth_operations(6, operations) == ["3.3333"]
def test_small_sample():
operations = [
"record 1 0",... | [
{
"docstring": "Record the height of the plant on given days and query the average growth rate over periods.\n\n:param n: number of operations\n:param operations: list of operations\n:return: list of results for each query operation",
"function_declaration": "def record_height_and_query_growth(n, operations... | [
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 record_and_query_growth(n, operations):\n days = {}\n \n def record(day, height):\n days[day] = height\n \n def query(d1, d2):\n i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089111",
"row_id": 89111,
"seed_ids": "[25307]"
} | 0.649014 | Taco_89111 | I | [
"record_height_and_query_growth",
"plant_growth_operations"
] | 2 | [
[
"plant_growth_operations",
"record_height_and_query_growth"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c609c1f52ff4598ab68d4a2a9e1a5a30314412c4 | 2d6e9850b549c89e5f0fb7d613a4b75fa6d9c474 | |||
v1.0 | instruct | Taco | Taco_89154_I | In a small town, there exists a network of N intersections connected by bidirectional roads. The town council has a problem; they want to determine whether it is possible to remove some roads such that the road network remains fully connected, but the number and length of the roads are minimized. Your job is to help th... | def minimal_spanning_tree(N, roads):
"""
Finds the minimal sum of all road lengths forming a fully connected network.
Args:
N (int): Number of intersections.
roads (list of tuples): List of roads where each tuple is (u, v, L).
Returns:
int: Minimal sum of road lengths in the spanni... | def test_minimal_spanning_tree():
# Test case 1
N = 4
roads = [(1, 2, 1), (1, 3, 3), (2, 3, 1), (3, 4, 1), (4, 1, 6)]
assert minimal_spanning_tree(N, roads) == 3
# Test case 2
N = 3
roads = [(1, 2, 1), (2, 3, 3), (1, 3, 4)]
assert minimal_spanning_tree(N, roads) == 4
# Test... | [
{
"docstring": "Finds the minimal sum of all road lengths forming a fully connected network.\n\nArgs:\nN (int): Number of intersections.\nroads (list of tuples): List of roads where each tuple is (u, v, L).\n\nReturns:\nint: Minimal sum of road lengths in the spanning tree.",
"function_declaration": "def mi... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimal_road_network(N, M, roads):\n \"\"\"\n Find the minimal sum of all road lengths forming a fully connected network (a spanning tree).\n \n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00089154",
"row_id": 89154,
"seed_ids": "[17434]"
} | 0.723592 | Taco_89154 | I | [
"minimal_spanning_tree",
"run_solution"
] | 2 | [
[
"run_solution",
"minimal_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 06da2f7f2c86695f01fdb8993de1655c63825d3e | 2f5b7a1bc53234b95e2c305756fa64d21d09a1b0 | |||
v1.0 | instruct | Taco | Taco_89177_I | Given a list of integers, you are required to find out the length of the longest subsequence such that every element in the subsequence is an increasing power of 2 sequence.
Example 1:
Input: [3, 10, 4, 8, 16, 20]
Output: 3
Explanation:
The longest subsequence that forms an increasing power of 2 is [4, 8, 16].
Exampl... | def is_power_of_2(x):
""" Helper function to check if a number is a power of 2. """
return (x != 0) and (x & (x - 1)) == 0
def longestPowerOf2Subseq(arr):
"""
Finds the length of the longest subsequence such that every element
in the subsequence is an increasing power of 2 sequence.
"""
pow... | from solution import longestPowerOf2Subseq
def test_longestPowerOf2Subseq_example1():
assert longestPowerOf2Subseq([3, 10, 4, 8, 16, 20]) == 3
def test_longestPowerOf2Subseq_example2():
assert longestPowerOf2Subseq([1, 2, 4, 8, 3, 6, 12]) == 4
def test_longestPowerOf2Subseq_no_powers_of_2():
assert longe... | [
{
"docstring": "Helper function to check if a number is a power of 2. ",
"function_declaration": "def is_power_of_2(x):",
"function_name": "is_power_of_2",
"parameter_list": "(x)"
},
{
"docstring": "Finds the length of the longest subsequence such that every element\nin the subsequence is an... | [
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 longestPowerOf2Subseq(nums):\n def is_power_of_2(x):\n return (x & (x - 1)) == 0 and x > 0\n\n powers_of_2 = sorted([num for num in nums if is_pow... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00089177",
"row_id": 89177,
"seed_ids": "[18644]"
} | 0.683641 | Taco_89177 | I | [
"is_power_of_2",
"longestPowerOf2Subseq"
] | 2 | [
[
"longestPowerOf2Subseq",
"is_power_of_2"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 15809e652833aa94f9d1df10a1671720de5872e6 | c53952601d481eb90fe951e783c9bca6fe80f781 | |||
v1.0 | instruct | Taco | Taco_89249_I | Given a number N, you need to generate all the prime numbers less than or equal to N and check whether the sum of these prime numbers is also a prime number.
Example 1:
Input: N = 10
Output: "No"
Explanation: The prime numbers <= 10 are [2, 3, 5, 7]. Their sum is 2+3+5+7 = 17, which is prime. So, the answer is "Yes".
... | def is_prime(num):
if num <= 1:
return False
if num == 2 or num == 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def isSumOfPrime... | from solution import isSumOfPrimesPrime
def test_example_1():
assert isSumOfPrimesPrime(10) == "Yes"
def test_example_2():
assert isSumOfPrimesPrime(20) == "No"
def test_small_prime():
assert isSumOfPrimesPrime(2) == "Yes"
def test_small_non_prime():
assert isSumOfPrimesPrime(4) == "Yes"
def test_l... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def isSumOfPrimesPrime(N):",
"function_name": "isSumOfPrimesPrime",
"parameter_list": "(N)"
}
] | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00089249",
"row_id": 89249,
"seed_ids": "[21946]"
} | 0.611589 | Taco_89249 | I | [
"is_prime",
"isSumOfPrimesPrime"
] | 2 | [
[
"isSumOfPrimesPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70485c058aa98ed77ecf676047e67ff1befe83dd | a95b953c033ade3eb16aafd1e2239f050cc2469a | |||
v1.0 | instruct | Taco | Taco_89270_I | Write a program that simulates a simple drawing application on a grid. The program should accept commands to draw horizontal and vertical lines of a specified length. Each grid cell is represented by an integer, starting with all cells initialized to 0. Drawing a line will set the corresponding grid cells to 1.
Comman... | def initialize_grid(size=100):
return [[0 for _ in range(size)] for _ in range(size)]
def draw_horizontal_line(grid, x, y, length):
for i in range(length):
grid[x][y + i] = 1
def draw_vertical_line(grid, x, y, length):
for i in range(length):
grid[x + i][y] = 1
def process_commands(comman... | from solution import initialize_grid, draw_horizontal_line, draw_vertical_line, process_commands
def test_initialize_grid():
grid = initialize_grid()
assert len(grid) == 100
assert len(grid[0]) == 100
assert all(cell == 0 for row in grid for cell in row)
def test_draw_horizontal_line():
grid = ini... | [
{
"docstring": null,
"function_declaration": "def initialize_grid(size=100):",
"function_name": "initialize_grid",
"parameter_list": "(size=100)"
},
{
"docstring": null,
"function_declaration": "def draw_horizontal_line(grid, x, y, length):",
"function_name": "draw_horizontal_line",
... | [
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 initialize_grid(size=100):\n return [[0 for _ in range(size)] for _ in range(size)]\n\ndef draw_horizontal_line(grid, x, y, length):\n for i in range(len... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089270",
"row_id": 89270,
"seed_ids": "[21291]"
} | 0.65109 | Taco_89270 | I | [
"initialize_grid",
"draw_horizontal_line",
"draw_vertical_line",
"process_commands",
"print_grid"
] | 5 | [
[
"process_commands",
"draw_horizontal_line"
],
[
"process_commands",
"draw_vertical_line"
],
[
"process_commands",
"initialize_grid"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 521c5514c0e0281b763facf7b91574d31e7c9b7b | eb9709c041eb65ea733b30895c425a70fbf408f3 | |||
v1.0 | instruct | Taco | Taco_89315_I | A large literature library wants to maintain a catalog of all books. Each book can belong to multiple categories and the library wants to keep track of the catalog efficiently.
Your task is to create a system to manage the library's book catalog, allowing efficient insertion, deletion, and retrieval of books by their... | class LibraryCatalog:
def __init__(self):
self.catalog = {}
self.book_categories = {}
def add_book(self, book_id, categories):
if book_id in self.book_categories:
return
self.book_categories[book_id] = set(categories)
for category in categories:
... | from solution import simulate_library_operations
def test_add_and_get_books():
commands = """add_book 1 fiction mystery
add_book 2 science fiction
add_book 3 mystery
get_books_by_category fiction
get_books_by_category mystery
remove_book 1
get_books_by_category fiction
get_books_by_category mystery
end"""
resu... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class LibraryCatalog:\n def __init__(self):\n self.catalog = {}\n self.book_categories = {}\n \n def add_book(self, book_id, categories):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089315",
"row_id": 89315,
"seed_ids": "[4398]"
} | 0.602131 | Taco_89315 | I | [
"process_commands",
"simulate_library_operations"
] | 2 | [
[
"simulate_library_operations",
"process_commands"
]
] | 1 | [] | false | [
"LibraryCatalog"
] | true | pytest | true | [] | true | 74e49ec73557826726dd14a3df2b475dd5aa2402 | 29e434fa5a44a096a2fe2e1535581be4025d5b38 | |||
v1.0 | instruct | Taco | Taco_89342_I | Given a 2D grid of size N x M, your task is to determine the number of unique islands. An island is formed by connected groups of '1's (land) on the grid. Connectivity is determined by horizontal or vertical adjacency, i.e., all horizontally or vertically neighboring cells forming a group of '1's make up one unique isl... | def dfs(grid, x, y, visited):
n = len(grid)
m = len(grid[0])
stack = [(x, y)]
while stack:
cx, cy = stack.pop()
if (cx, cy) in visited:
continue
visited.add((cx, cy))
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny = cx + dx, cy + dy
... | from solution import find_number_of_islands, parse_input
def test_example_case_1():
input_str = "2\n4 5\n1 1 0 0 0\n1 1 0 1 1\n0 0 0 1 1\n0 0 0 1 0\n3 3\n1 0 1\n0 1 0\n1 0 1\n"
test_cases = parse_input(input_str)
assert find_number_of_islands(test_cases) == [2, 5]
def test_single_island():
input_str =... | [
{
"docstring": null,
"function_declaration": "def dfs(grid, x, y, visited):",
"function_name": "dfs",
"parameter_list": "(grid, x, y, visited)"
},
{
"docstring": null,
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
}... | [
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_islands(grid, n, m):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0:\n return\n grid[x][y] = 0 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00089342",
"row_id": 89342,
"seed_ids": "[12076]"
} | 0.612039 | Taco_89342 | I | [
"dfs",
"num_islands",
"find_number_of_islands",
"parse_input"
] | 4 | [
[
"find_number_of_islands",
"num_islands"
],
[
"num_islands",
"dfs"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | e492d74a62012a89e1d7b0abf8ea3ae58c0edb7f | 7d2e90318962a4496b16e17d2497ac0998807d8d | |||
v1.0 | instruct | Taco | Taco_89344_I | Chef has decided to conduct a special operation to monitor and ensure the security of various city zones in Gotham. Each zone has a specific level of security, represented by a number. Zones are connected through a network of security paths, forming a complex web of routes.
Batman has built a new monitoring system tha... | from collections import defaultdict
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY]... | def test_monitor_security():
# Test case 1
N = 5
updates = {
"edges": [(1, 2), (2, 3), (3, 4), (4, 5)]
}
queries = [
[0, 1, 5],
[1, 3, 10],
[0, 3, 2],
[0, 5, 1]
]
expected_output = ["YES", "YES", "YES"]
assert monitor_security(N, queries, updates) ... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
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": "class GothamSecurity:\n def __init__(self, n, security_levels, edges):\n self.n = n\n self.security_levels = security_levels\n self.graph =... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00089344",
"row_id": 89344,
"seed_ids": "[6143]"
} | 0.629463 | Taco_89344 | I | [
"find",
"union",
"monitor_security"
] | 3 | [
[
"monitor_security",
"find"
],
[
"monitor_security",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 2a9c26e0b2c85f42f9e649819a5f012b8d8b67fb | 17074d840c92f295f39ce69292392e35fa600580 | |||
v1.0 | instruct | Taco | Taco_89380_I | A palindromic number is a number that remains the same when its digits are reversed. Given a number, determine whether it is a palindrome.
Input Format:
The input begins with number of test cases t in a single line. In each of the next t lines, there is a number n.
Output Format:
In each line print YES if the given n... | def is_palindromic_number(n):
"""
Determines if a given number is a palindrome.
"""
str_n = str(n)
return str_n == str_n[::-1]
def check_palindromic_numbers(t, numbers):
"""
Checks if each number in the list `numbers` is palindromic and returns results as a list.
"""
results = []
... | from solution import is_palindromic_number, check_palindromic_numbers
def test_is_palindromic_number():
assert is_palindromic_number(121)
assert is_palindromic_number(12321)
assert not is_palindromic_number(123)
assert is_palindromic_number(1)
assert is_palindromic_number(0)
assert not is_palin... | [
{
"docstring": "Determines if a given number is a palindrome.",
"function_declaration": "def is_palindromic_number(n):",
"function_name": "is_palindromic_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks if each number in the list `numbers` is palindromic and returns results as a li... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Determine if a given number n is a palindrome.\n \"\"\"\n str_n = str(n)\n return str_n == str_n[::-1]\n\ndef check... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00089380",
"row_id": 89380,
"seed_ids": "[3663]"
} | 0.782949 | Taco_89380 | I | [
"is_palindromic_number",
"check_palindromic_numbers"
] | 2 | [
[
"check_palindromic_numbers",
"is_palindromic_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 89c2ec9cf065704de3187a3ea4efe3829c154348 | be705c517909947673ddbd860786f53cdfc06946 | |||
v1.0 | instruct | Taco | Taco_89381_I | In a mystical land, there is a game played with arrays where the players derive the "Power Value" of a subarray. The Power Value of a subarray is defined as the sum of all prime numbers within that segment.
Given an array of non-negative integers and a number of queries, each query asks for the Power Value of a specif... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True # 2 is the only even prime number
if num % 2 == 0:
return False # other even numbers are not prime
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True... | from solution import is_prime, precompute_prime_sums, power_value
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
def test_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def precompute_prime_sums(arr):",
"function_name": "precompute_prime_sums",
"parameter_list": "(arr)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Function to perform the Sieve of Eratosthenes to find all primes up to max_num inclusive.\n Returns a list ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089381",
"row_id": 89381,
"seed_ids": "[5945]"
} | 0.665168 | Taco_89381 | I | [
"is_prime",
"precompute_prime_sums",
"power_value"
] | 3 | [
[
"power_value",
"precompute_prime_sums"
],
[
"precompute_prime_sums",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a693f1fc3d6dead6e4986b7fd885ae5f6116573a | 33ee7976eedb8fd288295a543a5621b89644628a | |||
v1.0 | instruct | Taco | Taco_89414_I | Given a list of distinct integers, we want to determine the kth smallest element in the list using the Quickselect algorithm. Quickselect is a selection algorithm to find the kth smallest element in an unordered list. It is related to the QuickSort sorting algorithm.
Your task is to implement the Quickselect algorithm... | def quickselect(arr, low, high, k):
if low == high:
return arr[low]
pivot_index = partition(arr, low, high)
if pivot_index == k:
return arr[pivot_index]
elif pivot_index < k:
return quickselect(arr, pivot_index + 1, high, k)
else:
return quickselect(arr, low, piv... | from solution import find_kth_smallest_element
def test_kth_smallest_element():
assert find_kth_smallest_element(6, 3, [7, 10, 4, 3, 20, 15]) == 7
assert find_kth_smallest_element(5, 1, [1, 2, 3, 4, 5]) == 1
assert find_kth_smallest_element(5, 5, [1, 2, 3, 4, 5]) == 5
assert find_kth_smallest_element(5... | [
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list": "(arr, low, high, k)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_l... | [
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 quickselect(arr, low, high, k):\n \"\"\"\n Helper function to perform the Quickselect algorithm.\n \"\"\"\n if low == high: # If the list contains... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089414",
"row_id": 89414,
"seed_ids": "[15604]"
} | 0.557567 | Taco_89414 | I | [
"quickselect",
"partition",
"find_kth_smallest_element"
] | 3 | [
[
"find_kth_smallest_element",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1c623f8ed55c73a16845d039847baf57206495cd | 11c8a9c34d2cd88ed51e9b632152181ff15dec78 | |||
v1.0 | instruct | Taco | Taco_89431_I | In a futuristic city-state named Proglandia, the government has implemented a public transportation system powered by monorails. The monorail network consists of several interconnected stations and straight tracks uniting them. Each station is identified by a unique integer.
The monorail system allows you to travel be... | from collections import deque
def shortest_path_monorail(num_stations, num_tracks, tracks, start, end):
# Create the graph as an adjacency list
graph = {i: [] for i in range(1, num_stations + 1)}
for u, v in tracks:
graph[u].append(v)
graph[v].append(u)
# BFS to find the short... | from solution import find_shortest_path
def test_shortest_path_case1():
input_data = "6 7\n1 2\n2 3\n2 4\n3 4\n4 5\n5 6\n3 6\n1 6"
assert find_shortest_path(input_data) == 3
def test_shortest_path_case2():
input_data = "5 5\n1 2\n1 3\n2 4\n3 4\n4 5\n1 5"
assert find_shortest_path(input_data) == 3
def... | [
{
"docstring": null,
"function_declaration": "def shortest_path_monorail(num_stations, num_tracks, tracks, start, end):",
"function_name": "shortest_path_monorail",
"parameter_list": "(num_stations, num_tracks, tracks, start, end)"
},
{
"docstring": null,
"function_declaration": "def fin... | [
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 shortest_path(N, M, edges, start, end):\n \"\"\"\n Returns the shortest path from start station to end station in the gi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089431",
"row_id": 89431,
"seed_ids": "[21004]"
} | 0.735556 | Taco_89431 | I | [
"shortest_path_monorail",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path_monorail"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e9906cc9e5e2cbbe4a374a90d7de2709f042d0bd | afea1b818083bcd352b5d9de44133ad862902f30 | |||
v1.0 | instruct | Taco | Taco_89440_I | A tech company wants to conduct reliable data transfers between two systems and asks you to write a program to determine the longest reliable data transfer path. A data transfer network is represented as an undirected graph where nodes represent devices, and edges represent the direct reliable connections between them.... | def find_longest_path(graph, n):
def dfs(node, visited):
visited[node] = True
max_depth = 0
for neighbor in graph[node]:
if not visited[neighbor]:
path_length = dfs(neighbor, visited)
max_depth = max(max_depth, path_length)
visited[node] = ... | from solution import longest_reliable_path
def test_case_1():
T = 1
test_cases = [
(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)])
]
assert longest_reliable_path(T, test_cases) == [4]
def test_case_2():
T = 1
test_cases = [
(3, 1, [(1, 2)])
]
assert longest_reliable_path(T, te... | [
{
"docstring": null,
"function_declaration": "def find_longest_path(graph, n):",
"function_name": "find_longest_path",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def longest_reliable_path(T, test_cases):",
"function_name": "longest_reliable_path",... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_path(graph, n):\n def dfs(node, visited):\n visited[node] = True\n max_depth = 0\n for neighbor in graph[node]:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089440",
"row_id": 89440,
"seed_ids": "[11266]"
} | 0.648437 | Taco_89440 | I | [
"find_longest_path",
"longest_reliable_path",
"process_input"
] | 3 | [
[
"longest_reliable_path",
"find_longest_path"
],
[
"process_input",
"longest_reliable_path"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 948aa384d74028bba1ccf374598fd2438a5f747a | d1c3221ec8f14fe11393253ac7ae4a46387478ef | |||
v1.0 | instruct | Taco | Taco_89468_I | Derek loves puzzles involving prime numbers. He recently came up with a new type of puzzle. Given an integer array `arr` of length `N`, he asks you to determine if there exists any subarray (contiguous part of the array) such that the sum of its elements is a prime number.
A prime number is a number greater than 1 tha... | from typing import List
def is_prime(num: int) -> bool:
"""
Determines if a number is a prime number.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
... | from solution import check_prime_subarray
def test_prime_subarray_exists():
assert check_prime_subarray([2, 3, -5, 5, 6]) == "YES"
assert check_prime_subarray([5]) == "YES"
assert check_prime_subarray([3, 7, 1, 2]) == "YES"
def test_no_prime_subarray():
assert check_prime_subarray([4, 6, 8]) == "NO"
... | [
{
"docstring": "Determines if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Checks if there exists any subarray whose sum is a prime number.",
"function_declaration": "def check_prime_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\nimport math\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089468",
"row_id": 89468,
"seed_ids": "[12758]"
} | 0.623585 | Taco_89468 | I | [
"is_prime",
"check_prime_subarray"
] | 2 | [
[
"check_prime_subarray",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1a8451d9b0caafe56f4d341795f7442bd6c9da2 | 33eb614ca9e353ddc86076080ca9c5178a55ca30 | |||
v1.0 | instruct | Taco | Taco_89503_I | Given a string s and a dictionary of words dict, determine if s can be segmented into a sequence of one or more dictionary words. Return all such possible segmentations in any order.
Example 1:
Input: s = "catsanddog", dict = ["cat","cats","and","sand","dog"]
Output: ["cats and dog","cat sand dog"]
Example 2:
Input: ... | def word_break_helper(s, word_dict, start, memo):
if start in memo:
return memo[start]
if start == len(s):
return [""]
segmentations = []
for end in range(start + 1, len(s) + 1):
word = s[start:end]
if word in word_dict:
subsequences = word_break_helper(... | from solution import word_break
def test_example_1():
s = "catsanddog"
word_dict = ["cat", "cats", "and", "sand", "dog"]
output = ["cats and dog", "cat sand dog"]
result = word_break(s, word_dict)
assert sorted(result) == sorted(output)
def test_example_2():
s = "pineapplepenapple"
word_di... | [
{
"docstring": null,
"function_declaration": "def word_break_helper(s, word_dict, start, memo):",
"function_name": "word_break_helper",
"parameter_list": "(s, word_dict, start, memo)"
},
{
"docstring": null,
"function_declaration": "def word_break(s, word_dict):",
"function_name": "w... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def word_break(s, dictionary):\n \"\"\"\n Determine if s can be segmented into a sequence of one or more dictionary words.\n Return all such possible segm... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00089503",
"row_id": 89503,
"seed_ids": "[12701]"
} | 0.652333 | Taco_89503 | I | [
"word_break_helper",
"word_break"
] | 2 | [
[
"word_break",
"word_break_helper"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f195d278d4fdcbb6a28f00ec39ac5b3d36a0c73a | 526cb238c9d0d58ac1c6642df0d7ec18598c58da | |||
v1.0 | instruct | Taco | Taco_89512_I | Write a program that takes an integer `n` as input, finds all the prime numbers less than or equal to `n`, and returns the sum of these prime numbers. A prime number is defined as any number greater than 1 that is not divisible by any number other than 1 and itself.
INPUT
The first line contains an integer `T` which r... | import itertools
def sieve_of_eratosthenes(n):
"""
Implements the Sieve of Eratosthenes algorithm to find all primes up to and
including `n`, and returns a list of these prime numbers.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
fo... | import pytest
from solution import process_input_and_output
def test_sample_input_1():
input_values = [2, 10, 20]
expected_output = [17, 77]
assert process_input_and_output(input_values) == expected_output
def test_small_input():
input_values = [2, 1, 2]
expected_output = [0, 2]
assert process... | [
{
"docstring": "Implements the Sieve of Eratosthenes algorithm to find all primes up to and\nincluding `n`, and returns a list of these prime numbers.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n This function uses the Sieve of Eratosthenes algorithm to find all prime numbers up to n.\n \"\"\"\n is_prime ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089512",
"row_id": 89512,
"seed_ids": "[18484]"
} | 0.669735 | Taco_89512 | I | [
"sieve_of_eratosthenes",
"sum_of_primes",
"process_input_and_output"
] | 3 | [
[
"process_input_and_output",
"sum_of_primes"
],
[
"sum_of_primes",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cf3e8d709f8add233d9cf4a299b484eb4e769592 | 806fbcc22263ef161d608acd847f5fae59f545a0 | |||
v1.0 | instruct | Taco | Taco_89582_I | Anna is studying prime numbers and their interesting properties. She comes across a unique problem related to prime numbers and their divisors. She wants to write a program to solve this problem but needs your help to do so.
You need to calculate the sum of all proper divisors of a given integer `n`, where a proper di... | def sum_of_proper_divisors(n):
"""
Calculate the sum of all proper divisors of n.
"""
if n <= 1:
return 0
divisors_sum = 1
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
divisors_sum += i
if i != n // i:
divisors_sum += n // i
retur... | import pytest
from solution import sum_of_proper_divisors, is_prime, process_test_cases
def test_sum_of_proper_divisors():
assert sum_of_proper_divisors(6) == 6
assert sum_of_proper_divisors(28) == 28
assert sum_of_proper_divisors(9) == 4
assert sum_of_proper_divisors(12) == 16
assert sum_of_proper... | [
{
"docstring": "Calculate the sum of all proper divisors of n.",
"function_declaration": "def sum_of_proper_divisors(n):",
"function_name": "sum_of_proper_divisors",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_proper_divisors(n):\n \"\"\"\n Calculate the sum of all proper divisors of n.\n \"\"\"\n proper_divisors_sum = 1 # 1 is always a proper div... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089582",
"row_id": 89582,
"seed_ids": "[3909]"
} | 0.658055 | Taco_89582 | I | [
"sum_of_proper_divisors",
"is_prime",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"is_prime"
],
[
"process_test_cases",
"sum_of_proper_divisors"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | eb65105932f536a077ff7a08c29673d3bb3d69a6 | 5f90da0aa11d0e9e8966c6c42777eeded3c97a80 | |||
v1.0 | instruct | Taco | Taco_89583_I | **Problem Statement**
Henry loves collecting and organizing unique antique items. He has a database of items, where each item is described by a unique identification number and a few characteristics. Henry wants to organize the items into different collections based on their characteristics. In particular, he wants to... | def can_partition(items, K):
from itertools import combinations
def check_no_overlap(items):
seen = set()
for item in items:
if any(char in seen for char in item[1:]):
return False
seen.update(item[1:])
return True
N = len(items)
if N... | from solution import partition_items
def test_partition_impossible():
N = 5
C = 3
items_data = [
"1 1 2 3",
"2 2 3 4",
"3 1 3 4",
"4 5 6 7",
"5 4 5 6"
]
K = 2
assert partition_items(N, C, items_data, K) == "impossible"
def test_partition_possible():
... | [
{
"docstring": null,
"function_declaration": "def can_partition(items, K):",
"function_name": "can_partition",
"parameter_list": "(items, K)"
},
{
"docstring": null,
"function_declaration": "def partition_items(N, C, items_data, K):",
"function_name": "partition_items",
"paramete... | [
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 partition_collections(N, C, items, K):\n \"\"\"\n Organize the items into collections of size K such that no items\n in the same collection share any ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00089583",
"row_id": 89583,
"seed_ids": "[14700]"
} | 0.625511 | Taco_89583 | I | [
"can_partition",
"partition_items"
] | 2 | [
[
"partition_items",
"can_partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f8340554046febd8be7009f5cfa576449adba035 | 7172c4824ce1cd5ea5f3c2e86429a0798adc2267 | |||
v1.0 | instruct | Taco | Taco_89605_I | You have a grid of size $n \times m$ where each cell can either be empty or contain a coin. The grid is initially given in such a way where each cell contains a number: $0$ for empty and $1$ for containing a coin. Your task is to pick up the coins while adhering to the following rules:
1. You start from any cell that ... | def dfs(grid, i, j, n, m, visited):
if i < 0 or i >= n or j < 0 or j >= m or grid[i][j] == 0 or visited[i][j]:
return 0
visited[i][j] = True
count = 1
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for direction in directions:
count += dfs(grid, i + direction[0], j + direction[1],... | def test_basic_case():
t = 2
test_cases = [
(3, 3, [
[1, 1, 0],
[1, 0, 1],
[0, 1, 1]
]),
(2, 2, [
[1, 1],
[1, 1]
])
]
assert max_coins_collected(t, test_cases) == [3, 4]
def test_single_row():
t = 1
test... | [
{
"docstring": null,
"function_declaration": "def dfs(grid, i, j, n, m, visited):",
"function_name": "dfs",
"parameter_list": "(grid, i, j, n, m, visited)"
},
{
"docstring": null,
"function_declaration": "def max_coins_collected(t, test_cases):",
"function_name": "max_coins_collected... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dfs(grid, i, j, n, m, visited):\n if i < 0 or i >= n or j < 0 or j >= m or grid[i][j] == 0 or visited[i][j]:\n return 0\n\n visited[i][j] = True\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089605",
"row_id": 89605,
"seed_ids": "[16211]"
} | 0.716422 | Taco_89605 | I | [
"dfs",
"max_coins_collected"
] | 2 | [
[
"max_coins_collected",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | caee28436aed9ea4f0bbf1655b062360754288e9 | 8e73309458c3c04a1d9183d658a07304387bc8fb | |||
v1.0 | instruct | Taco | Taco_89693_I | Emilia loves solving problems involving arrays and sequence manipulation. She's designed a special sequence transformation algorithm and needs your help to implement it.
Given an integer array `arr`, Emilia's algorithm finds the longest contiguous subarray where all elements are of the same value, and then it compress... | def reduce_array(arr):
n = len(arr)
reduced_arr = []
i = 0
while i < n:
current_value = arr[i]
j = i
while j < n and arr[j] == current_value:
j += 1
reduced_arr.append(current_value)
i = j
return reduced_arr
def emilias_algorithm(T, ... | from solution import reduce_array, emilias_algorithm
def test_reduce_array():
assert reduce_array([1, 1, 2, 2, 2, 3, 3]) == [1, 2, 3]
assert reduce_array([4, 4, 4, 4, 4]) == [4]
assert reduce_array([1, 1, 2, 3, 3, 3, 2, 2]) == [1, 2, 3, 2]
def test_emilias_algorithm():
test_cases = [
(7, [1, 1... | [
{
"docstring": null,
"function_declaration": "def reduce_array(arr):",
"function_name": "reduce_array",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def emilias_algorithm(T, test_cases):",
"function_name": "emilias_algorithm",
"parameter_list": "(T, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compress_sequence(arr):\n \"\"\"\n Compresses the array by collapsing longest contiguous subarrays of the same value.\n The process is repeated until ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089693",
"row_id": 89693,
"seed_ids": "[13506]"
} | 0.662442 | Taco_89693 | I | [
"reduce_array",
"emilias_algorithm"
] | 2 | [
[
"emilias_algorithm",
"reduce_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0207ff9d54b3faf37d673d316c3ff61008fc6eb1 | 6ed15ddba2edfabf2f527851c7e4205b4556124d | |||
v1.0 | instruct | Taco | Taco_89740_I | Given an infinite sequence of positive integers defined as follows:
Each element $a_n$ of the sequence is computed as the sum of the squares of the digits of $a_{n-1}$. The sequence starts with a given positive integer $a_0$.
If $a_0$ has only one digit, then $a_1$ can be directly computed. For an integer with more th... | def sum_of_squares_of_digits(n):
"""
Compute the sum of the squares of the digits of the number n.
"""
return sum(int(digit)**2 for digit in str(n))
def reaches_one_within_k_steps(a0, K):
"""
Determine if the sequence starting from a0 reaches 1 within K steps.
"""
for _ in range(K):
... | from solution import sum_of_squares_of_digits, reaches_one_within_k_steps, solution
def test_sum_of_squares_of_digits():
assert sum_of_squares_of_digits(19) == 1**2 + 9**2
assert sum_of_squares_of_digits(82) == 8**2 + 2**2
assert sum_of_squares_of_digits(100) == 1**2 + 0**2 + 0**2
def test_reaches_one_wit... | [
{
"docstring": "Compute the sum of the squares of the digits of the number n.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Determine if the sequence starting from a0 reaches 1 within K st... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_squares_of_digits(n):\n \"\"\"\n Compute the sum of the squares of the digits of the number n.\n \"\"\"\n return sum(int(digit)**2 for digit... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089740",
"row_id": 89740,
"seed_ids": "[3954]"
} | 0.67974 | Taco_89740 | I | [
"sum_of_squares_of_digits",
"reaches_one_within_k_steps",
"solution",
"main"
] | 4 | [
[
"reaches_one_within_k_steps",
"sum_of_squares_of_digits"
],
[
"solution",
"reaches_one_within_k_steps"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2cc8b0eba2974fb84dacaee5be5cb4c28bc722a0 | c809563a24d504b4c3f35262d758cb8e10607096 | |||
v1.0 | instruct | Taco | Taco_89824_I | In this Kata, you will be given an integer `n`, and your task is to find a pair of prime numbers such that their sum is equal to `n`. If multiple such pairs exist, return the pair with the smallest difference, and if there are still multiple pairs with the same difference, return the pair where the smaller prime number... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def solve(n):
primes = [i ... | from solution import solve
def test_solve():
assert solve(10) == [5, 5], "Expected [5, 5] for input 10"
assert solve(12) == [5, 7], "Expected [5, 7] for input 12"
assert solve(4) == [2, 2], "Expected [2, 2] for input 4"
assert solve(8) == [3, 5], "Expected [3, 5] for input 8"
assert solve(20) == [7... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def solve(n):",
"function_name": "solve",
"parameter_list": "(n)"
}
] | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00089824",
"row_id": 89824,
"seed_ids": "[14156]"
} | 0.768404 | Taco_89824 | I | [
"is_prime",
"solve"
] | 2 | [
[
"solve",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 41ff91d867c57b8c88894252e59a1fea65634729 | 84f81c896066a67470bff69a2d51d012bc91f23e | |||
v1.0 | instruct | Taco | Taco_89857_I | You are given a list of integers nums. Your task is to find the largest integer in the list which is a perfect square whose digit sum (sum of its digits) is a prime number. If no such integer exists, return -1.
Example 1:
Input: nums = [16, 25, 36, 49, 50]
Output: 49
Explanation:
16 -> digit sum = 1 + 6 = 7 (prime)
25... | import math
def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import largest_square_with_prime_digit_sum
def test_example_case():
assert largest_square_with_prime_digit_sum([16, 25, 36, 49, 50]) == 49
def test_single_element_prime_digit_sum():
assert largest_square_with_prime_digit_sum([49]) == 49
assert largest_square_with_prime_digit_sum([25]) == 25
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the sum of digits of a number.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
... | [
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_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n < 2:\n return False\n for i in range(2, int(math.sqrt(n)) + 1):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00089857",
"row_id": 89857,
"seed_ids": "[388]"
} | 0.607893 | Taco_89857 | I | [
"is_prime",
"digit_sum",
"largest_square_with_prime_digit_sum"
] | 3 | [
[
"largest_square_with_prime_digit_sum",
"digit_sum"
],
[
"largest_square_with_prime_digit_sum",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7fb16cfbf8c560eb8767b72b19602f87ce768191 | 60be43ae32b7c5fb239179a0294d213c46a4ba35 | |||
v1.0 | instruct | Taco | Taco_89922_I | Dexter is planning to conduct a robot simulation contest in his university. The contest involves navigating multiple robots through a grid and ensuring they don't collide with each other. Each robot follows a fixed path from its initial starting point to its destination and moves either horizontally or vertically. The ... | def will_collide(path1, path2):
"""
Determines if two paths will collide.
"""
# Unpack the points
x1_start, y1_start, x1_end, y1_end = path1
x2_start, y2_start, x2_end, y2_end = path2
# Generate all points in path 1
points1 = set()
if x1_start == x1_end: # Vertical line
for... | from solution import will_collide, count_non_colliding_pairs
def test_will_collide_simple_cases():
assert will_collide((1, 2, 1, 5), (2, 3, 5, 3)) == False
assert will_collide((1, 2, 1, 5), (4, 4, 4, 1)) == False
assert will_collide((1, 2, 1, 5), (1, 0, 1, 2)) == True
def test_will_collide_intersecting_pa... | [
{
"docstring": "Determines if two paths will collide.",
"function_declaration": "def will_collide(path1, path2):",
"function_name": "will_collide",
"parameter_list": "(path1, path2)"
},
{
"docstring": null,
"function_declaration": "def count_non_colliding_pairs(test_cases):",
"functi... | [
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 will_collide(path1, path2):\n \"\"\"\n Determines if two paths will collide.\n \"\"\"\n # Unpack the points\n x1_start, y1_start, x1_end, y1_end... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00089922",
"row_id": 89922,
"seed_ids": "[1418]"
} | 0.644116 | Taco_89922 | I | [
"will_collide",
"count_non_colliding_pairs",
"main"
] | 3 | [
[
"count_non_colliding_pairs",
"will_collide"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 601475cc655e2a3f05a8817bc37db676bd7819fd | 76fdd9471c589bca0e0514d3dcd7f2cde27c8cf2 | |||
v1.0 | instruct | Taco | Taco_89941_I | In a magical kingdom, there is a prestigious tournament of knights. Each knight can have a unique strength level represented by an integer. The king organizes them such that the knights stand in a line, and each knight must be stronger than the knight directly to their left or right. For a given list of knights' streng... | from itertools import permutations
def is_valid_arrangement(perm):
"""
Check if a given permutation is a valid arrangement where each knight
is stronger than the knight directly next to them.
"""
for i in range(len(perm) - 1):
if abs(perm[i] - perm[i + 1]) != 1:
return False
... | from solution import knight_arrangements
def test_sample_input_1():
result = knight_arrangements([3, 1, 2])
expected = [[1, 2, 3], [3, 2, 1]]
assert result == expected
def test_sample_input_2():
result = knight_arrangements([4, 3, 2, 1])
expected = [[1, 2, 3, 4], [4, 3, 2, 1]]
assert result ==... | [
{
"docstring": "Check if a given permutation is a valid arrangement where each knight\nis stronger than the knight directly next to them.",
"function_declaration": "def is_valid_arrangement(perm):",
"function_name": "is_valid_arrangement",
"parameter_list": "(perm)"
},
{
"docstring": "Given ... | [
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": "from itertools import permutations\n\ndef is_valid(arrangement):\n \"\"\"\n Checks if the arrangement satisfies the condition where each knight is stronger\n... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00089941",
"row_id": 89941,
"seed_ids": "[8795]"
} | 0.581206 | Taco_89941 | I | [
"is_valid_arrangement",
"knight_arrangements"
] | 2 | [
[
"knight_arrangements",
"is_valid_arrangement"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a427467c4bb6793019512e419abd708c9b1d710 | cf92c2fcc1066278bb767092f0c1511c707cdd5f | |||
v1.0 | instruct | Taco | Taco_89950_I | A company has introduced a new policy for managing employee tasks efficiently. There are 'T' tasks in total, and each task is assigned to one of the 'N' employees. Each task has a priority level represented by a positive integer, and each employee can handle only one task at a time.
If a task assigned to an employee i... | def process_tasks(test_cases):
results = []
for case in test_cases:
tasks = sorted(case[1:], key=lambda x: x[2]) # Sort by priority level
results.append(' '.join([task[1] for task in tasks]))
return results
def parse_input(input_string):
lines = input_string.strip().split("\n")
ind... | def test_parse_input():
input_string = """3
A X 5
B Y 2
C Z 1
0"""
expected_output = [
[3, ('A', 'X', 5), ('B', 'Y', 2), ('C', 'Z', 1)]
]
assert parse_input(input_string) == expected_output
def test_process_tasks():
test_cases = [
[3, ('A', 'X', 5), ('B', 'Y', 2), ('C', 'Z... | [
{
"docstring": null,
"function_declaration": "def process_tasks(test_cases):",
"function_name": "process_tasks",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter_list": "(... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def process_tasks(test_cases):\n results = []\n \n for tasks in test_cases:\n # Sort tasks by their priority level; as we need ascending order of p... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089950",
"row_id": 89950,
"seed_ids": "[17441]"
} | 0.615927 | Taco_89950 | I | [
"process_tasks",
"parse_input",
"task_management"
] | 3 | [
[
"task_management",
"parse_input"
],
[
"task_management",
"process_tasks"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | b4ef92c8512eaf05044fdce769ff280eaab1d212 | 9ccce6ba8b371357e71a1b73b8849e4d4d70447d | |||
v1.0 | instruct | Taco | Taco_89959_I | Leo is fascinated with prime numbers and often likes to play with them. Recently he discovered something interesting: median prime numbers.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The median of a list of numbers is the middle number when the numbers are ... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
def find_median_prime(n, sequence):
primes = [num for num in seque... | from solution import find_median_prime
def test_no_primes():
assert find_median_prime(4, [4, 6, 8, 10]) == -1
def test_all_primes():
assert find_median_prime(5, [3, 5, 7, 11, 13]) == 7
def test_some_primes():
assert find_median_prime(5, [3, 5, 12, 7, 14]) == 5
def test_one_prime():
assert find_media... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_median_prime(n, sequence):",
"function_name": "find_median_prime",
"parameter_list": "(n, sequence)"... | [
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 math\n\ndef is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00089959",
"row_id": 89959,
"seed_ids": "[16195]"
} | 0.58741 | Taco_89959 | I | [
"is_prime",
"find_median_prime"
] | 2 | [
[
"find_median_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2c81c3e72a900d3dd05e03406b7397a3ab0ea35 | a0f7f1edafc1f343db78165bf08b4c11057e327d | |||
v1.0 | instruct | Taco | Taco_89989_I | You are given a list of strings, each representing a binary number (i.e., strings of '0's and '1's). Your task is to group these binary numbers based on their Hamming distance from each other and return the number of groups formed. Two binary numbers are considered to be in the same group if their Hamming distance is l... | from typing import List
def hamming_distance(str1: str, str2: str) -> int:
"""
Calculate the Hamming distance between two binary strings.
"""
return sum(c1 != c2 for c1, c2 in zip(str1, str2))
def count_hamming_groups(binaries: List[str]) -> int:
"""
Group the binary numbers based on their Ham... | from solution import count_hamming_groups
def test_count_hamming_groups_single_group():
binaries = ["10100", "00100", "10110", "11100", "11011"]
assert count_hamming_groups(binaries) == 2
def test_count_hamming_groups_complex_case():
binaries = ["000", "001", "011", "100"]
assert count_hamming_gro... | [
{
"docstring": "Calculate the Hamming distance between two binary strings.",
"function_declaration": "def hamming_distance(str1, str2):",
"function_name": "hamming_distance",
"parameter_list": "(str1, str2)"
},
{
"docstring": "Group the binary numbers based on their Hamming distance and retu... | [
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 typing import List\n\ndef hamming_distance(a: str, b: str) -> int:\n \"\"\"\n Calculate the Hamming distance between two binary strings.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00089989",
"row_id": 89989,
"seed_ids": "[8605]"
} | 0.650957 | Taco_89989 | I | [
"hamming_distance",
"count_hamming_groups"
] | 2 | [
[
"count_hamming_groups",
"hamming_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 78132dffa800b159db5ca8e211c07bcab4a3945d | 51ef13cbebb50699e6298d50f8e6248d5e6015d4 | |||
v1.0 | instruct | Taco | Taco_90026_I | You are given an integer array `nums` of length `n`, and an integer `k` representing the number of steps to shift each element in the array to its right.
Write a function that performs this right rotation in place, meaning the array should be modified without using additional space for another array. The function shou... | from typing import List
def rotate_array(nums: List[int], k: int) -> List[int]:
"""
Rotates the elements of the array `nums` to the right by `k` steps.
Args:
nums (List[int]): List of integers to rotate.
k (int): Number of steps to rotate the array.
Returns:
List[int]: The rotated... | def test_rotate_array_basic():
assert rotate_array([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3]
def test_rotate_array_with_zero():
assert rotate_array([1, 2, 3, 4, 5], 0) == [1, 2, 3, 4, 5]
def test_rotate_array_k_greater_than_length():
assert rotate_array([1, 2, 3, 4, 5], 7) == [4, 5, 1, 2, 3]
def test_rotate... | [
{
"docstring": "Rotates the elements of the array `nums` to the right by `k` steps.\n\nArgs:\nnums (List[int]): List of integers to rotate.\nk (int): Number of steps to rotate the array.\n\nReturns:\nList[int]: The rotated array.",
"function_declaration": "def rotate_array(nums, k):",
"function_name": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef rotate_array(nums: List[int], k: int) -> List[int]:\n \"\"\"\n Rotates the elements of the array `nums` to the right by `k` st... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00090026",
"row_id": 90026,
"seed_ids": "[22670]"
} | 0.670887 | Taco_90026 | I | [
"rotate_array",
"reverse"
] | 2 | [
[
"rotate_array",
"reverse"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 537569294a6b0caac1cc94f5ae46f89952f732ad | 3f47707d8d9ec694c4b2de0a5b311fbefd9fcb55 | |||
v1.0 | instruct | Taco | Taco_90034_I | Miranda is interested in creating a new art installation for a city park. The installation consists of placing art pieces on several trees distributed throughout the park. The park can be viewed as a grid with R rows and C columns, where each cell contains either a tree ('T') or an empty space ('.'). Miranda needs to p... | from itertools import combinations
import math
def is_valid_distance(x1, y1, x2, y2, D):
"""Check if distance between two points (x1, y1) and (x2, y2) is at least D."""
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) >= D
def can_place_art_pieces(grid, R, C, K, D):
# Collect all positions of 'T'
tre... | from solution import art_installation
def test_art_installation_example_case():
R, C, K = 5, 5, 3
park_grid = [
"T.T..",
".TT.T",
".....",
".T.T.",
"TTTTT"
]
D = 2
assert art_installation(R, C, K, park_grid, D) == "YES"
def test_art_installation_no_solution(... | [
{
"docstring": "Check if distance between two points (x1, y1) and (x2, y2) is at least D.",
"function_declaration": "def is_valid_distance(x1, y1, x2, y2, D):",
"function_name": "is_valid_distance",
"parameter_list": "(x1, y1, x2, y2, D)"
},
{
"docstring": null,
"function_declaration": "... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom itertools import combinations\n\ndef can_place_art_pieces(R, C, K, park, D):\n trees = [(i, j) for i in range(R) for j in range(C) if park[i][... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090034",
"row_id": 90034,
"seed_ids": "[13776]"
} | 0.68187 | Taco_90034 | I | [
"is_valid_distance",
"can_place_art_pieces",
"art_installation"
] | 3 | [
[
"art_installation",
"can_place_art_pieces"
],
[
"can_place_art_pieces",
"is_valid_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c7b57383658b00f6857fecd38475baf34e13eeb9 | 4cdd2f1bd66f54e2b7b80f4591690d49ff97c1c5 | |||
v1.0 | instruct | Taco | Taco_90101_I | You are given a list of `n` distinct integers and a positive integer `k`. Your task is to implement a function `find_kth_largest(nums, k)` that returns the `k`-th largest element in the list.
The list is not necessarily sorted, and you should aim for an efficient algorithm with a time complexity better than `O(n log n... | import random
def quick_select(nums, low, high, k):
pivot = nums[high]
i = low
for j in range(low, high):
if nums[j] > pivot:
nums[i], nums[j] = nums[j], nums[i]
i += 1
nums[i], nums[high] = nums[high], nums[i]
if i == k:
return nums[i]
elif i < k:
... | from solution import find_kth_largest
def test_find_kth_largest_example1():
assert find_kth_largest([3, 2, 1, 5, 6, 4], 2) == 5
def test_find_kth_largest_example2():
assert find_kth_largest([7, 10, 4, 3, 20, 15], 3) == 10
def test_find_kth_largest_example3():
assert find_kth_largest([50, 30, 20, 70, 60],... | [
{
"docstring": null,
"function_declaration": "def quick_select(nums, low, high, k):",
"function_name": "quick_select",
"parameter_list": "(nums, low, high, k)"
},
{
"docstring": null,
"function_declaration": "def find_kth_largest(nums, k):",
"function_name": "find_kth_largest",
"... | [
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 find_kth_largest(nums, k):\n \"\"\"\n Returns the k-th largest element in the given list of distinct integers.\n \"\"\"\n heap = nu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090101",
"row_id": 90101,
"seed_ids": "[1836]"
} | 0.777466 | Taco_90101 | I | [
"quick_select",
"find_kth_largest"
] | 2 | [
[
"find_kth_largest",
"quick_select"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cbc99100404261db13d0854a0a6fc46c05348ae5 | edfef9515f2c7ba993a9c6f45705a2f01550726a | |||
v1.0 | instruct | Taco | Taco_90109_I | On a distant planet called Zog, a local engineer named Zark is trying to set up a communication network between cities. The planet has $ P $ cities numbered from $ 1 $ to $ P $, and there are $ Q $ possible cables that Zark can use to connect these cities. Each cable can connect city $ a $ to city $ b $ with latency $ ... | def find(parent, i):
if parent[i] == i:
return i
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
... | from solution import minimum_maximum_latency
def test_example_1():
P = 4
Q = 5
connections = [
(1, 2, 3),
(1, 3, 5),
(2, 3, 4),
(2, 4, 8),
(3, 4, 2)
]
assert minimum_maximum_latency(P, Q, connections) == 4
def test_single_edge():
P = 2
Q = 1
conn... | [
{
"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": "# Function to find the parent of an element\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\n#... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00090109",
"row_id": 90109,
"seed_ids": "[23759]"
} | 0.673955 | Taco_90109 | I | [
"find",
"union",
"minimum_maximum_latency",
"main"
] | 4 | [
[
"minimum_maximum_latency",
"find"
],
[
"minimum_maximum_latency",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 6f6014e83fe146fa01f537214f7c621948046d11 | a4df7feda991aaed49b2b3a5b2c5f75be639c75f | |||
v1.0 | instruct | Taco | Taco_90111_I | You are given an integer array $A$ of length $n$. Your task is to find the maximum length of a subarray where every element is divisible by at least one prime number in the range $[m, p]$.
A subarray is a contiguous part of an array.
Consider the following example for clarity.
-----Input-----
The first line conta... | from math import isqrt
def sieve_of_eratosthenes(max_num):
"""
Computes prime numbers up to max_num using the Sieve of Eratosthenes.
"""
sieve = [True] * (max_num + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers
for start in range(2, isqrt(max_num) + 1):
if sieve[start]... | import pytest
from solution import solve
def test_example_1():
t = 2
test_cases = [
(6, 2, 5, [6, 10, 15, 20, 25, 30]),
(5, 3, 7, [14, 21, 28, 35, 42]),
]
results = solve(t, test_cases)
assert results == [6, 5]
def test_edge_case_no_primes():
t = 1
test_cases = [
(4... | [
{
"docstring": "Computes prime numbers up to max_num using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Finds all prime numbers in the range [m, 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 sieve_of_eratosthenes(max_num):\n \"\"\" Helper function to generate a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm. \"\"\"... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00090111",
"row_id": 90111,
"seed_ids": "[3701]"
} | 0.757528 | Taco_90111 | I | [
"sieve_of_eratosthenes",
"primes_in_range",
"max_subarray_length_divisible_by_primes",
"solve"
] | 4 | [
[
"max_subarray_length_divisible_by_primes",
"primes_in_range"
],
[
"primes_in_range",
"sieve_of_eratosthenes"
],
[
"solve",
"max_subarray_length_divisible_by_primes"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 10610fc9293f6a8fdd0a8fd4c83819c1b26c77fc | eca3bcb6fbbac95ae465a2402e7ba656f71c2b28 | |||
v1.0 | instruct | Taco | Taco_90132_I | Write a function that determines whether a given list of integers is a list where every element is either 1 or a prime number. The function should take one argument, which is a list of integers, and return a boolean value.
The function should return `True` if every element in the list is either 1 or a prime number, a... | def is_prime(n):
"""
Helper function to determine if a given number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def a... | from solution import all_1_or_prime
def test_all_1_or_prime():
assert all_1_or_prime([1, 2, 3, 5, 7]) == True
assert all_1_or_prime([1, 2, 3, 4]) == False
assert all_1_or_prime([1, 1, 1]) == True
assert all_1_or_prime([2, 3, 5, 7, 11]) == True
assert all_1_or_prime([1, 2, 3, 4, 6]) == False
ass... | [
{
"docstring": "Helper function to determine if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determines whether every element in the list is either 1 or a prime number.",
"function_declara... | [
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 determine if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00090132",
"row_id": 90132,
"seed_ids": "[23038]"
} | 0.705646 | Taco_90132 | I | [
"is_prime",
"all_1_or_prime"
] | 2 | [
[
"all_1_or_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b2ff269370eb30aeb203cb0e0a628fe4f7c55fdc | fc837753330d4ab2ddc5f08b94b148467df1f3a1 | |||
v1.0 | instruct | Taco | Taco_90139_I | You are given a binary tree with n nodes. Each node in the tree has a positive integer value. You need to answer several queries about the tree. Each query can be one of the following types:
* Increment all node values in a specific subtree by a given value.
* Find the maximum value in a specific subtree.
To make it ... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def increment_subtree(node, inc):
if node:
node.value += inc
for child in node.children:
increment_subtree(child, inc)
def find_max_in_subtree(node):
if not node:
return flo... | import pytest
from solution import TreeNode, increment_subtree, find_max_in_subtree, solve_tree_problem
def test_increment_subtree():
node = TreeNode(1)
child1 = TreeNode(2)
child2 = TreeNode(3)
node.children = [child1, child2]
increment_subtree(node, 2)
assert node.value == 3
assert c... | [] | [
0,
0,
1,
0
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def solve_tree_queries(n, node_values, edges, queries):\n from collections import defaultdict, deque\n \n # Build the tree adjace... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00090139",
"row_id": 90139,
"seed_ids": "[9988]"
} | 0.60429 | Taco_90139 | I | [
"increment_subtree",
"find_max_in_subtree",
"solve_tree_problem"
] | 3 | [
[
"solve_tree_problem",
"find_max_in_subtree"
],
[
"solve_tree_problem",
"increment_subtree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | ccc176ca0a39bf2ed033a896d8bbe16686deaced | 6958e3c9692f0922dd14ae18eafab48d29a28e3a | |||
v1.0 | instruct | Taco | Taco_90161_I | Implement a function that takes a list of strings and returns a new list with all the strings that are palindromes. A palindrome is a word or phrase that reads the same forward and backward, ignoring spaces, punctuation, and case.
```python
def find_palindromes(words):
# Your code here
# Examples:
print(find_pali... | def is_palindrome(s):
"""
Helper function to check if a given string s is a palindrome
"""
# Remove non-alphanumeric characters and convert to lowercase
normalized_s = ''.join(char.lower() for char in s if char.isalnum())
return normalized_s == normalized_s[::-1]
def find_palindromes(words):
... | from solution import find_palindromes, is_palindrome
def test_is_palindrome():
assert is_palindrome('racecar') == True
assert is_palindrome('hello') == False
assert is_palindrome('A Santa at NASA') == True
assert is_palindrome('No lemon, no melon') == True
assert is_palindrome('world') == False
de... | [
{
"docstring": "Helper function to check if a given string s is a palindrome",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns a list of strings from the input list that are palindromes.",
"function_dec... | [
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_palindromes(words):\n \"\"\"\n Returns a list of palindromes from the input list of words.\n \"\"\"\n def is_palindrome(word):\n # Remo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090161",
"row_id": 90161,
"seed_ids": "[3951]"
} | 0.752079 | Taco_90161 | I | [
"is_palindrome",
"find_palindromes"
] | 2 | [
[
"find_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61f80670509f28f6b43855133ea21c9d383b6cb0 | 5cd8db45b76de49dfcf75993e3037ddf44845ee8 | |||
v1.0 | instruct | Taco | Taco_90181_I | In a secluded village, there is a map consisting of N houses connected by M bidirectional roads. Each road has a certain toll associated with it. The villagers want to ensure that their village is well connected in such a way that the total toll cost is minimized. As an expert in algorithms, help the villagers to find ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
... | from solution import minTollCost
def test_minTollCost_example1():
N = 4
M = 5
roads = [[1, 2, 5], [1, 3, 10], [2, 3, 7], [2, 4, 4], [3, 4, 3]]
assert minTollCost(N, M, roads) == 12
def test_minTollCost_example2():
N = 3
M = 3
roads = [[1, 2, 2], [2, 3, 3], [1, 3, 4]]
assert minTollCost... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090181",
"row_id": 90181,
"seed_ids": "[8153]"
} | 0.703117 | Taco_90181 | I | [
"find",
"union",
"minTollCost"
] | 3 | [
[
"minTollCost",
"find"
],
[
"minTollCost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 108bafdb99f6634893e4b2999461caf026114bf0 | 8ce229999f2111bf953313557152534c26082ae9 | |||
v1.0 | instruct | Taco | Taco_90226_I | Your company, AeroPath, has been developing an application to assist pilots in determining optimal flight paths. The application needs to account for various air traffic constraints and output a safe and efficient route for the pilots.
One specific problem that needs solving is determining if a flight plan can avoid a... | import math
def is_intersecting_circle(x1, y1, x2, y2, cx, cy, r):
# Translate coordinates so that the circle's center is at the origin
x1, y1, x2, y2 = x1 - cx, y1 - cy, x2 - cx, y2 - cy
dx = x2 - x1
dy = y2 - y1
# Coefficients of the quadratic equation
a = dx ** 2 + dy ** 2
b = ... | from solution import flight_path
def test_no_intersection():
assert flight_path(2, [(15, 15, 5), (25, 25, 5)], 0, 0, 10, 10) == "SAFE"
def test_single_restricted_zone():
assert flight_path(1, [(15, 15, 10)], 0, 0, 30, 30) == "RESTRICTED"
def test_multiple_restricted_zones():
assert flight_path(3, [(10, 1... | [
{
"docstring": null,
"function_declaration": "def is_intersecting_circle(x1, y1, x2, y2, cx, cy, r):",
"function_name": "is_intersecting_circle",
"parameter_list": "(x1, y1, x2, y2, cx, cy, r)"
},
{
"docstring": null,
"function_declaration": "def flight_path(n, restricted_zones, x_s, y_s... | [
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 math\n\ndef is_intersecting_circle(x_center, y_center, radius, x1, y1, x2, y2):\n \"\"\"\n Determine if the line segment from (x1, y1) to (x2, y2) int... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090226",
"row_id": 90226,
"seed_ids": "[25439]"
} | 0.657147 | Taco_90226 | I | [
"is_intersecting_circle",
"flight_path"
] | 2 | [
[
"flight_path",
"is_intersecting_circle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 654765a23a98cb42b66a1c7dca7aadfa3503fc17 | 1187bb629b39c581938af85ef995a3b5996da244 | |||
v1.0 | instruct | Taco | Taco_90239_I | The XYZ Company has launched a special program called "Employee of the Month." For this program, each department selects an employee based on their performance and assigns them points. The company wishes to automate the process of determining the Employee of the Month based on the points given.
You are given a list wh... | def employee_of_the_month(employee_data):
"""
Given a list of employee data tuples (name, department, points),
returns a dictionary with departments as keys and the
employee with the highest points as values.
"""
department_best = {}
for name, department, points in employee_data:
... | from solution import employee_of_the_month, format_employee_of_the_month
def test_basic_case():
employees = [
("Alice", "HR", 88),
("Bob", "IT", 92),
("Charlie", "HR", 90),
("David", "IT", 85),
("Eve", "HR", 88),
("Frank", "IT", 92)
]
result = employee_of_the... | [
{
"docstring": "Given a list of employee data tuples (name, department, points),\nreturns a dictionary with departments as keys and the \nemployee with the highest points as values.",
"function_declaration": "def employee_of_the_month(employee_data):",
"function_name": "employee_of_the_month",
"para... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_employee_of_the_month(employee_data):\n \"\"\"\n Determines the Employee of the Month for each department based on points.\n \"\"\"\n departme... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00090239",
"row_id": 90239,
"seed_ids": "[23277]"
} | 0.627763 | Taco_90239 | I | [
"employee_of_the_month",
"format_employee_of_the_month"
] | 2 | [
[
"format_employee_of_the_month",
"employee_of_the_month"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 305a85adabacc7f9dea3a211316fc8033cc7da6c | 68e9b1e22401d5a015fce375c646c4351097ac65 | |||
v1.0 | instruct | Taco | Taco_90242_I | Problem statement
Given a binary tree, return the vertical order traversal of its nodes' values.
The vertical order traversal of a binary tree is a traversal where we visit all nodes from top to bottom in each vertical column. Columns are ordered from left to right, and nodes in the same column are ordered based on t... | from collections import defaultdict, deque
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(level_order):
"""
Build a binary tree from level order list
"""
if not level_order:
return ... | import pytest
from solution import vertical_order
def test_vertical_order_case1():
input_data = [3, 9, 20, None, None, 15, 7]
expected_output = [
[9],
[3, 15],
[20],
[7]
]
assert vertical_order(input_data) == expected_output
def test_vertical_order_case2():
input_da... | [] | [
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, deque\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = Non... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00090242",
"row_id": 90242,
"seed_ids": "[9283]"
} | 0.653324 | Taco_90242 | I | [
"build_tree",
"verticalOrderTraversal",
"vertical_order"
] | 3 | [
[
"vertical_order",
"build_tree"
],
[
"vertical_order",
"verticalOrderTraversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 6828f533058aa1c64e72ddc1ceb9f17218fb811e | 1cfdc8ff45b2e3e4cc5c7d841db84a8262f67ed6 | |||
v1.0 | instruct | Taco | Taco_90261_I | In a certain state, there are N cities connected by M bidirectional roads. Each road connects two distinct cities A_i and B_i and has a length of C_i. A network of distributors needs to ensure the shortest delivery paths between specific distribution centers. Given P distribution centers, p_1, p_2, ..., p_P (not necess... | def floyd_warshall(n, roads):
# Initialize distance matrix
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for (u, v, w) in roads:
dist[u-1][v-1] = w
dist[v-1][u-1] = w
# Apply Floyd-Warshall
for k in range(n):
for i in range(n):
... | def test_minimum_total_distance_example_1():
N, M, P = 5, 6, 3
distribution_centers = [1, 3, 5]
roads = [
(1, 2, 2),
(2, 3, 3),
(2, 4, 4),
(3, 5, 1),
(4, 5, 6),
(5, 1, 7)
]
assert minimum_total_distance(N, M, P, distribution_centers, roads) == 6
def t... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, roads):",
"function_name": "floyd_warshall",
"parameter_list": "(n, roads)"
},
{
"docstring": null,
"function_declaration": "def minimum_spanning_tree_cost(p_indices, dist):",
"function_name": "minimum_spanning_tree_... | [
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": "import heapq\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n distances[start] = 0\n priority_queue = [(0, start)]\n \n wh... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00090261",
"row_id": 90261,
"seed_ids": "[1526]"
} | 0.752426 | Taco_90261 | I | [
"floyd_warshall",
"minimum_spanning_tree_cost",
"minimum_total_distance"
] | 3 | [
[
"minimum_total_distance",
"floyd_warshall"
],
[
"minimum_total_distance",
"minimum_spanning_tree_cost"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 56dce0a1bd501a55d14cb65a720ae961430954fe | e42b62ca6d7fe12504391a9f4614e315bbf7a9d1 | |||
v1.0 | instruct | Taco | Taco_90304_I | Samantha is practicing her coding skills with some fun number games. She recently learned about a fascinating concept called "self-dividing numbers". A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % ... | def self_dividing_number(num):
"""
Checks if a number is a self-dividing number.
"""
original_num = num
while num > 0:
digit = num % 10
if digit == 0 or original_num % digit != 0:
return False
num //= 10
return True
def self_dividing_numbers(left, right):
... | from solution import self_dividing_number, self_dividing_numbers
def test_self_dividing_number():
assert self_dividing_number(128) == True
assert self_dividing_number(102) == False
assert self_dividing_number(1) == True
assert self_dividing_number(11) == True
assert self_dividing_number(12) == True... | [
{
"docstring": "Checks if a number is a self-dividing number.",
"function_declaration": "def self_dividing_number(num):",
"function_name": "self_dividing_number",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of all self-dividing numbers between left and right, inclusive.",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_self_dividing(number):\n \"\"\"\n Helper function to check if the given number is a self-dividing number.\n \"\"\"\n original_number = number\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00090304",
"row_id": 90304,
"seed_ids": "[5475]"
} | 0.580595 | Taco_90304 | I | [
"self_dividing_number",
"self_dividing_numbers"
] | 2 | [
[
"self_dividing_numbers",
"self_dividing_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9de365b7cc4af7956e230dd00d25eb9fdb80a741 | 2a7ae9f1bfa0e140503253601be4027d63f26c60 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.