Here's an alternative to 'alternative'
]A=:2 8$ 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0
0 0 1 0 0 0 0 1
1 0 0 0 1 0 0 0
]B=:2 5$1 0 0 0 1 0 1 1 0 0
1 0 0 0 1
0 1 1 0 0
alt=: 13 :'(-:((2 2$0 1 1 0)$~#))(|: y /:y) -. 0 0'
alt
[: (-: ((2 2$0 1 1 0) $~ #)) 0 0 -.~ [: |: /:~
alt A
1
alt B
0
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Marshall
Lochbaum
Sent: Friday, July 27, 2012 11:56 AM
To: [email protected]
Subject: Re: [Jprogramming] Determining an 'alternating' binary array
Here's another option: convert the two rows into one using base 2, discard
the ones that are 0, and check if the remaining ones are 1 2 1...
I borrowed the sort in Raul's solution so that they must be in that order,
not 2 1 2... .
alternate =: (-: 1 2$~$)@:(0 -.~ #.@|:)@:/:~
Note that we don't have to convert to binary. In this case, we end up with
alternate =: (-: (0 1,:1 0)$~#)@:(0 0 -.~ |:)@:/:~
Marshall
On Fri, Jul 27, 2012 at 10:39 AM, Brian Schott
<[email protected]>wrote:
> Another approach?
>
> alternates =: [: -. 1 e. [: +/ 0 1 |."0 1 ] #"_ 1~ +./ noAnds =:
> *./@(-.@(*./)) check =: noAnds *. alternates
>
>
>
>
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm