Here's a home grown solution that might be interesting:
A=:L, 3 7 2 5
B=:7 2
f=: 13 :'x-:"1(i.$x){"1(($y),>:$y)$y'
f=: 13 :'x-:"1(i.$x){"1(($y),>:$y)$y'
B f A
0 1 0 0 0 0 0 1 0 0
Linda
-----Original Message-----
From: Programming <[email protected]> On Behalf Of Skip
Cave
Sent: Friday, October 26, 2018 5:14 PM
To: [email protected]
Subject: Re: [Jprogramming] Sub-string Matching
Thanks Mike and R.E. Boss!
The boolean version ssmb =. +./@E. is what I needed.
The non-boolean ssm=. +/@E. is nice in that it indicates multiple occurrences
of the string, though I don't really need it for what I was working on.
]a=. 1 2 3 4 ; 1 2 4 5 6; 1 3 2 5 4 1 ; 2 3 5 1 2 ; 1 2 3 1 2 3
┌───────┬─────────┬───────────┬─────────┬───────────┐
│1 2 3 4│1 2 4 5 6│1 3 2 5 4 1│2 3 5 1 2│1 2 3 1 2 3│
└───────┴─────────┴───────────┴─────────┴───────────┘
2 3 ssm"1 >a
1 0 0 1 2
2 3 ssmb"1 >a
1 0 0 1 1
]b=. 0 1 0 1 0;0 1 1;1 0 1 0 1 0 0 1 0 1 0 0 1;1 0 1 1 0 1 0;0 1 1 1 0;0 1
1 0 1 1
┌─────────┬─────┬─────────────────────────┬─────────────┬─────────┬───────────┐
│0 1 0 1 0│0 1 1│1 0 1 0 1 0 0 1 0 1 0 0 1│1 0 1 1 0 1 0│0 1 1 1 0│0 1 1 0
1 1│
└─────────┴─────┴─────────────────────────┴─────────────┴─────────┴───────────┘
1 1 ssm "1 >b
0 1 0 1 2 2
1 1 ssmb "1 >b
0 1 0 1 1 1
However:
0 0 ssm "1 >a
1 0 0 0 0 NB. Wrong!
0 0 ssmb "1 >a
1 0 0 0 0 NB. Wrong!
0 0 ssm "1 >b
8 9 2 6 8 6 NB. Wrong!
0 0 ssmb "1 >b
1 1 1 1 1 1 NB. Wrong!
All wrong! So detecting zeros is a problem with this scheme because of J's
zero-fill rule..
Skip
----------------------------------------------------------------------
For information about J forums see
https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&data=02%7C01%7C%7C900c85b67ea14a6afb4608d63b880074%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636761852634187360&sdata=O1h2xm4SxHPOSD%2B3oaMaxXLOEMgcQrnzEWclgpBDKXk%3D&reserved=0
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm