September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
36
Task/Array-concatenation/ALGOL-W/array-concatenation.alg
Normal file
36
Task/Array-concatenation/ALGOL-W/array-concatenation.alg
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
begin
|
||||
integer array a ( 1 :: 5 );
|
||||
integer array b ( 2 :: 4 );
|
||||
integer array c ( 1 :: 8 );
|
||||
|
||||
% concatenates the arrays a and b into c %
|
||||
% the lower and upper bounds of each array must be specified in %
|
||||
% the corresponding *Lb and *Ub parameters %
|
||||
procedure arrayConcatenate ( integer array a ( * )
|
||||
; integer value aLb, aUb
|
||||
; integer array b ( * )
|
||||
; integer value bLb, bUb
|
||||
; integer array c ( * )
|
||||
; integer value cLb, cUb
|
||||
) ;
|
||||
begin
|
||||
integer cPos;
|
||||
assert( ( cUb - cLb ) + 1 >= ( ( aUb + bUb ) - ( aLb + bLb ) ) - 2 );
|
||||
cPos := cLb;
|
||||
for aPos := aLb until aUb do begin
|
||||
c( cPos ) := a( aPos );
|
||||
cPos := cPos + 1
|
||||
end for_aPos ;
|
||||
for bPos := bLb until bUb do begin
|
||||
c( cPos ) := b( bPos );
|
||||
cPos := cPos + 1
|
||||
end for_bPos
|
||||
end arrayConcatenate ;
|
||||
|
||||
% test arrayConcatenate %
|
||||
for aPos := 1 until 5 do a( aPos ) := aPos;
|
||||
for bPos := 2 until 4 do b( bPos ) := - bPos;
|
||||
arrayConcatenate( a, 1, 5, b, 2, 4, c, 1, 8 );
|
||||
for cPos := 1 until 8 do writeon( i_w := 1, s_w := 1, c( cPos ) )
|
||||
|
||||
end.
|
||||
25
Task/Array-concatenation/Aime/array-concatenation.aime
Normal file
25
Task/Array-concatenation/Aime/array-concatenation.aime
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
list
|
||||
ac(list a, list b)
|
||||
{
|
||||
list o;
|
||||
|
||||
l_ucall(a, l_append, 1, o);
|
||||
l_ucall(b, l_append, 1, o);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
list a, b, c;
|
||||
|
||||
a = l_effect(1, 2, 3, 4);
|
||||
b = l_effect(5, 6, 7, 8);
|
||||
|
||||
c = ac(a, b);
|
||||
|
||||
l_ucall(c, o_, 1, " ");
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
Task/Array-concatenation/BASIC/array-concatenation-1.basic
Normal file
17
Task/Array-concatenation/BASIC/array-concatenation-1.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' Array concatenation
|
||||
OPTION BASE 1
|
||||
|
||||
CONST asize = 2
|
||||
CONST bsize = 3
|
||||
DECLARE a[asize] TYPE NUMBER
|
||||
DECLARE b[bsize] TYPE NUMBER
|
||||
|
||||
' BaCon has no array concatenation builtin, it will need to be done by hand
|
||||
LOCAL c TYPE NUMBER ARRAY asize + bsize
|
||||
FOR i = 1 TO asize
|
||||
c[i] = a[i]
|
||||
NEXT
|
||||
|
||||
FOR i = 1 TO bsize
|
||||
c[asize + i] = b[i]
|
||||
NEXT
|
||||
17
Task/Array-concatenation/BASIC/array-concatenation-3.basic
Normal file
17
Task/Array-concatenation/BASIC/array-concatenation-3.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
10 X=4 : Y=5
|
||||
20 DIM A(X) : DIM B(Y) : DIM C(X+Y)
|
||||
30 FOR I=1 TO X
|
||||
40 : A(I) = I
|
||||
50 NEXT
|
||||
60 FOR I=1 TO Y
|
||||
70 : B(I) = I*10
|
||||
80 NEXT
|
||||
90 FOR I=1 TO X
|
||||
100 : C(I) = A(I)
|
||||
110 NEXT
|
||||
120 FOR I=1 TO Y
|
||||
130 : C(X+I) = B(I)
|
||||
140 NEXT
|
||||
150 FOR I=1 TO X+Y
|
||||
160 : PRINT C(I);
|
||||
170 NEXT
|
||||
50
Task/Array-concatenation/C++/array-concatenation-3.cpp
Normal file
50
Task/Array-concatenation/C++/array-concatenation-3.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
int* concatArrays( T1& array_1, T2& array_2) {
|
||||
int arrayCount_1 = sizeof(array_1) / sizeof(array_1[0]);
|
||||
int arrayCount_2 = sizeof(array_2) / sizeof(array_2[0]);
|
||||
int newArraySize = arrayCount_1 + arrayCount_2;
|
||||
|
||||
int *p = new int[newArraySize];
|
||||
|
||||
for (int i = 0; i < arrayCount_1; i++) {
|
||||
p[i] = array_1[i];
|
||||
}
|
||||
|
||||
for (int i = arrayCount_1; i < newArraySize; i++) {
|
||||
int newIndex = i-arrayCount_2;
|
||||
|
||||
if (newArraySize % 2 == 1)
|
||||
newIndex--;
|
||||
|
||||
p[i] = array_2[newIndex];
|
||||
cout << "i: " << i << endl;
|
||||
cout << "array_2[i]: " << array_2[newIndex] << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int ary[4] = {1, 2, 3, 123};
|
||||
int anotherAry[3] = {4, 5, 6};
|
||||
|
||||
int *r = concatArrays(ary, anotherAry);
|
||||
|
||||
cout << *(r + 0) << endl;
|
||||
cout << *(r + 1) << endl;
|
||||
cout << *(r + 2) << endl;
|
||||
cout << *(r + 3) << endl;
|
||||
cout << *(r + 4) << endl;
|
||||
cout << *(r + 5) << endl;
|
||||
cout << *(r + 6) << endl;
|
||||
|
||||
delete r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
#define system.
|
||||
#define extensions.
|
||||
import extensions.
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
#var a := (1,2,3).
|
||||
#var b := (4,5).
|
||||
var a := (1,2,3).
|
||||
var b := (4,5).
|
||||
|
||||
console writeLine:"(":a:") + (":b:") = (":(a + b):")".
|
||||
console printLine("(",a,") + (",b,") = (",a + b,")"); readChar.
|
||||
].
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
Public Sub Main()
|
||||
Dim sString1 As String[] = ["The", "quick", "brown", "fox"]
|
||||
Dim sString2 As String[] = ["jumped", "over", "the", "lazy", "dog"]
|
||||
|
||||
sString1.Insert(sString2)
|
||||
|
||||
Print sString1.Join(" ")
|
||||
|
||||
End
|
||||
15
Task/Array-concatenation/Hy/array-concatenation.hy
Normal file
15
Task/Array-concatenation/Hy/array-concatenation.hy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
=> (setv a [1 2 3])
|
||||
=> a
|
||||
[1, 2, 3]
|
||||
|
||||
=> (+ a [4 5 6]) ; returns the concatenation
|
||||
[1, 2, 3, 4, 5, 6]
|
||||
=> a
|
||||
[1, 2, 3]
|
||||
|
||||
=> (.extend a [7 8 9]) ; modifies the list in place
|
||||
=> a
|
||||
[1, 2, 3, 7, 8, 9]
|
||||
|
||||
=> (+ [1 2] [3 4] [5 6]) ; can accept multiple arguments
|
||||
[1, 2, 3, 4, 5, 6]
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
public static Object[] objArrayConcat(Object[] o1, Object[] o2)
|
||||
{
|
||||
Object[] ret = new Object[o1.length + o2.length];
|
||||
|
||||
System.arraycopy(o1, 0, ret, 0, o1.length);
|
||||
System.arraycopy(o2, 0, ret, o1.length, o2.length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
Collection list1, list2, list1And2;
|
||||
//...list1 and list2 are instantiated...
|
||||
list1And2 = new ArrayList(list1); //or any other Collection you want
|
||||
list1And2.addAll(list2);
|
||||
8
Task/Array-concatenation/Java/array-concatenation.java
Normal file
8
Task/Array-concatenation/Java/array-concatenation.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
public static Object[] concat(Object[] arr1, Object[] arr2) {
|
||||
Object[] res = new Object[arr1.length + arr2.length];
|
||||
|
||||
System.arraycopy(arr1, 0, res, 0, arr1.length);
|
||||
System.arraycopy(arr2, 0, res, arr1.length, arr2.length);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
a = [1,2,3]
|
||||
b = [4,5,6]
|
||||
ab = [a,b]
|
||||
ab = [a;b]
|
||||
# the above bracket notation simply generates a call to vcat
|
||||
ab = vcat(a,b)
|
||||
# hcat is short for `horizontal concatenation`
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
val a : Array<T> = // initialise a
|
||||
val b : Array<T> = // initialise b
|
||||
val c = (a.toList() + b.toList()).copyToArray()
|
||||
fun main(args: Array<String>) {
|
||||
val a: Array<Int> = arrayOf(1, 2, 3) // initialise a
|
||||
val b: Array<Int> = arrayOf(4, 5, 6) // initialise b
|
||||
val c: Array<Int> = (a.toList() + b.toList()).toTypedArray()
|
||||
println(c)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
fun arrayConcat(a : Array<Any>, b : Array<Any>)
|
||||
= Array<Any>(a.size + b.size, {if (it in a.indices) a[it] else b[it - a.size]})
|
||||
fun arrayConcat(a: Array<Any>, b: Array<Any>): Array<Any> {
|
||||
return Array(a.size + b.size, { if (it in a.indices) a[it] else b[it - a.size] })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
val a : Collection<T> // initialise a
|
||||
val b : Collection<T> = // initialise b
|
||||
val c : Collection = a + b
|
||||
fun main(args: Array<String>) {
|
||||
val a: Collection<Int> = listOf(1, 2, 3) // initialise a
|
||||
val b: Collection<Int> = listOf(4, 5, 6) // initialise b
|
||||
val c: Collection<Int> = a + b
|
||||
println(c)
|
||||
}
|
||||
|
|
|
|||
6
Task/Array-concatenation/OoRexx/array-concatenation.rexx
Normal file
6
Task/Array-concatenation/OoRexx/array-concatenation.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a = .array~of(1,2,3)
|
||||
say "Array a has " a~items "items"
|
||||
b = .array~of(4,5,6)
|
||||
say "Array b has " b~items "items"
|
||||
a~appendall(b) -- adds all items from b to a
|
||||
say "Array a now has " a~items "
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
variable a = [1, 2, 3];
|
||||
variable b = [4, 5, 6];
|
||||
variable b = [4, 5, 6], c;
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
variable la = length(a), c = _typeof(a)[la+length(b)];
|
||||
c[ [:la-1] ] = a;
|
||||
c[ [la:] ] = b;
|
||||
c = [a, b];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
a = {1, 2, 3};
|
||||
b = {4, 5, 6};
|
||||
|
||||
variable c = list_concat(a, b);
|
||||
c = list_concat(a, b);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
c = list_to_array(c);
|
||||
list_join(a, b);
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
list_join(a, b);
|
||||
50
Task/Array-concatenation/Simula/array-concatenation.simula
Normal file
50
Task/Array-concatenation/Simula/array-concatenation.simula
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
BEGIN
|
||||
|
||||
CLASS ARRAYHOLDER(N); INTEGER N;
|
||||
BEGIN
|
||||
REAL ARRAY DATA(1:N);
|
||||
END;
|
||||
|
||||
REF(ARRAYHOLDER) PROCEDURE CONCAT(A, B); REF(ARRAYHOLDER) A, B;
|
||||
BEGIN
|
||||
REF(ARRAYHOLDER) C;
|
||||
INTEGER I, J;
|
||||
|
||||
C :- NEW ARRAYHOLDER(A.N + B.N);
|
||||
|
||||
FOR I := 1 STEP 1 UNTIL A.N DO
|
||||
BEGIN
|
||||
J := J+1; C.DATA(J) := A.DATA(I);
|
||||
END;
|
||||
|
||||
FOR I := 1 STEP 1 UNTIL B.N DO
|
||||
BEGIN
|
||||
J := J+1; C.DATA(J) := B.DATA(I);
|
||||
END;
|
||||
|
||||
CONCAT :- C;
|
||||
END;
|
||||
|
||||
REF(ARRAYHOLDER) X, Y, Z;
|
||||
INTEGER I;
|
||||
|
||||
X :- NEW ARRAYHOLDER(3);
|
||||
Y :- NEW ARRAYHOLDER(4);
|
||||
|
||||
I := 0;
|
||||
I := I+1; X.DATA(I) := 2*I;
|
||||
I := I+1; X.DATA(I) := 2*I;
|
||||
I := I+1; X.DATA(I) := 2*I;
|
||||
|
||||
I := 0;
|
||||
I := I+1; Y.DATA(I) := -3*I;
|
||||
I := I+1; Y.DATA(I) := -3*I;
|
||||
I := I+1; Y.DATA(I) := -3*I;
|
||||
I := I+1; Y.DATA(I) := -3*I;
|
||||
|
||||
Z :- CONCAT(X, Y);
|
||||
FOR I := 1 STEP 1 UNTIL Z.N DO
|
||||
OUTFIX(Z.DATA(I), 2, 7);
|
||||
OUTIMAGE;
|
||||
|
||||
END.
|
||||
38
Task/Array-concatenation/Stata/array-concatenation-1.stata
Normal file
38
Task/Array-concatenation/Stata/array-concatenation-1.stata
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
. matrix a=2,9,4\7,5,3\6,1,8
|
||||
. matrix list a
|
||||
|
||||
a[3,3]
|
||||
c1 c2 c3
|
||||
r1 2 9 4
|
||||
r2 7 5 3
|
||||
r3 6 1 8
|
||||
|
||||
. matrix b=I(3)
|
||||
. matrix list b
|
||||
|
||||
symmetric b[3,3]
|
||||
c1 c2 c3
|
||||
r1 1
|
||||
r2 0 1
|
||||
r3 0 0 1
|
||||
|
||||
. matrix c=a,b
|
||||
. matrix list c
|
||||
|
||||
c[3,6]
|
||||
c1 c2 c3 c1 c2 c3
|
||||
r1 2 9 4 1 0 0
|
||||
r2 7 5 3 0 1 0
|
||||
r3 6 1 8 0 0 1
|
||||
|
||||
. matrix c=a\b
|
||||
. matrix list c
|
||||
|
||||
c[6,3]
|
||||
c1 c2 c3
|
||||
r1 2 9 4
|
||||
r2 7 5 3
|
||||
r3 6 1 8
|
||||
r1 1 0 0
|
||||
r2 0 1 0
|
||||
r3 0 0 1
|
||||
25
Task/Array-concatenation/Stata/array-concatenation-2.stata
Normal file
25
Task/Array-concatenation/Stata/array-concatenation-2.stata
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
. mata
|
||||
: a=2,9,4\7,5,3\6,1,8
|
||||
|
||||
: b=I(3)
|
||||
|
||||
: a,b
|
||||
1 2 3 4 5 6
|
||||
+-------------------------+
|
||||
1 | 2 9 4 1 0 0 |
|
||||
2 | 7 5 3 0 1 0 |
|
||||
3 | 6 1 8 0 0 1 |
|
||||
+-------------------------+
|
||||
|
||||
: a\b
|
||||
1 2 3
|
||||
+-------------+
|
||||
1 | 2 9 4 |
|
||||
2 | 7 5 3 |
|
||||
3 | 6 1 8 |
|
||||
4 | 1 0 0 |
|
||||
5 | 0 1 0 |
|
||||
6 | 0 0 1 |
|
||||
+-------------+
|
||||
|
||||
: end
|
||||
2
Task/Array-concatenation/Zkl/array-concatenation.zkl
Normal file
2
Task/Array-concatenation/Zkl/array-concatenation.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
T(1,2).extend(T(4,5,6)) //-->L(1,2,4,5,6)
|
||||
T(1,2).extend(4,5,6) //-->L(1,2,4,5,6)
|
||||
Loading…
Add table
Add a link
Reference in a new issue