Re: [Jprogramming] Determining an 'alternating' binary array

2012-07-27 Thread Linda Alvord
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

Re: [Jprogramming] cap

2012-07-27 Thread Dan Bron
Raul wrote: > Anyways, the definition which is relevant when cap is the left tine of > a fork is a passive definition, and not an imperative definition. And > making this distinction -- that it's being used passively -- seems > worthwhile. I responded: > There are several issues with this i

Re: [Jprogramming] cap

2012-07-27 Thread Dan Bron
Raul wrote: > Anyways, the definition which is relevant when cap is the left tine of > a fork is a passive definition, and not an imperative definition. And > making this distinction -- that it's being used passively -- seems > worthwhile. There are several issues with this interpretation.

Re: [Jprogramming] Determining an 'alternating' binary array

2012-07-27 Thread Marshall Lochbaum
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 ha

Re: [Jprogramming] cap

2012-07-27 Thread km
I like to think of Cap [: as a left identity element for the tree representation of a fork. f g h is g f h and [: g h is g h Sent from my iPad On Jul 27, 2012, at 8:10 AM, Raul Miller wrote: > On Thu, Jul 26, 2012 at 7:43 PM, Dan Bron wrote: >> In a draft, I had originally written

Re: [Jprogramming] Determining an 'alternating' binary array

2012-07-27 Thread Brian Schott
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

Re: [Jprogramming] Determining an 'alternating' binary array

2012-07-27 Thread Raul Miller
alternate=: 0 1 *./@e.~ , , +/,-&(+/\)/&(\:~) In other words, we are requiring that the following only gives us 1s and 0s: [a] The starting data [b] The sums of the two rows [c] The difference of the running sums of these two rows (rearranging the rows so that the leftmost 1 appears in the first

[Jprogramming] Determining an 'alternating' binary array

2012-07-27 Thread David Vaughan
I have an array of shape (2 n), and I want to determine if it has a kind of alternating pattern, where 1s must appear on alternate rows, when reading from left to right. Some examples that do 'alternate': 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 Some exampl

Re: [Jprogramming] cap

2012-07-27 Thread Raul Miller
On Thu, Jul 26, 2012 at 7:43 PM, Dan Bron wrote: > In a draft, I had originally written "Meaning its definition is irrelevant". > I think that sums it up. Change "definition" to "imperative definition" and that seems reasonable. Mostly we think of using J verbs using their imperative tense. Geru