모든 모음이 포함 된 단어 찾기


28

프로그램은 이 단어 목록 에서 모든 모음 ( a e i o u y) 이 포함 된 모든 단어 를 찾아야합니다 . 이 작업을 수행하는 쉬운 방법이 있지만 가장 짧은 답변을 찾고 있습니다. 나는 어떤 언어라도 취할 것이지만 배쉬를보고 싶다.

다음은 예입니다 (훨씬 개선 될 수 있음).

cat wordlist.txt | grep "a" | grep "e" | grep "i" | grep "o" | grep "u" | grep "y"

당신의 점수는 코드의 길이입니다.

단어의 모든 발생을 계산하기 위해 -5 포인트.

최저 점수가 이깁니다.


11
그러한 프로필. 많은 사진. 매우 총독. 와우.
Doorknob

2
17 답변과 계산! cg, doc에서 더 많은 질문을하고 싶습니다. 종종 여기서 흥미로운 것을 보게 되겠지만, 알맞은 솔루션을 만드는 데 몇 시간의 시간이 필요하지 않습니다.
Cary Swoveland

2
예, 그러나 모음을 찾는 데 사용되는 언어 일 수는 없습니다.
TheDoctor

1
@TheDoctor 동요 주먹
Jason C

2
보너스가 있으면 코드 골프가 아닙니다. 대신 코드 도전을 사용하십시오.

답변:


7

GolfScript, 20 자-5 = 15 점

n%{'aeiouy'\-!},.,+`

Howard의 솔루션을 기반으로 하지만 짧은 테스트 ( \-!한 문자 이상 저장 &,6=), 짧은 길이 추가 ( .,+= 3 문자) 및 짧은 출력 형식 (출력을 줄 바꿈으로 구분해야한다고 말한 사람은 없으므로 `한 문자를 절약합니다)n* ).

소문자 단어 목록을 입력으로 제공 한 결과는 다음과 같습니다 (가독성을 위해 삽입 된 줄 바꿈).

["abstemiously" "authoritatively" "behaviourally" "consequentially" "counterrevolutionary"
"disadvantageously" "educationally" "encouragingly" "eukaryotic" "evolutionarily"
"evolutionary" "exclusionary" "facetiously" "gregariously" "heterosexuality" "homosexuality"
"importunately" "inconsequentially" "instantaneously" "insurrectionary" "intravenously"
"manoeuvrability" "neurologically" "neurotically" "ostentatiously" "pertinaciously"
"precariously" "precautionary" "questionably" "revolutionary" "simultaneously"
"supersonically" "tenaciously" "uncomplimentary" "uncontroversially" "unconventionally"
"undemocratically" "unemotionally" "unequivocally" "uninformatively" "unintentionally"
"unquestionably" "unrecognisably" 43]

(Ps. 기술적으로, 문제는 코드 가이 특정 입력에 대해 작동해야한다고 말하면 n%{'aeiouy'\-!},`43아직 한 문자가 더 짧을 것입니다.하지만 부정 행위를 고려합니다.)


설명:

  • n% 개행의 입력을 배열로 분할합니다.
  • { }, "grep"연산자로, 배열의 각 요소에 대한 중괄호 사이에 코드를 실행하고 실제 값을 반환하는 중괄호를 선택합니다.
    • 루프 내에서 'aeiouy'\-리터럴 문자열을 가져와 aeiouy후보 단어에서 찾은 모든 문자를 제거합니다. 그런 !다음 결과 문자열을 논리적으로 무효화하고 1문자열이 비어 있으면 (true), 그렇지 않으면 0(false)를 생성합니다.
  • .,+ 필터링 된 배열의 복사본을 만들고 그 안에있는 단어 수를 세고 결과를 원래 배열에 추가합니다.
  • 마지막으로 `배열의 평가를 해제하여 배열을 내용의 문자열 표현으로 변환합니다. (이것이 없으면 배열의 단어는 단순히 출력에 연결되어 읽을 수없는 혼란을 야기합니다.)

Congrats!! smallest answer!!!!
TheDoctor

abstemiously and facetiously are the only word with all 6 vowels in order. Just thought I'd share that with you. I found it cool.
dberm22

15

GolfScript, 19 characters

n%{'aeiouy'&,6=},n*

Usage:

golfscript vowels.gs < wordlist.txt

Output:

abstemiously
authoritatively
behaviourally
[...]
uninformatively
unintentionally
unquestionably
unrecognisably

If you also want to output the count at the end you can use

n%{'aeiouy'&,6=},.n*n@,

which is four characters longer.


1
I like it! It may be 4 chars longer, but that gets you a -5 pt bonus
TheDoctor

11

Python - 46 characters

filter(lambda x:set(x)>=set("AEIOUY"),open(f))

Readable version: It's already pretty readable :-)


8

APL, 21 - 5 = 16

(,≢)w/⍨∧⌿'aeiouy'∘.∊w

Expects to find the list of words as w. Returns a list of the words that contain all the vowels, plus their count. Tested with ngn apl. Here's an example.

Explanation

         'aeiouy'∘.∊w   # generate a truth table for every vowel ∊ every word
       ∧⌿               # reduce with ∧ along the rows (vowels)
    w/⍨                 # select the words that contain all the vowels
(,≢)                    # hook: append to the list its own tally

8

Ruby 38

Edit 34: Best so far (from @O-I):

a.split.select{|w|'aeiouy'.count(w)>5} 

Edit 1: I just noticed the question asked for 'y' to be included among the vowels, so I've edited my question accordingly. As @Nik pointed out in a comment to his answer, "aeiouy".chars is one character less than %w[a e i o u y], but I'll leave the latter, for diversity, even though I'm risking nightmares over the opportunity foregone.

Edit 2: Thanks to @O-I for suggesting the improvement:

s.split.select{|w|'aeiouy'.delete(w)==''}

which saves 11 characters from what I had before.

Edit 3 and 3a: @O-I has knock off a few more:

s.split.select{|w|'aeiouy'.tr(w,'')==''}

then

s.split.reject{|w|'aeiouy'.tr(w,'')[1]}

and again (3b):

a.split.select{|w|'aeiouy'.count(w)>5} 

I am a mere scribe!

Here are two more uncompettive solutions:

s.split.group_by{|w|'aeiouy'.delete(w)}['']       (43)
s.gsub(/(.+)\n/){|w|'aeiouy'.delete(w)==''?w:''} (48)

Initially I had:

s.split.select{|w|(w.chars&%w[a e i o u y]).size==6}

s is a string containing the words, separated by newlines. An array of words from s that contains all five vowels is returned. For readers unfamiliar with Ruby, %w[a e i o u y] #=> ["a", "e", "i", "o", "u", "y"] and & is array intersection.

Suppose

s = "abbreviations\nabduction\n"
s.split #=> ["abbreviations", "abduction"] 

In the block {...}, initially

w             #=> "abbreviations"
w.chars       #=> ["a", "b", "b", "r", "e", "v", "i", "a", "t", "i", "o", "n", "s"]
w.chars & %w[a e i o u y] #=> ["a", "e", "i", "o"]
(w.chars & %w[a e i o u y]).size == 6 #=> (4 == 6) => false,

so "abbreviations" is not selected.

If the string s may contain duplicates, s.split.select... can be replaced by s.split.uniq.select... to remove duplicates.

Just noticed I could save 1 char by replacing size==6 with size>5.


1
...size=5 is a bug - should be ...size==5
Uri Agassi

Thanks, @Uri, for pointing out the typo in the first line, which I've fixed (not a bug--see line above 'so "abbreviations" is not selected').
Cary Swoveland

@CarySwoveland You can save yourself 11 characters by doing this: s.split.select{|w|'aeiouy'.delete(w)==''}
O-I

That's great, @O-I. I've done an edit and found a place that in the grey cells.
Cary Swoveland

@CarySwoveland This will save 1 more character: s.split.select{|w|'aeiouy'.tr(w,'')==''}. I'm pretty sure you can get this under 40 characters if you use nil logic and the 'right' String method. Still looking...
O-I

6

Haskell - 67

main=interact$unlines.filter(and.flip map "aeiouy".flip elem).lines

2
This is code-golf , you should try to make the code shorter, for instance, by removing whitespace...
mniip

6

Ruby - 28 characters (or 27 if y is excluded from vowels)

("ieaouy".chars-s.chars)==[]

The complete command to run is (48 chars):

ruby -nle 'p $_ if ("ieaouy".chars-$_.chars)==[]'

EDIT: replaced puts with p as suggested by @CarySwoveland


Nice one, @Nik. %w[a e i o u] would save 1 char, p for puts, 3 more.
Cary Swoveland

Thanx, @CarySwoveland! I forgot about p, i rarely use it. As for %w[], if y is included in the set of vowels, the version with chars is still shorter.
Nik O'Lai

@NikO'Lai "aeiouy".delete(s)=='' might save you a few characters.
O-I

Very nice! Post it as ur own solution, @O-I. I will upvote it
Nik O'Lai

4

AWK - 29

/a/&&/e/&&/i/&&/o/&&/u/&&/y/

To run: Save the lowercase word list to wordlist.txt. Then, do:

mawk "/a/&&/e/&&/i/&&/o/&&/u/&&/y/" wordlist.txt

If your system does not have mawk, awk can be used as well.

You can also run it from a file by saving the program to program.awk and doing mawk or awk -f program.awk.


Choosing right order accelerate the job: '/y/&&/u/&&/i/&&/o/&&/a/&&/e/' !!
F. Hauri

4

Python, 45 characters

[w for w in open(f) if set('aeiouy')<=set(w)]

3

k [22-5=17 chars]

I have renamed the file "corncob_lowercase.txt" to "w"

Count the words [22 chars]

+/min'"aeiouy"in/:0:`w

Output

43

Find all words [25 chars]

x@&min'"aeiouy"in/:x:0:`w

Overall 43 words containing all the vowels (a e i o u y)

Output

"abstemiously"
"authoritatively"
"behaviourally"
..
..
"unintentionally"
"unquestionably"
"unrecognisably"

3

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.


Might be interested in search() instead of indexOf() saves 1 char.
Gaurang Tandon

Further, As far as I can see, in your shortest version, you do not need the .split() on "aeiouy". JS loops over an array and string in the same way. (Removing it saves you ~10 chars)
Gaurang Tandon

2

Ruby 39 38

Currently the shortest Ruby entry when counting the whole program including input and output.

Saved a char by using map instead of each:

$<.map{|w|w*5=~/a.*e.*i.*o.*u/m&&p(w)}

Another version, 39 characters with prettier output:

puts$<.select{|w|w*5=~/a.*e.*i.*o.*u/m}

Both programs take input from stdin or as a file name passed as a command line argument:
$ ruby wovels.rb wordlist.txt

It costs 3 extra characters to inclyde y as a wovel.


Anyway to use Enumerable#grep to shorten this? e.g., s.split.grep /a*e*i*o*u*y/ assuming s is a string of the words separated by newlines.
O-I

@O-I An interesting idea, but it would need some fiddling because the regex has the wovels in a fixed order. That's why i repeat the string 5 times before matching it, with .* between the wovels.
daniero

Could you clarify? Suppose s = "aeiouy\neiouay\nyuaioe\n". Then s.split.grep /a*e*i*o*u*y/ returns ["aeiouy", "eiouay", "yuaioe"] for me. Testing in pry Ruby 2.0.0. Great solution, by the way.
O-I

@O-I Oh wow, I assumed that grep used the =~ operator, but apparently it uses ===. My suspicion was that it would also match strings not containing all wovels, because for instance /e*a*i*o*u*y/=~"eioy" works. I really don't understand what the === between a regex and an operator actually does. Great find; I'd suggest you post it as an answer yourself. edit I was right: try with for instance "heya".
daniero

I think you are right that the regex needs tweaking, though. I'm finding edge cases that don't contain all vowels that are leaking through. Maybe too good to be true.
O-I

2

Mathematica (65 or 314)

Two very different approaches, the better one was proposed by Belisarius in the comments to my initial response. First, my brutish effort, which algorithmically generates every possible regular expression that matches a combination of six vowels (including "y"), and then checks every word in the target wordlist against every one of these 720 regular expressions. It works, but it's not very concise and it's slow.

b = Permutations[{"a", "e", "i", "o", "u","y"}]; Table[
 Select[StringSplit[
  URLFetch["http://www.mieliestronk.com/corncob_lowercase.txt"]], 
  StringMatchQ[#, (___ ~~ b[[i]][[1]] ~~ ___ ~~ 
      b[[i]][[2]] ~~ ___ ~~ b[[i]][[3]] ~~ ___ ~~ 
      b[[i]][[4]] ~~ ___ ~~ b[[i]][[5]]~~ ___ ~~ b[[i]][[6]] ~~ ___)] &], {i, 1, 
  Length[b]}]

~320 characters. A few could be saved through using alternate notation, and additional characters are lost preparing the dictionary file as a list of strings (the natural format for the dictionary in Mathematica. Other languages may not need this prep, but Mathematica does). If we omit that step, presuming it to have been handled for us, the same approach can be done in under 250 characters, and if we use Mathematica's built-in dictionary, we get even bigger savings,

Map[DictionaryLookup[(___ ~~ #[[1]] ~~ ___ ~~ #[[2]] ~~ ___ ~~ #[[3]] 
~~ ___ ~~ #[[4]] ~~ ___ ~~ #[[5]]~~ ___ ~~ #[[6]] ~~ ___) .., IgnoreCase -> True] &, 
 Permutations[{"a", "e", "i", "o", "u","y"}]]

Under 200 characters. Counting the number of words found requires only passing the result to Length[Flatten[]], which can be added around either block of code above, or can be done afterwards with, for example, Length@Flatten@%. The wordlist specified for this challenge gives 43 matches, and the Mathematica dictionary gives 64 (and is much quicker). Each dictionary has matching words not in the other. Mathematica finds "unprofessionally," for example, which is not in the shared list, and the shared list finds "eukaryotic," which is not in Mathematica's dictionary.

Belisarius proposed a vastly better solution. Assuming the wordlist has already been prepared and assigned to the variable l, he defines a single test based on Mathematica's StringFreeQ[] function, then applies this test to the word list using the Pick[] function. 65 characters, and it's about 400 times faster than my approach.

f@u_ := And @@ (! StringFreeQ[u, #] & /@ Characters@"aeiouy"); Pick[l,f /@ l]

In 65 chars: f@u_:=And@@(!StringFreeQ[u,#]&/@Characters@"aeiouy");Pick[l,f/@l] Where lis the words list
Dr. belisarius

That's because you forgot to consider the yas a vowel (as per the OP requirements!)
Dr. belisarius

@belisarius yep, I notice that after making my comment. I'm checking my results with that fixed.
Michael Stern

@belisarius confirmed -- your solution is much more concise and quicker than mine. Why don't you post it as its own solution? I'll up vote it.
Michael Stern

Thanks! If you like it, edit your answer including it. For me it's all about finding short solutions with the language, not accumulating rep:)
Dr. belisarius

2

Perl 6 - 35 characters

Inspired by @CarySwoveland 's Ruby solution:

say grep <a e i o u y>⊆*.comb,lines

This selects (greps) each line that returns True for <a e i o u y> ⊆ *.comb, which is just a fancy way of asking "is the Set ('a','e','i','o','u','y') a subset () of the Set made up of the letters of the input (*.comb)?"

Actually, both <a e i o u y> and *.comb only create Lists: (or (<=) if you're stuck in ASCII) turns them into Sets for you.

To get the number of lines printed, this 42 character - 5 = 37 point script will output that as well:

say +lines.grep(<a e i o u y>⊆*.comb)».say

2

C - 96 bytes

 char*gets(),*i,j[42];main(p){while(p=0,i=gets(j)){while(*i)p|=1<<*i++-96;~p&35684898||puts(j);}}

I saved several bytes of parentheses thanks to a fortunate coincidence of operator precedence.


2

Javascript - Score = 124 - 5 = 119 !!!

Edit: 17/02/14

function(l){z=[],l=l.split("\n"),t=0;while(r=l[t++]){o=0;for(i in k="aeiouy")o+=!~r.search(k[i]);if(o==0)z.push(r)}return z}

Big thanks to @Ismael Miguel for helping me cut off ~12 chars!

I removed the fat arrow notation function form because though I have seen it begin used, it doesn't work. No idea why...


To make it work:

Pass all the words separated by newline as an argument to the function as shown below.


Test:

// string is "facetiously\nabstemiously\nhello\nauthoritatively\nbye"

var answer = (function(l){z=[],l=l.split("\n"),t=0;while(r=l[t++]){o=0;for(i in k="aeiouy")o+=!~r.search(k[i]);if(o==0)z.push(r)}return z})("facetiously\nabstemiously\nhello\nauthoritatively\nbye")

console.log(answer);
console.log(answer.length);

/* output ->    
    ["facetiously", "abstemiously", "authoritatively"]
    3 // count
*/


Syntax error at line 1: expected expression, got '>' c=(s,j)=>{k="aeiouy".split("
Ismael Miguel

1
You can reduce if by moving k="aeiouy".split("") to be inside the for(i in k) loop. Using ; instead of new lines saves some bytes in Windows. And yet, I don't see how it will handle a list of words. And how to make it work.
Ismael Miguel

@IsmaelMiguel I know it (fat arrow notation) does not work. But since I had seen it being used here so I used it because it saves chars. But I removed it. And I do not understand your tip, thanks though for examining code. Incorporated your bytes tip. And my new program should might clear your both doubts. Thanks for reading. :)
Gaurang Tandon

Instead of k="aeiouy";o=0;for(i in k), try o=0;for(i in k='aeiouy'). and using the saves bytes, you can use them to change o+=RegExp(k[i]).test(s) into o+=RegExp(k[i],'i').test(s), taking up one more byte, but working with both upper and lowercase.
Ismael Miguel

Updated with better algorithm. Though I now understand your idea, but I do not understand why it works here and not here. Please help! Thanks :)
Gaurang Tandon

2

Bash + coreutils, 39

eval cat`printf "|grep %s" a e i o u y`

Takes input from stdin.


This looks eligible for the 5-point bonus.
Glenn Randers-Pehrson

@GlennRanders-Pehrson That bonus makes no sense to me at all ;-)
Digital Trauma

Whether it makes sense or not, you correctly emit 86 lines when processing a file containing two copies of the wordlist. Solutions that sort and only report 43 would not get the bonus, as I understand it.
Glenn Randers-Pehrson

2

sed 29 chars

/y/{/u/{/o/{/i/{/a/{/e/p}}}}}

Order choosed from Letter frequency on wikipedia to speed check.

On my host:

time sed -ne '/a/{/e/{/i/{/o/{/u/{/y/p}}}}}' </usr/share/dict/american-english >/dev/null 
real    0m0.046s

and

time sed -ne '/y/{/u/{/i/{/o/{/a/{/e/p}}}}}'</usr/share/dict/american-english >/dev/null 
real    0m0.030s

1
Nice (+1), but I think you need to include "sed -n " in the script, for a count of 36 bytes.
Glenn Randers-Pehrson

2

Bash (grep) - 36 bytes

g=grep;$g y|$g u|$g o|$g i|$g a|$g e

Note the order of vowels tested, least frequent first. For the test case, this runs about 3 times as fast as testing in order a e i o u y. That way the first test removes a larger number of words so subsequent tests have less work to do. Obviously this has no effect on the length of the code. Many of the other solutions posted here would benefit similarly from doing the tests in this order.


Why wc, aren't we finding, not counting? Also, do we count input code into character count?
orion

I don't really understand the bonus, "-5 points for counting all occurrences of the word". If it really means "reporting all occurrences of the word", that's what my scripts do, without the "|wc". I'm not using any "input code" because grep reads standard input, so "grep" is the "input code" and I counted it. I'll remove the "|wc" now.
Glenn Randers-Pehrson

I've disclaimed the bonus.
Glenn Randers-Pehrson

1

D - 196

import std.regex,std.stream;void main(string[]a){auto f=new File(a[1]);while(!f.eof)if(!(a[0]=f.readLine.idup).match("(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)(?=.*y).*").empty)std.stdio.writeln(a[0]);}

Un-golfed:

import std.regex, std.stream;

void main( string[] a )
{
    auto f = new File( a[1] );

    while( !f.eof )
        if( !( a[0] = f.readLine.idup ).match( "(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)(?=.*y).*" ).empty )
            std.stdio.writeln( a[0] );
}

Usage: C:\>rdmd vowels.d wordlist.txt

wordlist.txt must contain the lowercase list words.


1

Rebol (104 chars)

remove-each w d: read/lines %wordlist.txt[6 != length? collect[foreach n"aeiouy"[if find w n[keep n]]]]

Un-golfed:

remove-each w d: read/lines %wordlist.txt [
    6 != length? collect [foreach n "aeiouy" [if find w n [keep n]]]
]

d now contains list of found words. Here is an example from Rebol console:

>> ; paste in golf line.  This (REMOVE-EACH) returns the numbers of words removed from list

>> remove-each w d: read/lines %wordlist.txt[6 != length? collect[foreach n"aeiouy"[if find w n[keep n]]]]
== 58067

>> length? d
== 43

1

Smalltalk (36/57 chars)

'corncob_lowercase.txt' asFilename contents select:[:w | w includesAll:'aeiouy']

to get the count, send #size to the resulting collection. The result collection contains 43 words ('abstemiously' 'authoritatively' ... 'unquestionably' 'unrecognisably')

The code above has 77 chars, but I could have renamed the wordlist file to 'w', so I count the filename as 1 which gives a score of 57.

Is reading the file part of the problem or not? If not (see other examples), and the list of words is already in a collection c, then the code reduces to:

c select:[:w | w includesAll:'aeiouy']

which is 36 chars (with omittable whitespace removed).


1

updated: unnecessary spaces removed

Very slow but in bash (81 chars):

while read l;do [ `fold -w1<<<$l|sort -u|tr -dc ieaouy|wc -m` = 6 ]&&echo $l;done

EDIT: echo $l|fold -w1 replaced with fold -w1<<<$l as suggested by @nyuszika7h


This is code golf, you might want to minify your code a bit more. Start by removing unneeded whitespace. ;)
nyuszika7h

You can further minify the code by using fold -w1<<<$l instead of echo $l|fold -w1. Note: The current code is 84 characters, you shouldn't count the trailing newline.
nyuszika7h

Till today I knew nothing about <<<. Thank you again, @nyuszika7h. Can you tell me, where it is explained.
Nik O'Lai


1

JavaScript - 95 bytes

Here's my golf.

function f(s){return[var a=s.match(/^(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)(?=.*y).*/),a.length];}

And I would also like to point out that your golf doesn't seem to find all occurrences of vowels.

Ungolfed:

function countVowels(string) {
  var regex   = /^(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)(?=.*y).*/;
  var matches = string.match(regex);
  var length  = matches.length;
  return [matches, length];

1
Read the spec more carefully. He's looking for words which---like facetiously---contain all the vowels in a single word. Though he does not insist that they are contained in order as in facetiously.
dmckee

1
Your regex is wrong. All the look-ahead are effectively checking whether the first character is a vowel. You need (?=.*a) to check whether a is somewhere in the string.
n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

@dmckee That's why I used lookaheads. They don't require any specific order.
Isiah Meadows

@nhahtdh Thanks for the catch
Isiah Meadows

1

sort + uniq + sed

This one does not match repeated occurrences of a word. It also does not match the letter 'y' if is occurs at the beginning of a word.

sort wordlist.txt | uniq | sed -n '/a/p' | sed -n '/e/p' | sed -n '/i/p' | sed -n '/o/p' | sed -n '/u/p' | sed -nr '/^[^y]+y/p' 

As in your other answer, replace "sort wordlist.txt | uniq" with "sort -u wordlist.txt" to save 4 bytes.
Glenn Randers-Pehrson

1

Bash

Not as short as the OP's , but one line in Bash:

while read p; do if [ $(sed 's/[^aeiouy]//g' <<< $p | fold -w1 | sort | uniq | wc -l) -eq 6 ] ; then echo $p; fi; done < wordlist.txt

You could save four bytes by replacing "sort | uniq" with "sort -u"
Glenn Randers-Pehrson

Also you can remove the spaces from " | " and "; " to save a few more bytes
Glenn Randers-Pehrson

1

C# - 170

using System.Linq;class P{static void Main(string[]a){System.Console.Write(string.Join(",",System.IO.File.ReadAllLines(a[0]).Where(w=>"aeiouy".All(c=>w.Contains(c)))));}}

Formatted:

using System.Linq;
class P
{
    static void Main(string[] a) { 
        System.Console.Write(
            string.Join(",", System.IO.File.ReadAllLines(a[0])
                .Where(w => "aeiouy".All(c => w.Contains(c))))); 
    }
}

Not in the mood right now to implement counting puh but should be easy. The path to the (lower-case version of the) wordlist should be passed to the program as first argument:

program.exe D:\foo\bar\corncob_lowercase.txt

Output:

abstemiously,authoritatively,behaviourally,consequentially,counterrevolutionary,
disadvantageously,educationally,encouragingly,eukaryotic,evolutionarily,evolutio
nary,exclusionary,facetiously,gregariously,heterosexuality,homosexuality,importu
nately,inconsequentially,instantaneously,insurrectionary,intravenously,manoeuvra
bility,neurologically,neurotically,ostentatiously,pertinaciously,precariously,pr
ecautionary,questionably,revolutionary,simultaneously,supersonically,tenaciously
,uncomplimentary,uncontroversially,unconventionally,undemocratically,unemotional
ly,unequivocally,uninformatively,unintentionally,unquestionably,unrecognisably

I took the liberty of outputting and comma-separating the words; neither of which is specified in the rules (which state "must find all the words", not how (and IF) to output).

Including count (+output): 192 - 5 = 187

using System.Linq;class P{static void Main(string[]a){var r=System.IO.File.ReadAllLines(a[0]).Where(w=>"aeiouy".All(c=>w.Contains(c)));System.Console.Write(string.Join(",",r)+" "+r.Count());}}

Output:

abstemiously,authoritatively,behaviourally,consequentially,counterrevolutionary,
disadvantageously,educationally,encouragingly,eukaryotic,evolutionarily,evolutio
nary,exclusionary,facetiously,gregariously,heterosexuality,homosexuality,importu
nately,inconsequentially,instantaneously,insurrectionary,intravenously,manoeuvra
bility,neurologically,neurotically,ostentatiously,pertinaciously,precariously,pr
ecautionary,questionably,revolutionary,simultaneously,supersonically,tenaciously
,uncomplimentary,uncontroversially,unconventionally,undemocratically,unemotional
ly,unequivocally,uninformatively,unintentionally,unquestionably,unrecognisably 4
3

(Note the count at the end: 43)

No output ("must find all the words"): 137 - 5 = 132

using System.Linq;class P{static void Main(string[]a){var r=System.IO.File.ReadAllLines(a[0]).Where(w=>"aeiouy".All(c=>w.Contains(c)));}}

(Bending the rules a bitm then again: not really) This finds all the words and the count is available by executing r.Count().


1

C-Sharp

I've never done this before and I'm not exactly sure what the posting procedures are. But this is what i came up with:

185 bytes

Action<string>x=(s=>s.Split('\n').ToList().ForEach(w=>{if("aeiouy".All(v=>w.Contains(v)))Console.Write(w);}));using(var s=new StreamReader(@"C:\corncob_lowercase.txt"))x(s.ReadToEnd());

wordList = a List<string> of all the words.

if you want to display a total:

219 - 5 = 214 bytes

Action<string>x=(s=>{var t=0;s.Split('\n').ToList().ForEach(w=>{if("aeiouy".All(v=>w.Contains(v))){Console.Write(w);t++;}});Console.Write(t);});using(var s=new StreamReader(@"C:\corncob_lowercase.txt"))x(s.ReadToEnd());


Expanded

// init
var words = "";
var vowels = "aeiouy";
var total = 0;

using (var stream = new StreamReader(@"C:\corncob_lowercase.txt"))
{
    // read file
    words = stream.ReadToEnd();

    // convert word to List<string>
    var wordList = words.Split('\n').ToList();

    // loop through each word in the list
    foreach (var word in wordList)

        // check if the current word contains all the vowels
        if(vowels.All (w => word.ToCharArray().Contains(w)))
        {
            // Count total
            total += 1;
            // Output word
            Console.Write(word);
        }

    // Display total
    Console.WriteLine(total);
}

Generally if the question asks for a "program", you should post your complete program including loading/initialization, etc. Great work otherwise!
ProgrammerDan

Oh ok. So in the minified version i should include everything not just the line that achieves the requirement? I thought it was the latter judging by other answers as they lacked the code to load/read the txt file.
jzm

You'll see a variation of approaches, and given the age of the answer curation is likely not to be as strong on new answers, but in general if the question asks for a "program" it should be compilable and runnable as posted. Take the example in the question itself -- that is a complete, executable solution, that stands alone.
ProgrammerDan

ahh right. well, in that case i've updated the 2 shortened versions to be standalone.
jzm

Great! Be sure to update the text of your answer (you mention "without loading/reading") and compute your score.
ProgrammerDan

1

vb.net (Score 91 = 96c - 5)*0

*0 +49c min

This creates an enumeration contain all of the words which contain all of the vowels.

Dim r=IO.File.ReadLines(a(0)).Where(Function(w)"aeiou".Intersect(w).Count=5)
Dim c=r.Count

Your program must find all the words in this wordlist. This is a) not a program but a snippet of a program and b) doesn't read/use the wordlist.
RobIII

@RobIII vb.net has a minimum 49c for a basic console program. The arguments to the program (in this case the wordlist) are the array a. Plus as some others have pointed out it is valid program in LinqPad.
Adam Speight

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.