[Community Puzzle] Asteroids

https://www.codingame.com/training/easy/asteroids

Send your feedback or ask for help here!

Created by @XorZy,validated by @codybumba,@AgathokakologicalBit and @tuna_in_cream.
If you have any issues, feel free to ping them.

1 Like

Nice little puzzle.
I lazily casted int instead of actually using the floor function to round down and it didn’t work at first cause it would round -0.5 to 0 instead of -1.
So don’t be lazy and use the proper floor function :slight_smile:

9 Likes

Lots of fun!

3 Likes

The puzzle implicitly assumes that the visible path of an asteroid is a straight line, which holds only if t1, t2, t3 are close. Of course, fair enough for an easy puzzle.

It would be a very tough math/physics (not coding) problem if we would need to take into account gravity, Sun, Earth rotation, pictures taken on different days, etc.

1 Like

If you go that route, you’d need to know general relativity for space time curvature :sweat_smile:

3 Likes

I used int with Python and it worked.

2 Likes

Interesting. int(-0.5) should definitely return 0 instead of -1, thus causing the asteroid “V” to appear in the final picture when it should be out of screen.
Perhaps the reason it worked is because you are filtering out negative coordinates before the conversion?

2 Likes

Keep it in mind for Asteroids Ep. 2 :wink:

1 Like

For JVM users, there is a not widely known method, Math.floorDiv(), fits well for this purpose.

2 Likes

Yes I am and it wasn’t on purpose. :grin:

I don’t understand that part of statement:
If two or more asteroids have the same final coordinates, output only the closest one .

The closest one is determined how if the coordinates are the same? If I have A(0,1) B(0,1) C(0,1) which one is the closest one and why? :confused:

1 Like

A is closer than B, that is closer than C, and so on.
It’s in the statement. :wink:

True, I don’t know why but I couldn’t see it.
Thank you

1 Like

OK what is happening with “Greater delta”??? The A clearly moves 4 spots, then it suddenly moves 1 spot? This is extremely confusing.
OH time is a part of it. ok
So after 5 mins including time differences, I figured it out.

7 Likes

Yeah it wouldn’t make sense to provide three different times as input if you’re not supposed to use them :wink:

1 Like

I wouldn’t disagree, and to be honest I rushed this one due to it being late. But that being said, many many puzzles have unused information. Or at least information gathered from other means work. But you’re not wrong.

1 Like

Hi, I passed all the test and all validators except the last “Validator 10”… I didnt hard code any thing to pass the last test case, Not able to debug too … can anyone help me? Coding language: Python

If you round down with int, try with math.floor instead.

1 Like

It’s hard to tell what you did wrong without seeing your code but here are a few things to consider :

  • Use floats and not integers to compute the coordinates

  • Use floor on the final result, not int() as it will cause rounding issues

  • Make sure you discard asteroids that are outside the picture (x<0,y<0,x>=W,y>=H)

  • Make sure you only output the closest asteroid in case more than one have the same coordinates (A being the closest)

1 Like

I used int and my solution passed all the validators.