Talk:Largest int from concatenated ints: Difference between revisions

Line 10:
:Hi Nigel. Duplicates are not excluded. P.S. I assumed that the edit buttons were a (short term) casualty of the MW upgrade. [[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 16:09, 4 April 2013 (UTC)
::The Haskell entry that uses cycle goes in infinite loop if you feed it with numbers like 10 and 1010.-[[User:Bearophile|bearophile]] ([[User talk:Bearophile|talk]])
 
==On "Python: Compare repeated string method" Second entry for Python 2.6==
Hi Spoon, Is it the case that the first entry does not work on Python 2.6:
 
:<lang python>def maxnum(x):
maxlen = len(str(max(x)))
return ''.join(sorted((str(n) for n in x), reverse=True,
key=lambda i: i*(maxlen // len(i) + 1)))</lang>
 
The second version seems to be quite complex - using Fractions and logs, and although I do not have a version of Python 2.6 to hand, I cannot think of what of the above would break 2.6?
 
Here's your second version:
:<lang python>from fractions import Fraction
from math import log10
 
def maxnum(x):
return ''.join(str(n) for n in sorted(x, reverse=True,
key=lambda i: Fraction(i, 10**(int(log10(i))+1)-1)))</lang>
 
(P.S. thanks for catching my <code>maxnum'''x'''</code> errors)! --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 06:19, 6 April 2013 (UTC)
Anonymous user