benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b14b4107-512d-5e39-ba3a-3a26677769ad

Problem

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

complete prompt

import random
from itertools import combinations
import math

def task_func(n):
    """
    Generate n random dots within a unit square (0 to 1 on both axes) in a 2D space 
    and find the pair that comes closest to each other.

    Parameters:
    n (int): The number of points to generate. If n is less than 2, the function returns None.

    Returns:
    tuple or None: A tuple of the form ((x1, y1), (x2, y2)), which are the coordinates of the closest pair,
                   or None if n is less than 2.
    
    Note:
    - This function will return None if the input n less than 2.
    
    Requirements:
    - random
    - itertools.combinations
    - math

    Example:
    >>> random.seed(0)
    >>> print(task_func(2))
    ((0.8444218515250481, 0.7579544029403025), (0.420571580830845, 0.25891675029296335))
    """

instruct prompt

Generate n random dots within a unit square (0 to 1 on both axes) in a 2D space and find the pair that comes closest to each other.
Note that: This function will return None if the input n less than 2.
The function should output with:
    tuple or None: A tuple of the form ((x1, y1), (x2, y2)), which are the coordinates of the closest pair,
    or None if n is less than 2.
You should write self-contained code starting with:

Code

import random
from itertools import combinations
import math
def task_func(n):

code prompt

Code

import random
from itertools import combinations
import math
def task_func(n):

entry point

task_func

libs

  • math
  • random
  • itertools

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