47
\$\begingroup\$

An insignificant array is an array of positive integers, where the absolute differences between consecutive elements are all smaller than or equal to 1.

For example, the following array is insignificant:

[1, 2, 3, 4, 3, 4, 5, 5, 5, 4]

Because the corresponding (absolute) differences are:

[1, 1, 1, 1, 1, 1, 0, 0, 1]

Which are all smaller than or equal to 1.


Your task is to determine whether a given array of integers is insignificant.

  • You may assume that the array always contains at least two elements.
  • Standard input and output rules apply. You may take input (and output) in any reasonable format.
  • Default Loopholes are forbidden.
  • The truthy / falsy values have to be distinct and consistent.
  • This is , so shortest answer in bytes wins.

Test cases

Input -> Output

[1, 2, 3, 4, 3, 4, 5, 5, 5, 4] -> true
[1, 2, 3, 4, 5, 6, 7, 8, 9, 8] -> true
[3, 3, 3, 3, 3, 3, 3]          -> true
[3, 4, 4, 4, 3, 3, 3, 4, 4, 4] -> true
[1, 2, 3, 4]                   -> true 
[5, 4, 3, 2]                   -> true 
[1, 3, 5, 7, 9, 7, 5, 3, 1]    -> false
[1, 1, 1, 2, 3, 4, 5, 6, 19]   -> false
[3, 4, 5, 6, 7, 8, 7, 5]       -> false
[1, 2, 4, 10, 18, 10, 100]     -> false
[10, 20, 30, 30, 30]           -> false

I used the values true and false.

\$\endgroup\$
3
  • \$\begingroup\$ Do the truthy/falsy values actually have to be truthy/falsy in our language of choice, or can we use any two distinct and consistent values? \$\endgroup\$ Commented Sep 20, 2017 at 17:36
  • 1
    \$\begingroup\$ @MartinEnder Any two distinct and consistent values. P.S Sorry for the late response \$\endgroup\$
    – user70974
    Commented Sep 20, 2017 at 18:04
  • 5
    \$\begingroup\$ The text says you'll be given an array of integers, but that only arrays of positive integers can be insignificant. Should we be prepared for an array of negative integers? \$\endgroup\$
    – Mark S.
    Commented Sep 23, 2017 at 12:50

69 Answers 69

26
\$\begingroup\$

Jelly, 3 bytes

IỊẠ

Try it online!

How?

Just the perfect challenge for Jelly.

IỊẠ   Full program.

I     Increments; Get the difference between consecutive elements.
 Ị    Insignificant; return abs(number) ≤ 1.
  Ạ   All; returns 1 if all the elements are truthy, 0 otherwise.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ P wouldn't work would it, because if all the differences were 1 it'd output 1, but if one of them was 0 it would output 0? And if one difference was 5 but one was 0 it would still do 0? \$\endgroup\$
    – Tas
    Commented Sep 22, 2017 at 3:59
  • 1
    \$\begingroup\$ What about the "positive integers" requirement? \$\endgroup\$
    – 3D1T0R
    Commented Sep 23, 2017 at 3:06
21
\$\begingroup\$

JavaScript (ES7), 33 29 bytes

Saved 4 bytes thanks to @JohanKarlsson

a=>!a.some(v=>(a-(a=v))**2>1)

How?

When coerced to Number, arrays of at least two elements are evaluated to NaN. By re-using the input a as the variable holding the previous value, the first iteration of some() always results in ([v0, v1, ...] - a[0]) ** 2 = NaN, no matter the value of a[0]. So, the first test is always falsy and the actual comparisons start at the 2nd iteration, just as they're meant to.

Test cases

let f =

(a,p)=>!a.some(v=>(p-(p=v))**2>1)

console.log(f([1, 2, 3, 4, 3, 4, 5, 5, 5, 4])) // true
console.log(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 8])) // true
console.log(f([3, 3, 3, 3, 3, 3, 3]         )) // true
console.log(f([3, 4, 4, 4, 3, 3, 3, 4, 4, 4])) // true
console.log(f([1, 2, 3, 4]                  )) // true
console.log(f([5, 4, 3, 2]                  )) // true
console.log(f([1, 3, 5, 7, 9, 7, 5, 3, 1]   )) // false
console.log(f([1, 1, 1, 2, 3, 4, 5, 6, 19]  )) // false
console.log(f([3, 4, 5, 6, 7, 8, 7, 5]      )) // false
console.log(f([1, 2, 4, 10, 18, 10, 100]    )) // false
console.log(f([10, 20, 30, 30, 30]          )) // false

\$\endgroup\$
3
  • \$\begingroup\$ 29 bytes: a=>!a.some(v=>(a-(a=v))**2>1) \$\endgroup\$ Commented Sep 22, 2017 at 8:45
  • \$\begingroup\$ @JohanKarlsson Ah yes, the input is guaranteed to contain at least 2 elements, so that's safe. Thanks a lot! \$\endgroup\$
    – Arnauld
    Commented Sep 22, 2017 at 11:47
  • \$\begingroup\$ It requires two value than t/f so ! is unnecessary. Also even if 1 element possible p-(p=v) is zero and it works fine \$\endgroup\$
    – l4m2
    Commented Apr 2, 2021 at 13:36
11
\$\begingroup\$

Python 3, 40 bytes

f=lambda n,*t:t==()or-2<n-t[0]<=1==f(*t)

Try it online!

\$\endgroup\$
0
9
\$\begingroup\$

Mathematica, 24 bytes

Max@Abs@Differences@#<2&
\$\endgroup\$
2
9
\$\begingroup\$

Haskell, 34 33 bytes

all((<2).abs).(zipWith(-)=<<tail)

Try it online! -1 byte thanks to @user1472751


The point-free solution is one two again only one byte (thanks to -1 byte from @Dennis) shorter than the recursive approach:

f(a:b:r)=2>(a-b)^2&&f(b:r)
f _=1>0

Try it online!

\$\endgroup\$
0
8
\$\begingroup\$

Octave, 21 bytes

@(x)all(diff(x).^2<2)

Anonymous function that inputs a numeric vector and ouputs 1 if insignificant or 0 otherwise.

Try it online!

\$\endgroup\$
7
\$\begingroup\$

Pyth, 6 bytes

._MI.+

Verify all the test cases.


Pyth, 8 bytes

.A<R2aVt

Try it online!

Explanation

._MI.+   Full program.

    .+   Deltas.
   I     Is invariant under...
._M      Mapping with Sign. 0 if n == 0, -1 if n < 0, 1 if n > 0.

.A<R2aVt    Full program.

      Vt    Vectorize function, applied on the input zipped with the tail of the input.
     a      Absolute difference.
  <R2       For each, check if it is smaller than 2.
.A          All.
\$\endgroup\$
1
  • \$\begingroup\$ I have no idea why I thought I# instead of M. \$\endgroup\$
    – Steven H.
    Commented Sep 20, 2017 at 18:48
7
\$\begingroup\$

Python 2, 35 bytes

x=input()
while-2<x.pop(0)-x[0]<2:1

Exists with status code 1 for insignificant arrays, with status code 0 otherwise.

Try it online!

\$\endgroup\$
6
\$\begingroup\$

Husk, 4 bytes

ΛεẊ-

Try it online!

Explanation:

ΛεẊ- 2-function composition
Λ    (x -> y):f -> [x]:x -> TNum: Check if f returns a truthy result for all elements of x
 ε    f: TNum:x -> TNum: Check if abs(x) <= 1 (shamelessly stolen from Jelly)
  Ẋ   x: (x -> x -> y):f -> [x]:x -> [y]: reduce each overlapping pair of x by f
   -   f: TNum:x -> TNum:y -> TNum: y - x
\$\endgroup\$
6
\$\begingroup\$

Japt, 6 bytes

äa e<2

Try it online!

Explanation

ä        Get all pairs of elements
 a       Take absolute difference of each pair
         This results in the deltas of the array
   e     Check if every element...
    <2   Is less than 2
\$\endgroup\$
6
\$\begingroup\$

APL, 13 bytes

{×/(|2-/⍵)<2}

First APL answer \o/

Note: I am a bot owned by Hyper Neutrino. I exist mainly for chat testing.

Explanation

{×/(|2-/⍵)<2}
{           }  Function; right argument is ⍵
   (     )     Bracketed Expression
       /       Reduce
     2         Every pair (two elements) of
        ⍵      ⍵
      -        Using subtraction
    |          Magnitude (Absolute Value)
          <2   For each element, is it less than two?
  /            Reduce over
 ×             Multiplication (Product) (All)
\$\endgroup\$
2
  • 2
    \$\begingroup\$ 11 bytes as tacit - ∧/2>(|2-/⊢) \$\endgroup\$
    – Uriel
    Commented Oct 30, 2017 at 21:52
  • 1
    \$\begingroup\$ Vyxal bot how could you betray us like this? :p \$\endgroup\$
    – lyxal
    Commented Aug 16, 2021 at 11:22
5
\$\begingroup\$

05AB1E, 5 bytes

¥Ä2‹P

Try it online!

Explanation

¥        # calculate deltas
 Ä       # absolute values
  2‹     # smaller than 2
    P    # product
\$\endgroup\$
2
  • \$\begingroup\$ @Okx: I'm afraid not. It won't work for [5,2] for example. \$\endgroup\$
    – Emigna
    Commented Sep 20, 2017 at 17:28
  • \$\begingroup\$ 2‹ can be ! for -1 byte \$\endgroup\$ Commented Oct 20, 2023 at 14:56
5
\$\begingroup\$

Proton, 41 bytes

a=>all(-2<a[i]-a[i+1]<2for i:0..len(a)-1)

Try it online!

-16 bytes thanks to Mr. Xcoder
-2 bytes
-6 bytes thanks to Mr. Xcoder

\$\endgroup\$
4
  • \$\begingroup\$ 49 bytes (-16 bytes) \$\endgroup\$
    – Mr. Xcoder
    Commented Sep 20, 2017 at 16:06
  • \$\begingroup\$ @Mr.Xcoder I think the space in <2 for might be omittable. \$\endgroup\$ Commented Sep 20, 2017 at 16:08
  • \$\begingroup\$ @JonathanFrech There is no space there? \$\endgroup\$
    – Mr. Xcoder
    Commented Sep 20, 2017 at 16:08
  • \$\begingroup\$ @Mr.Xcoder oh yeah I don't know what I was thinking with all those crazy function chainings. Thanks! :D \$\endgroup\$
    – hyperneutrino
    Commented Sep 20, 2017 at 16:24
5
\$\begingroup\$

Ohm v2, 4 bytes

Δ2<Å

Try it online!

How?

Δ2<Å   ~ Full program.

Δ      ~ Absolute deltas.
 2<    ~ Is smaller than 2?
   Å   ~ Check if all elements are truthy.
\$\endgroup\$
5
\$\begingroup\$

C# (.NET Core), 51 45 44 + 18 bytes

-1 byte thanks to Jeppe Stig Nielsen

a=>a.Zip(a.Skip(1),(x,y)=>x-y).All(x=>x*x<4)

Byte count also includes:

using System.Linq;

Try it online!

Explanation:

a =>                      // Take an array of integers as input
    a.Zip(                // Combine each element with corresponding one from:
        a.Skip(1),        //     the input array without first element
        (x, y) => x - y   //     get their difference
    )
    .All(x => x * x < 4)  // Check if all differences are less than 2
                          // (We only care about 0 and 1, and so happens that when they're squared, it works like Abs! Magic!)
\$\endgroup\$
2
  • 3
    \$\begingroup\$ Little improvement: a=>a.Zip(a.Skip(1),(x,y)=>x-y).All(x=>x*x<4), it avoids the negation !. \$\endgroup\$ Commented Sep 20, 2017 at 19:42
  • \$\begingroup\$ @JeppeStigNielsen awesome, thank you! \$\endgroup\$ Commented Sep 20, 2017 at 19:48
5
\$\begingroup\$

Perl 6, 25 bytes

{?(2>all(.[]Z-.skip)>-2)}

Try it online!

This should be pretty readable. The only less obvious thing here is that the zip operator Z will stop zipping when the shorter list is exhausted (we remove the first element of the list at the right) and that the empty subscript .[], so called Zen slice, gives the whole list. .skip returns the list without the first element.

\$\endgroup\$
10
  • \$\begingroup\$ Are those two spaces really necessary? \$\endgroup\$ Commented Sep 20, 2017 at 15:52
  • \$\begingroup\$ @JonathanFrech: The right one probably no. Also I just realized that the .rotate is not needed here. \$\endgroup\$
    – Ramillies
    Commented Sep 20, 2017 at 15:53
  • \$\begingroup\$ Heck, even the left one could be removed. I really don't understand where the whitespace is required and where it is not... \$\endgroup\$
    – Ramillies
    Commented Sep 20, 2017 at 15:54
  • \$\begingroup\$ You could write -2< instead of -1≤ and <2 instead of ≤1 to save four more bytes. \$\endgroup\$
    – Sean
    Commented Sep 20, 2017 at 17:18
  • \$\begingroup\$ Er, I guess you actually have to reverse the comparisons 2>...>-2 to avoid interpreting the < in an erroneous way. \$\endgroup\$
    – Sean
    Commented Sep 20, 2017 at 17:21
5
\$\begingroup\$

R, 30 26 bytes

cat(all(diff(scan())^2<2))

Try it online!

\$\endgroup\$
4
  • 3
    \$\begingroup\$ I think function(a)all(diff(a)^2<2) saves 3 bytes. \$\endgroup\$
    – BLT
    Commented Sep 20, 2017 at 18:34
  • \$\begingroup\$ you could take the input from the console: all(diff(scan())^2<2) \$\endgroup\$
    – flodel
    Commented Sep 21, 2017 at 1:51
  • \$\begingroup\$ @BLT good point! \$\endgroup\$ Commented Sep 21, 2017 at 8:05
  • 1
    \$\begingroup\$ @flodel There was some recent discussion regarding the need to explicitly print the output when using scan, but it still saves a byte! \$\endgroup\$ Commented Sep 21, 2017 at 8:11
4
\$\begingroup\$

PowerShell, 62 bytes

param($a)$l=$a[0];($a|?{$_-$l-in1..-1;$l=$_}).count-eq$a.count

Try it online!

PowerShell doesn't have a .map or .some or similar command, so here we're individually checking each delta.

We take input $a and set $l equal to the first element. Then we loop through $a and take out each element where |?{...} the difference $_-$l is -in the range 1,0,-1. We then set $l equal to the current element. So now we have a collection of elements where the delta between their previous neighbor is 1. We take the .count of that and check whether it's -equal to the .count of the array as a whole. If it is, then every delta is 1 or less, so it's an insignificant array. That Boolean result is left on the pipeline, and output is implicit.

\$\endgroup\$
5
  • \$\begingroup\$ You can save 1 byte by getting rid of the param and doing $l=($a=$args)[0] \$\endgroup\$
    – briantist
    Commented Sep 21, 2017 at 20:49
  • \$\begingroup\$ @briantist That doesn't work, though. For example. This is because it's setting $l to be the whole input array in your suggestion. \$\endgroup\$ Commented Sep 21, 2017 at 20:54
  • \$\begingroup\$ I think it just requires changing the way you give arguments in TIO (each element needs to be specified separately). The way you have it now, the first element of $args is itself the whole array. Example \$\endgroup\$
    – briantist
    Commented Sep 21, 2017 at 20:57
  • \$\begingroup\$ That feels cheaty... \$\endgroup\$ Commented Sep 21, 2017 at 21:06
  • \$\begingroup\$ I think that's actually the correct way to use $args. If you called a script or function with a series of arguments separated as spaces, it would come in as separate elements in $args, and for TIO that's how to emulate that. I've personally used it that way many times before, but to each their own :) \$\endgroup\$
    – briantist
    Commented Sep 21, 2017 at 21:10
4
+250
\$\begingroup\$

Factor, 48 33 bytes

Saved 15 bytes thanks to @chunes!

[ dup rest v- vabs supremum 2 < ]

Try it online! (results are at the bottom)

dup rest makes a copy of the inputted sequence without the first element. v- subtracts that from the original sequence (\$a_n-a_{n-1}\$). Then vabs gets the absolute values of that. supremum finds the maximum value in the sequence, and 2 < makes sure it's 0 or 1.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ vabs is shorter than [ abs ] map. supremum is shorter than 0 [ max ] reduce. \$\endgroup\$
    – chunes
    Commented Mar 26, 2021 at 21:53
  • \$\begingroup\$ @chunes Nice, thanks! \$\endgroup\$
    – user
    Commented Mar 26, 2021 at 23:23
3
\$\begingroup\$

Python 3, 45 bytes

lambda k:all(-2<x-y<2for x,y in zip(k,k[1:]))

Try it online! or Try the test suite.

Thanks to Jonathan Frech for -2 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ abs(x-y)<2 -> -2<x-y<2. \$\endgroup\$ Commented Sep 20, 2017 at 15:46
3
\$\begingroup\$

MATL, 6 5 bytes

d|2<A

-1 byte thanks to Giuseppe

Try it online! or Verify all test-cases

\$\endgroup\$
7
  • \$\begingroup\$ I think per meta consensus you can use d|2< instead, as an array with a zero value is falsey in MATL. \$\endgroup\$
    – Giuseppe
    Commented Sep 20, 2017 at 15:56
  • 1
    \$\begingroup\$ Or d|2<A for something closer to your original answer. \$\endgroup\$
    – Giuseppe
    Commented Sep 20, 2017 at 15:59
  • 1
    \$\begingroup\$ @Giuseppe No they can't: The truthy / falsy values have to be distinct and consistent. \$\endgroup\$
    – Mr. Xcoder
    Commented Sep 20, 2017 at 15:59
  • \$\begingroup\$ @Mr.Xcoder "an array of all 1s for truthy" and "an array containing at least one zero for falsey" isn't distinct and consistent? \$\endgroup\$
    – Giuseppe
    Commented Sep 20, 2017 at 16:01
  • 2
    \$\begingroup\$ @Giuseppe "an array of all 1s for truthy" and "an array containing at least one zero for falsey" isn't distinct and consistent? - No, that is not acceptable, because they are inconsistent. \$\endgroup\$
    – user70974
    Commented Sep 20, 2017 at 16:13
3
\$\begingroup\$

anyfix, 9 bytes

I€A€2<»/&

Try it online!

I€A€2<»/&  Main Link
I          Deltas
 €         For each element
  A        Take its absolute value
   €  »    For each element
    2<     Is it less than two?
       /   Reduce over
        &  Logical AND

This is mostly a port of the 05AB1E solution except terrible because anyfix doesn't have autovectorization and other cool things

\$\endgroup\$
3
\$\begingroup\$

Java (OpenJDK 8), 60 bytes

a->{int r=1,p=a[0];for(int i:a)r|=(r=p-(p=i))*r;return r<2;}

Try it online!

  • 5 bytes thanks to @Nevay!
\$\endgroup\$
3
  • 1
    \$\begingroup\$ You can use r in the loop to calculate (p-n) only once, >>1 can be /2, or removed if you use | instead of +: a->{int r=1,p=a[0];for(int i:a)r|=(r=p-(p=i))*r;return r<2;} (60 bytes). \$\endgroup\$
    – Nevay
    Commented Sep 20, 2017 at 20:12
  • \$\begingroup\$ Cheers @Nevay, thank you! Perfect golfing, as usual ;-) \$\endgroup\$ Commented Sep 20, 2017 at 20:29
  • \$\begingroup\$ can you explain me how does it work? thank you! \$\endgroup\$
    – blurstream
    Commented Sep 22, 2017 at 9:01
3
\$\begingroup\$

C, 61 56 bytes

Thanks to @scottinet for saving five bytes!

r;f(a,n)int*a;{for(r=1;--n;r=(*a-*++a)/2?0:r);return r;}

Try it online!

C (gcc), 47 bytes

r;f(a,n)int*a;{for(r=1;--n;r=(*a-*++a)/2?0:r);}

Try it online!

\$\endgroup\$
8
  • \$\begingroup\$ And if it is allowed / if you feel like it, you may save 9 more bytes by storing the result in r instead of returning it. :-) \$\endgroup\$
    – scottinet
    Commented Sep 20, 2017 at 20:05
  • 1
    \$\begingroup\$ @scottinet I considered that, but it's not valid C even though it happens to work with gcc. It's allowed, though, so I guess I'll just include it as an alternate version. \$\endgroup\$
    – Steadybox
    Commented Sep 20, 2017 at 20:08
  • 2
    \$\begingroup\$ @scottinet Assigning a variable at the end of a function puts that value in the function's return adress, making it feel like it is returning the value. However, this behaviour is not part of the C specifications, thereby not guarenteed to work. It can also break with certain optimizing compiler flags. \$\endgroup\$ Commented Sep 20, 2017 at 20:25
  • 2
    \$\begingroup\$ @scottinet Ah, I am sorry. I think that would not be allowed as you cannot simply assign variables in your solution per agreed upon rule. As an example, using globally defined variables instead of function arguments would not be allowed either. Your task is to write a fully functional program / function. \$\endgroup\$ Commented Sep 20, 2017 at 20:33
  • 1
    \$\begingroup\$ @JonathanFrech languages are defined by their implementation here, so if you have a compiler which produces consistent results then the answer is valid, even if formally UB. \$\endgroup\$
    – Quentin
    Commented Sep 21, 2017 at 11:19
3
\$\begingroup\$

Ruby, 36 35 33 bytes

->b,*a{a.all?{|x|(b-(b=x))**2<2}}

Takes the input array as individual arguments.

-1 byte thanks to MegaTom, -2 bytes thanks to Jordan.

Try it online!

\$\endgroup\$
6
  • 2
    \$\begingroup\$ ->a{b,=a;a.all?{|x|(b-(b=x))**2<2}} is 35 bytes. \$\endgroup\$
    – MegaTom
    Commented Sep 21, 2017 at 18:55
  • \$\begingroup\$ @MegaTom right you are! \$\endgroup\$
    – Snack
    Commented Sep 21, 2017 at 18:59
  • 1
    \$\begingroup\$ ->b,*a{a.all?{|x|(b-(b=x))**2<2}} is 33 bytes. \$\endgroup\$
    – Jordan
    Commented Nov 1, 2017 at 20:27
  • \$\begingroup\$ @Jordan Not sure if that works - how are you passing the array into it? Passing the array like in the TIO just gives true for all test cases. \$\endgroup\$
    – Snack
    Commented Nov 1, 2017 at 22:29
  • \$\begingroup\$ No array, just pass the input as individual arguments. \$\endgroup\$
    – Jordan
    Commented Nov 1, 2017 at 22:35
3
\$\begingroup\$

Julia 0.6, 21 bytes

~x=all(diff(x).^2.<2)

Try it online!

-1 byte thanks to MarcMush: pass a single argument to all

\$\endgroup\$
2
  • 1
    \$\begingroup\$ you can add the missing functionnality yourself to mimic later behaviour (import Base: <; <(x) = i->i<x) \$\endgroup\$
    – MarcMush
    Commented Feb 13, 2023 at 23:01
  • 1
    \$\begingroup\$ -1 byte (and works in julia 1.0) ~x=all(diff(x).^2 .<2) \$\endgroup\$
    – MarcMush
    Commented Feb 13, 2023 at 23:02
2
\$\begingroup\$

Java (OpenJDK 8), 78 bytes

a->{int p=0,i=1;for(;i<a.length;p+=Math.abs(a[i]-a[i++-1])>1?1:0);return p<1;}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 37 36 bytes

(a,u)=>!a.some(e=>(e-=(u=e))>1|e<-1)

Edit: Saved 1 byte by stealing @Arnauld's trick.

\$\endgroup\$
2
  • \$\begingroup\$ You could use currying: a=>u=>!a.some(e=>(e-=(u=e))>1|e<-1) \$\endgroup\$
    – Bálint
    Commented Sep 24, 2017 at 10:30
  • \$\begingroup\$ @Bálint Sorry for the late response; I don't normally comment on "use currying" comments, but I will here because I'm not sure that's legal here since u is a temporary, not a parameter. (I can't use a global as it needs to start out as undefined and a global would not be reusable.) I guess I could apply the golf that was since applied to his answer of using a instead of u though... \$\endgroup\$
    – Neil
    Commented Nov 1, 2022 at 8:34
2
\$\begingroup\$

Pyth, 7 bytes

._I#I.+

Test Suite

Returns true/false.

Explanation:

     .+ Deltas, returns differences between consecutive values.
._      Signum, returns the sign of a number (1, 0, or -1).  Note that this should
             be equal to the input for insignificant arrays.
  I     Tests if it is equal to the input...
   #    For each in the input, and filter out those that aren't...
    I   And make sure none have been filtered out.
\$\endgroup\$
2
\$\begingroup\$

Mathematica, 34 bytes

Differences@#~MatchQ~{(1|0|-1)..}&

Explanation

                                 & (* Function *)
Differences                        (* which takes the consecutive differences*)
           @#                      (* of the input list *)
             ~MatchQ~              (* and returns whether it matches *)
                     {(1|0|-1)..}  (* a list consisting of one or more 1s, 0s, or -1s *)
\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.