Cats go Meow, Cows go Moo

40

5

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.

Sonic Atom

Posted 2015-12-21T15:09:57.390

Reputation: 501

42cue joke about a certain fox – Martin Ender – 2015-12-21T15:14:31.170

7I'm not sure I understand the challenge. Is the input one or two words? Can you give some example input/output pairs? – Zgarb – 2015-12-21T17:37:52.873

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? – Rɪᴋᴇʀ – 2015-12-21T17:37:53.047

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'? – Rɪᴋᴇʀ – 2015-12-21T17:40:10.113

31@MartinBüttner I'm not sure if I know which fox are you talking about. Jog my memory, what does it say? – James – 2015-12-21T20:17:55.513

2Long caaaaaaaat is long. – MikeTheLiar – 2015-12-21T20:49:16.570

4You specify the number of e's and o's, but not their order. Is Meooeoew a valid output for Caaat, for example? – Peter Olson – 2015-12-22T08:37:25.750

@DJMcMayhem I had to join just to upvote that comment... :) – A.P. – 2015-12-22T18:15:25.247

10For fox sake stop with the puns! – Eumel – 2015-12-22T22:05:11.687

@A.P. Same here – PNDA – 2015-12-23T08:11:47.667

1@PeterOlson No self-respecting kitty would ever say Meooeoew. That's trash talk! – Sonic Atom – 2016-01-07T12:28:48.017

Answers

17

Retina, 57 49 44 43 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

Martin Ender

Posted 2015-12-21T15:09:57.390

Reputation: 184 808

11

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

Eumel

Posted 2015-12-21T15:09:57.390

Reputation: 2 487

I have no way of testing that, but if it works as you say then I'm well impressed! – Sonic Atom – 2015-12-21T16:25:20.630

Can you give an explanation out of interest? – Sonic Atom – 2015-12-21T16:25:56.043

explanation is up btw, dont hesitate to ask if there are any questions – Eumel – 2015-12-21T18:14:43.863

Code-golfing like a boss. Wow. – Jakuje – 2015-12-21T20:41:46.807

7

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.

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.

Luke

Posted 2015-12-21T15:09:57.390

Reputation: 5 091

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 – 2015-12-21T16:48:40.363

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 – 2015-12-21T17:02:14.153

Nice, thanks. I figured I could do something like that but didn't quite know how. – Luke – 2015-12-21T18:00:58.157

This is very efficient. It should have more upvotes. – Sonic Atom – 2015-12-21T18:09:00.450

2Not again. – OldBunny2800 – 2015-12-22T18:00:52.767

5

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

Breakdown

/[ao]+/;
$\= "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=$&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.
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.

Kenney

Posted 2015-12-21T15:09:57.390

Reputation: 946

4

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

TFeld

Posted 2015-12-21T15:09:57.390

Reputation: 19 246

2

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

Peter Taylor

Posted 2015-12-21T15:09:57.390

Reputation: 41 901

1

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

AdmBorkBork

Posted 2015-12-21T15:09:57.390

Reputation: 41 581

1

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

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

brainkz

Posted 2015-12-21T15:09:57.390

Reputation: 349

Would disp( (b>0)*[...] + (c>0)*[...] ) work here? – Kenney – 2015-12-22T14:44:05.830

Good suggestion @Kenney – brainkz – 2015-12-23T14:48:15.580

1

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':'';

blackpla9ue

Posted 2015-12-21T15:09:57.390

Reputation: 111

$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 – 2015-12-23T13:32:36.397

1

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}]);

mathreadler

Posted 2015-12-21T15:09:57.390

Reputation: 141

1

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

Fidel Eduardo López

Posted 2015-12-21T15:09:57.390

Reputation: 111

2How does this take input? – a spaghetto – 2015-12-22T20:44:32.240

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 – 2015-12-22T21:07:29.020

1I think that makes this a snippet then. It needs to be a function or full program to be valid. :/ – a spaghetto – 2015-12-22T21:08:49.627

1Ok, I made it a function.. – Fidel Eduardo López – 2015-12-22T21:17:46.433

1

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

Pavlo

Posted 2015-12-21T15:09:57.390

Reputation: 127

Doesn't work on Caaat, output 'Caaats go Meoeoeow and must be 'Caaats go Meeeooow – Fidel Eduardo López – 2015-12-23T16:47:17.147

@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 – 2015-12-23T17:23:28.803

Well I guess you're right.. Funny meowing cats you have there :) – Fidel Eduardo López – 2015-12-23T18:13:10.187

1

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')));

readable:

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

=)

cottton

Posted 2015-12-21T15:09:57.390

Reputation: 111

0

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)
  • Elcan

    Posted 2015-12-21T15:09:57.390

    Reputation: 913

    0

    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.

    Cyv

    Posted 2015-12-21T15:09:57.390

    Reputation: 211

    0

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

    CHlM3RA

    Posted 2015-12-21T15:09:57.390

    Reputation: 21

    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 – 2015-12-23T16:53:13.613

    @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 – 2015-12-24T07:57:46.080

    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 – 2015-12-24T15:17:24.327

    -1

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

    romulusnr

    Posted 2015-12-21T15:09:57.390

    Reputation: 1

    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 – 2015-12-22T14:29:47.713