Raul wrote: > someone with a stronger background in permutations might be able to describe some useful techniques.
Ascending Radix numerals (aka the Factorial Number System) offer a natural way of putting permutations in 1-1 correspondence with the positive integers. These articles explain how: [1] https://en.wikipedia.org/wiki/Permutation#Numbering_permutations [2] https://en.wikipedia.org/wiki/Lehmer_code [3] https://en.wikipedia.org/wiki/Factorial_number_system Let's define a permutation on 4 points to be equivalent to a corresponding permutation on 5 points which fixes the 5th point. This is roughly analogous to saying the decimal numerals 3276 and 03276 (say) are "equivalent". EXAMPLE: these permutations are equivalent: 3 2 1 0 3 2 1 0 4 3 2 1 0 4 5 3 2 1 0 4 5 6 etc. Essentially (A.) follows the Lehmer approach, but does it back to front. Lehmer gives the same integer for two "equivalent" permutations, whereas (A.) doesn't… A. 3 2 1 0 23 A. 3 2 1 0 4 86 For this reason I feel the methods of [1], [2] and [3] offer a better-behaved way of enumerating permutations than (A.). Back in 1970 I worked on fast computer algorithms to do this on a Burroughs B6700 and eventually stumbled on the Lehmer code myself, or something very much like it, which I implemented in Algol. Alas the code is no longer extant, but I still have the manual algorithm. I'm going to dust off this old work, get my algorithm working as an explicit verb and derive a tacit implementation. But someone with a fresher brain could doubtless take [2] and implement Lehmer codes efficiently in J far quicker than I shall. On Mon, 14 Mar 2022 at 18:37, Raul Miller <[email protected]> wrote: > Watching this, I got to thinking about your anagram index of the "by suit" > deck. > > We know that an anagram index is in some sense based on the factorial > of the length of the sequence. > > But, also, we can use the indices of the sequence as a base for the > anagram index, if we toss the 0 and 1. For example: > > ((i.!4)A.i.4),._,.(_2}.i.-4)#:i.!4 > 0 1 2 3 _ 0 0 > 0 1 3 2 _ 0 1 > 0 2 1 3 _ 1 0 > 0 2 3 1 _ 1 1 > 0 3 1 2 _ 2 0 > 0 3 2 1 _ 2 1 > 1 0 2 3 _ 0 0 > 1 0 3 2 _ 0 1 > 1 2 0 3 _ 1 0 > 1 2 3 0 _ 1 1 > 1 3 0 2 _ 2 0 > 1 3 2 0 _ 2 1 > 2 0 1 3 _ 0 0 > 2 0 3 1 _ 0 1 > 2 1 0 3 _ 1 0 > 2 1 3 0 _ 1 1 > 2 3 0 1 _ 2 0 > 2 3 1 0 _ 2 1 > 3 0 1 2 _ 0 0 > 3 0 2 1 _ 0 1 > 3 1 0 2 _ 1 0 > 3 1 2 0 _ 1 1 > 3 2 0 1 _ 2 0 > 3 2 1 0 _ 2 1 > > We can see here that the swaps in the permutations (the numbers on the > left) correspond in some way to the "anagram index in base 0 1-.~i.-#" > (the numbers on the right). Here, I guess we ignore the leftmost and > rightmost values in the permutation, since they are fully determined, > in the sense of swaps, by the other values. > > So, now we have a way of looking at the anagram index of the > transposed deck of cards: > > (_2}.i.-52)#:A.,|:i.4 13 > 12 24 36 0 11 22 33 0 10 20 30 0 9 18 27 0 8 16 24 0 7 14 21 0 6 12 18 > 0 5 10 15 0 4 8 12 0 3 6 9 0 2 4 6 0 1 2 3 0 0 0 > > At first, the pattern there doesn't really leap out at us. But, after > a short look, it's obvious that these numbers occur in sequences of > four. So: > > _4]\(_2}.i.-52)#:A.,|:i.4 13 > 12 24 36 0 > 11 22 33 0 > 10 20 30 0 > 9 18 27 0 > 8 16 24 0 > 7 14 21 0 > 6 12 18 0 > 5 10 15 0 > 4 8 12 0 > 3 6 9 0 > 2 4 6 0 > 1 2 3 0 > > In other words, it's: > > _2}.,(i._13) */ 1|.i.4 > 12 24 36 0 11 22 33 0 10 20 30 0 9 18 27 0 8 16 24 0 7 14 21 0 6 12 18 > 0 5 10 15 0 4 8 12 0 3 6 9 0 2 4 6 0 1 2 3 0 0 0 > > Now... I should probably do some more experiments here, to see if I > could form a more general insight into how we might compute an > arbitrary anagram index. But there's definitely a pattern here, and > someone with a stronger background in permutations might be able to > describe some useful techniques. > > Thanks, > > -- > Raul > > On Sun, Mar 13, 2022 at 5:22 PM Michal Wallace <[email protected]> > wrote: > > > > I made a short beginner video about dealing cards, using ? and A. : > > > > https://www.youtube.com/watch?v=eXGKK8BkCkg > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
