text:
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
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

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

If there aren't any ghosts, is the input an empty string, or [null]?

it is an empty string.

Are the input and output formats strictly string types, or can we use a list? The specs say they're strings, but then they're referred to as lists.

This is the kind of feedback I wanted in the sandpit :. I'm not sure whether or not to change it now that people have answered. I refer to them as lists, because the string contains items, formatted as a list. You would probably have a better idea of what to do. You can edit it if this is an appropriate choice

The general consensus is that cumbersome/strict input and output formats should be avoided. Splitting and joining words just makes the code longer and it doesn't really add anything to the core challenge.

Is not wrong the output with Pac-Man? can you clarify? Thanks

Overall this is a great first challenge. Nice work!

Will Pac-Man always be the first in the input?

No he will not, Mega Man

Same here. Lol a

Jelly, 25 22 bytes
Ff”-ȯ⁸“JLKqḤṢ&F⁻ı»ṣ⁶¤ḟ

This is a monadic function. I/O is in form of lists. Try it online!
How it works
Ff”-ȯ⁸“JLKqḤṢ&F⁻ı»ṣ⁶¤ḟ  Monadic link. Argument: A (list of strings)

F                       Flatten A.
 f”-                    Filter it with the string "-" to detect "Pac-Man".
    ȯ⁸                  Flat logical OR with A. This yields A if there is no '-'
                        in the input, the string "-" otherwise.
                    ¤   Combine the three links to the left into a niladic chain.
      “JLKqḤṢ&F⁻ı»        Yield "Blinky Inky Pinky Clyde", using Jelly's built-in
                          English dictionary.
                  ṣ⁶      Split at spaces to yield
                          ["Blinky", "Inky", "Pinky", "Clyde"].
                     ḟ  Filter-false; removing all elements from that list that
                        appear in A or "-". This is a noop if A contains "Pac-Man".

Which dictionary did you use that has "Pinky" etc. in it? XD

The default one that came with my OS. Pinky means little finger iirc, so it should be present in most dictionaries. I had to construct Blinky as B + linky though. Not sure what a linky is...

Retina, 45 bytes
A`-
$
,;BliNClyde,INPiN
N
nky,
D`\w+,
.*;|,$

The trailing linefeed is significant. Input and output are comma separated.
Try it online! (The first line enables a linefeed-separated test suite.)
Explanation
I did not expect to be able to show off Retina's latest addition (deduplication stages) so soon, but it's really helpful for this challenge. :)
Stage 1: Anti-Grep
A`-

Anti-grep stages discard all lines that match the given regex. The regex is just - and the input is always a single line, so this discards all ghosts if the input contains Pac-Man.
Stage 2: Substitution
$
,;BliNClyde,INPiN

This simply appends the fixed string ,;BliNClyde,INPiN. This will be the list of ghosts in the output after some clean-up.
Stage 3: Substitution
N
nky,

Note that we've written the three *nky ghosts with an N in the previous stage (and omitted the comma after them), and we now expand this shorthand, which saves a couple of bytes. There is now a comma after every single ghost, and we've got the input ghosts and list of all ghosts separated by a semicolon.
Stage 3: Deduplication
D`\w+,

This is the new part. Deduplication stages find all instances of the given regex and discard all matched substrings which are equal to an earlier matched substring. The regex simply matches all the ghosts, both in the input and in the list of potential outputs. If the input contains a ghost, then the same ghost will be matched again in the second list and is discarded. Otherwise, the ghost is matched for the first time in the second list and kept. So after this, the list after the semicolon is our desired output. All that's left is a bit of clean-up:
Stage 5: Substitution
.*;|,$

We simply match everything up to the semicolon as well as the comma at the end of the string and remove them.

What about the Pac-Man case?

@KevinLau-notKenny See the explanation of the first stage.

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.

The if(x in s)<1 part is clever! +1

JavaScript ES6, 85 78 bytes
As an anonymous function
a=>["Blinky","Inky","Pinky","Clyde"].filter(c=>!a.includes(c)|a.some(v=>v[6]))

Today I learned about this filter function. Fun!
15 bytes saved thanks to Neil.
Usage:
(a=>["Blinky","Inky","Pinky","Clyde"].filter(c=>!a.includes(c)||a.includes("Pac-Man")))(["Pac-Man"])
> ["Blinky","Inky","Pinky","Clyde"]
(a=>["Blinky","Inky","Pinky","Clyde"].filter(c=>!a.includes(c)||a.includes("Pac-Man")))(["Pinky"])
> ["Blinky","Inky","Clyde"]
(a=>["Blinky","Inky","Pinky","Clyde"].filter(c=>!a.includes(c)||a.includes("Pac-Man")))([])
> ["Blinky","Inky","Pinky","Clyde"]

Rather than special-casing Pac-Man outside the filter, I think you can add it as a.includes("Pac-Main")||!a.includes(c) in the filter, at which point you only have one use of g and can therefore inline it and turn your block into an expression thus avoiding the return statement.

@Neil Great idea. I was able to cut out the return and the {} and saved a ton of bytes, thanks!

You can also save one byte by replacing your calls to a.includes with a[z="includes"] (first) and a[z] (second). Also, I think you can save another byte by using bitwise OR (|) on your boolean results instead of logical OR (||).

Actually, since Pac-Man is the longest possible input (and invalid inputs are impossible), we can test for the existence of a seventh character to test for Pac-Man: c=>!a.includes(c)||a.some(v=>v[6]). Using that with the bitwise OR brings the score down to 78.

@apsillers Ooh, that's a great, never would have thought to check length. I changed to the bitwise or and added that, thanks!

C, 171 bytes
Pass a NULL-terminated array of strings to f(), and it will print out the missing names.
*a[]={"Blinky","Inky","Pinky","Clyde",0},**s,**r,n;f(int**p){for(r=p;*p;)r=strcmp(*p++,"Pac-Man")?r:a+4;for(s=a;*s;++s){for(p=r,n=1;n&&*p;)n=strcmp(*s,*p++);n&&puts(*s);}}

Try it on ideone.

Pyth - 45 38  35 Bytes

=GwI!:G"a")j-["inky""pinky""blinky""clyde")cG

I!:=Gw"a")j-c:" p bl clyde"d"inky "dcG

j-c:" p bl clyde"d"inky "d?:z\aZYcz

-1 more byte thanks to Leaky Nun!
Input must be space delimited, all lowercase; outputs missing ghosts on separate lines unless pac-man is in the input.

You forgot "Pac-Man"

@JacquesMarais No, it works. The :z\a detects if there's an "a" in the input, and there will be an "a" in the input iff pac-man is in the input

I clicked the Pyth link and it didn't work when I entered "Pac-Man". When "Pac-Man" is entered, it should show all names, not none of them.

@JacquesMarais My mistake. Fixed.

}\az also tests if z contains the letter a. 1 byte shorter.

Ruby, 55 49 bytes
Try it online!
-6 bytes from @MartinEnder
->a{%w"Blinky Inky Pinky Clyde"-(a*''=~/-/?[]:a)}

Ruby arrays can undergo set subtraction, making it very easy to remove the appropriate ghosts.

How does this deal with Pac-Man?

@Neil it joins the array together using a*'' and regex-compares it to the - present in the name Pac-Man. If it's present, it subtracts nothing from the list of ghosts, and if it isn't, it subtracts the input list (so each element in the input list is removed from the list of ghosts)

Perl, 51 bytes
50 bytes code + 1 for -n
for$@(Blinky,Inky,Pinky,Clyde){print$@if/-/|!/$@/}g}

Usage
perl -ne 'for$@(Blinky,Inky,Pinky,Clyde){print$@if/-/|!/$@/}' <<< 'Pac-Man, Clyde'
BlinkyInkyPinkyClyde

I can amend the output if necessary, adding a space after each ghost, for + 3 bytes replacing print$@ with print"$@ ".
-6 bytes thanks to @MartinEnder!

Perl, 53 bytes
51 bytes code + 2 for -na
An alternative solution, using the smartmatch operator:
print grep/-/~~@F|!($_~~@F),Blinky,Inky,Pinky,Clyde

Usage
Requires a space separated list of input:
perl -nae 'print grep/-/~~@F|!($_~~@F),Blinky,Inky,Pinky,Clyde' <<< 'Clyde Pinky Inky'
Blinky
perl -nae 'print grep/-/~~@F|!($_~~@F),Blinky,Inky,Pinky,Clyde' <<< 'Clyde Pinky Inky Pac-Man'
BlinkyInkyPinkyClyde'

Python 2, 151 bytes
As there are already Python answers using sets and strings I decided to restrict myself to work with lists, which turned out to be pretty long and uncompetitive. However, as the approach taken is different as the common one used, here it is:
o=['Blinky','Clyde','Inky','Pinky']
p=lambda x:[l for l in reduce(lambda z,x:z+[y+[x]for y in z],o,[[]])if sorted(l+x)==o][0]if'Pac-Man'not in x else o

where the expected input is a list of strings.
The approach is to bruteforce all possible combinations (without taking order into account) of 0,1,2,3 and 4 elements. This is done by
reduce(lambda z,x:z+[y+[x]for y in z],o,[[]])

