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

Reply via email to