prelude_to_self-describing_sequence
Table of Contents
Prelude to Self-describing Sequence
First, start by reading the problem statement for Self-describing Sequence.
For this prelude, create an array, fr
, that contains the index of each place in f(n)
where f(n)
changes values (that is, where the next run of identical values appears).
n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 f(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 fr[n] 1 2 4 6 9 12 16 ...
This array is a kind of run-length encoding of function f(n)
.
Input
Input consists of a sequence of integers, one per line. The last entry is a 0, which should not be processed.
Output
For each non-zero input value, k
, print the value of n
where f(n)
changes to k
.
Sample Input
7 0
Sample Output
16
prelude_to_self-describing_sequence.txt · Last modified: 2011/09/20 06:34 by jtkorb