cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A342407 Number of 2's in the first 10^n entries of the Kolakoski sequence (A000002).

This page as a plain text file.
%I A342407 #24 Mar 25 2021 16:56:21
%S A342407 0,5,51,498,5004,50028,500014,4999954,49999325,499998777,5000002329,
%T A342407 49999998413,499999949299,4999999991841,49999999683763,
%U A342407 499999999022579,5000000005362272,50000000022520652,500000000055534895,5000000000274296550,50000000000909149240
%N A342407 Number of 2's in the first 10^n entries of the Kolakoski sequence (A000002).
%C A342407 This is a counterpart of A195206 in the sense that A195206 lists the number of 1's.
%F A342407 a(n) = 10^n - A195206(n).
%e A342407 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.
%o A342407 (Go)
%o A342407 package main
%o A342407 import (
%o A342407     "fmt"
%o A342407     "math"
%o A342407 )
%o A342407 func main() {
%o A342407     fmt.Println(a(5))
%o A342407 }
%o A342407 func a(n int) int {
%o A342407     k := int(math.Pow(10, float64(n))) // get the number of terms of the Kolakoski sequence (A000002) to generate
%o A342407     // seq stores the Kolakoski sequence
%o A342407     seq := make([]int, 0, k+1) // n+1 because instruction 2 could add one extra
%o A342407     var ind, i, toAppend int   // ind represents which instruction to follow
%o A342407     seq = append(seq, 1, 2, 2) // initial terms
%o A342407     ind = 2                    // follow third instruction next
%o A342407     i += 3                     // three numbers already added
%o A342407     for i < k {
%o A342407         if seq[ind] == 1 { // add one number?
%o A342407             if seq[len(seq)-1] == 1 {
%o A342407                 toAppend = 2
%o A342407             } else {
%o A342407                 toAppend = 1
%o A342407             }
%o A342407             seq = append(seq, toAppend)
%o A342407             i++   // we added a number
%o A342407             ind++ // next instruction
%o A342407         } else { // add two numbers
%o A342407             if seq[len(seq)-1] == 1 {
%o A342407                 toAppend = 2
%o A342407             } else {
%o A342407                 toAppend = 1
%o A342407             }
%o A342407             seq = append(seq, toAppend, toAppend) // append two numbers
%o A342407             i += 2 // we added two numbers
%o A342407             ind++
%o A342407         }
%o A342407     }
%o A342407     seq = seq[:k] // trim to k values
%o A342407     // now count twos
%o A342407     var twos int
%o A342407     for _, curr := range seq {
%o A342407         if curr == 2 {
%o A342407             twos++
%o A342407         }
%o A342407     }
%o A342407     return twos
%o A342407 }
%Y A342407 Cf. A000002. Counterpart of A195206.
%K A342407 nonn
%O A342407 0,2
%A A342407 _Ishan Goel_, Mar 11 2021