langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
13
Task/Arrays/NSIS/arrays.nsis
Normal file
13
Task/Arrays/NSIS/arrays.nsis
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
!include NSISArray.nsh
|
||||
Function ArrayTest
|
||||
Push $0
|
||||
; Declaring an array
|
||||
NSISArray::New TestArray 1 2
|
||||
NSISArray::Push TestArray "Hello"
|
||||
; NSISArray arrays are dynamic by default.
|
||||
NSISArray::Push TestArray "World"
|
||||
NSISArray::Read TestArray 1
|
||||
Pop $0
|
||||
DetailPrint $0
|
||||
Pop $0
|
||||
FunctionEnd
|
||||
20
Task/Arrays/Nemerle/arrays.nemerle
Normal file
20
Task/Arrays/Nemerle/arrays.nemerle
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
using System.Collections;
|
||||
|
||||
module ArrayOps
|
||||
{
|
||||
Main() : void
|
||||
{
|
||||
def fives = array(10);
|
||||
foreach (i in [1 .. 10]) fives[i - 1] = i * 5;
|
||||
def ten = fives[1];
|
||||
WriteLine($"Ten: $ten");
|
||||
|
||||
def dynamic = ArrayList();
|
||||
dynamic.Add(1);
|
||||
dynamic.Add(3);
|
||||
dynamic[1] = 2;
|
||||
foreach (i in dynamic) Write($"$i\t"); // Nemerle isn't great about displaying arrays, it's better with lists though
|
||||
}
|
||||
}
|
||||
34
Task/Arrays/NetRexx/arrays.netrexx
Normal file
34
Task/Arrays/NetRexx/arrays.netrexx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
array = int[10]
|
||||
array[0] = 42
|
||||
|
||||
say array[0] array[3]
|
||||
say
|
||||
|
||||
words = ['Ogof', 'Ffynnon', 'Ddu']
|
||||
|
||||
say words[0] words[1] words[2]
|
||||
say
|
||||
|
||||
-- Dynamic arrays can be simulated via the Java Collections package
|
||||
splk = ArrayList()
|
||||
splk.add(words[0])
|
||||
splk.add(words[1])
|
||||
splk.add(words[2])
|
||||
splk.add('Draenen')
|
||||
|
||||
say splk.get(0) splk.get(3)
|
||||
say splk.get(0) splk.get(1) splk.get(2)
|
||||
say
|
||||
|
||||
-- or by using NetRexx "indexed strings" (associative arrays)
|
||||
cymru = ''
|
||||
cymru[0] = 0
|
||||
cymru[0] = cymru[0] + 1; cymru[cymru[0]] = splk.get(0) splk.get(1) splk.get(2)
|
||||
cymru[0] = cymru[0] + 1; cymru[cymru[0]] = splk.get(0) splk.get(3)
|
||||
|
||||
loop x_ = 1 to cymru[0] by 1
|
||||
say x_':' cymru[x_]
|
||||
end x_
|
||||
2
Task/Arrays/NewLISP/arrays-1.newlisp
Normal file
2
Task/Arrays/NewLISP/arrays-1.newlisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(array 5)
|
||||
→ (nil nil nil nil nil)
|
||||
2
Task/Arrays/NewLISP/arrays-2.newlisp
Normal file
2
Task/Arrays/NewLISP/arrays-2.newlisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(set 'myarray (array 3 4 (sequence 1 12)))
|
||||
→ ((1 2 3 4) (5 6 7 8) (9 10 11 12))
|
||||
17
Task/Arrays/OCaml/arrays.ocaml
Normal file
17
Task/Arrays/OCaml/arrays.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Array.make 6 'A' ;;
|
||||
- : char array = [|'A'; 'A'; 'A'; 'A'; 'A'; 'A'|]
|
||||
|
||||
# Array.init 8 (fun i -> i * 10) ;;
|
||||
- : int array = [|0; 10; 20; 30; 40; 50; 60; 70|]
|
||||
|
||||
# let arr = [|0; 1; 2; 3; 4; 5; 6 |] ;;
|
||||
val arr : int array = [|0; 1; 2; 3; 4; 5; 6|]
|
||||
|
||||
# arr.(4) ;;
|
||||
- : int = 4
|
||||
|
||||
# arr.(4) <- 65 ;;
|
||||
- : unit = ()
|
||||
|
||||
# arr ;;
|
||||
- : int array = [|0; 1; 2; 3; 65; 5; 6|]
|
||||
10
Task/Arrays/Objeck/arrays.objeck
Normal file
10
Task/Arrays/Objeck/arrays.objeck
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
bundle Default {
|
||||
class Arithmetic {
|
||||
function : Main(args : System.String[]), Nil {
|
||||
array := Int->New[2];
|
||||
array[0] := 13;
|
||||
array[1] := 7;
|
||||
(array[0] + array[1])->PrintLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Task/Arrays/Objective-C/arrays.m
Normal file
23
Task/Arrays/Objective-C/arrays.m
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// NSArrays are ordered collections of NSObject subclasses only.
|
||||
|
||||
// Create an array of NSString objects.
|
||||
NSArray *firstArray = [[NSArray alloc] initWithObjects:@"Hewey", @"Louie", @"Dewey", nil];
|
||||
|
||||
// NSArrays are immutable; it does have a mutable subclass, however - NSMutableArray.
|
||||
// Let's instantiate one with a mutable copy of our array.
|
||||
// We can do this by sending our first array a -mutableCopy message.
|
||||
NSMutableArray *secondArray = [firstArray mutableCopy];
|
||||
|
||||
// Replace Louie with Launchpad McQuack.
|
||||
[secondArray replaceObjectAtIndex:1 withObject:@"Launchpad"];
|
||||
|
||||
// Display the first object in the array.
|
||||
NSLog(@"%@", [secondArray objectAtIndex:0]);
|
||||
|
||||
// In non-ARC or non-GC environments, retained objects must be released later.
|
||||
[firstArray release];
|
||||
[secondArray release];
|
||||
|
||||
// There is also a modern syntax which allows convenient creation of autoreleased immutable arrays.
|
||||
// No nil termination is then needed.
|
||||
NSArray *thirdArray = @[ @"Hewey", @"Louie", @"Dewey", @1, @2, @3 ];
|
||||
17
Task/Arrays/OxygenBasic/arrays.oxy
Normal file
17
Task/Arrays/OxygenBasic/arrays.oxy
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'CREATING AN ARRAY
|
||||
|
||||
float f[100]
|
||||
|
||||
'SETTING INDEX BASE
|
||||
|
||||
indexbase 1 'default
|
||||
|
||||
'FILLING PART OF AN ARRAY
|
||||
|
||||
f[20]<=1,2,3,4,5,1.25
|
||||
|
||||
'MAPPING AN ARRAY TO ANOTHER
|
||||
|
||||
float *g
|
||||
@g=@f[20]
|
||||
print g[6] 'result 1.25
|
||||
8
Task/Arrays/Oz/arrays.oz
Normal file
8
Task/Arrays/Oz/arrays.oz
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
declare
|
||||
Arr = {Array.new 1 %% lowest index
|
||||
10 %% highest index
|
||||
37} %% all 10 fields initialized to 37
|
||||
in
|
||||
{Show Arr.1}
|
||||
Arr.1 := 64
|
||||
{Show Arr.1}
|
||||
3
Task/Arrays/PARI-GP/arrays.pari
Normal file
3
Task/Arrays/PARI-GP/arrays.pari
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
v=[];
|
||||
v=concat(v,7);
|
||||
v[1]
|
||||
19
Task/Arrays/PL-I/arrays.pli
Normal file
19
Task/Arrays/PL-I/arrays.pli
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* Example of an array having fixed dimensions */
|
||||
declare A(10) float initial (1, 9, 4, 6, 7, 2, 5, 8, 3, 10);
|
||||
|
||||
A(6) = -45;
|
||||
|
||||
/* Example of an array having dynamic bounds. */
|
||||
get list (N);
|
||||
|
||||
begin;
|
||||
declare B(N) float initial (9, 4, 7, 3, 8, 11, 0, 5, 15, 6);
|
||||
B(3) = -11;
|
||||
end;
|
||||
|
||||
/* Example of a dynamic array. */
|
||||
declare C(N) float controlled;
|
||||
get list (N);
|
||||
allocate C;
|
||||
C = 0;
|
||||
c(7) = 12;
|
||||
33
Task/Arrays/Pascal/arrays.pascal
Normal file
33
Task/Arrays/Pascal/arrays.pascal
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
Program ArrayDemo;
|
||||
uses
|
||||
SysUtils;
|
||||
var
|
||||
StaticArray: array[0..9] of Integer;
|
||||
DynamicArray: array of Integer;
|
||||
StaticArrayText,
|
||||
DynamicArrayText: string;
|
||||
lcv: Integer;
|
||||
begin
|
||||
// Setting the length of the dynamic array the same as the static one
|
||||
SetLength(DynamicArray, Length(StaticArray));
|
||||
// Asking random numbers storing into the static array
|
||||
for lcv := 0 to Pred(Length(StaticArray)) do
|
||||
begin
|
||||
write('Enter a integer random number for position ', Succ(lcv), ': ');
|
||||
readln(StaticArray[lcv]);
|
||||
end;
|
||||
// Storing entered numbers of the static array in reverse order into the dynamic
|
||||
for lcv := 0 to Pred(Length(StaticArray)) do
|
||||
DynamicArray[Pred(Length(DynamicArray)) - lcv] := StaticArray[lcv];
|
||||
// Concatenating the static and dynamic array into a single string variable
|
||||
StaticArrayText := '';
|
||||
DynamicArrayText := '';
|
||||
for lcv := 0 to Pred(Length(StaticArray)) do
|
||||
begin
|
||||
StaticArrayText := StaticArrayText + IntToStr(StaticArray[lcv]) + ' ';
|
||||
DynamicArrayText := DynamicArrayText + IntToStr(DynamicArray[lcv]) + ' ';
|
||||
end;
|
||||
// Displaying both arrays
|
||||
writeln(StaticArrayText);
|
||||
writeln(DynamicArrayText);
|
||||
end.
|
||||
8
Task/Arrays/Perl-6/arrays.pl6
Normal file
8
Task/Arrays/Perl-6/arrays.pl6
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
my @arr;
|
||||
|
||||
push @arr, 1;
|
||||
push @arr, 3;
|
||||
|
||||
@arr[0] = 2;
|
||||
|
||||
say @arr[0];
|
||||
8
Task/Arrays/Pike/arrays.pike
Normal file
8
Task/Arrays/Pike/arrays.pike
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
int main(){
|
||||
// Initial array, few random elements.
|
||||
array arr = ({3,"hi",84.2});
|
||||
|
||||
arr += ({"adding","to","the","array"}); // Lets add some elements.
|
||||
|
||||
write(arr[5] + "\n"); // And finally print element 5.
|
||||
}
|
||||
16
Task/Arrays/PostScript/arrays.ps
Normal file
16
Task/Arrays/PostScript/arrays.ps
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
%Declaring array
|
||||
|
||||
/x [0 1] def
|
||||
|
||||
%Assigning value to an element, PostScript arrays are 0 based.
|
||||
|
||||
x 0 3 put
|
||||
|
||||
%Print array
|
||||
|
||||
x pstack
|
||||
[3 1]
|
||||
|
||||
%Get an element
|
||||
|
||||
x 1 get
|
||||
1
Task/Arrays/PowerShell/arrays-1.psh
Normal file
1
Task/Arrays/PowerShell/arrays-1.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = @()
|
||||
2
Task/Arrays/PowerShell/arrays-2.psh
Normal file
2
Task/Arrays/PowerShell/arrays-2.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$a = ,2
|
||||
$a = @(2) # alternative
|
||||
1
Task/Arrays/PowerShell/arrays-3.psh
Normal file
1
Task/Arrays/PowerShell/arrays-3.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a = 1,2,3
|
||||
1
Task/Arrays/PowerShell/arrays-4.psh
Normal file
1
Task/Arrays/PowerShell/arrays-4.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a += 5
|
||||
1
Task/Arrays/PowerShell/arrays-5.psh
Normal file
1
Task/Arrays/PowerShell/arrays-5.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a[1]
|
||||
1
Task/Arrays/PowerShell/arrays-6.psh
Normal file
1
Task/Arrays/PowerShell/arrays-6.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$a[1] = 42
|
||||
1
Task/Arrays/PowerShell/arrays-7.psh
Normal file
1
Task/Arrays/PowerShell/arrays-7.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$r = 1..100
|
||||
1
Task/Arrays/PowerShell/arrays-8.psh
Normal file
1
Task/Arrays/PowerShell/arrays-8.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$r[0..9+25..27+80,85,90]
|
||||
1
Task/Arrays/PowerShell/arrays-9.psh
Normal file
1
Task/Arrays/PowerShell/arrays-9.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$r[-1] # last index
|
||||
5
Task/Arrays/PureBasic/arrays-1.purebasic
Normal file
5
Task/Arrays/PureBasic/arrays-1.purebasic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
;Set up an Array of 23 cells, e.g. 0-22
|
||||
Dim MyArray.i(22)
|
||||
MyArray(0) = 7
|
||||
MyArray(1) = 11
|
||||
MyArray(7) = 23
|
||||
5
Task/Arrays/PureBasic/arrays-2.purebasic
Normal file
5
Task/Arrays/PureBasic/arrays-2.purebasic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
;Extend the Array above to 56 items without affecting the already stored data
|
||||
ReDim MyArray(55)
|
||||
MyArray(22) = 7
|
||||
MyArray(33) = 11
|
||||
MyArray(44) = 23
|
||||
6
Task/Arrays/PureBasic/arrays-3.purebasic
Normal file
6
Task/Arrays/PureBasic/arrays-3.purebasic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
;Find all 6 non-zero cells from the Array above
|
||||
For i=0 To ArraySize(MyArray())
|
||||
If MyArray(i)
|
||||
PrintN(Str(i)+" differs from zero.")
|
||||
EndIf
|
||||
Next
|
||||
4
Task/Arrays/PureBasic/arrays-4.purebasic
Normal file
4
Task/Arrays/PureBasic/arrays-4.purebasic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
; Now, set up a multi dimensional Array
|
||||
Dim MultiArray.i(800, 600)
|
||||
MultiArray(100, 200) = 640
|
||||
MultiArray(130, 40) = 120
|
||||
2
Task/Arrays/PureBasic/arrays-5.purebasic
Normal file
2
Task/Arrays/PureBasic/arrays-5.purebasic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Dim MultiArray2.i(64, 128, 32)
|
||||
PrintN( Str(ArraySize(MultiArray2(), 2)) ; Will tell that second dimension size is '128'
|
||||
2
Task/Arrays/REBOL/arrays-1.rebol
Normal file
2
Task/Arrays/REBOL/arrays-1.rebol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a: [] ; Empty.
|
||||
b: ["foo"] ; Pre-initialized.
|
||||
2
Task/Arrays/REBOL/arrays-2.rebol
Normal file
2
Task/Arrays/REBOL/arrays-2.rebol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
append a ["up" "down"] ; -> ["up" "down"]
|
||||
insert a [left right] ; -> [left right "up" "down"]
|
||||
4
Task/Arrays/REBOL/arrays-3.rebol
Normal file
4
Task/Arrays/REBOL/arrays-3.rebol
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
first a ; -> left
|
||||
third a ; -> "up"
|
||||
last a ; -> "down"
|
||||
a/2 ; -> right (Note: REBOL is 1-based.)
|
||||
10
Task/Arrays/REBOL/arrays-4.rebol
Normal file
10
Task/Arrays/REBOL/arrays-4.rebol
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
a ; -> [left right "up" "down"]
|
||||
next a ; -> [right "up" "down"]
|
||||
skip a 2 ; -> ["up" "down"]
|
||||
|
||||
a: next a ; -> [right "up" "down"]
|
||||
head a ; -> [left right "up" "down"]
|
||||
|
||||
copy a ; -> [left right "up" "down"]
|
||||
copy/part a 2 ; -> [left right]
|
||||
copy/part skip a 2 2 ; -> ["up" "down"]
|
||||
29
Task/Arrays/RLaB/arrays.rlab
Normal file
29
Task/Arrays/RLaB/arrays.rlab
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// 1-D (row- or column-vectors)
|
||||
// Static:
|
||||
// row-vector
|
||||
x = [1:3];
|
||||
x = zeros(1,3); x[1]=1; x[2]=2; x[3]=3;
|
||||
// column-vector
|
||||
x = [1:3]'; // or
|
||||
x = [1;2;3]; // or
|
||||
x = zeros(3,1); x[1]=1; x[2]=2; x[3]=3;
|
||||
// Dynamic:
|
||||
x = []; // create an empty array
|
||||
x = [x; 1, 2]; // add a row to 'x' containing [1, 2], or
|
||||
x = [x, [1; 2]]; // add a column to 'x' containing [1; 2]
|
||||
|
||||
// 2-D array
|
||||
// Static:
|
||||
x = zeros(3,5); // create an zero-filed matrix of size 3x5
|
||||
x[1;1] = 1; // set the x(1,1) element to 1
|
||||
x[2;] = [1,2,3,4,5]; // set the second row x(2,) to a row vector
|
||||
x[3;4:5] = [2,3]; // set x(3,4) to 2 and x(3,5) to 3
|
||||
// Dynamic
|
||||
x = [1:5]; // create an row-vector x(1,1)=1, x(1,2)=2, ... x(1,5)=5
|
||||
x = [x; 2, 3, 4, 6, 7]; // add to 'x' a row.
|
||||
|
||||
// Accessing an element of arrays:
|
||||
// to retrieve/print element of matrix 'x' just put this in a single line in the script
|
||||
i=1;
|
||||
j=2;
|
||||
x[i;j]
|
||||
27
Task/Arrays/RPG/arrays.rpg
Normal file
27
Task/Arrays/RPG/arrays.rpg
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
//-Static array
|
||||
//--def of 10 el array of integers, initialised to zeros
|
||||
D array...
|
||||
D s 10i 0 dim(10)
|
||||
D inz
|
||||
//--def an el
|
||||
D el_1...
|
||||
D s 10i 0 inz
|
||||
|
||||
/free
|
||||
|
||||
//-assign first el
|
||||
//--first element of RPG array is indexed with 1
|
||||
array(1) = 111;
|
||||
|
||||
//-get first el of array
|
||||
el_1 = array(1);
|
||||
|
||||
//--display it
|
||||
dsply ('First el of array='+%char(el_1));
|
||||
//--displays: First el of array=111
|
||||
|
||||
//---or shorter, without "el_1"
|
||||
dsply ('First el of array='+%char(array(1)));
|
||||
//--displays: First el of array=111
|
||||
|
||||
/end-free
|
||||
34
Task/Arrays/Retro/arrays.retro
Normal file
34
Task/Arrays/Retro/arrays.retro
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
needs array'
|
||||
|
||||
( Create an array with four elements )
|
||||
^array'new{ 1 2 3 4 } constant a
|
||||
|
||||
( Add 10 to each element in an array and update the array with the results )
|
||||
a [ 10 + ] ^array'map
|
||||
|
||||
( Apply a quote to each element in an array; leaves the contents alone )
|
||||
a [ 10 + putn cr ] ^array'apply
|
||||
|
||||
( Display an array )
|
||||
a ^array'display
|
||||
|
||||
( Look for a value in an array )
|
||||
3 a ^array'in?
|
||||
6 a ^array'in?
|
||||
|
||||
( Look for a string in an array )
|
||||
"hello" a ^array'stringIn?
|
||||
|
||||
( Reverse the order of items in an array )
|
||||
a ^array'reverse
|
||||
|
||||
( Append two arrays and return a new one )
|
||||
^array'new{ 1 2 3 } constant a
|
||||
^array'new{ 4 5 6 } constant b
|
||||
a b ^array'append constant c
|
||||
|
||||
( Create an array from the values returned by a quote )
|
||||
[ 1 2 "hello" "world" ] ^array'fromQuote constant d
|
||||
|
||||
( Create a quote from the values in an array )
|
||||
d ^array'toQuote
|
||||
9
Task/Arrays/Run-BASIC/arrays.run
Normal file
9
Task/Arrays/Run-BASIC/arrays.run
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
print "Enter array 1 greater than 0"; : input a1
|
||||
print "Enter array 2 greater than 0"; : input a2
|
||||
|
||||
dim chrArray$(max(a1,1),max(a2,1))
|
||||
dim numArray(max(a1,1),max(a2,1))
|
||||
|
||||
chrArray$(1,1) = "Hello"
|
||||
numArray(1,1) = 987.2
|
||||
print chrArray$(1,1);" ";numArray(1,1)
|
||||
14
Task/Arrays/Slate/arrays.slate
Normal file
14
Task/Arrays/Slate/arrays.slate
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
slate[1]> #x := ##(1 2 3).
|
||||
{1. 2. 3}
|
||||
slate[2]> x
|
||||
{1. 2. 3}
|
||||
slate[3]> #y := {1 + 2. 3 + 4. 5}.
|
||||
{3. 7. 5}
|
||||
slate[4]> y at: 2 put: 99.
|
||||
99
|
||||
slate[5]> y
|
||||
{3. 7. 99}
|
||||
slate[6]> x first
|
||||
1
|
||||
slate[7]> x at: 0.
|
||||
1
|
||||
5
Task/Arrays/Suneido/arrays.suneido
Normal file
5
Task/Arrays/Suneido/arrays.suneido
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
array = Object('zero', 'one', 'two')
|
||||
array.Add('three')
|
||||
array.Add('five', at: 5)
|
||||
array[4] = 'four'
|
||||
Print(array[3]) --> 'three'
|
||||
1
Task/Arrays/TI-83-BASIC/arrays-1.ti-83
Normal file
1
Task/Arrays/TI-83-BASIC/arrays-1.ti-83
Normal file
|
|
@ -0,0 +1 @@
|
|||
{1,2,3,4,5}→L1
|
||||
3
Task/Arrays/TI-83-BASIC/arrays-2.ti-83
Normal file
3
Task/Arrays/TI-83-BASIC/arrays-2.ti-83
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{1,2,3,4,5}→L1
|
||||
Disp L1(3)
|
||||
0→L1(4)
|
||||
7
Task/Arrays/TXR/arrays.txr
Normal file
7
Task/Arrays/TXR/arrays.txr
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@(collect)
|
||||
@line
|
||||
@(bind f @(split-str line ","))
|
||||
@(output)
|
||||
@{f[-1]}@\t@{f[1..-1] "\t"}@\t@{f[0]}
|
||||
@(end)
|
||||
@(end)
|
||||
5
Task/Arrays/TorqueScript/arrays-1.torquescript
Normal file
5
Task/Arrays/TorqueScript/arrays-1.torquescript
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$array[0] = "hi";
|
||||
$array[1] = "hello";
|
||||
|
||||
for(%i=0;%i<2;%i++)
|
||||
echo($array[%i]);
|
||||
5
Task/Arrays/TorqueScript/arrays-2.torquescript
Normal file
5
Task/Arrays/TorqueScript/arrays-2.torquescript
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$array["Greet",0] = "hi";
|
||||
$array["Greet",1] = "hello";
|
||||
|
||||
for(%i=0;%i<2;%i++)
|
||||
echo($array["Greet",%i]);
|
||||
6
Task/Arrays/UNIX-Shell/arrays-1.sh
Normal file
6
Task/Arrays/UNIX-Shell/arrays-1.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
alist=( item1 item2 item3 ) # creates a 3 item array called "alist"
|
||||
declare -a list2 # declare an empty list called "list2"
|
||||
declare -a list3[0] # empty list called "list3"; the subscript is ignored
|
||||
|
||||
# create a 4 item list, with a specific order
|
||||
list5=([3]=apple [2]=cherry [1]=banana [0]=strawberry)
|
||||
1
Task/Arrays/UNIX-Shell/arrays-10.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-10.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist
|
||||
2
Task/Arrays/UNIX-Shell/arrays-2.sh
Normal file
2
Task/Arrays/UNIX-Shell/arrays-2.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
count=${#alist[*]}
|
||||
echo "The number of items in alist is ${#alist[*]}"
|
||||
5
Task/Arrays/UNIX-Shell/arrays-3.sh
Normal file
5
Task/Arrays/UNIX-Shell/arrays-3.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x=0
|
||||
while [[ $x < ${#alist[*]} ]]; do
|
||||
echo "Item $x = ${alist[$x]}"
|
||||
: $((x++))
|
||||
done
|
||||
5
Task/Arrays/UNIX-Shell/arrays-4.sh
Normal file
5
Task/Arrays/UNIX-Shell/arrays-4.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x=${#alist[*]} # start with the number of items in the array
|
||||
while [[ $x > 0 ]]; do # while there are items left
|
||||
: $((x--)) # decrement first, because indexing is zero-based
|
||||
echo "Item $x = ${alist[$x]}" # show the current item
|
||||
done
|
||||
1
Task/Arrays/UNIX-Shell/arrays-5.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-5.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
alist[${#alist[*]}]=new_item
|
||||
10
Task/Arrays/UNIX-Shell/arrays-6.sh
Normal file
10
Task/Arrays/UNIX-Shell/arrays-6.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# shell function to append values to an array
|
||||
# push LIST VALUES ...
|
||||
push() {
|
||||
local var=${1:?'Missing variable name!'}
|
||||
shift
|
||||
eval "\$$var=( \"\${$var[@]}\" \"$@\" )"
|
||||
}
|
||||
|
||||
push alist "one thing to add"
|
||||
push alist many words to add
|
||||
1
Task/Arrays/UNIX-Shell/arrays-7.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-7.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist[0]
|
||||
23
Task/Arrays/UNIX-Shell/arrays-8.sh
Normal file
23
Task/Arrays/UNIX-Shell/arrays-8.sh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# pop ARRAY -- pop the last item on ARRAY and output it
|
||||
|
||||
pop() {
|
||||
local var=${1:?'Missing array name'}
|
||||
local x ; eval "x=\${#$var[*]}"
|
||||
if [[ $x > 0 ]]; then
|
||||
local val ; eval "val=\"\${$var[$((--x))]}\""
|
||||
unset $var[$x]
|
||||
else
|
||||
echo 1>&2 "No items in $var" ; exit 1
|
||||
fi
|
||||
echo "$val"
|
||||
}
|
||||
|
||||
alist=(a b c)
|
||||
pop alist
|
||||
a
|
||||
pop alist
|
||||
b
|
||||
pop alist
|
||||
c
|
||||
pop alist
|
||||
No items in alist
|
||||
1
Task/Arrays/UNIX-Shell/arrays-9.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-9.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist[*]
|
||||
6
Task/Arrays/Vala/arrays-1.vala
Normal file
6
Task/Arrays/Vala/arrays-1.vala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
int[] array = new int[10];
|
||||
|
||||
array[0] = 1;
|
||||
array[1] = 3;
|
||||
|
||||
stdout.printf("%d\n", array[0]);
|
||||
8
Task/Arrays/Vala/arrays-2.vala
Normal file
8
Task/Arrays/Vala/arrays-2.vala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var array = new ArrayList<int> ();
|
||||
|
||||
array.add(1);
|
||||
array.add(3);
|
||||
|
||||
array[0] = 2;
|
||||
|
||||
stdout.printf("%d\n", array[0]);
|
||||
78
Task/Arrays/X86-Assembly/arrays.x86
Normal file
78
Task/Arrays/X86-Assembly/arrays.x86
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
section .text
|
||||
global _start
|
||||
|
||||
_print:
|
||||
mov ebx, 1
|
||||
mov eax, 4
|
||||
int 0x80
|
||||
ret
|
||||
|
||||
_start:
|
||||
;print out our byte array. ergo, String.
|
||||
mov edx, sLen
|
||||
mov ecx, sArray
|
||||
call _print
|
||||
mov edx, f_len
|
||||
mov ecx, f_msg
|
||||
call _print
|
||||
mov edx, 6 ;our array members length.
|
||||
xor ecx, ecx
|
||||
mov ecx, 4
|
||||
;turnicate through the array and print all it's members.
|
||||
;At an offset of *4, each array member is referenced
|
||||
;at 1,2,3 and so on.
|
||||
_out_loops:
|
||||
push ecx
|
||||
mov ecx, [fArray+esi*4]
|
||||
call _print
|
||||
inc esi
|
||||
pop ecx
|
||||
loop _out_loops
|
||||
mov edx, u_len
|
||||
mov ecx, u_msg
|
||||
call _print
|
||||
;Let's populate 'uArray' with something from sArray.
|
||||
;mov edi, uArray
|
||||
mov ecx, 4
|
||||
xor esi, esi
|
||||
_read_loops:
|
||||
push dword [fArray+esi*4]
|
||||
pop dword [uArray+esi*4]
|
||||
inc esi
|
||||
loop _read_loops
|
||||
mov ecx, 4
|
||||
xor esi, esi
|
||||
_out_loops2:
|
||||
push ecx
|
||||
mov ecx, [uArray+esi*4]
|
||||
call _print
|
||||
inc esi
|
||||
pop ecx
|
||||
loop _out_loops2
|
||||
push 0x1
|
||||
mov eax, 1
|
||||
push eax
|
||||
int 0x80
|
||||
|
||||
section .data
|
||||
sArray db 'a','r','r','a','y','s',' ','a','r','e',' ','f','u','n',0xa
|
||||
sLen equ $-sArray
|
||||
|
||||
crap1 db "crap1",0xa
|
||||
crap2 db "crap2",0xa
|
||||
crap3 db "crap3",0xa
|
||||
crap4 db "crap4",0xa
|
||||
|
||||
fArray dd crap1,crap2
|
||||
dd crap3,crap4
|
||||
|
||||
f_msg db "fArray contents",0xa,"----------------------",0xa
|
||||
f_len equ $-f_msg
|
||||
u_msg db "uArray now holds fArray contents.. dumping..",0xa,"----------------------",0xa
|
||||
u_len equ $-u_msg
|
||||
|
||||
section .bss
|
||||
uArray resd 1
|
||||
resd 1
|
||||
resd 1
|
||||
resd 1
|
||||
8
Task/Arrays/XPL0/arrays.xpl0
Normal file
8
Task/Arrays/XPL0/arrays.xpl0
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
include c:\cxpl\codes;
|
||||
char A(10); \creates a static array of 10 bytes, pointed to by "A"
|
||||
char B; \declares a variable for a pointer to a dynamic array
|
||||
[A(3):= 14;
|
||||
B:= Reserve(10); \reserve 10 bytes and point to their starting address
|
||||
B(7):= 28;
|
||||
IntOut(0, A(3)+B(7)); \displays 42
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue