benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 5ef9b226-2add-56b6-a2bb-3ac5385bc9ad

Problem

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

complete prompt

import string
import random
from collections import Counter


def task_func(n, seed=None):
    """
    Generate a number of random lowercase letters and count their occurrences.

    This function takes an integer input to determine how many random letters 
    to generate and an optional seed for consistent randomness. It then creates 
    a list of these letters, chosen from the English lowercase alphabet, and 
    counts each letter's occurrences. The result is returned as a Counter 
    object (from the collections module) which behaves like a dictionary where 
    the keys are the letters, and the values are their counts.

    Parameters:
    n (int): The number of random letters to generate.
    seed (int, optional): A seed for the random number generator for consistent
                         results. Defaults to None.

    Returns:
    Counter: A collections.Counter object with the count of each letter.

    Requirements:
    - collections
    - string
    - random

    Example:
    >>> letter_counts = task_func(1000, seed=123)
    >>> print(letter_counts)
    Counter({'v': 48, 'b': 47, 'n': 46, 'r': 46, 'k': 46, 'z': 46, 'c': 44, 'e': 43, 'q': 43, 'l': 43, 'y': 42, 'm': 42, 'a': 42, 'u': 42, 'd': 36, 'o': 34, 'j': 34, 'g': 34, 'f': 33, 'h': 33, 'p': 32, 'w': 30, 'x': 30, 'i': 29, 't': 28, 's': 27})
    >>> task_func(10, seed=12)
    Counter({'v': 2, 'l': 2, 'p': 1, 'i': 1, 'q': 1, 'e': 1, 'm': 1, 'a': 1})

    Note: 
    The function internally uses a list to store the randomly generated 
    letters before counting them. The randomness of letter selection can be 
    consistent by providing a seed.
    """

instruct prompt

Generate a number of random lowercase letters and count their occurrences. This function takes an integer input to determine how many random letters to generate and an optional seed for consistent randomness. It then creates a list of these letters, chosen from the English lowercase alphabet, and counts each letter's occurrences. The result is returned as a Counter object (from the collections module) which behaves like a dictionary where the keys are the letters, and the values are their counts.
Note that: The function internally uses a list to store the randomly generated letters before counting them. The randomness of letter selection can be consistent by providing a seed.
The function should output with:
    Counter: A collections.Counter object with the count of each letter.
You should write self-contained code starting with:

Code

import string
import random
from collections import Counter
def task_func(n, seed=None):

code prompt

Code

import string
import random
from collections import Counter
def task_func(n, seed=None):

entry point

task_func

libs

  • collections
  • random
  • string

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