|
perm←{0=⍵:1 0⍴0 ⋄ ,[⍳2](⊂0,1+∇ ¯1+⍵) ⌷⍤1 ⍒⍤1 ∘.=⍨ ⍳⍵}
a. |
Write a version of perm that checks
its argument and result. For example:
assert←{⍺←'assertion failure' ⋄ 0∊⍵:⍺ ⎕signal 8 ⋄ shy←0}
perm_chk←{
assert 0=⍴⍴⍵:
assert 0≤⍵:
z←perm ⍵
assert (⍴z)≡(!⍵),⍵:
...
z
}
|
b. |
Write a 1-line, non-recursive, non-looping version of perm .
|
|