List rooted trees: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(→{{header|Haskell}}: Applied hlint, hindent.) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 790:
(()()()())
</pre>
=={{header|Kotlin}}==
Line 944 ⟶ 943:
([{}][][])
([][][][])</pre>
=={{header|Perl 6}}==▼
Bags are represented by Perl 6 type [http://doc.perl6.org/type/Bag <code>Bag</code>].▼
<lang perl6>use v6;▼
multi expand-tree ( Bag $tree ) {▼
bag(bag(bag()) (+) $tree) (+)▼
[(+)] (▼
$tree.keys ==> map {▼
$^a.&expand-tree.map: * (+) ( $tree (-) bag($^a) )▼
}▼
);▼
}▼
multi expand-trees ( Bag $trees ) {▼
[(+)] $trees.keys.map: { $_.&expand-tree } ;▼
} ▼
my $n = 5;▼
for ( bag(), bag(bag()), *.&expand-trees ... * )[$n] {▼
print ++$,".\t";▼
.say▼
};▼
</lang>▼
{{out}}▼
<pre>▼
1. bag(bag(), bag(bag()(2))) => 2▼
2. bag(bag(bag()(3))) => 1▼
3. bag(bag(bag(bag()), bag())) => 2▼
4. bag(bag(bag(bag(bag())))) => 1▼
5. bag(bag(bag())(2)) => 1▼
6. bag(bag(bag(bag()(2)))) => 1▼
7. bag(bag(), bag(bag(bag()))) => 2▼
8. bag(bag(bag()), bag()(2)) => 2▼
9. bag(bag()(4)) => 1▼
</pre>▼
The bag <code>bag(bag(bag()), bag()(2))</code> coresponds with <code>((())()())</code>. There are two independent ways how we can get it by nesting 4 bags.▼
=={{header|Phix}}==
Line 1,254 ⟶ 1,215:
((((()))))
#t</pre>
(formerly Perl 6)
▲Bags are represented by Perl 6 type [http://doc.perl6.org/type/Bag <code>Bag</code>].
▲<lang perl6>use v6;
▲multi expand-tree ( Bag $tree ) {
▲ bag(bag(bag()) (+) $tree) (+)
▲ [(+)] (
▲ $tree.keys ==> map {
▲ $^a.&expand-tree.map: * (+) ( $tree (-) bag($^a) )
▲ }
▲ );
▲}
▲multi expand-trees ( Bag $trees ) {
▲ [(+)] $trees.keys.map: { $_.&expand-tree } ;
▲}
▲my $n = 5;
▲for ( bag(), bag(bag()), *.&expand-trees ... * )[$n] {
▲ print ++$,".\t";
▲ .say
▲};
▲</lang>
▲{{out}}
▲<pre>
▲1. bag(bag(), bag(bag()(2))) => 2
▲2. bag(bag(bag()(3))) => 1
▲3. bag(bag(bag(bag()), bag())) => 2
▲4. bag(bag(bag(bag(bag())))) => 1
▲5. bag(bag(bag())(2)) => 1
▲6. bag(bag(bag(bag()(2)))) => 1
▲7. bag(bag(), bag(bag(bag()))) => 2
▲8. bag(bag(bag()), bag()(2)) => 2
▲9. bag(bag()(4)) => 1
▲</pre>
▲The bag <code>bag(bag(bag()), bag()(2))</code> coresponds with <code>((())()())</code>. There are two independent ways how we can get it by nesting 4 bags.
=={{header|REXX}}==
|