Hello,

Some wonderful ways of solving the problem....

Since many are not able to understand what fpp define is about, I shall
explain it with some data.

1) Given : Number n
2) Consider only ODD numbers greater than n - say OddsGreaterThanOrEqual(n)
3) In this set, find the smallest number m such that:
3.1) either m is a prime number
3.2) or, m is a power of a prime number.
(Full program attached after signature).


Now, to get a feel of what fpp can do, look at the following:

;/ fpp"0 i.10 10
_______________________________
│3│11│23│31│41│53│61│71│ 3│ 97│
│3│11│23│31│41│53│61│71│ 3│ 97│
│3│13│23│37│43│53│67│73│83│ 97│
│3│13│23│37│43│53│67│73│83│ 97│
│5│17│ 5│37│47│59│67│79│89│ 97│
│5│17│ 5│37│47│59│67│79│89│ 97│
│7│17│ 3│37│47│59│67│79│89│ 97│
│7│17│ 3│37│47│59│67│79│89│ 97│
│3│19│29│41│ 7│59│71│79│89│101│
│3│19│29│41│ 7│59│71│79│89│101│
________________________________

Remarks on the solution matrix:
a) All the number are primes
b) Note that there are small primes in the vicinity of powers of primes. So,
you see 5 where 24 & 25 are evaluated and 3 where 26& 27 are evaluated. This
is correct since the small primes 5 & 3 have their powers here (5^2 = 25)
and (3^3 = 27)
c) However, we donot see 2 in the vicinity of 64. That is because 2 is
explicitly excluded.

I have received some amazing solution suggestions. So, currently, I am
trying to understand them. Long way to go since I am trying to learn J via
this exercise. In case you have a solution in mind, do apply it on the
matrix like above to verify if thats what your solution does.

Thanks and Regards,
Yuva


*Full program:*
o =: 2&|
mo =: >: ` ] @. o
w =: ]=<.
NB. pl: list of primes less that given number
pl =: i. &. (p:^:_1)
ple=: pl@>:
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
t   NB. The solution
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to