32
\$\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
  • 18
    \$\begingroup\$ For the bonuses: What does the fox say? \$\endgroup\$ 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
    Nov 1, 2015 at 9:06
  • 2
    \$\begingroup\$ Cats say meow.. \$\endgroup\$ 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
    Nov 1, 2015 at 12:47
  • 5
    \$\begingroup\$ Why is there no link to this in this challenge? \$\endgroup\$
    – Jan
    Nov 1, 2015 at 20:50

66 Answers 66

1
\$\begingroup\$

Pyke, 391 -595 = -204 bytes (noncompetitive)

-58*10 extra animals, -15 for no "cat" string

"goes"Q.dt𛧷偮晪ꅢὐ𑈶ὥ𑈶墵𑈶셞𑈶𸣌᳙ᄷ쟿䁔𔣩𕕄漲𔵸ᬰ䵙ꄨ塋튖𴏵თ᠞鮔૪爟㍅爟⼱]꣟勒〥鴞᫠⬻䋥ュ⣹𓫌邦𴽩㺓𒀽𓫌堚퀦잓號漲ქ︆𐊷䦙ᔯ漲ᠥ쏔っ鮔𐩁牔鶇Ƒ䂝雥𐻳⬻⯎偮燩巺𑳦䯥𒀽봽鮔튖➒゗ᨼ𓫌䄇𓫌嚕𓫌㮷鮏𐓧ᘽ挳ᖘ𯃮漲𑙌𒀽睴윿꒲⬻𦼎鼤㨂ᘽdc2cY@]3J

Try it here!

Uses dictionary-based compression to store the words. Pyke is older than the question.

Animals it knows:

{'seals': 'bark', 'turkeys': 'gobble', 'mosquitos': 'whine', 'curlews': 'pipe', 'dogs': 'howl', 'sheep': 'bleat', 'elephants': 'trumpet', 'eagles': 'scream', 'raccoons': 'trill', 'goats': 'bleat', 'donkeys': 'bray', 'monkey': 'whoop', 'snakes': 'hiss', 'wolves': 'howl', 'grasshoppers': 'chirp', 'ferrets': 'dook', 'geese': 'honk', 'ducks': 'quack', 'chinchillas': 'squeak', 'oxen': 'low', 'pigs': 'snort', 'lions': 'snarl', 'antelopes': 'snort', 'crows': 'caw', 'hamsters': 'squeak', 'ravens': 'croak', 'leopards': 'snarl', 'tapirs': 'squeak', 'lambs': 'bleat', 'horses': 'neigh', 'jaguars': 'snarl', 'crickets': 'chirp', 'moose': 'bellow', 'cattle': 'moo', 'deer': 'bellow', 'rooks': 'caw', 'dolphins': 'click', 'whales': 'sing', 'owls': 'hoot', 'walruses': 'groan', 'cicadas': 'chirp', 'tigers': 'snarl', 'chickens': 'cluck', 'giraffes': 'bleat', 'mice': 'squeak', 'peacocks': 'scream', 'songbirds': 'sing', 'geckos': 'croak', 'frogs': 'croak', 'pigeons': 'coo', 'swans': 'cry', 'bitterns': 'boom', 'rhinoceros': 'bellow', 'cats': 'purr', 'badgers': 'growl', 'magpies': 'chatter', 'vultures': 'scream', 'elk': 'bleat'}
\$\endgroup\$
1
\$\begingroup\$

C++11, 316 - 11*10 - 15 = 191 bytes

#include <map>
#define t(a,b){#a,#b},
using s=std::string;int main(){std::map<s,s>m{t(cow,moo)t(crow,caw)t(dog,bark)t(hog,oink)t(lark,sing)t(lion,roar)t(oxen,low)t(rook,caw)t(seal,bark)t(sheep,baa)t(swan,cry){"c""at","meow"}};s l;while(int i=~getchar())l+=~i;printf("%s",(m[l]==""?l:l+" goes \""+m[l]+'"').c_str());}

Compiles well with VisualStudio. GCC wants me to #include <string> and #include <cstdio>. It would be shorter if I wouldn't go for bonuses, but I still hope author revises bonuses. I can't think of language where defining cow -> moo or so is way way shorter than 10bytes. Mine cost 3+key+value bytes for additional animal and flat 22+17 bytes for defining structure and so.

Ungolfed

#include <map>

#define t(a, b) { #a, #b },
using s = std::string;
int main()
{
    std::map<s, s> m{
        t(cow,moo)
        t(crow,caw)
        t(dog,bark)
        t(hog,oink)
        t(lark,sing)
        t(lion,roar)
        t(oxen,low)
        t(rook,caw)
        t(seal,bark)
        t(sheep,baa)
        t(swan,cry)
        { "c""at", "meow" }
    };
    s l;
    while (int i = ~getchar())
        l += ~i;
    printf("%s", (m[l] == "" ? l : l + " goes " + m[l]).c_str());
}
\$\endgroup\$
5
  • \$\begingroup\$ "t(crow,caw)" has a length of 11. So getting rid of that to "t(swan,cry)" would drop 14 bytes. And admittedly make it less fun :( \$\endgroup\$
    – Noodle9
    Nov 2, 2015 at 6:33
  • \$\begingroup\$ @user, As I said, I still hope author revises bonuses. \$\endgroup\$
    – Zereges
    Nov 2, 2015 at 9:01
  • \$\begingroup\$ You should state C++11 in the headline. Python 2 and 3 are also always distinct noted. While the using is no big deal, the initializer list is. \$\endgroup\$
    – Karl Napf
    Nov 28, 2016 at 14:23
  • \$\begingroup\$ @KarlNapf Thanks for pointing that out. \$\endgroup\$
    – Zereges
    Nov 28, 2016 at 17:07
  • \$\begingroup\$ You can also change #include <map> to #import<map> for -2 bytes. The space before < can be omitted and #import throws some warnings but is accepted be GCC and MSVC \$\endgroup\$
    – Karl Napf
    Nov 28, 2016 at 17:11
1
\$\begingroup\$

GolfScript, 25 - 15 = 10 bytes

."c""at"+=" goes 'Meow'"*

Try it online!

Example

."c""at"+=" goes 'Meow'"*   # Input: cat
."c""at"                    # Duplicate input, push c and at. Stack: cat cat c at
        +                   # Concatenate, Stack: cat cat cat
         =                  # Check if equal, Stack: cat 1
          " goes 'Meow'"*   # " goes 'Meow'" pushed onto stack n times, Stack: "cat" " goes 'Meow'"
                            # Implicitly print

Alternate Example

."c""at"+=" goes 'Meow'"*   # Input: asdf
."c""at"                    # Duplicate input, push c and at. Stack: asdf asdf c at
        +                   # Concatenate, Stack: asdf asdf cat
         =                  # Check if equal, Stack: asdf 0
          " goes 'Meow'"*   # " goes 'Meow'" pushed onto stack n times, Stack: "asdf" ""
                            # Implicitly print
\$\endgroup\$
0
\$\begingroup\$

Pyth, 31 - 15 = 16 bytes

You can try it out here

In+C99"at"zz;E+z" goes \"Meow\"

Explaination:

I                                # If-statement
 n                               # not equal
  +C99"at"                       # Adds the char 99 with the string "at" = "cat"
          z                      # z, the user input
           z                     # Print the user input
            ;                    # Ends all open parentheses
             E                   # Else-statement
              +z" goes \"Meow\"  # Adds ' goes "Meow"' to z and prints the result
\$\endgroup\$
1
  • 1
    \$\begingroup\$ C99 can be replaced with \C. It's still +\C"at", so you can keep the bonus. \$\endgroup\$
    – clapp
    Nov 2, 2015 at 1:19
0
\$\begingroup\$

C, 76 bytes

main(){char a[99];gets(a);printf("%s%s",a,strcmp(a,"cat")?"":" goes meow");}
\$\endgroup\$
0
\$\begingroup\$

PHP, 70-15 = 55 bytes

<?=$l=rtrim(stream_get_contents(STDIN),~òõ),$l==~œž‹?~ߘšŒßݲšˆÝ:'';

(saved as ISO-8859-1)

Uses inverted undefined constants as string literals:

  • ~òõ == "\r\n"
  • ~œž‹ == 'cat'
  • ~ߘšŒßݲšˆÝ == ' goes "Meow"'

Everything is combined in a single echo statement, shorthanded with <?=

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

Ruby, 35 + 2 (-p flag) - 15 = 22 bytes

$_==?c'at
'&&$_[-2]+=' goes "Meow"'

Inspired by trying to improve Peter Lenkefi's solution.

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

Ruby, 110 + 2 (-p flag) -60 (cow, ox, dog, bee, pig and crow) -15 (no cat) = 37 bytes

(h=Hash[*%W(cow Moo ox Low c\141t Meow dog Woof bee Buzz pig Oink crow Caw)][$_.chop])&&$_[-2]+=' goes "'+h+?"

Multiple animal Ruby solution... As long as the animal+sound is <8 characters, it shrinks for each one added. Gross abuse of Ruby. :)

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

Ruby, 26 + 1 = 27

With command-line flag -p, run

sub /^cat$/,'\& goes Meow'

Getting the no-cat bonus costs 2 bytes, which isn't actually worth it:

sub /^c at$/x,'\& goes Meow'
\$\endgroup\$
0
\$\begingroup\$

Hassium, 67 Bytes

func main()if((x=input())=="cat")print(x+" goes meow")else print(x)

See expanded here

\$\endgroup\$
1
  • \$\begingroup\$ It's fine to link to an online interpreter so that readers can test the code themselves, but you should still include sufficient explanation or expansion in the post such that a casual reader could convince themself that your submission is correct. \$\endgroup\$
    – Alex A.
    Dec 22, 2015 at 5:39
0
\$\begingroup\$

JacobFck, 31 Bytes

I really like the golfed version of this.

"cat"<|=_e>!:e"cat goes Meow">

See commented and expanded here

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

Python 2, 149-95 = 54 bytes

-8*10 extra animals, -15 for no "cat"

u=raw_input()
l="ca""t badger rhino okapi moose stag tiger hippo lion".split()
print u+' goes "%s"'%["Growl","Bellow","Meow"][`l`.find(u)%3]*(u in l)

Supported animals:

  • moose, stag, okapi, rhino (all Bellow)
  • tiger, badger, lion, hippo (all Growl)

This is not the shortest Python answer, but at least it does bother to try at some other animals! I add it here because the answer i had previously did not work, and I'm confident this will become the shortest Pyth answer once I translate it and golf it there.

How it works:

  1. Take input
  2. Create a list of animals in a very precise order.
  3. Print the input, and if the input is in the list, use the location of the input in the string representation of the list to index an array of sounds, and append the appropriate "goes" string.
\$\endgroup\$
0
\$\begingroup\$

Arcyóu, 38 bytes (non-competitive)

Since this version of the language was made after the challenge was posted, it is not eligible.

(: s(q))(?(= s "cat")"cat goes Meow" s

Arcyóu is a LISP-like golfing language.

Explanation:

(: s(q))           ; Set the variable s to the contents of STDIN
(? (= s "cat")     ; If-statement. Condition is s == "cat"
  "cat goes Meow"  ; If true: return the string "cat goes Meow"
  s                ; Otherwise, return what was entered

Arcyóu automatically prints the result of the last expression evaluated. In this case, it is the ? statement. It also allows you to leave off trailing close-parens.

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

Emacs Lisp (67 Bytes)

(set'a(read-string""))(message(pcase a("cat""cat goes meow")(_ a)))

It uses pattern matching to distinguish cats from other input. This could be extended to fit other animals in as well, but as most of them take up more than 10 characters, there is not much to be gained from that.

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

Milky Way 1.5.16, 29 bytes - 15 = 14

"c""at"+'?{b_" goes Meow"+_}!

Doesn't use a "cat" string.


Explanation

"c""at"      " goes Meow"      # push string to the stack
       +                 +     # add the TOS and the STOS
        '                      # read input from the command line
         ?{ _             _}   # if statement
           b                   # equality of the TOS and the STOS
                            !  # output the TOS

Usage

python3 milkyway.py <path-to-code> -i <input>
\$\endgroup\$
0
\$\begingroup\$

Perl, 13 bytes

The string "cat" does not appear in my code (Special thanks to Dennis for shaving 15 bytes off of the code, and teaching me some new Perl tricks):

s/^(c)at$/$& goes Meow/
\$\endgroup\$
4
  • \$\begingroup\$ Neither of those are mentioned in the OP, unless I am missing something? It simply needs to take input and replace "cat" with cat goes Meow. I'm not sure if I missed something but I think my answer is valid. \$\endgroup\$
    – Codefun64
    Dec 12, 2015 at 18:06
  • \$\begingroup\$ In other words, unless the string is exactly the string "cat" it should not be reached. \$\endgroup\$
    – quintopia
    Dec 13, 2015 at 0:33
  • \$\begingroup\$ Ah, I see what you mean. Very well, I'll make a minor edit to it. \$\endgroup\$
    – Codefun64
    Dec 13, 2015 at 3:03
  • \$\begingroup\$ Alternatively, s/^(c)at$/$& goes Meow/ with the -p switch. \$\endgroup\$
    – Dennis
    Dec 13, 2015 at 3:24
0
\$\begingroup\$

C#6, 302 - 110 - 15 = 177 bytes

This works for 12 different animals, including cat. It does not include the word "cat" verbatim.

using static System.Console;class P{static void Main(){var a=ReadLine();var d="bee,Buzz,c\x61t,Meow,cow,Moo,crow,Caw,dog,Bark,hog,Oink,lamb,Baa,lion,Roar,ox,Low,owl,Hoo,pig,Oink,rook,Caw,seal,Bark,sheep,Baa,swan,Cry".Split(',');int i=22;while(--i>0&&d[--i]!=a);Write(i<0?a:d[i]+" goes '"+d[i+1]+"'");}}

Indentation and new lines for clarity.

using static System.Console;
class P{
    static void Main(){
        var a=ReadLine();
        var d="bee,Buzz,c\x61t,Meow,cow,Moo,crow,Caw,dog,Bark,hog,Oink,lamb,Baa,lion,Roar,ox,Low,owl,Hoo,pig,Oink,rook,Caw,seal,Bark,sheep,Baa,swan,Cry".Split(',');
        int i=22;
        while(--i>0&&d[--i]!=a);
        Write(i<0?a:d[i]+" goes '"+d[i+1]+"'");
    }
}
\$\endgroup\$
0
\$\begingroup\$

DIG, 163 - 15 = 148 bytes

Disclaimer: Due to the fact that DIG was created after the challenge, this answer is non-competing.

Beautiful cats

Zoomed in (Note: This file will NOT compile, due to the nature of the language)

Impossible Cats

While I have no idea if this is considered a valid language for PPCG, it does complete the challenge. Documentation for the language can be found here and the interpreter can be found here.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! This language is pretty cool but I think the community and readers would benefit if you took this approach and included as well an enlarged version of the image -- even zooming on this one is too small. \$\endgroup\$
    – cat
    Dec 16, 2015 at 1:40
  • \$\begingroup\$ To be eligible for code golf, a language has to be capable of addition and primality testing. If that is the case for DIG, you're golden. Since DIG seems to be a lot newer than is question, it is also customary to include a disclaimer in the answer, stating that it is non-competing. \$\endgroup\$
    – Dennis
    Dec 16, 2015 at 1:43
0
\$\begingroup\$

Swift 2.0, 71 68-15 (no "cat") = 53 bytes

func a(s:String)->String{return s=="c\u{61}t" ?s+" goes \"Meow\"":s}

For some reason, a compilation error is thrown if there isn't a space before the ternary operator ?

Ungolfed

func a(s: String) -> String{
    return s == "c\u{61}t" ? s + " goes \"Meow\"" : s
}

This doesn't use "cat" in it by replacing the a with the unicode literal \u{61}. You can test this code here

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

JavaScript, 35 - 15 (-p no cat) = 20 Bytes

c=i=>(i=='c\at')?i+' says "Meow"':i

Can someone check to see that I did the header right?

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

Retina, 23 - 15 = 8 bytes

^ca\0*t$
$& goes "Meow"
\$\endgroup\$
0
0
\$\begingroup\$

Pylongolf2, 33-15=18 bytes

"tac"╨1cd_@0=b?" goes Meow"¿~

Explanations:

"tac"╨1cd_@0=b?" goes Meow"¿~
"tac"                         push "tac" to stack
     ╨1                       reverse it
       cd                     read input and then select latest item in stack
         _                    duplicate input
          @0                  select first item in stack
            =b                compare then swap places
              ?               if true,
               " goes Meow"¿  push " goes Meow" to stack and end if statement
                            ~ print it.
\$\endgroup\$
0
\$\begingroup\$

Lua 5.3.2, 229 - 25 - 15 - 80 (extra animals) = 109 bytes

r={...}a={['\99\97\116']='Meow',duck='Quack',sheep='Baa',bee='Buzz',frog='Croak',bat='Screech',elk='Bugle',swan='Cry',pig='Oink'}print(r[1]=='fox' and 'What does the fox say' or(a[r[1]] and r[1]..' goes "'..a[r[1]]..'"' or r[1]))

Ungolfed

local Args = {...}
local Sounds = {
    ['\99\97\116'] = 'Meow',
    duck = 'Quack',
    sheep = 'Baa',
    bee = 'Buzz',
    frog = 'Croak',
    bat = 'Screech',
    elk = 'Bugle',
    swan = 'Cry',
    pig = 'Oink'
}
print(
    Args[1] == 'fox' and 'What does the fox say' or (
        Sounds[Args[1]] and Args[1] .. ' goes "' .. Sounds[Args[1]] .. '"' or Args[1]
    )
)

I tried to make the logic a little clearer by putting it on multiple lines.
It's essentially a ternary operator ?:

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

AWK, 32 - 15 = 17

/^[c]at$/{$0=$0" goes 'Meow'"}1

I think this counts as not using "cat". Could have saved a couple bytes if "cat" were allowed to be anywhere in the line.

For giggles I also put together one with more animals, but it's not competitive, especially with trying to capture the correct verb to use, but here's what I came up with :)

{for(;I<split("ca""t,Meow,bees,Buzz,bird,Song,cow,Moo,crow,Caw,dog,Woof,duck,Quack,frogs,Croak,hog,Oink,ox,Low,pig,Oink,sheep,Baa,swan,Cry",a,",");)
m[a[I-1]="'"a[I+=2]"'"}
m[$0]{$0=$0($0~/s$/?" go ":" goes ")m[$0]}
/^fox$/{$0="What does the fox say"}
1
\$\endgroup\$
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
    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\$

Your Answer

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