问:
Kolmogorov complexity Chad Gadya
EDIT It is not clear how answers to the question of compressing a long text, without cumulative properties are relevant to golfing a short cumulative strong, any more than general Lempel Ziv techniques are relevant to code-golfing. Take note that the complexity of 99 bottles of beer is not O(Sqrt(n))

Knuth suggested  the notion of theoretical complexity of songs (Knuth, Donald E. "The complexity of songs." Communications of the ACM 27.4 (1984): 344-346.), noting that most cumulative songs are O(sqrt(n)).

Cumulative songs never showed up in PPCG. The challenge this time is Chad Gadya, a famous cumulative song in Aramaic and Hebrew, sung in cumulation of the seder. The lyrics can be found, e.g., here (blue text). (There are slight variations, so use this one, copied below).

To state the obvious, Chad Gadya belongs in the complexity class of the famous "Läuschen und Flöhchen" tale by the Grimm brothers, and some other more or less famous English songs, i.e., O(sqrt n).

The challenge is to write a program, in any programming language, that produces the song, each verse in its own line. The program takes no input, and cannot cheat by using, e.g., wget. A greater challenge is to make the solution so small that it can fit in a twitter message. (I bet no one here would be able to meet this challenge)

A short such program could be useful for twitter/sms holiday greetings. Please minimize the number of bytes (not characters). Output should be in UTF8.

Why is this interesting?

Knuth paper on the the complexity of cumulative songs

Song is very short; standard tricks would not help.

Space savings in Niqqud is an extra challenge.

Repetitions are not only due to the cumulative nature of the song.

The twitter objective seems impossible.

The song itself is quite short, much shorter than other songs that have been posted here. Compression of short text is more challenging than that of long text.

Output

חַד גַּדְיָא, חַד גַּדְיָא דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא שׁוּנְרָא, וְאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא כַלְבָּא, וְנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא חוּטְרָא, וְהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא נוּרָא, וְשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא מַיָּא, וְכָבָה לְנוּרָא, דְּשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא תוֹרָא, וְשָׁתָה לְמַיָּא, דְּכָבָה לְנוּרָא, דְּשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא הַשּׁוֹחֵט, וְשָׁחַט לְתוֹרָא, דְּשָׁתָה לְמַיָּא, דְּכָבָה לְנוּרָא, דְּשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא מַלְאַךְ הַמָּוֶת, וְשָׁחַט לְשׁוֹחֵט, דְּשָׁחַט לְתוֹרָא, דְּשָׁתָה לְמַיָּא, דְּכָבָה לְנוּרָא, דְּשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא
וַאֲתָא הַקָּדוֹשׁ בָּרוּךְ הוּא, וְשָׁחַט לְמַלְאַךְ הַמָּוֶת, דְּשָׁחַט לְשׁוֹחֵט, דְּשָׁחַט לְתוֹרָא, דְּשָׁתָה לְמַיָּא, דְּכָבָה לְנוּרָא, דְּשָׂרַף לְחוּטְרָא, דְּהִכָּה לְכַלְבָּא, דְּנָשַׁךְ לְשׁוּנְרָא, דְּאָכְלָה לְגַדְיָא, דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. חַד גַּדְיָא, חַד גַּדְיָא

If you find it hard to deal with Hebrew and Aramaic (tough luck...), try first getting your hands dirty with Läuschen und Flöhchen, and then proceed to the real challenge.

A related, but different question is that of "99 Bottles of Beer". If you care about complexity, you would notice that the theoretical complexity of bottles of beers is different from that of the two farthing kid.

答:
GolfScript, 577 bytes

```<code>"חַד גַּדְיָא, חַד גַּדְיָא. ":d"דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. "d+"\n"+:c"גַדְיָא,שׁוּנְרָא,כַלְבָּא,חוּטְרָא,נוּרָא,מַיָּא,תוֹרָא,שׁוֹחֵט,מַלְאַךְ הַמָּוֶת,הַקָּדוֹשׁ בָּרוּךְ הוּא"","/:y;"אָכְלָה,נָשַׁךְ,הִכָּה,שָׂרַף,כָבָה,שָׁתָה,שָׁחַט,שָׁחַט,שָׁחַט"","/:x;9,{"וַאֲתָא "\.6="הַ"""if\.y\1+=\", וְ"\.x\=\" לְ"\.y\=\,-1%{", דְּ"\.x\=\" לְ"\.y\=\;}%". "c}%
</code>```

Store the nouns and actions in variables by splitting strings.
Using a list of lists of increasing sizes, each in descending order - [[1],[2,1],[3,2,1]...] - print the first and subsequent lines of each stanza using those index values.

Title: Kolmogorov complexity Chad Gadya

Body:
GolfScript, 577 bytes

"חַד גַּדְיָא, חַד גַּדְיָא. ":d"דִּזְבַן אַבָּא בִּתְרֵי זוּזֵי. "d+"\n"+:c"גַדְיָא,שׁוּנְרָא,כַלְבָּא,חוּטְרָא,נוּרָא,מַיָּא,תוֹרָא,שׁוֹחֵט,מַלְאַךְ הַמָּוֶת,הַקָּדוֹשׁ בָּרוּךְ הוּא"","/:y;"אָכְלָה,נָשַׁךְ,הִכָּה,שָׂרַף,כָבָה,שָׁתָה,שָׁחַט,שָׁחַט,שָׁחַט"","/:x;9,{"וַאֲתָא "\.6="הַ"""if\.y\1+=\", וְ"\.x\=\" לְ"\.y\=\,-1%{", דְּ"\.x\=\" לְ"\.y\=\;}%". "c}%

Store the nouns and actions in variables by splitting strings.
Using a list of lists of increasing sizes, each in descending order - [[1],[2,1],[3,2,1]...] - print the first and subsequent lines of each stanza using those index values.


问:
List of primes under a million
This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines.

The task is to print out, in ascending order, all of the prime numbers less than a million. The output format should be one number per line of output.

The aim, as with most code golf submissions, is to minimise code size. Optimising for runtime is also a bonus, but is a secondary objective.

答:
Molecule (v6+), 19 bytes

```<code>0{1+_p?~}u1000000L
</code>```

Explanation:

```<code>0{1+_p?~}u1000000L
0{1+_p?~}          Push 0, add a code block.
         u1000000  Push one million.
                 L Repeat the code block 1000000 times.
</code>```

ContentLicense: CC BY-SA 3.0

Title: List of primes under a million

Body:
Molecule (v6+), 19 bytes

0{1+_p?~}u1000000L

Explanation:

0{1+_p?~}u1000000L
0{1+_p?~}          Push 0, add a code block.
         u1000000  Push one million.
                 L Repeat the code block 1000000 times.

ContentLicense: CC BY-SA 4.0


问:
Reverse positive runs

Input

Your input is a list of single-digit numbers in any reasonable format, including a string of digits.
The input will not be empty.

Output

Your output shall be the input list, but with each maximal run of nonzero digits being reversed.

Example

Consider the input

```<code>95883007414830
<--->  <---->
</code>```

where the nonzero runs have been marked with arrows.
Reversing each of these runs, we obtain the output

```<code>38859003841470
</code>```

Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

This challenge is related, but much more complex, since it includes additional string processing.

Test cases

```<code>4 -> 4
00 -> 00
123 -> 321
0010 -> 0010
12000345 -> 21000543
18161604 -> 61618104
95883007414830 -> 38859003841470
010230456078912 -> 010320654021987
357509902003550 -> 575309902005530
2492882377675046 -> 5767732882942064
03026302053000357099 -> 03036202035000753099
</code>```

Leaderboard

Here's a Stack Snippet to generate a leaderboard and list of winners by language.
To make sure your answer shows up, start it with a header of the form

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

You can keep old scores in the header by using the strikethrough tags: <s>57</s> will appear as <s>57</s>.

/* Configuration */

var QUESTION_ID = 78510; // 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 = 32014; // 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,]*[^\s,]),.*?(-?\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,
      });

  });

  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;
    if (! /<a/.test(lang)) lang = '' + lang + '';
    lang = jQuery(lang).text().toLowerCase();

    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.uniq > b.uniq) return 1;
    if (a.uniq < b.uniq) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

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

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

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

table thead {
  font-weight: bold;
}

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
C#, 133 bytes

Golfed

String m(String s){for(int i=0,p=i;i<s.Length;i++){if(s[i]=='0'){p=i+1;}else{s=s.Insert(p,s[i].ToString()).Remove(i+1,1);}}return s;}
```
<hr />
<p><strong>Ungolfed</strong></p>
<pre class="lang-cs prettyprint-override"><code>String m( String s ) {
    // i = Index on the String
    // p = Pointer of the last '0' found
    for (int i = 0, p = i; i < s.Length; i++) {
        if (s[ i ] == '0') {
            // Move the 'p' pointer to the index after this '0'
            p = i + 1;
        } else {
            // Insert the Char at the Index location to the Pointer location
            //    and remove the one at the Index Location + 1,
            //    since the String was incremented by one char due to the 'Insert()'.
            s = s.Insert( p, s[ i ].ToString() )
                 .Remove( i + 1, 1 );
        }
    }

    return s;
}
</code>```

Full code

using System;
using System.Collections.Generic;

