[Community Puzzle] Asteroids

This was really useful for me.
I was using int and it failed Validator 10 because of this.
I then replaced ‘int’ for ‘math.floor’ and it worked.

2 Likes

What does “only the closest one” mean in the context of the assignment?

The letter assigned to each asteroid represents its distance from your observation point.
Therefore you should only output the asteroid that is closest to you in case multiple asteroids have the same coordinates.

1 Like

Any tips for validator 7 ? I caaan’t get over that one …

1 Like

You may have incorrect rounding for values < 0. Check out the older comments about truncate() vs floor().

1 Like

Looking at this I have done something very different. I’m using c++.

I put the data into a 2D arrays.

measured the differences then made a 3rd 2D array.

I can do 7/10 cases so far but cant get passed 5, 9, 10.

can someone point me as to where I’m going wrong?

Hmm yea, I am using math.floor python 3, all tests and the following validators fine, except that 7th one. Is optimization considered ? maybe my code takes too long …

Validator 7 is exactly like the testcase ‘depth’ but with different letters.
So check that in case of several letters to be displayed at the same spot, you output the lowest one.
For example try to swap E and G in testcase ‘depth’ and see if it still outputs E.

2 Likes

Complete this puzzle with a quite simple method.

  1. Create a new copy of image filled with ‘.’ as result image.
  2. Read in the first and second image, keep all asteroid and 2 of its coordinates (from T1 and T2 time) in a dictionary.
  3. Then, simply calculate asteroid’s speed, and then the new coordinate for T3 (remember take floor value).
  4. Change result image, accordingly, if corresponding position already occupied by some other asteroid, means both have same destination. Take minimum of those 2. Also remember to perform bounds check incase asteroid move out of the picture.
  5. Output the result.
3 Likes

its Amazing

I seem to be having an issue with validator 10, I can pass the regular test 10.

I am by no means a great, or experienced programmer, I just like doing these challenges, as they are a lot of fun. I have ready through these replies, and I don’t think I’ve fallen for any traps:

  • I have computed simple distance, using only the change in X values for the new X, then the change in Y values for the new Y
  • I have used math.floor, not int
  • I make sure that the letters are displayed with priority on A, then B, and so on.

Any other hints?

Thank you for playing my puzzle.
Could be anything, really.
I’m taking shots in the dark here but I know some people have struggled with validator 10 because they were not iterating trough all the letters of the alphabet (stopping at index 24 for instance) and thus were failing to pass validator 10 since it has “Z” in its output.
If that is not the problem feel free to DM your solution so I can point you in the right direction.

2 Likes

It is hard to debug code without seeing it, I agree.

I don’t think it was “Z”, because there was a Z in the other one, and I was able to pass it.

I have taken advantage of your super kind gesture to have me send my very ugly code to you.

Thank you so much.

Thank you so much for the email!

Yes, it was Z. My issue was hidden from me because while test 10 does include Z, Z flies off the map, so isn’t printed, which was good for my code, because it didn’t know how to print Z.

I really appreciate you taking the time to help me out.

2 Likes

For anyone interested it turns out the problem was indeed the “Z” in the output.
Since it appears to be a (somewhat) common mistake amongst players I have once again edited the contribution so that the corresponding test case will also feature a “Z” in its output, which will hopefully make the problem easier to debug.

4 Likes

Nice puzzle :slight_smile:
I actually made the mistake of ignoring the T1, T2, T3 numbers in the input, so like many others “Greater Delta” was a wall :stuck_out_tongue:

I thought that the asteroids were supposed to stay within the grid even if they were flying off the grid, which means I had used min/max for this until I realized that the reason of the odd differences were because of the speed/time difference :sweat_smile:

2 Likes

Im really confused on how im supposed to get the coordinates of the asteroids. I can’t even begin to solve the problem without them

Read the lines one by one, keeping their rank in a variable, for example i.
Then read each character in the ith line and get the rank of each character that in a letter.
For example if the fourth line (rank i=3) is ---A---E--, then A’s coordinates are (3,3) and E’s coordinates are (3,7).

1 Like

You may use whatever coordinate system you want but I think the most common is to decide that the top left corner is (0,0) and the bottom right is (W-1,H-1). You can therefore get coordinates very easily by counting the numbers of rows to get the Y coordinate and the number of columns to get the X coordinate.

1 Like

Hi I am having struggle understanding something.
In case ‘Greater delta’, A is going 0 to 4, so in the third picture A should be out of bounds?
I don’t understand how it can appear in 5. If I bound its Y to 5 if it’s over 5 then it works, but then the case ‘Out of bounds’ doesn’t work anymore as it expects E and J to disappear.

2 Likes