Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
7
Task/Combinations/APL/combinations-1.apl
Normal file
7
Task/Combinations/APL/combinations-1.apl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
comb←{(⍺=0)∨⍺=⍵:⌷⍉⍪⍳⍺ ⋄ (0,1+(⍺-1)∇ ⍵-1)⍪1+⍺ ∇ ⍵-1}
|
||||
4 comb 5
|
||||
0 1 2 3
|
||||
0 1 2 5
|
||||
0 1 4 5
|
||||
0 3 4 5
|
||||
2 3 4 5
|
||||
7
Task/Combinations/APL/combinations-2.apl
Normal file
7
Task/Combinations/APL/combinations-2.apl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
comb←{
|
||||
⍺{
|
||||
0=⍺:⊂⍬
|
||||
0=≢⍵:⍬
|
||||
((⊃⍵),¨(⍺-1)∇r),⍺∇r←1↓⍵
|
||||
}⍳⍵
|
||||
}
|
||||
17
Task/Combinations/FOCAL/combinations.focal
Normal file
17
Task/Combinations/FOCAL/combinations.focal
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
01.10 S M=3
|
||||
01.20 S N=5
|
||||
01.30 D 2
|
||||
01.40 Q
|
||||
|
||||
02.10 F I=1,M;S C(I)=I-1
|
||||
02.20 D 3
|
||||
02.30 S I=M
|
||||
02.40 S C(I)=C(I)+1
|
||||
02.50 I (C(I)-N+M-I)2.8
|
||||
02.60 S I=I-1
|
||||
02.70 I (-I)2.4;R
|
||||
02.80 F J=I+1,M;S C(J)=C(J-1)+1
|
||||
02.90 G 2.2
|
||||
|
||||
03.10 F I=1,M;T %3,C(I)
|
||||
03.20 T !
|
||||
|
|
@ -1,3 +1 @@
|
|||
combr=: dyad define M.
|
||||
if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x combr&.<: y),1+x combr y-1 end.
|
||||
)
|
||||
combr=: ((0,.$:&.<:),1+($:<:))` (<:i.@,[) @.(>:+.0=[)M.
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
combr=: ((0,.$:&.<:),1+($:<:))` ([:i.<:,[) @.(>:+.0=[)M.
|
||||
combr=: dyad define M.
|
||||
if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x combr&.<: y),1+x combr y-1 end.
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1 @@
|
|||
combr1=: dyad define
|
||||
if.(x=#y) +. x=1 do.
|
||||
y
|
||||
else.
|
||||
(({.y) ,. (x-1) combr (}.y)) , (x combr }.y)
|
||||
end.
|
||||
)
|
||||
combr1=: (({.@],.<:@[$:}.@]),($:}.))` ] @.((= #)+.1=[)
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
combr1=: (({.@],.<:@($:}.)),($:}.))` ] @.((= #)+.1=[)
|
||||
combr1=: dyad define
|
||||
if.(x=#y) +. x=1 do.
|
||||
y
|
||||
else.
|
||||
(({.y) ,. (x-1) combr (}.y)) , (x combr }.y)
|
||||
end.
|
||||
)
|
||||
|
|
|
|||
29
Task/Combinations/Java/combinations-2.java
Normal file
29
Task/Combinations/Java/combinations-2.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class Combinations {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(createCombinations(List.of( 0, 1, 2, 3, 4 ), 3));
|
||||
System.out.println(createCombinations(List.of( "Crosby", "Nash", "Stills", "Young" ), 3));
|
||||
}
|
||||
|
||||
private static <T> List<List<T>> createCombinations(List<T> elements, int k) {
|
||||
List<List<T>> combinations = new ArrayList<List<T>>();
|
||||
createCombinations(elements, k, new ArrayList<T>(), combinations, 0);
|
||||
return combinations;
|
||||
}
|
||||
|
||||
private static <T> void createCombinations(
|
||||
List<T> elements, int k, List<T> accumulator, List<List<T>> combinations, int index) {
|
||||
if ( accumulator.size() == k ) {
|
||||
combinations.addFirst( new ArrayList<T>(accumulator) );
|
||||
} else if ( k - accumulator.size() <= elements.size() - index ) {
|
||||
createCombinations(elements, k, accumulator, combinations, index + 1);
|
||||
accumulator.add(elements.get(index));
|
||||
createCombinations(elements, k, accumulator, combinations, index + 1);
|
||||
accumulator.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
8
Task/Combinations/Miranda/combinations.miranda
Normal file
8
Task/Combinations/Miranda/combinations.miranda
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay (map show (comb 3 5)))]
|
||||
|
||||
comb :: num->num->[[num]]
|
||||
comb m n = comb' m [0..n-1]
|
||||
where comb' 0 xs = [[]]
|
||||
comb' m [] = []
|
||||
comb' m (x:xs) = map (x:) (comb' (m-1) xs) ++ comb' m xs
|
||||
2
Task/Combinations/PascalABC.NET/combinations.pas
Normal file
2
Task/Combinations/PascalABC.NET/combinations.pas
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
##
|
||||
(0..4).combinations(3).printlines;
|
||||
23
Task/Combinations/Refal/combinations.refal
Normal file
23
Task/Combinations/Refal/combinations.refal
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
$ENTRY Go {
|
||||
= <Prout <Comb 3 5>>;
|
||||
};
|
||||
|
||||
Comb {
|
||||
s.M s.N = <Comb1 s.M <Iota 0 <- s.N 1>>>;
|
||||
};
|
||||
|
||||
Comb1 {
|
||||
0 e.X = ();
|
||||
s.M = ;
|
||||
s.M s.X e.X = <PfxEach s.X <Comb1 <- s.M 1> e.X>> <Comb1 s.M e.X>;
|
||||
};
|
||||
|
||||
PfxEach {
|
||||
s.X = ;
|
||||
s.X (e.X) e.Y = (s.X e.X) <PfxEach s.X e.Y>;
|
||||
};
|
||||
|
||||
Iota {
|
||||
s.E s.E = s.E;
|
||||
s.S s.E = s.S <Iota <+ 1 s.S> s.E>;
|
||||
};
|
||||
7
Task/Combinations/Tailspin/combinations.tailspin
Normal file
7
Task/Combinations/Tailspin/combinations.tailspin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
operator (m comb n)
|
||||
[by 0..~$n] -> #
|
||||
when <[](..~$m)> do [$..., by $(last)~..~$n] -> #
|
||||
otherwise $!
|
||||
end comb
|
||||
|
||||
(3 comb 5) -> !OUT::write
|
||||
Loading…
Add table
Add a link
Reference in a new issue