Skip to main content
added 157 characters in body
Source Link

bash, 5656 54 38 bytes

[ -z $3 ]&&echo T||]||([ $1 != $3 ]&&echo F||(($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 Tthe exit code: 0 (for true) if the list is alternating, and F1 (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 print T;exit with return code 0;
  • else if the 1st element != the 3rd element, then print F;exit with return code 1;
  • else run the program recursively on the list with the first element removed.

bash, 56 bytes

[ -z $3 ]&&echo T||([ $1 != $3 ]&&echo F||(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 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.

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.
added 12 characters in body; deleted 5 characters in body
Source Link

bash, 56 bytes

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

Save inthis as a filescript, 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.

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.

bash, 56 bytes

[ -z $3 ]&&echo T||([ $1 != $3 ]&&echo F||(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 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.
Source Link

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.