7 kyu
Bugs Life
352 of 1,016saiyan91
Loading description...
Fundamentals
Geometry
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I can't figure out how hint #1 relates to the solution.
I would have deleted the first hint because it is not a hint at all. Can be easily misunderstood.
Hint #2 is normal.
Hint #1 is very good.
A beautiful problem. I liked it very much. Thanks.
this is not the shortest way?? i got the 3.95 noticing that bugs cant fly... cant proceed any further.
We find a large diagonal of a right triangle, according to the Pythagorean theorem. In 1 test I got the answer 3.74, but in the author the answer was 4.24. Why?
Is your question exactly the same as the one below?
Sorry, but I just didn't get an explanation to that.
Which diagonal has length of 3.74? Can a bug walk along it (i.e. does it stay on a wall all the time)?
Can't understand the idea of kata, why we can't go through the diagonals. It is the shortest way. In first test I got 3.74
Because the bug can't fly.
I translated this to Rust, please take a look!
Julia translation
This comment has been hidden.
It's not the only possible path.
Also added a C++ translation: https://www.codewars.com/kumite/5e491a2440d7a90032a6a484?sel=5e491a2440d7a90032a6a484 Please, take a look at it.
Hello! Who can explain me this Kata(idea) and solution please? I don't understand it.
Haskell translation
just done @JohanWiltink
Also added a Ruby translation. Please, take a look at it.
just done. for transparency, I've never coded in ruby so just clicked approve
This comment has been hidden.
Fixed.
Python translation. Please, review and approve.
Note: it addresses the issue of outdated description, so you can approve it without modifying the kata description yourself.
Did you fix the description? Or does it still mention rounding?
Fixed in the translation.
Hi guys, sorry, just seeing this. Do I need to approve the translation from my account? (if so, just how do I do that?) Just not sure if that comment was to me or not. Also, I am very happy to make chnages to the description in the JS version. Will do it now.
Yes, you should do this from the authoring account. Open the translation page (link provided) and press the big green
Approve
button.just done. Thank you. Making edits to description of JS one now.
There is no need, unless you want to add something for js only (and you use conditional formatting), all languages share the same description.
sorry, just cooking dinner and doing this! seen the changes to JS version were made just now. Thank you very much.
Please do not round results. Compare unrounded results with
assertApproxEquals
.Hi JohanWiltink, I was asked this in gitter by a user as to why I chose to do this, its a deliiberate choice. So, I am planning to build a bunch of Katas on mental math confidence. After these, I plan to refer back to this and show them how they could have done the solutions in under a min in their head using some composite techniques from different areas of maths (which will be developed through a series of Katas). Also, I wanted user to just practice with Math.round as well. If left unrounded, when they come back to it and look at their mental math solutions, the satisfaction will be much lower when it does not output same answer as this Kata.
@Johan: please see here! ;) (already an issue opened about python)
@Blind
( comment is about a different kata )
OK, approved that and closed that issue. Is that it for that kata / translation or are there any outstanding issues left?
And no, I didn't get a notification there. Does one only get notifications about threads one started?
No I hope it will be good, now. And no problem for the "delay". It was kinda funny to be chasing you in the dashboard... ;)
Notifications: no idea, never really understood how they (should?) work on CW... x)
thx and cheers (and sorry for the problems on the other kata).
@saiyan91: my apologies for polluting the discourse of your kata... ;)
@Saiyan
Great. Problem remains that if I calculate things in a slightly different order and arrive at
0.4999999999
instead of0.500000001
, it'll round wrong. ( Move it.5
either way andtrunc
,floor
andceil
will go wrong. )Floating point representation inevitably has this problem, and the only reliable way to not get bitten by it is by doing comparisons with a margin for error. ( That, or implement rationals. On top of BigInt probably. )
Practicing with
Math.round
is not a good thing.This is a bad kata design because computers can't calculate numbers in fractions like we do (unless you actually write a program which does calculate using fractions), and this very often leads to rounding mistakes.
Firstly, people do not just come back to already completed katas out of nowhere. Secondly, your statements about "mental math result != function result" makes no sense (in fact, I don't even understand what the user will be unsatisfied with, and why on earth will he/she be unsatisfied with it). Thirdly, the satisfaction will not be lower, it is already lower than it'd be without this crap about why rounding is good.
Also, if you're so keen to doo a series of mathematical katas about mental math or whatever, then why are you asking the user to return wrong answers?
@JohanWiltink, I just checked your solution method as well before replying, but with that method, is there anyway in which that rounding issue can occur? I did think of this, and thought as long as user is working out hypotenuse, and THEN rounding final answer to nearest integer, there would be no way for answer to round incorrectly and not hit the expected in random tests. As usual, pardon my ignorance and very happy to change code if you'd like, (was unware of Math.round being bad practice so thanks for that), but curious on above. Thank you very much. Also, just to be a bit clearer. I fully get that the numbers for a,b,c might square differently and therefore the additions of the a and b and c might be slightly different. But from reading stuff online on how JS does this, I thought the order of mag is too small to make difference to integer output in this question given operations invovled and therefore it was safe to do. But again, please let me know if just wrong, I am very happy to take on board suggestions and change accordingly. Thank you.
@FArekkusu, appreciate your time and comments. Okay, my understanding was as follows but a great chance I am just ignorant and wrong and very happy to learn. But I thought the rounding errors in JS are past order 10^-10 with basic addition and therefore can compound but still not impact the integer output given the operations involved in this question (again played with it on pen/paper and dummy tests to check whether this was right and was satisfied with output). So, when I show them the mental math approach I have in mind, the solution will marry up perfectly (there are layers to how I want to introduce roundings// squarings etc) and would be quite nice. I do take on board your point that people do not come back to Katas but I was planning at the end of my series to direct them to it. I am new to this, so please pardon any ignorance on approach.
This comment has been hidden.
This comment has been hidden.
@JohanWiltink, very nice. Thank you for that. I did not know that difference could occur in those 2 operations. Okay, would you like me to change the code to omit the rounding? also, not sure if upvoting does anything in this codewars but just gave you it. very helpful tip going forward in JS
Fixed it and approved.
Description still mentions "integer" twice.