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.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Clever. I like it!
I would not mind at all. Good catch.
Glad you both liked it. Looking at it now a couple of weeks later, I see a couple of ways to tighten it up, but I was probably pretty pleased with myself and rushed to hit submit.
Good kata. You might consider specifying the behavior for an empty str parameter. You specify the behavior for the upper bound on the parameter to return false, but do not specify lower-bound behavior. As a guess I was returning false for undefined or empty strings.
It may be a fundamental lesson of the kata to ONLY implement the functionality specified (an important lesson, IMO), in which case, it could be beneficial to specify the input in the error message. 'Failed for empty string parameter', or something. That would at least provide some focus for reevaluating a failed submission.
I ended up degrading my solution by setting up all of the edge case variations I could think of and tweaking my code until I hit upon an implementation that was accepted.
This comment is hidden because it contains spoiler information about the solution
That could possibly work. My desktop executes the worst test-case with DP solution in under two-seconds. Brute force solution takes 18 minutes.
Based on the error message, the snags seemed timeout-related, but I suspect it could have also been memory related; hitting a maximum stack-frame limit during recursion or simply due to the size of the arrays needed for memoization in a Dynamic Programming scenario.
I may just need to scale back the test scenarios to a maximum size that, while amenable to Dynamic Programming, might not necessarily rule-out brute-force solutions.
This doesn't feel any higher than a 4 kyu or 5 kyu to me. Anybody who solved it wanna chime in?
That's a good suggestion for a kata variant.
In fact, I initially started off writing a more complicated kata that would've called for something similar - a Plinko-like pegboard game where the input is a target bottom slot and a 2d array of pegs and missing pegs, while the output is the optimal (highest-probability) top slot to drop the ball. I wanted to structure the problem in such a way that Dynamic Programming was required, but I hit some snags with the constraints of the sandbox. In the meantime, I distilled the basic idea down to Pascal's Triangle and wrote this kata.
Before I return to my initial idea, it might be worth it to implement your variation. Feel free to do so yourself. If you beat me to it, I won't be mad =)
This is a very elegant solution. I broke my promise of <= 5000 and thus your submission. Apologies for changing it on you, and kudos for satisfying the original requirements to a tee.
Not at all, I think you read the Kata description and implemented the fastest (performant) solution that satisfied the requirements. I take any blame for not correctly conveying the intended spirit of the kata.
I probably should have removed the
We promise never to ask for any primes over 5000.
from the description so as not to encourage hard-coding of all primes out to 5000.The reason I limited my test cases to <= 5000 is because recursive solutions tended to get flaky in the sandbox environments at higher numbers.
Same here. I invalidated your solution. It's now: nth_fibonacci
Loading more items...