source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 2,290 | Write a Python function named `is_not_same_truthiness` that takes two arguments, `obj1` and `obj2`. The function should return `True` if `obj1` and `obj2` do not evaluate to the same truthiness, and `False` otherwise. The function should handle various types of inputs, including but not limited to integers, strings, li... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_truthiness(obj1, obj2) -> bool:
"""
Check if obj1 and obj2 do not evaluate to the same truthiness.
Parameters:
obj1 (Any): The first object to evaluate.
obj2 (Any): The second object to evaluate.
... |
code_exercise_27k | 2,291 | Write a Python function named `are_all_positive` that takes a list of numbers as an argument. The function should return `True` if all numbers in the list are positive (greater than 0), and `False` otherwise. The function should handle an empty list by returning `True`.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_all_positive(numbers: List[int]) -> bool:
"""
Check if all numbers in the given list are positive.
Args:
numbers (List[int]): The list of numbers to check.
Returns:
bool... |
code_exercise_27k | 2,292 | Write a Python function named `is_not_same_positive` that takes two arguments, `num1` and `num2`. The function should return `True` if either `num1` or `num2` is not a positive number, and `False` if both are positive numbers. The function should handle both integers and floating-point numbers.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_positive(num1: int | float, num2: int | float) -> bool:
"""
Check if either num1 or num2 is not a positive number.
Parameters:
num1 (int or float): The first number.
num2 (int or float): The second n... |
code_exercise_27k | 2,293 | Write a Python function named `are_all_negative` that takes a list of numbers as an argument. The function should return `True` if all the numbers in the list are negative (less than 0), and `False` otherwise. The function should handle an empty list by returning `True`.
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
def are_all_negative(numbers: List[int]) -> bool:
"""
Check if all numbers in the list are negative.
Args:
numbers (List[int]): The list of numbers to check.
Returns:
bool: True... |
code_exercise_27k | 2,294 | Write a Python function named `is_not_same_negative` that takes two arguments, `num1` and `num2`. The function should return `True` if either `num1` or `num2` is not a negative number, and `False` if both are negative numbers. The function should handle both integers and floating-point numbers.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_negative(num1: int | float, num2: int | float) -> bool:
"""
Check if either num1 or num2 is not a negative number.
Parameters:
num1 (int or float): The first number.
num2 (int or float): The second n... |
code_exercise_27k | 2,295 | Write a Python function named `are_all_even` that takes a list of integers as an argument. The function should return `True` if all the integers in the list are even numbers, and `False` otherwise.
The code should start with:
```python
from typing import List
def are_all_even(numbers: List[int]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_all_even(numbers: List[int]) -> bool:
"""
Check if all integers in the given list are even numbers.
Args:
numbers (List[int]): The list of integers to check.
Returns:
bo... |
code_exercise_27k | 2,296 | Write a Python function named `is_not_same_even` that takes two arguments, `num1` and `num2`. The function should return `True` if either `num1` or `num2` is not an even number, and `False` if both are even numbers. The function should handle any integer inputs.
The code should start with:
```python
def is_not_same_ev... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_even(num1: int, num2: int) -> bool:
"""
Check if either num1 or num2 is not an even number.
Parameters:
num1 (int): The first number.
num2 (int): The second number.
Returns:
bool: True if ei... |
code_exercise_27k | 2,297 | Write a Python function named `are_both_odd` that takes two arguments, `num1` and `num2`. The function should return `True` if both `num1` and `num2` are odd numbers, and `False` otherwise. The function should handle any integer inputs.
The code should start with:
```python
def are_both_odd(num1: int, num2: int) -> bo... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_both_odd(num1: int, num2: int) -> bool:
"""
Check if both num1 and num2 are odd numbers.
Args:
num1 (int): The first number to check.
num2 (int): The second number to check.
Returns:
boo... |
code_exercise_27k | 2,298 | Write a Python function named `is_not_same_odd` that takes two arguments, `num1` and `num2`. The function should return `True` if either `num1` or `num2` is not an odd number, and `False` if both are odd numbers. The function should handle both positive and negative integers.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_odd(num1: int, num2: int) -> bool:
"""
Check if either num1 or num2 is not an odd number.
Parameters:
num1 (int): The first number.
num2 (int): The second number.
Returns:
bool: True if eith... |
code_exercise_27k | 2,299 | Write a Python function named `are_numbers_divisible` that takes three arguments, `num1`, `num2`, and `divisor`. The function should return `True` if both `num1` and `num2` are divisible by `divisor`, and `False` otherwise. The function should handle cases where `divisor` is zero by returning `False`.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_numbers_divisible(num1: int, num2: int, divisor: int) -> bool:
"""
Check if both num1 and num2 are divisible by divisor.
Args:
num1 (int): The first number.
num2 (int): The second number.
div... |
code_exercise_27k | 2,301 | Write a Python function named `is_same_substring` that takes two arguments, `str1` and `str2`. The function should return `True` if `str1` is a substring of `str2` or vice versa, and `False` otherwise. The function should handle cases where either or both strings are empty.
The code should start with:
```python
def is... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_substring(str1: str, str2: str) -> bool:
"""
Check if str1 is a substring of str2 or vice versa.
Parameters:
str1 (str): The first string.
str2 (str): The second string.
Returns:
bool: True if s... |
code_exercise_27k | 2,303 | Write a Python function named `is_same_palindrome` that takes a single argument, `string`. The function should return `True` if `string` is a palindrome (reads the same forwards and backwards), and `False` otherwise. The function should handle both uppercase and lowercase characters, ignoring case sensitivity. Addition... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_palindrome(string: str) -> bool:
"""
Check if the input string is a palindrome, ignoring case sensitivity and non-alphabetic characters.
Parameters:
string (str): The input string to check.
Returns:
... |
code_exercise_27k | 2,307 | Write a Python function named `is_same_sorted` that takes two arguments, `lst1` and `lst2`. The function should return `True` if `lst1` and `lst2` have the same elements in the same order after being sorted, and `False` otherwise. The function should handle lists of any comparable elements, including integers, strings,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def is_same_sorted(lst1: List[Any], lst2: List[Any]) -> bool:
"""
Check if lst1 and lst2 have the same elements in the same order after sorting.
Parameters:
lst1 (List[Any]): The first list... |
code_exercise_27k | 2,308 | Write a Python function named `is_not_same_sorted` that takes two arguments, `lst1` and `lst2`. The function should return `True` if `lst1` and `lst2` do not have the same elements in the same order, and `False` if `lst1` and `lst2` have the same elements in the same order. The function should also handle cases where t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_not_same_sorted(lst1: List[int], lst2: List[int]) -> bool:
"""
Check if lst1 and lst2 do not have the same elements in the same order.
Args:
lst1 (List[int]): The first list.
... |
code_exercise_27k | 2,310 | Write a Python function named `is_not_same_subset` that takes two arguments, `set1` and `set2`. The function should return `True` if neither `set1` is a subset of `set2` nor `set2` is a subset of `set1`, and `False` if either `set1` is a subset of `set2` or `set2` is a subset of `set1`.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_subset(set1: set, set2: set) -> bool:
"""
Check if neither set1 is a subset of set2 nor set2 is a subset of set1.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 2,311 | Write a Python function named `have_common_elements` that takes two arguments, `set1` and `set2`. The function should return `True` if `set1` and `set2` have at least one common element, and `False` otherwise. The function should be efficient and avoid unnecessary computations.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def have_common_elements(set1: set, set2: set) -> bool:
"""
Check if two sets have at least one common element.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True i... |
code_exercise_27k | 2,312 | Write a Python function named `is_disjoint` that takes two arguments, `set1` and `set2`. The function should return `True` if `set1` and `set2` do not have any common elements, and `False` if `set1` and `set2` have at least one common element. The function should be efficient and should handle any size of sets.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_disjoint(set1: set, set2: set) -> bool:
"""
Check if two sets do not have any common elements.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True if set1 and... |
code_exercise_27k | 2,313 | Write a Python function named `is_same_difference` that takes two arguments, `set1` and `set2`. The function should return `True` if the symmetric difference between `set1` and `set2` is an empty set, and `False` otherwise. The symmetric difference between two sets is defined as the set of elements which are in either ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_difference(set1: set, set2: set) -> bool:
"""
Check if the symmetric difference between set1 and set2 is an empty set.
Parameters:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 2,314 | Write a Python function named `is_not_same_difference` that takes two arguments, `set1` and `set2`. The function should return `True` if the difference between `set1` and `set2` is not an empty set, and `False` if the difference between `set1` and `set2` is an empty set. The function should also handle cases where the ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_difference(set1: set, set2: set) -> bool:
"""
Check if the difference between set1 and set2 is not an empty set.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 2,315 | Write a Python function named `is_same_union` that takes two arguments, `set1` and `set2`. The function should return `True` if the union of `set1` and `set2` is equal to `set1` or equal to `set2`, and `False` otherwise. The function should handle cases where either or both sets are empty.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_union(set1: set, set2: set) -> bool:
"""
Check if the union of set1 and set2 is equal to set1 or equal to set2.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 2,316 | Write a Python function named `is_not_same_union` that takes two arguments, `set1` and `set2`. The function should return `True` if the union of `set1` and `set2` is neither equal to `set1` nor equal to `set2`, and `False` if the union of `set1` and `set2` is equal to `set1` or equal to `set2`.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_union(set1: set, set2: set) -> bool:
"""
Check if the union of set1 and set2 is neither equal to set1 nor equal to set2.
Args:
set1 (set): The first set.
set2 (set): The second set.
Retu... |
code_exercise_27k | 2,318 | Write a Python function named `is_not_same_difference_update` that takes two arguments, `set1` and `set2`. The function should return `True` if the difference between `set1` and `set2` is not an empty set after applying the `difference_update()` method, and `False` if the difference between `set1` and `set2` is an empt... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_difference_update(set1: set, set2: set) -> bool:
"""
Check if the difference between set1 and set2 is not an empty set after applying the difference_update() method.
Parameters:
set1 (set): The first set... |
code_exercise_27k | 2,319 | Write a Python function named `is_same_symmetric_difference` that takes two arguments, `set1` and `set2`. The function should return `True` if the symmetric difference between `set1` and `set2` is an empty set, and `False` otherwise. The symmetric difference of two sets is defined as the set of elements which are in ei... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_symmetric_difference(set1: set, set2: set) -> bool:
"""
Check if the symmetric difference between set1 and set2 is an empty set.
Parameters:
set1 (set): The first set.
set2 (set): The second set.
Re... |
code_exercise_27k | 2,320 | Write a Python function named `is_not_same_symmetric_difference` that takes two arguments, `set1` and `set2`. The function should return `True` if the symmetric difference between `set1` and `set2` is not an empty set, and `False` if the symmetric difference between `set1` and `set2` is an empty set.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_same_symmetric_difference(set1: set, set2: set) -> bool:
"""
Check if the symmetric difference between set1 and set2 is not an empty set.
Args:
set1 (set): The first set.
set2 (set): The second se... |
code_exercise_27k | 2,321 | Write a Python function named `is_empty_container` that takes a single argument, `obj`. The function should return `True` if `obj` is an empty container (such as an empty string, empty list, empty set, empty dictionary, etc.), and `False` otherwise. The function should handle various types of containers and return `Fal... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any
def is_empty_container(obj: Any) -> bool:
"""
Check if the given object is an empty container.
Parameters:
obj (Any): The input object to be checked.
Returns:
bool: True if obj is an emp... |
code_exercise_27k | 2,322 | Write a Python function named `is_not_empty` that takes a single argument, `obj`. The function should return `True` if `obj` is not an empty container (e.g., list, tuple, set, dictionary, string), and `False` if `obj` is an empty container. The function should handle various types of containers and return `False` for n... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_not_empty(obj) -> bool:
"""
Check if the given object is a non-empty container.
Parameters:
obj (Any): The input object to be checked.
Returns:
bool: True if obj is a non-empty container, False if obj is... |
code_exercise_27k | 2,324 | Write a Python function to calculate the difference between two numbers, ensuring that the result is always non-negative. The function should handle both integer and floating-point inputs. The code should start with:
```python
def non_negative_subtraction(num1: float, num2: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def non_negative_subtraction(num1: float, num2: float) -> float:
"""
Calculate the non-negative difference between two numbers.
This function takes two numbers as input and returns the absolute difference between them.
... |
code_exercise_27k | 2,325 | Write a Python function to calculate the product of two numbers using a recursive approach. The function should handle both integer and floating-point inputs. The code should start with:
```python
def recursive_multiplication(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def recursive_multiplication(num1: int, num2: int) -> int:
"""
Calculate the product of two numbers using a recursive approach.
Args:
num1 (int or float): The first number.
num2 (int or float): The second nu... |
code_exercise_27k | 2,326 | Write a Python function named `safe_division` that takes two parameters, `num1` (dividend) and `num2` (divisor), and returns the quotient of the division. If the divisor is zero, the function should return `None` instead of raising an error. The function should handle both integer and floating-point inputs.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_division(num1: int | float, num2: int | float) -> int | float | None:
"""
Safely divides two numbers and returns the quotient. If the divisor is zero, returns None.
Args:
num1 (int | float): The dividend.
... |
code_exercise_27k | 2,327 | Write a Python function to calculate the power of a given base raised to an exponent using an iterative approach. The function should handle both positive and negative exponents, as well as zero exponents. The code should start with:
```python
def power_iterative(base: int, exponent: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def power_iterative(base: int, exponent: int) -> int:
"""
Calculate the power of a given base raised to an exponent using an iterative approach.
Args:
base (int): The base number.
exponent (int): The exponen... |
code_exercise_27k | 2,329 | Write a Python function named `floor_division` that takes two parameters, `num1` (dividend) and `num2` (divisor), and returns the quotient of the division rounded down to the nearest integer. The function should handle both integer and floating-point inputs. The code should start with:
```python
import math
def floor_... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def floor_division(num1: float, num2: float) -> int:
"""
Returns the quotient of num1 divided by num2, rounded down to the nearest integer.
Args:
num1 (float): The dividend.
num2 (float): The di... |
code_exercise_27k | 2,330 | Write a Python function named `ceil_division` that takes two parameters, `num1` (dividend) and `num2` (divisor), and returns the quotient of the division rounded up to the nearest integer. The function should handle cases where the divisor is zero by raising a `ValueError`.
The code should start with:
```python
import... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def ceil_division(num1: int, num2: int) -> int:
"""
Calculate the quotient of num1 divided by num2, rounded up to the nearest integer.
Args:
num1 (int): The dividend.
num2 (int): The divisor.
... |
code_exercise_27k | 2,331 | Write a Python function named `find_maximum` that takes two parameters, `num1` and `num2`, and returns the maximum of the two numbers. The function should handle both integer and floating-point numbers. The code should start with:
```python
def find_maximum(num1: int | float, num2: int | float) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_maximum(num1: int | float, num2: int | float) -> int | float:
"""
Returns the maximum of two numbers.
This function takes two numbers as input and returns the maximum of the two numbers.
The numbers can be eith... |
code_exercise_27k | 2,332 | Write a Python function named `find_minimum` that takes two parameters, `num1` and `num2`, and returns the minimum of the two numbers. The function should handle both integer and floating-point numbers. The code should start with:
```python
def find_minimum(num1: int | float, num2: int | float) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_minimum(num1: int | float, num2: int | float) -> int | float:
"""
Returns the minimum of two numbers.
This function takes two numbers as input and returns the smaller of the two.
The numbers can be either integ... |
code_exercise_27k | 2,333 | Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers. The function should also be efficient by checking divisibility ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(num: int) -> bool:
"""
Determines if a given number is a prime number.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"... |
code_exercise_27k | 2,334 | Write a Python function to calculate the factorial of a given non-negative integer. The function should handle the case where the input is a negative number by raising a `ValueError`. The code should start with:
```python
def factorial(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(num: int) -> int:
"""
Calculate the factorial of a given non-negative integer.
Args:
num (int): The non-negative integer for which to calculate the factorial.
Returns:
int: The factorial o... |
code_exercise_27k | 2,336 | Write a Python function named `calculate_average` that takes a list of numbers as a parameter, `numbers`, and returns the average of the numbers. The function should handle the case where the input list is empty by returning `None` instead of raising an exception. The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_average(numbers: List[float]) -> Optional[float]:
"""
Calculate the average of a list of numbers.
Args:
numbers (List[float]): The list of numbers to calculate the av... |
code_exercise_27k | 2,340 | Write a Python function to determine if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself). The function should return `True` if the number is a perfect number, and `False` otherwise. The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_number(num: int) -> bool:
"""
Determines if a given number is a perfect number.
A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself).
Param... |
code_exercise_27k | 2,341 | Write a Python function named `is_happy_number` that takes one parameter, `num`, and returns `True` if the number is a happy number, and `False` otherwise. A happy number is a number that eventually reaches 1 when replaced by the sum of the squares of its digits, and the process is repeated with the sum until it either... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_happy_number(num: int) -> bool:
"""
Determines if a given number is a happy number.
A happy number is a number that eventually reaches 1 when replaced by the sum of the squares of its digits,
and the process is r... |
code_exercise_27k | 2,342 | Write a Python function named `convert_to_binary` that takes an integer `num` as input and returns a string representing the binary representation of the number. The function should handle both positive and negative integers. The binary representation for negative numbers should be in two's complement form.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_binary(num: int) -> str:
"""
Converts an integer to its binary representation.
For positive integers, the binary representation is returned directly.
For negative integers, the binary representation is re... |
code_exercise_27k | 2,344 | Write a Python function named `convert_to_hexadecimal` that takes an integer `num` as input and returns a string representing the hexadecimal representation of the number. The function should handle both positive and negative integers. The hexadecimal string should be in lowercase and should not include the '0x' prefix... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_hexadecimal(num: int) -> str:
"""
Converts an integer to its hexadecimal representation.
Args:
num (int): The integer to be converted.
Returns:
str: The hexadecimal representation of the ... |
code_exercise_27k | 2,346 | Write a Python function to calculate the factorial of a given number using an iterative implementation. The function should be named `calculate_factorial_iterative` and should take one parameter, `num`. The function should return the factorial of the number.
The code should start with:
```python
def calculate_factoria... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_factorial_iterative(num: int) -> int:
"""
Calculate the factorial of a given number using an iterative implementation.
Parameters:
num (int): The number for which to calculate the factorial.
Returns:
... |
code_exercise_27k | 2,350 | Write a Python function named `calculate_percentage` that takes two parameters, `part` and `whole`, and returns the percentage representation of the part in relation to the whole. The function should handle cases where `whole` is zero by returning `None` to avoid division by zero errors. The function should also ensure... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_percentage(part, whole):
"""
Calculate the percentage representation of the part in relation to the whole.
Parameters:
part (int or float): The part.
whole (int or float): The whole.
Returns:
... |
code_exercise_27k | 2,352 | Write a Python function named `calculate_cube` that takes one parameter, `num`, and returns the cube of the number. The function should handle both integer and floating-point inputs. The code should start with:
```python
def calculate_cube(num: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_cube(num: float) -> float:
"""
Calculate the cube of a given number.
Args:
num (float): The number to calculate the cube of.
Returns:
float: The cube of the input number.
"""
# Cal... |
code_exercise_27k | 2,353 | Write a Python function to calculate the result of raising a base number to a given exponent using a recursive approach. The function should handle both positive and negative exponents. The code should start with:
```python
def calculate_exponential_recursive(base: int, exponent: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_exponential_recursive(base: int, exponent: int) -> int:
"""
Calculate the result of raising a base number to a given exponent using a recursive approach.
Args:
base (int): The base number.
expo... |
code_exercise_27k | 2,354 | Write a Python function named `calculate_square_root` that takes one parameter, `num`, and returns the square root of the number. The function should handle non-negative numbers and return the square root as a float. If the input number is negative, the function should raise a `ValueError` with an appropriate message.
... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_square_root(num: float) -> float:
"""
Calculate the square root of a given non-negative number.
Args:
num (float): The number for which to calculate the square root.
Returns:
... |
code_exercise_27k | 2,356 | Write a Python function to calculate the average of a list of numbers. The function should handle an empty list by raising a `ValueError`. The code should start with:
```python
from typing import List
def calculate_average_of_list(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average_of_list(numbers: List[float]) -> float:
"""
Calculate the average of a list of numbers.
Args:
numbers (List[float]): The list of numbers to calculate the average from.
... |
code_exercise_27k | 2,358 | Write a Python function to calculate the product of all numbers in a given list. The function should handle lists containing integers or floating-point numbers. If the list is empty, the function should raise a `ValueError`.
The code should start with:
```python
from typing import List
from functools import reduce
imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
import operator
def calculate_product_of_list(numbers: List[float]) -> float:
"""
Calculate the product of all numbers in the given list.
Args:
numbers (List[flo... |
code_exercise_27k | 2,359 | Write a Python function named `calculate_factorial_iterative` that takes one parameter, `num`, and returns the factorial of the number using an iterative implementation. The function should handle non-negative integers only. If the input is a negative number, the function should raise a `ValueError`.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_factorial_iterative(num: int) -> int:
"""
Calculate the factorial of a given non-negative integer using an iterative approach.
Parameters:
num (int): The non-negative integer for which to calculate the fac... |
code_exercise_27k | 2,360 | Write a Python function to calculate the number of combinations (nCr) given `n` items and `r` selections. The function should handle edge cases such as when `n` is less than `r` and when `r` is zero. The code should start with:
```python
import math
def calculate_combination(n: int, r: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_combination(n: int, r: int) -> int:
"""
Calculate the number of combinations (nCr) given n items and r selections.
Args:
n (int): The total number of items.
r (int): The number of ... |
code_exercise_27k | 2,361 | Write a Python function to calculate the number of permutations (nPr) given `n` items and `r` selections. The function should handle cases where `n` is less than `r` by raising a `ValueError`. The code should start with:
```python
import math
def calculate_permutation(n: int, r: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_permutation(n: int, r: int) -> int:
"""
Calculate the number of permutations (nPr) given n items and r selections.
Args:
n (int): The total number of items.
r (int): The number of ... |
code_exercise_27k | 2,368 | Write a Python function to calculate the midpoint of a line segment given the coordinates of two points in a 2D plane. The function should take four parameters representing the coordinates of the two points and return the coordinates of the midpoint as a tuple.
The code should start with:
```python
def calculate_midpo... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_midpoint(x1: float, y1: float, x2: float, y2: float) -> tuple:
"""
Calculate the midpoint of a line segment connecting two points in a 2D plane.
Args:
x1 (float): The x-coordinate of the first point.
... |
code_exercise_27k | 2,369 | Write a Python function to calculate the area of a circle given its radius. The function should handle non-negative radius values and return the area as a float. The code should start with:
```python
import math
def calculate_area_of_circle(radius: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import math
def calculate_area_of_circle(radius: float) -> float:
"""
Calculate the area of a circle given its radius.
Args:
radius (float): The radius of the circle. Must be non-negative.
Returns:
f... |
code_exercise_27k | 2,371 | Write a Python function to calculate the area of a rectangle given its length and width. The function should handle non-negative inputs and return the area as a float. The code should start with:
```python
def calculate_area_of_rectangle(length: float, width: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_area_of_rectangle(length: float, width: float) -> float:
"""
Calculate the area of a rectangle given its length and width.
Args:
length (float): The length of the rectangle. Must be non-negative.
... |
code_exercise_27k | 2,372 | Write a Python function to calculate the perimeter of a rectangle given its length and width. The function should handle non-negative inputs and return the perimeter as a float. The code should start with:
```python
def calculate_perimeter_of_rectangle(length: float, width: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_perimeter_of_rectangle(length: float, width: float) -> float:
"""
Calculate the perimeter of a rectangle given its length and width.
Args:
length (float): The length of the rectangle. Must be non-negat... |
code_exercise_27k | 2,373 | Write a Python function to calculate the area of a triangle given its base and height. The function should handle non-negative inputs and return the area as a float. The code should start with:
```python
def calculate_area_of_triangle(base: float, height: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def calculate_area_of_triangle(base: float, height: float) -> float:
"""
Calculate the area of a triangle given its base and height.
Args:
base (float): The base length of the triangle.
height (float): The... |
code_exercise_27k | 2,375 | Write a Python function to calculate the area of a trapezoid given the lengths of its two bases and its height. The function should handle non-negative inputs and return the area as a float. The code should start with:
```python
def calculate_area_of_trapezoid(base1: float, base2: float, height: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_area_of_trapezoid(base1: float, base2: float, height: float) -> float:
"""
Calculate the area of a trapezoid given the lengths of its two bases and its height.
Parameters:
base1 (float): The length of the ... |
code_exercise_27k | 2,376 | Write a Python function to calculate the perimeter of a trapezoid given the lengths of its two bases and one of its sides. The function should handle non-negative inputs and return the perimeter as a float. The code should start with:
```python
def calculate_perimeter_of_trapezoid(base1: float, base2: float, side: floa... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_perimeter_of_trapezoid(base1: float, base2: float, side: float) -> float:
"""
Calculate the perimeter of a trapezoid given the lengths of its two bases and one of its sides.
Args:
base1 (float): The le... |
code_exercise_27k | 2,378 | Write a Python function to calculate the surface area of a cube given its side length. The function should handle non-negative side lengths and return the surface area as a float. The code should start with:
```python
def calculate_surface_area_of_cube(side_length: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_surface_area_of_cube(side_length: float) -> float:
"""
Calculate the surface area of a cube given its side length.
Args:
side_length (float): The side length of the cube. Must be non-negative.
Ret... |
code_exercise_27k | 2,379 | Write a Python function to calculate the volume of a cuboid given its length, width, and height. The function should handle non-negative dimensions and return the volume as a float. The code should start with:
```python
def calculate_volume_of_cuboid(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_of_cuboid(length: float, width: float, height: float) -> float:
"""
Calculate the volume of a cuboid given its length, width, and height.
Args:
length (float): The length of the cuboid.
... |
code_exercise_27k | 2,383 | Write a Python function to calculate the surface area of a sphere given its radius. The function should be named `calculate_surface_area_of_sphere` and should take one parameter, `radius`, and return the surface area of the sphere. The surface area of a sphere is given by the formula \(4 \pi r^2\), where \(r\) is the r... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_surface_area_of_sphere(radius: float) -> float:
"""
Calculate the surface area of a sphere given its radius.
The surface area of a sphere is calculated using the formula:
Surface Area = 4 * π ... |
code_exercise_27k | 2,384 | Write a Python function to calculate the surface area of a sphere given its radius. The function should handle non-negative radius values and return the surface area as a float. The code should start with:
```python
import math
def calculate_surface_area_of_sphere(radius: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import math
def calculate_surface_area_of_sphere(radius: float) -> float:
"""
Calculate the surface area of a sphere given its radius.
Args:
radius (float): The radius of the sphere. Must be non-negative.
Re... |
code_exercise_27k | 2,394 | Write a Python function to calculate the perimeter of a regular polygon given the length of each side and the number of sides. The function should handle input validation to ensure that the side length is positive and the number of sides is at least 3. The code should start with:
```python
def calculate_perimeter_of_re... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_perimeter_of_regular_polygon(side_length: float, num_sides: int) -> float:
"""
Calculate the perimeter of a regular polygon given the length of each side and the number of sides.
Args:
side_length (flo... |
code_exercise_27k | 2,395 | Write a Python function named `calculate_area_of_trapezoid` that takes three parameters, `base1`, `base2`, and `height`, and returns the area of a trapezoid with the given base lengths and height. The function should handle non-negative inputs only. The code should start with:
```python
def calculate_area_of_trapezoid(... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_area_of_trapezoid(base1: float, base2: float, height: float) -> float:
"""
Calculate the area of a trapezoid given the lengths of its two bases and its height.
Parameters:
base1 (float): The length of the ... |
code_exercise_27k | 2,396 | Write a Python function to calculate the surface area of a regular pyramid given its base area and height. The function should handle non-negative inputs and return the surface area as a float. The code should start with:
```python
import math
def calculate_surface_area_of_pyramid(base_area: float, height: float) -> f... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_surface_area_of_pyramid(base_area: float, height: float) -> float:
"""
Calculate the surface area of a regular pyramid given its base area and height.
Args:
base_area (float): The area of ... |
code_exercise_27k | 2,397 | Write a Python function to calculate the volume of a regular pyramid given its base area and height. The function should handle non-negative inputs and return the volume as a float. The code should start with:
```python
def calculate_volume_of_regular_pyramid(base_area: float, height: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_volume_of_regular_pyramid(base_area: float, height: float) -> float:
"""
Calculate the volume of a regular pyramid given its base area and height.
Args:
base_area (float): The area of the base of the p... |
code_exercise_27k | 2,400 | Write a Python function to calculate the surface area of a regular pyramid given its base length and slant height. The function should handle both integer and floating-point inputs and ensure that the base length and slant height are non-negative. The code should start with:
```python
def calculate_area_of_regular_pyra... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_area_of_regular_pyramid(base_length: float, slant_height: float) -> float:
"""
Calculate the surface area of a regular pyramid given its base length and slant height.
Args:
base_length (float): The len... |
code_exercise_27k | 2,404 | Write a Python function named `bitwise_not` that takes an integer as input and returns the result of performing a bitwise NOT operation on it. The function should handle both positive and negative integers correctly. The code should start with:
```python
def bitwise_not(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_not(num: int) -> int:
"""
Perform a bitwise NOT operation on the given integer.
The bitwise NOT operation inverts all the bits of the input integer. For example,
if the input is 5 (which is 101 in binary), t... |
code_exercise_27k | 2,406 | Write a Python function named `bitwise_right_shift` that takes two integers as input and returns the result of performing a bitwise right shift operation on the first integer by the number of positions specified by the second integer. The function should handle both positive and negative integers for the shift operatio... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_right_shift(num: int, shift: int) -> int:
"""
Perform a bitwise right shift operation on the given integer by the specified number of positions.
Args:
num (int): The integer to be shifted.
shift ... |
code_exercise_27k | 2,408 | Write a Python function named `bitwise_set_bit` that takes two integers as input: a number and a position. The function should return the result of setting the bit at the specified position in the number. The bit position is zero-indexed, meaning the least significant bit (rightmost bit) is at position 0.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_set_bit(num: int, position: int) -> int:
"""
Sets the bit at the specified position in the given number.
Args:
num (int): The number in which to set the bit.
position (int): The position of the b... |
code_exercise_27k | 2,410 | Write a Python function named `bitwise_count_set_bits` that takes an integer as input and returns the count of set bits (1s) in its binary representation. The function should efficiently count the number of 1s in the binary representation of the given integer using bitwise operations.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_count_set_bits(num: int) -> int:
"""
Counts the number of set bits (1s) in the binary representation of a given integer.
Args:
num (int): The integer whose set bits are to be counted.
Returns:
... |
code_exercise_27k | 2,417 | Write a Python function named `bitwise_reverse_byte` that takes an integer representing a byte (8 bits) as input and returns the byte with its bits reversed. The function should ensure that the input is within the valid range for a byte (0 to 255) and handle any invalid input appropriately.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_reverse_byte(byte: int) -> int:
"""
Reverses the bits of a given byte (8 bits).
Args:
byte (int): The byte (8 bits) to be reversed. Must be in the range 0 to 255.
Returns:
int: The byte with... |
code_exercise_27k | 2,423 | Write a Python function named `bitwise_modify_bit` that takes three integers as input: a number, a position, and a value. The function should modify the bit at the specified position in the number with the specified value and return the result. The function should ensure that the value is either 0 or 1, and the positio... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_modify_bit(num: int, position: int, value: int) -> int:
"""
Modifies the bit at the specified position in the number with the specified value and returns the result.
Args:
num (int): The number in which ... |
code_exercise_27k | 2,424 | Write a Python function named `bitwise_is_power_of_two` that takes an integer as input and returns `True` if it is a power of two, and `False` otherwise. The function should use bitwise operations to determine if the number is a power of two. The code should start with:
```python
def bitwise_is_power_of_two(num: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_power_of_two(num: int) -> bool:
"""
Determines if the given integer is a power of two using bitwise operations.
Args:
num (int): The integer to check.
Returns:
bool: True if the number is... |
code_exercise_27k | 2,425 | Write a Python function named `bitwise_next_power_of_two` that takes an integer as input and returns the next power of two greater than or equal to the input number. The function should use bitwise operations to achieve this efficiently.
The code should start with:
```python
def bitwise_next_power_of_two(num: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_next_power_of_two(num: int) -> int:
"""
Calculate the next power of two greater than or equal to the given integer using bitwise operations.
Args:
num (int): The integer for which to find the next power ... |
code_exercise_27k | 2,426 | Write a Python function named `count_trailing_zeros` that takes an integer as input and returns the count of trailing zeros (0s) in its binary representation. The function should handle both positive and negative integers. The code should start with:
```python
def count_trailing_zeros(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_trailing_zeros(num: int) -> int:
"""
Counts the number of trailing zeros in the binary representation of a given integer.
Args:
num (int): The integer whose trailing zeros are to be counted.
Returns:
... |
code_exercise_27k | 2,428 | Write a Python function named `bitwise_is_even` that takes an integer as input and returns `True` if it is an even number, and `False` otherwise. The function should use bitwise operations to determine the parity of the number. The code should start with:
```python
def bitwise_is_even(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_even(num: int) -> bool:
"""
Determines if a given integer is even using bitwise operations.
Args:
num (int): The integer to check for even parity.
Returns:
bool: True if the number is eve... |
code_exercise_27k | 2,429 | Write a Python function named `bitwise_is_odd` that takes an integer as input and returns `True` if it is an odd number, and `False` otherwise. The function should use bitwise operations to determine the parity of the number. The code should start with:
```python
def bitwise_is_odd(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_odd(num: int) -> bool:
"""
Determines if a given integer is odd using bitwise operations.
Args:
num (int): The integer to check for odd parity.
Returns:
bool: True if the number is odd, F... |
code_exercise_27k | 2,430 | Write a Python function named `bitwise_multiply_by_two` that takes an integer as input and returns the result of multiplying it by two using bitwise operations. The function should handle both positive and negative integers. The code should start with:
```python
def bitwise_multiply_by_two(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_multiply_by_two(num: int) -> int:
"""
Multiplies the given integer by two using bitwise operations.
This function takes an integer as input and returns the result of multiplying it by two using the bitwise left ... |
code_exercise_27k | 2,431 | Write a Python function named `bitwise_divide_by_two` that takes an integer as input and returns the result of dividing it by two using bitwise operations. The function should handle both positive and negative integers correctly. The code should start with:
```python
def bitwise_divide_by_two(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_divide_by_two(num: int) -> int:
"""
Divides the given integer by two using bitwise operations.
This function takes an integer as input and returns the result of dividing it by two using bitwise right shift opera... |
code_exercise_27k | 2,432 | Write a Python function named `bitwise_absolute_value` that takes an integer as input and returns its absolute value using bitwise operations. The function should handle both positive and negative integers efficiently without using any built-in absolute value functions or arithmetic operations other than bitwise operat... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_absolute_value(num: int) -> int:
"""
Calculate the absolute value of an integer using bitwise operations.
Args:
num (int): The integer for which to calculate the absolute value.
Returns:
int... |
code_exercise_27k | 2,433 | Write a Python function named `bitwise_max` that takes two integers as input and returns the maximum of the two using bitwise operations. The function should not use any conditional statements, loops, or built-in functions like `max()`. The code should start with:
```python
def bitwise_max(num1: int, num2: int) -> int:... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_max(num1: int, num2: int) -> int:
"""
Returns the maximum of two integers using bitwise operations.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns:
int:... |
code_exercise_27k | 2,434 | Write a Python function named `bitwise_min` that takes two integers as input and returns the minimum of the two using bitwise operations. The function should not use any conditional statements, loops, or built-in functions like `min` or `max`. The code should start with:
```python
def bitwise_min(num1: int, num2: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_min(num1: int, num2: int) -> int:
"""
Returns the minimum of two integers using bitwise operations.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns:
int:... |
code_exercise_27k | 2,436 | Write a Python function named `bitwise_swap_variables` that takes two integers as input and swaps their values using bitwise operations. The function should return a tuple containing the swapped values of the two integers. The code should start with:
```python
def bitwise_swap_variables(num1: int, num2: int) -> tuple:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_swap_variables(num1: int, num2: int) -> tuple:
"""
Swaps the values of two integers using bitwise XOR operations.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns... |
code_exercise_27k | 2,438 | Write a Python function named `bitwise_reverse_bits_in_byte` that takes an integer representing a byte (8 bits) as input and returns the byte with its bits reversed. The function should handle the input as an 8-bit integer and ensure that the output is also an 8-bit integer. The code should start with:
```python
def bi... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_reverse_bits_in_byte(byte: int) -> int:
"""
Reverses the bits of an 8-bit integer.
Args:
byte (int): The 8-bit integer to reverse.
Returns:
int: The 8-bit integer with its bits reversed.
... |
code_exercise_27k | 2,439 | Write a Python function named `count_set_bits` that takes an integer representing a byte (8 bits) as input and returns the count of set bits (1s) in its binary representation. The function should efficiently count the set bits using bitwise operations.
The code should start with:
```python
def count_set_bits(byte: int... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_set_bits(byte: int) -> int:
"""
Counts the number of set bits (1s) in the binary representation of an 8-bit integer.
Args:
byte (int): The byte (8 bits) to count the set bits in.
Returns:
int:... |
code_exercise_27k | 2,440 | Write a Python function named `bitwise_count_zeros_in_byte` that takes an integer representing a byte (8 bits) as input and returns the count of zero bits (0s) in its binary representation. The function should ensure that the input is within the valid range for a byte (0 to 255) and handle any invalid input appropriate... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_count_zeros_in_byte(byte: int) -> int:
"""
Counts the number of zero bits in the binary representation of a byte (8 bits).
Args:
byte (int): The byte (8 bits) to be checked. Must be in the range 0 to 255... |
code_exercise_27k | 2,441 | Write a Python function named `bitwise_is_bit_set_in_byte` that takes two integers as input: a byte (8 bits) and a position. The function should return `True` if the bit at the specified position in the byte is set (1), and `False` otherwise. The function should also validate that the position is within the valid range... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_bit_set_in_byte(byte: int, position: int) -> bool:
"""
Checks if the bit at the specified position in an 8-bit byte is set (1).
Args:
byte (int): The byte (8 bits) to check.
position (int): Th... |
code_exercise_27k | 2,442 | Write a Python function named `bitwise_set_bit_in_byte` that takes two integers as input: a byte (8 bits) and a position. The function should return the byte with the bit at the specified position set to 1. The position should be within the range of 0 to 7, inclusive. If the position is out of this range, the function ... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_set_bit_in_byte(byte: int, position: int) -> int:
"""
Sets the bit at the specified position in an 8-bit byte to 1.
Args:
byte (int): The 8-bit byte in which to set the bit.
position (int): The p... |
code_exercise_27k | 2,445 | Write a Python function named `bitwise_reverse_byte_order` that takes an integer representing a 32-bit value as input and returns the value with its byte order reversed. The function should handle the input as a 32-bit integer and reverse the order of its bytes. The code should start with:
```python
def bitwise_reverse... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_reverse_byte_order(value: int) -> int:
"""
Reverses the byte order of a 32-bit integer.
This function takes an integer representing a 32-bit value and returns the value
with its byte order reversed. Each byt... |
code_exercise_27k | 2,446 | Write a Python function named `bitwise_extract_nibble` that takes two integers as input: a byte (8 bits) and a nibble position. The function should return the nibble at the specified position in the byte. The nibble position is zero-indexed, meaning the least significant nibble (rightmost) is at position 0, and the mos... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_extract_nibble(byte: int, position: int) -> int:
"""
Extracts the nibble at the specified position from an 8-bit byte.
Args:
byte (int): The 8-bit byte from which to extract the nibble.
position ... |
code_exercise_27k | 2,450 | Write a Python function named `bitwise_is_power_of_two_fast` that takes an integer as input and returns `True` if it is a power of two, and `False` otherwise. The function should use bitwise operations to perform the check efficiently. The function should handle both positive and negative integers, returning `False` fo... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_power_of_two_fast(num: int) -> bool:
"""
Determines if a given integer is a power of two using bitwise operations.
Parameters:
num (int): The integer to check.
Returns:
bool: True if num is a pow... |
code_exercise_27k | 2,451 | Write a Python function named `bitwise_next_power_of_two` that takes an integer as input and returns the next power of two greater than or equal to the input number. The function should use bitwise operations to calculate the next power of two efficiently. The function should handle edge cases such as zero and negative... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_next_power_of_two(num: int) -> int:
"""
Calculate the next power of two greater than or equal to the given integer using bitwise operations.
Args:
num (int): The integer for which to find the next power ... |
code_exercise_27k | 2,452 | Write a Python function named `bitwise_count_trailing_zeros_fast` that takes an integer as input and returns the count of trailing zeros (0s) in its binary representation. The function should use bitwise operations to perform the count efficiently. The function should handle edge cases such as when the input is zero.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_count_trailing_zeros_fast(num: int) -> int:
"""
Counts the number of trailing zeros in the binary representation of a given integer using bitwise operations.
Args:
num (int): The integer whose trailing z... |
code_exercise_27k | 2,453 | Write a Python function named `bitwise_count_leading_zeros_fast` that takes an integer as input and returns the count of leading zeros (0s) in its binary representation. The function should use bitwise operations to perform the count efficiently. The function should handle both positive and negative integers, as well a... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_count_leading_zeros_fast(num: int) -> int:
"""
Counts the number of leading zeros in the binary representation of a given integer using bitwise operations.
Args:
num (int): The integer for which to count... |
code_exercise_27k | 2,454 | Write a Python function named `bitwise_is_even_fast` that takes an integer as input and returns `True` if it is an even number, and `False` otherwise. The function should use bitwise operations to perform the check. The code should start with:
```python
def bitwise_is_even_fast(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_even_fast(num: int) -> bool:
"""
Determines if a given integer is even using bitwise operations.
Args:
num (int): The integer to check for evenness.
Returns:
bool: True if the number is e... |
code_exercise_27k | 2,455 | Write a Python function named `bitwise_is_odd_fast` that takes an integer as input and returns `True` if it is an odd number, and `False` otherwise. The function should use bitwise operations to perform the check. The code should start with:
```python
def bitwise_is_odd_fast(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_is_odd_fast(num: int) -> bool:
"""
Determines if a given integer is odd using bitwise operations.
Args:
num (int): The integer to check for oddness.
Returns:
bool: True if the number is odd,... |
code_exercise_27k | 2,457 | Write a Python function named `bitwise_divide_by_power_of_two` that takes two integers as input: a number and a power of two. The function should return the result of dividing the number by the power of two using bitwise operations. The function should handle edge cases such as dividing by zero and negative powers of t... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_divide_by_power_of_two(num: int, power_of_two: int) -> int:
"""
Divides the given number by a power of two using bitwise operations.
Args:
num (int): The number to be divided.
power_of_two (int):... |
code_exercise_27k | 2,458 | Write a Python function named `bitwise_swap_variables_fast` that takes two integers as input and swaps their values using bitwise operations. The function should return a tuple containing the swapped values of the two integers. The code should start with:
```python
def bitwise_swap_variables_fast(num1: int, num2: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_swap_variables_fast(num1: int, num2: int) -> tuple:
"""
Swaps the values of two integers using bitwise XOR operations.
Parameters:
num1 (int): The first integer.
num2 (int): The second integer.
Retu... |
code_exercise_27k | 2,462 | Write a Python function named `bitwise_count_zeros_in_byte_fast` that takes an integer representing a byte (8 bits) as input and returns the count of zero bits (0s) in its binary representation. The function should use bitwise operations to perform the count efficiently. The code should start with:
```python
def bitwis... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_count_zeros_in_byte_fast(byte: int) -> int:
"""
Counts the number of zero bits in the binary representation of an 8-bit integer using bitwise operations.
Args:
byte (int): An integer representing an 8-bi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.