Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Permutations/Raku/permutations-1.raku
Normal file
1
Task/Permutations/Raku/permutations-1.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
.say for <a b c>.permutations
|
||||
16
Task/Permutations/Raku/permutations-2.raku
Normal file
16
Task/Permutations/Raku/permutations-2.raku
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
sub next_perm ( @a is copy ) {
|
||||
my $j = @a.end - 1;
|
||||
return Nil if --$j < 0 while @a[$j] after @a[$j+1];
|
||||
|
||||
my $aj = @a[$j];
|
||||
my $k = @a.end;
|
||||
$k-- while $aj after @a[$k];
|
||||
@a[ $j, $k ] .= reverse;
|
||||
|
||||
my $r = @a.end;
|
||||
my $s = $j + 1;
|
||||
@a[ $r--, $s++ ] .= reverse while $r > $s;
|
||||
return @a;
|
||||
}
|
||||
|
||||
.say for [<a b c>], &next_perm ...^ !*;
|
||||
13
Task/Permutations/Raku/permutations-3.raku
Normal file
13
Task/Permutations/Raku/permutations-3.raku
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
sub permute(+@items) {
|
||||
my @seq := 1..+@items;
|
||||
gather for (^[*] @seq) -> $n is copy {
|
||||
my @order;
|
||||
for @seq {
|
||||
unshift @order, $n mod $_;
|
||||
$n div= $_;
|
||||
}
|
||||
my @i-copy = @items;
|
||||
take map { |@i-copy.splice($_, 1) }, @order;
|
||||
}
|
||||
}
|
||||
.say for permute( 'a'..'c' )
|
||||
1
Task/Permutations/Raku/permutations-4.raku
Normal file
1
Task/Permutations/Raku/permutations-4.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
.say for permutations(3);
|
||||
47
Task/Permutations/Raku/permutations-5.raku
Normal file
47
Task/Permutations/Raku/permutations-5.raku
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Heap’s algorithm for generating permutations. Algorithm 2 in
|
||||
# Robert Sedgewick, 1977. Permutation generation methods. ACM
|
||||
# Comput. Surv. 9, 2 (June 1977), 137-164.
|
||||
|
||||
define(n, 3)
|
||||
define(n_minus_1, 2)
|
||||
|
||||
implicit none
|
||||
|
||||
integer a(1:n)
|
||||
|
||||
integer c(1:n)
|
||||
integer i, k
|
||||
integer tmp
|
||||
|
||||
10000 format ('(', I1, n_minus_1(' ', I1), ')')
|
||||
|
||||
# Initialize the data to be permuted.
|
||||
do i = 1, n {
|
||||
a(i) = i
|
||||
}
|
||||
|
||||
# What follows is a non-recursive Heap’s algorithm as presented by
|
||||
# Sedgewick. Sedgewick neglects to fully initialize c, so I have
|
||||
# corrected for that. Also I compute k without branching, by instead
|
||||
# doing a little arithmetic.
|
||||
do i = 1, n {
|
||||
c(i) = 1
|
||||
}
|
||||
i = 2
|
||||
write (*, 10000) a
|
||||
while (i <= n) {
|
||||
if (c(i) < i) {
|
||||
k = mod (i, 2) + ((1 - mod (i, 2)) * c(i))
|
||||
tmp = a(i)
|
||||
a(i) = a(k)
|
||||
a(k) = tmp
|
||||
c(i) = c(i) + 1
|
||||
i = 2
|
||||
write (*, 10000) a
|
||||
} else {
|
||||
c(i) = 1
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
34
Task/Permutations/Raku/permutations-6.raku
Normal file
34
Task/Permutations/Raku/permutations-6.raku
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
C Output from Public domain Ratfor, version 1.0
|
||||
implicit none
|
||||
integer a(1: 3)
|
||||
integer c(1: 3)
|
||||
integer i, k
|
||||
integer tmp
|
||||
10000 format ('(', i1, 2(' ', i1), ')')
|
||||
do23000 i = 1, 3
|
||||
a(i) = i
|
||||
23000 continue
|
||||
23001 continue
|
||||
do23002 i = 1, 3
|
||||
c(i) = 1
|
||||
23002 continue
|
||||
23003 continue
|
||||
i = 2
|
||||
write (*, 10000) a
|
||||
23004 if(i .le. 3)then
|
||||
if(c(i) .lt. i)then
|
||||
k = mod (i, 2) + ((1 - mod (i, 2)) * c(i))
|
||||
tmp = a(i)
|
||||
a(i) = a(k)
|
||||
a(k) = tmp
|
||||
c(i) = c(i) + 1
|
||||
i = 2
|
||||
write (*, 10000) a
|
||||
else
|
||||
c(i) = 1
|
||||
i = i + 1
|
||||
endif
|
||||
goto 23004
|
||||
endif
|
||||
23005 continue
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue