benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 20049650-6774-5bfc-adf3-88d1f3729ea8

Problem

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

complete prompt

import random
from collections import Counter

def task_func(values, weights, n_samples):
    """
    Sample random numbers based on a given weighted distribution and return a histogram of the samples.

    Parameters:
    - values (list): List of values to be sampled from.
    - weights (list): List of weights corresponding to the values.
    - n_samples (int): Number of samples to be drawn.

    Returns:
    - histogram (dict): A histogram as a dictionary with the values as keys and counts as values.

    Requirements:
    - collections.Counter
    - random

    Example:
    >>> random.seed(42)
    >>> task_func([1, 2, 3], [3, 2, 1], 1000)
    {2: 342, 1: 480, 3: 178}
    """

instruct prompt

Sample random numbers based on a given weighted distribution and return a histogram of the samples.
The function should output with:
    histogram (dict): A histogram as a dictionary with the values as keys and counts as values.
You should write self-contained code starting with:

Code

import random
from collections import Counter
def task_func(values, weights, n_samples):

code prompt

Code

import random
from collections import Counter
def task_func(values, weights, n_samples):

entry point

task_func

libs

  • collections
  • random

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