langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
17
Task/Identity-matrix/OCaml/identity-matrix-1.ocaml
Normal file
17
Task/Identity-matrix/OCaml/identity-matrix-1.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
$ ocaml
|
||||
|
||||
# let make_id_matrix n =
|
||||
let m = Array.make_matrix n n 0.0 in
|
||||
for i = 0 to pred n do
|
||||
m.(i).(i) <- 1.0
|
||||
done;
|
||||
(m)
|
||||
;;
|
||||
val make_id_matrix : int -> float array array = <fun>
|
||||
|
||||
# make_id_matrix 4 ;;
|
||||
- : float array array =
|
||||
[| [|1.; 0.; 0.; 0.|];
|
||||
[|0.; 1.; 0.; 0.|];
|
||||
[|0.; 0.; 1.; 0.|];
|
||||
[|0.; 0.; 0.; 1.|] |]
|
||||
13
Task/Identity-matrix/OCaml/identity-matrix-2.ocaml
Normal file
13
Task/Identity-matrix/OCaml/identity-matrix-2.ocaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# let make_id_matrix n =
|
||||
Array.init n (fun i ->
|
||||
Array.init n (fun j ->
|
||||
if i = j then 1.0 else 0.0))
|
||||
;;
|
||||
val make_id_matrix : int -> float array array = <fun>
|
||||
|
||||
# make_id_matrix 4 ;;
|
||||
- : float array array =
|
||||
[| [|1.; 0.; 0.; 0.|];
|
||||
[|0.; 1.; 0.; 0.|];
|
||||
[|0.; 0.; 1.; 0.|];
|
||||
[|0.; 0.; 0.; 1.|] |]
|
||||
1
Task/Identity-matrix/Octave/identity-matrix.octave
Normal file
1
Task/Identity-matrix/Octave/identity-matrix.octave
Normal file
|
|
@ -0,0 +1 @@
|
|||
I = eye(10)
|
||||
30
Task/Identity-matrix/OxygenBasic/identity-matrix.oxy
Normal file
30
Task/Identity-matrix/OxygenBasic/identity-matrix.oxy
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Class SquareMatrix
|
||||
'=================
|
||||
|
||||
double *Cell
|
||||
sys size
|
||||
|
||||
method SetIdentity()
|
||||
indexbase 0
|
||||
sys e,i,j
|
||||
e=size*size
|
||||
for i=0 to <size
|
||||
cell(i*size+j)=1 : j++
|
||||
next
|
||||
end method
|
||||
|
||||
method constructor(sys n)
|
||||
@cell=getmemory n*n*sizeof double
|
||||
size=n
|
||||
end method
|
||||
|
||||
method destructor()
|
||||
freememory @cell
|
||||
end method
|
||||
|
||||
end class
|
||||
|
||||
new SquareMatrix M(8)
|
||||
M.SetIdentity
|
||||
'...
|
||||
del M
|
||||
1
Task/Identity-matrix/PARI-GP/identity-matrix-1.pari
Normal file
1
Task/Identity-matrix/PARI-GP/identity-matrix-1.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
matid(9)
|
||||
1
Task/Identity-matrix/PARI-GP/identity-matrix-2.pari
Normal file
1
Task/Identity-matrix/PARI-GP/identity-matrix-2.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
matrix(9,9,i,j,i==j)
|
||||
6
Task/Identity-matrix/PL-I/identity-matrix.pli
Normal file
6
Task/Identity-matrix/PL-I/identity-matrix.pli
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
identity: procedure (A, n);
|
||||
declare A(n,n) fixed controlled;
|
||||
declare (i,n) fixed binary;
|
||||
allocate A; A = 0;
|
||||
do i = 1 to n; A(i,i) = 1; end;
|
||||
end identity;
|
||||
21
Task/Identity-matrix/Pascal/identity-matrix.pascal
Normal file
21
Task/Identity-matrix/Pascal/identity-matrix.pascal
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
program IdentityMatrix(input, output);
|
||||
|
||||
var
|
||||
matrix: array of array of integer;
|
||||
n, i, j: integer;
|
||||
|
||||
begin
|
||||
write('Size of matrix: ');
|
||||
readln(n);
|
||||
setlength(matrix, n, n);
|
||||
|
||||
for i := 0 to n - 1 do
|
||||
matrix[i,i] := 1;
|
||||
|
||||
for i := 0 to n - 1 do
|
||||
begin
|
||||
for j := 0 to n - 1 do
|
||||
write (matrix[i,j], ' ');
|
||||
writeln;
|
||||
end;
|
||||
end.
|
||||
9
Task/Identity-matrix/Perl-6/identity-matrix-1.pl6
Normal file
9
Task/Identity-matrix/Perl-6/identity-matrix-1.pl6
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
sub identity-matrix($n) {
|
||||
my @id;
|
||||
for ^$n X ^$n -> $i, $j {
|
||||
@id[$i][$j] = +($i == $j);
|
||||
}
|
||||
@id;
|
||||
}
|
||||
|
||||
.say for identity-matrix(5);
|
||||
5
Task/Identity-matrix/Perl-6/identity-matrix-2.pl6
Normal file
5
Task/Identity-matrix/Perl-6/identity-matrix-2.pl6
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
sub identity-matrix($n) {
|
||||
my @id = [0 xx $n] xx $n;
|
||||
@id[$_][$_] = 1 for ^$n;
|
||||
@id;
|
||||
}
|
||||
16
Task/Identity-matrix/PostScript/identity-matrix.ps
Normal file
16
Task/Identity-matrix/PostScript/identity-matrix.ps
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
% n ident [identity-matrix]
|
||||
% create an identity matrix of dimension n*n.
|
||||
% Uses a local dictionary for its one parameter, perhaps overkill.
|
||||
% Constructs arrays of arrays of integers using [], for loops, and stack manipulation.
|
||||
/ident { 1 dict begin /n exch def
|
||||
[
|
||||
1 1 n { % [ i
|
||||
[ exch % [ [ i
|
||||
1 1 n { % [ [ i j
|
||||
1 index eq { 1 }{ 0 } ifelse % [ [ i b
|
||||
exch % [ [ b i
|
||||
} for % [ [ b+ i
|
||||
pop ] % [ [ b+ ]
|
||||
} for % [ [b+]+ ]
|
||||
]
|
||||
end } def
|
||||
37
Task/Identity-matrix/PureBasic/identity-matrix.purebasic
Normal file
37
Task/Identity-matrix/PureBasic/identity-matrix.purebasic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
>Procedure identityMatrix(Array i(2), size) ;valid only for size >= 0
|
||||
;formats array i() as an identity matrix of size x size
|
||||
Dim i(size - 1, size - 1)
|
||||
|
||||
Protected j
|
||||
For j = 0 To size - 1
|
||||
i(j, j) = 1
|
||||
Next
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure displayMatrix(Array a(2))
|
||||
Protected rows = ArraySize(a(), 2), columns = ArraySize(a(), 1)
|
||||
Protected i, j
|
||||
|
||||
For i = 0 To rows
|
||||
For j = 0 To columns
|
||||
Print(RSet(Str(a(i, j)), 3, " "))
|
||||
Next
|
||||
PrintN("")
|
||||
Next
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
Dim i3(0, 0)
|
||||
Dim i4(0, 0)
|
||||
|
||||
identityMatrix(i3(), 3)
|
||||
identityMatrix(i4(), 4)
|
||||
|
||||
displayMatrix(i3())
|
||||
PrintN("")
|
||||
displayMatrix(i4())
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
20
Task/Identity-matrix/Run-BASIC/identity-matrix.run
Normal file
20
Task/Identity-matrix/Run-BASIC/identity-matrix.run
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
' formats array im() of size ims
|
||||
for ims = 4 to 6
|
||||
|
||||
print :print "--- Size: ";ims;" ---"
|
||||
Dim im(ims,ims)
|
||||
|
||||
For i = 1 To ims
|
||||
im(i,i) = 1
|
||||
next
|
||||
|
||||
For row = 1 To ims
|
||||
print "[";
|
||||
cma$ = ""
|
||||
For col = 1 To ims
|
||||
print cma$;im(row, col);
|
||||
cma$ = ", "
|
||||
next
|
||||
print "]"
|
||||
next
|
||||
next ims
|
||||
6
Task/Identity-matrix/Unicon/identity-matrix.unicon
Normal file
6
Task/Identity-matrix/Unicon/identity-matrix.unicon
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
link matrix
|
||||
procedure main(argv)
|
||||
if not (integer(argv[1]) > 0) then stop("Argument must be a positive integer.")
|
||||
matrix1 := identity_matrix(argv[1], argv[1])
|
||||
write_matrix(&output,matrix1)
|
||||
end
|
||||
17
Task/Identity-matrix/XPL0/identity-matrix.xpl0
Normal file
17
Task/Identity-matrix/XPL0/identity-matrix.xpl0
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
include c:\cxpl\codes;
|
||||
def IntSize = 4; \number of bytes in an integer
|
||||
int Matrix, Size, I, J;
|
||||
|
||||
[Text(0, "Size: "); Size:= IntIn(0);
|
||||
Matrix:= Reserve(Size*IntSize); \reserve memory for 2D integer array
|
||||
for I:= 0 to Size-1 do
|
||||
Matrix(I):= Reserve(Size*IntSize);
|
||||
for J:= 0 to Size-1 do \make array an identity matrix
|
||||
for I:= 0 to Size-1 do
|
||||
Matrix(I,J):= if I=J then 1 else 0;
|
||||
for J:= 0 to Size-1 do \display the result
|
||||
[for I:= 0 to Size-1 do
|
||||
[IntOut(0, Matrix(I,J)); ChOut(0, ^ )];
|
||||
CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue