Frodo and Black Riders

Back to General discussions forum

mooninvader     2020-07-01 23:00:15

could you tell me please how angle between the direction to the given hobbit and the direction in which the Rider looks is calculated please

Alexandr Milovantsev     2020-07-02 09:34:13

At first you have to calculate a vector from Rider to hobbit. Then convert this vector from rectangular coordinates to polar coordinates. Use atan2 library function for convenience. Then subtract angle of vector from angle of rider - it gives what you ask for.

mooninvader     2020-07-02 16:42:34

thanks, for your help

mooninvader     2020-07-03 15:29:01

for the data : 5 15 73 1.9 43 29 1.2 18 79 -0.2 89 28 0.5 80 54 -2.4

i got : 48 34 18 0 0 0

the expected answer is 50 34 17 0 0 0 104 > 100

so i think my answer is better but considered as wrong

is the checker right??

Alexandr Milovantsev     2020-07-04 12:30:50

I run my solution on your data and set rounding to 0.1. It gives me 49.8 33.7 16.5 0.0 0.0 0.0 as result. So I think checker is ok.

mooninvader     2020-07-06 17:31:42

thanks, it worked now

mithrandir2112     2022-04-02 16:07:27
User avatar

I have to say that I could not figure out what was wrong with my solution. I assumed the 100 x 100 grid was X = -50 to 50 and y = -50 to 50. So much time wasted checking if the points were inside the vision shape or outside the shape etc. If only I had realized sooner that the grid numbers are all positive. X = 0 through 100 and y = 0 through 100.

Rodion (admin)     2022-04-03 05:53:00
User avatar

Mithrandir, Hi!

That's wonderful that problem about Frodo (probably the only we have on LotR theme) is solved by colleague with such a suitable name :)

Thanks a lot for your hint. I just vaguely remember the task, but judging from the code you are quite right - and so I added clarification on field corner's coordinates, to prevent confusing more people!

mithrandir2112     2022-04-04 20:49:38
User avatar

Hi Rodion, Thanks for adding the clarification to the problem statement. The good news is I was forced to go much deeper into the analysis of the problem because I could not figure out why I was not getting the right answer. I was outputting points to CSV and graphing in Excel and when that didn't work I was using the CSV data to draw rider vision shapes in CAD to analyze the area and the overlapping areas because I couuldn't find any more errors in my logic or my code. Then the idea about the grid definition hit me and I was able to solve but I think I learned a lot more by not getting to the solution right away.

Thanks also creating and running the website. I really like it.

-Mithrandir

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