Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Last active August 29, 2015 14:05
Show Gist options
  • Save yuheiomori/cf7d12d500e836b339a2 to your computer and use it in GitHub Desktop.
Save yuheiomori/cf7d12d500e836b339a2 to your computer and use it in GitHub Desktop.
Data Recovery (CodeEval) in Python 3.x
# coding=utf-8
import sys
def find_lost(l):
l = sorted(l, key=lambda x: int(x))
for i, hint in enumerate(l):
if hint != str(i + 1):
return str(i + 1)
return str(len(l) + 1)
def main():
with open(sys.argv[1], "r") as f:
for line in f:
words, hints = [e.split(' ') for e in line.rstrip().split(';')]
hints.append(find_lost(hints))
zipped = list(zip(words, hints))
zipped = sorted(zipped, key=lambda x: int(x[1]))
print(' '.join([z[0] for z in zipped]))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment