Re: [Jprogramming] String replace puzzle

2020-12-19 Thread Raul Miller
I haven't seen anyone spell it out here, but the answer to your enigma is the same as the reason that you didn't need to perform a sequence of replacements: The code is designed such that all replacements happen against the original string. So you would have to stringreplace again to complete the

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Skip Cave
n=.'1+(2*3)+(4*(5+6))' '()'i.n 2 2 0 2 2 2 1 2 0 2 2 0 2 2 2 1 1 Now THAT is cool! I forgot one could use dyadic i. as "first occurrence". That's a much simpler way to generate the amend indices. . Skip Cave Cave Consulting LLC On Fri, Dec 18, 2020 at 12:21 PM 'Michael Day' via Programming <

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread xash
|. ('()'i.n)} ')','(',: n or tacit ([:|. ('()'&i.)`(')','(',:])}) n On Fri Dec 18, 2020 at 10:35 PM CET, Skip Cave wrote: > Using curlyrt: (amend in place) > > n=.'1+(2*3)+(4*(5+6))' > > > |.(+/1 2*'()'=/n)}n,(17#')'),:(17#'(') > > ((6+5)*4)+(3*2)+1 > > > > Skip Cave > Cave Consulting LLC > > > O

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Jimmy Gauvin
Hi, " amend in place " , that's very cool Thanks for demonstrating a practical use case. Jimmy PS you can use #.(base 2 decode) to replace +/1 2* On Fri, Dec 18, 2020 at 4:36 PM Skip Cave wrote: > Using curlyrt: (amend in place) > > n=.'1+(2*3)+(4*(5+6))' > > > |.(+/1 2*'()'=/n)}n,(17#'

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Skip Cave
Using curlyrt: (amend in place) n=.'1+(2*3)+(4*(5+6))' |.(+/1 2*'()'=/n)}n,(17#')'),:(17#'(') ((6+5)*4)+(3*2)+1 Skip Cave Cave Consulting LLC On Fri, Dec 18, 2020 at 12:21 PM 'Michael Day' via Programming < programm...@jsoftware.com> wrote: > Unlike in the K forum, the J-wires have been

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'robert therriault' via Programming
Slightly different approach by converting over and back from integers and doing some arithmetic |.@:(+ (+/ @: (1 _1 * 40 41 =/ ]))) &. (3&u:) '1 + (2 * 3) + (4 * (5 + 6))' ((6 + 5) * 4) + (3 * 2) + 1 Cheers, bob > On Dec 18, 2020, at 12:12, 'Michael Day' via Programming > wrote: > > Yes

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Joseph Novakovich
Right! 0 1 =/ '()' i. y is just '()' =/ y... Yes, day 15/2 is unfortunately similarly slow for me, where I update a length 3e7 array to track times. An equivalent scheme version manages in <600ms. The gap in performance is odd... Joseph On 12/18/20, 'Michael Day' via Programming wrote: > Yes, I

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
Yes, I ended up indexing brackets with    I. '()' =/ y ,  assuming that the left & right brackets were balanced! Part 2 was long-winded, recursive,  but evaluated quickly, luckily. My slowest routine for any of these posers is for part 2 of Day 15; best I managed was ~ 40 seconds. Cheers, M

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Joseph Novakovich
For part 1 I used pretty much the same approach, eval by way of reversing (|.&.;:): +/ {{".'('c}')'o}y['o c'=. I. 0 1=/'()'i.y=.|.&.;:y}}&> in Mine differs mostly in avoiding library definitions, amending parens by index. For part 2 I used ;: to calculate a depth vector for the tokens and then

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
Thanks, Brian - I thought I needed to put in a temporary intermediate value to avoid reversing the first change,  hence the three pairs rather than two. But the enigma remains, doesn't it:  what stops ']' becoming ')' ? Do rplc and/or stringreplace only work on a maximum of two pairs of before

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Brian Schott
What about the following? ( '()',')(' ) stringreplace|. '1 + (2 * 3) + (4 * (5 + 6))' ((6 + 5) * 4) + (3 * 2) + 1 On Fri, Dec 18, 2020 at 1:21 PM 'Michael Day' via Programming < programm...@jsoftware.com> wrote: > Unlike in the K forum, the J-wires have been virtually silent on this > year

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Peter Vernigorov
For the first part you can use charsub - https://www.jsoftware.com/help/user/lib_strings.htm#charsub '())('charsub |.'1*2+(3*4)' (4*3)+2*1 On Fri, Dec 18, 2020 at 19:21 'Michael Day' via Programming < programm...@jsoftware.com> wrote: > Unlike in the K forum, the J-wires have been virtually

[Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
Unlike in the K forum,  the J-wires have been virtually silent on this year's Advent of Code... Anyway,  today's problem,  number 18,  might interest J & APLers as part 1 is ALMOST plug-it-in to J/APL;  there's just one twist,  so to speak,  namely we need to reverse an arithmetic expression,