I wanted to do it without looping.
But my solution was incorrect.
The error just didn’t show with
the examples given.
Maybe I’ll find a better way.
Or at least refactor it a bit.

For now, this is at least correct:

i =: 0 -.~ (* i.@#)

s =: 2 : 0
a =. i m=y
n a} y
)

NB. ugly, repetitive junk solution
res1 -: '?'s'X' (] ((+ #\)@(2 I.@:=]) ((i.@#@] e. [) {"0 1 'X',.~]) #~)
(i.@# >:@e. 0 -.~ (* 2 }.@:-.@:| 0 , (+ i.@#))@i@(2&(=/@|:@]\))))
'X's'?' data1
res2 -: '?'s'X' (] ((+ #\)@(2 I.@:=]) ((i.@#@] e. [) {"0 1 'X',.~]) #~)
(i.@# >:@e. 0 -.~ (* 2 }.@:-.@:| 0 , (+ i.@#))@i@(2&(=/@|:@]\))))
'X's'?' data2


Am 04.02.21 um 08:48 schrieb Ben Gorte:
> 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
> 

-- 
----------------------
mail written using NEO
neo-layout.org

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

Reply via email to