21
3
Challenge
You will be given an input string, anywhere the word "Lemon"
is found it should be converted to "Lemonade"
but the a
, d
, and e
must be borrowed from somewhere else in the sentence.
Example
Example Input:
I found a lemon when I was a kid
Example Output:
I foun a lemonade whn I was kid
The Lemonade was created by stealing the following superscript letters from the original
I foun
da lemonade when I wasakid
This is just one possible output example, the "e", "d", and "a", could have been taken from anywhere (except for from the word lemon
of course)
Comments
•If there are not enough e
, a
, or d
s you must output what was do-able with the letters given. For example the input bdblemon
would output bblemond
•The lemon
text might not always be standalone (space on each side). For example you may have the word lemons
somewhere in the input and the output should be lemonades
•The input may contain any number of lemon
s, even 0 lemon
s (in which case the output would be identical to the input)
•You can make your lemonade with uppercase and lowercase letters, for example leMon
could become leMonade
, and the ade
borrowed can be any case (so it could also have become leMonADe
).
The case of the letter you borrowed must remain what it was when you borrowed it.
(Example input -> output, he hAD lemOn
-> h h lemOnADe
)
•Does not have to be a full program, a function alone is fine.
•You may assume input will be only the CP437 Character Set
Code Golf
This is code-golf, so the lowest number of bytes wins!
Pseudo-TestCases
*Note: For any given input there might be multiple possible outputs so your program may not output exactly as these test cases do, this is more just so people can understand the logic:
Input: EpaD leMons
Output: p LeMonaDEsInput: hello world
Output: hello worldInput: lemon lemon
Output: lemon lemon
*(Thee
,a
,d
letters should never be taken from another "Lemon")Input: HE HAD lemonade
Output: H H lemonADEadeInput: Do you like lemons? You hAd me at lemon!
Output: o you lik lemonADes? You h m t lemonade!Input: AE lemon
Output: lemonAEInput: 55bad lemon
Output: 55b lemonad
Throwing a recursion-error doesn't seem to comply to the first rule ("If there are not enough
e
,a
, ord
s you must output what was do-able with the letters given. For example the inputbdblemon
would outputbblemond
")? – Kevin Cruijssen – 2017-05-01T12:31:16.9431@KevinCruijssen Hmm, you're right. I was almost certain that throwing an error was initially allowed. Was it an edit during the grace period of the initial post? (Either that or I dreamed it.) Anyway, I'll try to fix that. Thanks for noticing. – Arnauld – 2017-05-01T12:38:55.913
I looked back in the history before making my comment in case it was indeed edited out. You could be right it might have been edited in the first 5 minutes, but no idea how to check that. And no problem, your answer is still pretty impressive, so I'll +1 it in advance. I have no doubt you'll be able to fix the issue (hopefully without causing to much added bytes). – Kevin Cruijssen – 2017-05-01T12:41:57.040
@KevinCruijssen That's fixed at the cost of 7 bytes for now. – Arnauld – 2017-05-01T13:21:19.300
2@Arnauld Yes sorry I edited that out within the first 2 minutes of the post maybe haha, my apologies – Albert Renshaw – 2017-05-01T17:08:31.883
@AlbertRenshaw No worries. At least, I'm not crazy. :-p – Arnauld – 2017-05-01T17:39:56.370