Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Array-concatenation/00-META.yaml
Normal file
5
Task/Array-concatenation/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
from: http://rosettacode.org/wiki/Array_concatenation
|
||||
note: Data Structures
|
||||
7
Task/Array-concatenation/00-TASK.txt
Normal file
7
Task/Array-concatenation/00-TASK.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
;Task:
|
||||
Show how to concatenate two arrays in your language.
|
||||
|
||||
|
||||
If this is as simple as <code><var>array1</var> + <var>array2</var></code>, so be it.
|
||||
<br><br>
|
||||
|
||||
3
Task/Array-concatenation/11l/array-concatenation.11l
Normal file
3
Task/Array-concatenation/11l/array-concatenation.11l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
V arr1 = [1, 2, 3]
|
||||
V arr2 = [4, 5, 6]
|
||||
print(arr1 [+] arr2)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
ArrayRam equ $00FF2000 ;this label points to 4k of free space.
|
||||
|
||||
;concatenate Array1 + Array2
|
||||
LEA ArrayRam,A0
|
||||
LEA Array1,A1
|
||||
MOVE.W #5-1,D1 ;LEN(Array1), measured in words.
|
||||
JSR memcpy_w
|
||||
;after this, A0 will point to the destination of the second array.
|
||||
|
||||
LEA Array2,A1 ;even though the source arrays are stored back-to-back in memory, we'll assume they're not just for demonstration purposes.
|
||||
MOVE.W #5-1,D1 ;LEN(Array2), measured in words
|
||||
JSR memcpy_w
|
||||
|
||||
JMP * ;halt the CPU
|
||||
memcpy_w:
|
||||
MOVE.W (A1)+,(A0)+
|
||||
DBRA D1,memcpy_w
|
||||
rts
|
||||
|
||||
Array1:
|
||||
DC.W 1,2,3,4,5
|
||||
Array2:
|
||||
DC.W 6,7,8,9,10
|
||||
1
Task/Array-concatenation/8th/array-concatenation.8th
Normal file
1
Task/Array-concatenation/8th/array-concatenation.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1,2,3] [4,5,6] a:+ .
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program concAreaString.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
.equ NBMAXITEMS, 20 //
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessLenArea: .asciz "The length of area 3 is : @ \n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
|
||||
/* areas strings */
|
||||
szString1: .asciz "Apples"
|
||||
szString2: .asciz "Oranges"
|
||||
szString3: .asciz "Pommes"
|
||||
szString4: .asciz "Raisins"
|
||||
szString5: .asciz "Abricots"
|
||||
|
||||
/* pointer items area 1*/
|
||||
tablesPoi1:
|
||||
pt1_1: .quad szString1
|
||||
pt1_2: .quad szString2
|
||||
ptVoid_1: .quad 0
|
||||
|
||||
/* pointer items area 2*/
|
||||
tablesPoi2:
|
||||
pt2_1: .quad szString3
|
||||
pt2_2: .quad szString4
|
||||
pt2_3: .quad szString5
|
||||
ptVoid_2: .quad 0
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
tablesPoi3: .skip 8 * NBMAXITEMS
|
||||
sZoneConv: .skip 30
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
|
||||
// copy area 1 -> area 3
|
||||
ldr x1,qAdrtablesPoi1 // begin pointer area 1
|
||||
ldr x3,qAdrtablesPoi3 // begin pointer area 3
|
||||
mov x0,0 // counter
|
||||
1:
|
||||
ldr x2,[x1,x0,lsl 3] // read string pointer address item x0 (8 bytes by pointer)
|
||||
cbz x2,2f // is null ?
|
||||
str x2,[x3,x0,lsl 3] // no store pointer in area 3
|
||||
add x0,x0,1 // increment counter
|
||||
b 1b // and loop
|
||||
2: // copy area 2 -> area 3
|
||||
ldr x1,qAdrtablesPoi2 // begin pointer area 2
|
||||
ldr x3,qAdrtablesPoi3 // begin pointer area 3
|
||||
mov x4,#0 // counter area 2
|
||||
3: // x0 contains the first void item in area 3
|
||||
ldr x2,[x1,x4,lsl #3] // read string pointer address item x0 (8 bytes by pointer)
|
||||
cbz x2,4f // is null ?
|
||||
str x2,[x3,x0,lsl #3] // no store pointer in area 3
|
||||
add x0,x0,1 // increment counter
|
||||
add x4,x4,1 // increment counter
|
||||
b 3b // and loop
|
||||
4:
|
||||
// count items number in area 3
|
||||
ldr x1,qAdrtablesPoi3 // begin pointer table
|
||||
mov x0,#0 // counter
|
||||
5: // begin loop
|
||||
ldr x2,[x1,x0,lsl #3] // read string pointer address item x0 (8 bytes by pointer)
|
||||
cmp x2,#0 // is null ?
|
||||
cinc x0,x0,ne // no increment counter
|
||||
bne 5b // and loop
|
||||
|
||||
ldr x1,qAdrsZoneConv // conversion decimal
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessLenArea
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
|
||||
100: // standard end of the program
|
||||
mov x0,0 // return code
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
qAdrtablesPoi1: .quad tablesPoi1
|
||||
qAdrtablesPoi2: .quad tablesPoi2
|
||||
qAdrtablesPoi3: .quad tablesPoi3
|
||||
qAdrszMessLenArea: .quad szMessLenArea
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
/****************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
10
Task/Array-concatenation/ABAP/array-concatenation.abap
Normal file
10
Task/Array-concatenation/ABAP/array-concatenation.abap
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
report z_array_concatenation.
|
||||
|
||||
data(itab1) = value int4_table( ( 1 ) ( 2 ) ( 3 ) ).
|
||||
data(itab2) = value int4_table( ( 4 ) ( 5 ) ( 6 ) ).
|
||||
|
||||
append lines of itab2 to itab1.
|
||||
|
||||
loop at itab1 assigning field-symbol(<line>).
|
||||
write <line>.
|
||||
endloop.
|
||||
1
Task/Array-concatenation/ACL2/array-concatenation.acl2
Normal file
1
Task/Array-concatenation/ACL2/array-concatenation.acl2
Normal file
|
|
@ -0,0 +1 @@
|
|||
(append xs ys)
|
||||
30
Task/Array-concatenation/ALGOL-68/array-concatenation.alg
Normal file
30
Task/Array-concatenation/ALGOL-68/array-concatenation.alg
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
MODE ARGTYPE = INT;
|
||||
MODE ARGLIST = FLEX[0]ARGTYPE;
|
||||
|
||||
OP + = (ARGLIST a, b)ARGLIST: (
|
||||
[LWB a:UPB a - LWB a + 1 + UPB b - LWB b + 1 ]ARGTYPE out;
|
||||
(
|
||||
out[LWB a:UPB a]:=a,
|
||||
out[UPB a+1:]:=b
|
||||
);
|
||||
out
|
||||
);
|
||||
|
||||
# Append #
|
||||
OP +:= = (REF ARGLIST lhs, ARGLIST rhs)ARGLIST: lhs := lhs + rhs;
|
||||
OP PLUSAB = (REF ARGLIST lhs, ARGLIST rhs)ARGLIST: lhs := lhs + rhs;
|
||||
|
||||
# Prefix #
|
||||
OP +=: = (ARGLIST lhs, REF ARGLIST rhs)ARGLIST: rhs := lhs + rhs;
|
||||
OP PLUSTO = (ARGLIST lhs, REF ARGLIST rhs)ARGLIST: rhs := lhs + rhs;
|
||||
|
||||
ARGLIST a := (1,2),
|
||||
b := (3,4,5);
|
||||
|
||||
print(("a + b",a + b, new line));
|
||||
|
||||
VOID(a +:= b);
|
||||
print(("a +:= b", a, new line));
|
||||
|
||||
VOID(a +=: b);
|
||||
print(("a +=: b", b, new line))
|
||||
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.
|
||||
3
Task/Array-concatenation/ANT/array-concatenation.ant
Normal file
3
Task/Array-concatenation/ANT/array-concatenation.ant
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
a:<1; <2; 3>>
|
||||
b: <"Hello"; 42>
|
||||
c: a,b
|
||||
2
Task/Array-concatenation/APL/array-concatenation.apl
Normal file
2
Task/Array-concatenation/APL/array-concatenation.apl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1 2 3 , 4 5 6
|
||||
1 2 3 4 5 6
|
||||
170
Task/Array-concatenation/ARM-Assembly/array-concatenation.arm
Normal file
170
Task/Array-concatenation/ARM-Assembly/array-concatenation.arm
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program concAreaString.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
.equ NBMAXITEMS, 20 @
|
||||
/* Initialized data */
|
||||
.data
|
||||
szMessLenArea: .ascii "The length of area 3 is : "
|
||||
sZoneconv: .fill 12,1,' '
|
||||
szCarriageReturn: .asciz "\n"
|
||||
|
||||
/* areas strings */
|
||||
szString1: .asciz "Apples"
|
||||
szString2: .asciz "Oranges"
|
||||
szString3: .asciz "Pommes"
|
||||
szString4: .asciz "Raisins"
|
||||
szString5: .asciz "Abricots"
|
||||
|
||||
/* pointer items area 1*/
|
||||
tablesPoi1:
|
||||
pt1_1: .int szString1
|
||||
pt1_2: .int szString2
|
||||
ptVoid_1: .int 0
|
||||
|
||||
/* pointer items area 2*/
|
||||
tablesPoi2:
|
||||
pt2_1: .int szString3
|
||||
pt2_2: .int szString4
|
||||
pt2_3: .int szString5
|
||||
ptVoid_2: .int 0
|
||||
|
||||
/* UnInitialized data */
|
||||
.bss
|
||||
tablesPoi3: .skip 4 * NBMAXITEMS
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: /* entry of program */
|
||||
push {fp,lr} /* saves 2 registers */
|
||||
|
||||
@ copy area 1 -> area 3
|
||||
ldr r1,iAdrtablesPoi1 @ begin pointer area 1
|
||||
ldr r3,iAdrtablesPoi3 @ begin pointer area 3
|
||||
mov r0,#0 @ counter
|
||||
1:
|
||||
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
|
||||
cmp r2,#0 @ is null ?
|
||||
strne r2,[r3,r0,lsl #2] @ no store pointer in area 3
|
||||
addne r0,#1 @ increment counter
|
||||
bne 1b @ and loop
|
||||
@ copy area 2 -> area 3
|
||||
ldr r1,iAdrtablesPoi2 @ begin pointer area 2
|
||||
ldr r3,iAdrtablesPoi3 @ begin pointer area 3
|
||||
mov r4,#0 @ counter area 2
|
||||
2: @ r0 contains the first void item in area 3
|
||||
ldr r2,[r1,r4,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
|
||||
cmp r2,#0 @ is null ?
|
||||
strne r2,[r3,r0,lsl #2] @ no store pointer in area 3
|
||||
addne r0,#1 @ increment counter
|
||||
addne r4,#1 @ increment counter
|
||||
bne 2b @ and loop
|
||||
|
||||
@ count items number in area 3
|
||||
ldr r1,iAdrtablesPoi3 @ begin pointer table
|
||||
mov r0,#0 @ counter
|
||||
3: @ begin loop
|
||||
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
|
||||
cmp r2,#0 @ is null ?
|
||||
addne r0,#1 @ no increment counter
|
||||
bne 3b @ and loop
|
||||
|
||||
ldr r1,iAdrsZoneconv @ conversion decimal
|
||||
bl conversion10S
|
||||
ldr r0,iAdrszMessLenArea
|
||||
bl affichageMess
|
||||
|
||||
100: /* standard end of the program */
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrtablesPoi1: .int tablesPoi1
|
||||
iAdrtablesPoi2: .int tablesPoi2
|
||||
iAdrtablesPoi3: .int tablesPoi3
|
||||
iAdrszMessLenArea: .int szMessLenArea
|
||||
iAdrsZoneconv: .int sZoneconv
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {fp,lr} /* save registres */
|
||||
push {r0,r1,r2,r7} /* save others registers */
|
||||
mov r2,#0 /* counter length */
|
||||
1: /* loop length calculation */
|
||||
ldrb r1,[r0,r2] /* read octet start position + index */
|
||||
cmp r1,#0 /* if 0 its over */
|
||||
addne r2,r2,#1 /* else add 1 in the length */
|
||||
bne 1b /* and loop */
|
||||
/* so here r2 contains the length of the message */
|
||||
mov r1,r0 /* address message in r1 */
|
||||
mov r0,#STDOUT /* code to write to the standard output Linux */
|
||||
mov r7, #WRITE /* code call system "write" */
|
||||
swi #0 /* call systeme */
|
||||
pop {r0,r1,r2,r7} /* restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registres */
|
||||
bx lr /* return */
|
||||
|
||||
/***************************************************/
|
||||
/* conversion register signed décimal */
|
||||
/***************************************************/
|
||||
/* r0 contient le registre */
|
||||
/* r1 contient l adresse de la zone de conversion */
|
||||
conversion10S:
|
||||
push {r0-r5,lr} /* save des registres */
|
||||
mov r2,r1 /* debut zone stockage */
|
||||
mov r5,#'+' /* par defaut le signe est + */
|
||||
cmp r0,#0 /* nombre négatif ? */
|
||||
movlt r5,#'-' /* oui le signe est - */
|
||||
mvnlt r0,r0 /* et inversion en valeur positive */
|
||||
addlt r0,#1
|
||||
mov r4,#10 /* longueur de la zone */
|
||||
1: /* debut de boucle de conversion */
|
||||
bl divisionpar10 /* division */
|
||||
add r1,#48 /* ajout de 48 au reste pour conversion ascii */
|
||||
strb r1,[r2,r4] /* stockage du byte en début de zone r5 + la position r4 */
|
||||
sub r4,r4,#1 /* position précedente */
|
||||
cmp r0,#0
|
||||
bne 1b /* boucle si quotient different de zéro */
|
||||
strb r5,[r2,r4] /* stockage du signe à la position courante */
|
||||
subs r4,r4,#1 /* position précedente */
|
||||
blt 100f /* si r4 < 0 fin */
|
||||
/* sinon il faut completer le debut de la zone avec des blancs */
|
||||
mov r3,#' ' /* caractere espace */
|
||||
2:
|
||||
strb r3,[r2,r4] /* stockage du byte */
|
||||
subs r4,r4,#1 /* position précedente */
|
||||
bge 2b /* boucle si r4 plus grand ou egal a zero */
|
||||
100: /* fin standard de la fonction */
|
||||
pop {r0-r5,lr} /*restaur desregistres */
|
||||
bx lr
|
||||
|
||||
/***************************************************/
|
||||
/* division par 10 signé */
|
||||
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
|
||||
/* and http://www.hackersdelight.org/ */
|
||||
/***************************************************/
|
||||
/* r0 contient le dividende */
|
||||
/* r0 retourne le quotient */
|
||||
/* r1 retourne le reste */
|
||||
divisionpar10:
|
||||
/* r0 contains the argument to be divided by 10 */
|
||||
push {r2-r4} /* save registers */
|
||||
mov r4,r0
|
||||
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
|
||||
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
|
||||
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
|
||||
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
|
||||
add r0, r2, r1 /* r0 <- r2 + r1 */
|
||||
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
|
||||
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
|
||||
pop {r2-r4}
|
||||
bx lr /* leave function */
|
||||
bx lr /* leave function */
|
||||
.Ls_magic_number_10: .word 0x66666667
|
||||
122
Task/Array-concatenation/ATS/array-concatenation.ats
Normal file
122
Task/Array-concatenation/ATS/array-concatenation.ats
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
(* The Rosetta Code array concatenation task, in ATS2. *)
|
||||
|
||||
(* In a way, the task is misleading: in a language such as ATS, one
|
||||
can always devise a very-easy-to-use array type, put the code for
|
||||
that in a library, and overload operators. Thus we can have
|
||||
"array1 + array2" as array concatenation in ATS, complete with
|
||||
garbage collection when the result no longer is needed.
|
||||
|
||||
It depends on what libraries are in one's repertoire.
|
||||
|
||||
Nevertheless, it seems fair to demonstrate how to concatenate two
|
||||
barebones arrays at the nitpicking lowest level, without anything
|
||||
but the barest contents of the ATS2 prelude. It will make ATS
|
||||
programming look difficult; but ATS programming *is* difficult,
|
||||
when you are using it to overcome the programming safety
|
||||
deficiencies of a language such as C, without losing the runtime
|
||||
efficiency of C code.
|
||||
|
||||
What we want is the kind of routine that would be used *in the
|
||||
implementation* of "array1 + array2". So let us begin ... *)
|
||||
|
||||
#include "share/atspre_staload.hats" (* Loads some needed template
|
||||
code. *)
|
||||
|
||||
fn {t : t@ype}
|
||||
|
||||
(* The demonstration will be for arrays of a non-linear type t. Were
|
||||
the arrays to contain a *linear* type (vt@ype), then either the old
|
||||
arrays would have to be destroyed or a copy procedure would be
|
||||
needed for the elements. *)
|
||||
|
||||
arrayconcat1 {m, n : nat}
|
||||
{pa, pb, pc : addr}
|
||||
(pfa : !(@[t][m]) @ pa,
|
||||
pfb : !(@[t][n]) @ pb,
|
||||
pfc : !(@[t?][m + n]) @ pc >> @[t][m + n] @ pc |
|
||||
pa : ptr pa,
|
||||
pb : ptr pb,
|
||||
pc : ptr pc,
|
||||
m : size_t m,
|
||||
n : size_t n) : void =
|
||||
|
||||
(* The routine takes as arguments three low-level arrays, passed by
|
||||
value, as pointers with associated views. The first array is of
|
||||
length m, with elements of type t, and the array must have been
|
||||
initialized; the second is a similar array of length n. The third
|
||||
array is uninitialized (thus the "?" character) and must have
|
||||
length m+n; its type will change to "initialized". *)
|
||||
|
||||
{
|
||||
prval (pfleft, pfright) = array_v_split {t?} {pc} {m + n} {m} pfc
|
||||
|
||||
(* We have had to split the view of array c into a left part pfleft,
|
||||
of length m, and a right part pfright of length n. Arrays a and b
|
||||
will be copied into the respective parts of c. *)
|
||||
|
||||
val _ = array_copy<t> (!pc, !pa, m)
|
||||
val _ = array_copy<t> (!(ptr_add<t> (pc, m)), !pb, n)
|
||||
|
||||
(* Copying an array *safely* is more complex than what we are doing
|
||||
here, but above the task has been given to the "array_copy"
|
||||
template in the prelude. The "!" signs appear because array_copy is
|
||||
call-by-reference but we are passing it pointers. *)
|
||||
|
||||
(* pfleft and pfright now refer to *initialized* arrays: one of length
|
||||
m, starting at address pc; the other of length n, starting at
|
||||
address pc+(m*sizeof<t>). *)
|
||||
|
||||
prval _ = pfc := array_v_unsplit {t} {pc} {m, n} (pfleft, pfright)
|
||||
|
||||
(* Before we can exit, the view of array c has to be replaced. It is
|
||||
replaced by "unsplitting" the (now initialized) left and right
|
||||
parts of the array. *)
|
||||
|
||||
(* We are done. Everything should now work, and the result will be
|
||||
safe from buffer overruns or underruns, and against accidental
|
||||
misuse of uninitialized data. *)
|
||||
|
||||
}
|
||||
|
||||
(* arrayconcat2 is a pass-by-reference interface to arrayconcat1. *)
|
||||
fn {t : t@ype}
|
||||
arrayconcat2 {m, n : nat}
|
||||
(a : &(@[t][m]),
|
||||
b : &(@[t][n]),
|
||||
c : &(@[t?][m + n]) >> @[t][m + n],
|
||||
m : size_t m,
|
||||
n : size_t n) : void =
|
||||
arrayconcat1 (view@ a, view@ b, view@ c |
|
||||
addr@ a, addr@ b, addr@ c, m, n)
|
||||
|
||||
(* Overloads to let you say "arrayconcat" for either routine above. *)
|
||||
overload arrayconcat with arrayconcat1
|
||||
overload arrayconcat with arrayconcat2
|
||||
|
||||
implement
|
||||
main0 () =
|
||||
|
||||
(* A demonstration program. *)
|
||||
|
||||
let
|
||||
(* Some arrays on the stack. Because they are on the stack, they
|
||||
will not need explicit freeing. *)
|
||||
var a = @[int][3] (1, 2, 3)
|
||||
var b = @[int][4] (5, 6, 7, 8)
|
||||
var c : @[int?][7]
|
||||
|
||||
in
|
||||
|
||||
(* Compute c as the concatenation of a and b. *)
|
||||
arrayconcat<int> (a, b, c, i2sz 3, i2sz 4);
|
||||
|
||||
(* The following simply prints the result. *)
|
||||
let
|
||||
(* Copy c to a linear linked list, because the prelude provides
|
||||
means to easily print such a list. *)
|
||||
val lst = array2list (c, i2sz 7)
|
||||
in
|
||||
println! (lst); (* Print the list. *)
|
||||
free lst (* The list is linear and must be freed. *)
|
||||
end
|
||||
end
|
||||
19
Task/Array-concatenation/AWK/array-concatenation.awk
Normal file
19
Task/Array-concatenation/AWK/array-concatenation.awk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/awk -f
|
||||
BEGIN {
|
||||
split("cul-de-sac",a,"-")
|
||||
split("1-2-3",b,"-")
|
||||
concat_array(a,b,c)
|
||||
|
||||
for (i in c) {
|
||||
print i,c[i]
|
||||
}
|
||||
}
|
||||
|
||||
function concat_array(a,b,c, nc) {
|
||||
for (i in a) {
|
||||
c[++nc]=a[i]
|
||||
}
|
||||
for (i in b) {
|
||||
c[++nc]=b[i]
|
||||
}
|
||||
}
|
||||
51
Task/Array-concatenation/Action-/array-concatenation.action
Normal file
51
Task/Array-concatenation/Action-/array-concatenation.action
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
BYTE FUNC Concat(INT ARRAY src1,src2,dst BYTE size1,size2)
|
||||
BYTE i
|
||||
|
||||
FOR i=0 TO size1-1
|
||||
DO
|
||||
dst(i)=src1(i)
|
||||
OD
|
||||
FOR i=0 TO size2-1
|
||||
DO
|
||||
dst(size1+i)=src2(i)
|
||||
OD
|
||||
RETURN (size1+size2)
|
||||
|
||||
PROC PrintArray(INT ARRAY a BYTE size)
|
||||
BYTE i
|
||||
|
||||
Put('[)
|
||||
FOR i=0 TO size-1
|
||||
DO
|
||||
PrintI(a(i))
|
||||
IF i<size-1 THEN
|
||||
Put(' )
|
||||
FI
|
||||
OD
|
||||
Put('])
|
||||
RETURN
|
||||
|
||||
PROC Test(INT ARRAY src1,src2 BYTE size1,size2)
|
||||
INT ARRAY res(20)
|
||||
BYTE size
|
||||
|
||||
size=Concat(src1,src2,res,size1,size2)
|
||||
PrintArray(src1,size1)
|
||||
Put('+)
|
||||
PrintArray(src2,size2)
|
||||
Put('=)
|
||||
PrintArray(res,size)
|
||||
PutE() PutE()
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
INT ARRAY
|
||||
a1=[1 2 3 4],
|
||||
a2=[5 6 7 8 9 10],
|
||||
;a workaround for a3=[-1 -2 -3 -4 -5]
|
||||
a3=[65535 65534 65533 65532 65531]
|
||||
|
||||
Test(a1,a2,4,6)
|
||||
Test(a2,a1,6,4)
|
||||
Test(a3,a2,5,4)
|
||||
RETURN
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var array1:Array = new Array(1, 2, 3);
|
||||
var array2:Array = new Array(4, 5, 6);
|
||||
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6]
|
||||
3
Task/Array-concatenation/Ada/array-concatenation.ada
Normal file
3
Task/Array-concatenation/Ada/array-concatenation.ada
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type T is array (Positive range <>) of Integer;
|
||||
X : T := (1, 2, 3);
|
||||
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6)
|
||||
23
Task/Array-concatenation/Aime/array-concatenation.aime
Normal file
23
Task/Array-concatenation/Aime/array-concatenation.aime
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
ac(list a, b)
|
||||
{
|
||||
list o;
|
||||
|
||||
o.copy(a);
|
||||
b.ucall(l_append, 1, o);
|
||||
|
||||
o;
|
||||
}
|
||||
|
||||
main(void)
|
||||
{
|
||||
list a, b, c;
|
||||
|
||||
a = list(1, 2, 3, 4);
|
||||
b = list(5, 6, 7, 8);
|
||||
|
||||
c = ac(a, b);
|
||||
|
||||
c.ucall(o_, 1, " ");
|
||||
|
||||
0;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#include <hbasic.h>
|
||||
Begin
|
||||
a1 = {}
|
||||
a2 = {}
|
||||
Take(100,"Hola",0.056,"Mundo!"), and Push All(a1)
|
||||
Take("Segundo",0,"array",~True,~False), and Push All(a2)
|
||||
Concat (a1, a2) and Print ( a2, Newl )
|
||||
End
|
||||
4
Task/Array-concatenation/Apex/array-concatenation.apex
Normal file
4
Task/Array-concatenation/Apex/array-concatenation.apex
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
List<String> listA = new List<String> { 'apple' };
|
||||
List<String> listB = new List<String> { 'banana' };
|
||||
listA.addAll(listB);
|
||||
System.debug(listA); // Prints (apple, banana)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
set listA to {1, 2, 3}
|
||||
set listB to {4, 5, 6}
|
||||
return listA & listB
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
on run
|
||||
|
||||
concat([["alpha", "beta", "gamma"], ¬
|
||||
["delta", "epsilon", "zeta"], ¬
|
||||
["eta", "theta", "iota"]])
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-- concat :: [[a]] -> [a]
|
||||
on concat(xxs)
|
||||
set lst to {}
|
||||
repeat with xs in xxs
|
||||
set lst to lst & xs
|
||||
end repeat
|
||||
return lst
|
||||
end concat
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
10 LET X = 4:Y = 5
|
||||
20 DIM A(X - 1),B(Y - 1),C(X + Y - 1)
|
||||
30 FOR I = 1 TO X:A(I - 1) = I: NEXT
|
||||
40 FOR I = 1 TO Y:B(I - 1) = I * 10: NEXT
|
||||
50 FOR I = 1 TO X:C(I - 1) = A(I - 1): NEXT
|
||||
60 FOR I = 1 TO Y:C(X + I - 1) = B(I - 1): NEXT
|
||||
70 FOR I = 1 TO X + Y: PRINT MID$ (" ",1,I > 1)C(I - 1);: NEXT
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
arr1: [1 2 3]
|
||||
arr2: ["four" "five" "six"]
|
||||
|
||||
print arr1 ++ arr2
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
List1 := [1, 2, 3]
|
||||
List2 := [4, 5, 6]
|
||||
cList := Arr_concatenate(List1, List2)
|
||||
MsgBox % Arr_disp(cList) ; [1, 2, 3, 4, 5, 6]
|
||||
|
||||
Arr_concatenate(p*) {
|
||||
res := Object()
|
||||
For each, obj in p
|
||||
For each, value in obj
|
||||
res.Insert(value)
|
||||
return res
|
||||
}
|
||||
|
||||
Arr_disp(arr) {
|
||||
for each, value in arr
|
||||
res .= ", " value
|
||||
return "[" SubStr(res, 3) "]"
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
List1 = 1,2,3
|
||||
List2 = 4,5,6
|
||||
|
||||
List2Array(List1 , "Array1_")
|
||||
List2Array(List2 , "Array2_")
|
||||
|
||||
ConcatArrays("Array1_", "Array2_", "MyArray")
|
||||
MsgBox, % Array2List("MyArray")
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
ConcatArrays(A1, A2, A3) { ; concatenates the arrays A1 and A2 to A3
|
||||
;---------------------------------------------------------------------------
|
||||
local i := 0
|
||||
%A3%0 := %A1%0 + %A2%0
|
||||
Loop, % %A1%0
|
||||
i++, %A3%%i% := %A1%%A_Index%
|
||||
Loop, % %A2%0
|
||||
i++, %A3%%i% := %A2%%A_Index%
|
||||
}
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
List2Array(List, Array) { ; creates an array from a comma separated list
|
||||
;---------------------------------------------------------------------------
|
||||
global
|
||||
StringSplit, %Array%, List, `,
|
||||
}
|
||||
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
Array2List(Array) { ; returns a comma separated list from an array
|
||||
;---------------------------------------------------------------------------
|
||||
Loop, % %Array%0
|
||||
List .= (A_Index = 1 ? "" : ",") %Array%%A_Index%
|
||||
Return, List
|
||||
}
|
||||
18
Task/Array-concatenation/AutoIt/array-concatenation.autoit
Normal file
18
Task/Array-concatenation/AutoIt/array-concatenation.autoit
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
_ArrayConcatenate($avArray, $avArray2)
|
||||
Func _ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource, $iStart = 0)
|
||||
If Not IsArray($avArrayTarget) Then Return SetError(1, 0, 0)
|
||||
If Not IsArray($avArraySource) Then Return SetError(2, 0, 0)
|
||||
If UBound($avArrayTarget, 0) <> 1 Then
|
||||
If UBound($avArraySource, 0) <> 1 Then Return SetError(5, 0, 0)
|
||||
Return SetError(3, 0, 0)
|
||||
EndIf
|
||||
If UBound($avArraySource, 0) <> 1 Then Return SetError(4, 0, 0)
|
||||
|
||||
Local $iUBoundTarget = UBound($avArrayTarget) - $iStart, $iUBoundSource = UBound($avArraySource)
|
||||
ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
|
||||
For $i = $iStart To $iUBoundSource - 1
|
||||
$avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]
|
||||
Next
|
||||
|
||||
Return $iUBoundTarget + $iUBoundSource
|
||||
EndFunc ;==>_ArrayConcatenate
|
||||
1
Task/Array-concatenation/Avail/array-concatenation.avail
Normal file
1
Task/Array-concatenation/Avail/array-concatenation.avail
Normal file
|
|
@ -0,0 +1 @@
|
|||
<1, 2, 3> ++ <¢a, ¢b, ¢c>
|
||||
36
Task/Array-concatenation/BASIC256/array-concatenation.basic
Normal file
36
Task/Array-concatenation/BASIC256/array-concatenation.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
arraybase 1
|
||||
global c
|
||||
|
||||
dimen = 5
|
||||
dim a(dimen)
|
||||
dim b(dimen)
|
||||
# Array initialization
|
||||
for i = 1 to dimen
|
||||
a[i] = i
|
||||
b[i] = i + dimen
|
||||
next i
|
||||
|
||||
nt = ConcatArrays(a, b)
|
||||
|
||||
for i = 1 to nt
|
||||
print c[i];
|
||||
if i < nt then print ", ";
|
||||
next i
|
||||
end
|
||||
|
||||
function ConcatArrays(a, b)
|
||||
ta = a[?]
|
||||
tb = b[?]
|
||||
|
||||
nt = ta + tb
|
||||
redim c(nt)
|
||||
|
||||
for i = 1 to ta
|
||||
c[i] = a[i]
|
||||
next i
|
||||
for i = 1 to tb
|
||||
c[i + ta] = b[i]
|
||||
next i
|
||||
|
||||
return nt
|
||||
end function
|
||||
19
Task/Array-concatenation/BBC-BASIC/array-concatenation.basic
Normal file
19
Task/Array-concatenation/BBC-BASIC/array-concatenation.basic
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
DIM a(3), b(4)
|
||||
a() = 1, 2, 3, 4
|
||||
b() = 5, 6, 7, 8, 9
|
||||
PROCconcat(a(), b(), c())
|
||||
|
||||
FOR i% = 0 TO DIM(c(),1)
|
||||
PRINT c(i%)
|
||||
NEXT
|
||||
END
|
||||
|
||||
DEF PROCconcat(a(), b(), RETURN c())
|
||||
LOCAL s%, na%, nb%
|
||||
s% = ^a(1) - ^a(0) : REM Size of each array element
|
||||
na% = DIM(a(),1)+1 : REM Number of elements in a()
|
||||
nb% = DIM(b(),1)+1 : REM Number of elements in b()
|
||||
DIM c(na%+nb%-1)
|
||||
SYS "RtlMoveMemory", ^c(0), ^a(0), s%*na%
|
||||
SYS "RtlMoveMemory", ^c(na%), ^b(0), s%*nb%
|
||||
ENDPROC
|
||||
1
Task/Array-concatenation/BQN/array-concatenation.bqn
Normal file
1
Task/Array-concatenation/BQN/array-concatenation.bqn
Normal file
|
|
@ -0,0 +1 @@
|
|||
1‿2‿3 ∾ 4‿5‿6
|
||||
9
Task/Array-concatenation/BaCon/array-concatenation.bacon
Normal file
9
Task/Array-concatenation/BaCon/array-concatenation.bacon
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
DECLARE a[] = { 1, 2, 3, 4, 5 }
|
||||
DECLARE b[] = { 6, 7, 8, 9, 10 }
|
||||
|
||||
DECLARE c ARRAY UBOUND(a) + UBOUND(b)
|
||||
|
||||
FOR x = 0 TO 4
|
||||
c[x] = a[x]
|
||||
c[x+5] = b[x]
|
||||
NEXT
|
||||
1
Task/Array-concatenation/Babel/array-concatenation.pb
Normal file
1
Task/Array-concatenation/Babel/array-concatenation.pb
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1 2 3] [4 5 6] cat ;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
blsq ) {1 2 3}{4 5 6}_+
|
||||
{1 2 3 4 5 6}
|
||||
14
Task/Array-concatenation/C++/array-concatenation-1.cpp
Normal file
14
Task/Array-concatenation/C++/array-concatenation-1.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<int> a(3), b(4);
|
||||
a[0] = 11; a[1] = 12; a[2] = 13;
|
||||
b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;
|
||||
|
||||
a.insert(a.end(), b.begin(), b.end());
|
||||
|
||||
for (int i = 0; i < a.size(); ++i)
|
||||
std::cout << "a[" << i << "] = " << a[i] << "\n";
|
||||
}
|
||||
13
Task/Array-concatenation/C++/array-concatenation-2.cpp
Normal file
13
Task/Array-concatenation/C++/array-concatenation-2.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::vector<int> a {1, 2, 3, 4};
|
||||
std::vector<int> b {5, 6, 7, 8, 9};
|
||||
|
||||
a.insert(a.end(), b.begin(), b.end());
|
||||
|
||||
for(int& i: a) std::cout << i << " ";
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
22
Task/Array-concatenation/C-sharp/array-concatenation-1.cs
Normal file
22
Task/Array-concatenation/C-sharp/array-concatenation-1.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
|
||||
namespace RosettaCode
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = { 1, 2, 3 };
|
||||
int[] b = { 4, 5, 6 };
|
||||
|
||||
int[] c = new int[a.Length + b.Length];
|
||||
a.CopyTo(c, 0);
|
||||
b.CopyTo(c, a.Length);
|
||||
|
||||
foreach(int n in c)
|
||||
{
|
||||
Console.WriteLine(n.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Task/Array-concatenation/C-sharp/array-concatenation-2.cs
Normal file
12
Task/Array-concatenation/C-sharp/array-concatenation-2.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = { 1, 2, 3 };
|
||||
int[] b = { 4, 5, 6 };
|
||||
|
||||
int[] c = a.Concat(b).ToArray();
|
||||
}
|
||||
}
|
||||
32
Task/Array-concatenation/C/array-concatenation.c
Normal file
32
Task/Array-concatenation/C/array-concatenation.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
|
||||
(TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));
|
||||
|
||||
void *array_concat(const void *a, size_t an,
|
||||
const void *b, size_t bn, size_t s)
|
||||
{
|
||||
char *p = malloc(s * (an + bn));
|
||||
memcpy(p, a, an*s);
|
||||
memcpy(p + an*s, b, bn*s);
|
||||
return p;
|
||||
}
|
||||
|
||||
// testing
|
||||
const int a[] = { 1, 2, 3, 4, 5 };
|
||||
const int b[] = { 6, 7, 8, 9, 0 };
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
int *c = ARRAY_CONCAT(int, a, 5, b, 5);
|
||||
|
||||
for(i = 0; i < 10; i++)
|
||||
printf("%d\n", c[i]);
|
||||
|
||||
free(c);
|
||||
return EXIT_SUCCCESS;
|
||||
}
|
||||
57
Task/Array-concatenation/COBOL/array-concatenation.cobol
Normal file
57
Task/Array-concatenation/COBOL/array-concatenation.cobol
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
identification division.
|
||||
program-id. array-concat.
|
||||
|
||||
environment division.
|
||||
configuration section.
|
||||
repository.
|
||||
function all intrinsic.
|
||||
|
||||
data division.
|
||||
working-storage section.
|
||||
01 table-one.
|
||||
05 int-field pic 999 occurs 0 to 5 depending on t1.
|
||||
01 table-two.
|
||||
05 int-field pic 9(4) occurs 0 to 10 depending on t2.
|
||||
|
||||
77 t1 pic 99.
|
||||
77 t2 pic 99.
|
||||
|
||||
77 show pic z(4).
|
||||
|
||||
procedure division.
|
||||
array-concat-main.
|
||||
perform initialize-tables
|
||||
perform concatenate-tables
|
||||
perform display-result
|
||||
goback.
|
||||
|
||||
initialize-tables.
|
||||
move 4 to t1
|
||||
perform varying tally from 1 by 1 until tally > t1
|
||||
compute int-field of table-one(tally) = tally * 3
|
||||
end-perform
|
||||
|
||||
move 3 to t2
|
||||
perform varying tally from 1 by 1 until tally > t2
|
||||
compute int-field of table-two(tally) = tally * 6
|
||||
end-perform
|
||||
.
|
||||
|
||||
concatenate-tables.
|
||||
perform varying tally from 1 by 1 until tally > t1
|
||||
add 1 to t2
|
||||
move int-field of table-one(tally)
|
||||
to int-field of table-two(t2)
|
||||
end-perform
|
||||
.
|
||||
|
||||
display-result.
|
||||
perform varying tally from 1 by 1 until tally = t2
|
||||
move int-field of table-two(tally) to show
|
||||
display trim(show) ", " with no advancing
|
||||
end-perform
|
||||
move int-field of table-two(tally) to show
|
||||
display trim(show)
|
||||
.
|
||||
|
||||
end program array-concat.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
shared void arrayConcatenation() {
|
||||
value a = Array {1, 2, 3};
|
||||
value b = Array {4, 5, 6};
|
||||
value c = concatenate(a, b);
|
||||
print(c);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
(concat [1 2 3] [4 5 6])
|
||||
|
|
@ -0,0 +1 @@
|
|||
(into [1 2 3] [4 5 6])
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# like in JavaScript
|
||||
a = [1, 2, 3]
|
||||
b = [4, 5, 6]
|
||||
c = a.concat b
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(concatenate 'vector #(0 1 2 3) #(4 5 6 7))
|
||||
=> #(0 1 2 3 4 5 6 7)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(setf arr1 (make-array '(3) :initial-contents '(1 2 3)))
|
||||
(setf arr2 (make-array '(3) :initial-contents '(4 5 6)))
|
||||
(setf arr3 (make-array '(3) :initial-contents '(7 8 9)))
|
||||
(setf arr4 (make-array '(6)))
|
||||
(setf arr5 (make-array '(9)))
|
||||
(setf arr4 (concatenate `(vector ,(array-element-type arr1)) arr1 arr2))
|
||||
(format t "~a" "concatenate arr1 and arr2: ")
|
||||
(write arr4)
|
||||
(terpri)
|
||||
(setf arr5 (concatenate `(vector ,(array-element-type arr1)) arr4 arr3))
|
||||
(format t "~a" "concatenate arr4 and arr3: ")
|
||||
(write arr5)
|
||||
(terpri)
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
MODULE ArrayConcat;
|
||||
IMPORT StdLog;
|
||||
|
||||
PROCEDURE Concat(x: ARRAY OF INTEGER; y: ARRAY OF INTEGER; OUT z: ARRAY OF INTEGER);
|
||||
VAR
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
ASSERT(LEN(x) + LEN(y) <= LEN(z));
|
||||
FOR i := 0 TO LEN(x) - 1 DO z[i] := x[i] END;
|
||||
FOR i := 0 TO LEN(y) - 1 DO z[i + LEN(x)] := y[i] END
|
||||
END Concat;
|
||||
|
||||
PROCEDURE Concat2(x: ARRAY OF INTEGER;y: ARRAY OF INTEGER): POINTER TO ARRAY OF INTEGER;
|
||||
VAR
|
||||
z: POINTER TO ARRAY OF INTEGER;
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
NEW(z,LEN(x) + LEN(y));
|
||||
FOR i := 0 TO LEN(x) - 1 DO z[i] := x[i] END;
|
||||
FOR i := 0 TO LEN(y) - 1 DO z[i + LEN(x)] := y[i] END;
|
||||
RETURN z;
|
||||
END Concat2;
|
||||
|
||||
PROCEDURE ShowArray(x: ARRAY OF INTEGER);
|
||||
VAR
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
i := 0;
|
||||
StdLog.Char('[');
|
||||
WHILE (i < LEN(x)) DO
|
||||
StdLog.Int(x[i]);IF i < LEN(x) - 1 THEN StdLog.Char(',') END;
|
||||
INC(i)
|
||||
END;
|
||||
StdLog.Char(']');StdLog.Ln;
|
||||
END ShowArray;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
x: ARRAY 10 OF INTEGER;
|
||||
y: ARRAY 15 OF INTEGER;
|
||||
z: ARRAY 25 OF INTEGER;
|
||||
w: POINTER TO ARRAY OF INTEGER;
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
FOR i := 0 TO LEN(x) - 1 DO x[i] := i END;
|
||||
FOR i := 0 TO LEN(y) - 1 DO y[i] := i END;
|
||||
Concat(x,y,z);StdLog.String("1> ");ShowArray(z);
|
||||
|
||||
NEW(w,LEN(x) + LEN(y));
|
||||
Concat(x,y,z);StdLog.String("2:> ");ShowArray(z);
|
||||
|
||||
StdLog.String("3:> ");ShowArray(Concat2(x,y));
|
||||
END Do;
|
||||
|
||||
END ArrayConcat.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
arr1 = [1, 2, 3]
|
||||
arr2 = ["foo", "bar", "baz"]
|
||||
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"]
|
||||
8
Task/Array-concatenation/D/array-concatenation.d
Normal file
8
Task/Array-concatenation/D/array-concatenation.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import std.stdio: writeln;
|
||||
|
||||
void main() {
|
||||
int[] a = [1, 2];
|
||||
int[] b = [4, 5, 6];
|
||||
|
||||
writeln(a, " ~ ", b, " = ", a ~ b);
|
||||
}
|
||||
53
Task/Array-concatenation/Delphi/array-concatenation-1.delphi
Normal file
53
Task/Array-concatenation/Delphi/array-concatenation-1.delphi
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// This example works on stuff as old as Delphi 5 (maybe older)
|
||||
// Modern Delphi / Object Pascal has both
|
||||
// • generic types
|
||||
// • the ability to concatenate arrays with the '+' operator
|
||||
// So I could just say:
|
||||
// myarray := [1] + [2, 3];
|
||||
// But if you do not have access to the latest/greatest, then:
|
||||
{$apptype console}
|
||||
|
||||
type
|
||||
// Array types must be declared in order to return them from functions
|
||||
// They can also be used with open array parameters.
|
||||
TArrayOfString = array of string;
|
||||
|
||||
function Concat( a, b : array of string ): TArrayOfString; overload;
|
||||
{
|
||||
Every array type needs its own 'Concat' function:
|
||||
function Concat( a, b : array of integer ): TArrayOfInteger; overload;
|
||||
function Concat( a, b : array of double ): TArrayOfDouble; overload;
|
||||
etc
|
||||
Also, dynamic and open array types ALWAYS start at 0. No need to complicate indexing here.
|
||||
}
|
||||
var
|
||||
n : Integer;
|
||||
begin
|
||||
SetLength( result, Length(a)+Length(b) );
|
||||
for n := 0 to High(a) do result[ n] := a[n];
|
||||
for n := 0 to High(b) do result[Length(a)+n] := b[n]
|
||||
end;
|
||||
|
||||
// Example time!
|
||||
function Join( a : array of string; sep : string = ' ' ): string;
|
||||
var
|
||||
n : integer;
|
||||
begin
|
||||
if Length(a) > 0 then result := a[0];
|
||||
for n := 1 to High(a) do result := result + sep + a[n]
|
||||
end;
|
||||
|
||||
var
|
||||
names : TArrayOfString;
|
||||
begin
|
||||
// Here we use the open array parameter constructor as a convenience
|
||||
names := Concat( ['Korra', 'Asami'], ['Bolin', 'Mako'] );
|
||||
WriteLn( Join(names) );
|
||||
|
||||
// Also convenient: open array parameters are assignment-compatible with our array type!
|
||||
names := Concat( names, ['Varrick', 'Zhu Li'] );
|
||||
WriteLn( #13#10, Join(names, ', ') );
|
||||
|
||||
names := Concat( ['Tenzin'], names );
|
||||
Writeln( #13#10, Join(names, #13#10 ) );
|
||||
end.
|
||||
38
Task/Array-concatenation/Delphi/array-concatenation-2.delphi
Normal file
38
Task/Array-concatenation/Delphi/array-concatenation-2.delphi
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
type
|
||||
TReturnArray = array of integer; //you need to define a type to be able to return it
|
||||
|
||||
function ConcatArray(a1,a2:array of integer):TReturnArray;
|
||||
var
|
||||
i,r:integer;
|
||||
begin
|
||||
{ Low(array) is not necessarily 0 }
|
||||
SetLength(result,High(a1)-Low(a1)+High(a2)-Low(a2)+2); //BAD idea to set a length you won't release, just to show the idea!
|
||||
r:=0; //index on the result may be different to indexes on the sources
|
||||
for i := Low(a1) to High(a1) do begin
|
||||
result[r] := a1[i];
|
||||
Inc(r);
|
||||
end;
|
||||
for i := Low(a2) to High(a2) do begin
|
||||
result[r] := a2[i];
|
||||
Inc(r);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
var
|
||||
a1,a2:array of integer;
|
||||
r1:array of integer;
|
||||
i:integer;
|
||||
begin
|
||||
SetLength(a1,4);
|
||||
SetLength(a2,3);
|
||||
for i := Low(a1) to High(a1) do
|
||||
a1[i] := i;
|
||||
for i := Low(a2) to High(a2) do
|
||||
a2[i] := i;
|
||||
TReturnArray(r1) := ConcatArray(a1,a2);
|
||||
for i := Low(r1) to High(r1) do
|
||||
showMessage(IntToStr(r1[i]));
|
||||
Finalize(r1); //IMPORTANT!
|
||||
ShowMessage(IntToStr(High(r1)));
|
||||
end;
|
||||
9
Task/Array-concatenation/Diego/array-concatenation.diego
Normal file
9
Task/Array-concatenation/Diego/array-concatenation.diego
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
set_namespace(rosettacode)_me();
|
||||
|
||||
add_ary(a)_values(1,2,3);
|
||||
add_ary(b)_values(4,5,6);
|
||||
me_msg()_ary[a]_concat[b]
|
||||
me_msg()_ary[a]_concat()_ary[b]; // alternative
|
||||
me_msg()_calc([a]+[b]); // alternative
|
||||
|
||||
reset_namespace[];
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var xs = [1,2,3]
|
||||
var ys = [4,5,6]
|
||||
var alls = Array.Concat(xs, ys)
|
||||
print(alls)
|
||||
2
Task/Array-concatenation/E/array-concatenation.e
Normal file
2
Task/Array-concatenation/E/array-concatenation.e
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
? [1,2] + [3,4]
|
||||
# value: [1, 2, 3, 4]
|
||||
4
Task/Array-concatenation/ECL/array-concatenation.ecl
Normal file
4
Task/Array-concatenation/ECL/array-concatenation.ecl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
A := [1, 2, 3, 4];
|
||||
B := [5, 6, 7, 8];
|
||||
|
||||
C := A + B;
|
||||
13
Task/Array-concatenation/EGL/array-concatenation.egl
Normal file
13
Task/Array-concatenation/EGL/array-concatenation.egl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
program ArrayConcatenation
|
||||
function main()
|
||||
a int[] = [ 1, 2, 3 ];
|
||||
b int[] = [ 4, 5, 6 ];
|
||||
c int[];
|
||||
c.appendAll(a);
|
||||
c.appendAll(b);
|
||||
|
||||
for (i int from 1 to c.getSize())
|
||||
SysLib.writeStdout("Element " :: i :: " = " :: c[i]);
|
||||
end
|
||||
end
|
||||
end
|
||||
8
Task/Array-concatenation/EMal/array-concatenation.emal
Normal file
8
Task/Array-concatenation/EMal/array-concatenation.emal
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
^|EMal has the concept of list expansion,
|
||||
|you can expand a list to function arguments
|
||||
|by prefixing it with the unary plus.
|
||||
|^
|
||||
List a = int[1,2,3]
|
||||
List b = int[4,5,6]
|
||||
List c = int[+a, +b]
|
||||
writeLine(c)
|
||||
31
Task/Array-concatenation/ERRE/array-concatenation.erre
Normal file
31
Task/Array-concatenation/ERRE/array-concatenation.erre
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
PROGRAM ARRAY_CONCAT
|
||||
|
||||
DIM A[5],B[5],C[10]
|
||||
|
||||
!
|
||||
! for rosettacode.org
|
||||
!
|
||||
|
||||
BEGIN
|
||||
DATA(1,2,3,4,5)
|
||||
DATA(6,7,8,9,0)
|
||||
|
||||
FOR I=1 TO 5 DO ! read array A[.]
|
||||
READ(A[I])
|
||||
END FOR
|
||||
FOR I=1 TO 5 DO ! read array B[.]
|
||||
READ(B[I])
|
||||
END FOR
|
||||
|
||||
FOR I=1 TO 10 DO ! append B[.] to A[.]
|
||||
IF I>5 THEN
|
||||
C[I]=B[I-5]
|
||||
ELSE
|
||||
C[I]=A[I]
|
||||
END IF
|
||||
PRINT(C[I];) ! print single C value
|
||||
END FOR
|
||||
|
||||
PRINT
|
||||
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
a[] = [ 1 2 3 ]
|
||||
b[] = [ 4 5 6 ]
|
||||
c[] = a[]
|
||||
for h in b[]
|
||||
c[] &= h
|
||||
.
|
||||
print c[]
|
||||
12
Task/Array-concatenation/EchoLisp/array-concatenation.l
Normal file
12
Task/Array-concatenation/EchoLisp/array-concatenation.l
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
;;;; VECTORS
|
||||
(vector-append (make-vector 6 42) (make-vector 4 666))
|
||||
→ #( 42 42 42 42 42 42 666 666 666 666)
|
||||
|
||||
;;;; LISTS
|
||||
(append (iota 5) (iota 6))
|
||||
→ (0 1 2 3 4 0 1 2 3 4 5)
|
||||
|
||||
;; NB - append may also be used with sequences (lazy lists)
|
||||
(lib 'sequences)
|
||||
(take (append [1 .. 7] [7 6 .. 0]) #:all)
|
||||
→ (1 2 3 4 5 6 7 6 5 4 3 2 1)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
String[] fruits = ["apples", "oranges"];
|
||||
String[] grains = ["wheat", "corn"];
|
||||
String[] all = fruits + grains;
|
||||
11
Task/Array-concatenation/Efene/array-concatenation.efene
Normal file
11
Task/Array-concatenation/Efene/array-concatenation.efene
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@public
|
||||
run = fn () {
|
||||
A = [1, 2, 3, 4]
|
||||
B = [5, 6, 7, 8]
|
||||
|
||||
C = A ++ B
|
||||
D = lists.append([A, B])
|
||||
|
||||
io.format("~p~n", [C])
|
||||
io.format("~p~n", [D])
|
||||
}
|
||||
3
Task/Array-concatenation/Ela/array-concatenation.ela
Normal file
3
Task/Array-concatenation/Ela/array-concatenation.ela
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
xs = [1,2,3]
|
||||
ys = [4,5,6]
|
||||
xs ++ ys
|
||||
11
Task/Array-concatenation/Elena/array-concatenation.elena
Normal file
11
Task/Array-concatenation/Elena/array-concatenation.elena
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import extensions;
|
||||
|
||||
public program()
|
||||
{
|
||||
var a := new int[]{1,2,3};
|
||||
var b := new int[]{4,5};
|
||||
|
||||
console.printLine(
|
||||
"(",a.asEnumerable(),") + (",b.asEnumerable(),
|
||||
") = (",(a + b).asEnumerable(),")").readChar();
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
iex(1)> [1, 2, 3] ++ [4, 5, 6]
|
||||
[1, 2, 3, 4, 5, 6]
|
||||
iex(2)> Enum.concat([[1, [2], 3], [4], [5, 6]])
|
||||
[1, [2], 3, 4, 5, 6]
|
||||
iex(3)> Enum.concat([1..3, [4,5,6], 7..9])
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
19
Task/Array-concatenation/Elm/array-concatenation.elm
Normal file
19
Task/Array-concatenation/Elm/array-concatenation.elm
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
|
||||
import Html.App exposing (beginnerProgram)
|
||||
import Array exposing (Array, append, initialize)
|
||||
|
||||
|
||||
xs : Array Int
|
||||
xs =
|
||||
initialize 3 identity -- [0, 1, 2]
|
||||
|
||||
ys : Array Int
|
||||
ys =
|
||||
initialize 3 <| (+) 3 -- [3, 4, 5]
|
||||
|
||||
main = beginnerProgram { model = ()
|
||||
, view = \_ -> toHtml (show (append xs ys))
|
||||
, update = \_ _ -> ()
|
||||
}
|
||||
|
||||
-- Array.fromList [0,1,2,3,4,5]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(vconcat '[1 2 3] '[4 5] '[6 7 8 9])
|
||||
=> [1 2 3 4 5 6 7 8 9]
|
||||
5
Task/Array-concatenation/Erlang/array-concatenation.erl
Normal file
5
Task/Array-concatenation/Erlang/array-concatenation.erl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
1> [1, 2, 3] ++ [4, 5, 6].
|
||||
[1,2,3,4,5,6]
|
||||
2> lists:append([1, 2, 3], [4, 5, 6]).
|
||||
[1,2,3,4,5,6]
|
||||
3>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
sequence s1,s2,s3
|
||||
s1 = {1,2,3}
|
||||
s2 = {4,5,6}
|
||||
s3 = s1 & s2
|
||||
? s3
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
let a = [|1; 2; 3|]
|
||||
let b = [|4; 5; 6;|]
|
||||
let c = Array.append a b
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
let x = [1; 2; 3]
|
||||
let y = [4; 5; 6]
|
||||
let z1 = x @ y
|
||||
let z2 = List.append x y
|
||||
9
Task/Array-concatenation/FBSL/array-concatenation.fbsl
Normal file
9
Task/Array-concatenation/FBSL/array-concatenation.fbsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#APPTYPE CONSOLE
|
||||
|
||||
DIM aint[] ={1, 2, 3}, astr[] ={"one", "two", "three"}, asng[] ={!1, !2, !3}
|
||||
|
||||
FOREACH DIM e IN ARRAYMERGE(aint, astr, asng)
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
|
||||
PAUSE
|
||||
|
|
@ -0,0 +1 @@
|
|||
append
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
( scratchpad ) USE: sequences
|
||||
( scratchpad ) { 1 2 } { 3 4 } append .
|
||||
{ 1 2 3 4 }
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
> a := [1,2,3]
|
||||
> b := [4,5,6]
|
||||
> a.addAll(b)
|
||||
> a
|
||||
[1,2,3,4,5,6]
|
||||
13
Task/Array-concatenation/Forth/array-concatenation.fth
Normal file
13
Task/Array-concatenation/Forth/array-concatenation.fth
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
: $!+ ( a u a' -- a'+u )
|
||||
2dup + >r swap move r> ;
|
||||
: cat ( a2 u2 a1 u1 -- a3 u1+u2 )
|
||||
align here dup >r $!+ $!+ r> tuck - dup allot ;
|
||||
|
||||
\ TEST
|
||||
create a1 1 , 2 , 3 ,
|
||||
create a2 4 , 5 ,
|
||||
a2 2 cells a1 3 cells cat dump
|
||||
|
||||
8018425F0: 01 00 00 00 00 00 00 00 - 02 00 00 00 00 00 00 00 ................
|
||||
801842600: 03 00 00 00 00 00 00 00 - 04 00 00 00 00 00 00 00 ................
|
||||
801842610: 05 00 00 00 00 00 00 00 - ........
|
||||
17
Task/Array-concatenation/Fortran/array-concatenation.f
Normal file
17
Task/Array-concatenation/Fortran/array-concatenation.f
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program Concat_Arrays
|
||||
implicit none
|
||||
|
||||
! Note: in Fortran 90 you must use the old array delimiters (/ , /)
|
||||
integer, dimension(3) :: a = [1, 2, 3] ! (/1, 2, 3/)
|
||||
integer, dimension(3) :: b = [4, 5, 6] ! (/4, 5, 6/)
|
||||
integer, dimension(:), allocatable :: c, d
|
||||
|
||||
allocate(c(size(a)+size(b)))
|
||||
c(1 : size(a)) = a
|
||||
c(size(a)+1 : size(a)+size(b)) = b
|
||||
print*, c
|
||||
|
||||
! alternative
|
||||
d = [a, b] ! (/a, b/)
|
||||
print*, d
|
||||
end program Concat_Arrays
|
||||
|
|
@ -0,0 +1 @@
|
|||
array2 := array0 + array1
|
||||
|
|
@ -0,0 +1 @@
|
|||
array2 := concat(array0, array1);
|
||||
26
Task/Array-concatenation/FreeBASIC/array-concatenation.basic
Normal file
26
Task/Array-concatenation/FreeBASIC/array-concatenation.basic
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub ConcatArrays(a() As String, b() As String, c() As String)
|
||||
Dim aSize As Integer = UBound(a) - LBound(a) + 1
|
||||
Dim bSize As Integer = UBound(b) - LBound(b) + 1
|
||||
Dim cSize As Integer = aSize + bSize
|
||||
Redim c(0 To cSize - 1)
|
||||
Dim i As Integer
|
||||
For i = 0 To aSize - 1
|
||||
c(i) = a(LBound(a) + i)
|
||||
Next
|
||||
For i = 0 To bSize - 1
|
||||
c(UBound(a) + i + 1) = b(LBound(b) + i)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Dim a(3) As String = {"The", "quick", "brown", "fox"}
|
||||
Dim b(4) As String = {"jumped", "over", "the", "lazy", "dog"}
|
||||
Dim c() As String
|
||||
ConcatArrays(a(), b(), c())
|
||||
For i As Integer = LBound(c) To UBound(c)
|
||||
Print c(i); " ";
|
||||
Next
|
||||
Print : Print
|
||||
Print "Press any key to quit the program"
|
||||
Sleep
|
||||
3
Task/Array-concatenation/Frink/array-concatenation.frink
Normal file
3
Task/Array-concatenation/Frink/array-concatenation.frink
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
a = [1,2]
|
||||
b = [3,4]
|
||||
a.pushAll[b]
|
||||
5
Task/Array-concatenation/FunL/array-concatenation.funl
Normal file
5
Task/Array-concatenation/FunL/array-concatenation.funl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
arr1 = array( [1, 2, 3] )
|
||||
arr2 = array( [4, 5, 6] )
|
||||
arr3 = array( [7, 8, 9] )
|
||||
|
||||
println( arr1 + arr2 + arr3 )
|
||||
|
|
@ -0,0 +1 @@
|
|||
concat as bs cd
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
void local fn DoIt
|
||||
CFArrayRef array = @[@"Alpha",@"Bravo",@"Charlie"]
|
||||
print array
|
||||
|
||||
array = fn ArrayByAddingObjectsFromArray( array, @[@"Delta",@"Echo",@"FutureBasic"] )
|
||||
print array
|
||||
end fn
|
||||
|
||||
window 1
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
10
Task/Array-concatenation/GAP/array-concatenation.gap
Normal file
10
Task/Array-concatenation/GAP/array-concatenation.gap
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Concatenate arrays
|
||||
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
|
||||
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
|
||||
|
||||
# Append to a variable
|
||||
a := [1, 2, 3];
|
||||
Append(a, [4, 5, 6);
|
||||
Append(a, [7, 8, 9]);
|
||||
a;
|
||||
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
|
||||
10
Task/Array-concatenation/GLSL/array-concatenation-1.glsl
Normal file
10
Task/Array-concatenation/GLSL/array-concatenation-1.glsl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#define array_concat(T,a1,a2,returned) \
|
||||
T[a1.length()+a2.length()] returned; \
|
||||
{ \
|
||||
for(int i = 0; i < a1.length(); i++){ \
|
||||
returned[i] = a1[i]; \
|
||||
} \
|
||||
for(int i = 0; i < a2.length(); i++){ \
|
||||
returned[i+a1.length()] = a2[i]; \
|
||||
} \
|
||||
}
|
||||
2
Task/Array-concatenation/GLSL/array-concatenation-2.glsl
Normal file
2
Task/Array-concatenation/GLSL/array-concatenation-2.glsl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
array_concat(float,float[](1.,2.,3.),float[](4.,5.,6.),returned);
|
||||
int i = returned.length();
|
||||
|
|
@ -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
|
||||
28
Task/Array-concatenation/Genie/array-concatenation.genie
Normal file
28
Task/Array-concatenation/Genie/array-concatenation.genie
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[indent=4]
|
||||
/*
|
||||
Array concatenation, in Genie
|
||||
Tectonics: valac array-concat.gs
|
||||
*/
|
||||
|
||||
/* Creates a new array */
|
||||
def int_array_concat(x:array of int, y:array of int):array of int
|
||||
var a = new Array of int(false, true, 0) /* (zero-terminated, clear, size) */
|
||||
a.append_vals (x, x.length)
|
||||
a.append_vals (y, y.length)
|
||||
|
||||
z:array of int = (owned) a.data
|
||||
return z
|
||||
|
||||
def int_show_array(a:array of int)
|
||||
for element in a do stdout.printf("%d ", element)
|
||||
stdout.printf("\n")
|
||||
|
||||
init
|
||||
x: array of int = {1, 2, 3}
|
||||
y: array of int = {3, 2, 1, 0, -1}
|
||||
z: array of int = int_array_concat(x, y)
|
||||
|
||||
stdout.printf("x: "); int_show_array(x)
|
||||
stdout.printf("y: "); int_show_array(y)
|
||||
stdout.printf("z: "); int_show_array(z)
|
||||
print "%d elements in new array", z.length
|
||||
35
Task/Array-concatenation/Go/array-concatenation-1.go
Normal file
35
Task/Array-concatenation/Go/array-concatenation-1.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// Example 1: Idiomatic in Go is use of the append function.
|
||||
// Elements must be of identical type.
|
||||
a := []int{1, 2, 3}
|
||||
b := []int{7, 12, 60} // these are technically slices, not arrays
|
||||
c := append(a, b...)
|
||||
fmt.Println(c)
|
||||
|
||||
// Example 2: Polymorphism.
|
||||
// interface{} is a type too, one that can reference values of any type.
|
||||
// This allows a sort of polymorphic list.
|
||||
i := []interface{}{1, 2, 3}
|
||||
j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
|
||||
k := append(i, j...) // append will allocate as needed
|
||||
fmt.Println(k)
|
||||
|
||||
// Example 3: Arrays, not slices.
|
||||
// A word like "array" on RC often means "whatever array means in your
|
||||
// language." In Go, the common role of "array" is usually filled by
|
||||
// Go slices, as in examples 1 and 2. If by "array" you really mean
|
||||
// "Go array," then you have to do a little extra work. The best
|
||||
// technique is almost always to create slices on the arrays and then
|
||||
// use the copy function.
|
||||
l := [...]int{1, 2, 3}
|
||||
m := [...]int{7, 12, 60} // arrays have constant size set at compile time
|
||||
var n [len(l) + len(m)]int
|
||||
copy(n[:], l[:]) // [:] creates a slice that references the entire array
|
||||
copy(n[len(l):], m[:])
|
||||
fmt.Println(n)
|
||||
|
||||
}
|
||||
57
Task/Array-concatenation/Go/array-concatenation-2.go
Normal file
57
Task/Array-concatenation/Go/array-concatenation-2.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Generic version
|
||||
// Easier to make the generic version accept any number of arguments,
|
||||
// and loop trough them. Otherwise there will be lots of code duplication.
|
||||
func ArrayConcat(arrays ...interface{}) interface{} {
|
||||
if len(arrays) == 0 {
|
||||
panic("Need at least one arguemnt")
|
||||
}
|
||||
var vals = make([]*reflect.SliceValue, len(arrays))
|
||||
var arrtype *reflect.SliceType
|
||||
var totalsize int
|
||||
for i,a := range arrays {
|
||||
v := reflect.NewValue(a)
|
||||
switch t := v.Type().(type) {
|
||||
case *reflect.SliceType:
|
||||
if arrtype == nil {
|
||||
arrtype = t
|
||||
} else if t != arrtype {
|
||||
panic("Unequal types")
|
||||
}
|
||||
vals[i] = v.(*reflect.SliceValue)
|
||||
totalsize += vals[i].Len()
|
||||
default: panic("not a slice")
|
||||
}
|
||||
}
|
||||
ret := reflect.MakeSlice(arrtype,totalsize,totalsize)
|
||||
targ := ret
|
||||
for _,v := range vals {
|
||||
reflect.Copy(targ, v)
|
||||
targ = targ.Slice(v.Len(),targ.Len())
|
||||
}
|
||||
return ret.Interface()
|
||||
}
|
||||
|
||||
// Type specific version
|
||||
func ArrayConcatInts(a, b []int) []int {
|
||||
ret := make([]int, len(a) + len(b))
|
||||
copy(ret, a)
|
||||
copy(ret[len(a):], b)
|
||||
return ret
|
||||
}
|
||||
|
||||
func main() {
|
||||
test1_a, test1_b := []int{1,2,3}, []int{4,5,6}
|
||||
test1_c := ArrayConcatInts(test1_a, test1_b)
|
||||
fmt.Println(test1_a, " + ", test1_b, " = ", test1_c)
|
||||
|
||||
test2_a, test2_b := []string{"a","b","c"}, []string{"d","e","f"}
|
||||
test2_c := ArrayConcat(test2_a, test2_b).([]string)
|
||||
fmt.Println(test2_a, " + ", test2_b, " = ", test2_c)
|
||||
}
|
||||
6
Task/Array-concatenation/Gosu/array-concatenation.gosu
Normal file
6
Task/Array-concatenation/Gosu/array-concatenation.gosu
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var listA = { 1, 2, 3 }
|
||||
var listB = { 4, 5, 6 }
|
||||
|
||||
var listC = listA.concat( listB )
|
||||
|
||||
print( listC ) // prints [1, 2, 3, 4, 5, 6]
|
||||
|
|
@ -0,0 +1 @@
|
|||
def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]
|
||||
|
|
@ -0,0 +1 @@
|
|||
println list
|
||||
|
|
@ -0,0 +1 @@
|
|||
(++) :: [a] -> [a] -> [a]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
[] ++ x = x
|
||||
(h:t) ++ y = h : (t ++ y)
|
||||
|
|
@ -0,0 +1 @@
|
|||
x ++ y = foldr (:) y x
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue