benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 84849405-69e5-5d58-87d8-83da390a232e
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import time
from datetime import datetime
import random
import matplotlib.pyplot as plt
# Constants
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
def task_func(n, output_path=None):
"""
Generate n random Unix timestamps and convert them to strings formatted as UTC DATE_FORMAT.
Plot a histogram of the distribution of the generated timestamps. If an output path is provided,
save the histogram to the specified path. Otherwise, display the plot.
Parameters:
n (int): The number of timestamps to generate.
output_path (str, optional): Path to save the histogram plot. Defaults to None.
Returns:
list: The list of n formatted timestamps.
Requirements:
- time
- datetime
- random
- matplotlib.pyplot
Example:
>>> random.seed(42)
>>> timestamps = task_func(n=3, output_path=None)
>>> print(timestamps)
['2013-07-06 20:56:46', '1977-07-29 23:34:23', '1971-09-14 11:29:44']
"""
instruct prompt
Generate n random Unix timestamps and convert them to strings formatted as UTC DATE_FORMAT. Plot a histogram of the distribution of the generated timestamps. If an output path is provided, save the histogram to the specified path. Otherwise, display the plot.
The function should output with:
list: The list of n formatted timestamps.
You should write self-contained code starting with:
Code
import time
from datetime import datetime
import random
import matplotlib.pyplot as plt
# Constants
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
def task_func(n, output_path=None):
code prompt
Code
import time
from datetime import datetime
import random
import matplotlib.pyplot as plt
# Constants
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
def task_func(n, output_path=None):
entry point
task_func
libs
- datetime
- random
- matplotlib
- time
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
initial import