Try also:

   t2 =: {. -: -...@[ {. ]

   a =: 1 2 3 4 1 2 3 4
   2 3 4 t2"0 1 a
0 0 1

It works like this:

     3{.a
1 2 3
   _3{.a
2 3 4   
   
   (4{.a) -: _4{.a
1

   4 t2 a 
1

   2 4 t2"0 1 (1 2 3 4 1 2 3 4)
0 1

   2 4 t2"0 1 ] 1 2 3 4 1 2 3 4
0 1



unigee wrote:
> 
> Hi
> 
> I seem to be having a bit of trouble performing this idea.
> 
> I am trying to get a subset of a list, and comparing the first element
> against the last element of the result.
> 
> 
>     2 >\/ (1 2 3 4 1 2 3 4)
> 1 2
> 2 3
> 3 4
> 4 1
> 1 2
> 2 3
> 3 4
> 
> t1 =: 4 : '(_1{a) -: (0{ a=. y >\/ (x))'
>    1 2 3 4 1 2 3 4 t1 2
> 0
> 
> 
>    4 >\/ (1 2 3 4 1 2 3 4)
> 1 2 3 4
> 2 3 4 1
> 3 4 1 2
> 4 1 2 3
> 1 2 3 4
> 
>    1 2 3 4 1 2 3 4 t1 4
> 1
> 
> t1 works as intended, but I am having trouble making it work with more
> than one right argument at a time
> Here are my failed attempts.
> 
>    1 2 3 4 1 2 3 4 t1 2 3 4 NB. result should be 0 0 1
> 0
> 
>    1 2 3 4 1 2 3 4 t1"0 2 3 4
> |length error
> |   1 2 3 4 1 2 3 4     t1"0 2 3 4
> 
>    1 2 3 4 1 2 3 4 t1 each (2 3 4)
> |length error
> |   1 2 3 4 1 2 3 4     t1 each(2 3 4)
> 
>    (1 2 3 4 1 2 3 4) t1"0 (2 3 4)
> |length error
> |   (1 2 3 4 1 2 3 4)    t1"0(2 3 4)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Checking-if-the-first-element-is-the-same-as-the-last-tp26282969s24193p26298117.html
Sent from the J Programming mailing list archive at Nabble.com.

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

Reply via email to