https://www.codingame.com/training/easy/hello-world

Send your feedback or ask for help here!

Created by @TBali,validated by @bbb000bbbyyy,@PatrickMcGinnisII and @Deltaspace.

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

https://www.codingame.com/training/easy/hello-world

Send your feedback or ask for help here!

Created by @TBali,validated by @bbb000bbbyyy,@PatrickMcGinnisII and @Deltaspace.

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

My code passes exactly half of the cases.

It doesn’t pass, for instance, test # 2:

Found: Haile to thee, Noble Master!

Expected: Chairete! Haile to thee, Noble Master!

My program counts the distance between locations using Haversine formula, and it indicates that the smallest distance is 2607 km to The_Globe_Theatre. While “Chariete!” can only be heard from Epidaurus, which is 9305 km from my location.

Even if I’m using a wrong formula, the discrepancy can’t be that big. What am I doing wrong?

Based on the expected output you mentioned, I assume we are talking about Test case #02, travel location #3, which is: N450915 E0125549. That is near Venice, halfway between London and Epidauros, Greece. See it on for example Google Maps:

https://www.google.hu/maps/place/45°09'15.0"N+12°55'49.0"E/@45.1559524,11.809514,8z/data=!4m5!3m4!1s0x0:0x0!8m2!3d45.1541667!4d12.9302778

PS: beware, based on reviewer feedback, I just changed the order of input of the puzzle, so you shall update your input parser code.

Sorry, somehow after your update all my code got deleted, so I probably won’t come back to this puzzle in the nearest future

If you ever submitted, you can get it back going to ‘results’ menu on the left, then to ‘history’ and ‘send to ide’. Sorry for the inconvenience.

My code passes all the cases except the second one…

I found “Chairete!” instead of “Chairete! Haile to thee, Noble Master!”

I used the wikipedia page given in the exercise and all the other cases seem right that’s why I don’t understand why it doesn’t seem good for test #2.

If someone can help me, it would be great !

Thanks in advance !

I assume it is the 4th location of IDE TEST #2, that is N450915 E0125549. Distance to both Epidauros Theater and London Globe Theater shall be 1191 km. I suggest try to print out to error log the distance values that your code calculates and see where is the difference.

Check your distances to the capitals, you certainly have two capitals that should be considered at equal distance but that you do not properly detect (due to rounding error or floating point inaccuracy).

Unfortunately, it’s a problem that is likely to happen as there are several possible formulas to compute the distance, which might lead to slightly different results. Anyway make sure (if appropriate to your programming language) to use 64-bit floating-point numbers (`double`

instead of `float`

in C/C++) to reduce that risk.

Hi,

To be honest, as the puzzle creator, I am a bit sad, that my puzzle received not too favourable average rating, with quite a big variance between 5s and 2s. As this was my very first puzzle candidate, I kindly ask for any feedback, what shall I do differently next time?

Did you find the puzzle too easy? Or too hard? Should it have been Medium instead of Easy?

Would you have needed more exact distance calculation formula in the description, instead of a wikipedia link and the need to figure it out yourself: sexagesimal DMS to decimal conversion, converting cardinal directions as the sign of the value, degree to radian conversion, which distance formula to use (with 64 bit float: any), rounding, etc.? (I thought if I write it all down, it is no longer a puzzle, maybe I was wrong.)

Were the test cases sufficient? Funny enough?

A few remarks:

- There are only 16 ratings for now (7 are <=2 stars).
- The “round and treat all values equal to the min” part could be trickier than you imagined (see my previous post in this thread), it can be frustrating to beginners who either do not know how to handle the boring floating-point issues or even are not aware of these issues. It seems to me that some easy (and maybe sometimes medium) puzzles have received bad ratings because of such issues.

+ I also checked very quickly and apparently you cannot solve this problem using the formula from Defibrillators. - Your puzzle did not benefit from a serious reviewing which could have spotted a few annoying points such as the previous one.

