Send your feedback or ask for help here!
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
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)/2 is a degree value that might need to be converted into radians.
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.
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.
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.
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 …
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)