Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Awesome, this should be considered best practice for C++ prior to C++11. So in my opinion every c++ developer should be aware of this solution too. For example you can't use std::to_string in c++99.
This comment is hidden because it contains spoiler information about the solution
Writting down the detailed steps on a paper helped me to clarify the algo ;)
So basically solution can be reduced to 2*(x1 * 2^0 + x2 * 2^1 + x3 * 2^2 ... xn * 2^n-1) + 1 or something similar, I see it now when I write it on paper, but why?
Is that generally known or you came up with this because of this kata?
I used to do this, but it's better to use std::to_string soo yeah.
Somethings wonky with negative test outputs.
I have derived the negative extension myself, as well as checked it against Wikipedia's...and yet it still gives errors on random negative numbers
Cheers! It looks like you solved the kata.
I suppose you've figured out that
source.Count()
enumerates the source and which is why it fails the tests. Using Count as an existence test is bad because the enumerable could be very large and costly to determine when all that is desired to know is whether there is at least one. The LINQ operator for existence tests is Any which does such a test -- but even calling Any would fail the test since it enumerates the first element of the enumerable.Imagine the following enumerable for a test case in CodeWars:
Implementations with early-out checks for
source.Count()
orsource.Any()
will encounter the CodeWars timeout and have their executions stopped.Thanks for your questions and for doing the kata.
I see no optimization here... just straighforward implementation of formula.
But for -6 -> -8 is expected and that is fine?
Edit:
I got it, thanks! :)
No, it should not be negative. Yes, you are missing the "Hint I" from the description.
This comment is hidden because it contains spoiler information about the solution
If the hashed pin is 99999 you this code will return string.Empty
I thougth CodeWars would check the boundary values when you do the Atempt?
Hello,
How fast was your solution?
Mine passes n = 10e7 in 1.394 seconds but it still times out during the random test.
[edit] for anyone wondering the threshold is to be able to return n=10e7 in approximately less than 1 second.
Tbh took me a while to pass in 12s :D
For this part: The operator must call the selector-Func no more than once per element.
What is considered element, is element considered pair, eg.:
Calling Tuple.Create(0,1) and Tuple.Create(1,2) is considered double calling for element 1? Or element is considered as pair 0 1 (or 1 2)?
------ edit -----
I figured out that it is pair but my test for iteration once over source was failing because I put
if (source.Count() == 0) yield break;
at begining of my second method that contained implementation, can someone explain why? I put that as protection line (not to even go to implementation if there are no elements) and it works fine only without that line. Imo I thing that it should't be an issue to have it or I am missing something?