| Bytes | Lang | Time | Link |
|---|---|---|---|
| 074 | Creating a list of every fiveletter combination from "babab" to "zyzyz" in pure Bash can be done using nested loops and ASCII character manipulation. Here's how you can achieve this in a 74character Bash script | 240716T013736Z | Roshini |
| nan | 240716T013427Z | Roshini | |
| nan | Python 3.8 prerelease | 240716T003953Z | squarero |
| 091 | R | 240706T210817Z | int 21h |
| 082 | Regenerate a | 240122T171739Z | DLosc |
| 040 | Perl 5 | 240122T154801Z | Xcali |
| 054 | Zsh P | 240121T192228Z | pxeger |
| 4035 | K ngn/k | 230807T034307Z | doug |
| 085 | Python 2 | 170112T221103Z | xnor |
| 080 | JavaScript Node.js | 230807T042254Z | l4m2 |
| 057 | Curry PAKCS | 230807T034258Z | alephalp |
| 008 | Vyxal | 230807T025950Z | emanresu |
| 117 | C gcc | 180119T142039Z | gastropn |
| 224 | ink | 190904T220518Z | Sara J |
| 064 | Shell | 190901T225411Z | user9289 |
| 058 | Zsh | 190902T061409Z | GammaFun |
| 010 | Jelly | 190810T195840Z | Erik the |
| 016 | MathGolf | 190808T095048Z | maxb |
| 011 | Brachylog v2 | 190808T072811Z | Unrelate |
| 033 | J | 190807T054425Z | Jonah |
| 082 | JavaScript Firefox 3057 | 170112T195405Z | Neil |
| 098 | R | 170113T171929Z | rturnbul |
| 254 | InformixSQL | 170116T041611Z | CompuLin |
| 347 | Java | 170115T115613Z | yeoman |
| 047 | Perl | 170112T124143Z | primo |
| 132 | R | 170114T020615Z | Patrick |
| 276 | TSQL | 170113T165930Z | Muqo |
| 086 | Scala | 170112T201213Z | jaxad012 |
| 080 | PHP | 170112T134556Z | Titus |
| 219 | C# | 170113T113429Z | Mr Scape |
| 163 | C | 170113T102235Z | dim |
| 185 | Batch | 170113T130955Z | Neil |
| 053 | Perl 6 | 170113T105534Z | Maniacs |
| 052 | Ruby | 170112T135326Z | G B |
| 054 | Perl | 170112T130049Z | smls |
| 117 | Python 2 | 170112T155852Z | ElPedro |
| 051 | Stacked | 170113T041954Z | Conor O& |
| 051 | Haskell | 170112T151312Z | nimi |
| 023 | Pyth | 170112T222450Z | busukxua |
| 090 | JavaScript ES6 | 170112T123913Z | Patrick |
| 361 | C | 170112T134427Z | Abel Tom |
| 028 | CJam | 170112T145749Z | Business |
| 074 | Pure Bash | 170112T164006Z | Digital |
| 094 | Python 2 | 170112T124233Z | Rod |
| 061 | Ruby | 170112T144213Z | G B |
| 110 | Python 3 | 170112T152019Z | Carra |
| 101 | Clojure | 170112T141439Z | NikoNyrh |
| 070 | Perl 6 | 170112T131439Z | smls |
| 016 | 05AB1E | 170112T123302Z | Emigna |
| 095 | Befunge | 170112T124830Z | James Ho |
| 018 | Brachylog | 170112T124814Z | Fatalize |
| 061 | Mathematica | 170112T121635Z | Martin E |
| 093 | Haskell | 170112T124245Z | Renzeee |
| 071 | Perl | 170112T124224Z | Dada |
| 021 | MATL | 170112T123330Z | Luis Men |
Creating a list of every five-letter combination from "babab" to "zyzyz" in pure Bash can be done using nested loops and ASCII character manipulation. Here's how you can achieve this in a 74-character Bash script:
for i in {b..z}{a..z}{a..z}{a..z}{a..z}; do echo $i; done
This script uses a nested brace expansion to iterate through all combinations of letters from 'babab' to 'zyzyz' and prints each combination.
If you need further details or have any additional questions, feel free to ask!
- Heading
babab, babac, babad, babae, babaf, babag, babah, babai, babaj, babak, babal, babam, baban, babao, babap, babaq, babar, babas, babat, babau, babav, babaw, babax, babay, babaz, babba, babbb, babbc, babbd, babbe, babbf, babbg, babbh, babbi, babbj, babbk, babbl, babbm, babbn, babbo, babbp, babbq, babbr, babbs, babbt, babbu, babbv, babbw, babbx, babby, babbz, babca, babcb, babcc, babcd, babce, babcf, babcg, babch, babci, babcj, babck, babcl, babcm, babcn, babco, babcp, babcq, babcr, babcs, babct, babcu, babcv, babcw, babcx, babcy, babcz, babda, babdb, babdc, babdd, babde, babdf, babdg, babdh, babdi, babdj, babdk, babdl, babdm, babdn, babdo, babdp, babdq, babdr, babds, babdt, babdu, babdv, babdw, babdx, babdy, babdz, babea, babeb, babec, babed, babee, babef, babeg, babeh, babei, babej, babek, babel, babem, baben, babeo, babep, babeq, baber, babes, babet, babeu, babeh, babeg, babee, babef, babej, babek, babeq, baber, babes, babet, babeu, babev, babew, babex, babey, babez, babfa, babfb, babfc, babfd, babfe, babff, babfg, babfh, babfi, babfj, babfk, babfl, babfm, babfn, babfo, babfp, babfq, babfr, babfs, babft, babfu, babfv, babfw, babfx, babfy, babfz, babga, babgb, babgc, babgd, babge, babgf, babgg, babgh, babgi, babgj, babgk, babgl, babgm, babgn, babgo, babgp, babgq, babgr, babgs, babgt, babgu, babgv, babgw, babgx, babgy, babgz, babha, babhb, babhc, babhd, babhe, babhf, babhg, babhh, babhi, babhj, babhk, babhl, babhm, babhn, babho, babhp, babhq, babhr, babhs, babht, babhu, babhv, babhw, babhx, babhy, babhz, babia, babib, babic, babid, babie, babif, babig, babih, babii, babij, babik, babil, babim, babin, babio, babip, babiq, babir, babis, babit, babiu, babiv, babiw, babix, babiy, babiz, babja, babjb, babjc, babjd, babje, babjf, babjg, babjh, babji, babjj, babjk, babjl, babjm, babjn, babjo, babjp, babjq, babjr, babjs, babjt, babju, babjv, babjw, babjx, babjy, babjz, babka, babkb, babkc, babkd, babke, babkf, babkg, babkh, babki, babkj, babkk, babkl, babkm, babkn, babko, babkp, babkq, babkr, babks, babkt, babku, babkv, babkw, babkx
Python 3.8 (pre-release), 111 (101?) bytes
f=lambda c:c and[a+b for a in f(c-1)for b in["aeiouy","bcdfghjklmnpqrstvwxz"][c%2]]or['']
print(*f(5),sep='\n')
If formatting isn't required, 10 bytes can be shaved off:
f=lambda c:c and[a+b for a in f(c-1)for b in["aeiouy","bcdfghjklmnpqrstvwxz"][c%2]]or['']
print(f(5))
R, 95 91 bytes
- the construction of the vowels sequence has been borrowed from an unpublished 86 bytes solution by J.Doe, available as a comment to this post.
- -4 bytes thanks to pajonk
L=letters
y=L[v<-0:5*5+c(1:-1,0)];x=L[-v]
`*`=\(a,b)outer(a,b,paste0)
t(t(sort(x*y*x*y*x)))
Despite that this amazing question has already two answers in R, I am sharing my answer too. It is based on outer function. Here it is used recursively 4 times. Instead of multiplication, the characters are pasted together resulting in every possible combination of characters \$x+y+x+y+x\$ as a 5-dimensional array with dimensions 20 x 6 x 20 x 6 x 20 and 288000 elements inside. The array is sorted and flattened at the same time, then transposed two times. This converts the 5d-array to a single column matrix, as per challenge requirements.
Regenerate -a, 82 bytes
[bcdfghjklmnpqrstvwxz][aeiouy][bcdfghjklmnpqrstvwxz][aeiouy][bcdfghjklmnpqrstvwxz]
Unfortunately, there's no clever way to do this in Regenerate--just gotta list all the options.
K (ngn/k), 40 35 bytes
+x@'!#'x:1_5^[`c$97+!26;]\"aeiouy"
-5 : clever shuffling from @ngn. Constant alphabet, alternating set differences.
Python 2, 85 bytes
W='BCDFGHJKLMNPQRSTVWXZ'
for s in['AEIOUY',W]*2:W=[w+c for w in W for c in s]
print W
I'm back six years later with a golf. The string W of consonants can also be used as the result of the first loop which gives all first-letter options. The fact that it's a string rather than a list is harmless because we just need to iterate over it. We can then write the other four letter sets cleanly as ['AEIOUY',W]*2.
Python, 92 bytes
f=lambda i=-4,s='':i*[s]or sum([f(i+1,s+c)for c in i%2*'AEIOUY'or'BCDFGHJKLMNPQRSTVWXZ'],[])
Can't let itertools win out. Iterative is 1 byte longer in Python 2.
W='',
for s in(['AEIOUY','BCDFGHJKLMNPQRSTVWXZ']*3)[1:]:W=[w+c for w in W for c in s]
print W
JavaScript (Node.js), 80 bytes
f=(i=5,s)=>i?[...i%2?'bcdfghjklmnpqrstvwxz':'aeiouy'].flatMap(e=>f(i-1,[s]+e)):s
JavaScript (Node.js), 99 bytes
f=(i=5,s='',j=35,c=j.toString(36))=>+c?'':i?f(i,s,j-1)+(i%2^/[aeiouy]/.test(c)?f(i-1,s+c):''):s+' '
Curry (PAKCS), 57 bytes
v=anyOf"aeiouy"
c=anyOf"bcdfghjklmnpqrstvwxz"
[c,v,c,v,c]
Vyxal, 8 bytes
k¹k∪"5ẎΠ
" # Pair
k¹ # Consonants
k∪ # and vowels
5Ẏ # Extend to length 5
Π # Take the cartesian product
C (gcc), 123 120 117 bytes
-6 bytes thanks to ceilingcat
char w[6];f(n,m,c,p){for(n=457653;c=p=n<1<<24;p&&puts(w))for(m=n++;m;m/=26)p*=!index("aeiouy",w[5-c]=m%26+97)^++c%2;}
ink, 224 bytes
LIST V=(a),e,i,o,u,y
LIST C=(b),c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,z
~temp D=C
~temp E=V
~temp F=C
~temp G=V
~temp H=C
-(L){D}{E}{F}{G}{H}
~H++
{H:->L}
~H=C
~G++
{G:->L}
~G=V
~F++
{F:->L}
~F=C
~E++
{E:->L}
~E=V
~D++
{D:->L}
Shell, 72 64
Try it online! (Thanks @Grimy)
echo {g..z}{a..f}{g..z}{a..f}{g..z}|tr b-z eiouybcdfghj-np-tvwxz
If it must be delimited by newlines (beware of the spaces) 69 bytes Try it online!:
echo {g..z}{a..f}{g..z}{a..f}{g..z}|tr \ b-z \\neiouybcdfghj-np-tvwxz
Original shell, 72 bytes (bash, ksh, zsh, a simple sh may not expand {..}) Try it online!
echo {a..t}{1..6}{a..t}{1..6}{a..t}|tr a-t1-6 bcdfghjklmnpqrstvwxzaeiouy
Less than half a second. Considering that a C equivalent runs in 0.228sec and a perl equivalent takes 2.1 seconds, this is Not slow (times reported as TiO measured them).
Zsh, 58 bytes
v=(a e i o u y)
c=(${${:-{b..z}}:|v})
echo $^c$^v$^c$^v$^c
${ :|foo} is set difference, and ${^foo} enables brace expansion over the contents of the array foo.
If newline-delimited is required, 64 bytes:
v=(a e i o u y)
c=(${${:-{b..z}}:|v})
<<<${(F):-$^c$^v$^c$^v$^c}
MathGolf, 25 16 bytes
╩æ╩¼`┼]m▒ε*mÅ─yn
Definitely not optimal, but this challenge got me to actually implement some features of MathGolf that have been in TODO since forever, mainly string subtraction and vowels/consonants. Once it's up on TIO I'll update this answer. MathGolf has been updated, and I'll add this as a disclaimer that some features used in this answer are newer than the challenge itself.
To fetch consonants and vowels from the dictionary, I filtered out words in the dictionary files which were duplicates, and found that I had 3 duplicates within the top 256 words of the dictionary. I decided that that 2 of these slots should be replaced by the string of consonants and the string of vowels. I was unsure of where "y" should be placed, but decided to place it among the vowels.
The one thing that is not in place is cartesian product for strings. Since I have not defined the output format yet, this feature did not make it into the latest version of MathGolf.
Explanation
ʑ fetch dictionary word 145 ("bcdfghjklmnpqrstvwxz")
ʬ fetch dictionary word 172 ("aeiouy")
` duplicate the top two items
┼ duplicate second item from top and push to top
] end array / wrap stack in array
stack is now ["<cons>", "<vow>", "<cons>", "<vow>", "<cons>"]
m▒ map each element to a list of chars
ε* reduce list by multiplication (cartesian product)
mÅ explicit map using next 2 operators
─ flatten array
y join array without separator to string or number
n join array with newlines to a string
J, 52 37 34 33 bytes
echo>,{5$'aeiouy'(-.~;[)u:97+i.26
-1 thanks to Adam's suggestion of u:97+i.26 to replace 26{.97|.a.
u:97+i.26extract letters a..z from ascii alphabeta.'aeiouy'(-.~;[)subtract the vowels from a..z, and link;that (the consonants) to the vowels, creating a boxed listconsonants ; vowels.5$extent that boxed list cyclically to 5 elements, yieldingconsonants ; vowels ; consonants ; vowels ; consonants.{create the cross product,flatten>open the boxes to create regular stringsechoprint the results
JavaScript (Firefox 30-57), 82 bytes
f=(i=5)=>i?[for(s of f(i-1))for(c of i%2?'bcdfghjklmnpqrstvwxz':'aeiouy')s+c]:['']
Returns an array of strings. Very fast version for 102 101 (1 byte thanks to @ETHproductions) bytes:
_=>[for(i of c='bcdfghjklmnpqrstvwxz')for(j of v='aeiouy')for(k of c)for(l of v)for(m of c)i+j+k+l+m]
R, 111 98 bytes
Added y as a vowel, and golfed off 13 bytes, thanks to @Patrick B.
l=letters
v=c(1,5,9,15,21,25)
apply(expand.grid(C<-l[-v],V<-l[v],C,V,C)[,5:1],1,cat,fill=T,sep="")
We use expand.grid to generate all possible combinations of V and C in a matrix, which we define from the preset variable letters (the alphabet). We reverse the combinations (as the default is for the first variable to rotate the fastest) to ensure alphabetical order. Then we iterate through each row of the matrix, printing each letter to stdout. We use the fill argument to cat to ensure that each word begins on a new line.
Informix-SQL, 254 bytes
an SQL version (IBM Informix dialect)
select x from table(list{'a','e','i','o','u','y'})(x)
into temp v;
select x from table(list{'b','c','d','f','g','h','j','k',
'l','m','n','p','q','r','s','t','v','w','x','z'})(x)
into temp c;
select k.x||j.x||i.x||v.x||c.x
from c,v,c i,v j,c k
order by 1
Java, 347 bytes -.-
public class N{public static void main(String[]a){String c="bcdfghjklmnpqrstvwxz";String v="aeiouy";int[]i=new int[5],e=new int[5];e[0]=e[2]=e[4]=20;e[1]=e[3]=6;m:while(true){System.out.println(c.charAt(i[0])+v.charAt(i[1])+c.charAt(i[2])+v.charAt(i[3])+c.charAt(i[4]));int p=4;while(true){++i[p];if(i[p]<e[p])break;i[p]=0;if(p==0)break m;--p;}}}}
Perl, 47 bytes
#!perl -l
/((^|[aeiouy])[^aeiouy]){3}/&&print for a..1x5
Counting the shebang as one.
R, 143 132 bytes
q=letters;v=c(1,5,9,15,21,25);x=list(q[-v],q[v],q[-v],q[v],q[-v]);Reduce(paste0,mapply(function(a,b)rep(a,e=b/20),x,cumprod(sapply(x,length))))
q=letters;v=c(1,5,9,15,21,25);x=list(a<-q[-v],b<-q[v],a,b,a);Reduce(paste0,mapply(function(a,b)rep(a,e=b/20),x,cumprod(lengths(x))))
This is my first go at code golf so I'd welcome any suggestions to chop it down further. So far it's all pretty standard R; the only possibly tricky thing here is that paste0 recycles its arguments to the length of the longest one.
Edit: used assignment trick from rturnbull, replaced sapply(x,length) with lengths.
T-SQL, 276
This answer assumes a query's result set is valid output.
WITH c AS(SELECT*FROM(VALUES('b'),('c'),('d'),('f'),('g'),('h'),('j'),('k'),('l'),('m'),('n'),('p'),('q'),('r'),('s'),('t'),('v'),('w'),('x'),('z'))c(_)),v AS(SELECT*FROM(VALUES('a'),('e'),('i'),('o'),('u'),('y'))v(_))SELECT c._+v._+b._+a._+d._ FROM c,v,c b,v a,c d ORDER BY 1
It works in SQL Server 2008 R2. I'm not sure currently where you'd be able to run it online given the number of rows returned, though.
One CTE definition holds the consonants from a derived table. The other holds the vowels from another derived table. Take the Cartesian product of three consonant CTEs and two vowel CTEs, and you can get an alphabetized list of the appropriately concatenated values.
Scala, 87 86 bytes
val a="aeiouy"
val b='a'to'z'diff a
for(c<-b;d<-a;e<-b;f<-a;g<-b)println(""+c+d+e+f+g)
PHP, 88 86 84 80 bytes
pretty string increment :)
6 bytes saved by @Christoph
for($s=$v=aeiouy;++$s<zyzza;preg_match("#[^$v]([$v][^$v]){2}#",$s)&&print"$s
");
loops through all strings from bababa to zyzyz and tests if they match the pattern. Run with -nr.
C#, 244 242 234 219 bytes
class P{static void Main(){string v="aeiouy",c="bcdfghjklmnpqrstvwxz";int i=0,j,k,l,m;for(;i<20;i++)for(j=0;j<6;j++)for(k=0;k<20;k++)for(l=0;l<6;l++)for(m=0;m<20;)System.Console.Write("\n"+c[i]+v[j]+c[k]+v[l]+c[m++]);}}
Ungolfed:
class P
{
static void Main()
{
string v = "aeiouy", c = "bcdfghjklmnpqrstvwxz";
int i=0, j, k, l, m;
for (; i < 20; i++)
for (j=0; j < 6; j++)
for (k=0; k < 20; k++)
for (l=0; l < 6; l++)
for (m=0; m < 20; )
System.Console.Write("\n"+c[i]+v[j]+c[k]+v[l]+c[m++]);
}
}
I doubt I can trim it any further. Done on C# 5, so no {c[i]}
C, 201 199 186 184 183 169 163 bytes
Doing it a bit differently than with the previous basic counting method:
f(){for(char*c="bcdfghjklmnpqrstvwxz",*v="aeiouy",i[5]={0},*s[]={c,v,c,v,c},j=0;j<5;puts("")){for(j=5;j--;putchar(s[j][i[j]]));for(;j++<5&&!s[j][++i[j]];i[j]=0);}}
Ungolfed:
f() {
for(char *c="bcdfghjklmnpqrstvwxz", *v="aeiouy", i[5]={0}, *s[]={c,v,c,v,c}, j=0; j<5; puts("")) {
for (j=5; j--; putchar(s[j][i[j]])) ;
for (; j++ < 5 && !s[j][++i[j]]; i[j]=0) ;
}
}
And written in a bit more conventional way:
f() {
char *c="bcdfghjklmnpqrstvwxz", *v="aeiouy", i[]={0,0,0,0,0}, *s[]={c,v,c,v,c}, j=0;
while (j>=0) {
for (j=0; j<5; j++) putchar(s[j][i[j]]); // output the word
while (--j>=0 && !s[j][++i[j]]) i[j]=0; // increment the counters
puts("");
}
}
Basically, i are the counters, and s the array of strings containing all the chars over which we should iterate, for each counter. The trick is the inner while loop: it is used to increment the counters, starting from the rightmost one. If we see that the next character we should display is the ending null char, we restart the counter to zero and the "carry" will be propagated to the next counter.
Thanks Cristoph!
Batch, 185 bytes
@set c=b c d f g h j k l m n p q r s t v w x z
@for %%i in (%c%)do @for %%j in (a e i o u y)do @for %%k in (%c%)do @for %%l in (a e i o u y)do @for %%m in (%c%)do @echo %%i%%j%%k%%l%%m
Batch is so verbose that it costs 4 bytes to put the vowels into a variable.
Perl 6, 53 Bytes
/<-[aeiouy]>**3%<[aeiouy]>/&&.say for [...] <a z>Xx 5
Takes a little time to have any output. Very inefficient. Does the job.
Ruby, 72 71 52 bytes
puts (?z..?z*5).grep /#{["[^aeiouy]"]*3*"[aeiouy]"}/
Thanks to Value Ink for the basic idea, which brought that down to 60 bytes.
Perl, 63 59 54 bytes
$a="aeiouy";$b="[^$a][$a]"x2;for("a"x5.."z"x5){say if/$b[^$a]/}
$a="aeiouy";$b="[^$a][$a]"x2;/$b[^$a]/&&say for"a"x5.."z"x5
$a=aeiouy;$b="[^$a][$a]"x2;/$b[^$a]/&&say for a.."z"x5
Trying Perl golf for a change.
EDIT: Looks like I've still got much to learn... :)
Python 2, 120 117 bytes
Thanks to @WheatWizard for the tabs tip.
x,y='aeiouy','bcdfghjklmnpqrstvwxz'
for a in x:
for e in x:
for b in y:
for c in y:
for d in y:print b+a+c+e+d
Not sure that this can be golfed much. Try it online truncates at 128KB but shows enough to give an idea. A local run with debug code to count the words gave a total of 288000. Runs in about 45 seconds if anyone wants to test.
zyzyv
zyzyw
zyzyx
zyzyz
Total word count: 288000
Non-compliant and therefore non-competing version (prints out nested arrays instead of the specified format) for 110 bytes:
x,y='aeiouy','bcdfghjklmnpqrstvwxz'
print[[[[c+a+d+b+e for e in y]for d in y]for c in y]for b in x]for a in x]
Stacked, noncompeting, 51 bytes
(consonants:@c vowels:@v c v c)multicartprod$outmap
Pretty simple. Try it here!
Haskell, 54 51 bytes
l="bcdfghjklmnpqrstvwxz":"aeiouy":l
mapM(l!!)[0..4]
mapM func list builds all words by taking the possible characters for index i from the list returned by func (list!!i).
Edit: @xnor found 2 bytes to save and looking at his solution, I found another one.
Pyth, 25 23 bytes
s.n*F[K-GJ"aeiouy"JKJKb
In pseudocode:
' ' G, b = "abcdefghijklmnopqrstuvwxyz", "\n"
' J"aeiouy" ' J = "aeiouy"
' K-GJ ' K = "bcdfghjklmnpqrstvwxz"
's.n ' "".join( flatten(
' *F ' reduce(cartesian_product,
' [K JKJKb' [K,J,K,J,K,b]
' ' # b makes it so that every word ends with \n so that
' ' # flattening and concatenating automatically deals with
' ' # newlines
JavaScript (ES6), 91 90 bytes
f=(s='',i=4)=>{for(c of i%2?'aeiouy':'bcdfghjklmnpqrstvwxz')i?f(s+c,i-1):console.log(s+c)}
Edits
- ETHproductions: -1 byte by removing extraneous group around ternary operator in
forstatement
Explanation
This defines a 5-deep recursive function that uses the parity of its depth of call to determine whether to iterate vowels or consonants. On each iteration, it checks to see whether to recurse or print by checking the amount of recursions left, and concatenates the letter of its current iteration to the end of the 5 character string that is currently being built depth-first.
Alternative 89 byte solution assuming ISO8859-1 encoding:
f=(s='',i=4)=>{for(c of i%2?'aeiouy':btoa`mÇ_äi骻-¿s`)i?f(s+c,i-1):console.log(s+c)}
Alternative 96 byte solution that returns entire output as single string:
f=(s='',i=4,o='')=>eval("for(c of i%2?'aeiouy':'bcdfghjklmnpqrstvwxz')o+=i?f(s+c,i-1):s+c+`\n`")
Run at your own risk. For the 91 byte solution, just use f() and for the 97 byte alternative, use console.log(f()).
C 361 bytes
f(){i,j,k,l,m;v[6]={97,101,105,111,117,121};c[25];s=26;for(i=0;i<26;i++)c[i]=97+i;for(i=0;i<26;i++){for(j=0;j<6;j++)if(c[i]==v[j])c[i]+=1;}for(i=0;i<s;i++)for(j=i+1;j<s;){ if(c[i]==c[j]){for(k=j;k<s-1;++k)c[k]=c[k+1];--s;}else ++j;}for(i=0;i<s;i++)for(j=0;j<6;j++)for(k=0;k<s;k++)for(l=0;l<6;l++)for(m=0;m<s;m++)printf("%c%c%c%c%c\n",c[i],v[j],c[k],v[l],c[m]);}
Ungolfed version:
void f()
{
int i,j, k,l,m;
int s=26;
int v[6]={97,101,105,111,117,121};
int c[s];
for(i=0;i<s;i++)
c[i]=97+i;
for(i=0;i<s;i++)
{
for(j=0;j<6;j++)
if(c[i]==v[j])
c[i]+=1;
}
for(i=0;i<s;i++)
for(j=i+1;j<s;)
{ if(c[i]==c[j])
{
for(k=j;k<s-1;++k)
c[k]=c[k+1];
--s;
}else
++j;
}
for(i=0;i<s;i++)
for(j=0;j<6;j++)
for(k=0;k<s;k++)
for(l=0;l<6;l++)
for(m=0;m<s;m++)
printf("%c%c%c%c%c\n",c[i],v[j],c[k],v[l],c[m]);
}
There must be some way to shorten this definitely.
Explanation
- Stored the integer values of a,e,i,o,u,y in a numerical array,
- Stored all alphabets in array, if it was a vowel, replaced it with a consonant, so there were duplicate consonant values in the array,
- Removed duplicate consonant values,
- Printed all combinations c-v-c-v-c.
CJam, 32 31 29 28 bytes
Saved 2 bytes thanks to Martin Ender and 1 byte thanks to kaine
"aeiouy"_'{,97>^\1$1$1$N]:m*
Try it online! (Note that the output gets cut off on TIO)
Explanation
"aeiouy"_ e# Push the six vowels and duplicate
'{,97> e# Push the whole alphabet
^ e# Symmetric set difference of the alphabet with the vowels, yields the consonants only
\ e# Swap top two elements
1$1$1$ e# Copy the second-from-the-top string to the top three times
e# This results in the array being consonants-vowels-consonants-vowels-consonants
N e# Add a newline character to the end of the list
] e# End an array. Puts everything done so far in an array
e# since there was no explicit start of the array.
:m* e# Reduce the array using Cartesian products
Pure Bash, 74
v={a,e,i,o,u,y}
c={b,c,d,f,g,h,{j..n},{p..t},v,w,x,z}
eval echo $c$v$c$v$c
Straightforward brace expansion.
If each item must be on its own line, then we have:
Pure Bash, 84
v={a,e,i,o,u,y}
c={b,c,d,f,g,h,{j..n},{p..t},v,w,x,z}
eval printf '%s\\n' $c$v$c$v$c
Python 2, 120 102 94 bytes
from itertools import*
lambda:map(''.join,product(*(('AEIOUY','BCDFGHJKLMNPQRSTVWXZ')*3)[1:]))
Ruby, 65 61 bytes
Completely different approach:
(b=[*?a..?z]-a="aeiouy".chars).product(a,b,a,b){|x|puts x*""}
New things I learned today: the Array#product function
Python 3 - 110 bytes
a,b="bcdfghjklmnpqrstvwxz","aeiouy";print(*(c+d+e+f+g for c in a for d in b for e in a for f in b for g in a))
Straightforward looping fun :)
Clojure, 101 bytes
(print(apply str(for[V["aeiouy"]C["bcdfghjklmnpqrstvwxz"]a C b V c C d V e C](str a b c d e "\n")))))
Not that exciting...
Perl 6, 70 bytes
$_=<a e i o u y>;my \c=[grep .none,"a".."z"];.say for [X~] c,$_,c,$_,c
Explanation of the interesting part:
.say for [X~] c, $_, c, $_, c
c, $_, c, $_, c # list of five lists
[X ] # lazily generate their Cartesian product
~ # and string-concatenate each result
.say for # iterate to print each result
The code before that just generates the list of vowels ($_) and the list of consonants (c), which is regrettably verbose.
05AB1E, 18 16 bytes
05AB1E uses CP-1252 encoding.
žP3ãžO3ãâ€øJ€¨ê»
Explanation
žP3ã # push all combinations of 3 consonants
žO3ã # push all combinations of 3 vowels
â # cartesian product
€ø # zip each pair of [ccc,vvv] (c=consonant,v=vowel)
J # join to list of strings ['cvcvcv','cvcvcv' ...]
۬ # remove last vowel from each
ê # sort and remove duplicates
» # join on newlines
For testing purposes I recommend replacing žP with a few consonants and žO with a few vowels.
Befunge, 95 bytes
::45*%\45*/:6%\6/:45*%\45*/:6%\6/1g,2g,1g,2g,1g,55+,1+:"}0":**-!#@_
bcdfghjklmnpqrstvwxz
aeiouy
Try it online!, although note that the output will be truncated.
This is just a loop over the range 0 to 287999, outputting the index as a mixed based number 20-6-20-6-20, with the "digits" of the number retrieved from the tables on the last two lines.
Brachylog, 18 bytes
@W:@Dg:2jcb:eac@w\
Explanation
@W:@D The list ["aeiouy", "bcdfghjklmnpqrstvwxz"]
g:2jcb The list ["bcdfghjklmnpqrstvwxz", "aeiouy", "bcdfghjklmnpqrstvwxz", "aeiouy", "bcdfghjklmnpqrstvwxz"]
:ea Take one character of each string
c Concatenate into a single string
@w Write to STDOUT followed by a newline
\ Backtrack: try other characters of the string
Mathematica, 72 65 61 bytes
Print@@@Tuples@{a=##/(b=#5#9#15#21#25#)&@@Alphabet[],b,a,b,a}
For testing, I recommend replacing Print@@@ with ""<>#&/@. Mathematica will then display a truncated form showing the first few and last few words, instead of taking forever to print 288,000 lines.
Explanation
I finally found a use for dividing strings. :)
I've been intrigued by the possibility of adding or multiplying strings for a while, but the actual use cases are fairly limited. The main point is that something like "foo"+"bar" or "foo"*"bar" (and consequently, the short form "foo""bar") is completely valid in Mathematica. However, it doesn't really know what to do with the strings in arithmetic expressions, so these things remain unevaluated. Mathematica does apply generally applicable simplifications though. In particular, the strings will be sorted into canonical order (which is fairly messed up in Mathematica, once you start sorting strings containing letters of various cases, digits and non-letters), which is often a dealbreaker, but doesn't matter here. Furthermore, "abc""abc" will be simplified to "abc"^2 (which is a problem when you have repeated strings, but we don't have that either), and something like "abc"/"abc" will actually cancel (which we'll be even making use of).
So what are we trying to golf here. We need a list of vowels and a list of consonants, so we can feed them to Tuples to generate all possible combinations. My first approach was the naive solution:
Characters@{a="bcdfghjklmnpqrstvwxz",b="aeiouy",a,b,a}
That hardcoded list of consonants does hurt a bit. Mathematica does have an Alphabet built-in which would allow me to avoid it, if I were able to remove the vowels in a cheap way. This is where it gets tricky though. The simplest way to remove elements is Complement, but that ends up being longer, using one of the following options:
{a=Complement[Alphabet[],b=Characters@"aeiouy"],b,a,b,a}
{a=Complement[x=Alphabet[],b=x[[{1,5,9,15,21,25}]]],b,a,b,a}
(Note that we don't need to apply Characters to the whole thing any more, because Alphabet[] gives a list of letters, not a string.)
So let's try that arithmetic business. If we represent the entire alphabet as a product of letters instead of a list, then we can remove letters by simple division, due to the cancelling rule. That saves a lot of bytes because we won't need Complement. Furthermore, "a""e""i""o""u""y" is actually a byte shorter than Characters@"aeiouy". So we do this with:
a=##/(b="a""e""i""o""u""y")&@@Alphabet[]
Where we're storing the consonant and vowel products in a and b, respectively. This works by writing a function which multiplies all its arguments with ## and divides them by the product of vowels. This function is applied to the alphabet list, which passes each letter in as a separate argument.
So far so good, but now we have
{a=##/(b="a""e""i""o""u""y")&@@Alphabet[],b,a,b,a}
as the argument to Tuples, and those things are still products, not lists. Normally, the shortest way to fix that is putting a List@@@ at the front, which turns the products into lists again. Unfortunately, adding those 7 bytes makes it longer than the naive approach.
However, it turns out that Tuples doesn't care about the heads of the inner lists at all. If you do
Tuples[{f[1, 2], f[3, 4]}]
(Yes, for an undefined f.) You'll get:
{{1, 3}, {1, 4}, {2, 3}, {2, 4}}
Just as if you had used a List instead of f. So we can actually pass those products straight to Tuples and still get the right result. This saves 5 bytes over the naive approach using two hardcoded strings.
Now the "a""e""i""o""u""y" is still fairly annoying. But wait, we can save a few bytes here as well! The arguments of our function are the individual letters. So if we just pick out the right arguments, we can reuse those instead of the string literals, which is shorter for three of them. We want arguments # (short for #1), #5, #9, #15, #21 and #25. If we put # at the end, then we also don't need to add any * to multiply them together, because (regex) #\d+ is a complete token that can't have any non-digit appended to it. Hence we end up with #5#9#15#21#25#, saving another 4 bytes.
Haskell, 93 bytes
c="bcdfghjklmnpqrstvwxz"
t=[[a,b]|a<-"aeiuoy",b<-c]
main=putStr$unlines[b:y++z|b<-c,y<-t,z<-t]
I have tried to slim the hardcoded lists of consonants and vowels down, but haven't been able to find something that saves bytes. This will output all possible five letter words in the order as stated in the post to stdout, being generated via list comprehensions.
Perl, 71 bytes
map{push@{1+/[aeiouy]/},$_}a..z;$"=",";say for glob"{@1}{@2}"x2 ."{@1}"
Explanation
I'll add more explanations later.
map{push@{1+/[aeiouy]/},$_}a..z; creates two arrays: @1 contains the consonants, and @2 contains the vowels.
glob when call with arguments like {a,b}{c,d} returns all permutations of the elements in the braces.
MATL, 21 bytes
11Y2'y'h2Y2X~6Myyy&Z*
Try it online! (but output is truncated).
11Y2 % Push 'aeiou' (predefined literal)
'y' % Push 'y'
h % Concatenate: gives 'aeiouy'
2Y2 % Push 'abcdefghijklmnopqrstuvwxyz' (predefined literal)
X~ % Set symmetric difference: gives 'bcdfghjklmnpqrstvwxz'
6M % Push 'aeiouy' again
yyy % Duplicate the second-top element three times onto the top. The stack now
% contains 'bcdfghjklmnpqrstvwxz', 'aeiouy', 'bcdfghjklmnpqrstvwxz',
% 'aeiouy', 'bcdfghjklmnpqrstvwxz'
&Z* % Cartesian product of all arrays present in the stack. Implicity display