183
17
I think the question as above is clear, but just in case:
Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline.
Qualifying programs will be those whose output is longer (in bytes) than the source code of the program, measured in bytes (assuming ASCII or UTF-8 encoding for the program source code).
I.e. the code must be shorter than the number of digits in the resulting number.
Leading zeros are disallowed under all circumstances. Counting leading zeroes trivialises the problem; ignoring leading zeros unnecessarily complicates the question.
The winning program will be the qualifying program which prints the integer with the smallest magnitude.
Leaderboard snippet
var QUESTION_ID = 67921;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, 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: true, 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 = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); }
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*)(?:,|[-\u2013] ).*?([\d,^!e+]+)(?=\:?[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
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.replace(/<sup>([^\n<]*)<\/sup>/g, "^$1").replace(/\(\d+(?:\^\d+,)? [\w\s]+\)/g, "").replace(/floor\(10\^(\d+)\/9\)/g, "$1 ones").replace(/(\d+) ones/g, function (_, x) { return Array(+x + 1).join(1); }).match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2].replace(/,/g, "").replace(/(\d+)\s*\^\s*(\d+)/, function (_, a, b) { return Math.pow(a, b); }).replace(/(\d+)!/, function (_, n) { for (var i = 1, j = 1; i <= n; i++) j *= i; return j; }), language: match[1], link: a.share_link, }); else console.log(body); }); 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('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) 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); } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list"> <h2>Shortest Solution 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>{{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>
64
Number 1 on the Hot Network Questions. Not bad for a first question...
– trichoplax – 2015-12-28T15:15:58.930Are you saying
<=
the number or<
the number? From reading the question, I guess<
, but just in case. – JimBobOH – 2015-12-28T15:55:47.1076@Kslkgh Strictly less than, otherwise the question is trivial for programs which implicitly print their last value. – Arandur – 2015-12-28T15:57:24.293
2Too bad Forth doesn't have an exponentiation operator. 8 8 ^ . Seven bytes; would print an eight digit number—but it would take a lot of bytes to define ^ – WGroleau – 2015-12-28T16:14:30.420
In 7, an esolang I made up a while ago but never implemented, the empty program would print
7
. Of course, there's more reason to that than just "because I wanted it to", but it would be a little long to explain here... – ETHproductions – 2015-12-28T18:51:16.5637Is
1.0
an integer? – histocrat – 2015-12-28T20:05:13.157It's too late now, but future challenges like this might do well to ask for scores stated as log10(number) – Sparr – 2015-12-28T21:19:42.337
@WGroleau works fine in dc (see my answer below). – Aaron Davies – 2015-12-28T21:32:18.343
Integer? Bother. If it were floating-point, Commodore Basic:
1?π
– Mark – 2015-12-28T21:39:13.2932Every Hot Network Question was number 1 at one point :P @trichoplax – Zach Gates – 2015-12-29T01:58:30.183
25
The restriction to UTF-8 is ridiculous and detrimental. Bytes are bytes, no matter the encoding. I strongly recommend that you change the rules, as as they currently are they disallow languages that are not character-based (e.g. Minecraft, Piet, Folders) or have longer UTF-8 byte counts than their "real" (valid according to this question) byte counts (e.g. APL, TI-BASIC, Seriously, Jelly).
– lirtosiast – 2015-12-29T03:35:44.3837@ZachGates that's not how the HNQ list works. ;) – Martin Ender – 2015-12-29T08:38:03.347
@ZachGates Hot Network Questions is sorted by how many "arbitrary hotness points" a question is assigned. This means most questions never get to the top. This question reached over 200 hotness points at one point, keeping all other questions across the network off the number 1 spot. – trichoplax – 2015-12-29T14:12:44.340
4@trichoplax I saw it at 367 hotness points at one point, beating everything else I've ever seen (except "Hello, World!" and The Programming Language Quiz). – ETHproductions – 2015-12-29T20:32:19.307
I spent some time looking for a language that would somehow print "1" given the empty program. (Or "0", but I'm not sure that counts.) I couldn't find one, but perhaps it's out there? If anybody else knows a language, feel free to take the idea. – David Z – 2015-12-31T14:55:34.913
2@DavidZ See the Retina answer. – Martin Ender – 2016-01-01T16:36:34.427
@Martin ah, there it is. I guess it must have been buried near the bottom when I commented, or else I really really can't read :-P because I definitely didn't see it before. – David Z – 2016-01-01T17:52:19.047
This challenge is very clever in that basically any language can participate. IMHO, it should be a standard "first program" like "Hello, World!" and FizzBuzz. – ETHproductions – 2016-03-16T18:04:57.143
Ok, but why is the question body and the title inconsistent? – CalculatorFeline – 2016-04-07T23:27:48.797
1I like how this user gained all 766 rep from this one question... Nice question. – HyperNeutrino – 2017-01-17T02:17:20.190
That leaderboard snippet is very broken. – 12Me21 – 2017-10-19T15:28:41.560