27
2
Given a list of 1
s and -1
s, determine whether or not it is a valid OVSF code (by outputting a truthy or falsey value).
OVSF codes are defined as follows:
[1]
is an OVSF code.If
X
is an OVSF code, thenX ++ X
andX ++ -X
are both OVSF codes.Here
++
is list concatenation, and-
negates every element in the list.No other lists are valid OVSF codes.
You may assume the input list contains only -1
and 1
, but you must handle the empty list correctly, as well as lists whose length is not a power of 2.
Shortest code (in bytes) wins.
Test cases
[] -> False
[1] -> True
[-1] -> False
[1, 1] -> True
[1, -1] -> True
[1, 1, 1, 1] -> True
[1, 1, 1, 1, 1] -> False
[1, -1, -1, 1, -1, 1, 1, -1] -> True
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1] -> True
5What does "OVSF" stand for? – NoOneIsHere – 2017-01-10T21:07:13.927
5Orthogonal variable spreading factor, which refers to the way they are used and also to a useful property they have. This didn’t seem very relevant, but the Wikipedia link explains it all (vaguely). – Lynn – 2017-01-10T21:21:53.463