Skip to main content
saved 2 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6),  49 48 47  4745 bytes

Saved 2 bytes thanks to @user81655

a=>a.sort(g=(p,q)=>p*q?g=>!p|-!q||g(p&p-1,q&q-1):!p-!q)[0]

Try it online!Try it online!

How?

We .sort() the input list with a recursive function that, given p and q, clears the least significant bit set in each variable until one of them is equal to 0 (or both of them simultaneously). This allows to order the list from most to least bits set. We then return the first entry, i.e. the "bittiest" one.

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      !p *| -!q ?        //   if both p-> and+1 qif arep = 0:
        g( and q  0,
       //     do a recursive call:
      //    p & por - 1, //   if q = 0,
 clear the least significant bit set|| in p
          q &// q - 1  //or  0 if p  0 clearand theq least significant0, bitin setwhich incase q...
        ) g(           //     end of recursive call
 ... we do a recursive call:              
 //   else:
      p & !p - !q     1, //     return +1 ifclear pthe =least 0significant andbit qset in 0,p
               q & q - 1  //         orclear -1the ifleast psignificant bit 0set andin q = 0
         )            //         or  0 if p =end qof =recursive 0call
  )[0]               // end of sort(); return the first entry

JavaScript (ES6),  49 48  47 bytes

a=>a.sort(g=(p,q)=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!

How?

We .sort() the input list with a recursive function that, given p and q, clears the least significant bit set in each variable until one of them is equal to 0 (or both of them simultaneously). This allows to order the list from most to least bits set. We then return the first entry, i.e. the "bittiest" one.

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p * q ?        //   if both p and q are  0:
        g(           //     do a recursive call:
          p & p - 1, //       clear the least significant bit set in p
          q & q - 1  //       clear the least significant bit set in q
        )            //     end of recursive call
      :              //   else:
        !p - !q      //     return +1 if p = 0 and q  0,
                     //         or -1 if p  0 and q = 0
                     //         or  0 if p = q = 0
  )[0]               // end of sort(); return the first entry

JavaScript (ES6),  49 48 47  45 bytes

Saved 2 bytes thanks to @user81655

a=>a.sort(g=(p,q)=>!p|-!q||g(p&p-1,q&q-1))[0]

Try it online!

How?

We .sort() the input list with a recursive function that, given p and q, clears the least significant bit set in each variable until one of them is equal to 0 (or both of them simultaneously). This allows to order the list from most to least bits set. We then return the first entry, i.e. the "bittiest" one.

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      !p | -!q       //     -> +1 if p = 0 and q  0,
                     //     or -1 if q = 0,
      ||             //     or  0 if p  0 and q  0, in which case ...
        g(           //     ... we do a recursive call: 
          p & p - 1, //       clear the least significant bit set in p
          q & q - 1  //       clear the least significant bit set in q
        )            //     end of recursive call
  )[0]               // end of sort(); return the first entry
minor update
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6),  49 48  47 bytes

a=>a.sort(g=(p,q)=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!

How?

We .sort() the input list with a recursive function that, given p and q, clears the least significant bit set in each variable until one of them is equal to 0 (or both of them simultaneously). This allows to order the list from most to least bits set. We then return the first entry, i.e. the "bittiest" one.

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p * q ?        //   if both p and q are ≠ 0:
        g(           //     do a recursive call:
          p & p - 1, //       removeclear the least significant bit set in p
          q & q - 1  //       removeclear the least significant bit set in q
        )            //     end of recursive call
      :              //   else:
        !p - !q      //     return +1 if p = 0 and q ≠ 0,
                     //         or -1 if p ≠ 0 and q = 0
                     //         or  0 if p = q = 0
  )[0]               // end of sort(); return the first entry

JavaScript (ES6),  49 48  47 bytes

a=>a.sort(g=(p,q)=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p * q ?        //   if both p and q are ≠ 0:
        g(           //     do a recursive call:
          p & p - 1, //       remove the least significant bit set in p
          q & q - 1  //       remove the least significant bit set in q
        )            //     end of recursive call
      :              //   else:
        !p - !q      //     return +1 if p = 0 and q ≠ 0,
                     //         or -1 if p ≠ 0 and q = 0
                     //         or  0 if p = q = 0
  )[0]               // end of sort(); return the first entry

JavaScript (ES6),  49 48  47 bytes

a=>a.sort(g=(p,q)=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!

How?

We .sort() the input list with a recursive function that, given p and q, clears the least significant bit set in each variable until one of them is equal to 0 (or both of them simultaneously). This allows to order the list from most to least bits set. We then return the first entry, i.e. the "bittiest" one.

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p * q ?        //   if both p and q are ≠ 0:
        g(           //     do a recursive call:
          p & p - 1, //       clear the least significant bit set in p
          q & q - 1  //       clear the least significant bit set in q
        )            //     end of recursive call
      :              //   else:
        !p - !q      //     return +1 if p = 0 and q ≠ 0,
                     //         or -1 if p ≠ 0 and q = 0
                     //         or  0 if p = q = 0
  )[0]               // end of sort(); return the first entry
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6),  49 48  4847 bytes

a=>a.sort(g=(p,q)=>p|q&&!p-!q+g=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!Try it online!

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p |* q &&?        //   abort if both p and q are 0:
      !p - !qg( +    //   increment the final result// if p = 0 anddo qa recursive 0call:
              p & p - 1, //   decrement it if p  0remove andthe qleast =significant 0
bit set in p
          q & q - 1  //   leave it unchanged if bothremove pthe andleast qsignificant arebit set 0in q
      g(  )            //     end of recursive call:
      :  p & p - 1, //     remove the least// significant bit setelse:
 in p
      !p - !q & q - 1  //     removereturn the+1 leastif significantp bit= set0 inand q ≠ 0,
      )               //   end of recursive call   or -1 if p ≠ 0 and q = 0
                     //   --> g(p, q) eventually returns popcnt(q) -or popcnt( 0 if p) = q = 0
  )[0]               // end of sort(); return the first entry

JavaScript (ES6),  49  48 bytes

a=>a.sort(g=(p,q)=>p|q&&!p-!q+g(p&p-1,q&q-1))[0]

Try it online!

Commented

a =>               // a[] = input list
  a.sort(          // sort a[] ...
    g = (p, q) =>  // ... using the recursive function g:
      p | q &&     //   abort if both p and q are 0
      !p - !q +    //   increment the final result if p = 0 and q  0
                   //   decrement it if p  0 and q = 0
                   //   leave it unchanged if both p and q are  0
      g(           //   recursive call:
        p & p - 1, //     remove the least significant bit set in p
        q & q - 1  //     remove the least significant bit set in q
      )            //   end of recursive call
                   //   --> g(p, q) eventually returns popcnt(q) - popcnt(p)
  )[0]             // end of sort(); return the first entry

JavaScript (ES6),  49 48  47 bytes

a=>a.sort(g=(p,q)=>p*q?g(p&p-1,q&q-1):!p-!q)[0]

Try it online!

Commented

a =>                 // a[] = input list
  a.sort(            // sort a[] ...
    g = (p, q) =>    // ... using the recursive function g:
      p * q ?        //   if both p and q are 0:
        g(           //     do a recursive call:
          p & p - 1, //       remove the least significant bit set in p
          q & q - 1  //       remove the least significant bit set in q
        )            //     end of recursive call
      :              //   else:
        !p - !q      //     return +1 if p = 0 and q ≠ 0,
                     //         or -1 if p ≠ 0 and q = 0
                     //         or  0 if p = q = 0
  )[0]               // end of sort(); return the first entry
minor update
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
added a commented version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading