10
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:
Input:
1 2
. Output:1
. I.e, you could only get2
by doing+1
, so one way.Input:
1 3
. Output:3
. I.e, you could get 3 by either doing+2
or+1+1
, or*3
Input:
1 4
. Output:4
.Input:
2 6
. Output:6
.Input:
2 7
. Output:9
.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 – 2016-06-21T21:11:51.743
4What 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 – 2016-06-21T22:23:02.040
1@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 – 2016-06-22T04:22:23.670@Peter Fair remark, restricted to positive numbers. – nicael – 2016-06-22T06:39:43.900