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 | Apps | Apps_12521_I | Given a string s and a list of words dict, determine the length of the shortest transformation sequence from s to a target word t (where t is any word in dict), such that:
1. Only one letter can be changed at a time.
2. Each transformed word must exist in the list of words dict or be the target word t.
Note that the ... | from collections import deque
def is_one_letter_diff(s1, s2):
""" Checks whether strings s1 and s2 differ by exactly one letter """
if len(s1) != len(s2):
return False
diff_count = sum(1 for a, b in zip(s1, s2) if a != b)
return diff_count == 1
def shortest_transformation_length(s, t, dict):
... | from solution import shortest_transformation_length
def test_example1():
s = "hit"
t = "cog"
dict = ["hot","dot","dog","lot","log"]
assert shortest_transformation_length(s, t, dict) == 0
def test_example2():
s = "hit"
t = "cog"
dict = ["hot","dot","dog","lot","log", "cog"]
assert short... | [
{
"docstring": "Checks whether strings s1 and s2 differ by exactly one letter ",
"function_declaration": "def is_one_letter_diff(s1, s2):",
"function_name": "is_one_letter_diff",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Determines the length of the shortest transformation sequence fro... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef ladderLength(s, t, word_dict):\n def all_variants(word):\n variants = set()\n for i in range(len(word)):\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00012521",
"row_id": 12521,
"seed_ids": "[310]"
} | 0.658316 | Apps_12521 | I | [
"is_one_letter_diff",
"shortest_transformation_length"
] | 2 | [
[
"shortest_transformation_length",
"is_one_letter_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ba17a946a350144e14f00aff8024962e65b50f3 | 5ab60f56588c35b8d7a0b4c5808f3181aa8ac198 | |||
v1.0 | instruct | Apps | Apps_12555_I | Max loves convex shapes and geometry. He recently stumbled upon the notion of Convex Hulls and became fascinated by them. Given a set of points in a 2D plane, he wants to find the Convex Hull of these points.
The Convex Hull of a set of 2D points is the smallest convex polygon that contains all the points.
Help Max b... | def cross_product(o, a, b):
"""
Calculates the cross product of vectors OA and OB.
A positive cross product indicates a counter-clockwise turn.
"""
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def convex_hull(points):
"""
Returns the points that make up the convex hu... | from solution import convex_hull
def test_convex_hull_basic():
points = [(0, 0), (1, 1), (2, 2), (1, 2), (2, 0), (3, 1)]
result = convex_hull(points)
expected = [(0, 0), (2, 0), (3, 1), (2, 2), (1, 2)]
assert result == expected
def test_convex_hull_with_collinear_points():
points = [(0, 0), (1, 1)... | [
{
"docstring": "Calculates the cross product of vectors OA and OB.\nA positive cross product indicates a counter-clockwise turn.",
"function_declaration": "def cross_product(o, a, b):",
"function_name": "cross_product",
"parameter_list": "(o, a, b)"
},
{
"docstring": "Returns the points that... | [
0,
0,
0,
0,
1,
1,
0,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def convex_hull(points):\n \"\"\"\n Computes the Convex Hull of a given set of points using Graham's Scan algorithm.\n \n :param points: List of tuples,... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00012555",
"row_id": 12555,
"seed_ids": "[2320]"
} | 0.586023 | Apps_12555 | I | [
"cross_product",
"convex_hull"
] | 2 | [
[
"convex_hull",
"cross_product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3533ffe0937c4022ef4fe83ac903cc9184407685 | da018d9697511b5c4665d528acceefdc18dacd68 | |||
v1.0 | instruct | Apps | Apps_12627_I | Write a program that calculates the highest scoring word(s) from a list of words based on their alphabetical value.
Each word's score is determined by summing the positional values of its letters (a=1, b=2, ... z=26). The program should find the word(s) with the highest score and return them.
-----Input:-----
- First... | def calculate_word_score(word):
"""
Calculate the score of a word based on alphabetical values of its letters.
"""
return sum(ord(char) - ord('a') + 1 for char in word)
def highest_scoring_word(test_cases):
"""
Determine the highest scoring word(s) from a list of test cases.
For each test c... | from solution import calculate_word_score, highest_scoring_word
def test_calculate_word_score():
assert calculate_word_score("hello") == 52
assert calculate_word_score("world") == 72
assert calculate_word_score("abc") == 6
assert calculate_word_score("cba") == 6
assert calculate_word_score("a") == ... | [
{
"docstring": "Calculate the score of a word based on alphabetical values of its letters.",
"function_declaration": "def calculate_word_score(word):",
"function_name": "calculate_word_score",
"parameter_list": "(word)"
},
{
"docstring": "Determine the highest scoring word(s) from a list of ... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def highest_scoring_words(test_cases):\n def word_score(word):\n return sum(ord(char) - ord('a') + 1 for char in word)\n\n results = []\n for words ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012627",
"row_id": 12627,
"seed_ids": "[1589]"
} | 0.704962 | Apps_12627 | I | [
"calculate_word_score",
"highest_scoring_word",
"main"
] | 3 | [
[
"highest_scoring_word",
"calculate_word_score"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ecbf6aabdf9d0a47d2e43cdc99ff603f13b5bcca | 944ed45a429009e573972491a47d7aab4fc36e3b | |||
v1.0 | instruct | Apps | Apps_12651_I | You are given an integer $N$. Your task is to generate the first $N$ rows of Pascal's Triangle.
Pascal's Triangle is defined as follows:
- The topmost row is numbered as row 0 and has a single element, 1.
- Each subsequent row has one more element than the previous row.
- The elements in each row are binomial coeffici... | def generate_pascals_triangle(n):
"""
Generates first n rows of Pascal's triangle.
:param n: The number of rows.
:return: A list of lists containing the first n rows of Pascal's triangle.
"""
triangle = []
for i in range(n):
row = [1] * (i + 1)
for j in range(1, i):
... | import pytest
from solution import generate_pascals_triangle, generate_and_print_pascals_triangle
def test_generate_pascals_triangle():
assert generate_pascals_triangle(1) == [[1]]
assert generate_pascals_triangle(2) == [[1], [1, 1]]
assert generate_pascals_triangle(3) == [[1], [1, 1], [1, 2, 1]]
asser... | [
{
"docstring": "Generates first n rows of Pascal's triangle.\n\n:param n: The number of rows.\n:return: A list of lists containing the first n rows of Pascal's triangle.",
"function_declaration": "def generate_pascals_triangle(n):",
"function_name": "generate_pascals_triangle",
"parameter_list": "(n... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_pascals_triangle(N):\n \"\"\"\n Generates the first N rows of Pascal's Triangle.\n \"\"\"\n triangle = []\n \n for i in range(N):\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012651",
"row_id": 12651,
"seed_ids": "[930]"
} | 0.533355 | Apps_12651 | I | [
"generate_pascals_triangle",
"generate_and_print_pascals_triangle"
] | 2 | [
[
"generate_and_print_pascals_triangle",
"generate_pascals_triangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48871716002bf599c7ed1429945fe6ce8e08838d | a6a5cfefc12c0ff1d69ec86fd1da50f141906fa2 | |||
v1.0 | instruct | Apps | Apps_12678_I | Given a string s of lowercase English letters and a list of words. Find the length of the longest word in the list that can be formed by deleting some characters of the given string s without rearranging the remaining characters.
Return the length of the longest word in the list that can be formed. If no word can be f... | def can_form_by_deleting(s, word):
"""
Check if `word` can be formed from `s` by deleting some characters without rearranging the remaining characters.
"""
it = iter(s)
return all(char in it for char in word)
def find_longest_word(s, words):
"""
Find the length of the longest word in `words... | from solution import find_longest_word
def test_example_1():
assert find_longest_word("abpcplea", ["ale","apple","monkey","plea"]) == 5
def test_example_2():
assert find_longest_word("abpcplea", ["a","b","c"]) == 1
def test_example_3():
assert find_longest_word("abcdef", ["gh", "i", "jkl"]) == 0
def tes... | [
{
"docstring": "Check if `word` can be formed from `s` by deleting some characters without rearranging the remaining characters.",
"function_declaration": "def can_form_by_deleting(s, word):",
"function_name": "can_form_by_deleting",
"parameter_list": "(s, word)"
},
{
"docstring": "Find the ... | [
1,
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form(s, word):\n \"\"\"\n Check if we can form 'word' by deleting some characters from 's' without rearranging the remaining characters.\n \"\"\"\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012678",
"row_id": 12678,
"seed_ids": "[414]"
} | 0.774899 | Apps_12678 | I | [
"can_form_by_deleting",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"can_form_by_deleting"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 59bbf68419f67210284f66f5e9f694fae63e424d | eb728b0bfa891386db1c4706afd65954b50e9ab2 | |||
v1.0 | instruct | Apps | Apps_12828_I | A palindrome is a string that reads the same forward and backward, ignoring spaces, punctuation, and case. Write two functions that work together to determine if a given input string is actually a palindrome.
1. The first function should preprocess the string, removing any non-alphanumeric characters and converting it... | def preprocess_string(input_str: str) -> str:
"""
Preprocess the string by removing non-alphanumeric characters and converting to lowercase.
"""
return ''.join(char.lower() for char in input_str if char.isalnum())
def is_palindrome(input_str: str) -> bool:
"""
Determine if the given input strin... | from solution import preprocess_string, is_palindrome
def test_preprocess_string():
assert preprocess_string("A man, a plan, a canal, Panama!") == "amanaplanacanalpanama"
assert preprocess_string("No lemon, no melon") == "nolemonnomelon"
assert preprocess_string("Hello, World!") == "helloworld"
def test_i... | [
{
"docstring": "Preprocess the string by removing non-alphanumeric characters and converting to lowercase.",
"function_declaration": "def preprocess_string(input_str):",
"function_name": "preprocess_string",
"parameter_list": "(input_str)"
},
{
"docstring": "Determine if the given input stri... | [
1,
0,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef preprocess_string(input_str: str) -> str:\n \"\"\"\n Remove non-alphanumeric characters from the string and convert to lowercase.\n \n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012828",
"row_id": 12828,
"seed_ids": "[1644]"
} | 0.81744 | Apps_12828 | I | [
"preprocess_string",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"preprocess_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70906abbef60f41bd51f513aa2b1589931171279 | 7ade19baee4d2200aef7028545f97de66982f4e1 | |||
v1.0 | instruct | Apps | Apps_12870_I | ## Task
You have been given a two-dimensional grid of characters, and a list of words. Your task is to find if each word in the list exists in the grid. A word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are horizontally or vertically neighboring. The same letter cell may not ... | def exist(board, word):
rows, cols = len(board), len(board[0])
def backtrack(r, c, index):
if index == len(word):
return True
if r < 0 or r >= rows or c < 0 or c >= cols or board[r][c] != word[index]:
return False
# mark the cell as visited by tempor... | from solution import word_search
def test_word_search_example1():
grid = [['A', 'B', 'C', 'E'],
['S', 'F', 'C', 'S'],
['A', 'D', 'E', 'E']]
words = ['ABCCED', 'SEE', 'ABCB']
assert word_search(grid, words) == [True, True, False]
def test_word_search_single_letter_grid():
grid =... | [
{
"docstring": null,
"function_declaration": "def exist(board, word):",
"function_name": "exist",
"parameter_list": "(board, word)"
},
{
"docstring": null,
"function_declaration": "def word_search(grid, words):",
"function_name": "word_search",
"parameter_list": "(grid, words)"
... | [
0,
1,
0,
0,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def exist(grid, word):\n rows, cols = len(grid), len(grid[0])\n \n def dfs(r, c, i):\n if i == len(word):\n return True\n if r < 0... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00012870",
"row_id": 12870,
"seed_ids": "[4068]"
} | 0.731384 | Apps_12870 | I | [
"exist",
"word_search"
] | 2 | [
[
"word_search",
"exist"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 534c532e331aef886d4d562435486cc91dc9e4fd | 8440ae00d6cb65fff87fbeb3c96fb440063f61e6 | |||
v1.0 | instruct | Apps | Apps_12959_I | Aman is learning about the concept of strong numbers. A strong number is a special number whose sum of the factorial of digits is equal to the original number. For example, 145 is a strong number because 1! + 4! + 5! = 145.
Aman's teacher has given him the task to find all strong numbers within a given range. Can you... | import math
def is_strong_number(num):
"""
Determines whether the given number is a strong number.
"""
return num == sum(math.factorial(int(digit)) for digit in str(num))
def find_strong_numbers(a, b):
"""
Returns a list of strong numbers within the given range [a, b].
"""
return [x fo... | from solution import is_strong_number, find_strong_numbers
def test_is_strong_number():
assert is_strong_number(1) == True
assert is_strong_number(2) == True
assert is_strong_number(145) == True
assert is_strong_number(154) == False
def test_find_strong_numbers_small_range():
assert find_strong_nu... | [
{
"docstring": "Determines whether the given number is a strong number.",
"function_declaration": "def is_strong_number(num):",
"function_name": "is_strong_number",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of strong numbers within the given range [a, b].",
"function_de... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_strong_number(num):\n \"\"\"\n Returns True if num is a strong number, else False.\n \"\"\"\n original_num = num\n sum_of_facto... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012959",
"row_id": 12959,
"seed_ids": "[1122]"
} | 0.618942 | Apps_12959 | I | [
"is_strong_number",
"find_strong_numbers"
] | 2 | [
[
"find_strong_numbers",
"is_strong_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3a001fb6df2a7b95b2ad3d771eee5ec0af89080 | 4ae50cae7cb83cb67815d4f251609e8248f769dd | |||
v1.0 | instruct | Apps | Apps_12960_I | A company is designing a fleet of autonomous drones that need to patrol a rectangular area divided into a grid of cells. Each cell is represented by a pair of coordinates `[x, y]`. The drones collect data in key locations and must visit all target cells efficiently.
You are to write a function called `optimal_drone_ro... | from itertools import permutations
def manhattan_distance(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
def optimal_drone_route(grid_size, start_point, target_points):
points = [start_point] + target_points
n = len(points)
# Calculate the distance matrix
dist = [[0] * n for _ in ran... | from solution import optimal_drone_route
def test_single_target_point():
grid_size = (4, 4)
start_point = (0, 0)
target_points = [(1, 1)]
assert optimal_drone_route(grid_size, start_point, target_points) == (4, [(0, 0), (1, 1), (0, 0)])
def test_multiple_target_points():
grid_size = (4, 4)
sta... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(p1, p2):",
"function_name": "manhattan_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def optimal_drone_route(grid_size, start_point, target_points):",
"function_name": "opt... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef calculate_manhattan_distance(p1, p2):\n \"\"\"\n Calculate the Manhattan distance between two points.\n \"\"\"\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00012960",
"row_id": 12960,
"seed_ids": "[1738]"
} | 0.620244 | Apps_12960 | I | [
"manhattan_distance",
"optimal_drone_route"
] | 2 | [
[
"optimal_drone_route",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae03d238b75dcd761e3a51f5171f4446f3873336 | 9d2c5a97c92a0e6f6554b6840dd2e50f74550773 | |||
v1.0 | instruct | Apps | Apps_12964_I | Create a function that takes a list of integers as input and returns a list of tuples. Each tuple will contain two elements:
1. The original integer.
2. A boolean that is True if the integer is a palindrome in its binary representation, and False otherwise.
A palindrome is a sequence that reads the same backward as f... | def is_binary_palindrome(number):
"""
Returns True if the binary representation of 'number' is a palindrome, False otherwise.
"""
binary_str = bin(number)[2:] # Convert to binary and remove '0b' prefix
return binary_str == binary_str[::-1]
def binary_palindrome_tuples(integers):
"""
Return... | from solution import binary_palindrome_tuples, is_binary_palindrome
def test_is_binary_palindrome():
assert is_binary_palindrome(3) == True # 3 -> '11'
assert is_binary_palindrome(5) == True # 5 -> '101'
assert is_binary_palindrome(6) == False # 6 -> '110'
assert is_binary_palindrome(9) == True # 9... | [
{
"docstring": "Returns True if the binary representation of 'number' is a palindrome, False otherwise.",
"function_declaration": "def is_binary_palindrome(number):",
"function_name": "is_binary_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of tuples where each ... | [
1,
0,
1,
1,
1,
0,
1,
0,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_palindrome(lst):\n \"\"\"\n Given a list of integers, return a list of tuples where each tuple contains the original integer\n and a boolean ind... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00012964",
"row_id": 12964,
"seed_ids": "[4555]"
} | 0.678721 | Apps_12964 | I | [
"is_binary_palindrome",
"binary_palindrome_tuples"
] | 2 | [
[
"binary_palindrome_tuples",
"is_binary_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 88785d1a2e5795163397a6568aa30bef89af5d4f | de2d062e797f445b6cd6ef2ca207661a8135e6ac | |||
v1.0 | instruct | Apps | Apps_12975_I | Eliza is a botanist tracking the growth patterns of multiple plants. One day, she comes up with a challenge to analyze the health of these plants. Given a string representing the growth rate of plants over several days, she wants to identify if there is a way to partition this string into contiguous substrings such tha... | def is_mountain_sequence(s):
"""
Check if a given string s is a valid mountain sequence.
"""
n = len(s)
if n < 3:
return False
peak_reached = False
i = 1
# Ascend to the peak
while i < n and s[i] > s[i - 1]:
i += 1
# Peak must not be at the beginnin... | def test_is_mountain_sequence():
assert is_mountain_sequence("123") == False
assert is_mountain_sequence("12321") == True
assert is_mountain_sequence("123321") == False
assert is_mountain_sequence("121") == True
def test_can_partition_into_mountains():
assert can_partition_into_mountains("12343... | [
{
"docstring": "Check if a given string s is a valid mountain sequence.",
"function_declaration": "def is_mountain_sequence(s):",
"function_name": "is_mountain_sequence",
"parameter_list": "(s)"
},
{
"docstring": "Check if the string can be partitioned into valid mountain sequences.",
"f... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_mountain_sequence(s, start, end):\n if end - start + 1 < 3:\n return False\n\n peak = start\n # Find the peak\n for i in range(start + 1, ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00012975",
"row_id": 12975,
"seed_ids": "[551]"
} | 0.646002 | Apps_12975 | I | [
"is_mountain_sequence",
"can_partition_into_mountains",
"analyze_growth_patterns"
] | 3 | [
[
"analyze_growth_patterns",
"can_partition_into_mountains"
],
[
"can_partition_into_mountains",
"is_mountain_sequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | a59d0be8ef54fdac9f98d5f3ad0b01bbc3af16e0 | 0623a1e47e339ef8943d7e75bdf4a60bed15c11d | |||
v1.0 | instruct | Apps | Apps_12980_I | In this problem, you are required to normalize a list of numbers for statistical analysis. Normalization transforms the data to a standard scale without distorting differences in the ranges of values. For this exercise, you will use min-max normalization.
The formula for min-max normalization is as follows:
\[ X_{\tex... | def min_max_normalize(numbers):
"""
This function normalizes a list of numbers using min-max normalization.
"""
min_val = min(numbers)
max_val = max(numbers)
# Handling the case where max and min are the same to avoid division by zero
if max_val == min_val:
return [0.00] * len(n... | import pytest
from solution import min_max_normalize, read_input_and_normalize
def test_min_max_normalize_simple_case():
assert min_max_normalize([1, 2, 3, 4, 5]) == [0.00, 0.25, 0.50, 0.75, 1.00]
def test_min_max_normalize_with_large_numbers():
assert min_max_normalize([1000, 2000, 3000, 10000]) == [0.00, 0.... | [
{
"docstring": "This function normalizes a list of numbers using min-max normalization.",
"function_declaration": "def min_max_normalize(numbers):",
"function_name": "min_max_normalize",
"parameter_list": "(numbers)"
},
{
"docstring": "Reads the input text, processes the numbers, and prints ... | [
1,
1,
1,
1,
1,
0,
1,
1,
0,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_max_normalize(data_points):\n \"\"\"\n Normalize a list of data points using min-max normalization.\n\n Args:\n data_points (list of int): List ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012980",
"row_id": 12980,
"seed_ids": "[723]"
} | 0.634706 | Apps_12980 | I | [
"min_max_normalize",
"read_input_and_normalize"
] | 2 | [
[
"read_input_and_normalize",
"min_max_normalize"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 768a642d574f9279954212c6954ab9ec38b82a8d | 988773fd0298a94cf0cf1ab6334c579859fc619d | |||
v1.0 | instruct | Apps | Apps_13032_I | You are organizing a charity run event, and athletes will run on a circular track. Each athlete has a different constant speed, and you need to determine the time at which the two fastest runners meet again at the starting point, assuming they start from the same point at the same time.
Write a function `meetingTime` ... | import math
def lcm(a, b):
"""
Returns the least common multiple of two integers a and b.
"""
return abs(a*b) // math.gcd(a, b)
def meetingTime(speeds):
"""
Returns the time in seconds when the two fastest runners will meet again at the starting point.
Parameters:
speeds (list of ... | from solution import meetingTime
def test_meetingTime_case1():
assert meetingTime([5, 4, 3, 2]) == 20
def test_meetingTime_case2():
assert meetingTime([6, 8, 3]) == 24
def test_meetingTime_case3():
assert meetingTime([10, 15, 20]) == 60
def test_meetingTime_case4():
assert meetingTime([7, 14, 28]) =... | [
{
"docstring": "Returns the least common multiple of two integers a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the time in seconds when the two fastest runners will meet again at the starting point.\n\nPara... | [
0,
0,
1,
0,
0,
0,
0,
1
] | 2 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\nfrom typing import List\n\ndef lcm(a: int, b: int) -> int:\n \"\"\"\n Helper function to compute the Least Common Multip... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013032",
"row_id": 13032,
"seed_ids": "[3269]"
} | 0.522192 | Apps_13032 | I | [
"lcm",
"meetingTime"
] | 2 | [
[
"meetingTime",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6ab2f8fb47bb032b282c964fc4be936295d37d0d | 4acf1db210c43a773f5a35beef2d13d379000eaa | |||
v1.0 | instruct | Apps | Apps_13085_I | Implement a function that processes a list of integers in the "Look-and-say" sequence. The Look-and-say sequence is a sequence in which each term is given by describing the previous term. For example, the sequence starts with "1", which is read off as "one 1" or "11" in the second term, and then "21" for the third term... | def look_and_say(n: int) -> str:
"""
Returns the nth term in the Look-and-say sequence.
"""
if n <= 0:
raise ValueError("Input must be a positive integer")
term = "1"
for _ in range(1, n):
term = next_term(term)
return term
def next_term(term: str) -> str:
... | def test_look_and_say_base_case():
assert look_and_say(1) == "1"
def test_look_and_say_second_term():
assert look_and_say(2) == "11"
def test_look_and_say_third_term():
assert look_and_say(3) == "21"
def test_look_and_say_fourth_term():
assert look_and_say(4) == "1211"
def test_look_and_say_fifth_te... | [
{
"docstring": "Returns the nth term in the Look-and-say sequence.",
"function_declaration": "def look_and_say(n):",
"function_name": "look_and_say",
"parameter_list": "(n)"
},
{
"docstring": "Generates the next term in the Look-and-say sequence from the current term.",
"function_declara... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def look_and_say(n: int) -> str:\n \"\"\"\n Returns the nth term in the Look-and-say sequence.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013085",
"row_id": 13085,
"seed_ids": "[3470]"
} | 0.647451 | Apps_13085 | I | [
"look_and_say",
"next_term"
] | 2 | [
[
"look_and_say",
"next_term"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 75ebccc47d0128b79139d4ccd7375825e671fa38 | 7b7860fdfe8b13e203a21a7e7a7f73c7be936f80 | |||
v1.0 | instruct | Apps | Apps_13086_I | Given a string `s` and an array of strings `words`, return the maximum length of a subsequence of `s` that is also a subsequence of a string in `words`.
A subsequence is defined as a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Exam... | def is_subsequence(s, word):
"""Helper function to check if 'word' is a subsequence of 's'."""
it = iter(s)
return all(char in it for char in word)
def max_subsequence_length(s, words):
"""
Given a string s and an array of strings words, return the maximum length of a subsequence of s
that is a... | from solution import max_subsequence_length
def test_example_1():
assert max_subsequence_length("abcde", ["a", "bb", "acd", "ace"]) == 3
def test_example_2():
assert max_subsequence_length("abcdefg", ["abc", "def", "gh", "cde"]) == 3
def test_example_3():
assert max_subsequence_length("xyz", ["a", "b", "... | [
{
"docstring": "Helper function to check if 'word' is a subsequence of 's'.",
"function_declaration": "def is_subsequence(s, word):",
"function_name": "is_subsequence",
"parameter_list": "(s, word)"
},
{
"docstring": "Given a string s and an array of strings words, return the maximum length ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(sub, s):\n \"\"\"\n Helper function to check if `sub` is a subsequence of `s`.\n \"\"\"\n iter_s = iter(s)\n return all(char in it... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013086",
"row_id": 13086,
"seed_ids": "[434]"
} | 0.80688 | Apps_13086 | I | [
"is_subsequence",
"max_subsequence_length"
] | 2 | [
[
"max_subsequence_length",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f5bb531e373865f190d46d1b1e009459d9aec9f5 | 9e9ef9206bb283963b40c1f4ec09fdeef33e5ff2 | |||
v1.0 | instruct | Apps | Apps_13130_I | A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors (excluding 1). For example, in base 10, the number '58' is a Smith number because:
- Its prime factorization is 2 × 29.
- The sum of its digits: 5 + 8 = 13.
- The sum of the digits of its prime factors: 2 + (2 +... | def digit_sum(n):
"""
Returns the sum of the digits of the given number.
"""
return sum(int(digit) for digit in str(n))
def is_smith_number(n):
"""
Determines if a number is a Smith number.
"""
def prime_factors(n):
"""
Returns the list of prime factors of the given numb... | import pytest
from solution import is_smith_number
def test_is_smith_number_58():
assert is_smith_number(58) == True
def test_is_smith_number_22():
assert is_smith_number(22) == True
def test_is_smith_number_4():
assert is_smith_number(4) == True
def test_is_smith_number_7():
assert is_smith_number(... | [
{
"docstring": "Returns the sum of the digits of the given number.",
"function_declaration": "def digit_sum(n):",
"function_name": "digit_sum",
"parameter_list": "(n)"
},
{
"docstring": "Determines if a number is a Smith number.",
"function_declaration": "def is_smith_number(n):",
"f... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def digit_sum(n):\n \"\"\"\n Calculate the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef prime_factors(n):... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00013130",
"row_id": 13130,
"seed_ids": "[4834]"
} | 0.625555 | Apps_13130 | I | [
"digit_sum",
"is_smith_number"
] | 2 | [
[
"is_smith_number",
"digit_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11993d41df469bf3b9a3f638c20165d844910428 | 822792dddfa0ed9c2c0c07e35aa5a9541eed8438 | |||
v1.0 | instruct | Apps | Apps_13177_I | In a distant land, there is a famous quiz competition called "Tech Trivia". This competition tests the participants on their quick thinking and problem-solving skills with a variety of challenges. One of the challenges involves solving a puzzle related to prime numbers.
You are given two integers M and N. Your task is... | def is_prime(number):
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i = 5
while i * i <= number:
if number % i == 0 or number % (i + 2) == 0:
return False
i += 6
return True
def fi... | from solution import tech_trivia, find_primes_in_range, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(12) == False
def test_find_primes_in_range():
assert find_primes_in_range(10, 20) ... | [
{
"docstring": null,
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
"docstring": null,
"function_declaration": "def find_primes_in_range(M, N):",
"function_name": "find_primes_in_range",
"parameter_list": "(M, N)"
... | [
1,
1,
1,
1,
1,
1,
1,
0,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n retu... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00013177",
"row_id": 13177,
"seed_ids": "[581]"
} | 0.623153 | Apps_13177 | I | [
"is_prime",
"find_primes_in_range",
"tech_trivia"
] | 3 | [
[
"find_primes_in_range",
"is_prime"
],
[
"tech_trivia",
"find_primes_in_range"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 76145e5ce20e7bef9064fe67fcfea2126662f022 | 5fd0a921bbdcb72ad62ab156c4511d3fc918de2b | |||
v1.0 | instruct | Apps | Apps_13178_I | You are given a grid with N$N$ rows and M$M$ columns, where each cell is either empty or contains a tree. A "tree" is represented by a cell with the value 1, and an "empty" cell is represented by the value 0. You can walk from one cell to another if and only if there is a clear path connecting them. A path is said to b... | def largest_clear_path_rectangle(grid, N, M):
if N == 0 or M == 0:
return 0, 0
# Initialize the lookup table for dynamic programming
dp = [[0] * M for _ in range(N)]
# Initialize variables to keep track of the maximum rectangle
max_area = 0
max_rows = 0
max_cols = 0
# ... | from solution import largest_clear_path_rectangle, parse_input, solve_largest_clear_path_rectangle, main
def test_largest_clear_path_rectangle():
grid = ['011', '001', '111']
assert largest_clear_path_rectangle(grid, 3, 3) == (1, 1)
grid = ['0000', '0010', '0010', '0000']
assert largest_clear_path... | [
{
"docstring": null,
"function_declaration": "def largest_clear_path_rectangle(grid, N, M):",
"function_name": "largest_clear_path_rectangle",
"parameter_list": "(grid, N, M)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_text):",
"function_name": "parse_inpu... | [
0,
0,
1,
0,
1,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_clear_path_rectangle(t, test_cases):\n \"\"\"\n Determine the maximum size of the largest clear path rectangle that does not contain any trees wit... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013178",
"row_id": 13178,
"seed_ids": "[1413]"
} | 0.655931 | Apps_13178 | I | [
"largest_clear_path_rectangle",
"parse_input",
"solve_largest_clear_path_rectangle",
"main"
] | 4 | [
[
"solve_largest_clear_path_rectangle",
"largest_clear_path_rectangle"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | dc4e89ba7c2e9f238df8d500dab7f797676b12c7 | c1cdf50e1f60bb02dd26b4e1f8e6a03a752aa09d | |||
v1.0 | instruct | Apps | Apps_13249_I | Implement a function that takes a list of integers and returns a new list where each integer is replaced based on the following rules:
1. If the integer is prime, replace it with the sum of its digits.
2. If the integer is even but not prime, replace it with the average of its non-zero digits (rounded down to the near... | def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def sum_of_digits(n):
return sum(int(digit) for digit in str(n))
def average_of_non_zero_digits(n):
digits = [int(digit) for digit in str(n) if int(digi... | import pytest
from solution import transform_list, is_prime, sum_of_digits, average_of_non_zero_digits, product_of_digits
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(19) == True
assert is_prime(20) == False
def test_sum_of_... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
0,
0,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013249",
"row_id": 13249,
"seed_ids": "[4866]"
} | 0.58601 | Apps_13249 | I | [
"is_prime",
"sum_of_digits",
"average_of_non_zero_digits",
"product_of_digits",
"transform_list"
] | 5 | [
[
"transform_list",
"average_of_non_zero_digits"
],
[
"transform_list",
"is_prime"
],
[
"transform_list",
"product_of_digits"
],
[
"transform_list",
"sum_of_digits"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 85cf5e5f14d437ca0cb582c2db83b482e9c9faf7 | 9452b9b052457c9f1a061a79c803ffa472a5191f | |||
v1.0 | instruct | Apps | Apps_13282_I | In a remote village, there is an ancient festival that requires villagers to arrange lanterns in a specific pattern. The lanterns are arranged in a grid, and each cell in the grid contains one lantern that can either be on ('1') or off ('0'). The aim of the villagers is to determine the largest rectangular area of cons... | def maximalRectangle(grid):
if not grid or not grid[0]:
return 0
num_rows = len(grid)
num_cols = len(grid[0])
max_area = 0
heights = [0] * num_cols
for row in grid:
for col in range(num_cols):
if row[col] == '1':
heights[col] += 1
else:
... | from solution import maximalRectangle
def test_example():
grid = [
["1", "0", "1", "0", "0"],
["1", "0", "1", "1", "1"],
["1", "1", "1", "1", "1"],
["1", "0", "0", "1", "0"]
]
assert maximalRectangle(grid) == 6
def test_smallest_grid_with_1():
grid = [["1"]]
assert ... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_li... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(grid):\n if not grid or not grid[0]:\n return 0\n \n def maximalHistArea(heights):\n stack = []\n max_area = 0\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00013282",
"row_id": 13282,
"seed_ids": "[1791]"
} | 0.708485 | Apps_13282 | I | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17f6e5d650508923b347c18f7125f8a9811b4950 | 3a66072f87772195c4b1509ab5e81a4655d9556c | |||
v1.0 | instruct | Apps | Apps_13308_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 prime number that is either 2 less or 2 more than another prime number, for example, (11, 13), (17, 19), and (29, 31). A twin prime consists of two prime numbers with a difference of 2.
Given an i... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
def... | from solution import twin_prime_count
def test_twin_prime_count():
assert twin_prime_count(10) == 2 # (3, 5) and (5, 7)
assert twin_prime_count(17) == 3 # (3, 5), (5, 7), (11, 13)
assert twin_prime_count(30) == 4 # (3, 5), (5, 7), (11, 13), (17, 19)
assert twin_prime_count(1) == "Not valid"
asse... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the number of twin prime pairs less than or equal to n.",
"function_declaration": "def twin_pri... | [
0,
0,
0,
0,
1,
1,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n *... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013308",
"row_id": 13308,
"seed_ids": "[4228]"
} | 0.67224 | Apps_13308 | I | [
"is_prime",
"twin_prime_count"
] | 2 | [
[
"twin_prime_count",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b1e860c55a92a190ba57e485d69a62eab30ecb05 | bfd19234ed19cfbbf25b67a17eb48df3397f9bf4 | |||
v1.0 | instruct | Apps | Apps_13318_I | Alice is interested in exploring sequences and has designed her own unique mathematical sequence based on a few initial parameters. The sequence $SEQ$ takes the following form:
You are given an integer $X$ and two functions $f1(N)$ and $f2(N)$:
- $f1(N)$: If $N$ is even, $f1(N) = N/2$. If $N$ is odd, $f1(N) = 3*N + 1... | def f1(N):
return N // 2 if N % 2 == 0 else 3 * N + 1
def f2(N):
return N // 4 if N % 2 == 0 else 2 * N + 1
def generate_sequence(X, K):
sequence = [X]
for i in range(K):
sequence.append(f1(sequence[-1]))
sequence.append(f2(sequence[-1]))
return sequence
def answer_queries(X, K, q... | import pytest
from solution import f1, f2, generate_sequence, answer_queries, process_input
def test_f1():
assert f1(4) == 2 # even
assert f1(5) == 16 # odd
def test_f2():
assert f2(4) == 1 # even
assert f2(5) == 11 # odd
def test_generate_sequence():
# X = 7, K = 3: Sequence should be [7, 22... | [
{
"docstring": null,
"function_declaration": "def f1(N):",
"function_name": "f1",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def f2(N):",
"function_name": "f2",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def ... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def f1(N):\n if N % 2 == 0:\n return N // 2\n else:\n return 3 * N + 1\n\ndef f2(N):\n if N % 2 == 0:\n return N // 4\n else:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013318",
"row_id": 13318,
"seed_ids": "[806]"
} | 0.674112 | Apps_13318 | I | [
"f1",
"f2",
"generate_sequence",
"answer_queries",
"process_input"
] | 5 | [
[
"answer_queries",
"generate_sequence"
],
[
"generate_sequence",
"f1"
],
[
"generate_sequence",
"f2"
],
[
"process_input",
"answer_queries"
]
] | 4 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 7e3d5aa927ab6e4c0e6a9ac2166d1a62753802af | 9fe8ae5141b9b4c143cba619b387b29fdf0b5d41 | |||
v1.0 | instruct | Apps | Apps_13328_I | Write a function to identify and sum all unique prime numbers in a given list of integers. The input list will not contain any repeating numbers, and all elements will be valid integers.
```python
sum_primes([2, 3, 5, 7, 11, 13]) # => 41
sum_primes([4, 6, 8, 10, 12]) # => 0
sum_primes([1... | def is_prime(n):
"""
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
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def su... | from solution import sum_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_sum_primes():
assert sum_primes([2, 3, 5, 7, 11, 13... | [
{
"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 the sum of all unique prime numbers in the given list of integers.",
"function_declaration":... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00013328",
"row_id": 13328,
"seed_ids": "[4520]"
} | 0.633199 | Apps_13328 | I | [
"is_prime",
"sum_primes"
] | 2 | [
[
"sum_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d2b05182ede5f6d9621b650992250371844f4743 | df799803140a94b9f6bc9d6cd90e122d4f969299 | |||
v1.0 | instruct | Apps | Apps_13354_I | Alex has recently learned about prime numbers and wants to create a binary array that indicates whether a number is prime or not. Given a number $N$, he needs to construct a binary array of length $N+1$ (i.e., indexed from 0 to $N$), where each position $i$ in the array will have the value 1 if $i$ is a prime number an... | def sieve_of_eratosthenes(max_num):
"""
Function to create a boolean array where True represents that the index is a prime number.
"""
is_prime = [True] * (max_num + 1)
is_prime[0], is_prime[1] = False, False
p = 2
while p * p <= max_num:
if is_prime[p]:
for i in ran... | def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0]
assert sieve_of_eratosthenes(5) == [0, 0, 1, 1, 0, 1]
def test_generate_prime_binary_arrays():
assert generate_prime_binary_arrays(2, [10, 5]) == [
"0 0 1 1 0 1 0 1 0 0 0",
"0 0 1 1 0 1"
... | [
{
"docstring": "Function to create a boolean array where True represents that the index is a prime number.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Function to generate the prim... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_n):\n \"\"\"\n Returns a list where index i contains 1 if i is a prime number and 0 otherwise.\n Uses the Sieve of Eratosthen... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00013354",
"row_id": 13354,
"seed_ids": "[655]"
} | 0.681936 | Apps_13354 | I | [
"sieve_of_eratosthenes",
"generate_prime_binary_arrays"
] | 2 | [
[
"generate_prime_binary_arrays",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 95000e11e53ad418634c40ca57bfb2dd4e982023 | 79fc08168ed5d632d5927d3d3dca5c22218c762d | |||
v1.0 | instruct | Apps | Apps_13374_I | Given a list of integers, write a program to find the sum of all prime numbers in the list.
-----Input-----
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains a list of space-separated integers.
-----Output-----
For each test case, display the sum of all pr... | import math
def is_prime(n):
"""
Check if a number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def su... | from solution import is_prime, sum_of_primes, process_input
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_sum_of_primes():
assert sum_o... | [
{
"docstring": "Check if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list nums.",
"function_declaration": "def sum_of_primes(nums):",
"f... | [
1,
1,
1,
1,
1,
1,
1,
0,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00013374",
"row_id": 13374,
"seed_ids": "[778]"
} | 0.660938 | Apps_13374 | I | [
"is_prime",
"sum_of_primes",
"process_input"
] | 3 | [
[
"process_input",
"sum_of_primes"
],
[
"sum_of_primes",
"is_prime"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | e7ed9ceba04cd3b5470ac6416e0a8f14197c158e | 36dd26aa8992ee38cff7b7d4b475eaa32e62fe66 | |||
v1.0 | instruct | Apps | Apps_13474_I | Given a binary tree, you need to find the maximum sum of the values of nodes on any path from the root node to a leaf node.
A binary tree is a tree data structure where each node has at most two children. Each node contains an integer value. You can traverse the tree starting from the root to any of the leaves to find... | class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_info):
nodes = {}
for i, (value, left, right) in enumerate(node_info):
if i not in nodes:
nodes[i] = Node(value)
if left != -1:
no... | from solution import maximum_sum_on_path
def test_sample_case():
N = 5
node_info = [
(3, 1, 2),
(4, -1, -1),
(5, 3, 4),
(7, -1, -1),
(6, -1, -1)
]
assert maximum_sum_on_path(N, node_info) == 15
def test_single_node():
N = 1
node_info = [
(10, -1,... | [] | [
0,
1,
0,
0,
0,
1,
1,
0,
1,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n \ndef max_sum_path(root):\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00013474",
"row_id": 13474,
"seed_ids": "[517]"
} | 0.658406 | Apps_13474 | I | [
"build_tree",
"find_max_sum",
"maximum_sum_on_path"
] | 3 | [
[
"maximum_sum_on_path",
"build_tree"
],
[
"maximum_sum_on_path",
"find_max_sum"
]
] | 2 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 90e507312c0895d0ed7c794ab2119eefbcd17ccb | 7a0aba39e04c9ffdfb76e1179a00dd3850fe5523 | |||
v1.0 | instruct | Apps | Apps_13496_I | Mark is planning a scavenger hunt for his family. To make it interesting, he placed some clues in different rooms of the house. Each clue states the next room to go to. However, some rooms might lead back to an already visited room, indicating a cycle. Mark wants to ensure that his family doesn't get stuck in a cycle a... | def is_valid_path(hunts):
"""
Determines if there's a valid path without a cycle for each scavenger hunt.
Parameters:
hunts (list of list of int): List of scavenger hunts, each hunt is represented
as a list of room numbers.
Ret... | from solution import scavenger_hunts
def test_valid_paths():
input_data = "2\n4\n2 3 4 0\n3\n1 2 3"
expected_output = ["Valid", "Cycle"]
assert scavenger_hunts(input_data) == expected_output
def test_cycle_with_single_room():
input_data = "1\n1\n1"
expected_output = ["Cycle"]
assert scavenger_... | [
{
"docstring": "Determines if there's a valid path without a cycle for each scavenger hunt.\n\nParameters:\nhunts (list of list of int): List of scavenger hunts, each hunt is represented \n as a list of room numbers.\n \nReturns:\nlist of str: \"Valid\" if... | [
0,
0,
0,
1,
0,
1,
1,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_path(t, hunts):\n results = []\n\n def has_cycle(room, visited, stack, adj):\n if stack[room]: # If room is currently in the stack, we ha... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013496",
"row_id": 13496,
"seed_ids": "[2189]"
} | 0.598565 | Apps_13496 | I | [
"is_valid_path",
"parse_input",
"scavenger_hunts"
] | 3 | [
[
"scavenger_hunts",
"is_valid_path"
],
[
"scavenger_hunts",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 7a1eb611e6221356721ae0a22abce96d4077ef54 | 1d1c85d222bb675b0915bd47c0984f47e672e0ed | |||
v1.0 | instruct | Apps | Apps_13572_I | **Grid Rotation Check**
You will receive two n x n integer grids `gridA` and `gridB`. Your task is to determine if `gridA` can be transformed into `gridB` by rotating it 90 degrees clockwise any number of times (0, 1, 2, or 3 times).
Each grid contains only positive integers and will have dimensions of at least 2x2. ... | from typing import List
def rotate_90_clockwise(grid: List[List[int]]) -> List[List[int]]:
"""
Rotates the grid 90 degrees clockwise.
"""
n = len(grid)
new_grid = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
new_grid[j][n - 1 - i] = grid[i][j]
return... | from solution import can_rotate_to_match
def test_no_rotation_needed():
gridA = [
[1, 2],
[3, 4]
]
gridB = [
[1, 2],
[3, 4]
]
assert can_rotate_to_match(gridA, gridB) == True
def test_one_rotation():
gridA = [
[1, 2],
[3, 4]
]
gridB = [
... | [
{
"docstring": "Rotates the grid 90 degrees clockwise.",
"function_declaration": "def rotate_90_clockwise(grid):",
"function_name": "rotate_90_clockwise",
"parameter_list": "(grid)"
},
{
"docstring": "Determines if gridA can be transformed into gridB by rotating it\n90 degrees clockwise any ... | [
1,
0,
0,
1,
1,
0,
0,
1,
1,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef rotate_90(grid: List[List[int]]) -> List[List[int]]:\n \"\"\"\n Rotates the given n x n grid 90 degrees clockwise.\n \"\"\"\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013572",
"row_id": 13572,
"seed_ids": "[4665]"
} | 0.694043 | Apps_13572 | I | [
"rotate_90_clockwise",
"can_rotate_to_match"
] | 2 | [
[
"can_rotate_to_match",
"rotate_90_clockwise"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f59f744296ed85d1444055ac04f1b8c7d5bf6f5 | 9796a6b2e02bd25680d7966edf6b2c00aa7d9d0b | |||
v1.0 | instruct | Apps | Apps_13599_I | You are working on a system that needs to log events to a file for auditing purposes. Each event is represented as a string, and every log entry should include a timestamp indicating when the event occurred.
Design a function that logs an event to a file named "event_log.txt". Each log entry should be written on a new... | import os
def get_current_timestamp():
from datetime import datetime
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def log_event(event_description):
try:
timestamp = get_current_timestamp()
log_entry = f"[{timestamp}] - {event_description}\n"
with open("event_log.txt... | import os
from unittest.mock import patch
from solution import log_event
def test_log_event_file_creation():
if os.path.exists("event_log.txt"):
os.remove("event_log.txt")
log_event("Test Event Creation")
assert os.path.exists("event_log.txt")
def test_log_event_entry_format():
with patch('so... | [
{
"docstring": null,
"function_declaration": "def get_current_timestamp():",
"function_name": "get_current_timestamp",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def log_event(event_description):",
"function_name": "log_event",
"parameter_list": "(eve... | [
1,
0,
1,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef get_current_timestamp():\n \"\"\"\n This helper function is assumed to exist and return a formatted timestamp.\n In a real scenario, this ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00013599",
"row_id": 13599,
"seed_ids": "[2773]"
} | 0.695137 | Apps_13599 | I | [
"get_current_timestamp",
"log_event"
] | 2 | [
[
"log_event",
"get_current_timestamp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b0ec4559f391a6950e71ab09b033b0357a7c8272 | edf3f2e48fda712128d97544eb84b7a158a655cc | |||
v1.0 | instruct | Apps | Apps_13613_I | The city council is planning to beautify city parks by planting trees. There are `n` parks in the city, and some pairs of parks are connected by bidirectional roads. To maximize the beauty, the council wants to plant a tree in each park such that no two adjacent parks (i.e., parks connected by a road) have the same typ... | from collections import deque
def min_tree_types(n, m, edges):
graph = [[] for _ in range(n)]
# Build the adjacency list
for u, v in edges:
graph[u - 1].append(v - 1)
graph[v - 1].append(u - 1)
color = [-1] * n
def bfs(start):
queue = deque([start])
co... | def test_beautify_parks():
test_cases = [
(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]),
(3, 2, [(1, 2), (2, 3)])
]
expected_outputs = [
(2, [1, 2, 1, 2]),
(2, [1, 2, 1])
]
results = solve_beautify_parks(test_cases)
for result, expected in zip(results, expect... | [
{
"docstring": null,
"function_declaration": "def min_tree_types(n, m, edges):",
"function_name": "min_tree_types",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_beautify_parks(test_cases):",
"function_name": "solve_beautify_parks",
... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef min_tree_types(T, test_cases):\n results = []\n\n for _ in range(T):\n n, m, edges = test_cases[_]\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00013613",
"row_id": 13613,
"seed_ids": "[928]"
} | 0.702541 | Apps_13613 | I | [
"min_tree_types",
"solve_beautify_parks"
] | 2 | [
[
"solve_beautify_parks",
"min_tree_types"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2dcf3e73dd1397190484c84248fb2a931ba72ad7 | 4600b344906800686981fcd5af0222c8a7e11cea | |||
v1.0 | instruct | Apps | Apps_13629_I | Given a grid of letters and a list of words, determine whether each word in the list can be formed by sequentially adjacent letters in the grid, such as left, right, up, or down, without reusing any letter cell.
-----Input-----
The first line contains an integer T denoting the total number of test cases.
In each test ... | def exist(board, word):
def dfs(board, word, i, j, word_index):
if word_index == len(word):
return True
if i < 0 or i >= len(board) or j < 0 or j >= len(board[0]) or board[i][j] != word[word_index]:
return False
temp = board[i][j]
board[i][j] = "#"
... | from solution import word_search, parse_input
def test_single_case():
input_string = "1\n3 4\na b c e\ns f c s\na d e e\n3\nabcced see sexe"
test_cases = parse_input(input_string)
result = word_search(test_cases)
assert result == ["YES", "YES", "NO"]
def test_multiple_cases():
input_string = (
... | [
{
"docstring": null,
"function_declaration": "def exist(board, word):",
"function_name": "exist",
"parameter_list": "(board, word)"
},
{
"docstring": null,
"function_declaration": "def word_search(test_cases):",
"function_name": "word_search",
"parameter_list": "(test_cases)"
}... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def exist(board, word):\n def dfs(i, j, k):\n if not (0 <= i < len(board) and 0 <= j < len(board[0])):\n return False\n if board[i][j] !... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013629",
"row_id": 13629,
"seed_ids": "[621]"
} | 0.779729 | Apps_13629 | I | [
"exist",
"word_search",
"parse_input"
] | 3 | [
[
"word_search",
"exist"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 083b93be987517b0c10f0ecd6623f5144ad7c51e | 274dbd38b4bc33a94544d98aae016fa2de64b816 | |||
v1.0 | instruct | Apps | Apps_13638_I | A programming company intends to evaluate the efficiency of their code refactoring tool. The company will provide a script consisting of multiple methods, and they need to identify and refactor all method invocations to follow a new naming convention. Specifically, all method names must be changed to camelCase style.
... | import re
def convert_snake_to_camel(snake_str):
"""
Converts a snake_case string to camelCase string.
"""
parts = snake_str.split('_')
camel_str = parts[0] + ''.join(word.capitalize() for word in parts[1:])
return camel_str
def refactor_script(script_lines):
"""
Refactors the given li... | def test_convert_snake_to_camel():
assert convert_snake_to_camel("create_user") == "createUser"
assert convert_snake_to_camel("get_user_details") == "getUserDetails"
assert convert_snake_to_camel("update") == "update"
assert convert_snake_to_camel("save_user_data_locally") == "saveUserDataLocally"
def ... | [
{
"docstring": "Converts a snake_case string to camelCase string.",
"function_declaration": "def convert_snake_to_camel(snake_str):",
"function_name": "convert_snake_to_camel",
"parameter_list": "(snake_str)"
},
{
"docstring": "Refactors the given list of script lines by converting all metho... | [
1,
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef convert_snake_to_camel(snake_str):\n \"\"\"\n Converts a snake_case string to camelCase string.\n \"\"\"\n parts = snake_str.split('_')... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00013638",
"row_id": 13638,
"seed_ids": "[952]"
} | 0.557803 | Apps_13638 | I | [
"convert_snake_to_camel",
"refactor_script",
"refactor_scripts"
] | 3 | [
[
"refactor_script",
"convert_snake_to_camel"
],
[
"refactor_scripts",
"refactor_script"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | bf1f9eeb806317239cc45de43edfaf22791af78f | 84cdd339cc3776629bf34a0bf954cdfd2294b365 | |||
v1.0 | instruct | Apps | Apps_13662_I | Write a function that takes a list of integers and groups them into a specified number of contiguous sublists such that the maximum sum of any sublist is minimized. Your function should return this minimized maximum sum.
For example, if you have the list [7, 2, 5, 10, 8] and you want to split it into 2 sublists, you c... | def can_split(nums, k, max_sum):
current_sum = 0
needed_splits = 1
for num in nums:
if current_sum + num > max_sum:
needed_splits += 1
current_sum = num
if needed_splits > k:
return False
else:
current_sum += num
... | from solution import minimize_max_sum
def test_minimize_max_sum_example():
assert minimize_max_sum([7, 2, 5, 10, 8], 2) == 18
def test_minimize_max_sum_one_element():
assert minimize_max_sum([1], 1) == 1
def test_minimize_max_sum_all_equal_elements():
assert minimize_max_sum([5, 5, 5, 5], 2) == 10
as... | [
{
"docstring": null,
"function_declaration": "def can_split(nums, k, max_sum):",
"function_name": "can_split",
"parameter_list": "(nums, k, max_sum)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_sum(arr, k):",
"function_name": "minimize_max_sum",
"parameter_l... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimize_max_sum(arr, k):\n \"\"\"\n This function takes a list of integers and groups them into a specified number\n of contiguous sublists such that ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013662",
"row_id": 13662,
"seed_ids": "[3591]"
} | 0.71941 | Apps_13662 | I | [
"can_split",
"minimize_max_sum"
] | 2 | [
[
"minimize_max_sum",
"can_split"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 205f103255eda54d7e8a3bf5d232e1ed4d188230 | 78f386699dcc0ca4bc5c8573607443f5c8988cf7 | |||
v1.0 | instruct | Apps | Apps_13760_I | # Introduction
A company has assigned you the task of improving their daily operations by automating the report generation process. Currently, they have a system that stores employee timesheet entries, and they need an end-of-day report summarizing each employee's total hours worked.
Each employee's timesheet entry c... | def merge_intervals(intervals):
"""
Merge overlapping intervals and return a list of merged intervals.
Intervals is a list of tuples (start, end).
"""
if not intervals:
return []
# Sort intervals by start time
intervals.sort()
merged = [intervals[0]]
for curren... | from solution import calculate_total_hours, merge_intervals
def test_merge_intervals():
assert merge_intervals([(9, 12), (14, 17), (11, 13)]) == [(9, 13), (14, 17)]
assert merge_intervals([(10, 13), (13, 16)]) == [(10, 16)]
assert merge_intervals([(9, 10), (12, 14)]) == [(9, 10), (12, 14)]
assert merge... | [
{
"docstring": "Merge overlapping intervals and return a list of merged intervals.\nIntervals is a list of tuples (start, end).",
"function_declaration": "def merge_intervals(intervals):",
"function_name": "merge_intervals",
"parameter_list": "(intervals)"
},
{
"docstring": "Calculate the to... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_hours(entries):\n def merge_intervals(intervals):\n if not intervals:\n return []\n\n # Sort intervals based on star... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013760",
"row_id": 13760,
"seed_ids": "[3397]"
} | 0.599973 | Apps_13760 | I | [
"merge_intervals",
"calculate_total_hours"
] | 2 | [
[
"calculate_total_hours",
"merge_intervals"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7fab1d0b6f2a5eaf18cc0d914a5f03af0a53c5e8 | f927bc68702fd3114856fc1ef44a535821304535 | |||
v1.0 | instruct | Apps | Apps_13771_I | In a matrix game, two players take turns placing either a '+' or a '-' on any empty cell in an n x n grid. The game ends when the grid is fully populated. The value of the game is calculated as the sum of the values in each row and each column interpreted as a binary number where '+' is treated as 1 and '-' as 0.
For ... | def max_game_value(n):
"""
Given the size of the grid `n`, calculate the maximum possible value of the game.
"""
# The maximum value is achieved by filling the entire grid with '+'
# Each row and column will then have value 2^n - 1 in binary which is (2^n - 1) in decimal.
# There are n rows and ... | from solution import max_game_value, solve_game_value
def test_max_game_value():
assert max_game_value(1) == 2 # 1 * (2^1 - 1) * 2 = 1 * 1 * 2 = 2
assert max_game_value(2) == 12 # 2 * (2^2 - 1) * 2 = 2 * 3 * 2 = 12
assert max_game_value(3) == 42 # 3 * (2^3 - 1) * 2 = 3 * 7 * 2 = 42
assert max_game_v... | [
{
"docstring": "Given the size of the grid `n`, calculate the maximum possible value of the game.",
"function_declaration": "def max_game_value(n):",
"function_name": "max_game_value",
"parameter_list": "(n)"
},
{
"docstring": "Processes multiple test cases to determine the maximum possible ... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_game_value(n):\n \"\"\"\n Calculate the maximum possible value of the game for an n x n grid.\n \"\"\"\n max_value_per_line = (1 << n) - 1\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00013771",
"row_id": 13771,
"seed_ids": "[1232]"
} | 0.72008 | Apps_13771 | I | [
"max_game_value",
"solve_game_value",
"process_input_input",
"output_solution"
] | 4 | [
[
"solve_game_value",
"max_game_value"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 856f9cdb505ab7a2a208a9bd87b9ba1861f7aafa | 454fec2196e1b07c0fe32d8107ee2d32e1b3491e | |||
v1.0 | instruct | Apps | Apps_13869_I | Write a function that takes a list of integers as an input, and returns the same list, but with each integer replaced by a representation of its prime factorization.
For each integer in the list:
1. If the integer is 1, simply replace it with "1".
2. If the integer is prime, replace it with the integer itself.
3. If t... | def prime_factors(n):
"""Helper function to calculate the prime factors of a given number n"""
i = 2
factors = []
while i * i <= n:
while (n % i) == 0:
factors.append(i)
n //= i
i += 1
if n > 1:
factors.append(n)
return factors
def prime_factoriza... | def test_prime_factors():
assert prime_factors(1) == []
assert prime_factors(2) == [2]
assert prime_factors(6) == [2, 3]
assert prime_factors(12) == [2, 2, 3]
assert prime_factors(18) == [2, 3, 3]
assert prime_factors(13) == [13]
def test_prime_factorization():
assert prime_factorization([1... | [
{
"docstring": "Helper function to calculate the prime factors of a given number n",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Replaces each integer in the list by its prime factorization string or the intege... | [
0,
1,
0,
1,
0,
1,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factorization(lst):\n def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00013869",
"row_id": 13869,
"seed_ids": "[3532]"
} | 0.816963 | Apps_13869 | I | [
"prime_factors",
"prime_factorization"
] | 2 | [
[
"prime_factorization",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 91c3a99f67cef4c158b5dffacba11bdc698c158f | f8ae61330d1b38d5c079125c96615df235ee70f4 | |||
v1.0 | instruct | Apps | Apps_13908_I | You are given a grid with $n$ rows and $m$ columns. Each cell of the grid contains an integer value which represents the height of that cell. You need to find the path from the top-left corner $(1, 1)$ to the bottom-right corner $(n, m)$ such that the maximum absolute difference in heights between any two consecutive c... | import heapq
def min_max_diff(grid, n, m):
directions = [(0, 1), (1, 0)]
max_diff = [[float('inf')] * m for _ in range(n)]
max_diff[0][0] = 0
heap = [(0, 0, 0)]
while heap:
diff, x, y = heapq.heappop(heap)
if (x, y) == (n - 1, m - 1):
return diff
for dx... | from solution import parse_input, solve
def test_example_one():
input_string = "2\n2 2\n1 3\n4 2\n3 3\n8 5 9\n7 3 6\n2 4 1\n"
t, test_cases = parse_input(input_string)
expected = [2, 3]
assert solve(t, test_cases) == expected
def test_single_cell():
input_string = "1\n1 1\n0\n"
t, test_cases =... | [
{
"docstring": null,
"function_declaration": "def min_max_diff(grid, n, m):",
"function_name": "min_max_diff",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve(t, test_cases):",
"function_name": "solve",
"parameter_list": "(t, test_cases... | [
0,
0,
0,
0,
1,
0,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_max_path_difference(test_cases):\n results = []\n \n for grid in test_cases:\n n = len(grid)\n m = len(grid[0])\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00013908",
"row_id": 13908,
"seed_ids": "[2381]"
} | 0.732355 | Apps_13908 | I | [
"min_max_diff",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"min_max_diff"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 2198fcf58dd857a5289c288e2839cf8d7fd85a94 | 51ae41b79fa2282b9c9f70a20a656d1c638181ae | |||
v1.0 | instruct | Apps | Apps_13956_I | You are given a list of integers. Write a function to sort this list such that all prime numbers appear before all non-prime numbers, while maintaining the relative order of prime numbers and relative order of non-prime numbers from the original list.
Here is the step-by-step explanation:
1. Extract all prime numbers... | def is_prime(n):
"""
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
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sort_p... | from solution import sort_primes_first
def test_prime_and_non_prime_mix():
assert sort_primes_first([10, 3, 5, 2, 8, 13, 4, 6]) == [3, 5, 2, 13, 10, 8, 4, 6]
def test_all_primes():
assert sort_primes_first([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_all_non_primes():
assert sort_primes_first([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": "Sort the list such that all prime numbers appear before non-prime numbers\nwhile maintaining relative or... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 == 2:\n return True\n if n % 2 ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00013956",
"row_id": 13956,
"seed_ids": "[4538]"
} | 0.62579 | Apps_13956 | I | [
"is_prime",
"sort_primes_first"
] | 2 | [
[
"sort_primes_first",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 430e6cda1c70e235a6e147f431d5b4930ec24a1e | 830593ff2acd5e3ffb9467c6f85cea9d9d1e45f0 | |||
v1.0 | instruct | Apps | Apps_14020_I | Given a list of integers, return a new list containing only the prime numbers found in the original list, maintaining their original order.
The list will never be empty and you do not need to account for non-integer values. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_prime_numbers(lst):
"""
Returns a list containing only the prime numbers from the original list... | from solution import is_prime, filter_prime_numbers
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_filter_prime_numbers():
assert filter_prime_numbers([2, 3, 4, 5, 6]) == [... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers from the original list.",
"function_declaration": "def filter_prime_numbers(l... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 r... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00014020",
"row_id": 14020,
"seed_ids": "[4553]"
} | 0.586542 | Apps_14020 | I | [
"is_prime",
"filter_prime_numbers"
] | 2 | [
[
"filter_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3eb29cb261907a4432838ad1fb4cdefc62b9810a | ac6764374a9284c4edcc1d3844021ca2a8f89b82 | |||
v1.0 | instruct | Apps | Apps_14086_I | **Task**
Implement a function that takes a list of words and finds the longest word that can be made from the combination of other words in the list. Each word in the list can only be used once and it cannot be constructed from the current word itself.
**Example**
For the input `words = ["rat", "cat", "cats", "dog... | def can_construct(word, word_set, original_word):
if word in word_set and word != original_word:
return True
for i in range(1, len(word)):
prefix = word[:i]
suffix = word[i:]
if prefix in word_set and can_construct(suffix, word_set, original_word):
return True
ret... | from solution import find_longest_word
def test_example_case():
assert find_longest_word(["rat", "cat", "cats", "dog", "catsdog"]) == "catsdog"
def test_no_constructible_word():
assert find_longest_word(["apple", "banana", "cherry"]) == ""
def test_single_word():
assert find_longest_word(["apple"]) == ""... | [
{
"docstring": null,
"function_declaration": "def can_construct(word, word_set, original_word):",
"function_name": "can_construct",
"parameter_list": "(word, word_set, original_word)"
},
{
"docstring": null,
"function_declaration": "def find_longest_word(words):",
"function_name": "f... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_word(words):\n \"\"\"\n Finds the longest word in the list that can be made from other words in the list.\n \"\"\"\n word_set = set(wor... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00014086",
"row_id": 14086,
"seed_ids": "[2769]"
} | 0.694851 | Apps_14086 | I | [
"can_construct",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"can_construct"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f0b6ca7144eb86158cc9628ae906904b5a9c2230 | f43b87e419fab0017c17e9b80926b37451e7be1a | |||
v1.0 | instruct | Apps | Apps_14087_I | ## Your story
You have recently become fascinated with palindrome numbers and decided to write a program to explore them further. You want to create a function that checks if a given number is a Palindrome Prime. A Palindrome Prime is a number that is both a palindrome and a prime number. Additionally, you want to gene... | def is_prime(num):
"""Return True if num is a prime number, otherwise False."""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def... | from solution import is_prime, is_palindrome, palindrome_primes
def test_is_prime():
# Testing prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(13) == True
# Testing non-prime numbers
assert is_prime(1) == False
assert is_pr... | [
{
"docstring": "Return True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Return True if num is a palindrome number, otherwise False.",
"function_declaration": "def is_p... | [
1,
1,
1,
1,
1,
0,
0,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00014087",
"row_id": 14087,
"seed_ids": "[4638]"
} | 0.703171 | Apps_14087 | I | [
"is_prime",
"is_palindrome",
"palindrome_primes"
] | 3 | [
[
"palindrome_primes",
"is_palindrome"
],
[
"palindrome_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 23be8c940627fe7c57d963a50422a83e884e5acd | e447bcb59a9e28638e58143dceede0c9053f82ea | |||
v1.0 | instruct | Apps | Apps_14103_I | A group of treasure hunters are trying to unlock a secret door to a hidden treasure. The door has a numeric keypad that accepts a positive integer input. The door opens if and only if the input number is a **happy number**. A happy number is defined as follows:
Starting with any positive integer, replace the number by... | def is_happy_number(n):
def get_next(number):
return sum(int(ch)**2 for ch in str(number))
seen = set()
while n != 1 and n not in seen:
seen.add(n)
n = get_next(n)
return n == 1
def determine_happy_numbers(numbers):
results = []
for num in numbers:
if i... | from solution import is_happy_number, determine_happy_numbers, process_input
def test_is_happy_number():
assert is_happy_number(19) is True
assert is_happy_number(2) is False
assert is_happy_number(100) is True
assert is_happy_number(1) is True
assert is_happy_number(7) is True
def test_determine_... | [
{
"docstring": null,
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def determine_happy_numbers(numbers):",
"function_name": "determine_happy_numbers",
"parameter_list... | [
0,
1,
1,
0,
1,
0,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_happy(n):\n \"\"\"\n Determines if a given number n is a happy number.\n \n Args:\n n (int): a positive integer\n \n Returns:\n bool:... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00014103",
"row_id": 14103,
"seed_ids": "[1404]"
} | 0.598748 | Apps_14103 | I | [
"is_happy_number",
"determine_happy_numbers",
"process_input"
] | 3 | [
[
"determine_happy_numbers",
"is_happy_number"
],
[
"process_input",
"determine_happy_numbers"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | e3c152dc4e3d43836ffd650d3bdef0f61fc973e0 | bdc6f230c466989a1323583e05d6b95bcfef7fb0 | |||
v1.0 | instruct | Apps | Apps_14136_I | Jane is organizing a reading group and she wants to order the books for her group in a special way. Each book has a distinct identifier represented as a positive integer. Jane will pick up books in ascending order but with a twist: she will select only those books whose identifiers have distinct digits. For example, th... | def has_distinct_digits(number):
"""Checks whether the given number has all distinct digits."""
digits = str(number)
return len(set(digits)) == len(digits)
def books_with_distinct_digits(n, m):
"""Returns a list of book identifiers within the range [n, m] with distinct digits."""
result = []
fo... | from solution import has_distinct_digits, books_with_distinct_digits, solve
def test_has_distinct_digits():
assert has_distinct_digits(102) == True
assert has_distinct_digits(112) == False
assert has_distinct_digits(12345) == True
assert has_distinct_digits(122345) == False
def test_books_with_distinc... | [
{
"docstring": "Checks whether the given number has all distinct digits.",
"function_declaration": "def has_distinct_digits(number):",
"function_name": "has_distinct_digits",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of book identifiers within the range [n, m] with disti... | [
1,
1,
0,
0,
0,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def distinct_digit_books(N, M):\n \"\"\"\n Return a list of integers in the range [N, M] that have distinct digits.\n \"\"\"\n def has_distinct_digits(x... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00014136",
"row_id": 14136,
"seed_ids": "[1395]"
} | 0.701324 | Apps_14136 | I | [
"has_distinct_digits",
"books_with_distinct_digits",
"solve"
] | 3 | [
[
"books_with_distinct_digits",
"has_distinct_digits"
],
[
"solve",
"books_with_distinct_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 61176eaf64350b9d5b3d775a68e5253c051aec0e | 4a7e2ee6c537a2ad9c4397808f52758d7a0d2cd3 | |||
v1.0 | instruct | Apps | Apps_14140_I | In an isolated town, there is a network of roads connecting several houses. Each house is represented by a node in a graph, and each road is represented by an edge with a certain cost. The town's mayor wants to ensure that there is a way to travel between any two houses with the minimum possible road construction cost ... | from heapq import heappop, heappush
from collections import defaultdict, deque
def find(parent, node):
if parent[node] == node:
return node
root = find(parent, parent[node])
parent[node] = root
return root
def union(parent, rank, node1, node2):
root1 = find(parent, node1)
root2 = find(... | def test_sample_case():
from io import StringIO
import sys
input = StringIO("""1
4 5
1 2 3
1 3 4
2 3 2
3 4 5
2 4 6
3
1 2
2 3
3 4
""")
sys.stdin = input
from solution import solve
solve()
def test_another_case():
from io import StringIO
import sys
input = StringIO("""1
4 4
1 2 1
2 3 ... | [
{
"docstring": null,
"function_declaration": "def find(parent, node):",
"function_name": "find",
"parameter_list": "(parent, node)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, node1, node2):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
0,
1,
0,
0,
0,
1,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 = fin... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014140",
"row_id": 14140,
"seed_ids": "[1276]"
} | 0.72956 | Apps_14140 | I | [
"find",
"union",
"kruskal",
"is_connected_after_removal",
"solve"
] | 5 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"solve",
"is_connected_after_removal"
],
[
"solve",
"kruskal"
],
[
"union",
"find"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 0ce9b263c8b501177fedd71540e115cb161fd4da | 107e48244627da606537155b830ca2f8d0e44bf8 | |||
v1.0 | instruct | Apps | Apps_14147_I | Write a function that accepts an array of integers and returns a new array containing only the prime numbers from the input array, preserving the original order. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
## Example
```
Input: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Output: [... | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for divisor in range(3, max_divisor, 2):
if n % divi... | from solution import extract_primes
def test_extract_primes_basic():
assert extract_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_extract_primes_all_primes():
assert extract_primes([11, 13, 17, 19, 22, 23, 25, 28, 29]) == [11, 13, 17, 19, 23, 29]
def test_extract_primes_no_primes():
asser... | [
{
"docstring": "Check if a given 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 input array.",
"function_declaration": "def extract_primes(arr):",
"functio... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ret... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00014147",
"row_id": 14147,
"seed_ids": "[3373]"
} | 0.707192 | Apps_14147 | I | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80bab5034e8c0682a57082fff5dd83905b1b9a47 | 96687270f6b49afe0d8c3d24386a7cf0de87a613 | |||
v1.0 | instruct | Apps | Apps_14256_I | You are provided with a list of integers, where each integer represents the number of pages in a book. Your task is to redistribute these books among a group of people such that each person gets a contiguous block of books, and the maximum number of pages any single person has to read is minimized.
Write a function th... | from typing import List
def can_allocate(pages: List[int], people: int, max_pages_limit: int) -> bool:
required_people = 1
current_pages = 0
for page in pages:
if current_pages + page > max_pages_limit:
required_people += 1
current_pages = page
... | from solution import minimize_max_pages
def test_minimize_max_pages_example():
pages = [100, 200, 300, 400, 500]
people = 2
assert minimize_max_pages(pages, people) == 900
def test_minimize_max_pages_single_book():
pages = [300]
people = 1
assert minimize_max_pages(pages, people) == 300
def t... | [
{
"docstring": null,
"function_declaration": "def can_allocate(pages, people, max_pages_limit):",
"function_name": "can_allocate",
"parameter_list": "(pages, people, max_pages_limit)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_pages(pages, people):",
"function_... | [
0,
0,
0,
1,
0,
1,
0,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef can_distribute(pages: List[int], people: int, max_pages: int) -> bool:\n \"\"\"\n Helper function to check if it's possible to ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00014256",
"row_id": 14256,
"seed_ids": "[4272]"
} | 0.668879 | Apps_14256 | I | [
"can_allocate",
"minimize_max_pages"
] | 2 | [
[
"minimize_max_pages",
"can_allocate"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6f78a820b9d0fb4ddf8f6234f15b2a4ced2a83c4 | 952596b6e323adf8249afa45e7f86c78e376845d | |||
v1.0 | instruct | Apps | Apps_14365_I | # Task
A palindrome is a string that reads the same forward and backward, while an almost palindrome is a string that would be a palindrome if at most one character were deleted.
Given a string, determine whether it is almost palindrome.
# Example
For `input = "radkar"`, the output should be `true`. You can remove t... | def is_palindrome(s):
"""
Helper function to check if a string is a palindrome.
"""
return s == s[::-1]
def is_almost_palindrome(input_string):
"""
Returns True if the input string is an almost palindrome, False otherwise.
"""
if is_palindrome(input_string):
return True
len... | from solution import is_almost_palindrome
def test_is_almost_palindrome_palindrome():
assert is_almost_palindrome("racecar") == True
def test_is_almost_palindrome_almost_palindrome():
assert is_almost_palindrome("radkar") == True
def test_is_almost_palindrome_not_almost_palindrome():
assert is_almost_pal... | [
{
"docstring": "Helper function to check if a string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the input string is an almost palindrome, False otherwise.",
"function_dec... | [
1,
0,
1,
1,
0,
0,
0,
0,
0,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_almost_palindrome(s):\n \"\"\"\n Determine if a string is an almost palindrome.\n\n Args:\n s (str): A non-empty string containing lowercase Engl... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00014365",
"row_id": 14365,
"seed_ids": "[4347]"
} | 0.74001 | Apps_14365 | I | [
"is_palindrome",
"is_almost_palindrome"
] | 2 | [
[
"is_almost_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c1f9dffce85962d7cf1fd2e486955cf5237a34e | f219c67fb6a8df64523e89d43a7b59c65dc1f90a | |||
v1.0 | instruct | Apps | Apps_14539_I | Given a list of integers, you need to count the number of subarrays (contiguous elements) that form a palindrome. A palindrome is a sequence that reads the same backward as forward.
For example:
- `[1, 2, 1]` is a palindrome.
- `[3, 4, 4, 3]` is a palindrome.
- `[5, 6, 7]` is not a palindrome.
The function should re... | def is_palindrome(subarray):
"""
Helper function to check if a subarray is a palindrome.
"""
return subarray == subarray[::-1]
def count_palindromic_subarrays(arr):
"""
Returns the count of palindromic subarrays in the given list.
"""
count = 0
n = len(arr)
for start in ran... | from solution import count_palindromic_subarrays
def test_single_element_lists():
assert count_palindromic_subarrays([1]) == 1
assert count_palindromic_subarrays([2]) == 1
def test_two_element_lists():
assert count_palindromic_subarrays([1, 2]) == 2
assert count_palindromic_subarrays([1, 1]) == 3
def... | [
{
"docstring": "Helper function to check if a subarray is a palindrome.",
"function_declaration": "def is_palindrome(subarray):",
"function_name": "is_palindrome",
"parameter_list": "(subarray)"
},
{
"docstring": "Returns the count of palindromic subarrays in the given list.",
"function_... | [
0,
0,
1,
0,
0,
0,
1,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(arr):\n \"\"\"\n Helper function to check if a given list is a palindrome.\n \"\"\"\n return arr == arr[::-1]\n\ndef count_palindromic... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014539",
"row_id": 14539,
"seed_ids": "[4082]"
} | 0.67993 | Apps_14539 | I | [
"is_palindrome",
"count_palindromic_subarrays"
] | 2 | [
[
"count_palindromic_subarrays",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 72e78c61b99aa8e9dbac02b54ba2c4cd5abc8a93 | 93da56a172272f4a88856c41f03a5444947c97bc | |||
v1.0 | instruct | Apps | Apps_14557_I | -----General Statement:-----
Write a program that reads two matrices and outputs their sum.
-----Input:-----
The input begins with two integers, n and m, specifying the number of rows and columns of the matrices (1 ≤ n, m ≤ 100). This is followed by 2 blocks, each consisting of n lines with m integers each, where each... | def read_matrix(n, m, matrix_input):
"""
Reads a matrix of size n by m from the given input list.
"""
matrix = []
for i in range(n):
row = matrix_input[i].split()
matrix.append([int(num) for num in row])
return matrix
def sum_matrices(matrix_a, matrix_b):
"""
Returns the... | from solution import matrix_sum
def test_matrix_sum_case1():
input_data = "2 3\n1 2 3\n4 5 6\n7 8 9\n10 11 12"
expected_output = "8 10 12\n14 16 18"
assert matrix_sum(input_data) == expected_output
def test_matrix_sum_case2():
input_data = "1 2\n-1000 -1000\n1000 1000"
expected_output = "0 0"
... | [
{
"docstring": "Reads a matrix of size n by m from the given input list.",
"function_declaration": "def read_matrix(n, m, matrix_input):",
"function_name": "read_matrix",
"parameter_list": "(n, m, matrix_input)"
},
{
"docstring": "Returns the summation of two matrices.",
"function_declar... | [
0,
1,
1,
1,
1,
0,
0,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def read_matrix(n, m):\n \"\"\"\n Reads a matrix of size n x m from standard input.\n \"\"\"\n matrix = []\n for _ in range(n):\n row = list(m... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00014557",
"row_id": 14557,
"seed_ids": "[1338]"
} | 0.582363 | Apps_14557 | I | [
"read_matrix",
"sum_matrices",
"parse_input",
"matrix_sum"
] | 4 | [
[
"matrix_sum",
"parse_input"
],
[
"matrix_sum",
"read_matrix"
],
[
"matrix_sum",
"sum_matrices"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 84f176f633bf5f70adf9aed6588604f26cdcb28f | 468d51387ad29b31d8108c8d113c35e7a01edc6c | |||
v1.0 | instruct | Apps | Apps_14594_I | Given an integer `n`, create a function to determine if `n` can be expressed as the sum of three positive distinct integers each of which also must be a prime number. If such a combination exists, return the three prime numbers as a tuple. If multiple combinations are possible, return any one of them. If no such combin... | def is_prime(num):
"""
Determines if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i + 2) == 0:
return Fals... | from solution import is_prime, sum_of_three_primes
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
def test_sum_of_three_primes():
assert sum_of_three_p... | [
{
"docstring": "Determines if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if n can be expressed as the sum of three distinct prime numbers.",
"function_declaration": "def ... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\ndef is_prime(n):\n \"\"\"Returns True if n is a prime number, otherwise False.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014594",
"row_id": 14594,
"seed_ids": "[3832]"
} | 0.731306 | Apps_14594 | I | [
"is_prime",
"sum_of_three_primes"
] | 2 | [
[
"sum_of_three_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d378fc7cf90572b13587083da182b3a33f2d2f04 | 5f222b81eb272d4021d8f03ee9dbd7f204982671 | |||
v1.0 | instruct | Apps | Apps_14597_I | In the world of programming, strings can often contain hidden meanings or patterns. One day, Aria discovered a special type of string called a "Balanced String." A string is considered balanced if every character in the string appears the same number of times. Aria, being curious, wants to know whether a given string i... | def is_balanced_string(S):
"""
Returns whether the string S is balanced or not.
"""
from collections import Counter
# Count frequency of each character
freq = Counter(S)
# Get all the frequency values
values = list(freq.values())
# Check if all frequency values are the... | from solution import is_balanced_string, check_balanced_strings
def test_is_balanced_string():
assert is_balanced_string("aabbcc") == True
assert is_balanced_string("abcabcabc") == True
assert is_balanced_string("aabbccdde") == False
assert is_balanced_string("abcd") == True
assert is_balanced_stri... | [
{
"docstring": "Returns whether the string S is balanced or not.",
"function_declaration": "def is_balanced_string(S):",
"function_name": "is_balanced_string",
"parameter_list": "(S)"
},
{
"docstring": "Returns a list indicating whether each string in strings is balanced.",
"function_dec... | [
1,
0,
1,
1,
0,
1,
0,
1,
0,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced_string(s):\n \"\"\"\n Returns 'YES' if the string s is balanced, 'NO' otherwise.\n A string is balanced if every character in the string ap... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014597",
"row_id": 14597,
"seed_ids": "[1369]"
} | 0.689866 | Apps_14597 | I | [
"is_balanced_string",
"check_balanced_strings"
] | 2 | [
[
"check_balanced_strings",
"is_balanced_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b15b020256d9641e2e81cc8a0e97175969d9692 | a4bcf6bc9bc136d33efc21d83189f2fa2f2a607b | |||
v1.0 | instruct | Apps | Apps_14637_I | Andrew loves playing with numbers. He recently encountered a number game while solving puzzles, and he found it quite fascinating. The game involves taking an integer and performing a series of transformations on it until he reaches a palindrome or gets stuck in a loop. Your task is to help Andrew determine the number ... | def is_palindrome(num):
"""
Check if the number is a palindrome.
"""
return str(num) == str(num)[::-1]
def find_palindrome_steps(number):
"""
Returns the number of steps required to reach a palindrome.
If the number does not become a palindrome within 1000 steps, returns -1.
"""
ste... | from solution import find_palindrome_steps
def test_find_palindrome_steps_initial_palindrome():
assert find_palindrome_steps(121) == 0
assert find_palindrome_steps(44) == 0
def test_find_palindrome_steps_steps_required():
assert find_palindrome_steps(87) == 4
assert find_palindrome_steps(28) == 2
... | [
{
"docstring": "Check if the number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns the number of steps required to reach a palindrome.\nIf the number does not become a palindrome wit... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef find_palindrome_steps(number):\n if is_palindrome(number):\n return 0\n \n ste... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00014637",
"row_id": 14637,
"seed_ids": "[3276]"
} | 0.723274 | Apps_14637 | I | [
"is_palindrome",
"find_palindrome_steps"
] | 2 | [
[
"find_palindrome_steps",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6f01dcefd9d7dacd73a9303d4ce1556fafedd62e | 610dd87a456b8ad8166a8428ed9a1e1f77cee011 | |||
v1.0 | instruct | Apps | Apps_14652_I | =====Function Descriptions=====
find_isbn(text)
In Python, the find_isbn(text) function can be used to extract and validate whether a given text contains a valid ISBN-10 or ISBN-13.
ISBN-10
An ISBN-10 is a ten-digit number, which may contain hyphens, and is validated by the following formula:
Sum of (digit * (11 - pos... | import re
def is_valid_isbn_10(isbn):
""" Check if the given ISBN-10 is valid """
isbn = isbn.replace('-', '')
if len(isbn) != 10 or not isbn[:-1].isdigit() or (isbn[-1] not in '0123456789X'):
return False
total = 0
for i, char in enumerate(isbn):
if char == 'X':
total +... | from solution import find_isbn, is_valid_isbn_10, is_valid_isbn_13
def test_valid_isbn_10():
assert is_valid_isbn_10('0-306-40615-2') == True
assert is_valid_isbn_10('0306406152') == True
assert is_valid_isbn_10('030640615X') == False
assert is_valid_isbn_10('0-306-40615-X') == False
assert is_vali... | [
{
"docstring": "Check if the given ISBN-10 is valid ",
"function_declaration": "def is_valid_isbn_10(isbn):",
"function_name": "is_valid_isbn_10",
"parameter_list": "(isbn)"
},
{
"docstring": "Check if the given ISBN-13 is valid ",
"function_declaration": "def is_valid_isbn_13(isbn):",
... | [
0,
0,
1,
0,
1,
0,
0,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_isbn10(isbn):\n \"\"\" Validates an ISBN-10 number. \"\"\"\n isbn = isbn.replace('-', '')\n if len(isbn) != 10 or not isbn[:-1].i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00014652",
"row_id": 14652,
"seed_ids": "[2616]"
} | 0.570281 | Apps_14652 | I | [
"is_valid_isbn_10",
"is_valid_isbn_13",
"find_isbn"
] | 3 | [
[
"find_isbn",
"is_valid_isbn_10"
],
[
"find_isbn",
"is_valid_isbn_13"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dd1a33eb2a0ac2f30ae620767eebcf6093f1188b | 62312fc1a69ce16322d49d917f916dfe8f91e851 | |||
v1.0 | instruct | Apps | Apps_14801_I | Given an integer n, return all structurally unique Binary Search Trees (BSTs) that have n nodes of unique values from 1 to n.
A Binary Search Tree is a binary tree with the following properties:
- The left subtree of a node contains only nodes with keys less than the node’s key.
- The right subtree of a node conta... | from typing import List, Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def generate_trees(n: int) -> List[Optional[TreeNode]]:
if n == 0:
return []
def generate_trees_range(start, end):
... | from solution import generate_and_serialize_trees
def test_generate_trees_case_1():
result = generate_and_serialize_trees(1)
expected = [[1]]
assert result == expected
def test_generate_trees_case_2():
result = generate_and_serialize_trees(2)
expected = [
[1, "null", 2],
[2, 1]
... | [] | [
1,
0,
0,
1,
0,
1,
1,
1,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef g... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00014801",
"row_id": 14801,
"seed_ids": "[1868]"
} | 0.497949 | Apps_14801 | I | [
"generate_trees",
"serialize_tree",
"generate_and_serialize_trees"
] | 3 | [
[
"generate_and_serialize_trees",
"generate_trees"
],
[
"generate_and_serialize_trees",
"serialize_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b564681d8431bf7146767d86232f0e23b6a9ccbc | 114b0dbc19f667a5fa730b22cf92b00c26967f01 | |||
v1.0 | instruct | Apps | Apps_14862_I | Write a function that takes a list of integers and returns a new list containing all the prime numbers from the original list. The returned list should be sorted in ascending order.
A prime number is a number that is greater than 1 and has no positive divisors other than 1 and itself.
Example:
Input: [15, 3, 10, 7,... | def is_prime(n):
"""
Returns True if n is a prime number, else returns False.
A prime number is a number that is greater than 1
and has no positive divisors other than 1 and itself.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if ... | from solution import is_prime, extract_sorted_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(-5) == False
assert is_prime(0) == False
assert is_prime(1) == False
def test_extract_sorte... | [
{
"docstring": "Returns True if n is a prime number, else returns False.\nA prime number is a number that is greater than 1 \nand has no positive divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstri... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 for i in range(2, int(n ** 0.5) + 1):\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00014862",
"row_id": 14862,
"seed_ids": "[3940]"
} | 0.708078 | Apps_14862 | I | [
"is_prime",
"extract_sorted_primes"
] | 2 | [
[
"extract_sorted_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 27a3d1a2acd112ccf75972337b9e7f5b0d45bf6d | 3ccbb0e3422251c566ebd1994d81b8315903a368 | |||
v1.0 | instruct | Apps | Apps_14905_I | =====Function Descriptions=====
sorted(iterable[, cmp[, key[, reverse]]])
This function returns a new sorted list from the elements of any iterable. The can be specified and to determine the sorted order. The option determines whether the list is sorted in descending order.
Sample Code
>>> a = [5, 2, 3, 1, 4]
>>> sor... | def calculate_final_total(purchase_amounts):
"""
This function takes a list of purchase amounts and returns a corresponding list of final amounts after applying the discount.
"""
final_amounts = []
for amount in purchase_amounts:
if amount <= 50:
final_amounts.append(round(a... | from solution import calculate_final_total, apply_discounts
def test_calculate_final_total_no_discount():
assert calculate_final_total([45.50]) == [45.50]
assert calculate_final_total([50.00]) == [50.00]
def test_calculate_final_total_ten_percent_discount():
assert calculate_final_total([75.00]) == [67.50... | [
{
"docstring": "This function takes a list of purchase amounts and returns a corresponding list of final amounts after applying the discount.",
"function_declaration": "def calculate_final_total(purchase_amounts):",
"function_name": "calculate_final_total",
"parameter_list": "(purchase_amounts)"
}... | [
1,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_amount(purchase_amount):\n \"\"\"\n Calculate the final purchase amount after applying the discount based on the rules provided.\n \n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00014905",
"row_id": 14905,
"seed_ids": "[2636]"
} | 0.621409 | Apps_14905 | I | [
"calculate_final_total",
"apply_discounts"
] | 2 | [
[
"apply_discounts",
"calculate_final_total"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13e0de106f5833b66d32ee215f2e6549c5e305ff | 9272df590a88fae41f7a3342f69ce8701dbc72b8 | |||
v1.0 | instruct | Apps | Apps_15029_I | Given an array of integers, your task is to determine the sum of all elements in the array that are prime numbers. If there are no prime numbers in the array, return 0.
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The first few prime numbers are: 2, 3, 5, 7, 1... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
d... | from solution import sum_of_primes
def test_sum_of_primes_with_primes():
assert sum_of_primes([2, 3, 4, 5, 6]) == 10
def test_sum_of_primes_without_primes():
assert sum_of_primes([4, 6, 8, 10, 12]) == 0
def test_sum_of_primes_with_repeated_primes():
assert sum_of_primes([1, 1, 2, 2, 2]) == 6
def test_su... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to calculate the sum of all prime numbers in an array.",
"function_declaration": "def sum_... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 T... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015029",
"row_id": 15029,
"seed_ids": "[3139]"
} | 0.658367 | Apps_15029 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71aefb3fc3db6609b676cc48379530e169bb760b | 703cc528acdc03785152a6165f499c99c198e547 | |||
v1.0 | instruct | Apps | Apps_15060_I | You are tasked with writing a function that determines the longest substring of two given strings, str1 and str2, that consists only of vowels (a, e, i, o, u).
### Input
Two strings, `str1` and `str2`.
### Output
Return the length of the longest common substring consisting only of vowels that appears in both `str1` a... | def is_vowel(char):
"""
Check if a character is a vowel.
"""
return char in 'aeiou'
def longest_vowel_substring(str1, str2):
"""
Determines the longest substring made up of only vowels common in both input strings.
Params:
str1 (str): First input string.
str2 (str): Sec... | from solution import longest_vowel_substring
def test_common_vowel_substring():
assert longest_vowel_substring("aeiouxxaeiou", "xxaeiouxx") == 5
def test_no_common_vowel_substring():
assert longest_vowel_substring("aeiox", "bdfgh") == 0
def test_single_common_vowel_substring():
assert longest_vowel_subst... | [
{
"docstring": "Check if a character is a vowel.",
"function_declaration": "def is_vowel(char):",
"function_name": "is_vowel",
"parameter_list": "(char)"
},
{
"docstring": "Determines the longest substring made up of only vowels common in both input strings.\n\nParams:\n str1 (str): First... | [
1,
0,
1,
0,
0,
0,
1,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_vowel_substr(str1, str2):\n \"\"\"\n Returns the length of the longest common substring consisting only of vowels in str1 and str2.\n \"... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00015060",
"row_id": 15060,
"seed_ids": "[4302]"
} | 0.712915 | Apps_15060 | I | [
"is_vowel",
"longest_vowel_substring"
] | 2 | [
[
"longest_vowel_substring",
"is_vowel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5b3e6af93b22627d50d79054967b8008d94adcf7 | 7b00330fef4e8437c519a108528b375225440e2d | |||
v1.0 | instruct | Apps | Apps_15071_I | A video streaming service uses a recommendation algorithm to suggest content to its users. Each user has a watch history of movies, where each movie is represented by a unique positive integer. The recommendation algorithm suggests movies based on the similarity of watch histories between users. Two users are said to h... | def find_similar_users(n, watch_histories):
"""
This function identifies all pairs of users with similar tastes in movies based
on their watch histories.
Parameters:
n (int): Number of users
watch_histories (list of list of int): A list where each element is a user's watch history
Retu... | def test_find_similar_users_case_1():
input_data = [
"4",
"3 1 2 3",
"3 2 1 3",
"2 4 5",
"3 6 7 8"
]
expected_output = "(1, 2)"
assert process_input_and_find_similar_users(input_data) == expected_output
def test_find_similar_users_case_2():
input_data = [
... | [
{
"docstring": "This function identifies all pairs of users with similar tastes in movies based\non their watch histories.\n\nParameters:\nn (int): Number of users\nwatch_histories (list of list of int): A list where each element is a user's watch history\n\nReturns:\nlist of tuple: A list of tuples where each ... | [
1,
1,
1,
1,
1,
1,
0,
1,
1,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_similar_users(n, watch_histories):\n from collections import defaultdict\n \n history_to_users = defaultdict(list)\n \n for i in range(n):\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00015071",
"row_id": 15071,
"seed_ids": "[2028]"
} | 0.611237 | Apps_15071 | I | [
"find_similar_users",
"process_input_and_find_similar_users"
] | 2 | [
[
"process_input_and_find_similar_users",
"find_similar_users"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 85a4bb8421829a1e833463e38d8620fa52b5caa9 | 1152363260830fbe181417e96c0383b0f258e73f | |||
v1.0 | instruct | Apps | Apps_15110_I | -----Problem-----
Emily is a secret agent who communicates using numeric sequences. These sequences form codes that must follow a defined set of rules. A sequence is valid if it can be formed by concatenating one or more instances of a specific "building block" sequence.
Each building block is a numeric string ... | def can_form_sequence(blocks, sequence):
"""
Determines if the sequence can be formed using the given blocks.
"""
n = len(sequence)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
for block in blocks:
if i >= len(block) and sequence[i-len(block):i] == b... | from solution import can_form_sequence, check_sequences
def test_can_form_sequence():
blocks = ["1", "101", "11"]
assert can_form_sequence(blocks, "11011") == True
assert can_form_sequence(blocks, "10101") == False
assert can_form_sequence(blocks, "111011") == True
assert can_form_sequence(blocks, ... | [
{
"docstring": "Determines if the sequence can be formed using the given blocks.",
"function_declaration": "def can_form_sequence(blocks, sequence):",
"function_name": "can_form_sequence",
"parameter_list": "(blocks, sequence)"
},
{
"docstring": null,
"function_declaration": "def check_s... | [
0,
0,
1,
1,
1,
0,
0,
1,
0,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_construct(sequence, blocks):\n n = len(sequence)\n dp = [False] * (n + 1)\n dp[0] = True\n\n for i in range(n):\n if dp[i]:\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00015110",
"row_id": 15110,
"seed_ids": "[1085]"
} | 0.669195 | Apps_15110 | I | [
"can_form_sequence",
"check_sequences"
] | 2 | [
[
"check_sequences",
"can_form_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 72e0136728e65d518a57bb9721b7d04349212706 | cdb79386d34e323a610552b8e351a6e62021b5e7 | |||
v1.0 | instruct | Apps | Apps_15149_I | You are given an integer array nums consisting of positive integers. You need to reorder the array in a way such that the sum of every pair of adjacent elements is a perfect square. If there are multiple ways to reorder the array, return any of them, otherwise, return an empty array if no such reordering is possible.
... | import itertools
import math
def is_perfect_square(x):
"""
Checks if a number x is a perfect square.
"""
s = int(math.sqrt(x))
return s * s == x
def reorder_to_perfect_squares(n, nums):
"""
Reorders the array so that the sum of every pair of adjacent elements is a perfect square.
If th... | from solution import reorder_to_perfect_squares_from_input
def test_case_1():
input_string = "3\n1 17 8"
result = reorder_to_perfect_squares_from_input(input_string)
assert result == [17, 8, 1] or result == [1, 8, 17]
def test_case_2():
input_string = "4\n2 2 2 2"
result = reorder_to_perfect_squar... | [
{
"docstring": "Checks if a number x is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Reorders the array so that the sum of every pair of adjacent elements is a perfect square.\nIf the... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom itertools import permutations\n\ndef is_perfect_square(x):\n s = int(math.isqrt(x))\n return s * s == x\n\ndef reorder_to_perfect_squares(nu... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00015149",
"row_id": 15149,
"seed_ids": "[2118]"
} | 0.692582 | Apps_15149 | I | [
"is_perfect_square",
"reorder_to_perfect_squares",
"reorder_to_perfect_squares_from_input"
] | 3 | [
[
"reorder_to_perfect_squares",
"is_perfect_square"
],
[
"reorder_to_perfect_squares_from_input",
"reorder_to_perfect_squares"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1b13db6f230e7e858c2237f9fce9fa82eebd9407 | 378a107ef486f9f0347ad262e25c2b6fec5e0425 | |||
v1.0 | instruct | Apps | Apps_15206_I | Write a function that takes a list of integers and returns a dictionary of the integers as keys and their corresponding list of prime factors (excluding 1) as values.
Prime factors of a number are prime numbers that divide the number exactly, without leaving a remainder. For instance, the prime factors of 12 are 2 and... | def prime_factors(n):
"""
Returns a list of prime factors of the given integer n.
"""
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
if i not in factors:
factors.append(i)
if n > 1 and n not in factors:
... | from solution import solution, prime_factors
def test_prime_factors_single():
assert prime_factors(10) == [2, 5]
assert prime_factors(15) == [3, 5]
assert prime_factors(21) == [3, 7]
def test_prime_factors_prime_number():
assert prime_factors(13) == [13]
assert prime_factors(7) == [7]
def test_pr... | [
{
"docstring": "Returns a list of prime factors of the given integer n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns a dictionary with integers as keys and their prime factors as values.",
"functio... | [
1,
1,
0,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n \"\"\"\n Helper function to return the list of prime factors of a given number n.\n \"\"\"\n factors = []\n d = 2\n while ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00015206",
"row_id": 15206,
"seed_ids": "[4498]"
} | 0.734136 | Apps_15206 | I | [
"prime_factors",
"solution"
] | 2 | [
[
"solution",
"prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7248e74b1274b3e7afcf0351e725afc5d3f1428a | 2d0f42b517ffe9f9097f9f2379441a1076e37462 | |||
v1.0 | instruct | Apps | Apps_15225_I | In a city known for its intricate network of roads, you are given a list of roads that connect various intersections. Each road has a travel time associated with it. The city authorities are planning to install a security camera on each road. Installing and maintaining security cameras costs money. Given an integer `n`... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import minimum_cost_to_install_cameras
def test_example_1():
n = 4
roads = [(1, 2, 5), (1, 3, 10), (2, 3, 2), (2, 4, 7), (3, 4, 1)]
assert minimum_cost_to_install_cameras(n, roads) == 8
def test_example_2():
n = 3
roads = [(1, 2, 4), (1, 3, 6), (2, 3, 1)]
assert minimum_cost_to_i... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015225",
"row_id": 15225,
"seed_ids": "[132]"
} | 0.701274 | Apps_15225 | I | [
"find",
"union",
"minimum_cost_to_install_cameras"
] | 3 | [
[
"minimum_cost_to_install_cameras",
"find"
],
[
"minimum_cost_to_install_cameras",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d923af912438798f4668802091709a8a8112a73f | 04dac8964bed8584ae010ec07bb34ecbc3857135 | |||
v1.0 | instruct | Apps | Apps_15277_I | ## Task:
You need to write a function **prime_triangle** that generates a pattern of prime numbers up to `n` rows.
* If the argument is 0 or a negative integer then it should return "" i.e. an empty string.
* The function should print prime numbers row-wise, one per row, for the first `n` rows where `n` is the input.... | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num ** 0.5) + 1, 2):
if num % i == 0:
return False
return True
... | from solution import is_prime, prime_triangle
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
assert is_prime(1) == False
def test_prime_triangle_zero_rows():
assert prime_tr... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a pattern of prime numbers up to `n` rows.",
"function_declaration": "def prime_triangle(n)... | [
0,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3,... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00015277",
"row_id": 15277,
"seed_ids": "[2812]"
} | 0.581029 | Apps_15277 | I | [
"is_prime",
"prime_triangle"
] | 2 | [
[
"prime_triangle",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4d6629fff21ea13f2a9ed9a8989e3afc7472060a | 48de5f7606044c29d25d77d226cc7e960480c75d | |||
v1.0 | instruct | Apps | Apps_15284_I | ## Task:
Given a list of integers, return a new list containing only the numbers that are prime. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
### Example:
```python
filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10])
```
should return
```python
[2, 3, 5, 7]
```
``... | def is_prime(n):
"""
Determine if the input 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... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(-3) == Fal... | [
{
"docstring": "Determine if the input number is a prime number.",
"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(numbers... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 % 2... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015284",
"row_id": 15284,
"seed_ids": "[4122]"
} | 0.658263 | Apps_15284 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 56c058113434148f75f748ccd06a0826a7add865 | a5ffa4527308094d009a34713fde857441f9af14 | |||
v1.0 | instruct | Apps | Apps_15362_I | Lina is an enthusiastic programmer who loves working with numbers. Recently, she has encountered a fascinating sequence called the Catalan sequence, where each Catalan number can be calculated using the formula:
C(n) = (2n)! / ((n + 1)! * n!)
The first few Catalan numbers are:
C(0)=1, C(1)=1, C(2)=2, C(3)=5, C(4)=14,... | import math
def catalan_number(n):
"""
Returns the nth Catalan number.
"""
return math.comb(2*n, n) // (n + 1)
def sum_of_catalan_numbers(n):
"""
Returns the sum of the first n Catalan numbers.
"""
return sum(catalan_number(i) for i in range(n + 1))
def sum_of_catalan_numbers_for_mult... | import pytest
from solution import sum_of_catalan_numbers, sum_of_catalan_numbers_for_multiple_cases
def test_catalan_number():
assert catalan_number(0) == 1
assert catalan_number(1) == 1
assert catalan_number(2) == 2
assert catalan_number(3) == 5
assert catalan_number(4) == 14
def test_sum_of_cat... | [
{
"docstring": "Returns the nth Catalan number.",
"function_declaration": "def catalan_number(n):",
"function_name": "catalan_number",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the first n Catalan numbers.",
"function_declaration": "def sum_of_catalan_numbers(n):",
... | [
0,
0,
1,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import factorial\n\ndef catalan_number(n):\n \"\"\"\n Returns the nth Catalan number.\n \"\"\"\n return factorial(2 * n) // (factorial(n + 1) ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015362",
"row_id": 15362,
"seed_ids": "[515]"
} | 0.562139 | Apps_15362 | I | [
"catalan_number",
"sum_of_catalan_numbers",
"sum_of_catalan_numbers_for_multiple_cases"
] | 3 | [
[
"sum_of_catalan_numbers",
"catalan_number"
],
[
"sum_of_catalan_numbers_for_multiple_cases",
"sum_of_catalan_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 03d718ea9e8734e891bdc0247d2b79d13bb32f72 | 999c3a86da85efec486b921f26bcdc56c8d468db | |||
v1.0 | instruct | Apps | Apps_15387_I | Lambda Inc. has hired you to track the rainfall in their experimental fields. They have provided you with a matrix `R` of dimensions `nxm`, where `Ri, j` represents the amount of rainfall in the ith row and the jth column. Lambda Inc. wants to investigate the rainfall data efficiently. To do this, they allow you to per... | def preprocess_sum_matrix(n, m, R):
# Create prefix sum matrix
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n+1):
for j in range(1, m+1):
prefix_sum[i][j] = R[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1]
return prefix_su... | from solution import preprocess_sum_matrix, compute_submatrix_sum, solve_rainfall_queries
def test_preprocess_sum_matrix():
rainfall_matrix = [
[9, 5, 4],
[2, 6, 7],
[1, 9, 3]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 9, 14, 18],
[0, 11, 22, 33],
... | [
{
"docstring": null,
"function_declaration": "def preprocess_sum_matrix(n, m, R):",
"function_name": "preprocess_sum_matrix",
"parameter_list": "(n, m, R)"
},
{
"docstring": null,
"function_declaration": "def compute_submatrix_sum(prefix_sum, iL, iR, jL, jR):",
"function_name": "comp... | [
1,
1,
0,
1,
1,
0,
1,
1,
0,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_prefix_sums(matrix):\n \"\"\"Calculates the prefix sums matrix for a given rainfall matrix.\"\"\"\n n = len(matrix)\n m = len(matrix[0])\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015387",
"row_id": 15387,
"seed_ids": "[1691]"
} | 0.561774 | Apps_15387 | I | [
"preprocess_sum_matrix",
"compute_submatrix_sum",
"solve_rainfall_queries"
] | 3 | [
[
"solve_rainfall_queries",
"compute_submatrix_sum"
],
[
"solve_rainfall_queries",
"preprocess_sum_matrix"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 63a470af4ff700bfc911f161ee4c020f82e23e4c | 26f8b8dd02ae1e6bf872d9ab77efed63bc2927e9 | |||
v1.0 | instruct | Apps | Apps_15548_I | Larry and Sergei are playing a game on a binary tree. A binary tree is a tree data structure where each node has at most two children. The game is played with one special node called the "queries node" and in each query, one can swap all the left and right children of any node in the tree. The goal of the game is to de... | class TreeNode:
def __init__(self, index):
self.index = index
self.left = None
self.right = None
def build_tree(n, nodes_info):
tree = {}
for i in range(n):
u, v, w = nodes_info[i]
if u not in tree:
tree[u] = TreeNode(u)
if v != -1:
tr... | from solution import play_game
def test_play_game_case_1():
n = 5
nodes_info = [
(1, 2, 3),
(2, 4, 5),
(3, -1, -1),
(4, -1, -1),
(5, -1, -1)
]
q = 3
queries = [2, 3, 2]
expected_output = ["NO", "NO", "YES"]
assert play_game(n, nodes_info, q, queries) ... | [] | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_same_tree_after_swaps(n, edges, q, queries):\n from collections import deque\n\n def clone_tree(root, graph):\n cloned = {}\n queue = deq... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015548",
"row_id": 15548,
"seed_ids": "[2050]"
} | 0.622919 | Apps_15548 | I | [
"build_tree",
"compare_trees",
"swap_children",
"find_node",
"play_game"
] | 5 | [
[
"play_game",
"build_tree"
],
[
"play_game",
"compare_trees"
],
[
"play_game",
"swap_children"
],
[
"swap_children",
"find_node"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2428f9edbd6e1443e33357bc52c69f5fd7c94184 | 099b3e487a9004402d445b9569bf6629dce40f70 | |||
v1.0 | instruct | Apps | Apps_15601_I | Write a function `max_rectangle_area(matrix)` that takes a 2D binary matrix filled with 0's and 1's and returns the area of the largest rectangle containing only 1's.
For example:
```python
matrix = [
[1, 1, 0, 1],
[1, 1, 1, 1],
[0, 1, 1, 0],
[0, 1, 1, 1]
]
max_rectangle_area(matrix) # returns 6
matri... | def max_histogram_area(heights):
"""
Helper function to find the maximum rectangular area under a histogram.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index ... | from solution import max_rectangle_area
def test_example1():
matrix = [
[1, 1, 0, 1],
[1, 1, 1, 1],
[0, 1, 1, 0],
[0, 1, 1, 1]
]
assert max_rectangle_area(matrix) == 6
def test_example2():
matrix = [
[0, 1, 0, 0, 1],
[1, 1, 1, 1, 0],
[1, 1, 1, 1,... | [
{
"docstring": "Helper function to find the maximum rectangular area under a histogram.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_ar... | [
1,
1,
1,
1,
1,
0,
1,
1,
1,
1
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or heights[index] >= ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015601",
"row_id": 15601,
"seed_ids": "[4766]"
} | 0.726414 | Apps_15601 | I | [
"max_histogram_area",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 23e4e142d8f9777b6a08012bcd465c5d817a3df3 | c29663de8cfd854bcfa41297991b9d7497ce4ceb | |||
v1.0 | instruct | Apps | Apps_15710_I | Sarah has a unique digital clock that malfunctioned. Instead of displaying the correct time, it shows 4 random non-negative integers. She needs to determine if it's possible to rearrange these integers to form a valid 24-hour format time (HH:MM).
A valid 24-hour format time ranges from 00:00 to 23:59. For example, 14:... | from itertools import permutations
def is_valid_time(a, b, c, d):
hour = a * 10 + b
minute = c * 10 + d
return 0 <= hour < 24 and 0 <= minute < 60
def can_form_valid_time(digits):
for perm in permutations(digits):
if is_valid_time(perm[0], perm[1], perm[2], perm[3]):
return "1"
... | from solution import is_valid_time, can_form_valid_time, check_times
def test_is_valid_time():
assert is_valid_time(1, 8, 3, 2) == True
assert is_valid_time(2, 4, 6, 9) == False
assert is_valid_time(0, 9, 5, 0) == True
assert is_valid_time(2, 5, 0, 0) == False
def test_can_form_valid_time():
asser... | [
{
"docstring": null,
"function_declaration": "def is_valid_time(a, b, c, d):",
"function_name": "is_valid_time",
"parameter_list": "(a, b, c, d)"
},
{
"docstring": null,
"function_declaration": "def can_form_valid_time(digits):",
"function_name": "can_form_valid_time",
"parameter... | [
0,
1,
0,
1,
1,
0,
1,
1,
1,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef can_form_valid_time(digits):\n for perm in permutations(digits):\n hours = perm[0] * 10 + perm[1]\n minut... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015710",
"row_id": 15710,
"seed_ids": "[742]"
} | 0.636253 | Apps_15710 | I | [
"is_valid_time",
"can_form_valid_time",
"check_times"
] | 3 | [
[
"can_form_valid_time",
"is_valid_time"
],
[
"check_times",
"can_form_valid_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7f1f696c047dd9f07f544a63a983fee02ac5b98f | a1204592a1c1c2b31521f5ae7ed40648e266ed17 | |||
v1.0 | instruct | Apps | Apps_15722_I | Chef recently became interested in number theory and is exploring the mathematical beauty behind prime numbers. He has a special interest in prime pairs. Two numbers are considered a prime pair if both numbers are prime and the absolute difference between them is 2 (for example, 3 and 5, or 11 and 13). He has now taske... | def sieve_of_eratosthenes(n):
"""
Creates a list of boolean values representing whether numbers are prime up to n.
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not primes
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + ... | import pytest
from solution import sieve_of_eratosthenes, count_prime_pairs, prime_pairs
def test_sieve():
assert sieve_of_eratosthenes(10) == [False, False, True, True, False, True, False, True, False, False, False]
assert sieve_of_eratosthenes(1) == [False, False]
def test_count_prime_pairs():
assert co... | [
{
"docstring": "Creates a list of boolean values representing whether numbers are prime up to n.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_prime_p... | [
0,
0,
1,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of boolean values indicating prime numbers up to n.\n \"\"\"\n is_pri... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00015722",
"row_id": 15722,
"seed_ids": "[1476]"
} | 0.724925 | Apps_15722 | I | [
"sieve_of_eratosthenes",
"count_prime_pairs",
"prime_pairs"
] | 3 | [
[
"count_prime_pairs",
"sieve_of_eratosthenes"
],
[
"prime_pairs",
"count_prime_pairs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 417d8684784314d0a34d10de1a0f3c88b4fd41a3 | b4be4ab238280bbf649b465138c0a46ca84c5ab1 | |||
v1.0 | instruct | Apps | Apps_15739_I | ## Task
You are organizing a marathon and have a list of participants' finish times in hours, minutes, and seconds. Your task is to determine the participants who finished the marathon in the median time.
Given a list of participants' finish times in the format `hh:mm:ss`, find the participants whose finish times are ... | def convert_to_seconds(time_str):
"""
Converts a time string in the format hh:mm:ss to the total number of seconds.
"""
h, m, s = map(int, time_str.split(':'))
return h * 3600 + m * 60 + s
def median_finish_times(times):
"""
Given a list of participants' finish times in the format hh:mm:ss,... | from solution import median_finish_times
def test_odd_number_of_times():
times = ["03:15:30", "02:45:20", "04:20:50", "03:10:15", "01:50:40"]
assert median_finish_times(times) == "03:10:15"
def test_even_number_of_times():
times = ["04:05:20", "03:35:10", "06:45:30", "03:25:40", "02:15:50", "05:30:25"]
... | [
{
"docstring": "Converts a time string in the format hh:mm:ss to the total number of seconds.",
"function_declaration": "def convert_to_seconds(time_str):",
"function_name": "convert_to_seconds",
"parameter_list": "(time_str)"
},
{
"docstring": "Given a list of participants' finish times in ... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def median_times(times):\n def time_to_seconds(t):\n hh, mm, ss = map(int, t.split(':'))\n return hh * 3600 + mm * 60 + ss\n\n # Convert the tim... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00015739",
"row_id": 15739,
"seed_ids": "[4678]"
} | 0.626844 | Apps_15739 | I | [
"convert_to_seconds",
"median_finish_times"
] | 2 | [
[
"median_finish_times",
"convert_to_seconds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6aacda2d28cc009fe930a033ec2bbc09e124e184 | ad92ba7b48c7cf3ac4d8abd40200b5bb577f6af6 | |||
v1.0 | instruct | Apps | Apps_15741_I | Create a function that takes an array of positive integers and returns an array containing only the prime numbers from the input array. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should utilize an efficient algorithm to determine the primality o... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns False.
"""
if n <= 1:
return False
if n == 2 or 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:
... | from solution import filter_primes, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(17) == True
assert is_prime(19) == True... | [
{
"docstring": "Returns True if n is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of positive integers.",
"function_declar... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 10 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00015741",
"row_id": 15741,
"seed_ids": "[4235]"
} | 0.687414 | Apps_15741 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca89d707e499654ecb3a26452f0126f349f79f57 | 26f6e6ac2bd063b88b376747e9d601f62f55d06f | |||
v1.0 | instruct | Apps | Apps_15794_I | ## Task
You are given a rectangular grid (matrix) where each cell contains an integer. Your task is to find the maximum sum of integers that can be obtained from any subrectangle within the grid. A subrectangle is defined by any four indices (i1, j1), (i2, j2) such that 0 ≤ i1 ≤ i2 < n and 0 ≤ j1 ≤ j2 < m, where n is t... | def max_subrectangle_sum(matrix):
"""
Calculate the maximum sum of any subrectangle within a given matrix.
"""
if not matrix or not matrix[0]:
return 0
n, m = len(matrix), len(matrix[0])
max_sum = float("-inf")
for left in range(m):
temp = [0] * n
for right ... | from solution import max_subrectangle_sum
def test_single_element():
matrix = [[1]]
assert max_subrectangle_sum(matrix) == 1
def test_all_positive_elements():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert max_subrectangle_sum(matrix) == 45
def test_all_negative_eleme... | [
{
"docstring": "Calculate the maximum sum of any subrectangle within a given matrix.",
"function_declaration": "def max_subrectangle_sum(matrix):",
"function_name": "max_subrectangle_sum",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum subarray using ... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subrectangle_sum(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n max_sum = float('-inf')... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00015794",
"row_id": 15794,
"seed_ids": "[3625]"
} | 0.663636 | Apps_15794 | I | [
"max_subrectangle_sum",
"kadane"
] | 2 | [
[
"max_subrectangle_sum",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 389a30fb9b99f335ffcd0dff05466c38952ceda3 | 5b1dd83aac462e6c6c2a49c9cfd0af6fde92827e | |||
v1.0 | instruct | Apps | Apps_15923_I | You are given a binary tree with N nodes. Each node of the tree contains some value. Your task is to determine the maximum sum of values that can be obtained from any path in the tree. A path is defined as any sequence of nodes from any starting node to any node in the tree along the parent-child connections. The path ... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def build_tree(values, parents):
nodes = [TreeNode(value) for value in values]
if not nodes:
return None
for i, parent in enumerate(parents, start=1):
if not nodes... | from solution import find_max_sum_in_tree
def test_sample_input():
N = 5
values = [10, -2, 7, 8, -6]
parents = [1, 1, 2, 2]
assert find_max_sum_in_tree(N, values, parents) == 23
def test_single_node():
N = 1
values = [5]
parents = []
assert find_max_sum_in_tree(N, values, parents) == 5... | [] | [
0,
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(nodes, parents, n):\n tree_nodes = [Tre... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00015923",
"row_id": 15923,
"seed_ids": "[2326]"
} | 0.721304 | Apps_15923 | I | [
"build_tree",
"max_path_sum",
"find_max_sum_in_tree"
] | 3 | [
[
"find_max_sum_in_tree",
"build_tree"
],
[
"find_max_sum_in_tree",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c99f41ee9e24eb3c4073ea8911550da118581917 | 24f368971382dff2dd68d3757d665f481d58dda4 | |||
v1.0 | instruct | Apps | Apps_15980_I | You are given a grid of size \(N \times M\) with non-negative integers in each cell. You can move from any cell to any of its 4 direct neighbors (up, down, left, right). You need to find a path from the top-left corner of the grid to the bottom-right corner such that the sum of integers along the path is minimized. You... | import heapq
def min_path_sum(grid):
N, M = len(grid), len(grid[0])
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
min_heap = [(grid[0][0], 0, 0)]
visited = set()
while min_heap:
current_sum, x, y = heapq.heappop(min_heap)
if (x, y) == (N-1, M-1):
return c... | from solution import solve_min_path_sum, process_input
def test_min_path_sum():
input_string = """2
3 3
1 3 1
1 5 1
4 2 1
2 2
1 2
1 1"""
test_cases = process_input(input_string)
result = solve_min_path_sum(test_cases)
assert result == [7, 3], f"Expected [7, 3] but got {result}"
def test_single_cell():... | [
{
"docstring": null,
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve_min_path_sum(test_cases):",
"function_name": "solve_min_path_sum",
"parameter_list": "(te... | [
0,
0,
0,
0,
1,
0,
0,
1,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef min_path_sum(grid):\n n = len(grid)\n m = len(grid[0])\n \n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n min_heap = [(grid[0... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00015980",
"row_id": 15980,
"seed_ids": "[579]"
} | 0.725136 | Apps_15980 | I | [
"min_path_sum",
"solve_min_path_sum",
"process_input"
] | 3 | [
[
"solve_min_path_sum",
"min_path_sum"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c0438f979b81e7c08250e1c2057253821b40d5b9 | de2b8586a4a45d78351cb4d43055e10a64e9cd1f | |||
v1.0 | instruct | Apps | Apps_15987_I | Lilly is a software engineer working on a new string manipulation library. One of the functionalities she needs to implement is a function that checks the balance and proper nesting of a specific type of brackets used in a particular scientific notation. The notation uses three types of brackets: round brackets '()', s... | def is_balanced(s):
"""
Check if the input string s is properly nested and balanced.
"""
stack = []
opening = '([{'
closing = ')]}'
matching = {')': '(', ']': '[', '}': '{'}
for char in s:
if char in opening:
stack.append(char)
elif char in closing:
... | from solution import check_balanced_brackets
def test_single_balanced_strings():
assert check_balanced_brackets(1, ["([]{})"]) == ["YES"]
assert check_balanced_brackets(1, ["[{}]"]) == ["YES"]
assert check_balanced_brackets(1, ["()[]{}"]) == ["YES"]
def test_single_unbalanced_strings():
assert check_b... | [
{
"docstring": "Check if the input string s is properly nested and balanced.",
"function_declaration": "def is_balanced(s):",
"function_name": "is_balanced",
"parameter_list": "(s)"
},
{
"docstring": "Given a number of strings, determine for each string if it is balanced and properly nested.... | [
1,
1,
1,
0,
1,
1,
1,
1,
1
] | 8 | easy | 0.889 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced_and_nested(strings):\n \"\"\"\n Checks if each string in the list is properly nested and balanced.\n \n :param strings: List of strings ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00015987",
"row_id": 15987,
"seed_ids": "[1050]"
} | 0.706787 | Apps_15987 | I | [
"is_balanced",
"check_balanced_brackets"
] | 2 | [
[
"check_balanced_brackets",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6088e1ae877bfe7aae218d1a5430138cbd35e049 | 358f6a76db93d22142931ea6a3592c937570def4 | |||
v1.0 | instruct | Apps | Apps_16051_I | -----Binary Tree Labelling-----
Given a binary tree, we want to label each node of the tree with a unique integer in such a way that the sum of all labels on the nodes in the left subtree of any given node is less than the sum of all labels on the nodes in the right subtree of that node.
Write a function that takes th... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def label_tree(root):
# Helper function to perform in-order traversal and label the nodes
def in_order_traversal(node, current_label):
if node is not None:
current_label ... | from solution import label_binary_tree
def test_label_binary_tree_small():
n = 7
level_order = [1, 2, 3, 4, 5, 6, 7]
result = label_binary_tree(n, level_order)
assert len(result) == n
assert result == [4, 2, 6, 1, 3, 5, 7]
def test_label_binary_tree_single_node():
n = 1
level_order = [1]
... | [] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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 s... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016051",
"row_id": 16051,
"seed_ids": "[731]"
} | 0.729868 | Apps_16051 | I | [
"label_tree",
"construct_tree_from_level_order",
"label_binary_tree"
] | 3 | [
[
"label_binary_tree",
"construct_tree_from_level_order"
],
[
"label_binary_tree",
"label_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 4c957c065abc20d11047052bdf93522337cc5ab4 | e15763a7e5aeb8b5bb60c10025306bda1e9ab015 | |||
v1.0 | instruct | Apps | Apps_16123_I | Write a function that takes two strings as input, representing two integers in Roman numeral format, and returns their sum as a Roman numeral. The input strings will not necessarily be in their simplest form, but the output must be.
Roman numeral symbols:
* `I = 1`
* `V = 5`
* `X = 10`
* `L = 50`
* `C = 100`
* `D = 50... | def roman_to_int(s):
"""
Convert a Roman numeral to an integer.
"""
roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
total = 0
prev_value = 0
for char in reversed(s):
value = roman_dict[char]
if value < prev_value:
total -= value... | from solution import roman_sum
def test_roman_sum_simple():
assert roman_sum("XIII", "IV") == "XVII"
assert roman_sum("X", "X") == "XX"
assert roman_sum("IX", "I") == "X"
assert roman_sum("I", "I") == "II"
def test_roman_sum_complex():
assert roman_sum("DCCC", "CC") == "M"
assert roman_sum("CD... | [
{
"docstring": "Convert a Roman numeral to an integer.",
"function_declaration": "def roman_to_int(s):",
"function_name": "roman_to_int",
"parameter_list": "(s)"
},
{
"docstring": "Convert an integer to a Roman numeral.",
"function_declaration": "def int_to_roman(num):",
"function_na... | [
1,
1,
0,
1,
1,
0,
1,
1,
0
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def roman_to_int(roman):\n roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n total = 0\n prev_value = 0\n \n for cha... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016123",
"row_id": 16123,
"seed_ids": "[3939]"
} | 0.666831 | Apps_16123 | I | [
"roman_to_int",
"int_to_roman",
"roman_sum"
] | 3 | [
[
"roman_sum",
"int_to_roman"
],
[
"roman_sum",
"roman_to_int"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 265bdfbe97c869c4a7286170bea1b26016cdd68d | efada10b27971b8cf80e6547cd233b3865b0855a | |||
v1.0 | instruct | Apps | Apps_16149_I | You are given a list of integers representing the sales over a number of days in a bookstore. From this list, we want to generate a report that helps analyze sales performance over a period of time.
# Task:
Write functions:
```
1. best_day(sales_list) - Returns the day (0-based index) with the highest sales.
2. worst... | def best_day(sales_list):
"""
Returns the day (0-based index) with the highest sales.
"""
return sales_list.index(max(sales_list))
def worst_day(sales_list):
"""
Returns the day (0-based index) with the lowest sales.
"""
return sales_list.index(min(sales_list))
def average_sales(sales_... | from solution import best_day, worst_day, average_sales, above_average_days
def test_best_day():
assert best_day([200, 180, 220, 210, 150, 300, 170]) == 5
assert best_day([1, 2, 3, 4, 5]) == 4
assert best_day([1000, 1000, 1000]) == 0
def test_worst_day():
assert worst_day([200, 180, 220, 210, 150, 300... | [
{
"docstring": "Returns the day (0-based index) with the highest sales.",
"function_declaration": "def best_day(sales_list):",
"function_name": "best_day",
"parameter_list": "(sales_list)"
},
{
"docstring": "Returns the day (0-based index) with the lowest sales.",
"function_declaration":... | [
0,
1,
1,
0,
1,
1,
1,
1,
0,
1
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def best_day(sales_list):\n \"\"\"\n Returns the 0-based index of the day with the highest sales.\n \"\"\"\n return sales_list.index(max(sales_list))\n\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016149",
"row_id": 16149,
"seed_ids": "[4061]"
} | 0.661828 | Apps_16149 | I | [
"best_day",
"worst_day",
"average_sales",
"above_average_days"
] | 4 | [
[
"above_average_days",
"average_sales"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 670fdaaaa696c2b509d0f5684cf33a32f64be8fc | 8bd7cee2fd4ac0b04ee54946f5c7b056673bb913 | |||
v1.0 | instruct | Apps | Apps_16158_I | Develop a function that takes an array of numbers and returns an array where each number is replaced by the nearest prime number. If a number is equidistant to two primes, the smaller prime should be selected.
To determine the nearest prime, you may use a helper function that checks if a number is prime.
## Examples
... | def is_prime(num):
"""Check if a given number is a prime number."""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i... | from solution import is_prime, nearest_prime, nearestPrimes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_nearest_prime():
assert nearest_pri... | [
{
"docstring": "Check if a given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the nearest prime number to the given number n.",
"function_declaration": "def nearest_prime(n):",
... | [
0,
1,
0,
1,
1,
1,
1,
1,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function that checks if the number n is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016158",
"row_id": 16158,
"seed_ids": "[4529]"
} | 0.720835 | Apps_16158 | I | [
"is_prime",
"nearest_prime",
"nearestPrimes"
] | 3 | [
[
"nearestPrimes",
"nearest_prime"
],
[
"nearest_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b42083342cd0a53c548cf35462b6ae0d4fdd5518 | d83496bbe67cb9ecd60d3124df774cb9ffc24231 | |||
v1.0 | instruct | Apps | Apps_16159_I | ## Math Evaluator
## Story
You're hired by a company that specializes in providing tools for educational purposes. You have been tasked with developing a simple math expression evaluator which can take a string input representing some basic math operations and evaluates it to an integer result.
## Task
You are requ... | def evaluate_math_expression(expression: str) -> int:
"""
Evaluates a given mathematical expression containing non-negative integers and the operators + and *.
The expression obeys the BODMAS rule and does not contain any parentheses.
"""
# Split the expression first by '+' to handle addition separa... | from solution import evaluate_math_expression
def test_single_number():
assert evaluate_math_expression("5") == 5
def test_simple_addition():
assert evaluate_math_expression("3+2") == 5
def test_simple_multiplication():
assert evaluate_math_expression("4*2") == 8
def test_combined_operations_1():
as... | [
{
"docstring": "Evaluates a given mathematical expression containing non-negative integers and the operators + and *.\nThe expression obeys the BODMAS rule and does not contain any parentheses.",
"function_declaration": "def evaluate_math_expression(expression):",
"function_name": "evaluate_math_express... | [
1,
1,
0,
1,
1,
0,
1,
1,
0,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def evaluate_math_expression(expression: str) -> int:\n # Split expression by '+' keeping track of segments\n parts = expression.split('+')\n \n # Evalu... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016159",
"row_id": 16159,
"seed_ids": "[1661]"
} | 0.676905 | Apps_16159 | I | [
"evaluate_math_expression",
"eval_multiplication"
] | 2 | [
[
"evaluate_math_expression",
"eval_multiplication"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3beccbb6fce6bee2e096975867b3f9a0f73e5da2 | d4deeddb319288aaa80784adb26d1ef280adc1b3 | |||
v1.0 | instruct | Apps | Apps_16165_I | Chef loves symmetry. He often plays with numbers and tries to find patterns among them. Today, he has come across an interesting problem and would love your help to solve it. The problem goes like this: Given two numbers A and B, find the greatest common divisor (GCD) of all the integers between A and B inclusive that ... | import math
def is_palindrome(n):
"""
Check if a given number n is a palindrome.
"""
return str(n) == str(n)[0:][::-1]
def find_palindromes(a, b):
"""
Find all palindromes in the range [a, b] inclusive.
"""
palindromes = [i for i in range(a, b + 1) if is_palindrome(i)]
return palin... | from solution import chef_loves_symmetry
def test_example_case1():
assert chef_loves_symmetry(1, [(10, 20)]) == ["Case #1: 11"]
def test_example_case2():
assert chef_loves_symmetry(1, [(5, 30)]) == ["Case #1: 1"]
def test_single_palindrome():
# Only one palindrome (11), GCD should be 11 itself
assert... | [
{
"docstring": "Check if a given number n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find all palindromes in the range [a, b] inclusive.",
"function_declaration": "def find_palindromes(a... | [
0,
0,
0,
1,
0,
0,
1,
0,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef gcd_of_palindr... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016165",
"row_id": 16165,
"seed_ids": "[864]"
} | 0.63674 | Apps_16165 | I | [
"is_palindrome",
"find_palindromes",
"gcd_of_list",
"gcd_of_palindromes_in_range",
"chef_loves_symmetry"
] | 5 | [
[
"chef_loves_symmetry",
"gcd_of_palindromes_in_range"
],
[
"find_palindromes",
"is_palindrome"
],
[
"gcd_of_palindromes_in_range",
"find_palindromes"
],
[
"gcd_of_palindromes_in_range",
"gcd_of_list"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 1f997dce8327b7ba615bb40e17cf5b0682f7fa5e | 636ce48c4626633b5288a2f97802c49ac9ed8abb | |||
v1.0 | instruct | Apps | Apps_16178_I | A **harmonic divisor number** is a positive integer whose divisors have a harmonic mean that is an integer.
The **harmonic mean** of a set of numbers is the reciprocal of the arithmetic mean of the reciprocals of the numbers. For example, the harmonic mean of 1, 2, and 4 is obtained by:
1. Finding the reciprocals: 1,... | def harmonic_mean(lst):
"""
Compute the harmonic mean of a list of divisors.
"""
from fractions import Fraction
if not lst:
return 0
n = len(lst)
sum_reciprocal = sum(Fraction(1, d) for d in lst)
harmonic_mean_value = Fraction(n, sum_reciprocal)
return harmonic... | from solution import harmonic_divisors, is_harmonic_divisor_number, divisors
def test_is_harmonic_divisor_number():
assert is_harmonic_divisor_number(1) == True
assert is_harmonic_divisor_number(6) == True
assert is_harmonic_divisor_number(28) == True
assert is_harmonic_divisor_number(10) == False
def... | [
{
"docstring": "Compute the harmonic mean of a list of divisors.",
"function_declaration": "def harmonic_mean(lst):",
"function_name": "harmonic_mean",
"parameter_list": "(lst)"
},
{
"docstring": "Compute the divisors of a number n.",
"function_declaration": "def divisors(n):",
"func... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def harmonic_divisors(x):\n def harmonic_mean(divisors):\n n = len(divisors)\n sum_reciprocals = sum(1/d for d in divisors)\n return n / sum... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016178",
"row_id": 16178,
"seed_ids": "[3405]"
} | 0.637828 | Apps_16178 | I | [
"harmonic_mean",
"divisors",
"is_harmonic_divisor_number",
"harmonic_divisors"
] | 4 | [
[
"harmonic_divisors",
"is_harmonic_divisor_number"
],
[
"is_harmonic_divisor_number",
"divisors"
],
[
"is_harmonic_divisor_number",
"harmonic_mean"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f17d5d7894daabcc7080e236e2a94bc16d7d4707 | e26ee60d509edd96214959400278ed3b66a03a5d | |||
v1.0 | instruct | Apps | Apps_16238_I | You are given a string s consisting of lowercase English letters. Your task is to determine if you can remove exactly one character from the string to make it a palindrome. A palindrome is a string that reads the same backward as forward.
Write a function to check if it is possible to convert the given string to a pal... | def can_be_palindrome_by_removing_one_char(s):
"""
Determines if a string can be converted to a palindrome
by removing exactly one character.
"""
def is_palindrome(x):
return x == x[::-1]
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
... | import pytest
from solution import check_remove_one_char_palindrome
def test_example_case_1():
assert check_remove_one_char_palindrome("abca") == "YES"
def test_example_case_2():
assert check_remove_one_char_palindrome("abc") == "NO"
def test_full_palindrome():
assert check_remove_one_char_palindrome("ra... | [
{
"docstring": "Determines if a string can be converted to a palindrome\nby removing exactly one character.",
"function_declaration": "def can_be_palindrome_by_removing_one_char(s):",
"function_name": "can_be_palindrome_by_removing_one_char",
"parameter_list": "(s)"
},
{
"docstring": null,
... | [
0,
0,
1,
1,
0,
0,
0,
1,
1,
0
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n def is_palindrome_range(i, j):\n return all(s[k] == s[j-k+i] for k in range(i, j))\n\n l, r = 0, len(s) - 1\n while l ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016238",
"row_id": 16238,
"seed_ids": "[48]"
} | 0.803635 | Apps_16238 | I | [
"can_be_palindrome_by_removing_one_char",
"check_remove_one_char_palindrome"
] | 2 | [
[
"check_remove_one_char_palindrome",
"can_be_palindrome_by_removing_one_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2f463a1ff22351ee02194d9f057953796100bff9 | f7637a601bc086006cd658c2ef87d94294701781 | |||
v1.0 | instruct | Apps | Apps_16349_I | You are given a tree structure with `n` nodes, each node containing a single integer value. The tree is rooted at node `1`. Your task is to implement a function that calculates the maximum path sum for any path in the tree.
A path is defined as any sequence of nodes from some starting node to any node in the tree alon... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(n, values, edges):
nodes = [TreeNode(values[i]) for i in range(n)]
for u, v in edges:
nodes[u - 1].children.append(nodes[v - 1])
nodes[v - 1].children.append(nodes[u - 1])
ret... | from solution import find_max_path_sum_in_trees
def test_max_path_sum_single_case():
T = 1
test_cases = [(6, [1, 2, -3, 4, -2, 6], [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)])]
result = find_max_path_sum_in_trees(T, test_cases)
assert result == [7]
def test_max_path_sum_multiple_cases():
T = 2
te... | [] | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(n, values, edges):\n nodes = [TreeNode(... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016349",
"row_id": 16349,
"seed_ids": "[1140]"
} | 0.695124 | Apps_16349 | I | [
"build_tree",
"max_path_sum",
"find_max_path_sum_in_trees"
] | 3 | [
[
"find_max_path_sum_in_trees",
"build_tree"
],
[
"find_max_path_sum_in_trees",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | cb6a95ec5d3197c5b92bef6fb0cdd6759374599b | a9fefbe7298f0d97cf1240ae50aedb635d27175a | |||
v1.0 | instruct | Apps | Apps_16465_I | Write a program that reads strings until an empty string is given.
The program needs to determine if each string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, ignoring spaces, punctuation, and capitalization.
-----Input:-----
- The in... | import re
def is_palindrome(s):
"""
Checks if the given string is a palindrome considering only alphanumeric characters and ignoring case.
"""
cleaned = re.sub(r'[^A-Za-z0-9]', '', s).lower()
return cleaned == cleaned[::-1]
def check_palindromes(strings):
"""
Takes a list of strings and re... | 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("No lemon, no melon") == True
assert is_palindrome("Hello, World!") == False
assert is_palindrome("Madam In Eden, I'm Adam") == True
asser... | [
{
"docstring": "Checks if the given string is a palindrome considering only alphanumeric characters and ignoring case.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a list of... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
0
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_palindrome(s):\n \"\"\"\n Checks if a given string s is a palindrome.\n Ignores spaces, punctuation, and capitalization.\n \"\"\"\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00016465",
"row_id": 16465,
"seed_ids": "[1589]"
} | 0.795866 | Apps_16465 | I | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ff62c000384aa3055b0af39cefcef8183c00a41 | 4375eb30ea8aac429903568fe8abad851e5719a0 | |||
v1.0 | instruct | Apps | Apps_16467_I | Chef loves playing with numbers and he recently discovered the concept of "lucky numbers". A lucky number is defined as a number that contains only the digits 4 and 7. Chef is curious to know how many lucky numbers exist within a given range \([A, B]\) inclusive. Can you help him?
-----Input-----
- The first line of t... | def is_lucky_number(n):
"""
Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.
"""
while n > 0:
digit = n % 10
if digit != 4 and digit != 7:
return False
n = n // 10
return True
def count_lucky_numbers(A, B):
"""
Returns the c... | from solution import is_lucky_number, count_lucky_numbers
def test_is_lucky_number():
# Test lucky numbers
assert is_lucky_number(4) == True
assert is_lucky_number(7) == True
assert is_lucky_number(44) == True
assert is_lucky_number(47) == True
# Test non-lucky numbers
assert is_lucky_numbe... | [
{
"docstring": "Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.",
"function_declaration": "def is_lucky_number(n):",
"function_name": "is_lucky_number",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of lucky numbers within the range [A, B] inclu... | [
1,
1,
0,
0,
0,
0,
0,
0,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_lucky_number(n):\n \"\"\"\n Checks if a number is a lucky number i.e., it contains only the digits 4 and 7.\n \"\"\"\n while n > 0:\n digi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016467",
"row_id": 16467,
"seed_ids": "[743]"
} | 0.592299 | Apps_16467 | I | [
"is_lucky_number",
"count_lucky_numbers",
"main"
] | 3 | [
[
"count_lucky_numbers",
"is_lucky_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cc0ec2cd26796ca45261e7a401556451eb994cc1 | 21697342bb490880e0839f77f647ae96fbb4e0c8 | |||
v1.0 | instruct | Apps | Apps_16477_I | Given a binary tree, determine if it is a valid binary search tree (BST).
A binary search tree (BST) is defined as follows:
- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- Both the left and r... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes):
tree_nodes = {}
for val, left, right in nodes:
if val not in tree_nodes:
tree_nodes[val] = TreeNode(val)
if... | import pytest
from solution import TreeNode, build_tree, is_valid_BST, check_bst
def test_is_valid_BST():
assert check_bst([(2, 1, 3), (1, -1, -1), (3, -1, -1)]) == True
def test_tree_with_duplicates():
assert check_bst([(2, 2, 3), (2, -1, -1), (3, -1, -1)]) == False
def test_left_child_greater_than_root():
... | [] | [
1,
1,
1,
1,
1,
0,
1,
0,
1,
1
] | 8 | easy | 0.8 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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_tr... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016477",
"row_id": 16477,
"seed_ids": "[1120]"
} | 0.637352 | Apps_16477 | I | [
"build_tree",
"is_valid_BST",
"check_bst"
] | 3 | [
[
"check_bst",
"build_tree"
],
[
"check_bst",
"is_valid_BST"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b099fcbb71a82afa1bad64f233b71bfffbae23bb | 212c2d91a526937eb0a3793bdf7ac9387248131d | |||
v1.0 | instruct | Apps | Apps_16574_I | In a faraway land, a king has a peculiar liking for palindromic numbers and prime numbers. He decides to invent a new kind of number which is both a palindrome and a prime. He calls these numbers "Prime Palindromes."
A number is said to be a palindrome if it reads the same forwards and backwards, for example, 121 or 1... | 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 is_palindrome(n):
return str(n) == str... | from solution import smallest_prime_palindrome
def test_case_1():
assert smallest_prime_palindrome(31) == 101
def test_case_2():
assert smallest_prime_palindrome(100) == 101
def test_case_3():
assert smallest_prime_palindrome(131) == 131
def test_case_4():
assert smallest_prime_palindrome(1) == 2
d... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
0,
1,
1,
0,
0,
1,
1,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_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_9 | {
"original_instruction": "",
"prompt_id": "00016574",
"row_id": 16574,
"seed_ids": "[2135]"
} | 0.740876 | Apps_16574 | I | [
"is_prime",
"is_palindrome",
"smallest_prime_palindrome"
] | 3 | [
[
"smallest_prime_palindrome",
"is_palindrome"
],
[
"smallest_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f0e6bd021643b313230209c5f94cb10bf68f9368 | 550fefbceca544590e52de8a359156cf41f53bef | |||
v1.0 | instruct | Apps | Apps_16622_I | You are a programmer on a mission to retrieve ancient data from an abandoned server room. The room contains an n × n grid of lockers, each potentially containing a storage unit. Each locker is identified by its row and column in the grid, both ranging from 1 to n. To retrieve the data, you must unlock exactly k storage... | def create_grid_and_start(n, k):
"""
Creates an n x n grid and specifies a starting point (r, c) such that
exactly k storage units can be unlocked without spreading corruption beyond k units.
"""
grid = [['0'] * n for _ in range(n)]
storage_units = k
# Start placing '1's in the diagonal... | import pytest
from solution import create_grid_and_start, format_output, place_and_unlock
def test_create_grid_and_start_with_5_and_5():
grid, r, c = create_grid_and_start(5, 5)
assert grid == [['1', '0', '0', '0', '0'],
['0', '1', '0', '0', '0'],
['0', '0', '1', '0', '0... | [
{
"docstring": "Creates an n x n grid and specifies a starting point (r, c) such that\nexactly k storage units can be unlocked without spreading corruption beyond k units.",
"function_declaration": "def create_grid_and_start(n, k):",
"function_name": "create_grid_and_start",
"parameter_list": "(n, k... | [
0,
0,
1,
1,
0,
1,
0,
0,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def place_storage_units(n, k):\n \"\"\"\n This function places exactly k storage units on an n x n grid in such a way that corruption can be contained.\n I... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00016622",
"row_id": 16622,
"seed_ids": "[2310]"
} | 0.602647 | Apps_16622 | I | [
"create_grid_and_start",
"format_output",
"place_and_unlock"
] | 3 | [
[
"place_and_unlock",
"create_grid_and_start"
],
[
"place_and_unlock",
"format_output"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | c95da87aac3116a7d4bf0e88b96910386b93f99e | 10db4c9a138be7eace947f9868a7c4abdbf62c16 | |||
v1.0 | instruct | Apps | Apps_16661_I | You are given a 2D grid with $N$ rows and $M$ columns, where each cell contains a non-negative integer representing the elevation at that point. The grid defines a landscape where water can only travel to adjacent cells (left, right, up, down) if the elevation of the adjacent cell is less than or equal to the current c... | def can_flow(grid, N, M, water_level):
"""
Check if water can flow from the top-left to the bottom-right at 'water_level'.
"""
from collections import deque
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(0, 0)])
visited = set([(0, 0)])
while queue:
x, y... | import pytest
from solution import highest_water_level
def test_example_case():
grid = [
[9, 8, 7, 6],
[6, 5, 4, 7],
[8, 3, 2, 1],
[7, 6, 5, 4]
]
N, M = 4, 4
assert highest_water_level(grid, N, M) == 4
def test_single_cell():
grid = [
[0]
]
N, M = 1,... | [
{
"docstring": "Check if water can flow from the top-left to the bottom-right at 'water_level'.",
"function_declaration": "def can_flow(grid, N, M, water_level):",
"function_name": "can_flow",
"parameter_list": "(grid, N, M, water_level)"
},
{
"docstring": "Calculates the highest water level... | [
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_flow(grid, N, M, water_level):\n \"\"\"\n Check if water can flow from the top-left to the bottom-right at 'water_level'.\n \"\"\"\n from collec... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016661",
"row_id": 16661,
"seed_ids": "[1533]"
} | 0.658834 | Apps_16661 | I | [
"can_flow",
"highest_water_level"
] | 2 | [
[
"highest_water_level",
"can_flow"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52bfe336e9900cd985dcb527c6ad1bbdb682d8a1 | 8eefcb31501d5b963a1839238af34c26022b8473 | |||
v1.0 | instruct | Apps | Apps_16673_I | You are given an array of $N$ integers. Your task is to find the maximum sum of any subsequence such that no two consecutive elements are selected.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line ... | def max_non_consecutive_sum(arr):
if not arr:
return 0
including = 0
excluding = 0
for num in arr:
new_excluding = max(including, excluding)
including = excluding + num
excluding = new_excluding
return max(including, excluding)
def process_input(input_... | from solution import max_non_consecutive_sum, process_input, format_output, solve
def test_max_non_consecutive_sum():
assert max_non_consecutive_sum([3, 2, 5, 10]) == 13
assert max_non_consecutive_sum([-1, -2, -3, -4]) == 0
assert max_non_consecutive_sum([1, 2, 3, 4, 5]) == 9
assert max_non_consecutive... | [
{
"docstring": null,
"function_declaration": "def max_non_consecutive_sum(arr):",
"function_name": "max_non_consecutive_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_str):",
"function_name": "process_input",
"parameter_li... | [
1,
0,
1,
0,
0,
1,
0,
1,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_no_consecutive(arr):\n include = 0 # sum including the current element\n exclude = 0 # sum excluding the current element\n \n for num in a... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016673",
"row_id": 16673,
"seed_ids": "[708]"
} | 0.818472 | Apps_16673 | I | [
"max_non_consecutive_sum",
"process_input",
"format_output",
"solve"
] | 4 | [
[
"process_input",
"max_non_consecutive_sum"
],
[
"solve",
"format_output"
],
[
"solve",
"process_input"
]
] | 3 | [
"process_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | c92d5417fea498ab9846baecb256e193ad13c4d7 | 8c6065819dbcb383ec9f9229b7aa629329828d1f | |||
v1.0 | instruct | Apps | Apps_16820_I | Write a function that takes a string s as input and returns all possible substrings that are palindromes. A palindromic string is one that reads the same forward and backwards. The substrings should be returned in an array in lexicographical order and should not contain duplicates.
For example, given the input string ... | def is_palindrome(s):
"""
Checks if a given string is a palindrome.
"""
return s == s[::-1]
def palindromic_substrings(s):
"""
Returns all unique palindromic substrings of the input string in lexicographical order.
"""
palindromes = set()
for i in range(len(s)):
for j i... | from solution import palindromic_substrings
def test_single_character():
assert palindromic_substrings("a") == ["a"]
assert palindromic_substrings("b") == ["b"]
def test_no_palindromes():
assert palindromic_substrings("abc") == ["a", "b", "c"]
def test_all_palindromes():
assert palindromic_substrings... | [
{
"docstring": "Checks if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all unique palindromic substrings of the input string in lexicographical order.",
"function_de... | [
1,
0,
0,
0,
1,
0,
0,
1,
0,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef find_palindromic_substrings(s):\n palindromic_substrings = set()\n n = len(s)\n \n # Generate all ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016820",
"row_id": 16820,
"seed_ids": "[2965]"
} | 0.747848 | Apps_16820 | I | [
"is_palindrome",
"palindromic_substrings"
] | 2 | [
[
"palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 56edda31de3d55f4a6f9f2a668c7754e76b90407 | d36cd597aabf0a072893df3ed0accd7d20c79426 | |||
v1.0 | instruct | Apps | Apps_16844_I | Matthew loves organizing his bookshelf. He arranges his books in non-decreasing order of their heights. One day, Matthew purchased a set of new books and added them randomly to his bookshelf. Now, some books on the shelf are out of order. To restore order, he wants to know the minimum number of books he needs to move t... | def min_books_to_move(test_cases):
results = []
for n, heights in test_cases:
# Find the longest non-decreasing subsequence
lis = []
for h in heights:
pos = binary_search_lis(lis, h)
if pos == len(lis):
lis.append(h)
else:
... | def test_min_books_to_move():
test_cases = [
(4, [4, 3, 2, 1]),
(5, [10, 20, 20, 10, 30]),
(6, [2, 1, 2, 3, 2, 2])
]
expected_results = [3, 1, 2]
assert min_books_to_move(test_cases) == expected_results
def test_all_books_in_order():
test_cases = [
(5, [1, 2, 3, 4,... | [
{
"docstring": null,
"function_declaration": "def min_books_to_move(test_cases):",
"function_name": "min_books_to_move",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def binary_search_lis(lis, height):",
"function_name": "binary_search_lis",
"... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_books_to_move(T, test_cases):\n results = []\n for N, heights in test_cases:\n # Compute the longest non-decreasing subsequence (LNDS)\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016844",
"row_id": 16844,
"seed_ids": "[714]"
} | 0.77696 | Apps_16844 | I | [
"min_books_to_move",
"binary_search_lis"
] | 2 | [
[
"min_books_to_move",
"binary_search_lis"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ec3d73998a656eaba6a42b58f7cc872c805348a3 | 41cc283b75194eebddc4319d795b07cdc5486e85 | |||
v1.0 | instruct | Apps | Apps_16867_I | Polycarp has a garden represented as a grid with $n$ rows and $m$ columns. The garden can either be empty (represented by a 0) or have weeds (represented by a 1). Polycarp wants to plant a rectangular section of flowers in the garden. You need to determine the size of the largest rectangular section of the garden that ... | def maximal_rectangle(grid):
"""
This function takes a grid as input and returns the area of the largest rectangle
containing only 0s.
"""
if not grid:
return 0
n, m = len(grid), len(grid[0])
dp = [0] * m
max_area = 0
for i in range(n):
for j in range(m):
... | from solution import process_input
def test_example_cases():
t = 2
test_cases_input = [
"3 4",
"1 0 0 0",
"0 0 0 1",
"0 1 0 0",
"2 5",
"0 1 1 0 1",
"0 0 0 0 0"
]
expected_output = [4, 5]
assert process_input(t, test_cases_input) == ... | [
{
"docstring": "This function takes a grid as input and returns the area of the largest rectangle\ncontaining only 0s.",
"function_declaration": "def maximal_rectangle(grid):",
"function_name": "maximal_rectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration"... | [
1,
1,
0,
1,
0,
0,
1,
1,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0] * m\n\n f... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016867",
"row_id": 16867,
"seed_ids": "[15]"
} | 0.61318 | Apps_16867 | I | [
"maximal_rectangle",
"largest_rectangles",
"process_input"
] | 3 | [
[
"largest_rectangles",
"maximal_rectangle"
],
[
"process_input",
"largest_rectangles"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | f663f4ed659c207ff5b56e67c42e0cca9957be13 | 75d761f018a03539d126ea581b5d310211897034 | |||
v1.0 | instruct | Apps | Apps_16890_I | You are given an array of N integers. You need to perform Q queries on the array. In each query,
- You are given two integers L and R. You need to determine how many distinct prime numbers are there in the subarray from index L to R inclusive.
Input:
- The first line contains two integers N and Q, the number of ele... | def generate_primes_up_to(n):
"""
Sieve of Eratosthenes to generate all primes up to n.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
return {num for num in range... | from solution import main
def test_sample_input():
assert main(
6,
3,
[2, 3, 4, 5, 6, 7],
[(1, 4), (2, 6), (1, 6)]
) == [3, 3, 4]
def test_all_non_primes():
assert main(
5,
2,
[4, 6, 8, 9, 10],
[(1, 3), (2, 5)]
) == [0, 0]
def test_all_p... | [
{
"docstring": "Sieve of Eratosthenes to generate all primes up to n.",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_distinct_primes(array, queries):",... | [
1,
0,
1,
1,
1,
0,
0,
1,
1
] | 6 | easy | 0.667 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_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 retu... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016890",
"row_id": 16890,
"seed_ids": "[1174]"
} | 0.601423 | Apps_16890 | I | [
"generate_primes_up_to",
"count_distinct_primes",
"main"
] | 3 | [
[
"count_distinct_primes",
"generate_primes_up_to"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 687526d3421a132cb0caf2d7a6e00e12dc059e4b | d2bba525d54b3c707192099350366cbc76e16fc7 | |||
v1.0 | instruct | Apps | Apps_16911_I | A mysterious island is inhabited by elves, who love to play games to test their mathematical prowess. One such game is called "Elf's Number Spiral".
The game involves constructing a square spiral of size $n × n$ filled with integers starting from 1 and spiraling outwards in a clockwise direction. The size $n$ is alway... | def generate_spiral_matrix(n):
spiral = [[0] * n for _ in range(n)]
x, y = n // 2, n // 2 # starting at the center of the matrix
spiral[x][y] = 1
number = 2
for layer in range(1, (n // 2) + 1):
y += 1 # move right to the first new cell in this layer
spiral[x][y] = number
n... | import pytest
from solution import elf_number_spiral
def test_case_1():
n, t = 5, 3
queries = [(1, 1), (2, 3), (5, 4)]
expected = [17, 4, 24]
assert elf_number_spiral(n, queries) == expected
def test_case_2():
n, t = 3, 4
queries = [(1, 3), (2, 2), (3, 1), (3, 3)]
expected = [3, 1, 7, 9]
... | [
{
"docstring": null,
"function_declaration": "def generate_spiral_matrix(n):",
"function_name": "generate_spiral_matrix",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def elf_number_spiral(n, queries):",
"function_name": "elf_number_spiral",
"parameter... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_spiral_matrix(n):\n matrix = [[0] * n for _ in range(n)]\n x = y = n // 2\n dx, dy = 0, -1\n counter = 1\n \n for i in range(n * n):\... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016911",
"row_id": 16911,
"seed_ids": "[2205]"
} | 0.617689 | Apps_16911 | I | [
"generate_spiral_matrix",
"elf_number_spiral"
] | 2 | [
[
"elf_number_spiral",
"generate_spiral_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3125334e79dce2437dcf2444dfceb83d8d5426f | 95b67f81e1dc23167b5a910a10838f76b4fced51 | |||
v1.0 | instruct | Apps | Apps_16937_I | Given a 2D matrix of size m x n, your task is to find the maximum sum of any rectangle within the matrix.
A rectangle in the matrix is defined by selecting two rows and two columns, and includes all the elements between and including the intersections of these rows and columns.
Example 1:
Input:
[
[1, 2, -1, -... | def maximum_sum_rectangle(matrix):
"""
Returns the maximum sum of any rectangle within the given 2D matrix.
"""
if not matrix or not matrix[0]:
return 0
m, n = len(matrix), len(matrix[0])
max_sum = float('-inf')
for left in range(n):
temp = [0] * m
for right in ... | from solution import maximum_sum_rectangle
def test_example1():
matrix = [
[1, 2, -1, -4, -20],
[-8, -3, 4, 2, 1],
[3, 8, 10, 1, 3],
[-4, -1, 1, 7, -6]
]
assert maximum_sum_rectangle(matrix) == 29
def test_example2():
matrix = [
[2, 1, -3, -4, 5],
[0, 6,... | [
{
"docstring": "Returns the maximum sum of any rectangle within the given 2D matrix.",
"function_declaration": "def maximum_sum_rectangle(matrix):",
"function_name": "maximum_sum_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum of any contig... | [
0,
1,
1,
1,
1,
1,
0,
0,
1,
0
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_rectangle(matrix):\n \"\"\"\n Given a 2D matrix, this function finds the maximum sum of any rectangle within the matrix.\n\n Parameters:\n m... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00016937",
"row_id": 16937,
"seed_ids": "[332]"
} | 0.744355 | Apps_16937 | I | [
"maximum_sum_rectangle",
"kadane"
] | 2 | [
[
"maximum_sum_rectangle",
"kadane"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 711e0fd53c0455e678e50a5787fe397b27aba461 | 0ba3bfea5d24bb9b39a852b807643f13d6b9e0eb | |||
v1.0 | instruct | Apps | Apps_16942_I | In a forest, there are several trees positioned in a 2D plane. Each tree is represented by its coordinates $(x, y)$ on the plane. You need to cut down some trees such that the remaining trees form the vertices of the convex hull enclosing the maximum possible area in the forest. The convex hull of a set of points is th... | from typing import List, Tuple
# Utility function to compute cross product of two vectors OA and OB
# A positive cross product indicates a counter-clockwise direction, whereas
# a negative cross product indicates a clockwise direction.
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0... | def test_cross_product():
# Test cases to ensure cross product function works properly.
assert cross((0, 0), (1, 1), (2, 2)) == 0
assert cross((0, 0), (1, 1), (1, 0)) == -1
assert cross((0, 0), (1, 1), (0, 1)) == 1
def test_convex_hull():
# Example test case 1
points1 = [(0, 0), (10, 0), (10, 1... | [
{
"docstring": null,
"function_declaration": "def cross(o, a, b):",
"function_name": "cross",
"parameter_list": "(o, a, b)"
},
{
"docstring": "Returns the points that form the convex hull using Andrew's monotone chain algorithm.\nThe returned list is in counter-clockwise order starting with ... | [
1,
0,
0,
0,
0,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Tuple\n\n# Utility function to compute cross product of two vectors OA and OB\n# A positive cross product indicates a counter-clockwise dir... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016942",
"row_id": 16942,
"seed_ids": "[740]"
} | 0.627498 | Apps_16942 | I | [
"cross",
"convex_hull",
"trees_in_convex_hull",
"solve"
] | 4 | [
[
"convex_hull",
"cross"
],
[
"solve",
"trees_in_convex_hull"
],
[
"trees_in_convex_hull",
"convex_hull"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | d43674e8a50d4c353f324476cc5fcb5d3d99effb | 90586ce4f5bd9366b7e8c5d973520033fcef49d6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.