Investigating how to factor quite large numbers in J, I've just bumped
into this curiosity, which
wrecked my loopy experiment at an early stage!...
4 p: 1
2
4 p: 1x NB. need to try extended in some cases...
3
!
Thanks for any advice,
Mike
On 25/04/2020 00:15, 'Mike Day' via Progra
Yes, that works as expected.
BUT consider:
__ q: 360 NB. generate a table of primes and powers:
2 3 5
3 2 1
((3+3*>:i._10),:~p:i.10) NB. set up a bigger table
2 3 5 7 11 13 17 19 23 29
33 30 27 24 21 18 15 12 9 6
NB. generate a number from it:
__ q: N NB. __ q: factors i
The bug seems to be confined to the argument 1x . 4 p: x searches x+2,
x+4, ... for primes. It starts at x+1 if x is even or is non-extended
1; but for extended 1 it starts at x+2.
Henry Rich
On 4/25/2020 4:48 AM, 'Michael Day' via Programming wrote:
Investigating how to factor quite large n
Am I using clear'' wrong?
I does not seem to work, but when I manually use (4!:55) and (4!:1) I get
the desired result. See my demonstration below.
$AA
77
clear''
$AA
77
clear
3 : '". ''do_'',('' ''-.~y),''_ (#~ -.@(4!:55)) (4!:1) 0 1 2 3'''
(4!:55) (4!:1) 0 1
1 1 1 1 1 1
The right argument to clear is the locale, default base.
It looks like you are in the z locale, so
clear'' NB. clear in base
(4!:55) (4!:1) 0 1NB. clear in z
On Sat, Apr 25, 2020 at 7:14 AM Brian Schott wrote:
>
> Am I using clear'' wrong?
> I does not seem to work, but when I manually
As it stands you haven't proved there is a problem.
Erasing a name erases one copy of the name. If AA__ and AA_z_ were both
defined, you would see what you saw.
Henry Rich
On 4/25/2020 10:14 AM, Brian Schott wrote:
Am I using clear'' wrong?
I does not seem to work, but when I manually use (
Chris,
Yes, I did not understand the right argument usage.
On Sat, Apr 25, 2020 at 10:35 AM chris burke wrote:
> The right argument to clear is the locale, default base.
>
> --
(B=)
--
For information about J forums see http://
Yes, I know... I should have offered 4 p: 1 2 3 4x or something similar.
Cheers,
Mike
Sent from my iPad
> On 25 Apr 2020, at 13:20, Henry Rich wrote:
>
> The bug seems to be confined to the argument 1x . 4 p: x searches x+2, x+4,
> ... for primes. It starts at x+1 if x is even or is non-ex
So far, Roger's solution for counting the divisors of any integer using __
q: seems the most efficient.
* div=:3 :'*/>:{:__ q:y'*
Test it:
* >div each 10 47 360 2357047123200*
*4 2 24 1620*
* ts '>div each 10 47 360 2357047123200' *
*2.89e_5 10944*
Finding and listing the actual divisors
factors=:,@>@(*/&.>/)@(<@(1,*/\)/.~)@q:
factors each 10 47 360 2357047123200
+++--+--
Don Guinn's factors verb, which I renamed "ldiv" for "list divisors" is
quite efficient (way more than my brute force approach):
* ldiv=:,@>@(*/&.>/)@(<@(1,*/\)/.~)@q:*
* ] ldiv each 10 47 360 2357047123200*
*│1 5 2 10│1 47│1 5 3 15 9 45 2 10 6 30 18 90 4 20 12 60 36 180 8 40 24 120
72 360│1 11
Also https://rosettacode.org/wiki/Factors_of_an_integer#J
Thanks,
--
Raul
On Fri, Apr 24, 2020 at 2:31 PM Roger Hui wrote:
>
> See https://code.jsoftware.com/wiki/Essays/Factorings
>
>
>
> On Fri, Apr 24, 2020 at 11:29 AM Skip Cave wrote:
>
> > I want to find all the integer factors of a posi
12 matches
Mail list logo