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
I based this off this solution for "Twice Linear": https://www.codewars.com/kata/reviews/5672692ee3659e3f8a00000c/groups/584704443b2dea171f000178
This comment is hidden because it contains spoiler information about the solution
I did this too! It seemed like a natural fit but it's still O(n log n) so not much faster than some of the sloppier solutions (above).
Binary is a way of writing numbers. Good primers might be https://www.mathsisfun.com/binary-number-system.html and https://en.wikipedia.org/wiki/Binary_number. In decimal (what you refer to as "regular numbers"), each "place" has a value: a tens place, a hundreds place, a thousands place. The same is true in binary, but the values of the places are powers of 2 instead of powers of 10. A binary number like "101110" has 0 in the ones place, 1 in the twos place, 1 in the fours place, 1 in the eights place, 0 in the sixteens place, and 1 in the thirty-twos place. To convert to decimal, we calculate the powers of two for each place and multiply by the digit in that place.
I would love for some hints about the mathematical part. I was also able to guess the closed form for the sequence and can prove it using mathematical induction, but I have no idea how I would have done that if I hadn't seen the pattern. This is a nonlinear recurrence relation, right? Is there a trick to analyze it?
This comment is hidden because it contains spoiler information about the solution
Ah, but it is! Can you elaborate on what doesn't look right about it? Maybe it looks "backwards"? I actually had to check it after your comment to make sure it worked correctly, but it does. I wrote a comment in response to @Lavios below to offer a theoretical justification for why it works. Maybe that will help, but if it doesn't, I'd be happy to answer any questions you have.
This comment is hidden because it contains spoiler information about the solution
Ah, this looks like it would be the perfect exercise! Is there something I can do to help fix it?
I really appreciated this.
Test comment!
You only need the
takeWhile
function. You don't need to keepisEven
or anything after that. That stuff belongs in the "test cases" (on the lower right, when you're working on the problem).I think this problem would be great for learning higher-order functions if it was based around the built-in array type (in JS) rather than a linked-list type :)
This comment is hidden because it contains spoiler information about the solution
Loading more items...