benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf da63a99a-33ca-539e-8e8f-db32fcc3c76c

Problem

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

complete prompt

from itertools import zip_longest
from scipy.spatial import distance

def task_func(points):
    """
    Calculate the Euclidean distances between consecutive points in a provided 
    list of 2D coordinates.

    This function takes a list of tuples, where each tuple contains two numbers
    representing a point in 2D space. It computes the Euclidean distance between
    each consecutive pair of points.

    If an empty list or a single point is passed, the function returns an empty list.
    If a tuple contains just one number it is assumed that both coordinates are equal to this number.
    Example: (2) == (2, 2)

    Parameters:
    points (list of tuples): A list of tuples where each tuple contains two 
                             numbers (x, y), representing a point in 2D space.

    Returns:
    list of floats: A list containing the Euclidean distances between 
                    consecutive points. Each distance is a float.
    
    Requirements:
    - itertools
    - scipy.spatial

    Example:
    >>> task_func([(1, 2), (3, 4), (5, 6), (7, 8)])
    [2.8284271247461903, 2.8284271247461903, 2.8284271247461903]

    >>> task_func([(1, 2), (4), (-1.2, 4)])
    [3.605551275463989, 5.2]
    """

instruct prompt

Calculate the Euclidean distances between consecutive points in a provided list of 2D coordinates. This function takes a list of tuples, where each tuple contains two numbers representing a point in 2D space. It computes the Euclidean distance between each consecutive pair of points. If an empty list or a single point is passed, the function returns an empty list. If a tuple contains just one number it is assumed that both coordinates are equal to this number. >>> task_func([(1, 2), (4), (-1.2, 4)]) [3.605551275463989, 5.2]
The function should output with:
    list of floats: A list containing the Euclidean distances between
    consecutive points. Each distance is a float.
You should write self-contained code starting with:

Code

from itertools import zip_longest
from scipy.spatial import distance
def task_func(points):

code prompt

Code

from itertools import zip_longest
from scipy.spatial import distance
def task_func(points):

entry point

task_func

libs

  • itertools
  • scipy

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