All ASCII characters with a given bit count Unicorn Meta Zoo #1: Why another podcast? ...
Are these square matrices always diagonalisable?
Raising a bilingual kid. When should we introduce the majority language?
What does the black goddess statue do and what is it?
Can gravitational waves pass through a black hole?
Will I be more secure with my own router behind my ISP's router?
Putting Ant-Man on house arrest
What is /etc/mtab in Linux?
Why did Israel vote against lifting the American embargo on Cuba?
France's Public Holidays' Puzzle
What's parked in Mil Moscow helicopter plant?
When does Bran Stark remember Jamie pushing him?
How did Elite on the NES work?
What *exactly* is electrical current, voltage, and resistance?
What is the purpose of the side handle on a hand ("eggbeater") drill?
Processing ADC conversion result: DMA vs Processor Registers
Marquee sign letters
Where to find documentation for `whois` command options?
What is the definining line between a helicopter and a drone a person can ride in?
Mechanism of the formation of peracetic acid
Simulate round-robin tournament draw
How would you suggest I follow up with coworkers about our deadline that's today?
Page Layouts : 1 column , 2 columns-left , 2 columns-right , 3 column
RIP Packet Format
How to keep bees out of canned beverages?
All ASCII characters with a given bit count
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
The PPCG Site design is on its way - help us make it awesome!
Sandbox for Proposed ChallengesConvert a “mixed-base” string to ASCIIScale up an image!All Aboard the ASCII TrainSum of Modulo SumsCount the characters - bit by bit!Calculate the binary split sum of a wordMap inputted ASCII charactersDiluted Integer SumsCount the lucky tickets within the given rangeCompare four integers, return word based on maximum
$begingroup$
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard ASCII character has a decimal value between 32 and 126 inclusive. These can be converted to their corresponding binary numbers in the range 100000 to 1111110 inclusive. When you sum the bits of these binary numbers you will always end up with an integer between 1 and 6 inclusive.
The Challenge
Given an integer between 1 and 6 inclusive as input, write a program or function which will output in any acceptable format all of the printable standard ASCII characters where the sum of the bits of their binary value is equal to the input integer.
Examples
1 -> ' @'
2 -> '!"$(0ABDHP`'
3 -> '#%&)*,1248CEFIJLQRTXabdhp'
6 -> '?_ow{}~'
The Rules
- Assume the input will always be an integer (or string representation of an integer) between 1 and 6 inclusive.
- You may write a program to display the results or a function to return them.
- Output may be in any reasonable format but must be consistent for all inputs. If you choose to output a quoted string then the same type of quotes must be used for all inputs.
- Standard loopholes prohibited as usual.
- This is code golf so shortest code in each language wins.
Test Cases
A full set of expected results is available here (TIO) (ungolfed Python implementation).
code-golf
$endgroup$
add a comment |
$begingroup$
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard ASCII character has a decimal value between 32 and 126 inclusive. These can be converted to their corresponding binary numbers in the range 100000 to 1111110 inclusive. When you sum the bits of these binary numbers you will always end up with an integer between 1 and 6 inclusive.
The Challenge
Given an integer between 1 and 6 inclusive as input, write a program or function which will output in any acceptable format all of the printable standard ASCII characters where the sum of the bits of their binary value is equal to the input integer.
Examples
1 -> ' @'
2 -> '!"$(0ABDHP`'
3 -> '#%&)*,1248CEFIJLQRTXabdhp'
6 -> '?_ow{}~'
The Rules
- Assume the input will always be an integer (or string representation of an integer) between 1 and 6 inclusive.
- You may write a program to display the results or a function to return them.
- Output may be in any reasonable format but must be consistent for all inputs. If you choose to output a quoted string then the same type of quotes must be used for all inputs.
- Standard loopholes prohibited as usual.
- This is code golf so shortest code in each language wins.
Test Cases
A full set of expected results is available here (TIO) (ungolfed Python implementation).
code-golf
$endgroup$
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.63
vs?
)?
$endgroup$
– Benjamin Urquhart
10 hours ago
1
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
4
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes ('
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.
$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago
add a comment |
$begingroup$
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard ASCII character has a decimal value between 32 and 126 inclusive. These can be converted to their corresponding binary numbers in the range 100000 to 1111110 inclusive. When you sum the bits of these binary numbers you will always end up with an integer between 1 and 6 inclusive.
The Challenge
Given an integer between 1 and 6 inclusive as input, write a program or function which will output in any acceptable format all of the printable standard ASCII characters where the sum of the bits of their binary value is equal to the input integer.
Examples
1 -> ' @'
2 -> '!"$(0ABDHP`'
3 -> '#%&)*,1248CEFIJLQRTXabdhp'
6 -> '?_ow{}~'
The Rules
- Assume the input will always be an integer (or string representation of an integer) between 1 and 6 inclusive.
- You may write a program to display the results or a function to return them.
- Output may be in any reasonable format but must be consistent for all inputs. If you choose to output a quoted string then the same type of quotes must be used for all inputs.
- Standard loopholes prohibited as usual.
- This is code golf so shortest code in each language wins.
Test Cases
A full set of expected results is available here (TIO) (ungolfed Python implementation).
code-golf
$endgroup$
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard ASCII character has a decimal value between 32 and 126 inclusive. These can be converted to their corresponding binary numbers in the range 100000 to 1111110 inclusive. When you sum the bits of these binary numbers you will always end up with an integer between 1 and 6 inclusive.
The Challenge
Given an integer between 1 and 6 inclusive as input, write a program or function which will output in any acceptable format all of the printable standard ASCII characters where the sum of the bits of their binary value is equal to the input integer.
Examples
1 -> ' @'
2 -> '!"$(0ABDHP`'
3 -> '#%&)*,1248CEFIJLQRTXabdhp'
6 -> '?_ow{}~'
The Rules
- Assume the input will always be an integer (or string representation of an integer) between 1 and 6 inclusive.
- You may write a program to display the results or a function to return them.
- Output may be in any reasonable format but must be consistent for all inputs. If you choose to output a quoted string then the same type of quotes must be used for all inputs.
- Standard loopholes prohibited as usual.
- This is code golf so shortest code in each language wins.
Test Cases
A full set of expected results is available here (TIO) (ungolfed Python implementation).
code-golf
code-golf
edited 2 hours ago
Rɪᴋᴇʀ
6,14043069
6,14043069
asked 11 hours ago
ElPedroElPedro
3,6281025
3,6281025
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.63
vs?
)?
$endgroup$
– Benjamin Urquhart
10 hours ago
1
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
4
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes ('
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.
$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago
add a comment |
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.63
vs?
)?
$endgroup$
– Benjamin Urquhart
10 hours ago
1
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
4
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes ('
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.
$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.
63
vs ?
)?$endgroup$
– Benjamin Urquhart
10 hours ago
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.
63
vs ?
)?$endgroup$
– Benjamin Urquhart
10 hours ago
1
1
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
4
4
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes (
'
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes (
'
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago
add a comment |
22 Answers
22
active
oldest
votes
$begingroup$
8088 assembly, IBM PC DOS, 35 34 bytes
Machine code:
be81 00ad 80ec 308a f433 db8a c8d0 e973 0143 75f9 3af3 7504 b40e cd10 403c 7e7e e8c3
Listing:
BE 0081 MOV SI, 081H ; address of DOS PSP command line
AD LODSW ; load space (20H) and value from command line
80 EC 30 SUB AH, '0' ; convert to numeric value
8A F4 MOV DH, AH ; AL = counter, DH = target value
CHR_LOOP:
33 DB XOR BX, BX ; clear bit counter
8A C8 MOV CL, AL ; current char to CL for test
BIT_LOOP:
D0 E9 SHR CL, 1 ; shift LSB to CF
73 01 JNC EBIT_LOOP ; if LSB = 0, don't increment
43 INC BX ; increment '1' bit counter
EBIT_LOOP:
75 F9 JNZ BIT_LOOP ; loop until CL = 0
3A F3 CMP DH, BL ; is current char the target value?
75 04 JNE ECHR_LOOP ; if not, do not display
B4 0E MOV AH, 0EH ; BIOS write char function
CD 10 INT 10H ; write AL to screen
ECHR_LOOP:
40 INC AX ; increment char loop
3C 7E CMP AL, 126 ; is char <= 126?
7E E8 JLE CHR_LOOP ; if so, keep looping
C3 RET ; return to DOS
Standalone PC DOS executable program, input number from command line. Output is displayed to console window.
Download and test ABCT.COM.
$endgroup$
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
add a comment |
$begingroup$
Jelly, 8 bytes
ØṖOB§=ʋƇ
Try it online!
ØṖ printable ascii character list
OB to binary
§ popcount
= equal to input?
ʋƇ filter (implicitly output)
$endgroup$
add a comment |
$begingroup$
Japt, 9 bytes
;EƶXc¤è1
Try it
;EƶXc¤è1 :Implicit input of integer U
;E :Printable ASCII
Æ :Filter each X
¶ :Test U for equality with
Xc : Character code of X
¤ : To binary string
è1 : Count the 1s
$endgroup$
add a comment |
$begingroup$
05AB1E, 8 bytes
žQʒÇbSOQ
Try it online!
Explanation
žQ # push the printable ascii characters
ʒ # filter, keep elements whose
Ç # character code
b # converted to binary
SO # has a digit sum
Q # equal to the input
$endgroup$
add a comment |
$begingroup$
Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]
Try it online!
$endgroup$
$begingroup$
I was trying to makecount
work but couldn't quite work out how. Respect as always.
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
JavaScript (Node.js), 70 69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]
Try it online!
$endgroup$
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
add a comment |
$begingroup$
Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇
Try it online!
| implicit input, n
₵R | push printable ascii
⟪ ⟫⁇ | filter the list where:
¤cbΣ | the sum of the code point in binary
= | is equal to n
$endgroup$
add a comment |
$begingroup$
Java 8, 131 bytes
Returns a java.util.stream.Stream<String>
n->java.util.stream.IntStream.range(32,127).filter(i->Long.toBinaryString(i).chars().map(c->c-48).sum()==n).mapToObj(c->(char)c+"")
Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>
:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}
Try it online!
$endgroup$
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 24 bytes
⎕ucs a⌿⍨(+⌿2⊤a←32…126)∘=
Try it online!
25 bytes in dzaima/APL:
⎕ucs a⌿⍨(+/¨2⊤¨a←32…126)=
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})
Try it online!
Takes input $n
, constructs a range from 32
to 126
and pulls out those numbers where |?{}
: the number, convert
ed ToString
in base 2
; converted t
oCharArray
; group
ed into 0
s and 1
s; taking the [1]
index of that grouping; taking the .count
thereof, and checking that it's -eq
ual to our input $n
umber. Those numbers are then cast as a char
-array and left on the pipeline. Output is implicit, with newlines between elements.
$endgroup$
add a comment |
$begingroup$
Perl 5 -a
, 50 bytes
map{(sprintf'%b',$_)=~y/1//-$F[0]||say chr}32..126
Try it online!
$endgroup$
$begingroup$
could save one byte using"@F"
instead of$F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
add a comment |
$begingroup$
Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Iθ
Try it online! Link is to verbose version of code. Explanation:
γ Predefined ASCII characters
Φ Filtered by
ι Current character's
℅ ASCII code
↨ Converted to base
² Literal 2
Σ Summed
⁼ Equals
θ First input
I Cast to integer
Implicitly printed
$endgroup$
add a comment |
$begingroup$
PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}
Try it online!
$endgroup$
add a comment |
$begingroup$
Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))
Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl-Shift-Enter to input it. The "2016 or later" is because it needs the CONCAT
function (the deprecated CONCATENATE
won't take an array as argument).
$endgroup$
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 96 bytes
n=>Enumerable.Range(32,95).Where(x=>Convert.ToString(x,2).Count(c=>c==49)==n).Select(x=>(char)x)
Try it online!
$endgroup$
add a comment |
$begingroup$
Brachylog, 7 bytes
∈Ṭ&ạhḃ+
Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
The input variable (which is an element of the output)
∈ is an element of
Ṭ the string containing every printable ASCII character
& and the input
ạh converted to a codepoint
ḃ converted to a list of binary digits
+ sums to
the output variable (which is the input).
$endgroup$
add a comment |
$begingroup$
J, 31 bytes
a.#~&(95{.32}.])]=1#.2#:@i.@^8:
Try it online!
2#:@i.@^8:
produces the binary numbers 0 through 255 (2 ^ 8
is 256)
1#.
sums each one
]=
produces a binary mask showing where the sum equals the original input
a.#~ mask
uses that binary mask to filter J's full ascii alphabeta.
&(95{.32}.])
but before doing so take only elements 32...126 from both the alphabet and the mask
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
Perl 6, 41 bytes
{chrs grep *.base(2).comb.sum==$_,^95+32}
Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183625%2fall-ascii-characters-with-a-given-bit-count%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
22 Answers
22
active
oldest
votes
22 Answers
22
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
8088 assembly, IBM PC DOS, 35 34 bytes
Machine code:
be81 00ad 80ec 308a f433 db8a c8d0 e973 0143 75f9 3af3 7504 b40e cd10 403c 7e7e e8c3
Listing:
BE 0081 MOV SI, 081H ; address of DOS PSP command line
AD LODSW ; load space (20H) and value from command line
80 EC 30 SUB AH, '0' ; convert to numeric value
8A F4 MOV DH, AH ; AL = counter, DH = target value
CHR_LOOP:
33 DB XOR BX, BX ; clear bit counter
8A C8 MOV CL, AL ; current char to CL for test
BIT_LOOP:
D0 E9 SHR CL, 1 ; shift LSB to CF
73 01 JNC EBIT_LOOP ; if LSB = 0, don't increment
43 INC BX ; increment '1' bit counter
EBIT_LOOP:
75 F9 JNZ BIT_LOOP ; loop until CL = 0
3A F3 CMP DH, BL ; is current char the target value?
75 04 JNE ECHR_LOOP ; if not, do not display
B4 0E MOV AH, 0EH ; BIOS write char function
CD 10 INT 10H ; write AL to screen
ECHR_LOOP:
40 INC AX ; increment char loop
3C 7E CMP AL, 126 ; is char <= 126?
7E E8 JLE CHR_LOOP ; if so, keep looping
C3 RET ; return to DOS
Standalone PC DOS executable program, input number from command line. Output is displayed to console window.
Download and test ABCT.COM.
$endgroup$
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
add a comment |
$begingroup$
8088 assembly, IBM PC DOS, 35 34 bytes
Machine code:
be81 00ad 80ec 308a f433 db8a c8d0 e973 0143 75f9 3af3 7504 b40e cd10 403c 7e7e e8c3
Listing:
BE 0081 MOV SI, 081H ; address of DOS PSP command line
AD LODSW ; load space (20H) and value from command line
80 EC 30 SUB AH, '0' ; convert to numeric value
8A F4 MOV DH, AH ; AL = counter, DH = target value
CHR_LOOP:
33 DB XOR BX, BX ; clear bit counter
8A C8 MOV CL, AL ; current char to CL for test
BIT_LOOP:
D0 E9 SHR CL, 1 ; shift LSB to CF
73 01 JNC EBIT_LOOP ; if LSB = 0, don't increment
43 INC BX ; increment '1' bit counter
EBIT_LOOP:
75 F9 JNZ BIT_LOOP ; loop until CL = 0
3A F3 CMP DH, BL ; is current char the target value?
75 04 JNE ECHR_LOOP ; if not, do not display
B4 0E MOV AH, 0EH ; BIOS write char function
CD 10 INT 10H ; write AL to screen
ECHR_LOOP:
40 INC AX ; increment char loop
3C 7E CMP AL, 126 ; is char <= 126?
7E E8 JLE CHR_LOOP ; if so, keep looping
C3 RET ; return to DOS
Standalone PC DOS executable program, input number from command line. Output is displayed to console window.
Download and test ABCT.COM.
$endgroup$
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
add a comment |
$begingroup$
8088 assembly, IBM PC DOS, 35 34 bytes
Machine code:
be81 00ad 80ec 308a f433 db8a c8d0 e973 0143 75f9 3af3 7504 b40e cd10 403c 7e7e e8c3
Listing:
BE 0081 MOV SI, 081H ; address of DOS PSP command line
AD LODSW ; load space (20H) and value from command line
80 EC 30 SUB AH, '0' ; convert to numeric value
8A F4 MOV DH, AH ; AL = counter, DH = target value
CHR_LOOP:
33 DB XOR BX, BX ; clear bit counter
8A C8 MOV CL, AL ; current char to CL for test
BIT_LOOP:
D0 E9 SHR CL, 1 ; shift LSB to CF
73 01 JNC EBIT_LOOP ; if LSB = 0, don't increment
43 INC BX ; increment '1' bit counter
EBIT_LOOP:
75 F9 JNZ BIT_LOOP ; loop until CL = 0
3A F3 CMP DH, BL ; is current char the target value?
75 04 JNE ECHR_LOOP ; if not, do not display
B4 0E MOV AH, 0EH ; BIOS write char function
CD 10 INT 10H ; write AL to screen
ECHR_LOOP:
40 INC AX ; increment char loop
3C 7E CMP AL, 126 ; is char <= 126?
7E E8 JLE CHR_LOOP ; if so, keep looping
C3 RET ; return to DOS
Standalone PC DOS executable program, input number from command line. Output is displayed to console window.
Download and test ABCT.COM.
$endgroup$
8088 assembly, IBM PC DOS, 35 34 bytes
Machine code:
be81 00ad 80ec 308a f433 db8a c8d0 e973 0143 75f9 3af3 7504 b40e cd10 403c 7e7e e8c3
Listing:
BE 0081 MOV SI, 081H ; address of DOS PSP command line
AD LODSW ; load space (20H) and value from command line
80 EC 30 SUB AH, '0' ; convert to numeric value
8A F4 MOV DH, AH ; AL = counter, DH = target value
CHR_LOOP:
33 DB XOR BX, BX ; clear bit counter
8A C8 MOV CL, AL ; current char to CL for test
BIT_LOOP:
D0 E9 SHR CL, 1 ; shift LSB to CF
73 01 JNC EBIT_LOOP ; if LSB = 0, don't increment
43 INC BX ; increment '1' bit counter
EBIT_LOOP:
75 F9 JNZ BIT_LOOP ; loop until CL = 0
3A F3 CMP DH, BL ; is current char the target value?
75 04 JNE ECHR_LOOP ; if not, do not display
B4 0E MOV AH, 0EH ; BIOS write char function
CD 10 INT 10H ; write AL to screen
ECHR_LOOP:
40 INC AX ; increment char loop
3C 7E CMP AL, 126 ; is char <= 126?
7E E8 JLE CHR_LOOP ; if so, keep looping
C3 RET ; return to DOS
Standalone PC DOS executable program, input number from command line. Output is displayed to console window.
Download and test ABCT.COM.
edited 8 hours ago
answered 9 hours ago
gwaughgwaugh
2,5381619
2,5381619
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
add a comment |
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
3
3
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
$begingroup$
For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.
$endgroup$
– Sparr
4 hours ago
add a comment |
$begingroup$
Jelly, 8 bytes
ØṖOB§=ʋƇ
Try it online!
ØṖ printable ascii character list
OB to binary
§ popcount
= equal to input?
ʋƇ filter (implicitly output)
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
ØṖOB§=ʋƇ
Try it online!
ØṖ printable ascii character list
OB to binary
§ popcount
= equal to input?
ʋƇ filter (implicitly output)
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
ØṖOB§=ʋƇ
Try it online!
ØṖ printable ascii character list
OB to binary
§ popcount
= equal to input?
ʋƇ filter (implicitly output)
$endgroup$
Jelly, 8 bytes
ØṖOB§=ʋƇ
Try it online!
ØṖ printable ascii character list
OB to binary
§ popcount
= equal to input?
ʋƇ filter (implicitly output)
answered 10 hours ago
ZylviijZylviij
36014
36014
add a comment |
add a comment |
$begingroup$
Japt, 9 bytes
;EƶXc¤è1
Try it
;EƶXc¤è1 :Implicit input of integer U
;E :Printable ASCII
Æ :Filter each X
¶ :Test U for equality with
Xc : Character code of X
¤ : To binary string
è1 : Count the 1s
$endgroup$
add a comment |
$begingroup$
Japt, 9 bytes
;EƶXc¤è1
Try it
;EƶXc¤è1 :Implicit input of integer U
;E :Printable ASCII
Æ :Filter each X
¶ :Test U for equality with
Xc : Character code of X
¤ : To binary string
è1 : Count the 1s
$endgroup$
add a comment |
$begingroup$
Japt, 9 bytes
;EƶXc¤è1
Try it
;EƶXc¤è1 :Implicit input of integer U
;E :Printable ASCII
Æ :Filter each X
¶ :Test U for equality with
Xc : Character code of X
¤ : To binary string
è1 : Count the 1s
$endgroup$
Japt, 9 bytes
;EƶXc¤è1
Try it
;EƶXc¤è1 :Implicit input of integer U
;E :Printable ASCII
Æ :Filter each X
¶ :Test U for equality with
Xc : Character code of X
¤ : To binary string
è1 : Count the 1s
answered 10 hours ago
ShaggyShaggy
19.2k21768
19.2k21768
add a comment |
add a comment |
$begingroup$
05AB1E, 8 bytes
žQʒÇbSOQ
Try it online!
Explanation
žQ # push the printable ascii characters
ʒ # filter, keep elements whose
Ç # character code
b # converted to binary
SO # has a digit sum
Q # equal to the input
$endgroup$
add a comment |
$begingroup$
05AB1E, 8 bytes
žQʒÇbSOQ
Try it online!
Explanation
žQ # push the printable ascii characters
ʒ # filter, keep elements whose
Ç # character code
b # converted to binary
SO # has a digit sum
Q # equal to the input
$endgroup$
add a comment |
$begingroup$
05AB1E, 8 bytes
žQʒÇbSOQ
Try it online!
Explanation
žQ # push the printable ascii characters
ʒ # filter, keep elements whose
Ç # character code
b # converted to binary
SO # has a digit sum
Q # equal to the input
$endgroup$
05AB1E, 8 bytes
žQʒÇbSOQ
Try it online!
Explanation
žQ # push the printable ascii characters
ʒ # filter, keep elements whose
Ç # character code
b # converted to binary
SO # has a digit sum
Q # equal to the input
answered 10 hours ago
EmignaEmigna
48.3k434147
48.3k434147
add a comment |
add a comment |
$begingroup$
Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]
Try it online!
$endgroup$
$begingroup$
I was trying to makecount
work but couldn't quite work out how. Respect as always.
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]
Try it online!
$endgroup$
$begingroup$
I was trying to makecount
work but couldn't quite work out how. Respect as always.
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]
Try it online!
$endgroup$
Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]
Try it online!
answered 10 hours ago
LynnLynn
51.2k899234
51.2k899234
$begingroup$
I was trying to makecount
work but couldn't quite work out how. Respect as always.
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
I was trying to makecount
work but couldn't quite work out how. Respect as always.
$endgroup$
– ElPedro
6 hours ago
$begingroup$
I was trying to make
count
work but couldn't quite work out how. Respect as always.$endgroup$
– ElPedro
6 hours ago
$begingroup$
I was trying to make
count
work but couldn't quite work out how. Respect as always.$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
JavaScript (Node.js), 70 69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 70 69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 70 69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)
Try it online!
$endgroup$
JavaScript (Node.js), 70 69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)
Try it online!
edited 10 hours ago
answered 10 hours ago
ArnauldArnauld
81.9k798337
81.9k798337
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&
Try it online!
answered 10 hours ago
J42161217J42161217
14.4k21354
14.4k21354
add a comment |
add a comment |
$begingroup$
Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]
Try it online!
$endgroup$
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
add a comment |
$begingroup$
Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]
Try it online!
$endgroup$
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
add a comment |
$begingroup$
Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]
Try it online!
$endgroup$
Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]
Try it online!
answered 10 hours ago
NeilNeil
2,002324
2,002324
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
add a comment |
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
$begingroup$
That's exactly what I got when I golfed my ref implementation. +1
$endgroup$
– ElPedro
10 hours ago
add a comment |
$begingroup$
Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇
Try it online!
| implicit input, n
₵R | push printable ascii
⟪ ⟫⁇ | filter the list where:
¤cbΣ | the sum of the code point in binary
= | is equal to n
$endgroup$
add a comment |
$begingroup$
Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇
Try it online!
| implicit input, n
₵R | push printable ascii
⟪ ⟫⁇ | filter the list where:
¤cbΣ | the sum of the code point in binary
= | is equal to n
$endgroup$
add a comment |
$begingroup$
Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇
Try it online!
| implicit input, n
₵R | push printable ascii
⟪ ⟫⁇ | filter the list where:
¤cbΣ | the sum of the code point in binary
= | is equal to n
$endgroup$
Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇
Try it online!
| implicit input, n
₵R | push printable ascii
⟪ ⟫⁇ | filter the list where:
¤cbΣ | the sum of the code point in binary
= | is equal to n
answered 10 hours ago
GiuseppeGiuseppe
18k31155
18k31155
add a comment |
add a comment |
$begingroup$
Java 8, 131 bytes
Returns a java.util.stream.Stream<String>
n->java.util.stream.IntStream.range(32,127).filter(i->Long.toBinaryString(i).chars().map(c->c-48).sum()==n).mapToObj(c->(char)c+"")
Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>
:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}
Try it online!
$endgroup$
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
add a comment |
$begingroup$
Java 8, 131 bytes
Returns a java.util.stream.Stream<String>
n->java.util.stream.IntStream.range(32,127).filter(i->Long.toBinaryString(i).chars().map(c->c-48).sum()==n).mapToObj(c->(char)c+"")
Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>
:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}
Try it online!
$endgroup$
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
add a comment |
$begingroup$
Java 8, 131 bytes
Returns a java.util.stream.Stream<String>
n->java.util.stream.IntStream.range(32,127).filter(i->Long.toBinaryString(i).chars().map(c->c-48).sum()==n).mapToObj(c->(char)c+"")
Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>
:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}
Try it online!
$endgroup$
Java 8, 131 bytes
Returns a java.util.stream.Stream<String>
n->java.util.stream.IntStream.range(32,127).filter(i->Long.toBinaryString(i).chars().map(c->c-48).sum()==n).mapToObj(c->(char)c+"")
Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>
:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}
Try it online!
edited 10 hours ago
answered 10 hours ago
Benjamin UrquhartBenjamin Urquhart
688111
688111
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
add a comment |
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
$begingroup$
128 bytes
$endgroup$
– Expired Data
6 hours ago
1
1
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
$begingroup$
Static access from non-static context reeeeeee. Thanks.
$endgroup$
– Benjamin Urquhart
6 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 24 bytes
⎕ucs a⌿⍨(+⌿2⊤a←32…126)∘=
Try it online!
25 bytes in dzaima/APL:
⎕ucs a⌿⍨(+/¨2⊤¨a←32…126)=
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL Extended, 24 bytes
⎕ucs a⌿⍨(+⌿2⊤a←32…126)∘=
Try it online!
25 bytes in dzaima/APL:
⎕ucs a⌿⍨(+/¨2⊤¨a←32…126)=
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL Extended, 24 bytes
⎕ucs a⌿⍨(+⌿2⊤a←32…126)∘=
Try it online!
25 bytes in dzaima/APL:
⎕ucs a⌿⍨(+/¨2⊤¨a←32…126)=
Try it online!
$endgroup$
Dyalog APL Extended, 24 bytes
⎕ucs a⌿⍨(+⌿2⊤a←32…126)∘=
Try it online!
25 bytes in dzaima/APL:
⎕ucs a⌿⍨(+/¨2⊤¨a←32…126)=
Try it online!
edited 10 hours ago
answered 10 hours ago
dzaimadzaima
16.1k22060
16.1k22060
add a comment |
add a comment |
$begingroup$
PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})
Try it online!
Takes input $n
, constructs a range from 32
to 126
and pulls out those numbers where |?{}
: the number, convert
ed ToString
in base 2
; converted t
oCharArray
; group
ed into 0
s and 1
s; taking the [1]
index of that grouping; taking the .count
thereof, and checking that it's -eq
ual to our input $n
umber. Those numbers are then cast as a char
-array and left on the pipeline. Output is implicit, with newlines between elements.
$endgroup$
add a comment |
$begingroup$
PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})
Try it online!
Takes input $n
, constructs a range from 32
to 126
and pulls out those numbers where |?{}
: the number, convert
ed ToString
in base 2
; converted t
oCharArray
; group
ed into 0
s and 1
s; taking the [1]
index of that grouping; taking the .count
thereof, and checking that it's -eq
ual to our input $n
umber. Those numbers are then cast as a char
-array and left on the pipeline. Output is implicit, with newlines between elements.
$endgroup$
add a comment |
$begingroup$
PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})
Try it online!
Takes input $n
, constructs a range from 32
to 126
and pulls out those numbers where |?{}
: the number, convert
ed ToString
in base 2
; converted t
oCharArray
; group
ed into 0
s and 1
s; taking the [1]
index of that grouping; taking the .count
thereof, and checking that it's -eq
ual to our input $n
umber. Those numbers are then cast as a char
-array and left on the pipeline. Output is implicit, with newlines between elements.
$endgroup$
PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})
Try it online!
Takes input $n
, constructs a range from 32
to 126
and pulls out those numbers where |?{}
: the number, convert
ed ToString
in base 2
; converted t
oCharArray
; group
ed into 0
s and 1
s; taking the [1]
index of that grouping; taking the .count
thereof, and checking that it's -eq
ual to our input $n
umber. Those numbers are then cast as a char
-array and left on the pipeline. Output is implicit, with newlines between elements.
answered 10 hours ago
AdmBorkBorkAdmBorkBork
28.1k468241
28.1k468241
add a comment |
add a comment |
$begingroup$
Perl 5 -a
, 50 bytes
map{(sprintf'%b',$_)=~y/1//-$F[0]||say chr}32..126
Try it online!
$endgroup$
$begingroup$
could save one byte using"@F"
instead of$F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
add a comment |
$begingroup$
Perl 5 -a
, 50 bytes
map{(sprintf'%b',$_)=~y/1//-$F[0]||say chr}32..126
Try it online!
$endgroup$
$begingroup$
could save one byte using"@F"
instead of$F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
add a comment |
$begingroup$
Perl 5 -a
, 50 bytes
map{(sprintf'%b',$_)=~y/1//-$F[0]||say chr}32..126
Try it online!
$endgroup$
Perl 5 -a
, 50 bytes
map{(sprintf'%b',$_)=~y/1//-$F[0]||say chr}32..126
Try it online!
answered 9 hours ago
XcaliXcali
5,545521
5,545521
$begingroup$
could save one byte using"@F"
instead of$F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
add a comment |
$begingroup$
could save one byte using"@F"
instead of$F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
$begingroup$
could save one byte using
"@F"
instead of $F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
could save one byte using
"@F"
instead of $F[0]
$endgroup$
– Nahuel Fouilleul
30 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
$begingroup$
48 bytes
$endgroup$
– Nahuel Fouilleul
14 mins ago
add a comment |
$begingroup$
Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Iθ
Try it online! Link is to verbose version of code. Explanation:
γ Predefined ASCII characters
Φ Filtered by
ι Current character's
℅ ASCII code
↨ Converted to base
² Literal 2
Σ Summed
⁼ Equals
θ First input
I Cast to integer
Implicitly printed
$endgroup$
add a comment |
$begingroup$
Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Iθ
Try it online! Link is to verbose version of code. Explanation:
γ Predefined ASCII characters
Φ Filtered by
ι Current character's
℅ ASCII code
↨ Converted to base
² Literal 2
Σ Summed
⁼ Equals
θ First input
I Cast to integer
Implicitly printed
$endgroup$
add a comment |
$begingroup$
Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Iθ
Try it online! Link is to verbose version of code. Explanation:
γ Predefined ASCII characters
Φ Filtered by
ι Current character's
℅ ASCII code
↨ Converted to base
² Literal 2
Σ Summed
⁼ Equals
θ First input
I Cast to integer
Implicitly printed
$endgroup$
Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Iθ
Try it online! Link is to verbose version of code. Explanation:
γ Predefined ASCII characters
Φ Filtered by
ι Current character's
℅ ASCII code
↨ Converted to base
² Literal 2
Σ Summed
⁼ Equals
θ First input
I Cast to integer
Implicitly printed
answered 9 hours ago
NeilNeil
83.2k745179
83.2k745179
add a comment |
add a comment |
$begingroup$
PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';
Try it online!
New contributor
$endgroup$
PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';
Try it online!
New contributor
New contributor
answered 8 hours ago
Russ GRuss G
313
313
New contributor
New contributor
add a comment |
add a comment |
$begingroup$
Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}
Try it online!
$endgroup$
Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}
Try it online!
answered 10 hours ago
G BG B
8,3261429
8,3261429
add a comment |
add a comment |
$begingroup$
Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))
Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl-Shift-Enter to input it. The "2016 or later" is because it needs the CONCAT
function (the deprecated CONCATENATE
won't take an array as argument).
$endgroup$
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))
Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl-Shift-Enter to input it. The "2016 or later" is because it needs the CONCAT
function (the deprecated CONCATENATE
won't take an array as argument).
$endgroup$
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))
Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl-Shift-Enter to input it. The "2016 or later" is because it needs the CONCAT
function (the deprecated CONCATENATE
won't take an array as argument).
$endgroup$
Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))
Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl-Shift-Enter to input it. The "2016 or later" is because it needs the CONCAT
function (the deprecated CONCATENATE
won't take an array as argument).
answered 6 hours ago
Sophia LechnerSophia Lechner
86017
86017
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
$begingroup$
I like this. I'm a Lotus Notes and 123 guy so this works for me :-)
$endgroup$
– ElPedro
6 hours ago
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 96 bytes
n=>Enumerable.Range(32,95).Where(x=>Convert.ToString(x,2).Count(c=>c==49)==n).Select(x=>(char)x)
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 96 bytes
n=>Enumerable.Range(32,95).Where(x=>Convert.ToString(x,2).Count(c=>c==49)==n).Select(x=>(char)x)
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 96 bytes
n=>Enumerable.Range(32,95).Where(x=>Convert.ToString(x,2).Count(c=>c==49)==n).Select(x=>(char)x)
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 96 bytes
n=>Enumerable.Range(32,95).Where(x=>Convert.ToString(x,2).Count(c=>c==49)==n).Select(x=>(char)x)
Try it online!
answered 2 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
3,074127
3,074127
add a comment |
add a comment |
$begingroup$
Brachylog, 7 bytes
∈Ṭ&ạhḃ+
Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
The input variable (which is an element of the output)
∈ is an element of
Ṭ the string containing every printable ASCII character
& and the input
ạh converted to a codepoint
ḃ converted to a list of binary digits
+ sums to
the output variable (which is the input).
$endgroup$
add a comment |
$begingroup$
Brachylog, 7 bytes
∈Ṭ&ạhḃ+
Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
The input variable (which is an element of the output)
∈ is an element of
Ṭ the string containing every printable ASCII character
& and the input
ạh converted to a codepoint
ḃ converted to a list of binary digits
+ sums to
the output variable (which is the input).
$endgroup$
add a comment |
$begingroup$
Brachylog, 7 bytes
∈Ṭ&ạhḃ+
Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
The input variable (which is an element of the output)
∈ is an element of
Ṭ the string containing every printable ASCII character
& and the input
ạh converted to a codepoint
ḃ converted to a list of binary digits
+ sums to
the output variable (which is the input).
$endgroup$
Brachylog, 7 bytes
∈Ṭ&ạhḃ+
Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
The input variable (which is an element of the output)
∈ is an element of
Ṭ the string containing every printable ASCII character
& and the input
ạh converted to a codepoint
ḃ converted to a list of binary digits
+ sums to
the output variable (which is the input).
edited 2 hours ago
answered 2 hours ago
Unrelated StringUnrelated String
1,731312
1,731312
add a comment |
add a comment |
$begingroup$
J, 31 bytes
a.#~&(95{.32}.])]=1#.2#:@i.@^8:
Try it online!
2#:@i.@^8:
produces the binary numbers 0 through 255 (2 ^ 8
is 256)
1#.
sums each one
]=
produces a binary mask showing where the sum equals the original input
a.#~ mask
uses that binary mask to filter J's full ascii alphabeta.
&(95{.32}.])
but before doing so take only elements 32...126 from both the alphabet and the mask
$endgroup$
add a comment |
$begingroup$
J, 31 bytes
a.#~&(95{.32}.])]=1#.2#:@i.@^8:
Try it online!
2#:@i.@^8:
produces the binary numbers 0 through 255 (2 ^ 8
is 256)
1#.
sums each one
]=
produces a binary mask showing where the sum equals the original input
a.#~ mask
uses that binary mask to filter J's full ascii alphabeta.
&(95{.32}.])
but before doing so take only elements 32...126 from both the alphabet and the mask
$endgroup$
add a comment |
$begingroup$
J, 31 bytes
a.#~&(95{.32}.])]=1#.2#:@i.@^8:
Try it online!
2#:@i.@^8:
produces the binary numbers 0 through 255 (2 ^ 8
is 256)
1#.
sums each one
]=
produces a binary mask showing where the sum equals the original input
a.#~ mask
uses that binary mask to filter J's full ascii alphabeta.
&(95{.32}.])
but before doing so take only elements 32...126 from both the alphabet and the mask
$endgroup$
J, 31 bytes
a.#~&(95{.32}.])]=1#.2#:@i.@^8:
Try it online!
2#:@i.@^8:
produces the binary numbers 0 through 255 (2 ^ 8
is 256)
1#.
sums each one
]=
produces a binary mask showing where the sum equals the original input
a.#~ mask
uses that binary mask to filter J's full ascii alphabeta.
&(95{.32}.])
but before doing so take only elements 32...126 from both the alphabet and the mask
edited 1 hour ago
answered 3 hours ago
JonahJonah
2,9681019
2,9681019
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
answered 4 hours ago
Neil A.Neil A.
1,378120
1,378120
add a comment |
add a comment |
$begingroup$
Perl 6, 41 bytes
{chrs grep *.base(2).comb.sum==$_,^95+32}
Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
$endgroup$
add a comment |
$begingroup$
Perl 6, 41 bytes
{chrs grep *.base(2).comb.sum==$_,^95+32}
Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
$endgroup$
add a comment |
$begingroup$
Perl 6, 41 bytes
{chrs grep *.base(2).comb.sum==$_,^95+32}
Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
$endgroup$
Perl 6, 41 bytes
{chrs grep *.base(2).comb.sum==$_,^95+32}
Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
answered 3 hours ago
Jo KingJo King
27.4k365133
27.4k365133
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183625%2fall-ascii-characters-with-a-given-bit-count%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg.
63
vs?
)?$endgroup$
– Benjamin Urquhart
10 hours ago
1
$begingroup$
Must be the actual characters.
$endgroup$
– ElPedro
10 hours ago
4
$begingroup$
"the same type of quotes must be used for all inputs" Python, for example, uses single quotes (
'
) for the string representation of a string by default, but uses double quotes ("
) if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.$endgroup$
– Erik the Outgolfer
10 hours ago
$begingroup$
@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)
$endgroup$
– ElPedro
7 hours ago