Yes as Hauke has previously identified, we need some more test cases to
fully test whether the spec is correctly implemented or not.
I'm thinking that the example outputs you've shown in your email aren't
correct, but I agree that your approach and Raul's generate different
solutions for that input and that your one (and Ben's and the current
solution on Rosetta code) generate the "correct" output as I
understand it. Here
is an updated set of test cases:

'data1 soln1'=: 'THEEQUICKBROWFFOX';'THEXEQUICKBROWFXFOX'
'data2 soln2'=: 'THEEQUICKBROWFOOX';'THEXEQUICKBROWFOOX'
'data3 soln3'=: 'TTHEEQUICKBROWFFOX';'TXTHEXEQUICKBROWFXFOX'
'data4 soln4'=: 'TTHEEQUICKBROWFOOOX';'TXTHEXEQUICKBROWFOOXOX'
'data5 soln5'=: '';''

showDigraphs=: dquote@(',' joinstring _2 <\ ])

dd_bg=: {{ ((+ idx&<)#y) {. y ({. ,'X', }.)~ idx =. >:+: 1 i.~ (=/"1) _2
]\y }}^:_
dd_md=: dtb@:((] ({.~ , 'X' , }.~) 1 (1 + 2 * i.)~ _2 =/\ ]) {.~ >:@#)
::($:@:,&' ')
digra=: * 2 | i.@# + +/\
dd_rm=: #!.'X'~ 1 j. [: digra # {. }. = }:
dd_pj=: ;@:(_2&(,`([,'X',])@.=/each@<\))^:_

Raul's approach looks as though with some more refinement of how to
calculate which sets of repeat letters need to be split, it should be
possible. At the moment it produces the incorrect result for data4.

   ([: showDigraphs dd_rm)&> data1;data2;data3;data4;data5
"TH,EX,EQ,UI,CK,BR,OW,FX,FO,X"
"TH,EX,EQ,UI,CK,BR,OW,FO,OX"
"TX,TH,EX,EQ,UI,CK,BR,OW,FX,FO,X"
"TX,TH,EX,EQ,UI,CK,BR,OW,FO,OO,X"
""
Iteratively applying Pascal's approaches do result in all digraphs being
split, but some pairs of letters are split unnecessarily.


On Fri, Feb 5, 2021 at 5:04 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

> Just before I venture into updating to the correct beta d...
>
> Raul's is elegant, single-pass and pretty spare.  Here's a verbose,
> inelegant,
> multi-pass one,  but it seems to work,  except perhaps for the last
> example,
> below.
>
> I stuck with _2 which means that with odd length strings an error is thrown
> on the last pair which is actually not a pair,  so needs to be catered for.
>
> anyway,  (it should appear on one line):
>     dedouble =: dtb@:((] ({.~ , 'X' , }.~) 1 (1 + 2 * i.)~ _2 =/\ ]) {.~
>  >:@#) ::($:@:,&' ')
>
> dtb is delete trailing blanks,  in strings,  I think.
>
>     dedouble^:_'THEEQUICKBROWFFOOX'
> THEXEQUICKBROWFXFOOX
>     dedouble^:_'THEEQUICKBROWFOOX'
> THEXEQUICKBROWFOOX
>
> This next example is a bit unlikely to occur,  but is this what's required?
>     dedouble 'THEEQUICKBROWFOOOX'
> THEXEQUICKBROWFOOOX
>
> Raul's version doesn't agree with mine here!  Is this result prederred?
>     rmdedouble 'THEEQUICKBROWFOOOX'
> THEXEQUICKBROWFOOOX
>
> Cheers,
>
> Mike
>
>
> On 04/02/2021 14:46, Raul Miller wrote:
> > 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,
> >
>
>
> --
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> 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