Last active
March 25, 2021 22:22
-
-
Save cognominal/5458754 to your computer and use it in GitHub Desktop.
Problem is \:get_attr_str() not implemented in class 'Coroutine'current instr.: 'print_exception' pc 111585 (src/gen/CORE.setting.pir:50152) (src/gen/CORE.setting:9760) #raku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We recursively.generate permutations | |
# Here is one step of the recursion : | |
# Given a array @l, $e is its first element and @m the array @l minus $e. We | |
# get the permutations of @l by getting all the permutations of @m. For each | |
# such permutation, we alternatively insert $e in each possible position obtaining | |
# @m+1 arrays. | |
sub permutations(*@l is copy) { | |
gather { | |
if @l == 1 { | |
take @l; | |
} else { | |
while (my $e = @l.shift) { | |
# say "=@l[]"; | |
# say $e; | |
for permutations(@l) -> @p { | |
for 0..@p { | |
my @r = @p; | |
@r.splice: $_, 0, $e; | |
# say "?@r[]"; | |
take @r; | |
} | |
} | |
} | |
} | |
} | |
} | |
my @a = permutations 1; | |
say "done: @a[]"; | |
@a = permutations 1..4; | |
say "done: @a[]"; | |
=begin END | |
proto sub fact($i) { ... } | |
multi sub fact(0) { 1 } | |
multi suv fact($n) { $n * fact($n-1)} | |
+uniq permutations(5) == fact 5 |
In the new version, I am stuck again with the same problem
I may have hit a limit of the current implementaton
[14:54] cognominal: iirc [Coke] has hit another limitation of gather/take recentely; if you reuse the same gather/take block, the first iterator has to be exhausted before the second one is started
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the problem was solved by moving the return outside the gather.
thx @jnthn.
the program is not yet correct.
I will submit the correct program as a pullt request to the rakudo repository