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] -> False
[-1, -1] -> False
[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