namespace Namespace {
    class Program {
        static void Main( String[] args ) {
            List<String> ls = new List<String>() {
                "4",
                "00",
                "123",
                "0010",
                "12000345",
                "18161604",
                "95883007414830",
                "010230456078912",
                "357509902003550",
                "2492882377675046",
                "03026302053000357099"
            };

            foreach (String s in ls) {
                String f = m( s );

                Console.WriteLine( String.Format( "{0,30}", s.Replace( "0", "0 " ) ) );
                Console.WriteLine( String.Format( "{0,30}", f.Replace( "0", "0 " ) ) );
                Console.WriteLine( "" );
            }

            Console.ReadLine();
        }

        static String m( String s ) {
            for (Int32 i = 0, p = i; i < s.Length; i++) {
                if (s[ i ] == '0') {
                    p = i + 1;
                } else {
                    s = s.Insert( p, s[ i ].ToString() ).Remove( i + 1, 1 );
                }
            }

            return s;
        }
    }
}
```

Title: Reverse positive runs

Body:
C#, 133 bytes

Golfed

String m(String s){for(int i=0,p=i;i<s.Length;i++){if(s[i]=='0'){p=i+1;}else{s=s.Insert(p,s[i].ToString()).Remove(i+1,1);}}return s;}

Ungolfed

String m( String s ) {
    // i = Index on the String
    // p = Pointer of the last '0' found
    for (int i = 0, p = i; i < s.Length; i++) {
        if (s[ i ] == '0') {
            // Move the 'p' pointer to the index after this '0'
            p = i + 1;
        } else {
            // Insert the Char at the Index location to the Pointer location
            //    and remove the one at the Index Location + 1,
            //    since the String was incremented by one char due to the 'Insert()'.
            s = s.Insert( p, s[ i ].ToString() )
                 .Remove( i + 1, 1 );
        }
    }

    return s;
}

Full code

using System;
using System.Collections.Generic;

namespace Namespace {
    class Program {
        static void Main( String[] args ) {
            List<String> ls = new List<String>() {
                "4",
                "00",
                "123",
                "0010",
                "12000345",
                "18161604",
                "95883007414830",
                "010230456078912",
                "357509902003550",
                "2492882377675046",
                "03026302053000357099"
            };

            foreach (String s in ls) {
                String f = m( s );

                Console.WriteLine( String.Format( "{0,30}", s.Replace( "0", "0 " ) ) );
                Console.WriteLine( String.Format( "{0,30}", f.Replace( "0", "0 " ) ) );
                Console.WriteLine( "" );
            }

            Console.ReadLine();
        }

        static String m( String s ) {
            for (Int32 i = 0, p = i; i < s.Length; i++) {
                if (s[ i ] == '0') {
                    p = i + 1;
                } else {
                    s = s.Insert( p, s[ i ].ToString() ).Remove( i + 1, 1 );
                }
            }

            return s;
        }
    }
}


答:
Perl, 22 bytes

Including +1 for -p option:

```<code>s/[^0]+/reverse$&/eg
</code>```

This is a pretty trivial substitution - sorry to be so boring.  Note that if your input is newline-terminated (e.g. using perl -pe 's/[^0]+/reverse$&/eg' <<<21000543 in Bash), it will catch the newline with the digits - use echo -n or printf to avoid that.  Alternatively, for a cost of one additional byte, change the character class to [1-9], and you can provide many inputs, one per line.

Title: Reverse positive runs

Body:
Input

Your input is a list of single-digit numbers in any reasonable format, including a string of digits.
The input will not be empty.

Output

Your output shall be the input list, but with each maximal run of nonzero digits being reversed.

Example

Consider the input

```<code>95883007414830
<--->  <---->
</code>```

where the nonzero runs have been marked with arrows.
Reversing each of these runs, we obtain the output

```<code>38859003841470
</code>```

Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

This challenge is related, but much more complex, since it includes additional string processing.

Test cases

```<code>4 -> 4
00 -> 00
123 -> 321
0010 -> 0010
12000345 -> 21000543
18161604 -> 61618104
95883007414830 -> 38859003841470
010230456078912 -> 010320654021987
357509902003550 -> 575309902005530
2492882377675046 -> 5767732882942064
03026302053000357099 -> 03036202035000753099
</code>```

Leaderboard

Here's a Stack Snippet to generate a leaderboard and list of winners by language.
To make sure your answer shows up, start it with a header of the form

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

You can keep old scores in the header by using the strikethrough tags: <s>57</s> will appear as <s>57</s>.

/* Configuration */

var QUESTION_ID = 78510; // 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 = 32014; // 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,]*[^\s,]),.*?(-?\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,
      });

  });

  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;
    if (! /<a/.test(lang)) lang = '' + lang + '';
    lang = jQuery(lang).text().toLowerCase();

    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.uniq > b.uniq) return 1;
    if (a.uniq < b.uniq) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

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

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

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

table thead {
  font-weight: bold;
}

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Perl, 22 bytes

Including +1 for -p option:

s/[^0]+/reverse$&/eg

This is a pretty trivial substitution - sorry to be so boring.  Note that if your input is newline-terminated (e.g. using perl -pe 's/[^0]+/reverse$&/eg' <<<21000543 in Bash), it will catch the newline with the digits - use echo -n or printf to avoid that.  Alternatively, for a cost of one additional byte, change the character class to [1-9], and you can provide many inputs, one per line.


问:
Shoot the ASCII Moon
(Previously on "Print the __ without using __" ... this one and this one)

The game of Hearts has a popular scoring variant called "Shooting the Moon," whereby instead of trying to not acquire penalty cards (and thus penalty points), as is the usual gameplay strategy, if you acquire all of the penalty cards you actually score the best that round. We're going to apply that same logic to some code golf.

The ASCII printable characters (plus space) are, in order

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

Let's divide these into three groups:

Alphanumeric:

```<code>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
</code>```

Symbolic (or non-alphanumeric)

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

and the space character.

Your task is to use the alphanumeric characters to print the symbolic characters (in any order), with the following restrictions:

The program/function should take no input and output to STDOUT (or equivalent).

You can use a symbolic character in your source code for a penalty of +5 per unique character.

Using the same character more than once does not increase your penalty (e.g., you can use [ 25 times and only get one +5 penalty)

Whitespace (including tabs and newlines) in the output or the source code is completely optional. Leading, trailing, inline - no penalties or bonuses. They still count for bytes in source code as usual.

If you manage to use all 32 symbolic characters in your code, you get a bonus of -100 points for Shooting the Moon instead of any penalties.

If you manage to use all 32 symbolic and all 62 alphanumeric characters in your code, you instead get a bonus of -250 points for Shooting the Sun instead of any penalties.

Characters inside literal strings, literal characters, or comments do not count for the bonus or the penalty. (E.g., a Foo program of something like "!#$%..." would be allowed, but would not get the bonus or penalty points for the characters inside the literal).

Literal string or comment delimiters do count, however, so something like // !#$*... would count the initial / for penalty/bonus calculations.

Yes, this rules out languages like Whitespace or the like, where everything not whitespace is treated as a comment. Bummer.

Scoring is bytes of code + penalty(ies) + bonus(es), lowest score wins. Negative scores are possible.

Example scores:

50 bytes code + (5 unique symbolic characters)*5 penalty each = 75 points

200 bytes code + (32 unique symbolic characters)*0 penalty each + (-250 bonus for shooting the sun) = -50 points

答:
Batch, -143 bytes

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

107 bytes of source code: +107

Shooting the Sun: -250

I didn't think this would beat anyone. After all it's batch!

Title: Shoot the ASCII Moon

Body:
Batch, -143 bytes

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

107 bytes of source code: +107

Shooting the Sun: -250

I didn't think this would beat anyone. After all it's batch!


问:
Count up folks!

Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

答:
ArnoldC, 415 bytes

```<code>IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP 0
GET YOUR ASS TO MARS n
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE x
YOU SET US UP n
STICK AROUND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
GET UP 1
ENOUGH TALK
TALK TO THE HAND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED
</code>```

The only thing of interest is to use n-x (where n is the goal and x the incremented variable) to test the end of the while loop instead of having a dedicated variable, so I end up having n-x and n-(n-x) = x in each loop run

Note: I can only count to 2^31-1. Well I guess the Terminators are not a real danger after all.

Title: Count up folks!

Body:
ArnoldC, 415 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP 0
GET YOUR ASS TO MARS n
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE x
YOU SET US UP n
STICK AROUND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
GET UP 1
ENOUGH TALK
TALK TO THE HAND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

The only thing of interest is to use n-x (where n is the goal and x the incremented variable) to test the end of the while loop instead of having a dedicated variable, so I end up having n-x and n-(n-x) = x in each loop run

Note: I can only count to 2^31-1. Well I guess the Terminators are not a real danger after all.


问:
Exploded substrings

Introduction

Let's observe the string abc. The substrings that can be made from this are:

```<code>a, ab, abc, b, bc, c
</code>```

We now need to align them under the initial string, like this:

```<code>abc
a
 b
  c
ab
 bc
abc
</code>```

The order of the string doesn't matter, so this is also perfectly valid:

```<code>abc
a
ab
abc
 b
 bc
  c
</code>```

So, the substring is positioned under the location of the substring in the initial string. So for abcdef and the substring cde, it would look like this:

```<code>abcdef
  cde
</code>```

The Task

The task is to align all substrings with a length greater than 0, like shown above. You can assume that the string itself will only contain alphabetic characters and has at least 1 character. For the padding, you can use a space or some other non-alphabetic printable ASCII character (32 - 127). Maybe not necessary to mention, but the string itself will only contain unique characters, so not like aba, since the a occurs twice.

Test cases

Input: abcde

Possible output:

```<code>a
ab
abc
abcd
abcde
 b
 bc
 bcd
 bcde
  c
  cd
  cde
   d
   de
    e
</code>```

Input: abcdefghij

Possible output:

```<code>a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
 b
 bc
 bcd
 bcde
 bcdef
 bcdefg
 bcdefgh
 bcdefghi
 bcdefghij
  c
  cd
  cde
  cdef
  cdefg
  cdefgh
  cdefghi
  cdefghij
   d
   de
   def
   defg
   defgh
   defghi
   defghij
    e
    ef
    efg
    efgh
    efghi
    efghij
     f
     fg
     fgh
     fghi
     fghij
      g
      gh
      ghi
      ghij
       h
       hi
       hij
        i
        ij
         j
</code>```

This is code-golf, so the submission with the least amount of bytes wins!

答:
Pyth, <s>14</s> <s>13</s> 10 bytes

Thanks to @FryAmTheEggman for saving 3 bytes.

```<code>jmXQ-Qd;.:
</code>```

Try it online!

Title: Exploded substrings

Body:
Pyth, <s>14</s> <s>13</s> 10 bytes

Thanks to @FryAmTheEggman for saving 3 bytes.

jmXQ-Qd;.:

Try it online!


问:
Watson-Crick palindromes

Problem

Create a function that can determine whether or not an arbitrary DNA string is a Watson-Crick palindrome. The function will take a DNA string and output a true  value if the string is a Watson-Crick palindrome and a false value if it is not. (True and False can also be represented as 1 and 0, respectively.)

The DNA string may either be in all uppercase or all lowercase depending on your preference.

Also, the DNA string will not be empty.

Explanation

A DNA string is a Watson-Crick palindrome when the complement of its reverse is equal to itself.

Given a DNA string, first reverse it, and then complement each character according to the DNA bases (A ↔ T and C ↔ G). If the original string is equal to the complemented-reverse string, it is a Watson-Crick palindrome.

For more, see this question. It is a different challenge where you must find the longest substring of a DNA string where that substring is a Watson-Crick palindrome.

Goal

This is code-golf and the shortest code wins.

Test Cases

The format is <input> = <output>.

```<code>ATCGCGAT = true
AGT = false
GTGACGTCAC = true
GCAGTGA = false
GCGC = true
AACTGCGTTTAC = false
ACTG = false
</code>```

答:
C#, 65 bytes

```<code>bool F(string s)=>s.SequenceEqual(s.Reverse().Select(x=>"GACT"[("GACT".IndexOf(x)+2)%4]));
</code>```

.NET has some fairly long framework method names at times, which doesn't necessarily make for the best code golf framework. In this case, framework method names make up 33 characters out of 90. :)

Based on the modulus trick from elsewhere in the thread:

```<code>bool F(string s)=>s.Zip(s.Reverse(),(a,b)=>a%8+b%8).All(x=>x%5==0);
</code>```

Now weighs in at 67 characters whereof 13 are method names.

Another minor optimization to shave off a whopping 2 characters:

```<code>bool F(string s)=>s.Zip(s.Reverse(),(a,b)=>(a%8+b%8)%5).Sum()<1;
</code>```

So, 65 of which 13 are framework names.

Edit:
Omitting some of the limited "boilerplate" from the solution and adding a couple of conditions leaves us with the expression

```<code>s.Zip(s.Reverse(),(a,b)=>(a%8+b%8)%5).Sum()
</code>```

Which gives 0 if and only if the string s is a valid answer.
As cat points out, "bool F(string s)=>" is actually replacable with "s=>" if it's otherwise clear in the code that the expression is a Func<string,bool>, ie. maps a string to a boolean.

Title: Watson-Crick palindromes

Body:
C#, 65 bytes

bool F(string s)=>s.SequenceEqual(s.Reverse().Select(x=>"GACT"[("GACT".IndexOf(x)+2)%4]));

.NET has some fairly long framework method names at times, which doesn't necessarily make for the best code golf framework. In this case, framework method names make up 33 characters out of 90. :)

Based on the modulus trick from elsewhere in the thread:

bool F(string s)=>s.Zip(s.Reverse(),(a,b)=>a%8+b%8).All(x=>x%5==0);

Now weighs in at 67 characters whereof 13 are method names.

Another minor optimization to shave off a whopping 2 characters:

bool F(string s)=>s.Zip(s.Reverse(),(a,b)=>(a%8+b%8)%5).Sum()<1;

So, 65 of which 13 are framework names.

Edit:
Omitting some of the limited "boilerplate" from the solution and adding a couple of conditions leaves us with the expression

s.Zip(s.Reverse(),(a,b)=>(a%8+b%8)%5).Sum()

Which gives 0 if and only if the string s is a valid answer.
As cat points out, "bool F(string s)=>" is actually replacable with "s=>" if it's otherwise clear in the code that the expression is a Func<string,bool>, ie. maps a string to a boolean.


问:
Calculate the Kronecker sum of two matrices
In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed.

A Kronecker product has the following properties:

```<code>A⊗B =  A(1,1)*B   A(1,2)*B
        A(2,1)*B   A(2,2)*B

     =  A(1,1)*B(1,1)   A(1,1)*B(1,2)   A(1,2)*B(1,1)   A(1,2)*B(1,2)
        A(1,1)*B(2,1)   A(1,1)*B(2,2)   A(1,2)*B(2,1)   A(1,2)*B(2,2)
        A(2,1)*B(1,1)   A(2,1)*B(1,2)   A(2,2)*B(1,1)   A(2,2)*B(1,2)
        A(2,2)*B(2,1)   A(2,2)*B(1,2)   A(2,2)*B(2,1)   A(2,2)*B(2,2)
</code>```

A Kronecker sum has the following properties:

```<code>A⊕B = A⊗Ib + Ia⊗B
</code>```

Ia and Ib are the identity matrices with the dimensions of A and B respectively. A and B are square matrices. Note that A and B can be of different sizes.

```<code>A⊕B =  A(1,1)+B(1,1)  B(1,2)         A(1,2)         0
        B(2,1)         A(1,1)+B(2,2)  0              A(1,2)
        A(2,1)         0              A(2,2)+B(1,1)  B(1,2)
        0              A(2,1)         B(2,1)         A(2,2)+B(2,2)
</code>```

Given two square matrices, A and B, calculate the Kronecker sum of the two matrices.

The size of the matrices will be at least 2-by-2. The maximum size will be whatever your computer / language can handle by default, but minimum 5-by-5 input (5 MB output).

All input values will be non-negative integers

Builtin functions that calculate the Kronecker sum or Kronecker products are not allowed

In general: Standard rules regarding I/O format, program & functions, loopholes etc.

Test cases:

```<code>A =
     1     2
     3     4
B =
     5    10
     7     9

A⊕B =
     6    10     2     0
     7    10     0     2
     3     0     9    10
     0     3     7    13

----

A =
    28    83    96
     5    70     4
    10    32    44
B =
    39    19    65
    77    49    71
    80    45    76

A⊕B =
    67    19    65    83     0     0    96     0     0
    77    77    71     0    83     0     0    96     0
    80    45   104     0     0    83     0     0    96
     5     0     0   109    19    65     4     0     0
     0     5     0    77   119    71     0     4     0
     0     0     5    80    45   146     0     0     4
    10     0     0    32     0     0    83    19    65
     0    10     0     0    32     0    77    93    71
     0     0    10     0     0    32    80    45   120

----

A =
    76    57    54
    76     8    78
    39     6    94
B =
    59    92
    55    29

A⊕B =
   135    92    57     0    54     0
    55   105     0    57     0    54
    76     0    67    92    78     0
     0    76    55    37     0    78
    39     0     6     0   153    92
     0    39     0     6    55   123
</code>```

答:
Ruby, 102

```<code>->a,b{r=0..-1+a.size*q=b.size
r.map{|i|r.map{|j|(i/q==j/q ?b[i%q][j%q]:0)+(i%q==j%q ?a[i/q][j/q]:0)}}}
</code>```

In test program

```<code>f=->a,b{r=0..-1+a.size*q=b.size
r.map{|i|r.map{|j|(i/q==j/q ?b[i%q][j%q]:0)+(i%q==j%q ?a[i/q][j/q]:0)}}}

aa =[[1,2],[3,4]]
bb =[[5,10],[7,9]]
f[aa,bb].each{|e|p e}
puts

aa =[[28,83,96],[5,70,4],[10,32,44]]
bb =[[39,19,65],[77,49,71],[80,45,76]]
f[aa,bb].each{|e|p e}
puts

aa =[[76,57,54],[76,8,78],[39,6,94]]
bb =[[59,92],[55,29]]
f[aa,bb].each{|e|p e}
puts
</code>```

Requires two 2D arrays as input and returns a 2D array.

There are probably better ways of doing this: using a function to avoid repetition; using a single loop and printing the output. Will look into them later.

Body:
Ruby, 102

->a,b{r=0..-1+a.size*q=b.size
r.map{|i|r.map{|j|(i/q==j/q ?b[i%q][j%q]:0)+(i%q==j%q ?a[i/q][j/q]:0)}}}

In test program

f=->a,b{r=0..-1+a.size*q=b.size
r.map{|i|r.map{|j|(i/q==j/q ?b[i%q][j%q]:0)+(i%q==j%q ?a[i/q][j/q]:0)}}}

aa =[[1,2],[3,4]]
bb =[[5,10],[7,9]]
f[aa,bb].each{|e|p e}
puts

aa =[[28,83,96],[5,70,4],[10,32,44]]
bb =[[39,19,65],[77,49,71],[80,45,76]]
f[aa,bb].each{|e|p e}
puts

aa =[[76,57,54],[76,8,78],[39,6,94]]
bb =[[59,92],[55,29]]
f[aa,bb].each{|e|p e}
puts

Requires two 2D arrays as input and returns a 2D array.

There are probably better ways of doing this: using a function to avoid repetition; using a single loop and printing the output. Will look into them later.


答:
MATL, <s>20</s> 18 bytes

Inspired by the pattern of substrings generated by @aditsu's answer

```<code>tt!+gR*c`t3Lt3$)tn
</code>```

Try it online!

The pattern of substrings is generated by an upper triangular matrix the same size as the input, and all submatrices obtained by successively removing the last row and column.

Explanation

```<code>t         % implicit input. Duplicate
t!+g      % square matrix with size as input
R         % keep upper triangular part
*c        % multiply element-wise with broadcast. Convert to char
`         % do...while
  t       %   duplicate
  3Lt3$)  %   remove last row and column
  tn      %   number of remaining elements. Used as loop condition
          % implicitly end loop and display
</code>```

Old approach (Cartesian power)

I'm keeping this approach in case it serves as inspiration for other answers

```<code>tn0:2Z^!S!2\Xu4LY)*c
</code>```

In the online compiler this runs out of memory for the longest test case.

Try it online!

Explanation

This generates all patterns of values 0, 1 and 2 in increasing order, and then transforms 2 into 0. This gives all possible patterns of 0 and 1 where the 1 values are contiguous. These are used to mark which characters are taken from the original string.

As an example, for string 'abc' the patterns are generated as follows. First the Cartesian power of [0 1 2] raised to the number of input characters is obtained:

```<code>0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
···
2 2 1
2 2 2
</code>```

Sorting each row gives

```<code>0 0 0
0 0 1
0 0 2
0 0 1
0 1 1
···
1 2 2
2 2 2
</code>```

Transforming 2 into 0 (i.e. mod(...,2)) and removing duplicate rows gives the final pattern

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

in which each row is a mask corresponding to a (contiguous) substring. The first row needs to be removed because it corresponds to the empty substring.

```<code>t      % Implicitly get input. Duplicate
n      % Number of elements
0:2    % Vector [0 1 2]
Z^     % Cartesian power. Each result is a row
!S!    % Sort each row
2\     % Modulo 2: transform 2 into 0
Xu     % Unique rows
4LY)   % Remove first (corresponds to the empty substring)
*      % Element-wise multiplication by original string
c      % Convert to char. Implicitly display
</code>```

Title: Exploded substrings

Body:
Introduction

Let's observe the string abc. The substrings that can be made from this are:

```<code>a, ab, abc, b, bc, c
</code>```

We now need to align them under the initial string, like this:

```<code>abc
a
 b
  c
ab
 bc
abc
</code>```

The order of the string doesn't matter, so this is also perfectly valid:

```<code>abc
a
ab
abc
 b
 bc
  c
</code>```

So, the substring is positioned under the location of the substring in the initial string. So for abcdef and the substring cde, it would look like this:

```<code>abcdef
  cde
</code>```

The Task

The task is to align all substrings with a length greater than 0, like shown above. You can assume that the string itself will only contain alphabetic characters and has at least 1 character. For the padding, you can use a space or some other non-alphabetic printable ASCII character (32 - 127). Maybe not necessary to mention, but the string itself will only contain unique characters, so not like aba, since the a occurs twice.

Test cases

Input: abcde

Possible output:

```<code>a
ab
abc
abcd
abcde
 b
 bc
 bcd
 bcde
  c
  cd
  cde
   d
   de
    e
</code>```

Input: abcdefghij

Possible output:

```<code>a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
 b
 bc
 bcd
 bcde
 bcdef
 bcdefg
 bcdefgh
 bcdefghi
 bcdefghij
  c
  cd
  cde
  cdef
  cdefg
  cdefgh
  cdefghi
  cdefghij
   d
   de
   def
   defg
   defgh
   defghi
   defghij
    e
    ef
    efg
    efgh
    efghi
    efghij
     f
     fg
     fgh
     fghi
     fghij
      g
      gh
      ghi
      ghij
       h
       hi
       hij
        i
        ij
         j
</code>```

This is code-golf, so the submission with the least amount of bytes wins!

Body:
MATL, <s>20</s> 18 bytes

Inspired by the pattern of substrings generated by @aditsu's answer

tt!+gR*c`t3Lt3$)tn

Try it online!

The pattern of substrings is generated by an upper triangular matrix the same size as the input, and all submatrices obtained by successively removing the last row and column.

Explanation

t         % implicit input. Duplicate
t!+g      % square matrix with size as input
R         % keep upper triangular part
*c        % multiply element-wise with broadcast. Convert to char
`         % do...while
  t       %   duplicate
  3Lt3$)  %   remove last row and column
  tn      %   number of remaining elements. Used as loop condition
          % implicitly end loop and display

Old approach (Cartesian power)

I'm keeping this approach in case it serves as inspiration for other answers

tn0:2Z^!S!2\Xu4LY)*c

In the online compiler this runs out of memory for the longest test case.

Try it online!

Explanation

This generates all patterns of values 0, 1 and 2 in increasing order, and then transforms 2 into 0. This gives all possible patterns of 0 and 1 where the 1 values are contiguous. These are used to mark which characters are taken from the original string.

As an example, for string 'abc' the patterns are generated as follows. First the Cartesian power of [0 1 2] raised to the number of input characters is obtained:

0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
···
2 2 1
2 2 2

Sorting each row gives

0 0 0
0 0 1
0 0 2
0 0 1
0 1 1
···
1 2 2
2 2 2

Transforming 2 into 0 (i.e. mod(...,2)) and removing duplicate rows gives the final pattern

0 0 0
0 0 1
0 1 1
0 1 0
1 1 1
1 1 0
1 0 0

in which each row is a mask corresponding to a (contiguous) substring. The first row needs to be removed because it corresponds to the empty substring.

t      % Implicitly get input. Duplicate
n      % Number of elements
0:2    % Vector [0 1 2]
Z^     % Cartesian power. Each result is a row
!S!    % Sort each row
2\     % Modulo 2: transform 2 into 0
Xu     % Unique rows
4LY)   % Remove first (corresponds to the empty substring)
*      % Element-wise multiplication by original string
c      % Convert to char. Implicitly display


答:
Retina, <s>48</s> <s>32</s> 31 bytes

Thanks to Kenny Lau for saving 3 bytes and paving the way for many more.

Byte count assumes ISO 8859-1 encoding.

```<code>M&!r`.+
%+`( *)\S(.+)$
$&¶$1 $2
</code>```

Try it online!

Order of the generated substrings:

```<code>abcde
 bcde
  cde
   de
    e
abcd
 bcd
  cd
   d
abc
 bc
  c
ab
 b
a
</code>```

Explanation

```<code>M&!r`.+
</code>```

This gets us all the prefixes of the input. This is done by matching (M) any substring (.+) starting from the end (r), considering overlapping matches (&) and returning all of those matches joined with linefeeds (!).

Now all we need to do is carve out the successive prefixes of those prefixes (by replacing them with spaces). We do this step by step with a loop:

```<code>%+`( *)\S(.+)$
$&¶$1 $2
</code>```

The % means that this entire thing is done to each line individually (considering it a separate string for time being, and joining it all back together with linefeeds at the end). The + tells Retina to run this substitution in a loop until the output stops changing (which in this case means that the regex no longer matches). The regex then tries to match the last line of the input with at least two non-space characters, and appends a new row where the first of those is replaced with a space.

Title: Exploded substrings

Body:
Retina, <s>48</s> <s>32</s> 31 bytes

Thanks to Kenny Lau for saving 3 bytes and paving the way for many more.

Byte count assumes ISO 8859-1 encoding.

M&!r`.+
%+`( *)\S(.+)$
$&¶$1 $2

Try it online!

Order of the generated substrings:

abcde
 bcde
  cde
   de
    e
abcd
 bcd
  cd
   d
abc
 bc
  c
ab
 b
a

Explanation

M&!r`.+

This gets us all the prefixes of the input. This is done by matching (M) any substring (.+) starting from the end (r), considering overlapping matches (&) and returning all of those matches joined with linefeeds (!).

Now all we need to do is carve out the successive prefixes of those prefixes (by replacing them with spaces). We do this step by step with a loop:

%+`( *)\S(.+)$
$&¶$1 $2

The % means that this entire thing is done to each line individually (considering it a separate string for time being, and joining it all back together with linefeeds at the end). The + tells Retina to run this substitution in a loop until the output stops changing (which in this case means that the regex no longer matches). The regex then tries to match the last line of the input with at least two non-space characters, and appends a new row where the first of those is replaced with a space.


答:
JavaScript (ES6), 89 bytes

document.write("```"+(

