Line Drawing Algorithm

Back to General discussions forum

simonhugo     2023-03-02 18:48:24
User avatar

I always get the answer: Your answer contains spaces. Perhaps some garbage in the output!

I have tried multiple input combinations in the ranges x1,x2: 0-255 and y1,y2 : 0-191 (horizontal, vertical, inclined in both directions with different angles), and I always get an answer without spaces and with a correct graphical representation.

zelevin     2023-03-02 21:48:55

What happens if you put a semicolon ; at the end of your print statement to tell the interpreter not to insert a newline?

simonhugo     2023-03-02 23:16:39
User avatar

With a semicolon at the end of the print command, what I get is a single line without blank spaces, and a correct graphical representation of the coordinates that I enter.

But the answer is always: "Your answer contains spaces. Perhaps some garbage in the output!"

zelevin     2023-03-02 23:27:58

With the semicolon, your output (and the code) looks correct to me. Not sure I can suggest anything else at the moment.

simonhugo     2023-03-03 13:29:00
User avatar

I already found the error. It has nothing to do with the displayed message. I realized when solving the "Circle Drawing Algorithm", that it indicated to me, here yes correctly, that the INT function is not allowed.

By removing the INT function from "coc=int(dec/16)", the program gives OK

Thank you, zelevin

simonhugo     2023-03-03 14:53:11
User avatar

But someone has had to touch something in the emulator.

Both programs (Line and Circle) have given ok when eliminating the cast to INT, and they gave an error with it.

However, I have now returned them to the emulator and without the cast to INT neither of them work. It's as if before the emulator was in integer arithmetic mode and someone has now changed the mode.

aszaloki     2024-06-04 13:26:26

Hi all,

may I have ask someone to check my solution? I have implemented Bresenham's algorithm (the complete solution which is extended to cover slopes between 0 and -1 as well) but the checker always says the my output contains space. I'm confused a little bit. Of course I do not want you to tell me the solution but I would appreciate if I get a (x0, y0, x1, y1) list which my code fails on. Thank you in advance!

zelevin     2024-06-04 19:15:38

Try terminating your print statement with a semicolon to prevent it from appending a newline.

aszaloki     2024-06-05 09:09:50

Thank you zelevin, but it does not help. I have already read the posts in this thread. Even I have eliminated the INT casting and substituted with my own. My output seems ok in every octants, the output string does not contain anything except the concatenated 16-based coordinates as the problem statement describes.

gardengnome     2024-06-05 09:58:08
User avatar

Do you actually read the input data from the test case in? It seems to be hardcoded in your code.

aszaloki     2024-06-05 13:13:35

Your answer is Wrong Expected answer was: Your answer contains spaces. Perhaps some garbage in the output!

Your answer was:

Your input data: ...please copy from example or construct manually...

I get this if read the input. In case of this problem the real input data is missing, instead there is a text... I do not understand why it is so. I tried different x0,y0,x1,y1 hardcoded, each of them passed.

gardengnome     2024-06-05 14:20:21
User avatar

On the problem page in the test data section, replace the '...please copy from example or construct manually...' with the test data '60 40 220 150'. Does you program a) read this data correctly, b) draw the corresponding line in the visualisation, and c) produce a hex output in the your answer section?

gardengnome     2024-06-05 15:41:00
User avatar

For the test case, your and my solution seem to produce the same answer. My text editor says the output strings are identical. However yours fails and mine passes when submitting. Not sure why.

aszaloki     2024-06-05 18:24:13

a) yes b) yes c) yes

:) beside my frustration about this my curiosity is increasing what there could be behind of this malfunction of my code (or of the checker)

Anyway, gardengnome thank you for the debugging. Feel free to investigate it further if you are interested in, I try to achieve my next rank by solving another problem :) (currently I am on 204 solved problem, need one more to get "Cardinal").

aszaloki     2024-06-05 19:13:28

May I have the input data which the checker script runs? I know it is not a "nice" request, but it may help to find the problem on my side if any. (technically CodeAbbey would just provide me input data and after test my code with them I would send my outputs to you or the responsible person.

Please login and solve 5 problems to be able to post at forum