Back to Topic List
Hi Kevin,
I have an issue with this description. I cannot find information about the initial head direction. So I set it to the direction to East. In this case the detailed example works as follows with my program:
Turn │ Pattern Seen │ Direction Chosen
──────│──────────────│──────────────────
0 │ 01245 │ 2
1 │ 01245 │ 2
2 │ 0145 │ 0
3 │ 01245 │ 2
4 │ 045 │ 0
5 │ 0145 │ 0
6 │ 01245 │ 2
7 │ 045 │ 0
8 │ 045 │ 0
Distance is 1.2393...
But if I set the initial direction to NorthWest, the table above is the same, but the Distance is 1.9318...
Anyway, it is not 0 as it is in the example in the description.
If we have different distances at the end of the simulation with different initial head directions, than the initial head direction should be given for each test case.
The more probable asnwer is that I misunderstood something. Do you have any idea what I have assumed/done wrong?
I commented my code how I tried to solve this problem.
Hi Adam!
Ideally whatever you choose ought to produce a similar outcome, since the worm only sees it's world from it's own perspective.
I looked through your code - thanks for the comments! I might have found some trouble points in the code.
1) GetEuclideanDistanceFromOrigo() doesn't look right.
It looks like Position.X and Position.Y refer to the system you describe at the beginning of Run(),
rather than the cartesian (x, y), which is fine.
But consider the point at Position.X = 1 and Position.Y = -1.
I think the distance to the origin would be 1, but GetEuclideanDistanceFromOrigo() would return 0.518...?
The math there looks almost correct, but not quite.
2) Food exists on the edges between nodes, not on nodes themselves.
For example given 4 nodes A, B, C, D, the worm would be able to travel A -> B, B -> C, C -> D, and then D -> B.
The fact that the worm has already visited B does not invalidate the move D -> B,
because the worm hadn't yet traveled the B <-> D path specifically.
Is your code checking for that behavior?
My unfamiliarity with C# makes it difficult for me to tell exactly, but this might be the issue why the worm can't return to the origin.
3) It looks like I made an error in the prompt, where I listed the directions relative to the worm's head as:
But the intended orientation coding has 4 and 5 flipped, so corrected it's:
Drawn out, this places 3 next to 4, and 5 next to 0.

In your comment block under Run() it looks like you may have understood the intuitive intended orientation system,
but at public static int[] ruleSetIndexMapping = new int[6] { 0, 1, 2, 3, -1, -2 }; it looks like you did correctly implement what was written in the prompt.
Sorry about that!
Although, I'm still not certain that any of those bugs necessarily cause the worm to behave differently based on its initial orientation... but maybe this helps troubleshoot - I'm interested to hear how it turns out!
Hi Kevin,
thank you very much!
1) You are absolutely right, basic math what I did wrong...shame on me. 2) Foods are on edges....I was careless, it is stated in the description. Second mistake from me :) 3) Thank you, yes it was a little bit strange :)
Now my code generates the same result for the examples.
But I have still differences with the real test. Some of my results are correct, some of them are wrong. I keep on observing my code. There must be something I do wrong still. I will let you know if I find it :)
Thanks again the deep troubleshooting!