Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import std.algorithm, std.range, std.traits, permutations2,
|
||||
permutations_by_swapping1;
|
||||
|
||||
auto prod(Range)(/*in*/ Range r) /*pure nothrow*/ {
|
||||
auto prod(Range)(Range r) /*pure*/ nothrow {
|
||||
return reduce!q{a * b}(cast(ForeachType!Range)1, r);
|
||||
}
|
||||
|
||||
|
|
|
|||
52
Task/Matrix-arithmetic/Go/matrix-arithmetic.go
Normal file
52
Task/Matrix-arithmetic/Go/matrix-arithmetic.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"permute"
|
||||
)
|
||||
|
||||
func determinant(m [][]float64) (d float64) {
|
||||
p := make([]int, len(m))
|
||||
for i := range p {
|
||||
p[i] = i
|
||||
}
|
||||
it := permute.Iter(p)
|
||||
for s := it(); s != 0; s = it() {
|
||||
pr := 1.
|
||||
for i, σ := range p {
|
||||
pr *= m[i][σ]
|
||||
}
|
||||
d += float64(s) * pr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func permanent(m [][]float64) (d float64) {
|
||||
p := make([]int, len(m))
|
||||
for i := range p {
|
||||
p[i] = i
|
||||
}
|
||||
it := permute.Iter(p)
|
||||
for s := it(); s != 0; s = it() {
|
||||
pr := 1.
|
||||
for i, σ := range p {
|
||||
pr *= m[i][σ]
|
||||
}
|
||||
d += pr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var m2 = [][]float64{
|
||||
{1, 2},
|
||||
{3, 4}}
|
||||
|
||||
var m3 = [][]float64{
|
||||
{2, 9, 4},
|
||||
{7, 5, 3},
|
||||
{6, 1, 8}}
|
||||
|
||||
func main() {
|
||||
fmt.Println(determinant(m2), permanent(m2))
|
||||
fmt.Println(determinant(m3), permanent(m3))
|
||||
}
|
||||
1
Task/Matrix-arithmetic/Julia/matrix-arithmetic-1.julia
Normal file
1
Task/Matrix-arithmetic/Julia/matrix-arithmetic-1.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
det(A)
|
||||
5
Task/Matrix-arithmetic/Julia/matrix-arithmetic-2.julia
Normal file
5
Task/Matrix-arithmetic/Julia/matrix-arithmetic-2.julia
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function perm(A)
|
||||
m, n = size(A)
|
||||
if m != n; throw(ArgumentError("permanent is for square matrices only")); end
|
||||
sum(σ -> prod(i -> A[i,σ[i]], 1:n), permutations(1:n))
|
||||
end
|
||||
3
Task/Matrix-arithmetic/Julia/matrix-arithmetic-3.julia
Normal file
3
Task/Matrix-arithmetic/Julia/matrix-arithmetic-3.julia
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
julia> A = [2 9 4; 7 5 3; 6 1 8]
|
||||
julia> det(A), perm(A)
|
||||
(-360.0,900)
|
||||
Loading…
Add table
Add a link
Reference in a new issue