For what it's worth, here's a parenthesis free implementation of my two variant definitions of cross (and note that I am using what is probably an unfamiliar J idiom here -- please feel free to ask for an explanation, if I am not making sense):
selch=: #"0"1 orflp=: +.|.@ cross1=: ,@selch~ = orflp cross2=: ,@selch~ =@i.@# orflp Example use: cross1 'abcde' a e b d c b d a e cross2 'abcde' a e b d c b d a e Here is a case where the implementation gives different results: cross1 'abcba' a c a b b a c a cross2 'abcba' a a b b c b b a a FYI, -- Raul On Mon, Dec 10, 2012 at 2:48 PM, Raul Miller <rauldmil...@gmail.com> wrote: > And, for what it's worth, here's a different plausible implementation > of cross (different only for the case of duplicated letters in the > argument when compared with the version I posted, below): > > (,@(#~"0"1) (+.|.)@=@(#\)) 'abcdedcba' > > Note that replacing = with =@(#\) should also work for Aai's original version. > > FYI, > > -- > Raul > > On Mon, Dec 10, 2012 at 1:28 PM, Raul Miller <rauldmil...@gmail.com> wrote: >> Here's a version that works with duplicated values (except note that >> there was no specification for what the behavior should be in this >> case): >> >> (,@(#~"0"1) (+.|.)@=)'abcde' >> a e >> b d >> c >> b d >> a e >> >> (,@(#~"0"1) (+.|.)@=)'abcdedcba' >> a e a >> b d d b >> c c >> b d d b >> a e a >> >> -- >> Raul >> >> On Mon, Dec 10, 2012 at 1:21 PM, Roger Hui <rogerhui.can...@gmail.com> wrote: >>> The expression fails if the argument has duplicate items. e.g. >>> >>> ((+.|.)@={"0 1 ' '&,.)'aabbb' >>> |length error >>> | ((+.|.)@={"0 1' '&,.)'aabbb' >>> >>> >>> >>> On Mon, Dec 10, 2012 at 10:18 AM, bob therriault >>> <bobtherria...@mac.com>wrote: >>> >>>> That is lovely Arie, >>>> >>>> It is that kind of elegance that I was chasing with my rougher attempts. >>>> >>>> Using the (+.|.) hook simplifies (|.+.]) precisely and the {" 0 1 >>>> combined with ' '&,. means that the selection of the string becomes a >>>> choice in each row of displaying either the corresponding element of the >>>> string or a blank. >>>> >>>> Cheers, bob >>>> >>>> On 2012-12-10, at 1:11 AM, Aai wrote: >>>> >>>> > ((+.|.)@={"0 1 ' '&,.)'abcde' >>>> >>>> ---------------------------------------------------------------------- >>>> 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