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 code-golf, 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
foxwith "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>
-
20\$\begingroup\$ For the bonuses: What does the fox say? \$\endgroup\$Stewie Griffin– Stewie Griffin2015年11月01日 08:11:29 +00:00Commented 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\$user3094403– user30944032015年11月01日 09:06:10 +00:00Commented Nov 1, 2015 at 9:06
-
2\$\begingroup\$ Cats say meow.. \$\endgroup\$Addison Crump– Addison Crump2015年11月01日 11:37:41 +00:00Commented Nov 1, 2015 at 11:37
-
2\$\begingroup\$ Instead of double quotes, can you use single ones? Also, can you output to stderr? \$\endgroup\$Blue– Blue2015年11月01日 12:47:45 +00:00Commented Nov 1, 2015 at 12:47
-
5\$\begingroup\$ Why is there no link to this in this challenge? \$\endgroup\$Jan– Jan2015年11月01日 20:50:29 +00:00Commented Nov 1, 2015 at 20:50
70 Answers 70
Pyth, 231-255 = -24 bytes
-24*10 extra animals, -15 for no "cat" string
pzI}zJv.Z"xÚ]Arà E ̄âñMOÛ|°
Ø¢mÞ1⁄2`&ÉR ̄'_ãPÍm1;ñÝ|,F ×ばつz#1⁄2öÂ÷ÜAPúõMh#Ì©UOC *CѰk%1ö ́qÌzj,å<&{jàRFÖ(\s ñ`GÂ:çkô#ù\M+üqíéaw ×ばつ_r]¢:jkz»ÚFÙ¦ÈcÅËØíëûÖOa¿Þμ ́6 ø¡ãEþþ:"jk(" goes "N@JzN
Pseudocode
Auto assign z to input
print z
J = decompress animal-sound dict
if z in J:
print " goes ", J[z], '"'
Animals it knows:
{'hare': 'squeak', 'seal': 'bark', 'lion': 'growl', 'rook': 'hiss', 'sheep': 'baa', 'hamster': 'squeak', 'moose': 'bellow', 'grasshopper': 'chirp', 'rhinoceros': 'bellow', 'cat': 'meow', 'tiger': 'growl', 'stag': 'bellow', 'crow': 'caw', 'okapi': 'bellow', 'snake': 'hiss', 'cicada': 'chirp', 'badger': 'growl', 'dog': 'bark', 'cricket': 'chirp', 'tapir': 'squeak', 'bird': 'chirp', 'sparrow': 'chirp', 'lamb': 'baa', "frog": "croak", "raven": "croak"}
-
19\$\begingroup\$ I feel like the bonus should be -10%, not -10 bytes. That would give a diminishing return to prevent abuses like this. (And that's 10% multiplied each time, not 10% of original added up, otherwise you'd only need 10 animals to get a score of 0 no matter how long the code was...) \$\endgroup\$Darrel Hoffman– Darrel Hoffman2015年11月01日 14:26:51 +00:00Commented Nov 1, 2015 at 14:26
-
\$\begingroup\$ @DarrelHoffman I'll bear that in mind for all future challenges. \$\endgroup\$user46470– user464702015年11月01日 16:13:16 +00:00Commented Nov 1, 2015 at 16:13
-
1\$\begingroup\$ Well, you successfully made my head explode, and I no longer know what the fox says. +1 \$\endgroup\$kirbyfan64sos– kirbyfan64sos2015年11月05日 03:47:40 +00:00Commented Nov 5, 2015 at 3:47
-
\$\begingroup\$ The raven goes croak? \$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2016年11月28日 18:53:52 +00:00Commented Nov 28, 2016 at 18:53
-
\$\begingroup\$ @carusocomputing According to wikipedia it does. I think they go
squalkmyself \$\endgroup\$Blue– Blue2016年11月28日 19:53:39 +00:00Commented Nov 28, 2016 at 19:53
TeaScript, 29 - 15 = 14 bytes
Doesn't use string cat.
xr(/^c\at$/,'$& goes "Meow"')
"What does the fox say" (length = 21) is longer than the bonus is worth.
-
\$\begingroup\$ The fox bonus is now worth it! \$\endgroup\$user46470– user464702015年11月02日 15:43:51 +00:00Commented Nov 2, 2015 at 15:43
PXLCODE, 114 bytes
I SHOULD GET BONUS BECAUSE THIS IS CAT LANGUAGE RIGHT?
ALSO FEED ME BUTTER
HAI 1.3
I HAS A V
GIMMEH V
BOTH SAEM V AN "cat",O RLY?
YA RLY,VISIBLE "cat goes meow"
NO WAI,VISIBLE V
OIC
KTHXBYE
-
4\$\begingroup\$ Welcome to Code Go- wait a second \$\endgroup\$Ginger– Ginger2022年02月05日 18:41:41 +00:00Commented Feb 5, 2022 at 18:41
APOL, 34 bytes
p(¿(=(i "cat") "cat goes meow" ⋔))
BEEP BOOP I AM NOT A ROBOT
-
\$\begingroup\$ Once again, I posted this to get this account enough rep to chat. \$\endgroup\$Ginger– Ginger2022年10月05日 19:12:15 +00:00Commented Oct 5, 2022 at 19:12
CJam, 12 bytes
q_:)"dbu"=" goes \"Meow\""*
The program is 27 bytes bytes long and doesn't use the word cat (-15 bytes).
Try it inline in the CJam interpreter.
How it works
q_ e# Read all input and push a copy.
:) e# Increment all code points of the copy.
"dbu"= e# Push 1/0 if the result is/isn't "dbu".
" goes \"Meow\""* e# Repeat the string that many times.
-
12\$\begingroup\$ I like the smiley
:)\$\endgroup\$ETHproductions– ETHproductions2015年11月01日 16:41:47 +00:00Commented Nov 1, 2015 at 16:41
JavaScript, (削除) 45 - 15 = 30 (削除ここまで) / 264 - 235 = 29
alert((s=(d='MeowBuzzSongMooMooCawBarkQuackCroakHissOinkBaaSingRoarLowCooCawBarkBaaHissCryRoarSingC\x61tBeeBirdCattleCowCrowDogDuckFrogHorseHogLambLarkLionOxPigeonRookSealSheepSnakeSwanTigerWhale'.split(/(?=[A-Z])/))[d.indexOf(i=prompt())-23])?i+' goes "'+s+'"':i)
Downside: you have to write the name of the animal with the first letter in uppercase and the rest in lowercase. Look below for another version which fixes this. This version escapes the a in cat with \x61 and includes code for the 22 extra animals from this list (all the allowed animals which had short enough words to be worth it):
bee buzz 7
bird song 8
cattle moo 9
cow moo 6
crow caw 7
dog bark 7
duck quack 9
frog croak 9
horse hiss 9
hog oink 7
lamb baa 7
lark sing 8
lion roar 8
ox low 5
pigeon coo 9
rook caw 7
seal bark 8
sheep baa 8
snake hiss 9
swan cry 7
tiger roar 9
whale sing 9
(thanks to my friend for helping me with the tedious task of making this list)
Ungolfed code:
data = 'MeowBuzzSongMooMooCawBarkQuackCroakHissOinkBaaSingRoarLowCooCawBarkBaaHissCryRoarSingC\x61tBeeBirdCattleCowCrowDogDuckFrogHorseHogLambLarkLionOxPigeonRookSealSheepSnakeSwanTigerWhale'.split(/(?=[A-Z])/);
input = prompt();
index = data.indexOf(input);
sound = data[index-23];
result = sound ? input + ' goes "' + sound + '"' : input;
alert(result);
First version, 45 bytes - 15 bonus = 30
alert((i=prompt())=='\x63at'?i+' goes "Meow"':i)
Yes, I know. I went from 30 to 29 with ALL that extra work. It was fun!
Version that allows full lowercase input, 294 bytes - 235 bonus = 59
alert((s=(d='MeowBuzzSongMooMooCawBarkQuackCroakHissOinkBaaSingRoarLowCooCawBarkBaaHissCryRoarSingC\x61tBeeBirdCattleCowCrowDogDuckFrogHorseHogLambLarkLionOxPigeonRookSealSheepSnakeSwanTigerWhale'.split(/(?=[A-Z])/))[d.indexOf((i=prompt())[0].toUpperCase()+i.slice(1))-23])?i+' goes "'+s+'"':i)
I also tried removing casing from the data array with .join().toLowerCase().split(',') but it ended up taking 297 characters instead.
-
\$\begingroup\$ edit: fixed quote marks and capital on meow (although the question isn't consistent with capitals) \$\endgroup\$Domino– Domino2015年11月05日 00:57:56 +00:00Commented Nov 5, 2015 at 0:57
-
\$\begingroup\$ And... my work here is done, proving that the -10 bonus was just enough :) \$\endgroup\$Domino– Domino2015年11月05日 01:46:13 +00:00Commented Nov 5, 2015 at 1:46
APL (Dyalog), 28 - 15 = 13 bytes
{⍵,' goes "Meow"'/⍨⍵≡⌽'tac'}
Input followed by goes "Meow" if input is equivalent to tac reversed.
{...} anonymous function
⌽'tac' reverse the string (to get the -15 bonus by avoiding the characters cat)
⍵≡ Boolean for whether the argument is identical to that
' goes "Meow"'/⍨ use that to filter the string (i.e. returns empty string if false)
⍵, append to the argument
JavaScript, (削除) 81 -ひく 20 -ひく 15 =わ 46 bytes (削除ここまで) 50 - 15 = 35 bytes
(o=prompt()=="ca"+"t")&&o+=' goes "Meow"';alert(o)
-
\$\begingroup\$ You can drop the double-quotes around Meow. \$\endgroup\$anotherdave– anotherdave2015年11月02日 16:10:03 +00:00Commented Nov 2, 2015 at 16:10
-
\$\begingroup\$ no, that's actually part of the question \$\endgroup\$Domino– Domino2015年11月05日 00:56:33 +00:00Commented Nov 5, 2015 at 0:56
-
1\$\begingroup\$ How about
'c\at'instead of'ca'+'t'? \$\endgroup\$Gustavo Rodrigues– Gustavo Rodrigues2015年11月10日 17:46:48 +00:00Commented Nov 10, 2015 at 17:46 -
1\$\begingroup\$
alert({'c\at':'c\at goes "Meow"',fox:'What does the fox say'}[a=prompt()]||a). Why not even drop the alert? It already returns the result to console. \$\endgroup\$Gustavo Rodrigues– Gustavo Rodrigues2015年11月10日 17:58:18 +00:00Commented Nov 10, 2015 at 17:58
Python 3, (削除) 81 (削除ここまで) (削除) 70 (削除ここまで) (削除) 55 (削除ここまで) 46 - 15 = 31 bytes
Thanks to Stewie Griffin for saving 15 bytes
Thanks to grc for saving 8 bytes.
Not using the string cat gives -15 bytes.
y=input()
print(y+' goes "Meow"'*(y=="ca""t"))
LOLCODE, (削除) 100 (削除ここまで) 109 Bytes
HAI 1
I HAS A I
GIMMEH I
BOTH SAEM I "cat",O RLY?
YA RLY,VISIBLE "cat goes Meow"
NO WAI,VISIBLE I
OIC
KTHXBYE
My first post on this platform, as well as my first code-golf challenge and my first code in LOLCODE, so there's probably lots to improve. I tried avoiding the "cat" with casting the equivalent hex-code ":(63):(61):(74)" instead, but it didn't work out for me. If you know a solution to this, please let me know!
*+9 Bytes because I didn't read the instructions clear enough
-
1\$\begingroup\$ Welcome to CGCC! Your TIO link appears to be blank, though the code itself looks valid \$\endgroup\$Jo King– Jo King2019年12月12日 23:32:30 +00:00Commented Dec 12, 2019 at 23:32
-
1\$\begingroup\$ Thanks for pointing that out @JoKing I fixed the link, it should include the code now. \$\endgroup\$Signus– Signus2019年12月13日 06:44:42 +00:00Commented Dec 13, 2019 at 6:44
-
1\$\begingroup\$ the code turns "cat" into "Meow", but it should instead turn it into "cat goes Meow". Still nice code though! \$\endgroup\$Belhenix– Belhenix2019年12月13日 17:41:06 +00:00Commented Dec 13, 2019 at 17:41
-
\$\begingroup\$ Thanks @Belhenix. I fixed it for the price of adding 9 bytes. Sadly the use of a variable for "cat" would've turned out to be 5 bytes longer, so I chose to stick with the uglier code. \$\endgroup\$Signus– Signus2019年12月17日 07:16:58 +00:00Commented Dec 17, 2019 at 7:16
Pyke, 391 -595 = -204 bytes
-58*10 extra animals, -15 for no "cat" string
"goes"Q.dt偮晪ꅢὐ𑈶ὥ𑈶墵𑈶셞𑈶᳙ᄷ쟿䁔漲ᬰ䵙ꄨ塋튖თ鮔૪爟マッハ爟巾]勒〥鴞⬻䋥ュ⣹邦㺓𒀽堚퀦잓號漲ქ︆𐊷䦙ᔯ漲ᠥ쏔っ鮔𐩁牔鶇Ƒ䂝雥⬻⯎偮燩巺䯥𒀽봽鮔튖➒ᨼ䄇嚕㮷鮏𐓧ᘽ挳ᖘ漲𒀽睴윿꒲⬻𦼎鼤㨂ᘽdc2cY@]3J
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'}
-
\$\begingroup\$ Why is this marked as noncompetitive? \$\endgroup\$thejonymyster– thejonymyster2022年10月06日 15:48:14 +00:00Commented Oct 6, 2022 at 15:48
-
\$\begingroup\$ At the time of writing, there was a rule where languages older than the question were non-competing \$\endgroup\$Blue– Blue2022年10月08日 15:02:30 +00:00Commented Oct 8, 2022 at 15:02
-
\$\begingroup\$ languages older than the question? or languages newer than the question? because im pretty sure it was the latter :P either way, you can take off the noncompetitive mark, site has new standards :-) \$\endgroup\$thejonymyster– thejonymyster2022年10月08日 18:04:47 +00:00Commented Oct 8, 2022 at 18:04
GNU sed, 37 - 15 = 22 bytes
sed -r 's/^(\x63at)$/1円 goes "Meow"/'
-
\$\begingroup\$ sed '/^c[a]t$/s/$/ goes "Meow"/' saves a few bytes. But the new 5% bonus is worthless compared to the original 15 byte bonus for not having "cat". \$\endgroup\$Glenn Randers-Pehrson– Glenn Randers-Pehrson2015年11月02日 15:03:09 +00:00Commented Nov 2, 2015 at 15:03
-
\$\begingroup\$ @GlennRanders-Pehrson Not any more! \$\endgroup\$user46470– user464702015年11月02日 15:45:42 +00:00Commented Nov 2, 2015 at 15:45
MATLAB, 58 - 15 = 43 bytes
Pretty straight forward, with bonus for not using cat in the code:
x=input('');if isequal(x,'dbu'-1);x=[x ' goes "Meow"'];end;x
Input must be given inside single quotes: ' '.
-
\$\begingroup\$ In its current form, this doesn't output correctly if 'cat' is given as input. You probably forgot x= within the if-statement. \$\endgroup\$slvrbld– slvrbld2015年11月05日 16:23:52 +00:00Commented Nov 5, 2015 at 16:23
-
\$\begingroup\$ But I'll also give you a tip to win back these bytes plus an additional 2: replace your entire if-statement by: if~any(x-'dbu'+1) \$\endgroup\$slvrbld– slvrbld2015年11月05日 16:32:56 +00:00Commented Nov 5, 2015 at 16:32
-
\$\begingroup\$ @slvrbld, thanks for noticing, it happened after I made an edit. BTW: your suggestion doesn't work for inputs that aren't 3 characters. =) \$\endgroup\$Stewie Griffin– Stewie Griffin2015年11月06日 15:53:31 +00:00Commented Nov 6, 2015 at 15:53
-
\$\begingroup\$ Ah, you're correct. I was too focused on the cat and fox and forgot about the rest. \$\endgroup\$slvrbld– slvrbld2015年11月09日 08:13:29 +00:00Commented Nov 9, 2015 at 8:13
Javascript, 117 bytes
for(c=0,s="bee.Buzz.bird.Song.c\at.Meow.cow.Moo.crow.Caw.dog.Bark.oxen.Low.owl.Who.rook.Caw.sheep.Baa.swan.Cry".split('.'),p=prompt(),a=![];c<s.length;c+=2){if(p==s[c])a=c}if(!a)alert(p=='fox'?'What does the fox say':p);else alert(s[a]+' goes "'+s[a+1]+'"')
I definitely haven't won here, but I've covered a lot of extra animals.
Javascript, 31 bytes
p=prompt();alert(p=='c\at'?p+' goes "Meow"':p)
HALT, 71 - 15 = 56 bytes
1 IF "cat" 2 ELSE 3
2 TYPE "MEOW";HALT
3 SET 0;NEXT
4 INCREMENT;STORE 0
HALT is a language I (@Downgoat) made designed for string processing, the only problem is that it's a bit long
Formatted
1 IF "cat" 2 ELSE 3
2 TYPE "MEOW"; HALT
3 SET 0 ; GOTO 6
4 INCREMENT ; STORE 0
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());
}
-
\$\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– Noodle92015年11月02日 06:33:01 +00:00Commented Nov 2, 2015 at 6:33
-
\$\begingroup\$ @user, As I said, I still hope author revises bonuses. \$\endgroup\$Zereges– Zereges2015年11月02日 09:01:30 +00:00Commented 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
usingis no big deal, the initializer list is. \$\endgroup\$Karl Napf– Karl Napf2016年11月28日 14:23:53 +00:00Commented Nov 28, 2016 at 14:23 -
\$\begingroup\$ @KarlNapf Thanks for pointing that out. \$\endgroup\$Zereges– Zereges2016年11月28日 17:07:55 +00:00Commented 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#importthrows some warnings but is accepted be GCC and MSVC \$\endgroup\$Karl Napf– Karl Napf2016年11月28日 17:11:29 +00:00Commented Nov 28, 2016 at 17:11
Python, (削除) 62 (削除ここまで) (削除) 58 (削除ここまで) 48 - 15 = (削除) 48 (削除ここまで) (削除) 44 (削除ここまで) 33 bytes
Thanks to Unrelated String for -10 bytes!
x=input()
print(x,*['goes "Meow"'][:"c""at"==x])
0x61 = a.
Try it online!
Revision 3: with cat without cat
Revision 2: with cat without cat
Revision 1: with cat without cat
-
\$\begingroup\$ The first
catis there \$\endgroup\$l4m2– l4m22022年02月05日 18:10:51 +00:00Commented Feb 5, 2022 at 18:10 -
\$\begingroup\$ @l4m2 Sorry, that will be fixed. \$\endgroup\$Oliver– Oliver2022年02月05日 18:12:40 +00:00Commented Feb 5, 2022 at 18:12
-
1
-
\$\begingroup\$ -2 by spinning the comparison around and using adjacent string literal concatenation over an escape sequence. Or, all the way down to 48. \$\endgroup\$Unrelated String– Unrelated String2022年02月05日 20:20:38 +00:00Commented Feb 5, 2022 at 20:20
JavaScript, 48 - 15 = 33 bytes
Uses \x61 as a substitute for the a in cat.
i=prompt();alert(i=="c\x61t"?i+' goes "Meow"':i)
Perl, 46 - 15 = 31
$_=join'',<>;s/(?<=^ca)t$/t goes "Meow"/;print
Ruby, (削除) 49 (削除ここまで) (削除) 46 (削除ここまで) 50 - 15 = 35 bytes
Pretty straight-forward I guess. Not using cat.
$<.map{|l|puts l==?c+'at
'??c+'at goes "Meow"':l}
Edit: Thanks for @w0lf for saving 3 bytes!
-
\$\begingroup\$ apparently there's no need for
chop: ideone.com/lTpShD \$\endgroup\$Cristian Lupascu– Cristian Lupascu2015年11月01日 09:36:52 +00:00Commented Nov 1, 2015 at 9:36 -
\$\begingroup\$ @w0lf "cat\n" != "cat" (At least it doesn't work for me) I'm guessing that ideone's STDIN doesn't have a trailing newline \$\endgroup\$Peter Lenkefi– Peter Lenkefi2015年11月01日 09:38:16 +00:00Commented Nov 1, 2015 at 9:38
-
\$\begingroup\$ Fair enough, I see where my example was wrong. Then your could consider doing this to shorten the code. \$\endgroup\$Cristian Lupascu– Cristian Lupascu2015年11月01日 09:41:22 +00:00Commented Nov 1, 2015 at 9:41
-
\$\begingroup\$ @PeterLenkefi, there are still a few cats left in your code... Did you forget to update it or...? \$\endgroup\$Stewie Griffin– Stewie Griffin2015年11月01日 13:03:58 +00:00Commented Nov 1, 2015 at 13:03
-
\$\begingroup\$ @StewieGriffin Damn it I did! My multitasking is not on top today. However in 5 mins I'll update it again. \$\endgroup\$Peter Lenkefi– Peter Lenkefi2015年11月01日 13:18:45 +00:00Commented Nov 1, 2015 at 13:18
PHP, 1204 - (10 * 64) - 15 - 20 = 529 bytes
<?php $i = $argv[1];$s = json_decode(gzuncompress(hex2bin("78da555351b2db200cbc8a27dfee057a1b192bc018104f40dcbccebb7b25d9499d8fcc588b10abddcddf1b64e4e8a04c3bd1eac86db7df3774e136dfa0744c5451805688bb400bac1e5900cfb42703ba1e3bc6e3ce82dabe8cef6f2d22af52b910b95ad93b72d173a22c8083f4d0f63bc75c131aa2e332d2ae45886e43ed7769082f438afc52027df46b20182af457b83c24537ad2c199484b99f6fe669dd9afcd6cc70ef67972a03bb8c10915abb12aa995bc7206deac48555818a9e80ea46cf8142020fe0aa0ccd761327e0db00e046f745426d0c531610d22af609d47aea8dade91d998ad447aebcef6aef0b32d7d64b8df4ddd84a0173c436b816a35475efbf8110bc254a3bf6a1420b76e7d1788f1a346ceb14f8e61b98c0bc44ddb0a46afe284582b55ea9087e1af2004236b3999278a452726c8cb8bef3c2d0086b14ad362f1f3b4032fe67b8aa59cae88742744aab26ccff3f47a2583af11ad0f344c0a1119910553b2d864929562270577b14a87d10635ea351a3e0895572ffd11f0f8ac0867fadf36898668249c65a732448e387de481c1c96931272598863c8ed09ec6b17020874c5792ac1e5bea8ee234c7c238df1a42faff449360552b55c05660d3d5426c4dcb0a7c26f874ac75f0d7a7da0e079da7145d74f848418fc71f5a75d652947a4e1edd469715fae023e29e96c3b0c748027e847a87c4ef4cc893820438722f666bc9a6cb69facf3f28e87499")));echo array_key_exists($i,$s)?"$i goes {$s->$i}":($i=="fox"?"What does the $i say":$i);
I use a json encoded gz compressed array of animal sounds. This means it works with all 65 allowed animals, but my script is huge. Also works with fox and doesn't have the word cat in it.
MATLAB, 46 bytes
regexprep(input(''),'^cat$','cat goes "Meow"')
Admittedly trivial. The input must be given in single quotes.
-
\$\begingroup\$ I'm not sure, but I think
ans = ..is generally not accepted, if the challenge is to print something. I'm not sure if it's a consensus, but it's quite common to usedispor something similar. \$\endgroup\$Stewie Griffin– Stewie Griffin2015年11月02日 15:01:07 +00:00Commented Nov 2, 2015 at 15:01
Beam, (削除) 208 (削除ここまで) 206 - 15 = 191 bytes
Not a competitive entry, but a bit of fun to do. It checks the first for letters of the input against cat. If it gets a mismatch it will shortcut to the standard cat program. If it matches it will append goes "Meow"
'''''''''>`\/n@>`)'''>`++\
/++++++++++/r /SP''+(++++/
\+)'PSrn@--S/ \rn@`>`)rn'''''>`++++++)++@P'p++++@'p-----@`p++@'p-@``p@++@'''''>`+++++++++)--@'p++@'p-----@++++++++@``p++@H
/@< (`< < `< ''<
>ruH
Java = 222 bytes (compressed)
public class A {public static void main(String[] args) {Scanner a=new Scanner(System.in);for(;;){String b=a.nextLine();if(!b.equalsIgnoreCase("cat"))System.out.println(b);else {System.out.println("meow");System.exit(0);}}}
Or I could decompress it.
Batch = 52 bytes
set /p k=
if "k"=="cat" (echo cat) ELSE (echo %k%)
Javascript: 48 Characters, 48 Bytes
function(s){return (s=="cat")?"cat goes meow":s}
Test
=>"Dog"
<="Dog"
=>"cat"
<="cat goes meow"
-
\$\begingroup\$ Good work! You could drop the parentheses around
s=="cat". Also, the cat's string is supposed to becat goes "Meow", so'function(s){return s=="cat"?'cat goes "Meow"':s}is completely valid. \$\endgroup\$ETHproductions– ETHproductions2015年11月08日 20:53:00 +00:00Commented Nov 8, 2015 at 20:53 -
\$\begingroup\$ If you wanted to save even more, you could use ES6:
s=>s=="cat"?s+' goes "Meow"':s(30 bytes) \$\endgroup\$ETHproductions– ETHproductions2015年11月08日 20:54:30 +00:00Commented Nov 8, 2015 at 20:54 -
\$\begingroup\$ @ETHproductions OOooh, that's good! I don't know that kind of syntax though, a link perhaps? \$\endgroup\$Fuzzyzilla– Fuzzyzilla2015年11月08日 23:41:11 +00:00Commented Nov 8, 2015 at 23:41
-
\$\begingroup\$ @Fuzzyzilla it's part of a new version of JavaScript called "ES6", link to the new function syntax and overview. Here are also tips for ES6 and tips for JavaScript in general \$\endgroup\$Downgoat– Downgoat2015年11月09日 00:22:35 +00:00Commented Nov 9, 2015 at 0:22
Haskell, 52-15 = 37 bytes
c"99円at"="99円at goes \"Meow\""
c s=s
main=interact c
Using 99円 as a substitute for c in "cat" so as to get the 15 bytes bonus.
Prolog, 48 bytes
p:-read(X),write(X),X=cat,write(' goes "Meow"').
Attempts to bring more animals to the party made the program longer even with bonuses.
ESMin, 23 - 15 = 8 chars / 58 - 15 = 43 bytes
ïċɘ㴃탵ɣK㐀攁退胦ްおр夁䰰ᷗȿ 쨀#
The byte to char ratio is real.