<p>You are given two positive integers <code>x</code> and <code>y</code>.</p>

<p>In one operation, you can do one of the four following operations:</p>

<ol>
	<li>Divide <code>x</code> by <code>11</code> if <code>x</code> is a multiple of <code>11</code>.</li>
	<li>Divide <code>x</code> by <code>5</code> if <code>x</code> is a multiple of <code>5</code>.</li>
	<li>Decrement <code>x</code> by <code>1</code>.</li>
	<li>Increment <code>x</code> by <code>1</code>.</li>
</ol>

<p>Return <em>the <strong>minimum</strong> number of operations required to make </em> <code>x</code> <i>and</i> <code>y</code> equal.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> x = 26, y = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> We can make 26 equal to 1 by applying the following operations: 
1. Decrement x by 1
2. Divide x by 5
3. Divide x by 5
It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> x = 54, y = 2
<strong>Output:</strong> 4
<strong>Explanation:</strong> We can make 54 equal to 2 by applying the following operations: 
1. Increment x by 1
2. Divide x by 11 
3. Divide x by 5
4. Increment x by 1
It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> x = 25, y = 30
<strong>Output:</strong> 5
<strong>Explanation:</strong> We can make 25 equal to 30 by applying the following operations: 
1. Increment x by 1
2. Increment x by 1
3. Increment x by 1
4. Increment x by 1
5. Increment x by 1
It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= x, y &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:
        """
            Dynamic programming approach:
            Calculate N[i] which is the minimum number of steps it takes to get from i to y.
            For 1 <= i <= y. The number of steps will just be y - i
            Then for i > y, We basically have three options, either /5, /3, or -1. 
            So just need to get the minimum of those 3 options.
            
            We stop calculation once i == x
        """
        
        if x <= y:
            return y - x
        
        minimum_steps_from = []

        # calculate N[0] to N[x+10], +10 in case we get better deal by making it divisible by 11
        for i in range(x + 11):
            if i <= y: 
                minimum_steps_from.append(y-i)
            else:
                potential_next_nums = []
                minim_steps = math.inf
                if i % 5 == 0:
                    minim_steps = min(minim_steps, minimum_steps_from[i//5]+1)
                else:
                    steps_to_next_divisible = (5 - (i % 5))
                    minim_steps = min(minim_steps, minimum_steps_from[(i+ steps_to_next_divisible) // 5] + steps_to_next_divisible + 1)
                if i % 11 == 0:
                    minim_steps = min(minim_steps, minimum_steps_from[i//11]+1)
                else:
                    steps_to_next_divisible = (11 - (i % 11))
                    minim_steps = min(minim_steps, minimum_steps_from[(i+ steps_to_next_divisible) // 11] + steps_to_next_divisible + 1)
                potential_next_nums.append(i-1)
                minim_steps = min(minim_steps, minimum_steps_from[i-1]+1)

                minimum_steps_from.append(minim_steps)
        print(minimum_steps_from)

        return minimum_steps_from[x]
17200