Ah, I see it now -- I should have looked closer at your digraphs. Here's a fixed version:
digra=: * 2 | i.@# + +/\ dedouble=: #!.'X'~ 1 j. [: digra #{.}.=}: (I could not think of a good name for the "compress out splits of non-digraphs" mechanism.) The moral of the story here is that numeric calculations can often replace simple recursive processes. (Because numbers can be defined recursively.) I hope this helps, -- Raul On Thu, Feb 4, 2021 at 5:50 AM Ric Sherlock <tikk...@gmail.com> wrote: > > Sorry I should have been a bit more explicit with the specification. > > The reason that the double O in the 2nd example does not get an X inserted > is that once the X is inserted for the first double, the Os are split > between 2 digraphs and no longer require to be separated. In other words, > after the first insertion, the digraphs need to be re-generated to see if > further insertions are required. > > _2 ]\ dedouble 'THEEQUICKBROWFOOX' > TH > EX > EQ > UI > CK > BR > OW > FO > OX > > A simple non-looping solution doesn't leap out at me! > > > On Thu, Feb 4, 2021 at 6:20 PM Raul Miller <rauldmil...@gmail.com> wrote: > > > I would be tempted to go with > > > > dedouble=: #!.'X'~ 1 j. #{.}.=}: > > > > But I do not understand why the double O in your second example does > > not get an X inserted. So maybe I am missing something. > > > > I hope this helps, > > > > -- > > Raul > > > > On Wed, Feb 3, 2021 at 11:02 PM Ric Sherlock <tikk...@gmail.com> wrote: > > > > > > I need to separate any digraphs in a string, that consist of 2 letters > > the > > > same, by inserting an 'X' between them. > > > _2 ]\ 'THEEQUICKBROWFFOX' > > > TH > > > EE > > > QU > > > IC > > > KB > > > RO > > > WF > > > FO > > > X > > > > > > 'EE' is a digraph that needs an 'X' inserted. Doing so will result in: > > > > > > TH > > > EX > > > EQ > > > UI > > > CK > > > BR > > > OW > > > FF > > > OX > > > > > > So now we also need to separate the 'FF' digraph. > > > > > > I want to define a verb "dedouble" that will process a string so: > > > dedouble 'THEEQUICKBROWFFOX' > > > THEXEQUICKBROWFXFOX > > > But: > > > dedouble 'THEEQUICKBROWFOOX' > > > THEXEQUICKBROWFOOX > > > > > > I have implemented a solution at > > > https://rosettacode.org/wiki/Playfair_cipher#J but am interested in > > > alternative implementations. > > > ---------------------------------------------------------------------- > > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm