Skip to content

Instantly share code, notes, and snippets.

@alexymik
Created January 14, 2016 01:25
Show Gist options
  • Save alexymik/78907acbc86999ad2ffd to your computer and use it in GitHub Desktop.
Save alexymik/78907acbc86999ad2ffd to your computer and use it in GitHub Desktop.
/*
Gur qrpvzny mvc bs gjb aba-artngvir vagrtref N naq O vf na vagrtre P jubfr
qrpvzny ercerfragngvba vf perngrq sebz gur qrpvzny ercerfragngvbaf
bs N naq O nf sbyybjf:
• gur svefg (v.r. gur zbfg fvtavsvpnag) qvtvg bs P vf gur svefg qvtvg bs N;
• gur frpbaq qvtvg bs P vf gur svefg qvtvg bs O;
• gur guveq qvtvg bs P vf gur frpbaq qvtvg bs N;
• gur sbhegu qvtvg bs P vf gur frpbaq qvtvg bs O;
• rgp.
Vs bar bs gur vagrtref N naq O ehaf bhg bs qvtvgf, gur erznvavat qvtvgf bs
gur bgure vagrtre ner nccraqrq gb gur erfhyg.
Gur qrpvzny ercerfragngvba bs 0 vf nffhzrq gb or "0".
Sbe rknzcyr, gur qrpvzny mvc bs 12 naq 56 vf 1526.
Gur qrpvzny mvc bs 56 naq 12 vf 5162.
Gur qrpvzny mvc bs 12345 naq 678 vf 16273845.
Gur qrpvzny mvc bs 123 naq 67890 vf 16273890.
Jevgr n shapgvba: shapgvba fbyhgvba(N, O); gung, tvira gjb aba-artngvir
vagrtref N naq O, ergheaf gurve qrpvzny mvc.
Gur shapgvba fubhyq erghea -1 vs gur erfhyg rkprrqf 100,000,000.
Sbe rknzcyr, tvira N = 12345 naq O = 678 gur shapgvba fubhyq erghea
16273845, nf rkcynvarq nobir.
Nffhzr gung:
• N naq O ner vagrtref jvguva gur enatr [0..100,000,000].
Va lbhe fbyhgvba, sbphf ba pbeerpgarff.
Gur cresbeznapr bs lbhe fbyhgvba jvyy abg or gur sbphf bs gur nffrffzrag.
*/
function solution(A, B) {
var strA = A.toString();
var strB = B.toString();
var output = '';
for (i = 0; i < strA.length || i < strB.length; i++) {
if (strA[i]) {
output = output + strA[i];
}
if (strB[i]) {
output = output + strB[i];
}
}
console.log('The decimal zip of ' + A + ' & ' + B + ' is ' + output);
output_int = parseInt(output);
if (output_int > 100000000) {
return -1
} else {
return(output_int);
}
}
console.log(solution(12, 56) == 1526);
console.log(solution(56, 12) == 5162);
console.log(solution(12345, 678) == 16273845);
console.log(solution(123, 67890) == 16273890);
console.log(solution(123444444444, 67890) == -1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment