langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,12 @@
using System.Console;
using Nemerle.Collections;
module ArrayCat
{
Main() : void
{
def arr1 = array[1, 2, 3]; def arr2 = array[4, 5, 6];
def arr12 = arr1.Append(arr2); // <----
foreach (i in arr12) Write($"$i ");
}
}

View file

@ -0,0 +1,28 @@
/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
cymru = [ 'Ogof Ffynnon Ddu', 'Ogof Draenen' ]
dlm = '-'.copies(40)
say dlm
loop c_ = 0 to cymru.length - 1
say c_ cymru[c_]
end c_
yorks = [ 'Malham Tarn Pot', 'Greygill Hole' ]
say dlm
loop y_ = 0 to yorks.length - 1
say y_ yorks[y_]
end y_
merge = ArrayList()
merge.addAll(Arrays.asList(cymru))
merge.addAll(Arrays.asList(yorks))
say dlm
merged = merge.toArray()
loop m_ = 0 to merged.length - 1
say m_ merged[m_]
end m_

View file

@ -0,0 +1,16 @@
; file: arraycon.lsp
; url: http://rosettacode.org/wiki/Array_concatenation
; author: oofoe 2012-01-28
(println "Append lists: " (append '(3 a 5 3) (sequence 1 9)))
(println "Multi append: "
(append '(this is)
'(a test)
'(of the emergency)
(sequence 3 1)))
(println "Append arrays: "
(append '((x 56) (b 99)) '((z 34) (c 23) (r 88))))
(exit)

View file

@ -0,0 +1,6 @@
# let list1 = [1; 2; 3];;
val list1 : int list = [1; 2; 3]
# let list2 = [4; 5; 6];;
val list2 : int list = [4; 5; 6]
# let list1and2 = list1 @ list2;;
val list1and2 : int list = [1; 2; 3; 4; 5; 6]

View file

@ -0,0 +1,6 @@
# let array1 = [|1; 2; 3|];;
val array1 : int array = [|1; 2; 3|]
# let array2 = [|4; 5; 6|];;
val array2 : int array = [|4; 5; 6|]
# let array1and2 = Array.append array1 array2;;
val array1and2 : int array = [|1; 2; 3; 4; 5; 6|]

View file

@ -0,0 +1,31 @@
bundle Default {
class Arithmetic {
function : Main(args : String[]) ~ Nil {
array1 := [3, 5, 7];
array2 := [2, 4, 6];
array3 := Copy(array1, array2);
each(i : array3) {
array3[i]->PrintLine();
};
}
function : native : Copy(array1 : Int[], array2 : Int[]) ~ Int[] {
max := array1->Size() + array2->Size();
array3 := Int->New[max];
i := 0;
for(i := i; i < array1->Size(); i += 1;) {
array3[i] := array1[i];
};
j := 0;
for(i := i; i < max; i += 1;) {
array3[i] := array2[j];
j += 1;
};
return array3;
}
}
}

View file

@ -0,0 +1,7 @@
NSArray *arr1 = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
[NSNumber numberWithInt:2],
[NSNumber numberWithInt:3], nil];
NSArray *arr2 = [NSArray arrayWithObjects:[NSNumber numberWithInt:4],
[NSNumber numberWithInt:5],
[NSNumber numberWithInt:6], nil];
NSArray *arr3 = [arr1 arrayByAddingObjectsFromArray:arr2];

View file

@ -0,0 +1,8 @@
NSArray *arr1 = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
[NSNumber numberWithInt:2],
[NSNumber numberWithInt:3], nil];
NSArray *arr2 = [NSArray arrayWithObjects:[NSNumber numberWithInt:4],
[NSNumber numberWithInt:5],
[NSNumber numberWithInt:6], nil];
NSMutableArray *arr3 = [NSMutableArray arrayWithArray:arr1];
[arr3 addObjectsFromArray:arr2];

View file

@ -0,0 +1,7 @@
#include <order/interpreter.h>
ORDER_PP( 8tuple_append(8tuple(1, 2, 3), 8tuple(4, 5, 6), 8pair(7, 8)) )
// -> (1,2,3,4,5,6,7,8)
ORDER_PP( 8seq_append(8seq(1, 2, 3), 8seq(4, 5, 6), 8seq(7, 8)) )
// -> (1)(2)(3)(4)(5)(6)(7)(8)

View file

@ -0,0 +1,22 @@
'CREATE DYNAMIC ARRAY SPACES USING STRINGS
string sa=nuls 5* sizeof float
string sb=sa
'MAP ARRAY VARIABLES ONTO STRINGS
float a at *sa
float b at *sb
'ASSIGN SOME VALUES
a<=10,20,30,40,50
b<=60,70,80,90,00
'ADD ARRAY B TO A BY STRING CONCATENATION
sa+=sb
'TEST
print a[7] 'result 70

View file

@ -0,0 +1,5 @@
%% concatenating 2 lists
{Append [a b] [c d]} = [a b c d]
%% concatenating 2 tuples
{Tuple.append t(1 2 3) u(4 5 6)} = u(1 2 3 4 5 6)

View file

@ -0,0 +1 @@
concat(u,v)

View file

@ -0,0 +1,3 @@
declare x(12) fixed;
declare b(5) fixed defined x;
declare c(7) fixed defined x(1sub+5);

View file

@ -0,0 +1,3 @@
declare x(m+n) fixed;
declare b(m) fixed defined x;
declare c(n) fixed defined x(1sub+hbound(b,1));

View file

@ -0,0 +1,14 @@
declare a(5,6) fixed;
declare b(3,4) fixed defined a(1sub, 2sub);
declare c(2,2) fixed defined a(1sub+hbound(b,1), 2sub+hbound(b,2));
declare (i, j, k) fixed;
a = 0;
put skip list ('Please type elements for a 3 x 4 matrix:');
get list (b);
put skip list ('Please type elements for a 2 x 2 matrix:');
get list (c);
put skip edit (c) ( skip, (hbound(c,2)) f(5,0) );
put skip list ('Composite matrix:');
put skip edit (a) ( skip, (hbound(a,2)) f(5,0) );

View file

@ -0,0 +1,13 @@
Please type elements for a 3 x 4 matrix:
Please type elements for a 2 x 2 matrix:
13 14
15 16
Composite matrix:
1 2 3 4 0 0
5 6 7 8 0 0
9 10 11 12 0 0
0 0 0 0 13 14
0 0 0 0 15 16

View file

@ -0,0 +1,8 @@
# the comma ',' can be used to concatenate arrays:
sub concatenateArrays(@a, @b) {
@a, @b
}
my @a1 = (1,2,3);
my @a2 = (2,3,4);
concatenateArrays(@a1,@a2).join(", ").say;

View file

@ -0,0 +1 @@
[1 2 3 4] [5 6 7 8] concat

View file

@ -0,0 +1,5 @@
$a = 1,2,3
$b = 4,5,6
$c = $a + $b
Write-Host $c

View file

@ -0,0 +1,47 @@
Procedure displayArray(Array a(1), msg.s)
Protected i
Print(msg + " [")
For i = 0 To ArraySize(a())
Print(Str(a(i)))
If i <> ArraySize(a())
Print(", ")
EndIf
Next
PrintN("]")
EndProcedure
Procedure randomElements(Array a(1), lo, hi)
Protected i
For i = 0 To ArraySize(a())
a(i) = random(hi - lo) + lo
Next
EndProcedure
Procedure arrayConcat(Array a(1), Array b(1), Array c(1))
Protected i, newSize = ArraySize(a()) + ArraySize(b()) + 1
Dim c(newSize)
For i = 0 To ArraySize(a())
c(i) = a(i)
Next
For i = 0 To ArraySize(b())
c(i + ArraySize(a()) + 1) = b(i)
Next
EndProcedure
If OpenConsole()
Dim a(random(3) + 1)
Dim b(random(3) + 1)
Dim c(0) ;array will be resized by arrayConcat()
randomElements(a(), -5, 5)
randomElements(b(), -5, 5)
displayArray(a(), "a:")
displayArray(b(), "b:")
arrayConcat(a(), b(), c())
displayArray(c(), "concat of a[] + b[]:")
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,7 @@
a1: [1 2 3]
a2: [4 5 6]
a3: [7 8 9]
append a1 a2 ; -> [1 2 3 4 5 6]
append/only a1 a3 ; -> [1 2 3 4 5 6 [7 8 9]]

View file

@ -0,0 +1,13 @@
>> x = [1, 2, 3]
>> y = [4, 5, 6]
// appending matrix 'y' on the right from matrix 'x' is possible if the two matrices have
// the same number of rows:
>> z1 = [x, y]
matrix columns 1 thru 6
1 2 3 4 5 6
// stacking matrix 'y' below the matrix 'x' is possible if the two matrices have
// the same number of columns:
>> z2 = [x; y]
1 2 3
4 5 6
>>

View file

@ -0,0 +1,3 @@
needs array'
^array'new{ 1 2 3 } ^array'new{ 4 5 6 } ^array'append

View file

@ -0,0 +1,20 @@
* # Concatenate 2 arrays (vectors)
define('cat(a1,a2)i,j') :(cat_end)
cat cat = array(prototype(a1) + prototype(a2))
cat1 i = i + 1; cat<i> = a1<i> :s(cat1)
cat2 j = j + 1; cat<i - 1 + j> = a2<j> :s(cat2)f(return)
cat_end
* # Fill arrays
str1 = '1 2 3 4 5'; arr1 = array(5)
loop i = i + 1; str1 len(p) span('0123456789') . arr1<i> @p :s(loop)
str2 = '6 7 8 9 10'; arr2 = array(5)
loop2 j = j + 1; str2 len(q) span('0123456789') . arr2<j> @q :s(loop2)
* # Test and display
arr3 = cat(arr1,arr2)
loop3 k = k + 1; str3 = str3 arr3<k> ' ' :s(loop3)
output = str1
output = str2
output = str3
end

View file

@ -0,0 +1,16 @@
$ include "seed7_05.s7i";
var array integer: a is [] (1, 2, 3, 4);
var array integer: b is [] (5, 6, 7, 8);
var array integer: c is [] (9, 10);
const proc: main is func
local
var integer: number is 0;
begin
c := a & b;
for number range c do
write(number <& " ");
end for;
writeln;
end func;

View file

@ -0,0 +1 @@
{1. 2. 3. 4. 5} ; {6. 7. 8. 9. 10}

View file

@ -0,0 +1,3 @@
val l1 = [1,2,3,4];;
val l2 = [5,6,7,8];;
val l3 = l1 @ l2 (* [1,2,3,4,5,6,7,8] *)

View file

@ -0,0 +1 @@
[1 2 3] [4 5 6] concat

View file

@ -0,0 +1,3 @@
array1=( 1 2 3 4 5 )
array2=( 6 7 8 9 10 )
botharrays=( ${array1[@]} ${array2[@]} )

View file

@ -0,0 +1,8 @@
array1='1 2 3 4 5'
array2='6 7 8 9 10'
# Concatenated to a Bash array ...
botharrays_a=( $array1 $array2 )
# Concatenated to a string ...
botharrays_s="$array1 $array2"

View file

@ -0,0 +1,18 @@
Function ArrayConcat(arr1, arr2)
ReDim ret(UBound(arr1) + UBound(arr2) + 1)
For i = 0 To UBound(arr1)
ret(i) = arr1(i)
Next
offset = Ubound(arr1) + 1
For i = 0 To UBound(arr2)
ret(i + offset) = arr2(i)
Next
ArrayConcat = ret
End Function
arr1 = array(10,20,30)
arr2 = array(40,50,60)
WScript.Echo "arr1 = array(" & Join(arr1,", ") & ")"
WScript.Echo "arr2 = array(" & Join(arr2,", ") & ")"
arr3 = ArrayConcat(arr1, arr2)
WScript.Echo "arr1 + arr2 = array(" & Join(arr3,", ") & ")"

View file

@ -0,0 +1,14 @@
int[] array_concat(int[]a,int[]b){
int[] c = new int[a.length + b.length];
Memory.copy(c, a, a.length * sizeof(int));
Memory.copy(&c[a.length], b, b.length * sizeof(int));
return c;
}
void main(){
int[] a = {1,2,3,4,5};
int[] b = {6,7,8};
int[] c = array_concat(a,b);
foreach(int i in c){
stdout.printf("%d\n",i);
}
}

View file

@ -0,0 +1,5 @@
Dim iArray1() As Integer = {1, 2, 3}
Dim iArray2() As Integer = {4, 5, 6}
Dim iArray3() As Integer = Nothing
iArray3 = iArray1.Concat(iArray2).ToArray

View file

@ -0,0 +1,3 @@
a = [1,2,3];
b = [4,5,6];
ab = grow(a, b);