So like this?
   dbld=. <"1]_2 ]\ str
   ;dbld,&.>(>=/&>dbld){'';'X'
AAXAbbCCCXC


On Thu, Feb 4, 2021 at 11:56 PM Ric Sherlock <tikk...@gmail.com> wrote:

> Only repeats that occur within a digraph need to be split, so:
>
>    showDigraphs dedouble 'AAABBCCCC'
> "AX,AX,AB,BC,CX,CX,C"
>
> On Fri, Feb 5, 2021 at 5:53 PM Devon McCormick <devon...@gmail.com> wrote:
>
> > How do you propose to handle triples and so on?  If you are using _2]\
> > instead of 2]\, you miss half the repeats.
> >    str=. 'AAAbbCCCC'
> >    ((2 ]\ ]);_2 ]\ ]) str   NB. Two ways of windowing.
> > +--+--+
> > |AA|AA|
> > |AA|Ab|
> > |Ab|bC|
> > |bb|CC|
> > |bC|C |
> > |CC|  |
> > |CC|  |
> > |CC|  |
> > +--+--+
> >    dbld=. 2 ]\ str
> >    ' '-.~,str,.' ',~(=/"1 dbld){' X'  NB. Assuming there will be no
> > legitimate spaces
> > AXAXAbXbCXCXCXC
> >
> >
> > On Thu, Feb 4, 2021 at 11:46 PM Ric Sherlock <tikk...@gmail.com> wrote:
> >
> > > Using ideas from the solutions so far, this is the version I currently
> > > prefer:
> > >
> > > getidx=: 1 >:@+:@i.~ =/"1@(_2 ]\ ])
> > > splitDigraph=: ({. , 'X' , }.)~ getidx
> > > dedouble=: dtb@:(>:@# {. splitDigraph)^:_
> > >
> > >    (soln1;soln2;soln3;soln4;soln5) -: dedouble&.>
> > > data1;data2;data3;data4;data5
> > > 1
> > >
> > >
> > > On Fri, Feb 5, 2021 at 5:32 PM Ben Gorte <bgo...@gmail.com> wrote:
> > >
> > > > Ah yes, better!
> > > > Works on the five test cases :-)
> > > >
> > > >
> > > > On Thu, 4 Feb 2021 at 23:13, Ric Sherlock <tikk...@gmail.com> wrote:
> > > >
> > > > > Thanks, yes that works!
> > > > > Here's a slightly simpler take on the same approach:
> > > > > {{ ((+ idx&<)#y) {. y ({. ,'X', }.)~ idx =. >:+: 1 i.~ (=/"1) _2
> ]\y
> > > > }}^:_
> > > > >
> > > > > On Thu, Feb 4, 2021 at 8:48 PM Ben Gorte <bgo...@gmail.com> wrote:
> > > > >
> > > > > > Think I've got it:
> > > > > >
> > > > > > data1 =: 'THEEQUICKBROWFFOX'
> > > > > >
> > > > > > data2 =: 'THEEQUICKBROWFOOX'
> > > > > >
> > > > > > {{ ((+where&<)#y) {. ({.&y ,'X', }.&y) where =. >: +: 1 i.~ _2
> =/\
> > > > > > y,'XX',(2|#y){.'X' }}^:_ data1
> > > > > >
> > > > > > THEXEQUICKBROWFXFOX
> > > > > >
> > > > > > {{ ((+where&<)#y) {. ({.&y ,'X', }.&y) where =. >: +: 1 i.~ _2
> =/\
> > > > > > y,'XX',(2|#y){.'X' }}^:_ data2
> > > > > >
> > > > > > THEXEQUICKBROWFOOX
> > > > > >
> > > > > >
> > > > > > Ben
> > > > > >
> > > > > > On Thu, 4 Feb 2021 at 17:02, Hauke Rehr <hauke.r...@uni-jena.de>
> > > > wrote:
> > > > > >
> > > > > > > I show this only as a different way to deal with it.
> > > > > > > There’s much space for improvement.
> > > > > > > It works correctly with the two examples you gave.
> > > > > > >
> > > > > > > data1 =: 'THEEQUICKBROWFFOX'
> > > > > > > data2 =: 'THEEQUICKBROWFOOX'
> > > > > > > res1  =: 'THEXEQUICKBROWFXFOX'
> > > > > > > res2  =: 'THEXEQUICKBROWFOOX'
> > > > > > >
> > > > > > > s =: 2 : 0
> > > > > > > a =. 0 -.~ (* i.@#) m=y
> > > > > > > n a} y
> > > > > > > )
> > > > > > >
> > > > > > > NB. ugly, repetitive junk solution
> > > > > > > res1 = ('?'s'X') (] (>:@(+ i.@#)@(2 I.@:=]) (([e.~i.@#@]){"0
> > > > 1'X',.~])
> > > > > > > #~) (i.@# >:@e. (* -.@(- (0 1 $~ $))@(2&|))@(-.&0@(*
> > > > > > > i.@#))@(2&(=/@|:@]\)))) ('X's'?') data1
> > > > > > > res2 = ('?'s'X') (] (>:@(+ i.@#)@(2 I.@:=]) (([e.~i.@#@]){"0
> > > > 1'X',.~])
> > > > > > > #~) (i.@# >:@e. (* -.@(- (0 1 $~ $))@(2&|))@(-.&0@(*
> > > > > > > i.@#))@(2&(=/@|:@]\)))) ('X's'?') data2
> > > > > > >
> > > > > > >
> > > > > > > Am 04.02.21 um 05:02 schrieb Ric Sherlock:
> > > > > > > > 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
> > > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > ----------------------
> > > > > > > mail written using NEO
> > > > > > > neo-layout.org
> > > > > > >
> > > > > > >
> > > >
> ----------------------------------------------------------------------
> > > > > > > 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
> > > >
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> >
> >
> > --
> >
> > Devon McCormick, CFA
> >
> > Quantitative Consultant
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 

Devon McCormick, CFA

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

Reply via email to