Javascript/JScript 147(152-5), 158(163-5) or 184(189-5) bytes:
Here is my Javascript and JScript horribly "ungolfyfied" version (164 152 152-5=147 bytes):
function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=s[k].indexOf(c[z])>=0;i==6&&(r[r.length]=s[k]);}return r;}
function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=6;for(z in c)i-=!!s[k].search(c[z]);i&&(r[r.length]=s[k]);}return r;}
Thank you @GaurangTandon for the search()
function, which saved me a byte!
RegExp based with HORRIBLE performance, but support both upper and lowercase (163-5=158 bytes):
function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=RegExp(c[z],'i').test(s[k]);i==6&&(r[r.length]=s[k]);}return r;}
RegExp based with BETTER performance, BUT takes a lot more bytes (189-5=184 bytes):
function(s,k,z,x,i,c,r,l){l=[];r=[];for(z in c='aeiouy'.split(''))l[z]=RegExp(c[z],'i');for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=l[z].test(s[k]);i==6&&(r[r.length]=s[k]);}return r;}
This one if just for the fun (175-5 bytes) and won't count as an answer:
function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=s[k].indexOf(c[z])>=0;i==6&&(r[r[r.length]=s[k]]=1+(r[s[k]]||0));}return r;}
It's based on the 1st answer, but has a 'twist': You can know how many times a word has been found.
You simply do like this:
var b=(function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=s[k].indexOf(c[z])>=0;i==6&&(r[r[r.length]=s[k]]=1+(r[s[k]]||0));}return r;})('youaie youaie youaie youaie a word');
b.youaie //should be 4
Since that length
doesn't have all vowels, it wont be deleted and still would be an answer for the bonus.
How do you call it?
"Simple": You wrap the function inside ()
and then add ('string goes here');
to the end.
Like this:
(function(s,k,z,x,i,c,r){c='aeiouy'.split('');r=[];for(k in s=(s+'').split(/\b/)){i=0;for(z in c)i+=s[k].indexOf(c[z])>=0;i==6&&(r[r.length]=s[k]);}return r;})('a sentence youyoy iyiuyoui yoiuae oiue oiuea');
This example will return an array only with 1 string: yoiuae
I know that this is the worst solution, but works!
Why am i counting -5?
Well, Javascript/JScript arrays have a property (length
) in arrays which tells the number of elements that it have.
After being confirmed in the question, the bonus of -5 is for telling the number of words.
Since the number of words is in that property, automatically I have the score of -5.
11such profile. many picture. very doge. wow. – Doorknob – 2014-02-15T04:04:44.693
217 answers and counting! I'd like to see more questions like yours on cg, doc. Often I'll see something interesting here, but don't have the several hours of time needed to produce a decent solution... – Cary Swoveland – 2014-02-15T19:00:17.110
"-5 points for counting all occurrences of the word." --> what exactly does this mean? We have to give the number of times that the SAME word shown up or the number of words? – Ismael Miguel – 2014-02-15T20:06:48.630
If it were the second option, I would have to change all my scores. Just to be sure. – Ismael Miguel – 2014-02-15T20:16:01.677
@IsmaelMiguel - i mean count all the words it finds – TheDoctor – 2014-02-15T20:18:16.417
Then i have to fix all my scores. – Ismael Miguel – 2014-02-15T20:24:30.207
@TheDoctor You say your score is the "length of the code". Does that include the size of the interpreter for scripted languages? – Jason C – 2014-02-15T20:26:29.883
@JasonC - what do you mean by interpreter? do you mean the code calling your program? – TheDoctor – 2014-02-15T20:27:20.420
@TheDoctor You can write a short program in Perl but to execute it you need the Perl interpreter; thousands of lines of code with a few hundred kB binary. – Jason C – 2014-02-15T20:29:23.523
Ok, the interpreter doesn't count! – TheDoctor – 2014-02-15T20:30:30.230
@TheDoctor So, then technically I can invent my own language and write an interpreter for it and that doesn't count? – Jason C – 2014-02-15T20:31:06.123
2Yes, but it can't be a language dedicated to finding vowels. – TheDoctor – 2014-02-15T20:33:40.117
1@TheDoctor Shakes fist – Jason C – 2014-02-15T20:38:36.233
1
By the way, sort of related, for anybody that's never seen this: http://www.99-bottles-of-beer.net/ Code in 1500+ languages to print the 99 bottles of beer song.
– Jason C – 2014-02-15T20:40:34.8031@JasonC Check out
perldoc perlcompile
regarding how much the perl interpreter is needed. ;) – dannysauer – 2014-02-16T17:56:11.5072if it has a bonus, then it isn't code-golf. Use code-challenge instead. – Tim Seguine – 2014-02-24T19:51:16.007