Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Last active December 11, 2015 06:49
Show Gist options
  • Save lambda-fairy/4562331 to your computer and use it in GitHub Desktop.
Save lambda-fairy/4562331 to your computer and use it in GitHub Desktop.
Keks solution
def max_index(items, start, end):
best_item = None
best_index = None
for index, item in zip(range(start, end), items[start:end]):
if best_item is None or item > best_item:
best_item = item
best_index = index
if best_index is None:
raise ValueError('maximum of empty sequence')
else:
return best_index
def keks(num, n_skip):
digits = list(num)
start = 0
for end in range(n_skip+1, len(digits)+1):
start = max_index(digits, start, end)
yield digits[start]
start += 1
def main():
with open('keks.in', 'r') as in_f:
with open('keks.out', 'w') as out_f:
n_digits, n_skip = map(int, in_f.readline().strip().split())
num = in_f.readline().strip()
print >>out_f, ''.join(keks(num, n_skip))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment