Eddie Bracho wrote:
>   shuffle =: 3 : '(?~#y){y’
> 
>   shuffle p: i.7
> 17 2 7 13 11 3 5

To return to the idea of using !, if you really wanted to:

        anagrait =: verb def 'y A.~ ?! x: # y'
        anagrait p: i. 7
   5 7 3 17 2 11 13

Summary: dyad A. takes a list (in the abstract sense of “a list of items”, 
where an item can be anything) and an “anagram index”, and re-arranges the list 
based on the anagram index (same items, reordered). 

The anagram index ranges from 0 to _1+ ! #list (because there are !#list 
possible permutations of the list) and dictates the order of the resulting 
list, i.e. which permutation will be selected. For example, anagram index 
(permutation number) 0 is always the list itself in its current order (i.e. 
monad 0&A. is an identity function) and _1 is always the list in precisely 
reverse order (so monad _1&A. is the same as monad |. ).

The actual encoding of the anagram index, or permutation number, is in itself 
quite an interesting algorithm, but you don’t need to know anything about it in 
order to use A. (because you can use monad A. to work out the the permutation 
number of any given list).

-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to