RosettaCodeData/Task/Matrix-arithmetic/Julia/matrix-arithmetic-2.julia

6 lines
177 B
Text
Raw Permalink Normal View History

2014-01-17 05:32:22 +00:00
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