Skip to main content
3 of 3
added 157 characters in body

bash, 56 54 38 bytes

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

Save this as a script, and pass the list of numbers as arguments (for an n-element list, you'll pass n arguments). The output is the exit code: 0 (for true) if the list is alternating, and 1 (for false) otherwise.

(Returning output in the exit code is allowed in the PPCG standard I/O methods.)

This works recursively:

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