236
\$\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\$
3
  • 6
    \$\begingroup\$ Do you not mean, "Golf you a quine for greater good!"? \$\endgroup\$ May 3, 2011 at 2:49
  • 64
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ May 3, 2011 at 2:52
  • 23
    \$\begingroup\$ Did anybody notice that this is question 69? \$\endgroup\$
    – aidan0626
    Oct 24, 2020 at 22:47

430 Answers 430

1
7 8
9
10 11
15
3
\$\begingroup\$

Pari/GP, 28 bytes

(()->print1("("self")()"))()

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Zsh, 40 bytes

s='s=\47%s\47;printf $s $s';printf $s $s

Try it online!

Until recently, this was the shortest universally trivially modifiable quine. Uses no external commands (printf is a builtin).

(Lesson learnt: don't describe your answer as the shortest possible.)

\$\endgroup\$
3
\$\begingroup\$

Joy, 32 bytes

[put "x." putchars 10 putch] x.

Try it online!

Joy is a stack-based language. It has an interesting operation, x, which means executing a block without popping it. So [P] x is equivalent to [P] P. This is useful for writing quines.

\$\endgroup\$
4
  • \$\begingroup\$ The second time I've seen Joy, after the appearance in your article about Esolangs. \$\endgroup\$ Apr 15, 2022 at 5:23
  • 1
    \$\begingroup\$ Let's see some DipDup answers too! \$\endgroup\$ Apr 15, 2022 at 5:26
  • \$\begingroup\$ As a sidenote, are you still in the CGoL community? \$\endgroup\$ Apr 15, 2022 at 5:27
  • 1
    \$\begingroup\$ @null I'm not active in the forum, just occasionally search the word "rlifesrc" to see if anyone has found a bug. \$\endgroup\$
    – alephalpha
    Apr 15, 2022 at 5:44
3
\$\begingroup\$

Pyxplot 0.8.4, 62 bytes

q="'";Q='"';s='pr"q=",Q,q,Q,";Q=",q,Q,q,";s=",q,s,q,";@s"';@s

This quine makes use of the macro expansion operator @ to execute the code stored in the string s. Both quote characters have to be extracted to variables because there is no way to get one without the other (not counting backslash escapes, which don't help here).

Fun fact: replace pr with print and @s with eval s and you have a not-so-golfy Ruby quine.

\$\endgroup\$
3
\$\begingroup\$

Fig, \$14\log_{256}(96)\approx\$ 11.524 bytes

"
h+C34"
h+C34

Try it online!

\$\endgroup\$
0
3
\$\begingroup\$

pl – Perl One-Liner Magic Wand, 22 bytes

Very late to the party, just for fun. This decades old Perl wrapper, was only released into the wild when Corona went viral.

The 3rd quine in the blog is the actual golf. Of interest here is the 2nd 1-letter alias variant. It's essentially the same as the Perl one, which it beats by 6 bytes. As on many examples on that page, hover the ▶ button, or the blue code box, to see the result.

&f(qw(&f(qw(%s)x2))x2)
\$\endgroup\$
4
  • \$\begingroup\$ Welcome to the site and nice first answer! The "default" online interpreter we use on this site, Try It Online!, has pl listed, so I've edited your answer slightly so it's closer to our standard format. Please, feel free to check out our main questions page for more challenges you can attempt! \$\endgroup\$ Oct 15, 2020 at 21:00
  • \$\begingroup\$ @caird-coinheringaahing Thanks, but that's a different pl. It implements some weird undocumented highly specialized language. It has nothing to do with Perl, other than being implemented in it. It's a total coincidence that it spews out my quine ;-) \$\endgroup\$
    – Daniel
    Oct 15, 2020 at 21:09
  • \$\begingroup\$ Huh, a very weird coincidence. My mistake, I've rolled back my edit \$\endgroup\$ Oct 15, 2020 at 21:10
  • \$\begingroup\$ @caird-coinheringaahing Actually not such a weird coincidence. Apart from the few (code golf only?) tasks that other pl language is capable of performing, everything you throw at it seems to be a quine. Like calling cat a language. \$\endgroup\$
    – Daniel
    Oct 16, 2020 at 21:49
3
\$\begingroup\$

Functional(), 904 880 846 768 716 692 684 662 605 602 bytes

),$,$$,($(8,( $(($(<,$(,,,)),($(4,$(9,,)),($(9,$(,,0,,)),($(0,$()),$ 4)(((0,9,,$)(((,)(( $(($($$,( 9((()(9($ <($ 4(8(, 4))))))$$),, $))(( $(,(,$),,(),, 9,, 0,, $,, 4,,(,())))))),(()($$())(8(9(9(8(4(4(8(9(8(8(<(9(9(9(9(9(9(9(8(<(8(<(<(4($,0(<(<(4(0(<(<(0($,0(<(<(9($,0(<(<(9(8(<(<(9(4(<(8(<(8(4(0(8(8(9(9(4(0(<(<(9(4(4(9(9(9(9(9(9(4($,0(<(8(8($,8(4($,0(4(8(<($,0(4(8(9($,8(9(8(8(8(9($,0(8(<(4(4(8(4(8(8(4(0(8(8(9(<(8(8(8(9(4(<(<(9($,<(0($,8(8(8(9(4($,0(4(<(9(9(8(4(<(0($,8(4(8(<(9(9(<(<(0($,<(<(8(4(<(9($,8(4(8(<(9(9(<(<(9($,8(4(<(4($,8(4(8(<(9(9(<(<(<(8(4(<(<($,8(4(8(8(4(0(8(<(8($,8(4(8(<(4(4(<(4(<(9(

Try it online!
Try the 605B version online!
Try the 662B version online!
Try the 684B version online!
Try the 692B version online!
Try the 716B version online!
Try the 768B version online!
Try the 846B version online!
Try the 880B version online!
Try the 904B version online!

This code comes from a generator code below;

),1,P,
:(h,
  & 1(
    :(l,1(>,>)),
    :(d,1(i,>)),
    :(i,1(>,`,>)),
    :(`,1()),
    1 d
  )(
    &(`,i,X)(
      &(>)(
        & 1(
          :(P,
            & i(
              &()(
                i(1 l(1 d(h(> d))))
              )
            )P
          ),
          > 1
        )
      )(
        & 1(
          >(X),>(),> i,> `,> 1,> d,>(>())
        )
      )
    )
  )
),
&()(
  P()
)(

h(i(
  i(h(d(d(
h(i(h(h(
l(i(
  i(
    i(
      i(
        i(
          i(i(h(l(h(l(l(d(1,`(l(l(d(`(l(l(`(1,`(l(l(i(1,`(l(l(i(h(l(l(i(d(l(h(l(
        h(d(`(h(
      h(i(
        i(
          d(`(l(
          l(i(
            d(d(i(
              i(
                i(i(i(i(d(1,`(l(h(h(1,h(d(1,`(d(h(l(1,`(d(h(i(1,
              h(i(h(h(
            h(i(1,`(h(
          l(d(d(h(d(h(
        h(d(`(h(
      h(i(l(h(h(
    h(i(d(l(l(i(1,l(`(1,h(h(
  h(i(
    d(1,`(d(
    l(i(i(h(d(l(`(1,h(d(h(
    l(i(i(l(l(`(1,l(l(h(d(l(i(1,h(d(h(
    l(i(i(l(l(i(1,h(d(l(d(1,h(d(h(
    l(i(i(l(l(l(h(d(l(l(1,h(d(h(
  h(d(`(h(
l(h(1,h(d(h(
l(d(d(l(d(l(i(

Try the generator code online! ( Try the encoder script online!)
Try the 605B generator code online!
Try the 662B generator code online! ( Try the 662B encoder script online! )
Try the 684B generator code online!
Try the 692B generator code online!
Try the 716B generator code online!
Try the 768B generator code online! ( Try the 768B encoder script online! )
Try the 846B generator code online!
Try the 880B generator code online!
Try the 904B generator code online!

The core part of the code is encoded with `,d,h,i,l for space,1,(,),comma respectively. Other characters &,>,:,P,X are treated as (,comma,(1,11,,1

The actual characters in the quine code,

  • 1 is converted to $
  • `,d,h,i,l are converted to 0,4,8,9,<

The encoded string forms a long long call chain with encoding rules below;

  • Z -> z( e.g. 1 -> d(
  • z -> z(1, e.g. h -> h(1,
\$\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\$
2
  • 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, 2013 at 23:51
  • \$\begingroup\$ @Justin Technically, 12 bytes saving. \$\endgroup\$
    – driima
    Nov 1, 2016 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\$

Mathematica 17 19

ToString[#0][] & []
\$\endgroup\$
1
  • \$\begingroup\$ Why Community Wiki? \$\endgroup\$
    – MD XF
    Jun 12, 2017 at 23:47
2
\$\begingroup\$

Node.js REPL (22)

console.log(RegExp.$1)
\$\endgroup\$
2
  • \$\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, 2014 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\$ Jul 16, 2017 at 5:21
2
\$\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\$
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\$

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\$

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\$
0
2
\$\begingroup\$

Straw, 10 bytes (non-competing)

(:%>>):%>>
\$\endgroup\$
1
  • \$\begingroup\$ Link to language is dead. Also, why is this non-competing? \$\endgroup\$ Sep 18, 2020 at 1:35
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\$
4
  • \$\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, 2016 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\$ Oct 7, 2016 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\$ Oct 7, 2016 at 13:09
  • \$\begingroup\$ $MyInvocation.MyCommand.ScriptBlock is 2 bytes shorter but almost definitely cheating? \$\endgroup\$
    – colsw
    Feb 22, 2017 at 22:38
2
\$\begingroup\$

Common Lisp - 73 35

Thanks to reader variables written #n= and #n#, with n an integer, Lisp code can be self-referential. Also, the printing functions can emit such reader variables when told to handle circular structures. The WRITE function accepts a :circle parameter for that purpose. It also returns the value being printed, which means that we have to globally set *PRINT-CIRCLE* to T (the initial, standard value is NIL), otherwise the REPL would report a stack-overflow exception when printing that value. Initializing the variable takes a lot of bytes and so the shorter solution is to return another value:

#1=(PROGN (WRITE '#1# :CIRCLE T) T)
\$\endgroup\$
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\$

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
  • 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\$ Jul 30, 2017 at 2:33
2
\$\begingroup\$

D, 85 bytes

enum c=q{import std.stdio;void main(){write("enum c=q{"~c~"};mixin(c);");}};mixin(c);
\$\endgroup\$
0
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\$
3
  • \$\begingroup\$ Nice. Basically the same as mine but with > at the beginning. I like it \$\endgroup\$
    – Riley
    Jan 16, 2017 at 23:01
  • \$\begingroup\$ I hope you don't mind that I used that trick in my new version :) \$\endgroup\$
    – Riley
    Jan 16, 2017 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, 2017 at 23:25
2
\$\begingroup\$

AWK, 72 bytes

BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}

In 6 years nobody had written an AWK solution :(


This can be run from command-line as:

awk 'BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}'

or placed in a file, FILE and run as:

awk -f FILE

Note: no newline is printed so if storing in a file... the file shouldn't have an EOF in it... maybe? We can add an EOF by adding print statements but that adds 12 bytes. This happens to be my first ever quine. :) It took me a bit to figure out how to get the quotation marks, since I first wanted to use \" but I'd have to escape the \ and then escape that one... ASCII to the rescue :)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ After I posted this I was curious if there was an extant AWK quine example. Apparently so at nyx.net/~gthompso/self_awk.txt. Given that, I believe this might be the shortest possible AWK quine. \$\endgroup\$ Feb 23, 2017 at 21:07
  • 2
    \$\begingroup\$ No this isn't the shortest AWK quine ;) \$\endgroup\$
    – DialFrost
    Nov 12, 2022 at 2:25
2
\$\begingroup\$

k, 48 bytes

This is, of course, ignoring the trivial quines, such as () or 1.

{}`0:(`c$34)/{(x;x;())}"{}`0:(`c$34)/{(x;x;())}"

Try it out.

\$\endgroup\$
1
7 8
9
10 11
15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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