Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -6,7 +6,7 @@ struct Permutations(bool doCopy=true, T) if (isMutable!T) {
|
|||
private uint[31] indexes;
|
||||
private ulong tot;
|
||||
|
||||
this (/*in*/ T[] items) /*pure nothrow*/
|
||||
this (in T[] items) pure /*nothrow*/
|
||||
in {
|
||||
static enum string L = text(indexes.length); // impure
|
||||
assert(items.length >= 0 && items.length <= indexes.length,
|
||||
|
|
@ -66,21 +66,18 @@ struct Permutations(bool doCopy=true, T) if (isMutable!T) {
|
|||
}
|
||||
|
||||
Permutations!(doCopy,T) permutations(bool doCopy=true, T)
|
||||
(/*in*/ T[] items)
|
||||
/*pure nothrow*/ if (isMutable!T) {
|
||||
(in T[] items)
|
||||
pure /*nothrow*/ if (isMutable!T) {
|
||||
return Permutations!(doCopy, T)(items);
|
||||
} unittest {
|
||||
import std.bigint;
|
||||
foreach (p; permutations([BigInt(1), BigInt(2), BigInt(3)]))
|
||||
assert((p[0] + 1) > 0);
|
||||
}
|
||||
|
||||
version (permutations2_main) {
|
||||
void main() {
|
||||
import std.stdio, std.bigint;
|
||||
foreach (p; permutations!false([1, 2, 3]))
|
||||
writeln(p);
|
||||
alias BigInt B;
|
||||
foreach (p; permutations!false([B(1), B(2), B(3)])) {}
|
||||
alias B = BigInt;
|
||||
foreach (p; [B(1), B(2), B(3)].permutations)
|
||||
assert((p[0] + 1) > 0);
|
||||
[1, 2, 3].permutations!false.writeln;
|
||||
[B(1), B(2), B(3)].permutations!false.writeln;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
Task/Permutations/Liberty-BASIC/permutations-1.liberty
Normal file
28
Task/Permutations/Liberty-BASIC/permutations-1.liberty
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
n=3
|
||||
dim a(n+1) '+1 needed due to bug in LB that checks loop condition
|
||||
' until (i=0) or (a(i)<a(i+1))
|
||||
'before executing i=i-1 in loop body.
|
||||
for i=1 to n: a(i)=i: next
|
||||
do
|
||||
for i=1 to n: print a(i);: next: print
|
||||
i=n
|
||||
do
|
||||
i=i-1
|
||||
loop until (i=0) or (a(i)<a(i+1))
|
||||
j=i+1
|
||||
k=n
|
||||
while j<k
|
||||
'swap a(j),a(k)
|
||||
tmp=a(j): a(j)=a(k): a(k)=tmp
|
||||
j=j+1
|
||||
k=k-1
|
||||
wend
|
||||
if i>0 then
|
||||
j=i+1
|
||||
while a(j)<a(i)
|
||||
j=j+1
|
||||
wend
|
||||
'swap a(i),a(j)
|
||||
tmp=a(j): a(j)=a(i): a(i)=tmp
|
||||
end if
|
||||
loop until i=0
|
||||
19
Task/Permutations/Liberty-BASIC/permutations-2.liberty
Normal file
19
Task/Permutations/Liberty-BASIC/permutations-2.liberty
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
n = 3
|
||||
|
||||
s$=""
|
||||
for i = 1 to n
|
||||
s$=s$;i
|
||||
next
|
||||
|
||||
res$=permutation$("", s$)
|
||||
|
||||
Function permutation$(pre$, post$)
|
||||
lgth = Len(post$)
|
||||
If lgth < 2 Then
|
||||
print pre$;post$
|
||||
Else
|
||||
For i = 1 To lgth
|
||||
tmp$=permutation$(pre$+Mid$(post$,i,1),Left$(post$,i-1)+Right$(post$,lgth-i))
|
||||
Next i
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue