Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread Hauke Rehr
oopless 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- >> F

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread Ric Sherlock
ss >> >> >> >> >> >> -----Original Message- >> From: Programming On Behalf >> Of Hauke Rehr >> Sent: vrijdag 5 februari 2021 12:50 >> To: programm...@jsoftware.com >> Subject: Re: [Jprogramming] Progressive insertion into a string

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread Ric Sherlock
t; > > > -Original Message- > From: Programming On Behalf Of > Hauke Rehr > Sent: vrijdag 5 februari 2021 12:50 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Progressive insertion into a string > > > > It took me a little to understand

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
com Subject: Re: [Jprogramming] Progressive insertion into a string I’ll sure take a look. I do think this belongs into any idiomatic J programmer’s toolset. Is there actually a kind of compilation of such a toolset yet? I found some spread on the phrases & dictionary which both serve a broade

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread Hauke Rehr
Of > Hauke Rehr > Sent: vrijdag 5 februari 2021 12:50 > To: programm...@jsoftware.com > 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-b

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
where I learned it. R.E. Boss -Original Message- From: Programming On Behalf Of Hauke Rehr Sent: vrijdag 5 februari 2021 12:50 To: programm...@jsoftware.com Subject: Re: [Jprogramming] Progressive insertion into a string It took me a little to understand why this works

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
sage- From: Programming On Behalf Of Hauke Rehr Sent: vrijdag 5 februari 2021 12:50 To: programm...@jsoftware.com 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 thi

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread Hauke Rehr
+--+ > > Then > >soln (-: 'X' v0a L:0 ])&}:data > 1 > > > R.E. Boss > > > -Original Message- > From: Programming On Behalf Of > R.E. Boss > Sent: vrijdag 5 februari 2021 10:33 > To: pr

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
---+--+ 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 On Behalf Of Ric Sherlock Sent: vrijdag 5 februari 2021 02:35 To: Programming JForum Subject: Re: [Jprogramming] Progress

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
S:0 v0 L:0 }:data NB. All (but last) solutions are correct 1 1 1 1 R.E. Boss -Original Message- From: Programming On Behalf Of Ric Sherlock Sent: vrijdag 5 februari 2021 02:35 To: Programming JForum Subject: Re: [Jprogramming] Progressive insertion into a string Yes as Hau

Re: [Jprogramming] Progressive insertion into a string

