204
\$\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
  • 50
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ – Rafe Kettler May 3 '11 at 2:52

330 Answers 330

3
\$\begingroup\$

Fueue, 411 391 381 376 bytes

(5(2(7(1(8(0(0(4(0(2(5(2(4(9(9(0(4(9(0(2(4(2(8(2(1(6(9(0(6(2(9(5(9(5(9(0(1(1(4(0(3(2(3(1(3(1(9(1(8(1(1(1(0(1(4(0(1(2(3(1(3(1(7(1(6(1(9(0(4(9(9(5(8(2(4(9(9(0(4(9(4(9(1(6(9(0(4(9(1(0(1(6(4(9(9(5(4(9(9(0(4(9(4(9(1(6(9(0(4(9(6(2(9(5(9(0(3(1(3(1(4(9(1(1(0(2(6(1(3(1(3(1(0(2(4(2(9(0(4(9(6(2(1(6(4(9(1(6[10(:91(H49~)~48<]):[[)+$7--32+*$5--10)~[<~)~~])~!]~[~)~~])~:[)--~+40--48)~:]~]

Try it online!

See also Ørjan Johansen's answer.

Basic idea (outdated):

(7(1(9(5(1(1(8(0...                  Data.
[9!(91[+(H~)]57<33]                  Begin the second pass and end the program on second pass.
):[                                  Duplicate and evaluate the block.
    [)+$7--32+*$5--10)~[<~)~~])~!]   On the second pass, print b*10+a+32 for each two digits a, b.
    )()[~)~~]~:~<                    Copy a digit and evaluate the next line between copies.
    [)----40+--~)48~:~~]             Print "("+digit and duplicate and evaluate the whole block on the next digit.
]
\$\endgroup\$
3
\$\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\$
3
\$\begingroup\$

Perl 5, 35 bytes

$_=q(print qq(\$_=q($_);eval));eval

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Welcome! Please consider adding an explanation or a link to an online interpreter. Code-only answers tend to be automatically flagged as low-quality. \$\endgroup\$ – mbomb007 Sep 20 at 15:42
  • 1
    \$\begingroup\$ No problem. I didn't realize that tio.run has an area to copy/paste submission markdown for code golf. Very cool. \$\endgroup\$ – booshlinux Sep 20 at 15:45
3
\$\begingroup\$

Keg, 49 43 bytes

\^\(\\\\\,\:\&\^\&\^\,\)\^\#^(\\,:&^&^,)^#

Try it online!

(note the trailing newline...)

-6 bytes thanks to Jo King reminding me that comments exist

This is a horrible mess, and I'm sure it can be outgolfed easily by someone comfortable with Keg's stack, and/or once "/' stop erroring. The first two thirds simply push each character from the last third to the stack in order (such that the last character is on top), and then the last third:

^                   Reverses the stack (such that the first character is on top),
 (         )        then does the following for each item CURRENTLY on the stack:
  \\,               print a backslash,
     :              duplicate the top of the stack,
      &             pop it to the register,
       ^            flip the stack,
        &           push the register,
         ^          flip the stack again,
          ,         and pop and print the top of the stack;
            ^       finally reversing what's left on the stack
             #\n    and commenting out the trailing newline,
                    so the stack is then implicitly printed bottom first,
                    with a trailing newline.

Essentially, it prints the first two thirds while copying itself onto the bottom of the stack, then flips the copy to be implicitly printed.

\$\endgroup\$
  • \$\begingroup\$ Thanks, fixed now... wait no \$\endgroup\$ – Unrelated String Oct 1 at 5:15
  • \$\begingroup\$ Now it's fixed \$\endgroup\$ – Unrelated String Oct 1 at 5:44
3
+100
\$\begingroup\$

Whispers v2, 38 bytes

> "print('> %r\\n>> ⍎1'%a)"
>> ⍎1

Try it online!

Abuses the fact that there's an eval as Python command (), which I can use to turn it into an arbitrary Python program. But of course, as a less cheaty feeling quine, there's:

Whispers v2, 270 bytes

> [62, 62, 32, 34, 49, 34, 10, 62, 32, 34, 62, 32, 34, 10, 62, 62, 32, 51, 43, 50, 10, 62, 62, 32, 69, 97, 99, 104, 32, 54, 32, 49, 10, 62, 62, 32, 39, 82, 10, 62, 62, 32, 79, 117, 116, 112, 117, 116, 32, 52, 32, 53]
>> "1"
> "> "
>> 3+2
>> Each 6 1
>> 'R
>> Output 4 5

Try it online!

Which encodes the ordinal values of the rest of the program on the first line, then prints the list then the list converted to characters.

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

Java (229 Characters)

class Main{public static void main(String[]args){char q='"';String s="class Main{public static void main(String[]args){char q='%c';String s=%c%s%c;System.out.print(s.format(s,q,q,s,q));}}";System.out.print(s.format(s,q,q,s,q));}}
\$\endgroup\$
  • 4
    \$\begingroup\$ You can shorten it by naming your class a one character name (such as q for quine). Also, there is no need for main(String[]args), just do something like main(String[]a) (total savings: 6 chars) \$\endgroup\$ – Justin Dec 11 '13 at 23:51
  • \$\begingroup\$ @Justin Technically, 12 bytes saving. \$\endgroup\$ – driima Nov 1 '16 at 8:59
2
\$\begingroup\$

Haskell, 93 68 characters

s="\nmain=putStrLn$\"s=\"++show s++s"
main=putStrLn$"s="++show s++s
\$\endgroup\$
2
\$\begingroup\$

Bash, 67/51 chars

f () 
{ 
    printf "%s\n${!1} $1" "$(local -f ${!1})"
}
f FUNCNAME

And 51 chars:

trap -- 'printf "%s\n:" "$(trap -p DEBUG)"' DEBUG
:
\$\endgroup\$
2
\$\begingroup\$

Zozotez Lisp: 73

((\ (x) (c x (c (c (" ") (c x))))) (" (\ (x) (c x (c (c (" ") (c x)))))))

This requires one of the REPLs. For one bootstrap expression quine I need it to print: 81

((\ (x) (p (c x (c (c (" ") (c x)))))) (" (\ (x) (p (c x (c (c (" ") (c x))))))))

Extended BrainFuck: 68

This uses mostly Brainfuck code except for the store string procedure.

>~"~!<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]"<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]

A 94 byte version that uses more EBF features:

{c|"{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c"}{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c
\$\endgroup\$
2
\$\begingroup\$

Node.js REPL (22)

console.log(RegExp.$1)
\$\endgroup\$
  • \$\begingroup\$ ...this abuses the fact that (I guess) the Node REPL internally executes a regex on the received line? I want to upvote because of the cleverness, but on the other hand I don't want to since it relies on extracting its own source code as a string... \$\endgroup\$ – FireFly Aug 22 '14 at 15:38
  • \$\begingroup\$ You need to specify the Node version this works in, because running in 7.5.0, this prints a single newline. \$\endgroup\$ – Patrick Roberts Jul 16 '17 at 5:21
2
\$\begingroup\$

MATLAB, 95 characters

There might be shorter ones, but I'm happy that it works at all.

function d=g();d='gvodujpo!e>h)*<e>(<e>\e)2;29*.2-e-e)29;foe*.2^<';d=[d(1:18)-1,d,d(18:end)-1];

Cleaner approach, exact same length:

function d=g();d='function d=g();d=[d(1:17),39,d,39,d(15:end)];';d=[d(1:17),39,d,39,d(15:end)];
\$\endgroup\$
2
\$\begingroup\$

Python 2, 31 bytes

s="print's=%r;exec s'%s";exec s

It's 2 bytes longer than the shortest Python quine on this question, but it's much more useful, since you don't need to write everything twice.

For example, to print a program's own source code in sorted order, we can just do:

s="print''.join(sorted('s=%r;exec s'%s))";exec s

Another example by @feersum can be found here.

Notes

The reason the quine works is because of %r's behaviour. With normal strings, %r puts single quotes around the string, e.g.

>>> print "%r"%"abc"
'abc'

But if you have a single quotes inside the string, it uses double quotes instead:

>>> print "%r"%"'abc'"
"'abc'"

This does, however, mean that the quine has a bit of a problem if you want to use both types of quotes in the string.

\$\endgroup\$
  • \$\begingroup\$ Python appends a leading newline to the output, so you will have to add a newline at the end of your program (making your program 32 bytes, not 31). \$\endgroup\$ – MilkyWay90 May 4 at 17:30
2
\$\begingroup\$

Burlesque - 1 byte

Technically, this is a quine:

1

Technically, this is also a quine:

{1 2 3}

Pretty much any literal is a quine.

This is also a quine which doesn't use a simple literal:

,#Q2 SH ~- ",#Q" \/ .+ sh

The comma is not necessary if you launch burlesque in no-stdin mode.

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

AppleScript, 2 Bytes

1

It's a little cheaty, but it is following the restrictions of a quine. If we don't count the trailing newline, then this solution becomes 1 byte - 1.

Whenever AppleScript has a final executed line of code, it prints the result of the last operation (whatever it is) to the command line.

text

Any class name has the same effect.

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

DUP, 51 bytes

0"0.[34,0[$;$][,1+]#]$!%%!"0.[34,0[$;$][,1+]#]$!%%!

Try it here.

Well, DUP quines are possible, just really, really, long. I'll have to golf some more.

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

Python 2 and 3 - 32 bytes

s='s=%r;print(s%%s)';print(s%s)

From Ray Toal's Quine Page

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

reticular, 9 bytes

"'34'coo;

This captures the string '34'coo;, then wraps around. After that, the number 34 is pushed the stack, converted to a character with c, finally being outputted with o. The next o outputs the captured string, and ; terminates the program.

Other quines:

"'34'c~O;
"6@P2*c~O;
\$\endgroup\$
2
\$\begingroup\$

Jelly, 6 bytes

There are two proper and payload capable "built-in" quines of 6-bytes:

“ØV”ṘV - takes no input
“ØV”   - make the string “ØV”
    Ṙ  - print and yield left (prints “ØV”, yields “ØV”)
     V - eval Jelly code (the code ØV yields the string “ṘV”)
       - implicit return of the string “ṘV”, so the final output is “ØV”ṘV

and

“Øv”Ṙv - as above,  except:
         v evals with an input, which in this case is empty; and
         Øv yields “Ṙv”

A payload may be placed directly after the leading open quote in either.

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

Straw, 10 bytes (non-competing)

(:%>>):%>>
\$\endgroup\$
2
\$\begingroup\$

Y, 2 bytes

Try it here!

Up

This is two commands. U is a capture link, and begins quoting the code, and has a U at the beginning of the result. It wraps around, since there is no matching U, and captures the string Up. Then, p prints it, and we are done.

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

PowerShell, 41 37 Bytes:

function q{"function q{$function:q};q"};q

filter q{"filter q{$function:q};q"};q

Thanks to TimmyD for saving 4 bytes

\$\endgroup\$
  • \$\begingroup\$ What interpreter / compiler does this work in? In this interpreter, this submission doesn't work (it outputs function q{End: { "function q{$function:q};q" }};q). \$\endgroup\$ – Loovjo Oct 6 '16 at 18:00
  • \$\begingroup\$ @Loovjo Most online PowerShell interpreters use an open-source PoSH that's roughly equivalent to PowerShell v0.5 and lacking many features. The above works fine in an actual install on Windows. \$\endgroup\$ – AdmBorkBork Oct 7 '16 at 13:08
  • \$\begingroup\$ At least in v4 on Windows 8.1, you can shave a few bytes using filter as follows -- filter q{"filter q{$function:q};q"};q for 37. \$\endgroup\$ – AdmBorkBork Oct 7 '16 at 13:09
  • \$\begingroup\$ $MyInvocation.MyCommand.ScriptBlock is 2 bytes shorter but almost definitely cheating? \$\endgroup\$ – colsw Feb 22 '17 at 22:38
2
\$\begingroup\$

Cheddar, 56 bytes

Try this one online!

let q='let q=%s%s%s;print IO.sprintf(q,@"39,q,@"39)';print IO.sprintf(q,@"39,q,@"39)

See the explanation below, except mentally replace % with IO.sprintf.




Well darn. @ETHProductions came up with this solution before me..

This is the shortest I could come up with... Maybe some abuse of functional operators could help me.

let q='let q=%s;print q%@"39+q+@"39';print q%@"39+q+@"39

Try it online! You can guess what the output is.

This code can be divided into two parts: the string and the output. The string part:

let q='let q=%s;print q%@"39+q+@"39';

is simply a formatting template.

The output part:

;print q%@"39+q+@"39

formats the string. @"39 is char 39, or '.

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

Pushy, 9 bytes

95 34
_"

(non-competing as the language postdates the challenge)

Although writing functional programs in Pushy is sometimes difficult, the quine is relatively simple:

95   % Push 95 to the stack (ASCII code for _ )
34   % Push 34 to the stack (ASCII code for " )
_    % Print representation of the stack: 95 34
"    % Print stack converted to string: _"

Notice that, although Pushy ignores newlines, it is needed here because the default separator for printing is \n - and there needs to be a trailing newline, hence making it 9 bytes


Alternatively, an 11-byte solution that does not require a newline:

78 95 34N_"

Works similarly to the one above, but N sets the separator an empty string.

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

Java 8, 94 bytes

()->{String s="()->{String s=%c%s%1$c;System.out.printf(s,34,s);}";System.out.printf(s,34,s);}

This is a lambda expression which prints its own source code to STDOUT. It uses a similar tactic to other Java quines here, but the lambda really helps cut down bytes.

If we wanted to be really cheeky and cut down two bytes, we could declare the lambda as x->, where x is an empty string, as according to meta, "taking no input" means you can assume empty input, and in function submissions input is given as a parameter.

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

Python 3, 38 bytes

There are already a lot of Python quines, but as far as I can see this one hasn't been posted yet. Technically it is a statement that evaluates to a string representation of itself, but other submissions do similar things.

'.__repr__()[:-1]*2'.__repr__()[:-1]*2

This works in a similar way to many quines in 2D langauges with "edge-wrap", where "string mode" is entered, the whole program is pushed to the stack, then string mode is executed and the program runs, printing the string mode character (usually ") followed by the contents of the stack (i.e. the program's source) then exiting.

A breakdown of the statement is as follows:

'.__repr__()[:-1]*2'                   # A string containing the body of the program.
                                       # .__repr__()[:-1]*2
                    .__repr__()        # The same string, but enclosed in single quote marks.
                                       # '.__repr__()[:-1]*2'
                               [:-1]   # A splice that crops off the last character.
                                       # '.__repr__()[:-1]*2
                                    *2 # Repeat the string.
                                       # '.__repr__()[:-1]*2'.__repr__()[:-1]*2

The reason I have used .__repr__() instead of repr(string) is because the quine relies on code following and not preceding the string. This is also why this is a statement and not a program; the print() function requires code before the string, which is not possible with this quine layout.

As you may have noticed, there's a much golfier statement that evaluates to this statement:

"'.__repr__()[:-1]*2"*2

But this isn't a quine, because it doesn't evaluate to itself.

\$\endgroup\$
  • 1
    \$\begingroup\$ Unfortunately, I don't think this is valid, since it's an expression (and therefore a snippet) rather than a full program. \$\endgroup\$ – Esolanging Fruit Jul 30 '17 at 2:33
2
\$\begingroup\$

Threead, 101 bytes

>91>60>93>62>91>105>54>50>99>111>100>111>62>93>60>91>60>93>62>91>99>111>62>93[<]>[i62codo>]<[<]>[co>]

Try it online!

My first thought for writing a Threead quine was to store the entire data section as one large number, in order to get a good compression ratio. This doesn't work because a) % appears to be broken, and b) Threead doesn't support bignum arithmetic.

Instead, I wrote this solution, which works along the same lines as a brainfuck quine, storing the characters of the code section of the program as individual tape elements. Then we just have to scan the list once in order to print it as data, and again to print it as code.

Although Threead allows for three threads, and requires their use when performing binary operations, this style of quine uses only unary operations and thus there was no point in using more than one thread, so I just did everything inside the first.

Explanation

>91>60>…>62>93            ASCII character codes of the rest of the program
[<]>                      Return the pointer to the start of the data
[                         While the current data cell is nonzero:
 i62                        Place 62 (ASCII code of >) on a temporary tape cell
 co                         Output it as a character (i.e. >)
 d                          Delete the temporary tape cell
 o                          Output the current data element as an integer
>]                        then continue the loop with the next data cell
<[<]>                     Return the pointer to the start of the data
[                         While the current data cell is nonzero:
 co                         Output it as a character
>]                        then continue the loop with the next data cell
\$\endgroup\$
  • \$\begingroup\$ Nice. Basically the same as mine but with > at the beginning. I like it \$\endgroup\$ – Riley Jan 16 '17 at 23:01
  • \$\begingroup\$ I hope you don't mind that I used that trick in my new version :) \$\endgroup\$ – Riley Jan 16 '17 at 23:23
  • \$\begingroup\$ @Riley: That's OK, we're pretty much all cooperating to improve the quine at this point. \$\endgroup\$ – user62131 Jan 16 '17 at 23:25
2
\$\begingroup\$

Alice, 9 bytes

Credits to Sp3000 for the idea of including the !.

"!<@o&9h.

Try it online!

Explanation

This works much like quines in other Fungeoids with an unmatched " that wraps the entire code (except itself) in a string because the instruction pointer move cyclically through the code.

"!<@o&9h."   Push code points of the entire program except the " to the
             stack (irrelevant).
!            Store 46 (the code point of '.') on the tape (irrelevant).
<            Send IP back west.
!            Store 104 (the code point of 'h') on the tape (irrelevant).
".h9&o@<!"   Push code points of the entire program except the " to the
             stack in reverse.
.            Duplicate the 33 (the code point of '!').
h            Increment to 34 (the code point of '"').
             Now the top nine values on the stack correspond to the entire
             code in reverse order.
9&           Repeat the next command 9 times.
o            Print 9 characters from the top of the stack.
@            Terminate the program.
\$\endgroup\$
2
\$\begingroup\$

Ohm, 22 20 bytes

-2 bytes thanks to Business Cat

"D34'DLaJL"D34'DLaJL

Try it online!

"D34'DLaJL"          # Push this string (everything after this)
           D         # Duplicate
            34'      # Push the character "
               D     # Duplicate
                L    # Print "
                 a   # Swap the top 2 elements 
                  JL # Print the string, ", then the string again.
\$\endgroup\$
  • \$\begingroup\$ You can save 2 bytes by replacing LLL with JL (in both occurrences). \$\endgroup\$ – Business Cat May 18 '17 at 17:56
2
\$\begingroup\$

x86/DOS assembly, 4619 bytes

bits 16
org 256
mov ah,64
mov bx,1
mov cx,720
mov dx,b+16
int 33
mov cx,90
mov si,b+16
c:push cx
mov ah,64
mov bx,1
mov cx,6
mov dx,b
int 33
mov cx,7
a:push cx
mov al,[si]
shr al,4
add al,48
cmp al,58
jb g
add al,39
g:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb e
add al,39
e:mov [b+9],al
mov ah,64
mov bx,1
mov cx,5
mov dx,b+6
int 33
pop cx
loop a
mov al,[si]
shr al,4
add al,48
cmp al,58
jb h
add al,39
h:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb n
add al,39
n:mov [b+9],al
mov ah,64
mov bx,1
mov cx,4
mov dx,b+6
int 33
pop cx
loop c
mov ah,64
mov bx,1
mov cx,5
mov dx,b+11
int 33
mov ah,76
int 33
b   db 13,10,' db 0x  ,',13,10,'end'
 db 0x62,0x69,0x74,0x73,0x20,0x31,0x36,0x0d
 db 0x0a,0x6f,0x72,0x67,0x20,0x32,0x35,0x36
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
 db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x37,0x32
 db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64
 db 0x78,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
 db 0x69,0x6e,0x74,0x20,0x33,0x33,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x39
 db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x73
 db 0x69,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
 db 0x63,0x3a,0x70,0x75,0x73,0x68,0x20,0x63
 db 0x78,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
 db 0x68,0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f
 db 0x76,0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x36
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78
 db 0x2c,0x62,0x0d,0x0a,0x69,0x6e,0x74,0x20
 db 0x33,0x33,0x0d,0x0a,0x6d,0x6f,0x76,0x20
 db 0x63,0x78,0x2c,0x37,0x0d,0x0a,0x61,0x3a
 db 0x70,0x75,0x73,0x68,0x20,0x63,0x78,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x6c,0x2c
 db 0x5b,0x73,0x69,0x5d,0x0d,0x0a,0x73,0x68
 db 0x72,0x20,0x61,0x6c,0x2c,0x34,0x0d,0x0a
 db 0x61,0x64,0x64,0x20,0x61,0x6c,0x2c,0x34
 db 0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20,0x61
 db 0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a,0x62
 db 0x20,0x67,0x0d,0x0a,0x61,0x64,0x64,0x20
 db 0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a,0x67
 db 0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62,0x2b
 db 0x38,0x5d,0x2c,0x61,0x6c,0x0d,0x0a,0x6c
 db 0x6f,0x64,0x73,0x62,0x0d,0x0a,0x61,0x6e
 db 0x64,0x20,0x61,0x6c,0x2c,0x31,0x35,0x0d
 db 0x0a,0x61,0x64,0x64,0x20,0x61,0x6c,0x2c
 db 0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20
 db 0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a
 db 0x62,0x20,0x65,0x0d,0x0a,0x61,0x64,0x64
 db 0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a
 db 0x65,0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62
 db 0x2b,0x39,0x5d,0x2c,0x61,0x6c,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c,0x36
 db 0x34,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x62
 db 0x78,0x2c,0x31,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x63,0x78,0x2c,0x35,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x64,0x78,0x2c,0x62,0x2b
 db 0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20,0x33
 db 0x33,0x0d,0x0a,0x70,0x6f,0x70,0x20,0x63
 db 0x78,0x0d,0x0a,0x6c,0x6f,0x6f,0x70,0x20
 db 0x61,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
 db 0x6c,0x2c,0x5b,0x73,0x69,0x5d,0x0d,0x0a
 db 0x73,0x68,0x72,0x20,0x61,0x6c,0x2c,0x34
 db 0x0d,0x0a,0x61,0x64,0x64,0x20,0x61,0x6c
 db 0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70
 db 0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a
 db 0x6a,0x62,0x20,0x68,0x0d,0x0a,0x61,0x64
 db 0x64,0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d
 db 0x0a,0x68,0x3a,0x6d,0x6f,0x76,0x20,0x5b
 db 0x62,0x2b,0x38,0x5d,0x2c,0x61,0x6c,0x0d
 db 0x0a,0x6c,0x6f,0x64,0x73,0x62,0x0d,0x0a
 db 0x61,0x6e,0x64,0x20,0x61,0x6c,0x2c,0x31
 db 0x35,0x0d,0x0a,0x61,0x64,0x64,0x20,0x61
 db 0x6c,0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d
 db 0x70,0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d
 db 0x0a,0x6a,0x62,0x20,0x6e,0x0d,0x0a,0x61
 db 0x64,0x64,0x20,0x61,0x6c,0x2c,0x33,0x39
 db 0x0d,0x0a,0x6e,0x3a,0x6d,0x6f,0x76,0x20
 db 0x5b,0x62,0x2b,0x39,0x5d,0x2c,0x61,0x6c
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
 db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x34,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78,0x2c
 db 0x62,0x2b,0x36,0x0d,0x0a,0x69,0x6e,0x74
 db 0x20,0x33,0x33,0x0d,0x0a,0x70,0x6f,0x70
 db 0x20,0x63,0x78,0x0d,0x0a,0x6c,0x6f,0x6f
 db 0x70,0x20,0x63,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x61,0x68,0x2c,0x36,0x34,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x62,0x78,0x2c,0x31
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x63,0x78
 db 0x2c,0x35,0x0d,0x0a,0x6d,0x6f,0x76,0x20
 db 0x64,0x78,0x2c,0x62,0x2b,0x31,0x31,0x0d
 db 0x0a,0x69,0x6e,0x74,0x20,0x33,0x33,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c
 db 0x37,0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20
 db 0x33,0x33,0x0d,0x0a,0x62,0x20,0x20,0x20
 db 0x64,0x62,0x20,0x31,0x33,0x2c,0x31,0x30
 db 0x2c,0x27,0x20,0x64,0x62,0x20,0x30,0x78
 db 0x20,0x20,0x2c,0x27,0x2c,0x31,0x33,0x2c
 db 0x31,0x30,0x2c,0x27,0x65,0x6e,0x64,0x27
end
\$\endgroup\$
2
\$\begingroup\$

ACL2, 41 bytes

(let((q"(let((q~x0))(cw q q))"))(cw q q))
\$\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.