benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e47a7fa6-93cc-5547-96fa-2872fee48a7b

Problem

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

complete prompt

import heapq
import random

def task_func(k, list_length = 5, min_value = 0, max_value = 100):
    """
    Find the k smallest numbers in a randomly generated list using heapq.

    Parameters:
    k (int): The number of smallest elements to find.
    list_length (int): The length of the randomly generated list of integers.
    min_value (int): The minimum value for randomly generated integers.
    max_value (int): The maximum value for randomly generated integers.

    Returns:
    tuple: A tuple containing two lists: 
        - list[int]: The randomly generated list of integers with the specified length.
        - list[int]: The k smallest numbers found using heapq.

    Requirements:
    - heapq
    - random

    Example:
    >>> random.seed(0)
    >>> rand_list, least_k = task_func(3)
    >>> least_k[0] in rand_list
    True
    >>> rand_list, least_k = task_func(3,5,100,100)
    >>> print(least_k)
    [100, 100, 100]
    """

instruct prompt

Find the k smallest numbers in a randomly generated list using heapq.
The function should output with:
    tuple: A tuple containing two lists:
    list[int]: The randomly generated list of integers with the specified length.
    list[int]: The k smallest numbers found using heapq.
You should write self-contained code starting with:

Code

import heapq
import random
def task_func(k, list_length = 5, min_value = 0, max_value = 100):

code prompt

Code

import heapq
import random
def task_func(k, list_length = 5, min_value = 0, max_value = 100):

entry point

task_func

libs

  • random
  • heapq

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