37
\$\begingroup\$

cat goes "Meow"

We are all familiar with the concept of a cat program. The user types something in, it is echoed back to the user. Easy. But all cat programs I've seen so far have missed one fact: a cat goes "Meow". So your task is to write a program that copies all STDIN to STDOUT UNLESS the input is cat, in which case your program should output cat goes "Meow".

Scoring

This is , so your score is your byte count, with a few modifiers:

  • If your program works for any additional animals other than cat (e.g. cow: cow goes "Moo"), for each additional animal: -10
  • If your program doesn't use the word "cat": -15
  • If your program responds to fox with "What does the fox say": -25

Animals and sounds that go together:

cow goes moo duck goes quack sheep goes baa bees go buzz frogs go croak

Anything else on this list is allowed.

Rules

  • Standard loopholes apply
  • You must not write anything to STDERR
  • You can use single quotes/no quotes instead of double quotes.

Leaderboard

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:

## Language Name, N bytes

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:

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

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:

## Perl, 43 + 2 (-p flag) = 45 bytes

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

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

var QUESTION_ID=62500;var OVERRIDE_USER=46470;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});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;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>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;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
16
  • 20
    \$\begingroup\$ For the bonuses: What does the fox say? \$\endgroup\$ Commented Nov 1, 2015 at 8:11
  • 1
    \$\begingroup\$ For the bonuses: can each additional animal be singular, or does "bees" always have to be plural, as in your list? \$\endgroup\$
    – ProgramFOX
    Commented Nov 1, 2015 at 9:06
  • 2
    \$\begingroup\$ Cats say meow.. \$\endgroup\$ Commented Nov 1, 2015 at 11:37
  • 1
    \$\begingroup\$ Instead of double quotes, can you use single ones? Also, can you output to stderr? \$\endgroup\$
    – Blue
    Commented Nov 1, 2015 at 12:47
  • 5
    \$\begingroup\$ Why is there no link to this in this challenge? \$\endgroup\$
    – Jan
    Commented Nov 1, 2015 at 20:50

70 Answers 70

1 2
3
0
\$\begingroup\$

Java, 174 - 15 = 159 bytes

interface a{static void main(String[]A){for(String s="";;s=new java.util.Scanner(System.in).nextLine())System.out.println(s+(s.equalsIgnoreCase("ca"+"t")?" goes meow":""));}}

Ungolfed:

interface a {
    static void main(String[] A){
        for (String s = "";;s = new java.util.Scanner(System.in).nextLine())
            System.out.println(s + (s.equalsIgnoreCase("ca"+"t") ? " goes meow" : ""));
    }
}
\$\endgroup\$
0
\$\begingroup\$

Python 3, 44 - 15 = 29

i=input();print(i+' goes Meow'*(i=='ca''t'))
\$\endgroup\$
0
\$\begingroup\$

0815, 132 - 15 = 117

}:(:!~>^:(:}:):{~$>^:):{=<:63:-^:
:{=<:61:-^:
:{=<:74:-^:
:{=<:0:-^:
:<:20:~>$<:67:~$<:6F:~>$<:65:~>$<:73:~${~$<:4D:~$&{~${~$<:77:~$
\$\endgroup\$
0
\$\begingroup\$

PHP, 47-15=32 bytes

<?=($s=fgets(STDIN)).[" goes Meow"][c.a.t!=$s];

4 bytes longer than on $argv[1], and: it works only on the first line of input (including the linebreak).

69-15=54 bytes to take all lines:

while(false!==$n=fgets(STDIN))$s.=$n;echo$s,[" goes Meow"][c.a.t!=$s];
\$\endgroup\$
1
  • \$\begingroup\$ @user46470: I guess that echo$argn,[" goes Meow"][c.a.t!=$argn],~õ; using php -R '<code>' (execute code for every line of input) would be a little cheating ... but it´s 5 bytes shorter. ;) \$\endgroup\$
    – Titus
    Commented Mar 15, 2017 at 2:11
0
\$\begingroup\$

Pepe, 244 - 15 = 229 bytes

Bonus -15 for not containing the word "cat"

rEeEEeeeEErrEEREEeererEeEEeeeeErrEEREEeererEeEEEeEeerrEEREEeererErrEEreeEEeeeEEreeEEeeeeEreeEEEeEeereeeEeeeeereeEEeeEEEreeEEeEEEEreeEEeeEeEreeEEEeeEEreeeEeeeeereeeEeeeEereeEeeEEeEreeEEeeEeEreeEEeEEEEreeEEEeEEEreeeEeeeEeREEEEeEEErEeREEeREReEReee

Try it online!

Commented version

re  # fix syntax highlighting, doesn't affect the program
rEeEEeeeEE  # push "c"
rrEE  # func

REEee re  # pop "c"
rEeEEeeeeE  # push "a"
rrEE  # func

REEee re  # pop "a"
rEeEEEeEee  # push "t"
rrEE  # func

REEee re  # pop "t"
rE
rrEE  # func

# Output the text
reeEEeeeEE reeEEeeeeE reeEEEeEee reeeEeeeee reeEEeeEEE reeEEeEEEE reeEEeeEeE reeEEEeeEE reeeEeeeee reeeEeeeEe reeEeeEEeE reeEEeeEeE reeEEeEEEE reeEEEeEEE reeeEeeeEe

# Clear the stack
REEEEeEEE

rEe  # end-pop

# Loop
REEe RE  # Take input, add a trailing null
ReE

Reee
\$\endgroup\$
0
\$\begingroup\$

Runic Enchantments, 50 - 15 = 35

D q?=1l" "\>
Rlril1-{=?/:1´759E" "=?@"goes Meow"@

Try it online!

In general, for a zero-length animal name and zero-length sound, the overhead for another animal is 10 bytes (roughly, :0""=2*?""). The fifteen bytes we get for cat makes it worth spending a net 1 byte encoding "cat" as the numerical value 1759 and extracting "cat" from the dictionary.

\$\endgroup\$
0
\$\begingroup\$

C (gcc), 81 - 15 = 66 bytes

Text input version

Does not contain the word "cat", so gets that bonus. All attempts at further bonuses made the program larger.

Assumes a little-endian machine where sizeof(int) >= 4 and where signed integers are of the two's complement variety.

q;main(c){for(;c=~getchar();)q=q<<8|putchar(~c);q^6513012||printf(" goes meow");}

Try it online!

q;main(c){
for(;c=~getchar();)         Read bit-flipped character from STDIN into c. getchar()
                            returns -1 on EOF, and with two's complement, ~c == -c - 1,
                            so we stop on EOF.
q=q<<8|putchar(~c);         Insert character at LSB of q, moving the current values along one
                            byte, while also sending it to STDOUT.
q^6513012||                 Is q non-equal to "cat"?
printf(" goes meow");}      If no (it IS equal), print addendum, otherwise ignore.

The above is fine for text-only input, and most binary input. The only (known by me) corner case is if the file happens to end with a NUL character followed by "cat" (\0cat), which will give a false positive. I am not 100% sure if we were meant to deal with anything but text, so here is the safer version too:

Binary-friendly version, 90 - 15 = 75 bytes

q,x;main(c){for(;c=~getchar();x++)q=q<<8|putchar(~c);x^3|q^6513012||printf(" goes meow");}

Try it online!

\$\endgroup\$
1
0
\$\begingroup\$

Python 3, 516 - [10 x 53] - 15 = -29 bytes

lambda i:([i+f' goes "{a.split(",")[0]}"'for a in("bark,dog,wolf,seal,zebra bellow,alligator,moose,okapi bleat,deer,elk,giraffe,sheep,goat,lamb bray,donkey,ass buzz,bee,mosquito caw,crow,raven,rook chirp,cicada,cricket,songbird chuckle,linnet croak,frog,toad cry,swan hiss,goose,snake,tarantula meow,c"+"at moo,calf,cow,ox oink,pig,hog roar,badger,bear,lion,tiger,jaguar,leopard scream,monkey,peacock,vulture screech,bat,eagle,owl squeak,hamster,mouse,rat,rabbit,hare,tapir").split()if i in a.split(",")[0:]]+[i])[0]

Try it online!

Started with all the animals on the list, sorted into optimal groupings by sounds they make, then culled down animals whose bytes use more than 10. The final list contains 54 animals, for a bonus of -540 bytes.

It doesn't contain cat for another -15 bytes.

It's an anonymous function that works like a table with the animal sounds as headers, and finds the corresponding header for the animal in the table, otherwise returns the input.

If I'm allowed to respond to cat with cat goes "hiss" as in the list of animal sounds, I can pull off another 5 bytes.

-3 bytes thanks to Reinstate Monica.

\$\endgroup\$
1
  • \$\begingroup\$ @ReinstateMonica Thanks, I had it that way to handle multi-word animals, but I've removed them all. Cheers \$\endgroup\$ Commented Dec 10, 2019 at 19:44
0
\$\begingroup\$

Japt, 18 bytes

r`^¯t$`È+` go ´ow

Try it

\$\endgroup\$
0
\$\begingroup\$

Gema, 24 characters - 15 = 9

\Ac\Lat\Z=$0 goes "Meow"

gema works like a filter, so an empty gema '' is the same as cat.

To avoid using the word “cat” literally, inserted a pointless \L (turns on line mode, like an inline -line switch, meaning following arguments can't cross line boundary).

Sample run:

bash-5.0$ echo -n cat | gema '\Ac\Lat\Z=$0 goes "Meow"'
cat goes "Meow"

bash-5.0$ echo -n cats | gema '\Ac\Lat\Z=$0 goes "Meow"'
cats

Try it online!

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.