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


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.

  • 7
    \$\begingroup\$ I'm not sure I understand the challenge. Is the input one or two words? Can you give some example input/output pairs? \$\endgroup\$
    – Zgarb
    Commented Dec 21, 2015 at 17:37
  • \$\begingroup\$ For the input 'cat', do the sum of the vowels equal to number of input vowels or the 'e's make up half and the 'o's make up half? \$\endgroup\$
    – Riker
    Commented Dec 21, 2015 at 17:37
  • \$\begingroup\$ And are the vowels directly copied, or would there just be more e/o's? For example: 'ceaaet' to 'ceaaets go meaaew' or 'ceaaets go meeoow'? \$\endgroup\$
    – Riker
    Commented Dec 21, 2015 at 17:40
  • 5
    \$\begingroup\$ You specify the number of e's and o's, but not their order. Is Meooeoew a valid output for Caaat, for example? \$\endgroup\$ Commented Dec 22, 2015 at 8:37
  • 1
    \$\begingroup\$ @PeterOlson No self-respecting kitty would ever say Meooeoew. That's trash talk! \$\endgroup\$
    – Sonic Atom
    Commented Jan 7, 2016 at 12:28

18 Answers 18


Retina, 57 49 44 43 41 bytes

So close... :) Pyth...

$0s go M$1$1

Try it online.

Expects input to be capitalised like Caaat or Coooow.


$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.


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):


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^^

  • \$\begingroup\$ I have no way of testing that, but if it works as you say then I'm well impressed! \$\endgroup\$
    – Sonic Atom
    Commented Dec 21, 2015 at 16:25
  • \$\begingroup\$ Can you give an explanation out of interest? \$\endgroup\$
    – Sonic Atom
    Commented Dec 21, 2015 at 16:25
  • \$\begingroup\$ explanation is up btw, dont hesitate to ask if there are any questions \$\endgroup\$
    – Eumel
    Commented Dec 21, 2015 at 18:14
  • \$\begingroup\$ Code-golfing like a boss. Wow. \$\endgroup\$
    – Jakuje
    Commented Dec 21, 2015 at 20:41

Pyth, 50 44 34

Takes input in the format ["caat", "coow"].

Pj.bs[rN3"s go M"S*-lN2+Y\o\w)Q"eo

Try it online.


  .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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – Jakube
    Commented Dec 21, 2015 at 16:48
  • \$\begingroup\$ 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. \$\endgroup\$
    – Jakube
    Commented Dec 21, 2015 at 17:02
  • \$\begingroup\$ Nice, thanks. I figured I could do something like that but didn't quite know how. \$\endgroup\$
    – Luke
    Commented Dec 21, 2015 at 18:00
  • \$\begingroup\$ This is very efficient. It should have more upvotes. \$\endgroup\$
    – Sonic Atom
    Commented Dec 21, 2015 at 18:09
  • 2
    \$\begingroup\$ Not again. \$\endgroup\$
    – AAM111
    Commented Dec 22, 2015 at 18:00

Perl, 66 61 55 54 bytes

includes +1 for -p

/[ao]+/;$\="s go M".$&=~y/a/e/r.o x($+[0]-1).(w)[/w/]

Input is expected to conform to /^C[ao]+[tw]$/ (no trailing newline!)
Usage: /bin/echo -n Caaat | perl -p 55.pl


$\= "s go M"        # assign to $OUTPUT_RECORD_SEPARATOR, normally `\n`. Saves 1 vs `$_.=`
   . $&             # 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=$&[email protected] x@l;$y=$x=~y/a/e/?w:'';s/$/s go M$x$y/


@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.
s/$/s go M$x$y/             # construct the desired output.

Example: Caaat

  • Capture $& as a and @l as (a,a,a).
  • 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

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

Online demo. Input is assumed to be in lower case.

For the same length:


s go M"N/_]"w

'CM"s go M"]2*q"ctw"-S/"teowoo"3/.{(2$,@*$}[MM"w

PowerShell, 135 132 bytes

"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

echo $p,' go M',str_repeat($s[0],$l),str_repeat($s[1],$l),$k?'w':'';
  • \$\begingroup\$ $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 \$\endgroup\$ Commented Dec 23, 2015 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" :""))}


func f(i:String)->String{
    var s = i.lowercaseString
    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:


  • 2
    \$\begingroup\$ How does this take input? \$\endgroup\$ Commented Dec 22, 2015 at 20:44
  • \$\begingroup\$ No input in this example, I made it for testing on playground, so no input on there, must use vars to test \$\endgroup\$ Commented Dec 22, 2015 at 21:07
  • 1
    \$\begingroup\$ I think that makes this a snippet then. It needs to be a function or full program to be valid. :/ \$\endgroup\$ Commented Dec 22, 2015 at 21:08
  • 1
    \$\begingroup\$ Ok, I made it a function.. \$\endgroup\$ Commented Dec 22, 2015 at 21:17

MATLAB: 190 152 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])


disp(['C',i(2:2+b+c),'s go M',i(2:1+b)+4,repmat('o',1,b+2*c),'w'*d])


Caaaaaaaats go Meeeeeeeeoooooooow

Cooooows go Moooooooooo

P.S.: Thanks to @Kenney for nice suggestion (see comments)!

  • \$\begingroup\$ Would disp( (b>0)*[...] + (c>0)*[...] ) work here? \$\endgroup\$
    – Kenney
    Commented Dec 22, 2015 at 14:44
  • \$\begingroup\$ Good suggestion @Kenney \$\endgroup\$
    – brainkz
    Commented Dec 23, 2015 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

  • \$\begingroup\$ Doesn't work on Caaat, output 'Caaats go Meoeoeow and must be 'Caaats go Meeeooow \$\endgroup\$ Commented Dec 23, 2015 at 16:47
  • \$\begingroup\$ @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." \$\endgroup\$
    – Pavlo
    Commented Dec 23, 2015 at 17:23
  • \$\begingroup\$ Well I guess you're right.. Funny meowing cats you have there :) \$\endgroup\$ Commented Dec 23, 2015 at 18:13

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)
  • \$\endgroup\$

    Ruby -nl, 64 bytes

    $_<<"s go M"+($2<?w??e*x+?o*x+?w:"oo"*x)

    Attempt This Online!


    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


    i=... .. " go M"
             (i:find"w"and o:rep(s*2) or 

    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: 115 92 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))
    • \$\begingroup\$ The input must be cat or cow not cats, cows. And doesn't capitalize. 'cats' output 'cats go Meow' should be 'Cats go Meow' \$\endgroup\$ Commented Dec 23, 2015 at 16:53
    • \$\begingroup\$ @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. \$\endgroup\$
      – CHlM3RA
      Commented Dec 24, 2015 at 7:57
    • \$\begingroup\$ Agree. input may use any capitalization, but output should always be capitalized as C[]ts go M[]w, isn't it? \$\endgroup\$ Commented Dec 24, 2015 at 15:17

    PHP, 170 164 161 157 bytes

    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
    v5: save 4 bytes by onelining it (not shown)

    • \$\begingroup\$ 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). \$\endgroup\$
      – Kenney
      Commented Dec 22, 2015 at 14:29

    Your Answer

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

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