Skip to content

Instantly share code, notes, and snippets.

@sprintr
Created February 18, 2024 20:15
Show Gist options
  • Save sprintr/e48d8bdc4c9bb5831408becbdf6122fc to your computer and use it in GitHub Desktop.
Save sprintr/e48d8bdc4c9bb5831408becbdf6122fc to your computer and use it in GitHub Desktop.

Run with the following bash command

ts-node computeJoinPoint.ts
function getDigitsTotal(x: number): number {
let total = 0;
while (x > 0) {
total += x % 10;
x = Math.floor(x / 10);
}
return total;
}
function computeJoinPoint(s1: number, s2: number): number {
let sum1 = s1,
sum2 = s2;
while (sum1 !== sum2) {
sum1 += getDigitsTotal(sum1);
sum2 += getDigitsTotal(sum2);
}
return sum1;
}
console.log(computeJoinPoint(471, 480));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment