How do you apply your solution to a=:3 4 [EMAIL PROTECTED] where I want, 
according to
the permutation (5 0 3;1 2), all 5's replaced by 0, all 0's by 3, all 3's by
5, all 1's by 2 and all 2's by 1?

R.E. Boss


>-----Oorspronkelijk bericht-----
>Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens p j
>Verzonden: maandag 20 maart 2006 17:19
>Aan: Programming forum
>Onderwerp: Re: [Jprogramming] Permuting atom values
>
>There's an easier way to do it.
>
>perm=: [EMAIL PROTECTED] A. i.
>  perm 3
>0 1 2
>0 2 1
>1 0 2
>1 2 0
>2 0 1
>2 1 0
>data=: 10 20 30
>
>  {&data  perm 3
>10 20 30
>10 30 20
>20 10 30
>20 30 10
>30 10 20
>30 20 10
>
>you just bind amend with its y dyad argument, and you
>have a Monad... that can operate on the original x
>argument.
>
>Sorry if I misunderstood what you wanted.
>
>--- "R.E. Boss" <[EMAIL PROTECTED]> wrote:
>
>> J does not have a primitive verb which permutes
>> values of atoms, like C.
>> permutes indexes. 
>> 
>> 
>> So, if P would be such a primitive, then (5 0 3; 1
>> 2) P y  would replace in
>> y each 5 by 0, each 0 by 3 and each 3 by 5 and swap
>> 1's and 2's.
>> 
>> Contrary to the behaviour of C. , preferably P
>> accepts only boxed left hand
>> argument.
>> 
>> 
>> One way to realize P with the use of C. is:
>> 
>> P=: [EMAIL PROTECTED] $ (((i.!.0~ ~.)@] { (((i.&.>~<) C. ]) ~.))
>> ,) 
>> 
>> 
>>    a ; (5 0 3;1 2) P  a =: 
>> 
>> +---------+---------+
>> |0 5 5 4 2|3 0 0 4 1|
>> |3 2 1 4 2|5 1 2 4 1|
>> |0 2 1 4 1|3 1 2 4 2|
>> |2 4 0 4 0|1 4 3 4 3|
>> |         |         |
>> |5 4 0 0 0|0 4 3 3 3|
>> |5 1 5 0 4|0 2 0 3 4|
>> |5 5 2 0 0|0 0 1 3 3|
>> |1 1 5 3 1|2 2 0 5 2|
>> |         |         |
>> |3 2 1 1 3|5 1 2 2 5|
>> |4 4 3 5 5|4 4 5 0 0|
>> |5 0 1 0 3|0 3 2 3 5|
>> |1 3 5 0 1|2 5 0 3 2|
>> +---------+---------+
>> 
>>
>> 
>> As can be seen, realizing P using C. can be rather
>> complicated 
>> 
>> On the other hand, it would be easy to realize C.
>> with the help of P, as C.
>> is a special case of P, applying P to the array of
>> indexes.
>> 
>> C. would be (roughly) equal to  (P [EMAIL PROTECTED]) { ] 
>> 
>>    (5 0 3;1 2) ((P [EMAIL PROTECTED]) { ]) 'ABCDEF'
>> 
>> DCBFEA
>> 
>>
>> 
>> The conclusion seems to be that P is more primitive
>> than C. 
>> 
>>
>> 
>> What is the opinion of the forum on this?
>> 
>>
>> 
>> R.E. Boss
>> 
>>
>> 
>>
>----------------------------------------------------------------------
>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> 
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>----------------------------------------------------------------------
>For information about J forums see http://www.jsoftware.com/forums.htm
>

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

Reply via email to