Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Permutations of an array - APL
Parent
Permutations of an array - APL
In Dyalog APL, there's a predefined function in the dfns
library to generate a matrix of permutations for a list of the numbers from 1 to n.
I want to create the same functionality, except that it should work for any array, not just a range 1 to n, in APL NARS2000.
How do I implement that?
Post
I assume the built-in definition you're referring to is pmat. That illustrates how to solve your problem near the bottom. The idea is simply if σ is a permutation of length N and A is an array of length N, then A[σ] is A permuted by σ. This leads to a definition like:
permute←{⍵[pmat⊃⍴⍵]}
with
permute 'abc'
producing
abc
acb
bac
bca
cab
cba
(The example in the documentation uses {⍵[pmat⍴⍵]}
but this seemed to lead to rank errors when I tried it in online interpreters using one of the definitions of pmat
listed on that page.)
0 comment threads