List rooted trees: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments.)
(Added 11l)
Line 33: Line 33:
As an example output, run 5 bags.   There should be 9 ways.
As an example output, run 5 bags.   There should be 9 ways.
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Python}}

<lang 11l>F bagchain(x, n, bb, start = 0)
I n == 0
R [x]

[(Int, String)] out
L(i) start .< bb.len
V (c, s) = bb[i]
I c <= n
out.extend(bagchain((x[0] + c, x[1]‘’s), n - c, bb, i))

R out

F bags(n)
I n == 0
R [(0, ‘’)]

[(Int, String)] upto
L(x) (n - 1 .< 0).step(-1)
upto.extend(bags(x))

R bagchain((0, ‘’), n - 1, upto).map((c, s) -> (c + 1, ‘(’s‘)’))

F replace_brackets(s)
V depth = 0
[String] out
L(c) s
I c == ‘(’
out.append(‘([{’[depth % 3])
depth++
E
depth--
out.append(‘)]}’[depth % 3])
R out.join(‘’)

L(x) bags(5)
print(replace_brackets(x[1]))</lang>

{{out}}
<pre>
([{([])}])
([{()()}])
([{()}{}])
([{}{}{}])
([{()}][])
([{}{}][])
([{}][{}])
([{}][][])
([][][][])
</pre>


=={{header|C}}==
=={{header|C}}==