Golf you a quine for great good!

  • 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> 




    Do you not mean, *"Golf you a quine for greater good!"?*

    @muntoo it's a play on "Learn you a Haskell for Great Good".

    Did anybody notice that this is question 69?

  • Hexagony, side-length 17 16, 816 705 bytes



    180963109168843880558244491673953327577233938129339173058720504081484022549811402058271303887670710274969455065557883702369807148960608553223879503892017157337685576056512546932243594316638247597075423507937943819812664454190530214807032600083287129465751195839469777849740055584043374711363571711078781297231590606019313065042667406784753422844".".>[email protected]#.#.#.#.#.#.#.>.(...........................<.".......".".>./.4.Q.;.+.<.#.>...........................<.".....".".>.#.#.>.N.2.'.\.>.............=.=......._.<.".....".".>.>.;.'.=.:.\.>.......................<."...".".>.\.'.%.'.<.#.>..............._.....<."...".".>.#.#.>.<.#.>...............=.=.<.".".".>.#.\.'.R./.>.................<.".!.........../.>.


    Try it online!



    This is what it looks like unfolded:



                    1 8 0 9 6 3 1 0 9 1 6 8 8 4 3 8
    8 0 5 5 8 2 4 4 4 9 1 6 7 3 9 5 3
    3 2 7 5 7 7 2 3 3 9 3 8 1 2 9 3 3 9
    1 7 3 0 5 8 7 2 0 5 0 4 0 8 1 4 8 4 0
    2 2 5 4 9 8 1 1 4 0 2 0 5 8 2 7 1 3 0 3
    8 8 7 6 7 0 7 1 0 2 7 4 9 6 9 4 5 5 0 6 5
    5 5 7 8 8 3 7 0 2 3 6 9 8 0 7 1 4 8 9 6 0 6
    0 8 5 5 3 2 2 3 8 7 9 5 0 3 8 9 2 0 1 7 1 5 7
    3 3 7 6 8 5 5 7 6 0 5 6 5 1 2 5 4 6 9 3 2 2 4 3
    5 9 4 3 1 6 6 3 8 2 4 7 5 9 7 0 7 5 4 2 3 5 0 7 9
    3 7 9 4 3 8 1 9 8 1 2 6 6 4 4 5 4 1 9 0 5 3 0 2 1 4
    8 0 7 0 3 2 6 0 0 0 8 3 2 8 7 1 2 9 4 6 5 7 5 1 1 9 5
    8 3 9 4 6 9 7 7 7 8 4 9 7 4 0 0 5 5 5 8 4 0 4 3 3 7 4 7
    1 1 3 6 3 5 7 1 7 1 1 0 7 8 7 8 1 2 9 7 2 3 1 5 9 0 6 0 6
    0 1 9 3 1 3 0 6 5 0 4 2 6 6 7 4 0 6 7 8 4 7 5 3 4 2 2 8 4 4
    " . " . > . @ . # . # . # . # . # . # . # . > . ( . . . . . .
    . . . . . . . . . . . . . . . . . . . . . < . " . . . . . .
    . " . " . > . / . 4 . Q . ; . + . < . # . > . . . . . . .
    . . . . . . . . . . . . . . . . . . . . < . " . . . . .
    " . " . > . # . # . > . N . 2 . ' . \ . > . . . . . .
    . . . . . . . = . = . . . . . . . _ . < . " . . . .
    . " . " . > . > . ; . ' . = . : . \ . > . . . . .
    . . . . . . . . . . . . . . . . . . < . " . . .
    " . " . > . \ . ' . % . ' . < . # . > . . . .
    . . . . . . . . . . . _ . . . . . < . " . .
    . " . " . > . # . # . > . < . # . > . . .
    . . . . . . . . . . . . = . = . < . " .
    " . " . > . # . \ . ' . R . / . > . .
    . . . . . . . . . . . . . . . < . "
    . ! . . . . . . . . . . . / . > .
    . . . . . . . . . . . . . . . .


    Ah well, this was quite the emotional rollercoaster... I stopped counting the number of times I switched between "haha, this is madness" and "wait, if I do this it should actually be fairly doable". The constraints imposed on the code by Hexagony's layout rules were... severe.



    It might be possible to reduce the side-length by 1 or 2 without changing the general approach, but it's going to be tough (only the cells with # are currently unused and available for the decoder). At the moment I also have absolutely no ideas left for how a more efficient approach, but I'm sure one exists. I'll give this some thought over the next few days and maybe try to golf off one side-length, before I add an explanation and everything.



    Well at least, I've proven it's possible...



    Some CJam scripts for my own future reference:




    Dear pete what is this.

    How long did it take to make this?

    @AandN I've been playing around with concepts for a general "template" since yesterday now and then (that didn't involve any actual testing... just typing up some stuff on a 7x7 grid and seeing if it might work... I discarded probably half a dozen approaches already there). The actual coding then took this evening... maybe 3 hours, I'd say.

    Well, my guess of 23 was a bit off... :P

    @RikerW Hey, I'm not done yet! (That said, yes it was.)

    Are you done yet?

    @EasterlyIrk Ummm, not quite... I've got a couple of ideas, but I haven't found the motivation yet to sit down for another 3-hour Hexagony session to try them out. :P

    Words can't explain how astonished I am when seeing this in action with Esoteric IDE step by step... To whom may want to understand this, this Hexagon encodes the "decoder" part into an integer which is printed with `!` and then with a mirror `/` on the 2nd last line it enters the decoder to print the decoder code to complete the quine. This has a miraculous use of `<` and `>` which reads the multiline very big integer and built the area for storing the decoder. I'd really love to know what "dozens of approaches" are being considered?

    Explanation? ---

    I suggest you check "Biggest Irreducbile Hello World" and its Python answer - puts 10^10^97! to shame.

  • MySQL, 167 characters


    SELECT REPLACE(@v:='SELECT REPLACE(@v:=\'2\',1+1,REPLACE(REPLACE(@v,\'\\\\\',\'\\\\\\\\\'),\'\\\'\',\'\\\\\\\'\'));',1+1,REPLACE(REPLACE(@v,'\\','\\\\'),'\'','\\\''));

    That's right. :-)


    I really did write this one myself. It was originally posted at my site.


  • Brain-Flak, 9.8e580 1.3e562 9.3e516 12818 11024 4452 4332 4240 4200 4180 3852 3656 3616 3540 2485 + 3 = 2488 bytes


    Now fits in the observable universe!


    (())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(())(())(()())(())(())(())(()())(()()()())(())(()()()()())(()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(())(())(()())(())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(())(())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(()()())(())(()()())(())(())(())(()())(()()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(())(())(())(()()())(())(())(())(()())(())(()())(()()()())(())(())(()()()()())(()())(()())(())(()()())(())(())(())(())(()()())(()())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(()()()()())(())(()()())(())(())(()())(())(()()()()())(())(()()()()())(())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(())(()()()()())(())(())(())(()())(())(()()()()())(())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()()()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(())(()())(()()()())(())(())(()())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(()()())(())(())(()())(())(())(()()()()())(()()()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(()()()())(()()()())(()())([[]]){({}()<(([{}]())<{({}())<>(((((()()()()()){}){}){}())[()])<>{({}())<>{}({}(((()()()){}())){}{})<>{({}())<>({}(((()()()()()){})){}{}())<>{{}<>({}(((()()()()){}){}){})(<>)}}<>(({})[()()])<>}}{}<>({}(<()>)<><{({}<>)<>}<>>){({}<>)<>}{}(<>)<>{({}<>)<>}{}(((((((()()()()()){}){}){}))()))>){({}()<((({}[()])()))>)}{}<>{({}<>)<>}{}>)}{}<>{({}<>)<>}<>

    Try it online!




    Explanation


    This Quine works like most Quines in esoteric languages; it has two parts an encoder and a decoder. The encoder is all of the parentheses at the beginning and the decoder is the more complex part at the very end.


    A naive way of encoding the program would be to put the ASCII value of every character in the decoder to the stack. This is not a very good idea because Brain-Flak only uses 8 characters (()<>[]{}) so you end up paying quite a few bytes to encode very little information. A smarter idea, and the one used up until now is to assign each of the 8 braces to an much smaller number (1-8) and convert these to the ASCII values with our decoder. This is nice because it costs no more than 18 bytes to encode a character as opposed to the prior 252.


    However this program does neither. It relies on the fact that Brain-Flak programs are all balanced to encode the 8 braces with the numbers up to 5. It encodes them as follows.


    (       -> 2
    < -> 3
    [ -> 4
    { -> 5
    ),>,],} -> 1

    All the close braces are assigned 1 because we can use context to determine which of them we need to use in a particular scenario. This may sound like a daunting task for a Brain-Flak program, but it really is not. Take for example the following encodings with the open braces decoded and the close braces replaced with a .:


    (.
    ((..
    <([.{...

    Hopefully you can see that the algorithm is pretty simple, we read left to right, each time we encounter a open brace we push its close brace to an imaginary stack and when we encounter a . we pop the top value and put it in place of the .. This new encoding saves us an enormous number of bytes in the encoder while only losing us a handful of bytes on the decoder.


    Low level explanation


    Work in progress


    *Just made the largest single golf in the history of PPCG* Nope. **9.8e580** is still impressive though.

    ... very big golf ...

    I think you win for most bytes cut off

    @Dennis isn't this a larger golf? or is it invalid

    @ASCII-only That's only **2.1 × 10^7417**. The other one is **10^(5.2 × 10^152)**.

    @Dennis Ah. the complexity of the expression was confusing me >_>

    From 9.8 * 10 ^ 580 to 2000. Wow

    Did you manage to make any progress on the low level explanation?

    @MilkyWay90 I was writing a memory visualizer for this but kind of got bored of it. At this point I only have a hazy recollection of how this even works.

    @SriotchilismO'Zaic Okay, thanks!

  • GolfScript, 2 bytes



    1



    (note trailing newline) This pushes the number 1 onto the stack. At the end of the program, GolfScript prints out all items in the stack (with no spaces in between), then prints a newline.



    This is a true quine (as listed in the question), because it actually executes the code; it doesn't just "read the source file and print it" (unlike the PHP submission).






    For another example, here's a GolfScript program to print 12345678:



    9,(;



    1. 9: push 9 to the stack

    2. ,: consume the 9 as an argument, push the array [0 1 2 3 4 5 6 7 8] to the stack

    3. (: consume the array as an argument, push the array [1 2 3 4 5 6 7 8] and the item 0 to the stack

    4. ;: discard the top item of the stack



    The stack now contains the array [1 2 3 4 5 6 7 8]. This gets written to standard output with no spaces between the elements, followed by a newline.


    Or PowerShell, or PHP :-)

    You didn't go back in time and give the inventor the idea to invent GolfScript, did you?

    Technically, `1` is not a quine in GolfScript: it outputs `1\n`, where `\n` denotes a newline. However, the two-char program `1\n` _is_ a quine.

    The one-char program `\n` probably also is?

    No, Ilmari, even that is not a quine. A quine is not just a program which prints its own source, it has to have a specific structure to be a quine.

    @Pseudonym a quine is literally a program which prints its own source. I don't think there are any arbitrary restrictions on "structure".

    @Rokk When Hofstader coined the term, he was specifically thinking of Quine's paradox. "Self-replicating program" or "self-copying program" is the more general term.

    @Pseudonym I see, thanks for the explanation.

    @Pseudonym This program doesn't just print its own source. I've expanded with an explanation.

    @ChrisJester-Young I don't dispute that it's a real, non-cheating self-replicating program. I'm just saying it's not a quine, which is a certain kind of self-replicating program.

    I doubt this is allowed, because on what counts as a valid quine, it says one part of the script has to encode another.

    This program is self-referencing because the program directly says that the exact source string should be printed to the console. The content of the reference is identical to the complete source code before it gets printed out. Therefore this program is a cheating quine.

  • Hexagony, side length 11, 314 bytes



    164248894991581511673077637999211259627125600306858995725520485910920851569759793601722945695269172442124287874075294735023125483.....!/:;.........)%'=a':\....................\...................\..................\.................\................\...............\..............\[email protected]\$><>'?2='%.<\:;_;4Q


    Try it online!






    Note: Currently the shortest program is only 261 bytes long, using a similar technique.



    Older version:



    Hexagony, side length 11, 330 bytes



    362003511553420961423766261426252539048636523959468260999944549820033581478284471415809677091006384959302453627348235790194699306179..../:{;+'=1P'%'a{:..\.....................\...................\..................\.................\................\...............\..............\.............\!$><........\[email protected]>{?2'%<......:;;4Q/


    Try it online!



    Encoder: Try it online!



    The program is roughly equivalent to this Python code: Try it online!



    Unfolded code:



               3 6 2 0 0 3 5 1 1 5 5
    3 4 2 0 9 6 1 4 2 3 7 6
    6 2 6 1 4 2 6 2 5 2 5 3 9
    0 4 8 6 3 6 5 2 3 9 5 9 4 6
    8 2 6 0 9 9 9 9 4 4 5 4 9 8 2
    0 0 3 3 5 8 1 4 7 8 2 8 4 4 7 1
    4 1 5 8 0 9 6 7 7 0 9 1 0 0 6 3 8
    4 9 5 9 3 0 2 4 5 3 6 2 7 3 4 8 2 3
    5 7 9 0 1 9 4 6 9 9 3 0 6 1 7 9 . . .
    . / : { ; + ' = 1 P ' % ' a { : . . \ .
    . . . . . . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . . \
    . . . . . . . . . . . . . \
    ! $ > < . . . . . . . . \
    . . @ > { ? 2 ' % < . .
    . . . . : ; ; 4 Q / .


    Two .s takes 1 bit. Any other characters take 1 bit and a base-97 digit.



    Explanation





    Click at the images for larger size. Each explanation part has corresponding Python code to help understanding.



    Data part



    Instead of the complex structure used in some other answers (with <, " and some other things), I just let the IP pass through the lower half.



    Data



    First, the IP runs through a lot of numbers and no-op's (.) and mirrors (\). Each digit appends to the number in the memory, so in the end the memory value is equal to the number at the start of the program.



    mem = 362003511...99306179


    ! prints it,



    stdout.write(str(mem))


    and $ jumps through the next >.



    Starting from the <. If the memory value mem is falsy (<= 0, i.e., the condition mem > 0 is not satisfied), we have done printing the program, and should exit. The IP would follow the upper path.



    Exit



    (let the IP runs around the world for about 33 commands before hitting the @ (which terminates the program) because putting it anywhere else incurs some additional bytes)



    If it's true, we follow the lower path, get redirected a few times and execute some more commands before hitting another conditional.





    # Python                    # Hexagony
    # go to memory cell (a) # {
    a = 2 # ?2
    # go to memory cell (b) # '
    b = mem % a # %


    Now the memory looks like this:



    Mem1



    If the value is truthy:



    if b > 0:


    the following code is executed:





    # Python                    # Hexagony
    b = ord('Q') # Q
    b = b*10+4 # 4
    # Note: now b == ord('.')+256*3
    stdout.write(chr(b%256)) # ;
    stdout.write(chr(b%256)) # ;


    See detailed explanation of the Q4 at MartinEnder's HelloWorld Hexagony answer. In short, this code prints . twice.



    Originally I planned for this to print . once. When I came up with this (print . twice) and implement it, about 10 digits were saved.



    Then,



    b = mem // a                # :


    Here is a important fact I realized that saved me about 14 digits: You don't need to be at where you started.






    To understand what I'm saying, let's have a BF analogy. (skip this if you already understood)



    Given the code



    while a != 0:
    b, a = a * 2, 0
    a, b = b, 0
    print(a)


    Assuming we let a be the value of the current cell and b be the value of the right cell, a straightforward translation of this to BF is:



    [             # while a != 0:
    [->++<] # b, a = a * 2, 0
    >[-<+>] # a, b = b, 0
    <. # print(a)
    ]


    However, note that we don't need to be at the same position all the time during the program. We can let the value of a be whatever we are at the start of each iteration, then we have this code:



    [             # while a != 0:
    [->++<] # b, a = a * 2, 0
    # implicitly let (a) be at the position of (b) now
    . # print(a)
    ]


    which is several bytes shorter.






    Also, the corner wrapping behavior also saves me from having a \ mirror there - without it I would not be able to fit the digits (+2 digits for the \ itself and +2 digits for an unpaired . to the right of it, not to mention the flags)



    (details:




    • The IP enters the lower-left corner, heading left

    • It get warped to the right corner, still heads left

    • It encounters a \ which reflects it, now it heads right-up

    • It goes into the corner and get warped again to the lower-left corner



    )






    If the value (of the mod 2 operation above) is falsy (zero), then we follow this path:





    # Python                 # Hexagony   # Memory visualization after execution
    b = mem // a # : # click here
    base = ord('a') # 97 # a
    y = b % base # '%
    offset = 33 # P1
    z = y + offset # ='+
    stdout.write(chr(z)) # ; # click here
    mem = b // base # {: # click here




    I won't explain too detailed here, but the offset is actually not exactly 33, but is congruent to 33 mod 256. And chr has an implicit % 256.


    Man, that is a *lot* of no-ops

    I laughed at "To understand what I'm saying, let's have a [BrainFuck] analogy." Only on PPCG... :)

    I scrolled like 3 times to the top of the answer to upvote it, only to find out that I did it already...

    Just had another look at this: have you tried avoiding `{` so you can lower the base from `a` down to `A` (naively by doing `='=` but some restructuring might be able to save on some `=` there)? That could shorten the data part significantly.

    @MartinEnder https://tio.run/##[email protected]/wD2LgwVTLDC1198A5QuiChKbEfHXvxyeH96fnv9mGdEaqFhHs1bI3VjNBQS1irS2UQD0aIRa4ioiDAmmyW2aMlYhWONEXLTlERlMcnCnJmK4ZLcUFWZSFFc[email protected]0SH5TUfkDx2QR/q//KVwBudwA1d/yhPa/@[email protected]/gQ" target="_blank">Failed? :( (originally the number is 132 digits long, when base is changed to `A` and the code is unchanged it's 124 bytes long, but each extra character or unpaired `.` adds 2 digits, so the added amount must be < 4 bytes to be useful)

    @user202729 Can't you move the code on the last line one cell right to avoid two unpaired `.`?

    @MartinEnder I overlooked that. / On another note, combining that idea with changing the offset to 1 gives this, which saves 7 digits in the data part.

    Decoder in side length 10 hexagon. Unfortunately the data is 9 digits longer than the maximum possible.

    Are you sure the bottom branch of that decoder works?

    @MartinEnder not really, but fixing it will make the data longer, not shorter...

    @MartinEnder I saved 10 bytes with the no-{ idea anyway.

    310 bytes by taking advantage of the new space from shortening the number

    308 bytes by taking out even more space

  • Prelude, 5157 4514 2348 1761 1537 664 569 535 423 241 214 184 178 175 169 148 142 136 133 bytes



    Thanks to Sp3000 for saving 3 bytes.



    This is rather long... (okay, it's still long ... at least it's beating the shortest known Brainfuck C# quine on this challenge now) but it's the first quine I discovered myself (my Lua and Julia submissions are really just translations of standard quine techniques into other languages) and as far as I'm aware no one has written a quine in Prelude so far, so I'm actually quite proud of this. :)



    7( -^^^2+8+2-!( 6+ !
    ((#^#(1- )#)8(1-)8)#)4337435843475142584337433447514237963742423434123534455634423547524558455296969647344257)


    That large number of digits is just an encoding of the core code, which is why the quine is so long.



    The digits encoding the quine have been generated with this CJam script.



    This requires a standard-compliant interpreter, which prints characters (using the values as character codes). So if you're using the Python interpreter you'll need to set NUMERIC_OUTPUT = False.



    Explanation



    First, a few words about Prelude: each line in Prelude is a separate "voice" which manipulates its own stack. These stacks are initialised to an infinite number of 0s. The program is executed column by column, where all commands in the column are executed "simultaneously" based on the previous stack states. Digits are pushed onto the stack individually, so 42 will push a 4, then a 2. There's no way to push larger numbers directly, you'll have to add them up. Values can be copied from adjacent stacks with v and ^. Brainfuck-style loops can be introduced with parentheses. See the link in the headline for more information.



    Here is the basic idea of the quine: first we push loads of digits onto the stack which encode the core of the quine. Said core then takes those digits,decodes them to print itself and then prints the digits as they appear in the code (and the trailing )).



    This is slightly complicated by the fact that I had to split the core over multiple lines. Originally I had the encoding at the start, but then needed to pad the other lines with the same number of spaces. This is why the initial scores were all so large. Now I've put the encoding at the end, but this means that I first need to skip the core, then push the digits, and jump back to the start and do the printing.



    The Encoding



    Since the code only has two voices, and and adjacency is cyclic, ^ and v are synonymous. That's good because v has by far the largest character code, so avoiding it by always using ^ makes encoding simpler. Now all character codes are in the range 10 to 94, inclusive. This means I can encode each character with exactly two decimal digits. There is one problem though: some characters, notably the linefeed, have a zero in their decimal representation. That's a problem because zeroes aren't easily distinguishable from the bottom of the stack. Luckily there's a simple fix to that: we offset the character codes by 2, so we have a range from 12 to 96, inclusive, that still comfortably fits in two decimal digits. Now of all the characters that can appear in the Prelude program, only 0 has a 0 in its representation (50), but we really don't need 0 at all. So that's the encoding I'm using, pushing each digit individually.



    However, since we're working with a stack, the representations are pushed in reverse. So if you look at the end of the encoding:



    ...9647344257


    Split into pairs and reverse, then subtract two, and then look up the character codes:



    57 42 34 47 96
    55 40 32 45 94
    7 ( - ^


    where 32 is corresponds to spaces. The core does exactly this transformation, and then prints the characters.



    The Core



    So let's look at how these numbers are actually processed. First, it's important to note that matching parentheses don't have to be on the same line in Prelude. There can only be one parenthesis per column, so there is no ambiguity in which parentheses belong together. In particular, the vertical position of the closing parenthesis is always irrelevant - the stack which is checked to determine whether the loop terminates (or is skipped entirely) will always be the one which has the (.



    We want to run the code exactly twice - the first time, we skip the core and push all the numbers at the end, the second time we run the core. In fact, after we've run the core, we'll push all those numbers again, but since the loop terminates afterwards, this is irrelevant. This gives the following skeleton:



    7(
    ( )43... encoding ...57)


    First, we push a 7 onto the first voice - if we don't do this, we'd never enter the loop (for the skeleton it's only important that this is non-zero... why it's specifically 7 we'll see later). Then we enter the main loop. Now, the second voice contains another loop. On the first pass, this loop will be skipped because the second stack is empty/contains only 0s. So we jump straight to the encoding and push all those digits onto the stack. The 7 we pushed onto the first stack is still there, so the loop repeats.



    This time, there is also a 7 on the second stack, so we do enter loop on the second voice. The loop on the second voice is designed such that the stack is empty again at the end, so it only runs once. It will also deplete the first stack... So when we leave the loop on the second voice, we push all the digits again, but now the 7 on the first stack has been discarded, so the main loop ends and the program terminates.



    Next, let's look at the first loop in the actual core. Doing things simultaneously with a ( or ) is quite interesting. I've marked the loop body here with =:



    -^^^2+8+2-!
    (#^#(1- )#)
    ==========


    That means the column containing ( is not considered part of the loop (the characters there are only executed once, and even if the loop is skipped). But the column containing the ) is part of the loop and is ran once on each iteration.



    So we start with a single -, which turns the 7 on the first stack into a -7... again, more on that later. As for the actual loop...



    The loop continues while the stack of digits hasn't been emptied. It processes two digits at a time,. The purpose of this loop is to decode the encoding, print the character, and at the same time shift the stack of digits to the first voice. So this part first:



    ^^^
    #^#


    The first column moves the 1-digit over to the first voice. The second column copies the 10-digit to the first voice while also copying the 1-digit back to the second voice. The third column moves that copy back to the first voice. That means the first voice now has the 1-digit twice and the 10-digit in between. The second voice has only another copy of the 10-digit. That means we can work with the values on the tops of the stacks and be sure there's two copies left on the first stack for later.



    Now we recover the character code from the two digits:



    2+8+2-!
    (1- )#


    The bottom is a small loop that just decrements the 10-digit to zero. For each iteration we want to add 10 to the top. Remember that the first 2 is not part of the loop, so the loop body is actually +8+2 which adds 10 (using the 2 pushed previously) and the pushes another 2. So when we're done with the loop, the first stack actually has the base-10 value and another 2. We subtract that 2 with - to account for the offset in the encoding and print the character with !. The # just discards the zero at the end of the bottom loop.



    Once this loop completes, the second stack is empty and the first stack holds all the digits in reverse order (and a -7 at the bottom). The rest is fairly simple:



    ( 6+ !
    8(1-)8)#


    This is the second loop of the core, which now prints back all the digits. To do so we need to 48 to each digit to get its correct character code. We do this with a simple loop that runs 8 times and adds 6 each time. The result is printed with ! and the 8 at the end is for the next iteration.



    So what about the -7? Yeah, 48 - 7 = 41 which is the character code of ). Magic!



    Finally, when we're done with that loop we discard the 8 we just pushed with # in order to ensure that we leave the outer loop on the second voice. We push all the digits again and the program terminates.


    Martin, you gotta stop somewhere.

    I love that this has over 5000 bytes golfed overall, plus an acknowledgement to Sp3000 for saving 3 of them.

    @KamilDrakari Those were the last 3 bytes though, so it's quite a big deal. ;)

  • Vim, 11 bytes



    q"iq"qP<Esc>hqP



    • iq"qP<Esc>: Manually insert a duplicate of the text that has to be outside the recording.

    • q" and hqP: Record the inside directly into the unnamed "" register, so it can be pasted in the middle. The h is the only repositioning required; if you put it inside the macro, it will be pasted into the result.



    Edit



    A note about recording with q": The unnamed register "" is a funny thing. It's not really a true register like the others, since text isn't stored there. It's actually a pointer to some other register (usually "- for deletes with no newline, "0 for yanks, or "1 for deletes with a newline). q" breaks the rules; it actually writes to "0. If your "" was already pointing to some register other than "0, q" will overwrite "0 but leave "" unchanged. When you start a fresh Vim, "" automatically points to "0, so you're fine in that case.



    Basically, Vim is weird and buggy.


    wait why doesn't this work for me

    @DestructibleWatermelon Can't say for sure, but one explanation is most likely. Probably should have had it in the write-up before, since it can throw people off. Read the edit.

    you should probably put something about how pressing `y` or something before running can help

    Why don't you use `␛` to show pressing the key? Part of this Unicode Block “Control Pictures”

    @mbomb007 The `` notation is standard in Vim mappings (`:help <>`) and that's what vimgolf.com uses. Any experienced vimgolfer will be used to reading it. As for the unicode, I have to squint to read the little letters, and they obscure the method of typing them and searching the help file.

    Can you explain more?

  • Javascript ES6 - 21 bytes



    $=_=>`$=${$};$()`;$()


    I call this quine "The Bling Quine."



    Sometimes, you gotta golf in style.


    Does `!$=_=>\`!$=${$}()\`()` save you 2 bytes?

    `Invalid assignment left hand side`. Wish it worked :(

    Does `!_=>\`!$=${$}()\`()` work ?

    Declaration of quine is missing. Nope.

    ``$=_=>eval(`$=${$};$()`);$()`` is a rather amusing quine to crash your browser.

    @PatrickRoberts `$=_=>eval\`$=${$};$()\`;$()` Two bytes off

    @TùxCräftîñg that won't work

    @TùxCräftîñg eliminating parentheses around template literals only works on native prototype functions, like `Array.prototype.join`.

    @MamaFunRoll TIL

    I love this one so much. I don't think it's quite correct, though - the REPL environments I run it in all enclose the output in quotes, and evaluating it with node.js doesn't output anything. Needs a `console.log` somewhere.

    Hmm, not sure. I wrote this over a year ago (it was considered valid then), and I haven't been following quine rule changes too closely. However, adding `alert` or `console.log` after the arrow function and wrapping the template string in parentheses would work.

    Also if You run this in the concole, it overwrites $ ( jQuery function ) on this site, and the upvote function won't work anymore. :)

    If this is a quine, `0` is too.

  • Cubix, 20 bytes



    [email protected]!<"OOw\o;/"


    Almost got the \o/...



    Net:



        3 4
    3 4
    Q u $ v @ ! < "
    O O w \ o ; / "
    . .
    . .


    Try it online



    Try it here!



    Additional notes



    Background story



    After being impressed by reading this great answer by @ais523, I started thinking about further golfing the quine. After all, there were quite a few no-ops in there, and that didn't feel very compressed. However, as the technique his answer (and mine as well) uses, requires the code to span full lines, a saving of at least 12 bytes was needed. There was one remark in his explanation that really got me thinking:




    On the subject of golfing down this quine further, [...] it'd need [...] some other way to represent the top face of the cube [...]




    Then, suddenly, as I stood up and walked away to get something to drink, it struck me: What if the program didn't use character codes, but rather numbers to represent the top face? This is especially short if the number we're printing has 2 digits. Cubix has 3 one-byte instructions for pushing double-digit numbers: N, S and Q, which push 10, 32 and 34 respectively, so this should be pretty golfy, I thought.



    The first complication with this idea is that the top face is now filled with useless numbers, so we can't use that anymore. The second complication is that the top face has a size which is the cube size squared, and it needed to have an even size, otherwise one number would also end up on the starting position of the instruction pointer, leading to a polluted stack. Because of these complications, my code needed to fit on a cube of size 2 (which can contain 'only' 24 bytes, so I had to golf off at least 21 bytes). Also, because the top and bottom faces are unusable, I only had 16 effective bytes.



    So I started by choosing the number that would become half of the top face. I started out with N (10), but that didn't quite work out because of the approach I was taking to print everything. Either way, I started anew and used S (32) for some reason. That did result in a proper quine, or so I thought. It all worked very well, but the quotes were missing. Then, it occured to me that the Q (34) would be really useful. After all, 34 is the character code of the double quote, which enables us to keep it on the stack, saving (2, in the layout I used then) precious bytes. After I changed the IP route a bit, all that was left was an excercise to fill in the blanks.



    How it works



    The code can be split up into 5 parts. I'll go over them one by one. Note that we are encoding the middle faces in reverse order because the stack model is first-in-last-out.



    Step 1: Printing the top face



    The irrelevant instructions have been replaced by no-ops (.). The IP starts the the third line, on the very left, pointing east. The stack is (obviously) empty.



        . .
    . .
    Q u . . . . . .
    O O . . . . . .
    . .
    . .


    The IP ends at the leftmost position on the fourth line, pointing west, about to wrap around to the rightmost position on that same line. The instructions executed are (without the control flow character):



    QOO
    Q # Push 34 (double quotes) to the stack
    OO # Output twice as number (the top face)


    The stack contains just 34, representlng the last character of the source.



    Step 2: Encode the fourth line



    This bit pretty much does what you expect it to do: encode the fourth line. The IP starts on the double quote at the end of that line, and goes west while pushing the character codes of every character it lands on until it finds a matching double quote. This matching double quote is also the last character on the fourth line, because the IP wraps again when it reaches the left edge.



    Effectively, the IP has moved one position to the left, and the stack now contains the representation of the fourth line in character codes and reverse order.



    Step 3: Push another quote



    We need to push another quote, and what better way than to recycle the Q at the start of the program by approaching it from the right? This has the added bonus that the IP directly runs into the quote that encodes the third line.



    Here's the net version for this step. Irrelevant intructions have been replaced by no-ops again, the no-ops that are executed have been replaced by hashtags (#) for illustration purposes and the IP starts at the last character on the fourth line.



        . .
    . .
    Q u $ . . . . .
    . . w \ . . / .
    . #
    . #


    The IP ends on the third line at the first instruction, about to wrap to the end of that line because it's pointing west. The following instructions (excluding control flow) are excecuted:



    $uQ
    $u # Don't do anthing
    Q # Push the double quote


    This double quote represents the one at the end of the third line.



    Step 4: Encoding the third line



    This works exactly the same as step 2, so please look there for an explanation.



    Step 5: Print the stack



    The stack now contains the fourth and third lines, in reverse order, so all we need to do now, it print it. The IP starts at the penultimate instruction on the third line, moving west. Here's the relevant part of the cube (again, irrelevant parts have been replaced by no-ops).



        . .
    . .
    . . . v @ ! < .
    . . . \ o ; / .
    . .
    . .


    This is a loop, as you might have seen/expected. The main body is:



    o;
    o # Print top of stack as character
    ; # Delete top of stack


    The loop ends if the top item is 0, which only happens when the stack is empty. If the loop ends, the @ is executed, ending the program.


    wish I could upvote this more

    Bounties are always welcome ;-)

  • Hexagony, side length 15 14 13 12, 616 533 456 383 bytes


    After several days of careful golfing, rearranging loops and starting over, I've finally managed to get it down to a side 12 hexagon.


    1845711724004994017660745324800783542810548755533855003470320302321248615173041097895645488030498537186418612923408209003405383437728326777573965676397524751468186829816614632962096935858"">./<$;-<.....>,.........==.........<"......."">'....>+'\.>.........==........<"......"">:>)<$=<..>..............$..<"...."">\'Q4;="/@>...............<"....."">P='%<.>.............<"..!'<.\=6,'/>

    Try it online!


    Unfolded:


                1 8 4 5 7 1 1 7 2 4 0 0
    4 9 9 4 0 1 7 6 6 0 7 4 5
    3 2 4 8 0 0 7 8 3 5 4 2 8 1
    0 5 4 8 7 5 5 5 3 3 8 5 5 0 0
    3 4 7 0 3 2 0 3 0 2 3 2 1 2 4 8
    6 1 5 1 7 3 0 4 1 0 9 7 8 9 5 6 4
    5 4 8 8 0 3 0 4 9 8 5 3 7 1 8 6 4 1
    8 6 1 2 9 2 3 4 0 8 2 0 9 0 0 3 4 0 5
    3 8 3 4 3 7 7 2 8 3 2 6 7 7 7 5 7 3 9 6
    5 6 7 6 3 9 7 5 2 4 7 5 1 4 6 8 1 8 6 8 2
    9 8 1 6 6 1 4 6 3 2 9 6 2 0 9 6 9 3 5 8 5 8
    " " > . / < $ ; - < . . . . . > , . . . . . .
    . . . = = . . . . . . . . . < " . . . . . .
    . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
    . " " > : > ) < $ = < . . > . . . . .
    . . . . . . . . . $ . . < " . . . .
    " " > \ ' Q 4 ; = " / @ > . . . .
    . . . . . . . . . . . < " . . .
    . . " " > P = ' % < . > . . .
    . . . . . . . . . . < " . .
    ! ' < . \ = 6 , ' / > . .
    . . . . . . . . . . . .

    While it doesn't look like the most golfed of Hexagony code, the type of encoding I used is optimised for longer runs of no-ops, which is something you would otherwise avoid.


    Explanation


    This beats the previous Hexagony answer by encoding the no-ops (.) in a different way. While that answer saves space by making every other character a ., mine encodes the number of no-ops. It also means the source doesn't have to be so restricted.


    Here I use a base 80 encoding, where numbers below 16 indicate runs of no-ops, and numbers between 16 and 79 represent the range 32 (!) to 95 (_) (I'm just now realising I golfed all the _s out of my code lol). Some Pythonic pseudocode:


    i = absurdly long number
    print(i)
    base = 80
    n = i%base
    while n:
    if n < 16:
    print("."*(16-n))
    else:
    print(ASCII(n+16))
    i = i//base
    n = i%base

    The number is encoded in the first half of the hexagon, with all the


    " " > 
    " " >
    ... etc

    on the left side and the


     > ,
    < "
    >
    < "
    ... etc

    on the right side redirecting the pointer to encode the number into one cell. This is taken from Martin Ender's answer (thanks), because I couldn't figure out a more efficient way.


    It then enters the bottom section through the ->:


           " " > \ ' Q 4 ; = " / @ > . . . .
    . . . . . . . . . . . < " . . .
    . . " " > P = ' % < . > . . .
    . . . . . . . . . . < " . .
    -> ! ' < . \ = 6 , ' / > . .

    ! prints the number and ' navigates to the right memory cell before starting the loop. P='% mods the current number by 80. If the result is 0, go up to the terminating @, else go down and create a cell next to the mod result with the value -16.


       . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
    . " " > : > ) < $ = < . . > . . . . .
    . . . . . . . . . $ . . < " . . . .
    " " > \ ' Q 4 ; = " / @ > . . . .
    /
    /

    Set the cell to (mod value + -16). If that value is negative, go up at the branching >+'\, otherwise go down.


    If the value is positive:


     " " > . / < $ ; - < . . . . . > , . . . . . .
    . . . = = . . . . . . . . . < " . . . . . .
    . " " > ' . . . . > + ' \ . > . . . . . .

    The pointer ends up at the ;-< which sets the cell to (mod value - -16) and print it.


    The the value is negative:


       . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
    . " " > : > ) < $ = < . . > . . . . .

    Go down to the > ) < section which starts the loop. Here it is isolated:


         . . > ) < $ = < . .
    . . . . . . . . .
    \ ' Q 4 ; = " /

    Which executes the code 'Q4;="= which prints a . (thanks again to Martin Ender, who wrote a program to find the letter-number combinations for characters) and moves back to the starting cell. It then increments ()) the mod value cell and loops again, until the mod value is positive.


    When that is done, it moves up and joins with the other section at:


     " " > . / < $ ; - < . . .
    \
    \

    The pointer then travels back to the start of the larger loop again


     " " > . / <--
    . . . = =
    . " " > '
    . . . = =
    . " " > :
    . . . . .
    " " > \ ' . .
    . . . . . . .
    . . " " > P = ' % < . > . . .

    This executes ='=:' which divides the current number by 80 and navigates to the correct cell.


    Old version (Side length 13)


    343492224739614249922260393321622160373961419962223434213460086222642247615159528192623434203460066247203920342162343419346017616112622045226041621962343418346002622192616220391962343417346001406218603959366061583947623434"">/':=<$;'<.....>(......................<"......"">....'...>=\..>.....................<"....."">....>)<.-...>...........==......<"...."">.."...'.../>.................<"..."">\Q4;3=/[email protected]>...............<".."".>c)='%<..>..!'<.\1*='/.\""

    Try it online!


    I can most definitely golf another side length off this, but I'll have to leave it til' tomorrow because it's getting late. Turns out I'm impatient and can't wait until tomorrow. Maybe another side can be golfed? :( ahhhhhhhhh i did it!


    I even golfed off a couple of extra digits with a base 77 encoding, but it doesn't really matter, since it has the same bytecount.


    This is amazing. The idea for this hybrid run-length encoding is really neat. :) Remind me to give you a bounty if I forget.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used