which returns
[[], ['Clyde'], ['Pinky'], ['Clyde', 'Pinky'], ['Inky'], ['Clyde', 'Inky'],
['Pinky', 'Inky'], ['Clyde', 'Pinky', 'Inky'], ['Blinky'], ['Clyde', 'Blinky'],
['Pinky', 'Blinky'], ['Clyde', 'Pinky', 'Blinky'], ['Inky', 'Blinky'],
['Clyde', 'Inky', 'Blinky'], ['Pinky', 'Inky', 'Blinky'],
['Clyde', 'Pinky', 'Inky', 'Blinky']]

and find the one which, in addition to the input list results in the complete list of ghosts.
Then it is checked if the string 'Pac-Man' is part of the input and, in case it is, the whole list of ghosts is returned. If not, only the ones which are not part of the input are returned.
Notice that the list containing all ghost names (o) is sorted alphabetically and the same goes for the list built as (sorted(l+x)). This is due to the fact that in Python, ['a','b']==['b','a'] is evaluated as False whereas ['a','b']==['a','b'] is evaluated as True.
3 bytes can be saved if it is permitted to return the answer as a list of lists ( by removing the [0] at the end of the first list comprehension). But as I'm not sure it is a valid output I am counting them.

Python 2, 66 61 96 bytes
g={"Blinky","Inky","Pinky","Clyde"};i=set(input());print",".join(g-i if not"Pac-Man"in i else g)

Input must be a list, output will be a string of names separated by a ,.
61 bytes version that doesn't handle Pac-Man:
print",".join({"Blinky","Inky","Pinky","Clyde"}-set(input()))

Pac-Man is not handled in this entry.

You don't need set[...]. Just use a {...} set literal.

I really didn't notice the Pac-Man thing even after reading the challenge 3 times... I'll fix my code.

Haskell, 91 bytes
import Data.List
p l=(if elem"Pac-Man"l then id else(\\l))["Blinky","Inky","Pinky","Clyde"]

Input is a list of strings. It decides whether to use the list as-is or do a list-difference based on the presence of "Pac-Man".
For extra fun, here is no Pac-Man:
import Data.List
(["Blinky","Inky","Pinky","Clyde"]\\)

Will be improving this answer soon, did it super late at night.

05AB1E, 47 44 bytes
•1g!Z~÷kÅ]°%Ï0›K/•35B0¡™svy'-åi,q}}v¹ykÌiy)˜

Explaination
•1g!Z~÷kÅ]°%Ï0›K/•35B0¡™                      # push list of the 4 ghosts
                        svy'-åi,q}}           # if Pac-Man is in input, quit and output list of all 4 ghosts
                                  v¹ykÌiy)˜   # otherwise, generate the list of ghosts missing from input

Try it online

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

Python 3, 77 bytes
lambda i:[g for g in"Blinky Inky Pinky Clyde".split()if g not in i or"-"in i]

Here is another answer at 89 bytes that I was playing with but didn't work out :(
lambda i:[g for g in[s+"nky"for s in"Bli I Pi".split()]+["Clyde"]if g not in i or"-"in i]

And here's the original at 85 bytes:
lambda i,n="Blinky Inky Pinky Clyde":([g for g in n.split()if g not in i],n)["-"in i]

These all take a single string of the names separated by spaces/commas.

Pascal (FPC), 204 200 bytes
Two loops, using a binary to find which ghosts+pacman are present. Takes the arguments from the commandline.
Thanks to @manatwork for saving some more bytes!
var a:array[1..4]of string=('Blinky','Inky','Pinky','Clyde');i,s:Byte;begin for i:=1to ParamCount do s:=1<<Pos(ParamStr(i)[4],'nykd-')or s;for i:=1to 4do if(1<<i and s=0)or(s>31)then WriteLn(a[i])end.

Try it online!
Ungolfed:
var
  a: array[1..4] of string = ('Blinky', 'Inky', 'Pinky', 'Clyde');
  i, s: byte;
begin
  for i:=1 to ParamCount do
    s := 1 << pos(ParamStr(i)[4], 'nykd-') or s; // fill bits by shifting, check for unique 4th char of names, '-' in 'pac-man', could also use the 3rd char
  for i:=1 to 4 do
    if (1 << i and s=0) or (s>31) then    // check if bits are on
      writeln(a[i]);
end.

Old version using a set, 227 209 bytes
Two loops, using a set to find which ghosts+pacman are present. Takes the arguments from the commandline.
var a:array[1..4]of string=('Blinky','Inky','Pinky','Clyde');i:byte;s:set of 1..5;begin for i:=1to ParamCount do s:=s+[pos(ParamStr(i)[4],'nykd-')];for i:=1to 4do if not(i in s)or(5in s)then writeln(a[i]);end.

Ungolfed:
var
  a: array[1..4] of string = ('Blinky', 'Inky', 'Pinky', 'Clyde');
  i: byte;
  s: set of 1..5;
begin
  for i:=1 to ParamCount do
    s := s + [pos(ParamStr(i)[4], 'nykd-')]; // fill set with indxs
  for i:=1 to 4 do
    if not(i in s) or (5 in s) then    // check indx not in set or pac-man is
      writeln(a[i]);
end.

Nice. Some ways to shortening it: integer → byte; remove declaration of g and use its value directly, ParamCount → 5 (as I understand the task, there will be no duplicated or invalid input items anyway). At least in FreePascal numeric literals may touch keywords, like i:=1to 5do or 5in s. See whether your supports it too.

I think using bits instead of set would be beneficial: http://pastebin.com/r2nB5wY3

@manatwork Wow, everytime I learn something new.. I am using your suggestions except for ParamCount, because the behavior is undefined for numbers bigger then actual input params (at least there is nothing about it in the docs), even though it works.

Lotus Notes @Formula language, 85 84 75 74 characters
-1 character by reversing the @If assignment
-9 Changed @Contains(i;"-") to @Like(i;"%-%") and removed @Trim (not needed if displayed using space as seperator)
-1 by removing the newline
Create a form with two fields: i (Text,Editable,Multi-value) and o (Text,Computed,Multi-value). Enter the following formula in o:
l:="Inky":"Pinky":"Blinky":"Clyde";@If(@Like(i;"%-%");l;@Replace(l;i;""))

From Notes client, create a new document using the form, enter the name(s) in the i field and press F9 to refresh the document. Answer displayed in field o.
This takes advantage of the fact that @Like and @Replace can can both be used either on a string or on a list of strings.

Batch, 141 bytes
@set g= Blinky Inky Pinky Clyde
@for %%a in (%*)do @if %%a==Pac-Man goto l
@for %%a in (%*)do call set g=%%g: %%a=%%
@l
@echo(%g:~1,-1%

(Subtract 6 bytes for :~1,-1 if leading and trailing whitespace is acceptable.) Requires Pac-Man in title case but the ghosts are case insensitive.

PHP program, 84 bytes
<?print_r(array_diff([Blinky,Inky,Pinky,Clyde],in_array('Pac-Man',$argv)?[]:$argv));

takes arguments from command line, prints result as an array.
filename must not be any of the ghosts or 'Pac-Man'!
short breakdown: remove (if 'Pac-Man' is in arguments: nothing, else all arguments) from all ghosts; print result recursively

examples:
>php -d error_reporting=0 ghosts.php Clyde
Array
(
    [0] => Blinky
    [1] => Inky
    [2] => Pinky
)
>php -d error_reporting=0 ghosts.php Clyde Blinky
Array
(
    [0] => Inky
    [1] => Pinky
)
>php -d error_reporting=0 ghosts.php Pac-Man Clyde
Array
(
    [0] => Blinky
    [1] => Inky
    [2] => Pinky
    [3] => Clyde
)

PHP function, 90 bytes
function p($a){return array_diff([Blinky,Inky,Pinky,Clyde],in_array('Pac-Man',$a)?[]:$a);}

takes and returns an array, use empty array for empty input, no other falsy value!
further thoughts

replace in_array(...) with strstr(join($argv),'-') to detect - instead of Pac-Man (-2)
use ereg('-',join($argv)) instead (another -2)
program could lose another 6 bytes in PHP<5.4 with register_globals on
to make the program print a comma-separated list: replace <?print_r( with <?=join(',', (+2). You may want to add ;echo"" to the call for a line break

Pyke, 45 39 38 37 32 bytes
.d膎㧫l4dc].^D`\-R{!*

Try it here!
.d膎㧫l4dc - dictionary_lookup('blinky inky pinky clyde').title().split()
].^ - xor(^, input)
D`\-R{!* - ^*("-" not in input)

jq, 69 characters
("Blinky Inky Pinky Clyde"/" ")as $a|if inside($a)then$a-. else$a end

Input is JSON, output is JSON, conditional syntax is pain.
Sample run:
bash-4.3$ jq '("Blinky Inky Pinky Clyde"/" ")as $a|if inside($a)then$a-. else$a end' <<< '["Clyde"]'
[
  "Blinky",
  "Inky",
  "Pinky"
]

bash-4.3$ jq '("Blinky Inky Pinky Clyde"/" ")as $a|if inside($a)then$a-. else$a end' <<< '["Pac-Man","Clyde"]'
[
  "Blinky",
  "Inky",
  "Pinky",
  "Clyde"
]

On-line test:

["Clyde"]
["Pac-Man","Clyde"]

Looks like jq has gotten more tolerant since this answer was posted in 2016...  This simplier version works now.
("Blinky Inky Pinky Clyde"/" ")as $a|$a-.

@cnamejj, I'm afraid you missed a part of the requirement: “However, if Pac-Man is in the input, all ghosts will be considered missing (because he eats them).” Unfortunately I don't see how could that be handled without the lengthy if.

ah, my bad...  I did miss that.

C# 135 bytes126 bytes
string[] g{"Blinky","Inky","Pinky","Clyde"};Console.WriteLine(String.Join(",",i.Contains("Pac-Man")?g:g.Except(i).ToArray()));

(where i is a string array containing the input)
After looking at the other examples, I see that C# is rather a verbose language :)

You can get 126 bytes by removing the spaces and the newline.

TSQL(sqlserver 2016), 114 bytes
Golfed:
DECLARE @ VARCHAR(99) = 'Blinky,Inky,Pinky,Clyde'

SELECT*FROM STRING_SPLIT('Blinky,Inky,Pinky,Clyde',',')EXCEPT SELECT*FROM STRING_SPLIT(@,','WHERE @ NOT LIKE'%-%'

Ungolfed:
DECLARE @ VARCHAR(99) = 'Blinky,Inky,Pinky,Clyde'

SELECT * FROM STRING_SPLIT('Blinky,Inky,Pinky,Clyde',',')
EXCEPT
SELECT * FROM STRING_SPLIT(@,',')
WHERE @ NOT LIKE'%-%'

Fiddle

Japt, 38 bytes (Non-competing)
Takes input as an array of strings, outputs an array of strings
`B¦nky Inky Pky CÒè`¸kUø`Pac-M` ?N:U

Try it online

05AB1E, 27 bytes
…ê¥¦¨™Å#'y«.•S:-•ª™IDJ{нaиK

Try it online or verify all test cases.
Explanation:
…ê¥¦¨™Å           # Push dictionary string "blink ink pink"
                  #  STACK: "blink ink pink"
       #          # Split it on spaces
                  #  STACK: ["blink","ink","pink"]
        'y       '# Push "y"
                  #  STACK: ["blink","ink","pink"],"y"
          «       # Append it to each string in the list
                  #  STACK: ["blinky","inky","pinky"]
           .•S:-• # Push compressed string "clyde"
                  #  STACK: ["blinky","inky","pinky"],"clyde"
             ª    # Append it to the list
                  #  STACK: ["blinky","inky","pinky","clyde"]
              ™   # Titlecase each string
                  #  STACK: ["Blinky","Inky","Pinky","Clyde"]
I                 # Push the input-list
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"]
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"]
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[]
 D                # Duplicate it
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"],["Pac-Man"]
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"],["Pinky"]
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[],[]
  J               # Join the copy to a single string
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"],"Pac-Man"
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"],"Pinky"
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[],""
   {              # Sort its characters
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"],"-MPaacn"
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"],"Pikny"
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[],""
    н             # Pop and leave just its first character
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"],"-"
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"],"P"
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[],""
     a            # Check if this is a letter
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],["Pac-Man"],0
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"],1
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[],0
      и           # Repeat the input-list that many times
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"],[]
                  #  STACK2: ["Blinky","Inky","Pinky","Clyde"],["Pinky"]
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"],[]
       K          # Remove those strings from the earlier quartet-list
                  #  STACK1: ["Blinky","Inky","Pinky","Clyde"]
                  #  STACK2: ["Blinky","Inky","Clyde"]
                  #  STACK3: ["Blinky","Inky","Pinky","Clyde"]
                  # (after which the resulting list is output implicitly)

See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why …ê¥¦¨™Å is "blink ink pink" and .•S:-• is "clyde".


text:
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.
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.

[tag:kolmogorov-complexity] would be a good tag for this

Are the uppercase B and C in Polar Bear and Boa Constrictor necessary? (In Batch this costs me 10% of my byte count...)

Is submitting a hash and bruteforcing the solution with a restricted set allowed? :D

This is a very nice first challenge!

Does the null terminator matter?

@AgentCrazyPython I don't think null terminators get output. Do you mean doing it in brainfuck or something, where they do get output?

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ or newlines

I'd +1 but you're at 42 upvotes, and who am I to disturb the ways of the galaxy?

@tfbninja, you may now upvote!

@Shaggy duly noted and upvoted!

05AB1E, 349 331 330 322 314 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—«.“?

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."

This one is summoning Cthulhu.

I can't see where the code ends and the packed data begins.

@Adám I know. It looks a lot like gibberish :) I'll add an explanation eventually which will hopefully make it clearer. I might want to try and golf it some more first though.

This is probably how laymen imagine code.

I have no idea what I just read...

Now do it again using the dictionary LOL.

It's not working anymore with the changed compression size from 214 to 255 somewhere at the start of 2017, but +1 regardless for the effort and explanation. :)

PHP, 420 414 434 414 412 bytes
call from CLI or prepend <pre> to output.
$v=[growl,roar,snort,flut,bray,hiss,trumpet,snarl,yelp,bellow,whistl];$a[6]=n;foreach($n=['polar bear',lion,hippopotamus,flamingo,zebra,'boa constrictor',elephant,leopard,peacock,walrus,zookeeper]as$i=>$p)echo$i?"I hear a$a[$i] $p $v[$i]ing in my ear.

":"",$q=ucwords($p),", $q, what do you hear?
",$i>9?"I hear children...

...":""&$z[]="$v[$i]ing like a$a[$i] $p";echo join(",
",$z),"...
that's what I hear.";

a couple of notices for undefined constants; PHP´s implicit cast to literal string kicks in again
adding the "n" for "an elephant" took 20 bytes ... hmpf.
got the 20 bytes back by reordering stuff :)

breakdown
$n=['polar bear',lion,hippopotamus,flamingo,zebra,'boa constrictor',elephant,leopard,peacock,walrus,zookeeper];
$v=[growl,roar,snort,flut,bray,hiss,trumpet,snarl,yelp,bellow,whistl];
$a[6]=n;
// loop through nouns with index $i
foreach($n as$i=>$p) echo
    // print first part:
        // not first noun: print second line to previous step
        $i?"I hear a$a[$i] $p $v[$i]ing in my ear.\n\n":"",
        // uppercase the first letter of each word in the noun, print
        $q=ucwords($p),
        // print uppercase noun again and the rest of the line
        ", $q, what do you hear?\n",
        // for last noun print bridge, else print nothing
        $i>9?"I hear children...\n\n...":""
    // ... AND add line to second part
        &$z[]="$v[$i]ing like a$a[$i] $p"
;
// print second part and final line
echo join(",\n",$z),"...\nthat's what I hear.";

JavaScript, 545 541 497 bytes
a="Polar Bear|Lion|Hippopotamus|Flamingo|Zebra|Boa Constrictor|Elephant|Leopard|Peacock|Walrus|Zookeeper".split`|`;s=btoa`º0:èj¼ìíÍùn·6ëk,áË3¶»¦¥ës²v«<ÛzYhÃ<!Ëe`.split`z`;a.map((m,n)=>{console.log(m+", "+m+", what do you hear?\n "+((n>9)?"I hear children...\n":"I hear a"+(n==5?"n ":" ")+a[n+1].toLowerCase()+" "+s[n+1]+"ing in my ear.\n"))});p="...";a.map((m,n)=>{if(n>9)return;p+=s[n]+"ing like a"+(n==6?"n ":" ")+m.toLowerCase()+(n>8?"...\nthat's what I hear.":",\n")});console.log(p)

Quite a fun challenge!
Thanks Downgoat for saving me 27 a ton of bytes using atob, and Titus for 4 bytes!
Ungolfed:
a="Polar Bear|Lion|Hippopotamus|Flamingo|Zebra|Boa Constrictor|Elephant|Leopard|Peacock|Walrus|Zookeeper".split`|`;
s=btoa`º0:èj¼ìíÍùn·6ëk,áË3¶»¦¥ës²v«<ÛzYhÃ<!Ëe`.split`z`;
a.map((m,n)=>{
  console.log(m+", "+m+", what do you hear?\n "+((n==10)?"I hear children...\n":"I hear a" + (n==5?"n ":" ") + a[n+1].toLowerCase() + " " + s[n+1] + "ing in my ear.\n"))
});
p="...";a.map((m,n)=>{
  if(n==10) return;
  p+=s[n] + "ing like a" + (n==6?"n ":" ") + m.toLowerCase() + (n==9?"...\nthat's what I hear.":",\n")
});
console.log(p);

a.map((n,m)=>n>9||(p+=s[n]...))

Why don't you have to declare the variables with var?

@OldBunny2800 For the purposes of golfing, you're allowed to set global variables. (Don't do this in a recursive function though!)

Your code doesn't work, I assume stack exchanged some letters in your base64 code. After the split I get ["ujA66Gq87O3N+W63NutrLOHLM7a7pqXrc7J2q", "", "bellow", "why2U="].

Define c=console.log; at the beginning then use c() to save 6 bytes. Or just save the string in a variable and print it once with alert().

You can also use template strings to reduce concatenation and escaped newlines.

it may save you a bit of bytes (and duplication of logic) if you start with n=1 instead of 0.

... and i wonder if encoding the determiner ("a", "an", nil for Children) in the hashes saves bytes.

@lolesque The c=console.log doesn't work because log must have a this of console or it produces an error. (Unless it doesn't in some browsers/environments?) The idea to put it all in a string sounds good, though

