[Question]
  [
## Introduction
You're making a robot that can navigate a set of books of varying heights. It can climb books and jump off books, but if the distance is too big it will stop to prevent damage. To figure out the ideal design, you're writing a simulator.
Your program will take as input a list of numbers, representing the heights of the books in the bookshelf, as well as a number indicating the durability of the robot. Starting from the first item of the list, your robot will traverse the bookshelf. If the robot comes across a change in height, it will only be able to continue if the change is less than or equal to the robot's durability. Your job is to output which book the robot is on when it stops, starting from either 0 or 1. You may safely assume that the height of the first book the robot is on will be equal to or less than the robot's durability.
## Scoring
This is code-golf, so shortest answer wins.
## Examples (starting from 1)
```
[1, 1, 1], 1 -> 3
[0, 1, 0], 0 -> 1
[1, 2, 3, 2], 1 -> 4
[1, 3, 4, 4, 0], 2 -> 4
[1, 3, 4, 4, 0, 1], 2 -> 4
```
  
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
```
dÔí°If[Abs[#2-#]>d,0,1+#0@##2,0]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P@X9pIWeadGOScXRyka6yrF2KToGOobaygYOyspGOgaxav8DSzNTSxwCijLzSqKrlZVrde3SgEpjHRyUY9UcHByquaqrDXWAsBaEwBwjEMsAzjHWMULIGeuYAKEBiG9Uy1X7HwA "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input `[durability][heights...]`. Returns 0-indexed.
```
If[Abs[#2-#]>d             ]    is the next height difference out of limits?
              ,0                  yes: 0
                ,1+#0@##2         no : recurse on tail and add 1
                         ,0       err: 0 (input len <2)
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/) / MATLAB, ~~37~~ 35 bytes
*2 bytes saved thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe)!*
```
@(x,d)sum(cumprod(abs(diff(x))<=d))
```
Output is 0-based.
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0InRbO4NFcjuTS3oCg/RSMxqVgjJTMtTaNCU9PGNkVT83@aRrShjgIIxQKxJheEbwThGyDxjYEkshIg3wSMDICiRpr/AQ)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
¬Ø»ß<1JTh
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCr8inPDFKVGgiLCIiLCJbMSwgMiwgMywgMV1cbjUiXQ==)
```
¬Ø»ß      # Get absolute differences
  <     # Find all less than the input
   1J   # Append a 1
      h # Get the first...
     T  # Index of a 1
```
[Answer]
# JavaScript (ES7), 41 bytes
*-6 thanks to @emanresu A*
```
d=>f=([a,...x])=>(a-x[0])**2<=d*d&&-~f(x)
```
# JavaScript (ES7), 42 bytes
```
d=>f=([a,...x])=>(a-x[0])**2<=d*d?f(x)+1:1
```
Recursive solution. Takes input via currying, robot durability first.
Relies on `NaN <= x` always being false, saving a check to see if `x` is long enough.
[Answer]
# [Emojicode](http://www.emojicode.org/), 272 bytes
```
üèÅüçáüíØüÜïüî°üëÇüèº‚ùóÔ∏è‚ùóÔ∏è‚û°Ô∏èdüé∂üÜïüî°üëÇüèº‚ùóÔ∏è‚ùóÔ∏è‚û°Ô∏èl l‚û°Ô∏èüñçüÜïa 0‚û°Ô∏èüñçüÜïcüê®a 0‚ùóÔ∏èüîÇv aüçá‚Ü™Ô∏èüç∫üíØv‚ùóÔ∏è‚ûñüç∫üíØüêΩl c‚ùóÔ∏è‚ùóÔ∏è‚ñ∂üôåüç∫düçáüö™üêáüíªc‚ùóÔ∏èüçâc‚¨ÖÔ∏è‚ûï1üçâüö™üêáüíªc‚ùóÔ∏èüçâ
```
[Try it online!](https://tio.run/##S83Nz8pMzk9JNfv//8P8/sYP83vbP8yftP7D/LapH@ZPWfhh/sQmoPieR3Onv9/RDyXnLQSSKR/m920jrCxHIQfC@DB/Wi9IeaKCAapA8of5E1aARMG6gKY1lSkkgtzxqG0VWKB3F8hFZTBTp8FEgPr25igko9g5DeikmT0gFSkQr8xaBVQG8tLuZJgFvZ3Jj9a0gs2aagji4lD1/78hlyEQAAA "Emojicode ‚Äì Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) + `-pa`, 40 bytes
```
//,$\++while!eof&&"@F">=abs+($_=<>)-$'}{
```
[Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiLy8sJFxcKyt3aGlsZSFlb2YmJlwiQEZcIj49YWJzKygkXz08PiktJCd9eyIsImFyZ3MiOiItcGEiLCJpbnB1dCI6IjJcbjFcbjNcbjRcbjRcbjAifQ==)
## Explanation
Thanks to `-pa` the durability is stored in `$_` (although this is quickly overwritten) and `@F`. This then loops `while` STDIN is not `eof` and `"@F"` (interpolates the values in `@F`, just the durability in this case) is greater than the next input (retrieved with `<>` and stored in `$_`) subtracted from the remainder of the previous `m//`atch (which starts out empty, `0` in numeric context). The body of the `while` is matching against nothing, purely to store the previous value in `$'` without having to set manually, and incrementing `$\`, which is automatically output thanks to `-p`. The final `}{` is to break out of the implicit `while (<STDIN>)` from `-p` (well, `-n` which is implied by `-p`) to prevent `$_` being output as well.
[Answer]
# [Python 3](https://docs.python.org/3/), 80 bytes
Returns 0-based index.
```
lambda l,n:next((i for i,(a,b)in enumerate(zip(l,l[1:]))if abs(a-b)>n),len(l)-1)
```
[Try it online!](https://tio.run/##fY@9CsMwDIT3PoVGCRTIT6dA@yJpBpva1KAoIXWg7cu7TrJ0ScVJy3fHoekdH6M2yV9uScxg7waEtVX3iogB/DhDYDRsKSg4XQY3m@jwEyYUlq5qe6LgwdgnmsLSVYnFKQoVFaU1LewgRzvsKoZVfV5iOMHPbLDeYXkEm3wPwxmeN5XZUhP/c@w9NfXt5prmoBF9/gccUfoC "Python 3 ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
5 if we may output 1-indexed and modular (i.e. yield 0 for the rightmost) - remove `;1`
```
IA>;1T·∏¢
```
A dyadic Link accepting a list and an integer that yields the 1-indexed stopping point.
**[Try it online!](https://tio.run/##y0rNyan8/9/T0c7aMOThjkX///@PNtRRMNZRMAEjAx0Fw9j/RgA "Jelly ‚Äì Try It Online")**
### How???
```
IA>;1T·∏¢ - Link: list, B; integer, D
I       - incremental differences of B
 A      - absolute values
  >     - greater than D?
   ;1   - concatenate a one
     T  - truthy 1-indexed indices
      ·∏¢ - head
```
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
(a:b:r)!s|s<abs(a-b)=1
(h:t)!s=1+t!s
x!_=0
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/XyPRKsmqSFOxuKbYJjGpWCNRN0nT1pBLI8OqBChoa6hdoljMVaEYb2vwPzcxM0/BViEln0uhoCgzr0RBRSHaUEcBhGIVFBUMUYWNoMIGGMLGQBKLBqCwCRgZgCSNuBT@w00HYgVdOwVjLrjBQFUgEUMuZDOhyky40IwDyoHFAQ "Haskell ‚Äì Try It Online")
Three definitions of infix `!`
* 1st: guards against big step stopping the robot.
* 2nd: step was fine, continue.
* 3rd: end of list.  
Due to 1 indexing it was possible to save something by reaching end of list instead of ending at a single element e.g. [x]!\_=0
[Answer]
# [Factor](https://factorcode.org/), ~~50~~ 43 bytes
```
[ differences vabs [ >= ] with count-head ]
```
[count-head](https://docs.factorcode.org/content/word-count-head,sequences.extras.html) postdates build 1525, the one TIO uses, so here's a screenshot running this in Factor's REPL:
[![enter image description here](https://i.stack.imgur.com/E9coq.gif)](https://i.stack.imgur.com/E9coq.gif)
## Explanation
Takes input as `durability heights`. 0-indexed. `count-head` is a combinator that applies a quotation to each element of a sequence, counting how many times the quotation returns `t` and stopping once an `f` is encountered.
```
                        ! 2 { 1 3 4 4 0 }
differences             ! 2 { 2 1 0 -4 }
vabs                    ! 2 { 2 1 0 4 }
[ >= ] with count-head  ! 3
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
¬•√Ñ‚Äπ1¬™1k
```
0-based.
[Try it online](https://tio.run/##yy9OTMpM/f//0NLDLY8adhoeWmWY/f9/tKGOsY4JEBroGMZyGQEA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC8f9DSw@3PGrYaXholWH2f53/0dHRhjpAGAtCCiCOEYhlAOcY6xgh5Ix1TIAQKGmEKgBSYBQbCwA).
**Explanation:**
```
¬•        # Get the deltas/forward-differences of the first (implicit) input-list
 √Ñ       # Convert each to its absolute value
  ‚Äπ      # Check for each integer in the list whether the second (implicit)
         # input-integer is smaller than it
   1¬™    # Append a trailing 1
     1k  # Pop the list, and push the (0-based) index of the first 1
         # (which is output implicitly as result)
```
---
Could be 5 bytes if we're allowed to output a modular index, so it'll output `-1` if it's able to travel across all books:
```
¬•√Ñ√ÖŒî‚Äπ
```
[Try it online](https://tio.run/##yy9OTMpM/f//0NLDLYdbz0151LDz//9oQx1jHRMgNNAxjOUyAgA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC6P9DSw@3HG49NyWi@FHDzv@1Ov@jo6MNdYAwFoQUQBwjEMsAzjHWMULIGeuYACFQ0ghVAKTAKDYWAA).
**Explanation:**
```
¬•√Ñ     # Same as above
  √ÖŒî   # Push the first 0-based index which is truthy for
       # (or -1 if none were truthy)
    ‚Äπ  #  Check if the second (implicit) input-integer is smaller than the
       #  current integer
       # (after which the found index is output implicitly as result)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~56~~ ~~51~~ 49 bytes
```
f(a,n,d)int*a;{n=!--n||(*a-*++a)/~d?:1+f(a,n,d);}
```
[Try it online!](https://tio.run/##bZLfToMwFMbv9xRHEhL@lGyM7cIh7sL4FBtZSFsmUctCSSRu@OjioYWOqU05hf6@0/O1hQZHSrsudzIiCHMLUXtZfBbJXRCIy8XxssDz/cydf7HtJvRHWdx2qIT3rBCOC@cZYOsnai7rcJdCAueQQN/b2IClActbEE1BhHHCVoYhWKm@mOADM3yhCk5zD0LDaExeY2zj0a2nRFJrlHOifeoh0sMkAXhz4rTmzCwbak@DhJZC1kBfssrDyOkrr7TS2jfPy31z/4TP2iIw/Y6sITsvK3D6KoVgvMG0RTy8PoAsPnmZO2N9dz5MeGYmBt9Xalctpq/kulFcTm9WadJ4ioENFA/zPyxGLP7gq@fBL3oVyoprNH07VSjKHcuWNsP9F9v@EDbWDod6V6TubUGJi@VOrf@0G8KRmEv4bWYskhKwGQSPfbTlXmARRkASMJfCk0SORdtZ233T/C07yi74@AE "C (gcc) ‚Äì Try It Online")
*Saved 5 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!!!*  
*Saved 2 bytes thanks to [AZTECCO](https://codegolf.stackexchange.com/users/84844/aztecco)!!!*
Inputs a pointer to an array of integers, its length (because pointers in C carry no length info), and the durability of the robot.  
Returns to the number of the book (starting at \$1\$) that the robot stops at.
[Answer]
# [Python 3](https://docs.python.org/3/), 53 bytes
```
s=lambda d,f,*t,p=0:d<abs(f-p)or t==()or-~s(d,*t,p=f)
```
[Try it online!](https://tio.run/##TY3BCsMgEETv/Yq5RYOCTXoKtT8ScjCIGGiNRC9F7K9bk1wCs7u8mYH132hX15cS5Ft9Zq2gmWFtZF6KQT/VHIjhnq4bopSkXv4LRJ8FQ4upgWUai8NIxjvDrqkOZTi4O1lcuK/7Wqn8OCSq29FpuAHw2@IiMU2yGUln8BfS/hitpbmh5Q8 "Python 3 ‚Äì Try It Online")
Input is taken as varargs. Surprisingly the 1-based indexing makes the code shorter, since "or" is a byte shorter than "and".
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 10 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
I am ridiculously out of practice! 0-indexed.
```
√§a pV√Ñ b>V
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=5GEgcFbEIGI%2bVg&input=WzEsMyw0LDQsMF0KMg)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
Output is 0-base
```
LengthWhile[Abs@Differences@#-#2,#<=0&]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2Yb898nNS@9JCM8IzMnNdoxqdjBJTMtLbUoNS85tdhBWVfZSEfZxtZALVbtf0BRZl5JdFp0taGOAgjVAnFsrDUXsrgRRNwAi7gxkMSmBShuAkYGQFkjkOx/AA "Wolfram Language (Mathematica) ‚Äì Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
Ôº©‚åïÔº•Œ∏‚à®‚ÅºŒ∫‚äñÔº¨Œ∏‚ÄπŒ∑‚Üî‚ÅªŒπ¬ßŒ∏‚äïŒ∫¬π
```
[Try it online!](https://tio.run/##RYxNC8IwEET/yh43sIJVb57EDyi06L30EJPFhsatTVLx38eqB4fhHQbemE4HM2if8yU4SbjXMeHJicVaP3AkOAc8jpP2EXuCA5vAd5bEFiuWW@pwVEoRVBwjdgS7axz8lBhrJ1NENy@pFMuvz1Upf7tXvxAUM7c5N01BsCbYfLtsCVZtXjz9Gw "Charcoal ‚Äì Try It Online") Link is to verbose version of code. 0-indexed. Explanation:
```
   Œ∏                    Input list
  Ôº•                     Map over values
      Œ∫                 Current index
     ‚Åº                  Equals
         Œ∏              Input list
        Ôº¨               Length
       ‚äñ                Decremented
    ‚à®                   Logical Or
           Œ∑            Input durability
          ‚Äπ             Is less than
              Œπ         Current value
            ‚Üî‚Åª          Absolute difference with
                Œ∏       Input list
               ¬ß        Indexed by
                  Œ∫     Current index
                 ‚äï      Incremented
 ‚åï                      Find index of
                   ¬π    Literal integer `1`
Ôº©                       Cast to string
                        Implicitly print
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 21 bytes
```
{*&(y<x|-x:1_-':x),1}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6rWUtOotKmo0a2wMozXVbeq0NQxrOXiSos2VABCawXDWG1DMM8IxDNA8IwVjJBkjRVMgNDAWsEITQSkCyQGADZFFyg=)
[Answer]
# [Julia 1.0](http://julialang.org/), 37 bytes
```
h/r=findfirst(abs.(diff([h;Inf])).>r)
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/P0O/yDYtMy8lLbOouEQjMalYTyMlMy1NIzrD2jMvLVZTU8@uSPM/l0NxRn65gr5GtKGOAgjFArGmgq2tgjGKlBFEygAsZYguZQwk4RpNUGSBUiZgZABUYARV8B8A "Julia 1.0 ‚Äì Try It Online")
**35 bytes** porting @LuisMendo's Octave solution: `h/r=sum(cumprod(abs.(diff(h)).<=r))`
[Answer]
# [Python 3](https://docs.python.org/3/), 71 bytes
```
lambda h,d:([abs(h[i+1]-h[i])>d for i in range(len(h)-1)]+[1]).index(1)
```
[Try it online!](https://tio.run/##TY7BCoMwDIbve4rcTLAOqzsJ@iJdD5XWteBqUQ8b4rN31V2EPwlf@AgJ39VOvo7LasLSPuOo3r1WYJluUKh@QStczmWRhqROwzDN4MB5mJV/GRyNR0sFJ5kLLunuvDYf5BQPLx05TIGCMzgiUxGDk6s/lxeuU78qiR9nyrStSDY3AAiz8ysO2WZ32PQORQfb@TxaBpr2jOIP "Python 3 ‚Äì Try It Online")
[Answer]
# APL+WIN, ~~12~~ 14 bytes
Plus 2 bytes to accomodate new example suggested by @chunes
Prompts for heights then durability. Index = 1
```
+/^\1,‚éï‚â•|-2-/‚éï
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tv7Z@XIyhDlDwUefSGl0jXX0g8z9Qhut/GpehAhByGXKBWEZANpcBlGkMxFBxYwUTIDTgMkLmAXUZAQA "APL (Dyalog Classic) ‚Äì Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 58 bytes
```
\d+
$*
,(1*)(1*)(?=,\1(1*))
,$2$3
(1*)(,(?!1\1)1*)*,.*
$#2
```
[Try it online!](https://tio.run/##HYgxDoAwDAP3/AKRoQ0RalLWqh/pggQDCwPi/yFEln22n/O97t1sHAsgASehHO6Nh/wtA6NihXg59UmGZO/EKwHOaiYcguKpTglWVvDl3FzlAw "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. 0-indexed. Takes the durability first followed by the list of heights. Explanation:
```
\d+
$*
```
Convert to unary.
```
,(1*)(1*)(?=,\1(1*))
,$2$3
```
Take the absolute difference between each height and the next (`$2` is for the positive difference, `$3` for the negative). Note that the last height remains in the input.
```
(1*)(,(?!1\1)1*)*,.*
$#2
```
Match the durability and as many differences that don't exceed the durability, then replace everything with the count of those differences. (The comma is necessary to avoid matching the last height.)
[Answer]
# x86-16 machine code, 17 bytes
```
00000000: 33ff 47ac 2a04 7302 f6d8 3ac4 7702 e2f2  3.G.*.s...:.w...
00000010: c3                                       .
```
Listing:
```
33 FF       XOR  DI, DI         ; zero jump counter 
        BOOK_LOOP: 
47          INC  DI             ; increment jump counter 
AC          LODSB               ; AL = current height 
2A 04       SUB  AL, [SI]       ; AL = AL - next height 
73 02       JAE  IS_POS         ; is positive? 
F6 D8       NEG  AL             ; if not, negate to get abs value 
        IS_POS: 
3A C4       CMP  AL, AH         ; over threshold? 
77 02       JA   DONE           ; if so, push the AZ-5 button 
E2 F2       LOOP BOOK_LOOP      ; otherwise, keep plugging 
        DONE: 
C3          RET                 ; return to caller
```
Input list at `[SI]`, length in `CX`, threshold in `AH`. Output stopping index (1 based) in `DI`.
About as vanilla asm as you can get. Any time I tried to get clever it was more bytes...
[Answer]
# [R](https://www.r-project.org/), ~~43~~ 42 bytes
*Edit: -1 byte thanks to pajonk (who anyway found a better approach...)*
```
function(x,y)which(c(abs(diff(x))>y,T))[1]
```
[Try it online!](https://tio.run/##jY7LCoMwFET3fsWFbnIhBV8bC/UruitFfCQkVI2YFM3X20Qp9AmFmVkM5w53XLRRQ1GaolLqelz4ra@NVD2ZqcVJyFqQmpSVJo3knMyIuaUnxHN0eTl0UETBC71hB/sckuANCVckRO8NiYLPlZhC4vJpKP1COSRd5efiv8Dtu59shjTLHn8B8a0WrOUwSSNA9a11wcD3BzCCwagqZcCvaJBdxxpZGtZaDJY7 "R ‚Äì Try It Online")
[Answer]
# [R](https://www.r-project.org/), 41 bytes
```
function(x,y)match(T,c(abs(diff(x))>y,T))
```
[Try it online!](https://tio.run/##jY7NCoMwEITvPsVCL7uQgj@9WKhP4V1ijCRUTTEpNU9vjVLoLxRm5jB8O@w4W2cuFXdVbcz5NLfXQThtBpyYp547obBkAnltsdFtixNR4VlJ9HKHAhMGQRQMO9gXkEVvSLwiMQVvSBJ9rqQMsiWfhg5fqAU5rApz6V/g9t1PNieW54@/AENrlexauGmnwAydX0JC6I/glITR1MZBWLGg@142mjvZeYrmOw "R ‚Äì Try It Online")
Based on [@Dominic van Essen's answer](https://codegolf.stackexchange.com/a/242294/55372), so test harness taken from there.
The idea emerged when golfing Dominic's answer and using `which`: "hmm, we need the first index and I remember that there's a function that returns only the first index (which is annoying in some challenges). Oh, it's `match`!"
[Answer]
# [Desmos](https://www.desmos.com/calculator), 96 50 47 bytes
*- a whopping **46** bytes thanks to [Aiden Chow](https://codegolf.stackexchange.com/users/96039/aiden-chow)  
- 3 bytes thanks to Aiden Chow again*
```
L=l.length
\min(\{(l[2...]-l)^2>aa:[1...L],L\})
```
Probably not the right language, but I had a lot of fun coding this.  
Receives a list `l` and durability `a` as input.  
[Online Version](https://www.desmos.com/calculator/bmnbivkwwd)
]