iKevinY/EulerPy

Line endings interfering with solution checking on Windows?

iKevinY opened this issue · 4 comments

From this thread over on Reddit, it seems as though there's an issue with solution checking on Windows. However, as I am running OS X (and don't have a Windows partition/VM set up at the moment), I can't verify anything about this issue.

From what I can gather, it seems as though the problem could be mitigated by changing line 129 in euler.py from is_correct = output == solution to is_correct = output.strip() == solution to strip the \r character printed by the output on Windows.

Could someone running Windows verify if this is indeed the case?

I found another solution that might help as well:
http://stackoverflow.com/a/2717154

I tried to test it, but someone added a new function that likes to eat up my output:

PS C:\Users\root\Downloads\EulerPy-master\EulerPy> .\euler.py -v 1
(time elapsed: 70 ms)nst solution: 233168

That's really odd, not sure how you're printing output, but I tried to "fix" that issue, itself, but I clearly don't know enough Python at this moment to really discern what is what, I just end up getting errors galore if I comment out anything. Gotta love Windows. :)

@Giancarlos I imagine what is happening is some strange interaction with a carriage return (the \r character) bringing the cursor back to the beginning of the line (even though it isn't supposed to), so instead of printing the time elapsed after the solution, it starts to overwrite the current line. I'm hoping to implement some changes discussed in issue #11 that will print the timing information on a new line instead, so this is yet another benefit of that potential change.

Hi, I can confirm the solution above (is_correct = output.strip() == solution) would indeed solve the problem on Windows. And Giancarlos is probably right that there's an '\r' somewhere, as Windows always puts an empty line ('\r\n') after each command output (and there's not much you can do about it: http://superuser.com/questions/97283/how-to-stop-the-windows-command-line-from-outputting-an-empty-line-after-each-co). Thanks for looking into this.

BTW, the solution proposed on Reddit (output = output[:-1].strip('\r') in the try-catch block just above) would also work (for the same reasons).

@mhkuu Great, thanks for confirming this. I'll do the former fix since it seems appropriate to strip() the output given the fact that the return value of get_solution() is strip()'d as well.