Skip to content

Commit 670b77e

Browse files
Update maximum_combination.py
1 parent 94182c7 commit 670b77e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

maths/maximum_combination.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
14
"""
25
Source: https://www.instagram.com/p/CG7kv65A6s1/?utm_source=ig_web_copy_link
3-
46
The following function accepts 2 positive integers
57
and makes the first number as large as possible
68
by swapping out its digits for digits in second number
7-
89
>>> maximum_combination(9132,5564)
910
9655
1011
>>> maximum_combination(523,76)
@@ -26,17 +27,17 @@ def maximum_combination(first_num, second_num):
2627
second_num = [int(x) for x in str(second_num)]
2728
first_num = [int(x) for x in str(first_num)]
2829
second_num.sort(reverse=True)
29-
for index, val in enumerate(first_num):
30+
for (index, val) in enumerate(first_num):
3031
if len(second_num) > 0:
3132
if second_num[0] > val:
3233
first_num[index] = second_num[0]
3334
second_num.pop(0)
3435
else:
3536
break
36-
return int("".join(map(str, first_num)))
37+
return int(''.join(map(str, first_num)))
3738

3839

39-
if __name__ == "__main__":
40+
if __name__ == '__main__':
4041
from doctest import testmod
4142

4243
testmod()

0 commit comments

Comments
 (0)