Skip to main content
added 526 characters in body
Source Link
Danis
  • 783
  • 6
  • 14

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

n%2**31 - since in python integers are infinite, have to change negative numbers. for example -4 becomes 2147483644

bin(...) - translate to binary format

count("1") - count the number of units


Python 3, 50 bytes

lambda n:n and n%2+z(n//b)
f=lambda l:max(l,key=z)

Try it online!

two bytes shorter, but doesn't work with negative numbers

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

n%2**31 - since in python integers are infinite, have to change negative numbers. for example -4 becomes 2147483644

bin(...) - translate to binary format

count("1") - count the number of units

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

n%2**31 - since in python integers are infinite, have to change negative numbers. for example -4 becomes 2147483644

bin(...) - translate to binary format

count("1") - count the number of units


Python 3, 50 bytes

lambda n:n and n%2+z(n//b)
f=lambda l:max(l,key=z)

Try it online!

two bytes shorter, but doesn't work with negative numbers

added 208 characters in body
Source Link
Danis
  • 783
  • 6
  • 14

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

n%2**31 - since in python integers are infinite, have to change negative numbers. for example -4 becomes 2147483644

bin(...) - translate to binary format

count("1") - count the number of units

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

n%2**31 - since in python integers are infinite, have to change negative numbers. for example -4 becomes 2147483644

bin(...) - translate to binary format

count("1") - count the number of units

added 58 characters in body
Source Link
Danis
  • 783
  • 6
  • 14

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**32n%2**31).count("1"))

Try it online!Try it online!

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**32).count("1"))

Try it online!

Python 3, 52 bytes

lambda l:max(l,key=lambda n:bin(n%2**31).count("1"))

Try it online!

Source Link
Danis
  • 783
  • 6
  • 14
Loading