# Is there a bump?

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 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

• Test Case Request: Numbers other than 0-1-2-3, also negatives allowed/disallowed? Commented Feb 14, 2018 at 22:47
• 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) Commented Feb 15, 2018 at 2:39
• @ETHproductions Isn't that already covered by [1,2,2]? Or am I missing something?
– anon
Commented Feb 15, 2018 at 8:13
• @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]. Commented Feb 15, 2018 at 9:54

# APL (Dyalog), 1519 20 bytes

2 bytes saved thanks to @EriktheOutgolfer

{2>≢⍵:0⋄2∊|2-/×2-/⍵}


Try it online!

1 for bump, 0 for no bump.

• Unfortunately, this gives an error for ⍬, while it should return 0 instead (or throw an error for all falsy inputs). Commented Feb 14, 2018 at 23:07
• Oh, and, if you fix the issue, 0∊2> can be 2∊ instead for -2 bytes. Commented Feb 14, 2018 at 23:21
• @EriktheOutgolfer temporary quick fix, thanks Commented Feb 14, 2018 at 23:45
• Still fails for singleton lists Commented Feb 14, 2018 at 23:48
• @H.PWiz A possible fix is to replace ⍬≡ with 2>≢ for just 1 extra byte. Commented Feb 14, 2018 at 23:51

# Windows Batch, 126120 114 bytes

I was pretty excited about my first use of the shift command.

This script generally works for numbers within 9 digits(no matter positive or negative.)

:L
@if %3.==. exit/b
@if %2 gtr %1 if %3 lss %2 goto:e
@if %2 lss %1 if %3 gtr %2 goto:e
@shift
@goto:L
:e
@echo T

• An empty response might count as a consistent value, otherwise I think you might be able to save a couple of bytes by moving the echo T to the end and jumping to it instead of repeating it. I'm also wondering whether you can save bytes by moving the @shift to the beginning of the loop but I'm not so sure whether that helps.
– Neil
Commented Feb 15, 2018 at 0:57
• @Neil Thanks for the if-golf. I don't see any reason moving @shift forward will help save bytes. I will take a look at the possible shift movement anyways. Commented Feb 15, 2018 at 1:01

# C (gcc), 78 bytes

Variant: loop

r,i;f(a,n)int*a;{for(r=n>2,i=0;i<n-2;)r=(a[i++]-a[i])*(a[i]-a[i+1])<0&&r;i=r;}


Try it online!

Variant: recursive

f(a,n)int*a;{n=(n<3)?0:((a[--n]-a[--n])*(a[n]-a[n-1])<0&&((n<2)?1:f(a,n+1)));}


Try it online!

The criteria is that a[i]-a[i+1] and a[i+1]-a[i+2] are non-zero and have opposite sign. i=r is just a way to return the value (described here).

P. S. Additional two test cases may reveal bugs: { 1, 2, 1, 2, 2 } and { 2, 2, 1, 2, 1 }

• Welcome to PPCG! Commented Mar 3, 2018 at 8:11
• By the way, I think a[--n]-a[--n] has undefined behaviour and a[i++]-a[i] has unspecified behaviour. Doesn't matter since they seem to work with gcc in this case. Commented Mar 3, 2018 at 8:15

# APL (Dyalog Classic), 15 bytes

0∨.>2×/2-/⊃,⊃,⊢


Try it online!

# C (gcc), 101 97 bytes

r,i;f(a,n)int*a;{for(i=n|1;--i;a[i]-=a[i-1]);for(r=0;--n>0;r=a[n]<0&a[n-1]>0|a[n]>0&a[n-1]<0|r);}


Try it online!

Differences the list, then looks for two neighboring differences that are not zero and have opposite sign.

• Welcome to PPCG! Commented Feb 15, 2018 at 17:03

# Retina 0.8.2, 43 bytes

.+
$* 1(1+)1¶\1¶1\1|¶(1+)(?<!\2¶\2)¶(?!\2)  Try it online! Takes input on separate lines and outputs 0 or 1. Explanation: .+$*


Convert to unary.

1            |


Count at most one matching regex.

  (1+)1¶\1¶1\1


Match a number that is surrounded by greater numbers on both sides.

               ¶(1+)(?<!\2¶\2)¶(?!\2)


Match a number that is not surrounded by greater or equal numbers on either side, i.e. both are less.

# Python, 91 bytes

def f(a):return[i for i,j in enumerate(a[1:-1])if(j>max(a[i+2],a[i])or j<min(a[i+2],a[i]))]


An empty array is a falsey value, while a populated array is truthy

# GFORTH 71 Bytes

: B ROT 2DUP = -1 = IF DROP ROT = -1 = IF  ELSE ." TRUE " THEN THEN ;


Output:

1 2 1 B TRUE  ok
19 4 19 B TRUE  ok
5 4 6 B  ok


# Elm, 102 bytes

f a b=case b of
c::d::e->a c d::f a(d::e)
_->[]
a g=case g of
[]->1<0
i::k->i<0||a k
a<<f(*)<<f(-)


## Explanation

This works very similar to my Haskell answer. Except Elm is missing all of the functions that do stuff so I had to make every thing from the ground up. You can test it by running the following here

import Html exposing (text)
f a b=case b of
c::d::e->a c d::f a(d::e)
_->[]
a g=case g of
[]->1<0
i::k->i<0||a k
g=a<<f(*)<<f(-)
s x=case x of
True->"True"
False->"False"
main=g[1,1,1,1,1,0,1]|>s|>text


# Perl 6, 50 47 bytes

{?grep {0>(.[1]-.[2])*[-] .[^2]},.rotor(3=>-2)}


Try it online!

# Rust, 90 bytes

|a:&[u32]|(1..a.len().max(1)-1).any(|i|a[i-1].cmp(&a[i])==a[i+1].cmp(&a[i])&&a[i]!=a[i-1])


Attempt This Online!

A simple condition chain would have the same length:

|a:&[u32]|(1..a.len().max(1)-1).any(|i|a[i-1]<a[i]&&a[i]>a[i+1]||a[i-1]>a[i]&&a[i]<a[i+1])


Attempt This Online!