Positive integers, obviously.  extension to an arbitrary set changes the
paradigm.

Integers only:

Arbitrary a:  a + ...

< c: 0 to c-a-1

Method: lower triangle of outer product convolution of iota, by indices.
The midline is equality:  excluded in the original statement, included here
as stated above.

Ravel to a list of pairs, take the ones needed (look carefully); sort as
desired.

I seem to recall a quickie that will generate the appropriate truth
triangle...

On Sun, Jan 25, 2009 at 12:52 PM, Ian Gorse <[email protected]> wrote:

> Hi list,
>
> I have been trying to find out a way how I can list all the positive
> numbers where a < b < c.
>
> For example, when c = 5, the output would be something like
>   2 6 $ 1 1 1 2 2 3 2 3 4 3 4 4 NB. example
> 1 1 1 2 2 3
> 2 3 4 3 4 4
> where the first row is a list of 'a' and the second row is a list of 'b'
>
> I have managed to do it with an explicit loop, but am looking for an
> alternative solution
>
> NB. Bruteforce
> list=: monad : 0
> a=.1
> b=.2
> c=.y
> result=.''
> while. b < c
> do.
> if. a < b do. result =. result , a , b end.
> b=.>:b
> if. b=c do. a=. >:a [ b=.a+1 end.
> end.
> n=. 2 ,~ 2 %~ #result
> |: n $ result
> )
>   list 5
> 1 1 1 2 2 3
> 2 3 4 3 4 4
>
> After starting this email, I noticed a pattern when I was running the
> script with higher values such as c= 10,
> and managed to re-write the script, instead of looping through all
> possible values (which is what my fist attempt does) I now use some
> simple math to find all the values instead.
>
> list2 =: monad : 0
> a=.1
> b=.2
> c=.y
> al=.'' NB. holds a list of a's
> bl=.'' NB. holds a list of b's
> while. a < c
> do.
> b=.(c-1)-a
> al=. al, b $ a
> bl=. bl , a+ >:i.b
> a=.>:a
> end.
> n=. 2, (#al)
> n $ al,bl
> )
>   list2 5
> 1 1 1 2 2 3
> 2 3 4 3 4 4
>
>   ts 'list 1000'
> 3.24764 1.25855e7
>   ts 'list2 1000'
> 0.046057 1.25852e7
>
> As you can see, list2 is by far a lot quicker than my original idea,
> but it still requires an explicit loop.
> Is there a solution to find a < b < c without such explicit loop?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Use Reply-To: & thread your email
after the first: or it may take a while, as
I get 2000+ emails per day.
--

Roy A. Crabtree
UNC '76 gaa.lifer#  11086

703-318-2106 (msgs only, use my name)

(mail, residence)
Roy A. Crabtree
3322 Wheeler Road SE
Oak Hill Apartments #T-4
Washington, DC 20032-4166

(secondary mail)
Roy A. Crabtree
USPS POB 58097
Washington, DC 20034-8097
[When you hear/read/see/feel what a y*ehudi plays/writes/sculpts/holds]
[(n)either violinist {Menuhin} (n)or writer {"The Y*ehudi Principle"} (n)or
molder (n)or older]
[you must strive/think/look/sense all of it, or you will miss the meanings
of it all]

[email protected] Forwards only to:
[email protected]
[email protected] CC: auto to ^

http://musings-roy-crabtree.blogspot.com [& others]
http://www.authorsden.com/royacrabtree
http://skyscraper.fortunecity.com/activex/720/resume/full.doc
--
(c) RAC/IP, ARE,PRO,PAST
(Copyright) Roy Andrew Crabtree/In Perpetuity
   All Rights/Reserved Explicitly
   Public Reuse Only
   Profits Always Safe Traded
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to