Created
October 8, 2014 21:03
-
-
Save elais/4e3be7725f71ca67dbfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxNum(M, k): | |
x = [int(x) for x in str(M)] | |
y = k | |
z = sorted(x, reverse = True) # nondeterminism | |
def swap(i, j, l): | |
tmp = l[i] | |
l[i] = l[j] | |
l[j] = tmp | |
return l | |
def find_index(number, i, l): | |
num = number | |
for x in range(i, len(l)): | |
if l[x] == num: | |
return x | |
for i in xrange(y): | |
if x[i] < z[i]: | |
index = find_index(z[i], i, x) | |
x = swap(i, index, x) | |
X = int(''.join([str(i) for i in x])) | |
print X |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment