I always thought I won’t need JfC for I have
a mixed language background and C is not the
strongest in the mix. There are so many
resources I still haven’t read … and now at
least that example page has been an interesting
and educational read. I’m buried in a long
list of outstanding (pun intended) reads
of documentation, of Essays, of Shades, etc. :-)
Am 06.02.21 um 03:45 schrieb Ric Sherlock:
> Thanks for that reference. It helped me understand what was going on here
> and a good reminder for me to revisit JfoC Programmers more often.
> A great solution guys! My new preferred version of dedouble:
>
> splitDigraph=: ,`([,'X',])@.((= {.) *. 2 | #@])
> dedouble=: splitDigraph/&.|.
>
> I can live with it not working for empty strings too, but if that were a
> deal-breaker I could define as:
>
> dedouble=: splitDigraph/&.|. :: ]
>
> On Sat, Feb 6, 2021 at 3:25 AM R.E. Boss <[email protected]> wrote:
>
>> "It took me a little to understand why this works (I first didn’t get
>> /&.|. actually works front-to-back) I like this approach."
>>
>>
>>
>> See the brilliant story in 25. Loopless Code VI: Temporary Variables<
>> https://www.jsoftware.com/help/jforc/loopless_code_vi_temporary_v.htm>
>> where I learned it.
>>
>>
>>
>>
>>
>> R.E. Boss
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Programming <[email protected]> On Behalf Of
>> Hauke Rehr
>> Sent: vrijdag 5 februari 2021 12:50
>> To: [email protected]
>> Subject: Re: [Jprogramming] Progressive insertion into a string
>>
>>
>>
>> It took me a little to understand why this works (I first didn’t get /&.|.
>> actually works front-to-back) I like this approach. I only wonder why you
>> didn’t
>>
>>
>>
>> v1a=:4 : '(,`(,`([,x,])@.(={.))@.(2|#@]))/&.|<mailto:2|#@]))/&.|>. y'
>>
>>
>>
>> and now you see it’s actually
>>
>>
>>
>> v2a=:4 : '(,`([,x,])@.((={.)*.2|#@]))/&.|<mailto:*.2|#@]))/&.|>. y'
>>
>>
>>
>> it’s a matter of taste, mostly
>>
>> but I think it’s more readable;
>>
>> and I developed a disgust to
>>
>> @.(0=<test>) and @.(1=<test>)
>>
>> just like with some people
>>
>> writing nonsense like
>>
>> if (myBool == true)
>>
>>
>>
>> Am 05.02.21 um 12:34 schrieb R.E. Boss:
>>
>>> Better is
>>
>>>
>>
>>> v0a=:4 : '((,`([,x,])@.(={.))`,@.(0=2|#@]))/&.|<mailto:0=2|#@]))/&.|>.
>> y'
>>
>>>
>>
>>> X v0a L:0 }:data
>>
>>>
>> +-------------------+------------------+---------------------+----------------------+
>>
>>>
>> |THEαEQUICKBROWFαFOX|THEαEQUICKBROWFOOX|TαTHEαEQUICKBROWFαFOX|TαTHEαEQUICKBROWFOOαOX|
>>
>>>
>> +-------------------+------------------+---------------------+----------------------+
>>
>>>
>>
>>> Then
>>
>>>
>>
>>> soln (-: 'X' v0a L:0 ])&}:data
>>
>>> 1
>>
>>>
>>
>>>
>>
>>> R.E. Boss
>>
>>>
>>
>>>
>>
>>> -----Original Message-----
>>
>>> From: Programming <[email protected]<mailto:
>> [email protected]>> On Behalf
>>
>>> Of R.E. Boss
>>
>>> Sent: vrijdag 5 februari 2021 10:33
>>
>>> To: [email protected]<mailto:[email protected]>
>>
>>> Subject: Re: [Jprogramming] Progressive insertion into a string
>>
>>>
>>
>>> v0=:((,`([,X,])@.(={.))`,@.(0=2|#@]))/&.|<mailto:0=2|#@]))/&.|>.
>> NB. My solution
>>
>>> v1=:3 : '(([:*./ ~:/"1)-: ([:I.2=/\{.)-:X I.@:={:)|<mailto:I.@:=%7b:)|>:
>> _2[\ y' NB. Check on correctness
>>
>>>
>>
>>> v0 data5 NB. Does not work on empty string,
>> it's OK with me
>>
>>> |domain error: v0
>>
>>> | v0 data5
>>
>>>
>>
>>> soln (,:~ v0 L:0)&}:data NB.
>> data=:data1;data2;data3;data4;data5
>>
>>>
>> NB. Same solution with α instead of X
>>
>>>
>> +-------------------+------------------+---------------------+----------------------+
>>
>>>
>> |THEαEQUICKBROWFαFOX|THEαEQUICKBROWFOOX|TαTHEαEQUICKBROWFαFOX|TαTHEαEQUICKBROWFOOαOX|
>>
>>>
>> +-------------------+------------------+---------------------+----------------------+
>>
>>>
>> |THEXEQUICKBROWFXFOX|THEXEQUICKBROWFOOX|TXTHEXEQUICKBROWFXFOX|TXTHEXEQUICKBROWFOOXOX|
>>
>>>
>> +-------------------+------------------+---------------------+----------------------+
>>
>>>
>>
>>> v1 S:0 v0 L:0 }:data NB. All (but last) solutions
>> are correct
>>
>>> 1 1 1 1
>>
>>>
>>
>>>
>>
>>> R.E. Boss
>>
>>>
>>
>>>
>>
>>> -----Original Message-----
>>
>>> From: Programming <[email protected]<mailto:
>> [email protected]>> On Behalf
>>
>>> Of Ric Sherlock
>>
>>> Sent: vrijdag 5 februari 2021 02:35
>>
>>> To: Programming JForum <[email protected]<mailto:
>> [email protected]>>
>>
>>> Subject: Re: [Jprogramming] Progressive insertion into a string
>>
>>>
>>
>>> 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.@#<mailto: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 <
>> [email protected]<mailto:[email protected]>> 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.@#<mailto: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
>>
>>> ----------------------------------------------------------------------
>>
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>> ----------------------------------------------------------------------
>>
>>> 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
>
--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm