Reputation: 37
So I'm working through a CodeEval problem right now, and, for some reason, I can't get past a 98/100 score.
Here's a link to the challenge on CodeEval:
https://www.codeeval.com/open_challenges/167/
Here's my code:
# -*- coding: utf-8 -*-
import sys
zeefile = open(sys.argv[1])
for line in zeefile:
if len(line) <= 55:
sys.stdout.write(line)
elif len(line) > 55:
line = line[:40].rsplit(" ", 1)[0]
sys.stdout.write(line)
sys.stdout.write('... <Read More> \n')
I've beaten my head against this wall for a several hours, even with a few devs far more talented than I'll ever be.
We're perplexed, to say the least. Ultimately, it's not a big deal, but I'd like to know if there's something being missed here so I can learn from it.
I've checked the code over and over, I've checked the input, I've checked the output...I can't find any inconsistency, or anything that suggests I'm missing that last 2% of a successful solution.
Any idea what we're missing as to why this isn't coming back as a 100% legit solution to the problem? I'm hoping some fresh eyes and sharp minds can help me out on this one! Thank you very much!
Upvotes: 1
Views: 51
Reputation: 1991
Try the following code (100% on Code Eval):
import sys
with open(sys.argv[1], 'r') as in_f:
for line in in_f:
line = line.strip()
if len(line) > 55:
line = "{0}... <Read More>".format(line[:40].rsplit(" ", 1)[0].rstrip())
sys.stdout.write("{0}\n".format(line))
I used this file:
Tom exhibited.
Amy Lawrence was proud and glad, and she tried to make Tom see it in her face - but he wouldn't look.
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many - very, very great many.
Tom's mouth watered for the apple, but he stuck to his work.
and got the following output:
Tom exhibited.
Amy Lawrence was proud and glad, and... <Read More>
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many -... <Read More>
Tom's mouth watered for the apple, but... <Read More>
Upvotes: 3