Geobitsian language is a new perversion of English where a word is broken into segments that each must start with a different letter. Then every time one of those starting letters appears in another string, it is replaced with its entire corresponding segment, maintaining capitalization.
This process is called Geobitsizing.
For example the word "Geobits" could be broken into
geo bits, and the nonsense poem
Algy met a Bear A Bear met Algy The Bear was bulgy The bulge was Algy
would be Geobitsized with it as
Algeoy met a Bitsear A Bitsear met Algeoy The Bitsear was bitsulgeoy The bitsulgeoe was Algeoy
G (though there are none) becomes
bits, and every
Note that each substitution is performed with respect to the original string, not any intermediate step. e.g. if
geo had been
gbo instead, the
b's created would not replaced with
Write a program or function that can generate Geobitsian language.
Take in a single-line string made of lowercase letters (a-z) and spaces. This will be the word used as the Geobitsizing argument, with the spaces separating the segments. You can assume:
- Segments will not be empty. So spaces will not neighbor each other nor be at the start or end of the string.
- Each segment starts with a different letter. Thus there cannot be more than 26.
For example, some valid segmented strings you must support are
do o r k nob (single letter segments have no effect but are valid). But
do o r k n ob are invalid.
Your program or function also needs to take in another arbitrary string to apply the Geobitsizing to, and print or return the resulting Geobitsian language.
You can assume this string only contains newlines and printable ASCII.
Remember that letter cases must be preserved from the input to the output.
Here are some more examples using
no pro gr am m ing as the Geobitsizing argument:
[empty string] →
Mmmm, mmm... MmmmMMM: m&m! →
Mmmm, mmm... MmmmMMM: m&m! (no change)
People think bananas are great, don't you? →
Proeoprole thingnok bamnoamnoams amre grreamt, dono't you?
Pet a Puppy Google Wikipedia
Proet am Prouproproy Groogrle Wingkingproedingam
Note that the results should be identical no matter how the argument is arranged, e.g.
ing pro m no am gr should yield the same results as above.
The shortest code in bytes wins.