benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 1b8fab8f-a648-5b9d-baca-858a6d1d12ea

Problem

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

complete prompt

import json
import os
import hashlib
import base64
import time

def task_func(file_path, unknown_key):
    """
    Reads a JSON file, extracts a value specified by an 'unknown_key' within a nested structure, hashes this value using SHA256,
    and writes the base64-encoded hash to a new file with a timestamp in its name. The JSON should contain a specific 
    structure where the value to be hashed is under 'A' -> [unknown_key] -> 'maindata' -> [index 0] -> 'Info'.

    Parameters:
    - file_path (str): The file path to read the JSON data from.
    - unknown_key (str): The key to look for in the nested JSON structure under the top-level key 'A'. This key should 
                         lead to a list of dictionaries under 'maindata', with the first dictionary containing the 'Info' key.

    Returns:
    str: The absolute file path of the newly created file containing the hashed value.
    
    Requirements:
    - json
    - os
    - hashlib
    - base64
    - time
    
    Example:
    >>> json_file = '/path/to/file.json'
    >>> new_file = task_func(json_file, 'B')
    >>> print(f"Hashed data saved at: {new_file}")
    """

instruct prompt

Reads a JSON file, extracts a value specified by an 'unknown_key' within a nested structure, hashes this value using SHA256, and writes the base64-encoded hash to a new file with a timestamp in its name. The JSON should contain a specific structure where the value to be hashed is under 'A' -> [unknown_key] -> 'maindata' -> [index 0] -> 'Info'.
The function should output with:
    str: The absolute file path of the newly created file containing the hashed value.
You should write self-contained code starting with:

Code

import json
import os
import hashlib
import base64
import time
def task_func(file_path, unknown_key):

code prompt

Code

import json
import os
import hashlib
import base64
import time
def task_func(file_path, unknown_key):

entry point

task_func

libs

  • base64
  • hashlib
  • time
  • os
  • json

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