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.
You could make this a little more difficult by also accepting negative amounts (formatted correctly ;) and requiring the function to throw an error if the running total drops below zero.. it's fine for beginners though.
I think some people are still confused by the ASCII jumping ;)
It might help to show the edge case where the rabbit is at the far fence: e.g. [3,1,0,0],0 and [4,1,0,0],0 both have the rabbit jump and land on the end position of the field. In the first case the rabbit faces right and will bounce back onto the final bean; in the second one, the rabbit faces left and misses it.
I initially understood this to mean that if prg>0, then the bottom layer is always filled. But in fact if prg is so low that it does not fill even the first layer, then it is empty too.
Maybe it could be clearer with "The slashes alternate between layers, starting with
\
in the lowest one and/
in the next layer."Seeing some of the solutions, I am glad I avoided regex for this one.
literally the first line
string[] delimiters = new string[] { " ", ",", ".", ":", "_", "-", "/", "", ";", "!", "?" };
these are not the only delimiting characters, you need to split on everything that isn't in [a-zA-Z] and '
MFW you submit a solution and then immediately see the shortcut that everyone else used in their solutions
The very definition of test-driven development! The description is lost just like you, but you don't need it. Just go and pass the tests.
I found a really elegant solution in Python, a little bit verbose to set up but ending with a simple one line sum.
You can find the answer by going through every combination of parens and summing up how many are true. But to avoid time outs you need to not repeat yourself too much. The hint is that each set of parentheses you add splits the problem into parts that you probably already solved before.
A little disappointing that the tests are so undemanding. Even the very naive solutions can pass.
This comment is hidden because it contains spoiler information about the solution
This one's definitely a performance kata, my initial naive solution took 3s on just the fixed tests and timed out on the random tests. After trying what I thought was a faster technique, the time tripled... Finally got something that squeaks in under the time limit if the RNG likes me. You have to be fast!
You've written an amazingly inefficient brute-force version of finding the answer, with the search space being literally all possible sums of numbers less than (n-1)^2. For very large n this will take a long time.
The fast, short solution is basically math nerd knowledge and not coding, but even so you could make a better brute force solution that stops checking in the innermost loop once result is bigger than n. You could also think about starting from n and trying to divide it into consecutive numbers rather than simply checking 0, 0+1, 0+1+2 etc. each time. If n can be divided into a sum of k consecutive numbers, then the middle number of the sequence will be about n/k.
I don't think there's a solution that's better than O(n^3), though there are some optimizations due to the nature of the required result. The three variables to find are x,y and size which are all bounded by the matrix size.
It was a fun dive into matrix searching, thanks :)
Converted to separate functions for each test, and commented.
Array.every and Array.some express the intention of the loop better than a plain for or forEach.
Loading more items...