File tree 1 file changed +6
-5
lines changed
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
+
1
4
"""
2
5
Source: https://www.instagram.com/p/CG7kv65A6s1/?utm_source=ig_web_copy_link
3
-
4
6
The following function accepts 2 positive integers
5
7
and makes the first number as large as possible
6
8
by swapping out its digits for digits in second number
7
-
8
9
>>> maximum_combination(9132,5564)
9
10
9655
10
11
>>> maximum_combination(523,76)
@@ -26,17 +27,17 @@ def maximum_combination(first_num, second_num):
26
27
second_num = [int (x ) for x in str (second_num )]
27
28
first_num = [int (x ) for x in str (first_num )]
28
29
second_num .sort (reverse = True )
29
- for index , val in enumerate (first_num ):
30
+ for ( index , val ) in enumerate (first_num ):
30
31
if len (second_num ) > 0 :
31
32
if second_num [0 ] > val :
32
33
first_num [index ] = second_num [0 ]
33
34
second_num .pop (0 )
34
35
else :
35
36
break
36
- return int ("" .join (map (str , first_num )))
37
+ return int ('' .join (map (str , first_num )))
37
38
38
39
39
- if __name__ == " __main__" :
40
+ if __name__ == ' __main__' :
40
41
from doctest import testmod
41
42
42
43
testmod ()
You can’t perform that action at this time.
0 commit comments