Skip to main content
added 36 characters in body
Source Link
Neil A.
  • 2.1k
  • 7
  • 22

C++ (gcc), 124124 113 bytes

-11 bytes thanks to @ceilingcat

#import<string>
std::stringauto a(int n){std::string f;for(int i=30,j,k;++i<127;j=nk;++i<127;f+=i*!j,j=n){k=i;whilefor(kk=i;k;k/=2)j-=k&1,k/=2;f+=i*!j;}return=k&1;return f;}

Try it online!Try it online!

Iterates through the printable character codes, finds those that match the number of 1 bits desired, returns the string containing those characters concatenated.

C++ (gcc), 124 bytes

#import<string>
std::string a(int n){std::string f;for(int i=30,j,k;++i<127;j=n){k=i;while(k)j-=k&1,k/=2;f+=i*!j;}return f;}

Try it online!

Iterates through the printable character codes, finds those that match the number of 1 bits desired, returns the string containing those characters concatenated.

C++ (gcc), 124 113 bytes

-11 bytes thanks to @ceilingcat

#import<string>
auto a(int n){std::string f;for(int i=30,j,k;++i<127;f+=i*!j,j=n)for(k=i;k;k/=2)j-=k&1;return f;}

Try it online!

Iterates through the printable character codes, finds those that match the number of 1 bits desired, returns the string containing those characters concatenated.

Source Link
Neil A.
  • 2.1k
  • 7
  • 22

C++ (gcc), 124 bytes

#import<string>
std::string a(int n){std::string f;for(int i=30,j,k;++i<127;j=n){k=i;while(k)j-=k&1,k/=2;f+=i*!j;}return f;}

Try it online!

Iterates through the printable character codes, finds those that match the number of 1 bits desired, returns the string containing those characters concatenated.