forked from dlefcoe/daily-questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
largestPossible.py
59 lines (29 loc) · 808 Bytes
/
largestPossible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''
This problem was asked by Twitter.
Given a list of numbers, create an algorithm that arranges them in order to form the largest possible integer.
For example, given [10, 7, 76, 415], you should return 77641510.
'''
# import random as r
import itertools as itt
mylist = [1, 345, 72, 180]
def maxNumberFromList(aList):
nList = itt.permutations(aList)
gList = []
for e in nList:
g = ""
for f in e:
g = g + str(f)
gList.append(int(g))
print('the g list')
print(gList)
mNum = max(gList)
return mNum
result = maxNumberFromList(mylist)
print(result)
# ross method...
from itertools import permutations as perms
mylist = [1, 345, 72, 180]
def bigchief(alist):
l = map(str, alist)
return max("".join(x) for x in perms(l))
print(bigchief(mylist))