2021-02-05 Thread R.E. Boss
;THEEQUICKBROWFOOX' 1 R.E. Boss -Original Message- From: Programming On Behalf Of Ric Sherlock Sent: donderdag 4 februari 2021 13:41 To: Programming JForum Subject: Re: [Jprogramming] Progressive insertion into a string This is very nice Pascal, but not quite right. The correct o

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
showDigraphs 'AAXAbbCCCXC' "AA,XA,bb,CC,CX,C" No as you can see there are 3 digraphs in that string that have repeated letters. dedouble 'AAAbb' AXAXAbbCCXCXC On Fri, Feb 5, 2021 at 6:02 PM Devon McCormick wrote: > So like this? >dbld=. <"1]_2 ]\ str >;dbld,&.>(>=/&>dbld){'';

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Devon McCormick
So like this? dbld=. <"1]_2 ]\ str ;dbld,&.>(>=/&>dbld){'';'X' AAXAbbCCCXC On Thu, Feb 4, 2021 at 11:56 PM Ric Sherlock wrote: > Only repeats that occur within a digraph need to be split, so: > >showDigraphs dedouble 'AAABB' > "AX,AX,AB,BC,CX,CX,C" > > On Fri, Feb 5, 2021 at 5:53

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
Only repeats that occur within a digraph need to be split, so: showDigraphs dedouble 'AAABB' "AX,AX,AB,BC,CX,CX,C" On Fri, Feb 5, 2021 at 5:53 PM Devon McCormick wrote: > How do you propose to handle triples and so on? If you are using _2]\ > instead of 2]\, you miss half the repeats. >

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Devon McCormick
How do you propose to handle triples and so on? If you are using _2]\ instead of 2]\, you miss half the repeats. str=. 'AAAbb' ((2 ]\ ]);_2 ]\ ]) str NB. Two ways of windowing. +--+--+ |AA|AA| |AA|Ab| |Ab|bC| |bb|CC| |bC|C | |CC| | |CC| | |CC| | +--+--+ dbld=. 2 ]\ str ' '-.~,

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
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, 20

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ben Gorte
Ah yes, better! Works on the five test cases :-) On Thu, 4 Feb 2021 at 23:13, Ric Sherlock 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

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Raul Miller
Well... That's actually a pretty big flaw in my implementation -- once there's a letter pair which is not in a digraph, my rewrite completely fails. It's certainly fixable, but with significant added complexity. For example, this almost works: lookup=: {&((8#2),8$0 3) digrap=: # {. {. , 2|[:]F:

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
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

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Hauke Rehr
The reason is ignorance on my side, so that’s a bad one :-) Am 04.02.21 um 17:29 schrieb Raul Miller: > The problem with 0,~ is that it throws an error when dedouble is > passed an empty argument. Is there a good reason for throwing that > error? > > Thanks, > -- -- mail wr

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Raul Miller
The problem with 0,~ is that it throws an error when dedouble is passed an empty argument. Is there a good reason for throwing that error? Thanks, -- Raul On Thu, Feb 4, 2021 at 10:31 AM Hauke Rehr wrote: > > Now that looks way better than what I did. > After digra, it works differently. > I’d

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Michael Day' via Programming
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

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Hauke Rehr
Now that looks way better than what I did. After digra, it works differently. I’d still say 0,~ instead of #{. because there is no dependence on its #, really. Every now and then I see uses of j. I wouldn’t have thought of. Is the list at the bottom of nuvoc’s jdot entry complete? I should start m

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Hauke Rehr
My solution should have met the specification. But you’re right, it’s far from simple (though its idea is – so I’m just bad at J). Am 04.02.21 um 11:49 schrieb Ric Sherlock: > Sorry I should have been a bit more explicit with the specification. > > The reason that the double O in the 2nd example

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Raul Miller
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 ca

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Michael Day' via Programming
I know you're interested in developing encode and decode for Playfair, but members _might_ like to know that the London Times "Listener" crosswords*, which appear every Saturday,  occasionally employ Playfair codes. FYI,  I've found these pertinent puzzles in my records:    4236  4303  4406  44

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
This is very nice Pascal, but not quite right. The correct output for 'THEEQUICKBROWFOOX' should be 'THEXEQUICKBROWFOOX' (See reply to Raul for more detail) If we could get it to only apply to the first instance of a doubled digraph, then iterating until there is no more change (^:_) would produce

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
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 wrote: > Think I've got it: > > data1 =: 'THEEQUICKBROWFFOX' > > data2 =: 'THEEQUICKBROWFOOX' > > {{ ((

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Ric Sherlock
Sorry I should have been a bit more explicit with the specification. The reason that the double O in the 2nd example does not get an X inserted is that once the X is inserted for the first double, the Os are split between 2 digraphs and no longer require to be separated. In other words, after the

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Pascal Jasmin' via Programming
if spaces are not allowed, then without boxing: (' ' -.~ ,)@:(_2&(,`([,'X',])@.=/\)) 'THEEQUICKBROWFOOX' THEXEQUICKBROWFOXOX On Thursday, February 4, 2021, 03:57:44 a.m. EST, Hauke Rehr wrote: doesn’t all that boxing/unboxing and cutting/gluing hurt? maybe I have to stop thinking ab

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Hauke Rehr
doesn’t all that boxing/unboxing and cutting/gluing hurt? maybe I have to stop thinking about improvements that actually aren’t improvements. Nice readable approach! Am 04.02.21 um 09:51 schrieb 'Pascal Jasmin' via Programming: > assuming you want all dedoubled on a pass and not just first match,

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Pascal Jasmin' via Programming
assuming you want all dedoubled on a pass and not just first match, ;@:(_2&(,`([,'X',])@.=/each@<\))^:_ 'THEEQUICKBROWFFOOOX' THEXEQUICKBROWFXFOXOXOX ;@:(_2&(,`([,'X',])@.=/each@<\)) 'THEEQUICKBROWFFOOOX' THEXEQUICKBROWFFOOXOX On Wednesday, February 3, 2021, 11:02:49 p.m. EST, Ric Sherlo

Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread Hauke Rehr
Ouch, I made the same mistake, but even worse. This time I actually care about a possible doublette at the very start. And the code looks a little bit less messy this way. But I’m done playing with this. I think Ben’s version is okay. Getting it done without looping may be interesting, but I don’t

Re: [Jprogramming] Progressive insertion into a string

2021-02-03 Thread Hauke Rehr
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 solu

Re: [Jprogramming] Progressive insertion into a string

2021-02-03 Thread 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

Re: [Jprogramming] Progressive insertion into a string

2021-02-03 Thread Hauke Rehr
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

Re: [Jprogramming] Progressive insertion into a string

2021-02-03 Thread Raul Miller
I would be tempted to go with dedouble=: #!.'X'~ 1 j. #{.}.=}: But I do not understand why the double O in your second example does not get an X inserted. So maybe I am missing something. I hope this helps, -- Raul On Wed, Feb 3, 2021 at 11:02 PM Ric Sherlock wrote: > > I need to separate an

[Jprogramming] Progressive insertion into a string

2021-02-03 Thread 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 separ