50
\$\begingroup\$

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.
\$\endgroup\$
  • 6
    \$\begingroup\$ kolmogorov-complexity would be a good tag for this \$\endgroup\$ – charredgrass Jul 19 '16 at 4:03
  • 3
    \$\begingroup\$ Are the uppercase B and C in Polar Bear and Boa Constrictor necessary? (In Batch this costs me 10% of my byte count...) \$\endgroup\$ – Neil Jul 19 '16 at 10:15
  • \$\begingroup\$ Is submitting a hash and bruteforcing the solution with a restricted set allowed? :D \$\endgroup\$ – polym Jul 19 '16 at 10:30
  • 4
    \$\begingroup\$ This is a very nice first challenge! \$\endgroup\$ – Alex A. Jul 19 '16 at 16:24
  • 1
    \$\begingroup\$ I'd +1 but you're at 42 upvotes, and who am I to disturb the ways of the galaxy? \$\endgroup\$ – FantaC Feb 14 '18 at 23:06

31 Answers 31

0
\$\begingroup\$

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!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.