问:
"Hello, World!"
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.

Furthermore, while all of <s>Wikipedia</s> (the Wikipedia entry has been deleted but there is a copy at archive.org
), esolangs and Rosetta Code have lists of "Hello, World!" programs, none of these are interested in having the shortest for each language (there is also this GitHub repository). If we want to be a significant site in the code golf community, I think we should try and create the ultimate catalogue of shortest "Hello, World!" programs (similar to how our basic quine challenge contains some of the shortest known quines in various languages). So let's do this!

The Rules

Each submission must be a full program.

The program must take no input, and print Hello, World! to STDOUT (this exact byte stream, including capitalization and punctuation) plus an optional trailing newline, and nothing else.

The program must not write anything to STDERR.

If anyone wants to abuse this by creating a language where the empty program prints Hello, World!, then congrats, they just paved the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

This is not about finding the language with the shortest "Hello, World!" program. This is about finding the shortest "Hello, World!" program in every language. Therefore, I will not mark any answer as "accepted".

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf - these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

For inspiration, check the Hello World Collection.

The Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](https://esolangs.org/wiki/Fish), 121 bytes
</code>```

/* Configuration */

var QUESTION_ID = 55422; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8478; // This should be the user ID of the challenge author.

/* App */

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) {
      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 = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\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 = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        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(''+lang+'').text();

    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, 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.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) 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);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  text-align: left !important;
  display: block !important;
}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 500px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=ffb5d0584c5f">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Title: "Hello, World!"

Body:
0815, <s>92</s> 80 bytes

<:48:~$<:65:~$<:6C:~$$><:6F:~$>@<:2C:~$<:20:~$<:57:~${~$<:72:~${~$<:64:~$<:21:~$


问:
The happy Ender problem
The happy ending problem (actually a theorem) states that

Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral.

The problem was so named by Paul Erdős when two mathematicians who first worked on the problem, Ester Klein and George Szekeres, became engaged and subsequently married.

Clarifications:

General position here means that no three points are collinear.

The quadrilateral formed by the four vertices will always be considered to be non-intersecting, irrespective of the order of the points. For example, given the four points [1 1], [1 2], [2 1], [2 2] the intended quadrilateral is the square, not the bow-tie:

A non-intersecting quadrilateral is convex if no interior angle exceeds 180 degrees; or equivalently if both diagonals lie inside the quadrilateral.

The challenge

Given 5 points with positive integer coordinates, output 4 of those points that form a convex quadrilateral.

Rules

If there are several solutions (that is, several sets of 4 points), you can consistently choose to output one of them or all.

Input and output formats are flexible as usual (arrays, lists, list of lists, strings with reasonable separators, etc).

Code golf, fewest bytes wins.

Test cases

Input:

```<code>[6 8] [1 10] [6 6] [5 9] [8 10]
</code>```

There is only one possible output:

```<code>[6 8] [1 10] [6 6] [5 9]
</code>```

Input:

```<code>[3 8] [7 5] [6 9] [7 8] [5 1]
</code>```

There are five solutions:

```<code>[3 8] [7 5] [6 9] [7 8]
[3 8] [7 5] [6 9] [5 1]
[3 8] [7 5] [7 8] [5 1]
[3 8] [6 9] [7 8] [5 1]
[7 5] [6 9] [7 8] [5 1]
</code>```

Input:

```<code>[4 8] [1 9] [9 9] [10 2] [1 6]
</code>```

There are three solutions:

```<code>[4 8] [1 9] [10 2] [1 6]
[4 8] [9 9] [10 2] [1 6]
[1 9] [9 9] [10 2] [1 6]
</code>```

To illustrate, here are the three solutions to this case:

答:
Mathematica <s>105</s> 96 bytes

Select[#~Subsets~{4},f@#&]& selects, from a list of (5) points, those subsets of 4 points that satisfy f.

f is satisfied when each point, of the 4 points in a set, lies on the RegionBoundary of the ConvexHull of the 4 points.

```<code>f@p_:=Apply[And,RegionBoundary@ConvexHullMesh@p~RegionMember~#&/@p];
Select[#~Subsets~{4},f@#&]&
</code>```

Test Cases

1. Let's look at at the 5 convex hulls of subsets (each of 4 points) of {{6, 8}, {1, 10}, {6, 6}, {5, 9}, {8, 10}}.

```<code>Select[#~Subsets~{4},f@#&[{{6, 8}, {1, 10}, {6, 6}, {5, 9}, {8, 10}}]
</code>```

{{{6, 8}, {1, 10}, {6, 6}, {5, 9}}}

{{6, 8}, {1, 10}, {6, 6}, {5, 9}}  is the only solution; each of the four points serves as a vertex of the convex hull (of the same 4 points).

{{6, 8}, {1, 10}, {6, 6},{8, 10}} is not a solution; the convex hull has only 3 vertices.  {6, 8} lies within the hull.

The remaining subsets also are not solutions:

2. {{4, 8}, {1, 9}, {9, 9}, {10, 2}, {1, 6}} has three solutions.

```<code>Select[#~Subsets~{4},f@#&[{{4, 8}, {1, 9}, {9, 9}, {10, 2}, {1, 6}}]
</code>```

{

{{4, 8}, {1, 9}, {10, 2}, {1, 6}},

{{4, 8}, {9, 9}, {10, 2}, {1, 6}},

{{1, 9}, {9, 9}, {10, 2}, {1, 6}}

}

3. {{3, 8}, {7, 5}, {6, 9}, {7, 8}, {5, 1}} has 5 solutions.

```<code>Select[#~Subsets~{4},f@#&[{{3, 8}, {7, 5}, {6, 9}, {7, 8}, {5, 1}}]
</code>```

{

{{3, 8}, {7, 5}, {6, 9}, {7, 8}},

{{3, 8}, {7, 5}, {6, 9}, {5, 1}},

{{3, 8}, {7, 5}, {7, 8}, {5, 1}},

{{3, 8}, {6, 9}, {7, 8}, {5, 1}},

{{7, 5}, {6, 9}, {7, 8}, {5, 1}}

}

Note that each of the five points lies on the boundary of the convex hull of all points.

If any one of the points is removed, the remaining 4 points will each be vertices of the reduced convex hull.

ContentLicense: CC BY-SA 3.0

Title: The happy Ender problem

Body:
Mathematica <s>105</s> 96 bytes

Select[#~Subsets~{4},f@#&]& selects, from a list of (5) points, those subsets of 4 points that satisfy f.

f is satisfied when each point, of the 4 points in a set, lies on the RegionBoundary of the ConvexHull of the 4 points.

f@p_:=Apply[And,RegionBoundary@ConvexHullMesh@p~RegionMember~#&/@p];
Select[#~Subsets~{4},f@#&]&

Test Cases

1. Let's look at at the 5 convex hulls of subsets (each of 4 points) of {{6, 8}, {1, 10}, {6, 6}, {5, 9}, {8, 10}}.

Select[#~Subsets~{4},f@#&[{{6, 8}, {1, 10}, {6, 6}, {5, 9}, {8, 10}}]

{{{6, 8}, {1, 10}, {6, 6}, {5, 9}}}

{{6, 8}, {1, 10}, {6, 6}, {5, 9}}  is the only solution; each of the four points serves as a vertex of the convex hull (of the same 4 points).

{{6, 8}, {1, 10}, {6, 6},{8, 10}} is not a solution; the convex hull has only 3 vertices.  {6, 8} lies within the hull.

The remaining subsets also are not solutions:

2. {{4, 8}, {1, 9}, {9, 9}, {10, 2}, {1, 6}} has three solutions.

Select[#~Subsets~{4},f@#&[{{4, 8}, {1, 9}, {9, 9}, {10, 2}, {1, 6}}]

{

{{4, 8}, {1, 9}, {10, 2}, {1, 6}},

{{4, 8}, {9, 9}, {10, 2}, {1, 6}},

{{1, 9}, {9, 9}, {10, 2}, {1, 6}}

}

3. {{3, 8}, {7, 5}, {6, 9}, {7, 8}, {5, 1}} has 5 solutions.

Select[#~Subsets~{4},f@#&[{{3, 8}, {7, 5}, {6, 9}, {7, 8}, {5, 1}}]

{

{{3, 8}, {7, 5}, {6, 9}, {7, 8}},

{{3, 8}, {7, 5}, {6, 9}, {5, 1}},

{{3, 8}, {7, 5}, {7, 8}, {5, 1}},

{{3, 8}, {6, 9}, {7, 8}, {5, 1}},

{{7, 5}, {6, 9}, {7, 8}, {5, 1}}

}

Note that each of the five points lies on the boundary of the convex hull of all points.

If any one of the points is removed, the remaining 4 points will each be vertices of the reduced convex hull.


答:
Javascript (ES6), <s>306</s> <s>293</s> 283 bytes

```<code>c=(v,w,x)=>(w[0]-v[0])*(w[1]-x[1])-(w[1]-v[1])*(w[0]-x[0])>0?1:0
i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])
j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}
f=(v)=>(r=[],k(...v),r)
</code>```

Explanation:

The function c computes the cross product of the vector between 3 adjacent points of the polygon and returns 1 if it is positive and 0 otherwise (note: the cross product cannot be zero as the points cannot be co-linear).

```<code>j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}
</code>```

The function k and j generate all cyclic permutations (ignoring reversing the order) of the input array.

```<code>i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])
</code>```

The function 'i' is then called for each cyclic permutation to calculate the sum of the function c for each of the 4 triplets of adjacent co-ordinates. If the cross products all have the same sign then they will all either be 0 or 1 and total to 0 (modulo 4) and the polygon is concave and is pushed into the output array. If any triplet has a different sign then the total will be non-zero (modulo 4) and the polygon is convex.

```<code>f=(v)=>(r=[],k(...v),r)
</code>```

The function f is used to initialise the output array and then call the above functions before returning the output.

Tests:

c=(v,w,x)=>(w[0]-v[0])*(w[1]-x[1])-(w[1]-v[1])*(w[0]-x[0])>0?1:0
i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])
j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}
f=(v)=>(r=[],k(...v),r)

tests = [
  [[6,8],[1,10],[6,6],[5,9],[8,10]],
  [[3,8],[7,5],[6,9],[7,8],[5,1]],
  [[4,8],[1,9],[9,9],[10,2],[1,6]]
];

tests.forEach(
  (test,i)=>{
    console.log( "Test " + (i+1) );
    f(test).forEach(
      (x)=>console.log( "  " + x.map((e)=>"("+e[0]+","+e[1]+")").join(','))
    );
  }
);```
</div>
</div>
</p>

