97
12
In this challenge, you should write a program or function which takes no input and prints or returns a string with the same number of bytes as the program itself. There are a few rules:
- You may only output bytes in the printable ASCII range (0x20 to 0x7E, inclusive), or newlines (0x0A or 0x0D).
- Your code must not be a quine, so the code and the output must differ in at least one byte.
- Your code must be at least one byte long.
- If your output contains trailing newlines, those are part of the byte count.
- If your code requires non-standard command-line flags, count them as usual (i.e. by adding the difference to a standard invocation of your language's implementation to the byte count), and the output's length must match your solution's score. E.g. if your program is
ab
and requires the non-standard flag-n
(we'll assume it can't be combined with standard flags, so it's 3 bytes), you should output 5 bytes in total. - The output doesn't always have to be the same, as long as you can show that every possible output satisfies the above requirements.
- Usual quine rules don't apply. You may read the source code or its size, but I doubt this will be shorter than hardcoding it in most languages.
You may write a program or a function and use any of the standard methods of providing output. Note that if you print the result, you may choose to print it either to the standard output or the standard error stream, but only one of them counts.
You may use any programming language, but note that these loopholes are forbidden by default.
This is code-golf, so the shortest valid answer – measured in bytes – wins.
Leaderboard
var QUESTION_ID=121056,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&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(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.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(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){var F=function(a){return a.lang.replace(/<\/?a.*?>/g,"").toLowerCase()},el=F(e),sl=F(s);return el>sl?1:el<sl?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;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="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
2Related. Related. – Martin Ender – 8 years ago
18"Your code must not be a quine" but... but... it's tagged [tag:quine] – Okx – 8 years ago
4@Okx Because it's a generalised quine, i.e. the required output depends on the source code. – Martin Ender – 8 years ago
@MartinEnder Can we use REPL languages? – Mr. Xcoder – 8 years ago
1
@Mr.Xcoder Yes, if you declare them as such.
– Martin Ender – 8 years agoNo tabs (0x09) allowed in output? – jaxad0127 – 8 years ago
1@DJMcMayhem I figured that in many esolangs it's trivial to print a null byte with one byte of code or similar things, and thought it would lead to more interesting answers if the results were actually readable. – Martin Ender – 8 years ago
@jaxad0127 In retrospect, I guess I could (or should) have allowed them, but now that there are already 70 answers, I don't want to make everyone go back and check if they can save bytes if I allow another character in the output. – Martin Ender – 8 years ago
About writing a function that takes no input, is it OK to produce a function that gives the right length when called with no inputs, even though it could be called with one or more inputs? – xnor – 8 years ago
@xnor sure, I guess. That's what all functions in some languages like JavaScript are like, aren't they? – Martin Ender – 8 years ago
@MartinEnder I was looking to submit Python's
bool
(with an extra space), which when called as justbool ()
on no inputs producesFalse
. Both have length 5. Would that be valid? – xnor – 8 years ago@xnor Neat idea, but functions need to return a string, not an object with a string representation of the required length. – Martin Ender – 8 years ago
4
@MartinEnder You should probably disallow output by exit code, which is a default. If you allow it nearly every one byte program in nearly every language is allowed. One user has already done this
– Post Rock Garf Hunter – 8 years ago2@WheatWizard output by exit code is not a string, so it doesn't apply here. – Martin Ender – 8 years ago
Was this question designed to mess with the heads of those people who get crazy high scores on questions by using languages which consist of all 0's and the file-length is the actual program? They could be printing a long time! – Cort Ammon – 8 years ago
@CortAmmon I don't see why this should be worse for them than an ordinary quine. – Ørjan Johansen – 8 years ago
Umm, when can we expect to see a winner declared? :3 – Koishore Roy – 8 years ago
1
@KoishoreRoy I don't accept answers for code golf. That just pins a (probably very uninteresting) 1-byte solution to the top. If anyone wants to see the overall winner, they can use the leaderboard (which actually shows 25 tied answers).
– Martin Ender – 8 years ago@MartinEnder thanks for clarifying :) – Koishore Roy – 8 years ago
I've changed [tag:quine] to [tag:self-referential] as per the new tag proposal on meta
– Jo King – 7 years ago