benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b63b2dbe-881e-52c5-950e-27c7a0c62b16

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

from multiprocessing import Pool
import math

def calculate_factorial(number: int) -> tuple:
    return number, math.factorial(number)
    
def task_func(numbers: list) -> dict:
    """
    Calculate factorials for a list of numbers in parallel using multiprocessing.

    Parameters:
    numbers (list[int]): List of numbers to calculate factorials.

    Returns:
    dict[int, int]: A dictionary with numbers as keys and their factorial as values.

    Raises:
    ValueError: If any element in the input list is not an integer or is negative.

    Requirements:
    - multiprocessing.Pool
    - math.factorial

    Example:
    >>> factorials = task_func([5, 6, 7, 8, 9])
    >>> factorials[5] == 120 and factorials[9] == 362880
    True
    """

instruct prompt

Calculate factorials for a list of numbers in parallel using multiprocessing.
The function should raise the exception for: ValueError: If any element in the input list is not an integer or is negative.
The function should output with:
    dict[int, int]: A dictionary with numbers as keys and their factorial as values.
You should write self-contained code starting with:

Code

from multiprocessing import Pool
import math
def calculate_factorial(number: int) -> tuple:
    return number, math.factorial(number)
    
def task_func(numbers: list) -> dict:

code prompt

Code

from multiprocessing import Pool
import math
def calculate_factorial(number: int) -> tuple:
    return number, math.factorial(number)
    
def task_func(numbers: list) -> dict:

entry point

task_func

libs

  • math
  • multiprocessing

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import