4
Context
As a conlanger, I am interested in creating a uniform, naturalistic language. One of the tricks is to create vocabulary according to certain structures of words. An example from English: In English, we have the word “tap” structured consonant-vowel-consonant. Usually, this means that there are many other words of this structure: “cat”, “dog”, “rock”, “fog”, “good”, etc.
Task
As input, you have:
- an array
C
containing strings: consonants (C
is the first letter in the word consonants). Identical consonants cannot be repeated on this list. For example, this list cannot contain ['b', 'b']. - an array
V
containing strings: vowels (V
is the first letter of the word vowels). Identical vowels cannot be repeated on this list. - string
S
, which contains something like this "CVCCV" (any combination of "C" and "V")
Your task is to replace “C” in the string with a randomly taken string from array C
and replace “V” in the string with a randomly taken string from array V
and return (or display) this string.
"randomly" is defined as all possibilities having an equal chance of being selected. This is a kind of simplification: in real languages as well as in conlangs, there are very frequent (for example 'r' in English) and not very frequent sounds but this is just a code-golf.
Rules
This is code-golf so the lowest byte count wins.
Examples
Input:
C = ['p', 'b', 't', 'd', 'k', 'g', 'm', 'n', 'w']
V = ['a', 'o', 'u', 'i', 'e', 'ä']
S = 'CVCCV'
Output:
pakto
Input:
C = ['p', 'b', 't', 'd', 'k', 'g', 'v', 's', 'r']
V = ['a', 'o', 'u', 'i', 'e', 'ä', 'ᵫ']
S = 'CVVCCVCCV'
Output:
koebrᵫvtä
Can
s
be a string of 0s and 1s? And what about an integer with the bits indicating to usec
orv
? – RGS – 2020-02-22T16:28:00.800@RGS Why do you need it? – Victor VosMottor thanks Monica – 2020-02-22T16:29:27.720
1To make it easier to pick consonants or vowels depending on what
s
has. – RGS – 2020-02-22T16:30:06.037@RGS In
task
I've written: ifC
ins
than consonant, else ifV
ins
than vowels, ain't it? – Victor VosMottor thanks Monica – 2020-02-22T16:31:41.597Exactly, I understand that. I just mean that if
s
was encoding that information in an easier way, it may create nicer solutions. – RGS – 2020-02-22T16:33:44.4104
Please clarify what you mean by randomly. Also, do we really need to handle non-ASCII input?
– Luis Mendo – 2020-02-22T17:36:40.7932Can each letter in C or V be used more than once? – Xcali – 2020-02-22T17:40:05.020
My guess is this was closed awaiting clarifications regarding Luis Mendo's questions above. – Jonathan Allan – 2020-02-24T01:01:39.547
@Luis Mendo I meant by randomly any pseudorandom library or algorithm with the same probability. Yes, you should handle non-ASCII input. – Victor VosMottor thanks Monica – 2020-02-24T12:32:21.193
1@VictorVosMottorthanksMonica You still haven't clarified what you mean by "randomly". Equally likely? Independent choices? Should each letter have non-zero probability? Please take a look at the meta post I linked to understand the problem – Luis Mendo – 2020-02-24T12:49:56.133