---Raul Miller wrote:
> On Thu, Jul 10, 2008 at 6:47 PM, Sherlock, Ric wrote:
> > a b c c d e e <span>e e e</span> f e f e f a a
> <span>a</span> f f <span>f</span>
> >
> > In English:
> > Group together all duplicate items that occur anytime
> beyond twice by wrapping them with a tag, naturally "bookending" them.
> >
> > Spoiler Alert.
> > ==============
> >
> >
> > Finding the mask of the atoms that need enclosing was Ok.
> But I find my solution for enclosing them long winded and
> overly complex. Is there a better way?
>
> t=: <"0 'abccdeeeeefefefaaafff'
>
> span=: (]`2:`[} '<span>' <@, 2&{::)@(]`_1:`[} '</span>' <@,~
> _1&{::)^:(2<#)
> teas=: [:; ,&.>&' '@;@(<@span/.~ 1 +/\@, 2 ~:/\ ])
>
> teas t
> a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f
> <span>f</span>
Using ideas from Raul's and Oleg's posts simplifies my solution:
msk1=: 0 0 , 3 (1 = [EMAIL PROTECTED])\ ]
group1=: ] </.~ [: +/\ 1 , 2 ~:/\ msk1
space=: }.@,@(' '&,.)&.>
bookend=: ;@,@(] ,. (' <span>';'</span> ') $~ #)
bookend space group1 t
a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f <span>f</span>
However my original code was faster and leaner:
ts=: 6!:2 , 7!:2 @]
(100) ts 'bookend space group t'
2.51652e_5 2816
(100) ts 'bookend space group1 t'
0.000119682 3008
(100) ts 'teas <"0 t'
0.0002852 5440
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm