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

2012-08-10 Thread Roger Hui
May I suggest you make this into an essay in the Wiki? On Fri, Aug 10, 2012 at 2:49 PM, Peter B. Kessler < peter.b.kess...@oracle.com> wrote: > In response to my request for a solution to the alternating binary array > problem that uses J's Sequential Machine (;:) verb, Raul Miller posted > thi

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

2012-08-10 Thread Peter B. Kessler
In response to my request for a solution to the alternating binary array problem that uses J's Sequential Machine (;:) verb, Raul Miller posted this[1] Here's an implementation which uses ;: smalt=: 12 > (3;1,~&>0 1 2 3,1 3 2 3,2 1 3 3,:3)&;:@:#.@|: I thought it would be worth writing Raul's

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

2012-08-03 Thread Raul Miller
On Fri, Aug 3, 2012 at 2:43 AM, Ian Shannon wrote > NB this also shows that garbage collection or something similar might be > affecting the times as I obtain different "curves" running this (and similar) > expressions multiple times. Yes, you get a lot of features from the host OS and the unde

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

2012-08-02 Thread Ian Shannon
Roger Hui writes: > >timer=: 6!:2 > >] t=: 3 : 'timer ''+/\a'' [ a=.y?@$0'"0 ] n=: 1e4 * 2 ^ i.7 > 0.000123759 0.000225448 0.000207568 0.000373511 0.00126888 0.00315096 > 0.00598093 > >load 'plot' >plot n;t > > Looks pretty linear to me. Linear? well maybe, interesting Yes.

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

2012-08-01 Thread Roger Hui
Peter Kessler writes: > For example, I love the use of "+/\" in the above to propagate the state of the match. > (Though, I worry a little about the efficiency of it, if prefix really reapplies the verb to > each of the possible prefixes, especially as the inputs get long.) See Appendix B of the

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

2012-07-31 Thread Thomas Costigliola
olution to the >> alternating 1's problem? >> >> Conversely, why is it not J-like to filter out the 0 0 columns (and check >> for 1 1 columns while you are there), then match successive 2x2 blocks to >> make sure they are all the same? Either "2 2 $ 0 1 1 0" o

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

2012-07-31 Thread Raul Miller
ose an > order.) I'm sure it would take me hours to construct that expression, and > maybe I shouldn't spend the time, if that's not the J way to do things like > this. Is that not J-like because I shouldn't be thinking in terms of > iterating over the input? >

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

2012-07-31 Thread R.E. Boss
> Van: Peter B. Kessler > Verzonden: maandag 30 juli 2012 22:12 (...) > > This doesn't address the case where both inputs have 1's in the same column > > ]C=:2 5 $ 1 0 0 1 0 0 1 0 1 0 > 1 0 0 1 0 > 0 1 0 1 0 > (>./-<./)+/\+/1 _1 *C > 1 > > The original stateme

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

2012-07-31 Thread Raul Miller
Actually, I said something in my previous post which was wrong: Function code 3 for sequential machine gives state table index. (This is not useful for a lot of the text processing I would like to do (where I want the state table index for each character being processed) but it's fine for this ap

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

2012-07-30 Thread David Ward Lambert
gt;) TESTDATA fsm=: (FUNCTION;STATE;MAP)&;: assert(2(#,:)1 1 1 0 1 1 1 0 0 0 0)-:(_1-.@:-:fsm ::_1:)@>TD > Date: Mon, 30 Jul 2012 13:12:29 -0700 > From: "Peter B. Kessler" > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Determining an 'alterna

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

2012-07-30 Thread Linda Alvord
mming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Devon McCormick Sent: Monday, July 30, 2012 7:24 PM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Determining an 'alternating' binary array You could implement this latter idea

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

2012-07-30 Thread Marshall Lochbaum
time, if that's not the J way to do things like > this. Is that not J-like because I shouldn't be thinking in terms of > iterating over the input? > > I'm trying to learn to think like a J programmer. Thanks for teaching me > to fish. > > .

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

2012-07-30 Thread Devon McCormick
You could implement this latter idea something like this: ok0;ok1=. 1|.ok0=. 1 0 ,: 0 1 +---+---+ |1 0|0 1| |0 1|1 0| +---+---+ (ok0;ok1) ([: *./ [: }: [: {. [: > [: +.&.>/ [ E.~&.>~ [: < 0 0 -.&.|:~ ]) C 0 ]Cok=:2 5 $ 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 (ok0;ok1) ([: *./ [: }: [

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

2012-07-30 Thread Peter B. Kessler
Thank you, thank you, thank you! I'll digest your mail, spend a few more productive hours with the Dictionary, and send comments, but this looks like the kind of explanation I've been wanting. ... peter Raul Miller wrote: On Mon, Jul 30, 2012 at 4:12 PM, Peter B. Kess

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

2012-07-30 Thread Raul Miller
On Mon, Jul 30, 2012 at 4:12 PM, Peter B. Kessler wrote: > In the "alternating binary array" case, it seems, to me, like what's called > for is a small finite state machine (or regular expression parser, if that's > how you think). Start in a neutral state, and move to a new state on > reading a

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

2012-07-30 Thread Peter B. Kessler
... peter -Oorspronkelijk bericht- Van: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] Namens Linda Alvord Verzonden: zaterdag 28 juli 2012 9:43 Aan: programm...@jsoftware.com Onderwerp: Re: [Jprogramming] Determining an 'al

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

2012-07-30 Thread Raul Miller
; So A qualifies, B does not. > > > R.E. Boss > > >> -Oorspronkelijk bericht- >> Van: programming-boun...@forums.jsoftware.com >> [mailto:programming-boun...@forums.jsoftware.com] Namens Linda Alvord >> Verzonden: zaterdag 28 juli 2012 9:43 >> Aan: programm..

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

2012-07-28 Thread R.E. Boss
zonden: zaterdag 28 juli 2012 9:43 > Aan: programm...@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)$~

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

2012-07-28 Thread Linda Alvord
Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Linda Alvord Sent: Saturday, July 28, 2012 3:14 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Determining an 'alternating' binary arr

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

2012-07-28 Thread Linda Alvord
re.com] On Behalf Of Linda Alvord Sent: Saturday, July 28, 2012 2:45 AM To: programm...@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

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

2012-07-27 Thread Linda Alvord
[: |: /:~ alt A 1 alt B 0 Linda -Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Marshall Lochbaum Sent: Friday, July 27, 2012 11:56 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] De

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] 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