Skip to content
loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

Did it long hand in js. Great puzzle!

const strength = num => {
  let count = 0;
  if (num === 0) {
    return 0;
  }
  while (num % 2 == 0) {
    num = num / 2;
    count++;
  }
  return count;
};

const strongestNumber = interval => {
  const [start, end] = interval;
  let strongest = start;

  for (let i = start; i <= end; i++) {
    if (strength(i) > strength(strongest)) {
      strongest = i;
    }
  }
  return strongest;
};

console.log(strongestNumber([1, 2]));
console.log(strongestNumber([5, 10]));
console.log(strongestNumber([48, 56]));
console.log(strongestNumber([129, 193]));
code of conduct - report abuse