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
because every g
becomes geo
, every G
(though there are none) becomes Geo
, every b
becomes bits
, and every B
becomes Bits
.
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 bits
.
Challenge
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 geo bits
, butt ner
, alex
, and do o r k nob
(single letter segments have no effect but are valid). But geo
, butt ner
, Alex
, and 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]
→ [empty string]
i
→ ing
I
→ Ing
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.
["no", "pro", "gr", "am", "m", "ing"]
\$\endgroup\$\\b${l}(\\S+)
although that does cost you 5 bytes. \$\endgroup\$abra cadabra
,!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
That should cover all edge cases, and there are a lot of them if one tries to use regexes... \$\endgroup\$