# Ways to get to the number

Given the input of the first number and the second number (both positive integers, zero exluded), determine in how many ways could you make the second out of the first, using following actions: +1,+2 and *3. Operations are simply applied from left to right.

Examples:

1. Input: 1 2. Output: 1. I.e, you could only get 2 by doing +1, so one way.

2. Input: 1 3. Output: 3. I.e, you could get 3 by either doing +2 or +1+1, or *3

3. Input: 1 4. Output: 4.

4. Input: 2 6. Output: 6.

5. Input: 2 7. Output: 9.

6. Input: 1 10. Output: 84.

In case there're no ways, e.g. 100 100, or 100 80, output is 0.

You could also take input as an array, or string with any convenient separator.

The shortest solution wins.

• It looks like it could be a dupe, sorry if it is - didn't find a similar question. – nicael Jun 21 '16 at 21:11
• What about inputs for which the answer should be infinite? E.g. any input where the first integer is negative, because you can multiply by three and then increment back to the original number and repeat as many times as you want. – Peter Taylor Jun 21 '16 at 22:23
• @Patrick: It does make sense though. Starting from -1 and going to 0, you can apply *3 +2 +1 as many times as you want, then apply +1 to get to 0. – Deusovi Jun 22 '16 at 4:22
• @Peter Fair remark, restricted to positive numbers. – nicael Jun 22 '16 at 6:39

# Pyth - 26 24 bytes

There seems to be a bug in Pyth that's making it take inputs in the wrong order, but it shouldn't matter anyway.

/m.vj;+sdzs^Lc3"+1+2*3"S


(1 10 timed out online, but worked on my computer).

• Timed out, with such small numbers? Huh. – nicael Jun 21 '16 at 21:54
• @nicael yeah, there's only 59K ways that I check for 10, but pyth is slooooooow – Maltysen Jun 21 '16 at 21:56

# Javascript ES6, 45 44 bytes

f=(a,b=B)=>a<(B=b)?f(a+1)+f(a+2)+f(a*3):a==b


Example runs:

f(1,2)  -> 1
f(2,6)  -> 6
f(1 10) -> 84

• Interesting use of default parameters, though admittedly it doesn't save any bytes here. =B and (B=) (b omitted on purpose) is 6 characters and the alternative is passing ,b 3 times to the recursive calls which is also 6 characters. Anyway, good job. – Patrick Roberts Jun 22 '16 at 3:55

# Pyth, 29 bytes

M?>GH0|qGH+sgLGtBtH?%H3ZgG/H3


Try it online!

Defines a function. Added three bytes in the link to call the function.