Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
try:
|
||||
cmp # Python 2 OK or NameError in Python 3
|
||||
def maxnum(x):
|
||||
return ''.join(sorted((str(n) for n in x),
|
||||
cmp=lambda x,y:cmp(y+x, x+y)))
|
||||
except NameError:
|
||||
# Python 3
|
||||
from functools import cmp_to_key
|
||||
def cmp(x, y):
|
||||
return -1 if x<y else ( 0 if x==y else 1)
|
||||
def maxnum(x):
|
||||
return ''.join(sorted((str(n) for n in x),
|
||||
key=cmp_to_key(lambda x,y:cmp(y+x, x+y))))
|
||||
|
||||
for numbers in [(1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
|
||||
print('Numbers: %r\n Largest integer: %15s' % (numbers, maxnum(numbers)))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def maxnum(x):
|
||||
maxlen = len(str(max(x)))
|
||||
return ''.join(sorted((str(v) for v in x), reverse=True,
|
||||
key=lambda i: i*(maxlen * 2 // len(i))))
|
||||
|
||||
for numbers in [(212, 21221), (1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
|
||||
print('Numbers: %r\n Largest integer: %15s' % (numbers, maxnum(numbers)))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
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)))
|
||||
|
||||
for numbers in [(1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
|
||||
print('Numbers: %r\n Largest integer: %15s' % (numbers, maxnum(numbers)))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
from itertools import permutations
|
||||
def maxnum(x):
|
||||
return max(int(''.join(n) for n in permutations(str(i) for i in x)))
|
||||
|
||||
for numbers in [(1, 34, 3, 98, 9, 76, 45, 4), (54, 546, 548, 60)]:
|
||||
print('Numbers: %r\n Largest integer: %15s' % (numbers, maxnum(numbers)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue