Ad
Code
Diff
  • function dividedByThree(int $n): bool
    {
      return base_convert(abs($n), 10, 3)[-1] == 0 && $n;
    }
    
    • function dividedByThree(int $number): bool
    • function dividedByThree(int $n): bool
    • {
    • return $number && !($number % 3);
    • return base_convert(abs($n), 10, 3)[-1] == 0 && $n;
    • }
Fundamentals
Logic
Code
Diff
  • function binaryGap($n) {
      return max(array_map('strlen', explode(1, trim(decbin($n), 0))));
    }
    • function binaryGap($n) {
    • return max(array_map('strlen', explode(1, decbin($n))));
    • return max(array_map('strlen', explode(1, trim(decbin($n), 0))));
    • }
Fundamentals
Logic
Code
Diff
  • function binaryGap($n) {
      return max(array_map('strlen', explode(1, decbin($n))));
    }
    • function binaryGap($n) {
    • return max([...array_map('strlen', explode(1, decbin($n))), 0]);
    • return max(array_map('strlen', explode(1, decbin($n))));
    • }
Fundamentals
Logic
Code
Diff
  • function binaryGap($n) {
      return max([...array_map('strlen', explode(1, decbin($n))), 0]);
    }
    • function binaryGap($n) {
    • preg_match_all('/[0]+/', trim(decbin($n), 0), $_);
    • return $_[0] ? max(array_map('strlen', $_[0])) : 0;
    • return max([...array_map('strlen', explode(1, decbin($n))), 0]);
    • }
Code
Diff
  • digit_sum = x => (x+'').match(/\d/g).reduce((a, e) => a + +e, 0);
    • digit_sum = x => (x+'').split('').reduce((a ,e) => a+ +e||0, 0);
    • digit_sum = x => (x+'').match(/\d/g).reduce((a, e) => a + +e, 0);
Code
Diff
  • digit_sum = x => (x+'').split('').reduce((a ,e) => a+ +e||0, 0);
    • digit_sum = x => String(Math.abs(x)).split('').reduce((a, x) => a + +x, 0);
    • digit_sum = x => (x+'').split('').reduce((a ,e) => a+ +e||0, 0);