Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erhanyasar/eb7a4e7de44ef1101cd6032468c03f4e to your computer and use it in GitHub Desktop.
Save erhanyasar/eb7a4e7de44ef1101cd6032468c03f4e to your computer and use it in GitHub Desktop.
A function returns depth for a given number under given conditions
/*
The depth of an integer n is defined to be how many multiples of n it is necessary to compute
before all 10 digits have appeared at least once in some multiple.
Example: let see n=42
Multiple value digits comment
42*1 42 2,4
42*2 84 8 4 existed
42*3 126 1,6 2 existed
42*4 168 - all existed
42*5 210 0 2,1 existed
42*6 252 5 2 existed
42*7 294 9 2,4 existed
42*8 336 3 6 existed
42*9 378 7 3,8 existed
Looking at the above table under digits column you can find all the digits from 0 to 9,
Hence it required 9 multiples of 42 to get all the digits. So the depth of 42 is 9.
Write a function named computeDepth which computes the depth of its integer argument.
Only positive numbers greater than zero will be passed as an input.
*/
function computeDepth(x = 42) {
let arrayOfDigits = new Set(),
index = 0;
function checkDigits(num) {
let arrayOfDigitsArr = num.toString().split("");
arrayOfDigitsArr.forEach((element) => arrayOfDigits.add(element));
}
while (Array.from(arrayOfDigits).length < 10) {
checkDigits(x * (index + 1));
index++;
}
return index;
}
console.log(computeDepth());
function computeDepth2(x = 42) {
let arrayOfDigits = new Set(),
index = 0;
while (Array.from(arrayOfDigits).length < 10) {
let arrayOfDigitsArr = (x * (index + 1)).toString().split("");
arrayOfDigitsArr.forEach((element) => arrayOfDigits.add(element));
index++;
}
return index;
}
console.log(computeDepth2());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment