Quine outputs itself in binary
Clash Royale CLAN TAG#URR8PPP
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not take input (or have an unused, empty input).
The output may be in any convient format.
Optional trailing newline is allowed.
Notice that one byte is 8 bits, and the length of the binary UTF-8 representation is necessarily a multiple of 8.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Standard loopholes are forbidden.
Example
Let's say your source code is Aä$$€h
, its corresponding UTF-8 binary representation is 010000011100001110100100001001000010010011100010100000101010110001101000
.
If I run Aä$$€h
the output must be 010000011100001110100100001001000010010011100010100000101010110001101000
.
A --> 01000001
ä --> 1100001110100100
$ --> 00100100
$ --> 00100100
€ --> 111000101000001010101100
h --> 01101000
Aä$$€h --> 010000011100001110100100001001000010010011100010100000101010110001101000
String to binary UTF-8 converters
Try it online!
utf8-convert
code-golf quine binary
$endgroup$
|
show 5 more comments
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not take input (or have an unused, empty input).
The output may be in any convient format.
Optional trailing newline is allowed.
Notice that one byte is 8 bits, and the length of the binary UTF-8 representation is necessarily a multiple of 8.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Standard loopholes are forbidden.
Example
Let's say your source code is Aä$$€h
, its corresponding UTF-8 binary representation is 010000011100001110100100001001000010010011100010100000101010110001101000
.
If I run Aä$$€h
the output must be 010000011100001110100100001001000010010011100010100000101010110001101000
.
A --> 01000001
ä --> 1100001110100100
$ --> 00100100
$ --> 00100100
€ --> 111000101000001010101100
h --> 01101000
Aä$$€h --> 010000011100001110100100001001000010010011100010100000101010110001101000
String to binary UTF-8 converters
Try it online!
utf8-convert
code-golf quine binary
$endgroup$
1
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
1
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as01011110
or0010011100100010
in UTF-8 (they look pretty alike:^
vs∧
)
$endgroup$
– Adám
Feb 4 at 19:44
1
$begingroup$
Better example:01111100
and0010001100100010
encode|
and∣
.
$endgroup$
– Adám
Feb 4 at 19:51
4
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
1
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18
|
show 5 more comments
$begingroup$
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not take input (or have an unused, empty input).
The output may be in any convient format.
Optional trailing newline is allowed.
Notice that one byte is 8 bits, and the length of the binary UTF-8 representation is necessarily a multiple of 8.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Standard loopholes are forbidden.
Example
Let's say your source code is Aä$$€h
, its corresponding UTF-8 binary representation is 010000011100001110100100001001000010010011100010100000101010110001101000
.
If I run Aä$$€h
the output must be 010000011100001110100100001001000010010011100010100000101010110001101000
.
A --> 01000001
ä --> 1100001110100100
$ --> 00100100
$ --> 00100100
€ --> 111000101000001010101100
h --> 01101000
Aä$$€h --> 010000011100001110100100001001000010010011100010100000101010110001101000
String to binary UTF-8 converters
Try it online!
utf8-convert
code-golf quine binary
$endgroup$
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not take input (or have an unused, empty input).
The output may be in any convient format.
Optional trailing newline is allowed.
Notice that one byte is 8 bits, and the length of the binary UTF-8 representation is necessarily a multiple of 8.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Standard loopholes are forbidden.
Example
Let's say your source code is Aä$$€h
, its corresponding UTF-8 binary representation is 010000011100001110100100001001000010010011100010100000101010110001101000
.
If I run Aä$$€h
the output must be 010000011100001110100100001001000010010011100010100000101010110001101000
.
A --> 01000001
ä --> 1100001110100100
$ --> 00100100
$ --> 00100100
€ --> 111000101000001010101100
h --> 01101000
Aä$$€h --> 010000011100001110100100001001000010010011100010100000101010110001101000
String to binary UTF-8 converters
Try it online!
utf8-convert
code-golf quine binary
code-golf quine binary
edited Feb 4 at 23:47
mdahmoune
asked Feb 4 at 18:12
mdahmounemdahmoune
1,6551725
1,6551725
1
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
1
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as01011110
or0010011100100010
in UTF-8 (they look pretty alike:^
vs∧
)
$endgroup$
– Adám
Feb 4 at 19:44
1
$begingroup$
Better example:01111100
and0010001100100010
encode|
and∣
.
$endgroup$
– Adám
Feb 4 at 19:51
4
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
1
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18
|
show 5 more comments
1
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
1
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as01011110
or0010011100100010
in UTF-8 (they look pretty alike:^
vs∧
)
$endgroup$
– Adám
Feb 4 at 19:44
1
$begingroup$
Better example:01111100
and0010001100100010
encode|
and∣
.
$endgroup$
– Adám
Feb 4 at 19:51
4
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
1
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18
1
1
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
1
1
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as
01011110
or 0010011100100010
in UTF-8 (they look pretty alike: ^
vs ∧
)$endgroup$
– Adám
Feb 4 at 19:44
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as
01011110
or 0010011100100010
in UTF-8 (they look pretty alike: ^
vs ∧
)$endgroup$
– Adám
Feb 4 at 19:44
1
1
$begingroup$
Better example:
01111100
and 0010001100100010
encode |
and ∣
.$endgroup$
– Adám
Feb 4 at 19:51
$begingroup$
Better example:
01111100
and 0010001100100010
encode |
and ∣
.$endgroup$
– Adám
Feb 4 at 19:51
4
4
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
1
1
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18
|
show 5 more comments
13 Answers
13
active
oldest
votes
$begingroup$
V, 28 (or 16?) Latin 1 bytes (35 UTF-8 bytes)
ñéÑ~"qpx!!xxd -b
ÎdW54|D
Íßó
Try it online!
Hexdump (in Latin 1):
00000000: f1e9 d17e 2271 7078 2121 7878 6420 2d62 ...~"qpx!!xxd -b
00000010: 0ace 6457 3534 7c44 0acd dff3 ..dW54|D....
Output (binary representation of the same code in UTF-8, not Latin 1):
110000111011000111000011101010011100001110010001011111100010001001110001011100000111100000100001001000010111100001111000011001000010000000101101011000100000110111000011100011100110010001010111001101010011010001111100010001000000110111000011100011011100001110011111110000111011001100001010
Explanation:
ñéÑ~"qpx " Standard quine. Anything after this doesn't affect the
" program's 'quine-ness' unless it modifies text in the buffer
!!xxd -b " Run xxd in binary mode on the text
Î " On every line...
dW " delete a WORD
54| " Go to the 54'th character on this line
D " And delete everything after the cursor
Í " Remove on every line...
ó " Any whitespace
ß " Including newlines
Or...
V, 16 bytes
ñéÑ~"qpx!!xxd -b
Try it online!
Output:
00000000: 11000011 10110001 11000011 10101001 11000011 10010001 ......
00000006: 01111110 00100010 01110001 01110000 01111000 00100001 ~"qpx!
0000000c: 00100001 01111000 01111000 01100100 00100000 00101101 !xxd -
00000012: 01100010 00001010 b.
OP said:
The output may be in any convenient format.
This outputs in a much more convenient format for V :P (but I'm not sure if that's stretching the rules)
$endgroup$
add a comment |
$begingroup$
CJam, 20 bytes
s"_~"+i2b8Te[%_~
Try it online!
Surprised to see CJam winning! we'll see how long that lasts...
$endgroup$
add a comment |
$begingroup$
05AB1E, 105 bytes
0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E has no UTF-8 conversion builtins, so I have to do everything manually..
Try it online or verify that it's a quine.
Explanation:
quine-part:
The shortest quine for 05AB1E is this one: 0"D34çý"D34çý
(14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ...
here: 0"D34çý..."D34çý...
. A short explanation of this quine:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Challenge part:
Now for the challenge part of the code. As I mentioned at the top, 05AB1E has no UTF-8 conversion builtins, so I have to do these things manually. I've used this source as reference on how to do that: Manually converting unicode codepoints into UTF-8 and UTF-16. Here a short summary of that regarding the conversion of Unicode characters to UTF-8:
- Convert the unicode characters to their unicode values (i.e.
"dЖ丽"
becomes[100,1046,20029]
) - Convert these unicode values to binary (i.e.
[100,1046,20029]
becomes["1100100","10000010110","100111000111101"]
) - Check in which of the following ranges the characters are:
0x00000000 - 0x0000007F
(0-127):0xxxxxxx
0x00000080 - 0x000007FF
(128-2047):110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF
(2048-65535):1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF
(65536-2097151):11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
There are also ranges for 5 or 6 bytes, but let's leave them out for now.
The character d
will be in the first range, so 1 byte in UTF-8; character Ж
is in the second range, so 2 bytes in UTF-8; and character 丽
is in the third range, so 3 bytes in UTF-8.
The x
in the pattern behind it are filled with the binary of these characters, from right to left. So the d
(1100100
) with pattern 0xxxxxxx
becomes 01100100
; the Ж
(10000010110
) with pattern 110xxxxx 10xxxxxx
becomes 11010000 10010110
; and the 丽
(100111000111101
) with pattern 1110xxxx 10xxxxxx 10xxxxxx
becomes 1110x100 10111000 10111101
, after which the remaining x
are replaced with 0
: 11100100 10111000 10111101
.
So, that approach I also used in my code. Instead of checking the actual ranges, I just look at the length of the binary and compare it to the amount of x
in the patterns however, since that saves a few bytes.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
See this 05AB1E answer of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Xó•18в
is [1,8,12,17]
.
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 60 bytes
-15 bytes from @Neil and @Shaggy
f=_=>[...Buffer(`f=`+f)].map(x=>x.toString(2).padStart(8,0))
Try it online!
$endgroup$
$begingroup$
padStart(8,0)
saves 2 bytes.
$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep themap
and ditch thejoin
to output an array of bits
$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
add a comment |
$begingroup$
Rust, 187 bytes
fn f(o:u8)for c in b"go!g)n;t9(zgns!b!ho!c#%#/huds)(zhg!b_n <27zqshou )#z;19cfn main()f(1);
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 46 bytes
<say "<$_>~~.EVAL".ords.fmt("%08b",'')>~~.EVAL
Try it online!
The standard quine with .fmt("%08b",'')
formats the list of ordinal values into length 8 binary and joins with an empty string.
$endgroup$
add a comment |
$begingroup$
Perl 5, 42 bytes
$_=q(say unpack'B*',"$_=q($_);eval");eval
TIO
$endgroup$
add a comment |
$begingroup$
Java 10, 339 308 265 227 225 186 184 bytes
v->var s="v->var s=%c%s%1$c;return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);";return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);
-8 bytes thanks to @NahuelFouilleul removing the unnecessary &255
(and an additional -35 for bringing to my attention that the full program specs of the challenge had been revoked and a function is allowed now as well..)
-41 bytes thanks to @OlivierGrégoire.
Try it online.
Explanation:
quine-part:
var s
contains the unformatted source code String%s
is used to put this String into itself withs.format(...)
%c
,%1$c
and34
are used to format the double-quotes ("
)s.format(s,34,s)
puts it all together
Challenge part:
v-> // Method with empty unused parameter and String return-type
var s="..."; // Unformatted source code String
return 0+ // Return, with a leading "0":
new java.math.BigInteger( // A BigInteger of:
s.format(s,34,s) // The actual source code String
.getBytes()) // Converted to a list of bytes (UTF-8 by default)
.toString(2); // And convert this BigInteger to a binary-String
$endgroup$
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned intc&255
is not needed
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing&255
however since we don't use any non-ASCII characters, thanks!
$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot aboutBigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing thereturn'0'+
toreturn 0+
. Hmm, why is that leading0
necessary btw? It confuses me that all inner binary-Strings have this leading0
, but the very first one not when usingBigInteger.toString(2)
..
$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
|
show 8 more comments
$begingroup$
Python 2, 68 67 bytes
_="print''.join(bin(256|ord(i))[3:]for i in'_=%r;exec _'%_)";exec _
Try it online!
A modification of this answer
-1 bytes by removing the space after 'in' (thanks @mdahmoune)
$endgroup$
$begingroup$
-1 byte: u can drop the space afterin
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do'%08b'%ord(i)
instead ofbin(256|ord(i))[3:]
, but it didn't work for some reason
$endgroup$
– Jo King
Feb 6 at 9:50
add a comment |
$begingroup$
R, 138 114 bytes
x=function()rev(rawToBits(rev(charToRaw(sprintf("x=%s;x()",gsub("\s","",paste(deparse(x),collapse="")))))));x()
Try it online!
Uses R’s ability to deparse functions to their character representation. The rev
s are needed because rawToBits
puts the least significant bit first. as.integer
is needed because otherwise the bits are displayed with a leading zero.
Edited once I realised that any convenient output was allowed. Also was out by one on original byte count.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 221 bytes
var s="var s=010;Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
C# (Visual C# Interactive Compiler) with flag /u:System.String
, 193 bytes
var s="var s=010;Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
$endgroup$
add a comment |
$begingroup$
Bash + GNU tools, 48 bytes
trap -- 'trap|xxd -b|cut -b9-64|tr -dc 01' EXIT
TIO
$endgroup$
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
add a comment |
$begingroup$
Shell script, 42 bytes
#!/bin/sh
xxd -b<"$0"|cut -b9-64|tr -dc 01
Two additional bytes may be removed (the quote marks) if the filename doesn't contain spaces or special characters.
$endgroup$
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also thecut -b9-
keeps the characters01
of the source that will not be translated withtr
, can be seen easier withtr -dc '01 n'
,cut -b9-64
should be used instead
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
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%2f179485%2fquine-outputs-itself-in-binary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
V, 28 (or 16?) Latin 1 bytes (35 UTF-8 bytes)
ñéÑ~"qpx!!xxd -b
ÎdW54|D
Íßó
Try it online!
Hexdump (in Latin 1):
00000000: f1e9 d17e 2271 7078 2121 7878 6420 2d62 ...~"qpx!!xxd -b
00000010: 0ace 6457 3534 7c44 0acd dff3 ..dW54|D....
Output (binary representation of the same code in UTF-8, not Latin 1):
110000111011000111000011101010011100001110010001011111100010001001110001011100000111100000100001001000010111100001111000011001000010000000101101011000100000110111000011100011100110010001010111001101010011010001111100010001000000110111000011100011011100001110011111110000111011001100001010
Explanation:
ñéÑ~"qpx " Standard quine. Anything after this doesn't affect the
" program's 'quine-ness' unless it modifies text in the buffer
!!xxd -b " Run xxd in binary mode on the text
Î " On every line...
dW " delete a WORD
54| " Go to the 54'th character on this line
D " And delete everything after the cursor
Í " Remove on every line...
ó " Any whitespace
ß " Including newlines
Or...
V, 16 bytes
ñéÑ~"qpx!!xxd -b
Try it online!
Output:
00000000: 11000011 10110001 11000011 10101001 11000011 10010001 ......
00000006: 01111110 00100010 01110001 01110000 01111000 00100001 ~"qpx!
0000000c: 00100001 01111000 01111000 01100100 00100000 00101101 !xxd -
00000012: 01100010 00001010 b.
OP said:
The output may be in any convenient format.
This outputs in a much more convenient format for V :P (but I'm not sure if that's stretching the rules)
$endgroup$
add a comment |
$begingroup$
V, 28 (or 16?) Latin 1 bytes (35 UTF-8 bytes)
ñéÑ~"qpx!!xxd -b
ÎdW54|D
Íßó
Try it online!
Hexdump (in Latin 1):
00000000: f1e9 d17e 2271 7078 2121 7878 6420 2d62 ...~"qpx!!xxd -b
00000010: 0ace 6457 3534 7c44 0acd dff3 ..dW54|D....
Output (binary representation of the same code in UTF-8, not Latin 1):
110000111011000111000011101010011100001110010001011111100010001001110001011100000111100000100001001000010111100001111000011001000010000000101101011000100000110111000011100011100110010001010111001101010011010001111100010001000000110111000011100011011100001110011111110000111011001100001010
Explanation:
ñéÑ~"qpx " Standard quine. Anything after this doesn't affect the
" program's 'quine-ness' unless it modifies text in the buffer
!!xxd -b " Run xxd in binary mode on the text
Î " On every line...
dW " delete a WORD
54| " Go to the 54'th character on this line
D " And delete everything after the cursor
Í " Remove on every line...
ó " Any whitespace
ß " Including newlines
Or...
V, 16 bytes
ñéÑ~"qpx!!xxd -b
Try it online!
Output:
00000000: 11000011 10110001 11000011 10101001 11000011 10010001 ......
00000006: 01111110 00100010 01110001 01110000 01111000 00100001 ~"qpx!
0000000c: 00100001 01111000 01111000 01100100 00100000 00101101 !xxd -
00000012: 01100010 00001010 b.
OP said:
The output may be in any convenient format.
This outputs in a much more convenient format for V :P (but I'm not sure if that's stretching the rules)
$endgroup$
add a comment |
$begingroup$
V, 28 (or 16?) Latin 1 bytes (35 UTF-8 bytes)
ñéÑ~"qpx!!xxd -b
ÎdW54|D
Íßó
Try it online!
Hexdump (in Latin 1):
00000000: f1e9 d17e 2271 7078 2121 7878 6420 2d62 ...~"qpx!!xxd -b
00000010: 0ace 6457 3534 7c44 0acd dff3 ..dW54|D....
Output (binary representation of the same code in UTF-8, not Latin 1):
110000111011000111000011101010011100001110010001011111100010001001110001011100000111100000100001001000010111100001111000011001000010000000101101011000100000110111000011100011100110010001010111001101010011010001111100010001000000110111000011100011011100001110011111110000111011001100001010
Explanation:
ñéÑ~"qpx " Standard quine. Anything after this doesn't affect the
" program's 'quine-ness' unless it modifies text in the buffer
!!xxd -b " Run xxd in binary mode on the text
Î " On every line...
dW " delete a WORD
54| " Go to the 54'th character on this line
D " And delete everything after the cursor
Í " Remove on every line...
ó " Any whitespace
ß " Including newlines
Or...
V, 16 bytes
ñéÑ~"qpx!!xxd -b
Try it online!
Output:
00000000: 11000011 10110001 11000011 10101001 11000011 10010001 ......
00000006: 01111110 00100010 01110001 01110000 01111000 00100001 ~"qpx!
0000000c: 00100001 01111000 01111000 01100100 00100000 00101101 !xxd -
00000012: 01100010 00001010 b.
OP said:
The output may be in any convenient format.
This outputs in a much more convenient format for V :P (but I'm not sure if that's stretching the rules)
$endgroup$
V, 28 (or 16?) Latin 1 bytes (35 UTF-8 bytes)
ñéÑ~"qpx!!xxd -b
ÎdW54|D
Íßó
Try it online!
Hexdump (in Latin 1):
00000000: f1e9 d17e 2271 7078 2121 7878 6420 2d62 ...~"qpx!!xxd -b
00000010: 0ace 6457 3534 7c44 0acd dff3 ..dW54|D....
Output (binary representation of the same code in UTF-8, not Latin 1):
110000111011000111000011101010011100001110010001011111100010001001110001011100000111100000100001001000010111100001111000011001000010000000101101011000100000110111000011100011100110010001010111001101010011010001111100010001000000110111000011100011011100001110011111110000111011001100001010
Explanation:
ñéÑ~"qpx " Standard quine. Anything after this doesn't affect the
" program's 'quine-ness' unless it modifies text in the buffer
!!xxd -b " Run xxd in binary mode on the text
Î " On every line...
dW " delete a WORD
54| " Go to the 54'th character on this line
D " And delete everything after the cursor
Í " Remove on every line...
ó " Any whitespace
ß " Including newlines
Or...
V, 16 bytes
ñéÑ~"qpx!!xxd -b
Try it online!
Output:
00000000: 11000011 10110001 11000011 10101001 11000011 10010001 ......
00000006: 01111110 00100010 01110001 01110000 01111000 00100001 ~"qpx!
0000000c: 00100001 01111000 01111000 01100100 00100000 00101101 !xxd -
00000012: 01100010 00001010 b.
OP said:
The output may be in any convenient format.
This outputs in a much more convenient format for V :P (but I'm not sure if that's stretching the rules)
edited Feb 6 at 23:07
answered Feb 4 at 18:29
DJMcMayhem♦DJMcMayhem
41k12146313
41k12146313
add a comment |
add a comment |
$begingroup$
CJam, 20 bytes
s"_~"+i2b8Te[%_~
Try it online!
Surprised to see CJam winning! we'll see how long that lasts...
$endgroup$
add a comment |
$begingroup$
CJam, 20 bytes
s"_~"+i2b8Te[%_~
Try it online!
Surprised to see CJam winning! we'll see how long that lasts...
$endgroup$
add a comment |
$begingroup$
CJam, 20 bytes
s"_~"+i2b8Te[%_~
Try it online!
Surprised to see CJam winning! we'll see how long that lasts...
$endgroup$
CJam, 20 bytes
s"_~"+i2b8Te[%_~
Try it online!
Surprised to see CJam winning! we'll see how long that lasts...
answered Feb 5 at 3:42
Esolanging FruitEsolanging Fruit
8,45432674
8,45432674
add a comment |
add a comment |
$begingroup$
05AB1E, 105 bytes
0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E has no UTF-8 conversion builtins, so I have to do everything manually..
Try it online or verify that it's a quine.
Explanation:
quine-part:
The shortest quine for 05AB1E is this one: 0"D34çý"D34çý
(14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ...
here: 0"D34çý..."D34çý...
. A short explanation of this quine:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Challenge part:
Now for the challenge part of the code. As I mentioned at the top, 05AB1E has no UTF-8 conversion builtins, so I have to do these things manually. I've used this source as reference on how to do that: Manually converting unicode codepoints into UTF-8 and UTF-16. Here a short summary of that regarding the conversion of Unicode characters to UTF-8:
- Convert the unicode characters to their unicode values (i.e.
"dЖ丽"
becomes[100,1046,20029]
) - Convert these unicode values to binary (i.e.
[100,1046,20029]
becomes["1100100","10000010110","100111000111101"]
) - Check in which of the following ranges the characters are:
0x00000000 - 0x0000007F
(0-127):0xxxxxxx
0x00000080 - 0x000007FF
(128-2047):110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF
(2048-65535):1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF
(65536-2097151):11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
There are also ranges for 5 or 6 bytes, but let's leave them out for now.
The character d
will be in the first range, so 1 byte in UTF-8; character Ж
is in the second range, so 2 bytes in UTF-8; and character 丽
is in the third range, so 3 bytes in UTF-8.
The x
in the pattern behind it are filled with the binary of these characters, from right to left. So the d
(1100100
) with pattern 0xxxxxxx
becomes 01100100
; the Ж
(10000010110
) with pattern 110xxxxx 10xxxxxx
becomes 11010000 10010110
; and the 丽
(100111000111101
) with pattern 1110xxxx 10xxxxxx 10xxxxxx
becomes 1110x100 10111000 10111101
, after which the remaining x
are replaced with 0
: 11100100 10111000 10111101
.
So, that approach I also used in my code. Instead of checking the actual ranges, I just look at the length of the binary and compare it to the amount of x
in the patterns however, since that saves a few bytes.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
See this 05AB1E answer of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Xó•18в
is [1,8,12,17]
.
$endgroup$
add a comment |
$begingroup$
05AB1E, 105 bytes
0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E has no UTF-8 conversion builtins, so I have to do everything manually..
Try it online or verify that it's a quine.
Explanation:
quine-part:
The shortest quine for 05AB1E is this one: 0"D34çý"D34çý
(14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ...
here: 0"D34çý..."D34çý...
. A short explanation of this quine:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Challenge part:
Now for the challenge part of the code. As I mentioned at the top, 05AB1E has no UTF-8 conversion builtins, so I have to do these things manually. I've used this source as reference on how to do that: Manually converting unicode codepoints into UTF-8 and UTF-16. Here a short summary of that regarding the conversion of Unicode characters to UTF-8:
- Convert the unicode characters to their unicode values (i.e.
"dЖ丽"
becomes[100,1046,20029]
) - Convert these unicode values to binary (i.e.
[100,1046,20029]
becomes["1100100","10000010110","100111000111101"]
) - Check in which of the following ranges the characters are:
0x00000000 - 0x0000007F
(0-127):0xxxxxxx
0x00000080 - 0x000007FF
(128-2047):110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF
(2048-65535):1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF
(65536-2097151):11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
There are also ranges for 5 or 6 bytes, but let's leave them out for now.
The character d
will be in the first range, so 1 byte in UTF-8; character Ж
is in the second range, so 2 bytes in UTF-8; and character 丽
is in the third range, so 3 bytes in UTF-8.
The x
in the pattern behind it are filled with the binary of these characters, from right to left. So the d
(1100100
) with pattern 0xxxxxxx
becomes 01100100
; the Ж
(10000010110
) with pattern 110xxxxx 10xxxxxx
becomes 11010000 10010110
; and the 丽
(100111000111101
) with pattern 1110xxxx 10xxxxxx 10xxxxxx
becomes 1110x100 10111000 10111101
, after which the remaining x
are replaced with 0
: 11100100 10111000 10111101
.
So, that approach I also used in my code. Instead of checking the actual ranges, I just look at the length of the binary and compare it to the amount of x
in the patterns however, since that saves a few bytes.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
See this 05AB1E answer of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Xó•18в
is [1,8,12,17]
.
$endgroup$
add a comment |
$begingroup$
05AB1E, 105 bytes
0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E has no UTF-8 conversion builtins, so I have to do everything manually..
Try it online or verify that it's a quine.
Explanation:
quine-part:
The shortest quine for 05AB1E is this one: 0"D34çý"D34çý
(14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ...
here: 0"D34çý..."D34çý...
. A short explanation of this quine:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Challenge part:
Now for the challenge part of the code. As I mentioned at the top, 05AB1E has no UTF-8 conversion builtins, so I have to do these things manually. I've used this source as reference on how to do that: Manually converting unicode codepoints into UTF-8 and UTF-16. Here a short summary of that regarding the conversion of Unicode characters to UTF-8:
- Convert the unicode characters to their unicode values (i.e.
"dЖ丽"
becomes[100,1046,20029]
) - Convert these unicode values to binary (i.e.
[100,1046,20029]
becomes["1100100","10000010110","100111000111101"]
) - Check in which of the following ranges the characters are:
0x00000000 - 0x0000007F
(0-127):0xxxxxxx
0x00000080 - 0x000007FF
(128-2047):110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF
(2048-65535):1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF
(65536-2097151):11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
There are also ranges for 5 or 6 bytes, but let's leave them out for now.
The character d
will be in the first range, so 1 byte in UTF-8; character Ж
is in the second range, so 2 bytes in UTF-8; and character 丽
is in the third range, so 3 bytes in UTF-8.
The x
in the pattern behind it are filled with the binary of these characters, from right to left. So the d
(1100100
) with pattern 0xxxxxxx
becomes 01100100
; the Ж
(10000010110
) with pattern 110xxxxx 10xxxxxx
becomes 11010000 10010110
; and the 丽
(100111000111101
) with pattern 1110xxxx 10xxxxxx 10xxxxxx
becomes 1110x100 10111000 10111101
, after which the remaining x
are replaced with 0
: 11100100 10111000 10111101
.
So, that approach I also used in my code. Instead of checking the actual ranges, I just look at the length of the binary and compare it to the amount of x
in the patterns however, since that saves a few bytes.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
See this 05AB1E answer of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Xó•18в
is [1,8,12,17]
.
$endgroup$
05AB1E, 105 bytes
0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E has no UTF-8 conversion builtins, so I have to do everything manually..
Try it online or verify that it's a quine.
Explanation:
quine-part:
The shortest quine for 05AB1E is this one: 0"D34çý"D34çý
(14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ...
here: 0"D34çý..."D34çý...
. A short explanation of this quine:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Challenge part:
Now for the challenge part of the code. As I mentioned at the top, 05AB1E has no UTF-8 conversion builtins, so I have to do these things manually. I've used this source as reference on how to do that: Manually converting unicode codepoints into UTF-8 and UTF-16. Here a short summary of that regarding the conversion of Unicode characters to UTF-8:
- Convert the unicode characters to their unicode values (i.e.
"dЖ丽"
becomes[100,1046,20029]
) - Convert these unicode values to binary (i.e.
[100,1046,20029]
becomes["1100100","10000010110","100111000111101"]
) - Check in which of the following ranges the characters are:
0x00000000 - 0x0000007F
(0-127):0xxxxxxx
0x00000080 - 0x000007FF
(128-2047):110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF
(2048-65535):1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF
(65536-2097151):11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
There are also ranges for 5 or 6 bytes, but let's leave them out for now.
The character d
will be in the first range, so 1 byte in UTF-8; character Ж
is in the second range, so 2 bytes in UTF-8; and character 丽
is in the third range, so 3 bytes in UTF-8.
The x
in the pattern behind it are filled with the binary of these characters, from right to left. So the d
(1100100
) with pattern 0xxxxxxx
becomes 01100100
; the Ж
(10000010110
) with pattern 110xxxxx 10xxxxxx
becomes 11010000 10010110
; and the 丽
(100111000111101
) with pattern 1110xxxx 10xxxxxx 10xxxxxx
becomes 1110x100 10111000 10111101
, after which the remaining x
are replaced with 0
: 11100100 10111000 10111101
.
So, that approach I also used in my code. Instead of checking the actual ranges, I just look at the length of the binary and compare it to the amount of x
in the patterns however, since that saves a few bytes.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
See this 05AB1E answer of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Xó•18в
is [1,8,12,17]
.
edited Feb 5 at 7:59
answered Feb 4 at 18:37
Kevin CruijssenKevin Cruijssen
38.7k557200
38.7k557200
add a comment |
add a comment |
$begingroup$
JavaScript (Node.js), 60 bytes
-15 bytes from @Neil and @Shaggy
f=_=>[...Buffer(`f=`+f)].map(x=>x.toString(2).padStart(8,0))
Try it online!
$endgroup$
$begingroup$
padStart(8,0)
saves 2 bytes.
$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep themap
and ditch thejoin
to output an array of bits
$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
add a comment |
$begingroup$
JavaScript (Node.js), 60 bytes
-15 bytes from @Neil and @Shaggy
f=_=>[...Buffer(`f=`+f)].map(x=>x.toString(2).padStart(8,0))
Try it online!
$endgroup$
$begingroup$
padStart(8,0)
saves 2 bytes.
$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep themap
and ditch thejoin
to output an array of bits
$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
add a comment |
$begingroup$
JavaScript (Node.js), 60 bytes
-15 bytes from @Neil and @Shaggy
f=_=>[...Buffer(`f=`+f)].map(x=>x.toString(2).padStart(8,0))
Try it online!
$endgroup$
JavaScript (Node.js), 60 bytes
-15 bytes from @Neil and @Shaggy
f=_=>[...Buffer(`f=`+f)].map(x=>x.toString(2).padStart(8,0))
Try it online!
edited Feb 5 at 2:35
answered Feb 4 at 18:58
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,21721669
5,21721669
$begingroup$
padStart(8,0)
saves 2 bytes.
$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep themap
and ditch thejoin
to output an array of bits
$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
add a comment |
$begingroup$
padStart(8,0)
saves 2 bytes.
$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep themap
and ditch thejoin
to output an array of bits
$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
$begingroup$
padStart(8,0)
saves 2 bytes.$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
padStart(8,0)
saves 2 bytes.$endgroup$
– Neil
Feb 4 at 21:57
$begingroup$
The spec allows for output to be in any convenient format so you could keep the
map
and ditch the join
to output an array of bits$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
The spec allows for output to be in any convenient format so you could keep the
map
and ditch the join
to output an array of bits$endgroup$
– Shaggy
Feb 4 at 23:35
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
60 bytes with output as an array of bytes.
$endgroup$
– Shaggy
Feb 4 at 23:46
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
$begingroup$
Thanks @Neil and @Shaggy!!
$endgroup$
– Luis felipe De jesus Munoz
Feb 5 at 2:35
add a comment |
$begingroup$
Rust, 187 bytes
fn f(o:u8)for c in b"go!g)n;t9(zgns!b!ho!c#%#/huds)(zhg!b_n <27zqshou )#z;19cfn main()f(1);
Try it online!
$endgroup$
add a comment |
$begingroup$
Rust, 187 bytes
fn f(o:u8)for c in b"go!g)n;t9(zgns!b!ho!c#%#/huds)(zhg!b_n <27zqshou )#z;19cfn main()f(1);
Try it online!
$endgroup$
add a comment |
$begingroup$
Rust, 187 bytes
fn f(o:u8)for c in b"go!g)n;t9(zgns!b!ho!c#%#/huds)(zhg!b_n <27zqshou )#z;19cfn main()f(1);
Try it online!
$endgroup$
Rust, 187 bytes
fn f(o:u8)for c in b"go!g)n;t9(zgns!b!ho!c#%#/huds)(zhg!b_n <27zqshou )#z;19cfn main()f(1);
Try it online!
answered Feb 4 at 21:51
NieDzejkobNieDzejkob
3,89111430
3,89111430
add a comment |
add a comment |
$begingroup$
Perl 6, 46 bytes
<say "<$_>~~.EVAL".ords.fmt("%08b",'')>~~.EVAL
Try it online!
The standard quine with .fmt("%08b",'')
formats the list of ordinal values into length 8 binary and joins with an empty string.
$endgroup$
add a comment |
$begingroup$
Perl 6, 46 bytes
<say "<$_>~~.EVAL".ords.fmt("%08b",'')>~~.EVAL
Try it online!
The standard quine with .fmt("%08b",'')
formats the list of ordinal values into length 8 binary and joins with an empty string.
$endgroup$
add a comment |
$begingroup$
Perl 6, 46 bytes
<say "<$_>~~.EVAL".ords.fmt("%08b",'')>~~.EVAL
Try it online!
The standard quine with .fmt("%08b",'')
formats the list of ordinal values into length 8 binary and joins with an empty string.
$endgroup$
Perl 6, 46 bytes
<say "<$_>~~.EVAL".ords.fmt("%08b",'')>~~.EVAL
Try it online!
The standard quine with .fmt("%08b",'')
formats the list of ordinal values into length 8 binary and joins with an empty string.
answered Feb 4 at 23:19
Jo KingJo King
23.7k257123
23.7k257123
add a comment |
add a comment |
$begingroup$
Perl 5, 42 bytes
$_=q(say unpack'B*',"$_=q($_);eval");eval
TIO
$endgroup$
add a comment |
$begingroup$
Perl 5, 42 bytes
$_=q(say unpack'B*',"$_=q($_);eval");eval
TIO
$endgroup$
add a comment |
$begingroup$
Perl 5, 42 bytes
$_=q(say unpack'B*',"$_=q($_);eval");eval
TIO
$endgroup$
Perl 5, 42 bytes
$_=q(say unpack'B*',"$_=q($_);eval");eval
TIO
answered Feb 5 at 10:26
Nahuel FouilleulNahuel Fouilleul
2,53529
2,53529
add a comment |
add a comment |
$begingroup$
Java 10, 339 308 265 227 225 186 184 bytes
v->var s="v->var s=%c%s%1$c;return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);";return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);
-8 bytes thanks to @NahuelFouilleul removing the unnecessary &255
(and an additional -35 for bringing to my attention that the full program specs of the challenge had been revoked and a function is allowed now as well..)
-41 bytes thanks to @OlivierGrégoire.
Try it online.
Explanation:
quine-part:
var s
contains the unformatted source code String%s
is used to put this String into itself withs.format(...)
%c
,%1$c
and34
are used to format the double-quotes ("
)s.format(s,34,s)
puts it all together
Challenge part:
v-> // Method with empty unused parameter and String return-type
var s="..."; // Unformatted source code String
return 0+ // Return, with a leading "0":
new java.math.BigInteger( // A BigInteger of:
s.format(s,34,s) // The actual source code String
.getBytes()) // Converted to a list of bytes (UTF-8 by default)
.toString(2); // And convert this BigInteger to a binary-String
$endgroup$
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned intc&255
is not needed
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing&255
however since we don't use any non-ASCII characters, thanks!
$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot aboutBigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing thereturn'0'+
toreturn 0+
. Hmm, why is that leading0
necessary btw? It confuses me that all inner binary-Strings have this leading0
, but the very first one not when usingBigInteger.toString(2)
..
$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
|
show 8 more comments
$begingroup$
Java 10, 339 308 265 227 225 186 184 bytes
v->var s="v->var s=%c%s%1$c;return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);";return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);
-8 bytes thanks to @NahuelFouilleul removing the unnecessary &255
(and an additional -35 for bringing to my attention that the full program specs of the challenge had been revoked and a function is allowed now as well..)
-41 bytes thanks to @OlivierGrégoire.
Try it online.
Explanation:
quine-part:
var s
contains the unformatted source code String%s
is used to put this String into itself withs.format(...)
%c
,%1$c
and34
are used to format the double-quotes ("
)s.format(s,34,s)
puts it all together
Challenge part:
v-> // Method with empty unused parameter and String return-type
var s="..."; // Unformatted source code String
return 0+ // Return, with a leading "0":
new java.math.BigInteger( // A BigInteger of:
s.format(s,34,s) // The actual source code String
.getBytes()) // Converted to a list of bytes (UTF-8 by default)
.toString(2); // And convert this BigInteger to a binary-String
$endgroup$
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned intc&255
is not needed
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing&255
however since we don't use any non-ASCII characters, thanks!
$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot aboutBigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing thereturn'0'+
toreturn 0+
. Hmm, why is that leading0
necessary btw? It confuses me that all inner binary-Strings have this leading0
, but the very first one not when usingBigInteger.toString(2)
..
$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
|
show 8 more comments
$begingroup$
Java 10, 339 308 265 227 225 186 184 bytes
v->var s="v->var s=%c%s%1$c;return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);";return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);
-8 bytes thanks to @NahuelFouilleul removing the unnecessary &255
(and an additional -35 for bringing to my attention that the full program specs of the challenge had been revoked and a function is allowed now as well..)
-41 bytes thanks to @OlivierGrégoire.
Try it online.
Explanation:
quine-part:
var s
contains the unformatted source code String%s
is used to put this String into itself withs.format(...)
%c
,%1$c
and34
are used to format the double-quotes ("
)s.format(s,34,s)
puts it all together
Challenge part:
v-> // Method with empty unused parameter and String return-type
var s="..."; // Unformatted source code String
return 0+ // Return, with a leading "0":
new java.math.BigInteger( // A BigInteger of:
s.format(s,34,s) // The actual source code String
.getBytes()) // Converted to a list of bytes (UTF-8 by default)
.toString(2); // And convert this BigInteger to a binary-String
$endgroup$
Java 10, 339 308 265 227 225 186 184 bytes
v->var s="v->var s=%c%s%1$c;return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);";return 0+new java.math.BigInteger(s.format(s,34,s).getBytes()).toString(2);
-8 bytes thanks to @NahuelFouilleul removing the unnecessary &255
(and an additional -35 for bringing to my attention that the full program specs of the challenge had been revoked and a function is allowed now as well..)
-41 bytes thanks to @OlivierGrégoire.
Try it online.
Explanation:
quine-part:
var s
contains the unformatted source code String%s
is used to put this String into itself withs.format(...)
%c
,%1$c
and34
are used to format the double-quotes ("
)s.format(s,34,s)
puts it all together
Challenge part:
v-> // Method with empty unused parameter and String return-type
var s="..."; // Unformatted source code String
return 0+ // Return, with a leading "0":
new java.math.BigInteger( // A BigInteger of:
s.format(s,34,s) // The actual source code String
.getBytes()) // Converted to a list of bytes (UTF-8 by default)
.toString(2); // And convert this BigInteger to a binary-String
edited Feb 5 at 14:49
answered Feb 4 at 18:34
Kevin CruijssenKevin Cruijssen
38.7k557200
38.7k557200
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned intc&255
is not needed
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing&255
however since we don't use any non-ASCII characters, thanks!
$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot aboutBigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing thereturn'0'+
toreturn 0+
. Hmm, why is that leading0
necessary btw? It confuses me that all inner binary-Strings have this leading0
, but the very first one not when usingBigInteger.toString(2)
..
$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
|
show 8 more comments
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned intc&255
is not needed
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing&255
however since we don't use any non-ASCII characters, thanks!
$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot aboutBigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing thereturn'0'+
toreturn 0+
. Hmm, why is that leading0
necessary btw? It confuses me that all inner binary-Strings have this leading0
, but the very first one not when usingBigInteger.toString(2)
..
$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
1
1
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned int
c&255
is not needed$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
265 bytes using lambda, also because all source is ascii seems unsigned int
c&255
is not needed$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:32
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing
&255
however since we don't use any non-ASCII characters, thanks!$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
@NahuelFouilleul The original question stated "You must build a full program." and "Your output has to be printed to STDOUT.", hence the verbose border-plate code I have instead of a lambda function returning a String. Good point about not needing
&255
however since we don't use any non-ASCII characters, thanks!$endgroup$
– Kevin Cruijssen
Feb 5 at 13:34
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
$begingroup$
ok i'm not yet very familar with the usages, but other languages like javascript give a lambda returning a string, also i don't understand why in java we don't count the type and the final semicolon when using lambda where could i find rules?
$endgroup$
– Nahuel Fouilleul
Feb 5 at 13:44
1
1
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
$begingroup$
Well, that's where I'm lost. However I tried and here's a new candidate for 184 bytes. Tell me if I'm wrong somewhere ;)
$endgroup$
– Olivier Grégoire
Feb 5 at 14:37
1
1
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot about
BigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing the return'0'+
to return 0+
. Hmm, why is that leading 0
necessary btw? It confuses me that all inner binary-Strings have this leading 0
, but the very first one not when using BigInteger.toString(2)
..$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
$begingroup$
@OlivierGrégoire Ah, nice approach! Completely forgot about
BigInteger
being pretty short for converting to binary-Strings. And 2 more bytes by changing the return'0'+
to return 0+
. Hmm, why is that leading 0
necessary btw? It confuses me that all inner binary-Strings have this leading 0
, but the very first one not when using BigInteger.toString(2)
..$endgroup$
– Kevin Cruijssen
Feb 5 at 14:44
|
show 8 more comments
$begingroup$
Python 2, 68 67 bytes
_="print''.join(bin(256|ord(i))[3:]for i in'_=%r;exec _'%_)";exec _
Try it online!
A modification of this answer
-1 bytes by removing the space after 'in' (thanks @mdahmoune)
$endgroup$
$begingroup$
-1 byte: u can drop the space afterin
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do'%08b'%ord(i)
instead ofbin(256|ord(i))[3:]
, but it didn't work for some reason
$endgroup$
– Jo King
Feb 6 at 9:50
add a comment |
$begingroup$
Python 2, 68 67 bytes
_="print''.join(bin(256|ord(i))[3:]for i in'_=%r;exec _'%_)";exec _
Try it online!
A modification of this answer
-1 bytes by removing the space after 'in' (thanks @mdahmoune)
$endgroup$
$begingroup$
-1 byte: u can drop the space afterin
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do'%08b'%ord(i)
instead ofbin(256|ord(i))[3:]
, but it didn't work for some reason
$endgroup$
– Jo King
Feb 6 at 9:50
add a comment |
$begingroup$
Python 2, 68 67 bytes
_="print''.join(bin(256|ord(i))[3:]for i in'_=%r;exec _'%_)";exec _
Try it online!
A modification of this answer
-1 bytes by removing the space after 'in' (thanks @mdahmoune)
$endgroup$
Python 2, 68 67 bytes
_="print''.join(bin(256|ord(i))[3:]for i in'_=%r;exec _'%_)";exec _
Try it online!
A modification of this answer
-1 bytes by removing the space after 'in' (thanks @mdahmoune)
edited Feb 6 at 13:06
answered Feb 5 at 18:19
MilkyWay90MilkyWay90
45819
45819
$begingroup$
-1 byte: u can drop the space afterin
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do'%08b'%ord(i)
instead ofbin(256|ord(i))[3:]
, but it didn't work for some reason
$endgroup$
– Jo King
Feb 6 at 9:50
add a comment |
$begingroup$
-1 byte: u can drop the space afterin
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do'%08b'%ord(i)
instead ofbin(256|ord(i))[3:]
, but it didn't work for some reason
$endgroup$
– Jo King
Feb 6 at 9:50
$begingroup$
-1 byte: u can drop the space after
in
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
-1 byte: u can drop the space after
in
$endgroup$
– mdahmoune
Feb 5 at 18:24
$begingroup$
you haven't updated your TIO link. also, I tried to do
'%08b'%ord(i)
instead of bin(256|ord(i))[3:]
, but it didn't work for some reason$endgroup$
– Jo King
Feb 6 at 9:50
$begingroup$
you haven't updated your TIO link. also, I tried to do
'%08b'%ord(i)
instead of bin(256|ord(i))[3:]
, but it didn't work for some reason$endgroup$
– Jo King
Feb 6 at 9:50
add a comment |
$begingroup$
R, 138 114 bytes
x=function()rev(rawToBits(rev(charToRaw(sprintf("x=%s;x()",gsub("\s","",paste(deparse(x),collapse="")))))));x()
Try it online!
Uses R’s ability to deparse functions to their character representation. The rev
s are needed because rawToBits
puts the least significant bit first. as.integer
is needed because otherwise the bits are displayed with a leading zero.
Edited once I realised that any convenient output was allowed. Also was out by one on original byte count.
$endgroup$
add a comment |
$begingroup$
R, 138 114 bytes
x=function()rev(rawToBits(rev(charToRaw(sprintf("x=%s;x()",gsub("\s","",paste(deparse(x),collapse="")))))));x()
Try it online!
Uses R’s ability to deparse functions to their character representation. The rev
s are needed because rawToBits
puts the least significant bit first. as.integer
is needed because otherwise the bits are displayed with a leading zero.
Edited once I realised that any convenient output was allowed. Also was out by one on original byte count.
$endgroup$
add a comment |
$begingroup$
R, 138 114 bytes
x=function()rev(rawToBits(rev(charToRaw(sprintf("x=%s;x()",gsub("\s","",paste(deparse(x),collapse="")))))));x()
Try it online!
Uses R’s ability to deparse functions to their character representation. The rev
s are needed because rawToBits
puts the least significant bit first. as.integer
is needed because otherwise the bits are displayed with a leading zero.
Edited once I realised that any convenient output was allowed. Also was out by one on original byte count.
$endgroup$
R, 138 114 bytes
x=function()rev(rawToBits(rev(charToRaw(sprintf("x=%s;x()",gsub("\s","",paste(deparse(x),collapse="")))))));x()
Try it online!
Uses R’s ability to deparse functions to their character representation. The rev
s are needed because rawToBits
puts the least significant bit first. as.integer
is needed because otherwise the bits are displayed with a leading zero.
Edited once I realised that any convenient output was allowed. Also was out by one on original byte count.
edited Feb 7 at 0:45
Jo King
23.7k257123
23.7k257123
answered Feb 5 at 20:08
Nick KennedyNick Kennedy
23114
23114
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 221 bytes
var s="var s=010;Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
C# (Visual C# Interactive Compiler) with flag /u:System.String
, 193 bytes
var s="var s=010;Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 221 bytes
var s="var s=010;Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
C# (Visual C# Interactive Compiler) with flag /u:System.String
, 193 bytes
var s="var s=010;Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 221 bytes
var s="var s=010;Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
C# (Visual C# Interactive Compiler) with flag /u:System.String
, 193 bytes
var s="var s=010;Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 221 bytes
var s="var s=010;Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(string.Concat(string.Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
C# (Visual C# Interactive Compiler) with flag /u:System.String
, 193 bytes
var s="var s=010;Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));";Write(Concat(Format(s,(char)34,s).Select(z=>Convert.ToString(z,2).PadLeft(8,'0'))));
Try it online!
edited Feb 4 at 22:57
answered Feb 4 at 22:38
Embodiment of IgnoranceEmbodiment of Ignorance
1,250119
1,250119
add a comment |
add a comment |
$begingroup$
Bash + GNU tools, 48 bytes
trap -- 'trap|xxd -b|cut -b9-64|tr -dc 01' EXIT
TIO
$endgroup$
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
add a comment |
$begingroup$
Bash + GNU tools, 48 bytes
trap -- 'trap|xxd -b|cut -b9-64|tr -dc 01' EXIT
TIO
$endgroup$
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
add a comment |
$begingroup$
Bash + GNU tools, 48 bytes
trap -- 'trap|xxd -b|cut -b9-64|tr -dc 01' EXIT
TIO
$endgroup$
Bash + GNU tools, 48 bytes
trap -- 'trap|xxd -b|cut -b9-64|tr -dc 01' EXIT
TIO
edited Feb 5 at 11:20
answered Feb 5 at 11:07
Nahuel FouilleulNahuel Fouilleul
2,53529
2,53529
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
add a comment |
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
$begingroup$
thanks, updated indeed it's the shortest variation otherwise should be removed from trap output
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:21
add a comment |
$begingroup$
Shell script, 42 bytes
#!/bin/sh
xxd -b<"$0"|cut -b9-64|tr -dc 01
Two additional bytes may be removed (the quote marks) if the filename doesn't contain spaces or special characters.
$endgroup$
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also thecut -b9-
keeps the characters01
of the source that will not be translated withtr
, can be seen easier withtr -dc '01 n'
,cut -b9-64
should be used instead
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
add a comment |
$begingroup$
Shell script, 42 bytes
#!/bin/sh
xxd -b<"$0"|cut -b9-64|tr -dc 01
Two additional bytes may be removed (the quote marks) if the filename doesn't contain spaces or special characters.
$endgroup$
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also thecut -b9-
keeps the characters01
of the source that will not be translated withtr
, can be seen easier withtr -dc '01 n'
,cut -b9-64
should be used instead
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
add a comment |
$begingroup$
Shell script, 42 bytes
#!/bin/sh
xxd -b<"$0"|cut -b9-64|tr -dc 01
Two additional bytes may be removed (the quote marks) if the filename doesn't contain spaces or special characters.
$endgroup$
Shell script, 42 bytes
#!/bin/sh
xxd -b<"$0"|cut -b9-64|tr -dc 01
Two additional bytes may be removed (the quote marks) if the filename doesn't contain spaces or special characters.
edited Feb 6 at 23:56
answered Feb 5 at 3:02
immibisimmibis
799412
799412
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also thecut -b9-
keeps the characters01
of the source that will not be translated withtr
, can be seen easier withtr -dc '01 n'
,cut -b9-64
should be used instead
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
add a comment |
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also thecut -b9-
keeps the characters01
of the source that will not be translated withtr
, can be seen easier withtr -dc '01 n'
,cut -b9-64
should be used instead
$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
1
1
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
I'm sure you can just label this as Bash and remove the first line, though this appears to be reading its own source code, which is not allowed
$endgroup$
– Jo King
Feb 5 at 3:43
$begingroup$
also the
cut -b9-
keeps the characters 01
of the source that will not be translated with tr
, can be seen easier with tr -dc '01 n'
, cut -b9-64
should be used instead$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
$begingroup$
also the
cut -b9-
keeps the characters 01
of the source that will not be translated with tr
, can be seen easier with tr -dc '01 n'
, cut -b9-64
should be used instead$endgroup$
– Nahuel Fouilleul
Feb 5 at 11:35
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%2f179485%2fquine-outputs-itself-in-binary%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
1
$begingroup$
By "binary", do you mean a string representation of the binary values, i.e. a string consisting of only 1's and 0's?
$endgroup$
– Rogem
Feb 4 at 18:38
1
$begingroup$
@mdahmoune Now that's already much better. The question remains how to represent something as UTF-8. Notice that Unicode representation is mainly based on the looks of a character (only occasionally on semantic meaning). What if no assigned Unicode glyph looks like a character in the source code? Unicode also has many look-alikes (homoglyphs). How does one decide which one to use? E.g. Dyalog APL has an AND function which may be encoded as
01011110
or0010011100100010
in UTF-8 (they look pretty alike:^
vs∧
)$endgroup$
– Adám
Feb 4 at 19:44
1
$begingroup$
Better example:
01111100
and0010001100100010
encode|
and∣
.$endgroup$
– Adám
Feb 4 at 19:51
4
$begingroup$
@Adám I think it would be fair to output any binary sequence that corresponds to a symbol that will compile/run in a certain implementation of a language.
$endgroup$
– qwr
Feb 4 at 20:09
1
$begingroup$
How about machine code? (Commodore C64 takes 28 bytes assuming the machine code itself is the "source")
$endgroup$
– Martin Rosenau
Feb 4 at 21:18