5 kyu
Cycle Detection: Floyd's The Tortoise and the The Hare
181 of 256user3482173
Loading description...
Mathematics
Algorithms
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.
Python: Needs random tests.
python new test framework is required. updated in this fork
This comment has been hidden.
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
The link to the other kata at the end of the description is broken and should redirect here
A good kata with a bearly understandable description. Like others said here, read the Wikipedia page before you start coding.
Fun fun :)
I really liked this challenge, but I agree with the below that the explanation is unecessarily complicated. I recommend that the user is simply pointed to the cycle detection page on Wikipedia to understand the concepts involved before coming back to complete the challenge (either that, or include more diagrams in the instructions themselves to make them clearer).
Anyhow, the bulk of the challenge here is just understanding what's going on, and not in the coding itself. As a coding problem I'd probably give it a 6 kyu with the caveat that the user has taken the time to digest the maths.
I got hung up thinking mu was the value of the start but instead its the index of the start.
This is an interesting topic, but the explanation is unecessarily confusing. There are much simpler explanations of the three steps, but I would probably recommend this be a 4kyu kata.
My submissions are timing out unexpectedly. There is not really any reason why, the algo is really straightforward. Not a level 5 kyu in my mind, but a nice subject. Thanks for the kata
This comment has been hidden.
Both sequences would be [0, 5]. mu is 0 since the cycle starts at the 0th element, and the distance between repetition is 5. mu is not the value of the element that starts the cycle, but the index. Do not ignore x0. I'd recommend you complete the "Greedy Algorithm" kata before attempting this one, as it explains cycle detection terms in greater detail: http://www.codewars.com/kata/5416f1834c24604c46000696
The integer division problem is irrelevant, since you're never going to be using the resulting number for anything other than equality and, e.g., 8 / 3 == 8 / 3 is always going to be true, even in JS.
Ah, ok! Now everything is clear. As I said: I must have missed something. I would have bet
mu
was the value and not the index. Sorry for missunderstanding and thank you for the explanation. Anyway, maybe it's not a bad idea to define these two values again in this Kata rather than assuming everyone has copleted the other one before?Just one tiny typo : on the line where it says "and the hare by two (tortoise=f(f(tortoise)). " I think you meant "and the hare by two (hare=f(f(hare)). "
Other than that, awesome series of katas, really refreshing (and you learn something new!), keep up the good work!