Not 100% sure it is bug in `:6 or the interaction with F.. ex
mjqjpqmgbljsphdztnvjfqwrcgsmlb ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) {{(4;~4{.]) u (4}.])}} ex NB. desired result ┌────┬─┐ │jpqm│7│ └────┴─┘ where {{(4;~4{.]) u (4}.])}} is a preprocessing adverb alternative to a fork, that will make a fork from its binding. code dump: isNoun =: (0 = 4!:0 ::0:)@:< isgerund =: 0:`(0 -.@e. 3 : ('a =. y (5!:0)';'1')"0)@.(0 < L.) :: 0: ar =: 1 : '5!:1 <''u''' ari =: 1 : 'if. isNoun ''u'' do. if. (isgerund -.@+. '''' -: ]) m do. m ar else. m end. else.u ar end.' ti =: ari ` ari NB. different from doubleadverb2.ijs: '' is passed to ` . boxed non gerund is ar'd ie a:`u ti2 =: ar ` ar F0 =: 1 : 'u ti ti `: 6' v2c =: 1 : '[. u ].' F1 =: 1 : '(ti u) ti (''''ti) `:6' F2 =: 1 : 'ti ti u `: 6' F01 =: ((ti (2 : 'ti')))(`:6) F02 =: 2 : '(u`)(`v)(`:6)' F02 =: ( ([.(2 : 'ti')) (2 : 'ti' ].) ) (`:6) F12 =: (2 : 'ti' ti) `: 6 The F02 conjunction returns an adverb and is identical in function to {{(4;~4{.]) u (4}.])}} when it is used as (4;~4{.]) F02 (4}.]) (ie. it binds params 0 and 2 of a fork, and waits to bind param 1 as an adverb) (4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) (4;~4{.]) F02 (4}.]) ex |noun result was required This seems like "too aggressive" invocation of "noun result expected" when `:6 is involved. Perhaps as interaction with explicit conjuncitons. when "normal" parameters are given to adverb, everything works as expected. including with intervening adverbs. [ ]: (4;~4{.]) F02 (4}.]) ex ┌────┬─┐ │mjqj│4│ └────┴─┘ The following displays are just the first line of multiline definition of Fold F.. ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) (4;~4{.]) F02 (4}.]) (4 ;~ 4 {. ]) ] (2 : 0) (((1 >:@({::) ]) ,&<~ [ ,~ _3 ({.) 0 {:: ])`(_2 Z: 1:)@.(4 = 0 #@~.@({::) ])) 4 }. ] NB. first line leading multiline definition (2 : 0 ) for F.. ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) {{(4;~4{.]) u (4}.])}} (4 ;~ 4 {. ]) ] (2 : 0) (((1 >:@({::) ]) ,&<~ [ ,~ _3 ({.) 0 {:: ])`(_2 Z: 1:)@.(4 = 0 #@~.@({::) ])) 4 }. ] NB. identical replacing the output of the F02 version for 2 : 0 with F.., is correct ((4 ;~ 4 {. ]) ] F.. (((1 >:@({::) ]) ,&<~ [ ,~ _3 ({.) 0 {:: ])`(_2 Z: 1:)@.(4 = 0 #@~.@({::) ])) 4 }. ]) ex ┌────┬─┐ │jpqm│7│ └────┴─┘ all of the modifiers that use `:6 fail with the same error. v2c (doesn't use `:6, and is equivalent to F1) works. it doesn't appear to be a bug in "explicit conjunctions" (those that reference x and y) - (+: 2 : 'x u@v y') -:@[ F02 (+:@]) -:@[ +: (2 : (':'; 'x u@v y')) - +:@] : 2 - (+: 2 : 'x u@v y') -:@[ F02 (+:@]) 3 _10 NB. 1 and 6 are result of v0 and v2. 1 +:@- 6 = _10 One possible fix that would make everything cleaner is if (] F..) did not expand to explicit definition. It is not needed yet,as a primitive. On Thursday, December 8, 2022 at 02:34:58 p.m. EST, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: mistake in Z definition found, Zl =: ] [ _3 Z: [ makes this work, ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Zl ]) F..) (4}.])) ex but still ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Zl ]) F.) (4}.])) ex |domain error On Thursday, December 8, 2022 at 02:15:39 p.m. EST, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: The short circuit you are trying to avoid is to skip the full partitioning part 4 #@~.\4 one approach is to separate into the simplest possible partition, then hope that i. special code finds the short circuit. 4 + (1 i.~ 4 = #@~."1) 4 ]\ ex your power approach is completely reasonable. A fold approach is complicated by seeking the index rather than a "computed result" There might be too much manipulated computation involved, but the general approach would be: x parameter to fold is (a: ,< 0) NB. initial y. if head cell of y is shorter than 4, then append x to last 3 chars. (better to preprocess y such that x (to F.) has first 4 chars, and y omits first 4.) if head is length 4, then apply test ((1 >:@{:: ] ) ,&<~ [,~ _3{.0{::])`(_2 Z: 1:)@.(4 = #@~. 0 {:: ]) ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) (4}.])) ex ┌────┬─┐ │jpqm│7│ └────┴─┘ I don't understand why this fails: (F. instead of F..) Z =: ] [ Z: ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Z~ _3:) F.) (4}.])) ex |domain error or ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F.) (4}.])) ex |domain error also it is not documented whether F. or F: are forward or reverse. On Thursday, December 8, 2022 at 11:28:12 a.m. EST, 'Michael Day' via Programming <programm...@jsoftware.com> wrote: Having remarked recently (re Advent of Code day 6): Very easy today, in J at least, and probably in APL & K/Q. (Though it suggests one should learn the new fold features, as it's inefficient to examine all the data for something that might occur early. No problem with 4kb, but ....) I've just had a look at the Jwiki entries about Fold, and wonder how it would work for day 6. The problem is so easy for J-ers that I don't think this will spoil it for forum users: ex mjqjpqmgbljsphdztnvjfqwrcgsmlb 4 + 4 i.~ 4 #@~.\ ex 7 QED #data NB. the size of my data set 4096 ts'4 + 4 i.~ 4 #@~.\ data' NB. time & space 0.0008555 67232 I didn't bother making a function for this! One way to stop early, rather than process the whole array, is this: ts'4 + (# - #@:((}.`])@.(4&([ = #@:~.@:{.))^:_)) data' 0.0007299 4736 (I know it's ugly, and non-optimal!) Similar time but with ca 14x space-saving. But there must be some sort of Fold to progressively examine 4-windows, or 14-windows in part 2, until the first appropriate window is found, when it stops. That should save time as well as space. Not necessary here, of course, but if there was a real application with many megabytes of data... Cheers, Mike On 06/12/2022 19:46, Brian Schott wrote: > I have successfully solved Day 5 using the following looping verb `tomove` > but cannot craft a Fold version, and would like help. > > *[FYI I have included an attachment that seems to load and execute > properly, but I could NOT get the email versions to load correctly, > presumably because of some funny characters.]* > > tomove=: dyad define > while. #y do. > x=.x move {. y > y =. }.y > end. > x > ) > > > NB. The verb `move` for part 1 is very simple: > > move =: dyad define > 'n f t'=. _1 1 1*y - 0 1 1 > take =. |.n{.>f{x > left =. <n}.>f{x > put =. <take,~>t{x > (left,put) (f,t)}x > ) > > NB. the inputs are produced as follows. > > top =: 0 :0 > [D] > [N] [C] > [Z] [M] [P] > 1 2 3 > ) > > state=.deb each ;/ |:|.}:1 5 9&{;._2 top > > bottom =: 0 :0 > move 1 from 2 to 1 > move 3 from 1 to 3 > move 2 from 2 to 1 > move 1 from 1 to 2 > ) > alpha =. a. {~97+i.26 > moves =. ".-.&alpha ;._2 bottom > > NB. finally the result is produced by the next phrase > > {:every state tomove moves > > > ---------------------------------------------------------------------- > For information about J forums seehttp://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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm