Somewhat more correct than my earlier offering, ppp:
rrr =: 3 : 0
n =. y
p =. 1, p: i. >: _1 p: -:n
l =. ''
while. #p =. }. p do.
l =. l, ({.*}.) p =. (([{.~ I.+e.~)n%{.) p
end.
/:~ l NB. sort list
)
sss =: 3 : 0 NB. Same idea as a non-tacit one-liner...
/:~;({.*}.)each }. (([{.~ I.+e.~)n%{.)@}.each^:a:<1 , p: i. >: _1 p: -:n =. y
)
_10{. "1 (ppp, rrr,: sss) 2025. NB. ppp missed a near prime year!
1981 1982 1983 1985 1991 1994 2005 2018 2019 0
1981 1982 1983 1985 1991 1994 2005 2018 2019 2021
1981 1982 1983 1985 1991 1994 2005 2018 2019 2021
Note that sss uses more time and space than ppp and rrr.
Cheers,
Mike
Sent from my iPad
> On 1 Jan 2019, at 10:35, Mike Day <[email protected]> wrote:
>
> After arguably too many New Year’s Eve drinks, and misreading the requirement
> as four prime divisors, my effort on the iPad led to iOS J701 crashing, and
> so to bed.
>
> It’s a lot easier if you only want two prime factors. Unlike Skip, I’ve
> assumed you only want squarefree factors, so here’s a function in the spirit
> of Raul’s comments:
>
> ppp =: 3 : 0
> n =. y
> p =. p: i. >: _1 p: -:n
> l =. ''
> while. #p do.
> NB. multiply first by rest, and remove too high elements
> l =. l, b =. n (>: # ]) ({. * }.) p
> NB. trim inputs to too high elements
> p =. }. p{.~ # b
> end.
> /:~ l NB. sorted list
> )
>
> ppp 30
> 6 10 14 15 21 22 26
>
> _5{. ppp 2030
> 1994 2005 2018 2019 2026 NB. Even evens allowed!
>
> Happy Nearly Prime 2019 Sent from my iPad Air running J701 under iOS 12.1.1,
> screen not too bad!
>
> Mike
>
>> On 1 Jan 2019, at 02:23, Bernie Eckhart <[email protected]> wrote:
>>
>> 1, 3, 673, 2019
>>
>> 4 factors is almost a prime.
>>
>> Let's denote only 4 factor numbers like 2019, i.e. every factor is a unique
>> integer that occurs only once, as "almost a prime" number.
>>
>> A problem is to compute efficiently all "almost a prime" numbers between 1
>> and any given prime number.
>>
>> Almost certainly a waste of time unless some pattern might be discovered
>> that allows one to predict and compute primes faster than other methods.
>>
>> I have no idea where to begin because I am not a mathematician and because
>> I am very new to J.
>>
>> HAPPY 2019!
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm