Background:
Take this input as an example:
1 1 2 1 1 2 1 3 1 3
If you look only at the first few digits, between 1 1 2
and 1 1 2 1 1 2 1
, this input appears to consist of the pattern 1 1 2
repeating indefinitely. This would make its period 3, as there are 3 numbers in the pattern.
Given only the first number, the period appears to be 1, as only the number 1
is in the input. Given the first two numbers, it still appears to be the number 1
repeating, so the period does not change.
Task:
Given an array of numbers (or strings, or similar), determine the period of each prefix of the array, and return the unique ones. For example, the above input would have periods of:
1 1 3 3 3 3 3 8 8 10
Thus, the output would be:
1 3 8 10
I/O:
Input should be an array of any set of a large number of different values. For example, numbers, strings, natural numbers, or pairs of integers. Booleans wouldn't be allowed, but chars/bytes would.
Output can be any reasonable representation of the numbers, such as an array/list, or a string with the numbers joined by newlines.
Test cases:
1 -> 1
1 2 1 1 2 1 -> 1 2 3
1 1 2 1 1 2 1 -> 1 3
1 2 1 2 1 2 1 2 4 -> 1 2 9
1 2 3 4 1 2 3 1 2 1 -> 1 2 3 4 7 9
4 4 4 4 4 4 4 4 4 4 -> 1