JSFiddle - React, Tailwind, and code Playground
JavaScript
// find matching digit to add to i and get d,
// if there is one that is not equal to i.
function m(d, i) {
o=d-i
if (0<=o && o<=9 && o!=i)
return o;
o+=10;
if (0<=o && o<=9 && o!=i)
return o;
return;
}
// find all possible right-most digit combinations that add
// to n without duplicating anything in a
function p(n,a) {
x=0;
r=[];
d=n%10;
for(i=0;i<10;i++) {
if ((!a || !a.contains(i)) &&
(o=m(d,i)) && (!a || !a.contains(o)) &&
i+o<=n)
r[x++]=[i,o]
}
return r;
}
// find all pairs of numbers adding up to n
// without any duplicate digits
function f(n,a) {
var x=0;
var r=[];
var d=p(n,a)
for(var i=0;i<d.length;i++) {
var s=Math.floor((n-d[i][0]-d[i][1])/10)
if (s>0) {
var t=f(s,d[i].concat(a))
for(var j=0;j<t.length;j++)
r[x++]=[t[j][0]*10+d[i][0],t[j][1]*10+d[i][1]]
} else {
r[x++]=d[i]
}
}
return r;
}
w=function(msg){document.writeln(msg)}
w("<pre>");
z=f(121212);
w("--RESULT--");
w("# of combinations: " + z.length);
for(i=0;i<z.length;i++)w("z[" + i + "]="+z[i]);
w("</pre>");