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.
Yup. My first try was recursive and completely off. Then I saw your comment, thought about the simple
1 x N
case, checked whether the induction holds and came to the same result as everyone else. I really should use the stuff I studied more often.Whenever I encounter a kata that's "Number of x in y" or "X at position N" or something like that, my first question is always "Can I math it?" Most sequencies can be solved mathematically instead of with loops or recursion or what have you. At that point, it's just a matter of crunching the sequence into an equation. The result is nearly always faster than programmatically calculating each N until you arrive at the one you want.
There are, of course, exceptions (prime numbers, for instance).
It's a similar solution to the one that is up voted the most just factored differently.