Ad
Puzzles
Games
Mathematics
Algorithms
Logic
Numbers
Data Types
Sequences
Arrays

Description

The Kolakoski Sequence is a infinite string of integers that describes it own construction. Each digit, in order, encodes the size of the run that some digit in the sequence appears.

The inital terms of the sequence seeded by [1,2] are:

1, 2, 2, 1, 1, 2, 1, 2, 2...

Notice that there is one 1, followed by two 2s, then two 1s. In general the repitition of digits can be described as:

1, 2, 2, 1, 1, 2, 1, 2, 2...

Or the sequence itself. That is the idea you will be exploring in this excercise.

Instructions

Task 1:

Generate_Kolakoski_Seq(seed, n)
Write a function that takes an array of symbols as a seed, and an integer n, and produces the Kolakoski Sequence for that seed up to the nth digit as a common separted string.

Generate_Kolakoski_Seq( [2,3], 11 )

returns "2,2,3,3,2,2,2,3,3,3,2"

Generate_Kolakoski_Seq( [2], 5 )

returns "2,2,2,2,2"

Task 2:

Find_Kolaskoski_Number(seed, n)
Write a function that takes an array of symbols and a large integer n, and returns the nth digit of the sequence as an integer.

Find_Kolaskoski_Number( [1,2], 10000 )

returns: 1

(There is a way to compute this without computing the whole sequence)

// takes int[] and int, returns string (comma seperated integers)
function Generate_Kolakoski_Seq(seed, n){

}


// takes int[] and int, returns int
function Find_Kolaskoski_Number(seed, n){

}