June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -14,5 +14,5 @@
|
|||
(t
|
||||
(setf (first comb-tail) curr)
|
||||
(mc (1+ curr) (1- left) (1- needed) (rest comb-tail))
|
||||
(mc (1+ curr) (1- left) needed comb)))))
|
||||
(mc (1+ curr) (1- left) needed comb-tail)))))
|
||||
(mc 0 n m combination))))
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ const int N = 5.
|
|||
|
||||
numbers = (:anN)
|
||||
[
|
||||
^ Array new length:anN; populate(:n)( n )
|
||||
^ Array new(anN); populate(:n)<int>( n )
|
||||
].
|
||||
|
||||
program =
|
||||
public program =
|
||||
[
|
||||
var aNumbers := numbers eval:N.
|
||||
var aNumbers := numbers(N).
|
||||
Combinator new:M of:aNumbers; forEach(:aRow)
|
||||
[
|
||||
console printLine:aRow
|
||||
console printLine(aRow toLiteral)
|
||||
].
|
||||
|
||||
console readChar.
|
||||
|
|
|
|||
5
Task/Combinations/Glee/combinations-1.glee
Normal file
5
Task/Combinations/Glee/combinations-1.glee
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
5!3 >>> ,,\
|
||||
|
||||
$$(5!3) give all combinations of 3 out of 5
|
||||
$$(>>>) sorted up,
|
||||
$$(,,\) printed with crlf delimiters.
|
||||
11
Task/Combinations/Glee/combinations-2.glee
Normal file
11
Task/Combinations/Glee/combinations-2.glee
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Result:
|
||||
1 2 3
|
||||
1 2 4
|
||||
1 2 5
|
||||
1 3 4
|
||||
1 3 5
|
||||
1 4 5
|
||||
2 3 4
|
||||
2 3 5
|
||||
2 4 5
|
||||
3 4 5
|
||||
27
Task/Combinations/Julia/combinations-2.julia
Normal file
27
Task/Combinations/Julia/combinations-2.julia
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
##############################
|
||||
# COMBINATIONS OF 3 OUT OF 5 #
|
||||
##############################
|
||||
|
||||
# Set n and m
|
||||
m = 5
|
||||
n = 3
|
||||
|
||||
# Prepare the boundary of the calculation. Only m - n numbers are changing in each position.
|
||||
max_n = m - n
|
||||
|
||||
#Prepare an array for result
|
||||
result = zeros(Int64, n)
|
||||
|
||||
function combinations(pos, val) # n, max_n and result are visible in the function
|
||||
for i = val:max_n # from current value to the boundary
|
||||
result[pos] = pos + i # fill the position of result
|
||||
if pos < n # if combination isn't complete,
|
||||
combinations(pos+1, i) # go to the next position
|
||||
else
|
||||
println(result) # combination is complete, print it
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
combinations(1, 0)
|
||||
end
|
||||
36
Task/Combinations/Modula-2/combinations.mod2
Normal file
36
Task/Combinations/Modula-2/combinations.mod2
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
MODULE Combinations;
|
||||
FROM STextIO IMPORT
|
||||
WriteString, WriteLn;
|
||||
FROM SWholeIO IMPORT
|
||||
WriteInt;
|
||||
|
||||
CONST
|
||||
MMax = 3;
|
||||
NMax = 5;
|
||||
|
||||
VAR
|
||||
Combination: ARRAY [0 .. MMax] OF CARDINAL;
|
||||
|
||||
PROCEDURE Generate(M: CARDINAL);
|
||||
VAR
|
||||
N, I: CARDINAL;
|
||||
BEGIN
|
||||
IF (M > MMax) THEN
|
||||
FOR I := 1 TO MMax DO
|
||||
WriteInt(Combination[I], 1);
|
||||
WriteString(' ');
|
||||
END;
|
||||
WriteLn;
|
||||
ELSE
|
||||
FOR N := 1 TO NMax DO
|
||||
IF (M = 1) OR (N > Combination[M - 1]) THEN
|
||||
Combination[M] := N;
|
||||
Generate(M + 1);
|
||||
END
|
||||
END
|
||||
END
|
||||
END Generate;
|
||||
|
||||
BEGIN
|
||||
Generate(1);
|
||||
END Combinations.
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
//Author: I. Gavryushin aka dcc0
|
||||
//set amount of elements as in $n var
|
||||
|
||||
$a=array(1,2,3,4,5);
|
||||
$k=3;
|
||||
$n=5;
|
||||
|
|
|
|||
75
Task/Combinations/Ring/combinations.ring
Normal file
75
Task/Combinations/Ring/combinations.ring
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
# Project : Combinations
|
||||
# Date : 2017/10/29
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
n = 5
|
||||
k = 3
|
||||
temp = []
|
||||
comb = []
|
||||
num = com(n, k)
|
||||
while true
|
||||
temp = []
|
||||
for n = 1 to 3
|
||||
tm = random(4) + 1
|
||||
add(temp, tm)
|
||||
next
|
||||
bool1 = (temp[1] = temp[2]) and (temp[1] = temp[3]) and (temp[2] = temp[3])
|
||||
bool2 = (temp[1] < temp[2]) and (temp[2] < temp[3])
|
||||
if not bool1 and bool2
|
||||
add(comb, temp)
|
||||
ok
|
||||
for p = 1 to len(comb) - 1
|
||||
for q = p + 1 to len(comb)
|
||||
if (comb[p][1] = comb[q][1]) and (comb[p][2] = comb[q][2]) and (comb[p][3] = comb[q][3])
|
||||
del(comb, p)
|
||||
ok
|
||||
next
|
||||
next
|
||||
if len(comb) = num
|
||||
exit
|
||||
ok
|
||||
end
|
||||
comb = sortfirst(comb, 1)
|
||||
see showarray(comb) + nl
|
||||
|
||||
func com(n, k)
|
||||
res1 = 1
|
||||
for n1 = n - k + 1 to n
|
||||
res1 = res1 * n1
|
||||
next
|
||||
res2 = 1
|
||||
for n2 = 1 to k
|
||||
res2 = res2 * n2
|
||||
next
|
||||
res3 = res1/res2
|
||||
return res3
|
||||
|
||||
func showarray(vect)
|
||||
svect = ""
|
||||
for nrs = 1 to len(vect)
|
||||
svect = "[" + vect[nrs][1] + " " + vect[nrs][2] + " " + vect[nrs][3] + "]" + nl
|
||||
see svect
|
||||
next
|
||||
|
||||
Func sortfirst(alist, ind)
|
||||
aList = sort(aList,ind)
|
||||
for n = 1 to len(alist)-1
|
||||
for m= n + 1 to len(aList)
|
||||
if alist[n][1] = alist[m][1] and alist[m][2] < alist[n][2]
|
||||
temp = alist[n]
|
||||
alist[n] = alist[m]
|
||||
alist[m] = temp
|
||||
ok
|
||||
next
|
||||
next
|
||||
for n = 1 to len(alist)-1
|
||||
for m= n + 1 to len(aList)
|
||||
if alist[n][1] = alist[m][1] and alist[n][2] = alist[m][2] and alist[m][3] < alist[n][3]
|
||||
temp = alist[n]
|
||||
alist[n] = alist[m]
|
||||
alist[m] = temp
|
||||
ok
|
||||
next
|
||||
next
|
||||
return aList
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
scala> (0 to 4 toList) combinations(3) toList
|
||||
res1: List[List[Int]] = List(List(0, 1, 2), List(0, 1, 3), List(0, 1, 4), List(0, 2, 3), List(0, 2, 4), List(0, 3, 4), List(1, 2, 3), List(1, 2, 4), List(1, 3, 4), List(2, 3, 4))
|
||||
scala>(0 to 4).combinations(3).toList
|
||||
res0: List[scala.collection.immutable.IndexedSeq[Int]] = List(Vector(0, 1, 2), Vector(0, 1, 3), Vector(0, 1, 4), Vector(0, 2, 3), Vector(0, 2, 4), Vector(0, 3, 4), Vector(1, 2, 3), Vector(1, 2, 4), Vector(1, 3, 4), Vector(2, 3, 4))
|
||||
|
|
|
|||
14
Task/Combinations/Stata/combinations-3.stata
Normal file
14
Task/Combinations/Stata/combinations-3.stata
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function combinations(n,k) {
|
||||
a = J(comb(n,k),k,.)
|
||||
u = 1..k
|
||||
for (i=1; 1; i++) {
|
||||
a[i,.] = u
|
||||
for (j=k; j>0; j--) {
|
||||
if (u[j]-j<n-k) break
|
||||
}
|
||||
if (j<1) return(a)
|
||||
u[j..k] = u[j]+1..u[j]+1+k-j
|
||||
}
|
||||
}
|
||||
|
||||
combinations(5,3)
|
||||
64
Task/Combinations/VBA/combinations.vba
Normal file
64
Task/Combinations/VBA/combinations.vba
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
Option Explicit
|
||||
Option Base 0
|
||||
'Option Base 1
|
||||
|
||||
Private ArrResult
|
||||
|
||||
Sub test()
|
||||
'compute
|
||||
Main_Combine 5, 3
|
||||
|
||||
'return
|
||||
Dim j As Long, i As Long, temp As String
|
||||
For i = LBound(ArrResult, 1) To UBound(ArrResult, 1)
|
||||
temp = vbNullString
|
||||
For j = LBound(ArrResult, 2) To UBound(ArrResult, 2)
|
||||
temp = temp & " " & ArrResult(i, j)
|
||||
Next
|
||||
Debug.Print temp
|
||||
Next
|
||||
Erase ArrResult
|
||||
End Sub
|
||||
|
||||
Private Sub Main_Combine(M As Long, N As Long)
|
||||
Dim MyArr, i As Long
|
||||
ReDim MyArr(M - 1)
|
||||
If LBound(MyArr) > 0 Then ReDim MyArr(M) 'Case Option Base 1
|
||||
For i = LBound(MyArr) To UBound(MyArr)
|
||||
MyArr(i) = i
|
||||
Next i
|
||||
i = IIf(LBound(MyArr) > 0, N, N - 1)
|
||||
ReDim ArrResult(i, LBound(MyArr))
|
||||
Combine MyArr, N, LBound(MyArr), LBound(MyArr)
|
||||
ReDim Preserve ArrResult(UBound(ArrResult, 1), UBound(ArrResult, 2) - 1)
|
||||
'In VBA Excel we can use Application.Transpose instead of personal Function Transposition
|
||||
ArrResult = Transposition(ArrResult)
|
||||
End Sub
|
||||
|
||||
Private Sub Combine(MyArr As Variant, Nb As Long, Deb As Long, Ind As Long)
|
||||
Dim i As Long, j As Long, N As Long
|
||||
For i = Deb To UBound(MyArr, 1)
|
||||
ArrResult(Ind, UBound(ArrResult, 2)) = MyArr(i)
|
||||
N = IIf(LBound(ArrResult, 1) = 0, Nb - 1, Nb)
|
||||
If Ind = N Then
|
||||
ReDim Preserve ArrResult(UBound(ArrResult, 1), UBound(ArrResult, 2) + 1)
|
||||
For j = LBound(ArrResult, 1) To UBound(ArrResult, 1)
|
||||
ArrResult(j, UBound(ArrResult, 2)) = ArrResult(j, UBound(ArrResult, 2) - 1)
|
||||
Next j
|
||||
Else
|
||||
Call Combine(MyArr, Nb, i + 1, Ind + 1)
|
||||
End If
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
Private Function Transposition(ByRef MyArr As Variant) As Variant
|
||||
Dim T, i As Long, j As Long
|
||||
ReDim T(LBound(MyArr, 2) To UBound(MyArr, 2), LBound(MyArr, 1) To UBound(MyArr, 1))
|
||||
For i = LBound(MyArr, 1) To UBound(MyArr, 1)
|
||||
For j = LBound(MyArr, 2) To UBound(MyArr, 2)
|
||||
T(j, i) = MyArr(i, j)
|
||||
Next j
|
||||
Next i
|
||||
Transposition = T
|
||||
Erase T
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue