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