s=>(a=[...s]).map((_,i)=>a.map((_,j)=>++j>i?r+=" ".repeat(i)+s.slice(i,j)+`
`:0),r="")&&r

)("abcde"))</code>```

Straight-forward approach. Output has a trailing newline.

Title: Exploded substrings

Body:
JavaScript (ES6), 89 bytes

document.write("<pre>"+(

s=>(a=[...s]).map((_,i)=>a.map((_,j)=>++j>i?r+=" ".repeat(i)+s.slice(i,j)+`
`:0),r="")&&r

)("abcde"))

Straight-forward approach. Output has a trailing newline.


问:
Print NxN spiral of ascending numbers
The numbers should be printed with leading zeroes in a field with length = (number of digits of N^2).

Input (N):

```<code>4
</code>```

Output:

```<code>01 12 11 10
02 13 16 09
03 14 15 08
04 05 06 07
</code>```

I am interested in the algorithm and the cleanliness of the implementation.
So, the white space does not count and the upper limit for N is 42.

答:
In Python3:

```<code>n=int(input())
results = {}
val = 1
location = (0,0)
direction = (0,1)

def nxt():
    return (location[0]+direction[0], location[1]+direction[1])

while val<=n*n:
    if set([-1,n]).intersection(nxt()) or nxt() in results:
        direction = (direction[1],direction[0]*-1)

    results[location], location, val = str(val), nxt(), val+1

slen = len(str(n*n))
for y in range(n):
    print( *[results[(x,y)].rjust(slen,'0') for x in range(n)] )
</code>```

Sample Output for 7:

```<code>01 24 23 22 21 20 19
02 25 40 39 38 37 18
03 26 41 48 47 36 17
04 27 42 49 46 35 16
05 28 43 44 45 34 15
06 29 30 31 32 33 14
07 08 09 10 11 12 13
</code>```

edit: A recursive solution - 263 Bytes

```<code>def a(m,s):
 b,r,t=m-s*s+1,s-1,range
 return[[[]],[[m]]][s]if s<2 else[[b]+list(t(b+4*r-1,b+3*r-1,-1))]+[[b+y+1]+a(m,s-2)[y]+[b+3*r-y-1]for y in t(s-2)]+[list(t(b+r,b+2*r+1))]
n=int(input())
for r in a(n*n,n):
 print(*[str(x).zfill(len(str(n*n)))for x in r])
</code>```

Title: Print NxN spiral of ascending numbers

Body:
In Python3:

n=int(input())
results = {}
val = 1
location = (0,0)
direction = (0,1)

def nxt():
    return (location[0]+direction[0], location[1]+direction[1])

while val<=n*n:
    if set([-1,n]).intersection(nxt()) or nxt() in results:
        direction = (direction[1],direction[0]*-1)

    results[location], location, val = str(val), nxt(), val+1

slen = len(str(n*n))
for y in range(n):
    print( *[results[(x,y)].rjust(slen,'0') for x in range(n)] )

Sample Output for 7:

01 24 23 22 21 20 19
02 25 40 39 38 37 18
03 26 41 48 47 36 17
04 27 42 49 46 35 16
05 28 43 44 45 34 15
06 29 30 31 32 33 14
07 08 09 10 11 12 13

edit: A recursive solution - 263 Bytes

def a(m,s):
 b,r,t=m-s*s+1,s-1,range
 return[[[]],[[m]]][s]if s<2 else[[b]+list(t(b+4*r-1,b+3*r-1,-1))]+[[b+y+1]+a(m,s-2)[y]+[b+3*r-y-1]for y in t(s-2)]+[list(t(b+r,b+2*r+1))]
n=int(input())
for r in a(n*n,n):
 print(*[str(x).zfill(len(str(n*n)))for x in r])

ContentLicense: CC BY-SA 2.5


问:
Generate a parity bit
A parity bit, is one of the simplest forms of a checksum. First, you have to pick the parity, even or odd. Let's say we pick even. Now, we need a message to transmit. Let's say our message is "Foo". This is written in binary as:

```<code>01000110 01101111 01101111
</code>```

Now, we count the total number of 1's in there, which is 15. Since 15 is an odd number, we must add one extra bit to the end of our message, and we will now have an even number of 'on' bits. This last added bit is known as the "parity bit". If we had picked an odd parity for our checksum, we would have to add an extra '0' so that the number of on bits remains odd.

The challenge:

You must write a program or function that determines what the correct parity bit for a string is. Your program must take two inputs:

A string, s. This is the message that the checksum will be calculated on. This will be restricted to the 95 printable ASCII characters.

A character or single character string p, that will either be e for even parity, or o for odd parity.

and produce a truthy-falsey value representing the correct parity bit. Truthy if it's a 1, and falsey if it's a 0.

Builtins that count the number of "on" bits in a string or character are not allowed. For example, a function f that does this: f('a') == 3 or f('foo') == 16 is banned. Anything else, such as base conversion, is fair game.

Test IO:

```<code>(without the quotes)
s: "0"
p: 'e'
output: 0

s: "Foo"
p: 'e'
output: 1

s: "Hello World!"
p: 'o'
output: 0

s: "Alex is right"
p: 'e'
output: 1

s: "Programming Puzzles and Code-Golf"
p: 'e'
output: 0

s: "Programming Puzzles and Code-Golf"
p: 'o'
output: 1
</code>```

This is codegolf, so standard loopholes apply, and the shortest answer in bytes wins.

Leaderboard

var QUESTION_ID=78569,OVERRIDE_USER=31716;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

```

答:
05AB1E, <s>15</s>, 13 bytes

Code:

```<code>€ÇbSOÈ„oe²k<^
</code>```

Example Input:

```<code>Programming Puzzles and Code-Golf
o
</code>```

Example Output:

```<code>1
</code>```

Explanation:

```<code>€                 # for each char in string
 Ç                # get ascii value
  b               # convert to binary
   S              # split to single chars (ex: '1101' to '1','1','0','1')
    O             # sum
     È            # check if even
      „oe         # push string "oe"
         ²        # push 2nd input (p)
          k       # get 1-based index of p in "oe"
           <      # decrease (to get either 0-based index)
            ^     # xor with result of È
</code>```

Thanks to Adnan for saving 2 bytes.

Title: Generate a parity bit

Body:
05AB1E, <s>15</s>, 13 bytes

Code:

€ÇbSOÈ„oe²k<^

Example Input:

Programming Puzzles and Code-Golf
o

Example Output:

1

Explanation:

€                 # for each char in string
 Ç                # get ascii value
  b               # convert to binary
   S              # split to single chars (ex: '1101' to '1','1','0','1')
    O             # sum
     È            # check if even
      „oe         # push string "oe"
         ²        # push 2nd input (p)
          k       # get 1-based index of p in "oe"
           <      # decrease (to get either 0-based index)
            ^     # xor with result of È

Thanks to Adnan for saving 2 bytes.


答:
sed, <s>67</s> 61 bytes

G;H;:1;s/\(.\)\(.*\n\)/\2\1/;t1;y/ACGT/TGCA/;G;s/^\(.*\)\1$/1/;t;c0
```

<p>(67 bytes)</p>

<h3>Test</h3>

<pre class="lang-bash prettyprint-override"><code>for line in ATCGCGAT AGT GTGACGTCAC GCAGTGA GCGC AACTGCGTTTAC ACTG
do echo -n "$line "
    sed 'G;H;:1;s/\(.\)\(.*\n\)/\2\1/;t1;y/ACGT/TGCA/;G;s/^\(.*\)\1$/1/;t;c0' <<<"$line"
done
</code>```

Output

ATCGCGAT 1
AGT 0
GTGACGTCAC 1
GCAGTGA 0
GCGC 1
AACTGCGTTTAC 0
ACTG 0
```

<hr>

<p>By using extended regular expressions, the byte count can be reduced to 61.</p>

```sed -r 'G;H;:1;s/(.)(.*\n)/\2\1/;t1;y/ACGT/TGCA/;G;s/^(.*)\1$/1/;t;c0'
```

Title: Watson-Crick palindromes

Body:
Problem

Create a function that can determine whether or not an arbitrary DNA string is a Watson-Crick palindrome. The function will take a DNA string and output a true  value if the string is a Watson-Crick palindrome and a false value if it is not. (True and False can also be represented as 1 and 0, respectively.)

The DNA string may either be in all uppercase or all lowercase depending on your preference.

Also, the DNA string will not be empty.

Explanation

A DNA string is a Watson-Crick palindrome when the complement of its reverse is equal to itself.

Given a DNA string, first reverse it, and then complement each character according to the DNA bases (A ↔ T and C ↔ G). If the original string is equal to the complemented-reverse string, it is a Watson-Crick palindrome.

For more, see this question. It is a different challenge where you must find the longest substring of a DNA string where that substring is a Watson-Crick palindrome.

Goal

This is code-golf and the shortest code wins.

Test Cases

The format is <input> = <output>.

```<code>ATCGCGAT = true
AGT = false
GTGACGTCAC = true
GCAGTGA = false
GCGC = true
AACTGCGTTTAC = false
ACTG = false
</code>```

Body:
sed, <s>67</s> 61 bytes

G;H;:1;s/\(.\)\(.*\n\)/\2\1/;t1;y/ACGT/TGCA/;G;s/^\(.*\)\1$/1/;t;c0

(67 bytes)

Test

for line in ATCGCGAT AGT GTGACGTCAC GCAGTGA GCGC AACTGCGTTTAC ACTG
do echo -n "$line "
    sed 'G;H;:1;s/\(.\)\(.*\n\)/\2\1/;t1;y/ACGT/TGCA/;G;s/^\(.*\)\1$/1/;t;c0' <<<"$line"
done

Output

ATCGCGAT 1
AGT 0
GTGACGTCAC 1
GCAGTGA 0
GCGC 1
AACTGCGTTTAC 0
ACTG 0

By using extended regular expressions, the byte count can be reduced to 61.

sed -r 'G;H;:1;s/(.)(.*\n)/\2\1/;t1;y/ACGT/TGCA/;G;s/^(.*)\1$/1/;t;c0'


答:
C++, <s>92</s> 81 bytes

#include<cstdio>
long i,n;int main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}
```

