15
1
Thanks to @ComradeSparklePony for the title.
This challenge should be very simple. You are given three lists.
The first is a list of first names, in title case.
The second is a list of adjectives, in lower case.
The third is a list of nouns, in lower case.
Please randomly select a name, optional adjective, and noun, and output <Name>'s <adjective> <noun>
. However, each word must begin with the same letter. You can assume that all words begin with a letter. You can also assume (but note in your answer if you do):
- that all words are composed solely of alphabetic characters
- that there is at least one noun for each name
- that there is at least one name for each noun
You cannot however assume that an adjective exists for a particular pair of name and noun, as the adjective is optional so the output will still be valid.
You do not have to select the shared letter uniformly, although all available letters must have a non-zero chance of occurring. You must however ensure that all outputs for a given letter have as near equal chance of occurring as possible within the limits of your language's random number generator. In the case of the adjective, this is equivalent to having an extra entry meaning "no adjective for this letter" which has the same chance as all of the other adjectives for that letter.
Example input lists:
Joan Neil Nicola Oswald Sherman Stephanie
new novel old original second silent
jeep noun novel output second sheep snake
Example outputs for these inputs (each line is a separate example):
Stephanie's second second
Sherman's silent snake
Oswald's original output
Nicola's novel novel
Neil's noun
Joan's jeep
Note no extra space between words in the last two examples.
This is code-golf, so the shortest code that breaks no standard loopholes wins!
In the unlikely event that it helps, you can input everything in upper case, but you still need to output in sentence case.
Are we correct to assume that the program should return: 1 name 1 adjective (if one matches the name) 1 noun ? Or are you asking to produce an output for each name? – DavidC – 2019-05-12T11:26:44.127
1Maybe you should add 'Joan' and 'jeep' in your example to illustrate the fact that there might be no adjective at all for a given letter? – Arnauld – 2019-05-12T11:55:14.370
Given your example input is the chance of no adjective 1 in 3 (since all adjective "lists" are 2 long)? ...and if 'Joan' and 'Jeep' were also there with no
j
-adjective would the chance become 4 in 9? Might be worth placing probabilities against outputs, or enumerating all outputs -- as I understand it not only "all outputs for a given letter..." but also all distinct outputs should have equal likelihood (given distinct values within each list). – Jonathan Allan – 2019-05-12T12:37:11.427@DavidC Sorry, I realise adding extra examples has made that unclear; you only produce one line of output for each invocation. – Neil – 2019-05-12T13:16:29.833
1@JonathanAllan Adding "Joan" and "jeep" wouldn't affect the relative chances of "Neil's noun" being output compared with other options containing "Neil" and "noun". – Neil – 2019-05-12T13:17:25.057
@JonathanAllan As it happens, the example does indeed have a chance of no adjective of 1 in 3, although I hadn't intended it that way. Adding "Joan" and "jeep" would alter the chance of no adjective depending on how frequently the letter "j" was chosen, so it's not necessarily 4 in 9. – Neil – 2019-05-12T13:25:35.067
I was talking about the chance of any output with no adjective. – Jonathan Allan – 2019-05-12T13:26:15.737
"so it's not necessarily 4 in 9" ...so we don't have to be uniform in our choices of name? – Jonathan Allan – 2019-05-12T13:27:35.137
@JonathanAllan You only have to be uniform in your choice between different names that start with the same letter. You don't have to be uniform in your choice of letter. – Neil – 2019-05-12T13:33:03.570
Right, I see (and now see it in the text), thanks for the clarification! – Jonathan Allan – 2019-05-12T13:34:46.870
Are we allowed an extra space between the words if there is no adjective? – Nick Kennedy – 2019-05-12T14:20:27.650
@NickKennedy No, sorry if that wasn't clear from the example. – Neil – 2019-05-12T14:31:49.960