How can I devise an algorithm that inputs an array of numbers - of any length - and determines if a function they form represents an alternating motion?
For example,