<p>And another version, using <code>iostream</code>, with the same byte count</p>

<pre class="lang-cpp prettyprint-override"><code>#include<iostream>
long i,n;int main(){for(std::cin>>n;i++<n;std::cout<<i<<' ');}
</code>```

Not using long would result in 32-bit integers in most platforms<; <s>also, C++'s iostream library with their std:: namespace are more verbose than C's I/O.</s> (edit - I stand corrected, this is not true)

Update (-9 bytes): Learnt that return was optional in C++ thanks to @anatolyg

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Body:
C++, <s>92</s> 81 bytes

#include<cstdio>
long i,n;int main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}

And another version, using iostream, with the same byte count

#include<iostream>
long i,n;int main(){for(std::cin>>n;i++<n;std::cout<<i<<' ');}

Not using long would result in 32-bit integers in most platforms<; <s>also, C++'s iostream library with their std:: namespace are more verbose than C's I/O.</s> (edit - I stand corrected, this is not true)

Update (-9 bytes): Learnt that return was optional in C++ thanks to @anatolyg


答:
C, 61 bytes

long i,n;main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}
```

Essentially the same as my C++ answer, but C (or gcc) is more lenient of missing #includes, a missing return-type for main, and missing return-statements.

Title: Count up folks!

Body:
C, 61 bytes

long i,n;main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}

Essentially the same as my C++ answer, but C (or gcc) is more lenient of missing #includes, a missing return-type for main, and missing return-statements.


答:
CJam, 20

```<code>q{__,{\_N+oSt}/;W<}h
</code>```

Try it online

Explanation:

```<code>q           read the input (initial string)
{…}h        do … while
  _         copy the current string
  _,        copy and get the length
  {…}/      for each value (say i) from 0 to length-1
    \       bring the string to the top
    _N+o    make a copy, append a newline and print
    St      set the i'th element to S=" "
  ;         pop the last result (array full of spaces)
  W<        remove the last character of the current string
             if the string is empty, the do-while loop terminates
</code>```

Title: Exploded substrings

Body:
CJam, 20

q{__,{\_N+oSt}/;W<}h

Try it online

Explanation:

q           read the input (initial string)
{…}h        do … while
  _         copy the current string
  _,        copy and get the length
  {…}/      for each value (say i) from 0 to length-1
    \       bring the string to the top
    _N+o    make a copy, append a newline and print
    St      set the i'th element to S=" "
  ;         pop the last result (array full of spaces)
  W<        remove the last character of the current string
             if the string is empty, the do-while loop terminates


答:
C#, <s>136</s> <s>132</s> 131 bytes

Golfed

String m(String s){String o="",e=o;for(int i=0,a,l=s.Length;i<l;i++,e+=" ")for(a=1;a+i<=l;a++)o+=e+s.Substring(i,a)+"\n";return o;}
```
<hr />
<p><strong>Ungolfed</strong></p>
<pre class="lang-cs prettyprint-override"><code>String m( String s ) {
    String o = "", e = o;

    for (int i = 0, a, l = s.Length; i < l; i++, e += " ")
        for (a = 1; a + i <= l; a++)
            o += e + s.Substring( i, a ) + "\n";

    return o;
}
</code>```

Full code

    using System;
using System.Collections.Generic;

namespace Namespace {
    class Program {
        static void Main( string[] args ) {
            List<String> ls = new List<String>() {
                    "abcde",
                    "abcdefghijklmnop",
                    "0123456789",
                };

            foreach (String s in ls) {
                Console.WriteLine( s );
                Console.WriteLine( m( s ) );
                Console.WriteLine( "" );
            }

            Console.ReadLine();
        }

        static String m( String s ) {
            String o = "", e = o;

            for (int i = 0, a, l = s.Length; i < l; i++, e += " ")
                for (a = 1; a + i <= l; a++)
                    o += e + s.Substring( i, a ) + "\n";

            return o;
        }
    }
}
```

Releases

v1.2 - -1 byte - Changed the String o="",e=""; to String o="",e=o; to save 1 byte. The idea was from Gallant ( I forgot to apply this part in the last update, I apologize. ).

v1.1 -  -4 bytes - Droped the brackets from the for loops and moved the e var space increment to the iterator zone of the outer for loop. The idea was from Gallant.

v1.0 - 136 bytes - Initial solution.

Title: Exploded substrings

Body:
C#, <s>136</s> <s>132</s> 131 bytes

Golfed

String m(String s){String o="",e=o;for(int i=0,a,l=s.Length;i<l;i++,e+=" ")for(a=1;a+i<=l;a++)o+=e+s.Substring(i,a)+"\n";return o;}

Ungolfed

String m( String s ) {
    String o = "", e = o;

    for (int i = 0, a, l = s.Length; i < l; i++, e += " ")
        for (a = 1; a + i <= l; a++)
            o += e + s.Substring( i, a ) + "\n";

    return o;
}

Full code

    using System;
using System.Collections.Generic;

namespace Namespace {
    class Program {
        static void Main( string[] args ) {
            List<String> ls = new List<String>() {
                    "abcde",
                    "abcdefghijklmnop",
                    "0123456789",
                };

            foreach (String s in ls) {
                Console.WriteLine( s );
                Console.WriteLine( m( s ) );
                Console.WriteLine( "" );
            }

            Console.ReadLine();
        }

        static String m( String s ) {
            String o = "", e = o;

            for (int i = 0, a, l = s.Length; i < l; i++, e += " ")
                for (a = 1; a + i <= l; a++)
                    o += e + s.Substring( i, a ) + "\n";

            return o;
        }
    }
}

Releases

v1.2 - -1 byte - Changed the String o="",e=""; to String o="",e=o; to save 1 byte. The idea was from Gallant ( I forgot to apply this part in the last update, I apologize. ).

v1.1 -  -4 bytes - Droped the brackets from the for loops and moved the e var space increment to the iterator zone of the outer for loop. The idea was from Gallant.

v1.0 - 136 bytes - Initial solution.


问:
ECHO! Echo! echo. (echo)
Your challenge, should you choose to accept it, is simple:

Implement RFC 862, also known as the Echo Protocol:

The Echo protocol

An echo service simply sends back to the originating source any data it receives.

TCP Based Echo Service

One echo service is defined as a connection based application on TCP. A server listens for TCP connections on TCP port 7.  Once a connection is established any data received is sent back.  This continues until the calling user terminates the connection.

UDP Based Echo Service

Another echo service is defined as a datagram based application on UDP.  A server listens for UDP datagrams on UDP port 7.  When a datagram is received, the data from it is sent back in an answering datagram.

Scoring

The score is one point for every byte of code as encoded in UTF-8 or a language-specific code page, whichever is smaller.

If the program incompletely implements RFC 862 by providing only UDP or only TCP, the score is doubled.

If the program incorrectly implements RFC 862 by either using a port other than 7 or by dropping or transforming certain bytes due to language limitations or corner cutting, the score is quadrupled. (This stacks with the preceding point if applicable.)

If the program is invalid, the score is ω.

Rules

A valid program:

Does not use standard loopholes.

Per connection:

Accepts connections and receive incoming data.

Sends outgoing data in an amount that is always less than or equal to the amount of data received.

Does not invoke programs external to itself. (Spawning children to deal with multiple connections is fine, spinning up inetd or its local equivalent is not.)

Does not use library functions specifically designed to start and maintain an echo service.

This is code golf, so lowest score wins.

答:
Python, <s>299</s> <s>295</s> <s>265</s> 263

from threading import*
from socket import*
a='',7;S=socket
u=S(2,2);u.bind(a)
def U():
 while 1:u.sendto(*u.recvfrom(4**8))
Thread(None,U).start()
def C(c,x):
 while c.send(c.recv(1)):1
s=S(2,1);s.bind(a);s.listen(1)
while 1:Thread(None,C,args=s.accept()).start()
```

handles both udp and tcp.

@MorganThrapp helped saving 33 (!) chars

Title: ECHO! Echo! echo. (echo)

Body:
Python, <s>299</s> <s>295</s> <s>265</s> 263

from threading import*
from socket import*
a='',7;S=socket
u=S(2,2);u.bind(a)
def U():
 while 1:u.sendto(*u.recvfrom(4**8))
Thread(None,U).start()
def C(c,x):
 while c.send(c.recv(1)):1
s=S(2,1);s.bind(a);s.listen(1)
while 1:Thread(None,C,args=s.accept()).start()

handles both udp and tcp.

@MorganThrapp helped saving 33 (!) chars


答:
Oracle SQL 11.2, 146 bytes

WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))SELECT LPAD(SUBSTR(:1,s.i,l.i),s.i+l.i-1)FROM v s,v l WHERE s.i+l.i<=LENGTH(:1)+1;
```
<p>Un-golfed</p>
<pre class="lang-sql prettyprint-override"><code>WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))
SELECT LPAD(SUBSTR(:1,s.i,l.i),s.i+l.i-1)
FROM   v s, v l
WHERE  s.i+l.i<=LENGTH(:1)+1
</code>```

