September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
18
Task/Matrix-arithmetic/Jq/matrix-arithmetic-1.jq
Normal file
18
Task/Matrix-arithmetic/Jq/matrix-arithmetic-1.jq
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Eliminate row i and row j
|
||||
def except(i;j):
|
||||
reduce del(.[i])[] as $row ([]; . + [$row | del(.[j]) ] );
|
||||
|
||||
def det:
|
||||
def parity(i): if i % 2 == 0 then 1 else -1 end;
|
||||
if length == 1 and (.[0] | length) == 1 then .[0][0]
|
||||
else . as $m
|
||||
| reduce range(0; length) as $i
|
||||
(0; . + parity($i) * $m[0][$i] * ( $m | except(0;$i) | det) )
|
||||
end ;
|
||||
|
||||
def perm:
|
||||
if length == 1 and (.[0] | length) == 1 then .[0][0]
|
||||
else . as $m
|
||||
| reduce range(0; length) as $i
|
||||
(0; . + $m[0][$i] * ( $m | except(0;$i) | perm) )
|
||||
end ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue