source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
19,110
Write a Python function to convert a given string into its binary representation using the ASCII standard for each character. The function should return a string where each byte (8 bits) of the binary representation is separated by a space. The code should start with: ```python def string_to_binary(s: str) -> str: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_binary(s: str) -> str: """ Converts a given string into its binary representation using the ASCII standard. Args: s (str): The input string to be converted. Returns: str: A string where ea...
evol_instruct_66k
19,119
Write a Python function to create a distinct list containing the union of two input lists. The union should include all unique elements from both lists. The function should handle lists of integers and return a sorted list of distinct elements. The code should start with: ```python from typing import List def union_o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def union_of_lists(list1: List[int], list2: List[int]) -> List[int]: """ Returns a sorted list of distinct elements that are present in either of the two input lists. Args: list1 (List[int])...
evol_instruct_66k
19,120
Write a Python function to identify the month from a given date string in the format "DD/MM/YYYY". The function should return the name of the month as a string. The code should start with: ```python def identify_month(date: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def identify_month(date: str) -> str: """ Identifies the month from a given date string in the format "DD/MM/YYYY". Args: date (str): The date string in the format "DD/MM/YYYY". Returns: str: The name o...
evol_instruct_66k
19,147
Write a Python function to generate a Fibonacci sequence of a given length `n`. The function should return a list containing the first `n` Fibonacci numbers. If `n` is less than or equal to 0, the function should return an empty list. The code should start with: ```python from typing import List def generate_fibonacc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci_sequence(n: int) -> List[int]: """ Generates a Fibonacci sequence of length n. Args: n (int): The length of the Fibonacci sequence to generate. Returns: L...
evol_instruct_66k
19,155
Write a Python function to create an email address with additional mailing parameters. The function should take a name, a domain, and a dictionary of mail parameters, and return a formatted email address string. The email address should be in the format `name@domain.com?param1=value1&param2=value2...`, where the parame...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_email_with_parameters(name: str, domain: str, mail_parameters: Dict[str, str]) -> str: """ Creates an email address with additional mailing parameters appended as query strings. Args: ...
evol_instruct_66k
19,172
Write a Python function to obtain the distinct elements from a given series of numeric integers. The function should perform a two-step process: firstly identifying repetitions and subsequently eliminating them. The function should be efficient and avoid using built-in set operations directly. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_distinct_elements(series: List[int]) -> List[int]: """ Obtain the distinct elements from a given series of numeric integers. Args: series (List[int]): The series of numeric integers ...
evol_instruct_66k
19,180
Write a Python function to reverse the order of words in a given sentence. The function should take a string as input and return a new string with the words in reverse order. The words in the input string are separated by spaces. The code should start with: ```python def reverse_words_order(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_words_order(sentence: str) -> str: """ Reverses the order of words in a given sentence. Args: sentence (str): The input sentence whose words are to be reversed. Returns: str: A new string ...
evol_instruct_66k
19,181
Write a Python function to perform cross-multiplication on two given numerical values and return the result. The function should handle any pair of integers or floating-point numbers. The code should start with: ```python def cross_multiply(num_1: float, num_2: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def cross_multiply(num_1: float, num_2: float) -> float: """ Perform cross-multiplication on two given numerical values and return the result. Args: num_1 (float): The first numerical value. num_2 (float): T...
evol_instruct_66k
19,183
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. """ # ...
evol_instruct_66k
19,185
Write a Python function to filter out all negative numbers from a given matrix. The matrix is represented as a list of lists, where each inner list represents a row in the matrix. The function should return a new matrix containing only the non-negative numbers from the original matrix. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_negative_numbers(matrix: List[List[int]]) -> List[List[int]]: """ Filters out all negative numbers from a given matrix. Args: matrix (List[List[int]]): A 2D list representing the ...
evol_instruct_66k
19,188
Write a Python function to transform a decimal number into a currency layout adhering to the United States Dollar (USD) format standardization. The function should format the number with commas as thousand separators and round it to two decimal places, prefixed with a dollar sign. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python def format_usd(decimal_number: float) -> str: """ Formats a decimal number into a currency layout adhering to the United States Dollar (USD) format. Args: decimal_number (float): The decimal number to be formatted. ...
evol_instruct_66k
19,191
Write a Python function to convert a given list of integers into a dictionary where each integer in the list is a key, and the corresponding value is the square of the integer represented as a string. The function should handle lists of any length, including empty lists. The code should start with: ```python from typi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def list_to_squared_dict(lst: List[int]) -> Dict[int, str]: """ Converts a list of integers into a dictionary where each integer is a key, and the corresponding value is the square of the integ...
evol_instruct_66k
19,192
Write a Python function to reverse a given DNA sequence and replace each nucleotide with its DNA complement according to the base pairing rules (A-T, T-A, C-G, and G-C). The function should handle only valid DNA sequences consisting of the characters 'A', 'T', 'C', and 'G'. The code should start with: ```python def rev...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_complement_dna_sequence(dna_sequence: str) -> str: """ Reverses the given DNA sequence and replaces each nucleotide with its DNA complement. Args: dna_sequence (str): The DNA sequence to be processed. It...
evol_instruct_66k
19,204
Write a Python function to compute the sum of the individual digits of a given integer. The function should handle both positive and negative integers. The code should start with: ```python def sum_of_digits(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def sum_of_digits(number: int) -> int: """ Computes the sum of the individual digits of a given integer. Args: number (int): The integer whose digits are to be summed. Returns: int: The sum of the ind...
evol_instruct_66k
19,221
Write a Python function to generate a 2D array of random floating point numbers within a specified range. The function should accept the number of rows, number of columns, and the range (minimum and maximum values) as parameters. The function should return the generated 2D array. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random def generate_random_2d_array(num_rows: int, num_columns: int, range_min: float, range_max: float) -> List[List[float]]: """ Generate a 2D array of random floating point numbers withi...
evol_instruct_66k
19,224
Write a Python function to calculate the mean value of a given list of numbers. The function should take a list of integers as input and return the mean value as a float. The code should start with: ```python from typing import List def calculate_mean(numbers: List[int]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mean(numbers: List[int]) -> float: """ Calculate the mean value of a given list of integers. Args: numbers (List[int]): A list of integers for which the mean value is to be cal...
evol_instruct_66k
19,236
Write a Python function to detect even numbers in a 2D matrix and determine their positions. The matrix can range from 1 x 1 to 100 x 100. The function should return a list of tuples where each tuple contains the even number and its position (row index, column index) in the matrix. 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, Tuple def find_even_numbers_in_matrix(matrix: List[List[int]]) -> List[Tuple[int, int, int]]: """ Detects even numbers in a 2D matrix and returns their positions. Args: matrix (List[List[in...
evol_instruct_66k
19,237
Write a Python function to merge two arrays of characters derived from provided alphabetic sequences and then sort the merged array in ascending lexicographical order and then in ascending sequence length order. The function should start with: ```python from typing import List def merge_and_sort_sequences(sequence1: s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_sequences(sequence1: str, sequence2: str) -> List[str]: """ Merges two arrays of characters derived from provided alphabetic sequences and sorts the merged array in ascending lexicogra...
evol_instruct_66k
19,255
Write a Python function to convert a matrix of hexadecimal strings to a matrix of their corresponding decimal values. The matrix is represented as a list of strings, where each string is a hexadecimal number prefixed with '0x'. The function should return a list of integers, each representing the decimal equivalent of t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def hex_to_dec_matrix(matrix_data: List[str]) -> List[int]: """ Converts a matrix of hexadecimal strings to a matrix of their corresponding decimal values. Args: matrix_data (List[str]): A l...
evol_instruct_66k
19,276
Write a Python function to duplicate all occurrences of each number in a given array while maintaining the original order of elements. The function should take a list of integers as input and return a new list where each element appears twice in succession. 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 duplicate_elements(array: List[int]) -> List[int]: """ Duplicates all occurrences of each number in the given array while maintaining the original order. Args: array (List[int]): The inp...
evol_instruct_66k
19,289
Write a Python function to reverse a given numerical array using slicing or inherent reversing techniques. The function should take a list of integers as input and return the reversed list. The code should start with: ```python from typing import List def reverse_array(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_array(arr: List[int]) -> List[int]: """ Reverses the given numerical array using slicing. Args: arr (List[int]): The numerical array to be reversed. Returns: List[...
evol_instruct_66k
19,292
Write a Python function to calculate the sum of all elements in a given list. The function should correctly handle the summation process and return the total sum. The code should start with: ```python from typing import List def calculate_sum(items: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(items: List[int]) -> int: """ Calculate the sum of all elements in the given list. Args: items (List[int]): The list of integers whose sum needs to be calculated. Retu...
evol_instruct_66k
19,299
Write a Python function to calculate the product of all even numbers up to a given limit `n` using a while loop. The function should start with: ```python def product_of_evens(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def product_of_evens(n: int) -> int: """ Calculate the product of all even numbers up to a given limit n. Args: n (int): The upper limit up to which the product of even numbers is calculated. Returns: ...
evol_instruct_66k
19,302
Write a Python function to determine if a given list contains any numerical values with decimal precision. The function should return `True` if at least one element in the list is a floating-point number, and `False` otherwise. The code should start with: ```python from typing import List, Union def contains_decimal(s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def contains_decimal(sequence: List[Union[int, float, str]]) -> bool: """ Determines if the given list contains any numerical values with decimal precision. Args: sequence (List[Union...
evol_instruct_66k
19,305
Write a Python function to sort a given array in ascending order using the bubble sort algorithm. The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def bubble_sort(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(nums: List[int]) -> List[int]: """ Sorts a given array in ascending order using the bubble sort algorithm. Args: nums (List[int]): The list of integers to be sorted. Ret...
evol_instruct_66k
19,311
Write a Python function to calculate the Least Common Multiple (LCM) of a set of two positive whole numbers, and optionally a third number. The function should handle the case where the third number is not provided. The code should start with: ```python def calculate_lcm(a: int, b: int, c: int = None) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_lcm(a: int, b: int, c: int = None) -> int: """ Calculate the Least Common Multiple (LCM) of two or three positive whole numbers. Args: a (int): The first positive whole number. b (int): The sec...
evol_instruct_66k
19,317
Write a Python function to calculate the total number of entries (rows) in a given DataFrame. The function should take a DataFrame as input and return the total number of rows. The code should start with: ```python import pandas as pd def count_entries(df: pd.DataFrame) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import pandas as pd def count_entries(df: pd.DataFrame) -> int: """ Calculate the total number of entries (rows) in a given DataFrame. Args: df (pd.DataFrame): The DataFrame for which to count the entries. R...
evol_instruct_66k
19,325
Write a Python function to find the maximum value among three given integers without using the built-in `max` function. The function should compare the values manually and return the largest one. The code should start with: ```python def find_max_of_three(a: int, b: int, c: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_of_three(a: int, b: int, c: int) -> int: """ Find the maximum value among three given integers without using the built-in max function. Args: a (int): The first integer. b (int): The second inte...
evol_instruct_66k
19,326
Write a Python function to determine if it is possible to transform two given lists of integers such that the first list becomes entirely composed of odd numbers while maintaining the same total sum of elements as the second list. If such a transformation is feasible, the function should return "YES"; otherwise, it sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def can_transform_to_all_odds(lst1: List[int], lst2: List[int]) -> str: """ Determines if it is possible to transform lst1 into a list of odd numbers while maintaining the same total sum of elements ...
evol_instruct_66k
19,330
Write a Python function to determine if a given input is divisible by both 5 and 8. The function should handle both numerical values and strings that can be converted to numerical values. If the input is a string that cannot be converted to a number, the function should return `False`. The function should be optimized ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_5_and_8(x) -> bool: """ Determines if a given input is divisible by both 5 and 8. Args: x (int or str): The input to check. Can be either a numerical value or a string that can be converted to a ...
evol_instruct_66k
19,336
Write a Python function to generate all possible combinations of a specified length from a given set of characters. The function should return a list of strings, where each string is a unique combination of the characters. The code should start with: ```python from typing import List def generate_combinations(characte...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import itertools def generate_combinations(characters: str, length: int) -> List[str]: """ Generate all possible combinations of a specified length from a given set of characters. Args: ch...
evol_instruct_66k
19,344
Write a Python function to extract a subsequence of length `n` from a given string `s`. The subsequence should be the first `n` characters of the string if `n` is less than or equal to the length of the string. If `n` is greater than the length of the string, the function should return the entire string. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python def get_subsequence(s: str, n: int) -> str: """ Extracts a subsequence of length `n` from the given string `s`. Args: s (str): The input string from which to extract the subsequence. n (int): The length of t...
evol_instruct_66k
19,345
Write a Python function to calculate the length of each string in a given list of strings. The function should return a list containing the lengths of the strings in the same order as they appear in the input list. The code should start with: ```python from typing import List def string_lengths(str_list: List[str]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_lengths(str_list: List[str]) -> List[int]: """ Calculate the length of each string in a given list of strings. Args: str_list (List[str]): A list of strings for which to calculate...
evol_instruct_66k
19,348
Write a Python function to count the frequency of a given digit in an array of integers. The function should iterate through each element in the array, check if it matches the given digit, and increment a counter if it does. The function should return the total count of the digit in the array. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_digit_frequency(arr: List[int], digit: int) -> int: """ Counts the frequency of a given digit in an array of integers. Args: arr (List[int]): The array of integers to search. ...
evol_instruct_66k
19,381
Write a Python function to rearrange the words in a given sentence into alphabetical order, considering edge cases where the words include numbers or special characters. The function should handle any given sentence and return the new sentence with words in alphabetical order. The code should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def alphabetize_sentence(sentence: str) -> str: """ Rearranges the words in a given sentence into alphabetical order. Args: sentence (str): The input sentence to be alphabetized. Returns: str: The sente...
evol_instruct_66k
19,403
Write a Python function to find the index of the first non-repeating character in a given string. The function should handle edge cases such as strings with all repeating characters, strings with unique or rare symbols, and empty strings. The function should return -1 for these edge cases. The code should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional def first_uniq_char(s: str) -> Optional[int]: """ Find the index of the first non-repeating character in the given string. Args: s (str): The input string to search for the first non-rep...
evol_instruct_66k
19,406
Write a Python function to determine the student's school year based on the number of years of study. The function should return the appropriate school year as a string: "Freshman" for 1 year, "Sophomore" for 2 years, "Junior" for 3 years, and "Senior" for 4 or more years. The code should start with: ```python def det...
Here is the Python code to solve the given problem in the markdown block: ```python def determine_school_year(years_of_study: int) -> str: """ Determine the student's school year based on the number of years of study. Args: years_of_study (int): The number of years the student has been studying. ...
evol_instruct_66k
19,414
Write a Python function to rotate the items within a square matrix to the right by a specified number of steps. The rotation should not distort the original structure of the matrix, and the user should be able to specify the number of rotation steps. The function should handle any size of square matrix and any non-nega...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_square_matrix(matrix: List[List[int]], steps: int) -> List[List[int]]: """ Rotates a square matrix to the right by a specified number of steps. Args: matrix (List[List[int]]): The...
evol_instruct_66k
19,421
Write a Python function to swap elements between two arrays of words while preserving their respective indices. The function should ensure that both arrays have the same length before performing the swap. If the arrays do not have the same length, the function should return a message indicating that the arrays should h...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def swap_elements(array1: List[str], array2: List[str]) -> Tuple[List[str], List[str]]: """ Swaps elements between two arrays of words while preserving their respective indices. Args: ...
evol_instruct_66k
19,422
Write a Python function to partition a list of integers into a pair of nested lists, where the first list contains all even numbers and the second list contains all odd numbers. The function should handle an empty list and ensure that the order of elements is preserved within each nested list. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def partition_list(lst: List[int]) -> Tuple[List[int], List[int]]: """ Partition a list of integers into a pair of nested lists, where the first list contains all even numbers and the second l...
evol_instruct_66k
19,428
Write a Python function to consolidate a list of disparate alphabetic characters into a single, unbroken text string. The function should handle any list of characters, including spaces and special characters. The code should start with: ```python from typing import List def consolidate_characters(characters: List[str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def consolidate_characters(characters: List[str]) -> str: """ Consolidates a list of disparate alphabetic characters into a single, unbroken text string. Args: characters (List[str]): A list...
evol_instruct_66k
19,431
Write a Python function to convert a given string into a list of words without using the built-in `split()`, `splitlines()`, or any other string separation functions. The function should handle multiple spaces between words and leading/trailing spaces. 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 string_to_list(s: str) -> List[str]: """ Converts a given string into a list of words without using built-in string separation functions. Args: s (str): The input string to be converted....
evol_instruct_66k
19,445
Write a Python function to correct the punctuation in a given sentence by replacing all erroneous punctuation marks with the proper ones. The function should specifically replace colons (`:`) with commas (`,`), semicolons (`;`) with periods (`.`), and exclamation marks (`!`) with question marks (`?`). The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python def fix_punctuation(sentence: str) -> str: """ Corrects the punctuation in a given sentence by replacing colons with commas, semicolons with periods, and exclamation marks with question marks. Args: sentence (st...
evol_instruct_66k
19,452
Write a Python function to calculate the volume of a right rectangular prism given its length, width, and height. The function should handle non-negative numerical inputs and return the volume as a float. The code should start with: ```python def calculate_volume(length: float, width: float, height: float) -> float: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_volume(length: float, width: float, height: float) -> float: """ Calculate the volume of a right rectangular prism given its length, width, and height. Args: length (float): The length of the prism. ...
evol_instruct_66k
19,453
Write a Python function to replace tuples containing a specific element with a new given tuple in a list of tuples. The function should take three parameters: the list of tuples, the element to match, and the replacement tuple. The function should return the modified list of tuples. 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, Tuple, Any def replace_tuples_with_element(tuples_list: List[Tuple[Any, ...]], match_element: Any, replacement: Tuple[Any, ...]) -> List[Tuple[Any, ...]]: """ Replace tuples containing a specific elemen...
evol_instruct_66k
19,486
Write a Python function to perform a source-to-source transformation and optimization of the given code snippet. The function should take four integers as input and return three calculated values. The original code calculates three variables `x`, `y`, and `z` using simple arithmetic operations. The task is to optimize ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_optimized(a: int, b: int, c: int, d: int) -> tuple: """ Optimizes the calculation of three variables by directly returning the results of arithmetic operations. Args: a (int): The first integer input. ...
evol_instruct_66k
19,488
Write a Python function to insert a given `value` into a dictionary `dic` at a specified `key` without using any built-in functions or methods that directly modify the dictionary. Handle key collisions by appending the value to a list stored at the key. If the key does not exist, create a new list with the value. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def insert_into_dict(dic: dict, key: str, value: any) -> None: """ Insert a value into a dictionary at a specified key without using built-in methods. If the key already exists, append the value to the list stored at that ke...
evol_instruct_66k
19,499
Write a Python function to find all the prime factors of a given integer `n`. The function should return a list of prime factors, including their multiplicities. The code should start with: ```python from typing import List def prime_factors(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def prime_factors(n: int) -> List[int]: """ Find all the prime factors of a given integer `n`, including their multiplicities. Args: n (int): The integer for which to find the prime factor...
evol_instruct_66k
19,504
Write a Python function to calculate the sum of all integers starting at 0 and incrementing by 1 up to and including a given number `n`. The function should efficiently compute the sum using a mathematical formula rather than a loop. The code should start with: ```python def sum_of_integers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_integers(n: int) -> int: """ Calculate the sum of all integers starting at 0 and incrementing by 1 up to and including the given number n. Args: n (int): The upper limit of the sequence (inclusive). ...
evol_instruct_66k
19,507
Write a Python function to simulate the behavior of JavaScript's `for...in` loop, which iterates over all enumerable properties of an object, including those inherited via its prototype chain. The function should take a dictionary representing an object and a list of dictionaries representing its prototype chain, and r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def iterate_properties(obj: Dict, prototype_chain: List[Dict]) -> List[Tuple[str, any]]: """ Simulate the behavior of JavaScript's `for...in` loop to iterate over all enumerable properties o...
evol_instruct_66k
19,511
Write a Python function to construct a dictionary that contains the frequency and the positions of each character from a given string without including any duplicates. The character should be the key, whereas the value should be another dictionary containing `frequency` and a list of `positions` respectively. The funct...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def character_frequency_positions(string: str) -> Dict[str, Dict[str, int or List[int]]]: """ Constructs a dictionary that contains the frequency and the positions of each character from a given st...
evol_instruct_66k
19,515
Write a Python function to accept an array of integers and return an array containing the unique elements in ascending order. The function must handle array lengths up to \(10^5\) and negative elements. The code should start with: ```python from typing import List def unique_sorted_elements(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 unique_sorted_elements(arr: List[int]) -> List[int]: """ Returns a list of unique elements from the input array in ascending order. Args: arr (List[int]): The input array of integers. ...
evol_instruct_66k
19,523
Write a Python function that generates a list of the first n even numbers using a generator expression. The function should take an integer `n` as input and return a list of the first `n` even numbers. The code should start with: ```python from typing import List def generate_first_n_evens(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_first_n_evens(n: int) -> List[int]: """ Generates a list of the first n even numbers using a generator expression. Args: n (int): The number of even numbers to generate. Re...
evol_instruct_66k
19,531
Write a Python function to solve the Traveling Salesman Problem (TSP) using the Nearest Neighbor heuristic. The function should take a list of cities represented as tuples of coordinates (x, y) and return the shortest path that visits all cities exactly once and returns to the starting city. The path should be represen...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def traveling_salesman_nearest_neighbor(cities: List[Tuple[int, int]]) -> List[int]: """ Solve the Traveling Salesman Problem using the Nearest Neighbor heuristic. Args: cities (List[...
evol_instruct_66k
19,546
Write a Python function to identify and count occurrences of the pattern where a single 'a' is immediately followed by a triplet of 'b's in a given string. The function should return the count of such patterns found in the string. The code should start with: ```python import re def count_abbb_patterns(input_str: str)...
Here is the Python code to solve the given problem in the markdown block: ```python import re def count_abbb_patterns(input_str: str) -> int: """ Counts the occurrences of the pattern 'abbb' in the given input string. Args: input_str (str): The input string to search for the pattern. Returns:...
evol_instruct_66k
19,554
Write a Python function to remove duplicates from a given list while preserving the order of the elements. The function should take a list of integers as input and return a new list with all duplicate elements removed. The code should start with: ```python from typing import List def remove_duplicates(input_list: List...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def remove_duplicates(input_list: List[int]) -> List[int]: """ Removes duplicates from the given list while preserving the order of the elements. Args: input_list (List[int]): The list of ...
evol_instruct_66k
19,555
Write a Python function to find the minimum value in a tuple of 15 elements. The function should handle tuples with exactly 15 elements and return the minimum value. If the input tuple does not have exactly 15 elements, the function should raise a `ValueError`. 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 Tuple def find_minimum_value(tup: Tuple[int, ...]) -> int: """ Find the minimum value in a tuple of exactly 15 elements. Args: tup (Tuple[int, ...]): A tuple containing exactly 15 integers. ...
evol_instruct_66k
19,561
Write a Python function to classify a list of books based on the author's nationality. The function should take a list of dictionaries, where each dictionary represents a book with keys `"title"` and `"author"`. The function should return a dictionary where the keys are the nationalities of the authors and the values a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def classify_books_by_nationality(books: List[Dict[str, str]]) -> Dict[str, List[Dict[str, str]]]: """ Classify a list of books based on the author's nationality. Args: books (List[Dic...
evol_instruct_66k
19,562
Write a Python function to determine the top `n` most frequent words in a given text. The function should handle case-insensitive word counting and should return the top `n` words along with their frequencies as a list of tuples. The code should start with: ```python from typing import List, Tuple import re from collec...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import re from collections import Counter def top_n_frequent_words(text: str, n: int) -> List[Tuple[str, int]]: """ Determine the top n most frequent words in a given text. Args: text...
evol_instruct_66k
19,564
Write a Python function to implement the Bubble Sort algorithm, which sorts a list of integers in ascending order. The function should be efficient in terms of time complexity and should handle any size of the input list. The code should start with: ```python from typing import List def bubble_sort(arr: List[int]) -> ...
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...
evol_instruct_66k
19,575
Write a Python function to determine if a specified integer exists within a two-dimensional numerical array and return its coordinates (row, column). The array can be up to 100x100 in size. If the integer is not found, the function should return `None`. The code should start with: ```python from typing import List, Tu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_integer_in_2d_array(arr: List[List[int]], x: int) -> Optional[Tuple[int, int]]: """ Determines if a specified integer exists within a two-dimensional numerical array and returns...
evol_instruct_66k
19,581
Write a Python function to sort a given list of integers in ascending order using the Merge Sort algorithm. Merge Sort is a divide-and-conquer algorithm that recursively divides the list into halves, sorts each half, and then merges the sorted halves back together. The function should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def merge_sort(sequence: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the Merge Sort algorithm. Args: sequence (List[int]): The list of integers to be sor...
evol_instruct_66k
19,586
Write a Python function to shuffle the elements of a given dictionary such that each key-value pair is displayed in a random order, ensuring no pair is repeated in subsequent runs. Additionally, balance the shuffle so that each data type ('fruit', 'vegetable', 'meat', 'drink', 'grain') appears only once before repeatin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple import random def balanced_shuffle_dict(input_dict: Dict[str, str]) -> Dict[str, str]: """ Shuffles the elements of a given dictionary such that each key-value pair is displayed in a random ...
evol_instruct_66k
19,593
Write a Python function to determine if a given positive integer is a power of four. The function should not use any built-in mathematical functions or operators, and it should optimize for time complexity. The function should start with: ```python def is_power_of_four(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_four(n: int) -> bool: """ Determine if a given positive integer is a power of four. Args: n (int): The positive integer to check. Returns: bool: True if the integer is a power of four, F...
evol_instruct_66k
19,595
Write a Python function to compute the Euclidean distance from a single reference point to every other point in a given list of points. The function should return a list of distances corresponding to each point in the input list. The code should start with: ```python from typing import List, Tuple import math def com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math def compute_euclidean_distances(ref_point: Tuple[float, float], points: List[Tuple[float, float]]) -> List[float]: """ Compute the Euclidean distance from a reference point to every ot...
evol_instruct_66k
19,598
Write a Python function to search for a given string in an array of strings and return the index of the first occurrence of the target string. If the target string is not found, return -1. The function should be efficient and handle edge cases such as an empty array or a target string that does not exist in the array. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def search_string(array: List[str], target: str) -> int: """ Searches for a given string in an array of strings and returns the index of the first occurrence. If the target string is not found, retur...
evol_instruct_66k
19,605
Write a Python function to iterate through a given list and return a new list containing each element followed by its index. The function should handle lists of any data type and length. The code should start with: ```python from typing import List, Any def indexed_elements(elements: List[Any]) -> List[tuple]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Any def indexed_elements(elements: List[Any]) -> List[tuple]: """ Returns a list of tuples where each tuple contains an element from the input list and its index. Args: elements (List[Any...
evol_instruct_66k
19,609
Write a Python function to compute the sum of the elements placed diagonally in a given two-dimensional array. The function should handle square matrices of any size. The code should start with: ```python from typing import List def diagonal_sum(matrix: List[List[int]]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def diagonal_sum(matrix: List[List[int]]) -> int: """ Compute the sum of the elements placed diagonally in a given two-dimensional square matrix. Args: matrix (List[List[int]]): A two-dimens...
evol_instruct_66k
19,610
Write a Python function to generate a list of integers starting from the first positive integer up to a specified value `n`. The function should handle cases where `n` is a positive integer, zero, or a negative integer. If `n` is zero or negative, the function should return an empty list. The code should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_integer_list(n: int) -> List[int]: """ Generate a list of integers starting from 1 up to a specified value `n`. Args: n (int): The upper limit of the range of integers to genera...
evol_instruct_66k
19,625
Write a Python function to reverse the digits of a given 32-bit signed integer `x` and return the result. If the reversed integer exceeds the boundaries of a 32-bit signed integer (`[-2^31, 2^31 - 1]`), the function should return `0`. The environment does not permit the use of 64-bit integers. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_integer(x: int) -> int: """ Reverses the digits of a given 32-bit signed integer and returns the result. If the reversed integer exceeds the boundaries of a 32-bit signed integer, the function returns 0. ...
evol_instruct_66k
19,630
Write a Python function to implement the bubble sort algorithm that sorts a given list of integers in ascending order. The function should print the state of the array after each iteration of the outer loop and after each swap operation within the inner loop. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_with_steps(array: List[int]) -> List[int]: """ Sorts the given list of integers using the bubble sort algorithm and prints the state of the array after each iteration and swap operation. ...
evol_instruct_66k
19,644
Write a Python function to determine the commission rate based on the gross sales amount. The commission rate should be calculated according to the following rules: - If the gross sales are greater than or equal to $10,000, the commission rate is 10%. - If the gross sales are between $5,000 and $9,999 (inclusive), the ...
Here is the Python code to solve the given problem in the markdown block: ```python def determine_commission_rate(gross_sales: float) -> float: """ Determine the commission rate based on the gross sales amount. Args: gross_sales (float): The gross sales amount. Returns: float: The comm...
evol_instruct_66k
19,648
Write a Python function to decode a given earmarked text string using a predefined translation scheme. The translation scheme is provided as a dictionary where each key is a character in the input string, and the corresponding value is the character it should be translated to. The function should handle any string and ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def decode_string(decoding_cipher: Dict[str, str], string: str) -> str: """ Decodes a given string using a predefined translation scheme. Args: decoding_cipher (Dict[str, str]): A dict...
evol_instruct_66k
19,659
Write a Python function to determine if a given alphanumeric character is present in a string that may contain both alphabetic and non-alphabetic symbols. The function should return `True` if the character is found in the string, and `False` otherwise. The code should start with: ```python def is_character_in_string(st...
Here is the Python code to solve the given problem in the markdown block: ```python def is_character_in_string(string: str, character: str) -> bool: """ Determines if a given alphanumeric character is present in a string. Args: string (str): The string to search within. character (str): The...
evol_instruct_66k
19,663
Write a Python function to calculate the total sum of all elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def total_sum(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def total_sum(lst: List[int]) -> int: """ Calculate the total sum of all elements in a given list of integers. Args: lst (List[int]): The list of integers whose sum is to be calculated. ...
evol_instruct_66k
19,673
Write a Python function to find the median of a given set of numbers. The function should sort the numbers in descending order manually (without using built-in sorting functions) and then determine the median. The median is the middle number in an ordered set if the set has an odd number of elements, or the average of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median_of_numbers(nums: List[int]) -> float: """ Find the median of a given set of numbers after sorting them in descending order. Args: nums (List[int]): The list of numbers to fin...
evol_instruct_66k
19,692
Write a Python function to filter out all elements with a numeric value of zero from a given list. The function should return a new list containing only the non-zero elements. The code should start with: ```python from typing import List def filter_zeros(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 filter_zeros(arr: List[int]) -> List[int]: """ Filters out all zero elements from the given list and returns a new list containing only the non-zero elements. Args: arr (List[int]): Th...
evol_instruct_66k
19,709
Write a Python function to calculate the arithmetic mean of a given list of discrete numerical elements. The function should handle lists of any length, including empty lists, and return `None` for empty lists. The code should start with: ```python from typing import List, Optional def calculate_mean(array: List[int])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def calculate_mean(array: List[int]) -> Optional[float]: """ Calculate the arithmetic mean of a given list of discrete numerical elements. Args: array (List[int]): The list of disc...
evol_instruct_66k
19,713
Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should return a new list with the duplicates removed. The code should start with: ```python from typing import List def remove_duplicates(lst: List[int]) -> List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(lst: List[int]) -> List[int]: """ Removes duplicate elements from the given list while preserving the order of the first occurrence of each element. Args: lst (List[int...
evol_instruct_66k
19,714
Write a Python function to calculate the arithmetic mean of a given list of numbers. The function should handle lists of integers and floating-point numbers. Additionally, the function should return `None` if the input list is empty to avoid division by zero. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union, Optional def calculate_arithmetic_mean(numbers: List[Union[int, float]]) -> Optional[float]: """ Calculate the arithmetic mean of a list of numbers. Args: numbers (List[Union[int, fl...
evol_instruct_66k
19,728
Write a Python function to reverse a given string while preserving the order of characters within the string. The function should handle any alphanumeric characters and special characters, ensuring that the reversed string maintains the integrity of each character's position relative to its neighbors. The code should ...
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 while preserving the order of characters. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ ...
evol_instruct_66k
19,755
Write a Python function to calculate the distance between two 2D points using different distance metrics: Euclidean, Manhattan, and Chebyshev. The function should accept two points represented as tuples of two floating-point numbers and a string indicating the distance metric to use. The function should return the calc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import math def calculate_distance(point1: Tuple[float, float], point2: Tuple[float, float], metric: str) -> float: """ Calculate the distance between two 2D points using the specified distance metric. ...
evol_instruct_66k
19,760
Write a Python function to count the number of unique characters in each of the three given strings. The function should return a tuple containing the count of unique characters for each string. The code should start with: ```python from typing import Tuple def count_unique_characters(s1: str, s2: str, s3: str) -> Tup...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def count_unique_characters(s1: str, s2: str, s3: str) -> Tuple[int, int, int]: """ Counts the number of unique characters in each of the three given strings. Args: s1 (str): The first stri...
evol_instruct_66k
19,765
Write a Python function to sort a list of alphanumeric strings based on the numeric digit embedded in each string. Each string contains exactly one digit. The function should return the sorted list. The code should start with: ```python from typing import List def sort_by_embedded_digit(strings: List[str]) -> List[st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_by_embedded_digit(strings: List[str]) -> List[str]: """ Sorts a list of alphanumeric strings based on the numeric digit embedded in each string. Args: strings (List[str]): A list of...
evol_instruct_66k
19,769
Write a Python function to determine the number of distinct ways to climb a staircase with `n` steps, where a person can either take 1 or 2 steps at a time. The function should use dynamic programming to efficiently compute the result. The code should start with: ```python def climb_stairs(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def climb_stairs(n: int) -> int: """ Calculate the number of distinct ways to climb a staircase with n steps. A person can either take 1 or 2 steps at a time. Args: n (int): The number of steps in the staircase....
evol_instruct_66k
19,774
Write a Python function to retain the first occurrence of each integer in a given array of integers, discarding any repeated occurrences, and return the array in its original order. The function should not use any built-in functions or additional libraries. 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 retain_first_occurrences(arr: List[int]) -> List[int]: """ Retains the first occurrence of each integer in the given array and discards any repeated occurrences, returning the array in its origin...
evol_instruct_66k
19,777
Write a Python function to swap the positions of two elements in a given list. The function should handle cases where the positions are out of bounds by returning the original list unchanged. The code should start with: ```python from typing import List def swap_elements(arr: List[int], pos1: int, pos2: int) -> List[i...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def swap_elements(arr: List[int], pos1: int, pos2: int) -> List[int]: """ Swaps the elements at the given positions in the list. Args: arr (List[int]): The list in which to swap elements. ...
evol_instruct_66k
19,779
Write a Python function to find and return a list of indices where a specified target integer appears in a given collection of integers. Additionally, the function should display the index of the initial instance where the target is first encountered. If the target does not appear in the collection, the function should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_indices_and_display_first(nums: List[int], target: int) -> List[int]: """ Finds and returns a list of indices where the specified target integer appears in the given collection of integers. ...
evol_instruct_66k
19,794
Write a Python function to identify the integer that appears with the highest frequency in a given list of numbers. If there are multiple integers with the same highest frequency, return the smallest integer among them. The code should start with: ```python from typing import List def most_frequent_integer(numbers: L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def most_frequent_integer(numbers: List[int]) -> int: """ Identify the integer that appears with the highest frequency in the given list of numbers. If there are multi...
evol_instruct_66k
19,800
Write a Python function to count the number of rows in a given DataFrame. The function should handle and display an error message if the input is not a DataFrame or if the DataFrame is empty. The code should start with: ```python from typing import Union import pandas as pd def count_rows_in_dataframe(df: Union[pd.Dat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union import pandas as pd def count_rows_in_dataframe(df: Union[pd.DataFrame, None]) -> int: """ Count the number of rows in a given DataFrame. Args: df (pd.DataFrame or None): The DataFrame to c...
evol_instruct_66k
19,803
Design a Python function to find the top `n` movies with the highest ratings from a given collection of movies and their ratings. The collection is represented as a dictionary where the keys are movie titles and the values are their ratings. The function should return a list of movie titles sorted by their ratings in d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def top_n_movies(movies: Dict[str, float], n: int) -> List[str]: """ Returns the top n movies with the highest ratings from a given collection of movies and their ratings. Args: movies...
evol_instruct_66k
19,805
Write a Python function to remove a specified element from a given tuple. The function should return a new tuple with the specified element removed. If the element is not present in the tuple, the function should return the original tuple. The code should start with: ```python from typing import Tuple def remove_elem...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def remove_element_from_tuple(original_tuple: Tuple[int], element_to_remove: int) -> Tuple[int]: """ Removes a specified element from a given tuple and returns a new tuple. Args: original_t...
evol_instruct_66k
19,810
Write a Python function to extract and return the tenth and eleventh elements from a given numerical array. The function should handle cases where the array has fewer than eleven elements by returning `None` for the missing elements. The code should start with: ```python from typing import List, Tuple def get_tenth_an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_tenth_and_eleventh_elements(arr: List[int]) -> Tuple[int, int]: """ Extracts and returns the tenth and eleventh elements from a given numerical array. Args: arr (List[int]): T...
evol_instruct_66k
19,819
Write a Python function to compute the cumulative sum of all integer values contained in a multi-tiered dictionary. The dictionary may include nested dictionaries, lists, tuples, integer values, and strings. The function should handle circular references and ignore non-integer values such as strings or floating point n...
Here is the Python code to solve the given problem in the markdown block: ```python def nested_sum(data: dict) -> int: """ Compute the cumulative sum of all integer values in a multi-tiered dictionary. Args: data (dict): The multi-tiered dictionary containing nested dictionaries, lists, tuples, int...
evol_instruct_66k
19,820
Write a Python function to calculate the total sum of all integers in a nested list. The list may contain other data types but ignore them for this calculation. The list may also be nested with more lists, which should also be taken into account. The given list is provided as an initial reference. Note that the list de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def calculate_total(my_list: List[Union[int, str, List]]) -> int: """ Calculate the total sum of all integers in a nested list. Args: my_list (List[Union[int, str, List]]): The nested...
evol_instruct_66k
19,865
Write a Python function to create a dictionary that represents a professional's attributes, including their profession, the span of practice in years, and the operating geographical location. The function should accept these attributes as parameters and return the dictionary. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_professional_attributes(profession: str, span_of_practice: str, location: str) -> Dict[str, str]: """ Creates a dictionary that represents a professional's attributes. Args: profe...
evol_instruct_66k
19,869
Write a Python function to calculate the sum of the squares of all even numbers in a given list. The function should iterate through the list, check if each number is even, and if so, add its square to a running total. The code should start with: ```python from typing import List def sum_of_squares_of_evens(nums: List...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sum_of_squares_of_evens(nums: List[int]) -> int: """ Calculate the sum of the squares of all even numbers in the given list. Args: nums (List[int]): The list of integers to process. ...
evol_instruct_66k
19,885
Write a Python function to identify and collect every prime number within a given range `[start, end]`. The function should return a list of all prime numbers found within this range. The code should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def find_primes_in_range(start: int, end: int) -> List[int]: """ Identify and collect every prime number within the given range [start, end]. Args: start (int): The starting numb...
evol_instruct_66k
19,890
Write a Python function to calculate the cumulative sum of subsequent array elements for a given list of integers. The function should return a list where each element at index `i` is the sum of all elements from the original list up to index `i` (inclusive). The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cumulative_sum(arr: List[int]) -> List[int]: """ Calculate the cumulative sum of subsequent array elements for a given list of integers. Args: arr (List[int]): The input list of integers...
evol_instruct_66k
19,897
Write a Python function to calculate the cumulative total of all positive integers ranging from zero through to a specified number `n`. The function should efficiently compute the sum using a mathematical formula rather than a loop. The code should start with: ```python def cumulative_total(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def cumulative_total(n: int) -> int: """ Calculate the cumulative total of all positive integers from 0 to n using a mathematical formula. Args: n (int): The upper limit of the range of integers to sum. Returns...