Collatz Paths: Forwards and Backwards along the Collatz Conjecture The Collatz conjecture is a very well-known conjecture. Take a positive integer; if it's even, divide by 2, else, multiply by 3 and add 1. Repeat until you reach 1 or something else happens. The conjecture is that this process always reaches 1.

You can also reverse the process. Start at 1, multiply by 2, and to branch to multiply by 3 and add 1 numbers, when you reach an even number that is 1 (mod 3), subtract 1 and divide by 3.

A Collatz path combines the two, trying to get from one number to another with those four operations.

For example, to get to 20 from 1:

1     *2
2     *2
4     *2
8     *2
16    *2
5     (-1)/3
10    *2
20    *2


You can also get to 3 from 10 by subtracting 1 and dividing by 3.

With these tools, you can traverse a Collatz path from one number to another. For example, the path from 20 to 3 is (divide by 2), (subtract 1, divide by 3).

In short, the available operations are:

n * 2       always
n // 2      if n % 2 == 0
n * 3 + 1   if n % 2 == 1
(n-1) // 3  if n % 6 == 4


Note: not all Collatz paths are short. a(7,3) could run 

7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 2, 4, 8, 16, 5, 10, 3


but a shorter path is 

7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 3


The Challenge

Find the length of the shortest Collatz path between any two positive integers, p and q.


Input is any two positive integers less than 2^20 to avoid integer overflow. The input method is left to the discretion of the golfer. The integers may be the same, in which case, the length of the Collatz path is 0.
Output should be one integer, denoting the length of the shortest Collatz path between p and q.


Test Cases

a(2,1)
1

a(4,1)
1         # 4 -&gt; 1

a(3,1)
6         # 3 -&gt; 10 -&gt; 5 -&gt; 16 -&gt; 8 -&gt; 4 -&gt; 1

a(11,12)
11        # 11 -&gt; 34 -&gt; 17 -&gt; 52 -&gt; 26 -&gt; 13
          # -&gt; 40 -&gt; 20 -&gt; 10 -&gt; 3 -&gt; 6 -&gt; 12

a(15,9)
20        # 46 -&gt; 23 -&gt; 70 -&gt; 35 -&gt; 106 -&gt; 53 -&gt; 160 -&gt; 80 -&gt; 40 -&gt; 13
          # -&gt; 26 -&gt; 52 -&gt; 17 -&gt; 34 -&gt; 11 -&gt; 22 -&gt;  7 -&gt; 14 -&gt; 28 -&gt; 9


Many thanks to orlp for their help in clarifying this challenge.

As always, if the problem is unclear, please let me know. Good luck and good golfing!
Haskell, 170 158 157 146 143 137 135 112 109 108 106 100 99 bytes
a!b=length$fst$break(elem b)$iterate(&gt;&gt;= \n-&gt;2*n:cycle[div n 2,n*3+1]!!n:[div(n-1)3|mod n 6==4])[a]

I did not expect that my original version was so much more golfable, this is also the work of @nimi @Lynn and @Laikoni!
Thanks @Laikoni for a byte, @Lynn for 11 14 20 21 bytes, @nimi for 8 bytes!
This expands the the tree of visited numbers (beginning by a) step by step, and checks in each step whether we arrived at the given number b.