Given a list \$X\$ of 2 or more integers, output whether, for all \$n\$ such that \$0 \leq n < length(X)-2\$, there exists a pair of equal integers in \$X\$ separated by exactly \$n\$ elements.
In other words: output whether, for all overlapping slices/windows of the input, there exists at least one slice/window of each length wherein the head of the slice/window equals the tail.
For example: [1, 1, 3, 2, 3, 1, 2, 1]
will return truthy, because
[1, x, x, x, x, x, x, 1]
These 1s are separated by 6 elements, the most possible in an 8 element list,
[x, 1, x, x, x, x, x, 1]
These 1s are separated by 5 elements,
[1, x, x, x, x, 1, x, x]
These 1s are separated by 4 elements,
[x, 1, x, x, x, 1, x, x]
These 1s are separated by 3 elements,
[x, x, x, 2, x, x, 2, x]
These 2s are separated by 2 elements,
[x, x, 3, x, 3, 1, x, 1]
These 3s are separated by 1 element (as are the 1s, but either pair is sufficient),
[1, 1, x, x, x, x, x, x]
And these 1s are separated by 0 elements, the least possible.
But [1, 1, 2, 2, 1, 1]
will return falsy, as there is no pair of equal elements separated by exactly one element. That is, there is no length 3 slice/window with a head equal to it's tail. See all length 3 slices/windows below:
[1, 1, 2]
[1, 2, 2]
[2, 2, 1]
[2, 1, 1]
Standard I/O applies, input does not have to allow negatives, or input can be a string of characters, etc.
Anything reasonable as long as you're not cheating :)
This is code-golf, so shortest code in bytes wins!
Examples
Truthy
[1, 1]
[1, 1, 1]
[3, 3, 7, 3]
[2, 2, 1, 2, 2]
[2, 1, 2, 2, 2]
[1, 3, 1, 3, 1, 1]
[1, 1, 3, 2, 3, 1, 2, 1]
[1, 1, 1, 1, 1, 1, 2, 1]
Falsy
[1, 2]
[1, 2, 1]
[1, 2, 3, 4]
[3, 1, 3, 1, 3]
[3, 1, 1, 3, 1]
[1, 3, 1, 1, 3, 1]
[1, 1, 2, 2, 2, 2, 1, 1]
[1, 1, 1, 1, 1, 1, 1, 2]
1, 1, 3, 2, 3, 1, 2, 1
would return falsy, as2 3 1 2
and1 3 2 3 1
dont have the same head/tail (2
vs1
). I also don't see what's gained by using|X|
in place oflength(X)
. I'm reverting it for now. EDIT: i see that my original wording also had that mistake. This should be a tad better. Feel free to reword this version, but I still don't agree with using absolute value bars for length. Seems like a barrier for entry. \$\endgroup\$n
pairs of one integer. \$\endgroup\$