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_27406_I | Given a list of integers, find the sum of the prime numbers present in the list.
Input Format
The first line contains $n$, the number of integers in the list. The second line contains an array $\mbox{A}[$ $\mathrm{~l~}$ of $n$ integers each separated by a space.
Constraints
$1\leq n\leq15$
$-100\le A[i]\le100$
... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes(numbers):
"""
Function to return the sum of prime numbers i... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(-5) == False
def test_sum_of_primes():
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to return the sum of prime numbers in the list.",
"function_declaration": "def sum_of_primes(n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if the number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027406",
"row_id": 27406,
"seed_ids": "[5168]"
} | 0.661327 | Taco_27406 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d058359b9465014de18090783d3f99dd3fdd0ca2 | cb1973664dc106a86e6ed68684ff3534b245830d | |||
v1.0 | instruct | Taco | Taco_27410_I | Anna is playing a game with her younger brother where she needs to solve some problems on prime numbers to win. The game consists of different rounds, and in each round, her brother gives her a number, and she needs to determine the sum of all prime numbers less than or equal to that number. Anna is very good at math, ... | def sum_of_primes(n):
"""
Returns the sum of all prime numbers less than or equal to n.
"""
if n < 2:
return 0
# Initialize a list to track prime numbers
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers
for i in range(2, int(n**0.5)... | from solution import sum_of_primes, solve_prime_sums
def test_sum_of_primes():
assert sum_of_primes(10) == 17
assert sum_of_primes(20) == 77
assert sum_of_primes(30) == 129
assert sum_of_primes(2) == 2
assert sum_of_primes(1) == 0
assert sum_of_primes(0) == 0
assert sum_of_primes(100) == 10... | [
{
"docstring": "Returns the sum of all prime numbers less than or equal to n.",
"function_declaration": "def sum_of_primes(n):",
"function_name": "sum_of_primes",
"parameter_list": "(n)"
},
{
"docstring": "Solves the game by calculating the sum of all prime numbers for each provided number.\... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027410",
"row_id": 27410,
"seed_ids": "[18864]"
} | 0.586839 | Taco_27410 | I | [
"sum_of_primes",
"solve_prime_sums"
] | 2 | [
[
"solve_prime_sums",
"sum_of_primes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0278ed84cfb9bcd3a4027b4b75a00095507f30e1 | 5c8a50c636aef16caac7761a01d7edf66622f7dd | |||
v1.0 | instruct | Taco | Taco_27444_I | You are contracted by a logistics company to develop software for optimizing truck cargo loads. The trucks have a maximum weight capacity and a list of items that need to be transported. Each item has a specific weight and value. The goal is to maximize the total value of the items loaded onto the truck without exceedi... | def knapsack(W, N, items):
"""
Solves the 0/1 Knapsack problem.
Args:
W (int): Maximum weight capacity of the truck.
N (int): Number of items.
items (list of tuples): List of items where each item is represented as (weight, value) tuple.
Returns:
int: The maximum total value of items t... | from solution import max_cargo_value
def test_sample_input():
input_str = "50\n3\n10 60\n20 100\n30 120"
assert max_cargo_value(input_str) == 220
def test_no_items():
input_str = "50\n0"
assert max_cargo_value(input_str) == 0
def test_exact_fit():
input_str = "50\n1\n50 100"
assert max_cargo_... | [
{
"docstring": "Solves the 0/1 Knapsack problem.\n\nArgs:\nW (int): Maximum weight capacity of the truck.\nN (int): Number of items.\nitems (list of tuples): List of items where each item is represented as (weight, value) tuple.\n\nReturns:\nint: The maximum total value of items that can be loaded onto the truc... | [
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 knapsack(W, items):\n \"\"\"\n Solves the 0/1 Knapsack problem using dynamic programming.\n \n Parameters:\n W (int): The maximum weight capacit... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00027444",
"row_id": 27444,
"seed_ids": "[13892]"
} | 0.703578 | Taco_27444 | I | [
"knapsack",
"parse_input",
"max_cargo_value"
] | 3 | [
[
"max_cargo_value",
"knapsack"
],
[
"max_cargo_value",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 781da995470cb55bd6ca77601bad6f945a418829 | 26f6777d8fc95f2008db63241515454ff80f7899 | |||
v1.0 | instruct | Taco | Taco_27452_I | In Japan, a custom called "Nengajo" exists, where people send greeting cards for the new year. The Japanese post office delivers these cards precisely on New Year's Day. However, they sort the collected cards in advance, based on a unique 5-digit postal code written on each of them. The postal code follows a format whe... | def count_unique_postal_codes(datasets):
results = []
for dataset in datasets:
unique_codes = set(dataset)
results.append(len(unique_codes))
return results
def process_input(input_string):
lines = input_string.strip().split('\n')
datasets = []
i = 0
while i < len(lines) and ... | from solution import solve, process_input, count_unique_postal_codes
def test_process_input():
input_data = """5
12345
23456
12345
34567
12300
3
00100
00101
00100
#"""
expected_output = [['12345', '23456', '12345', '34567', '12300'], ['00100', '00101', '00100']]
assert process_input(input_data) == expected... | [
{
"docstring": null,
"function_declaration": "def count_unique_postal_codes(datasets):",
"function_name": "count_unique_postal_codes",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_string):",
"function_name": "process_input",
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_unique_postal_codes(input_lines):\n \"\"\"\n Returns a list of integers where each integer represents the number of unique postal codes \n in ea... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00027452",
"row_id": 27452,
"seed_ids": "[16442]"
} | 0.5511 | Taco_27452 | I | [
"count_unique_postal_codes",
"process_input",
"solve"
] | 3 | [
[
"solve",
"count_unique_postal_codes"
],
[
"solve",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c2813036e42773b13e1bdfd7f13f32d7b906b797 | 2ca469a6749dcbff587353113fb61311516b49da | |||
v1.0 | instruct | Taco | Taco_27508_I | Lisa is passionate about numbers and loves to explore interesting properties about them. She is particularly fascinated by numbers that satisfy both of the following conditions:
1. **Perfect square**: A number that can be expressed as the square of an integer.
2. **Perfect cube**: A number that can be expressed as the... | def is_perfect_square(n):
"""
Check if a number is a perfect square.
"""
root = int(n**0.5)
return root * root == n
def is_perfect_cube(n):
"""
Check if a number is a perfect cube.
"""
root = int(n**(1/3))
return root * root * root == n or (root + 1) * (root + 1) * (root + 1) ==... | from solution import is_perfect_square, is_perfect_cube, check_perfect_square_and_cube
def test_is_perfect_square():
assert is_perfect_square(64) == True
assert is_perfect_square(65) == False
assert is_perfect_square(729) == True
assert is_perfect_square(1000) == False
def test_is_perfect_cube():
... | [
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a perfect cube.",
"function_declaration": "def is_perfect_cube(n):",
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_perfect_square(n):\n \"\"\"Check if n is a perfect square.\"\"\"\n root = int(n**0.5) \n return root * root == n\n\ndef is_perfect_cube(n):\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027508",
"row_id": 27508,
"seed_ids": "[9876]"
} | 0.621468 | Taco_27508 | I | [
"is_perfect_square",
"is_perfect_cube",
"check_perfect_square_and_cube"
] | 3 | [
[
"check_perfect_square_and_cube",
"is_perfect_cube"
],
[
"check_perfect_square_and_cube",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dfc6d2db5e4fb919f5093fff4505327dac64e3d2 | 046453b724492b4ad3581e192e03224e7443bcba | |||
v1.0 | instruct | Taco | Taco_27524_I | You are given an undirected graph with N nodes and M edges. Each of the edges has a positive weight. You need to find the minimum spanning tree (MST) of the graph, and then you have to calculate the sum of the degrees of all nodes in the MST.
Input
The first line contains two space-separated integers N and M.
Each of ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] < rank[rootY]:
parent[rootX] = rootY
elif rank[rootX] > rank[rootY]:
... | def test_sum_of_degrees_in_mst_case_1():
N = 4
M = 5
edges = [
(1, 2, 1),
(1, 3, 2),
(1, 4, 3),
(2, 3, 4),
(3, 4, 5)
]
result = sum_of_degrees_in_mst(N, M, edges)
assert result == 6
def test_sum_of_degrees_in_mst_case_2():
N = 3
M = 3
edges = ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = fi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027524",
"row_id": 27524,
"seed_ids": "[11585]"
} | 0.740902 | Taco_27524 | I | [
"find",
"union",
"kruskals_mst",
"sum_of_degrees_in_mst"
] | 4 | [
[
"kruskals_mst",
"find"
],
[
"kruskals_mst",
"union"
],
[
"sum_of_degrees_in_mst",
"kruskals_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 53ff7d8f022e526a8c6d3768b5349a99954c5128 | 088fceafa30b6f7f58d2f9e1a0fb685106b8d70b | |||
v1.0 | instruct | Taco | Taco_27624_I | Create a function that takes a string as input, which is a serialized representation of a binary tree, and reconstructs the binary tree. Each value in the tree is a single digit (0-9), and the serialization format follows preorder traversal where 'null' indicates a missing node.
Input Format:
- The first line contains... | from collections import deque
class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def deserialize(data):
if not data:
return None
nodes = data.split(',')
if nodes[0] == 'null':
return No... | from solution import process_test_cases, deserialize, level_order_traversal
def test_deserialize_and_level_order_traversal():
serialization = "1,2,null,null,3,4,null,null,5,null,null"
root = deserialize(serialization)
assert level_order_traversal(root) == [1, 2, 3, 4, 5]
serialization = "1,null,2,null... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027624",
"row_id": 27624,
"seed_ids": "[13474]"
} | 0.5645 | Taco_27624 | I | [
"deserialize",
"level_order_traversal",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"deserialize"
],
[
"process_test_cases",
"level_order_traversal"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e0464b878aaf31cb4afcbed4ede4ffeea37a6b22 | 5c7ee979b92f36e7a29b86b6c9e0a3ec23023f44 | |||
v1.0 | instruct | Taco | Taco_27762_I | Problem
In a city, a new communication system has been implemented, where information is relayed through a series of communication towers. Each tower can only communicate with another tower that satisfies a specific distance condition.
The city has a total of `N` communication towers, each positioned with a unique co... | import math
from heapq import heappop, heappush
def euclidean_distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def min_communication_links(N, D, coordinates):
edges = []
for i in range(N):
x1, y1 = coordinates[i]
for j in range(i + 1, N):
x2, y2 ... | from solution import solve_problem
def test_case_1():
input_data = "4 5\n0 0\n0 4\n4 0\n4 4\n"
assert solve_problem(input_data) == 3
def test_case_2():
input_data = "3 100\n0 0\n70 70\n140 140\n"
assert solve_problem(input_data) == 2
def test_case_3():
input_data = "3 3\n0 0\n10 0\n20 0\n"
as... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(x1, y1, x2, y2):",
"function_name": "euclidean_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def min_communication_links(N, D, coordinates):",
"function_name": "min... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom heapq import heappop, heappush\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef min_comm_... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00027762",
"row_id": 27762,
"seed_ids": "[23920]"
} | 0.654581 | Taco_27762 | I | [
"euclidean_distance",
"min_communication_links",
"solve_problem"
] | 3 | [
[
"min_communication_links",
"euclidean_distance"
],
[
"solve_problem",
"min_communication_links"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ec5e0e099528eee190cd8b91aea19e2784346a4a | 2404146ceb4983516e59f63fc9ed6cbe6cf8eaf7 | |||
v1.0 | instruct | Taco | Taco_27834_I | Create a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Prime numbers are integers greater than 1 that are only divisible by 1 and themselves.
Your function should adhere to the following rules:
- The input list can contain any integer, including... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_div = int(n**0.5) + 1
for d in range(3, max_div, 2):
if n % d == 0:
return False
return True
def filter_pr... | from solution import filter_primes
def test_filter_primes_are_correct():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_all_large_primes():
assert filter_primes([31, 33, 37, 39, 41, 43, 47]) == [31, 37, 41, 43, 47]
def test_filter_primes_includes_negatives_and_zero(... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters the list and returns only the prime numbers.",
"function_declaration": "def filter_primes(nums):",
"function_name... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def filter_primes(nums):\n \"\"\"\n Filters the prime numbers from the input list of integers.\n\n Parameters:\n nums (list): List of integers.\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027834",
"row_id": 27834,
"seed_ids": "[9921]"
} | 0.658739 | Taco_27834 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3a7db71dcf64e4a7934c5541df9f884992b9f12 | d4233551bfee9ffafc1d34f45c03f897144dccde | |||
v1.0 | instruct | Taco | Taco_27837_I | A secret spy agency has developed a new encrypted communication system. Each message is composed of a sequence of words, and each word is represented by a string of lowercase English letters. In order to decode the messages, agents must apply a specific transformation to each word.
The transformation works as follows:... | def smallest_lexicographic_rotation(word):
"""
Returns the lexicographically smallest rotation of the given word.
"""
concatenated = word + word
smallest_rotation = word
for i in range(1, len(word)):
rotation = concatenated[i:i+len(word)]
if rotation < smallest_rotation:
... | from solution import smallest_lexicographic_rotation, decode_messages
def test_smallest_lexicographic_rotation():
assert smallest_lexicographic_rotation("bca") == "abc"
assert smallest_lexicographic_rotation("zxy") == "xyz"
assert smallest_lexicographic_rotation("abc") == "abc"
assert smallest_lexicogr... | [
{
"docstring": "Returns the lexicographically smallest rotation of the given word.",
"function_declaration": "def smallest_lexicographic_rotation(word):",
"function_name": "smallest_lexicographic_rotation",
"parameter_list": "(word)"
},
{
"docstring": "Given a list of words, return a list wi... | [
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 smallest_lexicographic_rotation(word):\n \"\"\"\n Returns the lexicographically smallest rotation of the given word.\n \"\"\"\n concatenated = word... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00027837",
"row_id": 27837,
"seed_ids": "[14794]"
} | 0.670985 | Taco_27837 | I | [
"smallest_lexicographic_rotation",
"decode_messages"
] | 2 | [
[
"decode_messages",
"smallest_lexicographic_rotation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0364ccf434f7abffe9703ccee6e543056373fec3 | d498d8cff5b9f5d68f6d447c3bb803e4324c9571 | |||
v1.0 | instruct | Taco | Taco_27869_I | A robotics company is designing a delivery system where autonomous robots deliver packages within a building. The building consists of a series of rooms connected by hallways. The number of rooms is represented by N, and the hallways are represented as a matrix where the element at the i-th row and j-th column denotes ... | def floyd_warshall(matrix):
"""
Implements the Floyd-Warshall algorithm to find the shortest paths between all pairs of nodes.
Parameters:
matrix (list of list of int): The adjacency matrix representing the time between rooms.
Returns:
list of list of int: The matrix of the shortest paths betw... | def test_process_input_data():
input_data = [
"3",
"0 2 1000000",
"2 0 3",
"1000000 3 0",
"0 2",
"4",
"0 3 1000000 7",
"3 0 1 8",
"1000000 1 0 1000000",
"7 8 1000000 0",
"0 3",
"-1"
]
expected_output = [5, 7]
... | [
{
"docstring": "Implements the Floyd-Warshall algorithm to find the shortest paths between all pairs of nodes.\n\nParameters:\nmatrix (list of list of int): The adjacency matrix representing the time between rooms.\n\nReturns:\nlist of list of int: The matrix of the shortest paths between all pairs of nodes.",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_shortest_delivery_time(n, hallway_matrix, start, target):\n \"\"\"\n Uses Dijkstra's algorithm to find the shortest path in a graph with non-negativ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00027869",
"row_id": 27869,
"seed_ids": "[2835]"
} | 0.695137 | Taco_27869 | I | [
"floyd_warshall",
"find_shortest_delivery",
"process_input_data"
] | 3 | [
[
"find_shortest_delivery",
"floyd_warshall"
],
[
"process_input_data",
"find_shortest_delivery"
]
] | 2 | [
"process_input_data"
] | false | [] | false | pytest | false | [] | true | f3bfca07f6a7139e230177d35b402bdbc0788b95 | 60856366cc6baf9383a82f4096b626ff4e1c0400 | |||
v1.0 | instruct | Taco | Taco_27881_I | David loves to collect stamps. He has a unique collection of stamps from various countries. His collection consists of N stamps, each with a unique positive integer representing its value. David wants to sort his stamps based on their value in descending order. However, after visiting a stamp show, he purchased a new s... | def find_new_stamp_position(test_cases):
results = []
for test_case in test_cases:
N, stamps, X = test_case
stamps.append(X)
stamps.sort(reverse=True)
position = stamps.index(X) + 1
results.append(position)
return results
def parse_input(input_data):
lines = inpu... | def test_find_new_stamp_position():
input_data = "2\n3\n5 10 3\n4\n4\n8 1 6 2\n5"
expected_output = [3, 3]
assert execute(input_data) == expected_output
def test_all_same_values():
input_data = "1\n3\n5 5 5\n5"
expected_output = [1]
assert execute(input_data) == expected_output
def test_single... | [
{
"docstring": null,
"function_declaration": "def find_new_stamp_position(test_cases):",
"function_name": "find_new_stamp_position",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"p... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_stamp_position(T, test_cases):\n \"\"\"\n For each test case, find the position of the new stamp in the sorted (in descending order) collection.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00027881",
"row_id": 27881,
"seed_ids": "[14575]"
} | 0.635161 | Taco_27881 | I | [
"find_new_stamp_position",
"parse_input",
"execute"
] | 3 | [
[
"execute",
"find_new_stamp_position"
],
[
"execute",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | a0bb61853454c0ef8e2bac84f430755a56d7f83c | b8a69e34201fa5cc67be6dc6bebfa940ec7ac0a3 | |||
v1.0 | instruct | Taco | Taco_28016_I | You've just joined a new project team tasked with working on a file system that closely resembles a Unix-like directory system. The file system you are working on is represented by a tree structure where each node is either a directory or a file. Each directory can contain other directories or files, but files cannot c... | class Node:
def __init__(self, name, is_file=False):
self.name = name
self.is_file = is_file
self.children = {}
def parse_path(path):
# Parses the path into components
if path == '/':
return ['/']
return path.strip('/').split('/')
def find_node(root, path_parts):
# ... | def test_simple_structure():
n = 6
operations = [
"mkdir /a",
"mkdir /a/b",
"mkdir /a/b/c",
"mkfile /a/b/c/file1",
"mkdir /a/b/d",
"move /a/b/c /a/b/d"
]
expected_output = """
/
a
b
d
c
-file1
"""
import io
import sys
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, name, is_file=False):\n self.name = name\n self.is_file = is_file\n self.children = {}\n\nclass FileSystem... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028016",
"row_id": 28016,
"seed_ids": "[25396]"
} | 0.588967 | Taco_28016 | I | [
"parse_path",
"find_node",
"process_operations",
"print_tree",
"process_and_print"
] | 5 | [
[
"process_and_print",
"print_tree"
],
[
"process_and_print",
"process_operations"
],
[
"process_operations",
"find_node"
],
[
"process_operations",
"parse_path"
]
] | 4 | [] | false | [
"Node"
] | true | pytest | false | [] | true | 3ca4ca0dd057cee05201f51fb0ee23ff456cb4cb | 7577c295d0e8c64ddc0f715646ebe42c23a01fd4 | |||
v1.0 | instruct | Taco | Taco_28023_I | A wandering traveler decided to take a journey through a vast and enchanted forest. Along the way, he happened to find a magical map that led him to a golden tree. This tree was extraordinary as it could bear fruits of pure gold! Interestingly, the tree bore golden fruits in a special pattern that intrigued the travele... | MOD = 10**9 + 7
def fib(n, memo={1: 1, 2: 1}):
"""
Compute the nth Fibonacci number modulo 10**9 + 7 using memoization.
"""
if n in memo:
return memo[n]
memo[n] = (fib(n - 1, memo) + fib(n - 2, memo)) % MOD
return memo[n]
def golden_tree_fruits(D, days):
"""
For each day i... | from solution import golden_tree_fruits
def test_single_day():
assert golden_tree_fruits(1, [1]) == [1]
assert golden_tree_fruits(1, [2]) == [1]
def test_multiple_days():
assert golden_tree_fruits(2, [5, 13]) == [5, 233]
assert golden_tree_fruits(3, [3, 7, 10]) == [2, 13, 55]
def test_large_day_v... | [
{
"docstring": "Compute the nth Fibonacci number modulo 10**9 + 7 using memoization.",
"function_declaration": "def fib(n, memo={1: 1, 2: 1}):",
"function_name": "fib",
"parameter_list": "(n, memo={1: 1, 2: 1})"
},
{
"docstring": "For each day in `days`, return the number of golden fruits th... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef matrix_mult(A, B):\n return [[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % MOD,\n (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % MOD]... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028023",
"row_id": 28023,
"seed_ids": "[16095]"
} | 0.580535 | Taco_28023 | I | [
"fib",
"golden_tree_fruits"
] | 2 | [
[
"golden_tree_fruits",
"fib"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b7c88d2c49104b37eda15aac1ad0c38e7b03631a | 67357a9d02bf40c50ab182a9ac722a5dc0490857 | |||
v1.0 | instruct | Taco | Taco_28061_I | The Society of Self-Driving Cars (SSDC) has been testing its fleet in the simulated city of Autoville, which comprises a grid of $N \times N$ intersections. The goal of the tests is to navigate from the top-left corner of the grid to the bottom-right corner using the minimum amount of energy.
To navigate the grid, a c... | import heapq
def min_energy(grid):
N = len(grid)
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
pq = [(0, 0, 0)] # (cost, x, y)
costs = {(0, 0): 0}
while pq:
cost, x, y = heapq.heappop(pq)
if (x, y) == (N-1, N-1):
return cost
for dx, dy i... | from solution import min_energy_from_input
def test_case_1():
raw_input = "3\n1 2 3\n4 5 6\n7 8 9"
assert min_energy_from_input(raw_input) == 8
def test_case_2():
raw_input = "4\n1 3 5 7\n2 4 6 8\n3 5 7 9\n4 6 8 10"
assert min_energy_from_input(raw_input) == 9
def test_case_3():
raw_input = "2\n0... | [
{
"docstring": null,
"function_declaration": "def min_energy(grid):",
"function_name": "min_energy",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(raw_input):",
"function_name": "parse_input",
"parameter_list": "(raw_input)"
},
{
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_energy_required(grid):\n N = len(grid)\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def valid(x, y):\n return ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00028061",
"row_id": 28061,
"seed_ids": "[15999]"
} | 0.654918 | Taco_28061 | I | [
"min_energy",
"parse_input",
"min_energy_from_input"
] | 3 | [
[
"min_energy_from_input",
"min_energy"
],
[
"min_energy_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 2fd0674ddf30134e4b5ce41f1f9af12860ba5403 | 1828a543205a39916c831e8ca1321832d4e77fe6 | |||
v1.0 | instruct | Taco | Taco_28072_I | Alice loves playing with numbers. She often finds the sum of digits of a number amusing. However, sometimes she gets confused when there are multiple numbers. Can you help Alice by writing a program that calculates the sum of digits of each number in a list?
Input:
The first line contains an integer N, denoting the nu... | def sum_of_digits(number):
"""
Returns the sum of the digits of a given number.
"""
return sum(int(digit) for digit in str(number))
def sum_of_digits_in_list(numbers):
"""
Given a list of numbers, returns a list containing the sum of digits of each number.
"""
return [sum_of_digits(numb... | from solution import sum_of_digits, sum_of_digits_in_list
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
assert sum_of_digits(0) == 0
assert sum_of_digits(100000) == 1
def test_sum_of_digits_in_list():
assert sum_of_digi... | [
{
"docstring": "Returns the sum of the digits of a given number.",
"function_declaration": "def sum_of_digits(number):",
"function_name": "sum_of_digits",
"parameter_list": "(number)"
},
{
"docstring": "Given a list of numbers, returns a list containing the sum of digits of each number.",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sum_of_digits_of_list(nums):\n \"\"\"\n Returns a list of the sum of digits of each number in the input list.\n \"\"\"\n r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028072",
"row_id": 28072,
"seed_ids": "[11351]"
} | 0.770432 | Taco_28072 | I | [
"sum_of_digits",
"sum_of_digits_in_list"
] | 2 | [
[
"sum_of_digits_in_list",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c7a2c171fb510638ea2293315ab28722990803d9 | dd378ac07db117ba3476ed918fd7ecf119180a49 | |||
v1.0 | instruct | Taco | Taco_28079_I | A group of friends play a game called "Magic Strings." In this game, each player receives a string containing both alphabetic characters and special characters (such as '!', '@', '#', etc.). The goal is to transform the string into a "magic string" following these rules:
1. All alphabetic characters must be in upperca... | def is_magic_string(input_string):
# Filter out numeric characters and uppercase the alphabetic ones
transformed_string = ''.join([ch.upper() if ch.isalpha() else ch for ch in input_string if not ch.isdigit()])
# Check if the transformed string is a palindrome
if transformed_string == transformed_strin... | from solution import is_magic_string, magic_strings
def test_is_magic_string():
assert is_magic_string("he!l@lo") == "Not Magic"
assert is_magic_string("@123#") == "Not Magic"
assert is_magic_string("Rac#car") == "Magic"
assert is_magic_string("A1!a") == "Magic"
assert is_magic_string("!a!b!a!") ==... | [
{
"docstring": null,
"function_declaration": "def is_magic_string(input_string):",
"function_name": "is_magic_string",
"parameter_list": "(input_string)"
},
{
"docstring": null,
"function_declaration": "def magic_strings(n, strings):",
"function_name": "magic_strings",
"parameter... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic_string(s):\n \"\"\"Determines if a string can be transformed into a magic string.\"\"\"\n # Remove numeric characters\n transformed = ''.join... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028079",
"row_id": 28079,
"seed_ids": "[16099]"
} | 0.66693 | Taco_28079 | I | [
"is_magic_string",
"magic_strings"
] | 2 | [
[
"magic_strings",
"is_magic_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01e6422d3b7a6afcf03d759161d84448d1f10a2e | 47f168fd9c508e77272f519e3f08a1941ed5023f | |||
v1.0 | instruct | Taco | Taco_28100_I | A company wants to give a bonus to its employees based on their years of service and performance rating. The criteria for receiving the bonus are as follows:
- An employee must have at least N years of service.
- The performance rating must be greater than or equal to R.
Given the number of years of service and the p... | def is_eligible_for_bonus(N, R, S):
"""
Determines if an employee is eligible for a bonus based on years of service N,
required ratings R, and service years S.
:param N: Minimum years of service required
:param R: Minimum performance rating required
:param S: Actual years of service of the... | def test_is_eligible_for_bonus():
assert is_eligible_for_bonus(5, 7, 10) == "YES"
assert is_eligible_for_bonus(3, 5, 5) == "YES"
assert is_eligible_for_bonus(10, 8, 12) == "YES"
assert is_eligible_for_bonus(6, 6, 4) == "NO"
assert is_eligible_for_bonus(10, 5, 9) == "NO"
assert is_eligible_for_bo... | [
{
"docstring": "Determines if an employee is eligible for a bonus based on years of service N, \nrequired ratings R, and service years S.\n\n:param N: Minimum years of service required\n:param R: Minimum performance rating required\n:param S: Actual years of service of the employee\n:return: \"YES\" if the empl... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_eligible_for_bonus(N, R, S):\n \"\"\"\n Determines if an employee is eligible for a bonus based on years of service N, \n required ratings R, and s... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028100",
"row_id": 28100,
"seed_ids": "[6891]"
} | 0.710659 | Taco_28100 | I | [
"is_eligible_for_bonus",
"determine_bonus_eligibility",
"parse_input"
] | 3 | [
[
"determine_bonus_eligibility",
"is_eligible_for_bonus"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 5a6a9a3fa5ac1de4ba66a6d8b36d803735c9ac84 | 28551d1d523ef4b9482c4436cdfc4aa9681d1cbb | |||
v1.0 | instruct | Taco | Taco_28107_I | In a distant future, a new form of interplanetary communication called "Orbital Link" has been established. An Orbital Link is represented by a binary tree, with each node containing an integer value. To ensure message integrity, a mechanism called "Link Checksum" is used. The Checksum is determined by finding the maxi... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
if not nodes:
return None
node_list = [None] * len(nodes)
for i, (v, l, r) in enumerate(nodes):
if node_list[i] is None:
... | from solution import orbital_link_checksum
def test_example_case():
nodes = [
(10, 1, 2),
(5, -1, -1),
(12, 3, 4),
(6, -1, -1),
(7, -1, -1)
]
assert orbital_link_checksum(5, nodes) == 29
def test_single_node():
nodes = [
(10, -1, -1),
]
assert or... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_t... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028107",
"row_id": 28107,
"seed_ids": "[17688]"
} | 0.570355 | Taco_28107 | I | [
"build_tree",
"max_root_to_leaf_sum",
"orbital_link_checksum"
] | 3 | [
[
"orbital_link_checksum",
"build_tree"
],
[
"orbital_link_checksum",
"max_root_to_leaf_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | cb102ef7a26ab735aa7dafa1a25ba487231ef380 | 7927bdaa5a4081365394a37d12aabc997056b356 | |||
v1.0 | instruct | Taco | Taco_28108_I | You are given the root of a binary tree. You need to determine the maximum depth of the binary tree. The depth of a binary tree is the length of the longest path from the root node to a leaf. This path may or may not pass through the root.
Input:
First line of input contains the number of test cases T. For each test c... | class TreeNode:
"""
Definition for a binary tree node.
"""
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def buildTree(nodes):
"""
Helper function to build a tree from the level order traversal list.
"""
if not nodes or nodes[0] == "N":
... | from solution import solve_max_depth
def test_case_1():
test_cases = ["3 9 20 N N 15 7"]
results = solve_max_depth(test_cases)
assert results == [3], f"Expected [3], but got {results}"
def test_case_2():
test_cases = ["1 2 3 N 4 N 5 N N 6 7"]
results = solve_max_depth(test_cases)
assert result... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef buildTree(nodes):\n \"\"\"\n Th... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028108",
"row_id": 28108,
"seed_ids": "[9468]"
} | 0.552724 | Taco_28108 | I | [
"buildTree",
"maxDepth",
"solve_max_depth"
] | 3 | [
[
"solve_max_depth",
"buildTree"
],
[
"solve_max_depth",
"maxDepth"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 05238e9fe0c735592c19a64a7818c56c92a10957 | 81f560df3b1c512411a6d44bb069f1e2f6074ec9 | |||
v1.0 | instruct | Taco | Taco_28246_I | ## Problem
You are given a list of N numbers {n1, n2, ..., nN} and Q queries. There are two types of queries:
1. When i is input, it refers to a query of the form `accumulate(i)` which means you need to compute the accumulated sum of the first i numbers from the list, i.e., n1 + n2 + ... + ni.
2. When i, x are input,... | class NumberList:
def __init__(self, numbers):
self.numbers = numbers
self.prefix_sum = self._compute_prefix_sum(numbers)
def _compute_prefix_sum(self, numbers):
prefix_sum = [0] * (len(numbers) + 1)
for i in range(1, len(numbers) + 1):
prefix_sum[i] = prefix_sum[i -... | import pytest
from solution import run_solution
def test_example_1():
N = 4
Q = 3
numbers = [2, 4, 6, 8]
queries = [(1, 3), (2, 2, 5), (1, 4)]
expected = [12, 21]
assert run_solution(N, Q, numbers, queries) == expected
def test_example_2():
N = 5
Q = 4
numbers = [1, 2, 3, 4, 5]
... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class NumberList:\n def __init__(self, numbers):\n self.numbers = numbers\n self.prefix_sum = self._compute_prefix_sum(numbers)\n\n def _comput... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028246",
"row_id": 28246,
"seed_ids": "[12644]"
} | 0.78072 | Taco_28246 | I | [
"process_queries",
"run_solution"
] | 2 | [
[
"run_solution",
"process_queries"
]
] | 1 | [
"process_queries"
] | false | [
"NumberList"
] | true | pytest | true | [] | true | 8578236484e7e65d2d14ed391d9738f229c5438d | 3ca760de05dc0af20b7611d1d67fa7a7a8f8d439 | |||
v1.0 | instruct | Taco | Taco_28284_I | Write a program that implements the Merge Sort algorithm to sort an array of integers in ascending order. The algorithm must follow this high-level pseudo code structure:
1. If the array has one element or is empty, it is already sorted.
2. Divide the array into two halves.
3. Recursively sort each half.
4. Merge the ... | def merge(arr, left, mid, right):
# Create temporary arrays to hold left and right subarrays
left_sub = arr[left:mid+1]
right_sub = arr[mid+1:right+1]
# Initial indexes for left, right and merged subarrays
i = 0
j = 0
k = left
# Merging the subarrays back to arr
while i < l... | from solution import merge_sort, merge, sort_and_trace
def test_simple_case():
arr = [4, 1, 5, 3, 2]
sort_and_trace(arr)
def test_reverse_sorted():
arr = [8, 7, 6, 5]
sort_and_trace(arr)
def test_already_sorted():
arr = [1, 2, 3, 4, 5]
sort_and_trace(arr)
def test_all_elements_same():
ar... | [
{
"docstring": null,
"function_declaration": "def merge(arr, left, mid, right):",
"function_name": "merge",
"parameter_list": "(arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort(arr, left, right):",
"function_name": "merge_sort",
"parameter_l... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on the array and prints the state of the array after each merge operation.\n \"\"\"\n if len(arr) <=... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00028284",
"row_id": 28284,
"seed_ids": "[19801]"
} | 0.70437 | Taco_28284 | I | [
"merge",
"merge_sort",
"sort_and_trace",
"main"
] | 4 | [
[
"merge_sort",
"merge"
],
[
"sort_and_trace",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ad7aeacdfc6c0bf8c45395fcd98de7ee67918b61 | c2e11e36f1e528734d38d98891bd3a5184e5e35c | |||
v1.0 | instruct | Taco | Taco_28317_I | A delivery robot moves data files between rows of servers arranged in a grid. Each server in the grid is represented as a cell that can either be occupied by data files (`1`) or be empty (`0`). The robot can only move horizontally or vertically to an adjacent cell, but not diagonally.
You need to determine the maximu... | def max_continuous_data_files(grid):
def dfs(i, j):
if i < 0 or j < 0 or i >= n or j >= m or grid[i][j] == 0:
return 0
grid[i][j] = 0
return 1 + dfs(i+1, j) + dfs(i-1, j) + dfs(i, j+1) + dfs(i, j-1)
n = len(grid)
m = len(grid[0])
max_files = 0
for i in r... | # Test cases for max_continuous_data_files function
def test_single_cell_grid():
assert max_continuous_data_files([[0]]) == 0
assert max_continuous_data_files([[1]]) == 1
def test_no_data_files():
assert max_continuous_data_files([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
]) == 0
def ... | [
{
"docstring": null,
"function_declaration": "def max_continuous_data_files(grid):",
"function_name": "max_continuous_data_files",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def max_continuous_data_files_input():",
"function_name": "max_continuous_dat... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_data_files_transfer(n, m, grid):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] != 1:\n return 0\n grid... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00028317",
"row_id": 28317,
"seed_ids": "[24822]"
} | 0.649289 | Taco_28317 | I | [
"max_continuous_data_files",
"max_continuous_data_files_input"
] | 2 | [
[
"max_continuous_data_files_input",
"max_continuous_data_files"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 034b2125dddf756fa26d2b4fc14dcce872dcff4f | 6f2d9948eb30a46c61301b96280a3861546166a6 | |||
v1.0 | instruct | Taco | Taco_28349_I | A: 02 Longest Page Sequence
problem
You are given an integer array P, where P[i] represents the page number of a book in which a particular event happens on the i-th day. Your task is to find the length of the longest subsequence of pages where every page in the subsequence is greater than the previous page.
Input f... | from bisect import bisect_left
def longest_increasing_subsequence(pages):
"""
Finds the length of the longest increasing subsequence in the list of page numbers.
"""
if not pages:
return 0
lis = []
for page in pages:
pos = bisect_left(lis, page)
if pos < len(lis):
... | def test_longest_increasing_subsequence():
test_cases = [
(7, [100, 101, 102, 3, 4, 50, 200], 4),
(5, [10, 20, 10, 30, 40], 4),
(8, [5, 1, 6, 2, 7, 3, 8, 4], 4),
(5, [1, 2, 3, 4, 5], 5),
(5, [5, 4, 3, 2, 1], 1),
(0, [], 0),
(1, [42], 1),
]
for n, p, e... | [
{
"docstring": "Finds the length of the longest increasing subsequence in the list of page numbers.",
"function_declaration": "def longest_increasing_subsequence(pages):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(pages)"
},
{
"docstring": null,
"function_dec... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from bisect import bisect_left\n\ndef longest_increasing_subsequence(pages):\n \"\"\"\n Finds the length of the longest increasing subsequence in the list of... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028349",
"row_id": 28349,
"seed_ids": "[11575]"
} | 0.63131 | Taco_28349 | I | [
"longest_increasing_subsequence",
"solve_longest_page_sequence"
] | 2 | [
[
"solve_longest_page_sequence",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7fede64d40299dda1228e7b637fea65f77e784f4 | 4b96dc785ce22c0c77b1bb6a1c945f6b3189ee13 | |||
v1.0 | instruct | Taco | Taco_28432_I | A secluded island is governed by a peculiar society that believes in balancing energy to maintain peace. Each member of the society possesses a stone, the energy level of which is represented by a positive integer. The society has decided to balance these stones by transferring energy between them according to the foll... | def gcd(a, b):
while b:
a, b = b, a % b
return a
def max_total_energy(T, test_cases):
results = []
for i in range(T):
N, energies = test_cases[i]
total_energy = sum(energies)
max_energy = total_energy
# Check all pairs for possible optimal energy transfer
... | from solution import max_total_energy
def test_case_1():
assert max_total_energy(2, [(3, [6, 9, 12]), (2, [10, 15])]) == [27, 25]
def test_single_stone():
assert max_total_energy(1, [(1, [7])]) == [7]
def test_two_stones_no_transfer_possible():
assert max_total_energy(1, [(2, [7, 11])]) == [18]
def test... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def max_total_energy(T, test_cases):",
"function_name": "max_total_energy",
"parameter_list": "(T, test_cases)"
}
] | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import Counter\n\ndef maximum_total_energy(test_cases):\n results = []\n\n for energies in test_cases:\n if len(energies... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00028432",
"row_id": 28432,
"seed_ids": "[17785]"
} | 0.640199 | Taco_28432 | I | [
"gcd",
"max_total_energy"
] | 2 | [
[
"max_total_energy",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4118fef38c62085667227b9c22d069afe09cad9d | c6749834528117999ca83ffcc3698fea67de3a04 | |||
v1.0 | instruct | Taco | Taco_28573_I | Write a function ```capital_city``` that takes a country name as an input and returns its capital city. The function should be able to handle different variations in spelling and capitalization, as well as missing or additional accents. If the function does not recognize the country name, it should return "Unknown".
T... | import unicodedata
import re
def normalize_country_name(country: str) -> str:
"""
Normalize a country name by removing accents, extra spaces, and punctuation. Convert to lowercase.
"""
# Normalize the string to remove accents
normalized = unicodedata.normalize('NFKD', country).encode('ASCII', 'igno... | from solution import capital_city
def test_capital_city_france():
assert capital_city("France") == "Paris"
assert capital_city("france") == "Paris"
assert capital_city("FRANCE") == "Paris"
assert capital_city("FrAnCe") == "Paris"
assert capital_city(" France ") == "Paris"
assert capital_city("... | [
{
"docstring": "Normalize a country name by removing accents, extra spaces, and punctuation. Convert to lowercase.",
"function_declaration": "def normalize_country_name(country):",
"function_name": "normalize_country_name",
"parameter_list": "(country)"
},
{
"docstring": "Return the capital ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import unicodedata\n\ndef normalize_text(text: str) -> str:\n \"\"\"\n Normalize the text by removing accents, extra spaces, and converting to lowercase.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028573",
"row_id": 28573,
"seed_ids": "[3282]"
} | 0.533038 | Taco_28573 | I | [
"normalize_country_name",
"capital_city"
] | 2 | [
[
"capital_city",
"normalize_country_name"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 03ef94cd82dd490f60024bb8107a368906acf362 | 72d9c4a823ca0147c5ead8d3d929acad9ba6c4bd | |||
v1.0 | instruct | Taco | Taco_28574_I | In Treeland, there are multiple kingdoms with various castles connected by bidirectional roads. Treeland's road system forms an undirected tree, meaning there is exactly one path between any two castles. Recently, the treelandian government has decided to establish a wireless communication network between castles.
To ... | from collections import defaultdict, deque
def bfs_farthest_node(start, n, graph):
"""
Perform BFS to find the farthest node from the start node and the distance to it.
"""
visited = [False] * (n + 1)
queue = deque([(start, 0)])
visited[start] = True
farthest_node = start
max_dista... | from solution import solve
def test_example1():
input_data = "5\n1 2\n1 3\n3 4\n3 5\n2"
assert solve(input_data) == 1
def test_example2():
input_data = "6\n1 2\n1 3\n2 4\n2 5\n3 6\n3"
assert solve(input_data) == 1
def test_example3():
input_data = "4\n1 2\n1 3\n2 4\n1"
assert solve(input_data... | [
{
"docstring": "Perform BFS to find the farthest node from the start node and the distance to it.",
"function_declaration": "def bfs_farthest_node(start, n, graph):",
"function_name": "bfs_farthest_node",
"parameter_list": "(start, n, graph)"
},
{
"docstring": null,
"function_declaration... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\nfrom typing import List, Tuple\n\ndef minimum_max_distance(n: int, edges: List[Tuple[int, int]], k: int) -> int:\n def bfs(src: i... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00028574",
"row_id": 28574,
"seed_ids": "[10349]"
} | 0.622015 | Taco_28574 | I | [
"bfs_farthest_node",
"minimum_max_distance",
"solve"
] | 3 | [
[
"minimum_max_distance",
"bfs_farthest_node"
],
[
"solve",
"minimum_max_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 80432aaa37ee8e9b667dd45ee404d44cce8e2bd7 | 4d4d6e0c265075bbd2fa9fcbf7cb38c9da61e94a | |||
v1.0 | instruct | Taco | Taco_28588_I | The government of a city has decided to build a special road network for a festival. The road network can be represented as a tree graph, which contains `n` nodes connected by `n - 1` edges. Each edge has a weight representing the travel cost between the nodes it connects.
The city government wants to determine the m... | def dfs(node, parent, graph, max_cost, current_cost):
max_cost[node] = current_cost
for neighbor, weight in graph[node]:
if neighbor != parent:
dfs(neighbor, node, graph, max_cost, max(current_cost, weight))
def min_travel_cost(n, edges):
graph = [[] for _ in range(n+1)]
for u, v, w... | from solution import min_travel_cost
def test_example_case_1():
n = 5
edges = [
(1, 2, 3),
(1, 3, 2),
(3, 4, 4),
(3, 5, 6)
]
assert min_travel_cost(n, edges) == 6
def test_example_case_2():
n = 3
edges = [
(1, 2, 1),
(2, 3, 2)
]
assert mi... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, graph, max_cost, current_cost):",
"function_name": "dfs",
"parameter_list": "(node, parent, graph, max_cost, current_cost)"
},
{
"docstring": null,
"function_declaration": "def min_travel_cost(n, edges):",
"function_... | [
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 dfs(node, parent, graph, max_cost, current_cost):\n max_cost[node] = current_cost\n for neighbor, weight in graph[node]:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028588",
"row_id": 28588,
"seed_ids": "[7869]"
} | 0.748737 | Taco_28588 | I | [
"dfs",
"min_travel_cost"
] | 2 | [
[
"min_travel_cost",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4c603e0645d77c6a4f5e63c82cef2a343383cde0 | 2e710c3ef3884098a2810d55f3fb1dd14b995d81 | |||
v1.0 | instruct | Taco | Taco_28595_I | You are given a list of $n$ books, each with a certain number of pages. Your task is to allocate these books to $m$ students in such a way that each student gets at least one book, and the maximum number of pages assigned to a student is minimized.
Determine the maximum number of pages a student has to read in such an... | def is_feasible(pages, n, m, curr_min):
students_required = 1
curr_sum = 0
for i in range(n):
if (pages[i] > curr_min):
return False
if (curr_sum + pages[i] > curr_min):
students_required += 1
curr_sum = pages[i]
if s... | def test_find_min_max_pages():
assert find_min_max_pages([12, 34, 67, 90], 4, 2) == 113
assert find_min_max_pages([10, 20, 30, 40, 50], 5, 3) == 60
assert find_min_max_pages([10, 20, 30], 3, 3) == 30
assert find_min_max_pages([10, 20, 30], 3, 1) == 60
assert find_min_max_pages([5, 17, 100, 11], 4, 2... | [
{
"docstring": null,
"function_declaration": "def is_feasible(pages, n, m, curr_min):",
"function_name": "is_feasible",
"parameter_list": "(pages, n, m, curr_min)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(pages, n, m):",
"function_name": "find_min_max_p... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def allocate_books(n, m, pages):\n \"\"\"\n Allocates books to students such that the maximum number of pages any student has to read is minimized.\n \"\"... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00028595",
"row_id": 28595,
"seed_ids": "[17282]"
} | 0.752869 | Taco_28595 | I | [
"is_feasible",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_feasible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b9517ba4720cbaee30f491962fa15ffbf51e3c96 | 36e24e143bab0cb21f877a83d06c1a5266f4841d | |||
v1.0 | instruct | Taco | Taco_28640_I | Treasure Hunt
A group of archaeologists in a hidden valley discovered coordinates on an ancient map pointing to several potential treasure locations. Each location is marked with an (x, y) coordinate on a 2D grid.
To maximize the treasure collected, the archaeologists decide that they should visit the treasure locati... | from itertools import permutations
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def calculate_total_distance(route, coords):
total_distance = 0
total_distance += manhattan_distance(0, 0, coords[route[0]][0], coords[route[0]][1])
for i in range(len(route) - 1):
tot... | from solution import treasure_hunt
def test_sample_input():
input_data = ["3",
"1 1",
"2 1",
"2 2",
"2",
"1 2",
"3 4",
"0"]
expected_output = [8, 14]
assert treasure_hunt(inp... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def calculate_total_distance(route, coords):",
"function_name": "calcul... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\ndef minimum_travel_distance(treasure_l... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00028640",
"row_id": 28640,
"seed_ids": "[8640]"
} | 0.658843 | Taco_28640 | I | [
"manhattan_distance",
"calculate_total_distance",
"minimum_total_travel_distance",
"treasure_hunt"
] | 4 | [
[
"calculate_total_distance",
"manhattan_distance"
],
[
"minimum_total_travel_distance",
"calculate_total_distance"
],
[
"treasure_hunt",
"minimum_total_travel_distance"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f69a729214c02d59ae6e6ee28612aed2fb9fcddf | adb9e1cce32e429fb35b9c17528f42c89c477836 | |||
v1.0 | instruct | Taco | Taco_28681_I | Eve is a skilled botanist who loves exploring the fascinating world of plants. She recently came across an intriguing problem involving the beautiful gardens she studies. She decided to ask you for help in solving it. Can you help Eve with her problem?
You are given an integer $N$ representing the total number of diff... | def modinv(a, p):
"""
Returns the modular inverse of a under modulo p using Fermat's little theorem.
"""
return pow(a, p - 2, p)
def nCr_mod_p(n, r, p):
"""
Returns C(n, r) % p using Fermat's little theorem for the modulus.
"""
if r > n:
return 0
if r == 0 or n == r:
... | def test_unique_combinations():
assert unique_combinations(5, 3) == 10
assert unique_combinations(6, 2) == 15
assert unique_combinations(10, 5) == 252
assert unique_combinations(1, 1) == 1
assert unique_combinations(1000, 2) == 499500
assert unique_combinations(1000000, 1) == 1000000
assert ... | [
{
"docstring": "Returns the modular inverse of a under modulo p using Fermat's little theorem.",
"function_declaration": "def modinv(a, p):",
"function_name": "modinv",
"parameter_list": "(a, p)"
},
{
"docstring": "Returns C(n, r) % p using Fermat's little theorem for the modulus.",
"fun... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef mod_inv(a, p):\n \"\"\"\n Compute the modular multiplicative inverse of a under modulo p\n using Fermat's ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028681",
"row_id": 28681,
"seed_ids": "[20866]"
} | 0.559032 | Taco_28681 | I | [
"modinv",
"nCr_mod_p",
"unique_combinations"
] | 3 | [
[
"nCr_mod_p",
"modinv"
],
[
"unique_combinations",
"nCr_mod_p"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 3e62f77d6f786919260ee0581f5238f97d5e76ce | 4012fa5f7c8041db25448aa019bc1225cc308ae6 | |||
v1.0 | instruct | Taco | Taco_28712_I | Problem Statement
As a developer in a software company, you are responsible for designing algorithms to handle large-scale data processing. One of your assignments is to analyze the daily stock prices of multiple companies. You are given a list of stock prices for two companies over a period of time. Your task is to d... | def lcs_length(X, Y):
"""
Returns the length of the longest common subsequence (LCS) of two sequences.
"""
m = len(X)
n = len(Y)
# Create a 2D array to store the lengths of longest common subsequence.
L = [[0 for j in range(n+1)] for i in range(m+1)]
# Following steps build L[m... | from solution import longest_common_subsequence_length
def test_lcs_length_example_1():
assert longest_common_subsequence_length("1 3 4 1 2 1 5", "3 4 1 2 1 3") == 5
def test_lcs_length_example_2():
assert longest_common_subsequence_length("7 8 9 10", "1 2 3 4") == 0
def test_lcs_length_different_lengths():
... | [
{
"docstring": "Returns the length of the longest common subsequence (LCS) of two sequences.",
"function_declaration": "def lcs_length(X, Y):",
"function_name": "lcs_length",
"parameter_list": "(X, Y)"
},
{
"docstring": "Given two space-separated strings of integers, return the length of the... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def lcs_stock_prices(prices1, prices2):\n \"\"\"\n Returns the length of the longest common subsequence of the stock prices for two companies.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028712",
"row_id": 28712,
"seed_ids": "[19339]"
} | 0.693764 | Taco_28712 | I | [
"lcs_length",
"longest_common_subsequence_length"
] | 2 | [
[
"longest_common_subsequence_length",
"lcs_length"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 57633abe42a2f57a09b1d8756730afa4350719a0 | 77af3d4d658cf2e88e3a5f17d680820194180463 | |||
v1.0 | instruct | Taco | Taco_28802_I | Dan loves playing with numbers and is particularly fascinated by properties of prime numbers. He came up with a unique problem involving consecutive subsequences of prime numbers. A "Prime Consecutive Subsequence" is a consecutive subsequence in a sequence where all the numbers are prime. Dan needs your help to find th... | import math
def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def longest_prime_consecutive_subsequence(numbers):
max_lengt... | from solution import longest_prime_consecutive_subsequence
def test_sample_input():
numbers = [1, 2, 3, 5, 4, 7, 11, 13, 4, 6]
assert longest_prime_consecutive_subsequence(numbers) == 3
def test_all_primes():
numbers = [2, 3, 5, 7, 11, 13, 17, 19]
assert longest_prime_consecutive_subsequence(numbers) ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_consecutive_subsequence(numbers):",
"function_name": "longest_prime_consecutive_subsequence",
"... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00028802",
"row_id": 28802,
"seed_ids": "[22893]"
} | 0.697627 | Taco_28802 | I | [
"is_prime",
"longest_prime_consecutive_subsequence"
] | 2 | [
[
"longest_prime_consecutive_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 54324bc491df4ee68ab392a1b0b933eb838c64ba | f7602461528bb6cbbc511d66d12c1792cc2bb5d9 | |||
v1.0 | instruct | Taco | Taco_28864_I | Create a program that simulates the lottery draw process for a 6/49 type lottery where the player must pick 6 different numbers from a set of 49 consecutive numbers (1 through 49). The draw will randomly select 6 different numbers. The program will then compare the player's chosen numbers with the drawn numbers and det... | import random
def simulate_lottery_draw():
"""
Simulates the lottery draw process and returns a list of 6 unique drawn numbers.
"""
return sorted(random.sample(range(1, 50), 6))
def count_matches(drawn_numbers, chosen_numbers):
"""
Counts how many numbers in chosen_numbers match the drawn_numb... | import pytest
from unittest.mock import patch
from solution import simulate_lottery_draw, count_matches, lottery_simulation
def test_simulate_lottery_draw():
drawn_numbers = simulate_lottery_draw()
assert len(drawn_numbers) == 6
assert all(1 <= num <= 49 for num in drawn_numbers)
assert len(set(drawn_n... | [
{
"docstring": "Simulates the lottery draw process and returns a list of 6 unique drawn numbers.",
"function_declaration": "def simulate_lottery_draw():",
"function_name": "simulate_lottery_draw",
"parameter_list": "()"
},
{
"docstring": "Counts how many numbers in chosen_numbers match the d... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_lottery_numbers():\n \"\"\"\n Generates a set of 6 unique random numbers between 1 and 49 inclusive.\n \"\"\"\n return so... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00028864",
"row_id": 28864,
"seed_ids": "[23218]"
} | 0.532418 | Taco_28864 | I | [
"simulate_lottery_draw",
"count_matches",
"lottery_simulation"
] | 3 | [
[
"lottery_simulation",
"count_matches"
],
[
"lottery_simulation",
"simulate_lottery_draw"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 83b30ff5f0d13f0540da00bf5236666bf26400a9 | fc867ae26827b308f1d9fac790e0aed86def9fa4 | |||
v1.0 | instruct | Taco | Taco_28962_I | You are given a list of email addresses. Each email address in the list follows the format `username@domain.extension`. Your task is to filter out the invalid email addresses and print the valid ones in alphabetical order.
An email address is considered valid if:
1. The username contains only letters (a-z, A-Z), digit... | import re
def validate_email(email):
"""
Validates the email address according to specified rules.
- Username contains only letters, digits, dashes, underscores, and dots.
- Domain contains only letters and digits.
- Extension contains only letters and is 2 to 3 characters long.
"""
pattern... | from solution import validate_email, get_valid_emails
def test_validate_email():
assert validate_email('username@domain.com') == True
assert validate_email('user-name@domain.net') == True
assert validate_email('user_name@domain.org') == True
assert validate_email('user.name@domain.co.in') == False # in... | [
{
"docstring": "Validates the email address according to specified rules.\n- Username contains only letters, digits, dashes, underscores, and dots.\n- Domain contains only letters and digits.\n- Extension contains only letters and is 2 to 3 characters long.",
"function_declaration": "def validate_email(emai... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef validate_email(email):\n \"\"\"\n Validates the email address according to specified rules.\n - Username contains only letters, digits, d... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00028962",
"row_id": 28962,
"seed_ids": "[3507]"
} | 0.496971 | Taco_28962 | I | [
"validate_email",
"get_valid_emails"
] | 2 | [
[
"get_valid_emails",
"validate_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e00ba9a7b9714c14076f7cb6ee7d5fcacc0bc078 | 6421e8d86e10570d5173f052e1cd24524bc4e1bd | |||
v1.0 | instruct | Taco | Taco_28989_I | Given a grid of size n x n, you have to write a program that helps you identify the largest cross of 1s in that grid. A cross consists of one vertical and one horizontal line of 1s, intersecting at a single point. Both the vertical and horizontal lines must be of equal lengths, centered at the same point. The goal is t... | def largest_cross_in_grid(n, grid):
def compute_arm_lengths(matrix, n):
left = [[0] * n for _ in range(n)]
right = [[0] * n for _ in range(n)]
top = [[0] * n for _ in range(n)]
bottom = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
... | def test_get_largest_crosses_single():
input_string = "5\n1 0 1 1 1\n1 1 1 0 0\n1 1 1 1 1\n0 0 1 0 1\n1 1 1 1 1\n0"
assert get_largest_crosses(input_string) == [3]
def test_get_largest_crosses_multiple():
input_string = (
"5\n1 0 1 1 1\n1 1 1 0 0\n1 1 1 1 1\n0 0 1 0 1\n1 1 1 1 1\n"
"5\n0 0 ... | [
{
"docstring": null,
"function_declaration": "def largest_cross_in_grid(n, grid):",
"function_name": "largest_cross_in_grid",
"parameter_list": "(n, grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_cross_length(n, grid):\n if n == 0 or not grid:\n return 0\n \n def calculate_arm_lengths():\n left = [[0] * n for _ in range(n)]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028989",
"row_id": 28989,
"seed_ids": "[12508]"
} | 0.584531 | Taco_28989 | I | [
"largest_cross_in_grid",
"parse_input",
"get_largest_crosses"
] | 3 | [
[
"get_largest_crosses",
"largest_cross_in_grid"
],
[
"get_largest_crosses",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ae2d51831f512e3f9ce24926e4a27bc1677ec2b0 | fd152143ac3e0ac7c7acf30775c7e4c4f5876038 | |||
v1.0 | instruct | Taco | Taco_28993_I | You are given an integer array `arr` consisting of N$N$ positive integers. Your task is to handle multiple queries that ask for the sum of numbers in a specific subarray of `arr`. Each query provides the starting and ending index of the subarray, and you need to calculate the sum of the elements in that subarray.
----... | def prepare_prefix_sum(arr):
"""
Prepare the prefix sum array for the given array arr.
"""
n = len(arr)
prefix_sum = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1]
return prefix_sum
def sum_query(prefix_sum, l, r):
"""
Calculate the su... | from solution import handle_queries
def test_single_query():
N = 5
arr = [1, 2, 3, 4, 5]
Q = 1
queries = [(1, 3)]
assert handle_queries(N, arr, Q, queries) == [6]
def test_multiple_queries():
N = 5
arr = [1, 2, 3, 4, 5]
Q = 3
queries = [(1, 3), (2, 5), (1, 5)]
assert handle_que... | [
{
"docstring": "Prepare the prefix sum array for the given array arr.",
"function_declaration": "def prepare_prefix_sum(arr):",
"function_name": "prepare_prefix_sum",
"parameter_list": "(arr)"
},
{
"docstring": "Calculate the sum of the subarray from index l to r (1-indexed) using the prefix... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def subarray_sums(arr, queries):\n # Compute the prefix sum array\n prefix_sums = [0] * (len(arr) + 1)\n for i in range(len(arr)):\n prefix_sums[i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00028993",
"row_id": 28993,
"seed_ids": "[17833]"
} | 0.689221 | Taco_28993 | I | [
"prepare_prefix_sum",
"sum_query",
"handle_queries"
] | 3 | [
[
"handle_queries",
"prepare_prefix_sum"
],
[
"handle_queries",
"sum_query"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 4dc53c88cc45905bbda29b698c2515b79f0f4604 | ed8c3dfe6de0f5c474dbe28bbdf5006281b9e4b2 | |||
v1.0 | instruct | Taco | Taco_29044_I | Jasmine loves palindromic numbers. A palindromic number reads the same forwards and backwards, such as 121, 1331, or 7. She is also fascinated by sequences of numbers that can be split into multiple palindromic segments.
Given a sequence of positive integers, determine whether it can be partitioned into contiguous pal... | def is_palindrome(number):
"""
Check if a given number is a palindrome.
"""
str_number = str(number)
return str_number == str_number[::-1]
def can_partition_palindromic_segments(n, sequence):
"""
Determine if a sequence of numbers can be partitioned into contiguous palindromic segments.
... | from solution import is_palindrome, can_partition_palindromic_segments
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(11) == True
assert is_palindrome(1331) == True
assert is_palindrome(12321) == True
assert is_palindrome(1234... | [
{
"docstring": "Check if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Determine if a sequence of numbers can be partitioned into contiguous palindromic segments.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Checks if the given number (as an integer) is a palindrome.\n \"\"\"\n num_str = str(num)\n return num_str == num... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029044",
"row_id": 29044,
"seed_ids": "[5958]"
} | 0.66964 | Taco_29044 | I | [
"is_palindrome",
"can_partition_palindromic_segments"
] | 2 | [
[
"can_partition_palindromic_segments",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be2b670334572a7246e4f890c9d10b7363d32c1b | 33256ea21e01c3d7d6f579ab228ad29280f21dda | |||
v1.0 | instruct | Taco | Taco_29084_I | A software company has developed a new system that needs to store and retrieve both numbers and strings efficiently. One requirement is that the system needs to compare different entries to sort and perform quick lookups. The entries are either strings or integers, and they follow a strict format rule: all strings cont... | def sort_entries(entries):
"""
This function takes a list of mixed entries (numbers and strings) and sorts them
so that:
- All strings appear before any numbers.
- Strings are sorted in lexicographical order.
- Numbers are sorted in non-decreasing order.
:param entries: List of strings ... | from solution import read_and_sort_entries
def test_example_1():
assert read_and_sort_entries(6, "banana 7 apple 42 -15 orange") == ["apple", "banana", "orange", -15, 7, 42]
def test_example_2():
assert read_and_sort_entries(4, "10 -1 apple3 apple5") == ["apple3", "apple5", -1, 10]
def test_single_string():
... | [
{
"docstring": "This function takes a list of mixed entries (numbers and strings) and sorts them\nso that:\n- All strings appear before any numbers.\n- Strings are sorted in lexicographical order.\n- Numbers are sorted in non-decreasing order.\n\n:param entries: List of strings and integers\n:return: A sorted l... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sort_entries(entries):\n \"\"\"\n This function sorts a list of entries where strings come before numbers.\n Strings are sorted lexicographically and ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029084",
"row_id": 29084,
"seed_ids": "[15820]"
} | 0.647419 | Taco_29084 | I | [
"sort_entries",
"read_and_sort_entries"
] | 2 | [
[
"read_and_sort_entries",
"sort_entries"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de33089b3c1c2c429c4a474d2b92f32bd358df9b | 4a2afe6c845a77a8b46497e82c72c54248939848 | |||
v1.0 | instruct | Taco | Taco_29122_I | Eva loves to play with numbers and create new sequences. One day, she came up with a sequence by starting with a positive integer and repeatedly applying a specific transformation until she gets the number 1. The transformation she uses is: if the number is even, she divides it by 2; if the number is odd, she multiplie... | def collatz_steps(x):
"""
Returns the number of steps required for a given starting number x to reach 1
using the Collatz transformation.
"""
steps = 0
while x != 1:
if x % 2 == 0:
x //= 2
else:
x = 3 * x + 1
steps += 1
return steps
def colla... | from solution import collatz_steps, collatz_steps_for_multiple_numbers
def test_collatz_steps():
assert collatz_steps(6) == 8
assert collatz_steps(19) == 20
assert collatz_steps(27) == 111
assert collatz_steps(1) == 0
assert collatz_steps(2) == 1
def test_collatz_steps_for_multiple_numbers():
... | [
{
"docstring": "Returns the number of steps required for a given starting number x to reach 1 \nusing the Collatz transformation.",
"function_declaration": "def collatz_steps(x):",
"function_name": "collatz_steps",
"parameter_list": "(x)"
},
{
"docstring": "Returns a list with the number of ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def collatz_steps(x):\n \"\"\"\n Returns the number of steps required for a given starting number x to reach 1 \n using the Collatz transformation.\n \... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029122",
"row_id": 29122,
"seed_ids": "[10840]"
} | 0.670826 | Taco_29122 | I | [
"collatz_steps",
"collatz_steps_for_multiple_numbers"
] | 2 | [
[
"collatz_steps_for_multiple_numbers",
"collatz_steps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48448f6b29acc0f08dafb00f84c7cac22e959b5c | 520a5f498c4670b9f96442a73d15f55962afd964 | |||
v1.0 | instruct | Taco | Taco_29179_I | ## Problem Statement: Prime Sum Ranges
Given a list of N integers and Q queries, each query specifies a range [L, R] (1-indexed). For each query, output the sum of all prime numbers within that range of the list.
### Input Format
- The first line contains an integer N, the size of the list.
- The second line contains ... | def is_prime(n):
"""
Helper function to check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | def test_prime_sum_ranges():
# Test case 1
N = 6
arr = [1, 2, 3, 4, 5, 6]
queries = [(1, 3), (2, 5), (4, 6)]
assert prime_sum_ranges(N, arr, queries) == [5, 10, 5]
# Test case 2
N = 5
arr = [11, 15, 17, 19, 23]
queries = [(1, 2), (2, 4), (1, 5)]
assert prime_sum_ranges(N, arr, q... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of N integers and a list of queries, \neach query specifies a range [L, R] (1-indexed). \... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029179",
"row_id": 29179,
"seed_ids": "[19324]"
} | 0.651872 | Taco_29179 | I | [
"is_prime",
"prime_sum_ranges"
] | 2 | [
[
"prime_sum_ranges",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6bf85efb233b80b17a85a6f0072c1add864b8964 | 6058d151e493385cfa046f3e7f9aedc1d1c7badf | |||
v1.0 | instruct | Taco | Taco_29198_I | A kingdom is being attacked by a dragon, and the king wants to capture the dragon by laying traps along its possible flight path. There are N traps laid out in a straight line, each with a defined capture limit. The dragon follows a zigzag flight path, which means it can be captured if the adjacent trap has a higher li... | def longest_increasing_subsequence(traps):
"""
This function takes a list of trap limits and returns the length of the longest increasing subsequence.
"""
if not traps:
return 0
n = len(traps)
lis = [1] * n # Initialize LIS length array with 1 for each position
for i in ra... | from solution import process_traps
def test_sample_input():
traps = [1, 3, 2, 4, 6, 5]
assert process_traps(traps) == 4
def test_single_trap():
traps = [5]
assert process_traps(traps) == 1
def test_all_equal_traps():
traps = [2, 2, 2, 2, 2]
assert process_traps(traps) == 1
def test_strictly_... | [
{
"docstring": "This function takes a list of trap limits and returns the length of the longest increasing subsequence.",
"function_declaration": "def longest_increasing_subsequence(traps):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(traps)"
},
{
"docstring": nul... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_increasing_subsequence(traps):\n \"\"\"\n Finds the length of the longest increasing subsequence in trap limits.\n \n Args:\n traps (lis... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029198",
"row_id": 29198,
"seed_ids": "[22782]"
} | 0.563357 | Taco_29198 | I | [
"longest_increasing_subsequence",
"process_traps"
] | 2 | [
[
"process_traps",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19683b240a9c1c1efa12e81943e869d54bef10ac | 455fab09029dc0cea99c6e52e79c7f9f0a787bfb | |||
v1.0 | instruct | Taco | Taco_29252_I | You are given an array of positive integers where each integer represents the height of a player. You are organizing a game in which any two players can play a match. During the match, the taller player always wins. If two players have the same height, either one can win. A tournament is held in which every player comp... | from itertools import permutations
def count_unique_rankings(heights):
"""
Returns the number of unique ranking lists.
"""
unique_rankings = set()
for perm in permutations(heights):
unique_rankings.add(perm)
return len(unique_rankings)
# Function to be called for the task... | from solution import unique_ranking_count
def test_unique_ranking_count_all_unique():
assert unique_ranking_count("4 3 2 1") == 24
def test_unique_ranking_count_duplicates():
assert unique_ranking_count("3 3 2 1") == 12
def test_unique_ranking_count_all_same():
assert unique_ranking_count("1 1 1 1") == 1... | [
{
"docstring": "Returns the number of unique ranking lists.",
"function_declaration": "def count_unique_rankings(heights):",
"function_name": "count_unique_rankings",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def unique_ranking_count(heights_input):",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_ranking_lists(heights):\n \"\"\"\n Returns the number of unique ranking lists based on heights of players.\n \"\"\"\n # Converting list to a... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029252",
"row_id": 29252,
"seed_ids": "[1411]"
} | 0.736272 | Taco_29252 | I | [
"count_unique_rankings",
"unique_ranking_count"
] | 2 | [
[
"unique_ranking_count",
"count_unique_rankings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c153966e41197f497881f71ac4f4b6e93c63e90a | 4e9af2cf5627fa9e9cce1eccc3cb6e24c6da5c31 | |||
v1.0 | instruct | Taco | Taco_29270_I | **Problem**
You are working as an assistant to a game developer who is creating a new puzzle game involving grids. One of the main components of the game is to find paths within a grid.
The grid is an m x n grid filled with non-negative numbers, where each number represents the cost of stepping into that cell. Your t... | def min_path_sum(grid):
"""
Finds the minimum sum path from the top-left to bottom-right corner of the grid.
Only moves to the right and down are allowed.
"""
if not grid or not grid[0]:
return 0
m, n = len(grid), len(grid[0])
dp = [[0] * n for _ in range(m)]
dp[0][0] = grid[0]... | def test_min_path_sum():
grid1 = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_path_sum(grid1) == 7
grid2 = [
[1, 2],
[1, 1]
]
assert min_path_sum(grid2) == 3
def test_parse_input():
input_str = "3 3\n1 3 1\n1 5 1\n4 2 1\n2 2\n1 2\n1 1\n0 0"... | [
{
"docstring": "Finds the minimum sum path from the top-left to bottom-right corner of the grid.\nOnly moves to the right and down are allowed.",
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"functi... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_path_sum(grid):\n \"\"\"\n Finds the minimum sum path from the top-left to bottom-right corner of the grid.\n Only moves to the right and down are... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029270",
"row_id": 29270,
"seed_ids": "[5931]"
} | 0.717307 | Taco_29270 | I | [
"min_path_sum",
"parse_input",
"process_grids",
"main"
] | 4 | [
[
"process_grids",
"min_path_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e3e388e1c601a5fcb52dc8725919e9f1ad8d4bb0 | d9388cbc7a91a2380f8a00d2f43a6302e31f9e7e | |||
v1.0 | instruct | Taco | Taco_29275_I | You are given a binary tree where each node contains a value. A path in this binary tree is defined as a sequence of nodes starting from any node and ending at any node, directed downwards (i.e., only from parent nodes to child nodes). The sum of a path is defined as the sum of node values in that path.
Write a progra... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def dfs(node):
if not node:
return 0
left_sum = dfs(node.left)
right_sum = dfs(node.right)
max_single = max(max(left_sum, right_sum) + node.val, node.val)
return max_sing... | def test_dfs():
node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node1.left = node2
node1.right = node3
assert dfs(node1) == 4
def test_max_path_sum_single_node():
assert max_path_sum([], 1) == 1
def test_max_path_sum_small_tree():
edges = [(1, 2), (1, 3)]
assert max_pat... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\ndef build_tree(edges, n):\n node... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00029275",
"row_id": 29275,
"seed_ids": "[4975]"
} | 0.675714 | Taco_29275 | I | [
"dfs",
"max_path_sum",
"maximum_sum_of_paths",
"parse_input",
"main"
] | 5 | [
[
"max_path_sum",
"dfs"
],
[
"maximum_sum_of_paths",
"max_path_sum"
]
] | 2 | [
"parse_input"
] | false | [
"TreeNode"
] | true | pytest | false | [] | true | db747de3bfd63c62318ba5f568e26bda615d4904 | 3b1f3c756cb8cb01a7ff5f01249d96430889b139 | |||
v1.0 | instruct | Taco | Taco_29319_I | A large online retailer uses a high-traffic database to maintain records of user transactions. To support reporting and data analysis, they need to frequently count the number of transactions each user has made within a given range of transaction IDs.
You are provided with a list of transactions where each transaction... | from collections import defaultdict
from bisect import bisect_left, bisect_right
def preprocess_transactions(transactions):
user_transactions = defaultdict(list)
for user_id, trans_id in transactions:
user_transactions[user_id].append(trans_id)
for user_id in user_transactions:
user_tr... | def test_preprocess_transactions():
transactions = [(1, 5), (2, 15), (1, 25), (2, 35), (3, 50)]
expected = {
1: [5, 25],
2: [15, 35],
3: [50]
}
assert preprocess_transactions(transactions) == expected
def test_count_transactions_in_range():
user_transactions = {
1: [... | [
{
"docstring": null,
"function_declaration": "def preprocess_transactions(transactions):",
"function_name": "preprocess_transactions",
"parameter_list": "(transactions)"
},
{
"docstring": null,
"function_declaration": "def count_transactions_in_range(user_transactions, l, r):",
"func... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef transactions_in_range(num_transactions, num_queries, max_id, transactions, queries):\n \"\"\"\n Returns the number... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029319",
"row_id": 29319,
"seed_ids": "[7488]"
} | 0.677093 | Taco_29319 | I | [
"preprocess_transactions",
"count_transactions_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"count_transactions_in_range"
],
[
"process_queries",
"preprocess_transactions"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | f3c8d4776c558cb832bba5300aad2248c69ccffc | 13ec4eb201270f6ac4e036486f0d900ddf65a3e7 | |||
v1.0 | instruct | Taco | Taco_29375_I | You have been hired to develop an inventory management system for a warehouse. The warehouse has a series of shelves arranged in a linear fashion, each shelf containing a certain number of items. The shelves are numbered from 0 to N-1.
The warehouse managers have a specific way they want to retrieve items from the she... | def preprocess_items(items):
"""
Preprocess the items to create prefix sums.
"""
prefix_sums = [0] * (len(items) + 1)
for i in range(len(items)):
prefix_sums[i + 1] = prefix_sums[i] + items[i]
return prefix_sums
def query_sum(prefix_sums, i, j):
"""
Query the sum of items from s... | import pytest
from solution import preprocess_items, query_sum, handle_queries
def test_preprocess_items():
items = [2, 3, 7, 1, 6]
expected_prefix_sums = [0, 2, 5, 12, 13, 19]
assert preprocess_items(items) == expected_prefix_sums
def test_query_sum():
prefix_sums = [0, 2, 5, 12, 13, 19]
assert q... | [
{
"docstring": "Preprocess the items to create prefix sums.",
"function_declaration": "def preprocess_items(items):",
"function_name": "preprocess_items",
"parameter_list": "(items)"
},
{
"docstring": "Query the sum of items from shelf i to shelf j (inclusive).",
"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 preprocess_items(n, items):\n \"\"\"\n Preprocess the item counts on shelves to prepare for efficient range sum queries.\n Args:\n - n (int): The n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029375",
"row_id": 29375,
"seed_ids": "[19645]"
} | 0.660115 | Taco_29375 | I | [
"preprocess_items",
"query_sum",
"handle_queries"
] | 3 | [
[
"handle_queries",
"preprocess_items"
],
[
"handle_queries",
"query_sum"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 6d3e75423310af14442909169b368be674f06dcc | b4693803624c6d09e2954d363b3f53f85953a25f | |||
v1.0 | instruct | Taco | Taco_29414_I | Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, in the same order they appeared. Additionally, ensure your function handles an empty list and lists with no prime numbers appropriately.
For example:
```
filter_primes([2, 3, 4, 5, 10, 13]) ... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(0)
def test_filter_primes():
assert filter_primes(... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list.",
"function_declaration": "def filter_primes(lst):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029414",
"row_id": 29414,
"seed_ids": "[24725]"
} | 0.628924 | Taco_29414 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2fe684abbad73f30ecc854b9ba8f6e9a9342a7c7 | 125235e2845e7e0bb7274266d260c600626dfc70 | |||
v1.0 | instruct | Taco | Taco_29465_I | Gyan is organising a charity auction event where various items will be sold to the highest bidders. Each bidder can place multiple bids on different items. Gyan keeps track of all the bids and at the end of the auction, he wants to determine the winners for each item along with the winning bid amount. You are tasked wi... | def determine_winners(n, bids):
"""
Determines the winners for each item along with the winning bid amount.
Args:
n: an integer, the number of bids placed in the auction.
bids: a list of tuples, where each tuple contains (item name, bid amount, bidder name)
Returns:
A sorted list of st... | from solution import charity_auction
def test_charity_auction():
bids_input = [
"painting 300 John",
"vase 150 Alice",
"sculpture 200 Bob",
"vase 200 Charlie",
"painting 350 Emma",
"sculpture 250 John"
]
n = len(bids_input)
expected_output = [
"pa... | [
{
"docstring": "Determines the winners for each item along with the winning bid amount.\n\nArgs:\nn: an integer, the number of bids placed in the auction.\nbids: a list of tuples, where each tuple contains (item name, bid amount, bidder name)\n\nReturns:\nA sorted list of strings in the format \"item_name winni... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def determine_winners(bids):\n \"\"\"\n Determines the winners for each item in the auction.\n :param bids: List of tuples where each tuple contains (item... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029465",
"row_id": 29465,
"seed_ids": "[18351]"
} | 0.589818 | Taco_29465 | I | [
"determine_winners",
"charity_auction"
] | 2 | [
[
"charity_auction",
"determine_winners"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b08c0178dff4d21ee517597cd38740d8260eb51e | 0385f211111af9b572a3630acacf20c2463097ef | |||
v1.0 | instruct | Taco | Taco_29544_I | Write a function that takes an array of integers and returns an array containing only the prime numbers from the input array in the order they appeared.
Example: `input: [3, 4, 7, 10, 11, 13]` => `output: [3, 7, 11, 13]`
Note: An empty array should return an empty array. | def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import filter_primes
def test_filter_primes_no_primes():
assert filter_primes([4, 6, 8, 10, 12]) == []
def test_filter_primes_with_primes():
assert filter_primes([3, 4, 7, 10, 11, 13]) == [3, 7, 11, 13]
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19]) ... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes an array of integers and returns an array containing only the prime numbers\nfrom the input array in the order the... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029544",
"row_id": 29544,
"seed_ids": "[9189]"
} | 0.652457 | Taco_29544 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a33b4a3002085e9106a9d18a293a9020823f698f | c2bd8ef252326097fcdb656b978206ec79532926 | |||
v1.0 | instruct | Taco | Taco_29558_I | ## Task
Design a program that generates a sequence of prime numbers, and then organizes them into a specific formatted string. The length of the sequence is determined by the input provided by the user.
### Example
For `n = 5`, the prime sequence is `[2, 3, 5, 7, 11]` and the resultant formatted string should be:
```... | def generate_primes(n):
"""
Generates the first n prime numbers.
:param n: The number of primes to generate
:type n: int
:return: A list of the first n prime numbers
:rtype: list
"""
primes = []
candidate = 2
while len(primes) < n:
is_prime = all(candidate % prime !=... | def test_generate_primes():
assert generate_primes(1) == [2]
assert generate_primes(2) == [2, 3]
assert generate_primes(5) == [2, 3, 5, 7, 11]
assert generate_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_format_prime_sequence():
assert format_prime_sequence(1) == "P1: 2"
assert f... | [
{
"docstring": "Generates the first n prime numbers.\n\n:param n: The number of primes to generate\n:type n: int\n:return: A list of the first n prime numbers\n:rtype: list",
"function_declaration": "def generate_primes(n):",
"function_name": "generate_primes",
"parameter_list": "(n)"
},
{
"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(n):\n \"\"\"\n Generates the first n prime numbers.\n \n :param n: The number of primes to generate\n :type n: int\n :return:... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029558",
"row_id": 29558,
"seed_ids": "[11231]"
} | 0.600705 | Taco_29558 | I | [
"generate_primes",
"format_prime_sequence"
] | 2 | [
[
"format_prime_sequence",
"generate_primes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fa36a8a90e0704597210928bb3545c495a768d11 | 4ad932668637a7486c417d43a478cb8c95e4a24e | |||
v1.0 | instruct | Taco | Taco_29611_I | In a futuristic world, Lily finds herself in a city with a grid layout of size N×M, where each cell in the grid contains either 0 (representing an empty space) or 1 (representing an obstacle). Lily needs to navigate from the top-left corner (cell (1, 1)) to the bottom-right corner (cell (N, M)).
Lily can only move dow... | from collections import deque
def can_reach_endless_obstacle(grid, N, M, K):
# Directions for right and down moves
directions = [(0, 1), (1, 0)]
# Queue elements: (row, col, obstacles destroyed)
queue = deque([(0, 0, 0)])
visited = set((0, 0, 0)) # Store tuples of (x, y, obstacles destroyed)
... | from solution import parse_input_and_solve
def test_sample_input():
input_data = '''3
3 3 1
0 1 0
1 0 1
0 0 0
4 4 2
0 1 1 0
0 1 1 0
1 0 0 1
0 0 1 0
2 2 0
1 0
0 1'''
expected_output = '''YES
YES
NO'''
assert parse_input_and_solve(input_data) == expected_output
def test_single_path_no_obstacles():
input... | [
{
"docstring": null,
"function_declaration": "def can_reach_endless_obstacle(grid, N, M, K):",
"function_name": "can_reach_endless_obstacle",
"parameter_list": "(grid, N, M, K)"
},
{
"docstring": null,
"function_declaration": "def solve_obstacle_cases(test_cases):",
"function_name": ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef can_reach_destination(grid, N, M, K):\n directions = [(1, 0), (0, 1)] # down, right\n queue = deque([(0, 0, K)]) # (ro... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029611",
"row_id": 29611,
"seed_ids": "[8982]"
} | 0.738162 | Taco_29611 | I | [
"can_reach_endless_obstacle",
"solve_obstacle_cases",
"parse_input_and_solve"
] | 3 | [
[
"parse_input_and_solve",
"solve_obstacle_cases"
],
[
"solve_obstacle_cases",
"can_reach_endless_obstacle"
]
] | 2 | [
"parse_input_and_solve"
] | false | [] | false | pytest | true | [] | true | 7c6d138a1dee94e5fcdf3cc3ec40280a11dc00c5 | 35510b98dc3beeecc931284beee6bf09281509d2 | |||
v1.0 | instruct | Taco | Taco_29622_I | You are working on a software development project that involves managing a library of books. Each book has a unique identifier (ID), a title, an author, a publication year, and a list of genres it belongs to. You are tasked with creating a program that reads a list of books and provides various functionalities to manag... | class Book:
def __init__(self, id, title, author, year, genres):
self.id = id
self.title = title
self.author = author
self.year = year
self.genres = genres
class Library:
def __init__(self):
self.books = {}
def add_book(self, id, title, author, year, genres)... | import pytest
from solution import process_commands
def test_add_and_search_by_title():
commands = [
"5",
"ADD 1 The_Great_Gatsby F._Scott_Fitzgerald 1925 Fiction,Classic",
"ADD 2 To_Kill_a_Mockingbird Harper_Lee 1960 Fiction,Classic",
"SEARCH TITLE Gatsby",
"REMOVE 1",
... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Book:\n def __init__(self, book_id, title, author, year, genres):\n self.book_id = book_id\n self.title = title\n self.author = autho... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00029622",
"row_id": 29622,
"seed_ids": "[21997]"
} | 0.595094 | Taco_29622 | I | [
"format_book",
"process_commands",
"run_command"
] | 3 | [
[
"process_commands",
"format_book"
],
[
"run_command",
"process_commands"
]
] | 2 | [] | false | [
"Book",
"Library"
] | true | pytest | true | [] | true | f4ef26799aa7a72b57bd3071e8150731ebe68c53 | 384f8d915272f0b884e23721c571315e2ff97b5b | |||
v1.0 | instruct | Taco | Taco_29638_I | A company is trying to optimize the routing of their delivery trucks between various cities. Each city is connected by one-way roads, and the company wants to determine the shortest path for their trucks to deliver goods from the central warehouse to several destination cities. The problem can be represented as a direc... | from heapq import heappop, heappush
import sys
def dijkstra(n, edges, start):
graph = [[] for _ in range(n + 1)]
for u, v, w in edges:
graph[u].append((w, v))
distances = [float('inf')] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)] # (distance, node)
while prio... | def test_example_1():
n, m = 5, 6
roads = [
(1, 2, 2),
(1, 3, 4),
(2, 4, 7),
(3, 4, 1),
(4, 5, 3),
(3, 5, 1)
]
q = 3
queries = [4, 5, 2]
expected_output = [5, 5, 2]
assert solve(n, m, roads, q, queries) == expected_output
def test_example_2():... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, roads, q, queries):",
"function_name": "solve",
"parameter_list": "(n... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from heapq import heappop, heappush\nimport sys\n\ndef dijkstra(n, edges, start):\n graph = [[] for _ in range(n + 1)]\n for u, v, w in edges:\n graph... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029638",
"row_id": 29638,
"seed_ids": "[5031]"
} | 0.804321 | Taco_29638 | I | [
"dijkstra",
"solve"
] | 2 | [
[
"solve",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a215b6c87ce4be3339cbb143271fb0144557e649 | b85bacb774fe105f38b05388cbea0786cf1d5ec3 | |||
v1.0 | instruct | Taco | Taco_29651_I | You are given a list of `N` integers. Your task is to return a list of the same integers but with each prime number replaced by the closest Fibonacci number. If there are two Fibonacci numbers equally close to a prime number, replace it with the smaller one.
For the purpose of this question, the first few Fibonacci n... | def is_prime(n):
"""Return True if n is a prime number else False"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def closest_fibonacci(n):
... | from solution import is_prime, closest_fibonacci, replace_primes_with_fibonacci
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(10) == False
assert is_prime(17) == True
def test_closest_fibonacci():
assert closest_fibonacci... | [
{
"docstring": "Return True if n is a prime number else False",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return the closest Fibonacci number to n",
"function_declaration": "def closest_fibonacci(n):",
"functio... | [
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 math\n\ndef is_prime(number):\n if number <= 1:\n return False\n if number <= 3:\n return True\n if number % 2 == 0 or number % 3 == ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00029651",
"row_id": 29651,
"seed_ids": "[24875]"
} | 0.62525 | Taco_29651 | I | [
"is_prime",
"closest_fibonacci",
"replace_primes_with_fibonacci"
] | 3 | [
[
"replace_primes_with_fibonacci",
"closest_fibonacci"
],
[
"replace_primes_with_fibonacci",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4c76aeaf295b587ef131e4271fc5edd6e6ede1e2 | e5a50727b9691c0ae9f9a2a4d91870c54375def4 | |||
v1.0 | instruct | Taco | Taco_29662_I | You are given an undirected graph with $N$ nodes and $M$ edges. Each node has a weight assigned to it. For each query, you need to find the maximum weighted node in the connected component of a given node.
-----Input-----
- The first line of the input contains two space-separated integers $N$ and $M$ denoting the numb... | def find_connected_components(N, edges):
from collections import defaultdict, deque
graph = defaultdict(list)
for u, v in edges:
graph[u-1].append(v-1)
graph[v-1].append(u-1)
visited = [False] * N
components = []
def bfs(start):
component = []
queue = deque([st... | def test_find_connected_components():
N = 5
edges = [(1, 2), (1, 3), (3, 4), (4, 5)]
expected = [[0, 1, 2, 3, 4]]
assert find_connected_components(N, edges) == expected
def test_max_weight_in_components():
weights = [1, 2, 3, 4, 5]
components = [[0, 1, 2, 3, 4]]
expected = {0: 5, 1: 5, 2: 5... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(N, edges):",
"function_name": "find_connected_components",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def max_weight_in_components(weights, components):",
"function_name":... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_max_weight_in_connected_component(n, m, weights, edges, queries):\n from collections import defaultdict, deque\n \n # Step 1: Build adjacency lis... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029662",
"row_id": 29662,
"seed_ids": "[12470]"
} | 0.761936 | Taco_29662 | I | [
"find_connected_components",
"max_weight_in_components",
"process_queries",
"solve_graph_problem"
] | 4 | [
[
"process_queries",
"max_weight_in_components"
],
[
"solve_graph_problem",
"find_connected_components"
],
[
"solve_graph_problem",
"process_queries"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 404b9647c9eb11f84a9aa5dda0cee6cd33995629 | 7f5ce6eb833e66203d5118c9d6f6edb9575c6df8 | |||
v1.0 | instruct | Taco | Taco_29723_I | Problem Statement
Alex is planning a vacation trip and wants to ensure his luggage is packed efficiently. He has a backpack with a specific capacity and a list of items, each with a weight and a value. Alex wants to maximize the total value of the items he can carry without exceeding the capacity of his backpack.
You... | def knapsack(C, N, items):
"""
Solves the knapsack problem.
Parameters:
- C: int, capacity of the backpack
- N: int, number of items
- items: list of tuples, each tuple (Wi, Vi) indicates weight and value of an item
Returns:
- int, the maximum value that can be carried in the backp... | def test_knapsack_base_case():
assert knapsack(4, 3, [(1, 3), (4, 5), (3, 4)]) == 7
def test_knapsack_single_item_fits_perfectly():
assert knapsack(5, 1, [(5, 10)]) == 10
def test_knapsack_single_item_too_large():
assert knapsack(5, 1, [(6, 10)]) == 0
def test_knapsack_multiple_items():
assert knapsa... | [
{
"docstring": "Solves the knapsack problem.\n\nParameters:\n- C: int, capacity of the backpack\n- N: int, number of items\n- items: list of tuples, each tuple (Wi, Vi) indicates weight and value of an item\n\nReturns:\n- int, the maximum value that can be carried in the backpack without exceeding its capacity"... | [
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 knapsack(C, N, items):\n \"\"\"\n Solves the knapsack problem.\n \n Parameters:\n - C: int, capacity of the backpack\n - N: int, number of it... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029723",
"row_id": 29723,
"seed_ids": "[1053]"
} | 0.769229 | Taco_29723 | I | [
"knapsack",
"solve_knapsack_from_input"
] | 2 | [
[
"solve_knapsack_from_input",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f707a8c31787a590ac2b014d4e2f2a6f977717b5 | 6b57c58ce49f7890c6e06446ea618a9c82337453 | |||
v1.0 | instruct | Taco | Taco_29729_I | Harry is hosting a Halloween party and is organizing a treasure hunt for his friends. He has hidden multiple treasure chests around his house and each chest has a lock that can only be opened with a unique key. To add a twist to the game, each participant has a unique number and they can only open treasure chests whose... | def get_combinations(digits):
from itertools import combinations
unique_sums = set()
for i in range(1, len(digits) + 1):
for combo in combinations(digits, i):
unique_sums.add(sum(combo))
return unique_sums
def count_treasure_chests(p, participants, c, chests):
... | from solution import count_treasure_chests
def test_count_treasure_chests_sample():
P = 2
participants = [123, 456]
C = 3
chests = [6, 15, 24]
assert count_treasure_chests(P, participants, C, chests) == [1, 2]
def test_count_treasure_chests_no_chests():
P = 1
participants = [123]
C = 0... | [
{
"docstring": null,
"function_declaration": "def get_combinations(digits):",
"function_name": "get_combinations",
"parameter_list": "(digits)"
},
{
"docstring": null,
"function_declaration": "def count_treasure_chests(p, participants, c, chests):",
"function_name": "count_treasure_c... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_treasure_to_open(participant_numbers, lock_numbers):\n def get_digit_combinations_sums(number):\n from itertools import combinations\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00029729",
"row_id": 29729,
"seed_ids": "[5798]"
} | 0.610822 | Taco_29729 | I | [
"get_combinations",
"count_treasure_chests"
] | 2 | [
[
"count_treasure_chests",
"get_combinations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f6305e79bb73305e5ca1b7de91774f4df33d23b | 51e82d8686c2091047beae829c5e80f8cae75cf5 | |||
v1.0 | instruct | Taco | Taco_29735_I | Write a program to find the perimeter of a polygon given its vertices in a 2D plane. The polygon is defined by a list of points \((x_i, y_i)\) for \(i = 0\) to \(n-1\). The points are listed in a counter-clockwise order and the last point should be connected to the first point to close the polygon.
The perimeter of t... | import math
def calculate_distance(p1, p2):
"""
Helper function to calculate the Euclidean distance between two points.
"""
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
def polygon_perimeter(points):
"""
Function to calculate the perimeter of a polygon given its vertices.
"""
... | from solution import calculate_distance, polygon_perimeter, process_input
def test_calculate_distance():
assert calculate_distance((0, 0), (0, 1)) == 1.0
assert calculate_distance((0, 0), (1, 1)) == math.sqrt(2)
assert calculate_distance((1, 0), (0, 1)) == math.sqrt(2)
def test_polygon_perimeter_square():... | [
{
"docstring": "Helper function to calculate the Euclidean distance between two points.",
"function_declaration": "def calculate_distance(p1, p2):",
"function_name": "calculate_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": "Function to calculate the perimeter of a polygon given i... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Returns the Euclidean distance between two points p1 and p2.\n \"\"\"\n return math.sqrt((p1[... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029735",
"row_id": 29735,
"seed_ids": "[9743]"
} | 0.681362 | Taco_29735 | I | [
"calculate_distance",
"polygon_perimeter",
"process_input"
] | 3 | [
[
"polygon_perimeter",
"calculate_distance"
],
[
"process_input",
"polygon_perimeter"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 638585b0d40cc11b6c99697364c9b9aacf82e189 | bd6a0ffd9ed1d9aec73099ae594a9efd90357997 | |||
v1.0 | instruct | Taco | Taco_29750_I | Given an array of integers representing heights of adjacent sections of a wall, design an algorithm to find the minimum number of bricks that need to be removed so that the remaining wall is consistently decreasing in height from left to right.
The wall is represented by an array where each element denotes the height ... | def min_removals_to_decreasing_wall(n, heights):
"""
This function finds the minimum number of bricks to be removed
to ensure the wall is consistently decreasing in height from
left to right.
Parameters:
n (int): The number of sections in the wall.
heights (List[int]): A list of heights o... | def test_min_removals_to_decreasing_wall():
assert min_removals_to_decreasing_wall(6, [5, 3, 8, 6, 2, 9]) == 3
assert min_removals_to_decreasing_wall(5, [3, 1, 4, 2, 5]) == 3
assert min_removals_to_decreasing_wall(7, [9, 8, 7, 6, 5, 4, 3]) == 0
assert min_removals_to_decreasing_wall(4, [1, 2, 3, 4]) == ... | [
{
"docstring": "This function finds the minimum number of bricks to be removed \nto ensure the wall is consistently decreasing in height from \nleft to right.\n\nParameters:\nn (int): The number of sections in the wall.\nheights (List[int]): A list of heights of sections of the wall.\n\nReturns:\nint: The minim... | [
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 min_bricks_to_remove(heights):\n \"\"\"\n Returns the minimum number of bricks that need to be removed so that the remaining wall is consistently\n de... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029750",
"row_id": 29750,
"seed_ids": "[18504]"
} | 0.67505 | Taco_29750 | I | [
"min_removals_to_decreasing_wall",
"lower_bound"
] | 2 | [
[
"min_removals_to_decreasing_wall",
"lower_bound"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b6e50d6ccb4c244dcb8a2333825d9b3644d6447b | 9299dda8de978e2b1a020e226b2b8d2b70f895eb | |||
v1.0 | instruct | Taco | Taco_29764_I | Write a program that determines if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Print "YES" if the string is a palindrome, "NO" if not.
Constraints
* 1 ≤ length of st... | def is_palindrome(s):
"""
Determines if the given string is a palindrome ignoring spaces, punctuation, and capitalization.
"""
import re
cleaned = re.sub(r'[^A-Za-z0-9]', '', s).lower()
return cleaned == cleaned[::-1]
def check_palindromes(n, strings):
results = []
for s in strings:
... | from solution import is_palindrome, check_palindromes
def test_is_palindrome():
assert is_palindrome("A man a plan a canal Panama") == True
assert is_palindrome("racecar") == True
assert is_palindrome("Hello World") == False
assert is_palindrome("No 'x' in Nixon") == True
assert is_palindrome("Was ... | [
{
"docstring": "Determines if the given string is a palindrome ignoring spaces, punctuation, and capitalization.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def check_palindr... | [
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(s):\n \"\"\"\n Determines if the given string is a palindrome.\n \n Parameters:\n s (str): The input string to check\n \n Re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029764",
"row_id": 29764,
"seed_ids": "[5291]"
} | 0.800403 | Taco_29764 | I | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 31d0f0f89c7f940541e651c02e84ff5586138392 | 9e8d037840f817d3c998a70754c8b6ca160bdd50 | |||
v1.0 | instruct | Taco | Taco_29826_I | You are given a sequence of balloons, each balloon has a number written on it. You are allowed to burst the balloons. When you burst a balloon, the i-th balloon, you gain points equal to `nums[i-1] * nums[i] * nums[i+1]`. After the burst, the left and right balloons then become adjacent. You can burst the balloons in a... | def maxCoins(nums):
"""
Maximize points by bursting balloons.
"""
nums = [1] + nums + [1]
n = len(nums)
dp = [[0] * n for _ in range(n)]
for length in range(2, n):
for left in range(0, n - length):
right = left + length
for k in range(left + 1, right):
... | from solution import maxCoins_from_input
def test_maxCoins_example():
assert maxCoins_from_input(4, [3, 1, 5, 8]) == 167
def test_maxCoins_one_balloon():
assert maxCoins_from_input(1, [3]) == 3
def test_maxCoins_two_balloons():
assert maxCoins_from_input(2, [3, 1]) == 6
def test_maxCoins_all_same():
... | [
{
"docstring": "Maximize points by bursting balloons.",
"function_declaration": "def maxCoins(nums):",
"function_name": "maxCoins",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def maxCoins_from_input(n, nums):",
"function_name": "maxCoins_from_input",
... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maxCoins(nums):\n \"\"\"\n Returns the maximum coins/burst points that can be collected by bursting the balloons wisely.\n \"\"\"\n n = len(nums)\n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00029826",
"row_id": 29826,
"seed_ids": "[612]"
} | 0.614814 | Taco_29826 | I | [
"maxCoins",
"maxCoins_from_input"
] | 2 | [
[
"maxCoins_from_input",
"maxCoins"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a27e660c0b4dee12ae3c4ac6a22799db205e9586 | e98c31c686dd6924183bf196239429ec6cd35562 | |||
v1.0 | instruct | Taco | Taco_29881_I | You are given a list of points in a 2D plane, each represented by their x and y coordinates. Your task is to determine if there exists a circle that contains at least three of these points on its circumference.
Note:
1. The circle is said to contain a point if the point lies exactly on its circumference.
2. Consider a... | from math import isclose
def check_collinear(p1, p2, p3):
"""
Check if three points are collinear.
"""
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
return (y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)
def find_circle(points):
n = len(points)
for i in range(n):
for j in range(i+1, n... | from solution import circle_from_points
def test_circle_from_points_sample1():
assert circle_from_points(4, ["0 0", "1 0", "0 1", "1 1"]) == "yes"
def test_circle_from_points_sample2():
assert circle_from_points(3, ["0 0", "1 2", "3 6"]) == "no"
def test_circle_from_points_exactly_three_points_non_collinear(... | [
{
"docstring": "Check if three points are collinear.",
"function_declaration": "def check_collinear(p1, p2, p3):",
"function_name": "check_collinear",
"parameter_list": "(p1, p2, p3)"
},
{
"docstring": null,
"function_declaration": "def find_circle(points):",
"function_name": "find_c... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom math import isclose\n\ndef calculate_circle_center(x1, y1, x2, y2, x3, y3):\n \"\"\"\n Calculate the center of the c... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029881",
"row_id": 29881,
"seed_ids": "[22913]"
} | 0.716397 | Taco_29881 | I | [
"check_collinear",
"find_circle",
"circle_from_points"
] | 3 | [
[
"circle_from_points",
"find_circle"
],
[
"find_circle",
"check_collinear"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6ca5872061e7f4988a7997f38c426db0593e8ceb | 3664b76d6afae807b6d9cda9583b138472752fff | |||
v1.0 | instruct | Taco | Taco_29922_I | You are given a list of N integers. Your task is to find the length of the longest subsequence which is strictly increasing and consists of prime numbers only.
Note: A subsequence is derived from the list by deleting some or no elements without changing the order of the remaining elements.
------ Input Format ------
... | from bisect import bisect_left
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
limit = int(n**0.5) + 1
for i in range(3, limit, 2):
if n % i == 0:
return False
... | from solution import is_prime, longest_increasing_prime_subsequence, 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(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the length of the longest strictly increasing subsequence of prime numbers.",
"function_declaration": "def longe... | [
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 bisect\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029922",
"row_id": 29922,
"seed_ids": "[1341]"
} | 0.745682 | Taco_29922 | I | [
"is_prime",
"longest_increasing_prime_subsequence",
"process_test_cases",
"example_usage"
] | 4 | [
[
"example_usage",
"process_test_cases"
],
[
"longest_increasing_prime_subsequence",
"is_prime"
],
[
"process_test_cases",
"longest_increasing_prime_subsequence"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | afcd52a985a70d3c0a5c67983fb7abd6ad7a5f16 | f3778accc0995391ec6914ba1c858cf6147df5f2 | |||
v1.0 | instruct | Taco | Taco_29930_I | Your task is to write a function that takes an integer array and returns the "persistence" of that number. The persistence of a number is the number of times you must multiply the digits in the number until you reach a single digit.
For example, the persistence of 39 is three because 3*9=27, 2*7=14, and 1*4=4. Likewis... | from typing import List
def digit_product(n: int) -> int:
result = 1
while n > 0:
result *= n % 10
n //= 10
return result
def persistence(arr: List[int]) -> List[int]:
if not arr:
return []
def calculate_persistence(n: int) -> int:
count = 0
while n >= ... | from solution import persistence
def test_persistence_single_digits():
assert persistence([4, 5, 6]) == [0, 0, 0]
def test_persistence_multiple_digits():
assert persistence([39, 999, 25]) == [3, 4, 2]
def test_persistence_mixed_numbers():
assert persistence([39, 999, 4, 0]) == [3, 4, 0, 0]
def test_pers... | [
{
"docstring": null,
"function_declaration": "def digit_product(n):",
"function_name": "digit_product",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def persistence(arr):",
"function_name": "persistence",
"parameter_list": "(arr)"
},
{
"docstri... | [
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 digit_product(n: int) -> int:\n result = 1\n while n > 0:\n result *= n % 10\n n //= 10\n return result\n\nde... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029930",
"row_id": 29930,
"seed_ids": "[8141]"
} | 0.528756 | Taco_29930 | I | [
"digit_product",
"persistence"
] | 2 | [
[
"persistence",
"digit_product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06a69d6e7df8bf54e1091ce01ba7c9d69140d389 | 2d439cb6e86eac8451132b120856a703fda98510 | |||
v1.0 | instruct | Taco | Taco_29976_I | Encrypting and Decrypting Messages with Caesar Cipher
Caesar Cipher is one of the simplest and most widely known encryption techniques. In this method, each letter in the plaintext is shifted a certain number of places down or up the alphabet.
Let's implement both encryption and decryption using the Caesar Cipher tec... | def caesar_encrypt(message: str, shift: int) -> str:
def shift_char(c, shift):
if 'a' <= c <= 'z':
return chr((ord(c) - ord('a') + shift) % 26 + ord('a'))
elif 'A' <= c <= 'Z':
return chr((ord(c) - ord('A') + shift) % 26 + ord('A'))
else:
return c
... | from solution import caesar_encrypt, caesar_decrypt
def test_caesar_encrypt():
assert caesar_encrypt("Hello, World!", 3) == "Khoor, Zruog!"
assert caesar_encrypt("Attack at dawn!", 5) == "Fyyfhp fy ifbs!"
assert caesar_encrypt("Python", 13) == "Clguba"
assert caesar_encrypt("abcdefghijklmnopqrstuvwxyz"... | [
{
"docstring": null,
"function_declaration": "def caesar_encrypt(message, shift):",
"function_name": "caesar_encrypt",
"parameter_list": "(message, shift)"
},
{
"docstring": null,
"function_declaration": "def caesar_decrypt(encrypted_message, shift):",
"function_name": "caesar_decryp... | [
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 caesar_encrypt(message: str, shift: int) -> str:\n encrypted_message = []\n \n for char in message:\n if char.isalpha():\n shift_amo... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029976",
"row_id": 29976,
"seed_ids": "[19951]"
} | 0.75866 | Taco_29976 | I | [
"caesar_encrypt",
"caesar_decrypt"
] | 2 | [
[
"caesar_decrypt",
"caesar_encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9115838ca67423a0344a6e4e186b965a877b6f4 | e7c0d6ff5399e27028cbaf7848cb436f8ac32374 | |||
v1.0 | instruct | Taco | Taco_29998_I | Given a sequence of n integers a1, a2, ..., an, find the length of the longest increasing subsequence (LIS) where the difference between consecutive elements in the subsequence is at most k.
Constraints
* 1 ≤ n ≤ 1000
* 1 ≤ ai ≤ 10^9 (1 ≤ i ≤ n)
* 1 ≤ k ≤ 10^9
Input
The input is given in the following format:
> n ... | def longest_increasing_subsequence_with_limit(n, k, sequence):
# Initialize DP array where dp[i] represents the length of the LIS ending at index i
dp = [1] * n
# Populate the DP array
for i in range(1, n):
for j in range(i):
if sequence[i] > sequence[j] and sequence[i] - sequen... | from solution import lis_within_limit
def test_case_1():
input_str = "5 3\n1 3 5 10 12"
assert lis_within_limit(input_str) == 3
def test_case_2():
input_str = "6 2\n1 2 3 4 5 6"
assert lis_within_limit(input_str) == 6
def test_case_3():
input_str = "6 1\n10 20 30 40 50 60"
assert lis_within_l... | [
{
"docstring": null,
"function_declaration": "def longest_increasing_subsequence_with_limit(n, k, sequence):",
"function_name": "longest_increasing_subsequence_with_limit",
"parameter_list": "(n, k, sequence)"
},
{
"docstring": null,
"function_declaration": "def lis_within_limit(input_st... | [
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 longest_increasing_subsequence_with_diff_k(n, k, a):\n dp = [1] * n # dp[i] will store the length of the LIS ending at i with the given condition\n\n fo... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029998",
"row_id": 29998,
"seed_ids": "[21901]"
} | 0.819397 | Taco_29998 | I | [
"longest_increasing_subsequence_with_limit",
"lis_within_limit"
] | 2 | [
[
"lis_within_limit",
"longest_increasing_subsequence_with_limit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5733ec48d0d7b244c60497c75a393d8d952fde8a | dbc5cd391eaf5e48350fa6df19bf238765ea2c61 | |||
v1.0 | instruct | Taco | Taco_30002_I | You are given an integer array `nums` of length `n` (1 ≤ n ≤ 100,000) and an integer `target`. Your task is to find the indices of the two numbers such that they add up to `target`. Assume that each input would have exactly one solution, and you may not use the same element twice.
The answer should be returned as a li... | def two_sum(nums, target):
"""
Returns the indices of the two numbers such that they add up to target.
"""
index_map = {} # Stores number and its index
for index, num in enumerate(nums):
complement = target - num
if complement in index_map:
return sorted([index_map[compl... | from solution import two_sum, find_two_sum_indices
def test_example_1():
assert find_two_sum_indices(5, 9, [2, 7, 11, 15, 4]) == [0, 1]
def test_example_2():
assert find_two_sum_indices(4, 6, [3, 2, 4, 7]) == [1, 2]
def test_no_solution():
assert find_two_sum_indices(4, 10, [1, 2, 3, 4]) == [] # None ex... | [
{
"docstring": "Returns the indices of the two numbers such that they add up to target.",
"function_declaration": "def two_sum(nums, target):",
"function_name": "two_sum",
"parameter_list": "(nums, target)"
},
{
"docstring": null,
"function_declaration": "def find_two_sum_indices(n, targ... | [
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 two_sum_indices(nums, target):\n \"\"\"\n Finds the indices of the two numbers in `nums` that add up to `target`.\n \n Args:\n nums : List of in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030002",
"row_id": 30002,
"seed_ids": "[7071]"
} | 0.715825 | Taco_30002 | I | [
"two_sum",
"find_two_sum_indices"
] | 2 | [
[
"find_two_sum_indices",
"two_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60252078047e17d302a1ec5f1d411140026e3bbe | 8c4e69f3a8a46749e8c071cc7ab71d3750d6f14d | |||
v1.0 | instruct | Taco | Taco_30017_I | Two friends, Maya and Jacob, love playing number games. They recently discovered a new game based on prime factorization and decided to challenge each other. The game starts with an array of positive integers, and the players take turns. During a turn, a player must choose an element from the array and replace it with ... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def prime_factors(n):
factors = []
whi... | from solution import is_prime, prime_factors, choose_best_prime_factors, who_wins_game
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(13)
assert not is_prime(15)
def test_prime_factors():
assert prime_factors(4) == [2, 2... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
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 if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030017",
"row_id": 30017,
"seed_ids": "[18551]"
} | 0.691679 | Taco_30017 | I | [
"is_prime",
"prime_factors",
"choose_best_prime_factors",
"who_wins_game"
] | 4 | [
[
"choose_best_prime_factors",
"is_prime"
],
[
"choose_best_prime_factors",
"prime_factors"
],
[
"who_wins_game",
"choose_best_prime_factors"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 6fc3903ce55a113b2ea26666c0e99692f56b80ad | a6ffb3311055ca40c7b45f094fa4b33fb6a5608d | |||
v1.0 | instruct | Taco | Taco_30031_I | A group of adventurers finds themselves at the entrance of an ancient labyrinth. The labyrinth consists of a series of chambers connected by tunnels. Each chamber has a certain number of treasures and some traps which can reduce the party's health if not carefully navigated. The goal of the adventurers is to collect th... | import heapq
def optimal_path(n, h, chambers_info, connections):
# Parse inputs
treasures = {chamber: treasures for chamber, treasures, _ in chambers_info}
traps = {chamber: traps for chamber, _, traps in chambers_info}
adj = {i: [] for i in range(1, n + 1)}
for a, b, c in connections:
adj[... | def test_labyrinth_solver():
input_str = "5 1000\n1 10 0\n2 20 5\n3 30 10\n4 40 15\n5 50 20\n1 2 200\n2 3 150\n2 4 300\n2 5 500\n3 4 100\n4 5 250"
expected_output = [1, 2, 3, 4, 5]
assert labyrinth_solver(input_str) == expected_output
def test_labyrinth_solver_multiple_paths():
input_str = "4 1000\n1 1... | [
{
"docstring": null,
"function_declaration": "def optimal_path(n, h, chambers_info, connections):",
"function_name": "optimal_path",
"parameter_list": "(n, h, chambers_info, connections)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": ... | [
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": "import heapq\n\ndef labyrinth_optimal_path(chambers, connections, initial_health):\n n = len(chambers)\n graph = {i: [] for i in range(1, n + 1)}\n \n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00030031",
"row_id": 30031,
"seed_ids": "[7120]"
} | 0.6121 | Taco_30031 | I | [
"optimal_path",
"parse_input",
"labyrinth_solver"
] | 3 | [
[
"labyrinth_solver",
"optimal_path"
],
[
"labyrinth_solver",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | d9397404e69a40d601edbe1795e5d59c0f9d653a | 9b23a414d5c0f95cd58c40b77528228c74aeaf68 | |||
v1.0 | instruct | Taco | Taco_30117_I | Hana is the owner of a large orchard with various types of fruit trees. She has hired several gardeners to take care of the trees. Each gardener is assigned to a specific section of the orchard and has access to a distinct set of trees for maintenance. However, the gardeners need to periodically share certain resources... | def dfs(node, visited, graph):
stack = [node]
while stack:
current = stack.pop()
for neighbor in graph[current]:
if not visited[neighbor]:
visited[neighbor] = True
stack.append(neighbor)
def min_additional_edges(n, m, edges):
graph = [[] for _ in ... | def test_min_additional_edges():
test_cases = [
(4, 2, [(1, 2), (2, 3)]),
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(5, 1, [(4, 5)])
]
expected = [1, 0, 3]
assert process_test_cases(test_cases) == expected
def test_min_additional_edges_single_component():
test_cases = [
... | [
{
"docstring": null,
"function_declaration": "def dfs(node, visited, graph):",
"function_name": "dfs",
"parameter_list": "(node, visited, graph)"
},
{
"docstring": null,
"function_declaration": "def min_additional_edges(n, m, edges):",
"function_name": "min_additional_edges",
"pa... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = fi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030117",
"row_id": 30117,
"seed_ids": "[23587]"
} | 0.641532 | Taco_30117 | I | [
"dfs",
"min_additional_edges",
"process_test_cases"
] | 3 | [
[
"min_additional_edges",
"dfs"
],
[
"process_test_cases",
"min_additional_edges"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | b6b4e8875468bbb173ae682ca0cb24e233e2443a | 17c0c92bf1346609a3d006d39e643536bbf770ab | |||
v1.0 | instruct | Taco | Taco_30160_I | ## Task
Write a function that takes a list of integers and returns a list of strings. For each integer in the input list, the corresponding string in the output list should describe the number in words. Assume the input list only contains non-negative integers less than 100.
## Examples
```
[0, 5, 13, 22, 45] -> ["zer... | def number_to_words(number):
"""
Convert a number less than 100 to its English words representation.
"""
if 0 <= number <= 19:
return ["zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourtee... | from solution import list_of_numbers_to_words
def test_single_digit_numbers():
assert list_of_numbers_to_words([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \
["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
def test_teens():
assert list_of_numbers_to_words([10, 11, 12, 13, 14,... | [
{
"docstring": "Convert a number less than 100 to its English words representation.",
"function_declaration": "def number_to_words(number):",
"function_name": "number_to_words",
"parameter_list": "(number)"
},
{
"docstring": "Convert a list of integers to a list of their English words repres... | [
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 number_to_words(number):\n \"\"\"Convert a number to its word representation\"\"\"\n if not 0 <= number < 100:\n raise ValueError(\"Number out of ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030160",
"row_id": 30160,
"seed_ids": "[22255]"
} | 0.592364 | Taco_30160 | I | [
"number_to_words",
"list_of_numbers_to_words"
] | 2 | [
[
"list_of_numbers_to_words",
"number_to_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 30df8ea49b719c8d496325c48a88e5551bc5dfd8 | 760343b410b48bba31899b331e1e4afef43cb8c1 | |||
v1.0 | instruct | Taco | Taco_30275_I | A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A twin prime is a pair of prime numbers that differ by 2. For example, (3, 5), (11, 13), and (17, 19) are twin primes.
## Task:
Write a function ```twinPrimes(n)``` which returns all twin primes up to n (inclusive)... | def is_prime(num):
"""
Helper function to check if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import twinPrimes
def test_twinPrimes_example():
assert twinPrimes(20) == [(3, 5), (5, 7), (11, 13), (17, 19)]
def test_twinPrimes_small_numbers():
assert twinPrimes(1) == []
assert twinPrimes(2) == []
assert twinPrimes(3) == []
assert twinPrimes(10) == [(3, 5), (5, 7)]
def test_twi... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns all twin primes up to n (inclusive).",
"function_declaration": "def twinPrimes(n):",
... | [
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 is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n re... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030275",
"row_id": 30275,
"seed_ids": "[19784]"
} | 0.719834 | Taco_30275 | I | [
"is_prime",
"twinPrimes"
] | 2 | [
[
"twinPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2e88a2257165f4e8ca02765a62b5b9a9a4c40bdb | 0439c5beb7e50786be57559de3bfe7395591573a | |||
v1.0 | instruct | Taco | Taco_30299_I | A famous magician is performing a trick with a sequence of numbers. Given an integer sequence, he performs a series of operations to transform the sequence into a special form where all prime numbers come before all composite numbers, while preserving the relative order of the prime and composite numbers.
Your task is... | def is_prime(n):
"""
Determines if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
retu... | from solution import is_prime, rearrange_sequence
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(0) ==... | [
{
"docstring": "Determines if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Rearranges the given sequence such that all prime numbers come before all composite numbers,\nwhile preserving the relative... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030299",
"row_id": 30299,
"seed_ids": "[546]"
} | 0.646568 | Taco_30299 | I | [
"is_prime",
"rearrange_sequence"
] | 2 | [
[
"rearrange_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e311428cff6d0609d13cb7aac215641b0f92dc98 | 6425500f688270c3b3fd0ac13d8585bc691446c9 | |||
v1.0 | instruct | Taco | Taco_30340_I | In a distant kingdom, there's a wise king with a peculiar problem. He has a large bookshelf, and he wants to sort all the books on it in non-decreasing order according to their numeric indexes. However, due to his love for programming challenges, he wants to accomplish this with a specific sorting algorithm: Merge Sort... | def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[mid:]
merge_sort(left_half)
merge_sort(right_half)
i = j = k = 0
while i < len(left_half) and j < len(right_half):
if left_half[i] < right_half[j]:
... | import pytest
from solution import merge_sort, sort_books, format_input_output
def test_merge_sort_single_case():
input_array = [64, 34, 25, 12, 22]
merge_sort(input_array)
assert input_array == [12, 22, 25, 34, 64]
def test_merge_sort_empty_array():
input_array = []
merge_sort(input_array)
as... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def sort_books(test_cases):",
"function_name": "sort_books",
"parameter_list": "(test_cases)"
},
{
... | [
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 merge_sort(arr):\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n left = merge_sort(arr[:mid])\n right = merge_sort(arr[mid:])... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030340",
"row_id": 30340,
"seed_ids": "[1172]"
} | 0.619554 | Taco_30340 | I | [
"merge_sort",
"sort_books",
"format_input_output"
] | 3 | [
[
"format_input_output",
"sort_books"
],
[
"sort_books",
"merge_sort"
]
] | 2 | [
"format_input_output"
] | false | [] | false | pytest | true | [] | true | 86d02f5b5ecfcf8d9564ee819052f27f92677f87 | d3ef150c1b1157ee82e49ea307d2917610ce7c4b | |||
v1.0 | instruct | Taco | Taco_30397_I | Write a function that takes an array of integers and an integer k, and rearranges the array in such a way that the element at position i moves to position (i+k) % n, where n is the length of the array. The function should modify the array in place and return the modified array.
Note: You are not allowed to use any add... | def rearrange_array(arr, k):
"""
Rearranges the array such that the element at position i moves to position (i + k) % n.
Modifies the array in place and returns it.
"""
n = len(arr)
k = k % n # To handle cases where k > n
reverse(arr, 0, n - 1)
reverse(arr, 0, k - 1)
reverse(arr, k,... | from solution import rearrange_array
def test_rearrange_basic():
assert rearrange_array([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3]
def test_rearrange_single_element():
assert rearrange_array([1], 0) == [1]
assert rearrange_array([1], 1) == [1]
def test_rearrange_shift_more_than_length():
assert rearrange... | [
{
"docstring": "Rearranges the array such that the element at position i moves to position (i + k) % n.\nModifies the array in place and returns it.",
"function_declaration": "def rearrange_array(arr, k):",
"function_name": "rearrange_array",
"parameter_list": "(arr, k)"
},
{
"docstring": nu... | [
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 rearrange_array(arr, k):\n \"\"\"\n Rearranges the array so that each element at position i moves to position (i+k) % n.\n \n Parameters:\n - ar... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030397",
"row_id": 30397,
"seed_ids": "[13842]"
} | 0.653575 | Taco_30397 | I | [
"rearrange_array",
"reverse"
] | 2 | [
[
"rearrange_array",
"reverse"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f0392c855d0077cf0ddf7717b818d395f798ec33 | 29232b1a9dde01debc6ae046dfaab4fa653b6145 | |||
v1.0 | instruct | Taco | Taco_30401_I | Chef is experimenting with prime numbers and their interesting properties. Today, he is fascinated by the concept of twin primes. A pair of prime numbers (p1, p2) is called twin primes if p2 = p1 + 2. He seeks your help to determine the number of twin prime pairs (p1, p2) such that both p1 and p2 lie within the given r... | def sieve_of_eratosthenes(max_num):
"""
Generates a list to determine if numbers up to max_num are prime.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False
p = 2
while (p * p <= max_num):
if (is_prime[p] == True):
for i in range(p * p, max_num + 1, p... | def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [False, False, True, True, False, True, False, True, False, False, False]
def test_count_twin_primes_example1():
assert count_twin_primes(3, 13) == 3
def test_count_twin_primes_example2():
assert count_twin_primes(10, 19) == 2
def test... | [
{
"docstring": "Generates a list to determine if numbers up to max_num are prime.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Counts the twin prime pairs in the range [L, R]",
... | [
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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list to determine if numbers up to max_num are prime.\n \"\"\"\n is_prime = [True] * (max_nu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030401",
"row_id": 30401,
"seed_ids": "[18078]"
} | 0.681619 | Taco_30401 | I | [
"sieve_of_eratosthenes",
"count_twin_primes"
] | 2 | [
[
"count_twin_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0f58aef6df86fd5a9774e9fdad4aef731d827c16 | 62df11222069ccec88f89a251cc8889a85061760 | |||
v1.0 | instruct | Taco | Taco_30431_I | Given a binary tree, your task is to find the ‘k’th smallest element in this tree. The binary tree nodes contain integer values and follow the standard properties of a binary search tree (i.e., the left subtree of a node contains only nodes with keys less than the node's key, and the right subtree only nodes with keys ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(preorder):
"""
Build a binary search tree from a preorder traversal list.
"""
def helper(preorder_iter):
val = next(preorder_iter)
... | import pytest
from solution import build_tree, kth_smallest, find_kth_smallest
def test_kth_smallest():
# Test Case 1
tree1 = build_tree("5 3 2 null null 4 null null 8 7 null null 9 null null".split())
assert kth_smallest(tree1, 3) == 4
# Test Case 2
tree2 = build_tree("3 1 null null 4 null nu... | [] | [
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": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef build_t... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00030431",
"row_id": 30431,
"seed_ids": "[24255]"
} | 0.654014 | Taco_30431 | I | [
"build_tree",
"kth_smallest",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"build_tree"
],
[
"find_kth_smallest",
"kth_smallest"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5938ddd16c837657e2e15b2433320c6b214e1c21 | 7a79ac0996baa8adc3a5b4d0bd71ce2893922dfc | |||
v1.0 | instruct | Taco | Taco_30477_I | Alex works as an event coordinator and is organizing a series of events across multiple venues. Each event is represented by its start and end times. Some events may overlap in time, and Alex needs to find out the maximum number of overlapping events happening at any moment. Your task is to help Alex by writing a progr... | def find_max_overlap(events):
events.sort(key=lambda x: (x[0], x[1]))
start_times = sorted([event[0] for event in events])
end_times = sorted([event[1] for event in events])
max_overlap = 0
current_overlap = 0
i, j = 0, 0
n = len(events)
while i < n and j < n:
if start... | import pytest
from solution import max_overlapping_events, parse_input
def test_max_overlap():
input_data = "2\n3\n1 4\n2 5\n6 8\n4\n1 10\n2 5\n3 6\n7 11"
T, test_cases = parse_input(input_data)
assert max_overlapping_events(T, test_cases) == [2, 3]
def test_single_event():
input_data = "1\n1\n0 5"
... | [
{
"docstring": null,
"function_declaration": "def find_max_overlap(events):",
"function_name": "find_max_overlap",
"parameter_list": "(events)"
},
{
"docstring": null,
"function_declaration": "def max_overlapping_events(T, test_cases):",
"function_name": "max_overlapping_events",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_overlapping_events(test_cases):\n results = []\n for events in test_cases:\n times = []\n for start, end in events:\n times.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030477",
"row_id": 30477,
"seed_ids": "[8959]"
} | 0.637998 | Taco_30477 | I | [
"find_max_overlap",
"max_overlapping_events",
"parse_input"
] | 3 | [
[
"max_overlapping_events",
"find_max_overlap"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 36ba760fbcd0f1af281708570f32f2068a071269 | 2f3123ef6f18d1a50ba529c1bdb11bd570fdab2e | |||
v1.0 | instruct | Taco | Taco_30491_I | A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Determining if a number is prime is a common problem in programming and number theory.
In this exercise, you are required to write a function that takes a list of integers and returns a list of boolean values indic... | import math
def is_prime(n):
"""
Determines if a number n is prime.
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
limit = math.isqrt(n)
for i in range(3, limit + 1, 2):
... | from solution import is_prime, check_primes
def test_is_prime():
assert is_prime(2) == True, "2 is a prime number"
assert is_prime(3) == True, "3 is a prime number"
assert is_prime(4) == False, "4 is not a prime number"
assert is_prime(29) == True, "29 is a prime number"
assert is_prime(1) == False... | [
{
"docstring": "Determines if a number n is prime.\nReturns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list of strings\nindicating w... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030491",
"row_id": 30491,
"seed_ids": "[9638]"
} | 0.7797 | Taco_30491 | I | [
"is_prime",
"check_primes"
] | 2 | [
[
"check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 83ba2920add9c698dbd55b0e558b0527b93f8f0f | a9357bb40769cc9c617c49a0b9e7fc6fd18da489 | |||
v1.0 | instruct | Taco | Taco_30519_I | Write a program to find the smallest positive integer that is evenly divisible by all numbers from 1 to a given number `n`. In other words, find the Least Common Multiple (LCM) of all numbers from 1 to `n`. For example:
```
For n = 5
Numbers: 1, 2, 3, 4, 5
Smallest positive integer divisible by all these numbers is: 6... | import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def smallest_multiple(n):
"""
Returns the smallest positive integer that is evenly divisible by all numbers from 1 to n.
"""
if n == 1:
return 1
result = 1
... | from solution import smallest_multiple
def test_smallest_multiple_1():
assert smallest_multiple(1) == 1
def test_smallest_multiple_2():
assert smallest_multiple(2) == 2
def test_smallest_multiple_3():
assert smallest_multiple(3) == 6
def test_smallest_multiple_4():
assert smallest_multiple(4) == 12
... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the smallest positive integer that is evenly divisible by all numbers from 1 to n.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple (LCM) of two numbers.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030519",
"row_id": 30519,
"seed_ids": "[13820]"
} | 0.674826 | Taco_30519 | I | [
"lcm",
"smallest_multiple"
] | 2 | [
[
"smallest_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8541ad8582a2cb671462e002255c34b5d8564980 | 52e5da3e60b66471a2e60ff4c514ecbccfab3866 | |||
v1.0 | instruct | Taco | Taco_30544_I | Alicia is learning about sorting algorithms and came across the QuickSort algorithm. She understands the basic idea but wants to explore how QuickSort operates with different pivot selection strategies. One common strategy is to always pick the first element as the pivot. Alicia wants to determine the number of compari... | def quicksort_comparisons(arr, low, high):
if low < high:
pivotIndex = partition(arr, low, high)
left_comparisons = quicksort_comparisons(arr, low, pivotIndex - 1)
right_comparisons = quicksort_comparisons(arr, pivotIndex + 1, high)
total_comparisons = (high - low) + left_comparisons... | def test_total_quicksort_comparisons():
assert total_quicksort_comparisons(4, [4, 3, 2, 1]) == 6
assert total_quicksort_comparisons(5, [1, 2, 3, 4, 5]) == 10
assert total_quicksort_comparisons(1, [1]) == 0
assert total_quicksort_comparisons(3, [3, 2, 1]) == 3
assert total_quicksort_comparisons(6, [6... | [
{
"docstring": null,
"function_declaration": "def quicksort_comparisons(arr, low, high):",
"function_name": "quicksort_comparisons",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort_comparison_count(arr):\n \"\"\"\n Returns the total number of comparisons QuickSort makes when sorting the array using the first element as the... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00030544",
"row_id": 30544,
"seed_ids": "[21691]"
} | 0.492529 | Taco_30544 | I | [
"quicksort_comparisons",
"partition",
"total_quicksort_comparisons"
] | 3 | [
[
"quicksort_comparisons",
"partition"
],
[
"total_quicksort_comparisons",
"quicksort_comparisons"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 0279336ca75f2a9a3c91f64ef03b5dcd8d4eeb48 | 6cf8f62cacfba1d0f1fd68182168c639735d79fa | |||
v1.0 | instruct | Taco | Taco_30654_I | A binary heap is a complete binary tree which satisfies the heap property. The heap can be of two types:
- Max-Heap: In this type of heap, each parent node is greater than or equal to its child nodes.
- Min-Heap: In this type of heap, each parent node is less than or equal to its child nodes.
Given an array arr[] of s... | def heapify_max(arr, n, i):
largest = i
left = 2 * i + 1
right = 2 * i + 2
if left < n and arr[left] > arr[largest]:
largest = left
if right < n and arr[right] > arr[largest]:
largest = right
if largest != i:
arr[i], arr[largest] = arr[largest], arr[i]
... | from solution import buildMaxHeap, buildMinHeap, extractMax, extractMin
def test_buildMaxHeap():
arr = [4, 1, 3, 9, 7]
n = len(arr)
max_heap = buildMaxHeap(arr, n)
assert max_heap == [9, 7, 3, 1, 4]
def test_extractMax():
arr = [4, 1, 3, 9, 7]
n = len(arr)
buildMaxHeap(arr, n)
assert e... | [
{
"docstring": null,
"function_declaration": "def heapify_max(arr, n, i):",
"function_name": "heapify_max",
"parameter_list": "(arr, n, i)"
},
{
"docstring": null,
"function_declaration": "def buildMaxHeap(arr, n):",
"function_name": "buildMaxHeap",
"parameter_list": "(arr, n)"
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heapify_max(arr, n, i):\n \"\"\"Ensure the max-heap property starting from node i.\"\"\"\n largest = i # Initialize largest as root\n left = 2 * i + ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030654",
"row_id": 30654,
"seed_ids": "[24090]"
} | 0.611446 | Taco_30654 | I | [
"heapify_max",
"buildMaxHeap",
"extractMax",
"heapify_min",
"buildMinHeap",
"extractMin"
] | 6 | [
[
"buildMaxHeap",
"heapify_max"
],
[
"buildMinHeap",
"heapify_min"
],
[
"extractMax",
"heapify_max"
],
[
"extractMin",
"heapify_min"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 23eabf6b7df39542a871658a628eb08a8ac8d4f3 | 55ee462bcc270dac15559790f1ba413707f503b5 | |||
v1.0 | instruct | Taco | Taco_30739_I | You are working on a data compression algorithm and need to implement a simple version of the Run-Length Encoding (RLE) algorithm.
Run-Length Encoding is a very basic form of data compression in which consecutive occurrences of the same data value are stored as a single data value and count. For example, in a charact... | def encode_rle(s):
if not s:
return ""
encoded = []
prev_char = s[0]
count = 1
for char in s[1:]:
if char == prev_char:
count += 1
else:
encoded.append(f"{count}{prev_char}")
prev_char = char
count = 1
encoded... | def test_encode_rle():
assert encode_rle("AAAABBBCCDAA") == "4A3B2C1D2A"
assert encode_rle("AAAAAAAAAAAAAA") == "14A"
assert encode_rle("AABBA") == "2A2B1A"
assert encode_rle("ABB") == "1A2B"
assert encode_rle("") == ""
def test_decode_rle():
assert decode_rle("4A3B2C1D2A") == "AAAABBBCCDAA"
... | [
{
"docstring": null,
"function_declaration": "def encode_rle(s):",
"function_name": "encode_rle",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def decode_rle(s):",
"function_name": "decode_rle",
"parameter_list": "(s)"
},
{
"docstring": null,
... | [
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 rle_encode(input_str):\n \"\"\"\n Encodes the input string using Run-Length Encoding (RLE).\n \"\"\"\n if not input_str:\n return \"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030739",
"row_id": 30739,
"seed_ids": "[24155]"
} | 0.679555 | Taco_30739 | I | [
"encode_rle",
"decode_rle",
"run_rle"
] | 3 | [
[
"run_rle",
"decode_rle"
],
[
"run_rle",
"encode_rle"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 3a24b68cf1146451f873cb4de23d2319648e7cd5 | e9be488386e5ea7d953992c3a0cfdf66d5e0de7d | |||
v1.0 | instruct | Taco | Taco_30821_I | Write a function that takes a list of integers and returns a list containing all the integers that have at least one of their digits repeated. The order of the integers in the output list should be the same as their order in the input list.
### Input:
- A list of integers.
### Output:
- A list of integers with at lea... | def has_repeated_digits(n):
"""
Helper function to determine if the given integer has any repeated digits.
"""
digits = {}
n = abs(n) # Handle negative numbers by taking the absolute value
while n > 0:
digit = n % 10
if digit in digits:
return True
digits[dig... | from solution import filter_repeated_digits
def test_filter_repeated_digits_example_1():
assert filter_repeated_digits([123, 112, 456, 998, 789]) == [112, 998]
def test_filter_repeated_digits_example_2():
assert filter_repeated_digits([9876543210, 1234567890, 111222333, 444555666, 12321]) == [111222333, 44455... | [
{
"docstring": "Helper function to determine if the given integer has any repeated digits.",
"function_declaration": "def has_repeated_digits(n):",
"function_name": "has_repeated_digits",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list containing all th... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def repeated_digits(nums):\n \"\"\"\n Returns a list of integers that contain at least one repeated digit. The order\n of the integers in the output list ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030821",
"row_id": 30821,
"seed_ids": "[13383]"
} | 0.701974 | Taco_30821 | I | [
"has_repeated_digits",
"filter_repeated_digits"
] | 2 | [
[
"filter_repeated_digits",
"has_repeated_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efe0c666b36c70c20e3107b9aaa9bf7ea9824cc4 | ad91f894deae72767e43fc9cf080378a1b8bbd91 | |||
v1.0 | instruct | Taco | Taco_30846_I | # Objective
Write a function `minimumMoves` to determine the minimum number of moves required for a knight to move from its starting position `(x1, y1)` to a target position `(x2, y2)` on a standard 8x8 chessboard. A knight moves in an "L" shape: two squares in a horizontal or vertical direction, then one square perpe... | from collections import deque
def is_valid_position(x, y):
"""
Check if the position (x, y) is within the bounds of a standard 8x8 chessboard.
"""
return 1 <= x <= 8 and 1 <= y <= 8
def minimumMoves(x1: int, y1: int, x2: int, y2: int) -> int:
"""
Calculates the minimum number of moves required... | from solution import minimumMoves
def test_minimumMoves_start_equals_target():
assert minimumMoves(1, 1, 1, 1) == 0
assert minimumMoves(4, 4, 4, 4) == 0
def test_minimumMoves_simple_case():
assert minimumMoves(1, 1, 2, 3) == 1
assert minimumMoves(1, 1, 3, 2) == 1
def test_minimumMoves_general_cases()... | [
{
"docstring": "Check if the position (x, y) is within the bounds of a standard 8x8 chessboard.",
"function_declaration": "def is_valid_position(x, y):",
"function_name": "is_valid_position",
"parameter_list": "(x, y)"
},
{
"docstring": "Calculates the minimum number of moves required for a ... | [
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 minimumMoves(x1: int, y1: int, x2: int, y2: int) -> int:\n \"\"\"\n Determines the minimum number of moves required for ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030846",
"row_id": 30846,
"seed_ids": "[4466]"
} | 0.692922 | Taco_30846 | I | [
"is_valid_position",
"minimumMoves"
] | 2 | [
[
"minimumMoves",
"is_valid_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a05ab754102135828356d4893232372789f7b87 | ef0d3207ee62e2d83b0505a90628ff7b81750113 | |||
v1.0 | instruct | Taco | Taco_30856_I | The land of Eldoria has a complex underground water system that supplies water to various villages. The water system can be represented as a graph where each node is a village and each edge is a pipeline connecting two villages. Each pipeline has a certain capacity that represents the maximum amount of water it can sup... | from collections import defaultdict, deque
def bfs(capacity, source, sink, parent):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
u = queue.popleft()
for v in capacity[u]:
if v not in visited and capacity[u][v] > 0:
queue.appen... | import pytest
from solution import minimal_capacity
def test_case_1():
n = 4
m = 5
edges = [
(1, 2, 10),
(2, 3, 5),
(2, 4, 15),
(3, 4, 10),
(4, 3, 10)
]
assert minimal_capacity(n, m, edges) == 5
def test_case_2():
n = 3
m = 3
edges = [
(1... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, capacity, source, sink):",
"function_name": "edmo... | [
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 networkx as nx\n\ndef minimal_capacity_removal(n, m, edges):\n \"\"\"\n Returns the minimal capacity of an edge that, if removed, would result in the ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030856",
"row_id": 30856,
"seed_ids": "[9726]"
} | 0.667326 | Taco_30856 | I | [
"bfs",
"edmonds_karp",
"minimal_capacity"
] | 3 | [
[
"edmonds_karp",
"bfs"
],
[
"minimal_capacity",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c0eb31fbeb1f6b76c33f0d96814be34b0b344827 | 8a39c5aea459f012aaaf636cadc7adaca7b46ecb | |||
v1.0 | instruct | Taco | Taco_30858_I | Problem Statement
You are working on a software that processes geometric shapes. One of the shapes you need to handle is circles. Given a point in 2D space and a list of circles, determine which circles contain the point within their area.
A circle can be described by its center coordinates and its radius. A point is... | import math
def point_in_circle(px, py, cx, cy, r):
"""
Determines if the point (px, py) is inside the circle centered at (cx, cy) with radius r.
"""
distance = math.sqrt((px - cx) ** 2 + (py - cy) ** 2)
return distance <= r
def circles_containing_point(datasets):
"""
Given a list of datas... | from solution import point_in_circle, circles_containing_point
def test_point_in_circle():
assert point_in_circle(5, 5, 1, 1, 3) == False
assert point_in_circle(5, 5, 4, 4, 2) == True
assert point_in_circle(5, 5, 6, 6, 1) == False
assert point_in_circle(7, 9, 8, 10, 5) == True
assert point_in_circl... | [
{
"docstring": "Determines if the point (px, py) is inside the circle centered at (cx, cy) with radius r.",
"function_declaration": "def point_in_circle(px, py, cx, cy, r):",
"function_name": "point_in_circle",
"parameter_list": "(px, py, cx, cy, r)"
},
{
"docstring": "Given a list of datase... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef point_in_circles(px, py, circles):\n count = 0\n for (cx, cy, r) in circles:\n if math.sqrt((px - cx) ** 2 + (py - cy) ** 2) <= r:\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030858",
"row_id": 30858,
"seed_ids": "[19303]"
} | 0.63754 | Taco_30858 | I | [
"point_in_circle",
"circles_containing_point"
] | 2 | [
[
"circles_containing_point",
"point_in_circle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3d0c5325e2a2bbc079342a578a3b09a79f7536b | 297c8a964f38d618051ad4acd482e8703aaf8500 | |||
v1.0 | instruct | Taco | Taco_30900_I | Farmer John has a rectangular field, represented as a grid of size n x m (1 ≤ n, m ≤ 500). Each cell in the grid can either be fertile land or barren land. Bessie the cow loves to graze on fertile land and avoid barren land.
Farmer John wants to help Bessie by determining the maximum size of the square plot of fertile... | def max_fertile_square(n, m, field):
if n == 0 or m == 0:
return 0
dp = [[0] * m for _ in range(n)]
max_side = 0
for i in range(n):
for j in range(m):
if field[i][j] == '1':
if i == 0 or j == 0:
dp[i][j] = 1
else:
... | from solution import max_fertile_square
def test_example1():
n = 5
m = 6
field = [
"101010",
"111111",
"111110",
"111110",
"111000"
]
assert max_fertile_square(n, m, field) == 9
def test_example2():
n = 4
m = 4
field = [
"1010",
"... | [
{
"docstring": null,
"function_declaration": "def max_fertile_square(n, m, field):",
"function_name": "max_fertile_square",
"parameter_list": "(n, m, field)"
},
{
"docstring": null,
"function_declaration": "def max_fertile_square_from_input():",
"function_name": "max_fertile_square_f... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def max_fertile_square(n, m, field):\n if n == 0 or m == 0:\n return 0\n \n dp = [[0] * m for _ in range(n)]\n max_side... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030900",
"row_id": 30900,
"seed_ids": "[9642]"
} | 0.635845 | Taco_30900 | I | [
"max_fertile_square",
"max_fertile_square_from_input"
] | 2 | [
[
"max_fertile_square_from_input",
"max_fertile_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d933855d4cfc4d112e991bdab56dcfa9af44003 | 74f46754775d98387c1c45efb4744b5d8f86fe1f | |||
v1.0 | instruct | Taco | Taco_30901_I | You have been given a sequence of integers, and you are to determine whether it is a "mountain" sequence. A sequence is considered a "mountain" if and only if:
1. There exists a peak element such that elements before the peak are in strictly increasing order.
2. Elements after the peak are in strictly decreasing order... | def is_mountain_sequence(sequence):
n = len(sequence)
if n < 3:
return "NO"
peak_index = 0
# Get to the peak
while peak_index + 1 < n and sequence[peak_index] < sequence[peak_index + 1]:
peak_index += 1
if peak_index == 0 or peak_index == n - 1:
return "NO"
... | from solution import is_mountain_sequence, check_sequences
def test_is_mountain_sequence():
assert is_mountain_sequence([1, 2, 3, 4, 3, 2, 1]) == "YES"
assert is_mountain_sequence([1, 2, 3, 2, 1]) == "YES"
assert is_mountain_sequence([1, 2, 3, 4, 5]) == "NO"
assert is_mountain_sequence([5, 4, 3, 2, 1])... | [
{
"docstring": null,
"function_declaration": "def is_mountain_sequence(sequence):",
"function_name": "is_mountain_sequence",
"parameter_list": "(sequence)"
},
{
"docstring": null,
"function_declaration": "def check_sequences(num_sequences, sequences):",
"function_name": "check_sequen... | [
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_mountain_sequence(sequence):\n n = len(sequence)\n if n < 3:\n return \"NO\"\n \n peak_index = 0\n # Get to the peak\n while peak_i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030901",
"row_id": 30901,
"seed_ids": "[20204]"
} | 0.656083 | Taco_30901 | I | [
"is_mountain_sequence",
"check_sequences"
] | 2 | [
[
"check_sequences",
"is_mountain_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a44f829dc6efaa3ebc3e05116623680743a11b04 | b8760f0631438439f6b188130d06d371a4809cb2 | |||
v1.0 | instruct | Taco | Taco_30904_I | You are a software engineer at a company that stores a vast amount of data across multiple databases. Each database is represented as a grid where each cell contains numerical data. The company wants an efficient way to identify and sum up only the unique integers that appear in each row of each grid. Your task is to i... | def sum_unique_integers_in_rows(grid):
"""
Given a grid (list of lists of integers), returns a list of sums of unique integers for each row.
"""
result = []
for row in grid:
unique_integers = set(row)
row_sum = sum(unique_integers)
result.append(row_sum)
return result
d... | def test_sum_unique_integers_in_rows():
assert sum_unique_integers_in_rows([[1, 2, 3], [4, 4, 4], [1, 2, 2]]) == [6, 4, 3]
assert sum_unique_integers_in_rows([[2, 3], [3, 3], [1, 2]]) == [5, 3, 3]
assert sum_unique_integers_in_rows([[5], [5, 5, 5], [1, 1, 1, 1]]) == [5, 5, 1]
assert sum_unique_integers_... | [
{
"docstring": "Given a grid (list of lists of integers), returns a list of sums of unique integers for each row.",
"function_declaration": "def sum_unique_integers_in_rows(grid):",
"function_name": "sum_unique_integers_in_rows",
"parameter_list": "(grid)"
},
{
"docstring": "Processes multip... | [
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 sum_unique_integers_in_rows(grids):\n result = []\n \n for grid in grids:\n r, c = grid[0]\n data = grid[1:]\n \n for row ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030904",
"row_id": 30904,
"seed_ids": "[15321]"
} | 0.650008 | Taco_30904 | I | [
"sum_unique_integers_in_rows",
"process_grids"
] | 2 | [
[
"process_grids",
"sum_unique_integers_in_rows"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b732fb65dc0e9cfe4f1a32dd8bd0eb3017c0907e | 64d81657ffb2bb0e3d57274dfef7978d02df212b | |||
v1.0 | instruct | Taco | Taco_30960_I | David loves to go on hiking adventures and he always takes his drone with him to capture beautiful landscapes. The drone has a limited battery capacity, and David wants to maximize the number of peaks (highest points in their respective areas) it can record in one trip. Each peak has a significance value, and the drone... | def is_peak(grid, x, y):
"""
Check if a cell (x, y) is a peak in the grid.
"""
n = len(grid)
m = len(grid[0])
current_height = grid[x][y]
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < m ... | import pytest
from solution import max_total_significance
def test_basic_example():
heights = [
[1, 2, 1],
[3, 4, 3],
[1, 8, 1]
]
assert max_total_significance(3, 3, heights) == 8
def test_single_peak():
heights = [
[1, 3, 1],
[2, 4, 2],
[1, 1, 1]
]
... | [
{
"docstring": "Check if a cell (x, y) is a peak in the grid.",
"function_declaration": "def is_peak(grid, x, y):",
"function_name": "is_peak",
"parameter_list": "(grid, x, y)"
},
{
"docstring": "Find all peaks in the grid.",
"function_declaration": "def find_all_peaks(grid):",
"func... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_peaks(grid, n, m):\n peaks = []\n for i in range(n):\n for j in range(m):\n is_peak = True\n for di, dj in [(-1, 0), (1... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030960",
"row_id": 30960,
"seed_ids": "[16652]"
} | 0.595661 | Taco_30960 | I | [
"is_peak",
"find_all_peaks",
"max_total_significance"
] | 3 | [
[
"find_all_peaks",
"is_peak"
],
[
"max_total_significance",
"find_all_peaks"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cf8c704500e91d24683ceecc21db81a5d117a2ed | 24a96af48646e0bd0763f5fa45b5a04e34ce3f4d | |||
v1.0 | instruct | Taco | Taco_30961_I | Problem
James is obsessed with palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Given an integer `n`, he wants to find out the smallest palindrome greater than `n`.
Constraints
* 0 ≤ n ≤ 10^6
Input
The input is given in the following format:
```
n
```
An i... | def is_palindrome(num):
return str(num) == str(num)[::-1]
def smallest_palindrome_greater_than(n):
m = n + 1
while not is_palindrome(m):
m += 1
return m | from solution import is_palindrome, smallest_palindrome_greater_than
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(0) == True
assert is_palindrome(11) == True
assert is_palindrome(10) == False
def test_smallest_palindrome_greate... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def smallest_palindrome_greater_than(n):",
"function_name": "smallest_palindrome_greater_than",
"pa... | [
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 smallest_palindrome_greater_than(n):\n \"\"\"\n Returns the smallest palindromic number greater than n.\n \"\"\"\n def is_palindrome(num):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030961",
"row_id": 30961,
"seed_ids": "[14802]"
} | 0.851188 | Taco_30961 | I | [
"is_palindrome",
"smallest_palindrome_greater_than"
] | 2 | [
[
"smallest_palindrome_greater_than",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2a41a60a46ab8a7c1741f555d18c486ab11b63d2 | bd3797b49a2068695c7edd5abb38e6df8ffaf8b6 | |||
v1.0 | instruct | Taco | Taco_30968_I | In 18th century, Leonhard Euler formulated that numbers of the form $2^{2^n} + 1$ are prime numbers, which were later known as Fermat primes. A Fermat number is defined as follows:
$F_n = 2^{2^n} + 1$
Euler conjectured that all Fermat numbers are prime, but it was later proven false. In fact, except for the first few... | def is_prime(num):
"""Check if a number is prime."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
retur... | import pytest
from solution import is_prime, is_fermat_number, classify_number, process_numbers
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(6)
assert is_prime(7)
def test_is_fermat_number():
assert is_fermat_n... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if a number is a Fermat number.",
"function_declaration": "def is_fermat_number(n):",
"function_name": "is_ferma... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00030968",
"row_id": 30968,
"seed_ids": "[8097]"
} | 0.646132 | Taco_30968 | I | [
"is_prime",
"is_fermat_number",
"classify_number",
"process_numbers"
] | 4 | [
[
"classify_number",
"is_fermat_number"
],
[
"classify_number",
"is_prime"
],
[
"process_numbers",
"classify_number"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b2e6731382bb2367b7126e8f90723321f80fe578 | a53533c4c0ffd10f9b689d6ff3711ab8b575084f | |||
v1.0 | instruct | Taco | Taco_30976_I | Given a linked list, reverse every k nodes of the linked list.
Input
First line of input contains one integer n, which denotes the size of the linked list.
Second line contains n space separated integers representing the elements of the linked list.
Third line contains one integer k, which denotes the number of node... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverseKGroup(head, k):
def reverseLinkedList(head, k):
new_head, ptr = None, head
while k:
next_node = ptr.next
ptr.next = new_head
new_head = ptr
... | import pytest
from solution import reverse_k_nodes
def test_example1():
assert reverse_k_nodes(8, [1, 2, 3, 4, 5, 6, 7, 8], 3) == [3, 2, 1, 6, 5, 4, 7, 8]
def test_single_element_list():
assert reverse_k_nodes(1, [10], 1) == [10]
def test_all_nodes_reversed():
assert reverse_k_nodes(4, [1, 2, 3, 4], 4) =... | [] | [
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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef reverse_k_group(head: ListNode, k: int) -> List... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030976",
"row_id": 30976,
"seed_ids": "[20706]"
} | 0.686856 | Taco_30976 | I | [
"reverseKGroup",
"list_to_linked_list",
"linked_list_to_list",
"reverse_k_nodes"
] | 4 | [
[
"reverse_k_nodes",
"linked_list_to_list"
],
[
"reverse_k_nodes",
"list_to_linked_list"
],
[
"reverse_k_nodes",
"reverseKGroup"
]
] | 3 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 104dc88c6d2612c0993085c4daec9b5098ae5e78 | 2f1e4b3b7a6d8bc6993e25539f08c36ece979f25 | |||
v1.0 | instruct | Taco | Taco_30994_I | Problem E: Protect the Galaxy Research Stations
The United Galactic Federation has stationed a series of research stations in outer space for deep space exploration. Each research station is a sphere with a specific radius. Some of these stations are at risk of colliding due to unpredictable space debris. The Federati... | import math
def calculate_volume(radius):
"""Calculate the volume of a sphere given its radius."""
return (4/3) * math.pi * (radius ** 3)
def combined_force_field_volume(test_cases):
"""Calculate the combined volume of force fields needed for each test case."""
results = []
for case in test_cases:... | from solution import combined_force_field_volume, parse_input, calculate_volume
def test_combined_force_field_volume_single_station():
test_cases = [
[[0, 0, 0, 1]]
]
expected_results = [calculate_volume(1)]
assert combined_force_field_volume(test_cases) == expected_results
def test_combined_f... | [
{
"docstring": "Calculate the volume of a sphere given its radius.",
"function_declaration": "def calculate_volume(radius):",
"function_name": "calculate_volume",
"parameter_list": "(radius)"
},
{
"docstring": "Calculate the combined volume of force fields needed for each test case.",
"f... | [
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\n\ndef calculate_volume(radius):\n \"\"\"Calculate the volume of a sphere given its radius.\"\"\"\n return (4/3) * math.pi * (radius ** 3)\n\ndef... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030994",
"row_id": 30994,
"seed_ids": "[19966]"
} | 0.519701 | Taco_30994 | I | [
"calculate_volume",
"combined_force_field_volume",
"parse_input"
] | 3 | [
[
"combined_force_field_volume",
"calculate_volume"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 77a09867d593731c455de109b66cf6bfbc8b71e9 | 9c269737c72d68c6eb3bf735ab71a27bf7de9a46 | |||
v1.0 | instruct | Taco | Taco_31019_I | Your task is to write a function that takes in a list of integers and returns a new list containing only the prime numbers from the input list. Prime numbers are numbers greater than 1 that have no divisors other than 1 and themselves.
### Detailed Requirements
1. **Function Name**: filter_primes
2. **Input**:
... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
retur... | from solution import filter_primes
def test_filter_primes_mix_numbers():
assert filter_primes([2, 4, 5, 6, 9, 11, 13]) == [2, 5, 11, 13]
def test_filter_primes_negative_and_zero():
assert filter_primes([-3, 0, 1, 4, 7, 8]) == [7]
def test_filter_primes_all_non_primes():
assert filter_primes([0, 4, 6, 8, ... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the input list of integers.",
"function_declaration": "def filt... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031019",
"row_id": 31019,
"seed_ids": "[3510]"
} | 0.627471 | Taco_31019 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7950fc93e942cf0b6f04aaca578c0ab36ee66e82 | 8d29399e3db4f8537dfcc4d239f58393a3d4528b | |||
v1.0 | instruct | Taco | Taco_31038_I | Given an array of integers, return the product of all the unique prime numbers present in the array.
If no prime numbers are present in the array, return 1.
For example:
- Input: [4, 7, 8, 15, 7, 19]
- Output: 133 (since 7 and 19 are the unique prime numbers and 7 * 19 = 133)
- Input: [4, 6, 8, 10]
- Output: 1 (si... | def is_prime(n):
"""Check if a number is prime."""
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 True
def product_of_unique_primes(arr):
"""... | from solution import is_prime, product_of_unique_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_product_of_unique_primes():
assert product_of_unique_primes([4, 7, 8,... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return the product of all unique prime numbers in the given array.\nIf no prime numbers are found, return 1.",
"function_decla... | [
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 Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031038",
"row_id": 31038,
"seed_ids": "[3009]"
} | 0.602529 | Taco_31038 | I | [
"is_prime",
"product_of_unique_primes"
] | 2 | [
[
"product_of_unique_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4950a08defa42461276aa41a4cd81e24ace7f848 | 8ceed4d7e66056276f783568fa50461883ac743d | |||
v1.0 | instruct | Taco | Taco_31113_I | You are given an array B consisting of M positive integers.
Determine whether there exist *two distinct elements* in the array whose sum is a prime number.
Note that two elements are considered distinct if they have different indices in the array, even if their values are the same.
------ Input Format ------
- The ... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def check_prime_sum_exists(test_cases):
re... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_process_input():
input_lines = ["2", "4", "1 4 7 10", "3", "6 8 12"]
expected = [[1, 4, 7, 10], [6, 8, 12]]
assert pro... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def check_prime_sum_exists(test_cases):",
"function_name": "check_prime_sum_exists",
"parameter_list": "(test_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": "def is_prime(n):\n \"\"\"\n Determine if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031113",
"row_id": 31113,
"seed_ids": "[9042]"
} | 0.666318 | Taco_31113 | I | [
"is_prime",
"check_prime_sum_exists",
"process_input",
"main"
] | 4 | [
[
"check_prime_sum_exists",
"is_prime"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | e50388b62808a88401feada2879be17fab558925 | 496f97eefeaa0decb5a0ab07a558234f66d7186c | |||
v1.0 | instruct | Taco | Taco_31129_I | In an ancient kingdom, there exists a mysterious ritual that involves magic stones and pathways. The kingdom is represented as a series of numbered stones, and pathways between them. There is a unique stone from which the magic must begin, and one special stone where the ritual is completed.
The kingdom can be visuali... | import heapq
def dijkstra(n, edges, start):
distances = [float('inf')] * n
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if current_distance > distances[current_node]:
con... | def test_first_example():
n = 5
m = 6
edges_list = [
(1, 2, 2),
(1, 3, 2),
(2, 4, 2),
(3, 4, 2),
(4, 5, 2),
(2, 3, 1)
]
assert minimum_magical_difficulty(n, m, edges_list) == 6
def test_second_example():
n = 4
m = 4
edges_list = [
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def minimum_magical_difficulty(n, m, edges_list):",
"function_name": "minimum_magical_dif... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef minimum_magical_difficulty(n, m, edges):\n from collections import defaultdict\n import heapq\n\n graph = defaultdict(list)\n for u... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031129",
"row_id": 31129,
"seed_ids": "[20595]"
} | 0.630608 | Taco_31129 | I | [
"dijkstra",
"minimum_magical_difficulty"
] | 2 | [
[
"minimum_magical_difficulty",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3799149407e2cffd6088c6701ace45e944587b71 | 1cc54dc25b4b10bae0a5a7d30782db0c78378d45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.