<p><strong>Edit</strong>:</p>

<p>Can also handle co-linear points using the original version and changing the first two lines to:</p>

```t=(a,b,c)=>Math.sign((b[0]-a[0])*(b[1]-c[1])-(b[1]-a[1])*(b[0]-c[0]))
p=(a,b,c,d)=>[t(a,b,c),t(b,c,d),t(c,d,a),t(d,a,b)].filter(x=>x).reduce((p,c,i,a)=>p&c==a[0],1)
q=(a,m,n,o)=>[a[0],a[m],a[n],a[o]]
f=(a)=>{r=[];for(i=0;i<5;i++){b=a.slice();b.splice(i,1);r.push(q(b,1,2,3));r.push(q(b,1,3,2));r.push(q(b,2,1,3))}return r.filter((a)=>p(...a))}
```

However, since that case is specifically excluded in the question then the extra characters aren't necessary.

Title: The happy Ender problem

Body:
The happy ending problem (actually a theorem) states that

Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral.

The problem was so named by Paul Erdős when two mathematicians who first worked on the problem, Ester Klein and George Szekeres, became engaged and subsequently married.

Clarifications:

General position here means that no three points are collinear.

The quadrilateral formed by the four vertices will always be considered to be non-intersecting, irrespective of the order of the points. For example, given the four points [1 1], [1 2], [2 1], [2 2] the intended quadrilateral is the square, not the bow-tie:

A non-intersecting quadrilateral is convex if no interior angle exceeds 180 degrees; or equivalently if both diagonals lie inside the quadrilateral.

The challenge

Given 5 points with positive integer coordinates, output 4 of those points that form a convex quadrilateral.

Rules

If there are several solutions (that is, several sets of 4 points), you can consistently choose to output one of them or all.

Input and output formats are flexible as usual (arrays, lists, list of lists, strings with reasonable separators, etc).

Code golf, fewest bytes wins.

Test cases

Input:

```<code>[6 8] [1 10] [6 6] [5 9] [8 10]
</code>```

There is only one possible output:

```<code>[6 8] [1 10] [6 6] [5 9]
</code>```

Input:

```<code>[3 8] [7 5] [6 9] [7 8] [5 1]
</code>```

There are five solutions:

```<code>[3 8] [7 5] [6 9] [7 8]
[3 8] [7 5] [6 9] [5 1]
[3 8] [7 5] [7 8] [5 1]
[3 8] [6 9] [7 8] [5 1]
[7 5] [6 9] [7 8] [5 1]
</code>```

Input:

```<code>[4 8] [1 9] [9 9] [10 2] [1 6]
</code>```

There are three solutions:

```<code>[4 8] [1 9] [10 2] [1 6]
[4 8] [9 9] [10 2] [1 6]
[1 9] [9 9] [10 2] [1 6]
</code>```

To illustrate, here are the three solutions to this case:

Body:
Javascript (ES6), <s>306</s> <s>293</s> 283 bytes

c=(v,w,x)=>(w[0]-v[0])*(w[1]-x[1])-(w[1]-v[1])*(w[0]-x[0])>0?1:0
i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])
j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}
f=(v)=>(r=[],k(...v),r)

Explanation:

The function c computes the cross product of the vector between 3 adjacent points of the polygon and returns 1 if it is positive and 0 otherwise (note: the cross product cannot be zero as the points cannot be co-linear).

j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}

The function k and j generate all cyclic permutations (ignoring reversing the order) of the input array.

i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])

The function 'i' is then called for each cyclic permutation to calculate the sum of the function c for each of the 4 triplets of adjacent co-ordinates. If the cross products all have the same sign then they will all either be 0 or 1 and total to 0 (modulo 4) and the polygon is concave and is pushed into the output array. If any triplet has a different sign then the total will be non-zero (modulo 4) and the polygon is convex.

f=(v)=>(r=[],k(...v),r)

The function f is used to initialise the output array and then call the above functions before returning the output.

Tests:

c=(v,w,x)=>(w[0]-v[0])*(w[1]-x[1])-(w[1]-v[1])*(w[0]-x[0])>0?1:0
i=(v,w,x,y)=>(c(v,w,x)+c(w,x,y)+c(x,y,v)+c(y,v,w))%4==0&&r.push([v,w,x,y])
j=(v,w,x,y)=>{i(v,w,x,y);i(v,w,y,x);i(v,x,w,y)}
k=(v,w,x,y,z)=>{j(v,w,x,y);j(v,w,x,z);j(v,w,y,z);j(v,x,y,z);j(w,x,y,z)}
f=(v)=>(r=[],k(...v),r)

tests = [
  [[6,8],[1,10],[6,6],[5,9],[8,10]],
  [[3,8],[7,5],[6,9],[7,8],[5,1]],
  [[4,8],[1,9],[9,9],[10,2],[1,6]]
];

tests.forEach(
  (test,i)=>{
    console.log( "Test " + (i+1) );
    f(test).forEach(
      (x)=>console.log( "  " + x.map((e)=>"("+e[0]+","+e[1]+")").join(','))
    );
  }
);

Edit:

Can also handle co-linear points using the original version and changing the first two lines to:

t=(a,b,c)=>Math.sign((b[0]-a[0])*(b[1]-c[1])-(b[1]-a[1])*(b[0]-c[0]))
p=(a,b,c,d)=>[t(a,b,c),t(b,c,d),t(c,d,a),t(d,a,b)].filter(x=>x).reduce((p,c,i,a)=>p&c==a[0],1)
q=(a,m,n,o)=>[a[0],a[m],a[n],a[o]]
f=(a)=>{r=[];for(i=0;i<5;i++){b=a.slice();b.splice(i,1);r.push(q(b,1,2,3));r.push(q(b,1,3,2));r.push(q(b,2,1,3))}return r.filter((a)=>p(...a))}

However, since that case is specifically excluded in the question then the extra characters aren't necessary.


答:
ABCD, 366 bytes

```<code>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAADDAAADBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBDBBBBBBBBBBBBDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAADAAADBBBBBBDBBBBBBBBDBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBD
</code>```

