39
2
Given a list of positive integers determine if there is an element that is either greater than its two neighbors or less than its two neighbors (a "bump"). To be clear a bump can never be the first or last item of the list because they only have one neighbor.
Your program should output one of two consistent values each corresponding to either a list with no bumps or a list with bumps. What the values are is unimportant you may choose them yourself.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test cases
[] -> False
[1] -> False
[1,2] -> False
[1,2,1] -> True
[1,2,2] -> False
[1,2,3] -> False
[1,2,2,1] -> False
[1,2,2,3] -> False
[1,2,1,2] -> True
[1,3,2] -> True
[3,1,2] -> True
[2,2,2] -> False
5Test Case Request: Numbers other than 0-1-2-3, also negatives allowed/disallowed? – Magic Octopus Urn – 2018-02-14T22:47:52.473
Suggested test case:
[1,3,3]
(ensures that answers using Dennis's algorithm take the sign of the increments rather than just using the increments themselves) – ETHproductions – 2018-02-15T02:39:54.0271@ETHproductions Isn't that already covered by
[1,2,2]
? Or am I missing something? – Fund Monica's Lawsuit – 2018-02-15T08:13:42.4702@NicHartley, the deltas of
[1,2,2]
are the same as the signs of those deltas but that's not the case with[1,3,3]
. – Shaggy – 2018-02-15T09:54:28.790