new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
15
Task/Arrays/ACL2/arrays.acl2
Normal file
15
Task/Arrays/ACL2/arrays.acl2
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;; Create an array and store it in array-example
|
||||
(assign array-example
|
||||
(compress1 'array-example
|
||||
(list '(:header :dimensions (10)
|
||||
:maximum-length 11))))
|
||||
|
||||
;; Set a[5] to 22
|
||||
(assign array-example
|
||||
(aset1 'array-example
|
||||
(@ array-example)
|
||||
5
|
||||
22))
|
||||
|
||||
;; Get a[5]
|
||||
(aref1 'array-example (@ array-example) 5)
|
||||
43
Task/Arrays/Ada/arrays.ada
Normal file
43
Task/Arrays/Ada/arrays.ada
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
procedure Array_Test is
|
||||
|
||||
A, B : array (1..20) of Integer;
|
||||
|
||||
-- Ada array indices may begin at any value, not just 0 or 1
|
||||
C : array (-37..20) of integer
|
||||
|
||||
-- Ada arrays may be indexed by enumerated types, which are
|
||||
-- discrete non-numeric types
|
||||
type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
|
||||
type Activities is (Work, Fish);
|
||||
type Daily_Activities is array(Days) of Activities;
|
||||
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);
|
||||
|
||||
-- Or any numeric type
|
||||
type Fingers is range 1..4; -- exclude thumb
|
||||
type Fingers_Extended_Type is array(fingers) of Boolean;
|
||||
Fingers_Extended : Fingers_Extended_Type;
|
||||
|
||||
-- Array types may be unconstrained. The variables of the type
|
||||
-- must be constrained
|
||||
type Arr is array (Integer range <>) of Integer;
|
||||
Uninitialized : Arr (1 .. 10);
|
||||
Initialized_1 : Arr (1 .. 20) := (others => 1);
|
||||
Initialized_2 : Arr := (1 .. 30 => 2);
|
||||
Const : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
|
||||
Centered : Arr (-50..50) := (0 => 1, Others => 0);
|
||||
|
||||
Result : Integer
|
||||
begin
|
||||
|
||||
A := (others => 0); -- Assign whole array
|
||||
B := (1 => 1, 2 => 1, 3 => 2, others => 0);
|
||||
-- Assign whole array, different values
|
||||
A (1) := -1; -- Assign individual element
|
||||
A (2..4) := B (1..3); -- Assign a slice
|
||||
A (3..5) := (2, 4, -1); -- Assign a constant slice
|
||||
A (3..5) := A (4..6); -- It is OK to overlap slices when assigned
|
||||
|
||||
Fingers_Extended'First := False; -- Set first element of array
|
||||
Fingers_Extended'Last := False; -- Set last element of array
|
||||
|
||||
end Array_Test;
|
||||
2
Task/Arrays/BASIC/arrays-1.bas
Normal file
2
Task/Arrays/BASIC/arrays-1.bas
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
OPTION BASE 1
|
||||
DIM myArray(100) AS INTEGER
|
||||
2
Task/Arrays/C/arrays-1.c
Normal file
2
Task/Arrays/C/arrays-1.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
int myArray2[10] = { 1, 2, 0 }; /* the rest of elements get the value 0 */
|
||||
float myFloats[] ={1.2, 2.5, 3.333, 4.92, 11.2, 22.0 }; /* automatically sizes */
|
||||
8
Task/Arrays/CoffeeScript/arrays-1.coffee
Normal file
8
Task/Arrays/CoffeeScript/arrays-1.coffee
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
array1 = []
|
||||
array1[0] = "Dillenidae"
|
||||
array1[1] = "animus"
|
||||
array1[2] = "Kona"
|
||||
alert "Elements of array1: " + array1 # Dillenidae,animus,Kona
|
||||
|
||||
array2 = ["Cepphus", "excreta", "Gansu"]
|
||||
alert "Value of array2[1]: " + array2[1] # excreta
|
||||
7
Task/Arrays/Forth/arrays-1.fth
Normal file
7
Task/Arrays/Forth/arrays-1.fth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
create MyArray 1 , 2 , 3 , 4 , 5 , 5 cells allot
|
||||
here constant MyArrayEnd
|
||||
|
||||
30 MyArray 7 cells + !
|
||||
MyArray 7 cells + @ . \ 30
|
||||
|
||||
: .array MyArrayEnd MyArray do I @ . cell +loop ;
|
||||
1
Task/Arrays/Fortran/arrays-1.f
Normal file
1
Task/Arrays/Fortran/arrays-1.f
Normal file
|
|
@ -0,0 +1 @@
|
|||
integer a (10)
|
||||
3
Task/Arrays/Java/arrays-1.java
Normal file
3
Task/Arrays/Java/arrays-1.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
int[] array = new int[10]; //optionally, replace "new int[10]" with a braced list of ints like "{1, 2, 3}"
|
||||
array[0] = 42;
|
||||
System.out.println(array[3]);
|
||||
2
Task/Arrays/PHP/arrays-1.php
Normal file
2
Task/Arrays/PHP/arrays-1.php
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$NumberArray = array(0, 1, 2, 3, 4, 5, 6);
|
||||
$LetterArray = array("a", "b", "c", "d", "e", "f");
|
||||
2
Task/Arrays/PicoLisp/arrays-1.l
Normal file
2
Task/Arrays/PicoLisp/arrays-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(setq A '((1 2 3) (a b c) ((d e) NIL 777))) # Create a 3x3 structure
|
||||
(mapc println A) # Show it
|
||||
9
Task/Arrays/Prolog/arrays-1.pro
Normal file
9
Task/Arrays/Prolog/arrays-1.pro
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
singleassignment:-
|
||||
functor(Array,array,100), % create a term with 100 free Variables as arguments
|
||||
% index of arguments start at 1
|
||||
arg(1 ,Array,a), % put an a at position 1
|
||||
arg(12,Array,b), % put an b at position 12
|
||||
arg(1 ,Array,Value1), % get the value at position 1
|
||||
print(Value1),nl, % will print Value1 and therefore a followed by a newline
|
||||
arg(4 ,Array,Value2), % get the value at position 4 which is a free Variable
|
||||
print(Value2),nl. % will print that it is a free Variable followed by a newline
|
||||
8
Task/Arrays/Python/arrays-1.py
Normal file
8
Task/Arrays/Python/arrays-1.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
array = []
|
||||
|
||||
array.append(1)
|
||||
array.append(3)
|
||||
|
||||
array[0] = 2
|
||||
|
||||
print array[0]
|
||||
9
Task/Arrays/REXX/arrays-1.rexx
Normal file
9
Task/Arrays/REXX/arrays-1.rexx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*REXX program demonstrates array usage. */
|
||||
a.='not found' /*value for all a.xxx (so far). */
|
||||
|
||||
do j=1 to 100 /*start at 1, define 100 array elements.*/
|
||||
a.j=-j*100 /*define element as negative J thousand.*/
|
||||
end /*the above defines 100 elements. */
|
||||
|
||||
say 'element 50 is:' a.50
|
||||
say 'element 3000 is:' a.3000
|
||||
11
Task/Arrays/Scala/arrays-1.scala
Normal file
11
Task/Arrays/Scala/arrays-1.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Create a new integer array with capacity 10
|
||||
val a = new Array[Int](10)
|
||||
|
||||
// Create a new array containing specified items
|
||||
val b = Array("foo", "bar", "baz")
|
||||
|
||||
// Assign a value to element zero
|
||||
a(0) = 42
|
||||
|
||||
// Retrieve item at element 2
|
||||
val c = b(2)
|
||||
1
Task/Arrays/Smalltalk/arrays-1.st
Normal file
1
Task/Arrays/Smalltalk/arrays-1.st
Normal file
|
|
@ -0,0 +1 @@
|
|||
#(1 2 3 'four' 5.0 true false nil (10 20) $a)
|
||||
8
Task/Arrays/Tcl/arrays-1.tcl
Normal file
8
Task/Arrays/Tcl/arrays-1.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set ary {}
|
||||
|
||||
lappend ary 1
|
||||
lappend ary 3
|
||||
|
||||
lset ary 0 2
|
||||
|
||||
puts [lindex $ary 0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue