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 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return

View file

@ -0,0 +1,5 @@
let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;

View file

@ -0,0 +1,5 @@
let nbr1 = read_int ();;
let nbr2 = read_int ();;
let arr = Bigarray.Array2.create Bigarray.float32 Bigarray.c_layout nbr1 nbr2 ;;
arr.{0,0} <- 3.5;;
print_float arr.{0,0}; print_newline ();;

View file

@ -0,0 +1,23 @@
use IO;
bundle Default {
class TwoDee {
function : Main(args : System.String[]) ~ Nil {
DoIt();
}
function : native : DoIt() ~ Nil {
Console->GetInstance()->Print("Enter x: ");
x := Console->GetInstance()->ReadString()->ToInt();
Console->GetInstance()->Print("Enter y: ");
y := Console->GetInstance()->ReadString()->ToInt();
if(x > 0 & y > 0) {
array : Int[,] := Int->New[x, y];
array[0, 0] := 2;
array[0, 0]->PrintLine();
};
}
}
}

View file

@ -0,0 +1,28 @@
#import <Foundation/Foundation.h>
int main()
{
int num1, num2, i, j;
NSMutableArray *arr;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
scanf("%d %d", &num1, &num2);
NSLog(@"%d %d", num1, num2);
arr = [NSMutableArray arrayWithCapacity: (num1*num2)];
// initialize it with 0s
for(i=0; i < (num1*num2); i++) [arr addObject: [NSNumber numberWithInt: 0]];
// replace 0s with something more interesting
for(i=0; i < num1; i++) {
for(j=0; j < num2; j++) {
[arr replaceObjectAtIndex: (i*num2+j) withObject: [NSNumber numberWithInt: (i*j)]];
}
}
// access a value: i*num2+j, where i,j are the indexes for the bidimensional array
NSLog(@"%@", [arr objectAtIndex: (1*num2+3)]);
[pool release];
return 0;
}

View file

@ -0,0 +1,15 @@
declare
%% Read width and height from stdin
class TextFile from Open.file Open.text end
StdIn = {New TextFile init(name:stdin)}
Width = {String.toInt {StdIn getS($)}}
Height = {String.toInt {StdIn getS($)}}
%% create array
Arr = {Array.new 1 Width unit}
in
for X in 1..Width do
Arr.X := {Array.new 1 Height 0}
end
%% set and read element
Arr.1.1 := 42
{Show Arr.1.1}

View file

@ -0,0 +1,5 @@
tmp(m,n)={
my(M=matrix(m,n,i,j,0));
M[1,1]=1;
M[1,1]
};

View file

@ -0,0 +1,12 @@
/* First way using a controlled variable: */
declare A(*,*) float controlled;
get list (m, n);
allocate A(m,n);
get list (A);
put skip list (A);
/* The array remains allocated until the program terminates, */
/* or until explicitly destroyed using a FREE statement. */
free A;

View file

@ -0,0 +1,2 @@
6.00000E+0000 5.00000E+0000 4.00000E+0000 3.00000E+0000 2.00000E+0000
1.00000E+0000

View file

@ -0,0 +1,10 @@
/* Second way using a BEGIN block: */
get list (m, n);
begin;
declare A(m, n) float;
get list (A);
put skip list (A);
end;
/* The array is automatically destroyed when the block terminates. */

View file

@ -0,0 +1,3 @@
1.00000E+0000 2.00000E+0000 3.00000E+0000 4.00000E+0000 5.00000E+0000
6.00000E+0000 7.00000E+0000 8.00000E+0000 9.00000E+0000 1.00000E+0001
1.10000E+0001 1.20000E+0002

View file

@ -0,0 +1,11 @@
/* Third way using a PROCEDURE block: */
get list (m, n);
call S (m, n);
S: procedure (m, n);
declare A(m, n) float;
get list (A);
put skip list (A);
end S;
/* The array is automatically destroyed when the procedure terminates. */

View file

@ -0,0 +1,4 @@
1.00000E+0000 2.00000E+0000 3.00000E+0000 4.00000E+0000 5.00000E+0000
6.00000E+0000 7.00000E+0000 8.00000E+0000 9.00000E+0000 1.00000E+0001
1.10000E+0001 1.20000E+0001 1.30000E+0001 1.40000E+0001 1.50000E+0001
1.60000E+0001 1.70000E+0001 1.80000E+0001 1.90000E+0001 2.00000E+0001

View file

@ -0,0 +1,26 @@
program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
{ read values }
readln(d1, d2);
{ create array }
new(data, d1, d2);
{ write element }
data^[1,1] := 3.5;
{ output element }
writeln(data^[1,1]);
{ get rid of array }
dispose(data);
end.

View file

@ -0,0 +1,4 @@
my ($major,$minor) = prompt("Dimensions? ").comb(/\d+/);
my @array := [ for ^$major { [ for ^$minor {'@'} ] } ];
@array[ pick 1, ^$major ][ pick 1, ^$minor ] = ' ';
.say for @array;

View file

@ -0,0 +1,7 @@
$ ./two-dee
Dimensions? 5x35
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

View file

@ -0,0 +1,12 @@
vars itemrep;
incharitem(charin) -> itemrep;
;;; Read sizes
vars n1 = itemrep(), n2= itemrep();
;;; Create 0 based array
vars ar = newarray([0 ^(n1 - 1) 0 ^(n2 - 1)], 0);
;;; Set element value
15 -> ar(0, 0);
;;; Print element value
ar(0,0) =>
;;; Make sure array is unreferenced
0 -> ar;

View file

@ -0,0 +1,17 @@
If OpenConsole()
Define x, y
Print("Input X-Size: ")
x = Val(Input())
Print("Input Y-Size: ")
y = Val(Input())
Dim a(x,y) ; Should really check if x & y are larger then 1, but that would be less fun....
a(1,1)=Random(1000)
PrintN("a(1,1)= " + Str(a(1,1)) )
PrintN("Press ENTER to exit"):Input()
End ; Close down and let PureBasic delete the Console and all variables.
EndIf

View 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)

View file

@ -0,0 +1,21 @@
* # Get user X,Y dimensions
output = 'Enter X,Y:'; xy = trim(input)
xy break(',') . x ',' rem . y
* # Define and create array, 1-based
arr = array(x ',' y) ;* Or arr = array(xy)
* # Display array prototype
output = 'Prototype: ' prototype(arr)
* # Assign elements, angle or square brackets
* # Same array can hold ints, strings, etc.
arr<x,y> = 99; arr[1,1] = 'dog'
* # Display elements
output = 'arr[' xy '] = ' arr[x,y]
output = 'arr[1,1] = ' arr[1,1]
* # Release array for garbage collection
arr =
end

View file

@ -0,0 +1,16 @@
$ include "seed7_05.s7i";
const proc: main is func
local
var integer: numRows is 0;
var integer: numCols is 0;
var array array integer: anArray is 0 times 0 times 0;
begin
write("Give me the numer of rows: ");
readln(numRows);
write("Give me the numer of columns: ");
readln(numCols);
anArray := numRows times numCols times 0;
anArray[1][1] := 3;
writeln("The number at place [1, 1] is " <& anArray[1][1]);
end func;

View file

@ -0,0 +1,5 @@
val nbr1 = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn);
val nbr2 = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn);
val array = Array2.array (nbr1, nbr2, 0.0);
Array2.update (array, 0, 0, 3.5);
print (Real.toString (Array2.sub (array, 0, 0)) ^ "\n");

View file

@ -0,0 +1,14 @@
[ ( x y -- address )
cells malloc >r
dup cells >r
[ r> r> r> 2dup >r >r swap malloc swap i swap array.put >r ] iterate
r> r> nip
] is 2D-array
[ ( a b address -- value )
array.get array.get
] is 2D-get-element
[ ( value a b address -- )
array.get array.put
] is 2D-put-element

View file

@ -0,0 +1,4 @@
5 5 2D-array >r #! Create an array and save the pointer to it
10 2 3 r@ 2D-put-element #! Set element 2,3 to 10
2 3 r@ 2D-get-element #! Get the element at 2,3
r> drop #! Discard the pointer to the array

View file

@ -0,0 +1,9 @@
inc c:\cxpl\codes; \(command words can be abbreviated to first 3 letters)
def IntSize=4; \number of bytes in an integer (2 or 4 depending on version)
int X, Y, A, I;
[X:= IntIn(0); Y:= IntIn(0); \get 2 dimensions from user
A:= Reserve(X*IntSize);
for I:= 0 to X-1 do A(I):= Reserve(Y*IntSize);
A(X/2, Y/2):= X+Y;
IntOut(0, A(X/2, Y/2)); CrLf(0);
]