# Cats go Meow, Cows go Moo

Everyone knows that cats go meow, but what many don't realise is that caaaats go meeeeoooow. In fact, the length of the vowel sounds that the cat makes are dependant on the length of the vowel with which you address it.

In the same way, cows go moo, but coooows go moooooooo

## Challenge

You are to write a program that takes as input, a word meaning cat, and a word meaning cow, determine the number of main vowels, and print one of the following strings, as appropriate:

• C[]ts go M[]w
• C[]ws go M[]

Where [] stands for the vowels, according to the following rules:

• The number of e's and o's in "Meow" must both match the number of vowels found in the input word.
• The number of o's in "Moo" must be double the number of vowels found in the input word.

The program must recognise the input words cat and cow. Input may use any capitalisation that is most convenient, but the output must be capitalised exactly as shown above.

• cue joke about a certain fox – Martin Ender Dec 21 '15 at 15:14
• I'm not sure I understand the challenge. Is the input one or two words? Can you give some example input/output pairs? – Zgarb Dec 21 '15 at 17:37
• @MartinBüttner I'm not sure if I know which fox are you talking about. Jog my memory, what does it say? – James Dec 21 '15 at 20:17
• You specify the number of e's and o's, but not their order. Is Meooeoew a valid output for Caaat, for example? – Peter Olson Dec 22 '15 at 8:37
• For fox sake stop with the puns! – Eumel Dec 22 '15 at 22:05

## Retina, 57494443 41 bytes

So close... :) Pyth...

.(.+).
$0s go M$1$1 +aa(\w*$)
e$1ow wo o  Try it online. Expects input to be capitalised like Caaat or Coooow. ### Explanation .(.+).$0s go M$1$1


The regex matches the entire input, and captures the vowels in group 1 (we don't need anchors, because the match cannot fail and will greedily match the entire input). The substitution writes back that input, and appends s go M, followed by twice the vowels. For inputs Caaat and Coooow, we get:

Caaats go Maaaaaa
Coooows go Moooooooo


The output for cows is already correct. We just need to do something about those cats.

+aa(\w*$) e$1ow


The + tells Retina to repeat this stage as often as possible. The regex matches two as in the last part of the string (we ensure this with the $ anchor, so that we don't replace things inside Caaats). This will essentially match everything after M, as long as that part still has as. The two as are removed and the entire suffix after it is wrapped in e...ow: Caaats go Meaaaaow Caaats go Meeaaowow Caaats go Meeeowowow  Finally, there are two many ws in the result, so we remove those that precede an o (to make sure we're not messing up the w in Coooows): wo o  And we're left with: Caaats go Meeeooow  # LabVIEW, 58 LabVIEW Primitives creating strings like this is a pain... The leftmost vis are pattern matching, a+ and o+ respectively search for the lagest amount of as and os in a row. Taking the lenght of those i create 3 arrays 1 with lenght os 1 with lenght es and one with 2 times lenght os. Then all the parts get put together. First the original input, then s go M all the Arrays, the unused one are empty so they will be ignored, and finally a w if the input was cats. (If as were found there will be a t after the match, if not after match is empty) For the lolz i also implemented the fox with 6 different outputs^^ • I have no way of testing that, but if it works as you say then I'm well impressed! – Sonic Atom Dec 21 '15 at 16:25 • Can you give an explanation out of interest? – Sonic Atom Dec 21 '15 at 16:25 • explanation is up btw, dont hesitate to ask if there are any questions – Eumel Dec 21 '15 at 18:14 • Code-golfing like a boss. Wow. – Jakuje Dec 21 '15 at 20:41 # Pyth, 5044 34 Takes input in the format ["caat", "coow"]. Pj.bs[rN3"s go M"S*-lN2+Y\o\w)Q"eo  Try it online. Explained:  .b Map a lambda across two lists in parallel: Q The input, e.g. ["caat", "coow"] "eo The string "eo" s[ ) Create and concatenate a list of: rN3 - The item N in title caps (e.g. "Caat") "s go M" - The string "s go M" S - The sorted version of: +Y\o The item Y + "o" ("eo" or "oo") *-lN2 Times the length of N - 2 (number of vowels) \w - The string "w" Pj Join the result on \n and drop the final "w"  Thanks to Jakube for major reductions in length. • Some little things: You can replace the first jk with s, remove the second jk (it doesn't do anything at all), and replace "w\n" with \wb. – Jakube Dec 21 '15 at 16:48 • Also, most of your code appears twice in your code, like r.Q3 and other stuff. You could use a binary_map and save 10 additional chars. Pj.bs[rN3"s go M"S*-lN2+Y\o\w)Q"eo. Not sure, if you already have experience with maps, if you have any questions I can explain it to you on the Pyth Chat. – Jakube Dec 21 '15 at 17:02 • Nice, thanks. I figured I could do something like that but didn't quite know how. – Luke Dec 21 '15 at 18:00 • This is very efficient. It should have more upvotes. – Sonic Atom Dec 21 '15 at 18:09 • Not again. – OldBunny2800 Dec 22 '15 at 18:00 # Perl, 666155 54 bytes includes +1 for -p /[ao]+/;$\="s go M".$&=~y/a/e/r.o x($+[0]-1).(w)[/w/]


. $& # the matched vowels =~ y/a/e/r # translate a to e; /r returns a copy. . o x($+[0]-1)   # append 'o', repeated. $+[0] is string position of last match end. . (w)[/w/] # returns 'w' if there is no /w/ in the input, nothing if there is.  ### Previous version: @l=/[ao]/g;$x=$&x@l.o x@l;$y=$x=~y/a/e/?w:'';s/$/s go M$x$y/


Commented:

@l = /[ao]/g;               # captures $& as vowel and @l as list of vowels$x = $& x @l .o x @l; # construct the output vowels$y = $x =~ y/a/e/ ? w : ''; # correct vowel string for cats (aaaooo->eeeooo);$y='w' if cat.
• Set $x to three times a followed by 3 times o: aaaooo. • Translate all a in $x to e: eeeooo. The number of replacements (either 0 or positive) serves as a cat-detector: set $y to w if so. • Change the input by appending s go M, eeeooo and w. • update 61: Save 5 bytes by using list instead of string • update 55: save 6 bytes by inlining, assigning $\ rather than s/$/, and requiring no trailing newline in input. • update 54: save 1 byte by eliminating @l. ## Python 2, 74 bytes i=input() l=len(i)-2 print i+'s go M'+['e'*l+'o'*l+'w','o'*l*2][i[-1]>'v']  Takes input Caaat or Cooow ## CJam (60 57 55 53 bytes) "C%s%ss go M%sw "2*-2<q"ctw"-S/"teowoo"3/.{(2$,@*$}e%  Online demo. Input is assumed to be in lower case. For the same length: "C s go M"N/_]"w "a*q"ctw"-S/"teowoo"3/.{(2$,@*$M}]z  'CM"s go M"]2*q"ctw"-S/"teowoo"3/.{(2$,@*$}[MM"w "]]z  ## PowerShell, 135 132 bytes param($a,$b) [char[]]"$a$b"|%{if($_-eq'a'){$c++}$d++}
$d-=4+$c
"C$("a"*$c)ts go M$("e"*$c)$("o"*$c)w"
"C$("o"*$d)ws go M$("o"*2*$d)"


(linebreaks count same as semicolons, so line-breaked for clarity)

Surprisingly tricky challenge. And I'm reasonably sure this can be golfed further.

Takes input strings as $a and $b. Concatenates them and casts them as a char-array, then pipes that through a loop %{}. Each letter is then checked if it's -equal to 'a' and the associated counter variable is incremented appropriately. We then subtract 4+$c from $d to account for catcw in the input, and proceed to formulate the output sentences, modifying the vowels output times the corresponding counters. (In PowerShell, 'e'*3 would yield 'eee', for example.)

Almost similar to @omulusnr's answer but this produces the correct output and also input is case insensitive.

## PHP, 172

$p=$argv[1];
preg_match("/c([ao]+)/i",$p,$e);
$l=strlen($e[1]);
$s=($k=strcmp($e[0][1],'o'))?'eo':'oo'; echo$p,' go M',str_repeat($s[0],$l),str_repeat($s[1],$l),$k?'w':'';  • $p=$argv[1];preg_match("/c([ao]+)/i",$p,$e);$l=strlen($e[1]);$s=$k=strcmp($e[0][1],'o')?'eo':'oo';$r='str_repeat';echo$p,' go M',$r($s[0],$l),$r($s[1],$l),$k?'w':''; a little bit shorter to 166 bytes – Tschallacka Dec 23 '15 at 13:32 ## Swift 2, 3̶8̶1̶ 333 bytes func f(i:String)->String{var s=i.lowercaseString;s.replaceRange(s.startIndex...s.startIndex,with:String(s[s.startIndex]).uppercaseString);let c=i.characters.count-2;let l=s.characters.last;return(s+"s go M"+String(count:c,repeatedValue:l=="t" ?"e" :"o" as Character)+String(count:c,repeatedValue:"o" as Character)+(l=="t" ?"w" :""))}  Ungolfed: func f(i:String)->String{ var s = i.lowercaseString s.replaceRange(s.startIndex...s.startIndex,with:String(s[s.startIndex]).uppercaseString) let c = i.characters.count-2 let l = s.characters.last return(s+"s go M"+String(count:c,repeatedValue:l=="t" ?"e" :"o" as Character)+String(count:c,repeatedValue:"o" as Character)+(l=="t" ?"w" :"")) }  Takes cat or cow any capitalization. You can try it here: http://swiftlang.ng.bluemix.net/#/repl/3f79a5335cb745bf0ba7698804ae5da166dcee6663f1de4b045e3b8fa7e48415 • How does this take input? – a spaghetto Dec 22 '15 at 20:44 • No input in this example, I made it for testing on playground, so no input on there, must use vars to test – Fidel Eduardo López Dec 22 '15 at 21:07 • I think that makes this a snippet then. It needs to be a function or full program to be valid. :/ – a spaghetto Dec 22 '15 at 21:08 • Ok, I made it a function.. – Fidel Eduardo López Dec 22 '15 at 21:17 ## MATLAB: 190152 118 bytes i=input('','s');b=sum(i=='a');c=sum(i=='o');d=b>c;disp(['C',i(2:2+b+c),'s go M',i(2:1+b)+4,repmat('o',1,b+2*c),'w'*d])  Ungolfed: i=input('','s'); b=sum(i=='a'); c=sum(i=='o'); d=b>c; disp(['C',i(2:2+b+c),'s go M',i(2:1+b)+4,repmat('o',1,b+2*c),'w'*d])  Tests: caaaaaaaats Caaaaaaaats go Meeeeeeeeoooooooow cooooows Cooooows go Moooooooooo  P.S.: Thanks to @Kenney for nice suggestion (see comments)! • Would disp( (b>0)*[...] + (c>0)*[...] ) work here? – Kenney Dec 22 '15 at 14:44 • Good suggestion @Kenney – brainkz Dec 23 '15 at 14:48 # PHP, 138 bytes echo ucfirst($a=$argv[1]).'s go M'.(($n=substr_count($a,'a'))?str_repeat('e',$n).str_repeat('o',$n).'w':str_repeat('oo',substr_count($a,'o')));


echo ucfirst($a =$argv[1]) . 's go M'. (
($n = substr_count($a, 'a'))
? str_repeat('e', $n) . str_repeat('o',$n) . 'w'
: str_repeat('oo', substr_count($a, 'o')) );  tried shorter but wont work in PHP: #too long -- echo ucfirst($s=$argv[1]).'s go M'.(($o='o'and$n=substr_count($s,'a'))?str_repeat('e',$n).str_repeat($o,$n).'w':str_repeat('oo',substr_count($s,$o))); #too long -- echo ucfirst($s=$argv[1]).'s go M'.(($o='o'and$f=function($s,$n){return str_repeat($s,$n);}and$n=substr_count($s,'a'))?$f('e',$n).$f($o,$n).'w':$f('oo',substr_count($s,$o)));  =) # OCTAVE, 126 , 108 First version with variables and explanation, 126: L="ao"';S={'eo','oo'},e={'w',' '};a=sum(argv(){1}==L,2);b=find(a);disp([argv(){1},' goes m',vec(ones(sum(a),1)*S{b})',e{b}]);  Explanation: L knows which animal contains which letter. S knows what they repeat. e knows the ending. You need to have "automatic broadcasting" turned on for this to work, but it should be by default in all Octaves I've used. Of course there exist shorter ways with for example command regexprep (regular expressions with replacement), but there has already been several such approaches in answers already, so that would be boring. Edit: Skipping variables which only occur once, using octave on-the-fly indexing (don't know what it's called for real) and adding "i", input string variable: i=argv(){1};a=sum(i=="ao"',2);b=find(a);disp([i,' goes m',vec(ones(sum(a),1)*{'eo','oo'}{b})',{'w',''}{b}]);  # JavaScript (ES2015), 78 77 s=>s+'s go M'+(l=s.length-1,w=s[l]<'u',Array(l).join(w?'eo':'oo')+(w?'w':''))  Try it here: https://jsbin.com/guqaxejiha/1/edit?js,console • Doesn't work on Caaat, output 'Caaats go Meoeoeow and must be 'Caaats go Meeeooow – Fidel Eduardo López Dec 23 '15 at 16:47 • @FidelEduardoLópez the challenge does not specify the order: "The number of e's and o's in "Meow" must both match the number of vowels found in the input word." – Pavlo Dec 23 '15 at 17:23 • Well I guess you're right.. Funny meowing cats you have there :) – Fidel Eduardo López Dec 23 '15 at 18:13 ## Lua, 121 90 Bytes 121 Bytes i=...r="M"o="o"s=i:len()-3if(i:find("w"))then r=r..o:rep(s*2)else r=r..("e"):rep(s)..o:rep(s).."w"end print(i.." go "..r)  90 bytes i=....." go M"o="o"s=#i-7 print(i..(i:find"w"and o:rep(s*2)or("e"):rep(s)..o:rep(s).."w"))  Takes input such as 'Caats' or 'Coooows' case-sensitive. Since there are no requirements for invalid inputs, the output might be weird for, say, 'Foxes' or 'Oxen'. :P Ungolfed i=... .. " go M" o="o" s=#i-7 print(i.. (i:find"w"and o:rep(s*2) or ("e"):rep(s)..o:rep(s).."w") )  Update to 90 Bytes: Replaced if-control structure with logical operators, optimized string concatenation by appending more data in declaration of i. Removed parenthesis on i:find("w"). Interestingly enough, storing "o" to a variable saved a couple bytes when using rep, but would be counterproductive with "w" or "e". The more you know. # Lua: 11592 89 Bytes i=...l=#i-2o="o"io.write(i,"s go M",i:find"a"and("e"):rep(l)..o:rep(l).."w"or o:rep(l*2))  takes C[]t or C[]w as input; [] = a's or o's. A lowecase input will translate to the result. long version: i=... --"C[]t" or "C[]w" l=#i-2 --length of input -2 o="o" --shorten usage of "o" io.write(i,"s go M",i:find"a"and("e"):rep(l)..o:rep(l).."w"or o:rep(l*2)) -- if it's a C"a"t concat "s go M" then repeat --> Cats/Cows go M -- "e" and then "o" l times and concat else --> Cats go Meo -- repeat "o" l*2 times and concat --> Cows go Moo -- concat "w" and output evrything --> Cats go Meow  Example outputs: Caaat --> Caaats go Meeeooow Cat --> Cats go Meow Cow --> Cows go Moo  Edit: changed if then else to and or. removed ALL the non string space's. Also you cat try it here: Execute Lua Online but I couldn't figure out how to use the terminal so I've put it in a function. Edit: changed usage of "o" and removed () from :find. credit goes to Cyv for finding those optimizations. Added "s" and changed l=#i-3 to l=#i-2 With input including "s" only 88 byte: i=...l=#i-3o="o"io.write(i," go M",i:find"a"and("e"):rep(l)..o:rep(l).."w"or o:rep(l*2))  • The input must be cat or cow not cats, cows. And doesn't capitalize. 'cats' output 'cats go Meow' should be 'Cats go Meow' – Fidel Eduardo López Dec 23 '15 at 16:53 • @FidelEduardoLópez I agree on the first not on the second. According to word meaning cat, and a word meaning cow Cats is allowed but not according to input words cat and cow. Input may use any capitalisation and cat or Cat should bolth be valid. – CHlM3RA Dec 24 '15 at 7:57 • Agree. input may use any capitalization, but output should always be capitalized as C[]ts go M[]w, isn't it? – Fidel Eduardo López Dec 24 '15 at 15:17 # Dart, 114 112 110 104 102 100 bytes f(s)=>s+'s go M'.padRight(s[1]=='a'?s.length+4:0,'e').padRight(2*s.length+2,'o')+(s[1]=='a'?'w':'');  Try it online! • -2 bytes : Changed the way the u offset is calculated to reduce the number of additions • -2 bytes : Moved the check on the first pasdding to the width and not the character • -6 bytes : Changed the Cow/Cat check • -2 bytes : Got rid of variable assignments • -2 bytes : Reduced then umber of parentesis on 2*(s.length+1) # PHP, 170164161 157 bytes preg_match("/(?i)c([ao]+)/",$argv[1],$e);$n=strlen($e[1]);$c=$e[1][0];$a=($c=="a"?("ew"):("o")); echo "M".str_repeat($a[0],$n).str_repeat("o",$n).$a[1]."\n";  Takes any capitalization whatsoever. CaAaT, coOOOw, whatever. v2: don't really need [wt]$. also corrected char ct
v3: char ct was all wrong, condensed $a and$e assignment
v4: save 3 bytes on $af->$a
• Didn't downvote, but the output is wrong: missing $argv[0]."s go ". Try this preg_match("/(?i)c([ao]+)/",$x=$argv[1],$e);$a=$e[1][0]=="a"?"ew":"o";echo$x."s go M".str_repeat($a[0],$n=strlen($e[1])).str_repeat("o",$n).$a[1]."\n"; (correct output and 151 bytes). – Kenney Dec 22 '15 at 14:29