Skip to main content
1 of 3

bash, 56 bytes

[ -z $3 ]&&echo T||([ $1 != $3 ]&&echo F||(shift;$0 $*))

Save in a file, and pass the list of numbers as arguments (for an n-element list, you'll pass n arguments). The output is T if the list is alternating, and F otherwise.

This works recursively:

  • If the list has fewer than 3 elements, then print T;
  • else if the 1st element != the 3rd element, then print F;
  • else run the program recursively on the list with the first element removed.