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_8992_I | Implement a function `find_next_happy_number(n)` that finds the next "happy number" greater than `n`.
A "happy number" is defined by the following process:
- Starting with any positive integer, replace the number by the sum of the squares of its digits.
- Repeat the process until the number equals 1 (where it will s... | def is_happy_number(num):
seen = set()
while num != 1 and num not in seen:
seen.add(num)
num = sum(int(digit) ** 2 for digit in str(num))
return num == 1
def find_next_happy_number(n):
n += 1
while not is_happy_number(n):
n += 1
return n | from solution import find_next_happy_number, is_happy_number
def test_is_happy_number():
assert is_happy_number(19) == True
assert is_happy_number(1) == True
assert is_happy_number(7) == True
assert is_happy_number(2) == False
assert is_happy_number(4) == False
def test_find_next_happy_number():
... | [
{
"docstring": null,
"function_declaration": "def is_happy_number(num):",
"function_name": "is_happy_number",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_next_happy_number(n):",
"function_name": "find_next_happy_number",
"parameter_list": "... | [
1,
1,
1,
0,
0,
0,
1,
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_happy_number(num):\n \"\"\"\n Helper function to determine if a number is a happy number.\n \"\"\"\n seen = set()\n while num != 1 and num not... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00008992",
"row_id": 8992,
"seed_ids": "[3710]"
} | 0.568809 | Apps_8992 | I | [
"is_happy_number",
"find_next_happy_number"
] | 2 | [
[
"find_next_happy_number",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 90ae1149e24e02985d302208501793f6b6be5968 | 2bf6c4d4e1e8c848b1c064bd89d7a892a0bf4f47 | |||
v1.0 | instruct | Apps | Apps_8994_I | Complete the function that takes a list of integers and returns a new list containing only the elements that are prime numbers.
## Example
```python
[3, 4, 7, 10, 11] # should return [3, 7, 11]
``` | def is_prime(n):
"""
Helper function to 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_primes(lst):
"""
Returns a new list containing only the elements of lst that... | from solution import filter_primes
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
def test_filter_primes_no_primes():
assert filter_primes([1, 4, 6, 8, 9, 10, 12, 14]) == []
def test_filter_primes_mixed()... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the elements of lst that are prime numbers.",
"function_declaration": "d... | [
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 a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00008994",
"row_id": 8994,
"seed_ids": "[4728]"
} | 0.710328 | Apps_8994 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eae6c9e806cd4795f9d33d5007e9f528a6709fd8 | 5f68ec4f1e33f604565f80e8b14628286b91fb63 | |||
v1.0 | instruct | Apps | Apps_9096_I | You are given an array of $n$ integers. We define the beauty of an array as the length of the longest contiguous subarray that forms a palindrome. A contiguous subarray is a sequence of consecutive elements within the array.
Your task is to find the beauty of the given array.
A subarray is considered a palindrome if... | def is_palindrome(subarray):
"""
Helper function to check if a subarray is a palindrome.
"""
return subarray == subarray[::-1]
def beauty_of_array(arr):
"""
Function to find the beauty of the given array.
The beauty is defined as the length of the longest contiguous subarray that forms a pa... | from solution import beauty_of_array, process_test_cases
def test_is_palindrome():
# local helper for tests
from solution import is_palindrome
assert is_palindrome([1, 2, 2, 1]) == True
assert is_palindrome([1, 2, 3, 2, 1]) == True
assert is_palindrome([1, 2, 3]) == False
assert is_palindrome([... | [
{
"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": "Function to find the beauty of the given array.\nThe beauty is defined as the ... | [
0,
1,
1,
0,
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 longest_palindrome_subarray(arr):\n \"\"\"\n Returns the length of the longest contiguous subarray that forms a palindrome.\n \"\"\"\n n = len(arr)\... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00009096",
"row_id": 9096,
"seed_ids": "[82]"
} | 0.73012 | Apps_9096 | I | [
"is_palindrome",
"beauty_of_array",
"process_test_cases"
] | 3 | [
[
"beauty_of_array",
"is_palindrome"
],
[
"process_test_cases",
"beauty_of_array"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | e4f984cb524ffa1e1e1b2f011508d5f73fff62a8 | a487a359dd78947e4a6ea5ced34112931680cc67 | |||
v1.0 | instruct | Apps | Apps_9115_I | ___
# Task
**_Given_** a *list of integers*, **_return_** a *list of booleans* indicating whether each integer is a prime number.
___
# Notes
* The list of integers can contain both positive and negative numbers.
* Negative numbers and zero are considered not prime.
* The function should return a list of the same ... | 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 isPrime
def test_is_prime_positive_numbers():
assert isPrime([3, 5, 8, 13, 15]) == [True, True, False, True, False]
def test_is_prime_negative_and_zero():
assert isPrime([-3, 0, 1, -7, 2]) == [False, False, False, False, True]
def test_is_prime_mixed_numbers():
assert isPrime([17, 19... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Given a list of integers, returns a list of booleans indicating \nwhether each integer is a prime numbe... | [
1,
1,
1,
1,
1,
1,
0,
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(n):\n \"\"\"\n Helper function to determine if a number is prime.\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009115",
"row_id": 9115,
"seed_ids": "[3759]"
} | 0.736716 | Apps_9115 | I | [
"is_prime",
"isPrime"
] | 2 | [
[
"isPrime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f82c867291f806ce5e6560831d83c382cffcd9bf | 4353296167dbaa2981b1d5a32e9998f956cc9224 | |||
v1.0 | instruct | Apps | Apps_9136_I | You are given a number of books, each with a certain number of pages. You want to assign these books to exactly $k$ students so that each student gets a contiguous sequence of books. The goal is to minimize the maximum number of pages assigned to a student.
-----Input-----
The first line contains an integer $t$ ($1 \... | def is_possible(books, n, k, max_pages):
students_required = 1
current_pages = 0
for pages in books:
if current_pages + pages > max_pages:
students_required += 1
current_pages = pages
if students_required > k:
return False
else:
... | from solution import book_allocation
def test_case_1():
test_cases = [{'n': 4, 'k': 2, 'books': [12, 34, 67, 90]}]
assert book_allocation(test_cases) == [113]
def test_case_2():
test_cases = [{'n': 3, 'k': 1, 'books': [15, 20, 25]}]
assert book_allocation(test_cases) == [60]
def test_case_3():
te... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_maximum_pages(books, n, k):",
"function_name": "find... | [
1,
1,
0,
1,
1,
0,
0,
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": "def is_valid_distribution(pages, n, k, max_pages):\n students_required = 1\n current_pages_sum = 0\n\n for i in range(n):\n if pages[i] > max_pages:... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00009136",
"row_id": 9136,
"seed_ids": "[118]"
} | 0.760854 | Apps_9136 | I | [
"is_possible",
"find_minimum_maximum_pages",
"book_allocation"
] | 3 | [
[
"book_allocation",
"find_minimum_maximum_pages"
],
[
"find_minimum_maximum_pages",
"is_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | be2a0293e15c142bee3d6b29c6347e1cb9b2dd96 | 6c6f8e89bf6e77cea9e7194b934d9d3bed1fc5d9 | |||
v1.0 | instruct | Apps | Apps_9196_I | Given a list of integers, the code provided is supposed to return a new list containing only the prime numbers from the original list.
However, the code is not producing the correct output.
# Task
Fix the bug so that the function correctly returns a list of prime numbers.
# Notes
A prime number is a number greater... | def is_prime(num):
"""
Returns True if the number is prime, otherwise False.
"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(numbers):
"""
Returns a list containing only the pri... | 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(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
def test_filter_primes():
... | [
{
"docstring": "Returns True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list containing only the prime numbers from the original list.",
"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 Determine if the given integer n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009196",
"row_id": 9196,
"seed_ids": "[4565]"
} | 0.648219 | Apps_9196 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4aa33a2640bbeb33d998428f9d7a1378c9317c9 | 2d371b9c215902c97c5b7313c5f4007f7c3fa917 | |||
v1.0 | instruct | Apps | Apps_9215_I | You are given a list of strings words containing lowercase English alphabets. A permutation of the list is considered special if every adjacent pair of words in the permutation differ by exactly one character. Two words differ by exactly one character if the length of both words is the same and there is exactly one pos... | from itertools import permutations
def differs_by_one_char(w1, w2):
"""
Helper function to determine if two words differ by exactly one character.
"""
if len(w1) != len(w2):
return False
count = 0
for c1, c2 in zip(w1, w2):
if c1 != c2:
count += 1
if coun... | def test_example_1():
words = ["abc", "acc", "bcc"]
assert special_permutation_exists(words) == True
def test_example_2():
words = ["abc", "def"]
assert special_permutation_exists(words) == False
def test_example_3():
words = ["abc", "abe", "aec"]
assert special_permutation_exists(words) == Tr... | [
{
"docstring": "Helper function to determine if two words differ by exactly one character.",
"function_declaration": "def differs_by_one_char(w1, w2):",
"function_name": "differs_by_one_char",
"parameter_list": "(w1, w2)"
},
{
"docstring": "Determines if there exists a permutation of words w... | [
0,
0,
0,
1,
0,
1,
0,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef differ_by_one_char(word1, word2):\n \"\"\"\n Returns True if the two words differ by exactly one character, else Fal... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009215",
"row_id": 9215,
"seed_ids": "[2467]"
} | 0.795034 | Apps_9215 | I | [
"differs_by_one_char",
"special_permutation_exists"
] | 2 | [
[
"special_permutation_exists",
"differs_by_one_char"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 581b737681eaeaea4ba116514bdd1c346b74cdf1 | 8dfc3843182e92c10390166e371b8c56a58cf167 | |||
v1.0 | instruct | Apps | Apps_9265_I | Alex is planning to host a coding marathon and needs to set up a leaderboard. The leaderboard should rank participants based on their scores in descending order. In case two participants have the same score, they should be ranked based on their names in ascending alphabetical order. Alex has tasked you with writing a p... | def generate_leaderboard(test_cases):
results = []
for case_no, (num_participants, participants) in enumerate(test_cases, 1):
sorted_participants = sorted(participants, key=lambda x: (-x[1], x[0]))
results.append(f"Case #{case_no}:")
for name, score in sorted_participants:
r... | def test_case_single_participant():
input_data = "1\n1\nAlice 100"
expected_output = ["Case #1:", "Alice 100"]
assert coding_marathon_leaderboard(input_data) == expected_output
def test_case_multiple_participants_same_score():
input_data = "1\n3\nAlice 100\nBob 100\nCharlie 100"
expected_output = [... | [
{
"docstring": null,
"function_declaration": "def generate_leaderboard(test_cases):",
"function_name": "generate_leaderboard",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"paramet... | [
1,
0,
1,
0,
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": "def leaderboard(test_cases):\n \"\"\"\n Process multiple test cases and return ranked leaderboard of participants.\n Each leader board is sorted by score i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009265",
"row_id": 9265,
"seed_ids": "[686]"
} | 0.759219 | Apps_9265 | I | [
"generate_leaderboard",
"parse_input",
"coding_marathon_leaderboard"
] | 3 | [
[
"coding_marathon_leaderboard",
"generate_leaderboard"
],
[
"coding_marathon_leaderboard",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 125ee307104ba7b81bf2c8047c489655e74d70fa | 2ce021db74ec794faa7e6b35a4d48626ebdf2c88 | |||
v1.0 | instruct | Apps | Apps_9288_I | Write a function getLongestPalindrome that will return the longest palindromic substring in a given string. A palindrome is a word that reads the same backward as forward.
E.g 1: For s = "babad" the result should be "bab" or "aba" (both are valid)
E.g 2: For s = "cbbd" the result should be "bb"
E.g 3: For s = "abcdef"... | def getLongestPalindrome(s):
"""
Returns the longest palindromic substring in the given string s.
"""
n = len(s)
if n == 0:
return ""
longest = s[0]
for i in range(n):
# Check for odd-length palindromes
odd_palindrome = expandFromCenter(s, i, i)
if len(odd_p... | from solution import getLongestPalindrome
def test_getLongestPalindrome():
assert getLongestPalindrome("babad") in ["bab", "aba"]
assert getLongestPalindrome("cbbd") == "bb"
assert getLongestPalindrome("abcdef") == "a"
assert getLongestPalindrome("") == ""
assert getLongestPalindrome("a") == "a"
... | [
{
"docstring": "Returns the longest palindromic substring in the given string s.",
"function_declaration": "def getLongestPalindrome(s):",
"function_name": "getLongestPalindrome",
"parameter_list": "(s)"
},
{
"docstring": "Expands around the center and returns the longest palindromic substri... | [
1,
1,
1,
1,
0,
1,
1,
0,
1,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def getLongestPalindrome(s):\n \"\"\"\n Returns the longest palindromic substring in a given string s.\n \"\"\"\n if not s:\n return \"\"\n\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00009288",
"row_id": 9288,
"seed_ids": "[4861]"
} | 0.827803 | Apps_9288 | I | [
"getLongestPalindrome",
"expandFromCenter"
] | 2 | [
[
"getLongestPalindrome",
"expandFromCenter"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6ecdce765957f326612321a43c45b660d5dc8419 | 715cba050c73f9a2b134b337be23ca99333f2e5c | |||
v1.0 | instruct | Apps | Apps_9424_I | A group of friends is planning a hiking trip and they need to distribute their supplies evenly among themselves. They have a list of supplies of different weights, and they want to minimize the maximum load any one friend has to carry.
-----Input:-----
- First line will contain $T$, the number of test cases. Then the... | def can_distribute(weights, F, max_load):
current_load = 0
friends_used = 1
for weight in weights:
if current_load + weight > max_load:
friends_used += 1
current_load = weight
if friends_used > F:
return False
else:
current_loa... | from solution import minimize_maximum_load, process_input
def test_minimize_maximum_load():
input_data = """2
3
5
1 2 3 4 5
2
5
1 2 3 4 5"""
T, test_cases = process_input(input_data)
results = minimize_maximum_load(T, test_cases)
assert results == [6, 9]
def test_single_friend():
input_data = """1... | [
{
"docstring": null,
"function_declaration": "def can_distribute(weights, F, max_load):",
"function_name": "can_distribute",
"parameter_list": "(weights, F, max_load)"
},
{
"docstring": null,
"function_declaration": "def minimize_maximum_load(T, test_cases):",
"function_name": "minim... | [
1,
1,
1,
1,
1,
1,
0,
0,
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 min_max_load(T, test_cases):\n def canDistribute(weights, friends, max_load):\n current_load = 0\n used_friends = 1\n\n for weight in we... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00009424",
"row_id": 9424,
"seed_ids": "[1324]"
} | 0.707816 | Apps_9424 | I | [
"can_distribute",
"minimize_maximum_load",
"process_input"
] | 3 | [
[
"minimize_maximum_load",
"can_distribute"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | eb144677e186b61dcd7382a0e0685c0cc40e8ac0 | badca1278f9ba059355df1a6be00539f8cb9f0f0 | |||
v1.0 | instruct | Apps | Apps_9434_I | Write a function that accepts a list of integers and returns a list of tuples, each containing two elements: the integer and its number of divisors. The returned list should be sorted by the number of divisors in ascending order. If two integers have the same number of divisors, sort those integers in ascending numeric... | def count_divisors(n):
"""
Returns the number of divisors of n.
"""
if n == 1:
return 1
count = 0
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
count += 1
if i != n // i:
count += 1
return count
def sort_by_divisors(lst):
""... | def test_count_divisors():
assert count_divisors(1) == 1
assert count_divisors(6) == 4
assert count_divisors(14) == 4
assert count_divisors(12) == 6
assert count_divisors(25) == 3
def test_sort_by_divisors():
assert sort_by_divisors([6, 1, 14, 12]) == [(1, 1), (6, 4), (14, 4), (12, 6)]
asse... | [
{
"docstring": "Returns the number of divisors of n.",
"function_declaration": "def count_divisors(n):",
"function_name": "count_divisors",
"parameter_list": "(n)"
},
{
"docstring": "Accepts a list of integers and returns a list of tuples,\neach containing the integer and its number of divis... | [
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": "def count_divisors(n):\n \"\"\"\n Returns the count of divisors of a given integer n.\n \"\"\"\n if n == 0:\n return 0\n divisors_count = 0\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00009434",
"row_id": 9434,
"seed_ids": "[3230]"
} | 0.711375 | Apps_9434 | I | [
"count_divisors",
"sort_by_divisors"
] | 2 | [
[
"sort_by_divisors",
"count_divisors"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | af43ae4135ff1d1471a69f186d0d6303fcb598f8 | af859c5359d251dbd170c11fa5284c566dbdd99e | |||
v1.0 | instruct | Apps | Apps_9447_I | You are given an array representing the in-order traversal of a Binary Search Tree (BST). Your task is to reconstruct the original BST and then output the pre-order traversal of the reconstructed tree.
For example:
```
in_order = [2, 3, 5, 6, 7, 8, 10]
```
Your function `reconstruct_bst()` will take the in-order array... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def sorted_array_to_bst(arr):
if not arr:
return None
# Find the middle index
mid = len(arr) // 2
# Make the middle element the root
root = TreeNode(arr[mid])
# Recu... | from solution import reconstruct_bst
def test_reconstruct_bst_example():
in_order = [2, 3, 5, 6, 7, 8, 10]
expected_pre_order = [6, 3, 2, 5, 8, 7, 10]
assert reconstruct_bst(in_order) == expected_pre_order
def test_reconstruct_bst_single_element():
in_order = [7]
expected_pre_order = [7]
asser... | [] | [
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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef reconstruct_bst(in_order):\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00009447",
"row_id": 9447,
"seed_ids": "[4052]"
} | 0.515447 | Apps_9447 | I | [
"sorted_array_to_bst",
"pre_order_traversal",
"reconstruct_bst"
] | 3 | [
[
"reconstruct_bst",
"pre_order_traversal"
],
[
"reconstruct_bst",
"sorted_array_to_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | a33377a9261726155c4854107de514d374dd91c9 | 99a1c3e5b4dc4960f5980dbb17cc3b9db220e68b | |||
v1.0 | instruct | Apps | Apps_9453_I | You are given a list of integers where each integer represents the number of steps a person has climbed. For each number, you need to determine if it represents the last step of a valid staircase. A valid staircase is formed if and only if the number of steps climbed follows a triangular number sequence. A triangular n... | import math
def is_triangular_number(num):
if num <= 0:
return False
n = (-1 + math.sqrt(1 + 8 * num)) / 2
return n.is_integer()
def check_staircase_numbers(numbers):
return [is_triangular_number(num) for num in numbers] | from solution import check_staircase_numbers
def test_check_staircase_numbers_all_true():
assert check_staircase_numbers([1, 3, 6, 10, 15]) == [True, True, True, True, True]
def test_check_staircase_numbers_all_false():
assert check_staircase_numbers([4, 7, 9, 13, 16]) == [False, False, False, False, False]
... | [
{
"docstring": null,
"function_declaration": "def is_triangular_number(num):",
"function_name": "is_triangular_number",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def check_staircase_numbers(numbers):",
"function_name": "check_staircase_numbers",
"... | [
0,
1,
1,
0,
1,
0,
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": "def is_triangular_number(n):\n \"\"\"\n Checks if a given number n is a triangular number.\n \n A number n is triangular if and only if there exists a p... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00009453",
"row_id": 9453,
"seed_ids": "[2550]"
} | 0.612261 | Apps_9453 | I | [
"is_triangular_number",
"check_staircase_numbers"
] | 2 | [
[
"check_staircase_numbers",
"is_triangular_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4674cb6bbf97c2ba4a36d05071c4c6b98404b036 | 689cfe4319a8156c60e2ad9a9b76c64e3fb0dd16 | |||
v1.0 | instruct | Apps | Apps_9657_I | Write a function that takes in a list of integers and returns a list containing all the integers that are prime.
For example:
Input: [10, 15, 3, 7, 19]
Output: [3, 7, 19]
Note: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is a prime number
if n % 2 == 0:
return False # All other even numbers are not primes
for i in range(3, int(n**0.5) + 1, 2):
if n % i =... | from solution import get_prime_numbers
def test_all_prime_numbers():
assert get_prime_numbers([2, 3, 5, 7, 11, 13, 17, 19, 23]) == [2, 3, 5, 7, 11, 13, 17, 19, 23]
def test_no_prime_numbers():
assert get_prime_numbers([4, 6, 8, 10, 12]) == []
def test_mixed_prime_and_non_prime_numbers():
assert get_prime... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing all prime numbers from the input list.",
"function_declaration": "def get_prime_n... | [
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 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_8 | {
"original_instruction": "",
"prompt_id": "00009657",
"row_id": 9657,
"seed_ids": "[4310]"
} | 0.695519 | Apps_9657 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af53f2bfe584f5049f3e872cf9aa1f17bbb4c711 | 47435d40df2224827c3b5b9b494743f5350597a1 | |||
v1.0 | instruct | Apps | Apps_9677_I | An online bookstore keeps track of their inventory and sales using a specialized inventory management system. Each book is represented by a unique International Standard Book Number (ISBN), and its availability is represented by a positive integer indicating the number of copies in stock. The bookstore wants to run a p... | def get_top_k_books(test_cases):
results = []
for case in test_cases:
N, K, books = case
sorted_books = sorted(books, key=lambda x: (-x[1], x[0]))
results.extend(sorted_books[:K])
results.append(None) # Marker for end of test case
return results
def parse_input(input_data):... | from solution import process_bookstore_promotions
def test_single_case():
input_data = "1\n5 3\n9780321150793 7\n9780131103627 4\n9780201633610 12\n9780131101630 8\n9780201485677 10"
expected_output = "9780201633610 12\n9780201485677 10\n9780131101630 8"
assert process_bookstore_promotions(input_data) == e... | [
{
"docstring": null,
"function_declaration": "def get_top_k_books(test_cases):",
"function_name": "get_top_k_books",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"parameter_list": ... | [
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 most_available_books(test_cases):\n results = []\n for test_case in test_cases:\n N, K, books = test_case\n sorted_books = sorted(books, key... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009677",
"row_id": 9677,
"seed_ids": "[571]"
} | 0.700877 | Apps_9677 | I | [
"get_top_k_books",
"parse_input",
"format_output",
"process_bookstore_promotions"
] | 4 | [
[
"process_bookstore_promotions",
"format_output"
],
[
"process_bookstore_promotions",
"get_top_k_books"
],
[
"process_bookstore_promotions",
"parse_input"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 67a20388b03bb54bc9047a400246ace86d796c15 | 09a3db6ed1518b3f036964f40c2ea2087ad262ff | |||
v1.0 | instruct | Apps | Apps_9685_I | Write a function that takes a list of integers and returns the list sorted in ascending order based on the sum of their digits. If two numbers have the same sum of digits, they should be ordered by their original value.
Preserve spacing before/after characters if present.
## Examples
```
[34, 23, 12, 45] => [12, 23,... | def sum_of_digits(n):
"""
Returns the sum of digits of the number n.
"""
return sum(int(digit) for digit in str(n))
def sort_by_digit_sum(lst):
"""
Sorts the list of integers based on the sum of their digits.
If two numbers have the same sum of digits, they are ordered by their original val... | from solution import sum_of_digits, sort_by_digit_sum
def test_sum_of_digits():
assert sum_of_digits(34) == 7
assert sum_of_digits(23) == 5
assert sum_of_digits(12) == 3
assert sum_of_digits(45) == 9
assert sum_of_digits(222) == 6
assert sum_of_digits(131) == 5
def test_sort_by_digit_sum():
... | [
{
"docstring": "Returns the sum of digits of the number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Sorts the list of integers based on the sum of their digits.\nIf two numbers have the same sum of digits,... | [
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 sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of the number n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef sort_by_digit_s... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00009685",
"row_id": 9685,
"seed_ids": "[4363]"
} | 0.754548 | Apps_9685 | I | [
"sum_of_digits",
"sort_by_digit_sum"
] | 2 | [
[
"sort_by_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c1830a642f24d97f1180273564a65b65810e8a7 | 5d3f1fcab42b5be2fdbb63bc9c3e131064720cb9 | |||
v1.0 | instruct | Apps | Apps_9785_I | Both Alice and Bob are passionate about number theory and enjoy playing games that involve numbers. Recently, they started playing a new game involving prime numbers and lists of integers.
In the game, they are given a list of n integers. Alice and Bob take turns, starting with Alice, to choose any integer from the li... | def sieve_eratosthenes(max_number):
"""
Returns a list of primes less than or equal to max_number
using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (max_number + 1)
p = 2
while (p * p <= max_number):
if is_prime[p]:
for i in range(p * p, max_number + 1, p... | from solution import game_final_product
def test_example_1():
assert game_final_product(3, [4, 6, 8]) == 385 % (10**9 + 7)
def test_example_2():
assert game_final_product(2, [10, 5]) == 77 % (10**9 + 7)
def test_example_3():
assert game_final_product(1, [2]) == 3 % (10**9 + 7)
def test_large_numbers():
... | [
{
"docstring": "Returns a list of primes less than or equal to max_number\nusing the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_eratosthenes(max_number):",
"function_name": "sieve_eratosthenes",
"parameter_list": "(max_number)"
},
{
"docstring": "Finds the smallest... | [
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": "from sympy import nextprime\n\ndef optimal_game_product(n, a):\n \"\"\"\n Given a list of integers, return the final product of all numbers in the\n list a... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00009785",
"row_id": 9785,
"seed_ids": "[2182]"
} | 0.717094 | Apps_9785 | I | [
"sieve_eratosthenes",
"find_next_prime",
"game_final_product"
] | 3 | [
[
"game_final_product",
"find_next_prime"
],
[
"game_final_product",
"sieve_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0d45adb52b2b5c241d0f9a374d1f9b2ebb79b772 | c380f5fe2c2b3a9d2a0f88bec40a73627cdbc014 | |||
v1.0 | instruct | Apps | Apps_9842_I | There are N cities connected by M one-way roads. Each city is numbered from 1 to N and each road connects two cities and has a certain travel cost associated with it. Additionally, each city has a happiness value associated with it which you gain by visiting that city.
You start at city 1 and want to travel to city N,... | import heapq
def max_happiness(N, M, happiness, roads):
graph = [[] for _ in range(N+1)]
for u, v, cost in roads:
graph[u].append((v, cost))
distance = [float('-inf')] * (N+1)
distance[1] = happiness[0]
pq = [(-happiness[0], 1)]
while pq:
current_happiness, u = heapq.h... | from solution import find_max_happiness
def test_sample():
N = 4
M = 4
happiness = [3, 2, 5, 10]
roads = [(1, 2, 2), (2, 3, 2), (3, 4, 2), (1, 4, 7)]
assert find_max_happiness(N, M, happiness, roads) == 14
def test_single_road():
N = 2
M = 1
happiness = [1, 1000]
roads = [(1, 2, 1)... | [
{
"docstring": null,
"function_declaration": "def max_happiness(N, M, happiness, roads):",
"function_name": "max_happiness",
"parameter_list": "(N, M, happiness, roads)"
},
{
"docstring": null,
"function_declaration": "def find_max_happiness(N, M, happiness, roads):",
"function_name"... | [
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": "import heapq\n\ndef max_happiness(N, M, happiness, roads):\n graph = [[] for _ in range(N + 1)]\n for u, v, cost in roads:\n graph[u].append((v, cost))... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00009842",
"row_id": 9842,
"seed_ids": "[2323]"
} | 0.737014 | Apps_9842 | I | [
"max_happiness",
"find_max_happiness"
] | 2 | [
[
"find_max_happiness",
"max_happiness"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 10f8ccbe008c548fde067c4b04d127e04d6c1481 | 0bc90772b82d814679f4e0545399f9b574dd01cd | |||
v1.0 | instruct | Apps | Apps_9844_I | Emma works as a data analyst and frequently deals with large datasets. She comes across a problem where she needs to analyze a sequence of integers and determine whether it contains an increasing subsequence of length $K$. An increasing subsequence is a sequence of integers where each element is larger than the previou... | def increasing_subsequence_exists(T, test_cases):
results = []
for t in range(T):
N, K = test_cases[t][0]
sequence = test_cases[t][1]
if find_increasing_subseq_of_length_k(sequence, K):
results.append("YES")
else:
results.append("NO")
ret... | from solution import increasing_subsequence_exists
def test_sample_cases():
assert increasing_subsequence_exists(2, [((5, 3), [1, 2, 3, 4, 5]), ((5, 6), [1, 2, 3, 4, 5])]) == ["YES", "NO"]
def test_case_subsequence_of_length_1():
assert increasing_subsequence_exists(1, [((4, 1), [1, 7, 3, 4])]) == ["YES"]
de... | [
{
"docstring": null,
"function_declaration": "def increasing_subsequence_exists(T, test_cases):",
"function_name": "increasing_subsequence_exists",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def find_increasing_subseq_of_length_k(sequence, K):",
... | [
1,
1,
0,
1,
0,
0,
1,
0,
1,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def increasing_subsequence_exists(test_cases):\n results = []\n for case in test_cases:\n N, K = case[0], case[1]\n sequence = case[2]\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00009844",
"row_id": 9844,
"seed_ids": "[625]"
} | 0.708171 | Apps_9844 | I | [
"increasing_subsequence_exists",
"find_increasing_subseq_of_length_k",
"binary_search_lis_position"
] | 3 | [
[
"find_increasing_subseq_of_length_k",
"binary_search_lis_position"
],
[
"increasing_subsequence_exists",
"find_increasing_subseq_of_length_k"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 83e8a4e9481642fc42d4330ca422b144bf06c48f | 4eddcba2e80c421813381ac5519af8a4904fc9c2 | |||
v1.0 | instruct | Apps | Apps_9845_I | In a linked list, each node contains two fields: an integer value and a reference to the next node in the sequence. Write a function to check if a given linked list contains a cycle. A linked list has a cycle if a node's reference links back to a previous node in the list, creating a loop.
----Input----
The input wil... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def has_cycle(head):
"""
Checks if the linked list has a cycle.
:param head: The head of the linked list.
:return: True if there is a cycle, otherwise False.
"""
if not head:
return... | from solution import detect_cycle_in_list, build_linked_list, has_cycle
def test_no_cycle():
values = [1, 2, 3]
next_indices = [1, 2, -1]
head = build_linked_list(values, next_indices)
assert not has_cycle(head)
def test_one_cycle():
values = [1, 2, 3, 4]
next_indices = [1, 2, 3, 1]
head =... | [] | [
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": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef has_cycle(head):\n slow, fast = head, h... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009845",
"row_id": 9845,
"seed_ids": "[2172]"
} | 0.598058 | Apps_9845 | I | [
"has_cycle",
"build_linked_list",
"detect_cycle_in_list"
] | 3 | [
[
"detect_cycle_in_list",
"build_linked_list"
],
[
"detect_cycle_in_list",
"has_cycle"
]
] | 2 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | f8f9f2837fc72d6dfcfc2f40b437d0ed576cf9b7 | f9187dd19deb0f29f0437a13f127a79bfa28c71c | |||
v1.0 | instruct | Apps | Apps_9851_I | In a remote village, they have devised a new coding system for communication. Each letter of the alphabet is assigned a unique prime number starting from the smallest prime number (i.e., 'a' is assigned 2, 'b' is assigned 3, 'c' is assigned 5, and so on up to 'z' which is assigned the 26th prime number 101). To create ... | def get_primes_up_to(n):
primes = []
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
for start in range(2, n + 1):
if sieve[start]:
primes.append(start)
for multiple in range(start * start, n + 1, start):
sieve[multiple] = False
return p... | from solution import can_form_query_string
def test_case_1():
T = 1
test_cases = [
(3, ["a", "aa", "aaa"], "aaaa")
]
assert can_form_query_string(T, test_cases) == ["YES"]
def test_case_2():
T = 1
test_cases = [
(3, ["a", "b", "c"], "abc")
]
assert can_form_query_string... | [
{
"docstring": null,
"function_declaration": "def get_primes_up_to(n):",
"function_name": "get_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_prime_map():",
"function_name": "get_prime_map",
"parameter_list": "()"
},
{
"doc... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_prime_mapping():\n \"\"\"\n Returns a dictionary mapping each letter to a unique prime number starting from 2.\n \"\"\"\n import sympy\n prim... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009851",
"row_id": 9851,
"seed_ids": "[1129]"
} | 0.613471 | Apps_9851 | I | [
"get_primes_up_to",
"get_prime_map",
"get_string_product",
"can_form_query_string"
] | 4 | [
[
"can_form_query_string",
"get_prime_map"
],
[
"can_form_query_string",
"get_string_product"
],
[
"get_prime_map",
"get_primes_up_to"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5a3d17cb5c65a86b3e185eee9af2339bdf112be9 | 8a4fdcd0f0f18885e2c8e7f1a2ecd2292b0900e7 | |||
v1.0 | instruct | Apps | Apps_9960_I | Chef is very fond of symmetry. He considers a string symmetric if it reads the same backward as forward. Chef has a new task: given a collection of strings, he wants you to determine which ones are symmetric.
-----Input-----
- The first line contains an integer $N$ denoting the number of strings.
- Each of the next $N... | def is_symmetric_string(s):
"""
Checks if a string is symmetric (palindrome).
:param s: A string to be checked
:return: "Symmetric" if the string is a palindrome, otherwise "Not Symmetric"
"""
return "Symmetric" if s == s[::-1] else "Not Symmetric"
def check_symmetric_strings(strings):
"""... | from solution import is_symmetric_string, check_symmetric_strings
def test_is_symmetric_string():
assert is_symmetric_string("level") == "Symmetric"
assert is_symmetric_string("hello") == "Not Symmetric"
assert is_symmetric_string("deified") == "Symmetric"
assert is_symmetric_string("a") == "Symmetric"... | [
{
"docstring": "Checks if a string is symmetric (palindrome).\n\n:param s: A string to be checked\n:return: \"Symmetric\" if the string is a palindrome, otherwise \"Not Symmetric\"",
"function_declaration": "def is_symmetric_string(s):",
"function_name": "is_symmetric_string",
"parameter_list": "(s)... | [
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_symmetric_string(s):\n \"\"\"\n Determines if a string is symmetric (palindromic).\n Args:\n s (str): The input string.\n \n Returns:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009960",
"row_id": 9960,
"seed_ids": "[1551]"
} | 0.613041 | Apps_9960 | I | [
"is_symmetric_string",
"check_symmetric_strings"
] | 2 | [
[
"check_symmetric_strings",
"is_symmetric_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f682837a0934214f7410ea9c41217a274338f06d | 04960d3914afdc1bf46c7481f53eb6f7319fe6be | |||
v1.0 | instruct | Apps | Apps_9978_I | =====Function Descriptions=====
Sorting Algorithms
Sorting algorithms are techniques to arrange data in a particular order. These algorithms can be used to sort data in ascending or descending order.
Examples:
Bubble Sort
Bubble sort is an algorithm that repeatedly steps through the list, compares adjacent elements an... | def merge_sort(arr):
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
right_half = merge_sort(arr[mid:])
return merge(left_half, right_half)
def merge(left, ri... | from solution import merge_sort, sort_integers
def test_merge_sort():
assert merge_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9]
assert merge_sort([3, 1, 4, 1, 5]) == [1, 1, 3, 4, 5]
assert merge_sort([]) == []
assert merge_sort([7]) == [7]
assert merge_sort([4, 2, 7, 1]) == [1, 2, 4, 7]
asser... | [
{
"docstring": "Sorts a list of integers in ascending order using the merge sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"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 merge_sort(arr):\n \"\"\"\n Sorts a list in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00009978",
"row_id": 9978,
"seed_ids": "[2589]"
} | 0.695557 | Apps_9978 | I | [
"merge_sort",
"merge",
"sort_integers"
] | 3 | [
[
"merge_sort",
"merge"
],
[
"sort_integers",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9266b360e51600dce84ce0dfe61e54c6c65cd678 | 4e34f6b3e24afb4d26be04a743bf769dffc4e897 | |||
v1.0 | instruct | Apps | Apps_10006_I | Create a function that receives an integer `n` and returns a list of prime numbers up to `n` (inclusive). A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
## Example
```python
7 # should return [2, 3, 5, 7]
``` | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def primes_up_to(n):
"""
Returns a list of prime numbers up to n (inclusive)
"""
return [x for x in range(2, n + 1) if is_prime(x)] | from solution import is_prime, primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == Fals... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers up to n (inclusive)",
"function_declaration": "def primes_up_to(n):",
"function_name": "primes_up_to",
"par... | [
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 primes_up_to(n):\n \"\"\"\n Returns a list of prime numbers up to and including n.\n \"\"\"\n if n < 2:\n return []\n \n primes = []\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010006",
"row_id": 10006,
"seed_ids": "[4728]"
} | 0.767826 | Apps_10006 | I | [
"is_prime",
"primes_up_to"
] | 2 | [
[
"primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a98211a8934d0f375ef7001e4a55f14f3435c27 | 6648ab6d98f397553210e5d42b97fea049ce1ce2 | |||
v1.0 | instruct | Apps | Apps_10012_I | ### Binary Array Representation
You are given an integer `n`. Your task is to generate a binary representation of all numbers from `1` to `n` and return them in the form of a list of strings.
**Input**
- An integer `n` where `1 <= n <= 100`.
**Output**
- A list of strings representing the binary representations of a... | def decimal_to_binary(num):
"""
Converts a given decimal number to its binary representation as a string.
"""
binary_str = ""
while num > 0:
binary_str = str(num % 2) + binary_str
num = num // 2
return binary_str
def generate_binary_representations(n):
"""
Generates the ... | def test_decimal_to_binary():
assert decimal_to_binary(1) == "1"
assert decimal_to_binary(2) == "10"
assert decimal_to_binary(3) == "11"
assert decimal_to_binary(4) == "100"
assert decimal_to_binary(5) == "101"
def test_generate_binary_representations():
assert generate_binary_representations(1... | [
{
"docstring": "Converts a given decimal number to its binary representation as a string.",
"function_declaration": "def decimal_to_binary(num):",
"function_name": "decimal_to_binary",
"parameter_list": "(num)"
},
{
"docstring": "Generates the binary representations for all numbers from 1 to... | [
1,
0,
1,
1,
1,
1,
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 int_to_binary_string(number):\n \"\"\"\n Convert an integer to its binary string representation without leading zeros.\n \"\"\"\n if number == 0:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010012",
"row_id": 10012,
"seed_ids": "[4246]"
} | 0.667337 | Apps_10012 | I | [
"decimal_to_binary",
"generate_binary_representations"
] | 2 | [
[
"generate_binary_representations",
"decimal_to_binary"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b1bbf1af8245a14e0320876c2542922687862433 | 68ee4fa81981313c562674c13dd4670dcf819f07 | |||
v1.0 | instruct | Apps | Apps_10018_I | Create a function that takes an array of integers and returns a new array containing only the numbers that are prime.
## About prime numbers
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For instance, the number 2 is a prime number because it is only divisibl... | def is_prime(num):
"""
Helper function to determine if a number is a prime number.
Returns True if the number is prime, False otherwise.
"""
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):... | 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(16) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(-5) == Fals... | [
{
"docstring": "Helper function to determine if a number is a prime number.\nReturns True if the number is prime, False otherwise.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list containing only the prim... | [
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 n is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010018",
"row_id": 10018,
"seed_ids": "[3978]"
} | 0.690625 | Apps_10018 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a4bf3d6f9135bd2a63f452759b0e3b89595b6a0 | ad6eb3abb9545738ba68c275f860f4d163ef2838 | |||
v1.0 | instruct | Apps | Apps_10032_I | You are given a list, `wordList`, that contains `n` words and a `startWord` and `endWord` that are both in the `wordList`. A transformation sequence from the `startWord` to `endWord` is a sequence of words such that:
1. Each word in the sequence is in `wordList`.
2. The first word in the sequence is `startWord`.
3. Th... | from collections import deque
def is_one_letter_diff(word1, word2):
"""
Checks if the two words differ by exactly one character.
"""
diff_count = 0
for c1, c2 in zip(word1, word2):
if c1 != c2:
diff_count += 1
if diff_count > 1:
return False
return diff_c... | from solution import shortest_transformation_sequence
def test_example_1():
wordList = ["hot","dot","dog","lot","log","cog"]
startWord = "hit"
endWord = "cog"
assert shortest_transformation_sequence(wordList, startWord, endWord) == 5
def test_example_2():
wordList = ["hot","dot","dog","lot","log"]... | [
{
"docstring": "Checks if the two words differ by exactly one character.",
"function_declaration": "def is_one_letter_diff(word1, word2):",
"function_name": "is_one_letter_diff",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Returns the length of the shortest transformation sequence ... | [
1,
0,
0,
0,
0,
0,
1,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef differ_by_one(word1, word2):\n \"\"\"\n Check if word1 and word2 differ by exactly one character.\n \"\"\"\n return... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00010032",
"row_id": 10032,
"seed_ids": "[1958]"
} | 0.674273 | Apps_10032 | I | [
"is_one_letter_diff",
"shortest_transformation_sequence"
] | 2 | [
[
"shortest_transformation_sequence",
"is_one_letter_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 390e78af583ad80ab5870e285bd24b81660c1917 | 53d0d8caf8b8b6ae0dd085cc446b47d653d1ef8e | |||
v1.0 | instruct | Apps | Apps_10076_I | # Task
A "palindromic prime" is a prime number that is also a palindrome. Given an integer range `[a, b]`, your task is to find all palindromic primes within this range, inclusive of `a` and `b`.
# Input/Output
`[input]` integer `a`
Integer representing the start of the range (inclusive).
`[input]` integer `b`
Integ... | def is_palindrome(n):
"""
Check if a given number n is a palindrome.
"""
return str(n) == str(n)[::-1]
def is_prime(n):
"""
Check if a given number n is a prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
... | from solution import is_palindrome, is_prime, palindromic_primes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) ==... | [
{
"docstring": "Check if a given number n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Check if a given number n is a prime.",
"function_declaration": "def is_prime(n):",
"function_nam... | [
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 is_palindrome(x):\n return str(x) == str(x)[::-1]\n\ndef sieve_of_eratosthenes(n):\n is_prime = [True] * (n + 1)\n is_prime[0] = is_prime[1] = False\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00010076",
"row_id": 10076,
"seed_ids": "[4668]"
} | 0.58757 | Apps_10076 | I | [
"is_palindrome",
"is_prime",
"palindromic_primes"
] | 3 | [
[
"palindromic_primes",
"is_palindrome"
],
[
"palindromic_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6f811760abce25e068db576fc681f7be6deb90bc | 64cc01b4f672ca51fe68ced1060a89306f09e715 | |||
v1.0 | instruct | Apps | Apps_10203_I | Write a function `fibonacci_checker(n)` that takes an integer `n` as input and returns True if `n` is a part of the Fibonacci sequence, and False otherwise. The function should efficiently determine the status of `n` without generating the whole sequence up to `n`.
The Fibonacci sequence starts with `0, 1`, and each s... | import math
def is_perfect_square(x):
"""
Helper function to check if x is a perfect square.
"""
s = int(math.sqrt(x))
return s * s == x
def fibonacci_checker(n):
"""
Returns True if n is a Fibonacci number, and False if it is not.
"""
# A number is Fibonacci if and only if one or ... | from solution import fibonacci_checker
def test_fibonacci_checker_with_fib_numbers():
assert fibonacci_checker(0) == True
assert fibonacci_checker(1) == True
assert fibonacci_checker(2) == True
assert fibonacci_checker(3) == True
assert fibonacci_checker(5) == True
assert fibonacci_checker(8) =... | [
{
"docstring": "Helper function to check if x is a perfect square.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Returns True if n is a Fibonacci number, and False if it is not.",
"function_declarat... | [
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": "import math\n\ndef is_perfect_square(x):\n s = int(math.sqrt(x))\n return s * s == x\n\ndef fibonacci_checker(n):\n \"\"\"\n Returns True if `n` is a Fi... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010203",
"row_id": 10203,
"seed_ids": "[4442]"
} | 0.694117 | Apps_10203 | I | [
"is_perfect_square",
"fibonacci_checker"
] | 2 | [
[
"fibonacci_checker",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6fbe1ba2ac695a9cf4b1aeaf4db71b6796de50bf | d291a5160df9c415b49356cdff0d287e5c6074af | |||
v1.0 | instruct | Apps | Apps_10301_I | -----
STRING MANIPULATION AND REPLACEMENT
-----
Zeus, the god of thunder, is working on a secret project, and he seeks your help to decode a special message. The message is represented as a string, and the decoding involves a series of replace operations. Each replace operation replaces all occurrences of a substring... | def decode_message(message, operations):
"""
Applies a series of replace operations to the given message.
Parameters:
- message: The original message (string).
- operations: A list of tuples, where each tuple contains two strings (s1, s2),
representing the substring to be replaced and th... | from solution import decode_message, apply_replacements
def test_single_replacement():
assert decode_message("hello_world", [("hello", "hi")]) == "hi_world"
def test_multiple_replacements():
assert decode_message("hello_world", [("hello", "hi"), ("world", "earth")]) == "hi_earth"
def test_replacement_order()... | [
{
"docstring": "Applies a series of replace operations to the given message.\n\nParameters:\n- message: The original message (string).\n- operations: A list of tuples, where each tuple contains two strings (s1, s2), \n representing the substring to be replaced and the substring to replace it with, respectively... | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
0
] | 9 | easy | 0.9 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decode_message(original_message, replacements):\n \"\"\"\n Applies a sequence of replacements to the given string and returns the final decoded message.\n... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00010301",
"row_id": 10301,
"seed_ids": "[1049]"
} | 0.657321 | Apps_10301 | I | [
"decode_message",
"apply_replacements"
] | 2 | [
[
"apply_replacements",
"decode_message"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf0504fff98bc90348347b927034c199681bf62d | 14ad6c033b4c78e11290912fcfb031ba2b5aaf2f | |||
v1.0 | instruct | Apps | Apps_10330_I | Write a function `amicable_numbers(n)` that finds all pairs of amicable numbers less than or equal to `n`. Two numbers are considered amicable if the sum of the proper divisors of each number equals the other number. For example, (220, 284) is an amicable pair because the sum of proper divisors of 220 is 284, and the s... | def sum_of_proper_divisors(num):
"""Helper function to calculate the sum of proper divisors of num."""
proper_divisors_sum = 1 # 1 is a proper divisor for any num > 1
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
proper_divisors_sum += i
if i != num // i: # Avoid a... | from solution import amicable_numbers
def test_no_amicable_numbers():
assert amicable_numbers(1) == []
assert amicable_numbers(10) == []
def test_single_amicable_pair():
assert amicable_numbers(300) == [(220, 284)]
def test_multiple_amicable_pairs():
assert amicable_numbers(10000) == [(220, 284), (11... | [
{
"docstring": "Helper function to calculate the sum of proper divisors of num.",
"function_declaration": "def sum_of_proper_divisors(num):",
"function_name": "sum_of_proper_divisors",
"parameter_list": "(num)"
},
{
"docstring": "Function to find all pairs of amicable numbers less than or eq... | [
1,
1,
1,
1,
1,
1,
0,
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 sum_of_proper_divisors(num):\n \"\"\"\n Returns the sum of proper divisors of a given number 'num'.\n \"\"\"\n if num < 2:\n return 0\n pr... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010330",
"row_id": 10330,
"seed_ids": "[1653]"
} | 0.662305 | Apps_10330 | I | [
"sum_of_proper_divisors",
"amicable_numbers"
] | 2 | [
[
"amicable_numbers",
"sum_of_proper_divisors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e1519db82b21cc9eee51d9b55bf831ab66631453 | 1e06a369357619ff8ca4e16b98c0b9fe79edf1ad | |||
v1.0 | instruct | Apps | Apps_10344_I | The company has a network of warehouses where products are stored before being shipped to customers. The network of warehouses can be represented as an undirected graph, with each warehouse as a node and each direct road between two warehouses as an edge. The company's goal is to upgrade the network to ensure that ever... | import heapq
def prim_minimum_spanning_tree(n, edges):
# Adjacency list representation of the graph
graph = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
graph[u].append((w, v))
graph[v].append((w, u))
# Priority queue to pick the minimum weight edge
min_heap = [(0, 1)] # S... | def test_case_1():
input_data = """2
4 5
1 2 1
1 3 4
1 4 3
2 3 2
3 4 5
3 3
1 2 2
2 3 3
1 3 4"""
test_cases = parse_input(input_data)
assert min_upgrade_cost(test_cases) == [6, 5]
def test_case_2():
input_data = """1
5 6
1 2 2
1 3 3
1 4 1
1 5 4
2 3 5
4 5 6"""
test_cases = parse_input(input_data)
... | [
{
"docstring": null,
"function_declaration": "def prim_minimum_spanning_tree(n, edges):",
"function_name": "prim_minimum_spanning_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def min_upgrade_cost(test_cases):",
"function_name": "min_upgrade_c... | [
0,
1,
0,
1,
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 find_min_cost_to_upgrade_network(T, test_cases):\n \"\"\"\n Function to calculate minimum cost to upgrade the network using Kruskal's algorithm\n which... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00010344",
"row_id": 10344,
"seed_ids": "[1570]"
} | 0.717171 | Apps_10344 | I | [
"prim_minimum_spanning_tree",
"min_upgrade_cost",
"parse_input"
] | 3 | [
[
"min_upgrade_cost",
"prim_minimum_spanning_tree"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 64ec2288a0a72349cf64c5a6d283a7199173453f | df7288366c5800651ecba6085148bdd2e905a6d4 | |||
v1.0 | instruct | Apps | Apps_10374_I | There is a city with N buildings aligned in a straight row, numbered from 1 to N. Each building i has a certain height Hi. A building i can view the ocean if, and only if, there are no buildings taller than building i to its right. In other words, building i can view the ocean if all buildings to its right are shorter ... | def ocean_view_buildings(test_cases):
results = []
for buildings in test_cases:
N, heights = buildings
ocean_view_indexes = []
max_height_so_far = -1
for i in range(N - 1, -1, -1):
if heights[i] > max_height_so_far:
ocean_view_indexes.append(i + 1)
... | import pytest
from solution import ocean_view_buildings, parse_input, ocean_view_buildings_from_input
def test_ocean_view_buildings():
test_cases = [
(6, [4, 2, 3, 1, 5, 8]),
(5, [5, 4, 3, 2, 1]),
]
expected = [
"6",
"1 2 3 4 5"
]
assert ocean_view_buildings(test_cas... | [
{
"docstring": null,
"function_declaration": "def ocean_view_buildings(test_cases):",
"function_name": "ocean_view_buildings",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"param... | [
1,
0,
0,
0,
1,
0,
1,
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 can_view_ocean(N, heights):\n \"\"\"\n Returns indices of buildings that can view the ocean.\n \n Args:\n N : int : Number of buildings\n heig... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00010374",
"row_id": 10374,
"seed_ids": "[1075]"
} | 0.8494 | Apps_10374 | I | [
"ocean_view_buildings",
"parse_input",
"ocean_view_buildings_from_input"
] | 3 | [
[
"ocean_view_buildings_from_input",
"ocean_view_buildings"
],
[
"ocean_view_buildings_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 7dca9d4b3a55652b56ba37257f529b1bddd918cd | 22253cfeed53b979718b9e0b314428597f886cbe | |||
v1.0 | instruct | Apps | Apps_10413_I | Given a list of integers, determine if each integer is a 'happy number'. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a c... | def is_happy_number(n):
"""
Determines if the provided number n is a happy number.
"""
def get_next(number):
total_sum = 0
while number > 0:
number, digit = divmod(number, 10)
total_sum += digit * digit
return total_sum
seen_numbers = set()
wh... | from solution import is_happy_number, determine_happy_numbers
def test_is_happy_number_true():
assert is_happy_number(19) == True
def test_is_happy_number_false():
assert is_happy_number(20) == False
def test_determine_happy_numbers():
assert determine_happy_numbers([19, 20]) == ["YES", "NO"]
def test_m... | [
{
"docstring": "Determines if the provided number n is a happy number.",
"function_declaration": "def is_happy_number(n):",
"function_name": "is_happy_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks a list of integers to determine if each is a happy number.\nReturns a list of stri... | [
0,
1,
0,
1,
0,
1,
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_happy_number(n):\n \"\"\"\n Determine if a number n is a happy number.\n \"\"\"\n seen = set()\n while n not in seen:\n seen.add(n)\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010413",
"row_id": 10413,
"seed_ids": "[741]"
} | 0.598894 | Apps_10413 | I | [
"is_happy_number",
"determine_happy_numbers"
] | 2 | [
[
"determine_happy_numbers",
"is_happy_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 147c37ff269f9e50a9866c716be9591cb5846531 | 44c52b9edf7e3cb3496e724061de119d8f5a6661 | |||
v1.0 | instruct | Apps | Apps_10444_I | Each student in a class has received a unique identifier consisting of lowercase letters ('a' to 'z'). The class has a well-defined rule where a student can only move up in rank if the sum of the alphabetical positions of the letters in their identifier is greater than the sum of the letters in any of their predecessor... | def alphabetical_sum(identifier):
"""
Returns the sum of alphabetical positions of the characters in the identifier.
"""
return sum(ord(char) - ord('a') + 1 for char in identifier)
def ranked_students(students):
"""
Returns a list of students sorted based on the sum of the alphabetical position... | from solution import ranked_students
def test_ranked_students_basic_case():
students = ["abc", "abd", "aaa"]
assert ranked_students(students) == ["aaa", "abc", "abd"]
def test_ranked_students_single_element():
students = ["abc"]
assert ranked_students(students) == ["abc"]
def test_ranked_students_ide... | [
{
"docstring": "Returns the sum of alphabetical positions of the characters in the identifier.",
"function_declaration": "def alphabetical_sum(identifier):",
"function_name": "alphabetical_sum",
"parameter_list": "(identifier)"
},
{
"docstring": "Returns a list of students sorted based on th... | [
1,
1,
0,
0,
0,
1,
1,
0,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def alphabetical_sum(identifier):\n \"\"\"\n Returns the sum of alphabetical positions of the letters in the identifier.\n \"\"\"\... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010444",
"row_id": 10444,
"seed_ids": "[2668]"
} | 0.602972 | Apps_10444 | I | [
"alphabetical_sum",
"ranked_students"
] | 2 | [
[
"ranked_students",
"alphabetical_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f827161d61b724fa62a4a1e7fe33eabee7eae3e3 | 87b92e5657ef6977aad22b8e6a065fe5f83b0f42 | |||
v1.0 | instruct | Apps | Apps_10450_I | Your task is to determine if a sequence of moves in a chess game is valid based on the movement rules for each piece.
_________________________________________________
Rules:
1. The chessboard is represented by an 8x8 grid with columns labeled from 'a' to 'h' and rows from '1' to '8'. For example, the bottom-left cor... | def is_valid_move(piece, start, end):
col_diff = ord(end[0]) - ord(start[0])
row_diff = int(end[1]) - int(start[1])
if piece == 'Pawn':
# Assume it's a white Pawn for simplicity
return (col_diff == 0 and row_diff == 1) or \
(abs(col_diff) == 1 and row_diff == 1)
elif ... | from solution import are_moves_valid
def test_valid_moves():
assert are_moves_valid([('Pawn', 'e2', 'e3'), ('Knight', 'g1', 'f3')]) == True
assert are_moves_valid([('Rook', 'a1', 'a8'), ('Bishop', 'c1', 'g5')]) == True
assert are_moves_valid([('Queen', 'd1', 'd4'), ('King', 'e1', 'e2')]) == True
assert... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(piece, start, end):",
"function_name": "is_valid_move",
"parameter_list": "(piece, start, end)"
},
{
"docstring": null,
"function_declaration": "def are_moves_valid(moves):",
"function_name": "are_moves_valid",
"para... | [
0,
1,
1,
0,
0,
0,
1,
0,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_move(move):\n piece, start, end = move\n start_col, start_row = ord(start[0]) - ord('a'), int(start[1]) - 1\n end_col, end_row = ord(end[0]) -... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010450",
"row_id": 10450,
"seed_ids": "[4509]"
} | 0.611459 | Apps_10450 | I | [
"is_valid_move",
"are_moves_valid"
] | 2 | [
[
"are_moves_valid",
"is_valid_move"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ac4feaa11aca0a8ac55758bf7ee9498d057234a8 | a9e01d7b9b85fe4fe9f43dcee6162223c2c48cda | |||
v1.0 | instruct | Apps | Apps_10534_I | A village is planning to build roads to connect all its houses. The village has N houses, and a set of M potential roads. Each road i connects two houses u[i] and v[i], and has a cost associated with it, w[i].
To facilitate trade and communication, the village chief wants to ensure that all houses are connected direct... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def test_minimum_cost_to_connect_all_houses():
input_data = [
(2, [
(4, 5, [(1, 2, 10), (2, 3, 15), (3, 4, 10), (1, 4, 5), (2, 4, 10)]),
(3, 3, [(1, 2, 1), (2, 3, 2), (3, 1, 3)])
]),
]
expected_results = [
[25, 3]
]
for i, data in enumerate(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
] | 1 | hard | 0.111 | {
"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 xroot = fin... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010534",
"row_id": 10534,
"seed_ids": "[670]"
} | 0.752088 | Apps_10534 | I | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_all_houses"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_all_houses",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 8fa55f808cc9e88b136073ea95f73ea1b27752eb | 673e1aeecd7d26e188da7dd3f3b54520f04137cf | |||
v1.0 | instruct | Apps | Apps_10577_I | In a city, there is a single taxi service which serves multiple customers every day. Each taxi ride consists of picking up a customer from a specific location, driving to their destination, and then returning to the starting point. The service charges customers based on the total distance the taxi travels during each r... | def calculate_trip_cost(d, p, r):
"""
Returns the total cost of a taxi trip given the distance d, price per unit distance p, and return price per unit distance r.
The cost includes the trip to the customer's destination and the return trip to the starting location.
"""
if d == 0 and p == 0 and r == ... | def test_calculate_trip_cost():
assert calculate_trip_cost(10, 2, 1) == 30
assert calculate_trip_cost(15, 3, 2) == 75
assert calculate_trip_cost(0, 0, 0) == 0 # should return 0 as part of the function condition
assert calculate_trip_cost(1000, 100, 100) == 200000
assert calculate_trip_cost(500, 10,... | [
{
"docstring": "Returns the total cost of a taxi trip given the distance d, price per unit distance p, and return price per unit distance r.\nThe cost includes the trip to the customer's destination and the return trip to the starting location.",
"function_declaration": "def calculate_trip_cost(d, p, r):",
... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
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_trip_cost(d, p, r):\n \"\"\"\n Calculate the total cost of a taxi trip.\n \n Parameters:\n d (int): distance from pickup to destination... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010577",
"row_id": 10577,
"seed_ids": "[1268]"
} | 0.69467 | Apps_10577 | I | [
"calculate_trip_cost",
"process_trip_costs"
] | 2 | [
[
"process_trip_costs",
"calculate_trip_cost"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4b615ee4ec2c9be8171ff6ea2d7fd84d029a39df | 6b20e678c0c992419f0bb040ea4058c1180c4fb6 | |||
v1.0 | instruct | Apps | Apps_10593_I | Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. For the purposes of this problem, a prime number is a natural 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]
Outpu... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def filter_... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_filter_primes_no_... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out the prime numbers from a list of integers.",
"function_declaration": "def filter_primes(numbe... | [
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 for i in range(2, int... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010593",
"row_id": 10593,
"seed_ids": "[2827]"
} | 0.641953 | Apps_10593 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8de6528516c2caa8fedd821d1c3a1eccd25a11bd | 7dd9f0fc9cfd1466878ebddfeb0cb46704c99f7c | |||
v1.0 | instruct | Apps | Apps_10654_I | Write a function named `shared_divisors` that takes in two integers, `x` and `y`, and returns the number of common divisors they have. A divisor of a number `n` is a number `d` such that `n % d == 0`.
### Examples
```python
shared_divisors(12, 18) # should return 4, since the common divisors are 1, 2, 3, 6
shared_div... | def gcd(a, b):
"""
Returns the Greatest Common Divisor of `a` and `b` using the Euclidean algorithm.
"""
while b:
a, b = b, a % b
return a
def shared_divisors(x, y):
"""
Returns the number of common divisors of `x` and `y`.
"""
def count_divisors(n):
count = 0
... | from solution import shared_divisors
def test_shared_divisors_common():
assert shared_divisors(12, 18) == 4 # Common divisors: 1, 2, 3, 6
def test_shared_divisors_prime_numbers():
assert shared_divisors(7, 13) == 1 # Common divisor: 1
def test_shared_divisors_mixed():
assert shared_divisors(100, 75) ==... | [
{
"docstring": "Returns the Greatest Common Divisor of `a` and `b` using the Euclidean algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the number of common divisors of `x` and `y`.",
"function_declaratio... | [
0,
0,
0,
0,
0,
1,
1,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def shared_divisors(x, y):\n \"\"\"\n Returns the number of common divisors of x and y.\n \"\"\"\n def gcd(a, b):\n \"\"\"Helper function to comp... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010654",
"row_id": 10654,
"seed_ids": "[3200]"
} | 0.800174 | Apps_10654 | I | [
"gcd",
"shared_divisors"
] | 2 | [
[
"shared_divisors",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02b54c9580f4ecd25d764b4cdf1fe1be0df36280 | dc6d9cbde616e4e2e43d946bd68d1955ce4b5c8c | |||
v1.0 | instruct | Apps | Apps_10737_I | =====Problem Statement=====
You are given a list of N integers representing the heights of buildings in a city skyline. You need to implement a function that finds the largest rectangular area that can be formed with the buildings, where the width of each building is 1.
Each building's width is fixed at 1 unit, but th... | def max_histogram_area(heights):
"""
Returns the largest rectangular area possible in 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 += 1
e... | from solution import largest_rectangle_area
def test_example():
assert largest_rectangle_area(7, [6, 2, 5, 4, 5, 1, 6]) == 12
def test_single_building():
assert largest_rectangle_area(1, [5]) == 5
def test_increasing_heights():
assert largest_rectangle_area(5, [1, 2, 3, 4, 5]) == 9
def test_decreasing_h... | [
{
"docstring": "Returns the largest rectangular area possible in a histogram.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": "Returns the largest rectangular area possible with the given bui... | [
0,
1,
1,
1,
1,
1,
1,
0,
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 largest_rectangle_area(heights):\n \"\"\"\n Calculate the maximum rectangular area in a histogram given the list of heights.\n \"\"\"\n stack = []\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010737",
"row_id": 10737,
"seed_ids": "[2631]"
} | 0.718235 | Apps_10737 | I | [
"max_histogram_area",
"largest_rectangle_area"
] | 2 | [
[
"largest_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ff0ecefc5f50a8358ce84e1b2da4ff8005e9741b | 299ef8f1fd5346222344af57ead3e3293d1a1647 | |||
v1.0 | instruct | Apps | Apps_10784_I | You are given an array of integers and a target value. Your task is to determine whether there are two distinct elements in the array that add up to the target value. If such a pair exists, return the indices of the two numbers; otherwise, return `-1 -1`.
Note that the indices returned should be zero-based and in asce... | def find_two_sum_indices(array, target):
"""Finds indices of two elements in the array that add up to the target."""
num_to_index = {}
for index, num in enumerate(array):
if target - num in num_to_index:
return num_to_index[target - num], index
num_to_index[num] = index
retur... | import pytest
from solution import find_two_sum_indices, solve_tests, process_input
def test_find_two_sum_indices():
# Test case 1
array = [2, 7, 11, 15, 1]
target = 9
assert find_two_sum_indices(array, target) == (0, 1)
# Test case 2
array = [3, 3, 4]
target = 6
assert find_two_sum_in... | [
{
"docstring": "Finds indices of two elements in the array that add up to the target.",
"function_declaration": "def find_two_sum_indices(array, target):",
"function_name": "find_two_sum_indices",
"parameter_list": "(array, target)"
},
{
"docstring": null,
"function_declaration": "def so... | [
0,
0,
0,
1,
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_two_sum_indices(array, target):\n \"\"\"\n Returns the indices of two numbers in an array that add up to the target value.\n If no such pair exist... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00010784",
"row_id": 10784,
"seed_ids": "[650]"
} | 0.76102 | Apps_10784 | I | [
"find_two_sum_indices",
"solve_tests",
"process_input"
] | 3 | [
[
"solve_tests",
"find_two_sum_indices"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 3b374199af97efa25396880df5528f4ceda42be7 | 328a766f7e04d7ee1bdc5e06b9c56b038fbba6df | |||
v1.0 | instruct | Apps | Apps_10790_I | The online music streaming service, Melodify, allows users to create and share playlists. However, due to recent updates, users are required to ensure their playlists do not contain duplicate songs. You have been asked to create a function that checks a given playlist and removes any duplicate songs, preserving the ord... | def remove_duplicates(playlist):
"""
Removes duplicate songs from the playlist, preserving the order of their first occurrence.
Args:
playlist (list): A list of integers representing song IDs.
Returns:
list: A list of integers with duplicates removed.
"""
seen = set()
uniqu... | from solution import remove_duplicates, process_playlist
def test_remove_duplicates():
assert remove_duplicates([10, 20, 10, 30, 20, 40, 50, 40]) == [10, 20, 30, 40, 50]
assert remove_duplicates([1, 2, 2, 3, 4, 4, 5, 5, 1, 6]) == [1, 2, 3, 4, 5, 6]
assert remove_duplicates([]) == []
assert remove_dupli... | [
{
"docstring": "Removes duplicate songs from the playlist, preserving the order of their first occurrence.\n\nArgs:\nplaylist (list): A list of integers representing song IDs.\n\nReturns:\nlist: A list of integers with duplicates removed.",
"function_declaration": "def remove_duplicates(playlist):",
"fu... | [
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 remove_duplicates(playlist):\n \"\"\"\n Takes a list of integers representing song IDs, removes duplicates, and preserves order of first occurrence.\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010790",
"row_id": 10790,
"seed_ids": "[869]"
} | 0.556092 | Apps_10790 | I | [
"remove_duplicates",
"process_playlist"
] | 2 | [
[
"process_playlist",
"remove_duplicates"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4e0d96806f1be940d661a1105a3ddae8c7d2807 | 66cbab5d545eb8af4ccd1628baffab7f6c9210ba | |||
v1.0 | instruct | Apps | Apps_10800_I | You are given an undirected graph with $N$ nodes and $M$ edges. Each node is uniquely numbered from $1$ to $N$. Each edge has a weight associated with it. The graph may have multiple edges between two nodes but does not contain self-loops.
Your task is to determine the weight of the minimum spanning tree (MST) for the... | import heapq
def find_parent(parent, i):
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[x... | from solution import minimum_spanning_tree
def test_case_1():
t = 2
test_cases = [
(4, 5, [(1, 2, 3), (1, 3, 1), (2, 3, 3), (3, 4, 6), (2, 4, 2)]),
(3, 3, [(1, 2, 4), (2, 3, 7), (1, 3, 1)])
]
assert minimum_spanning_tree(t, test_cases) == [6, 5]
def test_case_disconnected_graph():
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
1,
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": "import heapq\n\ndef find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent,... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010800",
"row_id": 10800,
"seed_ids": "[729]"
} | 0.836437 | Apps_10800 | I | [
"find_parent",
"union",
"kruskal_mst",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal_mst",
"find_parent"
],
[
"kruskal_mst",
"union"
],
[
"minimum_spanning_tree",
"kruskal_mst"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 7a667d4527e286af5e2c78ccaf013a4d5358967e | 1e0978fbbdaebf7bf7850f5bcde70359c910ba55 | |||
v1.0 | instruct | Apps | Apps_10823_I | Write a function that takes an integer n as input and returns the sum of the factorials of its digits. The function should first calculate the factorial for each digit in the number, and then return the sum of these factorials. You are not allowed to use any built-in factorial function.
**Example**
```python
Input: n... | def factorial(digit: int) -> int:
"""
Returns the factorial of a given digit.
"""
if digit == 0 or digit == 1:
return 1
result = 1
for i in range(2, digit + 1):
result *= i
return result
def sum_of_digit_factorials(n: int) -> int:
"""
Returns the sum of the factorial... | from solution import sum_of_digit_factorials
def test_sum_of_digit_factorials_single_digit():
assert sum_of_digit_factorials(5) == 120
assert sum_of_digit_factorials(0) == 1
def test_sum_of_digit_factorials_multiple_digits():
assert sum_of_digit_factorials(123) == 9
assert sum_of_digit_factorials(405)... | [
{
"docstring": "Returns the factorial of a given digit.",
"function_declaration": "def factorial(digit):",
"function_name": "factorial",
"parameter_list": "(digit)"
},
{
"docstring": "Returns the sum of the factorials of the digits of an integer n.",
"function_declaration": "def sum_of_d... | [
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 factorial(digit: int) -> int:\n \"\"\"\n Returns the factorial of a given digit.\n \"\"\"\n if digit == 0 or digit == 1:\n return 1\n resu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00010823",
"row_id": 10823,
"seed_ids": "[4808]"
} | 0.672748 | Apps_10823 | I | [
"factorial",
"sum_of_digit_factorials"
] | 2 | [
[
"sum_of_digit_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd3882013744dc319cbb940fcb9523d8dadc47bf | 10ff6b281cfb12d2167be9b8abf5ffcf8ffb93a4 | |||
v1.0 | instruct | Apps | Apps_10929_I | In a magical kingdom, the king loves symmetry. Therefore, he has created a special sequence called a symmetric sequence. A symmetric sequence of length $n$ is defined as a sequence of integers $a_1, a_2, ..., a_n$ such that $a_i = a_{n+1-i}$ for all $1 \leq i \leq n$.
The king commands you to create a sequence of leng... | def is_prime(x):
if x <= 1:
return False
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
return False
return True
def generate_sequence(n):
if n == 1:
return [1]
elif n == 2:
return "No symmetric sequence exists"
sequence = [1] * n
unique_... | from solution import symmetric_sequences
def test_case_1():
assert symmetric_sequences(1, [1]) == [[1]]
def test_case_2():
assert symmetric_sequences(1, [2]) == ["No symmetric sequence exists"]
def test_case_3():
assert symmetric_sequences(1, [3]) == [[1, 2, 1]]
def test_multiple_cases():
assert sym... | [
{
"docstring": null,
"function_declaration": "def is_prime(x):",
"function_name": "is_prime",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def generate_sequence(n):",
"function_name": "generate_sequence",
"parameter_list": "(n)"
},
{
"docstring... | [
0,
0,
0,
0,
1,
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(num):\n \"\"\"\n Returns True if the number is prime, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00010929",
"row_id": 10929,
"seed_ids": "[2279]"
} | 0.639531 | Apps_10929 | I | [
"is_prime",
"generate_sequence",
"symmetric_sequences"
] | 3 | [
[
"generate_sequence",
"is_prime"
],
[
"symmetric_sequences",
"generate_sequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c30631fce1c2ace60689c2950ab8a78d0580e6bb | 541e68b0394f5574fa93081fc9438f38ab65ffeb | |||
v1.0 | instruct | Apps | Apps_10964_I | Tom is devising a new card game called "Prime Pairs". Each card is labeled with an integer from 1 to $N$. A "Prime Pair" consists of two numbers $(a, b)$ such that $a + b$ is a prime number. Tom wants to arrange the cards in such a way that there are exactly $K$ "Prime Pairs" in the entire deck. Your task is to help To... | from itertools import combinations
import sympy
def is_prime(num):
"""Check if a number is prime."""
return sympy.isprime(num)
def get_all_prime_pairs(N):
"""Generate all pairs (i, j) such that i < j and (i + j) is prime."""
pairs = []
for i, j in combinations(range(1, N+1), 2):
if is_prim... | from solution import prime_pairs_game
def test_prime_pairs_game_case_1():
assert prime_pairs_game(2, [(4, 2), (6, 5)]) == [
[1, 2, 3, 4],
[1, 2, 3, 4, 5, 6]
]
def test_prime_pairs_game_case_2():
assert prime_pairs_game(1, [(6, 1)]) == [
[1, 2, 3, 4, 5, 6]
]
def test_pr... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate all pairs (i, j) such that i < j and (i + j) is prime.",
"function_declaration": "def get_all_prime_pairs(N):",
... | [
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": "def is_prime(num):\n \"\"\"Check if a number is a prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00010964",
"row_id": 10964,
"seed_ids": "[1135]"
} | 0.742195 | Apps_10964 | I | [
"is_prime",
"get_all_prime_pairs",
"find_sequence",
"prime_pairs_game"
] | 4 | [
[
"find_sequence",
"get_all_prime_pairs"
],
[
"get_all_prime_pairs",
"is_prime"
],
[
"prime_pairs_game",
"find_sequence"
]
] | 3 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | f5f9feeefb4f842d56b49b6b7390f37ce9f78bfe | d79b6c5379326c6d972ad88742853d272c7a095a | |||
v1.0 | instruct | Apps | Apps_10997_I | Write a function that takes an array of numbers as input and returns an array containing two sub-arrays. One sub-array should contain all the numbers that are prime, and the other should contain all the non-prime numbers. Arrange the numbers in each sub-array in the same order they appeared in the input array.
A prime... | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def splitPr... | from solution import splitPrimes, is_prime
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_splitPrimes_with_mixed_numbers():
assert splitPrimes([2, 4, 6, 5, 9, 11, 15]) == [... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Splits the input array into two sub-arrays: one containing prime numbers, and the other containing non-prim... | [
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(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00010997",
"row_id": 10997,
"seed_ids": "[3993]"
} | 0.662243 | Apps_10997 | I | [
"is_prime",
"splitPrimes"
] | 2 | [
[
"splitPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d24c00fe6ce2dc62bd7c9896235e44e0461d7837 | 3f14e952e21446e16839e376bf7772f9fb1f30f5 | |||
v1.0 | instruct | Apps | Apps_11038_I | You have been given a binary tree with N nodes. Each node has a value associated with it. The path sum of any path in this binary tree is defined as the sum of the values of the nodes that the path visits. A path does not necessarily need to pass through the root.
Your task is to find and report the maximum path sum o... | class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def construct_tree(values, edges):
nodes = {i + 1: Node(values[i]) for i in range(len(values))}
for u, v in edges:
if not nodes[u].left:
nodes[u].left = nodes[v]
... | from solution import solve
def test_example1():
test_cases = [
([1, -2, 3], [(1, 2), (1, 3)])
]
assert solve(test_cases) == [4]
def test_example2():
test_cases = [
([-10, 9, 20, 15, 7], [(1, 2), (1, 3), (3, 4), (3, 5)])
]
assert solve(test_cases) == [42]
def test_single_node()... | [] | [
1,
0,
0,
0,
0,
1,
0,
1,
0
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef construct_tree(values, edges):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011038",
"row_id": 11038,
"seed_ids": "[1249]"
} | 0.709546 | Apps_11038 | I | [
"construct_tree",
"max_path_sum",
"solve"
] | 3 | [
[
"solve",
"construct_tree"
],
[
"solve",
"max_path_sum"
]
] | 2 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 435607fadf0518f85007c9450c81299cc52fe8fd | a97b2534e07907d85ee66e732b60280fb6046c0a | |||
v1.0 | instruct | Apps | Apps_11040_I | Write a function that takes a list of integers as input and returns a list containing all the prime numbers from the input list.
Example:
```python
filter_primes([10, 15, 19, 21, 23, 29, 31, 39]) => [19, 23, 29, 31]
filter_primes([4, 6, 8, 9, 10]) => []
filter_primes([2, 3, 5, 7, 11]) => [2, 3, 5, 7, 11]
```
Importan... | def is_prime(n):
"""
Helper function to check if a number is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def filter_primes(numbers):
"""
Takes a list of integers and returns a list of... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([10, 15, 19, 21, 23, 29, 31, 39]) == [19, 23, 29, 31]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_filter_primes_with_all_primes():
assert filter_primes([... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list of prime numbers from that list.",
"function_declarati... | [
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 if n == 2:\n return True\n if n % 2 =... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011040",
"row_id": 11040,
"seed_ids": "[2972]"
} | 0.688641 | Apps_11040 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6d54a4de21fb6d1c3be6c514ee90d2d0152560b | 246169a4b1da29836abbe151c06209c3e7e19564 | |||
v1.0 | instruct | Apps | Apps_11052_I | Given a list of integers, write a function that returns the sum of its elements that are prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For example:
- If the list is [1, 2, 3, 4, 5], the prime numbers are [2, 3, 5], and their sum is 10.
- If the... | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is a 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 sum_of_primes(numbers: List[int]) -> int:
... | from solution import sum_of_primes
def test_sum_of_primes_with_primes():
assert sum_of_primes([1, 2, 3, 4, 5]) == 10
def test_sum_of_primes_all_non_primes():
assert sum_of_primes([0, 1, 4, 6]) == 0
def test_sum_of_primes_mixed_numbers():
assert sum_of_primes([10, 11, 12, 13, 14]) == 24
def test_sum_of_p... | [
{
"docstring": "Helper function to determine if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers in the given list.",
"function_declaration": "def sum_of_primes(numb... | [
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 \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if n <= 1:\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00011052",
"row_id": 11052,
"seed_ids": "[3680]"
} | 0.693406 | Apps_11052 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 43138646abde035364e6d573cb02b39ba3a7d83a | c11ad3f8ecf1172e9021a24318f18856cbc34503 | |||
v1.0 | instruct | Apps | Apps_11113_I | Alice has a rectangular grid of size N x M, filled with integers. Bob helps Alice by providing a subgrid of size k x k. Alice wants to find the sum of the elements in this subgrid. Since Bob can be busy, the task is to optimize the query to find the sum as quickly as possible.
Can you help Alice by preprocessing the ... | def create_prefix_sum(grid):
"""
Create a prefix sum matrix for the given grid.
"""
N = len(grid)
M = len(grid[0])
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] = grid[i-1][j-1] + prefix_sum[i-... | from solution import create_prefix_sum, subgrid_sum, process_queries
def test_create_prefix_sum():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert create_p... | [
{
"docstring": "Create a prefix sum matrix for the given grid.",
"function_declaration": "def create_prefix_sum(grid):",
"function_name": "create_prefix_sum",
"parameter_list": "(grid)"
},
{
"docstring": "Calculate the sum of the subgrid from (x1, y1) to (x2, y2) using the prefix sum matrix.... | [
1,
1,
0,
1,
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 preprocess_grid(grid, n, m):\n \"\"\"\n Preprocess the grid to compute the prefix sum array.\n \"\"\"\n prefix_sum = [[0] * (m + 1) for _ in range(n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011113",
"row_id": 11113,
"seed_ids": "[901]"
} | 0.607663 | Apps_11113 | I | [
"create_prefix_sum",
"subgrid_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"create_prefix_sum"
],
[
"process_queries",
"subgrid_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | a29d469e418cc8c60ca654c22462d02405986633 | 8af03e15266905ab37c5418935b587d22145516c | |||
v1.0 | instruct | Apps | Apps_11168_I | In a mystical forest, there is a magical tree with $N$ nodes. Each node is uniquely identified by an integer from $1$ to $N$. The tree is rooted at node $1$. Each node has an associated integer value $a_i$ (1 ≤ i ≤ N).
A forest guardian is tasked with ensuring the health of the tree. To do this, he wants to determine... | def calculate_subtree_strengths(N, values, edges, queries):
from collections import defaultdict, deque
# Build the tree graph from edges
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Strengths array to store the sum of values in the subtree roote... | def test_calculate_subtree_strengths():
N = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
Q = 3
queries = [1, 2, 3]
result = run_queries(N, values, edges, Q, queries)
assert result == [15, 11, 3], f"Expected [15, 11, 3] but got {result}"
def test_single_node():
N =... | [
{
"docstring": null,
"function_declaration": "def calculate_subtree_strengths(N, values, edges, queries):",
"function_name": "calculate_subtree_strengths",
"parameter_list": "(N, values, edges, queries)"
},
{
"docstring": null,
"function_declaration": "def run_queries(N, values, edges, Q... | [
1,
1,
0,
0,
0,
0,
0,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_subtree_strengths(N, values, edges, queries):\n from collections import defaultdict, deque\n\n # Build the tree structure using adjacency list\n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011168",
"row_id": 11168,
"seed_ids": "[1006]"
} | 0.678357 | Apps_11168 | I | [
"calculate_subtree_strengths",
"run_queries"
] | 2 | [
[
"run_queries",
"calculate_subtree_strengths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d3c6ed14fbfede1cd3d61ebbc74f06e8442602f6 | 1a3f8c085ba6c77ffd936ce8fd71c74b9bbd9e29 | |||
v1.0 | instruct | Apps | Apps_11244_I | Given a list of words, find the length of the longest word that is a subsequence of the given string.
A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Return the length of the longest such word, or -1 if no word in t... | def is_subsequence(s, word):
it = iter(s)
return all(char in it for char in word)
def longest_subsequence_length(s, words):
max_length = -1
for word in words:
if is_subsequence(s, word):
max_length = max(max_length, len(word))
return max_length | from solution import longest_subsequence_length
def test_no_subsequence():
assert longest_subsequence_length("abc", ["def", "ghi"]) == -1
def test_one_subsequence():
assert longest_subsequence_length("abc", ["a", "d"]) == 1
def test_multiple_subsequences():
assert longest_subsequence_length("abpcplea", [... | [
{
"docstring": null,
"function_declaration": "def is_subsequence(s, word):",
"function_name": "is_subsequence",
"parameter_list": "(s, word)"
},
{
"docstring": null,
"function_declaration": "def longest_subsequence_length(s, words):",
"function_name": "longest_subsequence_length",
... | [
1,
1,
0,
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 longest_subsequence_word_length(s, words):\n \"\"\"\n Find the length of the longest word in the list 'words' that is a subsequence of the string 's'.\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00011244",
"row_id": 11244,
"seed_ids": "[3303]"
} | 0.723606 | Apps_11244 | I | [
"is_subsequence",
"longest_subsequence_length"
] | 2 | [
[
"longest_subsequence_length",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 08bdc4232fe56d1a7b84141054385d054b9e352f | e2846d66192956a393650da275e54a1a83413e19 | |||
v1.0 | instruct | Apps | Apps_11273_I | Write a function that takes a list of integers and returns a new list that contains all the integers from the original list that are prime numbers.
A prime number is a number that is greater than 1 and is only divisible by 1 and itself. For example, the first few prime numbers are 2, 3, 5, 7, 11, and so on.
Here is a... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def filter_primes(lst):
"""
Returns a list of prime numbers from the given ... | from solution import filter_primes
def test_filter_primes_mixed_numbers():
assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_prime_numbers():
assert filter_primes([11, 13, 17, 19]) == [11, 13, 17, 19]
def test_filter_primes_no_primes():
assert filter_primes([4, 6, ... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the given list.",
"function_declaration": "def filter_primes(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": "import math\n\ndef 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(math.sqrt(... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011273",
"row_id": 11273,
"seed_ids": "[1608]"
} | 0.754332 | Apps_11273 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46ac2bca75a70933cc4f6714b5d615ec202aa4b4 | 4f31dc12709ede5b7d3674ec4b33fdbfd8c75742 | |||
v1.0 | instruct | Apps | Apps_11293_I | Given a list of integers, write a function that returns a new list containing only the prime numbers from the original list.
Provide an implementation that is efficient and consider edge cases (e.g., negative numbers, zero, and one which are not primes).
Input will be a list of integers with length > 0. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import filter_primes
def test_filter_primes_empty():
assert filter_primes([]) == []
def test_filter_primes_no_primes():
assert filter_primes([-10, -3, 0, 1, 4, 6, 8, 9, 10]) == []
def test_filter_primes_with_primes():
assert filter_primes([-10, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the input list.",
"function_declaration": "def fi... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
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 Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011293",
"row_id": 11293,
"seed_ids": "[3816]"
} | 0.6346 | Apps_11293 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5b1a9211aa3a632e21b7e3f1d910479d224cc915 | 10097d588a77fe789a3cc33e6244db27f71965d6 | |||
v1.0 | instruct | Apps | Apps_11300_I | Olivia loves solving puzzles. She has recently come across a new type of combinatorial puzzle involving numbers. In this puzzle, she is given an array of integers and a target value. Her goal is to find the number of ways to choose a pair of distinct elements from the array such that their product is equal to the targe... | def count_pairs_with_product(arr, target):
n = len(arr)
count = 0
for i in range(n):
for j in range(i + 1, n):
if arr[i] * arr[j] == target:
count += 1
return count
def solve(test_cases):
results = []
for n, target, arr in test_cases:
results.append(c... | def test_count_pairs_with_product():
assert count_pairs_with_product([1, 3, 4, 2], 12) == 1
assert count_pairs_with_product([5, 4, 2, 1, 10], 20) == 2
def test_parse_input():
input_data = "2\n4 12\n1 3 4 2\n5 20\n5 4 2 1 10"
expected_output = [(4, 12, [1, 3, 4, 2]), (5, 20, [5, 4, 2, 1, 10])]
asser... | [
{
"docstring": null,
"function_declaration": "def count_pairs_with_product(arr, target):",
"function_name": "count_pairs_with_product",
"parameter_list": "(arr, target)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter... | [
0,
1,
1,
1,
0,
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 count_pairs_with_product(arr, target):\n \"\"\"\n Returns the number of pairs (i, j) where 0 ≤ i < j < n and the product of elements at positions i and j ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00011300",
"row_id": 11300,
"seed_ids": "[1410]"
} | 0.705273 | Apps_11300 | I | [
"count_pairs_with_product",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"count_pairs_with_product"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | e021c27020a72a3867ca13d7faaa913ea633df62 | 540f370ff41a507d58e351311e06a4ca3c83990e | |||
v1.0 | instruct | Apps | Apps_11334_I | You are given an integer $N$. Print the $N \times N$ matrix where the elements of each row are the Fibonacci sequence starting from the next Fibonacci number after the last element of the previous row.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The de... | def generate_fibonacci(n):
"""Helper function to generate the first `n` Fibonacci numbers."""
fib = [0] * n
fib[0] = 1
if n > 1:
fib[1] = 1
for i in range(2, n):
fib[i] = fib[i - 1] + fib[i - 2]
return fib
def fibonacci_matrix(N):
"""Generates an N x N matrix filled with Fib... | import io
from contextlib import redirect_stdout
from solution import main
def test_main():
input_data = "2\n2\n3\n"
expected_output = "1 1\n2 3\n1 1 2\n3 5 8\n13 21 34\n"
with io.StringIO() as buf, redirect_stdout(buf):
main(input_data)
output = buf.getvalue()
assert output == expected... | [
{
"docstring": "Helper function to generate the first `n` Fibonacci numbers.",
"function_declaration": "def generate_fibonacci(n):",
"function_name": "generate_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Generates an N x N matrix filled with Fibonacci sequence in a row-wise \nmann... | [
0,
1,
0,
1,
1,
1,
1,
0,
0,
1
] | 6 | medium | 0.6 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_fibonacci_matrix(N):\n def fibonacci_sequence(length):\n fibs = [0] * length\n fibs[0], fibs[1] = 1, 1\n for i in range(2, leng... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011334",
"row_id": 11334,
"seed_ids": "[930]"
} | 0.664389 | Apps_11334 | I | [
"generate_fibonacci",
"fibonacci_matrix",
"print_fibonacci_matrices",
"main"
] | 4 | [
[
"fibonacci_matrix",
"generate_fibonacci"
],
[
"print_fibonacci_matrices",
"fibonacci_matrix"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e9479abd9187c7fe6900cd16f65a153cf2f39d83 | ff0cb90b64940f7d485cfc3b0d16cf46c826d8ff | |||
v1.0 | instruct | Apps | Apps_11453_I | A botanist has a large rectangular garden and wants to build the maximum number of square plots of the same size within it, to experiment with plant arrangements. She also wants to ensure that no space is wasted in the garden and that the side lengths of the square plots are integers. Help the botanist determine the si... | def gcd(a, b):
"""
Helper function to find the Greatest Common Divisor (GCD)
of two numbers using Euclid's algorithm.
"""
while b:
a, b = b, a % b
return a
def largest_square_plot(M, N):
"""
Determines the side length of the largest square plot and the total number
of such s... | from solution import largest_square_plot
def test_example_case():
side_length, num_plots = largest_square_plot(20, 15)
assert side_length == 5
assert num_plots == 12
def test_equal_dimensions():
side_length, num_plots = largest_square_plot(10, 10)
assert side_length == 10
assert num_plots == 1... | [
{
"docstring": "Helper function to find the Greatest Common Divisor (GCD)\nof two numbers using Euclid's algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Determines the side length of the largest square plot and the ... | [
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 largest_square_plot(M, N):\n \"\"\"\n Calculate the side length of the largest square plot and the number\n of such plots needed to fill the entire gar... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011453",
"row_id": 11453,
"seed_ids": "[1004]"
} | 0.613812 | Apps_11453 | I | [
"gcd",
"largest_square_plot"
] | 2 | [
[
"largest_square_plot",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f519a0fb789a1f80e02943e383f973f24f7daf3b | 1120963956e75560fef98b15590c3c1f8a7d40c4 | |||
v1.0 | instruct | Apps | Apps_11484_I | Arun loves solving mathematical puzzles and recently came across the concept of prime numbers. He is fascinated by their properties and wants to create a program that helps him identify prime numbers within a given range.
Write a program that reads an integer N and then prints all prime numbers from 1 to N in ascendin... | def is_prime(n):
"""
Checks if a number n is prime.
"""
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:
return False
i += 6
... | from solution import is_prime, prime_numbers_up_to_N
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
assert is_prime(1) == False
assert is_prime(0) =... | [
{
"docstring": "Checks if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers from 1 to N.",
"function_declaration": "def prime_numbers_up_to_N(N):",
"function_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 is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n re... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00011484",
"row_id": 11484,
"seed_ids": "[652]"
} | 0.65993 | Apps_11484 | I | [
"is_prime",
"prime_numbers_up_to_N"
] | 2 | [
[
"prime_numbers_up_to_N",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6883f5bebd842984df177fa9f8af3b46def5f24 | 12c354e195250ca14f28f47065bff7c5bcb9aa21 | |||
v1.0 | instruct | Apps | Apps_11501_I | Given an array of integers representing the amount of time tasks take to complete, and a positive integer k representing the number of workers available, distribute the tasks among the workers to minimize the maximum working time of any worker. Each worker can only work on sequential tasks from the list (i.e., tasks ca... | def canDistribute(tasks, k, mid):
current_worker = 1
current_time = 0
for task in tasks:
if current_time + task > mid:
current_worker += 1
current_time = task
if current_worker > k:
return False
else:
current_time += task
... | from solution import minimizeMaxWorkingTime
def test_example_1():
assert minimizeMaxWorkingTime([10, 20, 30, 40], 2) == 60
def test_example_2():
assert minimizeMaxWorkingTime([10, 20, 30], 2) == 30
def test_example_3():
assert minimizeMaxWorkingTime([10, 25, 40, 5], 3) == 40
def test_single_task():
... | [
{
"docstring": null,
"function_declaration": "def canDistribute(tasks, k, mid):",
"function_name": "canDistribute",
"parameter_list": "(tasks, k, mid)"
},
{
"docstring": null,
"function_declaration": "def minimizeMaxWorkingTime(tasks, k):",
"function_name": "minimizeMaxWorkingTime",
... | [
0,
1,
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 distribute_tasks(tasks, k):\n def is_valid(max_time):\n \"\"\"\n Helper function to check if it's possible to distribute tasks such that\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00011501",
"row_id": 11501,
"seed_ids": "[141]"
} | 0.746672 | Apps_11501 | I | [
"canDistribute",
"minimizeMaxWorkingTime"
] | 2 | [
[
"minimizeMaxWorkingTime",
"canDistribute"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e5b206f07eb988e4361ac720b1e9533e35a78548 | c6362c064c3f337256bf3f7baf39435af148ad47 | |||
v1.0 | instruct | Apps | Apps_11586_I | You are a developer for a toy company that develops toys using DIY kits. Your company has recently launched a new series of toys that are built using a series of connected components. Each component is represented by a node in a graph, and there's exactly one path (no cycles) between any two components, forming a tree ... | from collections import defaultdict, deque
def preprocess_lca_and_max_weights(n, weights, edges):
# Adjacency list of the tree
tree = defaultdict(list)
for u, v in edges:
tree[u-1].append(v-1)
tree[v-1].append(u-1)
# Depth and parent info
depth = [-1] * n
parent = [[-1] * n... | from solution import process_queries
def test_basic_case():
n = 5
weights = [10, 30, 50, 70, 90]
edges = [(1, 2), (2, 3), (2, 4), (4, 5)]
queries = ["M 1 3", "M 1 5", "M 4 5"]
expected = [50, 90, 90]
assert process_queries(n, weights, edges, queries) == expected
def test_single_query():
n ... | [
{
"docstring": null,
"function_declaration": "def preprocess_lca_and_max_weights(n, weights, edges):",
"function_name": "preprocess_lca_and_max_weights",
"parameter_list": "(n, weights, edges)"
},
{
"docstring": null,
"function_declaration": "def find_max_weight(x, y, depth, parent, max_... | [
0,
1,
0,
0,
1,
0,
1,
1,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport sys\n\nsys.setrecursionlimit(40000)\n\nclass Tree:\n def __init__(self, n, weights):\n self.n = n\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011586",
"row_id": 11586,
"seed_ids": "[1005]"
} | 0.713689 | Apps_11586 | I | [
"preprocess_lca_and_max_weights",
"find_max_weight",
"process_queries"
] | 3 | [
[
"process_queries",
"find_max_weight"
],
[
"process_queries",
"preprocess_lca_and_max_weights"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 3527030fd5fa107731de4037896e10cfec796777 | a4302f869ddf0b8b170b8c9948d0d710a47e284e | |||
v1.0 | instruct | Apps | Apps_11594_I | =====Function Descriptions=====
map()
The map() function applies a given function to each item of an iterable (like list) and returns a list of the results.
Code
>>> def square(x):
... return x * x
>>> map(square, [0, 1, 2, 3, 4])
[0, 1, 4, 9, 16]
filter()
The filter() function constructs an iterator from element... | def to_uppercase(word):
"""
Converts the word to uppercase.
"""
return word.upper()
def starts_with_vowel(word):
"""
Returns True if the word starts with a vowel, False otherwise.
"""
return word[0].lower() in 'aeiou'
def filter_and_transform_words(n, words):
"""
Filters words ... | from solution import filter_and_transform_words
def test_filter_and_transform_words_all_vowels():
assert filter_and_transform_words(5, ["apple", "orange", "umbrella", "eagle", "igloo"]) == "APPLE ORANGE UMBRELLA EAGLE IGLOO"
def test_filter_and_transform_words_no_vowels():
assert filter_and_transform_words(5,... | [
{
"docstring": "Converts the word to uppercase.",
"function_declaration": "def to_uppercase(word):",
"function_name": "to_uppercase",
"parameter_list": "(word)"
},
{
"docstring": "Returns True if the word starts with a vowel, False otherwise.",
"function_declaration": "def starts_with_vo... | [
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 filter_words_starting_with_vowel(words):\n vowels = {'a', 'e', 'i', 'o', 'u'}\n\n def starts_with_vowel(word):\n return word[0].lower() in vowels\n... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00011594",
"row_id": 11594,
"seed_ids": "[2567]"
} | 0.629493 | Apps_11594 | I | [
"to_uppercase",
"starts_with_vowel",
"filter_and_transform_words"
] | 3 | [
[
"filter_and_transform_words",
"starts_with_vowel"
],
[
"filter_and_transform_words",
"to_uppercase"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 924c396dfd9b171b2bd4a1c5f6284865232d43a5 | 477bab9b28c329e2a8d1e77d7b7c7a97ffd3540e | |||
v1.0 | instruct | Apps | Apps_11602_I | Given two positive integer lists a and b each containing `n` elements (`1 <= n <= 100`), determine if the product of the integers in the two lists are both prime numbers. If both products are prime, return `True`, otherwise return `False`.
## Example
```
a = [3, 7]
b = [5, 11]
product_a = 3 * 7 = 21
product_b = 5 * ... | from math import isqrt
def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == ... | from solution import is_prime, prime_products
def test_is_prime():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(4) is False
assert is_prime(17) is True
assert is_prime(1) is False
assert is_prime(0) is False
assert is_prime(18) is False
def test_prime_products_all_... | [
{
"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": "Given two lists of positive integers a and b, returns True if the product of the integers in eac... | [
1,
0,
0,
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": "def is_prime(number):\n \"\"\"\n Determines if a number is a prime number.\n \"\"\"\n if number <= 1:\n return False\n for i in range(2, int(n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011602",
"row_id": 11602,
"seed_ids": "[4576]"
} | 0.637777 | Apps_11602 | I | [
"is_prime",
"prime_products"
] | 2 | [
[
"prime_products",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d736fe087420bd48a0a20dc560f729a99f23208e | 51c8292aec54c382768e24a3c3370987d3ba1851 | |||
v1.0 | instruct | Apps | Apps_11603_I | You are working on a novel time-tracking application for freelancers that tracks the time they spend on various tasks throughout their workday. Users start a task by entering its name and mark it as complete once they're done. However, users often forget to log the exact number of hours they worked on each task, requir... | def round_half_hour(n):
"""
Rounds a number to the nearest half hour increment.
"""
return round(n * 2) / 2
def task_durations(historical_data, new_tasks):
"""
Returns the duration for each task based on historical data.
If the task exists in historical data, return the average of the past ... | from solution import task_durations
def test_task_durations_with_existing_tasks():
historical_data = {
"design": [2, 2.5, 3],
"coding": [4.5, 4, 5]
}
new_tasks = ["design", "coding"]
result = task_durations(historical_data, new_tasks)
assert result == [2.5, 4.5]
def test_task_durat... | [
{
"docstring": "Rounds a number to the nearest half hour increment.",
"function_declaration": "def round_half_hour(n):",
"function_name": "round_half_hour",
"parameter_list": "(n)"
},
{
"docstring": "Returns the duration for each task based on historical data.\nIf the task exists in historic... | [
1,
1,
0,
1,
1,
1,
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 round_to_nearest_half_hour(hours):\n \"\"\"\n Rounds the float hours to the nearest half-hour increment.\n \"\"\"\n return round(hours * 2) / 2\n\nd... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011603",
"row_id": 11603,
"seed_ids": "[4091]"
} | 0.606456 | Apps_11603 | I | [
"round_half_hour",
"task_durations"
] | 2 | [
[
"task_durations",
"round_half_hour"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed43729264f213135d4606f884676eb0bab3b5e0 | c83039a1e89b52ab4b10c5bf626f77b250e3e56c | |||
v1.0 | instruct | Apps | Apps_11668_I | In a kingdom far away, there are N towns connected by M bidirectional roads. The kingdom's ruler wants to ensure that the kingdom is well-connected, and that for any two towns, there is at most one unique path connecting them.
- Each town is uniquely identified by an integer from 1 to N.
- Each road directly connects... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
p... | def test_minimum_total_travel_cost():
# Test Case 1
N = 5
M = 6
roads = [
(1, 2, 3),
(1, 3, 1),
(3, 4, 2),
(3, 5, 4),
(4, 5, 5),
(2, 4, 6)
]
assert minimum_total_travel_cost(N, M, roads) == 10
# Test Case 2
N = 4
M = 5
roads = ... | [
{
"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,
1,
1,
0,
0,
0,
0
] | 3 | medium | 0.333 | {
"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 root_x = fi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011668",
"row_id": 11668,
"seed_ids": "[629]"
} | 0.741464 | Apps_11668 | I | [
"find",
"union",
"kruskal_min_spanning_tree",
"minimum_total_travel_cost"
] | 4 | [
[
"kruskal_min_spanning_tree",
"find"
],
[
"kruskal_min_spanning_tree",
"union"
],
[
"minimum_total_travel_cost",
"kruskal_min_spanning_tree"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 233fe4d52b87a8c353f6e453a5ce94a04e5b47c1 | 676d66128e85568ff266784e115f8ed059353952 | |||
v1.0 | instruct | Apps | Apps_11674_I | You are given an undirected graph with $N$ nodes and $M$ edges. Each edge connects two different nodes and has a positive integer weight. Your task is to compute the sum of the weights of the edges in the Minimum Spanning Tree (MST) of this graph.
-----Input:-----
- First line will contain two integers $N$ and $M$.
- ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] ... | import pytest
from solution import minimum_spanning_tree
def test_mst_example_case():
n, m = 4, 5
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 2),
(1, 3, 6)
]
assert minimum_spanning_tree(n, m, edges) == 9
def test_mst_single_node():
n, m = 1, 0
edg... | [
{
"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,
1,
0
] | 2 | medium | 0.333 | {
"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 parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(parent... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00011674",
"row_id": 11674,
"seed_ids": "[1219]"
} | 0.828198 | Apps_11674 | I | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 5707c40b0225a7641aa007b8de071622fc17980a | 2623f07e2ab83c3c3ae25114c77bdf0116426a3c | |||
v1.0 | instruct | Apps | Apps_11705_I | Write a function that takes a list of integers and returns a new list containing the elements of the original list sorted in non-decreasing order, without using any built-in sorting functions. You are required to implement the Merge Sort algorithm to accomplish this task. The function must have a clear structure and be... | def merge_sort(arr):
"""
Sorts an array in non-decreasing order using the merge sort algorithm
and removes any duplicate values from the final sorted array.
"""
if len(arr) <= 1:
return arr
# Divide the array into two halves
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])
... | from solution import merge_sort
def test_merge_sort_basic():
assert merge_sort([4, 2, 7, 3, 1, 5]) == [1, 2, 3, 4, 5, 7]
def test_merge_sort_with_duplicates():
assert merge_sort([4, 4, 2, 7, 2, 3, 1, 5, 4, 1]) == [1, 2, 3, 4, 5, 7]
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_... | [
{
"docstring": "Sorts an array in non-decreasing order using the merge sort algorithm\nand removes any duplicate values from the final sorted array.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted... | [
1,
1,
1,
1,
0,
1,
1,
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 merge_sort(array):\n if len(array) <= 1:\n return array\n\n mid = len(array) // 2\n left_half = merge_sort(array[:mid])\n right_half = merge_... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00011705",
"row_id": 11705,
"seed_ids": "[3244]"
} | 0.680081 | Apps_11705 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 89fd6c38ae97947bcee931c51e7e9a7e139e149c | 729bfb5e42c0c9133fc3d29b0f301644107b9cf0 | |||
v1.0 | instruct | Apps | Apps_11738_I | You are given a grid of size n x n where each cell contains either '.' (representing an empty cell) or '*' (representing a blocked cell). A piece can only move to an adjacent cell (up, down, left, right) if that cell is empty. You are tasked with finding the minimum number of moves required to travel from the top-left ... | from collections import deque
def bfs_minimum_moves(grid, n):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * n for _ in range(n)]
queue = deque([(0, 0, 0)]) # (row, col, distance)
while queue:
r, c, dist = queue.popleft()
if r == n - 1 and c == n - 1:
... | import pytest
from solution import solve, parse_input
def test_example_case_1():
input_data = "2\n3\n...\n.*.\n...\n3\n*..\n.*.\n...\n"
t, test_cases = parse_input(input_data)
assert solve(t, test_cases) == [4, -1]
def test_impossible_start():
input_data = "1\n2\n*.\n..\n"
t, test_cases = parse_in... | [
{
"docstring": null,
"function_declaration": "def bfs_minimum_moves(grid, n):",
"function_name": "bfs_minimum_moves",
"parameter_list": "(grid, n)"
},
{
"docstring": null,
"function_declaration": "def solve(t, test_cases):",
"function_name": "solve",
"parameter_list": "(t, test_c... | [
0,
0,
1,
0,
0,
1,
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": "from collections import deque\n\ndef min_moves(t, test_cases):\n results = []\n \n for i in range(t):\n n, grid = test_cases[i]\n if grid[0][... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011738",
"row_id": 11738,
"seed_ids": "[2384]"
} | 0.824252 | Apps_11738 | I | [
"bfs_minimum_moves",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"bfs_minimum_moves"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | b52bfbb13d5078493acf682bff8690ac615cbed7 | 6eed5e4dadb72cc311830f7fa93ed831c1d46884 | |||
v1.0 | instruct | Apps | Apps_11769_I | A courier company operates in a city constructed as a hexagonal grid with unique intersections and roads. Each intersection is represented by a node and each road is an edge connecting two nodes. The city is designed in a way that each intersection connects to exactly three other intersections, resembling a perfect hex... | from collections import deque, defaultdict
def find_farthest_node(edges, start_node):
farthest_node = start_node
max_distance = 0
queue = deque([(start_node, 0)])
visited = set()
visited.add(start_node)
while queue:
current_node, distance = queue.popleft()
if distance > max... | def test_longest_path_length():
# Sample test case
assert longest_path_length(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == 4
# Single node graph
assert longest_path_length(1, []) == 0
# Two nodes graph (simplest tree)
assert longest_path_length(2, [(1, 2)]) == 1
# Linea... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(edges, start_node):",
"function_name": "find_farthest_node",
"parameter_list": "(edges, start_node)"
},
{
"docstring": null,
"function_declaration": "def longest_path_length(n, connections):",
"function_name": "long... | [
0,
1,
0,
1,
0,
0,
0,
0,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef longest_path_length(N, edges):\n def bfs(start_node):\n distance = [-1] * (N + 1)\n queue = deque... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011769",
"row_id": 11769,
"seed_ids": "[824]"
} | 0.737032 | Apps_11769 | I | [
"find_farthest_node",
"longest_path_length"
] | 2 | [
[
"longest_path_length",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 53d662f5feb41c0852d80b1ca70d985b202973b3 | dbdcd99689145cec4fb8b93d737e5c351f8d233b | |||
v1.0 | instruct | Apps | Apps_11804_I | In the bustling town of Numbertown, there's an annual festival called the Number Carnival where various puzzle contests are held. One of the most anticipated contests is the **"Prime Pathways"** game.
The game takes place on a large checkerboard where each cell contains a positive integer. The objective is to find a ... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num < 2:
return False
if num == 2:
return True
if num % 2 == 0:
return False
sqr = int(num ** 0.5) + 1
for div in range(3, sqr, 2):
if num % div == 0:
return False
return Tr... | import pytest
from solution import prime_pathways
def test_example_case():
board = [
[5, 4, 7],
[13, 11, 9],
[6, 2, 3]
]
assert prime_pathways(3, 3, board) == "YES"
def test_no_path():
board = [
[4, 4, 8],
[6, 10, 15],
[9, 8, 4]
]
assert prime_pa... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines if there is a path from the top-left to the bottom-right on the checkerboard\ncontaining only prime number... | [
0,
1,
1,
1,
1,
1,
0,
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 is_prime(n):\n \"\"\"\n Checks if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00011804",
"row_id": 11804,
"seed_ids": "[601]"
} | 0.581638 | Apps_11804 | I | [
"is_prime",
"find_prime_path",
"prime_pathways"
] | 3 | [
[
"find_prime_path",
"is_prime"
],
[
"prime_pathways",
"find_prime_path"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a6fc8d53aeb92c0fd06df6a0c44dba990683a5a1 | 2be5ffc9e0369c3d47a2a17e527eda262ba3428d | |||
v1.0 | instruct | Apps | Apps_11815_I | -----Problem Statement-----
Write a program that reads a list of integers and outputs the maximum value in the list.
-----Input-----
The first line contains an integer, t, the number of test cases. The next t lines each contain a sequence of space-separated integers representing a list of integers. Each list will have... | def find_max_values(test_cases):
"""
Returns a list of maximum values for each input list of integers.
:param test_cases: list of lists, where each inner list is a sequence of integers
:return: list of maximum integers for each input list
"""
return [max(test_case) for test_case in test_cas... | from io import StringIO
from solution import find_max_values, parse_input, process_input_outputs
import pytest
def test_find_max_values():
assert find_max_values([[1, 2, 3, 4, 5], [-10, -20, -30, -40, -50]]) == [5, -10]
assert find_max_values([[5], [-5], [0]]) == [5, -5, 0]
assert find_max_values([[1000, -... | [
{
"docstring": "Returns a list of maximum values for each input list of integers.\n\n:param test_cases: list of lists, where each inner list is a sequence of integers\n:return: list of maximum integers for each input list",
"function_declaration": "def find_max_values(test_cases):",
"function_name": "fi... | [
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 find_max_in_lists(list_of_lists):\n \"\"\"\n Given a list of lists of integers, return a list of the maximum values for each list.\n :param list_of_lis... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011815",
"row_id": 11815,
"seed_ids": "[683]"
} | 0.73702 | Apps_11815 | I | [
"find_max_values",
"parse_input",
"process_input_outputs"
] | 3 | [
[
"process_input_outputs",
"find_max_values"
],
[
"process_input_outputs",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 77a285202a83fa30964fffbcb165b37c00927007 | 80577fd16a36f444aa2463b88423bda2a73e1b5a | |||
v1.0 | instruct | Apps | Apps_11859_I | You are given an array of integers. Your task is to find the maximum length of any subsequence in the array that is strictly increasing, and then the maximum length of any subsequence in the array that is strictly decreasing. You will then compute the difference between these two lengths.
A subsequence is a sequence t... | def lis_length(arr):
"""
Function to return the length of the longest increasing subsequence.
"""
if not arr:
return 0
n = len(arr)
lis = [1] * n
for i in range(1, n):
for j in range(i):
if arr[i] > arr[j]:
lis[i] = max(lis[i], lis[j] + 1)
retu... | def test_lis_length():
assert lis_length([5, 3, 4, 8, 6]) == 3
assert lis_length([7, 7, 7]) == 1
assert lis_length([1, 2, 3, 4, 5]) == 5
assert lis_length([5, 4, 3, 2, 1]) == 1
assert lis_length([1]) == 1
assert lis_length([]) == 0
def test_lds_length():
assert lds_length([5, 3, 4, 8, 6]) =... | [
{
"docstring": "Function to return the length of the longest increasing subsequence.",
"function_declaration": "def lis_length(arr):",
"function_name": "lis_length",
"parameter_list": "(arr)"
},
{
"docstring": "Function to return the length of the longest decreasing subsequence.",
"funct... | [
0,
1,
0,
0,
1,
1,
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 length_of_LIS(nums):\n if not nums:\n return 0\n dp = [1] * len(nums)\n for i in range(1, len(nums)):\n for j in range(i):\n i... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011859",
"row_id": 11859,
"seed_ids": "[2158]"
} | 0.851466 | Apps_11859 | I | [
"lis_length",
"lds_length",
"difference_lis_lds"
] | 3 | [
[
"difference_lis_lds",
"lds_length"
],
[
"difference_lis_lds",
"lis_length"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 06bd92d41f97d28affa03aeb4a2f124cfef124c2 | 3ca27792d20d33d8cd78a0efe5f96622fadd87aa | |||
v1.0 | instruct | Apps | Apps_11864_I | In a city park, there are n benches arranged in a straight line. Each bench has a particular number of seats. A group of friends has decided to sit on these benches. The friends want to sit in such a way that no two friends are seated on the same bench. However, the friends have certain preferences: they either prefer ... | def max_seats_close_together(n, k, seats):
max_sum = 0
for i in range(n - k + 1):
max_sum = max(max_sum, sum(seats[i:i + k]))
return max_sum
def can_place_friends(seats, n, k, min_dist):
count = 1
last_pos = seats[0]
for i in range(1, n):
if seats[i] - last_pos >= min_dist:
... | from solution import friends_on_benches
def test_separate_friends():
test_cases = [
(7, 3, [4, 5, 3, 2, 8, 6, 7], 0),
(6, 2, [10, 20, 30, 40, 50, 60], 1)
]
assert friends_on_benches(2, test_cases) == [21, 50]
def test_close_together_basic():
test_cases = [
(3, 2, [1, 2, 3], 0)
... | [
{
"docstring": null,
"function_declaration": "def max_seats_close_together(n, k, seats):",
"function_name": "max_seats_close_together",
"parameter_list": "(n, k, seats)"
},
{
"docstring": null,
"function_declaration": "def can_place_friends(seats, n, k, min_dist):",
"function_name": ... | [
0,
1,
0,
0,
0,
0,
0,
1,
1,
1
] | 4 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_seats_or_distance(test_cases):\n results = []\n \n for n, k, seats, p in test_cases:\n if p == 0:\n # Friends prefer to sit close... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00011864",
"row_id": 11864,
"seed_ids": "[1671]"
} | 0.640259 | Apps_11864 | I | [
"max_seats_close_together",
"can_place_friends",
"max_distance_spread_out",
"friends_on_benches"
] | 4 | [
[
"friends_on_benches",
"max_distance_spread_out"
],
[
"friends_on_benches",
"max_seats_close_together"
],
[
"max_distance_spread_out",
"can_place_friends"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 143dd3c659870bc86c8a8109c49be171e0cde3fc | a09f3b6e47f05e09402831690e340fe9cae64aa0 | |||
v1.0 | instruct | Apps | Apps_11897_I | Write a function `find_kth_smallest(nums, k)` that takes a list of unique integers `nums` and an integer `k`, and returns the k-th smallest number in the list.
To make it more challenging, do not sort the entire list. Instead, implement an efficient algorithm (such as Quickselect) to find the k-th smallest number in e... | def partition(arr, left, right, pivot_index):
pivot_value = arr[pivot_index]
arr[pivot_index], arr[right] = arr[right], arr[pivot_index]
store_index = left
for i in range(left, right):
if arr[i] < pivot_value:
arr[store_index], arr[i] = arr[i], arr[store_index]
store_ind... | from solution import find_kth_smallest
def test_kth_smallest_positive_numbers():
assert find_kth_smallest([3, 1, 2, 5, 4], 2) == 2
def test_kth_smallest_first_element():
assert find_kth_smallest([9, 8, 7, 6, 5, 4, 3, 2, 1], 1) == 1
def test_kth_smallest_mixed_numbers():
assert find_kth_smallest([10, 20, ... | [
{
"docstring": null,
"function_declaration": "def partition(arr, left, right, pivot_index):",
"function_name": "partition",
"parameter_list": "(arr, left, right, pivot_index)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, left, right, k):",
"function_name": "q... | [
1,
1,
0,
1,
1,
1,
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": "import random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] < pivot:\n arr[i],... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011897",
"row_id": 11897,
"seed_ids": "[4900]"
} | 0.659411 | Apps_11897 | I | [
"partition",
"quickselect",
"find_kth_smallest"
] | 3 | [
[
"find_kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 75805a01880a0f3f8f87a2eae46991f65ebd2909 | d60547cf69363093f202a39c0a8e531e1de7a197 | |||
v1.0 | instruct | Apps | Apps_11903_I | Challenge:
Write a function that takes a list of integers and returns a new list that contains all the prime numbers from the original list, in the same order they appeared. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Consider the range of integers to be within 0 to... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import filter_primes
def test_filter_primes_all_primes():
assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11]
def test_filter_primes_no_primes():
assert filter_primes([4, 6, 8, 9, 10]) == []
def test_filter_primes_mixed_numbers():
assert filter_primes([15, 3, 11, 20, 17, 4, 1, 2, 19]... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list containing all prime numbers from the input list.",
"function_declaration": "def filter_primes(int_list):",... | [
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": "00011903",
"row_id": 11903,
"seed_ids": "[3677]"
} | 0.631303 | Apps_11903 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b963366d16c58b60a5d4fd3e68c3f9180cc8bec | e621337c00ed8152a4b20f959970a1f6c9ed54f7 | |||
v1.0 | instruct | Apps | Apps_11917_I | Matrix Diagonal Difference
In a given square matrix, the absolute difference between the sums of its diagonals is essential. A square matrix is a matrix with equal number of rows and columns. The task is to calculate the absolute difference between the sums of its principal diagonal and secondary diagonal.
The princi... | def diagonal_difference(matrix):
"""
Calculate the absolute difference between the sums of the principal and secondary diagonals of a square matrix.
:param matrix: List[List[int]]
:return: int
"""
n = len(matrix)
primary_diagonal_sum = sum(matrix[i][i] for i in range(n))
secondary_diago... | from solution import diagonal_difference, compute_differences, parse_input
def test_diagonal_difference():
matrix = [
[11, 2, 4],
[4, 5, 6],
[10, 8, -12]
]
assert diagonal_difference(matrix) == 15
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
... | [
{
"docstring": "Calculate the absolute difference between the sums of the principal and secondary diagonals of a square matrix.\n\n:param matrix: List[List[int]]\n:return: int",
"function_declaration": "def diagonal_difference(matrix):",
"function_name": "diagonal_difference",
"parameter_list": "(ma... | [
1,
0,
1,
0,
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": "def matrix_diagonal_difference(test_cases):\n results = []\n for case in test_cases:\n N, matrix = case\n primary_diagonal_sum = sum(matrix[i][i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00011917",
"row_id": 11917,
"seed_ids": "[1060]"
} | 0.603525 | Apps_11917 | I | [
"diagonal_difference",
"compute_differences",
"parse_input"
] | 3 | [
[
"compute_differences",
"diagonal_difference"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f22feb07faef82ea0feba6468dc50c2b9e3a926c | e2532be2c374aa09f3e3b39536ed09a9e7e937b7 | |||
v1.0 | instruct | Apps | Apps_11919_I | You are given an undirected graph with N vertices and M edges. Each vertex represents a city, and each edge represents a bidirectional road between two cities. Some of these edges have already been constructed, while others need to be constructed. Building a new road between two cities incurs a certain cost. Your task ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] ... | from solution import minimum_cost_to_connect_all_cities
def test_minimum_cost_basic():
edges = [[1, 2, 3],
[2, 3, 2],
[3, 4, 4],
[4, 1, 1],
[1, 3, 0]]
assert minimum_cost_to_connect_all_cities(4, 5, edges) == 3
def test_minimum_cost_already_connected():
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0,
0,
1,
1,
0,
1
] | 5 | medium | 0.625 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def find_minimum_cost_to_connect_cities(N, M, edges):\n \"\"\"\n Determines the minimum cost required to connect all cities.\n \n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00011919",
"row_id": 11919,
"seed_ids": "[1362]"
} | 0.789967 | Apps_11919 | I | [
"find",
"union",
"minimum_cost_to_connect_all_cities"
] | 3 | [
[
"minimum_cost_to_connect_all_cities",
"find"
],
[
"minimum_cost_to_connect_all_cities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1ac5cb8e258f208ec9f6ccdf7ac4d35b1084deca | 9c02fea612174f05e845a6e64aac4855412995ba | |||
v1.0 | instruct | Apps | Apps_11963_I | A function receives a matrix ```m x n``` (m rows and n columns) with integers. The function should calculate the largest rectangle area containing only 1's in the matrix and return its area.
The order that the function receives its arguments is:
```python
largest_rectangle(matrix)
```
## Examples
```python
matrix = ... | def largest_rectangle(matrix):
if not matrix or not matrix[0]:
return 0
max_area = 0
n = len(matrix[0])
heights = [0] * n
for row in matrix:
for i in range(n):
heights[i] = heights[i] + 1 if row[i] == 1 else 0
max_area = max(max_area, max_histogram_area(heights)... | from solution import largest_rectangle
def test_small_matrix():
matrix = [
[1, 0],
[1, 1]
]
assert largest_rectangle(matrix) == 2
def test_single_row():
matrix = [
[1, 0, 1, 1, 1]
]
assert largest_rectangle(matrix) == 3
def test_single_column():
matrix = [
... | [
{
"docstring": null,
"function_declaration": "def largest_rectangle(matrix):",
"function_name": "largest_rectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_... | [
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 largest_rectangle(matrix):\n def max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(his... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00011963",
"row_id": 11963,
"seed_ids": "[3260]"
} | 0.70656 | Apps_11963 | I | [
"largest_rectangle",
"max_histogram_area"
] | 2 | [
[
"largest_rectangle",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc7d87c3b4439ab28e9d7feee7436b6998359b12 | 2ddac387cac45ec2b7cd8d1a4357ef5da0e2e8f2 | |||
v1.0 | instruct | Apps | Apps_11969_I | Design a function that takes an integer `n` and returns the smallest number of trailing zeros in the factorial of any number greater than or equal to `n`.
Let's define the number of trailing zeros in the factorial of a number. For example, `5! = 120` has `1` trailing zero and `10! = 3628800` has `2` trailing zeros.
T... | def trailing_zeros(x):
"""
Helper function that calculates the number of trailing zeros in x factorial.
"""
count = 0
while x >= 5:
x //= 5
count += x
return count
def smallest_trailing_zeros(n: int) -> int:
"""
Returns the smallest number of trailing zeros in the factor... | from solution import smallest_trailing_zeros
def test_smallest_trailing_zeros_5():
assert smallest_trailing_zeros(5) == 1
def test_smallest_trailing_zeros_10():
assert smallest_trailing_zeros(10) == 2
def test_smallest_trailing_zeros_25():
assert smallest_trailing_zeros(25) == 6
def test_smallest_traili... | [
{
"docstring": "Helper function that calculates the number of trailing zeros in x factorial.",
"function_declaration": "def trailing_zeros(x):",
"function_name": "trailing_zeros",
"parameter_list": "(x)"
},
{
"docstring": "Returns the smallest number of trailing zeros in the factorial of any... | [
0,
0,
1,
0,
1,
1,
0,
0,
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 count_trailing_zeros(x):\n \"\"\"\n A helper function that calculates the number of trailing zeros in the factorial of x.\n \"\"\"\n count = 0\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00011969",
"row_id": 11969,
"seed_ids": "[4166]"
} | 0.666153 | Apps_11969 | I | [
"trailing_zeros",
"smallest_trailing_zeros"
] | 2 | [
[
"smallest_trailing_zeros",
"trailing_zeros"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 11c19f117cebe98597d7d24a4b2b41a55f5046c0 | edbd80b577068ee1264f584e4208e31994ff9aaf | |||
v1.0 | instruct | Apps | Apps_12015_I | Write a function in Python that takes a list of integers and returns a dictionary where the keys are the integers from the list and the values are the corresponding Fibonacci numbers. Ensure that the integers in the input list are non-negative. If the input list contains any negative integers, your function should rais... | def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
if n == 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for _ in range(2, n+1):
a, b = b, a + b
return b
def list_to_fibonacci_dict(lst):
"""
Given a list of non-negative integers, returns a d... | def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
def test_list_to_fibonacci_dict():
assert list_to_fibonacci_dict([0, 1, 2, 3, 4]) == {0: 0, 1: 1, 2: 1, 3: 2, 4: 3}
... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of non-negative integers, returns a dictionary where the keys are the integers\nand the values are the corres... | [
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 fibonacci(n):\n if n < 0:\n raise ValueError(\"Input list contains negative integers\")\n elif n == 0:\n return 0\n elif n == 1:\n ... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012015",
"row_id": 12015,
"seed_ids": "[3622]"
} | 0.70564 | Apps_12015 | I | [
"fibonacci",
"list_to_fibonacci_dict"
] | 2 | [
[
"list_to_fibonacci_dict",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 23bac8e91c93864a9f6f8f8ed0f346017e0a84d4 | 5d5594a3c001b651a711efedb2331970d5d29a9f | |||
v1.0 | instruct | Apps | Apps_12038_I | In a galaxy far, far away, a fleet of spaceships need to communicate with each other while traveling through space. Each spaceship is located at a point on a 2D Cartesian plane, and they transmit signals that can be received within a certain radius. You are tasked with determining the total number of unique communicati... | def can_communicate(x1, y1, r1, x2, y2, r2):
"""
Determines if two spaceships can communicate based on their coordinates and transmission radii.
"""
distance_squared = (x1 - x2)**2 + (y1 - y2)**2
return distance_squared <= (r1 + r2)**2
def count_communication_pairs(test_cases):
results = []
... | def test_count_communication_pairs():
test_cases = [
(
3,
[(0, 0, 1), (2, 2, 2), (1, 1, 2)]
),
(
4,
[(1, 2, 2), (2, 1, 2), (3, 3, 1), (6, 6, 5)]
)
]
result = count_communication_pairs(test_cases)
assert result == [... | [
{
"docstring": "Determines if two spaceships can communicate based on their coordinates and transmission radii.",
"function_declaration": "def can_communicate(x1, y1, r1, x2, y2, r2):",
"function_name": "can_communicate",
"parameter_list": "(x1, y1, r1, x2, y2, r2)"
},
{
"docstring": null,
... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef count_communication_pairs(t, test_cases):\n def can_communicate(ship1, ship2):\n x1, y1, r1 = ship1\n x2, y2, r2 = ship2\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00012038",
"row_id": 12038,
"seed_ids": "[101]"
} | 0.619572 | Apps_12038 | I | [
"can_communicate",
"count_communication_pairs"
] | 2 | [
[
"count_communication_pairs",
"can_communicate"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 29af98ef65835299165df1b24a341fedb4842365 | c2c264041d83cc500f4504a4b754677ad4e027a1 | |||
v1.0 | instruct | Apps | Apps_12053_I | Alice is participating in a coding competition, and she loves palindromic numbers. A number is a palindrome if it reads the same backward as forward. Alice is interested in finding out how many palindromic numbers exist within a specified range from $A$ to $B$ (both inclusive). Can you assist her in determining the cou... | def is_palindrome(num):
"""
Returns True if num is a palindrome, False otherwise.
"""
return str(num) == str(num)[::-1]
def count_palindromes(A, B):
"""
Returns the count of palindromic numbers between A and B (inclusive).
"""
count = 0
for i in range(A, B + 1):
if is_palind... | from solution import is_palindrome, count_palindromes, process_test_cases
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
assert is_palindrome(10) == False
def test_count_palindromes():
... | [
{
"docstring": "Returns True if num is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Returns the count of palindromic numbers between A and B (inclusive).",
"function_decl... | [
0,
0,
0,
0,
0,
1,
0,
0,
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 count_palindromic_numbers(a, b):\n \"\"\"\n Returns the number of palindromic numbers between a and b inclusive.\n \"\"\"\n def is_palindrome(n):\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00012053",
"row_id": 12053,
"seed_ids": "[1259]"
} | 0.710684 | Apps_12053 | I | [
"is_palindrome",
"count_palindromes",
"process_test_cases"
] | 3 | [
[
"count_palindromes",
"is_palindrome"
],
[
"process_test_cases",
"count_palindromes"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 9f8793b27ab459d8af409db5628e5c4f6a9bbbae | 80483547ab915ccdf195d740aec1c8d555ef434a | |||
v1.0 | instruct | Apps | Apps_12113_I | Create a function that simulates a simple voting system for an election with multiple candidates. Given an array of strings where each string represents a vote for a candidate, return a dictionary with each candidate's name as a key and their corresponding vote count as the value. If two or more candidates have the sam... | def tally_votes(votes):
"""
Given a list of votes, return a dictionary with each candidate's vote tally.
If the input list is empty, return an empty dictionary.
"""
tally = {}
for vote in votes:
if vote in tally:
tally[vote] += 1
else:
tally[vote] = 1
... | from solution import tally_votes, get_winner
def test_tally_votes_basic():
votes = ["Alice", "Bob", "Alice", "Eve", "Bob", "Alice"]
expected = {'Alice': 3, 'Bob': 2, 'Eve': 1}
assert tally_votes(votes) == expected
def test_tally_votes_empty():
votes = []
expected = {}
assert tally_votes(votes)... | [
{
"docstring": "Given a list of votes, return a dictionary with each candidate's vote tally.\nIf the input list is empty, return an empty dictionary.",
"function_declaration": "def tally_votes(votes):",
"function_name": "tally_votes",
"parameter_list": "(votes)"
},
{
"docstring": "Given a li... | [
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 voting_system(votes):\n \"\"\"\n Simulates a simple voting system for an election with multiple candidates.\n \n Parameters:\n votes (list of str... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012113",
"row_id": 12113,
"seed_ids": "[4277]"
} | 0.660721 | Apps_12113 | I | [
"tally_votes",
"get_winner"
] | 2 | [
[
"get_winner",
"tally_votes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 270a1f6ed322073c99c0c6e142022ae482a7b6af | 8a389f3df6f543dd18bf6f6b60ce030e9d65ebb0 | |||
v1.0 | instruct | Apps | Apps_12140_I | Write a function that takes an integer `n` and returns a list of the first `n` prime numbers.
For example, the first prime number is 2, the second is 3, the third is 5, and so on.
```
Note:
- 1 <= n <= 10**5
``` | def is_prime(num):
"""
Helper function to check if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
... | from solution import first_n_primes
def test_first_prime():
assert first_n_primes(1) == [2]
def test_first_two_primes():
assert first_n_primes(2) == [2, 3]
def test_first_five_primes():
assert first_n_primes(5) == [2, 3, 5, 7, 11]
def test_first_ten_primes():
assert first_n_primes(10) == [2, 3, 5, 7... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of the first n prime numbers.",
"function_declaration": "def first_n_primes(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 is_prime(num):\n \"\"\"\n Helper function to check if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00012140",
"row_id": 12140,
"seed_ids": "[4623]"
} | 0.750431 | Apps_12140 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 41b99d6eca564c96f9a0f12ca7700184714935e3 | 4d05a2a0a735a659d06a1c7fd65cfc4ff235f3a1 | |||
v1.0 | instruct | Apps | Apps_12190_I | The annual code-fest hosts a unique challenge where participants are required to solve a puzzle with a series of constraints. You are part of this exciting event and have taken upon yourself to tackle one of the tougher challenges. In this challenge, you are given an array of integers, and you need to find the sum of e... | def sum_of_divisibles(test_cases):
results = []
for case in test_cases:
N, D, array = case
total_sum = sum(x for x in array if x % D == 0)
results.append(total_sum)
return results
def parse_input(input_data):
lines = input_data.strip().split('\n')
T = int(lines[0])
test_... | def test_sum_of_divisibles():
input_data = "3\n5 2\n1 2 3 4 5\n4 5\n10 25 30 40\n6 3\n5 9 18 27 36 8"
expected_output = "6\n105\n90"
assert solve_codefest_problem(input_data) == expected_output
def test_single_element():
input_data = "2\n1 2\n4\n1 5\n5"
expected_output = "4\n5"
assert solve_cod... | [
{
"docstring": null,
"function_declaration": "def sum_of_divisibles(test_cases):",
"function_name": "sum_of_divisibles",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"parameter_lis... | [
1,
1,
0,
1,
1,
1,
1,
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 sum_divisible_by_d(test_cases):\n results = []\n for case in test_cases:\n N, D = case[0]\n array = case[1]\n total_sum = 0\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00012190",
"row_id": 12190,
"seed_ids": "[975]"
} | 0.668553 | Apps_12190 | I | [
"sum_of_divisibles",
"parse_input",
"format_output",
"solve_codefest_problem"
] | 4 | [
[
"solve_codefest_problem",
"format_output"
],
[
"solve_codefest_problem",
"parse_input"
],
[
"solve_codefest_problem",
"sum_of_divisibles"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | 464768de390d495a4fb7b46d9918e8ea1adf9479 | 1c95ed424493c14d120f2c90d10358615a2ab08e | |||
v1.0 | instruct | Apps | Apps_12199_I | Write a function that takes in a list of strings and returns a new list containing only those strings which are palindromes. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).
```
["level", "world", "deifi... | import re
def is_palindrome(s):
"""
Check if the given string s is a palindrome, ignoring case and non-alphanumeric characters.
"""
# Remove non-alphanumeric characters and convert to lowercase
cleaned = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
return cleaned == cleaned[::-1]
def filter_palindro... | from solution import filter_palindromes
def test_filter_palindromes_all_palindromes():
assert filter_palindromes(["level", "deified", "civic"]) == ["level", "deified", "civic"]
def test_filter_palindromes_mixed():
assert filter_palindromes(["level", "world", "deified", "hello", "civic"]) == ["level", "deified... | [
{
"docstring": "Check if the given string s is a palindrome, ignoring case and non-alphanumeric characters.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Filters a list of strings, returning only those which ar... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
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 is_palindrome(s):\n stripped = re.sub(r'[^a-zA-Z0-9]', '', s).lower()\n return stripped == stripped[::-1]\n\ndef filter_palindromes(strings):... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012199",
"row_id": 12199,
"seed_ids": "[4158]"
} | 0.734475 | Apps_12199 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45c2088f898ab10c6d12760584bd67a334a79039 | b6dc44da4c80758bd67266bd507c3c9b3aaf62a6 | |||
v1.0 | instruct | Apps | Apps_12211_I | You are given a rectangular grid of size `m x n` where each cell can either be `0` (empty) or `1` (blocked). Your task is to determine the number of distinct paths from the top-left corner to the bottom-right corner, moving only right or down, using Dynamic Programming.
You will solve this problem using both Brute For... | def brute_force_paths(grid, m, n, i=0, j=0):
"""
Recursively count the number of distinct paths in the grid using brute force.
"""
# If out of bounds or blocked cell
if i >= m or j >= n or grid[i][j] == 1:
return 0
# If we reached the bottom-right corner
if i == m-1 and j == n-1:
... | import pytest
from solution import brute_force_paths, dp_paths, count_paths
def test_sample_case():
test_cases = [
([[0, 0, 0], [0, 1, 0], [0, 0, 0]], 3, 3)
]
results = count_paths(test_cases)
assert results == [(2, 2)]
def test_blocked_start():
test_cases = [
([[1, 0, 0], [0, 1, 0... | [
{
"docstring": "Recursively count the number of distinct paths in the grid using brute force.",
"function_declaration": "def brute_force_paths(grid, m, n, i=0, j=0):",
"function_name": "brute_force_paths",
"parameter_list": "(grid, m, n, i=0, j=0)"
},
{
"docstring": "Use dynamic programming ... | [
1,
1,
0,
1,
0,
1,
0,
0,
0,
1
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_paths_brute_force(grid, m, n, i=0, j=0, memo=None):\n if memo is None:\n memo = {}\n \n if i >= m or j >= n or grid[i][j] == 1:\n ... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00012211",
"row_id": 12211,
"seed_ids": "[1183]"
} | 0.752414 | Apps_12211 | I | [
"brute_force_paths",
"dp_paths",
"count_paths"
] | 3 | [
[
"count_paths",
"brute_force_paths"
],
[
"count_paths",
"dp_paths"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b5eadf2c5a7563d1a3ee522bec2ee3171c799846 | 3166d32fcd238acf43df808798c4e45ac5ce017a | |||
v1.0 | instruct | Apps | Apps_12215_I | Write a function that takes a list of integers as an input and returns a list of objects. Each object should have two keys: "number", which is the integer from the list, and "is_prime", which is a boolean indicating whether the integer is a prime number. The output list should maintain the order of the input list. The ... | def is_prime(n):
"""Helper function to determine if a number n is prime."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def list_to_prime_obj... | from solution import list_to_prime_objects
def test_list_with_prime_and_non_prime_numbers():
input_data = [2, 3, 4, 5, 6, 7, 8, 9, 10]
expected_output = [
{"number": 2, "is_prime": True},
{"number": 3, "is_prime": True},
{"number": 4, "is_prime": False},
{"number": 5, "is_prime"... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Converts a list of integers into a list of objects\nwith the integer and its prime status.\n\n:param lst:... | [
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 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_5 | {
"original_instruction": "",
"prompt_id": "00012215",
"row_id": 12215,
"seed_ids": "[4644]"
} | 0.677934 | Apps_12215 | I | [
"is_prime",
"list_to_prime_objects"
] | 2 | [
[
"list_to_prime_objects",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab482716f7191852ec05f10e9f13c8e99daf4980 | 30925426893e744b2a7f0283e4de399af03bf16b | |||
v1.0 | instruct | Apps | Apps_12219_I | =====Function Descriptions=====
is_prime(n)
Returns True if the integer n is a prime number, otherwise returns False.
Code
>>> def is_prime(n):
... if n <= 1:
... return False
... for i in range(2, int(n ** 0.5) + 1):
... if n % i == 0:
... return False
... return True
>>> is_... | def is_prime(n):
"""
Returns True if the integer n is a prime number, otherwise returns False.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def prime_status_list(num_list):
"""
Given a list of integ... | from solution import is_prime, prime_status_list
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(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
def test_prime_status_list... | [
{
"docstring": "Returns True if the integer n is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of integers, returns a dictionary where each key is an integer from \nt... | [
1,
1,
1,
1,
1,
1,
1,
1,
1
] | 9 | easy | 1 | {
"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 \"\"\"\n Returns True if the integer n is a prime number, otherwise returns False.\n \"\"\"\n if n <= 1:\n ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00012219",
"row_id": 12219,
"seed_ids": "[2586]"
} | 0.781659 | Apps_12219 | I | [
"is_prime",
"prime_status_list"
] | 2 | [
[
"prime_status_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d24132c4632b59a815da2b8fbe77995f123595c | 35aa82b698383137354ee40240a9edf007456595 | |||
v1.0 | instruct | Apps | Apps_12249_I | In a faraway kingdom, there exist N cities connected by M roads. The ruler of the kingdom wants to create a special event where a selected city will be visited by exactly K guards. Each road is bidirectional and it takes 1 hour to travel from one city to another using any of the roads.
There are P queries to determine... | from collections import deque
import sys
def shortest_time_for_guards_to_gather(N, M, graph, K, starts):
# Initialize distance matrix
inf = sys.maxsize
dist = [[inf] * N for _ in range(N)]
# Update the distances using BFS
for i in range(N):
dist[i][i] = 0
q = deque([i])
... | def test_shortest_time_for_guards_to_gather():
input_data = '''1
4 4 2
1 2
2 3
3 4
4 1
3
1 3
2 4
1 2'''
expected_output = '''1
1
1'''
results = find_min_time_for_guards_gathering(input_data)
assert results == expected_output
def test_case_with_only_two_cities():
input_data = '''1
2 1 2
1 2
1
1 2'''... | [
{
"docstring": null,
"function_declaration": "def shortest_time_for_guards_to_gather(N, M, graph, K, starts):",
"function_name": "shortest_time_for_guards_to_gather",
"parameter_list": "(N, M, graph, K, starts)"
},
{
"docstring": null,
"function_declaration": "def process_input(input_dat... | [
0,
1,
0,
0,
0,
0,
0,
0,
1
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\nfrom typing import List, Tuple\n\ndef dijkstra(start_nodes: List[int], n: int, adj_list: List[List[Tuple[int, int... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00012249",
"row_id": 12249,
"seed_ids": "[1117]"
} | 0.826335 | Apps_12249 | I | [
"shortest_time_for_guards_to_gather",
"process_input",
"find_min_time_for_guards_gathering"
] | 3 | [
[
"find_min_time_for_guards_gathering",
"process_input"
],
[
"process_input",
"shortest_time_for_guards_to_gather"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 1fa90770ed2184a17225a0468d1a6fec6660d8cf | 40511d9f342112ee681d0540cd0827916248c523 | |||
v1.0 | instruct | Apps | Apps_12267_I | Given a list of non-negative integers nums, you are tasked with arranging them in such a way that they form the largest possible number. To clarify, the arrangement of the integers should form a number (concatenation of strings) and this number should be the largest possible.
You should implement a function `largestNu... | from functools import cmp_to_key
def custom_compare(x, y):
if x + y > y + x:
return -1
else:
return 1
def largestNumber(nums):
# Convert nums to strings so we can concatenate them
nums = list(map(str, nums))
# Sort nums by the custom comparator
nums.sort(key=cmp_to_key(cus... | from solution import largestNumber
def test_largest_number_example1():
assert largestNumber([10, 2]) == "210"
def test_largest_number_example2():
assert largestNumber([3, 30, 34, 5, 9]) == "9534330"
def test_largest_number_single_digit():
assert largestNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == "987654321... | [
{
"docstring": null,
"function_declaration": "def custom_compare(x, y):",
"function_name": "custom_compare",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def largestNumber(nums):",
"function_name": "largestNumber",
"parameter_list": "(nums)"
}
] | [
0,
1,
0,
0,
1,
1,
0,
1,
1,
0
] | 5 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import cmp_to_key\n\ndef largestNumber(nums):\n \"\"\"\n Given a list of non-negative integers nums, arrange them such that they form the large... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00012267",
"row_id": 12267,
"seed_ids": "[482]"
} | 0.668489 | Apps_12267 | I | [
"custom_compare",
"largestNumber"
] | 2 | [
[
"largestNumber",
"custom_compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d8d68327a1096d3e2c528d51bb320c2d99a5b07 | 43ff6957a0d9f7ca733386a59101e8c6ee867a34 | |||
v1.0 | instruct | Apps | Apps_12298_I | You have been assigned to develop a scheduling algorithm for a new project. Your team is given n tasks to complete, each with a specific duration. Each task can either be scheduled during the day or during the night. The day and night times have different limitations on the total duration of tasks that can be assigned:... | def schedule_tasks(n, D, N, tasks):
"""
Determines if it is possible to schedule tasks without exceeding daytime and nighttime limits.
Returns "YES" and a valid schedule if possible, otherwise returns "NO".
"""
day_tasks = []
night_tasks = []
day_total = 0
night_total = 0
def backtr... | def test_schedule_tasks():
# Test case 1
input_data = "4 10 12\n3 4 6 8"
output_data = "YES\n0 1 0 1"
assert wrapper_schedule_tasks(input_data) == output_data
# Test case 2
input_data = "3 5 6\n4 5 3"
output_data = "NO"
assert wrapper_schedule_tasks(input_data) == output_data
# Tes... | [
{
"docstring": "Determines if it is possible to schedule tasks without exceeding daytime and nighttime limits.\nReturns \"YES\" and a valid schedule if possible, otherwise returns \"NO\".",
"function_declaration": "def schedule_tasks(n, D, N, tasks):",
"function_name": "schedule_tasks",
"parameter_l... | [
0,
0,
1,
0,
0,
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": "def can_schedule_tasks(n, D, N, durations):\n \"\"\"\n Determine if it's possible to schedule all tasks within the given day and night duration limits.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012298",
"row_id": 12298,
"seed_ids": "[2105]"
} | 0.678201 | Apps_12298 | I | [
"schedule_tasks",
"wrapper_schedule_tasks"
] | 2 | [
[
"wrapper_schedule_tasks",
"schedule_tasks"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 31c8f1490decba119d912a0addc7e73e17a85082 | b87395b6ad95d70c24cf85b84a1fc3e1f42c45fe | |||
v1.0 | instruct | Apps | Apps_12304_I | You are given two integers `start` and `end` representing a range of integers [start, end]. Your task is to determine how many numbers within this range have prime number of set bits (1-bits) in their binary representation. To assist, design a function `countPrimeSetBits(start, end)`. The function should return the cou... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import countPrimeSetBits, is_prime
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(17) == True
assert is_prime(18) == False
def test_countPrimeSetBits... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Counts how many numbers between start and end inclusive have a prime number of set bits in binary representat... | [
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 countPrimeSetBits(start, end):\n \"\"\"\n Returns the count of numbers in the range [start, end] that have a prime number of set bits.\n \"\"\"\n de... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00012304",
"row_id": 12304,
"seed_ids": "[127]"
} | 0.612074 | Apps_12304 | I | [
"is_prime",
"countPrimeSetBits"
] | 2 | [
[
"countPrimeSetBits",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8e4dc824b3e632a71fae74578fab583a3f3cee09 | 023d6e51320fff14e948450843594aa1819d9aa7 | |||
v1.0 | instruct | Apps | Apps_12333_I | Sara loves to climb mountains, and she has become particularly fond of a mountain range that is represented as an array of integers, where each integer represents the height of a peak. This mountain range has several peaks and she wants to analyze these peaks based on different criteria.
You are to process Q queries ... | def count_peaks(arr, x, y):
"""
Counts the number of peaks in the subarray from index x to index y (inclusive).
"""
count = 0
for i in range(x, y - 1):
if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
count += 1
return count
def sum_peaks(arr, x, y):
"""
Calculates th... | def test_count_peaks():
arr = [1, 5, 3, 7, 4, 8, 2, 6]
assert count_peaks(arr, 1, 6) == 2
assert count_peaks(arr, 0, 8) == 3
assert count_peaks(arr, 2, 5) == 1
def test_sum_peaks():
arr = [1, 5, 3, 7, 4, 8, 2, 6]
assert sum_peaks(arr, 1, 6) == 12
assert sum_peaks(arr, 0, 8) == 20
assert... | [
{
"docstring": "Counts the number of peaks in the subarray from index x to index y (inclusive).",
"function_declaration": "def count_peaks(arr, x, y):",
"function_name": "count_peaks",
"parameter_list": "(arr, x, y)"
},
{
"docstring": "Calculates the sum of peaks in the subarray from index x... | [
1,
0,
0,
0,
0,
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": "def count_peaks(arr, x, y):\n count = 0\n for i in range(x, y-1):\n if arr[i] > arr[i-1] and arr[i] > arr[i+1]:\n count += 1\n return cou... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00012333",
"row_id": 12333,
"seed_ids": "[1005]"
} | 0.769217 | Apps_12333 | I | [
"count_peaks",
"sum_peaks",
"process_queries"
] | 3 | [
[
"process_queries",
"count_peaks"
],
[
"process_queries",
"sum_peaks"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 1c4ca43bde9804e01c5a9955cfa27424af58df30 | 921e738b4a687383a27bf4e73112e1d8c52986d7 | |||
v1.0 | instruct | Apps | Apps_12348_I | In the world of programming, efficient data structures are crucial for performance. One such data structure is the binary search tree (BST), which allows for fast lookups, insertions, and deletions.
Write a function that takes a list of integers and constructs a binary search tree (BST) from it. Then, write a separat... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def insert_into_bst(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert_into_bst(root.left, value)
else:
root.ri... | from solution import construct_bst_and_get_sorted_list
def test_empty_list():
assert construct_bst_and_get_sorted_list([]) == []
def test_single_element():
assert construct_bst_and_get_sorted_list([5]) == [5]
def test_multiple_elements():
assert construct_bst_and_get_sorted_list([7, 3, 9, 1, 6, 8]) == [1... | [] | [
1,
1,
1,
1,
1,
0,
1,
1,
0,
0
] | 7 | easy | 0.7 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n if root is... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00012348",
"row_id": 12348,
"seed_ids": "[3097]"
} | 0.519514 | Apps_12348 | I | [
"insert_into_bst",
"construct_bst",
"inorder_traversal",
"bst_to_sorted_list",
"construct_bst_and_get_sorted_list"
] | 5 | [
[
"bst_to_sorted_list",
"inorder_traversal"
],
[
"construct_bst",
"insert_into_bst"
],
[
"construct_bst_and_get_sorted_list",
"bst_to_sorted_list"
],
[
"construct_bst_and_get_sorted_list",
"construct_bst"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0acb8025e72e3deac3825c8fe2fd5a2865275dfe | 1a86b169c08dc11030afdf81b498ba14cdf2a6f8 | |||
v1.0 | instruct | Apps | Apps_12357_I | Given a rectangular grid of size $n \times m$ where each cell contains a number, find the maximum sum of number cells for any subgrid of size $k \times l$ within this grid. A subgrid in this context means a contiguous block of the grid starting from any cell and spanning $k \times l$ cells.
-----Input:-----
-
The fir... | def max_subgrid_sum(grid, n, m, k, l):
"""
Finds the maximum sum of any k x l subgrid in the given n x m grid.
:param grid: 2D list of integers representing the grid.
:param n: Number of rows in the grid.
:param m: Number of columns in the grid.
:param k: Number of rows for the subgrid.
:pa... | from solution import max_subgrid_sum
def test_max_subgrid_sum_example_case():
grid = [
[1, 2, 3, 4, 5],
[5, 6, 7, 8, 9],
[9, 3, 0, 6, 2],
[4, 8, 1, 5, 3]
]
n, m, k, l = 4, 5, 2, 3
assert max_subgrid_sum(grid, n, m, k, l) == 36
def test_max_subgrid_sum_minimal_case():
... | [
{
"docstring": "Finds the maximum sum of any k x l subgrid in the given n x m grid.\n\n:param grid: 2D list of integers representing the grid.\n:param n: Number of rows in the grid.\n:param m: Number of columns in the grid.\n:param k: Number of rows for the subgrid.\n:param l: Number of columns for the subgrid.... | [
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 max_subgrid_sum(grid, n, m, k, l):\n \"\"\"\n Find the maximum sum of a k x l subgrid within the grid of size n x m.\n \"\"\"\n # Precompute the pre... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00012357",
"row_id": 12357,
"seed_ids": "[1102]"
} | 0.648962 | Apps_12357 | I | [
"max_subgrid_sum",
"read_input_and_compute"
] | 2 | [
[
"read_input_and_compute",
"max_subgrid_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 60b85e3773db23c9b4230d937ec4a3ce7b42842f | f81dba72773d23961f76bed33858d6787cb04fcd | |||
v1.0 | instruct | Apps | Apps_12360_I | =====Problem Statement=====
Write a function that takes a list of integers and returns a new list containing the factorial of each integer in the original list. Do not use any built-in factorial function.
=====Example=====
If the input list is [1, 2, 3], the output list should be [1, 2, 6].
=====Input Format=====
The... | def factorial(n):
"""
Computes the factorial of a non-negative integer n.
"""
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
def list_factorials(int_list):
"""
Takes a list of integers and returns a list with the factoria... | from solution import factorial, list_factorials, main
def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
assert factorial(6) == 720
assert factorial(10) == 3628800... | [
{
"docstring": "Computes the factorial of a non-negative integer n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns a list with the factorial of each integer.",
"function_declarat... | [
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 factorial(n):\n \"\"\"\n Returns the factorial of a given number n.\n \"\"\"\n if n == 0:\n return 1\n result = 1\n for i in range(2, n... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012360",
"row_id": 12360,
"seed_ids": "[2612]"
} | 0.678794 | Apps_12360 | I | [
"factorial",
"list_factorials",
"main"
] | 3 | [
[
"list_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f08aa3295a0d178f98b5561e10df5e497dfd3344 | e5ebbf6d67cf8e48b61cafe71399c2d91eeaa0f7 | |||
v1.0 | instruct | Apps | Apps_12406_I | A group of biologists is studying the migratory patterns of a certain species of birds. They have tracked the birds across different waypoints and logged observations for each bird at various timestamps during their journey. The goal is to determine the longest continuous sequence of waypoints visited by any bird, wher... | def longest_increasing_sequence(observations):
"""
Find the length of the longest increasing sequence
of waypoints based on the observations of a single bird.
"""
observations.sort()
dp = [1] * len(observations)
for i in range(1, len(observations)):
for j in range(i):
if ... | from solution import longest_increasing_sequence, longest_sequence_for_all_birds
def test_longest_increasing_sequence():
assert longest_increasing_sequence([(1, 2), (2, 3), (3, 4)]) == 3
assert longest_increasing_sequence([(1, 5), (2, 3), (3, 2), (4, 1)]) == 1
assert longest_increasing_sequence([(10, 12), ... | [
{
"docstring": "Find the length of the longest increasing sequence\nof waypoints based on the observations of a single bird.",
"function_declaration": "def longest_increasing_sequence(observations):",
"function_name": "longest_increasing_sequence",
"parameter_list": "(observations)"
},
{
"do... | [
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 longest_increasing_subsequence(observations):\n \"\"\"\n Helper function to find the longest increasing subsequence based on the waypoint numbers.\n \n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00012406",
"row_id": 12406,
"seed_ids": "[1288]"
} | 0.664613 | Apps_12406 | I | [
"longest_increasing_sequence",
"longest_sequence_for_all_birds",
"parse_input"
] | 3 | [
[
"longest_sequence_for_all_birds",
"longest_increasing_sequence"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3c3fd55a5b2364526ecc69289db9fd3ab8b122ba | 61118cd990cd1b21291eef14ab76a8a10feef927 | |||
v1.0 | instruct | Apps | Apps_12446_I | Write a function that takes a list of Roman numeral strings and returns the sum of the numeral values. Roman numerals are represented by the following symbols:
```
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
```
In Roman numerals... | def roman_to_int(roman):
"""
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 roman[::-1]: # Traverse the string in reverse
value = roman_dict[char]
if value < ... | from solution import roman_to_int, sum_roman_numerals
def test_roman_to_int():
assert roman_to_int("III") == 3
assert roman_to_int("IV") == 4
assert roman_to_int("IX") == 9
assert roman_to_int("LVIII") == 58
assert roman_to_int("MCMXCIV") == 1994
def test_sum_roman_numerals():
assert sum_roman... | [
{
"docstring": "Convert a Roman numeral to an integer.",
"function_declaration": "def roman_to_int(roman):",
"function_name": "roman_to_int",
"parameter_list": "(roman)"
},
{
"docstring": "Convert a list of Roman numerals to their integer values and return their sum.",
"function_declarat... | [
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 roman_to_int(s):\n \"\"\"\n Converts a single Roman numeral string to an integer.\n \"\"\"\n roman_values = {\n 'I': 1, 'V': 5, 'X': 10, 'L':... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00012446",
"row_id": 12446,
"seed_ids": "[2960]"
} | 0.595932 | Apps_12446 | I | [
"roman_to_int",
"sum_roman_numerals"
] | 2 | [
[
"sum_roman_numerals",
"roman_to_int"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 060989671c9a80b6ded49c7b512be6bdce241273 | 2901f3caf6d84884aed8069d0ba2107fb0ee36c3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.