Talk:Prime decomposition: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 23: Line 23:
in real code, though, as it's not the fastest. Pythonic, yes. Quick, no.
in real code, though, as it's not the fastest. Pythonic, yes. Quick, no.
--[[User:64.238.49.65|64.238.49.65]] 15:04, 17 August 2008 (UTC)
--[[User:64.238.49.65|64.238.49.65]] 15:04, 17 August 2008 (UTC)
: Oh yea. I missed that! (I didn't write the original, and should have looked closer). --[[User:Paddy3118|Paddy3118]] 17:32, 17 August 2008 (UTC)

Revision as of 17:32, 17 August 2008

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. --Mwn3d 09:17, 5 February 2008 (MST)

It prints out the factors seperated by * to stdout, In the context of unix, where everything is a text stream this counts as a collection. Why do you think it's unconventional, If you haven't used libgmp it may look strange.

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. --Mwn3d 11:08, 5 February 2008 (MST)


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? 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. --Mwn3d 11:44, 6 February 2008 (MST)

Big Numbers

The OCaml and Python versions are incorrect, wrt big numbers?

Python integers automagically extend. For example:
   >>> 2**1234
   295811224608098629060044695716103590786339687135372992239556207050657350796238924261053837248378050186443647759070955993120820899330381760937027212482840944941362110665443775183495726811929203861182015218323892077355983393191208928867652655993602487903113708549402668624521100611794270340232766099317098048887493809023127398253860618772619035009883272941129544640111837184L
   >>>
--Paddy3118 06:36, 14 August 2008 (UTC)

The Python code has comparisons with sys.maxint in one of the functions, but the comparisons are really not necessary. You'ld probably not want to use the algorithm in real code, though, as it's not the fastest. Pythonic, yes. Quick, no. --64.238.49.65 15:04, 17 August 2008 (UTC)

Oh yea. I missed that! (I didn't write the original, and should have looked closer). --Paddy3118 17:32, 17 August 2008 (UTC)