I think you could reduce it further by removing the double "I hear ", i.e. changing: ", what do you hear?\n "+((n>9)?"I hear children...\n":"I hear a" into ", what do you hear?\n I hear "+((n>9)?"children...\n":"a"

///, 523 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:.

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

Dyalog APL, 387 bytes
⎕UCS¯2(219⌶)¯128+⎕UCS'øZýÓÁî°üÁ~`Û¯ß(4Õ+ÖjáïvXô ¶Dhkë ©4¹³`LxÖ4¢gÍ¼4ªBáDÚN¼ùV ÂÅF]@¸hÆà bKÚ¸_oQãÔÝ ¸$8§ú_ÔÈxÖ ~6*ãªd ¿ð>¥ÐB8þôÍxwÄ6Å
ô¡é¢wBlDµ¯ë
Ãbqè+ý+ÜÈýgu!gWËØ#0="«ë"HDÝÀV·¦/ÕMÆí}h<àì7å ÝÒëëñX³ýM <dÄ<ëmµñqP]¥c¬l¾¤ìÚã/$ÝÕqÙÞîCLéMÝÏ}OÔÏ¤r$¤è©~ì2[¢{·YWÒä¿¦à¶)YØ©;s÷¬¥+ó&¿ÉâgËr
,Ýî©)¥Ö2è´ÝÅd{úK5·Õ}ýÚ'

To ease reading: ⎕UCS¯2(219⌶)¯128+⎕UCS'...'
⎕UCS '...' convert string to Unicode code points
¯128+ subtract 128 to get -128 ≤ n ≤ 127
¯2(219⌶) un-zlib
⎕UCS convert Unicode code points to string
The source string is the following 365 bytes of zlib'ed Unicode code points:
F8 5A FD D3 C1 EE 04 B0 8C FC C1 7E 60 DB AF 91 DF 28 34 D5 2B D6 6A E1 EF 15 76 96 58 F4 09 B6 44 11 93 04 68 6B EB A0 A9 94 34 B9 10 98 0F B3 60 4C 78 0C D6 91 1C 34 A2 89 67 CD BC 34 AA 42 95 E1 44 9E DA 4E BC 0B 0F F9 87 85 56 20 83 C2 C5 46 5D 40 B8 68 C6 E0 20 92 62 13 81 89 4B DA B8 5F 9A 6F 51 E3 D4 DD 9F A0 B8 24 38 A7 FA 5F D4 C8 78 7F D6 A0 7E 36 2A E3 AA 64 20 BF F0 3E A5 D0 42 9A 95 38 FE F4 CD 8A 78 99 77 C4 17 89 11 10 36 82 C5 0D 8A 9A F4 A1 12 E9 A2 92 77 9D 42 1E 6C 44 B5 AF EB 0D 04 C3 62 71 87 9C E8 2B FD 2B DC 04 C8 FD 67 75 21 67 57 04 CB D8 23 12 30 9A 3D 22 AB EB 22 48 9E 44 DD C0 56 B7 87 85 A6 2F D5 03 4D 9D C6 ED 7D 1E 68 3C E0 EC 37 9C 94 08 86 E5 09 DD D2 EB EB F1 58 B3 FD 4D 20 04 3C 17 64 C4 3C EB 6D B5 F1 11 89 71 50 5D A5 63 AC 6C 9A BE A4 EC DA E3 2F 24 DD D5 71 D9 DE EE 04 43 4C E9 4D DD CF 7D 4F 13 D4 CF 13 A4 72 24 A4 E8 1A 9E A9 7E EC 1F 32 5B 19 10 A2 7B B7 01 59 57 D2 E4 BF A6 E0 B6 29 94 59 D8 A9 3B 73 1D 94 9B F7 AC A5 2B F3 26 BF C9 E2 67 7F CB 72 0A 2C DD EE A9 29 A5 D6 AD 92 32 E8 B4 DD C5 64 7B FA 8A 4B 35 AD B7 D5 7D 82 0F FD 1 DA

Python 3, 497 484 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.")

You could use the unpacking syntax to save some bytes:
change a=A[i] to a,b=A[i] and then you can write a and b instead of a[0] and a[1].
This will save 12 bytes.

Changing N=lambda m:("a","an")["E"==m[0]]+" "+m.lower() to N=lambda m:"an"[:("E"==m[0])+1]
and
n=a[0]+", ";P(n+n+"what do you hear?") to a+=", ";P(a+a+"what do you hear?") will save 2 more bytes.

General golfing question. Where you have len(A), since the purpose of this challenge is simply to generate the static output (not deal with dynamic input), is it acceptable to use a hard-coded 11 instead to save bytes?

@TaylorLopez sure, it's bad practice in general, but for golfing where the goal is to minimize code, I see no reason why not.

Pyth - 427 384 Bytes

=G"1, 1, what do you hear?\nI hear a 2 in my ear.\n"=Hc"growling/Polar Bear/roaring/Lion/snorting/Hippopotamus/fluting/Flamingo/braying/Zebra/hissing/Boa Constrictor/trumpeting/Elephant/snarling/Leopard/yelping/Peacock/bellowing/Walrus/whistling/Zookeeper"\/FNT
::G\1@H+yN1\2++r@H+yN3Zd@H+yN2)p+::G"I(.|\n)*"k\1@H20"I hear children...\n\n..."FN9
::"1 like a 2,"\1@HyN\2r@H+yN1Z)p"bellowing like a walrus...\nthat's what I hear.

J"%s, %s, what do you hear?"K"I hear a%sing in my ear.\n"=Hc"Polar Bear/roar/Lion/snort/Hippopotamus/flut/Flamingo/bray/Zebra/hiss/Boa Constrictor/trumpet/Elephant/snarl/Leopard/yelp/Peacock/bellow/Walrus/whistl/Zookeeper/growl"\/FN11
%J*2[@HyN)?qNT"I hear children...\n"%Kjd[?qN5\nkr@H+yN2Z@HhyN))p"..."FN9
+%=J"%sing like a%s"[@HtyN+?qN5\nk+dr@HyNZ)?qN8"..."\,)
"that's what I hear"

Try it here - permalink

Can you golf away the ings? I go crazy seeing PHP beat Pyth.

The code outputs a elephant.

All the problems (including the fact that PHP beat Pyth) are fixed!

Python 2 - 454 bytes
a="polar bear,lion,hippopotamus,flamingo,zebra,boa constrictor,elephant,leopard,peacock,walrus,zookeeper,whistl,bellow,yelp,snarl,trumpet,hiss,bray,flut,snort,roar,growl".split(',')
e='...\n\n'
r=range
print'\n'.join([(a[i].title()+', ')*2+"what do you hear?\nI hear "+((i<10)*("a%s %sing in my ear.\n"%("n "[i!=5:]+a[i+1],a[~-~i]))or"children%s..."%e+",\n".join(a[~j]+"ing like a"+"n "[j!=6:]+a[j]for j in r(10))+e+"that's what I hear.")for i in r(11)])

R 518 509 482 477 474 465 452 456 bytes
Link to R-Fiddle to try code
a=c("Polar Bear","Lion","Hippopotamus","Flamingo","Zebra","Boa Constrictor","Elephant","Leopard","Peacock","Walrus","Zookeeper")
b=c("...growl","roar","snort","flut","bray","hiss","trumpet","snarl","yelp","bellow","whistl")
d=c(rep("a ",6),"an ")
f=tolower(a)
cat(c(paste0(a,", ",a,", what do you hear?\nI hear ",c(paste0(d,f," ",b,"ing in my ear.")[-1],"children..."),"\n\n"),paste0(b,"ing like ",d,f,c(rep(",\n",9),"...\nthat's what I hear."))[-11]))

Moved children out of the vector a, and got rid of corresponding entry in the d vector to save 8 bytes
More tidying up and removing of subscripts made redundant by moving children, saved further 27 bytes.
Globalised the tolower function, saved 5 bytes
Replace writeLines with cat and reformatted appropriately (added \n in places) saved 3 bytes
Realised that if d is only 7 elements not the full 11, R will just loop back to the start again. As 11 < 14 then this works for us. Saved 9 bytes.
globalised subscripts, saved 13 bytes.
cat function was separating with " ", changed back to writeLines. Added 4 bytes (cat can be fixed by adding    ,sep="" to the function)

Welcome to PPCG! This is a nice first answer. Is there a way to try your code online?

Try this http://www.r-fiddle.org/#/fiddle?id=5pqkHPyL&version=1
although I had to add a character (backslash) to get it to read the apostrophe in "that's" correctly

Thank you. In R-Fiddle, I saw that you have a ' ' before each item of a after "Polar Bear". Is it normal?

I'm not entirely sure what you mean. Do you mean the space in the first section of the poem? As in the space before "Lion" here?
"Polar Bear, Polar Bear......\nI hear a ......\n Lion, Lion.....\nI hear a... "
I hadn't noticed this before. It comes from the cat function separating using a space. This can be fixed by adding sep="" to the function, however then using writeLines becomes preferable. (I've change the code back to writeLines)

C#, 575 525 520 526 507 504 497 494 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!