Well if you can take it, here’s what I commented on my own solution (that’s where I usually leave my hot takes, to remember them later on):

This puzzle has just about all it takes to tear the fun out.

Tedious input, useless input, numerical stability unawareness, voluntary hunting for rounding limits, unnatural output.

And quasiduplicate with an official puzzle, no less.

Not that I gave you a bad rating. I don’t remember what rating I gave, I just closed the page.

For me, this was such a nice puzzle - I have to learn few things on my own, which is fine. What I don’t like is validation on submitting result. I pass all test cases but didn’t pass Validator 6 on submit. And to be honest - looking for a bug in such mathematical code without any hint is nothing I would like to do. So I left this puzzle.

@Niako, @JBM, @Mejla: Thanks for the feedback. (And yes, I can take it )

The main takeaway for me is, that as a puzzle creator I need to focus much more on the ‘customer experience’.

If it is not too much to ask, I kindly ask to review and comment also my other puzzle (currently on the ‘contributions to be reviewed’ page) - maybe with the help of you it will be better in the end than this one.

I just finished it and there is too me few points missing making the debug a more complex. For example, I was having problem with puzzle 2 and 6. I realized that this is the only ones having a mix of N/S or E/W.

My first bet :

- I was using the wrong way of making conversion (to decimal but also for the +/-). I had to checked on several online converter to ensure it’s fine.

Second bet:

- I was using the wrong formula for the distance (because the formula is not given)… still no error.

Third bet:

- Rounding issue… but no

At the end it was because I didn’t realized that the angle for E/W had 3 digits and 2 for N/S (you mentionned it but I missed it). As a result, in the first debug, I checked E0162100 as 01° 62’ 100" and it was according my converter but instead it was 016° 21’ 00"

Maybe having the formula given and a step by step example would help a lot

Thanks for the feedback. Yes, 3 or 2 digits of longitude degree can make quite a difference.

I updated the puzzle description with some more specific hints on formula usage, coordinate conversions, 64-bit floats.

Hi! In python3 I use:

`sign = 1 if a[0] in ['N', 'E'] else -1`

for latitude and longtitude. But cases#2 and #6 failed.

Also I’ve used formula from wiki and got distances and answers in 2nd case:

[‘N373800’, ‘E0230800’] [‘N373800’, ‘E0230800’] 0.0

[‘N373800’, ‘E0230800’] [‘N513025’, ‘W0000542’] 2986.695524262495

[‘N373800’, ‘E0230800’] [‘N404532’, ‘W0735906’] 10801.48909842209

Chairete!

[‘N513025’, ‘W0000542’] [‘N373800’, ‘E0230800’] 2986.695524262495

[‘N513025’, ‘W0000542’] [‘N513025’, ‘W0000542’] 0.0

[‘N513025’, ‘W0000542’] [‘N404532’, ‘W0735906’] 8248.265905476199

Haile to thee, Noble Master!

[‘N404532’, ‘W0735906’] [‘N373800’, ‘E0230800’] 10801.48909842209

[‘N404532’, ‘W0735906’] [‘N513025’, ‘W0000542’] 8248.265905476199

[‘N404532’, ‘W0735906’] [‘N404532’, ‘W0735906’] 0.0

Hello, Dolly!

[‘N450915’, ‘E0125549’] [‘N373800’, ‘E0230800’] 1384.6340794800697

[‘N450915’, ‘E0125549’] [‘N513025’, ‘W0000542’] 1608.8048156436273

[‘N450915’, ‘E0125549’] [‘N404532’, ‘W0735906’] 9669.583300888533

Chairete!

[‘N505540’, ‘W0235856’] [‘N373800’, ‘E0230800’] 5432.102120089192

[‘N505540’, ‘W0235856’] [‘N513025’, ‘W0000542’] 2656.872234692642

[‘N505540’, ‘W0235856’] [‘N404532’, ‘W0735906’] 5592.914273079193

Haile to thee, Noble Master!

[‘N522335’, ‘W0411458’] [‘N373800’, ‘E0230800’] 7319.282253075043

[‘N522335’, ‘W0411458’] [‘N513025’, ‘W0000542’] 4577.035810425796

[‘N522335’, ‘W0411458’] [‘N404532’, ‘W0735906’] 3689.931510056004

Hello, Dolly!

[‘N450815’, ‘E0125649’] [‘N373800’, ‘E0230800’] 1382.0882714191703

[‘N450815’, ‘E0125649’] [‘N513025’, ‘W0000542’] 1611.2665451244145

[‘N450815’, ‘E0125649’] [‘N404532’, ‘W0735906’] 9671.397965775572

Chairete!

[‘N451015’, ‘E0125449’] [‘N373800’, ‘E0230800’] 1387.1800778182628

[‘N451015’, ‘E0125449’] [‘N513025’, ‘W0000542’] 1606.3434727884764

[‘N451015’, ‘E0125449’] [‘N404532’, ‘W0735906’] 9667.768787025907

Chairete!

[‘N512335’, ‘W0511458’] [‘N373800’, ‘E0230800’] 8380.007524859508

[‘N512335’, ‘W0511458’] [‘N513025’, ‘W0000542’] 5688.124812698316

[‘N512335’, ‘W0511458’] [‘N404532’, ‘W0735906’] 2576.530104476686

Where is my mistake?

For distance formula, see https://en.wikipedia.org/wiki/Great-circle_distance +

Use the 1st (arccos) formula from the above wikipedia page.

yes:

`fi1, fi2 = torad(a[1]), torad(b[1]) #to radians`

`t = math.sin(fi1)*math.sin(fi2)`

`p = math.cos(fi1)*math.cos(fi2)`

`q = math.cos(abs(torad(a[0]) - torad(b[0])))`

`r = 6371*math.acos(t + p*q)`

Use 64-bit precision float to avoid errors due to loss of precision.

used that:

`math.isclose(dists[j], min(dists), abs_tol=0.00001):`

Don’t forget to convert degrees, arcminutes, arcseconds to decimal degrees.

yes:

`decdeg = deg + (mn + sec/60)/60`

Don’t forget to handle North/South and East/West as the sign of decimal degrees.

yes:

`sign = 1 if a[0] in ['N', 'E'] else -1`

Don’t forget to convert decimal degrees to radians (distance formula is in radian!)

yes

`math.radians(decdeg*sign)`

And for separating degrees, minutes and seconds:

`deg = int(a[1:4]) if a[0] in ['E', 'W'] else int(a[1:3])`

`mn = int(a[-4:-2])`

`sec = int(a[-2:])`

Don’t mind…

Hi,

Unfortunately I don’t know Python so I don’t find what is the problem in the code you wrote. Checking my solution I noticed that all your calculated distances are wrong.

Maybe this could help: Here is the debug output from IDE TEST CASE 02, endpoint #3:

(Note: as per puzzle statement I rounded the distance to integer, so here it is already printed as integer. Below I print all coordinates in DMS, in decimal degrees and radian degrees)

Travel point #3: N450915 E0125549

= in DEG: (45.154166666667, 12.930277777778)

= in RAD: (0.78808887932761, 0.22567592041968)

distance = 1191 to Epidaurus:

N373800 E0230800

= in DEG: (37.633333333333, 23.133333333333)

= in RAD: (0.6568255751672, 0.40375283362802)

distance = 1191 to The_Globe_Theatre:

N513025 W0000542

= in DEG: (51.506944444444, -0.095)

= in RAD: (0.89896576819736, -0.0016580627893946)

distance = 6733 to Broadway:

N404532 W0735906

= in DEG: (40.758888888889, -73.985)

= in RAD: (0.71137681056564, -1.291281847088)

Result: closest capitals indexes = 0, 1; distance = 1191