You are provided with a non-empty array \$A\$ of integers, all greater than 0. But what good is an array if the elements do not sum up to the number \$N\$ (also provided as input)...
So to change that, you can pick any integer of your choice present in the array and replace any of its digits with a different digit between 0-9 of your choice. What is the minimum number of digits that you should replace so that the sum of the elements becomes \$N\$?
Note that after replacing the digits, some of the numbers may contain leading zeroes, which is fine. For example: you can change \$123\$ to \$023\$, or even \$000\$ if you want to. However, the input will not contain any leading zeroes and you cannot assume any before the input number.
Example
Consider the array \$A=[195, 95]\$ and \$N = 380\$. You can do the following replacements:
- 195 -> 185
- 185 -> 181
- 181 -> 281
- 95 -> 99
So the new array is \$A=[281,99]\$ with a sum of \$380\$ in 4 steps. However, this is not minimal and you can do it in even fewer steps:
- 195 -> 295
- 95 -> 85
So we got our desired sum in 2 steps. There is no way to get a sum of \$380\$ in less than 2 steps so the answer for \$A=[195, 95]\$ and \$N = 380\$ will be \$2\$.
More examples
A, N -> Answer
[195, 95], 380 -> 2
[100, 201], 0 -> 3
[32, 64], 96 -> 0
[7, 1, 1], 19 -> 2
[100, 37], 207 -> 1
[215], 25 -> 2
[123, 456], 1998 -> 6
Rules
- Standard loopholes are forbidden.
- You do not need to handle inputs for which answer does not exist.
- This is code-golf, so the shortest code, in bytes, wins.