login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A338643 Cycle lengths arising from interpreting sequence prefixes as graph node offsets. 1
1, 1, 2, 2, 3, 2, 3, 4, 3, 3, 4, 5, 3, 4, 4, 5, 6, 4, 4, 5, 5, 6, 7, 11, 5, 5, 6, 6, 7, 8, 5, 13, 6, 6, 7, 7, 8, 9, 6, 6, 16, 7, 7, 8, 8, 9, 10, 17, 7, 7, 10, 8, 8, 9, 9, 10, 11, 8, 10, 8, 8, 11, 9, 9, 10, 10, 11, 12, 8, 9, 11, 9, 9, 12, 10, 10, 11, 11, 12, 13 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,3
LINKS
Rémy Sigrist, C program for A338643
EXAMPLE
Start with a(1) = 1. Treat a(1) = 1 as a node pointing 1 space ahead which, wrapping around the end of the length-1 prefix, points to itself. This graph has a cycle length of 1, so a(2) = 1.
Now a(1..2) = [1, 1]. a(1) = 1 points 1 space ahead to a(2) and a(2) = 1 points 1 space ahead and wraps around to a(1), completing a cycle of length 2 so a(3) = 2.
Skipping ahead a bit, a(1..5) = [1, 1, 2, 2, 3]. In this prefix, a(1) = 1 points to a(2) = 1, which points to a(3) = 2, which points to a(5) = 3, which wraps around and points to a(3), for a cycle length of 2, so a(6) = 2.
PROG
(Kotlin)
fun graph_sequence(terms: Int): List<Int> {
val a = mutableListOf(1)
repeat(terms-1) { a += a.loopLength() }
return a
}
fun List<Int>.loopLength(): Int {
val visitedIndices = mutableMapOf<Int, Int>()
var idx = 0
var counter = 0
while (idx !in visitedIndices) {
visitedIndices[idx] = counter++
idx = (idx + this[idx]) % this.size
}
return counter - (visitedIndices[idx] ?: 0)
}
(C) See Links section.
CROSSREFS
Sequence in context: A366686 A071647 A034883 * A051125 A321126 A342765
KEYWORD
nonn
AUTHOR
Matthew Malone, Apr 21 2021
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified September 4 13:47 EDT 2024. Contains 375683 sequences. (Running on oeis4.)