Skip to main content
-3 bytes
Source Link
oeuf
  • 1.8k
  • 4
  • 18

K (ngn/k), 1010 7 bytes

{#(+/2\x)^0}

Try it online!Try it online!

Straightforward solution.Thanks @coltim for -3 bytes by suggesting me that I can just take the sum instead of the count of 1s

Cast the numberinteger into base 2, remove all the 0s, then return the length of the arraysum.

K (ngn/k), 10 bytes

{#(2\x)^0}

Try it online!

Straightforward solution. Cast the number into base 2, remove all the 0s, then return the length of the array.

K (ngn/k), 10 7 bytes

{+/2\x}

Try it online!

Thanks @coltim for -3 bytes by suggesting me that I can just take the sum instead of the count of 1s

Cast the integer into base 2, then sum.

Source Link
oeuf
  • 1.8k
  • 4
  • 18

K (ngn/k), 10 bytes

{#(2\x)^0}

Try it online!

Straightforward solution. Cast the number into base 2, remove all the 0s, then return the length of the array.