Proof (note that I'm actually using the interpreter of ABCD)

ContentLicense: CC BY-SA 4.0

Title: "Hello, World!"

Body:
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.

Furthermore, while all of <s>Wikipedia</s> (the Wikipedia entry has been deleted but there is a copy at archive.org
), esolangs and Rosetta Code have lists of "Hello, World!" programs, none of these are interested in having the shortest for each language (there is also this GitHub repository). If we want to be a significant site in the code golf community, I think we should try and create the ultimate catalogue of shortest "Hello, World!" programs (similar to how our basic quine challenge contains some of the shortest known quines in various languages). So let's do this!

The Rules

Each submission must be a full program.

The program must take no input, and print Hello, World! to STDOUT (this exact byte stream, including capitalization and punctuation) plus an optional trailing newline, and nothing else.

The program must not write anything to STDERR.

If anyone wants to abuse this by creating a language where the empty program prints Hello, World!, then congrats, they just paved the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

This is not about finding the language with the shortest "Hello, World!" program. This is about finding the shortest "Hello, World!" program in every language. Therefore, I will not mark any answer as "accepted".

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf - these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

For inspiration, check the Hello World Collection.

The Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](https://esolangs.org/wiki/Fish), 121 bytes
</code>```

/* Configuration */

var QUESTION_ID = 55422; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8478; // This should be the user ID of the challenge author.

/* App */

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) {
      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 = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\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 = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        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(''+lang+'').text();

    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, 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.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) 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);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  text-align: left !important;
  display: block !important;
}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 500px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=ffb5d0584c5f">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
ABCD, 366 bytes

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAADDAAADBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBDBBBBBBBBBBBBDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAADAAADBBBBBBDBBBBBBBBDBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBD

Proof (note that I'm actually using the interpreter of ABCD)


问:
Product over a range
Your task is simple: given two integers \$a\$ and \$b\$, output \$\Pi[a,b]\$; that is, the product of the range between \$a\$ and \$b\$. You may take \$a\$ and \$b\$ in any reasonable format, whether that be arguments to a function, a list input, STDIN, et cetera. You may output in any reasonable format, such as a return value (for functions) or STDOUT. \$a\$ will always be less than \$b\$.

Note that the end may be exclusive or inclusive of \$b\$. I'm not picky. ^_^

Test cases

```<code>[a,b) => result
[2,5) => 24
[5,10) => 15120
[-4,3) => 0
[0,3) => 0
[-4,0) => 24

[a,b] => result
[2,5] => 120
[5,10] => 151200
[-4,3] => 0
[0,3] => 0
[-4,-1] => 24
</code>```

This is a code-golf, so the shortest program in bytes wins.

Leaderboard

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=66202,OVERRIDE_USER=44713;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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/s.lang?1:e.lang<s.lang?-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;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
k/kona, 8 bytes

```<code>*/a+!b-a
</code>```

Let's break this down:
k reads right-to-left, so:

b-a finds the difference between b and a, to give the number of numbers required

!(b-a) generates a list from 0 to (b-a), giving the range [0, (b-a))

a+(!b-a) adds a to each element of the list, to get the range [a, b)

*/(a+!b-a) applies multiplication over all elements of the list; * is the multiply operator, and / is the over adverb, which is like a map/reduce function, applying its left-hand argument over all elements of its right-hand argument.

Title: Product over a range

Body:
k/kona, 8 bytes

*/a+!b-a

Let's break this down:
k reads right-to-left, so:

b-a finds the difference between b and a, to give the number of numbers required

!(b-a) generates a list from 0 to (b-a), giving the range [0, (b-a))

a+(!b-a) adds a to each element of the list, to get the range [a, b)

*/(a+!b-a) applies multiplication over all elements of the list; * is the multiply operator, and / is the over adverb, which is like a map/reduce function, applying its left-hand argument over all elements of its right-hand argument.


答:
PHP, 42 Bytes

```<code><?=array_product(range($ARGV[1],$ARGV[2]))

<?=                         // Open file, '=' is shorthand for 'echo'
array_product(              // Get product of array
range($argv[1],$argv[2])    // array is range from a to b
)
</code>```

Title: Product over a range

Body:
Your task is simple: given two integers \$a\$ and \$b\$, output \$\Pi[a,b]\$; that is, the product of the range between \$a\$ and \$b\$. You may take \$a\$ and \$b\$ in any reasonable format, whether that be arguments to a function, a list input, STDIN, et cetera. You may output in any reasonable format, such as a return value (for functions) or STDOUT. \$a\$ will always be less than \$b\$.

Note that the end may be exclusive or inclusive of \$b\$. I'm not picky. ^_^

Test cases

```<code>[a,b) => result
[2,5) => 24
[5,10) => 15120
[-4,3) => 0
[0,3) => 0
[-4,0) => 24

[a,b] => result
[2,5] => 120
[5,10] => 151200
[-4,3] => 0
[0,3] => 0
[-4,-1] => 24
</code>```

This is a code-golf, so the shortest program in bytes wins.

Leaderboard

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=66202,OVERRIDE_USER=44713;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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/s.lang?1:e.lang<s.lang?-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;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
PHP, 42 Bytes

<?=array_product(range($ARGV[1],$ARGV[2]))

<?=                         // Open file, '=' is shorthand for 'echo'
array_product(              // Get product of array
range($argv[1],$argv[2])    // array is range from a to b
)


问:
Stretch the word
The input is a word of lowercase letters not separated by whitespace. A newline at the end is optional.

The same word must be output in a modified version: For each character, double it the second time it appears in the original word, triple it the third time etc.

Example input:

```<code>bonobo
</code>```

Example output:

```<code>bonoobbooo
</code>```

Standard I/O rules apply. The shortest code in bytes wins.

Tests provided by @Neil :

```<code>tutu -> tuttuu
queue -> queuuee
bookkeeper -> boookkkeeepeeer
repetitive -> repeetittiiveee
uncopyrightables -> uncopyrightables
abracadabra -> abraacaaadaaaabbrraaaaa
mississippi -> misssiisssssssiiipppiiii
</code>```

答:
Swift, 134 bytes

```<code>var c = NSCountedSet(),n = ""
i.characters.forEach({var s = String($0);c.addObject(s);for _ in 0..<c.countForObject(s){n.append($0)}})
</code>```

Assumes Foundation has been implicitly imported.  i is the input of type String, n is the output of type String.

I'm falling back on Foundation classes here as NSCountedSet gives the the character count lookup behavior we want.  The problem with mixing Swift and Objective-C types is that Swift structs do not conform to NSObjectProtocol.  We see this issue when trying to store a Swift Character (String.CharacterView) in an NSCountedSet, which is expecting objects of type AnyObject (or NSObject).  I lose around 17 bytes having to create a String from each Character in the input string.

I also lose some bytes having to create a for loop to append the new characters based on their count in the set.  I can't use forEach here since the return type of countForObject is an Int, not a collection type.  There is room for improvement here.

Swift String types are immutable, so I can't explicitly mutate the input.  There may be room for improvement by using an NSMutableString, but the characters lost by explicitly declaring the input of that type and calling the appendString method may add more characters to the program.

Title: Stretch the word

Body:
Swift, 134 bytes

var c = NSCountedSet(),n = ""
i.characters.forEach({var s = String($0);c.addObject(s);for _ in 0..<c.countForObject(s){n.append($0)}})

Assumes Foundation has been implicitly imported.  i is the input of type String, n is the output of type String.

I'm falling back on Foundation classes here as NSCountedSet gives the the character count lookup behavior we want.  The problem with mixing Swift and Objective-C types is that Swift structs do not conform to NSObjectProtocol.  We see this issue when trying to store a Swift Character (String.CharacterView) in an NSCountedSet, which is expecting objects of type AnyObject (or NSObject).  I lose around 17 bytes having to create a String from each Character in the input string.

I also lose some bytes having to create a for loop to append the new characters based on their count in the set.  I can't use forEach here since the return type of countForObject is an Int, not a collection type.  There is room for improvement here.

Swift String types are immutable, so I can't explicitly mutate the input.  There may be room for improvement by using an NSMutableString, but the characters lost by explicitly declaring the input of that type and calling the appendString method may add more characters to the program.


问:
Reverse the truth
Write a program or function that:

takes in a string from stdio or arguments

replaces all occurrences of true with false and false with true

reverses it, but does not reverse true and false

returns or prints result

Examples (left side is input):

```<code>"true"                     "false"
"2false"                   "true2"
"true is false"            "true si false"
"false,true,undefined"     "denifednu,false,true"
"stressed-false"           "true-desserts"
"falstrue"                 "falseslaf"
"true false true x"        "x false true false"
</code>```

Standard loopholes apply.
This is code-golf, so shortest code in bytes wins.

Leaderboard

var QUESTION_ID=63256,OVERRIDE_USER=20569;function answersUrl(e){return"http://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"http://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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/s.lang?1:e.lang<s.lang?-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;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
PHP, 60 bytes

Simple, reverses the string first, then replaces the reversed versions with their respective swaps.

"falstrue" becomes "eurtslaf" becomes "falseslaf".

```<code><?=strtr(strrev($argv[1]),{'eurt'=>'false','eslaf'=>'true'})
</code>```

Title: Reverse the truth

Body:
PHP, 60 bytes

Simple, reverses the string first, then replaces the reversed versions with their respective swaps.

"falstrue" becomes "eurtslaf" becomes "falseslaf".

<?=strtr(strrev($argv[1]),{'eurt'=>'false','eslaf'=>'true'})


答:
Perl 5.10, 54 bytes

```<code>$_=reverse<>;s/(eurt)|(eslaf)/$1?"false":"true"/eg;say
</code>```

Reverse, then replace. A different way of doing it besides the hash table used for the other Perl answer, which ends up being shorter!

Try it online.

Title: Reverse the truth

Body:
Write a program or function that:

takes in a string from stdio or arguments

replaces all occurrences of true with false and false with true

reverses it, but does not reverse true and false

returns or prints result

Examples (left side is input):

```<code>"true"                     "false"
"2false"                   "true2"
"true is false"            "true si false"
"false,true,undefined"     "denifednu,false,true"
"stressed-false"           "true-desserts"
"falstrue"                 "falseslaf"
"true false true x"        "x false true false"
</code>```

Standard loopholes apply.
This is code-golf, so shortest code in bytes wins.

Leaderboard

var QUESTION_ID=63256,OVERRIDE_USER=20569;function answersUrl(e){return"http://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"http://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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/s.lang?1:e.lang<s.lang?-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;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
Perl 5.10, 54 bytes

$_=reverse<>;s/(eurt)|(eslaf)/$1?"false":"true"/eg;say

Reverse, then replace. A different way of doing it besides the hash table used for the other Perl answer, which ends up being shorter!

Try it online.


答:
APL (Dyalog Extended), <s>8</s> 3 bytesSBCS

×/…
```

Try it online!

… range

×/ multiplication across

This is an "atop" so a(×/…)b is ×/a…b.

Title: Product over a range

Body:
APL (Dyalog Extended), <s>8</s> 3 bytesSBCS

×/…

Try it online!

… range

×/ multiplication across

This is an "atop" so a(×/…)b is ×/a…b.


问:
Find the Factorial!
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

答:
Joy, 13 bytes

```<code>[1][*]primrec
</code>```

30 char requirement in codegolf?

Title: Find the Factorial!

Body:
Joy, 13 bytes

[1][*]primrec

30 char requirement in codegolf?


答:
MATLAB, <s>92</s> <s>90</s> <s>86</s> <s>83</s> <s>79</s> <s>74</s> 72 bytes

```<code>x=input('');I=@(x)~imdilate(x,ones(3));[C,N]=bwlabel(I(x));nnz(I(C)-x)+N
</code>```

This solution accepts the input in the form of a 2D matrix of 0's and 1's and will display the 3BV value for the provided input.

Here is slightly modified demo in Octave for those of you without MATLAB.

Explanation

The input matrix is dilated using a 3 x 3 matrix of 1's and then inverted (using ~) which identifies all of the points that do not have mines as neighbors (1) or do (0). To determine the number of connected regions, we use bwlabel to label each connected region of 1's. The first output is the label matrix (0 where the input was zero and any value in the range 1...N where there was a 1 in the input where N is the index of the connected group that it belongs to). The second output is the number of regions (the number of clicks required to open them). The result of the bwlabel is shown in the image on the left.

We expand the first output of bwlabel using imdilate (all non-zeros are expanded) using a 3 x 3 matrix of 1's. The result is shown in the image in the middle.

To determine the remaining clicks, we then count the squares that are not in this expanded region (~imdilate()) and not a mine (-x) (white squares in the image on the right) and add this to the total number of open regions (the number of different colors in the image on the left) to get the 3BV.

Title: Calculate the 3BV of a Minesweeper Board

Body:
The 3BV of a Minesweeper board represents the minimum number of left clicks required to solve the board if you already know the solution. It stands for "Bechtel's Board Benchmark Value". Here's his site explaining it.

Below is a solved Minesweeper board. The flags indicate mines; tiles without mines indicate the count of adjacent mines, including diagonally, except that tiles that should have "0" are left blank instead. The image shows which tiles need to be clicked in order to solve the board.

Clicks counted towards the 3BV are:

One for each flood-filled area of blank tiles (zero mines adjacent) and their non-blank neighbors.

One for each other non-mine tile.

Another Example (3BV = 39)

Given a 2D array of values, 0 for clear and 1 for a mine (or a boolean), return the 3BV.

A board's dimensions will be at least 8x8, and at most 24x30, inclusive. Your program should handle all possible boards, not just the examples.

Note: A board will never contain only mines.

Example I/O:

```<code>[[0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0],
[0,0,0,1,0,0,1,0],
[0,1,0,0,1,0,0,0],
[0,0,1,0,0,0,0,1],
[0,0,0,1,0,0,0,0],
[0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,1]]

23

[[0,0,1,0,0,0,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0],
[0,0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,0,0,0,0,0,0],
[0,1,0,0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,1,0,0,0,1,0,1,0,1,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,0,1],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1],
[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0],
[0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0],
[1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1],
[0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0],
[0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,1,0,1,1,0,0,0,1,0,0,0,1,1,0,0],
[0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0],
[0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0]]

187
</code>```

Body:
MATLAB, <s>92</s> <s>90</s> <s>86</s> <s>83</s> <s>79</s> <s>74</s> 72 bytes

x=input('');I=@(x)~imdilate(x,ones(3));[C,N]=bwlabel(I(x));nnz(I(C)-x)+N

This solution accepts the input in the form of a 2D matrix of 0's and 1's and will display the 3BV value for the provided input.

Here is slightly modified demo in Octave for those of you without MATLAB.

Explanation

The input matrix is dilated using a 3 x 3 matrix of 1's and then inverted (using ~) which identifies all of the points that do not have mines as neighbors (1) or do (0). To determine the number of connected regions, we use bwlabel to label each connected region of 1's. The first output is the label matrix (0 where the input was zero and any value in the range 1...N where there was a 1 in the input where N is the index of the connected group that it belongs to). The second output is the number of regions (the number of clicks required to open them). The result of the bwlabel is shown in the image on the left.

We expand the first output of bwlabel using imdilate (all non-zeros are expanded) using a 3 x 3 matrix of 1's. The result is shown in the image in the middle.

To determine the remaining clicks, we then count the squares that are not in this expanded region (~imdilate()) and not a mine (-x) (white squares in the image on the right) and add this to the total number of open regions (the number of different colors in the image on the left) to get the 3BV.


答:
Stack Cats, 134 + 3 = 137 <s>148</s> <s>907</s> bytes

I'm happy to give a 500-rep bounty to the first person who can bring this down below 100 (+3) bytes.

```<code>-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)
</code>```

Needs to be run with the -l switch of the Ruby interpreter, hence +3 bytes.

Try it online!

There's definitely still room for improvement here, but I haven't quite figured out myself yet how to program in this language effectively. The current solution was just a general idea for how to approach the challenge and I just wrote the code in a rather ad-hoc way. Even without changing the overall approach I'm confident that one can end up much closer to 100 bytes or even below.

Explanation

Proudly introducing my latest creation, this time in collaboration with Sp3000. :) The idea for this language was originally born for feersum's language design CnR, but at the time we weren't able to figure out whether this idea was usable, and then kept putting it off. A couple of weeks ago we decided to revisit the idea, cleaned up the design a lot and managed to make progress towards proving its Turing-completeness, so here it is.

Stack Cats is a stack-based, reversible programming language. In fact, in order to undo any piece of code, you simply mirror it (which means reversing it and swapping all brackets and slashes). Furthermore, every program has to have mirror symmetry itself. This implies that every non-trivial program has odd length and the form f g f-1, where g is a single very simple command which is also an involution. That makes programming and especially golfing in Stack Cats fairly tricky.

Note that the source code above isn't actually symmetric. This is because the -l switch lets you omit the first half (before the g), since it's redundant in any valid program anyway. So the full program is actually:

```<code>(]<*[[>>]<]^+<[>\]_-]<<<]*_-]]^:[_-:^:+<*]<//[[>>]^:<]:<]]^:[<//]]^:-!]<{>>>[[:_-_-^]<[}]<_!]<_!]<-!*-!^:[[^:]:_-_-:_-:_-:_-:_-_-^:)*-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)
</code>```

When I say "stack-based", I mean that the memory model is actually a tape of stacks. As in my other stack-based languages, each stack is initially implicitly filled an infinite amount of zero (this time, that was actually necessary to ensure full reversibility of all commands on all possible states). In addition to this the initial stack starts with a -1 on top when there is no input (which is the case here).

Output in Stack Cats works simply by printing the contents of the final stack, top to bottom. So the goal is to generate a stack with the following values (top is right):

```<code>33 100 108 114 111 87 32 44 111 108 108 101 72
</code>```

(There are a few other options but this is what the above program does.)

I'm going to represent the tape as follows, with the v indicating the tape head's position:

```<code>     v
... -1 ...
     0
</code>```

Now on to the code. Note that the program begins with a (...) which continues until just before the central *-*. This is a loop, which can be used as a conditional. The loop is entered and exited only when the top of the stack is positive. Since the initial stack holds a -1, the entire first half of the program is skipped. This makes programming a lot easier, but of course it's also somewhat wasteful in terms of golfing. I haven't yet been able to figure out how to make easy use of both halves of the code except for simple toy problems.

Next comes the *-*. Here, * takes the top of the stack XOR 1, i.e. turns -1 into -2, the - negates it to give 2 and then we have another *, giving 3. Now that the top of the stack is positive, we do enter the (...) in the second half. The code in there will be executed only once and now turns this single 3 into the stack we need for the output.

It turns out that the quickest way to obtain large numbers without loops is a Fibonacci-like progression where we repeatedly add the last value to the one before. I say Fibonacci-like because we have some flexibility here since we can occasionally increment or decrement values in the process, or add the last value to the previous one several times before swapping their roles.

For now, we're trying to compute 33 and 87, because they both appear in the same Fibonacci-like sequence. (And they are the character codes of ! and W.) If the top of the stack is a and the value below is b, I'll be writing this as (a, b), so the current state is (3, 0). Let's go:

```<code>:    Swap the top two values.              (  0,  3)
^    XOR the second into the first.        (  3,  3)
-    Negate top.                           ( -3,  3)
_    Subtract top from second.             (  6,  3)
     As you can see, -_ can be used to
     add the second-to-top to the top.
-_   Add second into top.                  (  9,  3)
:    Swap.                                 (  3,  9)
-_   Add second into top.                  ( 12,  9)
     The last two together form a normal
     "Fibonacci step".
:-_  Fibonacci step.                       ( 21, 12)
:-_  Fibonacci step.                       ( 33, 21)
:-_  Fibonacci step.                       ( 54, 33)
-_   Add second into top.                  ( 87, 33)
:    Swap.                                 ( 33, 87)
</code>```

Now [ pushes the 33 one stack to the left (moving the tape head along), :^ duplicates it and ] moves one copy back. Together, this just puts a 33 on the stack to the left. And then ]:^ moves the 33 to the right and duplicates it again there. So now we've got:

```<code>           v
          33
... 33 87 33 ...
     0  0  0
</code>```

Next, it turns out that most of the lower case letters are multiples of 3 and their other factors are 36, 37, 38 which aren't too far away. 99 is also useful, since we'll need both 100 and 101, so we now create a stack with those factors so we can multiply all of them by 3 later.

Stack Cats doesn't have a decrement or increment command. The standard way to increment a value is to combine bitwise NOT (!) and unary negation (-). However, if we know that our value is even we can also increment by toggling the least significant bit with *. Hence, the following !-*!- brings the 33 on top of the stack up to 36. Next, we pull over two 0s from the empty stack to the right, turn use them to get incremented copies of the 36 with >[!_>[!_. The tape now looks like this:

```<code>           v
          38
          37
          36
... 33 87 33 ...
     0  0  0
</code>```

Time for the loop:

```<code>>[{]>[^-_-_:]]<<<}
</code>```

Besides the (...) we've already seen, Stack Cats has another loop, {...}, but its semantics are also a bit unusual. The loop body is always executed at least once. When the loop starts, Stack Cats remembers the value on top of the stack, and then the loop doesn't terminate until that value is seen again at the end of an iteration. That means the easiest way to work through a stack is to put a zero on top and then shift the stack away one value at a time until we hit the zero at the bottom. Here is what the loop does:

```<code>>[       Fetch a zero from the empty stack to the right.
{        Loop until zero...
  ]        Push the current factor X to the right.
  >[       Fetch a zero from the stack next to that.
  ^        XOR X into that zero, duplicating X.
  -_-_     Add X into the new value twice, computing 3*X.
  :        Swap 3*X and X.
  ]]<<     Push X two stack to the right and return.
  <        Move back to the stack we're looping over.
}
>        Move onto the stack which now holds the multiples.
</code>```

This is the new tape:

```<code>              v
             99   33
            108   36
            111   37
... 33 87   114   38 ...
     0  0 0   0 0  0
</code>```

The next bit is [!-:^ which you've seen before: it increments the 99 to 100 and duplicates it on the empty stack next to it. The [[ moves one of those 100s over onto the 33 — we're now starting to build the final stack there. Here's what we've got:

```<code>(]<*[[>>]<]^+<[>\]_-]<<<]*_-]]^:[_-:^:+<*]<//[[>>]^:<]:<]]^:[<//]]^:-!]<{>>>[[:_-_-^]<[}]<_!]<_!]<-!*-!^:[[^:]:_-_-:_-:_-:_-:_-_-^:)*-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)
</code>```0

It's going to be annoying to fetch all the values from so many stacks away, so here's a new command. \ swaps the current stack with the one of the right, moving the tape head along. So the \\ now brings the output stack closer to the useful values:

```<code>(]<*[[>>]<]^+<[>\]_-]<<<]*_-]]^:[_-:^:+<*]<//[[>>]^:<]:<]]^:[<//]]^:-!]<{>>>[[:_-_-^]<[}]<_!]<_!]<-!*-!^:[[^:]:_-_-:_-:_-:_-:_-_-^:)*-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)
</code>```1

Next, there's >]:^ which moves the 108 onto the empty stack to duplicate it. [[>:[ moves one of them and the 114 onto the output stack. >:^[ duplicates the 111 and moves one copy onto the output stack. Then we fetch the 87 with <<]], and move the stack two positions further with another \\. We've now got World!:

```<code>(]<*[[>>]<]^+<[>\]_-]<<<]*_-]]^:[_-:^:+<*]<//[[>>]^:<]:<]]^:[<//]]^:-!]<{>>>[[:_-_-^]<[}]<_!]<_!]<-!*-!^:[[^:]:_-_-:_-:_-:_-:_-_-^:)*-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)
</code>```2

Time for the space: we've still got that 33 around, so we fetch and decrement it with >[*. We don't need those 36, 37, 38 any more, but we do need a 44. We also still need the 72 for the H later on, and we can actually compute that on the way. All of this is accomplished with the following code:

```<code>>+:^:-_]:^[[-_*[>>>[-_[
</code>```

The new command here is + which swaps the top of the stack with the third value from the top. We use it together with : to put the 36 below the 37 and 38. The ^ replaces the 37 with 37 XOR 38 which is 3. We then add this to 38 with :-_ which gives 41. ]:^ duplicates that on the stack to the right. Then we add a 32 into it with [[-_ and decrement it with * by toggling the least-significant bit. Voilà, there's our 72. We move it to the side with [, go back to the other copy of 41 with >>> and add another 3 into it with [-_ before putting it on the output stack with [. Next, we move the current stack to the left with /. Here's the current tape:

```<code>              v
             44
             32
             87
            111
            114
            108
            100  72  3
... 100 111  33 108 36 ...
      0   0   0   0  0
</code>```

Now all that's left is collecting a few more values with

```<code><]>+^[>[<<]]*>[
</code>```

The <] fetches the 111. Then >+^ swaps the 72 with the zero below in order to duplicate the 108. [>[ moves both of those onto the output stack. <<]] fetches the 100 and * turns it into a 101. Finally >[ gets the 72 and we're done.

If you've actually followed all of this you'll noticed that there's tons of stuff we could have done differently which may or may not have saved bytes. There are many more ways to compute the different numbers, maybe XOR would have been useful more often. We could also generate some larger or negative numbers, since the final values are taken modulo 256 before being printed. We could also have made more use of loops, or used the stacks differently. There are also further stack manipulation commands like | to reverse it, X to swap the stacks left and right and = to swap only their top values.

As difficult as it is to program in Stack Cats, it still provides quite a large set of useful commands, which allow for many different approaches to any given problem.

Title: "Hello, World!"

Body:
Stack Cats, 134 + 3 = 137 <s>148</s> <s>907</s> bytes

I'm happy to give a 500-rep bounty to the first person who can bring this down below 100 (+3) bytes.

-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)

Needs to be run with the -l switch of the Ruby interpreter, hence +3 bytes.

Try it online!

There's definitely still room for improvement here, but I haven't quite figured out myself yet how to program in this language effectively. The current solution was just a general idea for how to approach the challenge and I just wrote the code in a rather ad-hoc way. Even without changing the overall approach I'm confident that one can end up much closer to 100 bytes or even below.

Explanation

Proudly introducing my latest creation, this time in collaboration with Sp3000. :) The idea for this language was originally born for feersum's language design CnR, but at the time we weren't able to figure out whether this idea was usable, and then kept putting it off. A couple of weeks ago we decided to revisit the idea, cleaned up the design a lot and managed to make progress towards proving its Turing-completeness, so here it is.

Stack Cats is a stack-based, reversible programming language. In fact, in order to undo any piece of code, you simply mirror it (which means reversing it and swapping all brackets and slashes). Furthermore, every program has to have mirror symmetry itself. This implies that every non-trivial program has odd length and the form f g f-1, where g is a single very simple command which is also an involution. That makes programming and especially golfing in Stack Cats fairly tricky.

Note that the source code above isn't actually symmetric. This is because the -l switch lets you omit the first half (before the g), since it's redundant in any valid program anyway. So the full program is actually:

(]<*[[>>]<]^+<[>\]_-]<<<]*_-]]^:[_-:^:+<*]<//[[>>]^:<]:<]]^:[<//]]^:-!]<{>>>[[:_-_-^]<[}]<_!]<_!]<-!*-!^:[[^:]:_-_-:_-:_-:_-:_-_-^:)*-*(:^-_-_:-_:-_:-_:-_-_:[:^]]:^!-*!->[!_>[!_>[{]>[^-_-_:]]<<<}>[!-:^[[\\>]:^[[>:[>:^[<<]]\\>[*>+:^:-_]:^[[-_*[>>>[-_[/<]>+^[>[<<]]*>[)

When I say "stack-based", I mean that the memory model is actually a tape of stacks. As in my other stack-based languages, each stack is initially implicitly filled an infinite amount of zero (this time, that was actually necessary to ensure full reversibility of all commands on all possible states). In addition to this the initial stack starts with a -1 on top when there is no input (which is the case here).

Output in Stack Cats works simply by printing the contents of the final stack, top to bottom. So the goal is to generate a stack with the following values (top is right):

33 100 108 114 111 87 32 44 111 108 108 101 72

(There are a few other options but this is what the above program does.)

I'm going to represent the tape as follows, with the v indicating the tape head's position:

     v
... -1 ...
     0

Now on to the code. Note that the program begins with a (...) which continues until just before the central *-*. This is a loop, which can be used as a conditional. The loop is entered and exited only when the top of the stack is positive. Since the initial stack holds a -1, the entire first half of the program is skipped. This makes programming a lot easier, but of course it's also somewhat wasteful in terms of golfing. I haven't yet been able to figure out how to make easy use of both halves of the code except for simple toy problems.

Next comes the *-*. Here, * takes the top of the stack XOR 1, i.e. turns -1 into -2, the - negates it to give 2 and then we have another *, giving 3. Now that the top of the stack is positive, we do enter the (...) in the second half. The code in there will be executed only once and now turns this single 3 into the stack we need for the output.

It turns out that the quickest way to obtain large numbers without loops is a Fibonacci-like progression where we repeatedly add the last value to the one before. I say Fibonacci-like because we have some flexibility here since we can occasionally increment or decrement values in the process, or add the last value to the previous one several times before swapping their roles.

For now, we're trying to compute 33 and 87, because they both appear in the same Fibonacci-like sequence. (And they are the character codes of ! and W.) If the top of the stack is a and the value below is b, I'll be writing this as (a, b), so the current state is (3, 0). Let's go:

:    Swap the top two values.              (  0,  3)
^    XOR the second into the first.        (  3,  3)
-    Negate top.                           ( -3,  3)
_    Subtract top from second.             (  6,  3)
     As you can see, -_ can be used to
     add the second-to-top to the top.
-_   Add second into top.                  (  9,  3)
:    Swap.                                 (  3,  9)
-_   Add second into top.                  ( 12,  9)
     The last two together form a normal
     "Fibonacci step".
:-_  Fibonacci step.                       ( 21, 12)
:-_  Fibonacci step.                       ( 33, 21)
:-_  Fibonacci step.                       ( 54, 33)
-_   Add second into top.                  ( 87, 33)
:    Swap.                                 ( 33, 87)

Now [ pushes the 33 one stack to the left (moving the tape head along), :^ duplicates it and ] moves one copy back. Together, this just puts a 33 on the stack to the left. And then ]:^ moves the 33 to the right and duplicates it again there. So now we've got:

           v
          33
... 33 87 33 ...
     0  0  0

Next, it turns out that most of the lower case letters are multiples of 3 and their other factors are 36, 37, 38 which aren't too far away. 99 is also useful, since we'll need both 100 and 101, so we now create a stack with those factors so we can multiply all of them by 3 later.

Stack Cats doesn't have a decrement or increment command. The standard way to increment a value is to combine bitwise NOT (!) and unary negation (-). However, if we know that our value is even we can also increment by toggling the least significant bit with *. Hence, the following !-*!- brings the 33 on top of the stack up to 36. Next, we pull over two 0s from the empty stack to the right, turn use them to get incremented copies of the 36 with >[!_>[!_. The tape now looks like this:

           v
          38
          37
          36
... 33 87 33 ...
     0  0  0

Time for the loop:

>[{]>[^-_-_:]]<<<}

Besides the (...) we've already seen, Stack Cats has another loop, {...}, but its semantics are also a bit unusual. The loop body is always executed at least once. When the loop starts, Stack Cats remembers the value on top of the stack, and then the loop doesn't terminate until that value is seen again at the end of an iteration. That means the easiest way to work through a stack is to put a zero on top and then shift the stack away one value at a time until we hit the zero at the bottom. Here is what the loop does:

>[       Fetch a zero from the empty stack to the right.
{        Loop until zero...
  ]        Push the current factor X to the right.
  >[       Fetch a zero from the stack next to that.
  ^        XOR X into that zero, duplicating X.
  -_-_     Add X into the new value twice, computing 3*X.
  :        Swap 3*X and X.
  ]]<<     Push X two stack to the right and return.
  <        Move back to the stack we're looping over.
}
>        Move onto the stack which now holds the multiples.

This is the new tape:

              v
             99   33
            108   36
            111   37
... 33 87   114   38 ...
     0  0 0   0 0  0

The next bit is [!-:^ which you've seen before: it increments the 99 to 100 and duplicates it on the empty stack next to it. The [[ moves one of those 100s over onto the 33 — we're now starting to build the final stack there. Here's what we've got:

      v
                     33
               108   36
    100        111   37
...  33 87 100 114   38 ...
      0  0   0   0 0  0

It's going to be annoying to fetch all the values from so many stacks away, so here's a new command. \ swaps the current stack with the one of the right, moving the tape head along. So the \\ now brings the output stack closer to the useful values:

             v
                     33
               108   36
           100 111   37
... 87 100  33 114   38 ...
     0   0   0   0 0  0

Next, there's >]:^ which moves the 108 onto the empty stack to duplicate it. [[>:[ moves one of them and the 114 onto the output stack. >:^[ duplicates the 111 and moves one copy onto the output stack. Then we fetch the 87 with <<]], and move the stack two positions further with another \\. We've now got World!:

                  v
                 87
                111
                114 33
                108 36
                100 37
... 100 111 108  33 38 ...
      0   0   0   0  0

Time for the space: we've still got that 33 around, so we fetch and decrement it with >[*. We don't need those 36, 37, 38 any more, but we do need a 44. We also still need the 72 for the H later on, and we can actually compute that on the way. All of this is accomplished with the following code:

>+:^:-_]:^[[-_*[>>>[-_[

The new command here is + which swaps the top of the stack with the third value from the top. We use it together with : to put the 36 below the 37 and 38. The ^ replaces the 37 with 37 XOR 38 which is 3. We then add this to 38 with :-_ which gives 41. ]:^ duplicates that on the stack to the right. Then we add a 32 into it with [[-_ and decrement it with * by toggling the least-significant bit. Voilà, there's our 72. We move it to the side with [, go back to the other copy of 41 with >>> and add another 3 into it with [-_ before putting it on the output stack with [. Next, we move the current stack to the left with /. Here's the current tape:

              v
             44
             32
             87
            111
            114
            108
            100  72  3
... 100 111  33 108 36 ...
      0   0   0   0  0

Now all that's left is collecting a few more values with

<]>+^[>[<<]]*>[

The <] fetches the 111. Then >+^ swaps the 72 with the zero below in order to duplicate the 108. [>[ moves both of those onto the output stack. <<]] fetches the 100 and * turns it into a 101. Finally >[ gets the 72 and we're done.

If you've actually followed all of this you'll noticed that there's tons of stuff we could have done differently which may or may not have saved bytes. There are many more ways to compute the different numbers, maybe XOR would have been useful more often. We could also generate some larger or negative numbers, since the final values are taken modulo 256 before being printed. We could also have made more use of loops, or used the stacks differently. There are also further stack manipulation commands like | to reverse it, X to swap the stacks left and right and = to swap only their top values.

As difficult as it is to program in Stack Cats, it still provides quite a large set of useful commands, which allow for many different approaches to any given problem.


答:
Octave, <s>86</s> <s>84</s> <s>79</s> 66 bytes

```<code>@(x)nnz(~imdilate(c=imerode(~x,o=ones(3)),o)-x)+max(bwlabel(c)(:))
</code>```

This solution creates an anonymous function named ans which can then be passed a 2D matrix of 0's and 1's. The logic is the same as my MATLAB answer but uses a few tricks that Octave has to offer to save space.

This solution requires that the image package is installed.

Demo here

Body:
Octave, <s>86</s> <s>84</s> <s>79</s> 66 bytes

@(x)nnz(~imdilate(c=imerode(~x,o=ones(3)),o)-x)+max(bwlabel(c)(:))

This solution creates an anonymous function named ans which can then be passed a 2D matrix of 0's and 1's. The logic is the same as my MATLAB answer but uses a few tricks that Octave has to offer to save space.

This solution requires that the image package is installed.

Demo here


问:
Remainder When N divided by 2^M
Write the shortest code to find the remainder when an input number N is divided by 2^M. You cannot use /,* and % operator.</p>

```<code>Input Specification
Number of test cases followed by a pair of integers on each line.

Sample Input
1
150 6

Sample Output
22

Limits
1<T<1000
1<N<2^31
1<B<31

Time Limit
1 Sec
</code>```

答:
J, <s>15</s> <s>12</s> 9 bytes

6 bytes thanks to @miles.

```<code>#.@#:~#&2
</code>```

Previous 12-byte version

```<code>#.@({.~-)~#:
</code>```

Usage

```<code>>> f =: #.@({.~-)~#:
>> 6 f 150
<< 22
</code>```

Where >> is STDIN and << is STDOUT.

Explanation

#: converts n to base 2.

({.~-)~ then takes the last m digits from it

#. converts it back to base 2.

Previous 15-byte version:

```<code>2#.(0-[){.[:#:]
</code>```

Usage

```<code>>> f =: 2#.(0-[){.[:#:]
>> 6 f 150
<< 22
</code>```

Where >> is STDIN and << is STDOUT.

Explanation

[:#:] converts n to base 2.

(0-[){. then takes the last m digits from it

2#. converts it back to base 2.

ContentLicense: CC BY-SA 2.5

Title: Remainder When N divided by 2^M

Body:
J, <s>15</s> <s>12</s> 9 bytes

6 bytes thanks to @miles.

#.@#:~#&2

Previous 12-byte version

#.@({.~-)~#:

Usage

>> f =: #.@({.~-)~#:
>> 6 f 150
<< 22

Where >> is STDIN and << is STDOUT.

Explanation

#: converts n to base 2.

({.~-)~ then takes the last m digits from it

#. converts it back to base 2.

Previous 15-byte version:

2#.(0-[){.[:#:]

Usage

>> f =: 2#.(0-[){.[:#:]
>> 6 f 150
<< 22

Where >> is STDIN and << is STDOUT.

Explanation

[:#:] converts n to base 2.

(0-[){. then takes the last m digits from it

2#. converts it back to base 2.


问:
Find the number of x-digit numbers whose product of digits is N
Given two numbers \$N\$ and \$x\$, find the number of \$x\$-digit numbers whose product of digits is \$N\$

\$N <10^6\$ and \$x <12\$

```<code>Sample Input (N x):
8 3
Sample Output:
10
</code>```

答:
J, 40 bytes

```<code>[:+/[=[:*/"1(10#~])#:(10^<:@])}.[:i.10^]
</code>```

Generates all x-digit numbers, convert each to base 10, then find the product of each number, and test whether each number is equal to the left hand side, and then find the sum of each boolean.

Body:
J, 40 bytes

[:+/[=[:*/"1(10#~])#:(10^<:@])}.[:i.10^]

Generates all x-digit numbers, convert each to base 10, then find the product of each number, and test whether each number is equal to the left hand side, and then find the sum of each boolean.


问:
Shortest simple regex matching a binary word

Task

Define a simple regex as a non-empty regular expression consisting only of

characters 0 and 1,

grouping parentheses ( and ),

one-or-more repetition quantifier +.

Given a non-empty string of 0s and 1s, your program should find the shortest simple regex matching the full input string. (That is, when matching a simple regex, pretend it’s bookended by ^ and $.) If there are multiple shortest regexes, print any or all of them.)

code-golf, so the shortest submission (in bytes) wins.

Test cases

```<code>1 -> 1
00 -> 00 or 0+
010 -> 010
1110 -> 1+0
01010 -> 01010
0101010 -> 0(10)+ or (01)+0
011111 -> 01+
10110110 -> (1+0)+
01100110 -> (0110)+ or (01+0)+
010010010 -> (010)+
111100111 -> 1+001+ or 1+0+1+
00000101010 -> 0+(10)+ or (0+1)+0
1010110001 -> 1(0+1+)+ or (1+0+)+1
</code>```

答:
Pyth, 20 bytes

```<code>hf.x}z:zT1Zy*4"()01+
</code>```

This takes approximately 30 seconds to run, so it needs to be run offline.

Explanation:

```<code>hf.x}z:zT1Zy*4"()01+
                        Implicit: z is the input string.
              "()01+    "()01+"
            *4          Repeated 4 times
           y            All subsequences in length order
hf                      Output the first one such that
      :zT1              Form all regex matches of z with the candidate string
    }z                  Check if the input is one of the strings
  .x      Z             Discard errors
</code>```

I'm not completely sure that every shortest string is a subsequence of "()01+" * 4, but 4 can be increased to 9 at no byte cost if needed.

Body:
Pyth, 20 bytes

hf.x}z:zT1Zy*4"()01+

This takes approximately 30 seconds to run, so it needs to be run offline.

Explanation:

hf.x}z:zT1Zy*4"()01+
                        Implicit: z is the input string.
              "()01+    "()01+"
            *4          Repeated 4 times
           y            All subsequences in length order
hf                      Output the first one such that
      :zT1              Form all regex matches of z with the candidate string
    }z                  Check if the input is one of the strings
  .x      Z             Discard errors

I'm not completely sure that every shortest string is a subsequence of "()01+" * 4, but 4 can be increased to 9 at no byte cost if needed.


问:
Show the Top Five Comment Scores on a SE Post
A Stack Exchange script determines which five comments on questions or answers are initially seen on the main page of sites through the number of upvotes on them; the five comments with the highest number of votes are displayed. Your task is to recreate this behavior.

Write a full program or function taking input through STDIN, command-line args, or function arguments and prints or returns the top five comment scores. Input will be an array of integers representing the number of upvotes on the comments of some post. For instance, an input of

```<code>0, 2, 5, 4, 0, 1, 0
</code>```

means that the first comment has no votes, the second one has two votes, the third has five, the fourth had four, etc. The order of the comment scores should remain the same in the output.

If the input contains five or fewer comment scores, then the output should contain nothing more than the ones given. If two or more comment scores are the same, the first score(s) should be displayed. You may assume that the input array will contain at least one comment score.

The numbers in the output should be easily distinguished (so 02541 for case 1 is invalid). Otherwise there are no restrictions on output format; the numbers may be separated by a space or newline, or they may be in list format, etc.

Test cases:

```<code>[0, 2, 5, 4, 0, 1, 0] -> [0, 2, 5, 4, 1]
[2, 1, 1, 5, 3, 6] -> [2, 1, 5, 3, 6]
[0, 4, 5] -> [0, 4, 5]
[1, 1, 5, 1, 1, 5] -> [1, 1, 5, 1, 5]
[0, 2, 0, 0, 0, 0, 0, 0] -> [0, 2, 0, 0, 0]
[0, 0, 0, 0, 1, 0, 0, 0, 0] -> [0, 0, 0, 0, 1]
[5, 4, 2, 1, 0, 8, 7, 4, 6, 1, 0, 7] -> [5, 8, 7, 6, 7]
[6, 3, 2, 0, 69, 22, 0, 37, 0, 2, 1, 0, 0, 0, 5, 0, 1, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2] -> [6, 69, 22, 37, 5]
</code>```

The last example was taken from this Stack Overflow question.

If possible, please provide a link in your post where your submission can be run online.

This is code golf, so the shortest code in bytes wins. Good luck!

答:
Python 3.5, 68 bytes

f=lambda x,*h:x and x[:sum(t>x[0]for t in x+h)<5]+f(x[1:],*h,x[0]+1)
```

No match for my Python 2 answer, but only three bytes longer than its port to Python 3, and I think it's different enough to be interesting.

I/O is in form of tuples. Test it on repl.it.

Body:
Python 3.5, 68 bytes

f=lambda x,*h:x and x[:sum(t>x[0]for t in x+h)<5]+f(x[1:],*h,x[0]+1)

No match for my Python 2 answer, but only three bytes longer than its port to Python 3, and I think it's different enough to be interesting.

I/O is in form of tuples. Test it on repl.it.


问:
Write a program that always prints N when it is shifted N times up the ASCII alphabet
Write a program using only printable ASCII characters that takes no input. For reference, here are the 95 printable ASCII characters in order:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

When your program is run it should print 0 (plus an optional trailing newline) to stdout, then terminate normally.

When each character in your program is replaced by the character N spaces to its right in printable ASCII, looping around from ~ to space, the resulting printable ASCII string will ideally be a program runnable in the same language that takes no input and outputs N (plus an optional trailing newline) to stdout, then terminates normally, for N = 1 to 94.

For example, if your original program was

```<code>@Cat~(88 !)
</code>```

running it should output 0 and shifting all the characters up the printable ASCII scale by one

```<code>ADbu )99!"*
</code>```

should result in another program that outputs 1. Doing so again will ideally result in another program that outputs 2

```<code>BEcv!*::"#+
</code>```

and so on with 3 and 4, etc. up to the point of shifting 94 times

```<code>?B`s}'77~ (
</code>```

which ideally is a program that outputs 94.

The relief is that this is only the ideal behavior. Your program and its 94 derivatives do not all need to work, but the more that consecutively do from the start the better. (Programs that do not work may have any behavior whatsoever.)

Scoring

Your score is the number of consecutive programs starting from the original (the one that outputs 0) that do work, i.e. correctly output their corresponding N. The answer with the highest score (a maximum of 95) wins. If there's a tie then the program with the shortest length in bytes wins.

For example, if @Cat~(88 !) output 0 and ADbu )99!"* output 1 but BEcv!*::"#+ errored, then your score would be 2. It's 2 even if ?B`s}'77~ ( accurately outputs 94 and even if all the programs for N = 30 to 40 worked. Only the consecutive number of working programs, starting at zero, are counted.

Notes

To combat potential contention and loopholes, competing answers must output their numbers in decimal with no leading zeroes or signs or decimal points (i.e. plain 0 1 2 ... 94).

Languages that use different bases or number formats are allowed but are not eligible to win.

The presence of an optional trailing newline does not need to be consistent across programs.

Functions and REPL commands are not allowed, only full programs.

答:
CJam, 10 programs, 1 byte

I thought I'd better add this right off the bat before someone else gets cheeky and does it :P

```<code>0
</code>```

A CJam program with just a plain number outputs that number, so this is an easy way to get 10 programs that work, namely:

0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

The next program : unsurprisingly does not output 10 but gives an "unfinished operator" error.

This undoubtedly works in many languages.

Body:
CJam, 10 programs, 1 byte

I thought I'd better add this right off the bat before someone else gets cheeky and does it :P

0

A CJam program with just a plain number outputs that number, so this is an easy way to get 10 programs that work, namely:

0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

The next program : unsurprisingly does not output 10 but gives an "unfinished operator" error.

This undoubtedly works in many languages.


答:
><>, <s>17</s> 16 bytes

```<code>1v;n
$<*}-1.!?::
</code>```

-1 byte thanks to Jo King.

Since the question asks for a function as opposed to a full program, I allowed myself to accept the input from the stack without counting an additional 3 bytes for using the -v option.

This manages to be shorter than the other ><> answer because it jumps to the end-of-iteration code without having to hardcode the jump destination address : the current iteration counter (duplicated) is used as an address.

The iteration stops when the counter is 0, and jumping to (0, 0) while the direction pointer points to the right will execute the n; code that is otherwise unreachable, displaying the result and stopping the execution.

It handles 0! correctly and executes in 10*(n+1) ticks for n > 0 or 9 ticks for n = 0.

You can try it online.

Title: Find the Factorial!

Body:
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

Body:
><>, <s>17</s> 16 bytes

1v;n
$<*}-1.!?::

-1 byte thanks to Jo King.

Since the question asks for a function as opposed to a full program, I allowed myself to accept the input from the stack without counting an additional 3 bytes for using the -v option.

This manages to be shorter than the other ><> answer because it jumps to the end-of-iteration code without having to hardcode the jump destination address : the current iteration counter (duplicated) is used as an address.

The iteration stops when the counter is 0, and jumping to (0, 0) while the direction pointer points to the right will execute the n; code that is otherwise unreachable, displaying the result and stopping the execution.

It handles 0! correctly and executes in 10*(n+1) ticks for n > 0 or 9 ticks for n = 0.

You can try it online.


问:
Generate a "GitHub" Avatar

Background / Description

Note: as @HelkaHomba points out, the actual GitHub identicons are not actually random but based on the hash of a username

The default GitHub avatar is a 5x5-pixel image. A color is picked randomly, and then random pixels are filled in on one side (right or left, 2x5 size) using that color. Then that side is copied & flipped to the other side, across the y-axis. The pixels left over that are not filled in are #F0F0F0, or rgb(240,240,240).

The center column's pixels (1x5 size) are then randomly filled in, using the same color as previously.

Output

Note: for this challenge we will ignore the space that encloses the GitHub avatars

The program should output a 5x5 pixel image file. See http://meta.codegolf.stackexchange.com/a/9095/42499 for specifics

Examples

Note: these were obviously scaled up from 5x5 so you can see them

Good luck!

答:
Mathematica, <s>105</s> <s>102</s> <s>98</s> 94 bytes

```<code>c=1~RandomReal~3;r@l_:={c,4{4,4,4}/17}~RandomChoice~{l,5};Image[Join[#,r@1,Reverse@#]&@r@2]
</code>```

 is the Transpose operator.

Edit 1: Saved 3 bytes by replacing Round + RandomReal with RandomInteger

Edit 2: Saved 4 bytes by replacing RandomInteger with RandomChoice

Edit 3: Saved 4 bytes by replacing RandomColor and GrayLevel with RandomReal

Title: Generate a "GitHub" Avatar

Body:
Mathematica, <s>105</s> <s>102</s> <s>98</s> 94 bytes

c=1~RandomReal~3;r@l_:={c,4{4,4,4}/17}~RandomChoice~{l,5};Image[Join[#,r@1,Reverse@#]&@r@2]

 is the Transpose operator.

Edit 1: Saved 3 bytes by replacing Round + RandomReal with RandomInteger

Edit 2: Saved 4 bytes by replacing RandomInteger with RandomChoice

Edit 3: Saved 4 bytes by replacing RandomColor and GrayLevel with RandomReal