2
\$\begingroup\$

Your Goal:

Given an odd integer input n greater than 1, generate a random English word of length n. An English word is one in which the odd (1-based) indices are consonants and the even (1-based) indices are vowels, the vowels being aeiou.

Random

For the purposes of this challenge, you are to sample from the vowels and consonants uniformly, with replacement. In other words, each possible English word must be equally likely to appear as an output.

Example Inputs/Outputs

3 -> bab, tec, yiq
5 -> baron, nariz, linog
7 -> murovay, fanafim

Winner:

Winner is the Lowest Byte Count.

Upvote your Favorite one, Top 3 Upvoted will be Honorable Mentions :P

\$\endgroup\$
  • 4
    \$\begingroup\$ Welcome to the site. I don't really understand the challenge here. Maybe the sandbox (linked on the right), would be a good place to get feedback. \$\endgroup\$ – Wheat Wizard Feb 7 at 19:19
  • \$\begingroup\$ Are we making a function that generates the words? Or should the program simply generate them when run? \$\endgroup\$ – sugarfi Feb 7 at 19:49
  • 7
    \$\begingroup\$ Hi there. I've voted to close this as needing additional clarity, but do not fret when this gets closed! It's tough to get a challenge specified up to our standards the first few times you come up with one, so we have a sandbox for you to get feedback on them before they come to the main site. Hope you enjoy your time here, and happy golfing! \$\endgroup\$ – Giuseppe Feb 7 at 20:46
  • 4
    \$\begingroup\$ Be sure to specify what you mean by random. Also, how is the output size specified? Is it also random? \$\endgroup\$ – Luis Mendo Feb 7 at 21:35
  • 1
    \$\begingroup\$ I've gone ahead and edited it (and voted to re-open), please make edits to it as you feel appropriate! \$\endgroup\$ – Giuseppe Feb 12 at 19:19
5
\$\begingroup\$

05AB1E, 14 11 bytes

-3 bytes thanks to Kevin Cruijssen

EžN¸žMšNèΩJ

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ ¸ì can be š, .R can be Ω, and the } can be removed before the join. \$\endgroup\$ – Kevin Cruijssen Feb 10 at 7:49
  • \$\begingroup\$ oh wow, thank you! @KevinCruijssen \$\endgroup\$ – mabel Feb 10 at 9:07
2
\$\begingroup\$

Stax, 10 bytes

ÇÅφ⌠↑Ñ°↕Yx

Run and debug it

Explanation

FVcVv2l@_@L

F           In range 1 to the input, do this ...
 Vv         Vowels
   Vc       Consonants
     2l     Wrap the two inside a list
       @    Index the constructed list into the counter
            Note that the counter starts at 1,
            so this picks the constants list
            before the vowels list.
        _@  Index by the current counter
            (Stax doesn't have random number support)
          L Wrap the whole stack into a list
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Wow, nice job on this one \$\endgroup\$ – Mister SirCode Feb 13 at 12:17
2
\$\begingroup\$

GolfScript, 36 bytes

,{['aeiou'.123,97>^]\2%=.,rand=}%''+

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You can save some bytes by using ['aeiou'.123,97>^] instead of your long string. Generates the characters 98-123, then removes the vowels. Plus, they're in two distinct arrays too, which saves you a bunch too. the string and 21/ can be removed, meaning you're down 31 chars and up 18, netting 13. ,{['aeiou'.123,97>^]\2%=.,rand=}%''+ This worked for me. \$\endgroup\$ – Mathgeek Feb 14 at 14:18
1
\$\begingroup\$

Perl 5, 69 bytes

say map{([a,e,i,o,u],[grep!/[eiou]/,b..z])[$_%2][rand$_%2*16+5]}1..<>

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ruby, 76 bytes

Basic recursive function that adds a consonant and a vowel each time until there's only one character left, at which point it adds just the consonant.

f=->n{[*?b..?z].grep(/[^eiou]/).sample+(n<2?'':'aeiou'.chars.sample+f[n-2])}

Try it online!

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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