benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf bbccadd4-dd39-56ae-85d8-341209dbe1ec

Problem

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

complete prompt

import re import string from random import choice def task_func(n, pattern): """ Generates a random string of a specified length that conforms to a given regular expression pattern. The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters, of the specified length until one matches the pattern. Parameters: n (int): The length of the string to be generated. pattern (str): A regular expression pattern the generated string must match, including start and end anchors. Returns: str: A randomly generated string that matches the specified pattern. Requirements: - re - string - random.choice Examples: >>> len(task_func(5, '[a-z]*')) == 5 True >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$'))) True """
Plain-text mathematical notation (without MathML)
import re
import string
from random import choice

def task_func(n, pattern):
    """
    Generates a random string of a specified length that conforms to a given regular expression pattern.
    The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters,
    of the specified length until one matches the pattern.

    Parameters:
    n (int): The length of the string to be generated.
    pattern (str): A regular expression pattern the generated string must match, including start and end anchors.

    Returns:
    str: A randomly generated string that matches the specified pattern.

    Requirements:
    - re
    - string
    - random.choice

    Examples:
    >>> len(task_func(5, '[a-z]*')) == 5
    True

    >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$')))
    True
    """
Original LaTeX notation
import re
import string
from random import choice

def task_func(n, pattern):
    """
    Generates a random string of a specified length that conforms to a given regular expression pattern.
    The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters,
    of the specified length until one matches the pattern.

    Parameters:
    n (int): The length of the string to be generated.
    pattern (str): A regular expression pattern the generated string must match, including start and end anchors.

    Returns:
    str: A randomly generated string that matches the specified pattern.

    Requirements:
    - re
    - string
    - random.choice

    Examples:
    >>> len(task_func(5, '[a-z]*')) == 5
    True

    >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$')))
    True
    """

instruct prompt

Generates a random string of a specified length that conforms to a given regular expression pattern. The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters, of the specified length until one matches the pattern. >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$'))) True The function should output with: str: A randomly generated string that matches the specified pattern. You should write self-contained code starting with:
Plain-text mathematical notation (without MathML)
Generates a random string of a specified length that conforms to a given regular expression pattern. The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters, of the specified length until one matches the pattern. >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$'))) True
The function should output with:
    str: A randomly generated string that matches the specified pattern.
You should write self-contained code starting with:
Original LaTeX notation
Generates a random string of a specified length that conforms to a given regular expression pattern. The function repeatedly generates random strings, using both uppercase and lowercase ASCII letters, of the specified length until one matches the pattern. >>> bool(re.match('^[A-Z]+$', task_func(3, '^[A-Z]+$'))) True
The function should output with:
    str: A randomly generated string that matches the specified pattern.
You should write self-contained code starting with:

Code

import re
import string
from random import choice
def task_func(n, pattern):

code prompt

Code

import re
import string
from random import choice
def task_func(n, pattern):

entry point

task_func

libs

  • random
  • string
  • re

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