Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -1 +1,2 @@
|
|||
perms=: A.&i.~ !
|
||||
perms=: ! A.&i. ] NB. permutations of n things
|
||||
Perms=: {~ perms@# NB. generalized version
|
||||
|
|
|
|||
|
|
@ -1,7 +1,14 @@
|
|||
perms 2
|
||||
0 1
|
||||
1 0
|
||||
({~ perms@#)&.;: 'some random text'
|
||||
Perms 'abc'
|
||||
abc
|
||||
acb
|
||||
bac
|
||||
bca
|
||||
cab
|
||||
cba
|
||||
Perms&.;: 'some random text'
|
||||
some random text
|
||||
some text random
|
||||
random some text
|
||||
|
|
|
|||
4
Task/Permutations/PascalABC.NET/permutations.pas
Normal file
4
Task/Permutations/PascalABC.NET/permutations.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
##
|
||||
var a: array of integer := (1, 2, 3);
|
||||
writeln(a);
|
||||
while nextpermutation(a) do writeln(a);
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
templates lexicalPermutations
|
||||
when <=1> do [1] !
|
||||
permutations templates
|
||||
when <|=1> do [1] !
|
||||
otherwise
|
||||
def n: $;
|
||||
def p: [ $n - 1 -> lexicalPermutations ];
|
||||
1..$n -> \(def k: $;
|
||||
$p... -> [ $k, $... -> \(when <$k..> do $+1! otherwise $!\)] !\) !
|
||||
end lexicalPermutations
|
||||
n is $;
|
||||
expand templates
|
||||
p is $;
|
||||
1..$n -> templates
|
||||
k is $;
|
||||
[$p(..$k - 1)..., $n, $p($k..)...] !
|
||||
end !
|
||||
end expand
|
||||
$n - 1 -> # -> expand !
|
||||
end permutations
|
||||
|
||||
def alpha: ['ABCD'...];
|
||||
[ $alpha::length -> lexicalPermutations -> '$alpha($)...;' ] -> !OUT::write
|
||||
alpha is ['ABCD'...];
|
||||
[ $alpha::length -> permutations -> '$alpha($)...;' ] !
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
templates lexicalPermutations2
|
||||
def N: $;
|
||||
[[1]] -> #
|
||||
when <[<[]($N)>]> do $... !
|
||||
templates lexicalPermutations
|
||||
when <=1> do [1] !
|
||||
otherwise
|
||||
def tails: $;
|
||||
[1..$tails(1)::length+1 -> \(
|
||||
def first: $;
|
||||
$tails... -> [$first, $... -> \(when <$first..> do $+1! otherwise $!\)] !
|
||||
\)] -> #
|
||||
end lexicalPermutations2
|
||||
def n: $;
|
||||
def p: [ $n - 1 -> lexicalPermutations ];
|
||||
1..$n -> \(def k: $;
|
||||
$p... -> [ $k, $... -> \(when <$k..> do $+1! otherwise $!\)] !\) !
|
||||
end lexicalPermutations
|
||||
|
||||
def alpha: ['ABCD'...];
|
||||
[ $alpha::length -> lexicalPermutations2 -> '$alpha($)...;' ] -> !OUT::write
|
||||
[ $alpha::length -> lexicalPermutations -> '$alpha($)...;' ] -> !OUT::write
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
templates perms
|
||||
templates findPerms
|
||||
when <$@perms::length..> do $@perms !
|
||||
otherwise
|
||||
def index: $;
|
||||
$index..$@perms::length
|
||||
-> \(
|
||||
@perms([$, $index]): $@perms([$index, $])...;
|
||||
$index + 1 -> findPerms !
|
||||
\) !
|
||||
@perms([last, $index..last-1]): $@perms($index..last)...;
|
||||
end findPerms
|
||||
@: [1..$];
|
||||
1 -> findPerms !
|
||||
end perms
|
||||
lexicalPermutations templates
|
||||
when <|=1> do [1] !
|
||||
otherwise
|
||||
n is $;
|
||||
p is [ $n - 1 -> # ];
|
||||
1..$n -> templates
|
||||
k is $;
|
||||
$p... -> [ $k, $... -> templates
|
||||
when <|$k..> do $+1!
|
||||
otherwise $!
|
||||
end] !
|
||||
end!
|
||||
end lexicalPermutations
|
||||
|
||||
def alpha: ['ABCD'...];
|
||||
[4 -> perms -> '$alpha($)...;' ] -> !OUT::write
|
||||
alpha is ['ABCD'...];
|
||||
[ $alpha::length -> lexicalPermutations -> '$alpha($)...;' ] !
|
||||
|
|
|
|||
14
Task/Permutations/Tailspin/permutations-5.tailspin
Normal file
14
Task/Permutations/Tailspin/permutations-5.tailspin
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
templates lexicalPermutations2
|
||||
def N: $;
|
||||
[[1]] -> #
|
||||
when <[<[]($N)>]> do $... !
|
||||
otherwise
|
||||
def tails: $;
|
||||
[1..$tails(1)::length+1 -> \(
|
||||
def first: $;
|
||||
$tails... -> [$first, $... -> \(when <$first..> do $+1! otherwise $!\)] !
|
||||
\)] -> #
|
||||
end lexicalPermutations2
|
||||
|
||||
def alpha: ['ABCD'...];
|
||||
[ $alpha::length -> lexicalPermutations2 -> '$alpha($)...;' ] -> !OUT::write
|
||||
17
Task/Permutations/Tailspin/permutations-6.tailspin
Normal file
17
Task/Permutations/Tailspin/permutations-6.tailspin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
lexicalPermutations2 templates
|
||||
N is $;
|
||||
[[1]] -> # !
|
||||
when <|[<|[](=$N)>]> do $... !
|
||||
otherwise
|
||||
tails is $;
|
||||
[1..$tails(1)::length + 1 -> templates
|
||||
first is $;
|
||||
$tails... -> [$first, $... -> templates
|
||||
when <|$first..> do $ + 1!
|
||||
otherwise $!
|
||||
end] !
|
||||
end] -> # !
|
||||
end lexicalPermutations2
|
||||
|
||||
alpha is ['ABCD'...];
|
||||
[ $alpha::length -> lexicalPermutations2 -> '$alpha($)...;' ] !
|
||||
18
Task/Permutations/Tailspin/permutations-7.tailspin
Normal file
18
Task/Permutations/Tailspin/permutations-7.tailspin
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
templates perms
|
||||
templates findPerms
|
||||
when <$@perms::length..> do $@perms !
|
||||
otherwise
|
||||
def index: $;
|
||||
$index..$@perms::length
|
||||
-> \(
|
||||
@perms([$, $index]): $@perms([$index, $])...;
|
||||
$index + 1 -> findPerms !
|
||||
\) !
|
||||
@perms([last, $index..last-1]): $@perms($index..last)...;
|
||||
end findPerms
|
||||
@: [1..$];
|
||||
1 -> findPerms !
|
||||
end perms
|
||||
|
||||
def alpha: ['ABCD'...];
|
||||
[4 -> perms -> '$alpha($)...;' ] -> !OUT::write
|
||||
23
Task/Permutations/Tailspin/permutations-8.tailspin
Normal file
23
Task/Permutations/Tailspin/permutations-8.tailspin
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
perms templates
|
||||
findPerms source
|
||||
@ set [1..$@perms::length];
|
||||
1 -> # !
|
||||
when <|..0> do VOID
|
||||
when <|$@perms::length..> do
|
||||
$@perms !
|
||||
$ - 1 -> # !
|
||||
when <|?($@($) matches <|$@perms::length~..>)> do
|
||||
@perms([$@perms::last, $..~$@perms::last]) set $@perms($..)...;
|
||||
@($) set $;
|
||||
$ - 1 -> #!
|
||||
otherwise
|
||||
@perms([$@($), $]) set $@perms([$, $@($)])...;
|
||||
@($) set $@($) + 1;
|
||||
$ + 1 -> # !
|
||||
end findPerms
|
||||
@ set [1..$];
|
||||
$findPerms !
|
||||
end perms
|
||||
|
||||
alpha is ['ABCD'...];
|
||||
[4 -> perms -> '$alpha($)...;' ] !
|
||||
Loading…
Add table
Add a link
Reference in a new issue