Last active
August 29, 2015 14:05
-
-
Save yuheiomori/cf7d12d500e836b339a2 to your computer and use it in GitHub Desktop.
Data Recovery (CodeEval) in Python 3.x
This file contains hidden or 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
# 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