benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf ee65f9cd-8b06-5322-8083-046717be68ad

Problem

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

complete prompt

import random
import bisect
from array import array


def task_func(n=10, total=100):
    """
    Generates 'n' random integer numbers such that their sum equals 'total', sorts these numbers,
    and determines the position where a new random number can be inserted to maintain the sorted order.
    The function uses a retry mechanism to ensure the generated numbers sum up to 'total'.

    Parameters:
    n (int): The number of random numbers to generate. Default is 10.
    total (int): The total sum of the generated numbers. Default is 100.

    Returns:
    tuple: A tuple containing the sorted numbers as an array and the insertion position for a new number.

    Requirements:
    - random
    - bisect
    - array.array

    Examples:
    >>> sorted_nums, pos = task_func(5, 50)
    >>> len(sorted_nums) == 5
    True
    >>> sum(sorted_nums) == 50
    True
    """

instruct prompt

Generates 'n' random integer numbers such that their sum equals 'total', sorts these numbers, and determines the position where a new random number can be inserted to maintain the sorted order. The function uses a retry mechanism to ensure the generated numbers sum up to 'total'.
The function should output with:
    tuple: A tuple containing the sorted numbers as an array and the insertion position for a new number.
You should write self-contained code starting with:

Code

import random
import bisect
from array import array
def task_func(n=10, total=100):

code prompt

Code

import random
import bisect
from array import array
def task_func(n=10, total=100):

entry point

task_func

libs

  • bisect
  • random
  • array

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