[Question]
  [
You are playing a famous game called \$1\text{D Array BattleGround}\$. In the game, the player can be stationed in any position from \$0\$ to \$10^5\$.
You are a *Paratrooper* in the game and have the ability to do *two types of operation* \$-\$
* ***Advance***, which would **multiply** your position by \$2\$
* ***Fall-back***, which would **decrease** your current position by \$1\$
Each type of operation requires \$1\$ second.
You are stationed in \$N\$ and want to go to \$M\$ in the minimum time possible, (\$1≤ N, M ≤10^4\$).
Find out the minimum time you need to ***Get to \$M\$***.
*Note: After each operation, you must remain in the zone from \$0\$ to \$10^5\$.*
### Sample
```
Input : 4 6
Output: 2
Input : 10 1
Output: 9
Input : 1 3
Output: 3
Input : 2 10
Output: 5
Input : 666 6666
Output: 255
Input : 9999 10000
Output: 5000
```
This is a code-golf challenge so code with lowest bytes wins!
  
[Answer]
# JavaScript (ES6), 30 bytes
Takes input as `(N)(M)`.
```
N=>g=M=>M>N?M%2-~g(M+1>>1):N-M
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@9/P1i7d1tfWztfOz95X1Ui3Ll3DV9vQzs5Q08pP1/d/cn5ecX5Oql5OfrpGmoaJpoaZpqYCFOjrKxhxoSowNNDUMISrACqwRFegqWGMYoIxmgIjTZAhSCaYoikwMzPTBBEQh4DcYIquxBIIQMYAAVARyAwg6z8A "JavaScript (Node.js) – Try It Online")
### How?
Instead of going from \$N\$ to \$M\$, we go from \$M\$ to \$N\$.
While \$M\$ is greater than \$N\$:
* if \$M\$ is odd, increment it and divide it by \$2\$ (2 operations)
* if \$M\$ is even, just divide it by \$2\$ (1 operation)
When \$M\$ is less than or equal to \$N\$, the remaining number of operations is \$N-M\$.
*Example for \$N=666\$, \$M=6666\$:*
```
  M   | transformation     | operations | total
------+--------------------+------------+-------
 6666 | M / 2       = 3333 |      1     |   1
 3333 | (M + 1) / 2 = 1667 |      2     |   3
 1667 | (M + 1) / 2 = 834  |      2     |   5
 834  | M / 2       = 417  |      1     |   6
 417  | M + 249     = 666  |     249    |  255
```
With inverse operations in reverse order, this gives:
$$((((666-249)\times 2)\times 2-1)\times 2-1)\times 2=6666$$
The idea behind that is that it's always cheaper to process the greatest number of *fall-back* operations at the beginning of the process (i.e. when \$N\$ is still small) rather than exceeding \$M\$ by too large a margin with hasty *advance* operations and doing *fall-backs* afterwards.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~53~~ 34 bytes
Saved a whopping 19 bytes thanks to the man himself [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)!!!
```
f(N,M){M=M>N?M%2-~f(N,-~M/2):N-M;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9Nw0/HV7Pa19bXzs/eV9VItw4kolvnq2@kaeWn62td@z83MTNPQ1OhmqugKDOvJE1DSTUlJk9JJ03DRMdMU9NaAQr0tRSMFLT0MVQZGugYIpQBVVliVaVjjGqWMTZVRjqGBihmmWJTZWZmpgPEUMeB3GWKVZ0lEAANBAKQSpBpQCZIYe1/AA "C (gcc) – Try It Online")
A port of [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s [JavaScript answer](https://codegolf.stackexchange.com/a/206236/9481).
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 24 bytes [SBCS](https://en.wikipedia.org/wiki/SBCS)
Recursive dfn as per [Arnauld's answer](https://codegolf.stackexchange.com/a/206236/75323).
```
{⍵≤⍺:⍺-⍵⋄(2|⍵)+1+⍺∇⌈⍵÷2}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pR79ZHnUse9e6yAmJdEK@7RcOoBsjQ1DbUBoo96mh/1NMB5B/eblT7P03hUdsEhUe9fY@6mg0ftU1@1De1uCgZSJZkZBb/N1FIUzDjMjQAUoZchkDSmMsIxDbgMjMzA8kBAZclEIAFgQAA "APL (Dyalog Unicode) – Try It Online") We take Arnauld's approach but we use APL's nice builtins to make a single recursive call instead of having to choose the recursive call that we want to make (which would depend on the parity of M):
```
{⍵≤⍺:⍺-⍵⋄(2|⍵)+1+⍺∇⌈⍵÷2} ⍝ dfn taking N on the left and M on the right
{⍵≤⍺:                    } ⍝ if N is less than or equal to M
      ⍺-⍵                  ⍝ just return N - M
          ⋄                 ⍝ otherwise
                   ⍺∇⌈⍵÷2  ⍝ divide M by 2, round up and call this function recursively
                 1+         ⍝ to which we add 1 unconditionally
          (2|⍵)+            ⍝ and to which we add the parity of M, i.e. add one more iff M is odd.
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
←V€⁰¡ṁ§eD←;
```
[Try it online!](https://tio.run/##yygtzv7//1HbhLBHTWseNW44tPDhzsZDy1NdgELW////NzT4bwQA "Husk – Try It Online") Arguments are in reversed order (first target, then initial position).
# Explanation
Brute force turned out shorter than more efficient methods.
```
←V€⁰¡ṁ§eD←;  Inputs: M (stored in ⁰) and N (implicit).
          ;  Wrap in list: [N]
    ¡        Iterate, returning an infinite list:
     ṁ         Map and concatenate:
         ←       Decrement and
        D        double,
      §e         put the results in a two-element list.
 V           1-based index of first list that
  €⁰         Contains M.
←            Decrement.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Took quite a while to find an approach which could be implemented in under 16 bytes.
```
‘:Ḃȯ⁹>$Ɗ?Ƭ2i’
```
A dyadic Link accepting `M` on the left and `N` on the right which yields the time you need to manoeuvre.
**[Try it online!](https://tio.run/##y0rNyan8//9RwwyrhzuaTqx/1LjTTuVYl/2xNUaZjxpm/v//39AACP5bAgEA "Jelly – Try It Online")**
### How?
```
‘:Ḃȯ⁹>$Ɗ?Ƭ2i’ - Link: M, N
          2   - use two as the right argument (R) of:
         Ƭ    -   collect up, starting at M, while results are distinct:
        ?     -     if...
       Ɗ      -     ...condition: last three links as a monad - i.e. f(current_value):
  Ḃ           -       LSB (i.e. is current_value odd?)
      $       -       last two links as a monad:
     ⁹        -         chain's right argument, N
    >         -         greater than? (i.e. is current_value less than N?)
   ȯ          -       logical OR (i.e. is current_value either odd or less than N?)
‘             -     ...then: increment
 :            -     ...else: integer divide by R (2)
          i  - 1-based index of first occurrence of N in that
           ’ - decrement
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~15~~ 14 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Heading tag now includes the completely unnecessary space SE are forcing on us for no good reason
Well, seeing as everyone else is taking Arnauld's approach ...! Be sure to `+1` him if you're `+1`ing this.
Takes input in reverse order.
```
>V?¢ÌÒß°Uz:UnV
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=PlY/oszS37BVejpVblY&input=NjY2Ngo2NjY)
```
>V?¢ÌÒß°Uz:UnV     :Implicit input of integers U=M and V=N
>V                 :Is U greater than V
  ?                :If so
   ¢               :  Convert U to base-2 string
    Ì              :  Get last character
     Ò             :  Subtract the bitwise negation of
      ß            :  A recursive run of the programme with argument U (V remains unchanged)
       °U          :    Increment U
         z         :    Floor divide by 2
          :        :Else
           UnV     :  U subtracted from V
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 18 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
[ÐÆd#`DÉD½+;‚¼}Æ¾+
```
Inspired by [*@Arnauld*'s JavaScript answer](https://codegolf.stackexchange.com/a/206236/52210), so make sure to upvote him!
[Try it online](https://tio.run/##yy9OTMpM/f8/@vCEw20pygkuhztdDu3Vtn7UMOvQntrDbYf2aQMljXQMDWIB) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/6MMTDrelKCe4HO50ObRX2/pRw6xDe2oPtx3ap/3/8HodvUNb/0dHm@iYxepEGxroGIIoHWMgaaRjaACkzMzMdIAYJG0JBEBBIIiNBQA).
**Explanation:**
```
[         # Start an infinite loop:
 Ð        #  Triplicate the pair at the top
          #  (which will use the implicit input in the first iteration)
  Æ       #  Reduce it by subtracting (N-M)
   d      #  If this is non-negative (>=0):
    #     #   Stop the infinite loop
  `       #  Pop and push both values separated to the stack
   D      #  Duplicate the top value `M`
    É     #  Check if it's odd (1 if odd; 0 if even)
      ½   #  If it's 1: increase the counter_variable by 1
     D    #  (without popping by duplicating first)
     +    #  Add this 1/0 to `M`
      ;   #  And halve it
       ‚  #  Then pair it back together with the `N`
 ¼        #  At the end of each iteration, increase the counter_variable by 1
}Æ        # After the infinite loop: reduce by subtracting again (N-M)
  ¾+      # And add the counter_variable to this
          # (after which the result is output implicitly)
```
[Answer]
# perl -alp, 62 bytes
```
$;=pop@F;{$_<$;||last;$"+=1+$;%2;$;+=$;%2;$;/=2;redo}$_+=$"-$;
```
[Try it online!](https://tio.run/##LYjBCsIwEAXv@YolrKdQzEZdKM@AJ3@jFOxBCCa0vdn@emMODgwMU6Y53SpbiuRRGbHk8njiy8OdsW1pXFawdVEc4xTAcPEf5xgwT6@889Ce7Ri1XkmNeBIjdDGBxBtVpaaavtFG48hlfefPUrs0lh8 "Perl 5 – Try It Online")
This uses the same logic as most other solutions.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
Ｎθ⊞υＮＷ¬№υθ≔⁺⊖υ⊗υυＩ⊖Ｌ↨Ｌυ²
```
[Try it online!](https://tio.run/##VYzBCsIwEETvfkWOu1BBvUlP2l4EKf2FNC5NIE3aJKufHxNB0DnNPGZGaRmUlzbnm1s5DbxMFGDDdjdy1MCN@OVY@EsbSwIGn6Dz7FLtbIgoLjGa2cFoOUJPKtBCLtEDGBvRe57sx5fA9T2YMu1kTH/dO7k5abjKSF9f5yesanM@HsQ575/2DQ "Charcoal – Try It Online") Link is to verbose version of code. Takes inputs in the order `M`, `N`. Horribly inefficient breadth-first search, so don't bother putting in large numbers. Explanation:
```
Ｎθ
```
Input `M`.
```
⊞υＮ
```
Push `N` to the predefined empty list.
```
Ｗ¬№υθ
```
Repeat until `M` is present in the list...
```
≔⁺⊖υ⊗υυ
```
... concatenate the decremented list with the doubled list.
```
Ｉ⊖Ｌ↨Ｌυ²
```
Calculate the number of concatenations.
[Answer]
## Batch, 153 bytes
```
@echo off
@set/an=%1,c=0
:l
@if %n%==%2 echo %c%&exit/b
@set/a"c+=1,p=~-%2/n+1,q=p&p-1,r=n*p-%2,n-=1
@if %q%==0 if %r% lss %p% set/an=n*2+2
@goto l
```
Explanation:
```
set /a n=%1, c=0
```
Initialise `n` from the first parameter and clear the loop count.
```
if %n% == %2 echo %c% & exit /b
```
Output the count once the target in the second parameter is reached.
```
set /a " c += 1, p = ~-%2 / n + 1, q = p & p - 1, r = n * p - %2, n -= 1
```
* Increment the loop count
* Calculate the number of advances needed
* Calculate how near to the target advances would get
* Assume that we'll fall back
```
if %q% == 0 if %r% lss %p% set /a n = n * 2 + 2
```
If the advances would get near to the target then undo the fall back and advance instead.
[Answer]
# [bc](https://www.gnu.org/software/bc/manual/html_mono/bc.html), 61 bytes
```
define f(n,m){if(n>=m)return n-m;return 1+m%2+f(n,(m+m%2)/2)}
```
[Try it online!](https://tio.run/##LYoxCoAwEAR7X3GNkCMRTZSAiD5GTcDiUgStxLfHO3GanWV33UrZQzxSgKiSIbwPzmUmzOG8coLU0PSr1VQ7LTdFotg6fEpUgwGPVVS2M2A/MdBLOu6diPeeP4yUkZGBwaq8 "bc – Try It Online")
Given `n`, and `m`, return `n - m` if `n` is greater than or equal to `m`. Else, it returns `1` plus `1` (if `m` is odd), plus the result of (`n`, `m / 2`), with the division rounded upwards. The latter is done with a recursive call.
[Answer]
# Befunge-98, 75 bytes
The program keeps a running total of moves at `(0, 0)` and remembers `N` at `(1, 0)`. It definitely could be golfed some more.
```
p&01p&>:01g-0\`|>:2%|
2/1  v  >0g+.@ >^   >
1+2/2v  ^0-\g10<    >
0+g00<^p0
```
[Try it online!](https://tio.run/##JcixCoMwFIXhPU9xFl1CzLkZQity6YNIKAV7t5KlTr57jLj8/Hyf7fv/2Raej9Z2p3Wk1FFnigWu70PnNBwOKQqwA0rz0wta0N9BfIqpc2FYTbjgZnojl1LZWs4Z@coJ) Edit: I had to add some extra arrows for it to run on TIO for some reason. See comments.
I used the logic from [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s [JavaScript answer](https://codegolf.stackexchange.com/a/206236/9481).
[Answer]
# [Erlang (escript)](http://erlang.org/doc/man/escript.html), 65 bytes
Port of Arnauld's answer.
```
f(X,Y)->if X>Y->X-Y;true->1+(Y rem 2)+f(X,(Y+(Y rem 2))div 2)end.
```
[Try it online!](https://tio.run/##RYpBCgIxDEX3c4ouE2YyoIsuFHKOZiWDk0rAqRI7evxaV354PHh89ftSbqSvq9uztqFlSJMgseWQWIgTybn6rsSHESS4buGI4@8F8g@42rtLyzq3bbECFwzEQ@izx@njVhUyxBinTkSc2xc "Erlang (escript) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 22 bytes
A port of [RGS' APL answer](https://codegolf.stackexchange.com/a/206244/95594) with J's hooks and forks.
```
-`(($:>.@-:)+1+2|])@.<
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/dRM0NFSs7PQcdK00tQ21jWpiNR30bP5r/jdRSFMw4zI0AFKGXIZA0pjLCMQ24DIzMwPJAQGXJRCABYEAAA "J – Try It Online")
]