RosettaCodeData/Task/Nested-templated-data/00-TASK.txt

38 lines
1.5 KiB
Plaintext

A template for data is an arbitrarily nested tree of integer indices.
Data payloads are given as a separate mapping, array or other simpler, flat,
association of indices to individual items of data, and are strings.<br>
The idea is to create a data structure with the templates' nesting, and the
payload corresponding to each index appearing at the position of each index.
Answers using simple string replacement or regexp are to be avoided. The idea is
to use the native, or usual implementation of lists/tuples etc of the language
and to hierarchically traverse the template to generate the output.
;Task Detail:
Given the following input template <code>t</code> and list of payloads <code>p</code>:
<syntaxhighlight lang="text"># Square brackets are used here to denote nesting but may be changed for other,
# clear, visual representations of nested data appropriate to ones programming
# language.
t = [
[[1, 2],
[3, 4, 1],
5]]
p = 'Payload#0' ... 'Payload#6'</syntaxhighlight>
The correct output should have the following structure, (although spacing and
linefeeds may differ, the nesting and order should follow):
<syntaxhighlight lang="text">[[['Payload#1', 'Payload#2'],
['Payload#3', 'Payload#4', 'Payload#1'],
'Payload#5']]</syntaxhighlight>
1. Generate the output for the above template, <code>t</code>.<br>
;Optional Extended tasks:
2. Show which payloads remain unused.<br>
3. Give some indication/handling of indices without a payload.<br>
''Show output on this page.''