Skip to main content
added 45 characters in body
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283

Given a list of 1s and -1s, 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, then X ++ X and X ++ -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

Given a list of 1s and -1s, 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, then X ++ X and X ++ -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

Given a list of 1s and -1s, 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, then X ++ X and X ++ -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
Tweeted twitter.com/StackCodeGolf/status/819125780668104704
added 41 characters in body
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283

Given a list of 1s and -1s, 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, then X ++ X and X ++ -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

Given a list of 1s and -1s, determine whether or not it is a valid OVSF code.

OVSF codes are defined as follows:

  • [1] is an OVSF code.

  • If X is an OVSF code, then X ++ X and X ++ -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

Given a list of 1s and -1s, 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, then X ++ X and X ++ -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
edited tags
Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
added 34 characters in body
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283
Loading
Source Link
lynn
  • 69.2k
  • 11
  • 133
  • 283
Loading