Title: Exploded substrings

Body:
Oracle SQL 11.2, 146 bytes

WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))SELECT LPAD(SUBSTR(:1,s.i,l.i),s.i+l.i-1)FROM v s,v l WHERE s.i+l.i<=LENGTH(:1)+1;

Un-golfed

WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))
SELECT LPAD(SUBSTR(:1,s.i,l.i),s.i+l.i-1)
FROM   v s, v l
WHERE  s.i+l.i<=LENGTH(:1)+1


答:
Python 2.7, <s>70</s> 82 bytes

I couldn't figure out how to get it on 1 line. Call with e("abcde",0)

```<code>def e(s,p):
 f=len(s)
 for x in range(f):print(' '*p+s[:x+1])
 if f>1:e(s[1:],p+1)
</code>```

Title: Exploded substrings

Body:
Python 2.7, <s>70</s> 82 bytes

I couldn't figure out how to get it on 1 line. Call with e("abcde",0)

def e(s,p):
 f=len(s)
 for x in range(f):print(' '*p+s[:x+1])
 if f>1:e(s[1:],p+1)


答:
Pyth, 12 11 bytes

```<code>jm+*;xQdd.:
</code>```

Sadly the question allows us to assume unique characters, so I just lookup the first position of the substring, and pad with spaces.

Title: Exploded substrings

Body:
Pyth, 12 11 bytes

jm+*;xQdd.:

Sadly the question allows us to assume unique characters, so I just lookup the first position of the substring, and pad with spaces.


答:
JavaScript (ES6), 72

s=>{for(i=j=0;s[j]||s[j=++i];)console.log(' '.repeat(i)+s.slice(i,++j))}
```

Title: Exploded substrings

Body:
Introduction

Let's observe the string abc. The substrings that can be made from this are:

```<code>a, ab, abc, b, bc, c
</code>```

We now need to align them under the initial string, like this:

```<code>abc
a
 b
  c
ab
 bc
abc
</code>```

The order of the string doesn't matter, so this is also perfectly valid:

```<code>abc
a
ab
abc
 b
 bc
  c
</code>```

So, the substring is positioned under the location of the substring in the initial string. So for abcdef and the substring cde, it would look like this:

```<code>abcdef
  cde
</code>```

The Task

The task is to align all substrings with a length greater than 0, like shown above. You can assume that the string itself will only contain alphabetic characters and has at least 1 character. For the padding, you can use a space or some other non-alphabetic printable ASCII character (32 - 127). Maybe not necessary to mention, but the string itself will only contain unique characters, so not like aba, since the a occurs twice.

Test cases

Input: abcde

Possible output:

```<code>a
ab
abc
abcd
abcde
 b
 bc
 bcd
 bcde
  c
  cd
  cde
   d
   de
    e
</code>```

Input: abcdefghij

Possible output:

```<code>a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
 b
 bc
 bcd
 bcde
 bcdef
 bcdefg
 bcdefgh
 bcdefghi
 bcdefghij
  c
  cd
  cde
  cdef
  cdefg
  cdefgh
  cdefghi
  cdefghij
   d
   de
   def
   defg
   defgh
   defghi
   defghij
    e
    ef
    efg
    efgh
    efghi
    efghij
     f
     fg
     fgh
     fghi
     fghij
      g
      gh
      ghi
      ghij
       h
       hi
       hij
        i
        ij
         j
</code>```

This is code-golf, so the submission with the least amount of bytes wins!


答:
PowerShell v2+, 69 bytes

```<code>param($a)0..($b=$a.length-1)|%{($i=$_)..$b|%{" "*$i+-join$a[$i..$_]}}
</code>```

Takes input $a, loops over the length (setting $b in the process for use later). Each outer loop, we loop up to $b again, setting $i for use later. Each inner loop, we output $i number of spaces concatenated with a slice of the input string. Since we're just looping through the string, this will actually handle any arbitrary string (duplicate letters, spaces, whatever).

Example

```<code>PS C:\Tools\Scripts\golfing> .\exploded-substrings.ps1 "Golfing"
G
Go
Gol
Golf
Golfi
Golfin
Golfing
 o
 ol
 olf
 olfi
 olfin
 olfing
  l
  lf
  lfi
  lfin
  lfing
   f
   fi
   fin
   fing
    i
    in
    ing
     n
     ng
      g
</code>```

Title: Exploded substrings

Body:
PowerShell v2+, 69 bytes

param($a)0..($b=$a.length-1)|%{($i=$_)..$b|%{" "*$i+-join$a[$i..$_]}}

Takes input $a, loops over the length (setting $b in the process for use later). Each outer loop, we loop up to $b again, setting $i for use later. Each inner loop, we output $i number of spaces concatenated with a slice of the input string. Since we're just looping through the string, this will actually handle any arbitrary string (duplicate letters, spaces, whatever).

Example

PS C:\Tools\Scripts\golfing> .\exploded-substrings.ps1 "Golfing"
G
Go
Gol
Golf
Golfi
Golfin
Golfing
 o
 ol
 olf
 olfi
 olfin
 olfing
  l
  lf
  lfi
  lfin
  lfing
   f
   fi
   fin
   fing
    i
    in
    ing
     n
     ng
      g


答:
Java, 91 bytes

```<code>(s,c)->{s+=c%8;int e=1;for(int i:s.getBytes())while(i>0){if(i%2==1)e^=1;i/=2;}return e==0;}
</code>```

I did the same as @CAT97, but stripped some characters by using the modulo 8 and concatenate of @Luis Mendo and the use of int instead of boolean.

This is a lambda for a BiFunction<String, Character, Boolean>.

Title: Generate a parity bit

Body:
A parity bit, is one of the simplest forms of a checksum. First, you have to pick the parity, even or odd. Let's say we pick even. Now, we need a message to transmit. Let's say our message is "Foo". This is written in binary as:

```<code>01000110 01101111 01101111
</code>```

Now, we count the total number of 1's in there, which is 15. Since 15 is an odd number, we must add one extra bit to the end of our message, and we will now have an even number of 'on' bits. This last added bit is known as the "parity bit". If we had picked an odd parity for our checksum, we would have to add an extra '0' so that the number of on bits remains odd.

The challenge:

You must write a program or function that determines what the correct parity bit for a string is. Your program must take two inputs:

A string, s. This is the message that the checksum will be calculated on. This will be restricted to the 95 printable ASCII characters.

A character or single character string p, that will either be e for even parity, or o for odd parity.

and produce a truthy-falsey value representing the correct parity bit. Truthy if it's a 1, and falsey if it's a 0.

Builtins that count the number of "on" bits in a string or character are not allowed. For example, a function f that does this: f('a') == 3 or f('foo') == 16 is banned. Anything else, such as base conversion, is fair game.

Test IO:

```<code>(without the quotes)
s: "0"
p: 'e'
output: 0

s: "Foo"
p: 'e'
output: 1

s: "Hello World!"
p: 'o'
output: 0

s: "Alex is right"
p: 'e'
output: 1

s: "Programming Puzzles and Code-Golf"
p: 'e'
output: 0

s: "Programming Puzzles and Code-Golf"
p: 'o'
output: 1
</code>```

This is codegolf, so standard loopholes apply, and the shortest answer in bytes wins.

Leaderboard

var QUESTION_ID=78569,OVERRIDE_USER=31716;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:
Java, 91 bytes

(s,c)->{s+=c%8;int e=1;for(int i:s.getBytes())while(i>0){if(i%2==1)e^=1;i/=2;}return e==0;}

I did the same as @CAT97, but stripped some characters by using the modulo 8 and concatenate of @Luis Mendo and the use of int instead of boolean.

This is a lambda for a BiFunction<String, Character, Boolean>.


答:
C#, <s>105</s> <s>117</s> <s>109</s> <s>107</s> <s>101</s> <s>99</s> 59 bytes

Golfed

void m(ulong u){while(u>=0)System.Console.WriteLine(u--);}
```
<hr />
<p><strong>Ungolfed</strong></p>
<pre class="lang-cs prettyprint-override"><code>void m( ulong u ) {
    while (u >= 0)
        System.Console.WriteLine(u--);
}
</code>```

Releases

v3.0 - -40 bytes - Changed the output to directly print to the console with a new line at the end. This update allows the usage of ulong. Once again, this is thanks to hstde.

v2.4 -  -2 bytes - Replaced long with int due to the limitations of the capacity of List<T>, which is capped to the max of  Int32.MaxValue in the implementation. The reason for changing to int can be found here. You can also explore this limitation in Reference Source.

v2.3 -  -6 bytes - Using var instead of List<long>. Thanks to hstde.

v2.2 -  -2 bytes - Fixed the decrements of the counter and removed brackets.

v2.1 -  -8 bytes - Update to use the argument, making the code shorter and faster.

v2.0 - +12 bytes - Update to List<> since arrays max size is Int32.MaxValue == 2 ^ 32 - 1

v1.0 - 105 bytes - Initial release

Title: Count up folks!

Body:
C#, <s>105</s> <s>117</s> <s>109</s> <s>107</s> <s>101</s> <s>99</s> 59 bytes

Golfed

void m(ulong u){while(u>=0)System.Console.WriteLine(u--);}

Ungolfed

void m( ulong u ) {
    while (u >= 0)
        System.Console.WriteLine(u--);
}

Releases

v3.0 - -40 bytes - Changed the output to directly print to the console with a new line at the end. This update allows the usage of ulong. Once again, this is thanks to hstde.

v2.4 -  -2 bytes - Replaced long with int due to the limitations of the capacity of List<T>, which is capped to the max of  Int32.MaxValue in the implementation. The reason for changing to int can be found here. You can also explore this limitation in Reference Source.

v2.3 -  -6 bytes - Using var instead of List<long>. Thanks to hstde.

v2.2 -  -2 bytes - Fixed the decrements of the counter and removed brackets.

v2.1 -  -8 bytes - Update to use the argument, making the code shorter and faster.

v2.0 - +12 bytes - Update to List<> since arrays max size is Int32.MaxValue == 2 ^ 32 - 1

v1.0 - 105 bytes - Initial release


答:
JavaScript (Firefox 30-57), <s>65</s> 63 bytes

```<code>s=>[for(c of(i=0,s))for(d of(t=r=i?t+' ':'',s.slice(i++)))r+=d]
</code>```

Returns an array of strings. As ES6 it's 78 bytes:

```<code>s=>[...s].map((_,i,a)=>a.slice(i).map(c=>r.push(u+=c),t=u=i?t+' ':''),r=[])&&r
</code>```

Title: Exploded substrings

Body:
JavaScript (Firefox 30-57), <s>65</s> 63 bytes

s=>[for(c of(i=0,s))for(d of(t=r=i?t+' ':'',s.slice(i++)))r+=d]

Returns an array of strings. As ES6 it's 78 bytes:

s=>[...s].map((_,i,a)=>a.slice(i).map(c=>r.push(u+=c),t=u=i?t+' ':''),r=[])&&r


答:
Mathematica 89 bytes

```<code>r@i_:=StringReplace[i,#->" "]&/@(Complement[y,#]&/@Subsequences[y=Characters@i])//Column

</code>```

Explanation

i refers to the input string

Subsequences[y=Characters@i] returns all subsequences (represented lists of characters) of the input. (Subsequences was introduced in v. 10.4)

For each subsequence, Complement... returns those characters from the input string that are not present.  Each of those characters is replaced by an empty space via StringReplace[i,#->" "].

Column displays the results in a single column. Each output string has the same number of characters, resulting in aligned letters.

```<code>r@"abcdefgh"
</code>```

Title: Exploded substrings

Body:
Mathematica 89 bytes

r@i_:=StringReplace[i,#->" "]&/@(Complement[y,#]&/@Subsequences[y=Characters@i])//Column

Explanation

i refers to the input string

Subsequences[y=Characters@i] returns all subsequences (represented lists of characters) of the input. (Subsequences was introduced in v. 10.4)

For each subsequence, Complement... returns those characters from the input string that are not present.  Each of those characters is replaced by an empty space via StringReplace[i,#->" "].

Column displays the results in a single column. Each output string has the same number of characters, resulting in aligned letters.

r@"abcdefgh"


答:
Oracle SQL 11.2, 139 bytes

WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=:1)SELECT a.i FROM v a, v b GROUP BY a.i HAVING:1-2=SUM(SIGN(MOD(a.i,b.i)))ORDER BY 1;
```

Title: List of primes under a million

Body:
This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines.

The task is to print out, in ascending order, all of the prime numbers less than a million. The output format should be one number per line of output.

The aim, as with most code golf submissions, is to minimise code size. Optimising for runtime is also a bonus, but is a secondary objective.


答:
Matlab, 49 bytes

```<code>f=@(x,p)mod(sum(sum(dec2bin(x)-'0'))+(p-'e'>0),2)
</code>```

where:

x is the input string;

p is 'e' for even parity and 'o' for the odd one.

For example:

```<code>>> f('Programming Puzzles and Code-Golf','e')

ans =

     0
</code>```

Title: Generate a parity bit

Body:
Matlab, 49 bytes

f=@(x,p)mod(sum(sum(dec2bin(x)-'0'))+(p-'e'>0),2)

where:

x is the input string;

p is 'e' for even parity and 'o' for the odd one.

For example:

>> f('Programming Puzzles and Code-Golf','e')

ans =

     0


答:
Bash and unix tools (72 bytes)

```<code>f(){ bc<<<"$(xxd -b<<<"$2$1"|cut -b9-64|tail -c +7|tr -dc 1|wc -c)%2" }
</code>```

Excepts s as the first and p as the second argument. Fortunately the last 3 bits of o and e has odd and even parity respectively.

```<code>xxd -b        print the concatenation of `p` and `s` in binary
cut -b9-64    parse xxd output
tail -c +7    keep only the last 3 bits of `p`
tr -dc 1      keep only the `1`s
wc -c         count them
bc ...%2      modulo two
</code>```

Supplying the input via <<< adds a line feed character, but the parity of \n is even, so it is not a problem.

Title: Generate a parity bit

Body:
Bash and unix tools (72 bytes)

f(){ bc<<<"$(xxd -b<<<"$2$1"|cut -b9-64|tail -c +7|tr -dc 1|wc -c)%2" }

Excepts s as the first and p as the second argument. Fortunately the last 3 bits of o and e has odd and even parity respectively.

xxd -b        print the concatenation of `p` and `s` in binary
cut -b9-64    parse xxd output
tail -c +7    keep only the last 3 bits of `p`
tr -dc 1      keep only the `1`s
wc -c         count them
bc ...%2      modulo two

Supplying the input via <<< adds a line feed character, but the parity of \n is even, so it is not a problem.


答:
Oracle SQL 11.2, 44 bytes

SELECT LEVEL FROM DUAL CONNECT BY LEVEL<=:1;
```

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.


问:
Transform a matrix
Write a program or function where a matrix A (maximum value of dimensions of the matrix is 100) is transformed to a new matrix B. Each element of the new matrix B is the sum of the positive neighbors of the corresponding element of the matrix A.

Only neighbors in the four orthogonal directions are considered, and the edges do not wrap around.

Example input:

```<code> 1  2  3
 4 -1 -2
-3 -4 10
 1  2 10
</code>```

Output:

```<code> 6  4  2
 1  6 13
 5 12 10
 2 11 12
</code>```

Rules:

As input use integers.

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

答:
Mathcad,  bytes

Uses standard 2D convolution of the filtered array with a 3x3 kernel.  Variants with negative element sums and diagonal kernel also added as part compensation for the program not being in the running for least bytes.

No byte count entered as Mathcad scoring has yet to be determined.  However, using keyboard equivalence, it is the region of 28 bytes assuming that matrix input doesn't count towards the total.

Note that what you see in the image above is exactly how the solutionn is entered and displayed in Mathcad.

Title: Transform a matrix


问:
The alphabet in programming languages
Our task is to, for each letter of the (English) alphabet, write a program that prints the alphabet, in a language whose name starts with that letter.

Input: none

Output:

```<code>abcdefghijklmnopqrstuvwxyz
</code>```

uppercase and trailing newline optional

Rules:

The scoring metric is the length of the programming language name, plus the length of the code.  Hence, C will be assessed a "penalty" of 1, while GolfScript will be assessed a penalty of 10.

One language/implementation per answer.  Multiple answers are encouraged.

If a programming language name's first letter is not an English letter, it should not be coerced into one.  It will be treated as a separate letter (meaning less competition).

No answer will be accepted until every English letter has a solution.

Current rankings:

APL: 5

Brachylog: 11

Canvas: 7

DOS: 13

Eso2D: 20

Fish: 20

Gaia: 6

Husk: 8

IPEL: 23

Japt: 6

Keg: 6

Ly: 13

MathGolf: 9

Ni: 15

Owl: 14

Pip: 4

QuadR: 31

Ruby: 17

Stax: 6

Thunno: 8

Unix Shell: 31

V: 4

W: 4

XJam: 10

Yorick: 36

Z80Golf: 16

Tell me if I'm missing anybody.

Automatic leaderboard (experimental)

var QUESTION_ID=2078;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){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&&r.indexOf('non-competing')===-1&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],lang:/a)-(d<a)||e.size-s.size});var s={},a=null,n="A";e.forEach(function(e){n=e.lang[0].toUpperCase(),a=e.size;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+" is for").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.lang,p=o[0].toUpperCase();s[p]=s[p]||{language:e.language,lang:e.lang,letter:p,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return(e.letter>s.letter)-(e.letter<s.letter)});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.language).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),jQuery("#languages").append(jQuery(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*(?:<[^>]+>)?(?:[^]+?for )?((?:]*?>)?(?:(?! [(=→-])[^\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} /* font fix */ body {font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;} /* #language-list x-pos fix */ #answer-list {margin-right: 200px;}</code>```

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

Winners by Letter

Language	User	Score

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

Everything

	Language	Author	Size

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

```

Title: The alphabet in programming languages

Body:
B is for Bash, 11 -> <s>15</s> 24

<s>

echo {a..z}

</s>

echo {a..z}|tr -d \
                   ^
                 space


答:
Python 3, <s>80</s> 78 bytes

Loop through the number of spaces to prefix with and then the number of characters to end with.

lambda x:[print(' '*i+x[i:j+1])for i in range(len(x))for j in range(i,len(x))]
```

Edit: Removed spaces before the for loops.

Title: Exploded substrings

Body:
Python 3, <s>80</s> 78 bytes

Loop through the number of spaces to prefix with and then the number of characters to end with.

lambda x:[print(' '*i+x[i:j+1])for i in range(len(x))for j in range(i,len(x))]

Edit: Removed spaces before the for loops.