[Jprogramming] Determining an 'alternating' binary array
R.E. Boss
r.e.boss at planet.nl
Sat Jul 28 11:12:10 UTC 2012
My 2 cents:
(>./-<./)+/\+/1 _1 *A
1
(>./-<./)+/\+/1 _1 *B
2
So A qualifies, B does not.
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: programming-bounces at forums.jsoftware.com [mailto:programming-bounces at forums.jsoftware.com] Namens Linda Alvord
> Verzonden: zaterdag 28 juli 2012 9:43
> Aan: programming at jsoftware.com
> Onderwerp: Re: [Jprogramming] Determining an 'alternating' binary array
>
> In this case the tacit version leads to a better explicit definition:
>
>
> al=: 13 :'(-:((2 2$0 1 1 0)$~#))(|: y) -. 0 0'
> al
> [: (-: ((2 2$0 1 1 0) $~ #)) 0 0 -.~ |:
>
> al2=: 13 :'(-:(2 2$0 1 1 0)$~#)0 0 -.~|:y'
> al2
> [: (-: ((2 2$0 1 1 0) $~ #)) 0 0 -.~ |:
>
> Linda
>
> -----Original Message-----
> From: programming-bounces at forums.jsoftware.com
> [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Linda Alvord
> Sent: Saturday, July 28, 2012 3:14 AM
> To: programming at jsoftware.com
> Subject: Re: [Jprogramming] Determining an 'alternating' binary array
>
> This seems to work as well:
>
> (|:A)-: |: A/:A
> 1
> al=: 13 :'(-:((2 2$0 1 1 0)$~#))(|: y) -. 0 0'
> al
> [: (-: ((2 2$0 1 1 0) $~ #)) 0 0 -.~ |:
>
> al A
> 1
> al B
>
> -----Original Message-----
> From: programming-bounces at forums.jsoftware.com
> [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Linda Alvord
> Sent: Saturday, July 28, 2012 2:45 AM
> To: programming at jsoftware.com
> Subject: Re: [Jprogramming] Determining an 'alternating' binary array
>
> 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: programming-bounces at forums.jsoftware.com
> [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Marshall
> Lochbaum
> Sent: Friday, July 27, 2012 11:56 AM
> To: programming at jsoftware.com
> 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
> <schott.brian at gmail.com>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
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list