benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f005fb28-9313-5b5a-90b3-790bbd8391df

Problem

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

complete prompt

import re
import random
import string

def task_func(n, pattern, seed=None):
    """
    Generate a random string of length 'n' and find all non-overlapping matches
    of the regex 'pattern'.

    The function generates a random string of ASCII Letters and Digits using 
    the random module. By providing a seed the results are reproducable.
    Non overlapping matches of the provided pattern are then found using the re
    module.
    
    Parameters:
    n (int): The length of the random string to be generated.
    pattern (str): The regex pattern to search for in the random string.
    seed (int, optional): A seed parameter for the random number generator for reproducible results. Defaults to None.

    Returns:
    list: A list of all non-overlapping matches of the regex pattern in the generated string.

    Requirements:
    - re
    - random
    - string

    Example:
    >>> task_func(100, r'[A-Za-z]{5}', seed=12345)
    ['mrKBk', 'BqJOl', 'NJlwV', 'UfHVA', 'LGkjn', 'vubDv', 'GSVAa', 'kXLls', 'RKlVy', 'vZcoh', 'FnVZW', 'JQlqL']

    >>> task_func(1000, r'[1-9]{2}', seed=1)
    ['51', '84', '16', '79', '16', '28', '63', '82', '94', '18', '68', '42', '95', '33', '64', '38', '69', '56', '32', '16', '18', '19', '27']
     """

instruct prompt

Generate a random string of length 'n' and find all non-overlapping matches of the regex 'pattern'. The function generates a random string of ASCII Letters and Digits using the random module. By providing a seed the results are reproducable. Non overlapping matches of the provided pattern are then found using the re module. >>> task_func(1000, r'[1-9]{2}', seed=1) ['51', '84', '16', '79', '16', '28', '63', '82', '94', '18', '68', '42', '95', '33', '64', '38', '69', '56', '32', '16', '18', '19', '27']
The function should output with:
    list: A list of all non-overlapping matches of the regex pattern in the generated string.
You should write self-contained code starting with:

Code

import re
import random
import string
def task_func(n, pattern, seed=None):

code prompt

Code

import re
import random
import string
def task_func(n, pattern, seed=None):

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