答:
Python 3, <s>497</s> <s>484</s> 480 bytes

```<code>P=print
N=lambda m:"an"[:("E"==m[0])+1]+" "+m.lower()
h="I hear "
A=[a.split("|")for a in"Polar Bear|growl:Lion|roar:Hippopotamus|snort:Flamingo|flut:Zebra|bray:Boa Constrictor|hiss:Elephant|trumpet:Leopard|snarl:Peacock|yelp:Walrus|bellow:Zookeeper|whistl".split(":")]
for i in range(11):
 a,b=A[i]
 if i:P(h+N(a)+" "+b+"ing in my ear.\n")
 a+=", ";P(a+a+"what do you hear?")
P(h+"children...\n\n..."+",\n".join([z+"ing like "+N(y)for y,z in A[:-1]])+"...\nthat's what I hear.")
</code>```

(Credit for 13 bytes saved should go to Gábor Fekete, and an additional 4 bytes were saved by Taylor Lopez.)

So you could probably guess I was going to use a language like Python as a teaching tool.  This was the program before I started golfing it.

```<code>def startsWithVowel(name):
    firstLetter = name[0]
    return firstLetter in ["A", "E", "I", "O", "U"]

def aOrAn(name):
    return "an" if startsWithVowel(name) else "a"

animals = [
#    NAME (0),     SOUND (1)
    ("Polar Bear", "growling"),
    ("Lion", "roaring"),
    ("Hippopotamus", "snorting"),
    ("Flamingo", "fluting"),
    ("Zebra", "braying"),
    ("Boa Constrictor", "hissing"),
    ("Elephant", "trumpeting"),
    ("Leopard", "snarling"),
    ("Peacock", "yelping"),
    ("Walrus", "bellowing"),
    ("Robot Dragon", "screeching"),
    ("Owl", "hooting"),
    ("Monkey", "laughing"),
    ("Zookeeper", "whistling")]

NAME = 0
SOUND = 1
for animalNumber in range(len(animals)):
    thisAnimal = animals[animalNumber]
    if animalNumber + 1 < len(animals):
        nextAnimal = animals[animalNumber + 1]
    else:
        nextAnimal = None

    print("{n}, {n}, what do you hear?".format(n=thisAnimal[NAME]))

    if nextAnimal != None:
        print("I hear {a} {n} {s} in my ear.".format(n=nextAnimal[NAME].lower(),
                                                     s=nextAnimal[SOUND],
                                                     a=aOrAn(nextAnimal[NAME])))
    else:
        print("I hear children...")

        children = []
        for animal in animals[:-1]:
            children.append("{s} like {a} {n}".format(n=animal[NAME].lower(),
                                                      s=animal[SOUND],
                                                      a=aOrAn(animal[NAME])))
        print("...{}...".format(",\n".join(children)))
        print("that's what I hear.")
</code>```

Body:
The text of the children's book Polar Bear, Polar Bear, What Do You Hear?  has a very simple pattern.  You might use the text to teach introductory programming concepts.

My son was quickly bored by this idea, so I decided to play some golf with it instead.

The Challenge

In your programming language of choice, write the smallest program possible which will print the following text.  Output should match exactly, including case, spacing, and punctuation.

```<code>Polar Bear, Polar Bear, what do you hear?
I hear a lion roaring in my ear.

Lion, Lion, what do you hear?
I hear a hippopotamus snorting in my ear.

Hippopotamus, Hippopotamus, what do you hear?
I hear a flamingo fluting in my ear.

Flamingo, Flamingo, what do you hear?
I hear a zebra braying in my ear.

Zebra, Zebra, what do you hear?
I hear a boa constrictor hissing in my ear.

Boa Constrictor, Boa Constrictor, what do you hear?
I hear an elephant trumpeting in my ear.

Elephant, Elephant, what do you hear?
I hear a leopard snarling in my ear.

Leopard, Leopard, what do you hear?
I hear a peacock yelping in my ear.

Peacock, Peacock, what do you hear?
I hear a walrus bellowing in my ear.

Walrus, Walrus, what do you hear?
I hear a zookeeper whistling in my ear.

Zookeeper, Zookeeper, what do you hear?
I hear children...

...growling like a polar bear,
roaring like a lion,
snorting like a hippopotamus,
fluting like a flamingo,
braying like a zebra,
hissing like a boa constrictor,
trumpeting like an elephant,
snarling like a leopard,
yelping like a peacock,
bellowing like a walrus...
that's what I hear.
</code>```

Body:
Python 3, <s>497</s> <s>484</s> 480 bytes

P=print
N=lambda m:"an"[:("E"==m[0])+1]+" "+m.lower()
h="I hear "
A=[a.split("|")for a in"Polar Bear|growl:Lion|roar:Hippopotamus|snort:Flamingo|flut:Zebra|bray:Boa Constrictor|hiss:Elephant|trumpet:Leopard|snarl:Peacock|yelp:Walrus|bellow:Zookeeper|whistl".split(":")]
for i in range(11):
 a,b=A[i]
 if i:P(h+N(a)+" "+b+"ing in my ear.\n")
 a+=", ";P(a+a+"what do you hear?")
P(h+"children...\n\n..."+",\n".join([z+"ing like "+N(y)for y,z in A[:-1]])+"...\nthat's what I hear.")

(Credit for 13 bytes saved should go to Gábor Fekete, and an additional 4 bytes were saved by Taylor Lopez.)

So you could probably guess I was going to use a language like Python as a teaching tool.  This was the program before I started golfing it.

def startsWithVowel(name):
    firstLetter = name[0]
    return firstLetter in ["A", "E", "I", "O", "U"]

def aOrAn(name):
    return "an" if startsWithVowel(name) else "a"

animals = [
#    NAME (0),     SOUND (1)
    ("Polar Bear", "growling"),
    ("Lion", "roaring"),
    ("Hippopotamus", "snorting"),
    ("Flamingo", "fluting"),
    ("Zebra", "braying"),
    ("Boa Constrictor", "hissing"),
    ("Elephant", "trumpeting"),
    ("Leopard", "snarling"),
    ("Peacock", "yelping"),
    ("Walrus", "bellowing"),
    ("Robot Dragon", "screeching"),
    ("Owl", "hooting"),
    ("Monkey", "laughing"),
    ("Zookeeper", "whistling")]

NAME = 0
SOUND = 1
for animalNumber in range(len(animals)):
    thisAnimal = animals[animalNumber]
    if animalNumber + 1 < len(animals):
        nextAnimal = animals[animalNumber + 1]
    else:
        nextAnimal = None

    print("{n}, {n}, what do you hear?".format(n=thisAnimal[NAME]))

    if nextAnimal != None:
        print("I hear {a} {n} {s} in my ear.".format(n=nextAnimal[NAME].lower(),
                                                     s=nextAnimal[SOUND],
                                                     a=aOrAn(nextAnimal[NAME])))
    else:
        print("I hear children...")

        children = []
        for animal in animals[:-1]:
            children.append("{s} like {a} {n}".format(n=animal[NAME].lower(),
                                                      s=animal[SOUND],
                                                      a=aOrAn(animal[NAME])))
        print("...{}...".format(",\n".join(children)))
        print("that's what I hear.")


问:
Print all alphanumeric characters plus underscore
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

var QUESTION_ID=85666,OVERRIDE_USER=4162;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;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

```

答:
Excel VBA, 130 bytes

Have fun hitting enter...

```<code>Sub q()
For i = 1 To 123
If i > 47 And i < 58 Or i > 64 And i < 91 Or i > 96 And i < 123 Or i = 95 Then MsgBox Chr(i)
Next
End Sub
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Excel VBA, 130 bytes

Have fun hitting enter...

Sub q()
For i = 1 To 123
If i > 47 And i < 58 Or i > 64 And i < 91 Or i > 96 And i < 123 Or i = 95 Then MsgBox Chr(i)
Next
End Sub


问:
Which ghosts are missing?
In this challenge, given a list of ghosts from Pac-Man, you must output which ghosts are missing. You must do it in as few bytes as you can

Input

Input will consist of a string or list, which will include a number ghosts, which could include:

Blinky

Inky

Pinky

Clyde

However, input may also include Pac-Man (with that punctuation). So, the maximum amount of items in a list will be five, in any order. It can be assumed that no invalid items will be in the list

Output

Output will consist of a string, or list. This will include of all the ghosts that are not in the input, in any order. However, if Pac-Man is in the input, all ghosts will be considered missing (because he eats them).

Test cases

```<code>input: Clyde
output: Blinky, Inky, Pinky
alternate output: Inky, Pinky, Blinky
or one of the other 4 permutations

input: Clyde, Blinky # or however you delimit it
output: Inky, Pinky
alt: Pinky, Inky

input: Pac-Man, Clyde
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations

input:[null]
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations
</code>```

This is codegolf, so the lower the bytecount, the better.

答:
Python 3, 75 bytes

```<code>lambda s:[x for x in['Blinky','Inky','Pinky','Clyde']if(x in s)<1or'-'in s]
</code>```

Input is a comma-separated string, and the output will be a list.

ContentLicense: CC BY-SA 4.0

Title: Which ghosts are missing?

Body:
Python 3, 75 bytes

lambda s:[x for x in['Blinky','Inky','Pinky','Clyde']if(x in s)<1or'-'in s]

Input is a comma-separated string, and the output will be a list.


问:
Dijkstra's Challenge

Presented in honor of APL as an interactive tool turning 50 this year

Background

Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-be famous names, and a few future Turing Award winners (Backus, Curry, Dijkstra, Floyd, Iverson, Newell, Perlis, Wilkes). The paper also records the discussion that occurred after the presentation, ending with an exchange between Ken and [Edsger] Dijkstra, in which Ken’s reply to Dijkstra’s question was a one-liner.

Challenge

How would you represent a more complex operation, for example, the sum of all elements of a matrix M which are equal to the sum of the corresponding row and column indices?

Write a snippet or expression (no need for a full program or function) to calculate the sum of each element in a given integer matrix which is equal to the sum of its indices. Or, as FryAmTheEggman puts it: given a matrix M with elements aij return the sum of each aij where aij = i + j.

You may assume the matrix already being in a variable or memory location, or you may take it as an argument or input. You may use either 0 or 1 based indices.

Test cases

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

0 for empty matrix

```<code>2
</code>```

0 for 0 based indices or 2 for 1-based

```<code>1 5 2
9 4 2
5 9 6
</code>```

2 for 0 based or 10 for 1 based

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

11

```<code>3 -1 3 3
3 -1 3 1
</code>```

6 for 0 based or 3 for 1 based

Anecdote

Iverson's answer was ++/(M = ⍳¹ ⨢ ⍳¹)//M, which is neither valid in the Iverson Notation as defined in A Programming Language, nor in what eventually became APL. In Iverson notation, it would have been +/(M = ⍳¹(μ(M)) ⨢ ⍳¹(ν(M)))/M. In the very first versions of APL it was +/(,M=(⍳1↑⍴M)∘.+⍳1↓⍴M)/,M.

答:
MATL, <s>15</s> <s>14</s> 10 bytes

```<code>3#fbb+y=*s
</code>```

The input has rows separated by ;. For example: [1 5 2; 9 4 2; 5 9 6]. 1-based indexing is used.

Try it online! Or verify all test cases.

Explanation

I'll use the example with input [3 -1 3 3; 3 -1 3 1] in the explanation.

