source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 66,883 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
magic_evol_110k | 66,885 | Write a Python function to determine if a given large number is a prime number or not. The function should be optimized for large inputs and should handle potential input errors gracefully. The function should also include a mechanism to correct for faulty memory management, if any. The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
import random
def is_prime(n: int, retry_count: int = 3) -> bool:
"""
Determine if a given large number is a prime number.
Args:
n (int): The number to check for primality.
retry_count (int): Nu... |
magic_evol_110k | 66,892 | Write a Python function that accepts a list of unique numerical inputs and returns two values - the number with the most unique digits and the total count of such unique digits. If multiple numbers have the same unique digit count, return the number that appears first in the list along with its unique digit count.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_number_with_most_unique_digits(numbers: List[int]) -> Tuple[int, int]:
"""
Finds the number with the highest count of unique digits from a list of unique numerical inputs.
If multiple... |
magic_evol_110k | 66,925 | Write a Python function to identify and return the data type of each variable in a given list. The function should handle various data types such as strings, integers, lists, tuples, dictionaries, sets, floats, and booleans. The function should return a new list containing the data type names of each element in the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def identify_datatypes(data: List) -> List[str]:
"""
Identifies and returns the data type of each variable in the given list.
Args:
data (List): A list containing various data types.
Re... |
magic_evol_110k | 66,928 | Write a Python function to determine if a given string `s` is "happy" based on the frequency of unique combinations of `n` consecutive letters. A string is considered "happy" if each unique sequence of `n` consecutive letters appears at least twice. The function should handle edge cases like repetition with overlapping... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_happy(s: str, n: int) -> bool:
"""
Determine if a given string `s` is "happy" based on the frequency of unique combinations of `n` consecutive letters.
A string is considered "happy" if each unique sequence of `n` con... |
magic_evol_110k | 66,949 | Write a Python function to find the sorted unique common elements between two lists of integers without using built-in Python list functions (except for converting sets to lists). The function should handle cases with negative numbers and return a correctly sorted list. The function should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def common(l1: List[int], l2: List[int]) -> List[int]:
"""
Return sorted unique common elements for two lists without using built-in Python list functions and accounting for negative numbers.
Args:
... |
magic_evol_110k | 66,950 | Write a Python function to remove all duplicates from a given list of numbers while preserving the order of the elements. The function should return a new list with all unique elements in the order they first appeared in the original list.
The code should start with:
```python
from typing import List
def remove_dupli... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(my_list: List[int]) -> List[int]:
"""
Removes duplicates from a list of integers while preserving the order of the elements.
Args:
my_list (List[int]): T... |
magic_evol_110k | 66,953 | Write a Python function to determine the minimum and maximum elements present within a given array of integers. If there are duplicate numbers in the array, identify and return the indexes of the minimum and maximum numbers in all their occurrences. The function should return the results in dictionary format, where the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_min_max_indexes(numbers: List[int]) -> Dict[str, List[int]]:
"""
Determine the minimum and maximum elements present within the array and return their indexes.
Args:
numbers (L... |
magic_evol_110k | 66,969 | Write a Python function to compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm. The function should handle both positive and negative integers and return the absolute value of the GCD.
The code should start with:
```python
def gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
... |
magic_evol_110k | 66,974 | Write a Python function to transform a given list of string-formatted binary numbers into a list of their integer equivalents. The function should handle any list of valid binary strings and return a list of integers.
The code should start with:
```python
from typing import List
def binary_to_integers(binary_list: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_to_integers(binary_list: List[str]) -> List[int]:
"""
Converts a list of string-formatted binary numbers into a list of their integer equivalents.
Args:
binary_list (List[str]): A... |
magic_evol_110k | 66,978 | Write a Python function to find the common elements in two given unsorted arrays. The function should return a list of common elements in ascending order. The code should start with:
```python
from typing import List
def find_common_elements(arr1: List[int], arr2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_common_elements(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Find the common elements in two given unsorted arrays and return them in ascending order.
Args:
arr1 (List[int]... |
magic_evol_110k | 66,982 | Write a Python function to determine all prime numbers within a given range `[start, end)` using the Sieve of Eratosthenes algorithm. The function should exclude both endpoints `start` and `end`. Additionally, create a helper function to verify if a given number is prime.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, Fa... |
magic_evol_110k | 66,987 | Write a Python function to remove sequential duplicate entries from a given list of strings. The function should return a new list with all consecutive duplicate elements removed, ensuring that only the first occurrence of each sequence of duplicates is retained. The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_sequential_duplicates(arr: List[str]) -> List[str]:
"""
Removes sequential duplicate entries from a given list of strings.
Args:
arr (List[str]): The list of strings from which to... |
magic_evol_110k | 67,000 | Write a Python function to generate all unique permutations of a given list of words. The function should return a list of tuples, where each tuple represents a unique permutation of the input list. The function should handle lists of varying lengths and ensure that all permutations are unique.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_unique_permutations(words: List[str]) -> List[Tuple[str]]:
"""
Generate all unique permutations of a given list of words.
Args:
words (List[str]): A list... |
magic_evol_110k | 67,001 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. Additionally, identify and correct the issues in the provided erroneous code snippet.
The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Initialize an empty string to store the... |
magic_evol_110k | 67,003 | Write a Python function to determine if the product of all the numbers in a given list of positive integers forms a co-prime number. A number is considered co-prime if it is greater than 1 and only divisible by 1 and itself. The function should return `True` if the product is co-prime, otherwise `False`.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False oth... |
magic_evol_110k | 67,007 | Write a Python function to identify and return all hexadecimal values that start with the character 'B' from a given string. The function should use a regular expression to match these values.
The code should start with:
```python
import re
from typing import List
def find_hex_values_starting_with_B(text: str) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_hex_values_starting_with_B(text: str) -> List[str]:
"""
Finds and returns all hexadecimal values that start with the character 'B' from the given text.
Args:
text (str): T... |
magic_evol_110k | 67,012 | Write a Python function to count the frequency of each character in a given string and return the result as a dictionary. The keys of the dictionary should be the characters from the string, and the values should be the corresponding frequencies of those characters. The function should handle any string input, includin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(text: str) -> Dict[str, int]:
"""
Counts the frequency of each character in the given string and returns a dictionary with characters as keys and their frequencies as values.
... |
magic_evol_110k | 67,019 | Write a Python function to compute the perimeter of a triangle given the lengths of its three sides. The function should validate that the given side lengths can form a valid triangle before calculating the perimeter. If the side lengths do not form a valid triangle, the function should return `None`.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_perimeter(side1: float, side2: float, side3: float) -> float:
"""
Compute the perimeter of a triangle given the lengths of its three sides.
Args:
side1 (float): The length of the first side of the trian... |
magic_evol_110k | 67,020 | Write a Python function called `check_parity` that takes two integer input parameters, `x` and `y`. The function should return a boolean outcome based on the combined value of `x` and `y` for three arithmetic operations: addition, subtraction, and multiplication. If the combined value (result of addition, subtraction, ... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_parity(x: int, y: int) -> bool:
"""
Check if the combined value of two integers x and y exhibits even parity for addition, subtraction, and multiplication.
Args:
x (int): The first positive integer.
... |
magic_evol_110k | 67,036 | Write a Python function to identify the numerically most expansive (maximum) and most diminutive (minimum) entities in a given collection of integers. The function should return a tuple containing the maximum and minimum values.
The code should start with:
```python
from typing import List, Tuple
def find_extremes(co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_extremes(collection: List[int]) -> Tuple[int, int]:
"""
Identify the numerically most expansive (maximum) and most diminutive (minimum) entities in a given collection of integers.
Ar... |
magic_evol_110k | 67,037 | Write a Python function to identify and return all distinct lexemes (words) from a given text string, while managing text case differentiations and punctuation influences. The function should return a set of unique lexemes.
The code should start with:
```python
from typing import Set
def distinct_lexemes(text: str) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
import string
def distinct_lexemes(text: str) -> Set[str]:
"""
Identifies and returns all distinct lexemes (words) from a given text string,
managing text case differentiations and punctuation influen... |
magic_evol_110k | 67,042 | Write a Python function to calculate the sum of elements in a list. The function should handle both lists and individual arguments correctly. If the input is a list, it should sum the elements of the list. If the input is individual arguments, it should sum those arguments.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_sum(*args: Union[List[int], int]) -> int:
"""
Calculate the sum of elements in a list or individual arguments.
Args:
*args: A list of integers or individual integer arguments... |
magic_evol_110k | 67,047 | Write a Python function to compute the square root of each element in a given list without using any built-in or library functions for square root calculation. Additionally, implement a function to check if the calculated square root is an integer. If it is an integer, append the integer square root to a new list; othe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def square_root(n: int) -> float:
"""
Compute the square root of a given number using the Babylonian method.
Args:
n (int): The number for which to compute the square root.
Returns:
... |
magic_evol_110k | 67,053 | Write a Python function to generate the nth Fibonacci number efficiently. The function should handle large values of n and avoid unnecessary storage and computational complexities. The code should start with:
```python
def fibonacci(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci(n: int) -> int:
"""
Generate the nth Fibonacci number efficiently.
Args:
n (int): The position in the Fibonacci sequence to generate.
Returns:
int: The nth Fibonacci number.
"""
# ... |
magic_evol_110k | 67,055 | Write a Python function to process a list of strings, where each string contains only numerical digits. The function should return a list of strings, where each string describes the count of odd digits in the corresponding input string. The format of the output string should be: "the count of odd parts <count>n the str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def complex_sum(lst: List[str]) -> List[str] or str:
"""
Process a list of strings containing only numerical digits and return a list of formatted strings
describing the count of odd digits in each s... |
magic_evol_110k | 67,062 | Write a Python function that takes a list of integers as input and fulfills the following requirements: It should use a loop to print out the values and their respective indices, and it should include an optional second parameter to filter out values that are less than the given filter value.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def print_array_with_filter(arr: List[int], filter_value: Optional[int] = None) -> None:
"""
Prints the values and their respective indices from the given list, optionally filtering out values ... |
magic_evol_110k | 67,063 | Write a Python function to find the kth smallest number in a list of length n without sorting the list or using any built-in sort function. The function should use the Quickselect algorithm, which is a selection algorithm to find the kth smallest element in an unordered list. The function should handle lists with non-u... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def partition(lst: List[int], low: int, high: int) -> int:
"""
Partitions the list around a pivot such that elements less than or equal to the pivot
are on the left, and elements greater than the piv... |
magic_evol_110k | 67,073 | Write a Python function to convert any given hexadecimal number to its binary representation without using in-built or library functions. Ensure your solution handles both uppercase and lowercase letters, and invalid inputs. The function should return the binary representation as a string or an error message if the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_bin(hex_num: str) -> str:
"""
Converts a given hexadecimal number to its binary representation without using in-built or library functions.
Args:
hex_num (str): The hexadecimal number to be converted. It ... |
magic_evol_110k | 67,078 | Write a Python function to flatten a nested list of integers into a single list of integers. The nested list can have an arbitrary depth of nesting. The function should handle any valid input, including empty lists and lists with varying levels of nesting.
The code should start with:
```python
from typing import List,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def flatten_nested_list(nested_list: List[Union[int, List]]) -> List[int]:
"""
Flattens a nested list of integers into a single list of integers.
Args:
nested_list (List[Union[int, Li... |
magic_evol_110k | 67,083 | Write a Python function to display a provided 2D matrix in diagonal zigzag order. The function should handle invalid matrices by returning an empty list. The function should start with:
```python
from typing import List
def diagonal_zigzag(matrix: List[List[int]]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def diagonal_zigzag(matrix: List[List[int]]) -> List[int]:
"""
Display a provided 2D matrix in diagonal zigzag order.
Args:
matrix (List[List[int]]): The 2D matrix to be displayed in diagona... |
magic_evol_110k | 67,096 | Write a Python function to determine if a given integer is an even number. The function should return `True` if the number is even and `False` otherwise. The code should start with:
```python
def is_even(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_even(num: int) -> bool:
"""
Determines if a given integer is an even number.
Args:
num (int): The integer to be checked.
Returns:
bool: True if the number is even, False otherwise.
"""
# ... |
magic_evol_110k | 67,101 | Write a Python function to determine the unique elements in the intersection of three given sets. The function should take three sets as input and return a set containing the elements that are present in all three sets.
The code should start with:
```python
from typing import Set
def find_intersection_of_three_sets(s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def find_intersection_of_three_sets(setA: Set[int], setB: Set[int], setC: Set[int]) -> Set[int]:
"""
Determine the unique elements in the intersection of three sets.
Args:
setA (Set[int]): Th... |
magic_evol_110k | 67,102 | Write a Python function to find the maximum number in a list without using the built-in `max` function, and return the maximum value, a list of indices where this maximum value occurs, and the average of these indices rounded to the nearest integer. The function should handle lists containing duplicate maximum values a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_max_and_indices(data: List[int]) -> Tuple[int, List[int], int]:
"""
Finds the maximum number in a list and returns the maximum value, a list of indices where this maximum value occurs,
... |
magic_evol_110k | 67,115 | Write a Python function to generate prime numbers within a given range efficiently. The function should accept two integers, `start` and `end`, and return a list of all prime numbers within this range (inclusive). The function should be optimized to reduce unnecessary computations.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def generate_primes_in_range(start: int, end: int) -> List[int]:
"""
Generate a list of prime numbers within the given range [start, end].
Args:
start (int): The starting number ... |
magic_evol_110k | 67,121 | Write a Python function to traverse a multi-dimensional array of discrete numerical quantities, identify prime numbers, and handle any exceptions that might occur. The function should also manage memory allocation explicitly by using a generator to yield prime numbers one at a time. The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Generator
def check_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, F... |
magic_evol_110k | 67,124 | Write a Python function to evaluate a given algebraic expression with a single variable `x` and return the result after substituting `x` with a provided value. The algebraic expression will be in the form of a string, and the value of `x` will be provided as an integer. The function should handle basic arithmetic opera... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str, x: int) -> float:
"""
Evaluates a given algebraic expression with a single variable `x` and returns the result after substituting `x` with the provided value.
Args:
expressio... |
magic_evol_110k | 67,133 | Write a Python function to classify an array of ISO 8601 formatted date strings into sequentially ordered seven-day time periods. Each date in the input array should be grouped into periods where the difference between the earliest and latest date in each period is less than or equal to seven days. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from datetime import datetime, timedelta
def classify_dates_into_periods(dates: List[str]) -> List[List[str]]:
"""
Classify an array of ISO 8601 formatted date strings into sequentially ordered seven-day... |
magic_evol_110k | 67,135 | Write a Python function to traverse a doubly linked list that contains arrays. The function should return `True` if the given element exists in any of the arrays, and `False` otherwise. Additionally, the function should calculate and return the total search time in milliseconds. The doubly linked list is represented as... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import time
def search_element_in_doubly_linked_list(linked_list: List[List[int]], element: int) -> Tuple[bool, float]:
"""
Searches for a given element in a doubly linked list that contains array... |
magic_evol_110k | 67,136 | Write a Python function to generate all possible permutations of a given input string with a specified length `n`. The function should handle both unique permutations and permutations with repetitions. The code should start with:
```python
from typing import List
def generate_permutations(input_string: str, n: int, al... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from itertools import permutations, product
def generate_permutations(input_string: str, n: int, allow_repetitions: bool = False) -> List[str]:
"""
Generate all possible permutations of the input string ... |
magic_evol_110k | 67,139 | Write a Python function to sort and modify a list based on specific criteria. The function should take a list of integers `l`, a positive integer `n`, a string `s` ('asc' for ascending or 'desc' for descending), and another positive integer `m`. The function should modify every `n`-th element in the list by multiplying... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def advanced_sort(l: List[int], n: int, s: str, m: int) -> List[int]:
"""
Modifies every n-th element in the list by multiplying it with m, sorts these modified values,
and replaces the original n-th... |
magic_evol_110k | 67,143 | Write a Python function to merge two lists of strings while preserving the order of elements and removing duplicates. The function should return a new list that contains all unique elements from both lists, maintaining the order of their first appearance.
The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_unique_lists(arr1: List[str], arr2: List[str]) -> List[str]:
"""
Merge two lists of strings while preserving the order of elements and removing duplicates.
Args:
arr1 (List[str]): ... |
magic_evol_110k | 67,149 | Write a Python function to construct a regular expression pattern that accurately identifies the exact string "hello people" as well as variations where any character can be upper or lower case, and there can be multiple spaces between words. The function should return the constructed pattern.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def construct_regex_pattern() -> str:
"""
Constructs a regular expression pattern that matches the exact string "hello people"
with variations where any character can be upper or lower case, and there can be
m... |
magic_evol_110k | 67,156 | Write a Python function to calculate the detailed average cost of various product types, considering both primary expenditures and auxiliary expenditures such as taxes, delivery, and insurance costs. The main source data will be a dictionary where each key represents a product type, and the value is a list of tuples, e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def calculate_average_cost(products: Dict[str, List[Tuple[float, float]]]) -> Dict[str, float]:
"""
Calculate the detailed average cost of various product types, considering both primary and... |
magic_evol_110k | 67,162 | Write a Python function to transform a list of command-line arguments by replacing all occurrences of the `=` character with the `:` character in key-value pairs. The function should handle a dynamic number of arguments, where each argument is a string in the format `key=value`. The transformed arguments should be retu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_arguments(args: List[str]) -> List[str]:
"""
Transforms a list of command-line arguments by replacing all occurrences of '=' with ':'.
Args:
args (List[str]): A list of strings... |
magic_evol_110k | 67,184 | Write a Python function to recursively sum a list of numbers given as strings. If any string cannot be converted to an integer, the function should return a custom error message for that specific string. The function should handle the conversion and addition using recursion and a try-except structure.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def recursive_sum(lst: List[str], index: int = 0) -> int or str:
"""
Recursively sums a list of numbers given as strings. If any string cannot be converted to an integer,
returns a custom error messa... |
magic_evol_110k | 67,185 | Write a Python function to create a dictionary where the keys are composite tuples formed by combining two element-known tuples, and the values are lists containing the product and sum of the elements in the corresponding tuples. The function should filter out any invalid tuples that do not meet the criteria. The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_composite_dictionary(tuples: List[Tuple]) -> Dict[Tuple, List[int]]:
"""
Create a dictionary where the keys are composite tuples formed by combining two valid tuples,
and the ... |
magic_evol_110k | 67,195 | Write a Python function to perform a cyclical permutation operation on the elements at three specified positions within an integer numerical sequence. The function should take an array and three indices as input and return the array after performing the cyclic permutation. The cyclic permutation involves swapping the e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cyclic_permutation(arr: List[int], i: int, j: int, k: int) -> List[int]:
"""
Perform a cyclical permutation on the elements at the specified indices within the array.
Args:
arr (List[int... |
magic_evol_110k | 67,204 | Write a Python function to calculate the cube of a given number. The function should be named `calculate_cube` and should take a single integer or float as input. The function should return the cube of the input value. Additionally, write a test function named `test_calculate_cube` that contains ten assert statements t... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_cube(n: float) -> float:
"""
Calculate the cube of a given number.
Args:
n (float): The number to calculate the cube of.
Returns:
float: The cube of the input number.
"""
return n ... |
magic_evol_110k | 67,213 | Write a Python function to compute the product of all elements in a given list. The function should iterate over the list and accumulate the product by multiplying each element consecutively. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_product(input_array: List[int]) -> int:
"""
Compute the product of all elements in the given list.
Args:
input_array (List[int]): The list of integers whose product is to be comp... |
magic_evol_110k | 67,222 | Write a Python function to find the middlemost numerical entity from a given array of integers. If the array has an even number of elements, return the average of the two middlemost elements. The function should handle arrays of any length, including empty arrays.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_middle_number(arr: List[int]) -> Union[int, float]:
"""
Find the middlemost numerical entity from a given array of integers.
If the array has an even number of elements, return the av... |
magic_evol_110k | 67,229 | Write two Python functions to analyze the occurrences of a substring within a main string. The first function, `how_many_times`, should count the occurrences of a substring in the main string, including overlapping instances, and return both the count and the list of starting indices of these occurrences. The second fu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def how_many_times(string: str, substring: str) -> Tuple[int, List[int]]:
"""
Calculate the prevalence and indexing of a stipulated substring within the originating string. Encompass overlapping i... |
magic_evol_110k | 67,242 | Write a Python function to search for a specified term in a provided text sequence and return the index of the term if found. The search should be case-insensitive and should handle potential punctuation marks. If the term is not found, the function should return -1.
The code should start with:
```python
import re
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def search_term_in_text(text: str, term: str) -> int:
"""
Searches for a specified term in a provided text sequence and returns the index of the term if found.
The search is case-insensitive and handles potential ... |
magic_evol_110k | 67,252 | Write a Python function to determine if a given number `a` is the product of exactly three distinct prime numbers, and if so, return those three prime numbers. If the number is not the product of three distinct prime numbers, return the string `'Not a product of 3 distinct prime numbers.'`. The function should be desig... | Here is the Python code to solve the given problem in the markdown block:
```python
def intricate_prime_triplet_product(a: int) -> tuple or str:
"""
Determine if the given number `a` is the product of exactly three distinct prime numbers.
If so, return those three prime numbers as a tuple. Otherwise, return... |
magic_evol_110k | 67,258 | Write a Python function to display the elements of a two-dimensional matrix in a retrograde manner, both row-wise and column-wise. The matrix should be populated with elements from a one-dimensional array and must be constructed in the code as well. The function should return two lists: one for the retrograde row-wise ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def retrograde_traversal(arr: List[int]) -> (List[int], List[int]):
"""
Display the elements of a two-dimensional matrix in a retrograde manner, both row-wise and column-wise.
Args:
arr (Lis... |
magic_evol_110k | 67,262 | Write a Python function to generate a random integer within a specified range `[low, high]` (both inclusive) using the `random` module. The function should ensure that the generated integer is uniformly distributed within the specified range. The code should start with:
```python
import random
def generate_random_inte... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_integer(low: int, high: int) -> int:
"""
Generates a random integer within the specified range [low, high] (both inclusive).
Args:
low (int): The lower bound of the range (inclusiv... |
magic_evol_110k | 67,269 | Write a Python function to count the frequency of each unique number in a given list and return the result as a dictionary. The dictionary should map each unique number to its corresponding frequency of occurrence. The function should handle any list of integers, including empty lists and lists with duplicate elements.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_frequencies(nums: List[int]) -> Dict[int, int]:
"""
Counts the frequency of each unique number in the given list and returns a dictionary.
Args:
nums (List[int]): The list of... |
magic_evol_110k | 67,270 | Write a Python function to generate a list of ten distinct random numbers within the range of 10 to 50, ensuring no two elements are identical. The function should return the generated list.
The code should start with:
```python
from typing import List
import random
def generate_distinct_random_numbers() -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinct_random_numbers() -> List[int]:
"""
Generates a list of ten distinct random numbers within the range of 10 to 50.
Returns:
List[int]: A list containing ten... |
magic_evol_110k | 67,283 | Write a Python function to calculate the difference between the maximum and minimum values in a given list of integers. The function should handle lists of any length, including empty lists. If the list is empty, the function should return 0. The code should start with:
```python
from typing import List
def find_diffe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_difference(lst: List[int]) -> int:
"""
Calculate the difference between the maximum and minimum values in a list of integers.
Args:
lst (List[int]): The list of integers from which ... |
magic_evol_110k | 67,288 | Write a Python function to calculate the following information about a ship's journey:
1. The total distance the ship has traveled after 6 hours, considering the change in speed and the impact of the current.
2. The ship's actual average speed considering the current's impact on its speed.
3. The additional time it wou... | Here is the Python code to solve the given problem in the markdown block:
```python
def ship_journey_info(n: float) -> tuple:
"""
Calculate the total distance traveled, the actual average speed, and the additional time required to travel the same distance without the current.
Args:
n (float): The s... |
magic_evol_110k | 67,294 | Write a Python function to capitalize every fruit name in a given list of fruit names and return a new list containing the capitalized fruit names. The function should handle any list of strings, including empty lists and lists with mixed-case strings.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def capitalize_fruit_names(fruits: List[str]) -> List[str]:
"""
Capitalizes every fruit name in the given list of fruit names.
Args:
fruits (List[str]): A list of fruit names represented as ... |
magic_evol_110k | 67,295 | Write a Python function to merge two lists into a single unified list. The function should handle lists of any length and should not modify the original lists. The merged list should contain all elements from both input lists, maintaining the order of elements as they appear in the original lists.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list1: List[str], list2: List[str]) -> List[str]:
"""
Merges two lists into a single unified list without modifying the original lists.
Args:
list1 (List[str]): The first lis... |
magic_evol_110k | 67,311 | Write a Python function to disassemble a given text string into its individual characters. The function should return a list of characters where each character from the input string is an element in the list. The code should start with:
```python
from typing import List
def disassemble_string(sentence: str) -> List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def disassemble_string(sentence: str) -> List[str]:
"""
Disassembles a given text string into its individual characters and returns them as a list.
Args:
sentence (str): The input string to ... |
magic_evol_110k | 67,318 | Write a Python function to calculate the product of two numbers. The function should take two integers as input and return their product. The code should start with:
```python
def multiply(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply(x: int, y: int) -> int:
"""
Calculate the product of two integers.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
int: The product of x and y.
"""
#... |
magic_evol_110k | 67,322 | Write a Python function to calculate the absolute difference between two given numbers. The function should take two integers as input and return the absolute difference as an integer. The code should start with:
```python
def absolute_difference(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_difference(num1: int, num2: int) -> int:
"""
Calculate the absolute difference between two given numbers.
Args:
num1 (int): The first number.
num2 (int): The second number.
Returns:
... |
magic_evol_110k | 67,328 | Write a Python function to display the elements of a given list in reverse order, with each element repeated twice, separated by an asterisk. Additionally, append " - even" to the output line if the element is even, and " - odd" if the element is odd. Each element and its repetition should be on a new line. The functio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def display_reversed_elements(nums: List[int]) -> None:
"""
Displays the elements of the given list in reverse order, with each element repeated twice,
separated by an asterisk. Additionally, appends... |
magic_evol_110k | 67,339 | Write a Python function to return only the even numbers from two given lists, merged and sorted in descending order. Additionally, implement a helper function to handle the merging and sorting logic. The provided code snippet contains errors and an unfinished helper function; your task is to find and correct them.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_even_and_merge(l1: List[int], l2: List[int]) -> List[int]:
"""
Return only even numbers from both lists, merged and sorted in descending order.
Args:
l1 (List[int]): The first list o... |
magic_evol_110k | 67,340 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should return a list containing the first `n` Fibonacci numbers.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n numbers in the Fibonacci sequence.
The Fibonacci sequence is a series of numbers where each number is the sum of the two precedi... |
magic_evol_110k | 67,342 | Write a Python function to calculate the average of each pair of numbers from a list of tuples and the overall average of all numbers. The function should handle input validation to ensure that all values are numeric and raise an appropriate error if any value is non-numeric. The function should also write the averages... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_averages(pairs: List[Tuple[str, str]], filename: str) -> None:
"""
Calculate the average of each pair of numbers and the overall average of all numbers.
Write the averages to a s... |
magic_evol_110k | 67,347 | Write a Python function to generate a 3D array using NumPy that contains the numbers from 1 to `n^3`, where `n` is a positive integer, and then reshape it into an `n x n x n` matrix. The function should return the reshaped matrix.
The code should start with:
```python
import numpy as np
def generate_3d_matrix(n: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_3d_matrix(n: int) -> np.ndarray:
"""
Generate a 3D array using NumPy that contains the numbers from 1 to n^3,
and then reshape it into an n x n x n matrix.
Args:
n (int): The dim... |
magic_evol_110k | 67,355 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two given strings.
Args:
str1 (str): The first string.
str2 (str): The second ... |
magic_evol_110k | 67,368 | Write a Python function to find the k-th largest number in a given list of integers. The function should be efficient and handle lists of varying lengths. The code should start with:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> int:
"""
Find the k-th largest number in a given list of integers.
Args:
nums (List[int]): The list of integers from which to find the k-th l... |
magic_evol_110k | 67,383 | Write a Python function to find and return the n smallest unique numbers from a given list of integers. The function should ignore any repeated numbers and return exactly n unique smallest numbers. If the list contains fewer than n unique numbers, the function should return all unique numbers in ascending order.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_n_smallest_unique(arr: List[int], n: int) -> List[int]:
"""
Returns the n smallest unique numbers from the given list.
Args:
arr (List[int]): The list of integers from which to extra... |
magic_evol_110k | 67,384 | Write a Python function to check whether an input string is a palindrome using a regular expression. The function should be case and whitespace insensitive, meaning it should recognize "Race car" as a palindrome. The function should start with:
```python
import re
def is_palindrome(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_palindrome(input_string: str) -> bool:
"""
Check whether the input string is a palindrome using a regular expression.
The check is case and whitespace insensitive.
Args:
input_string (str): The... |
magic_evol_110k | 67,390 | Write a Python function to swap two numbers without using temporary variables or the built-in swap function. The function should be generic and work for any pair of integers. Additionally, provide a demonstration of swapping the numbers 10 and 20. The code should start with:
```python
def swap_numbers(a: int, b: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_numbers(a: int, b: int) -> tuple:
"""
Swaps two numbers without using temporary variables or the built-in swap function.
Args:
a (int): The first number to be swapped.
b (int): The second number to ... |
magic_evol_110k | 67,404 | Write a Python function to find all positive factors of a given integer `X`. The function should handle edge cases such as when `X` is zero or a negative number. The function should be optimized to avoid inefficiencies and inaccuracies present in the provided erroneous code.
The code should start with:
```python
def f... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_factors(X: int) -> list:
"""
Find all positive factors of a given integer X.
Args:
X (int): The integer for which to find the factors.
Returns:
list: A list of all positive factors of X, sorted... |
magic_evol_110k | 67,405 | Write a Python function to recursively prepend a given text string to each element in a nested list, while also appending the index of the 'nth' nested list to the string for each corresponding item. The function should handle errors when the input parameters are not a string and a list, respectively. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def prepend_text_to_list(string: str, lst: List[Any]) -> List[Any]:
"""
Recursively prepends a given text string to each element in a nested list,
while also appending the index of the 'nth' nes... |
magic_evol_110k | 67,406 | Write a Python function to determine if a given target substring exists within a specified parent string. The function should return a boolean value indicating whether the target substring is found in the parent string. The code should start with:
```python
def is_substring_in_parent(parent_string: str, target_substrin... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring_in_parent(parent_string: str, target_substring: str) -> bool:
"""
Determines if the target substring is present within the parent string.
Args:
parent_string (str): The string in which to search for... |
magic_evol_110k | 67,422 | Write a Python function to remove sequential duplicates from a given list while preserving the original order of elements. The list can contain both strings and integers. The function should start with:
```python
from typing import List, Union
def remove_sequential_duplicates(input_list: List[Union[str, int]]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def remove_sequential_duplicates(input_list: List[Union[str, int]]) -> List[Union[str, int]]:
"""
Removes sequential duplicates from a given list while preserving the original order of elements.
... |
magic_evol_110k | 67,424 | Write a Python function to merge two pre-sorted arrays into a single sorted array without using any external libraries. The function should efficiently combine the two arrays while maintaining the sorted order.
The code should start with:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two pre-sorted arrays into a single sorted array.
Args:
arr1 (List[int]): The first pre-sorted array.
... |
magic_evol_110k | 67,441 | Write a Python function to encrypt a given valid URL by replacing every forward slash `'/'` with `'[slash]'` and every period `'.'` with `'[dot]'`. The function should handle URLs with multiple forward slashes and periods.
The code should start with:
```python
def encrypt_url(address: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def encrypt_url(address: str) -> str:
"""
Encrypts a given valid URL by replacing every forward slash '/' with '[slash]' and every period '.' with '[dot]'.
Args:
address (str): The valid URL address to be encrypted.... |
magic_evol_110k | 67,445 | Write a Python function to find the single element in a circularly sorted array where every element appears exactly twice, except for one element which appears exactly once. The function should run in O(log n) time and use O(1) space.
The code should start with:
```python
from typing import List
def find_single_eleme... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_single_element(nums: List[int]) -> int:
"""
Find the single element in a circularly sorted array where every element appears exactly twice,
except for one element which appears exactly once.... |
magic_evol_110k | 67,452 | Write a Python function to reverse a given hexadecimal string. The function should take a hexadecimal string as input and return the string in reverse order. The function should handle both uppercase and lowercase hexadecimal characters.
The code should start with:
```python
def reverse_hex_string(hex_str: str) -> str... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_hex_string(hex_str: str) -> str:
"""
Reverses a given hexadecimal string.
Args:
hex_str (str): The hexadecimal string to be reversed.
Returns:
str: The reversed hexadecimal string.
Rais... |
magic_evol_110k | 67,460 | Write a Python function to reverse the order of elements in a given list of numerical values. The function should handle lists of any length and return the reversed list. The code should start with:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list of numerical values.
Args:
arr (List[int]): The list of numerical values to be reversed.
... |
magic_evol_110k | 67,464 | Write a Python function to find the maximum sum of a subarray within a given array of integers. The function should return the maximum sum of any contiguous subarray. The code should start with:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given array of integers.
Args:
arr (List[int]): The array of integers.
Return... |
magic_evol_110k | 67,468 | Write a Python function that counts the frequency of each unique integer in a nested list of integers. The function should handle nested lists of arbitrary depth and ignore non-integer values. The function should return a dictionary where the keys are the unique integers and the values are their respective frequencies.... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_numbers(input_list):
"""
Counts the frequency of each unique integer in a nested list of integers.
Args:
input_list (list): A nested list of integers.
Returns:
dict: A dictionary where the key... |
magic_evol_110k | 67,473 | Write a Python function to determine if a given string consists solely of consonants. The function should return `True` if the string contains only consonants, and `False` otherwise. Consonants are defined as any alphabetic character that is not a vowel (i.e., 'a', 'e', 'i', 'o', 'u' and their uppercase counterparts).
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_only_consonants(input_string: str) -> bool:
"""
Determines if the given string consists solely of consonants.
Args:
input_string (str): The string to be checked.
Returns:
bool: True if the string... |
magic_evol_110k | 67,479 | Write a Python function to generate a list of `n` random numbers within a specified range `[min_value, max_value]`. The function should ensure that the generated numbers are unique and sorted in ascending order. The code should start with:
```python
from typing import List
import random
def generate_unique_random_numb... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a list of `n` unique random numbers within the specified range `[min_value, max_value]... |
magic_evol_110k | 67,486 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should handle edge cases such as a 0x0 grid or a grid with only one row or column.
The code should start with:
```python
def unique_p... | Here is the Python code to solve the given problem in the markdown block:
```python
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of rows in the grid.
n (int):... |
magic_evol_110k | 67,499 | Write a Python function to identify all binary numbers from a given list of strings that are divisible by 5. The function should correctly convert each binary string to an integer, check if it is divisible by 5, and return a list of those binary strings that meet the criteria.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_divisible_by_five(binary_list: List[str]) -> List[str]:
"""
Identify and return all binary numbers from a given list of strings that are divisible by 5.
Args:
binary_list (List[str]... |
magic_evol_110k | 67,502 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second s... |
magic_evol_110k | 67,518 | Write a Python function to calculate the average of the square roots of all numbers in a given array. The function should handle both positive and zero numbers. The code should start with:
```python
from typing import List
import math
def average_of_square_roots(numbers: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import math
def average_of_square_roots(numbers: List[int]) -> float:
"""
Calculate the average of the square roots of all numbers in a given list.
Args:
numbers (List[int]): A list of non... |
magic_evol_110k | 67,539 | Write a Python function to determine the indices of the negative elements in each sub-array of a given two-dimensional array. The result should be presented as a list of lists, where each sub-list corresponds to the indices of the negative numbers in the original sub-arrays. The function should handle potential error c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_negative_indices(arr: List[List[int]]) -> List[List[int]]:
"""
Determine the indices of the negative elements in each sub-array of a given two-dimensional array.
Args:
arr (List[Lis... |
magic_evol_110k | 67,540 | Write a Python function to count the number of distinct numerical elements in a multi-dimensional array of integers. The function should correctly handle nested arrays and return the count of unique elements across all layers of arrays. The provided erroneous code needs to be rectified to achieve this.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_distinct_elements(arr: List[List[int]]) -> int:
"""
Count the number of distinct numerical elements in a multi-dimensional array of integers.
Args:
arr (List[List[int]]): A multi-d... |
magic_evol_110k | 67,544 | Write a Python function to arrange a given numeric array of integers such that all elements less than or equal to a specified upper limit `N` are sorted in ascending order, while elements greater than `N` are excluded from the result. The function should return the sorted sub-array.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def arrange_array_with_limit(arr: List[int], N: int) -> List[int]:
"""
Arranges the given numeric array such that all elements less than or equal to a specified upper limit `N`
are sorted in ascendin... |
magic_evol_110k | 67,551 | Write a Python function to determine if the product of two given integers is even or odd. The function should return a string "even" if the product is even and "odd" if the product is odd. The code should start with:
```python
def product_parity(a: int, b: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def product_parity(a: int, b: int) -> str:
"""
Determines if the product of two integers is even or odd.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
str: "even" if th... |
magic_evol_110k | 67,558 | Write a Python function to replace every instance of the numerical value "7" with the symbol "#" in a given digital sequence. The digital sequence can be a string or an integer. The function should handle both types of input and return the modified sequence as a string.
The code should start with:
```python
def replac... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_seven_with_hash(sequence: str) -> str:
"""
Replace every instance of the numerical value "7" with the symbol "#" in a given digital sequence.
Args:
sequence (str): The digital sequence (either a string o... |
magic_evol_110k | 67,562 | Write a Python function to generate all possible permutations of pairs formed by elements from two given lists. Each pair should consist of one element from the first list and one element from the second list. The function should return a list of tuples, where each tuple represents a pair.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_permutations(list1: List[int], list2: List[int]) -> List[Tuple[int, int]]:
"""
Generates all possible permutations of pairs formed by elements from two given lists.
... |
magic_evol_110k | 67,563 | Write a Python function to count the number of negative numbers in a given 2D matrix that is sorted in decreasing order both row-wise and column-wise. The function should efficiently utilize the properties of the matrix to avoid checking every element.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_negative_numbers(matrix: List[List[int]]) -> int:
"""
Counts the number of negative numbers in a given 2D matrix that is sorted in decreasing order both row-wise and column-wise.
Args:
... |
magic_evol_110k | 67,574 | Write a Python function to implement the Bubble Sort algorithm. The function should take a list of integers as input and return the sorted list. The function should be efficient and handle edge cases such as an empty list or a list with a single element.
The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Bubble Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
Li... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.