login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A342407
Number of 2's in the first 10^n entries of the Kolakoski sequence (A000002).
0
0, 5, 51, 498, 5004, 50028, 500014, 4999954, 49999325, 499998777, 5000002329, 49999998413, 499999949299, 4999999991841, 49999999683763, 499999999022579, 5000000005362272, 50000000022520652, 500000000055534895, 5000000000274296550, 50000000000909149240
OFFSET
0,2
COMMENTS
This is a counterpart of A195206 in the sense that A195206 lists the number of 1's.
FORMULA
a(n) = 10^n - A195206(n).
EXAMPLE
The first 10 entries of the Kolakoski sequence (A000002) are 1221121221. From this we see that a(0) = 0, since the first term is not a 2, and a(1)=5 since among the first 10 terms, 5 of them are 2's.
PROG
(Go)
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(a(5))
}
func a(n int) int {
k := int(math.Pow(10, float64(n))) // get the number of terms of the Kolakoski sequence (A000002) to generate
// seq stores the Kolakoski sequence
seq := make([]int, 0, k+1) // n+1 because instruction 2 could add one extra
var ind, i, toAppend int // ind represents which instruction to follow
seq = append(seq, 1, 2, 2) // initial terms
ind = 2 // follow third instruction next
i += 3 // three numbers already added
for i < k {
if seq[ind] == 1 { // add one number?
if seq[len(seq)-1] == 1 {
toAppend = 2
} else {
toAppend = 1
}
seq = append(seq, toAppend)
i++ // we added a number
ind++ // next instruction
} else { // add two numbers
if seq[len(seq)-1] == 1 {
toAppend = 2
} else {
toAppend = 1
}
seq = append(seq, toAppend, toAppend) // append two numbers
i += 2 // we added two numbers
ind++
}
}
seq = seq[:k] // trim to k values
// now count twos
var twos int
for _, curr := range seq {
if curr == 2 {
twos++
}
}
return twos
}
CROSSREFS
Cf. A000002. Counterpart of A195206.
Sequence in context: A369295 A145641 A317782 * A195211 A106415 A212819
KEYWORD
nonn
AUTHOR
Ishan Goel, Mar 11 2021
STATUS
approved