开发者

Haskell in SPOJ: "Wrong answer" in problem, but correct in my computer

开发者 https://www.devze.com 2023-01-10 01:22 出处:网络
Today, I submitted solutions on SPOJ to the COINS problem. I got the Fortran and the Perl solutions accepted, but I got \"Wrong answer\" in the Haskell solution. I thought that perhaps my code was fau

Today, I submitted solutions on SPOJ to the COINS problem. I got the Fortran and the Perl solutions accepted, but I got "Wrong answer" in the Haskell solution. I thought that perhaps my code was faulty at some point, but the results for 200K numbers (100K in the upper limit and 100K in the lower one) are exactly as per the Perl solution as can be seen below:

angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ seq 1000000000 -1 999900001 > p346.in
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ seq 0 100000 >> p346.in
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ ./p346.pl < p346.in > p346.po
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ ghc --make -o p346.exe p346.hs
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ ./p346.exe < p346.in > p346.ho
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$ diff p346.ho p346.po
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$
angelv@vaso:~/Dropbox/开发者_C百科ProgrammingGym/SPOJ$ head -n 5 p346.ho
4243218150
4243218150
4243218150
4243218150
4243218150
angelv@vaso:~/Dropbox/ProgrammingGym/SPOJ$

Is there any way to find what could be going on (perhaps the last few lines of the generated output?).


As I know, there isn't any way to look for the output in SPOJ. But I think that you can generate errors so the SPOJ compiler says "Hey, you have this runtime error!", but it would be induced by you, so, you can see where is it failing. (I haven't tested it, but.. if you return a non-zero value (if it is possible in Haskell) won't SPOJ tell you that ending number?)

I can't see your Haskell code, and I assume you have done other problems in Haskell already, so, you have take care of those little errors like "leaving a blank linke at the end" or re-reading the last line of input.

Sorry for my bad English, and sorry if my answer isn't what you've expected (The quest. I don't use SPOJ frecuently, and maybe there is another way, but the only one that comes to my mind is "If you want to debug it, throw errors and differentiate them".)

I don't know if this should be an answer or should be commented on the first post, but I can't add a comment there, I think it's because I'm new here.

Edit: I've asked in Haskell IRC channel, and a very gentle user told me about "System.Exit". Take a look, I hope it helps you: http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/System-Exit.html

Maybe there's another way to "debug" your program from SPOJ, but I don't know how. Have you tried commenting on the problem, or asking in the forum? You can also post your Haskell code in Haskell's IRC and ask if someone can take a look at it.

0

精彩评论

暂无评论...
验证码 换一张
取 消