update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
11
Task/Identity-matrix/Erlang/identity-matrix.erl
Normal file
11
Task/Identity-matrix/Erlang/identity-matrix.erl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%% Identity Matrix in Erlang for the Rosetta Code Wiki.
|
||||
%% Implemented by Arjun Sunel
|
||||
|
||||
-module(identity_matrix).
|
||||
-export([square_matrix/2 , identity/1]).
|
||||
|
||||
square_matrix(Size, Elements) ->
|
||||
[[Elements(Column, Row) || Column <- lists:seq(1, Size)] || Row <- lists:seq(1, Size)].
|
||||
|
||||
identity(Size) ->
|
||||
square_matrix(Size, fun(Column, Row) -> case Column of Row -> 1; _ -> 0 end end).
|
||||
1
Task/Identity-matrix/Julia/identity-matrix-1.julia
Normal file
1
Task/Identity-matrix/Julia/identity-matrix-1.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
eye(3)
|
||||
1
Task/Identity-matrix/Julia/identity-matrix-2.julia
Normal file
1
Task/Identity-matrix/Julia/identity-matrix-2.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
eye(int(readline(STDIN)))
|
||||
1
Task/Identity-matrix/Julia/identity-matrix-3.julia
Normal file
1
Task/Identity-matrix/Julia/identity-matrix-3.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
eye(2,3)
|
||||
32
Task/Identity-matrix/Objeck/identity-matrix.objeck
Normal file
32
Task/Identity-matrix/Objeck/identity-matrix.objeck
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
class IdentityMatrix {
|
||||
function : Matrix(n : Int) ~ Int[,] {
|
||||
array := Int->New[n,n];
|
||||
|
||||
for(row:=0; row<n; row+=1;){
|
||||
for(col:=0; col<n; col+=1;){
|
||||
if(row = col){
|
||||
array[row, col] := 1;
|
||||
}
|
||||
else{
|
||||
array[row,col] := 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
return array;
|
||||
}
|
||||
|
||||
function : PrintMatrix(array : Int[,]) ~ Nil {
|
||||
sizes := array->Size();
|
||||
for(row:=0; row<sizes[0]; row+=1;){
|
||||
for(col:=0; col<sizes[1]; col+=1;){
|
||||
value := array[row,col];
|
||||
"{$value} \t"->Print();
|
||||
};
|
||||
'\n'->PrintLine();
|
||||
};
|
||||
}
|
||||
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
PrintMatrix(Matrix(5));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
def identity(size)
|
||||
size.times.map { |i| size.times.map { |j| i == j ? 1 : 0 } }
|
||||
Array.new(size){|i| Array.new(size){|j| i==j ? 1 : 0}}
|
||||
end
|
||||
|
||||
[4,5,6].each do |size|
|
||||
puts size, identity(size.to_i).map {|r| r.to_s}, ""
|
||||
puts size, identity(size).map {|r| r.to_s}, ""
|
||||
end
|
||||
|
|
|
|||
33
Task/Identity-matrix/Seed7/identity-matrix.seed7
Normal file
33
Task/Identity-matrix/Seed7/identity-matrix.seed7
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const type: matrix is array array integer;
|
||||
|
||||
const func matrix: identity (in integer: size) is func
|
||||
result
|
||||
var matrix: identity is matrix.value;
|
||||
local
|
||||
var integer: index is 0;
|
||||
begin
|
||||
identity := size times size times 0;
|
||||
for index range 1 to size do
|
||||
identity[index][index] := 1;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const proc: writeMat (in matrix: a) is func
|
||||
local
|
||||
var integer: i is 0;
|
||||
var integer: num is 0;
|
||||
begin
|
||||
for key i range a do
|
||||
for num range a[i] do
|
||||
write(num lpad 2);
|
||||
end for;
|
||||
writeln;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeMat(identity(6));
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue