7 kyu
The Hotel with Infinite Rooms
109 of 335sazzadshopno
Loading description...
Fundamentals
Mathematics
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.
Please don't post solutions in the discourse page, the solutions page is here for that. If ever you post code somewhere (to ask for help for example), use a spoiler flag.
When my solution timed out - I started to focus on a mathematical solution. A great excercise. I (re)learned a lot. Thanks!
What's the mathematics topic I would need to know to answer this properly?
Triangular numbers and algebra
Thank you very much. Sorry for the late reply, the notification didn't light up as normal.
Can somebody help me with my code I get exec timed out and I cannot optimize it any further? Reply and I will post the code.
take a math approach https://nrich.maths.org/2478
This comment has been hidden.
Reduced the number of tests so the
O(1)
solutions should pass again.As per ferencDobi's comment, the random tests make this harder than a typical 7 kyu kata.
This comment has been hidden.
Start small. Write out by hand the solutions to smaller problems such as groupSize(1, 6), groupSize(1, 7), groupSize(1, 8), and so on. As you do so you may see a certain kind of pattern.
This comment has been hidden.
The
D
argument can be as high as1e19
. Of course, linear solutions will not work.Can you give me a hint to solv it? I already red something about Gauss sums and series of numbers, but haven´t found a better solution. The description should be includet a hint like: Cant be solved with loop because D is to large. Then I wouldn´t tried it.
My loop times out on the longer test set, so I put in some puts to see where it fails but for the longer test set I get not output. Where is it? Many thanks!
Your code might time out, O(1) solution required to pass big random tests.
Thank you for your comment but why does it time out without printing the puts statements which are before the loop?
Haskell : https://www.codewars.com/kumite/5baa49fc764231ab2500029e?sel=5baa49fc764231ab2500029e
Approved
This comment has been hidden.
A lot of the problems which involve loops can be made a lot more efficient if you think a little about what you are looping over. There is a closed form solution of this problem, but you can still loop and solve it with a little thought.
Out of beta. Congratulations :)
Thank you.
Ruby translation. Please, review and approve.
Approved.
Python translation. Please, review and approve.
Approved.
Are you sure you don't want to enforce
O(1)
solutions? Otherwise itis too easymight be a duplicate of some already existing kata.This comment has been hidden.
Added random tests to prevent this problem.. Can you take a look?
Yep, fine by me. I think you could lower the number of random tests from
10^8
to10^7
(or at the very least to5 * 10^7
). This will still disallowO(n)
solutions but will not make users wait 11 sec for the tests to pass.I might be missing something, but I don't think this is 7 kyu anymore...