Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,4 +0,0 @@
|
|||
-- As prototyped in the Generic_Real_Arrays specification:
|
||||
-- function Unit_Matrix (Order : Positive; First_1, First_2 : Integer := 1) return Real_Matrix;
|
||||
-- For the task:
|
||||
mat : Real_Matrix := Unit_Matrix(5);
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
type Matrix is array(Positive Range <>, Positive Range <>) of Integer;
|
||||
mat : Matrix(1..5,1..5) := (others => (others => 0));
|
||||
-- then after the declarative section:
|
||||
for i in mat'Range(1) loop mat(i,i) := 1; end loop;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
beads 1 program 'Identity matrix'
|
||||
|
||||
var
|
||||
id : array^2 of num
|
||||
n = 5
|
||||
|
||||
id : array^2 of num
|
||||
n = 5
|
||||
|
||||
calc main_init
|
||||
loop from:1 to:n index:i
|
||||
loop from:1 to:n index:j
|
||||
id[i,j] = 1 if i == j else 0
|
||||
loop from:1 to:n index:i
|
||||
loop from:1 to:n index:j
|
||||
id[i,j] = 1 if i == j else 0
|
||||
|
|
|
|||
|
|
@ -2,34 +2,34 @@ MODULE Algebras;
|
|||
IMPORT StdLog,Strings;
|
||||
|
||||
TYPE
|
||||
Matrix = POINTER TO ARRAY OF ARRAY OF INTEGER;
|
||||
|
||||
Matrix = POINTER TO ARRAY OF ARRAY OF INTEGER;
|
||||
|
||||
PROCEDURE NewIdentityMatrix(n: INTEGER): Matrix;
|
||||
VAR
|
||||
m: Matrix;
|
||||
i: INTEGER;
|
||||
m: Matrix;
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
NEW(m,n,n);
|
||||
FOR i := 0 TO n - 1 DO
|
||||
m[i,i] := 1;
|
||||
END;
|
||||
RETURN m;
|
||||
NEW(m,n,n);
|
||||
FOR i := 0 TO n - 1 DO
|
||||
m[i,i] := 1;
|
||||
END;
|
||||
RETURN m;
|
||||
END NewIdentityMatrix;
|
||||
|
||||
PROCEDURE Show(m: Matrix);
|
||||
VAR
|
||||
i,j: INTEGER;
|
||||
i,j: INTEGER;
|
||||
BEGIN
|
||||
FOR i := 0 TO LEN(m,0) - 1 DO
|
||||
FOR j := 0 TO LEN(m,1) - 1 DO
|
||||
StdLog.Int(m[i,j]);
|
||||
END;
|
||||
StdLog.Ln
|
||||
END
|
||||
FOR i := 0 TO LEN(m,0) - 1 DO
|
||||
FOR j := 0 TO LEN(m,1) - 1 DO
|
||||
StdLog.Int(m[i,j]);
|
||||
END;
|
||||
StdLog.Ln
|
||||
END
|
||||
END Show;
|
||||
|
||||
PROCEDURE Do*;
|
||||
BEGIN
|
||||
Show(NewIdentityMatrix(5));
|
||||
Show(NewIdentityMatrix(5));
|
||||
END Do;
|
||||
END Algebras.
|
||||
|
|
|
|||
|
|
@ -1,61 +1,61 @@
|
|||
class
|
||||
APPLICATION
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
ARGUMENTS
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
make
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
dim : INTEGER -- Dimension of the identity matrix
|
||||
do
|
||||
from dim := 1 until dim > 10 loop
|
||||
print_matrix( identity_matrix(dim) )
|
||||
dim := dim + 1
|
||||
io.new_line
|
||||
end
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
dim : INTEGER -- Dimension of the identity matrix
|
||||
do
|
||||
from dim := 1 until dim > 10 loop
|
||||
print_matrix( identity_matrix(dim) )
|
||||
dim := dim + 1
|
||||
io.new_line
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
identity_matrix(dim : INTEGER) : ARRAY2[REAL_64]
|
||||
identity_matrix(dim : INTEGER) : ARRAY2[REAL_64]
|
||||
|
||||
require
|
||||
dim > 0
|
||||
local
|
||||
matrix : ARRAY2[REAL_64]
|
||||
i : INTEGER
|
||||
do
|
||||
require
|
||||
dim > 0
|
||||
local
|
||||
matrix : ARRAY2[REAL_64]
|
||||
i : INTEGER
|
||||
do
|
||||
|
||||
create matrix.make_filled (0.0, dim, dim)
|
||||
from i := 1 until i > dim loop
|
||||
matrix.put(1.0, i, i)
|
||||
i := i + 1
|
||||
end
|
||||
create matrix.make_filled (0.0, dim, dim)
|
||||
from i := 1 until i > dim loop
|
||||
matrix.put(1.0, i, i)
|
||||
i := i + 1
|
||||
end
|
||||
|
||||
Result := matrix
|
||||
end
|
||||
Result := matrix
|
||||
end
|
||||
|
||||
print_matrix(matrix : ARRAY2[REAL_64])
|
||||
local
|
||||
i, j : INTEGER
|
||||
do
|
||||
from i := 1 until i > matrix.height loop
|
||||
print("[ ")
|
||||
from j := 1 until j > matrix.width loop
|
||||
print(matrix.item (i, j))
|
||||
print(" ")
|
||||
j := j + 1
|
||||
end
|
||||
print("]%N")
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
print_matrix(matrix : ARRAY2[REAL_64])
|
||||
local
|
||||
i, j : INTEGER
|
||||
do
|
||||
from i := 1 until i > matrix.height loop
|
||||
print("[ ")
|
||||
from j := 1 until j > matrix.width loop
|
||||
print(matrix.item (i, j))
|
||||
print(" ")
|
||||
j := j + 1
|
||||
end
|
||||
print("]%N")
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import extensions;
|
|||
import system'routines;
|
||||
import system'collections;
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var n := console.write("Enter the matrix size:").readLine().toInt();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
default {
|
||||
state_entry() {
|
||||
llListen(PUBLIC_CHANNEL, "", llGetOwner(), "");
|
||||
llOwnerSay("Please Enter a Dimension for an Identity Matrix.");
|
||||
}
|
||||
listen(integer iChannel, string sName, key kId, string sMessage) {
|
||||
llOwnerSay("You entered "+sMessage+".");
|
||||
list lMatrix = [];
|
||||
integer x = 0;
|
||||
integer n = (integer)sMessage;
|
||||
for(x=0 ; x<n*n ; x++) {
|
||||
lMatrix += [(integer)(((x+1)%(n+1))==1)];
|
||||
}
|
||||
//llOwnerSay("["+llList2CSV(lMatrix)+"]");
|
||||
for(x=0 ; x<n ; x++) {
|
||||
llOwnerSay("["+llList2CSV(llList2ListStrided(lMatrix, x*n, (x+1)*n-1, 1))+"]");
|
||||
}
|
||||
}
|
||||
state_entry() {
|
||||
llListen(PUBLIC_CHANNEL, "", llGetOwner(), "");
|
||||
llOwnerSay("Please Enter a Dimension for an Identity Matrix.");
|
||||
}
|
||||
listen(integer iChannel, string sName, key kId, string sMessage) {
|
||||
llOwnerSay("You entered "+sMessage+".");
|
||||
list lMatrix = [];
|
||||
integer x = 0;
|
||||
integer n = (integer)sMessage;
|
||||
for(x=0 ; x<n*n ; x++) {
|
||||
lMatrix += [(integer)(((x+1)%(n+1))==1)];
|
||||
}
|
||||
//llOwnerSay("["+llList2CSV(lMatrix)+"]");
|
||||
for(x=0 ; x<n ; x++) {
|
||||
llOwnerSay("["+llList2CSV(llList2ListStrided(lMatrix, x*n, (x+1)*n-1, 1))+"]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
function identity($length) {
|
||||
return array_map(function($key, $value) {$value[$key] = 1; return $value;}, range(0, $length-1),
|
||||
array_fill(0, $length, array_fill(0,$length, 0)));
|
||||
return array_map(function($key, $value) {$value[$key] = 1; return $value;}, range(0, $length-1),
|
||||
array_fill(0, $length, array_fill(0,$length, 0)));
|
||||
}
|
||||
function print_identity($identity) {
|
||||
echo implode(PHP_EOL, array_map(function ($value) {return implode(' ', $value);}, $identity));
|
||||
echo implode(PHP_EOL, array_map(function ($value) {return implode(' ', $value);}, $identity));
|
||||
}
|
||||
print_identity(identity(10));
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
function identity($n) {
|
||||
0..($n-1) | foreach{$row = @(0) * $n; $row[$_] = 1; ,$row}
|
||||
}
|
||||
function show($a) { $a | foreach{ "$_"} }
|
||||
$array = identity 4
|
||||
show $array
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
$array[0][0]
|
||||
$array[0][1]
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
%rotates one list clockwise by one integer
|
||||
rotate(Int,List,Rotated) :-
|
||||
integer(Int),
|
||||
length(Suff,Int),
|
||||
append(Pre,Suff,List),
|
||||
append(Suff,Pre,Rotated).
|
||||
integer(Int),
|
||||
length(Suff,Int),
|
||||
append(Pre,Suff,List),
|
||||
append(Suff,Pre,Rotated).
|
||||
%rotates a list of lists by a list of integers
|
||||
rotate(LoInts,LoLists,Rotated) :-
|
||||
is_list(LoInts),
|
||||
maplist(rotate,LoInts,LoLists,Rotated).
|
||||
is_list(LoInts),
|
||||
maplist(rotate,LoInts,LoLists,Rotated).
|
||||
|
||||
%helper function
|
||||
append_(Suff,Pre,List) :-
|
||||
append([Pre],Suff,List).
|
||||
append([Pre],Suff,List).
|
||||
idmatrix(N,IdMatrix):-
|
||||
%make an N length list of 1s and append with N-1 0s
|
||||
length(Ones,N),
|
||||
maplist(=(1),Ones),
|
||||
succ(N0,N),
|
||||
length(Zeros,N0),
|
||||
maplist(=(0),Zeros),
|
||||
maplist(append_(Zeros),Ones,M),
|
||||
%create the offsets at rotate each row
|
||||
numlist(0,N0,Offsets),
|
||||
rotate(Offsets,M,IdMatrix).
|
||||
%make an N length list of 1s and append with N-1 0s
|
||||
length(Ones,N),
|
||||
maplist(=(1),Ones),
|
||||
succ(N0,N),
|
||||
length(Zeros,N0),
|
||||
maplist(=(0),Zeros),
|
||||
maplist(append_(Zeros),Ones,M),
|
||||
%create the offsets at rotate each row
|
||||
numlist(0,N0,Offsets),
|
||||
rotate(Offsets,M,IdMatrix).
|
||||
|
||||
main :-
|
||||
idmatrix(5,I),
|
||||
maplist(writeln,I).
|
||||
idmatrix(5,I),
|
||||
maplist(writeln,I).
|
||||
|
|
|
|||
|
|
@ -18,30 +18,30 @@ LayoutButtonRow = list(size)
|
|||
app = new qApp
|
||||
{
|
||||
win = new qWidget() {
|
||||
setWindowTitle('Identity Matrix')
|
||||
move(500,100)
|
||||
reSize(600,600)
|
||||
winheight = win.height()
|
||||
fontSize = 18 + (winheight / 100)
|
||||
setWindowTitle('Identity Matrix')
|
||||
move(500,100)
|
||||
reSize(600,600)
|
||||
winheight = win.height()
|
||||
fontSize = 18 + (winheight / 100)
|
||||
|
||||
LayoutButtonMain = new QVBoxLayout()
|
||||
LayoutButtonMain.setSpacing(C_Spacing)
|
||||
LayoutButtonMain.setContentsmargins(0,0,0,0)
|
||||
LayoutButtonMain = new QVBoxLayout()
|
||||
LayoutButtonMain.setSpacing(C_Spacing)
|
||||
LayoutButtonMain.setContentsmargins(0,0,0,0)
|
||||
|
||||
for Row = 1 to size
|
||||
LayoutButtonRow[Row] = new QHBoxLayout() {
|
||||
setSpacing(C_Spacing)
|
||||
setContentsmargins(0,0,0,0)
|
||||
}
|
||||
for Col = 1 to size
|
||||
Button[Row][Col] = new QPushButton(win) {
|
||||
for Row = 1 to size
|
||||
LayoutButtonRow[Row] = new QHBoxLayout() {
|
||||
setSpacing(C_Spacing)
|
||||
setContentsmargins(0,0,0,0)
|
||||
}
|
||||
for Col = 1 to size
|
||||
Button[Row][Col] = new QPushButton(win) {
|
||||
setSizePolicy(1,1)
|
||||
}
|
||||
|
||||
LayoutButtonRow[Row].AddWidget(Button[Row][Col])
|
||||
next
|
||||
LayoutButtonMain.AddLayout(LayoutButtonRow[Row])
|
||||
next
|
||||
}
|
||||
|
||||
LayoutButtonRow[Row].AddWidget(Button[Row][Col])
|
||||
next
|
||||
LayoutButtonMain.AddLayout(LayoutButtonRow[Row])
|
||||
next
|
||||
LayoutDataRow1 = new QHBoxLayout() { setSpacing(C_Spacing) setContentsMargins(0,0,0,0) }
|
||||
LayoutButtonMain.AddLayout(LayoutDataRow1)
|
||||
setLayout(LayoutButtonMain)
|
||||
|
|
@ -61,6 +61,6 @@ func pBegin()
|
|||
Button[Row][Col].setStyleSheet(C_ButtonBlueStyle)
|
||||
Button[Row][Col].settext("0")
|
||||
ok
|
||||
next
|
||||
next
|
||||
next
|
||||
score = 0
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
(define (identity n)
|
||||
(letrec
|
||||
((uvec
|
||||
(lambda (m i acc)
|
||||
(if (= i n)
|
||||
acc
|
||||
(uvec m (+ i 1)
|
||||
(cons (if (= i m) 1 0) acc)))))
|
||||
(lambda (m i acc)
|
||||
(if (= i n)
|
||||
acc
|
||||
(uvec m (+ i 1)
|
||||
(cons (if (= i m) 1 0) acc)))))
|
||||
(idgen
|
||||
(lambda (i acc)
|
||||
(if (= i n)
|
||||
acc
|
||||
(idgen (+ i 1)
|
||||
(cons (uvec i 0 '()) acc))))))
|
||||
(lambda (i acc)
|
||||
(if (= i n)
|
||||
acc
|
||||
(idgen (+ i 1)
|
||||
(cons (uvec i 0 '()) acc))))))
|
||||
(idgen 0 '())))
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
set matrix to buildIdentityMatrix(3)
|
||||
|
||||
repeat for each item in matrix
|
||||
put it
|
||||
put it
|
||||
end repeat
|
||||
|
||||
set matrix to buildIdentityMatrix(17)
|
||||
|
||||
repeat for each item in matrix
|
||||
put it
|
||||
put it
|
||||
end repeat
|
||||
|
||||
function buildIdentityMatrix matrixSize
|
||||
set matrixList to ()
|
||||
repeat matrixSize times
|
||||
set rowMatrixIndex to the counter
|
||||
set rowMatrix to ()
|
||||
repeat matrixSize times
|
||||
if the counter equals rowMatrixIndex
|
||||
insert 1 after rowMatrix
|
||||
else
|
||||
insert 0 after rowMatrix
|
||||
end if
|
||||
end repeat
|
||||
insert rowMatrix nested after matrixList
|
||||
end repeat
|
||||
return matrixList
|
||||
set matrixList to ()
|
||||
repeat matrixSize times
|
||||
set rowMatrixIndex to the counter
|
||||
set rowMatrix to ()
|
||||
repeat matrixSize times
|
||||
if the counter equals rowMatrixIndex
|
||||
insert 1 after rowMatrix
|
||||
else
|
||||
insert 0 after rowMatrix
|
||||
end if
|
||||
end repeat
|
||||
insert rowMatrix nested after matrixList
|
||||
end repeat
|
||||
return matrixList
|
||||
end buildIdentityMatrix
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function unitMatrix(n) {
|
||||
return map(range(n), function(k1, v1) {
|
||||
return map(range(n), function(k2, v2) {
|
||||
return v2 == v1 ? 1 : 0;
|
||||
});
|
||||
});
|
||||
return map(range(n), function(k1, v1) {
|
||||
return map(range(n), function(k2, v2) {
|
||||
return v2 == v1 ? 1 : 0;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
proc I {rank {zero 0.0} {one 1.0}} {
|
||||
set m [lrepeat $rank [lrepeat $rank $zero]]
|
||||
for {set i 0} {$i < $rank} {incr i} {
|
||||
lset m $i $i $one
|
||||
lset m $i $i $one
|
||||
}
|
||||
return $m
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ proc I {rank {zero 0.0} {one 1.0}} {
|
|||
$m add columns $rank
|
||||
$m add rows $rank
|
||||
for {set i 0} {$i < $rank} {incr i} {
|
||||
for {set j 0} {$j < $rank} {incr j} {
|
||||
$m set cell $i $j [expr {$i==$j ? $one : $zero}]
|
||||
}
|
||||
for {set j 0} {$j < $rank} {incr j} {
|
||||
$m set cell $i $j [expr {$i==$j ? $one : $zero}]
|
||||
}
|
||||
}
|
||||
return $m
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
build_matrix(7)
|
||||
|
||||
Sub build_matrix(n)
|
||||
Dim matrix()
|
||||
ReDim matrix(n-1,n-1)
|
||||
i = 0
|
||||
'populate the matrix
|
||||
For row = 0 To n-1
|
||||
For col = 0 To n-1
|
||||
If col = i Then
|
||||
matrix(row,col) = 1
|
||||
Else
|
||||
matrix(row,col) = 0
|
||||
End If
|
||||
Next
|
||||
i = i + 1
|
||||
Next
|
||||
'display the matrix
|
||||
For row = 0 To n-1
|
||||
For col = 0 To n-1
|
||||
If col < n-1 Then
|
||||
WScript.StdOut.Write matrix(row,col) & " "
|
||||
Else
|
||||
WScript.StdOut.Write matrix(row,col)
|
||||
End If
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
End Sub
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
n = 8
|
||||
|
||||
arr = Identity(n)
|
||||
|
||||
for i = 0 to n-1
|
||||
for j = 0 to n-1
|
||||
wscript.stdout.Write arr(i,j) & " "
|
||||
next
|
||||
wscript.stdout.writeline
|
||||
next
|
||||
|
||||
Function Identity (size)
|
||||
Execute Replace("dim a(#,#):for i=0 to #:for j=0 to #:a(i,j)=0:next:a(i,i)=1:next","#",size-1)
|
||||
Identity = a
|
||||
End Function
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
int main (string[] args) {
|
||||
if (args.length < 2) {
|
||||
print ("Please, input an integer > 0.\n");
|
||||
return 0;
|
||||
}
|
||||
var n = int.parse (args[1]);
|
||||
if (n <= 0) {
|
||||
print ("Please, input an integer > 0.\n");
|
||||
return 0;
|
||||
}
|
||||
int[,] array = new int[n, n];
|
||||
for (var i = 0; i < n; i ++) {
|
||||
for (var j = 0; j < n; j ++) {
|
||||
if (i == j) array[i,j] = 1;
|
||||
else array[i,j] = 0;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < n; i ++) {
|
||||
for (var j = 0; j < n; j ++) {
|
||||
print ("%d ", array[i,j]);
|
||||
}
|
||||
print ("\b\n");
|
||||
}
|
||||
return 0;
|
||||
if (args.length < 2) {
|
||||
print ("Please, input an integer > 0.\n");
|
||||
return 0;
|
||||
}
|
||||
var n = int.parse (args[1]);
|
||||
if (n <= 0) {
|
||||
print ("Please, input an integer > 0.\n");
|
||||
return 0;
|
||||
}
|
||||
int[,] array = new int[n, n];
|
||||
for (var i = 0; i < n; i ++) {
|
||||
for (var j = 0; j < n; j ++) {
|
||||
if (i == j) array[i,j] = 1;
|
||||
else array[i,j] = 0;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < n; i ++) {
|
||||
for (var j = 0; j < n; j ++) {
|
||||
print ("%d ", array[i,j]);
|
||||
}
|
||||
print ("\b\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
PROGRAM "Identity matrix"
|
||||
VERSION "0.0000"
|
||||
VERSION "0.0000"
|
||||
|
||||
DECLARE FUNCTION Entry ()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue