join where

hi,

i get a list of strings from a system command - as example data:
q)show a:" "vs “a0 b0 c1 d0 e0 g1 h0 i0 ij”
“a0”
“b0”
“c1”
“d0”
“e0”
“g1”
“h0”
“i0”
“ij”

i want to “join where” adjacent lines have first line ending in “1”

q)b:“1”=last each a
q){$[b and not b[x-1];a[x,x+1];enlist a]}each til count a
,“a0”
,“b0”
(“c1”;“d0”)
,“d0”
,“e0”
(“g1”;“h0”)
,“h0”
,“i0”
,“ij”

i think there might be a shorter way using / or variants?

thanks! jack

do you mean this:

q)a:" "vs “a0 b0 c1 d0 e0 g1 h0 i0 ij”
q)b:“1”=last each a
q)?[(>)prior b;a(;)'next a;enlist each a]
,“a0”
,“b0”
(“c1”;“d0”)
,“d0”
,“e0”
(“g1”;“h0”)
,“h0”
,“i0”
,“ij”

?

thank you.

actually, i meant
? ?[p:(>)prior b;a(;)'next a;enlist each a]where not prev p

but i specified something different. thanks for the tip!

ok, maybe you want this then:

((til count a)except 1+where b) _ a

? :-)

sorry, better one is: (where not prev b) _ a

yeah, that is really nice
and you can do b a bit more efficiently too

q)\ts (where not prev"1"=last each a)_a

101 41666544

q)\ts (where not prev"1"=last flip a)_a

64 41666544

Cheers,

 Attila

How about this?

q)a:enlist each a

q)?[b;a,'next a;a]

,“a0”

,“b0”

(“c1”;“d0”)

,“d0”

,“e0”

(“g1”;“h0”)

,“h0”

,“i0”

,“ij”