Question: Use python! Please make sure pass each input test. Thank you! See: The Kolakoski Sequence - Numberphile The Kolakoski Sequence is a sequence of integers,
See: The Kolakoski Sequence - Numberphile The Kolakoski Sequence is a sequence of integers, made up only of 1s and 2s, which describes itself. The first few numbers are: 4 The sequence is interesting because if you count the "runs" (sequential identical numbers), the sequence is the same: One number in a row (happens to be 1) Two numbers in a row (2) Two numbers in a row (1) etc. . There are a number of ways to build this sequence, some more efficient than others. In this problem, you will use a method which is not very efficient, but which is very interesting: you will use recursion The recursive way to build this sequence is as follows: Generate a short version of the sequence Use that short sequence, as input, to build a longer version Repeat until it is as long as you want . . (Of course, you could optimize this by simply extending the shorter sequence, but we're not going to do that. In order to focus on recursion, you will rebuild the entire sequence from scratch, every time. The function will have a single parameter 'depth', which is a non- negative integer. This integer simply tells you how many times to expand the sequence. If depth-0, then return [1.2]. Otherwise, you must recurse, and use the shorter list to build a new, longer list. Do not expand the old list, build a new one from scratch. Your function will return a list of integers, which hre the integers of the sequence - expanded 'depth' many times
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
