Talk:List rooted trees
Definition of ways to nest
If I understand correctly, OEIS A81 lists the number of unique ways n bags can be nested, eg 9 for 5 bags. The task description states "As an example output, run 5 bags. There should be 12 ways.". In addition, "( () (()) () )" is considered different from "( (()) () () )". Please explain.
--CraigD (talk) 12:59, 20 August 2015 (UTC)
Raku: when I run the Raku solution I do not see the same output as shown on the web page
I'm puzzled. I run the script (saved exactly as posted on the web site, with the exception that I embed a she-bang and make the script executeable):
1 #!/opt/rakudo/rakudo-moar-2024.04-01-macos-arm64-clang/bin/raku 2 3 # Bags are represented by Raku type Bag. 4 5 use v6; 6 7 multi expand-tree ( Bag $tree ) { 8 bag(bag(bag()) (+) $tree) (+) 9 [(+)] ( 10 $tree.keys ==> map { 11 $^a.&expand-tree.map: * (+) ( $tree (-) bag($^a) ) 12 } 13 ); 14 } 15 16 multi expand-trees ( Bag $trees ) { 17 [(+)] $trees.keys.map: { $_.&expand-tree } ; 18 } 19 20 my $n = 5; 21 for ( bag(), bag(bag()), *.&expand-trees ... * )[$n] { 22 print ++$,".\t"; 23 .say 24 };
The output I see when running the Raku script on my machine: 1. Bag(Bag()(3)) => 1 2. Bag(Bag()(4)) => 1 3. Bag() => 3 4. Bag(Bag()(2)) => 1 5. Bag(Bag()) => 4
The results posted on the web page: 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
My environment: MacOS 14.6.1 Chip: M1 raku --version Welcome to Rakudo™ v2024.04. Implementing the Raku® Programming Language v6.d. Built on MoarVM version 2024.04.
I compiled this Raku from source.
Retired Build Engineer