Batch, 650 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#, 592 572 Bytes
using System;class p{static void Main(){string[] s={"","","Polar Bear","Lion","Hippopotamus","Flamingo","Zebra","Boa Contrictor","Elephant","Leopard","Peacock","Walrus","Zookeeper","growl","roar","snort","flut","bray","hiss","trumpet","snarl","yelp","bellow","whistl"};for(int i=2;i<13;i++){s[0]+=(s[i]+", "+s[i]+", what do you hear?\nI hear "+(i<12?"a"+(i==7?"n ":" ")+s[i+1].ToLower()+" "+s[i+12]+"ing in my ear.\n\n":"children...\n\n..."));if(i<12)s[1]+=s[i+11]+"ing like a"+(i==8?"n ":" ")+s[i].ToLower()+(i<11?",\n":"...\nthat's what I hear.\n");}Console.Write(s[0]+s[1]);}}

Had such a great time taking this challenge with my colleague! Thanks for the idea.
Formatted:
using System;
class p {
    static void Main() {
        string[] s = { "", "", "Polar Bear", "Lion", "Hippopotamus", "Flamingo", "Zebra", "Boa Contrictor", "Elephant", "Leopard", "Peacock", "Walrus", "Zookeeper", "growl", "roar", "snort", "flut", "bray", "hiss", "trumpet", "snarl", "yelp", "bellow", "whistl" };
        for (int i = 2; i < 13; i++) {
            s[0] += (s[i] + ", " + s[i] + ", what do you hear?\nI hear " + (i < 12 ? "a" + (i == 7 ? "n " : " ") + s[i + 1].ToLower() + " " + s[i + 12] + "ing in my ear.\n\n" : "children...\n\n..."));
            if (i < 12) s[1] += s[i + 11] + "ing like a" + (i == 8 ? "n " : " ") + s[i].ToLower() + (i < 11 ? ",\n" : "...\nthat's what I hear.\n");
        }
        Console.Write(s[0] + s[1]);
        Console.ReadKey();
    }
}

EDIT: Thank you for your numerous and awesome tips, they helped a lot and I'll try to get the other ones working as well.

Remove all of the unnecessary whitespace, you can use new[] instead o. new string[] Also you can make this into an anonymous function like in @aloisdg's answer

Welcome to PPCG! Good idea in this answer! You may find some inspiration to improve it in the tips for code golfing in C# page. Keep going!

You fell in the a elephant trap (I did too). It is an elephant ;)

Take out your "ing"s in the verb array and move it to the output for some more savings.

F#, 591 589 579 576 573 567 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)

Welcome to PPCG, nice answer!

I know #F is a .net languange, but I think for the purpose of this challenge you can replace the "\r\n" with a simple "\n", as the concept is the same and it saves bytes

@Vale thanks. saved 10 bytes

Doesn't affect the count, but you've spelled "Hippopotamus" wrong.

@GentlePurpleRain Heh. I thought I looked for all the spellings. I will fix it.

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.

Can you post the actual code? 402 bytes isn't that much (i.e. you can post it.)

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ The code is only tail -n+2 \$0|zcat;exit followed by a newline and a binary string of 379 bytes (the gzipped version of the text proposed).  Did you know the reason for  the downvote? (it's a semi standard procedure for bash self installing scripts with an archive inside, IMHO not so different from the use of a library in c++).

It seems you use coreutils (zcat), so your header must be (Bash + coreutils, 402 bytes) instead of (Bash (with zcat) 402). And, can you edit your answer (just append <!> at the end of your post)? I want to remove the downvote >:(

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ zcat is not from coreutils, it comes with gzip. In many system is a script with that calls gzip -cd "$@"... BTW I modified in Bash + zcat, 402 bytes.

Good, downvote removed. The upvote is mine.

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Thx I went one of your question with a similarly lazy answer...

It's called "Count up folks!" (discussion ends)

Python 3, 442 441 bytes
h=t=''
for n,s in zip('polar bear,lion,hippopotamus,flamingo,zebra,boa constrictor,elephant,leopard,peacock,walrus,zookeeper'.split(','),'...growl roar snort flut bray hiss trumpet snarl yelp bellow whistl'.split()):u='n'[:'el'in n],n,s,n.title();h+="I hear a{0} {1} {2}ing in my ear.\n\n{3}, {3} what do you hear?\n".format(*u);t+="{2}ing like a{0} {1},\n".format(*u)
print((h+'I hear children...\n\n'+t)[44:-30]+"...\nthat's what I hear.")

ungolfed:
animals = 'polar bear,lion,hippopotamus,flamingo,zebra,boa constrictor,elephant,leopard,peacock,walrus,zookeeper'.split(',')

sounds = '...growl roar snort flut bray hiss trumpet snarl yelp bellow whistl'.split()

h=t=''
for n,s in zip(animals,sounds):
    u='n'[:'el'in n], n, s, n.title()

    h+="I hear a{0} {1} {2}ing in my ear.\n\n{3}, {3} what do you hear?\n".format(*u)

    t+="{2}ing like a{0} {1},\n".format(*u)

print((h+'I hear children...\n\n'+t)[44:-30]+"...\nthat's what I hear.")

Basically, just a loop that builds up two strings representing the two parts of the story.  The 'n'[:'el'in n] handles the "an" for elephant.  The [44:-30] chops off the leading "I hear a polar bear growling in my ear" and the trailing "whistling like a zookeeper".

Emacs Lisp, 576 (621) bytes
(let*((a'("polar bear""lion""hippopotamus""flamingo""zebra""boa constrictor""elephant""leopard""peacock""walrus""zookeeper"))(l(length a))(m(- l 1))(s'("growl""roar""snort""flut""bray""hiss""trumpet""snarl""yelp""bellow""whistl")))(dotimes(i l)(message"%s, what do you hear?"(let((a(capitalize(nth i a))))(concat a", "a)))(if(not(eq i m))(message "I hear a %s %sing in my ear.\n"(nth(1+ i)a)(nth(1+ i)s))(message"I hear children...\n")(dotimes(j m)(message(concat(when(eq j 0)"...")"%sing like a %s"(if(eq(1+ j)m)"..."","))(nth j s)(nth j a)))(message"That's what I hear."))))

When fixing "an elephant", it takes slightly longer:
(let*((a'("polar bear""lion""hippopotamus""flamingo""zebra""boa constrictor""elephant""leopard""peacock""walrus""zookeeper"))(l(length a))(m(- l 1))(s'("growl""roar""snort""flut""bray""hiss""trumpet""snarl""yelp""bellow""whistl")))(dotimes(i l)(message"%s, what do you hear?"(let((a(capitalize(nth i a))))(concat a", "a)))(if(not(eq i m))(message "I hear a %s %sing in my ear.\n"(nth(1+ i)a)(nth(1+ i)s))(message"I hear children...\n")(dotimes(j m)(message(concat(when(eq j 0)"...")"%sing like a"(and(string-match-p"^[aeiou]"(nth j a))"n")" %s"(if(eq(1+ j)m)"..."","))(nth j s)(nth j a)))(message"That's what I hear."))))

Ungolfed:
(let* ((animals '("polar bear"
                  "lion"
                  "hippopotamus"
                  "flamingo"
                  "zebra"
                  "boa constrictor"
                  "elephant"
                  "leopard"
                  "peacock"
                  "walrus"
                  "zookeeper"))
       (l (length animals))
       (m(- l 1))
       (sounds '("growl"
                 "roar"
                 "snort"
                 "flut"
                 "bray"
                 "hiss"
                 "trumpet"
                 "snarl"
                 "yelp"
                 "bellow"
                 "whistl")))
  (dotimes (i l)
    (message "%s, what do you hear?"
             (let ((animal (capitalize (nth i animals))))
               (concat animal ", " animal)))
    (if (not (eq i m))
        (message "I hear a %s %sing in my ear.\n"
                 (nth (1+ i) animals)
                 (nth (1+ i) sounds))
      (message "I hear children...\n")
      (dotimes (j m)
        (message
         (concat
          (when (eq j 0) "...")
          "%sing like a"
          (and (string-match-p"^[aeiou]" (nth j animals)) "n")
          " %s"
          (if (eq (1+ j) m) "..." ","))
         (nth j sounds )
         (nth j animals)))
      (message"That's what I hear."))))

Your regex could be shortened from ^[aeiou] to ^e, couldn't it?

For the elephant yes, but if other animals were added it would need to change. With 600 bytes already, 6 bytes don't hurt that much.

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.

Can you add a link to ideone?

Added ideone link.

a[99][99] -> **a (-6). You can't call f() without arguments here, you need an n. Replace f(n){ with f{n;. Another -1 here. Also, f() is now callable.

@owacoder How come? **a means an array of character arrays (or a character pointer pointer), and, to me, it has always worked (gcc 4.8). What compiler do you use? If you don't use gcc, you must specify it. If you use gcc, it's a default.

@owacoder No! It makes an array that fits 98 strings of length 98! And you should definitely not call your ideone link "Try it online!" To golf, replace a[99][99] with a[<how many elements do I modify?>+1][<what is the maximum length of any string in here?>+1].

@owacoder I think the 99 in a[99][99] means 99 elements, including the null (\0), so [0]-[97] are available. And I really don't believe that 99 is the number of elements you actually need.

LUA 535 bytes
p=print a="growl.roar.snort.flut.bray.hiss.trumpet.snarl.yelp.bellow.whist"b="polar bear.lion.hippopotamus.flamingo.zebra.boa constrictor.elephant.leopard.peacock.walrus.zookeeper."z=a.gmatch(a,"%P+")x=b.gmatch(b,"%P+")w=''for j=1,11 do i=x()v=z()e=j==7 and'n 'or' 'p(j==1 and''or'I hear a'..e..i..' '..v..'ing in my ear.\n')w=w..(j>10 and''or v..'ing like a'..e..i..(j>9 and'...'or',')..'\n')y=i:gsub("^%l",a.upper):gsub("%s%l",a.upper)p(y..', '..y..' what do you hear?')end p('I hear children...\n')p('...'..w.."that's what I hear.")

ungolfed:
sound_list = "growl.roar.snort.flut.bray.hiss.trumpet.snarl.yelp.bellow.whist"
animal_list = "polar bear.lion.hippopotamus.flamingo.zebra.boa constrictor.elephant.leopard.peacock.walrus.zookeeper."

sound_it = string.gmatch(sound_list, "%P+")
animal_it = string.gmatch(animal_list, "%P+")
part_2 = ''

for i = 1, 11  do
    animal = animal_it()
    sound = sound_it()
    aORan = i == 7 and 'n ' or ' '

    print(i == 1 and '' or 'I hear a'..aORan..animal..' '..sound..'ing in my ear.\n')

    part_2 = part_2..(i > 10 and '' or sound..'ling like a'..aORan..animal..(i > 9 and '...' or ',')..'\n')

    big_animal = animal:gsub("^%l", string.upper):gsub("%s%l", string.upper)
    print(big_animal..', '..big_animal..' what do you hear?')
end

print('I hear children...\n')
print('...'..part_2.."that's what I hear.")

Try it online

QB64 (QuickBASIC), 581 bytes
The code expands a bit when you throw it in the interpreter, but this source file is valid to load as-is.  If you want to see the whole output before it scrolls past, then you'll need to add a width 80,46 statement to the beginning.
READ a$,v$
FOR x=0 TO 10
?a$+", "+a$+", what do you hear?"
IF x>9THEN
?"I hear children...":?:?"...";
RESTORE
FOR y=0 TO 9
READ a$,v$
?v$+"ing like ";
CALL j(a$)
IF y<9THEN?", "ELSE?"...":?"that's what I hear."
NEXT
END
ELSE
READ a$,v$
?"I hear ";
CALL j(a$)
?" "+v$+"ing in my ear."
?
END IF
NEXT
DATA"Polar Bear","growl","Lion","roar","Hippopotamus","snort","Flamingo","flut","Zebra","bray","Boa Constrictor","hiss","Elephant","trumpet","Leopard","snarl","Peacock","yelp","Walrus","bellow","Zookeper","whistl"
SUB j (A$)
?"a";
IF LEFT$(A$,1)="E"THEN?"n";
?" "+LCASE$(A$);
END SUB

I know this is kinda late, but: I think you can save some bytes by using GOSUB/RETURN instead of CALL/SUB/END SUB. Also, you can drop the quotes in DATA for all the entries that don't have spaces in them. Finally, since there's only one animal that starts with a vowel, A$="Elephant" is actually 1 byte shorter than LEFT$(A$,1)="E". Nice use of RESTORE, BTW!

PHP, 366 bytes
Lazy answer, but why write a custom decompressor when gzip is available?
Hex dump of PHP code (can be saved with xxd -r)
0000000: 3c3f 3d67 7a69 6e66 6c61 7465 2827 7d53  <?=gzinflate('}S
0000010: c16a 8430 10bd e72b e6d6 cbe0 2f14 b6b4  .j.0...+..../...
0000020: b4d0 c3de 0abd 8d6e baca c64c 1823 62bf  .......n...L.#b.
0000030: be51 3354 1472 58f3 76de f864 e6bd 5cd9  .Q3T.rX.v..d..\.
0000040: 91c0 c592 20ec f1d4 5284 1bc3 cc23 b4a9  .... ...R....#..
0000050: f26c 3ed6 1308 5cc7 1e84 493a 7f87 ce43  .l>...\...I:...C
0000060: 3f43 222a 633e 1381 b03d 0bef b75d 081c  ?C"*c>...=...]..
0000070: 3852 3f0e 3078 9678 147a df75 20ec ff15  8R?.0x.x.z.u ...
0000080: 857f 1cf5 498a 1318 4f9a 6f99 4450 54d4  ....I...O.o.DPT.
0000090: fab5 b510 a4df 7c14 fa5e 1884 7c14 246a  ......|..^..|.$j
00000a0: 2668 d80f 51ba 26b2 a4b9 87e1 2876 6182  &h..Q.&.....(va.
00000b0: 97ff 1e84 63a1 f001 0fd6 d9d0 928f 1065  ....c..........e
00000c0: ec83 3dcd fc9a 7904 4565 632d 0792 5bf2  ..=...y.Eec-..[.
00000d0: 84c4 9dcc dd48 0405 25a5 60a9 e1e6 01b3  .....H..%.`.....
00000e0: 75e1 2874 dd38 0405 25a1 899c a494 d4d6  u.(t.8..%.......
00000f0: 399e 8e4a 5f2b 89a0 67c9 4ee6 87b5 c10a  9..J_+..g.N.....
0000100: 4cc9 86e8 4ea6 2a8f a0b0 b4fb a6ed dc4d  L...N.*........M
0000110: acaf aaf4 6e7a dc85 a755 d375 0fbb ccbf  ....nz...U.u....
0000120: dea4 3ab5 a211 2651 2adf 1e34 1a7b adb6  ..:...&Q*..4.{..
0000130: fb8c 1bcd 6f26 35d7 6896 3c2a a121 45a3  ....o&5.h.<*.!E.
0000140: c1ca d543 eed0 683a b465 971c 34d9 6ca5  ...C..h:.e..4.l.
0000150: 3404 68d4 3b1d 29bb 65b2 17ca a847 cb2a  4.h.;.).e....G.*
0000160: 624b f169 d8d6 b66d aa32 7f27 293b       bK.i...m.2.');

I used a few iterations of zopfli to convert the source text to 349 bytes of compressed data, avoiding the ' character which would otherwise have to be escaped with backslashes.

Japt, 308 303 299 295 288 280 294 289 286 bytes
Contains a bunch of unprintables; follow the link below to view them.
`Pol BÁLiyHippopotam«yFlaÚÁoyZeßBoa CÆqÎtyE¤pÊCyLeopÂýPea¬ckyWalr«yZookeep`qy
`gwÓ2ÂüÍdfl©dßdÊdtruÛFdsnÓ)lpdÞ)owdØtl`qd
[¡[X',SX`, Ø º y Ê#?
I Ê# `Y<A?[Y¶5?``:'aSUg°Y v SVgY `g  my e.`R]¬:[`å,Á`Q='.³R²QU¯J £[Vv `g ¦ke `Y¶6?``:'aSXv]¬Ãq`,
` QR`È  's Ø I Ê#.`]¬]¬Ã·]¬

Test it
+14 bytes 'cause I'd ballsed up the walrus' line; will need to take another pass over it next week to see if I can get any of those bytes back.

Perl 6, 400 399 bytes
((my \a=<<"Polar Bear"Lion Hippopotamus Flamingo Zebra"Boa Constrictor"Elephant Leopard Peacock Walrus Zookeeper>>)>>.&{"$_, $_, what do you hear?
I hear a {a[++$!].lc} {($/=<growl roar snort flut bray hiss trumpet snarl yelp bellow whistl>)[$!]}ing in my ear.
"},"...{a[^10]>>.&{$/[$++]~"ing like a",.lc}.join(",
")}...
that's what I hear.")>>.trans(["a e",/a\s\s.*r/]=>["an e","children.."])>>.say

Try it online!
Sub-400 bytes!

Powershell 921 889 886 898 Bytes
it's not perfect, but it saves 300 Bytes :)
EDIT:
Thanks Jonathan Frech, i saved 32 Bytes. And thank you Veskah for correcting the Output.
filter Z($1,$2){while($1){$x,$1=$1
$y,$2=$2
[tuple]::Create($x,$y)}}
$0="ing"
$$="hear"
$1="I $$ a "
$3='in my ear.'
$a='Polar Bear'
$b='Lion'
$c='Hippopotamus'
$d='Flamingo'
$e='Zebra'
$f='Boa Constrictor'
$g='Elephant'
$h='Leopard'
$i='Peacock'
$j='Walrus'
$k='Zookeeper'
$v="children"
$2="roar$0"
$4="snort$0"
$5="flut$0"
$6="bray$0"
$7="hiss$0"
$8="trumpet$0"
$9="snarl$0"
$x="yelp$0"
$y="bellow$0"
$^="whistl$0"
$l="$1$b $2$3"
$m="$1$c $4$3"
$n="$1$d $5$3"
$o="$1$e $6$3"
$p="$1$f $7$3"
$q="I $$ an $g $8$3"
$r="$1$h $9$3"
$s="$1$i $x$3"
$t="$1$j $y$3"
$u="$1$k $^$3"
$z=' like a '
$w="I $$ $v..."
z $a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k $l,$m,$n,$o,$p,$q,$r,$s,$t,$u,$w|%{"$($_.item1),"*2+"what do you $$?";$_.item2;""}
"...growl$0$z$a,"
z $b,$c,$d,$e,$f $2,$4,$5,$6,$7|%{$_.item2+$z+$_.item1+","}
"$8 like an $g,"
z $h,$i $9,$x,$y|%{$_.item2+$z+$_.item1+","}
$y+$z+"Walrus..."
"that's what I $$."

Would not using a standard 7 bit ASCII character instead of an ö be more byte efficient?

Furthermore, I think there is some superfluous whitespace in your first line, along with a long function name.

Thank you for the hints :)! (I used the Ö just because taught i used already all useable ASCII signs XD)

The character ö is only represented using a single byte in some codepages, UTF-8 requires two bytes for this character.

Your output is a bit off. The last stanza repeats polar-bear which makes everything off by one and you include whistling which isn't needed. It's also missing an ellipses. It also writes an elephant There's also an extra line break between the earlier stanzas that can be axed by removing the "n".

Oh yeah, animals on the I hear a $_ $_ing in my ear and in the last stanza aren't capitalized. Edit to the previous comment because I just noticed: I meant to write it uses a Elephant in the last stanza

876b with less bugs

First of all thank you for improving the script!!! I corrected the things you have written, but the Code is still 898b long.(Now it gives you the correct Output ;) ) And the part with the walrus is shorter just with text XD. If you have another great idea, pls share it.

Pyth, 342 bytes
L:b"a e""an e"y>sm.F"
I hear a {1} {0} in my ear.

{2}, {2}, what do you hear?"+dr3edJC,+R"ing"c"growl
roar
snort
flut
bray
hiss
trumpet
snarl
yelp
bellow
whistl"bc"polar bear
lion
hippopotamus
flamingo
zebra
boa constrictor
elephant
leopard
peacock
walrus
zookeeper"b42"I hear children...
"jPPysm+j" like a "d",
"PJc2*6\."that's what I hear.

Try it online here.
Explanation to follow.

clojure, 526 bytes
(use 'clojure.string)(let[l lower-case
a(partition 2(split"Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x"#","))b(map(fn[[w x][y e]][(str
w", "w", what do you hear?
I hear a "(l y)" "e"ing in my ear.

")(str x"ing like a "(l w))])a(rest a))r
replace](print(r(str(r(join""(map first b))#".*x.*""I hear children...")(join",
"(butlast(map last b)))"...
that's what I hear.")#"(?i)a(?= e)""an")))

Here's my initial attempt. Gotta love the formatting and how unreadable it is. Hope the warnings from use 'clojure.string are acceptable.
Try it online.
Formatted code:
(use 'clojure.string)
(let [animal-sound (partition 2 (split "Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x" #","))
      sentences (map (fn [[animal-1 sound-1] [animal-2 sound-2]]
                       [(str animal-1 ", " animal-1 ", what do you hear?\nI hear a "
                             (lower-case animal-2) " " sound-2 "ing in my ear.\n\n") (str sound-1 "ing like a " (lower-case animal-1))])
                     animal-sound (rest animal-sound))]
  (print (replace (str
                    (replace (join "" (map first sentences)) #".*x.*" "I hear children...")
                    (join ",\n" (butlast (map last sentences)))
                    "...\nthat's what I hear.") #"(?i)a(?= e)" "an")))

Java, 571 555 538 or 516 Bytes
String p(){String r="",z="...",b,x;String[]a="Polar Bear!Lion!Hippopotamus!Flamingo!Zebra!Boa Constrictor!Elephant!Leopard!Peacock!Walrus!Zookeeper!growling!roaring!snorting!fluting!braying!hissing!trumpeting!snarling!yelping!bellowing!whistling".split("!");for(int i=1;i<11;i++){b=i==6?"n ":" ";x=a[i-1];z+=a[i+10]+" like a"+b+x+(i==10?"...":"\n");r+=x+" , "+x+", what do you hear?\n I hear a"+b+a[i].toLowerCase()+" "+a[i+11]+" in my ear.\n\n";}r+=a[10]+" what do you hear?\n\tI hear children...\n"+z+"\nthat's what I hear.";return r;}

But only 516 bytes is required to get result in JShell
String r="",z="...",b,x;String[]a="Polar Bear!Lion!Hippopotamus!Flamingo!Zebra!Boa Constrictor!Elephant!Leopard!Peacock!Walrus!Zookeeper!growling!roaring!snorting!fluting!braying!hissing!trumpeting!snarling!yelping!bellowing!whistling".split("!");for(int i=1;i<11;i++){b=i==6?"n ":" ";x=a[i-1];z+=a[i+10]+" like a"+b+x+(i==10?"...":"\n");r+=x+" , "+x+", what do you hear?\n I hear a"+b+a[i].toLowerCase()+" "+a[i+11]+" in my ear.\n\n";}r+=a[10]+" what do you hear?\n\tI hear children...\n"+z+"\nthat's what I hear."

It's giving incorrect output regarding spaces, tabs, lowercase and an vs a.. I've fixed and golfed it to 507 bytes

@KevinCruijssen your code is missing the "ing" of "I hear a ... ...ing in my ear". Also, very likely golfable by starting i with 0 up to 10 changing b=a[i-1] with b=a[i++] and removing the increment where it currently is.

Haskell 537 499 497 Bytes
import Data.Char
a&b=a++b
b=putStr
c=concat
d=init
e('E':s)="an e"&s
e s="a "&map toLower s
f="I hear "
l=zip(lines"Polar Bear\nLion\nHippopotamus\nFlamingo\nZebra\nBoa Constrictor\nElephant\nLeopard\nPeacock\nWalrus\nZookeeper")$words"growl roar snort flut bray hiss trumpet snarl yelp bellow whistl"
main=(b.drop 41.c)[f&e n&" "&v&"ing in my ear.\n\n"&n&", "&n&", what do you hear?\n"|(n,v)<-l]>>b(f&"children...\n\n..."&(d.d.c)[v&"ing like "&e n&",\n"|(n,v)<-d l]&"...\nthat's what I hear.\n")

Using the convention that a solution does not have be executable, only produce the output via some function, this can be shortened to 479 Bytes. The output is in g:
import Data.Char
a&b=a++b
c=concat
d=init
e('E':s)="an e"&s
e s="a "&map toLower s
f="I hear "
l=zip(lines"Polar Bear\nLion\nHippopotamus\nFlamingo\nZebra\nBoa Constrictor\nElephant\nLeopard\nPeacock\nWalrus\nZookeeper")$words"growl roar snort flut bray hiss trumpet snarl yelp bellow whistl"
g=(drop 41.c)[f&e n&" "&v&"ing in my ear.\n\n"&n&", "&n&", what do you hear?\n"|(n,v)<-l]&f&"children...\n\n..."&(d.d.c)[v&"ing like "&e n&",\n"|(n,v)<-d l]&"...\nthat's what I hear.\n"

Swift2, 519 bytes
var a=["Polar Bear","Lion","Hippopotamus","Flamingo","Zebra","Boa Constrictor","Elephant","Leopard","Peacock","Warlus","Zookeeper"],b=["...growl","roar","snort","flut","bray","hiss","trumpet","snarl","yelp","bellow","whistl"].map{"\($0)ing"},c=a.enumerate().map{"\($0.0==6 ?"an":"a") \($0.1)".lowercaseString},i=0,j=0
while i<11{print("\(a[i]), \(a[i++]), what do you hear?\nI hear \(i>10 ?"children...":"\(c[i]) \(b[i]) in my ear")\n")}
while j<10{print("\(b[j]) like \(c[j++])\(j>9 ?"...\nthat's what I hear.":",")")}

C (clang), 552 bytes
(*P)()=printf;l(char*s){for(;*s;s++)putchar(*s>64?*s|32:*s);}char*a[]={"Zookeeper","Walrus","Peacock","Leopard","Elephant","Boa Constrictor","Zebra","Flamingo","Hippopotamus","Lion","Polar Bear"},*s[]={"whistl","bellow","yelp","snarl","trumpet","hiss","bray","flut","snort","roar","growl"};f(i){for(i=11;i--;)P("%s, %s, what do you hear?\nI hear%s ",a[i],a[i],i?i^5?" a":" an":""),i?l(a[i-1]):0,P(i?" %sing in my ear.\n\n":"children...\n\n...",s[i-1]);for(i=11;--i;)P("%sing like a%s ",s[i],i^4?"":"n"),l(a[i]),P(i-1?",\n":"...\nthat's what I hear.");}

Try it online!

537 bytes

Perl 5, 413 bytes
@t=('Polar Bear',growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,'Boa Constrictor',hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl);say$_=$t[$i],", $_, what do you hear?
I hear ",/Zo/?"children...
":"a".n x(/C/).lc" $t[$i+=2] $t[$i+1]ing in my ear.
"while!/Zo/;pop@t;pop@t;print'...';say+(shift@t)."ing like a ".lc.(@t?",":'...')while$_=shift@t;say"that's what I hear."

Try it online!

JavaScript, 424 bytes
f=(x=0,a=btoa`>Z¯ ^j¼Ëó*i¢-jk¬ÌYZ)à£6^n¶³²
ì¶¸¶óW©©íÌ·¨¥ªÝÌ÷r$Íf¥®ë3f$yê^¯0`[s=`split`]`y`.join` `[s]`z`,g=z=>n[z]+`ing like `+h(17)+l(z)+(z>9?`...
that's what I hear.`:`,
`+g(++z)),h=m=>++x%m?`a `:`an `,l=y=>a[y].toLowerCase(n=btoa`º0:èj¼ìíÍùn·6ëk,áË3¶»¦¥ës²v«<ÛzYhÃ<!ËeÌ`[s]`z`))=>a[x]+`, ${a[x]}, what do you hear?
I hear `+(x>9?`children...

...`+g(0):h(6)+l(x)+` ${n[x]}ing in my ear.

`+f(x))

Test it

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
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

0 for empty matrix
2

0 for 0 based indices or 2 for 1-based
1 5 2
9 4 2
5 9 6

2 for 0 based or 10 for 1 based
 0 3  0  4
 0 4  1  4
 4 3  1  2
-2 4 -2 -1

11
3 -1 3 3
3 -1 3 1

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.

in which Ken’s reply to Dijkstra’s question was a one-liner. But then that one-liner was wrong?

Do I need to output it or print it out, or can I just write down the expression as a snippet?

@LuisMendo No, Iverson was actively designing the language, and at that iteration, his one-liner was correct. "APL" became famous with the publishing of the book A Programming Language, but at the time of publishing, the second expression was needed. Neither of these notations were ever implemented to be machine-executable.

@LeakyNun Write a snippet or expression to calculate

@Adám Thanks. It makes more sense now

Can I store the output in a variable?

@LeakyNun Yes you can.

MATL, 15 14 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

APL, 13 12 bytes
1 byte thanks to @jimmy23013.
1-indexed.
The array is stored in the variable m.

+/,m×m=+/¨⍳⍴m
+/∊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

Finally, I was waiting for this one.

I'm not sure the "To key in:" is a good idea. It only applies to TryAPL and RIDE, but not to the main product. At least you can explain that ``` means "APL key".

+/∊m∩¨+/¨⍳⍴m.

@jimmy23013 That's really good!

JavaScript, 49 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.

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.

Can you use unary as input?

@LeakyNun Don't know, I've kinda been trying to avoid it. It just seems too hacky, especially since Retina has no trouble with the conversion any more.

R, 24 bytes
sum(M[M==row(M)+col(M)])

1-based.
Test cases:
> M<-matrix(nrow=0,ncol=0)
> M
<0 x 0 matrix>
> sum(M[M==row(M)+col(M)])
[1] 0
> M<-matrix(2,nrow=1,ncol=1)
> M
     [,1]
[1,]    2
> sum(M[M==row(M)+col(M)])
[1] 2
> M<-matrix(c(1,9,5,5,4,9,2,2,6),nrow=3)
> M
     [,1] [,2] [,3]
[1,]    1    5    2
[2,]    9    4    2
[3,]    5    9    6
> sum(M[M==row(M)+col(M)])
[1] 10
> M<-matrix(c(0,0,4,-2,3,4,3,4,0,1,1,-2,4,4,2,-1),nrow=4)
> M
     [,1] [,2] [,3] [,4]
[1,]    0    3    0    4
[2,]    0    4    1    4
[3,]    4    3    1    2
[4,]   -2    4   -2   -1
> sum(M[M==row(M)+col(M)])
[1] 11
> M<-matrix(c(3,3,-1,-1,3,3,3,1),nrow=2)
> M
     [,1] [,2] [,3] [,4]
[1,]    3   -1    3    3
[2,]    3   -1    3    1
> sum(M[M==row(M)+col(M)])
[1] 3

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

Not only shortest until now; +1 for doing it in an Iverson language.

Jelly, 15 14 10 bytes
4 bytes thanks to Adnan.
1-indexed.

L€R€+"LR$=³×³FS
L€R€+"LR$=×³FS
J€+"J=×⁸FS

Try it online!
Verify all testcases at once.
(Slightly modified.)

I'm not sure if it works, but can you do J€ instead of L€R€?

Oh my God, you're a genius.

CJam, 23 21 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.

You can save a couple with _,, instead of the inner ee and . for the inner loop: ee{~_,,@f+1$.=.*~}%1b

@PeterTaylor Ah neat, thank you. :)

In fact, there's one more, by doing a kind of meet-in-the-middle: ee{~_@f-_,,.=.*~}%1b

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.

e=enumerate;sum(i*(x+y==i)for x,r in e(a)for y,i in e(r))

oh it didn't work. so its 57 bytes now : ( I added a quick explanation

You might want to include the link I just gave you.

k4, 24 bytes
Assumes the matrix is stored in m.
+//7h$m*m=(!#m)+/:\:!#*m

This is one of those puzzles where the simplifications involved in designing k from APL (and J) really hurt—k’s ! is the equivalent of APL’s ⍳ but only works on vectors, so I have to assemble the matrix of indices myself; inner product is one character in APL but five in k; and I lose three characters to handling the empty matrix properly because k doesn’t have strongly-typed matrices.

On the other hand, you have a powerful language which is much more consistent, and with much fewer primitives to learn.

Ruby, 63 bytes
With z as a two-dimensional array of numbers:
s=0;z.each_index{|i|z[i].each_index{|j|s+=i+j if z[i][j]==i+j}}

Not terribly exciting at all.
If z is a flattened array with x and y having the sizes of the arrays, such as:
x=z.size
y=z[0].size
z=z.flatten

Then we have this monstrousity - perhaps more ruby-ish with it's fancy products and zips, but actually larger:
(1..x).to_a.product((1..y).to_a).zip(z).inject(0){|s,n|s+(n[0][0]+n[0][1]==n[1]+2?n[1]:0)}

Perhaps there is a fancier array or enumerator method that would shorten it, I haven't found it yet, but I'd love to see it.

Actually, 21 bytes
ñ`i╗ñ"i╜+@;(=*"£Mi`MΣ

Try it online!
Thanks to Leaky Nun for making me stop being lazy and finally write this.
This uses 0-indexed matrices, and takes input as a nested list.
Explanation:
ñ`i╗ñ"i╜+@;(=*"£Mi`MΣ
ñ                      enumerate input
 `i╗ñ"i╜+@;(=*"£Mi`M   for each (i, row) pair:
  i╗                     flatten, store i in register 0
    ñ                    enumerate the row
     "i╜+@;(=*"£M        for each (j, val) pair:
      i╜+                  flatten, add i to j
         @;(               make an extra copy of val, bring i+j back to top
            =              compare equality of i+j and val
             *             multiply (0 if not equal, val if they are)
                 i       flatten the resulting list
                    Σ  sum the values

same byte-count, without function delimiters or registers

Pyth, 14 bytes
0-indexed.
ss.e.e*ZqZ+kYb

Test suite.

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

Matlab/Octave, 48 bytes
1-indexed.
Will not handle the first test case because [1:0] has size 1x0 for some reason
sum(sum(M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0)))

Tested in Octave 3.
Full program:
M = [2]
sum(sum(M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0)))
M = [1 5 2; 9 4 2; 5 9 6]
sum(sum(M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0)))
M = [ 0 3  0  4; 0 4  1  4; 4 3  1  2;-2 4 -2 -1]
sum(sum(M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0)))
M = [ 3 -1 3 3; 3 -1 3 1]
sum(sum(M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0)))

Welcome to PPCG! In Octave you can do sum((M.*(M-[1:size(M,1)]'-[1:size(M,2)]==0))(:)). Also, I think you can change ==0 by and initial ~ to further reduce byte count. Finally, note that you need to handle all test cases or else the question should be deleted

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}})

PHP, 59 bytes
foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;

expects array $a defined; must be empty or 2-dimensional, 0-indexed.
calculates sum to $s (previously 0 or undefined - 0 equals NULL)
insert +2 before final ) for 1-indexed behaviour
Happy Birthday APL!
functions and test suite
function f0($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;return $s|0; }
function f1($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y+2)*$v;return $s|0;}
$samples = [
    [], 0, 0,
    [[2]], 0, 2,
    [[1,5,2],[9,4,2],[5,9,6]], 2, 10,
    [[0,3,0,4],[0,4,1,4],[4,3,1,2],[-2,4,-2,-1]],11,11,
    [[3,-1,3,3],[3,-1,3,1]],6,3
];
function test($x,$e,$y){static $h='

input	output	expected	ok?
';echo"$h
",out($x),'	',out($y),'	',out($e),'	',cmp($e,$y)?'N':'Y',"
";$h='';}
while($samples)
{
    $a=array_shift($samples);
    test($a,'B0:'.array_shift($samples),'B0:'.f0($a));
    test($a,'B1:'.array_shift($samples),'B1:'.f1($a));
}

Wolfram Language (Mathematica), 42 bytes
ArrayRules/*Cases[p_~_~v_/;Tr@p==v:>v]/*Tr

Try it online!
1-indexed.
ArrayRules                                  (*Convert into a list of (position->value) Rules*)
          /*Cases[p_~_~v_/;Tr@p==v          (*select those where sum(position)==value*)
                                  :>v]/*Tr  (*and find the sum of those values*)

Brachylog, 15 bytes
{iiʰI-ʰ=∧Ihh}ᶠ+

Try it online!
              +    The output is the sum of
{           }ᶠ     all possible results of
 i                 taking a row from the input with its index,
  i                taking an element with its index
   ʰ               from that row,
    I    Ihh       and outputting the element
       =∧          so long as the index of the row is equal to
     -ʰ            the value of the element minus its index within the row.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/