Talk:Prime decomposition: Difference between revisions

(→‎Notes: new section)
 
(12 intermediate revisions by 8 users not shown)
Line 1:
==C==
Could someone explain the C example a bit more (either in text around it or in comments)? It's using some things I think may be a bit unconventional. Also, does it actually return some sort of collection which contains the factors? The task says it should. --[[User:Mwn3d|Mwn3d]] 09:17, 5 February 2008 (MST)
 
Line 4 ⟶ 5:
Why do you think it's unconventional, If you haven't used libgmp it may look strange.
 
==C==
This method seems to be incorrect. E.g. it does not find the decomposition for 2^41 - 1 == 13367 * 164511353. Can someone confirm this?
--[[User:Renfield|Renfield]] ([[User talk:Renfield|talk]]) 12:18, 18 June 2019 (UTC)
 
==Java==
Also the java example doesn't work for all integers > 1, maybe it could be fixed using the java bignum lib.
:I added a BigDecimal example, though I don't think anyone will ever need to go beyond Double.MAX_VALUE. If they want to, they shouldn't be using Java. Also, sign your talk page posts please. See [[Help:Formatting]] for tips. --[[User:Mwn3d|Mwn3d]] 11:08, 5 February 2008 (MST)
 
==J==
 
I note the J example simply calls a built-in - is that allowed? The task is kinda vague: "write a function that..." which could well include access to some language builtin. Or is the intent to show how one would solve the actual problem in that language? [[User:Sgeier|Sgeier]] 11:32, 6 February 2008 (MST)
:The vagueness is fine. Do it as simply as you see fit. If your language has prime decomposition built-in then that just makes it easier. --[[User:Mwn3d|Mwn3d]] 11:44, 6 February 2008 (MST)
Line 38 ⟶ 44:
 
To me, both requirements should be dropped (bignums and the use of "growing arrays" should be other tasks) --[[User:ShinTakezou|ShinTakezou]] 14:09, 7 April 2009 (UTC)
 
I also think that bignum/growing array requirements should be dropped. At the very least, the title of the page should indicate that big numbers are part of the challenge. --[[User:Showell|Showell]] 07:33, 5 January 2012 (UTC)
:Agreed. The task is asking far too much. Integer factorization is one of those basic programs one learns early, in any language. But if bignums are required, it's entirely another matter: first one needs a library (relatively hard), then one needs a good factorization algorithm (very hard). [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 23:28, 17 December 2017 (UTC)
 
== NZMATH ==
 
here's a Python 3 example using NZMATH modules--[[User:Billymac00|Billymac00]] 03:11, 3 January 2011 (UTC)
<lang python>
# snippet.py Python 3 to demo NZMATH ops ref: http://tnt.math.se.tmu.ac.jp/nzmath/
import sys
sys.path.append(r'C:\Python31\Lib')
sys.path.append(r'C:\Python31\Lib\site-packages')
 
from nzmath import prime
from nzmath import arith1
 
print("factors of 64 2 ways: ")
print(prime._factor(64)) # returns [ (2 , 6) ]
print("")
print(prime.properDivisors(64)) # returns [2, 4, 8, 16, 32]
</lang>
 
: You'd need to convert their format for the task, though: 64 needs to return <code>[2, 2, 2, 2, 2, 2]</code>.
: I did the same thing in [[Prime decomposition#PARI/GP|my PARI/GP solution]].
: [[User:CRGreathouse|CRGreathouse]] 19:57, 14 June 2011 (UTC)
 
== Propose to remove C GMP code ==
 
The GMP version of the C code is ''bad''. It can't realistically handle any number with a prime factor that's larger than 64 bit (so it's pretty pointless to use GMP to begin with), is written in a convoluted way, and leaks memory. Keeping it here only serves as a bad influence. If there are no objections soon, I'll delete it. --[[User:Ledrug|Ledrug]] 03:39, 4 August 2011 (UTC)
 
== C edits: can't be more than 8 ==
 
I'm reverting the last change of array size from 8 to 30, since it's mathematically impossible to have more (or fewer than) 8 numbers after each run. If you disagree because some diagnostic software says other wise, show me where it will fail. --[[User:Ledrug|Ledrug]] 20:59, 7 September 2011 (UTC)
 
: The program fails because it crashes and dumps core! However, I fixed it wrong and made the size too large: it only needs to be 9, not 30.
 
: <lang c> for (i = 1, q = p; i <= 30; i++, q += p) {
if (!(b[n] = bit_pos[q % 30])) continue;
b[n] = ~b[n];
shift[n++] = q / 30;
}</lang>
 
: I missed that bit_pos[] has only 8 nonzero elements. After this loop fills b[0] to b[7], it continues to assign b[8] = 0, because the assignment is before the <code>continue</code> statement. Therefore, program must declare array b[9] to hold elements b[0] to b[8]. --[[User:Kernigh|Kernigh]] 22:29, 7 September 2011 (UTC)
:: Ok. Don't edit it yet though, I'll modify that part of the logic soon. --[[User:Ledrug|Ledrug]] 22:32, 7 September 2011 (UTC)
 
== Factor missing from 15 November 2001 to 23 March 2012 ==
 
An anonymous user [http://rosettacode.org/mw/index.php?title=Prime_decomposition&diff=next&oldid=125923 accidentally deleted the Factor example] at '''15 November 2001'''. Rosetta Code never caught this mistake and never restored the deleted code. Nickolas [http://rosettacode.org/mw/index.php?title=Prime_decomposition&diff=134165&oldid=132999 contributed a new Factor example] at '''23 March 2012'''. --[[User:Kernigh|Kernigh]] 15:03, 23 March 2012 (UTC)
 
: '''2001'''? &nbsp; I thought ''Rosetta Code'' was inaugurated in '''2007'''. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 13:37, 16 October 2013 (UTC)
 
== Javascript ==
 
Javascript implementation without libraries fails with 100 as an argument. It decomposes to 2,2,25
Anonymous user