benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 82ff8866-c661-5693-892b-327b6924797a

Problem

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

complete prompt

import os
import hashlib

# Constants
DIRECTORY = "./hashed_files"


def task_func(input_string):
    """
    Hash each non-empty line of a multi-line string using SHA256 and save the hashes to files.
    The filename is the first 10 characters of the hash, with a '.txt' extension.

    Parameters:
    - input_string (str): A multi-line string to be processed.

    Returns:
    - list[str]: A list of file paths where the hashes of non-empty lines are saved.

    Requirements:
    - os
    - hashlib

    Notes:
    - If the DIRECTORY does not exist, it is created.
    - Empty lines in the input string are ignored.

    Example:
    >>> file_paths = task_func('line a\nfollows by line b\n\n...bye\n')
    >>> print(file_paths)
    ['./hashed_files/489fe1fa6c.txt', './hashed_files/67009597fe.txt', './hashed_files/eab4758603.txt']
    """

instruct prompt

Hash each non-empty line of a multi-line string using SHA256 and save the hashes to files. The filename is the first 10 characters of the hash, with a '.txt' extension.
Note that: Notes: If the DIRECTORY does not exist, it is created. Empty lines in the input string are ignored.
The function should output with:
    list[str]: A list of file paths where the hashes of non-empty lines are saved.
You should write self-contained code starting with:

Code

import os
import hashlib
# Constants
DIRECTORY = "./hashed_files"
def task_func(input_string):

code prompt

Code

import os
import hashlib
# Constants
DIRECTORY = "./hashed_files"
def task_func(input_string):

entry point

task_func

libs

  • hashlib
  • os

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