Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Razovsky,validated by @Remi,@Diabetos and @Mackhdo.

If you have any issues, feel free to ping them.

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Razovsky,validated by @Remi,@Diabetos and @Mackhdo.

If you have any issues, feel free to ping them.

1 Like

Hi everyone,

For the fast guys who already finished it, there was a problem of degree/radian conversion (on longitude calculationâ€¦) that led to mistakes in the testcases/validators. Shame on me.

This is now fixed, so donâ€™t hesitate to correct your solutions

1 Like

Are you sure this statement is correct?

`One degree in longitude between two points is equal to **111.11*cos( (latitude1+latitude2) /2)**.`

Hi @java_coffee_cup !

Yes. This is correct. But for a cosinus calculating on **degree** angles. @TBali just made a good observation that in my solution (C++) it is a cosinus calculating on **radian** angles.

As you are the second one to make this remark, i moved this part to **constraints** and changed this statement to :

One degree in longitude between two points is equal to

111.11*cos( (latitude1+latitude2) /2).BEWARE ! (latitude1+latitude2)/2is adegreevalue that might need to be converted intoradians.

Tell me if it is ok for you !

I though it was cos (avg of longitudes) ?

just a wild guess, because I have nowhere to make good use of the longitude values.

My bad, I checked some things but I trusted the formula, I didnâ€™t think about degrees/radian conversion.

1 Like

The explanation between this formula is quite visual, starting from the assumption that Earth is a perfect sphere:

- If you go one degree north or one degree south, it is the same distance whatever the longitude, hence latitude is always the same whatever the longitude.
- On the contrary, if you go one degree east or west at a longitude of 45Â° north, it will be a longer distance than at a longitude of 80Â° north. Hence the cosinus of the mean latitude on the longitude formula

Not your bad, my bad. You already helped a lot

Unfortunately, this one is funny, but not correct.

It seems the area is modeled as a *plan*, applying the latitude/longitude formulas (by the way, there really shouldnâ€™t be a need to mention degrees/radians : in the end, itâ€™s just an angle for which you want its cosine, at most mentioning to be careful of the actual unit expected by the platform `cos`

function should be enough), at least when looking at the expected results. But the text suggests modelling as a *sphere* ! In this case, the flight distance of the missile should be computed using spherical coordinates (which probably pushes the difficulty towards medium), and for points far enough from each other it makes a difference big enough that some tests have a different answer.

1 Like

Well, Iâ€™m not good enough to know about this. I found there longitude/latitude calculation formulas on internet, i am not a pro at all. What is sure is that there is no need for spherical coordinates.

I will do as you suggest, and remove the â€śearth is a sphereâ€ť thing. Might confuse the physics guys out here.

Just for my own knowlegde : isnâ€™t this longitude formula made considering earth as a perfect sphere, though ? Or i donâ€™t understand sh*t to geographical coordinates ?

Just copy the formula from the right official puzzleâ€¦

The formulas are correct when considering points at same latitude or longitude. But then when you â€ścomposeâ€ť using Euclid formula, that is only valid on a plane. The approximation is good enough for points not too far away. But as an example, imagine point A at (0, 0), and B at (89.99Â°, alpha), essentially they are 10000 km apart, which is the distance along the meridian, but if you take the cosine of the average latitude that is 0.7 and you will also account for 78 km per degree for alpha, which clearly doesnâ€™t make sense.

The correct approach is to convert the spherical coordinates (which is basically what you are given with latitude, longitude and altitude) to cartesian coordinates, where you can apply the euclidian distance. This is not 100% correct physically, as the straight line could go â€śthroughâ€ť the earth if the point at 160 km above the target is under the horizon.

Well, what i did is an approximation, and i knew it from the start. There are no extreme cases, as the latitude is between 16Â°51â€™29.3"N and 61Â°34â€™50.9"N, with a missile starting on 34Â°45â€™21.8"N.

Maybe i will do a medium version of this with spherical coordinates, for a more geographically accurate puzzle

For this puzzle though, i suggest that people follow the statement, and i am sorry if it disturbs some of you

Itâ€™s perfectly OK to use approximations !

The only small problem is that some actual test cases are on the verge of where the approximation holds, with exactly one failing with the â€ścorrectâ€ť implementation (didnâ€™t try the validators). My solution should pinpoint these edge cases on stderr.

1 Like

I am curious to have your result and see your code, if you are open to share it, donâ€™t hesitate to send me results of testcases and validators too in private message

If you go one degree north or one degree south, it is the same distance whatever the longitude, hence latitude is always the same whatever the longitude.

This is true if the two points are in the same longitude.

The test cases have different longitudes and latitudes.

I am no expert in GIS calculation, so relying on google:

You need Latitude and Longitude to calculate the distance between two locations with following formula: =acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371 (6371 is Earth radius in km.)

I also found this in TAN network (hinted by @nicola)

Either of them is approximation too, but should better suit your description where two points are in different Lats and Longs.

I am still struggling to comprehend the very long and complicated spec. The comprehension part is definitely harder then writing the code.

The point here was more to make a *read the statement* funny puzzle, than doing an accurate GIS puzzle, to be honest. Giving people everything they need if they search the statement and the given clues.

I will do better next time, I promise

hello great puzzle. I pass all the tests except test 3 Ferme Majonick (QuĂ©bec, Canada): possible. Send a Cow Harvester to bring back 20 cows.

I donâ€™t know why it gives me 19 cows as a result .

Hi to All, especially @Razovsky for this Puzzle !

â†’ Iâ€™ve got the same problem as @Kendra â€¦

My own computations calculate that the â€ś*Cow Harvester*â€ť can bring back **19.691538** cows in the 683.34467s allowed to harvest & take off vertically the 159.427 Km from the â€ś*Ferme Majonick (QuĂ©bec, Canada)*â€ť before the *hit-to-kill missile* collides with the collector !

=> Rounded down (as all my others calculations) to count only the *entirely harvestable cows* in time â€¦ **returns 19** for me, not 20 â€¦

â†’ can someone help me to understand where is my mistake, please ?

Thanks by advance, please â€¦

Hi,

For Ferme Majonick (QuĂ©bec, Canada), the Cow Harvester has 679.99728885721s to collect with a collect time per cow of 33.978933061502.

The total distance for that is 4165.4673792559km (lat distance: 1240.6974694444 long distance: 3973.18549716 elev distance: 159.954)

2 Likes