Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
56
Task/Combinations/Ada/combinations-1.adb
Normal file
56
Task/Combinations/Ada/combinations-1.adb
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Test_Combinations is
|
||||
generic
|
||||
type Integers is range <>;
|
||||
package Combinations is
|
||||
type Combination is array (Positive range <>) of Integers;
|
||||
procedure First (X : in out Combination);
|
||||
procedure Next (X : in out Combination);
|
||||
procedure Put (X : Combination);
|
||||
end Combinations;
|
||||
|
||||
package body Combinations is
|
||||
procedure First (X : in out Combination) is
|
||||
begin
|
||||
X (1) := Integers'First;
|
||||
for I in 2..X'Last loop
|
||||
X (I) := X (I - 1) + 1;
|
||||
end loop;
|
||||
end First;
|
||||
procedure Next (X : in out Combination) is
|
||||
begin
|
||||
for I in reverse X'Range loop
|
||||
if X (I) < Integers'Val (Integers'Pos (Integers'Last) - X'Last + I) then
|
||||
X (I) := X (I) + 1;
|
||||
for J in I + 1..X'Last loop
|
||||
X (J) := X (J - 1) + 1;
|
||||
end loop;
|
||||
return;
|
||||
end if;
|
||||
end loop;
|
||||
raise Constraint_Error;
|
||||
end Next;
|
||||
procedure Put (X : Combination) is
|
||||
begin
|
||||
for I in X'Range loop
|
||||
Put (Integers'Image (X (I)));
|
||||
end loop;
|
||||
end Put;
|
||||
end Combinations;
|
||||
|
||||
type Five is range 0..4;
|
||||
package Fives is new Combinations (Five);
|
||||
use Fives;
|
||||
|
||||
X : Combination (1..3);
|
||||
begin
|
||||
First (X);
|
||||
loop
|
||||
Put (X); New_Line;
|
||||
Next (X);
|
||||
end loop;
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
null;
|
||||
end Test_Combinations;
|
||||
1
Task/Combinations/Ada/combinations-2.adb
Normal file
1
Task/Combinations/Ada/combinations-2.adb
Normal file
|
|
@ -0,0 +1 @@
|
|||
type Five is range 0..4;
|
||||
11
Task/Combinations/Emacs-Lisp/combinations.el
Normal file
11
Task/Combinations/Emacs-Lisp/combinations.el
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(defun comb-recurse (m n n-max)
|
||||
(cond ((zerop m) '(()))
|
||||
((= n-max n) '())
|
||||
(t (append (mapcar #'(lambda (rest) (cons n rest))
|
||||
(comb-recurse (1- m) (1+ n) n-max))
|
||||
(comb-recurse m (1+ n) n-max)))))
|
||||
|
||||
(defun comb (m n)
|
||||
(comb-recurse m 0 n))
|
||||
|
||||
(comb 3 5)
|
||||
32
Task/Combinations/Euphoria/combinations.eu
Normal file
32
Task/Combinations/Euphoria/combinations.eu
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
sequence combinations = {}
|
||||
|
||||
procedure recurse(sequence remaining, /* digits remaining to compute */
|
||||
integer ne, /* number of digits expected for a valid combination */
|
||||
sequence selected = {}) /* digits already selected for a potential combination */
|
||||
integer nr = length(remaining) -- number of digits remaining to compute
|
||||
integer ns = length(selected) -- number of digits already selected for a potential combination
|
||||
if ns+nr = ne then
|
||||
combinations = append(combinations, selected & remaining)
|
||||
return
|
||||
end if
|
||||
if nr = 1 or ns = ne then
|
||||
combinations = append(combinations, selected)
|
||||
return
|
||||
end if
|
||||
-- select next
|
||||
recurse(remove(remaining, 1), ne, selected & remaining[1])
|
||||
-- skip next
|
||||
recurse(remove(remaining, 1), ne, selected)
|
||||
end procedure
|
||||
|
||||
function get_combinations(sequence s, integer lg)
|
||||
combinations = {}
|
||||
recurse(s, lg)
|
||||
return combinations
|
||||
end function
|
||||
|
||||
constant TEST_SEQUENCE = {0,1,2,3,4}
|
||||
|
||||
combinations = {}
|
||||
recurse(TEST_SEQUENCE, 3)
|
||||
? combinations
|
||||
7
Task/Combinations/Frink/combinations.frink
Normal file
7
Task/Combinations/Frink/combinations.frink
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
combinations[m, n] :=
|
||||
{
|
||||
a = toArray[0 to n-1]
|
||||
return lexicalSort[a.combinations[m]]
|
||||
}
|
||||
|
||||
println[formatTable[combinations[3,5]]]
|
||||
35
Task/Combinations/PowerShell/combinations.ps1
Normal file
35
Task/Combinations/PowerShell/combinations.ps1
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
$source = @'
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Powershell
|
||||
{
|
||||
public class CSharp
|
||||
{
|
||||
public static IEnumerable<int[]> Combinations(int m, int n)
|
||||
{
|
||||
int[] result = new int[m];
|
||||
Stack<int> stack = new Stack<int>();
|
||||
stack.Push(0);
|
||||
|
||||
while (stack.Count > 0) {
|
||||
int index = stack.Count - 1;
|
||||
int value = stack.Pop();
|
||||
|
||||
while (value < n) {
|
||||
result[index++] = value++;
|
||||
stack.Push(value);
|
||||
if (index == m) {
|
||||
yield return result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'@
|
||||
|
||||
Add-Type -TypeDefinition $source -Language CSharp
|
||||
|
||||
[Powershell.CSharp]::Combinations(3,5) | Format-Wide {$_} -Column 3 -Force
|
||||
40
Task/Combinations/VBScript/combinations.vbs
Normal file
40
Task/Combinations/VBScript/combinations.vbs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
Function Dec2Bin(n)
|
||||
q = n
|
||||
Dec2Bin = ""
|
||||
Do Until q = 0
|
||||
Dec2Bin = CStr(q Mod 2) & Dec2Bin
|
||||
q = Int(q / 2)
|
||||
Loop
|
||||
Dec2Bin = Right("00000" & Dec2Bin,6)
|
||||
End Function
|
||||
|
||||
Sub Combination(n,k)
|
||||
Dim arr()
|
||||
ReDim arr(n-1)
|
||||
For h = 0 To n-1
|
||||
arr(h) = h + 1
|
||||
Next
|
||||
Set list = CreateObject("System.Collections.Arraylist")
|
||||
For i = 1 To 2^n
|
||||
bin = Dec2Bin(i)
|
||||
c = 0
|
||||
tmp_combo = ""
|
||||
If Len(Replace(bin,"0","")) = k Then
|
||||
For j = Len(bin) To 1 Step -1
|
||||
If CInt(Mid(bin,j,1)) = 1 Then
|
||||
tmp_combo = tmp_combo & arr(c) & ","
|
||||
End If
|
||||
c = c + 1
|
||||
Next
|
||||
list.Add Mid(tmp_combo,1,(k*2)-1)
|
||||
End If
|
||||
Next
|
||||
list.Sort
|
||||
For l = 0 To list.Count-1
|
||||
WScript.StdOut.Write list(l)
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'Testing with n = 5 / k = 3
|
||||
Call Combination(5,3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue