201
\$\begingroup\$

Using your language of choice, golf a quine.

A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output.

No cheating -- that means that you can't just read the source file and print it. Also, in many languages, an empty file is also a quine: that isn't considered a legit quine either.

No error quines -- there is already a separate challenge for error quines.

Points for:

  • Smallest code (in bytes)
  • Most obfuscated/obscure solution
  • Using esoteric/obscure languages
  • Successfully using languages that are difficult to golf in

The following Stack Snippet can be used to get a quick view of the current score in each language, and thus to know which languages have existing answers and what sort of target you have to beat:

var QUESTION_ID=69;
var OVERRIDE_USER=98;

var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(index){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}
function commentUrl(index,answers){return"https://api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}
function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=!1;comment_page=1;getComments()}})}
function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}
getAnswers();var SCORE_REG=(function(){var headerTag=String.raw `h\d`
var score=String.raw `\-?\d+\.?\d*`
var normalText=String.raw `[^\n<>]*`
var strikethrough=String.raw `<s>${normalText}</s>|<strike>${normalText}</strike>|<del>${normalText}</del>`
var noDigitText=String.raw `[^\n\d<>]*`
var htmlTag=String.raw `<[^\n<>]+>`
return new RegExp(String.raw `<${headerTag}>`+String.raw `\s*([^\n,]*[^\s,]),.*?`+String.raw `(${score})`+String.raw `(?=`+String.raw `${noDigitText}`+String.raw `(?:(?:${strikethrough}|${htmlTag})${noDigitText})*`+String.raw `</${headerTag}>`+String.raw `)`)})();var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}
function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))
body='<h1>'+c.body.replace(OVERRIDE_REG,'')+'</h1>'});var match=body.match(SCORE_REG);if(match)
valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,})});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)
lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery('<i>'+a.language+'</i>').text().toLowerCase();languages[lang]=languages[lang]||{lang:a.language,user:a.user,size:a.size,link:a.link,uniq:lang}});var langs=[];for(var lang in languages)
if(languages.hasOwnProperty(lang))
langs.push(languages[lang]);langs.sort(function(a,b){if(a.uniq>b.uniq)return 1;if(a.uniq<b.uniq)return-1;return 0});for(var i=0;i<langs.length;++i)
{var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

\$\endgroup\$
  • 4
    \$\begingroup\$ Do you not mean, "Golf you a quine for greater good!"? \$\endgroup\$ – Mateen Ulhaq May 3 '11 at 2:49
  • 46
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ – Rafe Kettler May 3 '11 at 2:52

318 Answers 318

2
\$\begingroup\$

C (tcc), 64 bytes

main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}

Try it online!

could be one problem if compiler not use the stack based way of push arguments.
result of the print (tcc, gcc all in TIO today at last ok (not ok in clang)):

main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}
\$\endgroup\$
  • \$\begingroup\$ Related \$\endgroup\$ – No one Dec 23 '17 at 19:09
2
\$\begingroup\$

V, 4 bytes

2i2i

Try it online!

Marked as non-competing because this language postdates the challenge by several years.

Explanation:

2       " Two times:
 i      " Insert the following:
  2i    " The string '2i'

This is pretty straightforward. In fact, this almost works in regular vim. There is just one minor thing in the way: The string '2i' isn't inserted twice until you hit <esc>. In V, this is solved by implicitly ending every program with an <esc> (Really, that's an oversimplification, but it's close enough to the truth).

Old versions of V always added a newline to the output, which is why I didn't post this earlier. However, in commit b6c238d, this was fixed.

This answer works just because of luck. The approach doesn't extend well to general purpose quines/quine-variations. The shortest quine I'm aware of that can be trivially modified is

ñéÑ~"qpÿ

Try it online!

Explanation:

ñ           " Start recording into register 'q'
 éÑ         " Insert 'Ñ' (uppercase so that the recording doesn't stop here)
   ~        " Toggle the case the character under the cursor (the 'Ñ')
    "qp     " Paste the contents of register 'q'
       ÿ    " Stop recording and play it all back

The reason the ÿ is needed, is because it is implicitly added to the end of macros, a feature that is unfortunate for quines, but very convenient for golf.

The nice thing about this quine is that we can do almost anything inside of the recording and it is still valid since it will be pasted later anyway.

\$\endgroup\$
2
\$\begingroup\$

MaybeLater, 74 bytes

x="write(('x='+chr(34))+x+(chr(34))+x)"write(('x='+chr(34))+x+(chr(34))+x)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

ABAP, 515 bytes

REPORT R NO STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:
`REPORT.FORM F TABLES T.NEW-PAGE LINE-SIZE 78.WRITE:'REPORT R NO',` TO A,
`'STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:'.LOOP` TO A,
`AT T.REPLACE ALL OCCURENCES OF'``' IN T WITH'````'.WRITE:/'``'` TO A,
`NO-GAP,T NO-GAP,'`` TO A,'.ENDLOOP.WRITE:AT 78'.','GENERATE',` TO A,
`'SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.'.ENDFORM.` TO A.
GENERATE SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.

Should work on on any SAP system with SY-SAPRL >= '700'.

source

\$\endgroup\$
  • \$\begingroup\$ is this an error quine? \$\endgroup\$ – Destructible Lemon May 24 '17 at 23:53
  • \$\begingroup\$ @DestructibleLemon No, why do you ask? \$\endgroup\$ – MD XF May 25 '17 at 0:46
  • \$\begingroup\$ Anyone care to explain the serial downvoting? \$\endgroup\$ – MD XF May 25 '17 at 17:20
2
\$\begingroup\$

Java 8 - 392 bytes

interface Q{static void main(String[]a){p("interface Q{static void main(String[]a){p(");q(");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}

The main trick with this was using 34 cast to a character for the quotes that bound the string literals in order to not run into issues.

\$\endgroup\$
  • 3
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Steadybox Jan 9 '18 at 15:53
2
\$\begingroup\$

Wumpus, 9 bytes

"#34#9&o@

Try it online!

Explanation

This is a fairly standard Fungeoid quine. However, as opposed to most other Fungeoids, Wumpus's grid doesn't wrap around, so the IP actually bounces back and forth through the code:

"#34#9&o@o&9#32#"
     This pushes the individual code points of this string to the stack.
#34  Push 34.
#9   Push 9.
&o   Print 9 characters from the top of the stack.
@    Terminate the program.

There are several other ways to do this in 9 bytes, e.g. this one which generates the " from the # instead:

"#9[(~&o@

I haven't yet found a way to get it down to 8 bytes though (it might be possible: if there's a way to generate the 34 in three bytes that doesn't end in a digit, we could get rid of the # in front of the 9).

\$\endgroup\$
2
\$\begingroup\$

Rust, 108 characters

macro_rules!f(()=>("macro_rules!f(()=>({:?}));fn main(){{print!(f!(),f!())}}"));fn main(){print!(f!(),f!())}

This is a suboptimal solution, but it's so close to the current shortest solution that I wanted to post it anyway as it uses a completely different strategy. I think it can be optimized by using macro keyword instead of verbose macro_rules! when it becomes stable (which would reduce this to 96 characters).

\$\endgroup\$
2
\$\begingroup\$

Pari/GP, 29 bytes

(f=()->print1("(f="f")()"))()

Try it online!

\$\endgroup\$
2
\$\begingroup\$

SmileBASIC, 66 54 bytes

?MID$(("+CHR$(34))*3,19,54)?MID$(("+CHR$(34))*3,19,54)

This will work in most BASIC dialects.

\$\endgroup\$
2
\$\begingroup\$

Nim, 95 bytes

import strutils;let s="import strutils;let s=$#;echo s%s.repr[^49..^1]";echo s%s.repr[^49..^1]

Try it online!

After scrolling through the leaderboard snippet, I was surprised to see that Nim hasn't been represented here yet. So, let's fix it!

This follows the standard pattern of constructing and printing a string with a quoted representation of itself inserted in the middle. Unfortunately, Nim has a few features that make this golf-unfriendly:

  • String interpolation with % is not available unless you import strutils.
  • repr not only quotes strings, but also prepends them with a hex number (seemingly, memory address), like this: 0x40a6d0"my string". Therefore, we have to extract the right part.

Still, not so bad overall, as it is significantly shorter than the version currently posted at Rosetta Code, which actually doesn't even work without tweaks in recent versions of the language.

\$\endgroup\$
2
\$\begingroup\$

Gol><>, 6 5 bytes

sP#H"

Try it online!

Credit to Jo King.

How it works

sP#H"

s      +16
 P     +1
  #    Reverse direction
 P     +1
s      +16
    "  Start string literal
sP#H"  Push H, #, P, s and end string literal
   H   Print everything on the stack from the top, and halt
       The printed chars are s, P, #, H, 34 (")

Previous solution, 6 bytes

"r2ssH

Try it online!

How it works

"r2ssH  Push the string "r2ssH" to stack, "r" being at the bottom
"       Close the literal
 r      Reverse the stack
  2ss   Push 34 (")
     H  Print all content of the stack from top to bottom as chars, and halt

There were a couple of alternatives to consider:

  • S" prints the string right away (instead of pushing to stack), but then it gets harder to handle ".
  • `" is an alternative way to push 34 to the stack, but the string literal also treats `" as escaped " which is not desirable.
\$\endgroup\$
  • \$\begingroup\$ An interesting 8 byter using S" \$\endgroup\$ – Jo King Nov 28 '18 at 0:34
2
\$\begingroup\$

Cardinal, 10 bytes

",-#) %8-$

Try it online!

This should be a quine, except for a small bug in the interpreter which causes the ( command to throw an error. For completeness' sake, here's a version where a # is placed in the position the ( is accidentally calling. Note that the space is actually a NUL character. Bug is fixed, yay!

"% (#-,0-$ also works with just one pointer.

How It Works:

The % creates two pointers, going left and right (the ones going vertical don't matter). The right pointer is delayed by the 8 for three steps, which lets the left pointer execute ,-#) which changes the active value to #, decrements it and prints the ". Then the right pointer starts again, decrementing the active value to -1. $ sets the pointer location to 0,-1, which then runs " over the rest of the code, printing it.

\$\endgroup\$
  • 1
    \$\begingroup\$ You can download fixed and recompiled version (including source code) of the interpreter from my Github repo: github.com/m-lohmann/Cardinal. The original interpreter had several errors that needed fixing. \$\endgroup\$ – M L Jun 2 '18 at 0:08
  • \$\begingroup\$ I don't think your last edit worked properly, the URLs are identical. \$\endgroup\$ – Ørjan Johansen Sep 5 '18 at 18:11
  • \$\begingroup\$ @Orjan lol, it seems I had already made the exact change in a previous edit. \$\endgroup\$ – Jo King Sep 7 '18 at 13:30
2
\$\begingroup\$

J, 27 bytes

echo(,quote)'echo(,quote)'

Try it online!

It's surprising that there's no proper J quine submission yet.

How it works

echo(,quote)'echo(,quote)'
            'echo(,quote)'  The string `s`
      quote                 Wrap `s` with single quotes
     ,                      Concat s to the above; `(f g)x` is equal to `x f g x`
echo                        Explicitly print the result

echo is needed because the result of a non-REPL line is not printed.

\$\endgroup\$
2
\$\begingroup\$

Backhand, 21 bytes

"#v{<@^:[ba+0v|{$:o[}

Try it online!

This is my new 1D language Backhand. It's a little bit more complicated than the typical wrapping string literal quine.

Explanation:

The program initially starts with a step count of 3.

"      Start string literal, stepping 3 places at a time
       This pushes the source code, but all jumbled up :(

See my Hello, World! answer to see what you have to do to push a string normally.

"      End the garbage string literal
  v{   Step left and decrease the step count to 2
    <  Change direction to left
  v    Decrease the step count to 1
 #     No-op
"      Start string literal
       Now the step count is 1, so it actually pushes the source code
 #v{<@^:[ba+0v|{$:o[}    Push to stack going right and bounce off the end
 #v{<@^:[ba+0v|{$:o[     Push to stack going left
"      End string literal
  v    Decrease the step count to 0
  v    Decrease the step count to -1
       Now the pointer is technically going right, but with a step count of -1
"      Push the source code again...
  v    Decrease the step count to -2
    <  Change direction to left (step count is still negative, so it goes right)

      ^           Increase step count to -1
       :[         Dupe the top of stack (# 35) and decrement to 34 (")
         ba+      Add 10 and 11 to push 21 as the counter
            0     Push 0
             v    Decrease step count to -2
               {  Step left
              |   Pop 0 and continue moving left
                $ o    Swap the top two items and print the character
                   [}  Step right (against the wall so it bounces) and decrement the counter
              |{ :     Duplicate the counter and reflect if it is non-zero
                       Repeat this 21 times to print the source code
        [ a 0  Garbage
      ^        Increase the step counter to -1
     @         Terminate program
\$\endgroup\$
2
\$\begingroup\$

Elixir, 44 bytes

q=:'q=:~p;:io.format q,[q]';:io.format q,[q]

Try it online!

This is basically an existing quine taken from here, but I managed to save another 2 bytes by declaring q as an atom instead of a binary.

\$\endgroup\$
2
\$\begingroup\$

Clean, 123 102 bytes

module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="

Save as q.icl and compile with -b -nt.

Saved 21 bytes thanks to Οurous.

\$\endgroup\$
  • \$\begingroup\$ This can be improved to 102: module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s=" \$\endgroup\$ – Οurous Feb 13 at 7:09
  • \$\begingroup\$ @Οurous nice idea, thanks. \$\endgroup\$ – Keelan Feb 13 at 8:36
2
\$\begingroup\$

Golunar, 951 bytes (394.25 bytes as an integer value)

19370043316195921194914466480856680152267470323963447024756684537596068724128114478400203537500358028693578705195025299449504112473728653294217406768139954805008550643064305270958743186186490023003785512463398359429631224818444304976679217098389450981926661910005004089131207223929032173888419619738722341444212432611576207643452266161684471788295034889655803444137372629364500165719019777515305922257911642994836581634099155833200157295629218533465854143898419293035289733581625252699105530843807023973345521520887128012736565874423200184723012755626596238647926406709693583878890472621210970350861368171259284533764490596207310864352873729240842719608391238098412446205860013948766486129442046252306334230243913196704614648889659870117069927719874852423159076941049170045933025772364248625729725500550726133134993128102614696728457139079375133324957922066270555810085574853273966267981675757808791933974619299446035844180580831907739236954600685575

Golunar is the decimal representation of the number of zeros that a Unary code would need. It translates to this brainfuck code:

->+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>+[[>>+[>]+>++>+[<]<-]>>[>]<<-[<]<<+]+>+>-[>]++>++>++[[-<+]-<[-<[>++<-[>++<-[>++<-[>++<-[>--------<<[-]++>-[>++<-]]]]]]>[<+>-]+<<]>>[>>]<[>]<-[[-<+]-<<+>[>>]<[>]]<+]<[<<]>>[+++++++[<++++++>-]<.>>>]

Try it online!

I couldn't find an online Golunar interpreter, but you can use this Golunar to brainfuck converter to get the brainfuck code and then execute it.

This code is inspired by a brainfuck quine of Eric Bosman and Daniel B Cristofani. First it reads a list of bits that represent the bit-codes of the code part, then it builds up a list of bits that represent the ">" and "+" characters needed to print the first list. Those lists are merged and hold the binary value of the Golunar code. In the last step, the decimal value of the binary number are computed and printed.

[ 
tape: [decimal digits], value start marker/VS(-1)(starting cell), [input bits], between binary marker/BB(0), [binary output data]

input bits are 0 or 1, output bits are in reversed order and have the values 1(used) or 2(used and set)
input must be given in reversed order

decimal digits consist of two cells per value (value, digit used marker(DU)(1))

bit values:
> 000
< 001
+ 010
- 011
. 100
, 101
[ 110
] 111

]

-                       set VS

                    set input bits
>+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>
+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+
>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>
>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>
>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>
>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>
>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+
>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>
>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>

                    list rebuilding loop: append bits for "greater than" and plus symbols to the right of input data
+[                      for each input bit
  [                     while bit is greater than 0
    >>+                 copy bit to out data
    [>]+>++>+           append bits for plus (used markers plus 010)
    [<]<-               decrement in value
  ]
  >>[>]<<-              change most right character from plus to gt (010 to 000)
  [<]                   return to BB
  <<+                   repeat if not on VS
]
+>+>-                   prepare binary to decimal routine: set VS DU and first 1

[>]++>++>+              append bits for minus (011)

                    binary to decimal loop: use "double and add algorithm" to calculate the digits of the decimal value
+[                      if not on VS then
  [-<+]-                restore current bit value and go to VS
  <                     go to first DU
  [                 digit doubling loop
    -<                  remove DU and go to corresponding digit
    [
      >++<-             decrement current value and add 2 to temp value four times
      [
        >++<-
        [
          >++<-
          [
            >++<-
            [                   if value was greater than 4 then
              >---- ----        subtract 8 from temp
              <<[-]++           set next digit temp = 2 (DU plus 1)
              >-                decrement current digit
              [>++<-]           set temp = remaining value * 2
            ]
          ]
        ]
      ]
    ]
    >[<+>-]             set current digit = temp
    +                   set DU
    <<                  go to next digit
  ]                 end of digit doubling loop
  >>[>>]<[>]<           go to current bit
  -[                    if bit is 2 (used plus 1)
    [-<+]-              delete bit and go to VS
    <<+                 increment least significant digit
    >[>>]<[>]           go to current bit
  ]
  <+                    if not on VS then repeat  
]                   end of binary to decimal loop

<[<<]>                  go to most significant digit
>[                  printing loop: for each DU print corresponding value
  +++++++[<++++++>-]<.  add 48 to value (ASCII 0) and print
  >>>                   go to next DU
]
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 13 bytes

2096239D20BJ

Try it online!

Beats all the string-based 05AB1E quines.

Explanation:

2096239            # integer literal
       D           # duplicate
        20B        # convert the copy to base 20, yielding "D20BJ"
           J       # join with the original
\$\endgroup\$
1
\$\begingroup\$

Groovy:

`s='s=\\\';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*`2

Edit

Works in GroovyConsole

\$\endgroup\$
1
\$\begingroup\$

Ada, 274 258 257 Characters

with Text_IO;use Text_IO;procedure Q is M:Character:='"';T:String:="with Text_IO;use Text_IO;procedure Q is M:Character:=';T:String:=;begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;";begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;

pretty printed:

with Text_IO;
use Text_IO;
procedure Quine is
   M : Character := '"';
   T : String := "with Text_IO;use Text_IO;" &
     "procedure Q is M:Character:=';T:String:=;" &
     "begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;";
begin
   Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));
end Quine;

this program actually produces the short version (output can be redirected to q.adb).

\$\endgroup\$
1
\$\begingroup\$

C, 125 84 chars

main(){char*p="main(){char*p=%c%s%c,c='%c',s[256];sprintf(s,p,c,p,c,c);puts(s);}",c='"',s[256];sprintf(s,p,c,p,c,c);puts(s);}

It turns out that my idea was implemented much better:

main(){char*p="main(){char*p=%c%s%c;printf(p,34,p,34,10);}%c";printf(p,34,p,34,10);}
\$\endgroup\$
  • 1
    \$\begingroup\$ You could shave 9 chars off the shorter version by leaving out the trailing newline. \$\endgroup\$ – Ilmari Karonen Feb 3 '12 at 18:55
1
\$\begingroup\$

F♯# - 349 Characters

let s="\\\"\nnlet s=let z a b=s.Substring(a,b)System.Console.WriteLine()z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1" 
let z a b=s.Substring(a,b)
System.Console.WriteLine(z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1)

My first attempt at a quine - probably an easier (or shorter) way to do it, but not a bad first attempt I don't think

\$\endgroup\$
1
\$\begingroup\$

Tcl, 61 chars

set c {set c {$c};puts [subst -noc \$c]};puts [subst -noc $c]
\$\endgroup\$
1
\$\begingroup\$

Erlang escript 225 164 140

$ escript quine

main(_)->[A|B]=["main(_)->[A|B]=[","],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10])."],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10]).

$

Apparently escript has to have at least three lines.

\$\endgroup\$
1
\$\begingroup\$

Go - 583

Just because d;

package main
import "fmt"
func main(){
    a := string(byte(34))
    b := []string{
        "package main",
        "import fmt",
        "func main(){",
        "   a := string(byte(34))",
        "   b := []string{",
        "       ",
        "   }",
        "   for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}",
        "   for _,v:=range b{fmt.Println(b[6]+a+v+a+string(','))}",
        "   for i:=7;i<9;i++{fmt.Println(b[i])}",
        "}",
        }
    for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}
    for _,v:=range b{fmt.Println(b[5]+a+v+a+string(','))}
    for i:=7;i<11;i++{fmt.Println(b[i])}
}
\$\endgroup\$
  • \$\begingroup\$ this is awesome. \$\endgroup\$ – cat Dec 7 '15 at 14:50
1
\$\begingroup\$

Cobra - 143

class P
    def main
        s='class P{2}   def main{2}     s={1}{0}{1}{2}      Console.write(s,s,39to char,10to char)'
        Console.write(s,s,39to char,10to char)
\$\endgroup\$
1
\$\begingroup\$

Lua, 76 characters

s="s=%c%s%c;print(string.format(s,34,s,34))";print(string.format(s,34,s,34))

Another one with the usual format string technique.

\$\endgroup\$
1
\$\begingroup\$

Julia, 101 characters

s="s=%c%s%c;@printf %c%s%c 34 s 34 34 s 34";@printf "s=%c%s%c;@printf %c%s%c 34 s 34" 34 s 34 34 s 34

It's the usual format string technique, but unfortunately you can't get the format specification string from a variable in Julia, so I have to include it twice in the code, which blows everything up.

\$\endgroup\$
1
\$\begingroup\$

Minkolang 0.9, 10 bytes

This language was made after this challenge, but was not made for it.

"66*2-(O).

Like other 2D languages, the " makes everything between it and the next " a string. 66*2- adds the not-included " and (O). prints everything out and stops.

\$\endgroup\$
1
\$\begingroup\$

Scala, 84 bytes

val d="""
print("val d=\"\"\""+d+"\"\"\""+d)
"""
print("val d=\"\"\""+d+"\"\"\""+d)

Kinda straightforward, but putting it out there for completion.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.