Hello! I'm Mike! I'm from the UK, you can normally find me online as @MikeRogers0
This is the main bit of the task which jumped out to me. Especially the word "Cartesian (Car-tea-shin) Coordinates". I think that was keyword hint, but I kind of ignored it.
So what are we trying to do? We're going to be given coordinates, we need to return a score.
I thought the best place to start would be by getting the correct score given just one coordinate. So I just passed in X, looped though the radius-to-score mapping returning the source.
That actually worked out ok. I thought I was on the right track to solving this.
So I thought the right way I could get the correct was to just to pick the biggest of X & Y, then get the score from that. I messed about with a few coordinates like: x = 9, y = 0 x = 1, y = 1 & x = 0, y = 2 It look like it was working. I was feeling pretty good.
Spoiler: That was not the right solution. I then came back the term: "Cartesian (Car-tea-shin) Coordinates" I searched on Wikipedia, ended up on a page with diagram of a circle.
Then I realised my mistake, and I drew it onto a graph to emphasise it a bit better. If we look at 9,-9. My "take the biggest coordinates" approach wasn't so full proof. Obviously it would have worked if these were squares.
What we need to do is figure is if the point is within one of the circles. This distance, the black line
Luckily we know the distance these two lines, which gives us something which looks suspiciously like a triangle.
We need to use Pythagorean theorem!
I did have to search how to do "To the power of" & "Square root" in ruby. While searching Stackoverflow, I found:
I found out yesterday, there is actually a Math.hypot method to do this!
My full code looked a bit like: - I'm not fan about how I'm just setting x & z in the initialize - I don't really like how I calculated the score, or the "hypotenuse_score_map" variable naming. -- If I was to add a new score circle in & put it in the wrong place, it would probably break.
However! The tests were passing, so I was happy enough to submit it. I did run the tests a bunch & look what happens if I was to calculate the hypotenuse in the initialize, but that ended up being an exceptionally tiny difference.