([EMAIL PROTECTED]&.(p:^:_1)@>: >./@([^ <[EMAIL PROTECTED]) ])"0[160+i.20
157 157 157 163 163 163 163 167 167 169 169 169 169 173 173 173 173 173 173
179

[EMAIL PROTECTED]&.(p:^:_1)@>:  NB. Hui's solution, excluding the first (2)
<[EMAIL PROTECTED]                              NB. floor of prime log y
>./@([^ <[EMAIL PROTECTED])             NB. maximum of prime ^ floor of prime 
>^. y

Since ^. and ^ are inverse of each other it can be reformulated to

    ([EMAIL PROTECTED]&.(p:^:_1)@>: >./@: (<.&.^.) ])"0[160+i.20
157 157 157 163 163 163 163 167 167 167 167 167 167 173 173 173 173 173 173
179


R.E. BOSS



-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Yuvaraj Athur Raghuvir
Verzonden: donderdag 21 september 2006 6:35
Aan: Programming forum
Onderwerp: Re: [Jprogramming] Explicit to Tacit - newbie question

Hello,

Putting together the previous mails, I have written my first J program to
find the nearest prime or prime power to a number.
Here I am excluding powers of 2.

Hurrah!!
I could move quite far until I had to loop that incremented and applied the
logic.

Program follows.

Can fpp be tacitly defined?

Regards,
Yuva

J Program:
NB. find the nearest prime or prime power for a number
NB. odd means remainder is 1
o =: 2&|
NB. makeodd: - use tie + agenda (for implementing if condition!)
mo =: (>: ` ]) @. o
NB. whole: compare with Floor of number
w =: ]=<.
NB. pl: list of primes less that given number
pl =: i. &. (p:^:_1) NB. use of dual operator &. (Henry Rich)
NB. however, I need primes <= number
ple=: pl@>: NB. add one more and get the list! (Roger Hui)
NB. check if the we have found a suitable base prime
ckl =. w @: (ple ^. ]) NB. ckl: Check the log wrt primes list
d =:  +/ @: ckl NB.  done: stopping condition
NB. repeat the discovery by increasing the value
fpp =: 3 : 0
k =. mo y
while. (0 = d k) do.
k =. 2&+k
end.
j =. I. ckl k
t =. p:j
y,k, j , t , t ^. k
)



On 9/21/06, Roger Hui <[EMAIL PROTECTED]> wrote:
>
>   ple=: i.&.(p:^:_1)@>:
>   ple 30
> 2 3 5 7 11 13 17 19 23 29
>   ple 31
> 2 3 5 7 11 13 17 19 23 29 31
>   ple 32
> 2 3 5 7 11 13 17 19 23 29 31
>
> Or, alternatively,
>
>   ple=: pl@>:
>
> where pl is what you have already defined.
>
>
>
> ----- Original Message -----
> From: Yuvaraj Athur Raghuvir <[EMAIL PROTECTED]>
> Date: Wednesday, September 20, 2006 8:30 pm
> Subject: Re: [Jprogramming] Explicit to Tacit - newbie question
>
> > Thanks!
> >
> > Interesting  use of the dual/under operator &. Although I had
> > studied the
> > form, this usage didnot occur to me!
> >
> > As an extension question:
> >
> > p1 =: i. &. (p:^:_1)     NB. primes strictly less than number
> >
> > so,
> > p1 37
> > 2 3 5 7 11 13 17 19 23 29 31
> >
> > In the generated list, I want the number included if it is prime.
> > What would
> > that extension be using &. ?
> > Or, does that need compelete verb definition?
>
>
> ----------------------------------------------------------------------
> 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

Reply via email to