Task
Define a mod-fold as a function of the form f(x) = x % a1 % a2 % … % ak, where the ai are positive integers and k ≥ 0. (Here, % is the left-associative modulo operator.)
Given a list of n integers y0, …, yn−1, determine if there exists a mod-fold f so that each yi = f(i).
You may choose and fix any two outputs Y and N for your function/program. If there exists such an f, you must always return/print exactly Y; if not, you must always return/print exactly N. (These could be true
/false
, or 1
/0
, or false
/true
, etc.) Mention these in your answer.
The shortest submission in bytes wins.
Example
Define f(x) = x % 7 % 3. Its values start:
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...
| f(x) | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | ...
Thus, given 0 1 2 0 1 2 0 0 1 2
as input to our solution, we would print Y, as this f generates that sequence. However, given 0 1 0 1 2
as input, we would print N, as no f generates that sequence.
Test cases
The formulas given when the output is Y are just for reference; you must at no point print them.
0 1 2 3 4 5 Y (x)
1 N
0 0 0 Y (x%1)
0 1 2 0 1 2 0 0 1 2 Y (x%7%3)
0 0 1 N
0 1 2 3 4 5 6 0 0 1 2 Y (x%8%7)
0 1 2 0 1 2 0 1 2 3 N
0 2 1 0 2 1 0 2 1 N
0 1 0 0 0 1 0 0 0 0 1 Y (x%9%4%3%2)