4 kyu
Spinning Rings - Fidget Spinner Edition
105 of 263Voile
Loading description...
Performance
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.
This comment has been hidden.
This is not a kata issue. You can ask a question, but tag it accordingly.
I had similar issues; it seems that this kata is all about finding an algorithm rather then an optimization for a solution of the related kata "Spinning Rings". Hope that helps a bit. Have fun!
I am disappointed, because to me it feels like this kata is just about finding a math solution, not how to code a solution. Thought this is Codewars, not Mathwars.
I'm disappointed you didn't read the first paragraph of the description, clearly stating this is a performance version of an easier coding challenge.
False assumption. I read it and that's exactly the reason why I feel disappointed. Just wrote this as explanation for the author so he knows why I did not rate it well.
Your assumption that this task requires math is also false. There are solutions that rely heavily on programming concepts such as iteration and recursion, with only minimal math. Anyway, I would never downvote a good quality code challenge, even if I don't like it. But you vote however you want. I just think it's better you stay from (what you consider to be) math heavy kata's, rather than to preach your disgust of them.
Consider Codewars a panopoly of restaurants. Given the inclinations of your palate, you can freely choose where to eat your next meal.
Thank you @rowcased!
What helped me a lot was making graphs using the code from the easier version. I was then able to see the patterns and get the answer by doing math. Hope this helps you
ok, but don't use the "suggestion" tag for suggestions to others users; instead use it for kata suggestions
This comment has been hidden.
Still, spoiler tag required
Is this related to
GCD
andExtended Euclidean Algorithm
?This comment has been hidden.
While solving the kata it felt like GCD-related at some point, but I could not figure out how... So I can neither confirm nor deny that it is GCD.
This comment has been hidden.
This comment has been hidden.
C translation
approved
C# Translation
Approved
C++ translation
approved
D translation
approved
oops didn't see these yet :)
approv2d
This comment has been hidden.
Huh. I got it! 1,5 months later. And I can't see it anymore =)
This comment has been hidden.
This comment has been hidden.
None. Your solution incorrectly returns
-1
.my bad. Thanks!
COBOL translation.
approved
Lets say i have
spinningRings(6,6)
is the answer:
3
(they just need to be aligned 0)or
6
(they must align 0 at top)?7, with a pencil and a paper:
.
Wow, this was difficult... (2 days) I wanted to go with an ugly 10 lines solutions with lots of modulos and conditionals, but finally I found it easier to isolate some cases in sub-functions. My advice : use verbose variable names to keep your code readable and do not hesitate to split the problem in sub-functions even-though it is not necessary.
I loved this one! It challenged me for two monthes... I tried to study some advanced modular arithmetics to solve it... I eventually did it, with a very ugly solution :p
For those struggling with it, it seems there's no actual algebraic trick. If I may give an advice, once you found the cyclic pattern, just analyze what's happening in different cases and try to find out how you can safely short circuit excessively large iterations that cause time outs.
Edit: Well, after seeing the author's solution in JS, there is a trick... Good luck for the ones trying to find it out ;)
Thanks for the tip! I'm even more scared now... 😨
This comment has been hidden.
It's always Voile's Katas that I seem to get stuck on. I've not given up yet, but I don't see a pattern.
Voile's katas are great!
Can you share the biggest test cases? I code calculates 2^48,2^48 in less than a second on my pc, but always times out on here.
In Python the max is over 280224453318977.
This comment has been hidden.
Check input range ;-)
This comment has been hidden.
But there's also the
<= 2^48
;-)Do you think you have to time to count to
2^48
one by one?Definitely not ! However, without the algebraic knowledge necessary to create an effective algorithm to solve this conundrum, this is more of a math and algebraic problem than a coding problem. I would guess that myjinxin2015 below with his 2 line solution does in fact know that particular algebraic solution and thus was able to easily calculate the answer through math, rather than iteration. I would love to learn, so if there is a resource you could point me to in order to begin I would certainly read and learn it. Either way thankyou again for your replies.
Well, so far I don't think anyone actually knows what's going on with the solutions (not me either ;-)), so I'm afraid you're out of help ;-)
But maybe squinting at the pattern will help you a bit? ;-)
great kata :)
python: innerMax and outerMax should be camel-cased
;-)
What is the algebra behind this solution? I didn't solve it but i would like to understand it.
This comment has been hidden.
This comment has been hidden.
could your kata be a duplicate of this one?
That one has the two rotators rotating in the same direction.
ah ok :)
Two-Liner solution submitted ;-)
Nice first solve ;-)
I thought my code was very ugly already, but apparently it can get much worse :P
Now I've got to solve it just to see myjinxin2015's code!
Where can I find that 2 liner solution?