Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,4 +1,4 @@
|
|||
∘.=/⍳¨3 3
|
||||
∘.=⍨⍳3
|
||||
1 0 0
|
||||
0 1 0
|
||||
0 0 1
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
ID←{∘.=/⍳¨ ⍵ ⍵}
|
||||
ID←{∘.=⍨⍳⍵}
|
||||
ID 5
|
||||
1 0 0 0 0
|
||||
0 1 0 0 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
100 INPUT "MATRIX SIZE:"; SIZE%
|
||||
110 GOSUB 200"IDENTITYMATRIX
|
||||
120 FOR R = 0 TO SIZE%
|
||||
130 FOR C = 0 TO SIZE%
|
||||
140 LET S$ = CHR$(13)
|
||||
150 IF C < SIZE% THEN S$ = " "
|
||||
160 PRINT IM(R, C) S$; : NEXT C, R
|
||||
170 END
|
||||
|
||||
200 REMIDENTITYMATRIX SIZE%
|
||||
210 LET SIZE% = SIZE% - 1
|
||||
220 DIM IM(SIZE%, SIZE%)
|
||||
230 FOR I = 0 TO SIZE%
|
||||
240 LET IM(I, I) = 1 : NEXT I
|
||||
250 RETURN :IM
|
||||
25
Task/Identity-matrix/Delphi/identity-matrix.delphi
Normal file
25
Task/Identity-matrix/Delphi/identity-matrix.delphi
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
program IdentityMatrix;
|
||||
|
||||
// Modified from the Pascal version
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
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/Elixir/identity-matrix.elixir
Normal file
9
Task/Identity-matrix/Elixir/identity-matrix.elixir
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Matrix do
|
||||
def identity(n) do
|
||||
Enum.map(0..n-1, fn i ->
|
||||
for j <- 0..n-1, do: (if i==j, do: 1, else: 0)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
IO.inspect Matrix.identity(5)
|
||||
9
Task/Identity-matrix/Fortran/identity-matrix-2.f
Normal file
9
Task/Identity-matrix/Fortran/identity-matrix-2.f
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Program Identity
|
||||
Integer N
|
||||
Parameter (N = 666)
|
||||
Real A(N,N)
|
||||
Integer i,j
|
||||
|
||||
ForAll(i = 1:N, j = 1:N) A(i,j) = (i/j)*(j/i)
|
||||
|
||||
END
|
||||
|
|
@ -1,18 +1,19 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
"github.com/gonum/matrix/mat64"
|
||||
)
|
||||
|
||||
func I(n int) [][]float64 {
|
||||
m := make([][]float64, n)
|
||||
a := make([]float64, n*n)
|
||||
func eye(n int) *mat64.Dense {
|
||||
m := mat64.NewDense(n, n, nil)
|
||||
for i := 0; i < n; i++ {
|
||||
a[i] = 1
|
||||
m[i] = a[:n]
|
||||
a = a[n:]
|
||||
m.Set(i, i, 1)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat64.Formatted(eye(3)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,11 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
type matrix []float64
|
||||
mat "github.com/skelterjohn/go.matrix"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
|
||||
func I(n int) matrix {
|
||||
m := make(matrix, n*n)
|
||||
n++
|
||||
for i := 0; i < len(m); i += n {
|
||||
m[i] = 1
|
||||
}
|
||||
return m
|
||||
fmt.Println(mat.Eye(3))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
mat "github.com/skelterjohn/go.matrix"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat.Eye(3))
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
|
||||
func I(n int) [][]float64 {
|
||||
m := make([][]float64, n)
|
||||
for i := 0; i < n; i++ {
|
||||
a := make([]float64, n)
|
||||
a[i] = 1
|
||||
m[i] = a
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
|
|
|||
18
Task/Identity-matrix/Go/identity-matrix-4.go
Normal file
18
Task/Identity-matrix/Go/identity-matrix-4.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
|
||||
func I(n int) [][]float64 {
|
||||
m := make([][]float64, n)
|
||||
a := make([]float64, n*n)
|
||||
for i := 0; i < n; i++ {
|
||||
a[i] = 1
|
||||
m[i] = a[:n]
|
||||
a = a[n:]
|
||||
}
|
||||
return m
|
||||
}
|
||||
34
Task/Identity-matrix/Go/identity-matrix-5.go
Normal file
34
Task/Identity-matrix/Go/identity-matrix-5.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type matrix []float64
|
||||
|
||||
func main() {
|
||||
n := 3
|
||||
m := I(n)
|
||||
// dump flat represenation
|
||||
fmt.Println(m)
|
||||
|
||||
// function x turns a row and column into an index into the
|
||||
// flat representation.
|
||||
x := func(r, c int) int { return r*n + c }
|
||||
|
||||
// access m by row and column.
|
||||
for r := 0; r < n; r++ {
|
||||
for c := 0; c < n; c++ {
|
||||
fmt.Print(m[x(r, c)], " ")
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func I(n int) matrix {
|
||||
m := make(matrix, n*n)
|
||||
// a fast way to initialize the flat representation
|
||||
n++
|
||||
for i := 0; i < len(m); i += n {
|
||||
m[i] = 1
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
sub identity-matrix($n) {
|
||||
my @id;
|
||||
for ^$n X ^$n -> $i, $j {
|
||||
for flat ^$n X ^$n -> $i, $j {
|
||||
@id[$i][$j] = +($i == $j);
|
||||
}
|
||||
@id;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
sub identity-matrix($n) {
|
||||
[1, 0 xx $n-1], *.rotate(-1).item ... *[*-1] == 1
|
||||
([1, |(0 xx $n-1)].item, *.rotate(-1).item ... *)[^$n]
|
||||
}
|
||||
|
|
|
|||
21
Task/Identity-matrix/PowerShell/identity-matrix-1.psh
Normal file
21
Task/Identity-matrix/PowerShell/identity-matrix-1.psh
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function id($n) {
|
||||
if($n -gt 0) {
|
||||
$array = @(1..$n | foreach{ @(0) })
|
||||
0..($n-1) | foreach{
|
||||
$i = $_
|
||||
$array[$i] = @(switch(0..($n-1)){
|
||||
$i {1}
|
||||
default {0}
|
||||
})
|
||||
}
|
||||
$array
|
||||
} else { @() }
|
||||
}
|
||||
function show($a) {
|
||||
if($a.Count -gt 0) {
|
||||
$n = $a.Count - 1
|
||||
0..$n | foreach{ "$($a[$_][0..$n])" }
|
||||
}
|
||||
}
|
||||
$array = id 4
|
||||
show $array
|
||||
2
Task/Identity-matrix/PowerShell/identity-matrix-2.psh
Normal file
2
Task/Identity-matrix/PowerShell/identity-matrix-2.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$array[0][0]
|
||||
$array[0][1]
|
||||
29
Task/Identity-matrix/VBScript/identity-matrix.vb
Normal file
29
Task/Identity-matrix/VBScript/identity-matrix.vb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue