benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 505e19fa-25de-53d1-9978-d93a0bd9f8d2

Problem

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

complete prompt

import numpy as np
import matplotlib.pyplot as plt


# Constants
CITIES = ['New York', 'London', 'Beijing', 'Tokyo', 'Sydney', 'Paris', 'Berlin', 'Moscow', 'Madrid', 'Rome']

def task_func(city_dict, max_range=1000000, seed=0):
    """
    Given a constant list of cities (CITIES) and a dictionary 'city_dict' of people's names and their favorite cities, 
    this function generates a dictionary of city populations for the cities in the list and plots the population 
    data using a bar chart. The population values are randomly generated integers between 1 and 'max_range' if 
    the city is in the list of cities, otherwise the population value is -1. The random number generator is seeded
    with the value 'seed' before generating the population values.

    Parameters:
    city_dict (dict): The dictionary with keys as people's names and values as city names. 
    max_range (int, Optional): The maximum population value for the randomly generated population. Defaults to 1000000.
    Must be greater than 1.
    seed (int, Optional): The seed for the random number generator. Defaults to 0.

    Returns:
    dict: A dictionary with city names as keys and randomly generated populations as values.
    matplotlib.axes.Axes: The Axes object of the plot for further manipulation or testing.

    Requirements:
    - numpy for random number generation
    - matplotlib for plotting

    Example:
    >>> city_dict = {'John': 'New York', 'Alice': 'London', 'Bob': 'Beijing', 'Charlie': 'Tokyo', 'David': 'Sydney'}
    >>> population_dict, plot_axes = task_func(city_dict)
    """

instruct prompt

Given a constant list of cities (CITIES) and a dictionary 'city_dict' of people's names and their favorite cities, this function generates a dictionary of city populations for the cities in the list and plots the population data using a bar chart. The population values are randomly generated integers between 1 and 'max_range' if the city is in the list of cities, otherwise the population value is -1. The random number generator is seeded with the value 'seed' before generating the population values.
The function should output with:
    dict: A dictionary with city names as keys and randomly generated populations as values.
    matplotlib.axes.Axes: The Axes object of the plot for further manipulation or testing.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
# Constants
CITIES = ['New York', 'London', 'Beijing', 'Tokyo', 'Sydney', 'Paris', 'Berlin', 'Moscow', 'Madrid', 'Rome']
def task_func(city_dict, max_range=1000000, seed=0):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
# Constants
CITIES = ['New York', 'London', 'Beijing', 'Tokyo', 'Sydney', 'Paris', 'Berlin', 'Moscow', 'Madrid', 'Rome']
def task_func(city_dict, max_range=1000000, seed=0):

entry point

task_func

libs

  • numpy
  • matplotlib

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