12
Given two positive integers A and B, return the position p that minimises the number of prime factors (counting multiplicities) of the resulting integer, when B is inserted in A at p.
For example, given A = 1234 and B = 32, these are the possible insertions (with p being 0-indexed) and the corresponding information about their prime factors:
p | Result | Prime factors | Ω(N) / Count 0 | 321234 | [2, 3, 37, 1447] | 4 1 | 132234 | [2, 3, 22039] | 3 2 | 123234 | [2, 3, 19, 23, 47] | 5 3 | 123324 | [2, 2, 3, 43, 239] | 5 4 | 123432 | [2, 2, 2, 3, 37, 139] | 6
You can see that the result has a minimal number of prime factors, 3, when p is 1. So in this particular case, you should output 1.
Specs
If there are multiple positions p that minimise the result, you can choose to output all of them or any one of them.
You may choose 0-indexing or 1-indexing for p, but this choice must be consistent.
A and B can be taken as integers, strings or lists of digits.
You can compete in any programming language and can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (scored in bytes) wins!
Test cases
A, B -> p (0-indexed) / p (1-indexed) 1234, 32 -> 1 / 2 3456, 3 -> 4 / 5 378, 1824 -> 0 / 1 1824, 378 -> 4 / 5 67, 267 -> Any or all among: [1, 2] / [2, 3] 435, 1 -> Any or all among: [1, 2, 3] / [2, 3, 4] 378100, 1878980901 -> Any or all among: [5, 6] / [6, 7]
For convenience, here is a list of tuples representing each pair of inputs:
[(1234, 32), (3456, 3), (378, 1824), (1824, 378), (67, 267), (435, 1), (378100, 1878980901)]
1I get the feeling this is biased towards 05AB1E... – caird coinheringaahing – 2018-01-10T17:25:38.577
1Can we output the resulting number that has minimized prime factors instead of the index of the insertion? e.g. in your first test case
132234
instead of1
. – dylnan – 2018-01-10T17:43:02.1872@dylnan I am going to say no this time. – Mr. Xcoder – 2018-01-10T17:43:44.157