```<code>3#f    % Three-output find: for all nonzero values of implicit input matrix, pushes
       % three column vectors with row indices, column indices, and values
       %   Stack contains: [1;2;1;2;1;2;1;2], [1;1;2;2;3;3;4;4], [3;3;-1;-1;3;3;3;1]
bb     % Bubble up twice: move vectors of row and column indices to top
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [1;2;1;2;1;2;1;2], [1;1;2;2;3;3;4;4]
+      % Element-wise sum of top two arrays
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [2;3;3;4;4;5;5;6]
y      % Duplicate the vector of nonzero values onto the top of the stack
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [2;3;3;4;4;5;5;6], [3;3;-1;-1;3;3;3;1]
=      % Element-wise equality test of top two arrays
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [0;1;0;0;0;0;0;0]
*      % Element-wise multiply of top two arrays
       %   Stack contains: [0;3;0;0;0;0;0;0]
s      % Sum of array
       %   Stack contains: 3
</code>```

Title: Dijkstra's Challenge

Body:
MATL, <s>15</s> <s>14</s> 10 bytes

3#fbb+y=*s

The input has rows separated by ;. For example: [1 5 2; 9 4 2; 5 9 6]. 1-based indexing is used.

Try it online! Or verify all test cases.

Explanation

I'll use the example with input [3 -1 3 3; 3 -1 3 1] in the explanation.

3#f    % Three-output find: for all nonzero values of implicit input matrix, pushes
       % three column vectors with row indices, column indices, and values
       %   Stack contains: [1;2;1;2;1;2;1;2], [1;1;2;2;3;3;4;4], [3;3;-1;-1;3;3;3;1]
bb     % Bubble up twice: move vectors of row and column indices to top
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [1;2;1;2;1;2;1;2], [1;1;2;2;3;3;4;4]
+      % Element-wise sum of top two arrays
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [2;3;3;4;4;5;5;6]
y      % Duplicate the vector of nonzero values onto the top of the stack
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [2;3;3;4;4;5;5;6], [3;3;-1;-1;3;3;3;1]
=      % Element-wise equality test of top two arrays
       %   Stack contains: [3;3;-1;-1;3;3;3;1], [0;1;0;0;0;0;0;0]
*      % Element-wise multiply of top two arrays
       %   Stack contains: [0;3;0;0;0;0;0;0]
s      % Sum of array
       %   Stack contains: 3


问:
Polar Bear, Polar Bear, what do you hear?
The text of the children's book Polar Bear, Polar Bear, What Do You Hear?  has a very simple pattern.  You might use the text to teach introductory programming concepts.

My son was quickly bored by this idea, so I decided to play some golf with it instead.

The Challenge

In your programming language of choice, write the smallest program possible which will print the following text.  Output should match exactly, including case, spacing, and punctuation.

```<code>Polar Bear, Polar Bear, what do you hear?
I hear a lion roaring in my ear.

Lion, Lion, what do you hear?
I hear a hippopotamus snorting in my ear.

Hippopotamus, Hippopotamus, what do you hear?
I hear a flamingo fluting in my ear.

Flamingo, Flamingo, what do you hear?
I hear a zebra braying in my ear.

Zebra, Zebra, what do you hear?
I hear a boa constrictor hissing in my ear.

Boa Constrictor, Boa Constrictor, what do you hear?
I hear an elephant trumpeting in my ear.

Elephant, Elephant, what do you hear?
I hear a leopard snarling in my ear.

Leopard, Leopard, what do you hear?
I hear a peacock yelping in my ear.

Peacock, Peacock, what do you hear?
I hear a walrus bellowing in my ear.

Walrus, Walrus, what do you hear?
I hear a zookeeper whistling in my ear.

Zookeeper, Zookeeper, what do you hear?
I hear children...

...growling like a polar bear,
roaring like a lion,
snorting like a hippopotamus,
fluting like a flamingo,
braying like a zebra,
hissing like a boa constrictor,
trumpeting like an elephant,
snarling like a leopard,
yelping like a peacock,
bellowing like a walrus...
that's what I hear.
</code>```

答:
C, 596 bytes

Call f() without any arguments.
This is not the best golf in the world, I probably can shrink it more.

```<code>f(n){char*t,a[99][99]={"Polar Bear","Lion","Hippopotamus","Flamingo","Zebra","Boa Constrictor","Elephant","Leopard","Peacock","Walrus","Zookeeper","growl","roar","snort","flut","bray","hiss","trumpet","snarl","yelp","bellow","whistl"};for(n=0;n<11;){strcpy(t=a[n+30],n^6?" ":"n ");strcat(t,a[n++]);for(;*t=tolower(*t);++t);}for(n=0;printf("%s, %s, what do you hear?\n",a[n],a[n]),n<10;++n)printf("I hear a%s %sing in my ear.\n\n",a[n+31],a[12+n]);puts("I hear children...\n");for(n=11;n<21;++n)printf("%s%sing like a%s%s\n",n^11?"":"...",a[n],a[n+19],n^20?",":"...");puts("that's what I hear.");}
</code>```

Try it on ideone.

Body:
C, 596 bytes

Call f() without any arguments.
This is not the best golf in the world, I probably can shrink it more.

f(n){char*t,a[99][99]={"Polar Bear","Lion","Hippopotamus","Flamingo","Zebra","Boa Constrictor","Elephant","Leopard","Peacock","Walrus","Zookeeper","growl","roar","snort","flut","bray","hiss","trumpet","snarl","yelp","bellow","whistl"};for(n=0;n<11;){strcpy(t=a[n+30],n^6?" ":"n ");strcat(t,a[n++]);for(;*t=tolower(*t);++t);}for(n=0;printf("%s, %s, what do you hear?\n",a[n],a[n]),n<10;++n)printf("I hear a%s %sing in my ear.\n\n",a[n+31],a[12+n]);puts("I hear children...\n");for(n=11;n<21;++n)printf("%s%sing like a%s%s\n",n^11?"":"...",a[n],a[n+19],n^20?",":"...");puts("that's what I hear.");}

Try it on ideone.


答:
JavaScript, <s>49</s> 46 bytes

```<code>a.map((b,i)=>b.map((c,j)=>r+=c==i+j&&c),r=0)|r
</code>```

Edit: Saved 3 bytes thanks to @MartinEnder pointing out that snippets are allowed.

Title: Dijkstra's Challenge

Body:
Presented in honor of APL as an interactive tool turning 50 this year

Background

Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-be famous names, and a few future Turing Award winners (Backus, Curry, Dijkstra, Floyd, Iverson, Newell, Perlis, Wilkes). The paper also records the discussion that occurred after the presentation, ending with an exchange between Ken and [Edsger] Dijkstra, in which Ken’s reply to Dijkstra’s question was a one-liner.

Challenge

How would you represent a more complex operation, for example, the sum of all elements of a matrix M which are equal to the sum of the corresponding row and column indices?

Write a snippet or expression (no need for a full program or function) to calculate the sum of each element in a given integer matrix which is equal to the sum of its indices. Or, as FryAmTheEggman puts it: given a matrix M with elements aij return the sum of each aij where aij = i + j.

You may assume the matrix already being in a variable or memory location, or you may take it as an argument or input. You may use either 0 or 1 based indices.

Test cases

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

0 for empty matrix

```<code>2
</code>```

0 for 0 based indices or 2 for 1-based

```<code>1 5 2
9 4 2
5 9 6
</code>```

2 for 0 based or 10 for 1 based

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

11

```<code>3 -1 3 3
3 -1 3 1
</code>```

6 for 0 based or 3 for 1 based

Anecdote

Iverson's answer was ++/(M = ⍳¹ ⨢ ⍳¹)//M, which is neither valid in the Iverson Notation as defined in A Programming Language, nor in what eventually became APL. In Iverson notation, it would have been +/(M = ⍳¹(μ(M)) ⨢ ⍳¹(ν(M)))/M. In the very first versions of APL it was +/(,M=(⍳1↑⍴M)∘.+⍳1↓⍴M)/,M.

Body:
JavaScript, <s>49</s> 46 bytes

a.map((b,i)=>b.map((c,j)=>r+=c==i+j&&c),r=0)|r

Edit: Saved 3 bytes thanks to @MartinEnder pointing out that snippets are allowed.


答:
CJam, <s>23</s> <s>21</s> 20 bytes

Thanks to Peter Taylor for saving 3 bytes.

```<code>ee{~_@f-_,,.=.*~}%1b
</code>```

Expects the matrix to be on the stack and leaves the sum instead. Indices are zero-based in either case.

Test it here.

Title: Dijkstra's Challenge

Body:
CJam, <s>23</s> <s>21</s> 20 bytes

Thanks to Peter Taylor for saving 3 bytes.

ee{~_@f-_,,.=.*~}%1b

Expects the matrix to be on the stack and leaves the sum instead. Indices are zero-based in either case.

Test it here.


答:
J, 15 bytes

```<code>+/,M*M=+/&i./$M
</code>```

Uses zero-based indexing and assumes the matrix is already stored in variable M.

Explanation

```<code>+/,M*M=+/&i./$M
             $a  Get the shape of M
            /    Insert between the shape
         &i.     Create a range from 0 to each end exclusive
       +/        Forms a table which is the sum of each row and column index
     M=          1 if the element is equal to its index sum else 0
   M*            Multiply by their values
  ,              Flatten
+/               Reduce using addition to get the sum
</code>```

Title: Dijkstra's Challenge

Body:
J, 15 bytes

+/,M*M=+/&i./$M

Uses zero-based indexing and assumes the matrix is already stored in variable M.

Explanation

+/,M*M=+/&i./$M
             $a  Get the shape of M
            /    Insert between the shape
         &i.     Create a range from 0 to each end exclusive
       +/        Forms a table which is the sum of each row and column index
     M=          1 if the element is equal to its index sum else 0
   M*            Multiply by their values
  ,              Flatten
+/               Reduce using addition to get the sum


问:
Generate the Rummy Sequence
Your task is to take an input n and output element n of the Rummy Sequence, a sequence which I made (looking on OEIS will not help you).

Definition

Each element of the Rummy Sequence is a set of truthy or falsey values. Ex.: [true, false].

The steps to producing a member of the Rummy Sequence are quite simple:

Start out with the first index, [] (this is element 0).

Set the leftmost falsey to truthy. If there are no falseys to change, then increase the length of the list by 1 and set all members of the new list to falsey.

Repeat step 2 until reaching element n.

Example

Let's define our function as rummy(int n) (stuff in {} is a step taken to get to the answer):

```<code>>>> rummy(5)
{[]}
{[false]}
{[true]}
{[false, false]}
{[true, false]}
[true, true]
</code>```

Rules

Standard loopholes apply.

Must work for inputs 0 through your language's upper numerical bound.

You may output in any way you see fit, provided that it is clear that the output is a set of truthy/falseys.

Trivia

I call this the "Rummy Sequence" because, starting at index 2, it defines the sets you would need to lay down in each round of Progressive Rummy, where falsey is a book and truthy is a run.

Test Cases

```<code>>>> rummy(0)
[]

>>> rummy(1)
[false]

>>> rummy(6)
[false, false, false]

>>> rummy(20)
[true, true, true, true, true]

>>> rummy(1000)
[true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
</code>```

答:
Python 2, 61 bytes

j=(2*input()+.25)**.5-.5
print[i/j<j%1for i in range(int(j))]
```

<p>Solves for <em>n = j·(j+1)/2</em>. Input is taken from stdin.</p>

<p><strong>Sample Usage</strong></p>

<pre class="lang-python prettyprint-override"><code>$ echo 20 | python rummy-seq.py
[True, True, True, True, True]

$ echo 50 | python rummy-seq.py
[True, True, True, True, True, False, False, False, False]
</code>```

Demo.

Title: Generate the Rummy Sequence

Body:
Python 2, 61 bytes

j=(2*input()+.25)**.5-.5
print[i/j<j%1for i in range(int(j))]

Solves for n = j·(j+1)/2. Input is taken from stdin.

Sample Usage

$ echo 20 | python rummy-seq.py
[True, True, True, True, True]

$ echo 50 | python rummy-seq.py
[True, True, True, True, True, False, False, False, False]

Demo.


问:
Fibonacci reversed!

Introduction

We all know and love our Fibonacci sequence and have seen a myriad of challenge on it here already. However, we're still lacking a very simple case which this answer is going to provide: Reversed fibonacci! So given F_n your job is to find n.

Specification

Input

Your input will be a non-negative integer, which is guaranteed to be part of the fibonacci sequence.

Output

The output must be a non-negative integer as well.

What to do?

The introduction already said: Given a fibonacci number, output its index. Fiboancci number hereby is defined as F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2) and you're given F(n) and must return n.

Potential Corner Cases

0 is a valid in- and output.

If given "1" as input you may either output "1" or "2", as you prefer.

You may always assume that your input actually is a fibonacci number.

You may assume that the input is representable as a 32-bit signed integer.

Who wins?

This is code-golf so the shortest answer in bytes wins!

Standard rules apply of course.

Test-cases

```<code>0 -> 0
2 -> 3
3 -> 4
5 -> 5
8 -> 6
13 -> 7
1836311903 -> 46
</code>```

答:
JavaScript, 22 bytes

```<code>n=>Math.log(n)/.48+2|0
</code>```

Title: Fibonacci reversed!

Body:
JavaScript, 22 bytes

n=>Math.log(n)/.48+2|0


问:
A simple TCP server
Write a program or function that listens for incoming TCP traffic on port N. It offers a simple service: it calculates sum of IP address fields of incoming connection and returns.

Program or function reads integer N from arguments or stdin. It listens to incoming TCP connections on port N. When someone connects to that port, the program calculates sum of its IP address fields and sends it back to the client with trailing newline and closes connection.

Port number N is a valid port, and 210 < N < 215

Trailing newline can be either \nor \r\n

You can use either IPv4 or IPv6. Since IPv6 addresses are written in hexadecimal form, you must also provide result in same format, for example 2001:0db8:0000:0042:0000:8a2e:0370:7334 => 12ecd.

This is code-golf. Standard rules and loopholes apply.

Example

You run your server with ./server 1234. The server is now running and waiting for connections on port 1234. Then a client from 127.0.0.1 connects to your server. Your server performs a simple calculation: 127+0+0+1 => 128 and sends the result to the client (with trailing newline): 128\n. Then server closes connection and waits for next client.

Leaderboard

var QUESTION_ID=76379,OVERRIDE_USER=20569;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

```

答:
AutoIT, <s>308</s> <s>293</s> <s>281</s> <s>278</s> <s>275</s> <s>274</s> <s>272</s> <s>270</s> 264 bytes

```<code>Func K($n)
TCPStartup()
$A=TCPListen("127.0.0.1",$n)
Do
$B=TCPAccept($A)
Until $B>0
While 1
$C=TCPRecv($B,$n)
If $C Then
$e=StringInStr($C,"st:")+4
$d=stringsplit(StringMid($C,$e,StringInStr($C,":")-$e),".")
ConsoleWrite($d[1]+$d[2]+$d[3]+$d[4])
EndIf
WEnd
EndFunc
</code>```

Script-Example.com has an online compiler.

Reusing the port variable ($n) in the TCPRecv max-length parameter. Since it is never going to be less than 1024, it's saving me a byte.

Title: A simple TCP server

Body:
AutoIT, <s>308</s> <s>293</s> <s>281</s> <s>278</s> <s>275</s> <s>274</s> <s>272</s> <s>270</s> 264 bytes

Func K($n)
TCPStartup()
$A=TCPListen("127.0.0.1",$n)
Do
$B=TCPAccept($A)
Until $B>0
While 1
$C=TCPRecv($B,$n)
If $C Then
$e=StringInStr($C,"st:")+4
$d=stringsplit(StringMid($C,$e,StringInStr($C,":")-$e),".")
ConsoleWrite($d[1]+$d[2]+$d[3]+$d[4])
EndIf
WEnd
EndFunc

Script-Example.com has an online compiler.

Reusing the port variable ($n) in the TCPRecv max-length parameter. Since it is never going to be less than 1024, it's saving me a byte.


问:
#Hashtag_or_not
In this code golf challenge, you will verify hashtags!

#What_your_code_should_do

Input is a string. Output a truthy value if it is a valid hashtag, and a falsy value otherwise.

We define a string as a valid Hashtag if ...

It starts with a hash (#).

It doesn't have a number right after the hashtag (e.g. #2016USElection isn't a  valid hashtag).

It doesn't have any "special characters" (i.e. any character that isn't an alphabet, underscore (_) or a number).

You can assume that the input only contains ASCII characters. (It would be unfair if we did Unicode too.)

#Rules

Basic code-golf rules apply.

#Examples

Truthy:

```<code>#
#e
#_ABC
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016
</code>```

Falsy:

```<code>Hello, World!
#12thBday
#not-valid
#alsoNotValid!
#!not_a_hash
</code>```

答:
Lua, 39 bytes

```<code>print(arg[1]:match("^#[%a_][%a_%d]*$"))
</code>```

Straightforward copypasta of match description. Outputs falsy nil if not hashtag, outputs truthly hashtag back otherwise.

Can be shortened for one more byte by using find if outputing list of two values (which is truthly) doesn't break rules.

Title: #Hashtag_or_not

Body:
Lua, 39 bytes

print(arg[1]:match("^#[%a_][%a_%d]*$"))

Straightforward copypasta of match description. Outputs falsy nil if not hashtag, outputs truthly hashtag back otherwise.

Can be shortened for one more byte by using find if outputing list of two values (which is truthly) doesn't break rules.


答:
F#, <s>591</s> <s>589</s> <s>579</s> <s>576</s> <s>573</s> <s>567</s> 552 bytes

This is my first try at code golfing with a language i like. I bet there are some ways this could be made shorter. Runs in FSI, so no need for .NET boilerplate.

Edit: Shaved 10 bytes by removing \r. It still renders fine in VSCode so go figure. Cut another three bytes with function composition, and another three with a lambda, then six with a for loop instead of Seq.iter (getting rid of the lambda). Finally 15 bytes were cut by rearranging a(s:string)

```<code>let A="Polar Bear,Lion,Hippopotamus,Flamingo,Zebra,Boa Constrictor,Elephant,Leopard,Peacock,Walrus,Zookeeper".Split(',')
let S="growl,roar,snort,flut,bray,hiss,trumpet,snarl,yelp,bellow,whistl".Split(',')
let a(s:string)=(if s.[0]='E'then"an "else"a ")+s.ToLower()
let f i=sprintf"%s, %s, what do you hear?\nI hear "A.[i]A.[i]
for i in 0..9 do printfn"%s%s %sing in my ear.\n"(f i)(a A.[i+1])S.[i+1]
printf"%schildren...\n\n..."(f 10)
let t i=sprintf"%sing like %s"S.[i](a A.[i])
Seq.iter(t>>printfn"%s,")[0..8]
printfn"%s...\nthat's what I hear."(t 9)
</code>```

Title: Polar Bear, Polar Bear, what do you hear?

Body:
F#, <s>591</s> <s>589</s> <s>579</s> <s>576</s> <s>573</s> <s>567</s> 552 bytes

This is my first try at code golfing with a language i like. I bet there are some ways this could be made shorter. Runs in FSI, so no need for .NET boilerplate.

Edit: Shaved 10 bytes by removing \r. It still renders fine in VSCode so go figure. Cut another three bytes with function composition, and another three with a lambda, then six with a for loop instead of Seq.iter (getting rid of the lambda). Finally 15 bytes were cut by rearranging a(s:string)

let A="Polar Bear,Lion,Hippopotamus,Flamingo,Zebra,Boa Constrictor,Elephant,Leopard,Peacock,Walrus,Zookeeper".Split(',')
let S="growl,roar,snort,flut,bray,hiss,trumpet,snarl,yelp,bellow,whistl".Split(',')
let a(s:string)=(if s.[0]='E'then"an "else"a ")+s.ToLower()
let f i=sprintf"%s, %s, what do you hear?\nI hear "A.[i]A.[i]
for i in 0..9 do printfn"%s%s %sing in my ear.\n"(f i)(a A.[i+1])S.[i+1]
printf"%schildren...\n\n..."(f 10)
let t i=sprintf"%sing like %s"S.[i](a A.[i])
Seq.iter(t>>printfn"%s,")[0..8]
printfn"%s...\nthat's what I hear."(t 9)


答:
Retina, 46 bytes

Byte count assumes ISO 8859-1 encoding.

```<code>\d+
$*
M!`(?<=(\S* |.*¶)*)(?<-1>1)+\b(?(1)1)
1
</code>```

Input uses space and linefeed separators to represent the matrix. Indices are 0-based.

Try it online!

Explanation

Not quite the kind of challenge Retina was made for, but it's doing surprisingly well... :)

Stage 1: Substitution

```<code>\d+
$*
</code>```

This simply expands all the integers in the string as unary numbers using 1 as the unary digit. Negative numbers like -3 will simply become things like -111.

Stage 2: Match

```<code>M!`(?<=(\S* |.*¶)*)(?<-1>1)+\b(?(1)1)
</code>```

Due to the ! option, this prints all the matches of the given regex. Said regex uses balancing groups to check whether the current number is the same as the sum of its indices.

To do that, we first determine the sum of indices with the lookbehind (?<=(\S* |.*¶)*). This adds one capture for each number in front of the current one on the same line (via \S* ) as well as one capture for each line in front of the current one (via .*¶) to group 1. Hence, we get the zero-based sum of indices as a result.

Then we try to match the entire next number while removing captures from this stack with (?<-1>1)+\b. And then we make the match fail if any captures are left on group 1 with (?(1)1) to ensure equality.

Note that negative numbers are never matched, because the lookbehind cannot get past the - in front of list of 1s and the (?<-1>1)+ can't match it either.

This gives us a list of all the unary numbers which equal the sum of their indices.

Stage 3: Match

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

We end with another match stage, but without the ! option, this just counts the number of matches, which both sums all the unary numbers from the previous result and also converts that sum back to decimal.

Title: Dijkstra's Challenge

Body:
Retina, 46 bytes

Byte count assumes ISO 8859-1 encoding.

\d+
$*
M!`(?<=(\S* |.*¶)*)(?<-1>1)+\b(?(1)1)
1

Input uses space and linefeed separators to represent the matrix. Indices are 0-based.

Try it online!

Explanation

Not quite the kind of challenge Retina was made for, but it's doing surprisingly well... :)

Stage 1: Substitution

\d+
$*

This simply expands all the integers in the string as unary numbers using 1 as the unary digit. Negative numbers like -3 will simply become things like -111.

Stage 2: Match

M!`(?<=(\S* |.*¶)*)(?<-1>1)+\b(?(1)1)

Due to the ! option, this prints all the matches of the given regex. Said regex uses balancing groups to check whether the current number is the same as the sum of its indices.

To do that, we first determine the sum of indices with the lookbehind (?<=(\S* |.*¶)*). This adds one capture for each number in front of the current one on the same line (via \S* ) as well as one capture for each line in front of the current one (via .*¶) to group 1. Hence, we get the zero-based sum of indices as a result.

Then we try to match the entire next number while removing captures from this stack with (?<-1>1)+\b. And then we make the match fail if any captures are left on group 1 with (?(1)1) to ensure equality.

Note that negative numbers are never matched, because the lookbehind cannot get past the - in front of list of 1s and the (?<-1>1)+ can't match it either.

This gives us a list of all the unary numbers which equal the sum of their indices.

Stage 3: Match

1

We end with another match stage, but without the ! option, this just counts the number of matches, which both sums all the unary numbers from the previous result and also converts that sum back to decimal.


问:
Polynomial Long Division
Implement polynomial long division, an algorithm that divides two polynomials and gets the quotient and remainder:

(12x^3 - 5x^2 + 3x - 1) / (x^2 - 5) = 12x - 5 R 63x - 26

In your programs, you will represent polynomials as an array, with the constant term on the tail. for example, x^5 - 3x^4 + 2x^2 - x + 1 will become [1, -3, 0, 2, -1, 1].

The long division function you are going to write will return two values: the quotient and the remainder. You do not need to handle numerical imprecisions and arithmetic errors. Do not use math library to do your job, however, you may make your function able to deal with symbolic values. Shortest code wins.

EXAMPLE: div([12, -5, 3, -1], [1, 0, -5]) == ([12, -5], [63, -26])

答:
Haskell, 126

For a start:

```<code>l s _ 0=s
l(x:s)(y:t)n=x/y:l(zipWith(-)s$map(*(x/y))t++repeat 0)(y:t)(n-1)
d s t=splitAt n$l s t n where n=length s-length t+1
</code>```

Sample use:

```<code>*Main> d [12, -5, 3, -1] [1, 0, -5]
([12.0,-5.0],[63.0,-26.0])
</code>```

ContentLicense: CC BY-SA 2.5

Title: Polynomial Long Division

Body:
Haskell, 126

For a start:

l s _ 0=s
l(x:s)(y:t)n=x/y:l(zipWith(-)s$map(*(x/y))t++repeat 0)(y:t)(n-1)
d s t=splitAt n$l s t n where n=length s-length t+1

Sample use:

*Main> d [12, -5, 3, -1] [1, 0, -5]
([12.0,-5.0],[63.0,-26.0])


答:
Bash + zcat, 402 bytes

Just a joke:

a 2 lines bash script that tails itself and pipe the second line to zcat.

The second line is the gzipped text.

How to prepare it: all the text in a file a. Then

```<code>echo "tail -n+2 \$0|zcat;exit" > go.sh
gzip a ;
cat a.gz >> go.sh
chomod u+x go.sh
</code>```

The file so created when executed returns the starting text, 402 Bytes.

Body:
The text of the children's book Polar Bear, Polar Bear, What Do You Hear?  has a very simple pattern.  You might use the text to teach introductory programming concepts.

My son was quickly bored by this idea, so I decided to play some golf with it instead.

The Challenge

In your programming language of choice, write the smallest program possible which will print the following text.  Output should match exactly, including case, spacing, and punctuation.

```<code>Polar Bear, Polar Bear, what do you hear?
I hear a lion roaring in my ear.

Lion, Lion, what do you hear?
I hear a hippopotamus snorting in my ear.

Hippopotamus, Hippopotamus, what do you hear?
I hear a flamingo fluting in my ear.

Flamingo, Flamingo, what do you hear?
I hear a zebra braying in my ear.

Zebra, Zebra, what do you hear?
I hear a boa constrictor hissing in my ear.

Boa Constrictor, Boa Constrictor, what do you hear?
I hear an elephant trumpeting in my ear.

Elephant, Elephant, what do you hear?
I hear a leopard snarling in my ear.

Leopard, Leopard, what do you hear?
I hear a peacock yelping in my ear.

Peacock, Peacock, what do you hear?
I hear a walrus bellowing in my ear.

Walrus, Walrus, what do you hear?
I hear a zookeeper whistling in my ear.

Zookeeper, Zookeeper, what do you hear?
I hear children...

...growling like a polar bear,
roaring like a lion,
snorting like a hippopotamus,
fluting like a flamingo,
braying like a zebra,
hissing like a boa constrictor,
trumpeting like an elephant,
snarling like a leopard,
yelping like a peacock,
bellowing like a walrus...
that's what I hear.
</code>```

Body:
Bash + zcat, 402 bytes

Just a joke:

a 2 lines bash script that tails itself and pipe the second line to zcat.

The second line is the gzipped text.

How to prepare it: all the text in a file a. Then

echo "tail -n+2 \$0|zcat;exit" > go.sh
gzip a ;
cat a.gz >> go.sh
chomod u+x go.sh

The file so created when executed returns the starting text, 402 Bytes.


答:
Pyth, 8 bytes

```<code>_@{y/RQy
</code>```

Try it online: Demonstration or Test Suite

This is exponentially slow.

Explanation:

```<code>_@{y/RQyQQ    implicit Qs at the end, (Q = input)
       yQ     2*Q
    /RQ       divide each number in [0, 1, ..., 2*Q-1] by Q
              this results in a list of Q zeros and Q ones
   y          take all subsets
  {           remove duplicates
 @       Q    take the Qth element
_             print it reversed
</code>```

Title: Generate the Rummy Sequence

Body:
Your task is to take an input n and output element n of the Rummy Sequence, a sequence which I made (looking on OEIS will not help you).

Definition

Each element of the Rummy Sequence is a set of truthy or falsey values. Ex.: [true, false].

The steps to producing a member of the Rummy Sequence are quite simple:

Start out with the first index, [] (this is element 0).

Set the leftmost falsey to truthy. If there are no falseys to change, then increase the length of the list by 1 and set all members of the new list to falsey.

Repeat step 2 until reaching element n.

Example

Let's define our function as rummy(int n) (stuff in {} is a step taken to get to the answer):

```<code>>>> rummy(5)
{[]}
{[false]}
{[true]}
{[false, false]}
{[true, false]}
[true, true]
</code>```

Rules

Standard loopholes apply.

Must work for inputs 0 through your language's upper numerical bound.

You may output in any way you see fit, provided that it is clear that the output is a set of truthy/falseys.

Trivia

I call this the "Rummy Sequence" because, starting at index 2, it defines the sets you would need to lay down in each round of Progressive Rummy, where falsey is a book and truthy is a run.

Test Cases

```<code>>>> rummy(0)
[]

>>> rummy(1)
[false]

>>> rummy(6)
[false, false, false]

>>> rummy(20)
[true, true, true, true, true]

>>> rummy(1000)
[true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
</code>```

Body:
Pyth, 8 bytes

_@{y/RQy

Try it online: Demonstration or Test Suite

This is exponentially slow.

Explanation:

_@{y/RQyQQ    implicit Qs at the end, (Q = input)
       yQ     2*Q
    /RQ       divide each number in [0, 1, ..., 2*Q-1] by Q
              this results in a list of Q zeros and Q ones
   y          take all subsets
  {           remove duplicates
 @       Q    take the Qth element
_             print it reversed


答:
Javascript (Using external library) (105 bytes)

```<code>_.Range(97,26).Concat(_.Range(65,26).Concat(_.Range(48,10))).Push(95).Write("",x=>String.fromCharCode(x))
</code>```

What this does is gets the char code ranges from a-z, concats with A-Z, then concats 0-9, then pushes the code for _. Write takes a delimiter and joins everything together

Library: https://github.com/mvegh1/Enumerable/blob/master/linq.js

Title: Print all alphanumeric characters plus underscore

Body:
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

var QUESTION_ID=85666,OVERRIDE_USER=4162;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;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:
Javascript (Using external library) (105 bytes)

_.Range(97,26).Concat(_.Range(65,26).Concat(_.Range(48,10))).Push(95).Write("",x=>String.fromCharCode(x))

What this does is gets the char code ranges from a-z, concats with A-Z, then concats 0-9, then pushes the code for _. Write takes a delimiter and joins everything together

Library: https://github.com/mvegh1/Enumerable/blob/master/linq.js


答:
JavaScript, 55 bytes

x=>[...new Set(Object.keys(this).join`j345689`)].join``
```

The code works correctly only when executed inside the global Firefox browser console (tested with Firefox 47.0 on Linux Mint inside a freshly created profile).

To be able to open the console, you first have to set devtools.chrome.enabled to true in about:config. (You can then open it using Ctrl + Shift + J).

Even the most ridiculously small change to the browser will likely break this code. In fact, I'm not sure if it will even work on another operating system.

The name of the profile might matter as well. I've named mine Default User.

Body:
JavaScript, 55 bytes

x=>[...new Set(Object.keys(this).join`j345689`)].join``

The code works correctly only when executed inside the global Firefox browser console (tested with Firefox 47.0 on Linux Mint inside a freshly created profile).

To be able to open the console, you first have to set devtools.chrome.enabled to true in about:config. (You can then open it using Ctrl + Shift + J).

Even the most ridiculously small change to the browser will likely break this code. In fact, I'm not sure if it will even work on another operating system.

The name of the profile might matter as well. I've named mine Default User.


答:
Java, <s>117</s> 110 bytes

```<code>enum B{T,F};B[]r(int n){int i=0,c=0,j=0;while(n>=i)i+=++c;B[]a=new B[c-1];for(;j<n-i+c;)a[j++]=B.T;return a;}
</code>```

created my own boolean type, which allowed me to save 7bytes

Title: Generate the Rummy Sequence

Body:
Java, <s>117</s> 110 bytes

enum B{T,F};B[]r(int n){int i=0,c=0,j=0;while(n>=i)i+=++c;B[]a=new B[c-1];for(;j<n-i+c;)a[j++]=B.T;return a;}

created my own boolean type, which allowed me to save 7bytes


Body:
Brainfuck 36 Bytes (96 commands)

>++++++[-<++++++++>]+++++[<.+.+>-]<+++++++>+++++++++++++[-<.+.+>]<++++.++>+++++++++++++[-<.+.+>]

Explanation:

 >++++++[-<++++++++>]    Increment to '0'
 +++++[<.+.+>-]          Print 10 characters (0 to 9)
 <+++++++>               Increment to lower upper characters
 +++++++++++++[-<.+.+>]  Print 26 characters (A to Z)
 <++++.++>               Increment to '_' Print it and move to a
 +++++++++++++[-<.+.+>]  Print 26 characters (a to z)

EDIT: Most straightforward solution IMHO, still shorter than the others


答:
Pyth, 14 bytes

0-indexed.

```<code>ss.e.e*ZqZ+kYb
</code>```

Test suite.

Title: Dijkstra's Challenge

Body:
Presented in honor of APL as an interactive tool turning 50 this year

Background

Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-be famous names, and a few future Turing Award winners (Backus, Curry, Dijkstra, Floyd, Iverson, Newell, Perlis, Wilkes). The paper also records the discussion that occurred after the presentation, ending with an exchange between Ken and [Edsger] Dijkstra, in which Ken’s reply to Dijkstra’s question was a one-liner.

Challenge

How would you represent a more complex operation, for example, the sum of all elements of a matrix M which are equal to the sum of the corresponding row and column indices?

Write a snippet or expression (no need for a full program or function) to calculate the sum of each element in a given integer matrix which is equal to the sum of its indices. Or, as FryAmTheEggman puts it: given a matrix M with elements aij return the sum of each aij where aij = i + j.

You may assume the matrix already being in a variable or memory location, or you may take it as an argument or input. You may use either 0 or 1 based indices.

Test cases

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

0 for empty matrix

```<code>2
</code>```

0 for 0 based indices or 2 for 1-based

```<code>1 5 2
9 4 2
5 9 6
</code>```

2 for 0 based or 10 for 1 based

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

11

```<code>3 -1 3 3
3 -1 3 1
</code>```

6 for 0 based or 3 for 1 based

Anecdote

Iverson's answer was ++/(M = ⍳¹ ⨢ ⍳¹)//M, which is neither valid in the Iverson Notation as defined in A Programming Language, nor in what eventually became APL. In Iverson notation, it would have been +/(M = ⍳¹(μ(M)) ⨢ ⍳¹(ν(M)))/M. In the very first versions of APL it was +/(,M=(⍳1↑⍴M)∘.+⍳1↓⍴M)/,M.

Body:
Pyth, 14 bytes

0-indexed.

ss.e.e*ZqZ+kYb

Test suite.


答:
///, <s>523</s> 512 bytes

```<code>/_/\/\///:/ar_!/, what do you he:?
I he: _$/!a_#/ing in my e:.

_%/ing like a_&/, _*/,
_0/Pol: Be:_1/ion_2/ippopotamus_3/lamingo_4/ebra_5/oa _S/onstrictor_6/lephant_7/eopard_8/eacock_9/alrus_Q/ookeeper_R/trumpet/0&0$ l1 ro:#L1&L1$ h2 snort#H2&H2$ f3 flut#F3&F3$ z4 bray#Z4&Z4$ b5cS hiss#B5CS&B5CS$n e6 R#E6&E6$ l7 snarl#L7&L7$ p8 yelp#P8&P8$ w9 bellow#W9&W9$ zQ whistl#ZQ&ZQ!children...

...growl% pol: be:*ro:% l1*snort% h2*flut% f3*bray% z4*hiss% b5cS*R%n e6*snarl% l7*yelp% p8*bellow% w9...
that's what I he:.
</code>```

Try it online!

608 bytes less than the actual message (1120), this is less than half of it (560)!

Body:
///, <s>523</s> 512 bytes

/_/\/\///:/ar_!/, what do you he:?
I he: _$/!a_#/ing in my e:.

_%/ing like a_&/, _*/,
_0/Pol: Be:_1/ion_2/ippopotamus_3/lamingo_4/ebra_5/oa _S/onstrictor_6/lephant_7/eopard_8/eacock_9/alrus_Q/ookeeper_R/trumpet/0&0$ l1 ro:#L1&L1$ h2 snort#H2&H2$ f3 flut#F3&F3$ z4 bray#Z4&Z4$ b5cS hiss#B5CS&B5CS$n e6 R#E6&E6$ l7 snarl#L7&L7$ p8 yelp#P8&P8$ w9 bellow#W9&W9$ zQ whistl#ZQ&ZQ!children...

...growl% pol: be:*ro:% l1*snort% h2*flut% f3*bray% z4*hiss% b5cS*R%n e6*snarl% l7*yelp% p8*bellow% w9...
that's what I he:.

<a href="//slashes.tryitonline.net/#code=L18vXC9cLy8vOi9hcl8hLywgd2hhdCBkbyB5b3UgaGU6PwpJIGhlOiBfJC8hYV8jL2luZyBpbiBteSBlOi4KCl8lL2luZyBsaWtlIGFfJi8sIF8qLywKXzAvUG9sOiBCZTpfMS9pb25fMi9pcHBvcG90YW11c18zL2xhbWluZ29fNC9lYnJhXzUvb2EgX1Mvb25zdHJpY3Rvcl82L2xlcGhhbnRfNy9lb3BhcmRfOC9lYWNvY2tfOS9hbHJ1c19RL29va2VlcGVyX1IvdHJ1bXBldC8wJjAkIGwxIHJvOiNMMSZMMSQgaDIgc25vcnQjSDImSDIkIGYzIGZsdXQjRjMmRjMkIHo0IGJyYXkjWjQmWjQkIGI1Y1MgaGlzcyNCNUNTJkI1Q1MkbiBlNiBSI0U2JkU2JCBsNyBzbmFybCNMNyZMNyQgcDggeWVscCNQOCZQOCQgdzkgYmVsbG93I1c5Jlc5JCB6USB3aGlzdGwjWlEmWlEhY2hpbGRyZW4uLi4KCi4uLmdyb3dsJSBwb2w6IGJlOipybzolIGwxKnNub3J0JSBoMipmbHV0JSBmMypicmF5JSB6NCpoaXNzJSBiNWNTKlIlbiBlNipzbmFybCUgbDcqeWVscCUgcDgqYmVsbG93JSB3OS4uLgp0aGF0J3Mgd2hhdCBJIGhlOi4" rel="noreferrer">Try it online!

608 bytes less than the actual message (1120), this is less than half of it (560)!


答:
C#, <s>575</s> <s>525</s> <s>520</s> <s>526</s> <s>507</s> <s>504</s> <s>497</s> <s>494</s> 493 bytes

()=>{var t="growl,Polar Bear,roar,Lion,snort,Hippopotamus,flut,Flamingo,bray,Zebra,hiss,Boa Constrictor,trumpet,Elephant,snarl,Leopard,yelp,Peacock,bellow,Walrus,whistl,Zookeeper".Split(',');string r="",s="",z="a ",n="an ";for(int i=0,j=0;i<21;r+=t[++i]+$", {t[i]}, what do you hear?\nI hear "+(i>19?@"children...

...":(i==11?n:z)+t[++i+1].ToLower()+$" {t[i]}ing in my ear.\n\n"))s+=j<20?t[j]+"ing like "+(j==12?n:z)+t[++j].ToLower()+(++j<20?@",
":@"...
"):"that's what I hear.";return r+s;};
```

<p>C# lambda where the output is a <code>string</code>.</p>

<h3>Explanation</h3>

<ol>
<li>Init <code>t</code> as a string with the format <code>noise,animal,noise,animal,...</code> and split by <code>,</code>.</li>
<li>Declare <code>r</code> and <code>s</code>. <code>r</code> is the first part of the song and <code>s</code> the last part. <code>z</code> and <code>n</code> are here to handle <code>Elephant</code>.</li>
<li>Walk <code>t</code> and build <code>r</code> and <code>s</code> in the same loop. Weird ternary+interpolated stuff.</li>
<li>Return the first part of the song followed by the last part.</li>
</ol>

<h3>Code</h3>

<pre class="lang-csharp prettyprint-override"><code>()=>{
    var t="growl,Polar Bear,roar,Lion,snort,Hippopotamus,flut,Flamingo,bray,Zebra,hiss,Boa Constrictor,trumpet,Elephant,snarl,Leopard,yelp,Peacock,bellow,Walrus,whistl,Zookeeper".Split(',');
    string r="",s="",z="a ",n="an ";
    for(int i=0,j=0;i<21;r+=t[++i]+$", {t[i]}, what do you hear?\nI hear "+(i>19?@"children...

...":(i==11?n:z)+t[++i+1].ToLower()+$" {t[i]}ing in my ear.\n\n"))
        s+=j<20?t[j]+"ing like "+(j==12?n:z)+t[++j].ToLower()+(++j<20?@",
":@"...
"):"that's what I hear.";
    return r+s;
};
</code>```

Try it online!

Body:
C#, <s>575</s> <s>525</s> <s>520</s> <s>526</s> <s>507</s> <s>504</s> <s>497</s> <s>494</s> 493 bytes

()=>{var t="growl,Polar Bear,roar,Lion,snort,Hippopotamus,flut,Flamingo,bray,Zebra,hiss,Boa Constrictor,trumpet,Elephant,snarl,Leopard,yelp,Peacock,bellow,Walrus,whistl,Zookeeper".Split(',');string r="",s="",z="a ",n="an ";for(int i=0,j=0;i<21;r+=t[++i]+$", {t[i]}, what do you hear?\nI hear "+(i>19?@"children...

...":(i==11?n:z)+t[++i+1].ToLower()+$" {t[i]}ing in my ear.\n\n"))s+=j<20?t[j]+"ing like "+(j==12?n:z)+t[++j].ToLower()+(++j<20?@",
":@"...
"):"that's what I hear.";return r+s;};

C# lambda where the output is a string.

Explanation

Init t as a string with the format noise,animal,noise,animal,... and split by ,.

Declare r and s. r is the first part of the song and s the last part. z and n are here to handle Elephant.

Walk t and build r and s in the same loop. Weird ternary+interpolated stuff.

Return the first part of the song followed by the last part.

Code

()=>{
    var t="growl,Polar Bear,roar,Lion,snort,Hippopotamus,flut,Flamingo,bray,Zebra,hiss,Boa Constrictor,trumpet,Elephant,snarl,Leopard,yelp,Peacock,bellow,Walrus,whistl,Zookeeper".Split(',');
    string r="",s="",z="a ",n="an ";
    for(int i=0,j=0;i<21;r+=t[++i]+$", {t[i]}, what do you hear?\nI hear "+(i>19?@"children...

...":(i==11?n:z)+t[++i+1].ToLower()+$" {t[i]}ing in my ear.\n\n"))
        s+=j<20?t[j]+"ing like "+(j==12?n:z)+t[++j].ToLower()+(++j<20?@",
":@"...
"):"that's what I hear.";
    return r+s;
};

Try it online!


问:
Approximation of e
We all know that the Euler's number, denoted by \$e\$, to the power of some variable \$x\$, can be approximated by using the Maclaurin Series expansion:

$$e^x=\sum_{k=0}^{\infty}{\frac{x^k}{k!}}=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\frac{x^4}{4!}+\dots$$

By letting \$x\$ equal \$1\$, we obtain

$$\sum_{k=0}^{\infty}{\frac{1}{k!}{=\frac{1}{0!}+\frac{1}{1!}+\frac{1}{2!}+\frac{1}{3!}+\frac{1}{4!}+\dots\\=1+1+\frac{1}{2}+\frac{1}{6}+\frac{1}{24}+\dots}}$$

Challenge

Write a program in any language which approximates Euler's number by taking in an input \$n\$ and calculates the series to the \$n\$th term. Note that the first term has denominator \$0!\$, not \$1!\$, i.e. \$n=1\$ corresponds to \$\frac{1}{0!}\$.

Scoring

Program with least amount of bytes wins.

Title: Approximation of e

Body:
Java with Ten Foot Laser Pole, <s>238</s> 236 bytes

import sj224.tflp.math.*;interface U{static void main(String[]a){BigRational r=null,s,t;r=s=t=r.ONE;for(int n=new java.util.Scanner(System.in).nextInt()-1;n-->0;){t=t.multiply(r);s=s.add(t.pow(-1));r=r.add(r.ONE);}System.out.print(s);}}

Has much better overflow resistance than most of the other answers. For 100 terms, the result is

31710869445015912176908843526535027555643447320787267779096898248431156738548305814867560678144006224158425966541000436701189187481211772088720561290395499/11665776930493019085212404857033337561339496033047702683574120486902199999153739451117682997019564785781712240103402969781398151364608000000000000000000000


答:
Mathematica, 49 bytes

```<code>a=CharacterRange;"_"<>{48~a~57,65~a~90,97~a~122}&
</code>```

Anonymous function. Takes no input and returns the string "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" as output. Just concatenates a few character ranges.

Body:
Mathematica, 49 bytes

a=CharacterRange;"_"<>{48~a~57,65~a~90,97~a~122}&

Anonymous function. Takes no input and returns the string "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" as output. Just concatenates a few character ranges.


答:
PowerShell v4+, 107 bytes

```<code>param($n)((($n+($x='Pinky','Inky','Blinky','Clyde')|group|?{$_.count-eq1}).Name),$x)['-'-in[char[]]-join$n]
</code>```

A little clunky compared to others, as PowerShell lacks a ternary operator or any sort of map-style operator. As a result, we build our own.

Takes input $n as an explicit array of strings (e.g., .\which-ghosts-are-missing.ps1 @('Clyde','Blinky'). The rest of the program is one pseudo-ternary that's composed of an array that we index into via some logic [...]. The logic is simply whether the - character is anywhere in the input array -joined together into a single string and then re-cast as a char array, in order to use the -in operator. Thus, if Pac-Man is in the input array, this will be $TRUE and the second element of the pseudo-ternary array will be chosen, else the first will be chosen.

If it's the case that Pac-Man is not in the array, the first portion of the pseudo-ternary array is output. That is a combination of the input array $n concatenated with an array of all the ghosts (saved into $x). We pipe that new array into Group-Object which will group like items together, then select using Where-Object (aliased via |?{...} only the items where their .count is -equal to 1. That's all encapsulated in a parens, and we select the .Name property. This is where the v4 requirement comes in, as under v4 you can reference a hashtable label like this rather than using something like |Select Name, which saves several bytes.

Otherwise, since Pac-Man is in the input array, we need to output all the ghosts. Thankfully we already saved those into $x, so that's the choice in this case. Either way, the pipeline now contains a string array of ghosts, and output is implicit.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Clyde')
Pinky
Inky
Blinky

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Pac-Man','Clyde')
Pinky
Inky
Blinky
Clyde

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @()
Pinky
Inky
Blinky
Clyde

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Clyde','Blinky')
Pinky
Inky
</code>```

Title: Which ghosts are missing?

Body:
In this challenge, given a list of ghosts from Pac-Man, you must output which ghosts are missing. You must do it in as few bytes as you can

Input

Input will consist of a string or list, which will include a number ghosts, which could include:

Blinky

Inky

Pinky

Clyde

However, input may also include Pac-Man (with that punctuation). So, the maximum amount of items in a list will be five, in any order. It can be assumed that no invalid items will be in the list

Output

Output will consist of a string, or list. This will include of all the ghosts that are not in the input, in any order. However, if Pac-Man is in the input, all ghosts will be considered missing (because he eats them).

Test cases

```<code>input: Clyde
output: Blinky, Inky, Pinky
alternate output: Inky, Pinky, Blinky
or one of the other 4 permutations

input: Clyde, Blinky # or however you delimit it
output: Inky, Pinky
alt: Pinky, Inky

input: Pac-Man, Clyde
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations

input:[null]
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations
</code>```

This is codegolf, so the lower the bytecount, the better.

Body:
PowerShell v4+, 107 bytes

param($n)((($n+($x='Pinky','Inky','Blinky','Clyde')|group|?{$_.count-eq1}).Name),$x)['-'-in[char[]]-join$n]

A little clunky compared to others, as PowerShell lacks a ternary operator or any sort of map-style operator. As a result, we build our own.

Takes input $n as an explicit array of strings (e.g., .\which-ghosts-are-missing.ps1 @('Clyde','Blinky'). The rest of the program is one pseudo-ternary that's composed of an array that we index into via some logic [...]. The logic is simply whether the - character is anywhere in the input array -joined together into a single string and then re-cast as a char array, in order to use the -in operator. Thus, if Pac-Man is in the input array, this will be $TRUE and the second element of the pseudo-ternary array will be chosen, else the first will be chosen.

If it's the case that Pac-Man is not in the array, the first portion of the pseudo-ternary array is output. That is a combination of the input array $n concatenated with an array of all the ghosts (saved into $x). We pipe that new array into Group-Object which will group like items together, then select using Where-Object (aliased via |?{...} only the items where their .count is -equal to 1. That's all encapsulated in a parens, and we select the .Name property. This is where the v4 requirement comes in, as under v4 you can reference a hashtable label like this rather than using something like |Select Name, which saves several bytes.

Otherwise, since Pac-Man is in the input array, we need to output all the ghosts. Thankfully we already saved those into $x, so that's the choice in this case. Either way, the pipeline now contains a string array of ghosts, and output is implicit.

Examples

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Clyde')
Pinky
Inky
Blinky

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Pac-Man','Clyde')
Pinky
Inky
Blinky
Clyde

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @()
Pinky
Inky
Blinky
Clyde

PS C:\Tools\Scripts\golfing> .\which-ghosts-are-missing.ps1 @('Clyde','Blinky')
Pinky
Inky


答:
Jelly, <s>15</s> <s>14</s> 10 bytes

4 bytes thanks to Adnan.

1-indexed.

```
<s>L€R€+"LR$=³×³FS</s>
<s>L€R€+"LR$=×³FS</s>
J€+"J=×⁸FS
```

Try it online!

Verify all testcases at once.
(Slightly modified.)

Title: Dijkstra's Challenge

Body:
Jelly, <s>15</s> <s>14</s> 10 bytes

4 bytes thanks to Adnan.

1-indexed.

<s>L€R€+"LR$=³×³FS</s>
<s>L€R€+"LR$=×³FS</s>
J€+"J=×⁸FS

Try it online!

Verify all testcases at once.
(Slightly modified.)


答:
F#, <s>50</s> 59 bytes

```<code>Seq.iter(printf"%c"<<char)(95::[48..57]@[65..90]@[97..122])
</code>```

Output:

```<code>_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
</code>```

Edit: missed the digits the first time

Edit2, inspired by this Haskell solution this F# snippet is 67 bytes.

```<code>Seq.zip"aA0_""zZ9_"|>Seq.iter(fun(x,y)->Seq.iter(printf"%c")[x..y])
</code>```

Output:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

Body:
F#, <s>50</s> 59 bytes

Seq.iter(printf"%c"<<char)(95::[48..57]@[65..90]@[97..122])

Output:

_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Edit: missed the digits the first time

Edit2, inspired by this Haskell solution this F# snippet is 67 bytes.

Seq.zip"aA0_""zZ9_"|>Seq.iter(fun(x,y)->Seq.iter(printf"%c")[x..y])

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_


答:
Python 2 - 60 57 bytes

It's a code snippet, so it would be a few more bytes if I actually returned the value, I guess.
e=enumerate;sum(i*(x+y==i)for x,r in e(a)for y,i in e(r))

Thanks for the help Leaky Num :-)

Quick explanation. a is an array holding numbers. Simply iterate through indexes and sum up all values where the value equals the sum of the index.

Title: Dijkstra's Challenge


答:
Common Lisp, 160 bytes

```<code>(setq a 47)(loop(setq a(+ a 1))(princ(code-char a))(when(and(> a 56)(< a 64))(setq a 64))(when(and(> a 89)(< a 96))(setq a 96))(when(> a 121)(return)))(princ'_)
</code>```

Body:
Common Lisp, 160 bytes

(setq a 47)(loop(setq a(+ a 1))(princ(code-char a))(when(and(> a 56)(< a 64))(setq a 64))(when(and(> a 89)(< a 96))(setq a 96))(when(> a 121)(return)))(princ'_)


答:
APL, <s>13</s> 12 bytes

1 byte thanks to @jimmy23013.

1-indexed.

The array is stored in the variable m.

```
<s>+/,m×m=+/¨⍳⍴m</s>
+/∊m∩¨+/¨⍳⍴m
```

Try it online!

Based on the answer in J, which is a language based on APL.

In TryAPL, to key in: +/m`em`c`1+/`1`i`rm

With the array: +/m`em`c`1+/`1`i`rm `[ 2 4 `r 3 `21 3 3 3 `21 3 1

Explanation

```<code>+/∊m∩¨+/¨⍳⍴m
           m    temp ← variable
          ⍴     temp ← shape of temp
         ⍳      temp ← a 2D array where each element is
                       the corresponding index. for the
                       example, this gives:
                       ┌───┬───┬───┬───┐
                       │1 1│1 2│1 3│1 4│
                       ├───┼───┼───┼───┤
                       │2 1│2 2│2 3│2 4│
                       └───┴───┴───┴───┘
      +/¨       each element in temp ← its sum
   m∩¨          temp ← intersect each element in temp with the variable
+/              temp ← sum of temp
</code>```

Title: Dijkstra's Challenge

Body:
APL, <s>13</s> 12 bytes

1 byte thanks to @jimmy23013.

1-indexed.

The array is stored in the variable m.

<s>+/,m×m=+/¨⍳⍴m</s>
+/∊m∩¨+/¨⍳⍴m

Try it online!

Based on the answer in J, which is a language based on APL.

In TryAPL, to key in: +/m`em`c`1+/`1`i`rm

With the array: +/m`em`c`1+/`1`i`rm `[ 2 4 `r 3 `21 3 3 3 `21 3 1

Explanation

+/∊m∩¨+/¨⍳⍴m
           m    temp ← variable
          ⍴     temp ← shape of temp
         ⍳      temp ← a 2D array where each element is
                       the corresponding index. for the
                       example, this gives:
                       ┌───┬───┬───┬───┐
                       │1 1│1 2│1 3│1 4│
                       ├───┼───┼───┼───┤
                       │2 1│2 2│2 3│2 4│
                       └───┴───┴───┴───┘
      +/¨       each element in temp ← its sum
   m∩¨          temp ← intersect each element in temp with the variable
+/              temp ← sum of temp


答:
PowerShell v2+, 43 bytes

```<code>%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o
</code>```

As a snippet. Usage is to explicitly pipe the matrix to this (see examples below). Assumes that $i, and $o are either null or zero at the start (I've explicitly set them as such in the examples below), and utilizes 0-index.

Does a foreach loop on each row of the matrix. We set $j to 0, and then go through each element of the row in another loop $_|%{...}. Each inner loop, we increment $o by the current element multiplied by a Boolean ($_-eq$i+$j++), meaning if that Boolean is $TRUE, it'll be 1, otherwise 0. Then we exit the inner loop, increment $i, and start the next row. Finally, we leave $o on the pipeline at the end.

Examples

```<code>PS C:\Tools\Scripts\golfing> $o=0;$i=0;$j=0;@(@(3,-1,3,3),@(3,-1,3,1))|%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o
6

PS C:\Tools\Scripts\golfing> $o=0;$i=0;$j=0;@(@(0,3,0,4),@(0,4,1,4),@(4,3,1,2),@(-2,4,-2,-1))|%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o
11
</code>```

Title: Dijkstra's Challenge

Body:
PowerShell v2+, 43 bytes

%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o

As a snippet. Usage is to explicitly pipe the matrix to this (see examples below). Assumes that $i, and $o are either null or zero at the start (I've explicitly set them as such in the examples below), and utilizes 0-index.

Does a foreach loop on each row of the matrix. We set $j to 0, and then go through each element of the row in another loop $_|%{...}. Each inner loop, we increment $o by the current element multiplied by a Boolean ($_-eq$i+$j++), meaning if that Boolean is $TRUE, it'll be 1, otherwise 0. Then we exit the inner loop, increment $i, and start the next row. Finally, we leave $o on the pipeline at the end.

Examples

PS C:\Tools\Scripts\golfing> $o=0;$i=0;$j=0;@(@(3,-1,3,3),@(3,-1,3,1))|%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o
6

PS C:\Tools\Scripts\golfing> $o=0;$i=0;$j=0;@(@(0,3,0,4),@(0,4,1,4),@(4,3,1,2),@(-2,4,-2,-1))|%{$j=0;$_|%{$o+=$_*($_-eq$i+$j++)};$i++};$o
11


答:
05AB1E, <s>349</s> <s>331</s> <s>330</s> <s>322</s> <s>314</s> 311 bytes

```<code>•4i;kV_†©:š×Îj€Yå—‚‘%˜ESÎ´þ¤çÑ9¶‹{Å€7¾à{Ì®qA•35B0¡…ing«lV•7ü[¿‘¢wÀ¶à-‚¤î„jHâ™ÐJ'µ‡ÀÂý6›ü‚š¸€%NtÅýµL›fU¥ì€€uîT¡›Ÿ{!œ>'Ì&ý§¨Ü?é>•36B1ð:0¡™D©„, «D‚ø“€À€·€î—«?“¶«¸â€˜€JU¦“„¾“‚˜lv„I “—«0€†€¯¶å.“«0¡`yð«Y¦õ‚˜Nè«sr„ aN5Qi'n«}ð«N9›ijrj¨ðs«…...«}srJˆ}X¯‚ø€Jvy,¶?}…...DU?Y¨vN__i',¶}yð“€è€…“N6Qi'n«}ð®NèJl?}X,“€Š's€À I—«.“?
</code>```

Try it online

Explanation

•4i;kV_†©:š×Îj€Yå—‚‘%˜ESÎ´þ¤çÑ9¶‹{Å€7¾à{Ì®qA•

Packed string containing the sounds GROWL0ROAR0SNORT0FLUT0BRAY0HISS0TRUMPET0SNARL0YELP0BELLOW0WHISTL

35B0¡…ing«lV

Unpack, split on 0, add "ing" to each word, convert to lower and store in variable Y

•7ü[¿‘¢wÀ¶à-‚¤î„jHâ™ÐJ'µ‡ÀÂý6›ü‚š¸€%NtÅýµL›fU¥ì€€uîT¡›Ÿ{!œ>'Ì&ý§¨Ü?é>•

Packed string containing the animals POLAR1BEAR0LION0HIPPOPOTAMUS0FLAMINGO0ZEBRA0BOA1CONSTRICTOR0ELEPHANT0LEOPARD0PEACOCK0WALRUS0ZOOKEEPER

36B1ð:0¡™

Unpack, replace 1 with space, split on 0 and convert to title case

D©„, «D‚ø

Duplicate, save to register for later use, add ", " to one copy, duplicate that and zip.

“€À€·€î—«?“¶«¸

Dictionary words "what do you hear?", followed by a new line, added to a new list

â€˜€JU

Cartesian product of list of "Animal, Animal, " and "what do you hear?\n", flattened and joined and stores it in variable X.
Pruduces list of strings of the form "Animal, Animal, what do you hear?n".

¦“„¾“‚˜l

Take the remaining list of animals from before, remove the zookeeper and add children, convert to lower case.

v

For each animal:

```<code>„I “—«0€†€¯¶å.“«0¡`
</code>```

Push "I hear0 in my ear.", split on 0 and push as separate strings.

yð«Y¦õ‚˜Nè«

Push "animal sound" with children having no sound

sr„ a

Push "a" in correct place

N5Qi'n«}

If the animal is "Elephant" add "n"

ð«

Add space.

N9›ijrj¨ðs«…...«}

If animal is children, remove space and add "..."

srJˆ}

Join the sentence "I hear a(n) animal sound in my ear." (as well as the children one), store in global array and end loop

X¯‚ø€J

Retrieve the first lines, zip and join producing the first part of the rhyme "Animal, Animal, what do you hear?\nI hear a(n) animal sound in my ear."

vy,¶?}

Print followed by new line.

…...DU?

Print "..." and store a copy in variable X.

Y¨v

For each sound except "whistling":

N__i',¶}
For each line except the first one, start it with ",\n" (making the comma go on previous line)

yð“€è€…“

Push sound, space and "like a"

N6Qi'n«}

If Elephant add "n".

ð®NèJl?}X,

Retrieve the animal saved in register, join everything, print and end loop followed by "...".
This produces the "sound like a(n) animal," lines.

“€Š's€À I—«.“?

Print dictionary string "that's what I hear."

Body:
The text of the children's book Polar Bear, Polar Bear, What Do You Hear?  has a very simple pattern.  You might use the text to teach introductory programming concepts.

My son was quickly bored by this idea, so I decided to play some golf with it instead.

The Challenge

In your programming language of choice, write the smallest program possible which will print the following text.  Output should match exactly, including case, spacing, and punctuation.

```<code>Polar Bear, Polar Bear, what do you hear?
I hear a lion roaring in my ear.

Lion, Lion, what do you hear?
I hear a hippopotamus snorting in my ear.

Hippopotamus, Hippopotamus, what do you hear?
I hear a flamingo fluting in my ear.

Flamingo, Flamingo, what do you hear?
I hear a zebra braying in my ear.

Zebra, Zebra, what do you hear?
I hear a boa constrictor hissing in my ear.

Boa Constrictor, Boa Constrictor, what do you hear?
I hear an elephant trumpeting in my ear.

Elephant, Elephant, what do you hear?
I hear a leopard snarling in my ear.

Leopard, Leopard, what do you hear?
I hear a peacock yelping in my ear.

Peacock, Peacock, what do you hear?
I hear a walrus bellowing in my ear.

Walrus, Walrus, what do you hear?
I hear a zookeeper whistling in my ear.

Zookeeper, Zookeeper, what do you hear?
I hear children...

...growling like a polar bear,
roaring like a lion,
snorting like a hippopotamus,
fluting like a flamingo,
braying like a zebra,
hissing like a boa constrictor,
trumpeting like an elephant,
snarling like a leopard,
yelping like a peacock,
bellowing like a walrus...
that's what I hear.
</code>```

Body:
05AB1E, <s>349</s> <s>331</s> <s>330</s> <s>322</s> <s>314</s> 311 bytes

•4i;kV_†©:š×Îj€Yå—‚‘%˜ESÎ´þ¤çÑ9¶‹{Å€7¾à{Ì®qA•35B0¡…ing«lV•7ü[¿‘¢wÀ¶à-‚¤î„jHâ™ÐJ'µ‡ÀÂý6›ü‚š¸€%NtÅýµL›fU¥ì€€uîT¡›Ÿ{!œ>'Ì&ý§¨Ü?é>•36B1ð:0¡™D©„, «D‚ø“€À€·€î—«?“¶«¸â€˜€JU¦“„¾“‚˜lv„I “—«0€†€¯¶å.“«0¡`yð«Y¦õ‚˜Nè«sr„ aN5Qi'n«}ð«N9›ijrj¨ðs«…...«}srJˆ}X¯‚ø€Jvy,¶?}…...DU?Y¨vN__i',¶}yð“€è€…“N6Qi'n«}ð®NèJl?}X,“€Š's€À I—«.“?

<a href="http://05ab1e.tryitonline.net/#code=4oCiNGk7a1Zf4oCgwqk6xaHDl8OOauKCrFnDpeKAlOKAmuKAmCXLnEVTw47CtMO-wqTDp8OROcK24oC5e8OF4oKsN8K-w6B7w4zCrnFB4oCiMzVCMMKh4oCmaW5nwqtsVuKAojfDvFvCv-KAmMKid8OAwrbDoC3igJrCpMOu4oCeakjDouKEosOQSifCteKAocOAw4LDvTbigLrDvOKAmsWhwrjigqwlTnTDhcO9wrVM4oC6ZlXCpcOs4oKs4oKsdcOuVMKh4oC6xbh7IcWTPifDjCbDvcKnwqjDnD_DqT7igKIzNkIxw7A6MMKh4oSiRMKp4oCeLCDCq0TigJrDuOKAnOKCrMOA4oKswrfigqzDruKAlMKrP-KAnMK2wqvCuMOi4oKsy5zigqxKVcKm4oCc4oCewr7igJzigJrLnGx24oCeSSDigJzigJTCqzDigqzigKDigqzCr8K2w6Uu4oCcwqswwqFgecOwwqtZwqbDteKAmsucTsOowqtzcuKAniBhTjVRaSduwqt9w7DCq0454oC6aWpyasKow7BzwqvigKYuLi7Cq31zckrLhn1Ywq_igJrDuOKCrEp2eSzCtj994oCmLi4uRFU_WcKodk5fX2knLMK2fXnDsOKAnOKCrMOo4oKs4oCm4oCcTjZRaSduwqt9w7DCrk7DqEpsP31YLOKAnOKCrMWgJ3PigqzDgCBJ4oCUwqsu4oCcPw&input=" rel="noreferrer">Try it online

Explanation

•4i;kV_†©:š×Îj€Yå—‚‘%˜ESÎ´þ¤çÑ9¶‹{Å€7¾à{Ì®qA•

Packed string containing the sounds GROWL0ROAR0SNORT0FLUT0BRAY0HISS0TRUMPET0SNARL0YELP0BELLOW0WHISTL

35B0¡…ing«lV

Unpack, split on 0, add "ing" to each word, convert to lower and store in variable Y

•7ü[¿‘¢wÀ¶à-‚¤î„jHâ™ÐJ'µ‡ÀÂý6›ü‚š¸€%NtÅýµL›fU¥ì€€uîT¡›Ÿ{!œ>'Ì&ý§¨Ü?é>•

Packed string containing the animals POLAR1BEAR0LION0HIPPOPOTAMUS0FLAMINGO0ZEBRA0BOA1CONSTRICTOR0ELEPHANT0LEOPARD0PEACOCK0WALRUS0ZOOKEEPER

36B1ð:0¡™

Unpack, replace 1 with space, split on 0 and convert to title case

D©„, «D‚ø

Duplicate, save to register for later use, add ", " to one copy, duplicate that and zip.

“€À€·€î—«?“¶«¸

Dictionary words "what do you hear?", followed by a new line, added to a new list

â€˜€JU

Cartesian product of list of "Animal, Animal, " and "what do you hear?\n", flattened and joined and stores it in variable X.
Pruduces list of strings of the form "Animal, Animal, what do you hear?n".

¦“„¾“‚˜l

Take the remaining list of animals from before, remove the zookeeper and add children, convert to lower case.

v

For each animal:

„I “—«0€†€¯¶å.“«0¡`

Push "I hear0 in my ear.", split on 0 and push as separate strings.

yð«Y¦õ‚˜Nè«

Push "animal sound" with children having no sound

sr„ a

Push "a" in correct place

N5Qi'n«}

If the animal is "Elephant" add "n"

ð«

Add space.

N9›ijrj¨ðs«…...«}

If animal is children, remove space and add "..."

srJˆ}

Join the sentence "I hear a(n) animal sound in my ear." (as well as the children one), store in global array and end loop

X¯‚ø€J

Retrieve the first lines, zip and join producing the first part of the rhyme "Animal, Animal, what do you hear?\nI hear a(n) animal sound in my ear."

vy,¶?}

Print followed by new line.

…...DU?

Print "..." and store a copy in variable X.

Y¨v

For each sound except "whistling":

N__i',¶}
For each line except the first one, start it with ",\n" (making the comma go on previous line)

yð“€è€…“

Push sound, space and "like a"

N6Qi'n«}

If Elephant add "n".

ð®NèJl?}X,

Retrieve the animal saved in register, join everything, print and end loop followed by "...".
This produces the "sound like a(n) animal," lines.

“€Š's€À I—«.“?

Print dictionary string "that's what I hear."


答:
Python 2.x, 63 bytes

print''.join(chr(a)for a in range(123)if chr(a).isalnum())+'_'
```
<p>Try it online.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-python prettyprint-override"><code>chr(a)for a in range(123)if chr(a).isalnum() # generates a list iterating through ascii
                                             #  symbols, picking just numbers alphabet characters

''.join(...)+'_'                             # joins a list of items with no spacing;
                                             # appends '_' at the end
</code>```

My first golfing attempt; thanks to mbomb007 for the hints

Body:
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

var QUESTION_ID=85666,OVERRIDE_USER=4162;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;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:
Python 2.x, 63 bytes

print''.join(chr(a)for a in range(123)if chr(a).isalnum())+'_'

Try it online.

Explanation:

chr(a)for a in range(123)if chr(a).isalnum() # generates a list iterating through ascii
                                             #  symbols, picking just numbers alphabet characters

''.join(...)+'_'                             # joins a list of items with no spacing;
                                             # appends '_' at the end

My first golfing attempt; thanks to mbomb007 for the hints


答:
Lua, 70 bytes

1-indexed.

s=0 for i=1,#a do for j=1,#a[i]do s=i+j==a[i][j]and s+i+j or s end end
```

<p>Bonus: it works for ragged arrays!</p>

<p>Input stored in <code>a</code>, output stored in <code>s</code>.</p>

<h1>Full program:</h1>

<pre class="lang-lua prettyprint-override"><code>function Dijkstras_Challenge(a)
    s=0 for i=1,#a do for j=1,#a[i]do s=i+j==a[i][j]and s+i+j or s end end
    print(s)
end

Dijkstras_Challenge({})
Dijkstras_Challenge({{2}})
Dijkstras_Challenge({{1,5,2},{9,4,2},{5,9,6}})
Dijkstras_Challenge({{0,3,0,4},{0,4,1,4},{4,3,1,2},{-2,4,-2,-1}})
Dijkstras_Challenge({{3,-1,3,3},{3,-1,3,1}})
</code>```

Title: Dijkstra's Challenge

Body:
Presented in honor of APL as an interactive tool turning 50 this year

Background

Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-be famous names, and a few future Turing Award winners (Backus, Curry, Dijkstra, Floyd, Iverson, Newell, Perlis, Wilkes). The paper also records the discussion that occurred after the presentation, ending with an exchange between Ken and [Edsger] Dijkstra, in which Ken’s reply to Dijkstra’s question was a one-liner.

Challenge

How would you represent a more complex operation, for example, the sum of all elements of a matrix M which are equal to the sum of the corresponding row and column indices?

Write a snippet or expression (no need for a full program or function) to calculate the sum of each element in a given integer matrix which is equal to the sum of its indices. Or, as FryAmTheEggman puts it: given a matrix M with elements aij return the sum of each aij where aij = i + j.

You may assume the matrix already being in a variable or memory location, or you may take it as an argument or input. You may use either 0 or 1 based indices.

Test cases

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

0 for empty matrix

```<code>2
</code>```

0 for 0 based indices or 2 for 1-based

```<code>1 5 2
9 4 2
5 9 6
</code>```

2 for 0 based or 10 for 1 based

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

11

```<code>3 -1 3 3
3 -1 3 1
</code>```

6 for 0 based or 3 for 1 based

Anecdote

Iverson's answer was ++/(M = ⍳¹ ⨢ ⍳¹)//M, which is neither valid in the Iverson Notation as defined in A Programming Language, nor in what eventually became APL. In Iverson notation, it would have been +/(M = ⍳¹(μ(M)) ⨢ ⍳¹(ν(M)))/M. In the very first versions of APL it was +/(,M=(⍳1↑⍴M)∘.+⍳1↓⍴M)/,M.

Body:
Lua, 70 bytes

1-indexed.

s=0 for i=1,#a do for j=1,#a[i]do s=i+j==a[i][j]and s+i+j or s end end

Bonus: it works for ragged arrays!

Input stored in a, output stored in s.

Full program:

function Dijkstras_Challenge(a)
    s=0 for i=1,#a do for j=1,#a[i]do s=i+j==a[i][j]and s+i+j or s end end
    print(s)
end

Dijkstras_Challenge({})
Dijkstras_Challenge({{2}})
Dijkstras_Challenge({{1,5,2},{9,4,2},{5,9,6}})
Dijkstras_Challenge({{0,3,0,4},{0,4,1,4},{4,3,1,2},{-2,4,-2,-1}})
Dijkstras_Challenge({{3,-1,3,3},{3,-1,3,1}})


答:
Brainfuck, 89 bytes

```<code>+++++++++[>+++++>+<<-]>+++.>[<+.>-]<+++++++>>+++++++++++++[<+<+.+.>>-]<<+++++.+>[<+.+.>-]
</code>```

Try it here

Details:

```<code>+++++++++[>+++++>+<<-]>+++.  Goes to '0' while remembering a 9 for the 9 other numbers
[<+.>-]                      Simply prints for the next 9 characters
<+++++++>                    Moves it 7 space to the letters
>+++++++++++++               Saves a 13
[<+<+.+.>>-]                 Prints 2 char at a time while making a second '13' space
<<+++++.+>                   Moves 5, prints '_' and moves to the lowercases
[<+.+.>-]                    And again the double print
</code>```

If I could have commented, I would have to improve others answers. But since I can't, I might as well post my own. As I started writing this the lowest BF one was 96 long.

Body:
Brainfuck, 89 bytes

+++++++++[>+++++>+<<-]>+++.>[<+.>-]<+++++++>>+++++++++++++[<+<+.+.>>-]<<+++++.+>[<+.+.>-]

Try it here

Details:

+++++++++[>+++++>+<<-]>+++.  Goes to '0' while remembering a 9 for the 9 other numbers
[<+.>-]                      Simply prints for the next 9 characters
<+++++++>                    Moves it 7 space to the letters
>+++++++++++++               Saves a 13
[<+<+.+.>>-]                 Prints 2 char at a time while making a second '13' space
<<+++++.+>                   Moves 5, prints '_' and moves to the lowercases
[<+.+.>-]                    And again the double print

If I could have commented, I would have to improve others answers. But since I can't, I might as well post my own. As I started writing this the lowest BF one was 96 long.


问:
Select the word around the given index in a given string
In Windows, when you perform double-click in a text, the word around your cursor in the text will be selected.

(This feature has more complicated properties, but they will not be required to be implemented for this challenge.)

For example, let | be your cursor in abc de|f ghi.

Then, when you double click, the substring def will be selected.

Input/Output

You will be given two inputs: a string and an integer.

Your task is to return the word-substring of the string around the index specified by the integer.

Your cursor can be right before or right after the character in the string at the index specified.

If you use right before, please specify in your answer.

Specifications (Specs)

The index is guaranteed to be inside a word, so no edge cases like abc |def ghi or abc def| ghi.

The string will only contain printable ASCII characters (from U+0020 to U+007E).

The word "word" is defined by the regex (?<!\w)\w+(?!\w), where \w is defined by [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_], or "alphanumeric characters in ASCII including underscore".

The index can be 1-indexed or 0-indexed.

If you use 0-indexed, please specify it in your answer.

Testcases

The testcases are 1-indexed, and the cursor is right after the index specified.

The cursor position is for demonstration purpose only, which will not be required to be outputted.

```<code>string    index     output    cursor position
abc def   2         abc       ab|c def
abc def   5         def       abc d|ef
abc abc   2         abc       ab|c abc
ab cd ef  4         cd        ab c|d ef
ab   cd   6         cd        ab   c|d
ab!cd     1         ab        a|b!cd
</code>```

答:
Javascript (using external library) (168 bytes)

```<code>(n,w)=> _.From(w).Select((x,i)=>({i:i,x:x})).Split((i,v)=>v.x==" ").Where(a=>a.Min(i=>i.i)<=n-1&&a.Max(i=>i.i)>=n-2).First().Select(i=>i.x).Write("").match(/^\w*^\w*/)[0]
</code>```

Link to lib:https://github.com/mvegh1/Enumerable/blob/master/linq.js

Explanation of code: Library accepts a string, which gets parsed into a char array. It gets mapped to an object storing the index and the char. The sequence is split into subsequences at every occurrence of " ". The subsequences are filtered by checking if the cursor index is contained within the min and max index of the subsequence. Then we take the first subsequence. Then we transform back to just a char array. Then we concatenate all characters with "" as the delimiter. Then we validate against word regex. Then we take the first match.

Body:
Javascript (using external library) (168 bytes)

(n,w)=> _.From(w).Select((x,i)=>({i:i,x:x})).Split((i,v)=>v.x==" ").Where(a=>a.Min(i=>i.i)<=n-1&&a.Max(i=>i.i)>=n-2).First().Select(i=>i.x).Write("").match(/^\w*^\w*/)[0]

Link to lib:https://github.com/mvegh1/Enumerable/blob/master/linq.js

Explanation of code: Library accepts a string, which gets parsed into a char array. It gets mapped to an object storing the index and the char. The sequence is split into subsequences at every occurrence of " ". The subsequences are filtered by checking if the cursor index is contained within the min and max index of the subsequence. Then we take the first subsequence. Then we transform back to just a char array. Then we concatenate all characters with "" as the delimiter. Then we validate against word regex. Then we take the first match.


答:
Batch, <s>650</s> 647 bytes

```<code>@echo off
set e=echo(
set s=shift
call:d a "polar bear" ...growl "Polar Bear" a lion roar Lion a hippopotamus snort Hippopotamus a flamingo flut Flamingo a zebra bray Zebra a "boa constrictor" hiss "Boa Constrictor" an elephant trumpet Elephant a leopard snarl Leopard a peacock yelp Peacock a walrus bellow
exit/b
:d
call:v %* Walrus a zookeeper whistl Zookeeper
%e%I hear children...
%e%
:l
%e%%3ing like %1 %~2,
%s%
%s%
%s%
%s%
if not "%5"=="" goto l
%e%%3ing like a %2...
%e%that's what I hear.
exit/b
:v
%e%%~4, %~4, what do you hear?
if "%5"=="" exit/b
%e%I hear %5 %~6 %7ing in my ear.
%e%
%s%
%s%
%s%
%s%
goto v
</code>```

Because %* is the nearest thing Batch has to an array. If I can use Polar bear and Boa constrictor then I can save 10%... but I'm still more than 50% of the original text...

Edit: Saved 3 bytes by setting e=echo( with a ( instead of a space, which allows me to use it to echo blank lines, although I then have to write out @echo off in full.

Body:
Batch, <s>650</s> 647 bytes

@echo off
set e=echo(
set s=shift
call:d a "polar bear" ...growl "Polar Bear" a lion roar Lion a hippopotamus snort Hippopotamus a flamingo flut Flamingo a zebra bray Zebra a "boa constrictor" hiss "Boa Constrictor" an elephant trumpet Elephant a leopard snarl Leopard a peacock yelp Peacock a walrus bellow
exit/b
:d
call:v %* Walrus a zookeeper whistl Zookeeper
%e%I hear children...
%e%
:l
%e%%3ing like %1 %~2,
%s%
%s%
%s%
%s%
if not "%5"=="" goto l
%e%%3ing like a %2...
%e%that's what I hear.
exit/b
:v
%e%%~4, %~4, what do you hear?
if "%5"=="" exit/b
%e%I hear %5 %~6 %7ing in my ear.
%e%
%s%
%s%
%s%
%s%
goto v

Because %* is the nearest thing Batch has to an array. If I can use Polar bear and Boa constrictor then I can save 10%... but I'm still more than 50% of the original text...

Edit: Saved 3 bytes by setting e=echo( with a ( instead of a space, which allows me to use it to echo blank lines, although I then have to write out @echo off in full.


答:
C, <s>56</s> 55 bytes

i;k(){for(;putchar(i%26+"aA0"[i++/26])^57;);puts("_");}
```
<p>Output:</p>
```abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
```

Body:
C, <s>56</s> 55 bytes

i;k(){for(;putchar(i%26+"aA0"[i++/26])^57;);puts("_");}

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_