2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,2 +1,6 @@
|
|||
;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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1 +1 @@
|
|||
main : { [val 1 2 3] [val 4 5 6] cat }
|
||||
[1 2 3] [4 5 6] cat ;
|
||||
|
|
|
|||
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 @@
|
|||
(into [1 2 3] [4 5 6])
|
||||
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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(vconcat '[1 2 3] '[4 5] '[6 7 8 9])
|
||||
=> [1 2 3 4 5 6 7 8 9]
|
||||
16
Task/Array-concatenation/JavaScript/array-concatenation-2.js
Normal file
16
Task/Array-concatenation/JavaScript/array-concatenation-2.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
// concat :: [[a]] -> [a]
|
||||
function concat(xs) {
|
||||
return [].concat.apply([], xs);
|
||||
}
|
||||
|
||||
|
||||
return concat(
|
||||
[["alpha", "beta", "gamma"],
|
||||
["delta", "epsilon", "zeta"],
|
||||
["eta", "theta", "iota"]]
|
||||
);
|
||||
|
||||
})();
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
a = {1,2,3}
|
||||
b = {4,5,6}
|
||||
table.foreach(b,function(i,v)table.insert(a,v)end)
|
||||
for i,v in next,a do io.write (v..' ') end
|
||||
a = {1, 2, 3}
|
||||
b = {4, 5, 6}
|
||||
|
||||
for _, v in pairs(b) do
|
||||
table.insert(a, v)
|
||||
end
|
||||
|
||||
print(table.concat(a, ", "))
|
||||
|
|
|
|||
13
Task/Array-concatenation/Onyx/array-concatenation.onyx
Normal file
13
Task/Array-concatenation/Onyx/array-concatenation.onyx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# With two arrays on the stack, cat pops
|
||||
# them, concatenates them, and pushes the result back
|
||||
# on the stack. This works with arrays of integers,
|
||||
# strings, or whatever. For example,
|
||||
|
||||
[1 2 3] [4 5 6] cat # result: [1 2 3 4 5 6]
|
||||
[`abc' `def'] [`ghi' `jkl'] cat # result: [`abc' `def' `ghi' `jkl']
|
||||
|
||||
# To concatenate more than two arrays, push the number of arrays
|
||||
# to concatenate onto the stack and use ncat. For example,
|
||||
|
||||
[1 true `a'] [2 false `b'] [`3rd array'] 3 ncat
|
||||
# leaves [1 true `a' 2 false `b' `3rd array'] on the stack
|
||||
17
Task/Array-concatenation/Rust/array-concatenation.rust
Normal file
17
Task/Array-concatenation/Rust/array-concatenation.rust
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
fn main() {
|
||||
let a_vec: Vec<i32> = vec![1, 2, 3, 4, 5];
|
||||
let b_vec: Vec<i32> = vec![6; 5];
|
||||
|
||||
let c_vec = concatenate_arrays::<i32>(a_vec.as_slice(), b_vec.as_slice());
|
||||
|
||||
println!("{:?} ~ {:?} => {:?}", a_vec, b_vec, c_vec);
|
||||
}
|
||||
|
||||
fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
|
||||
let mut concat: Vec<T> = vec![x[0].clone(); x.len()];
|
||||
|
||||
concat.clone_from_slice(x);
|
||||
concat.extend_from_slice(y);
|
||||
|
||||
concat
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
variable a = [1, 2, 3];
|
||||
variable b = [4, 5, 6];
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
variable la = length(a), c = _typeof(a)[la+length(b)];
|
||||
c[ [:la-1] ] = a;
|
||||
c[ [la:] ] = b;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
a = {1, 2, 3};
|
||||
b = {4, 5, 6};
|
||||
|
||||
variable c = list_concat(a, b);
|
||||
|
|
@ -0,0 +1 @@
|
|||
c = list_to_array(c);
|
||||
|
|
@ -0,0 +1 @@
|
|||
list_join(a, b);
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
10 LET x=10
|
||||
20 LET y=20
|
||||
30 DIM a(x)
|
||||
40 DIM b(y)
|
||||
50 DIM c(x+y)
|
||||
60 FOR i=1 TO x
|
||||
70 LET c(i)=a(i)
|
||||
80 NEXT i
|
||||
90 FOR i=1 TO y
|
||||
100 LET c(x+i)=b(i)
|
||||
110 NEXT i
|
||||
120 FOR i=1 TO x+y
|
||||
130 PRINT c(i);", ";
|
||||
140 NEXT i
|
||||
Loading…
Add table
Add a link
Reference in a new issue