modifications in T denoted by ^^^^

T=: 3 : 0
NB. count number of repetitions
 t0=. ;<@i."0 #/.~ +/\1,2~:/\y
NB. identify where number is 1 and next number is 2 and identify last number
NB.
^^^^^^^^^^^^^^^^^^^^^^^
NB. identify where number is 2 or more and 
NB.     (next number is 0) or (number is last), add last identifiers
 t10=.(1 (_1})(2=1|.t0)*.t0=1.)+.(0=1|.!.0 t0)*.t0>1
NB.   ^^^^^^^^
NB. box string accordingly, add spaces after each token in a box,
NB.   except for the last token
 t1=. (' '}:@,@,.~])&.> y <;.2~ t10
NB. make (#t1) $' <span>';'</span> '
 t2=.(#t1) $' <span>';'</span> '
NB. stitch the last 2 together and ravel
NB. if t is odd delete last box, and raze
 ;}:^:(2|#t1),t1,.t2
)

   t3=: 'abccdeeeeefefefaaaffg'
   T t3
a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f g


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens Sherlock, Ric
> Verzonden: zaterdag 12 juli 2008 1:22
> Aan: Programming forum
> Onderwerp: RE: [Jprogramming] Programming brain-teaser
> 
> ---R.E. Boss wrote:
> > NB. if t is odd, delete last box and raze
> >    ;}:^:(2|#t1),t1,.t2
> > 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>
> >
> >
> > T=: 3 : 0
> > t0=. ;<@i."0 #/.~ +/\1,2~:/\y
> > t1=. (' '}:@,@,.~])&.> y <;.2~((2=1|.t0)*.t0=1.)+.(0=1|.!.0 t0)*.t0>1
> > t2=.(#t1) $' <span>';'</span> '
> > ;}:^:(2|#t1),t1,.t2
> > )
> 
> Both your solution and mine need fixing to handle cases with odd numbers
> of groups. Raul's is fine.
>    t3=. 'abccdeeeeefefefaaaffg'
> 
>    bookend space group1 t3
> a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f g <span>
>    T t3
> a b c c d e e <span>e e e</span> f e f e f a a <span>a</span>
>    teas <"0 t3
> a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f g
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to