3 ms·
http://rosetta.alhur.es/compare/nim/go/#Matrix_arithmetic http://rosetta.alhur.es/compare/nim/go/#Matrix_arithmetic Nim: proc det[M,N](a: Matrix[M,N]): fl
by jaws- 11y ago
http://rosetta.alhur.es/compare/nim/go/#Matrix_arithmetic http://rosetta.alhur.es/compare/nim/go/#Matrix_arithmetic
Nim:
proc det[M,N](a: Matrix[M,N]): float =
let n = toSeq 0..a.high
for sigma, sign in n.permutations:
var x = sign.float
for i in n: x *= a[i][sigma[i]]
result += x
Go:
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
}
I don't know anything about Go or Nim, but the Nim version looks infinitely more readable to me.